@pgxsinkit/client 0.1.46 → 0.1.49
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 +61 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +647 -72
- package/dist/index.js.map +11 -9
- package/dist/lazy-guard.d.ts +20 -1
- package/dist/lazy-guard.d.ts.map +1 -1
- package/dist/mutation.d.ts +10 -0
- package/dist/mutation.d.ts.map +1 -1
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +17 -0
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/live-query-fingerprint.d.ts +14 -0
- package/dist/worker/live-query-fingerprint.d.ts.map +1 -0
- package/dist/worker/live-query-manager.d.ts +130 -0
- package/dist/worker/live-query-manager.d.ts.map +1 -0
- package/dist/worker/protocol.d.ts +21 -5
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +2 -2
- package/skills/core/SKILL.md +25 -4
- package/skills/operating/SKILL.md +29 -1
- package/src/index.ts +243 -35
- package/src/lazy-guard.ts +67 -25
- package/src/mutation.ts +30 -0
- package/src/worker/attach-sync-client.ts +90 -16
- package/src/worker/define-sync-worker.ts +214 -52
- package/src/worker/live-query-fingerprint.ts +128 -0
- package/src/worker/live-query-manager.ts +591 -0
- package/src/worker/protocol.ts +23 -4
package/dist/lazy-guard.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
|
15
15
|
* objects that emit the SQL (`getTableConfig`/`getViewConfig`), so a token matches emission by
|
|
16
16
|
* construction — schema and all. See "Known limitations" in ADR-0021 for the residual edges.
|
|
17
17
|
*/
|
|
18
|
-
/** Static index of a registry's
|
|
18
|
+
/** Static index of a registry's synced relations and the exact quoted tokens their reads compile to. */
|
|
19
19
|
export interface LazyGuardIndex {
|
|
20
20
|
/** Registry keys whose subscription timing is `lazy`. */
|
|
21
21
|
readonly lazyKeys: ReadonlySet<string>;
|
|
@@ -27,6 +27,18 @@ export interface LazyGuardIndex {
|
|
|
27
27
|
* token collision-proof against bare aliases/CTEs.
|
|
28
28
|
*/
|
|
29
29
|
readonly lazyTokens: ReadonlyMap<string, readonly string[]>;
|
|
30
|
+
/**
|
|
31
|
+
* EVERY synced relation key (eager AND lazy). {@link lazyKeys} is a subset. Drives the hydration
|
|
32
|
+
* guarantee (ADR-0021/0032): a live subscription must gate `hydrating` on every consistency group it
|
|
33
|
+
* reads, not only the lazy ones — an eager group can still be catching up on a cold boot.
|
|
34
|
+
*/
|
|
35
|
+
readonly allKeys: ReadonlySet<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Per synced key (eager AND lazy), the exact quoted reference token(s) its reads compile to — the same
|
|
38
|
+
* token rules as {@link lazyTokens}, just spanning every subscription timing. {@link lazyTokens} is a
|
|
39
|
+
* subset restricted to the lazy keys (activation stays lazy-only; hydration spans all).
|
|
40
|
+
*/
|
|
41
|
+
readonly allTokens: ReadonlyMap<string, readonly string[]>;
|
|
30
42
|
}
|
|
31
43
|
/** Build the {@link LazyGuardIndex} for a registry. Cheap and pure — cache it per client. */
|
|
32
44
|
export declare function buildLazyGuardIndex(registry: SyncTableRegistry): LazyGuardIndex;
|
|
@@ -38,6 +50,13 @@ export declare function buildLazyGuardIndex(registry: SyncTableRegistry): LazyGu
|
|
|
38
50
|
* aliased and so needs no such guard.
|
|
39
51
|
*/
|
|
40
52
|
export declare function findReferencedLazyKeysInSql(sql: string, index: LazyGuardIndex): Set<string>;
|
|
53
|
+
/**
|
|
54
|
+
* The compiled-SQL scan across EVERY synced relation (eager AND lazy): the registry keys whose quoted
|
|
55
|
+
* reference token appears in `sql`. Same exact-token matching as {@link findReferencedLazyKeysInSql}, just
|
|
56
|
+
* over {@link LazyGuardIndex.allTokens}. Drives the hydration guarantee — the caller maps each key to its
|
|
57
|
+
* consistency group and gates a live subscription's `hydrating` on every group still catching up.
|
|
58
|
+
*/
|
|
59
|
+
export declare function findReferencedSyncedKeysInSql(sql: string, index: LazyGuardIndex): Set<string>;
|
|
41
60
|
/**
|
|
42
61
|
* The activation backstop (ADR-0021): throw if a query references a lazy relation that is still not
|
|
43
62
|
* active. Called *after* the referenced lazy relations have been activated, so in the normal path every
|
package/dist/lazy-guard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-guard.d.ts","sourceRoot":"","sources":["../src/lazy-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;;;;;;;;;;;GAeG;AAEH,
|
|
1
|
+
{"version":3,"file":"lazy-guard.d.ts","sourceRoot":"","sources":["../src/lazy-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;;;;;;;;;;;GAeG;AAEH,wGAAwG;AACxG,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;CAC5D;AA+BD,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,cAAc,CAmB/E;AAOD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,CAM3F;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,CAM7F;AAaD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC,GAAG,IAAI,CAIP;AAED,uHAAuH;AACvH,qBAAa,6BAA8B,SAAQ,KAAK;IACtD,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAEtC,YAAY,SAAS,EAAE,SAAS,MAAM,EAAE,EAUvC;CACF"}
|
package/dist/mutation.d.ts
CHANGED
|
@@ -104,6 +104,16 @@ export interface CreateMutationRuntimeOptions<TRegistry extends SyncTableRegistr
|
|
|
104
104
|
* surfaces the typed reason (e.g. "full") rather than a resolve/diff UI. Never silent.
|
|
105
105
|
*/
|
|
106
106
|
onReject?: (rejected: MutationDetail[]) => void | Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Invoked once per enqueue with the DISTINCT non-blind table keys of the planned batch (ADR-0039).
|
|
109
|
+
* An ordinary optimistic `create`/`update`/`delete` is a reference to its target, and a reference
|
|
110
|
+
* activates the target's lazy consistency group — the read path does this implicitly, the write path
|
|
111
|
+
* did not. The client wires this to a fire-and-forget `ensureSynced`, so the group is open by the time
|
|
112
|
+
* the echo returns. Purely-blind batches (only `updateBlind`) report nothing: a blind write is the
|
|
113
|
+
* deliberate no-echo, no-activation write-only exception. Fire-and-forget from the runtime's view —
|
|
114
|
+
* never awaited, and a throw here must never fail the enqueue (the runtime guards the call).
|
|
115
|
+
*/
|
|
116
|
+
onOrdinaryEnqueue?: (tables: readonly string[]) => void;
|
|
107
117
|
}
|
|
108
118
|
export interface MutationRuntime<TRegistry extends SyncTableRegistry> {
|
|
109
119
|
/** The registry fingerprint (ADR-0004) this runtime stamps onto enqueued mutations. */
|
package/dist/mutation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../src/mutation.ts"],"names":[],"mappings":"AA0EA,OAAO,KAAK,EAEV,WAAW,EACX,mBAAmB,EAEnB,oBAAoB,EAEpB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,SAAS,EACV,MAAM,sBAAsB,CAAC;AAa9B,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,iBAAiB,IAAI;KAClE,IAAI,IAAI,aAAa,CAAC,SAAS,CAAC,GAC7B;QACE,KAAK,EAAE,IAAI,CAAC;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,KAAK,EAAE,oBAAoB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;KAC9C,GACD;QACE,KAAK,EAAE,IAAI,CAAC;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClC,KAAK,EAAE,oBAAoB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC7C;;;;;WAKG;QACH,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,GACD;QACE,KAAK,EAAE,IAAI,CAAC;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACnC;CACN,CAAC,aAAa,CAAC,SAAS,C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OAAO,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAYzG;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,UAGzD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,MAAoB,UAG3F;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,MAAoB,UAE3G;AAED,wBAAgB,qBAAqB,CAAC,SAAS,SAAS,iBAAiB,EACvE,OAAO,EAAE,4BAA4B,CAAC,SAAS,CAAC,GAC/C,eAAe,CAAC,SAAS,CAAC,CA64B5B"}
|
|
@@ -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,
|
|
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,EAKL,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,EAaxB,MAAM,YAAY,CAAC;AAEpB,mHAAmH;AACnH,UAAU,U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,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,CA4iBxC;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"}
|
|
@@ -58,6 +58,23 @@ export interface DefineSyncWorkerOptions<TRegistry extends SyncTableRegistry> {
|
|
|
58
58
|
precreatedPglite?: CreateSyncClientOptions<TRegistry>["precreatedPglite"];
|
|
59
59
|
/** A fully-provisioned PGlite (forwarded to {@link CreateSyncClientOptions.pgliteInstance}; caller owns schema). */
|
|
60
60
|
pgliteInstance?: CreateSyncClientOptions<TRegistry>["pgliteInstance"];
|
|
61
|
+
/**
|
|
62
|
+
* Bounded zero-subscriber keep-alive for the live-query manager (ADR-0040 decision 4). When an entry's last
|
|
63
|
+
* subscriber leaves, a nonzero effective keep-alive retains its PGlite registration + diff state for a grace
|
|
64
|
+
* period so a matching resubscribe (e.g. a re-mounted route across tabs) reuses it verbatim — no ~400 ms
|
|
65
|
+
* re-materialization. Bounded by explicit budgets; DEFAULTS OFF (`defaultKeepAliveMs: 0` → tear a query
|
|
66
|
+
* down the instant its last consumer leaves, byte-identical to the pre-keep-alive behaviour). Standing
|
|
67
|
+
* argument for the 0 default: a retained entry STILL pays a full SQL rerun + diff on every dependent write —
|
|
68
|
+
* PGlite live queries cannot be paused — so retention only pays off for a genuinely hot, re-mounted query.
|
|
69
|
+
*/
|
|
70
|
+
liveQueries?: {
|
|
71
|
+
/** Baseline retention (ms) for a zero-subscriber entry; floored by each subscriber's own hint. Default 0. */
|
|
72
|
+
defaultKeepAliveMs?: number;
|
|
73
|
+
/** Max simultaneously-retained (zero-subscriber) entries — LRU-evicted past this. Default 16. */
|
|
74
|
+
maxRetainedQueries?: number;
|
|
75
|
+
/** Max total rows across all retained entries — LRU-evicted past this. Default 50_000. */
|
|
76
|
+
maxRetainedRows?: number;
|
|
77
|
+
};
|
|
61
78
|
}
|
|
62
79
|
/** The worker-side host: attach ports, await the boot, and (for tests) tear down. */
|
|
63
80
|
export interface SyncWorkerHost<TRegistry extends SyncTableRegistry> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-sync-worker.d.ts","sourceRoot":"","sources":["../../src/worker/define-sync-worker.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAoC,iBAAiB,EAAa,MAAM,sBAAsB,CAAC;AAI3G,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,uBAAuB,EAO5B,KAAK,UAAU,EAChB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"define-sync-worker.d.ts","sourceRoot":"","sources":["../../src/wor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,CAAC,kBAAkB,CAAC,CAAC;IAC1E,oHAAoH;IACpH,cAAc,CAAC,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACtE;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE;QACZ,6GAA6G;QAC7G,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,iGAAiG;QACjG,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,0FAA0F;QAC1F,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH;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;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,SAAS,SAAS,iBAAiB,EACxE,OAAO,EAAE,uBAAuB,CAAC,SAAS,CAAC,GAC1C,cAAc,CAAC,SAAS,CAAC,CA8uB3B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The map key (full canonical string — the dedup identity) plus a short digest for diagnostics (Slice 5). */
|
|
2
|
+
export interface LiveQueryFingerprint {
|
|
3
|
+
/** The exact dedup key: two subscriptions share a registration iff their `key` is identical. */
|
|
4
|
+
key: string;
|
|
5
|
+
/** A short, opaque hash of `key` — for diagnostics/observability only, NEVER used for dedup. */
|
|
6
|
+
digest: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Fingerprint a live query. `materialSql` is the POST-WRAP SQL (the manager's registration input); `params`
|
|
10
|
+
* are the decoded bound params; `pkColumns` selects the key mode. Returns the full canonical `key` (the dedup
|
|
11
|
+
* identity) and a short `digest` for diagnostics.
|
|
12
|
+
*/
|
|
13
|
+
export declare function fingerprintLiveQuery(materialSql: string, params: readonly unknown[], pkColumns?: readonly string[]): LiveQueryFingerprint;
|
|
14
|
+
//# sourceMappingURL=live-query-fingerprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-query-fingerprint.d.ts","sourceRoot":"","sources":["../../src/worker/live-query-fingerprint.ts"],"names":[],"mappings":"AAYA,8GAA8G;AAC9G,MAAM,WAAW,oBAAoB;IACnC,gGAAgG;IAChG,GAAG,EAAE,MAAM,CAAC;IACZ,gGAAgG;IAChG,MAAM,EAAE,MAAM,CAAC;CAChB;AAqFD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,SAAS,OAAO,EAAE,EAC1B,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAC5B,oBAAoB,CAetB"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { LiveNamespace } from "@electric-sql/pglite/live";
|
|
2
|
+
import type { LiveDiffPayload } from "./protocol";
|
|
3
|
+
type Row = Record<string, unknown>;
|
|
4
|
+
/** The wire diff a subscriber receives — exactly `computeLiveDiff`'s output, minus the caller's `queryId`. */
|
|
5
|
+
export type LiveDiffWire = Omit<LiveDiffPayload, "queryId">;
|
|
6
|
+
/** The two delivery callbacks a subscriber supplies; the caller wires these to its bridge posting. */
|
|
7
|
+
export interface LiveSubscriber {
|
|
8
|
+
/** The verbatim initial snapshot (NOT a diff), delivered ONCE before any diff (rows-before-diff ordering). */
|
|
9
|
+
deliverInitial(rows: readonly Row[]): void;
|
|
10
|
+
/** A subsequent change, already diffed against the last delivered set. */
|
|
11
|
+
deliverDiff(diff: LiveDiffWire): void;
|
|
12
|
+
}
|
|
13
|
+
/** Post-wrap SQL + bound params + optional single-column PK (selects `incrementalQuery` vs `query`). */
|
|
14
|
+
export interface LiveQuerySpec {
|
|
15
|
+
materialSql: string;
|
|
16
|
+
params: unknown[];
|
|
17
|
+
pkColumns?: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
/** Per-subscription options (ADR-0040). */
|
|
20
|
+
export interface LiveSubscribeOptions {
|
|
21
|
+
/**
|
|
22
|
+
* How long (ms) THIS subscriber asks the entry to be retained after IT (and any siblings) leave. The
|
|
23
|
+
* entry's effective keep-alive is `max(policy default, the max hint of the current active generation)`
|
|
24
|
+
* (see the generation rule on `subscribe`); the worker count/row budgets stay authoritative over any hint.
|
|
25
|
+
* Absent / 0 → no retention from this subscriber. Must be a finite number ≥ 0.
|
|
26
|
+
*/
|
|
27
|
+
keepAliveMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* An opaque grouping key for diagnostics only (ADR-0040 decision 5) — never part of the fingerprint, so it
|
|
30
|
+
* NEVER affects dedup or registration. The worker passes one stable scope per bridge port, so a snapshot's
|
|
31
|
+
* `scopeCount` reads as the distinct-tab count; the in-process client passes none.
|
|
32
|
+
*/
|
|
33
|
+
scope?: string;
|
|
34
|
+
}
|
|
35
|
+
/** A live registration's handle: awaited/tracked teardown and a coalesced refresh. */
|
|
36
|
+
export interface LiveSubscription {
|
|
37
|
+
/** Non-blocking for the caller; the promise is retained internally so `dispose()` awaits it (decision 1). */
|
|
38
|
+
unsubscribe(): Promise<void>;
|
|
39
|
+
/** Force one recompute; concurrent calls SHARE one underlying `live.refresh()` (never N stacked reruns). */
|
|
40
|
+
refresh(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/** The manager's bounded keep-alive policy (ADR-0040 decision 4). All fields default; the block is opt-in. */
|
|
43
|
+
export interface LiveQueryPolicy {
|
|
44
|
+
/**
|
|
45
|
+
* Default retention (ms) for a zero-subscriber entry, floored by each subscriber's own `keepAliveMs` hint.
|
|
46
|
+
* Default 0 — the current route-scoped behaviour (tear a query down the moment its last consumer leaves).
|
|
47
|
+
* The standing argument for 0: a retained zero-subscriber entry STILL pays a full SQL rerun + diff on every
|
|
48
|
+
* dependent-table write — PGlite live queries cannot be paused, only torn down — so retention trades that
|
|
49
|
+
* standing cost for avoiding re-materialization, and is only worth it for a genuinely hot, re-mounted query.
|
|
50
|
+
*/
|
|
51
|
+
defaultKeepAliveMs?: number;
|
|
52
|
+
/** Max simultaneously-retained (zero-subscriber) entries; LRU-evicted past this. Active entries never count. */
|
|
53
|
+
maxRetainedQueries?: number;
|
|
54
|
+
/** Max total rows held across ALL retained entries; LRU-evicted past this. Active entries never count. */
|
|
55
|
+
maxRetainedRows?: number;
|
|
56
|
+
}
|
|
57
|
+
type TimerHandle = unknown;
|
|
58
|
+
export interface LiveQueryManagerDeps {
|
|
59
|
+
/** The engine's `live` namespace — only the two registration entry points are used. */
|
|
60
|
+
live: Pick<LiveNamespace, "query" | "incrementalQuery">;
|
|
61
|
+
/** Bounded keep-alive policy (ADR-0040 decision 4); omitted → all defaults (retention off). */
|
|
62
|
+
policy?: LiveQueryPolicy;
|
|
63
|
+
/** Monotonic clock for keep-alive LRU accounting. Default `performance.now()` (Date.now fallback). */
|
|
64
|
+
now?: () => number;
|
|
65
|
+
/** Injectable eviction timer (tests drive it deterministically). Default `setTimeout`. */
|
|
66
|
+
setTimer?: (callback: () => void, ms: number) => TimerHandle;
|
|
67
|
+
/** Injectable timer cancel. Default `clearTimeout`. */
|
|
68
|
+
clearTimer?: (handle: TimerHandle) => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A structured-clone-safe, per-entry diagnostics record (ADR-0040 decision 5). It carries ONLY opaque
|
|
72
|
+
* fingerprint digests and counts/timings — NEVER SQL text, bound param values, or result-row values (those
|
|
73
|
+
* live only in the fingerprint's private `key`, which is deliberately absent here). Safe to cross the bridge
|
|
74
|
+
* and surface in support tooling.
|
|
75
|
+
*/
|
|
76
|
+
export interface LiveQueryDiagnostics {
|
|
77
|
+
/** The opaque fingerprint digest (a short hash — see live-query-fingerprint.ts). NEVER the full key. */
|
|
78
|
+
digest: string;
|
|
79
|
+
/** Current subscriber count (0 while retained). */
|
|
80
|
+
subscriberCount: number;
|
|
81
|
+
/**
|
|
82
|
+
* Distinct subscription scopes on this entry. The worker passes one scope per bridge port, so in WORKER
|
|
83
|
+
* mode this is the number of distinct tabs on the query; the in-process client passes none, so it stays 1
|
|
84
|
+
* while any subscriber is attached (0 while retained).
|
|
85
|
+
*/
|
|
86
|
+
scopeCount: number;
|
|
87
|
+
/** Rows currently held in the shared diff state. */
|
|
88
|
+
rowCount: number;
|
|
89
|
+
/** Whether this is a zero-subscriber entry currently kept alive (ADR-0040 decision 4). */
|
|
90
|
+
retained: boolean;
|
|
91
|
+
/** How many subscribes JOINED this entry rather than creating it (active-joins + retained rejoins). */
|
|
92
|
+
dedupHits: number;
|
|
93
|
+
/** Monotonic stamp (ms) when the entry was created. */
|
|
94
|
+
createdAt: number;
|
|
95
|
+
/** Time (ms) the registration setup took, or `null` until setup completes. */
|
|
96
|
+
setupMs: number | null;
|
|
97
|
+
/** Refresh timings for the shared registration (the hydration-chain / force refreshes). */
|
|
98
|
+
refresh: {
|
|
99
|
+
count: number;
|
|
100
|
+
lastMs: number | null;
|
|
101
|
+
totalMs: number;
|
|
102
|
+
maxMs: number;
|
|
103
|
+
};
|
|
104
|
+
/** Monotonic stamp (ms) of the last transition to zero subscribers, or `null` if never retained. */
|
|
105
|
+
lastUsedAt: number | null;
|
|
106
|
+
/** How long (ms) the entry has been retained (now − lastUsedAt), or `null` when not retained. */
|
|
107
|
+
retainedSinceMs: number | null;
|
|
108
|
+
/** A teardown is in flight (the entry is unsubscribing from PGlite). */
|
|
109
|
+
teardownPending: boolean;
|
|
110
|
+
}
|
|
111
|
+
export interface LiveQueryManager {
|
|
112
|
+
subscribe(spec: LiveQuerySpec, subscriber: LiveSubscriber, opts?: LiveSubscribeOptions): Promise<LiveSubscription>;
|
|
113
|
+
/** Tear down every live registration and await ALL teardowns (the Slice-1 close-vs-unsubscribe guard). */
|
|
114
|
+
dispose(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* A point-in-time diagnostics snapshot (ADR-0040 decision 5): one plain-object record per live entry,
|
|
117
|
+
* carrying digests + counts/timings only — NO SQL, params, or rows. For the `liveQueryDiagnostics` RPC and
|
|
118
|
+
* support tooling.
|
|
119
|
+
*/
|
|
120
|
+
snapshot(): LiveQueryDiagnostics[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Validate a keep-alive policy at the public boundary (ADR-0040 decision 4 — bounded, no permanent retention).
|
|
124
|
+
* Every provided field must be a finite number ≥ 0; the two budgets must additionally be integers. Throws a
|
|
125
|
+
* `TypeError` naming the offending field so a misconfiguration fails at construction, not at first subscribe.
|
|
126
|
+
*/
|
|
127
|
+
export declare function validateLiveQueryPolicy(policy: LiveQueryPolicy | undefined): void;
|
|
128
|
+
export declare function createLiveQueryManager(deps: LiveQueryManagerDeps): LiveQueryManager;
|
|
129
|
+
export {};
|
|
130
|
+
//# sourceMappingURL=live-query-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-query-manager.d.ts","sourceRoot":"","sources":["../../src/worker/live-query-manager.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAA+B,MAAM,2BAA2B,CAAC;AAK5F,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,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3C,0EAA0E;IAC1E,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CACvC;AAED,wGAAwG;AACxG,MAAM,WAAW,aAAa;IAC5B,WAAW,EA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C;IACxB;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,QAAQ,EAAE,OAAO,CAAC;IAClB,uGAAuG;IACvG,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,2FAA2F;IAC3F,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAClF,oGAAoG;IACpG,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,iGAAiG;IACjG,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,wEAAwE;IACxE,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACnH,0GAA0G;IAC1G,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB;;;;OAIG;IACH,QAAQ,IAAI,oBAAoB,EAAE,CAAC;CACpC;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,CAsBjF;AAyCD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,gBAAgB,CA8WnF"}
|
|
@@ -176,7 +176,7 @@ export interface TokenResponsePayload {
|
|
|
176
176
|
* The RPC ops the attach facade proxies to the worker's booted client — the write API (mirrors
|
|
177
177
|
* `client.mutate`/flush), mutation-state reads, and the one-shot raw inspection reads (`rawQuery`/`rawExec`).
|
|
178
178
|
*/
|
|
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";
|
|
179
|
+
export type RpcOp = "create" | "update" | "delete" | "batch" | "transaction" | "flush" | "reconcile" | "retryFailed" | "recoverSending" | "discardConflict" | "discardQuarantined" | "desync" | "discardEphemeral" | "readMutationDetails" | "diagnostics" | "rawQuery" | "rawExec" | "bootReport" | "liveQueryDiagnostics" | "exportStore" | "exportDiagnostics" | "exportData";
|
|
180
180
|
/** tab → worker: a write/read-of-mutation-state RPC. `id` correlates the matching {@link RpcResultPayload}. */
|
|
181
181
|
export interface RpcPayload {
|
|
182
182
|
op: RpcOp;
|
|
@@ -234,24 +234,40 @@ export interface SubscribePayload {
|
|
|
234
234
|
pkColumns?: string[];
|
|
235
235
|
/** Lazy relations to activate before the query runs (ADR-0021), forwarded to the worker's `prepareQuery`. */
|
|
236
236
|
use?: string[];
|
|
237
|
+
/**
|
|
238
|
+
* Per-subscription keep-alive hint (ms) for the worker's live-query manager (ADR-0040 decision 4): how long
|
|
239
|
+
* the shared registration should be retained after this subscription's last consumer leaves, so a matching
|
|
240
|
+
* resubscribe reuses it verbatim. ADDITIVE and backward-compatible both directions — an older tab omits it
|
|
241
|
+
* (the worker falls back to its `liveQueries.defaultKeepAliveMs`), and an older worker ignores it. Absent
|
|
242
|
+
* means "no hint".
|
|
243
|
+
*/
|
|
244
|
+
keepAliveMs?: number;
|
|
237
245
|
}
|
|
238
246
|
/** worker → tab: the initial ordered snapshot for a subscription. `id` correlates the `subscribe` request. */
|
|
239
247
|
export interface LiveInitialPayload {
|
|
240
248
|
queryId: string;
|
|
241
249
|
rows: Record<string, unknown>[];
|
|
242
250
|
/**
|
|
243
|
-
* The `lazy` relations the worker's guard activated for this query (ADR-0021)
|
|
244
|
-
* the
|
|
245
|
-
* `
|
|
251
|
+
* The `lazy` relations the worker's guard activated for this query (ADR-0021) — the relations held out
|
|
252
|
+
* of the eager boot set. Observability only: {@link hydratingTables}, not this, drives the tab's
|
|
253
|
+
* `hydrated` promise.
|
|
246
254
|
*/
|
|
247
255
|
lazyTables?: string[];
|
|
256
|
+
/**
|
|
257
|
+
* The referenced consistency groups' member tables (eager OR lazy) that were NOT YET caught up when this
|
|
258
|
+
* snapshot was taken (ADR-0021 / ADR-0032). Non-empty → the tab builds a `hydrated` promise the worker
|
|
259
|
+
* settles via `live-hydrated` (posted after the catch-up rows on this same port). Absent → every
|
|
260
|
+
* referenced group was already ready (steady state) or sync is disabled: nothing to hydrate.
|
|
261
|
+
*/
|
|
262
|
+
hydratingTables?: string[];
|
|
248
263
|
}
|
|
249
264
|
/**
|
|
250
265
|
* worker → tab: the subscription's lazy relations have completed their initial catch-up AND the live
|
|
251
266
|
* query has been refreshed against the caught-up store (ADR-0021). Posted on the SAME port as the
|
|
252
267
|
* live-diff stream, strictly after the refresh-triggered diff — so when the tab sees this, the rows
|
|
253
268
|
* 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
|
|
269
|
+
* promise (the React hooks' `hydrating` gate); never sent for a query with no pending groups (steady
|
|
270
|
+
* state / sync disabled), i.e. an empty `live-initial` {@link LiveInitialPayload.hydratingTables}.
|
|
255
271
|
*/
|
|
256
272
|
export interface LiveHydratedPayload {
|
|
257
273
|
queryId: string;
|
|
@@ -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,EA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U,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.49",
|
|
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.49"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@electric-sql/pglite": "0.5.4",
|
package/skills/core/SKILL.md
CHANGED
|
@@ -6,13 +6,14 @@ description: >-
|
|
|
6
6
|
API -> Postgres write path. Teaches the mental model the source does not make obvious: the two paths
|
|
7
7
|
are separate and asymmetric, there is exactly one write path (an in-database apply function, not
|
|
8
8
|
per-table CRUD), the Electric subquery flag is mandatory and fails closed, local PGlite schema is not
|
|
9
|
-
full DDL parity,
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
full DDL parity, writable tables must declare a conflict policy plus managed fields, ordinary writes
|
|
10
|
+
self-activate their lazy group, and authenticated groups must not activate before claims exist. Load
|
|
11
|
+
this before wiring sync, defining a registry, or debugging "writes don't appear" / "an acked write stays
|
|
12
|
+
pending" / "no rows stream" / "a removed member still sees rows".
|
|
12
13
|
metadata:
|
|
13
14
|
type: core
|
|
14
15
|
library: "@pgxsinkit/client"
|
|
15
|
-
library_version: "0.1.
|
|
16
|
+
library_version: "0.1.49"
|
|
16
17
|
source: https://pgxsinkit.github.io/llms-full.txt
|
|
17
18
|
---
|
|
18
19
|
|
|
@@ -65,6 +66,23 @@ the callback, reach relations through a directly-imported synced table/view obje
|
|
|
65
66
|
first-row-or-null variants. (Reactive equivalents: `useLiveDrizzleRows` for pure reads,
|
|
66
67
|
`useLiveQueryRaw({ use, build })` for raw fragments.)
|
|
67
68
|
|
|
69
|
+
**Auth-gated lazy groups.** A query that references one lazy relation activates its **whole consistency
|
|
70
|
+
group** with the claims available to that shape request. If the row filter returns `DENY_ALL` without a
|
|
71
|
+
user claim, do not let an authenticated-only query run while auth is unresolved: gate it (`ready: false`
|
|
72
|
+
in the React hooks) until the session exists. Making the group eager is not an equivalent fix — it can
|
|
73
|
+
open the same anonymous subscription during boot. A later auth notification can rotate/refetch the shape,
|
|
74
|
+
but the intended path is to activate it once with the correct claims. Activating a claims-denied group
|
|
75
|
+
with no auth token now emits a `console.warn` naming the group, so an accidental anonymous activation is
|
|
76
|
+
visible rather than silent.
|
|
77
|
+
|
|
78
|
+
Writes self-activate. An ordinary optimistic create/update/delete on a lazy `readwrite` entry activates
|
|
79
|
+
its group automatically at enqueue (a write is a reference, and a reference activates), so the Postgres
|
|
80
|
+
commit can echo through Electric and retire the acknowledged journal row — no manual activator query is
|
|
81
|
+
needed. Because that activation uses the claims available when the write runs, an authenticated-only group
|
|
82
|
+
still should not be written before the session exists (gate the write on auth, same as a read).
|
|
83
|
+
`updateBlind` is the deliberate exception: it has no overlay, does not activate its group, and retires on
|
|
84
|
+
the authoritative ack without an echo.
|
|
85
|
+
|
|
68
86
|
**Lint the split.** `@pgxsinkit/client` ships an oxlint rule via its `./oxlint` subpath export. Enable it
|
|
69
87
|
in the consuming repo's `.oxlintrc.jsonc` — `"jsPlugins": ["@pgxsinkit/client/oxlint"]` +
|
|
70
88
|
`"pgxsinkit/guarded-query-purity": "error"` — to catch a raw ``sql`…` `` fragment on the pure path and a
|
|
@@ -183,6 +201,9 @@ constraint that holds server-side also holds in PGlite.
|
|
|
183
201
|
- Writing directly to Postgres tables / building per-table CRUD instead of using the one write path.
|
|
184
202
|
- Reading a **readwrite** entry from its base `.table` instead of its `.view` overlay, so your own
|
|
185
203
|
optimistic writes do not appear locally until they round-trip through Postgres.
|
|
204
|
+
- Activating an authenticated lazy group before auth resolves — reading OR writing while claims are
|
|
205
|
+
unresolved activates the group against anonymous claims (now flagged by a console warning), leaving the
|
|
206
|
+
shape empty until a later rotation/refetch.
|
|
186
207
|
- Assuming PGlite enforces every Postgres constraint.
|
|
187
208
|
- Assuming a revoked member keeps their synced rows offline — membership changes converge both ways,
|
|
188
209
|
live and on resume.
|
|
@@ -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.49"
|
|
17
17
|
source: https://pgxsinkit.github.io/start/operating-in-production/
|
|
18
18
|
---
|
|
19
19
|
|
|
@@ -153,6 +153,34 @@ shows nothing" is worker mode working as designed, not an absence of requests. I
|
|
|
153
153
|
rejections surface only there). Full model:
|
|
154
154
|
<https://pgxsinkit.github.io/concepts/worker-mode/>.
|
|
155
155
|
|
|
156
|
+
## Live-query manager: dedup + keep-alive (ADR-0040)
|
|
157
|
+
|
|
158
|
+
Every reactive read (`useLiveDrizzleRows`/`useLiveQueryRaw`/`subscribeLiveRows`) is a **local SQL live
|
|
159
|
+
query**: PGlite materialises it once, then re-runs + diffs it on every write to its tables. That registration
|
|
160
|
+
is a real cost — ~a few hundred ms to materialise a heavy aggregate — and is **automatically deduplicated**:
|
|
161
|
+
identical queries (keyed on executed SQL + bound params, NOT `use`) share ONE registration and ONE re-run +
|
|
162
|
+
diff per write, fanned to every subscriber. So N components — or N tabs on the shared worker — on the same
|
|
163
|
+
query cost one materialisation, not N. You do nothing to get this.
|
|
164
|
+
|
|
165
|
+
Default lifetime is route-scoped: a live query is torn down the instant its last consumer unmounts, so a
|
|
166
|
+
navigate-away-and-back RE-materialises it. Opt a genuinely hot query into a grace period with a per-hook hint
|
|
167
|
+
`useLiveDrizzleRows(build, deps, { keepAliveMs: 30_000 })` (or the raw-hook / `subscribeLiveRows` field), or
|
|
168
|
+
set a worker/client-wide policy `defineSyncWorker({ …, liveQueries: { defaultKeepAliveMs, maxRetainedQueries,
|
|
169
|
+
maxRetainedRows } })` (defaults `0` / `16` / `50_000`; same block on `createSyncClient`). The effective
|
|
170
|
+
keep-alive is `max(default, subscribers' hints)`; the count/row budgets are authoritative over any hint and
|
|
171
|
+
LRU-evict zero-subscriber entries past them; active (still-subscribed) entries are never evicted.
|
|
172
|
+
|
|
173
|
+
**Keep the default 0 unless you have a specific hot query.** A retained zero-subscriber query is NOT paused —
|
|
174
|
+
PGlite live queries can't be — so it still pays a full re-run + diff on every write to its tables for as long
|
|
175
|
+
as it's held. Retention wins only for a frequently-re-mounted, write-COLD query; for a write-hot one it costs
|
|
176
|
+
more idle than the one re-materialisation it saves. For a fixed hot set, the endorsed "permanent" pattern is a
|
|
177
|
+
**mounted subscriber** (a root-provider hook that never unmounts) — one live registration for the app's life,
|
|
178
|
+
every route dedups onto it — not a retention setting; there is deliberately no retain-forever knob.
|
|
179
|
+
|
|
180
|
+
`client.liveQueryDiagnostics()` returns a per-entry snapshot — fingerprint DIGEST (never SQL/params/rows),
|
|
181
|
+
subscriber + row counts, setup/refresh timings, retention state — safe to log. The manager also emits
|
|
182
|
+
`live-query register|dedup-hit|retained|evicted|teardown-complete` lines on the debug rail (digests only).
|
|
183
|
+
|
|
156
184
|
## Store naming, backups, and restore (ADR-0035/0036)
|
|
157
185
|
|
|
158
186
|
**Stores are named by a plain `storePath`, never a storage URL.** The backend is derived (browser/worker →
|