import {z} from 'zod' export type Path = {[key: string]: string}; export type TagSchema = {TagName: string, TagValue?: string | undefined}; export type DiskConnectivity = {HostName?: string | undefined, href?: string | undefined}; export type Operation = {Name?: string | undefined, href?: string | undefined}; export type DiskDetailV2v0 = {DiskId?: string | undefined, Name?: string | undefined, LunSize?: string | undefined, TotalUsableSize?: string | undefined, DiskgroupName?: string | undefined, DiskgroupState?: string | undefined, State?: ('online' | 'offline') | undefined, MediaFormat?: string | undefined, Initialized?: boolean | undefined, Privlen?: string | undefined, Udid?: string | undefined, Numpaths?: number | undefined, Paths?: Array | undefined, Sectorsize?: number | undefined, Mediatype?: string | undefined, Flags?: string | undefined, Attribute?: string | undefined, Tags?: Array | undefined, Connectivity?: Array | undefined, HostConnectivity?: ('fullshared' | 'partialshared' | 'local') | undefined, FreeSize?: string | undefined, DmpDevice?: string | undefined, Operations?: Array | undefined}; export type PatchApiDisksDiskIdArgs = {nodename?: string | undefined, DiskId: string, dgname?: string | undefined, body: DiskDetailV2v0}; export type PatchApiDisksDiskIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const response = z.object({detail: z.string().optional(), status: z.number().int().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 disk object * * PATCH /disks/{DiskId} */ export const patchApiDisksDiskId = async (args: PatchApiDisksDiskIdArgs, options: PatchApiDisksDiskIdOptions) => { 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.nodename != null) query.append("nodename", String(args.nodename)) if (args.dgname != null) query.append("dgname", String(args.dgname)) const url = `${baseUrl.replace(/\/+$/, '')}/disks/${encodeURIComponent(String(args.DiskId))}${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(response, await res.json()) };