@aeye/query 0.6.4 → 0.6.6
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 +96 -5
- package/aeye-query.md +540 -299
- package/dist/index.d.ts +3634 -190
- package/dist/index.js +14916 -10558
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -58,8 +58,22 @@ is rejected — a relation compares by identity, not order.
|
|
|
58
58
|
|
|
59
59
|
Indexes are **composite**: an ordered list of parts, each with a prefix
|
|
60
60
|
distinct-row `count` (non-increasing); the index is unique iff its last part's
|
|
61
|
-
`count === 1`. Text matching is
|
|
62
|
-
|
|
61
|
+
`count === 1`. Text matching is governed by a text field's `casing`, else the engine's
|
|
62
|
+
`textCasing` default (`'fold'` unless you set it):
|
|
63
|
+
|
|
64
|
+
| `casing` | means | SQL for `a = b` | in-memory runtime |
|
|
65
|
+
|--------------|------------------------------------------------|-----------------------|-------------------|
|
|
66
|
+
| `'fold'` | case-INSENSITIVE, folded by the query | `LOWER(a) = LOWER(b)` | folds |
|
|
67
|
+
| `'collated'` | case-INSENSITIVE, folded by the COLUMN's collation | `a = b` | folds |
|
|
68
|
+
| `'exact'` | case-SENSITIVE | `a = b` | compares as-is |
|
|
69
|
+
|
|
70
|
+
`LOWER(col)` is not sargable, so `'fold'` costs every predicate over the column
|
|
71
|
+
its index — and on Postgres a column modelled as `text` may physically be a
|
|
72
|
+
`uuid`, where `LOWER()` does not exist at all. So set `textCasing: 'exact'` on
|
|
73
|
+
the engine for a schema of identifiers / codes / enums (`'collated'` when the
|
|
74
|
+
columns really do carry a case-insensitive collation, e.g. `citext`), and let
|
|
75
|
+
the individual columns that DO want folding say `casing: 'fold'` — a field's own
|
|
76
|
+
declaration always wins over the engine default. A Type may also be
|
|
63
77
|
flagged `semantic` / `search` to make it eligible for embedding similarity /
|
|
64
78
|
full-text search even when no individual field is flagged.
|
|
65
79
|
|
|
@@ -99,6 +113,7 @@ registry.registerType(order);
|
|
|
99
113
|
|
|
100
114
|
const engine = new QueryEngine(registry, {
|
|
101
115
|
executors: { user: arrayExecutor(userRows) }, // wire data for in-memory runs
|
|
116
|
+
textCasing: 'exact', // default case policy for text columns that declare none
|
|
102
117
|
});
|
|
103
118
|
```
|
|
104
119
|
|
|
@@ -362,6 +377,37 @@ Everything composes around that one call:
|
|
|
362
377
|
`exists` subquery or an `insert … select` source. An under-reported bound is
|
|
363
378
|
not a cosmetic gap — the SQL still emits `LIMIT ?` and a caller that binds the
|
|
364
379
|
declared signature leaves it NULL, which Postgres reads as *no limit*.
|
|
380
|
+
|
|
381
|
+
A param's type is the **meet** of every use — the most specific type
|
|
382
|
+
compatible with all of them, folded through `FieldType.meet`. Compared against
|
|
383
|
+
an `enum` in one place and plain `text` in another it is the **enum**;
|
|
384
|
+
`text{minLength:5}` beside `text{maxLength:10}` carries **both** bounds;
|
|
385
|
+
`number` beside `money` is `money`. The meet is commutative, associative,
|
|
386
|
+
idempotent and **sound** (it accepts nothing that both operands do not), so the
|
|
387
|
+
answer never depends on where in the JSON each use sits. Where the uses have no
|
|
388
|
+
meet the param is in **conflict** (`param.conflict`) and `params()` omits it.
|
|
389
|
+
|
|
390
|
+
It is the *greatest* lower bound for every type built from a **def** —
|
|
391
|
+
`x ⊓ ⊤ = x` holds for anything `parseType` / `parseFieldType` can produce. A
|
|
392
|
+
closed set IS the value schema, so a meet narrows a merged set by the merged
|
|
393
|
+
scalar constraints, and for a self-inconsistent type
|
|
394
|
+
(`text{values:['ab'], minLength:5}`, whose own bound rejects its own member)
|
|
395
|
+
even `x ⊓ text` narrows or conflicts. Since `0.6.6` that declaration is
|
|
396
|
+
**refused at parse time** (`field-type.bad-values`) rather than tolerated, so
|
|
397
|
+
the exception is gone from the def road. The public **constructors** do not
|
|
398
|
+
validate — `new TextFieldType({ values: [{ value: 'ab' }], minLength: 5 })` is
|
|
399
|
+
still buildable, and for one of those the meet is a lower bound only, exactly
|
|
400
|
+
as an uncompilable `pattern` is still constructible by hand. Soundness is kept
|
|
401
|
+
unconditionally on both roads, because it is the law a validator actually
|
|
402
|
+
depends on.
|
|
403
|
+
|
|
404
|
+
`engine.parameters(query)` → `ParamInfo[]` is the detailed view: per param,
|
|
405
|
+
every `use` (`{ at, type, category, field? }` — path, required type, category
|
|
406
|
+
summary, and the column the requirement came from), the merged `type`, and the
|
|
407
|
+
`conflict` when there is none. `engine.checkParams(query, params)` →
|
|
408
|
+
`Problems` checks SUPPLIED values against that merged type before execution
|
|
409
|
+
(`param.value` / `param.missing` / `param.unknown`); `null` always passes, and
|
|
410
|
+
the same check rides on `validateQuery(query, _, _, { params })`.
|
|
365
411
|
- **Filters.** `options.filters` is a `Record<source, ExprDef | Expr | null>` —
|
|
366
412
|
a single **boolean Expr** per source (or `null` / absent for none). The
|
|
367
413
|
`filters` EXPR in the query is only a placeholder (`{ source, fields? }`); the
|
|
@@ -806,9 +852,8 @@ constant `0`. See `examples/12-search-backing.ts`.
|
|
|
806
852
|
An `array` field is queried with the `array-op` predicate expression: `contains`
|
|
807
853
|
(a single element is present), `containsAny` / `containsAll` (overlap / superset
|
|
808
854
|
against an element list), and `isEmpty` / `notEmpty`. Element count is a
|
|
809
|
-
`comparison` over the builtin `arrayLength(field)` scalar function. (
|
|
810
|
-
|
|
811
|
-
case-insensitive, like text.)
|
|
855
|
+
`comparison` over the builtin `arrayLength(field)` scalar function. (Element matching follows the ELEMENT type's `casing`, else the engine's
|
|
856
|
+
`textCasing` default — the same rule a scalar text comparison uses.)
|
|
812
857
|
|
|
813
858
|
```ts
|
|
814
859
|
// containment — a single element is present:
|
|
@@ -974,6 +1019,51 @@ registry.functionList(); // every FunctionDef (default lib + your own
|
|
|
974
1019
|
describeFunctions(engine); // a promptable, by-shape listing for an LLM
|
|
975
1020
|
```
|
|
976
1021
|
|
|
1022
|
+
### Operators — `&&`, `<->`, `@>`
|
|
1023
|
+
|
|
1024
|
+
A function declaration cannot express an INFIX operator: `a && b` has no call
|
|
1025
|
+
form in any dialect, and `FunctionDef.sql` is a NAME, never a template.
|
|
1026
|
+
`registerOperator` is the other half — a declaration whose SQL is a per-dialect
|
|
1027
|
+
template, applied through the `operator` expr kind:
|
|
1028
|
+
|
|
1029
|
+
```ts
|
|
1030
|
+
registry.registerOperator({
|
|
1031
|
+
name: '&&', // SQL operator punctuation only
|
|
1032
|
+
operands: [{ name: 'left', type: { kind: 'json', as: 'Geometry' } },
|
|
1033
|
+
{ name: 'right', type: { kind: 'json', as: 'Geometry' } }],
|
|
1034
|
+
output: { kind: 'bool' }, // concrete, never 'inferred'
|
|
1035
|
+
instructions: 'Bounding-box overlap between two geometries. Cheap; a pre-filter for ST_Contains.',
|
|
1036
|
+
emit: { postgres: '({left} && {right})' }, // PARENTHESIZED; per Dialect.name
|
|
1037
|
+
selectivity: 0.1,
|
|
1038
|
+
});
|
|
1039
|
+
registry.registerOperatorRun('&&', (args) => Value.of(bboxOverlaps(args.left, args.right)));
|
|
1040
|
+
|
|
1041
|
+
// reference it by name with NAMED operands:
|
|
1042
|
+
// { kind: 'operator', op: '&&', args: { left: <expr>, right: <expr> } }
|
|
1043
|
+
```
|
|
1044
|
+
|
|
1045
|
+
```sql
|
|
1046
|
+
WHERE ("parcel"."shape" && ST_GeomFromGeoJSON($1))
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
The operand's **declared type reaches emission**, so a document operand binds
|
|
1050
|
+
through that type's own `cast` rather than the dialect's default json cast —
|
|
1051
|
+
without it Postgres refuses the statement (`operator does not exist: geometry &&
|
|
1052
|
+
jsonb`). A value position asserts only what its declaration WROTE: an operand's
|
|
1053
|
+
cast resolves from the operand's own `with` bag and never from the refinement's
|
|
1054
|
+
defaults, since those would pin a typmod the value never had to satisfy. A cast
|
|
1055
|
+
needing an option the operand did not write is refused at emit
|
|
1056
|
+
(`cast.unwritten-option`).
|
|
1057
|
+
|
|
1058
|
+
`registry.operatorList()` enumerates them; `describeOperators(engine)` renders
|
|
1059
|
+
the promptable block (and `describeEngine` includes it when any is registered).
|
|
1060
|
+
A dialect with no `emit` entry is **refused** at emit
|
|
1061
|
+
(`operator.unsupported-dialect`), never degraded to a neutral fragment; so is a
|
|
1062
|
+
missing `run` on the in-memory road (`operator.no-run`), because an operator is
|
|
1063
|
+
usually a predicate and NULL there means zero rows. Full rules — the name
|
|
1064
|
+
charset, the template checks, and what `OperatorDef` deliberately does not carry
|
|
1065
|
+
— are in `aeye-query.md`.
|
|
1066
|
+
|
|
977
1067
|
### Function reference
|
|
978
1068
|
|
|
979
1069
|
All builtin names are **camelCase** (no underscores). Where the emitted SQL
|
|
@@ -1169,6 +1259,7 @@ unusable construct. A kind appears only when it is applicable:
|
|
|
1169
1259
|
| joins | some Type has a relation field |
|
|
1170
1260
|
| `tabular-function-call` | ≥1 selected `tabular` function |
|
|
1171
1261
|
| `aggregate` / `window` / `function-call` | ≥1 selected function of that shape |
|
|
1262
|
+
| `operator` | ≥1 registered operator whose operand type some in-scope field could supply |
|
|
1172
1263
|
| `filters` | some Type has filterable fields |
|
|
1173
1264
|
|
|
1174
1265
|
The always-usable core (literal / param / binary / unary / comparison / logical
|