appwrite-cli 0.17.1 → 0.18.3

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 (81) hide show
  1. package/README.md +4 -16
  2. package/docs/examples/account/{create-session.md → create-email-session.md} +1 -1
  3. package/docs/examples/account/create-phone-session.md +3 -0
  4. package/docs/examples/account/create-phone-verification.md +1 -0
  5. package/docs/examples/account/update-phone-session.md +3 -0
  6. package/docs/examples/account/update-phone-verification.md +3 -0
  7. package/docs/examples/account/update-phone.md +3 -0
  8. package/docs/examples/{database → databases}/create-boolean-attribute.md +2 -1
  9. package/docs/examples/{database → databases}/create-collection.md +2 -1
  10. package/docs/examples/{database → databases}/create-document.md +2 -1
  11. package/docs/examples/{database → databases}/create-email-attribute.md +2 -1
  12. package/docs/examples/{database → databases}/create-enum-attribute.md +2 -1
  13. package/docs/examples/{database → databases}/create-float-attribute.md +2 -1
  14. package/docs/examples/{database → databases}/create-index.md +2 -1
  15. package/docs/examples/{database → databases}/create-integer-attribute.md +2 -1
  16. package/docs/examples/{database → databases}/create-ip-attribute.md +2 -1
  17. package/docs/examples/{database → databases}/create-string-attribute.md +2 -1
  18. package/docs/examples/{database → databases}/create-url-attribute.md +2 -1
  19. package/docs/examples/databases/create.md +3 -0
  20. package/docs/examples/databases/delete-attribute.md +4 -0
  21. package/docs/examples/databases/delete-collection.md +3 -0
  22. package/docs/examples/{database → databases}/delete-document.md +2 -1
  23. package/docs/examples/databases/delete-index.md +4 -0
  24. package/docs/examples/databases/delete.md +2 -0
  25. package/docs/examples/databases/get-attribute.md +4 -0
  26. package/docs/examples/databases/get-collection-usage.md +4 -0
  27. package/docs/examples/databases/get-collection.md +3 -0
  28. package/docs/examples/databases/get-database-usage.md +3 -0
  29. package/docs/examples/{database → databases}/get-document.md +2 -1
  30. package/docs/examples/databases/get-index.md +4 -0
  31. package/docs/examples/databases/get-usage.md +2 -0
  32. package/docs/examples/databases/get.md +2 -0
  33. package/docs/examples/databases/list-attributes.md +3 -0
  34. package/docs/examples/databases/list-collection-logs.md +5 -0
  35. package/docs/examples/databases/list-collections.md +8 -0
  36. package/docs/examples/{database → databases}/list-document-logs.md +2 -1
  37. package/docs/examples/databases/list-documents.md +10 -0
  38. package/docs/examples/databases/list-indexes.md +3 -0
  39. package/docs/examples/databases/list-logs.md +4 -0
  40. package/docs/examples/databases/list.md +7 -0
  41. package/docs/examples/{database → databases}/update-collection.md +2 -1
  42. package/docs/examples/{database → databases}/update-document.md +3 -2
  43. package/docs/examples/databases/update.md +3 -0
  44. package/docs/examples/projects/create-key.md +2 -1
  45. package/docs/examples/projects/update-key.md +2 -1
  46. package/docs/examples/projects/update-webhook-signature.md +3 -0
  47. package/docs/examples/users/{update-verification.md → update-email-verification.md} +1 -1
  48. package/docs/examples/users/update-phone-verification.md +3 -0
  49. package/docs/examples/users/update-phone.md +3 -0
  50. package/index.js +2 -2
  51. package/install.ps1 +2 -2
  52. package/install.sh +1 -1
  53. package/lib/client.js +3 -3
  54. package/lib/commands/account.js +202 -31
  55. package/lib/commands/{database.js → databases.js} +477 -177
  56. package/lib/commands/deploy.js +153 -71
  57. package/lib/commands/functions.js +4 -4
  58. package/lib/commands/generic.js +2 -2
  59. package/lib/commands/init.js +42 -24
  60. package/lib/commands/projects.js +43 -4
  61. package/lib/commands/storage.js +3 -3
  62. package/lib/commands/teams.js +2 -2
  63. package/lib/commands/users.js +71 -5
  64. package/lib/parser.js +1 -1
  65. package/lib/questions.js +45 -3
  66. package/package.json +1 -1
  67. package/docs/examples/account/delete.md +0 -1
  68. package/docs/examples/database/delete-attribute.md +0 -3
  69. package/docs/examples/database/delete-collection.md +0 -2
  70. package/docs/examples/database/delete-index.md +0 -3
  71. package/docs/examples/database/get-attribute.md +0 -3
  72. package/docs/examples/database/get-collection-usage.md +0 -3
  73. package/docs/examples/database/get-collection.md +0 -2
  74. package/docs/examples/database/get-index.md +0 -3
  75. package/docs/examples/database/get-usage.md +0 -2
  76. package/docs/examples/database/list-attributes.md +0 -2
  77. package/docs/examples/database/list-collection-logs.md +0 -4
  78. package/docs/examples/database/list-collections.md +0 -7
  79. package/docs/examples/database/list-documents.md +0 -9
  80. package/docs/examples/database/list-indexes.md +0 -2
  81. package/docs/examples/health/get-queue-usage.md +0 -1
@@ -6,34 +6,37 @@ const { questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollect
6
6
  const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
7
7
  const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment } = require('./functions');
8
8
  const {
9
- databaseCreateBooleanAttribute,
10
- databaseGetCollection,
11
- databaseCreateCollection,
12
- databaseCreateStringAttribute,
13
- databaseCreateIntegerAttribute,
14
- databaseCreateFloatAttribute,
15
- databaseCreateEmailAttribute,
16
- databaseCreateIndex,
17
- databaseCreateUrlAttribute,
18
- databaseCreateIpAttribute,
19
- databaseCreateEnumAttribute,
20
- databaseDeleteAttribute,
21
- databaseListAttributes,
22
- databaseListIndexes,
23
- databaseDeleteIndex
24
- } = require("./database");
9
+ databasesGet,
10
+ databasesCreate,
11
+ databasesCreateBooleanAttribute,
12
+ databasesGetCollection,
13
+ databasesCreateCollection,
14
+ databasesCreateStringAttribute,
15
+ databasesCreateIntegerAttribute,
16
+ databasesCreateFloatAttribute,
17
+ databasesCreateEmailAttribute,
18
+ databasesCreateIndex,
19
+ databasesCreateUrlAttribute,
20
+ databasesCreateIpAttribute,
21
+ databasesCreateEnumAttribute,
22
+ databasesDeleteAttribute,
23
+ databasesListAttributes,
24
+ databasesListIndexes,
25
+ databasesDeleteIndex
26
+ } = require("./databases");
25
27
 
26
28
  const POOL_DEBOUNCE = 2000; // in milliseconds
27
29
  const POOL_MAX_DEBOUNCES = 30;
28
30
 
29
31
  const awaitPools = {
30
- wipeAttributes: async (collectionId, iteration = 1) => {
32
+ wipeAttributes: async (databaseId, collectionId, iteration = 1) => {
31
33
  if (iteration > POOL_MAX_DEBOUNCES) {
32
34
  return false;
33
35
  }
34
36
 
35
37
  // TODO: Pagination?
36
- const { attributes: remoteAttributes } = await databaseListAttributes({
38
+ const { attributes: remoteAttributes } = await databasesListAttributes({
39
+ databaseId,
37
40
  collectionId,
38
41
  limit: 100,
39
42
  parseOutput: false
@@ -44,15 +47,16 @@ const awaitPools = {
44
47
  }
45
48
 
46
49
  await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
47
- return await awaitPools.wipeAttributes(collectionId, iteration + 1);
50
+ return await awaitPools.wipeAttributes(databaseId, collectionId, iteration + 1);
48
51
  },
49
- wipeIndexes: async (collectionId, iteration = 1) => {
52
+ wipeIndexes: async (databaseId, collectionId, iteration = 1) => {
50
53
  if (iteration > POOL_MAX_DEBOUNCES) {
51
54
  return false;
52
55
  }
53
56
 
54
57
  // TODO: Pagination?
55
- const { indexes: remoteIndexes } = await databaseListIndexes({
58
+ const { indexes: remoteIndexes } = await databasesListIndexes({
59
+ databaseId,
56
60
  collectionId,
57
61
  limit: 100,
58
62
  parseOutput: false
@@ -63,15 +67,16 @@ const awaitPools = {
63
67
  }
64
68
 
65
69
  await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
66
- return await awaitPools.wipeIndexes(collectionId, iteration + 1);
70
+ return await awaitPools.wipeIndexes(databaseId, collectionId, iteration + 1);
67
71
  },
68
- expectAttributes: async (collectionId, attributeKeys, iteration = 1) => {
72
+ expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
69
73
  if (iteration > POOL_MAX_DEBOUNCES) {
70
74
  return false;
71
75
  }
72
76
 
73
77
  // TODO: Pagination?
74
- const { attributes: remoteAttributes } = await databaseListAttributes({
78
+ const { attributes: remoteAttributes } = await databasesListAttributes({
79
+ databaseId,
75
80
  collectionId,
76
81
  limit: 100,
77
82
  parseOutput: false
@@ -94,15 +99,16 @@ const awaitPools = {
94
99
  }
95
100
 
96
101
  await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
97
- return await awaitPools.expectAttributes(collectionId, attributeKeys, iteration + 1);
102
+ return await awaitPools.expectAttributes(databaseId, collectionId, attributeKeys, iteration + 1);
98
103
  },
99
- expectIndexes: async (collectionId, indexKeys, iteration = 1) => {
104
+ expectIndexes: async (databaseId, collectionId, indexKeys, iteration = 1) => {
100
105
  if (iteration > POOL_MAX_DEBOUNCES) {
101
106
  return false;
102
107
  }
103
108
 
104
109
  // TODO: Pagination?
105
- const { indexes: remoteIndexes } = await databaseListIndexes({
110
+ const { indexes: remoteIndexes } = await databasesListIndexes({
111
+ databaseId,
106
112
  collectionId,
107
113
  limit: 100,
108
114
  parseOutput: false
@@ -125,32 +131,49 @@ const awaitPools = {
125
131
  }
126
132
 
127
133
  await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
128
- return await awaitPools.expectIndexes(collectionId, indexKeys, iteration + 1);
134
+ return await awaitPools.expectIndexes(databaseId, collectionId, indexKeys, iteration + 1);
129
135
  },
130
136
  }
131
137
 
132
138
  const deploy = new Command("deploy")
133
139
  .description(commandDescriptions['deploy'])
134
- .option("--all", "Flag to deploy collections and functions")
135
- .action(actionRunner(async ({ all }, command) => {
136
- if (all == undefined) {
137
- command.help()
138
- }
139
-
140
- try {
141
- await deployFunction();
142
- } catch (e) {
143
- error(e.message);
144
- }
145
- await deployCollection()
140
+ .action(actionRunner(async (_options, command) => {
141
+ command.help()
146
142
  }));
147
143
 
148
- const deployFunction = async () => {
144
+ const deployFunction = async ({ functionId, all } = {}) => {
149
145
  let response = {};
150
146
 
151
- let answers = await inquirer.prompt(questionsDeployFunctions)
152
- let functions = answers.functions.map((func) => JSONbig.parse(func))
147
+ const functionIds = [];
148
+
149
+ if(functionId) {
150
+ functionIds.push(functionId);
151
+ } else if(all) {
152
+ const functions = localConfig.getFunctions();
153
+ if (functions.length === 0) {
154
+ throw new Error("No functions found in the current directory.");
155
+ }
156
+ functionIds.push(...functions.map((func, idx) => {
157
+ return func.$id;
158
+ }));
159
+ }
153
160
 
161
+ if(functionIds.length <= 0) {
162
+ const answers = await inquirer.prompt(questionsDeployFunctions);
163
+ functionIds.push(...answers.functions);
164
+ }
165
+
166
+ let functions = functionIds.map((id) => {
167
+ const functions = localConfig.getFunctions();
168
+ const func = functions.find((f) => f.$id === id);
169
+
170
+ if(!func) {
171
+ throw new Error("Function '" + id + "' not found.")
172
+ }
173
+
174
+ return func;
175
+ });
176
+
154
177
  for (let func of functions) {
155
178
  log(`Deploying function ${func.name} ( ${func['$id']} )`)
156
179
 
@@ -230,12 +253,13 @@ const deployFunction = async () => {
230
253
  }
231
254
  }
232
255
 
233
- const createAttribute = async (collectionId, attribute) => {
256
+ const createAttribute = async (databaseId, collectionId, attribute) => {
234
257
  switch (attribute.type) {
235
258
  case 'string':
236
259
  switch (attribute.format) {
237
260
  case 'email':
238
- return await databaseCreateEmailAttribute({
261
+ return await databasesCreateEmailAttribute({
262
+ databaseId,
239
263
  collectionId,
240
264
  key: attribute.key,
241
265
  required: attribute.required,
@@ -244,7 +268,8 @@ const createAttribute = async (collectionId, attribute) => {
244
268
  parseOutput: false
245
269
  })
246
270
  case 'url':
247
- return await databaseCreateUrlAttribute({
271
+ return await databasesCreateUrlAttribute({
272
+ databaseId,
248
273
  collectionId,
249
274
  key: attribute.key,
250
275
  required: attribute.required,
@@ -253,7 +278,8 @@ const createAttribute = async (collectionId, attribute) => {
253
278
  parseOutput: false
254
279
  })
255
280
  case 'ip':
256
- return await databaseCreateIpAttribute({
281
+ return await databasesCreateIpAttribute({
282
+ databaseId,
257
283
  collectionId,
258
284
  key: attribute.key,
259
285
  required: attribute.required,
@@ -262,7 +288,8 @@ const createAttribute = async (collectionId, attribute) => {
262
288
  parseOutput: false
263
289
  })
264
290
  case 'enum':
265
- return await databaseCreateEnumAttribute({
291
+ return await databasesCreateEnumAttribute({
292
+ databaseId,
266
293
  collectionId,
267
294
  key: attribute.key,
268
295
  elements: attribute.elements,
@@ -272,7 +299,8 @@ const createAttribute = async (collectionId, attribute) => {
272
299
  parseOutput: false
273
300
  })
274
301
  default:
275
- return await databaseCreateStringAttribute({
302
+ return await databasesCreateStringAttribute({
303
+ databaseId,
276
304
  collectionId,
277
305
  key: attribute.key,
278
306
  size: attribute.size,
@@ -284,7 +312,8 @@ const createAttribute = async (collectionId, attribute) => {
284
312
 
285
313
  }
286
314
  case 'integer':
287
- return await databaseCreateIntegerAttribute({
315
+ return await databasesCreateIntegerAttribute({
316
+ databaseId,
288
317
  collectionId,
289
318
  key: attribute.key,
290
319
  required: attribute.required,
@@ -295,7 +324,8 @@ const createAttribute = async (collectionId, attribute) => {
295
324
  parseOutput: false
296
325
  })
297
326
  case 'double':
298
- return databaseCreateFloatAttribute({
327
+ return databasesCreateFloatAttribute({
328
+ databaseId,
299
329
  collectionId,
300
330
  key: attribute.key,
301
331
  required: attribute.required,
@@ -306,7 +336,9 @@ const createAttribute = async (collectionId, attribute) => {
306
336
  parseOutput: false
307
337
  })
308
338
  case 'boolean':
309
- return databaseCreateBooleanAttribute({
339
+ return databasesCreateBooleanAttribute({
340
+ databaseId,
341
+ databaseId,
310
342
  collectionId,
311
343
  key: attribute.key,
312
344
  required: attribute.required,
@@ -317,15 +349,55 @@ const createAttribute = async (collectionId, attribute) => {
317
349
  }
318
350
  }
319
351
 
320
- const deployCollection = async () => {
352
+ const deployCollection = async ({ all } = {}) => {
321
353
  let response = {};
322
- let answers = await inquirer.prompt(questionsDeployCollections[0])
323
- let collections = answers.collections.map((collection) => JSONbig.parse(collection));
354
+
355
+ let collectionIds = [];
356
+ const configCollections = localConfig.getCollections();
357
+
358
+ if(all) {
359
+ if (configCollections.length === 0) {
360
+ throw new Error("No collections found in the current directory. Run `appwrite init collection` to fetch all your collections.");
361
+ }
362
+ collectionIds.push(...configCollections.map((c) => c.$id));
363
+ }
364
+
365
+ if(collectionIds.length <= 0) {
366
+ let answers = await inquirer.prompt(questionsDeployCollections[0])
367
+ collectionIds.push(...answers.collections);
368
+ }
369
+
370
+ let collections = [];
371
+
372
+ for(const collectionId of collectionIds) {
373
+ const idCollections = configCollections.filter((c) => c.$id === collectionId);
374
+ collections.push(...idCollections);
375
+ }
324
376
 
325
377
  for (let collection of collections) {
326
378
  log(`Deploying collection ${collection.name} ( ${collection['$id']} )`)
379
+
380
+ let databaseId;
381
+
382
+ try {
383
+ const database = await databasesGet({
384
+ databaseId: collection.databaseId,
385
+ parseOutput: false,
386
+ });
387
+ databaseId = database.$id;
388
+ } catch(err) {
389
+ log(`Database ${collection.databaseId} not found. Creating it now...`);
390
+ const database = await databasesCreate({
391
+ databaseId: collection.databaseId,
392
+ name: collection.databaseId,
393
+ parseOutput: false,
394
+ });
395
+ databaseId = database.$id;
396
+ }
397
+
327
398
  try {
328
- response = await databaseGetCollection({
399
+ response = await databasesGetCollection({
400
+ databaseId,
329
401
  collectionId: collection['$id'],
330
402
  parseOutput: false,
331
403
  })
@@ -340,51 +412,55 @@ const deployCollection = async () => {
340
412
  log(`Updating attributes ... `);
341
413
 
342
414
  // TODO: Pagination?
343
- const { indexes: remoteIndexes } = await databaseListIndexes({
415
+ const { indexes: remoteIndexes } = await databasesListIndexes({
416
+ databaseId,
344
417
  collectionId: collection['$id'],
345
418
  limit: 100,
346
419
  parseOutput: false
347
420
  });
348
421
 
349
422
  await Promise.all(remoteIndexes.map(async index => {
350
- await databaseDeleteIndex({
423
+ await databasesDeleteIndex({
424
+ databaseId,
351
425
  collectionId: collection['$id'],
352
426
  key: index.key,
353
427
  parseOutput: false
354
428
  });
355
429
  }));
356
430
 
357
- const deleteIndexesPoolStatus = await awaitPools.wipeIndexes(collection['$id']);
431
+ const deleteIndexesPoolStatus = await awaitPools.wipeIndexes(databaseId, collection['$id']);
358
432
  if (!deleteIndexesPoolStatus) {
359
433
  throw new Error("Index deletion did not finish for too long.");
360
434
  }
361
435
 
362
436
  // TODO: Pagination?
363
- const { attributes: remoteAttributes } = await databaseListAttributes({
437
+ const { attributes: remoteAttributes } = await databasesListAttributes({
438
+ databaseId,
364
439
  collectionId: collection['$id'],
365
440
  limit: 100,
366
441
  parseOutput: false
367
442
  });
368
443
 
369
444
  await Promise.all(remoteAttributes.map(async attribute => {
370
- await databaseDeleteAttribute({
445
+ await databasesDeleteAttribute({
446
+ databaseId,
371
447
  collectionId: collection['$id'],
372
448
  key: attribute.key,
373
449
  parseOutput: false
374
450
  });
375
451
  }));
376
452
 
377
- const deleteAttributesPoolStatus = await awaitPools.wipeAttributes(collection['$id']);
453
+ const deleteAttributesPoolStatus = await awaitPools.wipeAttributes(databaseId, collection['$id']);
378
454
  if (!deleteAttributesPoolStatus) {
379
455
  throw new Error("Attribute deletion did not finish for too long.");
380
456
  }
381
457
 
382
458
  await Promise.all(collection.attributes.map(async attribute => {
383
- await createAttribute(collection['$id'], attribute);
459
+ await createAttribute(databaseId, collection['$id'], attribute);
384
460
  }));
385
461
 
386
462
  const attributeKeys = collection.attributes.map(attribute => attribute.key);
387
- const createPoolStatus = await awaitPools.expectAttributes(collection['$id'], attributeKeys);
463
+ const createPoolStatus = await awaitPools.expectAttributes(databaseId, collection['$id'], attributeKeys);
388
464
  if (!createPoolStatus) {
389
465
  throw new Error("Attribute creation did not finish for too long.");
390
466
  }
@@ -393,7 +469,8 @@ const deployCollection = async () => {
393
469
 
394
470
  log(`Creating indexes ...`)
395
471
  await Promise.all(collection.indexes.map(async index => {
396
- await databaseCreateIndex({
472
+ await databasesCreateIndex({
473
+ databaseId,
397
474
  collectionId: collection['$id'],
398
475
  key: index.key,
399
476
  type: index.type,
@@ -404,7 +481,7 @@ const deployCollection = async () => {
404
481
  }));
405
482
 
406
483
  const indexKeys = collection.indexes.map(attribute => attribute.key);
407
- const indexPoolStatus = await awaitPools.expectIndexes(collection['$id'], indexKeys);
484
+ const indexPoolStatus = await awaitPools.expectIndexes(databaseId, collection['$id'], indexKeys);
408
485
  if (!indexPoolStatus) {
409
486
  throw new Error("Index creation did not finish for too long.");
410
487
  }
@@ -413,7 +490,8 @@ const deployCollection = async () => {
413
490
  } catch (e) {
414
491
  if (e.code == 404) {
415
492
  log(`Collection ${collection.name} does not exist in the project. Creating ... `);
416
- response = await databaseCreateCollection({
493
+ response = await databasesCreateCollection({
494
+ databaseId,
417
495
  collectionId: collection['$id'],
418
496
  name: collection.name,
419
497
  permission: collection.permission,
@@ -424,11 +502,11 @@ const deployCollection = async () => {
424
502
 
425
503
  log(`Creating attributes ... `);
426
504
  await Promise.all(collection.attributes.map(async attribute => {
427
- await createAttribute(collection['$id'], attribute);
505
+ await createAttribute(databaseId, collection['$id'], attribute);
428
506
  }));
429
507
 
430
508
  const attributeKeys = collection.attributes.map(attribute => attribute.key);
431
- const attributePoolStatus = await awaitPools.expectAttributes(collection['$id'], attributeKeys);
509
+ const attributePoolStatus = await awaitPools.expectAttributes(databaseId, collection['$id'], attributeKeys);
432
510
  if (!attributePoolStatus) {
433
511
  throw new Error("Attribute creation did not finish for too long.");
434
512
  }
@@ -437,7 +515,8 @@ const deployCollection = async () => {
437
515
 
438
516
  log(`Creating indexes ...`);
439
517
  await Promise.all(collection.indexes.map(async index => {
440
- await databaseCreateIndex({
518
+ await databasesCreateIndex({
519
+ databaseId,
441
520
  collectionId: collection['$id'],
442
521
  key: index.key,
443
522
  type: index.type,
@@ -448,7 +527,7 @@ const deployCollection = async () => {
448
527
  }));
449
528
 
450
529
  const indexKeys = collection.indexes.map(attribute => attribute.key);
451
- const indexPoolStatus = await awaitPools.expectIndexes(collection['$id'], indexKeys);
530
+ const indexPoolStatus = await awaitPools.expectIndexes(databaseId, collection['$id'], indexKeys);
452
531
  if (!indexPoolStatus) {
453
532
  throw new Error("Index creation did not finish for too long.");
454
533
  }
@@ -466,11 +545,14 @@ const deployCollection = async () => {
466
545
  deploy
467
546
  .command("function")
468
547
  .description("Deploy functions in the current directory.")
548
+ .option(`--functionId <functionId>`, `Function ID`)
549
+ .option(`--all`, `Flag to deploy all functions`)
469
550
  .action(actionRunner(deployFunction));
470
551
 
471
552
  deploy
472
553
  .command("collection")
473
554
  .description("Deploy collections in the current project.")
555
+ .option(`--all`, `Flag to deploy all functions`)
474
556
  .action(actionRunner(deployCollection));
475
557
 
476
558
  module.exports = {
@@ -264,7 +264,7 @@ const functionsListDeployments = async ({ functionId, search, limit, offset, cur
264
264
  const functionsCreateDeployment = async ({ functionId, entrypoint, code, activate, parseOutput = true, sdk = undefined, onProgress = () => {}}) => {
265
265
  /* @param {string} functionId */
266
266
  /* @param {string} entrypoint */
267
- /* @param {string} code */
267
+ /* @param {InputFile} code */
268
268
  /* @param {boolean} activate */
269
269
 
270
270
  let client = !sdk ? await sdkForProject() : sdk;
@@ -576,7 +576,7 @@ functions
576
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
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
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.`)
579
+ .option(`--cursorDirection <cursorDirection>`, `Direction of the cursor, can be either 'before' or 'after'.`)
580
580
  .option(`--orderType <orderType>`, `Order result by ASC or DESC order.`)
581
581
  .action(actionRunner(functionsList))
582
582
 
@@ -630,7 +630,7 @@ functions
630
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
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
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.`)
633
+ .option(`--cursorDirection <cursorDirection>`, `Direction of the cursor, can be either 'before' or 'after'.`)
634
634
  .option(`--orderType <orderType>`, `Order result by ASC or DESC order.`)
635
635
  .action(actionRunner(functionsListDeployments))
636
636
 
@@ -680,7 +680,7 @@ functions
680
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)
681
681
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
682
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.`)
683
+ .option(`--cursorDirection <cursorDirection>`, `Direction of the cursor, can be either 'before' or 'after'.`)
684
684
  .action(actionRunner(functionsListExecutions))
685
685
 
686
686
  functions
@@ -5,7 +5,7 @@ const { sdkForConsole } = require("../sdks");
5
5
  const { globalConfig, localConfig } = require("../config");
6
6
  const { actionRunner, success, parseBool, commandDescriptions, log, parse } = require("../parser");
7
7
  const { questionsLogin } = require("../questions");
8
- const { accountCreateSession, accountDeleteSession } = require("./account");
8
+ const { accountCreateEmailSession, accountDeleteSession } = require("./account");
9
9
 
10
10
  const login = new Command("login")
11
11
  .description(commandDescriptions['login'])
@@ -14,7 +14,7 @@ const login = new Command("login")
14
14
 
15
15
  let client = await sdkForConsole(false);
16
16
 
17
- await accountCreateSession({
17
+ await accountCreateEmailSession({
18
18
  email: answers.email,
19
19
  password: answers.password,
20
20
  parseOutput: false,
@@ -6,22 +6,16 @@ const inquirer = require("inquirer");
6
6
  const { teamsCreate } = require("./teams");
7
7
  const { projectsCreate } = require("./projects");
8
8
  const { functionsCreate } = require("./functions");
9
- const { databaseListCollections } = require("./database");
9
+ const { databasesListCollections, databasesList } = require("./databases");
10
10
  const { sdkForConsole } = require("../sdks");
11
11
  const { localConfig } = require("../config");
12
- const { questionsInitProject, questionsInitFunction } = require("../questions");
12
+ const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions");
13
13
  const { success, log, actionRunner, commandDescriptions } = require("../parser");
14
14
 
15
15
  const init = new Command("init")
16
16
  .description(commandDescriptions['init'])
17
- .option("--all", "Flag to initialize projects and collection")
18
- .action(actionRunner(async ({ all }, command) => {
19
- if (all == undefined) {
20
- command.help()
21
- }
22
-
23
- await initProject();
24
- await initCollection()
17
+ .action(actionRunner(async (_options, command) => {
18
+ command.help();
25
19
  }));
26
20
 
27
21
  const initProject = async () => {
@@ -40,7 +34,7 @@ const initProject = async () => {
40
34
 
41
35
  let teamId = response['$id'];
42
36
  response = await projectsCreate({
43
- projectId: 'unique()',
37
+ projectId: answers.id,
44
38
  name: answers.project,
45
39
  teamId,
46
40
  parseOutput: false
@@ -54,6 +48,7 @@ const initProject = async () => {
54
48
  }
55
49
 
56
50
  const initFunction = async () => {
51
+ // TODO: Add CI/CD support (ID, name, runtime)
57
52
  let answers = await inquirer.prompt(questionsInitFunction)
58
53
 
59
54
  if (fs.existsSync(path.join(process.cwd(), 'functions', answers.name))) {
@@ -65,7 +60,7 @@ const initFunction = async () => {
65
60
  }
66
61
 
67
62
  let response = await functionsCreate({
68
- functionId: 'unique()',
63
+ functionId: answers.id,
69
64
  name: answers.name,
70
65
  runtime: answers.runtime.id,
71
66
  parseOutput: false
@@ -110,20 +105,41 @@ const initFunction = async () => {
110
105
  success();
111
106
  }
112
107
 
113
- const initCollection = async () => {
114
- // TODO: Pagination?
115
- let response = await databaseListCollections({
116
- limit: 100,
117
- parseOutput: false
118
- })
108
+ const initCollection = async ({ all, databaseId } = {}) => {
109
+ const databaseIds = [];
110
+
111
+ if(databaseId) {
112
+ databaseIds.push(databaseId);
113
+ } else if(all) {
114
+ let allDatabases = await databasesList({
115
+ parseOutput: false
116
+ })
119
117
 
120
- let collections = response.collections;
121
- log(`Found ${collections.length} collections`);
118
+ databaseIds.push(...allDatabases.databases.map((d) => d.$id));
119
+ }
120
+
121
+ if(databaseIds.length <= 0) {
122
+ let answers = await inquirer.prompt(questionsInitCollection)
123
+ if (!answers.databases) process.exit(1)
124
+ databaseIds.push(...answers.databases);
125
+ }
122
126
 
123
- collections.forEach(async collection => {
124
- log(`Fetching ${collection.name} ...`);
125
- localConfig.addCollection(collection);
126
- });
127
+ for(const databaseId of databaseIds) {
128
+ // TODO: Pagination?
129
+ let response = await databasesListCollections({
130
+ databaseId,
131
+ limit: 100,
132
+ parseOutput: false
133
+ })
134
+
135
+ let collections = response.collections;
136
+ log(`Found ${collections.length} collections`);
137
+
138
+ collections.forEach(async collection => {
139
+ log(`Fetching ${collection.name} ...`);
140
+ localConfig.addCollection(collection);
141
+ });
142
+ }
127
143
 
128
144
  success();
129
145
  }
@@ -141,6 +157,8 @@ init
141
157
  init
142
158
  .command("collection")
143
159
  .description("Initialise your Appwrite collections")
160
+ .option(`--databaseId <databaseId>`, `Database ID`)
161
+ .option(`--all`, `Flag to initialize all databases`)
144
162
  .action(actionRunner(initCollection))
145
163
 
146
164
  module.exports = {