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