@pgxsinkit/client 0.1.53 → 0.2.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 +22 -0
- package/dist/adoption.d.ts +118 -0
- package/dist/adoption.d.ts.map +1 -0
- package/dist/boot-report.d.ts +54 -15
- package/dist/boot-report.d.ts.map +1 -1
- package/dist/convergence.d.ts +2 -1
- package/dist/convergence.d.ts.map +1 -1
- package/dist/export-store.d.ts +1 -1
- package/dist/export-store.d.ts.map +1 -1
- package/dist/index.d.ts +270 -52
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4492 -1511
- package/dist/index.js.map +34 -24
- package/dist/live-rows-sql.d.ts +1 -1
- package/dist/local-store.d.ts +16 -31
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-tables.d.ts +4 -4
- package/dist/mutation.d.ts +12 -15
- package/dist/mutation.d.ts.map +1 -1
- package/dist/opfs-effects.d.ts +51 -0
- package/dist/opfs-effects.d.ts.map +1 -0
- package/dist/placement-probe.d.ts +75 -0
- package/dist/placement-probe.d.ts.map +1 -0
- package/dist/schema.d.ts +11 -16
- package/dist/schema.d.ts.map +1 -1
- package/dist/store-boot.d.ts +77 -0
- package/dist/store-boot.d.ts.map +1 -0
- package/dist/store-lifecycle.d.ts +153 -0
- package/dist/store-lifecycle.d.ts.map +1 -0
- package/dist/store-meta.d.ts +190 -0
- package/dist/store-meta.d.ts.map +1 -0
- package/dist/store-path.d.ts +77 -7
- package/dist/store-path.d.ts.map +1 -1
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/shape-inbox.d.ts +1 -1
- package/dist/sync/types.d.ts +3 -3
- package/dist/testing.js.map +3 -3
- package/dist/worker/attach-sync-client.d.ts +235 -12
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +138 -22
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/election-coordinator.d.ts +95 -0
- package/dist/worker/election-coordinator.d.ts.map +1 -0
- package/dist/worker/engine-control.d.ts +265 -0
- package/dist/worker/engine-control.d.ts.map +1 -0
- package/dist/worker/engine-router.d.ts +75 -0
- package/dist/worker/engine-router.d.ts.map +1 -0
- package/dist/worker/live-query-manager.d.ts.map +1 -1
- package/dist/worker/protocol.d.ts +15 -10
- package/dist/worker/protocol.d.ts.map +1 -1
- package/dist/worker/sw-placement.d.ts +37 -0
- package/dist/worker/sw-placement.d.ts.map +1 -0
- package/package.json +4 -3
- package/skills/core/SKILL.md +15 -12
- package/skills/operating/SKILL.md +103 -46
- package/src/adoption.ts +275 -0
- package/src/boot-report.ts +70 -17
- package/src/convergence.ts +2 -1
- package/src/export-store.ts +1 -1
- package/src/index.ts +1109 -115
- package/src/live-rows-sql.ts +1 -1
- package/src/local-store.ts +18 -40
- package/src/local-tables.ts +2 -2
- package/src/mutation.ts +67 -49
- package/src/mutations-api.ts +3 -3
- package/src/opfs-effects.ts +160 -0
- package/src/placement-probe.ts +168 -0
- package/src/schema.ts +17 -22
- package/src/store-boot.ts +343 -0
- package/src/store-lifecycle.ts +227 -0
- package/src/store-meta.ts +459 -0
- package/src/store-path.ts +197 -22
- package/src/sync/apply.ts +63 -63
- package/src/sync/index.ts +2 -2
- package/src/sync/shape-inbox.ts +1 -1
- package/src/sync/types.ts +3 -3
- package/src/testing.ts +2 -2
- package/src/worker/attach-sync-client.ts +1556 -97
- package/src/worker/define-sync-worker.ts +723 -73
- package/src/worker/election-coordinator.ts +462 -0
- package/src/worker/engine-control.ts +379 -0
- package/src/worker/engine-router.ts +355 -0
- package/src/worker/live-query-manager.ts +4 -1
- package/src/worker/protocol.ts +13 -10
- package/src/worker/sw-placement.ts +64 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type EngineIdentity, type ExecutionLimitConfig } from "./engine-control";
|
|
2
|
+
/**
|
|
3
|
+
* The namespaced key under which every ADR-0049 control message rides the tab↔SharedWorker transport, so the
|
|
4
|
+
* control plane coexists with the data-path bridge envelope (`protocol.ts`) without any change to it. The tab
|
|
5
|
+
* side (step 7) sends/reads the identical envelope.
|
|
6
|
+
*/
|
|
7
|
+
export { ENGINE_CONTROL_ENVELOPE_KEY } from "./engine-control";
|
|
8
|
+
/**
|
|
9
|
+
* The minimal MessagePort-shaped transport the router needs — the intersection of a real `MessagePort`, a
|
|
10
|
+
* `SharedWorker` connection port, and the pipe ends it mints. Modeled on `protocol.ts`'s `BridgePort` (kept
|
|
11
|
+
* local, not imported, because the router's transfer list is plain `unknown[]` and it never `close()`s a tab
|
|
12
|
+
* port). Injected everywhere so the router is exercised with plain recording ports (no worker) in tests.
|
|
13
|
+
*/
|
|
14
|
+
export interface RouterPort {
|
|
15
|
+
postMessage: (message: unknown, transfer?: unknown[]) => void;
|
|
16
|
+
addEventListener: (type: "message", listener: (event: {
|
|
17
|
+
data: unknown;
|
|
18
|
+
}) => void) => void;
|
|
19
|
+
removeEventListener: (type: "message", listener: (event: {
|
|
20
|
+
data: unknown;
|
|
21
|
+
}) => void) => void;
|
|
22
|
+
start?: () => void;
|
|
23
|
+
}
|
|
24
|
+
/** The setTimeout/clearTimeout pair the probe loop schedules on — injectable for deterministic tests. */
|
|
25
|
+
export interface RouterTimers {
|
|
26
|
+
setTimeout(fn: () => void, ms: number): unknown;
|
|
27
|
+
clearTimeout(handle: unknown): void;
|
|
28
|
+
}
|
|
29
|
+
export interface EngineRouterOptions {
|
|
30
|
+
/** The opaque id of THIS SharedWorker instance — scopes every minted {@link EngineIdentity}'s generation. */
|
|
31
|
+
swInstanceId: string;
|
|
32
|
+
/**
|
|
33
|
+
* Engine-construction execution limit (`undefined`/absent `maxDispatchMs` = DISABLED, ADR D5). The router
|
|
34
|
+
* only FORWARDS tab-reported overdue dispatches into control-channel probes when enabled; the verdict
|
|
35
|
+
* threshold is {@link probeMissThreshold}. Disabled → overdue reports are ignored entirely.
|
|
36
|
+
*/
|
|
37
|
+
executionLimit?: ExecutionLimitConfig;
|
|
38
|
+
/** Consecutive unanswered probe pings before an engine-loss verdict (default 3). */
|
|
39
|
+
probeMissThreshold?: number;
|
|
40
|
+
/** Injectable pipe factory (default `() => new MessageChannel()`) so tests can observe both minted ends. */
|
|
41
|
+
createPipe?: () => {
|
|
42
|
+
port1: RouterPort;
|
|
43
|
+
port2: RouterPort;
|
|
44
|
+
};
|
|
45
|
+
/** Injectable timers for probe scheduling (default `globalThis`) for deterministic tests. */
|
|
46
|
+
timers?: RouterTimers;
|
|
47
|
+
/** Milliseconds between probe pings once a dispatch is reported overdue (default 2000). */
|
|
48
|
+
probeIntervalMs?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface EngineRouter {
|
|
51
|
+
/**
|
|
52
|
+
* Register a tab's bridge port. Returns an unregister fn. If an engine is CURRENT and already ready, this
|
|
53
|
+
* late joiner is piped IMMEDIATELY; otherwise it is piped when the current engine's `engine-ready` fans out.
|
|
54
|
+
*/
|
|
55
|
+
attachTab(tabPort: RouterPort): () => void;
|
|
56
|
+
/**
|
|
57
|
+
* tab→SW: the leader coordinator announces a fresh engine control channel. Stamps the next
|
|
58
|
+
* {@link EngineIdentity} ({@link mintEngineIdentity}), stores the control channel, and returns the identity.
|
|
59
|
+
* On the engine's `engine-ready` for THIS identity it pipes every attached tab. Any prior engine's control
|
|
60
|
+
* listener/probe is cleared first (this does not itself fan a notice).
|
|
61
|
+
*/
|
|
62
|
+
announceEngine(controlPort: RouterPort): EngineIdentity;
|
|
63
|
+
/**
|
|
64
|
+
* Fan a relocation notice to every tab: `leader-granted` (untagged) or `engine-retiring` (tagged with the
|
|
65
|
+
* retired identity). BOTH clear the current identity + control channel. Engine-loss verdicts fan
|
|
66
|
+
* `engine-retiring` internally the same way.
|
|
67
|
+
*/
|
|
68
|
+
openHandoff(reason: "leader-granted" | "engine-retiring"): void;
|
|
69
|
+
/** The current identity, or `undefined` before the first announce / while relocating. */
|
|
70
|
+
currentIdentity(): EngineIdentity | undefined;
|
|
71
|
+
/** Total attached-tab count (used later for destroy peer-refusal). */
|
|
72
|
+
tabCount(): number;
|
|
73
|
+
}
|
|
74
|
+
export declare function createEngineRouter(options: EngineRouterOptions): EngineRouter;
|
|
75
|
+
//# sourceMappingURL=engine-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-router.d.ts","sourceRoot":"","sources":["../../src/worker/engine-router.ts"],"names":[],"mappings":"AAqBA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAE1B,MAAM,kBAAkB,CAAC;AAE1B;;;;GAIG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC9D,gBAAgB,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,KAAK,IAAI,CAAC;IAC1F,mBAAmB,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,KAAK,IAAI,CAAC;IAC7F,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,yGAAyG;AACzG,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAChD,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,mBAAmB;IAClC,6GAA6G;IAC7G,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,oFAAoF;IACpF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,4GAA4G;IAC5G,UAAU,CAAC,EAAE,MAAM;QAAE,KAAK,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,CAAC;IAC5D,6FAA6F;IAC7F,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,2FAA2F;IAC3F,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,IAAI,CAAC;IAC3C;;;;;OAKG;IACH,cAAc,CAAC,WAAW,EAAE,UAAU,GAAG,cAAc,CAAC;IACxD;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,IAAI,CAAC;IAChE,yFAAyF;IACzF,eAAe,IAAI,cAAc,GAAG,SAAS,CAAC;IAC9C,sEAAsE;IACtE,QAAQ,IAAI,MAAM,CAAC;CACpB;AAgBD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CA+O7E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-query-manager.d.ts","sourceRoot":"","sources":["../../src/worker/live-query-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"live-query-manager.d.ts","sourceRoot":"","sources":["../../src/worker/live-query-manager.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,aAAa,EAA+B,MAAM,2BAA2B,CAAC;AAM5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnC,8GAA8G;AAC9G,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;AAE5D,sGAAsG;AACtG,MAAM,WAAW,cAAc;IAC7B,8GAA8G;IAC9G,cAAc,CAAC,IAAI,EAAE,SAAS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CAmXnF"}
|
|
@@ -6,7 +6,8 @@ export declare const BRIDGE_PROTOCOL_VERSION: 1;
|
|
|
6
6
|
/**
|
|
7
7
|
* A structured-clone transferable (an `ArrayBuffer`, a `MessagePort`, …). The library carries no DOM lib
|
|
8
8
|
* dependency (like the convergence triggers), so this is the toolkit's own name for the type a future
|
|
9
|
-
* columnar codec would hand to `postMessage`'s transfer list.
|
|
9
|
+
* columnar codec would hand to `postMessage`'s transfer list. The wire-format-1 identity codec
|
|
10
|
+
* ({@link BRIDGE_PROTOCOL_VERSION}) never produces one.
|
|
10
11
|
*/
|
|
11
12
|
export type BridgeTransferable = unknown;
|
|
12
13
|
/**
|
|
@@ -110,6 +111,10 @@ export interface AttachPayload {
|
|
|
110
111
|
* memory-store selection travels as this explicit field. Set only by the test lane; never by a browser tab.
|
|
111
112
|
*/
|
|
112
113
|
testStoreBackend?: "memory";
|
|
114
|
+
/** ADR-0049 D5: the tab's engine-construction limit, checked by the host before it acknowledges attach. */
|
|
115
|
+
executionLimit?: {
|
|
116
|
+
maxDispatchMs?: number;
|
|
117
|
+
};
|
|
113
118
|
/**
|
|
114
119
|
* Restore the store from a backup on THIS attach (ADR-0035 decision 6) — the worker-mode carrier of
|
|
115
120
|
* `createSyncClient`'s `restoreFrom`. Restore rides the FIRST attach (the boot attach): a `File`/`Blob`
|
|
@@ -268,9 +273,9 @@ export interface SubscribePayload {
|
|
|
268
273
|
params: unknown[];
|
|
269
274
|
/**
|
|
270
275
|
* The unique output aliases the worker wraps the query's columns under so it is safe to MATERIALISE
|
|
271
|
-
* (one per output column, in the compiled SQL's column order).
|
|
272
|
-
*
|
|
273
|
-
*
|
|
276
|
+
* (one per output column, in the compiled SQL's column order). When omitted, the worker leaves the SQL
|
|
277
|
+
* untouched and returns name-keyed rows; supply it for a JOIN with same-named columns, which
|
|
278
|
+
* `live.query`/`live.incrementalQuery` otherwise
|
|
274
279
|
* refuse to materialise (`column "title" specified more than once`). When present, result columns are
|
|
275
280
|
* the aliases, so {@link pkColumns} must name a PK by its alias.
|
|
276
281
|
*/
|
|
@@ -286,9 +291,8 @@ export interface SubscribePayload {
|
|
|
286
291
|
/**
|
|
287
292
|
* Per-subscription keep-alive hint (ms) for the worker's live-query manager (ADR-0040 decision 4): how long
|
|
288
293
|
* the shared registration should be retained after this subscription's last consumer leaves, so a matching
|
|
289
|
-
* resubscribe reuses it verbatim.
|
|
290
|
-
*
|
|
291
|
-
* means "no hint".
|
|
294
|
+
* resubscribe reuses it verbatim. When omitted, the worker falls back to
|
|
295
|
+
* `liveQueries.defaultKeepAliveMs`; absent means "no hint".
|
|
292
296
|
*/
|
|
293
297
|
keepAliveMs?: number;
|
|
294
298
|
}
|
|
@@ -410,9 +414,10 @@ export interface BridgeCodec {
|
|
|
410
414
|
decode: (payload: unknown) => unknown;
|
|
411
415
|
}
|
|
412
416
|
/**
|
|
413
|
-
* The
|
|
414
|
-
*
|
|
415
|
-
* only this object, never the message types or
|
|
417
|
+
* The identity codec, wire-format version 1 ({@link BRIDGE_PROTOCOL_VERSION}): the body IS the payload,
|
|
418
|
+
* and the transport's structured clone does the real copying. No transferables. The sole codec at this
|
|
419
|
+
* wire version — swapping in a columnar codec later touches only this object, never the message types or
|
|
420
|
+
* the router.
|
|
416
421
|
*/
|
|
417
422
|
export declare const identityCodec: BridgeCodec;
|
|
418
423
|
/** Build a wire envelope, running the payload through the codec. Returns the envelope + any transferables. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/worker/protocol.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,eAAO,MAAM,cAAc,EAAG,kBAA2B,CAAC;AAC1D,eAAO,MAAM,uBAAuB,EAAG,CAA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AQ,CAAC,EAAE,kBAAkB,EAAE,CAAA;KAAE,CAAC;IACpF,oFAAoF;IACpF,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;CACvC;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,WAG3B,CAAC;AAIF,8GAA8G;AAC9G,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,OAAO,EAChB,EAAE,CAAC,EAAE,MAAM,GACV;IAAE,QAAQ,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAU/D;AAED,mHAAmH;AACnH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,cAAc,CAOtE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,OAAO,EAChB,EAAE,CAAC,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,kBAAkB,EAAE,GAC9B,IAAI,CAQN"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type PlacementProbeResult } from "../placement-probe";
|
|
2
|
+
/**
|
|
3
|
+
* The SharedWorker's engine-home decision (ADR-0049 D1). `shared-worker` = the engine boots in this
|
|
4
|
+
* SharedWorker scope (granted OPFS sync access, SW-direct, election never engages); `elected-worker` = the
|
|
5
|
+
* SharedWorker is router-only and each tab elects a dedicated engine worker. `probeError` carries the probe's
|
|
6
|
+
* verbatim denial attribution when NOT granted (diagnostics only, never parsed). `swInstanceId` scopes every
|
|
7
|
+
* minted engine identity's generation (`engine-router.ts`).
|
|
8
|
+
*/
|
|
9
|
+
export interface SwPlacementResult {
|
|
10
|
+
engineHome: "shared-worker" | "elected-worker";
|
|
11
|
+
probeError?: string;
|
|
12
|
+
swInstanceId: string;
|
|
13
|
+
/**
|
|
14
|
+
* Present ONLY on a `shared-worker` home that is a CAPABILITY-ABSENCE fallback (ADR-0049 D1), not an OPFS
|
|
15
|
+
* grant: the platform cannot hold sync-access handles in any home, so the engine boots in-SharedWorker on the
|
|
16
|
+
* IDBFS backend with the registry-declared durability. Carries the verbatim probe attribution the fallback
|
|
17
|
+
* boot stamps into `storageFallbackReason` (decision 12). Absent on a granted `shared-worker` (SW-direct OPFS)
|
|
18
|
+
* and on `elected-worker` — an OPFS-capable elected home is not a fallback.
|
|
19
|
+
*/
|
|
20
|
+
storageFallbackReason?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Injectable seams so the decision is deterministic in a Bun unit test (no real OPFS, no real crypto needed). */
|
|
23
|
+
export interface DecideSwPlacementDeps {
|
|
24
|
+
/** The placement probe; defaults to {@link probeOpfsSyncAccess}. Injected in tests to drive both verdicts. */
|
|
25
|
+
probe?: () => Promise<PlacementProbeResult>;
|
|
26
|
+
/** Mint the opaque SharedWorker instance id; defaults to `crypto.randomUUID()`. Injected for deterministic tests. */
|
|
27
|
+
mintInstanceId?: () => string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Decide the SharedWorker's engine home ONCE at startup (ADR-0049 D1, invariant 8 — probe per boot, never
|
|
31
|
+
* cached). Runs the placement probe; a granted verdict places the engine in-scope (`shared-worker`), a denied
|
|
32
|
+
* one puts the SharedWorker in router-only mode (`elected-worker`) and carries the probe's verbatim error for
|
|
33
|
+
* diagnostics. This is a PURE decision — no engine boots and no router is created here; the bootstrap
|
|
34
|
+
* (`define-sync-worker.ts`) acts on the result.
|
|
35
|
+
*/
|
|
36
|
+
export declare function decideSwPlacement(deps?: DecideSwPlacementDeps): Promise<SwPlacementResult>;
|
|
37
|
+
//# sourceMappingURL=sw-placement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-placement.d.ts","sourceRoot":"","sources":["../../src/worker/sw-placement.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,oBAAoB,EAAuB,MAAM,oBAAoB,CAAC;AAEpF;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,eAAe,GAAG,gBAAgB,CAAC;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,kHAAkH;AAClH,MAAM,WAAW,qBAAqB;IACpC,8GAA8G;IAC9G,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC5C,qHAAqH;IACrH,cAAc,CAAC,EAAE,MAAM,MAAM,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAahG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"tanstack-intent"
|
|
6
6
|
],
|
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
"@electric-sql/client": "^1.5.24",
|
|
37
37
|
"@electric-sql/experimental": "^6.0.24",
|
|
38
38
|
"@electric-sql/pglite-tools": "0.4.4",
|
|
39
|
-
"@pgxsinkit/contracts": "0.
|
|
39
|
+
"@pgxsinkit/contracts": "0.2.0",
|
|
40
|
+
"@pgxsinkit/pglite-opfs-repacked": "0.2.0"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
|
-
"@electric-sql/pglite": "0.5.4",
|
|
43
|
+
"@electric-sql/pglite": ">=0.5.4-pgx.0 <0.5.5",
|
|
43
44
|
"drizzle-orm": "1.0.0-rc.4",
|
|
44
45
|
"zod": "^4.4.3"
|
|
45
46
|
},
|
package/skills/core/SKILL.md
CHANGED
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: core
|
|
15
15
|
library: "@pgxsinkit/client"
|
|
16
|
-
library_version: "0.
|
|
16
|
+
library_version: "0.2.0"
|
|
17
17
|
source: https://pgxsinkit.github.io/llms-full.txt
|
|
18
18
|
---
|
|
19
19
|
|
|
@@ -213,17 +213,20 @@ constraint that holds server-side also holds in PGlite.
|
|
|
213
213
|
## Naming the local store
|
|
214
214
|
|
|
215
215
|
`createSyncClient`/`createClientPGlite` take a **plain `storePath`** (e.g. `"my-app-store"`), never a
|
|
216
|
-
storage URL — the backend is derived
|
|
217
|
-
|
|
218
|
-
the
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
`
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
default
|
|
225
|
-
|
|
226
|
-
|
|
216
|
+
storage URL — the backend is derived, not named: a capability-proven browser engine home uses the
|
|
217
|
+
constant-handle OPFS-repacked backend, fixed worker mode and browser fallbacks use IndexedDB, and bun/Node
|
|
218
|
+
uses the filesystem; anything containing `://` throws `InvalidStorePathError`. Memory-backed stores are
|
|
219
|
+
deliberately not expressible in the production API (pgxsinkit's retention + journal durability assume a
|
|
220
|
+
persisted store): in TESTS, spread `memoryStoreForTests("name")` from `@pgxsinkit/client/testing` into the
|
|
221
|
+
options; a caller-owned `pgliteInstance` that is provably non-persistent (a bare `new PGlite()`, or
|
|
222
|
+
`memory://`) is refused with `NonPersistentStoreError` unless a testing acknowledgment is spread alongside.
|
|
223
|
+
Separately from persistence, the store's flush **timing** is `durability`, declared once on the registry
|
|
224
|
+
(`storage.durability`, default `"relaxed"`) — never a per-open, per-tab, or minting-surface option. Its
|
|
225
|
+
physical behavior is backend-specific: idb detaches its whole-snapshot flush, while OPFS-repacked keeps the
|
|
226
|
+
host awaited but omits routine physical flushes. `"strict"` restores each backend's strict boundary. The
|
|
227
|
+
SharedWorker factory, capability-driven Safari/Chromium/Firefox engine placement, relocation outcomes,
|
|
228
|
+
adoption, destruction, write-latency rationale, and recovery windows live in the `operating` skill.
|
|
229
|
+
Backups, the SQL exports, and `restoreFrom` are there too.
|
|
227
230
|
|
|
228
231
|
## Where to look
|
|
229
232
|
|
|
@@ -7,13 +7,14 @@ description: >-
|
|
|
7
7
|
cadence (writes flush on enqueue; the interval is only a fallback), serverless edge cold starts and
|
|
8
8
|
warming, cache-control:no-store on a same-origin Electric shape proxy, the browser HTTP/2 connection
|
|
9
9
|
budget, the edge worker timeout vs Electric's long-poll, globalThis.__pgxsinkitDebug + the BootReport,
|
|
10
|
-
worker mode (defineSyncWorker/attachSyncClient —
|
|
11
|
-
|
|
12
|
-
storePath naming,
|
|
10
|
+
worker mode (defineSyncWorker/attachSyncClient — capability-driven Safari SharedWorker vs elected
|
|
11
|
+
Chromium/Firefox engine placement, factories, relocation outcomes, diagnostics, and the forwarded rail),
|
|
12
|
+
and the store lifecycle surface: storePath naming, backend-specific durability, adoption, supervised
|
|
13
|
+
destruction, exportStore/exportDiagnostics/exportData (+ drain guard), and restoreFrom.
|
|
13
14
|
metadata:
|
|
14
15
|
type: task
|
|
15
16
|
library: "@pgxsinkit/client"
|
|
16
|
-
library_version: "0.
|
|
17
|
+
library_version: "0.2.0"
|
|
17
18
|
source: https://pgxsinkit.github.io/start/operating-in-production/
|
|
18
19
|
---
|
|
19
20
|
|
|
@@ -96,18 +97,32 @@ no login screen to create ahead of, so START the mapped-store open at app bootst
|
|
|
96
97
|
memoised per userId so the provider's later open adopts it rather than opening a second instance. (Board
|
|
97
98
|
demo: `apps/board/src/board/store-registry.ts`, `store-prewarm.ts`.)
|
|
98
99
|
|
|
99
|
-
## Worker mode:
|
|
100
|
-
|
|
101
|
-
In a browser, prefer
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
100
|
+
## Worker mode: capability-placed off-thread engine (browser apps)
|
|
101
|
+
|
|
102
|
+
In a browser, prefer worker mode so PGlite, shape streams, journal machinery, and convergence leave the
|
|
103
|
+
main thread. The SharedWorker is always the communication centre. There is no placement option: where the
|
|
104
|
+
engine runs is a runtime capability decision. Under the default `storage.backend: "opfs"`, an
|
|
105
|
+
unconditional real synchronous-handle open at boot chooses the engine home: real macOS/iOS Safari
|
|
106
|
+
runs the OPFS-repacked engine directly in the SharedWorker; Chromium/Firefox elect one tab-spawned
|
|
107
|
+
dedicated engine worker through Web Locks. Playwright WebKitGTK denies the handle in both worker kinds and
|
|
108
|
+
exercises the capability fallback to idb (declared durability kept, `storageBackend: "idbfs"` +
|
|
109
|
+
`storageFallbackReason` on the BootReport). The one opt-out is `storage.backend: "idbfs"` on the registry:
|
|
110
|
+
no probe, no election, the engine boots in the SharedWorker on idb. `createSyncClient` remains the bun/Node
|
|
111
|
+
mode and the main-thread idb fallback where SharedWorker is missing.
|
|
112
|
+
|
|
113
|
+
**Two-file pattern.** One worker entry, bundled for both SharedWorker and dedicated Worker, calls
|
|
114
|
+
`defineSyncWorker({ registry, electricUrl, batchWriteUrl, … })` at module top level — no placement or
|
|
115
|
+
durability option (both are runtime/registry concerns); the registry is CODE, _imported_ by the worker
|
|
116
|
+
file, never cloned/serialized in. Give each store a stable SharedWorker name and always pass
|
|
117
|
+
`extendedLifetime: true` (Chromium 148+ grace period; ignore-safe elsewhere). The tab calls
|
|
118
|
+
`attachSyncClient({ worker, registry, getToken })`, where `worker` is a **factory**
|
|
119
|
+
(`worker: () => SharedWorker`), not an instance — a SharedWorker cannot be reconstructed from itself, and
|
|
120
|
+
the factory is what makes SharedWorker-death recovery a guarantee. The elected engine worker needs no
|
|
121
|
+
consumer wiring: the SharedWorker reports its own script URL and the winning tab constructs the engine as
|
|
122
|
+
`new Worker(reportedUrl, { type: "module" })`. Supply `createEngineWorker` ONLY as an override for entries
|
|
123
|
+
that cannot be reconstructed from their URL as a module worker (classic-script workers, `blob:`/`data:`
|
|
124
|
+
URLs, CSP); with no override and no derivable URL, attach fails with a typed error — never a silent
|
|
125
|
+
no-engine attach. The attached facade returns the same
|
|
111
126
|
client shape as `createSyncClient` (write API, one-shot Drizzle reads, live rows,
|
|
112
127
|
`ready`/`status`/`stop`) plus `notifyAuthChanged` and `setOnline`, proxied to the shared engine. One-shot
|
|
113
128
|
reads (`query`/`queryRow`/`queryRaw`/`queryRawRow`) compile on the tab and cross the bridge as ONE guarded
|
|
@@ -117,8 +132,10 @@ guarded here (the in-process unguarded escape hatch has no attach equivalent), a
|
|
|
117
132
|
`client.drizzle.transaction()` throws (no tab-local store). `ensureSynced` is proxied (additive,
|
|
118
133
|
idempotent); `isSynced` throws — it is a SYNCHRONOUS activation-started peek the tab's cached catch-up
|
|
119
134
|
readiness cannot answer (use `groupReady` for catch-up, `ensureSynced` to activate). Local
|
|
120
|
-
`pglite
|
|
121
|
-
|
|
135
|
+
`pglite` and `dropReadCache` are NOT proxied — there is no tab-local store and a cache rebuild is
|
|
136
|
+
engine-wide. `destroy()` IS proxied through a tab-side supervisor: it refuses peers with
|
|
137
|
+
`StoreDestroyRefusedError`, refuses owed journal rows unless `{ force: true }`, retires/closes the engine,
|
|
138
|
+
then runs a resumable deletion. The lazy lifecycle methods ARE proxied, but the engine is SHARED:
|
|
122
139
|
`desync(tableKey)` from one tab reverts the consistency group for EVERY attached tab (desync's group-wide
|
|
123
140
|
revert is engine-wide here — the footgun). For an ephemeral delivery window use `discardEphemeral(tableKey)`
|
|
124
141
|
instead — the scoped, multi-tab-safe finalize (drops the ephemeral rows, reverts to dormant, refuses a
|
|
@@ -129,10 +146,17 @@ attach client), it runs raw against the local store — bypasses the journal/ove
|
|
|
129
146
|
and never converges — so it is not an app-data read path. `replAdapter(client)` shapes it into the
|
|
130
147
|
`{ query, exec }` duck `@electric-sql/pglite-repl` needs (`client.pglite` stays unavailable). A worker file can bake multiple role variants and pick per attach via
|
|
131
148
|
`resolveRegistry(role)` + the tab's `role` (the board's admin/member registries; the spare needs it). The
|
|
132
|
-
worker entry can also pass the app-level schema prepare hooks `prepareLocalDbBeforeSchema` / `
|
|
149
|
+
worker entry can also pass the app-level schema prepare hooks `prepareLocalDbBeforeSchema` / `prepareLocalDbAfterSchema`
|
|
133
150
|
(app migrations, indexes, views) — same semantics as in-process, run in the worker around the registry schema
|
|
134
151
|
exec; they are worker-entry (not attach) options because a hook is a function and cannot cross the bridge.
|
|
135
152
|
|
|
153
|
+
**Identity switches do not wait for worker retirement.** Scope each worker identity by `storePath`; use a distinct,
|
|
154
|
+
stable SharedWorker name for each store. Multiple stores may remain alive concurrently. Detach/stop the old
|
|
155
|
+
client and immediately attach the new identity's worker/store — never wait for the old SharedWorker, elected
|
|
156
|
+
engine, provision expiry, or `extendedLifetime` grace period. In worker mode `stop()` detaches only this tab;
|
|
157
|
+
in-process mode it disposes live queries before closing that client's engine and store. The board's
|
|
158
|
+
`userId → storeId` registry and real-browser identity-switch lane demonstrate this guarantee.
|
|
159
|
+
|
|
136
160
|
**Auth stays tab-owned (ADR-0013).** The tab pushes `{accessToken, expiresAt}` at attach and on
|
|
137
161
|
`notifyAuthChanged`; the worker uses the cached token and sends a pull-request only when a request finds it
|
|
138
162
|
near expiry (any tab answers via `getToken`, first wins). The worker NEVER refreshes — exactly one refresher,
|
|
@@ -141,6 +165,9 @@ so GoTrue refresh-token reuse detection can't be tripped by a second client.
|
|
|
141
165
|
**Boot: spare-as-worker + internal prefetch overlap.** The spare store (see above) becomes a pre-spawned
|
|
142
166
|
schemaless worker at the login screen (create + initdb off every thread that matters); the userId→storeId
|
|
143
167
|
registry stays tab-side in localStorage so binding resolves before attach (SharedWorker naming needs it).
|
|
168
|
+
Call `provisionSyncWorker` with the same `worker` factory as attach; an elected
|
|
169
|
+
Chromium/Firefox pre-open shares the tab's one election coordinator and auto-derives the engine from the
|
|
170
|
+
SharedWorker's own script URL (override with `createEngineWorker` only for non-module/underivable entries).
|
|
144
171
|
Claim = bind id, attach, push config + token. On a PROVABLY-fresh claimed store, pass
|
|
145
172
|
`attachSyncClient({ freshStore: true })` (never for a mapped/returning store) and the worker overlaps the
|
|
146
173
|
shape catch-up with schema/journal/store-version recovery — far-user boot bounded by `max(create+schema,
|
|
@@ -163,6 +190,16 @@ shows nothing" is worker mode working as designed, not an absence of requests. I
|
|
|
163
190
|
rejections surface only there). Full model:
|
|
164
191
|
<https://pgxsinkit.github.io/concepts/worker-mode/>.
|
|
165
192
|
|
|
193
|
+
**Placement and relocation diagnostics.** Pull `client.bootReport()` and inspect `storageBackend`
|
|
194
|
+
(`opfs-repacked`/`idbfs`/`filesystem`/`memory`), `engineHome`
|
|
195
|
+
(`shared-worker`/`elected-worker`/`in-process`), and `storageFallbackReason`; never user-agent-sniff the
|
|
196
|
+
backend. During elected-engine handoff, `EngineRelocatedError("not-dispatched")` is safe to retry, while
|
|
197
|
+
`"unknown"` means a dispatched mutation may already be journaled — inspect/reconcile, never retry blindly.
|
|
198
|
+
The opt-in `executionLimit` is disabled by default — no finite worst-case query duration exists and the
|
|
199
|
+
limit converts slow to terminated by policy, so enabling it must be a deliberate choice. It is
|
|
200
|
+
elected-only, and must match between the worker entry and every tab (`ExecutionLimitMismatchError`
|
|
201
|
+
otherwise); SW-direct Safari rejects it as unsupported.
|
|
202
|
+
|
|
166
203
|
## Live-query manager: dedup + keep-alive (ADR-0040)
|
|
167
204
|
|
|
168
205
|
Every reactive read (`useLiveDrizzleRows`/`useLiveQueryRaw`/`subscribeLiveRows`) is a **local SQL live
|
|
@@ -193,27 +230,39 @@ subscriber + row counts, setup/refresh timings, retention state — safe to log.
|
|
|
193
230
|
|
|
194
231
|
## Store naming, backups, and restore (ADR-0035/0036)
|
|
195
232
|
|
|
196
|
-
**Stores are named by a plain `storePath`, never a storage URL.** The backend is derived
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
`
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
`
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
233
|
+
**Stores are named by a plain `storePath`, never a storage URL.** The backend is derived, not named — a
|
|
234
|
+
capability-proven browser engine home uses OPFS-repacked; fixed worker mode, a denied engine home, and the
|
|
235
|
+
main-thread browser fallback use IndexedDB; bun/Node uses the filesystem. Anything containing `://` throws
|
|
236
|
+
`InvalidStorePathError` — do not "fix" that by re-adding a scheme, drop it. Memory-backed stores are
|
|
237
|
+
deliberately unreachable from the production API (durability semantics assume a persisted store): tests spread
|
|
238
|
+
`memoryStoreForTests("name")` from `@pgxsinkit/client/testing`, and a caller-owned
|
|
239
|
+
`pgliteInstance`/`precreatedPglite` that is provably non-persistent (`dataDir` undefined — a bare
|
|
240
|
+
`new PGlite()` — or `memory://`) is refused with `NonPersistentStoreError` unless `testStoreAcknowledgment()`
|
|
241
|
+
is spread alongside. For browser store GC, get the IndexedDB name from
|
|
242
|
+
`storeIndexedDbDatabaseName(storePath)` — never assemble `/pglite/…` yourself.
|
|
243
|
+
|
|
244
|
+
**Relaxed durability is the default.** It is declared once, on the registry
|
|
245
|
+
(`SyncRegistryDefinition.storage.durability`, `"relaxed" | "strict"`) — never on a minting surface,
|
|
246
|
+
worker entry, or attach site, because durability follows the data, and one declaration binds every open
|
|
247
|
+
of every store minted from that registry. Its physical behavior is
|
|
248
|
+
backend-specific. On idb, relaxed returns before the whole-datadir snapshot flush and schedules it
|
|
249
|
+
asynchronously; strict pays that synchronous snapshot (~100–200ms per optimistic mutation). On
|
|
250
|
+
OPFS-repacked the host still awaits every sync: relaxed asserts VFS health and runs any due deferred repack
|
|
251
|
+
without an ordinary physical flush, while strict flushes arena data before metadata. Initialization,
|
|
252
|
+
repack activation, and open-state close use strict ordering in either OPFS mode. The resolved value is
|
|
253
|
+
stamped on the `boot pglite.create` rail line.
|
|
254
|
+
|
|
255
|
+
**The idb loss window.** On the idb backend the store is an in-memory FS with debounced whole-snapshot writes to
|
|
256
|
+
IndexedDB, so `relaxed`'s window is every write since the last COMPLETED snapshot (a whole-FS debounce). The
|
|
257
|
+
risk lands only on a crash before BOTH the journal rows reach the write API (~hundreds of ms after enqueue)
|
|
258
|
+
AND the scheduled snapshot lands — and synced tables are server-recoverable by construction, so only consumer
|
|
259
|
+
**local-only** tables carry real risk. `storage: { durability: "strict" }` on the registry is the escape
|
|
260
|
+
hatch if you keep unrecoverable local-only data and cannot accept that window; on idb it costs
|
|
261
|
+
~100–200ms/write (allowed and documented, not forbidden).
|
|
262
|
+
|
|
263
|
+
On OPFS-repacked, browser/worker termination recovers the longest valid stable metadata-log prefix; an
|
|
264
|
+
unflushed suffix may be absent. A returned strict boundary is stable under that browser-failure model. Do
|
|
265
|
+
not generalize this to power loss, media failure, or external store edits.
|
|
217
266
|
|
|
218
267
|
**Three exports, named by purpose, all returning `{ file, report }`** (report = phase timings + a
|
|
219
268
|
`MutationDiagnostics` snapshot, BootReport-style). They work identically on the in-process client and the
|
|
@@ -237,14 +286,22 @@ serialise through one lifecycle slot: a concurrent call rejects immediately with
|
|
|
237
286
|
(no queueing — retry after the holder settles). Ephemeral (`pg_temp`) content is never in any artefact.
|
|
238
287
|
|
|
239
288
|
**Restore** = `createSyncClient({ restoreFrom: backupFile, … })` (or `attachSyncClient` — the tarball rides
|
|
240
|
-
the boot attach), ONLY into a store path that does not exist
|
|
241
|
-
overwrite path is a deliberate `destroy()` first).
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
289
|
+
the boot attach), ONLY into a store path that does not exist in EITHER idb or OPFS
|
|
290
|
+
(`RestoreTargetExistsError` otherwise; the overwrite path is a deliberate `destroy()` first). Recovered
|
|
291
|
+
journal rows are quarantined because the write path has no mutation dedupe. A dirty-journal restore stays
|
|
292
|
+
offline for inspection; a clean-journal restore may honor the normal online options immediately. Inspect
|
|
293
|
+
`diagnostics()`, resolve quarantined rows via `discardQuarantined` (+ re-author if wanted), then reboot the
|
|
294
|
+
persisted store normally. Consumer docs:
|
|
246
295
|
<https://pgxsinkit.github.io/concepts/export-and-restore/>.
|
|
247
296
|
|
|
297
|
+
**Adoption and construction changes.** An existing idb store is authoritative and is never silently
|
|
298
|
+
replaced by a newly capable OPFS home. Automatic adoption is default-off and requires the worker-entry
|
|
299
|
+
declaration `adoption: "server-reconstructible"`; only a drained journal, authorized online reconstruction,
|
|
300
|
+
and a returned strict barrier permit the idb predecessor to be deleted. `adoptStore()` is the manual
|
|
301
|
+
creation-path equivalent and refuses a live store with `StoreInUseError`. Before changing a SW-direct
|
|
302
|
+
construction identity such as durability, await `retireSyncWorkerHost()` so an extended-lifetime worker
|
|
303
|
+
releases its handle without deleting the store; it refuses peers and does not apply to elected placement.
|
|
304
|
+
|
|
248
305
|
## Proxying Electric: force `cache-control: no-store`
|
|
249
306
|
|
|
250
307
|
Electric tags shape responses with a CDN-oriented `cache-control` (`max-age`, `stale-while-revalidate`).
|