@askdb/core 1.0.0-beta.43 → 1.0.0-beta.45
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 +15 -12
- package/dist/ask.d.ts +39 -38
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +135 -309
- package/dist/ask.js.map +1 -1
- package/dist/enrichment/index.d.ts +1 -1
- package/dist/enrichment/index.d.ts.map +1 -1
- package/dist/enrichment/prompt.d.ts +3 -3
- package/dist/enrichment/prompt.d.ts.map +1 -1
- package/dist/enrichment/prompt.js +41 -17
- package/dist/enrichment/prompt.js.map +1 -1
- package/dist/enrichment/suggest.d.ts +2 -2
- package/dist/enrichment/suggest.d.ts.map +1 -1
- package/dist/enrichment/suggest.js +6 -2
- package/dist/enrichment/suggest.js.map +1 -1
- package/dist/enrichment/types.d.ts +20 -1
- package/dist/enrichment/types.d.ts.map +1 -1
- package/dist/errors.d.ts +68 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/retrieval/synthesize-ddl.d.ts +11 -1
- package/dist/retrieval/synthesize-ddl.d.ts.map +1 -1
- package/dist/retrieval/synthesize-ddl.js +39 -34
- package/dist/retrieval/synthesize-ddl.js.map +1 -1
- package/dist/schema/normalize.d.ts +16 -0
- package/dist/schema/normalize.d.ts.map +1 -1
- package/dist/schema/normalize.js +1 -0
- package/dist/schema/normalize.js.map +1 -1
- package/dist/schema/v2/format.d.ts +35 -1
- package/dist/schema/v2/format.d.ts.map +1 -1
- package/dist/schema/v2/format.js +69 -22
- package/dist/schema/v2/format.js.map +1 -1
- package/dist/schema/v2/index.d.ts +2 -0
- package/dist/schema/v2/index.d.ts.map +1 -1
- package/dist/schema/v2/index.js +1 -0
- package/dist/schema/v2/index.js.map +1 -1
- package/dist/schema/v2/loader.d.ts +30 -4
- package/dist/schema/v2/loader.d.ts.map +1 -1
- package/dist/schema/v2/loader.js +90 -28
- package/dist/schema/v2/loader.js.map +1 -1
- package/dist/schema/v2/mentions.d.ts +43 -0
- package/dist/schema/v2/mentions.d.ts.map +1 -0
- package/dist/schema/v2/mentions.js +101 -0
- package/dist/schema/v2/mentions.js.map +1 -0
- package/dist/schema/v2/normalized.d.ts +5 -0
- package/dist/schema/v2/normalized.d.ts.map +1 -1
- package/dist/schema/v2/tenant-policy.d.ts +2 -2
- package/dist/sql/bind.d.ts +18 -5
- package/dist/sql/bind.d.ts.map +1 -1
- package/dist/sql/bind.js +36 -15
- package/dist/sql/bind.js.map +1 -1
- package/dist/sql/dialect-spec.d.ts +27 -1
- package/dist/sql/dialect-spec.d.ts.map +1 -1
- package/dist/sql/dialect-spec.js +20 -1
- package/dist/sql/dialect-spec.js.map +1 -1
- package/dist/sql/generate.d.ts +19 -11
- package/dist/sql/generate.d.ts.map +1 -1
- package/dist/sql/generate.js +72 -34
- package/dist/sql/generate.js.map +1 -1
- package/dist/sql/guardrail-decide.d.ts +56 -0
- package/dist/sql/guardrail-decide.d.ts.map +1 -0
- package/dist/sql/guardrail-decide.js +161 -0
- package/dist/sql/guardrail-decide.js.map +1 -0
- package/dist/sql/guardrails.d.ts +52 -0
- package/dist/sql/guardrails.d.ts.map +1 -0
- package/dist/sql/guardrails.js +100 -0
- package/dist/sql/guardrails.js.map +1 -0
- package/dist/sql/index.d.ts +4 -2
- package/dist/sql/index.d.ts.map +1 -1
- package/dist/sql/index.js +4 -2
- package/dist/sql/index.js.map +1 -1
- package/dist/sql/lexer.d.ts +13 -0
- package/dist/sql/lexer.d.ts.map +1 -1
- package/dist/sql/lexer.js +42 -7
- package/dist/sql/lexer.js.map +1 -1
- package/dist/sql/prompt-identifiers.d.ts +20 -0
- package/dist/sql/prompt-identifiers.d.ts.map +1 -0
- package/dist/sql/prompt-identifiers.js +64 -0
- package/dist/sql/prompt-identifiers.js.map +1 -0
- package/dist/sql/prompt.d.ts +7 -1
- package/dist/sql/prompt.d.ts.map +1 -1
- package/dist/sql/prompt.js +24 -3
- package/dist/sql/prompt.js.map +1 -1
- package/dist/sql/rebind.d.ts +89 -0
- package/dist/sql/rebind.d.ts.map +1 -0
- package/dist/sql/rebind.js +175 -0
- package/dist/sql/rebind.js.map +1 -0
- package/dist/sql/reserved-words.d.ts +15 -0
- package/dist/sql/reserved-words.d.ts.map +1 -0
- package/dist/sql/reserved-words.js +102 -0
- package/dist/sql/reserved-words.js.map +1 -0
- package/dist/sql/sensitive-guardrail.d.ts +7 -2
- package/dist/sql/sensitive-guardrail.d.ts.map +1 -1
- package/dist/sql/sensitive-guardrail.js +20 -37
- package/dist/sql/sensitive-guardrail.js.map +1 -1
- package/dist/sql/tenant-guardrail.d.ts +3 -14
- package/dist/sql/tenant-guardrail.d.ts.map +1 -1
- package/dist/sql/tenant-guardrail.js +16 -65
- package/dist/sql/tenant-guardrail.js.map +1 -1
- package/dist/sql/tenant-placeholders.d.ts +12 -23
- package/dist/sql/tenant-placeholders.d.ts.map +1 -1
- package/dist/sql/tenant-placeholders.js +46 -27
- package/dist/sql/tenant-placeholders.js.map +1 -1
- package/dist/sql/tenant-scope-expand.d.ts +46 -0
- package/dist/sql/tenant-scope-expand.d.ts.map +1 -0
- package/dist/sql/tenant-scope-expand.js +101 -0
- package/dist/sql/tenant-scope-expand.js.map +1 -0
- package/dist/sql/tsql-batch.d.ts +56 -0
- package/dist/sql/tsql-batch.d.ts.map +1 -0
- package/dist/sql/tsql-batch.js +246 -0
- package/dist/sql/tsql-batch.js.map +1 -0
- package/dist/sql/validate.d.ts +16 -3
- package/dist/sql/validate.d.ts.map +1 -1
- package/dist/sql/validate.js +43 -8
- package/dist/sql/validate.js.map +1 -1
- package/package.json +9 -6
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a T-SQL batch starts a second statement without a `;`.
|
|
3
|
+
*
|
|
4
|
+
* SQL Server needs no separator between statements: `SELECT 1 SELECT 2` is two
|
|
5
|
+
* statements, and Studio's Execute runs the validated SQL inside a batch. This check
|
|
6
|
+
* finds the second statement in SQL that is otherwise a single SELECT. Only the top
|
|
7
|
+
* level (outside every bracket) is checked: a second statement inside brackets is a
|
|
8
|
+
* syntax error, and SQL Server runs nothing from a batch that does not compile.
|
|
9
|
+
*
|
|
10
|
+
* Verbs that start a statement (`DECLARE`, `WHILE`, `EXEC`, …) are the keyword
|
|
11
|
+
* denylist's job (`SQLSERVER_DIALECT.extraForbiddenKeywords`). This module covers the
|
|
12
|
+
* statements no verb announces:
|
|
13
|
+
*
|
|
14
|
+
* - a top-level `SELECT` that follows no set operator and is not the main query
|
|
15
|
+
* after a leading `WITH` list;
|
|
16
|
+
* - a top-level `(SELECT …` right after a complete expression, such as
|
|
17
|
+
* `SELECT 1 (SELECT 2)`. After a keyword, an operator, a comma or a function name
|
|
18
|
+
* the bracket opens a subquery instead;
|
|
19
|
+
* - a label: a `:` written directly against anything but `(`, a comma or an operator.
|
|
20
|
+
*
|
|
21
|
+
* It also rejects code SQL Server may split into tokens differently from the lexer
|
|
22
|
+
* ({@link findAmbiguousTsqlText}): rather than copy every corner of SQL Server's
|
|
23
|
+
* tokenizer, the check accepts plain code only.
|
|
24
|
+
*/
|
|
25
|
+
import type { SqlToken } from "./lexer.js";
|
|
26
|
+
/** The token where a second statement starts. */
|
|
27
|
+
export type TsqlStatementBoundary = {
|
|
28
|
+
token: SqlToken;
|
|
29
|
+
/**
|
|
30
|
+
* `select`: a top-level SELECT that continues nothing. `query`: a top-level
|
|
31
|
+
* `(SELECT …` after a complete expression. `label`: a `:` that ends a label.
|
|
32
|
+
*/
|
|
33
|
+
kind: "select" | "query" | "label";
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Code SQL Server may split into tokens differently from the lexer, described for an
|
|
37
|
+
* error message, or `undefined`. Text inside strings and quoted identifiers is not
|
|
38
|
+
* checked; `tokens` holds no comments. Fails closed on:
|
|
39
|
+
*
|
|
40
|
+
* - a character outside {@link PLAIN_CODE}: Unicode whitespace and format characters
|
|
41
|
+
* (U+00A0, U+200B, U+FEFF), symbols, currency signs other than `$`, `\` (a money
|
|
42
|
+
* sign to SQL Server) and ASCII control characters;
|
|
43
|
+
* - a money sign with no digits after it (`$ .5` is one money literal to SQL Server);
|
|
44
|
+
* - a number written directly against a word or variable (`1ESELECT`, `0xSELECT`);
|
|
45
|
+
* - a `?` written directly against a name or number: Studio binds it as `@p0`, which
|
|
46
|
+
* SQL Server reads as part of that name (`x?:` becomes the label `x@p0:`).
|
|
47
|
+
*
|
|
48
|
+
* Model-written SQL contains none of these.
|
|
49
|
+
*/
|
|
50
|
+
export declare function findAmbiguousTsqlText(sql: string, tokens: readonly SqlToken[]): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The first place `tokens` starts a second T-SQL statement, or `undefined`.
|
|
53
|
+
* `tokens` holds no comments and no trailing `;`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function findTsqlStatementBoundary(tokens: readonly SqlToken[]): TsqlStatementBoundary | undefined;
|
|
56
|
+
//# sourceMappingURL=tsql-batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsql-batch.d.ts","sourceRoot":"","sources":["../../src/sql/tsql-batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,iDAAiD;AACjD,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;CACpC,CAAC;AAqCF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,GAAG,SAAS,CA6BlG;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,qBAAqB,GAAG,SAAS,CA8HxG"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { SQLSERVER_RESERVED_WORDS } from "./reserved-words.js";
|
|
2
|
+
/**
|
|
3
|
+
* Reserved words after which an expression or a subquery follows, so a `(SELECT …`
|
|
4
|
+
* after one of them is a subquery. Each is reserved in T-SQL, so none is an alias.
|
|
5
|
+
*/
|
|
6
|
+
const EXPRESSION_KEYWORDS = new Set([
|
|
7
|
+
"select", "distinct", "all", "any", "some", "top", "percent",
|
|
8
|
+
"from", "join", "where", "on", "having", "by",
|
|
9
|
+
"and", "or", "not", "in", "exists", "like", "between", "escape",
|
|
10
|
+
"case", "when", "then", "else",
|
|
11
|
+
"union", "except", "intersect",
|
|
12
|
+
]);
|
|
13
|
+
/** Reserved words that are also function names, so `name((SELECT …))` is a call. */
|
|
14
|
+
const RESERVED_FUNCTIONS = new Set([
|
|
15
|
+
"coalesce", "nullif", "convert", "try_convert", "left", "right",
|
|
16
|
+
"contains", "containstable", "freetext", "freetexttable", "openxml", "tsequal",
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* Punctuation an expression may follow: `(`, a comma, an operator, and `.` or `::`
|
|
20
|
+
* before a qualified function name.
|
|
21
|
+
*/
|
|
22
|
+
const EXPRESSION_PUNCTUATION = new Set(["(", ",", "=", "<", ">", "+", "-", "*", "/", "%", "&", "|", "^", "~", ".", "::"]);
|
|
23
|
+
const RESERVED = new Set(SQLSERVER_RESERVED_WORDS);
|
|
24
|
+
const SET_OPERATORS = new Set(["union", "except", "intersect"]);
|
|
25
|
+
/**
|
|
26
|
+
* A character allowed in T-SQL code outside strings and quoted names: printable ASCII
|
|
27
|
+
* except `\`, tab, line feed, carriage return, and Unicode letters, combining marks
|
|
28
|
+
* and decimal digits.
|
|
29
|
+
*/
|
|
30
|
+
const PLAIN_CODE = /[\t\n\r\x20-\x5b\x5d-\x7e\p{L}\p{M}\p{Nd}]/u;
|
|
31
|
+
const MONEY_SIGN = /^\p{Sc}$/u;
|
|
32
|
+
/**
|
|
33
|
+
* Code SQL Server may split into tokens differently from the lexer, described for an
|
|
34
|
+
* error message, or `undefined`. Text inside strings and quoted identifiers is not
|
|
35
|
+
* checked; `tokens` holds no comments. Fails closed on:
|
|
36
|
+
*
|
|
37
|
+
* - a character outside {@link PLAIN_CODE}: Unicode whitespace and format characters
|
|
38
|
+
* (U+00A0, U+200B, U+FEFF), symbols, currency signs other than `$`, `\` (a money
|
|
39
|
+
* sign to SQL Server) and ASCII control characters;
|
|
40
|
+
* - a money sign with no digits after it (`$ .5` is one money literal to SQL Server);
|
|
41
|
+
* - a number written directly against a word or variable (`1ESELECT`, `0xSELECT`);
|
|
42
|
+
* - a `?` written directly against a name or number: Studio binds it as `@p0`, which
|
|
43
|
+
* SQL Server reads as part of that name (`x?:` becomes the label `x@p0:`).
|
|
44
|
+
*
|
|
45
|
+
* Model-written SQL contains none of these.
|
|
46
|
+
*/
|
|
47
|
+
export function findAmbiguousTsqlText(sql, tokens) {
|
|
48
|
+
let from = 0;
|
|
49
|
+
const scanTo = (end) => {
|
|
50
|
+
for (const ch of sql.slice(from, end)) {
|
|
51
|
+
if (PLAIN_CODE.test(ch))
|
|
52
|
+
continue;
|
|
53
|
+
if (ch === "\\")
|
|
54
|
+
return "the character '\\'";
|
|
55
|
+
return `the character U+${ch.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
};
|
|
59
|
+
for (const [i, t] of tokens.entries()) {
|
|
60
|
+
if (t.kind === "string" || t.kind === "quoted_identifier") {
|
|
61
|
+
const found = scanTo(t.start);
|
|
62
|
+
if (found)
|
|
63
|
+
return found;
|
|
64
|
+
from = t.end;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const prev = tokens[i - 1];
|
|
68
|
+
if (isPunct(t, "?") && prev?.end === t.start && prev.kind !== "punct" && prev.kind !== "string") {
|
|
69
|
+
return `'${prev.text}?', a parameter marker written against a name`;
|
|
70
|
+
}
|
|
71
|
+
if (t.kind !== "number")
|
|
72
|
+
continue;
|
|
73
|
+
if (MONEY_SIGN.test(t.text))
|
|
74
|
+
return `the money sign '${t.text}'`;
|
|
75
|
+
const next = tokens[i + 1];
|
|
76
|
+
if (next?.start === t.end && (next.kind === "word" || next.kind === "parameter")) {
|
|
77
|
+
return `'${t.text}${next.text}', a number written against a word`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return scanTo(sql.length);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The first place `tokens` starts a second T-SQL statement, or `undefined`.
|
|
84
|
+
* `tokens` holds no comments and no trailing `;`.
|
|
85
|
+
*/
|
|
86
|
+
export function findTsqlStatementBoundary(tokens) {
|
|
87
|
+
/** Index of each `)` mapped to the index of the `(` it closes. */
|
|
88
|
+
const opener = new Map();
|
|
89
|
+
/** A top-level `ORDER BY` came earlier, so a later `OFFSET` is the keyword. */
|
|
90
|
+
let orderBy = false;
|
|
91
|
+
/** `tokens[i]` is `(` and a `SELECT` follows it, after any further `(`. */
|
|
92
|
+
const opensQuery = (i) => {
|
|
93
|
+
let j = i;
|
|
94
|
+
while (isPunct(tokens[j], "("))
|
|
95
|
+
j++;
|
|
96
|
+
return isWord(tokens[j], "select");
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The word at `j` is a keyword an expression follows. Keywords SQL Server does not
|
|
100
|
+
* reserve count only in their clause; anywhere else they are aliases
|
|
101
|
+
* (`SELECT 1 offset (SELECT 2)` is two statements).
|
|
102
|
+
*/
|
|
103
|
+
const introducesExpression = (j) => {
|
|
104
|
+
const word = tokens[j].lower;
|
|
105
|
+
if (EXPRESSION_KEYWORDS.has(word))
|
|
106
|
+
return true;
|
|
107
|
+
const prev = tokens[j - 1];
|
|
108
|
+
switch (word) {
|
|
109
|
+
case "offset":
|
|
110
|
+
// After a sort item, not as one (`ORDER BY offset` sorts by a column).
|
|
111
|
+
return orderBy && !isWord(prev, "by") && !isPunct(prev, ",");
|
|
112
|
+
case "next":
|
|
113
|
+
case "first":
|
|
114
|
+
return isWord(prev, "fetch");
|
|
115
|
+
case "ties":
|
|
116
|
+
return isWord(prev, "with");
|
|
117
|
+
case "apply":
|
|
118
|
+
return isWord(prev, "cross") || isWord(prev, "outer");
|
|
119
|
+
case "zone":
|
|
120
|
+
return isWord(prev, "time") && isWord(tokens[j - 2], "at");
|
|
121
|
+
default:
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* An expression may start right after `tokens[j]`, so a `(SELECT …` there is a
|
|
127
|
+
* subquery. Fails closed: anything not listed (a value, a name, `}`, an unknown
|
|
128
|
+
* keyword) ends the statement, and a `(SELECT …` after it starts a second one.
|
|
129
|
+
*/
|
|
130
|
+
const expressionMayFollow = (j) => {
|
|
131
|
+
const t = tokens[j];
|
|
132
|
+
if (!t)
|
|
133
|
+
return true;
|
|
134
|
+
switch (t.kind) {
|
|
135
|
+
case "number":
|
|
136
|
+
case "string":
|
|
137
|
+
case "parameter":
|
|
138
|
+
// `TOP 5 (SELECT …)`: the count, then the first select-list item.
|
|
139
|
+
return isWord(tokens[j - 1], "top");
|
|
140
|
+
case "word":
|
|
141
|
+
return introducesExpression(j);
|
|
142
|
+
case "punct": {
|
|
143
|
+
if (t.text !== ")")
|
|
144
|
+
return EXPRESSION_PUNCTUATION.has(t.text);
|
|
145
|
+
const openIndex = opener.get(j);
|
|
146
|
+
// `TOP (5) (SELECT …)`.
|
|
147
|
+
return openIndex !== undefined && isWord(tokens[openIndex - 1], "top");
|
|
148
|
+
}
|
|
149
|
+
default:
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* `name((SELECT …))` where `name` is a function: SQL Server reads an unquoted `name(`
|
|
155
|
+
* as a call whenever `name` is not an alias, that is, when an expression may start
|
|
156
|
+
* before it. A quoted name is a call only when qualified (`[dbo].[fn](`); alone,
|
|
157
|
+
* `[name]` is a column.
|
|
158
|
+
*/
|
|
159
|
+
const opensCallArgument = (i) => {
|
|
160
|
+
if (!isPunct(tokens[i + 1], "("))
|
|
161
|
+
return false;
|
|
162
|
+
const name = tokens[i - 1];
|
|
163
|
+
const callable = (name?.kind === "quoted_identifier" && isPunct(tokens[i - 2], ".")) ||
|
|
164
|
+
(name?.kind === "word" && (!RESERVED.has(name.lower) || RESERVED_FUNCTIONS.has(name.lower)));
|
|
165
|
+
return callable && expressionMayFollow(i - 2);
|
|
166
|
+
};
|
|
167
|
+
const open = [];
|
|
168
|
+
let headSeen = false;
|
|
169
|
+
/** After a leading `WITH`, the main query that follows the CTE list is still to come. */
|
|
170
|
+
let mainPending = false;
|
|
171
|
+
for (const [i, t] of tokens.entries()) {
|
|
172
|
+
const topLevel = open.length === 0;
|
|
173
|
+
if (isPunct(t, "(")) {
|
|
174
|
+
if (topLevel && opensQuery(i)) {
|
|
175
|
+
const prev = tokens[i - 1];
|
|
176
|
+
if (mainPending && (isWord(prev, "as") || isWord(prev, "materialized"))) {
|
|
177
|
+
// A CTE body.
|
|
178
|
+
}
|
|
179
|
+
else if (mainPending && isPunct(prev, ")")) {
|
|
180
|
+
mainPending = false;
|
|
181
|
+
}
|
|
182
|
+
else if (!expressionMayFollow(i - 1) && !opensCallArgument(i)) {
|
|
183
|
+
return { token: t, kind: "query" };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
open.push(i);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (isPunct(t, ")")) {
|
|
190
|
+
const openIndex = open.pop();
|
|
191
|
+
if (openIndex !== undefined)
|
|
192
|
+
opener.set(i, openIndex);
|
|
193
|
+
if (open.length === 0 && startsLabel(t, tokens[i + 1]))
|
|
194
|
+
return { token: t, kind: "label" };
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (!headSeen) {
|
|
198
|
+
headSeen = true;
|
|
199
|
+
mainPending = isWord(t, "with");
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (!topLevel)
|
|
203
|
+
continue;
|
|
204
|
+
if (startsLabel(t, tokens[i + 1]))
|
|
205
|
+
return { token: t, kind: "label" };
|
|
206
|
+
if (isWord(t, "by") && isWord(tokens[i - 1], "order"))
|
|
207
|
+
orderBy = true;
|
|
208
|
+
if (isWord(t, "select")) {
|
|
209
|
+
if (mainPending && isPunct(tokens[i - 1], ")")) {
|
|
210
|
+
mainPending = false;
|
|
211
|
+
}
|
|
212
|
+
else if (!followsSetOperator(tokens, i)) {
|
|
213
|
+
return { token: t, kind: "select" };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
/** `UNION [ALL | DISTINCT]`, `EXCEPT` or `INTERSECT` right before `tokens[i]`. */
|
|
220
|
+
function followsSetOperator(tokens, i) {
|
|
221
|
+
let prev = tokens[i - 1];
|
|
222
|
+
if (isWord(prev, "all") || isWord(prev, "distinct"))
|
|
223
|
+
prev = tokens[i - 2];
|
|
224
|
+
return prev?.kind === "word" && SET_OPERATORS.has(prev.lower);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* A `:` written directly against `t`, which T-SQL reads as ending a label (`name :` is a
|
|
228
|
+
* syntax error). Fails closed: any `t` counts except `(`, a comma or an operator, where
|
|
229
|
+
* an AskDB `:name` placeholder may follow, because SQL Server's label names include
|
|
230
|
+
* forms the lexer splits (`#@:`, `#1#:`). The lexer reads `l:SELECT` as `l` and a
|
|
231
|
+
* `:SELECT` parameter; `::` is one token and never a label.
|
|
232
|
+
*/
|
|
233
|
+
function startsLabel(t, next) {
|
|
234
|
+
if (next?.start !== t.end)
|
|
235
|
+
return false;
|
|
236
|
+
if (t.kind === "punct" && t.text !== "." && t.text !== "::" && EXPRESSION_PUNCTUATION.has(t.text))
|
|
237
|
+
return false;
|
|
238
|
+
return isPunct(next, ":") || (next.kind === "parameter" && next.text.startsWith(":"));
|
|
239
|
+
}
|
|
240
|
+
function isPunct(t, text) {
|
|
241
|
+
return t?.kind === "punct" && t.text === text;
|
|
242
|
+
}
|
|
243
|
+
function isWord(t, lower) {
|
|
244
|
+
return t?.kind === "word" && t.lower === lower;
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=tsql-batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsql-batch.js","sourceRoot":"","sources":["../../src/sql/tsql-batch.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAY/D;;;GAGG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS;IAC5D,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI;IAC7C,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ;IAC/D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAC9B,OAAO,EAAE,QAAQ,EAAE,WAAW;CAC/B,CAAC,CAAC;AAEH,oFAAoF;AACpF,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO;IAC/D,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS;CAC/E,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GA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K,CAAC;AACjD,CAAC"}
|
package/dist/sql/validate.d.ts
CHANGED
|
@@ -14,17 +14,30 @@ import { type DialectSpec } from "./dialect-spec.js";
|
|
|
14
14
|
* 3. `SQL_MULTI_STATEMENT` — any `;` other than a single trailing one.
|
|
15
15
|
* 4. `SQL_COMMENT` — any comment (`--`, `/* *\/`, and MySQL `#`).
|
|
16
16
|
* 5. `SQL_NOT_SELECT_OR_WITH` — the first token (after any `(`) is not `SELECT`/`WITH`.
|
|
17
|
-
* 6. `
|
|
17
|
+
* 6. `SQL_MULTI_STATEMENT`, SQL Server lexer only (so also for a dialect id that is no
|
|
18
|
+
* built-in engine) — a second statement written without `;`, which T-SQL doesn't
|
|
19
|
+
* need, or code SQL Server may split differently from the lexer (see `tsql-batch.ts`).
|
|
20
|
+
* 7. `SQL_FORBIDDEN_KEYWORD` — an unquoted keyword from the shared denylist or the
|
|
18
21
|
* dialect's `extraForbiddenKeywords`.
|
|
19
|
-
*
|
|
22
|
+
* 8. `SQL_FORBIDDEN_FUNCTION` — a call (`name(`) to a function in the dialect's
|
|
20
23
|
* `blockedFunctions` (side-effecting or file/network/sleep functions).
|
|
21
24
|
*
|
|
22
|
-
* Then the dialect's `extraValidate` runs on the
|
|
25
|
+
* Then the dialect's `extraValidate` runs on the statement without its trailing `;`.
|
|
26
|
+
*
|
|
27
|
+
* Returns the SQL trimmed and otherwise as written: a single trailing `;` (and any
|
|
28
|
+
* whitespace before it) is kept. A host that wraps the statement, for example in a
|
|
29
|
+
* row-cap subquery, removes the terminator first.
|
|
23
30
|
*
|
|
24
31
|
* The lexer follows `dialect.id`. When the id is not a built-in engine family, the SQL
|
|
25
32
|
* must pass under every built-in lexer with every built-in denylist.
|
|
26
33
|
*/
|
|
27
34
|
export declare function validateSelectSql(dialect: DialectSpec, sql: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* The words `validateSelectSql` rejects unquoted for a dialect, lowercase: the shared denylist
|
|
37
|
+
* and the spec's `extraForbiddenKeywords`, plus every built-in spec's for an id that is no
|
|
38
|
+
* built-in engine family. The NL→SQL prompt quotes names in this set.
|
|
39
|
+
*/
|
|
40
|
+
export declare function keywordsRejectedUnquoted(dialect: Pick<DialectSpec, "id" | "backslashEscapes" | "extraForbiddenKeywords">): Set<string>;
|
|
28
41
|
/** Explanation of guardrails satisfied by a string already passing {@link validateSelectSql}. */
|
|
29
42
|
export type SelectGuardrailExplain = {
|
|
30
43
|
statementKind: "select" | "with";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/sql/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/sql/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAyCxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAyB3E;AA6GD;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,kBAAkB,GAAG,wBAAwB,CAAC,GAC/E,GAAG,CAAC,MAAM,CAAC,CAIb;AAsCD,iGAAiG;AACjG,MAAM,MAAM,sBAAsB,GAAG;IACnC,aAAa,EAAE,QAAQ,GAAG,MAAM,CAAC;IACjC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,6FAA6F;AAC7F,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,MAAM,GAAG,sBAAsB,CAiB5F"}
|
package/dist/sql/validate.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SqlValidationError } from "../errors.js";
|
|
2
2
|
import { BUILT_IN_DIALECTS } from "./dialect-spec.js";
|
|
3
3
|
import { ENGINE_LEXER_PROFILES, GENERIC_LEXER, lexSql, lexerProfileFor, } from "./lexer.js";
|
|
4
|
+
import { findAmbiguousTsqlText, findTsqlStatementBoundary } from "./tsql-batch.js";
|
|
4
5
|
/**
|
|
5
6
|
* Keywords rejected in every dialect. Matched against unquoted word tokens only, so
|
|
6
7
|
* `deleted_at`, `"delete"`, and `'delete me'` are unaffected.
|
|
@@ -44,12 +45,19 @@ function validationError(rule, summary, hint) {
|
|
|
44
45
|
* 3. `SQL_MULTI_STATEMENT` — any `;` other than a single trailing one.
|
|
45
46
|
* 4. `SQL_COMMENT` — any comment (`--`, `/* *\/`, and MySQL `#`).
|
|
46
47
|
* 5. `SQL_NOT_SELECT_OR_WITH` — the first token (after any `(`) is not `SELECT`/`WITH`.
|
|
47
|
-
* 6. `
|
|
48
|
+
* 6. `SQL_MULTI_STATEMENT`, SQL Server lexer only (so also for a dialect id that is no
|
|
49
|
+
* built-in engine) — a second statement written without `;`, which T-SQL doesn't
|
|
50
|
+
* need, or code SQL Server may split differently from the lexer (see `tsql-batch.ts`).
|
|
51
|
+
* 7. `SQL_FORBIDDEN_KEYWORD` — an unquoted keyword from the shared denylist or the
|
|
48
52
|
* dialect's `extraForbiddenKeywords`.
|
|
49
|
-
*
|
|
53
|
+
* 8. `SQL_FORBIDDEN_FUNCTION` — a call (`name(`) to a function in the dialect's
|
|
50
54
|
* `blockedFunctions` (side-effecting or file/network/sleep functions).
|
|
51
55
|
*
|
|
52
|
-
* Then the dialect's `extraValidate` runs on the
|
|
56
|
+
* Then the dialect's `extraValidate` runs on the statement without its trailing `;`.
|
|
57
|
+
*
|
|
58
|
+
* Returns the SQL trimmed and otherwise as written: a single trailing `;` (and any
|
|
59
|
+
* whitespace before it) is kept. A host that wraps the statement, for example in a
|
|
60
|
+
* row-cap subquery, removes the terminator first.
|
|
53
61
|
*
|
|
54
62
|
* The lexer follows `dialect.id`. When the id is not a built-in engine family, the SQL
|
|
55
63
|
* must pass under every built-in lexer with every built-in denylist.
|
|
@@ -61,21 +69,20 @@ export function validateSelectSql(dialect, sql) {
|
|
|
61
69
|
}
|
|
62
70
|
const profile = lexerProfileFor(dialect);
|
|
63
71
|
let tokens;
|
|
72
|
+
const keywords = keywordsRejectedUnquoted(dialect);
|
|
64
73
|
if (profile) {
|
|
65
|
-
tokens = checkWithProfile(trimmed, profile,
|
|
74
|
+
tokens = checkWithProfile(trimmed, profile, keywords, blockedFunctionsFor(dialect));
|
|
66
75
|
}
|
|
67
76
|
else {
|
|
68
77
|
// Unknown engine: every plausible reading of the SQL must be safe.
|
|
69
|
-
const keywords = new Set([...forbiddenKeywordsFor(dialect), ...allBuiltInKeywords()]);
|
|
70
78
|
const functions = new Set([...blockedFunctionsFor(dialect), ...allBuiltInFunctions()]);
|
|
71
79
|
tokens = [];
|
|
72
80
|
for (const p of ENGINE_LEXER_PROFILES)
|
|
73
81
|
tokens = checkWithProfile(trimmed, p, keywords, functions);
|
|
74
82
|
}
|
|
75
83
|
const last = tokens[tokens.length - 1];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return normalized;
|
|
84
|
+
dialect.extraValidate?.(isPunct(last, ";") ? trimmed.slice(0, last.start).trim() : trimmed);
|
|
85
|
+
return trimmed;
|
|
79
86
|
}
|
|
80
87
|
function checkWithProfile(sql, profile, keywords, functions) {
|
|
81
88
|
const tokens = lexSql(sql, profile);
|
|
@@ -102,6 +109,22 @@ function checkWithProfile(sql, profile, keywords, functions) {
|
|
|
102
109
|
const got = head ? head.value.toLowerCase() : "";
|
|
103
110
|
throw validationError("SQL_NOT_SELECT_OR_WITH", `SQL must start with SELECT or WITH (got '${got || "none"}').`, "Regenerate as a read-only SELECT (optionally with WITH). INSERT/UPDATE/DELETE and procedural calls are blocked in dev guardrails.");
|
|
104
111
|
}
|
|
112
|
+
if (profile.id === "sqlserver") {
|
|
113
|
+
const ambiguous = findAmbiguousTsqlText(sql, tokens);
|
|
114
|
+
if (ambiguous) {
|
|
115
|
+
throw validationError("SQL_MULTI_STATEMENT", `Multiple SQL statements are not allowed: SQL Server may split code at ${ambiguous}, so the check can't tell where one statement ends.`, "Separate keywords, names and numbers with ASCII spaces, and keep other characters inside string literals or [bracketed] names.");
|
|
116
|
+
}
|
|
117
|
+
const statement = isPunct(tokens[tokens.length - 1], ";") ? tokens.slice(0, -1) : tokens;
|
|
118
|
+
const boundary = findTsqlStatementBoundary(statement);
|
|
119
|
+
if (boundary) {
|
|
120
|
+
const what = boundary.kind === "select"
|
|
121
|
+
? "a second SELECT"
|
|
122
|
+
: boundary.kind === "query"
|
|
123
|
+
? "a parenthesized query after a complete value"
|
|
124
|
+
: `the label '${boundary.token.text}:'`;
|
|
125
|
+
throw validationError("SQL_MULTI_STATEMENT", `Multiple SQL statements are not allowed: T-SQL needs no semicolon between statements, so ${what} starts a second statement.`, "Ask for a single SELECT (WITH … SELECT allowed). Combine results with UNION, a CTE, or a subquery after an operator, a comma, or a keyword such as IN, EXISTS, FROM or APPLY.");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
105
128
|
for (const t of tokens) {
|
|
106
129
|
if (t.kind === "word" && keywords.has(t.lower)) {
|
|
107
130
|
throw validationError("SQL_FORBIDDEN_KEYWORD", `Forbidden keyword in generated SQL: ${t.lower.toUpperCase()}.`, `Matched whole-word guardrail keyword "${t.lower}". This build allows read-only SELECT shape only; DDL/DML, SELECT … INTO, and similar verbs are rejected.`);
|
|
@@ -118,6 +141,18 @@ function checkWithProfile(sql, profile, keywords, functions) {
|
|
|
118
141
|
});
|
|
119
142
|
return tokens;
|
|
120
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* The words `validateSelectSql` rejects unquoted for a dialect, lowercase: the shared denylist
|
|
146
|
+
* and the spec's `extraForbiddenKeywords`, plus every built-in spec's for an id that is no
|
|
147
|
+
* built-in engine family. The NL→SQL prompt quotes names in this set.
|
|
148
|
+
*/
|
|
149
|
+
export function keywordsRejectedUnquoted(dialect) {
|
|
150
|
+
const keywords = forbiddenKeywordsFor(dialect);
|
|
151
|
+
if (!lexerProfileFor(dialect))
|
|
152
|
+
for (const word of allBuiltInKeywords())
|
|
153
|
+
keywords.add(word.toLowerCase());
|
|
154
|
+
return keywords;
|
|
155
|
+
}
|
|
121
156
|
function forbiddenKeywordsFor(dialect) {
|
|
122
157
|
return new Set([...BASE_FORBIDDEN, ...(dialect.extraForbiddenKeywords ?? [])].map((w) => w.toLowerCase()));
|
|
123
158
|
}
|
package/dist/sql/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/sql/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA8B,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,MAAM,EACN,eAAe,GAGhB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/sql/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA8B,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,MAAM,EACN,eAAe,GAGhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAEnF;;;;;;;GAOG;AACH,MAAM,cAAc,GAAsB;IACxC,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,UAAU;IACV,OAAO;IACP,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;CACP,CAAC;AAEF,SAAS,eAAe,CAAC,IAA2B,EAAE,OA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M,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@askdb/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.45",
|
|
4
4
|
"description": "AskDB core: dialect-agnostic NL→SQL pipeline. Provides ask() orchestration, schema/IR types, modes, logging, and retrieval input. Bring your own dialect (e.g. @askdb/postgres).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"askdb",
|
|
@@ -40,17 +40,20 @@
|
|
|
40
40
|
"NOTICE"
|
|
41
41
|
],
|
|
42
42
|
"engines": {
|
|
43
|
-
"node": ">=22.
|
|
43
|
+
"node": ">=22.23.4"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"ai": "^7.0.113",
|
|
47
46
|
"gray-matter": "^4.0.3",
|
|
48
|
-
"pino": "^10.
|
|
49
|
-
"zod": "^4.6.
|
|
47
|
+
"pino": "^10.4.0",
|
|
48
|
+
"zod": "^4.6.7"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"ai": "^6.0.0 || ^7.0.51"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
54
|
+
"ai": "^7.0.51",
|
|
52
55
|
"typescript": "^6.0.3",
|
|
53
|
-
"vitest": "^5.0.
|
|
56
|
+
"vitest": "^5.0.5"
|
|
54
57
|
},
|
|
55
58
|
"scripts": {
|
|
56
59
|
"build": "tsc -p tsconfig.build.json",
|