@aeye/query 0.6.0 → 0.6.2
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 +17 -0
- package/aeye-query.md +20 -18
- package/dist/index.d.ts +151 -26
- package/dist/index.js +622 -425
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -337,6 +337,16 @@ const result = await engine.run(query, { params, filters, includeTotal });
|
|
|
337
337
|
// result.total — pre-limit row count, when run with `includeTotal: true`
|
|
338
338
|
```
|
|
339
339
|
|
|
340
|
+
Each field's `type` is the full `ResolvedType`. A **computed** one carries
|
|
341
|
+
`aggregate` (does a group collapse happen anywhere in this expression?) and
|
|
342
|
+
`aggregateFn` — the APPLIED aggregate's name, present exactly when the value IS
|
|
343
|
+
one aggregate call. `sum(hours) as total_hours` reports `aggregateFn: 'sum'`
|
|
344
|
+
under any alias; `max(a) - min(b)` reports `aggregate: true` with NO
|
|
345
|
+
`aggregateFn` (it contains aggregates but is none); a window over an
|
|
346
|
+
aggregate-shaped function reports neither. Read it rather than inferring the
|
|
347
|
+
function from the output column NAME, which cannot see through an alias and
|
|
348
|
+
mistakes `hours * 2 as count` for an aggregate.
|
|
349
|
+
|
|
340
350
|
Everything composes around that one call:
|
|
341
351
|
|
|
342
352
|
- **Params.** A `param` (`{ kind: 'param', name }`) infers its type from how it
|
|
@@ -850,6 +860,13 @@ identifier; suffixed `_2`, `_3`, … on collision with a param the query already
|
|
|
850
860
|
uses). Failure cases (`drill.no-aggregation` / `non-invertible` /
|
|
851
861
|
`having-aggregate` / `window-unsupported`) return LLM-friendly `Problems`.
|
|
852
862
|
|
|
863
|
+
Each aggregate is replaced by its underlying row-level expression, and `count(*)`
|
|
864
|
+
— which has no single value — expands to the FROM type's fields MINUS the ones
|
|
865
|
+
the SELECT already projects itself. So `SELECT status, count(*) … GROUP BY status`
|
|
866
|
+
drills to `status` plus the remaining columns, with the group key projected ONCE.
|
|
867
|
+
The skip is keyed on the EXPRESSION (its canonical form), never on the output
|
|
868
|
+
name: two different expressions may legitimately share a name.
|
|
869
|
+
|
|
853
870
|
## Cost & estimation
|
|
854
871
|
|
|
855
872
|
Bottom-up estimates driven by each Type's cardinality (`count` rows, `bytes`
|
package/aeye-query.md
CHANGED
|
@@ -43,26 +43,25 @@ Every kind is one branch of the `ExprDef` union. Availability in the LLM schema
|
|
|
43
43
|
|
|
44
44
|
| kind | one-line meaning |
|
|
45
45
|
| ---- | ---------------- |
|
|
46
|
-
| `literal` | A constant scalar
|
|
46
|
+
| `literal` | A constant value: a scalar, or a whole JSON DOCUMENT (object / array) for a `json` / `array` field — bound as ONE parameter, never interpolated. |
|
|
47
47
|
| `param` | A named bind parameter; type inferred from use, bound at run/emit time. |
|
|
48
|
-
| `field-ref` | `<source>.<field>` — a field's value from a bound source. |
|
|
49
|
-
| `relation-path` | Walks relation fields from a source (optionally ending at a scalar); planner synthesizes the joins. |
|
|
48
|
+
| `field-ref` | `<source>.<field>` — a field's value from a bound source. A BELONGS-TO relation field projects that relation's IDENTITY off this row (no join); a HAS-MANY is refused (`ref.relation-has-many`). Read the target's OTHER fields through a `relation` join. |
|
|
50
49
|
| `binary` | Arithmetic `left <op> right` (`+ - * / %`). |
|
|
51
50
|
| `unary` | `<op> operand` (`-` / `+`). |
|
|
52
51
|
| `comparison` | `left <op> right` → boolean (`= <> < <= > >=`, `like`, `notLike`, `ilike`). A RELATION operand compares by identity in `=`/`<>` only: RHS a same-target relation (FK key) or a `{ pk }` value param; a has-many compares by membership (correlated `EXISTS`). |
|
|
53
52
|
| `logical` | Boolean connective `and` / `or` / `not` over operands. |
|
|
54
|
-
| `is-null` | `value IS [NOT] NULL`. |
|
|
53
|
+
| `is-null` | `value IS [NOT] NULL`. On a belongs-to relation it tests the KEY COLUMNS — i.e. whether the relation is UNSET — so it stays index-usable. |
|
|
55
54
|
| `between` | `value BETWEEN lower AND upper` (negatable). |
|
|
56
|
-
| `in` | `value IN (list \| subquery)` (negatable). A RELATION `value` matches list `{ pk }` values by FK key (belongs-to) or membership (has-many). |
|
|
55
|
+
| `in` | `value IN (list \| subquery)` (negatable). A RELATION `value` matches list `{ pk }` values by FK key (belongs-to) or membership (has-many); a COMPOSITE-key relation may not use the subquery form (`in.relation-composite`). |
|
|
57
56
|
| `case` | `CASE WHEN … THEN … [ELSE …] END`. |
|
|
58
57
|
| `function-call` | A scalar function call by name with named args. |
|
|
59
|
-
| `aggregate` | An aggregate function over a group (`count(*)` = empty args); optional `distinct`. |
|
|
58
|
+
| `aggregate` | An aggregate function over a group (`count(*)` = empty args); optional `distinct`. A relation field-ref is not aggregable (`ref.relation-aggregate`) — group by it instead. |
|
|
60
59
|
| `window` | A window (or windowed-aggregate) function over `partitionBy` / `orderBy`. |
|
|
61
60
|
| `subquery` | A scalar / single-field subquery in value position. |
|
|
62
61
|
| `exists` | `[NOT] EXISTS (subquery)` → boolean. |
|
|
63
62
|
| `array-op` | Predicate over an array field: `contains` / `containsAny` / `containsAll` / `isEmpty` / `notEmpty`. |
|
|
64
|
-
| `text-search` | Full-text predicate over a source (optionally one field) → boolean. |
|
|
65
|
-
| `text-score` | Numeric full-text relevance score of a source (optionally one field) → number (`ts_rank`). |
|
|
63
|
+
| `text-search` | Full-text predicate over a source (optionally one field) → boolean. Narrow it to a field unless the Type declares a search DOCUMENT — an unbacked whole-source search is refused (`text-search.unbacked`). |
|
|
64
|
+
| `text-score` | Numeric full-text relevance score of a source (optionally one field) → number (`ts_rank`). Same backing rule as `text-search` (`text-score.unbacked`). |
|
|
66
65
|
| `semantic` | Embedding-similarity score of a source's row vs a query (string / param / pairing ref) → number. |
|
|
67
66
|
| `filters` | An execution-time filter placeholder bound to a source (optional `fields` allowlist); predicate supplied at run time. |
|
|
68
67
|
| `excluded` | `EXCLUDED."field"` — the proposed row inside `INSERT … ON CONFLICT DO UPDATE`. |
|
|
@@ -80,7 +79,7 @@ Every kind is one branch of the `ExprDef` union. Availability in the LLM schema
|
|
|
80
79
|
Everything is referenced by its **Type name** — there is no alias to invent or keep in sync.
|
|
81
80
|
|
|
82
81
|
- **FROM** — `{ kind: 'type', type: 'user' }` binds under `source: 'user'` (not aliasable). Also available: `aliased` (escape hatch), `subquery`, and `function` (a tabular-function source).
|
|
83
|
-
- **Joins** — a `JoinDef` crosses a **single relation hop**: `on` is a `{ source, field }` ref (the bound source + its relation field). Joined rows bind under the target Type name; the join key is synthesized from the relation (you never write ON). Multi-hop = chained single-hop joins
|
|
82
|
+
- **Joins** — a `JoinDef` crosses a **single relation hop**: `on` is a `{ source, field }` ref (the bound source + its relation field). Joined rows bind under the target Type name; the join key is synthesized from the relation (you never write ON). Multi-hop = chained single-hop joins. `joinType` (`inner`/`left`/`right`/`full`, default `left`) is renamed from `type` to free that key. `and` adds an optional extra predicate.
|
|
84
83
|
- **DML** targets (`insert.into` / `update.type` / `delete.from`) bind under the Type name; DML targets take no alias.
|
|
85
84
|
- **`type` vs `source` rule.** `type` = a registered Type name (FROM `type`, DML targets, relation `to`, a `{ type, field }` semantic ref). `source` = a bound name in scope (Type name / join alias / CTE / aliased source) — used by `field-ref`, `semantic`/`text-search`/`text-score`/`filters`, and a join's `on.source`.
|
|
86
85
|
- **Disambiguation.** For a self-join or two instances of one Type, use `{ kind: 'aliased', type, as }` on FROM, or `as` on a join to override its hop's bound name. Two sources bound under one name → a `source.duplicate` validation error.
|
|
@@ -107,6 +106,8 @@ Types and fields declare **what write operations are possible**, and the model f
|
|
|
107
106
|
- **Field flags** — `insertable` / `updatable` on a `FieldDef` (default **true**). A field whose `FieldBacking.compute` is set defaults to `insertable:false, updatable:false` (override with an explicit flag). Validation rejects a listed non-insertable field (`insert.field-readonly`) / an assigned non-updatable field (`update.field-readonly`); the paired schema offers only insertable `fields` / updatable `set` fields.
|
|
108
107
|
- **Insert-requiredness (THE rule)** — a field is REQUIRED on insert iff it is **insertable AND non-nullable AND has no default AND is not computed**; otherwise optional (nullable / has-default) or excluded (non-insertable). One shared helper (`requiredOnInsert`) drives both the schema (required-vs-optional in paired mode) and validation (`insert.missing-required`, which lists the missing names).
|
|
109
108
|
- **Defaults** — `FieldBacking.default` is a `Value` or a factory `() => Value | Promise<Value>`. Its **presence alone** makes the field optional-on-insert (there is no `hasDefault` flag). At **runtime** an omitted defaulted field is materialized (the value is evaluated / the factory awaited, per row) into the inserted record. In **SQL** the column is simply left out of the INSERT and the database's own column `DEFAULT` fills it — so a JS-factory default is a runtime-only concern.
|
|
109
|
+
- **A write CELL carries a JSON value or an expression** — `WriteValueDef = JsonValue | ExprDef`. A raw SCALAR or a whole DOCUMENT (object / array, for a `json` / `array` column) becomes a literal; a `{ kind }` object is read as an EXPRESSION only when the kind names a REGISTERED expr kind, so a settings blob carrying a `kind` key stays data. An absent key OR a JSON `null` OMITS the field (its default fills in / it stays unset); `{ kind:"literal", value:null }` is the only way to set SQL NULL. A value written to a `json` / `array` column is JSON-ENCODED and bound as ONE parameter cast to the COLUMN's type (`Dialect.jsonValue`) — Postgres `CAST($1 AS jsonb)`, or `ARRAY[$1,$2]::text[]` for a native array column, which cannot take JSON text. The COLUMN decides, not the value's shape, so a JSON *scalar* into a `json` column (`"a bare string"`, `42`) is encoded and cast like any document rather than bound raw. SQL NULL is the exception: a null literal and an unbound param bind NULL, never the JSON value `null`. A param bound to a document is bound, never silently NULL.
|
|
110
|
+
- **A write value is checked against its COLUMN** — the cell's expr is walked in the target's scope, a `param` cell is OBSERVED against the column's field type (which is the only place a write param's type can come from), and a value of an incompatible category is refused (`write.type`). A RELATION column is exempt: what you write to it is the target's identity, not a value of the relation's own category.
|
|
110
111
|
- **Expr restrictions** — `FieldDef.exprs` is `{ not: ExprKind[] }` (exclude these kinds) or `{ only: ExprKind[] }` (allow exactly these). It can only NARROW what the field TYPE already permits. `field.allowsExpr(kind)` respects both the type floor and the restriction. Validation rejects a denied kind at the field's use site (`field.expr-denied`) — checked on a standalone `field-ref` (gated as `field-ref`), on each gating operator's DIRECT field-ref operand (gated as `comparison` / `between` / `in` / `is-null` / `array-op`), and on the field-naming exprs (`text-search` / `text-score` / `semantic` / `filters`). The paired schema omits an excluded field from the relevant enum and gates a kind away entirely when every candidate field excludes it.
|
|
111
112
|
|
|
112
113
|
## Semantic & text search + scoring / ranking
|
|
@@ -139,7 +140,7 @@ The flat `TypeDef` the LLM sees can be arbitrarily richer behind the scenes. A `
|
|
|
139
140
|
- **Default ordering** (`TypeBacking.defaultOrder`) — a Type's NATURAL sort, applied to a SELECT's `ORDER BY` when the query specifies none (and ordering is meaningful). `DefaultOrder` is `{ by: DefaultOrderTerm[]; applyTo? }`; each `DefaultOrderTerm` is `{ by: Computed; dir?; nulls? }` whose `by` is the sort KEY — the same dual `{ expr }` / `sql` / `run` `Computed` as computed fields, so one key emits to SQL AND sorts in memory identically (`dir` default `'asc'`; `nulls` else the direction-based default — asc ⇒ nulls first, desc ⇒ last — matching an explicit ORDER BY). It applies ONLY when the FROM binds the backed Type (joins never contribute their default order), the query has NO explicit `order`, and it is NOT aggregated (no `groupBy`, no bare aggregate) and NOT `DISTINCT` (both skipped — a base-field order is meaningless post-aggregation, and a non-selected DISTINCT key is illegal SQL). `applyTo` scopes WHICH selects receive it: `'result'` (default) ⇒ the ROOT query being run/emitted OR any `LIMIT`/`OFFSET` select; `'paginated'` ⇒ only a `LIMIT`/`OFFSET` select; `'all'` ⇒ every eligible select (incl. subqueries / CTEs). The ROOT is tracked by an `isRoot` marker threaded from `engine.run` / `engine.toSQL` onto the runtime / SQL context; nested queries (a subquery / EXISTS / IN subquery, a FROM subquery, a CTE body, a set-op branch) run/emit non-root. Example — newest-first: `defaultOrder: { by: [{ by: { expr: (a) => ref(a, 'createdAt') }, dir: 'desc' }] }` ⇒ an unsorted select over the Type gets `ORDER BY "t"."createdAt" DESC`. SELECT-only; DML is never reordered.
|
|
140
141
|
- **FLS** (`FieldBacking.access`) — a per-field gate emitting `CASE WHEN <pred> THEN <value> ELSE NULL END`; `false` ⇒ constant `NULL`.
|
|
141
142
|
- **Named joins & LATERAL** (`TypeBacking.joins`, opted into by `FieldBacking.joins: [name]`) — hidden joins added once per query only when a referencing field is emitted, deduped by name. A `JoinSpec` is a `relation` (reuses relation-join machinery) or a `lateral` (a correlated sub-select; Postgres `LEFT JOIN LATERAL (…) ON true`, base degrades to `ON 1 = 1` and evaluates per outer row; a `lateral.pick` names the default column).
|
|
142
|
-
- **Relation-join backing** (`FieldBacking.relation`, on a relation-typed field only) — drives a relation join's `ON` from explicit, LLM-HIDDEN physical foreign-key columns instead of the name convention (the JSON `FieldDef`/`TypeDef` are unchanged). `keys: [{ local, foreign? }]` are physical key-column pairs, ALL ANDed (composite FKs supported); `local` is the column on the side that DECLARES the relation, `foreign` the column on the TARGET (defaults to the target's identity). The backing lives on the OWNING **belongs-to** relation; a materialized inverse has-many REUSES the same FK (its forward relation's backing, orientation swapped). `on` is a fully custom, alias-correct predicate — `{ expr }` dual (SQL + runtime), with `sql` / `run` per-mode overrides; precedence like compute/access (`run`/`sql` override → `expr` → the `keys` mapping, else the convention). Every ON site (authored joins,
|
|
143
|
+
- **Relation-join backing** (`FieldBacking.relation`, on a relation-typed field only) — drives a relation join's `ON` from explicit, LLM-HIDDEN physical foreign-key columns instead of the name convention (the JSON `FieldDef`/`TypeDef` are unchanged). `keys: [{ local, foreign? }]` are physical key-column pairs, ALL ANDed (composite FKs supported); `local` is the column on the side that DECLARES the relation, `foreign` the column on the TARGET (defaults to the target's identity). The backing lives on the OWNING **belongs-to** relation; a materialized inverse has-many REUSES the same FK (its forward relation's backing, orientation swapped). `on` is a fully custom, alias-correct predicate — `{ expr }` dual (SQL + runtime), with `sql` / `run` per-mode overrides; precedence like compute/access (`run`/`sql` override → `expr` → the `keys` mapping, else the convention). Every ON site (authored joins, fan-out aggregate grouping, the `TypeBacking.joins` relation spec, joined UPDATE/DELETE) honors it and references the BOUND ALIASES, so aliased / self-joins work; `JoinDef.and` still ANDs onto whatever ON is produced. Example (the belongs-to owner): `fields: { user: { relation: { keys: [{ local: 'user_id', foreign: 'id' }] } } }` ⇒ `ON src.user_id = tgt.id` (and its inverse has-many `ON one.id = many.user_id`).
|
|
143
144
|
- **Search / semantic backing** — a `search`/`semantic`-flagged Type/field usually has a physical field hidden from the type system holding a precomputed `tsvector` / `pgvector`. `TypeBacking` and `FieldBacking` each take optional `search?: SearchBacking` / `semantic?: SemanticBacking` (field-level overrides type-level). Knobs (each factory takes the bound `alias` first): `vectorField` (the hidden physical field — a `SearchBacking.vectorField` emits `<alias>."f" @@ plainto_tsquery('<language>', $n)` without re-wrapping in `to_tsvector`; a `SemanticBacking.vectorField` is the left operand of the dialect's `similarity`, query vector bound as `$n::vector`), `language` (default `'english'`), `sql` (full override → boolean/numeric), `run` (runtime override), plus `SemanticBacking.vector` (row embedding source) and `embedder` (per-Type/field query embedder). Precedence (both modes): full `sql`/`run` override wins; else the hidden `vectorField`/`vector`; else the engine default. `toSQL` stays synchronous — the async embedder is never called there; a `vectorField`/`vector` query vector is a bound `$n::vector` param, and a `semantic(...)` TEXT-literal / text-param term is resolved to a pgvector-text literal from the caller's precomputed `embeddings` cache (see [SQL conversion](#sql-conversion): extract terms with `engine.semanticTexts`, embed, then `toSQL(query, dialect, { embeddings })`; a plain-text term with no/missing cache throws). The base dialect degrades (tsvector → `LIKE`, similarity → `0`) and never throws.
|
|
144
145
|
|
|
145
146
|
## Function library
|
|
@@ -168,14 +169,14 @@ Shapes: `scalar` `(args, ctx)→value`, `tabular` `(args, ctx)→rows`, `aggrega
|
|
|
168
169
|
|
|
169
170
|
| axis | levels (loose → tight) | constrains |
|
|
170
171
|
| ---- | ---------------------- | ---------- |
|
|
171
|
-
| `refs` | `open` · `types` · `fields` · `both` · `paired` | `field-ref` / `
|
|
172
|
+
| `refs` | `open` · `types` · `fields` · `both` · `paired` | every `{ source/type, field }` reference position — `field-ref`, a join's `on`, `semantic` / `text-search` / `text-score` / `filters` |
|
|
172
173
|
| `typeNames` | `open` · `enum` | bare Type-name positions (`from`, `into`, …) |
|
|
173
174
|
| `functions` | `open` · `names` · `typed` | function name + named-arg objects |
|
|
174
175
|
| `filters` | `open` · `paired` | the `filters` clause `(field, op)` pairs |
|
|
175
176
|
|
|
176
177
|
Pass a full/partial `SchemaDepth` object, or a preset string: `'open'` (every axis loose) / `'paired'` (every axis tight); the deprecated `strict: true`/`false` are sugar for those. A `FunctionSelector` (`{ scalar: [...], … }`) picks which functions appear; `maxEnumSize` auto-degrades any axis whose enumeration overflows the budget one level looser so a large catalog never yields an unusable schema.
|
|
177
178
|
|
|
178
|
-
**Capability gating** (independent of depth) omits any expr kind the available Types/functions can't use: `semantic` (some Type `isSemantic()`), `text-search`/`text-score` (`isSearchable()`), `array-op` (a Type has an array field), `
|
|
179
|
+
**Capability gating** (independent of depth) omits any expr kind the available Types/functions can't use: `semantic` (some Type `isSemantic()`), `text-search`/`text-score` (`isSearchable()`), `array-op` (a Type has an array field), `joins` (a Type has a relation), `tabular-function-call` (≥1 tabular fn), `aggregate`/`window`/`function-call` (≥1 fn of that shape), `filters` (a Type has filterable fields). The always-usable core (`literal`/`param`/`binary`/`unary`/`comparison`/`logical`/`in`/`between`/`is-null`/`exists`/`case`/`field-ref`/`subquery`) is never gated.
|
|
179
180
|
|
|
180
181
|
## Execution model
|
|
181
182
|
|
|
@@ -188,9 +189,10 @@ const result = await engine.run(query, { params, filters, includeTotal });
|
|
|
188
189
|
// result.total — pre-limit count, when run with includeTotal: true
|
|
189
190
|
```
|
|
190
191
|
|
|
192
|
+
- **An output field's `type`** is the full `ResolvedType`. A COMPUTED one carries `aggregate` (does a group collapse happen anywhere in this expression?) and `aggregateFn` — the APPLIED aggregate's name, present exactly when the value IS one aggregate call. `sum(hours) as total_hours` reports `aggregateFn: 'sum'` under any alias; `max(a) - min(b)` reports `aggregate: true` with NO `aggregateFn` (it contains aggregates but is none); a window over an aggregate-shaped function reports neither. Read it rather than inferring the function from the output column NAME, which cannot see through an alias and mistakes `hours * 2 as count` for an aggregate.
|
|
191
193
|
- **`includeTotal`** is an execution-time option (not a `SelectDef` field): `run` captures the pre-limit count; `toSQL(query, dialect, { includeTotal: true })` emits `COUNT(*) OVER () AS "$total"`.
|
|
192
194
|
- **`autoPaginate(query)`** adds `limit`/`offset` as bind params idempotently, so paging is just supplying values: `run(paged, { params: { limit, offset } })`.
|
|
193
|
-
- **Drill-down.** `drillDown(query, engine)` rebuilds the underlying-rows query behind an aggregate, parameterized (each GROUP BY key pinned to a bind param) — returns `{ query, params, warnings }`. `drillDownInto(query, groupRow, engine)` extracts one aggregated row's key values; then it is the same `run` call. Failures return LLM-friendly `Problems` (`drill.no-aggregation` / `non-invertible` / `having-aggregate` / `window-unsupported`).
|
|
195
|
+
- **Drill-down.** `drillDown(query, engine)` rebuilds the underlying-rows query behind an aggregate, parameterized (each GROUP BY key pinned to a bind param) — returns `{ query, params, warnings }`. `drillDownInto(query, groupRow, engine)` extracts one aggregated row's key values; then it is the same `run` call. Each aggregate becomes its row-level expression; `count(*)` expands to the FROM type's fields MINUS the ones the SELECT already projects (matched on the EXPRESSION, not the output name), so a group key is projected once. Failures return LLM-friendly `Problems` (`drill.no-aggregation` / `non-invertible` / `having-aggregate` / `window-unsupported`).
|
|
194
196
|
- **Standalone exprs.** `engine.evaluateExpr(expr, row?)` evaluates an `Expr`/`ExprDef` against a row; `engine.exprToSQL(expr, dialect)` emits `{ sql, params }` (params never interpolated).
|
|
195
197
|
|
|
196
198
|
### SQL conversion
|
|
@@ -260,7 +262,7 @@ Both the owned parser AND the wire schema draw their DIRECTED text from the SAME
|
|
|
260
262
|
|
|
261
263
|
**"Did you mean?" on EVERY unknown-name diagnostic.** A single reusable suggester — `didYouMean(input, candidates, { max? })` in `src/aids.ts` — appends "` — did you mean \`X\`?`" (or "`\`X\` or \`Y\`?`" up to `max`, default 1) whenever a bad NAME is a genuine typo of a valid one, and appends nothing otherwise. It is **typo-only**: a case-insensitive edit distance under a length-scaled budget (`suggestionBudget(len) = min(3, max(1, floor(len/3)))`, exposed alongside the lower-level `nearest(input, candidates, budget?)` primitive), so a short word tolerates one edit and a long one up to three — never a false match on an unrelated word. It powers, uniformly:
|
|
262
264
|
- **schema-enum** failures — a near-miss `op` / `dir` / `nulls` / function-name / Type-name / field-name value gets the canonical spelling appended to `expected <label>: <allowed>` (e.g. `"op": "notlike"` → "… like, notLike, ilike — did you mean `notLike`?"), and the union-no-match `kind` suggestion (`nearestKind` now just calls `nearest`);
|
|
263
|
-
- **validation** (`validateWalk`) unknown-name diagnostics — **field** (`ref` / `filters` / `
|
|
265
|
+
- **validation** (`validateWalk`) unknown-name diagnostics — **field** (`ref` / `filters` / `semantic` / `text-search` / `text-score` / `excluded` / `insert` / `update`, suggested from the resolved Type's field names), **source** (suggested from the bound source names in scope, via the new `QueryScope.sources()` accessor — every source bound anywhere up the chain), **Type** (`insert` / `update` / `delete` / `source` / relation-target, from the registry's Type names), **function** (`function-call` / `aggregate` / `window` / `tabular`, from the registry's function names of that shape), **named-arg** (from the function's declared param names), and **output** (`output` ref, from the SELECT's output field names). Candidates are gathered only when the error is emitted, so there is no hot-path cost.
|
|
264
266
|
|
|
265
267
|
**Tuning the report.** `buildQueryTool(engine, { report })` forwards a `FormatProblemsOptions` (`{ contextLines?, sectionHeaders?, lineNumbers?, maxProblems? }`) straight into `formatProblems`, so a caller can shape the diagnostics the model sees. Absent ⇒ the defaults (`contextLines: 2`, section headers + the `N │` line-number gutter on). E.g. `{ contextLines: 0 }` drops the surrounding context (just the underlined line), `{ contextLines: 4 }` widens it, `{ lineNumbers: false }` drops the gutter, and `{ maxProblems: 3 }` caps how many problems render.
|
|
266
268
|
|
|
@@ -276,13 +278,13 @@ Three DEFENSIVE dispatches — the zod-free parallels to `parseExpr` / `parseQue
|
|
|
276
278
|
|
|
277
279
|
The recursion is completed by four child-slot combinators alongside `exprRef`: **`queryRef`** (a parsed `Query` child — the set-operation arms, CTE bindings, subquery sources, `INSERT … SELECT`), **`queryDefRef`** (a subquery kept as a raw `QueryDef` — the value-position `subquery` / `exists` / `in`-subquery exprs re-parse it lazily, so it validates through `parseCheckedQuery` but returns the normalized `toJSON()` def), and **`sourceRef`** (a `QuerySource` child — a SELECT's `from`). The small building blocks are shared shapes in `queries/_shape.ts`: `selectFieldShape` (`{ expr, as? }`), `fieldValueShape` (`{ field, value }`), and `boundShape` (a limit/offset — a literal integer or a `{ kind:'param' }` def); `QueryOrder.SHAPE` and `QueryJoin.SHAPE` cover an ORDER BY term and a JOIN clause.
|
|
278
280
|
|
|
279
|
-
**The whole query tree now parses through the owned parser.** Expr kinds with a `static SHAPE`: the C1 exemplars (`comparison`, `field-ref`, `literal`, `param`, `logical`) + the C2 operators/predicates/functions/refs (`binary`, `unary`, `is-null`, `between`, `case`, `aggregate`, `window`, `function-call`, `
|
|
281
|
+
**The whole query tree now parses through the owned parser.** Expr kinds with a `static SHAPE`: the C1 exemplars (`comparison`, `field-ref`, `literal`, `param`, `logical`) + the C2 operators/predicates/functions/refs (`binary`, `unary`, `is-null`, `between`, `case`, `aggregate`, `window`, `function-call`, `array-op`, `output`, `excluded`, `text-search`, `text-score`) + the C3 finishers: `subquery`, `exists`, `in` (BOTH forms — its `SHAPE` dispatches on `in`: an array → the list form, an object → the subquery form via `queryDefRef`), `semantic` (whose `query` shape dispatches over the string / `param` / `{source,field}` / `{type,field}` forms), `tabular-function-call`, and `filters`. Query kinds with a `static SHAPE`: `select`, `insert` (incl. `onConflict`), `update`, `delete`, `union` / `intersect` / `except` (three `lit(kind)`-anchored shapes over the shared `SetOperationQuery`), `cte` (its entry shape structurally discriminates the plain vs recursive binding), and `expr`. Source kinds: `type`, `aliased`, `subquery`, `function`. Cross-field rules a plain `obj` can't express (e.g. `logical`'s `not`-arity, `in`'s list-vs-subquery dispatch, `cte`'s entry discrimination) live in a thin hand-written `Shape` wrapper around the base `obj`. An end-to-end test parses a complex SELECT (joins + where + groupBy + having + subquery + aggregate) to a `Query` `.toJSON()`-equal to the throwing `parseQuery`, and a SELECT malformed across several clauses surfaces every problem in ONE pass.
|
|
280
282
|
|
|
281
283
|
**This is the ACTIVE structural gate (C4 flipped).** `parseQueryInput` gates on `parseCheckedQuery` and feeds the sound result to `validateWalk`; the zod `safeParse` structural authority (and `problemsFromZod` / `flattenZodIssues`) has been retired. Zod remains ONLY the model-facing wire schema (`querySchema` / `buildSchemas`), unchanged. This is the intended structure-vs-semantics split: the owned parser accepts any registered kind + any string field, and unknown types / fields / functions are caught downstream by `validateWalk` with the existing aid-directed + `didYouMean` semantic messages.
|
|
282
284
|
|
|
283
285
|
### Compact tool-call schema (shared `$defs`)
|
|
284
286
|
|
|
285
|
-
The model-facing JSON-Schema (what `z.toJSONSchema` — and core's `compile()` — emit from `querySchema`) is **structurally factored**: the largest repeated fragments are built ONCE per schema-generation (a `SchemaCache` threaded on `SchemaOptions.cache`) and REUSED by identity everywhere they occur, so the converter emits each as a single `$def` + `$ref`s instead of inlining every copy. Factored fragments: each Type's **field-name enum** (`$def` `Fields_<Type>`, shared by field-ref /
|
|
287
|
+
The model-facing JSON-Schema (what `z.toJSONSchema` — and core's `compile()` — emit from `querySchema`) is **structurally factored**: the largest repeated fragments are built ONCE per schema-generation (a `SchemaCache` threaded on `SchemaOptions.cache`) and REUSED by identity everywhere they occur, so the converter emits each as a single `$def` + `$ref`s instead of inlining every copy. Factored fragments: each Type's **field-name enum** (`$def` `Fields_<Type>`, shared by field-ref / order / group-by / having / filters / text-search / semantic), the shared **`param`** expr, the reused **`Limit`** (number-or-param), and — the biggest win — the per-function **typed-args** blocks, keyed by argument SIGNATURE so the 100+ builtin functions (which collapse to a few dozen distinct signatures — dozens share a lone `value` arg) reuse one `$def` each. Names come from each shared fragment's `aid`, stamped as `meta.id` (`Fields_user`, `param`, `Limit`, `Args…`) so `z.toJSONSchema` factors AND names them; the ids are salted per schema-generation to stay unique in zod's process-global registry. This is a pure size/structure win — the schema accepts and rejects exactly the same queries with the same aid-directed diagnostics (a golden invariance test guards that), only smaller: on the bundled example fixture the minified `z.toJSONSchema` drops from **21.3 KB → 20.2 KB** (`open`) and **105.6 KB → 95.5 KB** (`paired`), the paired reduction concentrated in the field enums + typed-args (the ~100 genuinely-distinct per-function branches of `typed` mode are irreducible). A size-threshold test catches any regression that re-inlines the shared fragments.
|
|
286
288
|
|
|
287
289
|
## Self-describing the engine to a model
|
|
288
290
|
|
|
@@ -290,8 +292,8 @@ The `describe*` helpers render a compact, promptable capability summary (plain t
|
|
|
290
292
|
|
|
291
293
|
- **`describeEngine(engine, { types?, functions?, maxExamples?, instructions?, examples? })`** composes ONE block a model can read to know everything it may use: every (supplied) Type, then `describeExprs`, then `describeFunctions`, then `describeQueryExamples`, then `describeDialects`. `functions` narrows both the expr gating and the function listing to the schema's selection; `types` narrows the Type list + gating; `maxExamples` caps how many WORKED examples render PER function / node (default `DEFAULT_MAX_EXAMPLES` = 2; `0` omits examples). It no longer needs a separate example-text call — worked examples now live ON the nodes/functions (see below) and are folded in here.
|
|
292
294
|
- **Bring your own instructions / examples (use your OWN Types).** `instructions?: Record<string, string>` and `examples?: Record<string, readonly string[]>` (also `DescribeOverrides`, threaded through `describeExprs` / `describeFunctions` / `describeQueryExamples`) let a caller REPLACE the shipped `INSTRUCTIONS` / `EXAMPLES` for a given item — keyed by function NAME (`sum`, `count`, …) or node KIND (`window`, `in`, `select`, `union`, `cte`, …); names and kinds share ONE flat namespace (they are distinct strings). A key that is PRESENT swaps in the caller's string(s) — e.g. worked examples written against the caller's real domain Types instead of the generic shipped ones — while every key NOT present keeps the shipped default; overridden example lists are still capped by `maxExamples`, and an absent / empty override map renders byte-identically to today. Override strings are the CALLER's responsibility (rendered VERBATIM, not validated at render time): a caller can structurally pre-check their own example strings the same way the shipped-example test does — `JSON.parse` then a bare `createRegistry().parseCheckedQuery(...)` (full queries) / `parseCheckedExpr(...)` (expr fragments) and assert zero problems — before passing them in.
|
|
293
|
-
- **`describeExprs(engine, types?, functions?, maxExamples?)`** lists the CAPABILITY-GATED expression kinds — one `kind — INSTRUCTIONS` line per kind actually usable for the current Types/functions, filtered by the SAME gate the schema uses (`exprKindApplicable`), each followed by up to `maxExamples` `e.g. <json>` lines from the kind's `static EXAMPLES`. The always-usable core is never gated; `semantic` / `text-search` / `text-score` / `array-op` / `
|
|
295
|
+
- **`describeExprs(engine, types?, functions?, maxExamples?)`** lists the CAPABILITY-GATED expression kinds — one `kind — INSTRUCTIONS` line per kind actually usable for the current Types/functions, filtered by the SAME gate the schema uses (`exprKindApplicable`), each followed by up to `maxExamples` `e.g. <json>` lines from the kind's `static EXAMPLES`. The always-usable core is never gated; `semantic` / `text-search` / `text-score` / `array-op` / `tabular-function-call` appear only when an eligible Type/function exists (`excluded` / `output` are position-only and never listed).
|
|
294
296
|
- **`describeFunctions(engine, functions?, maxExamples?)`** renders each function as `name(a, b?): output — instructions` (named params, a trailing `?` marks optional), grouped by shape, each followed by up to `maxExamples` `e.g. <json>` lines from the function's `examples`.
|
|
295
297
|
- **`describeQueryExamples(engine, maxExamples?)`** renders a query-examples section: each registered query KIND that ships `static EXAMPLES` (SELECT, UNION/INTERSECT/EXCEPT, WITH/CTE) as `kind — INSTRUCTIONS` plus up to `maxExamples` worked example queries. Query-level constructs have no expr-catalog entry, so they get their own section.
|
|
296
298
|
- **Worked examples are a shipped, first-class surface.** Every `FunctionDef` may carry `examples?: readonly string[]` (RAW JSON strings — expr fragments or full queries that CALL it), and every Expr/Query node class may carry a `static readonly EXAMPLES?: readonly string[]` (plus, for query kinds, an optional `static INSTRUCTIONS`). Examples are TYPE-AGNOSTIC (illustrative generic source/field names like `event.score` / `user.name`) — they teach SHAPE while the catalog supplies the caller's real Type names. The shipped high-confusion set: the window family (`rank` / `denseRank` / `lag` / `lead` / `firstValue` / `lastValue` / `nthValue` / `cumeDist`), `dateTrunc` / `age` / `replace`, `count`; and the `window` / `exists` / `in` / `subquery` / `function-call` exprs and `select` / `union` / `cte` queries. This is the ONE source of truth — `describeEngine` only renders them. A structural test parses EVERY shipped example through a bare `createRegistry()`'s `parseCheckedQuery` / `parseCheckedExpr` and asserts zero problems.
|
|
297
|
-
- **Generated Type / Field docs.** `describeType` / `describeField` always emit a short `label` + long `description`: the developer's `TypeDef.label` / `FieldDef.description` when set, otherwise a sensible default GENERATED on demand from the meta-model — a Field from its FieldType (kind, bounds, `sensitive` / `semantic` / `search` flags, array item/bounds, a relation's `to` + `count` → belongs-to / has-many, nullability), a Type from its name + field/relation/index summary. Read the (possibly-generated) pair directly with `fieldMeta(field)` / `typeMeta(type)` (`{ label, description }`); nothing mutates the stored def — the strings are computed fresh per call.
|
|
299
|
+
- **Generated Type / Field docs.** `describeType` / `describeField` always emit a short `label` + long `description`: the developer's `TypeDef.label` / `FieldDef.description` when set, otherwise a sensible default GENERATED on demand from the meta-model — a Field from its FieldType (kind, bounds, `sensitive` / `semantic` / `search` flags, array item/bounds, a relation's `to` + `count` + its DIRECTION → belongs-to / has-many, read from `isBelongsTo()` rather than `count` so a materialized inverse is never described as a belongs-to, nullability), a Type from its name + field/relation/index summary. Read the (possibly-generated) pair directly with `fieldMeta(field)` / `typeMeta(type)` (`{ label, description }`); nothing mutates the stored def — the strings are computed fresh per call.
|
package/dist/index.d.ts
CHANGED
|
@@ -123,6 +123,11 @@ interface RelationFieldTypeDef {
|
|
|
123
123
|
* The relation field's NAME is the key for ALL purposes — there are no
|
|
124
124
|
* exposed foreign-key fields. `owns` (the FK living on THIS type) is
|
|
125
125
|
* INFERRED as `count === 1`; `count > 1` means the FK lives on the target.
|
|
126
|
+
* NOTE this holds for a DECLARED def only: the runtime discriminator is
|
|
127
|
+
* `RelationFieldType.isBelongsTo()` (`count === 1` AND no internal
|
|
128
|
+
* `inverseVia`), because a registry-materialized inverse is a has-many
|
|
129
|
+
* whatever its estimated `count` came out as. `inverseVia` is internal and
|
|
130
|
+
* never appears in this def.
|
|
126
131
|
*/
|
|
127
132
|
count: number;
|
|
128
133
|
/**
|
|
@@ -311,10 +316,19 @@ type UnaryOp = '-' | '+';
|
|
|
311
316
|
type ComparisonOp = '=' | '<>' | '<' | '<=' | '>' | '>=' | 'like' | 'notLike' | 'ilike';
|
|
312
317
|
/** Boolean connectives. `not` takes exactly one operand. */
|
|
313
318
|
type LogicalOp = 'and' | 'or' | 'not';
|
|
314
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* A literal constant VALUE — a scalar, or a whole JSON document (an object /
|
|
321
|
+
* array) for a `json` / `array` field.
|
|
322
|
+
*
|
|
323
|
+
* The non-scalar half exists because a WRITE CELL had no way to carry one: a
|
|
324
|
+
* `json` column could not be inserted or updated at all (a raw document was
|
|
325
|
+
* refused by the write parser, no expression could carry one, and the `param`
|
|
326
|
+
* route bound SQL `NULL` — see 0.6.1's A9). A non-scalar literal is bound as a
|
|
327
|
+
* single parameter through `Dialect.jsonValue`, never string-interpolated.
|
|
328
|
+
*/
|
|
315
329
|
interface LiteralExprDef {
|
|
316
330
|
kind: 'literal';
|
|
317
|
-
value:
|
|
331
|
+
value: JsonValue;
|
|
318
332
|
}
|
|
319
333
|
/**
|
|
320
334
|
* A direct field reference: `<source>.<field>`. Reuses `SourceFieldRef` — the
|
|
@@ -1280,6 +1294,26 @@ declare abstract class Dialect implements DialectEntry {
|
|
|
1280
1294
|
value: SqlText;
|
|
1281
1295
|
}[]): SqlText;
|
|
1282
1296
|
abstract sqlTypeFor(fieldType: FieldType): string;
|
|
1297
|
+
/**
|
|
1298
|
+
* Bind a whole JSON DOCUMENT (an object / array) as ONE parameter, cast to the
|
|
1299
|
+
* column type it is destined for. The single binding path for a non-scalar
|
|
1300
|
+
* VALUE — a `json` cell, an `array` cell, a document literal in a predicate.
|
|
1301
|
+
*
|
|
1302
|
+
* WHY A CAST, AND WHY THE FIELD TYPE. The document travels as its JSON TEXT in
|
|
1303
|
+
* a normal parameter slot (so `SqlValue` stays scalar and nothing is ever
|
|
1304
|
+
* string-interpolated), which means the server must be told what to parse it
|
|
1305
|
+
* AS. Left to inference, the same text is a `jsonb` in one column and a syntax
|
|
1306
|
+
* error in another. `fieldType` — supplied by the WRITE path, which knows the
|
|
1307
|
+
* column — makes that explicit; without it (a bare literal in a `where`, which
|
|
1308
|
+
* knows only its own shape) the dialect's own JSON type is the default.
|
|
1309
|
+
*
|
|
1310
|
+
* The base dialect casts to whatever `sqlTypeFor` names, which is the portable
|
|
1311
|
+
* answer for a JSON-typed column. A dialect with a NATIVE array type (Postgres
|
|
1312
|
+
* `text[]`) must override — an array literal there is not JSON text.
|
|
1313
|
+
*/
|
|
1314
|
+
jsonValue(value: JsonValue, fieldType?: FieldType): SqlText;
|
|
1315
|
+
/** This dialect's JSON column type — the default cast target for a document. */
|
|
1316
|
+
jsonSqlType(): string;
|
|
1283
1317
|
/**
|
|
1284
1318
|
* Length (element count) of array expression `arg`. Postgres `cardinality`;
|
|
1285
1319
|
* the base dialect degrades to `COALESCE(json_array_length(arg), 0)`.
|
|
@@ -1413,6 +1447,34 @@ interface ComputedResolved {
|
|
|
1413
1447
|
nullable: boolean;
|
|
1414
1448
|
/** Whether this computation is (or contains) an aggregate. */
|
|
1415
1449
|
aggregate: boolean;
|
|
1450
|
+
/**
|
|
1451
|
+
* The APPLIED aggregate function's name (`'sum'`, `'count'`, …) — present
|
|
1452
|
+
* exactly when this value IS one aggregate call, absent when it merely
|
|
1453
|
+
* CONTAINS one (`max(a) - min(b)` is `aggregate: true` with no single applied
|
|
1454
|
+
* function) and absent for every non-aggregate.
|
|
1455
|
+
*
|
|
1456
|
+
* It is a SIBLING of `aggregate` rather than a widening of it because the two
|
|
1457
|
+
* answer different questions: `aggregate` is a property of the whole SUBTREE
|
|
1458
|
+
* ("does a group collapse happen in here?", which drives placement validation
|
|
1459
|
+
* and grouping), while this is a property of ONE node. Folding them into
|
|
1460
|
+
* `false | string` would force a meaningless value for every composite.
|
|
1461
|
+
*
|
|
1462
|
+
* WHY IT EXISTS. Without it, a consumer labelling a computed column has to
|
|
1463
|
+
* recover the function from the column's OUTPUT NAME — `fieldNameOf` is
|
|
1464
|
+
* `as ?? (field-ref ? field : aggregate ? fn : col<i>)`, so an UNALIASED
|
|
1465
|
+
* aggregate's output name IS its function name — and then confirm that name
|
|
1466
|
+
* against the function catalog. That is evidence rather than fact, and it has
|
|
1467
|
+
* two dead spots: an ALIASED aggregate (`sum(hours) as total_hours`) cannot be
|
|
1468
|
+
* recovered at all, and a non-aggregate aliased onto a function name
|
|
1469
|
+
* (`hours * 2 as count`) is a false positive that only `aggregate` then
|
|
1470
|
+
* rejects. Reading this closes both.
|
|
1471
|
+
*
|
|
1472
|
+
* A WINDOW is deliberately excluded, even over an aggregate-shaped function
|
|
1473
|
+
* (`sum(x) OVER (…)`): it is per-row, collapses nothing, and already reports
|
|
1474
|
+
* `aggregate: false`. A scalar `function-call` does not set it either — this
|
|
1475
|
+
* names the aggregate that was APPLIED, not any function that was called.
|
|
1476
|
+
*/
|
|
1477
|
+
aggregateFn?: string;
|
|
1416
1478
|
}
|
|
1417
1479
|
/** The discriminated union of every expression / source resolution outcome. */
|
|
1418
1480
|
type ResolvedType = TypeResolved | FieldResolved | ComputedResolved;
|
|
@@ -2160,7 +2222,7 @@ declare class FieldRefExpr extends Expr {
|
|
|
2160
2222
|
readonly field: string;
|
|
2161
2223
|
static readonly KIND: "field-ref";
|
|
2162
2224
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
2163
|
-
static readonly INSTRUCTIONS: "`<source>.<field>` \u2014 a SCALAR field\u2019s value from a bound source. A ref to a RELATION field
|
|
2225
|
+
static readonly INSTRUCTIONS: "`<source>.<field>` \u2014 a SCALAR field\u2019s value from a bound source. A ref to a BELONGS-TO RELATION field IS a value: it projects the relation's IDENTITY \u2014 the target's key read off THIS row's own key column(s), as an object keyed by the target's identity field names (`{id:'u1'}`, `{tenantId:3,userId:1}`), NULL when unset \u2014 planning NO join and applying no target scope. Legal in `fields` / `RETURNING`, `order`, `groupBy`, `is null`, and an identity `=` / `<>` / `in`. To read any OTHER field of the target, cross the relation with a `relation` join (`joins:[{on:{kind:'relation',source,field,as}}]`) then field-ref the join alias. A HAS-MANY ref is REFUSED (`ref.relation-has-many`) \u2014 it has no key on this row and its value is a SET: join it, or test membership against a target key. A relation is still NOT a value as an arithmetic operand / `case` arm / function argument / aggregate; and to CORRELATE a subquery, join the relation and compare the joined key \u2014 never a relation field-ref against an id/scalar.";
|
|
2164
2226
|
readonly kind: "field-ref";
|
|
2165
2227
|
/** Wrap a `<source>.<field>` reference by its source alias and field name. */
|
|
2166
2228
|
constructor(source: string, field: string);
|
|
@@ -2401,15 +2463,15 @@ declare function bytesOfResolved(rt: ResolvedType): number;
|
|
|
2401
2463
|
*/
|
|
2402
2464
|
declare function reportCostProblems(cost: Cost, constraints: CostConstraints, p: Problems): void;
|
|
2403
2465
|
|
|
2404
|
-
/** A constant scalar
|
|
2466
|
+
/** A constant value: a scalar, or a whole JSON document (object / array). */
|
|
2405
2467
|
declare class LiteralExpr extends Expr {
|
|
2406
|
-
readonly value:
|
|
2468
|
+
readonly value: JsonValue;
|
|
2407
2469
|
static readonly KIND: "literal";
|
|
2408
2470
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
2409
|
-
static readonly INSTRUCTIONS: "A constant scalar
|
|
2471
|
+
static readonly INSTRUCTIONS: "A constant value: a scalar (string / number / boolean / null), or a whole JSON DOCUMENT (object / array) for a `json` / `array` field \u2014 which is how a write cell carries one. A document is bound as ONE parameter, never interpolated.";
|
|
2410
2472
|
readonly kind: "literal";
|
|
2411
|
-
/** Wrap a constant
|
|
2412
|
-
constructor(value:
|
|
2473
|
+
/** Wrap a constant value: a scalar, or a whole JSON document. */
|
|
2474
|
+
constructor(value: JsonValue);
|
|
2413
2475
|
/** Reconstruct a LiteralExpr from its JSON def (validates the `kind` discriminant). */
|
|
2414
2476
|
static from(json: ExprDef, _registry: Registry): LiteralExpr;
|
|
2415
2477
|
/**
|
|
@@ -2430,8 +2492,17 @@ declare class LiteralExpr extends Expr {
|
|
|
2430
2492
|
cost(ctx: CostContext, scope: QueryScope): Cost;
|
|
2431
2493
|
/** Evaluate to the wrapped constant value. */
|
|
2432
2494
|
evaluate(): Promise<Value>;
|
|
2433
|
-
/**
|
|
2434
|
-
|
|
2495
|
+
/**
|
|
2496
|
+
* Emit as a SqlText fragment — `NULL` keyword, a bound scalar param, or a
|
|
2497
|
+
* bound DOCUMENT.
|
|
2498
|
+
*
|
|
2499
|
+
* A document has no target field type HERE (a bare literal in a WHERE knows
|
|
2500
|
+
* only its own shape), so it binds through the dialect's default json type.
|
|
2501
|
+
* The WRITE path emits its cells through `writeCellSql`, which supplies the
|
|
2502
|
+
* target COLUMN's field type — the difference between a Postgres `jsonb` cast
|
|
2503
|
+
* and the `ARRAY[…]::text[]` a native array column actually needs.
|
|
2504
|
+
*/
|
|
2505
|
+
toSQL(dialect: Dialect, _ctx: SqlContext): SqlText;
|
|
2435
2506
|
/** Serialize back to its JSON ExprDef. */
|
|
2436
2507
|
toJSON(): LiteralExprDef;
|
|
2437
2508
|
/** Deep-copy this expr. */
|
|
@@ -2691,8 +2762,23 @@ declare class ParamExpr extends Expr {
|
|
|
2691
2762
|
cost(ctx: CostContext, scope: QueryScope): Cost;
|
|
2692
2763
|
/** Evaluate to the runtime-bound value for this param name. */
|
|
2693
2764
|
evaluate(ctx: RuntimeContext): Promise<Value>;
|
|
2694
|
-
/**
|
|
2695
|
-
|
|
2765
|
+
/**
|
|
2766
|
+
* Emit as a bound SqlText param slot (NULL until a value is supplied).
|
|
2767
|
+
*
|
|
2768
|
+
* A NON-SCALAR bound value — a JSON document, or a relation `{ pk }` object
|
|
2769
|
+
* that reached here undecomposed — binds through `Dialect.jsonValue`, NOT as
|
|
2770
|
+
* NULL. Binding NULL was the worst outcome available (A9): the statement
|
|
2771
|
+
* SUCCEEDED and the supplied value was silently dropped, so an INSERT of a
|
|
2772
|
+
* `json` column through a param appeared to work and lost the data. A
|
|
2773
|
+
* relation comparison still decomposes its `{ pk }` object into per-column
|
|
2774
|
+
* binds before reaching here, so that path is unchanged; anything that DOES
|
|
2775
|
+
* get here is a value the caller supplied, and is bound as one.
|
|
2776
|
+
*
|
|
2777
|
+
* A write CELL routes through `writeCellSql` first, which also knows the
|
|
2778
|
+
* target column's field type; this is the fallback for every other position,
|
|
2779
|
+
* which knows only the value's own shape.
|
|
2780
|
+
*/
|
|
2781
|
+
toSQL(dialect: Dialect, ctx: SqlContext): SqlText;
|
|
2696
2782
|
/** Serialize back to its JSON ExprDef. */
|
|
2697
2783
|
toJSON(): ParamExprDef;
|
|
2698
2784
|
/** Deep-copy this expr. */
|
|
@@ -2932,7 +3018,7 @@ declare class InExpr extends BoolExpr {
|
|
|
2932
3018
|
readonly not: boolean;
|
|
2933
3019
|
static readonly KIND: "in";
|
|
2934
3020
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
2935
|
-
static readonly INSTRUCTIONS: "`value IN (list | subquery)` (negatable via `not`): membership test. `in` is EITHER an explicit array of value exprs OR a subquery projecting exactly ONE field (correlated or not). When `value` is a RELATION field-ref, the list holds `{ pk }` VALUE params (or bare scalars for a single-key relation): a belongs-to matches by FK key, a has-many by MEMBERSHIP (\u2208 the related set); `NOT IN` negates.
|
|
3021
|
+
static readonly INSTRUCTIONS: "`value IN (list | subquery)` (negatable via `not`): membership test. `in` is EITHER an explicit array of value exprs OR a subquery projecting exactly ONE field (correlated or not). When `value` is a RELATION field-ref, the list holds `{ pk }` VALUE params (or bare scalars for a single-key relation): a belongs-to matches by FK key, a has-many by MEMBERSHIP (\u2208 the related set); `NOT IN` negates. A COMPOSITE-key relation may NOT use the subquery form (`in.relation-composite`) \u2014 one projected field cannot match a multi-column key, so list its `{ pk }` values instead. Inside the SUBQUERY, cross a relation with a `relation` join and field-ref the joined alias: projecting the relation field-ref itself yields its IDENTITY OBJECT, not a scalar id, and is refused here (`compare.relation-vs-value`). To correlate the subquery, JOIN the relation and compare the joined key to the outer scalar. Set `not:true` for NOT IN.";
|
|
2936
3022
|
/**
|
|
2937
3023
|
* Worked examples (see `ExprClass.EXAMPLES`) — the two `in` shapes: an explicit
|
|
2938
3024
|
* value LIST, and a single-field SUBQUERY that crosses a relation via a
|
|
@@ -3032,7 +3118,7 @@ declare class IsNullExpr extends BoolExpr {
|
|
|
3032
3118
|
readonly not: boolean;
|
|
3033
3119
|
static readonly KIND: "is-null";
|
|
3034
3120
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
3035
|
-
static readonly INSTRUCTIONS: "`value IS [NOT] NULL`.";
|
|
3121
|
+
static readonly INSTRUCTIONS: "`value IS [NOT] NULL`. On a BELONGS-TO relation field-ref it tests whether the relation is UNSET \u2014 the KEY COLUMNS, so it stays index-usable; a HAS-MANY there is refused (`ref.relation-has-many`) \u2014 use `[NOT] EXISTS` over the related rows instead.";
|
|
3036
3122
|
readonly kind: "is-null";
|
|
3037
3123
|
/** Wrap `value IS [NOT] NULL` as a null test. */
|
|
3038
3124
|
constructor(value: Expr, not: boolean);
|
|
@@ -3249,7 +3335,7 @@ declare class AggregateExpr extends Expr {
|
|
|
3249
3335
|
readonly distinct: boolean;
|
|
3250
3336
|
static readonly KIND: "aggregate";
|
|
3251
3337
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
3252
|
-
static readonly INSTRUCTIONS: "An aggregate function over a group (`count(*)` = empty args); optional `distinct`.";
|
|
3338
|
+
static readonly INSTRUCTIONS: "An aggregate function over a group (`count(*)` = empty args); optional `distinct`. A RELATION field-ref is NOT aggregable (`ref.relation-aggregate`) \u2014 its value is an IDENTITY: group by it, or aggregate a scalar off a `relation`-joined alias.";
|
|
3253
3339
|
readonly kind: "aggregate";
|
|
3254
3340
|
/** Wrap a registered aggregate `fn` with its named `args` and a DISTINCT flag. */
|
|
3255
3341
|
constructor(fn: string,
|
|
@@ -3282,7 +3368,17 @@ declare class AggregateExpr extends Expr {
|
|
|
3282
3368
|
static toSchema(opts: SchemaOptions): z.ZodTypeAny;
|
|
3283
3369
|
protected aggregateHere(): boolean;
|
|
3284
3370
|
forEachChild(visit: (child: Expr) => void): void;
|
|
3285
|
-
/**
|
|
3371
|
+
/**
|
|
3372
|
+
* Resolve to the function's declared output type, marked aggregate and nullable
|
|
3373
|
+
* (except `count`), and carrying the APPLIED function's name.
|
|
3374
|
+
*
|
|
3375
|
+
* `aggregateFn` is set on BOTH roads — including the unknown-function fallback,
|
|
3376
|
+
* where the name is still the fact of what was written even though the
|
|
3377
|
+
* resolution is a placeholder. This is the ONE node that can answer "which
|
|
3378
|
+
* aggregate is this?": every wrapping expr reports `aggregate: true` from its
|
|
3379
|
+
* children without a single applied function, and `Function.resolveOutput`
|
|
3380
|
+
* never sets it, so nothing propagates a stale name upward.
|
|
3381
|
+
*/
|
|
3286
3382
|
resolve(engine: QueryEngine, scope: QueryScope): ResolvedType;
|
|
3287
3383
|
/** Validate aggregate placement (not in WHERE, not nested) and the function's own named-arg checks. */
|
|
3288
3384
|
validateWalk(engine: QueryEngine, scope: QueryScope, p: Problems, ctx: ValidateContext): ResolvedType;
|
|
@@ -3692,7 +3788,7 @@ declare class TextSearchExpr extends BoolExpr {
|
|
|
3692
3788
|
readonly query: TextSearchQuery;
|
|
3693
3789
|
static readonly KIND: "text-search";
|
|
3694
3790
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
3695
|
-
static readonly INSTRUCTIONS: "Full-text predicate over a source (optionally one field) \u2192 boolean.";
|
|
3791
|
+
static readonly INSTRUCTIONS: "Full-text predicate over a source (optionally one field) \u2192 boolean. NARROW it to a text `field` unless the Type declares a searchable whole-record DOCUMENT: an unbacked whole-source search is REFUSED (`text-search.unbacked`) rather than guessing a column.";
|
|
3696
3792
|
readonly kind: "text-search";
|
|
3697
3793
|
/** Wrap the bound `source` (optional `field`) and the search query text. */
|
|
3698
3794
|
constructor(source: string, field: string | undefined, query: TextSearchQuery);
|
|
@@ -3748,7 +3844,7 @@ declare class TextScoreExpr extends Expr {
|
|
|
3748
3844
|
readonly query: TextSearchQuery;
|
|
3749
3845
|
static readonly KIND: "text-score";
|
|
3750
3846
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
3751
|
-
static readonly INSTRUCTIONS: "Numeric full-text relevance score of a source (optionally one field) \u2192 number (`ts_rank`).";
|
|
3847
|
+
static readonly INSTRUCTIONS: "Numeric full-text relevance score of a source (optionally one field) \u2192 number (`ts_rank`). NARROW it to a text `field` unless the Type declares a searchable whole-record DOCUMENT: an unbacked whole-source score is REFUSED (`text-score.unbacked`) rather than guessing a column.";
|
|
3752
3848
|
readonly kind: "text-score";
|
|
3753
3849
|
/** Wrap the bound `source` (optional `field`) and the query text to rank against. */
|
|
3754
3850
|
constructor(source: string, field: string | undefined, query: TextSearchQuery);
|
|
@@ -4313,12 +4409,19 @@ declare class JoinCtePlanner {
|
|
|
4313
4409
|
/** A value that may be bound as a SQL parameter. */
|
|
4314
4410
|
type SqlValue = string | number | boolean | null;
|
|
4315
4411
|
/**
|
|
4316
|
-
* A supplied param value:
|
|
4317
|
-
*
|
|
4318
|
-
*
|
|
4319
|
-
*
|
|
4412
|
+
* A supplied param value:
|
|
4413
|
+
* - a bindable SCALAR, bound directly;
|
|
4414
|
+
* - a RELATION KEY object (`{ pk }`, keyed by the target's PK field names) on
|
|
4415
|
+
* the RHS of a relation comparison (`assignedUser = { id: 5 }`), which the
|
|
4416
|
+
* comparison decomposes into per-column binds;
|
|
4417
|
+
* - or a whole JSON DOCUMENT for a `json` / `array` cell, bound as ONE
|
|
4418
|
+
* parameter through `Dialect.jsonValue` (0.6.1's A9 — such a value used to
|
|
4419
|
+
* bind SQL `NULL`, so the write succeeded and the data was dropped).
|
|
4420
|
+
*
|
|
4421
|
+
* `JsonValue` subsumes the relation-key object; the three cases are spelled out
|
|
4422
|
+
* because they are read very differently at the point of use.
|
|
4320
4423
|
*/
|
|
4321
|
-
type SqlParamValue =
|
|
4424
|
+
type SqlParamValue = JsonValue;
|
|
4322
4425
|
/** A rendered SQL string plus its ordered bind parameters. */
|
|
4323
4426
|
interface RenderedSql {
|
|
4324
4427
|
/** The flat SQL string with dialect-numbered placeholders. */
|
|
@@ -9347,6 +9450,27 @@ declare class PostgresDialect extends BaseDialect {
|
|
|
9347
9450
|
key: string;
|
|
9348
9451
|
value: SqlText;
|
|
9349
9452
|
}[]): SqlText;
|
|
9453
|
+
/** Postgres stores JSON as `jsonb` (it has the equality / ordering operators `json` lacks). */
|
|
9454
|
+
jsonSqlType(): string;
|
|
9455
|
+
/**
|
|
9456
|
+
* Bind a JSON DOCUMENT — with the one Postgres wrinkle that makes the base
|
|
9457
|
+
* implementation wrong here: a NATIVE array column (`text[]`, `integer[]`, …)
|
|
9458
|
+
* does NOT accept JSON text. `CAST('["a","b"]' AS text[])` is a syntax error,
|
|
9459
|
+
* because a Postgres array literal is `{a,b}`.
|
|
9460
|
+
*
|
|
9461
|
+
* So a document destined for a native array is CONSTRUCTED instead —
|
|
9462
|
+
* `ARRAY[$1, $2]::text[]` — with each element bound in its own slot. That
|
|
9463
|
+
* reuses the element-binding pattern the array containment operators already
|
|
9464
|
+
* use, needs no array-literal encoder (whose quoting / escaping / NULL rules
|
|
9465
|
+
* would be their own defect surface), and handles the empty array
|
|
9466
|
+
* (`ARRAY[]::text[]`, which Postgres accepts precisely because the cast names
|
|
9467
|
+
* the type). Elements recurse, so a `jsonb[]` column takes documents.
|
|
9468
|
+
*
|
|
9469
|
+
* Everything else — a `json` / `jsonb` column, a heterogeneous array (which
|
|
9470
|
+
* `sqlTypeFor` already stores as `jsonb`), or a bare document with no declared
|
|
9471
|
+
* target — casts the JSON text to `jsonb`.
|
|
9472
|
+
*/
|
|
9473
|
+
jsonValue(value: JsonValue, fieldType?: FieldType): SqlText;
|
|
9350
9474
|
/** Cast the query param to the pgvector type so `similarity` type-checks (`<param>::vector`). */
|
|
9351
9475
|
queryVectorParam(param: SqlText): SqlText;
|
|
9352
9476
|
/**
|
|
@@ -9488,7 +9612,8 @@ declare function autoPaginate(select: SelectQuery | SelectDef, opts?: AutoPagina
|
|
|
9488
9612
|
* AGGREGATED query's OUTPUT field that carries that key's value per row.
|
|
9489
9613
|
* No `groupRow`, no literals.
|
|
9490
9614
|
* 3. Replace each aggregate SELECT item with its underlying non-aggregated
|
|
9491
|
-
* expr: `sum(o.total)` → `o.total`, `count(*)` →
|
|
9615
|
+
* expr: `sum(o.total)` → `o.total`, `count(*)` → every FROM field the SELECT
|
|
9616
|
+
* does not already project itself (so a group key is not duplicated). An
|
|
9492
9617
|
* aggregate over a non-field argument (a literal / param) is
|
|
9493
9618
|
* `drill.non-invertible` (names the offending alias).
|
|
9494
9619
|
* 4. Drop GROUP BY / HAVING. A HAVING clause that references group keys (no
|
|
@@ -9875,7 +10000,7 @@ declare function describeEngine(engine: QueryEngine | Registry, options?: Descri
|
|
|
9875
10000
|
* so every Type / Field surfaces a human- / LLM-facing doc even when the dev
|
|
9876
10001
|
* authored none. Values are derived from what the meta-model already knows — a
|
|
9877
10002
|
* Field from its `FieldType` (kind, bounds, `sensitive` / `semantic` / `search`
|
|
9878
|
-
* flags, array item / bounds, a relation's `to` + `count`, nullability) and a
|
|
10003
|
+
* flags, array item / bounds, a relation's `to` + DIRECTION + `count`, nullability) and a
|
|
9879
10004
|
* Type from its name plus a field / relation / index summary.
|
|
9880
10005
|
*
|
|
9881
10006
|
* NOTHING here mutates the stored `TypeDef` / `FieldDef`: each string is
|
|
@@ -10026,4 +10151,4 @@ declare function parseQueryTool(engine: QueryEngine, raw: unknown, options?: Bui
|
|
|
10026
10151
|
*/
|
|
10027
10152
|
declare function buildQueryTool(engine: QueryEngine, options?: BuildQueryToolOptions): Tool<{}, {}, string, QueryToolInput, Promise<QueryResult>, [], Query>;
|
|
10028
10153
|
|
|
10029
|
-
export { AID_REGISTRY, type Access, type AccessRun, type AccessSql, AggregateExpr, type AggregateExprDef, type AggregateRun, type AidInfo, type AidOptions, type AliasedSourceDef, type ArgExprDef, ArrayFieldType, type ArrayFieldTypeDef, type ArrayOp, ArrayOpExpr, type ArrayOpExprDef, type AutoPaginateOptions, BUILTIN_EXPRS, BUILTIN_FIELD_TYPES, BUILTIN_LIBRARY, BUILTIN_QUERIES, Backing, BaseDialect, BetweenExpr, type BetweenExprDef, BinaryExpr, type BinaryExprDef, type BinaryOp, BoolExpr, BoolFieldType, type BoolFieldTypeDef, type BuildQueryToolOptions, type BuildSchemasOptions, type BuiltinFunction, type CTEDef, type CTERecursiveDef, type CTEStatementDef, CTEStatementQuery, type CaseBranchDef, type CaseBranchSpec, CaseExpr, type CaseExprDef, Code, type CodeLine, type CodeOptions, ComparisonExpr, type ComparisonExprDef, type ComparisonOp, type ComputeRun, type ComputeSql, type Computed, type ComputedResolved, type Cost, type CostConstraints, DEFAULT_MAX_CTE_ITERATIONS, DEFAULT_MAX_EXAMPLES, DEFAULT_MAX_QUERY_SCHEMA_TYPES, DateFieldType, type DateFieldTypeDef, type DefaultCondition, type DefaultConditionOp, type DefaultOrder, type DefaultOrderDir, type DefaultOrderScope, type DefaultOrderTerm, type DeleteDef, DeleteQuery, type DescribeEngineOptions, type DescribeOverrides, Dialect, type DialectEntry, type DrillDownFailure, type DrillDownIntoSuccess, type DrillDownResult, type DrillDownSuccess, type DrillParam, EQ_SELECTIVITY, type Embedder, ExcludedExpr, type ExcludedExprDef, type ExecutorContext, ExistsExpr, type ExistsExprDef, Expr, type ExprClass, type ExprClassEntry, type ExprDef, type ExprKind, ExprQuery, type ExprQueryDef, Field, type FieldBacking, type FieldDef, type FieldExprRestriction, FieldRefExpr, type FieldRefExprDef, type FieldResolved, type FieldSpec, FieldType, type FieldTypeClass, type FieldTypeDef, type FieldTypeKind, type FieldValueDef, type FilterDepth, FiltersExpr, type FiltersExprDef, type FnDepth, type FormatOptions, type FormatProblemsOptions, FunctionCallExpr, type FunctionCallExprDef, type FunctionDef, type FunctionParamDef, type FunctionRun, type FunctionSelector, type FunctionShape, type FunctionSourceDef, IN_SELECTIVITY, InExpr, type InExprDef, Index, type IndexDef, IndexPart, type IndexPartDef, type InferOptions, type InsertDef, InsertQuery, type InsertRowDef, IsNullExpr, type IsNullExprDef, type JSONEntry, type JoinBacking, JoinCtePlanner, type JoinDef, type JoinHop, type JoinOnDef, type JoinRequest, type JoinRunPlan, type JoinSpec, type JoinSqlPlan, type JoinType, JsonFieldType, type JsonFieldTypeDef, type JsonValue, type LateralJoinSpec, LiteralExpr, type LiteralExprDef, LogicalExpr, type LogicalExprDef, type LogicalOp, type MaybePromise, type Meta, MoneyFieldType, type MoneyFieldTypeDef, type MoneyOptions, type NameDepth, type NamedArgs, type Node, NumberFieldType, type NumberFieldTypeDef, type NumberOptions, type OnConflictDef, type OrderDef, type OrderEntry, OutputRefExpr, type OutputRefExprDef, type ParamDef, ParamExpr, type ParamExprDef, ParamSet, PostgresDialect, type Problem, Problems, Query, type QueryClass, type QueryClassEntry, type QueryDef, QueryEngine, type QueryEngineOptions, type QueryField, QueryFunction, QueryJoin, type QueryKind, QueryOrder, type QueryResult, type QueryResultArray, type QuerySchemaOptions, type QuerySchemas, QueryScope, QuerySource, QueryToolError, type QueryToolInput, QueryTypeError, type QueryValidator, RANGE_SELECTIVITY, ROOT_VALIDATE_CONTEXT, type RefDepth, Registry, type RelationBacking, RelationFieldType, type RelationFieldTypeDef, type RelationJoinOnDef, type RelationJoinSpec, type RelationKey, type RelationKeyPair, type RelationOn, type RelationOnPair, type RelationResolved, type RenderedSql, type ResolvedSchemaDepth, type ResolvedType, type RlsProvider, RuntimeContext, type RuntimeJoin, type RuntimeOptions, SEMANTIC_ROW_PENALTY, type ScalarKind, type ScalarRun, type ScalarValue, type SchemaDepth, type SchemaOptions, type SearchBacking, type SelectDef, type SelectFieldDef, SelectQuery, type SelectTypesOptions, type SelectedFunctions, type SemanticBacking, type SemanticEmbeddings, SemanticExpr, type SemanticExprDef, type SemanticQueryDef, type SemanticTextToVector, type SetDef, type SetOperationDef, SetOperationQuery, type SortEntryDef, type SortSelectionDef, type SorterDef, SorterExpr, type SourceDef, type SourceFieldOptionalRef, type SourceFieldRef, type SourceFieldsRef, type SourceRecord, type SourceRow, type Span, type SpanMeta, SqlContext, SqlText, type SqlValue, SubqueryExpr, type SubqueryExprDef, type SubquerySourceDef, TEXT_SEARCH_ROW_PENALTY, TabularFunctionCallExpr, type TabularFunctionCallExprDef, type TabularRun, TextFieldType, type TextFieldTypeDef, type TextOptions, TextScoreExpr, type TextScoreExprDef, TextSearchExpr, type TextSearchExprDef, TimestampFieldType, type TimestampFieldTypeDef, type TimezonePolicy, type ToSqlOptions, Type, type TypeBacking, type TypeDef, type TypeExecutor, type TypeFieldRef, type TypeResolved, type TypeSourceDef, type TypeSpec, type TypeState, UnaryExpr, type UnaryExprDef, type UnaryOp, type UpdateDef, UpdateQuery, type ValidateContext, Value, type ValueCategory, type ValueSchemaOptions, WINDOW_ORDER_ARG, WindowExpr, type WindowExprDef, type WindowOrderSpec, type WindowRun, type WriteValueDef, ZERO_COST, add, addCost, age, agg, aidInfo, aliasedDigest, and, arrayAgg, arrayAppend, arrayConcat, arrayContains, arrayDistinct, arrayExecutor, arrayIndexOf, arrayPrepend, arrayRemove, arraySlice, arrayToString, asFieldType, autoPaginate, avg, between, boolAnd, boolOr, buildQueryTool, buildSchemas, builtinDialects, bytesOfResolved, canonicalize, caseExpr, cloneRecord, code, concat, contains, containsAll, containsAny, count, countIf, countStar, createRegistry, currentTime, currentTimestamp, dateAdd, dateDiff, dateFormat, datePart, dateTrunc, day, dayOfWeek, dayOfYear, defaultConditionOps, defaultConditionWithout, depthInstructions, describeDialects, describeEngine, describeExprs, describeFunctions, describeInput, describeQueryExamples, describeType, describeTypes, didYouMean, directedMessage, div, drillDown, drillDownInto, e, editDistance, embeddingResolver, epoch, eq, excluded, exists, exprDefSchema, exprDigest, fieldMeta, fieldNameOf, fieldTypeDefSchema, filters, firstField, fn, fromEpoch, generatedFieldDescription, generatedFieldLabel, generatedTypeDescription, generatedTypeLabel, gt, gte, hour, humanize, ilike, inList, inSubquery, inferType, isEmpty, isNull, isScalar, isScalarValue, isType, isVectorText, join, joinAlias, joinCode, joinLines, jsonValueSchema, like, lit, lt, lte, makeDate, makeField, makeResult, max, maxCost, mergeRows, min, minute, mod, month, mul, nearest, nearestKind, neg, neq, not, notBetween, notEmpty, notExists, notInList, notInSubquery, notLike, notNull, or, output, param, parseQueryRequest, parseQueryTool, parseVectorText, plain, pos, querySchema, raw, recordKey, recordSignature, ref, relJoin, relationKeyColumns, relationOf, renameSource, reportCostProblems, resolveAccessRun, resolveAccessSql, resolveComputeRun, resolveComputeSql, resolveDefaultConditionRun, resolveDefaultConditionSql, resolveFields, resolveJoinRun, resolveJoinSql, resolveSchemaDepth, rlsPredicate, rowsCost, runAggregateFunction, runScalarFunction, runTabularFunction, runWindowFunction, scaleRows, second, selectFunctions, selectTypes, semantic, shouldUseStringSchema, singleRow, sortEntries, sourcesOf, span, stddev, stringAgg, stringToArray, sub, subquery, suggestionBudget, sum, syntheticType, tableFn, textScore, textSearch, timezoneSchema, toArrayRows, toVectorText, typeFromFields, typeMeta, value, valueFieldType, variance, week, when, widenNullable, window, withAid, year };
|
|
10154
|
+
export { AID_REGISTRY, type Access, type AccessRun, type AccessSql, AggregateExpr, type AggregateExprDef, type AggregateRun, type AidInfo, type AidOptions, type AliasedSourceDef, type ArgExprDef, ArrayFieldType, type ArrayFieldTypeDef, type ArrayOp, ArrayOpExpr, type ArrayOpExprDef, type AutoPaginateOptions, BUILTIN_EXPRS, BUILTIN_FIELD_TYPES, BUILTIN_LIBRARY, BUILTIN_QUERIES, Backing, BaseDialect, BetweenExpr, type BetweenExprDef, BinaryExpr, type BinaryExprDef, type BinaryOp, BoolExpr, BoolFieldType, type BoolFieldTypeDef, type BuildQueryToolOptions, type BuildSchemasOptions, type BuiltinFunction, type CTEDef, type CTERecursiveDef, type CTEStatementDef, CTEStatementQuery, type CaseBranchDef, type CaseBranchSpec, CaseExpr, type CaseExprDef, Code, type CodeLine, type CodeOptions, ComparisonExpr, type ComparisonExprDef, type ComparisonOp, type ComputeRun, type ComputeSql, type Computed, type ComputedResolved, type Cost, type CostConstraints, DEFAULT_MAX_CTE_ITERATIONS, DEFAULT_MAX_EXAMPLES, DEFAULT_MAX_QUERY_SCHEMA_TYPES, DateFieldType, type DateFieldTypeDef, type DefaultCondition, type DefaultConditionOp, type DefaultOrder, type DefaultOrderDir, type DefaultOrderScope, type DefaultOrderTerm, type DeleteDef, DeleteQuery, type DescribeEngineOptions, type DescribeOverrides, Dialect, type DialectEntry, type DrillDownFailure, type DrillDownIntoSuccess, type DrillDownResult, type DrillDownSuccess, type DrillParam, type DrillValue, EQ_SELECTIVITY, type Embedder, ExcludedExpr, type ExcludedExprDef, type ExecutorContext, ExistsExpr, type ExistsExprDef, Expr, type ExprClass, type ExprClassEntry, type ExprDef, type ExprKind, ExprQuery, type ExprQueryDef, Field, type FieldBacking, type FieldDef, type FieldExprRestriction, FieldRefExpr, type FieldRefExprDef, type FieldResolved, type FieldSpec, FieldType, type FieldTypeClass, type FieldTypeDef, type FieldTypeKind, type FieldValueDef, type FilterDepth, FiltersExpr, type FiltersExprDef, type FnDepth, type FormatOptions, type FormatProblemsOptions, FunctionCallExpr, type FunctionCallExprDef, type FunctionDef, type FunctionParamDef, type FunctionRun, type FunctionSelector, type FunctionShape, type FunctionSourceDef, IN_SELECTIVITY, InExpr, type InExprDef, Index, type IndexDef, IndexPart, type IndexPartDef, type InferOptions, type InsertDef, InsertQuery, type InsertRowDef, IsNullExpr, type IsNullExprDef, type JSONEntry, type JoinBacking, JoinCtePlanner, type JoinDef, type JoinHop, type JoinOnDef, type JoinRequest, type JoinRunPlan, type JoinSpec, type JoinSqlPlan, type JoinType, JsonFieldType, type JsonFieldTypeDef, type JsonValue, type LateralJoinSpec, LiteralExpr, type LiteralExprDef, LogicalExpr, type LogicalExprDef, type LogicalOp, type MaybePromise, type Meta, MoneyFieldType, type MoneyFieldTypeDef, type MoneyOptions, type NameDepth, type NamedArgs, type Node, NumberFieldType, type NumberFieldTypeDef, type NumberOptions, type OnConflictDef, type OrderDef, type OrderEntry, OutputRefExpr, type OutputRefExprDef, type ParamDef, ParamExpr, type ParamExprDef, ParamSet, PostgresDialect, type Problem, Problems, Query, type QueryClass, type QueryClassEntry, type QueryDef, QueryEngine, type QueryEngineOptions, type QueryField, QueryFunction, QueryJoin, type QueryKind, QueryOrder, type QueryResult, type QueryResultArray, type QuerySchemaOptions, type QuerySchemas, QueryScope, QuerySource, QueryToolError, type QueryToolInput, QueryTypeError, type QueryValidator, RANGE_SELECTIVITY, ROOT_VALIDATE_CONTEXT, type RefDepth, Registry, type RelationBacking, RelationFieldType, type RelationFieldTypeDef, type RelationJoinOnDef, type RelationJoinSpec, type RelationKey, type RelationKeyPair, type RelationOn, type RelationOnPair, type RelationResolved, type RenderedSql, type ResolvedSchemaDepth, type ResolvedType, type RlsProvider, RuntimeContext, type RuntimeJoin, type RuntimeOptions, SEMANTIC_ROW_PENALTY, type ScalarKind, type ScalarRun, type ScalarValue, type SchemaDepth, type SchemaOptions, type SearchBacking, type SelectDef, type SelectFieldDef, SelectQuery, type SelectTypesOptions, type SelectedFunctions, type SemanticBacking, type SemanticEmbeddings, SemanticExpr, type SemanticExprDef, type SemanticQueryDef, type SemanticTextToVector, type SetDef, type SetOperationDef, SetOperationQuery, type SortEntryDef, type SortSelectionDef, type SorterDef, SorterExpr, type SourceDef, type SourceFieldOptionalRef, type SourceFieldRef, type SourceFieldsRef, type SourceRecord, type SourceRow, type Span, type SpanMeta, SqlContext, type SqlParamValue, SqlText, type SqlValue, SubqueryExpr, type SubqueryExprDef, type SubquerySourceDef, TEXT_SEARCH_ROW_PENALTY, TabularFunctionCallExpr, type TabularFunctionCallExprDef, type TabularRun, TextFieldType, type TextFieldTypeDef, type TextOptions, TextScoreExpr, type TextScoreExprDef, TextSearchExpr, type TextSearchExprDef, TimestampFieldType, type TimestampFieldTypeDef, type TimezonePolicy, type ToSqlOptions, Type, type TypeBacking, type TypeDef, type TypeExecutor, type TypeFieldRef, type TypeResolved, type TypeSourceDef, type TypeSpec, type TypeState, UnaryExpr, type UnaryExprDef, type UnaryOp, type UpdateDef, UpdateQuery, type ValidateContext, Value, type ValueCategory, type ValueSchemaOptions, WINDOW_ORDER_ARG, WindowExpr, type WindowExprDef, type WindowOrderSpec, type WindowRun, type WriteValueDef, ZERO_COST, add, addCost, age, agg, aidInfo, aliasedDigest, and, arrayAgg, arrayAppend, arrayConcat, arrayContains, arrayDistinct, arrayExecutor, arrayIndexOf, arrayPrepend, arrayRemove, arraySlice, arrayToString, asFieldType, autoPaginate, avg, between, boolAnd, boolOr, buildQueryTool, buildSchemas, builtinDialects, bytesOfResolved, canonicalize, caseExpr, cloneRecord, code, concat, contains, containsAll, containsAny, count, countIf, countStar, createRegistry, currentTime, currentTimestamp, dateAdd, dateDiff, dateFormat, datePart, dateTrunc, day, dayOfWeek, dayOfYear, defaultConditionOps, defaultConditionWithout, depthInstructions, describeDialects, describeEngine, describeExprs, describeFunctions, describeInput, describeQueryExamples, describeType, describeTypes, didYouMean, directedMessage, div, drillDown, drillDownInto, e, editDistance, embeddingResolver, epoch, eq, excluded, exists, exprDefSchema, exprDigest, fieldMeta, fieldNameOf, fieldTypeDefSchema, filters, firstField, fn, fromEpoch, generatedFieldDescription, generatedFieldLabel, generatedTypeDescription, generatedTypeLabel, gt, gte, hour, humanize, ilike, inList, inSubquery, inferType, isEmpty, isNull, isScalar, isScalarValue, isType, isVectorText, join, joinAlias, joinCode, joinLines, jsonValueSchema, like, lit, lt, lte, makeDate, makeField, makeResult, max, maxCost, mergeRows, min, minute, mod, month, mul, nearest, nearestKind, neg, neq, not, notBetween, notEmpty, notExists, notInList, notInSubquery, notLike, notNull, or, output, param, parseQueryRequest, parseQueryTool, parseVectorText, plain, pos, querySchema, raw, recordKey, recordSignature, ref, relJoin, relationKeyColumns, relationOf, renameSource, reportCostProblems, resolveAccessRun, resolveAccessSql, resolveComputeRun, resolveComputeSql, resolveDefaultConditionRun, resolveDefaultConditionSql, resolveFields, resolveJoinRun, resolveJoinSql, resolveSchemaDepth, rlsPredicate, rowsCost, runAggregateFunction, runScalarFunction, runTabularFunction, runWindowFunction, scaleRows, second, selectFunctions, selectTypes, semantic, shouldUseStringSchema, singleRow, sortEntries, sourcesOf, span, stddev, stringAgg, stringToArray, sub, subquery, suggestionBudget, sum, syntheticType, tableFn, textScore, textSearch, timezoneSchema, toArrayRows, toVectorText, typeFromFields, typeMeta, value, valueFieldType, variance, week, when, widenNullable, window, withAid, year };
|