import { type DatasetCatalogSource, type DimensionCatalogEntry, type MeasureCatalogEntry, type MetricCatalogEntry, type FilterCatalogEntry, type RelationshipCatalogEntry } from './catalog.js'; import type { DatasetLimits } from './types.js'; /** * Version of the semantic contract format. Bump when the serialized shape * changes in a way that snapshot consumers must account for. */ export declare const SEMANTIC_CONTRACT_VERSION = 2; export interface ContractDimension { type: DimensionCatalogEntry['type']; column?: string; sql?: string; label?: string; description?: string; filterable: boolean; groupable: boolean; } export interface ContractMeasure { aggregation: MeasureCatalogEntry['aggregation']; field: string; /** Second column for argMax/argMin. */ argField?: string; /** Percentile level in [0, 1]. */ level?: number; sql?: string; label?: string; description?: string; } export interface ContractMetric { kind: MetricCatalogEntry['kind']; valueType: MetricCatalogEntry['valueType']; label?: string; description?: string; dimensions: string[]; measures?: string[]; filters: string[]; grains: string[]; grain?: string; requires?: string[]; } export interface ContractFilter { field: string; label?: string; description?: string; operators: string[]; valueType?: FilterCatalogEntry['valueType']; } export interface ContractRelationship { kind: RelationshipCatalogEntry['kind']; target: string; from: string; to: string; queryable: boolean; fields: string[]; } export interface ContractDataset { name: string; source: string; tenantKey?: string; timeKey?: string; requiresTenant: boolean; supportedGrains: string[]; dimensions: Record; measures: Record; metrics: Record; filters: Record; relationships: Record; limits?: DatasetLimits; } export interface SemanticContract { version: number; datasets: Record; contentHash: string; } type SemanticContractWithoutHash = Omit; export interface SerializeSemanticContractOptions { /** * Include raw `sql` escape-hatch expressions for dimensions/measures. * * Defaults to `true` for trusted contexts (snapshots, CI, codegen) where the * SQL already lives in the developer's source. Set to `false` when serving the * contract to untrusted consumers so internal SQL is not exposed. */ includeSql?: boolean; } /** * Builds a deterministic semantic contract from dataset instances. * * The contract is a normalized, sorted projection of the dataset catalog with a * version marker and content hash. Object keys and unordered arrays are sorted, * and SQL escape hatches are whitespace-normalized so logically equal models * produce identical JSON and hashes. This is the shared source consumed by * snapshots, diffs, CI validation, docs, and codegen. */ export declare function serializeSemanticContract(datasets: Record, options?: SerializeSemanticContractOptions): SemanticContract; /** * Serializes a contract with stable formatting for writing to disk and hashing. */ export declare function contractToStableJson(contract: SemanticContract | SemanticContractWithoutHash): string; /** * Computes the SHA-256 content hash for a normalized contract. * * Uses `@noble/hashes` (audited, isomorphic, synchronous) rather than * `node:crypto` so the contract stays usable in browser/edge runtimes. */ export declare function hashContract(contract: SemanticContract | SemanticContractWithoutHash): string; export {}; //# sourceMappingURL=contract.d.ts.map