From 12e5af7e8ac3ab49d4b67c9ee156bd37c44918de Mon Sep 17 00:00:00 2001 From: root Date: Sat, 12 Jul 2025 06:30:50 +0000 Subject: [PATCH 01/11] fix: add uri searchParams to URL based methods --- package.json | 2 +- src/client.ts | 2 +- src/enums/image-format.ts | 1 + src/services/avatars.ts | 35 +++++++++++++++++++++++++++++++++++ src/services/databases.ts | 4 ++++ src/services/storage.ts | 15 +++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ebce0e85..c4717855 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "0.10.0", + "version": "0.10.1", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index 481c7a0f..b404254b 100644 --- a/src/client.ts +++ b/src/client.ts @@ -115,7 +115,7 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '0.10.0', + 'x-sdk-version': '0.10.1', 'X-Appwrite-Response-Format': '1.7.0', }; diff --git a/src/enums/image-format.ts b/src/enums/image-format.ts index 5aad5f08..758fad74 100644 --- a/src/enums/image-format.ts +++ b/src/enums/image-format.ts @@ -5,4 +5,5 @@ export enum ImageFormat { Webp = 'webp', Heic = 'heic', Avif = 'avif', + Gif = 'gif', } \ No newline at end of file diff --git a/src/services/avatars.ts b/src/services/avatars.ts index 5795bfce..85952b13 100644 --- a/src/services/avatars.ts +++ b/src/services/avatars.ts @@ -387,6 +387,11 @@ export class Avatars extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } @@ -426,6 +431,11 @@ export class Avatars extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } @@ -449,6 +459,11 @@ export class Avatars extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } @@ -489,6 +504,11 @@ export class Avatars extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } @@ -529,6 +549,11 @@ export class Avatars extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } @@ -579,6 +604,11 @@ export class Avatars extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } @@ -616,6 +646,11 @@ export class Avatars extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } diff --git a/src/services/databases.ts b/src/services/databases.ts index e8bb0ab8..09186833 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -133,6 +133,10 @@ export class Databases extends Service { } /** + * **WARNING: Experimental Feature** - This endpoint is experimental and not + * yet officially supported. It may be subject to breaking changes or removal + * in future versions. + * * Create or update a Document. Before using this route, you should create a * new collection resource using either a [server * integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) diff --git a/src/services/storage.ts b/src/services/storage.ts index e574d6bc..e40614aa 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -442,6 +442,11 @@ export class Storage extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } @@ -523,6 +528,11 @@ export class Storage extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } @@ -547,6 +557,11 @@ export class Storage extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); + payload['project'] = this.client.config.project; + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } return uri; } From 1883cbeefe53c47e3df3bad86495e17c55d15b3a Mon Sep 17 00:00:00 2001 From: root Date: Sat, 12 Jul 2025 06:33:40 +0000 Subject: [PATCH 02/11] chore: add changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56e176f0..6ab2975b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change log +## 0.10.1 + +* Fix URL based methods like `getFileViewURL`, `getFilePreviewURL` etc. by adding the missing `projectId` to searchParams +* Add `gif` to ImageFormat enum + ## 0.10.0 * Add generate file URL methods like`getFilePreviewURL`, `getFileViewURL` etc. From bed892b5674b975a8e0a3773c6f32d15c0239d94 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 14 Jul 2025 18:01:24 +0200 Subject: [PATCH 03/11] ci: fix npm token --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a7817726..9e8e7165 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,4 +39,4 @@ jobs: - name: Publish run: npm publish --tag ${{ steps.release_tag.outputs.tag }} env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_NO_ORG }} From b38c15af084ba80e7e8ba435e117d4e341c8916c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 18 Jul 2025 12:48:37 +1200 Subject: [PATCH 04/11] Add inc/dec --- .github/workflows/publish.yml | 2 +- docs/examples/databases/create-document.md | 1 + .../databases/decrement-document-attribute.md | 18 ++++ .../databases/increment-document-attribute.md | 18 ++++ package.json | 2 +- src/client.ts | 2 +- src/models.ts | 4 + src/services/databases.ts | 92 +++++++++++++++++++ 8 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 docs/examples/databases/decrement-document-attribute.md create mode 100644 docs/examples/databases/increment-document-attribute.md diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a7817726..9e8e7165 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,4 +39,4 @@ jobs: - name: Publish run: npm publish --tag ${{ steps.release_tag.outputs.tag }} env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_NO_ORG }} diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index ec768fcf..c627ab32 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -2,6 +2,7 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setAdmin('') // .setSession('') // The user session to authenticate with .setKey('') // .setJWT(''); // Your secret JSON Web Token diff --git a/docs/examples/databases/decrement-document-attribute.md b/docs/examples/databases/decrement-document-attribute.md new file mode 100644 index 00000000..4c9c2d99 --- /dev/null +++ b/docs/examples/databases/decrement-document-attribute.md @@ -0,0 +1,18 @@ +import { Client, Databases } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const databases = new Databases(client); + +const result = await databases.decrementDocumentAttribute( + '', // databaseId + '', // collectionId + '', // documentId + '', // attribute + null, // value (optional) + null // min (optional) +); + +console.log(result); diff --git a/docs/examples/databases/increment-document-attribute.md b/docs/examples/databases/increment-document-attribute.md new file mode 100644 index 00000000..3a9d9490 --- /dev/null +++ b/docs/examples/databases/increment-document-attribute.md @@ -0,0 +1,18 @@ +import { Client, Databases } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const databases = new Databases(client); + +const result = await databases.incrementDocumentAttribute( + '', // databaseId + '', // collectionId + '', // documentId + '', // attribute + null, // value (optional) + null // max (optional) +); + +console.log(result); diff --git a/package.json b/package.json index c4717855..92479c87 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "0.10.1", + "version": "0.11.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index b404254b..22628773 100644 --- a/src/client.ts +++ b/src/client.ts @@ -115,7 +115,7 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '0.10.1', + 'x-sdk-version': '0.11.0', 'X-Appwrite-Response-Format': '1.7.0', }; diff --git a/src/models.ts b/src/models.ts index f6db5fab..5fafb2ab 100644 --- a/src/models.ts +++ b/src/models.ts @@ -189,6 +189,10 @@ export namespace Models { * Document ID. */ $id: string; + /** + * Document automatically incrementing ID. + */ + $sequence: number; /** * Collection ID. */ diff --git a/src/services/databases.ts b/src/services/databases.ts index 09186833..783d9327 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -256,4 +256,96 @@ export class Databases extends Service { 'content-type': 'application/json', }, payload); } + + /** + * Decrement a specific attribute of a document by a given value. + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string} documentId + * @param {string} attribute + * @param {number} value + * @param {number} min + * @throws {AppwriteException} + * @returns {Promise} + */ + decrementDocumentAttribute(databaseId: string, collectionId: string, documentId: string, attribute: string, value?: number, min?: number): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + + if (typeof attribute === 'undefined') { + throw new AppwriteException('Missing required parameter: "attribute"'); + } + + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute); + const payload: Payload = {}; + + if (typeof value !== 'undefined') { + payload['value'] = value; + } + + if (typeof min !== 'undefined') { + payload['min'] = min; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Increment a specific attribute of a document by a given value. + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string} documentId + * @param {string} attribute + * @param {number} value + * @param {number} max + * @throws {AppwriteException} + * @returns {Promise} + */ + incrementDocumentAttribute(databaseId: string, collectionId: string, documentId: string, attribute: string, value?: number, max?: number): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + + if (typeof attribute === 'undefined') { + throw new AppwriteException('Missing required parameter: "attribute"'); + } + + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute); + const payload: Payload = {}; + + if (typeof value !== 'undefined') { + payload['value'] = value; + } + + if (typeof max !== 'undefined') { + payload['max'] = max; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } }; From feff5c80b1b3ad88733c75563ad70760eea86c86 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 22 Jul 2025 16:15:08 +0000 Subject: [PATCH 05/11] chore: regenerate --- README.md | 4 +- docs/examples/databases/create-document.md | 1 - .../databases/decrement-document-attribute.md | 18 -- .../databases/increment-document-attribute.md | 18 -- docs/examples/databases/upsert-document.md | 8 +- docs/examples/tables/create-row.md | 19 ++ docs/examples/tables/create-rows.md | 16 + docs/examples/tables/delete-row.md | 15 + docs/examples/tables/get-row.md | 16 + docs/examples/tables/list-rows.md | 15 + docs/examples/tables/update-row.md | 17 ++ docs/examples/tables/upsert-row.md | 17 ++ src/client.ts | 2 +- src/index.ts | 1 + src/models.ts | 83 ++++-- src/services/account.ts | 118 ++++---- src/services/avatars.ts | 14 +- src/services/databases.ts | 134 ++------- src/services/functions.ts | 6 +- src/services/graphql.ts | 4 +- src/services/locale.ts | 16 +- src/services/messaging.ts | 4 +- src/services/storage.ts | 16 +- src/services/tables.ts | 279 ++++++++++++++++++ src/services/teams.ts | 38 +-- 25 files changed, 593 insertions(+), 286 deletions(-) delete mode 100644 docs/examples/databases/decrement-document-attribute.md delete mode 100644 docs/examples/databases/increment-document-attribute.md create mode 100644 docs/examples/tables/create-row.md create mode 100644 docs/examples/tables/create-rows.md create mode 100644 docs/examples/tables/delete-row.md create mode 100644 docs/examples/tables/get-row.md create mode 100644 docs/examples/tables/list-rows.md create mode 100644 docs/examples/tables/update-row.md create mode 100644 docs/examples/tables/upsert-row.md create mode 100644 src/services/tables.ts diff --git a/README.md b/README.md index 542c5c3e..40867bae 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite React Native SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-react-native.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.8.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).** +**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the React Native SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index c627ab32..ec768fcf 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -2,7 +2,6 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setAdmin('') // .setSession('') // The user session to authenticate with .setKey('') // .setJWT(''); // Your secret JSON Web Token diff --git a/docs/examples/databases/decrement-document-attribute.md b/docs/examples/databases/decrement-document-attribute.md deleted file mode 100644 index 4c9c2d99..00000000 --- a/docs/examples/databases/decrement-document-attribute.md +++ /dev/null @@ -1,18 +0,0 @@ -import { Client, Databases } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const databases = new Databases(client); - -const result = await databases.decrementDocumentAttribute( - '', // databaseId - '', // collectionId - '', // documentId - '', // attribute - null, // value (optional) - null // min (optional) -); - -console.log(result); diff --git a/docs/examples/databases/increment-document-attribute.md b/docs/examples/databases/increment-document-attribute.md deleted file mode 100644 index 3a9d9490..00000000 --- a/docs/examples/databases/increment-document-attribute.md +++ /dev/null @@ -1,18 +0,0 @@ -import { Client, Databases } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const databases = new Databases(client); - -const result = await databases.incrementDocumentAttribute( - '', // databaseId - '', // collectionId - '', // documentId - '', // attribute - null, // value (optional) - null // max (optional) -); - -console.log(result); diff --git a/docs/examples/databases/upsert-document.md b/docs/examples/databases/upsert-document.md index ae423d12..56d3af23 100644 --- a/docs/examples/databases/upsert-document.md +++ b/docs/examples/databases/upsert-document.md @@ -2,16 +2,16 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID + .setSession('') // The user session to authenticate with + .setKey('') // + .setJWT(''); // Your secret JSON Web Token const databases = new Databases(client); const result = await databases.upsertDocument( '', // databaseId '', // collectionId - '', // documentId - {}, // data - ["read("any")"] // permissions (optional) + '' // documentId ); console.log(result); diff --git a/docs/examples/tables/create-row.md b/docs/examples/tables/create-row.md new file mode 100644 index 00000000..75de1c2a --- /dev/null +++ b/docs/examples/tables/create-row.md @@ -0,0 +1,19 @@ +import { Client, Tables } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setKey('') // + .setJWT(''); // Your secret JSON Web Token + +const tables = new Tables(client); + +const result = await tables.createRow( + '', // databaseId + '', // tableId + '', // rowId + {}, // data + ["read("any")"] // permissions (optional) +); + +console.log(result); diff --git a/docs/examples/tables/create-rows.md b/docs/examples/tables/create-rows.md new file mode 100644 index 00000000..165aa4cb --- /dev/null +++ b/docs/examples/tables/create-rows.md @@ -0,0 +1,16 @@ +import { Client, Tables } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setAdmin('') // + .setKey(''); // + +const tables = new Tables(client); + +const result = await tables.createRows( + '', // databaseId + '', // tableId + [] // rows +); + +console.log(result); diff --git a/docs/examples/tables/delete-row.md b/docs/examples/tables/delete-row.md new file mode 100644 index 00000000..9746f85e --- /dev/null +++ b/docs/examples/tables/delete-row.md @@ -0,0 +1,15 @@ +import { Client, Tables } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const tables = new Tables(client); + +const result = await tables.deleteRow( + '', // databaseId + '', // tableId + '' // rowId +); + +console.log(result); diff --git a/docs/examples/tables/get-row.md b/docs/examples/tables/get-row.md new file mode 100644 index 00000000..b9434e39 --- /dev/null +++ b/docs/examples/tables/get-row.md @@ -0,0 +1,16 @@ +import { Client, Tables } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const tables = new Tables(client); + +const result = await tables.getRow( + '', // databaseId + '', // tableId + '', // rowId + [] // queries (optional) +); + +console.log(result); diff --git a/docs/examples/tables/list-rows.md b/docs/examples/tables/list-rows.md new file mode 100644 index 00000000..75f81a14 --- /dev/null +++ b/docs/examples/tables/list-rows.md @@ -0,0 +1,15 @@ +import { Client, Tables } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const tables = new Tables(client); + +const result = await tables.listRows( + '', // databaseId + '', // tableId + [] // queries (optional) +); + +console.log(result); diff --git a/docs/examples/tables/update-row.md b/docs/examples/tables/update-row.md new file mode 100644 index 00000000..7bb36dd2 --- /dev/null +++ b/docs/examples/tables/update-row.md @@ -0,0 +1,17 @@ +import { Client, Tables } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const tables = new Tables(client); + +const result = await tables.updateRow( + '', // databaseId + '', // tableId + '', // rowId + {}, // data (optional) + ["read("any")"] // permissions (optional) +); + +console.log(result); diff --git a/docs/examples/tables/upsert-row.md b/docs/examples/tables/upsert-row.md new file mode 100644 index 00000000..f176425a --- /dev/null +++ b/docs/examples/tables/upsert-row.md @@ -0,0 +1,17 @@ +import { Client, Tables } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setSession('') // The user session to authenticate with + .setKey('') // + .setJWT(''); // Your secret JSON Web Token + +const tables = new Tables(client); + +const result = await tables.upsertRow( + '', // databaseId + '', // tableId + '' // rowId +); + +console.log(result); diff --git a/src/client.ts b/src/client.ts index 22628773..a0b2f34c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -116,7 +116,7 @@ class Client { 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', 'x-sdk-version': '0.11.0', - 'X-Appwrite-Response-Format': '1.7.0', + 'X-Appwrite-Response-Format': '1.8.0', }; /** diff --git a/src/index.ts b/src/index.ts index bbc74cce..35d654c8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ export { Client, AppwriteException } from './client'; export { Account } from './services/account'; export { Avatars } from './services/avatars'; export { Databases } from './services/databases'; +export { Tables } from './services/tables'; export { Functions } from './services/functions'; export { Graphql } from './services/graphql'; export { Locale } from './services/locale'; diff --git a/src/models.ts b/src/models.ts index 5fafb2ab..1acb8a42 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1,10 +1,23 @@ export namespace Models { + /** + * Rows List + */ + export type RowList = { + /** + * Total number of rows rows that matched your query. + */ + total: number; + /** + * List of rows. + */ + rows: Row[]; + } /** * Documents List */ - export type DocumentList = { + export type DocumentList = { /** - * Total number of documents documents that matched your query. + * Total number of documents rows that matched your query. */ total: number; /** @@ -17,7 +30,7 @@ export namespace Models { */ export type SessionList = { /** - * Total number of sessions documents that matched your query. + * Total number of sessions rows that matched your query. */ total: number; /** @@ -30,7 +43,7 @@ export namespace Models { */ export type IdentityList = { /** - * Total number of identities documents that matched your query. + * Total number of identities rows that matched your query. */ total: number; /** @@ -43,7 +56,7 @@ export namespace Models { */ export type LogList = { /** - * Total number of logs documents that matched your query. + * Total number of logs rows that matched your query. */ total: number; /** @@ -56,7 +69,7 @@ export namespace Models { */ export type FileList = { /** - * Total number of files documents that matched your query. + * Total number of files rows that matched your query. */ total: number; /** @@ -67,9 +80,9 @@ export namespace Models { /** * Teams List */ - export type TeamList = { + export type TeamList = { /** - * Total number of teams documents that matched your query. + * Total number of teams rows that matched your query. */ total: number; /** @@ -82,7 +95,7 @@ export namespace Models { */ export type MembershipList = { /** - * Total number of memberships documents that matched your query. + * Total number of memberships rows that matched your query. */ total: number; /** @@ -95,7 +108,7 @@ export namespace Models { */ export type ExecutionList = { /** - * Total number of executions documents that matched your query. + * Total number of executions rows that matched your query. */ total: number; /** @@ -108,7 +121,7 @@ export namespace Models { */ export type CountryList = { /** - * Total number of countries documents that matched your query. + * Total number of countries rows that matched your query. */ total: number; /** @@ -121,7 +134,7 @@ export namespace Models { */ export type ContinentList = { /** - * Total number of continents documents that matched your query. + * Total number of continents rows that matched your query. */ total: number; /** @@ -134,7 +147,7 @@ export namespace Models { */ export type LanguageList = { /** - * Total number of languages documents that matched your query. + * Total number of languages rows that matched your query. */ total: number; /** @@ -147,7 +160,7 @@ export namespace Models { */ export type CurrencyList = { /** - * Total number of currencies documents that matched your query. + * Total number of currencies rows that matched your query. */ total: number; /** @@ -160,7 +173,7 @@ export namespace Models { */ export type PhoneList = { /** - * Total number of phones documents that matched your query. + * Total number of phones rows that matched your query. */ total: number; /** @@ -173,7 +186,7 @@ export namespace Models { */ export type LocaleCodeList = { /** - * Total number of localeCodes documents that matched your query. + * Total number of localeCodes rows that matched your query. */ total: number; /** @@ -181,6 +194,40 @@ export namespace Models { */ localeCodes: LocaleCode[]; } + /** + * Row + */ + export type Row = { + /** + * Row ID. + */ + $id: string; + /** + * Row automatically incrementing ID. + */ + $sequence: number; + /** + * Table ID. + */ + $tableId: string; + /** + * Database ID. + */ + $databaseId: string; + /** + * Row creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * Row update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Row permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + */ + $permissions: string[]; + [key: string]: any; + } /** * Document */ @@ -307,7 +354,7 @@ export namespace Models { /** * User */ - export type User = { + export type User = { /** * User ID. */ @@ -796,7 +843,7 @@ export namespace Models { /** * Team */ - export type Team = { + export type Team = { /** * Team ID. */ diff --git a/src/services/account.ts b/src/services/account.ts index bcd37339..cca5bae1 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -21,8 +21,8 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ - get(): Promise> { + */ + get(): Promise> { const apiPath = '/account'; const payload: Payload = {}; @@ -46,8 +46,8 @@ export class Account extends Service { * @param {string} name * @throws {AppwriteException} * @returns {Promise} - */ - create(userId: string, email: string, password: string, name?: string): Promise> { + */ + create(userId: string, email: string, password: string, name?: string): Promise> { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -99,8 +99,8 @@ export class Account extends Service { * @param {string} password * @throws {AppwriteException} * @returns {Promise} - */ - updateEmail(email: string, password: string): Promise> { + */ + updateEmail(email: string, password: string): Promise> { if (typeof email === 'undefined') { throw new AppwriteException('Missing required parameter: "email"'); } @@ -132,7 +132,7 @@ export class Account extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - */ + */ listIdentities(queries?: string[]): Promise { const apiPath = '/account/identities'; const payload: Payload = {}; @@ -152,7 +152,7 @@ export class Account extends Service { * @param {string} identityId * @throws {AppwriteException} * @returns {Promise} - */ + */ deleteIdentity(identityId: string): Promise<{}> { if (typeof identityId === 'undefined') { throw new AppwriteException('Missing required parameter: "identityId"'); @@ -176,7 +176,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ createJWT(): Promise { const apiPath = '/account/jwts'; const payload: Payload = {}; @@ -194,7 +194,7 @@ export class Account extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - */ + */ listLogs(queries?: string[]): Promise { const apiPath = '/account/logs'; const payload: Payload = {}; @@ -214,8 +214,8 @@ export class Account extends Service { * @param {boolean} mfa * @throws {AppwriteException} * @returns {Promise} - */ - updateMFA(mfa: boolean): Promise> { + */ + updateMFA(mfa: boolean): Promise> { if (typeof mfa === 'undefined') { throw new AppwriteException('Missing required parameter: "mfa"'); } @@ -242,7 +242,7 @@ export class Account extends Service { * @param {AuthenticatorType} type * @throws {AppwriteException} * @returns {Promise} - */ + */ createMfaAuthenticator(type: AuthenticatorType): Promise { if (typeof type === 'undefined') { throw new AppwriteException('Missing required parameter: "type"'); @@ -266,8 +266,8 @@ export class Account extends Service { * @param {string} otp * @throws {AppwriteException} * @returns {Promise} - */ - updateMfaAuthenticator(type: AuthenticatorType, otp: string): Promise> { + */ + updateMfaAuthenticator(type: AuthenticatorType, otp: string): Promise> { if (typeof type === 'undefined') { throw new AppwriteException('Missing required parameter: "type"'); } @@ -295,7 +295,7 @@ export class Account extends Service { * @param {AuthenticatorType} type * @throws {AppwriteException} * @returns {Promise} - */ + */ deleteMfaAuthenticator(type: AuthenticatorType): Promise<{}> { if (typeof type === 'undefined') { throw new AppwriteException('Missing required parameter: "type"'); @@ -318,7 +318,7 @@ export class Account extends Service { * @param {AuthenticationFactor} factor * @throws {AppwriteException} * @returns {Promise} - */ + */ createMfaChallenge(factor: AuthenticationFactor): Promise { if (typeof factor === 'undefined') { throw new AppwriteException('Missing required parameter: "factor"'); @@ -348,7 +348,7 @@ export class Account extends Service { * @param {string} otp * @throws {AppwriteException} * @returns {Promise} - */ + */ updateMfaChallenge(challengeId: string, otp: string): Promise { if (typeof challengeId === 'undefined') { throw new AppwriteException('Missing required parameter: "challengeId"'); @@ -380,7 +380,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listMfaFactors(): Promise { const apiPath = '/account/mfa/factors'; const payload: Payload = {}; @@ -398,7 +398,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ getMfaRecoveryCodes(): Promise { const apiPath = '/account/mfa/recovery-codes'; const payload: Payload = {}; @@ -417,7 +417,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ createMfaRecoveryCodes(): Promise { const apiPath = '/account/mfa/recovery-codes'; const payload: Payload = {}; @@ -436,7 +436,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ updateMfaRecoveryCodes(): Promise { const apiPath = '/account/mfa/recovery-codes'; const payload: Payload = {}; @@ -453,8 +453,8 @@ export class Account extends Service { * @param {string} name * @throws {AppwriteException} * @returns {Promise} - */ - updateName(name: string): Promise> { + */ + updateName(name: string): Promise> { if (typeof name === 'undefined') { throw new AppwriteException('Missing required parameter: "name"'); } @@ -481,8 +481,8 @@ export class Account extends Service { * @param {string} oldPassword * @throws {AppwriteException} * @returns {Promise} - */ - updatePassword(password: string, oldPassword?: string): Promise> { + */ + updatePassword(password: string, oldPassword?: string): Promise> { if (typeof password === 'undefined') { throw new AppwriteException('Missing required parameter: "password"'); } @@ -515,8 +515,8 @@ export class Account extends Service { * @param {string} password * @throws {AppwriteException} * @returns {Promise} - */ - updatePhone(phone: string, password: string): Promise> { + */ + updatePhone(phone: string, password: string): Promise> { if (typeof phone === 'undefined') { throw new AppwriteException('Missing required parameter: "phone"'); } @@ -547,8 +547,8 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ - getPrefs(): Promise { + */ + getPrefs(): Promise { const apiPath = '/account/prefs'; const payload: Payload = {}; @@ -565,8 +565,8 @@ export class Account extends Service { * @param {object} prefs * @throws {AppwriteException} * @returns {Promise} - */ - updatePrefs(prefs: object): Promise> { + */ + updatePrefs(prefs: object): Promise> { if (typeof prefs === 'undefined') { throw new AppwriteException('Missing required parameter: "prefs"'); } @@ -598,7 +598,7 @@ export class Account extends Service { * @param {string} url * @throws {AppwriteException} * @returns {Promise} - */ + */ createRecovery(email: string, url: string): Promise { if (typeof email === 'undefined') { throw new AppwriteException('Missing required parameter: "email"'); @@ -642,7 +642,7 @@ export class Account extends Service { * @param {string} password * @throws {AppwriteException} * @returns {Promise} - */ + */ updateRecovery(userId: string, secret: string, password: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -683,7 +683,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listSessions(): Promise { const apiPath = '/account/sessions'; const payload: Payload = {}; @@ -699,7 +699,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ deleteSessions(): Promise<{}> { const apiPath = '/account/sessions'; const payload: Payload = {}; @@ -721,7 +721,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ createAnonymousSession(): Promise { const apiPath = '/account/sessions/anonymous'; const payload: Payload = {}; @@ -744,7 +744,7 @@ export class Account extends Service { * @param {string} password * @throws {AppwriteException} * @returns {Promise} - */ + */ createEmailPasswordSession(email: string, password: string): Promise { if (typeof email === 'undefined') { throw new AppwriteException('Missing required parameter: "email"'); @@ -780,7 +780,8 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - */ + * @deprecated This API has been deprecated. + */ updateMagicURLSession(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -831,7 +832,7 @@ export class Account extends Service { * @param {string[]} scopes * @throws {AppwriteException} * @returns {void|string} - */ + */ createOAuth2Session(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): void | URL { if (typeof provider === 'undefined') { throw new AppwriteException('Missing required parameter: "provider"'); @@ -871,7 +872,8 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - */ + * @deprecated This API has been deprecated. + */ updatePhoneSession(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -907,7 +909,7 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - */ + */ createSession(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -941,7 +943,7 @@ export class Account extends Service { * @param {string} sessionId * @throws {AppwriteException} * @returns {Promise} - */ + */ getSession(sessionId: string): Promise { if (typeof sessionId === 'undefined') { throw new AppwriteException('Missing required parameter: "sessionId"'); @@ -963,7 +965,7 @@ export class Account extends Service { * @param {string} sessionId * @throws {AppwriteException} * @returns {Promise} - */ + */ updateSession(sessionId: string): Promise { if (typeof sessionId === 'undefined') { throw new AppwriteException('Missing required parameter: "sessionId"'); @@ -988,7 +990,7 @@ export class Account extends Service { * @param {string} sessionId * @throws {AppwriteException} * @returns {Promise} - */ + */ deleteSession(sessionId: string): Promise<{}> { if (typeof sessionId === 'undefined') { throw new AppwriteException('Missing required parameter: "sessionId"'); @@ -1010,8 +1012,8 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ - updateStatus(): Promise> { + */ + updateStatus(): Promise> { const apiPath = '/account/status'; const payload: Payload = {}; @@ -1033,7 +1035,7 @@ export class Account extends Service { * @param {string} providerId * @throws {AppwriteException} * @returns {Promise} - */ + */ createPushTarget(targetId: string, identifier: string, providerId?: string): Promise { if (typeof targetId === 'undefined') { throw new AppwriteException('Missing required parameter: "targetId"'); @@ -1075,7 +1077,7 @@ export class Account extends Service { * @param {string} identifier * @throws {AppwriteException} * @returns {Promise} - */ + */ updatePushTarget(targetId: string, identifier: string): Promise { if (typeof targetId === 'undefined') { throw new AppwriteException('Missing required parameter: "targetId"'); @@ -1106,7 +1108,7 @@ export class Account extends Service { * @param {string} targetId * @throws {AppwriteException} * @returns {Promise} - */ + */ deletePushTarget(targetId: string): Promise<{}> { if (typeof targetId === 'undefined') { throw new AppwriteException('Missing required parameter: "targetId"'); @@ -1138,7 +1140,7 @@ export class Account extends Service { * @param {boolean} phrase * @throws {AppwriteException} * @returns {Promise} - */ + */ createEmailToken(userId: string, email: string, phrase?: boolean): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -1191,7 +1193,7 @@ export class Account extends Service { * @param {boolean} phrase * @throws {AppwriteException} * @returns {Promise} - */ + */ createMagicURLToken(userId: string, email: string, url?: string, phrase?: boolean): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -1248,7 +1250,7 @@ export class Account extends Service { * @param {string[]} scopes * @throws {AppwriteException} * @returns {void|string} - */ + */ createOAuth2Token(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): void | URL { if (typeof provider === 'undefined') { throw new AppwriteException('Missing required parameter: "provider"'); @@ -1295,7 +1297,7 @@ export class Account extends Service { * @param {string} phone * @throws {AppwriteException} * @returns {Promise} - */ + */ createPhoneToken(userId: string, phone: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -1342,7 +1344,7 @@ export class Account extends Service { * @param {string} url * @throws {AppwriteException} * @returns {Promise} - */ + */ createVerification(url: string): Promise { if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); @@ -1371,7 +1373,7 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - */ + */ updateVerification(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -1410,7 +1412,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ createPhoneVerification(): Promise { const apiPath = '/account/verification/phone'; const payload: Payload = {}; @@ -1431,7 +1433,7 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - */ + */ updatePhoneVerification(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); diff --git a/src/services/avatars.ts b/src/services/avatars.ts index 85952b13..5a66f64f 100644 --- a/src/services/avatars.ts +++ b/src/services/avatars.ts @@ -34,7 +34,7 @@ export class Avatars extends Service { * @param {number} quality * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getBrowser(code: Browser, width?: number, height?: number, quality?: number): Promise { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); @@ -83,7 +83,7 @@ export class Avatars extends Service { * @param {number} quality * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): Promise { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); @@ -124,7 +124,7 @@ export class Avatars extends Service { * @param {string} url * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getFavicon(url: string): Promise { if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); @@ -166,7 +166,7 @@ export class Avatars extends Service { * @param {number} quality * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getFlag(code: Flag, width?: number, height?: number, quality?: number): Promise { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); @@ -216,7 +216,7 @@ export class Avatars extends Service { * @param {number} height * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getImage(url: string, width?: number, height?: number): Promise { if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); @@ -272,7 +272,7 @@ export class Avatars extends Service { * @param {string} background * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getInitials(name?: string, width?: number, height?: number, background?: string): Promise { const apiPath = '/avatars/initials'; const payload: Payload = {}; @@ -315,7 +315,7 @@ export class Avatars extends Service { * @param {boolean} download * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getQR(text: string, size?: number, margin?: number, download?: boolean): Promise { if (typeof text === 'undefined') { throw new AppwriteException('Missing required parameter: "text"'); diff --git a/src/services/databases.ts b/src/services/databases.ts index 783d9327..c0031fae 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -22,8 +22,9 @@ export class Databases extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - */ - listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { + * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.listRows` instead. + */ + listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -57,8 +58,9 @@ export class Databases extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - */ - createDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { + * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.createRow` instead. + */ + createDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -106,8 +108,9 @@ export class Databases extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - */ - getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { + * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.getRow` instead. + */ + getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -145,12 +148,11 @@ export class Databases extends Service { * @param {string} databaseId * @param {string} collectionId * @param {string} documentId - * @param {object} data - * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - */ - upsertDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { + * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.upsertRow` instead. + */ + upsertDocument(databaseId: string, collectionId: string, documentId: string): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -163,21 +165,9 @@ export class Databases extends Service { throw new AppwriteException('Missing required parameter: "documentId"'); } - if (typeof data === 'undefined') { - throw new AppwriteException('Missing required parameter: "data"'); - } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); const payload: Payload = {}; - if (typeof data !== 'undefined') { - payload['data'] = data; - } - - if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; - } - const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('put', uri, { 'content-type': 'application/json', @@ -195,8 +185,9 @@ export class Databases extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - */ - updateDocument(databaseId: string, collectionId: string, documentId: string, data?: object, permissions?: string[]): Promise { + * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.updateRow` instead. + */ + updateDocument(databaseId: string, collectionId: string, documentId: string, data?: object, permissions?: string[]): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -234,7 +225,8 @@ export class Databases extends Service { * @param {string} documentId * @throws {AppwriteException} * @returns {Promise} - */ + * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.deleteRow` instead. + */ deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<{}> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); @@ -256,96 +248,4 @@ export class Databases extends Service { 'content-type': 'application/json', }, payload); } - - /** - * Decrement a specific attribute of a document by a given value. - * - * @param {string} databaseId - * @param {string} collectionId - * @param {string} documentId - * @param {string} attribute - * @param {number} value - * @param {number} min - * @throws {AppwriteException} - * @returns {Promise} - */ - decrementDocumentAttribute(databaseId: string, collectionId: string, documentId: string, attribute: string, value?: number, min?: number): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof collectionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "collectionId"'); - } - - if (typeof documentId === 'undefined') { - throw new AppwriteException('Missing required parameter: "documentId"'); - } - - if (typeof attribute === 'undefined') { - throw new AppwriteException('Missing required parameter: "attribute"'); - } - - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute); - const payload: Payload = {}; - - if (typeof value !== 'undefined') { - payload['value'] = value; - } - - if (typeof min !== 'undefined') { - payload['min'] = min; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Increment a specific attribute of a document by a given value. - * - * @param {string} databaseId - * @param {string} collectionId - * @param {string} documentId - * @param {string} attribute - * @param {number} value - * @param {number} max - * @throws {AppwriteException} - * @returns {Promise} - */ - incrementDocumentAttribute(databaseId: string, collectionId: string, documentId: string, attribute: string, value?: number, max?: number): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof collectionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "collectionId"'); - } - - if (typeof documentId === 'undefined') { - throw new AppwriteException('Missing required parameter: "documentId"'); - } - - if (typeof attribute === 'undefined') { - throw new AppwriteException('Missing required parameter: "attribute"'); - } - - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute); - const payload: Payload = {}; - - if (typeof value !== 'undefined') { - payload['value'] = value; - } - - if (typeof max !== 'undefined') { - payload['max'] = max; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } }; diff --git a/src/services/functions.ts b/src/services/functions.ts index 4f41fe09..6b0134c7 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -22,7 +22,7 @@ export class Functions extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - */ + */ listExecutions(functionId: string, queries?: string[]): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); @@ -55,7 +55,7 @@ export class Functions extends Service { * @param {string} scheduledAt * @throws {AppwriteException} * @returns {Promise} - */ + */ createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object, scheduledAt?: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); @@ -101,7 +101,7 @@ export class Functions extends Service { * @param {string} executionId * @throws {AppwriteException} * @returns {Promise} - */ + */ getExecution(functionId: string, executionId: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); diff --git a/src/services/graphql.ts b/src/services/graphql.ts index a24adaa4..8655f00c 100644 --- a/src/services/graphql.ts +++ b/src/services/graphql.ts @@ -19,7 +19,7 @@ export class Graphql extends Service { * @param {object} query * @throws {AppwriteException} * @returns {Promise} - */ + */ query(query: object): Promise<{}> { if (typeof query === 'undefined') { throw new AppwriteException('Missing required parameter: "query"'); @@ -45,7 +45,7 @@ export class Graphql extends Service { * @param {object} query * @throws {AppwriteException} * @returns {Promise} - */ + */ mutation(query: object): Promise<{}> { if (typeof query === 'undefined') { throw new AppwriteException('Missing required parameter: "query"'); diff --git a/src/services/locale.ts b/src/services/locale.ts index 6498bd98..7a29f954 100644 --- a/src/services/locale.ts +++ b/src/services/locale.ts @@ -23,7 +23,7 @@ export class Locale extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ get(): Promise { const apiPath = '/locale'; const payload: Payload = {}; @@ -39,7 +39,7 @@ export class Locale extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listCodes(): Promise { const apiPath = '/locale/codes'; const payload: Payload = {}; @@ -55,7 +55,7 @@ export class Locale extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listContinents(): Promise { const apiPath = '/locale/continents'; const payload: Payload = {}; @@ -71,7 +71,7 @@ export class Locale extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listCountries(): Promise { const apiPath = '/locale/countries'; const payload: Payload = {}; @@ -87,7 +87,7 @@ export class Locale extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listCountriesEU(): Promise { const apiPath = '/locale/countries/eu'; const payload: Payload = {}; @@ -103,7 +103,7 @@ export class Locale extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listCountriesPhones(): Promise { const apiPath = '/locale/countries/phones'; const payload: Payload = {}; @@ -120,7 +120,7 @@ export class Locale extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listCurrencies(): Promise { const apiPath = '/locale/currencies'; const payload: Payload = {}; @@ -136,7 +136,7 @@ export class Locale extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ listLanguages(): Promise { const apiPath = '/locale/languages'; const payload: Payload = {}; diff --git a/src/services/messaging.ts b/src/services/messaging.ts index 6e33b9ab..e6edd34d 100644 --- a/src/services/messaging.ts +++ b/src/services/messaging.ts @@ -21,7 +21,7 @@ export class Messaging extends Service { * @param {string} targetId * @throws {AppwriteException} * @returns {Promise} - */ + */ createSubscriber(topicId: string, subscriberId: string, targetId: string): Promise { if (typeof topicId === 'undefined') { throw new AppwriteException('Missing required parameter: "topicId"'); @@ -59,7 +59,7 @@ export class Messaging extends Service { * @param {string} subscriberId * @throws {AppwriteException} * @returns {Promise} - */ + */ deleteSubscriber(topicId: string, subscriberId: string): Promise<{}> { if (typeof topicId === 'undefined') { throw new AppwriteException('Missing required parameter: "topicId"'); diff --git a/src/services/storage.ts b/src/services/storage.ts index e40614aa..e062b2fb 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -24,7 +24,7 @@ export class Storage extends Service { * @param {string} search * @throws {AppwriteException} * @returns {Promise} - */ + */ listFiles(bucketId: string, queries?: string[], search?: string): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); @@ -72,7 +72,7 @@ export class Storage extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - */ + */ async createFile(bucketId: string, fileId: string, file: {name: string, type: string, size: number, uri: string}, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); @@ -169,7 +169,7 @@ export class Storage extends Service { * @param {string} fileId * @throws {AppwriteException} * @returns {Promise} - */ + */ getFile(bucketId: string, fileId: string): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); @@ -197,7 +197,7 @@ export class Storage extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - */ + */ updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); @@ -232,7 +232,7 @@ export class Storage extends Service { * @param {string} fileId * @throws {AppwriteException} * @returns {Promise} - */ + */ deleteFile(bucketId: string, fileId: string): Promise<{}> { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); @@ -261,7 +261,7 @@ export class Storage extends Service { * @param {string} token * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getFileDownload(bucketId: string, fileId: string, token?: string): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); @@ -312,7 +312,7 @@ export class Storage extends Service { * @param {string} token * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat, token?: string): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); @@ -394,7 +394,7 @@ export class Storage extends Service { * @param {string} token * @throws {AppwriteException} * @returns {ArrayBuffer} - */ + */ getFileView(bucketId: string, fileId: string, token?: string): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); diff --git a/src/services/tables.ts b/src/services/tables.ts new file mode 100644 index 00000000..9e86fbee --- /dev/null +++ b/src/services/tables.ts @@ -0,0 +1,279 @@ +import { Service } from '../service'; +import { AppwriteException, Client } from '../client'; +import type { Models } from '../models'; +import type { UploadProgress, Payload } from '../client'; +import * as FileSystem from 'expo-file-system'; +import { Platform } from 'react-native'; + + +export class Tables extends Service { + + constructor(client: Client) + { + super(client); + } + + /** + * Get a list of all the user's rows in a given table. You can use the query + * params to filter your results. + * + * @param {string} databaseId + * @param {string} tableId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + listRows(databaseId: string, tableId: string, queries?: string[]): Promise> { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof tableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "tableId"'); + } + + const apiPath = '/databases/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', databaseId).replace('{tableId}', tableId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('get', uri, { + }, payload); + } + + /** + * Create a new Row. Before using this route, you should create a new table + * resource using either a [server + * integration](https://appwrite.io/docs/server/databases#databasesCreateTable) + * API or directly from your database console. + * + * @param {string} databaseId + * @param {string} tableId + * @param {string} rowId + * @param {object} data + * @param {string[]} permissions + * @throws {AppwriteException} + * @returns {Promise} + */ + createRow(databaseId: string, tableId: string, rowId: string, data: object, permissions?: string[]): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof tableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "tableId"'); + } + + if (typeof rowId === 'undefined') { + throw new AppwriteException('Missing required parameter: "rowId"'); + } + + if (typeof data === 'undefined') { + throw new AppwriteException('Missing required parameter: "data"'); + } + + const apiPath = '/databases/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', databaseId).replace('{tableId}', tableId); + const payload: Payload = {}; + + if (typeof rowId !== 'undefined') { + payload['rowId'] = rowId; + } + + if (typeof data !== 'undefined') { + payload['data'] = data; + } + + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create new Rows. Before using this route, you should create a new table + * resource using either a [server + * integration](https://appwrite.io/docs/server/databases#databasesCreateTable) + * API or directly from your database console. + * + * @param {string} databaseId + * @param {string} tableId + * @param {object[]} rows + * @throws {AppwriteException} + * @returns {Promise} + */ + createRows(databaseId: string, tableId: string, rows: object[]): Promise> { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof tableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "tableId"'); + } + + if (typeof rows === 'undefined') { + throw new AppwriteException('Missing required parameter: "rows"'); + } + + const apiPath = '/databases/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', databaseId).replace('{tableId}', tableId); + const payload: Payload = {}; + + if (typeof rows !== 'undefined') { + payload['rows'] = rows; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get a row by its unique ID. This endpoint response returns a JSON object + * with the row data. + * + * @param {string} databaseId + * @param {string} tableId + * @param {string} rowId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + getRow(databaseId: string, tableId: string, rowId: string, queries?: string[]): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof tableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "tableId"'); + } + + if (typeof rowId === 'undefined') { + throw new AppwriteException('Missing required parameter: "rowId"'); + } + + const apiPath = '/databases/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('get', uri, { + }, payload); + } + + /** + * Create or update a Row. Before using this route, you should create a new + * table resource using either a [server + * integration](https://appwrite.io/docs/server/databases#databasesCreateTable) + * API or directly from your database console. + * + * @param {string} databaseId + * @param {string} tableId + * @param {string} rowId + * @throws {AppwriteException} + * @returns {Promise} + */ + upsertRow(databaseId: string, tableId: string, rowId: string): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof tableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "tableId"'); + } + + if (typeof rowId === 'undefined') { + throw new AppwriteException('Missing required parameter: "rowId"'); + } + + const apiPath = '/databases/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); + const payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update a row by its unique ID. Using the patch method you can pass only + * specific fields that will get updated. + * + * @param {string} databaseId + * @param {string} tableId + * @param {string} rowId + * @param {object} data + * @param {string[]} permissions + * @throws {AppwriteException} + * @returns {Promise} + */ + updateRow(databaseId: string, tableId: string, rowId: string, data?: object, permissions?: string[]): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof tableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "tableId"'); + } + + if (typeof rowId === 'undefined') { + throw new AppwriteException('Missing required parameter: "rowId"'); + } + + const apiPath = '/databases/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); + const payload: Payload = {}; + + if (typeof data !== 'undefined') { + payload['data'] = data; + } + + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Delete a row by its unique ID. + * + * @param {string} databaseId + * @param {string} tableId + * @param {string} rowId + * @throws {AppwriteException} + * @returns {Promise} + */ + deleteRow(databaseId: string, tableId: string, rowId: string): Promise<{}> { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof tableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "tableId"'); + } + + if (typeof rowId === 'undefined') { + throw new AppwriteException('Missing required parameter: "rowId"'); + } + + const apiPath = '/databases/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); + const payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('delete', uri, { + 'content-type': 'application/json', + }, payload); + } +}; diff --git a/src/services/teams.ts b/src/services/teams.ts index 98e459f6..d45f7e93 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -21,8 +21,8 @@ export class Teams extends Service { * @param {string} search * @throws {AppwriteException} * @returns {Promise} - */ - list(queries?: string[], search?: string): Promise> { + */ + list(queries?: string[], search?: string): Promise> { const apiPath = '/teams'; const payload: Payload = {}; @@ -49,8 +49,8 @@ export class Teams extends Service { * @param {string[]} roles * @throws {AppwriteException} * @returns {Promise} - */ - create(teamId: string, name: string, roles?: string[]): Promise> { + */ + create(teamId: string, name: string, roles?: string[]): Promise> { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -86,8 +86,8 @@ export class Teams extends Service { * @param {string} teamId * @throws {AppwriteException} * @returns {Promise} - */ - get(teamId: string): Promise> { + */ + get(teamId: string): Promise> { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -107,8 +107,8 @@ export class Teams extends Service { * @param {string} name * @throws {AppwriteException} * @returns {Promise} - */ - updateName(teamId: string, name: string): Promise> { + */ + updateName(teamId: string, name: string): Promise> { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -137,7 +137,7 @@ export class Teams extends Service { * @param {string} teamId * @throws {AppwriteException} * @returns {Promise} - */ + */ delete(teamId: string): Promise<{}> { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); @@ -162,7 +162,7 @@ export class Teams extends Service { * @param {string} search * @throws {AppwriteException} * @returns {Promise} - */ + */ listMemberships(teamId: string, queries?: string[], search?: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); @@ -216,7 +216,7 @@ export class Teams extends Service { * @param {string} name * @throws {AppwriteException} * @returns {Promise} - */ + */ createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); @@ -268,7 +268,7 @@ export class Teams extends Service { * @param {string} membershipId * @throws {AppwriteException} * @returns {Promise} - */ + */ getMembership(teamId: string, membershipId: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); @@ -297,7 +297,7 @@ export class Teams extends Service { * @param {string[]} roles * @throws {AppwriteException} * @returns {Promise} - */ + */ updateMembership(teamId: string, membershipId: string, roles: string[]): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); @@ -333,7 +333,7 @@ export class Teams extends Service { * @param {string} membershipId * @throws {AppwriteException} * @returns {Promise} - */ + */ deleteMembership(teamId: string, membershipId: string): Promise<{}> { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); @@ -367,7 +367,7 @@ export class Teams extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - */ + */ updateMembershipStatus(teamId: string, membershipId: string, userId: string, secret: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); @@ -410,8 +410,8 @@ export class Teams extends Service { * @param {string} teamId * @throws {AppwriteException} * @returns {Promise} - */ - getPrefs(teamId: string): Promise { + */ + getPrefs(teamId: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -433,8 +433,8 @@ export class Teams extends Service { * @param {object} prefs * @throws {AppwriteException} * @returns {Promise} - */ - updatePrefs(teamId: string, prefs: object): Promise { + */ + updatePrefs(teamId: string, prefs: object): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } From c74ae03431542d0941c790785c2a060ba8d5a607 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Jul 2025 06:23:00 +0000 Subject: [PATCH 06/11] chore: regen --- README.md | 4 +- docs/examples/databases/create-document.md | 4 +- .../databases/decrement-document-attribute.md | 18 ++ .../databases/increment-document-attribute.md | 18 ++ docs/examples/databases/upsert-document.md | 8 +- docs/examples/tables/create-row.md | 19 -- docs/examples/tables/create-rows.md | 16 - docs/examples/tables/delete-row.md | 15 - docs/examples/tables/get-row.md | 16 - docs/examples/tables/list-rows.md | 15 - docs/examples/tables/update-row.md | 17 -- docs/examples/tables/upsert-row.md | 17 -- package.json | 2 +- src/client.ts | 4 +- src/index.ts | 1 - src/models.ts | 75 +---- src/services/account.ts | 2 - src/services/databases.ts | 114 ++++++- src/services/tables.ts | 279 ------------------ 19 files changed, 167 insertions(+), 477 deletions(-) create mode 100644 docs/examples/databases/decrement-document-attribute.md create mode 100644 docs/examples/databases/increment-document-attribute.md delete mode 100644 docs/examples/tables/create-row.md delete mode 100644 docs/examples/tables/create-rows.md delete mode 100644 docs/examples/tables/delete-row.md delete mode 100644 docs/examples/tables/get-row.md delete mode 100644 docs/examples/tables/list-rows.md delete mode 100644 docs/examples/tables/update-row.md delete mode 100644 docs/examples/tables/upsert-row.md delete mode 100644 src/services/tables.ts diff --git a/README.md b/README.md index 40867bae..542c5c3e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite React Native SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-react-native.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.8.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).** +**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the React Native SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index ec768fcf..1b28231e 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -2,9 +2,7 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setSession('') // The user session to authenticate with - .setKey('') // - .setJWT(''); // Your secret JSON Web Token + .setProject(''); // Your project ID const databases = new Databases(client); diff --git a/docs/examples/databases/decrement-document-attribute.md b/docs/examples/databases/decrement-document-attribute.md new file mode 100644 index 00000000..4c9c2d99 --- /dev/null +++ b/docs/examples/databases/decrement-document-attribute.md @@ -0,0 +1,18 @@ +import { Client, Databases } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const databases = new Databases(client); + +const result = await databases.decrementDocumentAttribute( + '', // databaseId + '', // collectionId + '', // documentId + '', // attribute + null, // value (optional) + null // min (optional) +); + +console.log(result); diff --git a/docs/examples/databases/increment-document-attribute.md b/docs/examples/databases/increment-document-attribute.md new file mode 100644 index 00000000..3a9d9490 --- /dev/null +++ b/docs/examples/databases/increment-document-attribute.md @@ -0,0 +1,18 @@ +import { Client, Databases } from "react-native-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const databases = new Databases(client); + +const result = await databases.incrementDocumentAttribute( + '', // databaseId + '', // collectionId + '', // documentId + '', // attribute + null, // value (optional) + null // max (optional) +); + +console.log(result); diff --git a/docs/examples/databases/upsert-document.md b/docs/examples/databases/upsert-document.md index 56d3af23..ae423d12 100644 --- a/docs/examples/databases/upsert-document.md +++ b/docs/examples/databases/upsert-document.md @@ -2,16 +2,16 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setSession('') // The user session to authenticate with - .setKey('') // - .setJWT(''); // Your secret JSON Web Token + .setProject(''); // Your project ID const databases = new Databases(client); const result = await databases.upsertDocument( '', // databaseId '', // collectionId - '' // documentId + '', // documentId + {}, // data + ["read("any")"] // permissions (optional) ); console.log(result); diff --git a/docs/examples/tables/create-row.md b/docs/examples/tables/create-row.md deleted file mode 100644 index 75de1c2a..00000000 --- a/docs/examples/tables/create-row.md +++ /dev/null @@ -1,19 +0,0 @@ -import { Client, Tables } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setSession('') // The user session to authenticate with - .setKey('') // - .setJWT(''); // Your secret JSON Web Token - -const tables = new Tables(client); - -const result = await tables.createRow( - '', // databaseId - '', // tableId - '', // rowId - {}, // data - ["read("any")"] // permissions (optional) -); - -console.log(result); diff --git a/docs/examples/tables/create-rows.md b/docs/examples/tables/create-rows.md deleted file mode 100644 index 165aa4cb..00000000 --- a/docs/examples/tables/create-rows.md +++ /dev/null @@ -1,16 +0,0 @@ -import { Client, Tables } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setAdmin('') // - .setKey(''); // - -const tables = new Tables(client); - -const result = await tables.createRows( - '', // databaseId - '', // tableId - [] // rows -); - -console.log(result); diff --git a/docs/examples/tables/delete-row.md b/docs/examples/tables/delete-row.md deleted file mode 100644 index 9746f85e..00000000 --- a/docs/examples/tables/delete-row.md +++ /dev/null @@ -1,15 +0,0 @@ -import { Client, Tables } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const tables = new Tables(client); - -const result = await tables.deleteRow( - '', // databaseId - '', // tableId - '' // rowId -); - -console.log(result); diff --git a/docs/examples/tables/get-row.md b/docs/examples/tables/get-row.md deleted file mode 100644 index b9434e39..00000000 --- a/docs/examples/tables/get-row.md +++ /dev/null @@ -1,16 +0,0 @@ -import { Client, Tables } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const tables = new Tables(client); - -const result = await tables.getRow( - '', // databaseId - '', // tableId - '', // rowId - [] // queries (optional) -); - -console.log(result); diff --git a/docs/examples/tables/list-rows.md b/docs/examples/tables/list-rows.md deleted file mode 100644 index 75f81a14..00000000 --- a/docs/examples/tables/list-rows.md +++ /dev/null @@ -1,15 +0,0 @@ -import { Client, Tables } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const tables = new Tables(client); - -const result = await tables.listRows( - '', // databaseId - '', // tableId - [] // queries (optional) -); - -console.log(result); diff --git a/docs/examples/tables/update-row.md b/docs/examples/tables/update-row.md deleted file mode 100644 index 7bb36dd2..00000000 --- a/docs/examples/tables/update-row.md +++ /dev/null @@ -1,17 +0,0 @@ -import { Client, Tables } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const tables = new Tables(client); - -const result = await tables.updateRow( - '', // databaseId - '', // tableId - '', // rowId - {}, // data (optional) - ["read("any")"] // permissions (optional) -); - -console.log(result); diff --git a/docs/examples/tables/upsert-row.md b/docs/examples/tables/upsert-row.md deleted file mode 100644 index f176425a..00000000 --- a/docs/examples/tables/upsert-row.md +++ /dev/null @@ -1,17 +0,0 @@ -import { Client, Tables } from "react-native-appwrite"; - -const client = new Client() - .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint - .setSession('') // The user session to authenticate with - .setKey('') // - .setJWT(''); // Your secret JSON Web Token - -const tables = new Tables(client); - -const result = await tables.upsertRow( - '', // databaseId - '', // tableId - '' // rowId -); - -console.log(result); diff --git a/package.json b/package.json index 92479c87..c4717855 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "0.11.0", + "version": "0.10.1", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index a0b2f34c..b404254b 100644 --- a/src/client.ts +++ b/src/client.ts @@ -115,8 +115,8 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '0.11.0', - 'X-Appwrite-Response-Format': '1.8.0', + 'x-sdk-version': '0.10.1', + 'X-Appwrite-Response-Format': '1.7.0', }; /** diff --git a/src/index.ts b/src/index.ts index 35d654c8..bbc74cce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ export { Client, AppwriteException } from './client'; export { Account } from './services/account'; export { Avatars } from './services/avatars'; export { Databases } from './services/databases'; -export { Tables } from './services/tables'; export { Functions } from './services/functions'; export { Graphql } from './services/graphql'; export { Locale } from './services/locale'; diff --git a/src/models.ts b/src/models.ts index 1acb8a42..13efc688 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1,23 +1,10 @@ export namespace Models { - /** - * Rows List - */ - export type RowList = { - /** - * Total number of rows rows that matched your query. - */ - total: number; - /** - * List of rows. - */ - rows: Row[]; - } /** * Documents List */ export type DocumentList = { /** - * Total number of documents rows that matched your query. + * Total number of documents documents that matched your query. */ total: number; /** @@ -30,7 +17,7 @@ export namespace Models { */ export type SessionList = { /** - * Total number of sessions rows that matched your query. + * Total number of sessions documents that matched your query. */ total: number; /** @@ -43,7 +30,7 @@ export namespace Models { */ export type IdentityList = { /** - * Total number of identities rows that matched your query. + * Total number of identities documents that matched your query. */ total: number; /** @@ -56,7 +43,7 @@ export namespace Models { */ export type LogList = { /** - * Total number of logs rows that matched your query. + * Total number of logs documents that matched your query. */ total: number; /** @@ -69,7 +56,7 @@ export namespace Models { */ export type FileList = { /** - * Total number of files rows that matched your query. + * Total number of files documents that matched your query. */ total: number; /** @@ -82,7 +69,7 @@ export namespace Models { */ export type TeamList = { /** - * Total number of teams rows that matched your query. + * Total number of teams documents that matched your query. */ total: number; /** @@ -95,7 +82,7 @@ export namespace Models { */ export type MembershipList = { /** - * Total number of memberships rows that matched your query. + * Total number of memberships documents that matched your query. */ total: number; /** @@ -108,7 +95,7 @@ export namespace Models { */ export type ExecutionList = { /** - * Total number of executions rows that matched your query. + * Total number of executions documents that matched your query. */ total: number; /** @@ -121,7 +108,7 @@ export namespace Models { */ export type CountryList = { /** - * Total number of countries rows that matched your query. + * Total number of countries documents that matched your query. */ total: number; /** @@ -134,7 +121,7 @@ export namespace Models { */ export type ContinentList = { /** - * Total number of continents rows that matched your query. + * Total number of continents documents that matched your query. */ total: number; /** @@ -147,7 +134,7 @@ export namespace Models { */ export type LanguageList = { /** - * Total number of languages rows that matched your query. + * Total number of languages documents that matched your query. */ total: number; /** @@ -160,7 +147,7 @@ export namespace Models { */ export type CurrencyList = { /** - * Total number of currencies rows that matched your query. + * Total number of currencies documents that matched your query. */ total: number; /** @@ -173,7 +160,7 @@ export namespace Models { */ export type PhoneList = { /** - * Total number of phones rows that matched your query. + * Total number of phones documents that matched your query. */ total: number; /** @@ -186,7 +173,7 @@ export namespace Models { */ export type LocaleCodeList = { /** - * Total number of localeCodes rows that matched your query. + * Total number of localeCodes documents that matched your query. */ total: number; /** @@ -194,40 +181,6 @@ export namespace Models { */ localeCodes: LocaleCode[]; } - /** - * Row - */ - export type Row = { - /** - * Row ID. - */ - $id: string; - /** - * Row automatically incrementing ID. - */ - $sequence: number; - /** - * Table ID. - */ - $tableId: string; - /** - * Database ID. - */ - $databaseId: string; - /** - * Row creation date in ISO 8601 format. - */ - $createdAt: string; - /** - * Row update date in ISO 8601 format. - */ - $updatedAt: string; - /** - * Row permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - */ - $permissions: string[]; - [key: string]: any; - } /** * Document */ diff --git a/src/services/account.ts b/src/services/account.ts index cca5bae1..713f7369 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -780,7 +780,6 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - * @deprecated This API has been deprecated. */ updateMagicURLSession(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { @@ -872,7 +871,6 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - * @deprecated This API has been deprecated. */ updatePhoneSession(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { diff --git a/src/services/databases.ts b/src/services/databases.ts index c0031fae..ca803325 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -22,7 +22,6 @@ export class Databases extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.listRows` instead. */ listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { if (typeof databaseId === 'undefined') { @@ -58,7 +57,6 @@ export class Databases extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.createRow` instead. */ createDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { if (typeof databaseId === 'undefined') { @@ -108,7 +106,6 @@ export class Databases extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.getRow` instead. */ getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { if (typeof databaseId === 'undefined') { @@ -148,11 +145,12 @@ export class Databases extends Service { * @param {string} databaseId * @param {string} collectionId * @param {string} documentId + * @param {object} data + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.upsertRow` instead. */ - upsertDocument(databaseId: string, collectionId: string, documentId: string): Promise { + upsertDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -165,9 +163,21 @@ export class Databases extends Service { throw new AppwriteException('Missing required parameter: "documentId"'); } + if (typeof data === 'undefined') { + throw new AppwriteException('Missing required parameter: "data"'); + } + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); const payload: Payload = {}; + if (typeof data !== 'undefined') { + payload['data'] = data; + } + + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('put', uri, { 'content-type': 'application/json', @@ -185,7 +195,6 @@ export class Databases extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.updateRow` instead. */ updateDocument(databaseId: string, collectionId: string, documentId: string, data?: object, permissions?: string[]): Promise { if (typeof databaseId === 'undefined') { @@ -225,7 +234,6 @@ export class Databases extends Service { * @param {string} documentId * @throws {AppwriteException} * @returns {Promise} - * @deprecated This API has been deprecated since 1.8.0. Please use `Tables.deleteRow` instead. */ deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<{}> { if (typeof databaseId === 'undefined') { @@ -248,4 +256,96 @@ export class Databases extends Service { 'content-type': 'application/json', }, payload); } + + /** + * Decrement a specific attribute of a document by a given value. + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string} documentId + * @param {string} attribute + * @param {number} value + * @param {number} min + * @throws {AppwriteException} + * @returns {Promise} + */ + decrementDocumentAttribute(databaseId: string, collectionId: string, documentId: string, attribute: string, value?: number, min?: number): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + + if (typeof attribute === 'undefined') { + throw new AppwriteException('Missing required parameter: "attribute"'); + } + + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute); + const payload: Payload = {}; + + if (typeof value !== 'undefined') { + payload['value'] = value; + } + + if (typeof min !== 'undefined') { + payload['min'] = min; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Increment a specific attribute of a document by a given value. + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string} documentId + * @param {string} attribute + * @param {number} value + * @param {number} max + * @throws {AppwriteException} + * @returns {Promise} + */ + incrementDocumentAttribute(databaseId: string, collectionId: string, documentId: string, attribute: string, value?: number, max?: number): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + + if (typeof attribute === 'undefined') { + throw new AppwriteException('Missing required parameter: "attribute"'); + } + + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute); + const payload: Payload = {}; + + if (typeof value !== 'undefined') { + payload['value'] = value; + } + + if (typeof max !== 'undefined') { + payload['max'] = max; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } }; diff --git a/src/services/tables.ts b/src/services/tables.ts deleted file mode 100644 index 9e86fbee..00000000 --- a/src/services/tables.ts +++ /dev/null @@ -1,279 +0,0 @@ -import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; -import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; -import * as FileSystem from 'expo-file-system'; -import { Platform } from 'react-native'; - - -export class Tables extends Service { - - constructor(client: Client) - { - super(client); - } - - /** - * Get a list of all the user's rows in a given table. You can use the query - * params to filter your results. - * - * @param {string} databaseId - * @param {string} tableId - * @param {string[]} queries - * @throws {AppwriteException} - * @returns {Promise} - */ - listRows(databaseId: string, tableId: string, queries?: string[]): Promise> { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof tableId === 'undefined') { - throw new AppwriteException('Missing required parameter: "tableId"'); - } - - const apiPath = '/databases/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', databaseId).replace('{tableId}', tableId); - const payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('get', uri, { - }, payload); - } - - /** - * Create a new Row. Before using this route, you should create a new table - * resource using either a [server - * integration](https://appwrite.io/docs/server/databases#databasesCreateTable) - * API or directly from your database console. - * - * @param {string} databaseId - * @param {string} tableId - * @param {string} rowId - * @param {object} data - * @param {string[]} permissions - * @throws {AppwriteException} - * @returns {Promise} - */ - createRow(databaseId: string, tableId: string, rowId: string, data: object, permissions?: string[]): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof tableId === 'undefined') { - throw new AppwriteException('Missing required parameter: "tableId"'); - } - - if (typeof rowId === 'undefined') { - throw new AppwriteException('Missing required parameter: "rowId"'); - } - - if (typeof data === 'undefined') { - throw new AppwriteException('Missing required parameter: "data"'); - } - - const apiPath = '/databases/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', databaseId).replace('{tableId}', tableId); - const payload: Payload = {}; - - if (typeof rowId !== 'undefined') { - payload['rowId'] = rowId; - } - - if (typeof data !== 'undefined') { - payload['data'] = data; - } - - if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create new Rows. Before using this route, you should create a new table - * resource using either a [server - * integration](https://appwrite.io/docs/server/databases#databasesCreateTable) - * API or directly from your database console. - * - * @param {string} databaseId - * @param {string} tableId - * @param {object[]} rows - * @throws {AppwriteException} - * @returns {Promise} - */ - createRows(databaseId: string, tableId: string, rows: object[]): Promise> { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof tableId === 'undefined') { - throw new AppwriteException('Missing required parameter: "tableId"'); - } - - if (typeof rows === 'undefined') { - throw new AppwriteException('Missing required parameter: "rows"'); - } - - const apiPath = '/databases/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', databaseId).replace('{tableId}', tableId); - const payload: Payload = {}; - - if (typeof rows !== 'undefined') { - payload['rows'] = rows; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Get a row by its unique ID. This endpoint response returns a JSON object - * with the row data. - * - * @param {string} databaseId - * @param {string} tableId - * @param {string} rowId - * @param {string[]} queries - * @throws {AppwriteException} - * @returns {Promise} - */ - getRow(databaseId: string, tableId: string, rowId: string, queries?: string[]): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof tableId === 'undefined') { - throw new AppwriteException('Missing required parameter: "tableId"'); - } - - if (typeof rowId === 'undefined') { - throw new AppwriteException('Missing required parameter: "rowId"'); - } - - const apiPath = '/databases/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); - const payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('get', uri, { - }, payload); - } - - /** - * Create or update a Row. Before using this route, you should create a new - * table resource using either a [server - * integration](https://appwrite.io/docs/server/databases#databasesCreateTable) - * API or directly from your database console. - * - * @param {string} databaseId - * @param {string} tableId - * @param {string} rowId - * @throws {AppwriteException} - * @returns {Promise} - */ - upsertRow(databaseId: string, tableId: string, rowId: string): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof tableId === 'undefined') { - throw new AppwriteException('Missing required parameter: "tableId"'); - } - - if (typeof rowId === 'undefined') { - throw new AppwriteException('Missing required parameter: "rowId"'); - } - - const apiPath = '/databases/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); - const payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update a row by its unique ID. Using the patch method you can pass only - * specific fields that will get updated. - * - * @param {string} databaseId - * @param {string} tableId - * @param {string} rowId - * @param {object} data - * @param {string[]} permissions - * @throws {AppwriteException} - * @returns {Promise} - */ - updateRow(databaseId: string, tableId: string, rowId: string, data?: object, permissions?: string[]): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof tableId === 'undefined') { - throw new AppwriteException('Missing required parameter: "tableId"'); - } - - if (typeof rowId === 'undefined') { - throw new AppwriteException('Missing required parameter: "rowId"'); - } - - const apiPath = '/databases/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); - const payload: Payload = {}; - - if (typeof data !== 'undefined') { - payload['data'] = data; - } - - if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Delete a row by its unique ID. - * - * @param {string} databaseId - * @param {string} tableId - * @param {string} rowId - * @throws {AppwriteException} - * @returns {Promise} - */ - deleteRow(databaseId: string, tableId: string, rowId: string): Promise<{}> { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof tableId === 'undefined') { - throw new AppwriteException('Missing required parameter: "tableId"'); - } - - if (typeof rowId === 'undefined') { - throw new AppwriteException('Missing required parameter: "rowId"'); - } - - const apiPath = '/databases/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); - const payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call('delete', uri, { - 'content-type': 'application/json', - }, payload); - } -}; From 13e14ec1854044e36582bb939c47a0db3b497904 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Jul 2025 06:25:52 +0000 Subject: [PATCH 07/11] chore: add changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab2975b..ad6d00f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log +## 0.10.2 + +* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service +* Add `sequence` support to `Document` model +* Fix autocompletion not working for `Document` model even when generic is passed + ## 0.10.1 * Fix URL based methods like `getFileViewURL`, `getFilePreviewURL` etc. by adding the missing `projectId` to searchParams From 29430cb5eea6ca1f72120af5048749719da50194 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Jul 2025 06:41:38 +0000 Subject: [PATCH 08/11] chore: regen to 1.7.x --- CHANGELOG.md | 2 +- package.json | 2 +- src/client.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6d00f7..a15eb1b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,4 +34,4 @@ ## 0.7.4 * Upgrade dependencies to resolve PlatformConstants error with Expo 53 -* Update doc examples to use new multi-region endpoint \ No newline at end of file +* Update doc examples to use new multi-region endpoint diff --git a/package.json b/package.json index c4717855..92479c87 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "0.10.1", + "version": "0.11.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index b404254b..22628773 100644 --- a/src/client.ts +++ b/src/client.ts @@ -115,7 +115,7 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '0.10.1', + 'x-sdk-version': '0.11.0', 'X-Appwrite-Response-Format': '1.7.0', }; From 1bd2fdfb4ba716577914dd487211813a84373f6a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Jul 2025 07:32:14 +0000 Subject: [PATCH 09/11] chore: hotfix --- src/models.ts | 73 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/src/models.ts b/src/models.ts index 13efc688..4887e222 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1,4 +1,7 @@ export namespace Models { + + declare const __default: unique symbol; + /** * Documents List */ @@ -12,6 +15,7 @@ export namespace Models { */ documents: Document[]; } + /** * Sessions List */ @@ -25,6 +29,7 @@ export namespace Models { */ sessions: Session[]; } + /** * Identities List */ @@ -38,6 +43,7 @@ export namespace Models { */ identities: Identity[]; } + /** * Logs List */ @@ -51,6 +57,7 @@ export namespace Models { */ logs: Log[]; } + /** * Files List */ @@ -64,6 +71,7 @@ export namespace Models { */ files: File[]; } + /** * Teams List */ @@ -77,6 +85,7 @@ export namespace Models { */ teams: Team[]; } + /** * Memberships List */ @@ -90,6 +99,7 @@ export namespace Models { */ memberships: Membership[]; } + /** * Executions List */ @@ -103,6 +113,7 @@ export namespace Models { */ executions: Execution[]; } + /** * Countries List */ @@ -116,6 +127,7 @@ export namespace Models { */ countries: Country[]; } + /** * Continents List */ @@ -129,6 +141,7 @@ export namespace Models { */ continents: Continent[]; } + /** * Languages List */ @@ -142,6 +155,7 @@ export namespace Models { */ languages: Language[]; } + /** * Currencies List */ @@ -155,6 +169,7 @@ export namespace Models { */ currencies: Currency[]; } + /** * Phones List */ @@ -168,6 +183,7 @@ export namespace Models { */ phones: Phone[]; } + /** * Locale codes list */ @@ -181,6 +197,7 @@ export namespace Models { */ localeCodes: LocaleCode[]; } + /** * Document */ @@ -213,8 +230,19 @@ export namespace Models { * Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). */ $permissions: string[]; - [key: string]: any; } + + export type DefaultDocument = Document & { + [key: string]: any; + [__default]: true; + }; + + export type DataWithoutDocumentKeys = { + [K in string]: any; + } & { + [K in keyof Document]?: never; + }; + /** * Log */ @@ -304,6 +332,7 @@ export namespace Models { */ countryName: string; } + /** * User */ @@ -385,6 +414,7 @@ export namespace Models { */ accessedAt: string; } + /** * AlgoMD5 */ @@ -394,6 +424,7 @@ export namespace Models { */ type: string; } + /** * AlgoSHA */ @@ -403,6 +434,7 @@ export namespace Models { */ type: string; } + /** * AlgoPHPass */ @@ -412,6 +444,7 @@ export namespace Models { */ type: string; } + /** * AlgoBcrypt */ @@ -421,6 +454,7 @@ export namespace Models { */ type: string; } + /** * AlgoScrypt */ @@ -446,6 +480,7 @@ export namespace Models { */ length: number; } + /** * AlgoScryptModified */ @@ -467,6 +502,7 @@ export namespace Models { */ signerKey: string; } + /** * AlgoArgon2 */ @@ -488,12 +524,24 @@ export namespace Models { */ threads: number; } + /** * Preferences */ export type Preferences = { - [key: string]: any; } + + export type DefaultPreferences = Preferences & { + [key: string]: any; + [__default]: true; + }; + + export type DataWithoutPreferencesKeys = { + [K in string]: any; + } & { + [K in keyof Preferences]?: never; + }; + /** * Session */ @@ -615,6 +663,7 @@ export namespace Models { */ mfaUpdatedAt: string; } + /** * Identity */ @@ -660,6 +709,7 @@ export namespace Models { */ providerRefreshToken: string; } + /** * Token */ @@ -689,6 +739,7 @@ export namespace Models { */ phrase: string; } + /** * JWT */ @@ -698,6 +749,7 @@ export namespace Models { */ jwt: string; } + /** * Locale */ @@ -731,6 +783,7 @@ export namespace Models { */ currency: string; } + /** * LocaleCode */ @@ -744,6 +797,7 @@ export namespace Models { */ name: string; } + /** * File */ @@ -793,6 +847,7 @@ export namespace Models { */ chunksUploaded: number; } + /** * Team */ @@ -822,6 +877,7 @@ export namespace Models { */ prefs: Preferences; } + /** * Membership */ @@ -879,6 +935,7 @@ export namespace Models { */ roles: string[]; } + /** * Execution */ @@ -952,6 +1009,7 @@ export namespace Models { */ scheduledAt?: string; } + /** * Country */ @@ -965,6 +1023,7 @@ export namespace Models { */ code: string; } + /** * Continent */ @@ -978,6 +1037,7 @@ export namespace Models { */ code: string; } + /** * Language */ @@ -995,6 +1055,7 @@ export namespace Models { */ nativeName: string; } + /** * Currency */ @@ -1028,6 +1089,7 @@ export namespace Models { */ namePlural: string; } + /** * Phone */ @@ -1045,6 +1107,7 @@ export namespace Models { */ countryName: string; } + /** * Headers */ @@ -1058,6 +1121,7 @@ export namespace Models { */ value: string; } + /** * MFA Challenge */ @@ -1079,6 +1143,7 @@ export namespace Models { */ expire: string; } + /** * MFA Recovery Codes */ @@ -1088,6 +1153,7 @@ export namespace Models { */ recoveryCodes: string[]; } + /** * MFAType */ @@ -1101,6 +1167,7 @@ export namespace Models { */ uri: string; } + /** * MFAFactors */ @@ -1122,6 +1189,7 @@ export namespace Models { */ recoveryCode: boolean; } + /** * Subscriber */ @@ -1163,6 +1231,7 @@ export namespace Models { */ providerType: string; } + /** * Target */ From 4010533a72e4dc78ac3b62894864967c18c86e3e Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Jul 2025 07:47:10 +0000 Subject: [PATCH 10/11] fix: version to 0.10.2 --- package.json | 2 +- src/client.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 92479c87..9c716a2a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "0.11.0", + "version": "0.10.2", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index 22628773..8c0125bb 100644 --- a/src/client.ts +++ b/src/client.ts @@ -115,7 +115,7 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '0.11.0', + 'x-sdk-version': '0.10.2', 'X-Appwrite-Response-Format': '1.7.0', }; From ed9ff97e62431a5975c5ba4e64bb6c9927643498 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 25 Jul 2025 09:37:24 +0000 Subject: [PATCH 11/11] fix: version in changelog --- CHANGELOG.md | 2 +- package.json | 2 +- src/client.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a15eb1b0..eda0bca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change log -## 0.10.2 +## 0.11.0 * Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service * Add `sequence` support to `Document` model diff --git a/package.json b/package.json index 9c716a2a..92479c87 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "0.10.2", + "version": "0.11.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index 8c0125bb..22628773 100644 --- a/src/client.ts +++ b/src/client.ts @@ -115,7 +115,7 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '0.10.2', + 'x-sdk-version': '0.11.0', 'X-Appwrite-Response-Format': '1.7.0', };