@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/README.md CHANGED
@@ -3,125 +3,143 @@
3
3
  This package is the TypeScript interface to the
4
4
  [Bumbledb](https://github.com/bjornpagen/bumbledb) embedded relational
5
5
  database. Schemas and queries are typed TypeScript values rather than SQL
6
- strings, while storage, admitted instances, transactions, and query execution run in
6
+ strings, while storage, admission, transactions, and query execution run in
7
7
  the native engine.
8
8
 
9
+ The API is **Effect-native**: every database operation constructs a lazy
10
+ [`Effect`](https://effect.website) and every native resource is scoped.
11
+ There is no Promise, synchronous, or disposal twin. Pure schema/query/scalar
12
+ construction and reads of already-owned metadata stay ordinary synchronous
13
+ expressions with no hidden native work. The package requires Effect
14
+ `4.0.0-rc.112` exactly, as a peer dependency.
15
+
9
16
  Relation declarations describe their fields, and the statements passed to
10
17
  `schema()` connect those fields into typed keys and references. Values remain
11
- ordinary `bigint`, `string`, boolean, byte, and interval values; queries infer
12
- their parameter and result types from how those values are used.
18
+ ordinary `bigint`, `number` (for `f64`), `string`, boolean, byte, `Uuid`,
19
+ and interval values; queries infer their parameter and result types from how
20
+ those values are used.
13
21
 
14
22
  ## Platform support
15
23
 
16
- The TypeScript package currently ships native binaries for **darwin-arm64**
17
- (macOS on Apple Silicon) and **linux-arm64** (Amazon Linux 2023, glibc 2.34).
18
- The matching optional `@bjornpagen/bumbledb-<platform>` package is selected
19
- automatically during installation. On another platform, importing the
20
- package returns an error that identifies the running platform and the
21
- available binaries.
24
+ The TypeScript package ships native binaries for **darwin-arm64**
25
+ (macOS on Apple Silicon), **linux-arm64**, and **linux-x64**.
26
+ The matching `@bjornpagen/bumbledb-<platform>` package is selected
27
+ automatically during installation. Schema and query authoring do not load
28
+ the addon. Attempting native database work on an unsupported platform fails
29
+ with a diagnostic identifying the running platform and available binaries.
30
+ Node 24 or newer is required; Edge and browser runtimes are unsupported.
31
+ Linux artifacts target Amazon Linux 2023 / glibc 2.34 or newer. Their
32
+ correctness CI is distinct from the Apple Silicon performance measurements.
22
33
 
23
34
  ## Install
24
35
 
25
36
  ```sh
26
- pnpm add @bjornpagen/bumbledb
37
+ pnpm add @bjornpagen/bumbledb@1.0.0 effect@4.0.0-rc.112
27
38
  ```
28
39
 
29
40
  ## Quick start
30
41
 
31
- Declare relations, connect their fields with keys and references, write
32
- records in a transaction, and query them with the typed builder. Parameters
33
- and result rows are inferred, and a failed constraint check is returned as
34
- structured data rather than thrown as an exception.
42
+ Declare relations, connect their fields with keys and references, build a
43
+ change set, apply it, and query the admitted state. Parameters and result
44
+ rows are inferred; a failed constraint check is a typed apply outcome, never
45
+ a thrown exception.
35
46
 
36
47
  ```ts
37
- import { bool, closed, contained, Db, type Infer, key, on, query, relation, schema, u64, v } from "@bjornpagen/bumbledb"
38
-
39
- // A fixed set can carry typed columns as well as names.
40
- // Its ID type is the union "DirectPass" | "JudgedPass" | "Failed".
41
- const Kind = closed(
42
- "Kind",
43
- ["DirectPass", "JudgedPass", "Failed"],
44
- { mastered: bool, rank: u64 },
45
- {
46
- DirectPass: { mastered: true, rank: 30n },
47
- JudgedPass: { mastered: true, rank: 20n },
48
- Failed: { mastered: false, rank: 10n }
49
- }
50
- )
48
+ import { Effect, Option } from "effect"
49
+ import {
50
+ capacity,
51
+ ChangeSet,
52
+ contained,
53
+ Db,
54
+ f64,
55
+ i64,
56
+ uuid,
57
+ interval,
58
+ key,
59
+ NativeRuntime,
60
+ on,
61
+ query,
62
+ ref,
63
+ relation,
64
+ schema,
65
+ str,
66
+ u64,
67
+ v,
68
+ weigh,
69
+ within
70
+ } from "@bjornpagen/bumbledb"
71
+ import type { ExecutionPolicy, NativeRuntimeOptions } from "@bjornpagen/bumbledb"
72
+
73
+ // Relations describe stored records. Identity fields are ordinary
74
+ // application-owned Uuid values — the database issues no identity.
75
+ const Student = relation("Student", { id: uuid, name: str, budget: u64 })
76
+ const Attempt = relation("Attempt", {
77
+ id: uuid,
78
+ student: uuid,
79
+ score: f64,
80
+ units: u64,
81
+ active: interval(i64)
82
+ })
51
83
 
52
- // Relations describe stored records.
53
- // `u64.fresh` marks an engine-minted primary key.
54
- const Attempt = relation("Attempt", { id: u64.fresh, kind: Kind.id })
55
- const Certificate = relation("Certificate", { attempt: u64, kind: Kind.id })
56
-
57
- // These statements declare the key and references. The final reference is
58
- // conditional: a certificate may cite only a mastered kind.
59
- const Review = schema("Review", { Kind, Attempt, Certificate }, [
60
- contained(on(Attempt, "kind"), on(Kind, "id")),
61
- key(Certificate, ["attempt"]),
62
- contained(on(Certificate, "attempt"), on(Attempt, "id")),
63
- contained(on(Certificate, "kind"), on(Kind.where({ mastered: true }), "id"))
84
+ // Keys are declared statements; references and capacity are laws.
85
+ const Learning = schema("Learning", { Student, Attempt }, [
86
+ key(Student, ["id"]),
87
+ key(Attempt, ["id"]),
88
+ contained(on(Attempt, "student"), on(Student, "id")),
89
+ capacity(on(Student, "id"), {
90
+ from: on(Attempt, "student"),
91
+ weight: weigh("units"),
92
+ within: within(0n, ref("budget"))
93
+ })
64
94
  ])
65
95
 
66
- const created = await Db.create("./review.db", Review)
67
- if (created.tag !== "accepted") {
68
- throw new Error("create rejected")
69
- }
70
- const db = created.value
71
-
72
- // All writes are checked together before the transaction commits. A fixed-set
73
- // column takes its name, and a wrong string is rejected by TypeScript and
74
- // again if an untyped value reaches the native boundary.
75
- const result = db.write((tx) => {
76
- const id = tx.reserve(Attempt, "id", 1n).at(0n)!
77
- tx.insert(Attempt, [{ id, kind: "DirectPass" }])
78
- tx.insert(Certificate, [{ attempt: id, kind: "DirectPass" }])
79
- })
96
+ // Measured policies are inputs — the library invents no limits.
97
+ declare const runtimePolicy: NativeRuntimeOptions
98
+ declare const work: ExecutionPolicy
99
+ declare const localPath: string
80
100
 
81
- // A failed constraint check is returned as typed data rather than thrown.
82
- if (result.tag === "rejected") {
83
- for (const v of result.violations) {
84
- console.error(v.kind, v.canonical, v.facts)
85
- }
86
- }
87
-
88
- // v(R) creates a typed variable for each column. Reusing one across records
89
- // creates the join, result rows follow the find keys, and parameters are typed
90
- // from where they are used.
91
- const certifiedAbove = query(Review).rule((r) => {
92
- const { attempt: a, kind: k } = v(Certificate)
93
- const { rank } = v(Kind)
101
+ // Queries are reusable typed values: reusing a v(R) variable is the join,
102
+ // the find record names the answer columns, and params are typed by use.
103
+ const attemptsFor = query(Learning).rule((r) => {
104
+ const { id, student, score, units, active } = v(Attempt)
94
105
  return r
95
- .match(Certificate, { attempt: a, kind: k })
96
- .match(Kind, { id: k, mastered: true, rank }) // reusing k at Kind.id creates the join
97
- .where(r.gt(rank, r.param("floor")))
98
- .find({ a, rank })
106
+ .match(Attempt, { id, student, score, units, active })
107
+ .where(r.eq(student, r.param("student")))
108
+ .find({ id, score })
99
109
  })
100
110
 
101
- const prepared = db.prepare(certifiedAbove)
102
- const rows = db.read((i) => i.execute(prepared, { floor: 15n })) // rows: { a: bigint; rank: bigint }[]
103
- console.log(rows)
104
-
105
- // A store read is one callback. The instance is invalid when the callback
106
- // returns; the witness is a clone and may escape.
107
- db.read((instance) => {
108
- console.log(instance.generation, instance.execute(prepared, { floor: 15n }))
109
- })
111
+ const program = Effect.scoped(
112
+ Effect.gen(function* () {
113
+ // First use: create explicitly. Use Db.open for an existing store.
114
+ const db = yield* Db.create(localPath, Learning, work)
115
+ const studentId = yield* Effect.sync(() => crypto.randomUUID())
116
+ const attemptId = yield* Effect.sync(() => crypto.randomUUID())
117
+
118
+ const draft = yield* ChangeSet.builder(Learning, work)
119
+ yield* draft.insert(Student, [{ id: studentId, name: "Ada", budget: 10n }])
120
+ yield* draft.insert(Attempt, [
121
+ { id: attemptId, student: studentId, score: 0.9, units: 1n, active: { start: 0n, end: 60n } }
122
+ ])
123
+ const changes = yield* draft.finish()
124
+
125
+ const outcome = yield* db.apply(changes, { ...work, expected: { kind: "any" } })
126
+ if (outcome.kind !== "accepted" && outcome.kind !== "no-change") {
127
+ return outcome
128
+ }
129
+ const snapshot = yield* db.snapshot(work)
130
+ const found = yield* snapshot.get(Student, { id: studentId }, work)
131
+ if (Option.isNone(found)) {
132
+ return outcome
133
+ }
134
+ const result = yield* snapshot.execute(attemptsFor, { student: studentId }, work)
135
+ const rows = yield* result.collect({ maxBytes: work.resultBytes }, work)
136
+ return { outcome, rows }
137
+ })
138
+ )
110
139
 
111
- // Dispatch over the fixed set uses native `switch` narrowing.
112
- // `satisfies never` checks that every possible name is handled.
113
- function describe(kind: Infer<typeof Kind.id>): string {
114
- switch (kind) {
115
- case "DirectPass":
116
- case "JudgedPass":
117
- return `mastered, rank ${Kind.axioms[kind].rank}`
118
- case "Failed":
119
- return "not mastered"
120
- default:
121
- return kind satisfies never
122
- }
123
- }
124
- console.log(describe("JudgedPass")) // "mastered, rank 20"
140
+ // One boundary for this script; an Effect app supplies the layer in its
141
+ // own application graph instead.
142
+ void Effect.runPromise(program.pipe(Effect.provide(NativeRuntime.layer(runtimePolicy))))
125
143
  ```
126
144
 
127
145
  Every `ts` fence in this README is extracted and type-checked against the
@@ -132,37 +150,57 @@ real surface by `test/readme.test.ts` — the examples cannot drift.
132
150
  The SDK translates TypeScript values directly into the engine's shared schema
133
151
  and query representations.
134
152
 
135
- - Fields use `bool`, `bytes`, `i64`, `u64`, `str`, `interval`, and
136
- `span`. `relation()` declares stored records, while `closed()` declares a
137
- fixed enum-like set whose values may carry typed columns. `Infer` exposes
138
- the resulting TypeScript value type.
153
+ - Fields use `bool`, `bytes`, `f64`, `i64`, `uuid`, `u64`, `str`, and
154
+ `interval` (`interval(f64)` is the dense float interval); `span` builds
155
+ checked interval values. `relation()` declares stored records, while
156
+ `closed()` declares a fixed enum-like set whose values may carry typed
157
+ columns. `Infer` exposes the resulting TypeScript value type. `Uuid` is
158
+ a structural template-literal string, not a nominal brand or a cast helper.
159
+ It represents all 128-bit UUID payloads in canonical text,
160
+ generated with the effectful `Effect.sync(() => crypto.randomUUID())`, parsed with the pure
161
+ `Uuid.parse` returning `Result`.
139
162
  - `schema()` accepts `key`, `contained`, `mirrors`, and `capacity`
140
- statements. `.where` makes a reference conditional, `within` sets a count
141
- or measurement range, and `weigh` chooses a numeric field or interval
142
- duration to measure.
143
- - `Db.create` and `Db.open` manage embedded stores. Create returns an
144
- `Admission`. Reads are a synchronous callback `db.read((instance, witness) => …)` —
145
- the instance cannot escape; the witness may. Writes use `write` or
146
- `writeFrom(witness, …)` and may return `abandon(payload)` to roll back
147
- explicitly. `insert` and `delete` report how many submitted records
148
- changed the set, and `reserve` returns never-reused IDs.
163
+ statements. Keys are declared statements there is no minted identity.
164
+ `capacity(target, { from, weight?, within })` takes named options;
165
+ `.where` makes a reference conditional, `within` sets a count or
166
+ measurement range, and `weigh` chooses a numeric field or interval
167
+ duration. Harmless equivalent window spellings lower to one canonical
168
+ law; genuinely different meanings still refuse.
169
+ - `NativeRuntime.layer(options)` owns the one bounded native runtime;
170
+ provide it once in the app graph. `Db.create` and `Db.open` are scoped
171
+ Effects over that runtime; `open` never creates and `create` refuses
172
+ existing authority. `db.apply(changes, { ...work, expected })` judges one
173
+ immutable final-state change: `accepted`, `no-change`,
174
+ `invariant-rejected` (complete statement diagnostics), or `moved`.
175
+ - `ChangeSet.builder(schema, work)` acquires a scoped database-free draft;
176
+ `insert`/`delete` are lazy bounded ingestion effects, `finish()` seals the
177
+ immutable `ChangeSet`. Snapshots satisfy the shared `QueryReader`: typed
178
+ `get` returns `Option`, `execute` returns a sealed `CompleteResult` whose
179
+ `collect({ maxBytes }, work)` is capped materialization and whose
180
+ `pages({ pageBytes }, work)` is a one-shot consuming `Stream` of owned page
181
+ arrays after complete evaluation. Delivery work is fresh: it does not
182
+ inherit the snapshot or execution deadline.
149
183
  - `query(S).rule(...)` builds typed queries. Reusing a variable created by
150
184
  `v(R)` joins records through that value. The builder supports named result
151
185
  rows, typed parameters, negation, comparisons, boolean conditions, set
152
- parameters, interval operations, aggregates, named intermediate results,
153
- and linear recursive reachability.
154
- - `Db.exhume` opens a store without its original application schema and
155
- exposes its stored relation descriptions and records by name. The returned
156
- handle uses `using` so the exclusive store lock is released at scope exit.
186
+ parameters, interval operations, exact aggregates (`sum`/`mean` over
187
+ `f64` are deterministic with one final rounding), named intermediate
188
+ results, nonrecursive composition of query templates, and linear
189
+ recursive reachability.
190
+ - `Scalar.field("units")` is an unresolved source-field leaf.
191
+ `Scalar.add(Scalar.field("units"), Scalar.u64(1n))` authors synchronously
192
+ without native loading. Native schema binding typechecks it, including
193
+ on zero rows. There is no `field<T>` assertion and no JS evaluator.
194
+ - Operational failure is the one `DbError` tagged-reason class in the
195
+ Effect error channel; interruption and finalizer problems stay in
196
+ `Cause`. Resource owners are scoped and report honest `CloseReport`s;
197
+ incomplete teardown surfaces as a structured `CloseFailure` defect.
157
198
 
158
199
  ## Cookbook
159
200
 
160
- The engine cookbook's 32 modeling recipes are translated to the TypeScript API
161
- in [COOKBOOK.md](./COOKBOOK.md). `test/cookbook-doc.test.ts` extracts and
162
- type-checks the document's TypeScript examples, while
163
- `test/cookbook.test.ts` opens every schema and prepares every query. The Rust
164
- and TypeScript versions are also checked to ensure that they describe the same
165
- schema.
201
+ Modeling recipes are translated to the TypeScript API in
202
+ [COOKBOOK.md](./COOKBOOK.md). `test/cookbook-doc.test.ts` extracts and
203
+ type-checks the document's TypeScript examples.
166
204
 
167
205
  ## Architecture
168
206
 
@@ -75,17 +75,15 @@ type IsNegative<N extends bigint> = `${N}` extends `-${string}` ? true : false;
75
75
  */
76
76
  type PathBan<F extends string> = string extends F ? unknown : F extends `${string}.${string}` ? RefusedPath<"pin the column — a two-column containment (Source(ref, f) <= Catalog(id, f)) proves the local copy, then name the local field"> : unknown;
77
77
  type NegativeBan<N extends bigint> = bigint extends N ? unknown : IsNegative<N> extends true ? BannedWindow<"capacity bounds are u64 — a negative bound is out of domain"> : unknown;
78
- type FloorBan<N extends bigint> = bigint extends N ? unknown : IsNegative<N> extends true ? BannedWindow<"capacity bounds are u64 — a negative bound is out of domain"> : N extends 0n ? BannedWindow<"`{0..*}` is vacuous — it provably says nothing; delete the statement"> : unknown;
79
- type RangeBan<Lo extends bigint, Hi extends bigint> = bigint extends Lo ? unknown : bigint extends Hi ? unknown : IsNegative<Lo> extends true ? BannedWindow<"capacity bounds are u64 a negative bound is out of domain"> : IsNegative<Hi> extends true ? BannedWindow<"capacity bounds are u64 — a negative bound is out of domain"> : Lo extends Hi ? Hi extends Lo ? Lo extends 0n ? BannedWindow<"`{0..0}` — the point window is written `{0}`: use within(0n)"> : BannedWindow<"`{n..n}` — an exact measure is written `{n}`: use within(n)"> : unknown : unknown;
80
- type UnitWindowBan<W extends CapacityWindow> = W["window"] extends {
81
- readonly kind: "floor";
82
- readonly lo: {
83
- readonly kind: "lit";
84
- readonly value: 1n;
85
- };
86
- } ? BannedWindow<"`{1..*}` on the unit instance says only what the bare containment sayswrite contained(source, target)"> : W["window"] extends {
87
- readonly kind: "floor";
88
- } ? BannedWindow<"`{N..*}` on the unit instance — a bare count floor is refused; weigh the source (`<=[w]{N..*}` stays legal) or drop the bound"> : unknown;
78
+ /**
79
+ * The spelling-ban tables are DELETED (C01, chapter 34): `{n..n}`, `{0..0}`,
80
+ * unit floors `{1..*}`/`{N..*}` and the vacuous `{0..*}` are harmless
81
+ * equivalent spellings that lower to the one canonical `(lo, hi)` law at
82
+ * the mint. Genuinely different semantics still refuse: negative bounds
83
+ * (out of the u64 domain) and inverted literal bounds.
84
+ */
85
+ type FloorBan<N extends bigint> = NegativeBan<N>;
86
+ type RangeBan<Lo extends bigint, Hi extends bigint> = bigint extends Lo ? unknown : bigint extends Hi ? unknown : IsNegative<Lo> extends true ? BannedWindow<"capacity bounds are u64 a negative bound is out of domain"> : IsNegative<Hi> extends true ? BannedWindow<"capacity bounds are u64 — a negative bound is out of domain"> : unknown;
89
87
  /**
90
88
  * The C18 dimension gate's ban row, unit instance (the engine's
91
89
  * `CapacityDimensionMixing` twin, ruled 2026-07-24): a unit (count)
@@ -183,6 +181,12 @@ declare function within<const Lo extends bigint, const Hi extends bigint>(lo: Lo
183
181
  readonly kind: "lit";
184
182
  readonly value: Hi;
185
183
  };
184
+ } | {
185
+ readonly kind: "exact";
186
+ readonly n: {
187
+ readonly kind: "lit";
188
+ readonly value: Lo;
189
+ };
186
190
  }>;
187
191
  /**
188
192
  * `[field]` — the measure: a u64-encoded field of the SOURCE row summed
@@ -206,6 +210,6 @@ declare function ref<const F extends string>(field: F & PathBan<F>): FieldRef<F>
206
210
  * (Duration weights pair with Duration-capable bounds — C18).
207
211
  */
208
212
  declare function duration<const F extends string>(field: F & PathBan<F>): DurationRef<F>;
209
- export type { BoundsOnTarget, CapacityWeight, CapacityWindow, DurationRef, FieldRef, UnitDimensionBan, UnitWindowBan, WeightOnSource };
213
+ export type { BoundsOnTarget, CapacityWeight, CapacityWindow, DurationRef, FieldRef, UnitDimensionBan, WeightOnSource };
210
214
  export { duration, isCapacityWeight, isCapacityWindow, ref, unitWeight, weigh, within };
211
215
  //# sourceMappingURL=capacity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"capacity.d.ts","sourceRoot":"","sources":["../src/capacity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC/E,OAAO,KAAK,EAAqB,kBAAkB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAEjF,QAAA,MAAM,QAAQ,EAAE,OAAO,MAA6C,CAAA;AAEpE,UAAU,cAAc,CAAC,CAAC,SAAS,kBAAkB,GAAG,kBAAkB;IACzE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IAClB,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;CACzB;AAED,UAAU,cAAc,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IACzD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IAClB,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;CACzB;AAED,UAAU,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC3C,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACt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E,WAAW,CAAC,CAAC,CAAC,GACrB,cAAc,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAAA;AAQxE,iBAAS,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAEvE;AAED;;;;;GAKG;AACH,iBAAS,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAE/E;AAED,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAA;AACvH,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"}
package/dist/capacity.js CHANGED
@@ -1,40 +1,4 @@
1
- /**
2
- * Capacity-law mints — the window, weight, and dependent-bound vocabulary
3
- * the one `capacity` statement constructor consumes
4
- * § the canonical-utterance law, restated
5
- * around the aggregate form). `within` is the ONE window spelling —
6
- * `within(n)` exact (`within(0n)` IS the exclusion's one spelling),
7
- * `within(lo, hi)` range (`within(0n, hi)` the canonical ceiling),
8
- * `within(lo, "*")` floor — `weigh` names the measure on the SOURCE row
9
- * (`weigh("watts")` a u64 field, `weigh(duration("booked"))` an interval's
10
- * measure), and `ref`/`duration` read a dependent bound from the
11
- * TARGET row (hi slot only — ruled 2026-07-24, C6). The ban table is
12
- * enforced REPRESENTATIONALLY in two tiers, split per-aggregate where
13
- * weight-sensitive (design § 6: a ban is canonical-utterance policing when
14
- * it is weight-independent, semantic deduplication when it is not):
15
- *
16
- * - **The type tier**: a banned spelling written as a LITERAL does not
17
- * compile — every negative bound, `within(n, n)`, `within(0n, 0n)`, and
18
- * `within(0n, "*")` are type errors naming the canonical form. The
19
- * weight-SENSITIVE row rides the `capacity` overloads themselves:
20
- * `within(1n, "*")` is banned on the unit overload only (`{1..*}` on the
21
- * count instance is the bare containment respelled —
22
- * `window_floor_containment`), and LEGAL on the weighted one ("positive
23
- * total" is not an existence claim over rows).
24
- * - **The construction tier**: a bound the type level cannot judge — a
25
- * COMPUTED `bigint`, or an inverted `within(lo, hi)` order — is judged at
26
- * construction with the same canonical-naming errors; and past both
27
- * tiers the engine's own spec validation remains the law for a hostile
28
- * FFI caller (the standing two-tier ban enforcement).
29
- *
30
- * The weight vocabulary is closed at the row (ruled 2026-07-24, ruling 6):
31
- * a path weight (`weigh("model.watts")`) is a typed refusal at BOTH tiers
32
- * whose diagnostic names the pinned-column idiom — the two-column
33
- * containment IS the join, stated as a law. Bounds are `bigint` (u64
34
- * crosses as bigint always, PRD-04's law); the witnessed measure comes
35
- * back as `bigint` too (u128-wide engine accumulator, C3).
36
- */
37
- import * as errors from "@superbuilders/errors";
1
+ import { AuthoringError } from "#errors.ts";
38
2
  const admitted = Symbol("bumbledb.capacity.admitted");
39
3
  function isCapacityWindow(value) {
40
4
  return typeof value === "object" && value !== null && admitted in value && "window" in value;
@@ -45,7 +9,9 @@ function isCapacityWeight(value) {
45
9
  const unitWeight = Object.freeze({ kind: "unit" });
46
10
  function assertRowLocal(field, role) {
47
11
  if (field.includes(".")) {
48
- throw errors.new(`${role} \`${field}\` walks a reference — the vocabulary is closed at the row (ruling 6): pin the column with a two-column containment (Source(ref, f) <= Catalog(id, f)) and name the local field`);
12
+ throw new AuthoringError({
13
+ message: `${role} \`${field}\` walks a reference — the vocabulary is closed at the row (ruling 6): pin the column with a two-column containment (Source(ref, f) <= Catalog(id, f)) and name the local field`
14
+ });
49
15
  }
50
16
  return field;
51
17
  }
@@ -58,29 +24,31 @@ function lit(value) {
58
24
  }
59
25
  function within(lo, hi) {
60
26
  if (lo < 0n) {
61
- throw errors.new(`capacity bounds are u64: within(${lo}${hi === undefined ? "" : ", …"}) is out of domain`);
27
+ throw new AuthoringError({
28
+ message: `capacity bounds are u64: within(${lo}${hi === undefined ? "" : ", …"}) is out of domain`
29
+ });
62
30
  }
63
31
  if (hi === undefined) {
64
32
  return admitWindow({ kind: "exact", n: lit(lo) });
65
33
  }
66
34
  if (hi === "*") {
67
- if (lo === 0n) {
68
- throw errors.new("the `{0..*}` window is vacuous — it provably says nothing; delete the statement");
69
- }
35
+ // `{0..*}` (vacuous) and `{N..*}` floors are ACCEPTED canonical laws
36
+ // (C01): normalization preserves authored statement attribution
37
+ // instead of policing the spelling.
70
38
  return admitWindow({ kind: "floor", lo: lit(lo) });
71
39
  }
72
40
  if (typeof hi === "bigint") {
73
41
  if (hi < 0n) {
74
- throw errors.new(`capacity bounds are u64: within(${lo}, ${hi}) is out of domain`);
42
+ throw new AuthoringError({ message: `capacity bounds are u64: within(${lo}, ${hi}) is out of domain` });
75
43
  }
76
44
  if (hi < lo) {
77
- throw errors.new(`the window \`{${lo}..${hi}}\` is inverted — no measure satisfies it; bounds are \`{lo..hi}\` with lo < hi (an exact measure is \`{n}\`: within(n))`);
45
+ throw new AuthoringError({
46
+ message: `the window \`{${lo}..${hi}}\` is inverted — no measure satisfies it; bounds are \`{lo..hi}\` with lo <= hi`
47
+ });
78
48
  }
79
49
  if (lo === hi) {
80
- if (lo === 0n) {
81
- throw errors.new("`{0..0}` the point window is written `{0}`: use within(0n)");
82
- }
83
- throw errors.new(`\`{${lo}..${lo}}\` — an exact measure is written \`{${lo}}\`: use within(${lo}n)`);
50
+ // `{n..n}` and `{0..0}` lower to the one canonical exact law.
51
+ return admitWindow({ kind: "exact", n: lit(lo) });
84
52
  }
85
53
  return admitWindow({ kind: "range", lo: lit(lo), hi: lit(hi) });
86
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"capacity.js","sourceRoot":"","sources":["../src/capacity.ts"],"names":[],"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6B;IAC3C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;AAC9F,CAAC;AAED,SAAS,GAAG,CAAyB,KAAqB;IACzD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,CAAC,KAAK,EAAE,iBAAiB,CAAC,EAAE,CAAgB,CAAA;AACxG,CAAC;AAED;;;;;GAKG;AACH,SAAS,QAAQ,CAAyB,KAAqB;IAC9D,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,CAAC,KAAK,EAAE,kBAAkB,CAAC,EAAE,CAAmB,CAAA;AACpH,CAAC;AAGD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"}
@@ -0,0 +1,54 @@
1
+ import type { Scope } from "effect";
2
+ import { Effect } from "effect";
3
+ import type { SchemaId } from "./compile.js";
4
+ import type { ChangesHandle } from "./db-native.js";
5
+ import type { Fact } from "./relation.js";
6
+ import type { ExecutionPolicy } from "./runtime.js";
7
+ import type { CloseReport } from "./runtime-errors.js";
8
+ import { DbError } from "./runtime-errors.js";
9
+ import type { AnySchema } from "./schema.js";
10
+ import type { Rel } from "./shape.js";
11
+ /**
12
+ * `ChangeSet` — the public name of the engine's checked immutable delta
13
+ * (chapter 30/34): schema-fingerprint-bound canonical native bytes with
14
+ * one-command `(add, remove ∖ add)` normalization and exact same-fact
15
+ * add-wins. Immutable and reusable while open; sealing/submitting it later
16
+ * retains the SAME native value — no second JS row walk ever happens.
17
+ */
18
+ interface ChangeSet<S extends AnySchema> {
19
+ readonly schemaId: SchemaId;
20
+ /** Phantom schema brand: a ChangeSet is only ever applied to its own S. */
21
+ readonly schema?: S;
22
+ close(): Effect.Effect<CloseReport>;
23
+ }
24
+ /**
25
+ * `ChangeDraft` — the scoped, database-free construction capability.
26
+ * Every method constructs a LAZY effect; execution reads the then-current
27
+ * iterable and charges its work again on every sequential rerun (no hidden
28
+ * memoization, no automatic retry, no iterator replay). Input must stay
29
+ * stable from an ingestion effect's execution start through its Exit;
30
+ * after successful ingestion the accepted native bytes are independent.
31
+ * Failure/interruption SPENDS the draft and initiates tracked drain.
32
+ * Concurrent/reentrant construction refuses and spends/drains the draft.
33
+ * `finish` consumes the draft; later ingestion or a second finish refuses
34
+ * through the spent capability state.
35
+ */
36
+ interface ChangeDraft<S extends AnySchema> {
37
+ insert<R extends Rel<S>>(relation: R, rows: Iterable<Fact<R>>): Effect.Effect<void, DbError>;
38
+ delete<R extends Rel<S>>(relation: R, rows: Iterable<Fact<R>>): Effect.Effect<void, DbError>;
39
+ finish(): Effect.Effect<ChangeSet<S>, DbError, Scope.Scope>;
40
+ close(): Effect.Effect<CloseReport>;
41
+ }
42
+ interface ChangesInternal {
43
+ readonly handle: ChangesHandle;
44
+ readonly schemaId: SchemaId;
45
+ closed: boolean;
46
+ }
47
+ /** Private cross-module accessor (db.apply retains the native ChangeSet). */
48
+ declare function internalChanges(value: object): ChangesInternal | undefined;
49
+ declare const ChangeSet: Readonly<{
50
+ builder: <S extends AnySchema>(schema: S, work: ExecutionPolicy) => Effect.Effect<ChangeDraft<S>, DbError, import("./runtime.js").NativeRuntime | Scope.Scope>;
51
+ }>;
52
+ export type { ChangeDraft };
53
+ export { ChangeSet, internalChanges };
54
+ //# sourceMappingURL=changes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changes.d.ts","sourceRo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