import {z} from 'zod' export type RuleUrn = string; export type CorrelationIdRequest = string; export type DqThresholdRequest = {severity?: string | undefined, value?: number | undefined, correlationId?: CorrelationIdRequest | undefined}; export type RuleParameterUrn = string; export type RuleParameterInstanceRequest = {correlationId?: CorrelationIdRequest | undefined, value?: string | undefined, ruleParameterUrn?: RuleParameterUrn | undefined}; export type CatalogAttributeUrn = string; export type RuleAttributeUrn = string; export type RuleMappingRequest = {catalogItemAttributeUrn?: CatalogAttributeUrn | undefined, ruleAttributeUrn?: RuleAttributeUrn | undefined, correlationId?: CorrelationIdRequest | undefined}; export type SubEntityKey = string; export type ConnectedMappingRequest = {connectedCatalogItemAttributeUrn: CatalogAttributeUrn, ruleAttributeUrn: RuleAttributeUrn, joinConfigurationKey: SubEntityKey, correlationId?: CorrelationIdRequest | undefined}; export type RuleInstanceWithMappingRequest = {ruleUrn?: RuleUrn | undefined, ruleInstanceName?: string | undefined, correlationId?: CorrelationIdRequest | undefined, dqThresholds?: {[key: string]: DqThresholdRequest} | undefined, parameterValues?: {[key: string]: RuleParameterInstanceRequest} | undefined, mappings?: {[key: string]: RuleMappingRequest} | undefined, connectedMappings?: {[key: string]: ConnectedMappingRequest} | undefined, enabled?: boolean | undefined}; export type InvalidSamplesConfiguration = {enabled?: boolean | undefined, sampleSize?: number | undefined}; export type ScheduleRequest = {cronExpression?: string | undefined, enabled?: boolean | undefined, ignoreMisfires?: boolean | undefined, description?: string | undefined, timeZone?: string | undefined, startAt?: string | undefined, endAt?: string | undefined, priority?: number | undefined}; export type AnomalyDetectionConfiguration = {enabled?: boolean | undefined}; export type ProfilingConfiguration = {enabled?: boolean | undefined, type?: string | undefined, sampleLimitCount?: number | undefined, sampleLimitPercentage?: number | undefined}; export type DqMonitorExportDefinitionRequest = {name?: string | undefined, type?: string | undefined, format?: string | undefined, correlationId?: CorrelationIdRequest | undefined, limit?: number | undefined, targetLocation?: Array | undefined, attributeUrns?: Array | undefined, enabled?: boolean | undefined}; export type CatalogItemUrn = string; export type ForeignKeyPairRequest = {localAttributeUrn?: CatalogAttributeUrn | undefined, connectedAttributeUrn?: CatalogAttributeUrn | undefined, correlationId?: CorrelationIdRequest | undefined, localAttributeTransformation?: string | undefined, connectedAttributeTransformation?: string | undefined, localAttributeTransformationFriendly?: string | undefined, connectedAttributeTransformationFriendly?: string | undefined}; export type JoinConfigurationRequest = {correlationId?: CorrelationIdRequest | undefined, connectedCatalogItemUrn?: CatalogItemUrn | undefined, foreignKeyPairs?: {[key: string]: ForeignKeyPairRequest} | undefined}; export type DataSlicePredicateRequest = {attributeUrn: CatalogAttributeUrn, operator: string, value?: string | undefined, listValues?: Array | undefined, rangeStart?: string | undefined, rangeEnd?: string | undefined}; export type DataSliceRequest = {label?: string | undefined, predicates: Array}; export type DqMonitorBatchCreateItemRequest = {name: string, manualRuleInstances?: ({[key: string]: RuleInstanceWithMappingRequest} | null) | undefined, invalidSamplesConfiguration?: (InvalidSamplesConfiguration | null) | undefined, schedule?: (ScheduleRequest | null) | undefined, anomalyDetectionConfiguration?: (AnomalyDetectionConfiguration | null) | undefined, profilingConfiguration?: (ProfilingConfiguration | null) | undefined, exportDefinitions?: ({[key: string]: DqMonitorExportDefinitionRequest} | null) | undefined, overallDqThresholds?: ({[key: string]: DqThresholdRequest} | null) | undefined, joinConfigurations?: ({[key: string]: JoinConfigurationRequest} | null) | undefined, dataSlice?: (DataSliceRequest | null) | undefined, id?: string | undefined, catalogItemUrn: CatalogItemUrn}; export type CreateApiDataQualityV1DqMonitorsBatchCreateArgs = {body: {data: Array}}; export type CreateApiDataQualityV1DqMonitorsBatchCreateOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const batchOperationMeta = z.object({total: z.number().int(), success: z.number().int(), fail: z.number().int()}); export const dqMonitorUrn = z.string(); export const subEntityKey = z.string(); export const problemDetail = z.object({type: z.string(), title: z.string(), detail: z.string()}); export const dqMonitorBatchResultItemResponse = z.union([z.object({id: z.string().optional(), status: z.string(), data: z.object({urn: dqMonitorUrn, correlationIds: z.record(z.string(), subEntityKey).optional()}), error: problemDetail.optional()}), z.object({id: z.string().optional(), status: z.string(), data: z.object({urn: dqMonitorUrn, correlationIds: z.record(z.string(), subEntityKey).optional()}).optional(), error: problemDetail})]); export const createApiDataQualityV1DqMonitorsBatchCreateResponse = z.object({meta: batchOperationMeta, results: z.array(dqMonitorBatchResultItemResponse)}); 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 }; /** * Create DQ monitors in batch * * POST /data-quality/v1/dq-monitors/batch/create */ export const createApiDataQualityV1DqMonitorsBatchCreate = async (args: CreateApiDataQualityV1DqMonitorsBatchCreateArgs, options?: CreateApiDataQualityV1DqMonitorsBatchCreateOptions) => { const {baseUrl = "https://your-environment.ataccama.one/api", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/data-quality/v1/dq-monitors/batch/create${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(createApiDataQualityV1DqMonitorsBatchCreateResponse, await res.json()) };