@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.
Files changed (192) hide show
  1. package/COOKBOOK.md +283 -1611
  2. package/README.md +156 -118
  3. package/dist/capacity.d.ts +16 -12
  4. package/dist/capacity.d.ts.map +1 -1
  5. package/dist/capacity.js +16 -48
  6. package/dist/capacity.js.map +1 -1
  7. package/dist/changes.d.ts +54 -0
  8. package/dist/changes.d.ts.map +1 -0
  9. package/dist/changes.js +245 -0
  10. package/dist/changes.js.map +1 -0
  11. package/dist/close.d.ts +24 -0
  12. package/dist/close.d.ts.map +1 -0
  13. package/dist/close.js +34 -0
  14. package/dist/close.js.map +1 -0
  15. package/dist/closed.d.ts +1 -3
  16. package/dist/closed.d.ts.map +1 -1
  17. package/dist/closed.js +24 -12
  18. package/dist/closed.js.map +1 -1
  19. package/dist/codec.d.ts +56 -0
  20. package/dist/codec.d.ts.map +1 -0
  21. package/dist/codec.js +289 -0
  22. package/dist/codec.js.map +1 -0
  23. package/dist/compile.d.ts +68 -0
  24. package/dist/compile.d.ts.map +1 -0
  25. package/dist/compile.js +75 -0
  26. package/dist/compile.js.map +1 -0
  27. package/dist/db-native.d.ts +170 -0
  28. package/dist/db-native.d.ts.map +1 -0
  29. package/dist/db-native.js +5 -0
  30. package/dist/db-native.js.map +1 -0
  31. package/dist/db.d.ts +101 -233
  32. package/dist/db.d.ts.map +1 -1
  33. package/dist/db.js +232 -1084
  34. package/dist/db.js.map +1 -1
  35. package/dist/errors.d.ts +57 -0
  36. package/dist/errors.d.ts.map +1 -0
  37. package/dist/errors.js +32 -0
  38. package/dist/errors.js.map +1 -0
  39. package/dist/face.d.ts.map +1 -1
  40. package/dist/face.js +2 -2
  41. package/dist/face.js.map +1 -1
  42. package/dist/fields.d.ts +65 -24
  43. package/dist/fields.d.ts.map +1 -1
  44. package/dist/fields.js +94 -24
  45. package/dist/fields.js.map +1 -1
  46. package/dist/index.d.ts +37 -32
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +17 -21
  49. package/dist/index.js.map +1 -1
  50. package/dist/internal/log.d.ts +24 -0
  51. package/dist/internal/log.d.ts.map +1 -0
  52. package/dist/internal/log.js +10 -0
  53. package/dist/internal/log.js.map +1 -0
  54. package/dist/law.d.ts +8 -13
  55. package/dist/law.d.ts.map +1 -1
  56. package/dist/law.js +6 -59
  57. package/dist/law.js.map +1 -1
  58. package/dist/lower.d.ts +0 -13
  59. package/dist/lower.d.ts.map +1 -1
  60. package/dist/lower.js +9 -17
  61. package/dist/lower.js.map +1 -1
  62. package/dist/migration.d.ts +33 -0
  63. package/dist/migration.d.ts.map +1 -0
  64. package/dist/migration.js +48 -0
  65. package/dist/migration.js.map +1 -0
  66. package/dist/native.d.ts +256 -301
  67. package/dist/native.d.ts.map +1 -1
  68. package/dist/native.js +65 -108
  69. package/dist/native.js.map +1 -1
  70. package/dist/query/atom.d.ts +24 -13
  71. package/dist/query/atom.d.ts.map +1 -1
  72. package/dist/query/atom.js +7 -3
  73. package/dist/query/atom.js.map +1 -1
  74. package/dist/query/compute.d.ts +68 -0
  75. package/dist/query/compute.d.ts.map +1 -0
  76. package/dist/query/compute.js +141 -0
  77. package/dist/query/compute.js.map +1 -0
  78. package/dist/query/find.d.ts +15 -8
  79. package/dist/query/find.d.ts.map +1 -1
  80. package/dist/query/find.js +6 -2
  81. package/dist/query/find.js.map +1 -1
  82. package/dist/query/lower.d.ts +23 -2
  83. package/dist/query/lower.d.ts.map +1 -1
  84. package/dist/query/lower.js +433 -80
  85. package/dist/query/lower.js.map +1 -1
  86. package/dist/query/parse-ir.d.ts.map +1 -1
  87. package/dist/query/parse-ir.js +17 -8
  88. package/dist/query/parse-ir.js.map +1 -1
  89. package/dist/query/run.d.ts +12 -2
  90. package/dist/query/run.d.ts.map +1 -1
  91. package/dist/query/run.js +26 -9
  92. package/dist/query/run.js.map +1 -1
  93. package/dist/query/scope.d.ts +47 -3
  94. package/dist/query/scope.d.ts.map +1 -1
  95. package/dist/query/scope.js +83 -19
  96. package/dist/query/scope.js.map +1 -1
  97. package/dist/relation.d.ts +3 -8
  98. package/dist/relation.d.ts.map +1 -1
  99. package/dist/relation.js +16 -10
  100. package/dist/relation.js.map +1 -1
  101. package/dist/result.d.ts +47 -0
  102. package/dist/result.d.ts.map +1 -0
  103. package/dist/result.js +50 -0
  104. package/dist/result.js.map +1 -0
  105. package/dist/rows.d.ts +69 -0
  106. package/dist/rows.d.ts.map +1 -0
  107. package/dist/rows.js +328 -0
  108. package/dist/rows.js.map +1 -0
  109. package/dist/runtime-codes.d.ts +2 -0
  110. package/dist/runtime-codes.d.ts.map +1 -0
  111. package/dist/runtime-codes.js +19 -0
  112. package/dist/runtime-codes.js.map +1 -0
  113. package/dist/runtime-errors.d.ts +106 -0
  114. package/dist/runtime-errors.d.ts.map +1 -0
  115. package/dist/runtime-errors.js +62 -0
  116. package/dist/runtime-errors.js.map +1 -0
  117. package/dist/runtime-native.d.ts +171 -0
  118. package/dist/runtime-native.d.ts.map +1 -0
  119. package/dist/runtime-native.js +5 -0
  120. package/dist/runtime-native.js.map +1 -0
  121. package/dist/runtime.d.ts +73 -0
  122. package/dist/runtime.d.ts.map +1 -0
  123. package/dist/runtime.js +293 -0
  124. package/dist/runtime.js.map +1 -0
  125. package/dist/scalar.d.ts +165 -0
  126. package/dist/scalar.d.ts.map +1 -0
  127. package/dist/scalar.js +344 -0
  128. package/dist/scalar.js.map +1 -0
  129. package/dist/schema.d.ts +1 -1
  130. package/dist/schema.d.ts.map +1 -1
  131. package/dist/schema.js +34 -37
  132. package/dist/schema.js.map +1 -1
  133. package/dist/shape.d.ts +28 -0
  134. package/dist/shape.d.ts.map +1 -0
  135. package/dist/shape.js +2 -0
  136. package/dist/shape.js.map +1 -0
  137. package/dist/spec.d.ts +27 -3
  138. package/dist/spec.d.ts.map +1 -1
  139. package/dist/spec.js +22 -1
  140. package/dist/spec.js.map +1 -1
  141. package/dist/statements.d.ts +16 -3
  142. package/dist/statements.d.ts.map +1 -1
  143. package/dist/statements.js +54 -28
  144. package/dist/statements.js.map +1 -1
  145. package/dist/uuid.d.ts +23 -0
  146. package/dist/uuid.d.ts.map +1 -0
  147. package/dist/uuid.js +54 -0
  148. package/dist/uuid.js.map +1 -0
  149. package/pack-provenance.json +7 -0
  150. package/package.json +12 -16
  151. package/src/capacity.ts +34 -54
  152. package/src/changes.ts +361 -0
  153. package/src/close.ts +53 -0
  154. package/src/closed.ts +25 -19
  155. package/src/codec.ts +379 -0
  156. package/src/compile.ts +149 -0
  157. package/src/db-native.ts +247 -0
  158. package/src/db.ts +461 -1632
  159. package/src/errors.ts +50 -0
  160. package/src/face.ts +2 -2
  161. package/src/fields.ts +182 -55
  162. package/src/index.ts +62 -126
  163. package/src/internal/log.ts +51 -0
  164. package/src/law.ts +13 -28
  165. package/src/lower.ts +9 -4
  166. package/src/migration.ts +69 -0
  167. package/src/native.ts +326 -487
  168. package/src/query/atom.ts +61 -25
  169. package/src/query/compute.ts +237 -0
  170. package/src/query/find.ts +31 -12
  171. package/src/query/lower.ts +531 -143
  172. package/src/query/parse-ir.ts +18 -13
  173. package/src/query/run.ts +32 -16
  174. package/src/query/scope.ts +140 -8
  175. package/src/relation.ts +17 -21
  176. package/src/result.ts +130 -0
  177. package/src/rows.ts +404 -0
  178. package/src/runtime-codes.ts +18 -0
  179. package/src/runtime-errors.ts +69 -0
  180. package/src/runtime-native.ts +242 -0
  181. package/src/runtime.ts +440 -0
  182. package/src/scalar.ts +560 -0
  183. package/src/schema.ts +35 -37
  184. package/src/shape.ts +31 -0
  185. package/src/spec.ts +33 -3
  186. package/src/statements.ts +75 -68
  187. package/src/uuid.ts +69 -0
  188. package/dist/marshal.d.ts +0 -44
  189. package/dist/marshal.d.ts.map +0 -1
  190. package/dist/marshal.js +0 -165
  191. package/dist/marshal.js.map +0 -1
  192. package/src/marshal.ts +0 -200
package/src/native.ts CHANGED
@@ -1,44 +1,47 @@
1
1
  import { createRequire } from "node:module"
2
- import * as errors from "@superbuilders/errors"
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
- /** The opaque database handle (owns the LMDB environment + exclusive lock). */
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
- type InstanceHandle = { readonly __brand: "bumbledb.instance" }
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 codec (`crates/bumbledb-log`): descriptor
22
- * parsed once vocabulary + braid map beside the fingerprint the wire
23
- * pins. Immutable plain data; no lifecycle verbs.
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 LogCodecHandle = { readonly __brand: "bumbledb.logCodec" }
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
- type FactValue = boolean | bigint | string | Uint8Array | IntervalValue
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 = { readonly kind: "var" } | { readonly kind: "aggregate"; readonly op: HeadOpIr }
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 = { readonly kind: "sum" } | { readonly kind: "min" } | { readonly kind: "max" }
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 log grammar lane's domain outcome: the payload, or a refusal row
143
- * whose `kind` is an identity string spelled exactly as
144
- * `crates/bumbledb-log` spells it (the `log-identities.json` mint table).
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
- /** `DecodeError::identity` the batch decode refusal identities. */
151
- type LogBatchDecodeKind =
152
- | "Truncated"
153
- | "BadMagic"
154
- | "Version"
155
- | "Flags"
156
- | "FingerprintMismatch"
157
- | "UnknownBraid"
158
- | "UnknownOpKind"
159
- | "UnknownRelation"
160
- | "ClosedRelation"
161
- | "OpRelationOutsideBraid"
162
- | "TagMismatch"
163
- | "BoolByte"
164
- | "InvalidUtf8"
165
- | "EmptyInterval"
166
- | "IntervalOverflow"
167
- | "TrailingBytes"
168
-
169
- /** The batch encode refusal identities (`EncodeError`, bridge-spelled). */
170
- type LogBatchEncodeKind =
171
- | "FingerprintMismatch"
172
- | "UnknownBraid"
173
- | "UnknownRelation"
174
- | "ClosedRelation"
175
- | "OpRelationOutsideBraid"
176
- | "Arity"
177
- | "Value"
178
- | "TooManyOps"
179
- | "TooManyRows"
180
-
181
- /** `ManifestError::identity`. */
182
- type LogManifestKind = "Malformed" | "Version"
183
-
184
- /** `CheckpointError::identity`. */
185
- type LogCheckpointKind = "Malformed" | "Version" | "Overflow" | "UnknownBraid" | "BraidSet"
186
-
187
- /** `SidecarError::identity`. */
188
- type LogSidecarKind = "Malformed" | "Version" | "UnknownBraid" | "Overflow"
189
-
190
- /**
191
- * The batch header both directions. The codec handle is the fingerprint
192
- * authority — the wire never carries one. `braid` is the raw braid id
193
- * (the smallest relation id in its component).
194
- */
195
- interface LogBatchHeader {
196
- readonly braid: number
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 LogOpKind = "insert" | "delete"
236
+ type LogCondition = { readonly kind: "unconditional" } | { readonly kind: "exactState"; readonly state: LogStateStamp }
204
237
 
205
- /**
206
- * One op inbound to `logEncodeBatch`: rows carry TAGGED values (the
207
- * query-literal lane's inbound spelling) so the bridge stays layout-blind
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
- /** One decoded op: rows cross exactly as the engine's `ValueOut` walk. */
217
- interface LogOpOut {
218
- readonly kind: LogOpKind
219
- readonly relation: number
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 LogBatch {
224
- readonly header: LogBatchHeader
225
- readonly ops: readonly LogOpOut[]
249
+ interface LogCommandRef {
250
+ readonly identity: LogIdentity
251
+ readonly receiptEpoch: bigint
252
+ readonly requestId: string
253
+ readonly digest: Uint8Array
226
254
  }
227
255
 
228
- interface LogBraidComponent {
229
- readonly braid: number
230
- readonly relations: readonly number[]
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
- /** The braid decomposition + serial-at statement ids of one theory. */
234
- interface LogBraids {
235
- readonly components: readonly LogBraidComponent[]
236
- readonly serialAt: readonly number[]
262
+ interface LogReceipt {
263
+ readonly command: LogCommandRef
264
+ readonly decisionAt: LogDecisionStamp
265
+ readonly stateAt: LogStateStamp
266
+ readonly outcome: LogOutcomeWire
237
267
  }
238
268
 
239
- /** The manifest document: an absent `checkpoint` is the store-birth null arm. */
240
- interface LogManifestDoc {
241
- readonly fingerprint: Uint8Array
242
- readonly checkpoint?: Uint8Array
269
+ interface LogLimits {
270
+ readonly envelopeBytes: bigint
271
+ readonly changeBytes: bigint
272
+ readonly evidenceBytes: bigint
273
+ readonly resultBytes: bigint
243
274
  }
244
275
 
245
- interface LogCheckpointHead {
246
- readonly braid: number
247
- readonly g: bigint
248
- readonly hash: Uint8Array
249
- readonly ts: bigint
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
- /** The `ckpt/{digest}` document. Derived facts (digest, vector sum) stay derived. */
253
- interface LogCheckpointDoc {
254
- readonly braids: readonly LogCheckpointHead[]
255
- readonly catalog: Uint8Array
256
- readonly writer: bigint
257
- readonly prev?: Uint8Array
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
- interface LogChainEntry {
261
- readonly braid: number
262
- readonly g: bigint
263
- readonly prev: Uint8Array
264
- readonly ts: bigint
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 LogPendingBatch {
268
- readonly braid: number
269
- readonly slot: bigint
270
- readonly bytes: Uint8Array
319
+ interface LogAuthority {
320
+ readonly identity: LogIdentity
321
+ readonly revision: bigint
322
+ readonly lifecycle: LogLifecycle
323
+ readonly activation: LogActivation
271
324
  }
272
325
 
273
- /** The chain sidecar document: an absent `pending` is the `Settled` arm. */
274
- interface LogChain {
275
- readonly entries: readonly LogChainEntry[]
276
- readonly pending?: LogPendingBatch
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
- type CreateResult =
387
- | { readonly tag: "accepted"; readonly db: DbHandle }
388
- | { readonly tag: "rejected"; readonly violations: readonly Violation[] }
389
- | { readonly tag: "schemaError"; readonly message: string }
390
- | { readonly tag: "newtypeMismatch"; readonly message: string }
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
- dbCreate(path: string, spec: SchemaSpec): Promise<CreateResult>
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
- dbWrite(db: DbHandle, callback: (tx: TxHandle) => boolean): NativeWriteOutcome
487
+ logIdentities(): string
499
488
 
500
- dbWriteFrom(db: DbHandle, witness: WitnessHandle, callback: (tx: TxHandle) => boolean): NativeWriteOutcome
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
- txDelete(tx: TxHandle, relationId: number, rows: bigint, cells: readonly FactValue[]): WireMutationReport
491
+ logSchemaFingerprint(schema: LogSchemaHandle): string
517
492
 
518
- txContains(tx: TxHandle, relationId: number, values: readonly FactValue[]): boolean
493
+ logReceiptKey(id: LogCommandId): Uint8Array
519
494
 
520
- txGet(tx: TxHandle, relationId: number, keyStatementId: number, keyValues: readonly FactValue[]): FactValue[] | null
495
+ logReceiptEncode(receipt: LogReceipt, limits: LogLimits): LogResult<Uint8Array, LogReceiptKind>
521
496
 
522
- txReserve(tx: TxHandle, relationId: number, fieldId: number, count: bigint): WireFreshRange
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
- dbPrepare(db: DbHandle, query: ParsedQuery): PrepareResult
503
+ logReceiptDecodeAt(id: LogCommandId, bytes: Uint8Array, limits: LogLimits): LogResult<LogReceipt, LogReceiptKind>
525
504
 
526
- preparedExecute(prepared: PreparedHandle, instance: InstanceHandle, params: readonly QueryParam[]): FactValue[][]
505
+ logControlEncode(authority: LogAuthority, cap: bigint): LogResult<Uint8Array, LogFrameKind>
527
506
 
528
- preparedClose(prepared: PreparedHandle): void
507
+ logControlDecode(bytes: Uint8Array, cap: bigint): LogResult<LogAuthority, LogFrameKind>
529
508
 
530
- instanceBuilderNew(spec: SchemaSpec): BuilderHandle
509
+ logGenesisEncode(record: LogGenesis, cap: bigint): LogResult<Uint8Array, LogFrameKind>
531
510
 
532
- instanceBuilderLoad(
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
- ownedCount(instance: OwnedHandle, relationId: number): bigint
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
- logParseCkptScratch(bytes: Uint8Array): Uint8Array | null
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
- interface NativeBinding extends Native {
602
- dbClose(db: DbHandle): void
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 = errors.trySync(() => requireNative.resolve(`${platformPackage}/package.json`))
609
- if (present.error) {
610
- throw errors.wrap(
611
- present.error,
612
- `no native binary for ${platform}-${arch}: @bjornpagen/bumbledb ships ${SHIPPED_PLATFORMS.join(", ")} only`
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 = errors.trySync(() => requireNative(platformPackage))
617
- if (loaded.error) {
618
- throw errors.wrap(loaded.error, `load the ${platformPackage} native binary (package present but unloadable)`)
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.data
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 binding.blake3Hash(data)
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 binding.descriptor(spec)
596
+ return ensureNativeBinding().descriptor(spec)
652
597
  })
653
598
  }
654
599
 
655
600
  /**
656
- * @internal the sealed per-theory log codec off the `DescriptorWire`
657
- * one implementation of the protocol grammar (`crates/bumbledb-log`),
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 internalLogCodec(descriptor: SealedDescriptor): LogCodecHandle {
662
- return bridged("bumbledb-log codec", function sealCodec() {
663
- return binding.logCodec(descriptor)
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 braid decomposition + serial-at statement ids, riding
669
- * the same `DescriptorWire`; the driver caches the result per theory
670
- * beside the codec handle. Not SDK API.
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 internalLogBraidsOf(descriptor: SealedDescriptor): LogBraids {
673
- return bridged("bumbledb-log braids", function deriveBraids() {
674
- return binding.logBraidsOf(descriptor)
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
- const error = errors.new(`bumbledb ${caught.kind}: ${caught.message}`)
772
- Object.defineProperty(error, "kind", { value: caught.kind, enumerable: true })
773
- return error
634
+ return new NativeReportedError({
635
+ kind: caught.kind,
636
+ message: `bumbledb ${caught.kind}: ${caught.message}`,
637
+ cause: caught
638
+ })
774
639
  }
775
- return errors.new(String(caught))
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
- const inner = errorFromThrow(caught)
783
- throw errors.wrap(inner, `${context}: ${inner.message}`)
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
- LogBatch,
815
- LogBatchDecodeKind,
816
- LogBatchEncodeKind,
817
- LogBatchHeader,
818
- LogBraidComponent,
819
- LogBraids,
820
- LogChain,
821
- LogChainEntry,
822
- LogCheckpointDoc,
823
- LogCheckpointHead,
824
- LogCheckpointKind,
825
- LogCodecHandle,
826
- LogManifestDoc,
827
- LogManifestKind,
828
- LogOpIn,
829
- LogOpKind,
830
- LogOpOut,
831
- LogPendingBatch,
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
- LogSidecarKind,
834
- Manifest,
835
- NativeWriteOutcome,
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
- internalLogBraidsOf,
868
- internalLogCodec,
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
  }