@bjornpagen/bumbledb 0.1.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 (108) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +84 -0
  3. package/dist/brand.d.ts +59 -0
  4. package/dist/brand.d.ts.map +1 -0
  5. package/dist/brand.js +47 -0
  6. package/dist/brand.js.map +1 -0
  7. package/dist/closed.d.ts +97 -0
  8. package/dist/closed.d.ts.map +1 -0
  9. package/dist/closed.js +107 -0
  10. package/dist/closed.js.map +1 -0
  11. package/dist/count.d.ts +55 -0
  12. package/dist/count.d.ts.map +1 -0
  13. package/dist/count.js +92 -0
  14. package/dist/count.js.map +1 -0
  15. package/dist/db.d.ts +341 -0
  16. package/dist/db.d.ts.map +1 -0
  17. package/dist/db.js +1016 -0
  18. package/dist/db.js.map +1 -0
  19. package/dist/exhume.d.ts +130 -0
  20. package/dist/exhume.d.ts.map +1 -0
  21. package/dist/exhume.js +145 -0
  22. package/dist/exhume.js.map +1 -0
  23. package/dist/face.d.ts +91 -0
  24. package/dist/face.d.ts.map +1 -0
  25. package/dist/face.js +69 -0
  26. package/dist/face.js.map +1 -0
  27. package/dist/fields.d.ts +187 -0
  28. package/dist/fields.d.ts.map +1 -0
  29. package/dist/fields.js +204 -0
  30. package/dist/fields.js.map +1 -0
  31. package/dist/index.d.ts +49 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +31 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/lower.d.ts +34 -0
  36. package/dist/lower.d.ts.map +1 -0
  37. package/dist/lower.js +105 -0
  38. package/dist/lower.js.map +1 -0
  39. package/dist/marshal.d.ts +79 -0
  40. package/dist/marshal.d.ts.map +1 -0
  41. package/dist/marshal.js +167 -0
  42. package/dist/marshal.js.map +1 -0
  43. package/dist/native.d.ts +532 -0
  44. package/dist/native.d.ts.map +1 -0
  45. package/dist/native.js +64 -0
  46. package/dist/native.js.map +1 -0
  47. package/dist/query/atom.d.ts +285 -0
  48. package/dist/query/atom.d.ts.map +1 -0
  49. package/dist/query/atom.js +281 -0
  50. package/dist/query/atom.js.map +1 -0
  51. package/dist/query/lower.d.ts +145 -0
  52. package/dist/query/lower.d.ts.map +1 -0
  53. package/dist/query/lower.js +604 -0
  54. package/dist/query/lower.js.map +1 -0
  55. package/dist/query/predicate.d.ts +101 -0
  56. package/dist/query/predicate.d.ts.map +1 -0
  57. package/dist/query/predicate.js +85 -0
  58. package/dist/query/predicate.js.map +1 -0
  59. package/dist/query/run.d.ts +30 -0
  60. package/dist/query/run.d.ts.map +1 -0
  61. package/dist/query/run.js +94 -0
  62. package/dist/query/run.js.map +1 -0
  63. package/dist/query/scope.d.ts +168 -0
  64. package/dist/query/scope.d.ts.map +1 -0
  65. package/dist/query/scope.js +134 -0
  66. package/dist/query/scope.js.map +1 -0
  67. package/dist/query/select.d.ts +106 -0
  68. package/dist/query/select.d.ts.map +1 -0
  69. package/dist/query/select.js +69 -0
  70. package/dist/query/select.js.map +1 -0
  71. package/dist/relation.d.ts +120 -0
  72. package/dist/relation.d.ts.map +1 -0
  73. package/dist/relation.js +108 -0
  74. package/dist/relation.js.map +1 -0
  75. package/dist/schema.d.ts +50 -0
  76. package/dist/schema.d.ts.map +1 -0
  77. package/dist/schema.js +235 -0
  78. package/dist/schema.js.map +1 -0
  79. package/dist/spec.d.ts +218 -0
  80. package/dist/spec.d.ts.map +1 -0
  81. package/dist/spec.js +154 -0
  82. package/dist/spec.js.map +1 -0
  83. package/dist/statements.d.ts +91 -0
  84. package/dist/statements.d.ts.map +1 -0
  85. package/dist/statements.js +101 -0
  86. package/dist/statements.js.map +1 -0
  87. package/package.json +66 -0
  88. package/src/brand.ts +82 -0
  89. package/src/closed.ts +228 -0
  90. package/src/count.ts +117 -0
  91. package/src/db.ts +1519 -0
  92. package/src/exhume.ts +243 -0
  93. package/src/face.ts +161 -0
  94. package/src/fields.ts +385 -0
  95. package/src/index.ts +185 -0
  96. package/src/lower.ts +118 -0
  97. package/src/marshal.ts +220 -0
  98. package/src/native.ts +576 -0
  99. package/src/query/atom.ts +556 -0
  100. package/src/query/lower.ts +855 -0
  101. package/src/query/predicate.ts +195 -0
  102. package/src/query/run.ts +106 -0
  103. package/src/query/scope.ts +301 -0
  104. package/src/query/select.ts +140 -0
  105. package/src/relation.ts +252 -0
  106. package/src/schema.ts +297 -0
  107. package/src/spec.ts +325 -0
  108. package/src/statements.ts +148 -0
@@ -0,0 +1,532 @@
1
+ import type { SchemaSpec, ValueSpec, ValueTypeSpec } from "#spec.ts";
2
+ /**
3
+ * The complete typed surface of the bumbledb-node napi bridge. ALL FFI
4
+ * typing lives in this one file — no other module may know the `.node`
5
+ * artifact exists. The bridge is a dumb bridge (PRD-04): descriptor in as
6
+ * data, queries in as IR data, facts in/out as value rows, rejections out as
7
+ * structured violation sets; anything smart lives in the SDK or the engine.
8
+ *
9
+ * Marshaling law: fact rows cross as NATURAL JS values, schema-directed by
10
+ * the engine descriptor (`boolean ⇄ bool`, `bigint ⇄ u64/i64`,
11
+ * `string ⇄ str`, `Uint8Array ⇄ bytes<N>`, `{ start, end }` ⇄ interval);
12
+ * IR, spec, and query params cross as TAGGED plain objects mirroring the
13
+ * engine's own data enums 1:1. Every u64/i64 crosses as `bigint`, never
14
+ * `number`. Domain outcomes (schema errors, fingerprint mismatches,
15
+ * rejections, generation moves, IR errors) are DATA; marshaling/shape
16
+ * violations and use-after-close THROW.
17
+ */
18
+ /** The opaque database handle (owns the LMDB environment + exclusive lock). */
19
+ type DbHandle = {
20
+ readonly __brand: "bumbledb.db";
21
+ };
22
+ /** One live MVCC read snapshot. */
23
+ type SnapshotHandle = {
24
+ readonly __brand: "bumbledb.snapshot";
25
+ };
26
+ /**
27
+ * One exhumed store — the read-only, theory-less open (engine 70-api.md
28
+ * § exhume). No close function exists for this handle anywhere on the
29
+ * bridge (the zero-closables law): the engine side is dropped when the
30
+ * handle is garbage-collected — reclamation only, never correctness.
31
+ */
32
+ type ExhumeHandle = {
33
+ readonly __brand: "bumbledb.exhume";
34
+ };
35
+ /**
36
+ * One live write transaction — the submitted delta with the engine's
37
+ * final-state point-read view. Spent by `txCommit`/`txAbort`.
38
+ */
39
+ type TxHandle = {
40
+ readonly __brand: "bumbledb.tx";
41
+ };
42
+ /** One prepared query/program (plan pinned at prepare). */
43
+ type PreparedHandle = {
44
+ readonly __brand: "bumbledb.prepared";
45
+ };
46
+ /** A half-open interval `[start, end)` as it crosses the boundary. */
47
+ interface IntervalValue {
48
+ readonly start: bigint;
49
+ readonly end: bigint;
50
+ }
51
+ /**
52
+ * One fact-row cell as a natural JS value. The expected engine type comes
53
+ * from the schema descriptor (marshaling is schema-directed, never guessed):
54
+ * `boolean` for bool, `bigint` for u64/i64, `string` for str, `Uint8Array`
55
+ * for bytes<N> (width-checked), `{ start, end }` for intervals.
56
+ */
57
+ type FactValue = boolean | bigint | string | Uint8Array | IntervalValue;
58
+ /**
59
+ * One tagged engine value — the 1:1 mirror of `bumbledb::Value` for the
60
+ * positions no schema field directs (IR literals, query params). The spec's
61
+ * `ValueSpec` vocabulary plus the bind-time-only Allen mask.
62
+ */
63
+ type TaggedValue = ValueSpec | {
64
+ readonly kind: "allenMask";
65
+ readonly mask: number;
66
+ };
67
+ /**
68
+ * One positional execution argument: a tagged scalar, or a param SET
69
+ * (`Term.paramSet` positions) as `{ kind: "set", values }`.
70
+ */
71
+ type QueryParam = TaggedValue | {
72
+ readonly kind: "set";
73
+ readonly values: readonly TaggedValue[];
74
+ };
75
+ /**
76
+ * The IR mirror (`bumbledb::ir`, 1:1): relations, fields, predicates, and
77
+ * params by NUMERIC id — the SDK resolves names through the manifest and
78
+ * sends ids; the bridge never sees names in queries. A plain query is sent
79
+ * as its degenerate one-predicate program.
80
+ */
81
+ interface ProgramIr {
82
+ readonly predicates: readonly PredicateDefIr[];
83
+ readonly output: number;
84
+ }
85
+ /** One predicate: the head shape its rules align against, and the rules. */
86
+ interface PredicateDefIr {
87
+ readonly head: readonly HeadTermIr[];
88
+ readonly rules: readonly RuleIr[];
89
+ }
90
+ /** One head position: a plain variable slot or an aggregate-op kind. */
91
+ type HeadTermIr = {
92
+ readonly kind: "var";
93
+ } | {
94
+ readonly kind: "aggregate";
95
+ readonly op: HeadOpIr;
96
+ };
97
+ /** The var-free aggregate-op kind at a head position. */
98
+ type HeadOpIr = "sum" | "min" | "max" | "count" | "countDistinct" | "argMax" | "argMin" | "pack";
99
+ /** One rule: conjunctive body, anti-join atoms, condition trees. */
100
+ interface RuleIr {
101
+ readonly finds: readonly FindTermIr[];
102
+ readonly atoms: readonly AtomIr[];
103
+ readonly negated: readonly AtomIr[];
104
+ readonly conditions: readonly ConditionTreeIr[];
105
+ }
106
+ /** One find term (mirrors `ir::FindTerm`). */
107
+ type FindTermIr = {
108
+ readonly kind: "var";
109
+ readonly var: number;
110
+ } | {
111
+ readonly kind: "aggregate";
112
+ readonly op: AggOpIr;
113
+ readonly over?: number;
114
+ } | {
115
+ readonly kind: "measure";
116
+ readonly var: number;
117
+ } | {
118
+ readonly kind: "aggregateMeasure";
119
+ readonly op: AggOpIr;
120
+ readonly over: number;
121
+ };
122
+ /** One aggregate operator (mirrors `ir::AggOp`; Arg ops carry their key). */
123
+ type AggOpIr = {
124
+ readonly kind: "sum";
125
+ } | {
126
+ readonly kind: "min";
127
+ } | {
128
+ readonly kind: "max";
129
+ } | {
130
+ readonly kind: "count";
131
+ } | {
132
+ readonly kind: "countDistinct";
133
+ } | {
134
+ readonly kind: "argMax";
135
+ readonly key: number;
136
+ } | {
137
+ readonly kind: "argMin";
138
+ readonly key: number;
139
+ } | {
140
+ readonly kind: "pack";
141
+ };
142
+ /** Where an atom draws its facts: a stored relation or a program predicate. */
143
+ type AtomSourceIr = {
144
+ readonly kind: "edb";
145
+ readonly relation: number;
146
+ } | {
147
+ readonly kind: "idb";
148
+ readonly pred: number;
149
+ };
150
+ /**
151
+ * One atom: named-field bindings as `[fieldId, term]` pairs; absence of a
152
+ * field is the wildcard.
153
+ */
154
+ interface AtomIr {
155
+ readonly source: AtomSourceIr;
156
+ readonly bindings: ReadonlyArray<readonly [number, TermIr]>;
157
+ }
158
+ /** One term of an atom binding or comparison (mirrors `ir::Term`). */
159
+ type TermIr = {
160
+ readonly kind: "var";
161
+ readonly var: number;
162
+ } | {
163
+ readonly kind: "param";
164
+ readonly param: number;
165
+ } | {
166
+ readonly kind: "paramSet";
167
+ readonly param: number;
168
+ } | {
169
+ readonly kind: "literal";
170
+ readonly value: TaggedValue;
171
+ } | {
172
+ readonly kind: "measure";
173
+ readonly var: number;
174
+ };
175
+ /** The `Allen` comparison's mask position: a literal mask or a param. */
176
+ type MaskTermIr = {
177
+ readonly kind: "literal";
178
+ readonly mask: number;
179
+ } | {
180
+ readonly kind: "param";
181
+ readonly param: number;
182
+ };
183
+ /** One comparison operator (mirrors `ir::CmpOp`). */
184
+ type CmpOpIr = {
185
+ readonly kind: "eq";
186
+ } | {
187
+ readonly kind: "ne";
188
+ } | {
189
+ readonly kind: "lt";
190
+ } | {
191
+ readonly kind: "le";
192
+ } | {
193
+ readonly kind: "gt";
194
+ } | {
195
+ readonly kind: "ge";
196
+ } | {
197
+ readonly kind: "allen";
198
+ readonly mask: MaskTermIr;
199
+ } | {
200
+ readonly kind: "pointIn";
201
+ };
202
+ /** One comparison condition. */
203
+ interface ComparisonIr {
204
+ readonly op: CmpOpIr;
205
+ readonly lhs: TermIr;
206
+ readonly rhs: TermIr;
207
+ }
208
+ /**
209
+ * The input condition grammar: any boolean combination of comparisons
210
+ * (validation distributes to DNF engine-side).
211
+ */
212
+ type ConditionTreeIr = {
213
+ readonly kind: "leaf";
214
+ readonly cmp: ComparisonIr;
215
+ } | {
216
+ readonly kind: "and";
217
+ readonly children: readonly ConditionTreeIr[];
218
+ } | {
219
+ readonly kind: "or";
220
+ readonly children: readonly ConditionTreeIr[];
221
+ };
222
+ /** A statement's form tag. */
223
+ type StatementKindTag = "functionality" | "containment" | "cardinality";
224
+ /** One field's name, dense id, and structural type. */
225
+ interface ManifestField {
226
+ readonly name: string;
227
+ readonly id: number;
228
+ readonly valueType: ValueTypeSpec;
229
+ }
230
+ /**
231
+ * One closed-relation ground axiom as manifest data: handle →
232
+ * declaration-order id → (column, value) pairs.
233
+ */
234
+ interface ManifestRow {
235
+ readonly handle: string;
236
+ readonly id: bigint;
237
+ readonly values: ReadonlyArray<{
238
+ readonly name: string;
239
+ readonly value: FactValue;
240
+ }>;
241
+ }
242
+ /**
243
+ * One relation's names and ids; a closed relation's sealed field list opens
244
+ * with the synthetic (`id`, u64) handle field and carries its extension.
245
+ */
246
+ interface ManifestRelation {
247
+ readonly name: string;
248
+ readonly id: number;
249
+ readonly fields: readonly ManifestField[];
250
+ readonly extension?: readonly ManifestRow[];
251
+ }
252
+ /** One statement's identity, form tag, and canonical spelling. */
253
+ interface ManifestStatement {
254
+ readonly id: number;
255
+ readonly kind: StatementKindTag;
256
+ readonly spelling: string;
257
+ }
258
+ /**
259
+ * The theory's manifest: every name → id pairing as plain data (PRD-02's
260
+ * tables, one JS object) — called once per open by the SDK.
261
+ */
262
+ interface Manifest {
263
+ readonly relations: readonly ManifestRelation[];
264
+ readonly statements: readonly ManifestStatement[];
265
+ }
266
+ /** One offending fact of a violation, decoded to named natural values. */
267
+ interface ViolationFact {
268
+ readonly relation: string;
269
+ readonly fields: ReadonlyArray<{
270
+ readonly name: string;
271
+ readonly value: FactValue;
272
+ }>;
273
+ }
274
+ /**
275
+ * One violated statement of a rejected commit, rendered to plain data: the
276
+ * statement id (materialized order), form tag, CANONICAL spelling (the
277
+ * engine's one renderer — a bijection on legal statements, paste-back-able),
278
+ * the form's direction/count payloads, and the decoded offending facts.
279
+ */
280
+ interface Violation {
281
+ readonly statementId: number;
282
+ readonly kind: StatementKindTag;
283
+ readonly canonical: string;
284
+ readonly direction?: "sourceUnsatisfied" | "targetRequired";
285
+ readonly count?: bigint;
286
+ readonly facts: readonly ViolationFact[];
287
+ }
288
+ /**
289
+ * `dbCreate`/`dbOpen`'s domain outcome. `schemaError` covers both spec
290
+ * resolution (unresolvable names, banned spellings — every issue in one
291
+ * message) and schema validation at the declaration boundary;
292
+ * `fingerprintMismatch` is `dbOpen`'s stored-theory refusal.
293
+ */
294
+ type DbOpenResult = {
295
+ readonly ok: true;
296
+ readonly db: DbHandle;
297
+ } | {
298
+ readonly ok: false;
299
+ readonly kind: "schemaError" | "fingerprintMismatch";
300
+ readonly message: string;
301
+ };
302
+ /**
303
+ * `dbExhume`'s domain outcome: the live exhume handle, or one of the three
304
+ * adoption-era refusals as data — `descriptorMissing` (the store predates
305
+ * self-describing stores and has not been adopted; the remedy is one
306
+ * fingerprint-matching `dbOpen` under the creating schema),
307
+ * `formatMismatch`, and `corruption` (the persisted descriptor fails its
308
+ * integrity gates). Genuine failures — a missing path, a held exclusive
309
+ * lock — throw.
310
+ */
311
+ type ExhumeResult = {
312
+ readonly ok: true;
313
+ readonly exhume: ExhumeHandle;
314
+ } | {
315
+ readonly ok: false;
316
+ readonly kind: "descriptorMissing" | "formatMismatch" | "corruption";
317
+ readonly message: string;
318
+ };
319
+ /**
320
+ * `dbWriteFrom`'s domain outcome: the live witnessed transaction, or the
321
+ * typed stale-premise verdict (a state-changing commit landed after the
322
+ * witness snapshot; retry policy is host-side).
323
+ */
324
+ type WriteFromResult = {
325
+ readonly ok: true;
326
+ readonly tx: TxHandle;
327
+ } | {
328
+ readonly ok: false;
329
+ readonly kind: "generationMoved";
330
+ readonly witnessed: bigint;
331
+ readonly current: bigint;
332
+ };
333
+ /**
334
+ * `txCommit`'s domain outcome: the committed generation, or the COMPLETE
335
+ * violation set (every violated statement cited once, per direction for a
336
+ * containment, in materialized statement order).
337
+ */
338
+ type CommitResult = {
339
+ readonly ok: true;
340
+ readonly generation: bigint;
341
+ } | {
342
+ readonly ok: false;
343
+ readonly violations: readonly Violation[];
344
+ };
345
+ /** `dbPrepare`'s domain outcome (IR roster errors are data). */
346
+ type PrepareResult = {
347
+ readonly ok: true;
348
+ readonly prepared: PreparedHandle;
349
+ } | {
350
+ readonly ok: false;
351
+ readonly kind: "irError";
352
+ readonly message: string;
353
+ };
354
+ /** One occurrence's plan drift (pinned vs live row counts). */
355
+ interface OccurrenceDrift {
356
+ readonly relation: number;
357
+ readonly pinned: bigint;
358
+ readonly live: bigint;
359
+ readonly ratio: number;
360
+ }
361
+ /**
362
+ * The pull-based plan-drift report: engine-policy-free — no threshold
363
+ * exists engine-side; the host owns reprepare policy.
364
+ */
365
+ interface Staleness {
366
+ readonly perOccurrence: readonly OccurrenceDrift[];
367
+ readonly maxRatio: number;
368
+ }
369
+ interface Native {
370
+ /**
371
+ * Proof-of-life export (PRD-03): a non-empty string naming the bridge
372
+ * crate version and the engine's storage format version — evidence the
373
+ * cargo path dependency compiled, linked, and loaded through Node-API.
374
+ */
375
+ engineVersion(): string;
376
+ /**
377
+ * Creates a fresh DURABLE store at `path` (frozen ruling 3: no ephemeral
378
+ * kind crosses this bridge). Refuses an already-initialized directory
379
+ * (throws); schema failures return as data.
380
+ */
381
+ dbCreate(path: string, spec: SchemaSpec): DbOpenResult;
382
+ /**
383
+ * Opens an existing durable store, verifying format version, store
384
+ * kind, and schema fingerprint (`fingerprintMismatch` as data).
385
+ */
386
+ dbOpen(path: string, spec: SchemaSpec): DbOpenResult;
387
+ /**
388
+ * Closes the handle. Dependent handles each hold the engine alive; the
389
+ * environment (and its exclusive lock) releases when the last closes.
390
+ */
391
+ dbClose(db: DbHandle): void;
392
+ /** The PRD-02 manifest — every name → id table, one plain object. */
393
+ dbManifest(db: DbHandle): Manifest;
394
+ /**
395
+ * The open store's schema fingerprint, 64 lowercase hex chars — the
396
+ * cross-host identity readback (`dbCreate` stored this exact value,
397
+ * `dbOpen` verified it). The engine computes; the bridge hex-encodes.
398
+ * Test-facing (the cross-host fingerprint lock); the SDK surface stays
399
+ * bijective with the Rust surface, which exposes no fingerprint
400
+ * accessor on `Db` — so no `Db` method wraps this.
401
+ */
402
+ dbFingerprint(db: DbHandle): string;
403
+ /**
404
+ * The current committed generation — diagnostics only. The write-side
405
+ * witness is always the SNAPSHOT handle (`dbWriteFrom`), never this
406
+ * integer: an integer witness would be a claim a caller could fabricate
407
+ * or stale-cache (the engine's recorded refusal).
408
+ */
409
+ dbGeneration(db: DbHandle): bigint;
410
+ /**
411
+ * Opens a store FROM ITS OWN PERSISTED DESCRIPTOR (the read-only,
412
+ * theory-less open; engine 70-api.md § exhume) — no schema crosses in.
413
+ * The three adoption-era refusals return as data ({@link ExhumeResult});
414
+ * genuine failures throw. The handle has no close anywhere on this
415
+ * bridge (zero closables): GC reclaims the engine side and releases the
416
+ * store's exclusive lock — reclamation only, never correctness.
417
+ */
418
+ dbExhume(path: string): ExhumeResult;
419
+ /**
420
+ * The exhumed store's persisted schema as manifest-shaped data — the
421
+ * engine's own manifest rendering of the STORED descriptor: relations
422
+ * in engine-id order, sealed field lists (a closed relation opens with
423
+ * the synthetic (`id`, u64) handle field) with structural value types,
424
+ * and closed-relation rosters.
425
+ */
426
+ exhumeDescriptor(exhume: ExhumeHandle): Manifest;
427
+ /**
428
+ * Full-relation export by NAME in row-id order, values marshaled per
429
+ * the STORED descriptor (str already resolved through `_dict` inside
430
+ * the engine; a closed relation scans its sealed roster). Each call is
431
+ * one self-contained snapshot read; an unknown relation name throws.
432
+ */
433
+ exhumeScan(exhume: ExhumeHandle, relationName: string): FactValue[][];
434
+ /** Opens one MVCC read snapshot as a live handle. */
435
+ dbSnapshot(db: DbHandle): SnapshotHandle;
436
+ /** Closes the snapshot, releasing its LMDB reader slot. */
437
+ snapshotClose(snap: SnapshotHandle): void;
438
+ /** Full-relation export in row-id order (one row per fact). */
439
+ snapshotScan(snap: SnapshotHandle, relationId: number): FactValue[][];
440
+ /** Committed-state membership of one fact (sealed field order). */
441
+ snapshotContains(snap: SnapshotHandle, relationId: number, values: readonly FactValue[]): boolean;
442
+ /**
443
+ * Committed-state point lookup through a key statement (`keyValues` in
444
+ * the statement's projection order); `null` on a miss.
445
+ */
446
+ snapshotGet(snap: SnapshotHandle, relationId: number, keyStatementId: number, keyValues: readonly FactValue[]): FactValue[] | null;
447
+ /**
448
+ * Begins a write transaction: the submitted delta. One write
449
+ * transaction may be open per db handle at a time (single-writer
450
+ * engine; a second begin throws rather than deadlocking the process).
451
+ */
452
+ dbWriteBegin(db: DbHandle): TxHandle;
453
+ /**
454
+ * Begins a WITNESSED write transaction: commits only if no
455
+ * state-changing commit landed since `snap` was taken —
456
+ * `generationMoved` as data otherwise (the optimistic
457
+ * read-compute-write loop's entry; retry policy stays host-side).
458
+ */
459
+ dbWriteFrom(db: DbHandle, snap: SnapshotHandle): WriteFromResult;
460
+ /**
461
+ * Records an insert into the delta; `true` iff the final state changed.
462
+ * Nothing is judged until commit; shape violations throw typed.
463
+ */
464
+ txInsert(tx: TxHandle, relationId: number, values: readonly FactValue[]): boolean;
465
+ /** Records a delete into the delta; `true` iff the final state changed. */
466
+ txDelete(tx: TxHandle, relationId: number, values: readonly FactValue[]): boolean;
467
+ /**
468
+ * Final-state membership (base + pending delta — the exact view the
469
+ * commit judgment judges; check-then-act is race-free by construction).
470
+ */
471
+ txContains(tx: TxHandle, relationId: number, values: readonly FactValue[]): boolean;
472
+ /** Final-state point lookup through a key statement; `null` on a miss. */
473
+ txGet(tx: TxHandle, relationId: number, keyStatementId: number, keyValues: readonly FactValue[]): FactValue[] | null;
474
+ /**
475
+ * Mints the next fresh value for `(relationId, fieldId)` and returns it
476
+ * — the engine's alloc-then-insert dyn-lane mint (there is no
477
+ * insert-with-omitted-fields spelling; include the minted id in the
478
+ * full row).
479
+ */
480
+ txAlloc(tx: TxHandle, relationId: number, fieldId: number): bigint;
481
+ /**
482
+ * Commits the delta: every dependency statement judged against the
483
+ * final state; a rejection carries the complete violation rendering.
484
+ * The handle is spent either way.
485
+ */
486
+ txCommit(tx: TxHandle): CommitResult;
487
+ /** Aborts the delta (LMDB was never touched). The handle is spent. */
488
+ txAbort(tx: TxHandle): void;
489
+ /**
490
+ * Prepares a program (IR as data, ids only; plan pinned at prepare).
491
+ * Roster errors return as data.
492
+ */
493
+ dbPrepare(db: DbHandle, program: ProgramIr): PrepareResult;
494
+ /**
495
+ * Executes against a snapshot with positional params. One-copy owned
496
+ * rows out, column order = the program's head order; answers are a set
497
+ * — the host sorts.
498
+ */
499
+ preparedExecute(prepared: PreparedHandle, snap: SnapshotHandle, params: readonly QueryParam[]): FactValue[][];
500
+ /** The pull-based plan-drift signal against a snapshot. */
501
+ preparedStaleness(prepared: PreparedHandle, snap: SnapshotHandle): Staleness;
502
+ /** Releases the prepared query. */
503
+ preparedClose(prepared: PreparedHandle): void;
504
+ }
505
+ /**
506
+ * Resolves and loads the native bridge from its per-platform binary package
507
+ * (`@bjornpagen/bumbledb-<platform>-<arch>`) — the Biome/esbuild/napi-rs
508
+ * pattern. npm/pnpm install ONLY the `optionalDependency` whose `os`/`cpu`
509
+ * match the host, so a matching host resolves the addon and every other host
510
+ * resolves nothing. The two failure modes are distinct and both typed:
511
+ *
512
+ * - the platform package is ABSENT (the expected state on any
513
+ * non-darwin-arm64 host, and on a foreign `platform`/`arch` passed under
514
+ * test) — an actionable unsupported-platform error naming the running
515
+ * `platform-arch` and the shipped set;
516
+ * - the platform package is PRESENT but its `bumbledb.node` will not load
517
+ * (a genuine ABI/corruption fault) — the wrapped loader error.
518
+ *
519
+ * Parameterized on `platform`/`arch` so the resolution law is exercised for
520
+ * foreign hosts as a unit, without spawning a foreign process.
521
+ */
522
+ declare function loadNativeBinding(platform: string, arch: string): Native;
523
+ /**
524
+ * The loaded bumbledb-node bridge for the running host. Import this object
525
+ * for every native call; the resolve-and-load happens once at module
526
+ * initialization and an absent or unloadable artifact fails fast here rather
527
+ * than at first use.
528
+ */
529
+ declare const native: Native;
530
+ export type { AggOpIr, AtomIr, AtomSourceIr, CmpOpIr, CommitResult, ComparisonIr, ConditionTreeIr, DbHandle, DbOpenResult, ExhumeHandle, ExhumeResult, FactValue, FindTermIr, HeadOpIr, HeadTermIr, IntervalValue, Manifest, ManifestField, ManifestRelation, ManifestRow, ManifestStatement, MaskTermIr, Native, OccurrenceDrift, PredicateDefIr, PreparedHandle, PrepareResult, ProgramIr, QueryParam, RuleIr, SnapshotHandle, Staleness, StatementKindTag, TaggedValue, TermIr, TxHandle, Violation, ViolationFact, WriteFromResult };
531
+ export { loadNativeBinding, native };
532
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAEpE;;;;;;;;;;;;;;;GAeG;AAEH,+EAA+E;AAC/E,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;CAAE,CAAA;AAEnD,mCAAmC;AACnC,KAAK,cAAc,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAA;CAAE,CAAA;AAE/D;;;;;GAKG;AACH,KAAK,YAAY,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;CAAE,CAAA;AAE3D;;;GAGG;AACH,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;CAAE,CAAA;AAEnD,2DAA2D;AAC3D,KAAK,cAAc,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAA;CAAE,CAAA;AAE/D,sEAAsE;AACtE,UAAU,aAAa;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACpB;AAED;;;;;GAKG;AACH,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,aAAa,CAAA;AAEvE;;;;GAIG;AACH,KAAK,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ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EACV,MAAM,EACN,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,SAAS,EACT,UAAU,EACV,MAAM,EACN,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,EACT,aAAa,EACb,eAAe,EACf,CAAA;AACD,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAA"}
package/dist/native.js ADDED
@@ -0,0 +1,64 @@
1
+ import { createRequire } from "node:module";
2
+ import * as errors from "@superbuilders/errors";
3
+ /**
4
+ * The sole platform this release ships (PRD-03 ruling 1: prebuilt-only,
5
+ * darwin-arm64). The per-platform-package structure below makes adding
6
+ * `darwin-x64`/`linux-*`/`win32-*` pure addition — one more `os`/`cpu`-gated
7
+ * package plus a CI matrix — never a redesign, so this string is the only
8
+ * place the shipped set is named for the unsupported-platform message.
9
+ */
10
+ const SHIPPED_PLATFORMS = "darwin-arm64";
11
+ /**
12
+ * CommonJS require anchored to this module, the only mechanism ESM has for
13
+ * loading a Node-API addon without an experimental flag (static `import` of
14
+ * `.node` files still sits behind `--experimental-addon-modules` on Node 24).
15
+ * It resolves the per-platform binary package by name (see
16
+ * {@link loadNativeBinding}); the addon never crosses as a relative path.
17
+ * createRequire is the only unflagged Node-API addon loader in ESM, and this
18
+ * file is the package's single sanctioned FFI boundary
19
+ * (docs/road-to-1.0.0/prd-03-arch-split-packaging.md).
20
+ */
21
+ const requireNative = createRequire(import.meta.url);
22
+ /**
23
+ * Resolves and loads the native bridge from its per-platform binary package
24
+ * (`@bjornpagen/bumbledb-<platform>-<arch>`) — the Biome/esbuild/napi-rs
25
+ * pattern. npm/pnpm install ONLY the `optionalDependency` whose `os`/`cpu`
26
+ * match the host, so a matching host resolves the addon and every other host
27
+ * resolves nothing. The two failure modes are distinct and both typed:
28
+ *
29
+ * - the platform package is ABSENT (the expected state on any
30
+ * non-darwin-arm64 host, and on a foreign `platform`/`arch` passed under
31
+ * test) — an actionable unsupported-platform error naming the running
32
+ * `platform-arch` and the shipped set;
33
+ * - the platform package is PRESENT but its `bumbledb.node` will not load
34
+ * (a genuine ABI/corruption fault) — the wrapped loader error.
35
+ *
36
+ * Parameterized on `platform`/`arch` so the resolution law is exercised for
37
+ * foreign hosts as a unit, without spawning a foreign process.
38
+ */
39
+ function loadNativeBinding(platform, arch) {
40
+ const platformPackage = `@bjornpagen/bumbledb-${platform}-${arch}`;
41
+ // Presence probe: the platform package's OWN manifest resolves iff the
42
+ // matching optional dependency was installed. Its absence is the
43
+ // expected, benign "unsupported platform" — never a corruption signal.
44
+ const present = errors.trySync(() => requireNative.resolve(`${platformPackage}/package.json`));
45
+ if (present.error) {
46
+ throw errors.wrap(present.error, `no native binary for ${platform}-${arch}: @bjornpagen/bumbledb ships ${SHIPPED_PLATFORMS} only`);
47
+ }
48
+ // The package is present; load its addon (its `main` is `bumbledb.node`).
49
+ // A failure HERE is corruption or an ABI mismatch, not an absent platform.
50
+ const loaded = errors.trySync(() => requireNative(platformPackage));
51
+ if (loaded.error) {
52
+ throw errors.wrap(loaded.error, `load the ${platformPackage} native binary (package present but unloadable)`);
53
+ }
54
+ return loaded.data;
55
+ }
56
+ /**
57
+ * The loaded bumbledb-node bridge for the running host. Import this object
58
+ * for every native call; the resolve-and-load happens once at module
59
+ * initialization and an absent or unloadable artifact fails fast here rather
60
+ * than at first use.
61
+ */
62
+ const native = loadNativeBinding(process.platform, process.arch);
63
+ export { loadNativeBinding, native };
64
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAgd/C;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,cAAc,CAAA;AAExC;;;;;;;;;GASG;AACH,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,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