import {z} from 'zod' export type GetApi3CollectionCollectionIdImagesArgs = {collection_id: number, include_image_language?: string | undefined, language?: string | undefined}; export type GetApi3CollectionCollectionIdImagesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApi3CollectionCollectionIdImagesResponse = z.object({id: z.number().int().optional(), backdrops: z.array(z.object({aspect_ratio: z.number().optional(), height: z.number().int().optional(), iso_639_1: z.unknown(), file_path: z.string().optional(), vote_average: z.number().optional(), vote_count: z.number().int().optional(), width: z.number().int().optional()})).optional(), posters: z.array(z.object({aspect_ratio: z.number().optional(), height: z.number().int().optional(), iso_639_1: z.string().optional(), file_path: z.string().optional(), vote_average: z.number().optional(), vote_count: z.number().int().optional(), width: z.number().int().optional()})).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 }; /** * Images * * GET /3/collection/{collection_id}/images */ export const getApi3CollectionCollectionIdImages = async (args: GetApi3CollectionCollectionIdImagesArgs, options?: GetApi3CollectionCollectionIdImagesOptions) => { const {baseUrl = "https://api.themoviedb.org", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_image_language != null) query.append("include_image_language", String(args.include_image_language)) if (args.language != null) query.append("language", String(args.language)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/3/collection/${encodeURIComponent(String(args.collection_id))}/images${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(getApi3CollectionCollectionIdImagesResponse, await res.json()) };