import {z} from 'zod' export type GetApiV1CollectionsCollectionIdContentInfoArgs = {'App-ID': string, 'Auth-Token': string, collection_id: string, only_active?: boolean | undefined, include_subcollections?: boolean | undefined, format_name?: string | undefined, by_storage_id?: boolean | undefined, types?: string | undefined}; export type GetApiV1CollectionsCollectionIdContentInfoOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const storageContentInfo = z.object({assets_count: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), file_count: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), storage_id: z.string().optional(), total_duration_milliseconds: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), total_size: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional()}); export const collectionContentInfoSchema = z.object({assets_count: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), collections_count: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), storage_info: z.array(storageContentInfo).optional(), title: z.string().optional(), total_duration_milliseconds: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), total_proxy_size: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), total_size: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).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 aggregated information about collection * * GET /v1/collections/{collection_id}/content/info/ */ export const getApiV1CollectionsCollectionIdContentInfo = async (args: GetApiV1CollectionsCollectionIdContentInfoArgs, options: GetApiV1CollectionsCollectionIdContentInfoOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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'])) if (args.only_active != null) query.append("only_active", String(args.only_active)) if (args.include_subcollections != null) query.append("include_subcollections", String(args.include_subcollections)) if (args.format_name != null) query.append("format_name", String(args.format_name)) if (args.by_storage_id != null) query.append("by_storage_id", String(args.by_storage_id)) if (args.types != null) query.append("types", String(args.types)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/collections/${encodeURIComponent(String(args.collection_id))}/content/info/${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(collectionContentInfoSchema, await res.json()) };