cross-tab-worker-databus 0.20.66 → 0.20.68

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.
@@ -296,6 +296,7 @@ var BatchingStorageWriter = class {
296
296
  };
297
297
 
298
298
  // src/core/cluster.ts
299
+ var CLUSTER_PROTOCOL_VERSION = 1;
299
300
  var DEFAULT_HEARTBEAT_INTERVAL_MS = 3e3;
300
301
  var DEFAULT_WORKER_TTL_MS = 1e4;
301
302
  var DEFAULT_STORAGE_PREFIX = "cross-tab-worker-databus";
@@ -356,6 +357,8 @@ var WorkerClusterRuntime = class {
356
357
  routeOwnerCacheMax;
357
358
  routeOwnerCacheHits = 0;
358
359
  routeOwnerCacheMisses = 0;
360
+ unknownMessageCount = 0;
361
+ lastUnknownMessageType = null;
359
362
  touchRouteOwnerCache(topicKey, value) {
360
363
  if (this.routeOwnerCache.has(topicKey)) this.routeOwnerCache.delete(topicKey);
361
364
  this.routeOwnerCache.set(topicKey, value);
@@ -712,6 +715,10 @@ var WorkerClusterRuntime = class {
712
715
  }
713
716
  return false;
714
717
  }
718
+ /** Count and last type of unknown protocol messages observed. */
719
+ getUnknownMessageStats() {
720
+ return { count: this.unknownMessageCount, lastType: this.lastUnknownMessageType };
721
+ }
715
722
  /** Read-only snapshot of the cluster state (workers, routes, assignments). */
716
723
  getSnapshot() {
717
724
  const routes = this.storage ? readAllByPrefix(this.storage, this.routePrefix).map(({ value }) => ({
@@ -719,6 +726,7 @@ var WorkerClusterRuntime = class {
719
726
  topic: this.knownTopics.get(value.topicKey) ?? null
720
727
  })) : [];
721
728
  return {
729
+ protocolVersion: CLUSTER_PROTOCOL_VERSION,
722
730
  coordinated: Boolean(this.storage && this.channel),
723
731
  suspended: this.suspended,
724
732
  currentWorker: { ...this.currentRecord },
@@ -775,9 +783,13 @@ var WorkerClusterRuntime = class {
775
783
  case "REGISTRY":
776
784
  this.reconcile();
777
785
  return;
778
- default:
786
+ default: {
787
+ this.unknownMessageCount += 1;
788
+ const unknown = message;
789
+ this.lastUnknownMessageType = typeof unknown.type === "string" ? unknown.type : null;
779
790
  this.handlers.onUnknownMessage?.(message);
780
791
  return;
792
+ }
781
793
  }
782
794
  };
783
795
  /** Handle a point-to-point CONTROL message (SUBSCRIBE / UNSUBSCRIBE / PUBLISH). */
@@ -971,7 +983,7 @@ var WorkerClusterRuntime = class {
971
983
  send(message) {
972
984
  if (!this.channel) return false;
973
985
  try {
974
- this.channel.postMessage(message);
986
+ this.channel.postMessage({ ...message, protocolVersion: CLUSTER_PROTOCOL_VERSION });
975
987
  return true;
976
988
  } catch {
977
989
  return false;
@@ -1883,6 +1895,7 @@ var CrossTabDataBus = class {
1883
1895
  recovery: this.getRecoveryStats(),
1884
1896
  dedup: this.getDedupStats(),
1885
1897
  replay: { enabled: Boolean(this.replayBuffers), topics: this.replayBuffers?.size ?? 0, messages },
1898
+ protocol: { version: this.cluster.getSnapshot().protocolVersion, unknownMessages: this.cluster.getUnknownMessageStats().count, lastUnknownMessageType: this.cluster.getUnknownMessageStats().lastType },
1886
1899
  cluster: this.cluster.getSnapshot()
1887
1900
  };
1888
1901
  }