trilean-sql 2.3.0 → 3.0.1
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/dist/compile.js +3 -6
- package/dist/{guard-D4CIUc5h.js → guard-CZ7Cvyh2.js} +10 -7
- package/dist/guard.d.ts +2 -1
- package/dist/guard.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +11 -20
- package/dist/compile-test-helpers.cjs +0 -76
- package/dist/compile-test-helpers.d.cts +0 -13
- package/dist/compile-test-helpers.d.ts +0 -13
- package/dist/compile-test-helpers.js +0 -69
- package/dist/compile.cjs +0 -287
- package/dist/compile.d.cts +0 -14
- package/dist/errors.cjs +0 -80
- package/dist/errors.d.cts +0 -53
- package/dist/guard-CCet6aaa.cjs +0 -434
- package/dist/guard-test-helpers.cjs +0 -16
- package/dist/guard-test-helpers.d.cts +0 -3
- package/dist/guard-test-helpers.d.ts +0 -3
- package/dist/guard-test-helpers.js +0 -15
- package/dist/guard.cjs +0 -3
- package/dist/guard.d.cts +0 -28
- package/dist/index.cjs +0 -11
- package/dist/index.d.cts +0 -5
- package/dist/options-DOE1_Cwr.cjs +0 -126
- package/dist/options.cjs +0 -5
- package/dist/options.d.cts +0 -97
- package/dist/portable-pattern.cjs +0 -150
- package/dist/portable-pattern.d.cts +0 -17
package/dist/guard-CCet6aaa.cjs
DELETED
|
@@ -1,434 +0,0 @@
|
|
|
1
|
-
const require_options = require("./options-DOE1_Cwr.cjs");
|
|
2
|
-
const require_portable_pattern = require("./portable-pattern.cjs");
|
|
3
|
-
let trilean_regex = require("trilean-regex");
|
|
4
|
-
// src/internal/identifier.ts
|
|
5
|
-
/**
|
|
6
|
-
* What a dialect can carry in a quoted identifier and in a bound text value, in one place: the guard decides with it before compilation and the compiler's own drift checks use it, so the two cannot disagree.
|
|
7
|
-
*
|
|
8
|
-
* The reasons describe the character or the count and never repeat the input, so an error built from one cannot carry a caller's value into a log.
|
|
9
|
-
*/
|
|
10
|
-
const NUL = "\0";
|
|
11
|
-
/** The most dot-separated segments a column may have: `schema.table.column`. SQLite's expression syntax is `schema-name.table-name.column-name` (https://www.sqlite.org/lang_expr.html). PostgreSQL's page on schemas says that "the even more general syntax database.schema.table can be used too, but at present this is just for pro forma compliance with the SQL standard. If you write a database name, it must be the same as the database you are connected to" (https://www.postgresql.org/docs/current/ddl-schemas.html). The compiler does not know the database the connection is on, so a leading database segment is refused as a choice, and the caller omits it. */
|
|
12
|
-
const MAX_COLUMN_SEGMENTS = {
|
|
13
|
-
postgres: 3,
|
|
14
|
-
sqlite: 3
|
|
15
|
-
};
|
|
16
|
-
/** The most dot-separated segments a table may have: `schema.table`. SQLite's `FROM` takes `schema-name.table-name` (https://www.sqlite.org/syntax/table-or-subquery.html), and for PostgreSQL a leading database segment is refused for the reason given at {@link MAX_COLUMN_SEGMENTS}. */
|
|
17
|
-
const MAX_TABLE_SEGMENTS = {
|
|
18
|
-
postgres: 2,
|
|
19
|
-
sqlite: 2
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Why a column or table name cannot be rendered as a quoted identifier for `dialect`, or `undefined` when it can.
|
|
23
|
-
*
|
|
24
|
-
* Refused: an empty name or segment; the NUL character, which neither engine accepts in a quoted identifier (PostgreSQL: "Quoted identifiers can contain any character, except the character with code zero", https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS) and which ends the statement text SQLite is given ("zSql is read up to the first zero terminator", https://www.sqlite.org/c3ref/prepare.html); an unpaired UTF-16 surrogate, which has no UTF-8 form, the encoding both engines read the statement in; and more segments than the dialect accepts. Every other character, a quote included, is carried by doubling the quote.
|
|
25
|
-
*/
|
|
26
|
-
function identifierProblem(role, name, dialect) {
|
|
27
|
-
if (name.length === 0) return "the name is empty";
|
|
28
|
-
if (name.includes(NUL)) return "the name contains a NUL character, which a quoted identifier cannot carry";
|
|
29
|
-
if (!name.isWellFormed()) return "the name contains an unpaired surrogate, which has no UTF-8 form";
|
|
30
|
-
const segments = name.split(".");
|
|
31
|
-
if (segments.some((segment) => segment.length === 0)) return "a dot-separated segment is empty";
|
|
32
|
-
const most = role === "column" ? MAX_COLUMN_SEGMENTS[dialect] : MAX_TABLE_SEGMENTS[dialect];
|
|
33
|
-
if (segments.length > most) return dialect === "postgres" ? `the name has ${String(segments.length)} dot-separated segments and at most ${String(most)} are accepted for a ${role}: PostgreSQL takes a leading database name only when it is the database the connection is on, which the compiler cannot know` : `the name has ${String(segments.length)} dot-separated segments and SQLite accepts at most ${String(most)} for a ${role}`;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Why a text, pattern or instant value cannot be bound for `dialect`, or `undefined` when it can.
|
|
37
|
-
*
|
|
38
|
-
* An unpaired surrogate has no UTF-8 form, and a driver silently replaces it with U+FFFD, so the engine would compare a value other than the one the evaluator saw. The NUL character is carried by SQLite as text but not by PostgreSQL, which rejects it with an invalid byte sequence error (a string constant "cannot contain the character with code zero", https://www.postgresql.org/docs/current/sql-syntax-lexical.html). The pattern of `portableMatches` and `portableNotMatches` is compiled to SQLite's `GLOB`, which reads it only up to its first NUL, so a NUL there is refused for SQLite as well; the pattern of `matches` and `notMatches` is a `REGEXP` argument and a registered function receives it whole.
|
|
39
|
-
*/
|
|
40
|
-
function valueProblem(value, dialect, role) {
|
|
41
|
-
if (!value.isWellFormed()) return "the value contains an unpaired surrogate, which has no UTF-8 form and would be replaced before the engine compared it";
|
|
42
|
-
if (!value.includes(NUL)) return void 0;
|
|
43
|
-
if (dialect === "postgres") return "PostgreSQL cannot carry the NUL character in a text value and rejects the statement with an invalid byte sequence error";
|
|
44
|
-
return role === "glob-pattern" ? "SQLite's GLOB reads a pattern only up to its first NUL character, so the pattern would match as a shorter one" : void 0;
|
|
45
|
-
}
|
|
46
|
-
// src/guard.ts
|
|
47
|
-
const STATIC_KIND_OF_PARAM_TYPE = {
|
|
48
|
-
text: "text",
|
|
49
|
-
number: "number",
|
|
50
|
-
boolean: "boolean",
|
|
51
|
-
timestamp: "instant"
|
|
52
|
-
};
|
|
53
|
-
/** The comparison operators that impose an ordering, as opposed to testing equality. trilean refuses these on booleans -- `true > false` is not a fact about the domain -- while both dialects answer them, so a boolean operand under one of these is a real divergence rather than a stylistic one. */
|
|
54
|
-
const ORDERING_OPERATORS = /* @__PURE__ */ new Set([
|
|
55
|
-
"gt",
|
|
56
|
-
"gte",
|
|
57
|
-
"lt",
|
|
58
|
-
"lte"
|
|
59
|
-
]);
|
|
60
|
-
/** A literal's own node kind is its value's kind. Written as a lookup rather than a switch so that every other expression kind falls out as "not statically knowable" by absence, which is the honest answer for all of them, rather than needing a branch each. */
|
|
61
|
-
const STATIC_KIND_OF_LITERAL = {
|
|
62
|
-
textLiteral: "text",
|
|
63
|
-
numberLiteral: "number",
|
|
64
|
-
booleanLiteral: "boolean",
|
|
65
|
-
instantLiteral: "instant"
|
|
66
|
-
};
|
|
67
|
-
const DIALECT_DIVERGENCE = {
|
|
68
|
-
postgres: {
|
|
69
|
-
complexNumbers: "PostgreSQL has no complex number type",
|
|
70
|
-
nan: "NaN is equal to nothing in trilean, not even itself, whereas PostgreSQL defines NaN as equal to itself and greater than every other double",
|
|
71
|
-
crossKindCoercion: "PostgreSQL may coerce one to the other and answer definitely",
|
|
72
|
-
textOrdering: (operandPath) => `PostgreSQL would order the text operand at ${operandPath} collation-wise and answer definitely`,
|
|
73
|
-
booleanOrdering: "PostgreSQL orders false before true"
|
|
74
|
-
},
|
|
75
|
-
sqlite: {
|
|
76
|
-
complexNumbers: "SQLite has no complex number type",
|
|
77
|
-
nan: "NaN is equal to nothing in trilean, not even itself, whereas SQLite has no NaN at all and a driver binding one substitutes SQL NULL -- so 'NaN = NaN' is indeterminate there rather than definitely false, and its negation matches every row instead of none",
|
|
78
|
-
crossKindCoercion: "SQLite's type affinity may coerce one to the other and answer definitely",
|
|
79
|
-
textOrdering: (operandPath) => `SQLite would answer definitely for the text operand at ${operandPath}, comparing it under the text affinity it applies to the other side ('9' > 5 is true there, while '10' > 5 is not)`,
|
|
80
|
-
booleanOrdering: "SQLite stores booleans as the integers 0 and 1 and orders them as integers"
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
function staticValueKindOf(node, options) {
|
|
84
|
-
if (node.kind !== "reference") return STATIC_KIND_OF_LITERAL[node.kind];
|
|
85
|
-
if (options === void 0 || typeof node.key !== "string") return void 0;
|
|
86
|
-
const paramType = options.columnFor(node.key).paramType;
|
|
87
|
-
return paramType === void 0 ? void 0 : STATIC_KIND_OF_PARAM_TYPE[paramType];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Resolves a `some`/`every`/`fold` node's `collection` onto the options a walk of its `item`/`filter` should use, or explains why it cannot be resolved.
|
|
91
|
-
*
|
|
92
|
-
* `options === undefined` is the one case that is not a refusal: a purely structural walk (no `options` at all) has no `columnFor` either, and every other options-dependent check in this file already answers "cannot tell, assume it passes" in that mode (see `staticValueKindOf`) -- refusing collection resolution specifically would make this the one exception to that convention rather than a consistent extension of it.
|
|
93
|
-
*/
|
|
94
|
-
function resolveCollectionForGuard(kind, collection, path, options) {
|
|
95
|
-
if (typeof collection !== "string") return {
|
|
96
|
-
kind,
|
|
97
|
-
path,
|
|
98
|
-
reason: "only a string collection key can be mapped to a correlated table; this collection is a non-string JSON value"
|
|
99
|
-
};
|
|
100
|
-
if (options === void 0) return { itemOptions: void 0 };
|
|
101
|
-
if (options.collectionFor === void 0) return {
|
|
102
|
-
kind,
|
|
103
|
-
path,
|
|
104
|
-
reason: "no 'collectionFor' option is set: describe how this collection maps onto a correlated table ({ table, join, columnFor }) to compile this node, or it falls back to in-process evaluation"
|
|
105
|
-
};
|
|
106
|
-
const binding = options.collectionFor(collection);
|
|
107
|
-
const tableProblem = identifierProblem("table", binding.table, options.dialect);
|
|
108
|
-
if (tableProblem !== void 0) return {
|
|
109
|
-
kind,
|
|
110
|
-
path,
|
|
111
|
-
reason: `the table mapped for this collection cannot be used: ${tableProblem}`,
|
|
112
|
-
identifier: {
|
|
113
|
-
role: "table",
|
|
114
|
-
key: collection,
|
|
115
|
-
problem: tableProblem
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
return { itemOptions: {
|
|
119
|
-
...options,
|
|
120
|
-
columnFor: binding.columnFor
|
|
121
|
-
} };
|
|
122
|
-
}
|
|
123
|
-
function findUnpushableExpression(node, path, divergence, options) {
|
|
124
|
-
const unrecognisedKind = node.kind;
|
|
125
|
-
switch (node.kind) {
|
|
126
|
-
case "reference":
|
|
127
|
-
if (typeof node.key !== "string") return {
|
|
128
|
-
kind: node.kind,
|
|
129
|
-
path,
|
|
130
|
-
reason: "only a string reference key can be mapped to a column; this key is a non-string JSON value"
|
|
131
|
-
};
|
|
132
|
-
if (node.unit !== void 0) return {
|
|
133
|
-
kind: node.kind,
|
|
134
|
-
path,
|
|
135
|
-
reason: "a reference declaring a unit asserts that the resolved value carries that same unit, and a SQL column carries no unit for that assertion to be checked against"
|
|
136
|
-
};
|
|
137
|
-
if (options !== void 0) {
|
|
138
|
-
const columnProblem = identifierProblem("column", options.columnFor(node.key).column, options.dialect);
|
|
139
|
-
if (columnProblem !== void 0) return {
|
|
140
|
-
kind: node.kind,
|
|
141
|
-
path,
|
|
142
|
-
reason: `the column mapped for this reference cannot be used: ${columnProblem}`,
|
|
143
|
-
identifier: {
|
|
144
|
-
role: "column",
|
|
145
|
-
key: node.key,
|
|
146
|
-
problem: columnProblem
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
return;
|
|
151
|
-
case "numberLiteral":
|
|
152
|
-
if (node.unit !== void 0) return {
|
|
153
|
-
kind: node.kind,
|
|
154
|
-
path,
|
|
155
|
-
reason: "a unit-tagged number is only comparable with an operand of the same unit, and SQL has no unit to compare"
|
|
156
|
-
};
|
|
157
|
-
if (Number.isNaN(node.value)) return {
|
|
158
|
-
kind: node.kind,
|
|
159
|
-
path,
|
|
160
|
-
reason: divergence.nan
|
|
161
|
-
};
|
|
162
|
-
return;
|
|
163
|
-
case "textLiteral":
|
|
164
|
-
case "instantLiteral": {
|
|
165
|
-
const problem = valueProblem(node.value, options?.dialect ?? "postgres", "text");
|
|
166
|
-
return problem === void 0 ? void 0 : {
|
|
167
|
-
kind: node.kind,
|
|
168
|
-
path,
|
|
169
|
-
reason: problem
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
case "booleanLiteral": return;
|
|
173
|
-
case "durationLiteral": return {
|
|
174
|
-
kind: node.kind,
|
|
175
|
-
path,
|
|
176
|
-
reason: "trilean compares two durations in whichever unit each carries, and a column holds no unit to carry"
|
|
177
|
-
};
|
|
178
|
-
case "complexLiteral": return {
|
|
179
|
-
kind: node.kind,
|
|
180
|
-
path,
|
|
181
|
-
reason: divergence.complexNumbers
|
|
182
|
-
};
|
|
183
|
-
case "arithmetic":
|
|
184
|
-
case "negate": return {
|
|
185
|
-
kind: node.kind,
|
|
186
|
-
path,
|
|
187
|
-
reason: "arithmetic carries and combines units, and pushing it down would drop that dimensional analysis without saying so"
|
|
188
|
-
};
|
|
189
|
-
case "call": return {
|
|
190
|
-
kind: node.kind,
|
|
191
|
-
path,
|
|
192
|
-
reason: "a function's implementation lives in the caller's FunctionRegistry, not in the database"
|
|
193
|
-
};
|
|
194
|
-
case "lookup": return {
|
|
195
|
-
kind: node.kind,
|
|
196
|
-
path,
|
|
197
|
-
reason: "a lookup table is resolved by the caller's resolvers"
|
|
198
|
-
};
|
|
199
|
-
case "conditional": return {
|
|
200
|
-
kind: node.kind,
|
|
201
|
-
path,
|
|
202
|
-
reason: "conditional evaluation is not implemented in this version of the compiler"
|
|
203
|
-
};
|
|
204
|
-
case "fold": {
|
|
205
|
-
if (node.combiner.mode === "reduce") return {
|
|
206
|
-
kind: node.kind,
|
|
207
|
-
path,
|
|
208
|
-
reason: "a 'reduce' fold threads an arbitrary combine expression through the collection in a caller-chosen order, which has no general SQL translation"
|
|
209
|
-
};
|
|
210
|
-
const resolved = resolveCollectionForGuard(node.kind, node.collection, path, options);
|
|
211
|
-
if ("reason" in resolved) return resolved;
|
|
212
|
-
const { itemOptions } = resolved;
|
|
213
|
-
if (node.filter !== void 0) {
|
|
214
|
-
const unpushableFilter = findUnpushablePredicate(node.filter, `${path}.filter`, itemOptions, divergence);
|
|
215
|
-
if (unpushableFilter !== void 0) return unpushableFilter;
|
|
216
|
-
}
|
|
217
|
-
const itemPath = `${path}.combiner.item`;
|
|
218
|
-
const unpushableItem = findUnpushableExpression(node.combiner.item, itemPath, divergence, itemOptions);
|
|
219
|
-
if (unpushableItem !== void 0) return unpushableItem;
|
|
220
|
-
const itemKind = staticValueKindOf(node.combiner.item, itemOptions);
|
|
221
|
-
if (itemKind === "text") return {
|
|
222
|
-
kind: node.kind,
|
|
223
|
-
path: itemPath,
|
|
224
|
-
reason: `a '${node.combiner.mode}' fold orders participating items by comparing them, and trilean never orders text values ('compare' returns wrong-type for text; use 'textCompare') -- but ${divergence.textOrdering(itemPath)}`
|
|
225
|
-
};
|
|
226
|
-
if (itemKind === "boolean") return {
|
|
227
|
-
kind: node.kind,
|
|
228
|
-
path: itemPath,
|
|
229
|
-
reason: `a '${node.combiner.mode}' fold orders participating items by comparing them, and booleans have no ordering in trilean -- whereas ${divergence.booleanOrdering}`
|
|
230
|
-
};
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
case "accumulator": return {
|
|
234
|
-
kind: node.kind,
|
|
235
|
-
path,
|
|
236
|
-
reason: "an accumulator is only meaningful inside a reduce fold"
|
|
237
|
-
};
|
|
238
|
-
case "delegate": return {
|
|
239
|
-
kind: node.kind,
|
|
240
|
-
path,
|
|
241
|
-
reason: "a delegated decision is made by an external system"
|
|
242
|
-
};
|
|
243
|
-
case "treeReference": return {
|
|
244
|
-
kind: node.kind,
|
|
245
|
-
path,
|
|
246
|
-
reason: "a referenced tree is resolved by the caller's resolvers; inline it before compiling"
|
|
247
|
-
};
|
|
248
|
-
default: return {
|
|
249
|
-
kind: unrecognisedKind,
|
|
250
|
-
path,
|
|
251
|
-
reason: "unrecognised expression node kind"
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
/** Checks the operands of a comparison-shaped predicate for a kind pairing trilean and the target engine would answer differently. Returns the objection against `path` itself, since the divergence is a property of the pairing rather than of either operand alone. */
|
|
256
|
-
function findKindDivergence(kind, path, operands, options, divergence) {
|
|
257
|
-
const known = operands.map((operand) => ({
|
|
258
|
-
path: operand.path,
|
|
259
|
-
staticKind: staticValueKindOf(operand.node, options)
|
|
260
|
-
})).filter((entry) => entry.staticKind !== void 0);
|
|
261
|
-
const first = known[0];
|
|
262
|
-
if (first === void 0) return void 0;
|
|
263
|
-
const mismatched = known.find((entry) => entry.staticKind !== first.staticKind);
|
|
264
|
-
if (mismatched !== void 0) return {
|
|
265
|
-
kind,
|
|
266
|
-
path,
|
|
267
|
-
reason: `trilean treats a comparison between a '${first.staticKind}' value (${first.path}) and a '${mismatched.staticKind}' value (${mismatched.path}) as wrong-type, whereas ${divergence.crossKindCoercion}`
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
function findUnpushablePredicate(node, path, options, divergence) {
|
|
271
|
-
const unrecognisedKind = node.kind;
|
|
272
|
-
switch (node.kind) {
|
|
273
|
-
case "not": return findUnpushablePredicate(node.operand, `${path}.operand`, options, divergence);
|
|
274
|
-
case "and":
|
|
275
|
-
case "or": return findUnpushablePredicate(node.left, `${path}.left`, options, divergence) ?? findUnpushablePredicate(node.right, `${path}.right`, options, divergence);
|
|
276
|
-
case "allOf":
|
|
277
|
-
case "anyOf":
|
|
278
|
-
for (const [index, operand] of node.operands.entries()) {
|
|
279
|
-
const unpushable = findUnpushablePredicate(operand, `${path}.operands[${String(index)}]`, options, divergence);
|
|
280
|
-
if (unpushable !== void 0) return unpushable;
|
|
281
|
-
}
|
|
282
|
-
return;
|
|
283
|
-
case "compare": {
|
|
284
|
-
const operands = [{
|
|
285
|
-
node: node.left,
|
|
286
|
-
path: `${path}.left`
|
|
287
|
-
}, {
|
|
288
|
-
node: node.right,
|
|
289
|
-
path: `${path}.right`
|
|
290
|
-
}];
|
|
291
|
-
for (const operand of operands) {
|
|
292
|
-
const unpushable = findUnpushableExpression(operand.node, operand.path, divergence, options);
|
|
293
|
-
if (unpushable !== void 0) return unpushable;
|
|
294
|
-
}
|
|
295
|
-
const mismatch = findKindDivergence(node.kind, path, operands, options, divergence);
|
|
296
|
-
if (mismatch !== void 0) return mismatch;
|
|
297
|
-
for (const operand of operands) {
|
|
298
|
-
const staticKind = staticValueKindOf(operand.node, options);
|
|
299
|
-
if (staticKind === "text") return {
|
|
300
|
-
kind: node.kind,
|
|
301
|
-
path,
|
|
302
|
-
reason: `'compare' never compares text in trilean -- it returns wrong-type and directs the caller to 'textCompare' -- but ${divergence.textOrdering(operand.path)}`
|
|
303
|
-
};
|
|
304
|
-
if (staticKind === "boolean" && ORDERING_OPERATORS.has(node.op)) return {
|
|
305
|
-
kind: node.kind,
|
|
306
|
-
path,
|
|
307
|
-
reason: `booleans have no ordering in trilean, so '${node.op}' against the boolean operand at ${operand.path} is wrong-type there, whereas ${divergence.booleanOrdering}`
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
case "textCompare": {
|
|
313
|
-
if ((node.op === "matches" || node.op === "notMatches") && options?.dialect === "sqlite" && options.sqliteRegexpAvailable === false) return {
|
|
314
|
-
kind: node.kind,
|
|
315
|
-
path,
|
|
316
|
-
reason: `options.sqliteRegexpAvailable is false: the caller has stated no regexp(pattern, value) function can be registered on this SQLite target, so '${node.op}' would compile to SQL that fails at query execution time with "no such function: REGEXP" instead of at compile time`
|
|
317
|
-
};
|
|
318
|
-
const operands = [{
|
|
319
|
-
node: node.left,
|
|
320
|
-
path: `${path}.left`
|
|
321
|
-
}, {
|
|
322
|
-
node: node.right,
|
|
323
|
-
path: `${path}.right`
|
|
324
|
-
}];
|
|
325
|
-
for (const operand of operands) {
|
|
326
|
-
const unpushable = findUnpushableExpression(operand.node, operand.path, divergence, options);
|
|
327
|
-
if (unpushable !== void 0) return unpushable;
|
|
328
|
-
const staticKind = staticValueKindOf(operand.node, options);
|
|
329
|
-
if (staticKind !== void 0 && staticKind !== "text") return {
|
|
330
|
-
kind: node.kind,
|
|
331
|
-
path,
|
|
332
|
-
reason: `'textCompare' requires text operands in trilean, and the operand at ${operand.path} is a '${staticKind}' value`
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
if (node.right.kind === "textLiteral" && (node.op === "portableMatches" || node.op === "portableNotMatches")) {
|
|
336
|
-
const patternProblem = valueProblem(node.right.value, options?.dialect ?? "postgres", "glob-pattern");
|
|
337
|
-
if (patternProblem !== void 0) return {
|
|
338
|
-
kind: node.kind,
|
|
339
|
-
path: `${path}.right`,
|
|
340
|
-
reason: patternProblem
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
const dialect = options?.dialect ?? "postgres";
|
|
344
|
-
if (dialect === "postgres" && (node.op === "matches" || node.op === "notMatches") && options?.postgresRegexpPushdown !== true) return {
|
|
345
|
-
kind: node.kind,
|
|
346
|
-
path,
|
|
347
|
-
reason: `'${node.op}' matches trilean's own ECMAScript 'RegExp' against the pattern, whereas PostgreSQL's '~'/'!~' would match it under PostgreSQL's own regular-expression dialect (POSIX ARE) -- a different language that can silently answer a different set of rows for the same pattern and data (for example, PostgreSQL's '.' matches a newline by default where ECMAScript's does not, and PostgreSQL's '\\w' follows the database's locale where ECMAScript's is ASCII-only) -- so this is refused unless 'postgresRegexpPushdown' is explicitly set 'true'`
|
|
348
|
-
};
|
|
349
|
-
if (node.op === "portableMatches" || node.op === "portableNotMatches") {
|
|
350
|
-
if (node.right.kind !== "textLiteral") return {
|
|
351
|
-
kind: node.kind,
|
|
352
|
-
path,
|
|
353
|
-
reason: "a 'portableMatches'/'portableNotMatches' pattern must be a literal, known at compile time -- translating it into this dialect's own pattern syntax happens once, at compile time, not per row"
|
|
354
|
-
};
|
|
355
|
-
try {
|
|
356
|
-
const ast = (0, trilean_regex.parseRegex)(node.right.value);
|
|
357
|
-
if (dialect === "postgres") require_portable_pattern.renderPostgresPattern(ast);
|
|
358
|
-
else require_portable_pattern.renderSqliteGlobPattern(ast);
|
|
359
|
-
} catch (error) {
|
|
360
|
-
return {
|
|
361
|
-
kind: node.kind,
|
|
362
|
-
path: `${path}.right`,
|
|
363
|
-
reason: error instanceof Error ? error.message : String(error)
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
case "memberOf": {
|
|
370
|
-
const operands = [{
|
|
371
|
-
node: node.operand,
|
|
372
|
-
path: `${path}.operand`
|
|
373
|
-
}, ...node.candidates.map((candidate, index) => ({
|
|
374
|
-
node: candidate,
|
|
375
|
-
path: `${path}.candidates[${String(index)}]`
|
|
376
|
-
}))];
|
|
377
|
-
for (const operand of operands) {
|
|
378
|
-
const unpushable = findUnpushableExpression(operand.node, operand.path, divergence, options);
|
|
379
|
-
if (unpushable !== void 0) return unpushable;
|
|
380
|
-
}
|
|
381
|
-
return findKindDivergence(node.kind, path, operands, options, divergence);
|
|
382
|
-
}
|
|
383
|
-
case "exists": return findUnpushableExpression(node.operand, `${path}.operand`, divergence, options);
|
|
384
|
-
case "some":
|
|
385
|
-
case "every": {
|
|
386
|
-
const resolved = resolveCollectionForGuard(node.kind, node.collection, path, options);
|
|
387
|
-
if ("reason" in resolved) return resolved;
|
|
388
|
-
const { itemOptions } = resolved;
|
|
389
|
-
const unpushableItem = findUnpushablePredicate(node.item, `${path}.item`, itemOptions, divergence);
|
|
390
|
-
if (unpushableItem !== void 0) return unpushableItem;
|
|
391
|
-
if (node.filter === void 0) return void 0;
|
|
392
|
-
return findUnpushablePredicate(node.filter, `${path}.filter`, itemOptions, divergence);
|
|
393
|
-
}
|
|
394
|
-
case "treeReference": return {
|
|
395
|
-
kind: node.kind,
|
|
396
|
-
path,
|
|
397
|
-
reason: "a referenced tree is resolved by the caller's resolvers; inline it before compiling"
|
|
398
|
-
};
|
|
399
|
-
default: return {
|
|
400
|
-
kind: unrecognisedKind,
|
|
401
|
-
path,
|
|
402
|
-
reason: "unrecognised predicate node kind"
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Walks the tree against the allow-list of what this compiler translates, and reports the first node it will not.
|
|
408
|
-
*
|
|
409
|
-
* The walk is an allow-list rather than a deny-list on purpose: a node kind added to trilean after this package was written is refused by default, instead of falling through to whatever branch happened to be last. That is the difference between a caller learning it must evaluate in process and a caller silently receiving a `WHERE` clause that answers a different question.
|
|
410
|
-
*
|
|
411
|
-
* `compilePredicateNode` runs this first and throws `UnsupportedNodeError` on any result, so calling it separately is only necessary to *decide* between pushdown and in-process evaluation without provoking an exception.
|
|
412
|
-
*
|
|
413
|
-
* Passing `options` widens the check: without them the walk is purely structural, and with them it also applies the operand-kind rules that depend on each mapped column's declared `paramType` (and therefore calls `columnFor`).
|
|
414
|
-
*
|
|
415
|
-
* Which nodes are refused does not depend on the dialect -- every divergence refused here is real in both -- except what a dialect cannot carry (see `valueProblem` and `identifierProblem`), which is decided for the dialect `options` names, and for PostgreSQL when there are none. A structural walk given no `options` otherwise refuses exactly what a walk given them would. What `options` also settles is which engine each `reason` describes; with none to read a dialect from, the reasons describe PostgreSQL, the dialect these refusals were first derived against.
|
|
416
|
-
* @throws `UnknownDialectError` if `options` names a dialect this version does not implement. Reporting a tree as pushable is a promise that `compilePredicateNode` will compile it, and under a dialect that does not exist it cannot -- so this is refused here rather than left to surface from the compiler, which is the one caller this function's answer is for.
|
|
417
|
-
*/
|
|
418
|
-
function findUnpushableNodeKind(node, options) {
|
|
419
|
-
const dialect = options?.dialect ?? "postgres";
|
|
420
|
-
require_options.assertImplementedDialect(dialect);
|
|
421
|
-
return findUnpushablePredicate(node, "$", options, DIALECT_DIVERGENCE[dialect]);
|
|
422
|
-
}
|
|
423
|
-
Object.defineProperty(exports, "findUnpushableNodeKind", {
|
|
424
|
-
enumerable: true,
|
|
425
|
-
get: function() {
|
|
426
|
-
return findUnpushableNodeKind;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
Object.defineProperty(exports, "identifierProblem", {
|
|
430
|
-
enumerable: true,
|
|
431
|
-
get: function() {
|
|
432
|
-
return identifierProblem;
|
|
433
|
-
}
|
|
434
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
// src/guard-test-helpers.ts
|
|
3
|
-
/** Shared across the split `guard.*.test.ts` files below -- a pushable comparison used as filler in trees whose real subject is something else entirely (an unrelated node kind, a collection wrapper). */
|
|
4
|
-
const ageOver = {
|
|
5
|
-
kind: "compare",
|
|
6
|
-
op: "gt",
|
|
7
|
-
left: {
|
|
8
|
-
kind: "reference",
|
|
9
|
-
key: "age"
|
|
10
|
-
},
|
|
11
|
-
right: {
|
|
12
|
-
kind: "numberLiteral",
|
|
13
|
-
value: 18
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
exports.ageOver = ageOver;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { PredicateNode } from "trilean";
|
|
2
|
-
/** Shared across the split `guard.*.test.ts` files below -- a pushable comparison used as filler in trees whose real subject is something else entirely (an unrelated node kind, a collection wrapper). */
|
|
3
|
-
export declare const ageOver: PredicateNode;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { PredicateNode } from "trilean";
|
|
2
|
-
/** Shared across the split `guard.*.test.ts` files below -- a pushable comparison used as filler in trees whose real subject is something else entirely (an unrelated node kind, a collection wrapper). */
|
|
3
|
-
export declare const ageOver: PredicateNode;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// src/guard-test-helpers.ts
|
|
2
|
-
/** Shared across the split `guard.*.test.ts` files below -- a pushable comparison used as filler in trees whose real subject is something else entirely (an unrelated node kind, a collection wrapper). */
|
|
3
|
-
const ageOver = {
|
|
4
|
-
kind: "compare",
|
|
5
|
-
op: "gt",
|
|
6
|
-
left: {
|
|
7
|
-
kind: "reference",
|
|
8
|
-
key: "age"
|
|
9
|
-
},
|
|
10
|
-
right: {
|
|
11
|
-
kind: "numberLiteral",
|
|
12
|
-
value: 18
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
export { ageOver };
|
package/dist/guard.cjs
DELETED
package/dist/guard.d.cts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { SqlCompileOptions } from "./options.cjs";
|
|
2
|
-
import { PredicateNode } from "trilean";
|
|
3
|
-
/** Where the walk stopped, and why. `kind` is the offending node's own `kind` even when the objection is not to the kind itself. */
|
|
4
|
-
export interface UnpushableNode {
|
|
5
|
-
kind: string;
|
|
6
|
-
/** A dotted path from the root of the tree, e.g. `$.operands[1].left`. */
|
|
7
|
-
path: string;
|
|
8
|
-
reason: string;
|
|
9
|
-
/** Set when the refusal is a mapped name the dialect cannot render as an identifier: which mapping returned it and under which key. `compilePredicateNode` reports it as `InvalidColumnError` or `InvalidCollectionTableError`. */
|
|
10
|
-
identifier?: {
|
|
11
|
-
role: "column" | "table";
|
|
12
|
-
key: string;
|
|
13
|
-
problem: string;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Walks the tree against the allow-list of what this compiler translates, and reports the first node it will not.
|
|
18
|
-
*
|
|
19
|
-
* The walk is an allow-list rather than a deny-list on purpose: a node kind added to trilean after this package was written is refused by default, instead of falling through to whatever branch happened to be last. That is the difference between a caller learning it must evaluate in process and a caller silently receiving a `WHERE` clause that answers a different question.
|
|
20
|
-
*
|
|
21
|
-
* `compilePredicateNode` runs this first and throws `UnsupportedNodeError` on any result, so calling it separately is only necessary to *decide* between pushdown and in-process evaluation without provoking an exception.
|
|
22
|
-
*
|
|
23
|
-
* Passing `options` widens the check: without them the walk is purely structural, and with them it also applies the operand-kind rules that depend on each mapped column's declared `paramType` (and therefore calls `columnFor`).
|
|
24
|
-
*
|
|
25
|
-
* Which nodes are refused does not depend on the dialect -- every divergence refused here is real in both -- except what a dialect cannot carry (see `valueProblem` and `identifierProblem`), which is decided for the dialect `options` names, and for PostgreSQL when there are none. A structural walk given no `options` otherwise refuses exactly what a walk given them would. What `options` also settles is which engine each `reason` describes; with none to read a dialect from, the reasons describe PostgreSQL, the dialect these refusals were first derived against.
|
|
26
|
-
* @throws `UnknownDialectError` if `options` names a dialect this version does not implement. Reporting a tree as pushable is a promise that `compilePredicateNode` will compile it, and under a dialect that does not exist it cannot -- so this is refused here rather than left to surface from the compiler, which is the one caller this function's answer is for.
|
|
27
|
-
*/
|
|
28
|
-
export declare function findUnpushableNodeKind(node: PredicateNode, options?: SqlCompileOptions): UnpushableNode | undefined;
|
package/dist/index.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_guard = require("./guard-CCet6aaa.cjs");
|
|
3
|
-
const require_compile = require("./compile.cjs");
|
|
4
|
-
const require_errors = require("./errors.cjs");
|
|
5
|
-
exports.InvalidCollectionTableError = require_errors.InvalidCollectionTableError;
|
|
6
|
-
exports.InvalidColumnError = require_errors.InvalidColumnError;
|
|
7
|
-
exports.TrileanSqlError = require_errors.TrileanSqlError;
|
|
8
|
-
exports.UnknownDialectError = require_errors.UnknownDialectError;
|
|
9
|
-
exports.UnsupportedNodeError = require_errors.UnsupportedNodeError;
|
|
10
|
-
exports.compilePredicateNode = require_compile.compilePredicateNode;
|
|
11
|
-
exports.findUnpushableNodeKind = require_guard.findUnpushableNodeKind;
|
package/dist/index.d.cts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { CompiledSql, SqlColumnBinding, SqlCompileOptions, SqlDialect, SqlParamType } from "./options.cjs";
|
|
2
|
-
import { UnpushableNode, findUnpushableNodeKind } from "./guard.cjs";
|
|
3
|
-
import { compilePredicateNode } from "./compile.cjs";
|
|
4
|
-
import { InvalidCollectionTableError, InvalidColumnError, TrileanSqlError, UnknownDialectError, UnsupportedNodeError } from "./errors.cjs";
|
|
5
|
-
export { type CompiledSql, InvalidCollectionTableError, InvalidColumnError, type SqlColumnBinding, type SqlCompileOptions, type SqlDialect, type SqlParamType, TrileanSqlError, UnknownDialectError, type UnpushableNode, UnsupportedNodeError, compilePredicateNode, findUnpushableNodeKind };
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
const require_errors = require("./errors.cjs");
|
|
2
|
-
// src/internal/sqlite-instant.ts
|
|
3
|
-
/**
|
|
4
|
-
* How the SQLite dialect reads an instant, in one place.
|
|
5
|
-
*
|
|
6
|
-
* SQLite has no timestamp type, and its date functions read far more than an instant: the text `now` is the present time, a time of day is a date in the year 2000, a number is a Julian day. The evaluator reads none of these. So the SQL decides first, with a shape test that needs no extension, whether a stored value is an instant in exactly one grammar, and only then converts it; any other value is NULL (unknown) whatever the date functions would make of it, and the same grammar is applied to an `instantLiteral` when the tree is compiled.
|
|
7
|
-
*
|
|
8
|
-
* The grammar: four-digit year, `-`, two-digit month, `-`, two-digit day, `T` or one space, two-digit hour, `:`, minute, `:`, second, an optional `.` and one or more fractional digits, then `Z` or a sign, two-digit hours, `:` and two-digit minutes. The value must also be a real moment: a month 1 to 12, a day that exists in that month (so no `02-30`), an hour 0 to 23, a minute and second 0 to 59 (no leap second, no hour 24), and an offset of at most 23:59. Within it SQLite, PostgreSQL and the evaluator (`Date.parse`) read the same instant, to the millisecond; the fraction is truncated to three digits, as `Date.parse` does, and is not rounded as SQLite's own date functions would.
|
|
9
|
-
*/
|
|
10
|
-
/** The characters up to the seconds, in the form SQLite's `GLOB` reads: four digits, `-`, two, `-`, two, `T` or a space, two, `:`, two, `:`, two. */
|
|
11
|
-
const DATE_AND_TIME_SHAPE = "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][T ][0-9][0-9]:[0-9][0-9]:[0-9][0-9]";
|
|
12
|
-
const OFFSET_SHAPE = "[+-][0-9][0-9]:[0-9][0-9]";
|
|
13
|
-
/** The characters before the seconds end, which are the first nineteen of a value in the grammar. */
|
|
14
|
-
const SECONDS_END = 19;
|
|
15
|
-
/** Where the fraction's point, or the zone, starts (1-based). */
|
|
16
|
-
const AFTER_SECONDS = 20;
|
|
17
|
-
/** The width of a numeric offset, `+HH:MM`. */
|
|
18
|
-
const OFFSET_WIDTH = 6;
|
|
19
|
-
const MILLISECONDS_PER_SECOND = 1e3;
|
|
20
|
-
const MILLISECONDS_PER_MINUTE = 6e4;
|
|
21
|
-
const MINUTES_PER_HOUR = 60;
|
|
22
|
-
const FRACTION_DIGITS = 3;
|
|
23
|
-
/**
|
|
24
|
-
* The SQL that reads `column` (an expression of one SQLite value) as whole milliseconds since the epoch, or NULL when it is not an instant in the grammar above. `column` appears many times, so it must be a column reference or a placeholder-free expression.
|
|
25
|
-
*/
|
|
26
|
-
function sqliteInstantColumn(column) {
|
|
27
|
-
const length = `length(${column})`;
|
|
28
|
-
const isZulu = `${column} GLOB '*Z'`;
|
|
29
|
-
const fractionLength = `(${length} - ${String(AFTER_SECONDS)} - CASE WHEN ${isZulu} THEN 1 ELSE ${String(OFFSET_WIDTH)} END)`;
|
|
30
|
-
const zoneStart = `CASE WHEN ${isZulu} THEN ${length} ELSE ${length} - ${String(5)} END`;
|
|
31
|
-
const afterSeconds = `substr(${column}, ${String(AFTER_SECONDS)})`;
|
|
32
|
-
const fractionOnly = `substr(${column}, ${String(21)}, ${fractionLength})`;
|
|
33
|
-
const zoneShape = `(${afterSeconds} = 'Z' OR ${afterSeconds} GLOB '${OFFSET_SHAPE}' OR (substr(${column}, ${String(AFTER_SECONDS)}, 1) = '.' AND ${fractionLength} > 0 AND ${fractionOnly} NOT GLOB '*[^0-9]*' AND (${isZulu} OR ${column} GLOB '*${OFFSET_SHAPE}')))`;
|
|
34
|
-
const shape = `instr(CAST(${column} AS BLOB), x'00') = 0 AND ${column} GLOB '${DATE_AND_TIME_SHAPE}*' AND ${zoneShape}`;
|
|
35
|
-
const dateAndTime = `substr(${column}, 1, ${String(SECONDS_END)})`;
|
|
36
|
-
const real = [
|
|
37
|
-
`strftime('%Y-%m-%d', ${dateAndTime}) = substr(${column}, 1, 10)`,
|
|
38
|
-
`strftime('%s', ${dateAndTime}) IS NOT NULL`,
|
|
39
|
-
`substr(${column}, 12, 2) < '24'`,
|
|
40
|
-
`(${isZulu} OR (substr(${column}, ${zoneStart} + 1, 2) <= '23' AND substr(${column}, ${zoneStart} + 4, 2) <= '59'))`
|
|
41
|
-
].join(" AND ");
|
|
42
|
-
const fraction = `CASE WHEN substr(${column}, ${String(AFTER_SECONDS)}, 1) = '.' THEN CAST(substr(${fractionOnly} || '00', 1, ${String(FRACTION_DIGITS)}) AS INTEGER) ELSE 0 END`;
|
|
43
|
-
const offsetMinutes = `CASE WHEN ${isZulu} THEN 0 ELSE (CASE substr(${column}, ${zoneStart}, 1) WHEN '-' THEN -1 ELSE 1 END) * (CAST(substr(${column}, ${zoneStart} + 1, 2) AS INTEGER) * ${String(MINUTES_PER_HOUR)} + CAST(substr(${column}, ${zoneStart} + 4, 2) AS INTEGER)) END`;
|
|
44
|
-
return `(CASE WHEN ${shape} AND ${real} THEN CAST(strftime('%s', ${dateAndTime}) AS INTEGER) * ${String(MILLISECONDS_PER_SECOND)} + ${fraction} - (${offsetMinutes}) * ${String(MILLISECONDS_PER_MINUTE)} END)`;
|
|
45
|
-
}
|
|
46
|
-
const INSTANT = /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})[T ](?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(?:\.(?<fraction>\d+))?(?:Z|(?<sign>[+-])(?<zoneHour>\d{2}):(?<zoneMinute>\d{2}))$/u;
|
|
47
|
-
const LAST_HOUR = 23;
|
|
48
|
-
const LAST_MINUTE_OR_SECOND = 59;
|
|
49
|
-
/**
|
|
50
|
-
* The bind value of an `instantLiteral` for SQLite: the whole milliseconds since the epoch of a text in the grammar above, computed from its parts with the rules the SQL applies to a stored value, or `null` (unknown) for any other text.
|
|
51
|
-
*/
|
|
52
|
-
function sqliteInstantParameter(iso) {
|
|
53
|
-
const groups = INSTANT.exec(iso)?.groups;
|
|
54
|
-
if (groups === void 0) return null;
|
|
55
|
-
const part = (name) => Number(groups[name] ?? 0);
|
|
56
|
-
const [year, month, day] = [
|
|
57
|
-
part("year"),
|
|
58
|
-
part("month"),
|
|
59
|
-
part("day")
|
|
60
|
-
];
|
|
61
|
-
const moment = /* @__PURE__ */ new Date(0);
|
|
62
|
-
moment.setUTCFullYear(year, month - 1, day);
|
|
63
|
-
moment.setUTCHours(part("hour"), part("minute"), part("second"), 0);
|
|
64
|
-
if (!(moment.getUTCFullYear() === year && moment.getUTCMonth() === month - 1 && moment.getUTCDate() === day) || part("hour") > LAST_HOUR || part("minute") > LAST_MINUTE_OR_SECOND || part("second") > LAST_MINUTE_OR_SECOND || part("zoneHour") > LAST_HOUR || part("zoneMinute") > LAST_MINUTE_OR_SECOND) return null;
|
|
65
|
-
const milliseconds = Number(`${groups.fraction ?? ""}00`.slice(0, FRACTION_DIGITS));
|
|
66
|
-
const offset = (groups.sign === "-" ? -1 : 1) * (part("zoneHour") * MINUTES_PER_HOUR + part("zoneMinute")) * MILLISECONDS_PER_MINUTE;
|
|
67
|
-
return moment.getTime() + milliseconds - offset;
|
|
68
|
-
}
|
|
69
|
-
// src/options.ts
|
|
70
|
-
/** The PostgreSQL type each declared value kind is cast to. `timestamptz` rather than `timestamp`: trilean's `instant` is an ISO-8601 string that may carry an offset, and parsing one as a naive `timestamp` would silently discard it. */
|
|
71
|
-
const POSTGRES_TYPE_NAME = {
|
|
72
|
-
text: "text",
|
|
73
|
-
number: "double precision",
|
|
74
|
-
boolean: "boolean",
|
|
75
|
-
timestamp: "timestamptz"
|
|
76
|
-
};
|
|
77
|
-
const DIALECT_CONFIG = {
|
|
78
|
-
postgres: {
|
|
79
|
-
matches: "~",
|
|
80
|
-
notMatches: "!~",
|
|
81
|
-
portableMatches: "~",
|
|
82
|
-
portableNotMatches: "!~",
|
|
83
|
-
placeholder: (index, castTo) => `$${String(index)}::${POSTGRES_TYPE_NAME[castTo]}`,
|
|
84
|
-
emptyMemberOfNullSuffix: "::boolean",
|
|
85
|
-
instantColumn: (columnSql) => columnSql,
|
|
86
|
-
instantParameter: (iso) => iso
|
|
87
|
-
},
|
|
88
|
-
sqlite: {
|
|
89
|
-
matches: "REGEXP",
|
|
90
|
-
notMatches: "NOT REGEXP",
|
|
91
|
-
portableMatches: "GLOB",
|
|
92
|
-
portableNotMatches: "NOT GLOB",
|
|
93
|
-
placeholder: () => "?",
|
|
94
|
-
emptyMemberOfNullSuffix: "",
|
|
95
|
-
instantColumn: sqliteInstantColumn,
|
|
96
|
-
instantParameter: sqliteInstantParameter
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Refuses a dialect this version does not implement, before anything indexes a per-dialect table with it.
|
|
101
|
-
*
|
|
102
|
-
* Both entry points check their own argument, because both are reachable with a name the type describes but cannot enforce -- a dialect is exactly the sort of value that arrives as a configuration string asserted into the union at the boundary. Left unchecked, that name is not caught anywhere: the compiler reads an operator off `undefined` and throws a `TypeError` naming an internal field, and the guard, whose tables are only consulted for a node it actually objects to, answers "pushable" for a tree the compiler then fails on -- the one thing `findUnpushableNodeKind` exists to decide, decided wrongly.
|
|
103
|
-
*
|
|
104
|
-
* `DIALECT_CONFIG` is the list, rather than a second constant, so implementing a dialect cannot leave this behind.
|
|
105
|
-
*/
|
|
106
|
-
function assertImplementedDialect(dialect) {
|
|
107
|
-
if (!Object.hasOwn(DIALECT_CONFIG, dialect)) throw new require_errors.UnknownDialectError(dialect, Object.keys(DIALECT_CONFIG));
|
|
108
|
-
}
|
|
109
|
-
Object.defineProperty(exports, "DIALECT_CONFIG", {
|
|
110
|
-
enumerable: true,
|
|
111
|
-
get: function() {
|
|
112
|
-
return DIALECT_CONFIG;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
Object.defineProperty(exports, "POSTGRES_TYPE_NAME", {
|
|
116
|
-
enumerable: true,
|
|
117
|
-
get: function() {
|
|
118
|
-
return POSTGRES_TYPE_NAME;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
Object.defineProperty(exports, "assertImplementedDialect", {
|
|
122
|
-
enumerable: true,
|
|
123
|
-
get: function() {
|
|
124
|
-
return assertImplementedDialect;
|
|
125
|
-
}
|
|
126
|
-
});
|