@aeye/query 0.5.0 → 0.6.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/dist/index.d.ts CHANGED
@@ -30,11 +30,27 @@ type JsonValue = string | number | boolean | null | JsonValue[] | {
30
30
  /** A scalar (leaf) JSON value — the payload of a literal expression and of
31
31
  * filter values. */
32
32
  type ScalarValue = string | number | boolean | null;
33
+ /**
34
+ * One member of a field's CLOSED VALUE SET (see `NumberOptions.values` /
35
+ * `TextFieldTypeDef.values`) — the stored value plus an optional human label.
36
+ *
37
+ * The label rides along with the value deliberately: `FieldDef` already carries
38
+ * a `label` that `describeField` renders, so naming is not foreign to this
39
+ * package, and splitting membership from presentation would put ONE closed set
40
+ * in two places that can drift.
41
+ */
42
+ interface FieldValueDef {
43
+ /** The stored value — one member of the closed set. */
44
+ value: string | number;
45
+ /** Human-facing name for this member (defaults to the value itself). */
46
+ label?: string;
47
+ }
33
48
  /**
34
49
  * Numeric option bag, shared by the `number` field type and by `money`'s
35
50
  * inner numeric configuration.
36
51
  * - `whole` — integral values only.
37
52
  * - `minPlaces` / `maxPlaces` — decimal-place bounds (display / precision).
53
+ * - `values` — a CLOSED SET this column may hold (see below).
38
54
  */
39
55
  interface NumberOptions {
40
56
  min?: number;
@@ -42,6 +58,17 @@ interface NumberOptions {
42
58
  whole?: boolean;
43
59
  minPlaces?: number;
44
60
  maxPlaces?: number;
61
+ /**
62
+ * The closed set of values this column may hold — an enum expressed as a
63
+ * CONSTRAINT ON the underlying scalar rather than as a separate field-type
64
+ * `kind` (which would fork every comparison / SQL-type / value-schema path
65
+ * for what is one extra fact). Three things depend on it and none of them are
66
+ * reachable from outside the library: equality SELECTIVITY becomes a
67
+ * defensible `1/n` instead of the fixed guess, the model-facing description
68
+ * can say `one of a|b|c`, and `toValueSchema()` narrows to the members
69
+ * instead of answering "any number". Composes with `min`/`max`.
70
+ */
71
+ values?: FieldValueDef[];
45
72
  }
46
73
  /** The `number` field type — a numeric value with the shared `NumberOptions`. */
47
74
  interface NumberFieldTypeDef extends NumberOptions {
@@ -63,6 +90,13 @@ interface TextFieldTypeDef {
63
90
  * Default false ⇒ case-insensitive (text operators lower-case both operands).
64
91
  */
65
92
  sensitive?: boolean;
93
+ /**
94
+ * The closed set of values this column may hold — see `NumberOptions.values`
95
+ * for why membership is a query fact. Composes with `pattern`: a regex
96
+ * expresses a SHAPE, a value set expresses MEMBERSHIP, and they are different
97
+ * facts, so both may be declared.
98
+ */
99
+ values?: FieldValueDef[];
66
100
  }
67
101
  /** The `money` field type — a monetary amount plus optional currency. */
68
102
  interface MoneyFieldTypeDef {
@@ -207,6 +241,19 @@ interface TypeDef {
207
241
  description?: string;
208
242
  fields: FieldDef[];
209
243
  indexes?: IndexDef[];
244
+ /**
245
+ * The field (or ordered fields) that IDENTIFY a row. When present it is THE
246
+ * answer for `Type.identityField()` / `Type.primaryKey()`: index ORDER becomes
247
+ * irrelevant, and a unique index on any other column is just a unique index.
248
+ *
249
+ * Without it identity is INFERRED as "the first single-part unique index, else
250
+ * the field named `id`" — which makes the identity of a Type depend on the
251
+ * order its indexes happen to be listed in. A Type declaring both `id` and a
252
+ * unique `email`, with the email index listed first, silently identifies by
253
+ * `email`, and every relation into it then joins a stored id against an email.
254
+ * Declaring it removes that whole class of failure.
255
+ */
256
+ identity?: string | string[];
210
257
  /** Estimated total row count — drives cost estimation. */
211
258
  count: number;
212
259
  /** Estimated average bytes per row (else derived as the sum of the fields' bytes). */
@@ -1063,6 +1110,15 @@ declare abstract class FieldType implements Node {
1063
1110
  * stricter or looser rules.
1064
1111
  */
1065
1112
  comparableWith(other: FieldType): boolean;
1113
+ /**
1114
+ * The fraction of rows a non-indexed EQUALITY predicate on a column of this
1115
+ * type is expected to keep, when the type itself knows better than the
1116
+ * package-wide `EQ_SELECTIVITY` guess. A closed value set of `n` members
1117
+ * answers `1/n`: a two-value flag keeps half the table, a fifty-value code
1118
+ * keeps 2% — today both are costed at the same fixed third. `undefined`
1119
+ * (the default) means "no better estimate; use the fixed one".
1120
+ */
1121
+ eqSelectivity(): number | undefined;
1066
1122
  /**
1067
1123
  * Whether TEXTUAL matching / comparison on a value of this type is
1068
1124
  * CASE-SENSITIVE. Default false (case-insensitive); only `text` fields
@@ -1105,7 +1161,6 @@ declare abstract class FieldType implements Node {
1105
1161
  * getter so a dialect INSTANCE can be registered directly.
1106
1162
  */
1107
1163
 
1108
- /** The abstract SQL-dialect contract; concrete dialects override the engine-specific points. */
1109
1164
  declare abstract class Dialect implements DialectEntry {
1110
1165
  /** The dialect's canonical name (e.g. `'base'`, `'postgres'`). */
1111
1166
  abstract readonly name: string;
@@ -1210,6 +1265,20 @@ declare abstract class Dialect implements DialectEntry {
1210
1265
  /** Shared lateral-join assembly; `on` is the raw ON-condition literal. */
1211
1266
  protected lateralJoinWith(subquery: SqlText, alias: string, joinType: 'left' | 'inner', on: string): SqlText;
1212
1267
  /** The SQL field type for a field type in this dialect. */
1268
+ /**
1269
+ * Build a JSON OBJECT from ordered `key → value` pairs — how a relation's
1270
+ * IDENTITY reaches the result boundary (`{ id: 5 }`, `{ tenantId: 3, userId: 1 }`).
1271
+ *
1272
+ * `json_build_object` is not ANSI, but neither is `json_array_length` which
1273
+ * this base dialect already emits for `arrayLength`: the portable dialect is
1274
+ * portable-ISH, and degrading a structured value to a concatenated string
1275
+ * would be worse than depending on the same JSON support that is already
1276
+ * assumed. Dialects with a richer JSON type override this.
1277
+ */
1278
+ jsonObject(entries: readonly {
1279
+ key: string;
1280
+ value: SqlText;
1281
+ }[]): SqlText;
1213
1282
  abstract sqlTypeFor(fieldType: FieldType): string;
1214
1283
  /**
1215
1284
  * Length (element count) of array expression `arg`. Postgres `cardinality`;
@@ -1294,8 +1363,16 @@ interface RelationResolved {
1294
1363
  readonly keyType: FieldType;
1295
1364
  /** The relation's target Type name (its `to`). */
1296
1365
  readonly to: string;
1297
- /** Cardinality: `1` = belongs-to (single target row), `>1` = has-many (a set). */
1366
+ /** Declared cardinality of the related rows (`1` = one-to-one / belongs-to shaped). */
1298
1367
  readonly count: number;
1368
+ /**
1369
+ * Which side the FOREIGN KEY is on: true = belongs-to, so this row holds the
1370
+ * target's identity locally; false = has-many, a SET keyed on the target.
1371
+ * Read this rather than `count` — a MATERIALIZED INVERSE can carry an
1372
+ * estimated `count` of 1 and is still a has-many (see
1373
+ * `RelationFieldType.isBelongsTo`).
1374
+ */
1375
+ readonly belongsTo: boolean;
1299
1376
  /** The ORDERED join-key pairs (composite-capable) driving relation comparison lowering. */
1300
1377
  readonly keys: readonly RelationKeyPair[];
1301
1378
  }
@@ -1357,6 +1434,20 @@ declare function sourcesOf(rt: ResolvedType): readonly FieldResolved[];
1357
1434
  declare function widenNullable(rt: ResolvedType, nullable?: boolean): ResolvedType;
1358
1435
  /** Type guard: a resolved type. */
1359
1436
  declare function isType(rt: ResolvedType): rt is TypeResolved;
1437
+ /**
1438
+ * The relation info when `rt` is a Type resolved from a relation FIELD-REF
1439
+ * (a belongs-to / has-many field), else `undefined`. Used by the scalar
1440
+ * operators to reject a relation used as a value and to allow (and key-compare)
1441
+ * a relation-vs-relation comparison.
1442
+ */
1443
+ declare function relationOf(rt: ResolvedType): RelationResolved | undefined;
1444
+ /**
1445
+ * The comparable-VALUE field type of a resolved value: its scalar field type,
1446
+ * else — for a relation Type — the relation's key value type. Used to type a
1447
+ * bind param compared against the operand (a relation compares by its FK key).
1448
+ * A non-relation whole Type has none.
1449
+ */
1450
+ declare function valueFieldType(rt: ResolvedType): FieldType | undefined;
1360
1451
  /** Type guard: a resolved scalar (field or computed value, never a type). */
1361
1452
  declare function isScalar(rt: ResolvedType): rt is FieldResolved | ComputedResolved;
1362
1453
 
@@ -1960,8 +2051,8 @@ interface ResolvedRelationOn {
1960
2051
  *
1961
2052
  * CONVENTION: a relation field's NAME is the key for all purposes. There are
1962
2053
  * no exposed foreign-key fields — `owns` (FK on THIS type, "belongs-to") is
1963
- * INFERRED as `count === 1`; `count > 1` ⇒ has-many (FK on the target). See
1964
- * `resolveKey`.
2054
+ * INFERRED as `count === 1` AND no `inverseVia` (see `isBelongsTo`); otherwise
2055
+ * has-many (FK on the target). See `resolveKey`.
1965
2056
  *
1966
2057
  * `inverseRelation`, when set on a belongs-to relation, asks the registry to
1967
2058
  * materialize a one-to-many relation of that name back on the TARGET Type.
@@ -1995,14 +2086,29 @@ declare class RelationFieldType extends FieldType {
1995
2086
  static from(json: FieldTypeDef): RelationFieldType;
1996
2087
  /** The Zod schema for this field type's JSON def. */
1997
2088
  static toSchema(): z.ZodTypeAny;
2089
+ /**
2090
+ * True when the FOREIGN KEY lives on THIS Type — a declared belongs-to. The
2091
+ * cardinality alone is NOT the discriminator: a MATERIALIZED INVERSE (one
2092
+ * carrying {@link inverseVia}) is never belongs-to however its estimated
2093
+ * `count` came out, because `Registry.finalize()` derives that count from a
2094
+ * ROW RATIO (`round(source.count / target.count)`) — so a 1:1 pair, or two
2095
+ * unmeasured Types sharing one declared row estimate, legitimately yields 1.
2096
+ *
2097
+ * Reading `count === 1` alone made such an inverse resolve its join as
2098
+ * `order.invoice = invoice.id`, where `order.invoice` is the SYNTHETIC
2099
+ * relation field the registry just added rather than a column — every
2100
+ * traversal then matched zero rows, silently. The FK side is knowable from
2101
+ * `inverseVia`; this is where that knowledge is applied.
2102
+ */
2103
+ isBelongsTo(): boolean;
1998
2104
  /**
1999
2105
  * Resolve the join key for this relation, given the relation field's NAME and
2000
2106
  * the two Types it relates. The relation field's NAME is the key:
2001
- * - belongs-to (`count === 1`): `this.<relName> = target.<identity>` —
2107
+ * - belongs-to ({@link isBelongsTo}): `this.<relName> = target.<identity>` —
2002
2108
  * the local relation field holds the target's identity value.
2003
- * - has-many (`count > 1`): `this.<identity> = target.<fk>` — where the
2004
- * FK on the target is `inverseVia` (for a materialized inverse) else the
2005
- * declaring Type's name in camelCase.
2109
+ * - has-many: `this.<identity> = target.<fk>` — where the FK on the target
2110
+ * is `inverseVia` (for a materialized inverse) else the declaring Type's
2111
+ * name in camelCase.
2006
2112
  */
2007
2113
  resolveKey(relationFieldName: string, thisType: Type, targetType: Type): RelationKey;
2008
2114
  /**
@@ -2025,7 +2131,7 @@ declare class RelationFieldType extends FieldType {
2025
2131
  * source, `targetAlias` = the target), so aliased / self-joins resolve.
2026
2132
  *
2027
2133
  * The backing lives on the OWNING (belongs-to) relation. A materialized
2028
- * inverse has-many (`count > 1` with an `inverseVia`) REUSES the SAME FK: its
2134
+ * inverse has-many (one carrying an `inverseVia`) REUSES the SAME FK: its
2029
2135
  * forward relation's `relation` backing on the target Type, with the key
2030
2136
  * orientation SWAPPED (the declaring side is now the join's target). A
2031
2137
  * directly-declared has-many (no `inverseVia`) has no forward relation to
@@ -2080,12 +2186,42 @@ declare class FieldRefExpr extends Expr {
2080
2186
  private resolveRelation;
2081
2187
  /** Validate the source resolves to a type and has the named field; report problems. */
2082
2188
  validateWalk(engine: QueryEngine, scope: QueryScope, p: Problems, ctx: ValidateContext): ResolvedType;
2189
+ /**
2190
+ * Report the relation-as-value problem for this position, if any. Split into
2191
+ * three distinct outcomes because they have three different fixes:
2192
+ * - an identity-value position + a BELONGS-TO ⇒ fine, it has a local key;
2193
+ * - an identity-value position + a HAS-MANY ⇒ there is no key on this row at
2194
+ * all and its "value" is a set, so say that instead of the join-it hint;
2195
+ * - inside an AGGREGATE ⇒ an identity is not summable/averageable/max-able
2196
+ * under any representation, so say that;
2197
+ * - anywhere else ⇒ the long-standing "join it" hint.
2198
+ */
2199
+ private checkRelationUse;
2083
2200
  /** Zero rows; cost is just the resolved field's byte size. */
2084
2201
  cost(ctx: CostContext, scope: QueryScope): Cost;
2085
2202
  /** A field-ref IS a plain column reference (drives GROUP BY / index-key costing). */
2086
2203
  fieldRef(): FieldRefExpr;
2087
2204
  /** Read the field's runtime value, honoring backing (joins/compute/access security). */
2088
2205
  evaluate(ctx: RuntimeContext, row: SourceRow | null): Promise<Value>;
2206
+ /**
2207
+ * Read this ref as a plain COLUMN, skipping the relation-identity projection.
2208
+ *
2209
+ * Needed because a belongs-to's local key column and the relation FIELD share
2210
+ * a name under the package's name convention (`order.userId` is both the
2211
+ * relation and the column holding its key). Every internal reader of a key
2212
+ * column — relation comparison lowering, ORDER BY / GROUP BY expansion, an
2213
+ * `IN` against a scalar subquery — wants the COLUMN; going through
2214
+ * {@link evaluate} would resolve the relation again and hand back the identity
2215
+ * object. Backing (compute / lateral / stored-name remap / access) still
2216
+ * applies exactly as it does for any other column.
2217
+ */
2218
+ columnValue(ctx: RuntimeContext, row: SourceRow | null): Promise<Value>;
2219
+ /**
2220
+ * Apply this field's `access` backing (FLS) to an already-computed value: a
2221
+ * denied field reads NULL. Shared by the relation-identity path, which
2222
+ * bypasses the stored/compute/lateral resolution but must not bypass security.
2223
+ */
2224
+ private securedRun;
2089
2225
  /** Read a stored field off the bound record, attaching the conceptual field's metadata. */
2090
2226
  private storedValue;
2091
2227
  /**
@@ -2102,6 +2238,18 @@ declare class FieldRefExpr extends Expr {
2102
2238
  private attachRelationRun;
2103
2239
  /** Emit as a SqlText column ref, lowering backing (joins/compute/access) when present. */
2104
2240
  toSQL(dialect: Dialect, ctx: SqlContext): SqlText;
2241
+ /**
2242
+ * Emit this ref as a plain COLUMN, skipping the relation-identity projection —
2243
+ * the SQL twin of {@link columnValue}, and needed for the same reason (a
2244
+ * belongs-to's key column shares the relation field's name).
2245
+ */
2246
+ columnSQL(dialect: Dialect, ctx: SqlContext): SqlText;
2247
+ /**
2248
+ * Apply this field's `access` backing (FLS) to an already-emitted fragment —
2249
+ * the SQL twin of {@link securedRun}, so a relation identity is secured by the
2250
+ * same rule as any other column.
2251
+ */
2252
+ private securedSql;
2105
2253
  /**
2106
2254
  * Register every named join this field opts into with the planner (SQL),
2107
2255
  * deduped on the join's deterministic alias so N fields sharing a join emit
@@ -2661,8 +2809,20 @@ declare class ComparisonExpr extends BoolExpr {
2661
2809
  * equality and the equality-like ops (`= <> like notLike ilike`) keep ~a third.
2662
2810
  * An index-covered `=` is discounted separately by the cost model (via
2663
2811
  * {@link indexProbe}); this is the non-indexed fallback.
2812
+ *
2813
+ * An `=` against a column whose field type declares a CLOSED VALUE SET uses
2814
+ * that type's own `1/n` instead of the fixed third — the one case where the
2815
+ * schema knows the real answer (`FieldType.eqSelectivity`).
2664
2816
  */
2665
- selectivity(): number;
2817
+ selectivity(ctx: CostContext, scope: QueryScope): number;
2818
+ /**
2819
+ * The `1/n` an operand's declared closed value set implies, or `undefined`
2820
+ * when neither side declares one. Both operands are consulted so
2821
+ * `:param = order.status` costs the same as `order.status = :param`; when both
2822
+ * declare a set the TIGHTER (smaller) estimate wins, since satisfying both
2823
+ * memberships can only narrow further.
2824
+ */
2825
+ private closedSetSelectivity;
2666
2826
  /** An `=` against a column is an index point-probe (arity 1); other ops are not. */
2667
2827
  indexProbe(): IndexProbe | undefined;
2668
2828
  /** Evaluate under 3VL: a NULL operand yields UNKNOWN; text compares case-insensitively unless a `sensitive` field is involved. */
@@ -2896,7 +3056,17 @@ declare class IsNullExpr extends BoolExpr {
2896
3056
  selectivity(): number;
2897
3057
  /** Evaluate the operand and return whether it is (not) null. */
2898
3058
  evaluateBool(ctx: RuntimeContext, row: SourceRow, group?: readonly SourceRow[]): Promise<boolean>;
2899
- /** Emit as a SqlText fragment (`value IS [NOT] NULL`). */
3059
+ /**
3060
+ * Emit as a SqlText fragment (`value IS [NOT] NULL`).
3061
+ *
3062
+ * A RELATION operand tests its KEY COLUMNS, not the assembled identity
3063
+ * object: the object is a constructed value and is never SQL NULL, so
3064
+ * `json_build_object(...) IS NULL` would be a constant false. Unset means any
3065
+ * key column is null (a partial composite key cannot join), so `IS NULL` is
3066
+ * the OR over them and `IS NOT NULL` the AND of their negations — which also
3067
+ * keeps the predicate index-usable. Matches the runtime, where a relation
3068
+ * ref with any null key evaluates to NULL.
3069
+ */
2900
3070
  toSQL(dialect: Dialect, ctx: SqlContext): SqlText;
2901
3071
  /** Serialize back to its JSON ExprDef. */
2902
3072
  toJSON(): IsNullExprDef;
@@ -4645,6 +4815,18 @@ interface RelationBacking {
4645
4815
  /** A dynamic, alias-correct custom `ON` (overrides `keys`). See {@link RelationOn}. */
4646
4816
  on?: RelationOn;
4647
4817
  }
4818
+ /**
4819
+ * Map a `RelationBacking`'s declared `keys` to ON column pairs ORIENTED to a
4820
+ * join's source (left) + target aliases. `forward` = the join goes the
4821
+ * belongs-to direction (the source alias is the declaring side); when `false`
4822
+ * (a has-many inverse reusing the forward FK) the orientation is swapped.
4823
+ * `targetIdentity` supplies the default column for any pair that omits `foreign`
4824
+ * (the belongs-to TARGET's identity field).
4825
+ */
4826
+ declare function relationKeyColumns(keys: ReadonlyArray<{
4827
+ local: string;
4828
+ foreign?: string;
4829
+ }>, forward: boolean, targetIdentity: string): RelationOnPair[];
4648
4830
  /**
4649
4831
  * The dev-side backing for a whole Type. All members are optional:
4650
4832
  * - `name` is the real underlying source name (default = the Type name); SQL
@@ -4891,6 +5073,13 @@ interface DefaultOrder {
4891
5073
  /** Which SELECTs receive this order (default `'result'`). */
4892
5074
  applyTo?: DefaultOrderScope;
4893
5075
  }
5076
+ /** The direction + NULLs placement of a resolved default-order term. */
5077
+ interface DefaultOrderDir {
5078
+ /** Sort direction (a term's `dir`, defaulted to `'asc'`). */
5079
+ readonly dir: 'asc' | 'desc';
5080
+ /** Explicit NULLs placement, or `undefined` for the direction-based default. */
5081
+ readonly nulls: 'first' | 'last' | undefined;
5082
+ }
4894
5083
  /** The SQL-mode resolution of a `JoinBacking` (`sql` raw fragment, else a `JoinSpec`). */
4895
5084
  type JoinSqlPlan = {
4896
5085
  readonly kind: 'none';
@@ -5087,6 +5276,25 @@ declare class Field implements Node {
5087
5276
  * to `JsonValue` by the annotation.
5088
5277
  */
5089
5278
  declare function exprDigest(expr: ExprDef): string;
5279
+ /**
5280
+ * Rewrite every `field-ref` whose `source` is `from` to `to`, leaving every
5281
+ * other node untouched. Round-trips through JSON (so the result is a plain,
5282
+ * independently-owned def) — the same `JSON.parse`-annotated idiom
5283
+ * {@link exprDigest} uses, no casts.
5284
+ */
5285
+ declare function renameSource(expr: ExprDef, from: string, to: string): ExprDef;
5286
+ /**
5287
+ * The digest an ALIASED usage of `expr` matches an index part on.
5288
+ *
5289
+ * An index part is a TYPE-level fact, so it is necessarily written against the
5290
+ * Type NAME (`IndexPartDef.expr` is an `ExprDef`, and a `field-ref` requires a
5291
+ * `source`). A QUERY may bind that same Type under an alias — `FROM user AS u`,
5292
+ * or either side of a self-join — and then its refs read `u.email`, whose raw
5293
+ * digest can never equal the part's `user.email`. Normalizing the USAGE back to
5294
+ * the Type name is what lets a declared index actually apply; the stored part
5295
+ * digest ({@link IndexPart.digest}) is deliberately left exactly as it is.
5296
+ */
5297
+ declare function aliasedDigest(expr: ExprDef, alias: string, typeName: string): string;
5090
5298
  /** One ordered part of a composite index: an expr + its prefix cardinality. */
5091
5299
  declare class IndexPart {
5092
5300
  /** The indexed expression, stored as raw JSON this phase. */
@@ -5137,10 +5345,19 @@ declare class Index {
5137
5345
  * Because part counts are non-increasing, a longer matched prefix always
5138
5346
  * yields a smaller (or equal) estimate — so this returns the tightest bound
5139
5347
  * the supplied predicates can achieve via this index.
5348
+ *
5349
+ * `alias` names the SOURCE the supplied usages are bound under together with
5350
+ * the TYPE this index belongs to; when they differ, each usage is normalized
5351
+ * back to the type name before matching (see {@link aliasedDigest}). Omitting
5352
+ * it keeps the literal, un-normalized match — the identity case, and what
5353
+ * every pre-existing caller gets.
5140
5354
  */
5141
5355
  prefixReduction(used: ReadonlyArray<{
5142
5356
  toJSON(): ExprDef;
5143
- }>): number | undefined;
5357
+ }>, alias?: {
5358
+ source: string;
5359
+ typeName: string;
5360
+ }): number | undefined;
5144
5361
  /** Build an Index from its `IndexDef` JSON. */
5145
5362
  static from(json: IndexDef): Index;
5146
5363
  /** Serialize to its `IndexDef` JSON shape (emitting `bytes` only when authored explicitly). */
@@ -5168,6 +5385,12 @@ interface TypeSpec {
5168
5385
  fields: Field[];
5169
5386
  /** The (composite) indexes declared on this Type. */
5170
5387
  indexes: Index[];
5388
+ /**
5389
+ * The field (or ordered fields) that IDENTIFY a row. When set it is THE
5390
+ * answer for {@link Type.identityField} / {@link Type.primaryKey} and index
5391
+ * order stops mattering. Omit to fall back to the inferred rule.
5392
+ */
5393
+ identity?: string | string[];
5171
5394
  /** Estimated row count. */
5172
5395
  count: number;
5173
5396
  /**
@@ -5206,6 +5429,12 @@ declare class Type implements Node {
5206
5429
  readonly fields: Field[];
5207
5430
  /** The (composite) indexes declared on this Type. */
5208
5431
  readonly indexes: Index[];
5432
+ /**
5433
+ * The DECLARED identity field names, in key order — normalized from the spec's
5434
+ * `string | string[]`. `undefined` means identity is INFERRED (first
5435
+ * single-part unique index, else `id`), which is index-order dependent.
5436
+ */
5437
+ readonly identity?: readonly string[];
5209
5438
  /** Estimated total row count (drives cost estimation). */
5210
5439
  readonly count: number;
5211
5440
  /** Estimated average bytes per row (drives byte-cost estimation). */
@@ -5232,31 +5461,76 @@ declare class Type implements Node {
5232
5461
  textFields(): Field[];
5233
5462
  /**
5234
5463
  * The IDENTITY field used as the join key on this Type's side of a relation:
5235
- * the field referenced by the first single-part UNIQUE index (one part,
5236
- * `count === 1`, whose expr is a field-ref), else the field named `id`, else
5237
- * a clear error. Relations resolve their keys through this.
5464
+ * the DECLARED `identity` when it names exactly one field, else the field
5465
+ * referenced by the first single-part UNIQUE index (one part, `count === 1`,
5466
+ * whose expr is a field-ref), else the field named `id`, else a clear error.
5467
+ * Relations resolve their keys through this.
5238
5468
  */
5239
5469
  identityField(): Field;
5240
5470
  /**
5241
5471
  * 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.
5472
+ * identityField} to COMPOSITE keys: the DECLARED `identity` when set, else the
5473
+ * single identity field (a single-part unique index's field, else `id`), else
5474
+ * the fields of the first multi-part UNIQUE index (last part `count === 1`)
5475
+ * whose every part is a field-ref. Relations map their key columns to these; a
5476
+ * relation VALUE is keyed by these field names. Throws when none exists.
5247
5477
  */
5248
5478
  primaryKey(): Field[];
5249
- /** The single identity field: the first single-part unique index's field, else `id`, else undefined. */
5479
+ /**
5480
+ * The fields named by an explicit `identity` declaration, in key order, or
5481
+ * `undefined` when none is declared. A declared name that is not a field on
5482
+ * this Type is an ERROR rather than a silent fall-back to the inferred rule —
5483
+ * falling back would reintroduce exactly the index-order dependence the
5484
+ * declaration exists to remove, and would do it invisibly.
5485
+ */
5486
+ private declaredIdentity;
5487
+ /**
5488
+ * The single identity field: the DECLARED `identity` when it is exactly one
5489
+ * field, else the first single-part unique index's field, else `id`, else
5490
+ * undefined. A declared COMPOSITE identity has no single field, so it yields
5491
+ * `undefined` here and is answered by {@link primaryKey}.
5492
+ */
5250
5493
  private singleIdentity;
5251
5494
  /**
5252
- * Fields eligible for semantic-aware querying: text fields flagged
5253
- * `semantic` or `search`, plus all relation fields (which can drive
5254
- * cross-entity semantic joins).
5495
+ * Fields eligible for semantic-aware querying: text fields flagged `semantic`
5496
+ * or `search`.
5497
+ *
5498
+ * Relation fields are NOT included. They used to be — on the theory that they
5499
+ * could drive cross-entity semantic joins — which made almost every Type
5500
+ * report itself semantic-eligible on the strength of having a foreign key, and
5501
+ * a whole-source semantic score then silently ran over a Type nobody had
5502
+ * declared semantic. A relation is a join, not an embedding.
5255
5503
  */
5256
5504
  semanticFields(): Field[];
5257
- /** Whether this Type is eligible for embedding-based semantic similarity. */
5505
+ /**
5506
+ * Whether ONE field is declared semantic-eligible: a text field flagged
5507
+ * `semantic` (or `search`, whose index is the same kind of derived artifact).
5508
+ */
5509
+ isFieldSemantic(field: Field): boolean;
5510
+ /**
5511
+ * Whether semantic scoring is possible ANYWHERE on this Type — the whole type
5512
+ * is flagged, or at least one field is. This is the ELIGIBILITY question
5513
+ * (does the `semantic` expr apply to this Type at all), which is what schema
5514
+ * gating and the capability description ask.
5515
+ *
5516
+ * What an UNNARROWED score reads is the row's embedding over
5517
+ * {@link semanticFields}, which no longer counts relation fields — so a Type
5518
+ * whose only "evidence" was owning a foreign key is no longer eligible at
5519
+ * all. See {@link isFieldSemantic} for the per-field question.
5520
+ */
5258
5521
  isSemantic(): boolean;
5259
- /** Whether this Type is eligible for full-text search. */
5522
+ /** Whether ONE field is declared full-text searchable. */
5523
+ isFieldSearchable(field: Field): boolean;
5524
+ /**
5525
+ * Whether full-text search is possible ANYWHERE on this Type — the whole type
5526
+ * is flagged, or at least one field is. The ELIGIBILITY question, used for
5527
+ * schema gating and the capability description.
5528
+ *
5529
+ * It is NOT the answer to "can this type be searched WITHOUT naming a field":
5530
+ * that needs a `SearchBacking` (the searchable document), whose absence is now
5531
+ * refused as `text-search.unbacked` rather than guessed at. See
5532
+ * {@link isFieldSearchable} for the per-field question.
5533
+ */
5260
5534
  isSearchable(): boolean;
5261
5535
  /** Build a Type from its JSON, parsing fields/indexes via `registry`. */
5262
5536
  static from(json: TypeDef, registry: Registry): Type;
@@ -6503,16 +6777,30 @@ interface ValidateContext {
6503
6777
  */
6504
6778
  readonly fieldExprKind?: ExprKind;
6505
6779
  /**
6506
- * Set by the FK-comparison operators (`comparison` / `in` / `between` /
6507
- * `binary`) when validating an operand, to permit a RELATION field-ref there
6508
- * (those operators compare two relations by FK key / reject relation-vs-scalar
6509
- * themselves). Everywhere else it is unset, so a bare relation field-ref used
6510
- * as a scalar VALUE (a select field, aggregate/window value, `partitionBy`,
6511
- * `orderBy`, group-by key, function arg) is a `ref.relation-not-value` error —
6512
- * a relation is a whole related row (possibly composite-keyed), never a value.
6780
+ * How a RELATION field-ref is allowed to be used at this position, if at all:
6781
+ *
6782
+ * - `'compare'` — set by the FK-comparison operators (`comparison` / `in` /
6783
+ * `between` / `binary`), which handle the relation THEMSELVES: a belongs-to
6784
+ * compares by key columns, a has-many by membership, and a
6785
+ * relation-vs-scalar is rejected by the operator.
6786
+ * - `'value'` — set where a relation's IDENTITY is a well-defined value: a
6787
+ * select field / RETURNING, an ORDER BY term, a GROUP BY key, a null test.
6788
+ * Only a BELONGS-TO has one (the key lives on this row); a has-many is a
6789
+ * SET and is refused with a message that says so.
6790
+ * - unset — a relation is not a value here at all (a function argument, a
6791
+ * `case` arm, an arithmetic operand, an aggregate), and a bare relation
6792
+ * field-ref is an error.
6793
+ *
6794
+ * Set ONLY for a DIRECT field-ref operand (see `_field-guard.ts`), so it never
6795
+ * leaks down into a nested expression that would not have earned it.
6513
6796
  */
6514
- readonly relationValueOk?: boolean;
6797
+ readonly relationUse?: RelationUse;
6515
6798
  }
6799
+ /**
6800
+ * How a RELATION field-ref may be used at a given validation position — see
6801
+ * `ValidateContext.relationUse`.
6802
+ */
6803
+ type RelationUse = 'compare' | 'value';
6516
6804
  /** The default top-level context: a bare expression may aggregate freely. */
6517
6805
  declare const ROOT_VALIDATE_CONTEXT: ValidateContext;
6518
6806
  /**
@@ -7365,6 +7653,8 @@ declare class NumberFieldType extends FieldType {
7365
7653
  static toSchema(): z.ZodTypeAny;
7366
7654
  /** Resolve to the `number` scalar comparison category. */
7367
7655
  resolve(): ScalarKind;
7656
+ /** A declared closed set of `n` members makes `= x` a `1/n` predicate. */
7657
+ eqSelectivity(): number | undefined;
7368
7658
  /** Estimated average stored byte size. */
7369
7659
  avgBytes(): number;
7370
7660
  /** SQL column type (`integer` when whole, else `numeric`). */
@@ -7373,7 +7663,7 @@ declare class NumberFieldType extends FieldType {
7373
7663
  toValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
7374
7664
  /** Serialize to its JSON def (flattening the compacted options). */
7375
7665
  toJSON(): NumberFieldTypeDef;
7376
- /** A copy of this field type (cloning the options bag). */
7666
+ /** A copy of this field type (deep-cloning the options bag's value set). */
7377
7667
  clone(): NumberFieldType;
7378
7668
  }
7379
7669
 
@@ -7391,6 +7681,8 @@ interface TextOptions {
7391
7681
  search?: boolean;
7392
7682
  /** When true, text matching is case-sensitive (default: case-insensitive). */
7393
7683
  sensitive?: boolean;
7684
+ /** The closed set of values this column may hold (see `NumberOptions.values`). */
7685
+ values?: FieldValueDef[];
7394
7686
  }
7395
7687
  /**
7396
7688
  * TextFieldType — a string field with optional length / pattern constraints,
@@ -7421,15 +7713,17 @@ declare class TextFieldType extends FieldType {
7421
7713
  static toSchema(): z.ZodTypeAny;
7422
7714
  /** Resolve to the `text` scalar comparison category. */
7423
7715
  resolve(): ScalarKind;
7716
+ /** A declared closed set of `n` members makes `= x` a `1/n` predicate. */
7717
+ eqSelectivity(): number | undefined;
7424
7718
  /** Estimated average stored byte size (half the max length, else 32). */
7425
7719
  avgBytes(): number;
7426
7720
  /** SQL column type (`varchar(n)` when bounded, else `text`). */
7427
7721
  toSQLType(): string;
7428
- /** Zod schema validating a string, honoring length / pattern options. */
7722
+ /** Zod schema validating a string, honoring the closed value set else length / pattern options. */
7429
7723
  toValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
7430
7724
  /** Serialize to its JSON def (flattening the compacted options). */
7431
7725
  toJSON(): TextFieldTypeDef;
7432
- /** A copy of this field type (cloning the options bag). */
7726
+ /** A copy of this field type (deep-cloning the options bag's value set). */
7433
7727
  clone(): TextFieldType;
7434
7728
  }
7435
7729
 
@@ -8340,7 +8634,12 @@ declare class SelectQuery extends Query {
8340
8634
  private fromSQL;
8341
8635
  /** One ORDER BY clause `<key> ASC|DESC [NULLS FIRST|LAST]` from a resolved key + dir/nulls. */
8342
8636
  private orderClauseSQL;
8343
- /** One ORDER BY term: `<expr> ASC|DESC [NULLS FIRST|LAST]`. */
8637
+ /**
8638
+ * One ORDER BY term: `<expr> ASC|DESC [NULLS FIRST|LAST]`. A RELATION term
8639
+ * expands to ONE clause per key column (each inheriting the term's direction
8640
+ * and NULLs placement) — lexicographic over the declared key order, and
8641
+ * index-usable, where sorting the assembled JSON object would be neither.
8642
+ */
8344
8643
  private orderTermSQL;
8345
8644
  /**
8346
8645
  * Emit the SELECT. A SELECT never prepends its own `WITH` (relation crossings
@@ -9038,6 +9337,16 @@ declare class PostgresDialect extends BaseDialect {
9038
9337
  * text-search config defaulting to `'english'`.
9039
9338
  */
9040
9339
  tsvectorSearch(tsv: SqlText, query: SqlText, language?: string): SqlText;
9340
+ /**
9341
+ * `jsonb_build_object` rather than the base `json_build_object`: `jsonb` has
9342
+ * equality and ordering operators, so a projected identity can also be
9343
+ * DISTINCTed or compared, where a `json` value cannot be (Postgres has no
9344
+ * equality operator for `json` at all).
9345
+ */
9346
+ jsonObject(entries: readonly {
9347
+ key: string;
9348
+ value: SqlText;
9349
+ }[]): SqlText;
9041
9350
  /** Cast the query param to the pgvector type so `similarity` type-checks (`<param>::vector`). */
9042
9351
  queryVectorParam(param: SqlText): SqlText;
9043
9352
  /**
@@ -9230,17 +9539,30 @@ interface DrillDownFailure {
9230
9539
  type DrillDownResult = DrillDownSuccess | DrillDownFailure;
9231
9540
  /**
9232
9541
  * A successful `drillDownInto`: the rebuilt query plus the EXTRACTED param
9233
- * VALUE map (each drill param's name → the scalar pulled from the group row),
9542
+ * VALUE map (each drill param's name → the value pulled from the group row),
9234
9543
  * ready for `engine.run(query, { params })`.
9235
9544
  */
9236
9545
  interface DrillDownIntoSuccess {
9237
9546
  /** The un-ravelled SELECT returning the underlying rows. */
9238
9547
  query: SelectQuery;
9239
- /** Bind-param values pulled from the group row (param name → scalar). */
9240
- params: Record<string, ScalarValue>;
9548
+ /**
9549
+ * Bind-param values pulled from the group row (param name → value). Usually a
9550
+ * scalar; a group key that is a RELATION carries that relation's IDENTITY
9551
+ * object (`{ id: 5 }`), which is exactly the shape the rebuilt query's
9552
+ * relation comparison binds.
9553
+ */
9554
+ params: Record<string, DrillValue>;
9241
9555
  /** Non-fatal notes carried over from `drillDown`. */
9242
9556
  warnings: Problems;
9243
9557
  }
9558
+ /**
9559
+ * A value a drill param can carry: a scalar, or the IDENTITY OBJECT of a
9560
+ * relation group key (keyed by the target's identity field names — see the
9561
+ * relation comparison lowering, which accepts exactly this shape).
9562
+ */
9563
+ type DrillValue = ScalarValue | {
9564
+ [key: string]: ScalarValue;
9565
+ };
9244
9566
  /**
9245
9567
  * Un-ravel an aggregating SELECT into a reusable query over the underlying
9246
9568
  * rows: pin each group key to a fresh bind param, replace each aggregate with
@@ -9704,4 +10026,4 @@ declare function parseQueryTool(engine: QueryEngine, raw: unknown, options?: Bui
9704
10026
  */
9705
10027
  declare function buildQueryTool(engine: QueryEngine, options?: BuildQueryToolOptions): Tool<{}, {}, string, QueryToolInput, Promise<QueryResult>, [], Query>;
9706
10028
 
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 };
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 };