/** * Constraint analysis utilities for projections. * * Extracts static range/bounds information from IR constraint expressions * that use built-in constraint functions (min, max, between, length). * * This enables projections to emit: * - SQL CHECK constraints (Prisma @@check, raw SQL) * - Zod .min()/.max() validators * - OpenAPI schema minimum/maximum * * IMPORTANT: This is projection-side analysis only. It does NOT alter * IR semantics or runtime behavior. Constraints that cannot be statically * analyzed are silently skipped — the runtime still evaluates them. */ import type { IRExpression, IRConstraint } from './ir'; /** Extracted numeric range for a property */ export interface NumericRange { /** Minimum value (inclusive), if known */ min?: number; /** Maximum value (inclusive), if known */ max?: number; /** The property path this range applies to (e.g., "self.price") */ propertyPath: string; } /** Extracted string length constraint */ export interface LengthConstraint { /** Minimum length, if known */ minLength?: number; /** Maximum length, if known */ maxLength?: number; /** The property path this constraint applies to */ propertyPath: string; } /** Extracted regex pattern constraint for a property */ export interface PatternConstraint { /** The regex pattern string */ pattern: string; /** The property path this pattern applies to */ propertyPath: string; } /** Result of analyzing all constraints on an entity */ export interface ConstraintAnalysis { /** Numeric ranges extracted from min/max/between calls */ numericRanges: NumericRange[]; /** Length constraints extracted from length() comparisons */ lengthConstraints: LengthConstraint[]; /** Regex pattern constraints extracted from matches() calls */ patternConstraints: PatternConstraint[]; } /** * Analyze a single constraint expression and extract range information. * * Recognized patterns: * - `between(self.prop, minVal, maxVal)` → NumericRange * - `min(self.prop, minVal)` → NumericRange (lower bound) * - `max(self.prop, maxVal)` → NumericRange (upper bound) * - `length(self.prop) >= N` → LengthConstraint * - `length(self.prop) <= N` → LengthConstraint * - `self.prop >= N` / `self.prop > N` → NumericRange * - `self.prop <= N` / `self.prop < N` → NumericRange * - `matches(self.prop, "pattern")` → PatternConstraint */ export declare function analyzeConstraintExpression(expression: IRExpression): { numericRanges: NumericRange[]; lengthConstraints: LengthConstraint[]; patternConstraints: PatternConstraint[]; }; /** * Analyze all constraints on an entity and aggregate range/length information. * * Multiple constraints on the same property are merged (tightest bounds win). */ export declare function analyzeConstraints(constraints: IRConstraint[]): ConstraintAnalysis; /** * Convert a NumericRange to a SQL CHECK constraint expression. * * @param range - The numeric range to convert * @param column - The SQL column name (defaults to property path stripped of "self.") * @returns SQL CHECK expression or undefined if no bounds */ export declare function numericRangeToCheckConstraint(range: NumericRange, column?: string): string | undefined; /** * Convert a LengthConstraint to a SQL CHECK constraint expression. * * @param lc - The length constraint * @param column - The SQL column name * @returns SQL CHECK expression or undefined if no bounds */ export declare function lengthConstraintToCheckConstraint(lc: LengthConstraint, column?: string): string | undefined; /** * Convert a NumericRange to a Zod method chain (e.g., ".min(0).max(100)"). * * @param range - The numeric range * @returns Zod method chain string */ export declare function numericRangeToZodChain(range: NumericRange): string; /** * Convert a LengthConstraint to a Zod method chain (e.g., ".min(1).max(255)"). * * @param lc - The length constraint * @returns Zod method chain string */ export declare function lengthConstraintToZodChain(lc: LengthConstraint): string; /** * Convert a PatternConstraint to a SQL CHECK constraint expression. * * Uses the ~ operator (PostgreSQL regex match). Other DBs may need adaptation. * * @param pc - The pattern constraint * @param column - The SQL column name * @returns SQL CHECK expression */ export declare function patternConstraintToCheckConstraint(pc: PatternConstraint, column?: string): string; /** * Convert a PatternConstraint to a Zod method chain (e.g., ".regex(/pattern/)"). * * @param pc - The pattern constraint * @returns Zod method chain string */ export declare function patternConstraintToZodChain(pc: PatternConstraint): string; //# sourceMappingURL=constraint-analysis.d.ts.map