From 184e784cd9db082fa95351deb93f77cc62a12376 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Mar 2026 12:58:06 +0000 Subject: [PATCH 1/6] feat: update Apple SDK to 14.2.0 * Added impersonation helpers to set impersonation headers. * Added `DocumentsDB` service with documents and transactions APIs. * Added `upsertDocuments` overloads supporting generic document types. * Deprecated old `upsertDocuments` in favor of generic variant. * Updated API version badge to 1.9.0 in README. * Updated compatibility note to server version 1.9.x in README. --- CHANGELOG.md | 12 +- README.md | 6 +- Sources/Appwrite/Client.swift | 59 +- Sources/Appwrite/Services/Databases.swift | 80 ++ Sources/Appwrite/Services/DocumentsDB.swift | 896 ++++++++++++++++++ Sources/Appwrite/Services/VectorsDB.swift | 610 ++++++++++++ .../Appwrite/WebSockets/MessageHandler.swift | 31 +- .../Appwrite/WebSockets/WebSocketClient.swift | 4 +- Sources/AppwriteModels/Document.swift | 8 +- Sources/AppwriteModels/Log.swift | 6 +- Sources/AppwriteModels/Row.swift | 8 +- Sources/AppwriteModels/User.swift | 24 +- docs/examples/databases/upsert-documents.md | 17 + docs/examples/documentsdb/create-document.md | 24 + docs/examples/documentsdb/create-documents.md | 16 + .../examples/documentsdb/create-operations.md | 25 + .../documentsdb/create-transaction.md | 14 + .../decrement-document-attribute.md | 20 + docs/examples/documentsdb/delete-document.md | 17 + .../documentsdb/delete-transaction.md | 14 + docs/examples/documentsdb/get-document.md | 18 + docs/examples/documentsdb/get-transaction.md | 14 + .../increment-document-attribute.md | 20 + docs/examples/documentsdb/list-documents.md | 19 + .../examples/documentsdb/list-transactions.md | 14 + docs/examples/documentsdb/update-document.md | 19 + .../documentsdb/update-transaction.md | 16 + docs/examples/documentsdb/upsert-document.md | 19 + docs/examples/vectorsdb/create-document.md | 28 + docs/examples/vectorsdb/create-operations.md | 25 + docs/examples/vectorsdb/create-transaction.md | 14 + docs/examples/vectorsdb/delete-document.md | 17 + docs/examples/vectorsdb/delete-transaction.md | 14 + docs/examples/vectorsdb/get-document.md | 18 + docs/examples/vectorsdb/get-transaction.md | 14 + docs/examples/vectorsdb/list-documents.md | 19 + docs/examples/vectorsdb/list-transactions.md | 14 + docs/examples/vectorsdb/update-document.md | 19 + docs/examples/vectorsdb/update-transaction.md | 16 + docs/examples/vectorsdb/upsert-document.md | 19 + example-swiftui/Shared/ExampleViewModel.swift | 2 +- .../UIKitExample/ViewController.swift | 2 +- 42 files changed, 2202 insertions(+), 49 deletions(-) create mode 100644 Sources/Appwrite/Services/DocumentsDB.swift create mode 100644 Sources/Appwrite/Services/VectorsDB.swift create mode 100644 docs/examples/databases/upsert-documents.md create mode 100644 docs/examples/documentsdb/create-document.md create mode 100644 docs/examples/documentsdb/create-documents.md create mode 100644 docs/examples/documentsdb/create-operations.md create mode 100644 docs/examples/documentsdb/create-transaction.md create mode 100644 docs/examples/documentsdb/decrement-document-attribute.md create mode 100644 docs/examples/documentsdb/delete-document.md create mode 100644 docs/examples/documentsdb/delete-transaction.md create mode 100644 docs/examples/documentsdb/get-document.md create mode 100644 docs/examples/documentsdb/get-transaction.md create mode 100644 docs/examples/documentsdb/increment-document-attribute.md create mode 100644 docs/examples/documentsdb/list-documents.md create mode 100644 docs/examples/documentsdb/list-transactions.md create mode 100644 docs/examples/documentsdb/update-document.md create mode 100644 docs/examples/documentsdb/update-transaction.md create mode 100644 docs/examples/documentsdb/upsert-document.md create mode 100644 docs/examples/vectorsdb/create-document.md create mode 100644 docs/examples/vectorsdb/create-operations.md create mode 100644 docs/examples/vectorsdb/create-transaction.md create mode 100644 docs/examples/vectorsdb/delete-document.md create mode 100644 docs/examples/vectorsdb/delete-transaction.md create mode 100644 docs/examples/vectorsdb/get-document.md create mode 100644 docs/examples/vectorsdb/get-transaction.md create mode 100644 docs/examples/vectorsdb/list-documents.md create mode 100644 docs/examples/vectorsdb/list-transactions.md create mode 100644 docs/examples/vectorsdb/update-document.md create mode 100644 docs/examples/vectorsdb/update-transaction.md create mode 100644 docs/examples/vectorsdb/upsert-document.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ea7afa..a5d2f10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Change Log -## 15.0.0 +## 14.2.0 -* Breaking: RealtimeChannel API required explicit IDs and threw errors. -* Added ttl parameter to listDocuments and listRows. -* Updated compatibility notes to latest server and SDK version. -* Updated Document and Row comments for clarity. +* Added impersonation helpers to set impersonation headers. +* Added `DocumentsDB` service with documents and transactions APIs. +* Added `upsertDocuments` overloads supporting generic document types. +* Deprecated old `upsertDocuments` in favor of generic variant. +* Updated API version badge to 1.9.0 in README. +* Updated compatibility note to server version 1.9.x in README. ## 14.1.0 diff --git a/README.md b/README.md index a87adfa..14a9e8b 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ ![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-apple.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.8.1-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.9.0-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) -**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-apple/releases).** +**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-apple/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Apple SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "15.0.0"), + .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "14.2.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 1cedc67..51755d1 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -1,6 +1,8 @@ import NIO import NIOCore +#if canImport(NIOFoundationCompat) import NIOFoundationCompat +#endif import NIOSSL import Foundation import AsyncHTTPClient @@ -24,8 +26,8 @@ open class Client { "x-sdk-name": "Apple", "x-sdk-platform": "client", "x-sdk-language": "apple", - "x-sdk-version": "15.0.0", - "x-appwrite-response-format": "1.8.0" + "x-sdk-version": "14.2.0", + "x-appwrite-response-format": "1.9.0" ] internal var config: [String: String] = [:] @@ -162,6 +164,51 @@ open class Client { return self } + /// + /// Set ImpersonateUserId + /// + /// Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + /// + /// @param String value + /// + /// @return Client + /// + open func setImpersonateUserId(_ value: String) -> Client { + config["impersonateuserid"] = value + _ = addHeader(key: "X-Appwrite-Impersonate-User-Id", value: value) + return self + } + + /// + /// Set ImpersonateUserEmail + /// + /// Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + /// + /// @param String value + /// + /// @return Client + /// + open func setImpersonateUserEmail(_ value: String) -> Client { + config["impersonateuseremail"] = value + _ = addHeader(key: "X-Appwrite-Impersonate-User-Email", value: value) + return self + } + + /// + /// Set ImpersonateUserPhone + /// + /// Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + /// + /// @param String value + /// + /// @return Client + /// + open func setImpersonateUserPhone(_ value: String) -> Client { + config["impersonateuserphone"] = value + _ = addHeader(key: "X-Appwrite-Impersonate-User-Phone", value: value) + return self + } + /// /// Set self signed @@ -378,7 +425,7 @@ open class Client { if data.readableBytes == 0 { return true as! T } - let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any] + let dict = try JSONSerialization.jsonObject(with: Data(data.readableBytesView)) as? [String: Any] return converter?(dict!) ?? dict! as! T } @@ -388,7 +435,7 @@ open class Client { var responseString = "" do { - let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any] + let dict = try JSONSerialization.jsonObject(with: Data(data.readableBytesView)) as? [String: Any] message = dict?["message"] as? String ?? response.status.reasonPhrase type = dict?["type"] as? String ?? "" @@ -420,9 +467,9 @@ open class Client { switch(input.sourceType) { case "path": - input.data = ByteBuffer(data: try! Data(contentsOf: URL(fileURLWithPath: input.path))) + input.data = ByteBuffer(bytes: try! Data(contentsOf: URL(fileURLWithPath: input.path))) case "data": - input.data = ByteBuffer(data: input.data as! Data) + input.data = ByteBuffer(bytes: input.data as! Data) default: break } diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 989e457..7438971 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -383,6 +383,86 @@ open class Databases: Service { ) } + /// + /// 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) + /// API or directly from your database console. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documents: [Any] + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DocumentList + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRows` instead.") + open func upsertDocuments( + databaseId: String, + collectionId: String, + documents: [Any], + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.DocumentList { + let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "documents": documents, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.DocumentList = { response in + return AppwriteModels.DocumentList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// 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) + /// API or directly from your database console. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documents: [Any] + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DocumentList + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRows` instead.") + open func upsertDocuments( + databaseId: String, + collectionId: String, + documents: [Any], + transactionId: String? = nil + ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { + return try await upsertDocuments( + databaseId: databaseId, + collectionId: collectionId, + documents: documents, + transactionId: transactionId, + nestedType: [String: AnyCodable].self + ) + } + /// /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. diff --git a/Sources/Appwrite/Services/DocumentsDB.swift b/Sources/Appwrite/Services/DocumentsDB.swift new file mode 100644 index 0000000..73f54c7 --- /dev/null +++ b/Sources/Appwrite/Services/DocumentsDB.swift @@ -0,0 +1,896 @@ +import AsyncHTTPClient +import Foundation +import NIO +import JSONCodable +import AppwriteEnums +import AppwriteModels + +/// +open class DocumentsDB: Service { + + /// + /// - Parameters: + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.TransactionList + /// + open func listTransactions( + queries: [String]? = nil + ) async throws -> AppwriteModels.TransactionList { + let apiPath: String = "/documentsdb/transactions" + + let apiParams: [String: Any?] = [ + "queries": queries + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.TransactionList = { response in + return AppwriteModels.TransactionList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - ttl: Int (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Transaction + /// + open func createTransaction( + ttl: Int? = nil + ) async throws -> AppwriteModels.Transaction { + let apiPath: String = "/documentsdb/transactions" + + let apiParams: [String: Any?] = [ + "ttl": ttl + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Transaction = { response in + return AppwriteModels.Transaction.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - transactionId: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Transaction + /// + open func getTransaction( + transactionId: String + ) async throws -> AppwriteModels.Transaction { + let apiPath: String = "/documentsdb/transactions/{transactionId}" + .replacingOccurrences(of: "{transactionId}", with: transactionId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.Transaction = { response in + return AppwriteModels.Transaction.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - transactionId: String + /// - commit: Bool (optional) + /// - rollback: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Transaction + /// + open func updateTransaction( + transactionId: String, + commit: Bool? = nil, + rollback: Bool? = nil + ) async throws -> AppwriteModels.Transaction { + let apiPath: String = "/documentsdb/transactions/{transactionId}" + .replacingOccurrences(of: "{transactionId}", with: transactionId) + + let apiParams: [String: Any?] = [ + "commit": commit, + "rollback": rollback + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Transaction = { response in + return AppwriteModels.Transaction.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - transactionId: String + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteTransaction( + transactionId: String + ) async throws -> Any { + let apiPath: String = "/documentsdb/transactions/{transactionId}" + .replacingOccurrences(of: "{transactionId}", with: transactionId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// - Parameters: + /// - transactionId: String + /// - operations: [Any] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Transaction + /// + open func createOperations( + transactionId: String, + operations: [Any]? = nil + ) async throws -> AppwriteModels.Transaction { + let apiPath: String = "/documentsdb/transactions/{transactionId}/operations" + .replacingOccurrences(of: "{transactionId}", with: transactionId) + + let apiParams: [String: Any?] = [ + "operations": operations + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Transaction = { response in + return AppwriteModels.Transaction.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get a list of all the user's documents in a given collection. You can use + /// the query params to filter your results. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - queries: [String] (optional) + /// - transactionId: String (optional) + /// - total: Bool (optional) + /// - ttl: Int (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DocumentList + /// + open func listDocuments( + databaseId: String, + collectionId: String, + queries: [String]? = nil, + transactionId: String? = nil, + total: Bool? = nil, + ttl: Int? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.DocumentList { + let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "queries": queries, + "transactionId": transactionId, + "total": total, + "ttl": ttl + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.DocumentList = { response in + return AppwriteModels.DocumentList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get a list of all the user's documents in a given collection. You can use + /// the query params to filter your results. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - queries: [String] (optional) + /// - transactionId: String (optional) + /// - total: Bool (optional) + /// - ttl: Int (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DocumentList + /// + open func listDocuments( + databaseId: String, + collectionId: String, + queries: [String]? = nil, + transactionId: String? = nil, + total: Bool? = nil, + ttl: Int? = nil + ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { + return try await listDocuments( + databaseId: databaseId, + collectionId: collectionId, + queries: queries, + transactionId: transactionId, + total: total, + ttl: ttl, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Create a new Document. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func createDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any, + permissions: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "documentId": documentId, + "data": data, + "permissions": permissions + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Document = { response in + return AppwriteModels.Document.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a new Document. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func createDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any, + permissions: [String]? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await createDocument( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + data: data, + permissions: permissions, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// 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#documentsDBCreateCollection) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documents: [Any] + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DocumentList + /// + open func createDocuments( + databaseId: String, + collectionId: String, + documents: [Any], + nestedType: T.Type + ) async throws -> AppwriteModels.DocumentList { + let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "documents": documents + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.DocumentList = { response in + return AppwriteModels.DocumentList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// 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#documentsDBCreateCollection) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documents: [Any] + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DocumentList + /// + open func createDocuments( + databaseId: String, + collectionId: String, + documents: [Any] + ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { + return try await createDocuments( + databaseId: databaseId, + collectionId: collectionId, + documents: documents, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Get a document by its unique ID. This endpoint response returns a JSON + /// object with the document data. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - queries: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func getDocument( + databaseId: String, + collectionId: String, + documentId: String, + queries: [String]? = nil, + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{documentId}", with: documentId) + + let apiParams: [String: Any?] = [ + "queries": queries, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.Document = { response in + return AppwriteModels.Document.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get a document by its unique ID. This endpoint response returns a JSON + /// object with the document data. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - queries: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func getDocument( + databaseId: String, + collectionId: String, + documentId: String, + queries: [String]? = nil, + transactionId: String? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await getDocument( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + queries: queries, + transactionId: transactionId, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// 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#documentsDBCreateCollection) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any? = nil, + permissions: [String]? = nil, + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/documentsdb/{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, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Document = { 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 + ) + } + + /// + /// 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#documentsDBCreateCollection) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any? = nil, + permissions: [String]? = nil, + transactionId: String? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await upsertDocument( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + data: data, + permissions: permissions, + transactionId: transactionId, + 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. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func updateDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any? = nil, + permissions: [String]? = nil, + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/documentsdb/{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, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Document = { response in + return AppwriteModels.Document.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a document by its unique ID. Using the patch method you can pass + /// only specific fields that will get updated. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func updateDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any? = nil, + permissions: [String]? = nil, + transactionId: String? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await updateDocument( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + data: data, + permissions: permissions, + transactionId: transactionId, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Delete a document by its unique ID. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteDocument( + databaseId: String, + collectionId: String, + documentId: String, + transactionId: String? = nil + ) async throws -> Any { + let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{documentId}", with: documentId) + + let apiParams: [String: Any?] = [ + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// Decrement a specific column of a row by a given value. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - attribute: String + /// - value: Double (optional) + /// - min: Double (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func decrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = nil, + min: Double? = nil, + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{documentId}", with: documentId) + .replacingOccurrences(of: "{attribute}", with: attribute) + + let apiParams: [String: Any?] = [ + "value": value, + "min": min, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Document = { response in + return AppwriteModels.Document.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Decrement a specific column of a row by a given value. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - attribute: String + /// - value: Double (optional) + /// - min: Double (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func decrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = nil, + min: Double? = nil, + transactionId: String? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await decrementDocumentAttribute( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + attribute: attribute, + value: value, + min: min, + transactionId: transactionId, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Increment a specific column of a row by a given value. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - attribute: String + /// - value: Double (optional) + /// - max: Double (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func incrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = nil, + max: Double? = nil, + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{documentId}", with: documentId) + .replacingOccurrences(of: "{attribute}", with: attribute) + + let apiParams: [String: Any?] = [ + "value": value, + "max": max, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Document = { response in + return AppwriteModels.Document.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Increment a specific column of a row by a given value. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - attribute: String + /// - value: Double (optional) + /// - max: Double (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func incrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = nil, + max: Double? = nil, + transactionId: String? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await incrementDocumentAttribute( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + attribute: attribute, + value: value, + max: max, + transactionId: transactionId, + nestedType: [String: AnyCodable].self + ) + } + + +} \ No newline at end of file diff --git a/Sources/Appwrite/Services/VectorsDB.swift b/Sources/Appwrite/Services/VectorsDB.swift new file mode 100644 index 0000000..ec56788 --- /dev/null +++ b/Sources/Appwrite/Services/VectorsDB.swift @@ -0,0 +1,610 @@ +import AsyncHTTPClient +import Foundation +import NIO +import JSONCodable +import AppwriteEnums +import AppwriteModels + +/// +open class VectorsDB: Service { + + /// + /// - Parameters: + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.TransactionList + /// + open func listTransactions( + queries: [String]? = nil + ) async throws -> AppwriteModels.TransactionList { + let apiPath: String = "/vectorsdb/transactions" + + let apiParams: [String: Any?] = [ + "queries": queries + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.TransactionList = { response in + return AppwriteModels.TransactionList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - ttl: Int (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Transaction + /// + open func createTransaction( + ttl: Int? = nil + ) async throws -> AppwriteModels.Transaction { + let apiPath: String = "/vectorsdb/transactions" + + let apiParams: [String: Any?] = [ + "ttl": ttl + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Transaction = { response in + return AppwriteModels.Transaction.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - transactionId: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Transaction + /// + open func getTransaction( + transactionId: String + ) async throws -> AppwriteModels.Transaction { + let apiPath: String = "/vectorsdb/transactions/{transactionId}" + .replacingOccurrences(of: "{transactionId}", with: transactionId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.Transaction = { response in + return AppwriteModels.Transaction.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - transactionId: String + /// - commit: Bool (optional) + /// - rollback: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Transaction + /// + open func updateTransaction( + transactionId: String, + commit: Bool? = nil, + rollback: Bool? = nil + ) async throws -> AppwriteModels.Transaction { + let apiPath: String = "/vectorsdb/transactions/{transactionId}" + .replacingOccurrences(of: "{transactionId}", with: transactionId) + + let apiParams: [String: Any?] = [ + "commit": commit, + "rollback": rollback + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Transaction = { response in + return AppwriteModels.Transaction.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - transactionId: String + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteTransaction( + transactionId: String + ) async throws -> Any { + let apiPath: String = "/vectorsdb/transactions/{transactionId}" + .replacingOccurrences(of: "{transactionId}", with: transactionId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// - Parameters: + /// - transactionId: String + /// - operations: [Any] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Transaction + /// + open func createOperations( + transactionId: String, + operations: [Any]? = nil + ) async throws -> AppwriteModels.Transaction { + let apiPath: String = "/vectorsdb/transactions/{transactionId}/operations" + .replacingOccurrences(of: "{transactionId}", with: transactionId) + + let apiParams: [String: Any?] = [ + "operations": operations + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Transaction = { response in + return AppwriteModels.Transaction.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - queries: [String] (optional) + /// - transactionId: String (optional) + /// - total: Bool (optional) + /// - ttl: Int (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DocumentList + /// + open func listDocuments( + databaseId: String, + collectionId: String, + queries: [String]? = nil, + transactionId: String? = nil, + total: Bool? = nil, + ttl: Int? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.DocumentList { + let apiPath: String = "/vectorsdb/{databaseId}/collections/{collectionId}/documents" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "queries": queries, + "transactionId": transactionId, + "total": total, + "ttl": ttl + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.DocumentList = { response in + return AppwriteModels.DocumentList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - queries: [String] (optional) + /// - transactionId: String (optional) + /// - total: Bool (optional) + /// - ttl: Int (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DocumentList + /// + open func listDocuments( + databaseId: String, + collectionId: String, + queries: [String]? = nil, + transactionId: String? = nil, + total: Bool? = nil, + ttl: Int? = nil + ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { + return try await listDocuments( + databaseId: databaseId, + collectionId: collectionId, + queries: queries, + transactionId: transactionId, + total: total, + ttl: ttl, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func createDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any, + permissions: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/vectorsdb/{databaseId}/collections/{collectionId}/documents" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "documentId": documentId, + "data": data, + "permissions": permissions + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Document = { response in + return AppwriteModels.Document.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func createDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any, + permissions: [String]? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await createDocument( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + data: data, + permissions: permissions, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - queries: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func getDocument( + databaseId: String, + collectionId: String, + documentId: String, + queries: [String]? = nil, + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{documentId}", with: documentId) + + let apiParams: [String: Any?] = [ + "queries": queries, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.Document = { response in + return AppwriteModels.Document.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - queries: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func getDocument( + databaseId: String, + collectionId: String, + documentId: String, + queries: [String]? = nil, + transactionId: String? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await getDocument( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + queries: queries, + transactionId: transactionId, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any? = nil, + permissions: [String]? = nil, + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/vectorsdb/{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, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Document = { 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 + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any? = nil, + permissions: [String]? = nil, + transactionId: String? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await upsertDocument( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + data: data, + permissions: permissions, + transactionId: transactionId, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func updateDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any? = nil, + permissions: [String]? = nil, + transactionId: String? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Document { + let apiPath: String = "/vectorsdb/{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, + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Document = { response in + return AppwriteModels.Document.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Document + /// + open func updateDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any? = nil, + permissions: [String]? = nil, + transactionId: String? = nil + ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { + return try await updateDocument( + databaseId: databaseId, + collectionId: collectionId, + documentId: documentId, + data: data, + permissions: permissions, + transactionId: transactionId, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - documentId: String + /// - transactionId: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteDocument( + databaseId: String, + collectionId: String, + documentId: String, + transactionId: String? = nil + ) async throws -> Any { + let apiPath: String = "/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{documentId}", with: documentId) + + let apiParams: [String: Any?] = [ + "transactionId": transactionId + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + +} \ No newline at end of file diff --git a/Sources/Appwrite/WebSockets/MessageHandler.swift b/Sources/Appwrite/WebSockets/MessageHandler.swift index 330b526..89f1193 100644 --- a/Sources/Appwrite/WebSockets/MessageHandler.swift +++ b/Sources/Appwrite/WebSockets/MessageHandler.swift @@ -1,5 +1,8 @@ import Foundation import NIO +#if canImport(NIOFoundationCompat) +import NIOFoundationCompat +#endif import NIOHTTP1 import NIOWebSocket @@ -18,7 +21,7 @@ class MessageHandler { self.client = client self.buffer = ByteBufferAllocator().buffer(capacity: 0) } - + private func unmaskedData(frame: WebSocketFrame) -> ByteBuffer { var frameData = frame.data if let maskingKey = frame.maskKey { @@ -31,7 +34,7 @@ class MessageHandler { extension MessageHandler: ChannelInboundHandler, RemovableChannelHandler { typealias InboundIn = WebSocketFrame - + public func channelRead(context: ChannelHandlerContext, data: NIOAny) { let frame = self.unwrapInboundIn(data) switch frame.opcode { @@ -56,18 +59,14 @@ extension MessageHandler: ChannelInboundHandler, RemovableChannelHandler { case .binary: let data = unmaskedData(frame: frame) if frame.fin { - guard let binaryData = data.getData(at: 0, length: data.readableBytes) else { - return - } + let binaryData = Data(data.readableBytesView) if let delegate = client.delegate { try! delegate.onMessage(data: binaryData) } else { client.onBinaryMessage(binaryData) } } else { - guard let binaryData = data.getData(at: 0, length: data.readableBytes) else { - return - } + let binaryData = Data(data.readableBytesView) binaryBuffer = binaryData } case .continuation: @@ -92,9 +91,7 @@ extension MessageHandler: ChannelInboundHandler, RemovableChannelHandler { } } else { if frame.fin { - guard let binaryData = data.getData(at: 0, length: data.readableBytes) else { - return - } + let binaryData = Data(data.readableBytesView) binaryBuffer.append(binaryData) if let delegate = client.delegate { try! delegate.onMessage(data: binaryBuffer) @@ -102,9 +99,7 @@ extension MessageHandler: ChannelInboundHandler, RemovableChannelHandler { client.onBinaryMessage(binaryBuffer) } } else { - guard let binaryData = data.getData(at: 0, length: data.readableBytes) else { - return - } + let binaryData = Data(data.readableBytesView) binaryBuffer.append(binaryData) } } @@ -114,18 +109,18 @@ extension MessageHandler: ChannelInboundHandler, RemovableChannelHandler { } let data = frame.data if !client.closeSent { - client.close(data: frame.data.getData(at: 0, length: frame.data.readableBytes) ?? Data()) + client.close(data: Data(frame.data.readableBytesView)) } if let delegate = client.delegate { - delegate.onClose(channel: context.channel, data: data.getData(at: 0, length: data.readableBytes)!) + delegate.onClose(channel: context.channel, data: Data(data.readableBytesView)) } else { - client.onClose(context.channel, data.getData(at: 0, length: data.readableBytes)!) + client.onClose(context.channel, Data(data.readableBytesView)) } default: break } } - + public func errorCaught(context: ChannelHandlerContext, error: Swift.Error) { if client.delegate != nil { try! client.delegate?.onError(error: error, status: nil) diff --git a/Sources/Appwrite/WebSockets/WebSocketClient.swift b/Sources/Appwrite/WebSockets/WebSocketClient.swift index 7c004d2..8e1b96e 100644 --- a/Sources/Appwrite/WebSockets/WebSocketClient.swift +++ b/Sources/Appwrite/WebSockets/WebSocketClient.swift @@ -1,9 +1,11 @@ import Foundation import NIO +#if canImport(NIOFoundationCompat) +import NIOFoundationCompat +#endif import NIOHTTP1 import NIOWebSocket import Dispatch -import NIOFoundationCompat import NIOSSL public let WEBSOCKET_LOCKER_QUEUE = "SyncLocker" diff --git a/Sources/AppwriteModels/Document.swift b/Sources/AppwriteModels/Document.swift index cbd8c6f..35d919e 100644 --- a/Sources/AppwriteModels/Document.swift +++ b/Sources/AppwriteModels/Document.swift @@ -18,7 +18,7 @@ open class Document: Codable { /// Document ID. public let id: String /// Document sequence ID. - public let sequence: Int + public let sequence: String /// Collection ID. public let collectionId: String /// Database ID. @@ -34,7 +34,7 @@ open class Document: Codable { init( id: String, - sequence: Int, + sequence: String, collectionId: String, databaseId: String, createdAt: String, @@ -56,7 +56,7 @@ open class Document: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) self.id = try container.decode(String.self, forKey: .id) - self.sequence = try container.decode(Int.self, forKey: .sequence) + self.sequence = try container.decode(String.self, forKey: .sequence) self.collectionId = try container.decode(String.self, forKey: .collectionId) self.databaseId = try container.decode(String.self, forKey: .databaseId) self.createdAt = try container.decode(String.self, forKey: .createdAt) @@ -94,7 +94,7 @@ open class Document: Codable { public static func from(map: [String: Any] ) -> Document { return Document( id: map["$id"] as? String ?? "", - sequence: map["$sequence"] as? Int ?? 0, + sequence: map["$sequence"] as? String ?? "", collectionId: map["$collectionId"] as? String ?? "", databaseId: map["$databaseId"] as? String ?? "", createdAt: map["$createdAt"] as? String ?? "", diff --git a/Sources/AppwriteModels/Log.swift b/Sources/AppwriteModels/Log.swift index ae5a3a5..79dde4f 100644 --- a/Sources/AppwriteModels/Log.swift +++ b/Sources/AppwriteModels/Log.swift @@ -30,11 +30,11 @@ open class Log: Codable { /// Event name. public let event: String - /// User ID. + /// User ID of the actor recorded for this log. During impersonation, this is the original impersonator, not the impersonated target user. public let userId: String - /// User Email. + /// User email of the actor recorded for this log. During impersonation, this is the original impersonator. public let userEmail: String - /// User Name. + /// User name of the actor recorded for this log. During impersonation, this is the original impersonator. public let userName: String /// API mode when event triggered. public let mode: String diff --git a/Sources/AppwriteModels/Row.swift b/Sources/AppwriteModels/Row.swift index d75e9e2..3bb3e1b 100644 --- a/Sources/AppwriteModels/Row.swift +++ b/Sources/AppwriteModels/Row.swift @@ -18,7 +18,7 @@ open class Row: Codable { /// Row ID. public let id: String /// Row sequence ID. - public let sequence: Int + public let sequence: String /// Table ID. public let tableId: String /// Database ID. @@ -34,7 +34,7 @@ open class Row: Codable { init( id: String, - sequence: Int, + sequence: String, tableId: String, databaseId: String, createdAt: String, @@ -56,7 +56,7 @@ open class Row: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) self.id = try container.decode(String.self, forKey: .id) - self.sequence = try container.decode(Int.self, forKey: .sequence) + self.sequence = try container.decode(String.self, forKey: .sequence) self.tableId = try container.decode(String.self, forKey: .tableId) self.databaseId = try container.decode(String.self, forKey: .databaseId) self.createdAt = try container.decode(String.self, forKey: .createdAt) @@ -94,7 +94,7 @@ open class Row: Codable { public static func from(map: [String: Any] ) -> Row { return Row( id: map["$id"] as! String, - sequence: map["$sequence"] as! Int, + sequence: map["$sequence"] as! String, tableId: map["$tableId"] as! String, databaseId: map["$databaseId"] as! String, createdAt: map["$createdAt"] as! String, diff --git a/Sources/AppwriteModels/User.swift b/Sources/AppwriteModels/User.swift index 186da68..9ed1bdd 100644 --- a/Sources/AppwriteModels/User.swift +++ b/Sources/AppwriteModels/User.swift @@ -24,6 +24,8 @@ open class User: Codable { case prefs = "prefs" case targets = "targets" case accessedAt = "accessedAt" + case impersonator = "impersonator" + case impersonatorUserId = "impersonatorUserId" } /// User ID. @@ -64,6 +66,10 @@ open class User: Codable { public let targets: [Target] /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. public let accessedAt: String + /// Whether the user can impersonate other users. + public let impersonator: Bool? + /// ID of the original actor performing the impersonation. Present only when the current request is impersonating another user. Internal audit logs attribute the action to this user, while the impersonated target is recorded only in internal audit payload data. + public let impersonatorUserId: String? init( id: String, @@ -84,7 +90,9 @@ open class User: Codable { mfa: Bool, prefs: Preferences, targets: [Target], - accessedAt: String + accessedAt: String, + impersonator: Bool?, + impersonatorUserId: String? ) { self.id = id self.createdAt = createdAt @@ -105,6 +113,8 @@ open class User: Codable { self.prefs = prefs self.targets = targets self.accessedAt = accessedAt + self.impersonator = impersonator + self.impersonatorUserId = impersonatorUserId } public required init(from decoder: Decoder) throws { @@ -129,6 +139,8 @@ open class User: Codable { self.prefs = try container.decode(Preferences.self, forKey: .prefs) self.targets = try container.decode([Target].self, forKey: .targets) self.accessedAt = try container.decode(String.self, forKey: .accessedAt) + self.impersonator = try container.decodeIfPresent(Bool.self, forKey: .impersonator) + self.impersonatorUserId = try container.decodeIfPresent(String.self, forKey: .impersonatorUserId) } public func encode(to encoder: Encoder) throws { @@ -153,6 +165,8 @@ open class User: Codable { try container.encode(prefs, forKey: .prefs) try container.encode(targets, forKey: .targets) try container.encode(accessedAt, forKey: .accessedAt) + try container.encodeIfPresent(impersonator, forKey: .impersonator) + try container.encodeIfPresent(impersonatorUserId, forKey: .impersonatorUserId) } public func toMap() -> [String: Any] { @@ -175,7 +189,9 @@ open class User: Codable { "mfa": mfa as Any, "prefs": prefs.toMap() as Any, "targets": targets.map { $0.toMap() } as Any, - "accessedAt": accessedAt as Any + "accessedAt": accessedAt as Any, + "impersonator": impersonator as Any, + "impersonatorUserId": impersonatorUserId as Any ] } @@ -199,7 +215,9 @@ open class User: Codable { mfa: map["mfa"] as! Bool, prefs: Preferences.from(map: map["prefs"] as! [String: Any]), targets: (map["targets"] as! [[String: Any]]).map { Target.from(map: $0) }, - accessedAt: map["accessedAt"] as! String + accessedAt: map["accessedAt"] as! String, + impersonator: map["impersonator"] as? Bool, + impersonatorUserId: map["impersonatorUserId"] as? String ) } } diff --git a/docs/examples/databases/upsert-documents.md b/docs/examples/databases/upsert-documents.md new file mode 100644 index 0000000..1ec3add --- /dev/null +++ b/docs/examples/databases/upsert-documents.md @@ -0,0 +1,17 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let databases = Databases(client) + +let documentList = try await databases.upsertDocuments( + databaseId: "", + collectionId: "", + documents: [], + transactionId: "" // optional +) + +``` diff --git a/docs/examples/documentsdb/create-document.md b/docs/examples/documentsdb/create-document.md new file mode 100644 index 0000000..b0cda1a --- /dev/null +++ b/docs/examples/documentsdb/create-document.md @@ -0,0 +1,24 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let document = try await documentsDB.createDocument( + databaseId: "", + collectionId: "", + documentId: "", + data: [ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 30, + "isAdmin": false + ], + permissions: [Permission.read(Role.any())] // optional +) + +``` diff --git a/docs/examples/documentsdb/create-documents.md b/docs/examples/documentsdb/create-documents.md new file mode 100644 index 0000000..edf3a9e --- /dev/null +++ b/docs/examples/documentsdb/create-documents.md @@ -0,0 +1,16 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let documentList = try await documentsDB.createDocuments( + databaseId: "", + collectionId: "", + documents: [] +) + +``` diff --git a/docs/examples/documentsdb/create-operations.md b/docs/examples/documentsdb/create-operations.md new file mode 100644 index 0000000..c1bc948 --- /dev/null +++ b/docs/examples/documentsdb/create-operations.md @@ -0,0 +1,25 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let transaction = try await documentsDB.createOperations( + transactionId: "", + operations: [ + { + "action": "create", + "databaseId": "", + "collectionId": "", + "documentId": "", + "data": { + "name": "Walter O'Brien" + } + } + ] // optional +) + +``` diff --git a/docs/examples/documentsdb/create-transaction.md b/docs/examples/documentsdb/create-transaction.md new file mode 100644 index 0000000..88030b7 --- /dev/null +++ b/docs/examples/documentsdb/create-transaction.md @@ -0,0 +1,14 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let transaction = try await documentsDB.createTransaction( + ttl: 60 // optional +) + +``` diff --git a/docs/examples/documentsdb/decrement-document-attribute.md b/docs/examples/documentsdb/decrement-document-attribute.md new file mode 100644 index 0000000..d0e1a0e --- /dev/null +++ b/docs/examples/documentsdb/decrement-document-attribute.md @@ -0,0 +1,20 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let document = try await documentsDB.decrementDocumentAttribute( + databaseId: "", + collectionId: "", + documentId: "", + attribute: "", + value: 0, // optional + min: 0, // optional + transactionId: "" // optional +) + +``` diff --git a/docs/examples/documentsdb/delete-document.md b/docs/examples/documentsdb/delete-document.md new file mode 100644 index 0000000..10eef17 --- /dev/null +++ b/docs/examples/documentsdb/delete-document.md @@ -0,0 +1,17 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let result = try await documentsDB.deleteDocument( + databaseId: "", + collectionId: "", + documentId: "", + transactionId: "" // optional +) + +``` diff --git a/docs/examples/documentsdb/delete-transaction.md b/docs/examples/documentsdb/delete-transaction.md new file mode 100644 index 0000000..ca1c9bb --- /dev/null +++ b/docs/examples/documentsdb/delete-transaction.md @@ -0,0 +1,14 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let result = try await documentsDB.deleteTransaction( + transactionId: "" +) + +``` diff --git a/docs/examples/documentsdb/get-document.md b/docs/examples/documentsdb/get-document.md new file mode 100644 index 0000000..504bbf1 --- /dev/null +++ b/docs/examples/documentsdb/get-document.md @@ -0,0 +1,18 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let document = try await documentsDB.getDocument( + databaseId: "", + collectionId: "", + documentId: "", + queries: [], // optional + transactionId: "" // optional +) + +``` diff --git a/docs/examples/documentsdb/get-transaction.md b/docs/examples/documentsdb/get-transaction.md new file mode 100644 index 0000000..4435dce --- /dev/null +++ b/docs/examples/documentsdb/get-transaction.md @@ -0,0 +1,14 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let transaction = try await documentsDB.getTransaction( + transactionId: "" +) + +``` diff --git a/docs/examples/documentsdb/increment-document-attribute.md b/docs/examples/documentsdb/increment-document-attribute.md new file mode 100644 index 0000000..9d92521 --- /dev/null +++ b/docs/examples/documentsdb/increment-document-attribute.md @@ -0,0 +1,20 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let document = try await documentsDB.incrementDocumentAttribute( + databaseId: "", + collectionId: "", + documentId: "", + attribute: "", + value: 0, // optional + max: 0, // optional + transactionId: "" // optional +) + +``` diff --git a/docs/examples/documentsdb/list-documents.md b/docs/examples/documentsdb/list-documents.md new file mode 100644 index 0000000..81768bc --- /dev/null +++ b/docs/examples/documentsdb/list-documents.md @@ -0,0 +1,19 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let documentList = try await documentsDB.listDocuments( + databaseId: "", + collectionId: "", + queries: [], // optional + transactionId: "", // optional + total: false, // optional + ttl: 0 // optional +) + +``` diff --git a/docs/examples/documentsdb/list-transactions.md b/docs/examples/documentsdb/list-transactions.md new file mode 100644 index 0000000..0fe1ca7 --- /dev/null +++ b/docs/examples/documentsdb/list-transactions.md @@ -0,0 +1,14 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let transactionList = try await documentsDB.listTransactions( + queries: [] // optional +) + +``` diff --git a/docs/examples/documentsdb/update-document.md b/docs/examples/documentsdb/update-document.md new file mode 100644 index 0000000..250ecd7 --- /dev/null +++ b/docs/examples/documentsdb/update-document.md @@ -0,0 +1,19 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let document = try await documentsDB.updateDocument( + databaseId: "", + collectionId: "", + documentId: "", + data: [:], // optional + permissions: [Permission.read(Role.any())], // optional + transactionId: "" // optional +) + +``` diff --git a/docs/examples/documentsdb/update-transaction.md b/docs/examples/documentsdb/update-transaction.md new file mode 100644 index 0000000..1ea869b --- /dev/null +++ b/docs/examples/documentsdb/update-transaction.md @@ -0,0 +1,16 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let transaction = try await documentsDB.updateTransaction( + transactionId: "", + commit: false, // optional + rollback: false // optional +) + +``` diff --git a/docs/examples/documentsdb/upsert-document.md b/docs/examples/documentsdb/upsert-document.md new file mode 100644 index 0000000..cede61c --- /dev/null +++ b/docs/examples/documentsdb/upsert-document.md @@ -0,0 +1,19 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let documentsDB = DocumentsDB(client) + +let document = try await documentsDB.upsertDocument( + databaseId: "", + collectionId: "", + documentId: "", + data: [:], // optional + permissions: [Permission.read(Role.any())], // optional + transactionId: "" // optional +) + +``` diff --git a/docs/examples/vectorsdb/create-document.md b/docs/examples/vectorsdb/create-document.md new file mode 100644 index 0000000..3b2ad89 --- /dev/null +++ b/docs/examples/vectorsdb/create-document.md @@ -0,0 +1,28 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let document = try await vectorsDB.createDocument( + databaseId: "", + collectionId: "", + documentId: "", + data: [ + "embeddings": [ + "0": 0.12, + "1": -0.55, + "2": 0.88, + "3": 1.02 + ], + "metadata": [ + "key": "value" + ] + ], + permissions: [Permission.read(Role.any())] // optional +) + +``` diff --git a/docs/examples/vectorsdb/create-operations.md b/docs/examples/vectorsdb/create-operations.md new file mode 100644 index 0000000..c90069a --- /dev/null +++ b/docs/examples/vectorsdb/create-operations.md @@ -0,0 +1,25 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let transaction = try await vectorsDB.createOperations( + transactionId: "", + operations: [ + { + "action": "create", + "databaseId": "", + "collectionId": "", + "documentId": "", + "data": { + "name": "Walter O'Brien" + } + } + ] // optional +) + +``` diff --git a/docs/examples/vectorsdb/create-transaction.md b/docs/examples/vectorsdb/create-transaction.md new file mode 100644 index 0000000..4cdabc2 --- /dev/null +++ b/docs/examples/vectorsdb/create-transaction.md @@ -0,0 +1,14 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let transaction = try await vectorsDB.createTransaction( + ttl: 60 // optional +) + +``` diff --git a/docs/examples/vectorsdb/delete-document.md b/docs/examples/vectorsdb/delete-document.md new file mode 100644 index 0000000..dd80e83 --- /dev/null +++ b/docs/examples/vectorsdb/delete-document.md @@ -0,0 +1,17 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let result = try await vectorsDB.deleteDocument( + databaseId: "", + collectionId: "", + documentId: "", + transactionId: "" // optional +) + +``` diff --git a/docs/examples/vectorsdb/delete-transaction.md b/docs/examples/vectorsdb/delete-transaction.md new file mode 100644 index 0000000..ff7538a --- /dev/null +++ b/docs/examples/vectorsdb/delete-transaction.md @@ -0,0 +1,14 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let result = try await vectorsDB.deleteTransaction( + transactionId: "" +) + +``` diff --git a/docs/examples/vectorsdb/get-document.md b/docs/examples/vectorsdb/get-document.md new file mode 100644 index 0000000..e181437 --- /dev/null +++ b/docs/examples/vectorsdb/get-document.md @@ -0,0 +1,18 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let document = try await vectorsDB.getDocument( + databaseId: "", + collectionId: "", + documentId: "", + queries: [], // optional + transactionId: "" // optional +) + +``` diff --git a/docs/examples/vectorsdb/get-transaction.md b/docs/examples/vectorsdb/get-transaction.md new file mode 100644 index 0000000..4b8fd1a --- /dev/null +++ b/docs/examples/vectorsdb/get-transaction.md @@ -0,0 +1,14 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let transaction = try await vectorsDB.getTransaction( + transactionId: "" +) + +``` diff --git a/docs/examples/vectorsdb/list-documents.md b/docs/examples/vectorsdb/list-documents.md new file mode 100644 index 0000000..c082c81 --- /dev/null +++ b/docs/examples/vectorsdb/list-documents.md @@ -0,0 +1,19 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let documentList = try await vectorsDB.listDocuments( + databaseId: "", + collectionId: "", + queries: [], // optional + transactionId: "", // optional + total: false, // optional + ttl: 0 // optional +) + +``` diff --git a/docs/examples/vectorsdb/list-transactions.md b/docs/examples/vectorsdb/list-transactions.md new file mode 100644 index 0000000..26aa4f4 --- /dev/null +++ b/docs/examples/vectorsdb/list-transactions.md @@ -0,0 +1,14 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let transactionList = try await vectorsDB.listTransactions( + queries: [] // optional +) + +``` diff --git a/docs/examples/vectorsdb/update-document.md b/docs/examples/vectorsdb/update-document.md new file mode 100644 index 0000000..f96706f --- /dev/null +++ b/docs/examples/vectorsdb/update-document.md @@ -0,0 +1,19 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let document = try await vectorsDB.updateDocument( + databaseId: "", + collectionId: "", + documentId: "", + data: [:], // optional + permissions: [Permission.read(Role.any())], // optional + transactionId: "" // optional +) + +``` diff --git a/docs/examples/vectorsdb/update-transaction.md b/docs/examples/vectorsdb/update-transaction.md new file mode 100644 index 0000000..f254540 --- /dev/null +++ b/docs/examples/vectorsdb/update-transaction.md @@ -0,0 +1,16 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let transaction = try await vectorsDB.updateTransaction( + transactionId: "", + commit: false, // optional + rollback: false // optional +) + +``` diff --git a/docs/examples/vectorsdb/upsert-document.md b/docs/examples/vectorsdb/upsert-document.md new file mode 100644 index 0000000..4fd8576 --- /dev/null +++ b/docs/examples/vectorsdb/upsert-document.md @@ -0,0 +1,19 @@ +```swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +let vectorsDB = VectorsDB(client) + +let document = try await vectorsDB.upsertDocument( + databaseId: "", + collectionId: "", + documentId: "", + data: [:], // optional + permissions: [Permission.read(Role.any())], // optional + transactionId: "" // optional +) + +``` diff --git a/example-swiftui/Shared/ExampleViewModel.swift b/example-swiftui/Shared/ExampleViewModel.swift index 3c6de09..aa3f4af 100644 --- a/example-swiftui/Shared/ExampleViewModel.swift +++ b/example-swiftui/Shared/ExampleViewModel.swift @@ -90,7 +90,7 @@ extension ExampleView { fileId: fileId ) DispatchQueue.main.async { - self.downloadedImage = Image(data: Data(buffer: data)) + self.downloadedImage = Image(data: Data(data.readableBytesView)) } } catch { DispatchQueue.main.async { diff --git a/example-uikit/UIKitExample/ViewController.swift b/example-uikit/UIKitExample/ViewController.swift index 656825f..73374a6 100644 --- a/example-uikit/UIKitExample/ViewController.swift +++ b/example-uikit/UIKitExample/ViewController.swift @@ -87,7 +87,7 @@ class ViewController: UIViewController { bucketId: bucketId, fileId: fileId ) - let data = response.getData(at: 0, length: response.readableBytes)! + let data = Data(response.readableBytesView) self.image.image = UIImage(data: data) } catch { self.response = String(describing: error) From 4d6b85ae1d2a13fe5bfe758ab1ac8a8ff9898715 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2026 04:22:40 +0000 Subject: [PATCH 2/6] chore: update Apple SDK to 15.0.0 --- CHANGELOG.md | 4 ++-- README.md | 4 ++-- Sources/Appwrite/Client.swift | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5d2f10..2072244 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,9 @@ # Change Log -## 14.2.0 +## 15.0.0 +* [BREAKING] Changed `$sequence` type from `int` to `string` for rows and documents * Added impersonation helpers to set impersonation headers. -* Added `DocumentsDB` service with documents and transactions APIs. * Added `upsertDocuments` overloads supporting generic document types. * Deprecated old `upsertDocuments` in favor of generic variant. * Updated API version badge to 1.9.0 in README. diff --git a/README.md b/README.md index 14a9e8b..20a0639 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![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) -**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-apple/releases).** +**This SDK is compatible with Appwrite server version 1.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-apple/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Apple SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "14.2.0"), + .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "15.0.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 51755d1..35dcc70 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -26,7 +26,7 @@ open class Client { "x-sdk-name": "Apple", "x-sdk-platform": "client", "x-sdk-language": "apple", - "x-sdk-version": "14.2.0", + "x-sdk-version": "15.0.0", "x-appwrite-response-format": "1.9.0" ] From e47cb7058cfe95bf37032d22f81f38a54c2833d9 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2026 05:24:48 +0000 Subject: [PATCH 3/6] chore: update Apple SDK to 15.0.0 --- Sources/Appwrite/Services/DocumentsDB.swift | 896 ------------------ Sources/Appwrite/Services/VectorsDB.swift | 610 ------------ docs/examples/documentsdb/create-document.md | 24 - docs/examples/documentsdb/create-documents.md | 16 - .../examples/documentsdb/create-operations.md | 25 - .../documentsdb/create-transaction.md | 14 - .../decrement-document-attribute.md | 20 - docs/examples/documentsdb/delete-document.md | 17 - .../documentsdb/delete-transaction.md | 14 - docs/examples/documentsdb/get-document.md | 18 - docs/examples/documentsdb/get-transaction.md | 14 - .../increment-document-attribute.md | 20 - docs/examples/documentsdb/list-documents.md | 19 - .../examples/documentsdb/list-transactions.md | 14 - docs/examples/documentsdb/update-document.md | 19 - .../documentsdb/update-transaction.md | 16 - docs/examples/documentsdb/upsert-document.md | 19 - docs/examples/vectorsdb/create-document.md | 28 - docs/examples/vectorsdb/create-operations.md | 25 - docs/examples/vectorsdb/create-transaction.md | 14 - docs/examples/vectorsdb/delete-document.md | 17 - docs/examples/vectorsdb/delete-transaction.md | 14 - docs/examples/vectorsdb/get-document.md | 18 - docs/examples/vectorsdb/get-transaction.md | 14 - docs/examples/vectorsdb/list-documents.md | 19 - docs/examples/vectorsdb/list-transactions.md | 14 - docs/examples/vectorsdb/update-document.md | 19 - docs/examples/vectorsdb/update-transaction.md | 16 - docs/examples/vectorsdb/upsert-document.md | 19 - 29 files changed, 1992 deletions(-) delete mode 100644 Sources/Appwrite/Services/DocumentsDB.swift delete mode 100644 Sources/Appwrite/Services/VectorsDB.swift delete mode 100644 docs/examples/documentsdb/create-document.md delete mode 100644 docs/examples/documentsdb/create-documents.md delete mode 100644 docs/examples/documentsdb/create-operations.md delete mode 100644 docs/examples/documentsdb/create-transaction.md delete mode 100644 docs/examples/documentsdb/decrement-document-attribute.md delete mode 100644 docs/examples/documentsdb/delete-document.md delete mode 100644 docs/examples/documentsdb/delete-transaction.md delete mode 100644 docs/examples/documentsdb/get-document.md delete mode 100644 docs/examples/documentsdb/get-transaction.md delete mode 100644 docs/examples/documentsdb/increment-document-attribute.md delete mode 100644 docs/examples/documentsdb/list-documents.md delete mode 100644 docs/examples/documentsdb/list-transactions.md delete mode 100644 docs/examples/documentsdb/update-document.md delete mode 100644 docs/examples/documentsdb/update-transaction.md delete mode 100644 docs/examples/documentsdb/upsert-document.md delete mode 100644 docs/examples/vectorsdb/create-document.md delete mode 100644 docs/examples/vectorsdb/create-operations.md delete mode 100644 docs/examples/vectorsdb/create-transaction.md delete mode 100644 docs/examples/vectorsdb/delete-document.md delete mode 100644 docs/examples/vectorsdb/delete-transaction.md delete mode 100644 docs/examples/vectorsdb/get-document.md delete mode 100644 docs/examples/vectorsdb/get-transaction.md delete mode 100644 docs/examples/vectorsdb/list-documents.md delete mode 100644 docs/examples/vectorsdb/list-transactions.md delete mode 100644 docs/examples/vectorsdb/update-document.md delete mode 100644 docs/examples/vectorsdb/update-transaction.md delete mode 100644 docs/examples/vectorsdb/upsert-document.md diff --git a/Sources/Appwrite/Services/DocumentsDB.swift b/Sources/Appwrite/Services/DocumentsDB.swift deleted file mode 100644 index 73f54c7..0000000 --- a/Sources/Appwrite/Services/DocumentsDB.swift +++ /dev/null @@ -1,896 +0,0 @@ -import AsyncHTTPClient -import Foundation -import NIO -import JSONCodable -import AppwriteEnums -import AppwriteModels - -/// -open class DocumentsDB: Service { - - /// - /// - Parameters: - /// - queries: [String] (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.TransactionList - /// - open func listTransactions( - queries: [String]? = nil - ) async throws -> AppwriteModels.TransactionList { - let apiPath: String = "/documentsdb/transactions" - - let apiParams: [String: Any?] = [ - "queries": queries - ] - - let apiHeaders: [String: String] = [:] - - let converter: (Any) -> AppwriteModels.TransactionList = { response in - return AppwriteModels.TransactionList.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "GET", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - ttl: Int (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Transaction - /// - open func createTransaction( - ttl: Int? = nil - ) async throws -> AppwriteModels.Transaction { - let apiPath: String = "/documentsdb/transactions" - - let apiParams: [String: Any?] = [ - "ttl": ttl - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Transaction = { response in - return AppwriteModels.Transaction.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "POST", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - transactionId: String - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Transaction - /// - open func getTransaction( - transactionId: String - ) async throws -> AppwriteModels.Transaction { - let apiPath: String = "/documentsdb/transactions/{transactionId}" - .replacingOccurrences(of: "{transactionId}", with: transactionId) - - let apiParams: [String: Any] = [:] - - let apiHeaders: [String: String] = [:] - - let converter: (Any) -> AppwriteModels.Transaction = { response in - return AppwriteModels.Transaction.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "GET", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - transactionId: String - /// - commit: Bool (optional) - /// - rollback: Bool (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Transaction - /// - open func updateTransaction( - transactionId: String, - commit: Bool? = nil, - rollback: Bool? = nil - ) async throws -> AppwriteModels.Transaction { - let apiPath: String = "/documentsdb/transactions/{transactionId}" - .replacingOccurrences(of: "{transactionId}", with: transactionId) - - let apiParams: [String: Any?] = [ - "commit": commit, - "rollback": rollback - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Transaction = { response in - return AppwriteModels.Transaction.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "PATCH", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - transactionId: String - /// - Throws: Exception if the request fails - /// - Returns: Any - /// - open func deleteTransaction( - transactionId: String - ) async throws -> Any { - let apiPath: String = "/documentsdb/transactions/{transactionId}" - .replacingOccurrences(of: "{transactionId}", with: transactionId) - - let apiParams: [String: Any] = [:] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - return try await client.call( - method: "DELETE", - path: apiPath, - headers: apiHeaders, - params: apiParams ) - } - - /// - /// - Parameters: - /// - transactionId: String - /// - operations: [Any] (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Transaction - /// - open func createOperations( - transactionId: String, - operations: [Any]? = nil - ) async throws -> AppwriteModels.Transaction { - let apiPath: String = "/documentsdb/transactions/{transactionId}/operations" - .replacingOccurrences(of: "{transactionId}", with: transactionId) - - let apiParams: [String: Any?] = [ - "operations": operations - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Transaction = { response in - return AppwriteModels.Transaction.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "POST", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Get a list of all the user's documents in a given collection. You can use - /// the query params to filter your results. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - queries: [String] (optional) - /// - transactionId: String (optional) - /// - total: Bool (optional) - /// - ttl: Int (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.DocumentList - /// - open func listDocuments( - databaseId: String, - collectionId: String, - queries: [String]? = nil, - transactionId: String? = nil, - total: Bool? = nil, - ttl: Int? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.DocumentList { - let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - - let apiParams: [String: Any?] = [ - "queries": queries, - "transactionId": transactionId, - "total": total, - "ttl": ttl - ] - - let apiHeaders: [String: String] = [:] - - let converter: (Any) -> AppwriteModels.DocumentList = { response in - return AppwriteModels.DocumentList.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "GET", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Get a list of all the user's documents in a given collection. You can use - /// the query params to filter your results. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - queries: [String] (optional) - /// - transactionId: String (optional) - /// - total: Bool (optional) - /// - ttl: Int (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.DocumentList - /// - open func listDocuments( - databaseId: String, - collectionId: String, - queries: [String]? = nil, - transactionId: String? = nil, - total: Bool? = nil, - ttl: Int? = nil - ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { - return try await listDocuments( - databaseId: databaseId, - collectionId: collectionId, - queries: queries, - transactionId: transactionId, - total: total, - ttl: ttl, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// Create a new Document. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) - /// API or directly from your database console. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any - /// - permissions: [String] (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func createDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any, - permissions: [String]? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - - let apiParams: [String: Any?] = [ - "documentId": documentId, - "data": data, - "permissions": permissions - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Document = { response in - return AppwriteModels.Document.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "POST", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Create a new Document. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) - /// API or directly from your database console. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any - /// - permissions: [String] (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func createDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any, - permissions: [String]? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await createDocument( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - data: data, - permissions: permissions, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// 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#documentsDBCreateCollection) - /// API or directly from your database console. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documents: [Any] - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.DocumentList - /// - open func createDocuments( - databaseId: String, - collectionId: String, - documents: [Any], - nestedType: T.Type - ) async throws -> AppwriteModels.DocumentList { - let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - - let apiParams: [String: Any?] = [ - "documents": documents - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.DocumentList = { response in - return AppwriteModels.DocumentList.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "POST", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// 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#documentsDBCreateCollection) - /// API or directly from your database console. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documents: [Any] - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.DocumentList - /// - open func createDocuments( - databaseId: String, - collectionId: String, - documents: [Any] - ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { - return try await createDocuments( - databaseId: databaseId, - collectionId: collectionId, - documents: documents, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// Get a document by its unique ID. This endpoint response returns a JSON - /// object with the document data. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - queries: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func getDocument( - databaseId: String, - collectionId: String, - documentId: String, - queries: [String]? = nil, - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - .replacingOccurrences(of: "{documentId}", with: documentId) - - let apiParams: [String: Any?] = [ - "queries": queries, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [:] - - let converter: (Any) -> AppwriteModels.Document = { response in - return AppwriteModels.Document.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "GET", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Get a document by its unique ID. This endpoint response returns a JSON - /// object with the document data. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - queries: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func getDocument( - databaseId: String, - collectionId: String, - documentId: String, - queries: [String]? = nil, - transactionId: String? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await getDocument( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - queries: queries, - transactionId: transactionId, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// 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#documentsDBCreateCollection) - /// API or directly from your database console. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any (optional) - /// - permissions: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func upsertDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any? = nil, - permissions: [String]? = nil, - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/documentsdb/{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, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Document = { 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 - ) - } - - /// - /// 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#documentsDBCreateCollection) - /// API or directly from your database console. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any (optional) - /// - permissions: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func upsertDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any? = nil, - permissions: [String]? = nil, - transactionId: String? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await upsertDocument( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - data: data, - permissions: permissions, - transactionId: transactionId, - 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. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any (optional) - /// - permissions: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func updateDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any? = nil, - permissions: [String]? = nil, - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/documentsdb/{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, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Document = { response in - return AppwriteModels.Document.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "PATCH", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Update a document by its unique ID. Using the patch method you can pass - /// only specific fields that will get updated. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any (optional) - /// - permissions: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func updateDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any? = nil, - permissions: [String]? = nil, - transactionId: String? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await updateDocument( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - data: data, - permissions: permissions, - transactionId: transactionId, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// Delete a document by its unique ID. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: Any - /// - open func deleteDocument( - databaseId: String, - collectionId: String, - documentId: String, - transactionId: String? = nil - ) async throws -> Any { - let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - .replacingOccurrences(of: "{documentId}", with: documentId) - - let apiParams: [String: Any?] = [ - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - return try await client.call( - method: "DELETE", - path: apiPath, - headers: apiHeaders, - params: apiParams ) - } - - /// - /// Decrement a specific column of a row by a given value. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - attribute: String - /// - value: Double (optional) - /// - min: Double (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func decrementDocumentAttribute( - databaseId: String, - collectionId: String, - documentId: String, - attribute: String, - value: Double? = nil, - min: Double? = nil, - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - .replacingOccurrences(of: "{documentId}", with: documentId) - .replacingOccurrences(of: "{attribute}", with: attribute) - - let apiParams: [String: Any?] = [ - "value": value, - "min": min, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Document = { response in - return AppwriteModels.Document.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "PATCH", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Decrement a specific column of a row by a given value. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - attribute: String - /// - value: Double (optional) - /// - min: Double (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func decrementDocumentAttribute( - databaseId: String, - collectionId: String, - documentId: String, - attribute: String, - value: Double? = nil, - min: Double? = nil, - transactionId: String? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await decrementDocumentAttribute( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - attribute: attribute, - value: value, - min: min, - transactionId: transactionId, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// Increment a specific column of a row by a given value. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - attribute: String - /// - value: Double (optional) - /// - max: Double (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func incrementDocumentAttribute( - databaseId: String, - collectionId: String, - documentId: String, - attribute: String, - value: Double? = nil, - max: Double? = nil, - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - .replacingOccurrences(of: "{documentId}", with: documentId) - .replacingOccurrences(of: "{attribute}", with: attribute) - - let apiParams: [String: Any?] = [ - "value": value, - "max": max, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Document = { response in - return AppwriteModels.Document.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "PATCH", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Increment a specific column of a row by a given value. - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - attribute: String - /// - value: Double (optional) - /// - max: Double (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func incrementDocumentAttribute( - databaseId: String, - collectionId: String, - documentId: String, - attribute: String, - value: Double? = nil, - max: Double? = nil, - transactionId: String? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await incrementDocumentAttribute( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - attribute: attribute, - value: value, - max: max, - transactionId: transactionId, - nestedType: [String: AnyCodable].self - ) - } - - -} \ No newline at end of file diff --git a/Sources/Appwrite/Services/VectorsDB.swift b/Sources/Appwrite/Services/VectorsDB.swift deleted file mode 100644 index ec56788..0000000 --- a/Sources/Appwrite/Services/VectorsDB.swift +++ /dev/null @@ -1,610 +0,0 @@ -import AsyncHTTPClient -import Foundation -import NIO -import JSONCodable -import AppwriteEnums -import AppwriteModels - -/// -open class VectorsDB: Service { - - /// - /// - Parameters: - /// - queries: [String] (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.TransactionList - /// - open func listTransactions( - queries: [String]? = nil - ) async throws -> AppwriteModels.TransactionList { - let apiPath: String = "/vectorsdb/transactions" - - let apiParams: [String: Any?] = [ - "queries": queries - ] - - let apiHeaders: [String: String] = [:] - - let converter: (Any) -> AppwriteModels.TransactionList = { response in - return AppwriteModels.TransactionList.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "GET", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - ttl: Int (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Transaction - /// - open func createTransaction( - ttl: Int? = nil - ) async throws -> AppwriteModels.Transaction { - let apiPath: String = "/vectorsdb/transactions" - - let apiParams: [String: Any?] = [ - "ttl": ttl - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Transaction = { response in - return AppwriteModels.Transaction.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "POST", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - transactionId: String - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Transaction - /// - open func getTransaction( - transactionId: String - ) async throws -> AppwriteModels.Transaction { - let apiPath: String = "/vectorsdb/transactions/{transactionId}" - .replacingOccurrences(of: "{transactionId}", with: transactionId) - - let apiParams: [String: Any] = [:] - - let apiHeaders: [String: String] = [:] - - let converter: (Any) -> AppwriteModels.Transaction = { response in - return AppwriteModels.Transaction.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "GET", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - transactionId: String - /// - commit: Bool (optional) - /// - rollback: Bool (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Transaction - /// - open func updateTransaction( - transactionId: String, - commit: Bool? = nil, - rollback: Bool? = nil - ) async throws -> AppwriteModels.Transaction { - let apiPath: String = "/vectorsdb/transactions/{transactionId}" - .replacingOccurrences(of: "{transactionId}", with: transactionId) - - let apiParams: [String: Any?] = [ - "commit": commit, - "rollback": rollback - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Transaction = { response in - return AppwriteModels.Transaction.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "PATCH", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - transactionId: String - /// - Throws: Exception if the request fails - /// - Returns: Any - /// - open func deleteTransaction( - transactionId: String - ) async throws -> Any { - let apiPath: String = "/vectorsdb/transactions/{transactionId}" - .replacingOccurrences(of: "{transactionId}", with: transactionId) - - let apiParams: [String: Any] = [:] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - return try await client.call( - method: "DELETE", - path: apiPath, - headers: apiHeaders, - params: apiParams ) - } - - /// - /// - Parameters: - /// - transactionId: String - /// - operations: [Any] (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Transaction - /// - open func createOperations( - transactionId: String, - operations: [Any]? = nil - ) async throws -> AppwriteModels.Transaction { - let apiPath: String = "/vectorsdb/transactions/{transactionId}/operations" - .replacingOccurrences(of: "{transactionId}", with: transactionId) - - let apiParams: [String: Any?] = [ - "operations": operations - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Transaction = { response in - return AppwriteModels.Transaction.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "POST", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - queries: [String] (optional) - /// - transactionId: String (optional) - /// - total: Bool (optional) - /// - ttl: Int (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.DocumentList - /// - open func listDocuments( - databaseId: String, - collectionId: String, - queries: [String]? = nil, - transactionId: String? = nil, - total: Bool? = nil, - ttl: Int? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.DocumentList { - let apiPath: String = "/vectorsdb/{databaseId}/collections/{collectionId}/documents" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - - let apiParams: [String: Any?] = [ - "queries": queries, - "transactionId": transactionId, - "total": total, - "ttl": ttl - ] - - let apiHeaders: [String: String] = [:] - - let converter: (Any) -> AppwriteModels.DocumentList = { response in - return AppwriteModels.DocumentList.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "GET", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - queries: [String] (optional) - /// - transactionId: String (optional) - /// - total: Bool (optional) - /// - ttl: Int (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.DocumentList - /// - open func listDocuments( - databaseId: String, - collectionId: String, - queries: [String]? = nil, - transactionId: String? = nil, - total: Bool? = nil, - ttl: Int? = nil - ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { - return try await listDocuments( - databaseId: databaseId, - collectionId: collectionId, - queries: queries, - transactionId: transactionId, - total: total, - ttl: ttl, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any - /// - permissions: [String] (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func createDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any, - permissions: [String]? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/vectorsdb/{databaseId}/collections/{collectionId}/documents" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - - let apiParams: [String: Any?] = [ - "documentId": documentId, - "data": data, - "permissions": permissions - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Document = { response in - return AppwriteModels.Document.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "POST", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any - /// - permissions: [String] (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func createDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any, - permissions: [String]? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await createDocument( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - data: data, - permissions: permissions, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - queries: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func getDocument( - databaseId: String, - collectionId: String, - documentId: String, - queries: [String]? = nil, - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - .replacingOccurrences(of: "{documentId}", with: documentId) - - let apiParams: [String: Any?] = [ - "queries": queries, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [:] - - let converter: (Any) -> AppwriteModels.Document = { response in - return AppwriteModels.Document.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "GET", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - queries: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func getDocument( - databaseId: String, - collectionId: String, - documentId: String, - queries: [String]? = nil, - transactionId: String? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await getDocument( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - queries: queries, - transactionId: transactionId, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any (optional) - /// - permissions: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func upsertDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any? = nil, - permissions: [String]? = nil, - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/vectorsdb/{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, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Document = { 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 - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any (optional) - /// - permissions: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func upsertDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any? = nil, - permissions: [String]? = nil, - transactionId: String? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await upsertDocument( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - data: data, - permissions: permissions, - transactionId: transactionId, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any (optional) - /// - permissions: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func updateDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any? = nil, - permissions: [String]? = nil, - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.Document { - let apiPath: String = "/vectorsdb/{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, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.Document = { response in - return AppwriteModels.Document.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "PATCH", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - data: Any (optional) - /// - permissions: [String] (optional) - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.Document - /// - open func updateDocument( - databaseId: String, - collectionId: String, - documentId: String, - data: Any? = nil, - permissions: [String]? = nil, - transactionId: String? = nil - ) async throws -> AppwriteModels.Document<[String: AnyCodable]> { - return try await updateDocument( - databaseId: databaseId, - collectionId: collectionId, - documentId: documentId, - data: data, - permissions: permissions, - transactionId: transactionId, - nestedType: [String: AnyCodable].self - ) - } - - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documentId: String - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: Any - /// - open func deleteDocument( - databaseId: String, - collectionId: String, - documentId: String, - transactionId: String? = nil - ) async throws -> Any { - let apiPath: String = "/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - .replacingOccurrences(of: "{documentId}", with: documentId) - - let apiParams: [String: Any?] = [ - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - return try await client.call( - method: "DELETE", - path: apiPath, - headers: apiHeaders, - params: apiParams ) - } - - -} \ No newline at end of file diff --git a/docs/examples/documentsdb/create-document.md b/docs/examples/documentsdb/create-document.md deleted file mode 100644 index b0cda1a..0000000 --- a/docs/examples/documentsdb/create-document.md +++ /dev/null @@ -1,24 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let document = try await documentsDB.createDocument( - databaseId: "", - collectionId: "", - documentId: "", - data: [ - "username": "walter.obrien", - "email": "walter.obrien@example.com", - "fullName": "Walter O'Brien", - "age": 30, - "isAdmin": false - ], - permissions: [Permission.read(Role.any())] // optional -) - -``` diff --git a/docs/examples/documentsdb/create-documents.md b/docs/examples/documentsdb/create-documents.md deleted file mode 100644 index edf3a9e..0000000 --- a/docs/examples/documentsdb/create-documents.md +++ /dev/null @@ -1,16 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let documentList = try await documentsDB.createDocuments( - databaseId: "", - collectionId: "", - documents: [] -) - -``` diff --git a/docs/examples/documentsdb/create-operations.md b/docs/examples/documentsdb/create-operations.md deleted file mode 100644 index c1bc948..0000000 --- a/docs/examples/documentsdb/create-operations.md +++ /dev/null @@ -1,25 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let transaction = try await documentsDB.createOperations( - transactionId: "", - operations: [ - { - "action": "create", - "databaseId": "", - "collectionId": "", - "documentId": "", - "data": { - "name": "Walter O'Brien" - } - } - ] // optional -) - -``` diff --git a/docs/examples/documentsdb/create-transaction.md b/docs/examples/documentsdb/create-transaction.md deleted file mode 100644 index 88030b7..0000000 --- a/docs/examples/documentsdb/create-transaction.md +++ /dev/null @@ -1,14 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let transaction = try await documentsDB.createTransaction( - ttl: 60 // optional -) - -``` diff --git a/docs/examples/documentsdb/decrement-document-attribute.md b/docs/examples/documentsdb/decrement-document-attribute.md deleted file mode 100644 index d0e1a0e..0000000 --- a/docs/examples/documentsdb/decrement-document-attribute.md +++ /dev/null @@ -1,20 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let document = try await documentsDB.decrementDocumentAttribute( - databaseId: "", - collectionId: "", - documentId: "", - attribute: "", - value: 0, // optional - min: 0, // optional - transactionId: "" // optional -) - -``` diff --git a/docs/examples/documentsdb/delete-document.md b/docs/examples/documentsdb/delete-document.md deleted file mode 100644 index 10eef17..0000000 --- a/docs/examples/documentsdb/delete-document.md +++ /dev/null @@ -1,17 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let result = try await documentsDB.deleteDocument( - databaseId: "", - collectionId: "", - documentId: "", - transactionId: "" // optional -) - -``` diff --git a/docs/examples/documentsdb/delete-transaction.md b/docs/examples/documentsdb/delete-transaction.md deleted file mode 100644 index ca1c9bb..0000000 --- a/docs/examples/documentsdb/delete-transaction.md +++ /dev/null @@ -1,14 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let result = try await documentsDB.deleteTransaction( - transactionId: "" -) - -``` diff --git a/docs/examples/documentsdb/get-document.md b/docs/examples/documentsdb/get-document.md deleted file mode 100644 index 504bbf1..0000000 --- a/docs/examples/documentsdb/get-document.md +++ /dev/null @@ -1,18 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let document = try await documentsDB.getDocument( - databaseId: "", - collectionId: "", - documentId: "", - queries: [], // optional - transactionId: "" // optional -) - -``` diff --git a/docs/examples/documentsdb/get-transaction.md b/docs/examples/documentsdb/get-transaction.md deleted file mode 100644 index 4435dce..0000000 --- a/docs/examples/documentsdb/get-transaction.md +++ /dev/null @@ -1,14 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let transaction = try await documentsDB.getTransaction( - transactionId: "" -) - -``` diff --git a/docs/examples/documentsdb/increment-document-attribute.md b/docs/examples/documentsdb/increment-document-attribute.md deleted file mode 100644 index 9d92521..0000000 --- a/docs/examples/documentsdb/increment-document-attribute.md +++ /dev/null @@ -1,20 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let document = try await documentsDB.incrementDocumentAttribute( - databaseId: "", - collectionId: "", - documentId: "", - attribute: "", - value: 0, // optional - max: 0, // optional - transactionId: "" // optional -) - -``` diff --git a/docs/examples/documentsdb/list-documents.md b/docs/examples/documentsdb/list-documents.md deleted file mode 100644 index 81768bc..0000000 --- a/docs/examples/documentsdb/list-documents.md +++ /dev/null @@ -1,19 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let documentList = try await documentsDB.listDocuments( - databaseId: "", - collectionId: "", - queries: [], // optional - transactionId: "", // optional - total: false, // optional - ttl: 0 // optional -) - -``` diff --git a/docs/examples/documentsdb/list-transactions.md b/docs/examples/documentsdb/list-transactions.md deleted file mode 100644 index 0fe1ca7..0000000 --- a/docs/examples/documentsdb/list-transactions.md +++ /dev/null @@ -1,14 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let transactionList = try await documentsDB.listTransactions( - queries: [] // optional -) - -``` diff --git a/docs/examples/documentsdb/update-document.md b/docs/examples/documentsdb/update-document.md deleted file mode 100644 index 250ecd7..0000000 --- a/docs/examples/documentsdb/update-document.md +++ /dev/null @@ -1,19 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let document = try await documentsDB.updateDocument( - databaseId: "", - collectionId: "", - documentId: "", - data: [:], // optional - permissions: [Permission.read(Role.any())], // optional - transactionId: "" // optional -) - -``` diff --git a/docs/examples/documentsdb/update-transaction.md b/docs/examples/documentsdb/update-transaction.md deleted file mode 100644 index 1ea869b..0000000 --- a/docs/examples/documentsdb/update-transaction.md +++ /dev/null @@ -1,16 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let transaction = try await documentsDB.updateTransaction( - transactionId: "", - commit: false, // optional - rollback: false // optional -) - -``` diff --git a/docs/examples/documentsdb/upsert-document.md b/docs/examples/documentsdb/upsert-document.md deleted file mode 100644 index cede61c..0000000 --- a/docs/examples/documentsdb/upsert-document.md +++ /dev/null @@ -1,19 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let documentsDB = DocumentsDB(client) - -let document = try await documentsDB.upsertDocument( - databaseId: "", - collectionId: "", - documentId: "", - data: [:], // optional - permissions: [Permission.read(Role.any())], // optional - transactionId: "" // optional -) - -``` diff --git a/docs/examples/vectorsdb/create-document.md b/docs/examples/vectorsdb/create-document.md deleted file mode 100644 index 3b2ad89..0000000 --- a/docs/examples/vectorsdb/create-document.md +++ /dev/null @@ -1,28 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let document = try await vectorsDB.createDocument( - databaseId: "", - collectionId: "", - documentId: "", - data: [ - "embeddings": [ - "0": 0.12, - "1": -0.55, - "2": 0.88, - "3": 1.02 - ], - "metadata": [ - "key": "value" - ] - ], - permissions: [Permission.read(Role.any())] // optional -) - -``` diff --git a/docs/examples/vectorsdb/create-operations.md b/docs/examples/vectorsdb/create-operations.md deleted file mode 100644 index c90069a..0000000 --- a/docs/examples/vectorsdb/create-operations.md +++ /dev/null @@ -1,25 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let transaction = try await vectorsDB.createOperations( - transactionId: "", - operations: [ - { - "action": "create", - "databaseId": "", - "collectionId": "", - "documentId": "", - "data": { - "name": "Walter O'Brien" - } - } - ] // optional -) - -``` diff --git a/docs/examples/vectorsdb/create-transaction.md b/docs/examples/vectorsdb/create-transaction.md deleted file mode 100644 index 4cdabc2..0000000 --- a/docs/examples/vectorsdb/create-transaction.md +++ /dev/null @@ -1,14 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let transaction = try await vectorsDB.createTransaction( - ttl: 60 // optional -) - -``` diff --git a/docs/examples/vectorsdb/delete-document.md b/docs/examples/vectorsdb/delete-document.md deleted file mode 100644 index dd80e83..0000000 --- a/docs/examples/vectorsdb/delete-document.md +++ /dev/null @@ -1,17 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let result = try await vectorsDB.deleteDocument( - databaseId: "", - collectionId: "", - documentId: "", - transactionId: "" // optional -) - -``` diff --git a/docs/examples/vectorsdb/delete-transaction.md b/docs/examples/vectorsdb/delete-transaction.md deleted file mode 100644 index ff7538a..0000000 --- a/docs/examples/vectorsdb/delete-transaction.md +++ /dev/null @@ -1,14 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let result = try await vectorsDB.deleteTransaction( - transactionId: "" -) - -``` diff --git a/docs/examples/vectorsdb/get-document.md b/docs/examples/vectorsdb/get-document.md deleted file mode 100644 index e181437..0000000 --- a/docs/examples/vectorsdb/get-document.md +++ /dev/null @@ -1,18 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let document = try await vectorsDB.getDocument( - databaseId: "", - collectionId: "", - documentId: "", - queries: [], // optional - transactionId: "" // optional -) - -``` diff --git a/docs/examples/vectorsdb/get-transaction.md b/docs/examples/vectorsdb/get-transaction.md deleted file mode 100644 index 4b8fd1a..0000000 --- a/docs/examples/vectorsdb/get-transaction.md +++ /dev/null @@ -1,14 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let transaction = try await vectorsDB.getTransaction( - transactionId: "" -) - -``` diff --git a/docs/examples/vectorsdb/list-documents.md b/docs/examples/vectorsdb/list-documents.md deleted file mode 100644 index c082c81..0000000 --- a/docs/examples/vectorsdb/list-documents.md +++ /dev/null @@ -1,19 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let documentList = try await vectorsDB.listDocuments( - databaseId: "", - collectionId: "", - queries: [], // optional - transactionId: "", // optional - total: false, // optional - ttl: 0 // optional -) - -``` diff --git a/docs/examples/vectorsdb/list-transactions.md b/docs/examples/vectorsdb/list-transactions.md deleted file mode 100644 index 26aa4f4..0000000 --- a/docs/examples/vectorsdb/list-transactions.md +++ /dev/null @@ -1,14 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let transactionList = try await vectorsDB.listTransactions( - queries: [] // optional -) - -``` diff --git a/docs/examples/vectorsdb/update-document.md b/docs/examples/vectorsdb/update-document.md deleted file mode 100644 index f96706f..0000000 --- a/docs/examples/vectorsdb/update-document.md +++ /dev/null @@ -1,19 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let document = try await vectorsDB.updateDocument( - databaseId: "", - collectionId: "", - documentId: "", - data: [:], // optional - permissions: [Permission.read(Role.any())], // optional - transactionId: "" // optional -) - -``` diff --git a/docs/examples/vectorsdb/update-transaction.md b/docs/examples/vectorsdb/update-transaction.md deleted file mode 100644 index f254540..0000000 --- a/docs/examples/vectorsdb/update-transaction.md +++ /dev/null @@ -1,16 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let transaction = try await vectorsDB.updateTransaction( - transactionId: "", - commit: false, // optional - rollback: false // optional -) - -``` diff --git a/docs/examples/vectorsdb/upsert-document.md b/docs/examples/vectorsdb/upsert-document.md deleted file mode 100644 index 4fd8576..0000000 --- a/docs/examples/vectorsdb/upsert-document.md +++ /dev/null @@ -1,19 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let vectorsDB = VectorsDB(client) - -let document = try await vectorsDB.upsertDocument( - databaseId: "", - collectionId: "", - documentId: "", - data: [:], // optional - permissions: [Permission.read(Role.any())], // optional - transactionId: "" // optional -) - -``` From fc260db0a5bc18e601a9d6f94fc0027f848dbf42 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Mar 2026 05:04:01 +0000 Subject: [PATCH 4/6] chore: update Apple SDK to 15.0.0 --- Sources/Appwrite/Services/Databases.swift | 80 --------------------- docs/examples/databases/upsert-documents.md | 17 ----- 2 files changed, 97 deletions(-) delete mode 100644 docs/examples/databases/upsert-documents.md diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 7438971..989e457 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -383,86 +383,6 @@ open class Databases: Service { ) } - /// - /// 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) - /// API or directly from your database console. - /// - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documents: [Any] - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.DocumentList - /// - @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRows` instead.") - open func upsertDocuments( - databaseId: String, - collectionId: String, - documents: [Any], - transactionId: String? = nil, - nestedType: T.Type - ) async throws -> AppwriteModels.DocumentList { - let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - - let apiParams: [String: Any?] = [ - "documents": documents, - "transactionId": transactionId - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.DocumentList = { response in - return AppwriteModels.DocumentList.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "PUT", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// 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) - /// API or directly from your database console. - /// - /// - /// - Parameters: - /// - databaseId: String - /// - collectionId: String - /// - documents: [Any] - /// - transactionId: String (optional) - /// - Throws: Exception if the request fails - /// - Returns: AppwriteModels.DocumentList - /// - @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRows` instead.") - open func upsertDocuments( - databaseId: String, - collectionId: String, - documents: [Any], - transactionId: String? = nil - ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { - return try await upsertDocuments( - databaseId: databaseId, - collectionId: collectionId, - documents: documents, - transactionId: transactionId, - nestedType: [String: AnyCodable].self - ) - } - /// /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. diff --git a/docs/examples/databases/upsert-documents.md b/docs/examples/databases/upsert-documents.md deleted file mode 100644 index 1ec3add..0000000 --- a/docs/examples/databases/upsert-documents.md +++ /dev/null @@ -1,17 +0,0 @@ -```swift -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setProject("") // Your project ID - -let databases = Databases(client) - -let documentList = try await databases.upsertDocuments( - databaseId: "", - collectionId: "", - documents: [], - transactionId: "" // optional -) - -``` From cc9c811c7fd6745be30747f67ef0853153e4934a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Mar 2026 05:15:49 +0000 Subject: [PATCH 5/6] chore: update Apple SDK to 15.0.0 --- CHANGELOG.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2072244..8864870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,15 @@ ## 15.0.0 -* [BREAKING] Changed `$sequence` type from `int` to `string` for rows and documents -* Added impersonation helpers to set impersonation headers. -* Added `upsertDocuments` overloads supporting generic document types. -* Deprecated old `upsertDocuments` in favor of generic variant. -* Updated API version badge to 1.9.0 in README. -* Updated compatibility note to server version 1.9.x in README. +* [BREAKING] Changed `$sequence` type from `Int` to `String` for `Row` and `Document` models +* Added impersonation support: `setImpersonateUserId()`, `setImpersonateUserEmail()`, `setImpersonateUserPhone()` on `Client` +* Added `impersonator` and `impersonatorUserId` optional fields to `User` model +* Updated `Log` model field descriptions to clarify impersonation behavior for `userId`, `userEmail`, `userName` +* Fixed `NIOFoundationCompat` import to be conditional with `#if canImport` for platform compatibility +* Fixed `ByteBuffer` to `Data` conversion to use `readableBytesView` throughout (Client and WebSocket handler) +* Fixed `ByteBuffer(data:)` calls replaced with `ByteBuffer(bytes:)` for file/data loading +* Updated `X-Appwrite-Response-Format` header to `1.9.0` +* Updated API version badge to `1.9.0` and compatibility note to server version `1.9.x` in README ## 14.1.0 From cf788ffee69443957179563133b1b4deb1a81a74 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Mar 2026 05:37:07 +0000 Subject: [PATCH 6/6] chore: update Apple SDK to 16.0.0 --- CHANGELOG.md | 9 ++++++++- README.md | 2 +- Sources/Appwrite/Client.swift | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8864870..fffd919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## 15.0.0 +## 16.0.0 * [BREAKING] Changed `$sequence` type from `Int` to `String` for `Row` and `Document` models * Added impersonation support: `setImpersonateUserId()`, `setImpersonateUserEmail()`, `setImpersonateUserPhone()` on `Client` @@ -12,6 +12,13 @@ * Updated `X-Appwrite-Response-Format` header to `1.9.0` * Updated API version badge to `1.9.0` and compatibility note to server version `1.9.x` in README +## 15.0.0 + +* Breaking: RealtimeChannel API required explicit IDs and threw errors. +* Added ttl parameter to listDocuments and listRows. +* Updated compatibility notes to latest server and SDK version. +* Updated Document and Row comments for clarity. + ## 14.1.0 * Add `queries` parameter to Realtime subscriptions for filtering events diff --git a/README.md b/README.md index 20a0639..028685c 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "15.0.0"), + .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "16.0.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 35dcc70..8687a95 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -26,7 +26,7 @@ open class Client { "x-sdk-name": "Apple", "x-sdk-platform": "client", "x-sdk-language": "apple", - "x-sdk-version": "15.0.0", + "x-sdk-version": "16.0.0", "x-appwrite-response-format": "1.9.0" ]