supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
126 lines • 4.01 kB
TypeScript
/**
* Custom Relationship Manager for Epic 7: Configuration Extensibility Framework
* Manages custom table relationship definitions and validation
*/
import type { createClient } from '@supabase/supabase-js';
import { ExtendedSeedConfig } from '../core/types/config-types';
type SupabaseClient = ReturnType<typeof createClient>;
export interface CustomRelationshipDefinition {
id: string;
fromTable: string;
toTable: string;
relationshipType: 'one_to_one' | 'one_to_many' | 'many_to_many';
fromColumn: string;
toColumn: string;
isRequired: boolean;
cascadeDelete: boolean;
generationStrategy: 'sequential' | 'random' | 'weighted' | 'custom';
customGenerator?: string;
metadata?: {
description?: string;
businessRule?: string;
validationRules?: string[];
};
}
export interface JunctionTableDefinition {
tableName: string;
leftTable: string;
rightTable: string;
leftColumn: string;
rightColumn: string;
additionalColumns?: Array<{
name: string;
type: string;
defaultValue?: any;
}>;
}
export interface InheritanceRule {
parentTable: string;
childTable: string;
inheritedFields: string[];
overrideStrategy: 'extend' | 'replace' | 'merge';
}
export interface RelationshipValidationResult {
valid: boolean;
errors: string[];
warnings: string[];
recommendations: string[];
relationshipGraph: RelationshipGraph;
}
export interface RelationshipGraph {
nodes: Array<{
table: string;
type: 'entity' | 'junction';
columns: string[];
}>;
edges: Array<{
from: string;
to: string;
relationship: CustomRelationshipDefinition;
strength: 'strong' | 'weak';
}>;
cycles: string[][];
orphanTables: string[];
}
export interface RelationshipGenerationPlan {
executionOrder: string[];
batchGroups: Array<{
tables: string[];
canExecuteInParallel: boolean;
dependencies: string[];
}>;
junctionTableCreation: Array<{
junctionTable: string;
dependsOn: string[];
executionOrder: number;
}>;
estimatedComplexity: 'low' | 'medium' | 'high' | 'critical';
}
export declare class CustomRelationshipManager {
private client;
private relationshipCache;
constructor(client: SupabaseClient);
/**
* Comprehensive validation of custom relationship definitions
*/
validateCustomRelationships(relationships: ExtendedSeedConfig['customRelationships']): Promise<RelationshipValidationResult>;
/**
* Generate execution plan for relationship seeding
*/
generateRelationshipExecutionPlan(relationships: ExtendedSeedConfig['customRelationships']): Promise<RelationshipGenerationPlan>;
/**
* Create custom relationship generators
*/
createRelationshipGenerators(relationships: CustomRelationshipDefinition[]): Map<string, (fromId: any, context: any) => any>;
/**
* Apply inheritance rules to data
*/
applyInheritanceRules(data: Record<string, any[]>, inheritanceRules: InheritanceRule[]): Record<string, any[]>;
/**
* Private helper methods
*/
private validateSingleRelationship;
private validateJunctionTable;
private validateInheritanceRule;
private buildRelationshipGraph;
private analyzeRelationshipGraph;
private topologicalSortTables;
private createBatchGroups;
private planJunctionTableCreation;
private estimateRelationshipComplexity;
private detectCycles;
private findOrphanTables;
private getTableDependencies;
private canProcessInParallel;
private createSequentialGenerator;
private createRandomGenerator;
private createWeightedGenerator;
private createCustomGenerator;
private pickFields;
private mergeRecords;
private tableExists;
private columnExists;
private getTableColumns;
}
export {};
//# sourceMappingURL=custom-relationship-manager.d.ts.map