cross-tab-worker-databus 0.20.65 → 0.20.66

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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.20.66] - 2026-09-05
4
+
5
+ ### Added
6
+ - Extended IndexedDB replay persistence with optional `pruneStrategy` (`count`, `age`, `both`) and `retentionMs`, applying the same trimming semantics as in-memory replay.
7
+
3
8
  ## [0.20.65] - 2026-09-05
4
9
 
5
10
  ### Added
@@ -2364,6 +2364,10 @@ function createIndexedDbReplayPersistence(options) {
2364
2364
  const dbName = options.dbName ?? "cross-tab-worker-databus";
2365
2365
  const storeName = "replay";
2366
2366
  const maxPerTopic = options.maxPerTopic;
2367
+ const pruneStrategy = options.pruneStrategy ?? "count";
2368
+ const retentionMs = options.retentionMs;
2369
+ if (!["count", "age", "both"].includes(pruneStrategy)) throw new TypeError("pruneStrategy must be count, age, or both.");
2370
+ if (retentionMs !== void 0 && (!Number.isFinite(retentionMs) || retentionMs <= 0)) throw new TypeError("retentionMs must be a positive finite number.");
2367
2371
  if (!Number.isSafeInteger(maxPerTopic) || maxPerTopic <= 0) {
2368
2372
  throw new TypeError(`maxPerTopic must be a positive safe integer, got ${String(maxPerTopic)}.`);
2369
2373
  }
@@ -2439,7 +2443,12 @@ function createIndexedDbReplayPersistence(options) {
2439
2443
  const store = transaction.objectStore(storeName);
2440
2444
  const request = store.get(message.topic);
2441
2445
  request.onsuccess = () => {
2442
- const messages = (request.result?.messages ?? []).concat(message).slice(-maxPerTopic);
2446
+ let messages = (request.result?.messages ?? []).concat(message);
2447
+ if (pruneStrategy !== "count" && retentionMs !== void 0) {
2448
+ const cutoff = Date.now() - retentionMs;
2449
+ messages = messages.filter((item) => item.timestamp === void 0 || item.timestamp >= cutoff);
2450
+ }
2451
+ if (pruneStrategy !== "age") messages = messages.slice(-maxPerTopic);
2443
2452
  store.put({ topic: message.topic, messages });
2444
2453
  };
2445
2454
  request.onerror = () => {