import {z} from 'zod' export type DatabaseCluster = {apiVersion?: string | undefined, kind?: string | undefined, metadata?: Record | undefined, spec?: ({allowUnsafeConfiguration?: boolean | undefined, backup?: ({enabled?: boolean | undefined, pitr?: ({backupStorageName?: string | undefined, enabled: boolean, uploadIntervalSec?: number | undefined}) | undefined, schedules?: (Array<{backupStorageName: string, enabled: boolean, name: string, retentionCopies?: number | undefined, schedule: string}>) | undefined}) | undefined, dataSource?: ({backupSource?: {backupStorageName: string, path: string} | undefined, dataImport?: ({config?: Record | undefined, dataImporterName: string, source: {path: string, s3?: ({accessKeyId?: string | undefined, bucket: string, credentialsSecretName: string, endpointURL: string, forcePathStyle?: boolean | undefined, region: string, secretAccessKey?: string | undefined, verifyTLS?: boolean | undefined}) | undefined}}) | undefined, dbClusterBackupName?: string | undefined, pitr?: ({date?: string | undefined, type?: ('date' | 'latest') | undefined}) | undefined}) | undefined, engine: {config?: string | undefined, crVersion?: string | undefined, replicas?: number | undefined, resources?: ({cpu?: (number | string) | undefined, memory?: (number | string) | undefined, limits?: ({cpu?: (number | string) | undefined, memory?: (number | string) | undefined}) | undefined, requests?: ({cpu?: (number | string) | undefined, memory?: (number | string) | undefined}) | undefined}) | undefined, storage: {class?: string | undefined, size: number | string}, type: 'pxc' | 'postgresql' | 'psmdb', userSecretsName?: string | undefined, version?: string | undefined}, engineFeatures?: ({psmdb?: ({splitHorizonDnsConfigName?: string | undefined}) | undefined}) | undefined, monitoring?: ({monitoringConfigName?: string | undefined, resources?: ({claims?: (Array<{name: string, request?: string | undefined}>) | undefined, limits?: ({[key: string]: number | string}) | undefined, requests?: ({[key: string]: number | string}) | undefined}) | undefined}) | undefined, paused?: boolean | undefined, podSchedulingPolicyName?: string | undefined, proxy?: ({config?: string | undefined, expose?: ({ipSourceRanges?: Array | undefined, loadBalancerConfigName?: string | undefined, type?: ('internal' | 'external' | 'ClusterIP' | 'LoadBalancer' | 'NodePort') | undefined}) | undefined, replicas?: number | undefined, resources?: ({cpu?: (number | string) | undefined, memory?: (number | string) | undefined, limits?: ({cpu?: (number | string) | undefined, memory?: (number | string) | undefined}) | undefined, requests?: ({cpu?: (number | string) | undefined, memory?: (number | string) | undefined}) | undefined}) | undefined, storage?: ({class?: string | undefined, size: number | string}) | undefined, type?: ('mongos' | 'haproxy' | 'proxysql' | 'pgbouncer') | undefined}) | undefined, sharding?: {configServer: {replicas: number}, enabled: boolean, shards: number} | undefined}) | undefined, status?: ({activeStorage?: string | undefined, conditions?: (Array<{lastTransitionTime: string, message: string, observedGeneration?: number | undefined, reason: string, status: 'True' | 'False' | 'Unknown', type: string}>) | undefined, crVersion?: string | undefined, dataImportJobName?: string | undefined, details?: string | undefined, engineFeatures?: ({psmdb?: ({splitHorizon?: ({domains?: (Array<{domain?: string | undefined, privateIP?: string | undefined, publicIP?: string | undefined}>) | undefined, host?: string | undefined}) | undefined}) | undefined}) | undefined, hostname?: string | undefined, message?: string | undefined, observedGeneration?: number | undefined, port?: number | undefined, ready?: number | undefined, recommendedCRVersion?: string | undefined, size?: number | undefined, status?: string | undefined}) | undefined}; export type UpdateApiNamespacesNamespaceDatabaseClustersNameArgs = {namespace: string, name: string, body: DatabaseCluster}; export type UpdateApiNamespacesNamespaceDatabaseClustersNameOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const databaseCluster = z.object({apiVersion: z.string().optional(), kind: z.string().optional(), metadata: z.object({}).optional(), spec: z.object({allowUnsafeConfiguration: z.boolean().optional(), backup: z.object({enabled: z.boolean().optional(), pitr: z.object({backupStorageName: z.string().optional(), enabled: z.boolean(), uploadIntervalSec: z.number().int().optional()}).optional(), schedules: z.array(z.object({backupStorageName: z.string(), enabled: z.boolean(), name: z.string(), retentionCopies: z.number().int().optional(), schedule: z.string()})).optional()}).optional(), dataSource: z.object({backupSource: z.object({backupStorageName: z.string(), path: z.string()}).optional(), dataImport: z.object({config: z.object({}).optional(), dataImporterName: z.string(), source: z.object({path: z.string(), s3: z.object({accessKeyId: z.string().optional(), bucket: z.string(), credentialsSecretName: z.string(), endpointURL: z.string(), forcePathStyle: z.boolean().optional(), region: z.string(), secretAccessKey: z.string().optional(), verifyTLS: z.boolean().optional()}).optional()})}).optional(), dbClusterBackupName: z.string().optional(), pitr: z.object({date: z.string().optional(), type: z.enum(["date", "latest"]).optional()}).optional()}).optional(), engine: z.object({config: z.string().optional(), crVersion: z.string().optional(), replicas: z.number().int().gte(1).optional(), resources: z.object({cpu: z.union([z.number().int(), z.string()]).optional(), memory: z.union([z.number().int(), z.string()]).optional(), limits: z.object({cpu: z.union([z.number().int(), z.string()]).optional(), memory: z.union([z.number().int(), z.string()]).optional()}).optional(), requests: z.object({cpu: z.union([z.number().int(), z.string()]).optional(), memory: z.union([z.number().int(), z.string()]).optional()}).optional()}).optional(), storage: z.object({class: z.string().optional(), size: z.union([z.number().int(), z.string()])}), type: z.enum(["pxc", "postgresql", "psmdb"]), userSecretsName: z.string().optional(), version: z.string().optional()}), engineFeatures: z.object({psmdb: z.object({splitHorizonDnsConfigName: z.string().optional()}).optional()}).optional(), monitoring: z.object({monitoringConfigName: z.string().optional(), resources: z.object({claims: z.array(z.object({name: z.string(), request: z.string().optional()})).optional(), limits: z.record(z.string(), z.union([z.number().int(), z.string()])).optional(), requests: z.record(z.string(), z.union([z.number().int(), z.string()])).optional()}).optional()}).optional(), paused: z.boolean().optional(), podSchedulingPolicyName: z.string().optional(), proxy: z.object({config: z.string().optional(), expose: z.object({ipSourceRanges: z.array(z.string()).optional(), loadBalancerConfigName: z.string().optional(), type: z.enum(["internal", "external", "ClusterIP", "LoadBalancer", "NodePort"]).optional()}).optional(), replicas: z.number().int().gte(1).optional(), resources: z.object({cpu: z.union([z.number().int(), z.string()]).optional(), memory: z.union([z.number().int(), z.string()]).optional(), limits: z.object({cpu: z.union([z.number().int(), z.string()]).optional(), memory: z.union([z.number().int(), z.string()]).optional()}).optional(), requests: z.object({cpu: z.union([z.number().int(), z.string()]).optional(), memory: z.union([z.number().int(), z.string()]).optional()}).optional()}).optional(), storage: z.object({class: z.string().optional(), size: z.union([z.number().int(), z.string()])}).optional(), type: z.enum(["mongos", "haproxy", "proxysql", "pgbouncer"]).optional()}).optional(), sharding: z.object({configServer: z.object({replicas: z.number().int().gte(1)}), enabled: z.boolean(), shards: z.number().int().gte(1)}).optional()}).optional(), status: z.object({activeStorage: z.string().optional(), conditions: z.array(z.object({lastTransitionTime: z.string(), message: z.string().max(32768), observedGeneration: z.number().int().gte(0).optional(), reason: z.string().min(1).max(1024), status: z.enum(["True", "False", "Unknown"]), type: z.string().max(316)})).optional(), crVersion: z.string().optional(), dataImportJobName: z.string().optional(), details: z.string().optional(), engineFeatures: z.object({psmdb: z.object({splitHorizon: z.object({domains: z.array(z.object({domain: z.string().optional(), privateIP: z.string().optional(), publicIP: z.string().optional()})).optional(), host: z.string().optional()}).optional()}).optional()}).optional(), hostname: z.string().optional(), message: z.string().optional(), observedGeneration: z.number().int().optional(), port: z.number().int().optional(), ready: z.number().int().optional(), recommendedCRVersion: z.string().optional(), size: z.number().int().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 cluster * * PUT /namespaces/{namespace}/database-clusters/{name} */ export const updateApiNamespacesNamespaceDatabaseClustersName = async (args: UpdateApiNamespacesNamespaceDatabaseClustersNameArgs, options: UpdateApiNamespacesNamespaceDatabaseClustersNameOptions) => { 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-clusters/${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(databaseCluster, await res.json()) };