@duckcodeailabs/dql-core 0.3.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/lineage/builder.d.ts +43 -0
  6. package/dist/lineage/builder.d.ts.map +1 -0
  7. package/dist/lineage/builder.js +192 -0
  8. package/dist/lineage/builder.js.map +1 -0
  9. package/dist/lineage/dependency-resolver.d.ts +44 -0
  10. package/dist/lineage/dependency-resolver.d.ts.map +1 -0
  11. package/dist/lineage/dependency-resolver.js +168 -0
  12. package/dist/lineage/dependency-resolver.js.map +1 -0
  13. package/dist/lineage/domain-lineage.d.ts +96 -0
  14. package/dist/lineage/domain-lineage.d.ts.map +1 -0
  15. package/dist/lineage/domain-lineage.js +140 -0
  16. package/dist/lineage/domain-lineage.js.map +1 -0
  17. package/dist/lineage/index.d.ts +6 -0
  18. package/dist/lineage/index.d.ts.map +1 -0
  19. package/dist/lineage/index.js +7 -0
  20. package/dist/lineage/index.js.map +1 -0
  21. package/dist/lineage/lineage-graph.d.ts +97 -0
  22. package/dist/lineage/lineage-graph.d.ts.map +1 -0
  23. package/dist/lineage/lineage-graph.js +198 -0
  24. package/dist/lineage/lineage-graph.js.map +1 -0
  25. package/dist/lineage/sql-parser.d.ts +23 -0
  26. package/dist/lineage/sql-parser.d.ts.map +1 -0
  27. package/dist/lineage/sql-parser.js +126 -0
  28. package/dist/lineage/sql-parser.js.map +1 -0
  29. package/dist/manifest/builder.d.ts +22 -0
  30. package/dist/manifest/builder.d.ts.map +1 -0
  31. package/dist/manifest/builder.js +538 -0
  32. package/dist/manifest/builder.js.map +1 -0
  33. package/dist/manifest/index.d.ts +3 -0
  34. package/dist/manifest/index.d.ts.map +1 -0
  35. package/dist/manifest/index.js +3 -0
  36. package/dist/manifest/index.js.map +1 -0
  37. package/dist/manifest/types.d.ts +168 -0
  38. package/dist/manifest/types.d.ts.map +1 -0
  39. package/dist/manifest/types.js +10 -0
  40. package/dist/manifest/types.js.map +1 -0
  41. package/dist/semantic/index.d.ts +1 -1
  42. package/dist/semantic/index.d.ts.map +1 -1
  43. package/dist/semantic/index.js +1 -1
  44. package/dist/semantic/index.js.map +1 -1
  45. package/dist/semantic/providers/index.d.ts +1 -1
  46. package/dist/semantic/providers/index.d.ts.map +1 -1
  47. package/dist/semantic/providers/index.js +1 -1
  48. package/dist/semantic/providers/index.js.map +1 -1
  49. package/dist/semantic/providers/registry.d.ts +7 -0
  50. package/dist/semantic/providers/registry.d.ts.map +1 -1
  51. package/dist/semantic/providers/registry.js +30 -0
  52. package/dist/semantic/providers/registry.js.map +1 -1
  53. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -4,4 +4,6 @@ export * from './parser/index.js';
4
4
  export * from './semantic/index.js';
5
5
  export * from './errors/index.js';
6
6
  export * from './formatter/index.js';
7
+ export * from './lineage/index.js';
8
+ export * from './manifest/index.js';
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -6,4 +6,6 @@ export * from './parser/index.js';
6
6
  export * from './semantic/index.js';
7
7
  export * from './errors/index.js';
8
8
  export * from './formatter/index.js';
9
+ export * from './lineage/index.js';
10
+ export * from './manifest/index.js';
9
11
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,wCAAwC;AAExC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,wCAAwC;AAExC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Lineage Builder — assembles the full answer-layer lineage graph.
3
+ *
4
+ * Walks DQL blocks and semantic layer definitions to build a complete
5
+ * LineageGraph connecting source tables → blocks → metrics → charts,
6
+ * with domain boundaries and certification edges.
7
+ */
8
+ import { LineageGraph } from './lineage-graph.js';
9
+ export interface LineageBlockInput {
10
+ name: string;
11
+ sql: string;
12
+ domain?: string;
13
+ owner?: string;
14
+ status?: 'draft' | 'review' | 'certified' | 'deprecated' | 'pending_recertification';
15
+ certifiedBy?: string;
16
+ /** Block type: custom, semantic, etc. */
17
+ blockType?: string;
18
+ /** Metric reference for semantic blocks */
19
+ metricRef?: string;
20
+ /** Chart type from visualization config */
21
+ chartType?: string;
22
+ /** Materialized table/view name */
23
+ materializedAs?: string;
24
+ }
25
+ export interface LineageMetricInput {
26
+ name: string;
27
+ table: string;
28
+ domain: string;
29
+ type: string;
30
+ }
31
+ export interface LineageDimensionInput {
32
+ name: string;
33
+ table: string;
34
+ }
35
+ export interface LineageBuilderOptions {
36
+ /** Known block names for implicit dependency resolution */
37
+ blockNames?: Set<string>;
38
+ }
39
+ /**
40
+ * Build a complete lineage graph from blocks and semantic definitions.
41
+ */
42
+ export declare function buildLineageGraph(blocks: LineageBlockInput[], metrics: LineageMetricInput[], dimensions: LineageDimensionInput[], options?: LineageBuilderOptions): LineageGraph;
43
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/lineage/builder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,YAAY,GAAG,yBAAyB,CAAC;IACrF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,2DAA2D;IAC3D,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,iBAAiB,EAAE,EAC3B,OAAO,EAAE,kBAAkB,EAAE,EAC7B,UAAU,EAAE,qBAAqB,EAAE,EACnC,OAAO,GAAE,qBAA0B,GAClC,YAAY,CAyId"}
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Lineage Builder — assembles the full answer-layer lineage graph.
3
+ *
4
+ * Walks DQL blocks and semantic layer definitions to build a complete
5
+ * LineageGraph connecting source tables → blocks → metrics → charts,
6
+ * with domain boundaries and certification edges.
7
+ */
8
+ import { extractTablesFromSql } from './sql-parser.js';
9
+ import { LineageGraph } from './lineage-graph.js';
10
+ /**
11
+ * Build a complete lineage graph from blocks and semantic definitions.
12
+ */
13
+ export function buildLineageGraph(blocks, metrics, dimensions, options = {}) {
14
+ const graph = new LineageGraph();
15
+ const blockNames = options.blockNames ?? new Set(blocks.map((b) => b.name));
16
+ const materializedMap = new Map();
17
+ for (const block of blocks) {
18
+ materializedMap.set((block.materializedAs ?? block.name).toLowerCase(), block.name);
19
+ }
20
+ // 1. Add block nodes
21
+ for (const block of blocks) {
22
+ graph.addNode({
23
+ id: `block:${block.name}`,
24
+ type: 'block',
25
+ name: block.name,
26
+ domain: block.domain,
27
+ owner: block.owner,
28
+ status: block.status,
29
+ metadata: {
30
+ blockType: block.blockType,
31
+ materializedAs: block.materializedAs,
32
+ },
33
+ });
34
+ }
35
+ // 2. Add metric nodes
36
+ for (const metric of metrics) {
37
+ graph.addNode({
38
+ id: `metric:${metric.name}`,
39
+ type: 'metric',
40
+ name: metric.name,
41
+ domain: metric.domain,
42
+ metadata: { type: metric.type },
43
+ });
44
+ // Metric → source table edge
45
+ const tableNodeId = ensureTableNode(graph, metric.table);
46
+ graph.addEdge({
47
+ source: tableNodeId,
48
+ target: `metric:${metric.name}`,
49
+ type: 'aggregates',
50
+ });
51
+ }
52
+ // 3. Add dimension nodes
53
+ for (const dim of dimensions) {
54
+ graph.addNode({
55
+ id: `dimension:${dim.name}`,
56
+ type: 'dimension',
57
+ name: dim.name,
58
+ });
59
+ const tableNodeId = ensureTableNode(graph, dim.table);
60
+ graph.addEdge({
61
+ source: tableNodeId,
62
+ target: `dimension:${dim.name}`,
63
+ type: 'reads_from',
64
+ });
65
+ }
66
+ // 4. Process each block's SQL for dependencies
67
+ for (const block of blocks) {
68
+ const blockNodeId = `block:${block.name}`;
69
+ const parseResult = extractTablesFromSql(block.sql);
70
+ // ref() calls → block-to-block edges
71
+ for (const ref of parseResult.refs) {
72
+ if (blockNames.has(ref)) {
73
+ graph.addEdge({
74
+ source: `block:${ref}`,
75
+ target: blockNodeId,
76
+ type: 'feeds_into',
77
+ });
78
+ addCrossDomainEdgeIfNeeded(graph, `block:${ref}`, blockNodeId);
79
+ }
80
+ }
81
+ // SQL table references
82
+ for (const table of parseResult.tables) {
83
+ const resolved = materializedMap.get(table.toLowerCase());
84
+ if (resolved && resolved !== block.name) {
85
+ // Table matches another block's materialized name
86
+ graph.addEdge({
87
+ source: `block:${resolved}`,
88
+ target: blockNodeId,
89
+ type: 'feeds_into',
90
+ });
91
+ addCrossDomainEdgeIfNeeded(graph, `block:${resolved}`, blockNodeId);
92
+ }
93
+ else if (!resolved) {
94
+ // External table dependency
95
+ const tableNodeId = ensureTableNode(graph, table);
96
+ graph.addEdge({
97
+ source: tableNodeId,
98
+ target: blockNodeId,
99
+ type: 'reads_from',
100
+ });
101
+ }
102
+ }
103
+ // Semantic block → metric edge
104
+ if (block.blockType === 'semantic' && block.metricRef) {
105
+ const metricNodeId = `metric:${block.metricRef}`;
106
+ if (graph.getNode(metricNodeId)) {
107
+ graph.addEdge({
108
+ source: metricNodeId,
109
+ target: blockNodeId,
110
+ type: 'aggregates',
111
+ });
112
+ addCrossDomainEdgeIfNeeded(graph, metricNodeId, blockNodeId);
113
+ }
114
+ }
115
+ // Chart visualization edge
116
+ if (block.chartType) {
117
+ const chartNodeId = `chart:${block.name}`;
118
+ graph.addNode({
119
+ id: chartNodeId,
120
+ type: 'chart',
121
+ name: `${block.name} (${block.chartType})`,
122
+ domain: block.domain,
123
+ metadata: { chartType: block.chartType },
124
+ });
125
+ graph.addEdge({
126
+ source: blockNodeId,
127
+ target: chartNodeId,
128
+ type: 'visualizes',
129
+ });
130
+ }
131
+ // Certification is stored as node metadata (status + certifiedBy), not as an edge.
132
+ // Self-loops would confuse graph traversal without adding lineage value.
133
+ }
134
+ // 5. Add domain nodes and connect
135
+ addDomainNodes(graph);
136
+ return graph;
137
+ }
138
+ /** Ensure a source_table node exists and return its ID. */
139
+ function ensureTableNode(graph, rawTableName) {
140
+ const tableName = normalizeTableName(rawTableName);
141
+ const nodeId = `table:${tableName}`;
142
+ if (!graph.getNode(nodeId)) {
143
+ graph.addNode({
144
+ id: nodeId,
145
+ type: 'source_table',
146
+ name: tableName,
147
+ });
148
+ }
149
+ return nodeId;
150
+ }
151
+ /**
152
+ * Normalize DuckDB reader function calls to plain table names.
153
+ * e.g., "read_csv_auto('./data/revenue.csv')" → "revenue"
154
+ */
155
+ function normalizeTableName(name) {
156
+ const readerMatch = name.match(/^(?:read_csv_auto|read_csv|read_parquet|read_json|read_json_auto)\s*\(\s*['"]([^'"]+)['"]\s*\)$/i);
157
+ if (readerMatch) {
158
+ // Extract filename without extension from the path
159
+ const path = readerMatch[1];
160
+ const filename = path.split('/').pop() ?? path;
161
+ return filename.replace(/\.(csv|parquet|json)$/i, '');
162
+ }
163
+ return name;
164
+ }
165
+ /** Add a crosses_domain edge if source and target are in different domains. */
166
+ function addCrossDomainEdgeIfNeeded(graph, sourceId, targetId) {
167
+ const sourceNode = graph.getNode(sourceId);
168
+ const targetNode = graph.getNode(targetId);
169
+ if (sourceNode?.domain && targetNode?.domain && sourceNode.domain !== targetNode.domain) {
170
+ graph.addEdge({
171
+ source: sourceId,
172
+ target: targetId,
173
+ type: 'crosses_domain',
174
+ sourceDomain: sourceNode.domain,
175
+ targetDomain: targetNode.domain,
176
+ });
177
+ }
178
+ }
179
+ /** Add domain nodes and connect blocks/metrics to their domains. */
180
+ function addDomainNodes(graph) {
181
+ const domains = graph.getDomains();
182
+ for (const domain of domains) {
183
+ const domainNodeId = `domain:${domain}`;
184
+ graph.addNode({
185
+ id: domainNodeId,
186
+ type: 'domain',
187
+ name: domain,
188
+ domain,
189
+ });
190
+ }
191
+ }
192
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/lineage/builder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAsClD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAA2B,EAC3B,OAA6B,EAC7B,UAAmC,EACnC,UAAiC,EAAE;IAEnC,MAAM,KAAK,GAAG,IAAI,YAAY,EAAE,CAAC;IACjC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5E,MAAM,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAElD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACtF,CAAC;IAED,qBAAqB;IACrB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAA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,OAAO,CAAC;YACZ,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,gBAAgB;YACtB,YAAY,EAAE,UAAU,CAAC,MAAM;YAC/B,YAAY,EAAE,UAAU,CAAC,MAAM;SAChC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,oEAAoE;AACpE,SAAS,cAAc,CAAC,KAAmB;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;IAEnC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,YAAY,GAAG,UAAU,MAAM,EAAE,CAAC;QACxC,KAAK,CAAC,OAAO,CAAC;YACZ,EAAE,EAAE,YAAY;YAChB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;YACZ,MAAM;SACP,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Dependency resolver for DQL blocks.
3
+ *
4
+ * Performs topological sorting of blocks based on ref() calls and
5
+ * SQL-extracted table dependencies. Detects circular dependencies.
6
+ */
7
+ /** Minimal block info needed for dependency resolution */
8
+ export interface BlockDependencyInfo {
9
+ /** Block name (unique identifier) */
10
+ name: string;
11
+ /** Raw SQL query for the block */
12
+ sql: string;
13
+ /** Domain the block belongs to */
14
+ domain?: string;
15
+ /** Materialized table/view name (defaults to block name) */
16
+ materializedAs?: string;
17
+ }
18
+ /** Result of dependency resolution */
19
+ export interface DependencyResolutionResult {
20
+ /** Blocks in execution order (dependencies first) */
21
+ executionOrder: string[];
22
+ /** Map of block name → its direct dependencies */
23
+ dependencyMap: Map<string, string[]>;
24
+ /** Map of block name → blocks that depend on it */
25
+ dependentsMap: Map<string, string[]>;
26
+ /** Circular dependency chains detected (empty if none) */
27
+ cycles: string[][];
28
+ }
29
+ /**
30
+ * Resolve dependencies among a set of blocks and return execution order.
31
+ *
32
+ * Uses both explicit ref() calls and implicit SQL table references to
33
+ * build the dependency graph. Returns a topological sort or reports cycles.
34
+ */
35
+ export declare function resolveDependencies(blocks: BlockDependencyInfo[]): DependencyResolutionResult;
36
+ /**
37
+ * Get all upstream dependencies (transitive) for a given block.
38
+ */
39
+ export declare function getUpstream(blockName: string, dependencyMap: Map<string, string[]>): string[];
40
+ /**
41
+ * Get all downstream dependents (transitive) for a given block.
42
+ */
43
+ export declare function getDownstream(blockName: string, dependentsMap: Map<string, string[]>): string[];
44
+ //# sourceMappingURL=dependency-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-resolver.d.ts","sourceRoot":"","sources":["../../src/lineage/dependency-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,sCAAsC;AACtC,MAAM,WAAW,0BAA0B;IACzC,qDAAqD;IACrD,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,kDAAkD;IAClD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACrC,mDAAmD;IACnD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACrC,0DAA0D;IAC1D,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,EAAE,GAAG,0BAA0B,CAgG7F;AA8CD;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAgB7F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAgB/F"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Dependency resolver for DQL blocks.
3
+ *
4
+ * Performs topological sorting of blocks based on ref() calls and
5
+ * SQL-extracted table dependencies. Detects circular dependencies.
6
+ */
7
+ import { extractTablesFromSql } from './sql-parser.js';
8
+ /**
9
+ * Resolve dependencies among a set of blocks and return execution order.
10
+ *
11
+ * Uses both explicit ref() calls and implicit SQL table references to
12
+ * build the dependency graph. Returns a topological sort or reports cycles.
13
+ */
14
+ export function resolveDependencies(blocks) {
15
+ const blockNames = new Set(blocks.map((b) => b.name));
16
+ const materializedNames = new Map();
17
+ // Map materialized names back to block names
18
+ for (const block of blocks) {
19
+ const matName = block.materializedAs ?? block.name;
20
+ materializedNames.set(matName.toLowerCase(), block.name);
21
+ }
22
+ // Build dependency map
23
+ const dependencyMap = new Map();
24
+ const dependentsMap = new Map();
25
+ for (const block of blocks) {
26
+ dependencyMap.set(block.name, []);
27
+ dependentsMap.set(block.name, []);
28
+ }
29
+ for (const block of blocks) {
30
+ const parseResult = extractTablesFromSql(block.sql);
31
+ const deps = new Set();
32
+ // Explicit ref() calls → direct dependencies
33
+ for (const ref of parseResult.refs) {
34
+ if (blockNames.has(ref)) {
35
+ deps.add(ref);
36
+ }
37
+ }
38
+ // Implicit SQL table references → check if they match a block name
39
+ for (const table of parseResult.tables) {
40
+ const resolved = materializedNames.get(table.toLowerCase());
41
+ if (resolved && resolved !== block.name) {
42
+ deps.add(resolved);
43
+ }
44
+ }
45
+ const depArray = [...deps];
46
+ dependencyMap.set(block.name, depArray);
47
+ // Build reverse map
48
+ for (const dep of depArray) {
49
+ const existing = dependentsMap.get(dep) ?? [];
50
+ existing.push(block.name);
51
+ dependentsMap.set(dep, existing);
52
+ }
53
+ }
54
+ // Topological sort (Kahn's algorithm): inDeg[node] = number of unresolved deps
55
+ const inDeg = new Map();
56
+ for (const block of blocks) {
57
+ const deps = dependencyMap.get(block.name) ?? [];
58
+ inDeg.set(block.name, deps.length);
59
+ }
60
+ const queue = [];
61
+ for (const [name, deg] of inDeg) {
62
+ if (deg === 0)
63
+ queue.push(name);
64
+ }
65
+ const executionOrder = [];
66
+ while (queue.length > 0) {
67
+ // Sort queue for deterministic output
68
+ queue.sort();
69
+ const current = queue.shift();
70
+ executionOrder.push(current);
71
+ // For each block that depends on current, reduce its in-degree
72
+ const dependents = dependentsMap.get(current) ?? [];
73
+ for (const dep of dependents) {
74
+ const newDeg = (inDeg.get(dep) ?? 1) - 1;
75
+ inDeg.set(dep, newDeg);
76
+ if (newDeg === 0) {
77
+ queue.push(dep);
78
+ }
79
+ }
80
+ }
81
+ // Detect cycles — any block not in executionOrder is part of a cycle
82
+ const cycles = [];
83
+ if (executionOrder.length < blocks.length) {
84
+ const inOrder = new Set(executionOrder);
85
+ const remaining = blocks.filter((b) => !inOrder.has(b.name)).map((b) => b.name);
86
+ // Find cycles via DFS
87
+ const visited = new Set();
88
+ for (const start of remaining) {
89
+ if (visited.has(start))
90
+ continue;
91
+ const cycle = findCycle(start, dependencyMap, visited);
92
+ if (cycle.length > 0) {
93
+ cycles.push(cycle);
94
+ }
95
+ }
96
+ }
97
+ return { executionOrder, dependencyMap, dependentsMap, cycles };
98
+ }
99
+ /** DFS cycle finder starting from a given node */
100
+ function findCycle(start, dependencyMap, globalVisited) {
101
+ const path = [];
102
+ const pathSet = new Set();
103
+ const stack = [{ node: start, depIdx: 0 }];
104
+ pathSet.add(start);
105
+ path.push(start);
106
+ globalVisited.add(start);
107
+ while (stack.length > 0) {
108
+ const top = stack[stack.length - 1];
109
+ const deps = dependencyMap.get(top.node) ?? [];
110
+ if (top.depIdx >= deps.length) {
111
+ stack.pop();
112
+ path.pop();
113
+ pathSet.delete(top.node);
114
+ continue;
115
+ }
116
+ const nextDep = deps[top.depIdx];
117
+ top.depIdx++;
118
+ if (pathSet.has(nextDep)) {
119
+ // Found cycle — extract from nextDep's position to end of path
120
+ const cycleStart = path.indexOf(nextDep);
121
+ return [...path.slice(cycleStart), nextDep];
122
+ }
123
+ if (!globalVisited.has(nextDep)) {
124
+ globalVisited.add(nextDep);
125
+ path.push(nextDep);
126
+ pathSet.add(nextDep);
127
+ stack.push({ node: nextDep, depIdx: 0 });
128
+ }
129
+ }
130
+ return [];
131
+ }
132
+ /**
133
+ * Get all upstream dependencies (transitive) for a given block.
134
+ */
135
+ export function getUpstream(blockName, dependencyMap) {
136
+ const visited = new Set();
137
+ const queue = [blockName];
138
+ while (queue.length > 0) {
139
+ const current = queue.shift();
140
+ const deps = dependencyMap.get(current) ?? [];
141
+ for (const dep of deps) {
142
+ if (!visited.has(dep)) {
143
+ visited.add(dep);
144
+ queue.push(dep);
145
+ }
146
+ }
147
+ }
148
+ return [...visited];
149
+ }
150
+ /**
151
+ * Get all downstream dependents (transitive) for a given block.
152
+ */
153
+ export function getDownstream(blockName, dependentsMap) {
154
+ const visited = new Set();
155
+ const queue = [blockName];
156
+ while (queue.length > 0) {
157
+ const current = queue.shift();
158
+ const deps = dependentsMap.get(current) ?? [];
159
+ for (const dep of deps) {
160
+ if (!visited.has(dep)) {
161
+ visited.add(dep);
162
+ queue.push(dep);
163
+ }
164
+ }
165
+ }
166
+ return [...visited];
167
+ }
168
+ //# sourceMappingURL=dependency-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-resolver.js","sourceRoot":"","sources":["../../src/lineage/dependency-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AA0BvD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAA6B;IAC/D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC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C,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,EAAG,CAAC;QAC/B,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC9C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACjB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Domain-specific lineage analysis — DQL's key differentiator.
3
+ *
4
+ * Tracks how data flows across business domains, creating "trust chains"
5
+ * where certified blocks serve as trust checkpoints. Enables impact analysis
6
+ * across domain boundaries.
7
+ */
8
+ import type { LineageGraph, LineageEdge } from './lineage-graph.js';
9
+ export interface TrustChainNode {
10
+ nodeId: string;
11
+ name: string;
12
+ domain?: string;
13
+ status?: string;
14
+ owner?: string;
15
+ /** Whether this node is a trust checkpoint (certified block) */
16
+ isTrustCheckpoint: boolean;
17
+ }
18
+ export interface TrustChain {
19
+ /** Ordered nodes from source to target */
20
+ nodes: TrustChainNode[];
21
+ /** Number of certified checkpoints in the chain */
22
+ certifiedCount: number;
23
+ /** Number of uncertified nodes (trust gaps) */
24
+ uncertifiedCount: number;
25
+ /** Trust score: certified / total (0.0 to 1.0) */
26
+ trustScore: number;
27
+ /** Domain boundaries crossed */
28
+ domainCrossings: Array<{
29
+ from: string;
30
+ to: string;
31
+ }>;
32
+ }
33
+ export interface DomainImpact {
34
+ /** Domain name */
35
+ domain: string;
36
+ /** Nodes in this domain that are affected */
37
+ affectedNodes: Array<{
38
+ id: string;
39
+ name: string;
40
+ status?: string;
41
+ }>;
42
+ /** Number of certified blocks affected */
43
+ certifiedBlocksAffected: number;
44
+ }
45
+ export interface ImpactAnalysis {
46
+ /** The source node being analyzed */
47
+ sourceNode: string;
48
+ /** Total downstream nodes affected */
49
+ totalAffected: number;
50
+ /** Breakdown by domain */
51
+ domainImpacts: DomainImpact[];
52
+ /** Cross-domain edges in the impact path */
53
+ domainCrossings: Array<{
54
+ from: string;
55
+ to: string;
56
+ edgeCount: number;
57
+ }>;
58
+ }
59
+ export interface DomainFlow {
60
+ /** Source domain */
61
+ from: string;
62
+ /** Target domain */
63
+ to: string;
64
+ /** Edges connecting these domains */
65
+ edges: LineageEdge[];
66
+ /** Nodes at the boundary (source side) */
67
+ sourceNodes: string[];
68
+ /** Nodes at the boundary (target side) */
69
+ targetNodes: string[];
70
+ }
71
+ /**
72
+ * Build a trust chain from a source node to a target node.
73
+ * Shows certification status at every step.
74
+ */
75
+ export declare function buildTrustChain(graph: LineageGraph, fromId: string, toId: string): TrustChain | null;
76
+ /**
77
+ * Analyze the impact of changing a node — which domains and blocks are affected downstream.
78
+ */
79
+ export declare function analyzeImpact(graph: LineageGraph, nodeId: string): ImpactAnalysis;
80
+ /**
81
+ * Detect all cross-domain data flows in the graph.
82
+ */
83
+ export declare function detectDomainFlows(graph: LineageGraph): DomainFlow[];
84
+ /**
85
+ * Get a trust overview for all blocks in a domain.
86
+ */
87
+ export declare function getDomainTrustOverview(graph: LineageGraph, domain: string): {
88
+ totalBlocks: number;
89
+ certified: number;
90
+ draft: number;
91
+ review: number;
92
+ deprecated: number;
93
+ pendingRecertification: number;
94
+ trustScore: number;
95
+ };
96
+ //# sourceMappingURL=domain-lineage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-lineage.d.ts","sourceRoot":"","sources":["../../src/lineage/domain-lineage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAe,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIjF,MAAM,WAAW,cAAc;IAC7B,MAA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