import {z} from 'zod' export type TagSchema = {TagName: string, TagValue?: string | undefined}; export type Operation = {Name?: string | undefined, href?: string | undefined}; export type VolumeDetailV2v0 = {Name?: string | undefined, Size?: string | undefined, DiskgroupId?: string | undefined, DiskgroupName?: string | undefined, State?: string | undefined, Layout?: string | undefined, KernelState?: string | undefined, RvgId?: string | undefined, VsetId?: string | undefined, DiskList?: (Array<{DmName?: string | undefined}>) | undefined, Logtype?: string | undefined, Nlog?: number | undefined, Loglen?: string | undefined, Nstripe?: number | undefined, Stripeunit?: string | undefined, Nmirror?: number | undefined, Mirror?: string | undefined, Stripe?: string | undefined, MirrorConfine?: string | undefined, NSnapMirror?: number | undefined, NSnapMirrorsInSync?: number | undefined, StorageSpecification?: string | undefined, Tags?: Array | undefined, Operations?: Array | undefined, Flags?: string | undefined, ExtendableSize?: string | undefined, Mode?: string | undefined, User?: string | undefined, Group?: string | undefined, Mounted?: boolean | undefined, IsSnapshot?: boolean | undefined}; export type PatchApiDiskgroupsDgIdVolumesVolIdArgs = {DgId: string, VolId: string, nodename?: string | undefined, body: VolumeDetailV2v0}; export type PatchApiDiskgroupsDgIdVolumesVolIdOptions = {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 volume * * PATCH /diskgroups/{DgId}/volumes/{VolId} */ export const patchApiDiskgroupsDgIdVolumesVolId = async (args: PatchApiDiskgroupsDgIdVolumesVolIdArgs, options: PatchApiDiskgroupsDgIdVolumesVolIdOptions) => { 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)) const url = `${baseUrl.replace(/\/+$/, '')}/diskgroups/${encodeURIComponent(String(args.DgId))}/volumes/${encodeURIComponent(String(args.VolId))}${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()) };