import {z} from 'zod' export type GetApiZfsDatasetsPaginatedArgs = {datasetType: 'ALL' | 'SNAPSHOT' | 'FILESYSTEM' | 'VOLUME', page?: number | undefined, size?: number | undefined, search?: string | undefined, nameFilter?: string | undefined, 'sort[0][field]'?: ('name' | 'used' | 'referenced') | undefined, 'sort[0][dir]'?: ('asc' | 'desc') | undefined}; export type GetApiZfsDatasetsPaginatedOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gzfsZFSPropertySource = z.object({data: z.string().optional(), type: z.string().optional()}); export const gzfsZFSProperty = z.object({source: gzfsZFSPropertySource.optional(), value: z.string().optional()}); export const gzfsDatasetType = z.enum(["ALL", "FILESYSTEM", "VOLUME", "SNAPSHOT"]); export const gzfsDataset = z.object({available: z.number().int().optional(), compressratio: z.number().optional(), createtxg: z.string().optional(), guid: z.string().optional(), mountpoint: z.string().optional(), name: z.string().optional(), pool: z.string().optional(), properties: z.record(z.string(), gzfsZFSProperty).optional(), referenced: z.number().int().optional(), type: gzfsDatasetType.optional(), used: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesZfsPaginatedDatasetsResponse = z.object({data: z.array(gzfsDataset).optional(), last_page: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalAPIResponseGithubComAlchemillahqSylveInternalInterfacesServicesZfsPaginatedDatasetsResponse = z.object({data: githubComAlchemillahqSylveInternalInterfacesServicesZfsPaginatedDatasetsResponse.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 all ZFS Datasets with Pagination * * GET /zfs/datasets/paginated */ export const getApiZfsDatasetsPaginated = async (args: GetApiZfsDatasetsPaginatedArgs, options: GetApiZfsDatasetsPaginatedOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.datasetType != null) query.append("datasetType", String(args.datasetType)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.search != null) query.append("search", String(args.search)) if (args.nameFilter != null) query.append("nameFilter", String(args.nameFilter)) if (args['sort[0][field]'] != null) query.append("sort[0][field]", String(args['sort[0][field]'])) if (args['sort[0][dir]'] != null) query.append("sort[0][dir]", String(args['sort[0][dir]'])) if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/zfs/datasets/paginated${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(githubComAlchemillahqSylveInternalAPIResponseGithubComAlchemillahqSylveInternalInterfacesServicesZfsPaginatedDatasetsResponse, await res.json()) };