Skip to content

Commit 97e1175

Browse files
authored
feat(serverless_jobs): generate SDKs (#974)
1 parent 886419d commit 97e1175

File tree

6 files changed

+585
-0
lines changed

6 files changed

+585
-0
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
API as ParentAPI,
5+
enrichForPagination,
6+
unmarshalServiceInfo,
7+
urlParams,
8+
validatePathParam,
9+
} from '../../../bridge'
10+
import type { Region, ServiceInfo } from '../../../bridge'
11+
import {
12+
marshalCreateJobDefinitionRequest,
13+
marshalUpdateJobDefinitionRequest,
14+
unmarshalJobDefinition,
15+
unmarshalJobRun,
16+
unmarshalListJobDefinitionsResponse,
17+
unmarshalListJobRunsResponse,
18+
} from './marshalling.gen'
19+
import type {
20+
CreateJobDefinitionRequest,
21+
DeleteJobDefinitionRequest,
22+
GetJobDefinitionRequest,
23+
GetJobRunRequest,
24+
GetServiceInfoRequest,
25+
JobDefinition,
26+
JobRun,
27+
ListJobDefinitionsRequest,
28+
ListJobDefinitionsResponse,
29+
ListJobRunsRequest,
30+
ListJobRunsResponse,
31+
StartJobDefinitionRequest,
32+
StopJobRunRequest,
33+
UpdateJobDefinitionRequest,
34+
} from './types.gen'
35+
36+
const jsonContentHeaders = {
37+
'Content-Type': 'application/json; charset=utf-8',
38+
}
39+
40+
/** Serverless Jobs API. */
41+
export class API extends ParentAPI {
42+
/** Lists the available regions of the API. */
43+
public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw']
44+
45+
getServiceInfo = (request: Readonly<GetServiceInfoRequest> = {}) =>
46+
this.client.fetch<ServiceInfo>(
47+
{
48+
method: 'GET',
49+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
50+
'region',
51+
request.region ?? this.client.settings.defaultRegion,
52+
)}`,
53+
},
54+
unmarshalServiceInfo,
55+
)
56+
57+
createJobDefinition = (request: Readonly<CreateJobDefinitionRequest>) =>
58+
this.client.fetch<JobDefinition>(
59+
{
60+
body: JSON.stringify(
61+
marshalCreateJobDefinitionRequest(request, this.client.settings),
62+
),
63+
headers: jsonContentHeaders,
64+
method: 'POST',
65+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
66+
'region',
67+
request.region ?? this.client.settings.defaultRegion,
68+
)}/job-definitions`,
69+
},
70+
unmarshalJobDefinition,
71+
)
72+
73+
getJobDefinition = (request: Readonly<GetJobDefinitionRequest>) =>
74+
this.client.fetch<JobDefinition>(
75+
{
76+
method: 'GET',
77+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
78+
'region',
79+
request.region ?? this.client.settings.defaultRegion,
80+
)}/job-definitions/${validatePathParam(
81+
'jobDefinitionId',
82+
request.jobDefinitionId,
83+
)}`,
84+
},
85+
unmarshalJobDefinition,
86+
)
87+
88+
protected pageOfListJobDefinitions = (
89+
request: Readonly<ListJobDefinitionsRequest> = {},
90+
) =>
91+
this.client.fetch<ListJobDefinitionsResponse>(
92+
{
93+
method: 'GET',
94+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
95+
'region',
96+
request.region ?? this.client.settings.defaultRegion,
97+
)}/job-definitions`,
98+
urlParams: urlParams(
99+
['order_by', request.orderBy ?? 'created_at_asc'],
100+
['page', request.page],
101+
[
102+
'page_size',
103+
request.pageSize ?? this.client.settings.defaultPageSize,
104+
],
105+
['project_id', request.projectId],
106+
),
107+
},
108+
unmarshalListJobDefinitionsResponse,
109+
)
110+
111+
listJobDefinitions = (request: Readonly<ListJobDefinitionsRequest> = {}) =>
112+
enrichForPagination(
113+
'jobDefinitions',
114+
this.pageOfListJobDefinitions,
115+
request,
116+
)
117+
118+
updateJobDefinition = (request: Readonly<UpdateJobDefinitionRequest>) =>
119+
this.client.fetch<JobDefinition>(
120+
{
121+
body: JSON.stringify(
122+
marshalUpdateJobDefinitionRequest(request, this.client.settings),
123+
),
124+
headers: jsonContentHeaders,
125+
method: 'PATCH',
126+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
127+
'region',
128+
request.region ?? this.client.settings.defaultRegion,
129+
)}/job-definitions/${validatePathParam(
130+
'jobDefinitionId',
131+
request.jobDefinitionId,
132+
)}`,
133+
},
134+
unmarshalJobDefinition,
135+
)
136+
137+
deleteJobDefinition = (request: Readonly<DeleteJobDefinitionRequest>) =>
138+
this.client.fetch<void>({
139+
method: 'DELETE',
140+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
141+
'region',
142+
request.region ?? this.client.settings.defaultRegion,
143+
)}/job-definitions/${validatePathParam(
144+
'jobDefinitionId',
145+
request.jobDefinitionId,
146+
)}`,
147+
})
148+
149+
startJobDefinition = (request: Readonly<StartJobDefinitionRequest>) =>
150+
this.client.fetch<JobRun>(
151+
{
152+
body: '{}',
153+
headers: jsonContentHeaders,
154+
method: 'POST',
155+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
156+
'region',
157+
request.region ?? this.client.settings.defaultRegion,
158+
)}/job-definitions/${validatePathParam(
159+
'jobDefinitionId',
160+
request.jobDefinitionId,
161+
)}/start`,
162+
},
163+
unmarshalJobRun,
164+
)
165+
166+
getJobRun = (request: Readonly<GetJobRunRequest>) =>
167+
this.client.fetch<JobRun>(
168+
{
169+
method: 'GET',
170+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
171+
'region',
172+
request.region ?? this.client.settings.defaultRegion,
173+
)}/job-runs/${validatePathParam('jobRunId', request.jobRunId)}`,
174+
},
175+
unmarshalJobRun,
176+
)
177+
178+
stopJobRun = (request: Readonly<StopJobRunRequest>) =>
179+
this.client.fetch<JobRun>(
180+
{
181+
body: '{}',
182+
headers: jsonContentHeaders,
183+
method: 'POST',
184+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
185+
'region',
186+
request.region ?? this.client.settings.defaultRegion,
187+
)}/job-runs/${validatePathParam('jobRunId', request.jobRunId)}/stop`,
188+
},
189+
unmarshalJobRun,
190+
)
191+
192+
protected pageOfListJobRuns = (request: Readonly<ListJobRunsRequest> = {}) =>
193+
this.client.fetch<ListJobRunsResponse>(
194+
{
195+
method: 'GET',
196+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam(
197+
'region',
198+
request.region ?? this.client.settings.defaultRegion,
199+
)}/job-runs`,
200+
urlParams: urlParams(
201+
['job_definition_id', request.jobDefinitionId],
202+
['order_by', request.orderBy ?? 'created_at_asc'],
203+
['page', request.page],
204+
[
205+
'page_size',
206+
request.pageSize ?? this.client.settings.defaultPageSize,
207+
],
208+
['project_id', request.projectId],
209+
),
210+
},
211+
unmarshalListJobRunsResponse,
212+
)
213+
214+
listJobRuns = (request: Readonly<ListJobRunsRequest> = {}) =>
215+
enrichForPagination('jobRuns', this.pageOfListJobRuns, request)
216+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import type { JobRunState } from './types.gen'
4+
5+
/** Lists transient statutes of the enum {@link JobRunState}. */
6+
export const JOB_RUN_TRANSIENT_STATUSES: JobRunState[] = [
7+
'queued',
8+
'scheduled',
9+
'running',
10+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
export { API } from './api.gen'
4+
export * from './content.gen'
5+
export type {
6+
CreateJobDefinitionRequest,
7+
DeleteJobDefinitionRequest,
8+
GetJobDefinitionRequest,
9+
GetJobRunRequest,
10+
GetServiceInfoRequest,
11+
JobDefinition,
12+
JobRun,
13+
JobRunState,
14+
ListJobDefinitionsRequest,
15+
ListJobDefinitionsRequestOrderBy,
16+
ListJobDefinitionsResponse,
17+
ListJobRunsRequest,
18+
ListJobRunsRequestOrderBy,
19+
ListJobRunsResponse,
20+
StartJobDefinitionRequest,
21+
StopJobRunRequest,
22+
UpdateJobDefinitionRequest,
23+
} from './types.gen'
24+
export * as ValidationRules from './validation-rules.gen'
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import randomName from '@scaleway/random-name'
4+
import {
5+
isJSONObject,
6+
unmarshalArrayOfObject,
7+
unmarshalDate,
8+
} from '../../../bridge'
9+
import type { DefaultValues } from '../../../bridge'
10+
import type {
11+
CreateJobDefinitionRequest,
12+
JobDefinition,
13+
JobRun,
14+
ListJobDefinitionsResponse,
15+
ListJobRunsResponse,
16+
UpdateJobDefinitionRequest,
17+
} from './types.gen'
18+
19+
export const unmarshalJobDefinition = (data: unknown) => {
20+
if (!isJSONObject(data)) {
21+
throw new TypeError(
22+
`Unmarshalling the type 'JobDefinition' failed as data isn't a dictionary.`,
23+
)
24+
}
25+
26+
return {
27+
command: data.command,
28+
cpuLimit: data.cpu_limit,
29+
createdAt: unmarshalDate(data.created_at),
30+
description: data.description,
31+
environmentVariables: data.environment_variables,
32+
imageUri: data.image_uri,
33+
jobDefinitionId: data.job_definition_id,
34+
jobTimeout: data.job_timeout,
35+
memoryLimit: data.memory_limit,
36+
name: data.name,
37+
projectId: data.project_id,
38+
region: data.region,
39+
updatedAt: unmarshalDate(data.updated_at),
40+
} as JobDefinition
41+
}
42+
43+
export const unmarshalJobRun = (data: unknown) => {
44+
if (!isJSONObject(data)) {
45+
throw new TypeError(
46+
`Unmarshalling the type 'JobRun' failed as data isn't a dictionary.`,
47+
)
48+
}
49+
50+
return {
51+
createdAt: unmarshalDate(data.created_at),
52+
errorMessage: data.error_message,
53+
exitCode: data.exit_code,
54+
jobDefinitionId: data.job_definition_id,
55+
jobRunId: data.job_run_id,
56+
region: data.region,
57+
runDuration: data.run_duration,
58+
state: data.state,
59+
terminatedAt: unmarshalDate(data.terminated_at),
60+
updatedAt: unmarshalDate(data.updated_at),
61+
} as JobRun
62+
}
63+
64+
export const unmarshalListJobDefinitionsResponse = (data: unknown) => {
65+
if (!isJSONObject(data)) {
66+
throw new TypeError(
67+
`Unmarshalling the type 'ListJobDefinitionsResponse' failed as data isn't a dictionary.`,
68+
)
69+
}
70+
71+
return {
72+
jobDefinitions: unmarshalArrayOfObject(
73+
data.job_definitions,
74+
unmarshalJobDefinition,
75+
),
76+
totalCount: data.total_count,
77+
} as ListJobDefinitionsResponse
78+
}
79+
80+
export const unmarshalListJobRunsResponse = (data: unknown) => {
81+
if (!isJSONObject(data)) {
82+
throw new TypeError(
83+
`Unmarshalling the type 'ListJobRunsResponse' failed as data isn't a dictionary.`,
84+
)
85+
}
86+
87+
return {
88+
jobRuns: unmarshalArrayOfObject(data.job_runs, unmarshalJobRun),
89+
totalCount: data.total_count,
90+
} as ListJobRunsResponse
91+
}
92+
93+
export const marshalCreateJobDefinitionRequest = (
94+
request: CreateJobDefinitionRequest,
95+
defaults: DefaultValues,
96+
): Record<string, unknown> => ({
97+
command: request.command,
98+
cpu_limit: request.cpuLimit,
99+
description: request.description,
100+
environment_variables: request.environmentVariables,
101+
image_uri: request.imageUri,
102+
job_timeout: request.jobTimeout,
103+
memory_limit: request.memoryLimit,
104+
name: request.name || randomName('job'),
105+
project_id: request.projectId ?? defaults.defaultProjectId,
106+
})
107+
108+
export const marshalUpdateJobDefinitionRequest = (
109+
request: UpdateJobDefinitionRequest,
110+
defaults: DefaultValues,
111+
): Record<string, unknown> => ({
112+
command: request.command,
113+
cpu_limit: request.cpuLimit,
114+
description: request.description,
115+
environment_variables: request.environmentVariables,
116+
image_uri: request.imageUri,
117+
job_timeout: request.jobTimeout,
118+
memory_limit: request.memoryLimit,
119+
name: request.name,
120+
})

0 commit comments

Comments
 (0)