cross-tab-worker-databus 0.20.68 → 0.20.71
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 +16 -0
- package/dist/centrifuge.d.ts +2 -0
- package/dist/centrifuge.d.ts.map +1 -1
- package/dist/centrifuge.js +5 -1
- package/dist/centrifuge.js.map +2 -2
- package/dist/{chunk-X6JTPZYW.js → chunk-D2SIT473.js} +32 -5
- package/dist/chunk-D2SIT473.js.map +7 -0
- package/dist/cjs/centrifuge.cjs +35 -4
- package/dist/cjs/centrifuge.cjs.map +2 -2
- package/dist/cjs/index.cjs +73 -4
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/core/cluster.d.ts +2 -0
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/core/data-bus.d.ts +9 -0
- package/dist/core/data-bus.d.ts.map +1 -1
- package/dist/core/replay-persistence.d.ts +2 -0
- package/dist/core/replay-persistence.d.ts.map +1 -1
- package/dist/core/types.d.ts +6 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.js +43 -1
- package/dist/index.js.map +2 -2
- package/dist/websocket.d.ts +2 -0
- package/dist/websocket.d.ts.map +1 -1
- package/docs/roadmap.md +13 -1
- package/docs/zh/roadmap.md +13 -1
- package/package.json +1 -1
- package/dist/chunk-X6JTPZYW.js.map +0 -7
package/dist/cjs/centrifuge.cjs
CHANGED
|
@@ -400,6 +400,7 @@ var WorkerClusterRuntime = class {
|
|
|
400
400
|
this.workerId = options.workerId ?? `worker-${this.tabId}-${this.environment.randomId()}`;
|
|
401
401
|
const now = this.environment.now();
|
|
402
402
|
this.currentRecord = {
|
|
403
|
+
protocolVersion: CLUSTER_PROTOCOL_VERSION,
|
|
403
404
|
workerId: this.workerId,
|
|
404
405
|
tabId: this.tabId,
|
|
405
406
|
load: 0,
|
|
@@ -721,16 +722,18 @@ var WorkerClusterRuntime = class {
|
|
|
721
722
|
}
|
|
722
723
|
/** Read-only snapshot of the cluster state (workers, routes, assignments). */
|
|
723
724
|
getSnapshot() {
|
|
725
|
+
const workers = this.storage ? this.readWorkers() : [{ ...this.currentRecord }];
|
|
724
726
|
const routes = this.storage ? readAllByPrefix(this.storage, this.routePrefix).map(({ value }) => ({
|
|
725
727
|
...value,
|
|
726
728
|
topic: this.knownTopics.get(value.topicKey) ?? null
|
|
727
729
|
})) : [];
|
|
728
730
|
return {
|
|
729
731
|
protocolVersion: CLUSTER_PROTOCOL_VERSION,
|
|
732
|
+
peerProtocolVersions: Object.fromEntries(workers.map((worker) => [worker.workerId, worker.protocolVersion ?? null])),
|
|
730
733
|
coordinated: Boolean(this.storage && this.channel),
|
|
731
734
|
suspended: this.suspended,
|
|
732
735
|
currentWorker: { ...this.currentRecord },
|
|
733
|
-
workers:
|
|
736
|
+
workers: workers.map((worker) => ({ ...worker })),
|
|
734
737
|
routes,
|
|
735
738
|
subscribedTopics: Array.from(this.subscribedTopics),
|
|
736
739
|
assignedTopics: Array.from(this.assignedTopics.values()),
|
|
@@ -1385,6 +1388,7 @@ function roundMs(value) {
|
|
|
1385
1388
|
|
|
1386
1389
|
// src/core/data-bus.ts
|
|
1387
1390
|
var PUBLICATION_EVENT = "DATABUS_PUBLICATION";
|
|
1391
|
+
var SDK_VERSION = "0.20.69";
|
|
1388
1392
|
var DEFAULT_REPLAY_MAX_PER_TOPIC = 100;
|
|
1389
1393
|
var PersistenceRetryCancelledError = class extends Error {
|
|
1390
1394
|
constructor() {
|
|
@@ -1413,6 +1417,8 @@ var CrossTabDataBus = class {
|
|
|
1413
1417
|
persistenceRetryMaxAttempts;
|
|
1414
1418
|
persistenceRetryBackoffMs;
|
|
1415
1419
|
persistenceRetryGeneration = 0;
|
|
1420
|
+
pendingReplayPersistence = [];
|
|
1421
|
+
replayPersistenceFlushScheduled = false;
|
|
1416
1422
|
replayHydration;
|
|
1417
1423
|
// Retention cleanup is coalesced so a burst of publications does not issue
|
|
1418
1424
|
// one IndexedDB read/write transaction per message. The newest cutoff wins.
|
|
@@ -1888,15 +1894,20 @@ var CrossTabDataBus = class {
|
|
|
1888
1894
|
getDiagnostics() {
|
|
1889
1895
|
let messages = 0;
|
|
1890
1896
|
if (this.replayBuffers) for (const buffer of this.replayBuffers.values()) messages += buffer.length;
|
|
1897
|
+
const cluster = this.cluster.getSnapshot();
|
|
1898
|
+
const unknownMessages = this.cluster.getUnknownMessageStats();
|
|
1899
|
+
const transport = this.transport;
|
|
1891
1900
|
return {
|
|
1892
1901
|
status: this.status,
|
|
1902
|
+
sdkVersion: SDK_VERSION,
|
|
1893
1903
|
started: this.started,
|
|
1894
1904
|
transportReady: this.transportReady,
|
|
1895
1905
|
recovery: this.getRecoveryStats(),
|
|
1896
1906
|
dedup: this.getDedupStats(),
|
|
1897
1907
|
replay: { enabled: Boolean(this.replayBuffers), topics: this.replayBuffers?.size ?? 0, messages },
|
|
1898
|
-
protocol: { version:
|
|
1899
|
-
|
|
1908
|
+
protocol: { version: cluster.protocolVersion, unknownMessages: unknownMessages.count, lastUnknownMessageType: unknownMessages.lastType, peers: cluster.peerProtocolVersions },
|
|
1909
|
+
transport: { name: transport.diagnosticsName ?? transport.constructor.name, backend: transport.diagnosticsBackend ?? null },
|
|
1910
|
+
cluster
|
|
1900
1911
|
};
|
|
1901
1912
|
}
|
|
1902
1913
|
/**
|
|
@@ -2042,12 +2053,28 @@ var CrossTabDataBus = class {
|
|
|
2042
2053
|
}
|
|
2043
2054
|
}
|
|
2044
2055
|
if (this.replayPersistence) {
|
|
2045
|
-
|
|
2056
|
+
if (this.replayPersistence.appendBatch) {
|
|
2057
|
+
this.pendingReplayPersistence.push(storedMessage);
|
|
2058
|
+
this.scheduleReplayPersistenceFlush();
|
|
2059
|
+
} else {
|
|
2060
|
+
void this.withPersistenceRetry("append", () => this.replayPersistence.append(storedMessage)).catch((error) => this.reportPersistenceError(error));
|
|
2061
|
+
}
|
|
2046
2062
|
if (this.replayRetentionMs !== void 0 && this.replayPersistence.clearBefore) {
|
|
2047
2063
|
this.scheduleReplayRetentionCleanup(this.now() - this.replayRetentionMs);
|
|
2048
2064
|
}
|
|
2049
2065
|
}
|
|
2050
2066
|
}
|
|
2067
|
+
scheduleReplayPersistenceFlush() {
|
|
2068
|
+
if (this.replayPersistenceFlushScheduled) return;
|
|
2069
|
+
this.replayPersistenceFlushScheduled = true;
|
|
2070
|
+
queueMicrotask(() => {
|
|
2071
|
+
this.replayPersistenceFlushScheduled = false;
|
|
2072
|
+
const batch = this.pendingReplayPersistence.splice(0);
|
|
2073
|
+
if (batch.length === 0 || !this.replayPersistence) return;
|
|
2074
|
+
const operation = this.replayPersistence.appendBatch ? () => this.replayPersistence.appendBatch(batch) : () => Promise.all(batch.map((message) => this.replayPersistence.append(message))).then(() => void 0);
|
|
2075
|
+
void this.withPersistenceRetry("append", operation).catch((error) => this.reportPersistenceError(error));
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2051
2078
|
async hydrateReplay() {
|
|
2052
2079
|
if (!this.replayBuffers || !this.replayPersistence) {
|
|
2053
2080
|
return;
|
|
@@ -2554,6 +2581,7 @@ var DEFAULT_SESSION_TIMEOUT_MS = DEFAULT_HEARTBEAT_INTERVAL_MS2 * DEFAULT_SESSIO
|
|
|
2554
2581
|
// src/centrifuge.ts
|
|
2555
2582
|
var import_meta = {};
|
|
2556
2583
|
var CentrifugeWorkerTransport = class {
|
|
2584
|
+
diagnosticsName = "centrifuge";
|
|
2557
2585
|
workerMode;
|
|
2558
2586
|
transferable;
|
|
2559
2587
|
heartbeatIntervalMs;
|
|
@@ -2572,6 +2600,9 @@ var CentrifugeWorkerTransport = class {
|
|
|
2572
2600
|
// Generation captured when the current backend was created. Error handlers
|
|
2573
2601
|
// only act when the backend that registered them is still current.
|
|
2574
2602
|
backendGeneration = 0;
|
|
2603
|
+
get diagnosticsBackend() {
|
|
2604
|
+
return this.backend ?? "uninitialized";
|
|
2605
|
+
}
|
|
2575
2606
|
constructor(options = {}) {
|
|
2576
2607
|
this.workerMode = options.workerMode ?? "dedicated";
|
|
2577
2608
|
this.transferable = options.transferable ?? false;
|