import {z} from 'zod' export type FileSetSchema = {archive_file_set_id?: string | undefined, asset_id?: string | undefined, base_dir: string, component_ids: Array, date_created?: string | undefined, date_deleted?: string | undefined, date_modified?: string | undefined, deleted_by_user?: string | undefined, file_count?: number | undefined, format_id: string, id?: string | undefined, is_archive?: boolean | undefined, name: string, original_storage_id?: string | undefined, status?: ('ACTIVE' | 'ARCHIVED' | 'DELETED') | undefined, storage_id?: string | undefined, type?: ('REGULAR' | 'MANY_FILES') | undefined, version_id?: string | undefined}; export type PatchApiV1AssetsAssetIdFileSetsFileSetIdArgs = {'App-ID': string, 'Auth-Token': string, asset_id: string, file_set_id: string, body: FileSetSchema}; export type PatchApiV1AssetsAssetIdFileSetsFileSetIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const fileSetSchema = z.object({archive_file_set_id: z.string().optional(), asset_id: z.string().optional(), base_dir: z.string(), component_ids: z.array(z.string()), date_created: z.string().optional(), date_deleted: z.string().optional(), date_modified: z.string().optional(), deleted_by_user: z.string().optional(), file_count: z.number().int().gte(-2147483648).lte(2147483647).optional(), format_id: z.string(), id: z.string().optional(), is_archive: z.boolean().optional(), name: z.string(), original_storage_id: z.string().optional(), status: z.enum(["ACTIVE", "ARCHIVED", "DELETED"]).optional(), storage_id: z.string().optional(), type: z.enum(["REGULAR", "MANY_FILES"]).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 set information * * PATCH /v1/assets/{asset_id}/file_sets/{file_set_id}/ */ export const patchApiV1AssetsAssetIdFileSetsFileSetId = async (args: PatchApiV1AssetsAssetIdFileSetsFileSetIdArgs, options: PatchApiV1AssetsAssetIdFileSetsFileSetIdOptions) => { 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/assets/${encodeURIComponent(String(args.asset_id))}/file_sets/${encodeURIComponent(String(args.file_set_id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(fileSetSchema, await res.json()) };