import {z} from 'zod' export type FormaatEnum = 'tekst' | 'getal' | 'datum' | 'datum_tijd'; export type EigenschapSpecificatie = {groep?: string | undefined, formaat: FormaatEnum, lengte: string, kardinaliteit: string, waardenverzameling?: Array | undefined}; export type PatchedEigenschap = {url?: string | undefined, naam?: string | undefined, catalogus?: string | undefined, definitie?: string | undefined, specificatie?: EigenschapSpecificatie | undefined, toelichting?: string | undefined, zaaktype?: string | undefined, zaaktypeIdentificatie?: string | undefined, statustype?: (string | null) | undefined, beginGeldigheid?: (string | null) | undefined, eindeGeldigheid?: (string | null) | undefined, beginObject?: (string | null) | undefined, eindeObject?: (string | null) | undefined}; export type PatchApiEigenschappenUuidArgs = {uuid: string, 'Content-Type': 'application/json', body: PatchedEigenschap}; export type PatchApiEigenschappenUuidOptions = {baseUrl?: string | undefined, JWTClaims?: string | undefined, fetch?: typeof fetch | undefined}; export const formaatEnum = z.enum(["tekst", "getal", "datum", "datum_tijd"]); export const eigenschapSpecificatie = z.object({groep: z.string().max(32).optional(), formaat: formaatEnum, lengte: z.string().max(14), kardinaliteit: z.string().max(3), waardenverzameling: z.array(z.string().max(100)).optional()}); export const eigenschap = z.object({url: z.string().min(1).max(1000), naam: z.string().max(20), catalogus: z.string(), definitie: z.string().max(255), specificatie: eigenschapSpecificatie, toelichting: z.string().max(1000).optional(), zaaktype: z.string(), zaaktypeIdentificatie: z.string(), statustype: z.string().nullable().optional(), beginGeldigheid: z.string().nullable().optional(), eindeGeldigheid: z.string().nullable().optional(), beginObject: z.string().nullable().optional(), eindeObject: z.string().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 }; /** * Werk een EIGENSCHAP deels bij. * * PATCH /eigenschappen/{uuid} */ export const patchApiEigenschappenUuid = async (args: PatchApiEigenschappenUuidArgs, options?: PatchApiEigenschappenUuidOptions) => { const {baseUrl = "https://virtserver.swaggerhub.com/michielverhoef/Catalogussen_API/1.3.0", fetch: fetchFn = fetch, JWTClaims} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (JWTClaims !== undefined) headers.set('authorization', `Bearer ${JWTClaims}`) const url = `${baseUrl.replace(/\/+$/, '')}/eigenschappen/${encodeURIComponent(String(args.uuid))}${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(eigenschap, await res.json()) };