rawsql-ts 0.11.11-beta → 0.11.13-beta
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.
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +14 -14
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.d.ts +3 -0
- package/dist/esm/src/index.js +3 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/models/Lexeme.d.ts +12 -0
- package/dist/esm/src/models/SqlPrintToken.d.ts +6 -4
- package/dist/esm/src/models/SqlPrintToken.js +2 -0
- package/dist/esm/src/models/SqlPrintToken.js.map +1 -1
- package/dist/esm/src/parsers/FunctionExpressionParser.js +5 -4
- package/dist/esm/src/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/esm/src/parsers/SelectQueryParser.js +3 -2
- package/dist/esm/src/parsers/SelectQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlPrintTokenParser.d.ts +40 -0
- package/dist/esm/src/parsers/SqlPrintTokenParser.js +103 -8
- package/dist/esm/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/esm/src/parsers/ValueParser.js +4 -4
- package/dist/esm/src/parsers/ValueParser.js.map +1 -1
- package/dist/esm/src/reporting/models/DataFlowGraph.d.ts +3 -1
- package/dist/esm/src/reporting/models/DataFlowGraph.js +5 -27
- package/dist/esm/src/reporting/models/DataFlowGraph.js.map +1 -1
- package/dist/esm/src/reporting/models/DataFlowNode.d.ts +8 -2
- package/dist/esm/src/reporting/models/DataFlowNode.js +34 -10
- package/dist/esm/src/reporting/models/DataFlowNode.js.map +1 -1
- package/dist/esm/src/reporting/services/ProcessHandler.d.ts +6 -42
- package/dist/esm/src/reporting/services/ProcessHandler.js +9 -164
- package/dist/esm/src/reporting/services/ProcessHandler.js.map +1 -1
- package/dist/esm/src/tokenReaders/BaseTokenReader.d.ts +5 -1
- package/dist/esm/src/tokenReaders/BaseTokenReader.js +19 -13
- package/dist/esm/src/tokenReaders/BaseTokenReader.js.map +1 -1
- package/dist/esm/src/transformers/CTEDependencyAnalyzer.d.ts +95 -0
- package/dist/esm/src/transformers/CTEDependencyAnalyzer.js +189 -0
- package/dist/esm/src/transformers/CTEDependencyAnalyzer.js.map +1 -0
- package/dist/esm/src/transformers/CTEDisabler.d.ts +7 -2
- package/dist/esm/src/transformers/CTEDisabler.js +25 -2
- package/dist/esm/src/transformers/CTEDisabler.js.map +1 -1
- package/dist/esm/src/transformers/QueryFlowDiagramGenerator.js +11 -1
- package/dist/esm/src/transformers/QueryFlowDiagramGenerator.js.map +1 -1
- package/dist/esm/src/transformers/SqlPrinter.d.ts +47 -2
- package/dist/esm/src/transformers/SqlPrinter.js +138 -51
- package/dist/esm/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/esm/src/utils/LexemeCursor.d.ts +57 -0
- package/dist/esm/src/utils/LexemeCursor.js +187 -0
- package/dist/esm/src/utils/LexemeCursor.js.map +1 -0
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +14 -14
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/Lexeme.d.ts +12 -0
- package/dist/src/models/SqlPrintToken.d.ts +6 -4
- package/dist/src/models/SqlPrintToken.js +2 -0
- package/dist/src/models/SqlPrintToken.js.map +1 -1
- package/dist/src/parsers/FunctionExpressionParser.js +5 -4
- package/dist/src/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/src/parsers/SelectQueryParser.js +3 -2
- package/dist/src/parsers/SelectQueryParser.js.map +1 -1
- package/dist/src/parsers/SqlPrintTokenParser.d.ts +40 -0
- package/dist/src/parsers/SqlPrintTokenParser.js +103 -8
- package/dist/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/src/parsers/ValueParser.js +4 -4
- package/dist/src/parsers/ValueParser.js.map +1 -1
- package/dist/src/reporting/models/DataFlowGraph.d.ts +3 -1
- package/dist/src/reporting/models/DataFlowGraph.js +5 -27
- package/dist/src/reporting/models/DataFlowGraph.js.map +1 -1
- package/dist/src/reporting/models/DataFlowNode.d.ts +8 -2
- package/dist/src/reporting/models/DataFlowNode.js +34 -10
- package/dist/src/reporting/models/DataFlowNode.js.map +1 -1
- package/dist/src/reporting/services/ProcessHandler.d.ts +6 -42
- package/dist/src/reporting/services/ProcessHandler.js +9 -164
- package/dist/src/reporting/services/ProcessHandler.js.map +1 -1
- package/dist/src/tokenReaders/BaseTokenReader.d.ts +5 -1
- package/dist/src/tokenReaders/BaseTokenReader.js +19 -13
- package/dist/src/tokenReaders/BaseTokenReader.js.map +1 -1
- package/dist/src/transformers/CTEDependencyAnalyzer.d.ts +95 -0
- package/dist/src/transformers/CTEDependencyAnalyzer.js +193 -0
- package/dist/src/transformers/CTEDependencyAnalyzer.js.map +1 -0
- package/dist/src/transformers/CTEDisabler.d.ts +7 -2
- package/dist/src/transformers/CTEDisabler.js +23 -0
- package/dist/src/transformers/CTEDisabler.js.map +1 -1
- package/dist/src/transformers/QueryFlowDiagramGenerator.js +11 -1
- package/dist/src/transformers/QueryFlowDiagramGenerator.js.map +1 -1
- package/dist/src/transformers/SqlPrinter.d.ts +47 -2
- package/dist/src/transformers/SqlPrinter.js +138 -51
- package/dist/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/src/utils/LexemeCursor.d.ts +57 -0
- package/dist/src/utils/LexemeCursor.js +191 -0
- package/dist/src/utils/LexemeCursor.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataFlowNode.js","sourceRoot":"","sources":["../../../../../src/reporting/models/DataFlowNode.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,OAAgB,gBAAgB;IAClC,YACW,EAAU,EACV,KAAa,EACb,IAAc,EACd,KAAgB,EAChB,OAAkB;Q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kBAAkB,CAAC,WAAmB,EAAE,SAAiB;QAC5D,MAAM,YAAY,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,EAAE,GAAG,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,WAAW,EAAE,CAAC;QAC/E,2EAA2E;QAC3E,OAAO,IAAI,aAAa,CAAC,EAAE,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,gBAAgB;IAC5C,YAAY,UAAkB,MAAM;QAChC,MAAM,KAAK,GAAG,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,SAAS,CAAC;QACxE,KAAK,CAAC,GAAG,OAAO,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC3D,CAAC;IAED,wBAAwB;QACpB,OAAO,GAAG,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;IACzC,CAAC;CACJ"}
|
|
@@ -2,54 +2,18 @@ import { SimpleSelectQuery } from '../../models/SimpleSelectQuery';
|
|
|
2
2
|
import { DataFlowGraph } from '../models/DataFlowGraph';
|
|
3
3
|
import { DataSourceHandler } from './DataSourceHandler';
|
|
4
4
|
/**
|
|
5
|
-
* Handles the processing of SQL clauses
|
|
5
|
+
* Handles the processing of SQL clauses for data flow generation
|
|
6
|
+
* Note: This class is simplified to focus on data flow only,
|
|
7
|
+
* filtering clauses like WHERE, GROUP BY, HAVING, etc. are excluded
|
|
6
8
|
*/
|
|
7
9
|
export declare class ProcessHandler {
|
|
8
10
|
private graph;
|
|
9
11
|
private dataSourceHandler;
|
|
10
12
|
constructor(graph: DataFlowGraph, dataSourceHandler: DataSourceHandler);
|
|
11
13
|
/**
|
|
12
|
-
* Processes SQL clauses
|
|
14
|
+
* Processes SQL clauses for data flow diagram generation
|
|
15
|
+
* Returns the current node ID without adding process nodes
|
|
16
|
+
* since we focus only on data flow (sources, joins, unions)
|
|
13
17
|
*/
|
|
14
18
|
processQueryClauses(query: SimpleSelectQuery, context: string, currentNodeId: string, cteNames: Set<string>, queryProcessor: (query: any, context: string, cteNames: Set<string>) => string): string;
|
|
15
|
-
/**
|
|
16
|
-
* Processes WHERE clause including subqueries
|
|
17
|
-
*/
|
|
18
|
-
private processWhereClause;
|
|
19
|
-
/**
|
|
20
|
-
* Processes GROUP BY clause
|
|
21
|
-
*/
|
|
22
|
-
private processGroupByClause;
|
|
23
|
-
/**
|
|
24
|
-
* Processes HAVING clause
|
|
25
|
-
*/
|
|
26
|
-
private processHavingClause;
|
|
27
|
-
/**
|
|
28
|
-
* Processes SELECT clause
|
|
29
|
-
*/
|
|
30
|
-
private processSelectClause;
|
|
31
|
-
/**
|
|
32
|
-
* Processes ORDER BY clause
|
|
33
|
-
*/
|
|
34
|
-
private processOrderByClause;
|
|
35
|
-
/**
|
|
36
|
-
* Processes LIMIT/OFFSET clause
|
|
37
|
-
*/
|
|
38
|
-
private processLimitClause;
|
|
39
|
-
/**
|
|
40
|
-
* Determines if a SELECT node should be added
|
|
41
|
-
*/
|
|
42
|
-
private shouldAddSelectNode;
|
|
43
|
-
/**
|
|
44
|
-
* Processes WHERE clause to find subqueries (EXISTS, IN, etc.)
|
|
45
|
-
*/
|
|
46
|
-
private processWhereSubqueries;
|
|
47
|
-
/**
|
|
48
|
-
* Recursively processes ValueComponent to find InlineQuery (subqueries)
|
|
49
|
-
*/
|
|
50
|
-
private processValueComponent;
|
|
51
|
-
/**
|
|
52
|
-
* Processes only the tables from a query for EXISTS/NOT EXISTS conditions
|
|
53
|
-
*/
|
|
54
|
-
private processQueryTablesOnly;
|
|
55
19
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { InlineQuery, FunctionCall, UnaryExpression, BinaryExpression } from '../../models/ValueComponent';
|
|
2
1
|
/**
|
|
3
|
-
* Handles the processing of SQL clauses
|
|
2
|
+
* Handles the processing of SQL clauses for data flow generation
|
|
3
|
+
* Note: This class is simplified to focus on data flow only,
|
|
4
|
+
* filtering clauses like WHERE, GROUP BY, HAVING, etc. are excluded
|
|
4
5
|
*/
|
|
5
6
|
export class ProcessHandler {
|
|
6
7
|
constructor(graph, dataSourceHandler) {
|
|
@@ -8,170 +9,14 @@ export class ProcessHandler {
|
|
|
8
9
|
this.dataSourceHandler = dataSourceHandler;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
|
-
* Processes SQL clauses
|
|
12
|
+
* Processes SQL clauses for data flow diagram generation
|
|
13
|
+
* Returns the current node ID without adding process nodes
|
|
14
|
+
* since we focus only on data flow (sources, joins, unions)
|
|
12
15
|
*/
|
|
13
16
|
processQueryClauses(query, context, currentNodeId, cteNames, queryProcessor) {
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
resultNodeId = this.processWhereClause(query.whereClause, context, resultNodeId, cteNames, queryProcessor);
|
|
18
|
-
}
|
|
19
|
-
// 3. Process GROUP BY clause
|
|
20
|
-
if (query.groupByClause && resultNodeId) {
|
|
21
|
-
resultNodeId = this.processGroupByClause(context, resultNodeId);
|
|
22
|
-
}
|
|
23
|
-
// 4. Process HAVING clause
|
|
24
|
-
if (query.havingClause && resultNodeId) {
|
|
25
|
-
resultNodeId = this.processHavingClause(context, resultNodeId);
|
|
26
|
-
}
|
|
27
|
-
// 5. Process SELECT clause - only add if needed
|
|
28
|
-
if (this.shouldAddSelectNode(query, context)) {
|
|
29
|
-
resultNodeId = this.processSelectClause(context, resultNodeId);
|
|
30
|
-
}
|
|
31
|
-
// 6. Process ORDER BY clause
|
|
32
|
-
if (query.orderByClause && resultNodeId) {
|
|
33
|
-
resultNodeId = this.processOrderByClause(context, resultNodeId);
|
|
34
|
-
}
|
|
35
|
-
// 7. Process LIMIT/OFFSET clause
|
|
36
|
-
if ((query.limitClause || query.offsetClause) && resultNodeId) {
|
|
37
|
-
resultNodeId = this.processLimitClause(context, resultNodeId, !!query.offsetClause);
|
|
38
|
-
}
|
|
39
|
-
return resultNodeId;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Processes WHERE clause including subqueries
|
|
43
|
-
*/
|
|
44
|
-
processWhereClause(whereClause, context, currentNodeId, cteNames, queryProcessor) {
|
|
45
|
-
const whereNode = this.graph.createProcessNode('where', context);
|
|
46
|
-
// Connect FROM result to WHERE
|
|
47
|
-
this.graph.addConnection(currentNodeId, whereNode.id);
|
|
48
|
-
// Process WHERE subqueries
|
|
49
|
-
const whereSubqueryInfo = this.processWhereSubqueries(whereClause, context, cteNames, queryProcessor);
|
|
50
|
-
// Connect WHERE subqueries to WHERE node
|
|
51
|
-
for (const subqueryInfo of whereSubqueryInfo) {
|
|
52
|
-
this.graph.addConnection(subqueryInfo.nodeId, whereNode.id, subqueryInfo.operator);
|
|
53
|
-
}
|
|
54
|
-
return whereNode.id;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Processes GROUP BY clause
|
|
58
|
-
*/
|
|
59
|
-
processGroupByClause(context, currentNodeId) {
|
|
60
|
-
const groupByNode = this.graph.createProcessNode('group by', context);
|
|
61
|
-
this.graph.addConnection(currentNodeId, groupByNode.id);
|
|
62
|
-
return groupByNode.id;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Processes HAVING clause
|
|
66
|
-
*/
|
|
67
|
-
processHavingClause(context, currentNodeId) {
|
|
68
|
-
const havingNode = this.graph.createProcessNode('having', context);
|
|
69
|
-
this.graph.addConnection(currentNodeId, havingNode.id);
|
|
70
|
-
return havingNode.id;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Processes SELECT clause
|
|
74
|
-
*/
|
|
75
|
-
processSelectClause(context, currentNodeId) {
|
|
76
|
-
const selectNode = this.graph.createProcessNode('select', context);
|
|
77
|
-
this.graph.addConnection(currentNodeId, selectNode.id);
|
|
78
|
-
return selectNode.id;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Processes ORDER BY clause
|
|
82
|
-
*/
|
|
83
|
-
processOrderByClause(context, currentNodeId) {
|
|
84
|
-
const orderByNode = this.graph.createProcessNode('order by', context);
|
|
85
|
-
this.graph.addConnection(currentNodeId, orderByNode.id);
|
|
86
|
-
return orderByNode.id;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Processes LIMIT/OFFSET clause
|
|
90
|
-
*/
|
|
91
|
-
processLimitClause(context, currentNodeId, hasOffset) {
|
|
92
|
-
const limitNode = this.graph.createProcessNode(hasOffset ? 'limit/offset' : 'limit', context);
|
|
93
|
-
this.graph.addConnection(currentNodeId, limitNode.id);
|
|
94
|
-
return limitNode.id;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Determines if a SELECT node should be added
|
|
98
|
-
*/
|
|
99
|
-
shouldAddSelectNode(query, context) {
|
|
100
|
-
// Always add SELECT node - UNION combines SELECT results, not raw data sources
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Processes WHERE clause to find subqueries (EXISTS, IN, etc.)
|
|
105
|
-
*/
|
|
106
|
-
processWhereSubqueries(whereClause, context, cteNames, queryProcessor) {
|
|
107
|
-
const subqueryInfo = [];
|
|
108
|
-
this.processValueComponent(whereClause.condition, context, cteNames, queryProcessor, subqueryInfo);
|
|
109
|
-
return subqueryInfo;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Recursively processes ValueComponent to find InlineQuery (subqueries)
|
|
113
|
-
*/
|
|
114
|
-
processValueComponent(value, context, cteNames, queryProcessor, subqueryInfo) {
|
|
115
|
-
if (value instanceof InlineQuery) {
|
|
116
|
-
const subqueryNodeId = queryProcessor(value.selectQuery, `${context}_where_subquery`, cteNames);
|
|
117
|
-
subqueryInfo.push({ nodeId: subqueryNodeId, operator: 'SUBQUERY' });
|
|
118
|
-
}
|
|
119
|
-
else if (value instanceof FunctionCall) {
|
|
120
|
-
const functionName = value.qualifiedName.name.toString().toLowerCase();
|
|
121
|
-
if (functionName === 'exists' && value.argument instanceof InlineQuery) {
|
|
122
|
-
const subqueryNodeId = queryProcessor(value.argument.selectQuery, `${context}_where_subquery`, cteNames);
|
|
123
|
-
subqueryInfo.push({ nodeId: subqueryNodeId, operator: 'EXISTS' });
|
|
124
|
-
}
|
|
125
|
-
else if (value.argument) {
|
|
126
|
-
this.processValueComponent(value.argument, context, cteNames, queryProcessor, subqueryInfo);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else if (value instanceof UnaryExpression) {
|
|
130
|
-
const operator = value.operator.value.toLowerCase();
|
|
131
|
-
if ((operator === 'exists' || operator === 'not exists') && value.expression instanceof InlineQuery) {
|
|
132
|
-
this.processQueryTablesOnly(value.expression.selectQuery, context, cteNames, subqueryInfo, operator.toUpperCase());
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
this.processValueComponent(value.expression, context, cteNames, queryProcessor, subqueryInfo);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else if (value instanceof BinaryExpression) {
|
|
139
|
-
const operator = value.operator.value.toLowerCase();
|
|
140
|
-
if ((operator === 'in' || operator === 'not in') && value.right instanceof InlineQuery) {
|
|
141
|
-
this.processQueryTablesOnly(value.right.selectQuery, context, cteNames, subqueryInfo, operator.toUpperCase());
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
this.processValueComponent(value.left, context, cteNames, queryProcessor, subqueryInfo);
|
|
145
|
-
this.processValueComponent(value.right, context, cteNames, queryProcessor, subqueryInfo);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
else if (value && typeof value === 'object') {
|
|
149
|
-
for (const [key, val] of Object.entries(value)) {
|
|
150
|
-
if (val && typeof val === 'object') {
|
|
151
|
-
if (Array.isArray(val)) {
|
|
152
|
-
val.forEach(item => {
|
|
153
|
-
if (item && typeof item === 'object' && 'selectQuery' in item) {
|
|
154
|
-
this.processValueComponent(item, context, cteNames, queryProcessor, subqueryInfo);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
else if ('selectQuery' in val) {
|
|
159
|
-
this.processValueComponent(val, context, cteNames, queryProcessor, subqueryInfo);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Processes only the tables from a query for EXISTS/NOT EXISTS conditions
|
|
167
|
-
*/
|
|
168
|
-
processQueryTablesOnly(query, context, cteNames, subqueryInfo, operator) {
|
|
169
|
-
if (query.fromClause) {
|
|
170
|
-
const tableNodes = this.dataSourceHandler.extractTableNodeIds(query.fromClause, cteNames);
|
|
171
|
-
for (const tableNodeId of tableNodes) {
|
|
172
|
-
subqueryInfo.push({ nodeId: tableNodeId, operator });
|
|
173
|
-
}
|
|
174
|
-
}
|
|
17
|
+
// Return the current node without adding process nodes
|
|
18
|
+
// Data flow focused: only sources, joins, and unions are shown
|
|
19
|
+
return currentNodeId;
|
|
175
20
|
}
|
|
176
21
|
}
|
|
177
22
|
//# sourceMappingURL=ProcessHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessHandler.js","sourceRoot":"","sources":["../../../../../src/reporting/services/ProcessHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProcessHandler.js","sourceRoot":"","sources":["../../../../../src/reporting/services/ProcessHandler.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACvB,YACY,KAAoB,EACpB,iBAAoC;QADpC,UAAK,GAAL,KAAK,CAAe;QACpB,sBAAiB,GAAjB,iBAAiB,CAAmB;IAC7C,CAAC;IAEJ;;;;OAIG;IACH,mBAAmB,CACf,KAAwB,EACxB,OAAe,EACf,aAAqB,EACrB,QAAqB,EACrB,cAA8E;QAE9E,uDAAuD;QACvD,+DAA+D;QAC/D,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ"}
|
|
@@ -29,7 +29,11 @@ export declare abstract class BaseTokenReader {
|
|
|
29
29
|
/**
|
|
30
30
|
* Create a lexeme with the specified type and value
|
|
31
31
|
*/
|
|
32
|
-
protected createLexeme(type: TokenType, value: string, comments?: string[] | null): Lexeme;
|
|
32
|
+
protected createLexeme(type: TokenType, value: string, comments?: string[] | null, startPosition?: number, endPosition?: number): Lexeme;
|
|
33
|
+
/**
|
|
34
|
+
* Create a lexeme with automatic position tracking
|
|
35
|
+
*/
|
|
36
|
+
protected createLexemeWithPosition(type: TokenType, value: string, startPos: number, comments?: string[] | null): Lexeme;
|
|
33
37
|
/**
|
|
34
38
|
* Get debug info for error reporting
|
|
35
39
|
*/
|
|
@@ -49,22 +49,28 @@ export class BaseTokenReader {
|
|
|
49
49
|
/**
|
|
50
50
|
* Create a lexeme with the specified type and value
|
|
51
51
|
*/
|
|
52
|
-
createLexeme(type, value, comments = null) {
|
|
53
|
-
|
|
54
|
-
// Benchmark tests showed that directly calling toLowerCase() is ~5x faster
|
|
55
|
-
// than first checking if the string is already lowercase.
|
|
56
|
-
// See benchmarks/lowercase-benchmark.js for detailed performance analysis.
|
|
57
|
-
return {
|
|
58
|
-
type,
|
|
59
|
-
value: value.toLowerCase(),
|
|
60
|
-
comments: comments,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
52
|
+
createLexeme(type, value, comments = null, startPosition, endPosition) {
|
|
53
|
+
const lexeme = {
|
|
64
54
|
type,
|
|
65
|
-
value
|
|
55
|
+
value: (type === TokenType.Command || type === TokenType.Operator || type === TokenType.Function)
|
|
56
|
+
? value.toLowerCase()
|
|
57
|
+
: value,
|
|
66
58
|
comments: comments,
|
|
67
59
|
};
|
|
60
|
+
// Add position information if provided
|
|
61
|
+
if (startPosition !== undefined && endPosition !== undefined) {
|
|
62
|
+
lexeme.position = {
|
|
63
|
+
startPosition,
|
|
64
|
+
endPosition,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return lexeme;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a lexeme with automatic position tracking
|
|
71
|
+
*/
|
|
72
|
+
createLexemeWithPosition(type, value, startPos, comments = null) {
|
|
73
|
+
return this.createLexeme(type, value, comments, startPos, startPos + value.length);
|
|
68
74
|
}
|
|
69
75
|
/**
|
|
70
76
|
* Get debug info for error reporting
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseTokenReader.js","sourceRoot":"","sources":["../../../../src/tokenReaders/BaseTokenReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,
|
|
1
|
+
{"version":3,"file":"BaseTokenReader.js","sourceRoot":"","sources":["../../../../src/tokenReaders/BaseTokenReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAkB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAgB,eAAe;IAIjC,YAAY,KAAa,EAAE,WAAmB,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,WAAW;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,WAAW,CAAC,QAAgB;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED;;OAEG;IACO,YAAY,CAAC,QAAgB,CAAC;QACpC,OAAO,IAAI,CAAC,QAAQ,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IACtD,CAAC;IAED;;OAEG;IACO,OAAO,CAAC,QAAgB,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACO,IAAI,CAAC,UAAkB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;IACvF,CAAC;IAED;;OAEG;IACO,oBAAoB,CAAC,WAAmB;QAC9C,OAAO,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACrE,CAAC;CAQJ"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { CommonTable } from "../models/Clause";
|
|
2
|
+
import { SimpleSelectQuery } from "../models/SimpleSelectQuery";
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing a dependency relationship between CTEs
|
|
5
|
+
*/
|
|
6
|
+
export interface CTEEdge {
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Interface representing a CTE node in the dependency graph
|
|
12
|
+
*/
|
|
13
|
+
export interface CTENode {
|
|
14
|
+
name: string;
|
|
15
|
+
cte: CommonTable;
|
|
16
|
+
dependencies: string[];
|
|
17
|
+
dependents: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Interface representing the complete CTE dependency graph
|
|
21
|
+
*/
|
|
22
|
+
export interface CTEDependencyGraph {
|
|
23
|
+
nodes: CTENode[];
|
|
24
|
+
edges: CTEEdge[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Analyzer for CTE dependencies in SQL queries.
|
|
28
|
+
* Provides functionality to analyze dependencies, detect circular references,
|
|
29
|
+
* and generate topological ordering of CTEs.
|
|
30
|
+
*/
|
|
31
|
+
export declare class CTEDependencyAnalyzer {
|
|
32
|
+
private static readonly ERROR_MESSAGES;
|
|
33
|
+
private readonly sourceCollector;
|
|
34
|
+
private readonly cteCollector;
|
|
35
|
+
private dependencyGraph;
|
|
36
|
+
private cteMap;
|
|
37
|
+
constructor();
|
|
38
|
+
/**
|
|
39
|
+
* Analyzes the dependencies between CTEs in the given query
|
|
40
|
+
* @param query The query to analyze
|
|
41
|
+
* @returns The dependency graph
|
|
42
|
+
*/
|
|
43
|
+
analyzeDependencies(query: SimpleSelectQuery): CTEDependencyGraph;
|
|
44
|
+
/**
|
|
45
|
+
* Gets the list of CTEs that the specified CTE depends on
|
|
46
|
+
* @param cteName The name of the CTE
|
|
47
|
+
* @returns Array of CTE names this CTE depends on
|
|
48
|
+
*/
|
|
49
|
+
getDependencies(cteName: string): string[];
|
|
50
|
+
/**
|
|
51
|
+
* Gets the list of CTEs that depend on the specified CTE
|
|
52
|
+
* @param cteName The name of the CTE
|
|
53
|
+
* @returns Array of CTE names that depend on this CTE
|
|
54
|
+
*/
|
|
55
|
+
getDependents(cteName: string): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Checks if there are any circular dependencies in the CTE graph
|
|
58
|
+
* @returns true if circular dependencies exist, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
hasCircularDependency(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the topological sort order for CTE execution
|
|
63
|
+
* @returns Array of CTE names in execution order
|
|
64
|
+
* @throws Error if circular dependencies are detected
|
|
65
|
+
*/
|
|
66
|
+
getExecutionOrder(): string[];
|
|
67
|
+
/**
|
|
68
|
+
* Builds the dependency graph from the given CTEs
|
|
69
|
+
* @param ctes Array of CommonTable objects
|
|
70
|
+
* @returns The constructed dependency graph
|
|
71
|
+
*/
|
|
72
|
+
private buildDependencyGraph;
|
|
73
|
+
/**
|
|
74
|
+
* Ensures that dependency analysis has been performed
|
|
75
|
+
* @throws Error if analyzeDependencies has not been called
|
|
76
|
+
*/
|
|
77
|
+
private ensureAnalyzed;
|
|
78
|
+
/**
|
|
79
|
+
* Builds the CTE name-to-object mapping for quick lookups
|
|
80
|
+
* @param ctes Array of CommonTable objects
|
|
81
|
+
*/
|
|
82
|
+
private buildCTEMap;
|
|
83
|
+
/**
|
|
84
|
+
* Finds a node in the dependency graph by CTE name
|
|
85
|
+
* @param cteName The name of the CTE to find
|
|
86
|
+
* @returns The CTENode if found, undefined otherwise
|
|
87
|
+
*/
|
|
88
|
+
private findNodeByName;
|
|
89
|
+
/**
|
|
90
|
+
* Extracts the name from a CommonTable
|
|
91
|
+
* @param cte The CommonTable object
|
|
92
|
+
* @returns The name of the CTE
|
|
93
|
+
*/
|
|
94
|
+
private static getCTEName;
|
|
95
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { CTECollector } from "./CTECollector";
|
|
2
|
+
import { TableSourceCollector } from "./TableSourceCollector";
|
|
3
|
+
/**
|
|
4
|
+
* Analyzer for CTE dependencies in SQL queries.
|
|
5
|
+
* Provides functionality to analyze dependencies, detect circular references,
|
|
6
|
+
* and generate topological ordering of CTEs.
|
|
7
|
+
*/
|
|
8
|
+
export class CTEDependencyAnalyzer {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.dependencyGraph = null;
|
|
11
|
+
this.cteMap = new Map();
|
|
12
|
+
this.sourceCollector = new TableSourceCollector(true);
|
|
13
|
+
this.cteCollector = new CTECollector();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Analyzes the dependencies between CTEs in the given query
|
|
17
|
+
* @param query The query to analyze
|
|
18
|
+
* @returns The dependency graph
|
|
19
|
+
*/
|
|
20
|
+
analyzeDependencies(query) {
|
|
21
|
+
const ctes = this.cteCollector.collect(query);
|
|
22
|
+
this.buildCTEMap(ctes);
|
|
23
|
+
this.dependencyGraph = this.buildDependencyGraph(ctes);
|
|
24
|
+
return this.dependencyGraph;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets the list of CTEs that the specified CTE depends on
|
|
28
|
+
* @param cteName The name of the CTE
|
|
29
|
+
* @returns Array of CTE names this CTE depends on
|
|
30
|
+
*/
|
|
31
|
+
getDependencies(cteName) {
|
|
32
|
+
this.ensureAnalyzed();
|
|
33
|
+
const node = this.findNodeByName(cteName);
|
|
34
|
+
return node ? [...node.dependencies] : [];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the list of CTEs that depend on the specified CTE
|
|
38
|
+
* @param cteName The name of the CTE
|
|
39
|
+
* @returns Array of CTE names that depend on this CTE
|
|
40
|
+
*/
|
|
41
|
+
getDependents(cteName) {
|
|
42
|
+
this.ensureAnalyzed();
|
|
43
|
+
const node = this.findNodeByName(cteName);
|
|
44
|
+
return node ? [...node.dependents] : [];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Checks if there are any circular dependencies in the CTE graph
|
|
48
|
+
* @returns true if circular dependencies exist, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
hasCircularDependency() {
|
|
51
|
+
this.ensureAnalyzed();
|
|
52
|
+
try {
|
|
53
|
+
this.getExecutionOrder();
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof Error && error.message.includes(CTEDependencyAnalyzer.ERROR_MESSAGES.CIRCULAR_REFERENCE)) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets the topological sort order for CTE execution
|
|
65
|
+
* @returns Array of CTE names in execution order
|
|
66
|
+
* @throws Error if circular dependencies are detected
|
|
67
|
+
*/
|
|
68
|
+
getExecutionOrder() {
|
|
69
|
+
this.ensureAnalyzed();
|
|
70
|
+
const visited = new Set();
|
|
71
|
+
const visiting = new Set();
|
|
72
|
+
const result = [];
|
|
73
|
+
// Build adjacency list from dependency graph
|
|
74
|
+
const dependencyMap = new Map();
|
|
75
|
+
for (const node of this.dependencyGraph.nodes) {
|
|
76
|
+
dependencyMap.set(node.name, new Set(node.dependencies));
|
|
77
|
+
}
|
|
78
|
+
const visit = (nodeName) => {
|
|
79
|
+
if (visited.has(nodeName))
|
|
80
|
+
return;
|
|
81
|
+
if (visiting.has(nodeName)) {
|
|
82
|
+
throw new Error(`${CTEDependencyAnalyzer.ERROR_MESSAGES.CIRCULAR_REFERENCE}: ${nodeName}`);
|
|
83
|
+
}
|
|
84
|
+
visiting.add(nodeName);
|
|
85
|
+
const deps = dependencyMap.get(nodeName) || new Set();
|
|
86
|
+
for (const dep of deps) {
|
|
87
|
+
visit(dep);
|
|
88
|
+
}
|
|
89
|
+
visiting.delete(nodeName);
|
|
90
|
+
visited.add(nodeName);
|
|
91
|
+
result.push(nodeName);
|
|
92
|
+
};
|
|
93
|
+
// Visit all nodes
|
|
94
|
+
for (const node of this.dependencyGraph.nodes) {
|
|
95
|
+
if (!visited.has(node.name)) {
|
|
96
|
+
visit(node.name);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Builds the dependency graph from the given CTEs
|
|
103
|
+
* @param ctes Array of CommonTable objects
|
|
104
|
+
* @returns The constructed dependency graph
|
|
105
|
+
*/
|
|
106
|
+
buildDependencyGraph(ctes) {
|
|
107
|
+
const nodes = [];
|
|
108
|
+
const edges = [];
|
|
109
|
+
const dependencyMap = new Map();
|
|
110
|
+
const dependentMap = new Map();
|
|
111
|
+
// Initialize maps for all CTEs
|
|
112
|
+
for (const cte of ctes) {
|
|
113
|
+
const name = CTEDependencyAnalyzer.getCTEName(cte);
|
|
114
|
+
dependencyMap.set(name, new Set());
|
|
115
|
+
dependentMap.set(name, new Set());
|
|
116
|
+
}
|
|
117
|
+
// Analyze dependencies for each CTE
|
|
118
|
+
for (const cte of ctes) {
|
|
119
|
+
const cteName = CTEDependencyAnalyzer.getCTEName(cte);
|
|
120
|
+
// Find all table/CTE references in this CTE's query
|
|
121
|
+
const referencedTables = this.sourceCollector.collect(cte.query);
|
|
122
|
+
for (const referencedTable of referencedTables) {
|
|
123
|
+
const referencedName = referencedTable.table.name;
|
|
124
|
+
// Only consider references to other CTEs in our collection
|
|
125
|
+
if (this.cteMap.has(referencedName) && referencedName !== cteName) {
|
|
126
|
+
dependencyMap.get(cteName).add(referencedName);
|
|
127
|
+
dependentMap.get(referencedName).add(cteName);
|
|
128
|
+
edges.push({
|
|
129
|
+
from: cteName,
|
|
130
|
+
to: referencedName
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Create nodes with dependency and dependent information
|
|
136
|
+
for (const cte of ctes) {
|
|
137
|
+
const name = CTEDependencyAnalyzer.getCTEName(cte);
|
|
138
|
+
nodes.push({
|
|
139
|
+
name,
|
|
140
|
+
cte,
|
|
141
|
+
dependencies: Array.from(dependencyMap.get(name) || new Set()),
|
|
142
|
+
dependents: Array.from(dependentMap.get(name) || new Set())
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return { nodes, edges };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Ensures that dependency analysis has been performed
|
|
149
|
+
* @throws Error if analyzeDependencies has not been called
|
|
150
|
+
*/
|
|
151
|
+
ensureAnalyzed() {
|
|
152
|
+
if (!this.dependencyGraph) {
|
|
153
|
+
throw new Error(CTEDependencyAnalyzer.ERROR_MESSAGES.NOT_ANALYZED);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Builds the CTE name-to-object mapping for quick lookups
|
|
158
|
+
* @param ctes Array of CommonTable objects
|
|
159
|
+
*/
|
|
160
|
+
buildCTEMap(ctes) {
|
|
161
|
+
this.cteMap.clear();
|
|
162
|
+
for (const cte of ctes) {
|
|
163
|
+
const name = CTEDependencyAnalyzer.getCTEName(cte);
|
|
164
|
+
this.cteMap.set(name, cte);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Finds a node in the dependency graph by CTE name
|
|
169
|
+
* @param cteName The name of the CTE to find
|
|
170
|
+
* @returns The CTENode if found, undefined otherwise
|
|
171
|
+
*/
|
|
172
|
+
findNodeByName(cteName) {
|
|
173
|
+
var _a;
|
|
174
|
+
return (_a = this.dependencyGraph) === null || _a === void 0 ? void 0 : _a.nodes.find(n => n.name === cteName);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Extracts the name from a CommonTable
|
|
178
|
+
* @param cte The CommonTable object
|
|
179
|
+
* @returns The name of the CTE
|
|
180
|
+
*/
|
|
181
|
+
static getCTEName(cte) {
|
|
182
|
+
return cte.aliasExpression.table.name;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
CTEDependencyAnalyzer.ERROR_MESSAGES = {
|
|
186
|
+
NOT_ANALYZED: "Must call analyzeDependencies first",
|
|
187
|
+
CIRCULAR_REFERENCE: "Circular reference detected in CTE"
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=CTEDependencyAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CTEDependencyAnalyzer.js","sourceRoot":"","sources":["../../../../src/transformers/CTEDependencyAnalyzer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA4B9D;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IAW9B;QAHQ,oBAAe,GAA8B,IAAI,CAAC;QAClD,WAAM,GAA6B,IAAI,GAAG,EAAE,CAAC;QAGjD,IAAI,CAAC,eAAe,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACI,mBAAmB,CAAC,KAAwB;QAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,OAAe;QAClC,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,IAAI,CAAC,c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