import {z} from 'zod' export type GetApiApiV1AnalyzeDocumentSimilarityListArgs = {jq_filters?: {[key: string]: string} | undefined}; export type GetApiApiV1AnalyzeDocumentSimilarityListOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const documentSimilarityRun = z.object({id: z.number().int().optional(), project_id: z.string().optional(), feature_source: z.string().max(50).nullable().optional(), unit_source: z.string().max(50).nullable().optional(), unit_type: z.string().max(50).nullable().optional(), unit_id: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), items_count: z.number().int(), created_by: z.number().int().nullable().optional(), created_date: z.string().optional()}); export const documentSimilarity = z.object({document_a__name: z.string().optional(), document_a__pk: z.string().optional(), document_b__name: z.string().optional(), document_b__pk: z.string().optional(), similarity: z.string(), run: documentSimilarityRun.optional()}); export const getApiApiV1AnalyzeDocumentSimilarityListResponse = z.array(documentSimilarity); 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 }; /** * Base Document Similarity List * * GET /api/v1/analyze/document-similarity/list/ */ export const getApiApiV1AnalyzeDocumentSimilarityList = async (args: GetApiApiV1AnalyzeDocumentSimilarityListArgs, options: GetApiApiV1AnalyzeDocumentSimilarityListOptions) => { 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-similarity/list/${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(getApiApiV1AnalyzeDocumentSimilarityListResponse, await res.json()) };