supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
143 lines • 4.36 kB
TypeScript
/**
* Dynamic Column Mapping System
* Automatically discovers and maps semantic fields to actual database columns
* Replaces hardcoded column assumptions with intelligent field detection
*/
import { SchemaIntrospectionResult, TablePattern } from './schema-introspector';
export interface SemanticField {
name: string;
description: string;
aliases: string[];
patterns: RegExp[];
dataType: 'string' | 'number' | 'boolean' | 'date' | 'uuid' | 'email' | 'url' | 'json';
required: boolean;
category: 'identity' | 'content' | 'metadata' | 'relationship' | 'system';
defaultValue?: any;
validation?: {
minLength?: number;
maxLength?: number;
pattern?: RegExp;
enumValues?: string[];
};
}
export interface ColumnMapping {
semanticField: string;
actualColumn: string;
confidence: number;
evidence: string[];
dataTypeMatch: boolean;
constraintMatch: boolean;
alternativeColumns?: string[];
}
export interface TableColumnMap {
tableName: string;
mappings: ColumnMapping[];
unmappedColumns: string[];
unmappedSemanticFields: string[];
confidence: number;
recommendations: MappingRecommendation[];
}
export interface MappingRecommendation {
type: 'column_rename' | 'add_column' | 'use_alternative' | 'ignore_field';
message: string;
semanticField?: string;
currentColumn?: string;
suggestedColumn?: string;
priority: 'high' | 'medium' | 'low';
impact: string;
}
export interface MappingConfig {
strictMode: boolean;
enablePatternMatching: boolean;
enableFuzzyMatching: boolean;
minimumConfidence: number;
preferExactMatches: boolean;
allowMultipleMappings: boolean;
customMappings?: Record<string, Record<string, string>>;
}
export declare class DynamicColumnMapper {
private semanticFields;
private config;
constructor(config?: MappingConfig);
/**
* Create column mappings for all tables in the schema
*/
createMappings(schemaInfo: SchemaIntrospectionResult): Promise<Map<string, TableColumnMap>>;
/**
* Create column mapping for a specific table
*/
createTableMapping(tablePattern: TablePattern, schemaInfo: SchemaIntrospectionResult): Promise<TableColumnMap>;
/**
* Find the best column mapping for a semantic field
*/
private findBestColumnMapping;
/**
* Score how well a column matches a semantic field
*/
private scoreColumnMatch;
/**
* Check if data types are compatible
*/
private isDataTypeCompatible;
/**
* Check if constraints are compatible
*/
private isConstraintCompatible;
/**
* Calculate fuzzy string match score
*/
private calculateFuzzyMatch;
/**
* Calculate Levenshtein distance between two strings
*/
private levenshteinDistance;
/**
* Create a custom mapping with high confidence
*/
private createCustomMapping;
/**
* Calculate overall confidence for a table mapping
*/
private calculateTableConfidence;
/**
* Generate recommendations for improving mappings
*/
private generateRecommendations;
/**
* Initialize semantic field definitions
*/
private initializeSemanticFields;
/**
* Get semantic fields for a table type
*/
private getSemanticFieldsForTable;
/**
* Get default configuration
*/
private getDefaultConfig;
/**
* Utility method to remove item from array
*/
private removeFromArray;
/**
* Get mapping for a specific table and semantic field
*/
getMapping(tableMappings: Map<string, TableColumnMap>, tableName: string, semanticField: string): string | null;
/**
* Validate existing mappings against current schema
*/
validateMappings(tableMappings: Map<string, TableColumnMap>, schemaInfo: SchemaIntrospectionResult): Promise<{
valid: boolean;
invalidMappings: Array<{
table: string;
field: string;
reason: string;
}>;
missingTables: string[];
}>;
/**
* Export mappings to configuration format
*/
exportMappings(tableMappings: Map<string, TableColumnMap>): Record<string, Record<string, string>>;
}
//# sourceMappingURL=dynamic-column-mapper.d.ts.map