react-native-appwrite 0.17.1 → 0.19.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 (54) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/sdk.js +1009 -21
  3. package/dist/cjs/sdk.js.map +1 -1
  4. package/dist/esm/sdk.js +1009 -22
  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/avatars/get-screenshot.md +35 -0
  9. package/docs/examples/databases/create-document.md +1 -1
  10. package/docs/examples/databases/list-documents.md +2 -1
  11. package/docs/examples/databases/update-document.md +1 -1
  12. package/docs/examples/databases/upsert-document.md +1 -1
  13. package/docs/examples/functions/list-executions.md +2 -1
  14. package/docs/examples/storage/create-file.md +1 -1
  15. package/docs/examples/storage/list-files.md +2 -1
  16. package/docs/examples/storage/update-file.md +1 -1
  17. package/docs/examples/tablesdb/create-row.md +1 -1
  18. package/docs/examples/tablesdb/list-rows.md +2 -1
  19. package/docs/examples/tablesdb/update-row.md +1 -1
  20. package/docs/examples/tablesdb/upsert-row.md +1 -1
  21. package/docs/examples/teams/list-memberships.md +2 -1
  22. package/docs/examples/teams/list.md +2 -1
  23. package/package.json +3 -4
  24. package/src/client.ts +1 -1
  25. package/src/enums/execution-status.ts +1 -0
  26. package/src/enums/output.ts +9 -0
  27. package/src/enums/theme.ts +4 -0
  28. package/src/enums/timezone.ts +421 -0
  29. package/src/index.ts +6 -0
  30. package/src/models.ts +1 -1
  31. package/src/operator.ts +308 -0
  32. package/src/query.ts +6 -6
  33. package/src/services/account.ts +34 -16
  34. package/src/services/avatars.ts +347 -0
  35. package/src/services/databases.ts +15 -7
  36. package/src/services/functions.ts +15 -7
  37. package/src/services/storage.ts +15 -7
  38. package/src/services/tables-db.ts +15 -7
  39. package/src/services/teams.ts +30 -14
  40. package/types/enums/execution-status.d.ts +2 -1
  41. package/types/enums/output.d.ts +9 -0
  42. package/types/enums/theme.d.ts +4 -0
  43. package/types/enums/timezone.d.ts +421 -0
  44. package/types/index.d.ts +6 -0
  45. package/types/models.d.ts +1 -1
  46. package/types/operator.d.ts +180 -0
  47. package/types/services/account.d.ts +8 -2
  48. package/types/services/avatars.d.ts +123 -0
  49. package/types/services/databases.d.ts +4 -1
  50. package/types/services/functions.d.ts +4 -1
  51. package/types/services/storage.d.ts +4 -1
  52. package/types/services/tables-db.d.ts +4 -1
  53. package/types/services/teams.d.ts +8 -2
  54. package/.gitpod.yml +0 -10
@@ -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();
@@ -183,33 +183,38 @@ export class Account extends Service {
183
183
  * Get the list of identities for the currently logged in user.
184
184
  *
185
185
  * @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
186
+ * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
186
187
  * @throws {AppwriteException}
187
188
  * @returns {Promise}
188
189
  */
189
- listIdentities(params?: { queries?: string[] }): Promise<Models.IdentityList>;
190
+ listIdentities(params?: { queries?: string[], total?: boolean }): Promise<Models.IdentityList>;
190
191
  /**
191
192
  * Get the list of identities for the currently logged in user.
192
193
  *
193
194
  * @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
195
+ * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
194
196
  * @throws {AppwriteException}
195
197
  * @returns {Promise<Models.IdentityList>}
196
198
  * @deprecated Use the object parameter style method for a better developer experience.
197
199
  */
198
- listIdentities(queries?: string[]): Promise<Models.IdentityList>;
200
+ listIdentities(queries?: string[], total?: boolean): Promise<Models.IdentityList>;
199
201
  listIdentities(
200
- paramsOrFirst?: { queries?: string[] } | string[]
202
+ paramsOrFirst?: { queries?: string[], total?: boolean } | string[],
203
+ ...rest: [(boolean)?]
201
204
  ): Promise<Models.IdentityList> {
202
- let params: { queries?: string[] };
205
+ let params: { queries?: string[], total?: boolean };
203
206
 
204
207
  if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
205
- params = (paramsOrFirst || {}) as { queries?: string[] };
208
+ params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean };
206
209
  } else {
207
210
  params = {
208
- queries: paramsOrFirst as string[]
211
+ queries: paramsOrFirst as string[],
212
+ total: rest[0] as boolean
209
213
  };
210
214
  }
211
215
 
212
216
  const queries = params.queries;
217
+ const total = params.total;
213
218
 
214
219
  const apiPath = '/account/identities';
215
220
  const payload: Payload = {};
@@ -218,6 +223,10 @@ export class Account extends Service {
218
223
  payload['queries'] = queries;
219
224
  }
220
225
 
226
+ if (typeof total !== 'undefined') {
227
+ payload['total'] = total;
228
+ }
229
+
221
230
  const uri = new URL(this.client.config.endpoint + apiPath);
222
231
  return this.client.call('get', uri, {
223
232
  }, payload);
@@ -288,33 +297,38 @@ export class Account extends Service {
288
297
  * 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.
289
298
  *
290
299
  * @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
300
+ * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
291
301
  * @throws {AppwriteException}
292
302
  * @returns {Promise}
293
303
  */
294
- listLogs(params?: { queries?: string[] }): Promise<Models.LogList>;
304
+ listLogs(params?: { queries?: string[], total?: boolean }): Promise<Models.LogList>;
295
305
  /**
296
306
  * 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.
297
307
  *
298
308
  * @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
309
+ * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
299
310
  * @throws {AppwriteException}
300
311
  * @returns {Promise<Models.LogList>}
301
312
  * @deprecated Use the object parameter style method for a better developer experience.
302
313
  */
303
- listLogs(queries?: string[]): Promise<Models.LogList>;
314
+ listLogs(queries?: string[], total?: boolean): Promise<Models.LogList>;
304
315
  listLogs(
305
- paramsOrFirst?: { queries?: string[] } | string[]
316
+ paramsOrFirst?: { queries?: string[], total?: boolean } | string[],
317
+ ...rest: [(boolean)?]
306
318
  ): Promise<Models.LogList> {
307
- let params: { queries?: string[] };
319
+ let params: { queries?: string[], total?: boolean };
308
320
 
309
321
  if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
310
- params = (paramsOrFirst || {}) as { queries?: string[] };
322
+ params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean };
311
323
  } else {
312
324
  params = {
313
- queries: paramsOrFirst as string[]
325
+ queries: paramsOrFirst as string[],
326
+ total: rest[0] as boolean
314
327
  };
315
328
  }
316
329
 
317
330
  const queries = params.queries;
331
+ const total = params.total;
318
332
 
319
333
  const apiPath = '/account/logs';
320
334
  const payload: Payload = {};
@@ -323,6 +337,10 @@ export class Account extends Service {
323
337
  payload['queries'] = queries;
324
338
  }
325
339
 
340
+ if (typeof total !== 'undefined') {
341
+ payload['total'] = total;
342
+ }
343
+
326
344
  const uri = new URL(this.client.config.endpoint + apiPath);
327
345
  return this.client.call('get', uri, {
328
346
  }, payload);
@@ -713,7 +731,7 @@ export class Account extends Service {
713
731
  throw new AppwriteException('Missing required parameter: "factor"');
714
732
  }
715
733
 
716
- const apiPath = '/account/mfa/challenge';
734
+ const apiPath = '/account/mfa/challenges';
717
735
  const payload: Payload = {};
718
736
 
719
737
  if (typeof factor !== 'undefined') {
@@ -762,7 +780,7 @@ export class Account extends Service {
762
780
  throw new AppwriteException('Missing required parameter: "factor"');
763
781
  }
764
782
 
765
- const apiPath = '/account/mfa/challenge';
783
+ const apiPath = '/account/mfa/challenges';
766
784
  const payload: Payload = {};
767
785
 
768
786
  if (typeof factor !== 'undefined') {
@@ -821,7 +839,7 @@ export class Account extends Service {
821
839
  throw new AppwriteException('Missing required parameter: "otp"');
822
840
  }
823
841
 
824
- const apiPath = '/account/mfa/challenge';
842
+ const apiPath = '/account/mfa/challenges';
825
843
  const payload: Payload = {};
826
844
 
827
845
  if (typeof challengeId !== 'undefined') {
@@ -883,7 +901,7 @@ export class Account extends Service {
883
901
  throw new AppwriteException('Missing required parameter: "otp"');
884
902
  }
885
903
 
886
- const apiPath = '/account/mfa/challenge';
904
+ const apiPath = '/account/mfa/challenges';
887
905
  const payload: Payload = {};
888
906
 
889
907
  if (typeof challengeId !== 'undefined') {