import {z} from 'zod' export type Tag = {key?: string | undefined, Value?: string | undefined}; export type Volume = {Id?: string | undefined, UserId?: string | undefined, BackendId: string, Backend?: string | undefined, Name: string, Description?: string | undefined, Type: string, iops?: number | undefined, Size?: number | undefined, Region?: string | undefined, AvailabilityZone?: string | undefined, Tags?: Array | undefined, SnapshotId?: string | undefined, Encrypted?: boolean | undefined, EncryptedSettings?: {[key: string]: string} | undefined, Metadata?: {[key: string]: string} | undefined}; export type CreateApiV1TenantIdVolumesArgs = {body: Volume}; export type CreateApiV1TenantIdVolumesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const tag = z.object({key: z.string().optional(), Value: z.string().optional()}); export const volumeFields = z.object({CreationTimeAtBackend: z.object({kind: z.object({StringValue: z.string().optional()}).optional()}).optional(), StartTimeAtBackend: z.object({kind: z.object({StringValue: z.string().optional()}).optional()}).optional(), VolumeId: z.object({kind: z.object({StringValue: z.string().optional()}).optional()}).optional(), Progress: z.object({kind: z.object({NumberValue: z.number().int().optional()}).optional()}).optional()}); export const volumeResult = z.object({Id: z.string().optional(), CreatedAt: z.string().optional(), UpdatedAt: z.string().optional(), TenantId: z.string().optional(), UserId: z.string().optional(), BackendId: z.string().optional(), Backend: z.string().optional(), Name: z.string().optional(), Description: z.string().optional(), Type: z.string().optional(), Size: z.number().int().optional(), Region: z.string().optional(), AvailabilityZone: z.string().optional(), Status: z.enum(["available", "creating", "inUse", "error", "updating", "deleting", "errorDeleting", "deleted"]).optional(), Tags: z.array(tag).optional(), SnapshotId: z.string().optional(), Encrypted: z.boolean().optional(), EncryptedSettings: z.record(z.string(), z.string()).optional(), Metadata: z.object({fields: volumeFields.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 }; /** * Create a volume. * * POST /v1/{tenantId}/volumes */ export const createApiV1TenantIdVolumes = async (args: CreateApiV1TenantIdVolumesArgs, options?: CreateApiV1TenantIdVolumesOptions) => { const {baseUrl = "https://virtserver.swaggerhub.com/open83/multi-cloud/1.0.0", 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(/\/+$/, '')}/v1/${encodeURIComponent(String(args.tenantId))}/volumes${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(volumeResult, await res.json()) };