@pgxsinkit/client 0.1.49 → 0.1.51
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 +76 -0
- package/dist/boot-report.d.ts.map +1 -1
- package/dist/index.d.ts +56 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1106 -312
- package/dist/index.js.map +19 -18
- package/dist/local-store.d.ts +58 -0
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-tables.d.ts +340 -0
- package/dist/local-tables.d.ts.map +1 -1
- package/dist/mutation.d.ts +36 -0
- package/dist/mutation.d.ts.map +1 -1
- package/dist/mutations-api.d.ts +82 -0
- package/dist/mutations-api.d.ts.map +1 -0
- package/dist/schema.d.ts +80 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/shape-sync.d.ts +6 -0
- package/dist/shape-sync.d.ts.map +1 -1
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/metadata-tables.d.ts +16 -0
- package/dist/sync/metadata-tables.d.ts.map +1 -1
- package/dist/sync/subscription-state.d.ts +10 -2
- package/dist/sync/subscription-state.d.ts.map +1 -1
- package/dist/sync/tags.d.ts +16 -4
- package/dist/sync/tags.d.ts.map +1 -1
- package/dist/sync/types.d.ts +12 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/protocol.d.ts +44 -1
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +2 -2
- package/skills/core/SKILL.md +1 -1
- package/skills/operating/SKILL.md +1 -1
- package/src/boot-report.ts +108 -0
- package/src/index.ts +555 -136
- package/src/local-store.ts +150 -3
- package/src/local-tables.ts +49 -1
- package/src/mutation.ts +256 -15
- package/src/mutations-api.ts +310 -0
- package/src/schema.ts +428 -197
- package/src/shape-sync.ts +11 -0
- package/src/sync/index.ts +14 -1
- package/src/sync/metadata-tables.ts +41 -0
- package/src/sync/subscription-state.ts +29 -4
- package/src/sync/tags.ts +34 -9
- package/src/sync/types.ts +12 -0
- package/src/worker/attach-sync-client.ts +114 -5
- package/src/worker/define-sync-worker.ts +65 -4
- package/src/worker/protocol.ts +38 -1
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
} from "./live-query-manager";
|
|
35
35
|
import {
|
|
36
36
|
type AttachPayload,
|
|
37
|
+
type BootMilestone,
|
|
37
38
|
type BridgeCodec,
|
|
38
39
|
type BridgeEnvelope,
|
|
39
40
|
type BridgeEvent,
|
|
@@ -314,6 +315,37 @@ export function defineSyncWorker<const TRegistry extends SyncTableRegistry>(
|
|
|
314
315
|
resolveBooted = resolve;
|
|
315
316
|
});
|
|
316
317
|
|
|
318
|
+
// ─── Boot milestone bridge (ADR-0041 stage 2) ────────────────────────────────────────────────────
|
|
319
|
+
// One engine crosses each background boot stage once. Broadcast a one-shot `milestone` as it crosses
|
|
320
|
+
// `writeReady`/`bootSettled` (or a `milestone-error` if the tail rejects the stage), and FOLD the current
|
|
321
|
+
// set into every `attach-ack` so a tab that attached after a stage fired resolves it from the ack. The
|
|
322
|
+
// ack itself fires AT `localReadReady` (the Option B contract), so that stage needs no milestone. Wired
|
|
323
|
+
// exactly once off the booted client's stage promises (`milestonesWired`), then driven purely by them.
|
|
324
|
+
const milestones = { writeReady: false, bootSettled: false };
|
|
325
|
+
const stageErrors: {
|
|
326
|
+
writeReady?: { message: string; detail?: unknown };
|
|
327
|
+
bootSettled?: { message: string; detail?: unknown };
|
|
328
|
+
} = {};
|
|
329
|
+
let milestonesWired = false;
|
|
330
|
+
const markMilestone = (stage: BootMilestone) => {
|
|
331
|
+
if (milestones[stage]) return;
|
|
332
|
+
milestones[stage] = true;
|
|
333
|
+
broadcastEvent({ kind: "milestone", stage });
|
|
334
|
+
};
|
|
335
|
+
const failMilestone = (stage: BootMilestone, error: unknown) => {
|
|
336
|
+
if (stageErrors[stage]) return;
|
|
337
|
+
const serialized = serializeError(error);
|
|
338
|
+
stageErrors[stage] = serialized;
|
|
339
|
+
broadcastEvent({ kind: "milestone-error", stage, error: serialized });
|
|
340
|
+
};
|
|
341
|
+
// Attach-ack fold fields for a LATE attach — the milestones/failures already crossed at ack time.
|
|
342
|
+
const milestoneAckFields = () => ({
|
|
343
|
+
...(milestones.writeReady ? { writeReady: true as const } : {}),
|
|
344
|
+
...(milestones.bootSettled ? { bootSettled: true as const } : {}),
|
|
345
|
+
...(stageErrors.writeReady ? { writeReadyError: stageErrors.writeReady } : {}),
|
|
346
|
+
...(stageErrors.bootSettled ? { bootSettledError: stageErrors.bootSettled } : {}),
|
|
347
|
+
});
|
|
348
|
+
|
|
317
349
|
const boot = (attach: AttachPayload): Promise<SyncClient<TRegistry>> => {
|
|
318
350
|
if (bootPromise) return bootPromise;
|
|
319
351
|
// The tab is the auth owner: seed the cache with the token it presented at attach (decision 3).
|
|
@@ -400,6 +432,11 @@ export function defineSyncWorker<const TRegistry extends SyncTableRegistry>(
|
|
|
400
432
|
// Boot observability (ADR-0034): broadcast the finalized report to currently-attached ports (one-shot
|
|
401
433
|
// push). Later tabs read the same report via the `bootReport` pull RPC — there is no replay event.
|
|
402
434
|
onBootReport: (report) => broadcastEvent({ kind: "boot-report", report }),
|
|
435
|
+
// ADR-0041 stage 2 (Option B contract): `createSyncClient` resolves AT `localReadReady`, so the boot
|
|
436
|
+
// promise now resolves there too — the attach handler acks at local-read readiness and the write/sync
|
|
437
|
+
// tail runs in the background, announced to tabs via the `writeReady`/`bootSettled` milestone messages
|
|
438
|
+
// wired in the attach handler below. The stage-1 `await booted.bootSettled` shim is deleted: attach no
|
|
439
|
+
// longer waits for the whole boot, which is exactly the behavioural change this stage delivers.
|
|
403
440
|
});
|
|
404
441
|
return bootPromise;
|
|
405
442
|
};
|
|
@@ -746,18 +783,42 @@ export function defineSyncWorker<const TRegistry extends SyncTableRegistry>(
|
|
|
746
783
|
(booted) => {
|
|
747
784
|
client = booted;
|
|
748
785
|
resolveBooted(booted);
|
|
786
|
+
// Wire the engine's background stage promises to the milestone bridge exactly ONCE (ADR-0041
|
|
787
|
+
// stage 2). `createSyncClient` resolved at `localReadReady`, so by here the engine has crossed
|
|
788
|
+
// that stage — the ack below carries it implicitly. `writeReady`/`bootSettled` cross later (or
|
|
789
|
+
// fail): broadcast each as a one-shot `milestone`/`milestone-error` for currently-attached ports
|
|
790
|
+
// and fold the current set into every subsequent ack for late attachers.
|
|
791
|
+
if (!milestonesWired) {
|
|
792
|
+
milestonesWired = true;
|
|
793
|
+
void booted.writeReady.then(
|
|
794
|
+
() => markMilestone("writeReady"),
|
|
795
|
+
(error: unknown) => failMilestone("writeReady", error),
|
|
796
|
+
);
|
|
797
|
+
void booted.bootSettled.then(
|
|
798
|
+
() => markMilestone("bootSettled"),
|
|
799
|
+
(error: unknown) => failMilestone("bootSettled", error),
|
|
800
|
+
);
|
|
801
|
+
}
|
|
749
802
|
// Track the engine's monotonic `ready` edge exactly once, so a LATER attach acked after the
|
|
750
803
|
// initial sync landed can resolve its `ready` straight from the ack (ADR-0032 FIX 3).
|
|
751
804
|
if (!engineReadyFired) {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
805
|
+
// ADR-0041: `ready` can now reject if the background write/sync tail fails after the client was
|
|
806
|
+
// handed out; swallow that here so it is not an unhandled rejection (the failure surfaces to
|
|
807
|
+
// tabs via the `milestone-error` broadcast / the stage-error ack fold instead).
|
|
808
|
+
void booted.ready.then(
|
|
809
|
+
() => {
|
|
810
|
+
engineReadyFired = true;
|
|
811
|
+
},
|
|
812
|
+
() => undefined,
|
|
813
|
+
);
|
|
755
814
|
}
|
|
756
815
|
// Ack AFTER the engine exists so the tab's subsequent traffic (rpc/subscribe) has a client to
|
|
757
|
-
// hit;
|
|
816
|
+
// hit; the ack fires AT `localReadReady` (Option B) and folds the current milestone set +
|
|
817
|
+
// engine-ready edge for a late-joining tab (ADR-0041 / ADR-0032 FIX 3).
|
|
758
818
|
postBridgeMessage(port, codec, "attach-ack", {
|
|
759
819
|
alreadyBooted,
|
|
760
820
|
...(engineReadyFired ? { engineReady: true } : {}),
|
|
821
|
+
...milestoneAckFields(),
|
|
761
822
|
});
|
|
762
823
|
postBridgeMessage(port, codec, "event", { kind: "status", status: booted.status });
|
|
763
824
|
},
|
package/src/worker/protocol.ts
CHANGED
|
@@ -179,6 +179,15 @@ export interface SetOnlinePayload {
|
|
|
179
179
|
online: boolean;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
/**
|
|
183
|
+
* The two background boot stages the worker announces over the bridge as one-shot milestones (ADR-0041
|
|
184
|
+
* stage 2). `localReadReady` is NOT in this set: under the Option B contract the `attach-ack` fires AT the
|
|
185
|
+
* engine's `localReadReady`, so a tab resolves that stage from the ack itself (early OR late attach) — it
|
|
186
|
+
* needs no separate milestone. `writeReady` and `bootSettled` cross in the background write/sync tail, after
|
|
187
|
+
* the ack, so they DO ride milestone messages (and the late-attach ack fold).
|
|
188
|
+
*/
|
|
189
|
+
export type BootMilestone = "writeReady" | "bootSettled";
|
|
190
|
+
|
|
182
191
|
/** worker → tab: attach acknowledged. `alreadyBooted` is false for the attach that booted the engine. */
|
|
183
192
|
export interface AttachAckPayload {
|
|
184
193
|
alreadyBooted: boolean;
|
|
@@ -189,9 +198,28 @@ export interface AttachAckPayload {
|
|
|
189
198
|
* the ack, rather than wait for a phase-"ready" status that may never come again.
|
|
190
199
|
*/
|
|
191
200
|
engineReady?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Late-attach milestone fold (ADR-0041 stage 2): true when the engine had ALREADY crossed `writeReady` /
|
|
203
|
+
* `bootSettled` by the time this attach was acked, so a tab attaching after the stage fired resolves it
|
|
204
|
+
* straight from the ack rather than waiting for a `milestone` broadcast it missed. The ack fires AT
|
|
205
|
+
* `localReadReady`, so that stage is always implied by a non-error ack and carries no boolean.
|
|
206
|
+
*/
|
|
207
|
+
writeReady?: boolean;
|
|
208
|
+
bootSettled?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Late-attach failure fold (ADR-0041 stage 2): present when the engine's background write/sync tail had
|
|
211
|
+
* already REJECTED a downstream stage before this attach was acked. The tab rejects the matching stage
|
|
212
|
+
* promise (so a gated write / `bootSettled` awaiter fails loudly rather than hangs) — but the attach
|
|
213
|
+
* itself still RESOLVES (the engine reached `localReadReady`; only the tail failed). A live milestone
|
|
214
|
+
* failure after attach rides the `milestone-error` broadcast instead.
|
|
215
|
+
*/
|
|
216
|
+
writeReadyError?: { message: string; detail?: unknown };
|
|
217
|
+
bootSettledError?: { message: string; detail?: unknown };
|
|
192
218
|
/**
|
|
193
219
|
* Present when the engine boot REJECTED for this attach: the tab rejects `attachSyncClient` with this
|
|
194
|
-
* message instead of hanging forever on the ack (ADR-0032 FIX 1). A later attach retries the boot.
|
|
220
|
+
* message instead of hanging forever on the ack (ADR-0032 FIX 1). A later attach retries the boot. This
|
|
221
|
+
* is a LOCAL-READ-CORE failure (the engine never reached `localReadReady`); a tail failure after
|
|
222
|
+
* `localReadReady` uses the stage-error fields above and does NOT reject the attach.
|
|
195
223
|
*/
|
|
196
224
|
error?: { message: string; detail?: unknown };
|
|
197
225
|
}
|
|
@@ -363,6 +391,15 @@ export interface LiveDiffPayload {
|
|
|
363
391
|
export type BridgeEvent =
|
|
364
392
|
| { kind: "status"; status: SyncRuntimeStatus }
|
|
365
393
|
| { kind: "groupReady"; groupKey: string }
|
|
394
|
+
// Staged boot readiness (ADR-0041 stage 2): a one-shot milestone as the engine crosses a background boot
|
|
395
|
+
// stage (`writeReady` / `bootSettled`), broadcast to currently-attached ports. A tab attaching AFTER a
|
|
396
|
+
// stage fired never sees the broadcast — it folds the current milestone set off its `attach-ack` instead.
|
|
397
|
+
// One engine crosses each stage once; every port observes the same monotonic sequence (ack fold + event).
|
|
398
|
+
| { kind: "milestone"; stage: BootMilestone }
|
|
399
|
+
// The mirror failure edge: the background write/sync tail REJECTED a downstream stage (ADR-0041). Rejects
|
|
400
|
+
// the tab's matching `writeReady` / `bootSettled` promise so an awaiter fails loudly rather than hanging;
|
|
401
|
+
// `localReadReady` (and the resolved attach) are unaffected — the engine reached local-read readiness.
|
|
402
|
+
| { kind: "milestone-error"; stage: BootMilestone; error: { message: string; detail?: unknown } }
|
|
366
403
|
| { kind: "conflict"; details: unknown }
|
|
367
404
|
| { kind: "quarantine"; details: unknown }
|
|
368
405
|
| { kind: "reject"; details: unknown }
|