import {z} from 'zod' export type DocumentNoteDetailUser = {pk?: number | undefined, first_name?: string | undefined, last_name?: string | undefined, username: string, photo?: string | undefined, name?: string | undefined, initials?: string | undefined}; export type DocumentNoteDetail = {pk?: number | undefined, note: string, timestamp?: string | undefined, user?: DocumentNoteDetailUser | undefined, location_start?: (number | null) | undefined, location_end?: (number | null) | undefined, document_id: number, field_value_id?: number | undefined, field_id?: string | undefined, selections?: Array> | undefined}; export type PatchApiApiV1DocumentDocumentNotesIdArgs = {id: string, body: DocumentNoteDetail}; export type PatchApiApiV1DocumentDocumentNotesIdOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const documentNoteDetailUser = z.object({pk: z.number().int().optional(), first_name: z.string().max(30).optional(), last_name: z.string().max(150).optional(), username: z.string().max(150), photo: z.string().optional(), name: z.string().max(255).optional(), initials: z.string().max(2).optional()}); export const documentNoteDetail = z.object({pk: z.number().int().optional(), note: z.string(), timestamp: z.string().optional(), user: documentNoteDetailUser.optional(), location_start: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), location_end: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), document_id: z.number().int(), field_value_id: z.number().int().optional(), field_id: z.string().optional(), selections: z.array(z.object({})).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 }; /** * Partial Update Document Note * * PATCH /api/v1/document/document-notes/{id}/ */ export const patchApiApiV1DocumentDocumentNotesId = async (args: PatchApiApiV1DocumentDocumentNotesIdArgs, options: PatchApiApiV1DocumentDocumentNotesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/document/document-notes/${encodeURIComponent(String(args.id))}/${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(documentNoteDetail, await res.json()) };