@pgxsinkit/client 0.2.4 → 0.2.6

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.
@@ -3,17 +3,18 @@ name: core
3
3
  description: >-
4
4
  Load when writing or reviewing code that uses @pgxsinkit/* (client, server, contracts, react) — the
5
5
  offline-first sync toolkit for the Postgres -> ElectricSQL -> PGlite read path and the client -> write
6
- API -> Postgres write path. Teaches the mental model the source does not make obvious: the two paths
7
- are separate and asymmetric, there is exactly one write path (an in-database apply function, not
8
- per-table CRUD), the Electric subquery flag is mandatory and fails closed, local PGlite schema is not
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".
6
+ API -> Postgres write path. Teaches the mental model the source does not make obvious: the two sync
7
+ paths are separate and asymmetric, there is exactly one write path (an in-database apply function, not
8
+ per-table CRUD), a third non-sync Event lane carries append-only facts, the Electric subquery flag is
9
+ mandatory and fails closed, local PGlite schema is not full DDL parity, writable tables must declare a
10
+ conflict policy plus managed fields, ordinary writes self-activate their lazy group, and authenticated
11
+ groups must not activate before claims exist. Load this before wiring sync, defining a registry, adding
12
+ an Event stream, or debugging "writes don't appear" / "an acked write stays pending" / "no rows stream"
13
+ / "a removed member still sees rows".
13
14
  metadata:
14
15
  type: core
15
16
  library: "@pgxsinkit/client"
16
- library_version: "0.2.4"
17
+ library_version: "0.2.6"
17
18
  source: https://pgxsinkit.github.io/llms-full.txt
18
19
  ---
19
20
 
@@ -24,13 +25,17 @@ are the product: `contracts` (the registry + shared types), `server` (the write
24
25
  proxy), `client` (local PGlite store + mutation runtime + convergence), and `react` (hooks). A consumer
25
26
  installs these and wires them; they do not "run pgxsinkit".
26
27
 
27
- ## The one idea everything else follows from: two separate, asymmetric paths
28
+ ## The one idea everything else follows from: two separate, asymmetric sync paths
28
29
 
29
30
  - **Read path:** Postgres → ElectricSQL → a server-side shape **proxy** (ownership-filtered) → local
30
31
  **PGlite**. Reads are served from PGlite.
31
32
  - **Write path:** client stages an optimistic local write → flushes a batch to the **write API** → one
32
33
  **in-database apply function** (`pgxsinkit_apply_mutations`) applies it under RLS → Postgres.
33
34
 
35
+ Those two are the **sync rail**, and almost everything below is about it. Beside them sits one more,
36
+ deliberately non-sync lane — the **Event lane** — for data that was never sync state (see below). So the
37
+ accurate count is two sync paths plus one event lane, not three paths.
38
+
34
39
  **Writes do not travel back to the writer through Electric.** The loop closes through Postgres: your
35
40
  write lands in Postgres, then streams back to _every_ subscriber (including you) as a normal Electric
36
41
  change, which clears the optimistic overlay. Do not look for a write to "come back" on the write
@@ -54,6 +59,34 @@ acked row **retires without a synced echo** (nothing local ever converges for it
54
59
  and throws at enqueue on an optimistic route. Never seed a phantom base row to satisfy `update` for an
55
60
  invisible target — that row + its overlay would linger forever behind the echo barrier; use `updateBlind`.
56
61
 
62
+ ## The third lane: Event streams are NOT the write path
63
+
64
+ High-volume, append-only client facts — "viewed this", interaction logs, review grades — are never edited,
65
+ never conflict, and are never read back down. They do not belong on a synced table (every client would
66
+ re-download its own log, and the conflict/overlay machinery would tax rows that cannot conflict). They go on
67
+ the **Event lane**, registered on the SAME registry under `streams` (the record key IS the stream name):
68
+
69
+ ```
70
+ appendEvent() → Outbox (durable, local-only) → flush → POST /api/events → queue → your consumer callback
71
+ ```
72
+
73
+ - **It is not a mutation.** No overlay, no echo, no conflict policy, no convergence — nothing comes back
74
+ down, and `appendEvent` resolves on **durable local enqueue, not on delivery** (it is `async`; its four
75
+ refusals — no streams registered, unknown stream, schema-invalid payload, oversized payload — REJECT the
76
+ promise, so `await`/`catch` it). Delivery is **at-least-once**: the server-side callback must be
77
+ idempotent, and deduping on the library-stamped `eventId` composes that to effectively-exactly-once.
78
+ - **Choose it over a writable table when the data is queue-shaped**: append-only, no client ever reads it
79
+ back, no per-row conflict, and volume high enough that syncing it would be self-inflicted. Choose a
80
+ `readwrite` table the moment anything needs to edit the row, resolve a conflict, show it optimistically,
81
+ or read it on another client. "Write-only table" (a `readwrite` entry that never streams) is the write
82
+ path's answer, not this lane's — that one still applies under RLS and acks per mutation.
83
+ - **Identity is server-stamped from verified claims** (`identity: { viewerId: { claimPath: ["sub"] } }`);
84
+ the client's envelope carries none, so never put an actor id in the payload. Object payloads must be
85
+ strict (`z.strictObject`), and a payload schema may evolve only backward-compatibly.
86
+ - The client-side surfaces are `onOutboxStatus` (drain signal) and `onEventLaneReport` (per-pass verdicts:
87
+ `acked` / `refused` / `rejected` / `deferred`, of which only `deferred` is non-terminal). Flush cadence
88
+ and batch caps are client config (`events`), never registry.
89
+
57
90
  ## Reading the local store: base table vs overlay view
58
91
 
59
92
  Reads run against local PGlite through the client, not hand-written SQL. For a **pure-Drizzle** read, pass
@@ -233,6 +266,11 @@ Backups, the SQL exports, and `restoreFrom` are there too.
233
266
 
234
267
  - Concepts: the two paths, read path, write path, Electric subqueries, local-schema DDL parity, and
235
268
  timestamps (microsecond BIGINT, decimal strings across the boundary).
269
+ - For the Event lane in full — the Outbox, verdicts, backpressure, the delivery contract and the limits —
270
+ read <https://pgxsinkit.github.io/concepts/event-lane/>, then load the skill for the half you are
271
+ writing: `operating` (@pgxsinkit/client) for the Outbox surfaces and flush tuning, `deploying`
272
+ (@pgxsinkit/server) for the ingest route, the pgmq/queue DDL and the consumer runner, and
273
+ `registry-authoring` (@pgxsinkit/contracts) for declaring a stream.
236
274
  - For deployment and runtime/operational behavior (cold starts, convergence cadence, the HTTP/2
237
275
  connection budget, the `globalThis.__pgxsinkitDebug` latency instrumentation), load the `operating`
238
276
  skill.