import {z} from 'zod' export type V1alpha1AWSAuthConfig = {clusterName?: string | undefined, roleARN?: string | undefined}; export type V1alpha1TLSClientConfig = {caData?: string | undefined, certData?: string | undefined, insecure?: boolean | undefined, keyData?: string | undefined, serverName?: string | undefined}; export type V1alpha1ClusterConfig = {awsAuthConfig?: V1alpha1AWSAuthConfig | undefined, bearerToken?: string | undefined, password?: string | undefined, tlsClientConfig?: V1alpha1TLSClientConfig | undefined, username?: string | undefined}; export type V1Time = {nanos?: number | undefined, seconds?: unknown | undefined}; export type V1alpha1ConnectionState = {attemptedAt?: V1Time | undefined, message?: string | undefined, status?: string | undefined}; export type V1alpha1Cluster = {config?: V1alpha1ClusterConfig | undefined, connectionState?: V1alpha1ConnectionState | undefined, name?: string | undefined, server?: string | undefined}; export type UpdateApiApiV1ClustersClusterServerArgs = {'cluster.server': string, body: V1alpha1Cluster}; export type UpdateApiApiV1ClustersClusterServerOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1alpha1AWSAuthConfig = z.object({clusterName: z.string().optional(), roleARN: z.string().optional()}); export const v1alpha1TLSClientConfig = z.object({caData: z.string().optional(), certData: z.string().optional(), insecure: z.boolean().optional(), keyData: z.string().optional(), serverName: z.string().optional()}); export const v1alpha1ClusterConfig = z.object({awsAuthConfig: v1alpha1AWSAuthConfig.optional(), bearerToken: z.string().optional(), password: z.string().optional(), tlsClientConfig: v1alpha1TLSClientConfig.optional(), username: z.string().optional()}); export const v1Time = z.object({nanos: z.number().int().optional(), seconds: z.string().optional()}); export const v1alpha1ConnectionState = z.object({attemptedAt: v1Time.optional(), message: z.string().optional(), status: z.string().optional()}); export const v1alpha1Cluster = z.object({config: v1alpha1ClusterConfig.optional(), connectionState: v1alpha1ConnectionState.optional(), name: z.string().optional(), server: z.string().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 updates a cluster * * PUT /api/v1/clusters/{cluster.server} */ export const updateApiApiV1ClustersClusterServer = async (args: UpdateApiApiV1ClustersClusterServerArgs, options: UpdateApiApiV1ClustersClusterServerOptions) => { 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") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/clusters/${encodeURIComponent(String(args['cluster.server']))}${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(v1alpha1Cluster, await res.json()) };