cross-tab-worker-databus 0.20.96 → 0.21.0

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.
@@ -694,6 +694,12 @@ function assertHeartbeatInterval(value) {
694
694
  `Centrifuge heartbeatIntervalMs must be a positive number or Infinity, got ${String(value)}.`
695
695
  );
696
696
  }
697
+ function assertPublicTopic(operation, topic) {
698
+ if (topic !== "") return;
699
+ throw new TypeError(
700
+ `CrossTabDataBus.${operation}("") addresses a channel no transport can route; use a non-empty topic.`
701
+ );
702
+ }
697
703
  function assertStructuredCloneable(value) {
698
704
  if (typeof structuredClone !== "function") return;
699
705
  try {
@@ -2468,7 +2474,7 @@ var DedupManager = class {
2468
2474
  };
2469
2475
 
2470
2476
  // src/core/version.ts
2471
- var SDK_VERSION = true ? "0.20.96" : "";
2477
+ var SDK_VERSION = true ? "0.21.0" : "";
2472
2478
 
2473
2479
  // src/core/data-bus.ts
2474
2480
  var DEFAULT_REPLAY_MAX_PER_TOPIC = 100;
@@ -2559,10 +2565,6 @@ var CrossTabDataBus = class {
2559
2565
  // themselves demand: the failure path starts an on-demand reopen instead of
2560
2566
  // stranding them until some unrelated future operation arrives.
2561
2567
  recoveryWaiters = 0;
2562
- // Latch for the empty-topic deprecation warning so a hot publish path cannot
2563
- // fill the console. It is per-bus and never reset: the warning is about the
2564
- // caller's code, not about a transient runtime condition.
2565
- emptyTopicWarned = false;
2566
2568
  /** Monotonic generation incremented on every successful transport open.
2567
2569
  * Stays in lockstep with `lastSuccessAt` so callers can detect that the
2568
2570
  * transport has been reopened even if the timestamp window is short. */
@@ -2957,8 +2959,11 @@ var CrossTabDataBus = class {
2957
2959
  * unsubscribe function for convenience. During an explicit stop() the
2958
2960
  * registration is rejected through onError and a no-op cleanup is returned,
2959
2961
  * so a late subscriber cannot leak into a future restart.
2962
+ * @throws {TypeError} when `topic` is `''` — no transport can address such a
2963
+ * channel, so the subscription could never receive anything.
2960
2964
  */
2961
2965
  subscribe(topic, handler, options) {
2966
+ assertPublicTopic("subscribe", topic);
2962
2967
  if (this.stopping) {
2963
2968
  this.reportError(new Error(
2964
2969
  "CrossTabDataBus is stopping; subscribe() was not registered. Wait for stop() to resolve, then call start() before subscribing again."
@@ -2967,7 +2972,6 @@ var CrossTabDataBus = class {
2967
2972
  };
2968
2973
  }
2969
2974
  this.ensureStarted();
2970
- if (topic === "") this.warnEmptyTopic("subscribe");
2971
2975
  const handlers = this.topicHandlers.get(topic) ?? /* @__PURE__ */ new Set();
2972
2976
  const wasUnused = handlers.size === 0;
2973
2977
  handlers.add(handler);
@@ -3017,20 +3021,10 @@ var CrossTabDataBus = class {
3017
3021
  resetDedup() {
3018
3022
  this.dedupManager.reset();
3019
3023
  }
3020
- /** Warn (once per bus) that an empty topic is deprecated, without changing
3021
- * behavior yet. `''` flows through routing as a literal channel, so the
3022
- * subscription it creates can never be addressed by a transport: the message
3023
- * silently goes nowhere. A future minor rejects it at this boundary. */
3024
- warnEmptyTopic(operation) {
3025
- if (this.emptyTopicWarned) return;
3026
- this.emptyTopicWarned = true;
3027
- console.warn(
3028
- `cross-tab-worker-databus: ${operation}("") addresses a channel no transport can route. Use a non-empty topic; passing "" is planned to throw in a future minor.`
3029
- );
3030
- }
3031
- /** Publish a message to `topic`. The owning Worker delivers it to the transport. */
3024
+ /** Publish a message to `topic`. The owning Worker delivers it to the transport.
3025
+ * @throws {TypeError} when `topic` is `''`; see `subscribe()`. */
3032
3026
  publish(topic, data, options) {
3033
- if (topic === "") this.warnEmptyTopic("publish");
3027
+ assertPublicTopic("publish", topic);
3034
3028
  this.ensureStarted();
3035
3029
  if (this.rejectPublishDuringStop("publish")) return;
3036
3030
  if (!this.cluster.publish(topic, data, options)) {
@@ -3045,11 +3039,14 @@ var CrossTabDataBus = class {
3045
3039
  * in one tick. Per-item dedup / replay / ordering is preserved; each item
3046
3040
  * may carry its own `messageId` / `timestamp` via `options`. Empty array is
3047
3041
  * a no-op; single-item array delegates to `publish()`.
3042
+ * @throws {TypeError} when `topic` is `''`; see `subscribe()`. Checked before
3043
+ * the empty-array no-op, so `publishBatch('', [])` throws too — the topic is
3044
+ * the caller's bug regardless of whether anything is carried.
3048
3045
  */
3049
3046
  publishBatch(topic, items) {
3047
+ assertPublicTopic("publishBatch", topic);
3050
3048
  this.ensureStarted();
3051
3049
  if (items.length === 0) return;
3052
- if (topic === "") this.warnEmptyTopic("publishBatch");
3053
3050
  if (this.rejectPublishDuringStop("publishBatch")) return;
3054
3051
  if (items.length === 1) {
3055
3052
  const first = items[0];
@@ -4218,9 +4215,6 @@ function createCentrifugeDataBus(options) {
4218
4215
  });
4219
4216
  }
4220
4217
  function createDefaultWorker() {
4221
- if (typeof Worker === "undefined") {
4222
- throw new Error("CentrifugeWorkerTransport requires a browser Worker implementation.");
4223
- }
4224
4218
  let workerUrl;
4225
4219
  try {
4226
4220
  workerUrl = new URL("./centrifuge.worker.js", import_meta.url);
@@ -4235,9 +4229,6 @@ function createDefaultWorker() {
4235
4229
  });
4236
4230
  }
4237
4231
  function createDefaultSharedWorker() {
4238
- if (typeof SharedWorker === "undefined") {
4239
- throw new Error("CentrifugeWorkerTransport requires a browser SharedWorker implementation.");
4240
- }
4241
4232
  let workerUrl;
4242
4233
  try {
4243
4234
  workerUrl = new URL("./centrifuge.shared.worker.js", import_meta.url);