@bjornpagen/bumbledb 0.20.2 → 1.0.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 +283 -1611
- package/README.md +156 -118
- package/dist/capacity.d.ts +16 -12
- package/dist/capacity.d.ts.map +1 -1
- package/dist/capacity.js +16 -48
- package/dist/capacity.js.map +1 -1
- package/dist/changes.d.ts +54 -0
- package/dist/changes.d.ts.map +1 -0
- package/dist/changes.js +245 -0
- package/dist/changes.js.map +1 -0
- package/dist/close.d.ts +24 -0
- package/dist/close.d.ts.map +1 -0
- package/dist/close.js +34 -0
- package/dist/close.js.map +1 -0
- package/dist/closed.d.ts +1 -3
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +24 -12
- package/dist/closed.js.map +1 -1
- package/dist/codec.d.ts +56 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +289 -0
- package/dist/codec.js.map +1 -0
- package/dist/compile.d.ts +68 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +75 -0
- package/dist/compile.js.map +1 -0
- package/dist/db-native.d.ts +170 -0
- package/dist/db-native.d.ts.map +1 -0
- package/dist/db-native.js +5 -0
- package/dist/db-native.js.map +1 -0
- package/dist/db.d.ts +101 -233
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +232 -1084
- package/dist/db.js.map +1 -1
- package/dist/errors.d.ts +57 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +32 -0
- package/dist/errors.js.map +1 -0
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +2 -2
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +65 -24
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +94 -24
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +37 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -21
- package/dist/index.js.map +1 -1
- package/dist/internal/log.d.ts +24 -0
- package/dist/internal/log.d.ts.map +1 -0
- package/dist/internal/log.js +10 -0
- package/dist/internal/log.js.map +1 -0
- package/dist/law.d.ts +8 -13
- package/dist/law.d.ts.map +1 -1
- package/dist/law.js +6 -59
- package/dist/law.js.map +1 -1
- package/dist/lower.d.ts +0 -13
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +9 -17
- package/dist/lower.js.map +1 -1
- package/dist/migration.d.ts +33 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +48 -0
- package/dist/migration.js.map +1 -0
- package/dist/native.d.ts +256 -301
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +65 -108
- package/dist/native.js.map +1 -1
- package/dist/query/atom.d.ts +24 -13
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +7 -3
- package/dist/query/atom.js.map +1 -1
- package/dist/query/compute.d.ts +68 -0
- package/dist/query/compute.d.ts.map +1 -0
- package/dist/query/compute.js +141 -0
- package/dist/query/compute.js.map +1 -0
- package/dist/query/find.d.ts +15 -8
- package/dist/query/find.d.ts.map +1 -1
- package/dist/query/find.js +6 -2
- package/dist/query/find.js.map +1 -1
- package/dist/query/lower.d.ts +23 -2
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +433 -80
- package/dist/query/lower.js.map +1 -1
- package/dist/query/parse-ir.d.ts.map +1 -1
- package/dist/query/parse-ir.js +17 -8
- package/dist/query/parse-ir.js.map +1 -1
- package/dist/query/run.d.ts +12 -2
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +26 -9
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +47 -3
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +83 -19
- package/dist/query/scope.js.map +1 -1
- package/dist/relation.d.ts +3 -8
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +16 -10
- package/dist/relation.js.map +1 -1
- package/dist/result.d.ts +47 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +50 -0
- package/dist/result.js.map +1 -0
- package/dist/rows.d.ts +69 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +328 -0
- package/dist/rows.js.map +1 -0
- package/dist/runtime-codes.d.ts +2 -0
- package/dist/runtime-codes.d.ts.map +1 -0
- package/dist/runtime-codes.js +19 -0
- package/dist/runtime-codes.js.map +1 -0
- package/dist/runtime-errors.d.ts +106 -0
- package/dist/runtime-errors.d.ts.map +1 -0
- package/dist/runtime-errors.js +62 -0
- package/dist/runtime-errors.js.map +1 -0
- package/dist/runtime-native.d.ts +171 -0
- package/dist/runtime-native.d.ts.map +1 -0
- package/dist/runtime-native.js +5 -0
- package/dist/runtime-native.js.map +1 -0
- package/dist/runtime.d.ts +73 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +293 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scalar.d.ts +165 -0
- package/dist/scalar.d.ts.map +1 -0
- package/dist/scalar.js +344 -0
- package/dist/scalar.js.map +1 -0
- package/dist/schema.d.ts +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +34 -37
- package/dist/schema.js.map +1 -1
- package/dist/shape.d.ts +28 -0
- package/dist/shape.d.ts.map +1 -0
- package/dist/shape.js +2 -0
- package/dist/shape.js.map +1 -0
- package/dist/spec.d.ts +27 -3
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js +22 -1
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +16 -3
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +54 -28
- package/dist/statements.js.map +1 -1
- package/dist/uuid.d.ts +23 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +54 -0
- package/dist/uuid.js.map +1 -0
- package/pack-provenance.json +7 -0
- package/package.json +12 -16
- package/src/capacity.ts +34 -54
- package/src/changes.ts +361 -0
- package/src/close.ts +53 -0
- package/src/closed.ts +25 -19
- package/src/codec.ts +379 -0
- package/src/compile.ts +149 -0
- package/src/db-native.ts +247 -0
- package/src/db.ts +461 -1632
- package/src/errors.ts +50 -0
- package/src/face.ts +2 -2
- package/src/fields.ts +182 -55
- package/src/index.ts +62 -126
- package/src/internal/log.ts +51 -0
- package/src/law.ts +13 -28
- package/src/lower.ts +9 -4
- package/src/migration.ts +69 -0
- package/src/native.ts +326 -487
- package/src/query/atom.ts +61 -25
- package/src/query/compute.ts +237 -0
- package/src/query/find.ts +31 -12
- package/src/query/lower.ts +531 -143
- package/src/query/parse-ir.ts +18 -13
- package/src/query/run.ts +32 -16
- package/src/query/scope.ts +140 -8
- package/src/relation.ts +17 -21
- package/src/result.ts +130 -0
- package/src/rows.ts +404 -0
- package/src/runtime-codes.ts +18 -0
- package/src/runtime-errors.ts +69 -0
- package/src/runtime-native.ts +242 -0
- package/src/runtime.ts +440 -0
- package/src/scalar.ts +560 -0
- package/src/schema.ts +35 -37
- package/src/shape.ts +31 -0
- package/src/spec.ts +33 -3
- package/src/statements.ts +75 -68
- package/src/uuid.ts +69 -0
- package/dist/marshal.d.ts +0 -44
- package/dist/marshal.d.ts.map +0 -1
- package/dist/marshal.js +0 -165
- package/dist/marshal.js.map +0 -1
- package/src/marshal.ts +0 -200
package/src/native.ts
CHANGED
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
import { createRequire } from "node:module"
|
|
2
|
-
import
|
|
2
|
+
import { Result } from "effect"
|
|
3
|
+
import { NativeLoadError, NativeOperationError, NativeReportedError } from "#errors.ts"
|
|
3
4
|
import type { SchemaSpec, ValueSpec, ValueTypeSpec } from "#spec.ts"
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* The opaque managed database capability. The native runtime registry —
|
|
8
|
+
* not this wrapper — owns the LMDB environment, the kernel directory
|
|
9
|
+
* lock and every session; a retained wrapper after a completed close is
|
|
10
|
+
* inert. Minted only by the managed handshake
|
|
11
|
+
* (`runtimeDirectoryDbOpen` → `runtimeDbTake` in #runtime-native.ts).
|
|
12
|
+
*/
|
|
6
13
|
type DbHandle = { readonly __brand: "bumbledb.db" }
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type WitnessHandle = { readonly __brand: "bumbledb.witness" }
|
|
11
|
-
|
|
12
|
-
type BuilderHandle = { readonly __brand: "bumbledb.builder" }
|
|
13
|
-
|
|
14
|
-
type OwnedHandle = { readonly __brand: "bumbledb.owned" }
|
|
15
|
-
|
|
16
|
-
type TxHandle = { readonly __brand: "bumbledb.tx" }
|
|
17
|
-
|
|
18
|
-
type PreparedHandle = { readonly __brand: "bumbledb.prepared" }
|
|
15
|
+
/** Admitted owned instance attached through directory publish — not a JS builder. */
|
|
19
16
|
|
|
20
17
|
/**
|
|
21
|
-
* The sealed per-theory log
|
|
22
|
-
*
|
|
23
|
-
*
|
|
18
|
+
* The sealed per-theory log schema (`crates/bumbledb-log` successor
|
|
19
|
+
* lanes): the validated core schema plus its fingerprint, shared by the
|
|
20
|
+
* command/decision grammar. Immutable plain data; no lifecycle verbs.
|
|
24
21
|
*/
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
interface WireMutationReport {
|
|
28
|
-
readonly submitted: bigint
|
|
29
|
-
readonly changed: bigint
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type WireFreshRange =
|
|
33
|
-
| { readonly empty: true }
|
|
34
|
-
| { readonly empty: false; readonly start: bigint; readonly endExclusive: bigint }
|
|
22
|
+
type LogSchemaHandle = { readonly __brand: "bumbledb.logSchema" }
|
|
35
23
|
|
|
24
|
+
/** A discrete half-open interval `[start, end)` over u64/i64. */
|
|
36
25
|
interface IntervalValue {
|
|
37
26
|
readonly start: bigint
|
|
38
27
|
readonly end: bigint
|
|
39
28
|
}
|
|
40
29
|
|
|
41
|
-
|
|
30
|
+
/**
|
|
31
|
+
* A dense-line half-open interval with canonical binary64 endpoints:
|
|
32
|
+
* NaN-free, strictly ordered; ±Infinity are unbounded endpoints.
|
|
33
|
+
*/
|
|
34
|
+
interface F64IntervalValue {
|
|
35
|
+
readonly start: number
|
|
36
|
+
readonly end: number
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* One marshalled cell. An application-owned Uuid crosses as its
|
|
41
|
+
* canonical hyphenated UUID string (chapter 32); there is no fresh
|
|
42
|
+
* range, reservation counter or issuance value anywhere on this wire.
|
|
43
|
+
*/
|
|
44
|
+
type FactValue = boolean | bigint | number | string | Uint8Array | IntervalValue | F64IntervalValue
|
|
42
45
|
|
|
43
46
|
type TaggedValue = ValueSpec
|
|
44
47
|
|
|
@@ -70,9 +73,32 @@ interface RecIr {
|
|
|
70
73
|
readonly rec: readonly RuleIr[]
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
type HeadTermIr =
|
|
76
|
+
type HeadTermIr =
|
|
77
|
+
| { readonly kind: "var" }
|
|
78
|
+
| { readonly kind: "compute" }
|
|
79
|
+
| { readonly kind: "aggregate"; readonly op: HeadOpIr }
|
|
74
80
|
|
|
75
|
-
type HeadOpIr = "sum" | "min" | "max" | "count" | "pack"
|
|
81
|
+
type HeadOpIr = "sum" | "mean" | "min" | "max" | "count" | "pack"
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The computed-find scalar expression (C05 `FindTerm::Compute(ScalarExpr)`):
|
|
85
|
+
* exactly the frozen core roster, spelled as the migration plan JSON spells
|
|
86
|
+
* the same expressions (one grammar, no second evaluator). `var` binds a
|
|
87
|
+
* rule variable ordinal on this lane.
|
|
88
|
+
*/
|
|
89
|
+
type NumericCastIr = "toF64" | "toF64Exact" | "toI64Exact" | "toU64Exact"
|
|
90
|
+
|
|
91
|
+
type ScalarExprIr =
|
|
92
|
+
| { readonly kind: "var"; readonly var: number }
|
|
93
|
+
| { readonly kind: "literal"; readonly value: TaggedValue }
|
|
94
|
+
| { readonly kind: "negate"; readonly expr: ScalarExprIr }
|
|
95
|
+
| { readonly kind: "add"; readonly left: ScalarExprIr; readonly right: ScalarExprIr }
|
|
96
|
+
| { readonly kind: "subtract"; readonly left: ScalarExprIr; readonly right: ScalarExprIr }
|
|
97
|
+
| { readonly kind: "multiply"; readonly left: ScalarExprIr; readonly right: ScalarExprIr }
|
|
98
|
+
| { readonly kind: "divide"; readonly left: ScalarExprIr; readonly right: ScalarExprIr }
|
|
99
|
+
| { readonly kind: "cast"; readonly cast: NumericCastIr; readonly expr: ScalarExprIr }
|
|
100
|
+
| { readonly kind: "isNaN"; readonly expr: ScalarExprIr }
|
|
101
|
+
| { readonly kind: "isFinite"; readonly expr: ScalarExprIr }
|
|
76
102
|
|
|
77
103
|
interface RuleIr {
|
|
78
104
|
readonly finds: readonly FindTermIr[]
|
|
@@ -81,10 +107,15 @@ interface RuleIr {
|
|
|
81
107
|
readonly conditions: readonly ConditionTreeIr[]
|
|
82
108
|
}
|
|
83
109
|
|
|
84
|
-
type FoldOpIr =
|
|
110
|
+
type FoldOpIr =
|
|
111
|
+
| { readonly kind: "sum" }
|
|
112
|
+
| { readonly kind: "mean" }
|
|
113
|
+
| { readonly kind: "min" }
|
|
114
|
+
| { readonly kind: "max" }
|
|
85
115
|
|
|
86
116
|
type FindTermIr =
|
|
87
117
|
| { readonly kind: "var"; readonly var: number }
|
|
118
|
+
| { readonly kind: "compute"; readonly expr: ScalarExprIr }
|
|
88
119
|
| { readonly kind: "count" }
|
|
89
120
|
| { readonly kind: "aggregate"; readonly op: FoldOpIr; readonly over: number }
|
|
90
121
|
| { readonly kind: "pack"; readonly over: number }
|
|
@@ -95,6 +126,7 @@ type ParsedQuery = QueryIr & { readonly [parsedQueryBrand]: true }
|
|
|
95
126
|
|
|
96
127
|
type AggOpIr =
|
|
97
128
|
| { readonly kind: "sum" }
|
|
129
|
+
| { readonly kind: "mean" }
|
|
98
130
|
| { readonly kind: "min" }
|
|
99
131
|
| { readonly kind: "max" }
|
|
100
132
|
| { readonly kind: "count" }
|
|
@@ -138,150 +170,180 @@ type ConditionTreeIr =
|
|
|
138
170
|
|
|
139
171
|
type StatementKindTag = "functionality" | "containment" | "capacity"
|
|
140
172
|
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
// Successor log grammar wire (C06 through the C09 bridge). The 0.x
|
|
175
|
+
// braids/codec/manifest/sidecar lanes and their mint tables are deleted.
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
|
|
141
178
|
/**
|
|
142
|
-
* A
|
|
143
|
-
*
|
|
144
|
-
*
|
|
179
|
+
* A grammar lane's domain outcome: the payload, or a refusal row whose
|
|
180
|
+
* `kind` is an identity string spelled exactly as `bumbledb-log`'s
|
|
181
|
+
* identities emitter spells it (`logIdentities()` / log-identities.json).
|
|
145
182
|
*/
|
|
146
183
|
type LogResult<T, K extends string> =
|
|
147
184
|
| { readonly ok: true; readonly value: T }
|
|
148
185
|
| { readonly ok: false; readonly kind: K; readonly message: string }
|
|
149
186
|
|
|
150
|
-
/** `
|
|
151
|
-
type
|
|
152
|
-
| "
|
|
153
|
-
| "
|
|
154
|
-
| "
|
|
155
|
-
| "
|
|
156
|
-
| "
|
|
157
|
-
| "
|
|
158
|
-
| "
|
|
159
|
-
| "
|
|
160
|
-
| "
|
|
161
|
-
| "
|
|
162
|
-
| "
|
|
163
|
-
| "
|
|
164
|
-
| "
|
|
165
|
-
| "
|
|
166
|
-
| "
|
|
167
|
-
| "
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
readonly
|
|
197
|
-
readonly braidGen: bigint
|
|
198
|
-
readonly prev: Uint8Array
|
|
199
|
-
readonly writer: bigint
|
|
200
|
-
readonly timestamp: bigint
|
|
187
|
+
/** `FrameError` kinds (the `frame` identity family). */
|
|
188
|
+
type LogFrameKind =
|
|
189
|
+
| "limitExceeded"
|
|
190
|
+
| "lengthOverflow"
|
|
191
|
+
| "allocation"
|
|
192
|
+
| "truncated"
|
|
193
|
+
| "family"
|
|
194
|
+
| "layout"
|
|
195
|
+
| "kind"
|
|
196
|
+
| "tag"
|
|
197
|
+
| "invalidEpoch"
|
|
198
|
+
| "stateIdentityMismatch"
|
|
199
|
+
| "emptyChangeSummary"
|
|
200
|
+
| "emptyEvidence"
|
|
201
|
+
| "invalidTerminalStamp"
|
|
202
|
+
| "invalidPreconditionEvidence"
|
|
203
|
+
| "invalidPolicy"
|
|
204
|
+
| "invalidSequence"
|
|
205
|
+
| "invalidCount"
|
|
206
|
+
| "trailingBytes"
|
|
207
|
+
|
|
208
|
+
/** Receipt-row kinds: the frame family plus the foreign-scope refusal. */
|
|
209
|
+
type LogReceiptKind = LogFrameKind | "foreignRow"
|
|
210
|
+
|
|
211
|
+
/** Command-lane kinds: frame family plus the two command-only arms. */
|
|
212
|
+
type LogCommandKind = LogFrameKind | "core" | "schemaMismatch"
|
|
213
|
+
|
|
214
|
+
/** Chain-step refusals from the decode-and-verify lane. */
|
|
215
|
+
type LogChainKind = "wrongParent" | "wrongSequence"
|
|
216
|
+
|
|
217
|
+
/** The complete database scope of every command/receipt/decision. */
|
|
218
|
+
interface LogIdentity {
|
|
219
|
+
/** Application-owned Uuid, canonical hyphenated UUID. */
|
|
220
|
+
readonly databaseId: string
|
|
221
|
+
readonly incarnationId: string
|
|
222
|
+
/** The core schema fingerprint, 64 lowercase hex characters. */
|
|
223
|
+
readonly schemaId: string
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface LogStateStamp {
|
|
227
|
+
readonly incarnation: string
|
|
228
|
+
readonly dataRevision: bigint
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
interface LogDecisionStamp {
|
|
232
|
+
readonly seq: bigint
|
|
233
|
+
readonly hash: Uint8Array
|
|
201
234
|
}
|
|
202
235
|
|
|
203
|
-
type
|
|
236
|
+
type LogCondition = { readonly kind: "unconditional" } | { readonly kind: "exactState"; readonly state: LogStateStamp }
|
|
204
237
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
* and the codec core is the one judge of every cell.
|
|
209
|
-
*/
|
|
210
|
-
interface LogOpIn {
|
|
211
|
-
readonly kind: LogOpKind
|
|
212
|
-
readonly relation: number
|
|
213
|
-
readonly rows: ReadonlyArray<readonly TaggedValue[]>
|
|
238
|
+
interface LogCommandId {
|
|
239
|
+
readonly receiptEpoch: bigint
|
|
240
|
+
readonly requestId: string
|
|
214
241
|
}
|
|
215
242
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
readonly
|
|
219
|
-
readonly
|
|
220
|
-
readonly rows: FactValue[][]
|
|
243
|
+
interface LogCommandMetadata {
|
|
244
|
+
readonly identity: LogIdentity
|
|
245
|
+
readonly id: LogCommandId
|
|
246
|
+
readonly condition: LogCondition
|
|
221
247
|
}
|
|
222
248
|
|
|
223
|
-
interface
|
|
224
|
-
readonly
|
|
225
|
-
readonly
|
|
249
|
+
interface LogCommandRef {
|
|
250
|
+
readonly identity: LogIdentity
|
|
251
|
+
readonly receiptEpoch: bigint
|
|
252
|
+
readonly requestId: string
|
|
253
|
+
readonly digest: Uint8Array
|
|
226
254
|
}
|
|
227
255
|
|
|
228
|
-
|
|
229
|
-
readonly
|
|
230
|
-
readonly
|
|
231
|
-
}
|
|
256
|
+
type LogOutcomeWire =
|
|
257
|
+
| { readonly kind: "committed"; readonly added: bigint; readonly removed: bigint; readonly result?: Uint8Array }
|
|
258
|
+
| { readonly kind: "noChange"; readonly result?: Uint8Array }
|
|
259
|
+
| { readonly kind: "preconditionFailed"; readonly expected: LogStateStamp; readonly observed: LogStateStamp }
|
|
260
|
+
| { readonly kind: "invariantRejected"; readonly evidence: Uint8Array }
|
|
232
261
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
readonly
|
|
236
|
-
readonly
|
|
262
|
+
interface LogReceipt {
|
|
263
|
+
readonly command: LogCommandRef
|
|
264
|
+
readonly decisionAt: LogDecisionStamp
|
|
265
|
+
readonly stateAt: LogStateStamp
|
|
266
|
+
readonly outcome: LogOutcomeWire
|
|
237
267
|
}
|
|
238
268
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
readonly
|
|
242
|
-
readonly
|
|
269
|
+
interface LogLimits {
|
|
270
|
+
readonly envelopeBytes: bigint
|
|
271
|
+
readonly changeBytes: bigint
|
|
272
|
+
readonly evidenceBytes: bigint
|
|
273
|
+
readonly resultBytes: bigint
|
|
243
274
|
}
|
|
244
275
|
|
|
245
|
-
|
|
246
|
-
readonly
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
276
|
+
type LogAccess =
|
|
277
|
+
| { readonly kind: "active" }
|
|
278
|
+
| {
|
|
279
|
+
readonly kind: "frozen"
|
|
280
|
+
readonly operation: string
|
|
281
|
+
readonly intent:
|
|
282
|
+
| { readonly kind: "erasure" }
|
|
283
|
+
| { readonly kind: "migration"; readonly planSetDigest: Uint8Array; readonly target: string }
|
|
284
|
+
}
|
|
251
285
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
286
|
+
type LogLifecycle =
|
|
287
|
+
| {
|
|
288
|
+
readonly kind: "live"
|
|
289
|
+
readonly access: LogAccess
|
|
290
|
+
readonly decision: LogDecisionStamp
|
|
291
|
+
readonly state: LogStateStamp
|
|
292
|
+
readonly receipts: { readonly openEpoch: bigint; readonly retiredThrough: bigint }
|
|
293
|
+
}
|
|
294
|
+
| {
|
|
295
|
+
readonly kind: "deleted"
|
|
296
|
+
readonly operation: string
|
|
297
|
+
readonly reason:
|
|
298
|
+
| { readonly kind: "erasure" }
|
|
299
|
+
| {
|
|
300
|
+
readonly kind: "migrationAborted"
|
|
301
|
+
readonly sourceDatabase: string
|
|
302
|
+
readonly sourceIncarnation: string
|
|
303
|
+
readonly planSetDigest: Uint8Array
|
|
304
|
+
}
|
|
305
|
+
}
|
|
259
306
|
|
|
260
|
-
|
|
261
|
-
readonly
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
307
|
+
type LogActivation =
|
|
308
|
+
| { readonly kind: "notActivated" }
|
|
309
|
+
| {
|
|
310
|
+
readonly kind: "activated"
|
|
311
|
+
readonly operation: string
|
|
312
|
+
readonly targetGenesis: Uint8Array
|
|
313
|
+
readonly cause:
|
|
314
|
+
| { readonly kind: "create" }
|
|
315
|
+
| { readonly kind: "restore" }
|
|
316
|
+
| { readonly kind: "migration"; readonly planSetDigest: Uint8Array }
|
|
317
|
+
}
|
|
266
318
|
|
|
267
|
-
interface
|
|
268
|
-
readonly
|
|
269
|
-
readonly
|
|
270
|
-
readonly
|
|
319
|
+
interface LogAuthority {
|
|
320
|
+
readonly identity: LogIdentity
|
|
321
|
+
readonly revision: bigint
|
|
322
|
+
readonly lifecycle: LogLifecycle
|
|
323
|
+
readonly activation: LogActivation
|
|
271
324
|
}
|
|
272
325
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
readonly
|
|
276
|
-
|
|
326
|
+
type LogGenesisProvenance =
|
|
327
|
+
| { readonly kind: "create" }
|
|
328
|
+
| { readonly kind: "restore"; readonly sourceEvidence: Uint8Array }
|
|
329
|
+
| {
|
|
330
|
+
readonly kind: "migration"
|
|
331
|
+
readonly sourceDatabase: string
|
|
332
|
+
readonly sourceIncarnation: string
|
|
333
|
+
readonly planSetDigest: Uint8Array
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
interface LogGenesis {
|
|
337
|
+
readonly identity: LogIdentity
|
|
338
|
+
readonly initialApplicationDigest: Uint8Array
|
|
339
|
+
readonly initialSystemDigest: Uint8Array
|
|
340
|
+
readonly provenance: LogGenesisProvenance
|
|
277
341
|
}
|
|
278
342
|
|
|
279
343
|
interface ManifestField {
|
|
280
344
|
readonly name: string
|
|
281
345
|
readonly id: number
|
|
282
346
|
readonly valueType: ValueTypeSpec
|
|
283
|
-
/** The field's fresh attribute, straight off the declared spec; a closed relation's synthetic `id` slot is never fresh. */
|
|
284
|
-
readonly fresh: boolean
|
|
285
347
|
/** The field's host newtype name off the declared spec; a closed relation's synthetic `id` slot carries the handle newtype. Absent on a bare column. */
|
|
286
348
|
readonly newtype?: string
|
|
287
349
|
}
|
|
@@ -299,17 +361,6 @@ interface ManifestRelation {
|
|
|
299
361
|
readonly extension?: readonly ManifestRow[]
|
|
300
362
|
}
|
|
301
363
|
|
|
302
|
-
interface ManifestStatement {
|
|
303
|
-
readonly id: number
|
|
304
|
-
readonly kind: StatementKindTag
|
|
305
|
-
readonly spelling: string
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
interface Manifest {
|
|
309
|
-
readonly relations: readonly ManifestRelation[]
|
|
310
|
-
readonly statements: readonly ManifestStatement[]
|
|
311
|
-
}
|
|
312
|
-
|
|
313
364
|
interface SealedSide {
|
|
314
365
|
readonly relation: number
|
|
315
366
|
readonly projection: readonly number[]
|
|
@@ -383,40 +434,12 @@ type Violation =
|
|
|
383
434
|
readonly facts: readonly ViolationFact[]
|
|
384
435
|
}
|
|
385
436
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* `dbOpen`'s domain outcome. `schemaError` spans both spec
|
|
394
|
-
* resolution (unresolvable names, banned spellings — every issue in one
|
|
395
|
-
* message) and schema validation at the declaration boundary;
|
|
396
|
-
* `newtypeMismatch` is the coherence wall's own kind; `fingerprintMismatch`
|
|
397
|
-
* is `dbOpen`'s stored-theory refusal.
|
|
398
|
-
*/
|
|
399
|
-
type DbOpenResult =
|
|
400
|
-
| { readonly ok: true; readonly db: DbHandle }
|
|
401
|
-
| {
|
|
402
|
-
readonly ok: false
|
|
403
|
-
readonly kind: "schemaError" | "newtypeMismatch" | "fingerprintMismatch"
|
|
404
|
-
readonly message: string
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
type NativeWriteOutcome =
|
|
408
|
-
| { readonly tag: "accepted"; readonly generation: bigint }
|
|
409
|
-
| { readonly tag: "rejected"; readonly violations: readonly Violation[] }
|
|
410
|
-
| { readonly tag: "abandoned" }
|
|
411
|
-
| { readonly tag: "moved"; readonly witnessed: bigint; readonly current: bigint }
|
|
412
|
-
|
|
413
|
-
type AdmitResult =
|
|
414
|
-
| { readonly tag: "accepted"; readonly value: OwnedHandle }
|
|
415
|
-
| { readonly tag: "rejected"; readonly violations: readonly Violation[] }
|
|
416
|
-
|
|
417
|
-
type PrepareResult =
|
|
418
|
-
| { readonly ok: true; readonly prepared: PreparedHandle }
|
|
419
|
-
| { readonly ok: false; readonly kind: "irError"; readonly message: string }
|
|
437
|
+
// The managed create/open outcome is `ManagedDbOutcome` in
|
|
438
|
+
// #runtime-native.ts (accepted | rejected | refused); reads, writes and
|
|
439
|
+
// queries are worker-affine session verbs there too. The historical
|
|
440
|
+
// raw-pointer `dbRead`/`dbWrite`/`tx*`/`instance*`/`prepared*` synchronous
|
|
441
|
+
// surface — a JS callback inside a native transaction — is deleted (P06),
|
|
442
|
+
// as are the fresh/reserve issuance verbs (`WireFreshRange`).
|
|
420
443
|
|
|
421
444
|
type ErrorFamilyKind =
|
|
422
445
|
| "formatMismatch"
|
|
@@ -431,7 +454,6 @@ type ErrorFamilyKind =
|
|
|
431
454
|
| "schema"
|
|
432
455
|
| "validation"
|
|
433
456
|
| "factShape"
|
|
434
|
-
| "freshExhausted"
|
|
435
457
|
| "closedRelationWrite"
|
|
436
458
|
| "commitSync"
|
|
437
459
|
| "transactionPoisoned"
|
|
@@ -441,201 +463,124 @@ type ErrorFamilyKind =
|
|
|
441
463
|
| "capacityRayMeasure"
|
|
442
464
|
| "derivedBudgetExceeded"
|
|
443
465
|
| "overflow"
|
|
466
|
+
| "scalar"
|
|
444
467
|
| "resultBytesOverflow"
|
|
445
468
|
| "corruption"
|
|
469
|
+
| "store"
|
|
446
470
|
|
|
447
471
|
type AdmissionTag = "accepted" | "rejected"
|
|
448
472
|
type WriteTag = "accepted" | "rejected" | "abandoned" | "moved"
|
|
449
|
-
type OpenKind = "schemaError" | "newtypeMismatch" | "fingerprintMismatch"
|
|
473
|
+
type OpenKind = "schemaError" | "newtypeMismatch" | "fingerprintMismatch" | "destinationExists"
|
|
450
474
|
type PrepareKind = "irError"
|
|
451
475
|
|
|
452
476
|
interface Native {
|
|
453
477
|
engineVersion(): string
|
|
454
478
|
|
|
479
|
+
/** Small identity-sized inputs only; bulk hashing rides `runtimeHash`. */
|
|
455
480
|
blake3Hash(data: Uint8Array): Uint8Array
|
|
456
481
|
|
|
457
482
|
descriptor(spec: SchemaSpec): SealedDescriptor
|
|
458
483
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
dbOpen(path: string, spec: SchemaSpec): Promise<DbOpenResult>
|
|
462
|
-
|
|
463
|
-
dbManifest(db: DbHandle): Manifest
|
|
464
|
-
|
|
465
|
-
dbFingerprint(db: DbHandle): string
|
|
466
|
-
|
|
467
|
-
dbGeneration(db: DbHandle): bigint
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* blake3 over the canonical catalog enumeration — the replication
|
|
471
|
-
* equality oracle: equal digests imply identical judged content
|
|
472
|
-
* regardless of page layout or allocation history.
|
|
473
|
-
*/
|
|
474
|
-
dbCatalogDigest(db: DbHandle): Uint8Array
|
|
475
|
-
|
|
476
|
-
dbFromInstance(path: string, instance: OwnedHandle): Promise<DbHandle>
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* Runs `callback` synchronously inside the engine read lease. The
|
|
480
|
-
* instance handle is invalid after the callback returns; the witness
|
|
481
|
-
* handle is a clone and may escape.
|
|
482
|
-
*/
|
|
483
|
-
dbRead<R>(db: DbHandle, callback: (instance: InstanceHandle, witness: WitnessHandle) => R): R
|
|
484
|
-
instanceGeneration(instance: InstanceHandle): bigint
|
|
485
|
-
instanceScan(instance: InstanceHandle, relationId: number): FactValue[][]
|
|
486
|
-
|
|
487
|
-
instanceCount(instance: InstanceHandle, relationId: number): bigint
|
|
488
|
-
instanceContains(instance: InstanceHandle, relationId: number, values: readonly FactValue[]): boolean
|
|
489
|
-
instanceGet(
|
|
490
|
-
instance: InstanceHandle,
|
|
491
|
-
relationId: number,
|
|
492
|
-
keyStatementId: number,
|
|
493
|
-
keyValues: readonly FactValue[]
|
|
494
|
-
): FactValue[] | null
|
|
495
|
-
instancePrepare(instance: InstanceHandle, query: ParsedQuery): PrepareResult
|
|
496
|
-
witnessClose(witness: WitnessHandle): void
|
|
484
|
+
// --- successor log grammar (small frames; command/decision lanes are
|
|
485
|
+
// executor verbs in #runtime-native.ts) ---
|
|
497
486
|
|
|
498
|
-
|
|
487
|
+
logIdentities(): string
|
|
499
488
|
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* Records a collection of inserts into the delta; returns the engine
|
|
503
|
-
* `{ submitted, changed }` report. `cells` is ONE flat row-major array
|
|
504
|
-
* (length rows×arity) in sealed field order, and `rows` is the EXPLICIT
|
|
505
|
-
* row count the caller states — the one collection crossing: the JS side
|
|
506
|
-
* alone knows N when the roster is fieldless (N nullary facts project to 0 cells, so no
|
|
507
|
-
* derivation can recover N), and the bridge verifies
|
|
508
|
-
* `cells.length === rows × arity` exactly against its resident sealed
|
|
509
|
-
* roster before building the engine's shape-proved collection in a
|
|
510
|
-
* single pass. Empty (`rows === 0n`, no cells) is lawful and still a
|
|
511
|
-
* mutation. Nothing is judged until commit; shape violations throw
|
|
512
|
-
* typed, naming relation and field.
|
|
513
|
-
*/
|
|
514
|
-
txInsert(tx: TxHandle, relationId: number, rows: bigint, cells: readonly FactValue[]): WireMutationReport
|
|
489
|
+
logSchema(spec: SchemaSpec): LogSchemaHandle
|
|
515
490
|
|
|
516
|
-
|
|
491
|
+
logSchemaFingerprint(schema: LogSchemaHandle): string
|
|
517
492
|
|
|
518
|
-
|
|
493
|
+
logReceiptKey(id: LogCommandId): Uint8Array
|
|
519
494
|
|
|
520
|
-
|
|
495
|
+
logReceiptEncode(receipt: LogReceipt, limits: LogLimits): LogResult<Uint8Array, LogReceiptKind>
|
|
521
496
|
|
|
522
|
-
|
|
497
|
+
logReceiptDecode(
|
|
498
|
+
expected: { readonly identity: LogIdentity; readonly receiptEpoch: bigint; readonly requestId: string },
|
|
499
|
+
bytes: Uint8Array,
|
|
500
|
+
limits: LogLimits
|
|
501
|
+
): LogResult<LogReceipt, LogReceiptKind>
|
|
523
502
|
|
|
524
|
-
|
|
503
|
+
logReceiptDecodeAt(id: LogCommandId, bytes: Uint8Array, limits: LogLimits): LogResult<LogReceipt, LogReceiptKind>
|
|
525
504
|
|
|
526
|
-
|
|
505
|
+
logControlEncode(authority: LogAuthority, cap: bigint): LogResult<Uint8Array, LogFrameKind>
|
|
527
506
|
|
|
528
|
-
|
|
507
|
+
logControlDecode(bytes: Uint8Array, cap: bigint): LogResult<LogAuthority, LogFrameKind>
|
|
529
508
|
|
|
530
|
-
|
|
509
|
+
logGenesisEncode(record: LogGenesis, cap: bigint): LogResult<Uint8Array, LogFrameKind>
|
|
531
510
|
|
|
532
|
-
|
|
533
|
-
builder: BuilderHandle,
|
|
534
|
-
relationId: number,
|
|
535
|
-
rows: bigint,
|
|
536
|
-
cells: readonly FactValue[]
|
|
537
|
-
): WireMutationReport
|
|
538
|
-
instanceBuilderDelete(
|
|
539
|
-
builder: BuilderHandle,
|
|
540
|
-
relationId: number,
|
|
541
|
-
rows: bigint,
|
|
542
|
-
cells: readonly FactValue[]
|
|
543
|
-
): WireMutationReport
|
|
544
|
-
instanceBuilderReserve(builder: BuilderHandle, relationId: number, fieldId: number, count: bigint): WireFreshRange
|
|
545
|
-
instanceBuilderContains(builder: BuilderHandle, relationId: number, values: readonly FactValue[]): boolean
|
|
546
|
-
instanceBuilderGet(
|
|
547
|
-
builder: BuilderHandle,
|
|
548
|
-
relationId: number,
|
|
549
|
-
keyStatementId: number,
|
|
550
|
-
keyValues: readonly FactValue[]
|
|
551
|
-
): FactValue[] | null
|
|
552
|
-
instanceBuilderClose(builder: BuilderHandle): void
|
|
553
|
-
instanceBuilderAdmit(builder: BuilderHandle): Promise<AdmitResult>
|
|
554
|
-
ownedInstanceClose(instance: OwnedHandle): void
|
|
555
|
-
ownedScan(instance: OwnedHandle, relationId: number): FactValue[][]
|
|
511
|
+
logGenesisDecode(bytes: Uint8Array, cap: bigint): LogResult<LogGenesis, LogFrameKind>
|
|
556
512
|
|
|
557
|
-
|
|
558
|
-
ownedContains(instance: OwnedHandle, relationId: number, values: readonly FactValue[]): boolean
|
|
559
|
-
ownedGet(
|
|
560
|
-
instance: OwnedHandle,
|
|
561
|
-
relationId: number,
|
|
562
|
-
keyStatementId: number,
|
|
563
|
-
keyValues: readonly FactValue[]
|
|
564
|
-
): FactValue[] | null
|
|
565
|
-
ownedPrepare(instance: OwnedHandle, query: ParsedQuery): PrepareResult
|
|
566
|
-
ownedExecute(prepared: PreparedHandle, instance: OwnedHandle, params: readonly QueryParam[]): FactValue[][]
|
|
567
|
-
|
|
568
|
-
logCodec(descriptor: SealedDescriptor): LogCodecHandle
|
|
569
|
-
|
|
570
|
-
logBraidsOf(descriptor: SealedDescriptor): LogBraids
|
|
571
|
-
|
|
572
|
-
logEncodeBatch(
|
|
573
|
-
handle: LogCodecHandle,
|
|
574
|
-
header: LogBatchHeader,
|
|
575
|
-
ops: readonly LogOpIn[]
|
|
576
|
-
): LogResult<Uint8Array, LogBatchEncodeKind>
|
|
577
|
-
|
|
578
|
-
logDecodeBatch(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogBatch, LogBatchDecodeKind>
|
|
579
|
-
|
|
580
|
-
logParseManifest(bytes: Uint8Array): LogResult<LogManifestDoc, LogManifestKind>
|
|
581
|
-
|
|
582
|
-
logRenderManifest(doc: LogManifestDoc): Uint8Array
|
|
583
|
-
|
|
584
|
-
logParseCheckpoint(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogCheckpointDoc, LogCheckpointKind>
|
|
585
|
-
|
|
586
|
-
logRenderCheckpoint(handle: LogCodecHandle, doc: LogCheckpointDoc): Uint8Array
|
|
587
|
-
|
|
588
|
-
logParseSidecar(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogChain, LogSidecarKind>
|
|
589
|
-
|
|
590
|
-
logRenderSidecar(handle: LogCodecHandle, chain: LogChain): Uint8Array
|
|
513
|
+
logGenesisStamp(record: LogGenesis, cap: bigint): LogResult<LogDecisionStamp, LogFrameKind>
|
|
591
514
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
logRenderCkptScratch(digest: Uint8Array): Uint8Array
|
|
515
|
+
logBlankDigests(): { readonly application: Uint8Array; readonly system: Uint8Array }
|
|
595
516
|
}
|
|
596
517
|
|
|
597
518
|
const SHIPPED_PLATFORMS = ["darwin-arm64", "linux-arm64", "linux-x64"] as const
|
|
598
519
|
|
|
599
520
|
const requireNative = createRequire(import.meta.url)
|
|
600
521
|
|
|
601
|
-
|
|
602
|
-
|
|
522
|
+
type NativeBinding = Native
|
|
523
|
+
|
|
524
|
+
function ensureNativeBinding(): NativeBinding {
|
|
525
|
+
const loaded = bindingCache
|
|
526
|
+
if (loaded !== undefined) {
|
|
527
|
+
return loaded
|
|
528
|
+
}
|
|
529
|
+
const next = loadNativeBinding(process.platform, process.arch)
|
|
530
|
+
bindingCache = next
|
|
531
|
+
return next
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Lazy singleton: the addon loads on first native access, not module evaluation. */
|
|
535
|
+
const native: NativeBinding = new Proxy({} as NativeBinding, {
|
|
536
|
+
get(_target, property, receiver) {
|
|
537
|
+
return Reflect.get(ensureNativeBinding(), property, receiver)
|
|
538
|
+
},
|
|
539
|
+
set(_target, property, value) {
|
|
540
|
+
return Reflect.set(ensureNativeBinding(), property, value)
|
|
541
|
+
}
|
|
542
|
+
})
|
|
543
|
+
|
|
544
|
+
let bindingCache: NativeBinding | undefined
|
|
545
|
+
|
|
546
|
+
function nativeBindingIsLoaded(): boolean {
|
|
547
|
+
return bindingCache !== undefined
|
|
603
548
|
}
|
|
604
549
|
|
|
605
550
|
function loadNativeBinding(platform: string, arch: string): NativeBinding {
|
|
606
551
|
const platformPackage = `@bjornpagen/bumbledb-${platform}-${arch}`
|
|
607
552
|
|
|
608
|
-
const present =
|
|
609
|
-
if (present
|
|
610
|
-
throw
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
553
|
+
const present = Result.try(() => requireNative.resolve(`${platformPackage}/package.json`))
|
|
554
|
+
if (Result.isFailure(present)) {
|
|
555
|
+
throw new NativeLoadError({
|
|
556
|
+
package: platformPackage,
|
|
557
|
+
operation: "resolve",
|
|
558
|
+
message: `no native binary for ${platform}-${arch}: @bjornpagen/bumbledb ships ${SHIPPED_PLATFORMS.join(", ")} only`,
|
|
559
|
+
cause: present.failure
|
|
560
|
+
})
|
|
614
561
|
}
|
|
615
562
|
|
|
616
|
-
const loaded =
|
|
617
|
-
if (loaded
|
|
618
|
-
throw
|
|
563
|
+
const loaded = Result.try(() => requireNative(platformPackage))
|
|
564
|
+
if (Result.isFailure(loaded)) {
|
|
565
|
+
throw new NativeLoadError({
|
|
566
|
+
package: platformPackage,
|
|
567
|
+
operation: "load",
|
|
568
|
+
message: `load the ${platformPackage} native binary (package present but unloadable)`,
|
|
569
|
+
cause: loaded.failure
|
|
570
|
+
})
|
|
619
571
|
}
|
|
620
|
-
return loaded.
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
const binding: NativeBinding = loadNativeBinding(process.platform, process.arch)
|
|
624
|
-
const native: Native = binding
|
|
625
|
-
|
|
626
|
-
function dbClose(db: DbHandle): void {
|
|
627
|
-
binding.dbClose(db)
|
|
572
|
+
return loaded.success
|
|
628
573
|
}
|
|
629
574
|
|
|
630
575
|
/**
|
|
631
576
|
* @internal blake3 of the given bytes via the resident native binding —
|
|
632
577
|
* the engine's own hash, lent to the replication driver
|
|
633
578
|
* (`@bjornpagen/bumbledb-log`). Not SDK API; the export is deliberately
|
|
634
|
-
* undocumented in the package surface.
|
|
579
|
+
* undocumented in the package surface. Small identity-sized inputs only.
|
|
635
580
|
*/
|
|
636
581
|
function internalBlake3(data: Uint8Array): Uint8Array {
|
|
637
582
|
return bridged("bumbledb blake3", function hashBytes() {
|
|
638
|
-
return
|
|
583
|
+
return ensureNativeBinding().blake3Hash(data)
|
|
639
584
|
})
|
|
640
585
|
}
|
|
641
586
|
|
|
@@ -648,110 +593,28 @@ function internalBlake3(data: Uint8Array): Uint8Array {
|
|
|
648
593
|
*/
|
|
649
594
|
function internalDescriptor(spec: SchemaSpec): SealedDescriptor {
|
|
650
595
|
return bridged("bumbledb descriptor", function sealSpec() {
|
|
651
|
-
return
|
|
596
|
+
return ensureNativeBinding().descriptor(spec)
|
|
652
597
|
})
|
|
653
598
|
}
|
|
654
599
|
|
|
655
600
|
/**
|
|
656
|
-
* @internal the
|
|
657
|
-
*
|
|
658
|
-
* lent to the replication driver (`@bjornpagen/bumbledb-log`). Not SDK
|
|
659
|
-
* API; the export is deliberately undocumented in the package surface.
|
|
601
|
+
* @internal the successor identity table emitted by the log core's one
|
|
602
|
+
* speller (`bumbledb_log::identities::emit`). Not SDK API.
|
|
660
603
|
*/
|
|
661
|
-
function
|
|
662
|
-
return bridged("bumbledb-log
|
|
663
|
-
return
|
|
604
|
+
function internalLogIdentities(): string {
|
|
605
|
+
return bridged("bumbledb-log identities", function emitIdentities() {
|
|
606
|
+
return ensureNativeBinding().logIdentities()
|
|
664
607
|
})
|
|
665
608
|
}
|
|
666
609
|
|
|
667
610
|
/**
|
|
668
|
-
* @internal the
|
|
669
|
-
*
|
|
670
|
-
*
|
|
611
|
+
* @internal the sealed per-theory log schema off the same `SchemaSpec`
|
|
612
|
+
* every other lane speaks — one validated core schema, lent to the
|
|
613
|
+
* replication driver (`@bjornpagen/bumbledb-log`). Not SDK API.
|
|
671
614
|
*/
|
|
672
|
-
function
|
|
673
|
-
return bridged("bumbledb-log
|
|
674
|
-
return
|
|
675
|
-
})
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
/** @internal batch encode through the sealed codec. Not SDK API. */
|
|
679
|
-
function internalLogEncodeBatch(
|
|
680
|
-
handle: LogCodecHandle,
|
|
681
|
-
header: LogBatchHeader,
|
|
682
|
-
ops: readonly LogOpIn[]
|
|
683
|
-
): LogResult<Uint8Array, LogBatchEncodeKind> {
|
|
684
|
-
return bridged("bumbledb-log encode", function encodeBatch() {
|
|
685
|
-
return binding.logEncodeBatch(handle, header, ops)
|
|
686
|
-
})
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
/** @internal batch decode through the sealed codec. Not SDK API. */
|
|
690
|
-
function internalLogDecodeBatch(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogBatch, LogBatchDecodeKind> {
|
|
691
|
-
return bridged("bumbledb-log decode", function decodeBatch() {
|
|
692
|
-
return binding.logDecodeBatch(handle, bytes)
|
|
693
|
-
})
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
/** @internal manifest document parse — grammar only, no IO. Not SDK API. */
|
|
697
|
-
function internalLogParseManifest(bytes: Uint8Array): LogResult<LogManifestDoc, LogManifestKind> {
|
|
698
|
-
return bridged("bumbledb-log manifest parse", function parseManifest() {
|
|
699
|
-
return binding.logParseManifest(bytes)
|
|
700
|
-
})
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
/** @internal the manifest's one encoding, byte-exact for CAS bodies. Not SDK API. */
|
|
704
|
-
function internalLogRenderManifest(doc: LogManifestDoc): Uint8Array {
|
|
705
|
-
return bridged("bumbledb-log manifest render", function renderManifest() {
|
|
706
|
-
return binding.logRenderManifest(doc)
|
|
707
|
-
})
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/** @internal checkpoint document parse against the theory's braids. Not SDK API. */
|
|
711
|
-
function internalLogParseCheckpoint(
|
|
712
|
-
handle: LogCodecHandle,
|
|
713
|
-
bytes: Uint8Array
|
|
714
|
-
): LogResult<LogCheckpointDoc, LogCheckpointKind> {
|
|
715
|
-
return bridged("bumbledb-log checkpoint parse", function parseCheckpoint() {
|
|
716
|
-
return binding.logParseCheckpoint(handle, bytes)
|
|
717
|
-
})
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
/** @internal checkpoint document render. Not SDK API. */
|
|
721
|
-
function internalLogRenderCheckpoint(handle: LogCodecHandle, doc: LogCheckpointDoc): Uint8Array {
|
|
722
|
-
return bridged("bumbledb-log checkpoint render", function renderCheckpoint() {
|
|
723
|
-
return binding.logRenderCheckpoint(handle, doc)
|
|
724
|
-
})
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/** @internal chain sidecar parse — the fs half stays in the driver. Not SDK API. */
|
|
728
|
-
function internalLogParseSidecar(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogChain, LogSidecarKind> {
|
|
729
|
-
return bridged("bumbledb-log sidecar parse", function parseSidecar() {
|
|
730
|
-
return binding.logParseSidecar(handle, bytes)
|
|
731
|
-
})
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
/** @internal chain sidecar render. Not SDK API. */
|
|
735
|
-
function internalLogRenderSidecar(handle: LogCodecHandle, chain: LogChain): Uint8Array {
|
|
736
|
-
return bridged("bumbledb-log sidecar render", function renderSidecar() {
|
|
737
|
-
return binding.logRenderSidecar(handle, chain)
|
|
738
|
-
})
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
/**
|
|
742
|
-
* @internal the digest a scratch-lease body names, or null — the refusal
|
|
743
|
-
* is undifferentiated by law. Not SDK API.
|
|
744
|
-
*/
|
|
745
|
-
function internalLogParseCkptScratch(bytes: Uint8Array): Uint8Array | null {
|
|
746
|
-
return bridged("bumbledb-log scratch parse", function parseScratch() {
|
|
747
|
-
return binding.logParseCkptScratch(bytes)
|
|
748
|
-
})
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
/** @internal the scratch-lease body: version byte + 32-byte digest. Not SDK API. */
|
|
752
|
-
function internalLogRenderCkptScratch(digest: Uint8Array): Uint8Array {
|
|
753
|
-
return bridged("bumbledb-log scratch render", function renderScratch() {
|
|
754
|
-
return binding.logRenderCkptScratch(digest)
|
|
615
|
+
function internalLogSchema(spec: SchemaSpec): LogSchemaHandle {
|
|
616
|
+
return bridged("bumbledb-log schema", function sealSchema() {
|
|
617
|
+
return ensureNativeBinding().logSchema(spec)
|
|
755
618
|
})
|
|
756
619
|
}
|
|
757
620
|
|
|
@@ -768,79 +631,70 @@ function errorFromThrow(caught: unknown): Error {
|
|
|
768
631
|
return caught
|
|
769
632
|
}
|
|
770
633
|
if (isEngineThrow(caught)) {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
634
|
+
return new NativeReportedError({
|
|
635
|
+
kind: caught.kind,
|
|
636
|
+
message: `bumbledb ${caught.kind}: ${caught.message}`,
|
|
637
|
+
cause: caught
|
|
638
|
+
})
|
|
774
639
|
}
|
|
775
|
-
return
|
|
640
|
+
return new NativeReportedError({ kind: "Unknown", message: String(caught), cause: caught })
|
|
776
641
|
}
|
|
777
642
|
|
|
778
643
|
function bridged<T>(context: string, run: () => T): T {
|
|
779
644
|
try {
|
|
780
645
|
return run()
|
|
781
646
|
} catch (caught) {
|
|
782
|
-
|
|
783
|
-
throw
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
async function bridgedAsync<T>(context: string, run: () => Promise<T>): Promise<T> {
|
|
788
|
-
try {
|
|
789
|
-
return await run()
|
|
790
|
-
} catch (caught) {
|
|
791
|
-
const inner = errorFromThrow(caught)
|
|
792
|
-
throw errors.wrap(inner, `${context}: ${inner.message}`)
|
|
647
|
+
if (caught instanceof Error) throw caught
|
|
648
|
+
throw new NativeOperationError({ operation: context, cause: caught })
|
|
793
649
|
}
|
|
794
650
|
}
|
|
795
651
|
|
|
796
652
|
export type {
|
|
797
653
|
AdmissionTag,
|
|
798
|
-
AdmitResult,
|
|
799
654
|
AggOpIr,
|
|
800
655
|
AtomIr,
|
|
801
656
|
AtomSourceIr,
|
|
802
|
-
BuilderHandle,
|
|
803
657
|
CmpOpIr,
|
|
804
658
|
ComparisonIr,
|
|
805
659
|
ConditionTreeIr,
|
|
806
660
|
DbHandle,
|
|
807
661
|
ErrorFamilyKind,
|
|
662
|
+
F64IntervalValue,
|
|
808
663
|
FactValue,
|
|
809
664
|
FindTermIr,
|
|
810
665
|
HeadOpIr,
|
|
811
666
|
HeadTermIr,
|
|
812
|
-
InstanceHandle,
|
|
813
667
|
IntervalValue,
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
668
|
+
LogAccess,
|
|
669
|
+
LogActivation,
|
|
670
|
+
LogAuthority,
|
|
671
|
+
LogChainKind,
|
|
672
|
+
LogCommandId,
|
|
673
|
+
LogCommandKind,
|
|
674
|
+
LogCommandMetadata,
|
|
675
|
+
LogCommandRef,
|
|
676
|
+
LogCondition,
|
|
677
|
+
LogDecisionStamp,
|
|
678
|
+
LogFrameKind,
|
|
679
|
+
LogGenesis,
|
|
680
|
+
LogGenesisProvenance,
|
|
681
|
+
LogIdentity,
|
|
682
|
+
LogLifecycle,
|
|
683
|
+
LogLimits,
|
|
684
|
+
LogOutcomeWire,
|
|
685
|
+
LogReceipt,
|
|
686
|
+
LogReceiptKind,
|
|
832
687
|
LogResult,
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
688
|
+
LogSchemaHandle,
|
|
689
|
+
LogStateStamp,
|
|
690
|
+
NumericCastIr,
|
|
836
691
|
OpenKind,
|
|
837
|
-
OwnedHandle,
|
|
838
692
|
ParsedQuery,
|
|
839
|
-
PreparedHandle,
|
|
840
693
|
PrepareKind,
|
|
841
694
|
QueryIr,
|
|
842
695
|
QueryParam,
|
|
843
696
|
RuleIr,
|
|
697
|
+
ScalarExprIr,
|
|
844
698
|
SealedDescriptor,
|
|
845
699
|
SealedHi,
|
|
846
700
|
SealedSide,
|
|
@@ -849,34 +703,19 @@ export type {
|
|
|
849
703
|
StatementKindTag,
|
|
850
704
|
TaggedValue,
|
|
851
705
|
TermIr,
|
|
852
|
-
TxHandle,
|
|
853
706
|
Violation,
|
|
854
707
|
ViolationFact,
|
|
855
|
-
WireFreshRange,
|
|
856
|
-
WireMutationReport,
|
|
857
|
-
WitnessHandle,
|
|
858
708
|
WriteTag
|
|
859
709
|
}
|
|
860
710
|
export {
|
|
861
711
|
bridged,
|
|
862
|
-
bridgedAsync,
|
|
863
|
-
dbClose,
|
|
864
712
|
errorFromThrow,
|
|
865
713
|
internalBlake3,
|
|
866
714
|
internalDescriptor,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
internalLogDecodeBatch,
|
|
870
|
-
internalLogEncodeBatch,
|
|
871
|
-
internalLogParseCheckpoint,
|
|
872
|
-
internalLogParseCkptScratch,
|
|
873
|
-
internalLogParseManifest,
|
|
874
|
-
internalLogParseSidecar,
|
|
875
|
-
internalLogRenderCheckpoint,
|
|
876
|
-
internalLogRenderCkptScratch,
|
|
877
|
-
internalLogRenderManifest,
|
|
878
|
-
internalLogRenderSidecar,
|
|
715
|
+
internalLogIdentities,
|
|
716
|
+
internalLogSchema,
|
|
879
717
|
loadNativeBinding,
|
|
880
718
|
native,
|
|
719
|
+
nativeBindingIsLoaded,
|
|
881
720
|
SHIPPED_PLATFORMS
|
|
882
721
|
}
|