import {z} from 'zod' export type MachinePowerState = 'MACHINE_POWER_STATE_UNSPECIFIED' | 'ON' | 'OFF' | 'POWERING_ON' | 'POWERING_OFF' | 'REBOOTING'; export type Decimal = {value?: string | undefined}; export type ClusterMachineState = 'STATE_UNSPECIFIED' | 'CREATING' | 'ACTIVE' | 'DELETING' | 'FAILED'; export type PatchApiV1ProjectsProjectIdClusterMachinesIdArgs = {projectId: string, id: string, body: {architecture?: string | undefined, cpuCores?: number | undefined, cpuModel?: string | undefined, cpuSpeedMhz?: number | undefined, createBy?: string | undefined, createTime?: string | undefined, dataCenterId?: string | undefined, diskSizeGib?: number | undefined, disks?: number | undefined, externalIpAddress?: string | undefined, gpuModelId?: string | undefined, gpus?: number | undefined, internalIpAddress?: string | undefined, machineTypeId?: string | undefined, memoryGib?: number | undefined, powerState?: MachinePowerState | undefined, priceHr?: Decimal | undefined, state?: ClusterMachineState | undefined, volumeIds?: Array | undefined}}; export type PatchApiV1ProjectsProjectIdClusterMachinesIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const machinePowerState = z.enum(["MACHINE_POWER_STATE_UNSPECIFIED", "ON", "OFF", "POWERING_ON", "POWERING_OFF", "REBOOTING"]); export const decimal = z.object({value: z.string().optional()}); export const clusterMachineState = z.enum(["STATE_UNSPECIFIED", "CREATING", "ACTIVE", "DELETING", "FAILED"]); export const clusterMachine = z.object({architecture: z.string().optional(), cpuCores: z.number().int().optional(), cpuModel: z.string().optional(), cpuSpeedMhz: z.number().int().optional(), createBy: z.string().optional(), createTime: z.string().optional(), dataCenterId: z.string().optional(), diskSizeGib: z.number().int().optional(), disks: z.number().int().optional(), externalIpAddress: z.string().optional(), gpuModelId: z.string().optional(), gpus: z.number().int().optional(), id: z.string().optional(), internalIpAddress: z.string().optional(), machineTypeId: z.string().optional(), memoryGib: z.number().int().optional(), powerState: machinePowerState.optional(), priceHr: decimal.optional(), projectId: z.string().optional(), state: clusterMachineState.optional(), volumeIds: z.array(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 a cluster machine * * PATCH /v1/projects/{projectId}/cluster-machines/{id} */ export const patchApiV1ProjectsProjectIdClusterMachinesId = async (args: PatchApiV1ProjectsProjectIdClusterMachinesIdArgs, options?: PatchApiV1ProjectsProjectIdClusterMachinesIdOptions) => { const {baseUrl = "https://rest.compute.cudo.org", 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", bearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectId))}/cluster-machines/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(clusterMachine, await res.json()) };