Skip to content

chore: regenerate sdk #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-swift.svg?color=green&style=flat-square)
![License](https://img.shields.io/github/license/appwrite/sdk-for-swift.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
Expand Down Expand Up @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "10.0.0"),
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "10.1.0"),
],
```

Expand Down
4 changes: 2 additions & 2 deletions Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class Client {
"x-sdk-name": "Swift",
"x-sdk-platform": "server",
"x-sdk-language": "swift",
"x-sdk-version": "10.0.0",
"x-sdk-version": "10.1.0",
"x-appwrite-response-format": "1.7.0"
]

Expand Down Expand Up @@ -257,7 +257,7 @@ open class Client {

return output.addingPercentEncoding(
withAllowedCharacters: .urlHostAllowed
) ?? ""
)?.replacingOccurrences(of: "+", with: "%2B") ?? "" // since urlHostAllowed doesn't include +
}

///
Expand Down
112 changes: 112 additions & 0 deletions Sources/Appwrite/Services/Databases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,10 @@ open class Databases: Service {
}

///
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create new Documents. Before using this route, you should create a new
/// collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
Expand Down Expand Up @@ -1699,6 +1703,10 @@ open class Databases: Service {
}

///
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create new Documents. Before using this route, you should create a new
/// collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
Expand All @@ -1724,6 +1732,10 @@ open class Databases: Service {
}

///
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create or update Documents. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
Expand Down Expand Up @@ -1768,6 +1780,10 @@ open class Databases: Service {
}

///
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create or update Documents. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
Expand Down Expand Up @@ -1866,6 +1882,10 @@ open class Databases: Service {
}

///
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Bulk delete documents using queries, if no queries are passed then all
/// documents are deleted.
///
Expand Down Expand Up @@ -1907,6 +1927,10 @@ open class Databases: Service {
}

///
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Bulk delete documents using queries, if no queries are passed then all
/// documents are deleted.
///
Expand Down Expand Up @@ -1997,6 +2021,94 @@ open class Databases: Service {
)
}

///
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create or update a Document. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
/// @param String databaseId
/// @param String collectionId
/// @param String documentId
/// @param Any data
/// @param [String] permissions
/// @throws Exception
/// @return array
///
open func upsertDocument<T>(
databaseId: String,
collectionId: String,
documentId: String,
data: Any,
permissions: [String]? = nil,
nestedType: T.Type
) async throws -> AppwriteModels.Document<T> {
let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}"
.replacingOccurrences(of: "{databaseId}", with: databaseId)
.replacingOccurrences(of: "{collectionId}", with: collectionId)
.replacingOccurrences(of: "{documentId}", with: documentId)

let apiParams: [String: Any?] = [
"data": data,
"permissions": permissions
]

let apiHeaders: [String: String] = [
"content-type": "application/json"
]

let converter: (Any) -> AppwriteModels.Document<T> = { response in
return AppwriteModels.Document.from(map: response as! [String: Any])
}

return try await client.call(
method: "PUT",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}

///
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create or update a Document. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
/// @param String databaseId
/// @param String collectionId
/// @param String documentId
/// @param Any data
/// @param [String] permissions
/// @throws Exception
/// @return array
///
open func upsertDocument(
databaseId: String,
collectionId: String,
documentId: String,
data: Any,
permissions: [String]? = nil
) async throws -> AppwriteModels.Document<[String: AnyCodable]> {
return try await upsertDocument(
databaseId: databaseId,
collectionId: collectionId,
documentId: documentId,
data: data,
permissions: permissions,
nestedType: [String: AnyCodable].self
)
}

///
/// Update a document by its unique ID. Using the patch method you can pass
/// only specific fields that will get updated.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Appwrite/Services/Tokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ open class Tokens: Service {

///
/// Create a new token. A token is linked to a file. Token can be passed as a
/// header or request get parameter.
/// request URL search parameter.
///
/// @param String bucketId
/// @param String fileId
Expand Down
2 changes: 1 addition & 1 deletion Sources/AppwriteModels/AttributeList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ open class AttributeList: Codable {
public static func from(map: [String: Any] ) -> AttributeList {
return AttributeList(
total: map["total"] as! Int,
attributes: map["attributes"] as! [AnyCodable]
attributes: (map["attributes"] as! [Any]).map { AnyCodable($0) }
)
}
}
16 changes: 13 additions & 3 deletions Sources/AppwriteModels/AttributeString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open class AttributeString: Codable {
case updatedAt = "$updatedAt"
case size = "size"
case `default` = "default"
case encrypt = "encrypt"
}

/// Attribute Key.
Expand Down Expand Up @@ -47,6 +48,9 @@ open class AttributeString: Codable {
/// Default value for attribute when not provided. Cannot be set when attribute is required.
public let `default`: String?

/// Defines whether this attribute is encrypted or not.
public let encrypt: Bool?


init(
key: String,
Expand All @@ -58,7 +62,8 @@ open class AttributeString: Codable {
createdAt: String,
updatedAt: String,
size: Int,
`default`: String?
`default`: String?,
encrypt: Bool?
) {
self.key = key
self.type = type
Expand All @@ -70,6 +75,7 @@ open class AttributeString: Codable {
self.updatedAt = updatedAt
self.size = size
self.`default` = `default`
self.encrypt = encrypt
}

public required init(from decoder: Decoder) throws {
Expand All @@ -85,6 +91,7 @@ open class AttributeString: Codable {
self.updatedAt = try container.decode(String.self, forKey: .updatedAt)
self.size = try container.decode(Int.self, forKey: .size)
self.`default` = try container.decodeIfPresent(String.self, forKey: .`default`)
self.encrypt = try container.decodeIfPresent(Bool.self, forKey: .encrypt)
}

public func encode(to encoder: Encoder) throws {
Expand All @@ -100,6 +107,7 @@ open class AttributeString: Codable {
try container.encode(updatedAt, forKey: .updatedAt)
try container.encode(size, forKey: .size)
try container.encodeIfPresent(`default`, forKey: .`default`)
try container.encodeIfPresent(encrypt, forKey: .encrypt)
}

public func toMap() -> [String: Any] {
Expand All @@ -113,7 +121,8 @@ open class AttributeString: Codable {
"$createdAt": createdAt as Any,
"$updatedAt": updatedAt as Any,
"size": size as Any,
"`default`": `default` as Any
"`default`": `default` as Any,
"encrypt": encrypt as Any
]
}

Expand All @@ -128,7 +137,8 @@ open class AttributeString: Codable {
createdAt: map["$createdAt"] as! String,
updatedAt: map["$updatedAt"] as! String,
size: map["size"] as! Int,
`default`: map["default"] as? String
`default`: map["default"] as? String,
encrypt: map["encrypt"] as? Bool
)
}
}
2 changes: 1 addition & 1 deletion Sources/AppwriteModels/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ open class Collection: Codable {
name: map["name"] as! String,
enabled: map["enabled"] as! Bool,
documentSecurity: map["documentSecurity"] as! Bool,
attributes: map["attributes"] as! [AnyCodable],
attributes: (map["attributes"] as! [Any]).map { AnyCodable($0) },
indexes: (map["indexes"] as! [[String: Any]]).map { Index.from(map: $0) }
)
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/AppwriteModels/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ open class Document<T : Codable>: Codable {

public static func from(map: [String: Any] ) -> Document {
return Document(
id: map["$id"] as! String,
collectionId: map["$collectionId"] as! String,
databaseId: map["$databaseId"] as! String,
createdAt: map["$createdAt"] as! String,
updatedAt: map["$updatedAt"] as! String,
permissions: map["$permissions"] as! [String],
id: map["$id"] as? String ?? "",
collectionId: map["$collectionId"] as? String ?? "",
databaseId: map["$databaseId"] as? String ?? "",
createdAt: map["$createdAt"] as? String ?? "",
updatedAt: map["$updatedAt"] as? String ?? "",
permissions: map["$permissions"] as? [String] ?? [],
data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: []))
)
}
Expand Down
17 changes: 17 additions & 0 deletions docs/examples/databases/upsert-document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Appwrite

let client = Client()
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>") // Your project ID
.setSession("") // The user session to authenticate with

let databases = Databases(client)

let document = try await databases.upsertDocument(
databaseId: "<DATABASE_ID>",
collectionId: "<COLLECTION_ID>",
documentId: "<DOCUMENT_ID>",
data: [:],
permissions: ["read("any")"] // optional
)