import {z} from 'zod' export type GetApiV1HostsHostIdTasksTaskIdArgs = {host_id: string, task_id: string}; export type GetApiV1HostsHostIdTasksTaskIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const task = z.object({completed_at: z.string().optional(), created_at: z.string(), database_id: z.string().optional(), entity_id: z.string(), error: z.string().optional(), host_id: z.string().optional(), instance_id: z.string().optional(), node_name: z.string().optional(), parent_id: z.string().optional(), scope: z.enum(["database", "host"]), status: z.enum(["pending", "running", "completed", "canceled", "canceling", "failed", "unknown"]), task_id: z.string(), type: z.string()}); 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 }; /** * Get host task * * GET /v1/hosts/{host_id}/tasks/{task_id} */ export const getApiV1HostsHostIdTasksTaskId = async (args: GetApiV1HostsHostIdTasksTaskIdArgs, options?: GetApiV1HostsHostIdTasksTaskIdOptions) => { const {baseUrl = "http:////localhost:3000", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/hosts/${encodeURIComponent(String(args.host_id))}/tasks/${encodeURIComponent(String(args.task_id))}${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(task, await res.json()) };