@steve31415/baselib 3.74.1 → 3.75.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.
|
@@ -85,7 +85,9 @@ export interface SyncClientOptions<B, C extends EventBody, S extends EventBody,
|
|
|
85
85
|
fetchBootstrap(signal: AbortSignal): Promise<B>;
|
|
86
86
|
fetchCatchup(afterSeq: number, signal: AbortSignal): Promise<CatchupResult<S>>;
|
|
87
87
|
beaconUrl: string;
|
|
88
|
-
|
|
88
|
+
/** The app's own sync socket. Needed only without `hubUrl`: an app whose
|
|
89
|
+
* server no longer serves one omits it (since 3.75.0). */
|
|
90
|
+
socketUrl?(): string;
|
|
89
91
|
runtime: SyncBrowserRuntime;
|
|
90
92
|
authState: {
|
|
91
93
|
isBlocked(): boolean;
|
|
@@ -124,7 +126,8 @@ export interface SyncClientOptions<B, C extends EventBody, S extends EventBody,
|
|
|
124
126
|
* `wss://<hub>/api/ws?app=<app>` and carries hints only; mutations go over
|
|
125
127
|
* `postEvents` and catch-ups over `fetchCatchup`, against the app.
|
|
126
128
|
* Unset or empty: the same-origin socket (`socketUrl`), exactly as before.
|
|
127
|
-
* Requires `app` and `postEvents`.
|
|
129
|
+
* Requires `app` and `postEvents`. One of `hubUrl` and `socketUrl` must be
|
|
130
|
+
* set: the constructor throws otherwise. */
|
|
128
131
|
hubUrl?: string;
|
|
129
132
|
/** This app's name on the hub socket (hub mode). */
|
|
130
133
|
app?: string;
|
|
@@ -198,6 +201,8 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
198
201
|
private visibleSinceMono;
|
|
199
202
|
private readonly counters;
|
|
200
203
|
private readonly hub;
|
|
204
|
+
/** Where the live socket goes: the hub's URL, or the app's own. */
|
|
205
|
+
private readonly socketUrl;
|
|
201
206
|
/** The live hub socket answered our `connect`. */
|
|
202
207
|
private hubAcked;
|
|
203
208
|
/** Counts acks: a catch-up establishes only if it began under the current one. */
|
|
@@ -386,7 +391,6 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
386
391
|
private cancelResyncFailureRetry;
|
|
387
392
|
private sendConnect;
|
|
388
393
|
private connectMessage;
|
|
389
|
-
private socketUrl;
|
|
390
394
|
private sendRaw;
|
|
391
395
|
private trySend;
|
|
392
396
|
private flushViaBeacon;
|
|
@@ -169,6 +169,8 @@ export class SyncClient {
|
|
|
169
169
|
// fields above then hold the hub socket; the app's own reachability has
|
|
170
170
|
// its own ladder here, independent of the socket's.
|
|
171
171
|
hub;
|
|
172
|
+
/** Where the live socket goes: the hub's URL, or the app's own. */
|
|
173
|
+
socketUrl;
|
|
172
174
|
/** The live hub socket answered our `connect`. */
|
|
173
175
|
hubAcked = false;
|
|
174
176
|
/** Counts acks: a catch-up establishes only if it began under the current one. */
|
|
@@ -201,12 +203,18 @@ export class SyncClient {
|
|
|
201
203
|
constructor(options) {
|
|
202
204
|
this.options = options;
|
|
203
205
|
if (!options.hubUrl) {
|
|
206
|
+
const sameOrigin = options.socketUrl?.bind(options);
|
|
207
|
+
if (!sameOrigin)
|
|
208
|
+
throw new Error('sync needs hubUrl or socketUrl');
|
|
204
209
|
this.hub = null;
|
|
210
|
+
this.socketUrl = () => sameOrigin();
|
|
205
211
|
return;
|
|
206
212
|
}
|
|
207
213
|
if (!options.app || !options.postEvents)
|
|
208
214
|
throw new Error('sync hub mode needs app and postEvents');
|
|
209
|
-
|
|
215
|
+
const url = hubSocketUrl(options.hubUrl, options.app);
|
|
216
|
+
this.hub = { app: options.app, postEvents: options.postEvents };
|
|
217
|
+
this.socketUrl = () => url;
|
|
210
218
|
}
|
|
211
219
|
init() {
|
|
212
220
|
if (this.disposed)
|
|
@@ -1900,9 +1908,6 @@ export class SyncClient {
|
|
|
1900
1908
|
return { type: 'connect', clientGuid: this.options.clientGuid };
|
|
1901
1909
|
return { type: 'connect', clientGuid: this.options.clientGuid, lastSeq: this.options.store.currentSeq() };
|
|
1902
1910
|
}
|
|
1903
|
-
socketUrl() {
|
|
1904
|
-
return this.hub?.socketUrl ?? this.options.socketUrl();
|
|
1905
|
-
}
|
|
1906
1911
|
sendRaw(message) {
|
|
1907
1912
|
if (this.socket?.readyState !== SOCKET_OPEN)
|
|
1908
1913
|
return;
|
package/package.json
CHANGED