import {z} from 'zod' export type DatabaseEngine = {apiVersion?: string | undefined, kind?: string | undefined, metadata?: Record | undefined, spec?: ({allowedVersions?: Array | undefined, secretKeys?: ({user?: (Array<{description?: string | undefined, name?: string | undefined}>) | undefined}) | undefined, type: string}) | undefined, status?: ({availableVersions?: ({backup?: ({[key: string]: {critical?: boolean | undefined, imageHash?: string | undefined, imagePath?: string | undefined, status?: string | undefined}}) | undefined, engine?: ({[key: string]: {critical?: boolean | undefined, imageHash?: string | undefined, imagePath?: string | undefined, status?: string | undefined}}) | undefined, proxy?: ({[key: string]: {[key: string]: {critical?: boolean | undefined, imageHash?: string | undefined, imagePath?: string | undefined, status?: string | undefined}}}) | undefined, tools?: ({[key: string]: {[key: string]: {critical?: boolean | undefined, imageHash?: string | undefined, imagePath?: string | undefined, status?: string | undefined}}}) | undefined}) | undefined, operatorUpgrade?: ({installPlanRef?: ({name?: string | undefined}) | undefined, message?: string | undefined, phase?: string | undefined, startedAt?: string | undefined, targetVersion?: string | undefined}) | undefined, operatorVersion?: string | undefined, pendingOperatorUpgrades?: (Array<{installPlanRef?: ({name?: string | undefined}) | undefined, targetVersion?: string | undefined}>) | undefined, status?: string | undefined}) | undefined}; export type UpdateApiNamespacesNamespaceDatabaseEnginesNameArgs = {namespace: string, name: string, body: DatabaseEngine}; export type UpdateApiNamespacesNamespaceDatabaseEnginesNameOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const databaseEngine = z.object({apiVersion: z.string().optional(), kind: z.string().optional(), metadata: z.object({}).optional(), spec: z.object({allowedVersions: z.array(z.string()).optional(), secretKeys: z.object({user: z.array(z.object({description: z.string().optional(), name: z.string().optional()})).optional()}).optional(), type: z.string()}).optional(), status: z.object({availableVersions: z.object({backup: z.record(z.string(), z.object({critical: z.boolean().optional(), imageHash: z.string().optional(), imagePath: z.string().optional(), status: z.string().optional()})).optional(), engine: z.record(z.string(), z.object({critical: z.boolean().optional(), imageHash: z.string().optional(), imagePath: z.string().optional(), status: z.string().optional()})).optional(), proxy: z.record(z.string(), z.record(z.string(), z.object({critical: z.boolean().optional(), imageHash: z.string().optional(), imagePath: z.string().optional(), status: z.string().optional()}))).optional(), tools: z.record(z.string(), z.record(z.string(), z.object({critical: z.boolean().optional(), imageHash: z.string().optional(), imagePath: z.string().optional(), status: z.string().optional()}))).optional()}).optional(), operatorUpgrade: z.object({installPlanRef: z.object({name: z.string().optional()}).optional(), message: z.string().optional(), phase: z.string().optional(), startedAt: z.string().optional(), targetVersion: z.string().optional()}).optional(), operatorVersion: z.string().optional(), pendingOperatorUpgrades: z.array(z.object({installPlanRef: z.object({name: z.string().optional()}).optional(), targetVersion: z.string().optional()})).optional(), status: z.string().optional()}).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 }; /** * Update database engine * * PUT /namespaces/{namespace}/database-engines/{name} */ export const updateApiNamespacesNamespaceDatabaseEnginesName = async (args: UpdateApiNamespacesNamespaceDatabaseEnginesNameArgs, options: UpdateApiNamespacesNamespaceDatabaseEnginesNameOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/namespaces/${encodeURIComponent(String(args.namespace))}/database-engines/${encodeURIComponent(String(args.name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(databaseEngine, await res.json()) };