appwrite-cli 0.18.3 → 1.0.0-RC2

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 (65) hide show
  1. package/.github/workflows/npm-publish.yml +8 -1
  2. package/LICENSE.md +1 -1
  3. package/README.md +4 -4
  4. package/docs/examples/account/create-phone-session.md +1 -1
  5. package/docs/examples/account/get-logs.md +0 -1
  6. package/docs/examples/account/update-phone.md +1 -1
  7. package/docs/examples/avatars/get-initials.md +0 -1
  8. package/docs/examples/databases/create-collection.md +2 -3
  9. package/docs/examples/databases/create-datetime-attribute.md +7 -0
  10. package/docs/examples/databases/create-document.md +0 -1
  11. package/docs/examples/databases/list-collection-logs.md +0 -1
  12. package/docs/examples/databases/list-collections.md +0 -4
  13. package/docs/examples/databases/list-document-logs.md +0 -1
  14. package/docs/examples/databases/list-documents.md +0 -6
  15. package/docs/examples/databases/list-logs.md +0 -1
  16. package/docs/examples/databases/list.md +0 -4
  17. package/docs/examples/databases/update-collection.md +0 -1
  18. package/docs/examples/databases/update-document.md +0 -1
  19. package/docs/examples/functions/create-variable.md +4 -0
  20. package/docs/examples/functions/create.md +1 -2
  21. package/docs/examples/functions/delete-variable.md +3 -0
  22. package/docs/examples/functions/get-function-usage.md +3 -0
  23. package/docs/examples/functions/get-usage.md +0 -1
  24. package/docs/examples/functions/get-variable.md +3 -0
  25. package/docs/examples/functions/list-deployments.md +0 -4
  26. package/docs/examples/functions/list-executions.md +0 -3
  27. package/docs/examples/functions/list-variables.md +4 -0
  28. package/docs/examples/functions/list.md +0 -4
  29. package/docs/examples/functions/update-variable.md +5 -0
  30. package/docs/examples/functions/update.md +1 -2
  31. package/docs/examples/projects/list.md +0 -4
  32. package/docs/examples/storage/create-bucket.md +1 -1
  33. package/docs/examples/storage/create-file.md +0 -1
  34. package/docs/examples/storage/list-buckets.md +0 -4
  35. package/docs/examples/storage/list-files.md +0 -4
  36. package/docs/examples/storage/update-bucket.md +1 -1
  37. package/docs/examples/storage/update-file.md +0 -1
  38. package/docs/examples/teams/get-memberships.md +0 -4
  39. package/docs/examples/teams/list-logs.md +0 -1
  40. package/docs/examples/teams/list.md +0 -4
  41. package/docs/examples/users/create-argon2user.md +5 -0
  42. package/docs/examples/users/create-bcrypt-user.md +5 -0
  43. package/docs/examples/users/create-m-d5user.md +5 -0
  44. package/docs/examples/users/create-p-h-pass-user.md +5 -0
  45. package/docs/examples/users/create-s-h-a-user.md +6 -0
  46. package/docs/examples/users/create-scrypt-modified-user.md +8 -0
  47. package/docs/examples/users/create-scrypt-user.md +10 -0
  48. package/docs/examples/users/create.md +3 -2
  49. package/docs/examples/users/get-logs.md +0 -1
  50. package/docs/examples/users/list.md +0 -4
  51. package/install.ps1 +2 -2
  52. package/install.sh +1 -1
  53. package/lib/client.js +6 -3
  54. package/lib/commands/account.js +18 -23
  55. package/lib/commands/avatars.js +2 -7
  56. package/lib/commands/databases.js +154 -210
  57. package/lib/commands/functions.js +226 -92
  58. package/lib/commands/generic.js +3 -3
  59. package/lib/commands/init.js +57 -15
  60. package/lib/commands/projects.js +10 -30
  61. package/lib/commands/storage.js +53 -105
  62. package/lib/commands/teams.js +17 -62
  63. package/lib/commands/users.js +414 -36
  64. package/lib/questions.js +1 -1
  65. package/package.json +1 -1
@@ -12,37 +12,21 @@ const { localConfig, globalConfig } = require("../config");
12
12
 
13
13
  const functions = new Command("functions").description(commandDescriptions['functions'])
14
14
 
15
- const functionsList = async ({ search, limit, offset, cursor, cursorDirection, orderType, parseOutput = true, sdk = undefined}) => {
15
+ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefined}) => {
16
+ /* @param {string[]} queries */
16
17
  /* @param {string} search */
17
- /* @param {number} limit */
18
- /* @param {number} offset */
19
- /* @param {string} cursor */
20
- /* @param {string} cursorDirection */
21
- /* @param {string} orderType */
22
18
 
23
19
  let client = !sdk ? await sdkForProject() : sdk;
24
20
  let path = '/functions';
25
21
  let payload = {};
26
22
 
27
23
  /** Query Params */
24
+ if (typeof queries !== 'undefined') {
25
+ payload['queries'] = queries;
26
+ }
28
27
  if (typeof search !== 'undefined') {
29
28
  payload['search'] = search;
30
29
  }
31
- if (typeof limit !== 'undefined') {
32
- payload['limit'] = limit;
33
- }
34
- if (typeof offset !== 'undefined') {
35
- payload['offset'] = offset;
36
- }
37
- if (typeof cursor !== 'undefined') {
38
- payload['cursor'] = cursor;
39
- }
40
- if (typeof cursorDirection !== 'undefined') {
41
- payload['cursorDirection'] = cursorDirection;
42
- }
43
- if (typeof orderType !== 'undefined') {
44
- payload['orderType'] = orderType;
45
- }
46
30
  let response = undefined;
47
31
  response = await client.call('get', path, {
48
32
  'content-type': 'application/json',
@@ -55,12 +39,11 @@ const functionsList = async ({ search, limit, offset, cursor, cursorDirection, o
55
39
  return response;
56
40
  }
57
41
 
58
- const functionsCreate = async ({ functionId, name, execute, runtime, vars, events, schedule, timeout, parseOutput = true, sdk = undefined}) => {
42
+ const functionsCreate = async ({ functionId, name, execute, runtime, events, schedule, timeout, parseOutput = true, sdk = undefined}) => {
59
43
  /* @param {string} functionId */
60
44
  /* @param {string} name */
61
45
  /* @param {string[]} execute */
62
46
  /* @param {string} runtime */
63
- /* @param {object} vars */
64
47
  /* @param {string[]} events */
65
48
  /* @param {string} schedule */
66
49
  /* @param {number} timeout */
@@ -86,10 +69,6 @@ const functionsCreate = async ({ functionId, name, execute, runtime, vars, event
86
69
  payload['runtime'] = runtime;
87
70
  }
88
71
 
89
- if (typeof vars !== 'undefined') {
90
- payload['vars'] = JSON.parse(vars);
91
- }
92
-
93
72
  if (typeof events !== 'undefined') {
94
73
  payload['events'] = events;
95
74
  }
@@ -131,6 +110,29 @@ const functionsListRuntimes = async ({ parseOutput = true, sdk = undefined}) =>
131
110
  return response;
132
111
  }
133
112
 
113
+ const functionsGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => {
114
+ /* @param {string} range */
115
+
116
+ let client = !sdk ? await sdkForProject() : sdk;
117
+ let path = '/functions/usage';
118
+ let payload = {};
119
+
120
+ /** Query Params */
121
+ if (typeof range !== 'undefined') {
122
+ payload['range'] = range;
123
+ }
124
+ let response = undefined;
125
+ response = await client.call('get', path, {
126
+ 'content-type': 'application/json',
127
+ }, payload);
128
+
129
+ if (parseOutput) {
130
+ parse(response)
131
+ success()
132
+ }
133
+ return response;
134
+ }
135
+
134
136
  const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined}) => {
135
137
  /* @param {string} functionId */
136
138
 
@@ -149,11 +151,10 @@ const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined})
149
151
  return response;
150
152
  }
151
153
 
152
- const functionsUpdate = async ({ functionId, name, execute, vars, events, schedule, timeout, parseOutput = true, sdk = undefined}) => {
154
+ const functionsUpdate = async ({ functionId, name, execute, events, schedule, timeout, parseOutput = true, sdk = undefined}) => {
153
155
  /* @param {string} functionId */
154
156
  /* @param {string} name */
155
157
  /* @param {string[]} execute */
156
- /* @param {object} vars */
157
158
  /* @param {string[]} events */
158
159
  /* @param {string} schedule */
159
160
  /* @param {number} timeout */
@@ -171,10 +172,6 @@ const functionsUpdate = async ({ functionId, name, execute, vars, events, schedu
171
172
  payload['execute'] = execute;
172
173
  }
173
174
 
174
- if (typeof vars !== 'undefined') {
175
- payload['vars'] = JSON.parse(vars);
176
- }
177
-
178
175
  if (typeof events !== 'undefined') {
179
176
  payload['events'] = events;
180
177
  }
@@ -217,38 +214,22 @@ const functionsDelete = async ({ functionId, parseOutput = true, sdk = undefined
217
214
  return response;
218
215
  }
219
216
 
220
- const functionsListDeployments = async ({ functionId, search, limit, offset, cursor, cursorDirection, orderType, parseOutput = true, sdk = undefined}) => {
217
+ const functionsListDeployments = async ({ functionId, queries, search, parseOutput = true, sdk = undefined}) => {
221
218
  /* @param {string} functionId */
219
+ /* @param {string[]} queries */
222
220
  /* @param {string} search */
223
- /* @param {number} limit */
224
- /* @param {number} offset */
225
- /* @param {string} cursor */
226
- /* @param {string} cursorDirection */
227
- /* @param {string} orderType */
228
221
 
229
222
  let client = !sdk ? await sdkForProject() : sdk;
230
223
  let path = '/functions/{functionId}/deployments'.replace('{functionId}', functionId);
231
224
  let payload = {};
232
225
 
233
226
  /** Query Params */
227
+ if (typeof queries !== 'undefined') {
228
+ payload['queries'] = queries;
229
+ }
234
230
  if (typeof search !== 'undefined') {
235
231
  payload['search'] = search;
236
232
  }
237
- if (typeof limit !== 'undefined') {
238
- payload['limit'] = limit;
239
- }
240
- if (typeof offset !== 'undefined') {
241
- payload['offset'] = offset;
242
- }
243
- if (typeof cursor !== 'undefined') {
244
- payload['cursor'] = cursor;
245
- }
246
- if (typeof cursorDirection !== 'undefined') {
247
- payload['cursorDirection'] = cursorDirection;
248
- }
249
- if (typeof orderType !== 'undefined') {
250
- payload['orderType'] = orderType;
251
- }
252
233
  let response = undefined;
253
234
  response = await client.call('get', path, {
254
235
  'content-type': 'application/json',
@@ -455,34 +436,22 @@ const functionsRetryBuild = async ({ functionId, deploymentId, buildId, parseOut
455
436
  return response;
456
437
  }
457
438
 
458
- const functionsListExecutions = async ({ functionId, limit, offset, search, cursor, cursorDirection, parseOutput = true, sdk = undefined}) => {
439
+ const functionsListExecutions = async ({ functionId, queries, search, parseOutput = true, sdk = undefined}) => {
459
440
  /* @param {string} functionId */
460
- /* @param {number} limit */
461
- /* @param {number} offset */
441
+ /* @param {string[]} queries */
462
442
  /* @param {string} search */
463
- /* @param {string} cursor */
464
- /* @param {string} cursorDirection */
465
443
 
466
444
  let client = !sdk ? await sdkForProject() : sdk;
467
445
  let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
468
446
  let payload = {};
469
447
 
470
448
  /** Query Params */
471
- if (typeof limit !== 'undefined') {
472
- payload['limit'] = limit;
473
- }
474
- if (typeof offset !== 'undefined') {
475
- payload['offset'] = offset;
449
+ if (typeof queries !== 'undefined') {
450
+ payload['queries'] = queries;
476
451
  }
477
452
  if (typeof search !== 'undefined') {
478
453
  payload['search'] = search;
479
454
  }
480
- if (typeof cursor !== 'undefined') {
481
- payload['cursor'] = cursor;
482
- }
483
- if (typeof cursorDirection !== 'undefined') {
484
- payload['cursorDirection'] = cursorDirection;
485
- }
486
455
  let response = undefined;
487
456
  response = await client.call('get', path, {
488
457
  'content-type': 'application/json',
@@ -544,7 +513,7 @@ const functionsGetExecution = async ({ functionId, executionId, parseOutput = tr
544
513
  return response;
545
514
  }
546
515
 
547
- const functionsGetUsage = async ({ functionId, range, parseOutput = true, sdk = undefined}) => {
516
+ const functionsGetFunctionUsage = async ({ functionId, range, parseOutput = true, sdk = undefined}) => {
548
517
  /* @param {string} functionId */
549
518
  /* @param {string} range */
550
519
 
@@ -568,16 +537,139 @@ const functionsGetUsage = async ({ functionId, range, parseOutput = true, sdk =
568
537
  return response;
569
538
  }
570
539
 
540
+ const functionsListVariables = async ({ functionId, queries, search, parseOutput = true, sdk = undefined}) => {
541
+ /* @param {string} functionId */
542
+ /* @param {string[]} queries */
543
+ /* @param {string} search */
544
+
545
+ let client = !sdk ? await sdkForProject() : sdk;
546
+ let path = '/functions/{functionId}/variables'.replace('{functionId}', functionId);
547
+ let payload = {};
548
+
549
+ /** Query Params */
550
+ if (typeof queries !== 'undefined') {
551
+ payload['queries'] = queries;
552
+ }
553
+ if (typeof search !== 'undefined') {
554
+ payload['search'] = search;
555
+ }
556
+ let response = undefined;
557
+ response = await client.call('get', path, {
558
+ 'content-type': 'application/json',
559
+ }, payload);
560
+
561
+ if (parseOutput) {
562
+ parse(response)
563
+ success()
564
+ }
565
+ return response;
566
+ }
567
+
568
+ const functionsCreateVariable = async ({ functionId, key, value, parseOutput = true, sdk = undefined}) => {
569
+ /* @param {string} functionId */
570
+ /* @param {string} key */
571
+ /* @param {string} value */
572
+
573
+ let client = !sdk ? await sdkForProject() : sdk;
574
+ let path = '/functions/{functionId}/variables'.replace('{functionId}', functionId);
575
+ let payload = {};
576
+
577
+ /** Body Params */
578
+ if (typeof key !== 'undefined') {
579
+ payload['key'] = key;
580
+ }
581
+
582
+ if (typeof value !== 'undefined') {
583
+ payload['value'] = value;
584
+ }
585
+
586
+ let response = undefined;
587
+ response = await client.call('post', path, {
588
+ 'content-type': 'application/json',
589
+ }, payload);
590
+
591
+ if (parseOutput) {
592
+ parse(response)
593
+ success()
594
+ }
595
+ return response;
596
+ }
597
+
598
+ const functionsGetVariable = async ({ functionId, variableId, parseOutput = true, sdk = undefined}) => {
599
+ /* @param {string} functionId */
600
+ /* @param {string} variableId */
601
+
602
+ let client = !sdk ? await sdkForProject() : sdk;
603
+ let path = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId);
604
+ let payload = {};
605
+ let response = undefined;
606
+ response = await client.call('get', path, {
607
+ 'content-type': 'application/json',
608
+ }, payload);
609
+
610
+ if (parseOutput) {
611
+ parse(response)
612
+ success()
613
+ }
614
+ return response;
615
+ }
616
+
617
+ const functionsUpdateVariable = async ({ functionId, variableId, key, value, parseOutput = true, sdk = undefined}) => {
618
+ /* @param {string} functionId */
619
+ /* @param {string} variableId */
620
+ /* @param {string} key */
621
+ /* @param {string} value */
622
+
623
+ let client = !sdk ? await sdkForProject() : sdk;
624
+ let path = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId);
625
+ let payload = {};
626
+
627
+ /** Body Params */
628
+ if (typeof key !== 'undefined') {
629
+ payload['key'] = key;
630
+ }
631
+
632
+ if (typeof value !== 'undefined') {
633
+ payload['value'] = value;
634
+ }
635
+
636
+ let response = undefined;
637
+ response = await client.call('put', path, {
638
+ 'content-type': 'application/json',
639
+ }, payload);
640
+
641
+ if (parseOutput) {
642
+ parse(response)
643
+ success()
644
+ }
645
+ return response;
646
+ }
647
+
648
+ const functionsDeleteVariable = async ({ functionId, variableId, parseOutput = true, sdk = undefined}) => {
649
+ /* @param {string} functionId */
650
+ /* @param {string} variableId */
651
+
652
+ let client = !sdk ? await sdkForProject() : sdk;
653
+ let path = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId);
654
+ let payload = {};
655
+ let response = undefined;
656
+ response = await client.call('delete', path, {
657
+ 'content-type': 'application/json',
658
+ }, payload);
659
+
660
+ if (parseOutput) {
661
+ parse(response)
662
+ success()
663
+ }
664
+ return response;
665
+ }
666
+
571
667
 
572
668
  functions
573
669
  .command(`list`)
574
670
  .description(`Get a list of all the project's functions. You can use the query params to filter your results.`)
671
+ .option(`--queries <queries...>`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, status, runtime, deployment, schedule, scheduleNext, schedulePrevious, timeout`)
575
672
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
576
- .option(`--limit <limit>`, `Maximum number of functions to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.`, parseInteger)
577
- .option(`--offset <offset>`, `Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination)`, parseInteger)
578
- .option(`--cursor <cursor>`, `ID of the function used as the starting point for the query, excluding the function itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination)`)
579
- .option(`--cursorDirection <cursorDirection>`, `Direction of the cursor, can be either 'before' or 'after'.`)
580
- .option(`--orderType <orderType>`, `Order result by ASC or DESC order.`)
581
673
  .action(actionRunner(functionsList))
582
674
 
583
675
  functions
@@ -585,9 +677,8 @@ functions
585
677
  .description(`Create a new function. You can pass a list of [permissions](/docs/permissions) to allow different project users or team with access to execute the function using the client API.`)
586
678
  .requiredOption(`--functionId <functionId>`, `Function ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`)
587
679
  .requiredOption(`--name <name>`, `Function name. Max length: 128 chars.`)
588
- .requiredOption(`--execute <execute...>`, `An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of 100 scopes are allowed, each 64 characters long.`)
680
+ .requiredOption(`--execute <execute...>`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
589
681
  .requiredOption(`--runtime <runtime>`, `Execution runtime.`)
590
- .option(`--vars <vars>`, `Key-value JSON object that will be passed to the function as environment variables.`)
591
682
  .option(`--events <events...>`, `Events list. Maximum of 100 events are allowed.`)
592
683
  .option(`--schedule <schedule>`, `Schedule CRON syntax.`)
593
684
  .option(`--timeout <timeout>`, `Function maximum execution time in seconds.`, parseInteger)
@@ -598,6 +689,12 @@ functions
598
689
  .description(`Get a list of all runtimes that are currently active on your instance.`)
599
690
  .action(actionRunner(functionsListRuntimes))
600
691
 
692
+ functions
693
+ .command(`getUsage`)
694
+ .description(``)
695
+ .option(`--range <range>`, `Date range.`)
696
+ .action(actionRunner(functionsGetUsage))
697
+
601
698
  functions
602
699
  .command(`get`)
603
700
  .description(`Get a function by its unique ID.`)
@@ -609,8 +706,7 @@ functions
609
706
  .description(`Update function by its unique ID.`)
610
707
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
611
708
  .requiredOption(`--name <name>`, `Function name. Max length: 128 chars.`)
612
- .requiredOption(`--execute <execute...>`, `An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of 100 scopes are allowed, each 64 characters long.`)
613
- .option(`--vars <vars>`, `Key-value JSON object that will be passed to the function as environment variables.`)
709
+ .requiredOption(`--execute <execute...>`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
614
710
  .option(`--events <events...>`, `Events list. Maximum of 100 events are allowed.`)
615
711
  .option(`--schedule <schedule>`, `Schedule CRON syntax.`)
616
712
  .option(`--timeout <timeout>`, `Maximum execution time in seconds.`, parseInteger)
@@ -626,12 +722,8 @@ functions
626
722
  .command(`listDeployments`)
627
723
  .description(`Get a list of all the project's code deployments. You can use the query params to filter your results.`)
628
724
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
725
+ .option(`--queries <queries...>`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: entrypoint, size, buildId, activate`)
629
726
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
630
- .option(`--limit <limit>`, `Maximum number of deployments to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.`, parseInteger)
631
- .option(`--offset <offset>`, `Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination)`, parseInteger)
632
- .option(`--cursor <cursor>`, `ID of the deployment used as the starting point for the query, excluding the deployment itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination)`)
633
- .option(`--cursorDirection <cursorDirection>`, `Direction of the cursor, can be either 'before' or 'after'.`)
634
- .option(`--orderType <orderType>`, `Order result by ASC or DESC order.`)
635
727
  .action(actionRunner(functionsListDeployments))
636
728
 
637
729
  functions
@@ -676,11 +768,8 @@ functions
676
768
  .command(`listExecutions`)
677
769
  .description(`Get a list of all the current user function execution logs. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project's executions. [Learn more about different API modes](/docs/admin).`)
678
770
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
679
- .option(`--limit <limit>`, `Maximum number of executions to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.`, parseInteger)
680
- .option(`--offset <offset>`, `Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](https://appwrite.io/docs/pagination)`, parseInteger)
771
+ .option(`--queries <queries...>`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: trigger, status, statusCode, time`)
681
772
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
682
- .option(`--cursor <cursor>`, `ID of the execution used as the starting point for the query, excluding the execution itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](https://appwrite.io/docs/pagination)`)
683
- .option(`--cursorDirection <cursorDirection>`, `Direction of the cursor, can be either 'before' or 'after'.`)
684
773
  .action(actionRunner(functionsListExecutions))
685
774
 
686
775
  functions
@@ -699,11 +788,50 @@ functions
699
788
  .action(actionRunner(functionsGetExecution))
700
789
 
701
790
  functions
702
- .command(`getUsage`)
791
+ .command(`getFunctionUsage`)
703
792
  .description(``)
704
793
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
705
794
  .option(`--range <range>`, `Date range.`)
706
- .action(actionRunner(functionsGetUsage))
795
+ .action(actionRunner(functionsGetFunctionUsage))
796
+
797
+ functions
798
+ .command(`listVariables`)
799
+ .description(`Get a list of all variables of a specific function.`)
800
+ .requiredOption(`--functionId <functionId>`, `Function unique ID.`)
801
+ .option(`--queries <queries...>`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: key`)
802
+ .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
803
+ .action(actionRunner(functionsListVariables))
804
+
805
+ functions
806
+ .command(`createVariable`)
807
+ .description(`Create a new function variable. These variables can be accessed within function in the 'env' object under the request variable.`)
808
+ .requiredOption(`--functionId <functionId>`, `Function unique ID.`)
809
+ .requiredOption(`--key <key>`, `Variable key. Max length: 255 chars.`)
810
+ .requiredOption(`--value <value>`, `Variable value. Max length: 8192 chars.`)
811
+ .action(actionRunner(functionsCreateVariable))
812
+
813
+ functions
814
+ .command(`getVariable`)
815
+ .description(`Get a variable by its unique ID.`)
816
+ .requiredOption(`--functionId <functionId>`, `Function unique ID.`)
817
+ .requiredOption(`--variableId <variableId>`, `Variable unique ID.`)
818
+ .action(actionRunner(functionsGetVariable))
819
+
820
+ functions
821
+ .command(`updateVariable`)
822
+ .description(`Update variable by its unique ID.`)
823
+ .requiredOption(`--functionId <functionId>`, `Function unique ID.`)
824
+ .requiredOption(`--variableId <variableId>`, `Variable unique ID.`)
825
+ .requiredOption(`--key <key>`, `Variable key. Max length: 255 chars.`)
826
+ .option(`--value <value>`, `Variable value. Max length: 8192 chars.`)
827
+ .action(actionRunner(functionsUpdateVariable))
828
+
829
+ functions
830
+ .command(`deleteVariable`)
831
+ .description(`Delete a variable by its unique ID.`)
832
+ .requiredOption(`--functionId <functionId>`, `Function unique ID.`)
833
+ .requiredOption(`--variableId <variableId>`, `Variable unique ID.`)
834
+ .action(actionRunner(functionsDeleteVariable))
707
835
 
708
836
 
709
837
  module.exports = {
@@ -711,6 +839,7 @@ module.exports = {
711
839
  functionsList,
712
840
  functionsCreate,
713
841
  functionsListRuntimes,
842
+ functionsGetUsage,
714
843
  functionsGet,
715
844
  functionsUpdate,
716
845
  functionsDelete,
@@ -723,5 +852,10 @@ module.exports = {
723
852
  functionsListExecutions,
724
853
  functionsCreateExecution,
725
854
  functionsGetExecution,
726
- functionsGetUsage
855
+ functionsGetFunctionUsage,
856
+ functionsListVariables,
857
+ functionsCreateVariable,
858
+ functionsGetVariable,
859
+ functionsUpdateVariable,
860
+ functionsDeleteVariable
727
861
  };
@@ -42,9 +42,9 @@ const logout = new Command("logout")
42
42
  const client = new Command("client")
43
43
  .description(commandDescriptions['client'])
44
44
  .option("--selfSigned <value>", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool)
45
- .option("--endpoint <endpoint>", "Set your Apwrite server endpoint")
46
- .option("--projectId <projectId>", "Set your Apwrite project ID")
47
- .option("--key <key>", "Set your Apwrite server's API key")
45
+ .option("--endpoint <endpoint>", "Set your Appwrite server endpoint")
46
+ .option("--projectId <projectId>", "Set your Appwrite project ID")
47
+ .option("--key <key>", "Set your Appwrite server's API key")
48
48
  .option("--debug", "Print CLI debug information")
49
49
  .option("--reset", "Reset the CLI configuration")
50
50
  .action(actionRunner(async ({ selfSigned, endpoint, projectId, key, debug, reset }, command) => {
@@ -50,8 +50,17 @@ const initProject = async () => {
50
50
  const initFunction = async () => {
51
51
  // TODO: Add CI/CD support (ID, name, runtime)
52
52
  let answers = await inquirer.prompt(questionsInitFunction)
53
+ let functionFolder = path.join(process.cwd(), 'functions');
53
54
 
54
- if (fs.existsSync(path.join(process.cwd(), 'functions', answers.name))) {
55
+ if (!fs.existsSync(functionFolder)) {
56
+ fs.mkdirSync(functionFolder, {
57
+ recursive: true
58
+ });
59
+ }
60
+
61
+ const functionDir = path.join(functionFolder, answers.name);
62
+
63
+ if (fs.existsSync(functionDir)) {
55
64
  throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
56
65
  }
57
66
 
@@ -66,20 +75,53 @@ const initFunction = async () => {
66
75
  parseOutput: false
67
76
  })
68
77
 
69
- let command = `
70
- mkdir -m 777 -p 'functions/${answers.name}' && \
71
- cd 'functions/${answers.name}' && \
72
- git init && \
73
- git remote add -f origin https://github.com/appwrite/functions-starter && \
74
- git config core.sparseCheckout true && \
75
- echo '${answers.runtime.id}' >> .git/info/sparse-checkout && \
76
- git pull origin main && \
77
- rm -rf .git && \
78
- mv ${answers.runtime.id}/* . && \
79
- rm -rf ${answers.runtime.id}`;
80
-
81
- // Execute the child process but do not print any std output
82
- childProcess.execSync(command, { stdio: 'pipe' });
78
+ fs.mkdirSync(functionDir, "777");
79
+
80
+ let gitInitCommands = "git clone --depth 1 --sparse https://github.com/appwrite/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched
81
+
82
+ let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;
83
+
84
+ /* Force use CMD as powershell does not support && */
85
+ if (process.platform == 'win32') {
86
+ gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
87
+ gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
88
+ }
89
+
90
+ /* Execute the child process but do not print any std output */
91
+ try {
92
+ childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
93
+ childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
94
+ } catch (error) {
95
+ /* Specialised errors with recommended actions to take */
96
+ if (error.message.includes('error: unknown option')) {
97
+ throw new Error(`${error.message} \n\nSuggestion: Try updating your git to the latest version, then trying to run this command again.`)
98
+ } else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {
99
+ throw new Error(`${error.message} \n\nSuggestion: It appears that git is not installed, try installing git then trying to run this command again.`)
100
+ } else {
101
+ throw error;
102
+ }
103
+ }
104
+
105
+ fs.rmSync(path.join(functionDir, ".git"), { recursive: true });
106
+ const copyRecursiveSync = (src, dest) => {
107
+ let exists = fs.existsSync(src);
108
+ let stats = exists && fs.statSync(src);
109
+ let isDirectory = exists && stats.isDirectory();
110
+ if (isDirectory) {
111
+ if (!fs.existsSync(dest)) {
112
+ fs.mkdirSync(dest);
113
+ }
114
+
115
+ fs.readdirSync(src).forEach(function(childItemName) {
116
+ copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
117
+ });
118
+ } else {
119
+ fs.copyFileSync(src, dest);
120
+ }
121
+ };
122
+ copyRecursiveSync(path.join(functionDir, answers.runtime.id), functionDir);
123
+
124
+ fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
83
125
 
84
126
  const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
85
127
  const readmeFile = fs.readFileSync(readmePath).toString();