@t1mmen/srtd
Version:
Supabase Repeatable Template Definitions (srtd): 🪄 Live-reloading SQL templates for Supabase DX. Make your database changes reviewable and migrations maintainable! 🚀
42 lines (41 loc) • 1.35 kB
TypeScript
/**
* Dependency Graph Builder
*
* Builds a dependency graph from SQL templates using @depends-on comments
* and provides topological sorting and cycle detection.
*/
/**
* Input template for dependency analysis
*/
export interface TemplateInput {
path: string;
content: string;
}
/**
* Build a dependency graph from templates
*
* Uses @depends-on comments to determine dependencies.
* Dependencies are matched by filename (basename) to full paths.
*
* Returns a Map where:
* - Keys are template paths
* - Values are arrays of template paths that the key depends on
*/
export declare function buildDependencyGraph(templates: TemplateInput[]): Map<string, string[]>;
/**
* Topologically sort templates based on dependencies
*
* Returns templates in an order where dependencies come before dependents.
* Uses depth-first search for stable ordering.
*
* Note: If cycles exist, returns a best-effort ordering.
* Use detectCycles() first to warn users.
*/
export declare function topologicalSort(graph: Map<string, string[]>): string[];
/**
* Detect cycles in the dependency graph
*
* Returns an array of cycles found. Each cycle is an array of template paths
* representing the cycle (e.g., ['/a.sql', '/b.sql'] means a -> b -> a).
*/
export declare function detectCycles(graph: Map<string, string[]>): string[][];