@steve31415/baselib 3.76.0 → 4.0.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.
- package/README.md +4 -3
- package/dist/deploy/rollback.js +33 -19
- package/dist/deploy/types.d.ts +9 -0
- package/dist/sync/db-bridge.d.ts +7 -0
- package/dist/sync/db-bridge.js +11 -0
- package/dist/sync/http-events.d.ts +35 -0
- package/dist/sync/http-events.js +106 -0
- package/dist/sync/index.d.ts +1 -2
- package/dist/sync/index.js +1 -2
- package/dist/sync/types.d.ts +8 -56
- package/dist/sync/types.js +2 -3
- package/dist/sync-browser/client.d.ts +45 -74
- package/dist/sync-browser/client.js +187 -470
- package/dist/sync-browser/hub.js +3 -4
- package/dist/sync-browser/page-hub-url.js +3 -4
- package/package.json +1 -1
- package/dist/sync/broadcaster.d.ts +0 -13
- package/dist/sync/broadcaster.js +0 -53
- package/dist/sync/session.d.ts +0 -75
- package/dist/sync/session.js +0 -283
|
@@ -85,13 +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
|
-
/** 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;
|
|
91
88
|
runtime: SyncBrowserRuntime;
|
|
92
89
|
authState: {
|
|
93
90
|
isBlocked(): boolean;
|
|
94
|
-
markBlocked(): void;
|
|
95
91
|
onBlocked(listener: () => void): () => void;
|
|
96
92
|
};
|
|
97
93
|
logger: Pick<BrowserLogger, 'info' | 'warn' | 'error'>;
|
|
@@ -111,26 +107,24 @@ export interface SyncClientOptions<B, C extends EventBody, S extends EventBody,
|
|
|
111
107
|
/** While hidden and disconnected, one HTTP catch-up per this interval
|
|
112
108
|
* (default 5 min). */
|
|
113
109
|
backgroundCatchupMs?: number;
|
|
114
|
-
/** POSTs events to the app's batch endpoint (the beacon URL) and
|
|
115
|
-
* its response.
|
|
116
|
-
*
|
|
117
|
-
|
|
118
|
-
* response's frames and catch-up (`handleSyncEventsRequest`) settle it. */
|
|
119
|
-
postEvents?(body: {
|
|
110
|
+
/** POSTs events to the app's batch endpoint (the beacon URL's route) and
|
|
111
|
+
* returns its response. Every mutation travels here, with `lastSeq`, and
|
|
112
|
+
* the response's frames and catch-up (`handleSyncEventsRequest`) settle it. */
|
|
113
|
+
postEvents(body: {
|
|
120
114
|
clientGuid: string;
|
|
121
115
|
events: ClientEvent<C>[];
|
|
122
116
|
lastSeq?: number;
|
|
123
117
|
}, signal: AbortSignal): Promise<HttpEventsResponse<S>>;
|
|
124
|
-
/**
|
|
125
|
-
* `https://hub.apps.snewman.net
|
|
126
|
-
* `wss://<hub>/api/ws?app=<app>` and
|
|
127
|
-
* `postEvents` and catch-ups over
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
hubUrl
|
|
132
|
-
/** This app's name on the hub socket
|
|
133
|
-
app
|
|
118
|
+
/** The connection hub's base URL (connection hub design §5.4–§5.5), e.g.
|
|
119
|
+
* `https://hub.apps.snewman.net`: pass `pageHubUrl()`, the page shell's
|
|
120
|
+
* `pw-hub-url`. The live socket goes to `wss://<hub>/api/ws?app=<app>` and
|
|
121
|
+
* carries hints only; mutations go over `postEvents` and catch-ups over
|
|
122
|
+
* `fetchCatchup`, against the app. Since 4.0.0 there is no same-origin
|
|
123
|
+
* socket to fall back to: the constructor throws when this is undefined or
|
|
124
|
+
* empty (a shell without the meta is a misconfiguration, said at once). */
|
|
125
|
+
hubUrl: string | undefined;
|
|
126
|
+
/** This app's name on the hub socket. */
|
|
127
|
+
app: string;
|
|
134
128
|
}
|
|
135
129
|
export declare class SyncClient<B, C extends EventBody, S extends EventBody, Summary = unknown> {
|
|
136
130
|
private readonly options;
|
|
@@ -164,8 +158,6 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
164
158
|
private outageEscalated;
|
|
165
159
|
private halted;
|
|
166
160
|
private refetchInFlight;
|
|
167
|
-
private probeInFlight;
|
|
168
|
-
private probeRequested;
|
|
169
161
|
private resyncTimes;
|
|
170
162
|
/** Forward-gap events delivered while a resync is reconciling; drained
|
|
171
163
|
* after the bootstrap installs. Non-null exactly while reconciling. */
|
|
@@ -182,12 +174,10 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
182
174
|
private disposed;
|
|
183
175
|
private hiddenSince;
|
|
184
176
|
private hiddenSocketFailed;
|
|
185
|
-
private beaconedWhileDormant;
|
|
186
177
|
private backgroundTickTimer;
|
|
187
178
|
private lastTickAt;
|
|
188
179
|
private catchupSlot;
|
|
189
|
-
private
|
|
190
|
-
private connectReplyTimer;
|
|
180
|
+
private wakeReplyTimer;
|
|
191
181
|
private socketCreatedHidden;
|
|
192
182
|
private socketOpenedAt;
|
|
193
183
|
private candidate;
|
|
@@ -200,8 +190,7 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
200
190
|
private stallCoveredUntil;
|
|
201
191
|
private visibleSinceMono;
|
|
202
192
|
private readonly counters;
|
|
203
|
-
|
|
204
|
-
/** Where the live socket goes: the hub's URL, or the app's own. */
|
|
193
|
+
/** The hub socket's URL. */
|
|
205
194
|
private readonly socketUrl;
|
|
206
195
|
/** The live hub socket answered our `connect`. */
|
|
207
196
|
private hubAcked;
|
|
@@ -256,7 +245,6 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
256
245
|
hasUnsafeWork(): boolean;
|
|
257
246
|
hasUnresolvedFailures(): boolean;
|
|
258
247
|
dismissFailure(eventGuid: string): void;
|
|
259
|
-
refreshConnectionForBuild(): void;
|
|
260
248
|
state(): SyncClientState;
|
|
261
249
|
subscribe(listener: (state: SyncClientState) => void): () => void;
|
|
262
250
|
private installRuntimeListeners;
|
|
@@ -298,11 +286,12 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
298
286
|
private armRollover;
|
|
299
287
|
private rolloverDelayMs;
|
|
300
288
|
/** Make-before-break, as notes' document sockets do: a replacement connects
|
|
301
|
-
* while the live socket keeps serving
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
* keeps serving until the
|
|
289
|
+
* while the live socket keeps serving hints, and takes over when the hub
|
|
290
|
+
* acks its connect. Nothing the user sees changes, even with an edit
|
|
291
|
+
* unsent. The replacement's handshake re-runs the hub's identity check; a
|
|
292
|
+
* 4403 asks the app whether the session is gone, as on the live socket. If
|
|
293
|
+
* it fails, the live socket keeps serving until the hub's age cap closes it
|
|
294
|
+
* (1012). */
|
|
306
295
|
private startRollover;
|
|
307
296
|
private promoteCandidate;
|
|
308
297
|
/** Abandons a rollover's replacement; `failure` logs why and tries again
|
|
@@ -315,11 +304,10 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
315
304
|
private cancelBackgroundTick;
|
|
316
305
|
private backgroundTick;
|
|
317
306
|
private unsettledPending;
|
|
318
|
-
private postPendingOverHttp;
|
|
319
307
|
/** The HTTP catch-up (review S5): one slot, a return aborts any other
|
|
320
|
-
* kind in flight, every kind gives up after 15 s.
|
|
321
|
-
*
|
|
322
|
-
*
|
|
308
|
+
* kind in flight, every kind gives up after 15 s. A request that finds the
|
|
309
|
+
* slot busy queues one more catch-up to start when it frees (one in
|
|
310
|
+
* flight, at most one queued), and the outcome feeds the app-request
|
|
323
311
|
* ladder. */
|
|
324
312
|
private runCatchup;
|
|
325
313
|
private withTimeout;
|
|
@@ -333,21 +321,15 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
333
321
|
/** The first failure of a return, before sync is back, retries quickly
|
|
334
322
|
* (once per return); anything else takes the ladder. */
|
|
335
323
|
private takeQuickRetry;
|
|
324
|
+
/** The 1-2-4-8-16-30 s ladder's next step after `attempts` failures, or
|
|
325
|
+
* 250 ms for a return's first failure. Both the hub socket and app
|
|
326
|
+
* requests retry on it, each with its own count. */
|
|
327
|
+
private nextRetryDelayMs;
|
|
336
328
|
private scheduleReconnect;
|
|
337
|
-
/** One HTTP round trip while the visible socket is down: delivers pending
|
|
338
|
-
* events (`postEvents`), then catches up — which applies their echoes, so
|
|
339
|
-
* the writes confirm — and doubles as the session probe (an expired
|
|
340
|
-
* session halts through the auth state). A WebSocket handshake can be
|
|
341
|
-
* stuck for minutes behind another one in the browser's per-IP queue while
|
|
342
|
-
* HTTP works at once (notes, 2026-10-01), so writes must not wait for it. */
|
|
343
|
-
private probeSession;
|
|
344
329
|
private startOutage;
|
|
345
330
|
/** ERROR only after OUTAGE_ESCALATE_MS of visible, on-time outage; re-armed
|
|
346
331
|
* on each return so an outage that began hidden still escalates (S3). */
|
|
347
332
|
private armEscalation;
|
|
348
|
-
private dispatchMessage;
|
|
349
|
-
private handleMessage;
|
|
350
|
-
private handleSocketCatchup;
|
|
351
333
|
/** Returns false when a forward gap prevented application. */
|
|
352
334
|
private handleServerEvent;
|
|
353
335
|
private handleRejection;
|
|
@@ -361,38 +343,28 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
361
343
|
/** On return: a verdict needs 60 s of visible time (review B2). */
|
|
362
344
|
private rearmFailureTimers;
|
|
363
345
|
private failUnconfirmed;
|
|
364
|
-
/** Logs and closes the open outage, if any
|
|
365
|
-
*
|
|
366
|
-
* succeeds without a socket after the outage escalated to ERROR. A hidden
|
|
367
|
-
* page stops attempting its socket after one hidden failure, so an
|
|
368
|
-
* escalated outage that went hidden stayed open, its ERROR unanswered by
|
|
369
|
-
* any recovery line, until the page was next shown (notes 2026-11-16,
|
|
370
|
-
* task a0f43dda: a tab left hidden for 9+ hours). The page is current
|
|
371
|
-
* then; the return reconnects as usual and a failure there opens a new
|
|
372
|
-
* outage. An outage that never escalated keeps its single log on return,
|
|
373
|
-
* which reports the whole hidden spell. */
|
|
346
|
+
/** Logs and closes the open outage, if any, once sync is established
|
|
347
|
+
* again. */
|
|
374
348
|
private endOutage;
|
|
375
349
|
private onSyncEstablished;
|
|
376
350
|
private requestReload;
|
|
377
351
|
private resyncFromServer;
|
|
378
|
-
/** Applies the events delivered while the bootstrap was in flight
|
|
379
|
-
*
|
|
380
|
-
* where a resync under a live stream converges; a hole (
|
|
381
|
-
*
|
|
382
|
-
* path instead. */
|
|
352
|
+
/** Applies the events delivered while the bootstrap was in flight (hint
|
|
353
|
+
* catch-ups, POST frames). Contiguous with the install point, they are
|
|
354
|
+
* where a resync under a live stream converges; a hole (an answer that
|
|
355
|
+
* skipped ahead, buffer overflow) schedules a fresh resync via the normal
|
|
356
|
+
* gap path instead. */
|
|
383
357
|
private drainAfterResync;
|
|
384
358
|
/** A stall episode ends only on proven convergence: a resync whose drain
|
|
385
|
-
* scheduled nothing further, or a complete
|
|
359
|
+
* scheduled nothing further, or a complete catch-up under the hub's ack. A successful
|
|
386
360
|
* reconcile alone is not convergence — in a chronic diverge-reconverge
|
|
387
361
|
* cycle every reconcile succeeds. */
|
|
388
362
|
private endResyncEpisode;
|
|
389
363
|
private scheduleResyncRetry;
|
|
390
364
|
private scheduleResyncFailureRetry;
|
|
391
365
|
private cancelResyncFailureRetry;
|
|
392
|
-
private sendConnect;
|
|
393
366
|
private connectMessage;
|
|
394
367
|
private sendRaw;
|
|
395
|
-
private trySend;
|
|
396
368
|
private flushViaBeacon;
|
|
397
369
|
private updateConnectedState;
|
|
398
370
|
private updatePendingState;
|
|
@@ -402,11 +374,11 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
402
374
|
private halt;
|
|
403
375
|
private clearConnectionTimers;
|
|
404
376
|
private clearAllTimers;
|
|
405
|
-
/** Live: the socket is open
|
|
406
|
-
*
|
|
407
|
-
*
|
|
377
|
+
/** Live: the socket is open, the hub answered our `connect` and the last
|
|
378
|
+
* app request succeeded (a pong overdue replaces the socket, so an open one
|
|
379
|
+
* has been heard from recently). */
|
|
408
380
|
private isLive;
|
|
409
|
-
/**
|
|
381
|
+
/** Is this close a quiet reconnect? 1012, 1013 or 4408 on a
|
|
410
382
|
* socket the hub had acked, and fewer than HUB_QUIET_CLOSE_BURST such
|
|
411
383
|
* closes in the last minute; anything else takes the outage path. */
|
|
412
384
|
private takeQuietHubClose;
|
|
@@ -415,10 +387,10 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
415
387
|
/** Established needs a complete catch-up that began under the current ack
|
|
416
388
|
* (review 3.60.1, finding 3). */
|
|
417
389
|
private establishesUnder;
|
|
418
|
-
/**
|
|
390
|
+
/** The state: live as `connected`/`syncing`; otherwise a countdown
|
|
419
391
|
* to whichever ladder (hub socket or app request) retries first; otherwise
|
|
420
392
|
* `connecting`, or `disconnected` once something has failed. */
|
|
421
|
-
private
|
|
393
|
+
private refreshState;
|
|
422
394
|
private handleHubMessage;
|
|
423
395
|
/** The hub routes hints to this socket from now on. Established still
|
|
424
396
|
* needs a catch-up that began after this (design §5.4); one queues behind
|
|
@@ -456,7 +428,7 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
456
428
|
/** Re-send paths (established, resync, return): post the unsettled edits
|
|
457
429
|
* unless a POST is already in flight. */
|
|
458
430
|
private kickPost;
|
|
459
|
-
/**
|
|
431
|
+
/** The mutation path: every unsettled edit in one POST, one POST in
|
|
460
432
|
* flight per tab. An edit submitted meanwhile posts after it succeeds; a
|
|
461
433
|
* failure leaves the retry to the app-request ladder. */
|
|
462
434
|
private runPost;
|
|
@@ -465,8 +437,7 @@ export declare class SyncClient<B, C extends EventBody, S extends EventBody, Sum
|
|
|
465
437
|
* carries the own events in order with any writer that interleaved, so no
|
|
466
438
|
* forward gap trips a resync. Then the outcomes: frames confirm their
|
|
467
439
|
* pending entry by GUID even at or below the tab's sequence (a resync may
|
|
468
|
-
* have moved it past them, review round 2 B1)
|
|
469
|
-
* the socket. */
|
|
440
|
+
* have moved it past them, review round 2 B1). */
|
|
470
441
|
private applyPostResponse;
|
|
471
442
|
private detachSocket;
|
|
472
443
|
private abortable;
|