@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
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Private core database bridge roster — the C09/C05 CONSUMER-side pin for
3
+ * the managed runtime verbs the chapter 35 core surface dispatches. Not a
4
+ * public API: nothing here is exported from the package barrel.
5
+ *
6
+ * OWNERSHIP NOTE (recorded in implementation/packets/P07.md): the addon
7
+ * implementation of every verb below is P06R's lane (`ts/crate/src/`,
8
+ * worker-affine sessions per P06.md's reactor design) on top of P02's C04
9
+ * owned snapshots and P03's C05 completed results. This file declares the
10
+ * exact shapes P07 codes against, exactly as `#runtime-native.ts` pins the
11
+ * landed runtime/directory/fs handshake. Every verb runs on the ONE bounded
12
+ * executor (no AsyncTask/libuv bypass), registers under the runtime's
13
+ * operation accounting, takes a `PolicyWire` converted once at admission,
14
+ * and completes through the registered callback; `runtimeCancel` cancels
15
+ * and joins any of them. Close verbs report the real drain outcome through
16
+ * `CloseWire`.
17
+ */
18
+ import type { DbHandle, ParsedQuery, QueryParam, SealedDescriptor, Violation } from "#native.ts"
19
+ import { native } from "#native.ts"
20
+ import type { CellValue } from "#rows.ts"
21
+ import type { CloseWire, OperationHandle, PolicyWire, RuntimeHandle } from "#runtime-native.ts"
22
+ import type { SchemaSpec } from "#spec.ts"
23
+
24
+ export interface SnapshotHandle {
25
+ readonly __snapshot: unique symbol
26
+ }
27
+ export interface SessionHandle {
28
+ readonly __session: unique symbol
29
+ }
30
+ export interface ResultHandle {
31
+ readonly __result: unique symbol
32
+ }
33
+ export interface CursorHandle {
34
+ readonly __cursor: unique symbol
35
+ }
36
+ export interface DraftHandle {
37
+ readonly __draft: unique symbol
38
+ }
39
+ export interface ChangesHandle {
40
+ readonly __changes: unique symbol
41
+ }
42
+
43
+ /** The core-local witness: catalog/store identity plus generation, never a StateStamp. */
44
+ export interface WitnessWire {
45
+ readonly store: string
46
+ readonly generation: bigint
47
+ }
48
+
49
+ export type ExpectedWire =
50
+ | { readonly kind: "any" }
51
+ | { readonly kind: "exact"; readonly store: string; readonly generation: bigint }
52
+
53
+ export type ApplyOutcomeWire =
54
+ | { readonly tag: "accepted"; readonly witness: WitnessWire }
55
+ | { readonly tag: "no-change"; readonly witness: WitnessWire }
56
+ | { readonly tag: "invariant-rejected"; readonly violations: readonly Violation[] }
57
+ | { readonly tag: "moved"; readonly witnessed: WitnessWire; readonly current: WitnessWire }
58
+
59
+ /** Bounded database diagnostics: measurements, never retained row payloads. */
60
+ export interface DbInspectionWire {
61
+ readonly generation: bigint
62
+ readonly mapBytes: bigint
63
+ readonly populatedBytes: bigint
64
+ readonly diskBytes: bigint
65
+ readonly residentEstimateBytes: bigint
66
+ readonly retainedOperations: bigint
67
+ }
68
+
69
+ export interface SnapshotWire {
70
+ readonly snapshot: SnapshotHandle
71
+ readonly witness: WitnessWire
72
+ }
73
+
74
+ export interface ChangesWire {
75
+ readonly changes: ChangesHandle
76
+ readonly fingerprint: string
77
+ }
78
+
79
+ export interface MutationReportWire {
80
+ readonly submitted: bigint
81
+ readonly changed: bigint
82
+ }
83
+
84
+ interface DbBridge {
85
+ /** Charged schema admission/compilation; take yields detached descriptor data. */
86
+ runtimeSchemaCompile(
87
+ runtime: RuntimeHandle,
88
+ policy: PolicyWire,
89
+ spec: SchemaSpec,
90
+ callback: () => void
91
+ ): OperationHandle
92
+ runtimeSchemaTake(operation: OperationHandle): SealedDescriptor
93
+
94
+ /** Coherent owned snapshot acquisition off a managed database. */
95
+ runtimeDbSnapshot(db: DbHandle, policy: PolicyWire, callback: () => void): OperationHandle
96
+ runtimeSnapshotTake(operation: OperationHandle): SnapshotWire
97
+ runtimeSnapshotClose(snapshot: SnapshotHandle, callback: (report: CloseWire) => void): void
98
+
99
+ /** Reusable snapshot-bound execution session (worker-affine natively). */
100
+ runtimeSnapshotSession(snapshot: SnapshotHandle, policy: PolicyWire, callback: () => void): OperationHandle
101
+ runtimeSessionTake(operation: OperationHandle): SessionHandle
102
+ runtimeSessionClose(session: SessionHandle, callback: (report: CloseWire) => void): void
103
+
104
+ /** Exact-key point read; take yields one owned row or null (absent). */
105
+ runtimeSnapshotGet(
106
+ snapshot: SnapshotHandle,
107
+ policy: PolicyWire,
108
+ relationId: number,
109
+ keyStatementId: number,
110
+ keyCells: readonly CellValue[],
111
+ callback: () => void
112
+ ): OperationHandle
113
+ runtimeRowTake(operation: OperationHandle): readonly CellValue[] | null
114
+
115
+ /**
116
+ * Complete bounded execution. The snapshot variant owns an internal
117
+ * one-shot session and closes it before publishing the result; the
118
+ * session variant reuses the caller's session. Either way the result is
119
+ * sealed and independent only after ALL evaluation succeeded (C05).
120
+ */
121
+ runtimeSnapshotExecute(
122
+ snapshot: SnapshotHandle,
123
+ policy: PolicyWire,
124
+ query: ParsedQuery,
125
+ params: readonly QueryParam[],
126
+ callback: () => void
127
+ ): OperationHandle
128
+ runtimeSessionExecute(
129
+ session: SessionHandle,
130
+ policy: PolicyWire,
131
+ query: ParsedQuery,
132
+ params: readonly QueryParam[],
133
+ callback: () => void
134
+ ): OperationHandle
135
+ runtimeResultTake(operation: OperationHandle): ResultHandle
136
+ runtimeResultClose(result: ResultHandle, callback: (report: CloseWire) => void): void
137
+
138
+ /**
139
+ * Bounded total materialization: refuses (ResourceLimit) BEFORE
140
+ * allocating past `policy.resultBytes`; a cap failure leaves the sealed
141
+ * backing available. Take yields owned row arrays.
142
+ */
143
+ runtimeResultCollect(result: ResultHandle, policy: PolicyWire, callback: () => void): OperationHandle
144
+ runtimeRowsTake(operation: OperationHandle): readonly (readonly CellValue[])[]
145
+
146
+ /**
147
+ * Atomic spend: moves the completed result's backing storage into one
148
+ * private cursor. A second transfer, or transfer racing collect,
149
+ * refuses (SpentHandle) before touching the backing.
150
+ */
151
+ runtimeResultCursor(result: ResultHandle, policy: PolicyWire, callback: () => void): OperationHandle
152
+ runtimeCursorTake(operation: OperationHandle): CursorHandle
153
+ /** One owned page bounded by `policy.resultBytes`; null is EOF (cursor storage reclaimed). */
154
+ runtimeCursorNext(cursor: CursorHandle, policy: PolicyWire, callback: () => void): OperationHandle
155
+ runtimePageTake(operation: OperationHandle): readonly (readonly CellValue[])[] | null
156
+ runtimeCursorClose(cursor: CursorHandle, callback: (report: CloseWire) => void): void
157
+
158
+ /** Database-free draft acquisition (schema compiled/checked on the executor). */
159
+ runtimeDraftOpen(runtime: RuntimeHandle, policy: PolicyWire, spec: SchemaSpec, callback: () => void): OperationHandle
160
+ runtimeDraftTake(operation: OperationHandle): DraftHandle
161
+ /**
162
+ * One bounded ingestion chunk (rows × arity cells, row-major, sealed
163
+ * field order). Chunks share the draft's cumulative aggregate budget —
164
+ * they never reset it. Failure spends the draft and starts tracked
165
+ * drain natively.
166
+ */
167
+ runtimeDraftInsert(
168
+ draft: DraftHandle,
169
+ policy: PolicyWire,
170
+ relationId: number,
171
+ rows: bigint,
172
+ cells: readonly CellValue[],
173
+ callback: () => void
174
+ ): OperationHandle
175
+ runtimeDraftDelete(
176
+ draft: DraftHandle,
177
+ policy: PolicyWire,
178
+ relationId: number,
179
+ rows: bigint,
180
+ cells: readonly CellValue[],
181
+ callback: () => void
182
+ ): OperationHandle
183
+ runtimeReportTake(operation: OperationHandle): MutationReportWire
184
+ /** Consumes the draft into an immutable schema-bound ChangeSet (one command, add-wins normalization). */
185
+ runtimeDraftFinish(draft: DraftHandle, policy: PolicyWire, callback: () => void): OperationHandle
186
+ runtimeChangesTake(operation: OperationHandle): ChangesWire
187
+ runtimeDraftClose(draft: DraftHandle, callback: (report: CloseWire) => void): void
188
+ runtimeChangesClose(changes: ChangesHandle, callback: (report: CloseWire) => void): void
189
+
190
+ /** One immutable final-state admission/commit under the managed owner. */
191
+ runtimeDbApply(
192
+ db: DbHandle,
193
+ policy: PolicyWire,
194
+ changes: ChangesHandle,
195
+ expected: ExpectedWire,
196
+ callback: () => void
197
+ ): OperationHandle
198
+ runtimeApplyTake(operation: OperationHandle): ApplyOutcomeWire
199
+
200
+ runtimeDbInspect(db: DbHandle, policy: PolicyWire, callback: () => void): OperationHandle
201
+ runtimeDbInspectTake(operation: OperationHandle): DbInspectionWire
202
+
203
+ /** Shared canonical row codec (also the log/migration encoding). */
204
+ runtimeEncodeRows(
205
+ runtime: RuntimeHandle,
206
+ policy: PolicyWire,
207
+ spec: SchemaSpec,
208
+ relationId: number,
209
+ rows: bigint,
210
+ cells: readonly CellValue[],
211
+ callback: () => void
212
+ ): OperationHandle
213
+ runtimeBytesTake(operation: OperationHandle): Uint8Array
214
+ runtimeDecodeRows(
215
+ runtime: RuntimeHandle,
216
+ policy: PolicyWire,
217
+ spec: SchemaSpec,
218
+ relationId: number,
219
+ bytes: Uint8Array,
220
+ callback: () => void
221
+ ): OperationHandle
222
+
223
+ /**
224
+ * Read-only migration-codec integration (C11; P09's native
225
+ * `schema_file::{schema_id, render}` / `migration::{plan, manifest}`
226
+ * lanes reached through the P06 executor). `hashChunk`-shaped: bounded
227
+ * owned input, bounded owned JSON response bytes, one registered
228
+ * cancellable operation. Neither verb opens, initializes, freezes or
229
+ * migrates a database.
230
+ */
231
+ runtimeMigrationSchema(
232
+ runtime: RuntimeHandle,
233
+ policy: PolicyWire,
234
+ spec: SchemaSpec,
235
+ callback: () => void
236
+ ): OperationHandle
237
+ runtimeMigrationRead(
238
+ runtime: RuntimeHandle,
239
+ policy: PolicyWire,
240
+ request: Uint8Array,
241
+ callback: () => void
242
+ ): OperationHandle
243
+ }
244
+
245
+ // The fresh-addon roster test pins this private declaration exactly as it
246
+ // pins #runtime-native.ts's; the two casts re-type the SAME single binding.
247
+ export const dbNative = native as typeof native & DbBridge