@minnowdb/core 0.8.0 → 0.9.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 (66) hide show
  1. package/dist/engine/artifact-cache.js +3 -2
  2. package/dist/engine/buffered-writer.js +12 -2
  3. package/dist/engine/client.d.ts +8 -2
  4. package/dist/engine/client.js +106 -22
  5. package/dist/engine/database.d.ts +5 -3
  6. package/dist/engine/database.js +2044 -1674
  7. package/dist/engine/errors.d.ts +19 -0
  8. package/dist/engine/errors.js +29 -0
  9. package/dist/engine/index.d.ts +1 -0
  10. package/dist/engine/index.js +4 -0
  11. package/dist/engine/live-accept.js +13 -0
  12. package/dist/engine/live-aggregate.js +54 -16
  13. package/dist/engine/live.d.ts +2 -0
  14. package/dist/engine/live.js +109 -108
  15. package/dist/engine/query-cache.js +17 -2
  16. package/dist/engine/query.d.ts +1 -2
  17. package/dist/engine/query.js +4 -7
  18. package/dist/engine/result-state.d.ts +7 -0
  19. package/dist/engine/result-state.js +15 -0
  20. package/dist/engine/vector.d.ts +4 -0
  21. package/dist/engine/vector.js +14 -14
  22. package/dist/engine/windows.js +15 -14
  23. package/dist/engine/worker-server.d.ts +1 -1
  24. package/dist/engine/worker-server.js +28 -15
  25. package/dist/engine/write-coordinator.js +54 -0
  26. package/dist/storage/indexeddb.js +134 -89
  27. package/dist/storage/opfs/index.d.ts +1 -1
  28. package/dist/storage/opfs/index.js +3 -1
  29. package/dist/storage/opfs/leader.js +20 -9
  30. package/dist/storage/opfs/rpc.js +3 -1
  31. package/dist/storage/opfs/store.d.ts +2 -0
  32. package/dist/storage/opfs/store.js +128 -40
  33. package/dist/storage/toolkit/record-core.js +2 -1
  34. package/dist/storage/types.d.ts +14 -0
  35. package/dist/storage/types.js +21 -0
  36. package/dist/transactions/index.d.ts +3 -0
  37. package/dist/transactions/index.js +4 -1
  38. package/dist/worker-protocol/index.d.ts +1 -1
  39. package/dist/worker-protocol/index.js +1 -1
  40. package/package.json +2 -2
  41. package/dist/date-value.d.ts +0 -20
  42. package/dist/engine/artifact-cache.d.ts +0 -29
  43. package/dist/engine/byte-estimates.d.ts +0 -11
  44. package/dist/engine/cancellation.d.ts +0 -2
  45. package/dist/engine/defaults.d.ts +0 -29
  46. package/dist/engine/group-index.d.ts +0 -33
  47. package/dist/engine/join-index.d.ts +0 -10
  48. package/dist/engine/live-aggregate.d.ts +0 -12
  49. package/dist/engine/live-equal.d.ts +0 -7
  50. package/dist/engine/point-read.d.ts +0 -59
  51. package/dist/engine/query-cache.d.ts +0 -21
  52. package/dist/engine/query-generations.d.ts +0 -8
  53. package/dist/engine/query-identity.d.ts +0 -3
  54. package/dist/engine/result-wire.d.ts +0 -70
  55. package/dist/engine/sort-keys.d.ts +0 -73
  56. package/dist/engine/sql-domains.d.ts +0 -97
  57. package/dist/engine/sql-functions.d.ts +0 -11
  58. package/dist/engine/sql-json.d.ts +0 -40
  59. package/dist/engine/sql-semantics.d.ts +0 -66
  60. package/dist/engine/worker-store-indexeddb.d.ts +0 -2
  61. package/dist/engine/worker-store-memory.d.ts +0 -2
  62. package/dist/engine/worker-store-opfs.d.ts +0 -2
  63. package/dist/engine/write-block-planner.d.ts +0 -19
  64. package/dist/storage/opfs/leader.d.ts +0 -460
  65. package/dist/storage/opfs/rpc.d.ts +0 -82
  66. package/dist/storage/opfs/snapshot-ledger.d.ts +0 -41
@@ -1,460 +0,0 @@
1
- import { type BeginTransactionInput, type BeginTransactionResult, type CloseSnapshotExportInput, type CancelSnapshotImportInput, type InterruptedSnapshotImportAbortResult, type AbortTransactionIfExpiredInput, type AdoptAbortedSegmentInput, type RenewTransactionInput, type CommitTransactionInput, type CompactionJobRecord, type CompactionJobRecordUpdate, type CreateGarbageCollectionJobInput, type UpdateGarbageCollectionPlanningInput, type DropTableColumnInput, type DropTableInput, type FtsCandidates, type FtsPostingQuery, type FtsPosting, type GarbageCollectionJobRecord, type GarbageCollectionStepResult, type LeaseRecord, type MoveLeaseInput, type ManifestSummary, type ManifestBlockPage, type ListManifestBlockPageInput, type ListRetiredManifestBlockPageInput, type RollbackTransactionArtifactsInput, type RenewLeaseInput, type RenewTempOwnerInput, type RunGarbageCollectionStepInput, type SegmentRecord, type StageTransactionArtifactsInput, type StoragePage, type StorageIntegrityMode, type StorageIntegrityReport, type StorageStats, type CatalogMutationOptions, type TableRecord, type TableRecordUpdate, type TempOwnerRecord, type TempRunPage, type TransactionRecord, type TransactionRecordUpdate, type WriteTransactionInput, type BeginUniqueKeyBuildInput, type RenewUniqueKeyBuildInput, type AppendUniqueKeyBuildChunkInput, type FinishUniqueKeyBuildInput, type AbortUniqueKeyBuildInput, type BeginPostingBuildInput, type RenewPostingBuildInput, type AppendPostingBuildChunkInput, type FinishPostingBuildInput, type AbortPostingBuildInput, type BeginSnapshotFrameExportInput, type BeginSnapshotFrameImportInput, type ReadSnapshotExportFrameInput, type RenewSnapshotFrameImportInput, type AppendSnapshotImportFramesInput, type FinishSnapshotFrameImportInput, type SnapshotFrame, type SnapshotFrameExportSession, type SnapshotFrameImportSession, type SnapshotFrameKind, type SnapshotFrameStreamHeader } from "../types.js";
2
- import { OpfsTree } from "./files.js";
3
- import { type Placement } from "../toolkit/extents.js";
4
- /** A failed checkpoint may defer compaction, but the recovery log itself stays bounded. */
5
- export declare const MAX_OPFS_WAL_BYTES: number;
6
- export declare const MAX_OPFS_CHECKPOINT_BYTES: number;
7
- interface IdPlacement {
8
- id: string;
9
- placement: Placement;
10
- }
11
- interface BlockRelocation {
12
- id: string;
13
- from: Placement;
14
- placement: Placement;
15
- }
16
- interface FtsChunkRelocation {
17
- key: string;
18
- ordinal: number;
19
- from: Placement;
20
- placement: Placement;
21
- }
22
- interface FtsBuildChunkRelocation extends FtsChunkRelocation {
23
- buildId: string;
24
- }
25
- interface FtsBasePointer {
26
- coversVersion: number;
27
- totalTokens: number;
28
- chunks: Placement[];
29
- chunkBounds: Array<{
30
- first: string;
31
- last: string;
32
- }>;
33
- }
34
- interface TempPageLedgerRecord {
35
- ownerId: string;
36
- runId: string;
37
- pageIndex: number;
38
- length: number;
39
- }
40
- interface SnapshotFrameExportState {
41
- sessionId: string;
42
- ownerId: string;
43
- createdAt: string;
44
- expiresAt: string;
45
- leaseRevision: number;
46
- manifestVersion: number;
47
- header: SnapshotFrameStreamHeader;
48
- ledgerId: string;
49
- ledgerLength: number;
50
- metadataFrameCount: number;
51
- nextSequence: number;
52
- metadataOffset: number;
53
- blockCursor: string | null;
54
- lastSequence: number | null;
55
- lastMetadataOffset: number | null;
56
- lastBlockId: string | null;
57
- }
58
- interface SnapshotFrameObservedState {
59
- frameCount: number;
60
- itemCount: number;
61
- storedBytes: number;
62
- }
63
- interface SnapshotFrameImportState {
64
- identity: string;
65
- ownerId: string;
66
- version: number;
67
- createdAt: string;
68
- expiresAt: string;
69
- header: SnapshotFrameStreamHeader;
70
- ledgerId: string;
71
- ledgerLength: number;
72
- nextSequence: number;
73
- stagedBytes: number;
74
- blockCount: number;
75
- blockBytes: number;
76
- checksum: number;
77
- currentKindIndex: number;
78
- observed: Record<SnapshotFrameKind, SnapshotFrameObservedState>;
79
- lastBatchStartSequence: number | null;
80
- lastBatchOffset: number | null;
81
- lastBatchFrameCount: number;
82
- completedReplay: boolean;
83
- }
84
- type WalEntryBody = {
85
- op: "relocatePayloads";
86
- blocks: BlockRelocation[];
87
- ftsChunks: FtsChunkRelocation[];
88
- ftsBuildChunks: FtsBuildChunkRelocation[];
89
- } | {
90
- op: "addTable";
91
- record: TableRecord;
92
- expectedCatalogEpoch: number | null;
93
- } | {
94
- op: "updateTable";
95
- id: string;
96
- expectedRevision: number;
97
- update: TableRecordUpdate;
98
- } | {
99
- op: "removeTable";
100
- id: string;
101
- expectedRevision: number;
102
- expectedCatalogEpoch: number | null;
103
- } | {
104
- op: "dropTable";
105
- input: DropTableInput;
106
- } | {
107
- op: "dropTableColumn";
108
- input: DropTableColumnInput;
109
- } | {
110
- op: "removeFtsColumn";
111
- tableId: string;
112
- columnId: string;
113
- } | {
114
- op: "removeAbortedSegment";
115
- id: string;
116
- expectedTransactionId: string;
117
- } | {
118
- op: "adoptAbortedSegment";
119
- input: AdoptAbortedSegmentInput;
120
- } | {
121
- op: "reserveRowIds";
122
- tableId: string;
123
- count: number;
124
- } | {
125
- op: "beginUniqueKeyBuild";
126
- input: BeginUniqueKeyBuildInput;
127
- } | {
128
- op: "renewUniqueKeyBuild";
129
- input: RenewUniqueKeyBuildInput;
130
- } | {
131
- op: "appendUniqueKeyBuildChunk";
132
- input: AppendUniqueKeyBuildChunkInput;
133
- } | {
134
- op: "finishUniqueKeyBuild";
135
- input: FinishUniqueKeyBuildInput;
136
- } | {
137
- op: "abortUniqueKeyBuild";
138
- input: AbortUniqueKeyBuildInput;
139
- } | {
140
- op: "reserveAutoIncrement";
141
- tableId: string;
142
- columnId: string;
143
- count: number;
144
- atLeast?: bigint;
145
- } | {
146
- op: "beginTransaction";
147
- input: BeginTransactionInput;
148
- } | {
149
- op: "createTransaction";
150
- record: TransactionRecord;
151
- } | {
152
- op: "renewTransaction";
153
- input: RenewTransactionInput;
154
- } | {
155
- op: "abortTransactionIfExpired";
156
- input: AbortTransactionIfExpiredInput;
157
- } | {
158
- op: "updateTransaction";
159
- id: string;
160
- expectedRevision: number;
161
- update: TransactionRecordUpdate;
162
- } | {
163
- op: "stageTransactionArtifacts";
164
- transactionId: string;
165
- expectedRevision: number;
166
- blocks: IdPlacement[];
167
- segments: SegmentRecord[];
168
- updatedAt: string;
169
- } | {
170
- op: "rollbackTransactionArtifacts";
171
- input: RollbackTransactionArtifactsInput;
172
- } | {
173
- op: "commitTransaction";
174
- input: CommitTransactionInput;
175
- } | {
176
- op: "writeTransaction";
177
- input: Omit<WriteTransactionInput, "blocks">;
178
- blocks: IdPlacement[];
179
- } | {
180
- op: "createLease";
181
- record: LeaseRecord;
182
- } | {
183
- op: "renewLease";
184
- input: RenewLeaseInput;
185
- } | {
186
- op: "moveLease";
187
- input: MoveLeaseInput;
188
- } | {
189
- op: "removeLeaseIfExpired";
190
- id: string;
191
- expectedRevision: number;
192
- expiresAtCutoff: string;
193
- } | {
194
- op: "removeLease";
195
- input: {
196
- id: string;
197
- ownerId: string;
198
- };
199
- } | {
200
- op: "createCompactionJob";
201
- record: CompactionJobRecord;
202
- } | {
203
- op: "updateCompactionJob";
204
- id: string;
205
- expectedRevision: number;
206
- update: CompactionJobRecordUpdate;
207
- } | {
208
- op: "cancelCompactionJob";
209
- id: string;
210
- expectedRevision: number;
211
- cancelledAt: string;
212
- } | {
213
- op: "removeCompactionJob";
214
- id: string;
215
- } | {
216
- op: "createGarbageCollectionJob";
217
- input: CreateGarbageCollectionJobInput;
218
- } | {
219
- op: "updateGarbageCollectionPlanning";
220
- input: UpdateGarbageCollectionPlanningInput;
221
- } | {
222
- op: "garbageCollectionStep";
223
- effect: {
224
- job: GarbageCollectionJobRecord;
225
- prunedManifestVersions: number[];
226
- reclaimedSegmentIds: string[];
227
- reclaimedBlockIds: string[];
228
- reclaimedTransactionIds: string[];
229
- updatedAt: string;
230
- };
231
- } | {
232
- op: "removeGarbageCollectionJob";
233
- id: string;
234
- } | {
235
- op: "removePrunedManifestRecords";
236
- maxItems: number;
237
- } | {
238
- op: "createTempOwner";
239
- record: TempOwnerRecord;
240
- } | {
241
- op: "renewTempOwner";
242
- input: RenewTempOwnerInput;
243
- } | {
244
- op: "removeTempOwnerIfExpired";
245
- ownerId: string;
246
- expiresAtCutoff: string;
247
- } | {
248
- op: "removeTempOwner";
249
- ownerId: string;
250
- } | {
251
- op: "reserveTempRunPages";
252
- pages: TempPageLedgerRecord[];
253
- } | {
254
- op: "restoreTempRunPages";
255
- pages: Array<Omit<TempPageLedgerRecord, "length"> & {
256
- length: number | null;
257
- }>;
258
- } | {
259
- op: "removeTempRun";
260
- ownerId: string;
261
- runId: string;
262
- } | {
263
- op: "writeFtsBase";
264
- tableId: string;
265
- columnId: string;
266
- pointer: FtsBasePointer;
267
- } | {
268
- op: "beginFtsBaseBuild";
269
- input: BeginPostingBuildInput;
270
- } | {
271
- op: "renewFtsBaseBuild";
272
- input: RenewPostingBuildInput;
273
- } | {
274
- op: "writeFtsBaseBuildChunk";
275
- input: Omit<AppendPostingBuildChunkInput, "chunk">;
276
- placement: Placement;
277
- bounds: {
278
- first: string;
279
- last: string;
280
- };
281
- totalTokens: number;
282
- retainedEntries: number;
283
- } | {
284
- op: "finishFtsBaseBuild";
285
- input: FinishPostingBuildInput;
286
- } | {
287
- op: "abortFtsBaseBuild";
288
- input: AbortPostingBuildInput;
289
- } | {
290
- op: "beginSnapshotFrameExport";
291
- state: SnapshotFrameExportState;
292
- } | {
293
- op: "advanceSnapshotFrameExport";
294
- input: ReadSnapshotExportFrameInput;
295
- expectedLeaseRevision: number;
296
- next: Pick<SnapshotFrameExportState, "nextSequence" | "metadataOffset" | "blockCursor" | "lastSequence" | "lastMetadataOffset" | "lastBlockId">;
297
- } | {
298
- op: "closeSnapshotFrameExport";
299
- input: CloseSnapshotExportInput;
300
- } | {
301
- op: "beginSnapshotFrameImport";
302
- state: SnapshotFrameImportState;
303
- } | {
304
- op: "renewSnapshotFrameImport";
305
- input: RenewSnapshotFrameImportInput;
306
- } | {
307
- op: "appendSnapshotImportFrames";
308
- input: RenewSnapshotFrameImportInput;
309
- state: Omit<SnapshotFrameImportState, "header">;
310
- blockPlacements: IdPlacement[];
311
- replay: boolean;
312
- } | {
313
- op: "finishSnapshotFrameImport";
314
- input: FinishSnapshotFrameImportInput;
315
- } | {
316
- op: "cancelSnapshotFrameImport";
317
- input: CancelSnapshotImportInput;
318
- };
319
- declare const CORE_READ_METHODS: readonly ["getTempOwner", "getTable", "getTableByName", "listTables", "getSegment", "listSegmentPage", "listTableSegmentPage", "getExistingUniqueKeys", "getUniqueKeyBuild", "getCurrentManifestVersion", "getCatalogProbe", "getCurrentManifest", "getManifest", "listManifestPage", "listManifestBlockPage", "listRetiredManifestBlockPage", "getTransaction", "getTransactions", "listTransactionPage", "getLease", "listLeases", "listExpiredLeasePage", "getCompactionJob", "listCompactionJobs", "listCompactionJobPage", "getGarbageCollectionJob", "listGarbageCollectionJobs", "listGarbageCollectionJobPage"];
320
- type CoreReadMethod = (typeof CORE_READ_METHODS)[number];
321
- declare const LOGGED_BODY_BUILDERS: {
322
- readonly createTempOwner: ([record]: unknown[]) => WalEntryBody;
323
- readonly renewTempOwner: ([input]: unknown[]) => WalEntryBody;
324
- readonly removeAbortedSegment: ([id, expectedTransactionId]: unknown[]) => WalEntryBody;
325
- readonly adoptAbortedSegment: ([input]: unknown[]) => WalEntryBody;
326
- readonly reserveRowIds: ([tableId, count]: unknown[]) => WalEntryBody;
327
- readonly beginUniqueKeyBuild: ([input]: unknown[]) => WalEntryBody;
328
- readonly renewUniqueKeyBuild: ([input]: unknown[]) => WalEntryBody;
329
- readonly appendUniqueKeyBuildChunk: ([input]: unknown[]) => WalEntryBody;
330
- readonly finishUniqueKeyBuild: ([input]: unknown[]) => WalEntryBody;
331
- readonly abortUniqueKeyBuild: ([input]: unknown[]) => WalEntryBody;
332
- readonly reserveAutoIncrement: ([tableId, columnId, count, atLeast]: unknown[]) => WalEntryBody;
333
- readonly createTransaction: ([record]: unknown[]) => WalEntryBody;
334
- readonly renewTransaction: ([input]: unknown[]) => WalEntryBody;
335
- readonly abortTransactionIfExpired: ([input]: unknown[]) => WalEntryBody;
336
- readonly updateTransaction: ([id, expectedRevision, update]: unknown[]) => WalEntryBody;
337
- readonly commitTransaction: ([input]: unknown[]) => WalEntryBody;
338
- readonly createLease: ([record]: unknown[]) => WalEntryBody;
339
- readonly renewLease: ([input]: unknown[]) => WalEntryBody;
340
- readonly moveLease: ([input]: unknown[]) => WalEntryBody;
341
- readonly removeLeaseIfExpired: ([id, expectedRevision, expiresAtCutoff]: unknown[]) => WalEntryBody;
342
- readonly removeLease: ([input]: unknown[]) => WalEntryBody;
343
- readonly createCompactionJob: ([record]: unknown[]) => WalEntryBody;
344
- readonly updateCompactionJob: ([id, expectedRevision, update]: unknown[]) => WalEntryBody;
345
- readonly cancelCompactionJob: ([id, expectedRevision, cancelledAt]: unknown[]) => WalEntryBody;
346
- readonly createGarbageCollectionJob: ([input]: unknown[]) => WalEntryBody;
347
- readonly updateGarbageCollectionPlanning: ([input]: unknown[]) => WalEntryBody;
348
- readonly removeGarbageCollectionJob: ([id]: unknown[]) => WalEntryBody;
349
- readonly removePrunedManifestRecords: ([maxItems]: unknown[]) => WalEntryBody;
350
- };
351
- type LoggedMethod = keyof typeof LOGGED_BODY_BUILDERS;
352
- /**
353
- * The leader: the one instance holding the database's write-ahead log handle, and with it
354
- * every other handle — checkpoint slots, the tail extent, a small cache of sealed extents.
355
- *
356
- * Because the handles are held, every operation's storage cost is a synchronous write or read
357
- * measured in microseconds, and because leadership is exclusive by the browser's own file
358
- * lock, the leader's in-memory `RecordCore` is always provably current — there are no
359
- * freshness probes anywhere. An operation is: validate and mutate the core (synchronously),
360
- * append one checksummed WAL frame (synchronously), acknowledge. The only awaits sit before
361
- * that critical section (extent appends that may seal, temp-file IO), so no observer ever
362
- * sees state mid-mutation.
363
- *
364
- * Checkpointing is also synchronous — dump, write to the older of two fixed slots, flush,
365
- * reset the WAL — which is what makes a single WAL file safe: the flush precedes the reset,
366
- * and a crash mid-checkpoint corrupts only the slot being written while the other slot plus
367
- * the un-reset WAL still reconstruct everything.
368
- */
369
- export declare class OpfsLeader {
370
- #private;
371
- private constructor();
372
- /** Builds a leader from held handles: newest valid checkpoint slot plus the WAL tail. */
373
- static recover(tree: OpfsTree, strict: boolean, handles: {
374
- wal: FileSystemSyncAccessHandle;
375
- slotA: FileSystemSyncAccessHandle;
376
- slotB: FileSystemSyncAccessHandle;
377
- }, checkpointEntries?: number, cleanupLimitBytes?: number): Promise<OpfsLeader>;
378
- /**
379
- * Fully synchronous: publish the same generation to both slots, flush each, then reset.
380
- * Therefore corruption of either post-success copy cannot expose an older database.
381
- */
382
- checkpointNow(): void;
383
- getBlock(id: string): Promise<Uint8Array | undefined>;
384
- getBlocks(ids: readonly string[]): Promise<Array<Uint8Array | undefined>>;
385
- readManifestBlock(version: number | null, id: string): Promise<Uint8Array | undefined>;
386
- hasManifestBlocks(version: number | null, ids: readonly string[]): Promise<boolean[]>;
387
- listManifestBlockPage(input: ListManifestBlockPageInput): Promise<ManifestBlockPage>;
388
- listRetiredManifestBlockPage(input: ListRetiredManifestBlockPageInput): Promise<ManifestBlockPage>;
389
- putTempRunPage(page: TempRunPage): Promise<void>;
390
- putTempRunPages(pages: readonly TempRunPage[]): Promise<void>;
391
- getTempRunPage(ownerId: string, runId: string, pageIndex: number): Promise<Uint8Array | undefined>;
392
- removeTempRun(ownerId: string, runId: string): Promise<void>;
393
- removeTempOwner(ownerId: string): Promise<void>;
394
- removeCompactionJob(id: string): Promise<boolean>;
395
- /** @internal Shared implementation installed for direct RecordCore reads below. */
396
- _readCoreGenerated(method: CoreReadMethod, args: unknown[]): Promise<unknown>;
397
- /** @internal Shared implementation installed for ordinary one-frame mutations below. */
398
- _loggedGenerated(method: LoggedMethod, args: unknown[]): Promise<unknown>;
399
- removeTempOwnerIfExpired(ownerId: string, expiresAtCutoff: string): Promise<boolean>;
400
- listTempOwnerIdsPage(afterOwnerId: string | null, limit: number): Promise<StoragePage<string, string>>;
401
- listExpiredTempOwnerPage(expiresAtCutoff: string, afterCursor: string | null, limit: number): Promise<StoragePage<string, string>>;
402
- addTable(record: TableRecord, options?: CatalogMutationOptions): Promise<void>;
403
- updateTable(id: string, expectedRevision: number, update: TableRecordUpdate): Promise<TableRecord>;
404
- removeTable(id: string, expectedRevision: number, options?: CatalogMutationOptions): Promise<void>;
405
- dropTable(input: DropTableInput): Promise<ManifestSummary>;
406
- dropTableColumn(input: DropTableColumnInput): Promise<ManifestSummary>;
407
- removeFtsColumn(tableId: string, columnId: string): Promise<void>;
408
- beginTransaction(input: BeginTransactionInput): Promise<BeginTransactionResult>;
409
- stageTransactionArtifacts(input: StageTransactionArtifactsInput): Promise<TransactionRecord>;
410
- rollbackTransactionArtifacts(input: RollbackTransactionArtifactsInput): Promise<TransactionRecord>;
411
- writeTransaction(input: WriteTransactionInput): Promise<ManifestSummary>;
412
- runGarbageCollectionStep(input: RunGarbageCollectionStepInput): Promise<GarbageCollectionStepResult>;
413
- writeFtsBase(tableId: string, columnId: string, input: {
414
- coversVersion: number;
415
- chunks: FtsPosting[][];
416
- totalTokens: number;
417
- }): Promise<void>;
418
- beginFtsBaseBuild(input: BeginPostingBuildInput): Promise<void>;
419
- renewFtsBaseBuild(input: RenewPostingBuildInput): Promise<void>;
420
- writeFtsBaseBuildChunk(input: AppendPostingBuildChunkInput): Promise<void>;
421
- finishFtsBaseBuild(input: FinishPostingBuildInput): Promise<void>;
422
- abortFtsBaseBuild(input: AbortPostingBuildInput): Promise<void>;
423
- readFtsCandidates(tableId: string, columnId: string, terms: readonly FtsPostingQuery[], upToVersion: number, maxRowIds?: number): Promise<FtsCandidates & {
424
- deltaChunkCount: number;
425
- totalTokens: number;
426
- coversVersion: number;
427
- hasBase: boolean;
428
- }>;
429
- readFtsPostings(tableId: string, columnId: string, upToVersion: number, maxRowIds?: number, maxRetainedBytes?: number): Promise<{
430
- deltaChunkCount: number;
431
- coversVersion: number;
432
- hasBase: boolean;
433
- postings: FtsPosting[];
434
- overflow: boolean;
435
- }>;
436
- beginSnapshotFrameExport(input: BeginSnapshotFrameExportInput): Promise<SnapshotFrameExportSession>;
437
- readSnapshotExportFrame(input: ReadSnapshotExportFrameInput): Promise<SnapshotFrame | undefined>;
438
- closeSnapshotFrameExport(input: CloseSnapshotExportInput): Promise<boolean>;
439
- beginSnapshotFrameImport(input: BeginSnapshotFrameImportInput): Promise<SnapshotFrameImportSession>;
440
- renewSnapshotFrameImport(input: RenewSnapshotFrameImportInput): Promise<SnapshotFrameImportSession>;
441
- appendSnapshotImportFrames(input: AppendSnapshotImportFramesInput): Promise<SnapshotFrameImportSession>;
442
- finishSnapshotFrameImport(input: FinishSnapshotFrameImportInput): Promise<void>;
443
- cancelSnapshotFrameImport(input: CancelSnapshotImportInput): Promise<InterruptedSnapshotImportAbortResult>;
444
- /** Live payload bytes plus the control files — what this database logically occupies. */
445
- getLogicalStorageBytes(): Promise<number>;
446
- getStorageStats(): Promise<StorageStats>;
447
- checkIntegrity(options?: {
448
- mode?: StorageIntegrityMode;
449
- maxIssues?: number;
450
- }): Promise<StorageIntegrityReport>;
451
- /** Graceful: flush, checkpoint (so the next leader's takeover is instant), release. */
452
- shutdown(): Promise<void>;
453
- /** Test-only: what tab death does — locks release, nothing is flushed or checkpointed. */
454
- crash(): void;
455
- }
456
- /** @internal Exact pre-read aggregate limit, exported only for the no-allocation regression. */
457
- export declare function assertBlockReadBatchByteLimit(placements: ReadonlyArray<{
458
- length: number;
459
- } | undefined>): void;
460
- export {};
@@ -1,82 +0,0 @@
1
- /**
2
- * The follower↔leader message vocabulary. Leadership traffic (`leader`, `ping`, `bid`, `yield`,
3
- * `released`) travels a `BroadcastChannel` named for the database, which every connection
4
- * hears. Request traffic is addressed: an `op` is posted into the leader's own channel (named
5
- * for the database plus the leader's instance id) and its `result` or `busy` into the
6
- * requester's, so block bytes are cloned once, into the tab that asked, rather than into every
7
- * tab. Correctness never rides on delivery: an operation is acknowledged only after the
8
- * leader's write-ahead log holds it. Reads retry after failover; mutations surface an uncertain
9
- * outcome instead of being executed twice. Leadership is arbitrated by the storage lock, not
10
- * by these messages.
11
- */
12
- export type StoreRpcMessage =
13
- /**
14
- * A follower's operation request. `requestId` doubles as the retry-dedupe key; `from` is the
15
- * requester's instance id, naming the channel its answer goes to.
16
- */
17
- {
18
- kind: "op";
19
- requestId: string;
20
- from: string;
21
- method: string;
22
- args: unknown[];
23
- } | {
24
- kind: "result";
25
- requestId: string;
26
- ok: true;
27
- value: unknown;
28
- } | {
29
- kind: "result";
30
- requestId: string;
31
- ok: false;
32
- error: SerializedStoreError;
33
- }
34
- /** The leader is still executing this request — reset the caller's patience. */
35
- | {
36
- kind: "busy";
37
- requestId: string;
38
- }
39
- /** The leader exists (sent on takeover and in answer to pings). */
40
- | {
41
- kind: "leader";
42
- leaderId: string;
43
- } | {
44
- kind: "ping";
45
- }
46
- /** A foreground follower asks the (background) leader to hand over. */
47
- | {
48
- kind: "bid";
49
- bidderId: string;
50
- foreground: boolean;
51
- }
52
- /** The leader has drained and released its handles for this bidder. */
53
- | {
54
- kind: "yield";
55
- to: string;
56
- }
57
- /** The leader closed or demoted; followers may race for the lock. */
58
- | {
59
- kind: "released";
60
- leaderId: string;
61
- };
62
- export interface SerializedStoreError {
63
- name: string;
64
- message: string;
65
- /** True for platform exceptions (quota!), whose `instanceof DOMException` must survive. */
66
- domException?: boolean;
67
- props?: Record<string, unknown>;
68
- }
69
- /** One legal maximum payload plus bounded envelope/catalog metadata. */
70
- export declare const MAX_OPFS_RPC_MESSAGE_BYTES: number;
71
- export declare const MAX_OPFS_RPC_IDENTIFIER_CHARACTERS = 1024;
72
- /** Conservative retained/transfer-byte estimate with total depth/cardinality refusal. */
73
- export declare function estimateRpcValueBytes(value: unknown): number;
74
- /** Total non-throwing parser for same-origin-but-untrusted BroadcastChannel traffic. */
75
- export declare function parseStoreRpcMessage(value: unknown, knownMethods: ReadonlySet<string>): StoreRpcMessage | undefined;
76
- /** Collision-resistant bounded identity; large byte leaves become SHA-256 descriptors. */
77
- export declare function fingerprintStoreRequest(method: string, args: unknown[]): Promise<{
78
- signature: string;
79
- retainedBytes: number;
80
- }>;
81
- export declare function serializeStoreError(error: unknown): SerializedStoreError;
82
- export declare function rehydrateStoreError(serialized: SerializedStoreError): Error;
@@ -1,41 +0,0 @@
1
- import { type SnapshotFrame, type SnapshotFrameKind } from "../types.js";
2
- import { type Placement } from "../toolkit/extents.js";
3
- import { OpfsTree } from "./files.js";
4
- type SnapshotLedgerKind = "export" | "import" | "completed";
5
- interface SnapshotLedgerRecord {
6
- readonly sequence: number;
7
- readonly kind: SnapshotFrameKind;
8
- readonly itemCount: number;
9
- readonly key: string | null;
10
- readonly payloadLength: number;
11
- readonly checksum: number;
12
- /** Metadata payloads are inline. Block payloads live once in an extent placement. */
13
- readonly payload?: Uint8Array;
14
- readonly placement?: Placement;
15
- }
16
- export interface SnapshotLedgerRead {
17
- readonly record: SnapshotLedgerRecord;
18
- readonly offset: number;
19
- readonly nextOffset: number;
20
- }
21
- export declare function snapshotLedgerPath(kind: SnapshotLedgerKind, id: string): string[];
22
- /**
23
- * Checksummed append-only control file for one snapshot session. A checkpoint stores only the
24
- * committed prefix length. Bytes beyond it are unpublished and truncated on recovery, so a
25
- * large import/export never creates a database-sized WAL/checkpoint collection.
26
- */
27
- export declare class SnapshotFrameLedger {
28
- #private;
29
- private constructor();
30
- static open(tree: OpfsTree, kind: SnapshotLedgerKind, id: string, committedLength: number, create: boolean): Promise<SnapshotFrameLedger>;
31
- get byteLength(): number;
32
- append(frame: SnapshotFrame, placement?: Placement): SnapshotLedgerRead;
33
- read(offset: number, committedLength?: number): SnapshotLedgerRead;
34
- records(committedLength?: number): IterableIterator<SnapshotLedgerRead>;
35
- flush(): void;
36
- truncate(length: number): void;
37
- /** Recovery adopts the next WAL-published prefix without copying or re-appending its bytes. */
38
- adoptLength(length: number): void;
39
- close(): void;
40
- }
41
- export {};