cross-tab-worker-databus 0.20.58 → 0.20.59

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.
@@ -1357,6 +1357,13 @@ var CrossTabDataBus = class {
1357
1357
  // a transport reopen succeeds so traces can correlate repeated failures.
1358
1358
  recoveryAttempt = 0;
1359
1359
  recoveryExhausted = false;
1360
+ /** Monotonic generation incremented on every successful transport open.
1361
+ * Stays in lockstep with `lastSuccessAt` so callers can detect that the
1362
+ * transport has been reopened even if the timestamp window is short. */
1363
+ recoveryGeneration = 0;
1364
+ /** Timestamp of the most recent successful transport open. Null until the
1365
+ * transport has reached the `ready` state at least once. */
1366
+ lastSuccessAt = null;
1360
1367
  // True while the tab is hidden so an in-flight transport start does not mark
1361
1368
  // the transport ready after suspendTransport() has stopped it.
1362
1369
  suspended = false;
@@ -1550,7 +1557,11 @@ var CrossTabDataBus = class {
1550
1557
  if (this.status === "error") {
1551
1558
  throw new Error("Transport failed during startup.");
1552
1559
  }
1553
- if (!this.suspended && !this.stopping) this.transportReady = true;
1560
+ if (!this.suspended && !this.stopping) {
1561
+ this.recoveryGeneration += 1;
1562
+ this.lastSuccessAt = this.now();
1563
+ this.transportReady = true;
1564
+ }
1554
1565
  });
1555
1566
  }).catch((error) => {
1556
1567
  if (stopClusterOnFailure) this.started = false;
@@ -1720,9 +1731,22 @@ var CrossTabDataBus = class {
1720
1731
  return this.status;
1721
1732
  }
1722
1733
  /** Return the current automatic transport recovery state. `hasError` means a transport error is currently retained. */
1734
+ /** Return the current automatic transport recovery state plus diagnostics.
1735
+ * `generation` increments on every successful transport open (initial start
1736
+ * and every recovery); `lastSuccessAt` is the timestamp of the most recent
1737
+ * successful open, or `null` until the transport reaches `ready`. */
1723
1738
  getRecoveryStats() {
1724
1739
  const errorMessage = this.lastError instanceof Error ? this.lastError.message : this.lastError === null ? null : String(this.lastError);
1725
- return { attempt: this.recoveryAttempt, exhausted: this.recoveryExhausted, maxAttempts: this.recoveryMaxAttempts, hasError: this.lastError !== null, errorMessage, errorAt: this.lastErrorAt };
1740
+ return {
1741
+ attempt: this.recoveryAttempt,
1742
+ exhausted: this.recoveryExhausted,
1743
+ maxAttempts: this.recoveryMaxAttempts,
1744
+ hasError: this.lastError !== null,
1745
+ errorMessage,
1746
+ errorAt: this.lastErrorAt,
1747
+ generation: this.recoveryGeneration,
1748
+ lastSuccessAt: this.lastSuccessAt
1749
+ };
1726
1750
  }
1727
1751
  /** Snapshot of the cluster state (workers, routes, assignments).
1728
1752
  * For diagnostics only — the returned object is a shallow copy but