@mmstack/mesh 21.15.0 → 21.15.1
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { isDevMode, signal, inject, Injector, computed, runInInjectionContext, DestroyRef, untracked, effect } from '@angular/core';
|
|
1
2
|
import { createWatch } from '@angular/core/primitives/signals';
|
|
2
3
|
import { createConvergingApply, createStoreContext, store, opSync, forkStore, isStoreReservedKey, OP_PROTO_VERSION, registerResource, throttled } from '@mmstack/primitives/core';
|
|
3
|
-
import { isDevMode, inject, Injector, signal, computed, runInInjectionContext, DestroyRef, untracked, effect } from '@angular/core';
|
|
4
4
|
import { createRanges, recordAdmission, admits, createRegisterStore, MESH_PROTO_VERSION, MESH_DIRECT_VERSION, checkEnvelope } from '@mmstack/mesh-protocol';
|
|
5
5
|
|
|
6
6
|
const emptyAdmission = () => ({
|
|
@@ -380,6 +380,7 @@ function meshSession(opt) {
|
|
|
380
380
|
cover = createRegisterStore();
|
|
381
381
|
maxSeq = 0;
|
|
382
382
|
owed = undefined; // its threshold belongs to the dead room's sequence
|
|
383
|
+
hooks.onGeneration?.(undefined);
|
|
383
384
|
};
|
|
384
385
|
/**
|
|
385
386
|
* Install a snapshot welcome ATOMICALLY: the registers (a cut's seed or the current registers),
|
|
@@ -457,6 +458,13 @@ function meshSession(opt) {
|
|
|
457
458
|
if (keep.length > replayed.length)
|
|
458
459
|
hooks.onConflicts?.(conflicts());
|
|
459
460
|
hooks.onOutboxChange?.();
|
|
461
|
+
if (newer)
|
|
462
|
+
hooks.onGeneration?.({
|
|
463
|
+
instance: gen.instance,
|
|
464
|
+
index: gen.index,
|
|
465
|
+
reason: gen.reason,
|
|
466
|
+
policy: gen.policy,
|
|
467
|
+
});
|
|
460
468
|
};
|
|
461
469
|
const handle = (msg) => {
|
|
462
470
|
if (msg.room !== opt.room)
|
|
@@ -853,6 +861,7 @@ function agentSeat(initial, opt) {
|
|
|
853
861
|
for (const cb of [...listeners])
|
|
854
862
|
cb(event);
|
|
855
863
|
};
|
|
864
|
+
const compaction = signal(undefined, ...(ngDevMode ? [{ debugName: "compaction" }] : /* istanbul ignore next */ []));
|
|
856
865
|
let welcomed = false;
|
|
857
866
|
let diverged = false;
|
|
858
867
|
let terminated = false;
|
|
@@ -886,6 +895,7 @@ function agentSeat(initial, opt) {
|
|
|
886
895
|
},
|
|
887
896
|
onResync: (seq) => emit({ kind: 'resync', seq }),
|
|
888
897
|
onDirect: (msg) => deliverDirect(directListeners, msg),
|
|
898
|
+
onCompaction: (state) => compaction.set(state),
|
|
889
899
|
onConflicts: (list) => {
|
|
890
900
|
// a refused write stays applied until the rehydrate that follows lands
|
|
891
901
|
if (list.some((c) => c.cause !== 'uncovered'))
|
|
@@ -931,6 +941,8 @@ function agentSeat(initial, opt) {
|
|
|
931
941
|
sync.flush();
|
|
932
942
|
},
|
|
933
943
|
conflicts: () => session.conflicts(),
|
|
944
|
+
compaction: compaction.asReadonly(),
|
|
945
|
+
declareReady: (pressed) => session.declareReady(pressed),
|
|
934
946
|
setAtPath: (path, value) => {
|
|
935
947
|
setAtPath(doc, path, value);
|
|
936
948
|
sync.flush();
|
|
@@ -1127,6 +1139,7 @@ function meshSync(source, opt) {
|
|
|
1127
1139
|
const peerMap = signal(new Map(), ...(ngDevMode ? [{ debugName: "peerMap" }] : /* istanbul ignore next */ []));
|
|
1128
1140
|
const conflicts = signal([], ...(ngDevMode ? [{ debugName: "conflicts" }] : /* istanbul ignore next */ []));
|
|
1129
1141
|
const compaction = signal(undefined, ...(ngDevMode ? [{ debugName: "compaction" }] : /* istanbul ignore next */ []));
|
|
1142
|
+
const generation = signal(undefined, ...(ngDevMode ? [{ debugName: "generation" }] : /* istanbul ignore next */ []));
|
|
1130
1143
|
const peers = computed(() => [...peerMap().values()], ...(ngDevMode ? [{ debugName: "peers" }] : /* istanbul ignore next */ []));
|
|
1131
1144
|
const policyVersion = opt.policyVersion ?? 0;
|
|
1132
1145
|
const health = computed(() => {
|
|
@@ -1316,6 +1329,7 @@ function meshSync(source, opt) {
|
|
|
1316
1329
|
onPeers: (map) => peerMap.set(map),
|
|
1317
1330
|
onConflicts: (list) => conflicts.set(list),
|
|
1318
1331
|
onCompaction: (state) => compaction.set(state),
|
|
1332
|
+
onGeneration: (next) => generation.set(next),
|
|
1319
1333
|
onOutboxChange: () => {
|
|
1320
1334
|
void persistOutbox();
|
|
1321
1335
|
acked.set(!session?.hasUnacked());
|
|
@@ -1546,6 +1560,7 @@ function meshSync(source, opt) {
|
|
|
1546
1560
|
},
|
|
1547
1561
|
conflicts: conflicts.asReadonly(),
|
|
1548
1562
|
compaction: compaction.asReadonly(),
|
|
1563
|
+
generation: generation.asReadonly(),
|
|
1549
1564
|
declareReady: (pressed) => session?.declareReady(pressed),
|
|
1550
1565
|
sync: {
|
|
1551
1566
|
override: (fn) => (started ? sync.override(fn) : fn()),
|