@pgxsinkit/client 0.2.0 → 0.2.2
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/index.d.ts +20 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +460 -165
- package/dist/index.js.map +8 -8
- package/dist/mutation.d.ts +6 -0
- package/dist/mutation.d.ts.map +1 -1
- package/dist/worker/attach-sync-client.d.ts +83 -22
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +33 -8
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/engine-control.d.ts +2 -1
- package/dist/worker/engine-control.d.ts.map +1 -1
- package/dist/worker/protocol.d.ts +33 -22
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +3 -3
- package/skills/core/SKILL.md +1 -1
- package/skills/operating/SKILL.md +57 -12
- package/src/index.ts +55 -7
- package/src/mutation.ts +48 -4
- package/src/worker/attach-sync-client.ts +327 -131
- package/src/worker/define-sync-worker.ts +445 -132
- package/src/worker/engine-control.ts +2 -2
- package/src/worker/protocol.ts +41 -7
|
@@ -148,8 +148,8 @@ export type EngineControlMessage =
|
|
|
148
148
|
type: "control-ack";
|
|
149
149
|
identity: EngineIdentity;
|
|
150
150
|
pingId: number;
|
|
151
|
-
/** Present only when the reserved teardown acknowledgement reports that host close failed. */
|
|
152
|
-
error?: { message: string; detail?: unknown };
|
|
151
|
+
/** Present only when the reserved teardown acknowledgement reports that host close failed. Mirrors `protocol.ts`'s `BridgeErrorWire` (this module deliberately imports nothing from the bridge). */
|
|
152
|
+
error?: { message: string; name?: string; detail?: unknown };
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* tab → SharedWorker: an execution-limit report — a dispatch has been outstanding `elapsedMs` past the
|
package/src/worker/protocol.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// never a real `Worker`/`SharedWorker` directly — which is exactly why the whole bridge is unit-testable
|
|
9
9
|
// over bun's `MessageChannel` with no worker at all.
|
|
10
10
|
|
|
11
|
-
import type { SyncRuntimeStatus } from "@pgxsinkit/contracts";
|
|
11
|
+
import type { SyncRuntimeStatus, SyncStorageDeclaration } from "@pgxsinkit/contracts";
|
|
12
12
|
|
|
13
13
|
import type { BootReport } from "../boot-report";
|
|
14
14
|
import type { ExportReport } from "../export-store";
|
|
@@ -31,7 +31,14 @@ export type BridgeTransferable = unknown;
|
|
|
31
31
|
* it, `Worker`/`self` do not); `close()` is optional (a dedicated `self` cannot be closed by the tab).
|
|
32
32
|
*/
|
|
33
33
|
export interface BridgePort {
|
|
34
|
-
|
|
34
|
+
// `transfer` is typed `any` (not `BridgeTransferable[]`) SOLELY so a real DOM `MessagePort`/`Worker` is
|
|
35
|
+
// assignable to `BridgePort` without a cast: the library carries no DOM lib, and DOM's overloaded
|
|
36
|
+
// `postMessage(message, transfer: Transferable[])` is CONTRAVARIANTLY stricter than any DOM-lib-free array
|
|
37
|
+
// type we could name here (`unknown[] | undefined` is not assignable to `Transferable[]`). The list is opaque
|
|
38
|
+
// to the library — the identity codec never produces one — so widening the param loses nothing internal while
|
|
39
|
+
// letting consumers pass `SharedWorker.port` (and a `() => SharedWorker` factory) with no `as unknown` laundering.
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- DOM-postMessage contravariance escape hatch
|
|
41
|
+
postMessage: (message: unknown, transfer?: any) => void;
|
|
35
42
|
addEventListener: (type: "message", listener: (event: { data: unknown }) => void) => void;
|
|
36
43
|
removeEventListener: (type: "message", listener: (event: { data: unknown }) => void) => void;
|
|
37
44
|
start?: () => void;
|
|
@@ -77,6 +84,19 @@ export type BridgeMessageType =
|
|
|
77
84
|
|
|
78
85
|
// ─── Payload shapes ───────────────────────────────────────────────────────────
|
|
79
86
|
|
|
87
|
+
/**
|
|
88
|
+
* The bridge's serialized-error wire shape. `message` always; `name` when the source error carried a
|
|
89
|
+
* non-default one, so a TYPED failure (e.g. a restore refused with `RestoreTargetExistsError`) stays
|
|
90
|
+
* type-detectable after the tab rebuilds it — a consumer must never be forced into message matching;
|
|
91
|
+
* `detail` for structured payloads (execution-limit mismatch, engine-relocated, …) that rebuild as their
|
|
92
|
+
* typed error class tab-side.
|
|
93
|
+
*/
|
|
94
|
+
export interface BridgeErrorWire {
|
|
95
|
+
message: string;
|
|
96
|
+
name?: string;
|
|
97
|
+
detail?: unknown;
|
|
98
|
+
}
|
|
99
|
+
|
|
80
100
|
/** A single auth token snapshot the tab owns and pushes to the worker (ADR-0032 decision 3). */
|
|
81
101
|
export interface AuthTokenSnapshot {
|
|
82
102
|
accessToken: string;
|
|
@@ -107,6 +127,13 @@ export interface ProvisionPayload {
|
|
|
107
127
|
* lane (via the attaching helper); a browser worker never sends it.
|
|
108
128
|
*/
|
|
109
129
|
testStoreBackend?: "memory";
|
|
130
|
+
/**
|
|
131
|
+
* The tab's WIRE storage declaration (ADR-0050) — the same declaration the pre-placement declaration
|
|
132
|
+
* message carried, repeated here so the ENGINE binds it (the mint's durability) wherever it runs. The
|
|
133
|
+
* first provision/attach binds the store's declaration; a later payload whose explicit field disagrees
|
|
134
|
+
* with the bound resolution is refused typed (`StorageDeclarationRefusedError`).
|
|
135
|
+
*/
|
|
136
|
+
storage?: SyncStorageDeclaration;
|
|
110
137
|
}
|
|
111
138
|
|
|
112
139
|
/** worker → tab: the provision completed (or failed). Lets the login screen confirm the spare is warm. */
|
|
@@ -159,6 +186,13 @@ export interface AttachPayload {
|
|
|
159
186
|
* this AFTER the engine has already booted is REFUSED (you cannot restore into a running store).
|
|
160
187
|
*/
|
|
161
188
|
restore?: RestoreArtefactWire;
|
|
189
|
+
/**
|
|
190
|
+
* The tab's WIRE storage declaration (ADR-0050) — repeated from the pre-placement declaration message so
|
|
191
|
+
* the ENGINE binds it (durability included) wherever it runs, the elected dedicated engine included (whose
|
|
192
|
+
* scope never saw the SharedWorker's declaration message). First payload binds; a later explicit
|
|
193
|
+
* disagreement with the bound resolution is refused typed (`StorageDeclarationRefusedError`).
|
|
194
|
+
*/
|
|
195
|
+
storage?: SyncStorageDeclaration;
|
|
162
196
|
/** The tab's current auth token at attach time, or null when unauthenticated. */
|
|
163
197
|
token: AuthTokenSnapshot | null;
|
|
164
198
|
/**
|
|
@@ -216,15 +250,15 @@ export interface AttachAckPayload {
|
|
|
216
250
|
* itself still RESOLVES (the engine reached `localReadReady`; only the tail failed). A live milestone
|
|
217
251
|
* failure after attach rides the `milestone-error` broadcast instead.
|
|
218
252
|
*/
|
|
219
|
-
writeReadyError?:
|
|
220
|
-
bootSettledError?:
|
|
253
|
+
writeReadyError?: BridgeErrorWire;
|
|
254
|
+
bootSettledError?: BridgeErrorWire;
|
|
221
255
|
/**
|
|
222
256
|
* Present when the engine boot REJECTED for this attach: the tab rejects `attachSyncClient` with this
|
|
223
257
|
* message instead of hanging forever on the ack (ADR-0032 FIX 1). A later attach retries the boot. This
|
|
224
258
|
* is a LOCAL-READ-CORE failure (the engine never reached `localReadReady`); a tail failure after
|
|
225
259
|
* `localReadReady` uses the stage-error fields above and does NOT reject the attach.
|
|
226
260
|
*/
|
|
227
|
-
error?:
|
|
261
|
+
error?: BridgeErrorWire;
|
|
228
262
|
}
|
|
229
263
|
|
|
230
264
|
/** worker → tab: a broadcast pull-request — any attached tab may answer, first response wins (ADR-0032 decision 3). */
|
|
@@ -336,7 +370,7 @@ export interface RpcResultPayload {
|
|
|
336
370
|
/** The resolved value (present when `ok`). */
|
|
337
371
|
value?: unknown;
|
|
338
372
|
/** The rejection message + optional structured detail (present when `!ok`). */
|
|
339
|
-
error?:
|
|
373
|
+
error?: BridgeErrorWire;
|
|
340
374
|
}
|
|
341
375
|
|
|
342
376
|
/** tab → worker: register a live query. `id` correlates the initial snapshot; `queryId` keys subsequent diffs. */
|
|
@@ -429,7 +463,7 @@ export type BridgeEvent =
|
|
|
429
463
|
// The mirror failure edge: the background write/sync tail REJECTED a downstream stage (ADR-0041). Rejects
|
|
430
464
|
// the tab's matching `writeReady` / `bootSettled` promise so an awaiter fails loudly rather than hanging;
|
|
431
465
|
// `localReadReady` (and the resolved attach) are unaffected — the engine reached local-read readiness.
|
|
432
|
-
| { kind: "milestone-error"; stage: BootMilestone; error:
|
|
466
|
+
| { kind: "milestone-error"; stage: BootMilestone; error: BridgeErrorWire }
|
|
433
467
|
| { kind: "conflict"; details: unknown }
|
|
434
468
|
| { kind: "quarantine"; details: unknown }
|
|
435
469
|
| { kind: "reject"; details: unknown }
|