trilean-sql 2.2.42 → 2.3.0
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 +5 -3
- package/dist/compile.cjs +23 -14
- package/dist/compile.d.cts +2 -1
- package/dist/compile.d.ts +2 -1
- package/dist/compile.js +23 -14
- package/dist/errors.cjs +2 -2
- package/dist/errors.js +2 -2
- package/dist/guard-CCet6aaa.cjs +434 -0
- package/dist/guard-D4CIUc5h.js +423 -0
- package/dist/guard.cjs +2 -342
- package/dist/guard.d.cts +7 -1
- package/dist/guard.d.ts +7 -1
- package/dist/guard.js +1 -342
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/guard.cjs
CHANGED
|
@@ -1,343 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
let trilean_regex = require("trilean-regex");
|
|
5
|
-
// src/guard.ts
|
|
6
|
-
const STATIC_KIND_OF_PARAM_TYPE = {
|
|
7
|
-
text: "text",
|
|
8
|
-
number: "number",
|
|
9
|
-
boolean: "boolean",
|
|
10
|
-
timestamp: "instant"
|
|
11
|
-
};
|
|
12
|
-
/** 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. */
|
|
13
|
-
const ORDERING_OPERATORS = /* @__PURE__ */ new Set([
|
|
14
|
-
"gt",
|
|
15
|
-
"gte",
|
|
16
|
-
"lt",
|
|
17
|
-
"lte"
|
|
18
|
-
]);
|
|
19
|
-
/** 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. */
|
|
20
|
-
const STATIC_KIND_OF_LITERAL = {
|
|
21
|
-
textLiteral: "text",
|
|
22
|
-
numberLiteral: "number",
|
|
23
|
-
booleanLiteral: "boolean",
|
|
24
|
-
instantLiteral: "instant"
|
|
25
|
-
};
|
|
26
|
-
const DIALECT_DIVERGENCE = {
|
|
27
|
-
postgres: {
|
|
28
|
-
complexNumbers: "PostgreSQL has no complex number type",
|
|
29
|
-
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",
|
|
30
|
-
crossKindCoercion: "PostgreSQL may coerce one to the other and answer definitely",
|
|
31
|
-
textOrdering: (operandPath) => `PostgreSQL would order the text operand at ${operandPath} collation-wise and answer definitely`,
|
|
32
|
-
booleanOrdering: "PostgreSQL orders false before true"
|
|
33
|
-
},
|
|
34
|
-
sqlite: {
|
|
35
|
-
complexNumbers: "SQLite has no complex number type",
|
|
36
|
-
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",
|
|
37
|
-
crossKindCoercion: "SQLite's type affinity may coerce one to the other and answer definitely",
|
|
38
|
-
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)`,
|
|
39
|
-
booleanOrdering: "SQLite stores booleans as the integers 0 and 1 and orders them as integers"
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
function staticValueKindOf(node, options) {
|
|
43
|
-
if (node.kind !== "reference") return STATIC_KIND_OF_LITERAL[node.kind];
|
|
44
|
-
if (options === void 0 || typeof node.key !== "string") return void 0;
|
|
45
|
-
const paramType = options.columnFor(node.key).paramType;
|
|
46
|
-
return paramType === void 0 ? void 0 : STATIC_KIND_OF_PARAM_TYPE[paramType];
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* 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.
|
|
50
|
-
*
|
|
51
|
-
* `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.
|
|
52
|
-
*/
|
|
53
|
-
function resolveCollectionForGuard(kind, collection, path, options) {
|
|
54
|
-
if (typeof collection !== "string") return {
|
|
55
|
-
kind,
|
|
56
|
-
path,
|
|
57
|
-
reason: "only a string collection key can be mapped to a correlated table; this collection is a non-string JSON value"
|
|
58
|
-
};
|
|
59
|
-
if (options === void 0) return { itemOptions: void 0 };
|
|
60
|
-
if (options.collectionFor === void 0) return {
|
|
61
|
-
kind,
|
|
62
|
-
path,
|
|
63
|
-
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"
|
|
64
|
-
};
|
|
65
|
-
const binding = options.collectionFor(collection);
|
|
66
|
-
return { itemOptions: {
|
|
67
|
-
...options,
|
|
68
|
-
columnFor: binding.columnFor
|
|
69
|
-
} };
|
|
70
|
-
}
|
|
71
|
-
function findUnpushableExpression(node, path, divergence, options) {
|
|
72
|
-
const unrecognisedKind = node.kind;
|
|
73
|
-
switch (node.kind) {
|
|
74
|
-
case "reference":
|
|
75
|
-
if (typeof node.key !== "string") return {
|
|
76
|
-
kind: node.kind,
|
|
77
|
-
path,
|
|
78
|
-
reason: "only a string reference key can be mapped to a column; this key is a non-string JSON value"
|
|
79
|
-
};
|
|
80
|
-
if (node.unit !== void 0) return {
|
|
81
|
-
kind: node.kind,
|
|
82
|
-
path,
|
|
83
|
-
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"
|
|
84
|
-
};
|
|
85
|
-
return;
|
|
86
|
-
case "numberLiteral":
|
|
87
|
-
if (node.unit !== void 0) return {
|
|
88
|
-
kind: node.kind,
|
|
89
|
-
path,
|
|
90
|
-
reason: "a unit-tagged number is only comparable with an operand of the same unit, and SQL has no unit to compare"
|
|
91
|
-
};
|
|
92
|
-
if (Number.isNaN(node.value)) return {
|
|
93
|
-
kind: node.kind,
|
|
94
|
-
path,
|
|
95
|
-
reason: divergence.nan
|
|
96
|
-
};
|
|
97
|
-
return;
|
|
98
|
-
case "textLiteral":
|
|
99
|
-
case "booleanLiteral":
|
|
100
|
-
case "instantLiteral": return;
|
|
101
|
-
case "durationLiteral": return {
|
|
102
|
-
kind: node.kind,
|
|
103
|
-
path,
|
|
104
|
-
reason: "trilean compares two durations in whichever unit each carries, and a column holds no unit to carry"
|
|
105
|
-
};
|
|
106
|
-
case "complexLiteral": return {
|
|
107
|
-
kind: node.kind,
|
|
108
|
-
path,
|
|
109
|
-
reason: divergence.complexNumbers
|
|
110
|
-
};
|
|
111
|
-
case "arithmetic":
|
|
112
|
-
case "negate": return {
|
|
113
|
-
kind: node.kind,
|
|
114
|
-
path,
|
|
115
|
-
reason: "arithmetic carries and combines units, and pushing it down would drop that dimensional analysis without saying so"
|
|
116
|
-
};
|
|
117
|
-
case "call": return {
|
|
118
|
-
kind: node.kind,
|
|
119
|
-
path,
|
|
120
|
-
reason: "a function's implementation lives in the caller's FunctionRegistry, not in the database"
|
|
121
|
-
};
|
|
122
|
-
case "lookup": return {
|
|
123
|
-
kind: node.kind,
|
|
124
|
-
path,
|
|
125
|
-
reason: "a lookup table is resolved by the caller's resolvers"
|
|
126
|
-
};
|
|
127
|
-
case "conditional": return {
|
|
128
|
-
kind: node.kind,
|
|
129
|
-
path,
|
|
130
|
-
reason: "conditional evaluation is not implemented in this version of the compiler"
|
|
131
|
-
};
|
|
132
|
-
case "fold": {
|
|
133
|
-
if (node.combiner.mode === "reduce") return {
|
|
134
|
-
kind: node.kind,
|
|
135
|
-
path,
|
|
136
|
-
reason: "a 'reduce' fold threads an arbitrary combine expression through the collection in a caller-chosen order, which has no general SQL translation"
|
|
137
|
-
};
|
|
138
|
-
const resolved = resolveCollectionForGuard(node.kind, node.collection, path, options);
|
|
139
|
-
if ("reason" in resolved) return resolved;
|
|
140
|
-
const { itemOptions } = resolved;
|
|
141
|
-
if (node.filter !== void 0) {
|
|
142
|
-
const unpushableFilter = findUnpushablePredicate(node.filter, `${path}.filter`, itemOptions, divergence);
|
|
143
|
-
if (unpushableFilter !== void 0) return unpushableFilter;
|
|
144
|
-
}
|
|
145
|
-
const itemPath = `${path}.combiner.item`;
|
|
146
|
-
const unpushableItem = findUnpushableExpression(node.combiner.item, itemPath, divergence, itemOptions);
|
|
147
|
-
if (unpushableItem !== void 0) return unpushableItem;
|
|
148
|
-
const itemKind = staticValueKindOf(node.combiner.item, itemOptions);
|
|
149
|
-
if (itemKind === "text") return {
|
|
150
|
-
kind: node.kind,
|
|
151
|
-
path: itemPath,
|
|
152
|
-
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)}`
|
|
153
|
-
};
|
|
154
|
-
if (itemKind === "boolean") return {
|
|
155
|
-
kind: node.kind,
|
|
156
|
-
path: itemPath,
|
|
157
|
-
reason: `a '${node.combiner.mode}' fold orders participating items by comparing them, and booleans have no ordering in trilean -- whereas ${divergence.booleanOrdering}`
|
|
158
|
-
};
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
case "accumulator": return {
|
|
162
|
-
kind: node.kind,
|
|
163
|
-
path,
|
|
164
|
-
reason: "an accumulator is only meaningful inside a reduce fold"
|
|
165
|
-
};
|
|
166
|
-
case "delegate": return {
|
|
167
|
-
kind: node.kind,
|
|
168
|
-
path,
|
|
169
|
-
reason: "a delegated decision is made by an external system"
|
|
170
|
-
};
|
|
171
|
-
case "treeReference": return {
|
|
172
|
-
kind: node.kind,
|
|
173
|
-
path,
|
|
174
|
-
reason: "a referenced tree is resolved by the caller's resolvers; inline it before compiling"
|
|
175
|
-
};
|
|
176
|
-
default: return {
|
|
177
|
-
kind: unrecognisedKind,
|
|
178
|
-
path,
|
|
179
|
-
reason: "unrecognised expression node kind"
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/** 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. */
|
|
184
|
-
function findKindDivergence(kind, path, operands, options, divergence) {
|
|
185
|
-
const known = operands.map((operand) => ({
|
|
186
|
-
path: operand.path,
|
|
187
|
-
staticKind: staticValueKindOf(operand.node, options)
|
|
188
|
-
})).filter((entry) => entry.staticKind !== void 0);
|
|
189
|
-
const first = known[0];
|
|
190
|
-
if (first === void 0) return void 0;
|
|
191
|
-
const mismatched = known.find((entry) => entry.staticKind !== first.staticKind);
|
|
192
|
-
if (mismatched !== void 0) return {
|
|
193
|
-
kind,
|
|
194
|
-
path,
|
|
195
|
-
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}`
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function findUnpushablePredicate(node, path, options, divergence) {
|
|
199
|
-
const unrecognisedKind = node.kind;
|
|
200
|
-
switch (node.kind) {
|
|
201
|
-
case "not": return findUnpushablePredicate(node.operand, `${path}.operand`, options, divergence);
|
|
202
|
-
case "and":
|
|
203
|
-
case "or": return findUnpushablePredicate(node.left, `${path}.left`, options, divergence) ?? findUnpushablePredicate(node.right, `${path}.right`, options, divergence);
|
|
204
|
-
case "allOf":
|
|
205
|
-
case "anyOf":
|
|
206
|
-
for (const [index, operand] of node.operands.entries()) {
|
|
207
|
-
const unpushable = findUnpushablePredicate(operand, `${path}.operands[${String(index)}]`, options, divergence);
|
|
208
|
-
if (unpushable !== void 0) return unpushable;
|
|
209
|
-
}
|
|
210
|
-
return;
|
|
211
|
-
case "compare": {
|
|
212
|
-
const operands = [{
|
|
213
|
-
node: node.left,
|
|
214
|
-
path: `${path}.left`
|
|
215
|
-
}, {
|
|
216
|
-
node: node.right,
|
|
217
|
-
path: `${path}.right`
|
|
218
|
-
}];
|
|
219
|
-
for (const operand of operands) {
|
|
220
|
-
const unpushable = findUnpushableExpression(operand.node, operand.path, divergence, options);
|
|
221
|
-
if (unpushable !== void 0) return unpushable;
|
|
222
|
-
}
|
|
223
|
-
const mismatch = findKindDivergence(node.kind, path, operands, options, divergence);
|
|
224
|
-
if (mismatch !== void 0) return mismatch;
|
|
225
|
-
for (const operand of operands) {
|
|
226
|
-
const staticKind = staticValueKindOf(operand.node, options);
|
|
227
|
-
if (staticKind === "text") return {
|
|
228
|
-
kind: node.kind,
|
|
229
|
-
path,
|
|
230
|
-
reason: `'compare' never compares text in trilean -- it returns wrong-type and directs the caller to 'textCompare' -- but ${divergence.textOrdering(operand.path)}`
|
|
231
|
-
};
|
|
232
|
-
if (staticKind === "boolean" && ORDERING_OPERATORS.has(node.op)) return {
|
|
233
|
-
kind: node.kind,
|
|
234
|
-
path,
|
|
235
|
-
reason: `booleans have no ordering in trilean, so '${node.op}' against the boolean operand at ${operand.path} is wrong-type there, whereas ${divergence.booleanOrdering}`
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
case "textCompare": {
|
|
241
|
-
if ((node.op === "matches" || node.op === "notMatches") && options?.dialect === "sqlite" && options.sqliteRegexpAvailable === false) return {
|
|
242
|
-
kind: node.kind,
|
|
243
|
-
path,
|
|
244
|
-
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`
|
|
245
|
-
};
|
|
246
|
-
const operands = [{
|
|
247
|
-
node: node.left,
|
|
248
|
-
path: `${path}.left`
|
|
249
|
-
}, {
|
|
250
|
-
node: node.right,
|
|
251
|
-
path: `${path}.right`
|
|
252
|
-
}];
|
|
253
|
-
for (const operand of operands) {
|
|
254
|
-
const unpushable = findUnpushableExpression(operand.node, operand.path, divergence, options);
|
|
255
|
-
if (unpushable !== void 0) return unpushable;
|
|
256
|
-
const staticKind = staticValueKindOf(operand.node, options);
|
|
257
|
-
if (staticKind !== void 0 && staticKind !== "text") return {
|
|
258
|
-
kind: node.kind,
|
|
259
|
-
path,
|
|
260
|
-
reason: `'textCompare' requires text operands in trilean, and the operand at ${operand.path} is a '${staticKind}' value`
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
const dialect = options?.dialect ?? "postgres";
|
|
264
|
-
if (dialect === "postgres" && (node.op === "matches" || node.op === "notMatches") && options?.postgresRegexpPushdown !== true) return {
|
|
265
|
-
kind: node.kind,
|
|
266
|
-
path,
|
|
267
|
-
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'`
|
|
268
|
-
};
|
|
269
|
-
if (node.op === "portableMatches" || node.op === "portableNotMatches") {
|
|
270
|
-
if (node.right.kind !== "textLiteral") return {
|
|
271
|
-
kind: node.kind,
|
|
272
|
-
path,
|
|
273
|
-
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"
|
|
274
|
-
};
|
|
275
|
-
try {
|
|
276
|
-
const ast = (0, trilean_regex.parseRegex)(node.right.value);
|
|
277
|
-
if (dialect === "postgres") require_portable_pattern.renderPostgresPattern(ast);
|
|
278
|
-
else require_portable_pattern.renderSqliteGlobPattern(ast);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
return {
|
|
281
|
-
kind: node.kind,
|
|
282
|
-
path: `${path}.right`,
|
|
283
|
-
reason: error instanceof Error ? error.message : String(error)
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
case "memberOf": {
|
|
290
|
-
const operands = [{
|
|
291
|
-
node: node.operand,
|
|
292
|
-
path: `${path}.operand`
|
|
293
|
-
}, ...node.candidates.map((candidate, index) => ({
|
|
294
|
-
node: candidate,
|
|
295
|
-
path: `${path}.candidates[${String(index)}]`
|
|
296
|
-
}))];
|
|
297
|
-
for (const operand of operands) {
|
|
298
|
-
const unpushable = findUnpushableExpression(operand.node, operand.path, divergence, options);
|
|
299
|
-
if (unpushable !== void 0) return unpushable;
|
|
300
|
-
}
|
|
301
|
-
return findKindDivergence(node.kind, path, operands, options, divergence);
|
|
302
|
-
}
|
|
303
|
-
case "exists": return findUnpushableExpression(node.operand, `${path}.operand`, divergence, options);
|
|
304
|
-
case "some":
|
|
305
|
-
case "every": {
|
|
306
|
-
const resolved = resolveCollectionForGuard(node.kind, node.collection, path, options);
|
|
307
|
-
if ("reason" in resolved) return resolved;
|
|
308
|
-
const { itemOptions } = resolved;
|
|
309
|
-
const unpushableItem = findUnpushablePredicate(node.item, `${path}.item`, itemOptions, divergence);
|
|
310
|
-
if (unpushableItem !== void 0) return unpushableItem;
|
|
311
|
-
if (node.filter === void 0) return void 0;
|
|
312
|
-
return findUnpushablePredicate(node.filter, `${path}.filter`, itemOptions, divergence);
|
|
313
|
-
}
|
|
314
|
-
case "treeReference": return {
|
|
315
|
-
kind: node.kind,
|
|
316
|
-
path,
|
|
317
|
-
reason: "a referenced tree is resolved by the caller's resolvers; inline it before compiling"
|
|
318
|
-
};
|
|
319
|
-
default: return {
|
|
320
|
-
kind: unrecognisedKind,
|
|
321
|
-
path,
|
|
322
|
-
reason: "unrecognised predicate node kind"
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Walks the tree against the allow-list of what this compiler translates, and reports the first node it will not.
|
|
328
|
-
*
|
|
329
|
-
* 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.
|
|
330
|
-
*
|
|
331
|
-
* `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.
|
|
332
|
-
*
|
|
333
|
-
* 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`).
|
|
334
|
-
*
|
|
335
|
-
* Which nodes are refused does not depend on the dialect -- every divergence refused here is real in both -- so a structural walk given no `options` 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.
|
|
336
|
-
* @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.
|
|
337
|
-
*/
|
|
338
|
-
function findUnpushableNodeKind(node, options) {
|
|
339
|
-
const dialect = options?.dialect ?? "postgres";
|
|
340
|
-
require_options.assertImplementedDialect(dialect);
|
|
341
|
-
return findUnpushablePredicate(node, "$", options, DIALECT_DIVERGENCE[dialect]);
|
|
342
|
-
}
|
|
343
|
-
exports.findUnpushableNodeKind = findUnpushableNodeKind;
|
|
2
|
+
const require_guard = require("./guard-CCet6aaa.cjs");
|
|
3
|
+
exports.findUnpushableNodeKind = require_guard.findUnpushableNodeKind;
|
package/dist/guard.d.cts
CHANGED
|
@@ -6,6 +6,12 @@ export interface UnpushableNode {
|
|
|
6
6
|
/** A dotted path from the root of the tree, e.g. `$.operands[1].left`. */
|
|
7
7
|
path: string;
|
|
8
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
|
+
};
|
|
9
15
|
}
|
|
10
16
|
/**
|
|
11
17
|
* Walks the tree against the allow-list of what this compiler translates, and reports the first node it will not.
|
|
@@ -16,7 +22,7 @@ export interface UnpushableNode {
|
|
|
16
22
|
*
|
|
17
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`).
|
|
18
24
|
*
|
|
19
|
-
* Which nodes are refused does not depend on the dialect -- every divergence refused here is real in both --
|
|
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.
|
|
20
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.
|
|
21
27
|
*/
|
|
22
28
|
export declare function findUnpushableNodeKind(node: PredicateNode, options?: SqlCompileOptions): UnpushableNode | undefined;
|
package/dist/guard.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ export interface UnpushableNode {
|
|
|
6
6
|
/** A dotted path from the root of the tree, e.g. `$.operands[1].left`. */
|
|
7
7
|
path: string;
|
|
8
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
|
+
};
|
|
9
15
|
}
|
|
10
16
|
/**
|
|
11
17
|
* Walks the tree against the allow-list of what this compiler translates, and reports the first node it will not.
|
|
@@ -16,7 +22,7 @@ export interface UnpushableNode {
|
|
|
16
22
|
*
|
|
17
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`).
|
|
18
24
|
*
|
|
19
|
-
* Which nodes are refused does not depend on the dialect -- every divergence refused here is real in both --
|
|
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.
|
|
20
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.
|
|
21
27
|
*/
|
|
22
28
|
export declare function findUnpushableNodeKind(node: PredicateNode, options?: SqlCompileOptions): UnpushableNode | undefined;
|