import {z} from 'zod' export type InternalHandlersUtilitiesBulkDeleteDownloadRequest = {ids: Array}; export type CreateApiUtilitiesDownloadsBulkDeleteArgs = {body: InternalHandlersUtilitiesBulkDeleteDownloadRequest}; export type CreateApiUtilitiesDownloadsBulkDeleteOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadType = z.enum(["http", "torrent", "path"]); export const githubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteItem = z.object({id: z.number().int().optional(), name: z.string().optional(), type: githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadType.optional(), uuid: z.string().optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteVMReference = z.object({storageId: z.number().int().optional(), vmId: z.number().int().optional(), vmName: z.string().optional(), vmRid: z.number().int().optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteFailure = z.object({code: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), retainedPaths: z.array(z.string()).optional(), type: githubComAlchemillahqSylveInternalDbModelsUtilitiesDownloadType.optional(), uuid: z.string().optional(), vmReferences: z.array(githubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteVMReference).optional()}); export const githubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteResult = z.object({deleted: z.array(githubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteItem).optional(), failed: z.array(githubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteFailure).optional()}); export const githubComAlchemillahqSylveInternalAPIResponseGithubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteResult = z.object({data: githubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteResult.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 }; /** * Bulk Delete Downloads * * POST /utilities/downloads/bulk-delete */ export const createApiUtilitiesDownloadsBulkDelete = async (args: CreateApiUtilitiesDownloadsBulkDeleteArgs, options: CreateApiUtilitiesDownloadsBulkDeleteOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/utilities/downloads/bulk-delete${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(githubComAlchemillahqSylveInternalAPIResponseGithubComAlchemillahqSylveInternalInterfacesServicesUtilitiesDownloadDeleteResult, await res.json()) };