@mmstack/primitives 20.16.0 → 20.17.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.
@@ -5619,6 +5619,13 @@ function createConvergingApply(opt) {
5619
5619
  // below the captured seq. Side-mapped so the public sibling/checkpoint shapes stay unchanged.
5620
5620
  let ingestSeq = 0;
5621
5621
  const seqs = new Map();
5622
+ // per-origin highest HLC applied: the observation vector (survives reset — knowledge, not state)
5623
+ const applied = new Map();
5624
+ const observeApplied = (origin, hlc) => {
5625
+ const cur = applied.get(origin);
5626
+ if (!cur || compareHlc(hlc, cur) > 0)
5627
+ applied.set(origin, hlc);
5628
+ };
5622
5629
  const setSeq = (key, origin, seq) => {
5623
5630
  let sm = seqs.get(key);
5624
5631
  if (!sm)
@@ -5873,6 +5880,7 @@ function createConvergingApply(opt) {
5873
5880
  ingest: (env, o) => {
5874
5881
  const touched = new Map();
5875
5882
  const seq = ++ingestSeq;
5883
+ observeApplied(env.origin, env.hlc);
5876
5884
  for (const op of env.ops) {
5877
5885
  if (o?.frontier && compareHlc(env.hlc, o.frontier) <= 0)
5878
5886
  continue;
@@ -5960,10 +5968,22 @@ function createConvergingApply(opt) {
5960
5968
  return out;
5961
5969
  },
5962
5970
  captureFrontier: () => ({ seq: ingestSeq }),
5971
+ appliedFrontier: () => Object.fromEntries(applied),
5963
5972
  liveAt: (path) => {
5964
5973
  const reg = registers.get(keyOf$1(path));
5965
5974
  return reg ? liveOf(reg) : [];
5966
5975
  },
5976
+ liveUnder: (path) => {
5977
+ const key = keyOf$1(path);
5978
+ const out = [];
5979
+ const at = registers.get(key);
5980
+ for (const reg of at ? [at, ...descendantsOf(key)] : descendantsOf(key)) {
5981
+ const siblings = liveOf(reg);
5982
+ if (siblings.length)
5983
+ out.push({ path: reg.path, siblings });
5984
+ }
5985
+ return out;
5986
+ },
5967
5987
  materialize: () => {
5968
5988
  const root = registers.get('');
5969
5989
  const res = root?.result;
@@ -5997,6 +6017,7 @@ function createConvergingApply(opt) {
5997
6017
  const reg = regAt(r.path);
5998
6018
  const key = keyOf$1(r.path);
5999
6019
  for (const s of r.siblings) {
6020
+ observeApplied(s.origin, s.hlc);
6000
6021
  const cur = reg.siblings.get(s.origin);
6001
6022
  if (!cur || compareHlc(s.hlc, cur.hlc) > 0) {
6002
6023
  reg.siblings.set(s.origin, s);
@@ -6004,6 +6025,7 @@ function createConvergingApply(opt) {
6004
6025
  }
6005
6026
  }
6006
6027
  for (const [o, h] of Object.entries(r.water)) {
6028
+ observeApplied(o, h); // a cited write was applied by the room this state came from
6007
6029
  const cur = reg.water.get(o);
6008
6030
  if (!cur || compareHlc(h, cur) > 0)
6009
6031
  reg.water.set(o, h);
@@ -6275,6 +6297,9 @@ function opSync(source, opt) {
6275
6297
  log.flush(); // fold pending base writes in first, so they count as observed
6276
6298
  return conv.captureFrontier();
6277
6299
  },
6300
+ liveUnder: (path) => conv.liveUnder(path),
6301
+ liveAt: (path) => conv.liveAt(path),
6302
+ appliedFrontier: () => conv.appliedFrontier(),
6278
6303
  commitScope: (frontier, fn) => {
6279
6304
  log.flush(); // earlier pending writes emit against the live frontier, not this one
6280
6305
  scopeFrontier = frontier;