@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/src/statements.ts
CHANGED
|
@@ -7,12 +7,16 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Every field reference is checked against the relation it names in the
|
|
9
9
|
* TYPE — existence through {@link FaceFields} (`on(R, "nope")` does not
|
|
10
|
-
* compile) and
|
|
11
|
-
* faces' projected
|
|
12
|
-
* (
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
10
|
+
* compile) and STRUCTURAL compatibility through {@link SameShapes}: the two
|
|
11
|
+
* faces' projected kind/width/element triples are read off the schema type
|
|
12
|
+
* (the minimal kernel — descriptors are pure structure) and constrained
|
|
13
|
+
* positionwise equal, so a u64 face against a str face, a bytes width
|
|
14
|
+
* mismatch, or an interval element mismatch is a compile error. Domains are
|
|
15
|
+
* NOT compared here — there is no domain to compare at construction: the
|
|
16
|
+
* statements themselves are what define the equivalence classes, and the
|
|
17
|
+
* domain wall lives where they aggregate — `schema()` (the
|
|
18
|
+
* one-generator-per-class law) and query joins (class names off the schema
|
|
19
|
+
* type). What is only a SEMANTIC property — the target side of a
|
|
16
20
|
* containment resolving a declared key of its relation — is DELIBERATELY
|
|
17
21
|
* not (and cannot be) stated here: whether `B(y)` is a key of `B` depends
|
|
18
22
|
* on which `key()` statements the surrounding `schema()` collects, a set no
|
|
@@ -23,7 +27,7 @@
|
|
|
23
27
|
|
|
24
28
|
import * as errors from "@superbuilders/errors"
|
|
25
29
|
import type { Count } from "#count.ts"
|
|
26
|
-
import { type AnyFace, type FaceData, renderFace, type SameArity, type
|
|
30
|
+
import { type AnyFace, type FaceData, renderFace, type SameArity, type SameShapes } from "#face.ts"
|
|
27
31
|
import type { AnyRelation, RelationFields } from "#relation.ts"
|
|
28
32
|
import { renderWindow, type WindowSpec } from "#spec.ts"
|
|
29
33
|
|
|
@@ -34,34 +38,60 @@ interface KeyData<R extends AnyRelation, Projection extends readonly string[]> {
|
|
|
34
38
|
readonly projection: Projection
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
/**
|
|
42
|
+
* A containment statement's runtime description — the two faces carried at
|
|
43
|
+
* their EXACT types (owner names and projection tuples are honest runtime
|
|
44
|
+
* properties, and they are the type-level carrier `schema()`'s law-typing
|
|
45
|
+
* pairs slots through). The defaults are the wide shape renderers and the
|
|
46
|
+
* wire lowering consume.
|
|
47
|
+
*/
|
|
48
|
+
interface ContainmentData<Src extends FaceData = FaceData, Tgt extends FaceData = FaceData> {
|
|
49
|
+
readonly kind: "containment"
|
|
50
|
+
readonly source: Src
|
|
51
|
+
readonly target: Tgt
|
|
52
|
+
readonly bidirectional: boolean
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A window statement's runtime description — target-left, faces at exact types like {@link ContainmentData}. */
|
|
56
|
+
interface WindowData<Tgt extends FaceData = FaceData, Src extends FaceData = FaceData> {
|
|
57
|
+
readonly kind: "window"
|
|
58
|
+
readonly target: Tgt
|
|
59
|
+
readonly window: WindowSpec
|
|
60
|
+
readonly source: Src
|
|
61
|
+
}
|
|
62
|
+
|
|
37
63
|
/** One statement's runtime description, tagged by form. */
|
|
38
|
-
type StatementData =
|
|
39
|
-
| KeyData<AnyRelation, readonly string[]>
|
|
40
|
-
| {
|
|
41
|
-
readonly kind: "containment"
|
|
42
|
-
readonly source: FaceData
|
|
43
|
-
readonly target: FaceData
|
|
44
|
-
readonly bidirectional: boolean
|
|
45
|
-
}
|
|
46
|
-
| {
|
|
47
|
-
readonly kind: "window"
|
|
48
|
-
readonly target: FaceData
|
|
49
|
-
readonly window: WindowSpec
|
|
50
|
-
readonly source: FaceData
|
|
51
|
-
}
|
|
64
|
+
type StatementData = KeyData<AnyRelation, readonly string[]> | ContainmentData | WindowData
|
|
52
65
|
|
|
53
66
|
/** An opaque statement value — what `schema()` assembles into a theory. */
|
|
54
67
|
interface Statement {
|
|
55
68
|
readonly data: StatementData
|
|
56
69
|
}
|
|
57
70
|
|
|
71
|
+
/**
|
|
72
|
+
* A containment (or `==` bijection) statement as a TYPED value: `data`
|
|
73
|
+
* carries both faces at their exact types, so the schema-level class laws
|
|
74
|
+
* can read every paired (relation, field) slot off the statement type —
|
|
75
|
+
* spell the statement list inline in `schema()` and the equivalence
|
|
76
|
+
* classes compute at the type level too. Structurally still a plain
|
|
77
|
+
* {@link Statement}.
|
|
78
|
+
*/
|
|
79
|
+
interface ContainedStatement<Src extends FaceData, Tgt extends FaceData> extends Statement {
|
|
80
|
+
readonly data: ContainmentData<Src, Tgt>
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A window statement as a TYPED value — the {@link ContainedStatement} of the window form. */
|
|
84
|
+
interface WindowStatement<Tgt extends FaceData, Src extends FaceData> extends Statement {
|
|
85
|
+
readonly data: WindowData<Tgt, Src>
|
|
86
|
+
}
|
|
87
|
+
|
|
58
88
|
/**
|
|
59
89
|
* A `key()` statement as a TYPED value: its `data` carries the owner
|
|
60
90
|
* relation and the projection tuple at their EXACT types (honest runtime
|
|
61
91
|
* properties — no phantom), which is what the key-statement-selected
|
|
62
92
|
* `get(relation, keyStatement, key)` overload types its key object by
|
|
63
93
|
* (`docs/architecture/70-api.md` § the freeze, the multi-key typed get) and
|
|
64
|
-
* what resolves each projected field's
|
|
94
|
+
* what resolves each projected field's descriptor through the owner's
|
|
65
95
|
* schema type. Structurally still a plain {@link Statement}.
|
|
66
96
|
*/
|
|
67
97
|
interface KeyStatement<R extends AnyRelation, Projection extends readonly string[]> extends Statement {
|
|
@@ -76,7 +106,7 @@ interface KeyStatement<R extends AnyRelation, Projection extends readonly string
|
|
|
76
106
|
* explicit one would only ever be a duplicate. Every projected name is
|
|
77
107
|
* checked against `R`'s field block in the type, and the tuple is carried
|
|
78
108
|
* in the returned value's type ({@link KeyStatement}) — keyed point reads
|
|
79
|
-
* through THIS statement are typed field-for-field,
|
|
109
|
+
* through THIS statement are typed field-for-field, descriptors resolvable
|
|
80
110
|
* through the owner's schema type.
|
|
81
111
|
*/
|
|
82
112
|
function key<
|
|
@@ -98,18 +128,18 @@ function key<
|
|
|
98
128
|
|
|
99
129
|
/**
|
|
100
130
|
* `A(X|φ) <= B(Y|ψ)` — conditional inclusion, source left. Arity mismatch
|
|
101
|
-
* between the two faces is a type error ({@link SameArity}); a
|
|
102
|
-
* pair is a type error ({@link
|
|
103
|
-
* equality of the projected
|
|
104
|
-
* resolve a declared key of B — a SEMANTIC property of the whole
|
|
105
|
-
* set that no face type can state, DELIBERATELY judged by the
|
|
106
|
-
* `Db.create`/`Db.open` (`SchemaError`), never re-checked here.
|
|
131
|
+
* between the two faces is a type error ({@link SameArity}); a structurally
|
|
132
|
+
* mismatched pair is a type error ({@link SameShapes} — positionwise
|
|
133
|
+
* equality of the projected kind/width/element triples). The target side
|
|
134
|
+
* must resolve a declared key of B — a SEMANTIC property of the whole
|
|
135
|
+
* statement set that no face type can state, DELIBERATELY judged by the
|
|
136
|
+
* engine at `Db.create`/`Db.open` (`SchemaError`), never re-checked here.
|
|
107
137
|
*/
|
|
108
138
|
function contained<A extends AnyFace, B extends AnyFace>(
|
|
109
139
|
source: A,
|
|
110
|
-
target: B & SameArity<A, B> &
|
|
111
|
-
):
|
|
112
|
-
const data:
|
|
140
|
+
target: B & SameArity<A, B> & SameShapes<A, B>
|
|
141
|
+
): ContainedStatement<A["data"], B["data"]> {
|
|
142
|
+
const data: ContainmentData<A["data"], B["data"]> = Object.freeze({
|
|
113
143
|
kind: "containment",
|
|
114
144
|
source: source.data,
|
|
115
145
|
target: target.data,
|
|
@@ -124,14 +154,14 @@ function contained<A extends AnyFace, B extends AnyFace>(
|
|
|
124
154
|
* two faces (each side contains the other). It lowers to the two adjacent
|
|
125
155
|
* containments in the `A <= B` first order (macro parity — the engine
|
|
126
156
|
* performs the split, source-first) and renders as `==` once, in the
|
|
127
|
-
* written orientation. Faces pair by arity AND
|
|
128
|
-
* {@link contained}.
|
|
157
|
+
* written orientation. Faces pair by arity AND structural shape, exactly
|
|
158
|
+
* as {@link contained}.
|
|
129
159
|
*/
|
|
130
160
|
function mirrors<A extends AnyFace, B extends AnyFace>(
|
|
131
161
|
source: A,
|
|
132
|
-
target: B & SameArity<A, B> &
|
|
133
|
-
):
|
|
134
|
-
const data:
|
|
162
|
+
target: B & SameArity<A, B> & SameShapes<A, B>
|
|
163
|
+
): ContainedStatement<A["data"], B["data"]> {
|
|
164
|
+
const data: ContainmentData<A["data"], B["data"]> = Object.freeze({
|
|
135
165
|
kind: "containment",
|
|
136
166
|
source: source.data,
|
|
137
167
|
target: target.data,
|
|
@@ -146,15 +176,16 @@ function mirrors<A extends AnyFace, B extends AnyFace>(
|
|
|
146
176
|
* target-left — macro parity), and the RIGHT face is the counted source.
|
|
147
177
|
* `window(on(Holder, "id"), atMost(3n), on(Account, "holder"))` says: each
|
|
148
178
|
* Holder id groups at most three Account rows by holder. The two faces
|
|
149
|
-
* pair by arity AND
|
|
150
|
-
* the grouping join reads the same positionwise field
|
|
179
|
+
* pair by arity AND structural shape ({@link SameShapes}), exactly as
|
|
180
|
+
* containment — the grouping join reads the same positionwise field
|
|
181
|
+
* pairing.
|
|
151
182
|
*/
|
|
152
183
|
function window<B extends AnyFace, A extends AnyFace>(
|
|
153
184
|
target: B,
|
|
154
185
|
count: Count,
|
|
155
|
-
source: A & SameArity<B, A> &
|
|
156
|
-
):
|
|
157
|
-
const data:
|
|
186
|
+
source: A & SameArity<B, A> & SameShapes<B, A>
|
|
187
|
+
): WindowStatement<B["data"], A["data"]> {
|
|
188
|
+
const data: WindowData<B["data"], A["data"]> = Object.freeze({
|
|
158
189
|
kind: "window",
|
|
159
190
|
target: target.data,
|
|
160
191
|
window: count.window,
|
|
@@ -187,5 +218,14 @@ function renderStatement(statement: Statement): string {
|
|
|
187
218
|
}
|
|
188
219
|
}
|
|
189
220
|
|
|
190
|
-
export type {
|
|
221
|
+
export type {
|
|
222
|
+
ContainedStatement,
|
|
223
|
+
ContainmentData,
|
|
224
|
+
KeyData,
|
|
225
|
+
KeyStatement,
|
|
226
|
+
Statement,
|
|
227
|
+
StatementData,
|
|
228
|
+
WindowData,
|
|
229
|
+
WindowStatement
|
|
230
|
+
}
|
|
191
231
|
export { contained, key, mirrors, renderStatement, window }
|