import {z} from 'zod' export type GetApiApiReleaseEventSeriesIdForEditArgs = {id: number}; export type GetApiApiReleaseEventSeriesIdForEditOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const eventCategory = z.enum(["Unspecified", "AlbumRelease", "Anniversary", "Club", "Concert", "Contest", "Convention", "Other", "Festival"]); export const contentLanguageSelection = z.enum(["Unspecified", "Japanese", "Romaji", "English"]); export const entryThumbForApiContract = z.object({mime: z.string().nullable().optional(), name: z.string().nullable().optional(), urlOriginal: z.string().nullable().optional(), urlSmallThumb: z.string().nullable().optional(), urlThumb: z.string().nullable().optional(), urlTinyThumb: z.string().nullable().optional()}); export const localizedStringWithIdContract = z.object({id: z.number().int().optional(), language: contentLanguageSelection.optional(), value: z.string().nullable().optional()}); export const entryStatus = z.enum(["Draft", "Finished", "Approved", "Locked"]); export const webLinkCategory = z.enum(["Official", "Commercial", "Reference", "Other"]); export const webLinkForApiContract = z.object({category: webLinkCategory.optional(), description: z.string().nullable().optional(), descriptionOrUrl: z.string().nullable().optional(), disabled: z.boolean().optional(), id: z.number().int().optional(), url: z.string().nullable().optional()}); export const releaseEventSeriesForEditForApiContract = z.object({category: eventCategory.optional(), defaultNameLanguage: contentLanguageSelection.optional(), deleted: z.boolean().optional(), description: z.string().nullable().optional(), id: z.number().int().optional(), mainPicture: entryThumbForApiContract.optional(), name: z.string().nullable().optional(), names: z.array(localizedStringWithIdContract).nullable().optional(), status: entryStatus.optional(), updateNotes: z.string().nullable().optional(), webLinks: z.array(webLinkForApiContract).nullable().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 }; /** * GET /api/releaseEventSeries/{id}/for-edit */ export const getApiApiReleaseEventSeriesIdForEdit = async (args: GetApiApiReleaseEventSeriesIdForEditArgs, options: GetApiApiReleaseEventSeriesIdForEditOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/releaseEventSeries/${encodeURIComponent(String(args.id))}/for-edit${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(releaseEventSeriesForEditForApiContract, await res.json()) };