@calimero-network/mero-react 5.1.0 → 6.0.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.
- package/dist/index.cjs +50 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -6
- package/dist/index.d.ts +77 -6
- package/dist/index.js +48 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1990,6 +1990,15 @@ function useNamespace(namespaceId) {
|
|
|
1990
1990
|
);
|
|
1991
1991
|
return { namespace: data, loading, error, refetch };
|
|
1992
1992
|
}
|
|
1993
|
+
function useNodeIdentity() {
|
|
1994
|
+
const { mero } = useMero();
|
|
1995
|
+
const { data, loading, error, refetch } = useAsyncResource(
|
|
1996
|
+
mero ? () => mero.admin.getNodeIdentity() : null,
|
|
1997
|
+
null,
|
|
1998
|
+
[mero]
|
|
1999
|
+
);
|
|
2000
|
+
return { identity: data, loading, error, refetch };
|
|
2001
|
+
}
|
|
1993
2002
|
function useNamespaceIdentity(namespaceId) {
|
|
1994
2003
|
const { mero } = useMero();
|
|
1995
2004
|
const { data, loading, error, refetch } = useAsyncResource(
|
|
@@ -2359,6 +2368,35 @@ function useDetachContextFromGroup() {
|
|
|
2359
2368
|
);
|
|
2360
2369
|
return { detachContextFromGroup, loading, error };
|
|
2361
2370
|
}
|
|
2371
|
+
var DEFAULT_MIGRATION_POLL_INTERVAL_MS = 5e3;
|
|
2372
|
+
function useMigrationEvents(namespaceId, onEvent) {
|
|
2373
|
+
const { mero } = useMero();
|
|
2374
|
+
const mountedRef = useMountedRef();
|
|
2375
|
+
const [live, setLive] = react.useState(false);
|
|
2376
|
+
const handlerRef = react.useRef(onEvent);
|
|
2377
|
+
handlerRef.current = onEvent;
|
|
2378
|
+
react.useEffect(() => {
|
|
2379
|
+
if (!mero || !namespaceId) return;
|
|
2380
|
+
const sse = mero.events;
|
|
2381
|
+
const unsubscribe = sse.onMigrationEvent((event) => handlerRef.current(event));
|
|
2382
|
+
let cancelled = false;
|
|
2383
|
+
void (async () => {
|
|
2384
|
+
try {
|
|
2385
|
+
await sse.connect();
|
|
2386
|
+
await sse.subscribe({ groupIds: [namespaceId] });
|
|
2387
|
+
if (!cancelled && mountedRef.current) setLive(true);
|
|
2388
|
+
} catch {
|
|
2389
|
+
if (!cancelled && mountedRef.current) setLive(false);
|
|
2390
|
+
}
|
|
2391
|
+
})();
|
|
2392
|
+
return () => {
|
|
2393
|
+
cancelled = true;
|
|
2394
|
+
if (mountedRef.current) setLive(false);
|
|
2395
|
+
unsubscribe();
|
|
2396
|
+
};
|
|
2397
|
+
}, [mero, namespaceId, mountedRef]);
|
|
2398
|
+
return live;
|
|
2399
|
+
}
|
|
2362
2400
|
function useMigrationStatus(namespaceId, options) {
|
|
2363
2401
|
const { mero } = useMero();
|
|
2364
2402
|
const [status, setStatus] = react.useState(null);
|
|
@@ -2403,7 +2441,8 @@ function useMigrationStatus(namespaceId, options) {
|
|
|
2403
2441
|
react.useEffect(() => {
|
|
2404
2442
|
void refetch();
|
|
2405
2443
|
}, [refetch]);
|
|
2406
|
-
const
|
|
2444
|
+
const sseLive = useMigrationEvents(namespaceId, () => void refetch());
|
|
2445
|
+
const pollIntervalMs = options?.pollIntervalMs ?? (sseLive ? void 0 : DEFAULT_MIGRATION_POLL_INTERVAL_MS);
|
|
2407
2446
|
react.useEffect(() => {
|
|
2408
2447
|
if (!pollIntervalMs || !mero || !namespaceId) return;
|
|
2409
2448
|
const handle = setInterval(() => void refetch(), pollIntervalMs);
|
|
@@ -2416,6 +2455,12 @@ function useMigrationStatus(namespaceId, options) {
|
|
|
2416
2455
|
rollup,
|
|
2417
2456
|
members,
|
|
2418
2457
|
allMigrated: rollup?.allMigrated ?? false,
|
|
2458
|
+
/**
|
|
2459
|
+
* When this node watched the fleet converge, or `null`. Durable, unlike
|
|
2460
|
+
* `allMigrated`, which is recomputed from in-TTL heartbeats and lapses back
|
|
2461
|
+
* to false when a member simply goes quiet.
|
|
2462
|
+
*/
|
|
2463
|
+
fleetCompletedAt: status?.fleetCompletedAt ?? null,
|
|
2419
2464
|
membersPendingSignature: rollup?.membersPendingSignature ?? 0,
|
|
2420
2465
|
/** Members whose migrate aborted (migration-check failed or apply errored). */
|
|
2421
2466
|
failed: rollup?.failed ?? 0,
|
|
@@ -2535,7 +2580,6 @@ var EMPTY_GROUP_APP_VERSION = {
|
|
|
2535
2580
|
version: null,
|
|
2536
2581
|
applicationId: null,
|
|
2537
2582
|
pendingApply: false,
|
|
2538
|
-
upgradePolicy: null,
|
|
2539
2583
|
activeUpgrade: null
|
|
2540
2584
|
};
|
|
2541
2585
|
function isZeroAppKey(appKey) {
|
|
@@ -2567,17 +2611,14 @@ function useGroupAppVersion(groupId) {
|
|
|
2567
2611
|
const namespace = namespaces.find((entry) => entry.namespaceId === groupId);
|
|
2568
2612
|
let appKey;
|
|
2569
2613
|
let applicationId;
|
|
2570
|
-
let upgradePolicy;
|
|
2571
2614
|
let activeUpgrade = null;
|
|
2572
2615
|
if (namespace) {
|
|
2573
2616
|
appKey = namespace.appKey;
|
|
2574
2617
|
applicationId = namespace.targetApplicationId;
|
|
2575
|
-
upgradePolicy = namespace.upgradePolicy ?? null;
|
|
2576
2618
|
} else {
|
|
2577
2619
|
const info = await mero.admin.getGroupInfo(groupId);
|
|
2578
2620
|
appKey = info.appKey;
|
|
2579
2621
|
applicationId = info.targetApplicationId;
|
|
2580
|
-
upgradePolicy = info.upgradePolicy ?? null;
|
|
2581
2622
|
activeUpgrade = info.activeUpgrade ?? null;
|
|
2582
2623
|
}
|
|
2583
2624
|
let version = null;
|
|
@@ -2591,7 +2632,7 @@ function useGroupAppVersion(groupId) {
|
|
|
2591
2632
|
}
|
|
2592
2633
|
}
|
|
2593
2634
|
if (mountedRef.current && seq === reqRef.current) {
|
|
2594
|
-
setData({ version, applicationId, pendingApply,
|
|
2635
|
+
setData({ version, applicationId, pendingApply, activeUpgrade });
|
|
2595
2636
|
}
|
|
2596
2637
|
} catch (err) {
|
|
2597
2638
|
const errorValue = toError(err);
|
|
@@ -2802,6 +2843,7 @@ exports.AppMode = AppMode;
|
|
|
2802
2843
|
exports.CalimeroLogo = CalimeroLogo;
|
|
2803
2844
|
exports.ConnectButton = ConnectButton;
|
|
2804
2845
|
exports.ConnectionType = ConnectionType;
|
|
2846
|
+
exports.DEFAULT_MIGRATION_POLL_INTERVAL_MS = DEFAULT_MIGRATION_POLL_INTERVAL_MS;
|
|
2805
2847
|
exports.LoginModal = LoginModal;
|
|
2806
2848
|
exports.MERO_CSS_VARS = MERO_CSS_VARS;
|
|
2807
2849
|
exports.MeroContext = MeroContext;
|
|
@@ -2862,6 +2904,7 @@ exports.useJoinSubgroupInheritance = useJoinSubgroupInheritance;
|
|
|
2862
2904
|
exports.useLatestVersion = useLatestVersion;
|
|
2863
2905
|
exports.useMemberMetadata = useMemberMetadata;
|
|
2864
2906
|
exports.useMero = useMero;
|
|
2907
|
+
exports.useMigrationEvents = useMigrationEvents;
|
|
2865
2908
|
exports.useMigrationStatus = useMigrationStatus;
|
|
2866
2909
|
exports.useMyAuthoredMigration = useMyAuthoredMigration;
|
|
2867
2910
|
exports.useNamespace = useNamespace;
|
|
@@ -2869,6 +2912,7 @@ exports.useNamespaceGroups = useNamespaceGroups;
|
|
|
2869
2912
|
exports.useNamespaceIdentity = useNamespaceIdentity;
|
|
2870
2913
|
exports.useNamespaces = useNamespaces;
|
|
2871
2914
|
exports.useNamespacesForApplication = useNamespacesForApplication;
|
|
2915
|
+
exports.useNodeIdentity = useNodeIdentity;
|
|
2872
2916
|
exports.useRemoveGroupMembers = useRemoveGroupMembers;
|
|
2873
2917
|
exports.useReparentGroup = useReparentGroup;
|
|
2874
2918
|
exports.useResyncContext = useResyncContext;
|