/** * Dependency Graph - builds and manages type dependencies for cascade generation * * This module provides: * - Graph construction from parsed schema relationships * - Topological sorting for correct generation order * - Cycle detection with clear error messages * - Parallel group identification for concurrent generation * * @packageDocumentation */ import type { ParsedGraph, RelationshipOperator } from './types.js'; /** * A node in the schema dependency graph representing an entity type */ export interface DependencyNode { /** Type name */ name: string; /** Types this node depends on (hard dependencies from -> and <-) */ dependsOn: string[]; /** Types that depend on this node */ dependedOnBy: string[]; /** Types this node softly depends on (from ~> and <~ fuzzy operators) */ softDependsOn: string[]; } /** * An edge in the dependency graph representing a relationship */ export interface DependencyEdge { /** Source type */ from: string; /** Target type */ to: string; /** Whether this is an array relationship */ isArray: boolean; /** The operator used: ->, ~>, <-, <~ */ operator: RelationshipOperator; /** Field name (may include ? suffix for optional fields) */ fieldName: string; } /** * The complete dependency graph structure */ export interface DependencyGraph { /** Map of type name to node */ nodes: Record; /** All edges in the graph */ edges: DependencyEdge[]; } /** * Primitive types that don't create dependencies * * These types are leaf values and do not reference other entity types. * Includes precision numeric types, temporal types, and binary types for * compatibility with IceType, Apache Iceberg, Parquet, ClickHouse, and DuckDB. * * @remarks * When checking if a field type is a primitive, use `PRIMITIVE_TYPES.has(type)`. * Non-primitive types (PascalCase names) are treated as entity references. * Type aliases (e.g., `bool` -> `boolean`) are resolved in `parseField()`. */ export declare const PRIMITIVE_TYPES: Set; /** * Error thrown when a circular dependency is detected */ export declare class CircularDependencyError extends Error { /** The path of types that form the cycle */ readonly cyclePath: string[]; constructor(cyclePath: string[]); } /** * Build a dependency graph from a parsed graph schema * * @param schema - The parsed graph from Graph() * @returns The dependency graph with nodes and edges */ export declare function buildDependencyGraph(schema: ParsedGraph): DependencyGraph; /** * Compute topological order for generating types * * Returns types in order such that dependencies come before dependents. * This is essential for cascade generation - we need to create referenced * entities before the entities that reference them. * * @param graph - The dependency graph * @param rootType - The root type to start from * @param ignoreOptional - If true, optional dependencies don't contribute to ordering * @returns Array of type names in generation order (dependencies first, root last) * @throws CircularDependencyError if a cycle is detected */ export declare function topologicalSort(graph: DependencyGraph, rootType: string, ignoreOptional?: boolean): string[]; /** * Options for cycle detection */ export interface DetectCyclesOptions { /** If true, optional dependencies are ignored when detecting cycles */ ignoreOptional?: boolean; } /** * Detect all cycles in the dependency graph * * @param graph - The dependency graph to check * @param options - Detection options * @returns Array of cycles, where each cycle is an array of type names * The first and last element of each cycle are the same (showing the loop) */ export declare function detectCycles(graph: DependencyGraph, options?: DetectCyclesOptions): string[][]; /** * Get parallel generation groups - types that can be generated concurrently * * Returns an array of arrays, where each inner array contains types that * can be generated in parallel (they have no dependencies on each other). * Groups are ordered so that earlier groups must complete before later ones. * * @param graph - The dependency graph * @param rootType - The root type to start from * @returns Array of parallel groups, in execution order */ export declare function getParallelGroups(graph: DependencyGraph, rootType: string): string[][]; /** * Get all dependencies for a specific type (including transitive) * * @param graph - The dependency graph * @param typeName - The type to get dependencies for * @returns Set of all type names this type depends on */ export declare function getAllDependencies(graph: DependencyGraph, typeName: string): Set; /** * Check if the graph has any cycles * * @param graph - The dependency graph * @returns true if cycles exist, false otherwise */ export declare function hasCycles(graph: DependencyGraph): boolean; /** * Get a human-readable visualization of the dependency graph * * @param graph - The dependency graph * @returns Multi-line string showing the graph structure */ export declare function visualizeGraph(graph: DependencyGraph): string; //# sourceMappingURL=dependency-graph.d.ts.map