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 V1H2OEngineVersion = {name?: string | undefined, deprecated?: boolean | undefined, aliases?: Array | undefined, image: string, 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 CreateApiV1ParentH2oEngineVersionsArgs = {parent: string, h2oEngineVersionId: string, body: V1H2OEngineVersion}; export type CreateApiV1ParentH2oEngineVersionsOptions = {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 v1H2OEngineVersion = z.object({name: z.string().optional(), deprecated: z.boolean().optional(), aliases: z.array(z.string()).optional(), image: z.string(), 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 v1CreateH2OEngineVersionResponse = z.object({h2oEngineVersion: v1H2OEngineVersion.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 H2OEngineVersion. * * POST /v1/{parent}/h2oEngineVersions */ export const createApiV1ParentH2oEngineVersions = async (args: CreateApiV1ParentH2oEngineVersionsArgs, options: CreateApiV1ParentH2oEngineVersionsOptions) => { 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.h2oEngineVersionId != null) query.append("h2oEngineVersionId", String(args.h2oEngineVersionId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.parent))}/h2oEngineVersions${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(v1CreateH2OEngineVersionResponse, await res.json()) };