cross-tab-worker-databus 0.20.60 → 0.20.62
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/CHANGELOG.md +20 -1
- package/dist/centrifuge.js +1 -1
- package/dist/{chunk-KLHPSFVU.js → chunk-NYBXYYPM.js} +28 -9
- package/dist/chunk-NYBXYYPM.js.map +7 -0
- package/dist/cjs/centrifuge.cjs +27 -8
- package/dist/cjs/centrifuge.cjs.map +2 -2
- package/dist/cjs/index.cjs +27 -8
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/core/cluster.d.ts +9 -4
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/core/data-bus.d.ts +26 -2
- package/dist/core/data-bus.d.ts.map +1 -1
- package/dist/core/types.d.ts +10 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/docs/roadmap.md +12 -1
- package/docs/zh/roadmap.md +12 -1
- package/package.json +1 -1
- package/dist/chunk-KLHPSFVU.js.map +0 -7
package/dist/cjs/index.cjs
CHANGED
|
@@ -702,9 +702,12 @@ var WorkerClusterRuntime = class {
|
|
|
702
702
|
routeOwnerIsLive(route, workers) {
|
|
703
703
|
return Boolean(route && workers.some((worker) => worker.workerId === route.workerId));
|
|
704
704
|
}
|
|
705
|
-
/** Broadcast an event to every tab — used to fan out transport publications.
|
|
706
|
-
|
|
707
|
-
|
|
705
|
+
/** Broadcast an event to every tab — used to fan out transport publications.
|
|
706
|
+
* `originTabId` (when set) is propagated across the BroadcastChannel hop so
|
|
707
|
+
* listeners can attribute the event to its source tab even after fan-out. */
|
|
708
|
+
broadcastEvent(eventType, payload, originTabId) {
|
|
709
|
+
const effectiveOriginTabId = originTabId ?? this.tabId;
|
|
710
|
+
this.send({ type: "EVENT", sourceWorkerId: this.workerId, eventType, payload, originTabId: effectiveOriginTabId });
|
|
708
711
|
}
|
|
709
712
|
isAssigned(topic) {
|
|
710
713
|
const topicKey = createOpaqueKey(topic);
|
|
@@ -792,7 +795,7 @@ var WorkerClusterRuntime = class {
|
|
|
792
795
|
case "ROUTE_RELEASED":
|
|
793
796
|
return this.handleRouteReleasedMessage(message);
|
|
794
797
|
case "EVENT":
|
|
795
|
-
this.handlers.onEvent(message.eventType, message.payload, message.sourceWorkerId);
|
|
798
|
+
this.handlers.onEvent(message.eventType, message.payload, message.sourceWorkerId, message.originTabId);
|
|
796
799
|
return;
|
|
797
800
|
case "REGISTRY":
|
|
798
801
|
default:
|
|
@@ -1544,9 +1547,10 @@ var CrossTabDataBus = class {
|
|
|
1544
1547
|
// typed `unknown` at the cluster boundary (the cluster is transport-
|
|
1545
1548
|
// agnostic); here we narrow it to DataBusMessage — the sender is our
|
|
1546
1549
|
// own broadcastEvent call, which always posts a DataBusMessage.
|
|
1547
|
-
onEvent: (eventType, payload) => {
|
|
1550
|
+
onEvent: (eventType, payload, _sourceWorkerId, originTabId) => {
|
|
1548
1551
|
if (eventType !== PUBLICATION_EVENT) return;
|
|
1549
|
-
const
|
|
1552
|
+
const incoming = payload;
|
|
1553
|
+
const message = incoming.originTabId !== void 0 ? incoming : originTabId !== void 0 ? { ...incoming, originTabId } : incoming;
|
|
1550
1554
|
if (this.cluster.hasLocalSubscriber(message.topic)) this.dispatch(message);
|
|
1551
1555
|
},
|
|
1552
1556
|
onSuspend: () => {
|
|
@@ -1860,6 +1864,20 @@ var CrossTabDataBus = class {
|
|
|
1860
1864
|
getClusterSnapshot() {
|
|
1861
1865
|
return this.cluster.getSnapshot();
|
|
1862
1866
|
}
|
|
1867
|
+
/** Return a single health snapshot combining lifecycle, recovery, dedup, replay, and cluster state. */
|
|
1868
|
+
getDiagnostics() {
|
|
1869
|
+
let messages = 0;
|
|
1870
|
+
if (this.replayBuffers) for (const buffer of this.replayBuffers.values()) messages += buffer.length;
|
|
1871
|
+
return {
|
|
1872
|
+
status: this.status,
|
|
1873
|
+
started: this.started,
|
|
1874
|
+
transportReady: this.transportReady,
|
|
1875
|
+
recovery: this.getRecoveryStats(),
|
|
1876
|
+
dedup: this.getDedupStats(),
|
|
1877
|
+
replay: { enabled: Boolean(this.replayBuffers), topics: this.replayBuffers?.size ?? 0, messages },
|
|
1878
|
+
cluster: this.cluster.getSnapshot()
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1863
1881
|
/**
|
|
1864
1882
|
* Gracefully stop the DataBus: unsubscribe all topics, stop the cluster,
|
|
1865
1883
|
* and close the transport. Idempotent.
|
|
@@ -1909,9 +1927,10 @@ var CrossTabDataBus = class {
|
|
|
1909
1927
|
this.trace.recordDiscarded(message.topic);
|
|
1910
1928
|
return;
|
|
1911
1929
|
}
|
|
1912
|
-
this.cluster.
|
|
1930
|
+
const stamped = message.originTabId === void 0 ? { ...message, originTabId: this.cluster.tabId } : message;
|
|
1931
|
+
this.cluster.broadcastEvent(PUBLICATION_EVENT, stamped, stamped.originTabId);
|
|
1913
1932
|
if (this.cluster.hasLocalSubscriber(message.topic)) {
|
|
1914
|
-
this.dispatch(
|
|
1933
|
+
this.dispatch(stamped);
|
|
1915
1934
|
return;
|
|
1916
1935
|
}
|
|
1917
1936
|
this.trace.recordDiscarded(message.topic);
|