import {z} from 'zod' export type GetApiZfsPoolsGuidStatusArgs = {guid: string}; export type GetApiZfsPoolsGuidStatusOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gzfsZPoolStatusVDEV: z.ZodType = z.object({alloc_space: z.string().optional(), checksum_errors: z.string().optional(), class: z.string().optional(), def_space: z.string().optional(), guid: z.string().optional(), name: z.string().optional(), path: z.string().optional(), read_errors: z.string().optional(), rep_dev_size: z.string().optional(), state: z.string().optional(), total_space: z.string().optional(), vdev_type: z.string().optional(), vdevs: z.record(z.string(), z.lazy(() => gzfsZPoolStatusVDEV)).optional(), write_errors: z.string().optional()}); export const gzfsZPoolStatusScanStats = z.object({bytes_per_scan: z.string().optional(), end_time: z.string().optional(), errors: z.string().optional(), examined: z.string().optional(), function: z.string().optional(), issued: z.string().optional(), issued_bytes_per_scan: z.string().optional(), pass_start: z.string().optional(), processed: z.string().optional(), scrub_pause: z.string().optional(), scrub_spent_paused: z.string().optional(), skipped: z.string().optional(), start_time: z.string().optional(), state: z.string().optional(), to_examine: z.string().optional()}); export const gzfsZPoolStatusPool = z.object({action: z.string().optional(), dedup: z.record(z.string(), gzfsZPoolStatusVDEV).optional(), l2cache: z.record(z.string(), gzfsZPoolStatusVDEV).optional(), logs: z.record(z.string(), gzfsZPoolStatusVDEV).optional(), name: z.string().optional(), pool_guid: z.string().optional(), scan_stats: gzfsZPoolStatusScanStats.optional(), spa_version: z.string().optional(), spares: z.record(z.string(), gzfsZPoolStatusVDEV).optional(), special: z.record(z.string(), gzfsZPoolStatusVDEV).optional(), state: z.string().optional(), status: z.string().optional(), txg: z.string().optional(), vdevs: z.record(z.string(), gzfsZPoolStatusVDEV).optional(), zpl_version: z.string().optional()}); export const githubComAlchemillahqSylveInternalAPIResponseGzfsZPoolStatusPool = z.object({data: gzfsZPoolStatusPool.optional(), error: z.string().optional(), message: z.string().optional(), status: 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 }; /** * Get Pool Status * * GET /zfs/pools/{guid}/status */ export const getApiZfsPoolsGuidStatus = async (args: GetApiZfsPoolsGuidStatusArgs, options: GetApiZfsPoolsGuidStatusOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/zfs/pools/${encodeURIComponent(String(args.guid))}/status${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(githubComAlchemillahqSylveInternalAPIResponseGzfsZPoolStatusPool, await res.json()) };