@memberjunction/generic-database-provider 6.2.0-edge.6 → 6.2.0-edge.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -0
- package/dist/GenericDatabaseProvider.d.ts +244 -39
- package/dist/GenericDatabaseProvider.d.ts.map +1 -1
- package/dist/GenericDatabaseProvider.js +676 -233
- package/dist/GenericDatabaseProvider.js.map +1 -1
- package/dist/clientClauseScreen.d.ts +16 -72
- package/dist/clientClauseScreen.d.ts.map +1 -1
- package/dist/clientClauseScreen.js +34 -278
- package/dist/clientClauseScreen.js.map +1 -1
- package/dist/composition/compositionAssembler.d.ts +33 -0
- package/dist/composition/compositionAssembler.d.ts.map +1 -0
- package/dist/composition/compositionAssembler.js +270 -0
- package/dist/composition/compositionAssembler.js.map +1 -0
- package/dist/composition/compositionInfo.d.ts +7 -0
- package/dist/composition/compositionInfo.d.ts.map +1 -0
- package/dist/composition/compositionInfo.js +31 -0
- package/dist/composition/compositionInfo.js.map +1 -0
- package/dist/composition/compositionLookup.d.ts +44 -0
- package/dist/composition/compositionLookup.d.ts.map +1 -0
- package/dist/composition/compositionLookup.js +122 -0
- package/dist/composition/compositionLookup.js.map +1 -0
- package/dist/composition/compositionRender.d.ts +136 -0
- package/dist/composition/compositionRender.d.ts.map +1 -0
- package/dist/composition/compositionRender.js +264 -0
- package/dist/composition/compositionRender.js.map +1 -0
- package/dist/composition/compositionTypes.d.ts +40 -0
- package/dist/composition/compositionTypes.d.ts.map +1 -0
- package/dist/composition/compositionTypes.js +2 -0
- package/dist/composition/compositionTypes.js.map +1 -0
- package/dist/composition/quotedTagRefusal.d.ts +44 -0
- package/dist/composition/quotedTagRefusal.d.ts.map +1 -0
- package/dist/composition/quotedTagRefusal.js +132 -0
- package/dist/composition/quotedTagRefusal.js.map +1 -0
- package/dist/composition/renderSteps.d.ts +16 -0
- package/dist/composition/renderSteps.d.ts.map +1 -0
- package/dist/composition/renderSteps.js +42 -0
- package/dist/composition/renderSteps.js.map +1 -0
- package/dist/composition/safetyGate.d.ts +46 -0
- package/dist/composition/safetyGate.d.ts.map +1 -0
- package/dist/composition/safetyGate.js +61 -0
- package/dist/composition/safetyGate.js.map +1 -0
- package/dist/composition/templateUnit.d.ts +95 -0
- package/dist/composition/templateUnit.d.ts.map +1 -0
- package/dist/composition/templateUnit.js +189 -0
- package/dist/composition/templateUnit.js.map +1 -0
- package/dist/describeStatement.d.ts +51 -0
- package/dist/describeStatement.d.ts.map +1 -0
- package/dist/describeStatement.js +19 -0
- package/dist/describeStatement.js.map +1 -0
- package/dist/fieldSecurity/projectionStars.d.ts +15 -0
- package/dist/fieldSecurity/projectionStars.d.ts.map +1 -0
- package/dist/fieldSecurity/projectionStars.js +116 -0
- package/dist/fieldSecurity/projectionStars.js.map +1 -0
- package/dist/fieldSecurity/queryColumnSecurity.d.ts +35 -0
- package/dist/fieldSecurity/queryColumnSecurity.d.ts.map +1 -0
- package/dist/fieldSecurity/queryColumnSecurity.js +84 -0
- package/dist/fieldSecurity/queryColumnSecurity.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/pagingLayout.d.ts +68 -0
- package/dist/pagingLayout.d.ts.map +1 -0
- package/dist/pagingLayout.js +190 -0
- package/dist/pagingLayout.js.map +1 -0
- package/dist/queryCompositionEngine.d.ts +22 -222
- package/dist/queryCompositionEngine.d.ts.map +1 -1
- package/dist/queryCompositionEngine.js +35 -729
- package/dist/queryCompositionEngine.js.map +1 -1
- package/dist/queryPagingEngine.d.ts +26 -5
- package/dist/queryPagingEngine.d.ts.map +1 -1
- package/dist/queryPagingEngine.js +51 -15
- package/dist/queryPagingEngine.js.map +1 -1
- package/dist/renderPipeline.d.ts +77 -85
- package/dist/renderPipeline.d.ts.map +1 -1
- package/dist/renderPipeline.js +70 -220
- package/dist/renderPipeline.js.map +1 -1
- package/dist/statementMemo.d.ts +29 -0
- package/dist/statementMemo.d.ts.map +1 -0
- package/dist/statementMemo.js +61 -0
- package/dist/statementMemo.js.map +1 -0
- package/dist/typedQueryParameter.d.ts +55 -0
- package/dist/typedQueryParameter.d.ts.map +1 -0
- package/dist/typedQueryParameter.js +122 -0
- package/dist/typedQueryParameter.js.map +1 -0
- package/package.json +14 -14
package/dist/renderPipeline.js
CHANGED
|
@@ -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 {
|
|
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
|
|
14
|
-
*
|
|
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** (
|
|
17
|
-
* 1. **
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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
|
|
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
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let currentSQL =
|
|
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 (
|
|
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
|
-
|
|
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:
|
|
95
|
-
ContextValues:
|
|
96
|
-
HasCompositions:
|
|
97
|
-
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
|
171
|
-
*
|
|
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
|
-
*
|
|
174
|
-
*
|
|
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
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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;
|
|
1
|
+
{"version":3,"file":"renderPipeline.js","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAmD,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE7H,OAA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AC,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,C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AAI,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"}
|