@memberjunction/generic-database-provider 6.2.0-edge.5 → 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 +165 -1
- package/dist/GenericDatabaseProvider.d.ts +599 -69
- package/dist/GenericDatabaseProvider.d.ts.map +1 -1
- package/dist/GenericDatabaseProvider.js +2055 -403
- package/dist/GenericDatabaseProvider.js.map +1 -1
- package/dist/SqlLogger.d.ts +26 -0
- package/dist/SqlLogger.d.ts.map +1 -1
- package/dist/SqlLogger.js +77 -20
- package/dist/SqlLogger.js.map +1 -1
- package/dist/clientClauseScreen.d.ts +44 -75
- package/dist/clientClauseScreen.d.ts.map +1 -1
- package/dist/clientClauseScreen.js +129 -267
- 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 +9 -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/recordChangeSnapshot.d.ts +43 -0
- package/dist/recordChangeSnapshot.d.ts.map +1 -0
- package/dist/recordChangeSnapshot.js +85 -0
- package/dist/recordChangeSnapshot.js.map +1 -0
- package/dist/renderPipeline.d.ts +91 -72
- package/dist/renderPipeline.d.ts.map +1 -1
- package/dist/renderPipeline.js +71 -179
- 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/systemUserFieldAccess.d.ts +16 -1
- package/dist/systemUserFieldAccess.d.ts.map +1 -1
- package/dist/systemUserFieldAccess.js +39 -8
- package/dist/systemUserFieldAccess.js.map +1 -1
- 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 +47 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -14
package/dist/renderPipeline.d.ts
CHANGED
|
@@ -18,21 +18,48 @@ export interface CompositionDiagnostic {
|
|
|
18
18
|
/** Number of inner CTEs hoisted from this dep */
|
|
19
19
|
InnerCTEsHoisted: number;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* One composed query instance as it was rendered: a composed query with one set of evaluated
|
|
23
|
+
* arguments, emitted as one CTE.
|
|
24
|
+
*/
|
|
25
|
+
export interface RenderInstanceTrace {
|
|
26
|
+
/** ID of the composed query (a synthetic ID for an inline dependency). */
|
|
27
|
+
QueryID: string;
|
|
28
|
+
QueryName: string;
|
|
29
|
+
/** The composition path as written. */
|
|
30
|
+
CategoryPath: string;
|
|
31
|
+
/** The CTE the instance is emitted as. */
|
|
32
|
+
CTEName: string;
|
|
33
|
+
/** The arguments, evaluated in the caller's scope, keyed by the composed query's parameter names. */
|
|
34
|
+
Arguments: Record<string, unknown>;
|
|
35
|
+
/** The instance's own SQL after its template rendered (its compositions replaced by their CTE names). */
|
|
36
|
+
RenderedSQL: string;
|
|
37
|
+
}
|
|
21
38
|
/**
|
|
22
39
|
* Pipeline trace capturing the SQL state after each pass.
|
|
23
|
-
* Used for error diagnosis — when
|
|
24
|
-
*
|
|
25
|
-
*
|
|
40
|
+
* Used for error diagnosis — when the database rejects the output, the caller can see what each
|
|
41
|
+
* pass produced.
|
|
42
|
+
*
|
|
43
|
+
* Composition renders first, then composes: the outer template renders once, each composed query
|
|
44
|
+
* instance renders on its own ({@link Instances}), and the plain SQL is assembled from them.
|
|
26
45
|
*/
|
|
27
46
|
export interface RenderTrace {
|
|
28
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* The assembled SQL: every template rendered, every composition emitted as a CTE. For a query
|
|
49
|
+
* without compositions, its rendered SQL. Before row caps and paging.
|
|
50
|
+
*/
|
|
29
51
|
AfterComposition: string;
|
|
30
52
|
/** Composition metadata: which deps resolved, which CTEs generated */
|
|
31
53
|
CompositionDiagnostics: CompositionDiagnostic[];
|
|
32
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* The fully resolved, executable SQL before row caps and paging: the same text as
|
|
56
|
+
* {@link AfterComposition}. Authorization checks read it, so it always holds every composed query.
|
|
57
|
+
*/
|
|
33
58
|
AfterTemplates: string;
|
|
34
59
|
/** SQL after paging (final) — only set if paging was applied */
|
|
35
60
|
AfterPaging: string | null;
|
|
61
|
+
/** Each composed query instance, dependencies first. Empty when the query composes nothing. */
|
|
62
|
+
Instances: RenderInstanceTrace[];
|
|
36
63
|
}
|
|
37
64
|
/**
|
|
38
65
|
* Context passed to {@link RenderPipeline.Run} controlling each pipeline stage.
|
|
@@ -40,13 +67,35 @@ export interface RenderTrace {
|
|
|
40
67
|
export interface RenderContext {
|
|
41
68
|
/** Target database platform */
|
|
42
69
|
Platform: DatabasePlatform;
|
|
70
|
+
/**
|
|
71
|
+
* The key of the dialect the template's SQL filters and boolean values render for. Defaults
|
|
72
|
+
* to {@link Platform}. Every render names its dialect, so two providers on different platforms
|
|
73
|
+
* in one process each render with their own filters.
|
|
74
|
+
*/
|
|
75
|
+
DialectKey?: string;
|
|
76
|
+
/** ID of the saved query being rendered, so a composition that leads back to it is refused as a cycle. */
|
|
77
|
+
QueryID?: string;
|
|
78
|
+
/** The saved query's name, for refusals written for its owners. */
|
|
79
|
+
QueryName?: string;
|
|
43
80
|
/** User context for permission checks on referenced queries */
|
|
44
81
|
ContextUser?: UserInfo;
|
|
45
82
|
/** Parameter values from the caller */
|
|
46
83
|
Parameters?: Record<string, string>;
|
|
84
|
+
/**
|
|
85
|
+
* Values only server code sets (`RunQueryParams.ServerParameters`). A caller value for a
|
|
86
|
+
* server-set parameter, here or in a composed query, is refused.
|
|
87
|
+
*/
|
|
88
|
+
ServerParameters?: Record<string, unknown>;
|
|
89
|
+
/** IANA time zone the template's `Context` dates are worked out in. UTC when unset. */
|
|
90
|
+
TimeZone?: string;
|
|
91
|
+
/** The clock the template's `Context` reads. Defaults to now. */
|
|
92
|
+
Now?: Date;
|
|
47
93
|
/** Formal parameter definitions (for validation). Null = skip validation. */
|
|
48
94
|
ParameterDefinitions?: MJQueryParameterEntity[];
|
|
49
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Whether the outer query is a template. A template passes the MJ Query interpreter gate
|
|
97
|
+
* (`QueryTemplate.Validate`, Refresh mode, refused on errors) before Nunjucks evaluates it.
|
|
98
|
+
*/
|
|
50
99
|
UsesTemplate?: boolean;
|
|
51
100
|
/** Inline dependency specs for transient query testing */
|
|
52
101
|
Dependencies?: QueryDependencySpec[];
|
|
@@ -64,11 +113,11 @@ export interface RenderContext {
|
|
|
64
113
|
/** MaxRows safety limit. Mutually exclusive with {@link Paging}. */
|
|
65
114
|
MaxRows?: number;
|
|
66
115
|
/**
|
|
67
|
-
*
|
|
68
|
-
* or `WITH`, reads in every CTE,
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
116
|
+
* Every rendered statement is held to the read-only check (one statement that starts with
|
|
117
|
+
* `SELECT` or `WITH`, reads in every CTE, does not `SELECT … INTO` a table, and calls no
|
|
118
|
+
* forbidden function), saved queries included. Set this where the caller, not a saved query,
|
|
119
|
+
* supplies the SQL (ad-hoc SQL, transient test queries): SQL with no statement at all is then
|
|
120
|
+
* refused too.
|
|
72
121
|
*/
|
|
73
122
|
RequireReadStatement?: boolean;
|
|
74
123
|
}
|
|
@@ -80,6 +129,11 @@ export interface RenderResult {
|
|
|
80
129
|
FinalSQL: string;
|
|
81
130
|
/** Parameters that were applied during template processing */
|
|
82
131
|
AppliedParameters: Record<string, string>;
|
|
132
|
+
/**
|
|
133
|
+
* The `Context` members the template read, with their values. Empty when it read none. A
|
|
134
|
+
* cached result depends on exactly these.
|
|
135
|
+
*/
|
|
136
|
+
ContextValues: Record<string, string>;
|
|
83
137
|
/** Whether composition tokens were found and resolved */
|
|
84
138
|
HasCompositions: boolean;
|
|
85
139
|
/** Metadata about each CTE generated during composition */
|
|
@@ -95,77 +149,43 @@ export interface RenderResult {
|
|
|
95
149
|
RowCap: RowCapOutcome | null;
|
|
96
150
|
}
|
|
97
151
|
/**
|
|
98
|
-
* RenderPipeline
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* **Pipeline order** (this is a data dependency, not a convention):
|
|
102
|
-
* 1. **Composition** resolves `{{query:"..."}}` tokens into CTEs. Must run
|
|
103
|
-
* BEFORE Nunjucks because pass-through parameters rename `{{ innerParam }}`
|
|
104
|
-
* to `{{ outerParam }}` — Nunjucks needs those tokens intact.
|
|
105
|
-
* 2. **Nunjucks** evaluates `{{ param | filter }}` and `{% if/for %}` blocks.
|
|
106
|
-
* Must run AFTER composition and BEFORE paging.
|
|
107
|
-
* 3. **Paging** detects ORDER BY and injects OFFSET/FETCH or LIMIT/OFFSET.
|
|
108
|
-
* Must run AFTER Nunjucks because it needs to detect whether
|
|
109
|
-
* `{% if SortField %} ORDER BY ... {% endif %}` resolved to an actual
|
|
110
|
-
* ORDER BY or not — that depends on runtime parameter values.
|
|
152
|
+
* RenderPipeline is the one entry point that turns query SQL into the SQL that runs, with
|
|
153
|
+
* enforced ordering and a diagnostic trace. Every path uses it: saved queries, ad hoc SQL,
|
|
154
|
+
* TestQuerySQL, specs and data contexts.
|
|
111
155
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
156
|
+
* **Pipeline order** (a data dependency, not a convention):
|
|
157
|
+
* 1. **Comments** are removed first, so template tags in them are inert.
|
|
158
|
+
* 2. **Interpreter gate**: a template must pass the MJ Query language check
|
|
159
|
+
* (`QueryTemplate.Validate`, Refresh mode); a template with errors is refused.
|
|
160
|
+
* 3. **Render, then compose**: Nunjucks renders the outer template once. Each composition it
|
|
161
|
+
* reaches records an instance (the composed query + its arguments evaluated in the caller's
|
|
162
|
+
* scope) and writes the instance's CTE name. Each instance then renders on its own, with only
|
|
163
|
+
* its arguments, recursively. The plain SQL is assembled from the rendered parts and is never
|
|
164
|
+
* rendered again, so a value that looks like a template tag stays a value.
|
|
165
|
+
* 4. **Safety**: the assembled statement must be a single read query (token-based; see
|
|
166
|
+
* {@link SafetyGate}).
|
|
167
|
+
* 5. **Row cap / paging** detect ORDER BY and inject TOP / OFFSET-FETCH / LIMIT, after rendering,
|
|
168
|
+
* because `{% if SortField %} ORDER BY … {% endif %}` decides whether there is an ORDER BY.
|
|
114
169
|
*/
|
|
115
170
|
export declare class RenderPipeline {
|
|
116
171
|
/**
|
|
117
|
-
* Runs the full rendering pipeline
|
|
172
|
+
* Runs the full rendering pipeline.
|
|
118
173
|
*
|
|
119
174
|
* @param sql - Raw SQL with potential composition tokens and template expressions
|
|
120
175
|
* @param ctx - Pipeline context (platform, user, parameters, paging, etc.)
|
|
121
176
|
* @returns Final SQL, applied parameters, composition metadata, and diagnostic trace
|
|
122
177
|
*/
|
|
123
178
|
static Run(sql: string, ctx: RenderContext): RenderResult;
|
|
179
|
+
/** Whether a MaxRows cap and paging were asked for; refuses both at once. */
|
|
180
|
+
private static capsOf;
|
|
124
181
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* {@link SQLParser.HasWriteStatement} inspects EVERY top-level statement, so
|
|
131
|
-
* it catches both a single rendered mutation and a stacked-statement
|
|
132
|
-
* injection payload (e.g. `SELECT 1; DROP TABLE x`) that the first-statement
|
|
133
|
-
* `StatementKind` alone would miss. It is AST-precise: matching is on the
|
|
134
|
-
* statement type, so it cannot false-positive on legitimate read queries —
|
|
135
|
-
* the `REPLACE()` string function, parenthesized SELECTs, trailing
|
|
136
|
-
* semicolons, or benign `SET` / `DECLARE` prefixes all pass.
|
|
137
|
-
*
|
|
138
|
-
* A second, token-based check rejects stacked statements (an internal
|
|
139
|
-
* statement-separating `;`). Unlike the AST check it fires even when the
|
|
140
|
-
* trailing payload makes the SQL unparseable — e.g. `SELECT 1; EXEC
|
|
141
|
-
* xp_cmdshell '…'` or `SELECT 1; WAITFOR DELAY '…'` — which is the
|
|
142
|
-
* stacked-injection class the AST scan misses (the whole string fails to
|
|
143
|
-
* parse, so there is no AST to classify). A rendered read query must be a
|
|
144
|
-
* single statement.
|
|
145
|
-
*
|
|
146
|
-
* When `requireReadStatement` is set (SQL a caller supplied rather than a
|
|
147
|
-
* saved query), the statement must first pass {@link IsReadOnlyQuery}: one
|
|
148
|
-
* statement, starting with SELECT or WITH, reading in every CTE, and not
|
|
149
|
-
* writing its rows into a table. That check works from tokens, so it also
|
|
150
|
-
* refuses a `SET` or `DECLARE` the AST check lets through, and it still
|
|
151
|
-
* accepts read queries the parser cannot read. Such SQL also may not call
|
|
152
|
-
* the functions the dialect lists in `CallerSQLForbiddenFunctions`
|
|
153
|
-
* (`query_to_xml`, `pg_read_file`, `OPENROWSET`, …): they read what a check
|
|
154
|
-
* of the tables the SQL references cannot see.
|
|
155
|
-
*
|
|
156
|
-
* The broader dangerous-keyword scan
|
|
157
|
-
* ({@link SQLExpressionValidator.validateFullQuery}) deliberately stays on
|
|
158
|
-
* the ad-hoc execution path (untrusted free-text input); it is unsuitable as
|
|
159
|
-
* a blanket gate here because it rejects legitimate read constructs (the
|
|
160
|
-
* `REPLACE()` string function, parenthesized SELECTs, etc.).
|
|
161
|
-
*/
|
|
162
|
-
private static assertSafeToExecute;
|
|
163
|
-
/**
|
|
164
|
-
* Resolves only the composition step — for callers that need composition
|
|
165
|
-
* without the full pipeline (e.g., save-time token analysis).
|
|
182
|
+
* Resolves only the composition step: the composed queries are rendered with the static
|
|
183
|
+
* arguments written in their composition tokens and assembled as CTEs; the outer SQL itself is
|
|
184
|
+
* not rendered (its own template tags stay as written). For callers that run SQL with
|
|
185
|
+
* compositions but no parameter values (GetData).
|
|
166
186
|
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
187
|
+
* @throws Error when a composition of the outer SQL passes a value of the outer query: without
|
|
188
|
+
* rendering there is no value to pass. Use {@link Run} for those.
|
|
169
189
|
*/
|
|
170
190
|
static ResolveCompositionOnly(sql: string, platform: DatabasePlatform, contextUser: UserInfo, outerParams?: Record<string, string>, inlineDependencies?: QueryDependencySpec[]): CompositionResult;
|
|
171
191
|
/**
|
|
@@ -173,7 +193,6 @@ export declare class RenderPipeline {
|
|
|
173
193
|
* Convenience wrapper for callers that need a fast guard.
|
|
174
194
|
*/
|
|
175
195
|
static HasCompositionTokens(sql: string): boolean;
|
|
176
|
-
private static
|
|
177
|
-
private static runTemplates;
|
|
196
|
+
private static traceOf;
|
|
178
197
|
}
|
|
179
198
|
//# sourceMappingURL=renderPipeline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPipeline.d.ts","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"renderPipeline.d.ts","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAa,MAAM,sBAAsB,CAAC;AAC7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D,eAAe,EAAE,OAAO,CAAC;IACzB,2DAA2D;IAC3D,IAAI,EAAE,kBAAkB,EAAE,CAAC;IAC3B,yCAAyC;IACzC,KAAK,EAAE,WAAW,CAAC;IACnB,4CAA4C;IAC5C,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACtC;;;OAGG;IACH,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;CAChC;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,cAAc;IAEvB;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY;IAoCzD,6EAA6E;IAC7E,OAAO,CAAC,MAAM,CAAC,MAAM;IAarB;;;;;;;;OAQG;IACH,MAAM,CAAC,sBAAsB,CACzB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,gBAAgB,EAC1B,WAAW,EAAE,QAAQ,EACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,kBAAkB,CAAC,EAAE,mBAAmB,EAAE,GAC3C,iBAAiB;IAMpB;;;OAGG;IACH,MAAM,CAAC,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAQjD,OAAO,CAAC,MAAM,CAAC,OAAO;CAsBzB"}
|
package/dist/renderPipeline.js
CHANGED
|
@@ -1,75 +1,51 @@
|
|
|
1
|
-
import { LogStatus } from '@memberjunction/core';
|
|
1
|
+
import { BuildQueryTemplateContext, LogStatus } from '@memberjunction/core';
|
|
2
2
|
import { GetDialect } from '@memberjunction/sql-dialect';
|
|
3
|
-
import { SQLParser, IsReadOnlyQuery, FindForbiddenFunctionCalls } from '@memberjunction/sql-parser';
|
|
4
3
|
import { QueryCompositionEngine } from './queryCompositionEngine.js';
|
|
5
4
|
import { QueryPagingEngine } from './queryPagingEngine.js';
|
|
6
|
-
import {
|
|
5
|
+
import { SafetyGate } from './composition/safetyGate.js';
|
|
6
|
+
import { CTEInfoOf } from './composition/compositionInfo.js';
|
|
7
|
+
import { AssembleComposition, NewCompositionRender, OuterRenderRequest } from './composition/renderSteps.js';
|
|
7
8
|
// ════════════════════════════════════════════════════════════════════
|
|
8
9
|
// Pipeline
|
|
9
10
|
// ════════════════════════════════════════════════════════════════════
|
|
10
11
|
/**
|
|
11
|
-
* RenderPipeline
|
|
12
|
-
*
|
|
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.
|
|
13
15
|
*
|
|
14
|
-
* **Pipeline order** (
|
|
15
|
-
* 1. **
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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.
|
|
27
29
|
*/
|
|
28
30
|
export class RenderPipeline {
|
|
29
31
|
/**
|
|
30
|
-
* Runs the full rendering pipeline
|
|
32
|
+
* Runs the full rendering pipeline.
|
|
31
33
|
*
|
|
32
34
|
* @param sql - Raw SQL with potential composition tokens and template expressions
|
|
33
35
|
* @param ctx - Pipeline context (platform, user, parameters, paging, etc.)
|
|
34
36
|
* @returns Final SQL, applied parameters, composition metadata, and diagnostic trace
|
|
35
37
|
*/
|
|
36
38
|
static Run(sql, ctx) {
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let currentSQL =
|
|
45
|
-
let appliedParameters = {};
|
|
46
|
-
// ── Step 1: Composition ──────────────────────────────────────
|
|
47
|
-
const compositionResult = RenderPipeline.runComposition(currentSQL, ctx);
|
|
48
|
-
currentSQL = compositionResult.ResolvedSQL;
|
|
49
|
-
const afterComposition = currentSQL;
|
|
50
|
-
const compositionDiagnostics = buildCompositionDiagnostics(compositionResult);
|
|
51
|
-
// ── Step 1.5: Strip SQL comments ─────────────────────────────
|
|
52
|
-
// Comments serve no runtime purpose in executed SQL and can contain
|
|
53
|
-
// {{ }} patterns (e.g. documentation examples) that would crash
|
|
54
|
-
// Nunjucks. Strip them after composition (which correctly ignores
|
|
55
|
-
// comment-embedded tokens) and before Nunjucks processes the SQL.
|
|
56
|
-
// Comments are still visible in Trace.AfterComposition for debugging.
|
|
57
|
-
currentSQL = SQLParser.StripComments(currentSQL, GetDialect(ctx.Platform));
|
|
58
|
-
// ── Step 2: Nunjucks template evaluation ─────────────────────
|
|
59
|
-
const templateResult = RenderPipeline.runTemplates(currentSQL, sql, ctx, compositionResult);
|
|
60
|
-
currentSQL = templateResult.processedSQL;
|
|
61
|
-
appliedParameters = templateResult.appliedParameters;
|
|
62
|
-
const afterTemplates = currentSQL;
|
|
63
|
-
// ── Step 2.5: Safety validation (mutation + injection guard) ──
|
|
64
|
-
// The fully-resolved query is the point where composition and parameter
|
|
65
|
-
// substitution — the only injection vectors — are complete, and where
|
|
66
|
-
// StatementKind reflects the user's actual statement (paging wrapping
|
|
67
|
-
// below always produces a SELECT). Saved queries otherwise skip the
|
|
68
|
-
// dangerous-keyword validation that ad-hoc queries get at execution.
|
|
69
|
-
RenderPipeline.assertSafeToExecute(afterTemplates, ctx.Platform, ctx.RequireReadStatement ?? false);
|
|
70
|
-
// ── 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;
|
|
71
47
|
let rowCap = null;
|
|
72
|
-
if (
|
|
48
|
+
if (caps.HasMaxRows) {
|
|
73
49
|
const capResult = QueryPagingEngine.ApplyMaxRows(currentSQL, ctx.MaxRows, ctx.Platform);
|
|
74
50
|
currentSQL = capResult.SQL;
|
|
75
51
|
rowCap = capResult.Outcome;
|
|
@@ -77,96 +53,41 @@ export class RenderPipeline {
|
|
|
77
53
|
LogStatus(`RenderPipeline: MaxRows ${ctx.MaxRows} was not applied — ${rowCap.Reason}. The query runs uncapped.`);
|
|
78
54
|
}
|
|
79
55
|
}
|
|
80
|
-
// ── Step 4: Paging (if requested) ────────────────────────────
|
|
81
56
|
let pagingResult = null;
|
|
82
|
-
|
|
83
|
-
if (hasPaging) {
|
|
57
|
+
if (caps.HasPaging) {
|
|
84
58
|
pagingResult = QueryPagingEngine.WrapWithPaging(currentSQL, ctx.Paging.StartRow, ctx.Paging.MaxRows, ctx.Platform);
|
|
85
59
|
currentSQL = pagingResult.DataSQL;
|
|
86
|
-
afterPaging = currentSQL;
|
|
87
60
|
}
|
|
88
61
|
return {
|
|
89
62
|
FinalSQL: currentSQL,
|
|
90
|
-
AppliedParameters:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
CompositionDiagnostics: compositionDiagnostics,
|
|
96
|
-
AfterTemplates: afterTemplates,
|
|
97
|
-
AfterPaging: afterPaging,
|
|
98
|
-
},
|
|
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),
|
|
99
68
|
PagingResult: pagingResult,
|
|
100
69
|
RowCap: rowCap,
|
|
101
70
|
};
|
|
102
71
|
}
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
* injection payload (e.g. `SELECT 1; DROP TABLE x`) that the first-statement
|
|
112
|
-
* `StatementKind` alone would miss. It is AST-precise: matching is on the
|
|
113
|
-
* statement type, so it cannot false-positive on legitimate read queries —
|
|
114
|
-
* the `REPLACE()` string function, parenthesized SELECTs, trailing
|
|
115
|
-
* semicolons, or benign `SET` / `DECLARE` prefixes all pass.
|
|
116
|
-
*
|
|
117
|
-
* A second, token-based check rejects stacked statements (an internal
|
|
118
|
-
* statement-separating `;`). Unlike the AST check it fires even when the
|
|
119
|
-
* trailing payload makes the SQL unparseable — e.g. `SELECT 1; EXEC
|
|
120
|
-
* xp_cmdshell '…'` or `SELECT 1; WAITFOR DELAY '…'` — which is the
|
|
121
|
-
* stacked-injection class the AST scan misses (the whole string fails to
|
|
122
|
-
* parse, so there is no AST to classify). A rendered read query must be a
|
|
123
|
-
* single statement.
|
|
124
|
-
*
|
|
125
|
-
* When `requireReadStatement` is set (SQL a caller supplied rather than a
|
|
126
|
-
* saved query), the statement must first pass {@link IsReadOnlyQuery}: one
|
|
127
|
-
* statement, starting with SELECT or WITH, reading in every CTE, and not
|
|
128
|
-
* writing its rows into a table. That check works from tokens, so it also
|
|
129
|
-
* refuses a `SET` or `DECLARE` the AST check lets through, and it still
|
|
130
|
-
* accepts read queries the parser cannot read. Such SQL also may not call
|
|
131
|
-
* the functions the dialect lists in `CallerSQLForbiddenFunctions`
|
|
132
|
-
* (`query_to_xml`, `pg_read_file`, `OPENROWSET`, …): they read what a check
|
|
133
|
-
* of the tables the SQL references cannot see.
|
|
134
|
-
*
|
|
135
|
-
* The broader dangerous-keyword scan
|
|
136
|
-
* ({@link SQLExpressionValidator.validateFullQuery}) deliberately stays on
|
|
137
|
-
* the ad-hoc execution path (untrusted free-text input); it is unsuitable as
|
|
138
|
-
* a blanket gate here because it rejects legitimate read constructs (the
|
|
139
|
-
* `REPLACE()` string function, parenthesized SELECTs, etc.).
|
|
140
|
-
*/
|
|
141
|
-
static assertSafeToExecute(sql, platform, requireReadStatement) {
|
|
142
|
-
const dialect = GetDialect(platform);
|
|
143
|
-
if (requireReadStatement) {
|
|
144
|
-
const check = IsReadOnlyQuery(sql, dialect);
|
|
145
|
-
if (!check.IsReadOnly) {
|
|
146
|
-
throw new Error(`RenderPipeline: only a single read query may be run here, and this SQL is not one: ${check.Reason}.`);
|
|
147
|
-
}
|
|
148
|
-
const forbidden = FindForbiddenFunctionCalls(sql, dialect);
|
|
149
|
-
if (forbidden.length > 0) {
|
|
150
|
-
throw new Error(`RenderPipeline: SQL supplied here may not call ${forbidden.join(', ')}. These functions run SQL ` +
|
|
151
|
-
'given as a string, or read files or other databases, so what they read cannot be checked.');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const parsed = new SQLParser(sql, dialect);
|
|
155
|
-
if (parsed.HasWriteStatement) {
|
|
156
|
-
throw new Error('RenderPipeline: rendered SQL contains a write statement ' +
|
|
157
|
-
'(mutation / DDL) — only a read query may be rendered for execution.');
|
|
158
|
-
}
|
|
159
|
-
if (SQLParser.HasStackedStatements(sql, dialect)) {
|
|
160
|
-
throw new Error('RenderPipeline: rendered SQL contains multiple statements ' +
|
|
161
|
-
'(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)}.`);
|
|
162
80
|
}
|
|
81
|
+
return { HasMaxRows: hasMaxRows, HasPaging: hasPaging };
|
|
163
82
|
}
|
|
164
83
|
/**
|
|
165
|
-
* Resolves only the composition step
|
|
166
|
-
*
|
|
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).
|
|
167
88
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
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.
|
|
170
91
|
*/
|
|
171
92
|
static ResolveCompositionOnly(sql, platform, contextUser, outerParams, inlineDependencies) {
|
|
172
93
|
return new QueryCompositionEngine().ResolveComposition(sql, platform, contextUser, outerParams, inlineDependencies);
|
|
@@ -180,57 +101,28 @@ export class RenderPipeline {
|
|
|
180
101
|
}
|
|
181
102
|
// ════════════════════════════════════════════════════════════════
|
|
182
103
|
// Internal pass implementations
|
|
183
|
-
//
|
|
184
|
-
static
|
|
185
|
-
const engine = new QueryCompositionEngine();
|
|
186
|
-
if (!engine.HasCompositionTokens(sql) || !ctx.ContextUser) {
|
|
187
|
-
return {
|
|
188
|
-
ResolvedSQL: sql,
|
|
189
|
-
CTEs: [],
|
|
190
|
-
DependencyGraph: new Map(),
|
|
191
|
-
HasCompositions: false,
|
|
192
|
-
AnyDependencyUsesTemplates: false,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
return engine.ResolveComposition(sql, ctx.Platform, ctx.ContextUser, ctx.Parameters, ctx.Dependencies);
|
|
196
|
-
}
|
|
197
|
-
static runTemplates(composedSQL, originalSQL, ctx, compositionResult) {
|
|
198
|
-
const needsTemplateProcessing = ctx.UsesTemplate || compositionResult.AnyDependencyUsesTemplates;
|
|
199
|
-
if (!needsTemplateProcessing) {
|
|
200
|
-
return { processedSQL: composedSQL, appliedParameters: {} };
|
|
201
|
-
}
|
|
202
|
-
// Build the template input. When a QueryInfo object is provided (saved
|
|
203
|
-
// query path), pass it directly so processQueryTemplate gets the real
|
|
204
|
-
// Parameters array for validation. Otherwise build a synthetic input.
|
|
205
|
-
const templateInput = ctx.QueryInfo ?? {
|
|
206
|
-
SQL: ctx.OriginalSQL ?? originalSQL,
|
|
207
|
-
UsesTemplate: ctx.UsesTemplate ?? false,
|
|
208
|
-
Parameters: ctx.ParameterDefinitions ?? [],
|
|
209
|
-
};
|
|
210
|
-
const skipUnknownParamCheck = compositionResult.AnyDependencyUsesTemplates || !ctx.ParameterDefinitions;
|
|
211
|
-
const result = QueryParameterProcessor.processQueryTemplate(templateInput, ctx.Parameters, composedSQL, skipUnknownParamCheck);
|
|
212
|
-
if (!result.success) {
|
|
213
|
-
throw new Error(result.error);
|
|
214
|
-
}
|
|
104
|
+
// ════════════════════════════════════════════════════════════════
|
|
105
|
+
static traceOf(assembled, afterPaging) {
|
|
215
106
|
return {
|
|
216
|
-
|
|
217
|
-
|
|
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
|
+
})),
|
|
218
125
|
};
|
|
219
126
|
}
|
|
220
127
|
}
|
|
221
|
-
// ════════════════════════════════════════════════════════════════════
|
|
222
|
-
// Helpers
|
|
223
|
-
// ════════════════════════════════════════════════════════════════════
|
|
224
|
-
function buildCompositionDiagnostics(result) {
|
|
225
|
-
return result.CTEs.map(cte => ({
|
|
226
|
-
DepName: cte.QueryName,
|
|
227
|
-
CategoryPath: cte.CategoryPath,
|
|
228
|
-
CTEName: cte.CTEName,
|
|
229
|
-
// We can't easily tell if ORDER BY was stripped without comparing
|
|
230
|
-
// original vs resolved SQL, so this is a best-effort flag based on
|
|
231
|
-
// whether the original had ORDER BY and the resolved doesn't.
|
|
232
|
-
OrderByStripped: /ORDER\s+BY\b/i.test(cte.OriginalSQL) && !/ORDER\s+BY\b/i.test(cte.ResolvedSQL),
|
|
233
|
-
InnerCTEsHoisted: 0, // TODO: track in composition engine
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
128
|
//# sourceMappingURL=renderPipeline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPipeline.js","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,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,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAyC,MAAM,6BAA6B,CAAC;AAC5G,OAAO,EAAE,iBAAiB,EAAmC,MAAM,wBAAwB,CAAC;AAG5F,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAyJ7G,uEAAuE;AACvE,WAAW;AACX,uEAAuE;AAEvE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,cAAc;IAEvB;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,GAAW,EAAE,GAAkB;QACtC,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,yBAAyB,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAA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AC;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"}
|