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.
Files changed (81) hide show
  1. package/dist/queryGenerator/index.d.ts +0 -4
  2. package/dist/queryGenerator/index.d.ts.map +1 -1
  3. package/dist/queryGenerator/index.js +1 -9
  4. package/dist/queryGenerator/index.js.map +1 -1
  5. package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts +26 -0
  6. package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts.map +1 -0
  7. package/dist/queryGenerator/treeWalker/aliasGenerator.js +31 -0
  8. package/dist/queryGenerator/treeWalker/aliasGenerator.js.map +1 -0
  9. package/dist/queryGenerator/treeWalker/classify.d.ts +19 -0
  10. package/dist/queryGenerator/treeWalker/classify.d.ts.map +1 -0
  11. package/dist/queryGenerator/treeWalker/classify.js +36 -0
  12. package/dist/queryGenerator/treeWalker/classify.js.map +1 -0
  13. package/dist/queryGenerator/treeWalker/compile.d.ts +29 -0
  14. package/dist/queryGenerator/treeWalker/compile.d.ts.map +1 -0
  15. package/dist/queryGenerator/treeWalker/compile.js +98 -0
  16. package/dist/queryGenerator/treeWalker/compile.js.map +1 -0
  17. package/dist/queryGenerator/treeWalker/cteTemplates.d.ts +50 -0
  18. package/dist/queryGenerator/treeWalker/cteTemplates.d.ts.map +1 -0
  19. package/dist/queryGenerator/treeWalker/cteTemplates.js +95 -0
  20. package/dist/queryGenerator/treeWalker/cteTemplates.js.map +1 -0
  21. package/dist/queryGenerator/treeWalker/index.d.ts +6 -0
  22. package/dist/queryGenerator/treeWalker/index.d.ts.map +1 -0
  23. package/dist/queryGenerator/treeWalker/index.js +9 -0
  24. package/dist/queryGenerator/treeWalker/index.js.map +1 -0
  25. package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts +28 -0
  26. package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts.map +1 -0
  27. package/dist/queryGenerator/treeWalker/mergeSiblings.js +54 -0
  28. package/dist/queryGenerator/treeWalker/mergeSiblings.js.map +1 -0
  29. package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts +40 -0
  30. package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts.map +1 -0
  31. package/dist/queryGenerator/treeWalker/operators/columnsOnly.js +56 -0
  32. package/dist/queryGenerator/treeWalker/operators/columnsOnly.js.map +1 -0
  33. package/dist/queryGenerator/treeWalker/operators/forEach.d.ts +45 -0
  34. package/dist/queryGenerator/treeWalker/operators/forEach.d.ts.map +1 -0
  35. package/dist/queryGenerator/treeWalker/operators/forEach.js +144 -0
  36. package/dist/queryGenerator/treeWalker/operators/forEach.js.map +1 -0
  37. package/dist/queryGenerator/treeWalker/operators/group.d.ts +35 -0
  38. package/dist/queryGenerator/treeWalker/operators/group.d.ts.map +1 -0
  39. package/dist/queryGenerator/treeWalker/operators/group.js +56 -0
  40. package/dist/queryGenerator/treeWalker/operators/group.js.map +1 -0
  41. package/dist/queryGenerator/treeWalker/operators/repeat.d.ts +45 -0
  42. package/dist/queryGenerator/treeWalker/operators/repeat.d.ts.map +1 -0
  43. package/dist/queryGenerator/treeWalker/operators/repeat.js +110 -0
  44. package/dist/queryGenerator/treeWalker/operators/repeat.js.map +1 -0
  45. package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts +54 -0
  46. package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts.map +1 -0
  47. package/dist/queryGenerator/treeWalker/operators/unionAll.js +121 -0
  48. package/dist/queryGenerator/treeWalker/operators/unionAll.js.map +1 -0
  49. package/dist/queryGenerator/treeWalker/render.d.ts +34 -0
  50. package/dist/queryGenerator/treeWalker/render.d.ts.map +1 -0
  51. package/dist/queryGenerator/treeWalker/render.js +41 -0
  52. package/dist/queryGenerator/treeWalker/render.js.map +1 -0
  53. package/dist/queryGenerator/treeWalker/types.d.ts +66 -0
  54. package/dist/queryGenerator/treeWalker/types.d.ts.map +1 -0
  55. package/dist/queryGenerator/treeWalker/types.js +14 -0
  56. package/dist/queryGenerator/treeWalker/types.js.map +1 -0
  57. package/dist/queryGenerator/treeWalker/walker.d.ts +36 -0
  58. package/dist/queryGenerator/treeWalker/walker.d.ts.map +1 -0
  59. package/dist/queryGenerator/treeWalker/walker.js +58 -0
  60. package/dist/queryGenerator/treeWalker/walker.js.map +1 -0
  61. package/dist/queryGenerator.d.ts +8 -94
  62. package/dist/queryGenerator.d.ts.map +1 -1
  63. package/dist/queryGenerator.js +16 -268
  64. package/dist/queryGenerator.js.map +1 -1
  65. package/package.json +1 -1
  66. package/dist/queryGenerator/ForEachProcessor.d.ts +0 -127
  67. package/dist/queryGenerator/ForEachProcessor.d.ts.map +0 -1
  68. package/dist/queryGenerator/ForEachProcessor.js +0 -351
  69. package/dist/queryGenerator/ForEachProcessor.js.map +0 -1
  70. package/dist/queryGenerator/RepeatProcessor.d.ts +0 -177
  71. package/dist/queryGenerator/RepeatProcessor.d.ts.map +0 -1
  72. package/dist/queryGenerator/RepeatProcessor.js +0 -336
  73. package/dist/queryGenerator/RepeatProcessor.js.map +0 -1
  74. package/dist/queryGenerator/SelectClauseBuilder.d.ts +0 -108
  75. package/dist/queryGenerator/SelectClauseBuilder.d.ts.map +0 -1
  76. package/dist/queryGenerator/SelectClauseBuilder.js +0 -346
  77. package/dist/queryGenerator/SelectClauseBuilder.js.map +0 -1
  78. package/dist/queryGenerator/SelectCombinationExpander.d.ts +0 -42
  79. package/dist/queryGenerator/SelectCombinationExpander.d.ts.map +0 -1
  80. package/dist/queryGenerator/SelectCombinationExpander.js +0 -95
  81. package/dist/queryGenerator/SelectCombinationExpander.js.map +0 -1
@@ -1,351 +0,0 @@
1
- "use strict";
2
- /**
3
- * Processes forEach operations and generates CROSS APPLY clauses.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ForEachProcessor = void 0;
7
- /**
8
- * Handles all forEach-related processing and CROSS APPLY generation.
9
- */
10
- class ForEachProcessor {
11
- pathParser;
12
- constructor(pathParser) {
13
- this.pathParser = pathParser;
14
- }
15
- /**
16
- * Check if a specific combination has forEach operations.
17
- */
18
- combinationHasForEach(combination) {
19
- for (let i = 0; i < combination.selects.length; i++) {
20
- const select = combination.selects[i];
21
- const unionChoice = combination.unionChoices[i];
22
- if (this.selectHasForEach(select)) {
23
- return true;
24
- }
25
- // If this select has a unionAll choice, also check the chosen branch.
26
- if (unionChoice >= 0 && select.unionAll?.[unionChoice]) {
27
- const chosenBranch = select.unionAll[unionChoice];
28
- if (this.selectHasForEach(chosenBranch)) {
29
- return true;
30
- }
31
- }
32
- }
33
- return false;
34
- }
35
- /**
36
- * Check if a single select has forEach operations (including nested).
37
- */
38
- selectHasForEach(select) {
39
- if (select.forEach || select.forEachOrNull) {
40
- return true;
41
- }
42
- if (select.select && this.hasForEachInSelects(select.select)) {
43
- return true;
44
- }
45
- return !!(select.unionAll && this.unionAllHasForEach(select.unionAll));
46
- }
47
- /**
48
- * Check if any select in the tree has forEach operations.
49
- */
50
- hasForEachInSelects(selects) {
51
- return selects.some((select) => this.selectHasForEach(select));
52
- }
53
- /**
54
- * Check if any unionAll option has forEach operations.
55
- */
56
- unionAllHasForEach(unionAllOptions) {
57
- return unionAllOptions.some((unionOption) => (unionOption.forEach ?? unionOption.forEachOrNull) !== undefined ||
58
- (unionOption.select && this.hasForEachInSelects(unionOption.select)));
59
- }
60
- /**
61
- * Build the forEach context map by generating contexts for all forEach.
62
- */
63
- buildForEachContextMap(selects, context, combination) {
64
- const forEachContextMap = new Map();
65
- const counterState = { value: 0 };
66
- const topLevelForEach = this.collectTopLevelForEach(selects, combination);
67
- for (const select of topLevelForEach) {
68
- this.generateForEachContexts(select, context.resourceAlias + ".json", context, forEachContextMap, counterState);
69
- }
70
- return { forEachContextMap, topLevelForEach };
71
- }
72
- /**
73
- * Collect all forEach that should be treated as top-level.
74
- */
75
- collectTopLevelForEach(selects, combination) {
76
- const topLevelForEach = [];
77
- for (const select of selects) {
78
- this.processSelectForEach(select, topLevelForEach);
79
- // Also process unionAll choices if present and parent doesn't have forEach.
80
- if (combination && !this.isForEachSelect(select)) {
81
- this.processUnionAllChoice(select, combination, topLevelForEach);
82
- }
83
- }
84
- return topLevelForEach;
85
- }
86
- /**
87
- * Process a select for forEach, handling both direct forEach and nested selects.
88
- */
89
- processSelectForEach(select, topLevelForEach) {
90
- if (this.isForEachSelect(select)) {
91
- topLevelForEach.push(select);
92
- }
93
- else if (select.select) {
94
- this.addForEachFromSelectArray(select.select, topLevelForEach);
95
- }
96
- }
97
- /**
98
- * Process a select with a unionAll choice from a combination.
99
- */
100
- processUnionAllChoice(select, combination, topLevelForEach) {
101
- const selectIndex = combination.selects.indexOf(select);
102
- const unionChoice = selectIndex >= 0 ? combination.unionChoices[selectIndex] : -1;
103
- if (unionChoice >= 0 && select.unionAll?.[unionChoice]) {
104
- const chosenBranch = select.unionAll[unionChoice];
105
- if (this.isForEachSelect(chosenBranch)) {
106
- topLevelForEach.push(chosenBranch);
107
- }
108
- else if (chosenBranch.select) {
109
- this.addForEachFromSelectArray(chosenBranch.select, topLevelForEach);
110
- }
111
- }
112
- }
113
- /**
114
- * Add forEach from a select array to the topLevelForEach list.
115
- */
116
- addForEachFromSelectArray(selects, topLevelForEach) {
117
- for (const nestedSelect of selects) {
118
- if (this.isForEachSelect(nestedSelect)) {
119
- topLevelForEach.push(nestedSelect);
120
- }
121
- }
122
- }
123
- /**
124
- * Check if a select is a forEach or forEachOrNull.
125
- */
126
- isForEachSelect(select) {
127
- return !!(select.forEach ?? select.forEachOrNull);
128
- }
129
- /**
130
- * Generate forEach contexts recursively.
131
- */
132
- generateForEachContexts(forEachSelect, sourceExpression, baseContext, forEachContextMap, counterState) {
133
- const applyAlias = `forEach_${counterState.value++}`;
134
- const forEachContext = this.createForEachContext(baseContext, applyAlias, sourceExpression, forEachSelect);
135
- forEachContextMap.set(forEachSelect, forEachContext);
136
- this.generateNestedForEachContexts(forEachSelect, applyAlias, forEachContext, forEachContextMap, counterState);
137
- }
138
- /**
139
- * Create a transpiler context specific to a forEach.
140
- */
141
- createForEachContext(baseContext, applyAlias, sourceExpression, forEachSelect) {
142
- const forEachPath = forEachSelect.forEach ?? forEachSelect.forEachOrNull;
143
- return {
144
- ...baseContext,
145
- iterationContext: `${applyAlias}.value`,
146
- currentForEachAlias: applyAlias,
147
- forEachSource: sourceExpression,
148
- forEachPath: `$.${forEachPath}`,
149
- };
150
- }
151
- /**
152
- * Generate nested forEach contexts within this forEach's select and unionAll options.
153
- */
154
- generateNestedForEachContexts(forEachSelect, applyAlias, baseContext, forEachContextMap, counterState) {
155
- if (forEachSelect.select) {
156
- this.generateNestedSelectContexts(forEachSelect.select, applyAlias, baseContext, forEachContextMap, counterState);
157
- }
158
- if (forEachSelect.unionAll) {
159
- this.generateNestedUnionAllContexts(forEachSelect.unionAll, applyAlias, baseContext, forEachContextMap, counterState);
160
- }
161
- }
162
- /**
163
- * Generate forEach contexts for nested selects.
164
- */
165
- generateNestedSelectContexts(nestedSelects, applyAlias, forEachContext, forEachContextMap, counterState) {
166
- for (const nestedSelect of nestedSelects) {
167
- if (this.isForEachSelect(nestedSelect)) {
168
- this.generateForEachContexts(nestedSelect, `${applyAlias}.value`, forEachContext, forEachContextMap, counterState);
169
- }
170
- }
171
- }
172
- /**
173
- * Generate forEach contexts for nested unionAll options.
174
- */
175
- generateNestedUnionAllContexts(unionAllOptions, applyAlias, forEachContext, forEachContextMap, counterState) {
176
- for (const unionOption of unionAllOptions) {
177
- if (this.isForEachSelect(unionOption)) {
178
- this.generateForEachContexts(unionOption, `${applyAlias}.value`, forEachContext, forEachContextMap, counterState);
179
- }
180
- }
181
- }
182
- /**
183
- * Build CROSS APPLY clauses in reverse order for forEach processing.
184
- */
185
- buildApplyClauses(forEachContextMap, topLevelForEach, combination) {
186
- return [...topLevelForEach]
187
- .reverse()
188
- .map((select) => {
189
- const forEachContext = forEachContextMap.get(select);
190
- if (!forEachContext) {
191
- throw new Error("forEach context not found");
192
- }
193
- return this.generateForEachClause(select, forEachContext, forEachContextMap, combination);
194
- })
195
- .join("");
196
- }
197
- /**
198
- * Generate CROSS APPLY clauses for a forEach and its nested forEach.
199
- */
200
- generateForEachClause(forEachSelect, forEachContext, forEachContextMap, combination) {
201
- const clause = this.buildApplyClause(forEachSelect, forEachContext);
202
- const nestedSelectClauses = this.processNestedSelectClauses(forEachSelect, forEachContextMap, combination);
203
- const nestedUnionClauses = this.processNestedUnionAllClauses(forEachSelect, forEachContextMap, combination);
204
- return clause + nestedSelectClauses + nestedUnionClauses;
205
- }
206
- /**
207
- * Build the APPLY clause for a forEach using its pre-generated context.
208
- */
209
- buildApplyClause(forEachSelect, forEachContext) {
210
- const rawPath = forEachSelect.forEach ?? forEachSelect.forEachOrNull;
211
- const isOrNull = !!forEachSelect.forEachOrNull;
212
- const applyType = isOrNull ? "OUTER APPLY" : "CROSS APPLY";
213
- const applyAlias = forEachContext.currentForEachAlias ?? "";
214
- const sourceExpression = forEachContext.forEachSource ?? "";
215
- const { path: pathWithoutWhere, whereCondition, useFirst, } = this.pathParser.parseFhirPathWhere(rawPath ?? "", forEachContext);
216
- const { path: forEachPath, arrayIndex } = this.pathParser.parseArrayIndexing(pathWithoutWhere);
217
- const arrayPaths = this.pathParser.detectArrayFlatteningPaths(forEachPath);
218
- if (arrayPaths.length > 1) {
219
- return this.buildNestedForEachClause(arrayPaths, sourceExpression, applyAlias, applyType, arrayIndex, whereCondition);
220
- }
221
- return this.buildSimpleApplyClause(applyType, sourceExpression, forEachPath, applyAlias, arrayIndex, whereCondition, useFirst);
222
- }
223
- /**
224
- * Build a simple APPLY clause for single array paths.
225
- */
226
- buildSimpleApplyClause(applyType, sourceExpression, forEachPath, applyAlias, arrayIndex, whereCondition, useFirst = false) {
227
- const whereClauses = this.buildWhereClauses(arrayIndex, whereCondition);
228
- if (whereClauses.length > 0 || useFirst) {
229
- // Build SELECT with WHERE clause and/or TOP 1 for .first()
230
- const topClause = useFirst ? "TOP 1 " : "";
231
- const orderBy = useFirst ? " ORDER BY [key]" : "";
232
- const whereClause = whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
233
- return `\n${applyType} (
234
- SELECT ${topClause}* FROM OPENJSON(${sourceExpression}, '$.${forEachPath}')
235
- ${whereClause}${orderBy}
236
- ) AS ${applyAlias}`;
237
- }
238
- return `\n${applyType} OPENJSON(${sourceExpression}, '$.${forEachPath}') AS ${applyAlias}`;
239
- }
240
- /**
241
- * Build WHERE clauses for APPLY operations.
242
- */
243
- buildWhereClauses(arrayIndex, whereCondition) {
244
- const whereClauses = [];
245
- if (arrayIndex !== null) {
246
- whereClauses.push(`[key] = '${arrayIndex}'`);
247
- }
248
- if (whereCondition !== null) {
249
- whereClauses.push(whereCondition);
250
- }
251
- return whereClauses;
252
- }
253
- /**
254
- * Build nested CROSS APPLY clauses for array flattening.
255
- */
256
- buildNestedForEachClause(arrayPaths, sourceExpression, finalAlias, applyType, arrayIndex, whereCondition) {
257
- let clauses = "";
258
- let currentSource = sourceExpression;
259
- for (let i = 0; i < arrayPaths.length; i++) {
260
- const isLast = i === arrayPaths.length - 1;
261
- const alias = isLast ? finalAlias : `${finalAlias}_nest${i}`;
262
- const pathSegment = this.pathParser.extractPathSegment(arrayPaths, i);
263
- const { cleanSegment, segmentIndex } = this.pathParser.parseSegmentIndexing(pathSegment);
264
- const jsonPath = `$.${cleanSegment}`;
265
- const whereClauses = this.buildNestedWhereClauses(isLast, segmentIndex, arrayIndex, whereCondition);
266
- clauses += this.buildApplyWithOptionalWhere(applyType, currentSource, jsonPath, alias, whereClauses);
267
- currentSource = `${alias}.value`;
268
- }
269
- return clauses;
270
- }
271
- /**
272
- * Build WHERE clause conditions for nested array filtering.
273
- */
274
- buildNestedWhereClauses(isLast, segmentIndex, arrayIndex, whereCondition) {
275
- const whereClauses = [];
276
- if (segmentIndex !== null) {
277
- whereClauses.push(`[key] = '${segmentIndex}'`);
278
- }
279
- else if (isLast && arrayIndex !== null && arrayIndex !== undefined) {
280
- whereClauses.push(`[key] = '${arrayIndex}'`);
281
- }
282
- if (isLast && whereCondition !== null && whereCondition !== undefined) {
283
- whereClauses.push(whereCondition);
284
- }
285
- return whereClauses;
286
- }
287
- /**
288
- * Build APPLY clause with optional WHERE conditions.
289
- */
290
- buildApplyWithOptionalWhere(applyType, source, jsonPath, alias, whereClauses) {
291
- if (whereClauses.length > 0) {
292
- return `\n${applyType} (
293
- SELECT * FROM OPENJSON(${source}, '${jsonPath}')
294
- WHERE ${whereClauses.join(" AND ")}
295
- ) AS ${alias}`;
296
- }
297
- return `\n${applyType} OPENJSON(${source}, '${jsonPath}') AS ${alias}`;
298
- }
299
- /**
300
- * Process nested forEach within this forEach's select.
301
- */
302
- processNestedSelectClauses(forEachSelect, forEachContextMap, combination) {
303
- if (!forEachSelect.select) {
304
- return "";
305
- }
306
- return forEachSelect.select
307
- .filter((nestedSelect) => this.isForEachSelect(nestedSelect))
308
- .map((nestedSelect) => {
309
- const nestedContext = forEachContextMap.get(nestedSelect);
310
- if (!nestedContext) {
311
- throw new Error("Nested forEach context not found");
312
- }
313
- return this.generateForEachClause(nestedSelect, nestedContext, forEachContextMap, combination);
314
- })
315
- .join("");
316
- }
317
- /**
318
- * Process nested forEach within this forEach's unionAll options.
319
- */
320
- processNestedUnionAllClauses(forEachSelect, forEachContextMap, combination) {
321
- if (!forEachSelect.unionAll || !combination) {
322
- return "";
323
- }
324
- const selectedUnionOption = this.getSelectedUnionOption(forEachSelect, combination);
325
- if (!selectedUnionOption || !this.isForEachSelect(selectedUnionOption)) {
326
- return "";
327
- }
328
- const nestedContext = forEachContextMap.get(selectedUnionOption);
329
- if (!nestedContext) {
330
- return "";
331
- }
332
- return this.generateForEachClause(selectedUnionOption, nestedContext, forEachContextMap, combination);
333
- }
334
- /**
335
- * Get the selected unionAll option for a forEach in a combination.
336
- */
337
- getSelectedUnionOption(forEachSelect, combination) {
338
- if (!forEachSelect.unionAll) {
339
- return null;
340
- }
341
- const selectIndex = combination.selects.indexOf(forEachSelect);
342
- const selectedUnionIndex = selectIndex >= 0 ? combination.unionChoices[selectIndex] : -1;
343
- if (selectedUnionIndex < 0 ||
344
- selectedUnionIndex >= forEachSelect.unionAll.length) {
345
- return null;
346
- }
347
- return forEachSelect.unionAll[selectedUnionIndex];
348
- }
349
- }
350
- exports.ForEachProcessor = ForEachProcessor;
351
- //# sourceMappingURL=ForEachProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ForEachProcessor.js","sourceRoot":"","sources":["../../src/queryGenerator/ForEachProcessor.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAsBH;;GAEG;AACH,MAAa,gBAAgB;IACV,UAAU,CAAa;IAExC,YAAY,UAAsB;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,qBAAqB,CAAC,WAA8B;QAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpD,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACtC,MAAM,WAAW,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAEhD,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,sEAAsE;YACtE,IAAI,WAAW,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;gBACvD,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAClD,IAAI,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,EAAE,CAAC;oBACxC,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,MAA4B;QAC3C,IAAI,M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,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACvE,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,aAAa,GAAG,iBAAiB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QACjE,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,IAAI,CAAC,qBAAqB,CAC/B,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,WAAW,CACZ,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,sBAAsB,CAC5B,aAAmC,EACnC,WAA8B;QAE9B,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC/D,MAAM,kBAAkB,GACtB,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAEhE,IACE,kBAAkB,GAAG,CAAC;YACtB,kBAAkB,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,EACnD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,aAAa,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IACpD,CAAC;CACF;AAjmBD,4CAimBC"}
@@ -1,177 +0,0 @@
1
- /**
2
- * Processes repeat operations and generates recursive CTEs.
3
- *
4
- * The repeat directive recursively traverses a tree structure by following
5
- * one or more FHIRPath expressions at each level. This is implemented using
6
- * SQL Server recursive Common Table Expressions (CTEs).
7
- *
8
- * @author John Grimes
9
- */
10
- import type { TranspilerContext } from "../fhirpath/transpiler.js";
11
- import { ViewDefinitionSelect } from "../types.js";
12
- import { SelectCombination } from "./SelectCombinationExpander.js";
13
- /**
14
- * Counter state for generating unique repeat CTE aliases.
15
- */
16
- interface CounterState {
17
- value: number;
18
- }
19
- /**
20
- * Context specific to a repeat operation.
21
- */
22
- export interface RepeatContext {
23
- /** Unique alias for the CTE (e.g., "repeat_0"). */
24
- cteAlias: string;
25
- /** FHIRPath expressions to follow recursively. */
26
- paths: string[];
27
- /** JSON source expression for the anchor member. */
28
- sourceExpression: string;
29
- /** The transpiler context for columns within this repeat. */
30
- transpilerContext: TranspilerContext;
31
- }
32
- /**
33
- * Result of building repeat context map.
34
- */
35
- export interface RepeatContextMapResult {
36
- repeatContextMap: Map<ViewDefinitionSelect, RepeatContext>;
37
- topLevelRepeat: ViewDefinitionSelect[];
38
- }
39
- /**
40
- * Handles all repeat-related processing and recursive CTE generation.
41
- *
42
- * The repeat directive works similarly to forEach but traverses tree structures
43
- * of arbitrary depth. For example, `repeat: ["item"]` follows the `item` array
44
- * at each level until no more items exist.
45
- *
46
- * Multiple paths can be specified (e.g., `["item", "answer.item"]`) to follow
47
- * different traversal patterns at each level, with results unioned together.
48
- */
49
- export declare class RepeatProcessor {
50
- /**
51
- * Check if a specific combination has repeat operations.
52
- *
53
- * @param combination - The select combination to check.
54
- * @returns True if any select in the combination has repeat.
55
- */
56
- combinationHasRepeat(combination: SelectCombination): boolean;
57
- /**
58
- * Check if a single select has repeat operations (including nested).
59
- *
60
- * @param select - The select element to check.
61
- * @returns True if the select or any nested select has repeat.
62
- */
63
- selectHasRepeat(select: ViewDefinitionSelect): boolean;
64
- /**
65
- * Check if any select in the array has repeat operations.
66
- */
67
- private hasRepeatInSelects;
68
- /**
69
- * Check if any unionAll option has repeat operations.
70
- */
71
- private unionAllHasRepeat;
72
- /**
73
- * Check if a select is a repeat select.
74
- */
75
- isRepeatSelect(select: ViewDefinitionSelect): boolean;
76
- /**
77
- * Build the repeat context map by generating contexts for all repeat operations.
78
- *
79
- * @param selects - The top-level select elements.
80
- * @param context - The base transpiler context.
81
- * @param combination - Optional combination for unionAll handling.
82
- * @param externalCounter - Optional external counter for shared CTE aliases across combinations.
83
- * @returns Map of repeat selects to their contexts and list of top-level repeats.
84
- */
85
- buildRepeatContextMap(selects: ViewDefinitionSelect[], context: TranspilerContext, combination?: SelectCombination, externalCounter?: CounterState): RepeatContextMapResult;
86
- /**
87
- * Collect all repeat selects that should be treated as top-level.
88
- */
89
- private collectTopLevelRepeat;
90
- /**
91
- * Process a select for repeat, handling both direct repeat and nested selects.
92
- */
93
- private processSelectRepeat;
94
- /**
95
- * Process a select with a unionAll choice from a combination.
96
- */
97
- private processUnionAllChoice;
98
- /**
99
- * Add repeat selects from a select array to the topLevelRepeat list.
100
- */
101
- private addRepeatFromSelectArray;
102
- /**
103
- * Generate repeat context for a single repeat select.
104
- */
105
- private generateRepeatContext;
106
- /**
107
- * Generate CTE definitions as an array for repeat operations.
108
- *
109
- * This method returns the CTE definitions without the WITH keyword,
110
- * allowing them to be consolidated when multiple unionAll branches
111
- * each have their own repeat CTEs.
112
- *
113
- * @param repeatContextMap - Map of repeat selects to their contexts.
114
- * @param topLevelRepeat - List of top-level repeat selects.
115
- * @param resourceAlias - The alias for the resource table (e.g., "r").
116
- * @param resourceType - The FHIR resource type.
117
- * @param testId - Optional test ID for filtering.
118
- * @param tableName - The fully qualified table name (e.g., "[dbo].[fhir_resources]").
119
- * @returns Array of CTE definition strings (without WITH keyword).
120
- */
121
- buildRepeatCteDefinitions(repeatContextMap: Map<ViewDefinitionSelect, RepeatContext>, topLevelRepeat: ViewDefinitionSelect[], resourceAlias: string, resourceType: string, testId?: string, tableName?: string): string[];
122
- /**
123
- * Generate a single recursive CTE definition.
124
- *
125
- * The CTE has the following structure:
126
- * - Anchor member: Selects initial items using the FIRST path from the root.
127
- * Only the first path is used for the anchor because subsequent paths
128
- * (like `answer.item`) represent traversal patterns that should only be
129
- * followed during recursion, not at the root level.
130
- * - Recursive member: For each path in repeat, follows that path from the
131
- * current level and unions all results.
132
- *
133
- * The CTE columns are:
134
- * - resource_id: Links back to the source resource.
135
- * - item_json: The JSON content of the current item (used for column extraction).
136
- * - depth: Recursion depth (used to prevent infinite loops).
137
- */
138
- private generateSingleCte;
139
- /**
140
- * Build a recursive member for a single path.
141
- *
142
- * Multi-segment paths like "answer.item" require nested CROSS APPLY clauses
143
- * to traverse through each array. For example, "answer.item" means:
144
- * 1. Iterate over the `answer` array
145
- * 2. For each answer, iterate over the `item` array within it
146
- *
147
- * @param path - The FHIRPath expression (e.g., "item" or "answer.item").
148
- * @param cteAlias - The alias of the recursive CTE.
149
- * @param index - Index of this path for alias generation.
150
- * @returns SQL fragment for the recursive member.
151
- */
152
- private buildRecursiveMember;
153
- /**
154
- * Build a JSON path from a FHIRPath expression.
155
- * Handles simple paths and dot-separated paths like "answer.item".
156
- */
157
- private buildJsonPath;
158
- /**
159
- * Build the test ID condition for filtering test data.
160
- *
161
- * @param resourceAlias - The alias for the resource table.
162
- * @param testId - Optional test ID for filtering.
163
- * @returns SQL condition string or empty string if no testId.
164
- */
165
- private buildTestIdCondition;
166
- /**
167
- * Build CROSS APPLY clause to join CTE results to the main query.
168
- *
169
- * @param repeatContextMap - Map of repeat selects to their contexts.
170
- * @param topLevelRepeat - List of top-level repeat selects.
171
- * @param resourceAlias - The alias for the resource table.
172
- * @returns The CROSS APPLY clause(s) for joining CTE results.
173
- */
174
- buildRepeatApplyClauses(repeatContextMap: Map<ViewDefinitionSelect, RepeatContext>, topLevelRepeat: ViewDefinitionSelect[], resourceAlias: string): string;
175
- }
176
- export {};
177
- //# sourceMappingURL=RepeatProcessor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RepeatProcessor.d.ts","sourceRoot":"","sources":["../../src/queryGenerator/RepeatProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;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