@optimystic/db-core 1.20.1 → 1.22.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 (77) hide show
  1. package/dist/src/btree/btree.d.ts +36 -4
  2. package/dist/src/btree/btree.d.ts.map +1 -1
  3. package/dist/src/btree/btree.js +86 -18
  4. package/dist/src/btree/btree.js.map +1 -1
  5. package/dist/src/cohort-topic/gossip/bus.d.ts +15 -14
  6. package/dist/src/cohort-topic/gossip/bus.d.ts.map +1 -1
  7. package/dist/src/cohort-topic/gossip/bus.js +15 -16
  8. package/dist/src/cohort-topic/gossip/bus.js.map +1 -1
  9. package/dist/src/cohort-topic/ports.d.ts +30 -4
  10. package/dist/src/cohort-topic/ports.d.ts.map +1 -1
  11. package/dist/src/cohort-topic/ports.js +14 -0
  12. package/dist/src/cohort-topic/ports.js.map +1 -1
  13. package/dist/src/cohort-topic/registration/renewal.d.ts +27 -1
  14. package/dist/src/cohort-topic/registration/renewal.d.ts.map +1 -1
  15. package/dist/src/cohort-topic/registration/renewal.js +15 -4
  16. package/dist/src/cohort-topic/registration/renewal.js.map +1 -1
  17. package/dist/src/cohort-topic/service.d.ts +21 -4
  18. package/dist/src/cohort-topic/service.d.ts.map +1 -1
  19. package/dist/src/cohort-topic/service.js +208 -18
  20. package/dist/src/cohort-topic/service.js.map +1 -1
  21. package/dist/src/cohort-topic/willingness.d.ts +1 -1
  22. package/dist/src/cohort-topic/willingness.js +1 -1
  23. package/dist/src/cohort-topic/wire/codec.d.ts +3 -1
  24. package/dist/src/cohort-topic/wire/codec.d.ts.map +1 -1
  25. package/dist/src/cohort-topic/wire/codec.js +7 -1
  26. package/dist/src/cohort-topic/wire/codec.js.map +1 -1
  27. package/dist/src/cohort-topic/wire/index.d.ts +1 -1
  28. package/dist/src/cohort-topic/wire/index.d.ts.map +1 -1
  29. package/dist/src/cohort-topic/wire/index.js +1 -1
  30. package/dist/src/cohort-topic/wire/index.js.map +1 -1
  31. package/dist/src/cohort-topic/wire/types.d.ts +17 -1
  32. package/dist/src/cohort-topic/wire/types.d.ts.map +1 -1
  33. package/dist/src/cohort-topic/wire/validate.d.ts +15 -1
  34. package/dist/src/cohort-topic/wire/validate.d.ts.map +1 -1
  35. package/dist/src/cohort-topic/wire/validate.js +39 -0
  36. package/dist/src/cohort-topic/wire/validate.js.map +1 -1
  37. package/dist/src/collection/collection.d.ts +43 -5
  38. package/dist/src/collection/collection.d.ts.map +1 -1
  39. package/dist/src/collection/collection.js +60 -13
  40. package/dist/src/collection/collection.js.map +1 -1
  41. package/dist/src/collection/struct.d.ts +6 -0
  42. package/dist/src/collection/struct.d.ts.map +1 -1
  43. package/dist/src/collection/struct.js.map +1 -1
  44. package/dist/src/collections/tree/tree.d.ts +3 -1
  45. package/dist/src/collections/tree/tree.d.ts.map +1 -1
  46. package/dist/src/collections/tree/tree.js +11 -5
  47. package/dist/src/collections/tree/tree.js.map +1 -1
  48. package/dist/src/network/struct.d.ts +15 -0
  49. package/dist/src/network/struct.d.ts.map +1 -1
  50. package/dist/src/network/struct.js.map +1 -1
  51. package/dist/src/testing/test-transactor.js +6 -2
  52. package/dist/src/testing/test-transactor.js.map +1 -1
  53. package/dist/src/transaction/coordinator.d.ts +6 -0
  54. package/dist/src/transaction/coordinator.d.ts.map +1 -1
  55. package/dist/src/transaction/coordinator.js +6 -0
  56. package/dist/src/transaction/coordinator.js.map +1 -1
  57. package/dist/src/transactor/network-transactor.d.ts.map +1 -1
  58. package/dist/src/transactor/network-transactor.js +1 -0
  59. package/dist/src/transactor/network-transactor.js.map +1 -1
  60. package/package.json +1 -1
  61. package/src/btree/btree.ts +92 -18
  62. package/src/cohort-topic/gossip/bus.ts +25 -26
  63. package/src/cohort-topic/ports.ts +31 -4
  64. package/src/cohort-topic/registration/renewal.ts +40 -5
  65. package/src/cohort-topic/service.ts +251 -21
  66. package/src/cohort-topic/willingness.ts +1 -1
  67. package/src/cohort-topic/wire/codec.ts +12 -0
  68. package/src/cohort-topic/wire/index.ts +3 -0
  69. package/src/cohort-topic/wire/types.ts +20 -0
  70. package/src/cohort-topic/wire/validate.ts +45 -0
  71. package/src/collection/collection.ts +3098 -3039
  72. package/src/collection/struct.ts +463 -456
  73. package/src/collections/tree/tree.ts +15 -7
  74. package/src/network/struct.ts +770 -755
  75. package/src/testing/test-transactor.ts +5 -2
  76. package/src/transaction/coordinator.ts +6 -0
  77. package/src/transactor/network-transactor.ts +1897 -1896
@@ -173,13 +173,14 @@ export interface TreeReadView<TKey, TEntry> {
173
173
  get(key: TKey): Promise<TEntry | undefined>;
174
174
  at(path: Path<TKey, TEntry>): TEntry | undefined;
175
175
  range(range: KeyRange<TKey>): AsyncIterableIterator<Path<TKey, TEntry>>;
176
+ entriesIn(range: KeyRange<TKey>): Promise<TEntry[]>;
176
177
  ascending(path: Path<TKey, TEntry>): AsyncIterableIterator<Path<TKey, TEntry>>;
177
178
  isValid(path: Path<TKey, TEntry>): boolean;
178
179
  }
179
180
 
180
181
  /** Carries the read {@link BTree} from wherever it gets built (the `createHeaderBlock`
181
- * callback on the create path, {@link Tree.attach} on the open path) to the `replace`
182
- * handler, which needs the live instance to invalidate outstanding paths. */
182
+ * callback on the create path, {@link Tree.attach} on the open path) to the collection's
183
+ * `onViewChanged` callback, which needs the live instance to invalidate outstanding paths. */
183
184
  interface BTreeHolder<TKey, TEntry> {
184
185
  btree?: BTree<TKey, TEntry>;
185
186
  }
@@ -318,13 +319,16 @@ export class Tree<TKey, TEntry> implements TreeReadView<TKey, TEntry> {
318
319
  await actionTree.deleteAt(path);
319
320
  }
320
321
  }
321
- // Mutations landed in `trx`, not the read btree, so its version counter never moved.
322
- // Bump it to invalidate any Path a caller still holds — preserving the path-invalidation
323
- // the previous in-place handler gave for free.
324
- held.btree?.invalidatePaths();
325
322
  return tally.result();
326
323
  }
327
324
  },
325
+ // Mutations land in `trx` and in the collection's cache, never through the read btree, so
326
+ // its version counter would never move on its own. The collection says when what its reads
327
+ // see changes — a staged action landing, a replay, a restore, a refresh, a commit folded in
328
+ // — and the bump invalidates every Path handed out before, and tells a point read or a
329
+ // range scan's setup part-way through a descent to read again (docs/btree.md §Reads under
330
+ // a concurrent change).
331
+ onViewChanged: () => held.btree?.invalidatePaths(),
328
332
  createHeaderBlock: (hid: BlockId, store: BlockStore<IBlock>) => { // Only called if the collection does not exist
329
333
  // Tricky bootstrapping here:
330
334
  // We need the root id to initialize the collection header, so we create the btree here.
@@ -344,7 +348,7 @@ export class Tree<TKey, TEntry> implements TreeReadView<TKey, TEntry> {
344
348
  /** Bind an opened collection to its read btree. On the create path `createHeaderBlock` already
345
349
  * built one (it needed the root id for the header); on the open path it never ran, so build it
346
350
  * over the collection's existing tracker. Either way the result is written back into `held` so
347
- * the `replace` handler's path-invalidation targets the very btree reads go through. */
351
+ * the collection's path-invalidation (`onViewChanged`) targets the very btree reads go through. */
348
352
  private static attach<TKey, TEntry>(
349
353
  collection: Collection<TreeReplaceAction<TKey, TEntry>>,
350
354
  held: BTreeHolder<TKey, TEntry>,
@@ -526,6 +530,10 @@ export class Tree<TKey, TEntry> implements TreeReadView<TKey, TEntry> {
526
530
  return this.btree.range(range);
527
531
  }
528
532
 
533
+ async entriesIn(range: KeyRange<TKey>): Promise<TEntry[]> {
534
+ return await this.btree.entriesIn(range);
535
+ }
536
+
529
537
  ascending(path: Path<TKey, TEntry>): AsyncIterableIterator<Path<TKey, TEntry>> {
530
538
  return this.btree.ascending(path);
531
539
  }