import {z} from 'zod' export type GetApiApiV1DocumentDocumentFieldAnnotationsUidArgs = {uid: string, jq_filters?: {[key: string]: string} | undefined}; export type GetApiApiV1DocumentDocumentFieldAnnotationsUidOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const documentFieldAnnotation = z.object({pk: z.number().int().optional(), uid: z.string().optional(), project_id: z.number().int().optional(), project_name: z.string().optional(), document_id: z.string().optional(), document_name: z.string().optional(), document_type: z.string().optional(), document_status: z.string().optional(), field_id: z.string().optional(), field_name: z.string().optional(), value: z.object({}).nullable().optional(), location_start: z.number().int().gte(0).lte(2147483647).nullable().optional(), location_end: z.number().int().gte(0).lte(2147483647).nullable().optional(), location_text: z.string().nullable().optional(), assignee_id: z.number().int(), assign_date: z.string().nullable().optional(), status_id: z.number().int(), status_name: z.string().optional(), assignee_name: z.string().optional(), modified_by_id: z.string().optional(), modified_date: z.string().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 }; /** * Field Annotation Details (not Field Annotation False Match) * * GET /api/v1/document/document-field-annotations/{uid}/ */ export const getApiApiV1DocumentDocumentFieldAnnotationsUid = async (args: GetApiApiV1DocumentDocumentFieldAnnotationsUidArgs, options: GetApiApiV1DocumentDocumentFieldAnnotationsUidOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.jq_filters != null) query.append("jq_filters", JSON.stringify(args.jq_filters)) if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/document/document-field-annotations/${encodeURIComponent(String(args.uid))}/${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(documentFieldAnnotation, await res.json()) };