From dbfef5f3c82c25789db39b4ca69303a7d2c2e1cb Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 3 Nov 2025 16:29:06 +1300 Subject: [PATCH] Add operators --- CHANGELOG.md | 5 + docs/examples/account/list-identities.md | 3 +- docs/examples/account/list-logs.md | 3 +- docs/examples/databases/create-document.md | 2 +- docs/examples/databases/list-documents.md | 3 +- docs/examples/databases/update-document.md | 2 +- docs/examples/databases/upsert-document.md | 2 +- docs/examples/functions/list-executions.md | 3 +- docs/examples/storage/create-file.md | 2 +- docs/examples/storage/list-files.md | 3 +- docs/examples/storage/update-file.md | 2 +- docs/examples/tablesdb/create-row.md | 2 +- docs/examples/tablesdb/list-rows.md | 3 +- docs/examples/tablesdb/update-row.md | 2 +- docs/examples/tablesdb/upsert-row.md | 2 +- docs/examples/teams/list-memberships.md | 3 +- docs/examples/teams/list.md | 3 +- package.json | 5 +- src/client.ts | 2 +- src/enums/execution-status.ts | 1 + src/index.ts | 3 + src/models.ts | 2 +- src/operator.ts | 308 +++++++++++++++++++++ src/query.ts | 12 +- src/services/account.ts | 42 ++- src/services/databases.ts | 22 +- src/services/functions.ts | 22 +- src/services/storage.ts | 22 +- src/services/tables-db.ts | 22 +- src/services/teams.ts | 44 ++- 30 files changed, 471 insertions(+), 81 deletions(-) create mode 100644 src/operator.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f1f15907..757a5f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change log +## 0.18.0 + +* Add `total` parameter to list queries allowing skipping counting rows in a table for improved performance +* Add `Operator` class for atomic modification of rows via update, bulk update, upsert, and bulk upsert operations + ## 0.17.1 * Add transaction support for Databases and TablesDB diff --git a/docs/examples/account/list-identities.md b/docs/examples/account/list-identities.md index 2a3bbae3..5ff727ad 100644 --- a/docs/examples/account/list-identities.md +++ b/docs/examples/account/list-identities.md @@ -7,7 +7,8 @@ const client = new Client() const account = new Account(client); const result = await account.listIdentities({ - queries: [] // optional + queries: [], // optional + total: false // optional }); console.log(result); diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index 4bb9f9fd..e3109f32 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -7,7 +7,8 @@ const client = new Client() const account = new Account(client); const result = await account.listLogs({ - queries: [] // optional + queries: [], // optional + total: false // optional }); console.log(result); diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 3f7fd9af..58ea6ee1 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -1,4 +1,4 @@ -import { Client, Databases } from "react-native-appwrite"; +import { Client, Databases, Permission, Role } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index a744a531..6a9959ab 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -10,7 +10,8 @@ const result = await databases.listDocuments({ databaseId: '', collectionId: '', queries: [], // optional - transactionId: '' // optional + transactionId: '', // optional + total: false // optional }); console.log(result); diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 29674bd3..a82fa523 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -1,4 +1,4 @@ -import { Client, Databases } from "react-native-appwrite"; +import { Client, Databases, Permission, Role } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/databases/upsert-document.md b/docs/examples/databases/upsert-document.md index aa8fd1ca..b6d2bed4 100644 --- a/docs/examples/databases/upsert-document.md +++ b/docs/examples/databases/upsert-document.md @@ -1,4 +1,4 @@ -import { Client, Databases } from "react-native-appwrite"; +import { Client, Databases, Permission, Role } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index 7b046dde..e832293e 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -8,7 +8,8 @@ const functions = new Functions(client); const result = await functions.listExecutions({ functionId: '', - queries: [] // optional + queries: [], // optional + total: false // optional }); console.log(result); diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 965c8d42..c1a383d5 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -1,4 +1,4 @@ -import { Client, Storage } from "react-native-appwrite"; +import { Client, Storage, Permission, Role } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index 4c6e159d..38569ad9 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -9,7 +9,8 @@ const storage = new Storage(client); const result = await storage.listFiles({ bucketId: '', queries: [], // optional - search: '' // optional + search: '', // optional + total: false // optional }); console.log(result); diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index 2a8092f8..dd98cdbb 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -1,4 +1,4 @@ -import { Client, Storage } from "react-native-appwrite"; +import { Client, Storage, Permission, Role } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/tablesdb/create-row.md b/docs/examples/tablesdb/create-row.md index 6be799f5..33f1c8d4 100644 --- a/docs/examples/tablesdb/create-row.md +++ b/docs/examples/tablesdb/create-row.md @@ -1,4 +1,4 @@ -import { Client, TablesDB } from "react-native-appwrite"; +import { Client, TablesDB, Permission, Role } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/tablesdb/list-rows.md b/docs/examples/tablesdb/list-rows.md index 7cab86bc..85e50b54 100644 --- a/docs/examples/tablesdb/list-rows.md +++ b/docs/examples/tablesdb/list-rows.md @@ -10,7 +10,8 @@ const result = await tablesDB.listRows({ databaseId: '', tableId: '', queries: [], // optional - transactionId: '' // optional + transactionId: '', // optional + total: false // optional }); console.log(result); diff --git a/docs/examples/tablesdb/update-row.md b/docs/examples/tablesdb/update-row.md index a83e3ea3..b53b927b 100644 --- a/docs/examples/tablesdb/update-row.md +++ b/docs/examples/tablesdb/update-row.md @@ -1,4 +1,4 @@ -import { Client, TablesDB } from "react-native-appwrite"; +import { Client, TablesDB, Permission, Role } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/tablesdb/upsert-row.md b/docs/examples/tablesdb/upsert-row.md index 7a82e071..28909273 100644 --- a/docs/examples/tablesdb/upsert-row.md +++ b/docs/examples/tablesdb/upsert-row.md @@ -1,4 +1,4 @@ -import { Client, TablesDB } from "react-native-appwrite"; +import { Client, TablesDB, Permission, Role } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index 12f71549..5c017378 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -9,7 +9,8 @@ const teams = new Teams(client); const result = await teams.listMemberships({ teamId: '', queries: [], // optional - search: '' // optional + search: '', // optional + total: false // optional }); console.log(result); diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index f9ca4c40..36fdcfbd 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -8,7 +8,8 @@ const teams = new Teams(client); const result = await teams.list({ queries: [], // optional - search: '' // optional + search: '', // optional + total: false // optional }); console.log(result); diff --git a/package.json b/package.json index c0a44cff..190e7f5a 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.17.1", + "version": "0.18.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { @@ -37,7 +37,6 @@ "react-native": ">=0.76.7 <1.0.0" }, "peerDependencies": { - "expo": "*", - "react-native": "*" + "expo": "*" } } diff --git a/src/client.ts b/src/client.ts index 428d8011..1bd50680 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.17.1', + 'x-sdk-version': '0.18.0', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/src/enums/execution-status.ts b/src/enums/execution-status.ts index 1781e941..992d987d 100644 --- a/src/enums/execution-status.ts +++ b/src/enums/execution-status.ts @@ -3,4 +3,5 @@ export enum ExecutionStatus { Processing = 'processing', Completed = 'completed', Failed = 'failed', + Scheduled = 'scheduled', } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index e8b51b8a..cbb31951 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ export { Query } from './query'; export { Permission } from './permission'; export { Role } from './role'; export { ID } from './id'; +export { Operator, Condition } from './operator'; export { AuthenticatorType } from './enums/authenticator-type'; export { AuthenticationFactor } from './enums/authentication-factor'; export { OAuthProvider } from './enums/o-auth-provider'; @@ -24,3 +25,5 @@ export { Flag } from './enums/flag'; export { ExecutionMethod } from './enums/execution-method'; export { ImageGravity } from './enums/image-gravity'; export { ImageFormat } from './enums/image-format'; +export { ExecutionTrigger } from './enums/execution-trigger'; +export { ExecutionStatus } from './enums/execution-status'; diff --git a/src/models.ts b/src/models.ts index 77fde954..8731110c 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1027,7 +1027,7 @@ export namespace Models { */ trigger: ExecutionTrigger; /** - * The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. + * The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, `failed`, or `scheduled`. */ status: ExecutionStatus; /** diff --git a/src/operator.ts b/src/operator.ts new file mode 100644 index 00000000..2386a6c4 --- /dev/null +++ b/src/operator.ts @@ -0,0 +1,308 @@ +type OperatorValuesSingle = string | number | boolean; +export type OperatorValuesList = string[] | number[] | boolean[] | any[]; +export type OperatorValues = OperatorValuesSingle | OperatorValuesList; + +export enum Condition { + Equal = "equal", + NotEqual = "notEqual", + GreaterThan = "greaterThan", + GreaterThanEqual = "greaterThanEqual", + LessThan = "lessThan", + LessThanEqual = "lessThanEqual", + Contains = "contains", + IsNull = "isNull", + IsNotNull = "isNotNull", +} + +/** + * Helper class to generate operator strings for atomic operations. + */ +export class Operator { + method: string; + values: OperatorValuesList | undefined; + + /** + * Constructor for Operator class. + * + * @param {string} method + * @param {OperatorValues} values + */ + constructor( + method: string, + values?: OperatorValues + ) { + this.method = method; + + if (values !== undefined) { + if (Array.isArray(values)) { + this.values = values; + } else { + this.values = [values] as OperatorValuesList; + } + } + } + + /** + * Convert the operator object to a JSON string. + * + * @returns {string} + */ + toString(): string { + return JSON.stringify({ + method: this.method, + values: this.values, + }); + } + + /** + * Increment a numeric attribute by a specified value. + * + * @param {number} value + * @param {number} max + * @returns {string} + */ + static increment = (value: number = 1, max?: number): string => { + if (isNaN(value) || !isFinite(value)) { + throw new Error("Value cannot be NaN or Infinity"); + } + if (max !== undefined && (isNaN(max) || !isFinite(max))) { + throw new Error("Max cannot be NaN or Infinity"); + } + const values: any[] = [value]; + if (max !== undefined) { + values.push(max); + } + return new Operator("increment", values).toString(); + }; + + /** + * Decrement a numeric attribute by a specified value. + * + * @param {number} value + * @param {number} min + * @returns {string} + */ + static decrement = (value: number = 1, min?: number): string => { + if (isNaN(value) || !isFinite(value)) { + throw new Error("Value cannot be NaN or Infinity"); + } + if (min !== undefined && (isNaN(min) || !isFinite(min))) { + throw new Error("Min cannot be NaN or Infinity"); + } + const values: any[] = [value]; + if (min !== undefined) { + values.push(min); + } + return new Operator("decrement", values).toString(); + }; + + /** + * Multiply a numeric attribute by a specified factor. + * + * @param {number} factor + * @param {number} max + * @returns {string} + */ + static multiply = (factor: number, max?: number): string => { + if (isNaN(factor) || !isFinite(factor)) { + throw new Error("Factor cannot be NaN or Infinity"); + } + if (max !== undefined && (isNaN(max) || !isFinite(max))) { + throw new Error("Max cannot be NaN or Infinity"); + } + const values: any[] = [factor]; + if (max !== undefined) { + values.push(max); + } + return new Operator("multiply", values).toString(); + }; + + /** + * Divide a numeric attribute by a specified divisor. + * + * @param {number} divisor + * @param {number} min + * @returns {string} + */ + static divide = (divisor: number, min?: number): string => { + if (isNaN(divisor) || !isFinite(divisor)) { + throw new Error("Divisor cannot be NaN or Infinity"); + } + if (min !== undefined && (isNaN(min) || !isFinite(min))) { + throw new Error("Min cannot be NaN or Infinity"); + } + if (divisor === 0) { + throw new Error("Divisor cannot be zero"); + } + const values: any[] = [divisor]; + if (min !== undefined) { + values.push(min); + } + return new Operator("divide", values).toString(); + }; + + /** + * Apply modulo operation on a numeric attribute. + * + * @param {number} divisor + * @returns {string} + */ + static modulo = (divisor: number): string => { + if (isNaN(divisor) || !isFinite(divisor)) { + throw new Error("Divisor cannot be NaN or Infinity"); + } + if (divisor === 0) { + throw new Error("Divisor cannot be zero"); + } + return new Operator("modulo", [divisor]).toString(); + }; + + /** + * Raise a numeric attribute to a specified power. + * + * @param {number} exponent + * @param {number} max + * @returns {string} + */ + static power = (exponent: number, max?: number): string => { + if (isNaN(exponent) || !isFinite(exponent)) { + throw new Error("Exponent cannot be NaN or Infinity"); + } + if (max !== undefined && (isNaN(max) || !isFinite(max))) { + throw new Error("Max cannot be NaN or Infinity"); + } + const values: any[] = [exponent]; + if (max !== undefined) { + values.push(max); + } + return new Operator("power", values).toString(); + }; + + /** + * Append values to an array attribute. + * + * @param {any[]} values + * @returns {string} + */ + static arrayAppend = (values: any[]): string => + new Operator("arrayAppend", values).toString(); + + /** + * Prepend values to an array attribute. + * + * @param {any[]} values + * @returns {string} + */ + static arrayPrepend = (values: any[]): string => + new Operator("arrayPrepend", values).toString(); + + /** + * Insert a value at a specific index in an array attribute. + * + * @param {number} index + * @param {any} value + * @returns {string} + */ + static arrayInsert = (index: number, value: any): string => + new Operator("arrayInsert", [index, value]).toString(); + + /** + * Remove a value from an array attribute. + * + * @param {any} value + * @returns {string} + */ + static arrayRemove = (value: any): string => + new Operator("arrayRemove", [value]).toString(); + + /** + * Remove duplicate values from an array attribute. + * + * @returns {string} + */ + static arrayUnique = (): string => + new Operator("arrayUnique", []).toString(); + + /** + * Keep only values that exist in both the current array and the provided array. + * + * @param {any[]} values + * @returns {string} + */ + static arrayIntersect = (values: any[]): string => + new Operator("arrayIntersect", values).toString(); + + /** + * Remove values from the array that exist in the provided array. + * + * @param {any[]} values + * @returns {string} + */ + static arrayDiff = (values: any[]): string => + new Operator("arrayDiff", values).toString(); + + /** + * Filter array values based on a condition. + * + * @param {Condition} condition + * @param {any} value + * @returns {string} + */ + static arrayFilter = (condition: Condition, value?: any): string => { + const values: any[] = [condition as string, value === undefined ? null : value]; + return new Operator("arrayFilter", values).toString(); + }; + + /** + * Concatenate a value to a string or array attribute. + * + * @param {any} value + * @returns {string} + */ + static stringConcat = (value: any): string => + new Operator("stringConcat", [value]).toString(); + + /** + * Replace occurrences of a search string with a replacement string. + * + * @param {string} search + * @param {string} replace + * @returns {string} + */ + static stringReplace = (search: string, replace: string): string => + new Operator("stringReplace", [search, replace]).toString(); + + /** + * Toggle a boolean attribute. + * + * @returns {string} + */ + static toggle = (): string => + new Operator("toggle", []).toString(); + + /** + * Add days to a date attribute. + * + * @param {number} days + * @returns {string} + */ + static dateAddDays = (days: number): string => + new Operator("dateAddDays", [days]).toString(); + + /** + * Subtract days from a date attribute. + * + * @param {number} days + * @returns {string} + */ + static dateSubDays = (days: number): string => + new Operator("dateSubDays", [days]).toString(); + + /** + * Set a date attribute to the current date and time. + * + * @returns {string} + */ + static dateSetNow = (): string => + new Operator("dateSetNow", []).toString(); +} diff --git a/src/query.ts b/src/query.ts index 6e963f2d..89a88ef3 100644 --- a/src/query.ts +++ b/src/query.ts @@ -162,7 +162,7 @@ export class Query { * @returns {string} */ static createdBefore = (value: string): string => - new Query("createdBefore", undefined, value).toString(); + Query.lessThan("$createdAt", value); /** * Filter resources where document was created after date. @@ -171,7 +171,7 @@ export class Query { * @returns {string} */ static createdAfter = (value: string): string => - new Query("createdAfter", undefined, value).toString(); + Query.greaterThan("$createdAt", value); /** * Filter resources where document was created between dates. @@ -181,7 +181,7 @@ export class Query { * @returns {string} */ static createdBetween = (start: string, end: string): string => - new Query("createdBetween", undefined, [start, end] as QueryTypesList).toString(); + Query.between("$createdAt", start, end); /** * Filter resources where document was updated before date. @@ -190,7 +190,7 @@ export class Query { * @returns {string} */ static updatedBefore = (value: string): string => - new Query("updatedBefore", undefined, value).toString(); + Query.lessThan("$updatedAt", value); /** * Filter resources where document was updated after date. @@ -199,7 +199,7 @@ export class Query { * @returns {string} */ static updatedAfter = (value: string): string => - new Query("updatedAfter", undefined, value).toString(); + Query.greaterThan("$updatedAt", value); /** * Filter resources where document was updated between dates. @@ -209,7 +209,7 @@ export class Query { * @returns {string} */ static updatedBetween = (start: string, end: string): string => - new Query("updatedBetween", undefined, [start, end] as QueryTypesList).toString(); + Query.between("$updatedAt", start, end); static or = (queries: string[]) => new Query("or", undefined, queries.map((query) => JSON.parse(query))).toString(); diff --git a/src/services/account.ts b/src/services/account.ts index f3c1f512..e3b86e18 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -183,33 +183,38 @@ export class Account extends Service { * Get the list of identities for the currently logged in user. * * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} */ - listIdentities(params?: { queries?: string[] }): Promise; + listIdentities(params?: { queries?: string[], total?: boolean }): Promise; /** * Get the list of identities for the currently logged in user. * * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - listIdentities(queries?: string[]): Promise; + listIdentities(queries?: string[], total?: boolean): Promise; listIdentities( - paramsOrFirst?: { queries?: string[] } | string[] + paramsOrFirst?: { queries?: string[], total?: boolean } | string[], + ...rest: [(boolean)?] ): Promise { - let params: { queries?: string[] }; + let params: { queries?: string[], total?: boolean }; if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { queries?: string[] }; + params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean }; } else { params = { - queries: paramsOrFirst as string[] + queries: paramsOrFirst as string[], + total: rest[0] as boolean }; } const queries = params.queries; + const total = params.total; const apiPath = '/account/identities'; const payload: Payload = {}; @@ -218,6 +223,10 @@ export class Account extends Service { payload['queries'] = queries; } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('get', uri, { }, payload); @@ -288,33 +297,38 @@ export class Account extends Service { * Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log. * * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} */ - listLogs(params?: { queries?: string[] }): Promise; + listLogs(params?: { queries?: string[], total?: boolean }): Promise; /** * Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log. * * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - listLogs(queries?: string[]): Promise; + listLogs(queries?: string[], total?: boolean): Promise; listLogs( - paramsOrFirst?: { queries?: string[] } | string[] + paramsOrFirst?: { queries?: string[], total?: boolean } | string[], + ...rest: [(boolean)?] ): Promise { - let params: { queries?: string[] }; + let params: { queries?: string[], total?: boolean }; if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { queries?: string[] }; + params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean }; } else { params = { - queries: paramsOrFirst as string[] + queries: paramsOrFirst as string[], + total: rest[0] as boolean }; } const queries = params.queries; + const total = params.total; const apiPath = '/account/logs'; const payload: Payload = {}; @@ -323,6 +337,10 @@ export class Account extends Service { payload['queries'] = queries; } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('get', uri, { }, payload); diff --git a/src/services/databases.ts b/src/services/databases.ts index 9cd625c4..e25662e9 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -314,11 +314,12 @@ export class Databases extends Service { * @param {string} params.collectionId - Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @param {string} params.transactionId - Transaction ID to read uncommitted changes within the transaction. + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} * @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.listRows` instead. */ - listDocuments(params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string }): Promise>; + listDocuments(params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean }): Promise>; /** * Get a list of all the user's documents in a given collection. You can use the query params to filter your results. * @@ -326,25 +327,27 @@ export class Databases extends Service { * @param {string} collectionId - Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @param {string} transactionId - Transaction ID to read uncommitted changes within the transaction. + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise>} * @deprecated Use the object parameter style method for a better developer experience. */ - listDocuments(databaseId: string, collectionId: string, queries?: string[], transactionId?: string): Promise>; + listDocuments(databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean): Promise>; listDocuments( - paramsOrFirst: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string } | string, - ...rest: [(string)?, (string[])?, (string)?] + paramsOrFirst: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean } | string, + ...rest: [(string)?, (string[])?, (string)?, (boolean)?] ): Promise> { - let params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string }; + let params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, queries?: string[], transactionId?: string }; + params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean }; } else { params = { databaseId: paramsOrFirst as string, collectionId: rest[0] as string, queries: rest[1] as string[], - transactionId: rest[2] as string + transactionId: rest[2] as string, + total: rest[3] as boolean }; } @@ -352,6 +355,7 @@ export class Databases extends Service { const collectionId = params.collectionId; const queries = params.queries; const transactionId = params.transactionId; + const total = params.total; if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); @@ -372,6 +376,10 @@ export class Databases extends Service { payload['transactionId'] = transactionId; } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('get', uri, { }, payload); diff --git a/src/services/functions.ts b/src/services/functions.ts index f9f9f2ce..8f2533ff 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -19,37 +19,41 @@ export class Functions extends Service { * * @param {string} params.functionId - Function ID. * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: trigger, status, responseStatusCode, duration, requestMethod, requestPath, deploymentId + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} */ - listExecutions(params: { functionId: string, queries?: string[] }): Promise; + listExecutions(params: { functionId: string, queries?: string[], total?: boolean }): Promise; /** * Get a list of all the current user function execution logs. You can use the query params to filter your results. * * @param {string} functionId - Function ID. * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: trigger, status, responseStatusCode, duration, requestMethod, requestPath, deploymentId + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - listExecutions(functionId: string, queries?: string[]): Promise; + listExecutions(functionId: string, queries?: string[], total?: boolean): Promise; listExecutions( - paramsOrFirst: { functionId: string, queries?: string[] } | string, - ...rest: [(string[])?] + paramsOrFirst: { functionId: string, queries?: string[], total?: boolean } | string, + ...rest: [(string[])?, (boolean)?] ): Promise { - let params: { functionId: string, queries?: string[] }; + let params: { functionId: string, queries?: string[], total?: boolean }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { functionId: string, queries?: string[] }; + params = (paramsOrFirst || {}) as { functionId: string, queries?: string[], total?: boolean }; } else { params = { functionId: paramsOrFirst as string, - queries: rest[0] as string[] + queries: rest[0] as string[], + total: rest[1] as boolean }; } const functionId = params.functionId; const queries = params.queries; + const total = params.total; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); @@ -62,6 +66,10 @@ export class Functions extends Service { payload['queries'] = queries; } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('get', uri, { }, payload); diff --git a/src/services/storage.ts b/src/services/storage.ts index 7b47ea23..e1d4a310 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -21,40 +21,44 @@ export class Storage extends Service { * @param {string} params.bucketId - Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded * @param {string} params.search - Search term to filter your list results. Max length: 256 chars. + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} */ - listFiles(params: { bucketId: string, queries?: string[], search?: string }): Promise; + listFiles(params: { bucketId: string, queries?: string[], search?: string, total?: boolean }): Promise; /** * Get a list of all the user files. You can use the query params to filter your results. * * @param {string} bucketId - Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded * @param {string} search - Search term to filter your list results. Max length: 256 chars. + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - listFiles(bucketId: string, queries?: string[], search?: string): Promise; + listFiles(bucketId: string, queries?: string[], search?: string, total?: boolean): Promise; listFiles( - paramsOrFirst: { bucketId: string, queries?: string[], search?: string } | string, - ...rest: [(string[])?, (string)?] + paramsOrFirst: { bucketId: string, queries?: string[], search?: string, total?: boolean } | string, + ...rest: [(string[])?, (string)?, (boolean)?] ): Promise { - let params: { bucketId: string, queries?: string[], search?: string }; + let params: { bucketId: string, queries?: string[], search?: string, total?: boolean }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { bucketId: string, queries?: string[], search?: string }; + params = (paramsOrFirst || {}) as { bucketId: string, queries?: string[], search?: string, total?: boolean }; } else { params = { bucketId: paramsOrFirst as string, queries: rest[0] as string[], - search: rest[1] as string + search: rest[1] as string, + total: rest[2] as boolean }; } const bucketId = params.bucketId; const queries = params.queries; const search = params.search; + const total = params.total; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); @@ -71,6 +75,10 @@ export class Storage extends Service { payload['search'] = search; } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('get', uri, { }, payload); diff --git a/src/services/tables-db.ts b/src/services/tables-db.ts index be113ec6..60290e1b 100644 --- a/src/services/tables-db.ts +++ b/src/services/tables-db.ts @@ -314,10 +314,11 @@ export class TablesDB extends Service { * @param {string} params.tableId - Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/products/databases/tables#create-table). * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @param {string} params.transactionId - Transaction ID to read uncommitted changes within the transaction. + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} */ - listRows(params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string }): Promise>; + listRows(params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean }): Promise>; /** * Get a list of all the user's rows in a given table. You can use the query params to filter your results. * @@ -325,25 +326,27 @@ export class TablesDB extends Service { * @param {string} tableId - Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/products/databases/tables#create-table). * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @param {string} transactionId - Transaction ID to read uncommitted changes within the transaction. + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise>} * @deprecated Use the object parameter style method for a better developer experience. */ - listRows(databaseId: string, tableId: string, queries?: string[], transactionId?: string): Promise>; + listRows(databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean): Promise>; listRows( - paramsOrFirst: { databaseId: string, tableId: string, queries?: string[], transactionId?: string } | string, - ...rest: [(string)?, (string[])?, (string)?] + paramsOrFirst: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean } | string, + ...rest: [(string)?, (string[])?, (string)?, (boolean)?] ): Promise> { - let params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string }; + let params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, queries?: string[], transactionId?: string }; + params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean }; } else { params = { databaseId: paramsOrFirst as string, tableId: rest[0] as string, queries: rest[1] as string[], - transactionId: rest[2] as string + transactionId: rest[2] as string, + total: rest[3] as boolean }; } @@ -351,6 +354,7 @@ export class TablesDB extends Service { const tableId = params.tableId; const queries = params.queries; const transactionId = params.transactionId; + const total = params.total; if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); @@ -371,6 +375,10 @@ export class TablesDB extends Service { payload['transactionId'] = transactionId; } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('get', uri, { }, payload); diff --git a/src/services/teams.ts b/src/services/teams.ts index b15f29ae..ae8c4ea4 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -18,37 +18,41 @@ export class Teams extends Service { * * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total, billingPlan * @param {string} params.search - Search term to filter your list results. Max length: 256 chars. + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} */ - list(params?: { queries?: string[], search?: string }): Promise>; + list(params?: { queries?: string[], search?: string, total?: boolean }): Promise>; /** * Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results. * * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total, billingPlan * @param {string} search - Search term to filter your list results. Max length: 256 chars. + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise>} * @deprecated Use the object parameter style method for a better developer experience. */ - list(queries?: string[], search?: string): Promise>; + list(queries?: string[], search?: string, total?: boolean): Promise>; list( - paramsOrFirst?: { queries?: string[], search?: string } | string[], - ...rest: [(string)?] + paramsOrFirst?: { queries?: string[], search?: string, total?: boolean } | string[], + ...rest: [(string)?, (boolean)?] ): Promise> { - let params: { queries?: string[], search?: string }; + let params: { queries?: string[], search?: string, total?: boolean }; if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { queries?: string[], search?: string }; + params = (paramsOrFirst || {}) as { queries?: string[], search?: string, total?: boolean }; } else { params = { queries: paramsOrFirst as string[], - search: rest[0] as string + search: rest[0] as string, + total: rest[1] as boolean }; } const queries = params.queries; const search = params.search; + const total = params.total; const apiPath = '/teams'; const payload: Payload = {}; @@ -61,6 +65,10 @@ export class Teams extends Service { payload['search'] = search; } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('get', uri, { }, payload); @@ -289,40 +297,44 @@ export class Teams extends Service { * @param {string} params.teamId - Team ID. * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, teamId, invited, joined, confirm, roles * @param {string} params.search - Search term to filter your list results. Max length: 256 chars. + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} */ - listMemberships(params: { teamId: string, queries?: string[], search?: string }): Promise; + listMemberships(params: { teamId: string, queries?: string[], search?: string, total?: boolean }): Promise; /** * Use this endpoint to list a team's members using the team's ID. All team members have read access to this endpoint. Hide sensitive attributes from the response by toggling membership privacy in the Console. * * @param {string} teamId - Team ID. * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, teamId, invited, joined, confirm, roles * @param {string} search - Search term to filter your list results. Max length: 256 chars. + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - listMemberships(teamId: string, queries?: string[], search?: string): Promise; + listMemberships(teamId: string, queries?: string[], search?: string, total?: boolean): Promise; listMemberships( - paramsOrFirst: { teamId: string, queries?: string[], search?: string } | string, - ...rest: [(string[])?, (string)?] + paramsOrFirst: { teamId: string, queries?: string[], search?: string, total?: boolean } | string, + ...rest: [(string[])?, (string)?, (boolean)?] ): Promise { - let params: { teamId: string, queries?: string[], search?: string }; + let params: { teamId: string, queries?: string[], search?: string, total?: boolean }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { teamId: string, queries?: string[], search?: string }; + params = (paramsOrFirst || {}) as { teamId: string, queries?: string[], search?: string, total?: boolean }; } else { params = { teamId: paramsOrFirst as string, queries: rest[0] as string[], - search: rest[1] as string + search: rest[1] as string, + total: rest[2] as boolean }; } const teamId = params.teamId; const queries = params.queries; const search = params.search; + const total = params.total; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); @@ -339,6 +351,10 @@ export class Teams extends Service { payload['search'] = search; } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call('get', uri, { }, payload);