@rebasepro/client 0.24.0 → 0.24.1-canary.g56af4a4

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,4 +1,4 @@
1
- import { DeleteProps, CollectionConfig, FetchCollectionProps, ListenCollectionProps, FetchOneProps, SaveProps, CollectionUpdateMeta, ChannelMessage, TableMetadata, BranchInfo, RebaseApiError, type RealtimeConnectionState } from "@rebasepro/types";
1
+ import { DeleteProps, CollectionConfig, FetchCollectionProps, ListenCollectionProps, FetchOneProps, ListenOneTarget, SaveProps, CollectionUpdateMeta, ChannelMessage, TableMetadata, BranchInfo, RebaseApiError, type RealtimeConnectionState } from "@rebasepro/types";
2
2
  import type { SqlScriptResult } from "@rebasepro/types";
3
3
  export interface RebaseWebSocketConfig {
4
4
  websocketUrl: string;
@@ -68,6 +68,26 @@ export declare class RebaseWebSocketClient {
68
68
  get hasSocket(): boolean;
69
69
  /** So the "no WebSocket in this environment" warning is said once, not per call. */
70
70
  private warnedNoWebSocket;
71
+ /**
72
+ * What the server said in its `hello` it does for this socket: empty
73
+ * until then, after a close, and for a server that sends no `hello`.
74
+ */
75
+ private serverOptIns;
76
+ /** This socket's id on the server, from its `hello` (with `channel_seq`). */
77
+ private serverClientId;
78
+ /** When the current socket last delivered anything, heartbeats included. */
79
+ private lastFrameAt;
80
+ private livenessTimer;
81
+ /** Give up on the current socket as though it had closed. Set per socket. */
82
+ private dropSocket;
83
+ /** Whether the server agreed, in its `hello`, to `name` for this socket. */
84
+ hasServerOptIn(name: string): boolean;
85
+ /**
86
+ * This socket's id on the server, as its broadcasts' `senderId` in a
87
+ * channel's history. Known once a server that numbers retained channels
88
+ * for it (`channel_seq`) has said hello.
89
+ */
90
+ get socketClientId(): string | undefined;
71
91
  /** Subscribe to broadcast/presence frames for one channel. */
72
92
  onChannelMessage(channel: string, handler: (message: ChannelMessage) => void): () => void;
73
93
  /** Notified after the socket comes back, so channels can re-join. */
@@ -94,11 +114,11 @@ export declare class RebaseWebSocketClient {
94
114
  */
95
115
  private maxReconnectAttempts;
96
116
  /**
97
- * How many failed redials make a blip an outage: the point at which every
98
- * registration is told `CONNECTION_LOST` and {@link state} reads
99
- * `disconnected`. Three is 2 + 4 + 8 s of backoff, about 14 s down.
117
+ * Reports the outage once the connection has been down for
118
+ * {@link OUTAGE_REPORT_AFTER_MS}. Armed by the first redial after a drop,
119
+ * cleared when a socket opens or the caller disconnects.
100
120
  */
101
- private lostAfterAttempts;
121
+ private outageTimer;
102
122
  /**
103
123
  * Whether a socket of this client has ever opened — what makes the next
104
124
  * open a *reconnect*, whose server has forgotten every subscription and
@@ -163,6 +183,15 @@ export declare class RebaseWebSocketClient {
163
183
  */
164
184
  disconnect(permanent?: boolean): void;
165
185
  private initWebSocket;
186
+ /** Read the server's `hello`: what it agreed to, and start watching for heartbeats. */
187
+ private receiveHello;
188
+ /**
189
+ * Redial when two heartbeats in a row have not arrived. Anything the
190
+ * server sends counts as a beat, so a busy socket is never judged on them.
191
+ */
192
+ private watchLiveness;
193
+ private stopLivenessWatch;
194
+ private forgetServerOptIns;
166
195
  private processMessageQueue;
167
196
  /**
168
197
  * Whether a frame that waited in the queue should go out on the socket
@@ -193,6 +222,7 @@ export declare class RebaseWebSocketClient {
193
222
  * failed. When the socket is back they are re-subscribed, and the fresh
194
223
  * `onUpdate` is the recovery.
195
224
  */
225
+ private clearOutageTimer;
196
226
  private reportConnectionLost;
197
227
  private notifyError;
198
228
  /**
@@ -231,6 +261,14 @@ export declare class RebaseWebSocketClient {
231
261
  fetchOne<M extends Record<string, unknown>>(props: FetchOneProps<M>): Promise<Record<string, unknown> | undefined>;
232
262
  save<M extends Record<string, unknown>>(props: SaveProps<M>): Promise<Record<string, unknown>>;
233
263
  delete<M extends Record<string, unknown>>(props: DeleteProps<M>): Promise<void>;
264
+ /**
265
+ * @deprecated Will leave the public `client.ws` type in the next minor.
266
+ * Not part of the app-facing client: the admin UI's SQL console reaches it
267
+ * through `<Rebase>`, and it answers only a caller with `database:write`.
268
+ * App code has no supported SQL or branch path on the client; run SQL
269
+ * server-side (`isSQLAdmin(driver.admin)`), and use `client.admin` for
270
+ * users and roles.
271
+ */
234
272
  executeSql(sql: string, options?: {
235
273
  database?: string;
236
274
  role?: string;
@@ -244,7 +282,14 @@ export declare class RebaseWebSocketClient {
244
282
  runSqlScript(sql: string, options?: {
245
283
  database?: string;
246
284
  role?: string;
285
+ signal?: AbortSignal;
247
286
  }): Promise<SqlScriptResult>;
287
+ /**
288
+ * Stop a console run its caller gave up on: never written if it has not
289
+ * been yet, and cancelled on a server whose `hello` listed `cancel_sql`. A server
290
+ * that does not is left to finish it, bounded by its `statement_timeout`.
291
+ */
292
+ private cancelSqlRun;
248
293
  fetchAvailableDatabases(): Promise<string[]>;
249
294
  fetchAvailableRoles(): Promise<string[]>;
250
295
  fetchApplicationRoles(): Promise<string[]>;
@@ -253,17 +298,41 @@ export declare class RebaseWebSocketClient {
253
298
  count<M extends Record<string, unknown>>(props: FetchCollectionProps<M>): Promise<number>;
254
299
  fetchUnmappedTables(mappedPaths?: string[]): Promise<string[]>;
255
300
  fetchTableMetadata(tableName: string): Promise<TableMetadata>;
301
+ /**
302
+ * @deprecated Will leave the public `client.ws` type in the next minor.
303
+ * Not part of the app-facing client: the admin UI's SQL console reaches it
304
+ * through `<Rebase>`, and it answers only a caller with `database:write`.
305
+ * App code has no supported SQL or branch path on the client; run SQL
306
+ * server-side (`isSQLAdmin(driver.admin)`), and use `client.admin` for
307
+ * users and roles.
308
+ */
256
309
  createBranch(name: string, options?: {
257
310
  source?: string;
258
311
  }): Promise<BranchInfo>;
312
+ /**
313
+ * @deprecated Will leave the public `client.ws` type in the next minor.
314
+ * Not part of the app-facing client: the admin UI's SQL console reaches it
315
+ * through `<Rebase>`, and it answers only a caller with `database:write`.
316
+ * App code has no supported SQL or branch path on the client; run SQL
317
+ * server-side (`isSQLAdmin(driver.admin)`), and use `client.admin` for
318
+ * users and roles.
319
+ */
259
320
  deleteBranch(name: string): Promise<void>;
260
321
  listBranches(): Promise<BranchInfo[]>;
261
322
  /**
262
- * Recursively compare two values for structural equality.
263
- * Handles primitives, null, undefined, Date, RegExp, arrays, and plain objects.
323
+ * Recursively compare two values a refetch can carry for structural
324
+ * equality: primitives, null, undefined, Date, RegExp, arrays and objects.
325
+ *
326
+ * A relation compares by the reference it holds, not by the row it happens
327
+ * to have loaded, so its `data` is left out on both sides. That used to be
328
+ * done by normalising each side into a copy first — two deep copies of
329
+ * every cached row on every frame, most of which then compared equal. It is
330
+ * done in place now, and an unchanged row costs no copy.
331
+ *
332
+ * `relationAware` is off for a relation's own fields: the copies never
333
+ * looked inside those either.
264
334
  */
265
335
  private deepEqual;
266
- private normalizeForComparison;
267
336
  /**
268
337
  * The address of a row, for matching it against another copy of itself.
269
338
  *
@@ -285,7 +354,7 @@ export declare class RebaseWebSocketClient {
285
354
  */
286
355
  private mergeRows;
287
356
  listenCollection<M extends Record<string, unknown>>(props: Omit<ListenCollectionProps<M>, "onUpdate" | "onError">, onUpdate: (rows: Record<string, unknown>[], meta?: CollectionUpdateMeta) => void, onError?: (error: Error) => void): () => void;
288
- listenOne<M extends Record<string, unknown>>(props: FetchOneProps<M>, onUpdate: (row: Record<string, unknown> | null) => void, onError?: (error: Error) => void): () => void;
357
+ listenOne<M extends Record<string, unknown>>(props: ListenOneTarget<M>, onUpdate: (row: Record<string, unknown> | null) => void, onError?: (error: Error) => void): () => void;
289
358
  /**
290
359
  * Send a `subscribe_collection` for an already-registered subscription and
291
360
  * arm its watchdog.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/client",
3
- "version": "0.24.0",
3
+ "version": "0.24.1-canary.g56af4a4",
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.24.0",
45
- "@rebasepro/utils": "0.24.0",
46
- "@rebasepro/types": "0.24.0"
44
+ "@rebasepro/common": "0.24.1-canary.g56af4a4",
45
+ "@rebasepro/types": "0.24.1-canary.g56af4a4",
46
+ "@rebasepro/utils": "0.24.1-canary.g56af4a4"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@jest/globals": "^30.4.1",
@@ -1 +0,0 @@
1
- export { QueryBuilder, or, and, cond } from "@rebasepro/common";