UNPKG

supa-seed

Version:

A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support

181 lines 5.85 kB
/** * Constraint Enforcement System for Association Intelligence * Phase 3, Checkpoint C2 - Advanced constraint validation and conflict resolution */ import { LoadedAsset } from '../features/generation/assets/asset-loader'; import { DistributionAssignment } from './distribution-algorithms'; export interface ConstraintRule { id: string; name: string; type: 'count' | 'content' | 'relationship' | 'temporal' | 'custom'; priority: 'low' | 'medium' | 'high' | 'critical'; description: string; validator: (assignment: DistributionAssignment, context: ValidationContext) => ConstraintValidationResult; conflictResolver?: (violation: ConstraintViolation, context: ResolutionContext) => ConstraintResolution | null; } export interface ValidationContext { allAssignments: DistributionAssignment[]; allAssets: LoadedAsset[]; globalConfig: ConstraintConfig; metadata: Record<string, any>; } export interface ResolutionContext extends ValidationContext { conflictHistory: ConstraintViolation[]; resolutionAttempts: number; maxRetries: number; } export interface ConstraintValidationResult { isValid: boolean; violations: ConstraintViolation[]; warnings: ConstraintWarning[]; metadata: { executionTime: number; assetsEvaluated: number; rulesApplied: string[]; }; } export interface ConstraintViolation { ruleId: string; ruleName: string; severity: 'warning' | 'error' | 'critical'; message: string; affectedTargets: string[]; affectedAssets: string[]; violationType: 'insufficient' | 'excess' | 'invalid' | 'conflict'; suggestedResolutions: string[]; metadata: Record<string, any>; } export interface ConstraintWarning { ruleId: string; message: string; targets: string[]; recommendation: string; } export interface ConstraintResolution { strategy: 'redistribute' | 'relax_constraint' | 'add_fallback' | 'manual_intervention' | 'partial_fulfillment'; description: string; actions: ResolutionAction[]; confidence: number; impact: 'low' | 'medium' | 'high'; } export interface ResolutionAction { type: 'move_asset' | 'generate_fallback' | 'modify_constraint' | 'create_target' | 'remove_constraint'; description: string; parameters: Record<string, any>; reversible: boolean; } export interface ConstraintConfig { enforcementLevel: 'strict' | 'balanced' | 'permissive'; allowPartialFulfillment: boolean; autoResolveConflicts: boolean; maxResolutionAttempts: number; fallbackGeneration: boolean; priorityWeighting: Record<string, number>; customResolvers: Record<string, (violation: ConstraintViolation) => ConstraintResolution>; } export interface EnforcementResult { success: boolean; resolvedViolations: number; unresolvableViolations: ConstraintViolation[]; appliedResolutions: ConstraintResolution[]; finalAssignments: DistributionAssignment[]; enforcementReport: EnforcementReport; } export interface EnforcementReport { summary: string; statistics: { totalRulesEvaluated: number; violationsFound: number; violationsResolved: number; resolutionSuccessRate: number; executionTime: number; assetsAffected: number; targetsAffected: number; }; violationsByType: Record<string, number>; resolutionsByStrategy: Record<string, number>; recommendations: string[]; performanceMetrics: { validationTime: number; resolutionTime: number; memoryUsage: number; }; } export declare class ConstraintEnforcementEngine { private rules; private config; constructor(config: ConstraintConfig); /** * Add a custom constraint rule to the enforcement engine */ addRule(rule: ConstraintRule): void; /** * Remove a constraint rule from the enforcement engine */ removeRule(ruleId: string): boolean; /** * Validate all assignments against constraint rules */ validateAssignments(assignments: DistributionAssignment[], allAssets: LoadedAsset[]): ConstraintValidationResult; /** * Enforce constraints by resolving violations */ enforceConstraints(assignments: DistributionAssignment[], allAssets: LoadedAsset[]): EnforcementResult; /** * Apply a constraint resolution to the assignments */ private applyResolution; /** * Execute a specific resolution action */ private executeResolutionAction; /** * Move an asset from one target to another */ private moveAsset; /** * Generate fallback assets when insufficient assets are available */ private generateFallback; /** * Modify constraint parameters for a target */ private modifyConstraint; /** * Create a new target to accommodate excess assets */ private createTarget; /** * Remove a specific constraint from a target */ private removeConstraintFromTarget; /** * Get default resolution strategy for a violation */ private getDefaultResolution; /** * Generate comprehensive enforcement report */ private generateEnforcementReport; /** * Initialize built-in constraint rules */ private initializeBuiltInRules; /** * Get all available constraint rules */ getRules(): ConstraintRule[]; /** * Get constraint rule by ID */ getRule(ruleId: string): ConstraintRule | undefined; /** * Update constraint configuration */ updateConfig(newConfig: Partial<ConstraintConfig>): void; /** * Create a constraint enforcement engine with default configuration */ static createDefault(): ConstraintEnforcementEngine; } //# sourceMappingURL=constraint-enforcement.d.ts.map