@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.
- package/COOKBOOK.md +283 -1611
- package/README.md +156 -118
- package/dist/capacity.d.ts +16 -12
- package/dist/capacity.d.ts.map +1 -1
- package/dist/capacity.js +16 -48
- package/dist/capacity.js.map +1 -1
- package/dist/changes.d.ts +54 -0
- package/dist/changes.d.ts.map +1 -0
- package/dist/changes.js +245 -0
- package/dist/changes.js.map +1 -0
- package/dist/close.d.ts +24 -0
- package/dist/close.d.ts.map +1 -0
- package/dist/close.js +34 -0
- package/dist/close.js.map +1 -0
- package/dist/closed.d.ts +1 -3
- package/dist/closed.d.ts.map +1 -1
- package/dist/closed.js +24 -12
- package/dist/closed.js.map +1 -1
- package/dist/codec.d.ts +56 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +289 -0
- package/dist/codec.js.map +1 -0
- package/dist/compile.d.ts +68 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +75 -0
- package/dist/compile.js.map +1 -0
- package/dist/db-native.d.ts +170 -0
- package/dist/db-native.d.ts.map +1 -0
- package/dist/db-native.js +5 -0
- package/dist/db-native.js.map +1 -0
- package/dist/db.d.ts +101 -233
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +232 -1084
- package/dist/db.js.map +1 -1
- package/dist/errors.d.ts +57 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +32 -0
- package/dist/errors.js.map +1 -0
- package/dist/face.d.ts.map +1 -1
- package/dist/face.js +2 -2
- package/dist/face.js.map +1 -1
- package/dist/fields.d.ts +65 -24
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +94 -24
- package/dist/fields.js.map +1 -1
- package/dist/index.d.ts +37 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -21
- package/dist/index.js.map +1 -1
- package/dist/internal/log.d.ts +24 -0
- package/dist/internal/log.d.ts.map +1 -0
- package/dist/internal/log.js +10 -0
- package/dist/internal/log.js.map +1 -0
- package/dist/law.d.ts +8 -13
- package/dist/law.d.ts.map +1 -1
- package/dist/law.js +6 -59
- package/dist/law.js.map +1 -1
- package/dist/lower.d.ts +0 -13
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +9 -17
- package/dist/lower.js.map +1 -1
- package/dist/migration.d.ts +33 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +48 -0
- package/dist/migration.js.map +1 -0
- package/dist/native.d.ts +256 -301
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +65 -108
- package/dist/native.js.map +1 -1
- package/dist/query/atom.d.ts +24 -13
- package/dist/query/atom.d.ts.map +1 -1
- package/dist/query/atom.js +7 -3
- package/dist/query/atom.js.map +1 -1
- package/dist/query/compute.d.ts +68 -0
- package/dist/query/compute.d.ts.map +1 -0
- package/dist/query/compute.js +141 -0
- package/dist/query/compute.js.map +1 -0
- package/dist/query/find.d.ts +15 -8
- package/dist/query/find.d.ts.map +1 -1
- package/dist/query/find.js +6 -2
- package/dist/query/find.js.map +1 -1
- package/dist/query/lower.d.ts +23 -2
- package/dist/query/lower.d.ts.map +1 -1
- package/dist/query/lower.js +433 -80
- package/dist/query/lower.js.map +1 -1
- package/dist/query/parse-ir.d.ts.map +1 -1
- package/dist/query/parse-ir.js +17 -8
- package/dist/query/parse-ir.js.map +1 -1
- package/dist/query/run.d.ts +12 -2
- package/dist/query/run.d.ts.map +1 -1
- package/dist/query/run.js +26 -9
- package/dist/query/run.js.map +1 -1
- package/dist/query/scope.d.ts +47 -3
- package/dist/query/scope.d.ts.map +1 -1
- package/dist/query/scope.js +83 -19
- package/dist/query/scope.js.map +1 -1
- package/dist/relation.d.ts +3 -8
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +16 -10
- package/dist/relation.js.map +1 -1
- package/dist/result.d.ts +47 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +50 -0
- package/dist/result.js.map +1 -0
- package/dist/rows.d.ts +69 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +328 -0
- package/dist/rows.js.map +1 -0
- package/dist/runtime-codes.d.ts +2 -0
- package/dist/runtime-codes.d.ts.map +1 -0
- package/dist/runtime-codes.js +19 -0
- package/dist/runtime-codes.js.map +1 -0
- package/dist/runtime-errors.d.ts +106 -0
- package/dist/runtime-errors.d.ts.map +1 -0
- package/dist/runtime-errors.js +62 -0
- package/dist/runtime-errors.js.map +1 -0
- package/dist/runtime-native.d.ts +171 -0
- package/dist/runtime-native.d.ts.map +1 -0
- package/dist/runtime-native.js +5 -0
- package/dist/runtime-native.js.map +1 -0
- package/dist/runtime.d.ts +73 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +293 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scalar.d.ts +165 -0
- package/dist/scalar.d.ts.map +1 -0
- package/dist/scalar.js +344 -0
- package/dist/scalar.js.map +1 -0
- package/dist/schema.d.ts +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +34 -37
- package/dist/schema.js.map +1 -1
- package/dist/shape.d.ts +28 -0
- package/dist/shape.d.ts.map +1 -0
- package/dist/shape.js +2 -0
- package/dist/shape.js.map +1 -0
- package/dist/spec.d.ts +27 -3
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js +22 -1
- package/dist/spec.js.map +1 -1
- package/dist/statements.d.ts +16 -3
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +54 -28
- package/dist/statements.js.map +1 -1
- package/dist/uuid.d.ts +23 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +54 -0
- package/dist/uuid.js.map +1 -0
- package/pack-provenance.json +7 -0
- package/package.json +12 -16
- package/src/capacity.ts +34 -54
- package/src/changes.ts +361 -0
- package/src/close.ts +53 -0
- package/src/closed.ts +25 -19
- package/src/codec.ts +379 -0
- package/src/compile.ts +149 -0
- package/src/db-native.ts +247 -0
- package/src/db.ts +461 -1632
- package/src/errors.ts +50 -0
- package/src/face.ts +2 -2
- package/src/fields.ts +182 -55
- package/src/index.ts +62 -126
- package/src/internal/log.ts +51 -0
- package/src/law.ts +13 -28
- package/src/lower.ts +9 -4
- package/src/migration.ts +69 -0
- package/src/native.ts +326 -487
- package/src/query/atom.ts +61 -25
- package/src/query/compute.ts +237 -0
- package/src/query/find.ts +31 -12
- package/src/query/lower.ts +531 -143
- package/src/query/parse-ir.ts +18 -13
- package/src/query/run.ts +32 -16
- package/src/query/scope.ts +140 -8
- package/src/relation.ts +17 -21
- package/src/result.ts +130 -0
- package/src/rows.ts +404 -0
- package/src/runtime-codes.ts +18 -0
- package/src/runtime-errors.ts +69 -0
- package/src/runtime-native.ts +242 -0
- package/src/runtime.ts +440 -0
- package/src/scalar.ts +560 -0
- package/src/schema.ts +35 -37
- package/src/shape.ts +31 -0
- package/src/spec.ts +33 -3
- package/src/statements.ts +75 -68
- package/src/uuid.ts +69 -0
- package/dist/marshal.d.ts +0 -44
- package/dist/marshal.d.ts.map +0 -1
- package/dist/marshal.js +0 -165
- package/dist/marshal.js.map +0 -1
- package/src/marshal.ts +0 -200
package/src/db-native.ts
ADDED
|
@@ -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
|