appwrite-cli 4.2.0 → 4.2.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.
@@ -9,429 +9,491 @@ 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 functions = new Command("functions").description(commandDescriptions['functions']).configureHelp({
14
39
  helpWidth: process.stdout.columns || 80
15
40
  })
16
41
 
42
+ /**
43
+ * @typedef {Object} FunctionsListRequestParams
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/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, enabled, runtime, deployment, schedule, scheduleNext, schedulePrevious, timeout, entrypoint, commands, installationId
45
+ * @property {string} search Search term to filter your list results. Max length: 256 chars.
46
+ * @property {boolean} parseOutput
47
+ * @property {libClient | undefined} sdk
48
+ */
49
+
50
+ /**
51
+ * @param {FunctionsListRequestParams} params
52
+ */
17
53
  const functionsList = async ({ queries, search, parseOutput = true, sdk = undefined}) => {
18
- /* @param {string[]} queries */
19
- /* @param {string} search */
20
-
21
54
  let client = !sdk ? await sdkForProject() : sdk;
55
+
22
56
  let apiPath = '/functions';
23
57
  let payload = {};
24
-
25
- /** Query Params */
26
58
  if (typeof queries !== 'undefined') {
27
59
  payload['queries'] = queries;
28
60
  }
29
61
  if (typeof search !== 'undefined') {
30
62
  payload['search'] = search;
31
63
  }
64
+
65
+
32
66
  let response = undefined;
67
+
33
68
  response = await client.call('get', apiPath, {
34
69
  'content-type': 'application/json',
35
70
  }, payload);
71
+
36
72
 
37
73
  if (parseOutput) {
38
74
  parse(response)
39
75
  success()
40
76
  }
77
+
41
78
  return response;
42
79
  }
43
80
 
81
+ /**
82
+ * @typedef {Object} FunctionsCreateRequestParams
83
+ * @property {string} functionId Function ID. Choose a custom ID or generate a random ID with 'ID.unique()'. 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.
84
+ * @property {string} name Function name. Max length: 128 chars.
85
+ * @property {string} runtime Execution runtime.
86
+ * @property {string[]} execute An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long.
87
+ * @property {string[]} events Events list. Maximum of 100 events are allowed.
88
+ * @property {string} schedule Schedule CRON syntax.
89
+ * @property {number} timeout Function maximum execution time in seconds.
90
+ * @property {boolean} enabled Is function enabled? When set to 'disabled', users cannot access the function but Server SDKs with and API key can still access the function. No data is lost when this is toggled.
91
+ * @property {boolean} logging Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project.
92
+ * @property {string} entrypoint Entrypoint File. This path is relative to the "providerRootDirectory".
93
+ * @property {string} commands Build Commands.
94
+ * @property {string} installationId Appwrite Installation ID for VCS (Version Control System) deployment.
95
+ * @property {string} providerRepositoryId Repository ID of the repo linked to the function.
96
+ * @property {string} providerBranch Production branch for the repo linked to the function.
97
+ * @property {boolean} providerSilentMode Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.
98
+ * @property {string} providerRootDirectory Path to function code in the linked repo.
99
+ * @property {string} templateRepository Repository name of the template.
100
+ * @property {string} templateOwner The name of the owner of the template.
101
+ * @property {string} templateRootDirectory Path to function code in the template repo.
102
+ * @property {string} templateBranch Production branch for the repo linked to the function template.
103
+ * @property {boolean} parseOutput
104
+ * @property {libClient | undefined} sdk
105
+ */
106
+
107
+ /**
108
+ * @param {FunctionsCreateRequestParams} params
109
+ */
44
110
  const functionsCreate = async ({ functionId, name, runtime, execute, events, schedule, timeout, enabled, logging, entrypoint, commands, installationId, providerRepositoryId, providerBranch, providerSilentMode, providerRootDirectory, templateRepository, templateOwner, templateRootDirectory, templateBranch, parseOutput = true, sdk = undefined}) => {
45
- /* @param {string} functionId */
46
- /* @param {string} name */
47
- /* @param {string} runtime */
48
- /* @param {string[]} execute */
49
- /* @param {string[]} events */
50
- /* @param {string} schedule */
51
- /* @param {number} timeout */
52
- /* @param {boolean} enabled */
53
- /* @param {boolean} logging */
54
- /* @param {string} entrypoint */
55
- /* @param {string} commands */
56
- /* @param {string} installationId */
57
- /* @param {string} providerRepositoryId */
58
- /* @param {string} providerBranch */
59
- /* @param {boolean} providerSilentMode */
60
- /* @param {string} providerRootDirectory */
61
- /* @param {string} templateRepository */
62
- /* @param {string} templateOwner */
63
- /* @param {string} templateRootDirectory */
64
- /* @param {string} templateBranch */
65
-
66
111
  let client = !sdk ? await sdkForProject() : sdk;
112
+
67
113
  let apiPath = '/functions';
68
114
  let payload = {};
69
-
70
- /** Body Params */
71
-
72
115
  if (typeof functionId !== 'undefined') {
73
116
  payload['functionId'] = functionId;
74
117
  }
75
-
76
-
77
118
  if (typeof name !== 'undefined') {
78
119
  payload['name'] = name;
79
120
  }
80
-
81
-
82
121
  if (typeof runtime !== 'undefined') {
83
122
  payload['runtime'] = runtime;
84
123
  }
85
-
86
124
  execute = execute === true ? [] : execute;
87
-
88
125
  if (typeof execute !== 'undefined') {
89
126
  payload['execute'] = execute;
90
127
  }
91
-
92
128
  events = events === true ? [] : events;
93
-
94
129
  if (typeof events !== 'undefined') {
95
130
  payload['events'] = events;
96
131
  }
97
-
98
-
99
132
  if (typeof schedule !== 'undefined') {
100
133
  payload['schedule'] = schedule;
101
134
  }
102
-
103
-
104
135
  if (typeof timeout !== 'undefined') {
105
136
  payload['timeout'] = timeout;
106
137
  }
107
-
108
-
109
138
  if (typeof enabled !== 'undefined') {
110
139
  payload['enabled'] = enabled;
111
140
  }
112
-
113
-
114
141
  if (typeof logging !== 'undefined') {
115
142
  payload['logging'] = logging;
116
143
  }
117
-
118
-
119
144
  if (typeof entrypoint !== 'undefined') {
120
145
  payload['entrypoint'] = entrypoint;
121
146
  }
122
-
123
-
124
147
  if (typeof commands !== 'undefined') {
125
148
  payload['commands'] = commands;
126
149
  }
127
-
128
-
129
150
  if (typeof installationId !== 'undefined') {
130
151
  payload['installationId'] = installationId;
131
152
  }
132
-
133
-
134
153
  if (typeof providerRepositoryId !== 'undefined') {
135
154
  payload['providerRepositoryId'] = providerRepositoryId;
136
155
  }
137
-
138
-
139
156
  if (typeof providerBranch !== 'undefined') {
140
157
  payload['providerBranch'] = providerBranch;
141
158
  }
142
-
143
-
144
159
  if (typeof providerSilentMode !== 'undefined') {
145
160
  payload['providerSilentMode'] = providerSilentMode;
146
161
  }
147
-
148
-
149
162
  if (typeof providerRootDirectory !== 'undefined') {
150
163
  payload['providerRootDirectory'] = providerRootDirectory;
151
164
  }
152
-
153
-
154
165
  if (typeof templateRepository !== 'undefined') {
155
166
  payload['templateRepository'] = templateRepository;
156
167
  }
157
-
158
-
159
168
  if (typeof templateOwner !== 'undefined') {
160
169
  payload['templateOwner'] = templateOwner;
161
170
  }
162
-
163
-
164
171
  if (typeof templateRootDirectory !== 'undefined') {
165
172
  payload['templateRootDirectory'] = templateRootDirectory;
166
173
  }
167
-
168
-
169
174
  if (typeof templateBranch !== 'undefined') {
170
175
  payload['templateBranch'] = templateBranch;
171
176
  }
172
177
 
178
+
173
179
  let response = undefined;
180
+
174
181
  response = await client.call('post', apiPath, {
175
182
  'content-type': 'application/json',
176
183
  }, payload);
184
+
177
185
 
178
186
  if (parseOutput) {
179
187
  parse(response)
180
188
  success()
181
189
  }
190
+
182
191
  return response;
183
192
  }
184
193
 
185
- const functionsListRuntimes = async ({ parseOutput = true, sdk = undefined}) => {
194
+ /**
195
+ * @typedef {Object} FunctionsListRuntimesRequestParams
196
+ * @property {boolean} parseOutput
197
+ * @property {libClient | undefined} sdk
198
+ */
186
199
 
200
+ /**
201
+ * @param {FunctionsListRuntimesRequestParams} params
202
+ */
203
+ const functionsListRuntimes = async ({ parseOutput = true, sdk = undefined}) => {
187
204
  let client = !sdk ? await sdkForProject() : sdk;
205
+
188
206
  let apiPath = '/functions/runtimes';
189
207
  let payload = {};
208
+
209
+
190
210
  let response = undefined;
211
+
191
212
  response = await client.call('get', apiPath, {
192
213
  'content-type': 'application/json',
193
214
  }, payload);
215
+
194
216
 
195
217
  if (parseOutput) {
196
218
  parse(response)
197
219
  success()
198
220
  }
221
+
199
222
  return response;
200
223
  }
201
224
 
202
- const functionsGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => {
203
- /* @param {string} range */
225
+ /**
226
+ * @typedef {Object} FunctionsGetUsageRequestParams
227
+ * @property {string} range Date range.
228
+ * @property {boolean} parseOutput
229
+ * @property {libClient | undefined} sdk
230
+ */
204
231
 
232
+ /**
233
+ * @param {FunctionsGetUsageRequestParams} params
234
+ */
235
+ const functionsGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => {
205
236
  let client = !sdk ? await sdkForProject() : sdk;
237
+
206
238
  let apiPath = '/functions/usage';
207
239
  let payload = {};
208
-
209
- /** Query Params */
210
240
  if (typeof range !== 'undefined') {
211
241
  payload['range'] = range;
212
242
  }
243
+
244
+
213
245
  let response = undefined;
246
+
214
247
  response = await client.call('get', apiPath, {
215
248
  'content-type': 'application/json',
216
249
  }, payload);
250
+
217
251
 
218
252
  if (parseOutput) {
219
253
  parse(response)
220
254
  success()
221
255
  }
256
+
222
257
  return response;
223
258
  }
224
259
 
225
- const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined}) => {
226
- /* @param {string} functionId */
260
+ /**
261
+ * @typedef {Object} FunctionsGetRequestParams
262
+ * @property {string} functionId Function ID.
263
+ * @property {boolean} parseOutput
264
+ * @property {libClient | undefined} sdk
265
+ */
227
266
 
267
+ /**
268
+ * @param {FunctionsGetRequestParams} params
269
+ */
270
+ const functionsGet = async ({ functionId, parseOutput = true, sdk = undefined}) => {
228
271
  let client = !sdk ? await sdkForProject() : sdk;
272
+
229
273
  let apiPath = '/functions/{functionId}'.replace('{functionId}', functionId);
230
274
  let payload = {};
275
+
276
+
231
277
  let response = undefined;
278
+
232
279
  response = await client.call('get', apiPath, {
233
280
  'content-type': 'application/json',
234
281
  }, payload);
282
+
235
283
 
236
284
  if (parseOutput) {
237
285
  parse(response)
238
286
  success()
239
287
  }
288
+
240
289
  return response;
241
290
  }
242
291
 
292
+ /**
293
+ * @typedef {Object} FunctionsUpdateRequestParams
294
+ * @property {string} functionId Function ID.
295
+ * @property {string} name Function name. Max length: 128 chars.
296
+ * @property {string} runtime Execution runtime.
297
+ * @property {string[]} execute An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long.
298
+ * @property {string[]} events Events list. Maximum of 100 events are allowed.
299
+ * @property {string} schedule Schedule CRON syntax.
300
+ * @property {number} timeout Maximum execution time in seconds.
301
+ * @property {boolean} enabled Is function enabled? When set to 'disabled', users cannot access the function but Server SDKs with and API key can still access the function. No data is lost when this is toggled.
302
+ * @property {boolean} logging Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project.
303
+ * @property {string} entrypoint Entrypoint File. This path is relative to the "providerRootDirectory".
304
+ * @property {string} commands Build Commands.
305
+ * @property {string} installationId Appwrite Installation ID for VCS (Version Controle System) deployment.
306
+ * @property {string} providerRepositoryId Repository ID of the repo linked to the function
307
+ * @property {string} providerBranch Production branch for the repo linked to the function
308
+ * @property {boolean} providerSilentMode Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.
309
+ * @property {string} providerRootDirectory Path to function code in the linked repo.
310
+ * @property {boolean} parseOutput
311
+ * @property {libClient | undefined} sdk
312
+ */
313
+
314
+ /**
315
+ * @param {FunctionsUpdateRequestParams} params
316
+ */
243
317
  const functionsUpdate = async ({ functionId, name, runtime, execute, events, schedule, timeout, enabled, logging, entrypoint, commands, installationId, providerRepositoryId, providerBranch, providerSilentMode, providerRootDirectory, parseOutput = true, sdk = undefined}) => {
244
- /* @param {string} functionId */
245
- /* @param {string} name */
246
- /* @param {string} runtime */
247
- /* @param {string[]} execute */
248
- /* @param {string[]} events */
249
- /* @param {string} schedule */
250
- /* @param {number} timeout */
251
- /* @param {boolean} enabled */
252
- /* @param {boolean} logging */
253
- /* @param {string} entrypoint */
254
- /* @param {string} commands */
255
- /* @param {string} installationId */
256
- /* @param {string} providerRepositoryId */
257
- /* @param {string} providerBranch */
258
- /* @param {boolean} providerSilentMode */
259
- /* @param {string} providerRootDirectory */
260
-
261
318
  let client = !sdk ? await sdkForProject() : sdk;
319
+
262
320
  let apiPath = '/functions/{functionId}'.replace('{functionId}', functionId);
263
321
  let payload = {};
264
-
265
- /** Body Params */
266
-
267
322
  if (typeof name !== 'undefined') {
268
323
  payload['name'] = name;
269
324
  }
270
-
271
-
272
325
  if (typeof runtime !== 'undefined') {
273
326
  payload['runtime'] = runtime;
274
327
  }
275
-
276
328
  execute = execute === true ? [] : execute;
277
-
278
329
  if (typeof execute !== 'undefined') {
279
330
  payload['execute'] = execute;
280
331
  }
281
-
282
332
  events = events === true ? [] : events;
283
-
284
333
  if (typeof events !== 'undefined') {
285
334
  payload['events'] = events;
286
335
  }
287
-
288
-
289
336
  if (typeof schedule !== 'undefined') {
290
337
  payload['schedule'] = schedule;
291
338
  }
292
-
293
-
294
339
  if (typeof timeout !== 'undefined') {
295
340
  payload['timeout'] = timeout;
296
341
  }
297
-
298
-
299
342
  if (typeof enabled !== 'undefined') {
300
343
  payload['enabled'] = enabled;
301
344
  }
302
-
303
-
304
345
  if (typeof logging !== 'undefined') {
305
346
  payload['logging'] = logging;
306
347
  }
307
-
308
-
309
348
  if (typeof entrypoint !== 'undefined') {
310
349
  payload['entrypoint'] = entrypoint;
311
350
  }
312
-
313
-
314
351
  if (typeof commands !== 'undefined') {
315
352
  payload['commands'] = commands;
316
353
  }
317
-
318
-
319
354
  if (typeof installationId !== 'undefined') {
320
355
  payload['installationId'] = installationId;
321
356
  }
322
-
323
-
324
357
  if (typeof providerRepositoryId !== 'undefined') {
325
358
  payload['providerRepositoryId'] = providerRepositoryId;
326
359
  }
327
-
328
-
329
360
  if (typeof providerBranch !== 'undefined') {
330
361
  payload['providerBranch'] = providerBranch;
331
362
  }
332
-
333
-
334
363
  if (typeof providerSilentMode !== 'undefined') {
335
364
  payload['providerSilentMode'] = providerSilentMode;
336
365
  }
337
-
338
-
339
366
  if (typeof providerRootDirectory !== 'undefined') {
340
367
  payload['providerRootDirectory'] = providerRootDirectory;
341
368
  }
342
369
 
370
+
343
371
  let response = undefined;
372
+
344
373
  response = await client.call('put', apiPath, {
345
374
  'content-type': 'application/json',
346
375
  }, payload);
376
+
347
377
 
348
378
  if (parseOutput) {
349
379
  parse(response)
350
380
  success()
351
381
  }
382
+
352
383
  return response;
353
384
  }
354
385
 
355
- const functionsDelete = async ({ functionId, parseOutput = true, sdk = undefined}) => {
356
- /* @param {string} functionId */
386
+ /**
387
+ * @typedef {Object} FunctionsDeleteRequestParams
388
+ * @property {string} functionId Function ID.
389
+ * @property {boolean} parseOutput
390
+ * @property {libClient | undefined} sdk
391
+ */
357
392
 
393
+ /**
394
+ * @param {FunctionsDeleteRequestParams} params
395
+ */
396
+ const functionsDelete = async ({ functionId, parseOutput = true, sdk = undefined}) => {
358
397
  let client = !sdk ? await sdkForProject() : sdk;
398
+
359
399
  let apiPath = '/functions/{functionId}'.replace('{functionId}', functionId);
360
400
  let payload = {};
401
+
402
+
361
403
  let response = undefined;
404
+
362
405
  response = await client.call('delete', apiPath, {
363
406
  'content-type': 'application/json',
364
407
  }, payload);
408
+
365
409
 
366
410
  if (parseOutput) {
367
411
  parse(response)
368
412
  success()
369
413
  }
414
+
370
415
  return response;
371
416
  }
372
417
 
418
+ /**
419
+ * @typedef {Object} FunctionsListDeploymentsRequestParams
420
+ * @property {string} functionId Function ID.
421
+ * @property {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: size, buildId, activate, entrypoint, commands
422
+ * @property {string} search Search term to filter your list results. Max length: 256 chars.
423
+ * @property {boolean} parseOutput
424
+ * @property {libClient | undefined} sdk
425
+ */
426
+
427
+ /**
428
+ * @param {FunctionsListDeploymentsRequestParams} params
429
+ */
373
430
  const functionsListDeployments = async ({ functionId, queries, search, parseOutput = true, sdk = undefined}) => {
374
- /* @param {string} functionId */
375
- /* @param {string[]} queries */
376
- /* @param {string} search */
377
-
378
431
  let client = !sdk ? await sdkForProject() : sdk;
432
+
379
433
  let apiPath = '/functions/{functionId}/deployments'.replace('{functionId}', functionId);
380
434
  let payload = {};
381
-
382
- /** Query Params */
383
435
  if (typeof queries !== 'undefined') {
384
436
  payload['queries'] = queries;
385
437
  }
386
438
  if (typeof search !== 'undefined') {
387
439
  payload['search'] = search;
388
440
  }
441
+
442
+
389
443
  let response = undefined;
444
+
390
445
  response = await client.call('get', apiPath, {
391
446
  'content-type': 'application/json',
392
447
  }, payload);
448
+
393
449
 
394
450
  if (parseOutput) {
395
451
  parse(response)
396
452
  success()
397
453
  }
454
+
398
455
  return response;
399
456
  }
400
457
 
458
+ /**
459
+ * @typedef {Object} FunctionsCreateDeploymentRequestParams
460
+ * @property {string} functionId Function ID.
461
+ * @property {string} code Gzip file with your code package. When used with the Appwrite CLI, pass the path to your code directory, and the CLI will automatically package your code. Use a path that is within the current directory.
462
+ * @property {boolean} activate Automatically activate the deployment when it is finished building.
463
+ * @property {string} entrypoint Entrypoint File.
464
+ * @property {string} commands Build Commands.
465
+ * @property {boolean} parseOutput
466
+ * @property {libClient | undefined} sdk
467
+ * @property {CallableFunction} onProgress
468
+ */
469
+
470
+ /**
471
+ * @param {FunctionsCreateDeploymentRequestParams} params
472
+ */
401
473
  const functionsCreateDeployment = async ({ functionId, code, activate, entrypoint, commands, parseOutput = true, sdk = undefined, onProgress = () => {}}) => {
402
- /* @param {string} functionId */
403
- /* @param {InputFile} code */
404
- /* @param {boolean} activate */
405
- /* @param {string} entrypoint */
406
- /* @param {string} commands */
407
-
408
474
  let client = !sdk ? await sdkForProject() : sdk;
475
+
409
476
  let apiPath = '/functions/{functionId}/deployments'.replace('{functionId}', functionId);
410
477
  let payload = {};
411
-
412
- /** Body Params */
413
-
414
478
  if (typeof entrypoint !== 'undefined') {
415
479
  payload['entrypoint'] = entrypoint;
416
480
  }
417
-
418
-
419
481
  if (typeof commands !== 'undefined') {
420
482
  payload['commands'] = commands;
421
483
  }
422
-
423
- let folderPath = fs.realpathSync(code);
424
- if (!fs.lstatSync(folderPath).isDirectory())
484
+ const folderPath = fs.realpathSync(code);
485
+ if (!fs.lstatSync(folderPath).isDirectory()) {
425
486
  throw new Error('The path is not a directory.');
487
+ }
426
488
 
427
489
  const ignorer = ignore();
428
490
 
429
491
  const func = localConfig.getFunction(functionId);
430
492
 
431
- if(func.ignore) {
493
+ if (func.ignore) {
432
494
  ignorer.add(func.ignore);
433
495
  log('Ignoring files using configuration from appwrite.json');
434
- } else if(fs.existsSync(pathLib.join(code, '.gitignore'))) {
496
+ } else if (fs.existsSync(pathLib.join(code, '.gitignore'))) {
435
497
  ignorer.add(fs.readFileSync(pathLib.join(code, '.gitignore')).toString());
436
498
  log('Ignoring files in .gitignore');
437
499
  }
@@ -445,414 +507,622 @@ const functionsCreateDeployment = async ({ functionId, code, activate, entrypoin
445
507
  cwd: folderPath,
446
508
  file: 'code.tar.gz'
447
509
  }, files);
448
- let archivePath = fs.realpathSync('code.tar.gz')
449
- if (typeof archivePath !== 'undefined') {
450
- payload['code'] = archivePath;
451
- code = archivePath;
452
- }
453
510
 
511
+ const filePath = fs.realpathSync(code);
512
+ const nodeStream = fs.createReadStream(filePath);
513
+ const stream = convertReadStreamToReadableStream(nodeStream);
454
514
 
515
+ if (typeof filePath !== 'undefined') {
516
+ code = { type: 'file', stream, filename: pathLib.basename(filePath), size: fs.statSync(filePath).size };
517
+ payload['code'] = code
518
+ }
455
519
  if (typeof activate !== 'undefined') {
456
- payload['activate'] = activate.toString();
520
+ payload['activate'] = activate;
457
521
  }
458
522
 
523
+
524
+
525
+ const size = code.size;
526
+
527
+ const apiHeaders = {
528
+ 'content-type': 'multipart/form-data',
529
+ };
530
+
531
+ let id = undefined;
459
532
  let response = undefined;
460
- const { size: size } = await promisify(fs.stat)(code);
461
533
 
462
- if (size <= libClient.CHUNK_SIZE) {
463
- payload['code'] = fs.createReadStream(payload['code']);
534
+ let chunksUploaded = 0;
464
535
 
465
- response = await client.call('post', apiPath, {
466
- 'content-type': 'multipart/form-data',
467
- }, payload).catch(err => {
468
- fs.unlinkSync(archivePath);
469
- throw err
470
- });
471
- } else {
472
- const streamFilePath = payload['code'];
536
+ let currentChunk = 1;
537
+ let currentPosition = 0;
538
+ let uploadableChunk = new Uint8Array(client.CHUNK_SIZE);
473
539
 
474
- const apiHeaders = {
475
- 'content-type': 'multipart/form-data',
476
- };
540
+ const uploadChunk = async (lastUpload = false) => {
541
+ if(currentChunk <= chunksUploaded) {
542
+ return;
543
+ }
477
544
 
478
- let offset = 0;
545
+ const start = ((currentChunk - 1) * client.CHUNK_SIZE);
546
+ let end = start + currentPosition - 1;
479
547
 
480
- while (offset < size) {
481
- let end = Math.min(offset + libClient.CHUNK_SIZE - 1, size - 1);
548
+ if(!lastUpload || currentChunk !== 1) {
549
+ apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
550
+ }
482
551
 
483
- apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
484
- if (response && response.$id) {
485
- apiHeaders['x-appwrite-id'] = response.$id;
552
+ let uploadableChunkTrimmed;
553
+
554
+ if(currentPosition + 1 >= client.CHUNK_SIZE) {
555
+ uploadableChunkTrimmed = uploadableChunk;
556
+ } else {
557
+ uploadableChunkTrimmed = new Uint8Array(currentPosition);
558
+ for(let i = 0; i <= currentPosition; i++) {
559
+ uploadableChunkTrimmed[i] = uploadableChunk[i];
486
560
  }
561
+ }
562
+
563
+ if (id) {
564
+ apiHeaders['x-appwrite-id'] = id;
565
+ }
566
+
567
+ payload['code'] = { type: 'file', file: new File([uploadableChunkTrimmed], code.filename), filename: code.filename };
487
568
 
488
- const stream = fs.createReadStream(streamFilePath, {
489
- start: offset,
490
- end
569
+ response = await client.call('post', apiPath, apiHeaders, payload);
570
+
571
+ if (!id) {
572
+ id = response['$id'];
573
+ }
574
+
575
+ if (onProgress !== null) {
576
+ onProgress({
577
+ $id: response['$id'],
578
+ progress: Math.min((currentChunk) * client.CHUNK_SIZE, size) / size * 100,
579
+ sizeUploaded: end+1,
580
+ chunksTotal: response['chunksTotal'],
581
+ chunksUploaded: response['chunksUploaded']
491
582
  });
492
- payload['code'] = stream;
493
- response = await client.call('post', apiPath, apiHeaders, payload);
494
-
495
- if (onProgress) {
496
- onProgress({
497
- $id: response.$id,
498
- progress: ( offset / size ) * 100,
499
- sizeUploaded: offset,
500
- chunksTotal: response.chunksTotal,
501
- chunksUploaded: response.chunksUploaded
502
- });
583
+ }
584
+
585
+ uploadableChunk = new Uint8Array(client.CHUNK_SIZE);
586
+ currentChunk++;
587
+ currentPosition = 0;
588
+ }
589
+
590
+ for await (const chunk of code.stream) {
591
+ for(const b of chunk) {
592
+ uploadableChunk[currentPosition] = b;
593
+
594
+ currentPosition++;
595
+ if(currentPosition >= client.CHUNK_SIZE) {
596
+ await uploadChunk();
597
+ currentPosition = 0;
503
598
  }
504
- offset += libClient.CHUNK_SIZE;
505
599
  }
506
600
  }
507
601
 
508
- fs.unlinkSync(archivePath);
509
-
602
+ if (currentPosition > 0) { // Check if there's any remaining data for the last chunk
603
+ await uploadChunk(true);
604
+ }
605
+
606
+ fs.unlinkSync(filePath);
607
+
510
608
  if (parseOutput) {
511
609
  parse(response)
512
610
  success()
513
611
  }
612
+
514
613
  return response;
614
+
515
615
  }
516
616
 
617
+ /**
618
+ * @typedef {Object} FunctionsGetDeploymentRequestParams
619
+ * @property {string} functionId Function ID.
620
+ * @property {string} deploymentId Deployment ID.
621
+ * @property {boolean} parseOutput
622
+ * @property {libClient | undefined} sdk
623
+ */
624
+
625
+ /**
626
+ * @param {FunctionsGetDeploymentRequestParams} params
627
+ */
517
628
  const functionsGetDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined}) => {
518
- /* @param {string} functionId */
519
- /* @param {string} deploymentId */
520
-
521
629
  let client = !sdk ? await sdkForProject() : sdk;
630
+
522
631
  let apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId);
523
632
  let payload = {};
633
+
634
+
524
635
  let response = undefined;
636
+
525
637
  response = await client.call('get', apiPath, {
526
638
  'content-type': 'application/json',
527
639
  }, payload);
640
+
528
641
 
529
642
  if (parseOutput) {
530
643
  parse(response)
531
644
  success()
532
645
  }
646
+
533
647
  return response;
534
648
  }
535
649
 
650
+ /**
651
+ * @typedef {Object} FunctionsUpdateDeploymentRequestParams
652
+ * @property {string} functionId Function ID.
653
+ * @property {string} deploymentId Deployment ID.
654
+ * @property {boolean} parseOutput
655
+ * @property {libClient | undefined} sdk
656
+ */
657
+
658
+ /**
659
+ * @param {FunctionsUpdateDeploymentRequestParams} params
660
+ */
536
661
  const functionsUpdateDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined}) => {
537
- /* @param {string} functionId */
538
- /* @param {string} deploymentId */
539
-
540
662
  let client = !sdk ? await sdkForProject() : sdk;
663
+
541
664
  let apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId);
542
665
  let payload = {};
666
+
667
+
543
668
  let response = undefined;
669
+
544
670
  response = await client.call('patch', apiPath, {
545
671
  'content-type': 'application/json',
546
672
  }, payload);
673
+
547
674
 
548
675
  if (parseOutput) {
549
676
  parse(response)
550
677
  success()
551
678
  }
679
+
552
680
  return response;
553
681
  }
554
682
 
683
+ /**
684
+ * @typedef {Object} FunctionsDeleteDeploymentRequestParams
685
+ * @property {string} functionId Function ID.
686
+ * @property {string} deploymentId Deployment ID.
687
+ * @property {boolean} parseOutput
688
+ * @property {libClient | undefined} sdk
689
+ */
690
+
691
+ /**
692
+ * @param {FunctionsDeleteDeploymentRequestParams} params
693
+ */
555
694
  const functionsDeleteDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined}) => {
556
- /* @param {string} functionId */
557
- /* @param {string} deploymentId */
558
-
559
695
  let client = !sdk ? await sdkForProject() : sdk;
696
+
560
697
  let apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId);
561
698
  let payload = {};
699
+
700
+
562
701
  let response = undefined;
702
+
563
703
  response = await client.call('delete', apiPath, {
564
704
  'content-type': 'application/json',
565
705
  }, payload);
706
+
566
707
 
567
708
  if (parseOutput) {
568
709
  parse(response)
569
710
  success()
570
711
  }
712
+
571
713
  return response;
572
714
  }
573
715
 
716
+ /**
717
+ * @typedef {Object} FunctionsCreateBuildRequestParams
718
+ * @property {string} functionId Function ID.
719
+ * @property {string} deploymentId Deployment ID.
720
+ * @property {string} buildId Build unique ID.
721
+ * @property {boolean} parseOutput
722
+ * @property {libClient | undefined} sdk
723
+ */
724
+
725
+ /**
726
+ * @param {FunctionsCreateBuildRequestParams} params
727
+ */
574
728
  const functionsCreateBuild = async ({ functionId, deploymentId, buildId, parseOutput = true, sdk = undefined}) => {
575
- /* @param {string} functionId */
576
- /* @param {string} deploymentId */
577
- /* @param {string} buildId */
578
-
579
729
  let client = !sdk ? await sdkForProject() : sdk;
730
+
580
731
  let apiPath = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId).replace('{buildId}', buildId);
581
732
  let payload = {};
733
+
734
+
582
735
  let response = undefined;
736
+
583
737
  response = await client.call('post', apiPath, {
584
738
  'content-type': 'application/json',
585
739
  }, payload);
740
+
586
741
 
587
742
  if (parseOutput) {
588
743
  parse(response)
589
744
  success()
590
745
  }
746
+
591
747
  return response;
592
748
  }
593
749
 
750
+ /**
751
+ * @typedef {Object} FunctionsDownloadDeploymentRequestParams
752
+ * @property {string} functionId Function ID.
753
+ * @property {string} deploymentId Deployment ID.
754
+ * @property {boolean} parseOutput
755
+ * @property {libClient | undefined} sdk
756
+ * @property {string} destination
757
+ */
758
+
759
+ /**
760
+ * @param {FunctionsDownloadDeploymentRequestParams} params
761
+ */
594
762
  const functionsDownloadDeployment = async ({ functionId, deploymentId, parseOutput = true, sdk = undefined, destination}) => {
595
- /* @param {string} functionId */
596
- /* @param {string} deploymentId */
597
-
598
763
  let client = !sdk ? await sdkForProject() : sdk;
764
+
599
765
  let apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId);
600
766
  let payload = {};
767
+
601
768
  payload['project'] = localConfig.getProject().projectId
602
769
  payload['key'] = globalConfig.getKey();
603
770
  const queryParams = new URLSearchParams(payload);
604
771
  apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
605
772
 
606
- const response = await client.call('get', apiPath, {
773
+ let response = undefined;
774
+
775
+ response = await client.call('get', apiPath, {
607
776
  'content-type': 'application/json',
608
777
  }, payload, 'arraybuffer');
609
778
 
610
779
  fs.writeFileSync(destination, response);
611
-
612
- if (parseOutput) {
613
- log(`File stored in ${destination}`)
780
+
781
+ if (parseOutput) {
782
+ parse(response)
614
783
  success()
615
784
  }
785
+
786
+ return response;
616
787
  }
617
788
 
789
+ /**
790
+ * @typedef {Object} FunctionsListExecutionsRequestParams
791
+ * @property {string} functionId Function ID.
792
+ * @property {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: trigger, status, responseStatusCode, duration
793
+ * @property {string} search Search term to filter your list results. Max length: 256 chars.
794
+ * @property {boolean} parseOutput
795
+ * @property {libClient | undefined} sdk
796
+ */
797
+
798
+ /**
799
+ * @param {FunctionsListExecutionsRequestParams} params
800
+ */
618
801
  const functionsListExecutions = async ({ functionId, queries, search, parseOutput = true, sdk = undefined}) => {
619
- /* @param {string} functionId */
620
- /* @param {string[]} queries */
621
- /* @param {string} search */
622
-
623
802
  let client = !sdk ? await sdkForProject() : sdk;
803
+
624
804
  let apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
625
805
  let payload = {};
626
-
627
- /** Query Params */
628
806
  if (typeof queries !== 'undefined') {
629
807
  payload['queries'] = queries;
630
808
  }
631
809
  if (typeof search !== 'undefined') {
632
810
  payload['search'] = search;
633
811
  }
812
+
813
+
634
814
  let response = undefined;
815
+
635
816
  response = await client.call('get', apiPath, {
636
817
  'content-type': 'application/json',
637
818
  }, payload);
819
+
638
820
 
639
821
  if (parseOutput) {
640
822
  parse(response)
641
823
  success()
642
824
  }
825
+
643
826
  return response;
644
827
  }
645
828
 
829
+ /**
830
+ * @typedef {Object} FunctionsCreateExecutionRequestParams
831
+ * @property {string} functionId Function ID.
832
+ * @property {string} body HTTP body of execution. Default value is empty string.
833
+ * @property {boolean} async Execute code in the background. Default value is false.
834
+ * @property {string} xpath HTTP path of execution. Path can include query params. Default value is /
835
+ * @property {string} method HTTP method of execution. Default value is GET.
836
+ * @property {object} headers HTTP headers of execution. Defaults to empty.
837
+ * @property {boolean} parseOutput
838
+ * @property {libClient | undefined} sdk
839
+ */
840
+
841
+ /**
842
+ * @param {FunctionsCreateExecutionRequestParams} params
843
+ */
646
844
  const functionsCreateExecution = async ({ functionId, body, async, xpath, method, headers, parseOutput = true, sdk = undefined}) => {
647
- /* @param {string} functionId */
648
- /* @param {string} body */
649
- /* @param {boolean} async */
650
- /* @param {string} xpath */
651
- /* @param {string} method */
652
- /* @param {object} headers */
653
-
654
845
  let client = !sdk ? await sdkForProject() : sdk;
846
+
655
847
  let apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
656
848
  let payload = {};
657
-
658
- /** Body Params */
659
-
660
849
  if (typeof body !== 'undefined') {
661
850
  payload['body'] = body;
662
851
  }
663
-
664
-
665
852
  if (typeof async !== 'undefined') {
666
853
  payload['async'] = async;
667
854
  }
668
-
669
-
670
855
  if (typeof xpath !== 'undefined') {
671
856
  payload['path'] = xpath;
672
857
  }
673
-
674
-
675
858
  if (typeof method !== 'undefined') {
676
859
  payload['method'] = method;
677
860
  }
678
-
679
861
  if (typeof headers !== 'undefined') {
680
862
  payload['headers'] = JSON.parse(headers);
681
863
  }
682
864
 
865
+
683
866
  let response = undefined;
867
+
684
868
  response = await client.call('post', apiPath, {
685
869
  'content-type': 'application/json',
686
870
  }, payload);
871
+
687
872
 
688
873
  if (parseOutput) {
689
874
  parse(response)
690
875
  success()
691
876
  }
877
+
692
878
  return response;
693
879
  }
694
880
 
881
+ /**
882
+ * @typedef {Object} FunctionsGetExecutionRequestParams
883
+ * @property {string} functionId Function ID.
884
+ * @property {string} executionId Execution ID.
885
+ * @property {boolean} parseOutput
886
+ * @property {libClient | undefined} sdk
887
+ */
888
+
889
+ /**
890
+ * @param {FunctionsGetExecutionRequestParams} params
891
+ */
695
892
  const functionsGetExecution = async ({ functionId, executionId, parseOutput = true, sdk = undefined}) => {
696
- /* @param {string} functionId */
697
- /* @param {string} executionId */
698
-
699
893
  let client = !sdk ? await sdkForProject() : sdk;
894
+
700
895
  let apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId);
701
896
  let payload = {};
897
+
898
+
702
899
  let response = undefined;
900
+
703
901
  response = await client.call('get', apiPath, {
704
902
  'content-type': 'application/json',
705
903
  }, payload);
904
+
706
905
 
707
906
  if (parseOutput) {
708
907
  parse(response)
709
908
  success()
710
909
  }
910
+
711
911
  return response;
712
912
  }
713
913
 
914
+ /**
915
+ * @typedef {Object} FunctionsGetFunctionUsageRequestParams
916
+ * @property {string} functionId Function ID.
917
+ * @property {string} range Date range.
918
+ * @property {boolean} parseOutput
919
+ * @property {libClient | undefined} sdk
920
+ */
921
+
922
+ /**
923
+ * @param {FunctionsGetFunctionUsageRequestParams} params
924
+ */
714
925
  const functionsGetFunctionUsage = async ({ functionId, range, parseOutput = true, sdk = undefined}) => {
715
- /* @param {string} functionId */
716
- /* @param {string} range */
717
-
718
926
  let client = !sdk ? await sdkForProject() : sdk;
927
+
719
928
  let apiPath = '/functions/{functionId}/usage'.replace('{functionId}', functionId);
720
929
  let payload = {};
721
-
722
- /** Query Params */
723
930
  if (typeof range !== 'undefined') {
724
931
  payload['range'] = range;
725
932
  }
933
+
934
+
726
935
  let response = undefined;
936
+
727
937
  response = await client.call('get', apiPath, {
728
938
  'content-type': 'application/json',
729
939
  }, payload);
940
+
730
941
 
731
942
  if (parseOutput) {
732
943
  parse(response)
733
944
  success()
734
945
  }
946
+
735
947
  return response;
736
948
  }
737
949
 
738
- const functionsListVariables = async ({ functionId, parseOutput = true, sdk = undefined}) => {
739
- /* @param {string} functionId */
950
+ /**
951
+ * @typedef {Object} FunctionsListVariablesRequestParams
952
+ * @property {string} functionId Function unique ID.
953
+ * @property {boolean} parseOutput
954
+ * @property {libClient | undefined} sdk
955
+ */
740
956
 
957
+ /**
958
+ * @param {FunctionsListVariablesRequestParams} params
959
+ */
960
+ const functionsListVariables = async ({ functionId, parseOutput = true, sdk = undefined}) => {
741
961
  let client = !sdk ? await sdkForProject() : sdk;
962
+
742
963
  let apiPath = '/functions/{functionId}/variables'.replace('{functionId}', functionId);
743
964
  let payload = {};
965
+
966
+
744
967
  let response = undefined;
968
+
745
969
  response = await client.call('get', apiPath, {
746
970
  'content-type': 'application/json',
747
971
  }, payload);
972
+
748
973
 
749
974
  if (parseOutput) {
750
975
  parse(response)
751
976
  success()
752
977
  }
978
+
753
979
  return response;
754
980
  }
755
981
 
982
+ /**
983
+ * @typedef {Object} FunctionsCreateVariableRequestParams
984
+ * @property {string} functionId Function unique ID.
985
+ * @property {string} key Variable key. Max length: 255 chars.
986
+ * @property {string} value Variable value. Max length: 8192 chars.
987
+ * @property {boolean} parseOutput
988
+ * @property {libClient | undefined} sdk
989
+ */
990
+
991
+ /**
992
+ * @param {FunctionsCreateVariableRequestParams} params
993
+ */
756
994
  const functionsCreateVariable = async ({ functionId, key, value, parseOutput = true, sdk = undefined}) => {
757
- /* @param {string} functionId */
758
- /* @param {string} key */
759
- /* @param {string} value */
760
-
761
995
  let client = !sdk ? await sdkForProject() : sdk;
996
+
762
997
  let apiPath = '/functions/{functionId}/variables'.replace('{functionId}', functionId);
763
998
  let payload = {};
764
-
765
- /** Body Params */
766
-
767
999
  if (typeof key !== 'undefined') {
768
1000
  payload['key'] = key;
769
1001
  }
770
-
771
-
772
1002
  if (typeof value !== 'undefined') {
773
1003
  payload['value'] = value;
774
1004
  }
775
1005
 
1006
+
776
1007
  let response = undefined;
1008
+
777
1009
  response = await client.call('post', apiPath, {
778
1010
  'content-type': 'application/json',
779
1011
  }, payload);
1012
+
780
1013
 
781
1014
  if (parseOutput) {
782
1015
  parse(response)
783
1016
  success()
784
1017
  }
1018
+
785
1019
  return response;
786
1020
  }
787
1021
 
1022
+ /**
1023
+ * @typedef {Object} FunctionsGetVariableRequestParams
1024
+ * @property {string} functionId Function unique ID.
1025
+ * @property {string} variableId Variable unique ID.
1026
+ * @property {boolean} parseOutput
1027
+ * @property {libClient | undefined} sdk
1028
+ */
1029
+
1030
+ /**
1031
+ * @param {FunctionsGetVariableRequestParams} params
1032
+ */
788
1033
  const functionsGetVariable = async ({ functionId, variableId, parseOutput = true, sdk = undefined}) => {
789
- /* @param {string} functionId */
790
- /* @param {string} variableId */
791
-
792
1034
  let client = !sdk ? await sdkForProject() : sdk;
1035
+
793
1036
  let apiPath = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId);
794
1037
  let payload = {};
1038
+
1039
+
795
1040
  let response = undefined;
1041
+
796
1042
  response = await client.call('get', apiPath, {
797
1043
  'content-type': 'application/json',
798
1044
  }, payload);
1045
+
799
1046
 
800
1047
  if (parseOutput) {
801
1048
  parse(response)
802
1049
  success()
803
1050
  }
1051
+
804
1052
  return response;
805
1053
  }
806
1054
 
1055
+ /**
1056
+ * @typedef {Object} FunctionsUpdateVariableRequestParams
1057
+ * @property {string} functionId Function unique ID.
1058
+ * @property {string} variableId Variable unique ID.
1059
+ * @property {string} key Variable key. Max length: 255 chars.
1060
+ * @property {string} value Variable value. Max length: 8192 chars.
1061
+ * @property {boolean} parseOutput
1062
+ * @property {libClient | undefined} sdk
1063
+ */
1064
+
1065
+ /**
1066
+ * @param {FunctionsUpdateVariableRequestParams} params
1067
+ */
807
1068
  const functionsUpdateVariable = async ({ functionId, variableId, key, value, parseOutput = true, sdk = undefined}) => {
808
- /* @param {string} functionId */
809
- /* @param {string} variableId */
810
- /* @param {string} key */
811
- /* @param {string} value */
812
-
813
1069
  let client = !sdk ? await sdkForProject() : sdk;
1070
+
814
1071
  let apiPath = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId);
815
1072
  let payload = {};
816
-
817
- /** Body Params */
818
-
819
1073
  if (typeof key !== 'undefined') {
820
1074
  payload['key'] = key;
821
1075
  }
822
-
823
-
824
1076
  if (typeof value !== 'undefined') {
825
1077
  payload['value'] = value;
826
1078
  }
827
1079
 
1080
+
828
1081
  let response = undefined;
1082
+
829
1083
  response = await client.call('put', apiPath, {
830
1084
  'content-type': 'application/json',
831
1085
  }, payload);
1086
+
832
1087
 
833
1088
  if (parseOutput) {
834
1089
  parse(response)
835
1090
  success()
836
1091
  }
1092
+
837
1093
  return response;
838
1094
  }
839
1095
 
1096
+ /**
1097
+ * @typedef {Object} FunctionsDeleteVariableRequestParams
1098
+ * @property {string} functionId Function unique ID.
1099
+ * @property {string} variableId Variable unique ID.
1100
+ * @property {boolean} parseOutput
1101
+ * @property {libClient | undefined} sdk
1102
+ */
1103
+
1104
+ /**
1105
+ * @param {FunctionsDeleteVariableRequestParams} params
1106
+ */
840
1107
  const functionsDeleteVariable = async ({ functionId, variableId, parseOutput = true, sdk = undefined}) => {
841
- /* @param {string} functionId */
842
- /* @param {string} variableId */
843
-
844
1108
  let client = !sdk ? await sdkForProject() : sdk;
1109
+
845
1110
  let apiPath = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId);
846
1111
  let payload = {};
1112
+
1113
+
847
1114
  let response = undefined;
1115
+
848
1116
  response = await client.call('delete', apiPath, {
849
1117
  'content-type': 'application/json',
850
1118
  }, payload);
1119
+
851
1120
 
852
1121
  if (parseOutput) {
853
1122
  parse(response)
854
1123
  success()
855
1124
  }
1125
+
856
1126
  return response;
857
1127
  }
858
1128
 
@@ -1061,27 +1331,27 @@ functions
1061
1331
 
1062
1332
  module.exports = {
1063
1333
  functions,
1064
- functionsList,
1065
- functionsCreate,
1066
- functionsListRuntimes,
1067
- functionsGetUsage,
1068
- functionsGet,
1069
- functionsUpdate,
1070
- functionsDelete,
1071
- functionsListDeployments,
1072
- functionsCreateDeployment,
1073
- functionsGetDeployment,
1074
- functionsUpdateDeployment,
1075
- functionsDeleteDeployment,
1076
- functionsCreateBuild,
1077
- functionsDownloadDeployment,
1078
- functionsListExecutions,
1079
- functionsCreateExecution,
1080
- functionsGetExecution,
1081
- functionsGetFunctionUsage,
1082
- functionsListVariables,
1083
- functionsCreateVariable,
1084
- functionsGetVariable,
1085
- functionsUpdateVariable,
1086
- functionsDeleteVariable
1087
- };
1334
+ functionsList,
1335
+ functionsCreate,
1336
+ functionsListRuntimes,
1337
+ functionsGetUsage,
1338
+ functionsGet,
1339
+ functionsUpdate,
1340
+ functionsDelete,
1341
+ functionsListDeployments,
1342
+ functionsCreateDeployment,
1343
+ functionsGetDeployment,
1344
+ functionsUpdateDeployment,
1345
+ functionsDeleteDeployment,
1346
+ functionsCreateBuild,
1347
+ functionsDownloadDeployment,
1348
+ functionsListExecutions,
1349
+ functionsCreateExecution,
1350
+ functionsGetExecution,
1351
+ functionsGetFunctionUsage,
1352
+ functionsListVariables,
1353
+ functionsCreateVariable,
1354
+ functionsGetVariable,
1355
+ functionsUpdateVariable,
1356
+ functionsDeleteVariable
1357
+ };