import {z} from 'zod' export type GetApiApiV1AnalyzeDocumentClusterIdArgs = {id: string, jq_filters?: {[key: string]: string} | undefined}; export type GetApiApiV1AnalyzeDocumentClusterIdOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const documentClusterDocumentDataInner = z.object({pk: z.number().int().optional(), name: z.string().max(1024).nullable().optional(), document_type: z.string().nullable().optional()}); export const documentCluster = z.object({pk: z.number().int().optional(), cluster_id: z.number().int().gte(-2147483648).lte(2147483647).optional(), name: z.string().max(300), self_name: z.string().max(200), description: z.string().max(300), cluster_by: z.string().max(100), using: z.string().max(20), created_date: z.string().optional(), documents_count: z.number().int().optional(), document_data: z.array(documentClusterDocumentDataInner).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 }; /** * Retrieve Document Cluster * * GET /api/v1/analyze/document-cluster/{id}/ */ export const getApiApiV1AnalyzeDocumentClusterId = async (args: GetApiApiV1AnalyzeDocumentClusterIdArgs, options: GetApiApiV1AnalyzeDocumentClusterIdOptions) => { 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/analyze/document-cluster/${encodeURIComponent(String(args.id))}/${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(documentCluster, await res.json()) };