@bjornpagen/bumbledb 1.0.0 → 1.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 (102) hide show
  1. package/COOKBOOK.md +64 -27
  2. package/README.md +21 -20
  3. package/dist/capacity.d.ts +1 -1
  4. package/dist/changes.d.ts +4 -5
  5. package/dist/changes.d.ts.map +1 -1
  6. package/dist/changes.js +37 -34
  7. package/dist/changes.js.map +1 -1
  8. package/dist/close.d.ts +2 -2
  9. package/dist/codec.d.ts +5 -6
  10. package/dist/codec.d.ts.map +1 -1
  11. package/dist/codec.js +6 -6
  12. package/dist/codec.js.map +1 -1
  13. package/dist/compile.d.ts +4 -6
  14. package/dist/compile.d.ts.map +1 -1
  15. package/dist/compile.js +6 -6
  16. package/dist/compile.js.map +1 -1
  17. package/dist/db-native.d.ts +43 -56
  18. package/dist/db-native.d.ts.map +1 -1
  19. package/dist/db-native.js.map +1 -1
  20. package/dist/db.d.ts +43 -28
  21. package/dist/db.d.ts.map +1 -1
  22. package/dist/db.js +77 -63
  23. package/dist/db.js.map +1 -1
  24. package/dist/errors.d.ts +4 -8
  25. package/dist/errors.d.ts.map +1 -1
  26. package/dist/errors.js +4 -8
  27. package/dist/errors.js.map +1 -1
  28. package/dist/fields.d.ts +4 -5
  29. package/dist/fields.d.ts.map +1 -1
  30. package/dist/fields.js.map +1 -1
  31. package/dist/index.d.ts +4 -4
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal/log.d.ts +4 -4
  36. package/dist/internal/log.d.ts.map +1 -1
  37. package/dist/internal/log.js +1 -1
  38. package/dist/internal/log.js.map +1 -1
  39. package/dist/law.d.ts +1 -1
  40. package/dist/migration.d.ts +5 -7
  41. package/dist/migration.d.ts.map +1 -1
  42. package/dist/migration.js +8 -9
  43. package/dist/migration.js.map +1 -1
  44. package/dist/native.d.ts +2 -2
  45. package/dist/native.d.ts.map +1 -1
  46. package/dist/native.js.map +1 -1
  47. package/dist/query/lower.d.ts +1 -1
  48. package/dist/result.d.ts +10 -25
  49. package/dist/result.d.ts.map +1 -1
  50. package/dist/result.js +7 -12
  51. package/dist/result.js.map +1 -1
  52. package/dist/rows.d.ts +10 -16
  53. package/dist/rows.d.ts.map +1 -1
  54. package/dist/rows.js +8 -45
  55. package/dist/rows.js.map +1 -1
  56. package/dist/runtime-codes.d.ts +1 -1
  57. package/dist/runtime-codes.d.ts.map +1 -1
  58. package/dist/runtime-codes.js +1 -2
  59. package/dist/runtime-codes.js.map +1 -1
  60. package/dist/runtime-errors.d.ts +3 -15
  61. package/dist/runtime-errors.d.ts.map +1 -1
  62. package/dist/runtime-errors.js +1 -5
  63. package/dist/runtime-errors.js.map +1 -1
  64. package/dist/runtime-native.d.ts +18 -48
  65. package/dist/runtime-native.d.ts.map +1 -1
  66. package/dist/runtime-native.js.map +1 -1
  67. package/dist/runtime.d.ts +12 -29
  68. package/dist/runtime.d.ts.map +1 -1
  69. package/dist/runtime.js +16 -57
  70. package/dist/runtime.js.map +1 -1
  71. package/dist/shape.d.ts +3 -4
  72. package/dist/shape.d.ts.map +1 -1
  73. package/dist/spec.d.ts +2 -2
  74. package/dist/spec.js +1 -1
  75. package/dist/statements.js +2 -2
  76. package/dist/statements.js.map +1 -1
  77. package/pack-provenance.json +3 -3
  78. package/package.json +4 -4
  79. package/src/capacity.ts +1 -1
  80. package/src/changes.ts +50 -48
  81. package/src/close.ts +2 -2
  82. package/src/codec.ts +8 -24
  83. package/src/compile.ts +8 -10
  84. package/src/db-native.ts +37 -83
  85. package/src/db.ts +156 -135
  86. package/src/errors.ts +4 -8
  87. package/src/fields.ts +4 -5
  88. package/src/index.ts +6 -5
  89. package/src/internal/log.ts +2 -7
  90. package/src/law.ts +1 -1
  91. package/src/migration.ts +8 -16
  92. package/src/native.ts +2 -3
  93. package/src/query/lower.ts +1 -1
  94. package/src/result.ts +16 -45
  95. package/src/rows.ts +12 -65
  96. package/src/runtime-codes.ts +1 -2
  97. package/src/runtime-errors.ts +1 -5
  98. package/src/runtime-native.ts +15 -68
  99. package/src/runtime.ts +53 -122
  100. package/src/shape.ts +3 -4
  101. package/src/spec.ts +2 -2
  102. package/src/statements.ts +2 -2
package/src/db-native.ts CHANGED
@@ -1,31 +1,22 @@
1
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
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 ownership and completes through the registered callback; `runtimeCancel` cancels
15
6
  * and joins any of them. Close verbs report the real drain outcome through
16
7
  * `CloseWire`.
17
8
  */
18
9
  import type { DbHandle, ParsedQuery, QueryParam, SealedDescriptor, Violation } from "#native.ts"
19
10
  import { native } from "#native.ts"
20
11
  import type { CellValue } from "#rows.ts"
21
- import type { CloseWire, OperationHandle, PolicyWire, RuntimeHandle } from "#runtime-native.ts"
12
+ import type { CloseWire, OperationHandle, RuntimeHandle } from "#runtime-native.ts"
22
13
  import type { SchemaSpec } from "#spec.ts"
23
14
 
24
15
  export interface SnapshotHandle {
25
16
  readonly __snapshot: unique symbol
26
17
  }
27
- export interface SessionHandle {
28
- readonly __session: unique symbol
18
+ export interface PreparedHandle {
19
+ readonly __prepared: unique symbol
29
20
  }
30
21
  export interface ResultHandle {
31
22
  readonly __result: unique symbol
@@ -59,10 +50,7 @@ export type ApplyOutcomeWire =
59
50
  /** Bounded database diagnostics: measurements, never retained row payloads. */
60
51
  export interface DbInspectionWire {
61
52
  readonly generation: bigint
62
- readonly mapBytes: bigint
63
- readonly populatedBytes: bigint
64
- readonly diskBytes: bigint
65
- readonly residentEstimateBytes: bigint
53
+ readonly storage: import("#db.ts").StorageInspection
66
54
  readonly retainedOperations: bigint
67
55
  }
68
56
 
@@ -82,29 +70,24 @@ export interface MutationReportWire {
82
70
  }
83
71
 
84
72
  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
73
+ /** Schema admission/compilation; take yields detached descriptor data. */
74
+ runtimeSchemaCompile(runtime: RuntimeHandle, spec: SchemaSpec, callback: () => void): OperationHandle
92
75
  runtimeSchemaTake(operation: OperationHandle): SealedDescriptor
93
76
 
94
77
  /** Coherent owned snapshot acquisition off a managed database. */
95
- runtimeDbSnapshot(db: DbHandle, policy: PolicyWire, callback: () => void): OperationHandle
78
+ runtimeDbSnapshot(db: DbHandle, callback: () => void): OperationHandle
96
79
  runtimeSnapshotTake(operation: OperationHandle): SnapshotWire
97
80
  runtimeSnapshotClose(snapshot: SnapshotHandle, callback: (report: CloseWire) => void): void
98
81
 
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
82
+ /** One compiled query, with an independent share of the snapshot pin. */
83
+ runtimeSnapshotPrepare(snapshot: SnapshotHandle, query: ParsedQuery, callback: () => void): OperationHandle
84
+ runtimePreparedTake(operation: OperationHandle): PreparedHandle
85
+ runtimePreparedClose(prepared: PreparedHandle, callback: (report: CloseWire) => void): void
86
+ runtimePreparedReleaseMemory(prepared: PreparedHandle, callback: () => void): OperationHandle
103
87
 
104
88
  /** Exact-key point read; take yields one owned row or null (absent). */
105
89
  runtimeSnapshotGet(
106
90
  snapshot: SnapshotHandle,
107
- policy: PolicyWire,
108
91
  relationId: number,
109
92
  keyStatementId: number,
110
93
  keyCells: readonly CellValue[],
@@ -113,34 +96,25 @@ interface DbBridge {
113
96
  runtimeRowTake(operation: OperationHandle): readonly CellValue[] | null
114
97
 
115
98
  /**
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).
99
+ * Complete execution. One-shot preparation drops before publication;
100
+ * explicit preparation reuses its compiled plan and scratch. The result is
101
+ * sealed and independent only after ALL evaluation succeeded.
120
102
  */
121
103
  runtimeSnapshotExecute(
122
104
  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
105
  query: ParsedQuery,
132
106
  params: readonly QueryParam[],
133
107
  callback: () => void
134
108
  ): OperationHandle
109
+ runtimePreparedExecute(prepared: PreparedHandle, params: readonly QueryParam[], callback: () => void): OperationHandle
135
110
  runtimeResultTake(operation: OperationHandle): ResultHandle
136
111
  runtimeResultClose(result: ResultHandle, callback: (report: CloseWire) => void): void
137
112
 
138
113
  /**
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.
114
+ * Explicit full materialization into final native row arrays.
115
+ * Failure leaves the sealed backing available.
142
116
  */
143
- runtimeResultCollect(result: ResultHandle, policy: PolicyWire, callback: () => void): OperationHandle
117
+ runtimeResultCollect(result: ResultHandle, callback: () => void): OperationHandle
144
118
  runtimeRowsTake(operation: OperationHandle): readonly (readonly CellValue[])[]
145
119
 
146
120
  /**
@@ -148,25 +122,24 @@ interface DbBridge {
148
122
  * private cursor. A second transfer, or transfer racing collect,
149
123
  * refuses (SpentHandle) before touching the backing.
150
124
  */
151
- runtimeResultCursor(result: ResultHandle, policy: PolicyWire, callback: () => void): OperationHandle
125
+ runtimeResultCursor(result: ResultHandle, callback: () => void): OperationHandle
152
126
  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
127
+ /** One bounded delivery batch; null is EOF. Execution is already complete. */
128
+ runtimeCursorNext(cursor: CursorHandle, callback: () => void): OperationHandle
155
129
  runtimePageTake(operation: OperationHandle): readonly (readonly CellValue[])[] | null
156
130
  runtimeCursorClose(cursor: CursorHandle, callback: (report: CloseWire) => void): void
157
131
 
158
132
  /** Database-free draft acquisition (schema compiled/checked on the executor). */
159
- runtimeDraftOpen(runtime: RuntimeHandle, policy: PolicyWire, spec: SchemaSpec, callback: () => void): OperationHandle
133
+ runtimeDraftOpen(runtime: RuntimeHandle, spec: SchemaSpec, callback: () => void): OperationHandle
160
134
  runtimeDraftTake(operation: OperationHandle): DraftHandle
161
135
  /**
162
136
  * 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
137
+ * field order). Rows are owned by the draft until finish. Failure spends
138
+ * the draft and starts tracked
165
139
  * drain natively.
166
140
  */
167
141
  runtimeDraftInsert(
168
142
  draft: DraftHandle,
169
- policy: PolicyWire,
170
143
  relationId: number,
171
144
  rows: bigint,
172
145
  cells: readonly CellValue[],
@@ -174,7 +147,6 @@ interface DbBridge {
174
147
  ): OperationHandle
175
148
  runtimeDraftDelete(
176
149
  draft: DraftHandle,
177
- policy: PolicyWire,
178
150
  relationId: number,
179
151
  rows: bigint,
180
152
  cells: readonly CellValue[],
@@ -182,28 +154,22 @@ interface DbBridge {
182
154
  ): OperationHandle
183
155
  runtimeReportTake(operation: OperationHandle): MutationReportWire
184
156
  /** Consumes the draft into an immutable schema-bound ChangeSet (one command, add-wins normalization). */
185
- runtimeDraftFinish(draft: DraftHandle, policy: PolicyWire, callback: () => void): OperationHandle
157
+ runtimeDraftFinish(draft: DraftHandle, callback: () => void): OperationHandle
186
158
  runtimeChangesTake(operation: OperationHandle): ChangesWire
187
159
  runtimeDraftClose(draft: DraftHandle, callback: (report: CloseWire) => void): void
188
160
  runtimeChangesClose(changes: ChangesHandle, callback: (report: CloseWire) => void): void
189
161
 
190
162
  /** 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
163
+ runtimeDbApply(db: DbHandle, changes: ChangesHandle, expected: ExpectedWire, callback: () => void): OperationHandle
198
164
  runtimeApplyTake(operation: OperationHandle): ApplyOutcomeWire
199
165
 
200
- runtimeDbInspect(db: DbHandle, policy: PolicyWire, callback: () => void): OperationHandle
166
+ runtimeDbInspect(db: DbHandle, callback: () => void): OperationHandle
167
+ runtimeDbClearCache(db: DbHandle, callback: () => void): OperationHandle
201
168
  runtimeDbInspectTake(operation: OperationHandle): DbInspectionWire
202
169
 
203
170
  /** Shared canonical row codec (also the log/migration encoding). */
204
171
  runtimeEncodeRows(
205
172
  runtime: RuntimeHandle,
206
- policy: PolicyWire,
207
173
  spec: SchemaSpec,
208
174
  relationId: number,
209
175
  rows: bigint,
@@ -213,7 +179,6 @@ interface DbBridge {
213
179
  runtimeBytesTake(operation: OperationHandle): Uint8Array
214
180
  runtimeDecodeRows(
215
181
  runtime: RuntimeHandle,
216
- policy: PolicyWire,
217
182
  spec: SchemaSpec,
218
183
  relationId: number,
219
184
  bytes: Uint8Array,
@@ -221,25 +186,14 @@ interface DbBridge {
221
186
  ): OperationHandle
222
187
 
223
188
  /**
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
189
+ * Read-only migration-codec integration over native `schema_file` and
190
+ * `migration::{plan, manifest}` through the shared executor: bounded
227
191
  * owned input, bounded owned JSON response bytes, one registered
228
192
  * cancellable operation. Neither verb opens, initializes, freezes or
229
193
  * migrates a database.
230
194
  */
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
195
+ runtimeMigrationSchema(runtime: RuntimeHandle, spec: SchemaSpec, callback: () => void): OperationHandle
196
+ runtimeMigrationRead(runtime: RuntimeHandle, request: Uint8Array, callback: () => void): OperationHandle
243
197
  }
244
198
 
245
199
  // The fresh-addon roster test pins this private declaration exactly as it