import {z} from 'zod' export type GetApiMfV1ImagesArgs = {user_name?: string | undefined, query_str?: string | undefined, page?: number | undefined, size?: number | undefined}; export type GetApiMfV1ImagesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const image = z.object({id: z.number().optional(), image_name: z.string().optional(), model_version_id: z.number().optional(), user_id: z.string().optional(), creation_timestamp: z.string().optional(), last_updated_timestamp: z.string().optional(), status: z.string().optional()}); export const images = z.array(image); 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 Image * * GET /mf/v1/images */ export const getApiMfV1Images = async (args: GetApiMfV1ImagesArgs, options?: GetApiMfV1ImagesOptions) => { const {baseUrl = "http://gateway.mlss.mf", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.user_name != null) query.append("user_name", String(args.user_name)) if (args.query_str != null) query.append("query_str", String(args.query_str)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) const url = `${baseUrl.replace(/\/+$/, '')}/mf/v1/images${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(images, await res.json()) };