sof-mssql 2.1.0 → 2.3.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 (102) hide show
  1. package/dist/fhirpath/visitor.d.ts +78 -0
  2. package/dist/fhirpath/visitor.d.ts.map +1 -1
  3. package/dist/fhirpath/visitor.js +208 -11
  4. package/dist/fhirpath/visitor.js.map +1 -1
  5. package/dist/parser.d.ts +1 -1
  6. package/dist/parser.js +1 -1
  7. package/dist/queryGenerator/index.d.ts +0 -4
  8. package/dist/queryGenerator/index.d.ts.map +1 -1
  9. package/dist/queryGenerator/index.js +1 -9
  10. package/dist/queryGenerator/index.js.map +1 -1
  11. package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts +26 -0
  12. package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts.map +1 -0
  13. package/dist/queryGenerator/treeWalker/aliasGenerator.js +31 -0
  14. package/dist/queryGenerator/treeWalker/aliasGenerator.js.map +1 -0
  15. package/dist/queryGenerator/treeWalker/classify.d.ts +19 -0
  16. package/dist/queryGenerator/treeWalker/classify.d.ts.map +1 -0
  17. package/dist/queryGenerator/treeWalker/classify.js +36 -0
  18. package/dist/queryGenerator/treeWalker/classify.js.map +1 -0
  19. package/dist/queryGenerator/treeWalker/compile.d.ts +29 -0
  20. package/dist/queryGenerator/treeWalker/compile.d.ts.map +1 -0
  21. package/dist/queryGenerator/treeWalker/compile.js +97 -0
  22. package/dist/queryGenerator/treeWalker/compile.js.map +1 -0
  23. package/dist/queryGenerator/treeWalker/cteTemplates.d.ts +58 -0
  24. package/dist/queryGenerator/treeWalker/cteTemplates.d.ts.map +1 -0
  25. package/dist/queryGenerator/treeWalker/cteTemplates.js +131 -0
  26. package/dist/queryGenerator/treeWalker/cteTemplates.js.map +1 -0
  27. package/dist/queryGenerator/treeWalker/index.d.ts +6 -0
  28. package/dist/queryGenerator/treeWalker/index.d.ts.map +1 -0
  29. package/dist/queryGenerator/treeWalker/index.js +9 -0
  30. package/dist/queryGenerator/treeWalker/index.js.map +1 -0
  31. package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts +28 -0
  32. package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts.map +1 -0
  33. package/dist/queryGenerator/treeWalker/mergeSiblings.js +54 -0
  34. package/dist/queryGenerator/treeWalker/mergeSiblings.js.map +1 -0
  35. package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts +40 -0
  36. package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts.map +1 -0
  37. package/dist/queryGenerator/treeWalker/operators/columnsOnly.js +56 -0
  38. package/dist/queryGenerator/treeWalker/operators/columnsOnly.js.map +1 -0
  39. package/dist/queryGenerator/treeWalker/operators/forEach.d.ts +47 -0
  40. package/dist/queryGenerator/treeWalker/operators/forEach.d.ts.map +1 -0
  41. package/dist/queryGenerator/treeWalker/operators/forEach.js +150 -0
  42. package/dist/queryGenerator/treeWalker/operators/forEach.js.map +1 -0
  43. package/dist/queryGenerator/treeWalker/operators/group.d.ts +35 -0
  44. package/dist/queryGenerator/treeWalker/operators/group.d.ts.map +1 -0
  45. package/dist/queryGenerator/treeWalker/operators/group.js +56 -0
  46. package/dist/queryGenerator/treeWalker/operators/group.js.map +1 -0
  47. package/dist/queryGenerator/treeWalker/operators/repeat.d.ts +47 -0
  48. package/dist/queryGenerator/treeWalker/operators/repeat.d.ts.map +1 -0
  49. package/dist/queryGenerator/treeWalker/operators/repeat.js +122 -0
  50. package/dist/queryGenerator/treeWalker/operators/repeat.js.map +1 -0
  51. package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts +54 -0
  52. package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts.map +1 -0
  53. package/dist/queryGenerator/treeWalker/operators/unionAll.js +121 -0
  54. package/dist/queryGenerator/treeWalker/operators/unionAll.js.map +1 -0
  55. package/dist/queryGenerator/treeWalker/render.d.ts +34 -0
  56. package/dist/queryGenerator/treeWalker/render.d.ts.map +1 -0
  57. package/dist/queryGenerator/treeWalker/render.js +41 -0
  58. package/dist/queryGenerator/treeWalker/render.js.map +1 -0
  59. package/dist/queryGenerator/treeWalker/types.d.ts +64 -0
  60. package/dist/queryGenerator/treeWalker/types.d.ts.map +1 -0
  61. package/dist/queryGenerator/treeWalker/types.js +14 -0
  62. package/dist/queryGenerator/treeWalker/types.js.map +1 -0
  63. package/dist/queryGenerator/treeWalker/walker.d.ts +36 -0
  64. package/dist/queryGenerator/treeWalker/walker.d.ts.map +1 -0
  65. package/dist/queryGenerator/treeWalker/walker.js +58 -0
  66. package/dist/queryGenerator/treeWalker/walker.js.map +1 -0
  67. package/dist/queryGenerator.d.ts +8 -94
  68. package/dist/queryGenerator.d.ts.map +1 -1
  69. package/dist/queryGenerator.js +16 -268
  70. package/dist/queryGenerator.js.map +1 -1
  71. package/dist/tests/utils/database.d.ts +2 -0
  72. package/dist/tests/utils/database.d.ts.map +1 -1
  73. package/dist/tests/utils/database.js +10 -1
  74. package/dist/tests/utils/database.js.map +1 -1
  75. package/dist/tests/utils/generator.d.ts +2 -0
  76. package/dist/tests/utils/generator.d.ts.map +1 -1
  77. package/dist/tests/utils/generator.js +24 -0
  78. package/dist/tests/utils/generator.js.map +1 -1
  79. package/dist/tests/utils/reporter.d.ts +1 -1
  80. package/dist/tests/utils/reporter.d.ts.map +1 -1
  81. package/dist/tests/utils/reporter.js +5 -4
  82. package/dist/tests/utils/reporter.js.map +1 -1
  83. package/dist/tests/utils/types.d.ts +1 -1
  84. package/dist/tests/utils/types.js +1 -1
  85. package/dist/types.d.ts +1 -1
  86. package/package.json +2 -1
  87. package/dist/queryGenerator/ForEachProcessor.d.ts +0 -127
  88. package/dist/queryGenerator/ForEachProcessor.d.ts.map +0 -1
  89. package/dist/queryGenerator/ForEachProcessor.js +0 -351
  90. package/dist/queryGenerator/ForEachProcessor.js.map +0 -1
  91. package/dist/queryGenerator/RepeatProcessor.d.ts +0 -177
  92. package/dist/queryGenerator/RepeatProcessor.d.ts.map +0 -1
  93. package/dist/queryGenerator/RepeatProcessor.js +0 -336
  94. package/dist/queryGenerator/RepeatProcessor.js.map +0 -1
  95. package/dist/queryGenerator/SelectClauseBuilder.d.ts +0 -108
  96. package/dist/queryGenerator/SelectClauseBuilder.d.ts.map +0 -1
  97. package/dist/queryGenerator/SelectClauseBuilder.js +0 -346
  98. package/dist/queryGenerator/SelectClauseBuilder.js.map +0 -1
  99. package/dist/queryGenerator/SelectCombinationExpander.d.ts +0 -42
  100. package/dist/queryGenerator/SelectCombinationExpander.d.ts.map +0 -1
  101. package/dist/queryGenerator/SelectCombinationExpander.js +0 -95
  102. package/dist/queryGenerator/SelectCombinationExpander.js.map +0 -1
@@ -3,17 +3,9 @@
3
3
  * Query generator components for building T-SQL from ViewDefinitions.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ColumnExpressionGenerator = exports.WhereClauseBuilder = exports.SelectClauseBuilder = exports.RepeatProcessor = exports.ForEachProcessor = exports.SelectCombinationExpander = exports.PathParser = void 0;
6
+ exports.ColumnExpressionGenerator = exports.WhereClauseBuilder = exports.PathParser = void 0;
7
7
  var PathParser_js_1 = require("./PathParser.js");
8
8
  Object.defineProperty(exports, "PathParser", { enumerable: true, get: function () { return PathParser_js_1.PathParser; } });
9
- var SelectCombinationExpander_js_1 = require("./SelectCombinationExpander.js");
10
- Object.defineProperty(exports, "SelectCombinationExpander", { enumerable: true, get: function () { return SelectCombinationExpander_js_1.SelectCombinationExpander; } });
11
- var ForEachProcessor_js_1 = require("./ForEachProcessor.js");
12
- Object.defineProperty(exports, "ForEachProcessor", { enumerable: true, get: function () { return ForEachProcessor_js_1.ForEachProcessor; } });
13
- var RepeatProcessor_js_1 = require("./RepeatProcessor.js");
14
- Object.defineProperty(exports, "RepeatProcessor", { enumerable: true, get: function () { return RepeatProcessor_js_1.RepeatProcessor; } });
15
- var SelectClauseBuilder_js_1 = require("./SelectClauseBuilder.js");
16
- Object.defineProperty(exports, "SelectClauseBuilder", { enumerable: true, get: function () { return SelectClauseBuilder_js_1.SelectClauseBuilder; } });
17
9
  var WhereClauseBuilder_js_1 = require("./WhereClauseBuilder.js");
18
10
  Object.defineProperty(exports, "WhereClauseBuilder", { enumerable: true, get: function () { return WhereClauseBuilder_js_1.WhereClauseBuilder; } });
19
11
  var ColumnExpressionGenerator_js_1 = require("./ColumnExpressionGenerator.js");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queryGenerator/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAA6C;AAApC,2GAAA,UAAU,OAAA;AACnB,+EAGwC;AADtC,yIAAA,yBAAyB,OAAA;AAE3B,6DAAyD;AAAhD,uHAAA,gBAAgB,OAAA;AACzB,2DAAsE;AAA7D,qHAAA,eAAe,OAAA;AACxB,mEAA+D;AAAtD,6HAAA,mBAAmB,OAAA;AAC5B,iEAA6D;AAApD,2HAAA,kBAAkB,OAAA;AAC3B,+EAA2E;AAAlE,yIAAA,yBAAyB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queryGenerator/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAA6C;AAApC,2GAAA,UAAU,OAAA;AACnB,iEAA6D;AAApD,2HAAA,kBAAkB,OAAA;AAC3B,+EAA2E;AAAlE,yIAAA,yBAAyB,OAAA"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Sole producer of all SQL aliases generated by the tree walker.
3
+ *
4
+ * Routing every alias through here guarantees uniqueness across the whole
5
+ * compile (the counter lives on Context.cteCounter and is shared by every
6
+ * recursive walk call).
7
+ */
8
+ import type { Context } from "./types.js";
9
+ /**
10
+ * Generates a globally unique SQL alias for the current compilation.
11
+ *
12
+ * Increments the shared `ctx.cteCounter` (a mutable reference threaded
13
+ * through every recursive walk call) and returns `"<prefix>_<n>"`. Because
14
+ * the counter is shared, aliases produced across different branches and depths
15
+ * of the tree are guaranteed to be distinct within a single
16
+ * `compileViewDefinition` call.
17
+ *
18
+ * @param ctx - The current walker context; its `cteCounter.value` is
19
+ * incremented as a side effect.
20
+ * @param prefix - A human-readable prefix that identifies the operator
21
+ * creating the alias (e.g. `"forEach"`, `"repeat"`, `"ua"`).
22
+ * @returns A string of the form `"<prefix>_<n>"` that is unique within the
23
+ * current compilation.
24
+ */
25
+ export declare function freshAlias(ctx: Context, prefix: string): string;
26
+ //# sourceMappingURL=aliasGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aliasGenerator.d.ts","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/aliasGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG/D"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Sole producer of all SQL aliases generated by the tree walker.
4
+ *
5
+ * Routing every alias through here guarantees uniqueness across the whole
6
+ * compile (the counter lives on Context.cteCounter and is shared by every
7
+ * recursive walk call).
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.freshAlias = freshAlias;
11
+ /**
12
+ * Generates a globally unique SQL alias for the current compilation.
13
+ *
14
+ * Increments the shared `ctx.cteCounter` (a mutable reference threaded
15
+ * through every recursive walk call) and returns `"<prefix>_<n>"`. Because
16
+ * the counter is shared, aliases produced across different branches and depths
17
+ * of the tree are guaranteed to be distinct within a single
18
+ * `compileViewDefinition` call.
19
+ *
20
+ * @param ctx - The current walker context; its `cteCounter.value` is
21
+ * incremented as a side effect.
22
+ * @param prefix - A human-readable prefix that identifies the operator
23
+ * creating the alias (e.g. `"forEach"`, `"repeat"`, `"ua"`).
24
+ * @returns A string of the form `"<prefix>_<n>"` that is unique within the
25
+ * current compilation.
26
+ */
27
+ function freshAlias(ctx, prefix) {
28
+ const id = ctx.cteCounter.value++;
29
+ return `${prefix}_${id}`;
30
+ }
31
+ //# sourceMappingURL=aliasGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aliasGenerator.js","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/aliasGenerator.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAoBH,gCAGC;AAnBD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,UAAU,CAAC,GAAY,EAAE,MAAc;IACrD,MAAM,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAClC,OAAO,GAAG,MAAM,IAAI,EAAE,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Classifies a ViewDefinition select node into one of the walker's NodeKinds.
3
+ */
4
+ import type { ViewDefinitionSelect } from "../../types.js";
5
+ import type { NodeKind } from "./types.js";
6
+ /**
7
+ * Classifies a ViewDefinition select node into one of the walker's NodeKinds.
8
+ *
9
+ * Operators are tested outer-to-inner: `forEachOrNull` first, then `forEach`,
10
+ * `repeat`, `unionAll`, `select` (Group), and finally `ColumnsOnly` as the
11
+ * base case. A node that carries multiple operator fields is classified as the
12
+ * outermost one; inner operators surface when the walker descends.
13
+ *
14
+ * @param node - The select node to classify.
15
+ * @returns The `NodeKind` string discriminant that determines which operator
16
+ * walker handles this node.
17
+ */
18
+ export declare function classifyNode(node: ViewDefinitionSelect): NodeKind;
19
+ //# sourceMappingURL=classify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/classify.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,oBAAoB,GAAG,QAAQ,CAWjE"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * Classifies a ViewDefinition select node into one of the walker's NodeKinds.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.classifyNode = classifyNode;
7
+ /**
8
+ * Classifies a ViewDefinition select node into one of the walker's NodeKinds.
9
+ *
10
+ * Operators are tested outer-to-inner: `forEachOrNull` first, then `forEach`,
11
+ * `repeat`, `unionAll`, `select` (Group), and finally `ColumnsOnly` as the
12
+ * base case. A node that carries multiple operator fields is classified as the
13
+ * outermost one; inner operators surface when the walker descends.
14
+ *
15
+ * @param node - The select node to classify.
16
+ * @returns The `NodeKind` string discriminant that determines which operator
17
+ * walker handles this node.
18
+ */
19
+ function classifyNode(node) {
20
+ // Operators are ordered outer-to-inner. A node with multiple operators
21
+ // (e.g. `{forEach, unionAll}`) is processed as the outer one; the inner
22
+ // operator surfaces when the walker descends into the node's
23
+ // `{column, select, unionAll}` sub-node.
24
+ if (node.forEachOrNull !== undefined)
25
+ return "ForEachOrNull";
26
+ if (node.forEach !== undefined)
27
+ return "ForEach";
28
+ if (node.repeat && node.repeat.length > 0)
29
+ return "Repeat";
30
+ if (node.unionAll && node.unionAll.length > 0)
31
+ return "UnionAll";
32
+ if (node.select && node.select.length > 0)
33
+ return "Group";
34
+ return "ColumnsOnly";
35
+ }
36
+ //# sourceMappingURL=classify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classify.js","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/classify.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAiBH,oCAWC;AAvBD;;;;;;;;;;;GAWG;AACH,SAAgB,YAAY,CAAC,IAA0B;IACrD,uEAAuE;IACvE,wEAAwE;IACxE,6DAA6D;IAC7D,yCAAyC;IACzC,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC;IAC7D,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACjD,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC3D,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,UAAU,CAAC;IACjE,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IAC1D,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Public entry point for the tree-walker query generator.
3
+ *
4
+ * Wraps viewDef.select as a synthetic Group node, walks it, and renders
5
+ * the resulting Fragment as a single T-SQL statement.
6
+ */
7
+ import { TranspilerContext } from "../../fhirpath/transpiler.js";
8
+ import type { TranspilationResult, ViewDefinition } from "../../types.js";
9
+ export interface CompileOptions {
10
+ tableName: string;
11
+ schemaName: string;
12
+ testId?: string;
13
+ transpilerCtx: TranspilerContext;
14
+ }
15
+ /**
16
+ * Compiles a ViewDefinition into a T-SQL query string and column metadata.
17
+ *
18
+ * Wraps `viewDef.select` as a synthetic root Group node, walks the entire
19
+ * select tree to produce a Fragment, then renders that Fragment into a
20
+ * complete T-SQL statement (WITH … SELECT … FROM … WHERE).
21
+ *
22
+ * @param viewDef - The parsed ViewDefinition whose `select` tree is compiled.
23
+ * @param options - Compilation options including table/schema names, an
24
+ * optional test-isolation ID, and the FHIRPath transpiler context.
25
+ * @returns A `TranspilationResult` containing the generated SQL string and
26
+ * an ordered array of column metadata matching the view's output shape.
27
+ */
28
+ export declare function compileViewDefinition(viewDef: ViewDefinition, options: CompileOptions): TranspilationResult;
29
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/compile.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAc,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EAEV,mBAAmB,EACnB,cAAc,EAEf,MAAM,gBAAgB,CAAC;AAYxB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,iBAAiB,CAAC;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,cAAc,GACtB,mBAAmB,CAuBrB"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /**
3
+ * Public entry point for the tree-walker query generator.
4
+ *
5
+ * Wraps viewDef.select as a synthetic Group node, walks it, and renders
6
+ * the resulting Fragment as a single T-SQL statement.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.compileViewDefinition = compileViewDefinition;
10
+ const transpiler_js_1 = require("../../fhirpath/transpiler.js");
11
+ const ColumnExpressionGenerator_js_1 = require("../ColumnExpressionGenerator.js");
12
+ const PathParser_js_1 = require("../PathParser.js");
13
+ const WhereClauseBuilder_js_1 = require("../WhereClauseBuilder.js");
14
+ const render_js_1 = require("./render.js");
15
+ const types_js_1 = require("./types.js");
16
+ const walker_js_1 = require("./walker.js");
17
+ const columnGenerator = new ColumnExpressionGenerator_js_1.ColumnExpressionGenerator();
18
+ const pathParser = new PathParser_js_1.PathParser();
19
+ const whereClauseBuilder = new WhereClauseBuilder_js_1.WhereClauseBuilder();
20
+ /**
21
+ * Compiles a ViewDefinition into a T-SQL query string and column metadata.
22
+ *
23
+ * Wraps `viewDef.select` as a synthetic root Group node, walks the entire
24
+ * select tree to produce a Fragment, then renders that Fragment into a
25
+ * complete T-SQL statement (WITH … SELECT … FROM … WHERE).
26
+ *
27
+ * @param viewDef - The parsed ViewDefinition whose `select` tree is compiled.
28
+ * @param options - Compilation options including table/schema names, an
29
+ * optional test-isolation ID, and the FHIRPath transpiler context.
30
+ * @returns A `TranspilationResult` containing the generated SQL string and
31
+ * an ordered array of column metadata matching the view's output shape.
32
+ */
33
+ function compileViewDefinition(viewDef, options) {
34
+ const resourceAlias = options.transpilerCtx.resourceAlias;
35
+ const ctx = buildRootContext(resourceAlias, options.transpilerCtx);
36
+ const rootNode = { select: viewDef.select };
37
+ const walk = (0, walker_js_1.makeWalker)({
38
+ columnGenerator,
39
+ pathParser,
40
+ schemaName: options.schemaName,
41
+ tableName: options.tableName,
42
+ });
43
+ const fragment = walk(rootNode, ctx);
44
+ const sql = (0, render_js_1.renderRoot)(fragment, viewDef, {
45
+ resourceAlias,
46
+ schemaName: options.schemaName,
47
+ tableName: options.tableName,
48
+ testId: options.testId,
49
+ whereClauseBuilder,
50
+ transpilerCtx: options.transpilerCtx,
51
+ });
52
+ return { sql, columns: collectColumnMetadata(viewDef.select) };
53
+ }
54
+ function buildRootContext(resourceAlias, transpilerCtx) {
55
+ const idKey = {
56
+ name: "id",
57
+ sqlExpr: `[${resourceAlias}].[id]`,
58
+ sqlType: types_js_1.SQL_INT,
59
+ };
60
+ return {
61
+ resourceAlias,
62
+ // Use unbracketed `r.json` for the JSON source: matches the FHIRPath
63
+ // transpiler's expectations (see visitor.ts handleJsonQueryMember which
64
+ // pattern-matches on the source string).
65
+ source: `${resourceAlias}.json`,
66
+ partitionKeys: [idKey],
67
+ ancestorApplies: "",
68
+ cteCounter: { value: 0 },
69
+ transpilerCtx,
70
+ };
71
+ }
72
+ /**
73
+ * Walk the select tree and collect ColumnInfo metadata in lexical order.
74
+ * Mirrors the behaviour of QueryGenerator.collectAllColumns so the public
75
+ * TranspilationResult.columns shape is unchanged.
76
+ */
77
+ function collectColumnMetadata(selects) {
78
+ const out = [];
79
+ for (const select of selects) {
80
+ if (select.column) {
81
+ for (const column of select.column) {
82
+ out.push({
83
+ name: column.name,
84
+ type: transpiler_js_1.Transpiler.inferSqlType(column.type, column.tag),
85
+ nullable: true,
86
+ description: column.description,
87
+ });
88
+ }
89
+ }
90
+ if (select.select)
91
+ out.push(...collectColumnMetadata(select.select));
92
+ if (select.unionAll)
93
+ out.push(...collectColumnMetadata(select.unionAll));
94
+ }
95
+ return out;
96
+ }
97
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/compile.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * SQL string templates for the recursive CTE produced by `repeat`.
3
+ *
4
+ * Builds the anchor + recursive members, propagating partition keys and
5
+ * baked scalar columns through both. Multi-segment paths chain CROSS APPLY
6
+ * OPENJSON per segment.
7
+ *
8
+ * Note: `__path` is built by string-concatenating each child's `[key]`.
9
+ * If a JSON object key contains a literal `.`, two distinct nodes could
10
+ * theoretically produce equal `__path` strings. FHIR JSON keys do not
11
+ * contain dots in practice; not a blocker.
12
+ *
13
+ * @author John Grimes
14
+ */
15
+ import { type CteDefinition, type PartitionKey } from "./types.js";
16
+ export interface BuildRepeatCteArgs {
17
+ cteAlias: string;
18
+ /** FHIRPath strings — first is the anchor path; all are recursive paths. */
19
+ paths: string[];
20
+ /** JSON source expression for the anchor (e.g. "r.json", "forEach_0.value"). */
21
+ source: string;
22
+ /** "FROM <table> AS [r]" — the resource table reference for the anchor. */
23
+ fromClause: string;
24
+ /** CROSS/OUTER APPLY chain inherited from ancestors (each starts with "\n"). */
25
+ ancestorApplies: string;
26
+ /** Partition keys propagated through anchor and recursive members. */
27
+ partitionKeys: PartitionKey[];
28
+ /** Resource-level WHERE applied to the anchor (or null to omit). */
29
+ resourcePredicate: string | null;
30
+ }
31
+ /**
32
+ * Builds the SQL body of the recursive CTE used by the Repeat operator.
33
+ *
34
+ * Produces a `CteDefinition` whose body is an anchor SELECT followed by one
35
+ * `UNION ALL` recursive SELECT per path in `args.paths`. The anchor starts
36
+ * at the resource root and expands each array element via `OPENJSON`; each
37
+ * recursive member re-expands from the CTE's own `item_json` column,
38
+ * appending `.[key]` to the `__path` accumulator for stable per-element
39
+ * identity. Multi-segment paths (e.g. `"a.b.c"`) produce a chain of nested
40
+ * `CROSS APPLY OPENJSON` calls.
41
+ *
42
+ * @param args - Parameters controlling CTE generation: the CTE alias, the
43
+ * FHIRPath repeat paths, the JSON source expression for the anchor, the
44
+ * resource table FROM clause, any ancestor APPLY chain, the partition keys
45
+ * to propagate, and an optional resource-level WHERE predicate for the
46
+ * anchor.
47
+ * @returns A `CteDefinition` with `alias` set to `args.cteAlias` and `body`
48
+ * containing the full anchor + recursive SQL (without the outer
49
+ * `alias AS (...)` wrapper, which `renderRoot` adds).
50
+ */
51
+ export declare function buildRepeatCte(args: BuildRepeatCteArgs): CteDefinition;
52
+ /**
53
+ * Renders the partition keys as a comma-separated list of bracket-quoted
54
+ * columns qualified by `alias` (e.g. `cte.[id], cte.[fe_0_key]`). Shared by the
55
+ * recursive-member projection and the repeat `%rowIndex` window's PARTITION BY.
56
+ */
57
+ export declare function qualifiedKeyCols(alias: string, keys: PartitionKey[]): string;
58
+ //# sourceMappingURL=cteTemplates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cteTemplates.d.ts","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/cteTemplates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EAGlB,MAAM,YAAY,CAAC;AAOpB,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,eAAe,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,oEAAoE;IACpE,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,aAAa,CAOtE;AAqED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,CAE5E"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * SQL string templates for the recursive CTE produced by `repeat`.
4
+ *
5
+ * Builds the anchor + recursive members, propagating partition keys and
6
+ * baked scalar columns through both. Multi-segment paths chain CROSS APPLY
7
+ * OPENJSON per segment.
8
+ *
9
+ * Note: `__path` is built by string-concatenating each child's `[key]`.
10
+ * If a JSON object key contains a literal `.`, two distinct nodes could
11
+ * theoretically produce equal `__path` strings. FHIR JSON keys do not
12
+ * contain dots in practice; not a blocker.
13
+ *
14
+ * @author John Grimes
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.buildRepeatCte = buildRepeatCte;
18
+ exports.qualifiedKeyCols = qualifiedKeyCols;
19
+ const types_js_1 = require("./types.js");
20
+ /**
21
+ * Builds the SQL body of the recursive CTE used by the Repeat operator.
22
+ *
23
+ * Produces a `CteDefinition` whose body is an anchor SELECT followed by one
24
+ * `UNION ALL` recursive SELECT per path in `args.paths`. The anchor starts
25
+ * at the resource root and expands each array element via `OPENJSON`; each
26
+ * recursive member re-expands from the CTE's own `item_json` column,
27
+ * appending `.[key]` to the `__path` accumulator for stable per-element
28
+ * identity. Multi-segment paths (e.g. `"a.b.c"`) produce a chain of nested
29
+ * `CROSS APPLY OPENJSON` calls.
30
+ *
31
+ * @param args - Parameters controlling CTE generation: the CTE alias, the
32
+ * FHIRPath repeat paths, the JSON source expression for the anchor, the
33
+ * resource table FROM clause, any ancestor APPLY chain, the partition keys
34
+ * to propagate, and an optional resource-level WHERE predicate for the
35
+ * anchor.
36
+ * @returns A `CteDefinition` with `alias` set to `args.cteAlias` and `body`
37
+ * containing the full anchor + recursive SQL (without the outer
38
+ * `alias AS (...)` wrapper, which `renderRoot` adds).
39
+ */
40
+ function buildRepeatCte(args) {
41
+ const anchor = buildAnchorMember(args);
42
+ const recBlocks = args.paths.map((p, i) => buildRecursiveMember(args, p, i));
43
+ const body = `${anchor}
44
+ UNION ALL
45
+ ${recBlocks.join("\n UNION ALL\n")}`;
46
+ return { alias: args.cteAlias, body };
47
+ }
48
+ function buildAnchorMember(args) {
49
+ const { paths, source, fromClause, ancestorApplies, partitionKeys, resourcePredicate, } = args;
50
+ const projLines = partitionKeys
51
+ .map((k) => `${k.sqlExpr} AS [${k.name}]`)
52
+ .join(",\n ");
53
+ const chain = buildOpenJsonChain(source, paths[0], "anchor");
54
+ const wherePart = resourcePredicate ? `\n ${resourcePredicate}` : "";
55
+ return ` SELECT
56
+ ${projLines},
57
+ CAST(${chain.lastAlias}.[key] AS ${types_js_1.SQL_NVARCHAR_MAX}) AS __path,
58
+ CAST(${orderSegment(chain.lastAlias)} AS ${types_js_1.SQL_NVARCHAR_MAX}) AS __order,
59
+ ${chain.lastAlias}.value AS item_json,
60
+ 0 AS depth
61
+ ${fromClause}${ancestorApplies}
62
+ ${chain.applyClauses}${wherePart}`;
63
+ }
64
+ function buildRecursiveMember(args, path, index) {
65
+ const { cteAlias, partitionKeys } = args;
66
+ const head = qualifiedKeyCols("cte", partitionKeys);
67
+ const chain = buildOpenJsonChain("cte.item_json", path, `child_${index}`);
68
+ return ` SELECT
69
+ ${head},
70
+ cte.__path + '.' + CAST(${chain.lastAlias}.[key] AS ${types_js_1.SQL_NVARCHAR_4000}) AS __path,
71
+ cte.__order + '.' + ${orderSegment(chain.lastAlias)} AS __order,
72
+ ${chain.lastAlias}.value AS item_json,
73
+ cte.depth + 1
74
+ FROM ${cteAlias} AS cte
75
+ ${chain.applyClauses}`;
76
+ }
77
+ /**
78
+ * Width, in characters, that each `__order` segment is zero-padded to. A level
79
+ * with up to 10^ORDER_SEGMENT_WIDTH elements still sorts correctly; ten digits
80
+ * assume no single level exceeds 10^10 elements.
81
+ */
82
+ const ORDER_SEGMENT_WIDTH = 10;
83
+ /**
84
+ * Builds one segment of the `__order` accumulator: the element's `[key]`
85
+ * zero-padded to a fixed width so that lexical ordering of the `.`-joined
86
+ * order string is equivalent to numeric depth-first (pre-order) traversal.
87
+ * Without padding, lexical order would break once a level has ten or more
88
+ * elements (e.g. `"10" < "2"`). This is what `%rowIndex` orders by inside a
89
+ * `repeat`.
90
+ *
91
+ * `__order` is emitted by every repeat CTE unconditionally: the walker builds
92
+ * the CTE before descending into the inner subtree, so whether `%rowIndex` is
93
+ * actually referenced is not yet known when the column list is generated.
94
+ */
95
+ function orderSegment(alias) {
96
+ const pad = "0".repeat(ORDER_SEGMENT_WIDTH);
97
+ return `RIGHT('${pad}' + CAST(${alias}.[key] AS NVARCHAR(${ORDER_SEGMENT_WIDTH})), ${ORDER_SEGMENT_WIDTH})`;
98
+ }
99
+ /**
100
+ * Renders the partition keys as a comma-separated list of bracket-quoted
101
+ * columns qualified by `alias` (e.g. `cte.[id], cte.[fe_0_key]`). Shared by the
102
+ * recursive-member projection and the repeat `%rowIndex` window's PARTITION BY.
103
+ */
104
+ function qualifiedKeyCols(alias, keys) {
105
+ return keys.map((k) => `${alias}.[${k.name}]`).join(", ");
106
+ }
107
+ /**
108
+ * Builds the CROSS APPLY OPENJSON chain for a (possibly multi-segment) path.
109
+ * For "a.b.c" produces three chained APPLYs; the last alias is `finalAlias`.
110
+ */
111
+ function buildOpenJsonChain(source, path, finalAlias) {
112
+ const segments = path.split(".");
113
+ if (segments.length === 1) {
114
+ return {
115
+ applyClauses: `CROSS APPLY OPENJSON(${source}, '$.${segments[0]}') AS ${finalAlias}`,
116
+ lastAlias: finalAlias,
117
+ };
118
+ }
119
+ let chain = "";
120
+ let currentSource = source;
121
+ for (let i = 0; i < segments.length; i++) {
122
+ const isLast = i === segments.length - 1;
123
+ const alias = isLast ? finalAlias : `${finalAlias}_${i}`;
124
+ if (i > 0)
125
+ chain += "\n ";
126
+ chain += `CROSS APPLY OPENJSON(${currentSource}, '$.${segments[i]}') AS ${alias}`;
127
+ currentSource = `${alias}.value`;
128
+ }
129
+ return { applyClauses: chain, lastAlias: finalAlias };
130
+ }
131
+ //# sourceMappingURL=cteTemplates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cteTemplates.js","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/cteTemplates.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Tree-walker query generator.
3
+ */
4
+ export { compileViewDefinition } from "./compile.js";
5
+ export type { CompileOptions } from "./compile.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Tree-walker query generator.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compileViewDefinition = void 0;
7
+ var compile_js_1 = require("./compile.js");
8
+ Object.defineProperty(exports, "compileViewDefinition", { enumerable: true, get: function () { return compile_js_1.compileViewDefinition; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2CAAqD;AAA5C,mHAAA,qBAAqB,OAAA"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Merges sibling fragments produced by walking children of a Group.
3
+ *
4
+ * Flattens CTE lists, concatenates `fromExtensions` strings and `columns`
5
+ * arrays in order, and passes `partitionKeys` through unchanged from `ctx`.
6
+ */
7
+ import type { Context, Fragment } from "./types.js";
8
+ /**
9
+ * Merges sibling Fragments produced by walking children of a Group node.
10
+ *
11
+ * Flattens each fragment's `ctes` list, concatenates `fromExtensions` strings
12
+ * (preserving order so aliases are introduced before they are referenced), and
13
+ * concatenates `columns` arrays in lexical order. `partitionKeys` are passed
14
+ * through unchanged from `ctx` — siblings share the same partition scope.
15
+ *
16
+ * Returns an empty Fragment (no CTEs, no extensions, no columns) when
17
+ * `fragments` is empty, and returns the sole fragment unchanged when only one
18
+ * is provided.
19
+ *
20
+ * @param fragments - Ordered array of sibling Fragments to merge.
21
+ * @param ctx - The context of the parent Group node, used to supply
22
+ * `partitionKeys` for the merged result and as the base for the empty-array
23
+ * case.
24
+ * @returns A single merged Fragment whose columns, CTEs, and FROM extensions
25
+ * are the ordered union of all input fragments.
26
+ */
27
+ export declare function mergeSiblings(fragments: Fragment[], ctx: Context): Fragment;
28
+ //# sourceMappingURL=mergeSiblings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeSiblings.d.ts","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/mergeSiblings.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,OAAO,GAAG,QAAQ,CA0B3E"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * Merges sibling fragments produced by walking children of a Group.
4
+ *
5
+ * Flattens CTE lists, concatenates `fromExtensions` strings and `columns`
6
+ * arrays in order, and passes `partitionKeys` through unchanged from `ctx`.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.mergeSiblings = mergeSiblings;
10
+ /**
11
+ * Merges sibling Fragments produced by walking children of a Group node.
12
+ *
13
+ * Flattens each fragment's `ctes` list, concatenates `fromExtensions` strings
14
+ * (preserving order so aliases are introduced before they are referenced), and
15
+ * concatenates `columns` arrays in lexical order. `partitionKeys` are passed
16
+ * through unchanged from `ctx` — siblings share the same partition scope.
17
+ *
18
+ * Returns an empty Fragment (no CTEs, no extensions, no columns) when
19
+ * `fragments` is empty, and returns the sole fragment unchanged when only one
20
+ * is provided.
21
+ *
22
+ * @param fragments - Ordered array of sibling Fragments to merge.
23
+ * @param ctx - The context of the parent Group node, used to supply
24
+ * `partitionKeys` for the merged result and as the base for the empty-array
25
+ * case.
26
+ * @returns A single merged Fragment whose columns, CTEs, and FROM extensions
27
+ * are the ordered union of all input fragments.
28
+ */
29
+ function mergeSiblings(fragments, ctx) {
30
+ if (fragments.length === 0) {
31
+ return {
32
+ ctes: [],
33
+ fromExtensions: "",
34
+ columns: [],
35
+ partitionKeys: ctx.partitionKeys,
36
+ };
37
+ }
38
+ if (fragments.length === 1)
39
+ return fragments[0];
40
+ const ctes = fragments.flatMap((f) => f.ctes);
41
+ const fromExtensions = fragments.map((f) => f.fromExtensions).join("");
42
+ const columns = fragments.flatMap((f) => f.columns);
43
+ // Row siblings + zero or more set siblings: each set fragment already carries
44
+ // its own INNER JOIN to its CTE, joined on the partition keys it inherited
45
+ // from `ctx`. The outer FROM stays as the resource table so row siblings can
46
+ // keep their references to `r` valid.
47
+ return {
48
+ ctes,
49
+ fromExtensions,
50
+ columns,
51
+ partitionKeys: ctx.partitionKeys,
52
+ };
53
+ }
54
+ //# sourceMappingURL=mergeSiblings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeSiblings.js","sourceRoot":"","sources":["../../../src/queryGenerator/treeWalker/mergeSiblings.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAuBH,sCA0BC;AA7CD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,aAAa,CAAC,SAAqB,EAAE,GAAY;IAC/D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO;YACL,IAAI,EAAE,EAAE;YACR,cAAc,EAAE,EAAE;YAClB,OAAO,EAAE,EAAE;YACX,aAAa,EAAE,GAAG,CAAC,aAAa;SACjC,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;IAEhD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,cAAc,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAEpD,8EAA8E;IAC9E,2EAA2E;IAC3E,6EAA6E;IAC7E,sCAAsC;IACtC,OAAO;QACL,IAAI;QACJ,cAAc;QACd,OAAO;QACP,aAAa,EAAE,GAAG,CAAC,aAAa;KACjC,CAAC;AACJ,CAAC"}