import {z} from 'zod' export type GetApiApiV2alphaBatchesBatchIdJobsArgs = {batch_id: number, q?: string | undefined, last_job_id?: number | undefined}; export type GetApiApiV2alphaBatchesBatchIdJobsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const dockerProcess = z.object({type: z.literal("docker"), command: z.array(z.string()), image: z.string(), mount_docker_socket: z.boolean().optional()}); export const jvmProcess = z.object({type: z.literal("jvm"), jar_spec: z.object({type: z.enum(["git_revision", "jar_url"]), value: z.string()}), command: z.array(z.string()), profile: z.boolean().optional(), spark_version: z.string().optional()}); export const fileTransfer = z.object({from: z.string(), to: z.string()}); export const createJobRequest = z.object({job_id: z.number().int(), process: z.discriminatedUnion("type", [dockerProcess, jvmProcess]), always_copy_output: z.boolean().optional(), always_run: z.boolean().optional(), attributes: z.record(z.string(), z.string()).optional(), env: z.array(z.object({name: z.string().optional(), value: z.string().optional()})).optional(), cloudfuse: z.array(z.object({bucket: z.string().min(1), mount_path: z.string().min(1), read_only: z.boolean()})).optional(), input_files: z.array(fileTransfer).optional(), output_files: z.array(fileTransfer).optional(), mount_tokens: z.boolean().optional(), network: z.enum(["public", "private"]).optional(), n_max_attempts: z.number().int().optional(), unconfined: z.boolean().optional(), parent_ids: z.array(z.number().int()).optional(), absolute_parent_ids: z.array(z.number().int()).optional(), in_update_parent_ids: z.array(z.number().int()).optional(), absolute_job_group_id: z.number().int().optional(), in_update_job_group_id: z.number().int().optional(), port: z.number().int().optional(), regions: z.array(z.string()).optional(), requester_pays_project: z.string().optional(), resources: z.object({cpu: z.string().optional(), memory: z.union([z.string(), z.enum(["lowmem", "standard", "highmem"])]).optional(), storage: z.string().optional(), machine_type: z.string().optional(), preemptible: z.boolean().optional()}).optional(), secrets: z.array(z.object({namespace: z.string().max(253), name: z.string().max(253), mount_path: z.string()})).optional(), service_account: z.object({namespace: z.string().max(253), name: z.string().max(253)}).optional(), timeout: z.number().gt(0).optional(), user_code: z.string().optional()}); export const jobV2Response = z.object({batch_id: z.number().int().optional(), job_id: z.number().int().optional(), state: z.enum(["pending", "running", "succeeded", "failed", "cancelled"]).optional(), exit_code: z.number().int().nullable().optional(), duration: z.number().nullable().optional(), cost: z.number().nullable().optional(), start_time: z.string().nullable().optional(), end_time: z.string().nullable().optional(), attributes: z.record(z.string(), z.string()).optional(), spec: createJobRequest.optional()}); export const jobV2ListResponse = z.object({jobs: z.array(jobV2Response).optional(), last_job_id: z.number().int().nullable().optional()}); 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 }; /** * List jobs in a batch * * GET /api/v2alpha/batches/{batch_id}/jobs */ export const getApiApiV2alphaBatchesBatchIdJobs = async (args: GetApiApiV2alphaBatchesBatchIdJobsArgs, options: GetApiApiV2alphaBatchesBatchIdJobsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.q != null) query.append("q", String(args.q)) if (args.last_job_id != null) query.append("last_job_id", String(args.last_job_id)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2alpha/batches/${encodeURIComponent(String(args.batch_id))}/jobs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(jobV2ListResponse, await res.json()) };