sof-mssql 2.1.0 → 2.2.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.
- package/dist/queryGenerator/index.d.ts +0 -4
- package/dist/queryGenerator/index.d.ts.map +1 -1
- package/dist/queryGenerator/index.js +1 -9
- package/dist/queryGenerator/index.js.map +1 -1
- package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts +26 -0
- package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/aliasGenerator.js +31 -0
- package/dist/queryGenerator/treeWalker/aliasGenerator.js.map +1 -0
- package/dist/queryGenerator/treeWalker/classify.d.ts +19 -0
- package/dist/queryGenerator/treeWalker/classify.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/classify.js +36 -0
- package/dist/queryGenerator/treeWalker/classify.js.map +1 -0
- package/dist/queryGenerator/treeWalker/compile.d.ts +29 -0
- package/dist/queryGenerator/treeWalker/compile.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/compile.js +98 -0
- package/dist/queryGenerator/treeWalker/compile.js.map +1 -0
- package/dist/queryGenerator/treeWalker/cteTemplates.d.ts +50 -0
- package/dist/queryGenerator/treeWalker/cteTemplates.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/cteTemplates.js +95 -0
- package/dist/queryGenerator/treeWalker/cteTemplates.js.map +1 -0
- package/dist/queryGenerator/treeWalker/index.d.ts +6 -0
- package/dist/queryGenerator/treeWalker/index.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/index.js +9 -0
- package/dist/queryGenerator/treeWalker/index.js.map +1 -0
- package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts +28 -0
- package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/mergeSiblings.js +54 -0
- package/dist/queryGenerator/treeWalker/mergeSiblings.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts +40 -0
- package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/columnsOnly.js +56 -0
- package/dist/queryGenerator/treeWalker/operators/columnsOnly.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/forEach.d.ts +45 -0
- package/dist/queryGenerator/treeWalker/operators/forEach.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/forEach.js +144 -0
- package/dist/queryGenerator/treeWalker/operators/forEach.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/group.d.ts +35 -0
- package/dist/queryGenerator/treeWalker/operators/group.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/group.js +56 -0
- package/dist/queryGenerator/treeWalker/operators/group.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/repeat.d.ts +45 -0
- package/dist/queryGenerator/treeWalker/operators/repeat.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/repeat.js +110 -0
- package/dist/queryGenerator/treeWalker/operators/repeat.js.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts +54 -0
- package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/operators/unionAll.js +121 -0
- package/dist/queryGenerator/treeWalker/operators/unionAll.js.map +1 -0
- package/dist/queryGenerator/treeWalker/render.d.ts +34 -0
- package/dist/queryGenerator/treeWalker/render.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/render.js +41 -0
- package/dist/queryGenerator/treeWalker/render.js.map +1 -0
- package/dist/queryGenerator/treeWalker/types.d.ts +66 -0
- package/dist/queryGenerator/treeWalker/types.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/types.js +14 -0
- package/dist/queryGenerator/treeWalker/types.js.map +1 -0
- package/dist/queryGenerator/treeWalker/walker.d.ts +36 -0
- package/dist/queryGenerator/treeWalker/walker.d.ts.map +1 -0
- package/dist/queryGenerator/treeWalker/walker.js +58 -0
- package/dist/queryGenerator/treeWalker/walker.js.map +1 -0
- package/dist/queryGenerator.d.ts +8 -94
- package/dist/queryGenerator.d.ts.map +1 -1
- package/dist/queryGenerator.js +16 -268
- package/dist/queryGenerator.js.map +1 -1
- package/package.json +1 -1
- package/dist/queryGenerator/ForEachProcessor.d.ts +0 -127
- package/dist/queryGenerator/ForEachProcessor.d.ts.map +0 -1
- package/dist/queryGenerator/ForEachProcessor.js +0 -351
- package/dist/queryGenerator/ForEachProcessor.js.map +0 -1
- package/dist/queryGenerator/RepeatProcessor.d.ts +0 -177
- package/dist/queryGenerator/RepeatProcessor.d.ts.map +0 -1
- package/dist/queryGenerator/RepeatProcessor.js +0 -336
- package/dist/queryGenerator/RepeatProcessor.js.map +0 -1
- package/dist/queryGenerator/SelectClauseBuilder.d.ts +0 -108
- package/dist/queryGenerator/SelectClauseBuilder.d.ts.map +0 -1
- package/dist/queryGenerator/SelectClauseBuilder.js +0 -346
- package/dist/queryGenerator/SelectClauseBuilder.js.map +0 -1
- package/dist/queryGenerator/SelectCombinationExpander.d.ts +0 -42
- package/dist/queryGenerator/SelectCombinationExpander.d.ts.map +0 -1
- package/dist/queryGenerator/SelectCombinationExpander.js +0 -95
- package/dist/queryGenerator/SelectCombinationExpander.js.map +0 -1
package/dist/queryGenerator.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* T-SQL query generator for ViewDefinition structures.
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* Public façade over the tree-walker query compiler. Builds the base
|
|
6
|
+
* transpiler context (resource alias, constants, optional test id) and
|
|
7
|
+
* delegates SQL generation to `compileViewDefinition`.
|
|
5
8
|
*/
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
exports.QueryGenerator = void 0;
|
|
8
|
-
const
|
|
9
|
-
const index_js_1 = require("./queryGenerator/index.js");
|
|
11
|
+
const index_js_1 = require("./queryGenerator/treeWalker/index.js");
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
13
|
+
* Compiles a SQL on FHIR `ViewDefinition` to a T-SQL query.
|
|
12
14
|
*/
|
|
13
15
|
class QueryGenerator {
|
|
14
16
|
options;
|
|
15
|
-
pathParser;
|
|
16
|
-
combinationExpander;
|
|
17
|
-
forEachProcessor;
|
|
18
|
-
repeatProcessor;
|
|
19
|
-
selectClauseBuilder;
|
|
20
|
-
whereClauseBuilder;
|
|
21
|
-
columnGenerator;
|
|
22
17
|
constructor(options = {}) {
|
|
23
18
|
this.options = {
|
|
24
19
|
tableName: "fhir_resources",
|
|
@@ -27,249 +22,26 @@ class QueryGenerator {
|
|
|
27
22
|
resourceJsonColumn: "json",
|
|
28
23
|
...options,
|
|
29
24
|
};
|
|
30
|
-
// Initialise specialised processors.
|
|
31
|
-
this.pathParser = new index_js_1.PathParser();
|
|
32
|
-
this.combinationExpander = new index_js_1.SelectCombinationExpander();
|
|
33
|
-
this.columnGenerator = new index_js_1.ColumnExpressionGenerator();
|
|
34
|
-
this.forEachProcessor = new index_js_1.ForEachProcessor(this.pathParser);
|
|
35
|
-
this.repeatProcessor = new index_js_1.RepeatProcessor();
|
|
36
|
-
this.selectClauseBuilder = new index_js_1.SelectClauseBuilder(this.columnGenerator);
|
|
37
|
-
this.whereClauseBuilder = new index_js_1.WhereClauseBuilder();
|
|
38
25
|
}
|
|
39
26
|
/**
|
|
40
27
|
* Generate a T-SQL query from a ViewDefinition.
|
|
41
28
|
*/
|
|
42
29
|
generateQuery(viewDef, testId) {
|
|
43
30
|
try {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const withClause = `WITH\n${allCteDefinitions.join(",\n")}\n`;
|
|
52
|
-
sql = withClause + statements.join("\nUNION ALL\n");
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
sql = statements.join("\nUNION ALL\n");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// Single statement. If it has CTEs, they're already included.
|
|
60
|
-
sql = statements[0];
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
sql,
|
|
64
|
-
columns,
|
|
65
|
-
};
|
|
31
|
+
const transpilerCtx = this.createBaseContext(viewDef, testId);
|
|
32
|
+
return (0, index_js_1.compileViewDefinition)(viewDef, {
|
|
33
|
+
tableName: this.options.tableName,
|
|
34
|
+
schemaName: this.options.schemaName,
|
|
35
|
+
testId,
|
|
36
|
+
transpilerCtx,
|
|
37
|
+
});
|
|
66
38
|
}
|
|
67
39
|
catch (error) {
|
|
68
40
|
throw new Error(`Failed to generate query for ViewDefinition: ${error}`);
|
|
69
41
|
}
|
|
70
42
|
}
|
|
71
43
|
/**
|
|
72
|
-
*
|
|
73
|
-
*/
|
|
74
|
-
generateAllSelectStatements(viewDef, context) {
|
|
75
|
-
const unionCombinations = this.combinationExpander.expandCombinations(viewDef.select);
|
|
76
|
-
const statements = [];
|
|
77
|
-
const allCteDefinitions = [];
|
|
78
|
-
const isMultiUnion = unionCombinations.length > 1;
|
|
79
|
-
// Shared counter state to ensure unique CTE aliases across all combinations.
|
|
80
|
-
const cteCounter = { value: 0 };
|
|
81
|
-
for (const combination of unionCombinations) {
|
|
82
|
-
const { statement, cteDefinitions } = this.generateStatementForCombination(combination, viewDef, context, isMultiUnion, cteCounter);
|
|
83
|
-
statements.push(statement);
|
|
84
|
-
allCteDefinitions.push(...cteDefinitions);
|
|
85
|
-
}
|
|
86
|
-
return { statements, allCteDefinitions };
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Generate a complete SQL statement for a specific combination.
|
|
90
|
-
*
|
|
91
|
-
* Routes to the appropriate statement generator based on the directives
|
|
92
|
-
* present in the combination:
|
|
93
|
-
* - Repeat statements use recursive CTEs.
|
|
94
|
-
* - ForEach statements use CROSS APPLY.
|
|
95
|
-
* - Simple statements have neither.
|
|
96
|
-
*
|
|
97
|
-
* @param combination - The select combination to generate.
|
|
98
|
-
* @param viewDef - The ViewDefinition being processed.
|
|
99
|
-
* @param context - The transpiler context.
|
|
100
|
-
* @param isMultiUnion - If true, CTEs are returned separately for consolidation.
|
|
101
|
-
* @param cteCounter - Shared counter for unique CTE aliases across combinations.
|
|
102
|
-
* @returns The statement and any CTE definitions (empty if not repeat or single statement).
|
|
103
|
-
*/
|
|
104
|
-
generateStatementForCombination(combination, viewDef, context, isMultiUnion, cteCounter) {
|
|
105
|
-
const hasRepeat = this.repeatProcessor.combinationHasRepeat(combination);
|
|
106
|
-
const hasForEach = this.forEachProcessor.combinationHasForEach(combination);
|
|
107
|
-
// Repeat takes precedence if both are present (forEach will be nested).
|
|
108
|
-
if (hasRepeat) {
|
|
109
|
-
return this.generateRepeatStatement(combination, viewDef, context, isMultiUnion, cteCounter);
|
|
110
|
-
}
|
|
111
|
-
else if (hasForEach) {
|
|
112
|
-
return {
|
|
113
|
-
statement: this.generateForEachStatement(combination, viewDef, context),
|
|
114
|
-
cteDefinitions: [],
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
return {
|
|
119
|
-
statement: this.generateSimpleStatement(combination, viewDef, context),
|
|
120
|
-
cteDefinitions: [],
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Generate a simple SELECT statement without forEach.
|
|
126
|
-
*/
|
|
127
|
-
generateSimpleStatement(combination, viewDef, context) {
|
|
128
|
-
const selectClause = this.selectClauseBuilder.generateSimpleSelectClause(combination, context);
|
|
129
|
-
const fromClause = this.generateFromClause(context);
|
|
130
|
-
const whereClause = this.whereClauseBuilder.buildWhereClause(viewDef.resource, context.resourceAlias, context.testId, viewDef.where, context);
|
|
131
|
-
let statement = `${selectClause}\n${fromClause}`;
|
|
132
|
-
if (whereClause !== null) {
|
|
133
|
-
statement += `\n${whereClause}`;
|
|
134
|
-
}
|
|
135
|
-
return statement;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Generate a SELECT statement with forEach using CROSS APPLY.
|
|
139
|
-
*/
|
|
140
|
-
generateForEachStatement(combination, viewDef, context) {
|
|
141
|
-
const fromClause = this.generateFromClause(context);
|
|
142
|
-
const { forEachContextMap, topLevelForEach } = this.forEachProcessor.buildForEachContextMap(combination.selects, context, combination);
|
|
143
|
-
const applyClauses = this.forEachProcessor.buildApplyClauses(forEachContextMap, topLevelForEach, combination);
|
|
144
|
-
const selectClause = this.selectClauseBuilder.generateForEachSelectClause(combination, context, forEachContextMap);
|
|
145
|
-
const whereClause = this.whereClauseBuilder.buildWhereClause(viewDef.resource, context.resourceAlias, context.testId, viewDef.where, context);
|
|
146
|
-
let statement = `${selectClause}\n${fromClause}${applyClauses}`;
|
|
147
|
-
if (whereClause !== null) {
|
|
148
|
-
statement += `\n${whereClause}`;
|
|
149
|
-
}
|
|
150
|
-
return statement;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Generate a SELECT statement with repeat using recursive CTEs.
|
|
154
|
-
*
|
|
155
|
-
* The repeat directive generates a recursive CTE that traverses a tree
|
|
156
|
-
* structure by following one or more paths at each level. The CTE is then
|
|
157
|
-
* joined to the main query using INNER JOIN.
|
|
158
|
-
*
|
|
159
|
-
* If the combination also contains forEach, the forEach is processed after
|
|
160
|
-
* the repeat CTE, using the repeat context as its source.
|
|
161
|
-
*
|
|
162
|
-
* @param combination - The select combination being processed.
|
|
163
|
-
* @param viewDef - The ViewDefinition.
|
|
164
|
-
* @param context - The transpiler context.
|
|
165
|
-
* @param isMultiUnion - If true, return CTE definitions separately for consolidation.
|
|
166
|
-
* @param cteCounter - Shared counter for unique CTE aliases across combinations.
|
|
167
|
-
* @returns Statement and CTE definitions.
|
|
168
|
-
*/
|
|
169
|
-
generateRepeatStatement(combination, viewDef, context, isMultiUnion, cteCounter) {
|
|
170
|
-
// Build repeat contexts and CTEs.
|
|
171
|
-
const { repeatContextMap, topLevelRepeat } = this.repeatProcessor.buildRepeatContextMap(combination.selects, context, combination, cteCounter);
|
|
172
|
-
const tableName = `[${this.options.schemaName}].[${this.options.tableName}]`;
|
|
173
|
-
const cteDefinitions = this.repeatProcessor.buildRepeatCteDefinitions(repeatContextMap, topLevelRepeat, context.resourceAlias, viewDef.resource, context.testId, tableName);
|
|
174
|
-
const joinClauses = this.repeatProcessor.buildRepeatApplyClauses(repeatContextMap, topLevelRepeat, context.resourceAlias);
|
|
175
|
-
const { selectClause, forEachApplyClauses } = this.buildRepeatSelectAndForEach(combination, context, repeatContextMap);
|
|
176
|
-
const fromClause = this.generateFromClause(context);
|
|
177
|
-
const statement = this.assembleRepeatStatement(selectClause, fromClause, joinClauses, forEachApplyClauses, cteDefinitions, isMultiUnion);
|
|
178
|
-
return { statement, cteDefinitions: isMultiUnion ? cteDefinitions : [] };
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Build select clause and forEach apply clauses for repeat statements.
|
|
182
|
-
*/
|
|
183
|
-
buildRepeatSelectAndForEach(combination, context, repeatContextMap) {
|
|
184
|
-
const hasNestedForEach = this.forEachProcessor.combinationHasForEach(combination);
|
|
185
|
-
if (!hasNestedForEach) {
|
|
186
|
-
return {
|
|
187
|
-
selectClause: this.selectClauseBuilder.generateRepeatSelectClause(combination, context, repeatContextMap),
|
|
188
|
-
forEachApplyClauses: "",
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
const { forEachContextMap, topLevelForEach } = this.forEachProcessor.buildForEachContextMap(combination.selects, context, combination);
|
|
192
|
-
this.updateForEachSourcesForRepeat(forEachContextMap, repeatContextMap);
|
|
193
|
-
return {
|
|
194
|
-
selectClause: this.selectClauseBuilder.generateRepeatSelectClause(combination, context, repeatContextMap, forEachContextMap),
|
|
195
|
-
forEachApplyClauses: this.forEachProcessor.buildApplyClauses(forEachContextMap, topLevelForEach, combination),
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Assemble the final repeat statement from its components.
|
|
200
|
-
*/
|
|
201
|
-
assembleRepeatStatement(selectClause, fromClause, joinClauses, forEachApplyClauses, cteDefinitions, isMultiUnion) {
|
|
202
|
-
const baseStatement = `${selectClause}\n${fromClause}${joinClauses}${forEachApplyClauses}`;
|
|
203
|
-
if (isMultiUnion) {
|
|
204
|
-
return baseStatement;
|
|
205
|
-
}
|
|
206
|
-
const withClause = cteDefinitions.length > 0 ? `WITH\n${cteDefinitions.join(",\n")}\n` : "";
|
|
207
|
-
return `${withClause}${baseStatement}`;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Update forEach source expressions to use repeat CTE instead of resource JSON.
|
|
211
|
-
*
|
|
212
|
-
* When forEach is nested inside repeat, the forEach should iterate over
|
|
213
|
-
* arrays within the repeat context (e.g., repeat_0.item_json) rather than
|
|
214
|
-
* the root resource JSON.
|
|
215
|
-
*/
|
|
216
|
-
updateForEachSourcesForRepeat(forEachContextMap, repeatContextMap) {
|
|
217
|
-
// Find the repeat select that contains each forEach.
|
|
218
|
-
for (const [forEachSelect, forEachContext] of forEachContextMap) {
|
|
219
|
-
const containingRepeat = this.findContainingRepeat(forEachSelect, repeatContextMap);
|
|
220
|
-
if (containingRepeat) {
|
|
221
|
-
const repeatContext = repeatContextMap.get(containingRepeat);
|
|
222
|
-
if (repeatContext) {
|
|
223
|
-
// Update the forEach source to use the repeat CTE's item_json.
|
|
224
|
-
forEachContext.forEachSource = `${repeatContext.cteAlias}.item_json`;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Find the repeat select that contains a given forEach select.
|
|
231
|
-
*/
|
|
232
|
-
findContainingRepeat(forEachSelect, repeatContextMap) {
|
|
233
|
-
// Check each repeat select to see if the forEach is nested within it.
|
|
234
|
-
for (const [repeatSelect] of repeatContextMap) {
|
|
235
|
-
if (this.isForEachNestedInRepeat(forEachSelect, repeatSelect)) {
|
|
236
|
-
return repeatSelect;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return undefined;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Check if a forEach select is nested within a repeat select.
|
|
243
|
-
*/
|
|
244
|
-
isForEachNestedInRepeat(forEachSelect, repeatSelect) {
|
|
245
|
-
if (!repeatSelect.select) {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
return this.isSelectNestedIn(forEachSelect, repeatSelect.select);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Recursively check if a select is nested within a list of selects.
|
|
252
|
-
*/
|
|
253
|
-
isSelectNestedIn(target, selects) {
|
|
254
|
-
for (const select of selects) {
|
|
255
|
-
if (select === target) {
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
if (select.select && this.isSelectNestedIn(target, select.select)) {
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Generate the FROM clause.
|
|
266
|
-
*/
|
|
267
|
-
generateFromClause(context) {
|
|
268
|
-
const tableName = `[${this.options.schemaName}].[${this.options.tableName}]`;
|
|
269
|
-
return `FROM ${tableName} AS [${context.resourceAlias}]`;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Create the base transpiler context.
|
|
44
|
+
* Create the base transpiler context with resource alias and constants.
|
|
273
45
|
*/
|
|
274
46
|
createBaseContext(viewDef, testId) {
|
|
275
47
|
const constants = {};
|
|
@@ -285,7 +57,8 @@ class QueryGenerator {
|
|
|
285
57
|
};
|
|
286
58
|
}
|
|
287
59
|
/**
|
|
288
|
-
* Extract the value from a ViewDefinitionConstant.
|
|
60
|
+
* Extract the value from a ViewDefinitionConstant. Throws if zero or more
|
|
61
|
+
* than one `value[x]` element is set.
|
|
289
62
|
*/
|
|
290
63
|
getConstantValue(constant) {
|
|
291
64
|
const primitiveKeys = [
|
|
@@ -320,31 +93,6 @@ class QueryGenerator {
|
|
|
320
93
|
const key = definedValues[0];
|
|
321
94
|
return constant[key];
|
|
322
95
|
}
|
|
323
|
-
/**
|
|
324
|
-
* Collect all column definitions from select elements.
|
|
325
|
-
*/
|
|
326
|
-
collectAllColumns(selects) {
|
|
327
|
-
const columns = [];
|
|
328
|
-
for (const select of selects) {
|
|
329
|
-
if (select.column) {
|
|
330
|
-
for (const column of select.column) {
|
|
331
|
-
columns.push({
|
|
332
|
-
name: column.name,
|
|
333
|
-
type: transpiler_js_1.Transpiler.inferSqlType(column.type, column.tag),
|
|
334
|
-
nullable: true, // FHIR data is generally nullable.
|
|
335
|
-
description: column.description,
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (select.select) {
|
|
340
|
-
columns.push(...this.collectAllColumns(select.select));
|
|
341
|
-
}
|
|
342
|
-
if (select.unionAll) {
|
|
343
|
-
columns.push(...this.collectAllColumns(select.unionAll));
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return columns;
|
|
347
|
-
}
|
|
348
96
|
}
|
|
349
97
|
exports.QueryGenerator = QueryGenerator;
|
|
350
98
|
//# sourceMappingURL=queryGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryGenerator.js","sourceRoot":"","sources":["../src/queryGenerator.ts"],"names":[],"mappings":";AAAA;;;
|
|
1
|
+
{"version":3,"file":"queryGenerator.js","sourceRoot":"","sources":["../src/queryGenerator.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,mEAA6E;AAc7E;;GAEG;AACH,MAAa,cAAc;IACR,OAAO,CAAkC;IAE1D,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG;YACb,SAAS,EAAE,gBAAgB;YAC3B,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE,IAAI;YACtB,kBAAkB,EAAE,MAAM;YAC1B,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED;;OAEG;IACH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Q,CAAC,GAAG,CAAC,KAAK,SAAS,CACrC,CAAC;QAEF,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,aAAa,QAAQ,CAAC,IAAI,kDAAkD,CAC7E,CAAC;QACJ,CAAC;QAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,aAAa,QAAQ,CAAC,IAAI,6DAA6D,aAAa,CAAC,MAAM,EAAE,CAC9G,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QAC7B,OAAO,QAAQ,CAAC,GAAG,CAA8B,CAAC;IACpD,CAAC;CACF;AArGD,wCAqGC"}
|
package/package.json
CHANGED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Processes forEach operations and generates CROSS APPLY clauses.
|
|
3
|
-
*/
|
|
4
|
-
import { TranspilerContext } from "../fhirpath/transpiler.js";
|
|
5
|
-
import { ViewDefinitionSelect } from "../types.js";
|
|
6
|
-
import { SelectCombination } from "./SelectCombinationExpander.js";
|
|
7
|
-
import { PathParser } from "./PathParser.js";
|
|
8
|
-
/**
|
|
9
|
-
* Result of building forEach context map.
|
|
10
|
-
*/
|
|
11
|
-
interface ForEachContextMapResult {
|
|
12
|
-
forEachContextMap: Map<ViewDefinitionSelect, TranspilerContext>;
|
|
13
|
-
topLevelForEach: ViewDefinitionSelect[];
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Handles all forEach-related processing and CROSS APPLY generation.
|
|
17
|
-
*/
|
|
18
|
-
export declare class ForEachProcessor {
|
|
19
|
-
private readonly pathParser;
|
|
20
|
-
constructor(pathParser: PathParser);
|
|
21
|
-
/**
|
|
22
|
-
* Check if a specific combination has forEach operations.
|
|
23
|
-
*/
|
|
24
|
-
combinationHasForEach(combination: SelectCombination): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Check if a single select has forEach operations (including nested).
|
|
27
|
-
*/
|
|
28
|
-
selectHasForEach(select: ViewDefinitionSelect): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Check if any select in the tree has forEach operations.
|
|
31
|
-
*/
|
|
32
|
-
private hasForEachInSelects;
|
|
33
|
-
/**
|
|
34
|
-
* Check if any unionAll option has forEach operations.
|
|
35
|
-
*/
|
|
36
|
-
private unionAllHasForEach;
|
|
37
|
-
/**
|
|
38
|
-
* Build the forEach context map by generating contexts for all forEach.
|
|
39
|
-
*/
|
|
40
|
-
buildForEachContextMap(selects: ViewDefinitionSelect[], context: TranspilerContext, combination?: SelectCombination): ForEachContextMapResult;
|
|
41
|
-
/**
|
|
42
|
-
* Collect all forEach that should be treated as top-level.
|
|
43
|
-
*/
|
|
44
|
-
private collectTopLevelForEach;
|
|
45
|
-
/**
|
|
46
|
-
* Process a select for forEach, handling both direct forEach and nested selects.
|
|
47
|
-
*/
|
|
48
|
-
private processSelectForEach;
|
|
49
|
-
/**
|
|
50
|
-
* Process a select with a unionAll choice from a combination.
|
|
51
|
-
*/
|
|
52
|
-
private processUnionAllChoice;
|
|
53
|
-
/**
|
|
54
|
-
* Add forEach from a select array to the topLevelForEach list.
|
|
55
|
-
*/
|
|
56
|
-
private addForEachFromSelectArray;
|
|
57
|
-
/**
|
|
58
|
-
* Check if a select is a forEach or forEachOrNull.
|
|
59
|
-
*/
|
|
60
|
-
private isForEachSelect;
|
|
61
|
-
/**
|
|
62
|
-
* Generate forEach contexts recursively.
|
|
63
|
-
*/
|
|
64
|
-
private generateForEachContexts;
|
|
65
|
-
/**
|
|
66
|
-
* Create a transpiler context specific to a forEach.
|
|
67
|
-
*/
|
|
68
|
-
private createForEachContext;
|
|
69
|
-
/**
|
|
70
|
-
* Generate nested forEach contexts within this forEach's select and unionAll options.
|
|
71
|
-
*/
|
|
72
|
-
private generateNestedForEachContexts;
|
|
73
|
-
/**
|
|
74
|
-
* Generate forEach contexts for nested selects.
|
|
75
|
-
*/
|
|
76
|
-
private generateNestedSelectContexts;
|
|
77
|
-
/**
|
|
78
|
-
* Generate forEach contexts for nested unionAll options.
|
|
79
|
-
*/
|
|
80
|
-
private generateNestedUnionAllContexts;
|
|
81
|
-
/**
|
|
82
|
-
* Build CROSS APPLY clauses in reverse order for forEach processing.
|
|
83
|
-
*/
|
|
84
|
-
buildApplyClauses(forEachContextMap: Map<ViewDefinitionSelect, TranspilerContext>, topLevelForEach: ViewDefinitionSelect[], combination: SelectCombination): string;
|
|
85
|
-
/**
|
|
86
|
-
* Generate CROSS APPLY clauses for a forEach and its nested forEach.
|
|
87
|
-
*/
|
|
88
|
-
private generateForEachClause;
|
|
89
|
-
/**
|
|
90
|
-
* Build the APPLY clause for a forEach using its pre-generated context.
|
|
91
|
-
*/
|
|
92
|
-
private buildApplyClause;
|
|
93
|
-
/**
|
|
94
|
-
* Build a simple APPLY clause for single array paths.
|
|
95
|
-
*/
|
|
96
|
-
private buildSimpleApplyClause;
|
|
97
|
-
/**
|
|
98
|
-
* Build WHERE clauses for APPLY operations.
|
|
99
|
-
*/
|
|
100
|
-
private buildWhereClauses;
|
|
101
|
-
/**
|
|
102
|
-
* Build nested CROSS APPLY clauses for array flattening.
|
|
103
|
-
*/
|
|
104
|
-
private buildNestedForEachClause;
|
|
105
|
-
/**
|
|
106
|
-
* Build WHERE clause conditions for nested array filtering.
|
|
107
|
-
*/
|
|
108
|
-
private buildNestedWhereClauses;
|
|
109
|
-
/**
|
|
110
|
-
* Build APPLY clause with optional WHERE conditions.
|
|
111
|
-
*/
|
|
112
|
-
private buildApplyWithOptionalWhere;
|
|
113
|
-
/**
|
|
114
|
-
* Process nested forEach within this forEach's select.
|
|
115
|
-
*/
|
|
116
|
-
private processNestedSelectClauses;
|
|
117
|
-
/**
|
|
118
|
-
* Process nested forEach within this forEach's unionAll options.
|
|
119
|
-
*/
|
|
120
|
-
private processNestedUnionAllClauses;
|
|
121
|
-
/**
|
|
122
|
-
* Get the selected unionAll option for a forEach in a combination.
|
|
123
|
-
*/
|
|
124
|
-
private getSelectedUnionOption;
|
|
125
|
-
}
|
|
126
|
-
export {};
|
|
127
|
-
//# sourceMappingURL=ForEachProcessor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ForEachProcessor.d.ts","sourceRoot":"","sources":["../../src/queryGenerator/ForEachProcessor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAS7C;;GAEG;AACH,UAAU,uBAAuB;IAC/B,iBAAiB,EAAE,GAAG,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,CAAC;IAChE,eAAe,EAAE,oBAAoB,EAAE,CAAC;CACzC;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;gBAE5B,UAAU,EAAE,UAAU;IAIlC;;OAEG;IACH,qBAAqB,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO;IAoB9D;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO;IAYvD;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;OAEG;IACH,sBAAsB,CACpB,OAAO,EAAE,oBAAoB,EAAE,EAC/B,OAAO,EAAE,iBAAiB,EAC1B,WAAW,CAAC,EAAE,iBAAiB,GAC9B,uBAAuB;IAsB1B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAkB9B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAmB7B;;OAEG;IACH,OAAO,CAA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