@bjornpagen/bumbledb 0.1.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 +1450 -0
- package/README.md +69 -30
- package/dist/closed.d.ts +157 -38
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +232 -47
- package/dist/closed.js.map +1 -1
- package/dist/count.d.ts +64 -17
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +37 -14
- package/dist/count.js.map +1 -1
- package/dist/db.d.ts +27 -8
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +33 -10
- package/dist/db.js.map +1 -1
- package/dist/exhume.d.ts +12 -11
- package/dist/exhume.d.ts.map +1 -1
- package/dist/exhume.js +7 -6
- package/dist/exhume.js.map +1 -1
- package/dist/face.d.ts +135 -30
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +44 -19
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +130 -130
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +60 -94
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +29 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -14
- 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 -7
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +66 -24
- package/dist/lower.js.map +1 -1
- package/dist/marshal.d.ts +36 -21
- package/dist/marshal.d.ts.map +1 -1
- package/dist/marshal.js +41 -25
- package/dist/marshal.js.map +1 -1
- package/dist/native.d.ts +6 -2
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +2 -2
- package/dist/native.js.map +1 -1
- package/dist/query/atom.d.ts +370 -174
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +75 -172
- package/dist/query/atom.js.map +1 -1
- package/dist/query/lower.d.ts +312 -109
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +906 -387
- package/dist/query/lower.js.map +1 -1
- package/dist/query/predicate.d.ts +70 -88
- package/dist/query/predicate.d.ts.map +1 -1
- package/dist/query/predicate.js +118 -72
- package/dist/query/predicate.js.map +1 -1
- package/dist/query/run.d.ts +19 -16
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +31 -24
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +178 -127
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +111 -108
- package/dist/query/scope.js.map +1 -1
- package/dist/query/select.d.ts +102 -80
- package/dist/query/select.d.ts.map +1 -1
- package/dist/query/select.js +39 -34
- package/dist/query/select.js.map +1 -1
- package/dist/relation.d.ts +48 -38
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +24 -19
- 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 +34 -9
- package/dist/schema.js.map +1 -1
- package/dist/spec.d.ts +7 -5
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +91 -36
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +42 -12
- package/dist/statements.js.map +1 -1
- package/package.json +4 -3
- package/src/closed.ts +448 -95
- package/src/count.ts +112 -18
- package/src/db.ts +45 -17
- package/src/exhume.ts +12 -11
- package/src/face.ts +211 -41
- package/src/fields.ts +199 -234
- package/src/index.ts +78 -61
- package/src/law.ts +519 -0
- package/src/lower.ts +82 -27
- package/src/marshal.ts +48 -30
- package/src/native.ts +8 -4
- package/src/query/atom.ts +525 -374
- package/src/query/lower.ts +1469 -538
- package/src/query/predicate.ts +208 -161
- package/src/query/run.ts +35 -25
- package/src/query/scope.ts +264 -218
- package/src/query/select.ts +168 -93
- package/src/relation.ts +47 -47
- package/src/schema.ts +69 -18
- package/src/spec.ts +7 -5
- package/src/statements.ts +124 -41
- package/dist/brand.d.ts +0 -59
- package/dist/brand.d.ts.map +0 -1
- package/dist/brand.js +0 -47
- package/dist/brand.js.map +0 -1
- package/src/brand.ts +0 -82
package/dist/face.d.ts
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Faces — the projection-with-selection value both containments and
|
|
3
|
-
* windows consume: `on(Account, "holder")
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* windows consume: `on(Account, "holder")` the common single-field
|
|
4
|
+
* position, `on(Booking, ["room", "during"])` the composite/pointwise
|
|
5
|
+
* position (one spelling, arity-generic), `on(Account.where({ kind:
|
|
6
|
+
* Kind.Savings }), "id")` the σ-carrying source, `on(Kind, "id")` a closed
|
|
7
|
+
* relation's sealed shape opened through its synthetic `id`,
|
|
8
|
+
* `on(Kind.where({ mastered: true }), "id")` the ψ-selected closed source
|
|
9
|
+
* (the selection lowered as-is — the ENGINE folds it against the sealed
|
|
10
|
+
* extension at validate, never the SDK). Projection is
|
|
11
|
+
* positional: tuple order is preserved in the type, and the statement
|
|
12
|
+
* constructors pair the two sides' tuples by arity ({@link SameArity}) AND
|
|
13
|
+
* by structural shape ({@link SameShapes}) — every projected field's
|
|
14
|
+
* kind/width/element triple is read off the schema type (the minimal
|
|
15
|
+
* kernel: descriptors are pure structure) and compared positionwise. There
|
|
16
|
+
* is no domain to compare at construction — domains are LAW-BORN: the
|
|
17
|
+
* statements themselves define the equivalence classes, and `schema()` is
|
|
18
|
+
* where they aggregate and get judged (the one-generator-per-class wall).
|
|
8
19
|
*/
|
|
9
|
-
import type { AnyClosed } from "#closed.ts";
|
|
10
|
-
import type {
|
|
20
|
+
import type { AnyClosed, AnySelectedClosed, PayloadField } from "#closed.ts";
|
|
21
|
+
import type { AnyField } from "#fields.ts";
|
|
22
|
+
import type { AnyRelation, AnySelected, FieldsShape, RelationFields, SelectionBinding } from "#relation.ts";
|
|
23
|
+
/**
|
|
24
|
+
* The OWNER a face source resolves to: a selected relation — ordinary σ or
|
|
25
|
+
* closed ψ, one shape — projects from its underlying relation; a bare
|
|
26
|
+
* relation or closed relation is its own owner. The type-level twin of
|
|
27
|
+
* {@link faceParts}'s split, and what a statement's face `data` carries at
|
|
28
|
+
* its EXACT type — `schema()`'s law-typing reads the owner's literal name
|
|
29
|
+
* (and the projection tuple) straight off the statement type.
|
|
30
|
+
*/
|
|
31
|
+
type OwnerOf<S extends FaceSource> = S extends AnySelected | AnySelectedClosed ? S["relation"] : S;
|
|
11
32
|
/**
|
|
12
33
|
* A disjunctive literal set for a selection binding — `field == {A, B}`.
|
|
13
34
|
* The signature of {@link oneOf} demands two leading literals, so the
|
|
@@ -25,34 +46,90 @@ interface OneOf<V> {
|
|
|
25
46
|
declare function oneOf<V>(first: V, second: V, ...rest: V[]): OneOf<V>;
|
|
26
47
|
/** The relation a face projects from — ordinary or closed. */
|
|
27
48
|
type FaceOwner = AnyRelation | AnyClosed;
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
/**
|
|
50
|
+
* A face's runtime description: owner, π (written order), σ (resolved
|
|
51
|
+
* bindings). Generic over the owner and projection so a STATEMENT value
|
|
52
|
+
* carries its paired coordinates at their exact types — the honest runtime
|
|
53
|
+
* properties (`owner.name`, `projection`) ARE the type-level carrier
|
|
54
|
+
* `schema()`'s law-typing reads; the defaults are the wide shape every
|
|
55
|
+
* renderer and lowering walk consumes.
|
|
56
|
+
*/
|
|
57
|
+
interface FaceData<O extends FaceOwner = FaceOwner, P extends readonly string[] = readonly string[]> {
|
|
58
|
+
readonly owner: O;
|
|
59
|
+
readonly projection: P;
|
|
32
60
|
readonly selection: readonly SelectionBinding[];
|
|
33
61
|
}
|
|
34
62
|
/**
|
|
35
|
-
* A face value. `
|
|
36
|
-
*
|
|
63
|
+
* A face value. `S` is the source exactly as written (the relation,
|
|
64
|
+
* selected relation, or closed relation `on()` was handed — the statement
|
|
65
|
+
* constructors resolve each projected field's DOMAIN through it), and `P`
|
|
66
|
+
* is the projection tuple as written (its length is the positional-pairing
|
|
67
|
+
* arity). Both are honest runtime properties, not phantoms — and `data`
|
|
68
|
+
* carries the resolved owner at its exact type, which is what a statement
|
|
69
|
+
* value hands to `schema()`'s law-typing.
|
|
37
70
|
*/
|
|
38
|
-
interface Face<P extends readonly string[]> {
|
|
71
|
+
interface Face<S extends FaceSource, P extends readonly string[]> {
|
|
72
|
+
readonly source: S;
|
|
39
73
|
readonly projection: P;
|
|
40
|
-
readonly data: FaceData
|
|
74
|
+
readonly data: FaceData<OwnerOf<S>, P>;
|
|
41
75
|
}
|
|
42
|
-
/** Any face value, whatever its projection. */
|
|
43
|
-
type AnyFace = Face<readonly string[]>;
|
|
44
|
-
/** What `on()` accepts: a relation, a
|
|
45
|
-
type FaceSource = AnyRelation | AnyClosed | AnySelected;
|
|
76
|
+
/** Any face value, whatever its source and projection. */
|
|
77
|
+
type AnyFace = Face<FaceSource, readonly string[]>;
|
|
78
|
+
/** What `on()` accepts: a relation, a closed relation, or either with a selection applied. */
|
|
79
|
+
type FaceSource = AnyRelation | AnyClosed | AnySelected | AnySelectedClosed;
|
|
46
80
|
/**
|
|
47
81
|
* The field names a face over `S` may project: a relation's declared
|
|
48
82
|
* fields; a selected relation's underlying fields; a closed relation's
|
|
49
|
-
* SEALED shape — the synthetic `id` plus its declared payload columns
|
|
50
|
-
* (`docs/architecture/70-api.md`: statement field
|
|
51
|
-
* shape).
|
|
83
|
+
* SEALED shape — the synthetic `id` plus its declared payload columns,
|
|
84
|
+
* bare or ψ-selected alike (`docs/architecture/70-api.md`: statement field
|
|
85
|
+
* names address the sealed shape).
|
|
52
86
|
*/
|
|
53
|
-
type FaceFields<S extends FaceSource> = S extends AnySelected ? keyof S["relation"]["fields"] & string : S extends AnyRelation ? keyof S["fields"] & string : S extends {
|
|
87
|
+
type FaceFields<S extends FaceSource> = S extends AnySelected ? keyof S["relation"]["fields"] & string : S extends AnySelectedClosed ? "id" | (keyof S["relation"]["columns"] & string) : S extends AnyRelation ? keyof S["fields"] & string : S extends {
|
|
54
88
|
readonly axioms: Readonly<Record<string, infer Row>>;
|
|
55
89
|
} ? "id" | (keyof Row & string) : never;
|
|
90
|
+
/**
|
|
91
|
+
* One descriptor's structural comparand: the kind/width/element triple —
|
|
92
|
+
* exactly the structure the minimal kernel carries, compared exactly as the
|
|
93
|
+
* engine's Q1 law pairs positions (`schema/validate.rs`): a `bytes` width is
|
|
94
|
+
* bound (bytes<16> vs bytes<32> mismatch), while an INTERVAL width is FREE —
|
|
95
|
+
* the pointwise judgments quantify over points, which carry an element
|
|
96
|
+
* domain and not a width, so `interval(u64)` pairs with `interval(u64, 1n)`
|
|
97
|
+
* (recipe 9's extent/slot mirrors, recipe 29's mixed-width zones) and the
|
|
98
|
+
* width slot reads `undefined` for every interval. Elements stay bound:
|
|
99
|
+
* u64-vs-i64 interval pairs still mismatch.
|
|
100
|
+
*/
|
|
101
|
+
type ShapeOf<F extends AnyField> = readonly [
|
|
102
|
+
F["kind"],
|
|
103
|
+
F extends {
|
|
104
|
+
readonly element: unknown;
|
|
105
|
+
} ? undefined : F extends {
|
|
106
|
+
readonly width: infer W;
|
|
107
|
+
} ? W : undefined,
|
|
108
|
+
F extends {
|
|
109
|
+
readonly element: infer E;
|
|
110
|
+
} ? E : undefined
|
|
111
|
+
];
|
|
112
|
+
/** One field's structural shape within a declared field block (`undefined` when the name is foreign). */
|
|
113
|
+
type ShapeIn<Fields extends FieldsShape, K extends string> = K extends keyof Fields ? ShapeOf<Fields[K]> : undefined;
|
|
114
|
+
/**
|
|
115
|
+
* The structural SHAPE of one projected field, read off the source's
|
|
116
|
+
* schema type — an ordinary or selected relation's field contributes its
|
|
117
|
+
* descriptor's triple; a closed relation (bare or ψ-selected) contributes
|
|
118
|
+
* its synthetic `id` as a u64 and its payload columns' declared
|
|
119
|
+
* descriptors' triples through the closed value's typed `columns` carrier
|
|
120
|
+
* (whose runtime twin is the frozen `columns` record the mint carries).
|
|
121
|
+
* The engine stays the final authority at `Db.create`/`Db.open`.
|
|
122
|
+
*/
|
|
123
|
+
type ProjectedShape<S extends FaceSource, K extends string> = S extends AnySelected ? ShapeIn<RelationFields<S["relation"]>, K> : S extends AnySelectedClosed ? K extends "id" ? ShapeOf<S["relation"]["id"]> : ShapeIn<S["relation"]["columns"], K> : S extends AnyRelation ? ShapeIn<RelationFields<S>, K> : S extends {
|
|
124
|
+
readonly id: infer Id extends AnyField;
|
|
125
|
+
readonly columns: infer Cols extends Record<string, PayloadField>;
|
|
126
|
+
} ? K extends "id" ? ShapeOf<Id> : ShapeIn<Cols, K> : undefined;
|
|
127
|
+
/** The positionwise structural-shape tuple of a projection over `S`. */
|
|
128
|
+
type ShapesOf<S extends FaceSource, P extends readonly string[]> = {
|
|
129
|
+
readonly [I in keyof P]: ProjectedShape<S, P[I] & string>;
|
|
130
|
+
};
|
|
131
|
+
/** The shape tuple a face projects, positionwise — the comparand of {@link SameShapes}. */
|
|
132
|
+
type FaceShapes<F extends AnyFace> = F extends Face<infer S, infer P> ? ShapesOf<S, P> : never;
|
|
56
133
|
/** The projection arity of a face. */
|
|
57
134
|
type Arity<F extends AnyFace> = F["projection"]["length"];
|
|
58
135
|
/**
|
|
@@ -73,19 +150,47 @@ interface FaceArityMismatch<Left, Right> {
|
|
|
73
150
|
*/
|
|
74
151
|
type SameArity<A extends AnyFace, B extends AnyFace> = Arity<A> extends Arity<B> ? Arity<B> extends Arity<A> ? unknown : FaceArityMismatch<Arity<A>, Arity<B>> : FaceArityMismatch<Arity<A>, Arity<B>>;
|
|
75
152
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
153
|
+
* The legible shape-mismatch verdict: when the two faces of a containment,
|
|
154
|
+
* bijection, or window project structurally incompatible fields at any
|
|
155
|
+
* position, this type is intersected into the second face's parameter and
|
|
156
|
+
* names both shape tuples — a u64 face against a str face, a bytes width
|
|
157
|
+
* mismatch, or an interval element mismatch is a COMPILE error.
|
|
158
|
+
*/
|
|
159
|
+
interface FaceShapeMismatch<Left, Right> {
|
|
160
|
+
readonly "face shape mismatch — positionwise kind, width, and element must be equal on both sides": readonly [
|
|
161
|
+
Left,
|
|
162
|
+
Right
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Resolves to `unknown` (a no-op intersection) when the two faces project
|
|
167
|
+
* positionwise-equal structural shapes, and to {@link FaceShapeMismatch}
|
|
168
|
+
* otherwise. Equality is mutual tuple assignability over the
|
|
169
|
+
* kind/width/element triples. This is the whole construction-time wall —
|
|
170
|
+
* deliberately: there is no domain to compare here. The domain wall lives
|
|
171
|
+
* where domains are BORN: `schema()` computes every field's class from the
|
|
172
|
+
* statement list and holds the one-generator-per-class law, and query
|
|
173
|
+
* joins compare class names off the schema type.
|
|
174
|
+
*/
|
|
175
|
+
type SameShapes<A extends AnyFace, B extends AnyFace> = FaceShapes<A> extends FaceShapes<B> ? FaceShapes<B> extends FaceShapes<A> ? unknown : FaceShapeMismatch<FaceShapes<A>, FaceShapes<B>> : FaceShapeMismatch<FaceShapes<A>, FaceShapes<B>>;
|
|
176
|
+
/**
|
|
177
|
+
* Projects a face — one spelling, arity-generic: `on(Account, "holder")`
|
|
178
|
+
* for the common single-field position, `on(Booking, ["room", "during"])`
|
|
179
|
+
* for the composite/pointwise position (the interval-pointwise `==` and
|
|
180
|
+
* coverage recipes), `on(Account.where({...}), "id")` for a σ-carrying
|
|
181
|
+
* source. Field names are typechecked against the source (unknown field =
|
|
182
|
+
* type error, names autocomplete); tuple order is preserved (positional
|
|
183
|
+
* pairing with the other side, macro parity). The empty projection is
|
|
184
|
+
* unwritable by signature — it has no meaning in the statement grammar.
|
|
81
185
|
*/
|
|
82
|
-
declare function on<S extends FaceSource, const
|
|
186
|
+
declare function on<S extends FaceSource, const F extends FaceFields<S>>(source: S, field: F): Face<S, readonly [F]>;
|
|
187
|
+
declare function on<S extends FaceSource, const P extends readonly [FaceFields<S>, ...FaceFields<S>[]]>(source: S, fields: P): Face<S, P>;
|
|
83
188
|
/**
|
|
84
189
|
* Renders one face in the exact macro notation — `Name(p1, p2 | f == lit,
|
|
85
190
|
* g == {a, b})`, the selection block only when σ is nonempty (the engine
|
|
86
191
|
* renderer's own shape, `schema/render.rs`).
|
|
87
192
|
*/
|
|
88
193
|
declare function renderFace(face: FaceData): string;
|
|
89
|
-
export type { AnyFace, Arity, Face, FaceArityMismatch, FaceData, FaceFields, FaceOwner, FaceSource, OneOf, SameArity };
|
|
194
|
+
export type { AnyFace, Arity, Face, FaceArityMismatch, FaceData, FaceFields, FaceOwner, FaceShapeMismatch, FaceShapes, FaceSource, OneOf, OwnerOf, SameArity, SameShapes };
|
|
90
195
|
export { on, oneOf, renderFace };
|
|
91
196
|
//# sourceMappingURL=face.d.ts.map
|
package/dist/face.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"face.d.ts","sourceRoot":"","sources":["../src/face.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"face.d.ts","sourceRoot":"","sources":["../src/face.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAM3G;;;;;;;GAOG;AACH,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,SAAS,WAAW,GAAG,iBAAiB,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;AAmBlG;;;;;GAKG;AACH,UAAU,KAAK,CAAC,CAAC;IAChB,QAAQ,CAAC,Q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,EAAE,CAAC,GACP,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAsCb;;;;GAIG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAW1C;AAED,YAAY,EACX,OAAO,EACP,KAAK,EACL,IAAI,EACJ,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,KAAK,EACL,OAAO,EACP,SAAS,EACT,UAAU,EACV,CAAA;AACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/face.js
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Faces — the projection-with-selection value both containments and
|
|
3
|
-
* windows consume: `on(Account, "holder")
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* windows consume: `on(Account, "holder")` the common single-field
|
|
4
|
+
* position, `on(Booking, ["room", "during"])` the composite/pointwise
|
|
5
|
+
* position (one spelling, arity-generic), `on(Account.where({ kind:
|
|
6
|
+
* Kind.Savings }), "id")` the σ-carrying source, `on(Kind, "id")` a closed
|
|
7
|
+
* relation's sealed shape opened through its synthetic `id`,
|
|
8
|
+
* `on(Kind.where({ mastered: true }), "id")` the ψ-selected closed source
|
|
9
|
+
* (the selection lowered as-is — the ENGINE folds it against the sealed
|
|
10
|
+
* extension at validate, never the SDK). Projection is
|
|
11
|
+
* positional: tuple order is preserved in the type, and the statement
|
|
12
|
+
* constructors pair the two sides' tuples by arity ({@link SameArity}) AND
|
|
13
|
+
* by structural shape ({@link SameShapes}) — every projected field's
|
|
14
|
+
* kind/width/element triple is read off the schema type (the minimal
|
|
15
|
+
* kernel: descriptors are pure structure) and compared positionwise. There
|
|
16
|
+
* is no domain to compare at construction — domains are LAW-BORN: the
|
|
17
|
+
* statements themselves define the equivalence classes, and `schema()` is
|
|
18
|
+
* where they aggregate and get judged (the one-generator-per-class wall).
|
|
8
19
|
*/
|
|
20
|
+
import * as errors from "@superbuilders/errors";
|
|
9
21
|
import { renderLiteralSet } from "#spec.ts";
|
|
10
22
|
/** The empty σ of a selection-free face, shared by every bare projection. */
|
|
11
23
|
const emptySelection = Object.freeze([]);
|
|
12
24
|
/**
|
|
13
|
-
* Splits a face source into its owner and σ: a selected relation
|
|
14
|
-
* its own bindings (`relation` is the
|
|
15
|
-
* no relation or closed value, and
|
|
16
|
-
* handle collisions); a bare relation
|
|
25
|
+
* Splits a face source into its owner and σ: a selected relation — ordinary
|
|
26
|
+
* σ or closed ψ, one shape — carries its own bindings (`relation` is the
|
|
27
|
+
* discriminant — the property exists on no relation or closed value, and
|
|
28
|
+
* `closed()` reserves the name against handle collisions); a bare relation
|
|
29
|
+
* or closed relation carries none.
|
|
17
30
|
*/
|
|
18
31
|
function faceParts(source) {
|
|
19
32
|
if ("relation" in source) {
|
|
@@ -31,22 +44,34 @@ function oneOf(first, second, ...rest) {
|
|
|
31
44
|
Object.freeze(literals);
|
|
32
45
|
return Object.freeze({ literals });
|
|
33
46
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* "id")`. Field names are typechecked against the source; tuple order is
|
|
37
|
-
* preserved (positional pairing with the other side, macro parity). At
|
|
38
|
-
* least one field by signature — an empty projection has no meaning in the
|
|
39
|
-
* statement grammar.
|
|
40
|
-
*/
|
|
41
|
-
function on(source, ...projection) {
|
|
47
|
+
function on(source, fields) {
|
|
48
|
+
const projection = Object.freeze(typeof fields === "string" ? [fields] : [...fields]);
|
|
42
49
|
const parts = faceParts(source);
|
|
43
|
-
Object.freeze(projection);
|
|
44
50
|
const data = Object.freeze({
|
|
45
51
|
owner: parts.owner,
|
|
46
52
|
projection,
|
|
47
53
|
selection: parts.selection
|
|
48
54
|
});
|
|
49
|
-
|
|
55
|
+
const value = Object.freeze({ source, projection, data });
|
|
56
|
+
if (!faceMinted(value, source, projection)) {
|
|
57
|
+
throw errors.new(`face over ${parts.owner.name}: face construction incomplete`);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The trusted seam of the face mint (the `refsComplete` pattern): the
|
|
63
|
+
* checkable facts — the value carries exactly the source and projection it
|
|
64
|
+
* was built from, and `data.owner` is exactly the owner {@link faceParts}
|
|
65
|
+
* resolves for that source — are verified before the wide construction is
|
|
66
|
+
* admitted at the exact {@link Face} type (whose `data` claims the owner at
|
|
67
|
+
* its precise type, the carrier the schema-level law-typing reads).
|
|
68
|
+
*/
|
|
69
|
+
function faceMinted(value, source, projection) {
|
|
70
|
+
const owner = "relation" in source ? source.relation : source;
|
|
71
|
+
return (value.source === source &&
|
|
72
|
+
value.projection === projection &&
|
|
73
|
+
value.data.owner === owner &&
|
|
74
|
+
value.data.projection === projection);
|
|
50
75
|
}
|
|
51
76
|
/**
|
|
52
77
|
* Renders one face in the exact macro notation — `Name(p1, p2 | f == lit,
|
package/dist/face.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"face.js","sourceRoot":"","sources":["../src/face.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"face.js","sourceRoot":"","sources":["../src/face.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAI/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE3C,6EAA6E;AAC7E,MAAM,cAAc,GAAgC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAYrE;;;;;;GAMG;AACH,SAAS,SAAS,CAAC,MAAkB;IAIpC,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;QAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAA;IAC/D,CAAC;IACD,OAAO,EAAE,KAAK,EA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