@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.
- package/README.md +150 -0
- package/dist/GenericDatabaseProvider.d.ts +329 -41
- package/dist/GenericDatabaseProvider.d.ts.map +1 -1
- package/dist/GenericDatabaseProvider.js +864 -238
- 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 +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- 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/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -14
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { AnalyzePagingShape, OutputOrderBy, SqlDocument } from '@memberjunction/sql-parser';
|
|
2
|
+
/** Reads the layout of one statement, from its parsed form when it can be read completely, else from tokens. */
|
|
3
|
+
export function ReadPagingLayout(statement, dialect) {
|
|
4
|
+
const parsed = parseStatement(statement, dialect);
|
|
5
|
+
return parsed === null ? layoutFromTokens(statement, dialect) : layoutFromDocument(statement, parsed, dialect);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The ORDER BY to put outside a derived table that wraps the statement: the statement's ORDER BY
|
|
9
|
+
* with every column qualifier dropped, since the derived table's alias replaces the inner ones.
|
|
10
|
+
* Qualifiers are read as identifier paths, so `a . Name` and `[a] /*c*\/ . [Name]` lose theirs like
|
|
11
|
+
* `a.Name`; a schema-qualified function name keeps its schema. `null` when the statement was read
|
|
12
|
+
* from tokens or has no ORDER BY.
|
|
13
|
+
*/
|
|
14
|
+
export function OuterOrderByText(layout) {
|
|
15
|
+
const parsed = layout.Parsed;
|
|
16
|
+
if (parsed === null || parsed.Body.OrderBy === null)
|
|
17
|
+
return null;
|
|
18
|
+
return OutputOrderBy(parsed.Document, parsed.Body.OrderBy).trim();
|
|
19
|
+
}
|
|
20
|
+
function parseStatement(statement, dialect) {
|
|
21
|
+
const document = SqlDocument.Parse(statement, dialect);
|
|
22
|
+
if (!document.IsComplete || document.HasStackedStatements().Value)
|
|
23
|
+
return null;
|
|
24
|
+
const first = document.Statements[0];
|
|
25
|
+
if (first === undefined || first.StatementKind !== 'Select' || first.Body.Kind === 'Unknown')
|
|
26
|
+
return null;
|
|
27
|
+
if (first.Tail.length > 0)
|
|
28
|
+
return null;
|
|
29
|
+
return { Document: document, Statement: first, Body: first.Body };
|
|
30
|
+
}
|
|
31
|
+
function layoutFromTokens(statement, dialect) {
|
|
32
|
+
const shape = AnalyzePagingShape(statement, dialect);
|
|
33
|
+
const hint = dialect.Grammar.QueryHintKeyword;
|
|
34
|
+
const tail = statement.substring(shape.TailStart).trim().toUpperCase();
|
|
35
|
+
return {
|
|
36
|
+
Statement: statement,
|
|
37
|
+
CTEDefinitions: shape.CTEs ? shape.CTEs.Definitions.map(d => d.Text) : [],
|
|
38
|
+
Recursive: shape.CTEs?.Recursive ?? false,
|
|
39
|
+
MainStart: shape.MainStart,
|
|
40
|
+
TailStart: shape.TailStart,
|
|
41
|
+
TailIsQueryHint: hint !== null && new RegExp(`^${hint.toUpperCase()}\\b`).test(tail),
|
|
42
|
+
OwnCaps: shape.OwnCaps,
|
|
43
|
+
OrderBy: shape.OrderBy,
|
|
44
|
+
IsSetOperation: shape.IsSetOperation,
|
|
45
|
+
IsDistinct: shape.IsDistinct,
|
|
46
|
+
ReturnsDocument: shape.ReturnsDocument,
|
|
47
|
+
SelectListStart: shape.SelectListStart,
|
|
48
|
+
Parsed: null,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function layoutFromDocument(statement, parsed, dialect) {
|
|
52
|
+
const { Document: doc, Statement: node, Body: body } = parsed;
|
|
53
|
+
const tail = tailClause(body);
|
|
54
|
+
const tailStart = tail?.Start ?? statement.length;
|
|
55
|
+
const clauseCap = clauseCapOf(body, statement, tailStart);
|
|
56
|
+
const orderEnd = clauseCap?.Start ?? tailStart;
|
|
57
|
+
return {
|
|
58
|
+
Statement: statement,
|
|
59
|
+
CTEDefinitions: (node.With?.CTEs ?? []).map(cte => doc.Text(cte)),
|
|
60
|
+
Recursive: node.With?.Recursive ?? false,
|
|
61
|
+
MainStart: body.Span.Start,
|
|
62
|
+
TailStart: tailStart,
|
|
63
|
+
TailIsQueryHint: tail?.IsHint === true && dialect.Grammar.QueryHintKeyword !== null,
|
|
64
|
+
OwnCaps: [...topCaps(body), ...(clauseCap ? [clauseCap] : [])],
|
|
65
|
+
OrderBy: body.OrderBy === null ? null : { Start: body.OrderBy.Span.Start, End: trimmedEnd(statement, orderEnd) },
|
|
66
|
+
IsSetOperation: body.Kind === 'SetOperation',
|
|
67
|
+
IsDistinct: selectBlocks(body).some(s => s.Distinct !== null && s.Distinct.Form !== 'All'),
|
|
68
|
+
ReturnsDocument: body.For?.Form === 'Json' ? 'json' : body.For?.Form === 'Xml' ? 'xml' : null,
|
|
69
|
+
SelectListStart: body.Kind === 'Select' ? selectListStart(body) : null,
|
|
70
|
+
Parsed: parsed,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** The clause that must stay last: the query-hint clause, or a row-locking FOR clause. */
|
|
74
|
+
function tailClause(body) {
|
|
75
|
+
if (body.Option !== null)
|
|
76
|
+
return { Start: body.Option.Span.Start, IsHint: true };
|
|
77
|
+
const lock = body.For !== null && ['Update', 'Share', 'NoKeyUpdate', 'KeyShare'].includes(body.For.Form);
|
|
78
|
+
return lock && body.For !== null ? { Start: body.For.Span.Start, IsHint: false } : null;
|
|
79
|
+
}
|
|
80
|
+
/** The select blocks at the top level: the body itself, or every branch of a set operation not in parentheses. */
|
|
81
|
+
function selectBlocks(body) {
|
|
82
|
+
if (body.Kind === 'Select')
|
|
83
|
+
return [body];
|
|
84
|
+
if (body.Kind === 'SetOperation')
|
|
85
|
+
return [...selectBlocks(body.Left), ...selectBlocks(body.Right)];
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
/** Every top-level select block's `TOP`, as a cap. */
|
|
89
|
+
function topCaps(body) {
|
|
90
|
+
return selectBlocks(body).flatMap(select => {
|
|
91
|
+
const top = select.Top;
|
|
92
|
+
if (top === null)
|
|
93
|
+
return [];
|
|
94
|
+
const rows = integerOf(top.Value.Tokens());
|
|
95
|
+
const numeric = rows !== null && !top.Percent && !top.WithTies;
|
|
96
|
+
return [{ Form: 'top', Rows: rows, Skip: 0, Numeric: numeric, Start: top.Span.Start, End: top.Span.End }];
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/** The trailing LIMIT / OFFSET / FETCH clauses as one cap, from the first of them to the last clause. */
|
|
100
|
+
function clauseCapOf(body, statement, tailStart) {
|
|
101
|
+
const parts = [body.Limit, body.Offset, body.Fetch].filter(p => p !== null);
|
|
102
|
+
if (parts.length === 0)
|
|
103
|
+
return null;
|
|
104
|
+
const start = Math.min(...parts.map(p => p.Span.Start));
|
|
105
|
+
let rows = null;
|
|
106
|
+
let skip = 0;
|
|
107
|
+
let numeric = true;
|
|
108
|
+
if (body.Limit !== null) {
|
|
109
|
+
rows = body.Limit.Value === null ? null : integerOf(body.Limit.Value.Tokens());
|
|
110
|
+
if (body.Limit.Value !== null && rows === null)
|
|
111
|
+
numeric = false;
|
|
112
|
+
const leading = body.Limit.LeadingOffset === null ? 0 : integerOf(body.Limit.LeadingOffset.Tokens());
|
|
113
|
+
if (leading === null)
|
|
114
|
+
numeric = false;
|
|
115
|
+
else
|
|
116
|
+
skip = leading;
|
|
117
|
+
}
|
|
118
|
+
if (body.Offset !== null) {
|
|
119
|
+
const value = integerOf(body.Offset.Value.Tokens());
|
|
120
|
+
if (value === null)
|
|
121
|
+
numeric = false;
|
|
122
|
+
else
|
|
123
|
+
skip = value;
|
|
124
|
+
}
|
|
125
|
+
if (body.Fetch !== null) {
|
|
126
|
+
rows = body.Fetch.Value === null ? 1 : integerOf(body.Fetch.Value.Tokens());
|
|
127
|
+
if (rows === null || body.Fetch.Percent || body.Fetch.WithTies)
|
|
128
|
+
numeric = false;
|
|
129
|
+
}
|
|
130
|
+
return { Form: 'clause', Rows: rows, Skip: skip, Numeric: numeric, Start: start, End: trimmedEnd(statement, tailStart) };
|
|
131
|
+
}
|
|
132
|
+
/** Just after `SELECT`, or after its `ALL` / `DISTINCT` modifier. */
|
|
133
|
+
function selectListStart(select) {
|
|
134
|
+
if (select.Distinct !== null && select.Distinct.Form !== 'DistinctOn')
|
|
135
|
+
return select.Distinct.Span.End;
|
|
136
|
+
return select.Span.Start + 'SELECT'.length;
|
|
137
|
+
}
|
|
138
|
+
function integerOf(tokens) {
|
|
139
|
+
return tokens.length === 1 && tokens[0].Kind === 'Number' && /^\d+$/.test(tokens[0].Text) ? Number(tokens[0].Text) : null;
|
|
140
|
+
}
|
|
141
|
+
/** `end`, moved back over trailing whitespace. */
|
|
142
|
+
function trimmedEnd(statement, end) {
|
|
143
|
+
let e = end;
|
|
144
|
+
while (e > 0 && /\s/.test(statement[e - 1]))
|
|
145
|
+
e--;
|
|
146
|
+
return e;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Functions whose presence in a select list changes how many rows the select returns: aggregates
|
|
150
|
+
* (one row for a select with no GROUP BY) and set-returning functions (several rows per input
|
|
151
|
+
* row). A select list calling any of them is never replaced for counting.
|
|
152
|
+
*/
|
|
153
|
+
const ROW_COUNT_FUNCTIONS = new Set([
|
|
154
|
+
'COUNT', 'COUNT_BIG', 'SUM', 'AVG', 'MIN', 'MAX', 'STDEV', 'STDEVP', 'STDDEV', 'STDDEV_POP', 'STDDEV_SAMP',
|
|
155
|
+
'VAR', 'VARP', 'VARIANCE', 'VAR_POP', 'VAR_SAMP', 'STRING_AGG', 'CHECKSUM_AGG', 'GROUPING', 'GROUPING_ID',
|
|
156
|
+
'APPROX_COUNT_DISTINCT', 'APPROX_PERCENTILE_CONT', 'APPROX_PERCENTILE_DISC', 'PERCENTILE_CONT', 'PERCENTILE_DISC',
|
|
157
|
+
'MODE', 'ARRAY_AGG', 'JSON_AGG', 'JSONB_AGG', 'JSON_OBJECT_AGG', 'JSONB_OBJECT_AGG', 'JSON_OBJECTAGG', 'JSON_ARRAYAGG',
|
|
158
|
+
'XMLAGG', 'BOOL_AND', 'BOOL_OR', 'EVERY', 'BIT_AND', 'BIT_OR', 'BIT_XOR', 'LISTAGG', 'GROUP_CONCAT', 'CORR',
|
|
159
|
+
'COVAR_POP', 'COVAR_SAMP', 'REGR_SLOPE', 'REGR_INTERCEPT', 'REGR_COUNT', 'REGR_R2', 'REGR_AVGX', 'REGR_AVGY',
|
|
160
|
+
'REGR_SXX', 'REGR_SYY', 'REGR_SXY', 'RANGE_AGG', 'RANGE_INTERSECT_AGG',
|
|
161
|
+
'GENERATE_SERIES', 'GENERATE_SUBSCRIPTS', 'UNNEST', 'REGEXP_MATCHES', 'REGEXP_SPLIT_TO_TABLE', 'STRING_TO_TABLE',
|
|
162
|
+
'JSON_ARRAY_ELEMENTS', 'JSON_ARRAY_ELEMENTS_TEXT', 'JSONB_ARRAY_ELEMENTS', 'JSONB_ARRAY_ELEMENTS_TEXT',
|
|
163
|
+
'JSON_EACH', 'JSON_EACH_TEXT', 'JSONB_EACH', 'JSONB_EACH_TEXT', 'JSON_OBJECT_KEYS', 'JSONB_OBJECT_KEYS',
|
|
164
|
+
'JSON_POPULATE_RECORDSET', 'JSONB_POPULATE_RECORDSET', 'JSON_TO_RECORDSET', 'JSONB_TO_RECORDSET',
|
|
165
|
+
'JSONB_PATH_QUERY', 'FLATTEN', 'EXPLODE', 'POSEXPLODE', 'INLINE',
|
|
166
|
+
]);
|
|
167
|
+
/**
|
|
168
|
+
* Whether a statement can be counted with its select list replaced by a constant: it was read
|
|
169
|
+
* completely and is one select block with no DISTINCT, GROUP BY, HAVING, WINDOW, QUALIFY, FOR
|
|
170
|
+
* clause or cap of its own, and its select list calls no aggregate or set-returning function.
|
|
171
|
+
* A user-defined aggregate is not recognised by name; such a select list would be counted per
|
|
172
|
+
* input row.
|
|
173
|
+
*/
|
|
174
|
+
export function CountBodyCanSelectConstant(layout) {
|
|
175
|
+
const body = layout.Parsed?.Body;
|
|
176
|
+
if (body === undefined || body.Kind !== 'Select' || layout.OwnCaps.length > 0)
|
|
177
|
+
return false;
|
|
178
|
+
if (body.Distinct !== null && body.Distinct.Form !== 'All')
|
|
179
|
+
return false;
|
|
180
|
+
if (body.GroupBy !== null || body.Having !== null || body.Window !== null || body.Qualify !== null)
|
|
181
|
+
return false;
|
|
182
|
+
if (body.For !== null || body.Into !== null || body.Unrecognized.length > 0)
|
|
183
|
+
return false;
|
|
184
|
+
return !body.SelectList.some(item => item.Expression.FunctionCalls().some(call => isRowCountFunction(call.Name.Parts)));
|
|
185
|
+
}
|
|
186
|
+
function isRowCountFunction(parts) {
|
|
187
|
+
const last = parts[parts.length - 1];
|
|
188
|
+
return last !== undefined && ROW_COUNT_FUNCTIONS.has(last.Value.toUpperCase());
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=pagingLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagingLayout.js","sourceRoot":"","sources":["../src/pagingLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AA+C5F,gHAAgH;AAChH,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,OAAmB;IACnE,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAClD,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACnH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAoB;IACjD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACjE,OAAO,aAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,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I,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5H,CAAC;AAED,SAAS,kBAAkB,CAAC,KAA4C;IACpE,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrC,OAAO,IAAI,KAAK,SAAS,IAAI,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
import { DatabasePlatform, UserInfo, QueryDependencySpec } from "@memberjunction/core";
|
|
2
|
-
|
|
3
|
-
* Minimal contract for queries flowing through the composition engine.
|
|
4
|
-
* `MJQueryEntityExtended` satisfies this structurally; synthetic inline
|
|
5
|
-
* dependency queries satisfy it via a plain-object literal with stubs.
|
|
6
|
-
*/
|
|
7
|
-
export interface IComposableQuery {
|
|
8
|
-
ID: string;
|
|
9
|
-
Name: string;
|
|
10
|
-
SQL: string | null;
|
|
11
|
-
UsesTemplate: boolean | null;
|
|
12
|
-
Reusable: boolean | null;
|
|
13
|
-
Status: string | null;
|
|
14
|
-
IsApproved: boolean;
|
|
15
|
-
UserCanRun(user: UserInfo, _visited?: Set<string>): {
|
|
16
|
-
canRun: boolean;
|
|
17
|
-
deniedEntities: string[];
|
|
18
|
-
};
|
|
19
|
-
GetPlatformSQL(platform: DatabasePlatform): string;
|
|
20
|
-
}
|
|
2
|
+
export type { IComposableQuery } from "./composition/compositionTypes.js";
|
|
21
3
|
/**
|
|
22
4
|
* Metadata about a single CTE generated during composition resolution.
|
|
23
5
|
*/
|
|
@@ -79,17 +61,13 @@ interface ParsedParameter {
|
|
|
79
61
|
PassThroughName: string | null;
|
|
80
62
|
}
|
|
81
63
|
/**
|
|
82
|
-
* QueryCompositionEngine resolves {{query:"CategoryPath/QueryName(params)"}}
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* - Recursive resolution of nested compositions
|
|
86
|
-
* - Cycle detection via an in-progress set
|
|
87
|
-
* - Parameter modes: static literals and pass-through from outer query
|
|
88
|
-
* - Deduplication of identical query+params references
|
|
89
|
-
* - Platform-aware SQL resolution via QueryInfo.GetPlatformSQL()
|
|
64
|
+
* QueryCompositionEngine reads and resolves `{{query:"CategoryPath/QueryName(params)"}}`
|
|
65
|
+
* composition tokens.
|
|
90
66
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
67
|
+
* Composition itself is render-then-compose (see `RenderPipeline.Run`): each composed query is
|
|
68
|
+
* rendered with its own arguments and the plain SQL is assembled from the rendered parts. This
|
|
69
|
+
* class keeps the token-reading methods and {@link ResolveComposition}, which composes SQL whose
|
|
70
|
+
* compositions take static arguments only, without rendering the outer SQL.
|
|
93
71
|
*/
|
|
94
72
|
export declare class QueryCompositionEngine {
|
|
95
73
|
/**
|
|
@@ -105,8 +83,6 @@ export declare class QueryCompositionEngine {
|
|
|
105
83
|
* at the same position in the original.
|
|
106
84
|
*/
|
|
107
85
|
private maskNonSQL;
|
|
108
|
-
/** Replaces the first occurrence of `token` that is real SQL, leaving comments and literals as written. */
|
|
109
|
-
private replaceToken;
|
|
110
86
|
/**
|
|
111
87
|
* Parses all {{query:"..."}} tokens from SQL without resolving them.
|
|
112
88
|
* Useful for dependency extraction during the save pipeline.
|
|
@@ -121,201 +97,25 @@ export declare class QueryCompositionEngine {
|
|
|
121
97
|
*/
|
|
122
98
|
ParseCompositionTokens(sql: string, platform?: DatabasePlatform): ParsedCompositionToken[];
|
|
123
99
|
/**
|
|
124
|
-
* Resolves
|
|
100
|
+
* Resolves the composition tokens of `sql` into CTEs without rendering `sql` itself: each
|
|
101
|
+
* composed query is rendered with the static arguments its token passes (its own compositions
|
|
102
|
+
* render as usual) and the result is assembled into one statement. The outer SQL's own template
|
|
103
|
+
* tags, if any, stay as written. References resolve by full category path and name only.
|
|
125
104
|
*
|
|
126
105
|
* @param sql - The SQL containing composition tokens
|
|
127
106
|
* @param platform - Target database platform for SQL resolution
|
|
128
107
|
* @param contextUser - User context for permission checks on referenced queries
|
|
129
|
-
* @param
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* Inline dependencies skip governance validation
|
|
133
|
-
*
|
|
134
|
-
* @
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
private resolveTokensRecursive;
|
|
141
|
-
/**
|
|
142
|
-
* Looks up a query by category path + name, checking inline dependencies first,
|
|
143
|
-
* then falling back to the metadata provider.
|
|
144
|
-
*
|
|
145
|
-
* For inline dependencies, creates a synthetic QueryInfo with the SQL and flags set
|
|
146
|
-
* appropriately. Inline queries skip governance validation (Reusable, IsApproved, etc.)
|
|
147
|
-
* since they are inherently authorized by the caller.
|
|
148
|
-
*/
|
|
149
|
-
private lookupQueryWithInline;
|
|
150
|
-
/**
|
|
151
|
-
* Finds a matching inline dependency spec for the given token.
|
|
152
|
-
*/
|
|
153
|
-
private findInlineDependency;
|
|
154
|
-
/**
|
|
155
|
-
* Builds a synthetic IComposableQuery from an inline dependency spec.
|
|
156
|
-
* Returns a plain object (not a BaseEntity) since we cannot construct
|
|
157
|
-
* MJQueryEntityExtended directly. Inline queries skip governance
|
|
158
|
-
* validation, so only the fields needed for composition resolution
|
|
159
|
-
* (ID, Name, SQL, UsesTemplate, GetPlatformSQL) are meaningful.
|
|
160
|
-
*/
|
|
161
|
-
private buildSyntheticQuery;
|
|
162
|
-
/**
|
|
163
|
-
* Looks up a query by category path + name from QueryEngine.
|
|
164
|
-
*/
|
|
165
|
-
private lookupQueryFromMetadata;
|
|
166
|
-
/**
|
|
167
|
-
* Validates that a referenced query is eligible for composition.
|
|
168
|
-
*/
|
|
169
|
-
private validateQueryComposable;
|
|
170
|
-
/**
|
|
171
|
-
* Resolves parameter values for a composition reference.
|
|
172
|
-
* Static values are used directly; pass-through values are looked up from outer params.
|
|
173
|
-
*/
|
|
174
|
-
private resolveParameters;
|
|
175
|
-
/**
|
|
176
|
-
* Substitutes resolved parameter values into a query's SQL.
|
|
177
|
-
* - Static values: replaces {{paramName}} with 'value'
|
|
178
|
-
* - Pass-through values: renames {{paramName}} to {{outerParamName}} so
|
|
179
|
-
* the downstream Nunjucks processor can resolve it from the outer query's parameters.
|
|
180
|
-
*/
|
|
181
|
-
/**
|
|
182
|
-
* Substitutes resolved parameter values into a query's SQL using the SQLParser's
|
|
183
|
-
* MJLexer-based template manipulation methods.
|
|
184
|
-
*
|
|
185
|
-
* - Pass-through values: renames the inner variable to the outer variable name,
|
|
186
|
-
* preserving any Nunjucks filter chain (e.g., `{{ lookbackDays | sqlNumber }}` → `{{ numDays | sqlNumber }}`)
|
|
187
|
-
* - Static values: replaces the entire template expression (including filters) with a literal value
|
|
188
|
-
*/
|
|
189
|
-
private substituteStaticParams;
|
|
190
|
-
/**
|
|
191
|
-
* Builds a deduplication key for a CTE based on query ID and sorted parameter values.
|
|
192
|
-
*/
|
|
193
|
-
private buildDeduplicationKey;
|
|
194
|
-
/**
|
|
195
|
-
* Generates a SQL-safe CTE name from the query name + short hash for uniqueness.
|
|
196
|
-
*/
|
|
197
|
-
private generateCTEName;
|
|
198
|
-
/**
|
|
199
|
-
* Resolves a DatabasePlatform string to the corresponding SQLDialect instance.
|
|
200
|
-
*/
|
|
108
|
+
* @param _outerParams - Not used: the outer SQL is not rendered, so its compositions take
|
|
109
|
+
* static arguments only. Kept for the signature.
|
|
110
|
+
* @param inlineDependencies - Optional inline dependency specs for transient query testing,
|
|
111
|
+
* searched before the saved queries. Inline dependencies skip governance validation
|
|
112
|
+
* (Reusable, IsApproved, UserCanRun).
|
|
113
|
+
* @returns CompositionResult with the composed SQL and provenance metadata
|
|
114
|
+
* @throws Error if a referenced query is not found, not composable, creates a cycle, or a
|
|
115
|
+
* composition of `sql` passes a value of the outer query (pass-through)
|
|
116
|
+
*/
|
|
117
|
+
ResolveComposition(sql: string, platform: DatabasePlatform, contextUser: UserInfo, _outerParams?: Record<string, string>, inlineDependencies?: QueryDependencySpec[]): CompositionResult;
|
|
118
|
+
/** The dialect of a platform. */
|
|
201
119
|
private getDialect;
|
|
202
|
-
/**
|
|
203
|
-
* Simple string hash for generating short, deterministic suffixes.
|
|
204
|
-
*/
|
|
205
|
-
private simpleHash;
|
|
206
|
-
/**
|
|
207
|
-
* Assembles CTE entries into a WITH clause prepended to the main SQL.
|
|
208
|
-
*
|
|
209
|
-
* Handles the case where a dependency query's SQL itself contains a WITH clause
|
|
210
|
-
* (inner CTEs). SQL does not allow nested WITH clauses, so inner CTEs are "hoisted"
|
|
211
|
-
* out as sibling CTE definitions preceding the dependency's own CTE.
|
|
212
|
-
*
|
|
213
|
-
* Cross-dep CTE name collisions: when two different dependencies each declare
|
|
214
|
-
* an inner CTE with the same name (e.g. both declare `PoolNameBridge`), the
|
|
215
|
-
* naive concatenation produces a duplicate CTE error from SQL Server. We
|
|
216
|
-
* track allocated names across the entire WITH and rename colliding inner
|
|
217
|
-
* CTEs (and rewrite intra-dep references to the renamed CTE) so the assembled
|
|
218
|
-
* SQL is valid. See Skip-Brain Bug C in
|
|
219
|
-
* `__tests__/skip-failure-regressions.test.ts` and `SKIP-QUERY-RENDERING-BUGS.md`.
|
|
220
|
-
*/
|
|
221
|
-
private assembleCTEs;
|
|
222
|
-
/**
|
|
223
|
-
* Takes a statement's trailing query-hint clause off ({@link SQLDialect.QueryHintKeyword},
|
|
224
|
-
* `OPTION (…)` on SQL Server), returning the hints in it. A CTE body cannot carry query hints;
|
|
225
|
-
* they belong to the statement the dependency is composed into. A dialect without a hint
|
|
226
|
-
* clause leaves the statement as it is.
|
|
227
|
-
*/
|
|
228
|
-
private splitQueryHints;
|
|
229
|
-
/**
|
|
230
|
-
* Adds query hints to a statement: into its own hint clause when it has one, otherwise as a
|
|
231
|
-
* new clause (`OPTION (…)` on SQL Server) after its last token, ahead of any trailing
|
|
232
|
-
* semicolon or comment. A hint already present, compared ignoring case and spacing, is not
|
|
233
|
-
* added twice. Hints only come from a dialect with a hint clause, so one is always named.
|
|
234
|
-
*/
|
|
235
|
-
private appendQueryHints;
|
|
236
|
-
/**
|
|
237
|
-
* Finds a statement's top-level trailing query-hint clause (`OPTION (…)` on SQL Server): where
|
|
238
|
-
* the keyword starts, where the list inside the parentheses starts and ends, and the hints in
|
|
239
|
-
* it split at top-level commas. `null` when the dialect has no hint clause or there is none.
|
|
240
|
-
*/
|
|
241
|
-
private findOptionList;
|
|
242
|
-
/** Hints with repeats removed, comparing case- and spacing-insensitively; first spelling kept. */
|
|
243
|
-
private distinctHints;
|
|
244
|
-
/**
|
|
245
|
-
* A dependency's statement without the semicolons before or after it (`;WITH …`, `… ;`),
|
|
246
|
-
* which a CTE body cannot hold.
|
|
247
|
-
*/
|
|
248
|
-
private withoutStatementSemicolons;
|
|
249
|
-
/**
|
|
250
|
-
* Validates that no CTE body still contains an illegal top-level ORDER BY
|
|
251
|
-
* after stripping. Throws a diagnostic error with the dep name, category
|
|
252
|
-
* path, and specific reason — replacing the cryptic SQL Server error
|
|
253
|
-
* "The ORDER BY clause is invalid in views, inline functions...".
|
|
254
|
-
*/
|
|
255
|
-
private validateCTEBodies;
|
|
256
|
-
/**
|
|
257
|
-
* Strips the surrounding bracket / quote characters from a CTE name so we
|
|
258
|
-
* can compare names case-insensitively across quoting styles. `[Foo]`,
|
|
259
|
-
* `"Foo"`, and bare `Foo` all canonicalize to `Foo`.
|
|
260
|
-
*/
|
|
261
|
-
private canonicalCTEName;
|
|
262
|
-
/**
|
|
263
|
-
* Deconflicts inner CTE names using a SymbolTable for name allocation.
|
|
264
|
-
* The SymbolTable guarantees uniqueness at registration time — name
|
|
265
|
-
* collisions become impossible by construction.
|
|
266
|
-
*
|
|
267
|
-
* Reference rewriting uses word-boundary regex over raw SQL. It does
|
|
268
|
-
* NOT skip string literals or comments — inner-CTE names are unlikely
|
|
269
|
-
* to appear as quoted text or column aliases in practice.
|
|
270
|
-
*/
|
|
271
|
-
private deconflictInnerCTEsViaSymbolTable;
|
|
272
|
-
/**
|
|
273
|
-
* Replaces every reference to `oldName` (bare, [bracketed], or "quoted")
|
|
274
|
-
* with bare `newName`. Case-insensitive. Word-boundary matched so
|
|
275
|
-
* `MyAcronymBridge` is not affected by renaming `AcronymBridge`.
|
|
276
|
-
*
|
|
277
|
-
* Does not attempt to skip string literals or comments — see the note on
|
|
278
|
-
* `deconflictInnerCTEsViaSymbolTable` for the trade-off rationale.
|
|
279
|
-
*/
|
|
280
|
-
private renameSQLIdentifier;
|
|
281
|
-
/**
|
|
282
|
-
* Extracts inner CTE definitions from SQL that starts with a WITH clause, and whether the
|
|
283
|
-
* clause is `WITH RECURSIVE`.
|
|
284
|
-
*
|
|
285
|
-
* Splits by position ({@link SplitLeadingCTEs}) so each definition is kept as written; when
|
|
286
|
-
* that cannot read the clause, falls back to {@link SQLParser.ExtractCTEs}.
|
|
287
|
-
*
|
|
288
|
-
* @param sql SQL starting with a WITH clause
|
|
289
|
-
* @param dialect SQL dialect for AST parsing
|
|
290
|
-
*/
|
|
291
|
-
private hoistInnerCTEs;
|
|
292
|
-
/**
|
|
293
|
-
* Strips a trailing ORDER BY clause from SQL that will be wrapped in a CTE.
|
|
294
|
-
*
|
|
295
|
-
* SQL Server disallows ORDER BY inside CTEs unless TOP, OFFSET, or FOR XML is present.
|
|
296
|
-
* PostgreSQL allows ORDER BY in CTEs, so no stripping is needed there.
|
|
297
|
-
*
|
|
298
|
-
* Delegates to the shared `AnalyzeTopLevelOrderBy` utility (orderByAnalyzer.ts)
|
|
299
|
-
* which implements a 2-tier strategy:
|
|
300
|
-
* Tier 1: AST parsing (with Nunjucks preprocessing if needed)
|
|
301
|
-
* Tier 2: MJLexer scanner with carried lexical state across token boundaries
|
|
302
|
-
*
|
|
303
|
-
* When both tiers fail to strip, falls back to OFFSET 0 ROWS injection as
|
|
304
|
-
* a last resort (semantically neutral but makes ORDER BY legal in CTEs).
|
|
305
|
-
*/
|
|
306
|
-
private stripTrailingOrderBy;
|
|
307
|
-
/**
|
|
308
|
-
* Injects OFFSET 0 ROWS after the last top-level ORDER BY clause to make it
|
|
309
|
-
* legal in a CTE without changing the result set.
|
|
310
|
-
*/
|
|
311
|
-
private injectOffset0Rows;
|
|
312
|
-
/**
|
|
313
|
-
* Strips SQL comments from the input string so that composition tokens
|
|
314
|
-
* inside comments are not treated as real references.
|
|
315
|
-
* Handles both single-line (-- ...) and multi-line block comments.
|
|
316
|
-
* Preserves string literals (single-quoted) to avoid stripping inside them.
|
|
317
|
-
*/
|
|
318
|
-
private stripSQLComments;
|
|
319
120
|
}
|
|
320
|
-
export {};
|
|
321
121
|
//# sourceMappingURL=queryCompositionEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryCompositionEngine.d.ts","sourceRoot":"","sources":["../src/queryCompositionEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queryCompositionEngine.d.ts","sourceRoot":"","sources":["../src/queryCompositionEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAMlH,YAAY,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;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