import {z} from 'zod' export type GetApiDestinationsDestinationIdDataIntegrityArgs = {destination_id: string, page_size?: number | undefined, order?: ('asc' | 'desc') | undefined, cursor?: string | undefined}; export type GetApiDestinationsDestinationIdDataIntegrityOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const mismatchedPartition = z.object({source_row_count: z.number().int(), destination_row_count: z.number().int(), last_modified_lower_bound_epoch: z.number().int(), last_modified_upper_bound_epoch: z.number().int()}); export const dataIntegrityResultResource = z.object({model_name: z.string(), is_healthy: z.boolean(), error_message: z.string(), sampling_rate: z.number(), total_rows_compared: z.number().int(), total_rows_stale: z.number().int(), total_rows_pending: z.number().int(), total_rows_missing: z.number().int(), total_rows_incorrect: z.number().int(), total_rows_orphaned: z.number().int(), mismatched_partitions: z.array(mismatchedPartition).optional()}); export const dataIntegrityJobResource = z.object({id: z.string(), org_schema: z.string(), submitted_at: z.string(), started_at: z.string(), ended_at: z.string(), destination_id: z.string(), status: z.string(), model_ids: z.array(z.string()), model_sample_primary_ids: z.record(z.string(), z.array(z.string())), data_integrity_results: z.array(dataIntegrityResultResource), log_message: z.string()}); export const listDataIntegrityJobResponse = z.object({jobs: z.array(dataIntegrityJobResource)}); export const getApiDestinationsDestinationIdDataIntegrityResponse = z.object({status: z.literal("success"), data: listDataIntegrityJobResponse, message: z.string(), has_next: z.boolean(), next_url: 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 }; /** * List data integrity jobs for a destination * * GET /destinations/{destination_id}/data-integrity */ export const getApiDestinationsDestinationIdDataIntegrity = async (args: GetApiDestinationsDestinationIdDataIntegrityArgs, options?: GetApiDestinationsDestinationIdDataIntegrityOptions) => { const {baseUrl = "https://api.prequel.co", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.order != null) query.append("order", String(args.order)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/destinations/${encodeURIComponent(String(args.destination_id))}/data-integrity${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(getApiDestinationsDestinationIdDataIntegrityResponse, await res.json()) };