@econ-v1/domain 7.6.172 → 7.6.174

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.
@@ -71,6 +71,14 @@ export class TransportManager {
71
71
  path: "offline",
72
72
  status: "offline",
73
73
  };
74
+ /** Set by `setOfflineOverride`. Consulted by `markOffline`/`markReconnecting` so that an
75
+ * adapter-owned latch (e.g. the browser-offline state in `HttpTransportSupervisor`) can
76
+ * force every offline/reconnecting verdict this manager publishes — including the ones it
77
+ * raises internally (a failed dial round, `abort()`) and the ones the managed client
78
+ * raises on a carrier retire — to carry a specific reason, without patching methods on
79
+ * this object.
80
+ * @type {(() => TransportOfflineReason | undefined) | undefined} */
81
+ #offlineOverride;
74
82
 
75
83
  /** @param {TransportManagerOptions} options */
76
84
  constructor(options) {
@@ -190,6 +198,11 @@ export class TransportManager {
190
198
 
191
199
  /** @param {number} attempt @param {string} nextRetryAt @returns {void} */
192
200
  markReconnecting(attempt, nextRetryAt) {
201
+ const forced = this.#offlineOverride?.();
202
+ if (forced !== undefined) {
203
+ this.#publishOffline(forced);
204
+ return;
205
+ }
193
206
  this.#setState({
194
207
  attempt: wholeAttempt(attempt),
195
208
  changedAt: this.#now(),
@@ -201,6 +214,31 @@ export class TransportManager {
201
214
 
202
215
  /** @param {TransportOfflineReason} [reason] @returns {void} */
203
216
  markOffline(reason) {
217
+ const forced = this.#offlineOverride?.();
218
+ const effectiveReason = forced !== undefined && (reason === undefined || reason === "node-unreachable")
219
+ ? forced
220
+ : reason;
221
+ this.#publishOffline(effectiveReason);
222
+ }
223
+
224
+ /**
225
+ * Lets an adapter force every offline/reconnecting verdict this manager publishes to
226
+ * carry a specific reason, without patching `markOffline`/`markReconnecting` on this
227
+ * object. While `overrideFn` is set and returns a reason: `markOffline(undefined)` and
228
+ * `markOffline("node-unreachable")` publish that reason instead, `markOffline` with any
229
+ * other explicit reason (e.g. `"session-required"`) passes through unchanged, and
230
+ * `markReconnecting(...)` publishes offline with that reason instead of a reconnecting
231
+ * state. `overrideFn` returning `undefined` (or no override set) leaves both methods
232
+ * unchanged. Pass `undefined` to clear the override.
233
+ * @param {(() => TransportOfflineReason | undefined) | undefined} overrideFn
234
+ * @returns {void}
235
+ */
236
+ setOfflineOverride(overrideFn) {
237
+ this.#offlineOverride = overrideFn;
238
+ }
239
+
240
+ /** @param {TransportOfflineReason} [reason] @returns {void} */
241
+ #publishOffline(reason) {
204
242
  this.#setState({
205
243
  changedAt: this.#now(),
206
244
  path: "offline",