@duckcodeailabs/dql-core 0.3.1 → 0.6.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 (42) hide show
  1. package/LICENSE +123 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/lineage/builder.d.ts +43 -0
  7. package/dist/lineage/builder.d.ts.map +1 -0
  8. package/dist/lineage/builder.js +192 -0
  9. package/dist/lineage/builder.js.map +1 -0
  10. package/dist/lineage/dependency-resolver.d.ts +44 -0
  11. package/dist/lineage/dependency-resolver.d.ts.map +1 -0
  12. package/dist/lineage/dependency-resolver.js +168 -0
  13. package/dist/lineage/dependency-resolver.js.map +1 -0
  14. package/dist/lineage/domain-lineage.d.ts +96 -0
  15. package/dist/lineage/domain-lineage.d.ts.map +1 -0
  16. package/dist/lineage/domain-lineage.js +140 -0
  17. package/dist/lineage/domain-lineage.js.map +1 -0
  18. package/dist/lineage/index.d.ts +6 -0
  19. package/dist/lineage/index.d.ts.map +1 -0
  20. package/dist/lineage/index.js +7 -0
  21. package/dist/lineage/index.js.map +1 -0
  22. package/dist/lineage/lineage-graph.d.ts +97 -0
  23. package/dist/lineage/lineage-graph.d.ts.map +1 -0
  24. package/dist/lineage/lineage-graph.js +198 -0
  25. package/dist/lineage/lineage-graph.js.map +1 -0
  26. package/dist/lineage/sql-parser.d.ts +23 -0
  27. package/dist/lineage/sql-parser.d.ts.map +1 -0
  28. package/dist/lineage/sql-parser.js +110 -0
  29. package/dist/lineage/sql-parser.js.map +1 -0
  30. package/dist/semantic/index.d.ts +1 -1
  31. package/dist/semantic/index.d.ts.map +1 -1
  32. package/dist/semantic/index.js +1 -1
  33. package/dist/semantic/index.js.map +1 -1
  34. package/dist/semantic/providers/index.d.ts +1 -1
  35. package/dist/semantic/providers/index.d.ts.map +1 -1
  36. package/dist/semantic/providers/index.js +1 -1
  37. package/dist/semantic/providers/index.js.map +1 -1
  38. package/dist/semantic/providers/registry.d.ts +7 -0
  39. package/dist/semantic/providers/registry.d.ts.map +1 -1
  40. package/dist/semantic/providers/registry.js +30 -0
  41. package/dist/semantic/providers/registry.js.map +1 -1
  42. package/package.json +8 -9
package/LICENSE ADDED
@@ -0,0 +1,123 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship.
41
+
42
+ "Contribution" shall mean any work of authorship, including the original version
43
+ of the Work and any modifications or additions to that Work or Derivative Works
44
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
45
+ by the copyright owner or by an individual or Legal Entity authorized to submit
46
+ on behalf of the copyright owner.
47
+
48
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
49
+ of whom a Contribution has been received by Licensor and subsequently
50
+ incorporated within the Work.
51
+
52
+ 2. Grant of Copyright License.
53
+
54
+ Subject to the terms and conditions of this License, each Contributor hereby
55
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
56
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
57
+ publicly display, publicly perform, sublicense, and distribute the Work and such
58
+ Derivative Works in Source or Object form.
59
+
60
+ 3. Grant of Patent License.
61
+
62
+ Subject to the terms and conditions of this License, each Contributor hereby
63
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
64
+ irrevocable patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution.
68
+
69
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
70
+ in any medium, with or without modifications, and in Source or Object form,
71
+ provided that You meet the following conditions:
72
+
73
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
74
+ this License; and
75
+
76
+ (b) You must cause any modified files to carry prominent notices stating that
77
+ You changed the files; and
78
+
79
+ (c) You must retain, in the Source form of any Derivative Works that You
80
+ distribute, all copyright, patent, trademark, and attribution notices from the
81
+ Source form of the Work, excluding those notices that do not pertain to any part
82
+ of the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
85
+ any Derivative Works that You distribute must include a readable copy of the
86
+ attribution notices contained within such NOTICE file, excluding those notices
87
+ that do not pertain to any part of the Derivative Works.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
92
+ for inclusion in the Work by You to the Licensor shall be under the terms and
93
+ conditions of this License, without any additional terms or conditions.
94
+
95
+ 6. Trademarks.
96
+
97
+ This License does not grant permission to use the trade names, trademarks,
98
+ service marks, or product names of the Licensor, except as required for
99
+ reasonable and customary use in describing the origin of the Work.
100
+
101
+ 7. Disclaimer of Warranty.
102
+
103
+ Unless required by applicable law or agreed to in writing, Licensor provides the
104
+ Work on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
105
+ express or implied, including, without limitation, any warranties or conditions
106
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
107
+ PURPOSE.
108
+
109
+ 8. Limitation of Liability.
110
+
111
+ In no event and under no legal theory, whether in tort (including negligence),
112
+ contract, or otherwise, unless required by applicable law, shall any Contributor
113
+ be liable to You for damages, including any direct, indirect, special,
114
+ incidental, or consequential damages of any character arising as a result of this
115
+ License or out of the use or inability to use the Work.
116
+
117
+ 9. Accepting Warranty or Additional Liability.
118
+
119
+ While redistributing the Work or Derivative Works thereof, You may choose to
120
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
121
+ other liability obligations and/or rights consistent with this License.
122
+
123
+ END OF TERMS AND CONDITIONS
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ 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';
7
8
  //# 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"}
package/dist/index.js CHANGED
@@ -6,4 +6,5 @@ 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';
9
10
  //# 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"}
@@ -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,K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AK,CAAC,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,IA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