import {z} from 'zod' export type V1ImagePullPolicy = 'IMAGE_PULL_POLICY_UNSPECIFIED' | 'IMAGE_PULL_POLICY_ALWAYS' | 'IMAGE_PULL_POLICY_NEVER' | 'IMAGE_PULL_POLICY_IF_NOT_PRESENT'; export type V1NotebookEngineImage = {name?: string | undefined, displayName?: string | undefined, image: string, enabled?: boolean | undefined, imagePullPolicy?: V1ImagePullPolicy | undefined, imagePullSecrets?: Array | undefined, createTime?: string | undefined, updateTime?: (string | null) | undefined, creator?: string | undefined, updater?: string | undefined, creatorDisplayName?: string | undefined, updaterDisplayName?: string | undefined}; export type CreateApiV1ParentNotebookEngineImagesArgs = {parent: string, notebookEngineImageId?: string | undefined, body: V1NotebookEngineImage}; export type CreateApiV1ParentNotebookEngineImagesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1ImagePullPolicy = z.enum(["IMAGE_PULL_POLICY_UNSPECIFIED", "IMAGE_PULL_POLICY_ALWAYS", "IMAGE_PULL_POLICY_NEVER", "IMAGE_PULL_POLICY_IF_NOT_PRESENT"]); export const v1NotebookEngineImage = z.object({name: z.string().optional(), displayName: z.string().optional(), image: z.string(), enabled: z.boolean().optional(), imagePullPolicy: v1ImagePullPolicy.optional(), imagePullSecrets: z.array(z.string()).optional(), createTime: z.string().optional(), updateTime: z.string().nullable().optional(), creator: z.string().optional(), updater: z.string().optional(), creatorDisplayName: z.string().optional(), updaterDisplayName: z.string().optional()}); export const v1CreateNotebookEngineImageResponse = z.object({notebookEngineImage: v1NotebookEngineImage.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 }; /** * Creates a new NotebookEngineImage. * * POST /v1/{parent}/notebookEngineImages */ export const createApiV1ParentNotebookEngineImages = async (args: CreateApiV1ParentNotebookEngineImagesArgs, options: CreateApiV1ParentNotebookEngineImagesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.notebookEngineImageId != null) query.append("notebookEngineImageId", String(args.notebookEngineImageId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.parent))}/notebookEngineImages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1CreateNotebookEngineImageResponse, await res.json()) };