@scaleway/sdk-function 1.2.0

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.
@@ -0,0 +1,470 @@
1
+ import randomName from "@scaleway/random-name";
2
+ import { resolveOneOf, isJSONObject, unmarshalDate, unmarshalArrayOfObject } from "@scaleway/sdk-client";
3
+ const unmarshalCron = (data) => {
4
+ if (!isJSONObject(data)) {
5
+ throw new TypeError(
6
+ `Unmarshalling the type 'Cron' failed as data isn't a dictionary.`
7
+ );
8
+ }
9
+ return {
10
+ args: data.args,
11
+ functionId: data.function_id,
12
+ id: data.id,
13
+ name: data.name,
14
+ schedule: data.schedule,
15
+ status: data.status
16
+ };
17
+ };
18
+ const unmarshalDomain = (data) => {
19
+ if (!isJSONObject(data)) {
20
+ throw new TypeError(
21
+ `Unmarshalling the type 'Domain' failed as data isn't a dictionary.`
22
+ );
23
+ }
24
+ return {
25
+ errorMessage: data.error_message,
26
+ functionId: data.function_id,
27
+ hostname: data.hostname,
28
+ id: data.id,
29
+ status: data.status,
30
+ url: data.url
31
+ };
32
+ };
33
+ const unmarshalSecretHashedValue = (data) => {
34
+ if (!isJSONObject(data)) {
35
+ throw new TypeError(
36
+ `Unmarshalling the type 'SecretHashedValue' failed as data isn't a dictionary.`
37
+ );
38
+ }
39
+ return {
40
+ hashedValue: data.hashed_value,
41
+ key: data.key
42
+ };
43
+ };
44
+ const unmarshalFunction = (data) => {
45
+ if (!isJSONObject(data)) {
46
+ throw new TypeError(
47
+ `Unmarshalling the type 'Function' failed as data isn't a dictionary.`
48
+ );
49
+ }
50
+ return {
51
+ buildMessage: data.build_message,
52
+ cpuLimit: data.cpu_limit,
53
+ createdAt: unmarshalDate(data.created_at),
54
+ description: data.description,
55
+ domainName: data.domain_name,
56
+ environmentVariables: data.environment_variables,
57
+ errorMessage: data.error_message,
58
+ handler: data.handler,
59
+ httpOption: data.http_option,
60
+ id: data.id,
61
+ maxScale: data.max_scale,
62
+ memoryLimit: data.memory_limit,
63
+ minScale: data.min_scale,
64
+ name: data.name,
65
+ namespaceId: data.namespace_id,
66
+ privacy: data.privacy,
67
+ readyAt: unmarshalDate(data.ready_at),
68
+ region: data.region,
69
+ runtime: data.runtime,
70
+ runtimeMessage: data.runtime_message,
71
+ sandbox: data.sandbox,
72
+ secretEnvironmentVariables: unmarshalArrayOfObject(
73
+ data.secret_environment_variables,
74
+ unmarshalSecretHashedValue
75
+ ),
76
+ status: data.status,
77
+ tags: data.tags,
78
+ timeout: data.timeout,
79
+ updatedAt: unmarshalDate(data.updated_at)
80
+ };
81
+ };
82
+ const unmarshalNamespace = (data) => {
83
+ if (!isJSONObject(data)) {
84
+ throw new TypeError(
85
+ `Unmarshalling the type 'Namespace' failed as data isn't a dictionary.`
86
+ );
87
+ }
88
+ return {
89
+ createdAt: unmarshalDate(data.created_at),
90
+ description: data.description,
91
+ environmentVariables: data.environment_variables,
92
+ errorMessage: data.error_message,
93
+ id: data.id,
94
+ name: data.name,
95
+ organizationId: data.organization_id,
96
+ projectId: data.project_id,
97
+ region: data.region,
98
+ registryEndpoint: data.registry_endpoint,
99
+ registryNamespaceId: data.registry_namespace_id,
100
+ secretEnvironmentVariables: unmarshalArrayOfObject(
101
+ data.secret_environment_variables,
102
+ unmarshalSecretHashedValue
103
+ ),
104
+ status: data.status,
105
+ tags: data.tags,
106
+ updatedAt: unmarshalDate(data.updated_at)
107
+ };
108
+ };
109
+ const unmarshalToken = (data) => {
110
+ if (!isJSONObject(data)) {
111
+ throw new TypeError(
112
+ `Unmarshalling the type 'Token' failed as data isn't a dictionary.`
113
+ );
114
+ }
115
+ return {
116
+ description: data.description,
117
+ expiresAt: unmarshalDate(data.expires_at),
118
+ functionId: data.function_id,
119
+ id: data.id,
120
+ namespaceId: data.namespace_id,
121
+ publicKey: data.public_key,
122
+ status: data.status,
123
+ token: data.token
124
+ };
125
+ };
126
+ const unmarshalTriggerMnqNatsClientConfig = (data) => {
127
+ if (!isJSONObject(data)) {
128
+ throw new TypeError(
129
+ `Unmarshalling the type 'TriggerMnqNatsClientConfig' failed as data isn't a dictionary.`
130
+ );
131
+ }
132
+ return {
133
+ mnqCredentialId: data.mnq_credential_id,
134
+ mnqNatsAccountId: data.mnq_nats_account_id,
135
+ mnqProjectId: data.mnq_project_id,
136
+ mnqRegion: data.mnq_region,
137
+ subject: data.subject
138
+ };
139
+ };
140
+ const unmarshalTriggerMnqSqsClientConfig = (data) => {
141
+ if (!isJSONObject(data)) {
142
+ throw new TypeError(
143
+ `Unmarshalling the type 'TriggerMnqSqsClientConfig' failed as data isn't a dictionary.`
144
+ );
145
+ }
146
+ return {
147
+ mnqCredentialId: data.mnq_credential_id,
148
+ mnqProjectId: data.mnq_project_id,
149
+ mnqRegion: data.mnq_region,
150
+ queue: data.queue
151
+ };
152
+ };
153
+ const unmarshalTriggerSqsClientConfig = (data) => {
154
+ if (!isJSONObject(data)) {
155
+ throw new TypeError(
156
+ `Unmarshalling the type 'TriggerSqsClientConfig' failed as data isn't a dictionary.`
157
+ );
158
+ }
159
+ return {
160
+ accessKey: data.access_key,
161
+ endpoint: data.endpoint,
162
+ queueUrl: data.queue_url,
163
+ secretKey: data.secret_key
164
+ };
165
+ };
166
+ const unmarshalTrigger = (data) => {
167
+ if (!isJSONObject(data)) {
168
+ throw new TypeError(
169
+ `Unmarshalling the type 'Trigger' failed as data isn't a dictionary.`
170
+ );
171
+ }
172
+ return {
173
+ description: data.description,
174
+ errorMessage: data.error_message,
175
+ functionId: data.function_id,
176
+ id: data.id,
177
+ inputType: data.input_type,
178
+ name: data.name,
179
+ scwNatsConfig: data.scw_nats_config ? unmarshalTriggerMnqNatsClientConfig(data.scw_nats_config) : void 0,
180
+ scwSqsConfig: data.scw_sqs_config ? unmarshalTriggerMnqSqsClientConfig(data.scw_sqs_config) : void 0,
181
+ sqsConfig: data.sqs_config ? unmarshalTriggerSqsClientConfig(data.sqs_config) : void 0,
182
+ status: data.status
183
+ };
184
+ };
185
+ const unmarshalDownloadURL = (data) => {
186
+ if (!isJSONObject(data)) {
187
+ throw new TypeError(
188
+ `Unmarshalling the type 'DownloadURL' failed as data isn't a dictionary.`
189
+ );
190
+ }
191
+ return {
192
+ headers: data.headers,
193
+ url: data.url
194
+ };
195
+ };
196
+ const unmarshalListCronsResponse = (data) => {
197
+ if (!isJSONObject(data)) {
198
+ throw new TypeError(
199
+ `Unmarshalling the type 'ListCronsResponse' failed as data isn't a dictionary.`
200
+ );
201
+ }
202
+ return {
203
+ crons: unmarshalArrayOfObject(data.crons, unmarshalCron),
204
+ totalCount: data.total_count
205
+ };
206
+ };
207
+ const unmarshalListDomainsResponse = (data) => {
208
+ if (!isJSONObject(data)) {
209
+ throw new TypeError(
210
+ `Unmarshalling the type 'ListDomainsResponse' failed as data isn't a dictionary.`
211
+ );
212
+ }
213
+ return {
214
+ domains: unmarshalArrayOfObject(data.domains, unmarshalDomain),
215
+ totalCount: data.total_count
216
+ };
217
+ };
218
+ const unmarshalRuntime = (data) => {
219
+ if (!isJSONObject(data)) {
220
+ throw new TypeError(
221
+ `Unmarshalling the type 'Runtime' failed as data isn't a dictionary.`
222
+ );
223
+ }
224
+ return {
225
+ codeSample: data.code_sample,
226
+ defaultHandler: data.default_handler,
227
+ extension: data.extension,
228
+ implementation: data.implementation,
229
+ language: data.language,
230
+ logoUrl: data.logo_url,
231
+ name: data.name,
232
+ status: data.status,
233
+ statusMessage: data.status_message,
234
+ version: data.version
235
+ };
236
+ };
237
+ const unmarshalListFunctionRuntimesResponse = (data) => {
238
+ if (!isJSONObject(data)) {
239
+ throw new TypeError(
240
+ `Unmarshalling the type 'ListFunctionRuntimesResponse' failed as data isn't a dictionary.`
241
+ );
242
+ }
243
+ return {
244
+ runtimes: unmarshalArrayOfObject(data.runtimes, unmarshalRuntime),
245
+ totalCount: data.total_count
246
+ };
247
+ };
248
+ const unmarshalListFunctionsResponse = (data) => {
249
+ if (!isJSONObject(data)) {
250
+ throw new TypeError(
251
+ `Unmarshalling the type 'ListFunctionsResponse' failed as data isn't a dictionary.`
252
+ );
253
+ }
254
+ return {
255
+ functions: unmarshalArrayOfObject(data.functions, unmarshalFunction),
256
+ totalCount: data.total_count
257
+ };
258
+ };
259
+ const unmarshalListNamespacesResponse = (data) => {
260
+ if (!isJSONObject(data)) {
261
+ throw new TypeError(
262
+ `Unmarshalling the type 'ListNamespacesResponse' failed as data isn't a dictionary.`
263
+ );
264
+ }
265
+ return {
266
+ namespaces: unmarshalArrayOfObject(data.namespaces, unmarshalNamespace),
267
+ totalCount: data.total_count
268
+ };
269
+ };
270
+ const unmarshalListTokensResponse = (data) => {
271
+ if (!isJSONObject(data)) {
272
+ throw new TypeError(
273
+ `Unmarshalling the type 'ListTokensResponse' failed as data isn't a dictionary.`
274
+ );
275
+ }
276
+ return {
277
+ tokens: unmarshalArrayOfObject(data.tokens, unmarshalToken),
278
+ totalCount: data.total_count
279
+ };
280
+ };
281
+ const unmarshalListTriggersResponse = (data) => {
282
+ if (!isJSONObject(data)) {
283
+ throw new TypeError(
284
+ `Unmarshalling the type 'ListTriggersResponse' failed as data isn't a dictionary.`
285
+ );
286
+ }
287
+ return {
288
+ totalCount: data.total_count,
289
+ triggers: unmarshalArrayOfObject(data.triggers, unmarshalTrigger)
290
+ };
291
+ };
292
+ const unmarshalUploadURL = (data) => {
293
+ if (!isJSONObject(data)) {
294
+ throw new TypeError(
295
+ `Unmarshalling the type 'UploadURL' failed as data isn't a dictionary.`
296
+ );
297
+ }
298
+ return {
299
+ headers: data.headers,
300
+ url: data.url
301
+ };
302
+ };
303
+ const marshalCreateCronRequest = (request, defaults) => ({
304
+ args: request.args,
305
+ function_id: request.functionId,
306
+ name: request.name,
307
+ schedule: request.schedule
308
+ });
309
+ const marshalCreateDomainRequest = (request, defaults) => ({
310
+ function_id: request.functionId,
311
+ hostname: request.hostname
312
+ });
313
+ const marshalSecret = (request, defaults) => ({
314
+ key: request.key,
315
+ value: request.value
316
+ });
317
+ const marshalCreateFunctionRequest = (request, defaults) => ({
318
+ description: request.description,
319
+ environment_variables: request.environmentVariables,
320
+ handler: request.handler,
321
+ http_option: request.httpOption,
322
+ max_scale: request.maxScale,
323
+ memory_limit: request.memoryLimit,
324
+ min_scale: request.minScale,
325
+ name: request.name || randomName("fn"),
326
+ namespace_id: request.namespaceId,
327
+ privacy: request.privacy,
328
+ runtime: request.runtime,
329
+ sandbox: request.sandbox,
330
+ secret_environment_variables: request.secretEnvironmentVariables !== void 0 ? request.secretEnvironmentVariables.map(
331
+ (elt) => marshalSecret(elt)
332
+ ) : void 0,
333
+ tags: request.tags,
334
+ timeout: request.timeout
335
+ });
336
+ const marshalCreateNamespaceRequest = (request, defaults) => ({
337
+ description: request.description,
338
+ environment_variables: request.environmentVariables,
339
+ name: request.name || randomName("ns"),
340
+ project_id: request.projectId ?? defaults.defaultProjectId,
341
+ secret_environment_variables: request.secretEnvironmentVariables !== void 0 ? request.secretEnvironmentVariables.map(
342
+ (elt) => marshalSecret(elt)
343
+ ) : void 0,
344
+ tags: request.tags
345
+ });
346
+ const marshalCreateTokenRequest = (request, defaults) => ({
347
+ description: request.description,
348
+ expires_at: request.expiresAt,
349
+ ...resolveOneOf([
350
+ { param: "function_id", value: request.functionId },
351
+ { param: "namespace_id", value: request.namespaceId }
352
+ ])
353
+ });
354
+ const marshalCreateTriggerRequestMnqNatsClientConfig = (request, defaults) => ({
355
+ mnq_nats_account_id: request.mnqNatsAccountId,
356
+ mnq_project_id: request.mnqProjectId,
357
+ mnq_region: request.mnqRegion,
358
+ subject: request.subject
359
+ });
360
+ const marshalCreateTriggerRequestMnqSqsClientConfig = (request, defaults) => ({
361
+ mnq_project_id: request.mnqProjectId,
362
+ mnq_region: request.mnqRegion,
363
+ queue: request.queue
364
+ });
365
+ const marshalCreateTriggerRequestSqsClientConfig = (request, defaults) => ({
366
+ access_key: request.accessKey,
367
+ endpoint: request.endpoint,
368
+ queue_url: request.queueUrl,
369
+ secret_key: request.secretKey
370
+ });
371
+ const marshalCreateTriggerRequest = (request, defaults) => ({
372
+ description: request.description,
373
+ function_id: request.functionId,
374
+ name: request.name,
375
+ ...resolveOneOf([
376
+ {
377
+ param: "scw_sqs_config",
378
+ value: request.scwSqsConfig !== void 0 ? marshalCreateTriggerRequestMnqSqsClientConfig(
379
+ request.scwSqsConfig
380
+ ) : void 0
381
+ },
382
+ {
383
+ param: "scw_nats_config",
384
+ value: request.scwNatsConfig !== void 0 ? marshalCreateTriggerRequestMnqNatsClientConfig(
385
+ request.scwNatsConfig
386
+ ) : void 0
387
+ },
388
+ {
389
+ param: "sqs_config",
390
+ value: request.sqsConfig !== void 0 ? marshalCreateTriggerRequestSqsClientConfig(
391
+ request.sqsConfig
392
+ ) : void 0
393
+ }
394
+ ])
395
+ });
396
+ const marshalUpdateCronRequest = (request, defaults) => ({
397
+ args: request.args,
398
+ function_id: request.functionId,
399
+ name: request.name,
400
+ schedule: request.schedule
401
+ });
402
+ const marshalUpdateFunctionRequest = (request, defaults) => ({
403
+ description: request.description,
404
+ environment_variables: request.environmentVariables,
405
+ handler: request.handler,
406
+ http_option: request.httpOption,
407
+ max_scale: request.maxScale,
408
+ memory_limit: request.memoryLimit,
409
+ min_scale: request.minScale,
410
+ privacy: request.privacy,
411
+ redeploy: request.redeploy,
412
+ runtime: request.runtime,
413
+ sandbox: request.sandbox,
414
+ secret_environment_variables: request.secretEnvironmentVariables !== void 0 ? request.secretEnvironmentVariables.map(
415
+ (elt) => marshalSecret(elt)
416
+ ) : void 0,
417
+ tags: request.tags,
418
+ timeout: request.timeout
419
+ });
420
+ const marshalUpdateNamespaceRequest = (request, defaults) => ({
421
+ description: request.description,
422
+ environment_variables: request.environmentVariables,
423
+ secret_environment_variables: request.secretEnvironmentVariables !== void 0 ? request.secretEnvironmentVariables.map(
424
+ (elt) => marshalSecret(elt)
425
+ ) : void 0,
426
+ tags: request.tags
427
+ });
428
+ const marshalUpdateTriggerRequestSqsClientConfig = (request, defaults) => ({
429
+ access_key: request.accessKey,
430
+ secret_key: request.secretKey
431
+ });
432
+ const marshalUpdateTriggerRequest = (request, defaults) => ({
433
+ description: request.description,
434
+ name: request.name,
435
+ ...resolveOneOf([
436
+ {
437
+ param: "sqs_config",
438
+ value: request.sqsConfig !== void 0 ? marshalUpdateTriggerRequestSqsClientConfig(
439
+ request.sqsConfig
440
+ ) : void 0
441
+ }
442
+ ])
443
+ });
444
+ export {
445
+ marshalCreateCronRequest,
446
+ marshalCreateDomainRequest,
447
+ marshalCreateFunctionRequest,
448
+ marshalCreateNamespaceRequest,
449
+ marshalCreateTokenRequest,
450
+ marshalCreateTriggerRequest,
451
+ marshalUpdateCronRequest,
452
+ marshalUpdateFunctionRequest,
453
+ marshalUpdateNamespaceRequest,
454
+ marshalUpdateTriggerRequest,
455
+ unmarshalCron,
456
+ unmarshalDomain,
457
+ unmarshalDownloadURL,
458
+ unmarshalFunction,
459
+ unmarshalListCronsResponse,
460
+ unmarshalListDomainsResponse,
461
+ unmarshalListFunctionRuntimesResponse,
462
+ unmarshalListFunctionsResponse,
463
+ unmarshalListNamespacesResponse,
464
+ unmarshalListTokensResponse,
465
+ unmarshalListTriggersResponse,
466
+ unmarshalNamespace,
467
+ unmarshalToken,
468
+ unmarshalTrigger,
469
+ unmarshalUploadURL
470
+ };