import {z} from 'zod' export type DocumentDetailStatusData = {id?: number | undefined, name: string, code?: (string | null) | undefined, order: number, is_active?: boolean | undefined, group?: (number | null) | undefined}; export type DocumentDetailAssigneeData = {pk?: number | undefined, first_name?: string | undefined, last_name?: string | undefined, username: string, photo?: string | undefined, name?: string | undefined, initials?: string | undefined} | null; export type DocumentDetailAvailableAssigneesDataInner = {pk?: number | undefined, first_name?: string | undefined, last_name?: string | undefined, username: string, photo?: string | undefined, name?: string | undefined, initials?: string | undefined}; export type DocumentDetail = {pk?: number | undefined, name?: (string | null) | undefined, document_type?: (string | null) | undefined, file_size?: number | undefined, folder?: (string | null) | undefined, created_date?: (string | null) | undefined, modified_date?: (string | null) | undefined, modified_by_name: string, created_by_name: string, created_by_initials: string, created_by_photo: string, modified_by_initials: string, modified_by_photo: string, status?: (number | null) | undefined, status_data: DocumentDetailStatusData, available_statuses_data?: Array> | undefined, assignee?: (number | null) | undefined, assign_date?: (string | null) | undefined, assignee_data: DocumentDetailAssigneeData, available_assignees_data: Array | null, description?: (string | null) | undefined, title?: (string | null) | undefined, initial_annotation_id?: string | undefined, page_locations?: Array> | undefined, page_bounds?: Array> | undefined, field_values?: Record | undefined, field_value_objects?: Record | undefined, prev_id?: number | undefined, next_id?: number | undefined, position?: string | undefined, documents_count?: string | undefined, sections?: Array> | undefined, cluster_id?: string | undefined, was_opened_in_annotator?: boolean | undefined, user_permissions?: Record | undefined}; export type PatchApiApiV1DocumentProjectProjectPkDocumentsIdArgs = {project_pk: string, id: string, body: DocumentDetail}; export type PatchApiApiV1DocumentProjectProjectPkDocumentsIdOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const documentDetailStatusData = z.object({id: z.number().int().optional(), name: z.string().max(100), code: z.string().max(100).nullable().optional(), order: z.number().int().gte(0).lte(32767), is_active: z.boolean().optional(), group: z.number().int().nullable().optional()}); export const documentDetailAssigneeData = 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()}).nullable(); export const documentDetailAvailableAssigneesDataInner = 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 documentDetail = z.object({pk: z.number().int().optional(), name: z.string().max(1024).nullable().optional(), document_type: z.string().nullable().optional(), file_size: z.number().int().gte(0).lte(2147483647).optional(), folder: z.string().max(1024).nullable().optional(), created_date: z.string().nullable().optional(), modified_date: z.string().nullable().optional(), modified_by_name: z.string(), created_by_name: z.string(), created_by_initials: z.string(), created_by_photo: z.string(), modified_by_initials: z.string(), modified_by_photo: z.string(), status: z.number().int().nullable().optional(), status_data: documentDetailStatusData, available_statuses_data: z.array(z.object({})).optional(), assignee: z.number().int().nullable().optional(), assign_date: z.string().nullable().optional(), assignee_data: documentDetailAssigneeData, available_assignees_data: z.array(documentDetailAvailableAssigneesDataInner).nullable(), description: z.string().nullable().optional(), title: z.string().max(1024).nullable().optional(), initial_annotation_id: z.string().optional(), page_locations: z.array(z.array(z.number().int())).optional(), page_bounds: z.array(z.array(z.number())).optional(), field_values: z.object({}).optional(), field_value_objects: z.object({}).optional(), prev_id: z.number().int().optional(), next_id: z.number().int().optional(), position: z.string().optional(), documents_count: z.string().optional(), sections: z.array(z.object({})).optional(), cluster_id: z.string().optional(), was_opened_in_annotator: z.boolean().optional(), user_permissions: 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 }; /** * PATCH /api/v1/document/project/{project_pk}/documents/{id}/ */ export const patchApiApiV1DocumentProjectProjectPkDocumentsId = async (args: PatchApiApiV1DocumentProjectProjectPkDocumentsIdArgs, options: PatchApiApiV1DocumentProjectProjectPkDocumentsIdOptions) => { 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/project/${encodeURIComponent(String(args.project_pk))}/documents/${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(documentDetail, await res.json()) };