react-native-appwrite 0.17.1 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/cjs/sdk.js +339 -17
  3. package/dist/cjs/sdk.js.map +1 -1
  4. package/dist/esm/sdk.js +339 -18
  5. package/dist/esm/sdk.js.map +1 -1
  6. package/docs/examples/account/list-identities.md +2 -1
  7. package/docs/examples/account/list-logs.md +2 -1
  8. package/docs/examples/databases/create-document.md +1 -1
  9. package/docs/examples/databases/list-documents.md +2 -1
  10. package/docs/examples/databases/update-document.md +1 -1
  11. package/docs/examples/databases/upsert-document.md +1 -1
  12. package/docs/examples/functions/list-executions.md +2 -1
  13. package/docs/examples/storage/create-file.md +1 -1
  14. package/docs/examples/storage/list-files.md +2 -1
  15. package/docs/examples/storage/update-file.md +1 -1
  16. package/docs/examples/tablesdb/create-row.md +1 -1
  17. package/docs/examples/tablesdb/list-rows.md +2 -1
  18. package/docs/examples/tablesdb/update-row.md +1 -1
  19. package/docs/examples/tablesdb/upsert-row.md +1 -1
  20. package/docs/examples/teams/list-memberships.md +2 -1
  21. package/docs/examples/teams/list.md +2 -1
  22. package/package.json +2 -3
  23. package/src/client.ts +1 -1
  24. package/src/enums/execution-status.ts +1 -0
  25. package/src/index.ts +3 -0
  26. package/src/models.ts +1 -1
  27. package/src/operator.ts +308 -0
  28. package/src/query.ts +6 -6
  29. package/src/services/account.ts +30 -12
  30. package/src/services/databases.ts +15 -7
  31. package/src/services/functions.ts +15 -7
  32. package/src/services/storage.ts +15 -7
  33. package/src/services/tables-db.ts +15 -7
  34. package/src/services/teams.ts +30 -14
  35. package/types/enums/execution-status.d.ts +2 -1
  36. package/types/index.d.ts +3 -0
  37. package/types/models.d.ts +1 -1
  38. package/types/operator.d.ts +180 -0
  39. package/types/services/account.d.ts +8 -2
  40. package/types/services/databases.d.ts +4 -1
  41. package/types/services/functions.d.ts +4 -1
  42. package/types/services/storage.d.ts +4 -1
  43. package/types/services/tables-db.d.ts +4 -1
  44. package/types/services/teams.d.ts +8 -2
@@ -7,7 +7,8 @@ const client = new Client()
7
7
  const account = new Account(client);
8
8
 
9
9
  const result = await account.listIdentities({
10
- queries: [] // optional
10
+ queries: [], // optional
11
+ total: false // optional
11
12
  });
12
13
 
13
14
  console.log(result);
@@ -7,7 +7,8 @@ const client = new Client()
7
7
  const account = new Account(client);
8
8
 
9
9
  const result = await account.listLogs({
10
- queries: [] // optional
10
+ queries: [], // optional
11
+ total: false // optional
11
12
  });
12
13
 
13
14
  console.log(result);
@@ -1,4 +1,4 @@
1
- import { Client, Databases } from "react-native-appwrite";
1
+ import { Client, Databases, Permission, Role } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -10,7 +10,8 @@ const result = await databases.listDocuments({
10
10
  databaseId: '<DATABASE_ID>',
11
11
  collectionId: '<COLLECTION_ID>',
12
12
  queries: [], // optional
13
- transactionId: '<TRANSACTION_ID>' // optional
13
+ transactionId: '<TRANSACTION_ID>', // optional
14
+ total: false // optional
14
15
  });
15
16
 
16
17
  console.log(result);
@@ -1,4 +1,4 @@
1
- import { Client, Databases } from "react-native-appwrite";
1
+ import { Client, Databases, Permission, Role } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -1,4 +1,4 @@
1
- import { Client, Databases } from "react-native-appwrite";
1
+ import { Client, Databases, Permission, Role } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -8,7 +8,8 @@ const functions = new Functions(client);
8
8
 
9
9
  const result = await functions.listExecutions({
10
10
  functionId: '<FUNCTION_ID>',
11
- queries: [] // optional
11
+ queries: [], // optional
12
+ total: false // optional
12
13
  });
13
14
 
14
15
  console.log(result);
@@ -1,4 +1,4 @@
1
- import { Client, Storage } from "react-native-appwrite";
1
+ import { Client, Storage, Permission, Role } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -9,7 +9,8 @@ const storage = new Storage(client);
9
9
  const result = await storage.listFiles({
10
10
  bucketId: '<BUCKET_ID>',
11
11
  queries: [], // optional
12
- search: '<SEARCH>' // optional
12
+ search: '<SEARCH>', // optional
13
+ total: false // optional
13
14
  });
14
15
 
15
16
  console.log(result);
@@ -1,4 +1,4 @@
1
- import { Client, Storage } from "react-native-appwrite";
1
+ import { Client, Storage, Permission, Role } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -1,4 +1,4 @@
1
- import { Client, TablesDB } from "react-native-appwrite";
1
+ import { Client, TablesDB, Permission, Role } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -10,7 +10,8 @@ const result = await tablesDB.listRows({
10
10
  databaseId: '<DATABASE_ID>',
11
11
  tableId: '<TABLE_ID>',
12
12
  queries: [], // optional
13
- transactionId: '<TRANSACTION_ID>' // optional
13
+ transactionId: '<TRANSACTION_ID>', // optional
14
+ total: false // optional
14
15
  });
15
16
 
16
17
  console.log(result);
@@ -1,4 +1,4 @@
1
- import { Client, TablesDB } from "react-native-appwrite";
1
+ import { Client, TablesDB, Permission, Role } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -1,4 +1,4 @@
1
- import { Client, TablesDB } from "react-native-appwrite";
1
+ import { Client, TablesDB, Permission, Role } from "react-native-appwrite";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -9,7 +9,8 @@ const teams = new Teams(client);
9
9
  const result = await teams.listMemberships({
10
10
  teamId: '<TEAM_ID>',
11
11
  queries: [], // optional
12
- search: '<SEARCH>' // optional
12
+ search: '<SEARCH>', // optional
13
+ total: false // optional
13
14
  });
14
15
 
15
16
  console.log(result);
@@ -8,7 +8,8 @@ const teams = new Teams(client);
8
8
 
9
9
  const result = await teams.list({
10
10
  queries: [], // optional
11
- search: '<SEARCH>' // optional
11
+ search: '<SEARCH>', // optional
12
+ total: false // optional
12
13
  });
13
14
 
14
15
  console.log(result);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-native-appwrite",
3
3
  "homepage": "https://appwrite.io/support",
4
4
  "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",
5
- "version": "0.17.1",
5
+ "version": "0.18.0",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "dist/cjs/sdk.js",
8
8
  "exports": {
@@ -37,7 +37,6 @@
37
37
  "react-native": ">=0.76.7 <1.0.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "expo": "*",
41
- "react-native": "*"
40
+ "expo": "*"
42
41
  }
43
42
  }
package/src/client.ts CHANGED
@@ -115,7 +115,7 @@ class Client {
115
115
  'x-sdk-name': 'React Native',
116
116
  'x-sdk-platform': 'client',
117
117
  'x-sdk-language': 'reactnative',
118
- 'x-sdk-version': '0.17.1',
118
+ 'x-sdk-version': '0.18.0',
119
119
  'X-Appwrite-Response-Format': '1.8.0',
120
120
  };
121
121
 
@@ -3,4 +3,5 @@ export enum ExecutionStatus {
3
3
  Processing = 'processing',
4
4
  Completed = 'completed',
5
5
  Failed = 'failed',
6
+ Scheduled = 'scheduled',
6
7
  }
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export { Query } from './query';
15
15
  export { Permission } from './permission';
16
16
  export { Role } from './role';
17
17
  export { ID } from './id';
18
+ export { Operator, Condition } from './operator';
18
19
  export { AuthenticatorType } from './enums/authenticator-type';
19
20
  export { AuthenticationFactor } from './enums/authentication-factor';
20
21
  export { OAuthProvider } from './enums/o-auth-provider';
@@ -24,3 +25,5 @@ export { Flag } from './enums/flag';
24
25
  export { ExecutionMethod } from './enums/execution-method';
25
26
  export { ImageGravity } from './enums/image-gravity';
26
27
  export { ImageFormat } from './enums/image-format';
28
+ export { ExecutionTrigger } from './enums/execution-trigger';
29
+ export { ExecutionStatus } from './enums/execution-status';
package/src/models.ts CHANGED
@@ -1027,7 +1027,7 @@ export namespace Models {
1027
1027
  */
1028
1028
  trigger: ExecutionTrigger;
1029
1029
  /**
1030
- * The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`.
1030
+ * The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, `failed`, or `scheduled`.
1031
1031
  */
1032
1032
  status: ExecutionStatus;
1033
1033
  /**
@@ -0,0 +1,308 @@
1
+ type OperatorValuesSingle = string | number | boolean;
2
+ export type OperatorValuesList = string[] | number[] | boolean[] | any[];
3
+ export type OperatorValues = OperatorValuesSingle | OperatorValuesList;
4
+
5
+ export enum Condition {
6
+ Equal = "equal",
7
+ NotEqual = "notEqual",
8
+ GreaterThan = "greaterThan",
9
+ GreaterThanEqual = "greaterThanEqual",
10
+ LessThan = "lessThan",
11
+ LessThanEqual = "lessThanEqual",
12
+ Contains = "contains",
13
+ IsNull = "isNull",
14
+ IsNotNull = "isNotNull",
15
+ }
16
+
17
+ /**
18
+ * Helper class to generate operator strings for atomic operations.
19
+ */
20
+ export class Operator {
21
+ method: string;
22
+ values: OperatorValuesList | undefined;
23
+
24
+ /**
25
+ * Constructor for Operator class.
26
+ *
27
+ * @param {string} method
28
+ * @param {OperatorValues} values
29
+ */
30
+ constructor(
31
+ method: string,
32
+ values?: OperatorValues
33
+ ) {
34
+ this.method = method;
35
+
36
+ if (values !== undefined) {
37
+ if (Array.isArray(values)) {
38
+ this.values = values;
39
+ } else {
40
+ this.values = [values] as OperatorValuesList;
41
+ }
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Convert the operator object to a JSON string.
47
+ *
48
+ * @returns {string}
49
+ */
50
+ toString(): string {
51
+ return JSON.stringify({
52
+ method: this.method,
53
+ values: this.values,
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Increment a numeric attribute by a specified value.
59
+ *
60
+ * @param {number} value
61
+ * @param {number} max
62
+ * @returns {string}
63
+ */
64
+ static increment = (value: number = 1, max?: number): string => {
65
+ if (isNaN(value) || !isFinite(value)) {
66
+ throw new Error("Value cannot be NaN or Infinity");
67
+ }
68
+ if (max !== undefined && (isNaN(max) || !isFinite(max))) {
69
+ throw new Error("Max cannot be NaN or Infinity");
70
+ }
71
+ const values: any[] = [value];
72
+ if (max !== undefined) {
73
+ values.push(max);
74
+ }
75
+ return new Operator("increment", values).toString();
76
+ };
77
+
78
+ /**
79
+ * Decrement a numeric attribute by a specified value.
80
+ *
81
+ * @param {number} value
82
+ * @param {number} min
83
+ * @returns {string}
84
+ */
85
+ static decrement = (value: number = 1, min?: number): string => {
86
+ if (isNaN(value) || !isFinite(value)) {
87
+ throw new Error("Value cannot be NaN or Infinity");
88
+ }
89
+ if (min !== undefined && (isNaN(min) || !isFinite(min))) {
90
+ throw new Error("Min cannot be NaN or Infinity");
91
+ }
92
+ const values: any[] = [value];
93
+ if (min !== undefined) {
94
+ values.push(min);
95
+ }
96
+ return new Operator("decrement", values).toString();
97
+ };
98
+
99
+ /**
100
+ * Multiply a numeric attribute by a specified factor.
101
+ *
102
+ * @param {number} factor
103
+ * @param {number} max
104
+ * @returns {string}
105
+ */
106
+ static multiply = (factor: number, max?: number): string => {
107
+ if (isNaN(factor) || !isFinite(factor)) {
108
+ throw new Error("Factor cannot be NaN or Infinity");
109
+ }
110
+ if (max !== undefined && (isNaN(max) || !isFinite(max))) {
111
+ throw new Error("Max cannot be NaN or Infinity");
112
+ }
113
+ const values: any[] = [factor];
114
+ if (max !== undefined) {
115
+ values.push(max);
116
+ }
117
+ return new Operator("multiply", values).toString();
118
+ };
119
+
120
+ /**
121
+ * Divide a numeric attribute by a specified divisor.
122
+ *
123
+ * @param {number} divisor
124
+ * @param {number} min
125
+ * @returns {string}
126
+ */
127
+ static divide = (divisor: number, min?: number): string => {
128
+ if (isNaN(divisor) || !isFinite(divisor)) {
129
+ throw new Error("Divisor cannot be NaN or Infinity");
130
+ }
131
+ if (min !== undefined && (isNaN(min) || !isFinite(min))) {
132
+ throw new Error("Min cannot be NaN or Infinity");
133
+ }
134
+ if (divisor === 0) {
135
+ throw new Error("Divisor cannot be zero");
136
+ }
137
+ const values: any[] = [divisor];
138
+ if (min !== undefined) {
139
+ values.push(min);
140
+ }
141
+ return new Operator("divide", values).toString();
142
+ };
143
+
144
+ /**
145
+ * Apply modulo operation on a numeric attribute.
146
+ *
147
+ * @param {number} divisor
148
+ * @returns {string}
149
+ */
150
+ static modulo = (divisor: number): string => {
151
+ if (isNaN(divisor) || !isFinite(divisor)) {
152
+ throw new Error("Divisor cannot be NaN or Infinity");
153
+ }
154
+ if (divisor === 0) {
155
+ throw new Error("Divisor cannot be zero");
156
+ }
157
+ return new Operator("modulo", [divisor]).toString();
158
+ };
159
+
160
+ /**
161
+ * Raise a numeric attribute to a specified power.
162
+ *
163
+ * @param {number} exponent
164
+ * @param {number} max
165
+ * @returns {string}
166
+ */
167
+ static power = (exponent: number, max?: number): string => {
168
+ if (isNaN(exponent) || !isFinite(exponent)) {
169
+ throw new Error("Exponent cannot be NaN or Infinity");
170
+ }
171
+ if (max !== undefined && (isNaN(max) || !isFinite(max))) {
172
+ throw new Error("Max cannot be NaN or Infinity");
173
+ }
174
+ const values: any[] = [exponent];
175
+ if (max !== undefined) {
176
+ values.push(max);
177
+ }
178
+ return new Operator("power", values).toString();
179
+ };
180
+
181
+ /**
182
+ * Append values to an array attribute.
183
+ *
184
+ * @param {any[]} values
185
+ * @returns {string}
186
+ */
187
+ static arrayAppend = (values: any[]): string =>
188
+ new Operator("arrayAppend", values).toString();
189
+
190
+ /**
191
+ * Prepend values to an array attribute.
192
+ *
193
+ * @param {any[]} values
194
+ * @returns {string}
195
+ */
196
+ static arrayPrepend = (values: any[]): string =>
197
+ new Operator("arrayPrepend", values).toString();
198
+
199
+ /**
200
+ * Insert a value at a specific index in an array attribute.
201
+ *
202
+ * @param {number} index
203
+ * @param {any} value
204
+ * @returns {string}
205
+ */
206
+ static arrayInsert = (index: number, value: any): string =>
207
+ new Operator("arrayInsert", [index, value]).toString();
208
+
209
+ /**
210
+ * Remove a value from an array attribute.
211
+ *
212
+ * @param {any} value
213
+ * @returns {string}
214
+ */
215
+ static arrayRemove = (value: any): string =>
216
+ new Operator("arrayRemove", [value]).toString();
217
+
218
+ /**
219
+ * Remove duplicate values from an array attribute.
220
+ *
221
+ * @returns {string}
222
+ */
223
+ static arrayUnique = (): string =>
224
+ new Operator("arrayUnique", []).toString();
225
+
226
+ /**
227
+ * Keep only values that exist in both the current array and the provided array.
228
+ *
229
+ * @param {any[]} values
230
+ * @returns {string}
231
+ */
232
+ static arrayIntersect = (values: any[]): string =>
233
+ new Operator("arrayIntersect", values).toString();
234
+
235
+ /**
236
+ * Remove values from the array that exist in the provided array.
237
+ *
238
+ * @param {any[]} values
239
+ * @returns {string}
240
+ */
241
+ static arrayDiff = (values: any[]): string =>
242
+ new Operator("arrayDiff", values).toString();
243
+
244
+ /**
245
+ * Filter array values based on a condition.
246
+ *
247
+ * @param {Condition} condition
248
+ * @param {any} value
249
+ * @returns {string}
250
+ */
251
+ static arrayFilter = (condition: Condition, value?: any): string => {
252
+ const values: any[] = [condition as string, value === undefined ? null : value];
253
+ return new Operator("arrayFilter", values).toString();
254
+ };
255
+
256
+ /**
257
+ * Concatenate a value to a string or array attribute.
258
+ *
259
+ * @param {any} value
260
+ * @returns {string}
261
+ */
262
+ static stringConcat = (value: any): string =>
263
+ new Operator("stringConcat", [value]).toString();
264
+
265
+ /**
266
+ * Replace occurrences of a search string with a replacement string.
267
+ *
268
+ * @param {string} search
269
+ * @param {string} replace
270
+ * @returns {string}
271
+ */
272
+ static stringReplace = (search: string, replace: string): string =>
273
+ new Operator("stringReplace", [search, replace]).toString();
274
+
275
+ /**
276
+ * Toggle a boolean attribute.
277
+ *
278
+ * @returns {string}
279
+ */
280
+ static toggle = (): string =>
281
+ new Operator("toggle", []).toString();
282
+
283
+ /**
284
+ * Add days to a date attribute.
285
+ *
286
+ * @param {number} days
287
+ * @returns {string}
288
+ */
289
+ static dateAddDays = (days: number): string =>
290
+ new Operator("dateAddDays", [days]).toString();
291
+
292
+ /**
293
+ * Subtract days from a date attribute.
294
+ *
295
+ * @param {number} days
296
+ * @returns {string}
297
+ */
298
+ static dateSubDays = (days: number): string =>
299
+ new Operator("dateSubDays", [days]).toString();
300
+
301
+ /**
302
+ * Set a date attribute to the current date and time.
303
+ *
304
+ * @returns {string}
305
+ */
306
+ static dateSetNow = (): string =>
307
+ new Operator("dateSetNow", []).toString();
308
+ }
package/src/query.ts CHANGED
@@ -162,7 +162,7 @@ export class Query {
162
162
  * @returns {string}
163
163
  */
164
164
  static createdBefore = (value: string): string =>
165
- new Query("createdBefore", undefined, value).toString();
165
+ Query.lessThan("$createdAt", value);
166
166
 
167
167
  /**
168
168
  * Filter resources where document was created after date.
@@ -171,7 +171,7 @@ export class Query {
171
171
  * @returns {string}
172
172
  */
173
173
  static createdAfter = (value: string): string =>
174
- new Query("createdAfter", undefined, value).toString();
174
+ Query.greaterThan("$createdAt", value);
175
175
 
176
176
  /**
177
177
  * Filter resources where document was created between dates.
@@ -181,7 +181,7 @@ export class Query {
181
181
  * @returns {string}
182
182
  */
183
183
  static createdBetween = (start: string, end: string): string =>
184
- new Query("createdBetween", undefined, [start, end] as QueryTypesList).toString();
184
+ Query.between("$createdAt", start, end);
185
185
 
186
186
  /**
187
187
  * Filter resources where document was updated before date.
@@ -190,7 +190,7 @@ export class Query {
190
190
  * @returns {string}
191
191
  */
192
192
  static updatedBefore = (value: string): string =>
193
- new Query("updatedBefore", undefined, value).toString();
193
+ Query.lessThan("$updatedAt", value);
194
194
 
195
195
  /**
196
196
  * Filter resources where document was updated after date.
@@ -199,7 +199,7 @@ export class Query {
199
199
  * @returns {string}
200
200
  */
201
201
  static updatedAfter = (value: string): string =>
202
- new Query("updatedAfter", undefined, value).toString();
202
+ Query.greaterThan("$updatedAt", value);
203
203
 
204
204
  /**
205
205
  * Filter resources where document was updated between dates.
@@ -209,7 +209,7 @@ export class Query {
209
209
  * @returns {string}
210
210
  */
211
211
  static updatedBetween = (start: string, end: string): string =>
212
- new Query("updatedBetween", undefined, [start, end] as QueryTypesList).toString();
212
+ Query.between("$updatedAt", start, end);
213
213
 
214
214
  static or = (queries: string[]) =>
215
215
  new Query("or", undefined, queries.map((query) => JSON.parse(query))).toString();