Skip to content

Conversation

abnegate
Copy link
Member

@abnegate abnegate commented Sep 12, 2025

This PR contains updates to the Node.js SDK for version 19.1.0-rc.1.

Summary by CodeRabbit

  • New Features
    • Added full transaction support for Databases and TablesDB: create, list, get, update (commit/rollback), delete, and batch operations.
    • Most document/row CRUD and attribute/column operations now accept an optional transactionId for staged changes.
  • Documentation
    • Added examples for all transaction flows and operations batching.
    • Updated CRUD samples to include optional transactionId.
    • Clarified geometry defaults in line/point/polygon examples.
    • Tweaked messaging push examples (image placeholder).
  • Chores
    • Bumped SDK version to 19.1.0-rc.1.
  • Style/Types
    • Tightened Query.equal and Query.notEqual typings (no runtime behavior change).

Copy link

coderabbitai bot commented Sep 12, 2025

Walkthrough

This update introduces transaction support across Databases and TablesDB services. New APIs were added: listTransactions, createTransaction, getTransaction, updateTransaction, deleteTransaction, and createOperations. Many CRUD and attribute/column methods now accept an optional transactionId, with overloads updated accordingly. Models gained Transaction and TransactionList types. Query.equal and Query.notEqual signatures were narrowed. SDK version bumped to 19.1.0-rc.1 with updated user agent/header. Extensive docs/examples were added or revised to include transactionId and adjusted geometry defaults. Messaging examples changed an image placeholder format.

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "feat: Node.js SDK update for version 19.1.0-rc.1" is directly related to the changeset (package/client version bump and wide SDK updates) and is concise and clear; however, it does not explicitly call out the primary functional addition (transactional APIs across Databases and TablesDB).
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-txn

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
docs/examples/tablesdb/increment-row-column.md (1)

1-18: Top‑level await with CommonJS will not run; wrap call or switch to ESM.

Using require() plus await at top level will throw in Node unless you’re in an ES module. Either wrap calls in an async IIFE or switch to import with "type":"module".

Example minimal fix (IIFE around the call):

 const tablesDB = new sdk.TablesDB(client);
 
-const result = await tablesDB.incrementRowColumn({
+(async () => {
+  const result = await tablesDB.incrementRowColumn({
     databaseId: '<DATABASE_ID>',
     tableId: '<TABLE_ID>',
     rowId: '<ROW_ID>',
     column: '',
-    value: null, // optional
-    max: null, // optional
+    // value: 1, // optional
+    // max: 10, // optional
     transactionId: '<TRANSACTION_ID>' // optional
-});
+  });
+  console.log(result);
+})().catch(console.error);
docs/examples/databases/delete-transaction.md (1)

1-13: Make snippet runnable and clarify return.

  • Wrap call (top‑level await + CommonJS).
  • Many delete endpoints return void/empty; assigning to result may confuse.
-const result = await databases.deleteTransaction({
-    transactionId: '<TRANSACTION_ID>'
-});
+await databases.deleteTransaction({
+  transactionId: '<TRANSACTION_ID>',
+});
+console.log('Transaction deleted');
docs/examples/databases/decrement-document-attribute.md (1)

10-18: Avoid nulls for optional fields; fix top-level await in CommonJS example

Passing null will be sent to the API (typeof null !== 'undefined'), likely causing validation errors. Also, top-level await with require() is invalid in CJS.

Apply either approach:

Option A — keep CJS and wrap in an async IIFE, omit unused keys:

-const result = await databases.decrementDocumentAttribute({
+;(async () => {
+  const result = await databases.decrementDocumentAttribute({
     databaseId: '<DATABASE_ID>',
     collectionId: '<COLLECTION_ID>',
     documentId: '<DOCUMENT_ID>',
     attribute: '',
-    value: null, // optional
-    min: null, // optional
-    transactionId: '<TRANSACTION_ID>' // optional
-});
+    // value: 1, // optional
+    // min: 0, // optional
+    // transactionId: '<TRANSACTION_ID>', // optional
+  });
+  console.log(result);
+})();

Option B — switch to ESM import (top-level await ok) and omit nulls.

docs/examples/tablesdb/delete-rows.md (1)

1-15: Fix: top-level await with CJS

Same issue here—require + top‑level await. Wrap in an async IIFE (or convert to ESM).

-const sdk = require('node-appwrite');
-
-const client = new sdk.Client()
-    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
-    .setProject('<YOUR_PROJECT_ID>') // Your project ID
-    .setKey('<YOUR_API_KEY>'); // Your secret API key
-
-const tablesDB = new sdk.TablesDB(client);
-
-const result = await tablesDB.deleteRows({
-    databaseId: '<DATABASE_ID>',
-    tableId: '<TABLE_ID>',
-    queries: [], // optional
-    transactionId: '<TRANSACTION_ID>' // optional
-});
+(async () => {
+  const sdk = require('node-appwrite');
+
+  const client = new sdk.Client()
+    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
+    .setProject('<YOUR_PROJECT_ID>') // Your project ID
+    .setKey('<YOUR_API_KEY>'); // Your secret API key
+
+  const tablesDB = new sdk.TablesDB(client);
+
+  const result = await tablesDB.deleteRows({
+    databaseId: '<DATABASE_ID>',
+    tableId: '<TABLE_ID>',
+    queries: [], // optional
+    transactionId: '<TRANSACTION_ID>' // optional
+  });
+  console.log(result);
+})().catch(console.error);
docs/examples/databases/create-operations.md (1)

1-24: Fix: make Node example CommonJS-safe, use ID.unique(), and mark operations required

Top-level await is invalid with require(); wrap in an async IIFE, prefer ID.unique() for server-safe IDs, and change the operations comment to "required".

-const sdk = require('node-appwrite');
-
-const client = new sdk.Client()
-    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
-    .setProject('<YOUR_PROJECT_ID>') // Your project ID
-    .setKey('<YOUR_API_KEY>'); // Your secret API key
-
-const databases = new sdk.Databases(client);
-
-const result = await databases.createOperations({
-    transactionId: '<TRANSACTION_ID>',
-    operations: [
-	    {
-	        "action": "create",
-	        "databaseId": "<DATABASE_ID>",
-	        "collectionId": "<COLLECTION_ID>",
-	        "documentId": "<DOCUMENT_ID>",
-	        "data": {
-	            "name": "Walter O'Brien"
-	        }
-	    }
-	] // optional
-});
+(async () => {
+  const sdk = require('node-appwrite');
+  const { ID } = sdk;
+
+  const client = new sdk.Client()
+    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
+    .setProject('<YOUR_PROJECT_ID>') // Your project ID
+    .setKey('<YOUR_API_KEY>'); // Your secret API key
+
+  const databases = new sdk.Databases(client);
+
+  const result = await databases.createOperations({
+    transactionId: '<TRANSACTION_ID>',
+    operations: [
+      {
+        action: 'create',
+        databaseId: '<DATABASE_ID>',
+        collectionId: '<COLLECTION_ID>',
+        documentId: ID.unique(),
+        data: { name: "Walter O'Brien" }
+      }
+    ] // required
+  });
+  console.log(result);
+})().catch(console.error);
docs/examples/databases/upsert-documents.md (1)

1-16: Fix: top-level await with CJS

Wrap with an async IIFE (or convert the whole snippet to ESM).

-const sdk = require('node-appwrite');
-
-const client = new sdk.Client()
-    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
-    .setProject('<YOUR_PROJECT_ID>') // Your project ID
-    .setKey('<YOUR_API_KEY>'); // Your secret API key
-
-const databases = new sdk.Databases(client);
-
-const result = await databases.upsertDocuments({
-    databaseId: '<DATABASE_ID>',
-    collectionId: '<COLLECTION_ID>',
-    documents: [],
-    transactionId: '<TRANSACTION_ID>' // optional
-});
+(async () => {
+  const sdk = require('node-appwrite');
+
+  const client = new sdk.Client()
+    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
+    .setProject('<YOUR_PROJECT_ID>') // Your project ID
+    .setKey('<YOUR_API_KEY>'); // Your secret API key
+
+  const databases = new sdk.Databases(client);
+
+  const result = await databases.upsertDocuments({
+    databaseId: '<DATABASE_ID>',
+    collectionId: '<COLLECTION_ID>',
+    documents: [
+      // Provide at least one document; include identifier fields as required by API.
+      // { $id: 'user_123', name: 'Alice' }
+    ],
+    transactionId: '<TRANSACTION_ID>' // optional
+  });
+  console.log(result);
+})().catch(console.error);
♻️ Duplicate comments (6)
docs/examples/databases/update-polygon-attribute.md (1)

1-18: Same top‑level await + CommonJS issue as other examples.

Apply the same IIFE or ESM pattern here for runnable snippets.

docs/examples/databases/update-line-attribute.md (1)

1-18: Same top‑level await + CommonJS issue as other examples.

Wrap in IIFE or migrate to ESM.

docs/examples/databases/create-line-attribute.md (1)

1-17: Same top‑level await + CommonJS issue as other examples.

Apply IIFE or ESM.

docs/examples/tablesdb/create-polygon-column.md (1)

1-17: Same top‑level await + CommonJS issue as other examples.

Wrap or switch to ESM.

docs/examples/tablesdb/create-line-column.md (1)

1-17: Same top‑level await + CommonJS issue as other examples.

Apply IIFE or ESM.

docs/examples/tablesdb/update-polygon-column.md (1)

1-18: Same top‑level await + CommonJS issue as other examples.

Wrap or use ESM.

🧹 Nitpick comments (37)
docs/examples/tablesdb/update-point-column.md (2)

15-15: Point default shape is correct; add coord-order hint.

[1, 2] matches a Point’s [x, y] (lon, lat) shape. Consider clarifying the order to avoid confusion.

-    default: [1, 2], // optional
+    default: [1, 2], // optional, [longitude, latitude]

10-17: Top‑level await with CommonJS require will not run as shown.

This snippet uses require(...) (CJS) plus top‑level await, which Node.js only supports in ESM. Wrap the call in an async IIFE to keep CJS.

-const result = await tablesDB.updatePointColumn({
+(async () => {
+  const result = await tablesDB.updatePointColumn({
     databaseId: '<DATABASE_ID>',
     tableId: '<TABLE_ID>',
     key: '',
     required: false,
     default: [1, 2], // optional
     newKey: '' // optional
-});
+  });
+})().catch(console.error);
package.json (1)

5-5: Versions match — centralize SDK version to avoid future drift.
package.json v19.1.0-rc.1 matches UA and 'x-sdk-version' literals in src/client.ts (lines 36, 85). Centralize the version (e.g., build-time define or shared constant) and consume it in src/client.ts for UA and header.

src/client.ts (1)

36-36: Single constant for SDK version (used in UA and headers).

Reduce the risk of mismatch by referencing one constant instead of duplicating the literal.

Apply within the changed lines:

-    let ua = 'AppwriteNodeJSSDK/19.1.0-rc.1';
+    let ua = `AppwriteNodeJSSDK/${SDK_VERSION}`;
-        'x-sdk-version': '19.1.0-rc.1',
+        'x-sdk-version': SDK_VERSION,

Add near the top of this file (or a small versions.ts module) to support the above:

export const SDK_VERSION = '19.1.0-rc.1';

Also applies to: 85-85

docs/examples/tablesdb/create-point-column.md (1)

15-15: Clarify coordinate order in example.

Add a brief note on expected order (e.g., [longitude, latitude]) to reduce ambiguity for Geo inputs.

docs/examples/databases/create-point-attribute.md (1)

15-15: Document point shape clearly.

Since default is a single point [1, 2], add a short comment about coordinate order and units to prevent misuse.

docs/examples/databases/update-point-attribute.md (1)

15-15: Add a note about point semantics.

Consider appending a comment indicating the coordinate order and valid ranges.

docs/examples/databases/create-polygon-attribute.md (1)

15-15: Explain polygon structure/closure in the snippet.

The example shows a closed ring (first=last). Add a one-liner stating rings must be closed and nested arrays represent polygons (and possibly orientation if required).

docs/examples/tablesdb/increment-row-column.md (1)

15-17: Avoid sending nulls for optional numeric fields.

If unset, omit value/max rather than sending null to reduce payload noise and potential validation issues.

docs/examples/databases/increment-document-attribute.md (1)

16-18: Clarify the provenance of transactionId in the snippet.

Add a short hint so users know to pass the ID returned by createTransaction.

-    transactionId: '<TRANSACTION_ID>' // optional
+    transactionId: '<TRANSACTION_ID>' // optional, from Databases.createTransaction()
src/services/databases.ts (4)

305-324: Clarify JSDoc: updateTransaction action semantics

Docstrings should state “Exactly one of commit or rollback must be true.”


424-482: Make operations required (or guard empty) in createOperations

Server likely expects at least one operation. Either make it required or reject empty arrays for better DX. Also consider adding a typed Operation model instead of object[].

-    createOperations(params: { transactionId: string, operations?: object[]  }): Promise<Models.Transaction>;
+    createOperations(params: { transactionId: string, operations: object[]  }): Promise<Models.Transaction>;

If you must keep it optional for BC, add a runtime check:

         const transactionId = params.transactionId;
         const operations = params.operations;

         if (typeof transactionId === 'undefined') {
             throw new AppwriteException('Missing required parameter: "transactionId"');
         }
+        if (!operations || operations.length === 0) {
+            throw new AppwriteException('Missing required parameter: "operations" (non-empty)');
+        }

232-239: Validate positive ttl in createTransaction

Guard non-positive values to fail fast client-side.

-        const ttl = params.ttl;
+        const ttl = params.ttl;
+        if (typeof ttl !== 'undefined' && (!Number.isFinite(ttl) || ttl <= 0)) {
+            throw new AppwriteException('Parameter "ttl" must be a positive number of seconds.');
+        }

Also applies to: 241-252


4649-4662: Fix JSDoc wording for decrementDocumentAttribute

Wording says “Value to increment…” on a decrement API.

- * @param {number} value - Value to increment the attribute by. The value must be a number.
+ * @param {number} value - Value to decrement the attribute by. The value must be a number.
src/services/tables-db.ts (2)

324-368: Disallow conflicting commit/rollback flags.

If both commit and rollback are true, the request is contradictory. Add a guard to fail fast.

Apply this diff inside updateTransaction() after extracting params:

 const transactionId = params.transactionId;
 const commit = params.commit;
 const rollback = params.rollback;

+if (commit === true && rollback === true) {
+    throw new AppwriteException('Only one of "commit" or "rollback" can be true.');
+}

4079-4092: Fix doc typos: wrong service name and broken docs link.

- * @param {string} params.tableId - Table ID. You can create a new table using the TableDB service [server integration](https://appwrite.io/docs/server/tablesdbdb#tablesdbCreate).
+ * @param {string} params.tableId - Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).
docs/examples/tablesdb/get-transaction.md (1)

10-12: Top-level await with require() can fail under CJS.

Wrap in an async IIFE or switch to ESM import in examples to avoid confusion.

-const result = await tablesDB.getTransaction({
-    transactionId: '<TRANSACTION_ID>'
-});
+(async () => {
+  const result = await tablesDB.getTransaction({ transactionId: '<TRANSACTION_ID>' });
+  console.log(result);
+})();
docs/examples/tablesdb/create-row.md (1)

3-6: Auth consistency: confirm session vs API key for write.

Creating rows is a write op; most server-side examples use .setKey(...). If this is meant for client-side/session usage, add a note; otherwise switch to API key for consistency.

-    .setSession(''); // The user session to authenticate with
+    .setKey('<YOUR_API_KEY>'); // Your secret API key
docs/examples/tablesdb/create-rows.md (1)

13-15: Consider adding a minimal row example to avoid empty payload confusion.

An empty rows: [] is valid but not illustrative. Add one example row.

-    rows: [],
+    rows: [
+      {
+        rowId: '<ROW_ID>',
+        data: { /* ...columns... */ },
+        // permissions: [sdk.Permission.read(sdk.Role.any())], // optional
+      }
+    ],
docs/examples/tablesdb/list-transactions.md (1)

10-12: Enhance with pagination/filter query examples.

Showing Query.limit(...)/Query.offset(...) (or filters) would make the example more practical.

-const result = await tablesDB.listTransactions({
-    queries: [] // optional
-});
+const result = await tablesDB.listTransactions({
+  queries: [
+    sdk.Query.limit(25),
+    sdk.Query.offset(0),
+    // sdk.Query.equal('status', 'open'),
+  ], // optional
+});
docs/examples/databases/create-documents.md (1)

13-15: Show at least one sample document to clarify payload shape.

A concrete item helps readers understand expected keys.

-    documents: [],
+    documents: [
+      {
+        documentId: '<DOCUMENT_ID>',
+        data: { /* ... */ },
+        // permissions: [sdk.Permission.read(sdk.Role.any())], // optional
+      }
+    ],
docs/examples/databases/update-documents.md (1)

14-15: Docs update LGTM; add a small runtime note about top‑level await.

The transactionId addition and trailing comma fix look good. One nit: this snippet uses require(...) (CommonJS) with top‑level await. That won’t run in Node unless the file is ESM (type: module/.mjs) or you wrap calls in an async IIFE. Consider adding a one‑line note or switching to import in examples.

docs/examples/databases/get-document.md (1)

14-15: Docs update LGTM; mind top‑level await with CommonJS.

Change is fine. Same nit as elsewhere: require + top‑level await will fail outside ESM. Add a brief note or wrap calls in an async IIFE to avoid confusion.

docs/examples/tablesdb/update-rows.md (1)

14-15: Looks good; add ESM/await note for consistency.

transactionId addition is clear. Please add the same ESM/top‑level await caveat as in other snippets to keep behavior expectations consistent across docs.

docs/examples/databases/upsert-document.md (1)

16-16: Minor: clarify transactionId meaning.

Consider a short comment “ID from createTransaction; operation runs inside that transaction if provided” to reduce ambiguity.

docs/examples/databases/create-transaction.md (1)

11-12: Clarify TTL units and top‑level await context.

  • Note TTL units (seconds?) to avoid guessing.
  • As elsewhere, require + top‑level await needs ESM or an async wrapper.
docs/examples/tablesdb/create-transaction.md (1)

11-12: Same TTL/await notes apply here.

Add “TTL in seconds” and the ESM/top‑level await caveat for parity with Databases docs.

docs/examples/databases/get-transaction.md (1)

11-12: LGTM; add small ESM/await note.

The example reads well. Add the standard note about top‑level await with CommonJS to prevent copy‑paste runtime errors.

docs/examples/tablesdb/delete-transaction.md (1)

11-12: LGTM; add the ESM/await caveat.

Mirror the top‑level await guidance used in other updated snippets.

docs/examples/databases/create-document.md (1)

1-23: Optional: avoid top-level await with CommonJS require.

These snippets use require(), where top-level await isn’t valid. Consider wrapping the call in an async IIFE to make it copy-paste runnable.

docs/examples/databases/list-transactions.md (1)

10-12: LGTM. Consider showcasing a simple filter query.

Optionally demonstrate a basic query (e.g., status or createdAt) to make the example more actionable.

docs/examples/tablesdb/create-operations.md (1)

1-23: Optional: avoid top-level await with CommonJS require.

Wrap in an async IIFE for copy-paste friendliness.

docs/examples/databases/update-document.md (1)

1-18: Optional: avoid top-level await with CommonJS require.

Wrap in an async IIFE for copy-paste execution.

docs/examples/tablesdb/upsert-rows.md (1)

13-15: Provide a concrete row example instead of an empty array.

A minimal row object helps users understand the payload shape.

-    rows: [],
+    rows: [
+      {
+        rowId: '<ROW_ID>',
+        data: { name: 'Walter O\'Brien' }
+      }
+    ],
     transactionId: '<TRANSACTION_ID>' // optional
docs/examples/tablesdb/update-transaction.md (1)

10-14: Clarify mutually exclusive flags

Presenting both commit and rollback (even as false) can confuse users. Show one intented path (commit or rollback) and omit the other.

Can you confirm API semantics: are commit and rollback mutually exclusive, and does omitting both leave the transaction “open”?

docs/examples/tablesdb/delete-rows.md (1)

10-15: Doc hint: required inputs vs queries

If deleteRows requires either specific row IDs or a non-empty queries to match rows, consider showing a minimal working filter or IDs to avoid “no-op” confusion.

Please confirm expected required fields for deleteRows in transactional context so we can adjust the example accordingly.

docs/examples/databases/upsert-documents.md (1)

10-15: Improve example fidelity

An empty documents: [] is a no-op. Show a minimal valid upsert payload (with identifiers per API contract) to help users copy-paste and run.

Please confirm whether upsert requires $id/primary key fields per document, or uses another matching strategy.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a6785a and 45b799f.

📒 Files selected for processing (56)
  • docs/examples/databases/create-document.md (1 hunks)
  • docs/examples/databases/create-documents.md (1 hunks)
  • docs/examples/databases/create-line-attribute.md (1 hunks)
  • docs/examples/databases/create-operations.md (1 hunks)
  • docs/examples/databases/create-point-attribute.md (1 hunks)
  • docs/examples/databases/create-polygon-attribute.md (1 hunks)
  • docs/examples/databases/create-transaction.md (1 hunks)
  • docs/examples/databases/decrement-document-attribute.md (1 hunks)
  • docs/examples/databases/delete-document.md (1 hunks)
  • docs/examples/databases/delete-documents.md (1 hunks)
  • docs/examples/databases/delete-transaction.md (1 hunks)
  • docs/examples/databases/get-document.md (1 hunks)
  • docs/examples/databases/get-transaction.md (1 hunks)
  • docs/examples/databases/increment-document-attribute.md (1 hunks)
  • docs/examples/databases/list-documents.md (1 hunks)
  • docs/examples/databases/list-transactions.md (1 hunks)
  • docs/examples/databases/update-document.md (1 hunks)
  • docs/examples/databases/update-documents.md (1 hunks)
  • docs/examples/databases/update-line-attribute.md (1 hunks)
  • docs/examples/databases/update-point-attribute.md (1 hunks)
  • docs/examples/databases/update-polygon-attribute.md (1 hunks)
  • docs/examples/databases/update-transaction.md (1 hunks)
  • docs/examples/databases/upsert-document.md (1 hunks)
  • docs/examples/databases/upsert-documents.md (1 hunks)
  • docs/examples/messaging/create-push.md (1 hunks)
  • docs/examples/messaging/update-push.md (1 hunks)
  • docs/examples/tablesdb/create-line-column.md (1 hunks)
  • docs/examples/tablesdb/create-operations.md (1 hunks)
  • docs/examples/tablesdb/create-point-column.md (1 hunks)
  • docs/examples/tablesdb/create-polygon-column.md (1 hunks)
  • docs/examples/tablesdb/create-row.md (1 hunks)
  • docs/examples/tablesdb/create-rows.md (1 hunks)
  • docs/examples/tablesdb/create-transaction.md (1 hunks)
  • docs/examples/tablesdb/decrement-row-column.md (1 hunks)
  • docs/examples/tablesdb/delete-row.md (1 hunks)
  • docs/examples/tablesdb/delete-rows.md (1 hunks)
  • docs/examples/tablesdb/delete-transaction.md (1 hunks)
  • docs/examples/tablesdb/get-row.md (1 hunks)
  • docs/examples/tablesdb/get-transaction.md (1 hunks)
  • docs/examples/tablesdb/increment-row-column.md (1 hunks)
  • docs/examples/tablesdb/list-rows.md (1 hunks)
  • docs/examples/tablesdb/list-transactions.md (1 hunks)
  • docs/examples/tablesdb/update-line-column.md (1 hunks)
  • docs/examples/tablesdb/update-point-column.md (1 hunks)
  • docs/examples/tablesdb/update-polygon-column.md (1 hunks)
  • docs/examples/tablesdb/update-row.md (1 hunks)
  • docs/examples/tablesdb/update-rows.md (1 hunks)
  • docs/examples/tablesdb/update-transaction.md (1 hunks)
  • docs/examples/tablesdb/upsert-row.md (1 hunks)
  • docs/examples/tablesdb/upsert-rows.md (1 hunks)
  • package.json (1 hunks)
  • src/client.ts (2 hunks)
  • src/models.ts (2 hunks)
  • src/query.ts (1 hunks)
  • src/services/databases.ts (37 hunks)
  • src/services/tables-db.ts (35 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-05T09:48:56.219Z
Learnt from: abnegate
PR: appwrite/sdk-for-node#121
File: docs/examples/databases/create-line-attribute.md:10-16
Timestamp: 2025-09-05T09:48:56.219Z
Learning: Documentation examples in .md files in the Appwrite Node.js SDK are illustrative and don't need to be strictly correct or executable code. They focus on showing API structure and usage patterns rather than being copy-paste ready.

Applied to files:

  • docs/examples/tablesdb/create-operations.md
  • docs/examples/databases/update-transaction.md
🧬 Code graph analysis (3)
src/query.ts (2)
src/client.ts (2)
  • QueryTypes (389-389)
  • Query (387-387)
src/index.ts (2)
  • QueryTypes (17-17)
  • Query (1-1)
src/services/tables-db.ts (1)
src/models.ts (5)
  • TransactionList (487-496)
  • Transaction (3828-3853)
  • Row (1985-2014)
  • DefaultRow (2016-2019)
  • RowList (11-20)
src/services/databases.ts (1)
src/models.ts (5)
  • TransactionList (487-496)
  • Transaction (3828-3853)
  • Document (2024-2053)
  • DefaultDocument (2055-2058)
  • DocumentList (25-34)
🔇 Additional comments (30)
docs/examples/messaging/create-push.md (1)

19-19: LGTM: placeholder format is now consistent.

Angle-bracket placeholder aligns with other docs. No further changes needed.

docs/examples/messaging/update-push.md (1)

19-19: LGTM: consistent placeholder style.

Matches create-push example; keeps docs uniform.

docs/examples/tablesdb/increment-row-column.md (1)

6-6: Auth method consistency check (session vs API key).

Most other examples use .setKey(...). Confirm .setSession('') here is intentional for TablesDB write ops; otherwise align to .setKey(...).

docs/examples/databases/update-polygon-attribute.md (1)

15-15: Polygon default looks correct (closed ring).

Ring starts/ends with [1, 2]. LGTM.

docs/examples/databases/update-line-attribute.md (1)

15-15: Line default expanded to 3 points—LGTM.

Meets “>=2 points” expectation for a line.

docs/examples/databases/create-line-attribute.md (1)

15-15: Updated default to 3 points—LGTM.

docs/examples/tablesdb/create-polygon-column.md (1)

15-15: Polygon default uses ring array—LGTM.

Closed ring and correct nesting.

docs/examples/tablesdb/create-line-column.md (1)

15-15: Line default to 3 points—LGTM.

docs/examples/tablesdb/update-polygon-column.md (1)

15-15: Polygon default ring/nesting—LGTM.

src/query.ts (1)

55-59: Type narrowing LGTM; no runtime change.

Switching equal/notEqual to QueryTypes removes redundant any[] while preserving array support via QueryTypesList. Good cleanup.

Also applies to: 65-69

src/models.ts (2)

484-497: TransactionList shape LGTM.

Naming and structure match other *List models.


3825-3853: Transaction model OK — single declaration found

export type Transaction is declared once at src/models.ts:3828; services reference it as Models.Transaction (e.g. src/services/tables-db.ts, src/services/databases.ts).

src/services/databases.ts (4)

3894-3979: Transaction API surface and document-level transactionId wiring look consistent

Good coverage across create/get/list/update/delete and batch ops. Overloads remain backward compatible with a trailing optional transactionId.

Also applies to: 3987-4057, 4063-4137, 4146-4219, 424-482, 4477-4556, 4743-4823, 3823-3850


5000-5009: No-op doc diff around getIndex

Looks like formatting-only; nothing to flag.

Also applies to: 5011-5020


4227-4294: DELETE param serialization — transactionId is sent in the JSON body, not as a query param

client.call only appends params to the URL for GET; for non-GET methods (including DELETE) it JSON.stringify()s the payload when content-type is application/json. deleteDocuments builds payload['transactionId'] and calls client.call('delete', ...), so transactionId will be sent in the request body — confirm the server accepts JSON bodies on DELETE. If not, move transactionId to the query string (or adjust client.call to treat DELETE like GET).
Location: src/services/databases.ts (4227-4294). Also applies to 4564-4631.


3818-3872: Confirmed: GET payload serialized to URL query params.

prepareRequest (src/client.ts, ~lines 216–280) flattens params and appends them to url.searchParams when method === 'GET', so transactionId and queries are encoded into the request URL.

src/services/tables-db.ts (6)

149-198: Transactions API surface and wiring look solid.

Overloads, parameter parsing, required checks, paths, and payload construction for list/create/get/update/delete transactions and createOperations are consistent with the SDK’s conventions.

Also applies to: 200-250, 252-301, 303-368, 370-420, 422-480


4082-4147: listRows: transactionId overloading and payload wiring LGTM.


4157-4241: Row create/upsert/update: transactionId parsing and JSON payload propagation are correct.

Also applies to: 4643-4720, 4731-4808


4248-4318: Bulk rows (create/upsert/update/delete): positional overloads and transactionId are correctly ordered and forwarded.

Also applies to: 4327-4397, 4406-4478, 4486-4552


4561-4632: getRow: optional transactionId for reading staged state is wired correctly.


4894-4977: Arithmetic ops: transactionId support is consistent; body keys (value/min/max) are conditionally included as expected.

Also applies to: 4989-5072

docs/examples/tablesdb/list-rows.md (1)

13-15: LGTM — transactionId wiring looks correct.

Optional queries and transactionId are shown clearly.

docs/examples/databases/delete-documents.md (1)

13-15: LGTM — docs correctly add optional transactionId.

Formatting and placement look consistent with other samples.

docs/examples/databases/list-documents.md (1)

13-15: LGTM — optional transactionId addition is clear.

No issues spotted.

docs/examples/databases/delete-document.md (1)

13-15: LGTM — example reads cleanly with transactionId.

Consistent with the other single-document operations.

docs/examples/tablesdb/delete-row.md (1)

13-15: LGTM. Add a quick auth note?

Doc reads well and shows the optional transactionId clearly. If delete operations require elevated privileges in your setup, consider swapping setSession for setKey in this specific example to avoid confusion.

docs/examples/tablesdb/create-operations.md (1)

10-23: Confirm whether “operations” is required; example labels it optional.

If the API requires at least one operation, mark the field as required in the doc to prevent misuse.

docs/examples/databases/update-transaction.md (1)

10-14: Clarify commit vs rollback semantics.

If exactly one of commit or rollback must be true, show one variant (e.g., commit: true) and omit the other to avoid ambiguity.

-    commit: false, // optional
-    rollback: false // optional
+    commit: true // set either commit or rollback as required by the API
docs/examples/tablesdb/get-row.md (1)

14-15: LGTM.

Transaction-aware read example looks clear and consistent.

Comment on lines +21 to 23
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix invalid permissions syntax (broken quotes) and prefer Permission/Role helpers.

The string ["read("any")"] is invalid JS. Use SDK helpers for clarity.

Apply:

-    permissions: ["read("any")"], // optional
+    permissions: [sdk.Permission.read(sdk.Role.any())], // optional
     transactionId: '<TRANSACTION_ID>' // optional
📝 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.

Suggested change
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
permissions: [sdk.Permission.read(sdk.Role.any())], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
🤖 Prompt for AI Agents
In docs/examples/databases/create-document.md around lines 21 to 23, the
permissions line uses invalid JS syntax with nested quotes (`["read("any")"]`);
replace it with the SDK permission/role helper usage (for example use
Permission.read('any') or Role.any() inside the array) and ensure the helper is
imported or referenced correctly so the permissions array is valid JS.

Comment on lines +15 to +16
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix invalid permissions syntax (broken quotes) and prefer Permission/Role helpers.

Use SDK helpers to avoid syntax errors and mirror recommended usage.

-    permissions: ["read("any")"], // optional
+    permissions: [sdk.Permission.read(sdk.Role.any())], // optional
     transactionId: '<TRANSACTION_ID>' // optional
📝 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.

Suggested change
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
permissions: [sdk.Permission.read(sdk.Role.any())], // optional
transactionId: '<TRANSACTION_ID>' // optional
🤖 Prompt for AI Agents
In docs/examples/databases/update-document.md around lines 15 to 16 the
permissions array uses invalid/broken inline quotes ("read("any")") and should
use the SDK Permission/Role helper functions instead; replace the string-based
permission with the SDK helper (e.g., Permission.read("any") or Role.any where
appropriate) so syntax is correct and follows recommended usage, and keep
transactionId as-is.

Comment on lines +15 to +16
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix invalid permissions example.

"read("any")" is incorrectly quoted and will throw. In the Node SDK, we typically use helpers. Suggest:

-    permissions: ["read("any")"], // optional
+    permissions: [sdk.Permission.read(sdk.Role.any())], // optional

Alternatively, if showing raw strings, use single quotes inside: 'read("any")'.

📝 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.

Suggested change
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
permissions: [sdk.Permission.read(sdk.Role.any())], // optional
transactionId: '<TRANSACTION_ID>' // optional
🤖 Prompt for AI Agents
In docs/examples/databases/upsert-document.md around lines 15 to 16, the
permissions example uses invalid quoting ("read("any")") which will throw;
update the example to use the SDK helper for read permissions (e.g., a
permissions helper function/object) or, if showing raw strings, escape/replace
the quotes correctly by using single quotes around the entire permission string
like 'read("any")' so the inner double quotes are preserved.

Comment on lines +21 to +22
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix invalid permissions string quoting; use Permission/Role helpers.

The current string literal is syntactically invalid in JS. Prefer the SDK helpers for clarity and type-safety.

Apply:

-    permissions: ["read("any")"], // optional
+    permissions: [sdk.Permission.read(sdk.Role.any())], // optional
📝 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.

Suggested change
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
permissions: [sdk.Permission.read(sdk.Role.any())], // optional
transactionId: '<TRANSACTION_ID>' // optional
🤖 Prompt for AI Agents
In docs/examples/tablesdb/create-row.md around lines 21–22, the permissions
entry uses an invalid JS string literal ("read("any")"); replace that string
with the SDK Permission/Role helper usage (call Permission.read with Role.any()
as the argument) and ensure Permission and Role are imported from the SDK; keep
transactionId as-is optional.

Comment on lines 15 to 18
value: null, // optional
min: null // optional
min: null, // optional
transactionId: '<TRANSACTION_ID>' // optional
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Don’t use null for numeric fields; omit or use a number.

value/min are number | undefined. null will be sent and likely rejected.

-    value: null, // optional
-    min: null, // optional
+    // value: 1, // optional
+    // min: 0, // optional

Optionally include them with real numbers as shown, or leave them out entirely.

📝 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.

Suggested change
value: null, // optional
min: null // optional
min: null, // optional
transactionId: '<TRANSACTION_ID>' // optional
});
// value: 1, // optional
// min: 0, // optional
transactionId: '<TRANSACTION_ID>' // optional
});
🤖 Prompt for AI Agents
In docs/examples/tablesdb/decrement-row-column.md around lines 15 to 18, the
snippet uses null for numeric fields (value/min) which are typed number |
undefined and will be rejected; change the example to either omit these
properties entirely or provide numeric values (e.g., value: 1, min: 0) and keep
transactionId as optional, so remove nulls and show valid numbers or leave the
fields out.

Comment on lines +15 to 16
default: [[1, 2], [3, 4], [5, 6]], // optional
newKey: '' // optional
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Example sends wrong key: use xdefault, not default.

SDK param is xdefault; using default will be ignored server-side.

-    default: [[1, 2], [3, 4], [5, 6]], // optional
+    xdefault: [[1, 2], [3, 4], [5, 6]], // optional
📝 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.

Suggested change
default: [[1, 2], [3, 4], [5, 6]], // optional
newKey: '' // optional
xdefault: [[1, 2], [3, 4], [5, 6]], // optional
newKey: '' // optional
🤖 Prompt for AI Agents
In docs/examples/tablesdb/update-line-column.md around lines 15 to 16, the
example uses the property name "default" which the SDK ignores; change the
property name to "xdefault" (e.g., replace default: [[1, 2], [3, 4], [5, 6]]
with xdefault: [[1, 2], [3, 4], [5, 6]]) and keep other optional keys like
newKey unchanged so the example sends the correct key accepted by the server.

Comment on lines +15 to 17
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix invalid permissions string; recommend Permission/Role helpers.

The current ["read("any")"] breaks the string. Use helpers or proper quoting.

Preferred (SDK helpers):

-    permissions: ["read("any")"], // optional
+    permissions: [sdk.Permission.read(sdk.Role.any())], // optional

Alternative (string literal):

-    permissions: ["read("any")"], // optional
+    permissions: ['read("any")'], // optional
📝 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.

Suggested change
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
permissions: [sdk.Permission.read(sdk.Role.any())], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
🤖 Prompt for AI Agents
In docs/examples/tablesdb/update-row.md around lines 15 to 17, the permissions
entry uses an invalid string syntax ["read("any")"] which breaks parsing; change
it to use the SDK Permission/Role helper (e.g., Permission.read("any") or
Role.any() depending on SDK) or, if using a string literal, escape/quote
correctly so the entire permission is a single string (for example
'read("any")') and keep transactionId unchanged.

Comment on lines +1 to +14
const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setKey('<YOUR_API_KEY>'); // Your secret API key

const tablesDB = new sdk.TablesDB(client);

const result = await tablesDB.updateTransaction({
transactionId: '<TRANSACTION_ID>',
commit: false, // optional
rollback: false // optional
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix: top-level await used with CommonJS require will not run

The snippet uses require(...) (CJS) with top‑level await. Node.js only supports top‑level await in ESM. Wrap the call in an async IIFE (or switch the example to ESM import syntax).

Apply this diff to make the example runnable as CJS:

-const sdk = require('node-appwrite');
-
-const client = new sdk.Client()
-    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
-    .setProject('<YOUR_PROJECT_ID>') // Your project ID
-    .setKey('<YOUR_API_KEY>'); // Your secret API key
-
-const tablesDB = new sdk.TablesDB(client);
-
-const result = await tablesDB.updateTransaction({
-    transactionId: '<TRANSACTION_ID>',
-    commit: false, // optional
-    rollback: false // optional
-});
+(async () => {
+  const sdk = require('node-appwrite');
+
+  const client = new sdk.Client()
+    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
+    .setProject('<YOUR_PROJECT_ID>') // Your project ID
+    .setKey('<YOUR_API_KEY>'); // Your secret API key
+
+  const tablesDB = new sdk.TablesDB(client);
+
+  const result = await tablesDB.updateTransaction({
+    transactionId: '<TRANSACTION_ID>',
+    // Set exactly one of the following depending on intent:
+    // commit: true,
+    // rollback: true,
+  });
+  console.log(result);
+})().catch(console.error);
📝 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.

Suggested change
const sdk = require('node-appwrite');
const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setKey('<YOUR_API_KEY>'); // Your secret API key
const tablesDB = new sdk.TablesDB(client);
const result = await tablesDB.updateTransaction({
transactionId: '<TRANSACTION_ID>',
commit: false, // optional
rollback: false // optional
});
(async () => {
const sdk = require('node-appwrite');
const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setKey('<YOUR_API_KEY>'); // Your secret API key
const tablesDB = new sdk.TablesDB(client);
const result = await tablesDB.updateTransaction({
transactionId: '<TRANSACTION_ID>',
// Set exactly one of the following depending on intent:
// commit: true,
// rollback: true,
});
console.log(result);
})().catch(console.error);
🤖 Prompt for AI Agents
In docs/examples/tablesdb/update-transaction.md around lines 1 to 14, the
snippet uses CommonJS require with top-level await which will not run in
Node.js; wrap the asynchronous code in an async IIFE so the await runs inside an
async function (or alternatively convert the example to ESM import syntax),
i.e., move the tablesDB.updateTransaction call and any awaits into an
immediately-invoked async function and invoke it so the example is runnable
under CJS.

Comment on lines +15 to 17
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Invalid permissions string; use SDK helpers or fix quoting.

Current example is a JS syntax error. Prefer SDK helpers.

-    permissions: ["read("any")"], // optional
+    permissions: [sdk.Permission.read(sdk.Role.any())], // optional
📝 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.

Suggested change
permissions: ["read("any")"], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
permissions: [sdk.Permission.read(sdk.Role.any())], // optional
transactionId: '<TRANSACTION_ID>' // optional
});
🤖 Prompt for AI Agents
In docs/examples/tablesdb/upsert-row.md around lines 15 to 17, the permissions
example contains an invalid JS token read("any") causing a syntax error; either
replace the raw string with a properly quoted/escaped string (e.g.,
'read("any")') or, preferably, use the SDK permission helper API (call the
appropriate helper that represents a read-any permission) and update the example
to pass that helper return value to permissions.

Comment on lines +305 to +370
/**
* Update a transaction, to either commit or roll back its operations.
*
* @param {string} params.transactionId - Transaction ID.
* @param {boolean} params.commit - Commit transaction?
* @param {boolean} params.rollback - Rollback transaction?
* @throws {AppwriteException}
* @returns {Promise<Models.Transaction>}
*/
updateTransaction(params: { transactionId: string, commit?: boolean, rollback?: boolean }): Promise<Models.Transaction>;
/**
* Update a transaction, to either commit or roll back its operations.
*
* @param {string} transactionId - Transaction ID.
* @param {boolean} commit - Commit transaction?
* @param {boolean} rollback - Rollback transaction?
* @throws {AppwriteException}
* @returns {Promise<Models.Transaction>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateTransaction(transactionId: string, commit?: boolean, rollback?: boolean): Promise<Models.Transaction>;
updateTransaction(
paramsOrFirst: { transactionId: string, commit?: boolean, rollback?: boolean } | string,
...rest: [(boolean)?, (boolean)?]
): Promise<Models.Transaction> {
let params: { transactionId: string, commit?: boolean, rollback?: boolean };

if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { transactionId: string, commit?: boolean, rollback?: boolean };
} else {
params = {
transactionId: paramsOrFirst as string,
commit: rest[0] as boolean,
rollback: rest[1] as boolean
};
}

const transactionId = params.transactionId;
const commit = params.commit;
const rollback = params.rollback;

if (typeof transactionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "transactionId"');
}

const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', transactionId);
const payload: Payload = {};
if (typeof commit !== 'undefined') {
payload['commit'] = commit;
}
if (typeof rollback !== 'undefined') {
payload['rollback'] = rollback;
}
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
'patch',
uri,
apiHeaders,
payload,
);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enforce exactly one of commit or rollback in updateTransaction

Allowing both or neither is ambiguous. Validate exclusivity before issuing the request.

         const transactionId = params.transactionId;
         const commit = params.commit;
         const rollback = params.rollback;

         if (typeof transactionId === 'undefined') {
             throw new AppwriteException('Missing required parameter: "transactionId"');
         }
 
+        // Exactly one action must be chosen
+        const actions = (commit ? 1 : 0) + (rollback ? 1 : 0);
+        if (actions !== 1) {
+            throw new AppwriteException('Provide exactly one of "commit" or "rollback".');
+        }
📝 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.

Suggested change
/**
* Update a transaction, to either commit or roll back its operations.
*
* @param {string} params.transactionId - Transaction ID.
* @param {boolean} params.commit - Commit transaction?
* @param {boolean} params.rollback - Rollback transaction?
* @throws {AppwriteException}
* @returns {Promise<Models.Transaction>}
*/
updateTransaction(params: { transactionId: string, commit?: boolean, rollback?: boolean }): Promise<Models.Transaction>;
/**
* Update a transaction, to either commit or roll back its operations.
*
* @param {string} transactionId - Transaction ID.
* @param {boolean} commit - Commit transaction?
* @param {boolean} rollback - Rollback transaction?
* @throws {AppwriteException}
* @returns {Promise<Models.Transaction>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateTransaction(transactionId: string, commit?: boolean, rollback?: boolean): Promise<Models.Transaction>;
updateTransaction(
paramsOrFirst: { transactionId: string, commit?: boolean, rollback?: boolean } | string,
...rest: [(boolean)?, (boolean)?]
): Promise<Models.Transaction> {
let params: { transactionId: string, commit?: boolean, rollback?: boolean };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { transactionId: string, commit?: boolean, rollback?: boolean };
} else {
params = {
transactionId: paramsOrFirst as string,
commit: rest[0] as boolean,
rollback: rest[1] as boolean
};
}
const transactionId = params.transactionId;
const commit = params.commit;
const rollback = params.rollback;
if (typeof transactionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "transactionId"');
}
const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', transactionId);
const payload: Payload = {};
if (typeof commit !== 'undefined') {
payload['commit'] = commit;
}
if (typeof rollback !== 'undefined') {
payload['rollback'] = rollback;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'patch',
uri,
apiHeaders,
payload,
);
}
/**
* Update a transaction, to either commit or roll back its operations.
*
* @param {string} params.transactionId - Transaction ID.
* @param {boolean} params.commit - Commit transaction?
* @param {boolean} params.rollback - Rollback transaction?
* @throws {AppwriteException}
* @returns {Promise<Models.Transaction>}
*/
updateTransaction(params: { transactionId: string, commit?: boolean, rollback?: boolean }): Promise<Models.Transaction>;
/**
* Update a transaction, to either commit or roll back its operations.
*
* @param {string} transactionId - Transaction ID.
* @param {boolean} commit - Commit transaction?
* @param {boolean} rollback - Rollback transaction?
* @throws {AppwriteException}
* @returns {Promise<Models.Transaction>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateTransaction(transactionId: string, commit?: boolean, rollback?: boolean): Promise<Models.Transaction>;
updateTransaction(
paramsOrFirst: { transactionId: string, commit?: boolean, rollback?: boolean } | string,
...rest: [(boolean)?, (boolean)?]
): Promise<Models.Transaction> {
let params: { transactionId: string, commit?: boolean, rollback?: boolean };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { transactionId: string, commit?: boolean, rollback?: boolean };
} else {
params = {
transactionId: paramsOrFirst as string,
commit: rest[0] as boolean,
rollback: rest[1] as boolean
};
}
const transactionId = params.transactionId;
const commit = params.commit;
const rollback = params.rollback;
if (typeof transactionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "transactionId"');
}
// Exactly one action must be chosen
const actions = (commit ? 1 : 0) + (rollback ? 1 : 0);
if (actions !== 1) {
throw new AppwriteException('Provide exactly one of "commit" or "rollback".');
}
const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', transactionId);
const payload: Payload = {};
if (typeof commit !== 'undefined') {
payload['commit'] = commit;
}
if (typeof rollback !== 'undefined') {
payload['rollback'] = rollback;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'patch',
uri,
apiHeaders,
payload,
);
}
🤖 Prompt for AI Agents
In src/services/databases.ts around lines 305 to 370, the updateTransaction
implementation currently allows both commit and rollback to be set or neither,
which is ambiguous; add a validation after extracting commit and rollback that
ensures exactly one is true (i.e., (commit === true) XOR (rollback === true));
if the check fails, throw an AppwriteException with a clear message like
'Exactly one of "commit" or "rollback" must be provided'; keep existing behavior
otherwise and proceed to build the payload and call the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant