import {z} from 'zod' export type ResolutionType = {height?: number | undefined, width?: number | undefined}; export type TimeBaseType = {denominator?: number | undefined, numerator?: number | undefined}; export type TimeCodeType = {frames_number?: number | undefined, is_drop_frame?: boolean | undefined, time_base?: TimeBaseType | undefined}; export type PlaylistKeyframeUpdateSchema = {date_created?: string | undefined, date_modified?: string | undefined, filename?: string | undefined, format?: (string | null) | undefined, is_custom_keyframe?: boolean | undefined, is_public?: boolean | undefined, name?: string | undefined, resolution?: ResolutionType | undefined, rotation?: (number | null) | undefined, size?: (number | null) | undefined, status?: ('OPEN' | 'GROWING' | 'AWAITED' | 'CLOSED' | 'FAILED' | 'ARCHIVED' | 'MISSING' | 'REDISCOVERED' | 'DELETED') | undefined, time_code?: TimeCodeType | undefined, type: 'KEYFRAME_MAP' | 'KEYFRAME' | 'POSTER', url?: string | undefined}; export type PatchApiV1PlaylistsPlaylistIdKeyframesKeyframeIdArgs = {'App-ID': string, 'Auth-Token': string, playlist_id: string, keyframe_id: string, body: PlaylistKeyframeUpdateSchema}; export type PatchApiV1PlaylistsPlaylistIdKeyframesKeyframeIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const resolutionType = z.object({height: z.number().int().gte(-2147483648).lte(2147483647).optional(), width: z.number().int().gte(-2147483648).lte(2147483647).optional()}); export const timeBaseType = z.object({denominator: z.number().int().gte(-2147483648).lte(2147483647).optional(), numerator: z.number().int().gte(-2147483648).lte(2147483647).optional()}); export const timeCodeType = z.object({frames_number: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).optional(), is_drop_frame: z.boolean().optional(), time_base: timeBaseType.optional()}); export const playlistKeyframeSchema = z.object({date_created: z.string().optional(), date_modified: z.string().optional(), filename: z.string().optional(), format: z.string().nullable().optional(), id: z.string().optional(), is_custom_keyframe: z.boolean().optional(), is_public: z.boolean().optional(), name: z.string().optional(), playlist_id: z.string().optional(), resolution: resolutionType.optional(), rotation: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), size: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).nullable().optional(), status: z.enum(["OPEN", "GROWING", "AWAITED", "CLOSED", "FAILED", "ARCHIVED", "MISSING", "REDISCOVERED", "DELETED"]).optional(), storage_id: z.string().optional(), time_code: timeCodeType.optional(), type: z.enum(["KEYFRAME_MAP", "KEYFRAME", "POSTER"]), url: 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 keyframe information * * PATCH /v1/playlists/{playlist_id}/keyframes/{keyframe_id}/ */ export const patchApiV1PlaylistsPlaylistIdKeyframesKeyframeId = async (args: PatchApiV1PlaylistsPlaylistIdKeyframesKeyframeIdArgs, options: PatchApiV1PlaylistsPlaylistIdKeyframesKeyframeIdOptions) => { 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/playlists/${encodeURIComponent(String(args.playlist_id))}/keyframes/${encodeURIComponent(String(args.keyframe_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(playlistKeyframeSchema, await res.json()) };