@rebasepro/client 0.34.1 → 0.34.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.
@@ -1,5 +1,28 @@
1
1
  import { DeleteProps, FetchCollectionProps, ListenCollectionProps, FetchOneProps, SaveProps, CollectionUpdateMeta, ChannelMessage, TableMetadata, BranchInfo, RebaseApiError, type RealtimeConnectionState } from "@rebasepro/types";
2
2
  import type { SqlScriptResult } from "@rebasepro/types";
3
+ /**
4
+ * Who ended a socket, as the `disconnect` event says it.
5
+ *
6
+ * - `server`: a close frame or a dropped connection (deploy, scale-in, proxy
7
+ * reload, network) — the close code says which.
8
+ * - `heartbeat`: this client gave up on it after two missed heartbeats.
9
+ * - `probe`: this client gave up on it when it did not answer the `ping` sent
10
+ * as the page woke.
11
+ * - `client`: this client closed it to sign in again (close code 4000).
12
+ */
13
+ export type RealtimeDisconnectCause = "server" | "heartbeat" | "probe" | "client";
14
+ /** What the `disconnect` event carries. */
15
+ export interface RealtimeDisconnectInfo {
16
+ /** The close code, when a close frame said one (1006 for a connection that just went). */
17
+ code?: number;
18
+ /** The close reason the other side gave, when it gave one. */
19
+ reason?: string;
20
+ cause: RealtimeDisconnectCause;
21
+ /** How long the socket had been open, in ms (0 when it never opened). */
22
+ openForMs: number;
23
+ /** How long since anything arrived on it, in ms. */
24
+ silentForMs: number;
25
+ }
3
26
  /**
4
27
  * A socket handler slot, declared with method syntax so its parameter is
5
28
  * compared bivariantly — the way an `on…` slot is assigned in practice. The
@@ -127,7 +150,16 @@ export declare class RebaseWebSocketClient {
127
150
  private serverClientId;
128
151
  /** When the current socket last delivered anything, heartbeats included. */
129
152
  private lastFrameAt;
153
+ /** When the current socket opened, for the `disconnect` event. */
154
+ private socketOpenedAt;
130
155
  private livenessTimer;
156
+ /** The current wake probe: when it was sent, and when it must have been answered by. */
157
+ private wakeProbe;
158
+ /**
159
+ * Why this client is about to close the current socket itself, read by its
160
+ * close handler so the `disconnect` event names the cause.
161
+ */
162
+ private closingFor;
131
163
  /** Give up on the current socket as though it had closed. Set per socket. */
132
164
  private dropSocket;
133
165
  /** Whether the server agreed, in its `hello`, to `name` for this socket. */
@@ -296,8 +328,24 @@ export declare class RebaseWebSocketClient {
296
328
  /**
297
329
  * Redial when two heartbeats in a row have not arrived. Anything the
298
330
  * server sends counts as a beat, so a busy socket is never judged on them.
331
+ *
332
+ * Never on a silence the page caused. A phone that locked, a tab the
333
+ * browser froze or a laptop that slept runs no timers and reads no frames,
334
+ * and on waking this interval used to fire before the frames waiting on
335
+ * the socket were read: it saw a minute of silence and tore down a socket
336
+ * that was fine, and every app on it saw a disconnect. A tick that comes
337
+ * far later than it was due is a wake: the socket is asked (`ping`, which
338
+ * a server that offers it answers at once) and given
339
+ * {@link WAKE_PROBE_TIMEOUT_MS} to say anything — or, from a server that
340
+ * does not offer `ping`, a whole deadline from now.
299
341
  */
300
342
  private watchLiveness;
343
+ /**
344
+ * The page has just woken (a late liveness tick, or the tab shown again):
345
+ * ask an open socket whether it is still there instead of judging it on
346
+ * the silence of the sleep. Does nothing while no heartbeats are watched.
347
+ */
348
+ private probeAfterWake;
301
349
  private stopLivenessWatch;
302
350
  private forgetServerOptIns;
303
351
  private processMessageQueue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/client",
3
- "version": "0.34.1",
3
+ "version": "0.34.2",
4
4
  "description": "HTTP SDK client for the Rebase custom backend",
5
5
  "keywords": [
6
6
  "rebase",
@@ -41,9 +41,9 @@
41
41
  "./package.json": "./package.json"
42
42
  },
43
43
  "dependencies": {
44
- "@rebasepro/common": "0.34.1",
45
- "@rebasepro/types": "0.34.1",
46
- "@rebasepro/utils": "0.34.1"
44
+ "@rebasepro/types": "0.34.2",
45
+ "@rebasepro/common": "0.34.2",
46
+ "@rebasepro/utils": "0.34.2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@jest/globals": "^30.4.1",