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/CHANGELOG.md b/CHANGELOG.md index 6ab2975b..a15eb1b0 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 @@ -28,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/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/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..13efc688 100644 --- a/src/models.ts +++ b/src/models.ts @@ -2,7 +2,7 @@ export namespace Models { /** * Documents List */ - export type DocumentList = { + export type DocumentList = { /** * Total number of documents documents that matched your query. */ @@ -67,7 +67,7 @@ export namespace Models { /** * Teams List */ - export type TeamList = { + export type TeamList = { /** * Total number of teams documents that matched your query. */ @@ -189,6 +189,10 @@ export namespace Models { * Document ID. */ $id: string; + /** + * Document automatically incrementing ID. + */ + $sequence: number; /** * Collection ID. */ @@ -303,7 +307,7 @@ export namespace Models { /** * User */ - export type User = { + export type User = { /** * User ID. */ @@ -792,7 +796,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..713f7369 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,7 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - */ + */ updateMagicURLSession(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -831,7 +831,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 +871,7 @@ export class Account extends Service { * @param {string} secret * @throws {AppwriteException} * @returns {Promise} - */ + */ updatePhoneSession(userId: string, secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); @@ -907,7 +907,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 +941,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 +963,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 +988,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 +1010,8 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ - updateStatus(): Promise> { + */ + updateStatus(): Promise> { const apiPath = '/account/status'; const payload: Payload = {}; @@ -1033,7 +1033,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 +1075,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 +1106,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 +1138,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 +1191,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 +1248,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 +1295,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 +1342,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 +1371,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 +1410,7 @@ export class Account extends Service { * * @throws {AppwriteException} * @returns {Promise} - */ + */ createPhoneVerification(): Promise { const apiPath = '/account/verification/phone'; const payload: Payload = {}; @@ -1431,7 +1431,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 09186833..ca803325 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -22,8 +22,8 @@ export class Databases extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - */ - listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { + */ + listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -57,8 +57,8 @@ export class Databases extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - */ - createDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { + */ + 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 +106,8 @@ export class Databases extends Service { * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} - */ - getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { + */ + getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -149,8 +149,8 @@ export class Databases extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - */ - upsertDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: 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"'); } @@ -195,8 +195,8 @@ export class Databases extends Service { * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} - */ - updateDocument(databaseId: string, collectionId: string, documentId: string, data?: object, permissions?: string[]): Promise { + */ + 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 +234,7 @@ export class Databases extends Service { * @param {string} documentId * @throws {AppwriteException} * @returns {Promise} - */ + */ deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<{}> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); @@ -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); + } }; 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/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"'); }