cross-tab-worker-databus 0.20.17 → 0.20.19

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.
@@ -1261,7 +1261,7 @@ var PersistenceRetryCancelledError = class extends Error {
1261
1261
  this.name = "PersistenceRetryCancelledError";
1262
1262
  }
1263
1263
  };
1264
- var CrossTabDataBus = class _CrossTabDataBus {
1264
+ var CrossTabDataBus = class {
1265
1265
  transport;
1266
1266
  cluster;
1267
1267
  // Map of topic → set of local subscribers.
@@ -1325,7 +1325,8 @@ var CrossTabDataBus = class _CrossTabDataBus {
1325
1325
  // stop to settle.
1326
1326
  pendingStop = null;
1327
1327
  // Minimum interval in ms between automatic recovery attempts.
1328
- static RECOVERY_COOLDOWN_MS = 1e3;
1328
+ recoveryCooldownMs;
1329
+ recoveryMaxAttempts;
1329
1330
  constructor(options) {
1330
1331
  const replay = options.replay;
1331
1332
  if (replay) {
@@ -1355,7 +1356,15 @@ var CrossTabDataBus = class _CrossTabDataBus {
1355
1356
  if (!Number.isFinite(this.persistenceRetryBackoffMs) || this.persistenceRetryBackoffMs < 0) {
1356
1357
  throw new TypeError("replay.persistenceRetry.backoffMs must be a non-negative finite number.");
1357
1358
  }
1358
- const { autoStart, initialConfig, trace, transport, dedup, ...clusterOptions } = options;
1359
+ const { autoStart, initialConfig, trace, transport, dedup, recovery, ...clusterOptions } = options;
1360
+ this.recoveryCooldownMs = recovery?.cooldownMs ?? 1e3;
1361
+ this.recoveryMaxAttempts = recovery?.maxAttempts ?? Number.POSITIVE_INFINITY;
1362
+ if (!Number.isFinite(this.recoveryCooldownMs) || this.recoveryCooldownMs <= 0) {
1363
+ throw new TypeError("recovery.cooldownMs must be a positive finite number.");
1364
+ }
1365
+ if (!(this.recoveryMaxAttempts === Number.POSITIVE_INFINITY || Number.isSafeInteger(this.recoveryMaxAttempts) && this.recoveryMaxAttempts > 0)) {
1366
+ throw new TypeError("recovery.maxAttempts must be a positive safe integer.");
1367
+ }
1359
1368
  this.now = dedup?.now ?? Date.now;
1360
1369
  this.replayHydration = this.hydrateReplay();
1361
1370
  this.transport = transport;
@@ -1911,15 +1920,16 @@ var CrossTabDataBus = class _CrossTabDataBus {
1911
1920
  }
1912
1921
  if (status === "error" && this.started && !this.stopping) {
1913
1922
  const now = this.now();
1914
- if (now - this.lastRecoveryAt >= _CrossTabDataBus.RECOVERY_COOLDOWN_MS) {
1923
+ if (now - this.lastRecoveryAt >= this.recoveryCooldownMs) {
1915
1924
  this.lastRecoveryAt = now;
1916
1925
  const attempt = ++this.recoveryAttempt;
1926
+ if (attempt > this.recoveryMaxAttempts) return;
1917
1927
  this.trace.event({ type: "reliability", operation: "transport_recovery", attempt, outcome: "scheduled" });
1918
1928
  setTimeout(() => {
1919
1929
  if (this.stopping || !this.started || this.suspended) return;
1920
1930
  if (this.status !== "error") return;
1921
1931
  void this.reopenTransport(attempt);
1922
- }, _CrossTabDataBus.RECOVERY_COOLDOWN_MS);
1932
+ }, this.recoveryCooldownMs);
1923
1933
  }
1924
1934
  }
1925
1935
  this.invokeHandlers(this.statusHandlers, (handler) => handler(status));