@minnowdb/core 0.3.0 → 0.4.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 (276) hide show
  1. package/README.md +4 -2
  2. package/dist/block-format/block.d.ts +32 -13
  3. package/dist/block-format/block.js +179 -55
  4. package/dist/block-format/checksum.d.ts +2 -1
  5. package/dist/block-format/checksum.js +5 -2
  6. package/dist/block-format/codecs.d.ts +7 -2
  7. package/dist/block-format/codecs.js +53 -12
  8. package/dist/block-format/column.d.ts +3 -2
  9. package/dist/block-format/column.js +96 -30
  10. package/dist/block-format/index.d.ts +2 -2
  11. package/dist/block-format/index.js +2 -2
  12. package/dist/block-format/physical.d.ts +8 -2
  13. package/dist/block-format/physical.js +14 -6
  14. package/dist/block-format/types.d.ts +7 -3
  15. package/dist/block-format/types.js +0 -1
  16. package/dist/block-format/unicode.d.ts +11 -0
  17. package/dist/block-format/unicode.js +46 -0
  18. package/dist/date-value.d.ts +15 -0
  19. package/dist/date-value.js +64 -0
  20. package/dist/engine/artifact-cache.d.ts +0 -1
  21. package/dist/engine/artifact-cache.js +0 -1
  22. package/dist/engine/batch.d.ts +5 -2
  23. package/dist/engine/batch.js +0 -1
  24. package/dist/engine/buffered-writer.d.ts +2 -1
  25. package/dist/engine/buffered-writer.js +34 -9
  26. package/dist/engine/cache-limits.d.ts +25 -0
  27. package/dist/engine/cache-limits.js +25 -0
  28. package/dist/engine/catalog.d.ts +5 -6
  29. package/dist/engine/catalog.js +5 -5
  30. package/dist/engine/client.d.ts +27 -7
  31. package/dist/engine/client.js +197 -31
  32. package/dist/engine/database.d.ts +161 -38
  33. package/dist/engine/database.js +4320 -1523
  34. package/dist/engine/defaults.d.ts +0 -1
  35. package/dist/engine/defaults.js +2 -4
  36. package/dist/engine/errors.d.ts +19 -1
  37. package/dist/engine/errors.js +32 -2
  38. package/dist/engine/fts.d.ts +0 -6
  39. package/dist/engine/fts.js +39 -14
  40. package/dist/engine/group-index.d.ts +0 -1
  41. package/dist/engine/group-index.js +6 -11
  42. package/dist/engine/index.d.ts +16 -11
  43. package/dist/engine/index.js +12 -10
  44. package/dist/engine/join-index.d.ts +0 -1
  45. package/dist/engine/join-index.js +2 -2
  46. package/dist/engine/keyed-live.d.ts +57 -0
  47. package/dist/engine/keyed-live.js +226 -0
  48. package/dist/engine/live-api.d.ts +4 -0
  49. package/dist/engine/live-api.js +4 -0
  50. package/dist/engine/live.d.ts +43 -26
  51. package/dist/engine/live.js +499 -129
  52. package/dist/engine/memory.d.ts +2 -1
  53. package/dist/engine/memory.js +3 -2
  54. package/dist/engine/optimizer.d.ts +0 -1
  55. package/dist/engine/optimizer.js +4 -4
  56. package/dist/engine/query-api.d.ts +3 -0
  57. package/dist/engine/query-api.js +3 -0
  58. package/dist/engine/query-cache.d.ts +0 -1
  59. package/dist/engine/query-cache.js +4 -4
  60. package/dist/engine/query.d.ts +4 -7
  61. package/dist/engine/query.js +348 -155
  62. package/dist/engine/result-wire.d.ts +0 -1
  63. package/dist/engine/result-wire.js +2 -2
  64. package/dist/engine/schema-wire.d.ts +1 -2
  65. package/dist/engine/schema-wire.js +0 -1
  66. package/dist/engine/schema.d.ts +3 -8
  67. package/dist/engine/schema.js +41 -24
  68. package/dist/engine/sort-keys.d.ts +0 -1
  69. package/dist/engine/sort-keys.js +2 -2
  70. package/dist/engine/sql-domains.d.ts +6 -1
  71. package/dist/engine/sql-domains.js +209 -45
  72. package/dist/engine/sql-driver.d.ts +2 -2
  73. package/dist/engine/sql-driver.js +0 -1
  74. package/dist/engine/sql-json.d.ts +0 -1
  75. package/dist/engine/sql-json.js +53 -7
  76. package/dist/engine/sql-semantics.d.ts +8 -5
  77. package/dist/engine/sql-semantics.js +427 -65
  78. package/dist/engine/typed-live.d.ts +67 -0
  79. package/dist/engine/typed-live.js +349 -0
  80. package/dist/engine/vector.d.ts +7 -1
  81. package/dist/engine/vector.js +202 -58
  82. package/dist/engine/worker-host.d.ts +8 -2
  83. package/dist/engine/worker-host.js +616 -152
  84. package/dist/engine/worker.d.ts +0 -1
  85. package/dist/engine/worker.js +3 -3
  86. package/dist/engine/write-block-planner.d.ts +18 -0
  87. package/dist/engine/write-block-planner.js +112 -0
  88. package/dist/index.d.ts +0 -1
  89. package/dist/index.js +0 -1
  90. package/dist/plan/index.d.ts +0 -1
  91. package/dist/plan/index.js +0 -1
  92. package/dist/storage/index.d.ts +1 -1
  93. package/dist/storage/index.js +1 -1
  94. package/dist/storage/indexeddb.d.ts +74 -65
  95. package/dist/storage/indexeddb.js +12301 -2076
  96. package/dist/storage/memory.d.ts +56 -66
  97. package/dist/storage/memory.js +1004 -139
  98. package/dist/storage/opfs/files.d.ts +18 -7
  99. package/dist/storage/opfs/files.js +115 -28
  100. package/dist/storage/opfs/index.d.ts +1 -1
  101. package/dist/storage/opfs/index.js +1 -1
  102. package/dist/storage/opfs/leader.d.ts +403 -91
  103. package/dist/storage/opfs/leader.js +4306 -602
  104. package/dist/storage/opfs/rpc.d.ts +15 -3
  105. package/dist/storage/opfs/rpc.js +223 -2
  106. package/dist/storage/opfs/snapshot-ledger.d.ts +40 -0
  107. package/dist/storage/opfs/snapshot-ledger.js +281 -0
  108. package/dist/storage/opfs/store.d.ts +26 -121
  109. package/dist/storage/opfs/store.js +436 -388
  110. package/dist/storage/persistence.d.ts +37 -0
  111. package/dist/storage/persistence.js +78 -0
  112. package/dist/storage/snapshot-stream.d.ts +24 -0
  113. package/dist/storage/snapshot-stream.js +897 -0
  114. package/dist/storage/snapshot.d.ts +9 -99
  115. package/dist/storage/snapshot.js +33 -309
  116. package/dist/storage/toolkit/extents.d.ts +41 -7
  117. package/dist/storage/toolkit/extents.js +402 -39
  118. package/dist/storage/toolkit/index.d.ts +3 -4
  119. package/dist/storage/toolkit/index.js +27 -3
  120. package/dist/storage/toolkit/record-core.d.ts +174 -61
  121. package/dist/storage/toolkit/record-core.js +5401 -849
  122. package/dist/storage/toolkit/sync-file.d.ts +10 -1
  123. package/dist/storage/toolkit/sync-file.js +50 -2
  124. package/dist/storage/toolkit/wal.d.ts +23 -5
  125. package/dist/storage/toolkit/wal.js +89 -27
  126. package/dist/storage/toolkit/wire.d.ts +4 -6
  127. package/dist/storage/toolkit/wire.js +80 -25
  128. package/dist/storage/types.d.ts +1271 -218
  129. package/dist/storage/types.js +1471 -138
  130. package/dist/testing/block-store-conformance.d.ts +0 -1
  131. package/dist/testing/block-store-conformance.js +877 -138
  132. package/dist/testing/index.d.ts +42 -31
  133. package/dist/testing/index.js +100 -68
  134. package/dist/testing/opfs-shim.d.ts +13 -3
  135. package/dist/testing/opfs-shim.js +40 -6
  136. package/dist/testing/simulator.d.ts +0 -1
  137. package/dist/testing/simulator.js +43 -12
  138. package/dist/testing/sqllogictest.d.ts +0 -1
  139. package/dist/testing/sqllogictest.js +0 -1
  140. package/dist/transactions/index.d.ts +81 -20
  141. package/dist/transactions/index.js +1050 -268
  142. package/dist/worker-protocol/index.d.ts +3 -2
  143. package/dist/worker-protocol/index.js +2 -5
  144. package/package.json +49 -1
  145. package/dist/block-format/block.d.ts.map +0 -1
  146. package/dist/block-format/block.js.map +0 -1
  147. package/dist/block-format/checksum.d.ts.map +0 -1
  148. package/dist/block-format/checksum.js.map +0 -1
  149. package/dist/block-format/codecs.d.ts.map +0 -1
  150. package/dist/block-format/codecs.js.map +0 -1
  151. package/dist/block-format/column.d.ts.map +0 -1
  152. package/dist/block-format/column.js.map +0 -1
  153. package/dist/block-format/index.d.ts.map +0 -1
  154. package/dist/block-format/index.js.map +0 -1
  155. package/dist/block-format/physical.d.ts.map +0 -1
  156. package/dist/block-format/physical.js.map +0 -1
  157. package/dist/block-format/types.d.ts.map +0 -1
  158. package/dist/block-format/types.js.map +0 -1
  159. package/dist/engine/artifact-cache.d.ts.map +0 -1
  160. package/dist/engine/artifact-cache.js.map +0 -1
  161. package/dist/engine/batch.d.ts.map +0 -1
  162. package/dist/engine/batch.js.map +0 -1
  163. package/dist/engine/buffered-writer.d.ts.map +0 -1
  164. package/dist/engine/buffered-writer.js.map +0 -1
  165. package/dist/engine/catalog.d.ts.map +0 -1
  166. package/dist/engine/catalog.js.map +0 -1
  167. package/dist/engine/client.d.ts.map +0 -1
  168. package/dist/engine/client.js.map +0 -1
  169. package/dist/engine/coordinator.d.ts +0 -17
  170. package/dist/engine/coordinator.d.ts.map +0 -1
  171. package/dist/engine/coordinator.js +0 -60
  172. package/dist/engine/coordinator.js.map +0 -1
  173. package/dist/engine/database.d.ts.map +0 -1
  174. package/dist/engine/database.js.map +0 -1
  175. package/dist/engine/defaults.d.ts.map +0 -1
  176. package/dist/engine/defaults.js.map +0 -1
  177. package/dist/engine/errors.d.ts.map +0 -1
  178. package/dist/engine/errors.js.map +0 -1
  179. package/dist/engine/fts.d.ts.map +0 -1
  180. package/dist/engine/fts.js.map +0 -1
  181. package/dist/engine/group-index.d.ts.map +0 -1
  182. package/dist/engine/group-index.js.map +0 -1
  183. package/dist/engine/index.d.ts.map +0 -1
  184. package/dist/engine/index.js.map +0 -1
  185. package/dist/engine/join-index.d.ts.map +0 -1
  186. package/dist/engine/join-index.js.map +0 -1
  187. package/dist/engine/live.d.ts.map +0 -1
  188. package/dist/engine/live.js.map +0 -1
  189. package/dist/engine/memory.d.ts.map +0 -1
  190. package/dist/engine/memory.js.map +0 -1
  191. package/dist/engine/optimizer.d.ts.map +0 -1
  192. package/dist/engine/optimizer.js.map +0 -1
  193. package/dist/engine/query-cache.d.ts.map +0 -1
  194. package/dist/engine/query-cache.js.map +0 -1
  195. package/dist/engine/query.d.ts.map +0 -1
  196. package/dist/engine/query.js.map +0 -1
  197. package/dist/engine/result-wire.d.ts.map +0 -1
  198. package/dist/engine/result-wire.js.map +0 -1
  199. package/dist/engine/schema-wire.d.ts.map +0 -1
  200. package/dist/engine/schema-wire.js.map +0 -1
  201. package/dist/engine/schema.d.ts.map +0 -1
  202. package/dist/engine/schema.js.map +0 -1
  203. package/dist/engine/sort-keys.d.ts.map +0 -1
  204. package/dist/engine/sort-keys.js.map +0 -1
  205. package/dist/engine/sql-domains.d.ts.map +0 -1
  206. package/dist/engine/sql-domains.js.map +0 -1
  207. package/dist/engine/sql-driver.d.ts.map +0 -1
  208. package/dist/engine/sql-driver.js.map +0 -1
  209. package/dist/engine/sql-json.d.ts.map +0 -1
  210. package/dist/engine/sql-json.js.map +0 -1
  211. package/dist/engine/sql-semantics.d.ts.map +0 -1
  212. package/dist/engine/sql-semantics.js.map +0 -1
  213. package/dist/engine/vector.d.ts.map +0 -1
  214. package/dist/engine/vector.js.map +0 -1
  215. package/dist/engine/worker-host.d.ts.map +0 -1
  216. package/dist/engine/worker-host.js.map +0 -1
  217. package/dist/engine/worker.d.ts.map +0 -1
  218. package/dist/engine/worker.js.map +0 -1
  219. package/dist/index.d.ts.map +0 -1
  220. package/dist/index.js.map +0 -1
  221. package/dist/plan/index.d.ts.map +0 -1
  222. package/dist/plan/index.js.map +0 -1
  223. package/dist/storage/fixture-shape.d.ts +0 -42
  224. package/dist/storage/fixture-shape.d.ts.map +0 -1
  225. package/dist/storage/fixture-shape.js +0 -146
  226. package/dist/storage/fixture-shape.js.map +0 -1
  227. package/dist/storage/index.d.ts.map +0 -1
  228. package/dist/storage/index.js.map +0 -1
  229. package/dist/storage/indexeddb.d.ts.map +0 -1
  230. package/dist/storage/indexeddb.js.map +0 -1
  231. package/dist/storage/memory.d.ts.map +0 -1
  232. package/dist/storage/memory.js.map +0 -1
  233. package/dist/storage/opfs/files.d.ts.map +0 -1
  234. package/dist/storage/opfs/files.js.map +0 -1
  235. package/dist/storage/opfs/index.d.ts.map +0 -1
  236. package/dist/storage/opfs/index.js.map +0 -1
  237. package/dist/storage/opfs/leader.d.ts.map +0 -1
  238. package/dist/storage/opfs/leader.js.map +0 -1
  239. package/dist/storage/opfs/rpc.d.ts.map +0 -1
  240. package/dist/storage/opfs/rpc.js.map +0 -1
  241. package/dist/storage/opfs/store.d.ts.map +0 -1
  242. package/dist/storage/opfs/store.js.map +0 -1
  243. package/dist/storage/snapshot.d.ts.map +0 -1
  244. package/dist/storage/snapshot.js.map +0 -1
  245. package/dist/storage/toolkit/extents.d.ts.map +0 -1
  246. package/dist/storage/toolkit/extents.js.map +0 -1
  247. package/dist/storage/toolkit/index.d.ts.map +0 -1
  248. package/dist/storage/toolkit/index.js.map +0 -1
  249. package/dist/storage/toolkit/record-core.d.ts.map +0 -1
  250. package/dist/storage/toolkit/record-core.js.map +0 -1
  251. package/dist/storage/toolkit/sync-file.d.ts.map +0 -1
  252. package/dist/storage/toolkit/sync-file.js.map +0 -1
  253. package/dist/storage/toolkit/wal.d.ts.map +0 -1
  254. package/dist/storage/toolkit/wal.js.map +0 -1
  255. package/dist/storage/toolkit/wire.d.ts.map +0 -1
  256. package/dist/storage/toolkit/wire.js.map +0 -1
  257. package/dist/storage/types.d.ts.map +0 -1
  258. package/dist/storage/types.js.map +0 -1
  259. package/dist/testing/block-store-conformance.d.ts.map +0 -1
  260. package/dist/testing/block-store-conformance.js.map +0 -1
  261. package/dist/testing/index.d.ts.map +0 -1
  262. package/dist/testing/index.js.map +0 -1
  263. package/dist/testing/opfs-shim.d.ts.map +0 -1
  264. package/dist/testing/opfs-shim.js.map +0 -1
  265. package/dist/testing/seeds.d.ts +0 -11
  266. package/dist/testing/seeds.d.ts.map +0 -1
  267. package/dist/testing/seeds.js +0 -50
  268. package/dist/testing/seeds.js.map +0 -1
  269. package/dist/testing/simulator.d.ts.map +0 -1
  270. package/dist/testing/simulator.js.map +0 -1
  271. package/dist/testing/sqllogictest.d.ts.map +0 -1
  272. package/dist/testing/sqllogictest.js.map +0 -1
  273. package/dist/transactions/index.d.ts.map +0 -1
  274. package/dist/transactions/index.js.map +0 -1
  275. package/dist/worker-protocol/index.d.ts.map +0 -1
  276. package/dist/worker-protocol/index.js.map +0 -1
@@ -2,6 +2,17 @@ import { MinnowDatabase } from "../engine/database.js";
2
2
  import { MemoryBlockStore } from "../storage/index.js";
3
3
  import { FaultInjectingBlockStore } from "./index.js";
4
4
  import { md5Hex } from "./sqllogictest.js";
5
+ async function collectStoragePages(read) {
6
+ const records = [];
7
+ let cursor = null;
8
+ for (;;) {
9
+ const page = await read(cursor);
10
+ records.push(...page.records);
11
+ if (page.nextCursor === null)
12
+ return records;
13
+ cursor = page.nextCursor;
14
+ }
15
+ }
5
16
  /** Chooses every storage completion from a seeded queue and keeps only a bounded trace tail. */
6
17
  export class DeterministicScheduler {
7
18
  #random;
@@ -40,6 +51,15 @@ export class DeterministicScheduler {
40
51
  await Promise.resolve();
41
52
  const pending = this.#pending.length;
42
53
  if (pending === 0) {
54
+ // Production maintenance deliberately yields through a timer between bounded pages.
55
+ // A microtask-only poll can therefore declare deadlock while the next scheduled store
56
+ // call is merely waiting for its event-loop turn. Let timers advance before counting an
57
+ // empty turn; the chosen storage completion order remains seeded and deterministic.
58
+ await nextEventLoopTurn();
59
+ if (this.#pending.length > 0) {
60
+ emptyTurns = 0;
61
+ continue;
62
+ }
43
63
  emptyTurns++;
44
64
  if (emptyTurns > 100) {
45
65
  throw new Error("Deterministic simulator deadlocked with no scheduled storage operation");
@@ -72,6 +92,20 @@ export class DeterministicScheduler {
72
92
  this.#trace.shift();
73
93
  }
74
94
  }
95
+ function nextEventLoopTurn() {
96
+ if (typeof MessageChannel === "undefined") {
97
+ return new Promise((resolve) => setTimeout(resolve, 0));
98
+ }
99
+ return new Promise((resolve) => {
100
+ const channel = new MessageChannel();
101
+ channel.port1.onmessage = () => {
102
+ channel.port1.close();
103
+ channel.port2.close();
104
+ resolve();
105
+ };
106
+ channel.port2.postMessage(undefined);
107
+ });
108
+ }
75
109
  /** Wraps every asynchronous BlockStore entry point in the deterministic completion scheduler. */
76
110
  export function scheduledBlockStore(store, scheduler) {
77
111
  return new Proxy(store, {
@@ -288,20 +322,20 @@ export async function runSimulation(plan, options = {}) {
288
322
  collectionTail.splice(0, collectionTail.length - 8);
289
323
  await drive(scheduler, sweeper.close());
290
324
  const rows = sortedRows(model);
291
- const [blockIds, segments, transactions, manifests, currentManifest, leases, compactions, storageBytes,] = await Promise.all([
292
- base.listBlockIds(),
293
- base.listSegments(),
294
- base.listTransactions(),
295
- base.listManifests(),
325
+ const [segments, transactions, manifests, currentManifest, leases, compactions, storageBytes] = await Promise.all([
326
+ collectStoragePages((cursor) => base.listSegmentPage(cursor, 256)),
327
+ collectStoragePages((cursor) => base.listTransactionPage(cursor, 256)),
328
+ collectStoragePages((cursor) => base.listManifestPage(cursor, 256)),
296
329
  base.getCurrentManifest(),
297
330
  base.listLeases(),
298
331
  base.listCompactionJobs(),
299
332
  base.getLogicalStorageBytes(),
300
333
  ]);
334
+ const blockCount = currentManifest?.liveBlockCount ?? 0;
301
335
  const blockLimit = plan.keySpace * 16 + 64;
302
336
  const segmentLimit = plan.keySpace + 16;
303
337
  const transactionLimit = segmentLimit + 16;
304
- if (blockIds.length > blockLimit ||
338
+ if (blockCount > blockLimit ||
305
339
  segments.length > segmentLimit ||
306
340
  transactions.length > transactionLimit) {
307
341
  const transactionStates = transactions.reduce((counts, transaction) => {
@@ -312,12 +346,12 @@ export async function runSimulation(plan, options = {}) {
312
346
  counts[compaction.state] = (counts[compaction.state] ?? 0) + 1;
313
347
  return counts;
314
348
  }, {});
315
- throw new Error(`Storage did not compact to a bound: ${String(blockIds.length)}/${String(blockLimit)} blocks, ` +
349
+ throw new Error(`Storage did not compact to a bound: ${String(blockCount)}/${String(blockLimit)} live blocks, ` +
316
350
  `${String(segments.length)}/${String(segmentLimit)} segments, ` +
317
351
  `${String(transactions.length)}/${String(transactionLimit)} transactions; ` +
318
352
  `${JSON.stringify(transactionStates)} transaction states, ` +
319
353
  `${JSON.stringify(compactionStates)} compaction states, ` +
320
- `${String(currentManifest?.blockIds.length ?? 0)} current blocks, compaction stopped at ${compactionStop}, ` +
354
+ `${String(currentManifest?.liveBlockCount ?? 0)} current blocks, compaction stopped at ${compactionStop}, ` +
321
355
  `${String(manifests.length)} manifests (${String(manifests.filter((manifest) => manifest.prunedAt !== undefined).length)} pruned) remain after ${String(maintenanceCompactions)} compactions ` +
322
356
  `and ${String(collectionPasses)} collection passes; collection tail ${JSON.stringify(collectionTail)}`);
323
357
  }
@@ -339,7 +373,7 @@ export async function runSimulation(plan, options = {}) {
339
373
  collectionPasses,
340
374
  collectionTail,
341
375
  rows,
342
- blockCount: blockIds.length,
376
+ blockCount,
343
377
  segmentCount: segments.length,
344
378
  transactionCount: transactions.length,
345
379
  manifestCount: manifests.length,
@@ -435,8 +469,6 @@ function validateSteps(steps, clients, keySpace) {
435
469
  "afterBlockWrite",
436
470
  "beforeBlockRead",
437
471
  "afterBlockRead",
438
- "beforeManifestCommit",
439
- "afterManifestCommit",
440
472
  "beforeTransactionCommit",
441
473
  "afterTransactionCommit",
442
474
  ]);
@@ -557,4 +589,3 @@ function greatestCommonDivisor(left, right) {
557
589
  [a, b] = [b, a % b];
558
590
  return a;
559
591
  }
560
- //# sourceMappingURL=simulator.js.map
@@ -87,4 +87,3 @@ export declare function renderSqlLogicValue(value: QueryValue, type: SqlLogicTyp
87
87
  /** Small browser-safe MD5 implementation for compatibility with the original corpus hashes. */
88
88
  export declare function md5Hex(input: string): string;
89
89
  export {};
90
- //# sourceMappingURL=sqllogictest.d.ts.map
@@ -432,4 +432,3 @@ const MD5_SHIFTS = [
432
432
  10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,
433
433
  ];
434
434
  const MD5_CONSTANTS = Array.from({ length: 64 }, (_, index) => Math.floor(Math.abs(Math.sin(index + 1)) * 2 ** 32));
435
- //# sourceMappingURL=sqllogictest.js.map
@@ -1,8 +1,16 @@
1
- import { type BlockStore, type BlockWrite, type LeaseKind, type LeaseRecord, type ManifestSummary, type RowIdRange, type SegmentRecord, type TransactionRecord, type FtsChanges, type UniqueKeyChanges } from "../storage/index.js";
1
+ import { type BlockStore, type BlockWrite, type LeaseKind, type LeaseRecord, MAX_LEASE_TTL_MS, type ManifestSummary, type RowIdRange, type SegmentRecord, type TableRecord, type TransactionRecord, type FtsChanges, type UniqueKeyChanges } from "../storage/types.js";
2
2
  export interface TransactionManagerOptions {
3
3
  now?: () => Date;
4
4
  createId?: () => string;
5
+ /** Durable writer deadline; live transactions renew every third of this interval. */
6
+ transactionTtlMs?: number;
7
+ /** Test seam for deterministic collection of an abandoned transaction reference. */
8
+ createWeakRef?: (transaction: DatabaseTransaction) => {
9
+ deref(): DatabaseTransaction | undefined;
10
+ };
5
11
  }
12
+ export declare const DEFAULT_TRANSACTION_TTL_MS = 30000;
13
+ export { MAX_LEASE_TTL_MS };
6
14
  export interface RecoveryOptions {
7
15
  staleBefore: Date;
8
16
  removePendingBlocks?: boolean;
@@ -23,6 +31,14 @@ export interface OpenLeasedSnapshotOptions {
23
31
  kind?: LeaseKind;
24
32
  version?: number | null;
25
33
  }
34
+ export interface BeginDeferredOptions {
35
+ /**
36
+ * Pins the captured snapshot with a renewable durable reader lease until this transaction
37
+ * either persists its own durable owner or finishes. Enabled by default; tightly bounded
38
+ * internal statements that cannot idle may opt out to retain the one-write fast path.
39
+ */
40
+ durableSnapshot?: boolean;
41
+ }
26
42
  export declare class TransactionClosedError extends Error {
27
43
  readonly transactionId: string;
28
44
  readonly name = "TransactionClosedError";
@@ -35,23 +51,27 @@ export interface TransactionCheckpoint {
35
51
  readonly pendingSegmentIds: readonly string[];
36
52
  readonly uniqueKeyChanges: readonly UniqueKeyChanges[];
37
53
  readonly ftsChanges: readonly FtsChanges[];
38
- readonly supersededBlockIds: readonly string[];
54
+ readonly compactionJobId: string | null;
55
+ readonly compactionSourceBlockIds: readonly string[];
56
+ readonly levelZeroSegmentLimits: ReadonlyArray<{
57
+ tableId: string;
58
+ limit: number;
59
+ }>;
39
60
  readonly changedTableIds: readonly string[];
40
61
  readonly logicallyUnchanged: boolean;
41
62
  }
42
63
  export declare class Snapshot {
43
- #private;
44
64
  private readonly store;
45
65
  readonly version: number | null;
46
- constructor(store: BlockStore, version: number | null, blockIds: readonly string[]);
47
- listBlockIds(): string[];
48
- hasBlock(id: string): boolean;
66
+ constructor(store: BlockStore, version: number | null);
67
+ hasBlock(id: string): Promise<boolean>;
68
+ hasBlocks(ids: readonly string[]): Promise<boolean[]>;
49
69
  getBlock(id: string): Promise<Uint8Array | undefined>;
50
70
  }
51
71
  export declare class LeasedSnapshot extends Snapshot {
52
72
  #private;
53
73
  private readonly now;
54
- constructor(store: BlockStore, version: number | null, blockIds: readonly string[], record: LeaseRecord, now: () => Date);
74
+ constructor(store: BlockStore, version: number | null, record: LeaseRecord, now: () => Date);
55
75
  get leaseId(): string;
56
76
  get expiresAt(): Date;
57
77
  getBlock(id: string): Promise<Uint8Array | undefined>;
@@ -63,7 +83,7 @@ export declare class LeasedSnapshot extends Snapshot {
63
83
  * (`SnapshotManifestMissingError`, `LeaseConflictError`) leave this snapshot open and pass
64
84
  * through.
65
85
  */
66
- moveTo(version: number | null, ttlMs: number, knownBlockIds?: readonly string[]): Promise<LeasedSnapshot | undefined>;
86
+ moveTo(version: number | null, ttlMs: number): Promise<LeasedSnapshot | undefined>;
67
87
  release(): Promise<void>;
68
88
  /** Closes this snapshot without touching the store — for a lease the store no longer holds. */
69
89
  discard(): void;
@@ -72,15 +92,44 @@ export declare class DatabaseTransaction {
72
92
  #private;
73
93
  private readonly store;
74
94
  private readonly now;
75
- constructor(store: BlockStore, record: TransactionRecord, now: () => Date, options?: {
95
+ private readonly ttlMs;
96
+ constructor(store: BlockStore, record: TransactionRecord, now: () => Date, ttlMs: number, createWeakRef: (transaction: DatabaseTransaction) => {
97
+ deref(): DatabaseTransaction | undefined;
98
+ }, options?: {
76
99
  persisted?: boolean;
100
+ initialCatalogProbe?: {
101
+ catalogEpoch: number;
102
+ manifestVersion: number | null;
103
+ schemaEpoch: number;
104
+ };
105
+ snapshotLease?: LeasedSnapshot;
77
106
  });
78
107
  get id(): string;
79
108
  get status(): TransactionRecord["status"];
80
109
  get snapshotVersion(): number | null;
81
110
  get pendingBlockIds(): string[];
82
111
  get pendingSegmentIds(): string[];
83
- get supersededBlockIds(): string[];
112
+ /** Process-local segments retained for a bounded single-shot commit. */
113
+ get deferredSegments(): SegmentRecord[];
114
+ get pendingTableNextRowId(): bigint | undefined;
115
+ get initialCatalogProbe(): {
116
+ catalogEpoch: number;
117
+ manifestVersion: number | null;
118
+ schemaEpoch: number;
119
+ } | undefined;
120
+ /** Exact local commit contribution; undefined until this transaction commits. */
121
+ get committedCatalogContribution(): {
122
+ transaction: TransactionRecord;
123
+ segments: SegmentRecord[];
124
+ initialCatalogProbe?: {
125
+ catalogEpoch: number;
126
+ manifestVersion: number | null;
127
+ schemaEpoch: number;
128
+ };
129
+ } | undefined;
130
+ get compactionSourceBlockIds(): string[];
131
+ /** Extends durable ownership; scope owners call this while user code is legitimately waiting. */
132
+ renew(): Promise<void>;
84
133
  /**
85
134
  * Counts every registration this transaction carries: staged blocks and segments, unique-key
86
135
  * entries, full-text entries, and supersessions. A caller that fails part-way through a
@@ -91,6 +140,8 @@ export declare class DatabaseTransaction {
91
140
  get stagedWorkCount(): number;
92
141
  /** Captures all publish-relevant state; row-id/autoincrement reservations deliberately burn. */
93
142
  checkpoint(): TransactionCheckpoint;
143
+ /** Conservative retained-size estimate used to refuse savepoint clones before allocating. */
144
+ checkpointRetainedBytes(): number;
94
145
  /** Rewinds staged artifacts and every in-memory commit delta to one earlier checkpoint. */
95
146
  rollbackTo(checkpoint: TransactionCheckpoint): Promise<void>;
96
147
  snapshot(): Promise<Snapshot>;
@@ -125,6 +176,8 @@ export declare class DatabaseTransaction {
125
176
  stageSegment(record: SegmentRecord): Promise<void>;
126
177
  /** Reconciles a persisted segment whose journal update was interrupted. */
127
178
  stageExistingSegment(segmentId: string): Promise<void>;
179
+ /** Atomically adopts an exact unpublished output left by an aborted attempt of this job. */
180
+ adoptAbortedCompactionSegment(record: SegmentRecord, abortedOwner: TransactionRecord): Promise<void>;
128
181
  /**
129
182
  * Records that this commit changes a table's logical content without staging a segment for
130
183
  * it — dropping the table, for instance, whose only publish is the retirement of its blocks.
@@ -147,7 +200,14 @@ export declare class DatabaseTransaction {
147
200
  * and token totals summed — so a scope can insert into one FTS table any number of times.
148
201
  */
149
202
  setFtsChanges(changes: FtsChanges): void;
150
- supersedeBlocks(blockIds: readonly string[]): void;
203
+ /**
204
+ * Binds a physical retirement to one persisted compaction job. Stores revalidate the job,
205
+ * source segments, current manifest, and aliases atomically with publication; this in-memory
206
+ * declaration is intent, never authority to hide arbitrary blocks.
207
+ */
208
+ setCompactionIntent(compactionJobId: string, sourceBlockIds: readonly string[]): void;
209
+ /** Adds an adapter-enforced post-commit level-zero ceiling for one table. */
210
+ limitLevelZeroSegments(tableId: string, limit: number): void;
151
211
  commit(): Promise<ManifestSummary>;
152
212
  rebase(): Promise<Snapshot>;
153
213
  abort(): Promise<void>;
@@ -157,14 +217,16 @@ export declare class TransactionManager {
157
217
  private readonly store;
158
218
  constructor(store: BlockStore, options?: TransactionManagerOptions);
159
219
  begin(): Promise<DatabaseTransaction>;
220
+ /** Atomically reserves an invisible catalog table for a create-and-populate transaction. */
221
+ beginWithPendingTable(record: TableRecord, expectedCatalogEpoch: number): Promise<DatabaseTransaction>;
160
222
  /**
161
- * Begins a transaction without a storage write: the record is pinned at the current manifest
162
- * version (one read) and written only when something is staged through the two-step methods
163
- * or never, when the whole write goes through `stageArtifactsAndCommit` on a store with
164
- * the single-shot `writeTransaction`, or the transaction aborts untouched. For writes whose
165
- * artifacts need no prior reservation; `beginWithReservation` is the shape for the rest.
223
+ * Begins without a transaction record. By default a renewable reader lease durably pins the
224
+ * probed manifest until the first two-step stage hands ownership to a transaction record. The
225
+ * record and lease are both omitted only for internal, uninterrupted single-shot writes that
226
+ * opt out and publish through `writeTransaction`. For writes whose artifacts need no prior
227
+ * reservation; `beginWithReservation` is the shape for the rest.
166
228
  */
167
- beginDeferred(): Promise<DatabaseTransaction>;
229
+ beginDeferred(options?: BeginDeferredOptions): Promise<DatabaseTransaction>;
168
230
  /**
169
231
  * Begins a transaction at the current manifest version and optionally reserves row ids and
170
232
  * auto-increment values in the same step. Stores implementing the atomic `beginTransaction`
@@ -186,7 +248,7 @@ export declare class TransactionManager {
186
248
  }>;
187
249
  resume(transactionId: string): Promise<DatabaseTransaction>;
188
250
  openSnapshot(version?: number | null): Promise<Snapshot>;
189
- openLeasedSnapshot(options: OpenLeasedSnapshotOptions, knownBlockIds?: readonly string[]): Promise<LeasedSnapshot>;
251
+ openLeasedSnapshot(options: OpenLeasedSnapshotOptions): Promise<LeasedSnapshot>;
190
252
  /**
191
253
  * Re-pins an open leased snapshot to another version — one reader moving on to a newer
192
254
  * commit. With the store's atomic `moveLease` the record stays and moves in one round trip;
@@ -197,8 +259,7 @@ export declare class TransactionManager {
197
259
  */
198
260
  moveLeasedSnapshot(snapshot: LeasedSnapshot, options: OpenLeasedSnapshotOptions & {
199
261
  version: number | null;
200
- }, knownBlockIds?: readonly string[]): Promise<LeasedSnapshot>;
262
+ }): Promise<LeasedSnapshot>;
201
263
  removeExpiredLeases(at?: Date): Promise<string[]>;
202
264
  recover(options: RecoveryOptions): Promise<RecoveryReport>;
203
265
  }
204
- //# sourceMappingURL=index.d.ts.map