import {z} from 'zod' export type GetApiRootMWfIdWorkflowWfIdHostArgs = {query?: string | undefined, order?: string | undefined, 'start-index'?: number | undefined, 'max-results'?: number | undefined}; export type GetApiRootMWfIdWorkflowWfIdHostOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const host = z.object({host_id: z.number().int().optional(), site_name: z.string().optional(), hostname: z.string().optional(), ip: z.string().optional(), uname: z.string().optional(), total_memory: z.string().optional()}); export const getApiRootMWfIdWorkflowWfIdHostResponse = z.array(host); 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 hosts on which a workflows job ran on * * GET /root/{m-wf-id}/workflow/{wf-id}/host */ export const getApiRootMWfIdWorkflowWfIdHost = async (args: GetApiRootMWfIdWorkflowWfIdHostArgs, options?: GetApiRootMWfIdWorkflowWfIdHostOptions) => { 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'])) const url = `${baseUrl.replace(/\/+$/, '')}/root/${encodeURIComponent(String(args['m-wf-id']))}/workflow/${encodeURIComponent(String(args['wf-id']))}/host${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(getApiRootMWfIdWorkflowWfIdHostResponse, await res.json()) };