@bjornpagen/bumbledb 0.2.0 → 0.4.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 +503 -427
- package/README.md +84 -36
- package/dist/closed.d.ts +111 -38
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +94 -99
- package/dist/closed.js.map +1 -1
- package/dist/db.d.ts +16 -2
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +46 -8
- package/dist/db.js.map +1 -1
- package/dist/face.d.ts +114 -69
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +38 -21
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +72 -87
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +35 -67
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +18 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -7
- 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/marshal.d.ts +33 -6
- package/dist/marshal.d.ts.map +1 -1
- package/dist/marshal.js +67 -6
- 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.map +1 -1
- package/dist/query/atom.d.ts +139 -56
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +7 -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 +341 -69
- 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/run.d.ts +15 -5
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +26 -6
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +100 -43
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +89 -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 +29 -15
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +45 -17
- 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 +10 -8
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +67 -31
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +97 -20
- package/dist/statements.js.map +1 -1
- package/package.json +2 -2
- package/src/closed.ts +214 -146
- package/src/db.ts +65 -10
- package/src/face.ts +169 -102
- package/src/fields.ts +97 -164
- package/src/index.ts +43 -18
- package/src/law.ts +519 -0
- package/src/lower.ts +36 -23
- package/src/marshal.ts +74 -7
- package/src/native.ts +6 -2
- package/src/query/atom.ts +155 -65
- package/src/query/lower.ts +572 -167
- package/src/query/predicate.ts +43 -33
- package/src/query/run.ts +26 -6
- package/src/query/scope.ts +161 -51
- package/src/query/select.ts +5 -5
- package/src/relation.ts +60 -26
- package/src/schema.ts +48 -7
- package/src/spec.ts +10 -8
- package/src/statements.ts +165 -46
package/dist/face.d.ts
CHANGED
|
@@ -4,37 +4,45 @@
|
|
|
4
4
|
* position, `on(Booking, ["room", "during"])` the composite/pointwise
|
|
5
5
|
* position (one spelling, arity-generic), `on(Account.where({ kind:
|
|
6
6
|
* Kind.Savings }), "id")` the σ-carrying source, `on(Kind, "id")` a closed
|
|
7
|
-
* relation's sealed shape opened through its synthetic `id
|
|
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
|
|
8
11
|
* positional: tuple order is preserved in the type, and the statement
|
|
9
12
|
* constructors pair the two sides' tuples by arity ({@link SameArity}) AND
|
|
10
|
-
* by
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* by structural shape ({@link SameShapes}) — every projected field's
|
|
14
|
+
* kind/width/element/roster quadruple is read off the schema type (the
|
|
15
|
+
* minimal kernel: descriptors are pure structure, and a closed reference's
|
|
16
|
+
* roster IS part of that structure) and compared positionwise. There is no
|
|
17
|
+
* domain to compare at construction — domains are LAW-BORN: the statements
|
|
18
|
+
* themselves define the equivalence classes, and `schema()` is where they
|
|
19
|
+
* aggregate and get judged (the one-generator-per-class wall).
|
|
14
20
|
*/
|
|
15
|
-
import type { AnyClosed, PayloadField } from "#closed.ts";
|
|
21
|
+
import type { AnyClosed, AnySelectedClosed, PayloadField } from "#closed.ts";
|
|
22
|
+
import type { AnyField } from "#fields.ts";
|
|
16
23
|
import type { AnyRelation, AnySelected, FieldsShape, RelationFields, SelectionBinding } from "#relation.ts";
|
|
17
24
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
25
|
+
* The OWNER a face source resolves to: a selected relation — ordinary σ or
|
|
26
|
+
* closed ψ, one shape — projects from its underlying relation; a bare
|
|
27
|
+
* relation or closed relation is its own owner. The type-level twin of
|
|
28
|
+
* {@link faceParts}'s split, and what a statement's face `data` carries at
|
|
29
|
+
* its EXACT type — `schema()`'s law-typing reads the owner's literal name
|
|
30
|
+
* (and the projection tuple) straight off the statement type.
|
|
22
31
|
*/
|
|
23
|
-
|
|
24
|
-
readonly literals: readonly [V, V, ...V[]];
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Constructs a literal set (read disjunctively) for a `where()` binding.
|
|
28
|
-
* Two leading arguments by signature: the degenerate sets have no spelling
|
|
29
|
-
* (the canonical-utterance law, `docs/architecture/70-api.md`).
|
|
30
|
-
*/
|
|
31
|
-
declare function oneOf<V>(first: V, second: V, ...rest: V[]): OneOf<V>;
|
|
32
|
+
type OwnerOf<S extends FaceSource> = S extends AnySelected | AnySelectedClosed ? S["relation"] : S;
|
|
32
33
|
/** The relation a face projects from — ordinary or closed. */
|
|
33
34
|
type FaceOwner = AnyRelation | AnyClosed;
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/**
|
|
36
|
+
* A face's runtime description: owner, π (written order), σ (resolved
|
|
37
|
+
* bindings). Generic over the owner and projection so a STATEMENT value
|
|
38
|
+
* carries its paired coordinates at their exact types — the honest runtime
|
|
39
|
+
* properties (`owner.name`, `projection`) ARE the type-level carrier
|
|
40
|
+
* `schema()`'s law-typing reads; the defaults are the wide shape every
|
|
41
|
+
* renderer and lowering walk consumes.
|
|
42
|
+
*/
|
|
43
|
+
interface FaceData<O extends FaceOwner = FaceOwner, P extends readonly string[] = readonly string[]> {
|
|
44
|
+
readonly owner: O;
|
|
45
|
+
readonly projection: P;
|
|
38
46
|
readonly selection: readonly SelectionBinding[];
|
|
39
47
|
}
|
|
40
48
|
/**
|
|
@@ -42,53 +50,84 @@ interface FaceData {
|
|
|
42
50
|
* selected relation, or closed relation `on()` was handed — the statement
|
|
43
51
|
* constructors resolve each projected field's DOMAIN through it), and `P`
|
|
44
52
|
* is the projection tuple as written (its length is the positional-pairing
|
|
45
|
-
* arity). Both are honest runtime properties, not phantoms
|
|
53
|
+
* arity). Both are honest runtime properties, not phantoms — and `data`
|
|
54
|
+
* carries the resolved owner at its exact type, which is what a statement
|
|
55
|
+
* value hands to `schema()`'s law-typing.
|
|
46
56
|
*/
|
|
47
57
|
interface Face<S extends FaceSource, P extends readonly string[]> {
|
|
48
58
|
readonly source: S;
|
|
49
59
|
readonly projection: P;
|
|
50
|
-
readonly data: FaceData
|
|
60
|
+
readonly data: FaceData<OwnerOf<S>, P>;
|
|
51
61
|
}
|
|
52
62
|
/** Any face value, whatever its source and projection. */
|
|
53
63
|
type AnyFace = Face<FaceSource, readonly string[]>;
|
|
54
|
-
/** What `on()` accepts: a relation, a
|
|
55
|
-
type FaceSource = AnyRelation | AnyClosed | AnySelected;
|
|
64
|
+
/** What `on()` accepts: a relation, a closed relation, or either with a selection applied. */
|
|
65
|
+
type FaceSource = AnyRelation | AnyClosed | AnySelected | AnySelectedClosed;
|
|
56
66
|
/**
|
|
57
67
|
* The field names a face over `S` may project: a relation's declared
|
|
58
68
|
* fields; a selected relation's underlying fields; a closed relation's
|
|
59
|
-
* SEALED shape — the synthetic `id` plus its declared payload columns
|
|
60
|
-
* (`docs/architecture/70-api.md`: statement field
|
|
61
|
-
* shape).
|
|
69
|
+
* SEALED shape — the synthetic `id` plus its declared payload columns,
|
|
70
|
+
* bare or ψ-selected alike (`docs/architecture/70-api.md`: statement field
|
|
71
|
+
* names address the sealed shape).
|
|
62
72
|
*/
|
|
63
|
-
type FaceFields<S extends FaceSource> = S extends AnySelected ? keyof S["relation"]["fields"] & string : S extends AnyRelation ? keyof S["fields"] & string : S extends {
|
|
73
|
+
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 {
|
|
64
74
|
readonly axioms: Readonly<Record<string, infer Row>>;
|
|
65
75
|
} ? "id" | (keyof Row & string) : never;
|
|
66
|
-
/** One field's domain label within a declared field block (`undefined` when the name is foreign). */
|
|
67
|
-
type DomainIn<Fields extends FieldsShape, K extends string> = K extends keyof Fields ? Fields[K]["domain"] : undefined;
|
|
68
76
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
77
|
+
* One descriptor's structural comparand: the kind/width/element/roster
|
|
78
|
+
* quadruple — exactly the structure the minimal kernel carries. The first
|
|
79
|
+
* three slots compare exactly as the engine's Q1 law pairs positions
|
|
80
|
+
* (`schema/validate.rs`): a `bytes` width is bound (bytes<16> vs bytes<32>
|
|
81
|
+
* mismatch), while an INTERVAL width is FREE — the pointwise judgments
|
|
82
|
+
* quantify over points, which carry an element domain and not a width, so
|
|
83
|
+
* `interval(u64)` pairs with `interval(u64, 1n)` (recipe 9's extent/slot
|
|
84
|
+
* mirrors, recipe 29's mixed-width zones) and the width slot reads
|
|
85
|
+
* `undefined` for every interval. Elements stay bound: u64-vs-i64 interval
|
|
86
|
+
* pairs still mismatch. The ROSTER slot is SDK-only structure (the engine's
|
|
87
|
+
* wire carries plain u64s): a closed reference contributes its handle
|
|
88
|
+
* union, every other kind `undefined`, so a plain u64 face cannot pair with
|
|
89
|
+
* a closed `[id]` face — the vocabulary's own descriptor (`Kind.id`) is the
|
|
90
|
+
* ONE spelling of a closed reference at this surface, and a bare column
|
|
91
|
+
* cannot alias a vocabulary through a declared law. The runtime twin is the
|
|
92
|
+
* statement constructors' roster-identity walk (`statements.ts`).
|
|
79
93
|
*/
|
|
80
|
-
type
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
type ShapeOf<F extends AnyField> = readonly [
|
|
95
|
+
F["kind"],
|
|
96
|
+
F extends {
|
|
97
|
+
readonly element: unknown;
|
|
98
|
+
} ? undefined : F extends {
|
|
99
|
+
readonly width: infer W;
|
|
100
|
+
} ? W : undefined,
|
|
101
|
+
F extends {
|
|
102
|
+
readonly element: infer E;
|
|
103
|
+
} ? E : undefined,
|
|
104
|
+
F extends {
|
|
105
|
+
readonly closed: {
|
|
106
|
+
readonly handles: readonly (infer H extends string)[];
|
|
107
|
+
};
|
|
108
|
+
} ? H : undefined
|
|
109
|
+
];
|
|
110
|
+
/** One field's structural shape within a declared field block (`undefined` when the name is foreign). */
|
|
111
|
+
type ShapeIn<Fields extends FieldsShape, K extends string> = K extends keyof Fields ? ShapeOf<Fields[K]> : undefined;
|
|
112
|
+
/**
|
|
113
|
+
* The structural SHAPE of one projected field, read off the source's
|
|
114
|
+
* schema type — an ordinary or selected relation's field contributes its
|
|
115
|
+
* descriptor's triple; a closed relation (bare or ψ-selected) contributes
|
|
116
|
+
* its synthetic `id` as a u64 and its payload columns' declared
|
|
117
|
+
* descriptors' triples through the closed value's typed `columns` carrier
|
|
118
|
+
* (whose runtime twin is the frozen `columns` record the mint carries).
|
|
119
|
+
* The engine stays the final authority at `Db.create`/`Db.open`.
|
|
120
|
+
*/
|
|
121
|
+
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 {
|
|
122
|
+
readonly id: infer Id extends AnyField;
|
|
84
123
|
readonly columns: infer Cols extends Record<string, PayloadField>;
|
|
85
|
-
} ? K extends "id" ?
|
|
86
|
-
/** The positionwise
|
|
87
|
-
type
|
|
88
|
-
readonly [I in keyof P]:
|
|
124
|
+
} ? K extends "id" ? ShapeOf<Id> : ShapeIn<Cols, K> : undefined;
|
|
125
|
+
/** The positionwise structural-shape tuple of a projection over `S`. */
|
|
126
|
+
type ShapesOf<S extends FaceSource, P extends readonly string[]> = {
|
|
127
|
+
readonly [I in keyof P]: ProjectedShape<S, P[I] & string>;
|
|
89
128
|
};
|
|
90
|
-
/** The
|
|
91
|
-
type
|
|
129
|
+
/** The shape tuple a face projects, positionwise — the comparand of {@link SameShapes}. */
|
|
130
|
+
type FaceShapes<F extends AnyFace> = F extends Face<infer S, infer P> ? ShapesOf<S, P> : never;
|
|
92
131
|
/** The projection arity of a face. */
|
|
93
132
|
type Arity<F extends AnyFace> = F["projection"]["length"];
|
|
94
133
|
/**
|
|
@@ -109,25 +148,31 @@ interface FaceArityMismatch<Left, Right> {
|
|
|
109
148
|
*/
|
|
110
149
|
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>>;
|
|
111
150
|
/**
|
|
112
|
-
* The legible
|
|
113
|
-
* bijection, or window project
|
|
114
|
-
* this type is intersected into the second face's parameter and
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
151
|
+
* The legible shape-mismatch verdict: when the two faces of a containment,
|
|
152
|
+
* bijection, or window project structurally incompatible fields at any
|
|
153
|
+
* position, this type is intersected into the second face's parameter and
|
|
154
|
+
* names both shape tuples — a u64 face against a str face, a bytes width
|
|
155
|
+
* mismatch, an interval element mismatch, or a bare column against a
|
|
156
|
+
* closed reference (the roster slot) is a COMPILE error.
|
|
118
157
|
*/
|
|
119
|
-
interface
|
|
120
|
-
readonly "face
|
|
158
|
+
interface FaceShapeMismatch<Left, Right> {
|
|
159
|
+
readonly "face shape mismatch — positionwise kind, width, element, and closed roster must be equal on both sides": readonly [
|
|
160
|
+
Left,
|
|
161
|
+
Right
|
|
162
|
+
];
|
|
121
163
|
}
|
|
122
164
|
/**
|
|
123
165
|
* Resolves to `unknown` (a no-op intersection) when the two faces project
|
|
124
|
-
* positionwise-equal
|
|
125
|
-
* otherwise. Equality is mutual tuple assignability over
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
166
|
+
* positionwise-equal structural shapes, and to {@link FaceShapeMismatch}
|
|
167
|
+
* otherwise. Equality is mutual tuple assignability over the
|
|
168
|
+
* kind/width/element/roster quadruples. This is the whole
|
|
169
|
+
* construction-time wall — deliberately: there is no domain to compare
|
|
170
|
+
* here (the roster is descriptor STRUCTURE, not a domain). The domain wall
|
|
171
|
+
* lives where domains are BORN: `schema()` computes every field's class
|
|
172
|
+
* from the statement list and holds the one-generator-per-class law, and
|
|
173
|
+
* query joins compare class names off the schema type.
|
|
129
174
|
*/
|
|
130
|
-
type
|
|
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>>;
|
|
131
176
|
/**
|
|
132
177
|
* Projects a face — one spelling, arity-generic: `on(Account, "holder")`
|
|
133
178
|
* for the common single-field position, `on(Booking, ["room", "during"])`
|
|
@@ -146,6 +191,6 @@ declare function on<S extends FaceSource, const P extends readonly [FaceFields<S
|
|
|
146
191
|
* renderer's own shape, `schema/render.rs`).
|
|
147
192
|
*/
|
|
148
193
|
declare function renderFace(face: FaceData): string;
|
|
149
|
-
export type { AnyFace, Arity, Face, FaceArityMismatch, FaceData,
|
|
150
|
-
export { on,
|
|
194
|
+
export type { AnyFace, Arity, Face, FaceArityMismatch, FaceData, FaceFields, FaceOwner, FaceShapeMismatch, FaceShapes, FaceSource, OwnerOf, SameArity, SameShapes };
|
|
195
|
+
export { on, renderFace };
|
|
151
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;;;;;;;;;;;;;;;;;;;GAmBG;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,cA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AAC,CAAC,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAC7F,MAAM,EAAE,CAAC,EACT,MAAM,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,OAAO,EACP,SAAS,EACT,UAAU,EACV,CAAA;AACD,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/face.js
CHANGED
|
@@ -4,22 +4,30 @@
|
|
|
4
4
|
* position, `on(Booking, ["room", "during"])` the composite/pointwise
|
|
5
5
|
* position (one spelling, arity-generic), `on(Account.where({ kind:
|
|
6
6
|
* Kind.Savings }), "id")` the σ-carrying source, `on(Kind, "id")` a closed
|
|
7
|
-
* relation's sealed shape opened through its synthetic `id
|
|
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
|
|
8
11
|
* positional: tuple order is preserved in the type, and the statement
|
|
9
12
|
* constructors pair the two sides' tuples by arity ({@link SameArity}) AND
|
|
10
|
-
* by
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* by structural shape ({@link SameShapes}) — every projected field's
|
|
14
|
+
* kind/width/element/roster quadruple is read off the schema type (the
|
|
15
|
+
* minimal kernel: descriptors are pure structure, and a closed reference's
|
|
16
|
+
* roster IS part of that structure) and compared positionwise. There is no
|
|
17
|
+
* domain to compare at construction — domains are LAW-BORN: the statements
|
|
18
|
+
* themselves define the equivalence classes, and `schema()` is where they
|
|
19
|
+
* aggregate and get judged (the one-generator-per-class wall).
|
|
14
20
|
*/
|
|
21
|
+
import * as errors from "@superbuilders/errors";
|
|
15
22
|
import { renderLiteralSet } from "#spec.ts";
|
|
16
23
|
/** The empty σ of a selection-free face, shared by every bare projection. */
|
|
17
24
|
const emptySelection = Object.freeze([]);
|
|
18
25
|
/**
|
|
19
|
-
* Splits a face source into its owner and σ: a selected relation
|
|
20
|
-
* its own bindings (`relation` is the
|
|
21
|
-
* no relation or closed value, and
|
|
22
|
-
* handle collisions); a bare relation
|
|
26
|
+
* Splits a face source into its owner and σ: a selected relation — ordinary
|
|
27
|
+
* σ or closed ψ, one shape — carries its own bindings (`relation` is the
|
|
28
|
+
* discriminant — the property exists on no relation or closed value, and
|
|
29
|
+
* `closed()` reserves the name against handle collisions); a bare relation
|
|
30
|
+
* or closed relation carries none.
|
|
23
31
|
*/
|
|
24
32
|
function faceParts(source) {
|
|
25
33
|
if ("relation" in source) {
|
|
@@ -27,16 +35,6 @@ function faceParts(source) {
|
|
|
27
35
|
}
|
|
28
36
|
return { owner: source, selection: emptySelection };
|
|
29
37
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Constructs a literal set (read disjunctively) for a `where()` binding.
|
|
32
|
-
* Two leading arguments by signature: the degenerate sets have no spelling
|
|
33
|
-
* (the canonical-utterance law, `docs/architecture/70-api.md`).
|
|
34
|
-
*/
|
|
35
|
-
function oneOf(first, second, ...rest) {
|
|
36
|
-
const literals = [first, second, ...rest];
|
|
37
|
-
Object.freeze(literals);
|
|
38
|
-
return Object.freeze({ literals });
|
|
39
|
-
}
|
|
40
38
|
function on(source, fields) {
|
|
41
39
|
const projection = Object.freeze(typeof fields === "string" ? [fields] : [...fields]);
|
|
42
40
|
const parts = faceParts(source);
|
|
@@ -45,7 +43,26 @@ function on(source, fields) {
|
|
|
45
43
|
projection,
|
|
46
44
|
selection: parts.selection
|
|
47
45
|
});
|
|
48
|
-
|
|
46
|
+
const value = Object.freeze({ source, projection, data });
|
|
47
|
+
if (!faceMinted(value, source, projection)) {
|
|
48
|
+
throw errors.new(`face over ${parts.owner.name}: face construction incomplete`);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The trusted seam of the face mint (the `refsComplete` pattern): the
|
|
54
|
+
* checkable facts — the value carries exactly the source and projection it
|
|
55
|
+
* was built from, and `data.owner` is exactly the owner {@link faceParts}
|
|
56
|
+
* resolves for that source — are verified before the wide construction is
|
|
57
|
+
* admitted at the exact {@link Face} type (whose `data` claims the owner at
|
|
58
|
+
* its precise type, the carrier the schema-level law-typing reads).
|
|
59
|
+
*/
|
|
60
|
+
function faceMinted(value, source, projection) {
|
|
61
|
+
const owner = "relation" in source ? source.relation : source;
|
|
62
|
+
return (value.source === source &&
|
|
63
|
+
value.projection === projection &&
|
|
64
|
+
value.data.owner === owner &&
|
|
65
|
+
value.data.projection === projection);
|
|
49
66
|
}
|
|
50
67
|
/**
|
|
51
68
|
* Renders one face in the exact macro notation — `Name(p1, p2 | f == lit,
|
|
@@ -64,5 +81,5 @@ function renderFace(face) {
|
|
|
64
81
|
.join(", ");
|
|
65
82
|
return `${face.owner.name}(${projection} | ${bindings})`;
|
|
66
83
|
}
|
|
67
|
-
export { on,
|
|
84
|
+
export { on, renderFace };
|
|
68
85
|
//# sourceMappingURL=face.js.map
|
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;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAI/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE3C,6EAA6E;AAC7E,MAAM,cAAc,GAAgC,MAAM,CAA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