import {z} from 'zod' export type DockerProcess = {type: 'docker', command: Array, image: string, mount_docker_socket?: boolean | undefined}; export type JvmProcess = {type: 'jvm', jar_spec: {type: 'git_revision' | 'jar_url', value: string}, command: Array, profile?: boolean | undefined, spark_version?: string | undefined}; export type FileTransfer = {from: string, to: string}; export type CreateJobRequest = {job_id: number, process: DockerProcess | JvmProcess, always_copy_output?: boolean | undefined, always_run?: boolean | undefined, attributes?: {[key: string]: string} | undefined, env?: (Array<{name?: string | undefined, value?: string | undefined}>) | undefined, cloudfuse?: Array<{bucket: string, mount_path: string, read_only: boolean}> | undefined, input_files?: Array | undefined, output_files?: Array | undefined, mount_tokens?: boolean | undefined, network?: ('public' | 'private') | undefined, n_max_attempts?: number | undefined, unconfined?: boolean | undefined, parent_ids?: Array | undefined, absolute_parent_ids?: Array | undefined, in_update_parent_ids?: Array | undefined, absolute_job_group_id?: number | undefined, in_update_job_group_id?: number | undefined, port?: number | undefined, regions?: Array | undefined, requester_pays_project?: string | undefined, resources?: ({cpu?: string | undefined, memory?: (string | 'lowmem' | 'standard' | 'highmem') | undefined, storage?: string | undefined, machine_type?: string | undefined, preemptible?: boolean | undefined}) | undefined, secrets?: Array<{namespace: string, name: string, mount_path: string}> | undefined, service_account?: {namespace: string, name: string} | undefined, timeout?: number | undefined, user_code?: string | undefined}; export type CreateApiApiV1alphaBatchesBatchIdJobsCreateArgs = {batch_id: number, body: CreateJobRequest}; export type CreateApiApiV1alphaBatchesBatchIdJobsCreateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiApiV1alphaBatchesBatchIdJobsCreateResponse = z.object({}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create a job * * POST /api/v1alpha/batches/{batch_id}/jobs/create */ export const createApiApiV1alphaBatchesBatchIdJobsCreate = async (args: CreateApiApiV1alphaBatchesBatchIdJobsCreateArgs, options: CreateApiApiV1alphaBatchesBatchIdJobsCreateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1alpha/batches/${encodeURIComponent(String(args.batch_id))}/jobs/create${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1alphaBatchesBatchIdJobsCreateResponse, await res.json()) };