@pgxsinkit/client 0.2.7 → 0.3.0
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/README.md +2 -1
- package/dist/boot-report.d.ts +5 -2
- package/dist/boot-report.d.ts.map +1 -1
- package/dist/circuits/envelope-to-change.d.ts +35 -0
- package/dist/circuits/envelope-to-change.d.ts.map +1 -0
- package/dist/circuits/group-sync.d.ts +123 -0
- package/dist/circuits/group-sync.d.ts.map +1 -0
- package/dist/circuits/shape-group.d.ts +77 -0
- package/dist/circuits/shape-group.d.ts.map +1 -0
- package/dist/circuits/stream-inbox.d.ts +126 -0
- package/dist/circuits/stream-inbox.d.ts.map +1 -0
- package/dist/circuits/stream-source.d.ts +90 -0
- package/dist/circuits/stream-source.d.ts.map +1 -0
- package/dist/circuits/subscription-client.d.ts +143 -0
- package/dist/circuits/subscription-client.d.ts.map +1 -0
- package/dist/circuits/sync-engine.d.ts +131 -0
- package/dist/circuits/sync-engine.d.ts.map +1 -0
- package/dist/debug.d.ts +0 -10
- package/dist/debug.d.ts.map +1 -1
- package/dist/export-dump.d.ts.map +1 -1
- package/dist/index.d.ts +47 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6258 -6443
- package/dist/index.js.map +26 -26
- package/dist/local-tables.d.ts +1 -1
- package/dist/local-tables.d.ts.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/sync/apply.d.ts +13 -21
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/copy.d.ts +8 -8
- package/dist/sync/fold.d.ts +40 -0
- package/dist/sync/fold.d.ts.map +1 -0
- package/dist/sync/metadata-tables.d.ts +25 -1
- package/dist/sync/metadata-tables.d.ts.map +1 -1
- package/dist/sync/subscription-state.d.ts +21 -2
- package/dist/sync/subscription-state.d.ts.map +1 -1
- package/dist/sync/types.d.ts +9 -129
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/testing.js +3 -3
- package/dist/testing.js.map +2 -2
- package/dist/worker/attach-sync-client.d.ts +3 -1
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +17 -1
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/engine-control.d.ts +53 -0
- package/dist/worker/engine-control.d.ts.map +1 -1
- package/package.json +4 -5
- package/skills/core/SKILL.md +72 -55
- package/skills/operating/SKILL.md +120 -120
- package/src/boot-report.ts +4 -3
- package/src/circuits/envelope-to-change.ts +102 -0
- package/src/circuits/group-sync.ts +1047 -0
- package/src/circuits/shape-group.ts +158 -0
- package/src/circuits/stream-inbox.ts +225 -0
- package/src/circuits/stream-source.ts +165 -0
- package/src/circuits/subscription-client.ts +353 -0
- package/src/circuits/sync-engine.ts +641 -0
- package/src/debug.ts +1 -85
- package/src/export-dump.ts +3 -2
- package/src/index.ts +290 -273
- package/src/lazy-guard.ts +1 -1
- package/src/local-tables.ts +9 -2
- package/src/schema.ts +2 -11
- package/src/sync/apply.ts +72 -110
- package/src/sync/copy.ts +15 -15
- package/src/sync/fold.ts +94 -0
- package/src/sync/metadata-tables.ts +42 -1
- package/src/sync/subscription-state.ts +21 -3
- package/src/sync/types.ts +13 -141
- package/src/testing.ts +2 -2
- package/src/worker/attach-sync-client.ts +8 -1
- package/src/worker/define-sync-worker.ts +122 -13
- package/src/worker/engine-control.ts +89 -0
- package/dist/read-stream-stall.d.ts +0 -54
- package/dist/read-stream-stall.d.ts.map +0 -1
- package/dist/shape-sync.d.ts +0 -207
- package/dist/shape-sync.d.ts.map +0 -1
- package/dist/sync/index.d.ts +0 -32
- package/dist/sync/index.d.ts.map +0 -1
- package/dist/sync/nudge.d.ts +0 -49
- package/dist/sync/nudge.d.ts.map +0 -1
- package/dist/sync/shape-inbox.d.ts +0 -215
- package/dist/sync/shape-inbox.d.ts.map +0 -1
- package/dist/sync/tags.d.ts +0 -142
- package/dist/sync/tags.d.ts.map +0 -1
- package/dist/sync-auth.d.ts +0 -53
- package/dist/sync-auth.d.ts.map +0 -1
- package/src/read-stream-stall.ts +0 -102
- package/src/shape-sync.ts +0 -533
- package/src/sync/index.ts +0 -1124
- package/src/sync/nudge.ts +0 -110
- package/src/sync/shape-inbox.ts +0 -566
- package/src/sync/tags.ts +0 -390
- package/src/sync-auth.ts +0 -117
|
@@ -27,7 +27,10 @@ export interface DefineSyncWorkerOptions<TRegistry extends SyncTableRegistry> {
|
|
|
27
27
|
* Takes a plain store PATH (ADR-0036); the internal `backendOverride` is the test lane's memory selection.
|
|
28
28
|
*/
|
|
29
29
|
createPglite?: (storePath: string, backendOverride?: "memory") => Promise<ClientPGlite>;
|
|
30
|
-
|
|
30
|
+
/** The pgxsinkit control plane — subscribe, token re-mint, convergence barrier (ADR-0055). */
|
|
31
|
+
controlPlaneUrl: string;
|
|
32
|
+
/** The edge that serves durable-streams reads. */
|
|
33
|
+
streamBaseUrl: string;
|
|
31
34
|
batchWriteUrl: string;
|
|
32
35
|
/** Static headers on every read + write request (e.g. a gateway `apikey`). See `createSyncClient`. */
|
|
33
36
|
requestHeaders?: Record<string, string>;
|
|
@@ -69,6 +72,19 @@ export interface DefineSyncWorkerOptions<TRegistry extends SyncTableRegistry> {
|
|
|
69
72
|
* channel to probe, so an enabled value is rejected as unsupported before engine boot.
|
|
70
73
|
*/
|
|
71
74
|
executionLimit?: ExecutionLimitConfig;
|
|
75
|
+
/**
|
|
76
|
+
* How long an attach may wait for the engine's IN-FLIGHT spare provision (ADR-0032 decision 5) before it
|
|
77
|
+
* fails typed with {@link ProvisionStalledError} instead of waiting. Measured from the provision attempt's
|
|
78
|
+
* START, not from the attach — a tab attaching late inherits however much of the budget the spare has
|
|
79
|
+
* already burned. The stalled attempt is LEFT RUNNING (an in-flight OPFS/IDB store open cannot be safely
|
|
80
|
+
* abandoned — a second open against the same store is an ownership conflict), so a later attach still
|
|
81
|
+
* ADOPTS it if it completes; refusing costs at most one extra initdb, never data (the spare is schemaless
|
|
82
|
+
* and holds no writes). Default 20000. `Number.POSITIVE_INFINITY` restores the unbounded wait (NOT
|
|
83
|
+
* recommended: a stalled spare then hangs every attach forever). Must be > 0 — anything else throws at
|
|
84
|
+
* construction. This bounds the ACCELERATOR only; nothing is inferred from it about engine liveness
|
|
85
|
+
* (ADR-0049 D5's refusal of timing-based engine-death detection is unchanged).
|
|
86
|
+
*/
|
|
87
|
+
provisionAdoptionBudgetMs?: number;
|
|
72
88
|
/** Injected transport binder. Defaults to auto-detecting the SharedWorker/dedicated-worker global scope. */
|
|
73
89
|
installGlobal?: boolean;
|
|
74
90
|
/** Injected codec (ADR-0032 S2 §1). Defaults to the v1 identity codec. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-sync-worker.d.ts","sourceRoot":"","sources":["../../src/worker/define-sync-worker.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAGV,sBAAsB,EAEtB,iBAAiB,EAElB,MAAM,sBAAsB,CAAC;AAa9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,uBAAuB,EAO5B,KAAK,UAAU,EAChB,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,KAAK,oBAAoB,EAAuB,MAAM,oBAAoB,CAAC;AAGpF,OAAO,EAML,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"define-sync-worker.d.ts","sourceRoot":"","sources":["../../src/worker/define-sync-worker.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAGV,sBAAsB,EAEtB,iBAAiB,EAElB,MAAM,sBAAsB,CAAC;AAa9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,uBAAuB,EAO5B,KAAK,UAAU,EAChB,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,KAAK,oBAAoB,EAAuB,MAAM,oBAAoB,CAAC;AAGpF,OAAO,EAML,KAAK,oBAAoB,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c,CAAC,EAAE,oBAAoB,CAAC;IACtC;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC,oHAAoH;IACpH,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnD,wEAAwE;IACxE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,IAAI,CAAC;IAC3D;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC7C;AAED,oHAAoH;AACpH,MAAM,WAAW,yBAAyB;IACxC,0GAA0G;IAC1G,UAAU,EAAE,iBAAiB,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IACxD,oHAAoH;IACpH,WAAW,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAqCD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI,CA8C1E"}
|
|
@@ -275,5 +275,58 @@ export declare function engineRelocatedToWire(error: EngineRelocatedError): Engi
|
|
|
275
275
|
* missing outcome, a non-object) — so a non-relocation error is never misclassified.
|
|
276
276
|
*/
|
|
277
277
|
export declare function engineRelocatedFromWire(detail: unknown): EngineRelocatedError | undefined;
|
|
278
|
+
/** The stable clone-safe discriminator a stalled spare adoption carries on the wire. Branch on this, never prose. */
|
|
279
|
+
export declare const PROVISION_STALLED_CODE = "provision-stalled";
|
|
280
|
+
/**
|
|
281
|
+
* The clone-safe wire form of a stalled spare adoption. Like the execution-limit and relocation errors it
|
|
282
|
+
* travels inside the EXISTING bridge error `detail` field (the `{ message, detail }` shape `serializeError`
|
|
283
|
+
* produces), so no new protocol field is needed; the attach side calls {@link provisionStalledFromWire} on
|
|
284
|
+
* every bridge error `detail` and rebuilds the CLASS.
|
|
285
|
+
*/
|
|
286
|
+
export interface ProvisionStalledWire {
|
|
287
|
+
code: typeof PROVISION_STALLED_CODE;
|
|
288
|
+
storePath: string;
|
|
289
|
+
elapsedMs: number;
|
|
290
|
+
budgetMs: number;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Thrown at attach when the engine's IN-FLIGHT spare provision (the pre-spawned schemaless store of ADR-0032
|
|
294
|
+
* decision 5) has not settled within the engine's `provisionAdoptionBudgetMs` — measured from the provision
|
|
295
|
+
* attempt's START, not from this attach. The spare is a pure ACCELERATOR, never a boot dependency, so an
|
|
296
|
+
* attach must never hang behind one: past the budget the attach is REFUSED typed, and the host can rebind to
|
|
297
|
+
* a fresh store (or retry) instead of sitting on "starting local database…" forever.
|
|
298
|
+
*
|
|
299
|
+
* What this is NOT: engine-death detection. Nothing is inferred about the engine's liveness from the elapsed
|
|
300
|
+
* time (ADR-0049 D5 refuses timing-based death inference, unchanged). The stalled attempt is deliberately LEFT
|
|
301
|
+
* RUNNING — an in-flight OPFS/IDB store open cannot be safely abandoned, a second open against the same store
|
|
302
|
+
* being an ownership conflict — so a later attach still ADOPTS it if it completes. Abandoning a slow spare
|
|
303
|
+
* costs at most one extra initdb, never data: the spare is schemaless and holds no writes.
|
|
304
|
+
*
|
|
305
|
+
* Survives the worker bridge AS THIS CLASS via the tagged {@link ProvisionStalledWire} `detail` (the same
|
|
306
|
+
* tagged-detail pair the execution-limit and relocation errors use), so a consumer can `instanceof`-branch it.
|
|
307
|
+
*/
|
|
308
|
+
export declare class ProvisionStalledError extends Error {
|
|
309
|
+
readonly code = "provision-stalled";
|
|
310
|
+
/** The store whose in-flight spare provision has not settled. */
|
|
311
|
+
readonly storePath: string;
|
|
312
|
+
/** How long that provision attempt has been running, in ms (measured from ITS start). */
|
|
313
|
+
readonly elapsedMs: number;
|
|
314
|
+
/** The budget it outran, in ms (the engine's effective `provisionAdoptionBudgetMs`). */
|
|
315
|
+
readonly budgetMs: number;
|
|
316
|
+
constructor(init: {
|
|
317
|
+
storePath: string;
|
|
318
|
+
elapsedMs: number;
|
|
319
|
+
budgetMs: number;
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/** Encode a {@link ProvisionStalledError} to its clone-safe wire form for the bridge error `detail` field. */
|
|
323
|
+
export declare function provisionStalledToWire(error: ProvisionStalledError): ProvisionStalledWire;
|
|
324
|
+
/**
|
|
325
|
+
* Reconstruct a typed {@link ProvisionStalledError} from a bridge error's `detail`. STRICT shape check:
|
|
326
|
+
* returns `undefined` for anything that is not exactly the `{ code: "provision-stalled", storePath,
|
|
327
|
+
* elapsedMs, budgetMs }` wire form (a foreign/absent detail, a wrong code, a missing/mistyped field, a
|
|
328
|
+
* non-object), so an unrelated failure is never misclassified as a stalled spare.
|
|
329
|
+
*/
|
|
330
|
+
export declare function provisionStalledFromWire(detail: unknown): ProvisionStalledError | undefined;
|
|
278
331
|
export {};
|
|
279
332
|
//# sourceMappingURL=engine-control.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-control.d.ts","sourceRoot":"","sources":["../../src/worker/engine-control.ts"],"names":[],"mappings":"AAYA,+EAA+E;AAC/E,eAAO,MAAM,2BAA2B,EAAG,SAAkB,CAAC;AAE9D,yFAAyF;AACzF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG;IAClE,CAAC,2BAA2B,CAAC,EAAE,oBAAoB,CAAC;CACrD,CAEA;AAED,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAMnF;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,mGAAmG;IACnG,YAAY,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,+FAA+F;AAC/F,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,GAAG,OAAO,CAElF;AAED;;;;GAI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AC,MAAM,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAMzF;AAID,qHAAqH;AACrH,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,OAAO,sBAAsB,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,uBAA0B;IACvC,iEAAiE;IACjE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,YAAY,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAc3E;CACF;AAED,8GAA8G;AAC9G,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,qBAAqB,GAAG,oBAAoB,CAOzF;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,qBAAqB,GAAG,SAAS,CAW3F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"tanstack-intent"
|
|
6
6
|
],
|
|
@@ -33,11 +33,10 @@
|
|
|
33
33
|
"build": "bun --cwd ../.. run build:public-packages"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@electric-sql/experimental": "^6.0.26",
|
|
36
|
+
"@durable-streams/client": "0.2.6",
|
|
38
37
|
"@electric-sql/pglite-tools": "0.4.5",
|
|
39
|
-
"@pgxsinkit/contracts": "0.
|
|
40
|
-
"@pgxsinkit/pglite-opfs-repacked": "0.
|
|
38
|
+
"@pgxsinkit/contracts": "0.3.0",
|
|
39
|
+
"@pgxsinkit/pglite-opfs-repacked": "0.3.0"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
43
42
|
"@electric-sql/pglite": ">=0.5.5-pgx.0 <0.5.5",
|
package/skills/core/SKILL.md
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: core
|
|
3
3
|
description: >-
|
|
4
|
-
Load when writing or reviewing code that uses @pgxsinkit/*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/ "
|
|
4
|
+
Load when writing or reviewing code that uses @pgxsinkit/* — the offline-first sync toolkit for the
|
|
5
|
+
Postgres -> Circuits engine -> durable-streams -> PGlite read path and the client -> write API ->
|
|
6
|
+
Postgres write path. Teaches the model the source does not make obvious: the two sync paths are
|
|
7
|
+
separate and asymmetric, exactly one write path (an in-database apply function, not per-table CRUD), a
|
|
8
|
+
non-sync Event lane carries append-only facts, a client asks the control plane for its streams
|
|
9
|
+
(controlPlaneUrl + streamBaseUrl, both or neither) and reads fail closed twice — 401 control plane, 403
|
|
10
|
+
edge — local PGlite schema is not full DDL parity, writable tables must declare a conflict policy plus
|
|
11
|
+
managed fields, ordinary writes self-activate their lazy group, and authenticated groups must not
|
|
12
|
+
activate before claims exist. Load before wiring sync, defining a registry, adding an Event stream, or
|
|
13
|
+
debugging "writes don't appear" / "an acked write stays pending" / "no rows stream" / "a removed
|
|
14
|
+
member still sees rows".
|
|
14
15
|
metadata:
|
|
15
16
|
type: core
|
|
16
17
|
library: "@pgxsinkit/client"
|
|
17
|
-
library_version: "0.
|
|
18
|
+
library_version: "0.3.0"
|
|
18
19
|
source: https://pgxsinkit.github.io/llms-full.txt
|
|
19
20
|
---
|
|
20
21
|
|
|
21
22
|
# Using pgxsinkit correctly
|
|
22
23
|
|
|
23
24
|
pgxsinkit is a **toolkit**, not a database, a framework, or the demo app. The `@pgxsinkit/*` packages
|
|
24
|
-
are the product: `contracts` (the registry + shared types), `server` (the write API
|
|
25
|
-
|
|
26
|
-
installs these and wires them; they do not "run pgxsinkit".
|
|
25
|
+
are the product: `contracts` (the registry + shared types), `server` (the write API, the read path's
|
|
26
|
+
**control plane**, and the **stream edge**), `client` (local PGlite store + mutation runtime +
|
|
27
|
+
convergence), and `react` (hooks). A consumer installs these and wires them; they do not "run pgxsinkit".
|
|
27
28
|
|
|
28
29
|
## The one idea everything else follows from: two separate, asymmetric sync paths
|
|
29
30
|
|
|
30
|
-
- **Read path:** Postgres →
|
|
31
|
-
**
|
|
31
|
+
- **Read path:** Postgres → the **Circuits engine** (ingests logical replication and maintains the shapes
|
|
32
|
+
the control plane creates) → **durable-streams** → the **edge** (token-gated) → local **PGlite**. The
|
|
33
|
+
client does not
|
|
34
|
+
construct a stream URL: it subscribes through the **control plane**, which decides which streams that
|
|
35
|
+
subject may read and hands back their paths. Reads are served from PGlite.
|
|
32
36
|
- **Write path:** client stages an optimistic local write → flushes a batch to the **write API** → one
|
|
33
37
|
**in-database apply function** (`pgxsinkit_apply_mutations`) applies it under RLS → Postgres.
|
|
34
38
|
|
|
@@ -36,10 +40,10 @@ Those two are the **sync rail**, and almost everything below is about it. Beside
|
|
|
36
40
|
deliberately non-sync lane — the **Event lane** — for data that was never sync state (see below). So the
|
|
37
41
|
accurate count is two sync paths plus one event lane, not three paths.
|
|
38
42
|
|
|
39
|
-
**Writes do not travel back to the writer
|
|
40
|
-
write lands in Postgres, then streams back to _every_ subscriber (including you) as
|
|
41
|
-
change, which clears the optimistic overlay. Do not look for a write to "come back" on the write
|
|
42
|
-
|
|
43
|
+
**Writes do not travel back to the writer on the write channel.** The loop closes through Postgres: your
|
|
44
|
+
write lands in Postgres, then streams back to _every_ subscriber (including you) as an ordinary read-path
|
|
45
|
+
change, which clears the optimistic overlay. Do not look for a write to "come back" on the write channel,
|
|
46
|
+
and do not try to write down the read path — it is read transport only.
|
|
43
47
|
|
|
44
48
|
## There is exactly one write path
|
|
45
49
|
|
|
@@ -100,17 +104,18 @@ first-row-or-null variants. (Reactive equivalents: `useLiveDrizzleRows` for pure
|
|
|
100
104
|
`useLiveQueryRaw({ use, build })` for raw fragments.)
|
|
101
105
|
|
|
102
106
|
**Auth-gated lazy groups.** A query that references one lazy relation activates its **whole consistency
|
|
103
|
-
group
|
|
104
|
-
user claim, do not let an authenticated-only query run while auth is
|
|
105
|
-
in the React hooks) until the session exists. Making the group eager
|
|
106
|
-
open the same anonymous subscription during boot.
|
|
107
|
-
|
|
107
|
+
group**, subscribing with the claims available at that moment. If the row filter returns
|
|
108
|
+
`DENY_ALL_PREDICATE` without a user claim, do not let an authenticated-only query run while auth is
|
|
109
|
+
unresolved: gate it (`ready: false` in the React hooks) until the session exists. Making the group eager
|
|
110
|
+
is not an equivalent fix — it can open the same anonymous subscription during boot. The control plane
|
|
111
|
+
declines a denied shape outright, so the group settles "ready" with nothing granted and stays empty;
|
|
112
|
+
activate it once with the correct claims instead. Activating a claims-denied group
|
|
108
113
|
with no auth token now emits a `console.warn` naming the group, so an accidental anonymous activation is
|
|
109
114
|
visible rather than silent.
|
|
110
115
|
|
|
111
116
|
Writes self-activate. An ordinary optimistic create/update/delete on a lazy `readwrite` entry activates
|
|
112
117
|
its group automatically at enqueue (a write is a reference, and a reference activates), so the Postgres
|
|
113
|
-
commit can echo
|
|
118
|
+
commit can echo down the read path and retire the acknowledged journal row — no manual activator query is
|
|
114
119
|
needed. Because that activation uses the claims available when the write runs, an authenticated-only group
|
|
115
120
|
still should not be written before the session exists (gate the write on auth, same as a read).
|
|
116
121
|
`updateBlind` is the deliberate exception: it has no overlay, does not activate its group, and retires on
|
|
@@ -129,7 +134,7 @@ redundant `use` (autofixable), the two things the types can't. (oxlint `jsPlugin
|
|
|
129
134
|
(not-yet-synced) writes on top of the synced base rows. Read it from the entry's **`.view`**
|
|
130
135
|
(`registry.<name>.view`) — **not** its `.table`. Selecting the base `.table` of a readwrite entry
|
|
131
136
|
silently omits the writer's own pending writes, so a just-issued create/edit/delete will not appear
|
|
132
|
-
locally until it round-trips through Postgres and streams back
|
|
137
|
+
locally until it round-trips through Postgres and streams back down the read path.
|
|
133
138
|
|
|
134
139
|
```ts
|
|
135
140
|
// readonly entry → base table
|
|
@@ -140,7 +145,7 @@ const reportView = registry.report.view!; // `.view` is populated only for readw
|
|
|
140
145
|
client.query((c) => c.drizzle.select({ id: reportView.id, status: reportView.status }).from(reportView));
|
|
141
146
|
```
|
|
142
147
|
|
|
143
|
-
This is the read-side twin of "writes return
|
|
148
|
+
This is the read-side twin of "writes return down the read path": your optimistic write is visible
|
|
144
149
|
immediately **only because you read the overlay view**; the base table catches up when Postgres streams the
|
|
145
150
|
committed row back. (`c.views.<name>` is the client's accessor for the same overlay views; the entry's
|
|
146
151
|
`.view` object is the direct handle. Type note: `.view` is typed as optional on a `SyncTableEntry`, so a
|
|
@@ -174,11 +179,10 @@ directly (a test, a perf harness, a diagnostic), not a replacement for it.
|
|
|
174
179
|
|
|
175
180
|
## Non-negotiables (each fails closed or throws)
|
|
176
181
|
|
|
177
|
-
1. **The
|
|
178
|
-
`
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
ask Electric to enable subqueries for your source, or self-host Electric with the flag.
|
|
182
|
+
1. **The read path is two URLs, both or neither.** `createSyncClient` / `defineSyncWorker` take
|
|
183
|
+
`controlPlaneUrl` (subscribe, stream-token re-mint, the convergence barrier) **and** `streamBaseUrl`
|
|
184
|
+
(the edge that serves durable-streams reads). They are separate deployments — the edge belongs on its
|
|
185
|
+
own origin, because the cache key is the URL — so supplying one without the other **throws** at boot.
|
|
182
186
|
2. **Writable tables have two hard requirements.** `defineSyncRegistry` throws unless every `readwrite`
|
|
183
187
|
table declares **both** a server-version managed field (a `nowMicroseconds`-on-update column,
|
|
184
188
|
conventionally `updated_at_us`, that optimistic convergence keys on) **and** a `conflictPolicy`
|
|
@@ -187,9 +191,14 @@ directly (a test, a perf harness, a diagnostic), not a replacement for it.
|
|
|
187
191
|
3. **Managed fields are server-assigned.** Fields stamped by `authClaim` (a verified claim at a JSON path —
|
|
188
192
|
`["sub"]` is the old `auth.uid()` owner idiom) / `nowMicroseconds` are set by the apply function; the
|
|
189
193
|
write API **rejects** a client payload that includes them. Never send them.
|
|
190
|
-
4. **
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
4. **Read authorization fails closed in two places, and they mean different things.** The control plane
|
|
195
|
+
answers **401** when the deployment's `resolveAuthClaims` yields no `sub` (the client reports
|
|
196
|
+
`auth-needed` and keeps retrying for a fresh token — an expired JWT is retryable, not a refusal); the
|
|
197
|
+
edge answers **403** for a stream token that expired or names a scope the subject no longer holds — the
|
|
198
|
+
client re-mints once, and a second rejection is read as revocation, so it truncates that scope and
|
|
199
|
+
unsubscribes. A `rowFilter` that restricts nothing —
|
|
200
|
+
no `customPredicate` and no `columns` allow-list — is **refused at definition time** rather than
|
|
201
|
+
quietly compiled into a shape with no subject test.
|
|
193
202
|
|
|
194
203
|
## Authorization runs in two engines — derive both from one predicate
|
|
195
204
|
|
|
@@ -198,25 +207,31 @@ engines, so the subject is referenced two ways:
|
|
|
198
207
|
|
|
199
208
|
- **Write path — RLS in Postgres:** policies use `auth.uid()` / `current_setting('request.jwt.claims')`;
|
|
200
209
|
the applier sets the claims before applying a batch.
|
|
201
|
-
- **Read path — the shape `rowFilter`:** the
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
210
|
+
- **Read path — the shape `rowFilter`:** the **control plane** compiles the filter once, at shape creation,
|
|
211
|
+
and posts it to the engine — so `customPredicate` returns a **predicate AST**, not SQL text. Author it
|
|
212
|
+
with the `p.*` builders over real Drizzle columns (`p.eq`, `p.and`/`p.or`/`p.not`, `p.in` +
|
|
213
|
+
`p.subquery`); `null` bypasses filtering (every row) and `DENY_ALL_PREDICATE` denies. There is no string
|
|
214
|
+
to escape and no grammar to satisfy, and comparisons are checked against the column's own TypeScript
|
|
215
|
+
type — a mistyped enum label or a `jsonb`/`Date` column with no scalar wire form is a compile error.
|
|
205
216
|
|
|
206
217
|
Use `buildSupabaseOwnerOrAdminNativePolicies` / `buildSupabaseMembershipNativePolicies` for the common
|
|
207
218
|
owner/membership shapes — they take **Drizzle columns**, so call them in `defineSyncTable`'s `extras`
|
|
208
219
|
callback; compose your own from `pgPolicy` + Drizzle operators for anything beyond them (e.g. collaborative
|
|
209
|
-
any-member writes).
|
|
210
|
-
|
|
220
|
+
any-member writes). Each ships its read-path mirror (`buildOwnerOrAdminShapePredicate`,
|
|
221
|
+
`buildMembershipShapePredicate`, `buildGrantScopeAccessShapePredicate`), so build the read filter and the
|
|
222
|
+
RLS policy from the same Drizzle columns and they cannot drift.
|
|
211
223
|
|
|
212
224
|
## Membership changes converge the local store — both ways, even offline
|
|
213
225
|
|
|
214
|
-
A subquery (membership) read filter is reactive in **both** directions,
|
|
215
|
-
re-subscribe: granting a membership **materialises** the container's rows
|
|
216
|
-
revoking one **evicts** them (a row reachable through a second membership
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
226
|
+
A subquery (membership) read filter — `p.in(col, p.subquery(…))` — is reactive in **both** directions,
|
|
227
|
+
against a running client with no re-subscribe: granting a membership **materialises** the container's rows
|
|
228
|
+
in the member's local PGlite; revoking one **evicts** them (a row reachable through a second membership
|
|
229
|
+
survives until its last grant is gone). The engine **states** each side rather than implying it: the wire
|
|
230
|
+
carries `upsert | delete`, so a row leaving your shape arrives as an explicit `delete` envelope. This holds
|
|
231
|
+
**live and across an offline gap** — a client disconnected when the membership changed converges on
|
|
232
|
+
reconnect (it resumes from its per-stream offset and replays what it missed), so a revoked member's read
|
|
233
|
+
access never lingers offline. Observe it on the live subscription or a normal resume, not by re-reading a
|
|
234
|
+
stream from the start.
|
|
220
235
|
|
|
221
236
|
## Local PGlite schema is not full DDL parity
|
|
222
237
|
|
|
@@ -227,16 +242,18 @@ constraint that holds server-side also holds in PGlite.
|
|
|
227
242
|
|
|
228
243
|
## Common mistakes
|
|
229
244
|
|
|
230
|
-
- Expecting an optimistic write to echo back on the write channel — it returns
|
|
231
|
-
-
|
|
245
|
+
- Expecting an optimistic write to echo back on the write channel — it returns down the read path.
|
|
246
|
+
- Configuring `controlPlaneUrl` without `streamBaseUrl` (or the reverse) — it throws; they are two
|
|
247
|
+
deployments, and the edge belongs on its own origin.
|
|
232
248
|
- Omitting `conflictPolicy` (throws) or sending a managed field in a write payload (rejected).
|
|
233
|
-
-
|
|
249
|
+
- Declaring a `rowFilter` that restricts nothing (no `customPredicate`, no `columns`) — refused at
|
|
250
|
+
definition time, because the compiled shape would carry no subject test.
|
|
234
251
|
- Writing directly to Postgres tables / building per-table CRUD instead of using the one write path.
|
|
235
252
|
- Reading a **readwrite** entry from its base `.table` instead of its `.view` overlay, so your own
|
|
236
253
|
optimistic writes do not appear locally until they round-trip through Postgres.
|
|
237
254
|
- Activating an authenticated lazy group before auth resolves — reading OR writing while claims are
|
|
238
|
-
unresolved
|
|
239
|
-
|
|
255
|
+
unresolved subscribes against anonymous claims (now flagged by a console warning), and the control plane
|
|
256
|
+
grants nothing, so the group stays empty until it is desynced and referenced again.
|
|
240
257
|
- Assuming PGlite enforces every Postgres constraint.
|
|
241
258
|
- Assuming a revoked member keeps their synced rows offline — membership changes converge both ways,
|
|
242
259
|
live and on resume.
|
|
@@ -264,8 +281,8 @@ Backups, the SQL exports, and `restoreFrom` are there too.
|
|
|
264
281
|
|
|
265
282
|
## Where to look
|
|
266
283
|
|
|
267
|
-
- Concepts: the two paths, read path, write path,
|
|
268
|
-
|
|
284
|
+
- Concepts: the two paths, read path, write path, local-schema DDL parity, and timestamps (microsecond
|
|
285
|
+
BIGINT, decimal strings across the boundary).
|
|
269
286
|
- For the Event lane in full — the Outbox, verdicts, backpressure, the delivery contract and the limits —
|
|
270
287
|
read <https://pgxsinkit.github.io/concepts/event-lane/>, then load the skill for the half you are
|
|
271
288
|
writing: `operating` (@pgxsinkit/client) for the Outbox surfaces and flush tuning, `deploying`
|