import {z} from 'zod' export type GetApiApiV1MusicArtistIdArgs = {id: string, releases?: boolean | undefined, tracks?: boolean | undefined, metadata?: boolean | undefined, summary?: boolean | undefined, playCount?: boolean | undefined, rating?: boolean | undefined}; export type GetApiApiV1MusicArtistIdOptions = {baseUrl: string, LocalUserJWT?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1MusicArtistIdResponse = z.object({}); 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 a single music artist. * * GET /api/v1/music/artist/{id} */ export const getApiApiV1MusicArtistId = async (args: GetApiApiV1MusicArtistIdArgs, options: GetApiApiV1MusicArtistIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, LocalUserJWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.releases != null) query.append("releases", String(args.releases)) if (args.tracks != null) query.append("tracks", String(args.tracks)) if (args.metadata != null) query.append("metadata", String(args.metadata)) if (args.summary != null) query.append("summary", String(args.summary)) if (args.playCount != null) query.append("playCount", String(args.playCount)) if (args.rating != null) query.append("rating", String(args.rating)) if (LocalUserJWT !== undefined) headers.set('authorization', `Bearer ${LocalUserJWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/music/artist/${encodeURIComponent(String(args.id))}${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(getApiApiV1MusicArtistIdResponse, await res.json()) };