@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/dist/native.d.ts CHANGED
@@ -1,50 +1,42 @@
1
1
  import type { SchemaSpec, ValueSpec, ValueTypeSpec } from "./spec.js";
2
- /** The opaque database handle (owns the LMDB environment + exclusive lock). */
2
+ /**
3
+ * The opaque managed database capability. The native runtime registry —
4
+ * not this wrapper — owns the LMDB environment, the kernel directory
5
+ * lock and every session; a retained wrapper after a completed close is
6
+ * inert. Minted only by the managed handshake
7
+ * (`runtimeDirectoryDbOpen` → `runtimeDbTake` in #runtime-native.ts).
8
+ */
3
9
  type DbHandle = {
4
10
  readonly __brand: "bumbledb.db";
5
11
  };
6
- type InstanceHandle = {
7
- readonly __brand: "bumbledb.instance";
8
- };
9
- type WitnessHandle = {
10
- readonly __brand: "bumbledb.witness";
11
- };
12
- type BuilderHandle = {
13
- readonly __brand: "bumbledb.builder";
14
- };
15
- type OwnedHandle = {
16
- readonly __brand: "bumbledb.owned";
17
- };
18
- type TxHandle = {
19
- readonly __brand: "bumbledb.tx";
20
- };
21
- type PreparedHandle = {
22
- readonly __brand: "bumbledb.prepared";
23
- };
12
+ /** Admitted owned instance attached through directory publish — not a JS builder. */
24
13
  /**
25
- * The sealed per-theory log codec (`crates/bumbledb-log`): descriptor
26
- * parsed once vocabulary + braid map beside the fingerprint the wire
27
- * pins. Immutable plain data; no lifecycle verbs.
14
+ * The sealed per-theory log schema (`crates/bumbledb-log` successor
15
+ * lanes): the validated core schema plus its fingerprint, shared by the
16
+ * command/decision grammar. Immutable plain data; no lifecycle verbs.
28
17
  */
29
- type LogCodecHandle = {
30
- readonly __brand: "bumbledb.logCodec";
31
- };
32
- interface WireMutationReport {
33
- readonly submitted: bigint;
34
- readonly changed: bigint;
35
- }
36
- type WireFreshRange = {
37
- readonly empty: true;
38
- } | {
39
- readonly empty: false;
40
- readonly start: bigint;
41
- readonly endExclusive: bigint;
18
+ type LogSchemaHandle = {
19
+ readonly __brand: "bumbledb.logSchema";
42
20
  };
21
+ /** A discrete half-open interval `[start, end)` over u64/i64. */
43
22
  interface IntervalValue {
44
23
  readonly start: bigint;
45
24
  readonly end: bigint;
46
25
  }
47
- type FactValue = boolean | bigint | string | Uint8Array | IntervalValue;
26
+ /**
27
+ * A dense-line half-open interval with canonical binary64 endpoints:
28
+ * NaN-free, strictly ordered; ±Infinity are unbounded endpoints.
29
+ */
30
+ interface F64IntervalValue {
31
+ readonly start: number;
32
+ readonly end: number;
33
+ }
34
+ /**
35
+ * One marshalled cell. An application-owned Uuid crosses as its
36
+ * canonical hyphenated UUID string (chapter 32); there is no fresh
37
+ * range, reservation counter or issuance value anywhere on this wire.
38
+ */
39
+ type FactValue = boolean | bigint | number | string | Uint8Array | IntervalValue | F64IntervalValue;
48
40
  type TaggedValue = ValueSpec;
49
41
  type QueryParam = TaggedValue | {
50
42
  readonly kind: "set";
@@ -73,11 +65,56 @@ interface RecIr {
73
65
  }
74
66
  type HeadTermIr = {
75
67
  readonly kind: "var";
68
+ } | {
69
+ readonly kind: "compute";
76
70
  } | {
77
71
  readonly kind: "aggregate";
78
72
  readonly op: HeadOpIr;
79
73
  };
80
- type HeadOpIr = "sum" | "min" | "max" | "count" | "pack";
74
+ type HeadOpIr = "sum" | "mean" | "min" | "max" | "count" | "pack";
75
+ /**
76
+ * The computed-find scalar expression (C05 `FindTerm::Compute(ScalarExpr)`):
77
+ * exactly the frozen core roster, spelled as the migration plan JSON spells
78
+ * the same expressions (one grammar, no second evaluator). `var` binds a
79
+ * rule variable ordinal on this lane.
80
+ */
81
+ type NumericCastIr = "toF64" | "toF64Exact" | "toI64Exact" | "toU64Exact";
82
+ type ScalarExprIr = {
83
+ readonly kind: "var";
84
+ readonly var: number;
85
+ } | {
86
+ readonly kind: "literal";
87
+ readonly value: TaggedValue;
88
+ } | {
89
+ readonly kind: "negate";
90
+ readonly expr: ScalarExprIr;
91
+ } | {
92
+ readonly kind: "add";
93
+ readonly left: ScalarExprIr;
94
+ readonly right: ScalarExprIr;
95
+ } | {
96
+ readonly kind: "subtract";
97
+ readonly left: ScalarExprIr;
98
+ readonly right: ScalarExprIr;
99
+ } | {
100
+ readonly kind: "multiply";
101
+ readonly left: ScalarExprIr;
102
+ readonly right: ScalarExprIr;
103
+ } | {
104
+ readonly kind: "divide";
105
+ readonly left: ScalarExprIr;
106
+ readonly right: ScalarExprIr;
107
+ } | {
108
+ readonly kind: "cast";
109
+ readonly cast: NumericCastIr;
110
+ readonly expr: ScalarExprIr;
111
+ } | {
112
+ readonly kind: "isNaN";
113
+ readonly expr: ScalarExprIr;
114
+ } | {
115
+ readonly kind: "isFinite";
116
+ readonly expr: ScalarExprIr;
117
+ };
81
118
  interface RuleIr {
82
119
  readonly finds: readonly FindTermIr[];
83
120
  readonly atoms: readonly AtomIr[];
@@ -86,6 +123,8 @@ interface RuleIr {
86
123
  }
87
124
  type FoldOpIr = {
88
125
  readonly kind: "sum";
126
+ } | {
127
+ readonly kind: "mean";
89
128
  } | {
90
129
  readonly kind: "min";
91
130
  } | {
@@ -94,6 +133,9 @@ type FoldOpIr = {
94
133
  type FindTermIr = {
95
134
  readonly kind: "var";
96
135
  readonly var: number;
136
+ } | {
137
+ readonly kind: "compute";
138
+ readonly expr: ScalarExprIr;
97
139
  } | {
98
140
  readonly kind: "count";
99
141
  } | {
@@ -110,6 +152,8 @@ type ParsedQuery = QueryIr & {
110
152
  };
111
153
  type AggOpIr = {
112
154
  readonly kind: "sum";
155
+ } | {
156
+ readonly kind: "mean";
113
157
  } | {
114
158
  readonly kind: "min";
115
159
  } | {
@@ -178,9 +222,9 @@ type ConditionTreeIr = {
178
222
  };
179
223
  type StatementKindTag = "functionality" | "containment" | "capacity";
180
224
  /**
181
- * A log grammar lane's domain outcome: the payload, or a refusal row
182
- * whose `kind` is an identity string spelled exactly as
183
- * `crates/bumbledb-log` spells it (the `log-identities.json` mint table).
225
+ * A grammar lane's domain outcome: the payload, or a refusal row whose
226
+ * `kind` is an identity string spelled exactly as `bumbledb-log`'s
227
+ * identities emitter spells it (`logIdentities()` / log-identities.json).
184
228
  */
185
229
  type LogResult<T, K extends string> = {
186
230
  readonly ok: true;
@@ -190,98 +234,155 @@ type LogResult<T, K extends string> = {
190
234
  readonly kind: K;
191
235
  readonly message: string;
192
236
  };
193
- /** `DecodeError::identity` the batch decode refusal identities. */
194
- type LogBatchDecodeKind = "Truncated" | "BadMagic" | "Version" | "Flags" | "FingerprintMismatch" | "UnknownBraid" | "UnknownOpKind" | "UnknownRelation" | "ClosedRelation" | "OpRelationOutsideBraid" | "TagMismatch" | "BoolByte" | "InvalidUtf8" | "EmptyInterval" | "IntervalOverflow" | "TrailingBytes";
195
- /** The batch encode refusal identities (`EncodeError`, bridge-spelled). */
196
- type LogBatchEncodeKind = "FingerprintMismatch" | "UnknownBraid" | "UnknownRelation" | "ClosedRelation" | "OpRelationOutsideBraid" | "Arity" | "Value" | "TooManyOps" | "TooManyRows";
197
- /** `ManifestError::identity`. */
198
- type LogManifestKind = "Malformed" | "Version";
199
- /** `CheckpointError::identity`. */
200
- type LogCheckpointKind = "Malformed" | "Version" | "Overflow" | "UnknownBraid" | "BraidSet";
201
- /** `SidecarError::identity`. */
202
- type LogSidecarKind = "Malformed" | "Version" | "UnknownBraid" | "Overflow";
203
- /**
204
- * The batch header both directions. The codec handle is the fingerprint
205
- * authority — the wire never carries one. `braid` is the raw braid id
206
- * (the smallest relation id in its component).
207
- */
208
- interface LogBatchHeader {
209
- readonly braid: number;
210
- readonly braidGen: bigint;
211
- readonly prev: Uint8Array;
212
- readonly writer: bigint;
213
- readonly timestamp: bigint;
214
- }
215
- type LogOpKind = "insert" | "delete";
216
- /**
217
- * One op inbound to `logEncodeBatch`: rows carry TAGGED values (the
218
- * query-literal lane's inbound spelling) so the bridge stays layout-blind
219
- * and the codec core is the one judge of every cell.
220
- */
221
- interface LogOpIn {
222
- readonly kind: LogOpKind;
223
- readonly relation: number;
224
- readonly rows: ReadonlyArray<readonly TaggedValue[]>;
225
- }
226
- /** One decoded op: rows cross exactly as the engine's `ValueOut` walk. */
227
- interface LogOpOut {
228
- readonly kind: LogOpKind;
229
- readonly relation: number;
230
- readonly rows: FactValue[][];
237
+ /** `FrameError` kinds (the `frame` identity family). */
238
+ type LogFrameKind = "limitExceeded" | "lengthOverflow" | "allocation" | "truncated" | "family" | "layout" | "kind" | "tag" | "invalidEpoch" | "stateIdentityMismatch" | "emptyChangeSummary" | "emptyEvidence" | "invalidTerminalStamp" | "invalidPreconditionEvidence" | "invalidPolicy" | "invalidSequence" | "invalidCount" | "trailingBytes";
239
+ /** Receipt-row kinds: the frame family plus the foreign-scope refusal. */
240
+ type LogReceiptKind = LogFrameKind | "foreignRow";
241
+ /** Command-lane kinds: frame family plus the two command-only arms. */
242
+ type LogCommandKind = LogFrameKind | "core" | "schemaMismatch";
243
+ /** Chain-step refusals from the decode-and-verify lane. */
244
+ type LogChainKind = "wrongParent" | "wrongSequence";
245
+ /** The complete database scope of every command/receipt/decision. */
246
+ interface LogIdentity {
247
+ /** Application-owned Uuid, canonical hyphenated UUID. */
248
+ readonly databaseId: string;
249
+ readonly incarnationId: string;
250
+ /** The core schema fingerprint, 64 lowercase hex characters. */
251
+ readonly schemaId: string;
231
252
  }
232
- interface LogBatch {
233
- readonly header: LogBatchHeader;
234
- readonly ops: readonly LogOpOut[];
253
+ interface LogStateStamp {
254
+ readonly incarnation: string;
255
+ readonly dataRevision: bigint;
235
256
  }
236
- interface LogBraidComponent {
237
- readonly braid: number;
238
- readonly relations: readonly number[];
257
+ interface LogDecisionStamp {
258
+ readonly seq: bigint;
259
+ readonly hash: Uint8Array;
239
260
  }
240
- /** The braid decomposition + serial-at statement ids of one theory. */
241
- interface LogBraids {
242
- readonly components: readonly LogBraidComponent[];
243
- readonly serialAt: readonly number[];
261
+ type LogCondition = {
262
+ readonly kind: "unconditional";
263
+ } | {
264
+ readonly kind: "exactState";
265
+ readonly state: LogStateStamp;
266
+ };
267
+ interface LogCommandId {
268
+ readonly receiptEpoch: bigint;
269
+ readonly requestId: string;
244
270
  }
245
- /** The manifest document: an absent `checkpoint` is the store-birth null arm. */
246
- interface LogManifestDoc {
247
- readonly fingerprint: Uint8Array;
248
- readonly checkpoint?: Uint8Array;
271
+ interface LogCommandMetadata {
272
+ readonly identity: LogIdentity;
273
+ readonly id: LogCommandId;
274
+ readonly condition: LogCondition;
249
275
  }
250
- interface LogCheckpointHead {
251
- readonly braid: number;
252
- readonly g: bigint;
253
- readonly hash: Uint8Array;
254
- readonly ts: bigint;
276
+ interface LogCommandRef {
277
+ readonly identity: LogIdentity;
278
+ readonly receiptEpoch: bigint;
279
+ readonly requestId: string;
280
+ readonly digest: Uint8Array;
255
281
  }
256
- /** The `ckpt/{digest}` document. Derived facts (digest, vector sum) stay derived. */
257
- interface LogCheckpointDoc {
258
- readonly braids: readonly LogCheckpointHead[];
259
- readonly catalog: Uint8Array;
260
- readonly writer: bigint;
261
- readonly prev?: Uint8Array;
282
+ type LogOutcomeWire = {
283
+ readonly kind: "committed";
284
+ readonly added: bigint;
285
+ readonly removed: bigint;
286
+ readonly result?: Uint8Array;
287
+ } | {
288
+ readonly kind: "noChange";
289
+ readonly result?: Uint8Array;
290
+ } | {
291
+ readonly kind: "preconditionFailed";
292
+ readonly expected: LogStateStamp;
293
+ readonly observed: LogStateStamp;
294
+ } | {
295
+ readonly kind: "invariantRejected";
296
+ readonly evidence: Uint8Array;
297
+ };
298
+ interface LogReceipt {
299
+ readonly command: LogCommandRef;
300
+ readonly decisionAt: LogDecisionStamp;
301
+ readonly stateAt: LogStateStamp;
302
+ readonly outcome: LogOutcomeWire;
262
303
  }
263
- interface LogChainEntry {
264
- readonly braid: number;
265
- readonly g: bigint;
266
- readonly prev: Uint8Array;
267
- readonly ts: bigint;
304
+ interface LogLimits {
305
+ readonly envelopeBytes: bigint;
306
+ readonly changeBytes: bigint;
307
+ readonly evidenceBytes: bigint;
308
+ readonly resultBytes: bigint;
268
309
  }
269
- interface LogPendingBatch {
270
- readonly braid: number;
271
- readonly slot: bigint;
272
- readonly bytes: Uint8Array;
310
+ type LogAccess = {
311
+ readonly kind: "active";
312
+ } | {
313
+ readonly kind: "frozen";
314
+ readonly operation: string;
315
+ readonly intent: {
316
+ readonly kind: "erasure";
317
+ } | {
318
+ readonly kind: "migration";
319
+ readonly planSetDigest: Uint8Array;
320
+ readonly target: string;
321
+ };
322
+ };
323
+ type LogLifecycle = {
324
+ readonly kind: "live";
325
+ readonly access: LogAccess;
326
+ readonly decision: LogDecisionStamp;
327
+ readonly state: LogStateStamp;
328
+ readonly receipts: {
329
+ readonly openEpoch: bigint;
330
+ readonly retiredThrough: bigint;
331
+ };
332
+ } | {
333
+ readonly kind: "deleted";
334
+ readonly operation: string;
335
+ readonly reason: {
336
+ readonly kind: "erasure";
337
+ } | {
338
+ readonly kind: "migrationAborted";
339
+ readonly sourceDatabase: string;
340
+ readonly sourceIncarnation: string;
341
+ readonly planSetDigest: Uint8Array;
342
+ };
343
+ };
344
+ type LogActivation = {
345
+ readonly kind: "notActivated";
346
+ } | {
347
+ readonly kind: "activated";
348
+ readonly operation: string;
349
+ readonly targetGenesis: Uint8Array;
350
+ readonly cause: {
351
+ readonly kind: "create";
352
+ } | {
353
+ readonly kind: "restore";
354
+ } | {
355
+ readonly kind: "migration";
356
+ readonly planSetDigest: Uint8Array;
357
+ };
358
+ };
359
+ interface LogAuthority {
360
+ readonly identity: LogIdentity;
361
+ readonly revision: bigint;
362
+ readonly lifecycle: LogLifecycle;
363
+ readonly activation: LogActivation;
273
364
  }
274
- /** The chain sidecar document: an absent `pending` is the `Settled` arm. */
275
- interface LogChain {
276
- readonly entries: readonly LogChainEntry[];
277
- readonly pending?: LogPendingBatch;
365
+ type LogGenesisProvenance = {
366
+ readonly kind: "create";
367
+ } | {
368
+ readonly kind: "restore";
369
+ readonly sourceEvidence: Uint8Array;
370
+ } | {
371
+ readonly kind: "migration";
372
+ readonly sourceDatabase: string;
373
+ readonly sourceIncarnation: string;
374
+ readonly planSetDigest: Uint8Array;
375
+ };
376
+ interface LogGenesis {
377
+ readonly identity: LogIdentity;
378
+ readonly initialApplicationDigest: Uint8Array;
379
+ readonly initialSystemDigest: Uint8Array;
380
+ readonly provenance: LogGenesisProvenance;
278
381
  }
279
382
  interface ManifestField {
280
383
  readonly name: string;
281
384
  readonly id: number;
282
385
  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
386
  /** 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
387
  readonly newtype?: string;
287
388
  }
@@ -299,15 +400,6 @@ interface ManifestRelation {
299
400
  readonly fields: readonly ManifestField[];
300
401
  readonly extension?: readonly ManifestRow[];
301
402
  }
302
- interface ManifestStatement {
303
- readonly id: number;
304
- readonly kind: StatementKindTag;
305
- readonly spelling: string;
306
- }
307
- interface Manifest {
308
- readonly relations: readonly ManifestRelation[];
309
- readonly statements: readonly ManifestStatement[];
310
- }
311
403
  interface SealedSide {
312
404
  readonly relation: number;
313
405
  readonly projection: readonly number[];
@@ -386,159 +478,48 @@ type Violation = {
386
478
  readonly measure: bigint;
387
479
  readonly facts: readonly ViolationFact[];
388
480
  };
389
- type CreateResult = {
390
- readonly tag: "accepted";
391
- readonly db: DbHandle;
392
- } | {
393
- readonly tag: "rejected";
394
- readonly violations: readonly Violation[];
395
- } | {
396
- readonly tag: "schemaError";
397
- readonly message: string;
398
- } | {
399
- readonly tag: "newtypeMismatch";
400
- readonly message: string;
401
- };
402
- /**
403
- * `dbOpen`'s domain outcome. `schemaError` spans both spec
404
- * resolution (unresolvable names, banned spellings — every issue in one
405
- * message) and schema validation at the declaration boundary;
406
- * `newtypeMismatch` is the coherence wall's own kind; `fingerprintMismatch`
407
- * is `dbOpen`'s stored-theory refusal.
408
- */
409
- type DbOpenResult = {
410
- readonly ok: true;
411
- readonly db: DbHandle;
412
- } | {
413
- readonly ok: false;
414
- readonly kind: "schemaError" | "newtypeMismatch" | "fingerprintMismatch";
415
- readonly message: string;
416
- };
417
- type NativeWriteOutcome = {
418
- readonly tag: "accepted";
419
- readonly generation: bigint;
420
- } | {
421
- readonly tag: "rejected";
422
- readonly violations: readonly Violation[];
423
- } | {
424
- readonly tag: "abandoned";
425
- } | {
426
- readonly tag: "moved";
427
- readonly witnessed: bigint;
428
- readonly current: bigint;
429
- };
430
- type AdmitResult = {
431
- readonly tag: "accepted";
432
- readonly value: OwnedHandle;
433
- } | {
434
- readonly tag: "rejected";
435
- readonly violations: readonly Violation[];
436
- };
437
- type PrepareResult = {
438
- readonly ok: true;
439
- readonly prepared: PreparedHandle;
440
- } | {
441
- readonly ok: false;
442
- readonly kind: "irError";
443
- readonly message: string;
444
- };
445
- type ErrorFamilyKind = "formatMismatch" | "schemaMismatch" | "alreadyInitialized" | "destinationExists" | "publishedButUnsynced" | "environmentLocked" | "io" | "lmdb" | "readersFull" | "schema" | "validation" | "factShape" | "freshExhausted" | "closedRelationWrite" | "commitSync" | "transactionPoisoned" | "foreignPrepared" | "foreignWitness" | "param" | "capacityRayMeasure" | "derivedBudgetExceeded" | "overflow" | "resultBytesOverflow" | "corruption";
481
+ type ErrorFamilyKind = "formatMismatch" | "schemaMismatch" | "alreadyInitialized" | "destinationExists" | "publishedButUnsynced" | "environmentLocked" | "io" | "lmdb" | "readersFull" | "schema" | "validation" | "factShape" | "closedRelationWrite" | "commitSync" | "transactionPoisoned" | "foreignPrepared" | "foreignWitness" | "param" | "capacityRayMeasure" | "derivedBudgetExceeded" | "overflow" | "scalar" | "resultBytesOverflow" | "corruption" | "store";
446
482
  type AdmissionTag = "accepted" | "rejected";
447
483
  type WriteTag = "accepted" | "rejected" | "abandoned" | "moved";
448
- type OpenKind = "schemaError" | "newtypeMismatch" | "fingerprintMismatch";
484
+ type OpenKind = "schemaError" | "newtypeMismatch" | "fingerprintMismatch" | "destinationExists";
449
485
  type PrepareKind = "irError";
450
486
  interface Native {
451
487
  engineVersion(): string;
488
+ /** Small identity-sized inputs only; bulk hashing rides `runtimeHash`. */
452
489
  blake3Hash(data: Uint8Array): Uint8Array;
453
490
  descriptor(spec: SchemaSpec): SealedDescriptor;
454
- dbCreate(path: string, spec: SchemaSpec): Promise<CreateResult>;
455
- dbOpen(path: string, spec: SchemaSpec): Promise<DbOpenResult>;
456
- dbManifest(db: DbHandle): Manifest;
457
- dbFingerprint(db: DbHandle): string;
458
- dbGeneration(db: DbHandle): bigint;
459
- /**
460
- * blake3 over the canonical catalog enumeration — the replication
461
- * equality oracle: equal digests imply identical judged content
462
- * regardless of page layout or allocation history.
463
- */
464
- dbCatalogDigest(db: DbHandle): Uint8Array;
465
- dbFromInstance(path: string, instance: OwnedHandle): Promise<DbHandle>;
466
- /**
467
- * Runs `callback` synchronously inside the engine read lease. The
468
- * instance handle is invalid after the callback returns; the witness
469
- * handle is a clone and may escape.
470
- */
471
- dbRead<R>(db: DbHandle, callback: (instance: InstanceHandle, witness: WitnessHandle) => R): R;
472
- instanceGeneration(instance: InstanceHandle): bigint;
473
- instanceScan(instance: InstanceHandle, relationId: number): FactValue[][];
474
- instanceCount(instance: InstanceHandle, relationId: number): bigint;
475
- instanceContains(instance: InstanceHandle, relationId: number, values: readonly FactValue[]): boolean;
476
- instanceGet(instance: InstanceHandle, relationId: number, keyStatementId: number, keyValues: readonly FactValue[]): FactValue[] | null;
477
- instancePrepare(instance: InstanceHandle, query: ParsedQuery): PrepareResult;
478
- witnessClose(witness: WitnessHandle): void;
479
- dbWrite(db: DbHandle, callback: (tx: TxHandle) => boolean): NativeWriteOutcome;
480
- dbWriteFrom(db: DbHandle, witness: WitnessHandle, callback: (tx: TxHandle) => boolean): NativeWriteOutcome;
481
- /**
482
- * Records a collection of inserts into the delta; returns the engine
483
- * `{ submitted, changed }` report. `cells` is ONE flat row-major array
484
- * (length rows×arity) in sealed field order, and `rows` is the EXPLICIT
485
- * row count the caller states — the one collection crossing: the JS side
486
- * alone knows N when the roster is fieldless (N nullary facts project to 0 cells, so no
487
- * derivation can recover N), and the bridge verifies
488
- * `cells.length === rows × arity` exactly against its resident sealed
489
- * roster before building the engine's shape-proved collection in a
490
- * single pass. Empty (`rows === 0n`, no cells) is lawful and still a
491
- * mutation. Nothing is judged until commit; shape violations throw
492
- * typed, naming relation and field.
493
- */
494
- txInsert(tx: TxHandle, relationId: number, rows: bigint, cells: readonly FactValue[]): WireMutationReport;
495
- txDelete(tx: TxHandle, relationId: number, rows: bigint, cells: readonly FactValue[]): WireMutationReport;
496
- txContains(tx: TxHandle, relationId: number, values: readonly FactValue[]): boolean;
497
- txGet(tx: TxHandle, relationId: number, keyStatementId: number, keyValues: readonly FactValue[]): FactValue[] | null;
498
- txReserve(tx: TxHandle, relationId: number, fieldId: number, count: bigint): WireFreshRange;
499
- dbPrepare(db: DbHandle, query: ParsedQuery): PrepareResult;
500
- preparedExecute(prepared: PreparedHandle, instance: InstanceHandle, params: readonly QueryParam[]): FactValue[][];
501
- preparedClose(prepared: PreparedHandle): void;
502
- instanceBuilderNew(spec: SchemaSpec): BuilderHandle;
503
- instanceBuilderLoad(builder: BuilderHandle, relationId: number, rows: bigint, cells: readonly FactValue[]): WireMutationReport;
504
- instanceBuilderDelete(builder: BuilderHandle, relationId: number, rows: bigint, cells: readonly FactValue[]): WireMutationReport;
505
- instanceBuilderReserve(builder: BuilderHandle, relationId: number, fieldId: number, count: bigint): WireFreshRange;
506
- instanceBuilderContains(builder: BuilderHandle, relationId: number, values: readonly FactValue[]): boolean;
507
- instanceBuilderGet(builder: BuilderHandle, relationId: number, keyStatementId: number, keyValues: readonly FactValue[]): FactValue[] | null;
508
- instanceBuilderClose(builder: BuilderHandle): void;
509
- instanceBuilderAdmit(builder: BuilderHandle): Promise<AdmitResult>;
510
- ownedInstanceClose(instance: OwnedHandle): void;
511
- ownedScan(instance: OwnedHandle, relationId: number): FactValue[][];
512
- ownedCount(instance: OwnedHandle, relationId: number): bigint;
513
- ownedContains(instance: OwnedHandle, relationId: number, values: readonly FactValue[]): boolean;
514
- ownedGet(instance: OwnedHandle, relationId: number, keyStatementId: number, keyValues: readonly FactValue[]): FactValue[] | null;
515
- ownedPrepare(instance: OwnedHandle, query: ParsedQuery): PrepareResult;
516
- ownedExecute(prepared: PreparedHandle, instance: OwnedHandle, params: readonly QueryParam[]): FactValue[][];
517
- logCodec(descriptor: SealedDescriptor): LogCodecHandle;
518
- logBraidsOf(descriptor: SealedDescriptor): LogBraids;
519
- logEncodeBatch(handle: LogCodecHandle, header: LogBatchHeader, ops: readonly LogOpIn[]): LogResult<Uint8Array, LogBatchEncodeKind>;
520
- logDecodeBatch(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogBatch, LogBatchDecodeKind>;
521
- logParseManifest(bytes: Uint8Array): LogResult<LogManifestDoc, LogManifestKind>;
522
- logRenderManifest(doc: LogManifestDoc): Uint8Array;
523
- logParseCheckpoint(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogCheckpointDoc, LogCheckpointKind>;
524
- logRenderCheckpoint(handle: LogCodecHandle, doc: LogCheckpointDoc): Uint8Array;
525
- logParseSidecar(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogChain, LogSidecarKind>;
526
- logRenderSidecar(handle: LogCodecHandle, chain: LogChain): Uint8Array;
527
- logParseCkptScratch(bytes: Uint8Array): Uint8Array | null;
528
- logRenderCkptScratch(digest: Uint8Array): Uint8Array;
491
+ logIdentities(): string;
492
+ logSchema(spec: SchemaSpec): LogSchemaHandle;
493
+ logSchemaFingerprint(schema: LogSchemaHandle): string;
494
+ logReceiptKey(id: LogCommandId): Uint8Array;
495
+ logReceiptEncode(receipt: LogReceipt, limits: LogLimits): LogResult<Uint8Array, LogReceiptKind>;
496
+ logReceiptDecode(expected: {
497
+ readonly identity: LogIdentity;
498
+ readonly receiptEpoch: bigint;
499
+ readonly requestId: string;
500
+ }, bytes: Uint8Array, limits: LogLimits): LogResult<LogReceipt, LogReceiptKind>;
501
+ logReceiptDecodeAt(id: LogCommandId, bytes: Uint8Array, limits: LogLimits): LogResult<LogReceipt, LogReceiptKind>;
502
+ logControlEncode(authority: LogAuthority, cap: bigint): LogResult<Uint8Array, LogFrameKind>;
503
+ logControlDecode(bytes: Uint8Array, cap: bigint): LogResult<LogAuthority, LogFrameKind>;
504
+ logGenesisEncode(record: LogGenesis, cap: bigint): LogResult<Uint8Array, LogFrameKind>;
505
+ logGenesisDecode(bytes: Uint8Array, cap: bigint): LogResult<LogGenesis, LogFrameKind>;
506
+ logGenesisStamp(record: LogGenesis, cap: bigint): LogResult<LogDecisionStamp, LogFrameKind>;
507
+ logBlankDigests(): {
508
+ readonly application: Uint8Array;
509
+ readonly system: Uint8Array;
510
+ };
529
511
  }
530
512
  declare const SHIPPED_PLATFORMS: readonly ["darwin-arm64", "linux-arm64", "linux-x64"];
531
- interface NativeBinding extends Native {
532
- dbClose(db: DbHandle): void;
533
- }
513
+ type NativeBinding = Native;
514
+ /** Lazy singleton: the addon loads on first native access, not module evaluation. */
515
+ declare const native: NativeBinding;
516
+ declare function nativeBindingIsLoaded(): boolean;
534
517
  declare function loadNativeBinding(platform: string, arch: string): NativeBinding;
535
- declare const native: Native;
536
- declare function dbClose(db: DbHandle): void;
537
518
  /**
538
519
  * @internal blake3 of the given bytes via the resident native binding —
539
520
  * the engine's own hash, lent to the replication driver
540
521
  * (`@bjornpagen/bumbledb-log`). Not SDK API; the export is deliberately
541
- * undocumented in the package surface.
522
+ * undocumented in the package surface. Small identity-sized inputs only.
542
523
  */
543
524
  declare function internalBlake3(data: Uint8Array): Uint8Array;
544
525
  /**
@@ -550,44 +531,18 @@ declare function internalBlake3(data: Uint8Array): Uint8Array;
550
531
  */
551
532
  declare function internalDescriptor(spec: SchemaSpec): SealedDescriptor;
552
533
  /**
553
- * @internal the sealed per-theory log codec off the `DescriptorWire`
554
- * one implementation of the protocol grammar (`crates/bumbledb-log`),
555
- * lent to the replication driver (`@bjornpagen/bumbledb-log`). Not SDK
556
- * API; the export is deliberately undocumented in the package surface.
557
- */
558
- declare function internalLogCodec(descriptor: SealedDescriptor): LogCodecHandle;
559
- /**
560
- * @internal the braid decomposition + serial-at statement ids, riding
561
- * the same `DescriptorWire`; the driver caches the result per theory
562
- * beside the codec handle. Not SDK API.
534
+ * @internal the successor identity table emitted by the log core's one
535
+ * speller (`bumbledb_log::identities::emit`). Not SDK API.
563
536
  */
564
- declare function internalLogBraidsOf(descriptor: SealedDescriptor): LogBraids;
565
- /** @internal batch encode through the sealed codec. Not SDK API. */
566
- declare function internalLogEncodeBatch(handle: LogCodecHandle, header: LogBatchHeader, ops: readonly LogOpIn[]): LogResult<Uint8Array, LogBatchEncodeKind>;
567
- /** @internal batch decode through the sealed codec. Not SDK API. */
568
- declare function internalLogDecodeBatch(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogBatch, LogBatchDecodeKind>;
569
- /** @internal manifest document parse — grammar only, no IO. Not SDK API. */
570
- declare function internalLogParseManifest(bytes: Uint8Array): LogResult<LogManifestDoc, LogManifestKind>;
571
- /** @internal the manifest's one encoding, byte-exact for CAS bodies. Not SDK API. */
572
- declare function internalLogRenderManifest(doc: LogManifestDoc): Uint8Array;
573
- /** @internal checkpoint document parse against the theory's braids. Not SDK API. */
574
- declare function internalLogParseCheckpoint(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogCheckpointDoc, LogCheckpointKind>;
575
- /** @internal checkpoint document render. Not SDK API. */
576
- declare function internalLogRenderCheckpoint(handle: LogCodecHandle, doc: LogCheckpointDoc): Uint8Array;
577
- /** @internal chain sidecar parse — the fs half stays in the driver. Not SDK API. */
578
- declare function internalLogParseSidecar(handle: LogCodecHandle, bytes: Uint8Array): LogResult<LogChain, LogSidecarKind>;
579
- /** @internal chain sidecar render. Not SDK API. */
580
- declare function internalLogRenderSidecar(handle: LogCodecHandle, chain: LogChain): Uint8Array;
537
+ declare function internalLogIdentities(): string;
581
538
  /**
582
- * @internal the digest a scratch-lease body names, or null the refusal
583
- * is undifferentiated by law. Not SDK API.
539
+ * @internal the sealed per-theory log schema off the same `SchemaSpec`
540
+ * every other lane speaks one validated core schema, lent to the
541
+ * replication driver (`@bjornpagen/bumbledb-log`). Not SDK API.
584
542
  */
585
- declare function internalLogParseCkptScratch(bytes: Uint8Array): Uint8Array | null;
586
- /** @internal the scratch-lease body: version byte + 32-byte digest. Not SDK API. */
587
- declare function internalLogRenderCkptScratch(digest: Uint8Array): Uint8Array;
543
+ declare function internalLogSchema(spec: SchemaSpec): LogSchemaHandle;
588
544
  declare function errorFromThrow(caught: unknown): Error;
589
545
  declare function bridged<T>(context: string, run: () => T): T;
590
- declare function bridgedAsync<T>(context: string, run: () => Promise<T>): Promise<T>;
591
- export type { AdmissionTag, AdmitResult, AggOpIr, AtomIr, AtomSourceIr, BuilderHandle, CmpOpIr, ComparisonIr, ConditionTreeIr, DbHandle, ErrorFamilyKind, FactValue, FindTermIr, HeadOpIr, HeadTermIr, InstanceHandle, IntervalValue, LogBatch, LogBatchDecodeKind, LogBatchEncodeKind, LogBatchHeader, LogBraidComponent, LogBraids, LogChain, LogChainEntry, LogCheckpointDoc, LogCheckpointHead, LogCheckpointKind, LogCodecHandle, LogManifestDoc, LogManifestKind, LogOpIn, LogOpKind, LogOpOut, LogPendingBatch, LogResult, LogSidecarKind, Manifest, NativeWriteOutcome, OpenKind, OwnedHandle, ParsedQuery, PreparedHandle, PrepareKind, QueryIr, QueryParam, RuleIr, SealedDescriptor, SealedHi, SealedSide, SealedStatement, SealedWeight, StatementKindTag, TaggedValue, TermIr, TxHandle, Violation, ViolationFact, WireFreshRange, WireMutationReport, WitnessHandle, WriteTag };
592
- export { bridged, bridgedAsync, dbClose, errorFromThrow, internalBlake3, internalDescriptor, internalLogBraidsOf, internalLogCodec, internalLogDecodeBatch, internalLogEncodeBatch, internalLogParseCheckpoint, internalLogParseCkptScratch, internalLogParseManifest, internalLogParseSidecar, internalLogRenderCheckpoint, internalLogRenderCkptScratch, internalLogRenderManifest, internalLogRenderSidecar, loadNativeBinding, native, SHIPPED_PLATFORMS };
546
+ export type { AdmissionTag, AggOpIr, AtomIr, AtomSourceIr, CmpOpIr, ComparisonIr, ConditionTreeIr, DbHandle, ErrorFamilyKind, F64IntervalValue, FactValue, FindTermIr, HeadOpIr, HeadTermIr, IntervalValue, LogAccess, LogActivation, LogAuthority, LogChainKind, LogCommandId, LogCommandKind, LogCommandMetadata, LogCommandRef, LogCondition, LogDecisionStamp, LogFrameKind, LogGenesis, LogGenesisProvenance, LogIdentity, LogLifecycle, LogLimits, LogOutcomeWire, LogReceipt, LogReceiptKind, LogResult, LogSchemaHandle, LogStateStamp, NumericCastIr, OpenKind, ParsedQuery, PrepareKind, QueryIr, QueryParam, RuleIr, ScalarExprIr, SealedDescriptor, SealedHi, SealedSide, SealedStatement, SealedWeight, StatementKindTag, TaggedValue, TermIr, Violation, ViolationFact, WriteTag };
547
+ export { bridged, errorFromThrow, internalBlake3, internalDescriptor, internalLogIdentities, internalLogSchema, loadNativeBinding, native, nativeBindingIsLoaded, SHIPPED_PLATFORMS };
593
548
  //# sourceMappingURL=native.d.ts.map