@scaleway/sdk-jobs 2.1.1 → 2.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.
@@ -0,0 +1,275 @@
1
+ import randomName from "@scaleway/random-name";
2
+ import { resolveOneOf, isJSONObject, unmarshalDate, unmarshalArrayOfObject } from "@scaleway/sdk-client";
3
+ const unmarshalSecretEnvVar = (data) => {
4
+ if (!isJSONObject(data)) {
5
+ throw new TypeError(
6
+ `Unmarshalling the type 'SecretEnvVar' failed as data isn't a dictionary.`
7
+ );
8
+ }
9
+ return {
10
+ name: data.name
11
+ };
12
+ };
13
+ const unmarshalSecretFile = (data) => {
14
+ if (!isJSONObject(data)) {
15
+ throw new TypeError(
16
+ `Unmarshalling the type 'SecretFile' failed as data isn't a dictionary.`
17
+ );
18
+ }
19
+ return {
20
+ path: data.path
21
+ };
22
+ };
23
+ const unmarshalSecret = (data) => {
24
+ if (!isJSONObject(data)) {
25
+ throw new TypeError(
26
+ `Unmarshalling the type 'Secret' failed as data isn't a dictionary.`
27
+ );
28
+ }
29
+ return {
30
+ envVar: data.env_var ? unmarshalSecretEnvVar(data.env_var) : void 0,
31
+ file: data.file ? unmarshalSecretFile(data.file) : void 0,
32
+ jobDefinitionId: data.job_definition_id,
33
+ secretId: data.secret_id,
34
+ secretManagerId: data.secret_manager_id,
35
+ secretManagerVersion: data.secret_manager_version
36
+ };
37
+ };
38
+ const unmarshalCronSchedule = (data) => {
39
+ if (!isJSONObject(data)) {
40
+ throw new TypeError(
41
+ `Unmarshalling the type 'CronSchedule' failed as data isn't a dictionary.`
42
+ );
43
+ }
44
+ return {
45
+ schedule: data.schedule,
46
+ timezone: data.timezone
47
+ };
48
+ };
49
+ const unmarshalJobDefinition = (data) => {
50
+ if (!isJSONObject(data)) {
51
+ throw new TypeError(
52
+ `Unmarshalling the type 'JobDefinition' failed as data isn't a dictionary.`
53
+ );
54
+ }
55
+ return {
56
+ args: data.args,
57
+ command: data.command,
58
+ cpuLimit: data.cpu_limit,
59
+ createdAt: unmarshalDate(data.created_at),
60
+ cronSchedule: data.cron_schedule ? unmarshalCronSchedule(data.cron_schedule) : void 0,
61
+ description: data.description,
62
+ environmentVariables: data.environment_variables,
63
+ id: data.id,
64
+ imageUri: data.image_uri,
65
+ jobTimeout: data.job_timeout,
66
+ localStorageCapacity: data.local_storage_capacity,
67
+ memoryLimit: data.memory_limit,
68
+ name: data.name,
69
+ projectId: data.project_id,
70
+ region: data.region,
71
+ startupCommand: data.startup_command,
72
+ updatedAt: unmarshalDate(data.updated_at)
73
+ };
74
+ };
75
+ const unmarshalJobRun = (data) => {
76
+ if (!isJSONObject(data)) {
77
+ throw new TypeError(
78
+ `Unmarshalling the type 'JobRun' failed as data isn't a dictionary.`
79
+ );
80
+ }
81
+ return {
82
+ args: data.args,
83
+ command: data.command,
84
+ cpuLimit: data.cpu_limit,
85
+ createdAt: unmarshalDate(data.created_at),
86
+ environmentVariables: data.environment_variables,
87
+ errorMessage: data.error_message,
88
+ exitCode: data.exit_code,
89
+ id: data.id,
90
+ jobDefinitionId: data.job_definition_id,
91
+ localStorageCapacity: data.local_storage_capacity,
92
+ memoryLimit: data.memory_limit,
93
+ reason: data.reason ? data.reason : void 0,
94
+ region: data.region,
95
+ runDuration: data.run_duration,
96
+ startedAt: unmarshalDate(data.started_at),
97
+ startupCommand: data.startup_command,
98
+ state: data.state,
99
+ terminatedAt: unmarshalDate(data.terminated_at),
100
+ updatedAt: unmarshalDate(data.updated_at)
101
+ };
102
+ };
103
+ const unmarshalCreateSecretsResponse = (data) => {
104
+ if (!isJSONObject(data)) {
105
+ throw new TypeError(
106
+ `Unmarshalling the type 'CreateSecretsResponse' failed as data isn't a dictionary.`
107
+ );
108
+ }
109
+ return {
110
+ secrets: unmarshalArrayOfObject(data.secrets, unmarshalSecret)
111
+ };
112
+ };
113
+ const unmarshalJobLimits = (data) => {
114
+ if (!isJSONObject(data)) {
115
+ throw new TypeError(
116
+ `Unmarshalling the type 'JobLimits' failed as data isn't a dictionary.`
117
+ );
118
+ }
119
+ return {
120
+ secretsPerJobDefinition: data.secrets_per_job_definition
121
+ };
122
+ };
123
+ const unmarshalListJobDefinitionsResponse = (data) => {
124
+ if (!isJSONObject(data)) {
125
+ throw new TypeError(
126
+ `Unmarshalling the type 'ListJobDefinitionsResponse' failed as data isn't a dictionary.`
127
+ );
128
+ }
129
+ return {
130
+ jobDefinitions: unmarshalArrayOfObject(
131
+ data.job_definitions,
132
+ unmarshalJobDefinition
133
+ ),
134
+ totalCount: data.total_count
135
+ };
136
+ };
137
+ const unmarshalResource = (data) => {
138
+ if (!isJSONObject(data)) {
139
+ throw new TypeError(
140
+ `Unmarshalling the type 'Resource' failed as data isn't a dictionary.`
141
+ );
142
+ }
143
+ return {
144
+ computeLimitMvcpu: data.compute_limit_mvcpu,
145
+ memoryLimitBytes: data.memory_limit_bytes
146
+ };
147
+ };
148
+ const unmarshalListJobResourcesResponse = (data) => {
149
+ if (!isJSONObject(data)) {
150
+ throw new TypeError(
151
+ `Unmarshalling the type 'ListJobResourcesResponse' failed as data isn't a dictionary.`
152
+ );
153
+ }
154
+ return {
155
+ resources: unmarshalArrayOfObject(data.resources, unmarshalResource)
156
+ };
157
+ };
158
+ const unmarshalListJobRunsResponse = (data) => {
159
+ if (!isJSONObject(data)) {
160
+ throw new TypeError(
161
+ `Unmarshalling the type 'ListJobRunsResponse' failed as data isn't a dictionary.`
162
+ );
163
+ }
164
+ return {
165
+ jobRuns: unmarshalArrayOfObject(data.job_runs, unmarshalJobRun),
166
+ totalCount: data.total_count
167
+ };
168
+ };
169
+ const unmarshalListSecretsResponse = (data) => {
170
+ if (!isJSONObject(data)) {
171
+ throw new TypeError(
172
+ `Unmarshalling the type 'ListSecretsResponse' failed as data isn't a dictionary.`
173
+ );
174
+ }
175
+ return {
176
+ secrets: unmarshalArrayOfObject(data.secrets, unmarshalSecret),
177
+ totalCount: data.total_count
178
+ };
179
+ };
180
+ const unmarshalStartJobDefinitionResponse = (data) => {
181
+ if (!isJSONObject(data)) {
182
+ throw new TypeError(
183
+ `Unmarshalling the type 'StartJobDefinitionResponse' failed as data isn't a dictionary.`
184
+ );
185
+ }
186
+ return {
187
+ jobRuns: unmarshalArrayOfObject(data.job_runs, unmarshalJobRun)
188
+ };
189
+ };
190
+ const marshalCreateJobDefinitionRequestCronScheduleConfig = (request, defaults) => ({
191
+ schedule: request.schedule,
192
+ timezone: request.timezone
193
+ });
194
+ const marshalCreateJobDefinitionRequest = (request, defaults) => ({
195
+ args: request.args,
196
+ command: request.command,
197
+ cpu_limit: request.cpuLimit,
198
+ cron_schedule: request.cronSchedule !== void 0 ? marshalCreateJobDefinitionRequestCronScheduleConfig(
199
+ request.cronSchedule
200
+ ) : void 0,
201
+ description: request.description,
202
+ environment_variables: request.environmentVariables !== void 0 ? request.environmentVariables : void 0,
203
+ image_uri: request.imageUri,
204
+ job_timeout: request.jobTimeout,
205
+ local_storage_capacity: request.localStorageCapacity,
206
+ memory_limit: request.memoryLimit,
207
+ name: request.name || randomName("job"),
208
+ project_id: request.projectId ?? defaults.defaultProjectId,
209
+ startup_command: request.startupCommand
210
+ });
211
+ const marshalCreateSecretsRequestSecretConfig = (request, defaults) => ({
212
+ secret_manager_id: request.secretManagerId,
213
+ secret_manager_version: request.secretManagerVersion,
214
+ ...resolveOneOf([
215
+ { param: "path", value: request.path },
216
+ { param: "env_var_name", value: request.envVarName }
217
+ ])
218
+ });
219
+ const marshalCreateSecretsRequest = (request, defaults) => ({
220
+ job_definition_id: request.jobDefinitionId,
221
+ secrets: request.secrets.map(
222
+ (elt) => marshalCreateSecretsRequestSecretConfig(elt)
223
+ )
224
+ });
225
+ const marshalStartJobDefinitionRequest = (request, defaults) => ({
226
+ args: request.args,
227
+ command: request.command,
228
+ environment_variables: request.environmentVariables,
229
+ replicas: request.replicas,
230
+ startup_command: request.startupCommand
231
+ });
232
+ const marshalUpdateJobDefinitionRequestCronScheduleConfig = (request, defaults) => ({
233
+ schedule: request.schedule,
234
+ timezone: request.timezone
235
+ });
236
+ const marshalUpdateJobDefinitionRequest = (request, defaults) => ({
237
+ args: request.args,
238
+ command: request.command,
239
+ cpu_limit: request.cpuLimit,
240
+ cron_schedule: request.cronSchedule !== void 0 ? marshalUpdateJobDefinitionRequestCronScheduleConfig(
241
+ request.cronSchedule
242
+ ) : void 0,
243
+ description: request.description,
244
+ environment_variables: request.environmentVariables,
245
+ image_uri: request.imageUri,
246
+ job_timeout: request.jobTimeout,
247
+ local_storage_capacity: request.localStorageCapacity,
248
+ memory_limit: request.memoryLimit,
249
+ name: request.name,
250
+ startup_command: request.startupCommand
251
+ });
252
+ const marshalUpdateSecretRequest = (request, defaults) => ({
253
+ secret_manager_version: request.secretManagerVersion,
254
+ ...resolveOneOf([
255
+ { param: "path", value: request.path },
256
+ { param: "env_var_name", value: request.envVarName }
257
+ ])
258
+ });
259
+ export {
260
+ marshalCreateJobDefinitionRequest,
261
+ marshalCreateSecretsRequest,
262
+ marshalStartJobDefinitionRequest,
263
+ marshalUpdateJobDefinitionRequest,
264
+ marshalUpdateSecretRequest,
265
+ unmarshalCreateSecretsResponse,
266
+ unmarshalJobDefinition,
267
+ unmarshalJobLimits,
268
+ unmarshalJobRun,
269
+ unmarshalListJobDefinitionsResponse,
270
+ unmarshalListJobResourcesResponse,
271
+ unmarshalListJobRunsResponse,
272
+ unmarshalListSecretsResponse,
273
+ unmarshalSecret,
274
+ unmarshalStartJobDefinitionResponse
275
+ };