@moku-labs/web 2.2.0 → 2.2.2

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.
@@ -1763,6 +1763,20 @@ interface ChannelOptions<T> {
1763
1763
  * order) on seed, closing the connect→load race. Defaults to `false` (deliver live).
1764
1764
  */
1765
1765
  bufferUntilSeed?: boolean;
1766
+ /**
1767
+ * Guard called on every socket close before the reconnect backoff is scheduled. Return `false`
1768
+ * to suppress reconnection (e.g. stop on a terminal close code like `4401` for 401 Unauthorized
1769
+ * / channel-not-found). The default — when omitted — always reconnects. The guard receives the
1770
+ * `CloseEvent`, so callers can inspect `event.code` / `event.reason` / `event.wasClean`.
1771
+ *
1772
+ * @param event - The `CloseEvent` from the closed socket.
1773
+ * @returns `true` (or `undefined`) to reconnect; `false` to stop permanently.
1774
+ * @example
1775
+ * ```ts
1776
+ * shouldReconnect: (event) => event.code !== 4401
1777
+ * ```
1778
+ */
1779
+ shouldReconnect?: (event: CloseEvent) => boolean;
1766
1780
  }
1767
1781
  /** A live realtime channel (the surface returned by {@link createChannel}). */
1768
1782
  interface Channel<T> {
package/dist/browser.mjs CHANGED
@@ -3518,6 +3518,7 @@ function runSwap(doSwap, transition, beforeCapture) {
3518
3518
  }
3519
3519
  else result = docWithVt.startViewTransition(doSwap);
3520
3520
  Promise.resolve(result?.finished).then(clearMarker).catch(clearMarker);
3521
+ Promise.resolve(result?.ready).catch(() => {});
3521
3522
  }
3522
3523
  /**
3523
3524
  * Replace the `swapSelector` region of the live document with the matching
@@ -4499,10 +4500,12 @@ function createChannel(options) {
4499
4500
  ws.addEventListener("open", () => {
4500
4501
  reconnectAttempts = 0;
4501
4502
  });
4502
- ws.addEventListener("close", () => {
4503
+ ws.addEventListener("close", (event) => {
4503
4504
  if (socket !== ws || desiredId === void 0) return;
4504
4505
  socket = void 0;
4505
- if (reconnectCfg) scheduleReconnect();
4506
+ if (!reconnectCfg) return;
4507
+ if (options.shouldReconnect?.(event) === false) return;
4508
+ scheduleReconnect();
4506
4509
  });
4507
4510
  }
4508
4511
  /**
package/dist/index.cjs CHANGED
@@ -10224,6 +10224,7 @@ function runSwap(doSwap, transition, beforeCapture) {
10224
10224
  }
10225
10225
  else result = docWithVt.startViewTransition(doSwap);
10226
10226
  Promise.resolve(result?.finished).then(clearMarker).catch(clearMarker);
10227
+ Promise.resolve(result?.ready).catch(() => {});
10227
10228
  }
10228
10229
  /**
10229
10230
  * Replace the `swapSelector` region of the live document with the matching
@@ -11205,10 +11206,12 @@ function createChannel(options) {
11205
11206
  ws.addEventListener("open", () => {
11206
11207
  reconnectAttempts = 0;
11207
11208
  });
11208
- ws.addEventListener("close", () => {
11209
+ ws.addEventListener("close", (event) => {
11209
11210
  if (socket !== ws || desiredId === void 0) return;
11210
11211
  socket = void 0;
11211
- if (reconnectCfg) scheduleReconnect();
11212
+ if (!reconnectCfg) return;
11213
+ if (options.shouldReconnect?.(event) === false) return;
11214
+ scheduleReconnect();
11212
11215
  });
11213
11216
  }
11214
11217
  /**
package/dist/index.d.cts CHANGED
@@ -3683,6 +3683,20 @@ interface ChannelOptions<T> {
3683
3683
  * order) on seed, closing the connect→load race. Defaults to `false` (deliver live).
3684
3684
  */
3685
3685
  bufferUntilSeed?: boolean;
3686
+ /**
3687
+ * Guard called on every socket close before the reconnect backoff is scheduled. Return `false`
3688
+ * to suppress reconnection (e.g. stop on a terminal close code like `4401` for 401 Unauthorized
3689
+ * / channel-not-found). The default — when omitted — always reconnects. The guard receives the
3690
+ * `CloseEvent`, so callers can inspect `event.code` / `event.reason` / `event.wasClean`.
3691
+ *
3692
+ * @param event - The `CloseEvent` from the closed socket.
3693
+ * @returns `true` (or `undefined`) to reconnect; `false` to stop permanently.
3694
+ * @example
3695
+ * ```ts
3696
+ * shouldReconnect: (event) => event.code !== 4401
3697
+ * ```
3698
+ */
3699
+ shouldReconnect?: (event: CloseEvent) => boolean;
3686
3700
  }
3687
3701
  /** A live realtime channel (the surface returned by {@link createChannel}). */
3688
3702
  interface Channel<T> {
package/dist/index.d.mts CHANGED
@@ -3681,6 +3681,20 @@ interface ChannelOptions<T> {
3681
3681
  * order) on seed, closing the connect→load race. Defaults to `false` (deliver live).
3682
3682
  */
3683
3683
  bufferUntilSeed?: boolean;
3684
+ /**
3685
+ * Guard called on every socket close before the reconnect backoff is scheduled. Return `false`
3686
+ * to suppress reconnection (e.g. stop on a terminal close code like `4401` for 401 Unauthorized
3687
+ * / channel-not-found). The default — when omitted — always reconnects. The guard receives the
3688
+ * `CloseEvent`, so callers can inspect `event.code` / `event.reason` / `event.wasClean`.
3689
+ *
3690
+ * @param event - The `CloseEvent` from the closed socket.
3691
+ * @returns `true` (or `undefined`) to reconnect; `false` to stop permanently.
3692
+ * @example
3693
+ * ```ts
3694
+ * shouldReconnect: (event) => event.code !== 4401
3695
+ * ```
3696
+ */
3697
+ shouldReconnect?: (event: CloseEvent) => boolean;
3684
3698
  }
3685
3699
  /** A live realtime channel (the surface returned by {@link createChannel}). */
3686
3700
  interface Channel<T> {
package/dist/index.mjs CHANGED
@@ -10211,6 +10211,7 @@ function runSwap(doSwap, transition, beforeCapture) {
10211
10211
  }
10212
10212
  else result = docWithVt.startViewTransition(doSwap);
10213
10213
  Promise.resolve(result?.finished).then(clearMarker).catch(clearMarker);
10214
+ Promise.resolve(result?.ready).catch(() => {});
10214
10215
  }
10215
10216
  /**
10216
10217
  * Replace the `swapSelector` region of the live document with the matching
@@ -11192,10 +11193,12 @@ function createChannel(options) {
11192
11193
  ws.addEventListener("open", () => {
11193
11194
  reconnectAttempts = 0;
11194
11195
  });
11195
- ws.addEventListener("close", () => {
11196
+ ws.addEventListener("close", (event) => {
11196
11197
  if (socket !== ws || desiredId === void 0) return;
11197
11198
  socket = void 0;
11198
- if (reconnectCfg) scheduleReconnect();
11199
+ if (!reconnectCfg) return;
11200
+ if (options.shouldReconnect?.(event) === false) return;
11201
+ scheduleReconnect();
11199
11202
  });
11200
11203
  }
11201
11204
  /**
package/package.json CHANGED
@@ -132,5 +132,5 @@
132
132
  "test:build-e2e": "bun test src/plugins/build/__tests__/e2e/",
133
133
  "test:coverage": "vitest run --project unit --project integration --coverage"
134
134
  },
135
- "version": "2.2.0"
135
+ "version": "2.2.2"
136
136
  }