@steve31415/baselib 3.59.1 → 3.60.1
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 +5 -2
- package/dist/sync/session.d.ts +35 -1
- package/dist/sync/session.js +56 -4
- package/dist/sync/types.d.ts +29 -0
- package/dist/sync-browser/client.d.ts +120 -8
- package/dist/sync-browser/client.js +569 -36
- package/dist/sync-browser/hub.d.ts +33 -0
- package/dist/sync-browser/hub.js +49 -0
- package/dist/sync-browser/index.d.ts +1 -0
- package/dist/sync-browser/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The client's ping period; the hub closes a socket silent for 180 s. */
|
|
2
|
+
export declare const HUB_PING_INTERVAL_MS = 30000;
|
|
3
|
+
/** Two missed pongs: a ping unanswered and nothing heard for this long
|
|
4
|
+
* replaces the socket (any frame counts as life, as in Radar's client). */
|
|
5
|
+
export declare const HUB_PONG_TIMEOUT_MS: number;
|
|
6
|
+
/** While visible, one HTTP catch-up at least this often, whatever the hub
|
|
7
|
+
* socket's state: the bound on a lost hint (design §5.5, review C-B1). */
|
|
8
|
+
export declare const HUB_FLOOR_MS: number;
|
|
9
|
+
/** A `sync_available` hint runs a catch-up at once; further hints within
|
|
10
|
+
* this window fold into one trailing catch-up. */
|
|
11
|
+
export declare const HUB_HINT_DEBOUNCE_MS = 500;
|
|
12
|
+
/** The hub's auth check was unavailable ("try again later"): a quiet
|
|
13
|
+
* reconnect, like 1012. */
|
|
14
|
+
export declare const CLOSE_TRY_AGAIN_LATER = 1013;
|
|
15
|
+
/** The hub heard nothing on the socket for 180 s: a quiet reconnect. */
|
|
16
|
+
export declare const CLOSE_HUB_IDLE = 4408;
|
|
17
|
+
/** `ws(s)://<hub host>/api/ws?app=<app>`, the scheme following the hub URL's. */
|
|
18
|
+
export declare function hubSocketUrl(hubUrl: string, app: string): string;
|
|
19
|
+
/** What a hub frame asks of the client. Unknown frames and fields are
|
|
20
|
+
* ignored (hub versions overlap during a hub deploy), and so is a hint for
|
|
21
|
+
* another app. `pong` and anything unknown only count as signs of life. */
|
|
22
|
+
export type HubFrame = {
|
|
23
|
+
kind: 'ack';
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'sync_available';
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'build_changed';
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'life';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'unparseable';
|
|
32
|
+
};
|
|
33
|
+
export declare function parseHubFrame(raw: string, app: string): HubFrame;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The sync client's hub mode, the parts that need none of its state
|
|
2
|
+
// (connection hub design ~/migration/research/connection-hub-design-2026-10-30.md
|
|
3
|
+
// §5.4–§5.5, as amended by §12, §14.4 and the 2026-11-03 socket age cap).
|
|
4
|
+
// The client itself (client.ts) branches on hub mode at a few seams; these
|
|
5
|
+
// are the hub's wire facts it relies on.
|
|
6
|
+
/** The client's ping period; the hub closes a socket silent for 180 s. */
|
|
7
|
+
export const HUB_PING_INTERVAL_MS = 30_000;
|
|
8
|
+
/** Two missed pongs: a ping unanswered and nothing heard for this long
|
|
9
|
+
* replaces the socket (any frame counts as life, as in Radar's client). */
|
|
10
|
+
export const HUB_PONG_TIMEOUT_MS = 2 * HUB_PING_INTERVAL_MS;
|
|
11
|
+
/** While visible, one HTTP catch-up at least this often, whatever the hub
|
|
12
|
+
* socket's state: the bound on a lost hint (design §5.5, review C-B1). */
|
|
13
|
+
export const HUB_FLOOR_MS = 2 * 60 * 1000;
|
|
14
|
+
/** A `sync_available` hint runs a catch-up at once; further hints within
|
|
15
|
+
* this window fold into one trailing catch-up. */
|
|
16
|
+
export const HUB_HINT_DEBOUNCE_MS = 500;
|
|
17
|
+
/** The hub's auth check was unavailable ("try again later"): a quiet
|
|
18
|
+
* reconnect, like 1012. */
|
|
19
|
+
export const CLOSE_TRY_AGAIN_LATER = 1013;
|
|
20
|
+
/** The hub heard nothing on the socket for 180 s: a quiet reconnect. */
|
|
21
|
+
export const CLOSE_HUB_IDLE = 4408;
|
|
22
|
+
/** `ws(s)://<hub host>/api/ws?app=<app>`, the scheme following the hub URL's. */
|
|
23
|
+
export function hubSocketUrl(hubUrl, app) {
|
|
24
|
+
const url = new URL('/api/ws', hubUrl);
|
|
25
|
+
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
26
|
+
url.searchParams.set('app', app);
|
|
27
|
+
return url.toString();
|
|
28
|
+
}
|
|
29
|
+
export function parseHubFrame(raw, app) {
|
|
30
|
+
let frame;
|
|
31
|
+
try {
|
|
32
|
+
frame = JSON.parse(raw);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { kind: 'unparseable' };
|
|
36
|
+
}
|
|
37
|
+
if (frame === null || typeof frame !== 'object')
|
|
38
|
+
return { kind: 'life' };
|
|
39
|
+
const { type, app: frameApp, kind } = frame;
|
|
40
|
+
if (type === 'ack')
|
|
41
|
+
return { kind: 'ack' };
|
|
42
|
+
if (type !== 'hint' || (frameApp !== undefined && frameApp !== app))
|
|
43
|
+
return { kind: 'life' };
|
|
44
|
+
if (kind === 'sync_available')
|
|
45
|
+
return { kind: 'sync_available' };
|
|
46
|
+
if (kind === 'build_changed')
|
|
47
|
+
return { kind: 'build_changed' };
|
|
48
|
+
return { kind: 'life' };
|
|
49
|
+
}
|
package/package.json
CHANGED