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