@askdb/core 1.0.0-beta.42 → 1.0.0-beta.43
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 +6 -4
- package/dist/ask.d.ts +92 -4
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +234 -23
- package/dist/ask.js.map +1 -1
- package/dist/errors.d.ts +41 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/schema/v2/index.d.ts +1 -1
- package/dist/schema/v2/index.d.ts.map +1 -1
- package/dist/schema/v2/loader.d.ts +9 -1
- package/dist/schema/v2/loader.d.ts.map +1 -1
- package/dist/schema/v2/loader.js +171 -49
- package/dist/schema/v2/loader.js.map +1 -1
- package/dist/schema/v2/normalized.d.ts +33 -0
- package/dist/schema/v2/normalized.d.ts.map +1 -1
- package/dist/schema/v2/parser.d.ts +9 -0
- package/dist/schema/v2/parser.d.ts.map +1 -1
- package/dist/schema/v2/parser.js +18 -2
- package/dist/schema/v2/parser.js.map +1 -1
- package/dist/schema/v2/tenant-policy-loader.d.ts.map +1 -1
- package/dist/schema/v2/tenant-policy-loader.js +7 -3
- package/dist/schema/v2/tenant-policy-loader.js.map +1 -1
- package/dist/schema/v2/tenant-policy.d.ts +28 -21
- package/dist/schema/v2/tenant-policy.d.ts.map +1 -1
- package/dist/schema/v2/tenant-policy.js +67 -11
- package/dist/schema/v2/tenant-policy.js.map +1 -1
- package/dist/sql/bind.d.ts +17 -15
- package/dist/sql/bind.d.ts.map +1 -1
- package/dist/sql/bind.js +34 -172
- package/dist/sql/bind.js.map +1 -1
- package/dist/sql/dialect-spec.d.ts +21 -2
- package/dist/sql/dialect-spec.d.ts.map +1 -1
- package/dist/sql/dialect-spec.js +74 -3
- package/dist/sql/dialect-spec.js.map +1 -1
- package/dist/sql/generate.d.ts +12 -0
- package/dist/sql/generate.d.ts.map +1 -1
- package/dist/sql/generate.js +24 -16
- package/dist/sql/generate.js.map +1 -1
- package/dist/sql/lexer.d.ts +114 -0
- package/dist/sql/lexer.d.ts.map +1 -0
- package/dist/sql/lexer.js +397 -0
- package/dist/sql/lexer.js.map +1 -0
- package/dist/sql/sensitive-guardrail.d.ts +18 -3
- package/dist/sql/sensitive-guardrail.d.ts.map +1 -1
- package/dist/sql/sensitive-guardrail.js +440 -153
- package/dist/sql/sensitive-guardrail.js.map +1 -1
- package/dist/sql/tenant-guardrail.d.ts +70 -8
- package/dist/sql/tenant-guardrail.d.ts.map +1 -1
- package/dist/sql/tenant-guardrail.js +799 -52
- package/dist/sql/tenant-guardrail.js.map +1 -1
- package/dist/sql/tenant-hierarchy.d.ts +19 -0
- package/dist/sql/tenant-hierarchy.d.ts.map +1 -0
- package/dist/sql/tenant-hierarchy.js +53 -0
- package/dist/sql/tenant-hierarchy.js.map +1 -0
- package/dist/sql/tenant-placeholders.d.ts +60 -10
- package/dist/sql/tenant-placeholders.d.ts.map +1 -1
- package/dist/sql/tenant-placeholders.js +229 -58
- package/dist/sql/tenant-placeholders.js.map +1 -1
- package/dist/sql/tenant-prompt.d.ts +4 -0
- package/dist/sql/tenant-prompt.d.ts.map +1 -1
- package/dist/sql/tenant-prompt.js +79 -11
- package/dist/sql/tenant-prompt.js.map +1 -1
- package/dist/sql/tenant-scope-validate.d.ts +3 -1
- package/dist/sql/tenant-scope-validate.d.ts.map +1 -1
- package/dist/sql/tenant-scope-validate.js +5 -2
- package/dist/sql/tenant-scope-validate.js.map +1 -1
- package/dist/sql/validate.d.ts +24 -4
- package/dist/sql/validate.d.ts.map +1 -1
- package/dist/sql/validate.js +123 -37
- package/dist/sql/validate.js.map +1 -1
- package/package.json +6 -5
- package/dist/exec/postgres.d.ts +0 -6
- package/dist/exec/postgres.d.ts.map +0 -1
- package/dist/exec/postgres.js +0 -30
- package/dist/exec/postgres.js.map +0 -1
- package/dist/modes/post-execute-log.d.ts +0 -9
- package/dist/modes/post-execute-log.d.ts.map +0 -1
- package/dist/modes/post-execute-log.js +0 -26
- package/dist/modes/post-execute-log.js.map +0 -1
package/dist/sql/generate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/sql/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,IAAI,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EAAE,uBAAuB,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,GAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/sql/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,IAAI,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EAAE,uBAAuB,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,GAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,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WAAW,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC;IACrG,MAAM,EAAE,IAAI,CACV;QACE,KAAK,EAAE,aAAa,CAAC,qBAAqB;QAC1C,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM;QACjD,kBAAkB;KACnB,EACD,8BAA8B,CAC/B,CAAC;IACF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dialect-aware SQL lexer shared by the read-only validator, the sensitive-identifier
|
|
3
|
+
* guardrail, and the placeholder scanner.
|
|
4
|
+
*
|
|
5
|
+
* It only splits SQL into tokens — it does not parse. Its job is to agree with the
|
|
6
|
+
* target engine about where strings, quoted identifiers, and comments begin and end,
|
|
7
|
+
* because every downstream check ("is there a second statement?", "is `DELETE` a
|
|
8
|
+
* keyword here?", "is `ssn` a column reference?") depends on that boundary. Rules per
|
|
9
|
+
* engine:
|
|
10
|
+
*
|
|
11
|
+
* | Construct | Postgres | MySQL/MariaDB | SQL Server | SQLite |
|
|
12
|
+
* |---------------------------|----------|------------------------|------------|--------|
|
|
13
|
+
* | `'…'` backslash escapes | no | yes (`backslashEscapes`) | no | no |
|
|
14
|
+
* | `E'…'` backslash escapes | yes | — | — | — |
|
|
15
|
+
* | `$tag$…$tag$` | yes | — | — | — |
|
|
16
|
+
* | `"…"` | ident | string | ident | ident |
|
|
17
|
+
* | `` `…` `` | — | ident | — | ident |
|
|
18
|
+
* | `[…]` | — | — | ident (`]]`) | ident |
|
|
19
|
+
* | `#` line comment | — | yes | — | — |
|
|
20
|
+
* | `--` line comment | yes | only before whitespace | yes | yes |
|
|
21
|
+
* | nested `/* … *\/` | yes | no (`/*! … *\/` runs) | yes | no |
|
|
22
|
+
*
|
|
23
|
+
* The lexer never throws: a string, quoted identifier, or comment that runs off the end
|
|
24
|
+
* of the input is returned with `unterminated: true` so callers can fail closed.
|
|
25
|
+
*/
|
|
26
|
+
import type { DialectSpec } from "./dialect-spec.js";
|
|
27
|
+
export type SqlLexerProfileId = "postgres" | "mysql" | "sqlserver" | "sqlite" | "generic";
|
|
28
|
+
export type SqlLexerProfile = {
|
|
29
|
+
id: SqlLexerProfileId;
|
|
30
|
+
/** `'…'` (and MySQL `"…"`) treat backslash as an escape character. */
|
|
31
|
+
backslashEscapes: boolean;
|
|
32
|
+
/** Whether `"…"` is a quoted identifier (ANSI) or a string literal (MySQL default mode). */
|
|
33
|
+
doubleQuote: "identifier" | "string";
|
|
34
|
+
backtickIdentifiers: boolean;
|
|
35
|
+
/** `[…]` quoted identifiers. `"doubled"` accepts `]]` as an escaped `]` (SQL Server). */
|
|
36
|
+
bracketIdentifiers: false | "simple" | "doubled";
|
|
37
|
+
/** Postgres `$tag$ … $tag$` strings. */
|
|
38
|
+
dollarQuotes: boolean;
|
|
39
|
+
/** Postgres `E'…'` strings with backslash escapes. */
|
|
40
|
+
escapeStrings: boolean;
|
|
41
|
+
/** MySQL `#` line comments. */
|
|
42
|
+
hashComments: boolean;
|
|
43
|
+
/** MySQL: `--` starts a comment only when followed by whitespace, a control char, or EOF. */
|
|
44
|
+
dashCommentNeedsSpace: boolean;
|
|
45
|
+
nestedBlockComments: boolean;
|
|
46
|
+
/** MySQL/MariaDB `/*! … *\/` and `/*M! … *\/`: the body is executed, so it is lexed as code. */
|
|
47
|
+
executableComments: boolean;
|
|
48
|
+
/** `@name` / `@@name` variables and parameters. Off for Postgres, where `@` is an operator. */
|
|
49
|
+
atVariables: boolean;
|
|
50
|
+
/** SQL Server `#temp` / `##temp` table names. */
|
|
51
|
+
hashIdentifiers: boolean;
|
|
52
|
+
};
|
|
53
|
+
export declare const POSTGRES_LEXER: SqlLexerProfile;
|
|
54
|
+
export declare const MYSQL_LEXER: SqlLexerProfile;
|
|
55
|
+
export declare const SQLSERVER_LEXER: SqlLexerProfile;
|
|
56
|
+
export declare const SQLITE_LEXER: SqlLexerProfile;
|
|
57
|
+
/**
|
|
58
|
+
* Dialect-agnostic profile for callers that have no dialect (the tenant placeholder
|
|
59
|
+
* path, the sensitive guardrail when no dialect is supplied). Recognizes the union of
|
|
60
|
+
* quoting forms — `'…'`, `E'…'`, `$tag$…$tag$`, `"…"`, `` `…` ``, `[…]` — with the
|
|
61
|
+
* escape rules the owning engine uses, and standard `--` / `/* *\/` comments.
|
|
62
|
+
*/
|
|
63
|
+
export declare const GENERIC_LEXER: SqlLexerProfile;
|
|
64
|
+
/** Every engine-specific profile. Used when the dialect is unknown and each reading must be safe. */
|
|
65
|
+
export declare const ENGINE_LEXER_PROFILES: readonly SqlLexerProfile[];
|
|
66
|
+
/**
|
|
67
|
+
* The lexer profile for a dialect, or `undefined` when the id is not a built-in engine
|
|
68
|
+
* family (callers should then check every profile in {@link ENGINE_LEXER_PROFILES}).
|
|
69
|
+
*
|
|
70
|
+
* `backslashEscapes` on the spec is honored: MySQL with `NO_BACKSLASH_ESCAPES` sets it
|
|
71
|
+
* to `false`; Postgres with `standard_conforming_strings = off` sets it to `true`.
|
|
72
|
+
* An unset value on a MySQL-family spec means the server default (escapes on).
|
|
73
|
+
*/
|
|
74
|
+
export declare function lexerProfileFor(dialect: Pick<DialectSpec, "id" | "backslashEscapes">): SqlLexerProfile | undefined;
|
|
75
|
+
export type SqlTokenKind =
|
|
76
|
+
/** Unquoted identifier or keyword. */
|
|
77
|
+
"word" | "quoted_identifier" | "string" | "number"
|
|
78
|
+
/** `$1`, `:name`, `@name`, `@@name`. */
|
|
79
|
+
| "parameter"
|
|
80
|
+
/** Any other single character, plus `::`. Includes `(`, `)`, `,`, `.`, `;`. */
|
|
81
|
+
| "punct" | "comment";
|
|
82
|
+
export type SqlToken = {
|
|
83
|
+
kind: SqlTokenKind;
|
|
84
|
+
/** Exact source text of the token. */
|
|
85
|
+
text: string;
|
|
86
|
+
/**
|
|
87
|
+
* `word`: the text as written. `quoted_identifier`: the unescaped name.
|
|
88
|
+
* Everything else: same as `text`.
|
|
89
|
+
*/
|
|
90
|
+
value: string;
|
|
91
|
+
/** Lower-cased `value`, for case-insensitive keyword and name matching. */
|
|
92
|
+
lower: string;
|
|
93
|
+
start: number;
|
|
94
|
+
end: number;
|
|
95
|
+
/** Opening delimiter for strings and quoted identifiers (`'`, `"`, `` ` ``, `[`, `$tag$`). */
|
|
96
|
+
quote?: string;
|
|
97
|
+
/**
|
|
98
|
+
* The closing delimiter was never found; the token runs to the end of the input. On a
|
|
99
|
+
* MySQL `/*!` opener it means the matching `*\/` never came (the body is still lexed
|
|
100
|
+
* as code after it).
|
|
101
|
+
*/
|
|
102
|
+
unterminated?: true;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Whether the `--` at `i` starts a line comment. It always does, except on MySQL/MariaDB
|
|
106
|
+
* (`needsSpace`), where it must be followed by whitespace, a control character, or the end
|
|
107
|
+
* of the statement: there `--1` is two minus signs and a number.
|
|
108
|
+
*/
|
|
109
|
+
export declare function startsDashComment(sql: string, i: number, needsSpace: boolean): boolean;
|
|
110
|
+
/** Split `sql` into tokens under `profile`. Whitespace is dropped; comments are kept. */
|
|
111
|
+
export declare function lexSql(sql: string, profile: SqlLexerProfile): SqlToken[];
|
|
112
|
+
/** True when any token ran off the end of the input. */
|
|
113
|
+
export declare function hasUnterminatedToken(tokens: readonly SqlToken[]): boolean;
|
|
114
|
+
//# sourceMappingURL=lexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexer.d.ts","sourceRoot":"","sources":["../../src/sql/lexer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE1F,MAAM,MAAM,eAAe,GAA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AAM,QAAQ,GAAG;IACrB,IAAI,EAAE,YAAY,CAAC;IACnB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,8FAA8F;IAC9F,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC;CACrB,CAAC;AAQF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAItF;AAED,yFAAyF;AACzF,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,EAAE,CAsQxE;AAED,wDAAwD;AACxD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,OAAO,CAEzE"}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
export const POSTGRES_LEXER = {
|
|
2
|
+
id: "postgres",
|
|
3
|
+
backslashEscapes: false,
|
|
4
|
+
doubleQuote: "identifier",
|
|
5
|
+
backtickIdentifiers: false,
|
|
6
|
+
bracketIdentifiers: false,
|
|
7
|
+
dollarQuotes: true,
|
|
8
|
+
escapeStrings: true,
|
|
9
|
+
hashComments: false,
|
|
10
|
+
dashCommentNeedsSpace: false,
|
|
11
|
+
nestedBlockComments: true,
|
|
12
|
+
executableComments: false,
|
|
13
|
+
atVariables: false,
|
|
14
|
+
hashIdentifiers: false,
|
|
15
|
+
};
|
|
16
|
+
export const MYSQL_LEXER = {
|
|
17
|
+
id: "mysql",
|
|
18
|
+
backslashEscapes: true,
|
|
19
|
+
doubleQuote: "string",
|
|
20
|
+
backtickIdentifiers: true,
|
|
21
|
+
bracketIdentifiers: false,
|
|
22
|
+
dollarQuotes: false,
|
|
23
|
+
escapeStrings: false,
|
|
24
|
+
hashComments: true,
|
|
25
|
+
dashCommentNeedsSpace: true,
|
|
26
|
+
nestedBlockComments: false,
|
|
27
|
+
executableComments: true,
|
|
28
|
+
atVariables: true,
|
|
29
|
+
hashIdentifiers: false,
|
|
30
|
+
};
|
|
31
|
+
export const SQLSERVER_LEXER = {
|
|
32
|
+
id: "sqlserver",
|
|
33
|
+
backslashEscapes: false,
|
|
34
|
+
doubleQuote: "identifier",
|
|
35
|
+
backtickIdentifiers: false,
|
|
36
|
+
bracketIdentifiers: "doubled",
|
|
37
|
+
dollarQuotes: false,
|
|
38
|
+
escapeStrings: false,
|
|
39
|
+
hashComments: false,
|
|
40
|
+
dashCommentNeedsSpace: false,
|
|
41
|
+
nestedBlockComments: true,
|
|
42
|
+
executableComments: false,
|
|
43
|
+
atVariables: true,
|
|
44
|
+
hashIdentifiers: true,
|
|
45
|
+
};
|
|
46
|
+
export const SQLITE_LEXER = {
|
|
47
|
+
id: "sqlite",
|
|
48
|
+
backslashEscapes: false,
|
|
49
|
+
doubleQuote: "identifier",
|
|
50
|
+
backtickIdentifiers: true,
|
|
51
|
+
bracketIdentifiers: "simple",
|
|
52
|
+
dollarQuotes: false,
|
|
53
|
+
escapeStrings: false,
|
|
54
|
+
hashComments: false,
|
|
55
|
+
dashCommentNeedsSpace: false,
|
|
56
|
+
nestedBlockComments: false,
|
|
57
|
+
executableComments: false,
|
|
58
|
+
atVariables: true,
|
|
59
|
+
hashIdentifiers: false,
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Dialect-agnostic profile for callers that have no dialect (the tenant placeholder
|
|
63
|
+
* path, the sensitive guardrail when no dialect is supplied). Recognizes the union of
|
|
64
|
+
* quoting forms — `'…'`, `E'…'`, `$tag$…$tag$`, `"…"`, `` `…` ``, `[…]` — with the
|
|
65
|
+
* escape rules the owning engine uses, and standard `--` / `/* *\/` comments.
|
|
66
|
+
*/
|
|
67
|
+
export const GENERIC_LEXER = {
|
|
68
|
+
id: "generic",
|
|
69
|
+
backslashEscapes: false,
|
|
70
|
+
doubleQuote: "identifier",
|
|
71
|
+
backtickIdentifiers: true,
|
|
72
|
+
bracketIdentifiers: "doubled",
|
|
73
|
+
dollarQuotes: true,
|
|
74
|
+
escapeStrings: true,
|
|
75
|
+
hashComments: false,
|
|
76
|
+
dashCommentNeedsSpace: false,
|
|
77
|
+
nestedBlockComments: false,
|
|
78
|
+
executableComments: false,
|
|
79
|
+
atVariables: true,
|
|
80
|
+
hashIdentifiers: false,
|
|
81
|
+
};
|
|
82
|
+
/** Every engine-specific profile. Used when the dialect is unknown and each reading must be safe. */
|
|
83
|
+
export const ENGINE_LEXER_PROFILES = [
|
|
84
|
+
POSTGRES_LEXER,
|
|
85
|
+
MYSQL_LEXER,
|
|
86
|
+
SQLSERVER_LEXER,
|
|
87
|
+
SQLITE_LEXER,
|
|
88
|
+
];
|
|
89
|
+
/**
|
|
90
|
+
* The lexer profile for a dialect, or `undefined` when the id is not a built-in engine
|
|
91
|
+
* family (callers should then check every profile in {@link ENGINE_LEXER_PROFILES}).
|
|
92
|
+
*
|
|
93
|
+
* `backslashEscapes` on the spec is honored: MySQL with `NO_BACKSLASH_ESCAPES` sets it
|
|
94
|
+
* to `false`; Postgres with `standard_conforming_strings = off` sets it to `true`.
|
|
95
|
+
* An unset value on a MySQL-family spec means the server default (escapes on).
|
|
96
|
+
*/
|
|
97
|
+
export function lexerProfileFor(dialect) {
|
|
98
|
+
switch (dialect.id) {
|
|
99
|
+
case "postgres":
|
|
100
|
+
case "cockroachdb":
|
|
101
|
+
return dialect.backslashEscapes === true
|
|
102
|
+
? { ...POSTGRES_LEXER, backslashEscapes: true }
|
|
103
|
+
: POSTGRES_LEXER;
|
|
104
|
+
case "mysql":
|
|
105
|
+
case "mariadb":
|
|
106
|
+
return dialect.backslashEscapes === false
|
|
107
|
+
? { ...MYSQL_LEXER, backslashEscapes: false }
|
|
108
|
+
: MYSQL_LEXER;
|
|
109
|
+
case "sqlserver":
|
|
110
|
+
return SQLSERVER_LEXER;
|
|
111
|
+
case "sqlite":
|
|
112
|
+
return SQLITE_LEXER;
|
|
113
|
+
default:
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const WORD_START = /[A-Za-z_\u0080-]/;
|
|
118
|
+
const WORD_CHAR = /[A-Za-z0-9_$\u0080-]/;
|
|
119
|
+
const DIGIT = /[0-9]/;
|
|
120
|
+
const HEX = /[0-9A-Fa-f]/;
|
|
121
|
+
const DOLLAR_TAG = /^\$([A-Za-z_\u0080-][A-Za-z0-9_\u0080-]*)?\$/;
|
|
122
|
+
/**
|
|
123
|
+
* Whether the `--` at `i` starts a line comment. It always does, except on MySQL/MariaDB
|
|
124
|
+
* (`needsSpace`), where it must be followed by whitespace, a control character, or the end
|
|
125
|
+
* of the statement: there `--1` is two minus signs and a number.
|
|
126
|
+
*/
|
|
127
|
+
export function startsDashComment(sql, i, needsSpace) {
|
|
128
|
+
if (sql[i] !== "-" || sql[i + 1] !== "-")
|
|
129
|
+
return false;
|
|
130
|
+
const after = sql[i + 2];
|
|
131
|
+
return !needsSpace || after === undefined || /[\s\x00-\x1f]/.test(after);
|
|
132
|
+
}
|
|
133
|
+
/** Split `sql` into tokens under `profile`. Whitespace is dropped; comments are kept. */
|
|
134
|
+
export function lexSql(sql, profile) {
|
|
135
|
+
const tokens = [];
|
|
136
|
+
const n = sql.length;
|
|
137
|
+
let i = 0;
|
|
138
|
+
/** Index in `tokens` of the open MySQL `/*! … *\/` executable-comment opener, or -1. */
|
|
139
|
+
let executableOpener = -1;
|
|
140
|
+
const push = (kind, start, end, extra) => {
|
|
141
|
+
const text = sql.slice(start, end);
|
|
142
|
+
const value = extra?.value ?? text;
|
|
143
|
+
const token = { kind, text, value, lower: value.toLowerCase(), start, end };
|
|
144
|
+
if (extra?.quote !== undefined)
|
|
145
|
+
token.quote = extra.quote;
|
|
146
|
+
if (extra?.unterminated)
|
|
147
|
+
token.unterminated = true;
|
|
148
|
+
tokens.push(token);
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Scan a delimited run starting after the opening delimiter at `from`. `close` doubled
|
|
152
|
+
* is always an escaped delimiter; `backslash` additionally makes `\x` an escape.
|
|
153
|
+
*/
|
|
154
|
+
const scanDelimited = (from, close, backslash) => {
|
|
155
|
+
let j = from;
|
|
156
|
+
let value = "";
|
|
157
|
+
while (j < n) {
|
|
158
|
+
const c = sql[j];
|
|
159
|
+
if (backslash && c === "\\") {
|
|
160
|
+
value += sql.slice(j, j + 2);
|
|
161
|
+
j += 2;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (c === close) {
|
|
165
|
+
if (sql[j + 1] === close) {
|
|
166
|
+
value += close;
|
|
167
|
+
j += 2;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
return { end: j + 1, value, terminated: true };
|
|
171
|
+
}
|
|
172
|
+
value += c;
|
|
173
|
+
j++;
|
|
174
|
+
}
|
|
175
|
+
return { end: n, value, terminated: false };
|
|
176
|
+
};
|
|
177
|
+
const lexString = (start, quoteAt, backslash, kind) => {
|
|
178
|
+
const q = sql[quoteAt];
|
|
179
|
+
const r = scanDelimited(quoteAt + 1, q, backslash);
|
|
180
|
+
push(kind, start, Math.min(r.end, n), {
|
|
181
|
+
quote: q,
|
|
182
|
+
...(kind === "quoted_identifier" ? { value: r.value } : {}),
|
|
183
|
+
unterminated: !r.terminated,
|
|
184
|
+
});
|
|
185
|
+
i = r.end;
|
|
186
|
+
};
|
|
187
|
+
while (i < n) {
|
|
188
|
+
const ch = sql[i];
|
|
189
|
+
const next = sql[i + 1];
|
|
190
|
+
if (/\s/.test(ch)) {
|
|
191
|
+
i++;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
// ---- comments -------------------------------------------------------
|
|
195
|
+
if (ch === "-" && next === "-") {
|
|
196
|
+
if (startsDashComment(sql, i, profile.dashCommentNeedsSpace)) {
|
|
197
|
+
let j = i + 2;
|
|
198
|
+
while (j < n && sql[j] !== "\n" && sql[j] !== "\r")
|
|
199
|
+
j++;
|
|
200
|
+
push("comment", i, j);
|
|
201
|
+
i = j;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (ch === "#" && profile.hashComments) {
|
|
206
|
+
let j = i + 1;
|
|
207
|
+
while (j < n && sql[j] !== "\n" && sql[j] !== "\r")
|
|
208
|
+
j++;
|
|
209
|
+
push("comment", i, j);
|
|
210
|
+
i = j;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (ch === "*" && next === "/" && executableOpener !== -1) {
|
|
214
|
+
push("comment", i, i + 2);
|
|
215
|
+
executableOpener = -1;
|
|
216
|
+
i += 2;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (ch === "/" && next === "*") {
|
|
220
|
+
if (profile.executableComments && executableOpener === -1) {
|
|
221
|
+
const exec = /^\/\*M?!\d*/.exec(sql.slice(i));
|
|
222
|
+
if (exec) {
|
|
223
|
+
executableOpener = tokens.length;
|
|
224
|
+
push("comment", i, i + exec[0].length);
|
|
225
|
+
i += exec[0].length;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
let j = i + 2;
|
|
230
|
+
let depth = 1;
|
|
231
|
+
while (j < n) {
|
|
232
|
+
if (sql[j] === "*" && sql[j + 1] === "/") {
|
|
233
|
+
depth--;
|
|
234
|
+
j += 2;
|
|
235
|
+
if (depth === 0)
|
|
236
|
+
break;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (profile.nestedBlockComments && sql[j] === "/" && sql[j + 1] === "*") {
|
|
240
|
+
depth++;
|
|
241
|
+
j += 2;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
j++;
|
|
245
|
+
}
|
|
246
|
+
push("comment", i, Math.min(j, n), { unterminated: depth > 0 });
|
|
247
|
+
i = j;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
// ---- strings and quoted identifiers ---------------------------------
|
|
251
|
+
if (ch === "'") {
|
|
252
|
+
lexString(i, i, profile.backslashEscapes, "string");
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (ch === '"') {
|
|
256
|
+
if (profile.doubleQuote === "identifier")
|
|
257
|
+
lexString(i, i, false, "quoted_identifier");
|
|
258
|
+
else
|
|
259
|
+
lexString(i, i, profile.backslashEscapes, "string");
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
if (ch === "`" && profile.backtickIdentifiers) {
|
|
263
|
+
lexString(i, i, false, "quoted_identifier");
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (ch === "[" && profile.bracketIdentifiers) {
|
|
267
|
+
let j = i + 1;
|
|
268
|
+
let value = "";
|
|
269
|
+
let terminated = false;
|
|
270
|
+
while (j < n) {
|
|
271
|
+
if (sql[j] === "]") {
|
|
272
|
+
if (profile.bracketIdentifiers === "doubled" && sql[j + 1] === "]") {
|
|
273
|
+
value += "]";
|
|
274
|
+
j += 2;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
j++;
|
|
278
|
+
terminated = true;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
value += sql[j];
|
|
282
|
+
j++;
|
|
283
|
+
}
|
|
284
|
+
push("quoted_identifier", i, j, { value, quote: "[", unterminated: !terminated });
|
|
285
|
+
i = j;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (ch === "$") {
|
|
289
|
+
if (profile.dollarQuotes) {
|
|
290
|
+
const tag = DOLLAR_TAG.exec(sql.slice(i));
|
|
291
|
+
if (tag) {
|
|
292
|
+
const opener = tag[0];
|
|
293
|
+
const closeAt = sql.indexOf(opener, i + opener.length);
|
|
294
|
+
const end = closeAt === -1 ? n : closeAt + opener.length;
|
|
295
|
+
push("string", i, end, { quote: opener, unterminated: closeAt === -1 });
|
|
296
|
+
i = end;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (next !== undefined && (DIGIT.test(next) || (!profile.dollarQuotes && WORD_START.test(next)))) {
|
|
301
|
+
let j = i + 1;
|
|
302
|
+
while (j < n && WORD_CHAR.test(sql[j]) && sql[j] !== "$")
|
|
303
|
+
j++;
|
|
304
|
+
push("parameter", i, j);
|
|
305
|
+
i = j;
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// ---- words (and prefixed string literals) ---------------------------
|
|
310
|
+
if (WORD_START.test(ch) || (ch === "#" && profile.hashIdentifiers && next !== undefined && (next === "#" || WORD_START.test(next)))) {
|
|
311
|
+
let j = i + 1;
|
|
312
|
+
while (j < n && (WORD_CHAR.test(sql[j]) || (profile.hashIdentifiers && sql[j] === "#")))
|
|
313
|
+
j++;
|
|
314
|
+
const word = sql.slice(i, j);
|
|
315
|
+
if (sql[j] === "'" && j - i === 1) {
|
|
316
|
+
const prefix = word.toLowerCase();
|
|
317
|
+
if (prefix === "e" && profile.escapeStrings) {
|
|
318
|
+
lexString(i, j, true, "string");
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (prefix === "n" || prefix === "x" || prefix === "b") {
|
|
322
|
+
lexString(i, j, profile.backslashEscapes, "string");
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
push("word", i, j);
|
|
327
|
+
i = j;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
// ---- numbers --------------------------------------------------------
|
|
331
|
+
if (DIGIT.test(ch) || (ch === "." && next !== undefined && DIGIT.test(next))) {
|
|
332
|
+
let j = i;
|
|
333
|
+
if (ch === "0" && (next === "x" || next === "X") && HEX.test(sql[i + 2] ?? "")) {
|
|
334
|
+
j = i + 2;
|
|
335
|
+
while (j < n && HEX.test(sql[j]))
|
|
336
|
+
j++;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
while (j < n && DIGIT.test(sql[j]))
|
|
340
|
+
j++;
|
|
341
|
+
if (sql[j] === "." && sql[j + 1] !== ".") {
|
|
342
|
+
j++;
|
|
343
|
+
while (j < n && DIGIT.test(sql[j]))
|
|
344
|
+
j++;
|
|
345
|
+
}
|
|
346
|
+
if ((sql[j] === "e" || sql[j] === "E") && /^[eE][+-]?[0-9]/.test(sql.slice(j))) {
|
|
347
|
+
j += sql[j + 1] === "+" || sql[j + 1] === "-" ? 2 : 1;
|
|
348
|
+
while (j < n && DIGIT.test(sql[j]))
|
|
349
|
+
j++;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// Trailing letters (`1from`, MySQL `1abc`) are lexed as a separate word so a keyword
|
|
353
|
+
// glued to a number is still seen.
|
|
354
|
+
push("number", i, j);
|
|
355
|
+
i = j;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
// ---- parameters and punctuation -------------------------------------
|
|
359
|
+
if (ch === ":" && next === ":") {
|
|
360
|
+
push("punct", i, i + 2);
|
|
361
|
+
i += 2;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (ch === ":" && next !== undefined && WORD_START.test(next)) {
|
|
365
|
+
let j = i + 1;
|
|
366
|
+
while (j < n && WORD_CHAR.test(sql[j]))
|
|
367
|
+
j++;
|
|
368
|
+
push("parameter", i, j);
|
|
369
|
+
i = j;
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (ch === "@" && profile.atVariables) {
|
|
373
|
+
let j = i + 1;
|
|
374
|
+
if (sql[j] === "@")
|
|
375
|
+
j++;
|
|
376
|
+
if (j < n && WORD_START.test(sql[j])) {
|
|
377
|
+
while (j < n && WORD_CHAR.test(sql[j]))
|
|
378
|
+
j++;
|
|
379
|
+
push("parameter", i, j);
|
|
380
|
+
i = j;
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
push("punct", i, i + 1);
|
|
385
|
+
i++;
|
|
386
|
+
}
|
|
387
|
+
// An executable comment whose `*\/` never came: its body was lexed as code, but the
|
|
388
|
+
// comment itself runs off the end, so flag the opener like any other unclosed comment.
|
|
389
|
+
if (executableOpener !== -1)
|
|
390
|
+
tokens[executableOpener].unterminated = true;
|
|
391
|
+
return tokens;
|
|
392
|
+
}
|
|
393
|
+
/** True when any token ran off the end of the input. */
|
|
394
|
+
export function hasUnterminatedToken(tokens) {
|
|
395
|
+
return tokens.some((t) => t.unterminated === true);
|
|
396
|
+
}
|
|
397
|
+
//# sourceMappingURL=lexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexer.js","sourceRoot":"","sources":["../../src/sql/lexer.ts"],"names":[],"mappings":"AAuDA,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,EAAE,EAAE,UAAU;IACd,gBAAgB,EAAE,KAAK;IACvB,WAAW,EAAE,YAAY;IACzB,mBAAmB,EAAE,KAAK;IAC1B,kBAAkB,EAAE,KAAK;IACzB,YAAY,EAAE,IAAI;IAClB,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,KAAK;IACnB,qBAAqB,EAAE,KAAK;IAC5B,mBAAmB,EAAE,IAAI;IACzB,kBAAkB,EAAE,KAAK;IACzB,WAAW,EAAE,KAAK;IAClB,eAAe,EAAE,KAAK;CACvB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAoB;IAC1C,EAAE,EAAE,OAAO;IACX,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,QAAQ;IACrB,mBAAmB,EAAE,IAAI;IACzB,kBAAkB,EAAE,KAAK;IACzB,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,KAAK;IACpB,YAAY,EAAE,IAAI;IAClB,qBAAqB,EAAE,IAAI;IAC3B,mBAAmB,EAAE,KAAK;IAC1B,kBAAkB,EAAE,IAAI;IACxB,WAAW,EAAE,IAAI;IACjB,eAAe,EAAE,KAAK;CACvB,CAAC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AAC,EAAE,CAAC,CAAC,CAAC;YACxB,CAAC,GAAG,CAAC,CAAC;YACN,SAAS;QACX,CAAC;QACD,IAAI,EAAE,KAAK,GAAG,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACtC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG;gBAAE,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC;gBACtC,OAAO,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC;oBAAE,CAAC,EAAE,CAAC;gBAC7C,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;gBACxB,CAAC,GAAG,CAAC,CAAC;gBACN,SAAS;YACX,CAAC;QACH,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACxB,CAAC,EAAE,CAAC;IACN,CAAC;IAED,oFAAoF;IACpF,uFAAuF;IACvF,IAAI,gBAAgB,KAAK,CAAC,CAAC;QAAE,MAAM,CAAC,gBAAgB,CAAE,CAAC,YAAY,GAAG,IAAI,CAAC;IAE3E,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,oBAAoB,CAAC,MAA2B;IAC9D,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type SensitiveReference, type SensitiveScopeReport } from "../errors.js";
|
|
2
2
|
import type { AnyNormalizedSchema } from "../schema/types.js";
|
|
3
|
+
import type { DialectSpec } from "./dialect-spec.js";
|
|
3
4
|
export type SensitiveGuardrailMode = "warn" | "strict";
|
|
4
5
|
export type ValidateSensitiveReferencesOptions = {
|
|
5
6
|
/**
|
|
@@ -8,6 +9,13 @@ export type ValidateSensitiveReferencesOptions = {
|
|
|
8
9
|
* proven clean (references found, or scope could not be resolved).
|
|
9
10
|
*/
|
|
10
11
|
mode?: SensitiveGuardrailMode;
|
|
12
|
+
/**
|
|
13
|
+
* The engine the SQL targets, so strings, quoted identifiers, and comments are lexed
|
|
14
|
+
* the way that engine reads them (e.g. MySQL backslash escapes, Postgres `E'…'`).
|
|
15
|
+
* When omitted, references are collected under every built-in engine's reading, which
|
|
16
|
+
* is conservative and can over-report in rare cases.
|
|
17
|
+
*/
|
|
18
|
+
dialect?: Pick<DialectSpec, "id" | "backslashEscapes">;
|
|
11
19
|
};
|
|
12
20
|
export type SensitiveGuardrailResult = {
|
|
13
21
|
/** True only when nothing sensitive was referenced **and** table scope was fully resolved. */
|
|
@@ -31,10 +39,17 @@ export type SensitiveGuardrailResult = {
|
|
|
31
39
|
* are resolved first. When scope cannot be resolved (no resolvable table source, or a
|
|
32
40
|
* qualifier that binds to nothing known), the check fails conservatively — it widens
|
|
33
41
|
* matching and reports why in {@link SensitiveGuardrailResult.unresolvedScope} — rather
|
|
34
|
-
* than passing silently.
|
|
42
|
+
* than passing silently. A string, quoted identifier, or comment that never closes is
|
|
43
|
+
* reported the same way (`UNTERMINATED_TOKEN`).
|
|
44
|
+
*
|
|
45
|
+
* `SELECT *`, `alias.*`, and whole-row references such as `row_to_json(alias)` count as
|
|
46
|
+
* referencing every sensitive column of the table they reach. They expand per query
|
|
47
|
+
* block: a bare `*` covers its own `SELECT`'s FROM/JOIN tables, and an alias resolves in
|
|
48
|
+
* its own block first, then in enclosing blocks. When the block structure cannot be
|
|
49
|
+
* read with confidence, they expand against every table in the statement.
|
|
35
50
|
*
|
|
36
|
-
* Heuristic, not a SQL parser
|
|
37
|
-
* database-side column privileges.
|
|
51
|
+
* Heuristic, not a SQL parser, and not a security boundary. It is defense in depth for
|
|
52
|
+
* review and enforcement; database-side column privileges are the real control.
|
|
38
53
|
*/
|
|
39
54
|
export declare function validateSensitiveReferences(sql: string, schema: AnyNormalizedSchema, options?: ValidateSensitiveReferencesOptions): SensitiveGuardrailResult;
|
|
40
55
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sensitive-guardrail.d.ts","sourceRoot":"","sources":["../../src/sql/sensitive-guardrail.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAGvB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"sensitive-guardrail.d.ts","sourceRoot":"","sources":["../../src/sql/sensitive-guardrail.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAGvB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAUrD,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEvD,MAAM,MAAM,kCAAkC,GAAG;IAC/C;;;;OAIG;IACH,IAAI,CAAC,EAAE,sBAAsB,CAAC;IAC9B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,kBAAkB,CAAC,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,8FAA8F;IAC9F,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,kBAAkB,EAAE,CAAC;IACjC,8FAA8F;IAC9F,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,2BAA2B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