@memberjunction/generic-database-provider 6.2.0-edge.6 → 6.2.0-edge.8

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 (88) hide show
  1. package/README.md +150 -0
  2. package/dist/GenericDatabaseProvider.d.ts +329 -41
  3. package/dist/GenericDatabaseProvider.d.ts.map +1 -1
  4. package/dist/GenericDatabaseProvider.js +864 -238
  5. package/dist/GenericDatabaseProvider.js.map +1 -1
  6. package/dist/clientClauseScreen.d.ts +16 -72
  7. package/dist/clientClauseScreen.d.ts.map +1 -1
  8. package/dist/clientClauseScreen.js +34 -278
  9. package/dist/clientClauseScreen.js.map +1 -1
  10. package/dist/composition/compositionAssembler.d.ts +33 -0
  11. package/dist/composition/compositionAssembler.d.ts.map +1 -0
  12. package/dist/composition/compositionAssembler.js +270 -0
  13. package/dist/composition/compositionAssembler.js.map +1 -0
  14. package/dist/composition/compositionInfo.d.ts +7 -0
  15. package/dist/composition/compositionInfo.d.ts.map +1 -0
  16. package/dist/composition/compositionInfo.js +31 -0
  17. package/dist/composition/compositionInfo.js.map +1 -0
  18. package/dist/composition/compositionLookup.d.ts +44 -0
  19. package/dist/composition/compositionLookup.d.ts.map +1 -0
  20. package/dist/composition/compositionLookup.js +122 -0
  21. package/dist/composition/compositionLookup.js.map +1 -0
  22. package/dist/composition/compositionRender.d.ts +136 -0
  23. package/dist/composition/compositionRender.d.ts.map +1 -0
  24. package/dist/composition/compositionRender.js +264 -0
  25. package/dist/composition/compositionRender.js.map +1 -0
  26. package/dist/composition/compositionTypes.d.ts +40 -0
  27. package/dist/composition/compositionTypes.d.ts.map +1 -0
  28. package/dist/composition/compositionTypes.js +2 -0
  29. package/dist/composition/compositionTypes.js.map +1 -0
  30. package/dist/composition/quotedTagRefusal.d.ts +44 -0
  31. package/dist/composition/quotedTagRefusal.d.ts.map +1 -0
  32. package/dist/composition/quotedTagRefusal.js +132 -0
  33. package/dist/composition/quotedTagRefusal.js.map +1 -0
  34. package/dist/composition/renderSteps.d.ts +16 -0
  35. package/dist/composition/renderSteps.d.ts.map +1 -0
  36. package/dist/composition/renderSteps.js +42 -0
  37. package/dist/composition/renderSteps.js.map +1 -0
  38. package/dist/composition/safetyGate.d.ts +46 -0
  39. package/dist/composition/safetyGate.d.ts.map +1 -0
  40. package/dist/composition/safetyGate.js +61 -0
  41. package/dist/composition/safetyGate.js.map +1 -0
  42. package/dist/composition/templateUnit.d.ts +95 -0
  43. package/dist/composition/templateUnit.d.ts.map +1 -0
  44. package/dist/composition/templateUnit.js +189 -0
  45. package/dist/composition/templateUnit.js.map +1 -0
  46. package/dist/describeStatement.d.ts +51 -0
  47. package/dist/describeStatement.d.ts.map +1 -0
  48. package/dist/describeStatement.js +19 -0
  49. package/dist/describeStatement.js.map +1 -0
  50. package/dist/fieldSecurity/projectionStars.d.ts +15 -0
  51. package/dist/fieldSecurity/projectionStars.d.ts.map +1 -0
  52. package/dist/fieldSecurity/projectionStars.js +116 -0
  53. package/dist/fieldSecurity/projectionStars.js.map +1 -0
  54. package/dist/fieldSecurity/queryColumnSecurity.d.ts +35 -0
  55. package/dist/fieldSecurity/queryColumnSecurity.d.ts.map +1 -0
  56. package/dist/fieldSecurity/queryColumnSecurity.js +84 -0
  57. package/dist/fieldSecurity/queryColumnSecurity.js.map +1 -0
  58. package/dist/index.d.ts +10 -2
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +6 -1
  61. package/dist/index.js.map +1 -1
  62. package/dist/pagingLayout.d.ts +68 -0
  63. package/dist/pagingLayout.d.ts.map +1 -0
  64. package/dist/pagingLayout.js +190 -0
  65. package/dist/pagingLayout.js.map +1 -0
  66. package/dist/queryCompositionEngine.d.ts +22 -222
  67. package/dist/queryCompositionEngine.d.ts.map +1 -1
  68. package/dist/queryCompositionEngine.js +35 -729
  69. package/dist/queryCompositionEngine.js.map +1 -1
  70. package/dist/queryPagingEngine.d.ts +26 -5
  71. package/dist/queryPagingEngine.d.ts.map +1 -1
  72. package/dist/queryPagingEngine.js +51 -15
  73. package/dist/queryPagingEngine.js.map +1 -1
  74. package/dist/renderPipeline.d.ts +77 -85
  75. package/dist/renderPipeline.d.ts.map +1 -1
  76. package/dist/renderPipeline.js +70 -220
  77. package/dist/renderPipeline.js.map +1 -1
  78. package/dist/statementMemo.d.ts +29 -0
  79. package/dist/statementMemo.d.ts.map +1 -0
  80. package/dist/statementMemo.js +61 -0
  81. package/dist/statementMemo.js.map +1 -0
  82. package/dist/typedQueryParameter.d.ts +55 -0
  83. package/dist/typedQueryParameter.d.ts.map +1 -0
  84. package/dist/typedQueryParameter.js +122 -0
  85. package/dist/typedQueryParameter.js.map +1 -0
  86. package/dist/types.d.ts +11 -0
  87. package/dist/types.d.ts.map +1 -1
  88. package/package.json +14 -14
@@ -1,79 +1,51 @@
1
1
  import { BuildQueryTemplateContext, LogStatus } from '@memberjunction/core';
2
- import { QueryEngine } from '@memberjunction/core-entities';
3
- import { UUIDMap, UUIDSet } from '@memberjunction/global';
4
2
  import { GetDialect } from '@memberjunction/sql-dialect';
5
- import { SQLParser, IsReadOnlyQuery, FindForbiddenFunctionCalls } from '@memberjunction/sql-parser';
6
3
  import { QueryCompositionEngine } from './queryCompositionEngine.js';
7
4
  import { QueryPagingEngine } from './queryPagingEngine.js';
8
- import { QueryParameterProcessor } from '@memberjunction/query-processor';
5
+ import { SafetyGate } from './composition/safetyGate.js';
6
+ import { CTEInfoOf } from './composition/compositionInfo.js';
7
+ import { AssembleComposition, NewCompositionRender, OuterRenderRequest } from './composition/renderSteps.js';
9
8
  // ════════════════════════════════════════════════════════════════════
10
9
  // Pipeline
11
10
  // ════════════════════════════════════════════════════════════════════
12
11
  /**
13
- * RenderPipeline wraps the existing composition → template → paging calls
14
- * into a single entry point with enforced ordering and diagnostic tracing.
12
+ * RenderPipeline is the one entry point that turns query SQL into the SQL that runs, with
13
+ * enforced ordering and a diagnostic trace. Every path uses it: saved queries, ad hoc SQL,
14
+ * TestQuerySQL, specs and data contexts.
15
15
  *
16
- * **Pipeline order** (this is a data dependency, not a convention):
17
- * 1. **Composition** resolves `{{query:"..."}}` tokens into CTEs. Must run
18
- * BEFORE Nunjucks because pass-through parameters rename `{{ innerParam }}`
19
- * to `{{ outerParam }}` — Nunjucks needs those tokens intact.
20
- * 2. **Nunjucks** evaluates `{{ param | filter }}` and `{% if/for %}` blocks.
21
- * Must run AFTER composition and BEFORE paging.
22
- * 3. **Paging** detects ORDER BY and injects OFFSET/FETCH or LIMIT/OFFSET.
23
- * Must run AFTER Nunjucks because it needs to detect whether
24
- * `{% if SortField %} ORDER BY ... {% endif %}` resolved to an actual
25
- * ORDER BY or not — that depends on runtime parameter values.
26
- *
27
- * The `Trace` field on the result captures the SQL state after each pass,
28
- * enabling diagnosis when SQL Server rejects the output.
16
+ * **Pipeline order** (a data dependency, not a convention):
17
+ * 1. **Comments** are removed first, so template tags in them are inert.
18
+ * 2. **Interpreter gate**: a template must pass the MJ Query language check
19
+ * (`QueryTemplate.Validate`, Refresh mode); a template with errors is refused.
20
+ * 3. **Render, then compose**: Nunjucks renders the outer template once. Each composition it
21
+ * reaches records an instance (the composed query + its arguments evaluated in the caller's
22
+ * scope) and writes the instance's CTE name. Each instance then renders on its own, with only
23
+ * its arguments, recursively. The plain SQL is assembled from the rendered parts and is never
24
+ * rendered again, so a value that looks like a template tag stays a value.
25
+ * 4. **Safety**: the assembled statement must be a single read query (token-based; see
26
+ * {@link SafetyGate}).
27
+ * 5. **Row cap / paging** detect ORDER BY and inject TOP / OFFSET-FETCH / LIMIT, after rendering,
28
+ * because `{% if SortField %} ORDER BY … {% endif %}` decides whether there is an ORDER BY.
29
29
  */
30
30
  export class RenderPipeline {
31
31
  /**
32
- * Runs the full rendering pipeline: composition → Nunjucks → paging.
32
+ * Runs the full rendering pipeline.
33
33
  *
34
34
  * @param sql - Raw SQL with potential composition tokens and template expressions
35
35
  * @param ctx - Pipeline context (platform, user, parameters, paging, etc.)
36
36
  * @returns Final SQL, applied parameters, composition metadata, and diagnostic trace
37
37
  */
38
38
  static Run(sql, ctx) {
39
- const hasMaxRows = ctx.MaxRows != null && ctx.MaxRows > 0;
40
- const hasPaging = ctx.Paging != null && QueryPagingEngine.ShouldPage(ctx.Paging.StartRow, ctx.Paging.MaxRows);
41
- if (hasMaxRows && hasPaging) {
42
- throw new Error('RenderPipeline.Run: ctx.MaxRows and ctx.Paging are mutually exclusive. ' +
43
- 'Use Paging for pagination (StartRow + MaxRows) or MaxRows alone for a safety cap. ' +
44
- `Got MaxRows=${ctx.MaxRows} and Paging=${JSON.stringify(ctx.Paging)}.`);
45
- }
46
- let currentSQL = sql;
47
- let appliedParameters = {};
48
- let contextValues = {};
49
- // ── Step 1: Composition ──────────────────────────────────────
50
- const compositionResult = RenderPipeline.runComposition(currentSQL, ctx);
51
- currentSQL = compositionResult.ResolvedSQL;
52
- const afterComposition = currentSQL;
53
- const compositionDiagnostics = buildCompositionDiagnostics(compositionResult);
54
- // ── Step 1.5: Strip SQL comments ─────────────────────────────
55
- // Comments serve no runtime purpose in executed SQL and can contain
56
- // {{ }} patterns (e.g. documentation examples) that would crash
57
- // Nunjucks. Strip them after composition (which correctly ignores
58
- // comment-embedded tokens) and before Nunjucks processes the SQL.
59
- // Comments are still visible in Trace.AfterComposition for debugging.
60
- currentSQL = SQLParser.StripComments(currentSQL, GetDialect(ctx.Platform));
61
- // ── Step 2: Nunjucks template evaluation ─────────────────────
62
- const templateResult = RenderPipeline.runTemplates(currentSQL, sql, ctx, compositionResult);
63
- currentSQL = templateResult.processedSQL;
64
- appliedParameters = templateResult.appliedParameters;
65
- contextValues = templateResult.contextValues;
66
- const afterTemplates = currentSQL;
67
- // ── Step 2.5: Safety validation (mutation + injection guard) ──
68
- // The fully-resolved query is the point where composition and parameter
69
- // substitution — the only injection vectors — are complete, and where
70
- // StatementKind reflects the user's actual statement (paging wrapping
71
- // below always produces a SELECT). Saved queries otherwise skip the
72
- // dangerous-keyword validation that ad-hoc queries get at execution.
73
- RenderPipeline.assertSafeToExecute(afterTemplates, ctx.Platform, ctx.RequireReadStatement ?? false);
74
- // ── Step 3: MaxRows safety limit (if specified) ──────────────
39
+ const caps = RenderPipeline.capsOf(ctx);
40
+ const dialect = GetDialect(ctx.Platform);
41
+ const context = BuildQueryTemplateContext({ User: ctx.ContextUser, TimeZone: ctx.TimeZone, Now: ctx.Now });
42
+ const render = NewCompositionRender(ctx, dialect, context, false);
43
+ const outer = render.RenderOuter(OuterRenderRequest(sql, ctx));
44
+ const assembled = AssembleComposition(outer.SQL, render.Instances, dialect);
45
+ SafetyGate.AssertSafeToExecute(assembled.SQL, dialect, ctx.RequireReadStatement === true);
46
+ let currentSQL = assembled.SQL;
75
47
  let rowCap = null;
76
- if (hasMaxRows) {
48
+ if (caps.HasMaxRows) {
77
49
  const capResult = QueryPagingEngine.ApplyMaxRows(currentSQL, ctx.MaxRows, ctx.Platform);
78
50
  currentSQL = capResult.SQL;
79
51
  rowCap = capResult.Outcome;
@@ -81,97 +53,41 @@ export class RenderPipeline {
81
53
  LogStatus(`RenderPipeline: MaxRows ${ctx.MaxRows} was not applied — ${rowCap.Reason}. The query runs uncapped.`);
82
54
  }
83
55
  }
84
- // ── Step 4: Paging (if requested) ────────────────────────────
85
56
  let pagingResult = null;
86
- let afterPaging = null;
87
- if (hasPaging) {
57
+ if (caps.HasPaging) {
88
58
  pagingResult = QueryPagingEngine.WrapWithPaging(currentSQL, ctx.Paging.StartRow, ctx.Paging.MaxRows, ctx.Platform);
89
59
  currentSQL = pagingResult.DataSQL;
90
- afterPaging = currentSQL;
91
60
  }
92
61
  return {
93
62
  FinalSQL: currentSQL,
94
- AppliedParameters: appliedParameters,
95
- ContextValues: contextValues,
96
- HasCompositions: compositionResult.HasCompositions,
97
- CTEs: compositionResult.CTEs,
98
- Trace: {
99
- AfterComposition: afterComposition,
100
- CompositionDiagnostics: compositionDiagnostics,
101
- AfterTemplates: afterTemplates,
102
- AfterPaging: afterPaging,
103
- },
63
+ AppliedParameters: outer.AppliedParameters,
64
+ ContextValues: context.ReadValues(),
65
+ HasCompositions: outer.HasCompositions,
66
+ CTEs: render.Instances.map(CTEInfoOf),
67
+ Trace: RenderPipeline.traceOf(assembled, pagingResult ? currentSQL : null),
104
68
  PagingResult: pagingResult,
105
69
  RowCap: rowCap,
106
70
  };
107
71
  }
108
- /**
109
- * Defense-in-depth guard on the fully-resolved query: throws when the
110
- * rendered SQL contains a write statement anywhere — a DML mutation
111
- * (INSERT / UPDATE / DELETE / MERGE / REPLACE), DDL (DROP / CREATE / ALTER /
112
- * TRUNCATE / RENAME), or EXEC / CALL / GRANT / REVOKE / USE.
113
- *
114
- * {@link SQLParser.HasWriteStatement} inspects EVERY top-level statement, so
115
- * it catches both a single rendered mutation and a stacked-statement
116
- * injection payload (e.g. `SELECT 1; DROP TABLE x`) that the first-statement
117
- * `StatementKind` alone would miss. It is AST-precise: matching is on the
118
- * statement type, so it cannot false-positive on legitimate read queries —
119
- * the `REPLACE()` string function, parenthesized SELECTs, trailing
120
- * semicolons, or benign `SET` / `DECLARE` prefixes all pass.
121
- *
122
- * A second, token-based check rejects stacked statements (an internal
123
- * statement-separating `;`). Unlike the AST check it fires even when the
124
- * trailing payload makes the SQL unparseable — e.g. `SELECT 1; EXEC
125
- * xp_cmdshell '…'` or `SELECT 1; WAITFOR DELAY '…'` — which is the
126
- * stacked-injection class the AST scan misses (the whole string fails to
127
- * parse, so there is no AST to classify). A rendered read query must be a
128
- * single statement.
129
- *
130
- * When `requireReadStatement` is set (SQL a caller supplied rather than a
131
- * saved query), the statement must first pass {@link IsReadOnlyQuery}: one
132
- * statement, starting with SELECT or WITH, reading in every CTE, and not
133
- * writing its rows into a table. That check works from tokens, so it also
134
- * refuses a `SET` or `DECLARE` the AST check lets through, and it still
135
- * accepts read queries the parser cannot read. Such SQL also may not call
136
- * the functions the dialect lists in `CallerSQLForbiddenFunctions`
137
- * (`query_to_xml`, `pg_read_file`, `OPENROWSET`, …): they read what a check
138
- * of the tables the SQL references cannot see.
139
- *
140
- * The broader dangerous-keyword scan
141
- * ({@link SQLExpressionValidator.validateFullQuery}) deliberately stays on
142
- * the ad-hoc execution path (untrusted free-text input); it is unsuitable as
143
- * a blanket gate here because it rejects legitimate read constructs (the
144
- * `REPLACE()` string function, parenthesized SELECTs, etc.).
145
- */
146
- static assertSafeToExecute(sql, platform, requireReadStatement) {
147
- const dialect = GetDialect(platform);
148
- if (requireReadStatement) {
149
- const check = IsReadOnlyQuery(sql, dialect);
150
- if (!check.IsReadOnly) {
151
- throw new Error(`RenderPipeline: only a single read query may be run here, and this SQL is not one: ${check.Reason}.`);
152
- }
153
- const forbidden = FindForbiddenFunctionCalls(sql, dialect);
154
- if (forbidden.length > 0) {
155
- throw new Error(`RenderPipeline: SQL supplied here may not call ${forbidden.join(', ')}. These functions run SQL ` +
156
- 'given as a string, or read files or other databases, so what they read cannot be checked.');
157
- }
158
- }
159
- const parsed = new SQLParser(sql, dialect);
160
- if (parsed.HasWriteStatement) {
161
- throw new Error('RenderPipeline: rendered SQL contains a write statement ' +
162
- '(mutation / DDL) — only a read query may be rendered for execution.');
163
- }
164
- if (SQLParser.HasStackedStatements(sql, dialect)) {
165
- throw new Error('RenderPipeline: rendered SQL contains multiple statements ' +
166
- '(a stacked-statement injection) — only a single read query may be rendered.');
72
+ /** Whether a MaxRows cap and paging were asked for; refuses both at once. */
73
+ static capsOf(ctx) {
74
+ const hasMaxRows = ctx.MaxRows != null && ctx.MaxRows > 0;
75
+ const hasPaging = ctx.Paging != null && QueryPagingEngine.ShouldPage(ctx.Paging.StartRow, ctx.Paging.MaxRows);
76
+ if (hasMaxRows && hasPaging) {
77
+ throw new Error('RenderPipeline.Run: ctx.MaxRows and ctx.Paging are mutually exclusive. ' +
78
+ 'Use Paging for pagination (StartRow + MaxRows) or MaxRows alone for a safety cap. ' +
79
+ `Got MaxRows=${ctx.MaxRows} and Paging=${JSON.stringify(ctx.Paging)}.`);
167
80
  }
81
+ return { HasMaxRows: hasMaxRows, HasPaging: hasPaging };
168
82
  }
169
83
  /**
170
- * Resolves only the composition step — for callers that need composition
171
- * without the full pipeline (e.g., save-time token analysis).
84
+ * Resolves only the composition step: the composed queries are rendered with the static
85
+ * arguments written in their composition tokens and assembled as CTEs; the outer SQL itself is
86
+ * not rendered (its own template tags stay as written). For callers that run SQL with
87
+ * compositions but no parameter values (GetData).
172
88
  *
173
- * Wraps {@link QueryCompositionEngine.ResolveComposition} to maintain the
174
- * existing public API while the internal implementation may change.
89
+ * @throws Error when a composition of the outer SQL passes a value of the outer query: without
90
+ * rendering there is no value to pass. Use {@link Run} for those.
175
91
  */
176
92
  static ResolveCompositionOnly(sql, platform, contextUser, outerParams, inlineDependencies) {
177
93
  return new QueryCompositionEngine().ResolveComposition(sql, platform, contextUser, outerParams, inlineDependencies);
@@ -185,94 +101,28 @@ export class RenderPipeline {
185
101
  }
186
102
  // ════════════════════════════════════════════════════════════════
187
103
  // Internal pass implementations
188
- // ═════════════════════════════════════════════════════���══════════
189
- static runComposition(sql, ctx) {
190
- const engine = new QueryCompositionEngine();
191
- if (!engine.HasCompositionTokens(sql) || !ctx.ContextUser) {
192
- return {
193
- ResolvedSQL: sql,
194
- CTEs: [],
195
- DependencyGraph: new Map(),
196
- HasCompositions: false,
197
- AnyDependencyUsesTemplates: false,
198
- };
199
- }
200
- return engine.ResolveComposition(sql, ctx.Platform, ctx.ContextUser, ctx.Parameters, ctx.Dependencies);
201
- }
202
- static runTemplates(composedSQL, originalSQL, ctx, compositionResult) {
203
- const needsTemplateProcessing = ctx.UsesTemplate || compositionResult.AnyDependencyUsesTemplates;
204
- if (!needsTemplateProcessing) {
205
- return { processedSQL: composedSQL, appliedParameters: {}, contextValues: {} };
206
- }
207
- // Build the template input. When a QueryInfo object is provided (saved
208
- // query path), pass it directly so processQueryTemplate gets the real
209
- // Parameters array for validation. Otherwise build a synthetic input.
210
- const templateInput = ctx.QueryInfo ?? {
211
- SQL: ctx.OriginalSQL ?? originalSQL,
212
- UsesTemplate: ctx.UsesTemplate ?? false,
213
- Parameters: ctx.ParameterDefinitions ?? [],
214
- };
215
- const skipUnknownParamCheck = compositionResult.AnyDependencyUsesTemplates || !ctx.ParameterDefinitions;
216
- const result = QueryParameterProcessor.ProcessQueryTemplate(templateInput, ctx.Parameters, composedSQL, skipUnknownParamCheck, RenderPipeline.buildServerValues(ctx, compositionResult));
217
- if (!result.success) {
218
- throw new Error(result.error);
219
- }
220
- return {
221
- processedSQL: result.processedSQL,
222
- appliedParameters: (result.appliedParameters || {}),
223
- contextValues: result.contextValues ?? {},
224
- };
225
- }
226
- /**
227
- * What the server sets on this render: its `ServerParameters`, the names that reach a
228
- * server-set parameter of a composed query, and the `Context` object, worked out from the
229
- * context user and the run's time zone. Context members resolve only when the template reads them.
230
- */
231
- static buildServerValues(ctx, compositionResult) {
104
+ // ════════════════════════════════════════════════════════════════
105
+ static traceOf(assembled, afterPaging) {
232
106
  return {
233
- ServerParameters: ctx.ServerParameters,
234
- ProtectedNames: RenderPipeline.composedServerSetNames(compositionResult),
235
- Context: BuildQueryTemplateContext({ User: ctx.ContextUser, TimeZone: ctx.TimeZone, Now: ctx.Now }),
107
+ AfterComposition: assembled.SQL,
108
+ CompositionDiagnostics: assembled.Instances.map(a => ({
109
+ DepName: a.Instance.Resolved.Query.Name,
110
+ CategoryPath: a.Instance.Path.FullPath,
111
+ CTEName: a.Instance.CTEName,
112
+ OrderByStripped: a.OrderByStripped,
113
+ InnerCTEsHoisted: a.InnerCTEsHoisted,
114
+ })),
115
+ AfterTemplates: assembled.SQL,
116
+ AfterPaging: afterPaging,
117
+ Instances: assembled.Instances.map(a => ({
118
+ QueryID: a.Instance.Resolved.Query.ID,
119
+ QueryName: a.Instance.Resolved.Query.Name,
120
+ CategoryPath: a.Instance.Path.FullPath,
121
+ CTEName: a.Instance.CTEName,
122
+ Arguments: { ...a.Instance.Arguments },
123
+ RenderedSQL: a.Instance.RenderedSQL,
124
+ })),
236
125
  };
237
126
  }
238
- /**
239
- * The names a caller value may not use because they reach a server-set parameter of a composed
240
- * query: the parameter's own name when the composition token leaves it unmapped (it then reads
241
- * the outer render context), or the outer name it is passed through from. A static value in the
242
- * token is the query author's and protects nothing.
243
- */
244
- static composedServerSetNames(compositionResult) {
245
- if (compositionResult.CTEs.length === 0) {
246
- return [];
247
- }
248
- const composedIDs = new UUIDSet(compositionResult.CTEs.map(c => c.QueryID));
249
- const composed = new UUIDMap(QueryEngine.Instance.Queries.filter(q => composedIDs.Has(q.ID)).map((q) => [q.ID, q]));
250
- const names = new Set();
251
- for (const cte of compositionResult.CTEs) {
252
- for (const param of composed.Get(cte.QueryID)?.QueryParameters.filter(p => p.IsServerSet) ?? []) {
253
- const mapped = cte.Parameters[param.Name];
254
- const passThrough = mapped === undefined ? param.Name : /^\{\{\s*([A-Za-z_]\w*)\s*\}\}$/.exec(mapped)?.[1];
255
- if (passThrough) {
256
- names.add(passThrough);
257
- }
258
- }
259
- }
260
- return [...names];
261
- }
262
- }
263
- // ════════════════════════════════════════════════════════════════════
264
- // Helpers
265
- // ════════════════════════════════════════════════════════════════════
266
- function buildCompositionDiagnostics(result) {
267
- return result.CTEs.map(cte => ({
268
- DepName: cte.QueryName,
269
- CategoryPath: cte.CategoryPath,
270
- CTEName: cte.CTEName,
271
- // We can't easily tell if ORDER BY was stripped without comparing
272
- // original vs resolved SQL, so this is a best-effort flag based on
273
- // whether the original had ORDER BY and the resolved doesn't.
274
- OrderByStripped: /ORDER\s+BY\b/i.test(cte.OriginalSQL) && !/ORDER\s+BY\b/i.test(cte.ResolvedSQL),
275
- InnerCTEsHoisted: 0, // TODO: track in composition engine
276
- }));
277
127
  }
278
128
  //# sourceMappingURL=renderPipeline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderPipeline.js","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAmD,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC7H,OAAO,EAAiD,WAAW,EAAE,MAAM,+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AClD,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI;gBACvC,YAAY,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ;gBACtC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO;gBAC3B,eAAe,EAAE,CAAC,CAAC,eAAe;gBAClC,gBAAgB,EAAE,CAAC,CAAC,gBAAgB;aACvC,CAAC,CAAC;YACH,cAAc,EAAE,SAAS,CAAC,GAAG;YAC7B,WAAW,EAAE,WAAW;YACxB,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACrC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBACrC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI;gBACzC,YAAY,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ;gBACtC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO;gBAC3B,SAAS,EAAE,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE;gBACtC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW;aACtC,CAAC,CAAC;SACN,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A bounded memo of facts about SQL statements, keyed by a SHA-256 of the dialect key and the
3
+ * statement text, so a long statement is never kept as a key. When full, the entry stored longest
4
+ * ago goes first. An optional lifetime makes an entry expire, for facts that depend on the
5
+ * database schema rather than on the text alone.
6
+ */
7
+ export declare class StatementMemo<V> {
8
+ private readonly maxEntries;
9
+ private readonly ttlMs;
10
+ private readonly entries;
11
+ /**
12
+ * @param maxEntries - How many entries are kept.
13
+ * @param ttlMs - How long an entry is trusted, in milliseconds; `null` for as long as it is kept.
14
+ */
15
+ constructor(maxEntries: number, ttlMs?: number | null);
16
+ /** The key of `sql` read in `dialectKey`. */
17
+ static KeyOf(sql: string, dialectKey: string): string;
18
+ /** The value kept under `key`; undefined when there is none or it has expired. */
19
+ Get(key: string, now?: number): V | undefined;
20
+ /** Keeps `value` under `key`, dropping the oldest entry when full. */
21
+ Set(key: string, value: V, now?: number): void;
22
+ /** The value under `key`, computing and keeping it on a miss. */
23
+ GetOrCompute(key: string, compute: () => V): V;
24
+ /** Forgets the entry under `key`. */
25
+ Delete(key: string): void;
26
+ /** How many entries are kept. */
27
+ get Size(): number;
28
+ }
29
+ //# sourceMappingURL=statementMemo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statementMemo.d.ts","sourceRoot":"","sources":["../src/statementMemo.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,aAAa,CAAC,CAAC;IAOZ,OAAO,CAAC,QAAQ,CAAC,UAAU;IAAU,OAAO,CAAC,QAAQ,CAAC,KAAK;IANvE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiE;IAEzF;;;OAGG;gBAC0B,UAAU,EAAE,MAAM,EAAmB,KAAK,GAAE,MAAM,GAAG,IAAW;IAE7F,6CAA6C;IAC7C,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IAIrD,kFAAkF;IAClF,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAmB,GAAG,CAAC,GAAG,SAAS;IAUzD,sEAAsE;IACtE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,GAAE,MAAmB,GAAG,IAAI;IAS1D,iEAAiE;IACjE,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC;IAQ9C,qCAAqC;IACrC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIzB,iCAAiC;IACjC,IAAI,IAAI,IAAI,MAAM,CAEjB;CACJ"}
@@ -0,0 +1,61 @@
1
+ import { createHash } from 'node:crypto';
2
+ /**
3
+ * A bounded memo of facts about SQL statements, keyed by a SHA-256 of the dialect key and the
4
+ * statement text, so a long statement is never kept as a key. When full, the entry stored longest
5
+ * ago goes first. An optional lifetime makes an entry expire, for facts that depend on the
6
+ * database schema rather than on the text alone.
7
+ */
8
+ export class StatementMemo {
9
+ /**
10
+ * @param maxEntries - How many entries are kept.
11
+ * @param ttlMs - How long an entry is trusted, in milliseconds; `null` for as long as it is kept.
12
+ */
13
+ constructor(maxEntries, ttlMs = null) {
14
+ this.maxEntries = maxEntries;
15
+ this.ttlMs = ttlMs;
16
+ this.entries = new Map();
17
+ }
18
+ /** The key of `sql` read in `dialectKey`. */
19
+ static KeyOf(sql, dialectKey) {
20
+ return createHash('sha256').update(dialectKey).update('\u0000').update(sql).digest('hex');
21
+ }
22
+ /** The value kept under `key`; undefined when there is none or it has expired. */
23
+ Get(key, now = Date.now()) {
24
+ const entry = this.entries.get(key);
25
+ if (!entry)
26
+ return undefined;
27
+ if (this.ttlMs !== null && now - entry.At > this.ttlMs) {
28
+ this.entries.delete(key);
29
+ return undefined;
30
+ }
31
+ return entry.Value;
32
+ }
33
+ /** Keeps `value` under `key`, dropping the oldest entry when full. */
34
+ Set(key, value, now = Date.now()) {
35
+ this.entries.delete(key);
36
+ if (this.entries.size >= this.maxEntries) {
37
+ const oldest = this.entries.keys().next();
38
+ if (!oldest.done)
39
+ this.entries.delete(oldest.value);
40
+ }
41
+ this.entries.set(key, { Value: value, At: now });
42
+ }
43
+ /** The value under `key`, computing and keeping it on a miss. */
44
+ GetOrCompute(key, compute) {
45
+ const kept = this.Get(key);
46
+ if (kept !== undefined)
47
+ return kept;
48
+ const value = compute();
49
+ this.Set(key, value);
50
+ return value;
51
+ }
52
+ /** Forgets the entry under `key`. */
53
+ Delete(key) {
54
+ this.entries.delete(key);
55
+ }
56
+ /** How many entries are kept. */
57
+ get Size() {
58
+ return this.entries.size;
59
+ }
60
+ }
61
+ //# sourceMappingURL=statementMemo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statementMemo.js","sourceRoot":"","sources":["../src/statementMemo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IAGtB;;;OAGG;IACH,YAA6B,UAAkB,EAAmB,QAAuB,IAAI;QAAhE,eAAU,GAAV,UAAU,CAAQ;QAAmB,UAAK,GAAL,KAAK,CAAsB;QAN5E,YAAO,GAAG,IAAI,GAAG,EAAsD,CAAC;IAMO,CAAC;IAEjG,6CAA6C;IAC7C,MAAM,CAAC,KAAK,CAAC,GAAW,EAAE,UAAkB;QACxC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9F,CAAC;IAED,kFAAkF;IAClF,GAAG,CAAC,GAAW,EAAE,MAAc,IAAI,CAAC,GAAG,EAAE;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,GAAG,GAAG,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YACrD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACzB,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,KAAK,CAAC,KAAK,CAAC;IACvB,CAAC;IAED,sEAAsE;IACtE,GAAG,CAAC,GAAW,EAAE,KAAQ,EAAE,MAAc,IAAI,CAAC,GAAG,EAAE;QAC/C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;YAC1C,IAAI,CAAC,MAAM,CAAC,IAAI;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,iEAAiE;IACjE,YAAY,CAAC,GAAW,EAAE,OAAgB;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACpC,MAAM,KAAK,GAAG,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACrB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,qCAAqC;IACrC,MAAM,CAAC,GAAW;QACd,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,iCAAiC;IACjC,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC7B,CAAC;CACJ"}
@@ -0,0 +1,55 @@
1
+ /** A value a {@link TypedQueryParameter} carries. */
2
+ export type TypedQueryParameterValue = string | number | boolean | Date | null;
3
+ /**
4
+ * One bind parameter with the database type of the column it is compared with, such as
5
+ * `varchar(50)` or `datetime2(7)`. Statements reference it by the placeholder the dialect's
6
+ * binding gives (`DialectBinding.TypedParameter`): SQL Server providers bind it by name with that
7
+ * declared type, so a varchar column is compared with a varchar value and keeps its index seek;
8
+ * PostgreSQL providers bind it by position, and the placeholder casts it.
9
+ */
10
+ export declare class TypedQueryParameter {
11
+ /** The name the driver binds it under (`mj_p0`), or its position's name (`$1`). */
12
+ readonly Name: string;
13
+ /** The database type, as the server describes it. */
14
+ readonly SQLType: string;
15
+ readonly Value: TypedQueryParameterValue;
16
+ constructor(
17
+ /** The name the driver binds it under (`mj_p0`), or its position's name (`$1`). */
18
+ Name: string,
19
+ /** The database type, as the server describes it. */
20
+ SQLType: string, Value: TypedQueryParameterValue);
21
+ }
22
+ /**
23
+ * One bind parameter passed by name, whose type the driver infers from the value. Statements
24
+ * reference it by the dialect's placeholder (`DialectBinding.ParameterPlaceholder`): SQL Server
25
+ * providers bind it by name (`@p0` is bound as `p0`) and leave the statement text alone; PostgreSQL
26
+ * providers bind it by position (`$1`).
27
+ *
28
+ * This is how MJ's own parameterized SQL passes untyped values. A plain array of values is the
29
+ * legacy positional form, which SQL Server providers bind by rewriting every `?` in the text,
30
+ * including a `?` inside a string literal, quoted identifier or comment.
31
+ */
32
+ export declare class NamedQueryParameter {
33
+ /** The name the driver binds it under (`p0`), or its position's name (`$1`). */
34
+ readonly Name: string;
35
+ readonly Value: TypedQueryParameterValue;
36
+ constructor(
37
+ /** The name the driver binds it under (`p0`), or its position's name (`$1`). */
38
+ Name: string, Value: TypedQueryParameterValue);
39
+ }
40
+ /** True when `parameters` is a non-empty list of {@link NamedQueryParameter}. */
41
+ export declare function IsNamedQueryParameterList(parameters: unknown): parameters is NamedQueryParameter[];
42
+ /** True when `parameters` is a non-empty list of {@link TypedQueryParameter}. */
43
+ export declare function IsTypedQueryParameterList(parameters: unknown): parameters is TypedQueryParameter[];
44
+ /**
45
+ * `value` converted to what a parameter of database type `sqlType` binds: a boolean for a bit or
46
+ * boolean column, a finite number for a numeric one, a `Date` for a date or timestamp one, and text
47
+ * otherwise. Undefined when the value cannot be one (a non-numeric string for an int column, an
48
+ * invalid date), so the caller can refuse rather than bind a value the database would reject or
49
+ * read differently.
50
+ *
51
+ * @param value - The value, in native form (booleans as booleans, dates as `Date` or ISO text with its zone).
52
+ * @param sqlType - The column's type as the server describes it, such as `varchar(50)` or `timestamp with time zone`.
53
+ */
54
+ export declare function TypedBindValue(value: unknown, sqlType: string): TypedQueryParameterValue | undefined;
55
+ //# sourceMappingURL=typedQueryParameter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typedQueryParameter.d.ts","sourceRoot":"","sources":["../src/typedQueryParameter.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/E;;;;;;GAMG;AACH,qBAAa,mBAAmB;IAExB,mFAAmF;aACnE,IAAI,EAAE,MAAM;IAC5B,qDAAqD;aACrC,OAAO,EAAE,MAAM;aACf,KAAK,EAAE,wBAAwB;;IAJ/C,mFAAmF;IACnE,IAAI,EAAE,MAAM;IAC5B,qDAAqD;IACrC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,wBAAwB;CAEtD;AAED;;;;;;;;;GASG;AACH,qBAAa,mBAAmB;IAExB,gFAAgF;aAChE,IAAI,EAAE,MAAM;aACZ,KAAK,EAAE,wBAAwB;;IAF/C,gFAAgF;IAChE,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,wBAAwB;CAEtD;AAED,iFAAiF;AACjF,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI,mBAAmB,EAAE,CAElG;AAED,iFAAiF;AACjF,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI,mBAAmB,EAAE,CAElG;AAcD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAYpG"}