import {z} from 'zod' export type DataCheckSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, dataAssetId?: boolean | undefined, dataStoreId?: boolean | undefined, name?: boolean | undefined, description?: boolean | undefined, checkType?: boolean | undefined, columnName?: boolean | undefined, segmentColumn?: boolean | undefined, acceptedValues?: boolean | undefined, pattern?: boolean | undefined, formatPreset?: boolean | undefined, samplePercent?: boolean | undefined, referenceTableKey?: boolean | undefined, referenceColumnName?: boolean | undefined, customSql?: boolean | undefined, intervalInMinutes?: boolean | undefined, isEnabled?: boolean | undefined, isManagedByFile?: boolean | undefined, alertCondition?: boolean | undefined, alertThreshold?: boolean | undefined, monitorId?: boolean | undefined, dataReconciliationId?: boolean | undefined, lastRunAt?: boolean | undefined, lastRunStatus?: boolean | undefined, lastRunMessage?: boolean | undefined, lastValue?: boolean | undefined, failingRowsSample?: boolean | undefined, lastSegmentCount?: boolean | undefined, externalId?: boolean | undefined, createdByUserId?: boolean | undefined}; export type CreateApiDataCheckIdGetItemArgs = {id: string, body: {select?: DataCheckSelectSchema | undefined}}; export type CreateApiDataCheckIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const dataCheck = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), version: z.number().optional(), projectId: z.string(), dataAssetId: z.string(), dataStoreId: z.string().optional(), name: z.string(), description: z.string().optional(), checkType: z.enum(["Null Percent", "Duplicate Percent", "Distinct Count", "Minimum", "Maximum", "Average", "Sum", "Invalid Percent", "Format Mismatch Percent", "Orphan Count", "Row Count", "Custom SQL", "Failing Rows", "dbt Test"]), columnName: z.string().optional(), segmentColumn: z.string().optional(), acceptedValues: z.object({}).optional(), pattern: z.string().optional(), formatPreset: z.string().optional(), samplePercent: z.number().optional(), referenceTableKey: z.string().optional(), referenceColumnName: z.string().optional(), customSql: z.string().optional(), intervalInMinutes: z.number(), isEnabled: z.boolean(), isManagedByFile: z.boolean(), alertCondition: z.enum(["Unusually High", "Unusually Low", "Above", "Below"]).optional(), alertThreshold: z.number().optional(), monitorId: z.string().optional(), dataReconciliationId: z.string().optional(), lastRunAt: z.object({}).optional(), lastRunStatus: z.string().optional(), lastRunMessage: z.string().optional(), lastValue: z.number().optional(), failingRowsSample: z.object({}).optional(), lastSegmentCount: z.number().optional(), externalId: z.string().optional(), createdByUserId: z.string().optional()}); export const createApiDataCheckIdGetItemResponse = z.object({data: dataCheck.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 }; /** * Get Data Check * * POST /data-check/{id}/get-item */ export const createApiDataCheckIdGetItem = async (args: CreateApiDataCheckIdGetItemArgs, options?: CreateApiDataCheckIdGetItemOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/data-check/${encodeURIComponent(String(args.id))}/get-item${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiDataCheckIdGetItemResponse, await res.json()) };