import type { PolicyFilter } from "../types"; import type { JsonSchemaConnectorPolicy } from "./json-schema-types"; /** * A single logical branch within a JSON-Schema policy that matched the dataset. * Typically corresponds to one entry in schema.properties.properties.anyOf[*], * or an allOf group inside one of those entries. */ export interface PolicyBranchMatch { /** * Index into the top-level anyOf array under the policy's * `policy.properties.properties.anyOf`. */ branchIndex: number; /** * Required attribute names for this branch. These correspond to Schema.properties keys * like "sha256_hashed_email", "postal_code", etc. */ requiredAttributes: string[]; /** * Filters collected from the property definitions for this branch's required attributes. * Filters live on the property definitions (sibling `properties` to `anyOf`), not on branches. * These follow the existing PolicyFilter structure and can be fed directly into filterToSql. */ filters: PolicyFilter[]; /** * Additional required subfield paths per attribute, used to generate IS NOT NULL WHERE clauses. * Derived from `$ref` resolution against `$defs` in the JSON Schema. * * Example: for `sha256_hashed_phone_number` referencing an object-type `$def`, * this produces `(company_data."ds"."_rosetta_stone"."sha256_hashed_phone_number"."type" IS NOT NULL)`. */ additionalRequiredProperties: Array<{ attributeName: string; paths: string[]; }>; } /** * Evaluation result for a single JSON-Schema-based policy. */ export interface PolicyEvaluation { /** The policy that was evaluated. */ policy: JsonSchemaConnectorPolicy; /** Whether dataset.schema is compatible with the policy's JSON Schema. */ isValid: boolean; /** Branches within the policy that are satisfied for this dataset. */ matches: PolicyBranchMatch[]; /** Human-readable validation issues if isValid === false. */ errors: string[]; }