import {z} from 'zod' export type GetApiApiV1ModelsIdSnapshotsSnapshotIdArgs = {'X-Fields'?: unknown | undefined}; export type GetApiApiV1ModelsIdSnapshotsSnapshotIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const groupRef = z.object({id: z.number().int().optional(), name: z.string().optional(), url: z.string().optional()}); export const userRefDump = z.object({id: z.number().int().optional(), username: z.string().optional(), url: z.string().optional()}); export const tagRefDump = z.object({id: z.number().int().optional(), name: z.string().optional(), group: groupRef.optional(), url: z.string().optional()}); export const modelVersionRefDump = z.object({versionNumber: z.number().int().optional(), url: z.string().optional()}); export const modelRefDump = z.object({id: z.number().int().optional(), group: groupRef.optional(), url: z.string().optional(), deleted: z.boolean().optional(), name: z.string()}); export const artifactRefDump = z.object({id: z.number().int().optional(), group: groupRef.optional(), url: z.string().optional(), deleted: z.boolean().optional()}); export const modelVersionDump = z.object({description: z.string().optional(), model: modelRefDump.optional(), artifact: artifactRefDump.optional(), versionNumber: z.number().int().optional(), createdOn: z.string().optional()}); export const snapshotsIdModelDump = z.object({id: z.number().int().optional(), snapshot: z.number().int().optional(), group: groupRef.optional(), user: userRefDump.optional(), createdOn: z.string().optional(), snapshotCreatedOn: z.string().optional(), lastModifiedOn: z.string().optional(), latestSnapshot: z.boolean().optional(), hasDraft: z.boolean().optional(), tags: z.array(tagRefDump).optional(), deleted: z.boolean().optional(), name: z.string(), description: z.string().optional(), versions: z.array(modelVersionRefDump).optional(), latestVersion: modelVersionDump.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 }; /** * Gets a Snapshot for the resource by snapshot id * * GET /api/v1/models/{id}/snapshots/{snapshotId} */ export const getApiApiV1ModelsIdSnapshotsSnapshotId = async (args: GetApiApiV1ModelsIdSnapshotsSnapshotIdArgs, options: GetApiApiV1ModelsIdSnapshotsSnapshotIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Fields'] != null) headers.set("X-Fields", String(args['X-Fields'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/models/${encodeURIComponent(String(args.id))}/snapshots/${encodeURIComponent(String(args.snapshotId))}${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(snapshotsIdModelDump, await res.json()) };