appwrite-cli 4.2.0 → 4.2.2

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.
@@ -9,151 +9,227 @@ const { Command } = require('commander');
9
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
10
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
11
11
  const { localConfig, globalConfig } = require("../config");
12
+ const { File } = require('undici');
13
+ const { ReadableStream } = require('stream/web');
14
+
15
+ /**
16
+ * @param {fs.ReadStream} readStream
17
+ * @returns {ReadableStream}
18
+ */
19
+ function convertReadStreamToReadableStream(readStream) {
20
+ return new ReadableStream({
21
+ start(controller) {
22
+ readStream.on("data", (chunk) => {
23
+ controller.enqueue(chunk);
24
+ });
25
+ readStream.on("end", () => {
26
+ controller.close();
27
+ });
28
+ readStream.on("error", (err) => {
29
+ controller.error(err);
30
+ });
31
+ },
32
+ cancel() {
33
+ readStream.destroy();
34
+ },
35
+ });
36
+ }
12
37
 
13
38
  const project = new Command("project").description(commandDescriptions['project']).configureHelp({
14
39
  helpWidth: process.stdout.columns || 80
15
- })
40
+ })
16
41
 
17
- const projectGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => {
18
- /* @param {string} range */
42
+ /**
43
+ * @typedef {Object} ProjectGetUsageRequestParams
44
+ * @property {string} range Date range.
45
+ * @property {boolean} parseOutput
46
+ * @property {libClient | undefined} sdk
47
+ */
19
48
 
49
+ /**
50
+ * @param {ProjectGetUsageRequestParams} params
51
+ */
52
+ const projectGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => {
20
53
  let client = !sdk ? await sdkForProject() : sdk;
21
54
  let apiPath = '/project/usage';
22
55
  let payload = {};
23
-
24
- /** Query Params */
25
56
  if (typeof range !== 'undefined') {
26
57
  payload['range'] = range;
27
58
  }
59
+
28
60
  let response = undefined;
61
+
29
62
  response = await client.call('get', apiPath, {
30
63
  'content-type': 'application/json',
31
64
  }, payload);
32
-
65
+
33
66
  if (parseOutput) {
34
67
  parse(response)
35
68
  success()
36
69
  }
70
+
37
71
  return response;
38
72
  }
39
73
 
40
- const projectListVariables = async ({ parseOutput = true, sdk = undefined}) => {
74
+ /**
75
+ * @typedef {Object} ProjectListVariablesRequestParams
76
+ * @property {boolean} parseOutput
77
+ * @property {libClient | undefined} sdk
78
+ */
41
79
 
80
+ /**
81
+ * @param {ProjectListVariablesRequestParams} params
82
+ */
83
+ const projectListVariables = async ({ parseOutput = true, sdk = undefined}) => {
42
84
  let client = !sdk ? await sdkForProject() : sdk;
43
85
  let apiPath = '/project/variables';
44
86
  let payload = {};
87
+
45
88
  let response = undefined;
89
+
46
90
  response = await client.call('get', apiPath, {
47
91
  'content-type': 'application/json',
48
92
  }, payload);
49
-
93
+
50
94
  if (parseOutput) {
51
95
  parse(response)
52
96
  success()
53
97
  }
98
+
54
99
  return response;
55
100
  }
56
101
 
57
- const projectCreateVariable = async ({ key, value, parseOutput = true, sdk = undefined}) => {
58
- /* @param {string} key */
59
- /* @param {string} value */
102
+ /**
103
+ * @typedef {Object} ProjectCreateVariableRequestParams
104
+ * @property {string} key Variable key. Max length: 255 chars.
105
+ * @property {string} value Variable value. Max length: 8192 chars.
106
+ * @property {boolean} parseOutput
107
+ * @property {libClient | undefined} sdk
108
+ */
60
109
 
110
+ /**
111
+ * @param {ProjectCreateVariableRequestParams} params
112
+ */
113
+ const projectCreateVariable = async ({ key, value, parseOutput = true, sdk = undefined}) => {
61
114
  let client = !sdk ? await sdkForProject() : sdk;
62
115
  let apiPath = '/project/variables';
63
116
  let payload = {};
64
-
65
- /** Body Params */
66
-
67
117
  if (typeof key !== 'undefined') {
68
118
  payload['key'] = key;
69
119
  }
70
-
71
-
72
120
  if (typeof value !== 'undefined') {
73
121
  payload['value'] = value;
74
122
  }
75
123
 
76
124
  let response = undefined;
125
+
77
126
  response = await client.call('post', apiPath, {
78
127
  'content-type': 'application/json',
79
128
  }, payload);
80
-
129
+
81
130
  if (parseOutput) {
82
131
  parse(response)
83
132
  success()
84
133
  }
134
+
85
135
  return response;
86
136
  }
87
137
 
88
- const projectGetVariable = async ({ variableId, parseOutput = true, sdk = undefined}) => {
89
- /* @param {string} variableId */
138
+ /**
139
+ * @typedef {Object} ProjectGetVariableRequestParams
140
+ * @property {string} variableId Variable unique ID.
141
+ * @property {boolean} parseOutput
142
+ * @property {libClient | undefined} sdk
143
+ */
90
144
 
145
+ /**
146
+ * @param {ProjectGetVariableRequestParams} params
147
+ */
148
+ const projectGetVariable = async ({ variableId, parseOutput = true, sdk = undefined}) => {
91
149
  let client = !sdk ? await sdkForProject() : sdk;
92
150
  let apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId);
93
151
  let payload = {};
152
+
94
153
  let response = undefined;
154
+
95
155
  response = await client.call('get', apiPath, {
96
156
  'content-type': 'application/json',
97
157
  }, payload);
98
-
158
+
99
159
  if (parseOutput) {
100
160
  parse(response)
101
161
  success()
102
162
  }
163
+
103
164
  return response;
104
165
  }
105
166
 
106
- const projectUpdateVariable = async ({ variableId, key, value, parseOutput = true, sdk = undefined}) => {
107
- /* @param {string} variableId */
108
- /* @param {string} key */
109
- /* @param {string} value */
167
+ /**
168
+ * @typedef {Object} ProjectUpdateVariableRequestParams
169
+ * @property {string} variableId Variable unique ID.
170
+ * @property {string} key Variable key. Max length: 255 chars.
171
+ * @property {string} value Variable value. Max length: 8192 chars.
172
+ * @property {boolean} parseOutput
173
+ * @property {libClient | undefined} sdk
174
+ */
110
175
 
176
+ /**
177
+ * @param {ProjectUpdateVariableRequestParams} params
178
+ */
179
+ const projectUpdateVariable = async ({ variableId, key, value, parseOutput = true, sdk = undefined}) => {
111
180
  let client = !sdk ? await sdkForProject() : sdk;
112
181
  let apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId);
113
182
  let payload = {};
114
-
115
- /** Body Params */
116
-
117
183
  if (typeof key !== 'undefined') {
118
184
  payload['key'] = key;
119
185
  }
120
-
121
-
122
186
  if (typeof value !== 'undefined') {
123
187
  payload['value'] = value;
124
188
  }
125
189
 
126
190
  let response = undefined;
191
+
127
192
  response = await client.call('put', apiPath, {
128
193
  'content-type': 'application/json',
129
194
  }, payload);
130
-
195
+
131
196
  if (parseOutput) {
132
197
  parse(response)
133
198
  success()
134
199
  }
200
+
135
201
  return response;
136
202
  }
137
203
 
138
- const projectDeleteVariable = async ({ variableId, parseOutput = true, sdk = undefined}) => {
139
- /* @param {string} variableId */
204
+ /**
205
+ * @typedef {Object} ProjectDeleteVariableRequestParams
206
+ * @property {string} variableId Variable unique ID.
207
+ * @property {boolean} parseOutput
208
+ * @property {libClient | undefined} sdk
209
+ */
140
210
 
211
+ /**
212
+ * @param {ProjectDeleteVariableRequestParams} params
213
+ */
214
+ const projectDeleteVariable = async ({ variableId, parseOutput = true, sdk = undefined}) => {
141
215
  let client = !sdk ? await sdkForProject() : sdk;
142
216
  let apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId);
143
217
  let payload = {};
218
+
144
219
  let response = undefined;
220
+
145
221
  response = await client.call('delete', apiPath, {
146
222
  'content-type': 'application/json',
147
223
  }, payload);
148
-
224
+
149
225
  if (parseOutput) {
150
226
  parse(response)
151
227
  success()
152
228
  }
229
+
153
230
  return response;
154
231
  }
155
232
 
156
-
157
233
  project
158
234
  .command(`getUsage`)
159
235
  .description(``)
@@ -192,7 +268,6 @@ project
192
268
  .requiredOption(`--variableId <variableId>`, `Variable unique ID.`)
193
269
  .action(actionRunner(projectDeleteVariable))
194
270
 
195
-
196
271
  module.exports = {
197
272
  project,
198
273
  projectGetUsage,
@@ -201,4 +276,4 @@ module.exports = {
201
276
  projectGetVariable,
202
277
  projectUpdateVariable,
203
278
  projectDeleteVariable
204
- };
279
+ };