Conversation
* 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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis pull request introduces version 16.0.0 of the Appwrite Swift SDK with breaking changes and new features. The Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR updates the Apple SDK to version 14.2.0, adding two new database services ( Key issues found:
Confidence Score: 2/5
Important Files Changed
|
| @@ -94,7 +94,7 @@ open class Row<T : Codable>: Codable { | |||
| public static func from(map: [String: Any] ) -> Row { | |||
There was a problem hiding this comment.
Force unwrap will crash if
$sequence is absent
The from(map:) factory uses a force-cast as! String for $sequence. If the server response ever omits this field (e.g. for an older server version), the app will crash at runtime. The parallel change in Document.swift correctly uses a safe optional cast with a default value (as? String ?? ""). This inconsistency should be resolved.
| public static func from(map: [String: Any] ) -> Row { | |
| sequence: map["$sequence"] as? String ?? "", |
| /// - collectionId: String | ||
| /// - documents: [Any] | ||
| /// - Throws: Exception if the request fails |
There was a problem hiding this comment.
Formatting issue: missing trailing newline before closing parenthesis
The closing ) of client.call(...) is on the same line as params: apiParams with extra spaces, likely a codegen artifact. The same pattern also appears in deleteDocument (line 971) and in VectorsDB.deleteTransaction / VectorsDB.deleteDocument. While Swift accepts this syntactically, it is inconsistent with all other methods in the file.
| /// - collectionId: String | |
| /// - documents: [Any] | |
| /// - Throws: Exception if the request fails | |
| params: apiParams | |
| ) |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Actionable comments posted: 10
🧹 Nitpick comments (5)
Sources/AppwriteModels/Row.swift (1)
97-97: Inconsistent optional handling compared toDocument.swift.
Row.from(map:)uses a force cast (as! String) forsequence, whileDocument.from(map:)uses a safer optional cast with fallback (as? String ?? ""). This inconsistency could cause a runtime crash if the server response doesn't include$sequenceor returns an unexpected type.Consider aligning with the safer pattern used in
Document.swift:♻️ Proposed fix for safer optional handling
- sequence: map["$sequence"] as! String, + sequence: map["$sequence"] as? String ?? "",🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Sources/AppwriteModels/Row.swift` at line 97, The Row.from(map:) initializer is force-casting sequence using "sequence: map[\"$sequence\"] as! String" which can crash; change it to the same safe pattern used in Document.from(map:) by using an optional cast with a fallback (e.g., map["$sequence"] as? String ?? "") for the sequence field in Row.from(map:) to avoid runtime crashes when the key is missing or has an unexpected type.docs/examples/databases/upsert-documents.md (1)
1-15: Show the new typed overload here.This snippet resolves to the
[String: AnyCodable]convenience overload, so it does not actually demonstrate the new generic API introduced in this PR. If the goal is to steer users toward typed documents, addnestedType:with a small model.Proposed fix
+struct Book: Codable { + let title: String +} + let documentList = try await databases.upsertDocuments( databaseId: "<DATABASE_ID>", collectionId: "<COLLECTION_ID>", documents: [], - transactionId: "<TRANSACTION_ID>" // optional + transactionId: "<TRANSACTION_ID>", // optional + nestedType: Book.self )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/examples/databases/upsert-documents.md` around lines 1 - 15, The example currently calls Databases.upsertDocuments and resolves to the untyped [String: AnyCodable] overload; update the snippet to demonstrate the new generic API by adding the nestedType: parameter and a small typed model (e.g., a struct) so the call uses the typed overload of upsertDocuments; reference the Databases type, the upsertDocuments function, and the nestedType argument name when making the change.docs/examples/vectorsdb/delete-transaction.md (1)
10-12: Optional clarity tweak: avoid implying a typed response payload for delete.Since this method returns
Any, using_communicates intent better in docs.Proposed doc tweak
-let result = try await vectorsDB.deleteTransaction( +try await vectorsDB.deleteTransaction( transactionId: "<TRANSACTION_ID>" )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/examples/vectorsdb/delete-transaction.md` around lines 10 - 12, The example assigns the Any return from vectorsDB.deleteTransaction to a typed variable `result`, implying a structured payload; change the example to discard the return value using `_` when calling vectorsDB.deleteTransaction(transactionId: "<TRANSACTION_ID>") so the docs communicate that the method returns an opaque Any and the response is intentionally ignored; update the snippet around the call to use `_ = try await vectorsDB.deleteTransaction(...)` or simply `try await vectorsDB.deleteTransaction(...)` referencing the `vectorsDB.deleteTransaction` call and `transactionId` parameter.docs/examples/documentsdb/delete-document.md (1)
10-15: Optional clarity tweak: dropresultbinding for delete response.For delete examples, direct
try awaitis less misleading than binding an untyped return.Proposed doc tweak
-let result = try await documentsDB.deleteDocument( +try await documentsDB.deleteDocument( databaseId: "<DATABASE_ID>", collectionId: "<COLLECTION_ID>", documentId: "<DOCUMENT_ID>", transactionId: "<TRANSACTION_ID>" // optional )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/examples/documentsdb/delete-document.md` around lines 10 - 15, Drop the unused `result` binding in the delete example to avoid implying a meaningful return value; replace the bound call with a direct call to documentsDB.deleteDocument using `try await documentsDB.deleteDocument(databaseId: "<DATABASE_ID>", collectionId: "<COLLECTION_ID>", documentId: "<DOCUMENT_ID>", transactionId: "<TRANSACTION_ID>")` so the example shows the correct, unambiguous usage of the deleteDocument API.docs/examples/documentsdb/delete-transaction.md (1)
10-12: Optional clarity tweak: don’t bind delete response unless you use it.Using direct
try awaitis clearer for this delete example.Proposed doc tweak
-let result = try await documentsDB.deleteTransaction( +try await documentsDB.deleteTransaction( transactionId: "<TRANSACTION_ID>" )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/examples/documentsdb/delete-transaction.md` around lines 10 - 12, The example currently assigns the delete result to a variable (`let result = try await documentsDB.deleteTransaction(transactionId: "<TRANSACTION_ID>")`) even though the response isn't used; replace that line to call the function without binding (use `try await documentsDB.deleteTransaction(transactionId: "<TRANSACTION_ID>")`) so the example is clearer and avoids unused variable warnings—locate the call to documentsDB.deleteTransaction in the example and remove the `let result =` binding.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG.md`:
- Around line 5-10: The 14.2.0 changelog entry documents DocumentsDB but omits
the new public VectorsDB service; update CHANGELOG.md under the 14.2.0 notes to
add a line like "Added VectorsDB service
(Sources/Appwrite/Services/VectorsDB.swift) exposing the VectorsDB public
service" so consumers see the new VectorsDB addition alongside
DocumentsDB—mention the VectorsDB symbol/class name and a brief one-line
description of what it provides.
In `@docs/examples/documentsdb/increment-document-attribute.md`:
- Line 14: The example uses an empty attribute value (attribute: "") which is
invalid and likely to be copied by users; update the example to use a clear
placeholder token such as attribute: "<ATTRIBUTE_NAME>" (or attribute:
"myAttribute") so readers replace it with a real attribute name—locate the
attribute field in the example and replace the empty string with a non-empty
placeholder.
In `@docs/examples/documentsdb/upsert-document.md`:
- Line 14: The example uses an untyped empty Swift dictionary literal `data:
[:]` which can break type inference; update the snippet where `data:` appears by
providing a concrete payload (e.g., a small key/value example) or an explicitly
typed empty dictionary (e.g., `data: [String: Any]()`) so the example compiles
when copied into Swift projects; ensure the change is made in the
upsert-document example where `data:` is set.
In `@docs/examples/vectorsdb/create-document.md`:
- Around line 14-20: The example under data/embeddings currently shows
embeddings as an object with numeric string keys ("0", "1", "2", "3"); change it
to an ordered array of numbers so consumers and vector DBs can parse it
correctly — replace the object value for the embeddings field with an ordered
array (e.g., embeddings: [0.12, -0.55, 0.88, 1.02]) wherever the "data" ->
"embeddings" example appears.
In `@README.md`:
- Around line 5-10: Update the compatibility statement text to match the API
version badge: replace the string "This SDK is compatible with Appwrite server
version 1.8.x." with "This SDK is compatible with Appwrite server version
1.9.x." so the README's compatibility statement aligns with the Version badge
(1.9.0) and the PR description; ensure the exact phrase change is applied
wherever the 1.8.x compatibility sentence appears.
In `@Sources/Appwrite/Client.swift`:
- Around line 470-472: The ByteBuffer initialization is using a non-existent
initializer (ByteBuffer(bytes:)) in the switch handling for the upload input;
update the cases that set input.data to use the NIOFoundationCompat API
ByteBuffer(data: Data) instead: in the "path" branch create Data from URL and
pass it to ByteBuffer(data:) and in the "data" branch cast input.data to Data
and wrap it with ByteBuffer(data:), locating the changes around the switch cases
"path" and "data" where input.data is assigned in Sources/Appwrite/Client.swift.
In `@Sources/Appwrite/Services/DocumentsDB.swift`:
- Around line 719-720: The doc summaries mistakenly use "column of a row"
(copied from TablesDB); update the comments to say "attribute of a document"
instead — e.g., change "Decrement a specific column of a row by a given value."
to "Decrement a specific attribute of a document by a given value." and make the
same replacement for the related summary at the other occurrence (the duplicate
comment around lines 807-808) and any other similar summaries in
DocumentsDB.swift (look for the increment/decrement method summaries or
functions handling document attribute updates) so public docs refer to document
attributes, not table columns/rows.
- Around line 297-362: Add an optional transactionId: String? = nil parameter to
both createDocument<T>(...) and the non-generic createDocument(...) overload
(and to the createDocuments<T>/createDocuments overloads) and include
"transactionId": transactionId in their apiParams dictionaries so create
operations can participate in Appwrite transactions; update the method
signatures in DocumentsDB.swift (look for createDocument<T>, createDocument,
createDocuments<T>, createDocuments) and pass transactionId through to
client.call. Also correct the documentation strings for
decrementDocumentAttribute and incrementDocumentAttribute by replacing "column
of a row" with "attribute of a document".
In `@Sources/Appwrite/Services/VectorsDB.swift`:
- Around line 286-345: Add an optional transactionId: String? parameter (default
nil) to both createDocument<T>(...) and the non-generic createDocument(...)
overloads in VectorsDB.swift, include "transactionId": transactionId in the
apiParams dictionary used by createDocument<T>, and update the non-generic
createDocument to forward the new transactionId when calling the generic
createDocument (keep nestedType forwarding as-is). Reference the
createDocument<T>(databaseId:collectionId:documentId:data:permissions:nestedType:)
function and the
createDocument(databaseId:collectionId:documentId:data:permissions:) overload to
locate where to add the parameter and apiParams entry.
In `@Sources/AppwriteModels/Document.swift`:
- Line 21: The Document model's public property sequence was changed from Int to
String (public let sequence: String), which is an API-breaking change; update
the project's CHANGELOG/migration notes to document this breaking change and
provide migration guidance (e.g., treat Document.sequence as String or convert
with Int(Document.sequence) where numeric semantics are required), then search
for and update all code paths, tests, and Codable decoding logic that expect
Document.sequence as Int (and any references in Row.swift comparisons) to either
accept String or explicitly convert/parse it to Int, ensuring compile-time fixes
and adding a note about server API alignment.
---
Nitpick comments:
In `@docs/examples/databases/upsert-documents.md`:
- Around line 1-15: The example currently calls Databases.upsertDocuments and
resolves to the untyped [String: AnyCodable] overload; update the snippet to
demonstrate the new generic API by adding the nestedType: parameter and a small
typed model (e.g., a struct) so the call uses the typed overload of
upsertDocuments; reference the Databases type, the upsertDocuments function, and
the nestedType argument name when making the change.
In `@docs/examples/documentsdb/delete-document.md`:
- Around line 10-15: Drop the unused `result` binding in the delete example to
avoid implying a meaningful return value; replace the bound call with a direct
call to documentsDB.deleteDocument using `try await
documentsDB.deleteDocument(databaseId: "<DATABASE_ID>", collectionId:
"<COLLECTION_ID>", documentId: "<DOCUMENT_ID>", transactionId:
"<TRANSACTION_ID>")` so the example shows the correct, unambiguous usage of the
deleteDocument API.
In `@docs/examples/documentsdb/delete-transaction.md`:
- Around line 10-12: The example currently assigns the delete result to a
variable (`let result = try await documentsDB.deleteTransaction(transactionId:
"<TRANSACTION_ID>")`) even though the response isn't used; replace that line to
call the function without binding (use `try await
documentsDB.deleteTransaction(transactionId: "<TRANSACTION_ID>")`) so the
example is clearer and avoids unused variable warnings—locate the call to
documentsDB.deleteTransaction in the example and remove the `let result =`
binding.
In `@docs/examples/vectorsdb/delete-transaction.md`:
- Around line 10-12: The example assigns the Any return from
vectorsDB.deleteTransaction to a typed variable `result`, implying a structured
payload; change the example to discard the return value using `_` when calling
vectorsDB.deleteTransaction(transactionId: "<TRANSACTION_ID>") so the docs
communicate that the method returns an opaque Any and the response is
intentionally ignored; update the snippet around the call to use `_ = try await
vectorsDB.deleteTransaction(...)` or simply `try await
vectorsDB.deleteTransaction(...)` referencing the `vectorsDB.deleteTransaction`
call and `transactionId` parameter.
In `@Sources/AppwriteModels/Row.swift`:
- Line 97: The Row.from(map:) initializer is force-casting sequence using
"sequence: map[\"$sequence\"] as! String" which can crash; change it to the same
safe pattern used in Document.from(map:) by using an optional cast with a
fallback (e.g., map["$sequence"] as? String ?? "") for the sequence field in
Row.from(map:) to avoid runtime crashes when the key is missing or has an
unexpected type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4b83461e-e037-4557-a408-eb7389f1f376
📒 Files selected for processing (42)
CHANGELOG.mdREADME.mdSources/Appwrite/Client.swiftSources/Appwrite/Services/Databases.swiftSources/Appwrite/Services/DocumentsDB.swiftSources/Appwrite/Services/VectorsDB.swiftSources/Appwrite/WebSockets/MessageHandler.swiftSources/Appwrite/WebSockets/WebSocketClient.swiftSources/AppwriteModels/Document.swiftSources/AppwriteModels/Log.swiftSources/AppwriteModels/Row.swiftSources/AppwriteModels/User.swiftdocs/examples/databases/upsert-documents.mddocs/examples/documentsdb/create-document.mddocs/examples/documentsdb/create-documents.mddocs/examples/documentsdb/create-operations.mddocs/examples/documentsdb/create-transaction.mddocs/examples/documentsdb/decrement-document-attribute.mddocs/examples/documentsdb/delete-document.mddocs/examples/documentsdb/delete-transaction.mddocs/examples/documentsdb/get-document.mddocs/examples/documentsdb/get-transaction.mddocs/examples/documentsdb/increment-document-attribute.mddocs/examples/documentsdb/list-documents.mddocs/examples/documentsdb/list-transactions.mddocs/examples/documentsdb/update-document.mddocs/examples/documentsdb/update-transaction.mddocs/examples/documentsdb/upsert-document.mddocs/examples/vectorsdb/create-document.mddocs/examples/vectorsdb/create-operations.mddocs/examples/vectorsdb/create-transaction.mddocs/examples/vectorsdb/delete-document.mddocs/examples/vectorsdb/delete-transaction.mddocs/examples/vectorsdb/get-document.mddocs/examples/vectorsdb/get-transaction.mddocs/examples/vectorsdb/list-documents.mddocs/examples/vectorsdb/list-transactions.mddocs/examples/vectorsdb/update-document.mddocs/examples/vectorsdb/update-transaction.mddocs/examples/vectorsdb/upsert-document.mdexample-swiftui/Shared/ExampleViewModel.swiftexample-uikit/UIKitExample/ViewController.swift
| * 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. |
There was a problem hiding this comment.
Document VectorsDB in the 14.2.0 notes.
Sources/Appwrite/Services/VectorsDB.swift adds a new public service, but the release notes only call out DocumentsDB. That leaves the changelog incomplete for consumers scanning what's new.
Proposed fix
* Added impersonation helpers to set impersonation headers.
* Added `DocumentsDB` service with documents and transactions APIs.
+* Added `VectorsDB` service with documents and transactions APIs.
* Added `upsertDocuments` overloads supporting generic document types.🧰 Tools
🪛 LanguageTool
[style] ~7-~7: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...with documents and transactions APIs. * Added upsertDocuments overloads supporting ...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@CHANGELOG.md` around lines 5 - 10, The 14.2.0 changelog entry documents
DocumentsDB but omits the new public VectorsDB service; update CHANGELOG.md
under the 14.2.0 notes to add a line like "Added VectorsDB service
(Sources/Appwrite/Services/VectorsDB.swift) exposing the VectorsDB public
service" so consumers see the new VectorsDB addition alongside
DocumentsDB—mention the VectorsDB symbol/class name and a brief one-line
description of what it provides.
| databaseId: "<DATABASE_ID>", | ||
| collectionId: "<COLLECTION_ID>", | ||
| documentId: "<DOCUMENT_ID>", | ||
| attribute: "", |
There was a problem hiding this comment.
Use a non-empty attribute placeholder
attribute: "" suggests an invalid value. Prefer a placeholder token to avoid users copying a failing request. Line 14 should be updated.
Proposed docs fix
- attribute: "",
+ attribute: "<ATTRIBUTE_KEY>",📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| attribute: "", | |
| attribute: "<ATTRIBUTE_KEY>", |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/examples/documentsdb/increment-document-attribute.md` at line 14, The
example uses an empty attribute value (attribute: "") which is invalid and
likely to be copied by users; update the example to use a clear placeholder
token such as attribute: "<ATTRIBUTE_NAME>" (or attribute: "myAttribute") so
readers replace it with a real attribute name—locate the attribute field in the
example and replace the empty string with a non-empty placeholder.
| data: [ | ||
| "embeddings": [ | ||
| "0": 0.12, | ||
| "1": -0.55, | ||
| "2": 0.88, | ||
| "3": 1.02 | ||
| ], |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In Appwrite Server 1.9.x / Apple SDK 14.2.0, what JSON shape should a VectorsDB document's embedding field use in createDocument examples: an ordered array of numbers or an object keyed by indices?
💡 Result:
In Appwrite Server 1.9.x with Apple SDK 14.2.0, VectorsDB appears to be an experimental or upcoming feature referred to as "documentsdb" in development (PR #10518), likely for vector embeddings storage. No official documentation or examples for VectorsDB createDocument were found in current sources. Standard Appwrite Databases documents use JSON objects for data, and arrays of numbers are supported as attribute values when the attribute is configured as an array type (e.g., float array). For embedding fields, use an ordered array of numbers [0.1, 0.2, ...], as this is the conventional format for vector embeddings across vector databases (e.g., Supabase vectors use float32 arrays). An object keyed by indices is not standard and unsupported. Configure the embedding attribute as a required float array in the VectorsDB collection.
Citations:
- 1: https://appwrite.io/docs/references/cloud/client-apple/databases
- 2: https://appwrite.io/docs/products/databases/documents
- 3: https://supabase.com/docs/guides/storage/vector/querying-vectors
- 4: documentsdb api appwrite#10518
- 5: https://appwrite.io/docs/products/databases/tables
- 6: https://appwrite.io/docs/databases-queries
- 7: https://appwrite.io/threads/1327217059603415060
Fix the VectorsDB embedding format to use an ordered array.
The current example encodes embeddings as an object with indexed keys ("0", "1", etc.), which is not the standard format for vector embeddings. Vector databases expect embeddings as ordered arrays of numbers. The sample as written will fail when readers copy it.
✏️ Suggested doc fix
data: [
- "embeddings": [
- "0": 0.12,
- "1": -0.55,
- "2": 0.88,
- "3": 1.02
- ],
+ "embeddings": [0.12, -0.55, 0.88, 1.02],
"metadata": [
"key": "value"
]
],📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| data: [ | |
| "embeddings": [ | |
| "0": 0.12, | |
| "1": -0.55, | |
| "2": 0.88, | |
| "3": 1.02 | |
| ], | |
| data: [ | |
| "embeddings": [0.12, -0.55, 0.88, 1.02], | |
| "metadata": [ | |
| "key": "value" | |
| ] | |
| ], |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/examples/vectorsdb/create-document.md` around lines 14 - 20, The example
under data/embeddings currently shows embeddings as an object with numeric
string keys ("0", "1", "2", "3"); change it to an ordered array of numbers so
consumers and vector DBs can parse it correctly — replace the object value for
the embeddings field with an ordered array (e.g., embeddings: [0.12, -0.55,
0.88, 1.02]) wherever the "data" -> "embeddings" example appears.
| open func createDocument<T>( | ||
| databaseId: String, | ||
| collectionId: String, | ||
| documentId: String, | ||
| data: Any, | ||
| permissions: [String]? = nil, | ||
| nestedType: T.Type | ||
| ) async throws -> AppwriteModels.Document<T> { | ||
| 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<T> = { 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<T> | ||
| /// | ||
| 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 | ||
| ) | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's examine the DocumentsDB.swift file to see the method signatures
git ls-files | grep -i "DocumentsDB.swift"Repository: appwrite/sdk-for-apple
Length of output: 109
🏁 Script executed:
# Get the file and check its size
wc -l Sources/Appwrite/Services/DocumentsDB.swiftRepository: appwrite/sdk-for-apple
Length of output: 113
🏁 Script executed:
# Extract the method signatures for create, upsert, update, delete methods
rg -A 8 "open func (createDocument|createDocuments|upsertDocument|updateDocument|deleteDocument)" Sources/Appwrite/Services/DocumentsDB.swift -B 0Repository: appwrite/sdk-for-apple
Length of output: 3231
🏁 Script executed:
# Check the documentation at lines 719-720 and 807-808
sed -n '715,725p; 803,813p' Sources/Appwrite/Services/DocumentsDB.swiftRepository: appwrite/sdk-for-apple
Length of output: 603
🏁 Script executed:
# Get full context of the numeric attribute helper methods
sed -n '716,740p; 804,828p' Sources/Appwrite/Services/DocumentsDB.swiftRepository: appwrite/sdk-for-apple
Length of output: 1528
🌐 Web query:
Appwrite transaction API stageable create operation documentation
💡 Result:
Appwrite's Transactions API allows staging create operations (and other operations) for atomic execution across databases and tables. Official documentation is at https://appwrite.io/docs/products/databases/transactions. ## Workflow 1. Create a transaction: tablesDB.createTransaction returns a transaction object with $id. 2. Stage create operations using transactionId: - Single: tablesDB.createRow({ ..., transactionId: tx.$id }) - Multiple: tablesDB.createOperations({ transactionId: tx.$id, operations: [{ action: 'create', databaseId: '...', tableId: '...', data: { ... } }] }) 3. Commit: tablesDB.updateTransaction({ transactionId: tx.$id, action: 'commit' }) or rollback. Staged operations are not persisted until commit. Supports create, update, upsert, delete, increment/decrement, and bulk variants. Limits apply based on plan (e.g., max operations per transaction). Example (Web SDK): const tx = await tablesDB.createTransaction; await tablesDB.createRow({ databaseId: '<DATABASE_ID>', tableId: '<TABLE_ID>', data: { name: 'Walter' }, transactionId: tx.$id }); await tablesDB.updateTransaction({ transactionId: tx.$id, action: 'commit' }); For full API reference, see https://appwrite.io/docs/references/cloud/databases#databasesCreateTransaction, #databasesCreateRow (with transactionId), etc.
Citations:
- 1: https://appwrite.io/docs/products/databases/transactions
- 2: https://appwrite.io/blog/post/announcing-transactions-api
- 3: https://appwrite.io/docs/products/databases/bulk-operations
🏁 Script executed:
# Let's also check if there's a TablesDB.swift to confirm copy-paste source
fd "TablesDB.swift"Repository: appwrite/sdk-for-apple
Length of output: 106
Add transactionId parameter to createDocument and createDocuments methods.
createDocument and createDocuments are the only mutating document methods in this service that cannot participate in transactions. Appwrite's transaction API supports staging create operations via transactionId, and the other mutating methods (upsertDocument, updateDocument, deleteDocument) already expose this parameter. Without it, callers cannot create documents inside a transaction through DocumentsDB.
Also fix documentation for decrementDocumentAttribute and incrementDocumentAttribute (lines ~719 and ~807): change "column of a row" to "attribute of a document" to correct copy-paste terminology from TablesDB.swift.
Proposed changes
Add transactionId: String? = nil parameter to:
createDocument<T>andcreateDocumentmethod signaturescreateDocuments<T>andcreateDocumentsmethod signatures- Include in
apiParamsdictionary for each method
Update documentation strings:
- Line ~719: "Decrement a specific column of a row" → "Decrement a specific attribute of a document"
- Line ~807: "Increment a specific column of a row" → "Increment a specific attribute of a document"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Sources/Appwrite/Services/DocumentsDB.swift` around lines 297 - 362, Add an
optional transactionId: String? = nil parameter to both createDocument<T>(...)
and the non-generic createDocument(...) overload (and to the
createDocuments<T>/createDocuments overloads) and include "transactionId":
transactionId in their apiParams dictionaries so create operations can
participate in Appwrite transactions; update the method signatures in
DocumentsDB.swift (look for createDocument<T>, createDocument,
createDocuments<T>, createDocuments) and pass transactionId through to
client.call. Also correct the documentation strings for
decrementDocumentAttribute and incrementDocumentAttribute by replacing "column
of a row" with "attribute of a document".
| /// | ||
| /// Decrement a specific column of a row by a given value. |
There was a problem hiding this comment.
Fix the copied TablesDB wording.
These summaries say "column of a row", but this API operates on document attributes. The current text will confuse readers of the public docs.
Proposed fix
- /// Decrement a specific column of a row by a given value.
+ /// Decrement a specific attribute of a document by a given value.
@@
- /// Increment a specific column of a row by a given value.
+ /// Increment a specific attribute of a document by a given value.Also applies to: 807-808
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Sources/Appwrite/Services/DocumentsDB.swift` around lines 719 - 720, The doc
summaries mistakenly use "column of a row" (copied from TablesDB); update the
comments to say "attribute of a document" instead — e.g., change "Decrement a
specific column of a row by a given value." to "Decrement a specific attribute
of a document by a given value." and make the same replacement for the related
summary at the other occurrence (the duplicate comment around lines 807-808) and
any other similar summaries in DocumentsDB.swift (look for the
increment/decrement method summaries or functions handling document attribute
updates) so public docs refer to document attributes, not table columns/rows.
| open func createDocument<T>( | ||
| databaseId: String, | ||
| collectionId: String, | ||
| documentId: String, | ||
| data: Any, | ||
| permissions: [String]? = nil, | ||
| nestedType: T.Type | ||
| ) async throws -> AppwriteModels.Document<T> { | ||
| 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<T> = { 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<T> | ||
| /// | ||
| 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 | ||
| ) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "VectorsDB.swift" -type fRepository: appwrite/sdk-for-apple
Length of output: 109
🏁 Script executed:
wc -l Sources/Appwrite/Services/VectorsDB.swiftRepository: appwrite/sdk-for-apple
Length of output: 111
🏁 Script executed:
# Get method signatures for the mentioned methods
sed -n '1,500p' Sources/Appwrite/Services/VectorsDB.swift | grep -A 8 "func createDocument\|func upsertDocument\|func updateDocument\|func deleteDocument"Repository: appwrite/sdk-for-apple
Length of output: 1367
🏁 Script executed:
sed -n '400,609p' Sources/Appwrite/Services/VectorsDB.swift | grep -A 8 "func updateDocument\|func deleteDocument"Repository: appwrite/sdk-for-apple
Length of output: 1133
🏁 Script executed:
# Also search for transactionId usage across the entire file
grep -n "transactionId" Sources/Appwrite/Services/VectorsDB.swiftRepository: appwrite/sdk-for-apple
Length of output: 2229
🏁 Script executed:
find . -name "Databases.swift" -path "*/Services/*" -type fRepository: appwrite/sdk-for-apple
Length of output: 109
🏁 Script executed:
# Check createDocument signature in Databases.swift
grep -A 8 "func createDocument<T>" Sources/Appwrite/Services/Databases.swift | head -20Repository: appwrite/sdk-for-apple
Length of output: 357
🏁 Script executed:
# Also check other document methods in Databases.swift
grep -A 6 "func upsertDocument\|func updateDocument\|func deleteDocument" Sources/Appwrite/Services/Databases.swift | grep -A 6 "transactionId" | head -30Repository: appwrite/sdk-for-apple
Length of output: 875
Add transactionId parameter to createDocument methods.
In VectorsDB.swift, createDocument is the only document mutation method without transactionId support. The standard Databases.swift service includes it on createDocument, and upsertDocument, updateDocument, and deleteDocument in VectorsDB.swift already have it. This gap prevents creating vector documents within transactions.
Proposed fix
open func createDocument<T>(
databaseId: String,
collectionId: String,
documentId: String,
data: Any,
permissions: [String]? = nil,
+ transactionId: String? = nil,
nestedType: T.Type
) async throws -> AppwriteModels.Document<T> {
@@
let apiParams: [String: Any?] = [
"documentId": documentId,
"data": data,
- "permissions": permissions
+ "permissions": permissions,
+ "transactionId": transactionId
]
@@
open func createDocument(
databaseId: String,
collectionId: String,
documentId: String,
data: Any,
- permissions: [String]? = nil
+ permissions: [String]? = nil,
+ transactionId: String? = nil
) async throws -> AppwriteModels.Document<[String: AnyCodable]> {
return try await createDocument(
databaseId: databaseId,
collectionId: collectionId,
documentId: documentId,
data: data,
permissions: permissions,
+ transactionId: transactionId,
nestedType: [String: AnyCodable].self
)
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Sources/Appwrite/Services/VectorsDB.swift` around lines 286 - 345, Add an
optional transactionId: String? parameter (default nil) to both
createDocument<T>(...) and the non-generic createDocument(...) overloads in
VectorsDB.swift, include "transactionId": transactionId in the apiParams
dictionary used by createDocument<T>, and update the non-generic createDocument
to forward the new transactionId when calling the generic createDocument (keep
nestedType forwarding as-is). Reference the
createDocument<T>(databaseId:collectionId:documentId:data:permissions:nestedType:)
function and the
createDocument(databaseId:collectionId:documentId:data:permissions:) overload to
locate where to add the parameter and apiParams entry.
| public let id: String | ||
| /// Document sequence ID. | ||
| public let sequence: Int | ||
| public let sequence: String |
There was a problem hiding this comment.
Breaking change: sequence type changed from Int to String.
This is an API-breaking change. Existing code that accesses document.sequence as an Int will fail to compile. The change is consistent with Row.swift which also uses String for sequence, indicating an intentional alignment with server API changes.
Ensure this breaking change is documented in the CHANGELOG or migration notes.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Sources/AppwriteModels/Document.swift` at line 21, The Document model's
public property sequence was changed from Int to String (public let sequence:
String), which is an API-breaking change; update the project's
CHANGELOG/migration notes to document this breaking change and provide migration
guidance (e.g., treat Document.sequence as String or convert with
Int(Document.sequence) where numeric semantics are required), then search for
and update all code paths, tests, and Codable decoding logic that expect
Document.sequence as Int (and any references in Row.swift comparisons) to either
accept String or explicitly convert/parse it to Int, ensuring compile-time fixes
and adding a note about server API alignment.
This PR contains updates to the Apple SDK for version 16.0.0.
Summary by CodeRabbit
Breaking Changes
sequencefield changed from Int to String in Row and Document models.New Features
Documentation