import {z} from 'zod' export type GetApiZfsDashboardSnapshotOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardARCPoint = z.object({compressedSize: z.number().int().optional(), dataSize: z.number().int().optional(), demandHitRatio: z.number().optional(), evictNotEnoughEvents: z.number().int().optional(), evictionsPerSecond: z.number().optional(), headerSize: z.number().int().optional(), hitRatio: z.number().optional(), id: z.number().int().optional(), l2Allocated: z.number().int().optional(), l2DeviceCount: z.number().int().optional(), l2HitRatio: z.number().optional(), l2ReadBytesPerSecond: z.number().int().optional(), l2Size: z.number().int().optional(), l2WriteBytesPerSecond: z.number().int().optional(), maxSize: z.number().int().optional(), memoryThrottleEvents: z.number().int().optional(), metadataSize: z.number().int().optional(), minSize: z.number().int().optional(), otherSize: z.number().int().optional(), prefetchHitRatio: z.number().optional(), size: z.number().int().optional(), targetSize: z.number().int().optional(), time: z.number().int().optional(), uncompressedSize: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardPoolErrors = z.object({checksum: z.number().int().optional(), read: z.number().int().optional(), scan: z.number().int().optional(), write: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardIOStats = z.object({intervalSeconds: z.number().int().optional(), latencyAvailable: z.boolean().optional(), readBytesPerSecond: z.number().int().optional(), readIOPS: z.number().int().optional(), readLatencyNanos: z.number().int().optional(), sampledAt: z.number().int().optional(), valid: z.boolean().optional(), writeBytesPerSecond: z.number().int().optional(), writeIOPS: z.number().int().optional(), writeLatencyNanos: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardPoolScan = z.object({endTime: z.string().optional(), errors: z.number().int().optional(), examined: z.number().int().optional(), function: z.string().optional(), issued: z.number().int().optional(), processed: z.number().int().optional(), progressPercent: z.number().optional(), startTime: z.string().optional(), state: z.string().optional(), toExamine: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardPoolTopology = z.object({cache: z.number().int().optional(), dataVdevs: z.number().int().optional(), dedup: z.number().int().optional(), disks: z.number().int().optional(), logs: z.number().int().optional(), spares: z.number().int().optional(), special: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardPoolSnapshot = z.object({action: z.string().optional(), allocated: z.number().int().optional(), dedupRatio: z.number().optional(), errors: githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardPoolErrors.optional(), fragmentation: z.number().optional(), free: z.number().int().optional(), guid: z.string().optional(), io: githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardIOStats.optional(), name: z.string().optional(), scan: githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardPoolScan.optional(), size: z.number().int().optional(), state: z.string().optional(), status: z.string().optional(), statusAvailable: z.boolean().optional(), topology: githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardPoolTopology.optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardSnapshot = z.object({arc: githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardARCPoint.optional(), generatedAt: z.number().int().optional(), pools: z.array(githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardPoolSnapshot).optional(), sampledAt: z.number().int().optional(), stale: z.boolean().optional()}); export const githubComAlchemillahqSylveInternalAPIResponseGithubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardSnapshot = z.object({data: githubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardSnapshot.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 the current ZFS dashboard snapshot * * GET /zfs/dashboard/snapshot */ export const getApiZfsDashboardSnapshot = async (options: GetApiZfsDashboardSnapshotOptions) => { 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/dashboard/snapshot${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(githubComAlchemillahqSylveInternalAPIResponseGithubComAlchemillahqSylveInternalInterfacesServicesZfsDashboardSnapshot, await res.json()) };