@mmstack/primitives 22.11.0 → 22.12.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.
@@ -5435,6 +5435,13 @@ function createConvergingApply(opt) {
5435
5435
  // below the captured seq. Side-mapped so the public sibling/checkpoint shapes stay unchanged.
5436
5436
  let ingestSeq = 0;
5437
5437
  const seqs = new Map();
5438
+ // per-origin highest HLC applied: the observation vector (survives reset — knowledge, not state)
5439
+ const applied = new Map();
5440
+ const observeApplied = (origin, hlc) => {
5441
+ const cur = applied.get(origin);
5442
+ if (!cur || compareHlc(hlc, cur) > 0)
5443
+ applied.set(origin, hlc);
5444
+ };
5438
5445
  const setSeq = (key, origin, seq) => {
5439
5446
  let sm = seqs.get(key);
5440
5447
  if (!sm)
@@ -5689,6 +5696,7 @@ function createConvergingApply(opt) {
5689
5696
  ingest: (env, o) => {
5690
5697
  const touched = new Map();
5691
5698
  const seq = ++ingestSeq;
5699
+ observeApplied(env.origin, env.hlc);
5692
5700
  for (const op of env.ops) {
5693
5701
  if (o?.frontier && compareHlc(env.hlc, o.frontier) <= 0)
5694
5702
  continue;
@@ -5776,10 +5784,22 @@ function createConvergingApply(opt) {
5776
5784
  return out;
5777
5785
  },
5778
5786
  captureFrontier: () => ({ seq: ingestSeq }),
5787
+ appliedFrontier: () => Object.fromEntries(applied),
5779
5788
  liveAt: (path) => {
5780
5789
  const reg = registers.get(keyOf$1(path));
5781
5790
  return reg ? liveOf(reg) : [];
5782
5791
  },
5792
+ liveUnder: (path) => {
5793
+ const key = keyOf$1(path);
5794
+ const out = [];
5795
+ const at = registers.get(key);
5796
+ for (const reg of at ? [at, ...descendantsOf(key)] : descendantsOf(key)) {
5797
+ const siblings = liveOf(reg);
5798
+ if (siblings.length)
5799
+ out.push({ path: reg.path, siblings });
5800
+ }
5801
+ return out;
5802
+ },
5783
5803
  materialize: () => {
5784
5804
  const root = registers.get('');
5785
5805
  const res = root?.result;
@@ -5813,6 +5833,7 @@ function createConvergingApply(opt) {
5813
5833
  const reg = regAt(r.path);
5814
5834
  const key = keyOf$1(r.path);
5815
5835
  for (const s of r.siblings) {
5836
+ observeApplied(s.origin, s.hlc);
5816
5837
  const cur = reg.siblings.get(s.origin);
5817
5838
  if (!cur || compareHlc(s.hlc, cur.hlc) > 0) {
5818
5839
  reg.siblings.set(s.origin, s);
@@ -5820,6 +5841,7 @@ function createConvergingApply(opt) {
5820
5841
  }
5821
5842
  }
5822
5843
  for (const [o, h] of Object.entries(r.water)) {
5844
+ observeApplied(o, h); // a cited write was applied by the room this state came from
5823
5845
  const cur = reg.water.get(o);
5824
5846
  if (!cur || compareHlc(h, cur) > 0)
5825
5847
  reg.water.set(o, h);
@@ -6092,6 +6114,9 @@ function opSync(source, opt) {
6092
6114
  log.flush(); // fold pending base writes in first, so they count as observed
6093
6115
  return conv.captureFrontier();
6094
6116
  },
6117
+ liveUnder: (path) => conv.liveUnder(path),
6118
+ liveAt: (path) => conv.liveAt(path),
6119
+ appliedFrontier: () => conv.appliedFrontier(),
6095
6120
  commitScope: (frontier, fn) => {
6096
6121
  log.flush(); // earlier pending writes emit against the live frontier, not this one
6097
6122
  scopeFrontier = frontier;