import {z} from 'zod' export type GetApiPublicDataQualityV1DataQualityRuleArgs = {descSort?: boolean | undefined}; export type GetApiPublicDataQualityV1DataQualityRuleOptions = {baseUrl: string, httpAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dataQualityRuleKind = z.literal("DataQualityRule"); export const mapLabelKeyString = z.record(z.string(), z.string()); export const attachedPolicy = z.object({name: z.string(), displayName: z.string().optional(), readAccess: z.boolean()}); export const dataQualityRuleMetadataOutput = z.object({name: z.string(), labels: mapLabelKeyString.optional(), createdAt: z.string(), updatedAt: z.string(), createdBy: z.string(), updatedBy: z.string(), attachedPolicies: z.array(attachedPolicy).optional(), builtIn: z.boolean()}); export const cel = z.object({celExpression: z.string(), displayName: z.string(), description: z.string().optional(), customErrorMessage: z.string().optional(), type: z.literal("Cel")}); export const enforceAvro = z.object({displayName: z.string(), description: z.string().optional(), customErrorMessage: z.string().optional(), type: z.literal("EnforceAvro")}); export const enforceSchemaId = z.object({displayName: z.string(), description: z.string().optional(), customErrorMessage: z.string().optional(), type: z.literal("EnforceSchemaId")}); export const jsonObject = z.object({}); export const jsonSchema = z.object({schema: jsonObject, displayName: z.string(), description: z.string().optional(), customErrorMessage: z.string().optional(), type: z.literal("JsonSchema")}); export const dataQualityRuleSpecOutput = z.discriminatedUnion("type", [cel, enforceAvro, enforceSchemaId, jsonSchema]); export const dataQualityRuleOutputResourceV1 = z.object({apiVersion: z.string(), kind: dataQualityRuleKind, metadata: dataQualityRuleMetadataOutput, spec: dataQualityRuleSpecOutput}); export const getApiPublicDataQualityV1DataQualityRuleResponse = z.array(dataQualityRuleOutputResourceV1); 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 DataQualityRule resources * * GET /public/data-quality/v1/data-quality-rule */ export const getApiPublicDataQualityV1DataQualityRule = async (args: GetApiPublicDataQualityV1DataQualityRuleArgs, options: GetApiPublicDataQualityV1DataQualityRuleOptions) => { const {baseUrl, fetch: fetchFn = fetch, httpAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.descSort != null) query.append("descSort", String(args.descSort)) if (httpAuth !== undefined) headers.set('authorization', `Bearer ${httpAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/data-quality/v1/data-quality-rule${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(getApiPublicDataQualityV1DataQualityRuleResponse, await res.json()) };