@bjornpagen/bumbledb 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COOKBOOK.md +462 -406
- package/README.md +66 -31
- package/dist/closed.d.ts +121 -25
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +108 -42
- package/dist/closed.js.map +1 -1
- package/dist/db.d.ts +12 -1
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +20 -5
- package/dist/db.js.map +1 -1
- package/dist/face.d.ts +100 -55
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +36 -10
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +50 -79
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +20 -53
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +17 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/law.d.ts +224 -0
- package/dist/law.d.ts.map +1 -0
- package/dist/law.js +224 -0
- package/dist/law.js.map +1 -0
- package/dist/lower.d.ts +17 -10
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +34 -23
- package/dist/lower.js.map +1 -1
- package/dist/native.d.ts +6 -2
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js.map +1 -1
- package/dist/query/atom.d.ts +88 -50
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +4 -1
- package/dist/query/atom.js.map +1 -1
- package/dist/query/lower.d.ts +71 -56
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +90 -43
- package/dist/query/lower.js.map +1 -1
- package/dist/query/predicate.d.ts +10 -9
- package/dist/query/predicate.d.ts.map +1 -1
- package/dist/query/predicate.js +2 -2
- package/dist/query/predicate.js.map +1 -1
- package/dist/query/scope.d.ts +76 -41
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +77 -30
- package/dist/query/scope.js.map +1 -1
- package/dist/query/select.d.ts +5 -5
- package/dist/query/select.d.ts.map +1 -1
- package/dist/relation.d.ts +21 -8
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +13 -7
- package/dist/relation.js.map +1 -1
- package/dist/schema.d.ts +41 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +16 -2
- package/dist/schema.js.map +1 -1
- package/dist/spec.d.ts +7 -6
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +61 -31
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +22 -17
- package/dist/statements.js.map +1 -1
- package/package.json +2 -2
- package/src/closed.ts +243 -68
- package/src/db.ts +23 -5
- package/src/face.ts +162 -84
- package/src/fields.ts +57 -136
- package/src/index.ts +42 -16
- package/src/law.ts +519 -0
- package/src/lower.ts +36 -23
- package/src/native.ts +6 -2
- package/src/query/atom.ts +105 -58
- package/src/query/lower.ts +271 -139
- package/src/query/predicate.ts +43 -33
- package/src/query/scope.ts +125 -49
- package/src/query/select.ts +5 -5
- package/src/relation.ts +15 -9
- package/src/schema.ts +48 -7
- package/src/spec.ts +7 -6
- package/src/statements.ts +83 -43
package/dist/query/scope.d.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Query scope terms,
|
|
2
|
+
* Query scope terms, LAW-TYPED edition: string-named variables and
|
|
3
3
|
* parameters as plain frozen values. A `Var` is a NAME — it is typed by the
|
|
4
|
-
* field it first binds (
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* and
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* the
|
|
15
|
-
*
|
|
16
|
-
*
|
|
4
|
+
* field slot it first binds (the descriptor AND the slot's law-computed
|
|
5
|
+
* CLASS, read off the schema's class map through the rule builder's
|
|
6
|
+
* environment), reuse of the name within one rule IS the join, and a
|
|
7
|
+
* class-mismatched reuse is a compile error: a var joins only class-equal
|
|
8
|
+
* slots, and BARE PAIRS ONLY WITH BARE (ruling 3 — a slot in no law has no
|
|
9
|
+
* class and never joins a classed slot; the deliberate sum-domain pointer
|
|
10
|
+
* stays legal against other bare slots). Params are query-global by name
|
|
11
|
+
* and typed BY USE: the field position or comparison sibling that anchors
|
|
12
|
+
* a param types it, the query's inferred `Params` object is exactly the
|
|
13
|
+
* params the rules use, and a param value that no rule uses simply never
|
|
14
|
+
* registers — the query executes under its own inferred type (the
|
|
15
|
+
* bug-hunt law). This module also owns the environment/typing utilities
|
|
16
|
+
* the whole surface shares: the env shape (var name → classed slot), the
|
|
17
|
+
* class-equality judgment {@link JoinOk} with its runtime twin
|
|
18
|
+
* {@link fieldJoins}, and the record-folding helpers `Params` and `Row`
|
|
19
|
+
* inference ride.
|
|
17
20
|
*/
|
|
18
21
|
import type { AnyField, Infer } from "#fields.ts";
|
|
19
22
|
/**
|
|
@@ -89,6 +92,20 @@ type AnyTerm = Var | Param | SetParam | MaskParam | Duration;
|
|
|
89
92
|
declare function isTerm(value: unknown): value is AnyTerm;
|
|
90
93
|
/** Builds one variable term. */
|
|
91
94
|
declare function makeVar<const Name extends string>(name: Name): Var<Name>;
|
|
95
|
+
/** The record `makeVars` mints: one own frozen `Var<Name>` per requested name, each typed exactly. */
|
|
96
|
+
type VarsRecord<Names extends string> = {
|
|
97
|
+
readonly [N in Names]: Var<N>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Mints several variables at once — `const { service, w } = r.vars("service",
|
|
101
|
+
* "w")`: tuple-to-object, each name typed exactly (`Var<"service">`),
|
|
102
|
+
* inference identical to the one-at-a-time `r.var` spelling (one lowering,
|
|
103
|
+
* two entry flavors). Each key is defined as an OWN property (a name like
|
|
104
|
+
* `"__proto__"` is a record key like any other, never a prototype write),
|
|
105
|
+
* and a duplicate name in one call is a construction error: each name mints
|
|
106
|
+
* one variable — write it once and reuse the binding.
|
|
107
|
+
*/
|
|
108
|
+
declare function makeVars<const Names extends readonly string[]>(...names: Names): VarsRecord<Names[number]>;
|
|
92
109
|
/** Builds one scalar-parameter term. */
|
|
93
110
|
declare function makeParam<const Name extends string>(name: Name): Param<Name>;
|
|
94
111
|
/** Builds one set-parameter term. */
|
|
@@ -98,11 +115,23 @@ declare function makeMaskParam<const Name extends string>(name: Name): MaskParam
|
|
|
98
115
|
/** Builds one measure term over an interval-typed variable's name. */
|
|
99
116
|
declare function makeDuration<const Name extends string>(name: Name): Duration<Name>;
|
|
100
117
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
118
|
+
* One bound field slot: the field's descriptor plus the slot's
|
|
119
|
+
* law-computed CLASS (`undefined` = bare — the slot is in no law). The one
|
|
120
|
+
* shape the rule environment carries per variable, at the TYPE level (env
|
|
121
|
+
* entries hold the schema type's class-map lookups) and at RUNTIME alike
|
|
122
|
+
* (the rule's `varFields` record holds exactly this shape, read off the
|
|
123
|
+
* schema value's frozen class map) — one shape, two tiers, one walk.
|
|
124
|
+
*/
|
|
125
|
+
interface ClassedField {
|
|
126
|
+
readonly field: AnyField;
|
|
127
|
+
readonly class: string | undefined;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A rule's typing environment: variable name → the classed slot it first
|
|
131
|
+
* bound. Purely a TYPE — the runtime twin is the rule's `varFields`
|
|
103
132
|
* record, and the two are built by the same walk.
|
|
104
133
|
*/
|
|
105
|
-
type EnvShape = Record<string,
|
|
134
|
+
type EnvShape = Record<string, ClassedField>;
|
|
106
135
|
/** A params object type — what `execute` takes and inference carries. */
|
|
107
136
|
type ParamsRecord = Readonly<Record<string, unknown>>;
|
|
108
137
|
/** Flattens an intersection into one displayed object type (hover legibility). */
|
|
@@ -116,8 +145,6 @@ type UnionToIntersection<U> = (U extends unknown ? (member: U) => void : never)
|
|
|
116
145
|
* (the machinery both `Params` and `Row` inference ride).
|
|
117
146
|
*/
|
|
118
147
|
type ShapeOf<U> = [U] extends [never] ? Record<never, never> : Flatten<UnionToIntersection<U>>;
|
|
119
|
-
/** Reads a field descriptor's domain label (S1: the label IS the domain check). */
|
|
120
|
-
type DomainOf<F extends AnyField> = F["domain"];
|
|
121
148
|
/** Reads a field descriptor's width label (`bytes<N>`, `interval<E, W>`); `undefined` when the kind carries none. */
|
|
122
149
|
type WidthOf<F extends AnyField> = F extends {
|
|
123
150
|
readonly width: infer W;
|
|
@@ -127,31 +154,39 @@ type ElementOf<F extends AnyField> = F extends {
|
|
|
127
154
|
readonly element: infer E;
|
|
128
155
|
} ? E : undefined;
|
|
129
156
|
/**
|
|
130
|
-
* The
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
157
|
+
* The join judgment: two bound slots join iff their descriptors' structure
|
|
158
|
+
* agrees (kind, width label, interval element) AND their law-computed
|
|
159
|
+
* classes agree — same class name joins, and bare (`undefined`) pairs only
|
|
160
|
+
* with bare (ruling 3: a field in no law has no class; a bare↔classed
|
|
161
|
+
* pairing refuses). The class names come off the SCHEMA type's class map —
|
|
162
|
+
* the statements are the typing; no descriptor label exists to compare.
|
|
134
163
|
*/
|
|
135
|
-
type JoinOk<A extends
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
WidthOf<
|
|
139
|
-
ElementOf<
|
|
140
|
-
]
|
|
164
|
+
type JoinOk<A extends ClassedField, B extends ClassedField> = [
|
|
165
|
+
A["field"]["kind"],
|
|
166
|
+
A["class"],
|
|
167
|
+
WidthOf<A["field"]>,
|
|
168
|
+
ElementOf<A["field"]>
|
|
169
|
+
] extends [B["field"]["kind"], B["class"], WidthOf<B["field"]>, ElementOf<B["field"]>] ? [B["field"]["kind"], B["class"], WidthOf<B["field"]>, ElementOf<B["field"]>] extends [
|
|
170
|
+
A["field"]["kind"],
|
|
171
|
+
A["class"],
|
|
172
|
+
WidthOf<A["field"]>,
|
|
173
|
+
ElementOf<A["field"]>
|
|
174
|
+
] ? true : false : false;
|
|
141
175
|
/**
|
|
142
|
-
* The runtime twin of {@link JoinOk}: two
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
176
|
+
* The runtime twin of {@link JoinOk}: two bound slots join iff descriptor
|
|
177
|
+
* structure and class agree — the same comparison the type tier makes,
|
|
178
|
+
* judged on the honest runtime values (the descriptor and the schema
|
|
179
|
+
* value's frozen class map). The rule builders throw through this on a
|
|
180
|
+
* class-unequal variable reuse, so the wall holds for untyped callers too,
|
|
181
|
+
* not only where the compiler can see.
|
|
148
182
|
*/
|
|
149
|
-
declare function fieldJoins(a:
|
|
183
|
+
declare function fieldJoins(a: ClassedField, b: ClassedField): boolean;
|
|
150
184
|
/**
|
|
151
|
-
* Renders one
|
|
152
|
-
* grammar's
|
|
185
|
+
* Renders one bound slot for join-mismatch diagnostics — the structural
|
|
186
|
+
* kind in the schema grammar's spelling plus the slot's law-computed class
|
|
187
|
+
* (`u64 in class Holder.id`; a lawless slot renders `bare`).
|
|
153
188
|
*/
|
|
154
|
-
declare function renderFieldKind(
|
|
189
|
+
declare function renderFieldKind(slot: ClassedField): string;
|
|
155
190
|
/**
|
|
156
191
|
* What a PARAM anchored at field `F` accepts at execution: the field's
|
|
157
192
|
* bare value type, exactly. At an interval field the engine resolves the
|
|
@@ -179,6 +214,6 @@ interface ParamEntry {
|
|
|
179
214
|
readonly anchor: AnyField | "measure" | undefined;
|
|
180
215
|
readonly op: "binding" | "eq" | "ne" | "lt" | "le" | "gt" | "ge" | "pointIn" | "allen";
|
|
181
216
|
}
|
|
182
|
-
export type { AnyTerm,
|
|
183
|
-
export { fieldJoins, inferred, isTerm, makeDuration, makeMaskParam, makeParam, makeSetParam, makeVar, renderFieldKind, term };
|
|
217
|
+
export type { AnyTerm, ClassedField, Duration, EnvShape, Flatten, InferredOf, JoinOk, MaskParam, Param, ParamEntry, ParamsRecord, ParamValueAt, SetParam, ShapeOf, UnionToIntersection, Var, VarsRecord };
|
|
218
|
+
export { fieldJoins, inferred, isTerm, makeDuration, makeMaskParam, makeParam, makeSetParam, makeVar, makeVars, renderFieldKind, term };
|
|
184
219
|
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/query/scope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/query/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEjD;;;;GAIG;AACH,QAAA,MAAM,IAAI,EAAE,OAAO,MAAsC,CAAA;AAEzD;;;;;GAKG;AACH,QAAA,MAAM,QAAQ,EAAE,OAAO,MAA0C,CAAA;AAEjE;;;;;;GAMG;AACH,UAAU,GAAG,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IACzC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACnB;AAED;;;;;GAKG;AACH,UAAU,KAAK,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IAC3C,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACnB;AAED;;;;;;GAMG;AACH,UAAU,QAAQ,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IAC9C,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACnB;AAED;;;;;GAKG;AACH,UAAU,SAAS,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IAC/C,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,WAAW,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACnB;AAED;;;;;;;GAOG;AACH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,SAAS;IAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAA;AAEhG;;;;;;;;GAQG;AACH,UAAU,UAAU;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,CAAA;IACxC,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;IACjD,QAAQ,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAA;CACtF;AAED,YAAY,EACX,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,UAAU,EACV,MAAM,EACN,SAAS,EACT,KAAK,EACL,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,mBAAmB,EACnB,GAAG,EACH,UAAU,EACV,CAAA;AACD,OAAO,EACN,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,aAAa,EACb,SAAS,EACT,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,CAAA"}
|
package/dist/query/scope.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Query scope terms,
|
|
2
|
+
* Query scope terms, LAW-TYPED edition: string-named variables and
|
|
3
3
|
* parameters as plain frozen values. A `Var` is a NAME — it is typed by the
|
|
4
|
-
* field it first binds (
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* and
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* the
|
|
15
|
-
*
|
|
16
|
-
*
|
|
4
|
+
* field slot it first binds (the descriptor AND the slot's law-computed
|
|
5
|
+
* CLASS, read off the schema's class map through the rule builder's
|
|
6
|
+
* environment), reuse of the name within one rule IS the join, and a
|
|
7
|
+
* class-mismatched reuse is a compile error: a var joins only class-equal
|
|
8
|
+
* slots, and BARE PAIRS ONLY WITH BARE (ruling 3 — a slot in no law has no
|
|
9
|
+
* class and never joins a classed slot; the deliberate sum-domain pointer
|
|
10
|
+
* stays legal against other bare slots). Params are query-global by name
|
|
11
|
+
* and typed BY USE: the field position or comparison sibling that anchors
|
|
12
|
+
* a param types it, the query's inferred `Params` object is exactly the
|
|
13
|
+
* params the rules use, and a param value that no rule uses simply never
|
|
14
|
+
* registers — the query executes under its own inferred type (the
|
|
15
|
+
* bug-hunt law). This module also owns the environment/typing utilities
|
|
16
|
+
* the whole surface shares: the env shape (var name → classed slot), the
|
|
17
|
+
* class-equality judgment {@link JoinOk} with its runtime twin
|
|
18
|
+
* {@link fieldJoins}, and the record-folding helpers `Params` and `Row`
|
|
19
|
+
* inference ride.
|
|
17
20
|
*/
|
|
21
|
+
import * as errors from "@superbuilders/errors";
|
|
18
22
|
/**
|
|
19
23
|
* The runtime discriminant of query term values. Host literals (bigints,
|
|
20
24
|
* strings, interval objects) never carry it, so "is this position a term
|
|
@@ -37,6 +41,47 @@ function makeVar(name) {
|
|
|
37
41
|
const value = { [term]: "var", name };
|
|
38
42
|
return Object.freeze(value);
|
|
39
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* The trusted seam of the vars mint: every requested name reads back as an
|
|
46
|
+
* own var term of exactly that name — verified before the record is
|
|
47
|
+
* admitted at the {@link VarsRecord} type (a name riding the
|
|
48
|
+
* object-protocol accessor instead of an own definition would fail exactly
|
|
49
|
+
* this check).
|
|
50
|
+
*/
|
|
51
|
+
function varsMinted(record, names) {
|
|
52
|
+
return names.every(function varMinted(name) {
|
|
53
|
+
if (!Object.hasOwn(record, name)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const value = record[name];
|
|
57
|
+
return isTerm(value) && value[term] === "var" && value.name === name;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Mints several variables at once — `const { service, w } = r.vars("service",
|
|
62
|
+
* "w")`: tuple-to-object, each name typed exactly (`Var<"service">`),
|
|
63
|
+
* inference identical to the one-at-a-time `r.var` spelling (one lowering,
|
|
64
|
+
* two entry flavors). Each key is defined as an OWN property (a name like
|
|
65
|
+
* `"__proto__"` is a record key like any other, never a prototype write),
|
|
66
|
+
* and a duplicate name in one call is a construction error: each name mints
|
|
67
|
+
* one variable — write it once and reuse the binding.
|
|
68
|
+
*/
|
|
69
|
+
function makeVars(...names) {
|
|
70
|
+
const out = {};
|
|
71
|
+
const seen = new Set();
|
|
72
|
+
for (const name of names) {
|
|
73
|
+
if (seen.has(name)) {
|
|
74
|
+
throw errors.new(`vars: duplicate name ${name} — each name mints one variable; write it once and reuse the binding`);
|
|
75
|
+
}
|
|
76
|
+
seen.add(name);
|
|
77
|
+
Object.defineProperty(out, name, { value: makeVar(name), enumerable: true });
|
|
78
|
+
}
|
|
79
|
+
Object.freeze(out);
|
|
80
|
+
if (!varsMinted(out, names)) {
|
|
81
|
+
throw errors.new("vars: variable minting incomplete");
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
40
85
|
/** Builds one scalar-parameter term. */
|
|
41
86
|
function makeParam(name) {
|
|
42
87
|
const value = { [term]: "param", name };
|
|
@@ -58,25 +103,27 @@ function makeDuration(name) {
|
|
|
58
103
|
return Object.freeze(value);
|
|
59
104
|
}
|
|
60
105
|
/**
|
|
61
|
-
* The runtime twin of {@link JoinOk}: two
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
106
|
+
* The runtime twin of {@link JoinOk}: two bound slots join iff descriptor
|
|
107
|
+
* structure and class agree — the same comparison the type tier makes,
|
|
108
|
+
* judged on the honest runtime values (the descriptor and the schema
|
|
109
|
+
* value's frozen class map). The rule builders throw through this on a
|
|
110
|
+
* class-unequal variable reuse, so the wall holds for untyped callers too,
|
|
111
|
+
* not only where the compiler can see.
|
|
67
112
|
*/
|
|
68
113
|
function fieldJoins(a, b) {
|
|
69
|
-
const widthA = "width" in a ? a.width : undefined;
|
|
70
|
-
const widthB = "width" in b ? b.width : undefined;
|
|
71
|
-
const elementA = "element" in a ? a.element : undefined;
|
|
72
|
-
const elementB = "element" in b ? b.element : undefined;
|
|
73
|
-
return a.kind === b.kind && a.
|
|
114
|
+
const widthA = "width" in a.field ? a.field.width : undefined;
|
|
115
|
+
const widthB = "width" in b.field ? b.field.width : undefined;
|
|
116
|
+
const elementA = "element" in a.field ? a.field.element : undefined;
|
|
117
|
+
const elementB = "element" in b.field ? b.field.element : undefined;
|
|
118
|
+
return a.field.kind === b.field.kind && a.class === b.class && widthA === widthB && elementA === elementB;
|
|
74
119
|
}
|
|
75
120
|
/**
|
|
76
|
-
* Renders one
|
|
77
|
-
* grammar's
|
|
121
|
+
* Renders one bound slot for join-mismatch diagnostics — the structural
|
|
122
|
+
* kind in the schema grammar's spelling plus the slot's law-computed class
|
|
123
|
+
* (`u64 in class Holder.id`; a lawless slot renders `bare`).
|
|
78
124
|
*/
|
|
79
|
-
function renderFieldKind(
|
|
125
|
+
function renderFieldKind(slot) {
|
|
126
|
+
const field = slot.field;
|
|
80
127
|
let base = field.kind;
|
|
81
128
|
if (field.kind === "bytes") {
|
|
82
129
|
base = `bytes<${field.width}>`;
|
|
@@ -84,7 +131,7 @@ function renderFieldKind(field) {
|
|
|
84
131
|
if (field.kind === "interval") {
|
|
85
132
|
base = field.width === undefined ? `interval<${field.element}>` : `interval<${field.element}, ${field.width}>`;
|
|
86
133
|
}
|
|
87
|
-
return
|
|
134
|
+
return slot.class === undefined ? `${base} (bare)` : `${base} in class ${slot.class}`;
|
|
88
135
|
}
|
|
89
|
-
export { fieldJoins, inferred, isTerm, makeDuration, makeMaskParam, makeParam, makeSetParam, makeVar, renderFieldKind, term };
|
|
136
|
+
export { fieldJoins, inferred, isTerm, makeDuration, makeMaskParam, makeParam, makeSetParam, makeVar, makeVars, renderFieldKind, term };
|
|
90
137
|
//# sourceMappingURL=scope.js.map
|
package/dist/query/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/query/scope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/query/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAG/C;;;;GAIG;AACH,MAAM,IAAI,GAAkB,MAAM,CAAC,qBAAqB,CAAC,CAAA;AAEzD;;;;;GAKG;AACH,MAAM,QAAQ,GAAkB,MAAM,CAAC,yBAAyB,CAAC,CAAA;AAgEjE,6EAA6E;AAC7E,SAAS,MAAM,CAAC,KAAc;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,IAAI,IAAI,KAAK,CAAA;AACpE,CAAC;AAED,gCAAgC;AAChC,SAAS,OAAO,CAA4B,IAAU;IACrD,MAAM,KAAK,GAAc,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAKD;;;;;;GAMG;AACH,SAAS,UAAU,CAClB,MAAyC,EACzC,KAAuB;IAEvB,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,SAAS,CAAC,IAAI;QACzC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,KAAK,CAAA;QACb,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CA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AAQ,KAAK,QAAQ,CAAA;AAC1G,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,IAAkB;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;IACxB,IAAI,IAAI,GAAW,KAAK,CAAC,IAAI,CAAA;IAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,IAAI,GAAG,SAAS,KAAK,CAAC,KAAK,GAAG,CAAA;IAC/B,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,IAAI,GAAG,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,KAAK,GAAG,CAAA;IAC/G,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,aAAa,IAAI,CAAC,KAAK,EAAE,CAAA;AACtF,CAAC;AAiDD,OAAO,EACN,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,aAAa,EACb,SAAS,EACT,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,CAAA"}
|
package/dist/query/select.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ type CheckNameSelect<Env extends EnvShape, S> = {
|
|
|
95
95
|
* type.
|
|
96
96
|
*/
|
|
97
97
|
type SelectEntryRow<Env extends EnvShape, E> = E extends string ? {
|
|
98
|
-
readonly [K in E]: Infer<Env[E & keyof Env]>;
|
|
98
|
+
readonly [K in E]: Infer<Env[E & keyof Env]["field"]>;
|
|
99
99
|
} : E extends Duration<infer N extends string> ? {
|
|
100
100
|
readonly [K in N]: bigint;
|
|
101
101
|
} : E extends Agg<"count", undefined> ? {
|
|
@@ -103,13 +103,13 @@ type SelectEntryRow<Env extends EnvShape, E> = E extends string ? {
|
|
|
103
103
|
} : E extends Agg<"countDistinct", infer O extends string> ? {
|
|
104
104
|
readonly [K in O]: bigint;
|
|
105
105
|
} : E extends Agg<"sum" | "min" | "max", infer O> ? O extends string ? {
|
|
106
|
-
readonly [K in O]: Infer<Env[O & keyof Env]>;
|
|
106
|
+
readonly [K in O]: Infer<Env[O & keyof Env]["field"]>;
|
|
107
107
|
} : O extends Duration<infer N extends string> ? {
|
|
108
108
|
readonly [K in N]: bigint;
|
|
109
109
|
} : never : E extends Agg<"argMax" | "argMin", infer O extends string, string> ? {
|
|
110
|
-
readonly [K in O]: Infer<Env[O & keyof Env]>;
|
|
110
|
+
readonly [K in O]: Infer<Env[O & keyof Env]["field"]>;
|
|
111
111
|
} : E extends Agg<"pack", infer O extends string> ? {
|
|
112
|
-
readonly [K in O]: Infer<Env[O & keyof Env]>;
|
|
112
|
+
readonly [K in O]: Infer<Env[O & keyof Env]["field"]>;
|
|
113
113
|
} : never;
|
|
114
114
|
/** The inferred answer-row object type of a select tuple. */
|
|
115
115
|
type RowOfSelect<Env extends EnvShape, S extends readonly SelectEntry[]> = ShapeOf<SelectEntryRow<Env, S[number]>>;
|
|
@@ -119,7 +119,7 @@ type RowOfSelect<Env extends EnvShape, S extends readonly SelectEntry[]> = Shape
|
|
|
119
119
|
* smears into one column's type), mirroring {@link SelectEntryRow}.
|
|
120
120
|
*/
|
|
121
121
|
type NameSelectRow<Env extends EnvShape, N> = N extends string ? {
|
|
122
|
-
readonly [K in N]: Infer<Env[K & keyof Env]>;
|
|
122
|
+
readonly [K in N]: Infer<Env[K & keyof Env]["field"]>;
|
|
123
123
|
} : never;
|
|
124
124
|
/** The inferred answer-row object type of a names-only (recursive-rule) select tuple. */
|
|
125
125
|
type RowOfNameSelect<Env extends EnvShape, S extends readonly string[]> = ShapeOf<NameSelectRow<Env, S[number]>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.d.ts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AAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAElH;;;;GAIG;AACH,KAAK,aAAa,CAAC,GAAG,SAAS,QAAQ,EAAE,CAAC,IAAI,CAAC,SAAS,MAAM,GAC3D;IAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;CAAE,GACzD,KAAK,CAAA;AAER,yFAAyF;AACzF,KAAK,eAAe,CAAC,GAAG,SAAS,QAAQ,EAAE,CAAC,SAAS,SAAS,MAAM,EAAE,IAAI,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAEhH,YAAY,EACX,GAAG,EACH,SAAS,EACT,MAAM,EACN,eAAe,EACf,WAAW,EACX,eAAe,EACf,WAAW,EACX,WAAW,EACX,aAAa,EACb,cAAc,EACd,CAAA;AACD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA"}
|
package/dist/relation.d.ts
CHANGED
|
@@ -17,13 +17,23 @@ import type { LiteralSetSpec } from "#spec.ts";
|
|
|
17
17
|
type Flatten<T> = {
|
|
18
18
|
[K in keyof T]: T[K];
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a whole `where()` selection against the declared fields, in the
|
|
22
|
+
* selection's written order (macro parity: σ is spelled, not sorted). An
|
|
23
|
+
* empty selection is the bare relation respelled and rejected (the
|
|
24
|
+
* canonical-utterance law). THE one selection resolver — `closed()`'s
|
|
25
|
+
* `where()` resolves its payload columns through this same machine (a
|
|
26
|
+
* `ClosedColumn` is structurally a {@link RelationField}), so both surfaces
|
|
27
|
+
* share one vocabulary and one error voice.
|
|
28
|
+
*/
|
|
29
|
+
declare function resolveSelection(name: string, ordered: readonly RelationField[], entries: ReadonlyArray<readonly [string, unknown]>): readonly SelectionBinding[];
|
|
20
30
|
/** The field block of a relation: field name to field descriptor. */
|
|
21
31
|
type FieldsShape = Record<string, AnyField>;
|
|
22
32
|
/**
|
|
23
33
|
* A typed field reference (`Account.fields.holder`) — the value statements,
|
|
24
34
|
* selections, and queries address a field through. Purely positional
|
|
25
|
-
* (relation name + field name); the field's descriptor
|
|
26
|
-
*
|
|
35
|
+
* (relation name + field name); the field's descriptor is read off the
|
|
36
|
+
* relation's schema type structurally.
|
|
27
37
|
*/
|
|
28
38
|
interface FieldRef<Rel extends string, Name extends string> {
|
|
29
39
|
readonly relation: Rel;
|
|
@@ -105,13 +115,16 @@ type FreshKeys<R extends AnyRelation> = {
|
|
|
105
115
|
*/
|
|
106
116
|
type InsertFact<R extends AnyRelation> = Flatten<Omit<Fact<R>, FreshKeys<R>> & Partial<Pick<Fact<R>, FreshKeys<R>>>>;
|
|
107
117
|
/**
|
|
108
|
-
* Declares one relation: `relation("Account", { id:
|
|
109
|
-
* holder:
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
118
|
+
* Declares one relation: `relation("Account", { id: u64.fresh,
|
|
119
|
+
* holder: u64, kind: Kind.id, ... })` — every field is a pure-structure
|
|
120
|
+
* descriptor (the constructor values themselves; domains are never
|
|
121
|
+
* declared: `schema()` computes them from the statements). Field
|
|
122
|
+
* declaration order is ordinal-id order (macro parity), carried at BOTH
|
|
123
|
+
* levels: the type level by the fields object, the value level by the
|
|
124
|
+
* frozen `data.fields` list — the law the schema-level class naming leans
|
|
125
|
+
* on. The returned value is frozen and side-effect free.
|
|
113
126
|
*/
|
|
114
127
|
declare function relation<const Name extends string, Fields extends FieldsShape>(name: Name, fields: Fields): Relation<Name, Fields>;
|
|
115
128
|
export type { AnyRelation, AnySelected, Fact, FieldRef, FieldRefs, FieldsShape, FreshKeys, InsertFact, Relation, RelationData, RelationField, RelationFields, Selected, SelectionBinding, SelectionInput };
|
|
116
|
-
export { relation };
|
|
129
|
+
export { relation, resolveSelection };
|
|
117
130
|
//# sourceMappingURL=relation.d.ts.map
|
package/dist/relation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation.d.ts","sourceRoot":"","sources":["../src/relation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,KAAK,QAAQ,EAA6B,KAAK,KAAK,EAAa,MAAM,YAAY,CAAA;AAC5F,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,UAAU,CAAA;AAE3D,kFAAkF;AAClF,KAAK,OAAO,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"relation.d.ts","sourceRoot":"","sources":["../src/relation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,KAAK,QAAQ,EAA6B,KAAK,KAAK,EAAa,MAAM,YAAY,CAAA;AAC5F,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,UAAU,CAAA;AAE3D,kFAAkF;AAClF,KAAK,OAAO,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAoC1C;;;;;;;;GAQG;AACH,iBAAS,gBAAgB,CACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,aAAa,EAAE,EACjC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAChD,SAAS,gBAAgB,EAAE,CAoB7B;AAED,qEAAqE;AACrE,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAE3C;;;;;GAKG;AACH,UAA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,CAAC,SAAS,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEpH;;;;;;;;;GASG;AACH,iBAAS,QAAQ,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,MAAM,SAAS,WAAW,EACtE,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,GACZ,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CA6BxB;AAED,YAAY,EACX,WAAW,EACX,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,CAAA;AACD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA"}
|
package/dist/relation.js
CHANGED
|
@@ -45,7 +45,10 @@ function resolveEntry(field, entry) {
|
|
|
45
45
|
* Resolves a whole `where()` selection against the declared fields, in the
|
|
46
46
|
* selection's written order (macro parity: σ is spelled, not sorted). An
|
|
47
47
|
* empty selection is the bare relation respelled and rejected (the
|
|
48
|
-
* canonical-utterance law).
|
|
48
|
+
* canonical-utterance law). THE one selection resolver — `closed()`'s
|
|
49
|
+
* `where()` resolves its payload columns through this same machine (a
|
|
50
|
+
* `ClosedColumn` is structurally a {@link RelationField}), so both surfaces
|
|
51
|
+
* share one vocabulary and one error voice.
|
|
49
52
|
*/
|
|
50
53
|
function resolveSelection(name, ordered, entries) {
|
|
51
54
|
const bindings = [];
|
|
@@ -67,11 +70,14 @@ function resolveSelection(name, ordered, entries) {
|
|
|
67
70
|
return Object.freeze(bindings);
|
|
68
71
|
}
|
|
69
72
|
/**
|
|
70
|
-
* Declares one relation: `relation("Account", { id:
|
|
71
|
-
* holder:
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
73
|
+
* Declares one relation: `relation("Account", { id: u64.fresh,
|
|
74
|
+
* holder: u64, kind: Kind.id, ... })` — every field is a pure-structure
|
|
75
|
+
* descriptor (the constructor values themselves; domains are never
|
|
76
|
+
* declared: `schema()` computes them from the statements). Field
|
|
77
|
+
* declaration order is ordinal-id order (macro parity), carried at BOTH
|
|
78
|
+
* levels: the type level by the fields object, the value level by the
|
|
79
|
+
* frozen `data.fields` list — the law the schema-level class naming leans
|
|
80
|
+
* on. The returned value is frozen and side-effect free.
|
|
75
81
|
*/
|
|
76
82
|
function relation(name, fields) {
|
|
77
83
|
const ordered = [];
|
|
@@ -103,5 +109,5 @@ function relation(name, fields) {
|
|
|
103
109
|
holder.value = value;
|
|
104
110
|
return value;
|
|
105
111
|
}
|
|
106
|
-
export { relation };
|
|
112
|
+
export { relation, resolveSelection };
|
|
107
113
|
//# sourceMappingURL=relation.js.map
|
package/dist/relation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation.js","sourceRoot":"","sources":["../src/relation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAE/C,OAAO,EAAiB,yBAAyB,EAAc,SAAS,EAAE,MAAM,YAAY,CAAA;AAM5F;;;;;;GAMG;AACH,SAAS,YAAY,CACpB,IAA6B,EAC7B,MAAc;IAEd,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,SAAS,MAAM,CAAC,SAAS;QACzD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;QAC3B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,CAAA;IAC5F,CAAC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EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAC9E,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACnB,IAAI,CAAC,YAAY,CAAe,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;QAC/C,MAAM,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,2CAA2C,CAAC,CAAA;IAC9E,CAAC;IACD,MAAM,MAAM,GAAkD,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;IAClF,SAAS,KAAK,CAAC,SAAiC;QAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;QAC1B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,qDAAqD,CAAC,CAAA;QACxF,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC;YACpB,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SACrE,CAAC,CAAA;IACH,CAAC;IACD,MAAM,KAAK,GAA2B,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;IACxF,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,OAAO,KAAK,CAAA;AACb,CAAC;AAmBD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -9,20 +9,49 @@
|
|
|
9
9
|
* same judge, the same two-boundary split as Rust.
|
|
10
10
|
*/
|
|
11
11
|
import type { AnyClosed } from "#closed.ts";
|
|
12
|
+
import { type ClassesOf, type LawfulStatements, type SchemaClasses } from "#law.ts";
|
|
12
13
|
import type { AnyRelation } from "#relation.ts";
|
|
13
14
|
import { type Statement } from "#statements.ts";
|
|
14
15
|
/** One member of a schema's relation record. */
|
|
15
16
|
type SchemaRelation = AnyRelation | AnyClosed;
|
|
16
17
|
/** The relation record a schema is generic over — what `Db` and queries key on. */
|
|
17
18
|
type SchemaRelations = Record<string, SchemaRelation>;
|
|
18
|
-
/**
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* A theory value: named relations, the DECLARED dependency statements, and
|
|
21
|
+
* the LAW-COMPUTED class map (`classes` — relation → field → class name,
|
|
22
|
+
* `undefined` = bare). The class map is THE domain authority: `schema()`
|
|
23
|
+
* computes it FROM the statement list at both tiers (the type through
|
|
24
|
+
* {@link ClassesOf}, the value through the union-find twin), queries
|
|
25
|
+
* compare class names off it, and the wire lowering emits it as the spec
|
|
26
|
+
* `newtype` labels. Nothing is ever synthesized: `statements` is exactly
|
|
27
|
+
* the declared list, in written order.
|
|
28
|
+
*/
|
|
29
|
+
interface Schema<Rels extends SchemaRelations, Classes extends SchemaClasses = SchemaClasses> {
|
|
20
30
|
readonly name: string;
|
|
21
31
|
readonly relations: Rels;
|
|
22
32
|
readonly statements: readonly Statement[];
|
|
33
|
+
readonly classes: Classes;
|
|
23
34
|
}
|
|
24
35
|
/** Any schema value, whatever its relation record. */
|
|
25
36
|
type AnySchema = Schema<SchemaRelations>;
|
|
37
|
+
/**
|
|
38
|
+
* Forces the class map to EVALUATE at the `schema()` boundary: a two-level
|
|
39
|
+
* mapped copy, type-identical to `C` — but instantiation resolves it to
|
|
40
|
+
* the finished relation → field → class record, so hovering a schema value
|
|
41
|
+
* (or anything carrying its `Classes` parameter — queries, `Db`) shows the
|
|
42
|
+
* computed record instead of the unevaluated `ClassesOf<...>` application
|
|
43
|
+
* dragging the whole statement-tuple type along. The conditional wrapper
|
|
44
|
+
* is the display mechanism, not a judgment: resolving it drops the alias
|
|
45
|
+
* reference, so tsc renders the finished record (measured against tsc's
|
|
46
|
+
* own type rendering; a bare mapped alias still displays by name).
|
|
47
|
+
* Display-only by construction; `classesComplete` guards the same type at
|
|
48
|
+
* the value tier.
|
|
49
|
+
*/
|
|
50
|
+
type EvaluatedClasses<C extends SchemaClasses> = C extends SchemaClasses ? {
|
|
51
|
+
readonly [N in keyof C]: {
|
|
52
|
+
readonly [F in keyof C[N]]: C[N][F];
|
|
53
|
+
};
|
|
54
|
+
} : never;
|
|
26
55
|
/**
|
|
27
56
|
* Assembles a theory:
|
|
28
57
|
* `schema("Ledger", { Kind, Account, Holder }, [ ...statements ])`.
|
|
@@ -43,8 +72,17 @@ type AnySchema = Schema<SchemaRelations>;
|
|
|
43
72
|
* list: the engine materializes them itself, in its own pinned order
|
|
44
73
|
* (`SchemaDescriptor::materialized_statements`), and restating them would
|
|
45
74
|
* double them.
|
|
75
|
+
*
|
|
76
|
+
* THE LAW-TYPING happens here too (rulings 2/3 — the laws type the
|
|
77
|
+
* columns): the statement list induces the equivalence classes over field
|
|
78
|
+
* slots, at the TYPE level ({@link ClassesOf} — spell the statement list
|
|
79
|
+
* inline so the tuple type stays precise) and at runtime (the union-find
|
|
80
|
+
* twin), and the one-generator-per-class wall holds at both tiers — the
|
|
81
|
+
* {@link LawfulStatements} verdict lands the compile error on the
|
|
82
|
+
* statements argument; `computeClasses` throws the same content naming the
|
|
83
|
+
* exact statement.
|
|
46
84
|
*/
|
|
47
|
-
declare function schema<const Rels extends SchemaRelations>(name: string, relations: Rels, statements:
|
|
85
|
+
declare function schema<const Rels extends SchemaRelations, const Stmts extends readonly Statement[]>(name: string, relations: Rels, statements: Stmts & LawfulStatements<Rels, Stmts>): Schema<Rels, EvaluatedClasses<ClassesOf<Rels, Stmts>>>;
|
|
48
86
|
export type { AnySchema, Schema, SchemaRelation, SchemaRelations };
|
|
49
87
|
export { schema };
|
|
50
88
|
//# sourceMappingURL=schema.d.ts.map
|