import {z} from 'zod' export type FileBaseSchema = {asset_id?: string | undefined, checksum?: (string | null) | undefined, date_created?: string | undefined, date_modified?: string | undefined, directory_path: string, file_date_created?: string | undefined, file_date_modified?: string | undefined, file_set_id?: string | undefined, format_id?: string | undefined, id?: string | undefined, name?: string | undefined, original_name: string, parent_id?: (string | null) | undefined, size?: number | undefined, status?: ('OPEN' | 'GROWING' | 'AWAITED' | 'CLOSED' | 'FAILED' | 'ARCHIVED' | 'MISSING' | 'REDISCOVERED' | 'DELETED') | undefined, storage_id?: string | undefined, template?: string | undefined, template_engine?: ('SIMPLE' | 'JINJA2' | 'null' | null) | undefined, type: 'FILE' | 'DIRECTORY' | 'SYMLINK' | 'SEQUENCE', user_id?: (string | null) | undefined, version_id?: string | undefined}; export type UpdateApiV1StoragesStorageIdFilesArgs = {'App-ID': string, 'Auth-Token': string, storage_id: string, body: FileBaseSchema}; export type UpdateApiV1StoragesStorageIdFilesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const fileBaseSchema = z.object({asset_id: z.string().optional(), checksum: z.string().nullable().optional(), date_created: z.string().optional(), date_modified: z.string().optional(), directory_path: z.string(), file_date_created: z.string().optional(), file_date_modified: z.string().optional(), file_set_id: z.string().optional(), format_id: z.string().optional(), id: z.string().optional(), name: z.string().optional(), original_name: z.string(), parent_id: z.string().nullable().optional(), size: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), status: z.enum(["OPEN", "GROWING", "AWAITED", "CLOSED", "FAILED", "ARCHIVED", "MISSING", "REDISCOVERED", "DELETED"]).optional(), storage_id: z.string().optional(), template: z.string().optional(), template_engine: z.enum(["SIMPLE", "JINJA2", "null"]).nullable().optional(), type: z.enum(["FILE", "DIRECTORY", "SYMLINK", "SEQUENCE"]), user_id: z.string().nullable().optional(), version_id: 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 }; /** * Update file by storage ID and path * * PUT /v1/storages/{storage_id}/files/ */ export const updateApiV1StoragesStorageIdFiles = async (args: UpdateApiV1StoragesStorageIdFilesArgs, options: UpdateApiV1StoragesStorageIdFilesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/storages/${encodeURIComponent(String(args.storage_id))}/files/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(fileBaseSchema, await res.json()) };