@mmstack/primitives 21.11.0 → 21.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.
@@ -5395,6 +5395,13 @@ function createConvergingApply(opt) {
5395
5395
  // below the captured seq. Side-mapped so the public sibling/checkpoint shapes stay unchanged.
5396
5396
  let ingestSeq = 0;
5397
5397
  const seqs = new Map();
5398
+ // per-origin highest HLC applied: the observation vector (survives reset — knowledge, not state)
5399
+ const applied = new Map();
5400
+ const observeApplied = (origin, hlc) => {
5401
+ const cur = applied.get(origin);
5402
+ if (!cur || compareHlc(hlc, cur) > 0)
5403
+ applied.set(origin, hlc);
5404
+ };
5398
5405
  const setSeq = (key, origin, seq) => {
5399
5406
  let sm = seqs.get(key);
5400
5407
  if (!sm)
@@ -5649,6 +5656,7 @@ function createConvergingApply(opt) {
5649
5656
  ingest: (env, o) => {
5650
5657
  const touched = new Map();
5651
5658
  const seq = ++ingestSeq;
5659
+ observeApplied(env.origin, env.hlc);
5652
5660
  for (const op of env.ops) {
5653
5661
  if (o?.frontier && compareHlc(env.hlc, o.frontier) <= 0)
5654
5662
  continue;
@@ -5736,10 +5744,22 @@ function createConvergingApply(opt) {
5736
5744
  return out;
5737
5745
  },
5738
5746
  captureFrontier: () => ({ seq: ingestSeq }),
5747
+ appliedFrontier: () => Object.fromEntries(applied),
5739
5748
  liveAt: (path) => {
5740
5749
  const reg = registers.get(keyOf$1(path));
5741
5750
  return reg ? liveOf(reg) : [];
5742
5751
  },
5752
+ liveUnder: (path) => {
5753
+ const key = keyOf$1(path);
5754
+ const out = [];
5755
+ const at = registers.get(key);
5756
+ for (const reg of at ? [at, ...descendantsOf(key)] : descendantsOf(key)) {
5757
+ const siblings = liveOf(reg);
5758
+ if (siblings.length)
5759
+ out.push({ path: reg.path, siblings });
5760
+ }
5761
+ return out;
5762
+ },
5743
5763
  materialize: () => {
5744
5764
  const root = registers.get('');
5745
5765
  const res = root?.result;
@@ -5773,6 +5793,7 @@ function createConvergingApply(opt) {
5773
5793
  const reg = regAt(r.path);
5774
5794
  const key = keyOf$1(r.path);
5775
5795
  for (const s of r.siblings) {
5796
+ observeApplied(s.origin, s.hlc);
5776
5797
  const cur = reg.siblings.get(s.origin);
5777
5798
  if (!cur || compareHlc(s.hlc, cur.hlc) > 0) {
5778
5799
  reg.siblings.set(s.origin, s);
@@ -5780,6 +5801,7 @@ function createConvergingApply(opt) {
5780
5801
  }
5781
5802
  }
5782
5803
  for (const [o, h] of Object.entries(r.water)) {
5804
+ observeApplied(o, h); // a cited write was applied by the room this state came from
5783
5805
  const cur = reg.water.get(o);
5784
5806
  if (!cur || compareHlc(h, cur) > 0)
5785
5807
  reg.water.set(o, h);
@@ -6051,6 +6073,9 @@ function opSync(source, opt) {
6051
6073
  log.flush(); // fold pending base writes in first, so they count as observed
6052
6074
  return conv.captureFrontier();
6053
6075
  },
6076
+ liveUnder: (path) => conv.liveUnder(path),
6077
+ liveAt: (path) => conv.liveAt(path),
6078
+ appliedFrontier: () => conv.appliedFrontier(),
6054
6079
  commitScope: (frontier, fn) => {
6055
6080
  log.flush(); // earlier pending writes emit against the live frontier, not this one
6056
6081
  scopeFrontier = frontier;