@aeye/query 0.3.10 → 0.5.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 +32 -6
- package/aeye-query.md +9 -4
- package/dist/index.d.ts +248 -28
- package/dist/index.js +465 -59
- package/package.json +51 -51
package/README.md
CHANGED
|
@@ -45,6 +45,17 @@ automatically gain the matching has-many field pointing back. The join key on
|
|
|
45
45
|
either side resolves through each Type's *identity field* (the field of its
|
|
46
46
|
first unique single-field index, else the field named `id`).
|
|
47
47
|
|
|
48
|
+
A relation field can be **compared directly to a value** in `= <> in notIn`,
|
|
49
|
+
where the value is an object keyed by the target's **primary key** (single or
|
|
50
|
+
composite) — `{ kind: 'comparison', op: '=', left: relRef, right: { kind:
|
|
51
|
+
'param', name: 'u' } }` with `:u = { id: 5 }` (a single-key relation also
|
|
52
|
+
accepts a bare scalar). A **belongs-to** matches its FK columns; a **has-many**
|
|
53
|
+
matches by **membership** — `= value` is a correlated `EXISTS` testing that the
|
|
54
|
+
value's key is in the related set (`<>` / `notIn` → `NOT EXISTS`). Two relations
|
|
55
|
+
of the same target compare by their FK key (`order.customer = invoice.customer`);
|
|
56
|
+
a has-many may not be compared to another relation. Ordering / LIKE on a relation
|
|
57
|
+
is rejected — a relation compares by identity, not order.
|
|
58
|
+
|
|
48
59
|
Indexes are **composite**: an ordered list of parts, each with a prefix
|
|
49
60
|
distinct-row `count` (non-increasing); the index is unique iff its last part's
|
|
50
61
|
`count === 1`. Text matching is **case-insensitive by default** — set a text
|
|
@@ -839,17 +850,32 @@ identifier; suffixed `_2`, `_3`, … on collision with a param the query already
|
|
|
839
850
|
uses). Failure cases (`drill.no-aggregation` / `non-invertible` /
|
|
840
851
|
`having-aggregate` / `window-unsupported`) return LLM-friendly `Problems`.
|
|
841
852
|
|
|
842
|
-
## Cost
|
|
853
|
+
## Cost & estimation
|
|
843
854
|
|
|
844
|
-
|
|
845
|
-
indexes
|
|
855
|
+
Bottom-up estimates driven by each Type's cardinality (`count` rows, `bytes`
|
|
856
|
+
per row), its indexes + fixed **selectivity** for predicates (an indexed
|
|
857
|
+
equality narrows toward one row; a non-indexed one applies `EQ_SELECTIVITY`),
|
|
858
|
+
and per-Type / per-field `changes` rates. Five estimators hang off the engine:
|
|
846
859
|
|
|
847
860
|
```ts
|
|
848
|
-
const cost
|
|
849
|
-
const
|
|
850
|
-
//
|
|
861
|
+
const cost = engine.cost(select); // { rows, bytes } — WORK to produce the result (scanned rows)
|
|
862
|
+
const output = engine.outputCost(select); // { rows, bytes } — SIZE of the result (delivered rows × projection width)
|
|
863
|
+
const affected = engine.affected(update); // { rows, types: [{ type, rows }] } — rows an INSERT/UPDATE/DELETE (or CTE) mutates
|
|
864
|
+
const refs = engine.references(select); // { types, fields, functions } — exactly what the query READS
|
|
865
|
+
const ttl = engine.changeInterval(select); // ms until the data behind it could change (0 = always, -1 = never, else fastest rate)
|
|
866
|
+
|
|
867
|
+
// Constraints reject over-budget queries during validation:
|
|
868
|
+
const problems = engine.validateQuery(select, undefined, { maxRows: 100, maxBytes: 1_000_000 });
|
|
869
|
+
// → cost.rows-exceeded / cost.bytes-exceeded when the estimate blows past a cap
|
|
851
870
|
```
|
|
852
871
|
|
|
872
|
+
`cost` estimates work (OR-aware, index-probe driven); `outputCost` sizes the
|
|
873
|
+
delivered result (post-WHERE/GROUP/DISTINCT, capped by LIMIT/OFFSET);
|
|
874
|
+
`affected` counts mutated rows per Type; `references` powers `changeInterval`,
|
|
875
|
+
which folds the read Types' / fields' / functions' `changes` rates into a single
|
|
876
|
+
freshness / cache-TTL signal. All accept the same execution-time
|
|
877
|
+
`options.params` / `filters` / `sort` so the estimate reflects what actually runs.
|
|
878
|
+
|
|
853
879
|
## Functions
|
|
854
880
|
|
|
855
881
|
All four function shapes are uniform: declare a `FunctionDef` (name, shape,
|
package/aeye-query.md
CHANGED
|
@@ -47,11 +47,11 @@ Every kind is one branch of the `ExprDef` union. Availability in the LLM schema
|
|
|
47
47
|
| `relation-path` | Walks relation fields from a source (optionally ending at a scalar); planner synthesizes the joins. |
|
|
48
48
|
| `binary` | Arithmetic `left <op> right` (`+ - * / %`). |
|
|
49
49
|
| `unary` | `<op> operand` (`-` / `+`). |
|
|
50
|
-
| `comparison` | `left <op> right` → boolean (`= <> < <= > >=`, `like`, `notLike`, `ilike`). |
|
|
50
|
+
| `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`). |
|
|
51
51
|
| `logical` | Boolean connective `and` / `or` / `not` over operands. |
|
|
52
52
|
| `is-null` | `value IS [NOT] NULL`. |
|
|
53
53
|
| `between` | `value BETWEEN lower AND upper` (negatable). |
|
|
54
|
-
| `in` | `value IN (list \| subquery)` (negatable). |
|
|
54
|
+
| `in` | `value IN (list \| subquery)` (negatable). A RELATION `value` matches list `{ pk }` values by FK key (belongs-to) or membership (has-many). |
|
|
55
55
|
| `case` | `CASE WHEN … THEN … [ELSE …] END`. |
|
|
56
56
|
| `function-call` | A scalar function call by name with named args. |
|
|
57
57
|
| `aggregate` | An aggregate function over a group (`count(*)` = empty args); optional `distinct`. |
|
|
@@ -89,7 +89,7 @@ Everything is referenced by its **Type name** — there is no alias to invent or
|
|
|
89
89
|
- **Single-expression query** — `{ kind: 'expr', expr }` for a scalar computation.
|
|
90
90
|
- **Params** — `{ kind: 'param', name }` infers its type from use; bound at run/emit via `options.params`. Introspect with `query.params(engine)` → `ParamDef[]`.
|
|
91
91
|
- **Filters** — a `filters` placeholder (`{ source, fields? }`) is authored by the LLM but the **predicate is supplied at execution time** by the developer: `options.filters` is a `Record<source, boolean Expr | ExprDef | null>`. The placeholder evaluates/emits it (vacuously `TRUE` when none). Introspect exposed sources + fields with `query.filters(engine)` → `Record<source, { fields: QueryField[] }>` (name + resolved type + nullability + kind, restricted to any `fields` allowlist); `query.filterSources()` lists targetable sources.
|
|
92
|
-
- **Cost** —
|
|
92
|
+
- **Cost & estimation** — bottom-up estimates driven by Type `count`/`bytes`, indexes + selectivity, and per-Type/field `changes` rates. `engine.cost(query)` → `{ rows, bytes }` (the WORK to produce the result); `engine.outputCost(query)` → `{ rows, bytes }` (the SIZE of the result — delivered rows × projection width); `engine.affected(query)` → `{ rows, types[] }` (rows an INSERT/UPDATE/DELETE or CTE mutates, OR-aware via indexes); `engine.references(query)` → `{ types, fields, functions }` (exactly what the query reads, incl. execution-time `filters`/`sort` and called functions); `engine.changeInterval(query)` → ms until the data behind it could change (freshness/cache-TTL: `0` = always, `-1` = never, else the fastest read rate). `validateQuery(query, _, { maxRows, maxBytes })` rejects over-budget queries (`cost.rows-exceeded` / `cost.bytes-exceeded`).
|
|
93
93
|
|
|
94
94
|
## Write model & permissions
|
|
95
95
|
|
|
@@ -130,7 +130,7 @@ The flat `TypeDef` the LLM sees can be arbitrarily richer behind the scenes. A `
|
|
|
130
130
|
- **FLS** (`FieldBacking.access`) — a per-field gate emitting `CASE WHEN <pred> THEN <value> ELSE NULL END`; `false` ⇒ constant `NULL`.
|
|
131
131
|
- **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).
|
|
132
132
|
- **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, `relation-path` value + runtime, 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`).
|
|
133
|
-
- **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
|
|
133
|
+
- **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.
|
|
134
134
|
|
|
135
135
|
## Function library
|
|
136
136
|
|
|
@@ -187,6 +187,11 @@ const result = await engine.run(query, { params, filters, includeTotal });
|
|
|
187
187
|
|
|
188
188
|
`engine.toSQL(query, dialect, options?)` emits `{ sql, params }` for any registered dialect. Base uses `?` placeholders; Postgres uses `$1, $2, …`. Relation joins synthesize their ON clause from the relation key. `toSQL` accepts the same `params` / `filters` / `includeTotal` options as `run`, so emitted SQL matches what would run.
|
|
189
189
|
|
|
190
|
+
- **Semantic text terms → vectors (extract → embed → sync build).** A `semantic(...)` term whose query is a TEXT literal (or a text `param` value) is TEXT, not an embedding, and cannot be bound as `'<text>'::vector`. Because SQL emission is SYNCHRONOUS, the caller embeds up front and passes the vectors in — `toSQL` (and `run`) stay sync for every caller:
|
|
191
|
+
1. **Extract** — `engine.semanticTexts(query, opts?) → string[]` returns the DISTINCT plain-text semantic terms needing embedding, in a stable (first-seen) order. It reuses `toSQL`'s exact emit walk, so it finds terms at ANY depth (nested boolean AND/OR/NOT, a subquery WHERE, a computed-field expr, a function-call arg, a CASE/WHEN — anywhere an `Expr` sits) and never returns an already-`'[…]'` vector-text term. `opts` are the same `params` / `filters` a bind would see.
|
|
192
|
+
2. **Embed** each returned term (the caller's model/network call) and fill a `text → vector` cache — a `ReadonlyMap<string, readonly number[]>` (a resolver function `(text) => readonly number[] | undefined` is accepted too; both are the `SemanticEmbeddings` type).
|
|
193
|
+
3. **Build** — `engine.toSQL(query, dialect, { embeddings })` looks each term up, formats it with `toVectorText`, and binds `$n::vector` (all sync). A needed term MISSING from the cache **throws** (fail loud) rather than mis-binding; with NO cache a plain-text term likewise throws. A **pre-embedded `'[…]'` vector-text term / param is bound as-is** (never looked up), and a `vectorField` backing (query vector already a `$n::vector` param) is unchanged. The SAME `embeddings` cache is accepted by `engine.run(query, { embeddings })` for in-memory scoring (no embedder required). Helpers: `toVectorText(number[]) → '[…]'`, `parseVectorText('[…]') → number[]`, `isVectorText(string)`. (Replaces the former `convertSemanticText` seam + `toSQLAsync` — with vectors precomputed, nothing in `toSQL` is async.)
|
|
194
|
+
|
|
190
195
|
## The LLM tool
|
|
191
196
|
|
|
192
197
|
The parse+validate pipeline is exposed **standalone**, so you can validate a query without building a `Tool` just to call `.parse` on it. All three entries share ONE implementation:
|
package/dist/index.d.ts
CHANGED
|
@@ -1267,22 +1267,37 @@ declare abstract class Dialect implements DialectEntry {
|
|
|
1267
1267
|
* comparison is compared by FK key and a relation-vs-scalar comparison is
|
|
1268
1268
|
* rejected (`compare.relation-vs-value`).
|
|
1269
1269
|
*/
|
|
1270
|
+
/**
|
|
1271
|
+
* One join-key column pair of a relation, oriented to the relation's own side:
|
|
1272
|
+
* `local` a column on the relation's SOURCE side, `foreign` the matching column
|
|
1273
|
+
* on the TARGET (the target's PK field for a belongs-to). `keyType` is the
|
|
1274
|
+
* scalar value type flowing across it — used to type a bind param and to
|
|
1275
|
+
* validate a supplied relation VALUE's field.
|
|
1276
|
+
*/
|
|
1277
|
+
interface RelationKeyPair {
|
|
1278
|
+
readonly local: string;
|
|
1279
|
+
readonly foreign: string;
|
|
1280
|
+
readonly keyType: FieldType;
|
|
1281
|
+
}
|
|
1270
1282
|
interface RelationResolved {
|
|
1271
1283
|
/** The bound source the relation field is read from. */
|
|
1272
1284
|
readonly source: string;
|
|
1273
1285
|
/** The relation field's name on that source. */
|
|
1274
1286
|
readonly field: string;
|
|
1275
|
-
/** The LOCAL key column carrying the value a comparison
|
|
1287
|
+
/** The LOCAL key column carrying the value a comparison compares by (`keys[0].local`). */
|
|
1276
1288
|
readonly keyField: string;
|
|
1277
1289
|
/**
|
|
1278
|
-
* The SCALAR field type of the relation's key VALUE (
|
|
1279
|
-
* target's identity value; a has-many keys on this
|
|
1280
|
-
* bind param compared against the relation be typed
|
|
1281
|
-
* comparison read as an id compare.
|
|
1290
|
+
* The SCALAR field type of the relation's (leading) key VALUE (`keys[0].keyType`).
|
|
1291
|
+
* A belongs-to holds the target's identity value; a has-many keys on this
|
|
1292
|
+
* Type's identity. Lets a bind param compared against the relation be typed.
|
|
1282
1293
|
*/
|
|
1283
1294
|
readonly keyType: FieldType;
|
|
1284
1295
|
/** The relation's target Type name (its `to`). */
|
|
1285
1296
|
readonly to: string;
|
|
1297
|
+
/** Cardinality: `1` = belongs-to (single target row), `>1` = has-many (a set). */
|
|
1298
|
+
readonly count: number;
|
|
1299
|
+
/** The ORDERED join-key pairs (composite-capable) driving relation comparison lowering. */
|
|
1300
|
+
readonly keys: readonly RelationKeyPair[];
|
|
1286
1301
|
}
|
|
1287
1302
|
/** A resolved value that is an entire Type (a whole row/source). */
|
|
1288
1303
|
interface TypeResolved {
|
|
@@ -1492,6 +1507,57 @@ declare class QueryScope {
|
|
|
1492
1507
|
child(): QueryScope;
|
|
1493
1508
|
}
|
|
1494
1509
|
|
|
1510
|
+
/**
|
|
1511
|
+
* pgvector TEXT helpers + the precomputed text→vector embedding cache.
|
|
1512
|
+
*
|
|
1513
|
+
* A `semantic(...)` term can be a plain-text LITERAL or a text PARAM value. Such
|
|
1514
|
+
* text is NOT an embedding — it must be turned into a vector before it can be
|
|
1515
|
+
* compared. Postgres has no array bind type, so a query vector travels as a
|
|
1516
|
+
* pgvector TEXT literal (`[a,b,c]`) and is cast `::vector` by the dialect. The
|
|
1517
|
+
* embedding itself is a model/network call the query layer does not own, so the
|
|
1518
|
+
* CALLER embeds up front (see `semanticTexts`) and passes the resulting
|
|
1519
|
+
* text→vector cache (see {@link SemanticEmbeddings}) into `engine.toSQL` /
|
|
1520
|
+
* `engine.run`; binding then stays fully SYNCHRONOUS.
|
|
1521
|
+
*
|
|
1522
|
+
* This module has NO runtime imports (pure string/number work), so it sits at
|
|
1523
|
+
* the bottom of the module graph and is safe to import from both the SQL and the
|
|
1524
|
+
* runtime paths.
|
|
1525
|
+
*/
|
|
1526
|
+
/**
|
|
1527
|
+
* A caller-supplied SYNC converter turning a plain-text semantic term — a
|
|
1528
|
+
* `semantic(...)` TEXT LITERAL, or the runtime value of a text PARAM — into its
|
|
1529
|
+
* pgvector TEXT form (a bracketed literal such as `[0.0123,-0.045,…]`). It is the
|
|
1530
|
+
* INTERNAL seam the SQL emit path threads (built from a {@link SemanticEmbeddings}
|
|
1531
|
+
* cache by `engine.toSQL`); callers supply the {@link SemanticEmbeddings} cache,
|
|
1532
|
+
* not this converter directly.
|
|
1533
|
+
*/
|
|
1534
|
+
type SemanticTextToVector = (text: string) => string;
|
|
1535
|
+
/**
|
|
1536
|
+
* The precomputed text→vector cache a caller fills after embedding the terms
|
|
1537
|
+
* `semanticTexts` extracted, and passes to `engine.toSQL` / `engine.run`
|
|
1538
|
+
* so a `semantic(...)` text term binds SYNCHRONOUSLY. The primary shape is a
|
|
1539
|
+
* `ReadonlyMap<string, readonly number[]>` (text → vector); a resolver function
|
|
1540
|
+
* is accepted as a superset. A term absent from the cache is a fail-loud error at
|
|
1541
|
+
* bind time (never a silently mis-bound `'<text>'::vector`).
|
|
1542
|
+
*/
|
|
1543
|
+
type SemanticEmbeddings = ReadonlyMap<string, readonly number[]> | ((text: string) => readonly number[] | undefined);
|
|
1544
|
+
/**
|
|
1545
|
+
* Normalize a {@link SemanticEmbeddings} (map OR resolver) into a lookup
|
|
1546
|
+
* function `text → vector | undefined`. Pure — no runtime imports.
|
|
1547
|
+
*/
|
|
1548
|
+
declare function embeddingResolver(embeddings: SemanticEmbeddings): (text: string) => readonly number[] | undefined;
|
|
1549
|
+
/** Whether `text` is already in pgvector TEXT form (a bracketed `[…]` literal). */
|
|
1550
|
+
declare function isVectorText(text: string): boolean;
|
|
1551
|
+
/** Format an embedding vector as pgvector TEXT (`[a,b,c]`, no spaces). */
|
|
1552
|
+
declare function toVectorText(vector: readonly number[]): string;
|
|
1553
|
+
/**
|
|
1554
|
+
* Parse a pgvector TEXT literal (`[a,b,c]`) back into numbers. Tolerates
|
|
1555
|
+
* surrounding whitespace and an empty vector (`[]` ⇒ `[]`). Throws on a value
|
|
1556
|
+
* that is not bracketed pgvector text (so a mis-supplied term fails loudly rather
|
|
1557
|
+
* than silently scoring against a garbage vector).
|
|
1558
|
+
*/
|
|
1559
|
+
declare function parseVectorText(text: string): number[];
|
|
1560
|
+
|
|
1495
1561
|
/**
|
|
1496
1562
|
* Row-Level-Security injection.
|
|
1497
1563
|
*
|
|
@@ -1703,6 +1769,16 @@ interface RuntimeOptions {
|
|
|
1703
1769
|
includeTotal?: boolean;
|
|
1704
1770
|
/** Embedder override (defaults to the engine's). */
|
|
1705
1771
|
embedder?: Embedder;
|
|
1772
|
+
/**
|
|
1773
|
+
* Precomputed text→vector cache (see {@link SemanticEmbeddings}) for a
|
|
1774
|
+
* `semantic(...)` QUERY term (a text literal, or a text-param value), mirroring
|
|
1775
|
+
* the SQL path's `toSQL({ embeddings })`. The term's vector is looked up here
|
|
1776
|
+
* and cosine-scored in-memory (no embedder / network call); a pre-embedded
|
|
1777
|
+
* `[…]` value is used directly. Takes precedence over `embedder` for the query
|
|
1778
|
+
* term. A term MISSING from the cache throws (fail loud). With no cache, the
|
|
1779
|
+
* existing embedder path is used unchanged.
|
|
1780
|
+
*/
|
|
1781
|
+
embeddings?: SemanticEmbeddings;
|
|
1706
1782
|
/** Per-record embedding lookup for semantic scoring. */
|
|
1707
1783
|
recordEmbedding?: (source: string, id: JsonValue) => Promise<number[] | null>;
|
|
1708
1784
|
/** Cap on recursive-CTE iterations. */
|
|
@@ -1761,6 +1837,12 @@ declare class RuntimeContext {
|
|
|
1761
1837
|
*/
|
|
1762
1838
|
private readonly sourceTypes;
|
|
1763
1839
|
private readonly embedder?;
|
|
1840
|
+
/**
|
|
1841
|
+
* Precomputed text→vector cache for a semantic QUERY term (SQL parity), or
|
|
1842
|
+
* `undefined`. Normalized to a lookup function; `undefined` when no cache was
|
|
1843
|
+
* supplied.
|
|
1844
|
+
*/
|
|
1845
|
+
readonly resolveEmbedding?: (text: string) => readonly number[] | undefined;
|
|
1764
1846
|
private readonly recordEmbedding?;
|
|
1765
1847
|
constructor(engine: QueryEngine, options?: RuntimeOptions);
|
|
1766
1848
|
/** The bound value of `name`, or NULL when unbound. */
|
|
@@ -1923,6 +2005,18 @@ declare class RelationFieldType extends FieldType {
|
|
|
1923
2005
|
* declaring Type's name in camelCase.
|
|
1924
2006
|
*/
|
|
1925
2007
|
resolveKey(relationFieldName: string, thisType: Type, targetType: Type): RelationKey;
|
|
2008
|
+
/**
|
|
2009
|
+
* The UNALIASED, ordered join-key column pairs for this relation — the
|
|
2010
|
+
* composite/backing-aware generalization of {@link resolveKey}. Each pair is
|
|
2011
|
+
* `{ local, foreign }`: `local` a column on THIS Type's side, `foreign` the
|
|
2012
|
+
* matching column on the TARGET (the target's PK field for a belongs-to). Uses
|
|
2013
|
+
* the field's `RelationBacking.keys` when declared, else the single
|
|
2014
|
+
* name-convention pair. Drives relation comparison lowering (`= <> in`).
|
|
2015
|
+
*/
|
|
2016
|
+
resolveKeys(engine: QueryEngine, relationFieldName: string, thisType: Type, targetType: Type): {
|
|
2017
|
+
local: string;
|
|
2018
|
+
foreign: string;
|
|
2019
|
+
}[];
|
|
1926
2020
|
/**
|
|
1927
2021
|
* Resolve the full join `ON` for this relation hop, consulting the field's
|
|
1928
2022
|
* DEV-SIDE `RelationBacking` (physical FK columns / custom predicate) and
|
|
@@ -2545,7 +2639,7 @@ declare class ComparisonExpr extends BoolExpr {
|
|
|
2545
2639
|
readonly right: Expr;
|
|
2546
2640
|
static readonly KIND: "comparison";
|
|
2547
2641
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
2548
|
-
static readonly INSTRUCTIONS: "`left <op> right` \u2192 boolean (`= <> < <= > >=`, `like`, `notLike`, `ilike`).
|
|
2642
|
+
static readonly INSTRUCTIONS: "`left <op> right` \u2192 boolean (`= <> < <= > >=`, `like`, `notLike`, `ilike`). A RELATION field-ref compares by IDENTITY with `=`/`<>` ONLY (ordering / LIKE on a relation is rejected). Its RHS may be (a) another relation of the SAME target \u2014 compared by FK key (`order.customer = invoice.customer`); or (b) a `{ pk }` VALUE param keyed by the target's primary-key fields (`assignedUser = :u` with `:u = {id:5}`); a single-key relation also accepts a bare scalar param. A BELONGS-TO compares the FK columns; a HAS-MANY compares by MEMBERSHIP \u2014 `= value` is TRUE when the value's key is in the related set (correlated EXISTS), `<>` is NOT EXISTS; a has-many may not be compared to another relation. Do NOT compare a relation to a scalar id COLUMN/field-ref (the correlation bug) \u2014 JOIN the relation (`joins:[{on:{kind:'relation',source,field,as}}]`) and compare the joined key.";
|
|
2549
2643
|
readonly kind: "comparison";
|
|
2550
2644
|
/** Wrap `left <op> right` as a scalar comparison predicate. */
|
|
2551
2645
|
constructor(op: ComparisonOp, left: Expr, right: Expr);
|
|
@@ -2678,7 +2772,7 @@ declare class InExpr extends BoolExpr {
|
|
|
2678
2772
|
readonly not: boolean;
|
|
2679
2773
|
static readonly KIND: "in";
|
|
2680
2774
|
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
2681
|
-
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). To project a value across a relation, add a `relation` join
|
|
2775
|
+
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. To project a value across a relation in the SUBQUERY form, add a `relation` join and field-ref the joined alias \u2014 do NOT project/compare a relation field-ref as a scalar id. To correlate the subquery, JOIN the relation and compare the joined key to the outer scalar. Set `not:true` for NOT IN.";
|
|
2682
2776
|
/**
|
|
2683
2777
|
* Worked examples (see `ExprClass.EXAMPLES`) — the two `in` shapes: an explicit
|
|
2684
2778
|
* value LIST, and a single-field SUBQUERY that crosses a relation via a
|
|
@@ -3306,9 +3400,13 @@ declare class SemanticExpr extends Expr {
|
|
|
3306
3400
|
*/
|
|
3307
3401
|
scanRowPenalty(): number;
|
|
3308
3402
|
/**
|
|
3309
|
-
*
|
|
3310
|
-
*
|
|
3311
|
-
*
|
|
3403
|
+
* Resolve the query side into a vector (null when unavailable). A caller-supplied
|
|
3404
|
+
* precomputed embeddings cache (`ctx.resolveEmbedding`, mirroring the SQL path's
|
|
3405
|
+
* `toSQL({ embeddings })`) takes precedence when present — the term's vector is
|
|
3406
|
+
* looked up synchronously; a pre-embedded `[…]` value short-circuits the lookup.
|
|
3407
|
+
* A term MISSING from the cache throws (fail loud). With no cache it falls back
|
|
3408
|
+
* to the `SemanticBacking`'s `embedder` override, else the run / engine embedder
|
|
3409
|
+
* (unchanged existing behavior).
|
|
3312
3410
|
*/
|
|
3313
3411
|
private queryVector;
|
|
3314
3412
|
/** Embed `text` via the backing's `embedder` override, else the run's embedder (cached). */
|
|
@@ -3371,8 +3469,25 @@ declare class SemanticExpr extends Expr {
|
|
|
3371
3469
|
private sideVectorSQL;
|
|
3372
3470
|
/** The `SemanticBacking` in effect for a bound `alias` (+ field), or `undefined`. */
|
|
3373
3471
|
private backingForAlias;
|
|
3374
|
-
/**
|
|
3472
|
+
/**
|
|
3473
|
+
* The query side of the similarity, emitted for SQL (text / param only). A
|
|
3474
|
+
* `semantic(...)` term is TEXT — never a raw embedding — so a literal (and a
|
|
3475
|
+
* plain-text param VALUE) is EMBEDDED into a pgvector TEXT literal (`[…]`) via
|
|
3476
|
+
* the caller's `ctx.semanticText` converter before it is bound; the dialect
|
|
3477
|
+
* then casts it `::vector`. Two existing valid inputs are preserved untouched:
|
|
3478
|
+
* a PRE-EMBEDDED vector-text term / param (already `[…]`) is bound as-is, and a
|
|
3479
|
+
* `null` / absent param binds `null`. When a plain-text term is hit but NO
|
|
3480
|
+
* embeddings cache was supplied — or the term is missing from it — this THROWS
|
|
3481
|
+
* (rather than emitting the invalid `'<text>'::vector`).
|
|
3482
|
+
*/
|
|
3375
3483
|
private querySQL;
|
|
3484
|
+
/**
|
|
3485
|
+
* Resolve a plain-text semantic term to its pgvector TEXT literal via the
|
|
3486
|
+
* caller's precomputed embeddings (`ctx.semanticText`, built from
|
|
3487
|
+
* `toSQL({ embeddings })`), or THROW a directed error when no cache was
|
|
3488
|
+
* supplied. The converter itself throws when the cache lacks THIS term.
|
|
3489
|
+
*/
|
|
3490
|
+
private vectorTextForSql;
|
|
3376
3491
|
/** Serialize back to its JSON ExprDef. */
|
|
3377
3492
|
toJSON(): SemanticExprDef;
|
|
3378
3493
|
/** Deep-copy this expr. */
|
|
@@ -3929,7 +4044,7 @@ declare class JoinCtePlanner {
|
|
|
3929
4044
|
/** The RLS predicate provider, folded into every planned join / CTE. */
|
|
3930
4045
|
readonly rls: RlsProvider | undefined;
|
|
3931
4046
|
/** Bound param values, so RLS predicates with params emit real bindings. */
|
|
3932
|
-
readonly params: Readonly<Record<string,
|
|
4047
|
+
readonly params: Readonly<Record<string, SqlParamValue>>;
|
|
3933
4048
|
/**
|
|
3934
4049
|
* Implicit-join mode: lower every required join to a FROM/USING source item
|
|
3935
4050
|
* plus a WHERE-able key predicate (instead of a `JOIN … ON …` clause). Set
|
|
@@ -3960,7 +4075,7 @@ declare class JoinCtePlanner {
|
|
|
3960
4075
|
/** The RLS predicate provider, folded into every planned join / CTE. */
|
|
3961
4076
|
rls: RlsProvider | undefined,
|
|
3962
4077
|
/** Bound param values, so RLS predicates with params emit real bindings. */
|
|
3963
|
-
params?: Readonly<Record<string,
|
|
4078
|
+
params?: Readonly<Record<string, SqlParamValue>>,
|
|
3964
4079
|
/**
|
|
3965
4080
|
* Implicit-join mode: lower every required join to a FROM/USING source item
|
|
3966
4081
|
* plus a WHERE-able key predicate (instead of a `JOIN … ON …` clause). Set
|
|
@@ -4027,6 +4142,13 @@ declare class JoinCtePlanner {
|
|
|
4027
4142
|
|
|
4028
4143
|
/** A value that may be bound as a SQL parameter. */
|
|
4029
4144
|
type SqlValue = string | number | boolean | null;
|
|
4145
|
+
/**
|
|
4146
|
+
* A supplied param value: a bindable scalar, OR a RELATION KEY object (`{ pk }`
|
|
4147
|
+
* keyed by the target's PK field names) used on the RHS of a relation
|
|
4148
|
+
* comparison (`assignedUser = { id: 5 }`). A relation comparison decomposes the
|
|
4149
|
+
* object into per-column binds; a scalar binds directly.
|
|
4150
|
+
*/
|
|
4151
|
+
type SqlParamValue = SqlValue | Readonly<Record<string, SqlValue>>;
|
|
4030
4152
|
/** A rendered SQL string plus its ordered bind parameters. */
|
|
4031
4153
|
interface RenderedSql {
|
|
4032
4154
|
/** The flat SQL string with dialect-numbered placeholders. */
|
|
@@ -4099,8 +4221,8 @@ declare class SqlContext {
|
|
|
4099
4221
|
readonly rls: RlsProvider | undefined;
|
|
4100
4222
|
/** True while emitting inside an aggregate's argument (fan-out routing). */
|
|
4101
4223
|
readonly inAggregate: boolean;
|
|
4102
|
-
/** Bound parameter VALUES (param name →
|
|
4103
|
-
readonly params: Readonly<Record<string,
|
|
4224
|
+
/** Bound parameter VALUES (param name → scalar, or a relation `{ pk }` object), for `param` emission. */
|
|
4225
|
+
readonly params: Readonly<Record<string, SqlParamValue>>;
|
|
4104
4226
|
/**
|
|
4105
4227
|
* Execution-time filter EXPRS (already parsed), keyed by source name — read
|
|
4106
4228
|
* by a `filters` placeholder's `toSQL`. Propagates to nested levels (a
|
|
@@ -4129,6 +4251,17 @@ declare class SqlContext {
|
|
|
4129
4251
|
* subquery may carry its own sorter), mirroring `filters`.
|
|
4130
4252
|
*/
|
|
4131
4253
|
readonly sortSpec: readonly SortSelectionDef[];
|
|
4254
|
+
/**
|
|
4255
|
+
* INTERNAL SYNC converter turning a plain-text semantic term (a `semantic(...)`
|
|
4256
|
+
* literal, or a text-param value) into its pgvector TEXT literal (`[…]`) so it
|
|
4257
|
+
* can be bound + cast `::vector`. Built by `engine.toSQL` from its precomputed
|
|
4258
|
+
* `opts.embeddings` cache (looking each term up + formatting the vector);
|
|
4259
|
+
* throws when the cache lacks the term. Undefined when the caller supplied no
|
|
4260
|
+
* embeddings — a `SemanticExpr` that hits a plain-text term then throws
|
|
4261
|
+
* (rather than emitting the invalid `'<text>'::vector`). Propagated to every
|
|
4262
|
+
* nested level so a subquery's semantic terms resolve too.
|
|
4263
|
+
*/
|
|
4264
|
+
readonly semanticText: SemanticTextToVector | undefined;
|
|
4132
4265
|
constructor(
|
|
4133
4266
|
/** The active dialect (identical to the `dialect` argument of `toSQL`). */
|
|
4134
4267
|
dialect: Dialect,
|
|
@@ -4142,8 +4275,8 @@ declare class SqlContext {
|
|
|
4142
4275
|
rls: RlsProvider | undefined,
|
|
4143
4276
|
/** True while emitting inside an aggregate's argument (fan-out routing). */
|
|
4144
4277
|
inAggregate?: boolean,
|
|
4145
|
-
/** Bound parameter VALUES (param name →
|
|
4146
|
-
params?: Readonly<Record<string,
|
|
4278
|
+
/** Bound parameter VALUES (param name → scalar, or a relation `{ pk }` object), for `param` emission. */
|
|
4279
|
+
params?: Readonly<Record<string, SqlParamValue>>,
|
|
4147
4280
|
/**
|
|
4148
4281
|
* Execution-time filter EXPRS (already parsed), keyed by source name — read
|
|
4149
4282
|
* by a `filters` placeholder's `toSQL`. Propagates to nested levels (a
|
|
@@ -4171,7 +4304,18 @@ declare class SqlContext {
|
|
|
4171
4304
|
* it EXPANDS a sorter into concrete terms. Propagates to nested levels (a
|
|
4172
4305
|
* subquery may carry its own sorter), mirroring `filters`.
|
|
4173
4306
|
*/
|
|
4174
|
-
sortSpec?: readonly SortSelectionDef[]
|
|
4307
|
+
sortSpec?: readonly SortSelectionDef[],
|
|
4308
|
+
/**
|
|
4309
|
+
* INTERNAL SYNC converter turning a plain-text semantic term (a `semantic(...)`
|
|
4310
|
+
* literal, or a text-param value) into its pgvector TEXT literal (`[…]`) so it
|
|
4311
|
+
* can be bound + cast `::vector`. Built by `engine.toSQL` from its precomputed
|
|
4312
|
+
* `opts.embeddings` cache (looking each term up + formatting the vector);
|
|
4313
|
+
* throws when the cache lacks the term. Undefined when the caller supplied no
|
|
4314
|
+
* embeddings — a `SemanticExpr` that hits a plain-text term then throws
|
|
4315
|
+
* (rather than emitting the invalid `'<text>'::vector`). Propagated to every
|
|
4316
|
+
* nested level so a subquery's semantic terms resolve too.
|
|
4317
|
+
*/
|
|
4318
|
+
semanticText?: SemanticTextToVector | undefined);
|
|
4175
4319
|
/** The execution-supplied filter expr bound to `source`, or `undefined`. */
|
|
4176
4320
|
filtersFor(source: string): Expr | undefined;
|
|
4177
4321
|
/** Same context with a different scope (same planner / level / root status). */
|
|
@@ -5093,6 +5237,17 @@ declare class Type implements Node {
|
|
|
5093
5237
|
* a clear error. Relations resolve their keys through this.
|
|
5094
5238
|
*/
|
|
5095
5239
|
identityField(): Field;
|
|
5240
|
+
/**
|
|
5241
|
+
* The ordered PRIMARY KEY fields of this Type — generalizing {@link
|
|
5242
|
+
* identityField} to COMPOSITE keys: the single identity field (a single-part
|
|
5243
|
+
* unique index's field, else `id`) when present, else the fields of the first
|
|
5244
|
+
* multi-part UNIQUE index (last part `count === 1`) whose every part is a
|
|
5245
|
+
* field-ref. Relations map their key columns to these; a relation VALUE is
|
|
5246
|
+
* keyed by these field names. Throws when none exists.
|
|
5247
|
+
*/
|
|
5248
|
+
primaryKey(): Field[];
|
|
5249
|
+
/** The single identity field: the first single-part unique index's field, else `id`, else undefined. */
|
|
5250
|
+
private singleIdentity;
|
|
5096
5251
|
/**
|
|
5097
5252
|
* Fields eligible for semantic-aware querying: text fields flagged
|
|
5098
5253
|
* `semantic` or `search`, plus all relation fields (which can drive
|
|
@@ -5421,6 +5576,31 @@ interface CostOptions {
|
|
|
5421
5576
|
/** Execution-time param VALUES, so a param-bound LIMIT / OFFSET resolves in `outputCost`. */
|
|
5422
5577
|
params?: Readonly<Record<string, JsonValue>>;
|
|
5423
5578
|
}
|
|
5579
|
+
/** The dialect-agnostic SQL-emit options common to {@link QueryEngine.toSQL} / {@link QueryEngine.semanticTexts}. */
|
|
5580
|
+
interface BaseSqlOptions {
|
|
5581
|
+
/** Per-Type RLS predicate provider. */
|
|
5582
|
+
rls?: RlsProvider;
|
|
5583
|
+
/** Values for named bind parameters (name → scalar, or a relation `{ pk }` object). */
|
|
5584
|
+
params?: Readonly<Record<string, SqlParamValue>>;
|
|
5585
|
+
/** Execution-time filter predicates per source (authored `ExprDef` or parsed `Expr`). */
|
|
5586
|
+
filters?: Record<string, ExprDef | Expr | null>;
|
|
5587
|
+
/** Execution-time dynamic-sort selection, feeding a SELECT `order`'s `sorter`. */
|
|
5588
|
+
sort?: SortSelectionDef[];
|
|
5589
|
+
/** Emit `COUNT(*) OVER () AS "$total"` on the top-level SELECT. */
|
|
5590
|
+
includeTotal?: boolean;
|
|
5591
|
+
}
|
|
5592
|
+
/** Options for {@link QueryEngine.toSQL}. */
|
|
5593
|
+
interface ToSqlOptions extends BaseSqlOptions {
|
|
5594
|
+
/**
|
|
5595
|
+
* Precomputed text→vector cache (see {@link SemanticEmbeddings}) for every
|
|
5596
|
+
* `semantic(...)` text term — the vectors the caller obtained by embedding the
|
|
5597
|
+
* terms {@link QueryEngine.semanticTexts} returned. Each such term is
|
|
5598
|
+
* looked up here, formatted to pgvector TEXT, and bound (all SYNC). A needed
|
|
5599
|
+
* term ABSENT from the cache throws (never a silently mis-bound
|
|
5600
|
+
* `'<text>'::vector`); an already-`[…]` vector-text term needs no entry.
|
|
5601
|
+
*/
|
|
5602
|
+
embeddings?: SemanticEmbeddings;
|
|
5603
|
+
}
|
|
5424
5604
|
/**
|
|
5425
5605
|
* The query engine: holds the {@link Registry}, exposes type / function lookup,
|
|
5426
5606
|
* and is the entry point for resolve / validate / cost / run / toSQL.
|
|
@@ -5611,17 +5791,57 @@ declare class QueryEngine {
|
|
|
5611
5791
|
* `opts.sort` (an ordered `{ sort, dir? }` list) feeds the `sorter` placeholders
|
|
5612
5792
|
* in a SELECT `order`; `opts.includeTotal` emits the `COUNT(*) OVER () AS
|
|
5613
5793
|
* "$total"` column on the top-level SELECT.
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5794
|
+
*
|
|
5795
|
+
* `opts.embeddings` is a precomputed text→vector cache (see {@link
|
|
5796
|
+
* SemanticEmbeddings}): a `semantic(...)` TEXT literal — or the value of a
|
|
5797
|
+
* `semantic(...)` text PARAM — is looked up there, formatted to a pgvector TEXT
|
|
5798
|
+
* literal (`[…]`), and bound (all synchronous). Obtain the terms to embed with
|
|
5799
|
+
* {@link semanticTexts}, embed them, fill the cache, then call this. A
|
|
5800
|
+
* plain-text semantic term with NO cache — or one MISSING from the cache —
|
|
5801
|
+
* THROWS (rather than emitting the invalid `'<text>'::vector`); a pre-embedded
|
|
5802
|
+
* `[…]` vector-text param is always bound as-is (never looked up).
|
|
5803
|
+
*/
|
|
5804
|
+
toSQL(query: Query | QueryDef, dialect: string | Dialect, opts?: ToSqlOptions): {
|
|
5622
5805
|
sql: string;
|
|
5623
5806
|
params: SqlValue[];
|
|
5624
5807
|
};
|
|
5808
|
+
/**
|
|
5809
|
+
* Extract the DISTINCT plain-text `semantic(...)` terms in `query` (+ the same
|
|
5810
|
+
* execution-time `opts` `toSQL` sees — `filters` / `params` can carry a semantic
|
|
5811
|
+
* text term) that need embedding, in a STABLE (first-seen) order. Give it a
|
|
5812
|
+
* query + params, get back the text to embed: embed each, fill a
|
|
5813
|
+
* {@link SemanticEmbeddings} cache, then pass that as `toSQL`'s `opts.embeddings`.
|
|
5814
|
+
*
|
|
5815
|
+
* Reuses `toSQL`'s exact emit walk (a discarded COLLECTING pass) rather than a
|
|
5816
|
+
* second walker, so it sees precisely the terms `toSQL` would bind. A term
|
|
5817
|
+
* already in pgvector TEXT form (`[…]`) needs no embedding and is NOT returned;
|
|
5818
|
+
* an absent / relation-`{ pk }` param value is not a semantic term and is
|
|
5819
|
+
* skipped.
|
|
5820
|
+
*/
|
|
5821
|
+
semanticTexts(query: Query | QueryDef, opts?: BaseSqlOptions): string[];
|
|
5822
|
+
/**
|
|
5823
|
+
* A dialect for the discarded {@link semanticTexts} pass. The rendered
|
|
5824
|
+
* SQL is thrown away and every dialect drives the same semantic-term walk (a
|
|
5825
|
+
* `semantic(...)` term's query side is emitted — hence collected — regardless of
|
|
5826
|
+
* dialect), so any registered dialect serves; the first is used.
|
|
5827
|
+
*/
|
|
5828
|
+
private collectDialect;
|
|
5829
|
+
/**
|
|
5830
|
+
* Build the INTERNAL sync `semanticText` seam (text → pgvector TEXT) the emit
|
|
5831
|
+
* path threads, from a precomputed {@link SemanticEmbeddings} cache: look the
|
|
5832
|
+
* term up and format its vector with {@link toVectorText}; a term MISSING from
|
|
5833
|
+
* the cache throws the same fail-loud error the emit path would (never a
|
|
5834
|
+
* silently mis-bound `'<text>'::vector`). Returns `undefined` when no cache was
|
|
5835
|
+
* supplied, so a plain-text term then hits the emit path's own "no embeddings"
|
|
5836
|
+
* throw.
|
|
5837
|
+
*/
|
|
5838
|
+
private semanticConverter;
|
|
5839
|
+
/**
|
|
5840
|
+
* Shared SQL-emit core for {@link toSQL} / {@link semanticTexts}: resolve
|
|
5841
|
+
* the dialect, build the root {@link SqlContext} (threading params / filters /
|
|
5842
|
+
* sort / includeTotal + the SYNC `semanticText` converter), and render.
|
|
5843
|
+
*/
|
|
5844
|
+
private emitSQL;
|
|
5625
5845
|
/**
|
|
5626
5846
|
* Parse an execution-time filter map (`source → ExprDef | Expr | null`) into a
|
|
5627
5847
|
* map of bound `Expr`s, dropping `null` / absent entries. A `filters`
|
|
@@ -5659,7 +5879,7 @@ declare class QueryEngine {
|
|
|
5659
5879
|
*/
|
|
5660
5880
|
exprToSQL(expr: Expr | ExprDef, dialect: string | Dialect, opts?: {
|
|
5661
5881
|
rls?: RlsProvider;
|
|
5662
|
-
params?: Readonly<Record<string,
|
|
5882
|
+
params?: Readonly<Record<string, SqlParamValue>>;
|
|
5663
5883
|
filters?: Record<string, ExprDef | Expr | null>;
|
|
5664
5884
|
}): RenderedSql;
|
|
5665
5885
|
}
|
|
@@ -9484,4 +9704,4 @@ declare function parseQueryTool(engine: QueryEngine, raw: unknown, options?: Bui
|
|
|
9484
9704
|
*/
|
|
9485
9705
|
declare function buildQueryTool(engine: QueryEngine, options?: BuildQueryToolOptions): Tool<{}, {}, string, QueryToolInput, Promise<QueryResult>, [], Query>;
|
|
9486
9706
|
|
|
9487
|
-
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 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 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, 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, RelationFieldType, type RelationFieldTypeDef, type RelationJoinOnDef, type RelationJoinSpec, type RelationKey, 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 SelectDef, type SelectFieldDef, SelectQuery, type SelectTypesOptions, type SelectedFunctions, SemanticExpr, type SemanticExprDef, type SemanticQueryDef, 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, 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, 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, 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, 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, plain, pos, querySchema, raw, recordKey, recordSignature, ref, relJoin, 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, typeFromFields, typeMeta, value, variance, week, when, widenNullable, window, withAid, year };
|
|
9707
|
+
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 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 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, 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, RelationFieldType, type RelationFieldTypeDef, type RelationJoinOnDef, type RelationJoinSpec, type RelationKey, 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 SelectDef, type SelectFieldDef, SelectQuery, type SelectTypesOptions, type SelectedFunctions, 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, 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, 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, variance, week, when, widenNullable, window, withAid, year };
|