@pgxsinkit/client 0.1.41 → 0.1.46
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 +40 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -19
- package/dist/index.js.map +6 -6
- 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 +17 -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 +6 -2
- package/src/index.ts +77 -20
- package/src/worker/attach-sync-client.ts +28 -1
- package/src/worker/define-sync-worker.ts +30 -2
- package/src/worker/protocol.ts +18 -0
|
@@ -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,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,EAGL,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAEhB,KAAK,UAAU,EACf,KAAK,kBAAkB,
|
|
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,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CAAC,SAAS,CAAC,GAC1C,cAAc,CAAC,SAAS,CAAC,CAomB3B"}
|
|
@@ -40,7 +40,7 @@ export interface BridgeEnvelope {
|
|
|
40
40
|
/** Codec-encoded body — opaque to the router; decode with the same {@link BridgeCodec}. */
|
|
41
41
|
payload: unknown;
|
|
42
42
|
}
|
|
43
|
-
export type BridgeMessageType = "provision" | "attach" | "detach" | "token-push" | "token-response" | "rpc" | "subscribe" | "unsubscribe" | "wake" | "set-online" | "provision-ack" | "attach-ack" | "token-request" | "rpc-result" | "live-initial" | "live-diff" | "event";
|
|
43
|
+
export type BridgeMessageType = "provision" | "attach" | "detach" | "token-push" | "token-response" | "rpc" | "subscribe" | "unsubscribe" | "wake" | "set-online" | "provision-ack" | "attach-ack" | "token-request" | "rpc-result" | "live-initial" | "live-diff" | "live-hydrated" | "event";
|
|
44
44
|
/** A single auth token snapshot the tab owns and pushes to the worker (ADR-0032 decision 3). */
|
|
45
45
|
export interface AuthTokenSnapshot {
|
|
46
46
|
accessToken: string;
|
|
@@ -239,6 +239,22 @@ export interface SubscribePayload {
|
|
|
239
239
|
export interface LiveInitialPayload {
|
|
240
240
|
queryId: string;
|
|
241
241
|
rows: Record<string, unknown>[];
|
|
242
|
+
/**
|
|
243
|
+
* The `lazy` relations the worker's guard activated for this query (ADR-0021). Streams are started but
|
|
244
|
+
* the initial catch-up may still be in flight when this snapshot is taken — the tab awaits its
|
|
245
|
+
* `groupReady` per key (fed by the worker's `groupReady` broadcasts) to know the rows are complete.
|
|
246
|
+
*/
|
|
247
|
+
lazyTables?: string[];
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* worker → tab: the subscription's lazy relations have completed their initial catch-up AND the live
|
|
251
|
+
* query has been refreshed against the caught-up store (ADR-0021). Posted on the SAME port as the
|
|
252
|
+
* live-diff stream, strictly after the refresh-triggered diff — so when the tab sees this, the rows
|
|
253
|
+
* reflecting the catch-up have already been delivered. Resolves the tab subscription's `hydrated`
|
|
254
|
+
* promise (the React hooks' `hydrating` gate); never sent for a query with no lazy relations.
|
|
255
|
+
*/
|
|
256
|
+
export interface LiveHydratedPayload {
|
|
257
|
+
queryId: string;
|
|
242
258
|
}
|
|
243
259
|
/**
|
|
244
260
|
* worker → tab: a DIFF update for a subscription (§4). Never a full result-set resend after the initial
|
|
@@ -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,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,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;IACnB,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,OAAO,cAAc,CAAC;IAC1B,CAAC,E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;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"tanstack-intent"
|
|
6
6
|
],
|
|
@@ -36,7 +36,7 @@
|
|
|
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.1.
|
|
39
|
+
"@pgxsinkit/contracts": "0.1.46"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@electric-sql/pglite": "0.5.4",
|
package/skills/core/SKILL.md
CHANGED
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: task
|
|
15
15
|
library: "@pgxsinkit/client"
|
|
16
|
-
library_version: "0.1.
|
|
16
|
+
library_version: "0.1.46"
|
|
17
17
|
source: https://pgxsinkit.github.io/start/operating-in-production/
|
|
18
18
|
---
|
|
19
19
|
|
|
@@ -146,7 +146,11 @@ clock and re-printed as `[pgxsinkit·w <ms>ms] …`, gated by that tab's own `gl
|
|
|
146
146
|
the flag on the TAB as usual; the write/read/boot phases below read the same, just origin-tagged. The front
|
|
147
147
|
half of boot runs on the FIRST attach before any tab is listening, so the worker buffers those pre-attach
|
|
148
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).
|
|
149
|
+
the boot's opening phases reach it too, ADR-0034). The worker's NETWORK traffic is invisible the same way:
|
|
150
|
+
shape requests never appear in the page's Network panel — "rail shows `shape request start`, Network tab
|
|
151
|
+
shows nothing" is worker mode working as designed, not an absence of requests. Inspect the worker itself
|
|
152
|
+
(`chrome://inspect/#workers` → inspect) for the real requests, status codes, and errors (e.g. CORS
|
|
153
|
+
rejections surface only there). Full model:
|
|
150
154
|
<https://pgxsinkit.github.io/concepts/worker-mode/>.
|
|
151
155
|
|
|
152
156
|
## Store naming, backups, and restore (ADR-0035/0036)
|
package/src/index.ts
CHANGED
|
@@ -615,6 +615,31 @@ export interface SubscribeLiveRowsInput {
|
|
|
615
615
|
export interface LiveRowsSubscription<TRow> {
|
|
616
616
|
initialRows: TRow[];
|
|
617
617
|
unsubscribe: () => void;
|
|
618
|
+
/**
|
|
619
|
+
* The `lazy` relations the query reads (the guard's scan). Activation (stream start) completed before
|
|
620
|
+
* the subscription registered, but the initial CATCH-UP may still be in flight — `initialRows` can be
|
|
621
|
+
* legitimately empty until it lands. Await {@link hydrated} for completion.
|
|
622
|
+
*/
|
|
623
|
+
lazyTables?: readonly string[];
|
|
624
|
+
/**
|
|
625
|
+
* Present only when the query reads `lazy` relations: resolves once their initial catch-up has
|
|
626
|
+
* completed AND this subscription has already delivered rows reflecting it (the seam refreshes the
|
|
627
|
+
* live query after catch-up, then resolves — rows-before-signal is guaranteed, so flipping a UI out
|
|
628
|
+
* of its loading state on this promise can never flash a false "empty"). Absent for an eager-only
|
|
629
|
+
* query (nothing to await). Offline note: stays pending until the catch-up truly completes — gate
|
|
630
|
+
* empty-state COPY on it, not data access (rows flow regardless).
|
|
631
|
+
*/
|
|
632
|
+
hydrated?: Promise<void>;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Result of {@link SyncClient.prepareQuery}: the `lazy` relations the guard scanned out of the SQL
|
|
637
|
+
* (∪ the explicit `use`) and activated. Activation means the group's STREAM IS STARTED — reads are
|
|
638
|
+
* safe from the tripwire — not that its initial catch-up has completed; await
|
|
639
|
+
* {@link SyncClient.groupReady} per key for that (see ADR-0021 / ADR-0032 decision 6).
|
|
640
|
+
*/
|
|
641
|
+
export interface PreparedQueryResult<TRegistry extends SyncTableRegistry> {
|
|
642
|
+
lazyTables: readonly SyncTableName<TRegistry>[];
|
|
618
643
|
}
|
|
619
644
|
|
|
620
645
|
export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
@@ -723,9 +748,12 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
|
723
748
|
) => Promise<TRows[number] | null>;
|
|
724
749
|
/**
|
|
725
750
|
* Activate one or more lazy relations (ADR-0021): open their consistency-group subscription if held
|
|
726
|
-
* out of the eager boot, resolving once
|
|
727
|
-
*
|
|
728
|
-
*
|
|
751
|
+
* out of the eager boot, resolving once each group's STREAM IS STARTED — reads are then tripwire-safe,
|
|
752
|
+
* but the initial catch-up may still be in flight (local rows can be legitimately empty/stale until it
|
|
753
|
+
* lands; await {@link groupReady} per relation for catch-up completion — deliberately separate so an
|
|
754
|
+
* offline client still reads its persisted local rows instead of hanging on the network). Idempotent —
|
|
755
|
+
* eager or already-started relations resolve immediately. Use to pre-activate before a
|
|
756
|
+
* raw/`client.drizzle` read, or as the manual escape hatch the tripwire points to.
|
|
729
757
|
*/
|
|
730
758
|
ensureSynced: (keys: readonly SyncTableName<TRegistry>[]) => Promise<void>;
|
|
731
759
|
/**
|
|
@@ -763,14 +791,16 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
|
763
791
|
discardEphemeral: (key: SyncTableName<TRegistry>) => Promise<void>;
|
|
764
792
|
/**
|
|
765
793
|
* The read-path safety seam (ADR-0021): scan the compiled `sql` for the lazy relations it reads
|
|
766
|
-
* (∪ the optional `use`)
|
|
767
|
-
*
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
794
|
+
* (∪ the optional `use`) and activate them — so a lazy relation auto-activates on *any* reference
|
|
795
|
+
* (FROM, JOIN, subquery, WHERE). Resolves once it is safe to run the query (streams started, tripwire
|
|
796
|
+
* satisfied) and returns the activated keys ({@link PreparedQueryResult}) so a consumer can further
|
|
797
|
+
* await {@link groupReady} per key for catch-up completion — the React hooks drive `hydrating` off
|
|
798
|
+
* exactly that. A backstop throws {@link LazyRelationNotActivatedError} only if a referenced relation
|
|
799
|
+
* could not be activated. Exposed for the React live hooks (which own their query build);
|
|
800
|
+
* `query`/`queryRow` are the higher-level non-live wrappers. Raw, non-Drizzle SQL is out of scope —
|
|
801
|
+
* pass `use`, or `ensureSynced` first.
|
|
772
802
|
*/
|
|
773
|
-
prepareQuery: (input: PrepareQueryInput<TRegistry>) => Promise<
|
|
803
|
+
prepareQuery: (input: PrepareQueryInput<TRegistry>) => Promise<PreparedQueryResult<TRegistry>>;
|
|
774
804
|
/**
|
|
775
805
|
* Author an atomic write-**unit** (ADR-0022 §2). The callback receives collecting table handles; every
|
|
776
806
|
* mutation it issues is tagged into one unit and enqueued atomically when the callback returns.
|
|
@@ -1386,6 +1416,17 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
1386
1416
|
await Promise.all([...groupKeys].map((groupKey) => activeSync.ensureGroupStarted(groupKey)));
|
|
1387
1417
|
};
|
|
1388
1418
|
|
|
1419
|
+
// Per-table catch-up completion (ADR-0032 decision 6) — the body of `client.groupReady`, hoisted so the
|
|
1420
|
+
// live-rows seam can also await it when building a subscription's `hydrated` promise.
|
|
1421
|
+
const groupReadyForTable = async (table: SyncTableName<TRegistry>): Promise<void> => {
|
|
1422
|
+
const activeSync = sync;
|
|
1423
|
+
// Sync disabled → local-only: every relation is trivially "ready" (nothing to await).
|
|
1424
|
+
if (activeSync == null) return;
|
|
1425
|
+
const groupKey = activeSync.groupKeyForTable(table as string);
|
|
1426
|
+
if (groupKey == null) return;
|
|
1427
|
+
await activeSync.groupReady(groupKey);
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1389
1430
|
const isSynced: SyncClient<TRegistry>["isSynced"] = (key) => {
|
|
1390
1431
|
const activeSync = sync;
|
|
1391
1432
|
// Sync disabled → local-only: reads hit whatever is in the local store, so nothing is "dormant".
|
|
@@ -1551,7 +1592,8 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
1551
1592
|
// subscription at worst, never a wrong result). Detection and activation are one step (ADR-0021).
|
|
1552
1593
|
const toActivate = new Set<string>(use ?? []);
|
|
1553
1594
|
for (const key of findReferencedLazyKeysInSql(sql, lazyGuardIndex)) toActivate.add(key);
|
|
1554
|
-
|
|
1595
|
+
const lazyTables = [...toActivate] as SyncTableName<TRegistry>[];
|
|
1596
|
+
await ensureSynced(lazyTables);
|
|
1555
1597
|
// Backstop: if a referenced lazy relation is somehow still not active (a failed start, or no group),
|
|
1556
1598
|
// throw rather than let the query read empty/stale. In the normal path everything scanned was just
|
|
1557
1599
|
// activated, so this passes.
|
|
@@ -1560,6 +1602,9 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
1560
1602
|
index: lazyGuardIndex,
|
|
1561
1603
|
isActive: (key) => isSynced(key as SyncTableName<TRegistry>),
|
|
1562
1604
|
});
|
|
1605
|
+
// Activated = streams started, NOT caught up. Hand back the keys so consumers (the React hooks'
|
|
1606
|
+
// `hydrating`) can await `groupReady` per key without blocking the read on the network.
|
|
1607
|
+
return { lazyTables };
|
|
1563
1608
|
};
|
|
1564
1609
|
|
|
1565
1610
|
const runGuardedQuery = async <TRows extends readonly unknown[]>(
|
|
@@ -1684,19 +1729,12 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
1684
1729
|
discardEphemeral,
|
|
1685
1730
|
prepareQuery,
|
|
1686
1731
|
transaction,
|
|
1687
|
-
groupReady:
|
|
1688
|
-
const activeSync = sync;
|
|
1689
|
-
// Sync disabled → local-only: every relation is trivially "ready" (nothing to await).
|
|
1690
|
-
if (activeSync == null) return;
|
|
1691
|
-
const groupKey = activeSync.groupKeyForTable(table as string);
|
|
1692
|
-
if (groupKey == null) return;
|
|
1693
|
-
await activeSync.groupReady(groupKey);
|
|
1694
|
-
},
|
|
1732
|
+
groupReady: groupReadyForTable,
|
|
1695
1733
|
// The live-rows seam over PGlite's own `live` extension (ADR-0032 S2 §4) — the EXACT call the React
|
|
1696
1734
|
// hooks made inline before the seam existed (`pglite.live.query` → `initialResults.rows` + `subscribe`),
|
|
1697
1735
|
// so the in-process path is unchanged. `pkColumns` is unused here: PGlite's live query already diffs
|
|
1698
1736
|
// incrementally against its own materialized state; the column set only matters for the worker bridge.
|
|
1699
|
-
subscribeLiveRows: async ({ sql, params, fields }, onRows) => {
|
|
1737
|
+
subscribeLiveRows: async ({ sql, params, fields, use }, onRows) => {
|
|
1700
1738
|
// Render the query safe to materialise: a JOIN with same-named columns fails `live.query`'s
|
|
1701
1739
|
// temp-view creation (`column "title" specified more than once`) unless every output column has a
|
|
1702
1740
|
// unique alias. No `fields` → SQL unchanged (backward-compatible name-keyed rows).
|
|
@@ -1706,11 +1744,30 @@ export async function createSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
1706
1744
|
onRows(results.rows as never);
|
|
1707
1745
|
};
|
|
1708
1746
|
registered.subscribe(listener);
|
|
1747
|
+
let unsubscribed = false;
|
|
1748
|
+
// The query's lazy relations (guard scan ∪ `use`; the caller's `prepareQuery` already activated
|
|
1749
|
+
// them). When present, build the `hydrated` promise with rows-before-signal ordering: await the
|
|
1750
|
+
// groups' catch-up, refresh the live query against the caught-up store (its listener delivers the
|
|
1751
|
+
// rows synchronously inside the refresh), THEN resolve — matching the worker bridge's contract.
|
|
1752
|
+
const lazySet = new Set<string>(use ?? []);
|
|
1753
|
+
for (const key of findReferencedLazyKeysInSql(sql, lazyGuardIndex)) lazySet.add(key);
|
|
1754
|
+
const lazyTables = [...lazySet];
|
|
1755
|
+
const hydrated =
|
|
1756
|
+
lazyTables.length > 0
|
|
1757
|
+
? Promise.all(lazyTables.map((table) => groupReadyForTable(table as SyncTableName<TRegistry>)))
|
|
1758
|
+
.then(async () => {
|
|
1759
|
+
if (!unsubscribed) await registered.refresh();
|
|
1760
|
+
})
|
|
1761
|
+
.catch(() => undefined)
|
|
1762
|
+
: undefined;
|
|
1709
1763
|
return {
|
|
1710
1764
|
initialRows: registered.initialResults.rows as never,
|
|
1711
1765
|
unsubscribe: () => {
|
|
1766
|
+
unsubscribed = true;
|
|
1712
1767
|
void registered.unsubscribe(listener);
|
|
1713
1768
|
},
|
|
1769
|
+
...(lazyTables.length > 0 ? { lazyTables } : {}),
|
|
1770
|
+
...(hydrated ? { hydrated } : {}),
|
|
1714
1771
|
};
|
|
1715
1772
|
},
|
|
1716
1773
|
// Boot observability (ADR-0034): the finalized report (null before initial sync completes / after an
|
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
identityCodec,
|
|
49
49
|
isBridgeEnvelope,
|
|
50
50
|
type LiveDiffPayload,
|
|
51
|
+
type LiveHydratedPayload,
|
|
51
52
|
type LiveInitialPayload,
|
|
52
53
|
postBridgeMessage,
|
|
53
54
|
type ProvisionAckPayload,
|
|
@@ -151,6 +152,10 @@ export async function attachSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
151
152
|
{ resolve: (payload: LiveInitialPayload) => void; reject: (error: Error) => void }
|
|
152
153
|
>();
|
|
153
154
|
const diffHandlers = new Map<string, (diff: Omit<LiveDiffPayload, "queryId">) => void>();
|
|
155
|
+
// Resolvers for per-subscription `hydrated` promises, keyed by queryId. The worker posts
|
|
156
|
+
// `live-hydrated` on the same port as the diff stream, strictly after the catch-up rows — so
|
|
157
|
+
// resolution here guarantees the rows have already been applied by the materializer.
|
|
158
|
+
const hydratedPending = new Map<string, () => void>();
|
|
154
159
|
|
|
155
160
|
// ─── Status + readiness ──────────────────────────────────────────────────────────────────────────
|
|
156
161
|
const status: SyncRuntimeStatus = { phase: "booting", isRunning: false };
|
|
@@ -305,6 +310,12 @@ export async function attachSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
305
310
|
diffHandlers.get(diff.queryId)?.(diff);
|
|
306
311
|
break;
|
|
307
312
|
}
|
|
313
|
+
case "live-hydrated": {
|
|
314
|
+
const { queryId } = payload as LiveHydratedPayload;
|
|
315
|
+
hydratedPending.get(queryId)?.();
|
|
316
|
+
hydratedPending.delete(queryId);
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
308
319
|
case "event":
|
|
309
320
|
onEvent(payload as BridgeEvent);
|
|
310
321
|
break;
|
|
@@ -409,12 +420,27 @@ export async function attachSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
409
420
|
throw error;
|
|
410
421
|
}
|
|
411
422
|
const initialRows = materializer.seed(initial.rows as TRow[]);
|
|
423
|
+
// Lazy relations present → build the `hydrated` promise the worker settles via `live-hydrated`
|
|
424
|
+
// (posted after the catch-up rows on the same port — rows-before-signal). Resolved on unsubscribe
|
|
425
|
+
// too, so an abandoned subscription never leaves a forever-pending promise behind.
|
|
426
|
+
let hydrated: Promise<void> | undefined;
|
|
427
|
+
if (initial.lazyTables) {
|
|
428
|
+
hydrated = new Promise<void>((resolve) => {
|
|
429
|
+
hydratedPending.set(queryId, resolve);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
412
432
|
return {
|
|
413
433
|
initialRows,
|
|
414
434
|
unsubscribe: () => {
|
|
415
435
|
diffHandlers.delete(queryId);
|
|
436
|
+
hydratedPending.get(queryId)?.();
|
|
437
|
+
hydratedPending.delete(queryId);
|
|
416
438
|
postBridgeMessage(port, codec, "unsubscribe", { queryId });
|
|
417
439
|
},
|
|
440
|
+
// The lazy relations the worker's guard activated for this query — streams started, catch-up
|
|
441
|
+
// possibly still in flight; `hydrated` resolves once the caught-up rows have been delivered.
|
|
442
|
+
...(initial.lazyTables ? { lazyTables: initial.lazyTables } : {}),
|
|
443
|
+
...(hydrated ? { hydrated } : {}),
|
|
418
444
|
};
|
|
419
445
|
};
|
|
420
446
|
|
|
@@ -504,7 +530,8 @@ export async function attachSyncClient<const TRegistry extends SyncTableRegistry
|
|
|
504
530
|
discardEphemeral: (key) => rpc<void>("discardEphemeral", [key]),
|
|
505
531
|
// The worker activates lazy relations inside its `subscribe` handler (via the `use` hint), so the tab's
|
|
506
532
|
// `prepareQuery` is a no-op — the live-rows subscription is already guarded worker-side (ADR-0021).
|
|
507
|
-
|
|
533
|
+
// Empty `lazyTables`: the real scan's keys travel back on the subscription itself (`live-initial`).
|
|
534
|
+
prepareQuery: async () => ({ lazyTables: [] }),
|
|
508
535
|
transaction: async ({ mode }: { mode: WriteMode }, run) => {
|
|
509
536
|
// Collect the unit's mutations tab-side (the run callback cannot cross the wire), then RPC the
|
|
510
537
|
// serialized items + mode; the worker replays them into a real `client.transaction` (matching acks).
|
|
@@ -451,7 +451,9 @@ export function defineSyncWorker<const TRegistry extends SyncTableRegistry>(
|
|
|
451
451
|
// Activate any lazy relations the query reads BEFORE registering the live query (ADR-0021) — the worker
|
|
452
452
|
// owns the real client, so its `prepareQuery` does the real work; the tab's `prepareQuery` is a no-op.
|
|
453
453
|
// Scan the ORIGINAL sql (the wrap only adds an outer `SELECT * FROM (...)`; table refs are inside).
|
|
454
|
-
|
|
454
|
+
// The activated keys travel back on the initial snapshot: activation is stream-start, not catch-up,
|
|
455
|
+
// so the tab needs them to await `groupReady` (its `hydrating` signal) without blocking this register.
|
|
456
|
+
const prepared = await active.prepareQuery({ sql, ...(use ? { use: use as SyncTableName<TRegistry>[] } : {}) });
|
|
455
457
|
|
|
456
458
|
const live = active.pglite.live;
|
|
457
459
|
// Render the query safe to materialise: a JOIN with same-named columns fails BOTH live APIs' temp-view
|
|
@@ -469,7 +471,17 @@ export function defineSyncWorker<const TRegistry extends SyncTableRegistry>(
|
|
|
469
471
|
|
|
470
472
|
const state = seedLiveDiffState(registered.initialResults.rows, pkColumns);
|
|
471
473
|
// Initial snapshot verbatim (not a diff), correlated to the subscribe request so the tab resolves.
|
|
472
|
-
postBridgeMessage(
|
|
474
|
+
postBridgeMessage(
|
|
475
|
+
port,
|
|
476
|
+
codec,
|
|
477
|
+
"live-initial",
|
|
478
|
+
{
|
|
479
|
+
queryId,
|
|
480
|
+
rows: registered.initialResults.rows,
|
|
481
|
+
...(prepared.lazyTables.length > 0 ? { lazyTables: prepared.lazyTables.map(String) } : {}),
|
|
482
|
+
},
|
|
483
|
+
id,
|
|
484
|
+
);
|
|
473
485
|
|
|
474
486
|
const listener = (results: { rows: Record<string, unknown>[] }) => {
|
|
475
487
|
// `subscribe` fires only on a real change (never the initial), so every fire yields a genuine delta.
|
|
@@ -481,6 +493,22 @@ export function defineSyncWorker<const TRegistry extends SyncTableRegistry>(
|
|
|
481
493
|
port,
|
|
482
494
|
unsubscribe: () => void registered.unsubscribe(listener),
|
|
483
495
|
});
|
|
496
|
+
|
|
497
|
+
// Hydration completion travels the SAME port as the diff stream, so ordering is guaranteed: await the
|
|
498
|
+
// lazy groups' catch-up, force one refresh of the live query against the caught-up store (its listener
|
|
499
|
+
// posts the rows as a live-diff, synchronously inside the refresh), THEN post `live-hydrated`. The tab
|
|
500
|
+
// therefore always has the caught-up rows before its `hydrated` resolves — a readiness signal on a side
|
|
501
|
+
// channel (e.g. the `groupReady` broadcast) can beat the rows and flash a false "empty" state.
|
|
502
|
+
if (prepared.lazyTables.length > 0) {
|
|
503
|
+
void Promise.all(prepared.lazyTables.map((key) => active.groupReady(key)))
|
|
504
|
+
.then(async () => {
|
|
505
|
+
if (!liveSubs.has(queryId)) return; // unsubscribed while catching up
|
|
506
|
+
await registered.refresh();
|
|
507
|
+
if (!liveSubs.has(queryId)) return;
|
|
508
|
+
postBridgeMessage(port, codec, "live-hydrated", { queryId });
|
|
509
|
+
})
|
|
510
|
+
.catch(() => undefined); // a torn-down engine mid-catch-up must not surface as an unhandled rejection
|
|
511
|
+
}
|
|
484
512
|
};
|
|
485
513
|
|
|
486
514
|
// ─── Per-port message routing ────────────────────────────────────────────────────────────────────
|
package/src/worker/protocol.ts
CHANGED
|
@@ -71,6 +71,7 @@ export type BridgeMessageType =
|
|
|
71
71
|
| "rpc-result"
|
|
72
72
|
| "live-initial"
|
|
73
73
|
| "live-diff"
|
|
74
|
+
| "live-hydrated"
|
|
74
75
|
| "event";
|
|
75
76
|
|
|
76
77
|
// ─── Payload shapes ───────────────────────────────────────────────────────────
|
|
@@ -304,6 +305,23 @@ export interface SubscribePayload {
|
|
|
304
305
|
export interface LiveInitialPayload {
|
|
305
306
|
queryId: string;
|
|
306
307
|
rows: Record<string, unknown>[];
|
|
308
|
+
/**
|
|
309
|
+
* The `lazy` relations the worker's guard activated for this query (ADR-0021). Streams are started but
|
|
310
|
+
* the initial catch-up may still be in flight when this snapshot is taken — the tab awaits its
|
|
311
|
+
* `groupReady` per key (fed by the worker's `groupReady` broadcasts) to know the rows are complete.
|
|
312
|
+
*/
|
|
313
|
+
lazyTables?: string[];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* worker → tab: the subscription's lazy relations have completed their initial catch-up AND the live
|
|
318
|
+
* query has been refreshed against the caught-up store (ADR-0021). Posted on the SAME port as the
|
|
319
|
+
* live-diff stream, strictly after the refresh-triggered diff — so when the tab sees this, the rows
|
|
320
|
+
* reflecting the catch-up have already been delivered. Resolves the tab subscription's `hydrated`
|
|
321
|
+
* promise (the React hooks' `hydrating` gate); never sent for a query with no lazy relations.
|
|
322
|
+
*/
|
|
323
|
+
export interface LiveHydratedPayload {
|
|
324
|
+
queryId: string;
|
|
307
325
|
}
|
|
308
326
|
|
|
309
327
|
/**
|