@bjornpagen/bumbledb 0.12.2 → 0.15.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 (46) hide show
  1. package/COOKBOOK.md +35 -21
  2. package/README.md +82 -55
  3. package/dist/db.d.ts +173 -130
  4. package/dist/db.d.ts.map +1 -1
  5. package/dist/db.js +782 -371
  6. package/dist/db.js.map +1 -1
  7. package/dist/index.d.ts +7 -13
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +4 -9
  10. package/dist/index.js.map +1 -1
  11. package/dist/marshal.d.ts +5 -27
  12. package/dist/marshal.d.ts.map +1 -1
  13. package/dist/marshal.js +4 -21
  14. package/dist/marshal.js.map +1 -1
  15. package/dist/native.d.ts +157 -168
  16. package/dist/native.d.ts.map +1 -1
  17. package/dist/native.js +46 -8
  18. package/dist/native.js.map +1 -1
  19. package/dist/query/find.d.ts +14 -9
  20. package/dist/query/find.d.ts.map +1 -1
  21. package/dist/query/find.js +2 -2
  22. package/dist/query/find.js.map +1 -1
  23. package/dist/query/lower.d.ts.map +1 -1
  24. package/dist/query/lower.js +5 -4
  25. package/dist/query/lower.js.map +1 -1
  26. package/dist/query/parse-ir.d.ts.map +1 -1
  27. package/dist/query/parse-ir.js +11 -9
  28. package/dist/query/parse-ir.js.map +1 -1
  29. package/dist/relation.d.ts +4 -25
  30. package/dist/relation.d.ts.map +1 -1
  31. package/dist/relation.js +3 -4
  32. package/dist/relation.js.map +1 -1
  33. package/package.json +3 -3
  34. package/src/db.ts +1151 -500
  35. package/src/index.ts +28 -24
  36. package/src/marshal.ts +5 -35
  37. package/src/native.ts +248 -175
  38. package/src/query/find.ts +19 -14
  39. package/src/query/lower.ts +7 -6
  40. package/src/query/parse-ir.ts +11 -9
  41. package/src/relation.ts +3 -28
  42. package/dist/exhume.d.ts +0 -143
  43. package/dist/exhume.d.ts.map +0 -1
  44. package/dist/exhume.js +0 -166
  45. package/dist/exhume.js.map +0 -1
  46. package/src/exhume.ts +0 -267
package/src/index.ts CHANGED
@@ -5,9 +5,8 @@
5
5
  * never declared: THE LAWS TYPE THE COLUMNS, `schema()` computing every
6
6
  * field's equivalence class FROM the statement list at both tiers), the
7
7
  * statement algebra with `schema()` and `SchemaSpec` lowering (PRD-06), the `Db`
8
- * runtime (exclusive-lock stores, transactions, typed violations, scoped
9
- * snapshot reads, one-shot `write`/`writeFrom` with `abandon` — PRD-07, zero
10
- * closables), the query surface (kysely-shaped:
8
+ * runtime (exclusive-lock stores, transactions, typed violations, callback
9
+ * instance reads, one-shot `write`/`writeFrom` with `abandon` — PRD-07), the query surface (kysely-shaped:
11
10
  * `query(S).rule(r => { const { id, name } = v(Holder); return r.match(Holder, { id, name }).find({ name }) })` —
12
11
  * variables minted by `v()` and joined by OBJECT REFERENCE (reuse is the
13
12
  * join), the head a `find` RECORD whose keys name the answer columns
@@ -17,10 +16,7 @@
17
16
  * `db.prepare` as a plain value; the comparison/connective builders are
18
17
  * also free exports, and the free names `eq`/`not`/`and`/`or` collide with
19
18
  * common host identifiers — import aliasing is the answer; the SDK does
20
- * not rename for collision-avoidance), the exhume surface
21
- * (`Db.exhume` — the one schema-independent read path: the store's
22
- * self-described shapes and raw facts by name, typed at bare structural
23
- * values, deliberately schema-free). The raw native bridge is not exported.
19
+ * not rename for collision-avoidance). The raw native bridge is not exported.
24
20
  */
25
21
 
26
22
  export type {
@@ -51,35 +47,44 @@ export { closed } from "#closed.ts"
51
47
  export type {
52
48
  Abandon,
53
49
  AbandonedArm,
50
+ Admission,
54
51
  CapacityViolation,
52
+ Committed,
55
53
  ContainmentViolation,
56
54
  DeclaredKeyFact,
57
55
  DeclaredKeyViolation,
58
56
  DeltaBuild,
57
+ FreshRange,
59
58
  ImpliedKeyViolation,
60
59
  MemberRelation,
61
60
  MirrorViolation,
61
+ MutationReport,
62
62
  OffendingFact,
63
+ OwnedInstance,
63
64
  Prepared,
64
- ReadScope,
65
+ ReadInstance,
66
+ SyncResult,
65
67
  Tx,
66
68
  Violation,
67
- WriteResult
69
+ Witness,
70
+ WriteFromOutcome,
71
+ WriteOutcome,
72
+ WriteTx
68
73
  } from "#db.ts"
69
- export { abandon, Db, ErrGenerationMoved, ErrNewtypeMismatch } from "#db.ts"
70
- export type {
71
- Exhumed,
72
- ExhumedAxiom,
73
- ExhumedDescriptor,
74
- ExhumedFact,
75
- ExhumedField,
76
- ExhumedRelation
77
- } from "#exhume.ts"
78
74
  export {
79
- ErrExhumeCorruption,
80
- ErrExhumeFormatMismatch,
81
- ErrExhumeNoDescriptor
82
- } from "#exhume.ts"
75
+ abandon,
76
+ Db,
77
+ ErrAsyncCallback,
78
+ ErrForeignPrepared,
79
+ ErrForeignWitness,
80
+ ErrFingerprintMismatch,
81
+ ErrIrError,
82
+ ErrNewtypeMismatch,
83
+ ErrSchemaError,
84
+ ErrSpentHandle,
85
+ ErrUseAfterScope,
86
+ InstanceBuilder
87
+ } from "#db.ts"
83
88
  export type {
84
89
  AnyFace,
85
90
  Arity,
@@ -114,7 +119,7 @@ export type {
114
119
  export { bool, bytes, i64, interval, span, str, u64 } from "#fields.ts"
115
120
  export type { ClassesOf, ClassWall, LawfulStatements, RelationClasses, SchemaClasses } from "#law.ts"
116
121
  export { lower, lowerClosed, lowerRelation } from "#lower.ts"
117
- export type { KeyFact, Minted } from "#marshal.ts"
122
+ export type { KeyFact } from "#marshal.ts"
118
123
  export type { FactValue, ParsedQuery, QueryIr, StatementKindTag } from "#native.ts"
119
124
 
120
125
  export type {
@@ -169,7 +174,6 @@ export type {
169
174
  Fact,
170
175
  FieldsShape,
171
176
  FreshKeys,
172
- InsertFact,
173
177
  Relation,
174
178
  RelationData,
175
179
  RelationField,
package/src/marshal.ts CHANGED
@@ -43,13 +43,6 @@ function isFreshField(field: AnyField): boolean {
43
43
  return "fresh" in field && field.fresh === true
44
44
  }
45
45
 
46
- /**
47
- * The inferred object type `tx.insert` returns: one property per
48
- * fresh-marked field of `R`, carrying the minted (or resupplied) id as a
49
- * bare `bigint`. A relation with no fresh field returns the empty object.
50
- */
51
- type Minted<R extends AnyRelation> = { [K in FreshKeys<R>]: Fact<R>[K] }
52
-
53
46
  /**
54
47
  * The key object `get` reads through. THE PRIMARY-KEY RULE: `get` always
55
48
  * reads through the PRIMARY candidate key — the first-declared one in the
@@ -74,10 +67,7 @@ type KeyFact<R extends AnyRelation> = [FreshKeys<R>] extends [never]
74
67
  * ALLOCATION-FREE IDENTITY (the admission predicate is the type
75
68
  * reprojection; the value passes through untouched): every consumer
76
69
  * downstream — `rowOf`, `keyRowOf`, the query param marshal — only READS
77
- * properties, so no copy is warranted. The one mutating consumer
78
- * (`mintFreshCells` on the insert path) takes its own spread copy at the
79
- * call site, so the caller's fact object is never written through this
80
- * seam.
70
+ * properties, so no copy is warranted.
81
71
  */
82
72
  function recordOf(fact: object): Readonly<Record<string, unknown>> {
83
73
  if (!isStringIndexed(fact)) {
@@ -203,9 +193,8 @@ function cellOf(context: string, field: AnyField, value: unknown): FactValue {
203
193
 
204
194
  /**
205
195
  * Marshals one complete fact object to its positional row, in field
206
- * declaration order (= ordinal ids). Every declared field must be present;
207
- * fresh minting happens BEFORE this point (the transaction fills omitted
208
- * fresh cells via the engine's alloc lane).
196
+ * declaration order (= ordinal ids). Every declared field must be present.
197
+ * Mint with `tx.reserve` first; insert takes complete facts.
209
198
  */
210
199
  function rowOf(relation: RelationData, fact: Readonly<Record<string, unknown>>): FactValue[] {
211
200
  return relation.fields.map(function marshalCell(declared) {
@@ -260,25 +249,6 @@ function isCompleteFact<R extends AnyRelation>(
260
249
  })
261
250
  }
262
251
 
263
- /**
264
- * The insert-return trusted seam (R11): one insert's return carries the
265
- * engine's changed-state report beside the collected fresh cells (minted by
266
- * the engine or resupplied by the caller) — the bit is verified boolean and
267
- * the fresh ids present, same presence-only direction as
268
- * {@link isCompleteFact}.
269
- */
270
- function isInserted<R extends AnyRelation>(
271
- relation: R,
272
- value: Readonly<Record<string, FactValue | boolean>>
273
- ): value is Readonly<Record<string, FactValue | boolean>> & { readonly changed: boolean } & Minted<R> {
274
- return (
275
- typeof value.changed === "boolean" &&
276
- relation.data.fields.every(function presentWhenFresh(declared) {
277
- return !isFreshField(declared.field) || value[declared.name] !== undefined
278
- })
279
- )
280
- }
281
-
282
252
  /**
283
253
  * Unmarshals one positional row to the relation's named, frozen fact object
284
254
  * of bare structural values — the inverse of {@link rowOf},
@@ -310,5 +280,5 @@ function factOf<R extends AnyRelation>(relation: R, row: readonly FactValue[]):
310
280
  return decoded
311
281
  }
312
282
 
313
- export type { KeyFact, Minted }
314
- export { cellOf, factOf, handleOf, isFreshField, isInserted, keyRowOf, recordOf, rowOf }
283
+ export type { KeyFact }
284
+ export { cellOf, factOf, handleOf, isFreshField, keyRowOf, recordOf, rowOf }