/** * SchemaAST Class * * The main class for working with schema graphs. * Provides graph operations like navigation, validation, and topological sorting. */ import type { ColumnNode, IndexNode, SchemaAST as ISchemaAST, RelationshipNode, RelationshipType, TableNode, ValidationError } from './types.js'; /** * Schema AST - A graph representation of a database schema. * * Enables: * - Graph navigation (dependencies, dependents) * - Circular dependency detection * - Topological sorting for correct DDL order * - Smart relation inference * - Schema validation */ export declare class SchemaAST implements ISchemaAST { readonly tables: Map; readonly relationships: RelationshipNode[]; readonly indexes: IndexNode[]; /** * Get a table by name. */ getTable(name: string): TableNode | undefined; /** * Add a table to the schema. */ addTable(table: TableNode): void; /** * Remove a table from the schema. */ removeTable(name: string): boolean; /** * Get all table nodes. */ getTables(): TableNode[]; /** * Get all table names. */ getTableNames(): string[]; /** * Get all tables that depend on this table (have FKs pointing to it). * These are tables that reference this table's primary key. */ getDependentTables(table: TableNode): TableNode[]; /** * Get all tables this table depends on (has FKs to). * These are tables that this table references. */ getDependencies(table: TableNode): TableNode[]; /** * Get the relationship between two tables (if any). */ getRelationship(from: TableNode, to: TableNode): RelationshipNode | undefined; /** * Get all relationships for a table. */ getTableRelationships(table: TableNode): RelationshipNode[]; /** * Get the column that a foreign key column references. */ getReferencedColumn(fkColumn: ColumnNode): ColumnNode | undefined; /** * Detect circular foreign key dependencies. * Returns arrays of tables that form cycles. */ detectCircularDependencies(): TableNode[][]; /** * Check if there are any circular dependencies. */ hasCircularDependencies(): boolean; /** * Get tables in correct order for CREATE (dependencies first). * Tables with no dependencies come first, then tables that depend on them, etc. */ getCreateOrder(): TableNode[]; /** * Get tables in correct order for DROP (dependents first). * Tables that depend on others come first, then the tables they depend on. */ getDropOrder(): TableNode[]; /** * Topological sort respecting FK dependencies. * Uses Kahn's algorithm for stable ordering. */ private topologicalSort; /** * Validate schema integrity. * Checks for: * - Missing FK targets * - Circular dependencies * - Orphan columns * - Duplicate indexes */ validate(): ValidationError[]; /** * Check if the schema is valid (no validation errors). */ isValid(): boolean; /** * Check if a table looks like a junction table (ManyToMany through). * Junction tables typically have: * - Exactly 2 foreign keys * - Few other columns (id, maybe timestamps) * - Primary key might be composite of the FKs */ isJunctionTable(table: TableNode): boolean; /** * Infer relation type from schema structure. */ inferRelationType(rel: RelationshipNode): RelationshipType; /** * Get the inverse relation type. */ getInverseRelationType(type: RelationshipType): RelationshipType; /** * Add an index to the schema. */ addIndex(index: IndexNode): void; /** * Get all indexes for a table. */ getTableIndexes(tableName: string): IndexNode[]; /** * Find an index by name. */ getIndex(name: string): IndexNode | undefined; /** * Add a relationship to the schema. */ addRelationship(rel: RelationshipNode): void; /** * Remove a relationship from the schema. */ removeRelationship(name: string): boolean; /** * Create a deep clone of this schema. */ clone(): SchemaAST; /** * Get statistics about the schema. */ getStats(): { tableCount: number; columnCount: number; relationshipCount: number; indexCount: number; }; /** * Convert schema to a plain object for serialization/debugging. */ toJSON(): object; } //# sourceMappingURL=schemaAST.d.ts.map