@pgxsinkit/client 0.2.2 → 0.2.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"engine-router.d.ts","sourceRoot":"","sources":["../../src/worker/engine-router.ts"],"names":[],"mappings":"AAqBA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAE1B,MAAM,kBAAkB,CAAC;AAE1B;;;;GAIG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC9D,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;CACpB;AAED,yGAAyG;AACzG,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAChD,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,mBAAmB;IAClC,6GAA6G;IAC7G,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,oFAAoF;IACpF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,4GAA4G;IAC5G,UAAU,CAAC,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
1
  {
2
2
  "name": "@pgxsinkit/client",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "keywords": [
5
5
  "tanstack-intent"
6
6
  ],
@@ -36,8 +36,8 @@
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.2.2",
40
- "@pgxsinkit/pglite-opfs-repacked": "0.2.2"
39
+ "@pgxsinkit/contracts": "0.2.3",
40
+ "@pgxsinkit/pglite-opfs-repacked": "0.2.3"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@electric-sql/pglite": ">=0.5.4-pgx.0 <0.5.5",
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: core
15
15
  library: "@pgxsinkit/client"
16
- library_version: "0.2.2"
16
+ library_version: "0.2.3"
17
17
  source: https://pgxsinkit.github.io/llms-full.txt
18
18
  ---
19
19
 
@@ -225,7 +225,8 @@ Separately from persistence, the store's flush **timing** is `durability`, decla
225
225
  physical behavior is backend-specific: idb detaches its whole-snapshot flush, while OPFS-repacked keeps the
226
226
  host awaited but omits routine physical flushes. `"strict"` restores each backend's strict boundary. The
227
227
  SharedWorker factory, capability-driven Safari/Chromium/Firefox engine placement, relocation outcomes,
228
- adoption, destruction, write-latency rationale, and recovery windows live in the `operating` skill.
228
+ backend permanence, destruction, write-latency rationale, and recovery windows live in the `operating`
229
+ skill.
229
230
  Backups, the SQL exports, and `restoreFrom` are there too.
230
231
 
231
232
  ## Where to look
@@ -9,12 +9,12 @@ description: >-
9
9
  budget, the edge worker timeout vs Electric's long-poll, globalThis.__pgxsinkitDebug + the BootReport,
10
10
  worker mode (defineSyncWorker/attachSyncClient — capability-driven Safari SharedWorker vs elected
11
11
  Chromium/Firefox engine placement, factories, relocation outcomes, diagnostics, and the forwarded rail),
12
- and the store lifecycle surface: storePath naming, backend-specific durability, adoption, supervised
13
- destruction, exportStore/exportDiagnostics/exportData (+ drain guard), and restoreFrom.
12
+ and the store lifecycle surface: storePath naming, backend-specific durability, backend permanence,
13
+ supervised destruction, exportStore/exportDiagnostics/exportData (+ drain guard), and restoreFrom.
14
14
  metadata:
15
15
  type: task
16
16
  library: "@pgxsinkit/client"
17
- library_version: "0.2.2"
17
+ library_version: "0.2.3"
18
18
  source: https://pgxsinkit.github.io/start/operating-in-production/
19
19
  ---
20
20
 
@@ -81,6 +81,12 @@ best-effort: a rejected warm is caught to `undefined` and PGlite loads its own a
81
81
  fails the boot. The `boot pglite assets warm` rail stamp times it. (Board demo: `apps/board/src/board/
82
82
  pglite-warm.ts` shows the Vite `?url` asset-URL pattern PGlite's `exports` field otherwise blocks.)
83
83
 
84
+ **In worker mode the engine loads PGlite's OWN assets — deliberately; do not pre-supply them.** The tab's
85
+ warm still serves the engine, by priming the same-origin HTTP cache the worker fetches from. Handing the
86
+ engine a pre-compiled `WebAssembly.Module` benched NET-NEGATIVE: it forces compile-to-completion before
87
+ instantiate (forfeiting the pipelining PGlite gets from its own streaming load) and the engine realm has no
88
+ overlap window longer than the placement/handshake gap, so the compile only competes for CPU at spawn.
89
+
84
90
  Pre-warming only hides the WASM fetch+compile; `PGlite.create` still spends ~1.9s on `initdb` + store open,
85
91
  and that can't start until the store id is known (usually the signed-in user). To hide it too, create the
86
92
  store EAGERLY under a generated id on the first screen and BIND it at auth. `createClientPGlite(storePath,
@@ -110,6 +116,17 @@ exercises the capability fallback to idb (declared durability kept, `storageBack
110
116
  no probe, no election, the engine boots in the SharedWorker on idb. `createSyncClient` remains the bun/Node
111
117
  mode and the main-thread idb fallback where SharedWorker is missing.
112
118
 
119
+ **A home with NO grant refuses a store already committed to OPFS.** A boot whose home holds no sync-access
120
+ grant (a tab realm, the in-process fallback) over a store whose meta record says `opfs-committed` fails
121
+ CLOSED with `CommittedStoreUnreachableError` — it cannot open that store, and `idb://<storePath>` would be an
122
+ EMPTY sibling (app looks wiped, offline writes fork into a store no worker-mode boot opens). No override
123
+ flag; the message names both exits — boot from a granted home, or destroy first with
124
+ `destroyStoreArtifacts(storePath)`, the path-addressed destroy (the failed boot leaves you no client to call
125
+ `destroy()` on) that deletes both backends plus the sentinel and the meta record and needs no grant; quiesce
126
+ any live worker for the path first (`quiesceStoreWorker`). The error is `instanceof`-branchable on the tab
127
+ side in worker mode too (it crosses the bridge as its class) and carries the refused `storePath`. A no-grant
128
+ `provision` declines that store for the same reason rather than pre-minting the sibling.
129
+
113
130
  **Two-file pattern.** One worker entry, bundled for both SharedWorker and dedicated Worker, calls
114
131
  `defineSyncWorker({ registry, electricUrl, batchWriteUrl, … })` at module top level — no placement or
115
132
  durability option (both are runtime/registry concerns); the registry is CODE, _imported_ by the worker
@@ -174,6 +191,15 @@ registry stays tab-side in localStorage so binding resolves before attach (Share
174
191
  Call `provisionSyncWorker` with the same `worker` input as attach (the factory form, so elected-mode recovery is armed for provisioning too); an elected
175
192
  Chromium/Firefox pre-open shares the tab's one election coordinator and auto-derives the engine from the
176
193
  SharedWorker's own script URL (override with `createEngineWorker` only for non-module/underivable entries).
194
+ `provisionExpiryMs` (default 60000) is ONE deadline: it retires the abandoned elected claim AND settles the
195
+ returned promise with the typed `ProvisionExpiredError` in both modes, so a provision behind a dead
196
+ SharedWorker connection fails loudly rather than hanging. It bounds YOUR promise; the worker-side create
197
+ attempt follows the placement. SW-direct: the attempt is left running — a later attach adopts that create if it
198
+ completed and waits on it if it is stuck, and a retried provision re-acks the same attempt rather than starting
199
+ a second open. Elected: the deadline also releases the provision claim, and a LAST-claim release retires and
200
+ terminates the engine with that attempt inside it, so the next attach elects a fresh engine (an attach that
201
+ adopted the coordinator earlier keeps its claim, and with it that engine).
202
+ Fire-and-forget callers should `.catch()` it like any un-awaited promise.
177
203
  Claim = bind id, attach, push config + token. On a PROVABLY-fresh claimed store, pass
178
204
  `attachSyncClient({ freshStore: true })` (never for a mapped/returning store) and the worker overlaps the
179
205
  shape catch-up with schema/journal/store-version recovery — far-user boot bounded by `max(create+schema,
@@ -300,11 +326,17 @@ offline for inspection; a clean-journal restore may honor the normal online opti
300
326
  persisted store normally. Consumer docs:
301
327
  <https://pgxsinkit.github.io/concepts/export-and-restore/>.
302
328
 
303
- **Adoption.** An existing idb store is authoritative and is never silently replaced by a newly capable
304
- OPFS home. Automatic adoption is default-off and requires the worker-entry declaration
305
- `adoption: "server-reconstructible"`; only a drained journal, authorized online reconstruction, and a
306
- returned strict barrier permit the idb predecessor to be deleted. `adoptStore()` is the manual
307
- creation-path equivalent and refuses a live store with `StoreInUseError`.
329
+ **Backend permanence.** A store's storage backend is FIXED at its first mint, for the store's whole
330
+ life. An existing idb store is opened IN PLACE by a newly capable OPFS home — no candidate, no
331
+ sentinel, nothing copied, nothing deleted (`storageBackend: "idbfs"` + a `storageFallbackReason` on the
332
+ report); a no-grant home refuses a committed OPFS store instead (above). The ONE route to another
333
+ backend is a deliberate destroy — `client.destroy()`, or `destroyStoreArtifacts(storePath)` for a store
334
+ nobody holds — then a fresh boot that re-syncs from the server and mints on the then-best backend.
335
+ Budget a full cold bootstrap, and expect local-only state (anything written via `rawExec`, un-flushed
336
+ journal rows dropped by `force`) to be gone: the replacement is a NEW store, not a converted one. There
337
+ is no migration API and no in-place conversion. For a storage-PREFERENCE change, mint under a FRESH path
338
+ and destroy the obsolete one in the background — never delete-and-recreate the same path while a
339
+ predecessor worker may still hold it.
308
340
 
309
341
  **Resetting and deleting stores (ADR-0050).** Three non-interchangeable levers — pick by what you keep
310
342
  and whether the store is running:
@@ -52,9 +52,9 @@ export interface BootReport {
52
52
  * The verbatim reason an opfs-CAPABLE boot (the probe granted sync-access handles) nonetheless opened `idbfs`
53
53
  * (ADR-0049 decision 12). Set ONLY when such a fallback actually occurred — never on a plain idb boot (the probe
54
54
  * denied from the start), and never on a granted opfs boot that stayed on opfs. Today's set-sites are the
55
- * granted-then-idb transitions the client owns: a declaration-gated adoption that deferred/failed (idb stays
56
- * authoritative) and the recordless idb-store downgrade (invariant 14 — never a fresh opfs mint over an
57
- * existing idb store's data). Additive field; `reportVersion` stays `1`.
55
+ * granted-then-idb transitions the client owns: the recordless idb-store downgrade (invariant 14 — an existing
56
+ * idb store is opened in place, never overwritten by a fresh opfs mint) and the virgin-uncreatable session
57
+ * idbfs fallback (the verbatim opfs open failure). Additive field; `reportVersion` stays `1`.
58
58
  */
59
59
  storageFallbackReason?: string;
60
60
  /** Whether the ADR-0032 S4 fetch/schema overlap was active for this boot. */