@bjornpagen/bumbledb 0.4.0 → 0.6.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 +191 -92
- package/README.md +9 -7
- package/dist/closed.d.ts +30 -2
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +66 -20
- package/dist/closed.js.map +1 -1
- package/dist/db.d.ts +33 -6
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +89 -72
- package/dist/db.js.map +1 -1
- package/dist/exhume.d.ts.map +1 -1
- package/dist/exhume.js +1 -14
- package/dist/exhume.js.map +1 -1
- package/dist/face.d.ts +1 -1
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +2 -1
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +18 -1
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +44 -16
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +18 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/law.d.ts +2 -1
- package/dist/law.d.ts.map +1 -1
- package/dist/law.js +15 -14
- package/dist/law.js.map +1 -1
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +1 -7
- package/dist/lower.js.map +1 -1
- package/dist/marshal.d.ts.map +1 -1
- package/dist/marshal.js +15 -27
- package/dist/marshal.js.map +1 -1
- package/dist/native.d.ts +21 -2
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +20 -3
- package/dist/native.js.map +1 -1
- package/dist/order.d.ts +36 -0
- package/dist/order.d.ts.map +1 -0
- package/dist/order.js +135 -0
- package/dist/order.js.map +1 -0
- package/dist/query/atom.d.ts +140 -206
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +33 -52
- package/dist/query/atom.js.map +1 -1
- package/dist/query/find.d.ts +116 -0
- package/dist/query/find.d.ts.map +1 -0
- package/dist/query/{select.js → find.js} +22 -22
- package/dist/query/find.js.map +1 -0
- package/dist/query/lower.d.ts +124 -162
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +462 -507
- package/dist/query/lower.js.map +1 -1
- package/dist/query/predicate.d.ts +22 -14
- package/dist/query/predicate.d.ts.map +1 -1
- package/dist/query/predicate.js +45 -20
- package/dist/query/predicate.js.map +1 -1
- package/dist/query/run.d.ts +3 -3
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +10 -11
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +124 -83
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +77 -70
- package/dist/query/scope.js.map +1 -1
- package/dist/relation.d.ts +9 -22
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +9 -28
- package/dist/relation.js.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +7 -31
- package/dist/schema.js.map +1 -1
- package/dist/statements.d.ts +5 -2
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +30 -35
- package/dist/statements.js.map +1 -1
- package/package.json +2 -5
- package/src/closed.ts +73 -28
- package/src/db.ts +126 -88
- package/src/exhume.ts +1 -15
- package/src/face.ts +4 -3
- package/src/fields.ts +58 -16
- package/src/index.ts +19 -13
- package/src/law.ts +15 -14
- package/src/lower.ts +2 -9
- package/src/marshal.ts +15 -31
- package/src/native.ts +22 -4
- package/src/order.ts +156 -0
- package/src/query/atom.ts +186 -276
- package/src/query/find.ts +212 -0
- package/src/query/lower.ts +614 -749
- package/src/query/predicate.ts +47 -20
- package/src/query/run.ts +11 -13
- package/src/query/scope.ts +165 -132
- package/src/relation.ts +9 -51
- package/src/schema.ts +7 -33
- package/src/statements.ts +33 -38
- package/dist/query/select.d.ts +0 -128
- package/dist/query/select.d.ts.map +0 -1
- package/dist/query/select.js.map +0 -1
- package/src/query/select.ts +0 -215
package/dist/closed.d.ts
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* shape.
|
|
31
31
|
*/
|
|
32
32
|
import { type AnyField, type ClosedIdField, type Infer } from "#fields.ts";
|
|
33
|
+
import type { AnyRelation, RelationField } from "#relation.ts";
|
|
33
34
|
import { type SelectionBinding, type SelectionInput } from "#relation.ts";
|
|
34
35
|
import type { LiteralSpec } from "#spec.ts";
|
|
35
36
|
/**
|
|
@@ -44,7 +45,7 @@ type PayloadField = Exclude<AnyField, {
|
|
|
44
45
|
* unspellable — the sealed shape mints the synthetic `id` itself (ordinal
|
|
45
46
|
* 0 of the matchable fields), so a declared column named `id` would be
|
|
46
47
|
* shadowed by the synthetic slot everywhere the shape resolves by name
|
|
47
|
-
* (`
|
|
48
|
+
* (`sealedFieldsOf`, the projected face, `spec.rs`'s resolver). The wall is
|
|
48
49
|
* typed here and judged again at construction in {@link mintClosed} — the
|
|
49
50
|
* runtime twin for untyped callers, warmer and earlier than the engine's
|
|
50
51
|
* `DuplicateFieldName` at `Db.create`.
|
|
@@ -173,6 +174,33 @@ interface AnyClosed {
|
|
|
173
174
|
readonly axioms: Readonly<Record<string, object>>;
|
|
174
175
|
readonly columns: Readonly<Record<string, PayloadField>>;
|
|
175
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* THE relation-kind discriminant — the ONE spelling of "is this schema
|
|
179
|
+
* member closed?" (the type tier's twin is the `AnyClosed` conditional
|
|
180
|
+
* arms). A closed relation's runtime description carries its handle
|
|
181
|
+
* roster; an ordinary relation's never does. Every runtime closed/ordinary
|
|
182
|
+
* fork in the SDK judges through this predicate — never a re-spelled
|
|
183
|
+
* structural probe.
|
|
184
|
+
*/
|
|
185
|
+
declare function isClosedMember(member: AnyRelation | AnyClosed): member is AnyClosed;
|
|
186
|
+
/**
|
|
187
|
+
* The SEALED field list of a schema member — THE one reader of "what
|
|
188
|
+
* fields does this owner expose": an ordinary relation's declared fields;
|
|
189
|
+
* a closed relation's sealed shape — the synthetic `id` (the value's own
|
|
190
|
+
* roster-carrying descriptor, by identity) at ordinal 0, then the declared
|
|
191
|
+
* payload columns at declared index + 1 (the sealed shift, mirroring the
|
|
192
|
+
* engine's `SchemaDescriptor::sealed_fields`). A `ClosedColumn` is
|
|
193
|
+
* structurally a `RelationField`, so both kinds read uniformly.
|
|
194
|
+
*/
|
|
195
|
+
declare function sealedFieldsOf(member: AnyRelation | AnyClosed): readonly RelationField[];
|
|
196
|
+
/**
|
|
197
|
+
* One sealed field by name — derived from {@link sealedFieldsOf}, so the
|
|
198
|
+
* closed synthetic `id` resolves everywhere a name is looked up (no reader
|
|
199
|
+
* can silently lack the `id` arm). `undefined` when the name is foreign
|
|
200
|
+
* (the type tiers make that unwritable; the engine re-judges at
|
|
201
|
+
* `Db.create`).
|
|
202
|
+
*/
|
|
203
|
+
declare function sealedFieldOf(member: AnyRelation | AnyClosed, fieldName: string): AnyField | undefined;
|
|
176
204
|
/** Bare tier: `closed("Kind", ["Checking", "Savings"])` — handles only. */
|
|
177
205
|
declare function closed<const Name extends string, const Handles extends readonly [string, ...string[]]>(name: Name, handles: Handles): Closed<Name, Handles[number], Record<never, never>>;
|
|
178
206
|
/**
|
|
@@ -189,5 +217,5 @@ declare function closed<const Name extends string, const Handles extends readonl
|
|
|
189
217
|
*/
|
|
190
218
|
declare function closed<const Name extends string, const Cols extends PayloadColumns, Handles extends string>(name: Name, columns: Cols, axioms: Axioms<Handles, Cols>): Closed<Name, Handles, Cols>;
|
|
191
219
|
export type { AnyClosed, AnySelectedClosed, AxiomRow, Axioms, Closed, ClosedColumn, ClosedCore, ClosedData, ClosedRow, ClosedSelectable, ClosedSelectionInput, PayloadField, SelectedClosed };
|
|
192
|
-
export { closed };
|
|
220
|
+
export { closed, isClosedMember, sealedFieldOf, sealedFieldsOf };
|
|
193
221
|
//# sourceMappingURL=closed.d.ts.map
|
package/dist/closed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closed.d.ts","sourceRoot":"","sources":["../src/closed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,KAAK,CAAC,OAAO,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAC9F,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,GACd,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,iBAAS,MAAM,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,KAAK,CAAC,IAAI,SAAS,cAAc,EAAE,OAAO,SAAS,MAAM,EACnG,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,IAAI,EACb,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,GAC3B,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;AA6K9B,YAAY,EACX,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,MAAM,EACN,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,CAAA;AACD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,CAAA"}
|
package/dist/closed.js
CHANGED
|
@@ -32,6 +32,45 @@
|
|
|
32
32
|
import * as errors from "@superbuilders/errors";
|
|
33
33
|
import { assertDeclarationOrderKey, literalOf } from "#fields.ts";
|
|
34
34
|
import { resolveSelection } from "#relation.ts";
|
|
35
|
+
/**
|
|
36
|
+
* THE relation-kind discriminant — the ONE spelling of "is this schema
|
|
37
|
+
* member closed?" (the type tier's twin is the `AnyClosed` conditional
|
|
38
|
+
* arms). A closed relation's runtime description carries its handle
|
|
39
|
+
* roster; an ordinary relation's never does. Every runtime closed/ordinary
|
|
40
|
+
* fork in the SDK judges through this predicate — never a re-spelled
|
|
41
|
+
* structural probe.
|
|
42
|
+
*/
|
|
43
|
+
function isClosedMember(member) {
|
|
44
|
+
return "handles" in member.data;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The SEALED field list of a schema member — THE one reader of "what
|
|
48
|
+
* fields does this owner expose": an ordinary relation's declared fields;
|
|
49
|
+
* a closed relation's sealed shape — the synthetic `id` (the value's own
|
|
50
|
+
* roster-carrying descriptor, by identity) at ordinal 0, then the declared
|
|
51
|
+
* payload columns at declared index + 1 (the sealed shift, mirroring the
|
|
52
|
+
* engine's `SchemaDescriptor::sealed_fields`). A `ClosedColumn` is
|
|
53
|
+
* structurally a `RelationField`, so both kinds read uniformly.
|
|
54
|
+
*/
|
|
55
|
+
function sealedFieldsOf(member) {
|
|
56
|
+
if (isClosedMember(member)) {
|
|
57
|
+
return Object.freeze([Object.freeze({ name: "id", field: member.id }), ...member.data.columns]);
|
|
58
|
+
}
|
|
59
|
+
return member.data.fields;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* One sealed field by name — derived from {@link sealedFieldsOf}, so the
|
|
63
|
+
* closed synthetic `id` resolves everywhere a name is looked up (no reader
|
|
64
|
+
* can silently lack the `id` arm). `undefined` when the name is foreign
|
|
65
|
+
* (the type tiers make that unwritable; the engine re-judges at
|
|
66
|
+
* `Db.create`).
|
|
67
|
+
*/
|
|
68
|
+
function sealedFieldOf(member, fieldName) {
|
|
69
|
+
const declared = sealedFieldsOf(member).find(function byName(candidate) {
|
|
70
|
+
return candidate.name === fieldName;
|
|
71
|
+
});
|
|
72
|
+
return declared?.field;
|
|
73
|
+
}
|
|
35
74
|
/** Narrows the two-tier second argument: a handle tuple (bare tier) or a column block (payload tier). */
|
|
36
75
|
function isHandleTuple(shape) {
|
|
37
76
|
return Array.isArray(shape);
|
|
@@ -51,7 +90,8 @@ function handleKeysOwn(axioms, names) {
|
|
|
51
90
|
* The trusted seam of the axiom-readback mint: every handle carries an own
|
|
52
91
|
* frozen row and every row carries every declared column as an own
|
|
53
92
|
* property — verified before the record is admitted as the typed
|
|
54
|
-
* {@link Axioms} (the
|
|
93
|
+
* {@link Axioms} (the trusted-admission-seam pattern — its home is
|
|
94
|
+
* `isTypedScope` in query/lower.ts).
|
|
55
95
|
*/
|
|
56
96
|
function axiomsMinted(record, handles, cols) {
|
|
57
97
|
return handles.every(function rowMinted(handle) {
|
|
@@ -62,28 +102,17 @@ function axiomsMinted(record, handles, cols) {
|
|
|
62
102
|
}));
|
|
63
103
|
});
|
|
64
104
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Reads one handle's ground axiom row for lowering. The typed payload
|
|
67
|
-
* surface makes absence unrepresentable ({@link Axioms} carries every
|
|
68
|
-
* handle's row); the refusal below guards the one ill-typed path — payload
|
|
69
|
-
* columns with the bare tier's absent axioms — which no public spelling
|
|
70
|
-
* reaches.
|
|
71
|
-
*/
|
|
72
|
-
function groundRow(name, axioms, handle) {
|
|
73
|
-
if (axioms === undefined) {
|
|
74
|
-
throw errors.new(`closed relation ${name}: payload columns declared without ground axioms`);
|
|
75
|
-
}
|
|
76
|
-
return axioms[handle];
|
|
77
|
-
}
|
|
78
105
|
/**
|
|
79
106
|
* Mints the axiom-readback record: one own frozen row per handle (the bare
|
|
80
107
|
* tier's rows are empty — it declares no columns), each row a fresh copy of
|
|
81
|
-
* its ground axiom.
|
|
108
|
+
* its ground axiom. Both tiers supply a REAL axioms record ({@link
|
|
109
|
+
* closedBare} mints its empty rows), so the columns-without-axioms state is
|
|
110
|
+
* unrepresentable here — no undefined arm exists to guard.
|
|
82
111
|
*/
|
|
83
112
|
function mintAxioms(name, handles, cols, axioms) {
|
|
84
113
|
const out = {};
|
|
85
114
|
for (const handle of handles) {
|
|
86
|
-
const row =
|
|
115
|
+
const row = Object.freeze({ ...axioms[handle] });
|
|
87
116
|
Object.defineProperty(out, handle, { value: row, enumerable: true });
|
|
88
117
|
}
|
|
89
118
|
Object.freeze(out);
|
|
@@ -104,9 +133,26 @@ function closed(name, shape, axioms) {
|
|
|
104
133
|
}
|
|
105
134
|
return closedPayload(name, shape, axioms);
|
|
106
135
|
}
|
|
107
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* The bare tier's precisely-typed builder: no columns, and the axioms
|
|
138
|
+
* record is the EMPTY-ROW record over the handle roster (one own frozen
|
|
139
|
+
* `{}` per handle, `__proto__`-safe own-property definition) — the same
|
|
140
|
+
* representation the payload tier carries, so `mintClosed` never sees a
|
|
141
|
+
* tier fork and the columns-without-axioms state stops being spellable.
|
|
142
|
+
*/
|
|
108
143
|
function closedBare(name, handles) {
|
|
109
|
-
|
|
144
|
+
const empty = {};
|
|
145
|
+
for (const handle of handles) {
|
|
146
|
+
/** A duplicated name mints one row; the roster's own duplicate refusal in {@link mintClosed} stays the judge. */
|
|
147
|
+
if (!Object.hasOwn(empty, handle)) {
|
|
148
|
+
Object.defineProperty(empty, handle, { value: Object.freeze({}), enumerable: true });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
Object.freeze(empty);
|
|
152
|
+
if (!axiomsMinted(empty, handles, [])) {
|
|
153
|
+
throw errors.new(`closed relation ${name}: bare-tier axiom-row minting incomplete`);
|
|
154
|
+
}
|
|
155
|
+
return mintClosed(name, handles, {}, empty);
|
|
110
156
|
}
|
|
111
157
|
/**
|
|
112
158
|
* The payload tier's precisely-typed builder: column names are judged
|
|
@@ -168,8 +214,8 @@ function mintClosed(name, handles, columns, axioms) {
|
|
|
168
214
|
}
|
|
169
215
|
Object.freeze(cols);
|
|
170
216
|
const rows = handleList.map(function lowerRow(handle) {
|
|
217
|
+
const row = axioms[handle];
|
|
171
218
|
const values = cols.map(function lowerAxiomLiteral(column) {
|
|
172
|
-
const row = groundRow(name, axioms, handle);
|
|
173
219
|
return Object.freeze(literalOf(column.field, row[column.name]));
|
|
174
220
|
});
|
|
175
221
|
return Object.freeze({ handle, values: Object.freeze(values) });
|
|
@@ -217,5 +263,5 @@ function mintClosed(name, handles, columns, axioms) {
|
|
|
217
263
|
holder.value = value;
|
|
218
264
|
return value;
|
|
219
265
|
}
|
|
220
|
-
export { closed };
|
|
266
|
+
export { closed, isClosedMember, sealedFieldOf, sealedFieldsOf };
|
|
221
267
|
//# sourceMappingURL=closed.js.map
|
package/dist/closed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closed.js","sourceRoot":"","sources":["../src/closed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAEN,yBAAyB,EAIzB,SAAS,EACT,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"closed.js","sourceRoot":"","sources":["../src/closed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAEN,yBAAyB,EAIzB,SAAS,EACT,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,gBAAgB,EAA8C,MAAM,cAAc,CAAA;AA0J3F;;;;;;;GAOG;AACH,SAAS,cAAc,CAAC,MAA+B;IACtD,OAAO,SAAS,IAAI,MAAM,CAAC,IAAI,CAAA;AAChC,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,MAA+B;IACtD,IAAI,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;IAChG,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAA;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,MAA+B,EAAE,SAAiB;IACxE,MAAM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KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,MAAM,CAAC,GAAG,CAAC,mBAAmB,IAAI,qDAAqD,CAAC,CAAA;QAC/F,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC;YACpB,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SAClE,CAAC,CAAA;IACH,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,CAAA;IACvE,MAAM,KAAK,GACV,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1E,IAAI,CAAC,aAAa,CAAsB,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;QACtD,MAAM,MAAM,CAAC,GAAG,CAAC,mBAAmB,IAAI,wCAAwC,CAAC,CAAA;IAClF,CAAC;IACD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,OAAO,KAAK,CAAA;AACb,CAAC;AAiBD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,CAAA"}
|
package/dist/db.d.ts
CHANGED
|
@@ -290,11 +290,16 @@ interface Db<Rels extends SchemaRelations> {
|
|
|
290
290
|
* The ONE witnessed-write form: snapshot → `fn` (premise reads via
|
|
291
291
|
* `snap`, delta via `tx`) → witnessed commit, which lands only if no
|
|
292
292
|
* state-changing commit intervened since the snapshot. On a moved
|
|
293
|
-
* generation the WHOLE `fn` reruns on a fresh snapshot
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
293
|
+
* generation the WHOLE `fn` reruns on a fresh snapshot: this process
|
|
294
|
+
* holds the store's only write handle, so every generation move is
|
|
295
|
+
* self-inflicted by the host's own interleaved writes, and each rerun
|
|
296
|
+
* witnesses a strictly newer generation — the benign race converges.
|
|
297
|
+
* The loop's honesty bound is {@link WITNESSED_ATTEMPT_CAP}: a callback
|
|
298
|
+
* that moves the generation on EVERY attempt (a plain `db.write` before
|
|
299
|
+
* its first tx verb) would spin forever, so past the cap the typed
|
|
300
|
+
* {@link ErrWitnessedLivelock} is thrown instead of a silent loop (the
|
|
301
|
+
* engine's ruling: the error, never a loop — retry is host policy, and
|
|
302
|
+
* the cap is that policy's own diagnostic). `fn` may decline to commit
|
|
298
303
|
* by returning {@link abandon}`(payload)` — the outcome is then
|
|
299
304
|
* `{ ok: false, abandoned: payload }` and NO commit (not even an empty
|
|
300
305
|
* one) is issued.
|
|
@@ -309,6 +314,28 @@ interface Db<Rels extends SchemaRelations> {
|
|
|
309
314
|
*/
|
|
310
315
|
prepare<Row, Params extends ParamsRecord>(q: Query<Rels, Row, Params>): Prepared<Rels, Row, Params>;
|
|
311
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* The witnessed loop's attempt cap — a generous power of two. Benign
|
|
319
|
+
* self-inflicted contention (the host's own commits landing between an
|
|
320
|
+
* attempt's snapshot and its witnessed begin) converges in a handful of
|
|
321
|
+
* retries because each rerun reads a FRESHER snapshot; a workload that moves
|
|
322
|
+
* the generation on EVERY one of this many consecutive attempts is not
|
|
323
|
+
* converging and never will (see {@link ErrWitnessedLivelock}).
|
|
324
|
+
*/
|
|
325
|
+
declare const WITNESSED_ATTEMPT_CAP = 64;
|
|
326
|
+
/**
|
|
327
|
+
* The typed livelock refusal `writeWitnessed` throws past
|
|
328
|
+
* {@link WITNESSED_ATTEMPT_CAP} attempts: every attempt found the generation
|
|
329
|
+
* moved, which is only sustainable when the callback ITSELF (even
|
|
330
|
+
* indirectly) issues an interleaved plain `db.write` before its first tx
|
|
331
|
+
* verb on every attempt — each rerun then re-moves the generation it is
|
|
332
|
+
* about to witness, forever. That is host-policy pathology, not engine
|
|
333
|
+
* judgment (the engine ships the error, never a loop), so it THROWS rather
|
|
334
|
+
* than returning a result arm. Match with `errors.is`; the remedy is to
|
|
335
|
+
* move the interleaved write out of the callback (or make it first-attempt
|
|
336
|
+
* only — the delta belongs on `tx`, premise reads on `snap`).
|
|
337
|
+
*/
|
|
338
|
+
declare const ErrWitnessedLivelock: Error;
|
|
312
339
|
/**
|
|
313
340
|
* The engine twin of the schema-level class wall, as a matchable value
|
|
314
341
|
* (`errors.is`): the shared lowering rejected a spec whose statement pairs
|
|
@@ -359,5 +386,5 @@ declare const Db: Readonly<{
|
|
|
359
386
|
exhume(storePath: string): Promise<Exhumed>;
|
|
360
387
|
}>;
|
|
361
388
|
export type { Abandon, DeclaredKeyFact, DeltaBuild, MemberRelation, OffendingFact, Prepared, ReadScope, Tx, Violation, WitnessedWriteResult, WriteResult };
|
|
362
|
-
export { abandon, Db, ErrNewtypeMismatch };
|
|
389
|
+
export { abandon, Db, ErrNewtypeMismatch, ErrWitnessedLivelock, WITNESSED_ATTEMPT_CAP };
|
|
363
390
|
//# sourceMappingURL=db.d.ts.map
|
package/dist/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAIzC,OAAO,EAKN,KAAK,OAAO,EAEZ,KAAK,MAAM,EAGX,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAEX,SAAS,EAIT,SAAS,EACT,gBAAgB,EAIhB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,eAAe,QAAQ,MAAM,UAAU,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAG/F;;;;;;;;;;;OAWG;sBACqB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;EAGhD,CAAA;AAEF,YAAY,EACX,OAAO,EACP,eAAe,EACf,UAAU,EACV,cAAc,EACd,aAAa,EACb,QAAQ,EACR,SAAS,EACT,EAAE,EACF,SAAS,EACT,oBAAoB,EACpB,WAAW,EACX,CAAA;AACD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,CAAA"}
|
package/dist/db.js
CHANGED
|
@@ -31,10 +31,12 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import * as path from "node:path";
|
|
33
33
|
import * as errors from "@superbuilders/errors";
|
|
34
|
+
import { isClosedMember, sealedFieldsOf } from "#closed.ts";
|
|
34
35
|
import { exhumeStore } from "#exhume.ts";
|
|
36
|
+
import { rosterOf } from "#fields.ts";
|
|
35
37
|
import { lower } from "#lower.ts";
|
|
36
38
|
import { factOf, handleOf, isFreshField, isMintedFresh, keyRowOf, recordOf, rowOf } from "#marshal.ts";
|
|
37
|
-
import { native } from "#native.ts";
|
|
39
|
+
import { bridged, native } from "#native.ts";
|
|
38
40
|
import { lowerQuery } from "#query/lower.ts";
|
|
39
41
|
import { decodeAnswers, wireParams } from "#query/run.ts";
|
|
40
42
|
/**
|
|
@@ -70,18 +72,6 @@ function isAbandon(value) {
|
|
|
70
72
|
* values stay bare, nothing is asserted.
|
|
71
73
|
*/
|
|
72
74
|
const preparedTypes = Symbol("bumbledb.prepared.types");
|
|
73
|
-
/**
|
|
74
|
-
* The bridge guard: runs one native call and wraps anything it throws —
|
|
75
|
-
* marshal-shape refusals and handle-lifecycle refusals cross as genuine
|
|
76
|
-
* typed failures, never bare foreign errors.
|
|
77
|
-
*/
|
|
78
|
-
function bridged(context, run) {
|
|
79
|
-
const result = errors.trySync(run);
|
|
80
|
-
if (result.error) {
|
|
81
|
-
throw errors.wrap(result.error, context);
|
|
82
|
-
}
|
|
83
|
-
return result.data;
|
|
84
|
-
}
|
|
85
75
|
/**
|
|
86
76
|
* Mirrors the engine's materialized statement order
|
|
87
77
|
* (`SchemaDescriptor::materialized_statements`, pinned by the fingerprint):
|
|
@@ -110,7 +100,7 @@ function materializedEntries(theory) {
|
|
|
110
100
|
function impliedKeyEntries(theory) {
|
|
111
101
|
const entries = [];
|
|
112
102
|
for (const member of Object.values(theory.relations)) {
|
|
113
|
-
if (
|
|
103
|
+
if (isClosedMember(member)) {
|
|
114
104
|
continue;
|
|
115
105
|
}
|
|
116
106
|
for (const declared of member.data.fields) {
|
|
@@ -124,7 +114,7 @@ function impliedKeyEntries(theory) {
|
|
|
124
114
|
}
|
|
125
115
|
}
|
|
126
116
|
for (const member of Object.values(theory.relations)) {
|
|
127
|
-
if (
|
|
117
|
+
if (isClosedMember(member)) {
|
|
128
118
|
entries.push({
|
|
129
119
|
kind: "functionality",
|
|
130
120
|
statement: undefined,
|
|
@@ -188,6 +178,27 @@ function isStatementValue(value) {
|
|
|
188
178
|
const data = value.data;
|
|
189
179
|
return typeof data === "object" && data !== null && "kind" in data;
|
|
190
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* THE one selector dispatch of the `get` overload pair (primary-key vs
|
|
183
|
+
* key-statement, `docs/architecture/70-api.md` § the freeze): judges the
|
|
184
|
+
* middle argument once and hands the narrowed pieces to the chosen
|
|
185
|
+
* continuation. `Db.get` and the read scope's `get` both dispatch through
|
|
186
|
+
* here, so the two mismatch refusals speak with one voice and the symmetry
|
|
187
|
+
* rule (`db.get(...) === db.read(snap => snap.get(...))`) holds by
|
|
188
|
+
* construction.
|
|
189
|
+
*/
|
|
190
|
+
function selectKeyRead(keyOrStatement, declaredKey, byStatement, byPrimary) {
|
|
191
|
+
if (declaredKey !== undefined) {
|
|
192
|
+
if (!isStatementValue(keyOrStatement)) {
|
|
193
|
+
throw errors.new("keyed get takes a key() statement value as its second argument");
|
|
194
|
+
}
|
|
195
|
+
return byStatement(keyOrStatement, declaredKey);
|
|
196
|
+
}
|
|
197
|
+
if (isStatementValue(keyOrStatement)) {
|
|
198
|
+
throw errors.new("keyed get with a statement selector also takes the key object — get(relation, keyStatement, key)");
|
|
199
|
+
}
|
|
200
|
+
return byPrimary(keyOrStatement);
|
|
201
|
+
}
|
|
191
202
|
/** Maps a slot's reversal flag to the violation's `orientation` payload. */
|
|
192
203
|
function orientationOf(reversed) {
|
|
193
204
|
if (reversed === undefined) {
|
|
@@ -198,21 +209,6 @@ function orientationOf(reversed) {
|
|
|
198
209
|
}
|
|
199
210
|
return "written";
|
|
200
211
|
}
|
|
201
|
-
/**
|
|
202
|
-
* The declared field descriptors a violation's offending cells decode
|
|
203
|
-
* through: an ordinary relation's declared fields; a closed relation's
|
|
204
|
-
* SEALED shape — the roster-carrying synthetic `id` (the member's own
|
|
205
|
-
* reference descriptor) plus its payload columns (a `ClosedColumn` is
|
|
206
|
-
* structurally a `RelationField`). This is how {@link openDb}'s
|
|
207
|
-
* `offendingFactOf` reaches the open-time descriptors: the cited relation
|
|
208
|
-
* name resolves to the schema member, and the member carries them.
|
|
209
|
-
*/
|
|
210
|
-
function declaredFieldsOf(member) {
|
|
211
|
-
if ("axioms" in member) {
|
|
212
|
-
return [{ name: "id", field: member.id }, ...member.data.columns];
|
|
213
|
-
}
|
|
214
|
-
return member.data.fields;
|
|
215
|
-
}
|
|
216
212
|
/**
|
|
217
213
|
* Builds the id-resolution tables from the manifest, verifying the SDK's
|
|
218
214
|
* positional mirror against the engine's reported order — any drift
|
|
@@ -280,6 +276,28 @@ const planReclaimer = new FinalizationRegistry(function reclaimPlan(handle) {
|
|
|
280
276
|
* callback on a fresh snapshot. It never escapes the SDK.
|
|
281
277
|
*/
|
|
282
278
|
const generationMovedSignal = errors.new("bumbledb witnessed generation moved");
|
|
279
|
+
/**
|
|
280
|
+
* The witnessed loop's attempt cap — a generous power of two. Benign
|
|
281
|
+
* self-inflicted contention (the host's own commits landing between an
|
|
282
|
+
* attempt's snapshot and its witnessed begin) converges in a handful of
|
|
283
|
+
* retries because each rerun reads a FRESHER snapshot; a workload that moves
|
|
284
|
+
* the generation on EVERY one of this many consecutive attempts is not
|
|
285
|
+
* converging and never will (see {@link ErrWitnessedLivelock}).
|
|
286
|
+
*/
|
|
287
|
+
const WITNESSED_ATTEMPT_CAP = 64;
|
|
288
|
+
/**
|
|
289
|
+
* The typed livelock refusal `writeWitnessed` throws past
|
|
290
|
+
* {@link WITNESSED_ATTEMPT_CAP} attempts: every attempt found the generation
|
|
291
|
+
* moved, which is only sustainable when the callback ITSELF (even
|
|
292
|
+
* indirectly) issues an interleaved plain `db.write` before its first tx
|
|
293
|
+
* verb on every attempt — each rerun then re-moves the generation it is
|
|
294
|
+
* about to witness, forever. That is host-policy pathology, not engine
|
|
295
|
+
* judgment (the engine ships the error, never a loop), so it THROWS rather
|
|
296
|
+
* than returning a result arm. Match with `errors.is`; the remedy is to
|
|
297
|
+
* move the interleaved write out of the callback (or make it first-attempt
|
|
298
|
+
* only — the delta belongs on `tx`, premise reads on `snap`).
|
|
299
|
+
*/
|
|
300
|
+
const ErrWitnessedLivelock = errors.new("bumbledb writeWitnessed livelock: the generation moved on every attempt — the callback itself commits an interleaved write each try, so no snapshot can ever stay current");
|
|
283
301
|
/**
|
|
284
302
|
* Fills one insert's omitted fresh cells through the engine's
|
|
285
303
|
* alloc-then-insert dyn lane (there is no insert-with-omitted-fields wire
|
|
@@ -328,7 +346,7 @@ function openDb(handle, theory, manifest) {
|
|
|
328
346
|
if (entry === undefined || entry.member !== relation) {
|
|
329
347
|
throw errors.new(`relation ${relation.name} is not a member of schema ${theory.name}`);
|
|
330
348
|
}
|
|
331
|
-
if (
|
|
349
|
+
if (isClosedMember(relation)) {
|
|
332
350
|
throw errors.new(`relation ${relation.name} is closed — its extension is schema data (axioms), never scanned or written`);
|
|
333
351
|
}
|
|
334
352
|
return entry;
|
|
@@ -338,15 +356,16 @@ function openDb(handle, theory, manifest) {
|
|
|
338
356
|
if (entry === undefined || !isMemberName(fact.relation)) {
|
|
339
357
|
throw errors.new(`bumbledb violation cites unknown relation ${fact.relation}`);
|
|
340
358
|
}
|
|
341
|
-
const declared =
|
|
359
|
+
const declared = sealedFieldsOf(entry.member);
|
|
342
360
|
const decoded = {};
|
|
343
361
|
for (const cell of fact.fields) {
|
|
344
362
|
const cited = declared.find(function byName(candidate) {
|
|
345
363
|
return candidate.name === cell.name;
|
|
346
364
|
});
|
|
365
|
+
const roster = rosterOf(cited?.field);
|
|
347
366
|
decoded[cell.name] =
|
|
348
|
-
|
|
349
|
-
? handleOf(`violation fact ${fact.relation} field ${cell.name}`,
|
|
367
|
+
roster !== undefined
|
|
368
|
+
? handleOf(`violation fact ${fact.relation} field ${cell.name}`, roster, cell.value)
|
|
350
369
|
: cell.value;
|
|
351
370
|
}
|
|
352
371
|
return Object.freeze({ relation: fact.relation, fact: Object.freeze(decoded) });
|
|
@@ -406,21 +425,15 @@ function openDb(handle, theory, manifest) {
|
|
|
406
425
|
function get(relation, keyOrStatement, declaredKey) {
|
|
407
426
|
assertLive();
|
|
408
427
|
const entry = resolveOrdinary(relation);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
428
|
+
return selectKeyRead(keyOrStatement, declaredKey, function byStatement(statement, key) {
|
|
429
|
+
return readThroughKey(relation, entry, declaredKeyOf(relation, statement), recordOf(key));
|
|
430
|
+
}, function byPrimary(key) {
|
|
431
|
+
const primaryKey = entry.primaryKey;
|
|
432
|
+
if (primaryKey === undefined) {
|
|
433
|
+
throw errors.new(`relation ${relation.name} has no candidate key — keyed get requires a fresh field or a declared key statement`);
|
|
412
434
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
if (isStatementValue(keyOrStatement)) {
|
|
417
|
-
throw errors.new("keyed get with a statement selector also takes the key object — get(relation, keyStatement, key)");
|
|
418
|
-
}
|
|
419
|
-
const primaryKey = entry.primaryKey;
|
|
420
|
-
if (primaryKey === undefined) {
|
|
421
|
-
throw errors.new(`relation ${relation.name} has no candidate key — keyed get requires a fresh field or a declared key statement`);
|
|
422
|
-
}
|
|
423
|
-
return readThroughKey(relation, entry, primaryKey, recordOf(keyOrStatement));
|
|
435
|
+
return readThroughKey(relation, entry, primaryKey, recordOf(key));
|
|
436
|
+
});
|
|
424
437
|
}
|
|
425
438
|
return { contains, get };
|
|
426
439
|
}
|
|
@@ -479,7 +492,7 @@ function openDb(handle, theory, manifest) {
|
|
|
479
492
|
const rows = bridged("execute bumbledb prepared query", function callExecute() {
|
|
480
493
|
return native.preparedExecute(plan.handle, state.handle, wire);
|
|
481
494
|
});
|
|
482
|
-
return decodeAnswers(plan.
|
|
495
|
+
return decodeAnswers(plan.finds, rows);
|
|
483
496
|
}
|
|
484
497
|
const scope = Object.freeze({
|
|
485
498
|
generation,
|
|
@@ -556,16 +569,11 @@ function openDb(handle, theory, manifest) {
|
|
|
556
569
|
}
|
|
557
570
|
function get(relation, keyOrStatement, declaredKey) {
|
|
558
571
|
return read(function getInScope(snap) {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
if (isStatementValue(keyOrStatement)) {
|
|
566
|
-
throw errors.new("keyed get with a statement selector also takes the key object — get(relation, keyStatement, key)");
|
|
567
|
-
}
|
|
568
|
-
return snap.get(relation, keyOrStatement);
|
|
572
|
+
return selectKeyRead(keyOrStatement, declaredKey, function byStatement(statement, key) {
|
|
573
|
+
return snap.get(relation, statement, key);
|
|
574
|
+
}, function byPrimary(key) {
|
|
575
|
+
return snap.get(relation, key);
|
|
576
|
+
});
|
|
569
577
|
});
|
|
570
578
|
}
|
|
571
579
|
function contains(relation, fact) {
|
|
@@ -835,13 +843,29 @@ function openDb(handle, theory, manifest) {
|
|
|
835
843
|
}
|
|
836
844
|
return commitWitnessed(state, txHandle);
|
|
837
845
|
}
|
|
846
|
+
/**
|
|
847
|
+
* The witnessed retry loop. What it retries: the benign race — the
|
|
848
|
+
* host's OWN interleaved commit landing between an attempt's snapshot
|
|
849
|
+
* and its witnessed begin (every writer shares this handle, so a move
|
|
850
|
+
* is always self-inflicted) — by rerunning the WHOLE callback on a
|
|
851
|
+
* fresh snapshot, which converges because each rerun witnesses a
|
|
852
|
+
* strictly newer generation. What it refuses: the pathology where the
|
|
853
|
+
* callback itself (even indirectly) issues a plain `db.write` before
|
|
854
|
+
* its first tx verb, moving the generation on EVERY attempt — an
|
|
855
|
+
* unbounded loop would spin forever with no diagnostic, so past
|
|
856
|
+
* {@link WITNESSED_ATTEMPT_CAP} attempts the loop throws the typed
|
|
857
|
+
* {@link ErrWitnessedLivelock} instead (the engine's ruling: the
|
|
858
|
+
* error, never a loop — retry is host policy, and this is the host
|
|
859
|
+
* policy's own honesty bound).
|
|
860
|
+
*/
|
|
838
861
|
function writeWitnessed(fn) {
|
|
839
|
-
for (
|
|
862
|
+
for (let attempts = 0; attempts < WITNESSED_ATTEMPT_CAP; attempts += 1) {
|
|
840
863
|
const attempt = witnessedAttempt(fn);
|
|
841
864
|
if (attempt !== undefined) {
|
|
842
865
|
return attempt;
|
|
843
866
|
}
|
|
844
867
|
}
|
|
868
|
+
throw errors.wrap(ErrWitnessedLivelock, `writeWitnessed livelock: the generation moved on all ${WITNESSED_ATTEMPT_CAP} attempts against schema ${theory.name}`);
|
|
845
869
|
}
|
|
846
870
|
/**
|
|
847
871
|
* Verifies the declaration-ordinal law the query lowering leans on
|
|
@@ -860,16 +884,9 @@ function openDb(handle, theory, manifest) {
|
|
|
860
884
|
if (member === undefined) {
|
|
861
885
|
throw errors.new(`bumbledb manifest drift: schema ${theory.name} lost relation ${name}`);
|
|
862
886
|
}
|
|
863
|
-
const sealed =
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
...member.data.columns.map(function columnName(column) {
|
|
867
|
-
return column.name;
|
|
868
|
-
})
|
|
869
|
-
]
|
|
870
|
-
: member.data.fields.map(function fieldName(declared) {
|
|
871
|
-
return declared.name;
|
|
872
|
-
});
|
|
887
|
+
const sealed = sealedFieldsOf(member).map(function fieldName(declared) {
|
|
888
|
+
return declared.name;
|
|
889
|
+
});
|
|
873
890
|
sealed.forEach(function verifyField(fieldName, fieldOrdinal) {
|
|
874
891
|
if (entry.fieldIds.get(fieldName) !== fieldOrdinal) {
|
|
875
892
|
throw errors.new(`bumbledb manifest drift: ${name}.${fieldName} has engine field id ${entry.fieldIds.get(fieldName)}, its sealed ordinal is ${fieldOrdinal}`);
|
|
@@ -910,7 +927,7 @@ function openDb(handle, theory, manifest) {
|
|
|
910
927
|
handle: preparedHandle,
|
|
911
928
|
owner,
|
|
912
929
|
params: q.data.params,
|
|
913
|
-
|
|
930
|
+
finds: q.data.finds
|
|
914
931
|
}));
|
|
915
932
|
planReclaimer.register(prepared, preparedHandle);
|
|
916
933
|
return prepared;
|
|
@@ -1058,5 +1075,5 @@ const Db = Object.freeze({
|
|
|
1058
1075
|
return exhumeStore(path.resolve(storePath));
|
|
1059
1076
|
}
|
|
1060
1077
|
});
|
|
1061
|
-
export { abandon, Db, ErrNewtypeMismatch };
|
|
1078
|
+
export { abandon, Db, ErrNewtypeMismatch, ErrWitnessedLivelock, WITNESSED_ATTEMPT_CAP };
|
|
1062
1079
|
//# sourceMappingURL=db.js.map
|