cross-tab-worker-databus 0.21.2 → 0.21.4

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.
@@ -307,10 +307,51 @@ function publicationMetadata(messageId, timestamp) {
307
307
  };
308
308
  }
309
309
 
310
+ // src/utils/error-utils.ts
311
+ function serializeError(error) {
312
+ if (error instanceof Error) {
313
+ return {
314
+ name: error.name,
315
+ message: error.message,
316
+ ...error.stack ? { stack: error.stack } : {}
317
+ };
318
+ }
319
+ const context = error === void 0 ? void 0 : error;
320
+ return {
321
+ name: "CentrifugeError",
322
+ message: typeof error === "string" ? error : "Centrifuge worker operation failed.",
323
+ ...context === void 0 || !isStructuredCloneable(context) ? {} : { context }
324
+ };
325
+ }
326
+ function isStructuredCloneable(value) {
327
+ if (typeof structuredClone !== "function") return true;
328
+ try {
329
+ structuredClone(value);
330
+ return true;
331
+ } catch {
332
+ return false;
333
+ }
334
+ }
335
+ function deserializeWorkerError(error) {
336
+ const result = new Error(error.message);
337
+ result.name = error.name;
338
+ if (error.stack) result.stack = error.stack;
339
+ if (error.context !== void 0) Object.assign(result, { context: error.context });
340
+ return result;
341
+ }
342
+ function describeFailure(error) {
343
+ try {
344
+ if (error instanceof Error) return error.message;
345
+ return String(error);
346
+ } catch {
347
+ return `[unstringifiable ${typeof error}]`;
348
+ }
349
+ }
350
+
310
351
  // src/utils/validation.ts
311
352
  function assertPositiveSafeInteger(value, name) {
312
353
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
313
- throw new TypeError(`${name} must be a positive safe integer, got ${String(value)}.`);
354
+ throw new TypeError(`${name} must be a positive safe integer, got ${describeFailure(value)}.`);
314
355
  }
315
356
  }
316
357
  function assertPositiveFiniteNumber(value, name) {
@@ -325,7 +366,7 @@ function assertNonNegativeFiniteNumber(value, name) {
325
366
  }
326
367
  function assertPruneStrategy(value) {
327
368
  const allowed = [PRUNE_STRATEGY.COUNT, PRUNE_STRATEGY.AGE, PRUNE_STRATEGY.BOTH];
328
- if (!allowed.includes(String(value))) {
369
+ if (!allowed.includes(describeFailure(value))) {
329
370
  throw new TypeError("pruneStrategy must be count, age, or both.");
330
371
  }
331
372
  }
@@ -400,7 +441,7 @@ function assertHeartbeatInterval(value) {
400
441
  if (value === Infinity) return;
401
442
  if (typeof value === "number" && Number.isFinite(value) && value > 0) return;
402
443
  throw new TypeError(
403
- `Centrifuge heartbeatIntervalMs must be a positive number or Infinity, got ${String(value)}.`
444
+ `Centrifuge heartbeatIntervalMs must be a positive number or Infinity, got ${describeFailure(value)}.`
404
445
  );
405
446
  }
406
447
  function assertPublicTopic(operation, topic) {
@@ -2346,7 +2387,7 @@ var DedupManager = class {
2346
2387
  };
2347
2388
 
2348
2389
  // src/core/version.ts
2349
- var SDK_VERSION = true ? "0.21.2" : "";
2390
+ var SDK_VERSION = true ? "0.21.4" : "";
2350
2391
 
2351
2392
  // src/core/data-bus.ts
2352
2393
  var DEFAULT_REPLAY_MAX_PER_TOPIC = 100;
@@ -2655,7 +2696,7 @@ var CrossTabDataBus = class {
2655
2696
  if (this.queuedStart) return this.queuedStart;
2656
2697
  const stop = this.stopPromise ?? Promise.resolve();
2657
2698
  const token = ++this.queuedStartToken;
2658
- const queued = stop.catch(() => void 0).then(() => {
2699
+ const queued = stop.then(() => {
2659
2700
  if (this.queuedStart === queued) this.queuedStart = null;
2660
2701
  if (token <= this.canceledQueuedStartToken) return;
2661
2702
  return this.start(config);
@@ -2737,7 +2778,7 @@ var CrossTabDataBus = class {
2737
2778
  const chainedPendingStop = this.pendingStop;
2738
2779
  const isCurrentLifecycle = () => lifecycleEpoch === this.lifecycleEpoch;
2739
2780
  let startupInProgress = true;
2740
- return before.catch(() => void 0).then(() => {
2781
+ return before.then(() => {
2741
2782
  if (!isCurrentLifecycle() || this.stopping || this.suspended) return;
2742
2783
  if (this.pendingStop === chainedPendingStop) this.pendingStop = null;
2743
2784
  this.transportHasConnected = false;
@@ -2964,7 +3005,7 @@ var CrossTabDataBus = class {
2964
3005
  * the most recent successful open, or `null` until the transport reaches
2965
3006
  * `ready`. */
2966
3007
  getRecoveryStats() {
2967
- const errorMessage = this.lastError instanceof Error ? this.lastError.message : this.lastError === null ? null : String(this.lastError);
3008
+ const errorMessage = this.lastError === null ? null : describeFailure(this.lastError);
2968
3009
  return {
2969
3010
  attempt: this.recoveryAttempt,
2970
3011
  exhausted: this.recoveryExhausted,
@@ -3235,7 +3276,7 @@ var CrossTabDataBus = class {
3235
3276
  }
3236
3277
  this.lastFailure = {
3237
3278
  source,
3238
- message: error instanceof Error ? error.message : String(error),
3279
+ message: describeFailure(error),
3239
3280
  at
3240
3281
  };
3241
3282
  if (source === FAILURE_SOURCE.PERSISTENCE) {
@@ -3536,6 +3577,8 @@ export {
3536
3577
  isWildcardTopic,
3537
3578
  topicMatchesPattern,
3538
3579
  publicationMetadata,
3580
+ serializeError,
3581
+ deserializeWorkerError,
3539
3582
  assertPositiveSafeInteger,
3540
3583
  assertPositiveFiniteNumber,
3541
3584
  assertPruneStrategy,
@@ -3547,4 +3590,4 @@ export {
3547
3590
  parseDataBusPublication,
3548
3591
  selectWorkerBackend
3549
3592
  };
3550
- //# sourceMappingURL=chunk-HRB4SND7.js.map
3593
+ //# sourceMappingURL=chunk-WFVM7HPE.js.map