appwrite-cli 5.0.5 → 6.0.0-rc.1

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 (53) hide show
  1. package/README.md +4 -4
  2. package/docs/examples/functions/create-build.md +1 -1
  3. package/docs/examples/functions/create-execution.md +1 -0
  4. package/docs/examples/functions/create.md +1 -0
  5. package/docs/examples/functions/delete-execution.md +3 -0
  6. package/docs/examples/functions/update-deployment-build.md +3 -0
  7. package/docs/examples/functions/update.md +1 -0
  8. package/docs/examples/projects/create-j-w-t.md +4 -0
  9. package/docs/examples/projects/update-mock-numbers.md +3 -0
  10. package/docs/examples/projects/update-session-alerts.md +3 -0
  11. package/docs/examples/users/create-j-w-t.md +4 -0
  12. package/docs/examples/vcs/get-repository-contents.md +4 -0
  13. package/index.js +34 -7
  14. package/install.ps1 +3 -3
  15. package/install.sh +2 -2
  16. package/lib/client.js +17 -3
  17. package/lib/commands/account.js +306 -152
  18. package/lib/commands/assistant.js +8 -5
  19. package/lib/commands/avatars.js +114 -58
  20. package/lib/commands/console.js +8 -5
  21. package/lib/commands/databases.js +353 -164
  22. package/lib/commands/functions.js +310 -100
  23. package/lib/commands/generic.js +206 -54
  24. package/lib/commands/graphql.js +14 -8
  25. package/lib/commands/health.js +140 -71
  26. package/lib/commands/init.js +250 -155
  27. package/lib/commands/locale.js +50 -26
  28. package/lib/commands/messaging.js +334 -156
  29. package/lib/commands/migrations.js +98 -50
  30. package/lib/commands/project.js +38 -20
  31. package/lib/commands/projects.js +449 -144
  32. package/lib/commands/proxy.js +32 -17
  33. package/lib/commands/pull.js +231 -0
  34. package/lib/commands/push.js +1518 -0
  35. package/lib/commands/run.js +282 -0
  36. package/lib/commands/storage.js +160 -76
  37. package/lib/commands/teams.js +102 -50
  38. package/lib/commands/users.js +324 -134
  39. package/lib/commands/vcs.js +102 -29
  40. package/lib/config.js +190 -18
  41. package/lib/emulation/docker.js +187 -0
  42. package/lib/emulation/utils.js +177 -0
  43. package/lib/id.js +30 -0
  44. package/lib/paginate.js +1 -2
  45. package/lib/parser.js +69 -12
  46. package/lib/questions.js +452 -80
  47. package/lib/sdks.js +1 -1
  48. package/lib/spinner.js +103 -0
  49. package/lib/utils.js +242 -4
  50. package/lib/validations.js +17 -0
  51. package/package.json +6 -2
  52. package/scoop/appwrite.json +3 -3
  53. package/lib/commands/deploy.js +0 -940
@@ -4,7 +4,7 @@ const tar = require("tar");
4
4
  const ignore = require("ignore");
5
5
  const { promisify } = require('util');
6
6
  const libClient = require('../client.js');
7
- const { getAllFiles } = require('../utils.js');
7
+ const { getAllFiles, showConsoleLink } = require('../utils.js');
8
8
  const { Command } = require('commander');
9
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
10
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -43,6 +43,7 @@ const proxy = new Command("proxy").description(commandDescriptions['proxy']).con
43
43
  * @typedef {Object} ProxyListRulesRequestParams
44
44
  * @property {string[]} 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: domain, resourceType, resourceId, url
45
45
  * @property {string} search Search term to filter your list results. Max length: 256 chars.
46
+ * @property {boolean} overrideForCli
46
47
  * @property {boolean} parseOutput
47
48
  * @property {libClient | undefined} sdk
48
49
  */
@@ -50,8 +51,9 @@ const proxy = new Command("proxy").description(commandDescriptions['proxy']).con
50
51
  /**
51
52
  * @param {ProxyListRulesRequestParams} params
52
53
  */
53
- const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undefined}) => {
54
- let client = !sdk ? await sdkForProject() : sdk;
54
+ const proxyListRules = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
55
+ let client = !sdk ? await sdkForProject() :
56
+ sdk;
55
57
  let apiPath = '/proxy/rules';
56
58
  let payload = {};
57
59
  if (typeof queries !== 'undefined') {
@@ -71,8 +73,9 @@ const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undef
71
73
  parse(response)
72
74
  success()
73
75
  }
74
-
76
+
75
77
  return response;
78
+
76
79
  }
77
80
 
78
81
  /**
@@ -80,6 +83,7 @@ const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undef
80
83
  * @property {string} domain Domain name.
81
84
  * @property {ResourceType} resourceType Action definition for the rule. Possible values are "api", "function"
82
85
  * @property {string} resourceId ID of resource for the action type. If resourceType is "api", leave empty. If resourceType is "function", provide ID of the function.
86
+ * @property {boolean} overrideForCli
83
87
  * @property {boolean} parseOutput
84
88
  * @property {libClient | undefined} sdk
85
89
  */
@@ -87,8 +91,9 @@ const proxyListRules = async ({ queries, search, parseOutput = true, sdk = undef
87
91
  /**
88
92
  * @param {ProxyCreateRuleRequestParams} params
89
93
  */
90
- const proxyCreateRule = async ({ domain, resourceType, resourceId, parseOutput = true, sdk = undefined}) => {
91
- let client = !sdk ? await sdkForProject() : sdk;
94
+ const proxyCreateRule = async ({domain,resourceType,resourceId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
95
+ let client = !sdk ? await sdkForProject() :
96
+ sdk;
92
97
  let apiPath = '/proxy/rules';
93
98
  let payload = {};
94
99
  if (typeof domain !== 'undefined') {
@@ -111,13 +116,15 @@ const proxyCreateRule = async ({ domain, resourceType, resourceId, parseOutput =
111
116
  parse(response)
112
117
  success()
113
118
  }
114
-
119
+
115
120
  return response;
121
+
116
122
  }
117
123
 
118
124
  /**
119
125
  * @typedef {Object} ProxyGetRuleRequestParams
120
126
  * @property {string} ruleId Rule ID.
127
+ * @property {boolean} overrideForCli
121
128
  * @property {boolean} parseOutput
122
129
  * @property {libClient | undefined} sdk
123
130
  */
@@ -125,8 +132,9 @@ const proxyCreateRule = async ({ domain, resourceType, resourceId, parseOutput =
125
132
  /**
126
133
  * @param {ProxyGetRuleRequestParams} params
127
134
  */
128
- const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
129
- let client = !sdk ? await sdkForProject() : sdk;
135
+ const proxyGetRule = async ({ruleId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
136
+ let client = !sdk ? await sdkForProject() :
137
+ sdk;
130
138
  let apiPath = '/proxy/rules/{ruleId}'.replace('{ruleId}', ruleId);
131
139
  let payload = {};
132
140
 
@@ -140,13 +148,15 @@ const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
140
148
  parse(response)
141
149
  success()
142
150
  }
143
-
151
+
144
152
  return response;
153
+
145
154
  }
146
155
 
147
156
  /**
148
157
  * @typedef {Object} ProxyDeleteRuleRequestParams
149
158
  * @property {string} ruleId Rule ID.
159
+ * @property {boolean} overrideForCli
150
160
  * @property {boolean} parseOutput
151
161
  * @property {libClient | undefined} sdk
152
162
  */
@@ -154,8 +164,9 @@ const proxyGetRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
154
164
  /**
155
165
  * @param {ProxyDeleteRuleRequestParams} params
156
166
  */
157
- const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
158
- let client = !sdk ? await sdkForProject() : sdk;
167
+ const proxyDeleteRule = async ({ruleId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
168
+ let client = !sdk ? await sdkForProject() :
169
+ sdk;
159
170
  let apiPath = '/proxy/rules/{ruleId}'.replace('{ruleId}', ruleId);
160
171
  let payload = {};
161
172
 
@@ -169,13 +180,15 @@ const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) =
169
180
  parse(response)
170
181
  success()
171
182
  }
172
-
183
+
173
184
  return response;
185
+
174
186
  }
175
187
 
176
188
  /**
177
189
  * @typedef {Object} ProxyUpdateRuleVerificationRequestParams
178
190
  * @property {string} ruleId Rule ID.
191
+ * @property {boolean} overrideForCli
179
192
  * @property {boolean} parseOutput
180
193
  * @property {libClient | undefined} sdk
181
194
  */
@@ -183,8 +196,9 @@ const proxyDeleteRule = async ({ ruleId, parseOutput = true, sdk = undefined}) =
183
196
  /**
184
197
  * @param {ProxyUpdateRuleVerificationRequestParams} params
185
198
  */
186
- const proxyUpdateRuleVerification = async ({ ruleId, parseOutput = true, sdk = undefined}) => {
187
- let client = !sdk ? await sdkForProject() : sdk;
199
+ const proxyUpdateRuleVerification = async ({ruleId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
200
+ let client = !sdk ? await sdkForProject() :
201
+ sdk;
188
202
  let apiPath = '/proxy/rules/{ruleId}/verification'.replace('{ruleId}', ruleId);
189
203
  let payload = {};
190
204
 
@@ -198,8 +212,9 @@ const proxyUpdateRuleVerification = async ({ ruleId, parseOutput = true, sdk = u
198
212
  parse(response)
199
213
  success()
200
214
  }
201
-
215
+
202
216
  return response;
217
+
203
218
  }
204
219
 
205
220
  proxy
@@ -242,4 +257,4 @@ module.exports = {
242
257
  proxyGetRule,
243
258
  proxyDeleteRule,
244
259
  proxyUpdateRuleVerification
245
- };
260
+ };
@@ -0,0 +1,231 @@
1
+ const fs = require("fs");
2
+ const tar = require("tar");
3
+ const { Command } = require("commander");
4
+ const inquirer = require("inquirer");
5
+ const { messagingListTopics } = require("./messaging");
6
+ const { teamsList } = require("./teams");
7
+ const { projectsGet } = require("./projects");
8
+ const { functionsList, functionsDownloadDeployment } = require("./functions");
9
+ const { databasesGet, databasesListCollections, databasesList } = require("./databases");
10
+ const { storageListBuckets } = require("./storage");
11
+ const { localConfig } = require("../config");
12
+ const { paginate } = require("../paginate");
13
+ const { questionsPullCollection, questionsPullFunctions, questionsPullResources } = require("../questions");
14
+ const { cliConfig, success, log, actionRunner, commandDescriptions } = require("../parser");
15
+
16
+ const pullResources = async () => {
17
+ const actions = {
18
+ project: pullProject,
19
+ functions: pullFunctions,
20
+ collections: pullCollection,
21
+ buckets: pullBucket,
22
+ teams: pullTeam,
23
+ messages: pullMessagingTopic
24
+ }
25
+
26
+ if (cliConfig.all) {
27
+ for (let action of Object.values(actions)) {
28
+ await action();
29
+ }
30
+ } else {
31
+ const answers = await inquirer.prompt(questionsPullResources[0]);
32
+
33
+ const action = actions[answers.resource];
34
+ if (action !== undefined) {
35
+ await action({ returnOnZero: true });
36
+ }
37
+ }
38
+ };
39
+
40
+ const pullProject = async () => {
41
+ try {
42
+ let response = await projectsGet({
43
+ parseOutput: false,
44
+ projectId: localConfig.getProject().projectId
45
+
46
+ })
47
+
48
+ localConfig.setProject(response.$id, response.name, response);
49
+
50
+ success();
51
+ } catch (e) {
52
+ throw e;
53
+ }
54
+ }
55
+
56
+ const pullFunctions = async () => {
57
+ const localFunctions = localConfig.getFunctions();
58
+
59
+ const functions = cliConfig.all
60
+ ? (await paginate(functionsList, { parseOutput: false }, 100, 'functions')).functions
61
+ : (await inquirer.prompt(questionsPullFunctions)).functions;
62
+
63
+ log(`Pulling ${functions.length} functions`);
64
+
65
+ for (let func of functions) {
66
+ const functionExistLocally = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']) !== undefined;
67
+
68
+ if (functionExistLocally) {
69
+ localConfig.updateFunction(func['$id'], func);
70
+ } else {
71
+ func['path'] = `functions/${func['$id']}`;
72
+ localConfig.addFunction(func);
73
+ localFunctions.push(func);
74
+ }
75
+
76
+ const localFunction = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']);
77
+
78
+ if (localFunction['deployment'] === '') {
79
+ continue
80
+ }
81
+
82
+ const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
83
+
84
+ await functionsDownloadDeployment({
85
+ functionId: func['$id'],
86
+ deploymentId: func['deployment'],
87
+ destination: compressedFileName,
88
+ overrideForCli: true,
89
+ parseOutput: false
90
+ })
91
+
92
+ if (!fs.existsSync(localFunction['path'])) {
93
+ fs.mkdirSync(localFunction['path'], { recursive: true });
94
+ }
95
+
96
+ tar.extract({
97
+ sync: true,
98
+ cwd: localFunction['path'],
99
+ file: compressedFileName,
100
+ strict: false,
101
+ });
102
+
103
+ fs.rmSync(compressedFileName);
104
+ success(`Pulled ${func['name']} code and settings`)
105
+ }
106
+ }
107
+
108
+ const pullCollection = async () => {
109
+ let databases = cliConfig.ids;
110
+
111
+ if (databases.length === 0) {
112
+ if (cliConfig.all) {
113
+ databases = (await paginate(databasesList, { parseOutput: false }, 100, 'databases')).databases.map(database => database.$id);
114
+ } else {
115
+ databases = (await inquirer.prompt(questionsPullCollection)).databases;
116
+ }
117
+ }
118
+
119
+ for (const databaseId of databases) {
120
+ const database = await databasesGet({
121
+ databaseId,
122
+ parseOutput: false
123
+ });
124
+
125
+ localConfig.addDatabase(database);
126
+
127
+ const { collections, total } = await paginate(databasesListCollections, {
128
+ databaseId,
129
+ parseOutput: false
130
+ }, 100, 'collections');
131
+
132
+ log(`Found ${total} collections`);
133
+
134
+ collections.map(async collection => {
135
+ log(`Fetching ${collection.name} ...`);
136
+ localConfig.addCollection({
137
+ ...collection,
138
+ '$createdAt': undefined,
139
+ '$updatedAt': undefined
140
+ });
141
+ });
142
+ }
143
+
144
+ success();
145
+ }
146
+
147
+ const pullBucket = async () => {
148
+ const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets');
149
+
150
+ log(`Found ${buckets.length} buckets`);
151
+
152
+ buckets.forEach(bucket => localConfig.addBucket(bucket));
153
+
154
+ success();
155
+ }
156
+
157
+ const pullTeam = async () => {
158
+ const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams');
159
+
160
+ log(`Found ${teams.length} teams`);
161
+
162
+ teams.forEach(team => {
163
+ const { total, $updatedAt, $createdAt, prefs, ...rest } = team;
164
+ localConfig.addTeam(rest);
165
+ });
166
+
167
+ success();
168
+ }
169
+
170
+ const pullMessagingTopic = async () => {
171
+ const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics');
172
+
173
+ log(`Found ${topics.length} topics`);
174
+
175
+ topics.forEach(topic => {
176
+ localConfig.addMessagingTopic(topic);
177
+ });
178
+
179
+ success();
180
+ }
181
+
182
+ const pull = new Command("pull")
183
+ .description(commandDescriptions['pull'])
184
+ .action(actionRunner(pullResources));
185
+
186
+ pull
187
+ .command("all")
188
+ .description("Pull all resource.")
189
+ .action(actionRunner(() => {
190
+ cliConfig.all = true;
191
+ return pullResources();
192
+ }));
193
+
194
+ pull
195
+ .command("project")
196
+ .description("Pull your Appwrite project name, services and auth settings")
197
+ .action(actionRunner(pullProject));
198
+
199
+ pull
200
+ .command("function")
201
+ .alias("functions")
202
+ .description("Pulling your Appwrite cloud function")
203
+ .action(actionRunner(pullFunctions))
204
+
205
+ pull
206
+ .command("collection")
207
+ .alias("collections")
208
+ .description("Pulling your Appwrite collections")
209
+ .action(actionRunner(pullCollection))
210
+
211
+ pull
212
+ .command("bucket")
213
+ .alias("buckets")
214
+ .description("Pulling your Appwrite buckets")
215
+ .action(actionRunner(pullBucket))
216
+
217
+ pull
218
+ .command("team")
219
+ .alias("teams")
220
+ .description("Pulling your Appwrite teams")
221
+ .action(actionRunner(pullTeam))
222
+
223
+ pull
224
+ .command("topic")
225
+ .alias("topics")
226
+ .description("Initialise your Appwrite messaging topics")
227
+ .action(actionRunner(pullMessagingTopic))
228
+
229
+ module.exports = {
230
+ pull,
231
+ };