@pgxsinkit/client 0.1.36 → 0.1.40
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/dist/boot-report.d.ts +134 -0
- package/dist/boot-report.d.ts.map +1 -0
- package/dist/export-data.d.ts +100 -0
- package/dist/export-data.d.ts.map +1 -0
- package/dist/export-dump.d.ts +92 -0
- package/dist/export-dump.d.ts.map +1 -0
- package/dist/export-store.d.ts +214 -0
- package/dist/export-store.d.ts.map +1 -0
- package/dist/index.d.ts +206 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +886 -69
- package/dist/index.js.map +21 -14
- package/dist/lazy-guard.d.ts +4 -3
- package/dist/lazy-guard.d.ts.map +1 -1
- package/dist/lifecycle-slot.d.ts +31 -0
- package/dist/lifecycle-slot.d.ts.map +1 -0
- package/dist/live-rows-sql.d.ts +21 -0
- package/dist/live-rows-sql.d.ts.map +1 -0
- package/dist/mutation-state.d.ts +9 -2
- package/dist/mutation-state.d.ts.map +1 -1
- package/dist/mutation.d.ts +12 -0
- package/dist/mutation.d.ts.map +1 -1
- package/dist/schema.d.ts +33 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/shape-sync.d.ts +10 -0
- package/dist/shape-sync.d.ts.map +1 -1
- package/dist/store-path.d.ts +132 -0
- package/dist/store-path.d.ts.map +1 -0
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/types.d.ts +8 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/testing.d.ts +27 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +17 -0
- package/dist/testing.js.map +11 -0
- package/dist/worker/attach-sync-client.d.ts +23 -2
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +5 -4
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/protocol.d.ts +89 -8
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +9 -4
- package/skills/core/SKILL.md +14 -1
- package/skills/operating/SKILL.md +75 -15
- package/src/boot-report.ts +287 -0
- package/src/export-data.ts +300 -0
- package/src/export-dump.ts +239 -0
- package/src/export-store.ts +309 -0
- package/src/index.ts +623 -82
- package/src/lazy-guard.ts +23 -9
- package/src/lifecycle-slot.ts +66 -0
- package/src/live-rows-sql.ts +45 -0
- package/src/mutation-state.ts +11 -2
- package/src/mutation.ts +42 -0
- package/src/schema.ts +120 -1
- package/src/shape-sync.ts +21 -0
- package/src/store-path.ts +249 -0
- package/src/sync/index.ts +11 -0
- package/src/sync/types.ts +9 -0
- package/src/testing.ts +53 -0
- package/src/worker/attach-sync-client.ts +101 -6
- package/src/worker/define-sync-worker.ts +196 -30
- package/src/worker/protocol.ts +110 -10
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SyncRuntimeStatus, SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
2
|
+
import type { BootReport } from "../boot-report";
|
|
2
3
|
import { type MutationDetail, type SyncClient } from "../index";
|
|
3
4
|
import type { LocalStoreVersionEvent } from "../local-store";
|
|
4
5
|
import { type AuthTokenSnapshot, type BridgeCodec, type BridgePort, type BridgeTransferable } from "./protocol";
|
|
@@ -27,7 +28,12 @@ export interface AttachSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
27
28
|
getToken?: () => Promise<AuthTokenSnapshot | null>;
|
|
28
29
|
/** The bound store id (resolved tab-side before attach — SharedWorker naming, ADR-0032 decision 5). */
|
|
29
30
|
storeId?: string;
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The plain store PATH (ADR-0036) the worker opens if it must create its own store — a name, not a
|
|
33
|
+
* storage URL. Spread `memoryStoreForTests(...)` from `@pgxsinkit/client/testing` here for a memory store
|
|
34
|
+
* in tests (it also carries the internal marker forwarded to the worker as the memory-backend override).
|
|
35
|
+
*/
|
|
36
|
+
storePath?: string;
|
|
31
37
|
syncEnabled?: boolean;
|
|
32
38
|
/**
|
|
33
39
|
* Which baked registry the worker boots (ADR-0032 S3) — forwarded in the attach `config.role`. A worker
|
|
@@ -41,6 +47,15 @@ export interface AttachSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
41
47
|
* the worker's `createSyncClient` then overlaps the shape catch-up with its local boot phases.
|
|
42
48
|
*/
|
|
43
49
|
freshStore?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Restore the worker's store from a backup on attach (ADR-0035 decision 6) — the worker-mode `restoreFrom`.
|
|
52
|
+
* A `File`/`Blob` as produced by {@link SyncClient.exportStore}; the facade decomposes it into a transferred
|
|
53
|
+
* `ArrayBuffer` + name/mime ({@link RestoreArtefactWire}) and the worker recomposes it for `createSyncClient`.
|
|
54
|
+
* Restore rides the FIRST (boot) attach: passing it when the worker's engine has ALREADY booted rejects the
|
|
55
|
+
* attach with a typed error (you cannot restore into a running store). The restored engine boots offline and
|
|
56
|
+
* its recovered journal is quarantined, exactly as in-process — see `restoreFrom` on `createSyncClient`.
|
|
57
|
+
*/
|
|
58
|
+
restoreFrom?: File | Blob;
|
|
44
59
|
codec?: BridgeCodec;
|
|
45
60
|
onStatusChange?: (status: SyncRuntimeStatus) => void;
|
|
46
61
|
onConflict?: (details: MutationDetail[]) => void;
|
|
@@ -48,6 +63,12 @@ export interface AttachSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
48
63
|
onReject?: (details: MutationDetail[]) => void;
|
|
49
64
|
onSchemaChange?: (event: LocalStoreVersionEvent) => void;
|
|
50
65
|
onSyncError?: (error: Error) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Boot observability (ADR-0034): invoked once with the worker engine's finalized {@link BootReport} if the
|
|
68
|
+
* engine's boot finalizes WHILE this tab is attached (the one-shot `boot-report` broadcast). A tab that
|
|
69
|
+
* attaches AFTER the boot never receives the push — it reads the report via {@link SyncClient.bootReport}.
|
|
70
|
+
*/
|
|
71
|
+
onBootReport?: (report: BootReport) => void;
|
|
51
72
|
}
|
|
52
73
|
/**
|
|
53
74
|
* The worker-attached client: `SyncClient`'s shape, worker-proxied, plus `notifyAuthChanged` (re-push the
|
|
@@ -70,6 +91,6 @@ export declare function attachSyncClient<const TRegistry extends SyncTableRegist
|
|
|
70
91
|
* provision (its initdb settled); rejects only if the worker reports the create failed — the caller treats
|
|
71
92
|
* either outcome as best-effort, since attach falls back to a fresh create regardless.
|
|
72
93
|
*/
|
|
73
|
-
export declare function provisionSyncWorker<TRegistry extends SyncTableRegistry>(options: Pick<AttachSyncClientOptions<TRegistry>, "worker" | "port" | "storeId" | "
|
|
94
|
+
export declare function provisionSyncWorker<TRegistry extends SyncTableRegistry>(options: Pick<AttachSyncClientOptions<TRegistry>, "worker" | "port" | "storeId" | "storePath" | "codec">): Promise<void>;
|
|
74
95
|
export {};
|
|
75
96
|
//# sourceMappingURL=attach-sync-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-sync-client.d.ts","sourceRoot":"","sources":["../../src/worker/attach-sync-client.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAEV,iBAAiB,EAEjB,iBAAiB,EAElB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAIL,KAAK,cAAc,EAEnB,KAAK,UAAU,EAGhB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"attach-sync-client.d.ts","sourceRoot":"","sources":["../../src/worker/attach-sync-client.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAEV,iBAAiB,EAEjB,iBAAiB,EAElB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,OAAO,EAIL,KAAK,cAAc,EAEnB,KAAK,UAAU,EAGhB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAG7D,OAAO,EA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,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACrD,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IACjD,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IACnD,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IAC/C,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACzD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACrC;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CAC7C;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,SAAS,SAAS,iBAAiB,IAAI,UAAU,CAAC,SAAS,CAAC,GAAG;IAC5F,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B;;;;OAIG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACtC,CAAC;AAEF,wBAAsB,gBAAgB,CAAC,KAAK,CAAC,SAAS,SAAS,iBAAiB,EAC9E,OAAO,EAAE,uBAAuB,CAAC,SAAS,CAAC,GAC1C,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAycxC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,SAAS,iBAAiB,EACrE,OAAO,EAAE,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC,GACvG,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
|
@@ -20,16 +20,17 @@ export interface DefineSyncWorkerOptions<TRegistry extends SyncTableRegistry> {
|
|
|
20
20
|
* How the worker creates its raw PGlite store (provision + fresh-attach paths). Defaults to
|
|
21
21
|
* {@link createClientPGlite}, which loads PGlite's own boot assets — in a browser worker those hit the
|
|
22
22
|
* same-origin HTTP cache the tab's login-screen warm already primed (ADR-0032 S3). Injected in tests.
|
|
23
|
+
* Takes a plain store PATH (ADR-0036); the internal `backendOverride` is the test lane's memory selection.
|
|
23
24
|
*/
|
|
24
|
-
createPglite?: (
|
|
25
|
+
createPglite?: (storePath: string, backendOverride?: "memory") => Promise<ClientPGlite>;
|
|
25
26
|
electricUrl: string;
|
|
26
27
|
writeUrl: string;
|
|
27
28
|
/** Static headers on every read + write request (e.g. a gateway `apikey`). See `createSyncClient`. */
|
|
28
29
|
requestHeaders?: Record<string, string>;
|
|
29
30
|
/** Write-only headers merged over {@link requestHeaders} (e.g. region/DB-affinity). See `createSyncClient`. */
|
|
30
31
|
writeRequestHeaders?: Record<string, string>;
|
|
31
|
-
/** Default
|
|
32
|
-
|
|
32
|
+
/** Default plain store PATH (ADR-0036) if the first attach carries none — a name, not a storage URL. */
|
|
33
|
+
storePath?: string;
|
|
33
34
|
maxMutationAttempts?: number;
|
|
34
35
|
syncEnabled?: boolean;
|
|
35
36
|
/**
|
|
@@ -51,7 +52,7 @@ export interface DefineSyncWorkerOptions<TRegistry extends SyncTableRegistry> {
|
|
|
51
52
|
/**
|
|
52
53
|
* A raw PGlite the worker uses instead of creating its own (forwarded to `createSyncClient`'s
|
|
53
54
|
* {@link CreateSyncClientOptions.precreatedPglite}) — the client still applies schema/reconcile. In a
|
|
54
|
-
* browser worker the store is minted internally (`
|
|
55
|
+
* browser worker the store is minted internally (`storePath`); this is the seam for a prepopulated store in
|
|
55
56
|
* tests, and the future spare-worker claim (ADR-0032 decision 5).
|
|
56
57
|
*/
|
|
57
58
|
precreatedPglite?: CreateSyncClientOptions<TRegistry>["precreatedPglite"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-sync-worker.d.ts","sourceRoot":"","sources":["../../src/worker/define-sync-worker.ts"],"names":[],"mappings":"AASA,OA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,4GAA4G;IAC5G,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;IAC1E,oHAAoH;IACpH,cAAc,CAAC,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC;CACvE;AAED,qFAAqF;AACrF,MAAM,WAAW,cAAc,CAAC,SAAS,SAAS,iBAAiB;IACjE,8GAA8G;IAC9G,OAAO,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACpC,uGAAuG;IACvG,UAAU,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;IACjD,kGAAkG;IAClG,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAOD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,SAAS,SAAS,iBAAiB,EACxE,OAAO,EAAE,uBAAuB,CAAC,SAAS,CAAC,GAC1C,cAAc,CAAC,SAAS,CAAC,CAwkB3B"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { SyncRuntimeStatus } from "@pgxsinkit/contracts";
|
|
2
|
+
import type { BootReport } from "../boot-report";
|
|
3
|
+
import type { ExportReport } from "../export-store";
|
|
2
4
|
export declare const BRIDGE_CHANNEL: "pgxsinkit-bridge";
|
|
3
5
|
export declare const BRIDGE_PROTOCOL_VERSION: 1;
|
|
4
6
|
/**
|
|
@@ -56,8 +58,18 @@ export interface AuthTokenSnapshot {
|
|
|
56
58
|
export interface ProvisionPayload {
|
|
57
59
|
/** The bound store id (informational; naming is done tab-side via the SharedWorker name). */
|
|
58
60
|
storeId?: string;
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
+
/**
|
|
62
|
+
* The plain store PATH (ADR-0036) to `create` ahead of attach — a name, not a storage URL; the worker
|
|
63
|
+
* derives the backend (IndexedDB in a browser worker). When omitted, `storeId`/the worker default is used.
|
|
64
|
+
*/
|
|
65
|
+
storePath?: string;
|
|
66
|
+
/**
|
|
67
|
+
* @internal INTERNAL WIRE FIELD (not consumer config, ADR-0036). Carries the testing memory-backend
|
|
68
|
+
* override across the bridge, because a symbol-keyed marker does NOT survive `postMessage` structured
|
|
69
|
+
* clone — so the worker's memory-store selection travels as this explicit field. Set only by the test
|
|
70
|
+
* lane (via the attaching helper); a browser worker never sends it.
|
|
71
|
+
*/
|
|
72
|
+
testStoreBackend?: "memory";
|
|
61
73
|
}
|
|
62
74
|
/** worker → tab: the provision completed (or failed). Lets the login screen confirm the spare is warm. */
|
|
63
75
|
export interface ProvisionAckPayload {
|
|
@@ -68,12 +80,45 @@ export interface ProvisionAckPayload {
|
|
|
68
80
|
message: string;
|
|
69
81
|
};
|
|
70
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* tab → worker: a store-backup tarball to restore from, carried on the boot {@link AttachPayload}
|
|
85
|
+
* (ADR-0035 decision 6). The mirror image of {@link ExportArtefactWire}: a `File`/`Blob` cannot cross the
|
|
86
|
+
* bridge as a transferable, so it is decomposed into its zero-copy `ArrayBuffer` (listed on `postMessage`'s
|
|
87
|
+
* transfer list) plus the metadata to rebuild it, and the worker reassembles a `Blob` from
|
|
88
|
+
* `buffer`/`mimeType` to hand `createSyncClient` as `restoreFrom`.
|
|
89
|
+
*/
|
|
90
|
+
export interface RestoreArtefactWire {
|
|
91
|
+
/** The backup tarball bytes — transferred, not copied. */
|
|
92
|
+
buffer: ArrayBuffer;
|
|
93
|
+
/** The backup file name (informational; PGlite's `loadDataDir` reads the bytes, not the name). */
|
|
94
|
+
fileName: string;
|
|
95
|
+
/** The backup MIME type (`application/x-gzip` / `application/x-tar`), used to rebuild the `Blob`. */
|
|
96
|
+
mimeType: string;
|
|
97
|
+
}
|
|
71
98
|
/** tab → worker: the attach handshake. The first attach boots the engine; later attaches join it. */
|
|
72
99
|
export interface AttachPayload {
|
|
73
100
|
/** The bound store id (SharedWorker naming resolves it tab-side before attach — ADR-0032 decision 5). */
|
|
74
101
|
storeId?: string;
|
|
75
|
-
/**
|
|
76
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Explicit plain store PATH (ADR-0036) if the worker should create its own store — a name, not a storage
|
|
104
|
+
* URL; the worker derives the backend. When omitted, `storeId`/the worker default is used.
|
|
105
|
+
*/
|
|
106
|
+
storePath?: string;
|
|
107
|
+
/**
|
|
108
|
+
* @internal INTERNAL WIRE FIELD (not consumer config, ADR-0036). Carries the testing memory-backend
|
|
109
|
+
* override across the bridge — a symbol-keyed marker does not survive structured clone, so the worker's
|
|
110
|
+
* memory-store selection travels as this explicit field. Set only by the test lane; never by a browser tab.
|
|
111
|
+
*/
|
|
112
|
+
testStoreBackend?: "memory";
|
|
113
|
+
/**
|
|
114
|
+
* Restore the store from a backup on THIS attach (ADR-0035 decision 6) — the worker-mode carrier of
|
|
115
|
+
* `createSyncClient`'s `restoreFrom`. Restore rides the FIRST attach (the boot attach): a `File`/`Blob`
|
|
116
|
+
* cannot cross `postMessage` as a transferable, so the tab decomposes it into a transferred `ArrayBuffer`
|
|
117
|
+
* plus its name/mime — the {@link ExportArtefactWire} pattern in reverse — and the worker recomposes it
|
|
118
|
+
* into a `Blob` and hands it to `createSyncClient`. Absent on every ordinary attach. An attach that carries
|
|
119
|
+
* this AFTER the engine has already booted is REFUSED (you cannot restore into a running store).
|
|
120
|
+
*/
|
|
121
|
+
restore?: RestoreArtefactWire;
|
|
77
122
|
/** The tab's current auth token at attach time, or null when unauthenticated. */
|
|
78
123
|
token: AuthTokenSnapshot | null;
|
|
79
124
|
/**
|
|
@@ -131,12 +176,31 @@ export interface TokenResponsePayload {
|
|
|
131
176
|
* The RPC ops the attach facade proxies to the worker's booted client — the write API (mirrors
|
|
132
177
|
* `client.mutate`/flush), mutation-state reads, and the one-shot raw inspection reads (`rawQuery`/`rawExec`).
|
|
133
178
|
*/
|
|
134
|
-
export type RpcOp = "create" | "update" | "delete" | "batch" | "transaction" | "flush" | "reconcile" | "retryFailed" | "recoverSending" | "discardConflict" | "discardQuarantined" | "readMutationDetails" | "diagnostics" | "rawQuery" | "rawExec";
|
|
179
|
+
export type RpcOp = "create" | "update" | "delete" | "batch" | "transaction" | "flush" | "reconcile" | "retryFailed" | "recoverSending" | "discardConflict" | "discardQuarantined" | "desync" | "discardEphemeral" | "readMutationDetails" | "diagnostics" | "rawQuery" | "rawExec" | "bootReport" | "exportStore" | "exportDiagnostics" | "exportData";
|
|
135
180
|
/** tab → worker: a write/read-of-mutation-state RPC. `id` correlates the matching {@link RpcResultPayload}. */
|
|
136
181
|
export interface RpcPayload {
|
|
137
182
|
op: RpcOp;
|
|
138
183
|
args: unknown[];
|
|
139
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* worker → tab: the wire form of ANY local-store export (ADR-0035) — the store backup's tarball OR the
|
|
187
|
+
* diagnostic dump's SQL — carried as the `value` of an {@link RpcResultPayload}. The artefact crosses as a
|
|
188
|
+
* transferred `ArrayBuffer` (zero-copy — the sender lists `buffer` in `postMessage`'s transfer list) plus
|
|
189
|
+
* the metadata to rebuild it; the tab reconstructs a `File` from `buffer`/`fileName`/`mimeType`. A `File`
|
|
190
|
+
* cannot itself be transferred, so it is decomposed here and reassembled tab-side, exactly the pattern the
|
|
191
|
+
* codec's transferable seam anticipates for a zero-copy live-diff payload. `report` is the discriminated
|
|
192
|
+
* {@link ExportReport} union, so the tab knows which export it round-tripped.
|
|
193
|
+
*/
|
|
194
|
+
export interface ExportArtefactWire {
|
|
195
|
+
/** The artefact bytes (tarball or SQL) — transferred, not copied. */
|
|
196
|
+
buffer: ArrayBuffer;
|
|
197
|
+
/** The generated (or caller-supplied) artefact file name. */
|
|
198
|
+
fileName: string;
|
|
199
|
+
/** The artefact MIME type (`application/x-gzip` / `application/x-tar` for a backup, `application/sql` for a dump). */
|
|
200
|
+
mimeType: string;
|
|
201
|
+
/** The export report (ADR-0035), structured-cloned as a plain object — the `kind`-discriminated union. */
|
|
202
|
+
report: ExportReport;
|
|
203
|
+
}
|
|
140
204
|
/** worker → tab: an RPC outcome, mirroring today's in-process resolve/reject semantics. */
|
|
141
205
|
export interface RpcResultPayload {
|
|
142
206
|
ok: boolean;
|
|
@@ -153,10 +217,19 @@ export interface SubscribePayload {
|
|
|
153
217
|
queryId: string;
|
|
154
218
|
sql: string;
|
|
155
219
|
params: unknown[];
|
|
220
|
+
/**
|
|
221
|
+
* The unique output aliases the worker wraps the query's columns under so it is safe to MATERIALISE
|
|
222
|
+
* (one per output column, in the compiled SQL's column order). ADDITIVE and backward-compatible: an
|
|
223
|
+
* older tab omits it and the worker leaves the SQL untouched (name-keyed rows, as before); a newer tab
|
|
224
|
+
* supplies it for a JOIN with same-named columns, which `live.query`/`live.incrementalQuery` otherwise
|
|
225
|
+
* refuse to materialise (`column "title" specified more than once`). When present, result columns are
|
|
226
|
+
* the aliases, so {@link pkColumns} must name a PK by its alias.
|
|
227
|
+
*/
|
|
228
|
+
fields?: string[];
|
|
156
229
|
/**
|
|
157
230
|
* The result's primary-key columns, driving diff keying (§4). One column → the incremental path
|
|
158
231
|
* (`live.incrementalQuery`); many → worker-side diff by composite PK; empty/absent → value-identity
|
|
159
|
-
* fallback for a keyless query.
|
|
232
|
+
* fallback for a keyless query. When {@link fields} is supplied these name the ALIASED result columns.
|
|
160
233
|
*/
|
|
161
234
|
pkColumns?: string[];
|
|
162
235
|
/** Lazy relations to activate before the query runs (ADR-0021), forwarded to the worker's `prepareQuery`. */
|
|
@@ -215,6 +288,9 @@ export type BridgeEvent = {
|
|
|
215
288
|
label: string;
|
|
216
289
|
ms: number;
|
|
217
290
|
data?: Record<string, unknown>;
|
|
291
|
+
} | {
|
|
292
|
+
kind: "boot-report";
|
|
293
|
+
report: BootReport;
|
|
218
294
|
} | {
|
|
219
295
|
kind: "debug";
|
|
220
296
|
stamp: number;
|
|
@@ -255,6 +331,11 @@ export declare function encodeEnvelope(codec: BridgeCodec, type: BridgeMessageTy
|
|
|
255
331
|
};
|
|
256
332
|
/** Type-guard a received message as a bridge envelope of the current protocol version (ignore foreign traffic). */
|
|
257
333
|
export declare function isBridgeEnvelope(data: unknown): data is BridgeEnvelope;
|
|
258
|
-
/**
|
|
259
|
-
|
|
334
|
+
/**
|
|
335
|
+
* Send a typed message over a port: encode → post (with any transferables). The one write choke point.
|
|
336
|
+
* `transfer` lets a caller declare payload-specific transferables (e.g. a store-backup's `ArrayBuffer`,
|
|
337
|
+
* ADR-0035) WITHOUT teaching the shared codec about that op — they are merged after any the codec itself
|
|
338
|
+
* produces, so both the codec's future zero-copy path and per-message transfers coexist.
|
|
339
|
+
*/
|
|
340
|
+
export declare function postBridgeMessage(port: BridgePort, codec: BridgeCodec, type: BridgeMessageType, payload: unknown, id?: string, transfer?: BridgeTransferable[]): void;
|
|
260
341
|
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -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,eAAO,MAAM,cAAc,EAAG,kBAA2B,CAAC;AAC1D,eAAO,MAAM,uBAAuB,EAAG,CAAU,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IACzE,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,E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AC,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"tanstack-intent"
|
|
6
6
|
],
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
21
|
"default": "./dist/index.js"
|
|
22
22
|
},
|
|
23
|
+
"./testing": {
|
|
24
|
+
"types": "./dist/testing.d.ts",
|
|
25
|
+
"default": "./dist/testing.js"
|
|
26
|
+
},
|
|
23
27
|
"./oxlint": "./oxlint-plugin.js"
|
|
24
28
|
},
|
|
25
29
|
"publishConfig": {
|
|
@@ -29,9 +33,10 @@
|
|
|
29
33
|
"build": "bun --cwd ../.. run build:public-packages"
|
|
30
34
|
},
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@electric-sql/client": "^1.5.
|
|
33
|
-
"@electric-sql/experimental": "^6.0.
|
|
34
|
-
"@
|
|
36
|
+
"@electric-sql/client": "^1.5.24",
|
|
37
|
+
"@electric-sql/experimental": "^6.0.24",
|
|
38
|
+
"@electric-sql/pglite-tools": "0.4.4",
|
|
39
|
+
"@pgxsinkit/contracts": "0.1.40"
|
|
35
40
|
},
|
|
36
41
|
"peerDependencies": {
|
|
37
42
|
"@electric-sql/pglite": "0.5.4",
|
package/skills/core/SKILL.md
CHANGED
|
@@ -12,7 +12,7 @@ description: >-
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: core
|
|
14
14
|
library: "@pgxsinkit/client"
|
|
15
|
-
library_version: "0.1.
|
|
15
|
+
library_version: "0.1.40"
|
|
16
16
|
source: https://pgxsinkit.github.io/llms-full.txt
|
|
17
17
|
---
|
|
18
18
|
|
|
@@ -186,6 +186,19 @@ constraint that holds server-side also holds in PGlite.
|
|
|
186
186
|
- Assuming PGlite enforces every Postgres constraint.
|
|
187
187
|
- Assuming a revoked member keeps their synced rows offline — membership changes converge both ways,
|
|
188
188
|
live and on resume.
|
|
189
|
+
- Passing a PGlite storage URL (`idb://…`, `memory://…`) as `storePath` — the contract is a plain
|
|
190
|
+
name and schemes throw; the backend is derived (ADR-0036).
|
|
191
|
+
|
|
192
|
+
## Naming the local store
|
|
193
|
+
|
|
194
|
+
`createSyncClient`/`createClientPGlite` take a **plain `storePath`** (e.g. `"my-app-store"`), never a
|
|
195
|
+
storage URL — the backend is derived (browser/worker → IndexedDB, bun/Node → filesystem), and anything
|
|
196
|
+
containing `://` throws `InvalidStorePathError`. Memory-backed stores are deliberately not expressible in
|
|
197
|
+
the production API (pgxsinkit's retention + journal durability assume a persisted store): in TESTS, spread
|
|
198
|
+
`memoryStoreForTests("name")` from `@pgxsinkit/client/testing` into the options; a caller-owned
|
|
199
|
+
`pgliteInstance` that is provably non-persistent (a bare `new PGlite()`, or `memory://`) is refused with
|
|
200
|
+
`NonPersistentStoreError` unless a testing acknowledgment is spread alongside. Backups, the SQL exports,
|
|
201
|
+
and `restoreFrom` are the `operating` skill's territory.
|
|
189
202
|
|
|
190
203
|
## Where to look
|
|
191
204
|
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: operating
|
|
3
3
|
description: >-
|
|
4
|
-
Load when deploying or operating a live pgxsinkit app,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
flush on enqueue; the interval is only a fallback), serverless edge cold starts and
|
|
8
|
-
cache-control:no-store on a same-origin Electric shape proxy, the browser HTTP/2 connection
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
writes take seconds to appear in another client.
|
|
4
|
+
Load when deploying or operating a live pgxsinkit app, when diagnosing a sync/write that "feels slow"
|
|
5
|
+
in a browser even though the server is fast, or when wiring backups/export/restore. Covers the runtime
|
|
6
|
+
and deployment properties (not toolkit bugs) that decide whether a live app feels fast: convergence
|
|
7
|
+
cadence (writes flush on enqueue; the interval is only a fallback), serverless edge cold starts and
|
|
8
|
+
warming, cache-control:no-store on a same-origin Electric shape proxy, the browser HTTP/2 connection
|
|
9
|
+
budget, the edge worker timeout vs Electric's long-poll, globalThis.__pgxsinkitDebug + the BootReport,
|
|
10
|
+
worker mode (defineSyncWorker/attachSyncClient — the whole engine in a SharedWorker, spare-as-worker
|
|
11
|
+
boot, per-group readiness, the rail forwarded as [pgxsinkit·w]), and the store lifecycle surface:
|
|
12
|
+
storePath naming, exportStore/exportDiagnostics/exportData (+ drain guard), and restoreFrom.
|
|
14
13
|
metadata:
|
|
15
14
|
type: task
|
|
16
15
|
library: "@pgxsinkit/client"
|
|
17
|
-
library_version: "0.1.
|
|
16
|
+
library_version: "0.1.40"
|
|
18
17
|
source: https://pgxsinkit.github.io/start/operating-in-production/
|
|
19
18
|
---
|
|
20
19
|
|
|
@@ -83,13 +82,13 @@ pglite-warm.ts` shows the Vite `?url` asset-URL pattern PGlite's `exports` field
|
|
|
83
82
|
|
|
84
83
|
Pre-warming only hides the WASM fetch+compile; `PGlite.create` still spends ~1.9s on `initdb` + store open,
|
|
85
84
|
and that can't start until the store id is known (usually the signed-in user). To hide it too, create the
|
|
86
|
-
store EAGERLY under a generated id on the first screen and BIND it at auth. `createClientPGlite(
|
|
85
|
+
store EAGERLY under a generated id on the first screen and BIND it at auth. `createClientPGlite(storePath,
|
|
87
86
|
{ bootAssets })` runs the exact same create the client does internally (electric + live extensions, warm
|
|
88
87
|
consumption, the `boot pglite.create` stamp) and returns a schemaless instance; hand the still-pending
|
|
89
88
|
promise to `createSyncClient`'s `precreatedPglite` option. Unlike `pgliteInstance` (caller owns schema),
|
|
90
89
|
`precreatedPglite` lets the client still run schema exec, prepare hooks, journal recovery and store-version
|
|
91
90
|
reconcile — so the eager create buys only `initdb`, and the role/registry-derived schema stays post-auth. A
|
|
92
|
-
rejected `precreatedPglite` is caught and falls back to the `
|
|
91
|
+
rejected `precreatedPglite` is caught and falls back to the `storePath` create path (which also consumes
|
|
93
92
|
`pgliteBootAssets`), so it is a pure accelerator, never a boot dependency. Bind eager stores to users with a
|
|
94
93
|
small localStorage registry (userId→storeId plus one unbound "spare"): create a spare on the login screen,
|
|
95
94
|
claim it at sign-in, and GC any store that is neither mapped nor the spare. On a signed-in RELOAD there is
|
|
@@ -112,7 +111,12 @@ serialized in. The tab calls `attachSyncClient({ worker, registry, getToken })`,
|
|
|
112
111
|
client shape as `createSyncClient` (write API, Drizzle read BUILDING on the tab, live rows,
|
|
113
112
|
`ready`/`status`/`stop`) plus `notifyAuthChanged` and `setOnline`, proxied to the shared engine. One-shot
|
|
114
113
|
`query`/`queryRaw` and local `pglite`/`ensureSynced`/`destroy` are NOT proxied (they throw) — reactive live
|
|
115
|
-
rows are the read path in worker mode. The
|
|
114
|
+
rows are the read path in worker mode. The lazy lifecycle methods ARE proxied, but the engine is SHARED:
|
|
115
|
+
`desync(tableKey)` from one tab reverts the consistency group for EVERY attached tab (desync's group-wide
|
|
116
|
+
revert is engine-wide here — the footgun). For an ephemeral delivery window use `discardEphemeral(tableKey)`
|
|
117
|
+
instead — the scoped, multi-tab-safe finalize (drops the ephemeral rows, reverts to dormant, refuses a
|
|
118
|
+
group with any persistent member); safe under a shared engine because an ephemeral window is
|
|
119
|
+
per-delivery-session and single-consumer. The exception is the INSPECTION surface `rawQuery(sql, params)` /
|
|
116
120
|
`rawExec(sql)` (debug pages, REPLs, ad-hoc counts): identical on both clients (executed in the worker on the
|
|
117
121
|
attach client), it runs raw against the local store — bypasses the journal/overlay, any write stays local
|
|
118
122
|
and never converges — so it is not an app-data read path. `replAdapter(client)` shapes it into the
|
|
@@ -139,9 +143,53 @@ progressive paint use `await client.groupReady(tableKey)` or read `status.groups
|
|
|
139
143
|
**Debug rail is forwarded and origin-tagged.** A SharedWorker's own console is invisible to the page (only
|
|
140
144
|
`chrome://inspect`), so the worker forwards every rail line to each tab, stamped with the WORKER's monotonic
|
|
141
145
|
clock and re-printed as `[pgxsinkit·w <ms>ms] …`, gated by that tab's own `globalThis.__pgxsinkitDebug`. Set
|
|
142
|
-
the flag on the TAB as usual; the write/read/boot phases below read the same, just origin-tagged.
|
|
146
|
+
the flag on the TAB as usual; the write/read/boot phases below read the same, just origin-tagged. The front
|
|
147
|
+
half of boot runs on the FIRST attach before any tab is listening, so the worker buffers those pre-attach
|
|
148
|
+
rail lines in a bounded ring (last 500) and replays them `[replay]`-marked to the first attaching tab (so
|
|
149
|
+
the boot's opening phases reach it too, ADR-0034). Full model:
|
|
143
150
|
<https://pgxsinkit.github.io/concepts/worker-mode/>.
|
|
144
151
|
|
|
152
|
+
## Store naming, backups, and restore (ADR-0035/0036)
|
|
153
|
+
|
|
154
|
+
**Stores are named by a plain `storePath`, never a storage URL.** The backend is derived (browser/worker →
|
|
155
|
+
IndexedDB, bun/Node → filesystem); anything containing `://` throws `InvalidStorePathError` — do not "fix"
|
|
156
|
+
that by re-adding a scheme, drop it. Memory-backed stores are deliberately unreachable from the production
|
|
157
|
+
API (durability semantics assume a persisted store): tests spread `memoryStoreForTests("name")` from
|
|
158
|
+
`@pgxsinkit/client/testing`, and a caller-owned `pgliteInstance`/`precreatedPglite` that is provably
|
|
159
|
+
non-persistent (`dataDir` undefined — a bare `new PGlite()` — or `memory://`) is refused with
|
|
160
|
+
`NonPersistentStoreError` unless `testStoreAcknowledgment()` is spread alongside. For browser store GC, get
|
|
161
|
+
the IndexedDB name from `storeIndexedDbDatabaseName(storePath)` — never assemble `/pglite/…` yourself.
|
|
162
|
+
|
|
163
|
+
**Three exports, named by purpose, all returning `{ file, report }`** (report = phase timings + a
|
|
164
|
+
`MutationDiagnostics` snapshot, BootReport-style). They work identically on the in-process client and the
|
|
165
|
+
attach client (the artefact crosses the bridge as a transferred buffer):
|
|
166
|
+
|
|
167
|
+
- `exportStore()` — the **store backup**: a live, checkpointed `dumpDataDir` tarball of the WHOLE store,
|
|
168
|
+
journal and overlay included. Never blocks, works offline with unflushed writes; restorable ONLY into
|
|
169
|
+
PGlite via restore below. This is the backup/migration format.
|
|
170
|
+
- `exportDiagnostics()` — everything as SQL (synced + overlay + journal + views/functions + the `pgxsinkit`
|
|
171
|
+
schema) for support evidence. Never blocks; not for restoring.
|
|
172
|
+
- `exportData({ drainJournal? })` — the **portable** SQL (synced tables + their enum types, nothing of
|
|
173
|
+
pgxsinkit's machinery; loads into vanilla Postgres). The ONE blocking variant: it requires a fully
|
|
174
|
+
drained journal (an `acked` write whose echo has not landed is NOT yet in the synced tables), so it
|
|
175
|
+
flushes and awaits convergence up to `drainJournal.timeoutMs` (default 15s), failing fast with
|
|
176
|
+
`DataExportDrainError` (+ diagnostics) on `failed`/`quarantined`/`conflicted` rows. `drainJournal: false`
|
|
177
|
+
exports synced state as-is and flags it in the report.
|
|
178
|
+
|
|
179
|
+
The pg_dump variants run against a **throwaway clone** booted from the backup — the live engine is never
|
|
180
|
+
suspended and tabs never pause. Exports, `destroy()`, `discardEphemeral()`, and `dropReadCache()` all
|
|
181
|
+
serialise through one lifecycle slot: a concurrent call rejects immediately with `LifecycleBusyError`
|
|
182
|
+
(no queueing — retry after the holder settles). Ephemeral (`pg_temp`) content is never in any artefact.
|
|
183
|
+
|
|
184
|
+
**Restore** = `createSyncClient({ restoreFrom: backupFile, … })` (or `attachSyncClient` — the tarball rides
|
|
185
|
+
the boot attach), ONLY into a store path that does not exist yet (`RestoreTargetExistsError` otherwise; the
|
|
186
|
+
overwrite path is a deliberate `destroy()` first). A restored engine ALWAYS boots offline — no shape
|
|
187
|
+
streams, no flush, whatever options say — and every journal row recovered from the backup is parked in the
|
|
188
|
+
terminal `quarantined` state (the write path has no mutation dedupe, so replaying recovered writes is
|
|
189
|
+
unsafe). Inspect `diagnostics()`, resolve rows via `discardQuarantined` (+ re-author if wanted), then go
|
|
190
|
+
online by REBOOTING the now-persisted store normally. Consumer docs:
|
|
191
|
+
<https://pgxsinkit.github.io/concepts/export-and-restore/>.
|
|
192
|
+
|
|
145
193
|
## Proxying Electric: force `cache-control: no-store`
|
|
146
194
|
|
|
147
195
|
Electric tags shape responses with a CDN-oriented `cache-control` (`max-age`, `stale-while-revalidate`).
|
|
@@ -199,6 +247,18 @@ pglite.create` → `boot client ready` phases (local store open, schema apply, j
|
|
|
199
247
|
store-version reconcile, sync start) let you attribute a slow first paint to a specific boot phase, and
|
|
200
248
|
`boot pglite assets warm` times the optional boot-asset pre-warm (see below).
|
|
201
249
|
|
|
250
|
+
**Structured boot numbers — the `BootReport`.** The rail lines are for a human reading a console; for
|
|
251
|
+
machine-keepable numbers (dashboards, CI budget gates) every boot ALSO builds a versioned `BootReport`,
|
|
252
|
+
independently of the rail so it exists whether or not the flag is on (ADR-0034). Read it by push
|
|
253
|
+
(`onBootReport?: (report) => void` client option, fires once at boot completion) or pull
|
|
254
|
+
(`await client.bootReport()` → the most recent completed boot, `null` before the first sync; in worker mode
|
|
255
|
+
it round-trips to the worker's stored report, so a late tab reads a boot that predates it). It carries
|
|
256
|
+
`totalMs`, decomposed `phases`, and a per-group `groups[]`. Two reading caveats: groups catch up
|
|
257
|
+
CONCURRENTLY on one WASM thread, so a group's `fetchMs` is an UPPER BOUND on network wait (it absorbs other
|
|
258
|
+
groups' applies + main-thread work between deliveries), and concurrent `applyMs` can overlap — never sum
|
|
259
|
+
them into a `totalMs` partition; and a non-null `provision` block is a spare's off-thread `initdb` made
|
|
260
|
+
visible (then `phases.pgliteCreateMs` is `null`).
|
|
261
|
+
|
|
202
262
|
A `catch-up watermark aligned {floor}` line marks the one moment the group finished its initial catch-up
|
|
203
263
|
and aligned its commit floors (ADR-0031). Electric's catch-up responses are CDN-cacheable and carry the
|
|
204
264
|
`up-to-date` watermark inside the cached body, so a quiet shape's stale cached watermark would otherwise
|