import {z} from 'zod' export type UpdateApiBatchBatchIdAudioIdArgs = {body: {data: {id: string, type: 'audio', attributes: {category?: ('b-roll' | 'briefings' | 'greetings' | 'interviews' | 'newscasts' | 'recording') | undefined, title: string, description: string, instructions?: string | undefined, notes?: string | undefined, tags?: Array | undefined, created_at: string, subdiv?: string | undefined, country: string, city?: string | undefined, status?: ('unpublished' | 'published' | 'uploaded' | 'needs-approval') | undefined, id3_artist?: string | undefined, id3_album?: string | undefined, id3_genre?: string | undefined, id3_composer?: string | undefined, id3_conductor?: string | undefined, id3_track?: number | undefined, id3_disc_number?: number | undefined, id3_year?: number | undefined}, relationships: {authors?: {data: Array<{id: string, type: 'author'}>} | undefined, batch?: {data: {id: string, type: 'batch'}} | undefined, batch_upload: {data: {id: string, type: 'batch-upload' | 'batch-multipart-upload'}}, hometowns?: {data: Array<{id: string, type: 'location'}>} | undefined, themes?: {data: Array<{id: string, type: 'theme'}>} | undefined, service_unit: {data: {id: string, type: 'service-unit'}}}}}}; export type UpdateApiBatchBatchIdAudioIdOptions = {baseUrl?: string | undefined, DVIDS?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiBatchBatchIdAudioIdResponse = z.object({data: z.object({id: z.string(), type: z.literal("audio"), attributes: z.object({category: z.enum(["b-roll", "briefings", "greetings", "interviews", "newscasts", "recording"]).optional(), title: z.string().max(255), description: z.string().max(65535), instructions: z.string().max(65535).optional(), notes: z.string().max(65535).optional(), tags: z.array(z.string().max(100)).optional(), created_at: z.string(), subdiv: z.string().max(50).optional(), country: z.string().max(2), city: z.string().max(75).optional(), status: z.enum(["unpublished", "published", "uploaded", "needs-approval"]).optional(), id3_artist: z.string().max(100).optional(), id3_album: z.string().max(100).optional(), id3_genre: z.string().max(100).optional(), id3_composer: z.string().max(100).optional(), id3_conductor: z.string().max(100).optional(), id3_track: z.number().int().optional(), id3_disc_number: z.number().int().optional(), id3_year: z.number().int().optional()}), relationships: z.object({authors: z.object({data: z.array(z.object({id: z.string(), type: z.literal("author")}))}).optional(), batch: z.object({data: z.object({id: z.string(), type: z.literal("batch")})}).optional(), batch_upload: z.object({data: z.object({id: z.string(), type: z.enum(["batch-upload", "batch-multipart-upload"])})}), hometowns: z.object({data: z.array(z.object({id: z.string(), type: z.literal("location")}))}).optional(), themes: z.object({data: z.array(z.object({id: z.string(), type: z.literal("theme")}))}).optional(), service_unit: z.object({data: z.object({id: z.string(), type: z.literal("service-unit")})})})})}); 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 an audio clip by id * * PUT /batch/{batch_id}/audio/{id} */ export const updateApiBatchBatchIdAudioId = async (args: UpdateApiBatchBatchIdAudioIdArgs, options?: UpdateApiBatchBatchIdAudioIdOptions) => { const {baseUrl = "https://submitapi.dvidshub.net", fetch: fetchFn = fetch, DVIDS} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") headers.set('accept', "application/vnd.api+json") if (DVIDS !== undefined) headers.set('authorization', `Bearer ${DVIDS}`) const url = `${baseUrl.replace(/\/+$/, '')}/batch/${encodeURIComponent(String(args.batch_id))}/audio/${encodeURIComponent(String(args.id))}${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(updateApiBatchBatchIdAudioIdResponse, await res.json()) };