import {z} from 'zod' export type GetApiContentArtistAllSummaryArgs = {query?: string | undefined, releaseId?: number | undefined, trackId?: number | undefined, withContext?: boolean | undefined, archived?: boolean | undefined}; export type GetApiContentArtistAllSummaryOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const imageDTO = z.object({fileId: z.string().optional(), isTemp: z.boolean().optional(), filename: z.string().optional(), externalUrl: z.string().optional(), lastUpdateDate: z.string().optional()}); export const artistSummaryDTO = z.object({artistId: z.number().int().optional(), name: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), middleName: z.string().optional(), spotifyArtistKey: z.string().optional(), isni: z.string().optional(), releasesCount: z.number().int().optional(), tracksCount: z.number().int().optional(), archivedAt: z.string().optional(), image: imageDTO.optional()}); export const getApiContentArtistAllSummaryResponse = z.array(artistSummaryDTO); 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 /content/artist/all/summary */ export const getApiContentArtistAllSummary = async (args: GetApiContentArtistAllSummaryArgs, options?: GetApiContentArtistAllSummaryOptions) => { const {baseUrl = "http://api.revelator.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.query != null) query.append("query", String(args.query)) if (args.releaseId != null) query.append("releaseId", String(args.releaseId)) if (args.trackId != null) query.append("trackId", String(args.trackId)) if (args.withContext != null) query.append("withContext", String(args.withContext)) if (args.archived != null) query.append("archived", String(args.archived)) const url = `${baseUrl.replace(/\/+$/, '')}/content/artist/all/summary${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(getApiContentArtistAllSummaryResponse, await res.json()) };