import {z} from 'zod' export type GetApiUtilitiesDownloadsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadedFile = z.object({download: z.lazy(() => githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloads.optional()), downloadId: z.number().int().optional(), id: z.number().int().optional(), name: z.string().optional(), size: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadStatus = z.enum(["pending", "processing", "done", "failed"]); export const githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadType = z.enum(["http", "torrent", "path"]); export const githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadUType = z.enum(["base-rootfs", "cloud-init", "uncategorized"]); export const githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloads: z.ZodType = z.object({automaticExtraction: z.boolean().optional(), automaticRawConversion: z.boolean().optional(), createdAt: z.string().optional(), error: z.string().optional(), extractedPath: z.string().optional(), files: z.array(githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadedFile).optional(), id: z.number().int().optional(), ignoreTLS: z.boolean().optional(), isUpload: z.boolean().optional(), name: z.string().optional(), path: z.string().optional(), progress: z.number().int().optional(), size: z.number().int().optional(), status: githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadStatus.optional(), storagePool: z.string().optional(), type: githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadType.optional(), uType: githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadUType.optional(), updatedAt: z.string().optional(), url: z.string().optional(), uuid: z.string().optional()}); export const githubComAlchemillahqSylveInternalAPIResponseArrayGithubComAlchemillahqSylveInternalDbModelsUtilitiesDownloads = z.object({data: z.array(githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloads).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 }; /** * List Downloads * * GET /utilities/downloads */ export const getApiUtilitiesDownloads = async (options: GetApiUtilitiesDownloadsOptions) => { 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(/\/+$/, '')}/utilities/downloads${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(githubComAlchemillahqSylveInternalAPIResponseArrayGithubComAlchemillahqSylveInternalDbModelsUtilitiesDownloads, await res.json()) };