cross-tab-worker-databus 0.4.0 → 0.5.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/CHANGELOG.md +13 -0
- package/dist/centrifuge.js +1 -1
- package/dist/{chunk-ZGQRELIV.js → chunk-W7DAXK4D.js} +33 -2
- package/dist/{chunk-ZGQRELIV.js.map → chunk-W7DAXK4D.js.map} +2 -2
- package/dist/cjs/centrifuge.cjs +32 -1
- package/dist/cjs/centrifuge.cjs.map +2 -2
- package/dist/cjs/index.cjs +81 -1
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/core/data-bus.d.ts +12 -5
- package/dist/core/data-bus.d.ts.map +1 -1
- package/dist/core/replay-persistence.d.ts +13 -0
- package/dist/core/replay-persistence.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -1
- package/dist/index.js.map +3 -3
- package/docs/README.md +2 -1
- package/docs/api.md +1 -1
- package/docs/roadmap.md +18 -0
- package/docs/zh/README.md +2 -1
- package/docs/zh/api.md +1 -1
- package/docs/zh/roadmap.md +18 -0
- package/package.json +2 -1
package/dist/cjs/centrifuge.cjs
CHANGED
|
@@ -1201,6 +1201,8 @@ var CrossTabDataBus = class _CrossTabDataBus {
|
|
|
1201
1201
|
// replay is enabled — buffering is opt-in and must cost nothing otherwise.
|
|
1202
1202
|
replayBuffers;
|
|
1203
1203
|
replayMaxPerTopic;
|
|
1204
|
+
replayPersistence;
|
|
1205
|
+
replayHydration;
|
|
1204
1206
|
initialConfig;
|
|
1205
1207
|
hasInitialConfig;
|
|
1206
1208
|
trace;
|
|
@@ -1240,6 +1242,8 @@ var CrossTabDataBus = class _CrossTabDataBus {
|
|
|
1240
1242
|
}
|
|
1241
1243
|
this.replayMaxPerTopic = replay?.maxPerTopic ?? DEFAULT_REPLAY_MAX_PER_TOPIC;
|
|
1242
1244
|
this.replayBuffers = replay ? /* @__PURE__ */ new Map() : null;
|
|
1245
|
+
this.replayPersistence = replay?.persistence ?? null;
|
|
1246
|
+
this.replayHydration = this.hydrateReplay();
|
|
1243
1247
|
const { autoStart, initialConfig, trace, transport, ...clusterOptions } = options;
|
|
1244
1248
|
this.transport = transport;
|
|
1245
1249
|
this.initialConfig = initialConfig;
|
|
@@ -1408,7 +1412,13 @@ var CrossTabDataBus = class _CrossTabDataBus {
|
|
|
1408
1412
|
typeof options.replay === "number" ? Math.floor(options.replay) : this.replayMaxPerTopic,
|
|
1409
1413
|
this.replayMaxPerTopic
|
|
1410
1414
|
);
|
|
1411
|
-
this.
|
|
1415
|
+
if (this.replayPersistence) {
|
|
1416
|
+
void this.replayHydration.then(() => {
|
|
1417
|
+
if (this.topicHandlers.get(topic)?.has(handler)) this.deliverReplay(topic, limit, handler);
|
|
1418
|
+
});
|
|
1419
|
+
} else {
|
|
1420
|
+
this.deliverReplay(topic, limit, handler);
|
|
1421
|
+
}
|
|
1412
1422
|
}
|
|
1413
1423
|
return () => this.unsubscribe(topic, handler);
|
|
1414
1424
|
}
|
|
@@ -1532,6 +1542,27 @@ var CrossTabDataBus = class _CrossTabDataBus {
|
|
|
1532
1542
|
}
|
|
1533
1543
|
buffer.push(message);
|
|
1534
1544
|
if (buffer.length > this.replayMaxPerTopic) buffer.shift();
|
|
1545
|
+
if (this.replayPersistence) {
|
|
1546
|
+
void this.replayPersistence.append(message).catch((error) => this.reportError(error));
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
async hydrateReplay() {
|
|
1550
|
+
if (!this.replayBuffers || !this.replayPersistence) {
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
try {
|
|
1554
|
+
for (const message of await this.replayPersistence.load()) {
|
|
1555
|
+
let buffer = this.replayBuffers.get(message.topic);
|
|
1556
|
+
if (!buffer) {
|
|
1557
|
+
buffer = [];
|
|
1558
|
+
this.replayBuffers.set(message.topic, buffer);
|
|
1559
|
+
}
|
|
1560
|
+
buffer.push(message);
|
|
1561
|
+
if (buffer.length > this.replayMaxPerTopic) buffer.shift();
|
|
1562
|
+
}
|
|
1563
|
+
} catch (error) {
|
|
1564
|
+
this.reportError(error);
|
|
1565
|
+
}
|
|
1535
1566
|
}
|
|
1536
1567
|
/** Deliver buffered history to a newly-registered handler. For an exact
|
|
1537
1568
|
* topic this is that topic's ring; for a wildcard subscription every
|