@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,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a database server reports about the result set a statement would return, without the
|
|
3
|
+
* statement's rows: each output column's name, position, exact type, nullability and, when the
|
|
4
|
+
* column passes a table or view column through unchanged, that column.
|
|
5
|
+
*/
|
|
6
|
+
/** The table or view column an output column passes through unchanged. */
|
|
7
|
+
export interface DescribedColumnSource {
|
|
8
|
+
/** The schema of the table or view. */
|
|
9
|
+
readonly Schema: string;
|
|
10
|
+
/** The table or view. */
|
|
11
|
+
readonly Object: string;
|
|
12
|
+
/** The column of that table or view. */
|
|
13
|
+
readonly Column: string;
|
|
14
|
+
}
|
|
15
|
+
/** One output column of a described statement. */
|
|
16
|
+
export interface DescribedColumn {
|
|
17
|
+
/** The name the client receives; `''` for a column the statement leaves unnamed. */
|
|
18
|
+
readonly Name: string;
|
|
19
|
+
/** The column's 1-based position in the result. */
|
|
20
|
+
readonly Ordinal: number;
|
|
21
|
+
/** The type without length, precision or scale, such as `nvarchar` or `character varying`. */
|
|
22
|
+
readonly SQLBaseType: string;
|
|
23
|
+
/** The type as the server writes it, such as `nvarchar(100)`, `decimal(18,2)` or `character varying(100)`. */
|
|
24
|
+
readonly SQLFullType: string;
|
|
25
|
+
/** Whether the column can hold NULL; `null` when the server does not say (PostgreSQL). */
|
|
26
|
+
readonly IsNullable: boolean | null;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the column is computed rather than passed through: it has no source column (an
|
|
29
|
+
* expression, aggregate, literal or set-operation output), or its source column is itself a
|
|
30
|
+
* computed column.
|
|
31
|
+
*/
|
|
32
|
+
readonly IsComputed: boolean;
|
|
33
|
+
/** The table or view column the value comes from unchanged; `null` when there is none. */
|
|
34
|
+
readonly Source: DescribedColumnSource | null;
|
|
35
|
+
}
|
|
36
|
+
/** The result of describing a statement. */
|
|
37
|
+
export interface DescribeStatementResult {
|
|
38
|
+
/** Whether the server described the statement. */
|
|
39
|
+
readonly Success: boolean;
|
|
40
|
+
/** The output columns, in order. Empty when the description failed. */
|
|
41
|
+
readonly Columns: readonly DescribedColumn[];
|
|
42
|
+
/** The server's error text, one entry per error, when the description failed. */
|
|
43
|
+
readonly Diagnostics: readonly string[];
|
|
44
|
+
}
|
|
45
|
+
/** A failed description carrying `messages`. */
|
|
46
|
+
export declare function DescribeStatementFailure(...messages: string[]): DescribeStatementResult;
|
|
47
|
+
/** A successful description of `columns`. */
|
|
48
|
+
export declare function DescribeStatementSuccess(columns: readonly DescribedColumn[]): DescribeStatementResult;
|
|
49
|
+
/** The base type of a full type: the text before its first `(`, trimmed (`decimal(18,2)` → `decimal`). */
|
|
50
|
+
export declare function BaseTypeOf(fullType: string): string;
|
|
51
|
+
//# sourceMappingURL=describeStatement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describeStatement.d.ts","sourceRoot":"","sources":["../src/describeStatement.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,qBAAqB;IAClC,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yBAAyB;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wCAAwC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CAC3B;AAED,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC5B,oFAAoF;IACpF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,8GAA8G;IAC9G,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,0FAA0F;IAC1F,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,0FAA0F;IAC1F,QAAQ,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACjD;AAED,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACpC,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IAC7C,iFAAiF;IACjF,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C;AAED,gDAAgD;AAChD,wBAAgB,wBAAwB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,uBAAuB,CAEvF;AAED,6CAA6C;AAC7C,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,uBAAuB,CAErG;AAED,0GAA0G;AAC1G,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGnD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a database server reports about the result set a statement would return, without the
|
|
3
|
+
* statement's rows: each output column's name, position, exact type, nullability and, when the
|
|
4
|
+
* column passes a table or view column through unchanged, that column.
|
|
5
|
+
*/
|
|
6
|
+
/** A failed description carrying `messages`. */
|
|
7
|
+
export function DescribeStatementFailure(...messages) {
|
|
8
|
+
return Object.freeze({ Success: false, Columns: Object.freeze([]), Diagnostics: Object.freeze(messages.filter(m => m.length > 0)) });
|
|
9
|
+
}
|
|
10
|
+
/** A successful description of `columns`. */
|
|
11
|
+
export function DescribeStatementSuccess(columns) {
|
|
12
|
+
return Object.freeze({ Success: true, Columns: Object.freeze([...columns]), Diagnostics: Object.freeze([]) });
|
|
13
|
+
}
|
|
14
|
+
/** The base type of a full type: the text before its first `(`, trimmed (`decimal(18,2)` → `decimal`). */
|
|
15
|
+
export function BaseTypeOf(fullType) {
|
|
16
|
+
const open = fullType.indexOf('(');
|
|
17
|
+
return (open < 0 ? fullType : fullType.slice(0, open)).trim();
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=describeStatement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describeStatement.js","sourceRoot":"","sources":["../src/describeStatement.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4CH,gDAAgD;AAChD,MAAM,UAAU,wBAAwB,CAAC,GAAG,QAAkB;IAC1D,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACzI,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,wBAAwB,CAAC,OAAmC;IACxE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAClH,CAAC;AAED,0GAA0G;AAC1G,MAAM,UAAU,UAAU,CAAC,QAAgB;IACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ParserDialect } from '@memberjunction/sql-dialect';
|
|
2
|
+
/**
|
|
3
|
+
* The character offsets of the `*` of every projection star in `sql` (see the module comment).
|
|
4
|
+
* Empty when the statement is not read completely, holds more than one statement, carries a
|
|
5
|
+
* disqualifying whole-row construct or a PIVOT / UNPIVOT, or has no such star.
|
|
6
|
+
*
|
|
7
|
+
* A star qualifies only in a select block that is the statement's query, a CTE body or a derived
|
|
8
|
+
* table reached from it, that is not a branch of a set operation, and that has no DISTINCT and no
|
|
9
|
+
* GROUP BY (each compares the star's columns, denied ones included, across rows).
|
|
10
|
+
*
|
|
11
|
+
* @param sql - The rendered statement.
|
|
12
|
+
* @param dialect - The dialect it runs under.
|
|
13
|
+
*/
|
|
14
|
+
export declare function FindProjectionStars(sql: string, dialect: ParserDialect): ReadonlySet<number>;
|
|
15
|
+
//# sourceMappingURL=projectionStars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectionStars.d.ts","sourceRoot":"","sources":["../../src/fieldSecurity/projectionStars.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAYjE;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,CAY5F"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SECURITY — finds the `*` and `alias.*` select items of a saved query's rendered SQL whose columns
|
|
3
|
+
* can only reach the caller as output columns: the star is a whole select item of a select block
|
|
4
|
+
* whose rows flow, unchanged in shape, into the statement's result. Field-level security lets such
|
|
5
|
+
* a star run and drops the denied columns from the result; every other star (and every statement
|
|
6
|
+
* this reading cannot vouch for) stays refused by the token gate.
|
|
7
|
+
*/
|
|
8
|
+
import { SqlDocument, WalkSqlNodes } from '@memberjunction/sql-parser';
|
|
9
|
+
/**
|
|
10
|
+
* Whole-row constructs that let a denied column shape the result without being named, so a
|
|
11
|
+
* statement carrying one gets no projection star: a document form (`FOR JSON`), a natural join,
|
|
12
|
+
* a row value (`row_to_json(t)`, a bare relation name on PostgreSQL) and an ordinal ORDER BY,
|
|
13
|
+
* which can sort by a column the star brought in.
|
|
14
|
+
*/
|
|
15
|
+
const DISQUALIFYING_CONSTRUCTS = new Set([
|
|
16
|
+
'ForDocument', 'NaturalJoin', 'RowFunction', 'RowReference', 'OrdinalOrderBy',
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* The character offsets of the `*` of every projection star in `sql` (see the module comment).
|
|
20
|
+
* Empty when the statement is not read completely, holds more than one statement, carries a
|
|
21
|
+
* disqualifying whole-row construct or a PIVOT / UNPIVOT, or has no such star.
|
|
22
|
+
*
|
|
23
|
+
* A star qualifies only in a select block that is the statement's query, a CTE body or a derived
|
|
24
|
+
* table reached from it, that is not a branch of a set operation, and that has no DISTINCT and no
|
|
25
|
+
* GROUP BY (each compares the star's columns, denied ones included, across rows).
|
|
26
|
+
*
|
|
27
|
+
* @param sql - The rendered statement.
|
|
28
|
+
* @param dialect - The dialect it runs under.
|
|
29
|
+
*/
|
|
30
|
+
export function FindProjectionStars(sql, dialect) {
|
|
31
|
+
const doc = SqlDocument.Parse(sql, dialect);
|
|
32
|
+
if (!statementQualifies(doc))
|
|
33
|
+
return new Set();
|
|
34
|
+
const offsets = new Set();
|
|
35
|
+
for (const core of rowSourceCores(doc.Statements[0])) {
|
|
36
|
+
if (!coreQualifies(core))
|
|
37
|
+
continue;
|
|
38
|
+
for (const item of core.SelectList) {
|
|
39
|
+
const offset = item.IsStar ? starOffset(doc, item) : -1;
|
|
40
|
+
if (offset >= 0)
|
|
41
|
+
offsets.add(offset);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return offsets;
|
|
45
|
+
}
|
|
46
|
+
/** Whether the document is one fully read statement with no disqualifying construct or pivot. */
|
|
47
|
+
function statementQualifies(doc) {
|
|
48
|
+
if (!doc.IsComplete || doc.Statements.length !== 1)
|
|
49
|
+
return false;
|
|
50
|
+
const constructs = doc.WholeRowConstructs();
|
|
51
|
+
if (!constructs.Complete || constructs.Value.some(c => DISQUALIFYING_CONSTRUCTS.has(c.Kind)))
|
|
52
|
+
return false;
|
|
53
|
+
let pivot = false;
|
|
54
|
+
WalkSqlNodes(doc.Statements, node => {
|
|
55
|
+
if (node.Kind === 'Pivot')
|
|
56
|
+
pivot = true;
|
|
57
|
+
});
|
|
58
|
+
return !pivot;
|
|
59
|
+
}
|
|
60
|
+
/** The select blocks whose rows reach the statement's result as rows: the query, CTE bodies and derived tables. */
|
|
61
|
+
function rowSourceCores(statement) {
|
|
62
|
+
const cores = [];
|
|
63
|
+
visitQuery(statement, cores);
|
|
64
|
+
return cores;
|
|
65
|
+
}
|
|
66
|
+
function visitQuery(node, cores) {
|
|
67
|
+
for (const cte of node.With?.CTEs ?? [])
|
|
68
|
+
visitQuery(cte.Body, cores);
|
|
69
|
+
if (node.Body.Kind !== 'Unknown')
|
|
70
|
+
visitExpression(node.Body, cores);
|
|
71
|
+
}
|
|
72
|
+
/** A set operation's branches and a VALUES list are not row sources: their rows are compared or built. */
|
|
73
|
+
function visitExpression(expression, cores) {
|
|
74
|
+
if (expression.Kind === 'Select') {
|
|
75
|
+
cores.push(expression);
|
|
76
|
+
for (const source of expression.From?.Sources ?? [])
|
|
77
|
+
visitSource(source, cores);
|
|
78
|
+
}
|
|
79
|
+
else if (expression.Kind === 'Parenthesized') {
|
|
80
|
+
visitQuery(expression.Query, cores);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function visitSource(source, cores) {
|
|
84
|
+
switch (source.Kind) {
|
|
85
|
+
case 'Derived':
|
|
86
|
+
visitQuery(source.Query, cores);
|
|
87
|
+
return;
|
|
88
|
+
case 'Join':
|
|
89
|
+
visitSource(source.Left, cores);
|
|
90
|
+
visitSource(source.Right, cores);
|
|
91
|
+
return;
|
|
92
|
+
case 'Apply':
|
|
93
|
+
visitSource(source.Left, cores);
|
|
94
|
+
visitSource(source.Right, cores);
|
|
95
|
+
return;
|
|
96
|
+
case 'ParenthesizedSource':
|
|
97
|
+
visitSource(source.Inner, cores);
|
|
98
|
+
return;
|
|
99
|
+
default: return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** DISTINCT and GROUP BY compare every column of the block's rows, so its stars do not qualify. */
|
|
103
|
+
function coreQualifies(core) {
|
|
104
|
+
const distinct = core.Distinct !== null && core.Distinct.Form !== 'All';
|
|
105
|
+
return !distinct && core.GroupBy === null && core.Unrecognized.length === 0;
|
|
106
|
+
}
|
|
107
|
+
/** The offset of the `*` of a star select item, or -1 when the item is not exactly a star. */
|
|
108
|
+
function starOffset(doc, item) {
|
|
109
|
+
const stars = item.Expression.Stars();
|
|
110
|
+
if (stars.length !== 1 || stars[0].FunctionName !== null || item.Alias !== null)
|
|
111
|
+
return -1;
|
|
112
|
+
const text = doc.Text(item.Expression.Span);
|
|
113
|
+
const at = text.lastIndexOf('*');
|
|
114
|
+
return at < 0 || text.slice(at + 1).trim().length > 0 ? -1 : item.Expression.Span.Start + at;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=projectionStars.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectionStars.js","sourceRoot":"","sources":["../../src/fieldSecurity/projectionStars.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAMvE;;;;;GAKG;AACH,MAAM,wBAAwB,GAA8B,IAAI,GAAG,CAAe;IAC9E,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB;CAChF,CAAC,CAAC;AAE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AAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;AACjG,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SECURITY — which output columns of a saved query a field-level security restricted caller must
|
|
3
|
+
* not receive, and dropping them from the rows. Used only for queries whose denied columns can
|
|
4
|
+
* reach the output through a projection star (`projectionStars.ts`); a query that names a denied
|
|
5
|
+
* field is refused before it runs.
|
|
6
|
+
*
|
|
7
|
+
* The output columns come from the database's own description of the rendered statement
|
|
8
|
+
* (`DescribeStatement`), mapped through MJ metadata: the source schema and view (or table, or an
|
|
9
|
+
* alternate base view) name an entity, the source column one of its fields. The description is
|
|
10
|
+
* the same for every caller, so the provider keeps it per rendered statement and dialect
|
|
11
|
+
* (`StatementMemo`); which columns a caller loses is worked out per call.
|
|
12
|
+
*/
|
|
13
|
+
import type { EntityInfo, UserInfo } from '@memberjunction/core';
|
|
14
|
+
import type { DescribedColumn } from '../describeStatement.js';
|
|
15
|
+
/**
|
|
16
|
+
* The output column names `user` must not receive:
|
|
17
|
+
* - every column whose source is a field the user is denied on the entity that source names;
|
|
18
|
+
* - every column whose source names no entity, or that has no source, whose name may name a
|
|
19
|
+
* field the user is denied on any of `readEntities` (a conservative catch for a pass-through
|
|
20
|
+
* the database did not trace).
|
|
21
|
+
*
|
|
22
|
+
* @param columns The description of the rendered statement
|
|
23
|
+
* @param catalog Every entity the provider knows
|
|
24
|
+
* @param readEntities The entities the statement reads
|
|
25
|
+
* @param user The caller
|
|
26
|
+
*/
|
|
27
|
+
export declare function WithheldColumnNames(columns: readonly DescribedColumn[], catalog: readonly EntityInfo[], readEntities: readonly EntityInfo[], user: UserInfo): Set<string>;
|
|
28
|
+
/**
|
|
29
|
+
* The names in `rows` that `columns` does not describe: a sign the statement's shape changed
|
|
30
|
+
* since it was described.
|
|
31
|
+
*/
|
|
32
|
+
export declare function UndescribedColumnNames(rows: readonly Record<string, unknown>[], columns: readonly DescribedColumn[]): Set<string>;
|
|
33
|
+
/** `rows` without the `withheld` columns, as new row objects; `rows` itself when nothing is withheld. */
|
|
34
|
+
export declare function WithholdColumns<T extends Record<string, unknown>>(rows: readonly T[], withheld: ReadonlySet<string>): T[];
|
|
35
|
+
//# sourceMappingURL=queryColumnSecurity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryColumnSecurity.d.ts","sourceRoot":"","sources":["../../src/fieldSecurity/queryColumnSecurity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAoB/D;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,OAAO,EAAE,SAAS,UAAU,EAAE,EAC9B,YAAY,EAAE,SAAS,UAAU,EAAE,EACnC,IAAI,EAAE,QAAQ,GACf,GAAG,CAAC,MAAM,CAAC,CAoBb;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CASjI;AAED,yGAAyG;AACzG,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CASzH"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ReferenceMayNameField } from '@memberjunction/core';
|
|
2
|
+
/** Folded `schema.object` → the entities whose base view, base table or alternate base view it is. */
|
|
3
|
+
function relationIndex(catalog) {
|
|
4
|
+
const index = new Map();
|
|
5
|
+
const add = (schema, name, entity) => {
|
|
6
|
+
if (!name)
|
|
7
|
+
return;
|
|
8
|
+
const key = `${(schema ?? '').toLowerCase()}.${name.toLowerCase()}`;
|
|
9
|
+
const list = index.get(key) ?? [];
|
|
10
|
+
if (!list.includes(entity))
|
|
11
|
+
list.push(entity);
|
|
12
|
+
index.set(key, list);
|
|
13
|
+
};
|
|
14
|
+
for (const entity of catalog) {
|
|
15
|
+
add(entity.SchemaName, entity.BaseView, entity);
|
|
16
|
+
add(entity.SchemaName, entity.BaseTable, entity);
|
|
17
|
+
for (const view of entity.AlternateBaseViews ?? [])
|
|
18
|
+
add(view.SchemaName ?? entity.SchemaName, view.ViewName, entity);
|
|
19
|
+
}
|
|
20
|
+
return index;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The output column names `user` must not receive:
|
|
24
|
+
* - every column whose source is a field the user is denied on the entity that source names;
|
|
25
|
+
* - every column whose source names no entity, or that has no source, whose name may name a
|
|
26
|
+
* field the user is denied on any of `readEntities` (a conservative catch for a pass-through
|
|
27
|
+
* the database did not trace).
|
|
28
|
+
*
|
|
29
|
+
* @param columns The description of the rendered statement
|
|
30
|
+
* @param catalog Every entity the provider knows
|
|
31
|
+
* @param readEntities The entities the statement reads
|
|
32
|
+
* @param user The caller
|
|
33
|
+
*/
|
|
34
|
+
export function WithheldColumnNames(columns, catalog, readEntities, user) {
|
|
35
|
+
const index = relationIndex(catalog);
|
|
36
|
+
const deniedByEntity = new Map();
|
|
37
|
+
const deniedOf = (entity) => {
|
|
38
|
+
let denied = deniedByEntity.get(entity);
|
|
39
|
+
if (!denied) {
|
|
40
|
+
denied = entity.FieldLevelSecurityApplies ? entity.GetDeniedReadFields(user) : new Set();
|
|
41
|
+
deniedByEntity.set(entity, denied);
|
|
42
|
+
}
|
|
43
|
+
return denied;
|
|
44
|
+
};
|
|
45
|
+
const withheld = new Set();
|
|
46
|
+
for (const column of columns) {
|
|
47
|
+
const entities = column.Source ? index.get(`${column.Source.Schema.toLowerCase()}.${column.Source.Object.toLowerCase()}`) : undefined;
|
|
48
|
+
const denied = entities
|
|
49
|
+
? entities.some(e => deniedOf(e).has(column.Source.Column.toLowerCase()))
|
|
50
|
+
: readEntities.some(e => [...deniedOf(e)].some(name => ReferenceMayNameField(column.Name, name)));
|
|
51
|
+
if (denied)
|
|
52
|
+
withheld.add(column.Name);
|
|
53
|
+
}
|
|
54
|
+
return withheld;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The names in `rows` that `columns` does not describe: a sign the statement's shape changed
|
|
58
|
+
* since it was described.
|
|
59
|
+
*/
|
|
60
|
+
export function UndescribedColumnNames(rows, columns) {
|
|
61
|
+
const described = new Set(columns.map(c => c.Name));
|
|
62
|
+
const unknown = new Set();
|
|
63
|
+
for (const row of rows) {
|
|
64
|
+
for (const name of Object.keys(row)) {
|
|
65
|
+
if (!described.has(name))
|
|
66
|
+
unknown.add(name);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return unknown;
|
|
70
|
+
}
|
|
71
|
+
/** `rows` without the `withheld` columns, as new row objects; `rows` itself when nothing is withheld. */
|
|
72
|
+
export function WithholdColumns(rows, withheld) {
|
|
73
|
+
if (withheld.size === 0)
|
|
74
|
+
return rows;
|
|
75
|
+
return rows.map(row => {
|
|
76
|
+
const kept = {};
|
|
77
|
+
for (const [name, value] of Object.entries(row)) {
|
|
78
|
+
if (!withheld.has(name))
|
|
79
|
+
kept[name] = value;
|
|
80
|
+
}
|
|
81
|
+
return kept;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=queryColumnSecurity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryColumnSecurity.js","sourceRoot":"","sources":["../../src/fie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|
1
|
-
export { GenericDatabaseProvider, DoomedTransactionError, ExecuteSQLBatchOptions } from './GenericDatabaseProvider.js';
|
|
1
|
+
export { GenericDatabaseProvider, DoomedTransactionError, ExecuteSQLBatchOptions, SummarizeSqlParameters, FormatSqlParameterTypesForError, } from './GenericDatabaseProvider.js';
|
|
2
|
+
export type { SqlParameterSummary, SqlObservation, ISqlObserver } from './GenericDatabaseProvider.js';
|
|
2
3
|
export { DatabaseWellKnownUserSource } from './DatabaseWellKnownUserSource.js';
|
|
3
4
|
export { SystemUserID } from './systemUser.js';
|
|
4
5
|
export type { SaveCoercedValue, SaveCallBinding, SaveSQLFragment, SaveReturnContext, RecordChangePayload, } from './saveTypes.js';
|
|
@@ -9,7 +10,7 @@ export { ClientClauseScreen, IsClientClauseScreeningProvider } from './clientCla
|
|
|
9
10
|
export type { ClientClauseText, ClientViewClauseSet, EntityBaseViewAllowList, ClientClauseScreeningProvider, StatementReads, StatementRelation } from './clientClauseScreen.js';
|
|
10
11
|
export { SystemUserFieldAccessLossReason, FindSystemUserFieldAccessViolations, SystemUserFieldAccessViolation, SystemUserHoldsRole, SystemUserFieldAccessSweepOptions, } from './systemUserFieldAccess.js';
|
|
11
12
|
export { SystemUserFieldAccessCheck, LoadSystemUserFieldAccessCheck } from './SystemUserFieldAccessCheck.js';
|
|
12
|
-
export { SqlLoggingOptions, SqlLoggingSession, SqlSchemaPlaceholder } from './types.js';
|
|
13
|
+
export { SqlLoggingOptions, SqlLoggingSession, SqlSchemaPlaceholder, DatabasePoolStats } from './types.js';
|
|
13
14
|
export { SqlLoggingSessionImpl, SCHEMA_PLACEHOLDER_LOOKBEHIND } from './SqlLogger.js';
|
|
14
15
|
export { QueryCompositionEngine, CompositionCTEInfo, CompositionResult } from './queryCompositionEngine.js';
|
|
15
16
|
export { CountOnlyBatchCoalescer, IsCoalescibleCountBatch } from './countOnlyBatch.js';
|
|
@@ -17,7 +18,14 @@ export type { CountOnlyRow, CountSQLExecutor } from './countOnlyBatch.js';
|
|
|
17
18
|
export { QueryPagingEngine, PagingWrappedSQL } from './queryPagingEngine.js';
|
|
18
19
|
export type { RowCapOutcome, RowCapMethod, RowCapResult } from './queryPagingEngine.js';
|
|
19
20
|
export { RenderPipeline, RenderContext, RenderResult, RenderTrace, CompositionDiagnostic } from './renderPipeline.js';
|
|
21
|
+
export { SafetyGate, QuerySafetyError, IsQuerySafetyError } from './composition/safetyGate.js';
|
|
20
22
|
export { SymbolTable } from './symbolTable.js';
|
|
21
23
|
export { AnalyzeTopLevelOrderBy, HasTopLevelOrderBy, ExtractOrderBy, ParseToIR, RenderIR } from '@memberjunction/sql-parser';
|
|
22
24
|
export type { OrderByAnalysis, QueryIR, CTENode, Fragment, SQLFragment, TemplateExprFragment, BlockFragment, CommentFragment, CompositionRefFragment, CTEOrigin } from '@memberjunction/sql-parser';
|
|
25
|
+
export { DescribeStatementFailure, DescribeStatementSuccess, BaseTypeOf } from './describeStatement.js';
|
|
26
|
+
export type { DescribedColumn, DescribedColumnSource, DescribeStatementResult } from './describeStatement.js';
|
|
27
|
+
export { TypedQueryParameter, IsTypedQueryParameterList, TypedBindValue, NamedQueryParameter, IsNamedQueryParameterList } from './typedQueryParameter.js';
|
|
28
|
+
export type { TypedQueryParameterValue } from './typedQueryParameter.js';
|
|
29
|
+
export { StatementMemo } from './statementMemo.js';
|
|
30
|
+
export { FindProjectionStars } from './fieldSecurity/projectionStars.js';
|
|
23
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,GAClC,MAAM,8BAA8B,CAAC;AACtC,YA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ransactionError } from './GenericDatabaseProvider.js';
|
|
1
|
+
export { GenericDatabaseProvider, DoomedTransactionError, SummarizeSqlParameters, FormatSqlParameterTypesForError, } from './GenericDatabaseProvider.js';
|
|
2
2
|
// Side-effect import: registers DatabaseWellKnownUserSource with the class factory so any
|
|
3
3
|
// process holding a database provider can resolve MJ's built-in accounts.
|
|
4
4
|
export { DatabaseWellKnownUserSource } from './DatabaseWellKnownUserSource.js';
|
|
@@ -16,7 +16,12 @@ export { QueryCompositionEngine } from './queryCompositionEngine.js';
|
|
|
16
16
|
export { CountOnlyBatchCoalescer, IsCoalescibleCountBatch } from './countOnlyBatch.js';
|
|
17
17
|
export { QueryPagingEngine } from './queryPagingEngine.js';
|
|
18
18
|
export { RenderPipeline } from './renderPipeline.js';
|
|
19
|
+
export { SafetyGate, QuerySafetyError, IsQuerySafetyError } from './composition/safetyGate.js';
|
|
19
20
|
export { SymbolTable } from './symbolTable.js';
|
|
20
21
|
// Re-export from @memberjunction/sql-parser for backward compatibility
|
|
21
22
|
export { AnalyzeTopLevelOrderBy, HasTopLevelOrderBy, ExtractOrderBy, ParseToIR, RenderIR } from '@memberjunction/sql-parser';
|
|
23
|
+
export { DescribeStatementFailure, DescribeStatementSuccess, BaseTypeOf } from './describeStatement.js';
|
|
24
|
+
export { TypedQueryParameter, IsTypedQueryParameterList, TypedBindValue, NamedQueryParameter, IsNamedQueryParameterList } from './typedQueryParameter.js';
|
|
25
|
+
export { StatementMemo } from './statementMemo.js';
|
|
26
|
+
export { FindProjectionStars } from './fieldSecurity/projectionStars.js';
|
|
22
27
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,sBAAsB,EA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QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE7H,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAExG,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,cAAc,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAE1J,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { SqlDocument } from '@memberjunction/sql-parser';
|
|
2
|
+
import type { OwnRowCap, QueryExpression, StatementNode } from '@memberjunction/sql-parser';
|
|
3
|
+
import type { SQLDialect } from '@memberjunction/sql-dialect';
|
|
4
|
+
/** A query expression the structural parser read: anything but an `Unknown` node. */
|
|
5
|
+
type ReadQuery = Exclude<QueryExpression, {
|
|
6
|
+
Kind: 'Unknown';
|
|
7
|
+
}>;
|
|
8
|
+
/** The parsed form of a statement, kept beside its layout when the structural parser read all of it. */
|
|
9
|
+
export interface PagingDocument {
|
|
10
|
+
readonly Document: SqlDocument;
|
|
11
|
+
readonly Statement: StatementNode;
|
|
12
|
+
readonly Body: ReadQuery;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What the paging and row-cap steps need to know about one statement. All offsets are positions
|
|
16
|
+
* in {@link Statement}.
|
|
17
|
+
*
|
|
18
|
+
* It is read from a {@link SqlDocument} when the structural parser reads the statement completely
|
|
19
|
+
* ({@link Parsed} is then set), and from tokens otherwise, so SQL the parser cannot fully read is
|
|
20
|
+
* still paged and capped as before.
|
|
21
|
+
*/
|
|
22
|
+
export interface PagingLayout {
|
|
23
|
+
readonly Statement: string;
|
|
24
|
+
/** The leading CTE definitions, each as written; empty when there is no leading WITH. */
|
|
25
|
+
readonly CTEDefinitions: readonly string[];
|
|
26
|
+
/** Whether the leading WITH carries the dialect's recursive keyword. */
|
|
27
|
+
readonly Recursive: boolean;
|
|
28
|
+
/** Where the main statement (after any leading CTEs) starts. */
|
|
29
|
+
readonly MainStart: number;
|
|
30
|
+
/** Where a clause that must stay last starts (the query-hint clause, a row lock); the length when none. */
|
|
31
|
+
readonly TailStart: number;
|
|
32
|
+
/** Whether that last clause is the dialect's query-hint clause (`OPTION (…)`). */
|
|
33
|
+
readonly TailIsQueryHint: boolean;
|
|
34
|
+
/** The caps the main statement carries at its top level, in order. */
|
|
35
|
+
readonly OwnCaps: readonly OwnRowCap[];
|
|
36
|
+
/** The main statement's top-level ORDER BY. */
|
|
37
|
+
readonly OrderBy: {
|
|
38
|
+
readonly Start: number;
|
|
39
|
+
readonly End: number;
|
|
40
|
+
} | null;
|
|
41
|
+
readonly IsSetOperation: boolean;
|
|
42
|
+
readonly IsDistinct: boolean;
|
|
43
|
+
readonly ReturnsDocument: 'json' | 'xml' | null;
|
|
44
|
+
/** Just after the main statement's first top-level `SELECT [ALL | DISTINCT]`; `null` when it has none. */
|
|
45
|
+
readonly SelectListStart: number | null;
|
|
46
|
+
/** The parsed statement; `null` when the layout was read from tokens. */
|
|
47
|
+
readonly Parsed: PagingDocument | null;
|
|
48
|
+
}
|
|
49
|
+
/** Reads the layout of one statement, from its parsed form when it can be read completely, else from tokens. */
|
|
50
|
+
export declare function ReadPagingLayout(statement: string, dialect: SQLDialect): PagingLayout;
|
|
51
|
+
/**
|
|
52
|
+
* The ORDER BY to put outside a derived table that wraps the statement: the statement's ORDER BY
|
|
53
|
+
* with every column qualifier dropped, since the derived table's alias replaces the inner ones.
|
|
54
|
+
* Qualifiers are read as identifier paths, so `a . Name` and `[a] /*c*\/ . [Name]` lose theirs like
|
|
55
|
+
* `a.Name`; a schema-qualified function name keeps its schema. `null` when the statement was read
|
|
56
|
+
* from tokens or has no ORDER BY.
|
|
57
|
+
*/
|
|
58
|
+
export declare function OuterOrderByText(layout: PagingLayout): string | null;
|
|
59
|
+
/**
|
|
60
|
+
* Whether a statement can be counted with its select list replaced by a constant: it was read
|
|
61
|
+
* completely and is one select block with no DISTINCT, GROUP BY, HAVING, WINDOW, QUALIFY, FOR
|
|
62
|
+
* clause or cap of its own, and its select list calls no aggregate or set-returning function.
|
|
63
|
+
* A user-defined aggregate is not recognised by name; such a select list would be counted per
|
|
64
|
+
* input row.
|
|
65
|
+
*/
|
|
66
|
+
export declare function CountBodyCanSelectConstant(layout: PagingLayout): boolean;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=pagingLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagingLayout.d.ts","sourceRoot":"","sources":["../src/pagingLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC5F,OAAO,KAAK,EAAE,SAAS,EAAe,eAAe,EAAc,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACrH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,qFAAqF;AACrF,KAAK,SAAS,GAAG,OAAO,CAAC,eAAe,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAE/D,wGAAwG;AACxG,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,2GAA2G;IAC3G,QAAQ,CAAC,SAAS,E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