@bjornpagen/bumbledb 0.20.3 → 1.0.1

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