import {z} from 'zod' export type GetApiRootMWfIdWorkflowWfIdJobJobIdJobInstanceArgs = {query?: string | undefined, order?: string | undefined, 'start-index'?: number | undefined, 'max-results'?: number | undefined, recent?: boolean | undefined}; export type GetApiRootMWfIdWorkflowWfIdJobJobIdJobInstanceOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const jobInstance = z.object({job_instance_id: z.number().int().optional(), host_id: z.number().int().optional(), job_submit_seq: z.number().int().optional(), sched_id: z.string().optional(), site_name: z.string().optional(), user: z.string().optional(), work_dir: z.string().optional(), cluster_start: z.number().optional(), cluster_duration: z.number().optional(), local_duration: z.number().optional(), subwf_id: z.number().int().optional(), stdout_text: z.string().optional(), stderr_text: z.string().optional(), stdin_file: z.string().optional(), stdout_file: z.string().optional(), stderr_file: z.string().optional(), multiplier_factor: z.string().optional(), exitcode: z.string().optional()}); export const getApiRootMWfIdWorkflowWfIdJobJobIdJobInstanceResponse = z.array(jobInstance); 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 }; /** * Retrieve all job's job instances * * GET /root/{m-wf-id}/workflow/{wf-id}/job/{job-id}/job-instance */ export const getApiRootMWfIdWorkflowWfIdJobJobIdJobInstance = async (args: GetApiRootMWfIdWorkflowWfIdJobJobIdJobInstanceArgs, options?: GetApiRootMWfIdWorkflowWfIdJobJobIdJobInstanceOptions) => { const {baseUrl = "https://localhost:5000/api/v1/user/unknown", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.query != null) query.append("query", String(args.query)) if (args.order != null) query.append("order", String(args.order)) if (args['start-index'] != null) query.append("start-index", String(args['start-index'])) if (args['max-results'] != null) query.append("max-results", String(args['max-results'])) if (args.recent != null) query.append("recent", String(args.recent)) const url = `${baseUrl.replace(/\/+$/, '')}/root/${encodeURIComponent(String(args['m-wf-id']))}/workflow/${encodeURIComponent(String(args['wf-id']))}/job/${encodeURIComponent(String(args['job-id']))}/job-instance${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(getApiRootMWfIdWorkflowWfIdJobJobIdJobInstanceResponse, await res.json()) };