@aeye/query 0.6.5 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -5
- package/aeye-query.md +540 -303
- package/dist/index.d.ts +3314 -166
- package/dist/index.js +8201 -4169
- package/package.json +57 -51
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,123 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { Tool } from '@aeye/core';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* TEXT CASING — how a textual comparison treats letter case, and WHO performs
|
|
6
|
+
* the folding.
|
|
7
|
+
*
|
|
8
|
+
* Two facts hide inside "case-insensitive matching", and collapsing them into a
|
|
9
|
+
* boolean is what made the old `sensitive` flag unable to express a real
|
|
10
|
+
* deployment:
|
|
11
|
+
*
|
|
12
|
+
* 1. **What the comparison MEANS** — does `'Ada' = 'ada'` hold? This is a
|
|
13
|
+
* semantic of the query, so it must hold identically in BOTH roads (the
|
|
14
|
+
* in-memory runtime and the emitted SQL); the package tests that agreement
|
|
15
|
+
* explicitly (`runtime-sql-agreement.test.ts`).
|
|
16
|
+
* 2. **WHO implements the fold in SQL** — this package, by wrapping both
|
|
17
|
+
* operands in `LOWER(...)`, or the COLUMN's own collation. A column declared
|
|
18
|
+
* `citext`, or with a non-deterministic (`deterministic = false`) collation,
|
|
19
|
+
* or on an engine whose default collation is case-insensitive (SQL Server's
|
|
20
|
+
* usual `*_CI_*`), already compares case-insensitively — so `LOWER()` there
|
|
21
|
+
* buys nothing and costs everything: it is not sargable, so every predicate
|
|
22
|
+
* over the column stops using its index.
|
|
23
|
+
*
|
|
24
|
+
* The cost is not only an index. `LOWER()` is a TEXT function, and this package
|
|
25
|
+
* knows a column's LOGICAL type, never its physical one — a uuid-valued
|
|
26
|
+
* identifier is honestly modelled as `text` (it is compared and rendered as
|
|
27
|
+
* text), but on PostgreSQL `LOWER(uuid)` is `function lower(uuid) does not
|
|
28
|
+
* exist`. A consumer measured exactly that: every row-security predicate
|
|
29
|
+
* comparing a `uuid` owner column to the caller's id failed outright, so a
|
|
30
|
+
* default meant to be forgiving produced SQL that could not run.
|
|
31
|
+
*
|
|
32
|
+
* Hence three states, not a flag. Each has a distinct pair of behaviours, so
|
|
33
|
+
* none is a synonym for another:
|
|
34
|
+
*
|
|
35
|
+
* | casing | means | SQL for `a = b` | in-memory runtime |
|
|
36
|
+
* |--------------|------------------------------------|-------------------------|-------------------|
|
|
37
|
+
* | `'fold'` | insensitive, THIS PACKAGE folds | `LOWER(a) = LOWER(b)` | folds |
|
|
38
|
+
* | `'collated'` | insensitive, the COLUMN's collation folds | `a = b` | folds |
|
|
39
|
+
* | `'exact'` | case-sensitive | `a = b` | compares as-is |
|
|
40
|
+
*
|
|
41
|
+
* `'collated'` is the state that makes the owner's case expressible truthfully:
|
|
42
|
+
* it keeps the MEANING insensitive (so the runtime still folds, and a query
|
|
43
|
+
* means one thing wherever it runs) while emitting a bare, index-usable
|
|
44
|
+
* comparison. It is a CLAIM ABOUT THE STORE, and an unverifiable one — this
|
|
45
|
+
* package cannot read a column's collation — so declaring it over a
|
|
46
|
+
* case-sensitive column is the one way to make the two roads disagree. That is
|
|
47
|
+
* the trade for expressing the fact at all, and it is why it is not the default.
|
|
48
|
+
*
|
|
49
|
+
* WHERE THE POLICY LIVES, and why it is not the Dialect. A casing is resolved
|
|
50
|
+
* from the FIELD's own declaration when it makes one, and otherwise from
|
|
51
|
+
* {@link QueryEngine.textCasing}. The engine is deliberate: it is the only layer
|
|
52
|
+
* BOTH roads can see (`SqlContext.engine` and `RuntimeContext.engine`), whereas
|
|
53
|
+
* a `Dialect` is an argument to `toSQL` and is absent from the runtime entirely
|
|
54
|
+
* — so a dialect-level default could only ever govern half of a semantic that
|
|
55
|
+
* has to hold in both halves. Collation is genuinely a property of a COLUMN, so
|
|
56
|
+
* the per-field declaration is the precise place to state it; the engine default
|
|
57
|
+
* exists so a deployment whose columns are uniform says it once instead of on
|
|
58
|
+
* every declaration.
|
|
59
|
+
*/
|
|
60
|
+
/** The casing policies, as an array (the source of the union and of the def schema's enum). */
|
|
61
|
+
declare const TEXT_CASINGS: readonly ["fold", "collated", "exact"];
|
|
62
|
+
/** How a textual comparison treats letter case — see the table in this module's docs. */
|
|
63
|
+
type TextCasing = (typeof TEXT_CASINGS)[number];
|
|
64
|
+
/**
|
|
65
|
+
* The package's default when neither the field nor the engine declares one.
|
|
66
|
+
*
|
|
67
|
+
* `'fold'` — unchanged from every release before the policy existed. This
|
|
68
|
+
* package is authored against by MODELS as much as by people, and a model
|
|
69
|
+
* writing `status = 'Active'` against stored `active` is the case the forgiving
|
|
70
|
+
* default was chosen for; flipping it would silently change which rows an
|
|
71
|
+
* existing deployment's queries return, with nothing — no problem, no type
|
|
72
|
+
* error, no thrown call — able to detect it. A deployment whose text columns are
|
|
73
|
+
* identifiers, codes or enums (where the fold is pure cost) says so in one
|
|
74
|
+
* place: `new QueryEngine(registry, { textCasing: 'exact' })`.
|
|
75
|
+
*/
|
|
76
|
+
declare const DEFAULT_TEXT_CASING: TextCasing;
|
|
77
|
+
/**
|
|
78
|
+
* How CONSTRAINED each casing is — the one place the precedence between them is
|
|
79
|
+
* declared, so the two consumers cannot drift apart:
|
|
80
|
+
*
|
|
81
|
+
* - a COMPARISON whose two operands declare different casings takes the
|
|
82
|
+
* strictest (preserving the old rule that a `sensitive` field on either side
|
|
83
|
+
* forced a case-sensitive match);
|
|
84
|
+
* - a MEET (`TextFieldType.meetWith`, which types a bind param from every use
|
|
85
|
+
* at once) takes the strictest for the same reason it ORs `whole`.
|
|
86
|
+
*
|
|
87
|
+
* `exact` is strictest — it matches the fewest values. `fold` outranks
|
|
88
|
+
* `collated` because the two agree on MEANING and disagree on who guarantees it:
|
|
89
|
+
* when one operand's store folds and the other's may not, folding here is the
|
|
90
|
+
* answer that is right either way.
|
|
91
|
+
*
|
|
92
|
+
* A max over a total order is commutative, associative and idempotent, which is
|
|
93
|
+
* exactly what `ParamSet`'s order-independent fold requires (`_meet.ts`).
|
|
94
|
+
*/
|
|
95
|
+
declare function casingRank(casing: TextCasing): number;
|
|
96
|
+
/** The stricter of two casings (see {@link casingRank}). */
|
|
97
|
+
declare function strictestCasing(a: TextCasing, b: TextCasing): TextCasing;
|
|
98
|
+
/**
|
|
99
|
+
* The casing in effect for a comparison, from the casings its operands DECLARE
|
|
100
|
+
* and the engine's default.
|
|
101
|
+
*
|
|
102
|
+
* A declaration is authoritative: the default is consulted only when NEITHER
|
|
103
|
+
* side declares one. That ordering is the whole point — a literal, a param or a
|
|
104
|
+
* computed column carries no field type, so if the default were folded in
|
|
105
|
+
* per-operand, an engine default of `'exact'` would silently override a column
|
|
106
|
+
* that explicitly declared `'fold'` merely by comparing it to a string literal.
|
|
107
|
+
*/
|
|
108
|
+
declare function effectiveCasing(left: TextCasing | undefined, right: TextCasing | undefined, fallback: TextCasing): TextCasing;
|
|
109
|
+
/**
|
|
110
|
+
* Whether SQL must wrap both operands in `LOWER(...)`. ONLY `'fold'` does:
|
|
111
|
+
* `'collated'` delegates the fold to the column, and `'exact'` does not fold.
|
|
112
|
+
*/
|
|
113
|
+
declare function foldsInSql(casing: TextCasing): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Whether the in-memory runtime must lower-case both operands. Both
|
|
116
|
+
* insensitive casings do — `'collated'` asserts the STORE folds, and the runtime
|
|
117
|
+
* exists to give the same answer the store would.
|
|
118
|
+
*/
|
|
119
|
+
declare function foldsAtRuntime(casing: TextCasing): boolean;
|
|
120
|
+
|
|
4
121
|
/**
|
|
5
122
|
* `@aeye/query` JSON Schema — THE central JSON-shape contract.
|
|
6
123
|
*
|
|
@@ -22,6 +139,7 @@ import { Tool } from '@aeye/core';
|
|
|
22
139
|
* - Optional-and-omitted is preferred over `| null`; where a field is
|
|
23
140
|
* semantically nullable in storage we say so explicitly.
|
|
24
141
|
*/
|
|
142
|
+
|
|
25
143
|
/** Any JSON value. The recursive object branch uses an index signature so
|
|
26
144
|
* arbitrary JSON trees are representable without `any`. */
|
|
27
145
|
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
@@ -45,6 +163,47 @@ interface FieldValueDef {
|
|
|
45
163
|
/** Human-facing name for this member (defaults to the value itself). */
|
|
46
164
|
label?: string;
|
|
47
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* The REFINEMENT key every field-type branch carries — the registered name that
|
|
168
|
+
* narrows this builtin (`{ kind: 'text', as: 'uuid' }`).
|
|
169
|
+
*
|
|
170
|
+
* Declared ONCE and extended by all nine branches, so `as` cannot end up meaning
|
|
171
|
+
* two different things on two of them, and adding it to a tenth branch is not
|
|
172
|
+
* something anyone has to remember.
|
|
173
|
+
*
|
|
174
|
+
* The refinement's own declaration (its narrowed options, its `instructions`,
|
|
175
|
+
* its per-dialect SQL type, its stricter value gate) lives in the REGISTRY, not
|
|
176
|
+
* here — see `refinement.ts`. That is what keeps `kind` one of the nine builtins
|
|
177
|
+
* on the wire, and therefore keeps `ScalarKind`, `FieldTypeDef` and every
|
|
178
|
+
* exhaustiveness guard over them closed.
|
|
179
|
+
*/
|
|
180
|
+
interface FieldTypeRefinementKey {
|
|
181
|
+
/**
|
|
182
|
+
* The name of a REGISTERED field-type refinement of this `kind`. Unknown
|
|
183
|
+
* names are refused at parse (`field-type.unknown-refinement`), and a use site
|
|
184
|
+
* may narrow the refinement's declared options further but never widen them.
|
|
185
|
+
*/
|
|
186
|
+
as?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Values for the options the REFINEMENT declares for ITSELF — the ones its
|
|
189
|
+
* base has never heard of (`{ as: 'Geometry', with: { subtype: 'Polygon',
|
|
190
|
+
* srid: 4326 } }`). Each key must be an option the named refinement declares,
|
|
191
|
+
* and each value is validated against that option's own `FieldTypeDef`; an
|
|
192
|
+
* unknown key is refused at parse rather than dropped.
|
|
193
|
+
*
|
|
194
|
+
* A SEPARATE BAG rather than keys spliced into the branch, because the branch
|
|
195
|
+
* is a CLOSED, strictly-parsed shape: an author-declared `srid` sitting beside
|
|
196
|
+
* `minLength` would either force every branch schema open (so a typo'd base
|
|
197
|
+
* option would then be read as somebody's custom one) or make `{maxLength}`
|
|
198
|
+
* ambiguous between the base's option and a refinement's. Keeping the two
|
|
199
|
+
* vocabularies in two bags is what lets both stay strict.
|
|
200
|
+
*
|
|
201
|
+
* Absent for every unrefined type, and absent for a refinement whose options
|
|
202
|
+
* are all left at their declared defaults — so an existing def serializes
|
|
203
|
+
* byte-for-byte as it always did.
|
|
204
|
+
*/
|
|
205
|
+
with?: Readonly<Record<string, JsonValue>>;
|
|
206
|
+
}
|
|
48
207
|
/**
|
|
49
208
|
* Numeric option bag, shared by the `number` field type and by `money`'s
|
|
50
209
|
* inner numeric configuration.
|
|
@@ -71,11 +230,11 @@ interface NumberOptions {
|
|
|
71
230
|
values?: FieldValueDef[];
|
|
72
231
|
}
|
|
73
232
|
/** The `number` field type — a numeric value with the shared `NumberOptions`. */
|
|
74
|
-
interface NumberFieldTypeDef extends NumberOptions {
|
|
233
|
+
interface NumberFieldTypeDef extends NumberOptions, FieldTypeRefinementKey {
|
|
75
234
|
kind: 'number';
|
|
76
235
|
}
|
|
77
236
|
/** The `text` field type — a string with optional length / pattern / search config. */
|
|
78
|
-
interface TextFieldTypeDef {
|
|
237
|
+
interface TextFieldTypeDef extends FieldTypeRefinementKey {
|
|
79
238
|
kind: 'text';
|
|
80
239
|
minLength?: number;
|
|
81
240
|
maxLength?: number;
|
|
@@ -86,10 +245,12 @@ interface TextFieldTypeDef {
|
|
|
86
245
|
/** Eligible for full-text search. */
|
|
87
246
|
search?: boolean;
|
|
88
247
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
248
|
+
* How textual matching / comparison on this field treats letter case, and —
|
|
249
|
+
* when it is insensitive — WHO folds. Omitted ⇒ the engine's `textCasing`
|
|
250
|
+
* default (`'fold'` unless the deployment says otherwise). See
|
|
251
|
+
* {@link TextCasing}.
|
|
91
252
|
*/
|
|
92
|
-
|
|
253
|
+
casing?: TextCasing;
|
|
93
254
|
/**
|
|
94
255
|
* The closed set of values this column may hold — see `NumberOptions.values`
|
|
95
256
|
* for why membership is a query fact. Composes with `pattern`: a regex
|
|
@@ -99,7 +260,7 @@ interface TextFieldTypeDef {
|
|
|
99
260
|
values?: FieldValueDef[];
|
|
100
261
|
}
|
|
101
262
|
/** The `money` field type — a monetary amount plus optional currency. */
|
|
102
|
-
interface MoneyFieldTypeDef {
|
|
263
|
+
interface MoneyFieldTypeDef extends FieldTypeRefinementKey {
|
|
103
264
|
kind: 'money';
|
|
104
265
|
/** Numeric configuration of the underlying amount. */
|
|
105
266
|
number?: NumberOptions;
|
|
@@ -107,11 +268,11 @@ interface MoneyFieldTypeDef {
|
|
|
107
268
|
currency?: string;
|
|
108
269
|
}
|
|
109
270
|
/** The `bool` field type — a boolean value. */
|
|
110
|
-
interface BoolFieldTypeDef {
|
|
271
|
+
interface BoolFieldTypeDef extends FieldTypeRefinementKey {
|
|
111
272
|
kind: 'bool';
|
|
112
273
|
}
|
|
113
274
|
/** The `relation` field type — a typed link to another Type (see `to` / `count`). */
|
|
114
|
-
interface RelationFieldTypeDef {
|
|
275
|
+
interface RelationFieldTypeDef extends FieldTypeRefinementKey {
|
|
115
276
|
kind: 'relation';
|
|
116
277
|
/** Name of the target Type this relation points to. */
|
|
117
278
|
to: string;
|
|
@@ -142,17 +303,17 @@ interface RelationFieldTypeDef {
|
|
|
142
303
|
* `false` (naive / local). */
|
|
143
304
|
type TimezonePolicy = string | boolean;
|
|
144
305
|
/** The `date` field type — a calendar date with an optional timezone policy. */
|
|
145
|
-
interface DateFieldTypeDef {
|
|
306
|
+
interface DateFieldTypeDef extends FieldTypeRefinementKey {
|
|
146
307
|
kind: 'date';
|
|
147
308
|
timezone?: TimezonePolicy;
|
|
148
309
|
}
|
|
149
310
|
/** The `timestamp` field type — a date+time with an optional timezone policy. */
|
|
150
|
-
interface TimestampFieldTypeDef {
|
|
311
|
+
interface TimestampFieldTypeDef extends FieldTypeRefinementKey {
|
|
151
312
|
kind: 'timestamp';
|
|
152
313
|
timezone?: TimezonePolicy;
|
|
153
314
|
}
|
|
154
315
|
/** The `json` field type — an arbitrary JSON value with an optional schema constraint. */
|
|
155
|
-
interface JsonFieldTypeDef {
|
|
316
|
+
interface JsonFieldTypeDef extends FieldTypeRefinementKey {
|
|
156
317
|
kind: 'json';
|
|
157
318
|
/** Optional JSON-Schema-shaped constraint for the stored value. */
|
|
158
319
|
schema?: JsonValue;
|
|
@@ -164,7 +325,7 @@ interface JsonFieldTypeDef {
|
|
|
164
325
|
* elements (any JSON value is accepted). Because `item` is itself a
|
|
165
326
|
* `FieldTypeDef`, arrays nest (e.g. `array<array<number>>`).
|
|
166
327
|
*/
|
|
167
|
-
interface ArrayFieldTypeDef {
|
|
328
|
+
interface ArrayFieldTypeDef extends FieldTypeRefinementKey {
|
|
168
329
|
kind: 'array';
|
|
169
330
|
minItems?: number;
|
|
170
331
|
maxItems?: number;
|
|
@@ -491,6 +652,28 @@ interface FunctionCallExprDef {
|
|
|
491
652
|
/** Arguments keyed by declared parameter name. */
|
|
492
653
|
args: Record<string, ExprDef>;
|
|
493
654
|
}
|
|
655
|
+
/**
|
|
656
|
+
* A REGISTERED OPERATOR applied to its operands — `{ kind:'operator', op:'&&',
|
|
657
|
+
* args:{ left, right } }`.
|
|
658
|
+
*
|
|
659
|
+
* FUNCTION-SHAPED ON THE WIRE, exactly like every other operator in this
|
|
660
|
+
* language: `comparison` is `{op, left, right}`, not an infix string. Infix
|
|
661
|
+
* exists only in EMITTED SQL, where the operator's declaration supplies a
|
|
662
|
+
* per-dialect template. `args` are keyed by the declared OPERAND name for the
|
|
663
|
+
* same reason a function call's are keyed by parameter name — a positional list
|
|
664
|
+
* is the shape a model most reliably gets wrong.
|
|
665
|
+
*
|
|
666
|
+
* `op` names an operator registered with `registry.registerOperator`; the KIND
|
|
667
|
+
* is closed (this package owns it) while the VOCABULARY is open, which is
|
|
668
|
+
* precisely the relationship `function-call` has to `registerFunction`.
|
|
669
|
+
*/
|
|
670
|
+
interface OperatorExprDef {
|
|
671
|
+
kind: 'operator';
|
|
672
|
+
/** A registered operator name (`&&`, `<->`, `@>`). */
|
|
673
|
+
op: string;
|
|
674
|
+
/** Operands keyed by declared operand name. */
|
|
675
|
+
args: Record<string, ExprDef>;
|
|
676
|
+
}
|
|
494
677
|
/**
|
|
495
678
|
* A type-valued function call (produces rows; usable as a source). `args` are
|
|
496
679
|
* keyed by declared parameter name.
|
|
@@ -629,7 +812,7 @@ interface ArgExprDef {
|
|
|
629
812
|
/** The aggregate parameter name this placeholder stands in for (e.g. `value`). */
|
|
630
813
|
name: string;
|
|
631
814
|
}
|
|
632
|
-
type ExprDef = LiteralExprDef | OutputRefExprDef | SorterDef | ArgExprDef | FieldRefExprDef | ParamExprDef | BinaryExprDef | UnaryExprDef | ComparisonExprDef | LogicalExprDef | InExprDef | BetweenExprDef | IsNullExprDef | ExistsExprDef | ArrayOpExprDef | CaseExprDef | AggregateExprDef | WindowExprDef | FunctionCallExprDef | TabularFunctionCallExprDef | SemanticExprDef | TextSearchExprDef | TextScoreExprDef | FiltersExprDef | SubqueryExprDef | ExcludedExprDef;
|
|
815
|
+
type ExprDef = LiteralExprDef | OutputRefExprDef | SorterDef | ArgExprDef | FieldRefExprDef | ParamExprDef | BinaryExprDef | UnaryExprDef | ComparisonExprDef | LogicalExprDef | InExprDef | BetweenExprDef | IsNullExprDef | ExistsExprDef | ArrayOpExprDef | CaseExprDef | AggregateExprDef | WindowExprDef | FunctionCallExprDef | TabularFunctionCallExprDef | OperatorExprDef | SemanticExprDef | TextSearchExprDef | TextScoreExprDef | FiltersExprDef | SubqueryExprDef | ExcludedExprDef;
|
|
633
816
|
/** The set of `kind` discriminants for expressions. */
|
|
634
817
|
type ExprKind = ExprDef['kind'];
|
|
635
818
|
/**
|
|
@@ -946,7 +1129,17 @@ interface FunctionDef {
|
|
|
946
1129
|
output: FieldTypeDef | {
|
|
947
1130
|
type: string;
|
|
948
1131
|
} | 'inferred';
|
|
949
|
-
/**
|
|
1132
|
+
/**
|
|
1133
|
+
* The emitted SQL function NAME, when it differs from `name` (`log10` → `log`,
|
|
1134
|
+
* `rowNumber` → `row_number`). NOT a template: the emit path substitutes this
|
|
1135
|
+
* identifier and nothing else — `name(arg, arg)` is the only call form a
|
|
1136
|
+
* declaration can produce (`FunctionCallExpr.toSQL`). Anything shaped
|
|
1137
|
+
* otherwise, or differing BY DIALECT, is code: a `Dialect` subclass
|
|
1138
|
+
* overriding `emitBuiltinCall`, which is consulted first.
|
|
1139
|
+
*
|
|
1140
|
+
* It is raw-interpolated, exactly as `name` is, so it is held to the same
|
|
1141
|
+
* identifier pattern at registration (`registry.registerFunction`).
|
|
1142
|
+
*/
|
|
950
1143
|
sql?: string;
|
|
951
1144
|
/**
|
|
952
1145
|
* DECLARED-PARAMETER INDICES whose argument must be emitted as an INLINE SQL
|
|
@@ -1101,6 +1294,659 @@ declare class QueryTypeError extends Error {
|
|
|
1101
1294
|
constructor(problem: Problem);
|
|
1102
1295
|
}
|
|
1103
1296
|
|
|
1297
|
+
/**
|
|
1298
|
+
* FIELD-TYPE REFINEMENTS — a registered NAME over a builtin base.
|
|
1299
|
+
*
|
|
1300
|
+
* `{ kind: 'text', as: 'uuid' }` is a `text` column that a deployment has named
|
|
1301
|
+
* `uuid` and narrowed once, centrally, instead of at every declaration site. The
|
|
1302
|
+
* spelling is deliberate and it is the whole reason this feature is affordable:
|
|
1303
|
+
*
|
|
1304
|
+
* - the wire `kind` stays one of the nine builtins, so `ScalarKind` never
|
|
1305
|
+
* opens, every `def.kind === 'text'` narrowing and every `instanceof
|
|
1306
|
+
* TextFieldType` check stays correct by construction, and the exhaustiveness
|
|
1307
|
+
* guards in the SQL / cost / value-schema switches stay unreachable;
|
|
1308
|
+
* - a DECLARATION is pure JSON, so it can be persisted, sent over the wire and
|
|
1309
|
+
* shown to a model, while the CODE half ({@link FieldTypeImpl}) is a separate
|
|
1310
|
+
* registration — the same split `FunctionDef` has to `FunctionRun`, and for a
|
|
1311
|
+
* measured reason rather than symmetry (see {@link FieldTypeImpl});
|
|
1312
|
+
* - the library COMPILES the declaration into a builtin instance. A declarer
|
|
1313
|
+
* never writes a `FieldType` subclass, never writes `meetWith`, and therefore
|
|
1314
|
+
* cannot break the lattice laws `param-meet.test.ts` proves.
|
|
1315
|
+
*
|
|
1316
|
+
* WHAT IT BUYS, measured. A catalog that declares `id: { kind: 'text' }` at ~40
|
|
1317
|
+
* sites emits `LOWER("t"."id") = LOWER($1)` for every id predicate — index-
|
|
1318
|
+
* defeating, and a hard `function lower(uuid) does not exist` over a physical
|
|
1319
|
+
* uuid column. One `uuid` refinement declaring `casing: 'exact'` turns all forty
|
|
1320
|
+
* into a bare, sargable `=`, and it does so through the ordinary meet rather
|
|
1321
|
+
* than through a new rule.
|
|
1322
|
+
*
|
|
1323
|
+
* NARROWING, NEVER WIDENING. A refinement's `options` are the FLOOR every use of
|
|
1324
|
+
* it stands on: a use site's own options are MET with them (`FieldType.meet`),
|
|
1325
|
+
* so a site may narrow further and a site that tries to widen is simply absorbed
|
|
1326
|
+
* — the met type is a lower bound of both by construction. A site whose options
|
|
1327
|
+
* cannot coexist with the declaration's (`as:'uuid'` beside `maxLength: 10`) has
|
|
1328
|
+
* no meet at all and is REFUSED where declarations are read, next to
|
|
1329
|
+
* `field-type.bad-values` and `field-type.bad-pattern`. That is gin's
|
|
1330
|
+
* `Extension.narrow` law, and this package already satisfies it because here the
|
|
1331
|
+
* meet IS narrow.
|
|
1332
|
+
*
|
|
1333
|
+
* TWO OPTION VOCABULARIES, AND THEY STAY APART. `options` narrows the BASE's own
|
|
1334
|
+
* vocabulary and is typed straight off `FieldTypeDef`. {@link
|
|
1335
|
+
* FieldTypeRefinementDefFor.ownOptions} declares options the base has never
|
|
1336
|
+
* heard of (`srid`, `subtype`), each typed by a `FieldTypeDef` of its own, and a
|
|
1337
|
+
* site supplies them in a separate `with` bag. They are two bags rather than one
|
|
1338
|
+
* because merging them would make a `{maxLength}` template slot ambiguous
|
|
1339
|
+
* between the base's option and a refinement's, and would force the strictly-
|
|
1340
|
+
* parsed branch schemas open — after which a typo'd base option would be read as
|
|
1341
|
+
* somebody's custom one. Both obey the same law from opposite directions: a base
|
|
1342
|
+
* option narrows through the OPTIONS meet, an own option through the flat
|
|
1343
|
+
* `meetExact` (unset is TOP, equal keeps, different conflicts), which is the
|
|
1344
|
+
* only lattice a single-valued attribute has.
|
|
1345
|
+
*
|
|
1346
|
+
* BOTH ROADS, NOT ONLY SQL. A refinement's SQL half is a declaration
|
|
1347
|
+
* (`sql` / `cast`, per dialect); its IN-MEMORY half is
|
|
1348
|
+
* {@link FieldTypeImpl.compareValues}, the comparator `Value.compareTo`
|
|
1349
|
+
* consults. The two exist to answer the SAME question the same way — a type
|
|
1350
|
+
* whose stored SQL ordering differs from its stringified one gives two answers
|
|
1351
|
+
* for one query until it declares the comparator, and nothing static can detect
|
|
1352
|
+
* that (`differentialCheck` in `conformance.ts` is what can).
|
|
1353
|
+
*/
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* Allowed charset for a registered refinement NAME.
|
|
1357
|
+
*
|
|
1358
|
+
* A capital is allowed, and that is a deliberate cross-library decision rather
|
|
1359
|
+
* than a loose default. A consumer that registers the same logical type in BOTH
|
|
1360
|
+
* `@aeye/gin` and this package has to spell it once: gin refuses a package type
|
|
1361
|
+
* name that does not START with a capital (a shipped, measured rule — a system
|
|
1362
|
+
* package's lower-case `time` silently shadowed a user's `time` in every
|
|
1363
|
+
* session), so a lower-case-only rule here would make every such name
|
|
1364
|
+
* unspellable in one library or the other. Measured over the two worked
|
|
1365
|
+
* examples: `geometry`/`latlng` are refused by gin, `Geometry`/`LatLng` would be
|
|
1366
|
+
* refused by a lower-case-only rule here, and no third spelling satisfies both.
|
|
1367
|
+
*
|
|
1368
|
+
* It is also the rule this package already applies to the OTHER name a third
|
|
1369
|
+
* party registers: `FUNCTION_NAME_PATTERN` is `^[A-Za-z_][A-Za-z0-9_.]*$`, which
|
|
1370
|
+
* is how `ST_Contains` registers. A dot is excluded here (a refinement name is
|
|
1371
|
+
* never schema-qualified and renders inside a type tag), and so is a leading
|
|
1372
|
+
* underscore (it reads as private in every language a declarer comes from).
|
|
1373
|
+
*/
|
|
1374
|
+
declare const REFINEMENT_NAME_PATTERN: RegExp;
|
|
1375
|
+
/**
|
|
1376
|
+
* The OPTION BAG of one builtin branch — that branch's own def minus the
|
|
1377
|
+
* discriminant and the two refinement keys.
|
|
1378
|
+
*
|
|
1379
|
+
* DERIVED from `FieldTypeDef`, never restated: an option added to a builtin is
|
|
1380
|
+
* immediately declarable on a refinement of it, and an option removed from one
|
|
1381
|
+
* stops compiling at every declaration that still names it.
|
|
1382
|
+
*/
|
|
1383
|
+
type FieldTypeOptionsOf<B extends ScalarKind> = Omit<Extract<FieldTypeDef, {
|
|
1384
|
+
kind: B;
|
|
1385
|
+
}>, 'kind' | 'as' | 'with'>;
|
|
1386
|
+
/**
|
|
1387
|
+
* One option a refinement declares FOR ITSELF — an option its base has never
|
|
1388
|
+
* heard of (`srid`, `subtype`), supplied per column in the def's `with` bag.
|
|
1389
|
+
*
|
|
1390
|
+
* `type` is an ordinary {@link FieldTypeDef}, so validation, the model-facing
|
|
1391
|
+
* description and the JSON round-trip all come from machinery that already
|
|
1392
|
+
* exists — the same reason `FunctionDef.params` types its parameters that way
|
|
1393
|
+
* rather than inventing a second vocabulary.
|
|
1394
|
+
*/
|
|
1395
|
+
interface FieldTypeOptionDecl {
|
|
1396
|
+
/**
|
|
1397
|
+
* The option's own type, in this package's field-type vocabulary. A site's
|
|
1398
|
+
* value is checked against it with {@link FieldType.validValue}, at parse,
|
|
1399
|
+
* where the def is read.
|
|
1400
|
+
*/
|
|
1401
|
+
readonly type: FieldTypeDef;
|
|
1402
|
+
/**
|
|
1403
|
+
* The value a column that names none carries. REQUIRED for an option any
|
|
1404
|
+
* `sql` / `cast` template interpolates — a template must resolve for EVERY
|
|
1405
|
+
* column, and "the site said nothing" is otherwise a hole with no answer.
|
|
1406
|
+
*/
|
|
1407
|
+
readonly default?: JsonValue;
|
|
1408
|
+
/** What the option means, for a model. Rendered beside it in the generated schema. */
|
|
1409
|
+
readonly docs?: string;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* The OPERATOR each arm of {@link FieldTypeCompareDecl} governs, as a model
|
|
1413
|
+
* would write it — the one vocabulary every renderer of a refused arm derives
|
|
1414
|
+
* from.
|
|
1415
|
+
*
|
|
1416
|
+
* A total `Record` over the arms, and it is the ONLY place the arm key set is
|
|
1417
|
+
* spelled outside the interface itself. It was spelled twice more, as
|
|
1418
|
+
* `if (!compare.equality) …` chains in two files with two different glyph
|
|
1419
|
+
* vocabularies — so a FOURTH arm would have compiled clean and been mentioned by
|
|
1420
|
+
* neither the type tag nor the generated schema's glossary, which is exactly the
|
|
1421
|
+
* failure those renderers exist to prevent. Adding an arm now fails to compile
|
|
1422
|
+
* here, and both readers pick it up for free.
|
|
1423
|
+
*/
|
|
1424
|
+
declare const COMPARE_ARM_OPERATORS: Readonly<Record<keyof FieldTypeCompareDecl, string>>;
|
|
1425
|
+
/**
|
|
1426
|
+
* The operators a refinement REFUSES, in a stable order — the shared half of
|
|
1427
|
+
* every "what can I not write on this column" rendering.
|
|
1428
|
+
*/
|
|
1429
|
+
declare function refusedOperators(compare: Required<FieldTypeCompareDecl>): string[];
|
|
1430
|
+
/**
|
|
1431
|
+
* WHICH ARMS OF THE BUILTIN COMPARISON GRAMMAR a refinement admits.
|
|
1432
|
+
*
|
|
1433
|
+
* `ComparisonOp` is a closed 9-member union (`=`, `<>`, `<`, `<=`, `>`, `>=`,
|
|
1434
|
+
* `like`, `notLike`, `ilike`) and it STAYS closed — what a type declares is
|
|
1435
|
+
* which of them mean anything for it, not a new one. Every arm defaults to
|
|
1436
|
+
* `true`, so an existing declaration keeps the grammar it always had.
|
|
1437
|
+
*
|
|
1438
|
+
* The refusal is `Problems`-grade (`comparison.type`) and quotes the type's own
|
|
1439
|
+
* `instructions`, because "you cannot order a geometry" is only half an answer:
|
|
1440
|
+
* the half that saves a round trip is what to reach for instead, and the
|
|
1441
|
+
* declaration is the one place that knows.
|
|
1442
|
+
*/
|
|
1443
|
+
interface FieldTypeCompareDecl {
|
|
1444
|
+
/** `=` / `<>`. Default `true`. */
|
|
1445
|
+
readonly equality?: boolean;
|
|
1446
|
+
/** `<` / `<=` / `>` / `>=`. Default `true`. */
|
|
1447
|
+
readonly ordering?: boolean;
|
|
1448
|
+
/**
|
|
1449
|
+
* `like` / `notLike` / `ilike`. Default `true`. Already gated by the operand's
|
|
1450
|
+
* CATEGORY being text, so this narrows a text refinement and is simply moot
|
|
1451
|
+
* for the other eight bases.
|
|
1452
|
+
*/
|
|
1453
|
+
readonly textMatch?: boolean;
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* A field-type refinement DECLARATION, for one base `B`. The union over every
|
|
1457
|
+
* base is {@link FieldTypeRefinementDef}, which is what `registerFieldType`
|
|
1458
|
+
* takes; splitting it per-base is what makes `options` narrow to the base's own
|
|
1459
|
+
* vocabulary at the call site.
|
|
1460
|
+
*/
|
|
1461
|
+
interface FieldTypeRefinementDefFor<B extends ScalarKind> {
|
|
1462
|
+
/**
|
|
1463
|
+
* The registered name — the `as` a field declares. Held to
|
|
1464
|
+
* {@link REFINEMENT_NAME_PATTERN}, and it renders VERBATIM everywhere a model
|
|
1465
|
+
* reads it (the type tag, the generated `as` enum): never lower-cased, never
|
|
1466
|
+
* pluralized, never decorated. A model reads this package's surface and a
|
|
1467
|
+
* sibling library's in one session, and a spelling difference between them
|
|
1468
|
+
* reads as two different types.
|
|
1469
|
+
*/
|
|
1470
|
+
readonly name: string;
|
|
1471
|
+
/** The BUILTIN bucket this refines. Must be a {@link ScalarKind}. */
|
|
1472
|
+
readonly base: B;
|
|
1473
|
+
/**
|
|
1474
|
+
* What the type MEANS, for a model. REQUIRED — and deliberately stricter than
|
|
1475
|
+
* `FunctionDef.instructions`, which is optional. Measured: an undocumented
|
|
1476
|
+
* registered item renders as a bare signature beside documented siblings, and
|
|
1477
|
+
* a model choosing among them is guessing. The expensive failure is not the
|
|
1478
|
+
* ~20 tokens of the line, it is the validate-fail retry that carries the
|
|
1479
|
+
* WHOLE schema a second time.
|
|
1480
|
+
*/
|
|
1481
|
+
readonly instructions: string;
|
|
1482
|
+
/**
|
|
1483
|
+
* The narrowing this refinement declares, in the base's own option vocabulary.
|
|
1484
|
+
* Every use of the refinement stands on it (see the module docs): a site may
|
|
1485
|
+
* narrow further, and a site that contradicts it is refused.
|
|
1486
|
+
*/
|
|
1487
|
+
readonly options?: FieldTypeOptionsOf<B>;
|
|
1488
|
+
/**
|
|
1489
|
+
* The options this refinement declares FOR ITSELF, beyond its base's
|
|
1490
|
+
* vocabulary — `{ srid: { type: { kind:'number', whole:true }, default: 4326 } }`.
|
|
1491
|
+
* A column supplies them in its `with` bag.
|
|
1492
|
+
*
|
|
1493
|
+
* They meet through the flat {@link meetExact} lattice, per key: unset is TOP,
|
|
1494
|
+
* equal keeps, and two DIFFERENT values conflict — because there is no third
|
|
1495
|
+
* SRID that is both 4326 and 3857, exactly as there is no third `pattern` that
|
|
1496
|
+
* is both `^a` and `^b`. So "narrow, never widen" reads here as "a use may SET
|
|
1497
|
+
* an option the declaration left open, and may not contradict another use".
|
|
1498
|
+
*/
|
|
1499
|
+
readonly ownOptions?: Readonly<Record<string, FieldTypeOptionDecl>>;
|
|
1500
|
+
/**
|
|
1501
|
+
* Which arms of the builtin comparison grammar this type admits — see
|
|
1502
|
+
* {@link FieldTypeCompareDecl}. Omitted ⇒ all three, i.e. the grammar the base
|
|
1503
|
+
* kind already had.
|
|
1504
|
+
*/
|
|
1505
|
+
readonly compare?: FieldTypeCompareDecl;
|
|
1506
|
+
/**
|
|
1507
|
+
* OTHER registered refinement names a value of this type may be compared
|
|
1508
|
+
* with — the declared form of the hardcoded `number`/`money` and
|
|
1509
|
+
* `date`/`timestamp` families in `field-type.ts`.
|
|
1510
|
+
*
|
|
1511
|
+
* It only ever GROWS the comparability relation; it never shrinks it, and that
|
|
1512
|
+
* is load-bearing rather than a simplification. `meet` implies
|
|
1513
|
+
* `comparableWith` (a property test asserts it over every pair), so a
|
|
1514
|
+
* declaration that could REMOVE an edge would have to remove the corresponding
|
|
1515
|
+
* meet with it — and the meet a restriction would have to remove is
|
|
1516
|
+
* `refinement ⊓ its own unrefined base`, i.e. the `x ⊓ ⊤ = x` identity. One
|
|
1517
|
+
* declaration would then owe the lattice a carve-out. Growing the relation
|
|
1518
|
+
* owes it nothing: a superset of the meets is still a superset.
|
|
1519
|
+
*
|
|
1520
|
+
* THE REGISTRY SYMMETRIZES IT. Naming a type that does not name you back
|
|
1521
|
+
* records the edge in BOTH directions and files a `warn`-grade note
|
|
1522
|
+
* (`Registry.fieldTypeComparabilityNotes`), so commutativity of
|
|
1523
|
+
* `comparableWith` is structural rather than the declarer's discipline — and
|
|
1524
|
+
* so a name may be declared before the type it names is registered, which
|
|
1525
|
+
* mutual pairs otherwise make impossible.
|
|
1526
|
+
*
|
|
1527
|
+
* It is NOT transitive and is not meant to be: `Meters` may be comparable with
|
|
1528
|
+
* `Number` and `Feet` comparable with `Number` while `Meters` and `Feet` are
|
|
1529
|
+
* not comparable with each other.
|
|
1530
|
+
*/
|
|
1531
|
+
readonly comparableWith?: readonly string[];
|
|
1532
|
+
/**
|
|
1533
|
+
* Per-dialect SQL TYPE — the CAST target for a value of this type, keyed by
|
|
1534
|
+
* `Dialect.name`. A `{slot}` naming a base `options` key resolves at
|
|
1535
|
+
* REGISTRATION (those are constants); a slot naming an {@link ownOptions} key
|
|
1536
|
+
* resolves PER COLUMN, from that column's `with` bag or the option's declared
|
|
1537
|
+
* `default`. A dialect with no entry falls back to the builtin's answer for
|
|
1538
|
+
* the base kind.
|
|
1539
|
+
*/
|
|
1540
|
+
readonly sql?: Readonly<Record<string, string>>;
|
|
1541
|
+
/**
|
|
1542
|
+
* Per-dialect CAST of a bound DOCUMENT into this type, keyed by
|
|
1543
|
+
* `Dialect.name`. `{value}` is the bound parameter slot and must appear at
|
|
1544
|
+
* least once; every other `{slot}` names a declared option — a base one
|
|
1545
|
+
* resolving at registration, an own one per column (see {@link sql}).
|
|
1546
|
+
*
|
|
1547
|
+
* ONLY DECLARABLE ON A BASE WHOSE VALUES ROUTE THROUGH `Dialect.jsonValue`
|
|
1548
|
+
* (see {@link CAST_CAPABLE_BASES}) — a scalar predicate binds its value
|
|
1549
|
+
* directly and there is no seam for a template to reach, so a `cast` on a
|
|
1550
|
+
* `text` base would validate at registration and then be silently inert on
|
|
1551
|
+
* every predicate over the column. It is refused instead. What a scalar base
|
|
1552
|
+
* declares is `sql`, the cast TARGET.
|
|
1553
|
+
*
|
|
1554
|
+
* A cast-capable base with no entry for a dialect falls back to the BASE's
|
|
1555
|
+
* cast — a fallback, not a degrade, because the base's answer is a real answer
|
|
1556
|
+
* for a value of the base type.
|
|
1557
|
+
*/
|
|
1558
|
+
readonly cast?: Readonly<Record<string, string>>;
|
|
1559
|
+
/** Estimated average stored bytes, when the base's own estimate is wrong (a `uuid` is 16, not 32). */
|
|
1560
|
+
readonly avgBytes?: number;
|
|
1561
|
+
/**
|
|
1562
|
+
* Who declared it — surfaced when a SECOND declarer claims the same name, so
|
|
1563
|
+
* the refusal names the incumbent instead of just the collision.
|
|
1564
|
+
*/
|
|
1565
|
+
readonly declaredBy?: string;
|
|
1566
|
+
}
|
|
1567
|
+
/**
|
|
1568
|
+
* A field-type refinement declaration. A discriminated union over `base`, so
|
|
1569
|
+
* `{ base: 'text' }` type-checks its `options` against the `text` branch and
|
|
1570
|
+
* nothing else — and `relation` is not a member at all, so an unrefinable base
|
|
1571
|
+
* is a COMPILE error rather than only a registration one (the runtime check
|
|
1572
|
+
* stays, for a caller with no types).
|
|
1573
|
+
*/
|
|
1574
|
+
type FieldTypeRefinementDef = {
|
|
1575
|
+
[B in RefinableBase]: FieldTypeRefinementDefFor<B>;
|
|
1576
|
+
}[RefinableBase];
|
|
1577
|
+
/**
|
|
1578
|
+
* The CODE half of a refinement — `registry.registerFieldTypeImpl(name, impl)`,
|
|
1579
|
+
* the exact counterpart of `registerFunctionRun` beside `registerFunction`.
|
|
1580
|
+
*
|
|
1581
|
+
* IT IS SPLIT FROM THE DECLARATION FOR A MEASURED REASON, not for symmetry. A
|
|
1582
|
+
* `FieldTypeRefinementDef` is what a consumer PERSISTS and replays at boot, and
|
|
1583
|
+
* a zod schema does not vanish under `JSON.stringify` — it stringifies into a
|
|
1584
|
+
* plausible husk that survives the round-trip, passes every registration check,
|
|
1585
|
+
* and then throws a raw `TypeError` out of zod's internals at the first
|
|
1586
|
+
* `validValue()`: no `QueryTypeError`, no code, no path, and the strictest gate
|
|
1587
|
+
* on that column silently dead. Keeping a schema on the declaration would make
|
|
1588
|
+
* that the DEFAULT outcome of doing the obvious thing with it. With the split,
|
|
1589
|
+
* a declaration is pure JSON and round-trips honestly, and the half that cannot
|
|
1590
|
+
* survive a round-trip is the half nobody tries to store.
|
|
1591
|
+
*/
|
|
1592
|
+
interface FieldTypeImpl {
|
|
1593
|
+
/**
|
|
1594
|
+
* A STRICTER value gate than the base's own (`z.uuid()` for a `uuid`), applied
|
|
1595
|
+
* in CONJUNCTION with the field's own schema — never as a replacement, since a
|
|
1596
|
+
* use site may narrow further and answering with this alone would admit values
|
|
1597
|
+
* the field's own options refuse (see `FieldType.toValueSchema`).
|
|
1598
|
+
*
|
|
1599
|
+
* `FieldTypeDef` has no record branch, so this is also the declared home of a
|
|
1600
|
+
* STRUCTURAL value contract for a refinement whose raw value is an object.
|
|
1601
|
+
*/
|
|
1602
|
+
readonly value?: z.ZodTypeAny;
|
|
1603
|
+
/**
|
|
1604
|
+
* HOW TWO VALUES OF THIS TYPE ORDER, in the IN-MEMORY runtime — the hook
|
|
1605
|
+
* `Value.compareTo` consults before its own rules (`runtime/value.ts`).
|
|
1606
|
+
*
|
|
1607
|
+
* WHAT IT IS FOR, precisely. `Value.compareTo` compares numbers numerically,
|
|
1608
|
+
* booleans false-first, and EVERYTHING ELSE by `String(raw)`. So a refinement
|
|
1609
|
+
* whose stored SQL type orders differently from its stringified form answers
|
|
1610
|
+
* two different things for one query depending on which road ran it:
|
|
1611
|
+
* `{ base:'text', sql:{postgres:'inet'} }` holding `10.0.0.2` and `10.0.0.10`
|
|
1612
|
+
* orders them by address at the database (`inet` compares numerically) and
|
|
1613
|
+
* lexicographically here (`'10.0.0.10' < '10.0.0.2'`). Declaring a comparator
|
|
1614
|
+
* is how the runtime is told what the store already knew.
|
|
1615
|
+
*
|
|
1616
|
+
* IT GOVERNS EQUALITY TOO, and deliberately: `Value.equals` / `identical` are
|
|
1617
|
+
* `compareTo(...) === 0`, so ONE comparator keeps ordering and equality from
|
|
1618
|
+
* contradicting each other. That is also why there is no separate
|
|
1619
|
+
* `equalValues` — and the reason is the SQL half rather than tidiness. A btree
|
|
1620
|
+
* operator class requires its `=` and its `<` to be consistent, so a single
|
|
1621
|
+
* comparator is the faithful model of the thing the emitted statement actually
|
|
1622
|
+
* runs on; two hooks would let this package describe an index Postgres would
|
|
1623
|
+
* refuse to build.
|
|
1624
|
+
*
|
|
1625
|
+
* THE CONSEQUENCE, which is easy to miss: a type whose EQUALITY is finer than
|
|
1626
|
+
* its ordering has to TIE-BREAK inside the comparator. Answering `0` for two
|
|
1627
|
+
* values you consider distinct does not merely conflate them under `=` — it
|
|
1628
|
+
* also leaves their relative ORDER undefined, so `ORDER BY` returns them in
|
|
1629
|
+
* whichever order the sort happened to produce and the database returns them
|
|
1630
|
+
* in whichever order its index happened to hold. Semver build metadata, a
|
|
1631
|
+
* username sorted case-insensitively, and a zoned timestamp ordered by instant
|
|
1632
|
+
* are all this shape: compare the primary key first, then the tie-breaker, and
|
|
1633
|
+
* both roads become deterministic together.
|
|
1634
|
+
*
|
|
1635
|
+
* IT OUT-RANKS CASE FOLDING. `Value.compareToCase` consults it before folding,
|
|
1636
|
+
* because a type that has said how its values compare has said so including
|
|
1637
|
+
* their case; a refinement that wants the package's folding declares no
|
|
1638
|
+
* comparator and sets `options.casing` instead.
|
|
1639
|
+
*
|
|
1640
|
+
* IT IS HANDED VALUES THAT ARE NOT OF YOUR TYPE — a comparison, a sort key or
|
|
1641
|
+
* a `min()` reaches it with whatever the row held, which is what makes it a
|
|
1642
|
+
* comparator rather than an assertion. Return a negative / zero / positive
|
|
1643
|
+
* number; a `NaN` or non-numeric answer is read as "equal" rather than allowed
|
|
1644
|
+
* to corrupt a sort, and a THROW is not caught. `checkFieldType`
|
|
1645
|
+
* property-tests reflexivity, antisymmetry, transitivity and totality over
|
|
1646
|
+
* your samples; `differentialCheck` settles the one question neither it nor
|
|
1647
|
+
* registration can — whether it agrees with the database.
|
|
1648
|
+
*/
|
|
1649
|
+
readonly compareValues?: ValueComparator;
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* A refinement's in-memory ordering ({@link FieldTypeImpl.compareValues}) — the
|
|
1653
|
+
* `Array.prototype.sort` contract over two RAW values.
|
|
1654
|
+
*
|
|
1655
|
+
* Typed against `JsonValue` rather than against a narrowed value type, because
|
|
1656
|
+
* it is reached from `Value.compareTo`, which is total over every cell a row can
|
|
1657
|
+
* hold and cannot know that a given cell really is of your type. A comparator
|
|
1658
|
+
* written as though it will only ever see well-formed values of its own type is
|
|
1659
|
+
* the shape that throws out of a sort.
|
|
1660
|
+
*/
|
|
1661
|
+
type ValueComparator = (a: JsonValue, b: JsonValue) => number;
|
|
1662
|
+
/**
|
|
1663
|
+
* The bases a refinement may narrow: every `ScalarKind` EXCEPT `relation`.
|
|
1664
|
+
*
|
|
1665
|
+
* A relation carries an IDENTITY (`to`) and a cardinality ESTIMATE (`count`),
|
|
1666
|
+
* neither of which is a constraint a name can narrow — the same fact
|
|
1667
|
+
* `param-meet.test.ts` already records by giving `relation` no TOP ("its `to` is
|
|
1668
|
+
* an identity, not a constraint, so there is no relation that constrains
|
|
1669
|
+
* nothing"). Measured consequence of allowing it: a site had to restate `to` and
|
|
1670
|
+
* `count` verbatim, which is the exact duplication this feature removes, and a
|
|
1671
|
+
* declaration that named only `count` registered cleanly and then refused every
|
|
1672
|
+
* column that used it, blaming the column. Refused at the declaration instead.
|
|
1673
|
+
*/
|
|
1674
|
+
declare const REFINABLE_BASES: ("number" | "text" | "money" | "bool" | "date" | "timestamp" | "json" | "array")[];
|
|
1675
|
+
/** A base a refinement may narrow (see {@link REFINABLE_BASES}). */
|
|
1676
|
+
type RefinableBase = Exclude<ScalarKind, 'relation'>;
|
|
1677
|
+
/**
|
|
1678
|
+
* An option this refinement declares FOR ITSELF, compiled: its declared type as
|
|
1679
|
+
* a `FieldType` (so a site's value is checked by the machinery that already
|
|
1680
|
+
* checks every other value) beside the declaration it came from.
|
|
1681
|
+
*/
|
|
1682
|
+
interface CompiledFieldTypeOption {
|
|
1683
|
+
/** The option name — the key a column writes in its `with` bag. */
|
|
1684
|
+
readonly name: string;
|
|
1685
|
+
/** The option's declared type, parsed. */
|
|
1686
|
+
readonly type: FieldType;
|
|
1687
|
+
/** The declared type's def, for the generated schema and for describing it. */
|
|
1688
|
+
readonly typeDef: FieldTypeDef;
|
|
1689
|
+
/** The value a column that names none carries, or `undefined`. */
|
|
1690
|
+
readonly default: JsonValue | undefined;
|
|
1691
|
+
/** What the option means, for a model. */
|
|
1692
|
+
readonly docs: string | undefined;
|
|
1693
|
+
/** Whether any `sql` / `cast` template interpolates it — which is what makes its values an injection surface. */
|
|
1694
|
+
readonly interpolated: boolean;
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* A COMPILED refinement — the declaration plus the builtin instance its
|
|
1698
|
+
* `options` parse to, which is the operand every use site is met against.
|
|
1699
|
+
*
|
|
1700
|
+
* Built only by {@link FieldTypeRefinement.compile} (via
|
|
1701
|
+
* `Registry.registerFieldType`), so an instance in hand has already passed every
|
|
1702
|
+
* registration-time check.
|
|
1703
|
+
*/
|
|
1704
|
+
declare class FieldTypeRefinement {
|
|
1705
|
+
/** The registered name — the `as` on the wire. */
|
|
1706
|
+
readonly name: string;
|
|
1707
|
+
/** The builtin bucket this refines. */
|
|
1708
|
+
readonly base: ScalarKind;
|
|
1709
|
+
/** What this type means, for a model. */
|
|
1710
|
+
readonly instructions: string;
|
|
1711
|
+
/**
|
|
1712
|
+
* The declaration's own options as a parsed `FieldType` — the FLOOR a use
|
|
1713
|
+
* site is met against. Carries no refinement itself, so meeting it with a
|
|
1714
|
+
* site's type is a pure options meet.
|
|
1715
|
+
*/
|
|
1716
|
+
readonly declared: FieldType;
|
|
1717
|
+
/**
|
|
1718
|
+
* The options this refinement declares FOR ITSELF, in declaration order —
|
|
1719
|
+
* the vocabulary a column's `with` bag may name.
|
|
1720
|
+
*/
|
|
1721
|
+
readonly ownOptions: ReadonlyMap<string, CompiledFieldTypeOption>;
|
|
1722
|
+
/**
|
|
1723
|
+
* Which arms of the builtin comparison grammar this type admits, every arm
|
|
1724
|
+
* resolved (an omitted one defaults to `true`, i.e. the base's own grammar).
|
|
1725
|
+
*/
|
|
1726
|
+
readonly compare: Required<FieldTypeCompareDecl>;
|
|
1727
|
+
/** The `comparableWith` names AS DECLARED, before the registry symmetrizes them. */
|
|
1728
|
+
readonly declaredComparableWith: readonly string[];
|
|
1729
|
+
/** The declared average stored bytes, or `undefined` to keep the base's estimate. */
|
|
1730
|
+
readonly avgBytes: number | undefined;
|
|
1731
|
+
/** Per dialect name, the compiled `sql` template (base slots already resolved). */
|
|
1732
|
+
private readonly sqlTypes;
|
|
1733
|
+
/** Per dialect name, the compiled `cast` template (its `{value}` slots still open). */
|
|
1734
|
+
private readonly casts;
|
|
1735
|
+
/** Who declared it, when they said. */
|
|
1736
|
+
readonly declaredBy: string | undefined;
|
|
1737
|
+
private constructor();
|
|
1738
|
+
/**
|
|
1739
|
+
* The OTHER refinement names this type may be compared with — the declared
|
|
1740
|
+
* relation after the registry has symmetrized it. Mutable, and mutated ONLY by
|
|
1741
|
+
* {@link linkComparable}: an edge may be declared before the type on its far
|
|
1742
|
+
* end is registered, and both ends must end up carrying it whichever order
|
|
1743
|
+
* they arrive in.
|
|
1744
|
+
*/
|
|
1745
|
+
private readonly comparable;
|
|
1746
|
+
/**
|
|
1747
|
+
* Record a comparability edge to `other`. Registry-only — it is what makes the
|
|
1748
|
+
* relation symmetric, and it is called for BOTH ends of every edge, so no
|
|
1749
|
+
* declarer can produce a one-way one.
|
|
1750
|
+
*/
|
|
1751
|
+
linkComparable(other: string): void;
|
|
1752
|
+
/**
|
|
1753
|
+
* Whether a value of this type may be compared with one of the refinement
|
|
1754
|
+
* named `other` — itself always, plus every symmetrized declared edge.
|
|
1755
|
+
*
|
|
1756
|
+
* By NAME rather than by instance, unlike the meet. The meet has to be exact
|
|
1757
|
+
* because it hands back a type whose value gate and `sqlType` a caller then
|
|
1758
|
+
* uses; comparability only answers whether a predicate is meaningful, and
|
|
1759
|
+
* answering `true` for a same-named type compiled in another registry cannot
|
|
1760
|
+
* produce a wrong TYPE — the meet still refuses it.
|
|
1761
|
+
*/
|
|
1762
|
+
comparableTo(other: string): boolean;
|
|
1763
|
+
/** The declared own-option names, in declaration order (for messages and schemas). */
|
|
1764
|
+
ownOptionNames(): string[];
|
|
1765
|
+
/** The CODE half, when one has been registered (see {@link FieldTypeImpl}). */
|
|
1766
|
+
private impl;
|
|
1767
|
+
/**
|
|
1768
|
+
* The stricter value gate this refinement's IMPL supplies, or `undefined`.
|
|
1769
|
+
* Read by `FieldType.toValueSchema`, which conjoins it with the field's own.
|
|
1770
|
+
*/
|
|
1771
|
+
get value(): z.ZodTypeAny | undefined;
|
|
1772
|
+
/**
|
|
1773
|
+
* The in-memory ordering this refinement's IMPL supplies, or `undefined`.
|
|
1774
|
+
* Read by `FieldType.valueComparator`, which is what `Value.compareTo`
|
|
1775
|
+
* consults (see {@link FieldTypeImpl.compareValues}).
|
|
1776
|
+
*/
|
|
1777
|
+
get compareValues(): ValueComparator | undefined;
|
|
1778
|
+
/**
|
|
1779
|
+
* Attach the code half. Called only by `Registry.registerFieldTypeImpl`, which
|
|
1780
|
+
* owns the checks (that the impl is registered once, that a supplied `value`
|
|
1781
|
+
* is really a zod schema, that a supplied `compareValues` is really a
|
|
1782
|
+
* function, and that the catalog has not been parsed yet).
|
|
1783
|
+
*/
|
|
1784
|
+
attachImpl(impl: FieldTypeImpl): void;
|
|
1785
|
+
/** Whether a code half has already been attached (the registry's once-only check). */
|
|
1786
|
+
get hasImpl(): boolean;
|
|
1787
|
+
/**
|
|
1788
|
+
* Validate and compile a declaration. Every check is cheap because the
|
|
1789
|
+
* declaration is data, and every one of them refuses rather than warns: a
|
|
1790
|
+
* refinement that registered half-broken would be wrong on every column that
|
|
1791
|
+
* ever names it.
|
|
1792
|
+
*/
|
|
1793
|
+
static compile(def: FieldTypeRefinementDef, registry: Registry,
|
|
1794
|
+
/**
|
|
1795
|
+
* How the declared `options` become a `FieldType`. Supplied by the registry
|
|
1796
|
+
* rather than taken off it, because this road must NOT freeze the refinement
|
|
1797
|
+
* vocabulary — compiling the first declaration would otherwise refuse the
|
|
1798
|
+
* second (`Registry.parseFieldTypeUnflagged`).
|
|
1799
|
+
*/
|
|
1800
|
+
parseFieldType: (json: FieldTypeDef) => FieldType): FieldTypeRefinement;
|
|
1801
|
+
/**
|
|
1802
|
+
* The field type a use site declaring `as: <this>` resolves to — the MEET of
|
|
1803
|
+
* this refinement's declared options and the site's own, tagged with this
|
|
1804
|
+
* refinement.
|
|
1805
|
+
*
|
|
1806
|
+
* The meet is the whole enforcement: its result is a lower bound of BOTH, so a
|
|
1807
|
+
* site can only ever narrow, and a site whose options cannot coexist with the
|
|
1808
|
+
* declaration's has no meet and is refused here. No new lattice law is
|
|
1809
|
+
* introduced — `as` itself merges through the existing flat `meetExact`, in
|
|
1810
|
+
* which a registered name meets only itself and an unrefined base is TOP.
|
|
1811
|
+
*/
|
|
1812
|
+
refine(site: FieldType, withOptions?: Readonly<Record<string, JsonValue>>): FieldType;
|
|
1813
|
+
/**
|
|
1814
|
+
* A column's `with` bag, checked and canonicalized — or `undefined` when it
|
|
1815
|
+
* declares none.
|
|
1816
|
+
*
|
|
1817
|
+
* Checked HERE, where the def is read, for the same reason every other
|
|
1818
|
+
* declaration defect is: emit is the only other place the values are known,
|
|
1819
|
+
* and a refusal there has no declaration to point at. Canonicalized (keys
|
|
1820
|
+
* sorted, empty dropped) because `toJSON` feeds `meet`'s identity comparison
|
|
1821
|
+
* and a bag that serialized in insertion order would make two equal types
|
|
1822
|
+
* unequal.
|
|
1823
|
+
*/
|
|
1824
|
+
private checkOwnOptions;
|
|
1825
|
+
/**
|
|
1826
|
+
* The EFFECTIVE value of own option `key` for a column carrying `options` —
|
|
1827
|
+
* the column's own, else the declared `default`, else `undefined`.
|
|
1828
|
+
*
|
|
1829
|
+
* A default is resolved on READ rather than materialized into the bag, and
|
|
1830
|
+
* that is what keeps the flat lattice honest: materializing it would make a
|
|
1831
|
+
* column that said nothing carry `Geometry` and a column that said `Polygon`
|
|
1832
|
+
* CONFLICT with it, when the second is exactly the narrowing the first left
|
|
1833
|
+
* room for.
|
|
1834
|
+
*/
|
|
1835
|
+
optionValue(key: string, options: Readonly<Record<string, JsonValue>> | undefined): JsonValue | undefined;
|
|
1836
|
+
/** Every own option's effective value for a column carrying `options`, as interpolable tokens. */
|
|
1837
|
+
private optionTokens;
|
|
1838
|
+
/**
|
|
1839
|
+
* The declared SQL type for `dialect` on a column carrying `options`, or
|
|
1840
|
+
* `undefined` to keep the builtin's answer.
|
|
1841
|
+
*
|
|
1842
|
+
* Resolved per COLUMN rather than at registration, because an own option holds
|
|
1843
|
+
* a different value on every column — `geometry({subtype},{srid})` is
|
|
1844
|
+
* `geometry(Point,4326)` on one and `geometry(Polygon,3857)` on the next. Every
|
|
1845
|
+
* token it can splice was proved safe at registration (a closed declared type)
|
|
1846
|
+
* and again at parse (the value itself), so this cannot fail.
|
|
1847
|
+
*/
|
|
1848
|
+
sqlType(dialect: string, options?: Readonly<Record<string, JsonValue>>): string | undefined;
|
|
1849
|
+
/**
|
|
1850
|
+
* The declared cast for `dialect` as literal segments around the `{value}`
|
|
1851
|
+
* slot, or `undefined` to keep the base's cast. Own-option slots resolve
|
|
1852
|
+
* against `options`, exactly as {@link sqlType}'s do.
|
|
1853
|
+
*/
|
|
1854
|
+
cast(dialect: string, options?: Readonly<Record<string, JsonValue>>): readonly string[] | undefined;
|
|
1855
|
+
/**
|
|
1856
|
+
* The own-option names this refinement's `cast` for `dialect` INTERPOLATES, or
|
|
1857
|
+
* an empty set.
|
|
1858
|
+
*
|
|
1859
|
+
* Asked by a VALUE position, which is not a column and therefore has no
|
|
1860
|
+
* honest value for those slots. {@link cast} fills them from the column's own
|
|
1861
|
+
* bag ELSE the option's declared DEFAULT, and that default-fill is exactly
|
|
1862
|
+
* right for a column (it is a fact about that column) and exactly wrong for a
|
|
1863
|
+
* value: a default is the TYPE's, not this value's, so filling it PINS a
|
|
1864
|
+
* constraint the value was never required to satisfy — measured, a
|
|
1865
|
+
* `geometry(Point,4326)` typmod cast applied to a Polygon document, which
|
|
1866
|
+
* PostGIS rejects outright.
|
|
1867
|
+
*
|
|
1868
|
+
* This is the same rule the model-facing renderer follows for an operand
|
|
1869
|
+
* (`llm/describe.ts`'s `'operand'` tag style shows only what a declaration
|
|
1870
|
+
* WROTE, never the refinement's defaults). One rule, two surfaces: what a
|
|
1871
|
+
* declaration did not write is not a constraint anyone may assert on its
|
|
1872
|
+
* behalf.
|
|
1873
|
+
*/
|
|
1874
|
+
castOptions(dialect: string): ReadonlySet<string>;
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* The `as` KEY of one builtin branch's generated def schema — a `z.enum` of the
|
|
1878
|
+
* refinements registered over THAT base, or a key that REFUSES any value when
|
|
1879
|
+
* none are.
|
|
1880
|
+
*
|
|
1881
|
+
* This is what makes the vocabulary REAL rather than advisory. The def schema is
|
|
1882
|
+
* what a model authors a Type against, and it was built from the static
|
|
1883
|
+
* `BUILTIN_FIELD_TYPES` array — so with an open `as: string` a model would be
|
|
1884
|
+
* free to invent `{kind:'text', as:'uuid4'}` and only find out at parse. Offered
|
|
1885
|
+
* as an enum, the only names it can write are names that exist.
|
|
1886
|
+
*
|
|
1887
|
+
* Filtered BY BASE, because a refinement of `text` is not a choice a `number`
|
|
1888
|
+
* field has; and each name carries its `instructions` inline, because a bare
|
|
1889
|
+
* list of names tells a model what it may write and not what any of them mean.
|
|
1890
|
+
* The names render VERBATIM — a model reads this surface and a sibling type
|
|
1891
|
+
* system's in one session, and a spelling difference between them reads as two
|
|
1892
|
+
* different types.
|
|
1893
|
+
*
|
|
1894
|
+
* THE EMPTY CASE IS A REFUSAL, NOT AN OMISSION, and the difference is the whole
|
|
1895
|
+
* point of the key. Omitting it let zod STRIP an `as` a model wrote on a base
|
|
1896
|
+
* with no registrations — and the normal pipeline is `Tool.parse` →
|
|
1897
|
+
* `engine.parseType(result)`, so `parseType` never sees the raw def and the loud
|
|
1898
|
+
* `field-type.unknown-refinement` never fires. The identical mistake was caught
|
|
1899
|
+
* on `text` and silently discarded on `json`.
|
|
1900
|
+
*
|
|
1901
|
+
* `z.never()` refuses any value while `.optional()` keeps the key absent-able,
|
|
1902
|
+
* and it is the right refusal for two reasons: `z.undefined()` is
|
|
1903
|
+
* UNREPRESENTABLE in JSON Schema (it throws, and under `unrepresentable: 'any'`
|
|
1904
|
+
* it renders as "permit anything" — the opposite of the intent), whereas `never`
|
|
1905
|
+
* renders as `{"not":{}}`. That is true of ONE BRANCH's schema; converting the
|
|
1906
|
+
* whole `fieldTypeDefSchema` union is a separate, pre-existing matter (see the
|
|
1907
|
+
* known limit in `CHANGELOG.md`).
|
|
1908
|
+
*
|
|
1909
|
+
* Returns a spreadable fragment rather than a schema so a branch declares the
|
|
1910
|
+
* key exactly where it declares the rest of its wire shape.
|
|
1911
|
+
*/
|
|
1912
|
+
declare function refinementKeySchema(base: ScalarKind, opts?: SchemaOptions): {
|
|
1913
|
+
as: z.ZodTypeAny;
|
|
1914
|
+
with: z.ZodTypeAny;
|
|
1915
|
+
};
|
|
1916
|
+
|
|
1917
|
+
/**
|
|
1918
|
+
* Shared helpers for a field type's CLOSED VALUE SET (`values`) — the enum the
|
|
1919
|
+
* `text` and `number` scalars express as a constraint ON themselves rather than
|
|
1920
|
+
* as a separate field-type `kind`.
|
|
1921
|
+
*
|
|
1922
|
+
* Membership is a QUERY fact, not a display one: it decides equality
|
|
1923
|
+
* selectivity, it is the highest-value line the model can be told about a
|
|
1924
|
+
* `where` clause, it is what a WRITE to the column is checked against
|
|
1925
|
+
* ({@link isClosedSetMember}), it is the narrowing a bind param inherits from
|
|
1926
|
+
* its uses ({@link meetFieldValues}), and it is the honest answer for
|
|
1927
|
+
* `toValueSchema()`. The human-facing `label` rides along with each member so
|
|
1928
|
+
* one closed set has one home (see `FieldValueDef`).
|
|
1929
|
+
*/
|
|
1930
|
+
|
|
1931
|
+
/**
|
|
1932
|
+
* A closed-set violation found inside a written value: the offending value, the
|
|
1933
|
+
* set it had to belong to, and WHERE it sits — an empty `at` for the value
|
|
1934
|
+
* itself, or the array indices leading to it (outermost first) when the set is
|
|
1935
|
+
* declared on a container's ELEMENT type.
|
|
1936
|
+
*
|
|
1937
|
+
* Structured rather than a rendered string so the message lives at the ONE place
|
|
1938
|
+
* that knows the column's name (`validateWriteValue`), instead of every field
|
|
1939
|
+
* type re-deriving the same sentence.
|
|
1940
|
+
*/
|
|
1941
|
+
interface ClosedSetViolation {
|
|
1942
|
+
/** Array indices from the written value down to the offender; empty = the value itself. */
|
|
1943
|
+
readonly at: readonly number[];
|
|
1944
|
+
/** The value that is not a member. */
|
|
1945
|
+
readonly value: JsonValue;
|
|
1946
|
+
/** The set it had to belong to. */
|
|
1947
|
+
readonly values: readonly FieldValueDef[];
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1104
1950
|
/**
|
|
1105
1951
|
* Abstract `FieldType` base class + the `FieldTypeClass` static contract.
|
|
1106
1952
|
*
|
|
@@ -1115,13 +1961,19 @@ declare class QueryTypeError extends Error {
|
|
|
1115
1961
|
* map — never a central switch in this file.
|
|
1116
1962
|
*/
|
|
1117
1963
|
|
|
1964
|
+
/**
|
|
1965
|
+
* The underlying primitive categories, as an array — the source of both the
|
|
1966
|
+
* {@link ScalarKind} union and the runtime membership check a refinement's
|
|
1967
|
+
* `base` is held to.
|
|
1968
|
+
*/
|
|
1969
|
+
declare const SCALAR_KINDS: readonly ["number", "text", "bool", "date", "timestamp", "json", "money", "relation", "array"];
|
|
1118
1970
|
/**
|
|
1119
1971
|
* The underlying primitive category a field type resolves to. This is the
|
|
1120
1972
|
* comparability / SQL-bucket of the type, distinct from the richer `kind`
|
|
1121
1973
|
* (e.g. both `number` and `money` are numeric, but `money` is its own
|
|
1122
1974
|
* kind). Used by `comparableWith`, cost estimation, and SQL emission.
|
|
1123
1975
|
*/
|
|
1124
|
-
type ScalarKind =
|
|
1976
|
+
type ScalarKind = (typeof SCALAR_KINDS)[number];
|
|
1125
1977
|
/**
|
|
1126
1978
|
* Static-side contract every concrete FieldType class satisfies, so the
|
|
1127
1979
|
* Registry can dispatch JSON parsing by `kind`. Analogous to gin's
|
|
@@ -1149,48 +2001,333 @@ interface FieldTypeClass {
|
|
|
1149
2001
|
declare abstract class FieldType implements Node {
|
|
1150
2002
|
/** The `kind` discriminant (matches the subclass's `static NAME`). */
|
|
1151
2003
|
abstract readonly kind: FieldTypeKind;
|
|
1152
|
-
/**
|
|
1153
|
-
|
|
1154
|
-
/**
|
|
1155
|
-
|
|
2004
|
+
/** The refinement this instance carries; set only through {@link withRefinement}. */
|
|
2005
|
+
private declaredRefinement;
|
|
2006
|
+
/**
|
|
2007
|
+
* This COLUMN's values for the options the refinement declares for ITSELF
|
|
2008
|
+
* (`{ subtype: 'Polygon' }`), canonicalized (keys sorted) and holding only
|
|
2009
|
+
* what the column actually said — a defaulted option is absent here and
|
|
2010
|
+
* resolved on read (`FieldTypeRefinement.optionValue`).
|
|
2011
|
+
*
|
|
2012
|
+
* A separate bag from the builtin's own options because the two are validated
|
|
2013
|
+
* by different declarations, and because the flat lattice they meet through is
|
|
2014
|
+
* not the one the builtin's bag meets through. `undefined` for every unrefined
|
|
2015
|
+
* type and for every refined one that took all its defaults, so an existing
|
|
2016
|
+
* def serializes exactly as it did.
|
|
2017
|
+
*/
|
|
2018
|
+
private declaredOptions;
|
|
2019
|
+
/** The registered refinement narrowing this type, or `undefined` for a plain builtin. */
|
|
2020
|
+
get refinement(): FieldTypeRefinement | undefined;
|
|
2021
|
+
/**
|
|
2022
|
+
* The registered refinement's NAME — the `as` on the wire — or `undefined`.
|
|
2023
|
+
* It renders VERBATIM wherever a model sees it.
|
|
2024
|
+
*/
|
|
2025
|
+
get as(): string | undefined;
|
|
2026
|
+
/** This column's own values for its refinement's declared options — the `with` bag, or `undefined`. */
|
|
2027
|
+
get refinementOptions(): Readonly<Record<string, JsonValue>> | undefined;
|
|
2028
|
+
/**
|
|
2029
|
+
* The EFFECTIVE value of the refinement option `key` — this column's own, else
|
|
2030
|
+
* the refinement's declared default, else `undefined`. The one accessor every
|
|
2031
|
+
* consumer (SQL emission, the description, the meet) asks, so "the column said
|
|
2032
|
+
* nothing" and "the type's default" can never diverge.
|
|
2033
|
+
*/
|
|
2034
|
+
refinementOption(key: string): JsonValue | undefined;
|
|
2035
|
+
/**
|
|
2036
|
+
* A COPY of this type tagged with `refinement` and its `options` (or `this`,
|
|
2037
|
+
* when it already carries exactly those).
|
|
2038
|
+
*
|
|
2039
|
+
* The CHECKED road is `Registry.parseFieldType` / `FieldTypeRefinement.refine`,
|
|
2040
|
+
* which meets the site's options against the declaration's and validates the
|
|
2041
|
+
* `with` bag before tagging. This is the unchecked constructor half — same
|
|
2042
|
+
* caveat as `new TextFieldType({...})`, which does not validate either.
|
|
2043
|
+
*/
|
|
2044
|
+
withRefinement(refinement: FieldTypeRefinement | undefined, options?: Readonly<Record<string, JsonValue>>): FieldType;
|
|
2045
|
+
/**
|
|
2046
|
+
* Serialize to the matching `*FieldTypeDef` JSON branch, plus the `as` of any
|
|
2047
|
+
* refinement it carries. Appended LAST and only when present, so an unrefined
|
|
2048
|
+
* type serializes byte-for-byte as it always did — which matters because
|
|
2049
|
+
* `meet` compares two types by their serialized form.
|
|
2050
|
+
*/
|
|
2051
|
+
toJSON(): FieldTypeDef;
|
|
2052
|
+
/** The BUILTIN's own JSON def, without any refinement key. */
|
|
2053
|
+
protected abstract builtinJSON(): FieldTypeDef;
|
|
2054
|
+
/**
|
|
2055
|
+
* `own` with this type's `as` appended, or `own` unchanged. Generic in the
|
|
2056
|
+
* BRANCH, so a concrete class can re-declare `toJSON()` with its own
|
|
2057
|
+
* `*FieldTypeDef` return type and route through here without losing it.
|
|
2058
|
+
*
|
|
2059
|
+
* The base's `toJSON()` above is what makes those re-declarations a pure TYPE
|
|
2060
|
+
* refinement rather than a rule a new class can forget: a class that declares
|
|
2061
|
+
* no `toJSON()` of its own still serializes its refinement.
|
|
2062
|
+
*/
|
|
2063
|
+
protected withRefinementKey<T extends FieldTypeDef>(own: T): T;
|
|
2064
|
+
/** Deep-copy this field type, refinement included. */
|
|
2065
|
+
clone(): FieldType;
|
|
2066
|
+
/** Deep-copy the BUILTIN half — the options bag and nothing else. */
|
|
2067
|
+
protected abstract builtinClone(): FieldType;
|
|
2068
|
+
/** `copy` carrying THIS type's refinement and its options — the shared half of {@link clone}. */
|
|
2069
|
+
protected sameRefinement<T extends FieldType>(copy: T): T;
|
|
2070
|
+
/**
|
|
2071
|
+
* The refinement's declared SQL type for `dialect` — resolved against THIS
|
|
2072
|
+
* column's own options — or `undefined` to keep the builtin's answer.
|
|
2073
|
+
*
|
|
2074
|
+
* On the FieldType rather than read off `refinement` directly, because the
|
|
2075
|
+
* option values live here: `Dialect.sqlTypeFor` would otherwise have to know
|
|
2076
|
+
* that a refinement's template takes a bag, and every dialect would have to
|
|
2077
|
+
* remember to pass it.
|
|
2078
|
+
*/
|
|
2079
|
+
refinedSqlType(dialect: string): string | undefined;
|
|
2080
|
+
/** The refinement's declared cast for `dialect`, resolved against this column's own options. */
|
|
2081
|
+
refinedCast(dialect: string): readonly string[] | undefined;
|
|
2082
|
+
/**
|
|
2083
|
+
* The declared-cast options THIS instance has not written a value for — the
|
|
2084
|
+
* ones {@link refinedCast} would fill from the refinement's DEFAULTS.
|
|
2085
|
+
*
|
|
2086
|
+
* Empty for a cast that interpolates nothing, and empty for an instance whose
|
|
2087
|
+
* own `with` bag covers every slot. Non-empty means "this cast can only be
|
|
2088
|
+
* resolved by asserting something the declaration did not say", which a COLUMN
|
|
2089
|
+
* may do (a default is a fact about the column) and a VALUE may not — see
|
|
2090
|
+
* {@link FieldTypeRefinement.castOptions}, and `refuseUnwrittenCast` in
|
|
2091
|
+
* `sql/dialect.ts`, which reads this. (The refusal lives in the DIALECT, not
|
|
2092
|
+
* at the operand's emit site, because a dialect binding a native array
|
|
2093
|
+
* re-enters `jsonValue` per ELEMENT.)
|
|
2094
|
+
*/
|
|
2095
|
+
uncastableOptions(dialect: string): string[];
|
|
1156
2096
|
/** The underlying primitive category this type resolves to. */
|
|
1157
2097
|
abstract resolve(): ScalarKind;
|
|
1158
2098
|
/**
|
|
1159
2099
|
* Whether a value of this type can be meaningfully compared with one of
|
|
1160
|
-
* `other
|
|
1161
|
-
*
|
|
1162
|
-
*
|
|
2100
|
+
* `other` — the builtin category rule, PLUS any edge the two types'
|
|
2101
|
+
* refinements declare (`comparableWith`).
|
|
2102
|
+
*
|
|
2103
|
+
* FINAL, and the declared half is added here rather than in the subclasses so
|
|
2104
|
+
* a builtin that narrows the rule (`json` compares only with `json`) cannot
|
|
2105
|
+
* accidentally shut a declared edge out. Subclasses override
|
|
2106
|
+
* {@link builtinComparableWith}.
|
|
2107
|
+
*
|
|
2108
|
+
* The declared half only ever ADDS. That is what keeps "a meet implies
|
|
2109
|
+
* comparability" true with no carve-out: a superset of a relation the meet was
|
|
2110
|
+
* already inside is still a superset (see `FieldTypeRefinementDefFor.comparableWith`).
|
|
1163
2111
|
*/
|
|
1164
2112
|
comparableWith(other: FieldType): boolean;
|
|
2113
|
+
/**
|
|
2114
|
+
* The BUILTIN comparability rule: same category, with number/money and
|
|
2115
|
+
* date/timestamp treated as mutually comparable families. Subclasses override
|
|
2116
|
+
* for stricter or looser rules.
|
|
2117
|
+
*/
|
|
2118
|
+
protected builtinComparableWith(other: FieldType): boolean;
|
|
2119
|
+
/**
|
|
2120
|
+
* Whether EVERY value this type admits renders as a bare SQL token
|
|
2121
|
+
* (`^[A-Za-z0-9_]+$`) — the question `registerFieldType` asks of an option a
|
|
2122
|
+
* `sql` / `cast` template interpolates, since a template's values are its
|
|
2123
|
+
* whole injection surface.
|
|
2124
|
+
*
|
|
2125
|
+
* Declared ON THE TYPE rather than as a switch over kinds in `refinement.ts`,
|
|
2126
|
+
* so a tenth field type answers for itself instead of falling into whichever
|
|
2127
|
+
* arm a `default:` happened to pick. The default answer is the closed set's: a
|
|
2128
|
+
* type with a `values` set admits exactly those, so it is token-safe when they
|
|
2129
|
+
* all are, and a type with no set admits an unbounded range and is not.
|
|
2130
|
+
*/
|
|
2131
|
+
tokenSafeValues(): boolean;
|
|
2132
|
+
/**
|
|
2133
|
+
* Whether a value of this type participates in FULL-TEXT search — the fact
|
|
2134
|
+
* `Type.isFieldSearchable` / `Type.isSearchable` and the `text-search` schema
|
|
2135
|
+
* gating ask.
|
|
2136
|
+
*
|
|
2137
|
+
* `false` by default: full-text indexing is a declared artifact, and a type
|
|
2138
|
+
* that has not said it produces one does not. Only `text` overrides it today.
|
|
2139
|
+
* An `array<text search:true>` therefore answers `false` — the ELEMENT is
|
|
2140
|
+
* indexed, the array is not, which is the behaviour that shipped; the seam is
|
|
2141
|
+
* what makes changing that a one-line decision rather than a survey.
|
|
2142
|
+
*/
|
|
2143
|
+
isSearchable(): boolean;
|
|
2144
|
+
/**
|
|
2145
|
+
* Whether a value of this type is embedded for SEMANTIC scoring — the fact
|
|
2146
|
+
* `Type.isFieldSemantic` / `Type.semanticFields` and the `semantic` expr ask.
|
|
2147
|
+
*
|
|
2148
|
+
* `search` implies it: a full-text index is the same kind of derived artifact,
|
|
2149
|
+
* and a deployment that maintains one maintains the embedding beside it. A
|
|
2150
|
+
* RELATION is not semantic here even though a `semantic` expr may TARGET one
|
|
2151
|
+
* (`Field.allowsExpr`) — the two are different questions, and conflating them
|
|
2152
|
+
* made every Type with a foreign key report itself semantic-eligible.
|
|
2153
|
+
*/
|
|
2154
|
+
isSemantic(): boolean;
|
|
2155
|
+
/**
|
|
2156
|
+
* The ELEMENT type of a CONTAINER, or `undefined` for a scalar — and for a
|
|
2157
|
+
* container that declares no element type, which is a real state (`{kind:
|
|
2158
|
+
* 'array'}` with no `item` is a heterogeneous array, emitted as `jsonb`).
|
|
2159
|
+
*
|
|
2160
|
+
* So it is an ACCESSOR, not the container test: `resolve() === 'array'` is
|
|
2161
|
+
* what gates `array-op`, and an item-less array must still be allowed one.
|
|
2162
|
+
*/
|
|
2163
|
+
itemType(): FieldType | undefined;
|
|
2164
|
+
/**
|
|
2165
|
+
* The CLOSED SET of values THIS type admits, or `undefined` when it declares
|
|
2166
|
+
* none (the unconstrained default). Total on the value-category union so
|
|
2167
|
+
* every consumer of membership — equality selectivity, the model-facing
|
|
2168
|
+
* description, `toValueSchema`, the write check, the param meet — asks ONE
|
|
2169
|
+
* question instead of testing for the classes that happen to carry a `values`
|
|
2170
|
+
* option today.
|
|
2171
|
+
*
|
|
2172
|
+
* It is deliberately NOT recursive. A CONTAINER declares no set of its own —
|
|
2173
|
+
* an `array<text one of a|b>` admits ARRAYS, not `a` and `b` — so surfacing
|
|
2174
|
+
* its element's set here would make `eqSelectivity` answer `1/n` for a
|
|
2175
|
+
* predicate that compares whole arrays, and would render the column as
|
|
2176
|
+
* `array one of a|b`. The element's set reaches the behaviours that DO make
|
|
2177
|
+
* sense for a container by other roads: `toValueSchema` validates
|
|
2178
|
+
* element-wise, {@link closedSetViolation} walks into elements, `meet` meets
|
|
2179
|
+
* element types, and the description renders the item type inside `array<…>`.
|
|
2180
|
+
*/
|
|
2181
|
+
values(): readonly FieldValueDef[] | undefined;
|
|
2182
|
+
/**
|
|
2183
|
+
* The first closed-set violation in `raw`, or `undefined` when there is none.
|
|
2184
|
+
* The recursive counterpart to {@link values}: it answers for a whole written
|
|
2185
|
+
* VALUE, so a container walks into its elements.
|
|
2186
|
+
*
|
|
2187
|
+
* It exists because the write check cannot be one accessor deep. Asking only
|
|
2188
|
+
* `values()` accepted `SET tags = ['bogus']` on an `array<text one of a|b>`
|
|
2189
|
+
* silently — while that column's own `toValueSchema()` rejected the very same
|
|
2190
|
+
* array — so a value the type refused reached SQL. Asking `validValue(raw)`
|
|
2191
|
+
* instead would have over-reached in the other direction, turning every
|
|
2192
|
+
* declared bound (`minLength`, `min`/`max`) into a write-time refusal, which
|
|
2193
|
+
* is a different feature. This asks exactly the membership question, at every
|
|
2194
|
+
* depth.
|
|
2195
|
+
*/
|
|
2196
|
+
closedSetViolation(raw: JsonValue): ClosedSetViolation | undefined;
|
|
1165
2197
|
/**
|
|
1166
2198
|
* The fraction of rows a non-indexed EQUALITY predicate on a column of this
|
|
1167
2199
|
* type is expected to keep, when the type itself knows better than the
|
|
1168
2200
|
* package-wide `EQ_SELECTIVITY` guess. A closed value set of `n` members
|
|
1169
2201
|
* answers `1/n`: a two-value flag keeps half the table, a fifty-value code
|
|
1170
|
-
* keeps 2% —
|
|
1171
|
-
*
|
|
2202
|
+
* keeps 2% — otherwise both would be costed at the same fixed third.
|
|
2203
|
+
* `undefined` means "no better estimate; use the fixed one".
|
|
2204
|
+
*
|
|
2205
|
+
* Derived from {@link values} rather than overridden per class, so a type
|
|
2206
|
+
* that declares a closed set cannot forget to declare its selectivity —
|
|
2207
|
+
* `money` did exactly that, carrying a `values` set through its inner
|
|
2208
|
+
* `NumberOptions` and still costing `= x` at the fixed guess.
|
|
1172
2209
|
*/
|
|
1173
2210
|
eqSelectivity(): number | undefined;
|
|
1174
2211
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
2212
|
+
* The MEET of this type and `other`: the most specific type whose values
|
|
2213
|
+
* satisfy BOTH, or `undefined` when no such type exists.
|
|
2214
|
+
*
|
|
2215
|
+
* The constructive form of {@link comparableWith} — and a STRICTLY stronger
|
|
2216
|
+
* question. `comparableWith` asks whether the two live in the same value
|
|
2217
|
+
* category; a meet also has to reconcile their CONSTRAINTS, so two `text`
|
|
2218
|
+
* types with disjoint closed sets are comparable and have no meet. (The
|
|
2219
|
+
* converse never happens: a meet implies comparability.) A custom FieldType
|
|
2220
|
+
* that widens `comparableWith` should override {@link meetWith} to match, or
|
|
2221
|
+
* the two answers drift apart.
|
|
2222
|
+
*
|
|
2223
|
+
* It exists for bind params, which are typed from EVERY place they are used
|
|
2224
|
+
* (`ParamSet`): `enum ⊓ text = enum`, `text{minLength:5} ⊓ text{maxLength:10}`
|
|
2225
|
+
* carries both bounds, and `enum{a,b} ⊓ enum{b,c} = enum{b}`. The operation is
|
|
2226
|
+
* commutative, associative and idempotent — see `field-types/_meet.ts` — which
|
|
2227
|
+
* is what makes the inferred type independent of the order the walk happened
|
|
2228
|
+
* to visit the uses in. It is also SOUND: the meet accepts nothing that both
|
|
2229
|
+
* operands do not. All four are property-tested (`param-meet.test.ts`).
|
|
2230
|
+
*
|
|
2231
|
+
* IT IS THE *GREATEST* LOWER BOUND FOR EVERY TYPE BUILT THROUGH `from` — AND
|
|
2232
|
+
* ONLY A LOWER BOUND FOR ONE BUILT BY HAND. The distinction is the whole of
|
|
2233
|
+
* the caveat, so it is worth stating exactly.
|
|
2234
|
+
*
|
|
2235
|
+
* A closed set IS the value schema (`toValueSchema` short-circuits on it), so
|
|
2236
|
+
* a meet narrows a merged set by the merged scalar constraints. For a
|
|
2237
|
+
* SELF-INCONSISTENT type — one whose own set and own constraints disagree —
|
|
2238
|
+
* that narrowing bites even against the unconstrained type of its own kind:
|
|
2239
|
+
*
|
|
2240
|
+
* x = new TextFieldType({ values:['ab'], minLength:5 })
|
|
2241
|
+
* x.validValue('ab') ⇒ true (the set short-circuits the bound)
|
|
2242
|
+
* x ⊓ text ⇒ undefined (not x)
|
|
2243
|
+
*
|
|
2244
|
+
* The narrowing itself is not optional — keeping `1` from
|
|
2245
|
+
* `text{values:[1,'b']} ⊓ text` would ADMIT a value plain `text` refuses, i.e.
|
|
2246
|
+
* break soundness, which is the law a validator actually depends on. So the
|
|
2247
|
+
* declaration is what had to go: since `0.6.6` such a set is REFUSED where
|
|
2248
|
+
* declarations are read (`field-type.bad-values` from `from` / `parseType`,
|
|
2249
|
+
* plus a per-kind member schema that no longer offers a `number` field a text
|
|
2250
|
+
* member). Over everything a DEF can express, `x ⊓ ⊤ = x` therefore holds
|
|
2251
|
+
* unconditionally, and `param.conflict` can no longer blame a query for a
|
|
2252
|
+
* defect in the type.
|
|
2253
|
+
*
|
|
2254
|
+
* The public CONSTRUCTORS still do not validate — the same caveat
|
|
2255
|
+
* `TextOptions.pattern` carries for an uncompilable regex — so
|
|
2256
|
+
* `new TextFieldType({ values:['ab'], minLength:5 })` remains buildable and
|
|
2257
|
+
* remains a lower bound only. `param-meet.test.ts` asserts the law over a type
|
|
2258
|
+
* set it first proves `parseFieldType` can build, and exercises the hand-built
|
|
2259
|
+
* road separately, so neither half can rot into the other.
|
|
2260
|
+
*/
|
|
2261
|
+
meet(other: FieldType): FieldType | undefined;
|
|
2262
|
+
/**
|
|
2263
|
+
* The kind-specific half of {@link meet}, reached only for two types that are
|
|
2264
|
+
* NOT already identical. A type carrying options overrides it to reconcile
|
|
2265
|
+
* them, and a type comparable ACROSS kinds (`number`/`money`,
|
|
2266
|
+
* `date`/`timestamp`) delegates to whichever side is the more specific.
|
|
2267
|
+
*
|
|
2268
|
+
* The default is "no meet", which is exactly right for a kind with NO
|
|
2269
|
+
* options — two such types are always JSON-identical, so `meet` has already
|
|
2270
|
+
* answered and this is never reached for them — and deliberately fail-LOUD
|
|
2271
|
+
* for a kind that gains options and forgets to override: reporting a spurious
|
|
2272
|
+
* `param.conflict` is visible, whereas the tempting default of "same kind ⇒
|
|
2273
|
+
* return `this`" would silently pick the left operand, which is the
|
|
2274
|
+
* order-dependence this whole mechanism exists to remove.
|
|
2275
|
+
*/
|
|
2276
|
+
protected meetWith(_other: FieldType): FieldType | undefined;
|
|
2277
|
+
/**
|
|
2278
|
+
* The {@link TextCasing} this type DECLARES for textual matching /
|
|
2279
|
+
* comparison, or `undefined` when it declares none — in which case the
|
|
2280
|
+
* engine's `textCasing` default applies (see `text-casing.ts`).
|
|
2281
|
+
*
|
|
2282
|
+
* `undefined` is a distinct answer from any of the three casings, and the
|
|
2283
|
+
* distinction is what keeps a declaration authoritative: a type that says
|
|
2284
|
+
* nothing INHERITS the deployment's default, and can never out-vote a field
|
|
2285
|
+
* that did say something. Only `text` declares one; every other kind
|
|
2286
|
+
* case-folds nothing, so the question is moot for it — a comparison with a
|
|
2287
|
+
* non-text operand never consults a casing at all.
|
|
2288
|
+
*/
|
|
2289
|
+
textCasing(): TextCasing | undefined;
|
|
2290
|
+
/**
|
|
2291
|
+
* The IN-MEMORY ordering this type declares, or `undefined` — the hook
|
|
2292
|
+
* `Value.compareTo` consults before its own rules.
|
|
2293
|
+
*
|
|
2294
|
+
* FINAL, and answered from the refinement rather than overridable per class,
|
|
2295
|
+
* which is the opposite of {@link textCasing} and deliberately so. A casing is
|
|
2296
|
+
* a BUILTIN option (`text` declares one, and the refinement narrows it through
|
|
2297
|
+
* the ordinary options meet), so the class is the right owner. A comparator is
|
|
2298
|
+
* not an option at all — it is the CODE half a declaration cannot carry, and
|
|
2299
|
+
* the nine builtins each have a comparison rule `Value` implements directly.
|
|
2300
|
+
* Leaving it overridable would invite a tenth builtin to answer here instead
|
|
2301
|
+
* of in `Value`, where the pair of roads is kept in agreement.
|
|
1179
2302
|
*/
|
|
1180
|
-
|
|
2303
|
+
valueComparator(): ValueComparator | undefined;
|
|
1181
2304
|
/**
|
|
1182
2305
|
* Zod schema for a raw JS VALUE of this field type, honoring options
|
|
1183
2306
|
* (e.g. number min/max/int, text length/pattern). Distinct from the
|
|
1184
2307
|
* static `toSchema`, which schemas the JSON *definition*.
|
|
2308
|
+
*
|
|
2309
|
+
* A refinement's declared `value` is applied as a CONJUNCTION, never as a
|
|
2310
|
+
* replacement. It is a stricter gate on the BASE, but a use site may narrow
|
|
2311
|
+
* further (`{kind:'text', as:'uuid', pattern:'^a'}`), and answering with the
|
|
2312
|
+
* declaration's schema alone would ADMIT a value the field's own options
|
|
2313
|
+
* refuse — i.e. break the soundness law the meet is property-tested against.
|
|
1185
2314
|
*/
|
|
1186
|
-
|
|
2315
|
+
toValueSchema(opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
2316
|
+
/** The BUILTIN's own value schema, before any refinement narrows it. */
|
|
2317
|
+
protected abstract builtinValueSchema(opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
1187
2318
|
/**
|
|
1188
2319
|
* Whether `raw` is a valid value of this type. Default: delegate to
|
|
1189
2320
|
* `toValueSchema`. Subclasses rarely need to override.
|
|
1190
2321
|
*/
|
|
1191
2322
|
validValue(raw: JsonValue): boolean;
|
|
1192
|
-
/**
|
|
1193
|
-
|
|
2323
|
+
/**
|
|
2324
|
+
* Estimated average bytes a value of this type occupies — a refinement's
|
|
2325
|
+
* declared estimate when it has one (a `uuid` stores 16 bytes, not the 32 an
|
|
2326
|
+
* unbounded `text` is guessed at), else the builtin's.
|
|
2327
|
+
*/
|
|
2328
|
+
avgBytes(): number;
|
|
2329
|
+
/** The BUILTIN's own byte estimate, before any refinement corrects it. */
|
|
2330
|
+
protected abstract builtinAvgBytes(): number;
|
|
1194
2331
|
/**
|
|
1195
2332
|
* A neutral base SQL type name for this field type. Phase 5 dialects may
|
|
1196
2333
|
* override per-dialect; to avoid a phase-5 dependency this signature
|
|
@@ -1213,6 +2350,37 @@ declare abstract class FieldType implements Node {
|
|
|
1213
2350
|
* getter so a dialect INSTANCE can be registered directly.
|
|
1214
2351
|
*/
|
|
1215
2352
|
|
|
2353
|
+
/**
|
|
2354
|
+
* WHO a value being bound belongs to — supplied by a VALUE position, absent for
|
|
2355
|
+
* a COLUMN, and the distinction is what decides whether a declared `cast` may
|
|
2356
|
+
* fill an option the target did not write.
|
|
2357
|
+
*
|
|
2358
|
+
* - **a COLUMN** (`site` absent) — a real column. Its refinement's option
|
|
2359
|
+
* DEFAULTS are facts about it, so a cast may resolve them; that is what makes
|
|
2360
|
+
* a write cell emit `ST_GeomFromGeoJSON($1)::geometry(Polygon,4326)`.
|
|
2361
|
+
* - **a VALUE** (`site` present) — a declared type standing in for "any value
|
|
2362
|
+
* of this type", which is what an operator OPERAND is. Filling a slot from
|
|
2363
|
+
* the refinement's default PINS a constraint the value was never required to
|
|
2364
|
+
* satisfy: measured on the flagship predicate, an operand declaring
|
|
2365
|
+
* `{kind:'json', as:'Geometry'}` with no `with` cast a Polygon document to
|
|
2366
|
+
* `::geometry(Point,4326)` — a PostGIS TYPMOD — and the server refused it
|
|
2367
|
+
* (`Geometry type (Polygon) does not match column type (Point)`).
|
|
2368
|
+
*
|
|
2369
|
+
* It is the same rule the model-facing renderer already follows: an operand's
|
|
2370
|
+
* tag shows only what its declaration WROTE. One rule, two surfaces.
|
|
2371
|
+
*
|
|
2372
|
+
* IT CARRIES THE OPERATOR AS WELL AS THE OPERAND, because the refusal is a
|
|
2373
|
+
* message to a DECLARER and the operand name alone does not identify a
|
|
2374
|
+
* declaration: two registered operators both having a `right` gave `… at
|
|
2375
|
+
* args.right` twice and named neither. The precedent is one screen away in
|
|
2376
|
+
* `OperatorExpr.toSQL` — *"Operator '&&' is missing required operand 'right'"*.
|
|
2377
|
+
*/
|
|
2378
|
+
interface ValueSite {
|
|
2379
|
+
/** The registered operator this value is an operand of. */
|
|
2380
|
+
readonly operator: string;
|
|
2381
|
+
/** The declared operand name — the `args` key, and the emit template's slot. */
|
|
2382
|
+
readonly operand: string;
|
|
2383
|
+
}
|
|
1216
2384
|
declare abstract class Dialect implements DialectEntry {
|
|
1217
2385
|
/** The dialect's canonical name (e.g. `'base'`, `'postgres'`). */
|
|
1218
2386
|
abstract readonly name: string;
|
|
@@ -1265,6 +2433,14 @@ declare abstract class Dialect implements DialectEntry {
|
|
|
1265
2433
|
* `<tsv> @@ plainto_tsquery(<language>, <query>)` (default `language`
|
|
1266
2434
|
* `'english'`); the base dialect has no tsvector type and DEGRADES to a
|
|
1267
2435
|
* case-insensitive substring `LIKE` (ignoring `language`).
|
|
2436
|
+
*
|
|
2437
|
+
* NO `sensitive` / casing parameter, deliberately. A stored tsvector has
|
|
2438
|
+
* ALREADY been folded and stemmed, so an `'exact'` casing is not
|
|
2439
|
+
* expressible over one at any price, and `@@` ignores case unconditionally.
|
|
2440
|
+
* The base dialect's `LOWER(...)` degrade therefore matches what Postgres
|
|
2441
|
+
* does for the same query — honouring a casing here would make the two
|
|
2442
|
+
* dialects disagree about one predicate, which is worse than not offering
|
|
2443
|
+
* the knob. Narrow the search to a plain text FIELD when case must matter.
|
|
1268
2444
|
*/
|
|
1269
2445
|
abstract tsvectorSearch(tsv: SqlText, query: SqlText, language?: string): SqlText;
|
|
1270
2446
|
/**
|
|
@@ -1331,7 +2507,22 @@ declare abstract class Dialect implements DialectEntry {
|
|
|
1331
2507
|
key: string;
|
|
1332
2508
|
value: SqlText;
|
|
1333
2509
|
}[]): SqlText;
|
|
1334
|
-
|
|
2510
|
+
/**
|
|
2511
|
+
* The SQL type for `fieldType` in this dialect — a REFINEMENT's declared `sql`
|
|
2512
|
+
* for this dialect when it has one, else the builtin's own mapping.
|
|
2513
|
+
*
|
|
2514
|
+
* A refinement with no entry for this dialect falls through to the base kind's
|
|
2515
|
+
* answer, which is a real answer for a value of the base type — a fallback,
|
|
2516
|
+
* not a degrade. That is why this never throws for an unmapped dialect.
|
|
2517
|
+
*
|
|
2518
|
+
* Asked of the FIELD TYPE rather than of its refinement, because a declared
|
|
2519
|
+
* `sql` template may interpolate options the COLUMN carries
|
|
2520
|
+
* (`geometry({subtype},{srid})`) — so the answer is per column, and the column
|
|
2521
|
+
* is the only thing that has both halves.
|
|
2522
|
+
*/
|
|
2523
|
+
sqlTypeFor(fieldType: FieldType): string;
|
|
2524
|
+
/** The BUILTIN per-kind SQL type mapping, before any refinement overrides it. */
|
|
2525
|
+
protected abstract builtinSqlTypeFor(fieldType: FieldType): string;
|
|
1335
2526
|
/**
|
|
1336
2527
|
* Bind a whole JSON DOCUMENT (an object / array) as ONE parameter, cast to the
|
|
1337
2528
|
* column type it is destined for. The single binding path for a non-scalar
|
|
@@ -1348,8 +2539,49 @@ declare abstract class Dialect implements DialectEntry {
|
|
|
1348
2539
|
* The base dialect casts to whatever `sqlTypeFor` names, which is the portable
|
|
1349
2540
|
* answer for a JSON-typed column. A dialect with a NATIVE array type (Postgres
|
|
1350
2541
|
* `text[]`) must override — an array literal there is not JSON text.
|
|
1351
|
-
|
|
1352
|
-
|
|
2542
|
+
*
|
|
2543
|
+
* `site` says this is a VALUE position rather than a column, and names who to
|
|
2544
|
+
* blame when the target's declared cast cannot honestly be resolved there —
|
|
2545
|
+
* see {@link ValueSite} and {@link refuseUnwrittenCast}. Absent ⇒ a COLUMN,
|
|
2546
|
+
* which is what the write path is and what every dialect caller predating the
|
|
2547
|
+
* rule remains.
|
|
2548
|
+
*/
|
|
2549
|
+
jsonValue(value: JsonValue, fieldType?: FieldType, site?: ValueSite): SqlText;
|
|
2550
|
+
/**
|
|
2551
|
+
* Bind a JSON document the way this dialect does it, before any refinement's
|
|
2552
|
+
* declared `cast` template replaces the wrapper. A dialect overrides THIS
|
|
2553
|
+
* (Postgres does, for native array columns); {@link jsonValue} stays final so
|
|
2554
|
+
* a `cast` declaration is honoured on every dialect rather than on the ones
|
|
2555
|
+
* that happened not to override.
|
|
2556
|
+
*
|
|
2557
|
+
* AN OVERRIDE THAT RECURSES MUST CARRY `site` THROUGH, and that is the whole
|
|
2558
|
+
* reason it is a parameter here rather than a flag the caller checks once.
|
|
2559
|
+
* Postgres constructs a native array ELEMENT-WISE (`ARRAY[…]::geometry[]`),
|
|
2560
|
+
* re-entering `jsonValue` per element with the ITEM's type — so a value
|
|
2561
|
+
* position that was refused correctly one level up bound its elements through
|
|
2562
|
+
* the item's defaults one level down, which is the same defect reached by the
|
|
2563
|
+
* one road the first cut could not see. Measured before the fix: an
|
|
2564
|
+
* `array<json as Geometry>` OPERAND with no `with`, handed a Polygon document,
|
|
2565
|
+
* emitted `ARRAY[ST_GeomFromGeoJSON($1)::geometry(Point)]::geometry(Point)[]`.
|
|
2566
|
+
*
|
|
2567
|
+
* THAT REQUIREMENT RESTS ON THIS COMMENT, AND THE ALTERNATIVE WAS WEIGHED.
|
|
2568
|
+
* There is no LOUD spelling available: TypeScript lets an override declare
|
|
2569
|
+
* FEWER parameters, so making `site` required would not break an existing
|
|
2570
|
+
* 2-argument override, and `jsonValue`'s own third argument is optional so a
|
|
2571
|
+
* recursing call that drops it still compiles. The genuinely loud shape is to
|
|
2572
|
+
* stop depending on override discipline at all — hoist the refusal in
|
|
2573
|
+
* {@link jsonValue} to walk `castTargetsOf(fieldType)` (the type, then an
|
|
2574
|
+
* array's item, recursively — the walk `checkOperandCastsAreWritable` already
|
|
2575
|
+
* owns) BEFORE dispatching, so no dialect can route around it. It is not what
|
|
2576
|
+
* ships, because it refuses strictly MORE: an `array<json as …>` whose
|
|
2577
|
+
* elements are all scalars binds every element as a bare parameter and reaches
|
|
2578
|
+
* no element cast, and hoisting would refuse that emit for a cast that was
|
|
2579
|
+
* never going to fire. Refusing a legal statement is worse than a documented
|
|
2580
|
+
* requirement on the two dialects in this package, so the requirement is
|
|
2581
|
+
* documented — and if a third dialect ever binds containers element-wise, the
|
|
2582
|
+
* hoist is the change to make rather than a third copy of this note.
|
|
2583
|
+
*/
|
|
2584
|
+
protected builtinJsonValue(value: JsonValue, fieldType?: FieldType, _site?: ValueSite): SqlText;
|
|
1353
2585
|
/** This dialect's JSON column type — the default cast target for a document. */
|
|
1354
2586
|
jsonSqlType(): string;
|
|
1355
2587
|
/**
|
|
@@ -1591,52 +2823,174 @@ declare function isScalar(rt: ResolvedType): rt is FieldResolved | ComputedResol
|
|
|
1591
2823
|
* - `reference(name, at)` — a `ParamExpr` announces it exists at a JSON
|
|
1592
2824
|
* path. Used to detect params that are never given a type
|
|
1593
2825
|
* (`param.untyped`).
|
|
1594
|
-
* - `observe(name, fieldType, at)` — an operator (comparison / in /
|
|
1595
|
-
* / function-call /
|
|
1596
|
-
* field type the param is being
|
|
1597
|
-
*
|
|
1598
|
-
*
|
|
1599
|
-
*
|
|
1600
|
-
*
|
|
1601
|
-
*
|
|
1602
|
-
*
|
|
1603
|
-
*
|
|
1604
|
-
*
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
2826
|
+
* - `observe(name, fieldType, at, from?)` — an operator (comparison / in /
|
|
2827
|
+
* between / function-call / write cell / row bound) resolved its NON-param
|
|
2828
|
+
* side and tells the set what field type the param is being used AS, plus
|
|
2829
|
+
* where, plus (when it has one) the resolved value the requirement came
|
|
2830
|
+
* from, so the use can name the COLUMN that produced it.
|
|
2831
|
+
*
|
|
2832
|
+
* After the walk, `problems(p)` emits the type diagnostics, `checkValues(p, …)`
|
|
2833
|
+
* checks SUPPLIED values against the inferred types, and `resolved` / `info` /
|
|
2834
|
+
* `toJSON` export what was inferred.
|
|
2835
|
+
*
|
|
2836
|
+
* THE MERGED TYPE IS A MEET, NOT THE FIRST USE. Every observation of a name is
|
|
2837
|
+
* folded with `FieldType.meet`, which yields the most SPECIFIC type compatible
|
|
2838
|
+
* with all of them: a param compared against an `enum` in one place and plain
|
|
2839
|
+
* `text` in another is an ENUM, and `text{minLength:5}` beside
|
|
2840
|
+
* `text{maxLength:10}` carries both bounds. Seeding with the first observation
|
|
2841
|
+
* and keeping it (what this did through 0.6.5) is neither — it answers whichever
|
|
2842
|
+
* use the walk happened to reach first, which is a property of the JSON's shape
|
|
2843
|
+
* rather than of the query's meaning. Because a meet is commutative, associative
|
|
2844
|
+
* and idempotent (see `field-types/_meet.ts`), the fold's answer does not depend
|
|
2845
|
+
* on the observation order; only WHICH PAIR a conflict is reported against does.
|
|
2846
|
+
*
|
|
2847
|
+
* Type-safety note: this module performs ZERO casts. Field-type unification is
|
|
2848
|
+
* decided purely through `FieldType.meet`, a total method on the value-category
|
|
2849
|
+
* union.
|
|
2850
|
+
*/
|
|
2851
|
+
|
|
2852
|
+
/**
|
|
2853
|
+
* ONE recorded use of a param: where it is used and what that use requires of
|
|
2854
|
+
* it. The public per-use record, carrying the same grade of detail a query's
|
|
2855
|
+
* RESULT fields do (`QueryField`) — the full `type` for a consumer that wants
|
|
2856
|
+
* options / membership, plus the JSON-friendly `category` summary so a caller
|
|
2857
|
+
* never has to walk a FieldType just to label a column — and, additionally, the
|
|
2858
|
+
* `field` the requirement came from, which is the answer to "why did this param
|
|
2859
|
+
* get this type?".
|
|
2860
|
+
*/
|
|
2861
|
+
interface ParamUse {
|
|
2862
|
+
/** Structural JSON path of the observing operand — where in the query this use sits. */
|
|
2863
|
+
readonly at: ReadonlyArray<string | number>;
|
|
2864
|
+
/** The field type THIS use requires the param to be. */
|
|
2865
|
+
readonly type: FieldType;
|
|
2866
|
+
/** The value category of {@link type} (`type.resolve()`) — a compact, JSON-friendly summary. */
|
|
2867
|
+
readonly category: ScalarKind;
|
|
2868
|
+
/**
|
|
2869
|
+
* The declared column this requirement was DERIVED from, when it came from
|
|
2870
|
+
* one — a comparison against `task.status`, a write into `task.status`, an
|
|
2871
|
+
* array op over `task.tags` (whose requirement is that column's ITEM type).
|
|
2872
|
+
* Absent when the requirement is structural rather than a column's: a row
|
|
2873
|
+
* bound is a number because it is a row COUNT, a function argument is its
|
|
2874
|
+
* declared parameter type, and a computed operand has no single owning field.
|
|
2875
|
+
*/
|
|
2876
|
+
readonly field?: FieldReference;
|
|
2877
|
+
}
|
|
2878
|
+
/** Why a param has no merged type: the two requirements that cannot be satisfied at once. */
|
|
2879
|
+
interface ParamConflict {
|
|
2880
|
+
/** The meet of every use BEFORE the offending one — what the param was required to be so far. */
|
|
2881
|
+
readonly required: FieldType;
|
|
2882
|
+
/** Where the first of those uses sits (the anchor for the accumulated requirement). */
|
|
2883
|
+
readonly requiredAt: ReadonlyArray<string | number>;
|
|
2884
|
+
/** The use that cannot be satisfied together with {@link required}. */
|
|
2885
|
+
readonly use: ParamUse;
|
|
2886
|
+
/** The rendered explanation, as it appears in the `param.conflict` problem. */
|
|
2887
|
+
readonly message: string;
|
|
2888
|
+
}
|
|
2889
|
+
/**
|
|
2890
|
+
* Everything known about ONE bind parameter — its uses, the type merged from
|
|
2891
|
+
* them, and the conflict when they have no meet. The rich counterpart to
|
|
2892
|
+
* {@link ParamDef}, which stays the minimal `{ name, type }` a caller binds
|
|
2893
|
+
* with; this is what a caller reads to EXPLAIN a param (a UI labelling an input,
|
|
2894
|
+
* a diagnostic saying which use forced which type).
|
|
2895
|
+
*/
|
|
2896
|
+
interface ParamInfo {
|
|
2897
|
+
/** The parameter's name. */
|
|
2898
|
+
readonly name: string;
|
|
2899
|
+
/** Every place the bare `param` expr appears, in walk order. */
|
|
2900
|
+
readonly references: ReadonlyArray<ReadonlyArray<string | number>>;
|
|
2901
|
+
/** Every typed use, in walk order. Empty ⇒ the param is untyped. */
|
|
2902
|
+
readonly uses: readonly ParamUse[];
|
|
2903
|
+
/** The MEET of every use — absent when there are no uses, or when they conflict. */
|
|
2904
|
+
readonly type?: FieldType;
|
|
2905
|
+
/** The value category of {@link type}, when there is one. */
|
|
2906
|
+
readonly category?: ScalarKind;
|
|
2907
|
+
/** Present exactly when there are uses but no {@link type}. */
|
|
2908
|
+
readonly conflict?: ParamConflict;
|
|
2909
|
+
}
|
|
2910
|
+
/** Accumulates bind-parameter references + typed uses across a query, merges them, and reports conflicts as Problems. */
|
|
1608
2911
|
declare class ParamSet {
|
|
1609
|
-
/** name → accumulated references +
|
|
2912
|
+
/** name → accumulated references + uses. Insertion-ordered. */
|
|
1610
2913
|
private readonly records;
|
|
1611
2914
|
private record;
|
|
1612
2915
|
/** Announce that a `param` expression with `name` exists at JSON path `at`. */
|
|
1613
2916
|
reference(name: string, at?: ReadonlyArray<string | number>): void;
|
|
1614
2917
|
/**
|
|
1615
2918
|
* Record that `name` is used where a value of `fieldType` is expected, at
|
|
1616
|
-
* JSON path `at`. Callers invoke this AFTER resolving their non-param side
|
|
2919
|
+
* JSON path `at`. Callers invoke this AFTER resolving their non-param side,
|
|
2920
|
+
* and pass that resolution as `from` when they have it, so the use can name
|
|
2921
|
+
* the COLUMN behind the requirement.
|
|
1617
2922
|
*/
|
|
1618
|
-
observe(name: string, fieldType: FieldType, at?: ReadonlyArray<string | number
|
|
2923
|
+
observe(name: string, fieldType: FieldType, at?: ReadonlyArray<string | number>, from?: ResolvedType): void;
|
|
1619
2924
|
/** Names of every param seen (referenced and/or observed), in first-seen order. */
|
|
1620
2925
|
names(): string[];
|
|
1621
2926
|
/**
|
|
1622
|
-
* The unified field type inferred for `name
|
|
1623
|
-
* never
|
|
1624
|
-
* the unification; every later observation must be `comparableWith` it.
|
|
2927
|
+
* The unified field type inferred for `name` — the MEET of every use — or
|
|
2928
|
+
* `undefined` when it was never used OR its uses conflict.
|
|
1625
2929
|
*/
|
|
1626
2930
|
resolved(name: string): FieldType | undefined;
|
|
1627
2931
|
/**
|
|
1628
|
-
*
|
|
1629
|
-
*
|
|
1630
|
-
*
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
2932
|
+
* Everything known about `name`: its references, its uses, the merged type,
|
|
2933
|
+
* and the conflict when there is none. `undefined` for a name this set has
|
|
2934
|
+
* never seen.
|
|
2935
|
+
*/
|
|
2936
|
+
info(name: string): ParamInfo | undefined;
|
|
2937
|
+
/** Every param this set has seen, in first-seen order — the full introspection surface. */
|
|
2938
|
+
all(): ParamInfo[];
|
|
2939
|
+
/** Assemble one param's public view: its record plus the merged outcome. */
|
|
2940
|
+
private buildInfo;
|
|
2941
|
+
/**
|
|
2942
|
+
* Fold this param's uses into their meet. Recomputed rather than memoized:
|
|
2943
|
+
* uses accumulate DURING the walk (a `param` expr resolves its own type
|
|
2944
|
+
* mid-walk, before the later uses exist), so a cached answer would pin the
|
|
2945
|
+
* partial one. The fold is linear in the number of uses of ONE param.
|
|
2946
|
+
*/
|
|
2947
|
+
private merge;
|
|
2948
|
+
/**
|
|
2949
|
+
* Emit param TYPE diagnostics into `p`:
|
|
2950
|
+
* - `param.untyped` — referenced but never used against any type, so its
|
|
2951
|
+
* input type cannot be inferred. Reported at each reference site.
|
|
2952
|
+
* - `param.conflict` — used in ways with no common type. The message names
|
|
2953
|
+
* both requirements AND both paths, and says WHICH of the two failed: two
|
|
2954
|
+
* different value categories, or one category whose constraints cannot be
|
|
2955
|
+
* satisfied together (two closed sets sharing no member, two disjoint
|
|
2956
|
+
* length bounds). Reported at the offending use.
|
|
1634
2957
|
*/
|
|
1635
2958
|
problems(p: Problems): void;
|
|
2959
|
+
/**
|
|
2960
|
+
* Check SUPPLIED param values against the type each param's uses require —
|
|
2961
|
+
* the check that turns "bound and silently wrong" into a stated problem. Ran
|
|
2962
|
+
* BEFORE execution, and reported as Problems rather than thrown, so a bad
|
|
2963
|
+
* binding reads like every other diagnostic this package emits.
|
|
2964
|
+
*
|
|
2965
|
+
* Three findings, and only one of them blocks:
|
|
2966
|
+
* - `param.value` (ERROR) — the value does not satisfy the merged type. A
|
|
2967
|
+
* `null` never does this: a param is always potentially-null (see
|
|
2968
|
+
* `ParamExpr.resolve`), and binding SQL NULL is a legitimate thing to ask
|
|
2969
|
+
* for.
|
|
2970
|
+
* - `param.missing` (WARNING) — a typed param has no value. Not an error,
|
|
2971
|
+
* because an unbound param deliberately binds NULL, which `autoPaginate`
|
|
2972
|
+
* relies on to mean "no limit / no offset".
|
|
2973
|
+
* - `param.unknown` (WARNING) — a value was supplied under a name this query
|
|
2974
|
+
* has no param for, which is what a typo looks like. Not an error, because
|
|
2975
|
+
* one params bag is routinely reused across several queries.
|
|
2976
|
+
*
|
|
2977
|
+
* A RELATION-typed param is exempt from the value check — see the comment at
|
|
2978
|
+
* the site; it binds an IDENTITY, which for a composite key is a keyed object
|
|
2979
|
+
* the relation's own value schema does not describe.
|
|
2980
|
+
*
|
|
2981
|
+
* A param with NO merged type is skipped: `param.untyped` / `param.conflict`
|
|
2982
|
+
* (from {@link problems}) already say why, and there is nothing to check
|
|
2983
|
+
* against.
|
|
2984
|
+
*/
|
|
2985
|
+
checkValues(p: Problems, values: Readonly<Record<string, JsonValue | undefined>>): void;
|
|
1636
2986
|
/**
|
|
1637
2987
|
* Export the resolved params as `ParamDef[]` for building the query's input
|
|
1638
|
-
* schema + binding map. Params that are untyped or in conflict are
|
|
1639
|
-
*
|
|
2988
|
+
* schema + binding map. Params that are untyped or in conflict are SKIPPED:
|
|
2989
|
+
* a `ParamDef` exists to say what to bind, and one without a type would be a
|
|
2990
|
+
* lie about a param nothing can bind correctly. Their problems are reported
|
|
2991
|
+
* by {@link problems}, and {@link all} still reports them in full — with their
|
|
2992
|
+
* uses and their conflict — for a caller that wants to explain rather than
|
|
2993
|
+
* bind. (That split is why `ParamDef.type` stays required.)
|
|
1640
2994
|
*/
|
|
1641
2995
|
toJSON(): ParamDef[];
|
|
1642
2996
|
}
|
|
@@ -1824,9 +3178,19 @@ declare function rlsPredicate(rls: RlsProvider | undefined, dialect: Dialect, en
|
|
|
1824
3178
|
* Mirrors cletus's `Value` (a runtime value plus optional schema metadata)
|
|
1825
3179
|
* but typed against this package's `JsonValue` / `Field` / `FieldType` and
|
|
1826
3180
|
* with ZERO `any` / casts. The optional `field` / `type` carry schema context
|
|
1827
|
-
* when an expression can supply it
|
|
1828
|
-
* values leave them undefined — result-level type metadata is produced from
|
|
3181
|
+
* when an expression can supply it; result-level type metadata is produced from
|
|
1829
3182
|
* RESOLUTION (`Query.outputFields`), independent of these per-cell values.
|
|
3183
|
+
*
|
|
3184
|
+
* WHERE `type` COMES FROM, and why it matters more than it used to. A field-ref
|
|
3185
|
+
* supplies the column's own type; a registered FUNCTION or OPERATOR supplies its
|
|
3186
|
+
* DECLARED output type ({@link withType}, applied by the dispatch helpers in
|
|
3187
|
+
* `functions.ts`); a literal, a param and an arithmetic result carry none. It is
|
|
3188
|
+
* the channel a declaration reaches a comparison through — both the
|
|
3189
|
+
* {@link TextCasing} a text type declares and the {@link ValueComparator} a
|
|
3190
|
+
* refinement's impl declares — so a produced value with no type is a value whose
|
|
3191
|
+
* declaration cannot govern how it is compared. That was the whole of the
|
|
3192
|
+
* in-memory gap for a registered type: the hook existed nowhere, and even with
|
|
3193
|
+
* the hook a computed value had no type to reach it with.
|
|
1830
3194
|
*/
|
|
1831
3195
|
|
|
1832
3196
|
/** The runtime category a value falls into, inferred from its JS shape. */
|
|
@@ -1850,6 +3214,21 @@ declare class Value {
|
|
|
1850
3214
|
static of(raw: JsonValue, field?: Field, type?: FieldType): Value;
|
|
1851
3215
|
/** The SQL `NULL` value. */
|
|
1852
3216
|
static null(): Value;
|
|
3217
|
+
/**
|
|
3218
|
+
* This value carrying `type` — the seam a registered function's / operator's
|
|
3219
|
+
* DECLARED output reaches its result through (see the module docs).
|
|
3220
|
+
*
|
|
3221
|
+
* THE DECLARATION WINS over whatever the run happened to tag, and that is the
|
|
3222
|
+
* point rather than an accident: `resolve()` answers the declared output type,
|
|
3223
|
+
* so a result whose per-cell type disagreed with it would make the two halves
|
|
3224
|
+
* of one call describe different types — and the per-cell one is the half
|
|
3225
|
+
* nothing validates. A run that legitimately wants to say more about its
|
|
3226
|
+
* result says it in the declaration.
|
|
3227
|
+
*
|
|
3228
|
+
* `undefined` is a no-op, so the ordinary "this function declares `inferred`"
|
|
3229
|
+
* case allocates nothing.
|
|
3230
|
+
*/
|
|
3231
|
+
withType(type: FieldType | undefined): Value;
|
|
1853
3232
|
/** Whether the raw value is SQL `NULL`. */
|
|
1854
3233
|
isNull(): boolean;
|
|
1855
3234
|
/** Coerce to a number (NaN when not numerically meaningful). */
|
|
@@ -1861,22 +3240,61 @@ declare class Value {
|
|
|
1861
3240
|
/** Runtime category of the raw value. */
|
|
1862
3241
|
category(): ValueCategory;
|
|
1863
3242
|
/**
|
|
1864
|
-
*
|
|
1865
|
-
*
|
|
3243
|
+
* The {@link ValueComparator} this value's originating field type DECLARES, or
|
|
3244
|
+
* `undefined` — either because no type metadata reached this cell, or because
|
|
3245
|
+
* the type is a plain builtin (whose comparison rule is {@link compareTo}
|
|
3246
|
+
* itself) or a refinement with no registered impl.
|
|
3247
|
+
*
|
|
3248
|
+
* The exact counterpart of {@link textCasing}, and unresolved for the same
|
|
3249
|
+
* reason: a `Value` cannot see the other operand, and which of two declarations
|
|
3250
|
+
* governs is a decision for the pair (see {@link effectiveComparator}).
|
|
3251
|
+
*/
|
|
3252
|
+
comparator(): ValueComparator | undefined;
|
|
3253
|
+
/**
|
|
3254
|
+
* Three-way comparison for sorting / ordering. NULLs sort first. A type that
|
|
3255
|
+
* DECLARES how its values compare decides; otherwise numbers compare
|
|
3256
|
+
* numerically, booleans false-first, and everything else by its stringified
|
|
3257
|
+
* form.
|
|
3258
|
+
*
|
|
3259
|
+
* NULL IS DECIDED BEFORE THE DECLARATION IS CONSULTED, and that ordering is
|
|
3260
|
+
* load-bearing. SQL's NULL placement is a property of the SORT, not of the
|
|
3261
|
+
* column's type — `ORDER BY … NULLS FIRST` is the same clause whatever the
|
|
3262
|
+
* type is — so a comparator is never handed a NULL and never has to have an
|
|
3263
|
+
* opinion about one. It also means a comparator cannot accidentally break
|
|
3264
|
+
* three-valued logic, which `evaluateBool` settles one layer up.
|
|
1866
3265
|
*/
|
|
1867
3266
|
compareTo(other: Value): number;
|
|
1868
3267
|
/**
|
|
1869
|
-
*
|
|
1870
|
-
*
|
|
1871
|
-
*
|
|
1872
|
-
*
|
|
3268
|
+
* The {@link TextCasing} this value's originating field type DECLARES, or
|
|
3269
|
+
* `undefined` — either because no type metadata reached this cell (a literal,
|
|
3270
|
+
* a param, a computed column) or because the type declares no casing.
|
|
3271
|
+
*
|
|
3272
|
+
* Deliberately NOT resolved to a boolean here. A `Value` cannot see the
|
|
3273
|
+
* engine, and the fallback is the ENGINE's default; folding it in with a
|
|
3274
|
+
* `?? false` was how the old accessor made "declares nothing" and "declares
|
|
3275
|
+
* case-insensitive" indistinguishable — which is precisely what a per-field
|
|
3276
|
+
* declaration has to out-rank. The comparison site resolves the two operands'
|
|
3277
|
+
* declarations against `ctx.engine.textCasing` together (`effectiveCasing`).
|
|
1873
3278
|
*/
|
|
1874
|
-
|
|
3279
|
+
textCasing(): TextCasing | undefined;
|
|
1875
3280
|
/**
|
|
1876
3281
|
* Three-way comparison honoring text case-sensitivity: identical to
|
|
1877
3282
|
* `compareTo` except that, when both operands are strings and `sensitive`
|
|
1878
3283
|
* is false, both are lower-cased before comparing. Numbers / booleans are
|
|
1879
3284
|
* unaffected (no case-folding applies).
|
|
3285
|
+
*
|
|
3286
|
+
* A DECLARED COMPARATOR OUT-RANKS THE FOLD, which is why the case branch is
|
|
3287
|
+
* guarded by it rather than reached first. `casing` and `compareValues` are
|
|
3288
|
+
* two ways to say how values of a type compare, and a type that supplied the
|
|
3289
|
+
* second has answered the whole question — folding its operands before handing
|
|
3290
|
+
* them over would silently mutate the input to a comparator that may not be
|
|
3291
|
+
* comparing text at all (an `inet`, a semver, a sortable id). A refinement
|
|
3292
|
+
* that wants the package's folding declares no comparator and narrows
|
|
3293
|
+
* `options.casing` instead.
|
|
3294
|
+
*
|
|
3295
|
+
* The guard SKIPS the fold rather than dispatching the comparator here, so
|
|
3296
|
+
* NULL placement stays decided in one place ({@link compareTo}) — a comparator
|
|
3297
|
+
* is never handed a NULL by either road.
|
|
1880
3298
|
*/
|
|
1881
3299
|
compareToCase(other: Value, sensitive: boolean): number;
|
|
1882
3300
|
/** SQL-equality (NULL is never equal to anything, including NULL). */
|
|
@@ -2217,7 +3635,7 @@ declare class RelationFieldType extends FieldType {
|
|
|
2217
3635
|
/** Reconstruct from a JSON def (throws on a kind mismatch). */
|
|
2218
3636
|
static from(json: FieldTypeDef): RelationFieldType;
|
|
2219
3637
|
/** The Zod schema for this field type's JSON def. */
|
|
2220
|
-
static toSchema(): z.ZodTypeAny;
|
|
3638
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
2221
3639
|
/**
|
|
2222
3640
|
* True when the FOREIGN KEY lives on THIS Type — a declared belongs-to. The
|
|
2223
3641
|
* cardinality alone is NOT the discriminator: a MATERIALIZED INVERSE (one
|
|
@@ -2272,18 +3690,38 @@ declare class RelationFieldType extends FieldType {
|
|
|
2272
3690
|
resolveOn(engine: QueryEngine, relationFieldName: string, thisType: Type, targetType: Type, leftAlias: string, targetAlias: string): ResolvedRelationOn;
|
|
2273
3691
|
/** Resolve to the `relation` scalar comparison category. */
|
|
2274
3692
|
resolve(): ScalarKind;
|
|
2275
|
-
/**
|
|
2276
|
-
|
|
3693
|
+
/**
|
|
3694
|
+
* A relation is only comparable with another relation to the same Type. It is
|
|
3695
|
+
* also the one base a refinement may not narrow, so no declared edge can ever
|
|
3696
|
+
* widen this.
|
|
3697
|
+
*/
|
|
3698
|
+
protected builtinComparableWith(other: FieldType): boolean;
|
|
3699
|
+
/**
|
|
3700
|
+
* Meet with another relation to the SAME target. What flows through a relation
|
|
3701
|
+
* value is the target's IDENTITY, and the two sides agree on it as soon as
|
|
3702
|
+
* they agree on `to`; the rest of the shape is not a value constraint —
|
|
3703
|
+
* `count` is an ESTIMATE (a materialized inverse derives it from a row ratio),
|
|
3704
|
+
* so the meet takes the tighter of the two, and `inverseRelation` /
|
|
3705
|
+
* `inverseVia` describe the SCHEMA EDGE rather than the value, so they are
|
|
3706
|
+
* dropped rather than reconciled — a merged relation is a type for a bound
|
|
3707
|
+
* VALUE, never an edge anything traverses. Two identical relations never reach
|
|
3708
|
+
* here (`meet` short-circuits), so nothing is lost by dropping them.
|
|
3709
|
+
*/
|
|
3710
|
+
protected meetWith(other: FieldType): FieldType | undefined;
|
|
2277
3711
|
/** Estimated average stored byte size (a short id string). */
|
|
2278
|
-
|
|
3712
|
+
protected builtinAvgBytes(): number;
|
|
2279
3713
|
/** SQL column type for the stored identifier reference. */
|
|
2280
3714
|
toSQLType(): string;
|
|
2281
3715
|
/** Zod schema validating a relation value (the related row's identifier). */
|
|
2282
|
-
|
|
3716
|
+
protected builtinValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
2283
3717
|
/** Serialize to its JSON def (`inverseVia` is internal, never emitted). */
|
|
3718
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
2284
3719
|
toJSON(): RelationFieldTypeDef;
|
|
3720
|
+
protected builtinJSON(): RelationFieldTypeDef;
|
|
2285
3721
|
/** A copy of this relation (preserving internal `inverseVia`). */
|
|
3722
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
2286
3723
|
clone(): RelationFieldType;
|
|
3724
|
+
protected builtinClone(): RelationFieldType;
|
|
2287
3725
|
}
|
|
2288
3726
|
|
|
2289
3727
|
/** A direct field reference `<source>.<field>`. */
|
|
@@ -2995,15 +4433,16 @@ declare class ComparisonExpr extends BoolExpr {
|
|
|
2995
4433
|
private closedSetSelectivity;
|
|
2996
4434
|
/** An `=` against a column is an index point-probe (arity 1); other ops are not. */
|
|
2997
4435
|
indexProbe(): IndexProbe | undefined;
|
|
2998
|
-
/** Evaluate under 3VL: a NULL operand yields UNKNOWN; text
|
|
4436
|
+
/** Evaluate under 3VL: a NULL operand yields UNKNOWN; text folds case unless the governing {@link TextCasing} is `'exact'`. */
|
|
2999
4437
|
evaluateBool(ctx: RuntimeContext, row: SourceRow, group?: readonly SourceRow[]): Promise<boolean | undefined>;
|
|
3000
4438
|
/**
|
|
3001
4439
|
* LIKE / notLike / ilike via SQL wildcard → regex translation. `ilike` is
|
|
3002
|
-
* always case-insensitive
|
|
3003
|
-
* `
|
|
4440
|
+
* always case-insensitive (the op says so, and no casing is consulted);
|
|
4441
|
+
* `like` / `notLike` fold unless the governing {@link TextCasing} resolved to
|
|
4442
|
+
* `'exact'` (`sensitive === true` here).
|
|
3004
4443
|
*/
|
|
3005
4444
|
private evalLike;
|
|
3006
|
-
/** Emit as a SqlText fragment (ILIKE delegates to the dialect;
|
|
4445
|
+
/** Emit as a SqlText fragment (ILIKE delegates to the dialect; a `'fold'`-cased text comparison wraps both operands in `LOWER(...)`). */
|
|
3007
4446
|
toSQL(dialect: Dialect, ctx: SqlContext): SqlText;
|
|
3008
4447
|
/** Serialize back to its JSON ExprDef. */
|
|
3009
4448
|
toJSON(): ComparisonExprDef;
|
|
@@ -3349,10 +4788,14 @@ declare class ArrayOpExpr extends BoolExpr {
|
|
|
3349
4788
|
/** Validate the target is an array field and the element operands match its arity and item type. */
|
|
3350
4789
|
validateWalk(engine: QueryEngine, scope: QueryScope, p: Problems, ctx: ValidateContext): ResolvedType;
|
|
3351
4790
|
/**
|
|
3352
|
-
* Whether textual element comparison is case-sensitive
|
|
3353
|
-
*
|
|
3354
|
-
*
|
|
3355
|
-
*
|
|
4791
|
+
* Whether textual element comparison is case-sensitive: the ELEMENT type's
|
|
4792
|
+
* declared {@link TextCasing} when the target Value carries one, else the
|
|
4793
|
+
* engine's default — the same resolution `ComparisonExpr` applies to a
|
|
4794
|
+
* scalar, so `tags contains 'BETA'` and `tag = 'BETA'` cannot answer
|
|
4795
|
+
* differently for one deployment.
|
|
4796
|
+
*
|
|
4797
|
+
* A non-text element folds nothing regardless, because `compareToCase` only
|
|
4798
|
+
* folds when BOTH raw values are strings.
|
|
3356
4799
|
*/
|
|
3357
4800
|
private elementCaseSensitive;
|
|
3358
4801
|
/** Evaluate the predicate: containment / overlap / emptiness over the target array. */
|
|
@@ -3675,6 +5118,103 @@ declare class TabularFunctionCallExpr extends Expr {
|
|
|
3675
5118
|
toCode(): string;
|
|
3676
5119
|
}
|
|
3677
5120
|
|
|
5121
|
+
/** A registered operator applied to its named operands. */
|
|
5122
|
+
declare class OperatorExpr extends Expr {
|
|
5123
|
+
readonly op: string;
|
|
5124
|
+
/** Operands keyed by declared operand name (insertion order preserved). */
|
|
5125
|
+
readonly args: ReadonlyMap<string, Expr>;
|
|
5126
|
+
static readonly KIND: "operator";
|
|
5127
|
+
/** Concise LLM-facing summary of this expr kind (see `ExprClass.INSTRUCTIONS`). */
|
|
5128
|
+
static readonly INSTRUCTIONS: "A REGISTERED operator (`&&`, `<->`, `@>`) applied to NAMED operands \u2014 `{op:'&&', args:{left:\u2026, right:\u2026}}`, keyed by the declared operand name, NOT positional. The operators block of this catalog lists every one that exists here, with its operand types, its result type and what it means; there are no others, and an operator is NOT a function (a function call is `kind:'function-call'`).";
|
|
5129
|
+
readonly kind: "operator";
|
|
5130
|
+
/** Apply the registered operator `op` to its named `args`. */
|
|
5131
|
+
constructor(op: string,
|
|
5132
|
+
/** Operands keyed by declared operand name (insertion order preserved). */
|
|
5133
|
+
args: ReadonlyMap<string, Expr>);
|
|
5134
|
+
/** Reconstruct an OperatorExpr from its JSON def, parsing named operands via the registry. */
|
|
5135
|
+
static from(json: ExprDef, registry: Registry): OperatorExpr;
|
|
5136
|
+
/**
|
|
5137
|
+
* Owned structural {@link Shape} — the zod-free parallel parser. Builds an
|
|
5138
|
+
* `OperatorExpr` equal to `from`'s output on a valid def; the operator-exists
|
|
5139
|
+
* / operand checks stay in `validateWalk`, as they do for a function call. See
|
|
5140
|
+
* `shape/`.
|
|
5141
|
+
*/
|
|
5142
|
+
static readonly SHAPE: Shape<OperatorExpr>;
|
|
5143
|
+
/**
|
|
5144
|
+
* Zod schema for this expr kind's JSON shape.
|
|
5145
|
+
*
|
|
5146
|
+
* `op` is ENUM-LOCKED to the registered operator names whenever a registry is
|
|
5147
|
+
* supplied and the `functions` depth axis asks for more than `open` — the same
|
|
5148
|
+
* argument that made a refinement's `as` an enum rather than a string: a model
|
|
5149
|
+
* free to write `op: '&&'` into a registry that has no `&&` finds out at
|
|
5150
|
+
* validate, one whole round trip later. The glossary carries each operator's
|
|
5151
|
+
* signature and `instructions` inline, because a bare list of glyphs tells a
|
|
5152
|
+
* model what it may write and not what any of them mean.
|
|
5153
|
+
*
|
|
5154
|
+
* At `typed` depth each operator additionally gets its own STRICT operand
|
|
5155
|
+
* object, so a misspelled operand name is refused by the schema rather than by
|
|
5156
|
+
* validation. The axis is `functions` rather than an axis of its own: an
|
|
5157
|
+
* operator IS a named-argument call, and a caller who asked for loose function
|
|
5158
|
+
* calls did not ask for strict operator ones.
|
|
5159
|
+
*/
|
|
5160
|
+
static toSchema(opts: SchemaOptions): z.ZodTypeAny;
|
|
5161
|
+
forEachChild(visit: (child: Expr) => void): void;
|
|
5162
|
+
protected aggregateHere(): boolean;
|
|
5163
|
+
/** Resolve to the operator's DECLARED output type (text fallback when unregistered). */
|
|
5164
|
+
resolve(engine: QueryEngine, scope: QueryScope): ResolvedType;
|
|
5165
|
+
/**
|
|
5166
|
+
* The call's resolved output: the operator's DECLARED type, nullable when any
|
|
5167
|
+
* operand is, aggregate when any operand is.
|
|
5168
|
+
*
|
|
5169
|
+
* Declared, never inferred — an operator exists precisely because its result
|
|
5170
|
+
* is not derivable from its operands (`<->` takes two geometries and produces
|
|
5171
|
+
* a number), so there is no `'inferred'` arm to mirror.
|
|
5172
|
+
*/
|
|
5173
|
+
private outputOf;
|
|
5174
|
+
/** Validate the operator exists, observe bind-param operands, then judge the call. */
|
|
5175
|
+
validateWalk(engine: QueryEngine, scope: QueryScope, p: Problems, ctx: ValidateContext): ResolvedType;
|
|
5176
|
+
/** Cost is the operands' child costs plus any intrinsic cost the operator declares. */
|
|
5177
|
+
cost(ctx: CostContext, scope: QueryScope): Cost;
|
|
5178
|
+
/**
|
|
5179
|
+
* The declared WHERE selectivity, or the base's (keep everything) for an
|
|
5180
|
+
* operator that declares none or is not registered here.
|
|
5181
|
+
*/
|
|
5182
|
+
selectivity(ctx: CostContext, scope: QueryScope): number;
|
|
5183
|
+
/** Evaluate the operands and run the registered operator implementation. */
|
|
5184
|
+
evaluate(ctx: RuntimeContext, row: SourceRow | null, group?: readonly SourceRow[]): Promise<Value>;
|
|
5185
|
+
/**
|
|
5186
|
+
* Emit the operator's DECLARED template for this dialect, operands spliced
|
|
5187
|
+
* into their named slots.
|
|
5188
|
+
*
|
|
5189
|
+
* A DIALECT WITH NO DECLARED TEMPLATE IS REFUSED, and that asymmetry with
|
|
5190
|
+
* `BaseDialect.emitBuiltinCall` — which degrades silently for builtins
|
|
5191
|
+
* (`dateAdd` → the input date unchanged, `arrayContains` → `(1 = 0)`) — is
|
|
5192
|
+
* deliberate. A builtin's degrade is portable-SQL policy for a function whose
|
|
5193
|
+
* semantics this package owns, documents and tests. A third party cannot
|
|
5194
|
+
* document a degrade this package never sees, and `&&` degrading to `(1 = 0)`
|
|
5195
|
+
* returns ZERO ROWS for a query the caller believed ran: a wrong answer that
|
|
5196
|
+
* looks exactly like a right one. The refusal names the alternatives it can
|
|
5197
|
+
* name — the dialects that ARE declared — because a refusal with no remedy
|
|
5198
|
+
* costs the retry it was meant to prevent.
|
|
5199
|
+
*/
|
|
5200
|
+
toSQL(dialect: Dialect, ctx: SqlContext): SqlText;
|
|
5201
|
+
/** Serialize back to its JSON ExprDef. */
|
|
5202
|
+
toJSON(): OperatorExprDef;
|
|
5203
|
+
/** Deep-copy this expr (and its operand children). */
|
|
5204
|
+
clone(): OperatorExpr;
|
|
5205
|
+
/**
|
|
5206
|
+
* Render the WIRE shape — `&&(left: …, right: …)` — rather than infix.
|
|
5207
|
+
*
|
|
5208
|
+
* An infix rendering needs the DECLARED operand order, and `toCode()` has no
|
|
5209
|
+
* registry to look it up in; rendering in AUTHORED order instead would
|
|
5210
|
+
* silently swap the operands of a non-commutative operator, which is worse
|
|
5211
|
+
* than reading like a call. It is also honest: the operator IS function-shaped
|
|
5212
|
+
* on the wire, and this is a debugging rendering of the authored tree, not of
|
|
5213
|
+
* the SQL. Infix appears where infix is real — in the emitted SQL.
|
|
5214
|
+
*/
|
|
5215
|
+
toCode(): string;
|
|
5216
|
+
}
|
|
5217
|
+
|
|
3678
5218
|
/**
|
|
3679
5219
|
* SemanticExpr — semantic-similarity score of a BOUND SOURCE's row against a
|
|
3680
5220
|
* query (≈1 = most similar). Resolves to a numeric `ComputedResolved`.
|
|
@@ -3920,8 +5460,8 @@ declare class TextSearchExpr extends BoolExpr {
|
|
|
3920
5460
|
scanRowPenalty(): number;
|
|
3921
5461
|
/**
|
|
3922
5462
|
* Basic token match: the searched text matches when it contains every
|
|
3923
|
-
* whitespace-separated token of the query.
|
|
3924
|
-
* searched field is `
|
|
5463
|
+
* whitespace-separated token of the query. case-FOLDED unless the
|
|
5464
|
+
* searched field's effective {@link TextCasing} is `'exact'`. When a `SearchBacking` is in effect its `run`
|
|
3925
5465
|
* override decides the boolean, or its hidden `vectorField`'s stored text is
|
|
3926
5466
|
* token-matched; otherwise today's whole-record / field text is matched. The
|
|
3927
5467
|
* dialect tsvector / ranking forms are a SQL-emission concern.
|
|
@@ -3976,8 +5516,8 @@ declare class TextScoreExpr extends Expr {
|
|
|
3976
5516
|
scanRowPenalty(): number;
|
|
3977
5517
|
/**
|
|
3978
5518
|
* A deterministic in-memory relevance in [0, 1]: the FRACTION of the query's
|
|
3979
|
-
* tokens present in the searched text (case-
|
|
3980
|
-
* `
|
|
5519
|
+
* tokens present in the searched text (case-folded unless the field's
|
|
5520
|
+
* effective {@link TextCasing} is `'exact'`). When a `SearchBacking` is in effect its `run` override decides
|
|
3981
5521
|
* a boolean (⇒ 1/0), or its hidden `vectorField`'s stored text is scored;
|
|
3982
5522
|
* otherwise the whole-record / field text is scored.
|
|
3983
5523
|
*/
|
|
@@ -5464,6 +7004,21 @@ declare class Field implements Node {
|
|
|
5464
7004
|
* field, `text-search`/`text-score` a text field, `semantic` a semantic-eligible
|
|
5465
7005
|
* field (a semantic/search text field, or a relation). Every other kind is
|
|
5466
7006
|
* type-agnostic (any field allows it).
|
|
7007
|
+
*
|
|
7008
|
+
* ASKED OF THE TYPE, never by `instanceof`. The two CATEGORY gates go through
|
|
7009
|
+
* `resolve()` — the same answer `categoryOf` gives every comparison in the
|
|
7010
|
+
* package, so there is one spelling of "is text" rather than two, and it
|
|
7011
|
+
* survives two builds of this package existing in one process (`index.ts`
|
|
7012
|
+
* records that measurement). The SEMANTIC gate goes through the type's own
|
|
7013
|
+
* `isSemantic()`, which is where the `search`/`semantic` options are read now
|
|
7014
|
+
* — this used to reach into `TextFieldType.options` from outside the class,
|
|
7015
|
+
* as did three other sites, one of them a hand-copied duplicate.
|
|
7016
|
+
*
|
|
7017
|
+
* A `relation` is admitted here and is NOT `isSemantic()`, deliberately: this
|
|
7018
|
+
* asks whether a `semantic` expr may TARGET the field, while `isSemantic()`
|
|
7019
|
+
* asks whether the field's own values are embedded. Merging them made every
|
|
7020
|
+
* Type owning a foreign key report itself semantic-eligible (see
|
|
7021
|
+
* `Type.semanticFields`).
|
|
5467
7022
|
*/
|
|
5468
7023
|
private fieldTypeAllowsExpr;
|
|
5469
7024
|
/**
|
|
@@ -5689,7 +7244,16 @@ declare class Type implements Node {
|
|
|
5689
7244
|
constructor(spec: TypeSpec);
|
|
5690
7245
|
/** Look up a field by name. */
|
|
5691
7246
|
field(name: string): Field | undefined;
|
|
5692
|
-
/**
|
|
7247
|
+
/**
|
|
7248
|
+
* Fields whose type is a relation to another Type.
|
|
7249
|
+
*
|
|
7250
|
+
* Through `resolve()` rather than `instanceof`, here and in
|
|
7251
|
+
* {@link textFields}: it is the same answer `categoryOf` gives every
|
|
7252
|
+
* comparison in the package (one spelling of "is a relation", not two), it
|
|
7253
|
+
* needs no concrete-class import, and it survives two builds of this package
|
|
7254
|
+
* coexisting in one process — where `instanceof` is FALSE across the copies
|
|
7255
|
+
* (measured; see the note in `index.ts`).
|
|
7256
|
+
*/
|
|
5693
7257
|
relationFields(): Field[];
|
|
5694
7258
|
/** Fields whose type is `text` (the candidates a narrowed text-search targets). */
|
|
5695
7259
|
textFields(): Field[];
|
|
@@ -5739,6 +7303,14 @@ declare class Type implements Node {
|
|
|
5739
7303
|
/**
|
|
5740
7304
|
* Whether ONE field is declared semantic-eligible: a text field flagged
|
|
5741
7305
|
* `semantic` (or `search`, whose index is the same kind of derived artifact).
|
|
7306
|
+
*
|
|
7307
|
+
* The fact lives on the FIELD TYPE ({@link FieldType.isSemantic}), which is
|
|
7308
|
+
* what makes this method — and `exprs/semantic.ts`, which used to carry a
|
|
7309
|
+
* hand-copied duplicate of the predicate — one reader of one definition. A
|
|
7310
|
+
* registered REFINEMENT inherits it rather than re-declaring it: `search` /
|
|
7311
|
+
* `semantic` are `text`'s own options, so
|
|
7312
|
+
* `registerFieldType({ base:'text', options:{ semantic:true } })` makes every
|
|
7313
|
+
* column that names the type semantic with no new declaration surface.
|
|
5742
7314
|
*/
|
|
5743
7315
|
isFieldSemantic(field: Field): boolean;
|
|
5744
7316
|
/**
|
|
@@ -5753,7 +7325,7 @@ declare class Type implements Node {
|
|
|
5753
7325
|
* all. See {@link isFieldSemantic} for the per-field question.
|
|
5754
7326
|
*/
|
|
5755
7327
|
isSemantic(): boolean;
|
|
5756
|
-
/** Whether ONE field is declared full-text searchable. */
|
|
7328
|
+
/** Whether ONE field is declared full-text searchable (see {@link FieldType.isSearchable}). */
|
|
5757
7329
|
isFieldSearchable(field: Field): boolean;
|
|
5758
7330
|
/**
|
|
5759
7331
|
* Whether full-text search is possible ANYWHERE on this Type — the whole type
|
|
@@ -5833,6 +7405,16 @@ declare function arrayExecutor(rows: readonly SourceRecord[]): TypeExecutor;
|
|
|
5833
7405
|
* - window — `(partition, index) => Value` the ordered partition + position.
|
|
5834
7406
|
*
|
|
5835
7407
|
* Everything is typed against `Value` and `NamedArgs`; no `any` / casts.
|
|
7408
|
+
*
|
|
7409
|
+
* EVERY SCALAR-VALUED DISPATCH TAGS ITS RESULT WITH THE CALLABLE'S DECLARED
|
|
7410
|
+
* OUTPUT TYPE ({@link declaredOutput} / `Value.withType`), which is the second
|
|
7411
|
+
* half of making the in-memory road honest for a registered type. The comparator
|
|
7412
|
+
* a refinement declares reaches a comparison through `Value.type`, and a
|
|
7413
|
+
* PRODUCED value had none — so `ORDER BY (a <-> b)` over a declared `Meters`
|
|
7414
|
+
* stringified its keys while `ORDER BY parcel.distance` over the same type did
|
|
7415
|
+
* not, for no reason a caller could see. It is done HERE, in the four dispatch
|
|
7416
|
+
* helpers, rather than in the five call-shaped exprs, because the fact is one
|
|
7417
|
+
* fact: a call's value is of its declared output type.
|
|
5836
7418
|
*/
|
|
5837
7419
|
|
|
5838
7420
|
/** A `T` that may be produced synchronously or via a Promise. */
|
|
@@ -5864,6 +7446,18 @@ type AggregateRun = (rows: readonly NamedArgs[], ctx: RuntimeContext) => MaybePr
|
|
|
5864
7446
|
* is the JSON array of that row's order values) which `WindowExpr` injects.
|
|
5865
7447
|
*/
|
|
5866
7448
|
type WindowRun = (partition: readonly NamedArgs[], index: number, ctx: RuntimeContext) => MaybePromise<Value>;
|
|
7449
|
+
/**
|
|
7450
|
+
* A registered OPERATOR's implementation: its named operands in, a single
|
|
7451
|
+
* `Value` out — structurally a {@link ScalarRun}, and deliberately a NAME of its
|
|
7452
|
+
* own rather than a reuse of that alias.
|
|
7453
|
+
*
|
|
7454
|
+
* There is no shape TAG here, because an operator has exactly one shape. That is
|
|
7455
|
+
* also why `registerOperatorRun` takes the closure directly while
|
|
7456
|
+
* `registerFunctionRun` takes a `{ shape, run }` pair: the tag exists on the
|
|
7457
|
+
* function side to stop an aggregate def being given a scalar run, and an
|
|
7458
|
+
* operator has no second shape to be confused with.
|
|
7459
|
+
*/
|
|
7460
|
+
type OperatorRun = (args: NamedArgs, ctx: RuntimeContext) => MaybePromise<Value>;
|
|
5867
7461
|
/** The reserved named-arg key carrying a window row's ORDER-BY key. */
|
|
5868
7462
|
declare const WINDOW_ORDER_ARG = "$order";
|
|
5869
7463
|
/**
|
|
@@ -5885,7 +7479,41 @@ type FunctionRun = {
|
|
|
5885
7479
|
};
|
|
5886
7480
|
/** Run a registered SCALAR function over its named args (NULL if absent). */
|
|
5887
7481
|
declare function runScalarFunction(engine: QueryEngine, name: string, args: NamedArgs, ctx: RuntimeContext): Promise<Value>;
|
|
5888
|
-
/**
|
|
7482
|
+
/**
|
|
7483
|
+
* Run a registered OPERATOR over its named operands — REFUSING when no
|
|
7484
|
+
* implementation is registered.
|
|
7485
|
+
*
|
|
7486
|
+
* THIS IS THE ONE PLACE THIS PACKAGE'S "a missing run answers NULL" rule DOES
|
|
7487
|
+
* NOT APPLY, and the asymmetry is deliberate rather than an oversight of the
|
|
7488
|
+
* function precedent it otherwise copies. The parity argument fails on two
|
|
7489
|
+
* measured points:
|
|
7490
|
+
*
|
|
7491
|
+
* - **`emit` is REQUIRED and `run` is OPTIONAL**, so an operator is far more
|
|
7492
|
+
* likely to lack a run than a function is. A registered function without a
|
|
7493
|
+
* run is a declaration nobody finished; an operator without one is the
|
|
7494
|
+
* NORMAL, documented shape of a SQL-road operator.
|
|
7495
|
+
* - **an operator is usually a PREDICATE.** A scalar function answering NULL in
|
|
7496
|
+
* a projection puts a visible NULL in the output; a `bool` operator answering
|
|
7497
|
+
* NULL in a `WHERE` is UNKNOWN for every row, so the query returns ZERO ROWS
|
|
7498
|
+
* and looks like it ran. That is precisely the failure `OperatorExpr.toSQL`
|
|
7499
|
+
* refuses an unsupported dialect for — "a wrong answer that looks exactly
|
|
7500
|
+
* like a right one" — and it would be incoherent to refuse it on the SQL road
|
|
7501
|
+
* and produce it on the in-memory one.
|
|
7502
|
+
*
|
|
7503
|
+
* So the in-memory road refuses with the same `Problems`-grade message the emit
|
|
7504
|
+
* road uses. A deployment that genuinely wants a SQL-road-only operator gets an
|
|
7505
|
+
* error naming the operator the moment something tries to evaluate it, which is
|
|
7506
|
+
* the only honest answer: there is no value this package can compute for it.
|
|
7507
|
+
*/
|
|
7508
|
+
declare function runOperator(engine: QueryEngine, name: string, args: NamedArgs, ctx: RuntimeContext): Promise<Value>;
|
|
7509
|
+
/**
|
|
7510
|
+
* Run a registered TABULAR function over its named args (empty rows if absent).
|
|
7511
|
+
*
|
|
7512
|
+
* The ONE dispatch that does not tag its result, because its `Value` is not a
|
|
7513
|
+
* value of the function's output type: `raw` is the produced ROWS, and the
|
|
7514
|
+
* declared output names the Type those rows belong to. Tagging it would put a
|
|
7515
|
+
* row-set behind a scalar comparator.
|
|
7516
|
+
*/
|
|
5889
7517
|
declare function runTabularFunction(engine: QueryEngine, name: string, args: NamedArgs, ctx: RuntimeContext): Promise<Value>;
|
|
5890
7518
|
/** Run a registered AGGREGATE function over a group's per-row args (NULL if absent). */
|
|
5891
7519
|
declare function runAggregateFunction(engine: QueryEngine, name: string, rows: readonly NamedArgs[], ctx: RuntimeContext): Promise<Value>;
|
|
@@ -5909,12 +7537,29 @@ declare function runWindowFunction(engine: QueryEngine, name: string, partition:
|
|
|
5909
7537
|
* output FieldType through the registry); the engine caches the instances.
|
|
5910
7538
|
*/
|
|
5911
7539
|
|
|
5912
|
-
/**
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
7540
|
+
/**
|
|
7541
|
+
* ONE DECLARED, NAMED ARGUMENT — the half a FUNCTION parameter and an OPERATOR
|
|
7542
|
+
* operand share, and the type that DEFINES their common key set.
|
|
7543
|
+
*
|
|
7544
|
+
* Both are "a name plus the type a supplied expression is judged against", and
|
|
7545
|
+
* both are read by exactly the same two pieces of machinery: `observeNamedParams`
|
|
7546
|
+
* (which types a bare bind param FROM the declaration) and
|
|
7547
|
+
* {@link validateNamedCall} (which judges every other argument against it). Those
|
|
7548
|
+
* two took a `QueryFunction`, which is why an operator could not have reused
|
|
7549
|
+
* them; they take this instead, so an operand is not a second, drifting spelling
|
|
7550
|
+
* of the same fact.
|
|
7551
|
+
*/
|
|
7552
|
+
interface DeclaredArg {
|
|
7553
|
+
/** The declared name — the key a call writes in its `args` object. */
|
|
7554
|
+
readonly name: string;
|
|
7555
|
+
/** The declared type, or `undefined` when it accepts any (`type: 'any'`). */
|
|
7556
|
+
readonly fieldType: FieldType | undefined;
|
|
7557
|
+
/** Whether a call may omit it. Absent ⇒ required (an operator's operands always are). */
|
|
7558
|
+
readonly optional?: boolean;
|
|
7559
|
+
}
|
|
7560
|
+
/** A parsed declared parameter: a {@link DeclaredArg} whose optionality is always resolved. */
|
|
7561
|
+
interface ResolvedParam extends DeclaredArg {
|
|
7562
|
+
readonly optional: boolean;
|
|
5918
7563
|
}
|
|
5919
7564
|
/**
|
|
5920
7565
|
* A parsed output declaration:
|
|
@@ -5941,7 +7586,11 @@ declare class QueryFunction {
|
|
|
5941
7586
|
readonly params: ResolvedParam[];
|
|
5942
7587
|
/** The output declaration: a static field type, a Type reference, or `'inferred'`. */
|
|
5943
7588
|
readonly output: ResolvedOutput;
|
|
5944
|
-
/**
|
|
7589
|
+
/**
|
|
7590
|
+
* The emitted SQL function NAME when it differs from {@link name} — NOT a
|
|
7591
|
+
* template. See {@link FunctionDef.sql}: per-dialect or non-`name(args)`
|
|
7592
|
+
* emission is a `Dialect` subclass, not a declaration.
|
|
7593
|
+
*/
|
|
5945
7594
|
readonly sql?: string;
|
|
5946
7595
|
/**
|
|
5947
7596
|
* Declared-parameter indices whose argument is emitted as an INLINE SQL
|
|
@@ -6037,9 +7686,55 @@ declare class QueryFunction {
|
|
|
6037
7686
|
* - every supplied arg must name a real param → `function.unknown-arg`.
|
|
6038
7687
|
* - each supplied arg must be type-compatible → `function.arg-type`
|
|
6039
7688
|
* (a `'any'` param accepts anything), reported at path `['args', name]`.
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
7689
|
+
*
|
|
7690
|
+
* `paramArgs` names the arguments that are a BARE bind param (`{kind:'param'}`),
|
|
7691
|
+
* which the caller has already observed against the declared parameter type
|
|
7692
|
+
* (`observeNamedParams`). They are exempt from the type check for the reason
|
|
7693
|
+
* `ComparisonExpr` exempts a param operand: a param has no type of its own —
|
|
7694
|
+
* this call site is where it GETS one — so there is nothing here to be wrong.
|
|
7695
|
+
* A param whose uses across the query have no common type is reported once, by
|
|
7696
|
+
* `ParamSet`, as `param.conflict`.
|
|
7697
|
+
*/
|
|
7698
|
+
validateCall(namedArgs: ReadonlyMap<string, ResolvedType>, p: Problems, paramArgs?: ReadonlySet<string>): void;
|
|
7699
|
+
}
|
|
7700
|
+
/**
|
|
7701
|
+
* How one callable's call-shaped diagnostics READ. A `Record`-free bag rather
|
|
7702
|
+
* than three string arguments, because the four words only mean anything
|
|
7703
|
+
* together and a caller supplying them in the wrong order would produce a
|
|
7704
|
+
* grammatical message about the wrong thing.
|
|
7705
|
+
*/
|
|
7706
|
+
interface CallVocabulary {
|
|
7707
|
+
/** The callable, capitalized as a sentence subject: `Function` / `Operator`. */
|
|
7708
|
+
readonly noun: string;
|
|
7709
|
+
/** What a CALL supplies, capitalized: `Argument` / `Operand`. */
|
|
7710
|
+
readonly supplied: string;
|
|
7711
|
+
/** What a DECLARATION declares: `parameter` / `operand`. */
|
|
7712
|
+
readonly declared: string;
|
|
7713
|
+
/** The problem-code prefix: `function` / `operator`. */
|
|
7714
|
+
readonly code: string;
|
|
7715
|
+
}
|
|
7716
|
+
/**
|
|
7717
|
+
* Validate a call's NAMED arguments against its DECLARED ones — the three checks
|
|
7718
|
+
* a function call and an operator both need, in one place:
|
|
7719
|
+
* - every REQUIRED declaration must be supplied → `<code>.missing-arg`;
|
|
7720
|
+
* - every supplied arg must name a real one → `<code>.unknown-arg`;
|
|
7721
|
+
* - each supplied arg must be type-compatible → `<code>.arg-type`
|
|
7722
|
+
* (an `undefined` declared type accepts anything), at path `['args', name]`.
|
|
7723
|
+
*
|
|
7724
|
+
* `paramArgs` names the arguments that are a BARE bind param (`{kind:'param'}`),
|
|
7725
|
+
* which the caller has already observed against the declared type
|
|
7726
|
+
* (`observeNamedParams`). They are exempt from the type check for the reason
|
|
7727
|
+
* `ComparisonExpr` exempts a param operand: a param has no type of its own —
|
|
7728
|
+
* this call site is where it GETS one — so there is nothing here to be wrong. A
|
|
7729
|
+
* param whose uses across the query have no common type is reported once, by
|
|
7730
|
+
* `ParamSet`, as `param.conflict`.
|
|
7731
|
+
*
|
|
7732
|
+
* SHARED rather than copied onto the operator, because the three checks are the
|
|
7733
|
+
* whole of what "a named-argument call" means and a second copy would drift in
|
|
7734
|
+
* exactly the way the A22 fix showed one had already: three of the four
|
|
7735
|
+
* call-shaped exprs never observed their params at all, and the fourth did.
|
|
7736
|
+
*/
|
|
7737
|
+
declare function validateNamedCall(words: CallVocabulary, name: string, declared: readonly DeclaredArg[], namedArgs: ReadonlyMap<string, ResolvedType>, p: Problems, paramArgs?: ReadonlySet<string>): void;
|
|
6043
7738
|
/**
|
|
6044
7739
|
* The merge semantics of ONE aggregate CALL: the function's declared
|
|
6045
7740
|
* {@link AggregateMerge}, reduced to `'none'` when the call is DISTINCT and the
|
|
@@ -6057,6 +7752,317 @@ declare class QueryFunction {
|
|
|
6057
7752
|
*/
|
|
6058
7753
|
declare function mergeOfAggregateCall(declared: AggregateMerge | undefined, distinct: boolean): AggregateMerge;
|
|
6059
7754
|
|
|
7755
|
+
/**
|
|
7756
|
+
* `{slot}` SQL TEMPLATES — the scanner two declarations share.
|
|
7757
|
+
*
|
|
7758
|
+
* A refinement declares `sql` / `cast` templates whose slots are its declared
|
|
7759
|
+
* OPTIONS (`geometry({subtype},{srid})`); an operator declares `emit` templates
|
|
7760
|
+
* whose slots are its declared OPERANDS (`({left} && {right})`). The two fill
|
|
7761
|
+
* their slots with entirely different things — one splices a validated token,
|
|
7762
|
+
* the other an already-emitted `SqlText` fragment — but they SCAN identically,
|
|
7763
|
+
* and a scanner that differed by one character between them would let a slot
|
|
7764
|
+
* spelling pass one declaration road and be read as literal text on the other.
|
|
7765
|
+
*
|
|
7766
|
+
* So this module owns exactly the part that must not differ: finding the slots,
|
|
7767
|
+
* splitting the literal text around them, and handing each slot name back to the
|
|
7768
|
+
* caller to resolve. Every decision that is not scanning — what a slot may name,
|
|
7769
|
+
* what the resolved text must look like, what a missing one means — stays with
|
|
7770
|
+
* the declaration that owns it.
|
|
7771
|
+
*
|
|
7772
|
+
* A LIST of parts rather than a string with placeholders left in it, because a
|
|
7773
|
+
* slot's value is filled later (per column, per emit) and re-scanning for `{…}`
|
|
7774
|
+
* at that point would let a resolved value that happened to contain braces be
|
|
7775
|
+
* read as a slot of its own.
|
|
7776
|
+
*/
|
|
7777
|
+
/** One piece of a compiled template: literal SQL the declarer wrote, or a slot still to be filled. */
|
|
7778
|
+
type TemplatePart = {
|
|
7779
|
+
readonly text: string;
|
|
7780
|
+
} | {
|
|
7781
|
+
readonly slot: string;
|
|
7782
|
+
};
|
|
7783
|
+
/** A compiled template — literal parts and the slots still to be filled. */
|
|
7784
|
+
type Template = readonly TemplatePart[];
|
|
7785
|
+
/** Whether `part` is an unresolved slot (the discriminator, in one place). */
|
|
7786
|
+
declare function isSlot(part: TemplatePart): part is {
|
|
7787
|
+
readonly slot: string;
|
|
7788
|
+
};
|
|
7789
|
+
/**
|
|
7790
|
+
* Split `template` into its literal parts and its `{slot}` parts, asking
|
|
7791
|
+
* `resolve` what each slot name means.
|
|
7792
|
+
*
|
|
7793
|
+
* `resolve` returns the part to emit — `{ text }` for a slot that resolves NOW
|
|
7794
|
+
* (a refinement's base option is a declaration-time constant) or `{ slot }` for
|
|
7795
|
+
* one that resolves later — and is expected to THROW for a name it does not
|
|
7796
|
+
* recognise. Refusing is the caller's job because only the caller can say what
|
|
7797
|
+
* the legal names were and what they are for, and a slot silently kept as
|
|
7798
|
+
* literal text is the failure this whole mechanism exists to prevent: it would
|
|
7799
|
+
* emit `{srid}` into SQL verbatim.
|
|
7800
|
+
*/
|
|
7801
|
+
declare function scanTemplate(template: string, resolve: (slot: string) => TemplatePart): Template;
|
|
7802
|
+
/** Every slot name `template` still carries, in first-appearance order. */
|
|
7803
|
+
declare function templateSlotNames(template: Template): Set<string>;
|
|
7804
|
+
|
|
7805
|
+
/**
|
|
7806
|
+
* REGISTERED OPERATORS — `&&`, `<->`, `@>`: a name whose SQL a DECLARATION
|
|
7807
|
+
* supplies, per dialect.
|
|
7808
|
+
*
|
|
7809
|
+
* A domain's predicates were already reachable as ordinary scalar FUNCTIONS
|
|
7810
|
+
* (`ST_Contains(a, b)` registers and emits today, with no library change). What
|
|
7811
|
+
* a function declaration cannot express is the OTHER half of every real SQL
|
|
7812
|
+
* domain: the infix operators, which have no call form at all — `a && b` is not
|
|
7813
|
+
* `&&(a, b)` in any dialect — and whose SQL differs by dialect, which
|
|
7814
|
+
* `FunctionDef.sql` (a NAME, never a template) has no way to say.
|
|
7815
|
+
*
|
|
7816
|
+
* ONE NEW EXPR KIND, NOT N REGISTERED EXPR CLASSES. `ExprKind` gains exactly one
|
|
7817
|
+
* member, once, at this package's own hand (`operator`), and the operator
|
|
7818
|
+
* VOCABULARY is what a third party opens — precisely the relationship
|
|
7819
|
+
* `function-call` already has to `registerFunction`. The alternative,
|
|
7820
|
+
* `defineExpr`, is parse DISPATCH for a whole `ExprDef.kind`: registering one
|
|
7821
|
+
* re-points every program's parse in that registry, and it asks a declarer to
|
|
7822
|
+
* implement `resolve` / `validateWalk` / `evaluate` / `cost` / `selectivity` /
|
|
7823
|
+
* `toSQL` / `toJSON` / `clone` / `toCode` / `SHAPE` — ten members for `a && b`,
|
|
7824
|
+
* where a function author writes one JSON object.
|
|
7825
|
+
*
|
|
7826
|
+
* THE DECLARATION IS PURE JSON, so it persists, crosses the wire and reaches a
|
|
7827
|
+
* model; the `run` half is code, registered separately
|
|
7828
|
+
* (`registry.registerOperatorRun`), exactly as `FunctionRun` sits beside
|
|
7829
|
+
* `FunctionDef`. That split is not symmetry — it is what lets a consumer store a
|
|
7830
|
+
* catalog of operators in a database and replay it at boot.
|
|
7831
|
+
*
|
|
7832
|
+
* WHAT IT DELIBERATELY DOES NOT CARRY, each because nothing would read it:
|
|
7833
|
+
*
|
|
7834
|
+
* - **`precedence`.** Every emit template ships PARENTHESIZED (checked at
|
|
7835
|
+
* registration, see {@link compileEmit}), and there is no text parser in this
|
|
7836
|
+
* package — the authoring surface is JSON, so an operator is function-shaped
|
|
7837
|
+
* on the wire and precedence never arises at parse. That leaves `toCode()`,
|
|
7838
|
+
* which renders the WIRE shape (`&&(left: …, right: …)`) rather than infix,
|
|
7839
|
+
* because rendering infix needs the declared operand ORDER and `toCode` has
|
|
7840
|
+
* no registry to look it up in — an infix rendering in AUTHORED order would
|
|
7841
|
+
* silently swap `<->`'s operands. With no infix rendering anywhere, a
|
|
7842
|
+
* `precedence` number has no reader at all. It comes back with a text DSL, if
|
|
7843
|
+
* one ever arrives.
|
|
7844
|
+
* - **`indexed`.** The cost model's {@link import('./cost').IndexProbe} means
|
|
7845
|
+
* "this column is bound to N POINT values", which is what an index PREFIX
|
|
7846
|
+
* reduction is computed from. A bounding-box overlap is not that, so
|
|
7847
|
+
* crediting it would claim a reduction that does not apply. Declare
|
|
7848
|
+
* {@link OperatorDef.selectivity} instead, which the same model reads and
|
|
7849
|
+
* which says the true thing.
|
|
7850
|
+
* - **`changes`.** `QueryReferences` enumerates the FUNCTIONS a query invokes
|
|
7851
|
+
* and `changeInterval` folds their `changes`; there is no operator channel,
|
|
7852
|
+
* so a declared `changes` would be silently ignored. Adding one is a change
|
|
7853
|
+
* to a public result shape and belongs with the in-memory work, not here.
|
|
7854
|
+
*/
|
|
7855
|
+
|
|
7856
|
+
/**
|
|
7857
|
+
* Allowed charset for a registered operator NAME — the SQL operator punctuation,
|
|
7858
|
+
* and NOTHING that could be read as an identifier.
|
|
7859
|
+
*
|
|
7860
|
+
* This is the set PostgreSQL itself allows in `CREATE OPERATOR`
|
|
7861
|
+
* (`+ - * / < > = ~ ! @ # % ^ & | ` ?`), which is the honest answer to "what will
|
|
7862
|
+
* a dialect actually accept": every engine with user-definable operators draws
|
|
7863
|
+
* from that punctuation, and no engine accepts a bare word as an infix operator
|
|
7864
|
+
* without quoting rules of its own. The 63-character cap is Postgres's
|
|
7865
|
+
* `NAMEDATALEN - 1`; a longer name could not be created there in the first place.
|
|
7866
|
+
*
|
|
7867
|
+
* IT IS DISJOINT FROM `FUNCTION_NAME_PATTERN` (`^[A-Za-z_][A-Za-z0-9_.]*$`), and
|
|
7868
|
+
* that is the point rather than a side effect. The two registries are separate
|
|
7869
|
+
* maps looked up by different expr kinds, so overlapping charsets would let one
|
|
7870
|
+
* name mean two callables — and a model reading `describeEngine` would see
|
|
7871
|
+
* `overlaps` in the operators block and in the functions block with no way to
|
|
7872
|
+
* tell which `kind` reaches which. A WORD operator (`OVERLAPS`, `IS DISTINCT
|
|
7873
|
+
* FROM`) is therefore spelled one of the two ways that already work: as a
|
|
7874
|
+
* function, or as the literal text of an emit template under a punctuation name.
|
|
7875
|
+
*
|
|
7876
|
+
* The COMMENT sequences are refused separately ({@link refuseCommentSequence}) —
|
|
7877
|
+
* they are drawn from this very charset, and `--` is not an operator anywhere,
|
|
7878
|
+
* it is the start of a line comment.
|
|
7879
|
+
*/
|
|
7880
|
+
declare const OPERATOR_NAME_PATTERN: RegExp;
|
|
7881
|
+
/**
|
|
7882
|
+
* One operand a registered operator declares — the same relationship
|
|
7883
|
+
* `FunctionParamDef` has to a function, and deliberately the same vocabulary: an
|
|
7884
|
+
* operand's `type` is an ordinary {@link FieldTypeDef}, so it is validated,
|
|
7885
|
+
* described, meet-checked and round-tripped by machinery that already exists.
|
|
7886
|
+
*
|
|
7887
|
+
* There is no `optional`. An operator's arity is FIXED by the SQL it emits — the
|
|
7888
|
+
* template names every operand, and a template that could drop one would emit a
|
|
7889
|
+
* dangling `&&` — so "supplied or not" is not a question a declaration gets to
|
|
7890
|
+
* leave open. That is the one place this shape deliberately differs from
|
|
7891
|
+
* `FunctionParamDef`.
|
|
7892
|
+
*/
|
|
7893
|
+
interface OperatorOperandDef {
|
|
7894
|
+
/** The operand's name — the key a call writes in `args`, and the template's `{slot}`. */
|
|
7895
|
+
readonly name: string;
|
|
7896
|
+
/**
|
|
7897
|
+
* The operand's declared type, or `'any'` to accept every field type. `'any'`
|
|
7898
|
+
* declares nothing to check a call against AND nothing to type a bare bind
|
|
7899
|
+
* param from, so it is a real widening rather than a shorthand.
|
|
7900
|
+
*/
|
|
7901
|
+
readonly type: FieldTypeDef | 'any';
|
|
7902
|
+
}
|
|
7903
|
+
/**
|
|
7904
|
+
* A registered operator's DECLARATION — pure JSON, persistable, replayable, and
|
|
7905
|
+
* the thing a model is shown.
|
|
7906
|
+
*/
|
|
7907
|
+
interface OperatorDef {
|
|
7908
|
+
/**
|
|
7909
|
+
* The operator, spelled as SQL spells it (`&&`, `<->`, `@>`). Held to
|
|
7910
|
+
* {@link OPERATOR_NAME_PATTERN}; it is the registry key AND the token a model
|
|
7911
|
+
* writes in `{ kind: 'operator', op: '&&' }`, and it renders VERBATIM
|
|
7912
|
+
* everywhere either of them reads it.
|
|
7913
|
+
*/
|
|
7914
|
+
readonly name: string;
|
|
7915
|
+
/** The operands, in declared order. At least one; an operand-less operator is a constant, i.e. a function. */
|
|
7916
|
+
readonly operands: readonly OperatorOperandDef[];
|
|
7917
|
+
/**
|
|
7918
|
+
* The type the operator PRODUCES. Concrete — never `'inferred'`, unlike
|
|
7919
|
+
* `FunctionDef.output`: an operator's whole reason to exist is that its
|
|
7920
|
+
* meaning is not derivable from its operands (`<->` takes two geometries and
|
|
7921
|
+
* yields a NUMBER), so inferring it from the first argument would be wrong far
|
|
7922
|
+
* more often than right.
|
|
7923
|
+
*/
|
|
7924
|
+
readonly output: FieldTypeDef;
|
|
7925
|
+
/**
|
|
7926
|
+
* What the operator MEANS, for a model. REQUIRED, and deliberately stricter
|
|
7927
|
+
* than `FunctionDef.instructions`, which is optional. Measured: an
|
|
7928
|
+
* undocumented registered item renders as a bare signature beside documented
|
|
7929
|
+
* siblings, and a model choosing among four PostGIS predicates from that
|
|
7930
|
+
* listing is guessing. The expensive failure is not the ~25 tokens of the
|
|
7931
|
+
* line, it is the validate-fail retry that carries the WHOLE schema a second
|
|
7932
|
+
* time.
|
|
7933
|
+
*/
|
|
7934
|
+
readonly instructions: string;
|
|
7935
|
+
/**
|
|
7936
|
+
* Worked examples as RAW JSON strings (the `FunctionDef.examples` contract),
|
|
7937
|
+
* rendered under the signature by `describeOperators` and round-tripped by
|
|
7938
|
+
* {@link QueryOperator.toJSON}.
|
|
7939
|
+
*/
|
|
7940
|
+
readonly examples?: readonly string[];
|
|
7941
|
+
/**
|
|
7942
|
+
* Per-dialect emission, keyed by `Dialect.name`. `{operandName}` slots are
|
|
7943
|
+
* replaced by that operand's already-emitted SQL fragment.
|
|
7944
|
+
*
|
|
7945
|
+
* A DIALECT WITH NO ENTRY IS UNSUPPORTED, and emitting for it is REFUSED
|
|
7946
|
+
* rather than degraded — see `OperatorExpr.toSQL`. The base dialect degrades
|
|
7947
|
+
* silently for BUILTINS whose semantics this package owns and documents
|
|
7948
|
+
* (`dateAdd` → the input date unchanged, `arrayContains` → `(1 = 0)`); that is
|
|
7949
|
+
* portable-SQL policy for a function whose degrade is written down and tested.
|
|
7950
|
+
* A third party cannot document a degrade this package never sees, and `&&`
|
|
7951
|
+
* degrading to `(1 = 0)` returns ZERO ROWS for a query the caller believed
|
|
7952
|
+
* ran.
|
|
7953
|
+
*/
|
|
7954
|
+
readonly emit: Readonly<Record<string, string>>;
|
|
7955
|
+
/**
|
|
7956
|
+
* The fraction of rows this operator keeps as a WHERE predicate — the same
|
|
7957
|
+
* declared-fact idiom as `FunctionDef.cost`. Defaults to 1 (keeps everything),
|
|
7958
|
+
* which is what an undeclared predicate already costs.
|
|
7959
|
+
*/
|
|
7960
|
+
readonly selectivity?: number;
|
|
7961
|
+
/** Intrinsic per-call cost beyond the operands' own (default none). */
|
|
7962
|
+
readonly cost?: Cost;
|
|
7963
|
+
/**
|
|
7964
|
+
* Who declared it — surfaced when a SECOND declarer claims the same name, so
|
|
7965
|
+
* the refusal names the incumbent instead of just the collision.
|
|
7966
|
+
*/
|
|
7967
|
+
readonly declaredBy?: string;
|
|
7968
|
+
}
|
|
7969
|
+
/**
|
|
7970
|
+
* A COMPILED operator — the declaration plus its operand / output types parsed
|
|
7971
|
+
* and its emit templates split.
|
|
7972
|
+
*
|
|
7973
|
+
* Built only by {@link QueryOperator.compile} (via `Registry.registerOperator`),
|
|
7974
|
+
* so an instance in hand has already passed every registration-time check.
|
|
7975
|
+
*
|
|
7976
|
+
* COMPILED EAGERLY, unlike `QueryFunction`, which the engine builds lazily on
|
|
7977
|
+
* first call. The difference is deliberate and it is the step-2 lesson applied:
|
|
7978
|
+
* a defect found at the CALL has no declaration to attribute it to, and an emit
|
|
7979
|
+
* template is only ever wrong at the declaration. It costs one ordering rule —
|
|
7980
|
+
* every field-type refinement an operand names must be registered first — which
|
|
7981
|
+
* is the same rule a Type already lives under, and it is enforced with the
|
|
7982
|
+
* message that road already has (`field-type.unknown-refinement`). Compiling
|
|
7983
|
+
* does NOT freeze the refinement vocabulary: the operand types parse through the
|
|
7984
|
+
* registry's unflagged road, so a refinement may still be registered afterwards.
|
|
7985
|
+
*/
|
|
7986
|
+
declare class QueryOperator {
|
|
7987
|
+
/** The operator as SQL spells it — the registry key and the wire `op`. */
|
|
7988
|
+
readonly name: string;
|
|
7989
|
+
/** The declared operands, in order, each type parsed (`undefined` for `'any'`). */
|
|
7990
|
+
readonly operands: readonly DeclaredArg[];
|
|
7991
|
+
/** The type this operator produces. */
|
|
7992
|
+
readonly output: FieldType;
|
|
7993
|
+
/** What it means, for a model. */
|
|
7994
|
+
readonly instructions: string;
|
|
7995
|
+
/** Worked examples as raw JSON strings, or `undefined`. */
|
|
7996
|
+
readonly examples: readonly string[] | undefined;
|
|
7997
|
+
/** Per dialect name, the compiled emit template. */
|
|
7998
|
+
private readonly emits;
|
|
7999
|
+
/** The declared WHERE selectivity (1 when undeclared). */
|
|
8000
|
+
readonly selectivity: number;
|
|
8001
|
+
/** The declared intrinsic cost (zero when undeclared). */
|
|
8002
|
+
readonly cost: Cost;
|
|
8003
|
+
/** Who declared it, when they said. */
|
|
8004
|
+
readonly declaredBy: string | undefined;
|
|
8005
|
+
/** The declaration verbatim, for {@link toJSON} — a declaration round-trips as itself. */
|
|
8006
|
+
private readonly def;
|
|
8007
|
+
private constructor();
|
|
8008
|
+
/** The dialect names this operator declares SQL for, in declaration order. */
|
|
8009
|
+
dialects(): string[];
|
|
8010
|
+
/**
|
|
8011
|
+
* The declared operand named `name`, or `undefined`.
|
|
8012
|
+
*
|
|
8013
|
+
* Read at EMIT as well as at validate: an operand's declared type is what lets
|
|
8014
|
+
* a document operand bind through its type's own `cast` template rather than
|
|
8015
|
+
* through the dialect's default json cast (see `OperatorExpr.toSQL`). A map
|
|
8016
|
+
* rather than a scan because an emit walks every slot of every operator
|
|
8017
|
+
* occurrence in a statement.
|
|
8018
|
+
*/
|
|
8019
|
+
operand(name: string): DeclaredArg | undefined;
|
|
8020
|
+
/** {@link operands} keyed by name, built once in the constructor (see {@link operand}). */
|
|
8021
|
+
private readonly operandsByName;
|
|
8022
|
+
/**
|
|
8023
|
+
* Validate a call's named operands — the same three checks a function call is
|
|
8024
|
+
* held to (`operator.missing-arg` / `.unknown-arg` / `.arg-type`), through the
|
|
8025
|
+
* shared {@link validateNamedCall} rather than a second copy of them.
|
|
8026
|
+
*
|
|
8027
|
+
* NO INTERACTION WITH A TYPE'S DECLARED `compare`, and that is a decision
|
|
8028
|
+
* rather than an omission. `compare` says which arms of the CLOSED builtin
|
|
8029
|
+
* comparison grammar (`= <> < <= > >=`, LIKE, and through the shared gate
|
|
8030
|
+
* BETWEEN / IN / containment) mean anything for a type. An operator is not one
|
|
8031
|
+
* of those nine: it declares its own operands and its own meaning, so a type
|
|
8032
|
+
* declaring `equality: false` is exactly the type an operator is FOR —
|
|
8033
|
+
* `Geometry` refuses `=` because comparing two geometries for equality is
|
|
8034
|
+
* meaningless, and `&&` is what a caller reaches for instead. Gating operators
|
|
8035
|
+
* on `compare` would delete the mechanism that makes an honest declaration
|
|
8036
|
+
* usable at all.
|
|
8037
|
+
*/
|
|
8038
|
+
validateCall(namedArgs: ReadonlyMap<string, ResolvedType>, p: Problems, paramArgs: ReadonlySet<string>): void;
|
|
8039
|
+
/** The compiled emit template for `dialect`, or `undefined` when it declares none. */
|
|
8040
|
+
emitFor(dialect: string): Template | undefined;
|
|
8041
|
+
/**
|
|
8042
|
+
* The declaration this was compiled from — byte-identical, so a consumer that
|
|
8043
|
+
* persisted a catalog reads back exactly what it wrote. (Unlike
|
|
8044
|
+
* `QueryFunction.toJSON`, which RE-EMITS from parsed parts; there is nothing
|
|
8045
|
+
* to gain here from re-deriving a def the registry already holds, and
|
|
8046
|
+
* re-deriving is how a round-trip acquires drift.)
|
|
8047
|
+
*/
|
|
8048
|
+
toJSON(): OperatorDef;
|
|
8049
|
+
/**
|
|
8050
|
+
* Validate and compile a declaration. Every check refuses rather than warns:
|
|
8051
|
+
* an operator that registered half-broken would be wrong in every query that
|
|
8052
|
+
* ever named it, and the SQL half of it would be wrong at a point with no
|
|
8053
|
+
* declaration in sight.
|
|
8054
|
+
*/
|
|
8055
|
+
static compile(def: OperatorDef, registry: Registry,
|
|
8056
|
+
/**
|
|
8057
|
+
* How an operand's declared type becomes a `FieldType`. Supplied by the
|
|
8058
|
+
* registry rather than taken off it, because compiling must NOT freeze the
|
|
8059
|
+
* refinement vocabulary — a registry that refused every later
|
|
8060
|
+
* `registerFieldType` merely because an operator was declared would make the
|
|
8061
|
+
* two registrations order-coupled for no reason.
|
|
8062
|
+
*/
|
|
8063
|
+
parseFieldType: (json: FieldTypeDef) => FieldType): QueryOperator;
|
|
8064
|
+
}
|
|
8065
|
+
|
|
6060
8066
|
/**
|
|
6061
8067
|
* QueryEngine — the minimal engine surface needed by resolution + validation
|
|
6062
8068
|
* THIS PHASE (Phase 2).
|
|
@@ -6082,10 +8088,27 @@ interface Embedder {
|
|
|
6082
8088
|
/** Embed `text` into a dense vector. */
|
|
6083
8089
|
embed(text: string): Promise<number[]>;
|
|
6084
8090
|
}
|
|
6085
|
-
/** Options for constructing a {@link QueryEngine} (embedder, executors, backings). */
|
|
8091
|
+
/** Options for constructing a {@link QueryEngine} (embedder, executors, backings, text casing). */
|
|
6086
8092
|
interface QueryEngineOptions {
|
|
6087
8093
|
/** Optional embedder for semantic features. */
|
|
6088
8094
|
embedder?: Embedder;
|
|
8095
|
+
/**
|
|
8096
|
+
* The DEFAULT {@link TextCasing} for text columns that declare none — the
|
|
8097
|
+
* deployment-wide answer to "does `'Ada' = 'ada'` hold, and who folds?".
|
|
8098
|
+
* Defaults to {@link DEFAULT_TEXT_CASING} (`'fold'`, this package's behaviour
|
|
8099
|
+
* in every release before the option existed).
|
|
8100
|
+
*
|
|
8101
|
+
* Set it once, here, rather than on every declaration; a field that declares
|
|
8102
|
+
* its own `casing` still wins, because collation is genuinely a per-COLUMN
|
|
8103
|
+
* fact and this default only ever speaks for the columns that said nothing.
|
|
8104
|
+
*
|
|
8105
|
+
* A deployment whose text columns are mostly identifiers, codes, uuids or
|
|
8106
|
+
* enums wants `'exact'`: folding them is semantically pointless, it makes
|
|
8107
|
+
* every predicate over them non-sargable, and on PostgreSQL a `LOWER()` over
|
|
8108
|
+
* a physical `uuid` column does not merely deoptimise — the function does not
|
|
8109
|
+
* exist for that type and the statement errors.
|
|
8110
|
+
*/
|
|
8111
|
+
textCasing?: TextCasing;
|
|
6089
8112
|
/** Per-Type data + validation providers, keyed by Type name. */
|
|
6090
8113
|
executors?: Record<string, TypeExecutor>;
|
|
6091
8114
|
/**
|
|
@@ -6153,6 +8176,14 @@ declare class QueryEngine {
|
|
|
6153
8176
|
readonly registry: Registry;
|
|
6154
8177
|
/** Optional embedding provider (semantic features, Phase 4). */
|
|
6155
8178
|
readonly embedder?: Embedder;
|
|
8179
|
+
/**
|
|
8180
|
+
* The default {@link TextCasing} for text columns that declare none. Read by
|
|
8181
|
+
* BOTH emission roads — `ComparisonExpr` / `ArrayOpExpr` / `text-search` /
|
|
8182
|
+
* `text-score` reach it through `SqlContext.engine` and
|
|
8183
|
+
* `RuntimeContext.engine` — which is why the policy lives on the engine and
|
|
8184
|
+
* not on a `Dialect` (an argument to `toSQL`, invisible to the runtime).
|
|
8185
|
+
*/
|
|
8186
|
+
readonly textCasing: TextCasing;
|
|
6156
8187
|
/**
|
|
6157
8188
|
* The NEUTRAL cost context over this engine — no execution-time `filters` /
|
|
6158
8189
|
* `sort` / `params`.
|
|
@@ -6245,6 +8276,16 @@ declare class QueryEngine {
|
|
|
6245
8276
|
* Wraps the registry's JSON `FunctionDef` once and caches the instance.
|
|
6246
8277
|
*/
|
|
6247
8278
|
lookupFunction(name: string): QueryFunction | undefined;
|
|
8279
|
+
/**
|
|
8280
|
+
* Look up a registered OPERATOR by name, or `undefined`.
|
|
8281
|
+
*
|
|
8282
|
+
* No cache, unlike {@link lookupFunction}: an operator is COMPILED at
|
|
8283
|
+
* registration (an emit template is only ever wrong at its declaration), so
|
|
8284
|
+
* the registry already holds the parsed instance and this is a map read.
|
|
8285
|
+
*/
|
|
8286
|
+
lookupOperator(name: string): QueryOperator | undefined;
|
|
8287
|
+
/** An operator's runtime implementation, if registered on the registry. */
|
|
8288
|
+
operatorRun(name: string): OperatorRun | undefined;
|
|
6248
8289
|
/** Create a fresh root scope (with its own shared `ParamSet`). */
|
|
6249
8290
|
globalScope(): QueryScope;
|
|
6250
8291
|
/** Parse a JSON expr def into an `Expr` via the registry. */
|
|
@@ -6265,9 +8306,42 @@ declare class QueryEngine {
|
|
|
6265
8306
|
* Validate a query: structural walk + accumulated param diagnostics + each
|
|
6266
8307
|
* referenced Type's executor `validate` hook. When `constraints` are
|
|
6267
8308
|
* supplied, the estimated `cost` is checked too and `cost.rows-exceeded` /
|
|
6268
|
-
* `cost.bytes-exceeded` problems are appended (opt-in).
|
|
8309
|
+
* `cost.bytes-exceeded` problems are appended (opt-in). When `options.params`
|
|
8310
|
+
* are supplied, the VALUES are checked against the type each param's uses
|
|
8311
|
+
* require, appending `param.value` / `param.missing` / `param.unknown` (also
|
|
8312
|
+
* opt-in — see {@link checkParams}).
|
|
6269
8313
|
*/
|
|
6270
8314
|
validateQuery(query: Query | QueryDef, scope?: QueryScope, constraints?: CostConstraints, options?: CostOptions): Problems;
|
|
8315
|
+
/**
|
|
8316
|
+
* The full introspection of a query's bind PARAMETERS: for each, every place
|
|
8317
|
+
* it is used, what each use requires of it, the type MERGED from those uses,
|
|
8318
|
+
* and the conflict when they have none. The rich counterpart to
|
|
8319
|
+
* `Query.params()` (which reports the minimal `{ name, type }` a caller
|
|
8320
|
+
* binds with) — read this to EXPLAIN a param rather than to bind one.
|
|
8321
|
+
*
|
|
8322
|
+
* A param's type is the MEET of its uses, i.e. the most specific type
|
|
8323
|
+
* compatible with all of them: compared against an `enum` in one place and
|
|
8324
|
+
* plain `text` in another it is the ENUM, and it is that answer regardless of
|
|
8325
|
+
* which use the walk reached first.
|
|
8326
|
+
*/
|
|
8327
|
+
parameters(query: Query | QueryDef, scope?: QueryScope): ParamInfo[];
|
|
8328
|
+
/**
|
|
8329
|
+
* Check SUPPLIED param values against what the query's uses of each param
|
|
8330
|
+
* require — the PRE-EXECUTION gate for a binding, and the only place a bound
|
|
8331
|
+
* value is compared with the type it is bound into. Returns the value
|
|
8332
|
+
* problems and nothing else (a standalone entry point, mirroring
|
|
8333
|
+
* {@link checkCost}); the param TYPE problems — `param.untyped` /
|
|
8334
|
+
* `param.conflict` — come from {@link validateQuery}.
|
|
8335
|
+
*
|
|
8336
|
+
* `param.value` (error) is a value that does not satisfy the merged type;
|
|
8337
|
+
* `param.missing` (warning) is a typed param with no value, which binds SQL
|
|
8338
|
+
* NULL; `param.unknown` (warning) is a value supplied under a name the query
|
|
8339
|
+
* has no param for. Reported as Problems rather than thrown, so a bad binding
|
|
8340
|
+
* reads like every other diagnostic — and so `run` / `toSQL` stay unchanged:
|
|
8341
|
+
* they do NOT validate, because a hot path that can only throw is not the
|
|
8342
|
+
* place to discover this.
|
|
8343
|
+
*/
|
|
8344
|
+
checkParams(query: Query | QueryDef, params: Readonly<Record<string, JsonValue | undefined>>, scope?: QueryScope): Problems;
|
|
6271
8345
|
/**
|
|
6272
8346
|
* Estimate a query's `{ rows, bytes }` cost against a scope (root if omitted).
|
|
6273
8347
|
* `options` may supply the execution-time `filters` / `sort` the query is
|
|
@@ -6599,6 +8673,27 @@ declare abstract class Query {
|
|
|
6599
8673
|
* (see {@link observeRowBounds}), so a bound at ANY nesting depth lands here.
|
|
6600
8674
|
*/
|
|
6601
8675
|
params(engine: QueryEngine, scope?: QueryScope): ParamDef[];
|
|
8676
|
+
/**
|
|
8677
|
+
* The FULL introspection of this query's bind parameters: for each, every
|
|
8678
|
+
* place it is used, what each use requires of it, the type MERGED from those
|
|
8679
|
+
* uses (the meet — the most specific type compatible with all of them), and
|
|
8680
|
+
* the conflict when they have none.
|
|
8681
|
+
*
|
|
8682
|
+
* The rich counterpart to {@link params}, which reports only `{ name, type }`
|
|
8683
|
+
* for the params that HAVE a type. This reports every param the query
|
|
8684
|
+
* mentions, including the untyped and the conflicting ones, with enough detail
|
|
8685
|
+
* to explain the answer: a UI can label an input from `type` and say why from
|
|
8686
|
+
* `uses`, and a caller can check a supplied value against exactly the type the
|
|
8687
|
+
* query requires (see `QueryEngine.checkParams`).
|
|
8688
|
+
*/
|
|
8689
|
+
paramInfo(engine: QueryEngine, scope?: QueryScope): ParamInfo[];
|
|
8690
|
+
/**
|
|
8691
|
+
* Run the resolution / validation walk purely for its side effect of
|
|
8692
|
+
* populating the scope's shared `ParamSet`, discarding the problems. Shared by
|
|
8693
|
+
* {@link params} / {@link paramInfo} / `QueryEngine.checkParams`, so all three
|
|
8694
|
+
* see exactly the same observations.
|
|
8695
|
+
*/
|
|
8696
|
+
walkParams(engine: QueryEngine, scope?: QueryScope): QueryScope;
|
|
6602
8697
|
/**
|
|
6603
8698
|
* Observe a `limit` / `offset` ROW BOUND that is bound to a `param` (see
|
|
6604
8699
|
* `autoPaginate`) against a number field type — a bound is always a row count
|
|
@@ -6869,6 +8964,145 @@ interface CheckCtx {
|
|
|
6869
8964
|
interface Shape<T> {
|
|
6870
8965
|
check(json: unknown, ctx: CheckCtx): T | typeof INVALID;
|
|
6871
8966
|
}
|
|
8967
|
+
/** A plain, non-array object (so string keys can be indexed off it). */
|
|
8968
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
8969
|
+
/**
|
|
8970
|
+
* An aid-directed `expected <label>[, got <received>]` message — the shared
|
|
8971
|
+
* phrasing behind every scalar mismatch and the dispatch's not-object error.
|
|
8972
|
+
* Reuses `aidInfo` (the query-domain label) + `describeInput` from `aids.ts`.
|
|
8973
|
+
*/
|
|
8974
|
+
declare function expected(aid: string, json: unknown): string;
|
|
8975
|
+
/** Exact-equality shape (used for a `kind` discriminant). Mismatch → INVALID. */
|
|
8976
|
+
declare function lit$1<const V extends string | number | boolean | null>(value: V): Shape<V>;
|
|
8977
|
+
/** A string. Mismatch → aid-directed `shape.type` + INVALID. */
|
|
8978
|
+
declare function str(aid: string): Shape<string>;
|
|
8979
|
+
/** A number. Mismatch → aid-directed `shape.type` + INVALID. */
|
|
8980
|
+
declare function num(aid: string): Shape<number>;
|
|
8981
|
+
/** An integer (`Number.isInteger`). Mismatch → aid-directed `shape.type` + INVALID. */
|
|
8982
|
+
declare function int(aid: string): Shape<number>;
|
|
8983
|
+
/** A boolean. Mismatch → aid-directed `shape.type` + INVALID. */
|
|
8984
|
+
declare function bool(aid: string): Shape<boolean>;
|
|
8985
|
+
/** A leaf scalar (`string | number | boolean | null`). Mismatch → INVALID. */
|
|
8986
|
+
declare function scalar(aid: string): Shape<ScalarValue>;
|
|
8987
|
+
/**
|
|
8988
|
+
* ANY JSON value — a scalar, or a whole document (array / object) whose every
|
|
8989
|
+
* leaf is itself JSON. Mismatch → aid-directed `shape.type` + INVALID.
|
|
8990
|
+
*
|
|
8991
|
+
* The RECURSIVE check is what makes this safe to build a `LiteralExpr` from:
|
|
8992
|
+
* the incoming value is `unknown` (off the wire, or out of a caller's
|
|
8993
|
+
* hand-built def), so a `Date`, a function, an `undefined` member or a
|
|
8994
|
+
* non-finite number would otherwise be accepted here and surface only as a
|
|
8995
|
+
* broken bind — or a silently-null column — much later, which is the exact
|
|
8996
|
+
* class of bug the write-value work (A9) exists to end.
|
|
8997
|
+
*/
|
|
8998
|
+
declare function json(aid: string): Shape<JsonValue>;
|
|
8999
|
+
/**
|
|
9000
|
+
* Depth cap for {@link isJsonValue}. Deeper than any authored query fragment or
|
|
9001
|
+
* settings document is expected to nest, and shallow enough that a CYCLIC
|
|
9002
|
+
* hand-built object is rejected rather than overflowing the stack (a cycle is
|
|
9003
|
+
* impossible in parsed JSON, but a caller may hand us any object).
|
|
9004
|
+
*/
|
|
9005
|
+
declare const JSON_MAX_DEPTH = 64;
|
|
9006
|
+
/** Whether `value` is a JSON value all the way down (see {@link json}). */
|
|
9007
|
+
declare function isJsonValue(value: unknown, depth: number): value is JsonValue;
|
|
9008
|
+
/**
|
|
9009
|
+
* Membership in `values`. On a miss, emits `expected <label>: a, b, c` plus a
|
|
9010
|
+
* `didYouMean` suggestion (when the input is a near-miss string) → INVALID.
|
|
9011
|
+
*/
|
|
9012
|
+
declare function enumOf<const V extends string>(values: readonly V[], aid: string): Shape<V>;
|
|
9013
|
+
/** Wrap a shape so an absent / `undefined` value is accepted (→ `undefined`). */
|
|
9014
|
+
declare function optional<T>(inner: Shape<T>): Shape<T | undefined>;
|
|
9015
|
+
/**
|
|
9016
|
+
* A homogeneous list. Non-array → aid-directed `shape.array` + INVALID; each
|
|
9017
|
+
* element is checked at `problems.at(i, …)`; `min` / `max` violations record a
|
|
9018
|
+
* problem. Accumulates: every bad element / bound is reported in one pass.
|
|
9019
|
+
*/
|
|
9020
|
+
declare function list<T>(shape: Shape<T>, opts?: {
|
|
9021
|
+
min?: number;
|
|
9022
|
+
max?: number;
|
|
9023
|
+
}): Shape<T[]>;
|
|
9024
|
+
/**
|
|
9025
|
+
* A homogeneous RECORD — an object of `{ [name: string]: value }` (the named
|
|
9026
|
+
* function-argument map). Non-object → aid-directed `shape.not-object` + INVALID;
|
|
9027
|
+
* each value is checked at `problems.at(name, …)`; accumulates (every bad value
|
|
9028
|
+
* is reported in one pass). Returns an insertion-ordered `Map<string, T>`
|
|
9029
|
+
* (mirroring `parseNamedArgs`), so the four function-call exprs keep their args'
|
|
9030
|
+
* declared order.
|
|
9031
|
+
*/
|
|
9032
|
+
declare function record<T>(shape: Shape<T>, aid: string): Shape<Map<string, T>>;
|
|
9033
|
+
/** A child-expr slot: defensively dispatched via `registry.parseCheckedExpr`. */
|
|
9034
|
+
declare function exprRef(): Shape<Expr>;
|
|
9035
|
+
/**
|
|
9036
|
+
* A child-QUERY slot yielding a parsed {@link Query}: defensively dispatched via
|
|
9037
|
+
* `registry.parseCheckedQuery`. Used by the set-operation arms, CTE bindings,
|
|
9038
|
+
* subquery sources, and `INSERT … SELECT` — every position that holds a fully
|
|
9039
|
+
* PARSED sub-query. Records the sub-query's problems (accumulating) and returns
|
|
9040
|
+
* the built `Query` or {@link INVALID}.
|
|
9041
|
+
*/
|
|
9042
|
+
declare function queryRef(): Shape<Query>;
|
|
9043
|
+
/**
|
|
9044
|
+
* A child-QUERY slot kept as a raw {@link QueryDef} (not a parsed `Query`). The
|
|
9045
|
+
* value-position subquery exprs (`subquery` / `exists` / the `in`-subquery form)
|
|
9046
|
+
* store the query's JSON def and re-parse it lazily at eval / emit time, so this
|
|
9047
|
+
* still validates the sub-query STRUCTURALLY through `parseCheckedQuery` (so its
|
|
9048
|
+
* problems accumulate) but returns its normalized `toJSON()` def rather than the
|
|
9049
|
+
* built instance. {@link INVALID} when the sub-query failed to parse.
|
|
9050
|
+
*/
|
|
9051
|
+
declare function queryDefRef(): Shape<QueryDef>;
|
|
9052
|
+
/** A child-SOURCE slot: defensively dispatched via `registry.parseCheckedSource`. */
|
|
9053
|
+
declare function sourceRef(): Shape<QuerySource>;
|
|
9054
|
+
/**
|
|
9055
|
+
* An object shape. `fields` maps each key to the {@link Shape} for its value;
|
|
9056
|
+
* `build` constructs `T` from the fully-typed parsed values `F` (inferred from
|
|
9057
|
+
* the field shapes — see the module header on why the generic is inverted so
|
|
9058
|
+
* NO cast is needed).
|
|
9059
|
+
*
|
|
9060
|
+
* Behavior (never throws, accumulates):
|
|
9061
|
+
* - non-object `json` → aid-directed `shape.not-object` → INVALID;
|
|
9062
|
+
* - EVERY field is checked at `problems.at(key, …)` — a missing non-optional
|
|
9063
|
+
* field records `shape.required`; a field named in `opts.optional` may be
|
|
9064
|
+
* absent — and checking CONTINUES past a bad field so siblings' problems
|
|
9065
|
+
* surface in the same pass;
|
|
9066
|
+
* - if any REQUIRED field is invalid/absent (checked AFTER the siblings) →
|
|
9067
|
+
* INVALID; otherwise `build(values)`.
|
|
9068
|
+
*/
|
|
9069
|
+
declare function obj<F extends Record<string, unknown>, T>(fields: {
|
|
9070
|
+
[K in keyof F]: Shape<F[K]>;
|
|
9071
|
+
}, build: (values: F) => T, opts?: {
|
|
9072
|
+
optional?: readonly (keyof F & string)[];
|
|
9073
|
+
aid?: string;
|
|
9074
|
+
}): Shape<T>;
|
|
9075
|
+
|
|
9076
|
+
/**
|
|
9077
|
+
* Barrel for the owned, zod-free structural-parser combinators. See
|
|
9078
|
+
* `shape.ts` for the design (never throws, accumulates problems, no casts).
|
|
9079
|
+
*/
|
|
9080
|
+
|
|
9081
|
+
type index_CheckCtx = CheckCtx;
|
|
9082
|
+
declare const index_INVALID: typeof INVALID;
|
|
9083
|
+
declare const index_JSON_MAX_DEPTH: typeof JSON_MAX_DEPTH;
|
|
9084
|
+
type index_Shape<T> = Shape<T>;
|
|
9085
|
+
declare const index_bool: typeof bool;
|
|
9086
|
+
declare const index_enumOf: typeof enumOf;
|
|
9087
|
+
declare const index_expected: typeof expected;
|
|
9088
|
+
declare const index_exprRef: typeof exprRef;
|
|
9089
|
+
declare const index_int: typeof int;
|
|
9090
|
+
declare const index_isJsonValue: typeof isJsonValue;
|
|
9091
|
+
declare const index_isRecord: typeof isRecord;
|
|
9092
|
+
declare const index_json: typeof json;
|
|
9093
|
+
declare const index_list: typeof list;
|
|
9094
|
+
declare const index_num: typeof num;
|
|
9095
|
+
declare const index_obj: typeof obj;
|
|
9096
|
+
declare const index_optional: typeof optional;
|
|
9097
|
+
declare const index_queryDefRef: typeof queryDefRef;
|
|
9098
|
+
declare const index_queryRef: typeof queryRef;
|
|
9099
|
+
declare const index_record: typeof record;
|
|
9100
|
+
declare const index_scalar: typeof scalar;
|
|
9101
|
+
declare const index_sourceRef: typeof sourceRef;
|
|
9102
|
+
declare const index_str: typeof str;
|
|
9103
|
+
declare namespace index {
|
|
9104
|
+
export { type index_CheckCtx as CheckCtx, index_INVALID as INVALID, index_JSON_MAX_DEPTH as JSON_MAX_DEPTH, type index_Shape as Shape, index_bool as bool, index_enumOf as enumOf, index_expected as expected, index_exprRef as exprRef, index_int as int, index_isJsonValue as isJsonValue, index_isRecord as isRecord, index_json as json, index_list as list, lit$1 as lit, index_num as num, index_obj as obj, index_optional as optional, index_queryDefRef as queryDefRef, index_queryRef as queryRef, index_record as record, index_scalar as scalar, index_sourceRef as sourceRef, index_str as str };
|
|
9105
|
+
}
|
|
6872
9106
|
|
|
6873
9107
|
/**
|
|
6874
9108
|
* Structured code representation with spans tying every rendered range
|
|
@@ -7449,6 +9683,112 @@ declare class Registry {
|
|
|
7449
9683
|
fieldTypeClass(kind: string): FieldTypeClass | undefined;
|
|
7450
9684
|
/** Enumerate every registered FieldType class (for schema builders). */
|
|
7451
9685
|
fieldTypeClassList(): FieldTypeClass[];
|
|
9686
|
+
/**
|
|
9687
|
+
* Every registered field-type KIND, in registration order — the builtin
|
|
9688
|
+
* vocabulary a `FieldTypeDef.kind` may name in THIS registry.
|
|
9689
|
+
*
|
|
9690
|
+
* Exported because "which kinds exist" was previously only answerable by
|
|
9691
|
+
* reaching for the `BUILTIN_FIELD_TYPES` array, i.e. by asking the package
|
|
9692
|
+
* rather than the registry — which is wrong the moment a deployment builds a
|
|
9693
|
+
* registry that is not `createRegistry()`.
|
|
9694
|
+
*/
|
|
9695
|
+
fieldTypeKinds(): FieldTypeKind[];
|
|
9696
|
+
/** Registered refinements by name (see `refinement.ts`). */
|
|
9697
|
+
private readonly fieldTypeRefinements;
|
|
9698
|
+
/**
|
|
9699
|
+
* Register a field-type REFINEMENT — a name over a builtin base, carrying its
|
|
9700
|
+
* narrowed options, its model-facing `instructions`, its per-dialect SQL type
|
|
9701
|
+
* and cast, and an optional stricter value gate.
|
|
9702
|
+
*
|
|
9703
|
+
* Every check the declaration is held to runs HERE and throws a
|
|
9704
|
+
* `QueryTypeError` (`field-type.bad-refinement`) — see
|
|
9705
|
+
* `FieldTypeRefinement.compile`. A refinement that registered half-broken
|
|
9706
|
+
* would be wrong on every column that ever named it, so nothing is warned and
|
|
9707
|
+
* deferred.
|
|
9708
|
+
*
|
|
9709
|
+
* ORDERING MATTERS: a stored `{kind:'text', as:'uuid'}` parses against the
|
|
9710
|
+
* registry it is handed, so every refinement a catalog names must be
|
|
9711
|
+
* registered BEFORE `parseType` runs over it (an unknown name is refused,
|
|
9712
|
+
* loudly, rather than silently degrading to the bare base).
|
|
9713
|
+
*/
|
|
9714
|
+
registerFieldType(def: FieldTypeRefinementDef): this;
|
|
9715
|
+
/**
|
|
9716
|
+
* SYMMETRIZE the new refinement's declared `comparableWith` against everything
|
|
9717
|
+
* already registered — every edge either side names is recorded on BOTH ends.
|
|
9718
|
+
*
|
|
9719
|
+
* Commutativity of comparability is then STRUCTURAL rather than the declarer's
|
|
9720
|
+
* discipline: `a.comparableWith(b)` and `b.comparableWith(a)` cannot disagree,
|
|
9721
|
+
* because there is no direction stored to disagree about. Which also means an
|
|
9722
|
+
* edge may name a type that is not registered yet — unavoidable for a mutual
|
|
9723
|
+
* pair, since one of the two has to be declared first, and the reason this
|
|
9724
|
+
* runs on EVERY registration rather than only resolving the new one's list.
|
|
9725
|
+
*
|
|
9726
|
+
* A one-sided declaration is honoured and NOTED (`warn`) rather than refused.
|
|
9727
|
+
* Refusing would make a mutual pair the only legal spelling and force both
|
|
9728
|
+
* declarers to know about each other, which is exactly the coupling a
|
|
9729
|
+
* registry-level relation removes; and dropping it would silently discard the
|
|
9730
|
+
* fact one of them stated. The note is the honest middle, and
|
|
9731
|
+
* {@link fieldTypeComparabilityNotes} is where a consumer reads it.
|
|
9732
|
+
*/
|
|
9733
|
+
private linkComparability;
|
|
9734
|
+
/** One-sided `comparableWith` declarations the registry symmetrized (see {@link linkComparability}). */
|
|
9735
|
+
private readonly comparabilityNotes;
|
|
9736
|
+
/**
|
|
9737
|
+
* The `warn`-grade notes {@link registerFieldType} filed while symmetrizing
|
|
9738
|
+
* declared comparability. Empty for a registry whose declarations all name
|
|
9739
|
+
* each other (or name nothing).
|
|
9740
|
+
*/
|
|
9741
|
+
fieldTypeComparabilityNotes(): readonly Problem[];
|
|
9742
|
+
/**
|
|
9743
|
+
* Register the CODE half of a refinement — a stricter value gate and the
|
|
9744
|
+
* in-memory ordering. The counterpart of `registerFunctionRun` beside
|
|
9745
|
+
* `registerFunction`, and split from the declaration for the reason
|
|
9746
|
+
* {@link FieldTypeImpl} gives: a declaration is PERSISTED, and neither a zod
|
|
9747
|
+
* schema nor a closure survives that round-trip honestly.
|
|
9748
|
+
*
|
|
9749
|
+
* The impl attaches to the compiled refinement, which every column naming it
|
|
9750
|
+
* SHARES — so it has to be registered before those columns are parsed, exactly
|
|
9751
|
+
* as the declaration does.
|
|
9752
|
+
*/
|
|
9753
|
+
registerFieldTypeImpl(name: string, impl: FieldTypeImpl): this;
|
|
9754
|
+
/**
|
|
9755
|
+
* Set once this registry has built a FIELD TYPE — through `parseFieldType`,
|
|
9756
|
+
* and so through `parseType` / `registerType` / `Type.from` / a function's
|
|
9757
|
+
* declared parameter types, all of which route there. Registration of a
|
|
9758
|
+
* refinement (or its impl) is refused past that point; see
|
|
9759
|
+
* {@link refuseLateRegistration}.
|
|
9760
|
+
*/
|
|
9761
|
+
private catalogBuilt;
|
|
9762
|
+
/**
|
|
9763
|
+
* Refuse a refinement registration once this registry has built a field type.
|
|
9764
|
+
*
|
|
9765
|
+
* A stored `{kind:'text', as:'uuid'}` resolves against whatever the registry
|
|
9766
|
+
* knew AT PARSE TIME, and the resolved column is what every later predicate
|
|
9767
|
+
* uses. So a system that registers `uuid` after the catalog crawl leaves every
|
|
9768
|
+
* already-parsed column carrying the un-narrowed base — the `LOWER()` this
|
|
9769
|
+
* feature exists to remove — while the type tag still reads `text` and no
|
|
9770
|
+
* error is raised anywhere. A late IMPL is worse still: it attaches to the
|
|
9771
|
+
* compiled refinement every column naming it SHARES, so it retroactively
|
|
9772
|
+
* changes what an already-handed-out column validates against, mid-process.
|
|
9773
|
+
* That is the one failure in this design that is SILENT, which is why ordering
|
|
9774
|
+
* is enforced rather than documented.
|
|
9775
|
+
*
|
|
9776
|
+
* Armed at the field-type parse rather than at `parseType`, because
|
|
9777
|
+
* `parseType` is not the only road to a refined instance — `parseFieldType` is
|
|
9778
|
+
* public, `Type.from` is on the package barrel, and a function's declared
|
|
9779
|
+
* parameter types parse through the same place.
|
|
9780
|
+
*/
|
|
9781
|
+
private refuseLateRegistration;
|
|
9782
|
+
/** Look up a registered field-type refinement by name, or `undefined`. */
|
|
9783
|
+
fieldTypeRefinement(name: string): FieldTypeRefinement | undefined;
|
|
9784
|
+
/** Enumerate every registered field-type refinement (for docs / describe). */
|
|
9785
|
+
fieldTypeRefinementList(): FieldTypeRefinement[];
|
|
9786
|
+
/**
|
|
9787
|
+
* The registered refinement NAMES — the closed vocabulary a `FieldTypeDef.as`
|
|
9788
|
+
* may name. This is what the generated def schema renders as a `z.enum`, and
|
|
9789
|
+
* therefore what stops a model inventing `{kind:'text', as:'uuid4'}`.
|
|
9790
|
+
*/
|
|
9791
|
+
fieldTypeRefinementNames(): string[];
|
|
7452
9792
|
/** Registry-level default average bytes per field-type kind (a `Field` with no explicit `bytes` falls back here). */
|
|
7453
9793
|
private readonly defaultFieldTypeBytes;
|
|
7454
9794
|
/**
|
|
@@ -7460,8 +9800,32 @@ declare class Registry {
|
|
|
7460
9800
|
setDefaultFieldBytes(kind: string, bytes: number): this;
|
|
7461
9801
|
/** The configured default bytes for a field-type kind, or `undefined` when unset. */
|
|
7462
9802
|
defaultFieldBytes(kind: string): number | undefined;
|
|
7463
|
-
/**
|
|
9803
|
+
/**
|
|
9804
|
+
* Parse a `FieldTypeDef` into a `FieldType` instance by dispatching on kind,
|
|
9805
|
+
* then applying any `as` REFINEMENT it names.
|
|
9806
|
+
*
|
|
9807
|
+
* A refinement is applied by MEETING the declaration's options with the site's
|
|
9808
|
+
* own, so a use site may narrow it further and a site that contradicts it is
|
|
9809
|
+
* refused (`field-type.refinement-conflict`) — see `FieldTypeRefinement.refine`.
|
|
9810
|
+
* An `as` naming nothing registered is likewise refused rather than dropped:
|
|
9811
|
+
* silently degrading to the bare base would take a `uuid` column's
|
|
9812
|
+
* `casing: 'exact'` with it and put an index-defeating `LOWER()` back on every
|
|
9813
|
+
* predicate over it.
|
|
9814
|
+
*/
|
|
7464
9815
|
parseFieldType(json: FieldTypeDef): FieldType;
|
|
9816
|
+
/**
|
|
9817
|
+
* {@link parseFieldType} WITHOUT freezing the vocabulary — the road
|
|
9818
|
+
* `FieldTypeRefinement.compile` takes to build a declaration's own options.
|
|
9819
|
+
*
|
|
9820
|
+
* The exemption is necessary and narrow: compiling the FIRST refinement would
|
|
9821
|
+
* otherwise freeze the registry and refuse the second. It SAVES AND RESTORES
|
|
9822
|
+
* the flag rather than bypassing the public method, because a composite option
|
|
9823
|
+
* recurses through `parseFieldType` for its element (`ArrayFieldType.from`) and
|
|
9824
|
+
* a bypass would only exempt the top level.
|
|
9825
|
+
*/
|
|
9826
|
+
private parseFieldTypeUnflagged;
|
|
9827
|
+
/** The parse itself, with no opinion about freezing (see the two callers above). */
|
|
9828
|
+
private parseFieldTypeInternal;
|
|
7465
9829
|
/**
|
|
7466
9830
|
* Register a named Type instance for lookup + reference resolution, optionally
|
|
7467
9831
|
* with its DEV-SIDE `TypeBacking` (computed fields, RLS/FLS, a real source
|
|
@@ -7492,7 +9856,13 @@ declare class Registry {
|
|
|
7492
9856
|
type(name: string): Type | undefined;
|
|
7493
9857
|
/** Enumerate every registered named Type. */
|
|
7494
9858
|
typeList(): Type[];
|
|
7495
|
-
/**
|
|
9859
|
+
/**
|
|
9860
|
+
* Parse a `TypeDef` into a `Type` instance (does NOT auto-register).
|
|
9861
|
+
*
|
|
9862
|
+
* This FREEZES the refinement vocabulary: the field types it builds resolved
|
|
9863
|
+
* their `as` against the registry as it stands now, so a refinement
|
|
9864
|
+
* registered afterwards could not reach them (see `refuseLateRegistration`).
|
|
9865
|
+
*/
|
|
7496
9866
|
parseType(json: TypeDef): Type;
|
|
7497
9867
|
/**
|
|
7498
9868
|
* Register a function definition (scalar / aggregate / window / tabular) for
|
|
@@ -7500,6 +9870,12 @@ declare class Registry {
|
|
|
7500
9870
|
* (`^[A-Za-z_][A-Za-z0-9_.]*$`); the dialects raw-interpolate `${name}(` when
|
|
7501
9871
|
* emitting calls, so a non-identifier name is rejected here to guarantee the
|
|
7502
9872
|
* generated SQL can never contain an unescaped arbitrary string.
|
|
9873
|
+
*
|
|
9874
|
+
* `sql` — the emitted name when it differs (`log10` → `log`) — is held to the
|
|
9875
|
+
* SAME pattern, because it is interpolated through the SAME raw slot: the four
|
|
9876
|
+
* call-shaped exprs emit `${fn.sql ?? fn.name}(`. Checking only `name` left
|
|
9877
|
+
* the guarantee reachable around, through a field whose whole purpose is to
|
|
9878
|
+
* replace the checked one.
|
|
7503
9879
|
*/
|
|
7504
9880
|
registerFunction(fn: FunctionDef): this;
|
|
7505
9881
|
/** Look up a registered function definition by name, or `undefined`. */
|
|
@@ -7514,6 +9890,51 @@ declare class Registry {
|
|
|
7514
9890
|
registerFunctionRun(name: string, run: FunctionRun): this;
|
|
7515
9891
|
/** Look up a function's runtime implementation, if any. */
|
|
7516
9892
|
functionRun(name: string): FunctionRun | undefined;
|
|
9893
|
+
/** Registered operators by name, COMPILED (see `operator.ts`). */
|
|
9894
|
+
private readonly operators;
|
|
9895
|
+
/** Runtime implementations of registered operators. */
|
|
9896
|
+
private readonly operatorRuns;
|
|
9897
|
+
/**
|
|
9898
|
+
* Register an OPERATOR — a name whose SQL a declaration supplies, per dialect
|
|
9899
|
+
* (`{ postgres: '({left} && {right})' }`).
|
|
9900
|
+
*
|
|
9901
|
+
* Every check the declaration is held to runs HERE and throws a
|
|
9902
|
+
* `QueryTypeError` (`operator.bad-declaration`) — see `QueryOperator.compile`.
|
|
9903
|
+
* COMPILED EAGERLY, unlike a `FunctionDef`, which the engine parses lazily on
|
|
9904
|
+
* first call: a defect in an emit template has no meaning at a call site, and
|
|
9905
|
+
* a failure there has no declaration to attribute it to.
|
|
9906
|
+
*
|
|
9907
|
+
* ORDERING: an operand naming a field-type refinement (`{kind:'json',
|
|
9908
|
+
* as:'Geometry'}`) needs that refinement registered FIRST, and says so with
|
|
9909
|
+
* `field-type.unknown-refinement`. Registering an operator does NOT freeze the
|
|
9910
|
+
* refinement vocabulary, so the reverse order stays open — the operand types
|
|
9911
|
+
* parse through the unflagged road for exactly that reason.
|
|
9912
|
+
*/
|
|
9913
|
+
registerOperator(def: OperatorDef): this;
|
|
9914
|
+
/** Look up a registered operator by name, or `undefined`. */
|
|
9915
|
+
operator(name: string): QueryOperator | undefined;
|
|
9916
|
+
/** Enumerate every registered operator (for docs / describe / schema generation). */
|
|
9917
|
+
operatorList(): QueryOperator[];
|
|
9918
|
+
/**
|
|
9919
|
+
* The registered operator NAMES — the closed vocabulary an `OperatorExprDef.op`
|
|
9920
|
+
* may name in THIS registry. What the generated schema renders as a `z.enum`,
|
|
9921
|
+
* and therefore what stops a model inventing an operator that does not exist.
|
|
9922
|
+
*/
|
|
9923
|
+
operatorNames(): string[];
|
|
9924
|
+
/**
|
|
9925
|
+
* Register an operator's IN-MEMORY implementation — the counterpart of
|
|
9926
|
+
* `registerFunctionRun`, and the code half of a declaration that is otherwise
|
|
9927
|
+
* pure JSON.
|
|
9928
|
+
*
|
|
9929
|
+
* The DECLARATION must already be registered. A run for an unknown operator is
|
|
9930
|
+
* refused rather than stored against a name nothing dispatches, because the
|
|
9931
|
+
* failure is otherwise perfectly silent: `engine.run` would answer NULL for
|
|
9932
|
+
* every row and the SQL road would keep working, so the typo would surface as
|
|
9933
|
+
* a data defect rather than as an error.
|
|
9934
|
+
*/
|
|
9935
|
+
registerOperatorRun(name: string, run: OperatorRun): this;
|
|
9936
|
+
/** Look up an operator's runtime implementation, if any. */
|
|
9937
|
+
operatorRun(name: string): OperatorRun | undefined;
|
|
7517
9938
|
/** Register an Expr class so `parseExpr` can dispatch JSON by `kind`. */
|
|
7518
9939
|
defineExpr(cls: ExprClass): this;
|
|
7519
9940
|
/** Look up the Expr class for a given kind. */
|
|
@@ -7928,6 +10349,20 @@ declare function nearest(input: string, candidates: readonly string[], budget?:
|
|
|
7928
10349
|
*
|
|
7929
10350
|
* p.error('ref.unknown-field',
|
|
7930
10351
|
* `Type '${t.name}' has no field '${bad}'.${didYouMean(bad, t.fields.map(f => f.name))}`);
|
|
10352
|
+
*
|
|
10353
|
+
* TOTAL FOR A NON-STRING `input`, even though the signature says `string`, and
|
|
10354
|
+
* that guard is load-bearing rather than defensive noise. This composes a
|
|
10355
|
+
* DIAGNOSTIC, and every caller is on the road whose whole contract is that a
|
|
10356
|
+
* defect is REPORTED rather than raised — but the value it is handed is by
|
|
10357
|
+
* definition an unchecked one (that is what "unknown name" means). Measured:
|
|
10358
|
+
* `validateQuery` over `{kind:'text-search', query:'x'}` with no `source` reached
|
|
10359
|
+
* `exprs/text-search.ts`'s unknown-source diagnostic, which read `input.length`
|
|
10360
|
+
* for the edit budget and threw a raw `TypeError` out of this module — turning a
|
|
10361
|
+
* reportable problem into an uncaught crash. The DEFENSIVE parser
|
|
10362
|
+
* (`parseCheckedQuery`) refuses that def first, so the crash was reachable only
|
|
10363
|
+
* on the unchecked `validateQuery` road; the fix belongs here rather than at the
|
|
10364
|
+
* one call site that happened to trip it, because every other unknown-NAME
|
|
10365
|
+
* diagnostic in the package reads the same kind of value.
|
|
7931
10366
|
*/
|
|
7932
10367
|
declare function didYouMean(input: string, candidates: readonly string[], opts?: {
|
|
7933
10368
|
max?: number;
|
|
@@ -7993,24 +10428,63 @@ declare class NumberFieldType extends FieldType {
|
|
|
7993
10428
|
constructor(
|
|
7994
10429
|
/** Bounds / integer / decimal-place constraints for this number. */
|
|
7995
10430
|
options?: NumberOptions);
|
|
7996
|
-
/**
|
|
10431
|
+
/**
|
|
10432
|
+
* Reconstruct from a JSON def. Throws a `QueryTypeError` on a kind mismatch,
|
|
10433
|
+
* and on a closed set holding a member this type's own bounds / integrality
|
|
10434
|
+
* reject — including a TEXT member, which is how a mixed-scalar set that
|
|
10435
|
+
* bypassed the def schema is caught on the parse road.
|
|
10436
|
+
*/
|
|
7997
10437
|
static from(json: FieldTypeDef): NumberFieldType;
|
|
7998
10438
|
/** The Zod schema for this field type's JSON def. */
|
|
7999
|
-
static toSchema(): z.ZodTypeAny;
|
|
10439
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
8000
10440
|
/** Resolve to the `number` scalar comparison category. */
|
|
8001
10441
|
resolve(): ScalarKind;
|
|
8002
|
-
/**
|
|
8003
|
-
|
|
10442
|
+
/** The closed set this number may hold, when one is declared (drives `eqSelectivity`, membership, the meet). */
|
|
10443
|
+
values(): readonly FieldValueDef[] | undefined;
|
|
10444
|
+
/**
|
|
10445
|
+
* A WHOLE number is a legal type for a refinement option a `sql` / `cast`
|
|
10446
|
+
* template interpolates (see {@link FieldType.tokenSafeValues}) — it is the
|
|
10447
|
+
* `number` half of the closed-type rule, and it is what makes
|
|
10448
|
+
* `{ kind:'number', whole:true }` a spellable type for an `srid`.
|
|
10449
|
+
*
|
|
10450
|
+
* ALMOST every value it admits is a bare token, and the residue is why the
|
|
10451
|
+
* template mechanism does not rest on this check alone: `String(-4)` is `-4`
|
|
10452
|
+
* and `String(1e21)` is `1e+21`, neither of which is one. Those are refused
|
|
10453
|
+
* PER VALUE where the column is parsed (`FieldTypeRefinement.refine`), so the
|
|
10454
|
+
* pair is total; declaring a closed `values` set (or `min: 0` and a `max`)
|
|
10455
|
+
* moves that refusal onto the TYPE, where the message is better.
|
|
10456
|
+
*
|
|
10457
|
+
* A DECLARED CLOSED SET WINS OUTRIGHT, and `whole` is only the fallback for a
|
|
10458
|
+
* type that declares none. Written as `||` first, which let `whole: true`
|
|
10459
|
+
* short-circuit past a set the base was about to inspect — so
|
|
10460
|
+
* `{whole: true, values: [{value: -1}, {value: 5}]}` registered cleanly and
|
|
10461
|
+
* then refused every column writing `-1`, a DECLARED, LEGAL member of the
|
|
10462
|
+
* type's own set. That is the exact failure a `relation` base is refused for
|
|
10463
|
+
* ("registered cleanly and then refused every column that used it, blaming the
|
|
10464
|
+
* column"), and the information to refuse it at the declaration was already in
|
|
10465
|
+
* hand.
|
|
10466
|
+
*/
|
|
10467
|
+
tokenSafeValues(): boolean;
|
|
10468
|
+
/**
|
|
10469
|
+
* Meet with another `number` (bounds / integrality / closed set reconciled by
|
|
10470
|
+
* {@link meetNumberOptions}), or with `money` — which is the more specific of
|
|
10471
|
+
* the pair `comparableWith` calls mutually numeric, so it answers for both.
|
|
10472
|
+
*/
|
|
10473
|
+
protected meetWith(other: FieldType): FieldType | undefined;
|
|
8004
10474
|
/** Estimated average stored byte size. */
|
|
8005
|
-
|
|
10475
|
+
protected builtinAvgBytes(): number;
|
|
8006
10476
|
/** SQL column type (`integer` when whole, else `numeric`). */
|
|
8007
10477
|
toSQLType(): string;
|
|
8008
10478
|
/** Zod schema validating a number value, honoring the options. */
|
|
8009
|
-
|
|
10479
|
+
protected builtinValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
8010
10480
|
/** Serialize to its JSON def (flattening the compacted options). */
|
|
10481
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
8011
10482
|
toJSON(): NumberFieldTypeDef;
|
|
10483
|
+
protected builtinJSON(): NumberFieldTypeDef;
|
|
8012
10484
|
/** A copy of this field type (deep-cloning the options bag's value set). */
|
|
10485
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
8013
10486
|
clone(): NumberFieldType;
|
|
10487
|
+
protected builtinClone(): NumberFieldType;
|
|
8014
10488
|
}
|
|
8015
10489
|
|
|
8016
10490
|
/** Options bag for a text field type (instance-side). */
|
|
@@ -8019,27 +10493,53 @@ interface TextOptions {
|
|
|
8019
10493
|
minLength?: number;
|
|
8020
10494
|
/** Maximum string length. */
|
|
8021
10495
|
maxLength?: number;
|
|
8022
|
-
/**
|
|
10496
|
+
/**
|
|
10497
|
+
* Format regex the value must match. Validated by {@link TextFieldType.from},
|
|
10498
|
+
* which is the road every in-package parse takes (a Type's fields, a nested
|
|
10499
|
+
* `array` item, a function parameter) — so a type built from a DEF cannot
|
|
10500
|
+
* carry an uncompilable one. The CONSTRUCTOR does not validate, so a
|
|
10501
|
+
* hand-built `new TextFieldType({ pattern: '([' })` still can, and will throw
|
|
10502
|
+
* a `SyntaxError` at whichever use compiles it first. Same caveat as every
|
|
10503
|
+
* other option supplied by hand rather than parsed.
|
|
10504
|
+
*/
|
|
8023
10505
|
pattern?: string;
|
|
8024
10506
|
/** Eligible for embedding-based semantic similarity. */
|
|
8025
10507
|
semantic?: boolean;
|
|
8026
10508
|
/** Eligible for full-text search. */
|
|
8027
10509
|
search?: boolean;
|
|
8028
|
-
/**
|
|
8029
|
-
|
|
10510
|
+
/**
|
|
10511
|
+
* How textual matching on this field treats letter case — and, when it is
|
|
10512
|
+
* insensitive, WHO folds (see {@link TextCasing}). Absent ⇒ the engine's
|
|
10513
|
+
* `textCasing` default; present, it is authoritative over that default.
|
|
10514
|
+
*
|
|
10515
|
+
* `'collated'` is a claim about the PHYSICAL column (a `citext`, a
|
|
10516
|
+
* non-deterministic collation, a case-insensitive server default) that this
|
|
10517
|
+
* package cannot verify — declare it only where the store really does fold.
|
|
10518
|
+
*/
|
|
10519
|
+
casing?: TextCasing;
|
|
8030
10520
|
/** The closed set of values this column may hold (see `NumberOptions.values`). */
|
|
8031
10521
|
values?: FieldValueDef[];
|
|
8032
10522
|
}
|
|
8033
10523
|
/**
|
|
8034
10524
|
* TextFieldType — a string field with optional length / pattern constraints,
|
|
8035
|
-
* semantic-search / full-text flags, and a `
|
|
8036
|
-
*
|
|
8037
|
-
*
|
|
8038
|
-
*
|
|
8039
|
-
*
|
|
8040
|
-
*
|
|
8041
|
-
*
|
|
8042
|
-
*
|
|
10525
|
+
* semantic-search / full-text flags, and a `casing` policy.
|
|
10526
|
+
*
|
|
10527
|
+
* CASING RULE (important). The casing in effect for this field is its own
|
|
10528
|
+
* `casing` when it declares one, and otherwise the engine's `textCasing`
|
|
10529
|
+
* default — which ships as `'fold'`, i.e. textual matching is CASE-INSENSITIVE
|
|
10530
|
+
* unless a field or the deployment says otherwise. What that governs, exactly:
|
|
10531
|
+
* the scalar comparison operators (`= <> < <= > >=`), `like` / `notLike`,
|
|
10532
|
+
* `array-op` element containment, and whether a full-text `search` / `score`
|
|
10533
|
+
* degrades to an exact-case `LIKE`. `ilike` is case-insensitive by definition
|
|
10534
|
+
* and consults no casing.
|
|
10535
|
+
*
|
|
10536
|
+
* What it does NOT govern, because those roads have never case-folded on either
|
|
10537
|
+
* side (runtime or SQL): `in`, `between`, `order` / `distinct` / `group by`,
|
|
10538
|
+
* relation identity comparison, and the text scalar FUNCTIONS (`startsWith`,
|
|
10539
|
+
* `indexOf`, `replace`, `arrayContains`, which compare as-is and map onto the
|
|
10540
|
+
* database's own exact-matching builtins). Their behaviour is unchanged and is
|
|
10541
|
+
* the same in both roads; it is simply not part of what this option turns off.
|
|
10542
|
+
* `lower(...)` / `upper(...)` remain the explicit way to fold inside a function.
|
|
8043
10543
|
*/
|
|
8044
10544
|
declare class TextFieldType extends FieldType {
|
|
8045
10545
|
/** Length / pattern / search / sensitivity options for this string. */
|
|
@@ -8051,26 +10551,62 @@ declare class TextFieldType extends FieldType {
|
|
|
8051
10551
|
constructor(
|
|
8052
10552
|
/** Length / pattern / search / sensitivity options for this string. */
|
|
8053
10553
|
options?: TextOptions);
|
|
8054
|
-
/**
|
|
8055
|
-
|
|
8056
|
-
/**
|
|
10554
|
+
/** This field's DECLARED casing, or `undefined` to inherit the engine's default. */
|
|
10555
|
+
textCasing(): TextCasing | undefined;
|
|
10556
|
+
/**
|
|
10557
|
+
* Reconstruct from a JSON def. Throws a `QueryTypeError` on a kind mismatch,
|
|
10558
|
+
* on an uncompilable `pattern`, on a closed set holding a member this type's
|
|
10559
|
+
* own length / pattern constraints reject, and on the retired `sensitive`
|
|
10560
|
+
* key — all four are defects in the DECLARATION, and this is the road every
|
|
10561
|
+
* in-package parse takes.
|
|
10562
|
+
*/
|
|
8057
10563
|
static from(json: FieldTypeDef): TextFieldType;
|
|
8058
10564
|
/** The Zod schema for this field type's JSON def. */
|
|
8059
|
-
static toSchema(): z.ZodTypeAny;
|
|
10565
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
8060
10566
|
/** Resolve to the `text` scalar comparison category. */
|
|
8061
10567
|
resolve(): ScalarKind;
|
|
8062
|
-
/**
|
|
8063
|
-
|
|
10568
|
+
/** The closed set this string may hold, when one is declared (drives `eqSelectivity`, membership, the meet). */
|
|
10569
|
+
values(): readonly FieldValueDef[] | undefined;
|
|
10570
|
+
/**
|
|
10571
|
+
* Full-text search eligibility — the declared `search` flag, and the ONE
|
|
10572
|
+
* reader of it (see `FieldType.isSearchable`). A REFINEMENT declaring
|
|
10573
|
+
* `options: { search: true }` arrives here through the ordinary options meet,
|
|
10574
|
+
* so it needs no separate declaration surface.
|
|
10575
|
+
*/
|
|
10576
|
+
isSearchable(): boolean;
|
|
10577
|
+
/**
|
|
10578
|
+
* Semantic (embedding) eligibility — `semantic`, OR `search`, whose index is
|
|
10579
|
+
* the same kind of derived artifact. The two flags stay separately DECLARED
|
|
10580
|
+
* (and separately rendered in the model-facing tag, `text(search,semantic)`);
|
|
10581
|
+
* this is the derived capability every gate asks about.
|
|
10582
|
+
*/
|
|
10583
|
+
isSemantic(): boolean;
|
|
10584
|
+
/**
|
|
10585
|
+
* Meet with another `text`: bounds tighten, a `pattern` must AGREE (there is
|
|
10586
|
+
* no regex that is the intersection of two others, so two different formats
|
|
10587
|
+
* are a genuine conflict), flags OR, the CASING takes the stricter of the two
|
|
10588
|
+
* (`casingRank` — the same precedence a comparison between two differently
|
|
10589
|
+
* cased columns uses, so a param's inferred type and the comparison it was
|
|
10590
|
+
* inferred from can never disagree), and the closed sets intersect. The merged
|
|
10591
|
+
* SET is then narrowed by the merged CONSTRAINTS — the two can arrive from
|
|
10592
|
+
* different uses, and a closed set is the value schema, so a member that
|
|
10593
|
+
* cannot satisfy the merged length/pattern would otherwise be accepted.
|
|
10594
|
+
*/
|
|
10595
|
+
protected meetWith(other: FieldType): FieldType | undefined;
|
|
8064
10596
|
/** Estimated average stored byte size (half the max length, else 32). */
|
|
8065
|
-
|
|
10597
|
+
protected builtinAvgBytes(): number;
|
|
8066
10598
|
/** SQL column type (`varchar(n)` when bounded, else `text`). */
|
|
8067
10599
|
toSQLType(): string;
|
|
8068
10600
|
/** Zod schema validating a string, honoring the closed value set else length / pattern options. */
|
|
8069
|
-
|
|
10601
|
+
protected builtinValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
8070
10602
|
/** Serialize to its JSON def (flattening the compacted options). */
|
|
10603
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
8071
10604
|
toJSON(): TextFieldTypeDef;
|
|
10605
|
+
protected builtinJSON(): TextFieldTypeDef;
|
|
8072
10606
|
/** A copy of this field type (deep-cloning the options bag's value set). */
|
|
10607
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
8073
10608
|
clone(): TextFieldType;
|
|
10609
|
+
protected builtinClone(): TextFieldType;
|
|
8074
10610
|
}
|
|
8075
10611
|
|
|
8076
10612
|
/** Instance-side options for a money field type. */
|
|
@@ -8095,22 +10631,46 @@ declare class MoneyFieldType extends FieldType {
|
|
|
8095
10631
|
constructor(
|
|
8096
10632
|
/** Numeric + currency options for this monetary field. */
|
|
8097
10633
|
options?: MoneyOptions);
|
|
8098
|
-
/**
|
|
10634
|
+
/**
|
|
10635
|
+
* Reconstruct from a JSON def. Throws a `QueryTypeError` on a kind mismatch,
|
|
10636
|
+
* and on an AMOUNT whose closed set holds a member its own bounds reject —
|
|
10637
|
+
* reported at `number.values`, which is where a money def actually declares
|
|
10638
|
+
* one.
|
|
10639
|
+
*/
|
|
8099
10640
|
static from(json: FieldTypeDef): MoneyFieldType;
|
|
8100
10641
|
/** The Zod schema for this field type's JSON def. */
|
|
8101
|
-
static toSchema(): z.ZodTypeAny;
|
|
10642
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
8102
10643
|
/** Resolve to the `money` scalar comparison category. */
|
|
8103
10644
|
resolve(): ScalarKind;
|
|
10645
|
+
/**
|
|
10646
|
+
* The closed set the AMOUNT may hold, read through the inner numeric bag. It
|
|
10647
|
+
* is the same declaration a `number` column makes, so it drives the same
|
|
10648
|
+
* `eqSelectivity` / membership / meet behaviour — before this accessor existed
|
|
10649
|
+
* a `money` column with a declared value set costed `= x` at the fixed guess,
|
|
10650
|
+
* because the two classes that carried a set each answered for themselves.
|
|
10651
|
+
*/
|
|
10652
|
+
values(): readonly FieldValueDef[] | undefined;
|
|
10653
|
+
/**
|
|
10654
|
+
* Meet with `money` (currencies must AGREE — there is no amount that is both
|
|
10655
|
+
* USD and EUR) or with `number`, which constrains only the amount. `money` is
|
|
10656
|
+
* the more specific side of the numeric family, so it answers for both
|
|
10657
|
+
* directions (see `NumberFieldType.meetWith`).
|
|
10658
|
+
*/
|
|
10659
|
+
protected meetWith(other: FieldType): FieldType | undefined;
|
|
8104
10660
|
/** Estimated average stored byte size. */
|
|
8105
|
-
|
|
10661
|
+
protected builtinAvgBytes(): number;
|
|
8106
10662
|
/** SQL column type for a monetary amount. */
|
|
8107
10663
|
toSQLType(): string;
|
|
8108
10664
|
/** Zod schema validating the amount, honoring the inner number options. */
|
|
8109
|
-
|
|
10665
|
+
protected builtinValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
8110
10666
|
/** Serialize to its JSON def (flattening the compacted options). */
|
|
10667
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
8111
10668
|
toJSON(): MoneyFieldTypeDef;
|
|
10669
|
+
protected builtinJSON(): MoneyFieldTypeDef;
|
|
8112
10670
|
/** A copy of this field type (cloning the options bag). */
|
|
10671
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
8113
10672
|
clone(): MoneyFieldType;
|
|
10673
|
+
protected builtinClone(): MoneyFieldType;
|
|
8114
10674
|
}
|
|
8115
10675
|
|
|
8116
10676
|
/** BoolFieldType — a boolean field. Carries no options. */
|
|
@@ -8122,19 +10682,30 @@ declare class BoolFieldType extends FieldType {
|
|
|
8122
10682
|
/** Reconstruct from a JSON def (throws on a kind mismatch). */
|
|
8123
10683
|
static from(json: FieldTypeDef): BoolFieldType;
|
|
8124
10684
|
/** The Zod schema for this field type's JSON def. */
|
|
8125
|
-
static toSchema(): z.ZodTypeAny;
|
|
10685
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
8126
10686
|
/** Resolve to the `bool` scalar comparison category. */
|
|
8127
10687
|
resolve(): ScalarKind;
|
|
10688
|
+
/**
|
|
10689
|
+
* A bool admits exactly `true` and `false`, so every value it can hold is
|
|
10690
|
+
* already a bare SQL token — which makes it a legal type for a refinement
|
|
10691
|
+
* option a `sql` / `cast` template interpolates (see
|
|
10692
|
+
* {@link FieldType.tokenSafeValues}).
|
|
10693
|
+
*/
|
|
10694
|
+
tokenSafeValues(): boolean;
|
|
8128
10695
|
/** Estimated average stored byte size. */
|
|
8129
|
-
|
|
10696
|
+
protected builtinAvgBytes(): number;
|
|
8130
10697
|
/** SQL column type for a boolean. */
|
|
8131
10698
|
toSQLType(): string;
|
|
8132
10699
|
/** Zod schema validating a boolean value. */
|
|
8133
|
-
|
|
10700
|
+
protected builtinValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
8134
10701
|
/** Serialize to its JSON def. */
|
|
10702
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
8135
10703
|
toJSON(): BoolFieldTypeDef;
|
|
10704
|
+
protected builtinJSON(): BoolFieldTypeDef;
|
|
8136
10705
|
/** A copy of this field type. */
|
|
10706
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
8137
10707
|
clone(): BoolFieldType;
|
|
10708
|
+
protected builtinClone(): BoolFieldType;
|
|
8138
10709
|
}
|
|
8139
10710
|
|
|
8140
10711
|
/**
|
|
@@ -8154,19 +10725,30 @@ declare class DateFieldType extends FieldType {
|
|
|
8154
10725
|
/** Reconstruct from a JSON def (throws on a kind mismatch). */
|
|
8155
10726
|
static from(json: FieldTypeDef): DateFieldType;
|
|
8156
10727
|
/** The Zod schema for this field type's JSON def. */
|
|
8157
|
-
static toSchema(): z.ZodTypeAny;
|
|
10728
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
8158
10729
|
/** Resolve to the `date` scalar comparison category. */
|
|
8159
10730
|
resolve(): ScalarKind;
|
|
10731
|
+
/**
|
|
10732
|
+
* Meet with another `date` (timezone policies must AGREE — a naive and a
|
|
10733
|
+
* tz-aware value are not the same instant) or with `timestamp`, which is the
|
|
10734
|
+
* more specific side of the temporal family and answers for both: an ISO
|
|
10735
|
+
* timestamp satisfies this type's date schema, but not the reverse.
|
|
10736
|
+
*/
|
|
10737
|
+
protected meetWith(other: FieldType): FieldType | undefined;
|
|
8160
10738
|
/** Estimated average stored byte size. */
|
|
8161
|
-
|
|
10739
|
+
protected builtinAvgBytes(): number;
|
|
8162
10740
|
/** SQL column type for a calendar date. */
|
|
8163
10741
|
toSQLType(): string;
|
|
8164
10742
|
/** Zod schema validating an ISO date (`YYYY-MM-DD`) value. */
|
|
8165
|
-
|
|
10743
|
+
protected builtinValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
8166
10744
|
/** Serialize to its JSON def (omitting `timezone` when unset). */
|
|
10745
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
8167
10746
|
toJSON(): DateFieldTypeDef;
|
|
10747
|
+
protected builtinJSON(): DateFieldTypeDef;
|
|
8168
10748
|
/** A copy of this field type. */
|
|
10749
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
8169
10750
|
clone(): DateFieldType;
|
|
10751
|
+
protected builtinClone(): DateFieldType;
|
|
8170
10752
|
}
|
|
8171
10753
|
|
|
8172
10754
|
/** Zod schema for the shared timezone policy (`string | true | false`). */
|
|
@@ -8188,19 +10770,37 @@ declare class TimestampFieldType extends FieldType {
|
|
|
8188
10770
|
/** Reconstruct from a JSON def (throws on a kind mismatch). */
|
|
8189
10771
|
static from(json: FieldTypeDef): TimestampFieldType;
|
|
8190
10772
|
/** The Zod schema for this field type's JSON def. */
|
|
8191
|
-
static toSchema(): z.ZodTypeAny;
|
|
10773
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
8192
10774
|
/** Resolve to the `timestamp` scalar comparison category. */
|
|
8193
10775
|
resolve(): ScalarKind;
|
|
10776
|
+
/**
|
|
10777
|
+
* Meet with another `timestamp`, or with `date` — this type is the more
|
|
10778
|
+
* specific of the temporal family (a value of it satisfies a `date`'s ISO
|
|
10779
|
+
* prefix, not the reverse), so it IS the meet of the pair, and
|
|
10780
|
+
* `DateFieldType.meetWith` delegates here. Timezone policies must AGREE either
|
|
10781
|
+
* way: a naive and a tz-aware value are not the same instant, so there is no
|
|
10782
|
+
* third policy that is both.
|
|
10783
|
+
*
|
|
10784
|
+
* The other side's policy is read off its JSON def rather than through an
|
|
10785
|
+
* `instanceof DateFieldType`, which would close an import cycle (`date.ts`
|
|
10786
|
+
* already imports {@link timezoneSchema} from here). The def is a
|
|
10787
|
+
* discriminated union, so the narrowing is a compile-time fact, not a cast.
|
|
10788
|
+
*/
|
|
10789
|
+
protected meetWith(other: FieldType): FieldType | undefined;
|
|
8194
10790
|
/** Estimated average stored byte size. */
|
|
8195
|
-
|
|
10791
|
+
protected builtinAvgBytes(): number;
|
|
8196
10792
|
/** SQL column type (`timestamp` when naive, else `timestamptz`). */
|
|
8197
10793
|
toSQLType(): string;
|
|
8198
10794
|
/** Zod schema validating an ISO timestamp (`YYYY-MM-DD HH:MM`) value. */
|
|
8199
|
-
|
|
10795
|
+
protected builtinValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
8200
10796
|
/** Serialize to its JSON def (omitting `timezone` when unset). */
|
|
10797
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
8201
10798
|
toJSON(): TimestampFieldTypeDef;
|
|
10799
|
+
protected builtinJSON(): TimestampFieldTypeDef;
|
|
8202
10800
|
/** A copy of this field type. */
|
|
10801
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
8203
10802
|
clone(): TimestampFieldType;
|
|
10803
|
+
protected builtinClone(): TimestampFieldType;
|
|
8204
10804
|
}
|
|
8205
10805
|
|
|
8206
10806
|
/** A recursive Zod schema matching any JSON value. */
|
|
@@ -8223,21 +10823,32 @@ declare class JsonFieldType extends FieldType {
|
|
|
8223
10823
|
/** Reconstruct from a JSON def (throws on a kind mismatch). */
|
|
8224
10824
|
static from(json: FieldTypeDef): JsonFieldType;
|
|
8225
10825
|
/** The Zod schema for this field type's JSON def. */
|
|
8226
|
-
static toSchema(): z.ZodTypeAny;
|
|
10826
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
8227
10827
|
/** Resolve to the `json` scalar comparison category. */
|
|
8228
10828
|
resolve(): ScalarKind;
|
|
8229
|
-
/** JSON only compares meaningfully with other JSON. */
|
|
8230
|
-
|
|
10829
|
+
/** JSON only compares meaningfully with other JSON — plus any declared refinement edge. */
|
|
10830
|
+
protected builtinComparableWith(other: FieldType): boolean;
|
|
10831
|
+
/**
|
|
10832
|
+
* Meet with another `json`. The optional `schema` is a single-valued
|
|
10833
|
+
* constraint this package stores verbatim and cannot intersect, so two
|
|
10834
|
+
* DIFFERENT schemas conflict rather than silently picking one; an absent
|
|
10835
|
+
* schema constrains nothing and adopts the other's.
|
|
10836
|
+
*/
|
|
10837
|
+
protected meetWith(other: FieldType): FieldType | undefined;
|
|
8231
10838
|
/** Estimated average stored byte size. */
|
|
8232
|
-
|
|
10839
|
+
protected builtinAvgBytes(): number;
|
|
8233
10840
|
/** SQL column type for a JSON document. */
|
|
8234
10841
|
toSQLType(): string;
|
|
8235
10842
|
/** Zod schema validating any JSON value. */
|
|
8236
|
-
|
|
10843
|
+
protected builtinValueSchema(_opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
8237
10844
|
/** Serialize to its JSON def (omitting `schema` when unset). */
|
|
10845
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
8238
10846
|
toJSON(): JsonFieldTypeDef;
|
|
10847
|
+
protected builtinJSON(): JsonFieldTypeDef;
|
|
8239
10848
|
/** A deep copy, structurally cloning the optional `schema` data. */
|
|
10849
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
8240
10850
|
clone(): JsonFieldType;
|
|
10851
|
+
protected builtinClone(): JsonFieldType;
|
|
8241
10852
|
}
|
|
8242
10853
|
|
|
8243
10854
|
/**
|
|
@@ -8272,25 +10883,54 @@ declare class ArrayFieldType extends FieldType {
|
|
|
8272
10883
|
/** Reconstruct from a JSON def, parsing the element type via the registry. */
|
|
8273
10884
|
static from(json: FieldTypeDef, registry?: Registry): ArrayFieldType;
|
|
8274
10885
|
/** The Zod schema for this field type's JSON def. */
|
|
8275
|
-
static toSchema(): z.ZodTypeAny;
|
|
10886
|
+
static toSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
8276
10887
|
/** Resolve to the `array` scalar comparison category. */
|
|
8277
10888
|
resolve(): ScalarKind;
|
|
10889
|
+
/**
|
|
10890
|
+
* The declared ELEMENT type, or `undefined` for a heterogeneous array — the
|
|
10891
|
+
* one accessor every consumer that recurses into an array reads, so none of
|
|
10892
|
+
* them narrows to this class to reach `item` (see `FieldType.itemType`).
|
|
10893
|
+
*/
|
|
10894
|
+
itemType(): FieldType | undefined;
|
|
8278
10895
|
/**
|
|
8279
10896
|
* Arrays compare only with other arrays. When BOTH sides declare an element
|
|
8280
10897
|
* type, the element types must themselves be comparable; an unknown element
|
|
8281
10898
|
* type on either side is treated as compatible (no constraint to enforce).
|
|
8282
10899
|
*/
|
|
8283
|
-
|
|
10900
|
+
protected builtinComparableWith(other: FieldType): boolean;
|
|
10901
|
+
/**
|
|
10902
|
+
* The first closed-set violation among the ELEMENTS. An array declares no set
|
|
10903
|
+
* of its own (see `FieldType.values`), but its item type may — and writing
|
|
10904
|
+
* `['bogus']` into an `array<text one of a|b>` is exactly as wrong as writing
|
|
10905
|
+
* `'bogus'` into the scalar column. It was silently ACCEPTED, while this very
|
|
10906
|
+
* type's `toValueSchema()` rejected the same array. Recurses, so an
|
|
10907
|
+
* `array<array<text one of …>>` reports the whole index path.
|
|
10908
|
+
*
|
|
10909
|
+
* A non-array `raw` is not this check's business: writing a scalar to an array
|
|
10910
|
+
* column is a CATEGORY error, refused earlier as `write.type`.
|
|
10911
|
+
*/
|
|
10912
|
+
closedSetViolation(raw: JsonValue): ClosedSetViolation | undefined;
|
|
10913
|
+
/**
|
|
10914
|
+
* Meet with another `array`: element counts tighten and the ELEMENT types meet
|
|
10915
|
+
* recursively. An unknown element type on either side is TOP (no constraint),
|
|
10916
|
+
* so it adopts the other's — the same asymmetry `comparableWith` already
|
|
10917
|
+
* applies, made constructive.
|
|
10918
|
+
*/
|
|
10919
|
+
protected meetWith(other: FieldType): FieldType | undefined;
|
|
8284
10920
|
/** Estimated average stored byte size (midpoint count × per-element bytes). */
|
|
8285
|
-
|
|
10921
|
+
protected builtinAvgBytes(): number;
|
|
8286
10922
|
/** Neutral SQL column type; dialects produce the real array type. */
|
|
8287
10923
|
toSQLType(): string;
|
|
8288
10924
|
/** Zod schema validating an array value, honoring element type and bounds. */
|
|
8289
|
-
|
|
10925
|
+
protected builtinValueSchema(opts?: ValueSchemaOptions): z.ZodTypeAny;
|
|
8290
10926
|
/** Serialize to its JSON def (recursing into the element type). */
|
|
10927
|
+
/** Serialize to its JSON def, carrying any `as` refinement (see `FieldType.toJSON`). */
|
|
8291
10928
|
toJSON(): ArrayFieldTypeDef;
|
|
10929
|
+
protected builtinJSON(): ArrayFieldTypeDef;
|
|
8292
10930
|
/** A deep copy (cloning the element type). */
|
|
10931
|
+
/** A copy of this field type, refinement included (see `FieldType.clone`). */
|
|
8293
10932
|
clone(): ArrayFieldType;
|
|
10933
|
+
protected builtinClone(): ArrayFieldType;
|
|
8294
10934
|
/** A compact source-like rendering, e.g. `array<text>` or `array`. */
|
|
8295
10935
|
toCode(): string;
|
|
8296
10936
|
}
|
|
@@ -8304,10 +10944,459 @@ declare class ArrayFieldType extends FieldType {
|
|
|
8304
10944
|
declare const BUILTIN_FIELD_TYPES: readonly FieldTypeClass[];
|
|
8305
10945
|
/**
|
|
8306
10946
|
* Zod schema for the full `FieldTypeDef` discriminated union — the union of
|
|
8307
|
-
* each
|
|
8308
|
-
*
|
|
10947
|
+
* each field type's `toSchema(opts)`. Built with `.or` folding to avoid the
|
|
10948
|
+
* tuple cast `z.union([...])` would require.
|
|
10949
|
+
*
|
|
10950
|
+
* REGISTRY-DRIVEN when `opts.registry` is supplied: the branches come from the
|
|
10951
|
+
* registry's own `fieldTypeClassList()` rather than from the static
|
|
10952
|
+
* `BUILTIN_FIELD_TYPES` array, and each branch renders its `as` key as an ENUM
|
|
10953
|
+
* of the refinements registered over that base. Without a registry it falls back
|
|
10954
|
+
* to the builtins with no `as` offered at all — which is the honest answer,
|
|
10955
|
+
* since a schema built from nothing knows of no refinement to name.
|
|
10956
|
+
*
|
|
10957
|
+
* That distinction is the point rather than a nicety: this schema is what a
|
|
10958
|
+
* model authors a Type against, so an `as` left open as a free string is an
|
|
10959
|
+
* invitation to invent `{kind:'text', as:'uuid4'}` and find out at parse.
|
|
10960
|
+
*/
|
|
10961
|
+
declare function fieldTypeDefSchema(opts?: SchemaOptions): z.ZodTypeAny;
|
|
10962
|
+
|
|
10963
|
+
/**
|
|
10964
|
+
* The JSON VALUE an expr carries AT EMIT TIME — a literal's own value, or the
|
|
10965
|
+
* value bound to a param — and the routing decision that follows from it.
|
|
10966
|
+
*
|
|
10967
|
+
* WHY THIS IS SHARED. `Dialect.jsonValue(value, fieldType?, site?)` is where a
|
|
10968
|
+
* declared type's `cast` template fires
|
|
10969
|
+
* (`ST_GeomFromGeoJSON($1)::geometry(Polygon,4326)` instead of
|
|
10970
|
+
* `CAST($1 AS jsonb)`), and it can only fire when the caller SUPPLIES the field
|
|
10971
|
+
* type. Through `0.6.6`'s first pass exactly one road did — the write cell — so
|
|
10972
|
+
* a document reaching SQL anywhere else emitted the base cast and Postgres
|
|
10973
|
+
* refused the statement outright (`operator does not exist: geometry && jsonb`).
|
|
10974
|
+
* Any position that KNOWS the type a value is destined for should route through
|
|
10975
|
+
* here; the two that do are a write cell (the column's type) and a registered
|
|
10976
|
+
* operator's operand (the DECLARED operand type).
|
|
10977
|
+
*
|
|
10978
|
+
* `LiteralExpr` / `ParamExpr` in a position with no declared target still cannot
|
|
10979
|
+
* be helped — a bare literal in a `WHERE` knows only its own shape, and a param's
|
|
10980
|
+
* INFERRED type does not exist at emit time (`engine.toSQL` builds a fresh scope
|
|
10981
|
+
* and runs no validation walk). That is a separate, wider change; this module is
|
|
10982
|
+
* for the positions where the answer is already in hand.
|
|
10983
|
+
*
|
|
10984
|
+
* THE COLUMN-VS-VALUE RULE LIVES IN THE DIALECT, not here — see
|
|
10985
|
+
* {@link ValueSite}. It has to: Postgres binds a native array ELEMENT-WISE and
|
|
10986
|
+
* re-enters `jsonValue` per element, so a rule enforced at this one call site was
|
|
10987
|
+
* enforced for the container and skipped for everything inside it.
|
|
10988
|
+
*/
|
|
10989
|
+
|
|
10990
|
+
/**
|
|
10991
|
+
* The JSON value `expr` carries at emit time, or `undefined` when it is an
|
|
10992
|
+
* expression to emit normally (a field ref, a function call, an unbound param).
|
|
10993
|
+
*/
|
|
10994
|
+
declare function boundValue(expr: Expr, ctx: SqlContext): JsonValue | undefined;
|
|
10995
|
+
/**
|
|
10996
|
+
* Emit `expr` in a position whose target type is KNOWN, binding a carried
|
|
10997
|
+
* document (or any value destined for a `json` target) through
|
|
10998
|
+
* {@link Dialect.jsonValue} so the target's declared `cast` fires.
|
|
10999
|
+
*
|
|
11000
|
+
* The routing predicate is the A12 one, unchanged and shared rather than
|
|
11001
|
+
* restated: a value routes when it is an OBJECT (a document has no other correct
|
|
11002
|
+
* binding) or when the target is a `json` one (a scalar into a `json` slot needs
|
|
11003
|
+
* the cast too — the difference between a Postgres `jsonb` cast and the
|
|
11004
|
+
* `ARRAY[…]::text[]` a native array column actually needs).
|
|
11005
|
+
*
|
|
11006
|
+
* SQL NULL stays SQL NULL: a null literal is the documented way to write one,
|
|
11007
|
+
* and routing it would emit `CAST('null' AS jsonb)` — the JSON *value* `null`, a
|
|
11008
|
+
* different thing.
|
|
11009
|
+
*
|
|
11010
|
+
* `site` marks this a VALUE position and names the operand it belongs to; absent
|
|
11011
|
+
* ⇒ a COLUMN. A value position whose target's cast interpolates an option the
|
|
11012
|
+
* position did not write is REFUSED there rather than filled from the
|
|
11013
|
+
* refinement's defaults — see {@link ValueSite}.
|
|
11014
|
+
*/
|
|
11015
|
+
declare function typedValueSql(expr: Expr, target: FieldType | undefined, dialect: Dialect, ctx: SqlContext, site?: ValueSite): SqlText;
|
|
11016
|
+
|
|
11017
|
+
/**
|
|
11018
|
+
* The default value corpus every soundness / gate check runs over — one
|
|
11019
|
+
* representative of each JSON shape a column can be handed.
|
|
11020
|
+
*
|
|
11021
|
+
* It is deliberately SMALL and category-spanning rather than exhaustive: the
|
|
11022
|
+
* properties here are universally quantified, so a counterexample is what a
|
|
11023
|
+
* corpus is for, and one member per shape finds the counterexamples that
|
|
11024
|
+
* actually occur (a `null`, an empty string, a wrong-category scalar, a
|
|
11025
|
+
* container where a scalar was expected). A consumer whose type has interesting
|
|
11026
|
+
* values of its own passes them as `samples` — a geometry's corpus should hold a
|
|
11027
|
+
* real GeoJSON `Point`, and nothing here can guess one.
|
|
8309
11028
|
*/
|
|
8310
|
-
declare
|
|
11029
|
+
declare const DEFAULT_SAMPLES: readonly JsonValue[];
|
|
11030
|
+
/**
|
|
11031
|
+
* The unconstrained (TOP) type of each refinable kind — the right-hand side of
|
|
11032
|
+
* the `x ⊓ ⊤ = x` law.
|
|
11033
|
+
*
|
|
11034
|
+
* `relation` is absent, and that is a fact about relations rather than an
|
|
11035
|
+
* omission: its `to` is an IDENTITY, not a constraint, so there is no relation
|
|
11036
|
+
* that constrains nothing and therefore no top to meet against. It is also the
|
|
11037
|
+
* one base a refinement may not narrow, so nothing this module checks can
|
|
11038
|
+
* produce one.
|
|
11039
|
+
*/
|
|
11040
|
+
declare function topsByKind(): Partial<Record<FieldTypeKind, FieldType>>;
|
|
11041
|
+
/** One law's verdict: its name and every combination that broke it. */
|
|
11042
|
+
interface LatticeLaw {
|
|
11043
|
+
/** Stable law name — `commutative`, `associative`, `sound`, … */
|
|
11044
|
+
readonly law: string;
|
|
11045
|
+
/** What the law says, for a failure message that explains itself. */
|
|
11046
|
+
readonly states: string;
|
|
11047
|
+
/**
|
|
11048
|
+
* Every offending combination, as `"<a> ∧ <b>: <what happened>"`. EMPTY means
|
|
11049
|
+
* the law holds. Collected rather than thrown at the first one, because a
|
|
11050
|
+
* broken meet usually breaks in a family and the first counterexample is
|
|
11051
|
+
* rarely the informative one.
|
|
11052
|
+
*/
|
|
11053
|
+
readonly violations: readonly string[];
|
|
11054
|
+
}
|
|
11055
|
+
/** The verdict of {@link checkLatticeLaws} — one entry per law, plus the roll-up. */
|
|
11056
|
+
interface LatticeLawReport {
|
|
11057
|
+
/** True when every law holds. */
|
|
11058
|
+
readonly ok: boolean;
|
|
11059
|
+
/** Every law, in a stable order, whether or not it holds. */
|
|
11060
|
+
readonly laws: readonly LatticeLaw[];
|
|
11061
|
+
/** Only the laws that failed — what a test asserts is empty. */
|
|
11062
|
+
readonly failed: readonly LatticeLaw[];
|
|
11063
|
+
}
|
|
11064
|
+
/** What {@link checkLatticeLaws} needs beyond the types themselves. */
|
|
11065
|
+
interface LatticeLawOptions {
|
|
11066
|
+
/**
|
|
11067
|
+
* The registry the types were built from. Supplied ⇒ the ROUND-TRIP law runs:
|
|
11068
|
+
* every type, and every type the meet produces, must re-parse on the registry
|
|
11069
|
+
* that produced it to exactly itself. That is the property a meet's def has to
|
|
11070
|
+
* satisfy to be handed back through `params()` at all.
|
|
11071
|
+
*/
|
|
11072
|
+
readonly registry?: Registry;
|
|
11073
|
+
/** The value corpus the soundness law is proved over. Defaults to {@link DEFAULT_SAMPLES}. */
|
|
11074
|
+
readonly samples?: readonly JsonValue[];
|
|
11075
|
+
/** The TOP of each kind, for `x ⊓ ⊤ = x`. Defaults to {@link topsByKind}. */
|
|
11076
|
+
readonly tops?: Partial<Record<FieldTypeKind, FieldType>>;
|
|
11077
|
+
}
|
|
11078
|
+
/**
|
|
11079
|
+
* Prove the meet is a genuine meet over `types` — the six laws, plus the two the
|
|
11080
|
+
* `as` tag added.
|
|
11081
|
+
*
|
|
11082
|
+
* THE LAWS ARE UNCONDITIONAL AND THERE ARE NO CARVE-OUTS. A meet that needs an
|
|
11083
|
+
* exception is not a meet: `ParamSet` folds an arbitrary number of observations
|
|
11084
|
+
* in walk order, so a law that holds "except for X" means a param's inferred
|
|
11085
|
+
* type depends on where in the JSON tree its uses happened to sit. If a type set
|
|
11086
|
+
* cannot satisfy one of these, the answer is a fix to the type or a refusal at
|
|
11087
|
+
* the declaration — which is exactly how the `0.6.6` closed-set narrowing was
|
|
11088
|
+
* resolved, and why `x ⊓ ⊤ = x` is stated with no expected-failure list.
|
|
11089
|
+
*
|
|
11090
|
+
* The loops compare CANONICAL STRINGS rather than deep-equalling defs: a
|
|
11091
|
+
* hundred-name set is ~10^6 triples for associativity alone, and a deep compare
|
|
11092
|
+
* spends the whole budget inside the comparison rather than on the property.
|
|
11093
|
+
*/
|
|
11094
|
+
declare function checkLatticeLaws(types: Readonly<Record<string, FieldType>>, opts?: LatticeLawOptions): LatticeLawReport;
|
|
11095
|
+
/**
|
|
11096
|
+
* The CODE half a consumer hands {@link checkFieldType}, plus the values it
|
|
11097
|
+
* wants the properties proved over.
|
|
11098
|
+
*/
|
|
11099
|
+
interface FieldTypeCheckImpl extends FieldTypeImpl {
|
|
11100
|
+
/**
|
|
11101
|
+
* Values of this type, added to {@link DEFAULT_SAMPLES}. Supply real ones: the
|
|
11102
|
+
* default corpus spans JSON shapes, and only the declarer knows what a
|
|
11103
|
+
* well-formed value of THEIR type looks like — a gate that refuses everything
|
|
11104
|
+
* in the default corpus and everything real is vacuous in the direction that
|
|
11105
|
+
* matters, and nothing here can tell without one.
|
|
11106
|
+
*/
|
|
11107
|
+
readonly samples?: readonly JsonValue[];
|
|
11108
|
+
}
|
|
11109
|
+
/** The verdict of {@link checkFieldType}. */
|
|
11110
|
+
interface FieldTypeConformanceReport {
|
|
11111
|
+
/** True when nothing was found — what a consumer's test asserts. */
|
|
11112
|
+
readonly ok: boolean;
|
|
11113
|
+
/** Everything found, as `Problem`s: `error` blocks, `warning` is worth reading. */
|
|
11114
|
+
readonly problems: readonly Problem[];
|
|
11115
|
+
/**
|
|
11116
|
+
* The lattice verdict over the type set built from the declaration, or
|
|
11117
|
+
* `undefined` when the declaration did not register at all (in which case
|
|
11118
|
+
* there was nothing to prove anything about).
|
|
11119
|
+
*/
|
|
11120
|
+
readonly lattice: LatticeLawReport | undefined;
|
|
11121
|
+
}
|
|
11122
|
+
/**
|
|
11123
|
+
* Run the builtins' own property tests against ONE declaration — the four
|
|
11124
|
+
* lattice laws, round-trip identity, `clone` equality, soundness, and (with an
|
|
11125
|
+
* `impl`) the two cross-library facts about its value gate.
|
|
11126
|
+
*
|
|
11127
|
+
* WHAT IT BUILDS. A fresh registry carrying `decl`, a PEER refinement over the
|
|
11128
|
+
* same base (which must conflict with it — a registered name meets only itself),
|
|
11129
|
+
* and the unrefined TOP of every refinable kind. Then, for each option the
|
|
11130
|
+
* declaration declares for itself, a column for every value that option can take
|
|
11131
|
+
* — enumerable when the option's type is a closed set, otherwise its default.
|
|
11132
|
+
* The result is the smallest set that exercises every arm the declaration
|
|
11133
|
+
* touches: the `as` lattice against another name and against its own base, the
|
|
11134
|
+
* OWN-OPTION lattice against a sibling column and against a column that left the
|
|
11135
|
+
* option unset, and the cross-kind families the tag can fall off.
|
|
11136
|
+
*
|
|
11137
|
+
* WHAT IT CANNOT DO, said plainly rather than left to be discovered: it cannot
|
|
11138
|
+
* tell whether the emitted SQL means what the declarer intended, and it cannot
|
|
11139
|
+
* tell whether an in-memory answer agrees with the database's. Those need a live
|
|
11140
|
+
* connection and belong in a consumer's integration suite.
|
|
11141
|
+
*/
|
|
11142
|
+
declare function checkFieldType(decl: FieldTypeRefinementDef, impl?: FieldTypeCheckImpl): FieldTypeConformanceReport;
|
|
11143
|
+
/** What {@link checkOperator} needs beyond the declaration. */
|
|
11144
|
+
interface OperatorCheckOptions {
|
|
11145
|
+
/**
|
|
11146
|
+
* The registry to register into. Supply one already carrying the field-type
|
|
11147
|
+
* REFINEMENTS the operands name — an operand typed `{kind:'json',
|
|
11148
|
+
* as:'Geometry'}` cannot compile on a registry with no `Geometry`, and
|
|
11149
|
+
* "register your types first" is a fact about the declaration rather than a
|
|
11150
|
+
* failure of it. Defaults to a bare {@link createRegistry}.
|
|
11151
|
+
*/
|
|
11152
|
+
readonly registry?: Registry;
|
|
11153
|
+
}
|
|
11154
|
+
/** The verdict of {@link checkOperator}. */
|
|
11155
|
+
interface OperatorConformanceReport {
|
|
11156
|
+
/** True when nothing was found — what a consumer's test asserts. */
|
|
11157
|
+
readonly ok: boolean;
|
|
11158
|
+
/** Everything found, as `Problem`s: `error` blocks, `warning` is worth reading. */
|
|
11159
|
+
readonly problems: readonly Problem[];
|
|
11160
|
+
/**
|
|
11161
|
+
* The lattice verdict over the operand / output types, or `undefined` when the
|
|
11162
|
+
* declaration did not register at all. It should be identical to the verdict
|
|
11163
|
+
* WITHOUT the operator — see {@link checkOperator}.
|
|
11164
|
+
*/
|
|
11165
|
+
readonly lattice: LatticeLawReport | undefined;
|
|
11166
|
+
}
|
|
11167
|
+
/**
|
|
11168
|
+
* Check ONE operator declaration — the counterpart of {@link checkFieldType},
|
|
11169
|
+
* and deliberately a different set of questions, because an operator is a
|
|
11170
|
+
* different kind of thing.
|
|
11171
|
+
*
|
|
11172
|
+
* A refinement is a LATTICE PARTICIPANT: it changes what every meet over its
|
|
11173
|
+
* base answers, so its check is a property over a set of types. An operator is a
|
|
11174
|
+
* LEAF: it declares operand types and emits SQL, and it changes nothing about
|
|
11175
|
+
* how any type behaves. So the laws it is held to are the ones only a set can
|
|
11176
|
+
* see FAIL — and the interesting assertion is that they still HOLD, i.e. that
|
|
11177
|
+
* registering an operator has not perturbed the lattice over the very types it
|
|
11178
|
+
* names. (`registerOperator` parses those types through the registry, which is
|
|
11179
|
+
* exactly the sort of thing that could freeze a vocabulary or share a compiled
|
|
11180
|
+
* refinement instance wrongly; the law set is what would notice.)
|
|
11181
|
+
*
|
|
11182
|
+
* Plus the three things a REGISTRATION cannot check, each with a real failure
|
|
11183
|
+
* behind it:
|
|
11184
|
+
*
|
|
11185
|
+
* 1. **Every declared dialect is REGISTERED here.** `emit: { postgress: … }` is
|
|
11186
|
+
* a legal declaration — `emit` is keyed by an arbitrary string, and it has
|
|
11187
|
+
* to be, since a dialect may be registered after the operator. So a typo
|
|
11188
|
+
* produces an operator that registers cleanly, describes itself normally,
|
|
11189
|
+
* and is REFUSED at emit on every dialect that exists. Reported as an error,
|
|
11190
|
+
* because there is no reading of it that is intended.
|
|
11191
|
+
* 2. **Every `examples` string parses, and is an example OF THIS OPERATOR.** An
|
|
11192
|
+
* example is raw JSON round-tripped verbatim into a prompt, so a malformed
|
|
11193
|
+
* one teaches a model malformed syntax — the most expensive kind of wrong,
|
|
11194
|
+
* since the model will reproduce it and then fail validation.
|
|
11195
|
+
* 3. **Every example's `args` name the DECLARED operands.** The structural
|
|
11196
|
+
* parser accepts any record of exprs (the operand check is validation's job,
|
|
11197
|
+
* and an example has no query around it to validate), so this is the only
|
|
11198
|
+
* place a shipped example's operand names are compared with the declaration.
|
|
11199
|
+
*/
|
|
11200
|
+
declare function checkOperator(decl: OperatorDef, opts?: OperatorCheckOptions): OperatorConformanceReport;
|
|
11201
|
+
|
|
11202
|
+
/**
|
|
11203
|
+
* One row a live database handed back — a column-name → value map, which is what
|
|
11204
|
+
* every driver this could be wired to already produces (`pg`'s `result.rows`,
|
|
11205
|
+
* `mysql2`'s, `better-sqlite3`'s `.all()`).
|
|
11206
|
+
*
|
|
11207
|
+
* THE VALUES ARE `unknown`, DELIBERATELY, and this is the harness's second
|
|
11208
|
+
* unverifiable premise after "the same rows". A driver decides what a column
|
|
11209
|
+
* DESERIALISES to, and the defaults are not this package's JSON model: `pg`
|
|
11210
|
+
* hands back a `Date` for `timestamptz`, a STRING for `numeric` and `bigint`
|
|
11211
|
+
* (precision it will not silently lose), and a `Buffer` for `bytea`. Typed as
|
|
11212
|
+
* `JsonValue` this compiled only because `pg` types its rows as `any` — and a
|
|
11213
|
+
* DRIVER ARTIFACT filed as a divergence of the type is the most expensive kind
|
|
11214
|
+
* of false positive a harness can produce.
|
|
11215
|
+
*
|
|
11216
|
+
* WHICH ARTIFACTS ACTUALLY REACH THE COMPARISON, measured, because the obvious
|
|
11217
|
+
* example is not one of them. {@link canonical} renders both sides through
|
|
11218
|
+
* `JSON.stringify`, and `JSON.stringify(new Date(iso))` is byte-identical to
|
|
11219
|
+
* `JSON.stringify(iso)` — so a `timestamptz` `Date` beside `engine.run`'s ISO
|
|
11220
|
+
* string AGREES (`order asc` / `distinct` / `group by` all `agreed=true` with a
|
|
11221
|
+
* real `Date` on the driver side). The two that DO fire are the ones whose
|
|
11222
|
+
* rendering differs: a `numeric` arrives as `"1.5"` against a run-side `1.5`,
|
|
11223
|
+
* and a `bytea` as `{"type":"Buffer","data":[…]}` against a string. Both
|
|
11224
|
+
* disagree on every probe.
|
|
11225
|
+
*
|
|
11226
|
+
* So the remedy is the caller's and it is one line at their end, not a
|
|
11227
|
+
* normalisation this package could guess: register the type parsers that match
|
|
11228
|
+
* your model (`pg.types.setTypeParser(1700, Number)` for a numeric), or project
|
|
11229
|
+
* a text form in the column you point `columns.field` at. A first run against a
|
|
11230
|
+
* `numeric` column will say so loudly, which is the point of leaving it visible
|
|
11231
|
+
* rather than coercing.
|
|
11232
|
+
*/
|
|
11233
|
+
type DifferentialRow = Readonly<Record<string, unknown>>;
|
|
11234
|
+
/**
|
|
11235
|
+
* How {@link differentialCheck} reaches the live database: the emitted statement
|
|
11236
|
+
* and its positional params in, its rows out.
|
|
11237
|
+
*
|
|
11238
|
+
* ```ts
|
|
11239
|
+
* execute: async (sql, params) => (await pool.query(sql, [...params])).rows
|
|
11240
|
+
* ```
|
|
11241
|
+
*
|
|
11242
|
+
* It is a CALLBACK rather than a driver dependency for the reason every seam in
|
|
11243
|
+
* this package is: the package has no database client, must not acquire one, and
|
|
11244
|
+
* a consumer's pool already carries their connection, their search path and
|
|
11245
|
+
* their transaction.
|
|
11246
|
+
*/
|
|
11247
|
+
type DifferentialExecute = (sql: string, params: readonly SqlValue[]) => Promise<readonly DifferentialRow[]>;
|
|
11248
|
+
/** Which COLUMNS {@link differentialCheck} drives its probes from. */
|
|
11249
|
+
interface DifferentialColumns {
|
|
11250
|
+
/** A registered Type name — and a real table of that name in the database. */
|
|
11251
|
+
readonly type: string;
|
|
11252
|
+
/** A field of `type` whose declared field type is the one under test. */
|
|
11253
|
+
readonly field: string;
|
|
11254
|
+
/**
|
|
11255
|
+
* A SECOND field of the same type, for the probes that need two operands — the
|
|
11256
|
+
* comparison arms, and every operator / function of arity ≥ 2.
|
|
11257
|
+
*
|
|
11258
|
+
* Optional, and its absence is REPORTED rather than silently narrowing the run:
|
|
11259
|
+
* a check that quietly skipped most of what it was asked to do would be worse
|
|
11260
|
+
* than one that did not run. THE SAME FIELD TYPE is not decoration either: one
|
|
11261
|
+
* of a different kind makes every arm illegal, which used to read as `ok: true`
|
|
11262
|
+
* with nothing compared and is now `conformance.differential-no-arms`.
|
|
11263
|
+
*/
|
|
11264
|
+
readonly other?: string;
|
|
11265
|
+
}
|
|
11266
|
+
/** What {@link differentialCheck} needs. */
|
|
11267
|
+
interface DifferentialCheckOptions {
|
|
11268
|
+
/**
|
|
11269
|
+
* The engine to drive BOTH roads from — its registry carrying the declaration
|
|
11270
|
+
* under test, and its executor for {@link DifferentialColumns.type} holding
|
|
11271
|
+
* THE SAME ROWS the database's table holds.
|
|
11272
|
+
*
|
|
11273
|
+
* That last part is the harness's one unverifiable premise, and it is stated
|
|
11274
|
+
* rather than checked because nothing here can check it: if the two row sets
|
|
11275
|
+
* differ, every probe disagrees and the report blames the type. Point the
|
|
11276
|
+
* executor at the same fixture the table was seeded from.
|
|
11277
|
+
*/
|
|
11278
|
+
readonly engine: QueryEngine;
|
|
11279
|
+
/** The dialect to emit for — a name registered on the engine's registry. */
|
|
11280
|
+
readonly dialect: string;
|
|
11281
|
+
/** The live database (see {@link DifferentialExecute}). */
|
|
11282
|
+
readonly execute: DifferentialExecute;
|
|
11283
|
+
/** The columns to drive the probes from. */
|
|
11284
|
+
readonly columns: DifferentialColumns;
|
|
11285
|
+
/** Registered OPERATOR names to exercise over those columns. Default: none. */
|
|
11286
|
+
readonly operators?: readonly string[];
|
|
11287
|
+
/** Registered scalar FUNCTION names to exercise over those columns. Default: none. */
|
|
11288
|
+
readonly functions?: readonly string[];
|
|
11289
|
+
}
|
|
11290
|
+
/**
|
|
11291
|
+
* HOW a probe's two answers are compared, which is a property of the probe
|
|
11292
|
+
* rather than a global.
|
|
11293
|
+
*
|
|
11294
|
+
* - `'sequence'` — position by position. The ORDER probes, where the SEQUENCE
|
|
11295
|
+
* is the whole property under test.
|
|
11296
|
+
* - `'multiset'` — both sides sorted canonically first. Everything else, where
|
|
11297
|
+
* the VALUES are the property and the `ORDER BY` is there only to give the
|
|
11298
|
+
* statement a deterministic plan. A `valueProbe` projects an expression and
|
|
11299
|
+
* orders by the driving FIELD, so two rows with equal driving values may come
|
|
11300
|
+
* back in either order — positionally that is a disagreement, and it is not
|
|
11301
|
+
* one. Comparing the multiset removes the "your driving column must be
|
|
11302
|
+
* unique" precondition instead of documenting it.
|
|
11303
|
+
*/
|
|
11304
|
+
type DifferentialComparison = 'sequence' | 'multiset';
|
|
11305
|
+
/** One probe: the statement, both roads' answers, and whether they agreed. */
|
|
11306
|
+
interface DifferentialProbe {
|
|
11307
|
+
/** What this probe exercises — `order asc`, `field < other`, `&&`, `ST_Contains`. */
|
|
11308
|
+
readonly label: string;
|
|
11309
|
+
/** The statement that was emitted and executed. */
|
|
11310
|
+
readonly sql: string;
|
|
11311
|
+
/** The values `engine.run` produced, in row order. */
|
|
11312
|
+
readonly runValues: readonly JsonValue[];
|
|
11313
|
+
/**
|
|
11314
|
+
* The values the database produced, in row order — `unknown`, because that is
|
|
11315
|
+
* what a driver hands back (see {@link DifferentialRow}).
|
|
11316
|
+
*/
|
|
11317
|
+
readonly sqlValues: readonly unknown[];
|
|
11318
|
+
/** How the two were compared (see {@link DifferentialComparison}). */
|
|
11319
|
+
readonly comparison: DifferentialComparison;
|
|
11320
|
+
/** Whether the two agreed. */
|
|
11321
|
+
readonly agreed: boolean;
|
|
11322
|
+
}
|
|
11323
|
+
/** The verdict of {@link differentialCheck}. */
|
|
11324
|
+
interface DifferentialReport {
|
|
11325
|
+
/**
|
|
11326
|
+
* True when NOTHING was found — every probe ran, every probe agreed, and
|
|
11327
|
+
* nothing the CALLER asked for was skipped. Arms this package's own validation
|
|
11328
|
+
* refuses do not count against it (they are in {@link unprobeable} instead):
|
|
11329
|
+
* a `json` type cannot be `LIKE`d, and reporting that as a finding would make
|
|
11330
|
+
* `ok` false for a correct declaration on its first run.
|
|
11331
|
+
*/
|
|
11332
|
+
readonly ok: boolean;
|
|
11333
|
+
/** Everything found: a disagreement or a throw is an `error`, a skip a `warning`. */
|
|
11334
|
+
readonly problems: readonly Problem[];
|
|
11335
|
+
/** Every probe that ran, agreed or not — the record a consumer diffs across releases. */
|
|
11336
|
+
readonly probes: readonly DifferentialProbe[];
|
|
11337
|
+
/**
|
|
11338
|
+
* Probes that were NOT emitted because `engine.validateQuery` refuses them,
|
|
11339
|
+
* each with the codes it refused for — the harness's blind spots, named.
|
|
11340
|
+
*
|
|
11341
|
+
* It exists because the alternative is invisible. The arm loop enumerates all
|
|
11342
|
+
* nine comparison operators, and several are illegal for any given type for
|
|
11343
|
+
* reasons a `compare` declaration does not state (`like` over a `json` column
|
|
11344
|
+
* is `comparison.like`, not `compare.textMatch`). Emitting them anyway sends
|
|
11345
|
+
* statements this package calls invalid to a real server and files each
|
|
11346
|
+
* refusal as a divergence — three red herrings on a correct declaration's
|
|
11347
|
+
* first run, which is the failure the arm skip claims to prevent.
|
|
11348
|
+
*/
|
|
11349
|
+
readonly unprobeable: readonly DifferentialSkip[];
|
|
11350
|
+
}
|
|
11351
|
+
/** One probe `engine.validateQuery` refused, and why (see {@link DifferentialReport.unprobeable}). */
|
|
11352
|
+
interface DifferentialSkip {
|
|
11353
|
+
/** The probe's label. */
|
|
11354
|
+
readonly label: string;
|
|
11355
|
+
/** The problem codes validation reported, in walk order. */
|
|
11356
|
+
readonly codes: readonly string[];
|
|
11357
|
+
}
|
|
11358
|
+
/**
|
|
11359
|
+
* Run every probe BOTH WAYS — `engine.run` and the live database — and report
|
|
11360
|
+
* where they disagreed. The one failure mode neither registration nor
|
|
11361
|
+
* {@link checkFieldType} can detect, and the reason it needs a connection.
|
|
11362
|
+
*
|
|
11363
|
+
* WHAT IT IS FOR. A registered type has two halves that must answer the same
|
|
11364
|
+
* question the same way: its SQL half (`sql` / `cast`, per dialect) and its
|
|
11365
|
+
* in-memory half (`FieldTypeImpl.compareValues`). Nothing static relates them —
|
|
11366
|
+
* this package cannot read a column's collation, cannot know what a PostGIS
|
|
11367
|
+
* `&&` returns, and cannot know that `inet` orders by address while a string
|
|
11368
|
+
* orders lexicographically. A declaration whose two halves disagree produces
|
|
11369
|
+
* TWO ANSWERS FOR ONE QUERY, silently, and which one a caller gets depends only
|
|
11370
|
+
* on whether they ran it or emitted it.
|
|
11371
|
+
*
|
|
11372
|
+
* WHERE IT BELONGS. A consumer's INTEGRATION suite, not their unit tests — it is
|
|
11373
|
+
* this package's `integration/run.ts` shape: a real connection, real fixtures,
|
|
11374
|
+
* and deliberately outside `npm test`. It is exported from
|
|
11375
|
+
* `@aeye/query/conformance` beside {@link checkFieldType} and
|
|
11376
|
+
* {@link checkOperator} because it answers the same question they do, one level
|
|
11377
|
+
* further out; nothing in this package's own suite calls it against a database.
|
|
11378
|
+
*
|
|
11379
|
+
* ```ts
|
|
11380
|
+
* const report = await differentialCheck({
|
|
11381
|
+
* engine, dialect: 'postgres',
|
|
11382
|
+
* execute: async (sql, params) => (await pool.query(sql, [...params])).rows,
|
|
11383
|
+
* columns: { type: 'parcel', field: 'shape', other: 'nextShape' },
|
|
11384
|
+
* operators: ['&&'], functions: ['ST_Distance'],
|
|
11385
|
+
* });
|
|
11386
|
+
* expect(report.problems).toEqual([]);
|
|
11387
|
+
* ```
|
|
11388
|
+
*
|
|
11389
|
+
* EVERY PROBE IS DRIVEN FROM COLUMNS, never from a bound sample, and that is a
|
|
11390
|
+
* deliberate boundary rather than a simplification. A bound VALUE reaches a
|
|
11391
|
+
* declared `cast` only in a write cell or a registered operator's operand
|
|
11392
|
+
* (`exprs/_bound-value.ts`); everywhere else it binds through the dialect's
|
|
11393
|
+
* default, which is a KNOWN and documented limit. Probing with samples would
|
|
11394
|
+
* therefore report that limit — the same disagreement, for every type, on every
|
|
11395
|
+
* run — and bury the divergence the harness exists to find. Seed the values you
|
|
11396
|
+
* care about into the table instead: they are then columns, and every road types
|
|
11397
|
+
* them.
|
|
11398
|
+
*/
|
|
11399
|
+
declare function differentialCheck(opts: DifferentialCheckOptions): Promise<DifferentialReport>;
|
|
8311
11400
|
|
|
8312
11401
|
/**
|
|
8313
11402
|
* Ergonomic expression BUILDER — `e.*`.
|
|
@@ -8975,7 +12064,13 @@ declare class SelectQuery extends Query {
|
|
|
8975
12064
|
private allTrue;
|
|
8976
12065
|
/** Project the select fields over a row + group into an output record. */
|
|
8977
12066
|
private project;
|
|
8978
|
-
/**
|
|
12067
|
+
/**
|
|
12068
|
+
* Group rows by the GROUP BY key tuple, preserving first-seen order.
|
|
12069
|
+
*
|
|
12070
|
+
* Keyed on the raw values' JSON, so a refinement's declared `compareValues`
|
|
12071
|
+
* does NOT decide which rows share a group — see `recordSignature` in
|
|
12072
|
+
* `runtime/record.ts` for the boundary and why it is drawn there.
|
|
12073
|
+
*/
|
|
8979
12074
|
private groupRows;
|
|
8980
12075
|
/**
|
|
8981
12076
|
* Sort the projected rows by the FROM Type's `defaultOrder` when it applies
|
|
@@ -9699,7 +12794,36 @@ declare const BUILTIN_LIBRARY: readonly BuiltinFunction[];
|
|
|
9699
12794
|
|
|
9700
12795
|
/** The first field's value of a record (scalar-subquery semantics), or null. */
|
|
9701
12796
|
declare function firstField(record: SourceRecord): JsonValue;
|
|
9702
|
-
/**
|
|
12797
|
+
/**
|
|
12798
|
+
* A stable, key-sorted JSON key for a record (distinct / set-op dedupe).
|
|
12799
|
+
*
|
|
12800
|
+
* IDENTITY HERE IS RAW, AND A DECLARED `compareValues` DOES NOT REACH IT. That
|
|
12801
|
+
* is a stated boundary rather than an oversight, and the signature is the reason
|
|
12802
|
+
* it is one: this takes a `SourceRecord` — raw cells, with no `Field` and no
|
|
12803
|
+
* `FieldType` anywhere in scope — because a whole ROW's identity is not a
|
|
12804
|
+
* question any one column's type can answer. Every road that compares two VALUES
|
|
12805
|
+
* (`= <>`, ordering, `BETWEEN`, `IN`, join and relation equality, `min` / `max`)
|
|
12806
|
+
* goes through `Value.compareTo` and does honour the comparator.
|
|
12807
|
+
*
|
|
12808
|
+
* The consequence, for a comparator whose equality is COARSER than raw identity
|
|
12809
|
+
* (a `Net` that treats a /24 as one value, a version that ignores build
|
|
12810
|
+
* metadata): `WHERE a = b` calls two rows the same while `SELECT DISTINCT`,
|
|
12811
|
+
* `GROUP BY`, an aggregate's `DISTINCT` and the set operations keep them apart —
|
|
12812
|
+
* and a database whose column type agrees with the comparator collapses them, so
|
|
12813
|
+
* the two roads disagree. A comparator that only REORDERS (an `inet`, a semver
|
|
12814
|
+
* with no metadata) has identical equality and is unaffected, which is the
|
|
12815
|
+
* common case.
|
|
12816
|
+
*
|
|
12817
|
+
* It is not hidden and it is not un-measurable: `checkFieldType` warns
|
|
12818
|
+
* statically when a declaration's comparator merges two values it admits
|
|
12819
|
+
* (`conformance.comparator-coarser-than-identity`), and `differentialCheck`
|
|
12820
|
+
* ships `distinct` and `group by` probes that settle it against a real column
|
|
12821
|
+
* type. Closing it means grouping by SORT-MERGE rather than by hash — a
|
|
12822
|
+
* comparator is an ORDER, not a canonical form, so there is no key to build from
|
|
12823
|
+
* one — which changes the complexity of every DISTINCT and GROUP BY in the
|
|
12824
|
+
* package, including the ones with no refined column in sight. That is a
|
|
12825
|
+
* deliberate decision, not a to-do.
|
|
12826
|
+
*/
|
|
9703
12827
|
declare function recordSignature(record: SourceRecord): string;
|
|
9704
12828
|
|
|
9705
12829
|
/**
|
|
@@ -9719,7 +12843,7 @@ declare class BaseDialect extends Dialect {
|
|
|
9719
12843
|
bindPlaceholder(_index: number): string;
|
|
9720
12844
|
/**
|
|
9721
12845
|
* ANSI fallback: substring match via `LIKE`. Case-insensitive by default
|
|
9722
|
-
* (both sides wrapped in `LOWER`); plain `LIKE` when the field is `
|
|
12846
|
+
* (both sides wrapped in `LOWER`); plain `LIKE` when the field's casing is `'exact'`.
|
|
9723
12847
|
*/
|
|
9724
12848
|
textSearch(col: SqlText, query: string, sensitive?: boolean): SqlText;
|
|
9725
12849
|
/** No vector support in portable SQL: similarity degrades to a literal 0. */
|
|
@@ -9741,7 +12865,7 @@ declare class BaseDialect extends Dialect {
|
|
|
9741
12865
|
* (integer vs decimal, bounded varchar). No casts: each branch narrows via
|
|
9742
12866
|
* `instanceof`.
|
|
9743
12867
|
*/
|
|
9744
|
-
|
|
12868
|
+
protected builtinSqlTypeFor(fieldType: FieldType): string;
|
|
9745
12869
|
/** Element count via `json_array_length` (NULL-safe to 0). */
|
|
9746
12870
|
arrayLength(arg: SqlText): SqlText;
|
|
9747
12871
|
/** ANSI has no array containment — fail loudly rather than emit wrong SQL. */
|
|
@@ -9771,7 +12895,7 @@ declare class PostgresDialect extends BaseDialect {
|
|
|
9771
12895
|
ilike(left: SqlText, right: SqlText): SqlText;
|
|
9772
12896
|
/**
|
|
9773
12897
|
* Full-text search via the text-search operators (inherently case-folded).
|
|
9774
|
-
*
|
|
12898
|
+
* An `'exact'`-cased field falls back to an exact-case substring `LIKE`.
|
|
9775
12899
|
*/
|
|
9776
12900
|
textSearch(col: SqlText, query: string, sensitive?: boolean): SqlText;
|
|
9777
12901
|
/** Cosine similarity over a pgvector embedding field (`<=>` = distance). */
|
|
@@ -9811,13 +12935,17 @@ declare class PostgresDialect extends BaseDialect {
|
|
|
9811
12935
|
* Everything else — a `json` / `jsonb` column, a heterogeneous array (which
|
|
9812
12936
|
* `sqlTypeFor` already stores as `jsonb`), or a bare document with no declared
|
|
9813
12937
|
* target — casts the JSON text to `jsonb`.
|
|
12938
|
+
*
|
|
12939
|
+
* THE ELEMENT RECURSION CARRIES `site`, so the value-position rule reaches the
|
|
12940
|
+
* ITEM's declared cast as well as the container's — see
|
|
12941
|
+
* `Dialect.builtinJsonValue` for the emit this closed.
|
|
9814
12942
|
*/
|
|
9815
|
-
|
|
12943
|
+
protected builtinJsonValue(value: JsonValue, fieldType?: FieldType, site?: ValueSite): SqlText;
|
|
9816
12944
|
/** Cast the query param to the pgvector type so `similarity` type-checks (`<param>::vector`). */
|
|
9817
12945
|
queryVectorParam(param: SqlText): SqlText;
|
|
9818
12946
|
/**
|
|
9819
12947
|
* `ts_rank(to_tsvector(col), plainto_tsquery(query))` — a numeric relevance.
|
|
9820
|
-
*
|
|
12948
|
+
* An `'exact'`-cased field has no case-folded ranking, so it degrades to a numeric
|
|
9821
12949
|
* match over the exact-case substring `LIKE` (mirrors `textSearch`).
|
|
9822
12950
|
*/
|
|
9823
12951
|
textRank(col: SqlText, query: string, sensitive?: boolean): SqlText;
|
|
@@ -9830,7 +12958,7 @@ declare class PostgresDialect extends BaseDialect {
|
|
|
9830
12958
|
/** Native `LEFT JOIN LATERAL (…) AS alias ON true` (Postgres lateral support). */
|
|
9831
12959
|
lateralJoin(subquery: SqlText, alias: string, joinType: 'left' | 'inner'): SqlText;
|
|
9832
12960
|
/** Postgres field types (text / jsonb / timestamptz / numeric). */
|
|
9833
|
-
|
|
12961
|
+
protected builtinSqlTypeFor(fieldType: FieldType): string;
|
|
9834
12962
|
/** Render an inline date-field token as a QUOTED STRING (`date_part('day', …)`). */
|
|
9835
12963
|
rawArgLiteral(token: string): SqlText;
|
|
9836
12964
|
/**
|
|
@@ -10313,6 +13441,26 @@ declare function describeTypes(engine: QueryEngine | Registry, types?: readonly
|
|
|
10313
13441
|
* functions the model may call. Defaults to every registered function.
|
|
10314
13442
|
*/
|
|
10315
13443
|
declare function describeFunctions(engine: QueryEngine | Registry, selector?: FunctionSelector, maxExamples?: number, overrides?: DescribeOverrides): string;
|
|
13444
|
+
/**
|
|
13445
|
+
* The REGISTERED OPERATOR catalog — one
|
|
13446
|
+
* `&& (left: json, right: json) → bool — instructions` line each, plus their
|
|
13447
|
+
* worked examples.
|
|
13448
|
+
*
|
|
13449
|
+
* `describeFunctions` with a different iterator, and it exists for the same
|
|
13450
|
+
* measured reason: an operator a model is not TOLD about is an operator it
|
|
13451
|
+
* cannot use, and a `json` column carrying a PostGIS geometry describes itself
|
|
13452
|
+
* as "a JSON document" no matter how good its operators are. The operand types
|
|
13453
|
+
* render as their resolved CATEGORY plus the registered NAME the column will
|
|
13454
|
+
* carry, because "which of these two `json`s does `&&` take" is exactly the
|
|
13455
|
+
* question a refinement was introduced to answer.
|
|
13456
|
+
*
|
|
13457
|
+
* Not capability-gated by Type, unlike the expression catalog: an operator's
|
|
13458
|
+
* relevance is decided by the SCHEMA gate (`exprKindApplicable`) that removes
|
|
13459
|
+
* the `operator` kind wholesale, and a listing that dropped individual operators
|
|
13460
|
+
* while the kind stayed available would offer a model a construct with no
|
|
13461
|
+
* vocabulary to write in it.
|
|
13462
|
+
*/
|
|
13463
|
+
declare function describeOperators(engine: QueryEngine | Registry, maxExamples?: number, overrides?: DescribeOverrides): string;
|
|
10316
13464
|
/**
|
|
10317
13465
|
* The CAPABILITY-GATED expression catalog: one `kind — INSTRUCTIONS` line per
|
|
10318
13466
|
* expr kind actually USABLE for the current engine's Types / functions. It
|
|
@@ -10383,7 +13531,7 @@ declare function describeEngine(engine: QueryEngine | Registry, options?: Descri
|
|
|
10383
13531
|
* A developer-supplied `label` / `description` ALWAYS wins; these fill the gap
|
|
10384
13532
|
* so every Type / Field surfaces a human- / LLM-facing doc even when the dev
|
|
10385
13533
|
* authored none. Values are derived from what the meta-model already knows — a
|
|
10386
|
-
* Field from its `FieldType` (kind, bounds, `
|
|
13534
|
+
* Field from its `FieldType` (kind, bounds, `casing` / `semantic` / `search`
|
|
10387
13535
|
* flags, array item / bounds, a relation's `to` + DIRECTION + `count`, nullability) and a
|
|
10388
13536
|
* Type from its name plus a field / relation / index summary.
|
|
10389
13537
|
*
|
|
@@ -10535,4 +13683,4 @@ declare function parseQueryTool(engine: QueryEngine, raw: unknown, options?: Bui
|
|
|
10535
13683
|
*/
|
|
10536
13684
|
declare function buildQueryTool(engine: QueryEngine, options?: BuildQueryToolOptions): Tool<{}, {}, string, QueryToolInput, Promise<QueryResult>, [], Query>;
|
|
10537
13685
|
|
|
10538
|
-
export { AID_REGISTRY, type Access, type AccessRun, type AccessSql, AggregateExpr, type AggregateExprDef, type AggregateMerge, type AggregateRun, type AidInfo, type AidOptions, type AliasedSourceDef, type ArgExprDef, ArrayFieldType, type ArrayFieldTypeDef, type ArrayOp, ArrayOpExpr, type ArrayOpExprDef, type AutoPaginateOptions, BUILTIN_EXPRS, BUILTIN_FIELD_TYPES, BUILTIN_LIBRARY, BUILTIN_QUERIES, Backing, BaseDialect, BetweenExpr, type BetweenExprDef, BinaryExpr, type BinaryExprDef, type BinaryOp, BoolExpr, BoolFieldType, type BoolFieldTypeDef, type BuildQueryToolOptions, type BuildSchemasOptions, type BuiltinFunction, type CTEDef, type CTERecursiveDef, type CTEStatementDef, CTEStatementQuery, type CaseBranchDef, type CaseBranchSpec, CaseExpr, type CaseExprDef, Code, type CodeLine, type CodeOptions, ComparisonExpr, type ComparisonExprDef, type ComparisonOp, type ComputeRun, type ComputeSql, type Computed, type ComputedResolved, type Cost, type CostConstraints, DEFAULT_MAX_CTE_ITERATIONS, DEFAULT_MAX_EXAMPLES, DEFAULT_MAX_QUERY_SCHEMA_TYPES, DateFieldType, type DateFieldTypeDef, type DefaultCondition, type DefaultConditionOp, type DefaultOrder, type DefaultOrderDir, type DefaultOrderScope, type DefaultOrderTerm, type DeleteDef, DeleteQuery, type DescribeEngineOptions, type DescribeOverrides, Dialect, type DialectEntry, type DrillDownFailure, type DrillDownIntoSuccess, type DrillDownResult, type DrillDownSuccess, type DrillParam, type DrillValue, EQ_SELECTIVITY, type Embedder, ExcludedExpr, type ExcludedExprDef, type ExecutorContext, ExistsExpr, type ExistsExprDef, Expr, type ExprClass, type ExprClassEntry, type ExprDef, type ExprKind, ExprQuery, type ExprQueryDef, Field, type FieldBacking, type FieldDef, type FieldExprRestriction, FieldRefExpr, type FieldRefExprDef, type FieldResolved, type FieldSpec, FieldType, type FieldTypeClass, type FieldTypeDef, type FieldTypeKind, type FieldValueDef, type FilterDepth, FiltersExpr, type FiltersExprDef, type FnDepth, type FormatOptions, type FormatProblemsOptions, FunctionCallExpr, type FunctionCallExprDef, type FunctionDef, type FunctionParamDef, type FunctionRun, type FunctionSelector, type FunctionShape, type FunctionSourceDef, IN_SELECTIVITY, InExpr, type InExprDef, Index, type IndexDef, IndexPart, type IndexPartDef, type InferOptions, type InsertDef, InsertQuery, type InsertRowDef, IsNullExpr, type IsNullExprDef, type JSONEntry, type JoinBacking, JoinCtePlanner, type JoinDef, type JoinHop, type JoinOnDef, type JoinRequest, type JoinRunPlan, type JoinSpec, type JoinSqlPlan, type JoinType, JsonFieldType, type JsonFieldTypeDef, type JsonValue, type LateralJoinSpec, LiteralExpr, type LiteralExprDef, LogicalExpr, type LogicalExprDef, type LogicalOp, type MaybePromise, type Meta, MoneyFieldType, type MoneyFieldTypeDef, type MoneyOptions, type NameDepth, type NamedArgs, type Node, NumberFieldType, type NumberFieldTypeDef, type NumberOptions, type OnConflictDef, type OrderDef, type OrderEntry, OutputRefExpr, type OutputRefExprDef, type PaginatableDef, type PaginatableQuery, 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, RECURSIVE_CTE_LEVELS, ROOT_VALIDATE_CONTEXT, type RefDepth, Registry, type RelationBacking, RelationFieldType, type RelationFieldTypeDef, type RelationJoinOnDef, type RelationJoinSpec, type RelationKey, type RelationKeyPair, type RelationOn, type RelationOnPair, type RelationResolved, type RenderedSql, type ResolvedSchemaDepth, type ResolvedType, type RlsProvider, RuntimeContext, type RuntimeJoin, type RuntimeOptions, SEMANTIC_ROW_PENALTY, type ScalarKind, type ScalarRun, type ScalarValue, type SchemaDepth, type SchemaOptions, type SearchBacking, type SelectDef, type SelectFieldDef, SelectQuery, type SelectTypesOptions, type SelectedFunctions, type SemanticBacking, type SemanticEmbeddings, SemanticExpr, type SemanticExprDef, type SemanticQueryDef, type SemanticTextToVector, type SetDef, type SetOperationDef, SetOperationQuery, type SortEntryDef, type SortSelectionDef, type SorterDef, SorterExpr, type SourceDef, type SourceFieldOptionalRef, type SourceFieldRef, type SourceFieldsRef, type SourceRecord, type SourceRow, type Span, type SpanMeta, SqlContext, type SqlParamValue, SqlText, type SqlValue, SubqueryExpr, type SubqueryExprDef, type SubquerySourceDef, TEXT_SEARCH_ROW_PENALTY, TabularFunctionCallExpr, type TabularFunctionCallExprDef, type TabularRun, TextFieldType, type TextFieldTypeDef, type TextOptions, TextScoreExpr, type TextScoreExprDef, TextSearchExpr, type TextSearchExprDef, TimestampFieldType, type TimestampFieldTypeDef, type TimezonePolicy, type ToSqlOptions, Type, type TypeBacking, type TypeDef, type TypeExecutor, type TypeFieldRef, type TypeResolved, type TypeSourceDef, type TypeSpec, type TypeState, UnaryExpr, type UnaryExprDef, type UnaryOp, type UpdateDef, UpdateQuery, type ValidateContext, Value, type ValueCategory, type ValueSchemaOptions, WINDOW_ORDER_ARG, WindowExpr, type WindowExprDef, type WindowOrderSpec, type WindowRun, type WriteValueDef, ZERO_COST, add, addCost, age, agg, aidInfo, aliasedDigest, and, arrayAgg, arrayAppend, arrayConcat, arrayContains, arrayDistinct, arrayExecutor, arrayIndexOf, arrayPrepend, arrayRemove, arraySlice, arrayToString, asFieldType, autoPaginate, avg, between, boolAnd, boolOr, buildQueryTool, buildSchemas, builtinDialects, bytesOfResolved, canAutoPaginate, 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, mergeOfAggregateCall, 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 };
|
|
13686
|
+
export { AID_REGISTRY, type Access, type AccessRun, type AccessSql, AggregateExpr, type AggregateExprDef, type AggregateMerge, 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, COMPARE_ARM_OPERATORS, type CTEDef, type CTERecursiveDef, type CTEStatementDef, CTEStatementQuery, type CallVocabulary, type CaseBranchDef, type CaseBranchSpec, CaseExpr, type CaseExprDef, type CheckCtx, Code, type CodeLine, type CodeOptions, ComparisonExpr, type ComparisonExprDef, type ComparisonOp, type CompiledFieldTypeOption, type ComputeRun, type ComputeSql, type Computed, type ComputedResolved, type Cost, type CostConstraints, DEFAULT_MAX_CTE_ITERATIONS, DEFAULT_MAX_EXAMPLES, DEFAULT_MAX_QUERY_SCHEMA_TYPES, DEFAULT_SAMPLES, DEFAULT_TEXT_CASING, DateFieldType, type DateFieldTypeDef, type DeclaredArg, type DefaultCondition, type DefaultConditionOp, type DefaultOrder, type DefaultOrderDir, type DefaultOrderScope, type DefaultOrderTerm, type DeleteDef, DeleteQuery, type DescribeEngineOptions, type DescribeOverrides, Dialect, type DialectEntry, type DifferentialCheckOptions, type DifferentialColumns, type DifferentialComparison, type DifferentialExecute, type DifferentialProbe, type DifferentialReport, type DifferentialRow, type DifferentialSkip, type DrillDownFailure, type DrillDownIntoSuccess, type DrillDownResult, type DrillDownSuccess, type DrillParam, type DrillValue, EQ_SELECTIVITY, type Embedder, ExcludedExpr, type ExcludedExprDef, type ExecutorContext, ExistsExpr, type ExistsExprDef, Expr, type ExprClass, type ExprClassEntry, type ExprDef, type ExprKind, ExprQuery, type ExprQueryDef, Field, type FieldBacking, type FieldDef, type FieldExprRestriction, FieldRefExpr, type FieldRefExprDef, type FieldResolved, type FieldSpec, FieldType, type FieldTypeCheckImpl, type FieldTypeClass, type FieldTypeCompareDecl, type FieldTypeConformanceReport, type FieldTypeDef, type FieldTypeImpl, type FieldTypeKind, type FieldTypeOptionDecl, type FieldTypeOptionsOf, FieldTypeRefinement, type FieldTypeRefinementDef, type FieldTypeRefinementDefFor, type FieldTypeRefinementKey, 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, type LatticeLaw, type LatticeLawOptions, type LatticeLawReport, 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, OPERATOR_NAME_PATTERN, type OnConflictDef, type OperatorCheckOptions, type OperatorConformanceReport, type OperatorDef, OperatorExpr, type OperatorExprDef, type OperatorOperandDef, type OperatorRun, type OrderDef, type OrderEntry, OutputRefExpr, type OutputRefExprDef, type PaginatableDef, type PaginatableQuery, type ParamConflict, type ParamDef, ParamExpr, type ParamExprDef, type ParamInfo, ParamSet, type ParamUse, PostgresDialect, type Problem, Problems, Query, type QueryClass, type QueryClassEntry, type QueryDef, QueryEngine, type QueryEngineOptions, type QueryField, QueryFunction, QueryJoin, type QueryKind, QueryOperator, QueryOrder, type QueryResult, type QueryResultArray, type QuerySchemaOptions, type QuerySchemas, QueryScope, QuerySource, QueryToolError, type QueryToolInput, QueryTypeError, type QueryValidator, RANGE_SELECTIVITY, RECURSIVE_CTE_LEVELS, REFINABLE_BASES, REFINEMENT_NAME_PATTERN, ROOT_VALIDATE_CONTEXT, type RefDepth, type RefinableBase, Registry, type RelationBacking, RelationFieldType, type RelationFieldTypeDef, type RelationJoinOnDef, type RelationJoinSpec, type RelationKey, type RelationKeyPair, type RelationOn, type RelationOnPair, type RelationResolved, type RenderedSql, type ResolvedParam, type ResolvedSchemaDepth, type ResolvedType, type RlsProvider, RuntimeContext, type RuntimeJoin, type RuntimeOptions, SCALAR_KINDS, 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 Shape, type SortEntryDef, type SortSelectionDef, type SorterDef, SorterExpr, type SourceDef, type SourceFieldOptionalRef, type SourceFieldRef, type SourceFieldsRef, type SourceRecord, type SourceRow, type Span, type SpanMeta, SqlContext, type SqlParamValue, SqlText, type SqlValue, SubqueryExpr, type SubqueryExprDef, type SubquerySourceDef, TEXT_CASINGS, TEXT_SEARCH_ROW_PENALTY, TabularFunctionCallExpr, type TabularFunctionCallExprDef, type TabularRun, type Template, type TemplatePart, type TextCasing, 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 ValueComparator, type ValueSchemaOptions, type ValueSite, 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, boundValue, buildQueryTool, buildSchemas, builtinDialects, bytesOfResolved, canAutoPaginate, canonicalize, caseExpr, casingRank, checkFieldType, checkLatticeLaws, checkOperator, 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, describeOperators, describeQueryExamples, describeType, describeTypes, didYouMean, differentialCheck, directedMessage, div, drillDown, drillDownInto, e, editDistance, effectiveCasing, embeddingResolver, epoch, eq, excluded, exists, exprDefSchema, exprDigest, fieldMeta, fieldNameOf, fieldTypeDefSchema, filters, firstField, fn, foldsAtRuntime, foldsInSql, fromEpoch, generatedFieldDescription, generatedFieldLabel, generatedTypeDescription, generatedTypeLabel, gt, gte, hour, humanize, ilike, inList, inSubquery, inferType, isEmpty, isNull, isScalar, isScalarValue, isSlot, isType, isVectorText, join, joinAlias, joinCode, joinLines, jsonValueSchema, like, lit, lt, lte, makeDate, makeField, makeResult, max, maxCost, mergeOfAggregateCall, 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, refinementKeySchema, refusedOperators, relJoin, relationKeyColumns, relationOf, renameSource, reportCostProblems, resolveAccessRun, resolveAccessSql, resolveComputeRun, resolveComputeSql, resolveDefaultConditionRun, resolveDefaultConditionSql, resolveFields, resolveJoinRun, resolveJoinSql, resolveSchemaDepth, rlsPredicate, rowsCost, runAggregateFunction, runOperator, runScalarFunction, runTabularFunction, runWindowFunction, scaleRows, scanTemplate, second, selectFunctions, selectTypes, semantic, index as shape, shouldUseStringSchema, singleRow, sortEntries, sourcesOf, span, stddev, strictestCasing, stringAgg, stringToArray, sub, subquery, suggestionBudget, sum, syntheticType, tableFn, templateSlotNames, textScore, textSearch, timezoneSchema, toArrayRows, toVectorText, topsByKind, typeFromFields, typeMeta, typedValueSql, validateNamedCall, value, valueFieldType, variance, week, when, widenNullable, window, withAid, year };
|