@pgxsinkit/client 0.1.32 → 0.1.40

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.
Files changed (111) hide show
  1. package/README.md +11 -0
  2. package/dist/boot-report.d.ts +134 -0
  3. package/dist/boot-report.d.ts.map +1 -0
  4. package/dist/convergence.d.ts +76 -0
  5. package/dist/convergence.d.ts.map +1 -0
  6. package/dist/debug.d.ts +34 -0
  7. package/dist/debug.d.ts.map +1 -0
  8. package/dist/export-data.d.ts +100 -0
  9. package/dist/export-data.d.ts.map +1 -0
  10. package/dist/export-dump.d.ts +92 -0
  11. package/dist/export-dump.d.ts.map +1 -0
  12. package/dist/export-store.d.ts +214 -0
  13. package/dist/export-store.d.ts.map +1 -0
  14. package/dist/index.d.ts +615 -8
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +8083 -2286
  17. package/dist/index.js.map +81 -44
  18. package/dist/lazy-guard.d.ts +59 -0
  19. package/dist/lazy-guard.d.ts.map +1 -0
  20. package/dist/lifecycle-slot.d.ts +31 -0
  21. package/dist/lifecycle-slot.d.ts.map +1 -0
  22. package/dist/live-rows-sql.d.ts +21 -0
  23. package/dist/live-rows-sql.d.ts.map +1 -0
  24. package/dist/local-store.d.ts +56 -0
  25. package/dist/local-store.d.ts.map +1 -0
  26. package/dist/local-tables.d.ts +707 -0
  27. package/dist/local-tables.d.ts.map +1 -0
  28. package/dist/mutation-state.d.ts +69 -0
  29. package/dist/mutation-state.d.ts.map +1 -0
  30. package/dist/mutation.d.ts +129 -4
  31. package/dist/mutation.d.ts.map +1 -1
  32. package/dist/schema.d.ts +82 -0
  33. package/dist/schema.d.ts.map +1 -1
  34. package/dist/shape-sync.d.ts +190 -0
  35. package/dist/shape-sync.d.ts.map +1 -0
  36. package/dist/store-path.d.ts +132 -0
  37. package/dist/store-path.d.ts.map +1 -0
  38. package/dist/sync/apply.d.ts +51 -0
  39. package/dist/sync/apply.d.ts.map +1 -0
  40. package/dist/sync/copy.d.ts +43 -0
  41. package/dist/sync/copy.d.ts.map +1 -0
  42. package/dist/sync/drizzle-executor.d.ts +5 -0
  43. package/dist/sync/drizzle-executor.d.ts.map +1 -0
  44. package/dist/sync/index.d.ts +32 -0
  45. package/dist/sync/index.d.ts.map +1 -0
  46. package/dist/sync/metadata-tables.d.ts +131 -0
  47. package/dist/sync/metadata-tables.d.ts.map +1 -0
  48. package/dist/sync/nudge.d.ts +49 -0
  49. package/dist/sync/nudge.d.ts.map +1 -0
  50. package/dist/sync/shape-inbox.d.ts +215 -0
  51. package/dist/sync/shape-inbox.d.ts.map +1 -0
  52. package/dist/sync/subscription-state.d.ts +39 -0
  53. package/dist/sync/subscription-state.d.ts.map +1 -0
  54. package/dist/sync/tags.d.ts +130 -0
  55. package/dist/sync/tags.d.ts.map +1 -0
  56. package/dist/sync/types.d.ts +126 -0
  57. package/dist/sync/types.d.ts.map +1 -0
  58. package/dist/sync-auth.d.ts +53 -0
  59. package/dist/sync-auth.d.ts.map +1 -0
  60. package/dist/testing.d.ts +27 -0
  61. package/dist/testing.d.ts.map +1 -0
  62. package/dist/testing.js +17 -0
  63. package/dist/testing.js.map +11 -0
  64. package/dist/worker/attach-sync-client.d.ts +96 -0
  65. package/dist/worker/attach-sync-client.d.ts.map +1 -0
  66. package/dist/worker/define-sync-worker.d.ts +76 -0
  67. package/dist/worker/define-sync-worker.d.ts.map +1 -0
  68. package/dist/worker/live-diff.d.ts +44 -0
  69. package/dist/worker/live-diff.d.ts.map +1 -0
  70. package/dist/worker/protocol.d.ts +341 -0
  71. package/dist/worker/protocol.d.ts.map +1 -0
  72. package/dist/worker/token-cache.d.ts +26 -0
  73. package/dist/worker/token-cache.d.ts.map +1 -0
  74. package/oxlint-plugin.js +143 -0
  75. package/package.json +20 -7
  76. package/skills/core/SKILL.md +210 -0
  77. package/skills/operating/SKILL.md +303 -0
  78. package/src/boot-report.ts +287 -0
  79. package/src/convergence.ts +197 -0
  80. package/src/debug.ts +151 -0
  81. package/src/export-data.ts +300 -0
  82. package/src/export-dump.ts +239 -0
  83. package/src/export-store.ts +309 -0
  84. package/src/index.ts +1652 -51
  85. package/src/lazy-guard.ts +135 -0
  86. package/src/lifecycle-slot.ts +66 -0
  87. package/src/live-rows-sql.ts +45 -0
  88. package/src/local-store.ts +193 -0
  89. package/src/local-tables.ts +546 -0
  90. package/src/mutation-state.ts +99 -0
  91. package/src/mutation.ts +1910 -562
  92. package/src/schema.ts +472 -28
  93. package/src/shape-sync.ts +498 -0
  94. package/src/store-path.ts +249 -0
  95. package/src/sync/apply.ts +530 -0
  96. package/src/sync/copy.ts +206 -0
  97. package/src/sync/drizzle-executor.ts +48 -0
  98. package/src/sync/index.ts +1087 -0
  99. package/src/sync/metadata-tables.ts +67 -0
  100. package/src/sync/nudge.ts +110 -0
  101. package/src/sync/shape-inbox.ts +566 -0
  102. package/src/sync/subscription-state.ts +135 -0
  103. package/src/sync/tags.ts +365 -0
  104. package/src/sync/types.ts +141 -0
  105. package/src/sync-auth.ts +117 -0
  106. package/src/testing.ts +53 -0
  107. package/src/worker/attach-sync-client.ts +653 -0
  108. package/src/worker/define-sync-worker.ts +762 -0
  109. package/src/worker/live-diff.ts +140 -0
  110. package/src/worker/protocol.ts +425 -0
  111. package/src/worker/token-cache.ts +84 -0
@@ -0,0 +1,17 @@
1
+ // @bun
2
+ // packages/client/src/store-path.ts
3
+ var TEST_STORE_BACKEND = Symbol.for("pgxsinkit.internal.testStoreBackend");
4
+
5
+ // packages/client/src/testing.ts
6
+ function memoryStoreForTests(storePath) {
7
+ return { storePath, [TEST_STORE_BACKEND]: "memory" };
8
+ }
9
+ function testStoreAcknowledgment() {
10
+ return { [TEST_STORE_BACKEND]: "acknowledged" };
11
+ }
12
+ export {
13
+ testStoreAcknowledgment,
14
+ memoryStoreForTests
15
+ };
16
+
17
+ //# debugId=7077823A374194F864756E2164756E21
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/store-path.ts", "../src/testing.ts"],
4
+ "sourcesContent": [
5
+ "// Store path contract (ADR-0036). The public seams (`createSyncClient`, `createClientPGlite`, the worker\n// attach/provision messages, the board store registry) take a `storePath` — a PLAIN path/name, never a\n// PGlite storage URL. The storage backend is DERIVED from the environment here, never chosen by the\n// consumer: IndexedDB in a browser (or a worker), the filesystem on Bun/Node. A memory-backed store is\n// not a product configuration — pgxsinkit's durability semantics (persistent retention, the optimistic\n// Mutation journal) assume a persisted store — so it exists ONLY behind the explicit testing\n// acknowledgment (`@pgxsinkit/client/testing`), carried into option handling as the module-internal\n// {@link TEST_STORE_BACKEND} symbol.\n//\n// This module is the ONLY place in the toolkit that assembles `idb://` / `file://` / `memory://` URLs (the\n// export machinery's throwaway clone, a later slice, is the one other internal `memory://` site). A\n// resolved URL is internal plumbing: it never leaks into config, results, reports, or errors as something\n// a consumer could copy back into a storePath — hence the scheme-rejection guard below fails the old\n// contract loudly at the boundary rather than silently re-interpreting it.\n\n/**\n * Thrown when a `storePath` is not a plain name (ADR-0036 decision 1): it carries a URL scheme (`://`) or\n * is empty/whitespace-only. A distinct type — not a bare `Error` — so a caller can `instanceof`-branch the\n * old dataDir-URL contract from a genuine store failure. The message names the plain-path contract and\n * shows the corrected form, without echoing a resolvable URL a consumer might imitate.\n */\nexport class InvalidStorePathError extends Error {\n constructor(message: string) {\n super(`[pgxsinkit] ${message}`);\n this.name = \"InvalidStorePathError\";\n }\n}\n\n/**\n * Thrown when a caller-owned PGlite handed to {@link CreateSyncClientOptions.pgliteInstance} /\n * {@link CreateSyncClientOptions.precreatedPglite} is PROVABLY non-persistent (ADR-0036 decision 4): its\n * `dataDir` is `undefined` (PGlite's in-memory default — the `new PGlite()` a copy-paste reaches) or begins\n * `memory://`. Names both the why (durability semantics assume a persisted store) and the two exits, so a\n * consumer is never left guessing which store to hand us instead.\n */\nexport class NonPersistentStoreError extends Error {\n constructor(observed: \"in-memory-default\" | \"memory-scheme\") {\n const reason =\n observed === \"in-memory-default\"\n ? \"its dataDir is undefined — PGlite's default is an in-memory store (`new PGlite()`)\"\n : \"its dataDir is a memory-backed store\";\n super(\n `[pgxsinkit] refusing a non-persistent PGlite instance: ${reason}. pgxsinkit's durability semantics ` +\n \"(persistent retention, the optimistic Mutation journal) assume a persisted store — a memory store \" +\n \"would silently forget acked-but-unflushed writes. Either hand a persisted instance (open it under a \" +\n \"plain store path so the backend is derived), or, for a test/ephemeral store, acknowledge it with \" +\n '`memoryStoreForTests` / `testStoreAcknowledgment` from \"@pgxsinkit/client/testing\" (ADR-0036).',\n );\n this.name = \"NonPersistentStoreError\";\n }\n}\n\n/**\n * Thrown when a restore (`restoreFrom`, ADR-0035 decision 6) targets a store path whose backend store ALREADY\n * exists. Restore is a CREATION-path feature — it boots a brand-new store on `loadDataDir` — and never\n * overlays a live store: silently merging a backup into an existing datadir would corrupt it. A distinct type\n * (not a bare `Error`) so a caller can `instanceof`-branch \"target already there\" from a genuine boot failure.\n * The remedy is a deliberate manual {@link SyncClient.destroy} of the existing store first (never automatic —\n * dropping a user's local store must be their explicit act).\n */\nexport class RestoreTargetExistsError extends Error {\n constructor(storePath: string) {\n super(\n `[pgxsinkit] refusing to restore into ${JSON.stringify(storePath)}: a store already exists at that path. ` +\n \"Restore only ever boots a brand-new store (it never overlays an existing one — that would corrupt the \" +\n \"datadir). Destroy the existing store first (a deliberate `destroy()`), then restore into the now-fresh \" +\n \"path (ADR-0035 decision 6).\",\n );\n this.name = \"RestoreTargetExistsError\";\n }\n}\n\n/**\n * The module-internal marker a testing helper stamps onto the options object so option handling can select\n * the memory backend / unlock the BYO refusal (ADR-0036 decision 3). `Symbol.for` (not a bare `Symbol()`)\n * on purpose: each public entry point is bundled STANDALONE (`scripts/build-public-packages.ts`,\n * `splitting: false`), so a plain module symbol would be DUPLICATED between the main bundle and the\n * `./testing` bundle — two distinct symbols, and the marker set by `./testing` would be invisible to the\n * main entry's reader. The global registry key guarantees ONE symbol across bundles. It is deliberately\n * absent from the main entry's exports and from every public type, so a production consumer cannot name it.\n */\nexport const TEST_STORE_BACKEND: unique symbol = Symbol.for(\"pgxsinkit.internal.testStoreBackend\");\n\n/**\n * What a testing helper's marker asks of option handling: `\"memory\"` mints a scheme-selected memory store\n * (and, being ours-under-the-covers, also unlocks the BYO refusal); `\"acknowledged\"` only unlocks the BYO\n * refusal for a caller who owns the (test) instance themselves. Both are visible, deliberate acts — an\n * import whose name says what it is.\n */\nexport type TestStoreMarker = \"memory\" | \"acknowledged\";\n\n/** An options object that MAY carry the internal testing marker (read via {@link readTestStoreMarker}). */\nexport type WithTestStoreMarker = { [TEST_STORE_BACKEND]?: TestStoreMarker };\n\n/** Read the internal testing marker off an options object, or `undefined` when none was stamped. */\nexport function readTestStoreMarker(options: unknown): TestStoreMarker | undefined {\n if (options == null || typeof options !== \"object\") return undefined;\n const marker = (options as WithTestStoreMarker)[TEST_STORE_BACKEND];\n return marker === \"memory\" || marker === \"acknowledged\" ? marker : undefined;\n}\n\n/**\n * What {@link createClientPGlite} (and any store-opening seam) accepts as its store argument: a plain\n * `storePath` string, or the option object a testing helper mints (`memoryStoreForTests(...)`) — carrying a\n * `storePath` plus the invisible internal marker. Accepting the object form is what lets the testing\n * helper's output flow STRAIGHT into `createClientPGlite(memoryStoreForTests(\"x\"))` without a consumer ever\n * naming a backend.\n */\nexport type StorePathInput = string | ({ storePath: string } & WithTestStoreMarker);\n\n/** Normalise a {@link StorePathInput} to a plain path plus any internal memory-backend override it carried. */\nexport function normaliseStorePathInput(input: StorePathInput): { storePath: string; backendOverride?: \"memory\" } {\n if (typeof input === \"string\") return { storePath: input };\n return {\n storePath: input.storePath,\n ...(readTestStoreMarker(input) === \"memory\" ? { backendOverride: \"memory\" as const } : {}),\n };\n}\n\n/**\n * The environment seam the backend derivation reads — factored out so a browser derivation is fakeable in\n * a Bun unit test (there is no `indexedDB` there). `hasIndexedDb` is the browser/worker signal: PGlite's\n * IndexedDB backend needs `indexedDB`, which a browser tab AND a Web/Shared/dedicated worker expose but\n * Bun/Node do not — so it distinguishes \"run in the browser\" (idb) from \"run on the server\" (filesystem)\n * without a DOM-lib dependency.\n */\nexport interface StoreEnv {\n hasIndexedDb: boolean;\n}\n\n/** Detect the ambient store environment off `globalThis` (the library carries no DOM lib dependency). */\nfunction detectStoreEnv(): StoreEnv {\n return { hasIndexedDb: typeof (globalThis as { indexedDB?: unknown }).indexedDB !== \"undefined\" };\n}\n\n/**\n * Resolve a plain {@link storePath} to the PGlite dataDir URL the store opens at — the ONE derivation point\n * (ADR-0036 decision 2). Browser/worker (`indexedDB` present) → `idb://<storePath>`; Bun/Node → `file://<storePath>`\n * (relative paths resolve against the working directory, exactly as PGlite's filesystem backend does — pass\n * an absolute path if that matters). The `backendOverride` is internal-only: `\"memory\"` selects a\n * scheme-selected `memory://<storePath>` store for the sanctioned test/ephemeral lanes.\n *\n * Rejects a scheme-bearing or empty/whitespace-only path with {@link InvalidStorePathError} — the storePath\n * contract fails loudly at the boundary, never silently re-interpreted (no-legacy rule). The returned URL is\n * internal plumbing; do not surface it to consumers as something to imitate.\n *\n * CRITICAL (ADR-0036 decision 5, probed on PGlite 0.5.4): memory selection is ALWAYS the scheme-selected\n * `memory://` form, NEVER PGlite's explicit `fs: new MemoryFS()` option — `dumpDataDir` from an explicit-`fs`\n * instance silently omits relation files created after initdb, so a restored clone raises \"relation does not\n * exist\". Callers that need a memory store must route through this function, never construct `MemoryFS`.\n */\nexport function resolveStoreDataDir(\n storePath: string,\n backendOverride?: \"memory\",\n env: StoreEnv = detectStoreEnv(),\n): string {\n if (typeof storePath !== \"string\" || storePath.trim().length === 0) {\n throw new InvalidStorePathError(\n 'invalid storePath: expected a non-empty plain store name (e.g. \"my-app-store\"); received an empty or whitespace-only value (ADR-0036).',\n );\n }\n if (storePath.includes(\"://\")) {\n throw new InvalidStorePathError(\n `invalid storePath ${JSON.stringify(storePath)}: a store path is a plain name, not a storage URL. ` +\n 'Pass just the name (e.g. \"my-app-store\") — the storage backend (IndexedDB in a browser, the ' +\n \"filesystem on Bun/Node) is derived for you; drop the scheme prefix (ADR-0036).\",\n );\n }\n if (backendOverride === \"memory\") return `memory://${storePath}`;\n return env.hasIndexedDb ? `idb://${storePath}` : `file://${storePath}`;\n}\n\n/**\n * The IndexedDB database name a browser store occupies (ADR-0036) — a browser-only OPERATIONAL helper for\n * orphan GC / corrupt-store deletion (`indexedDB.deleteDatabase(...)`), NOT part of the create path. PGlite\n * maps `idb://<storePath>` to the IndexedDB database `/pglite/<storePath>` (its `WASM_PREFIX` `/pglite`\n * joined with the path after the scheme; verified against `@electric-sql/pglite` 0.5.4 dist). Exposed so a\n * consumer that GCs its own stores routes that PGlite-internal naming knowledge through the library rather\n * than re-deriving the `/pglite/` prefix itself. Rejects a scheme-bearing/empty path exactly as\n * {@link resolveStoreDataDir} does, so the two stay in lockstep.\n */\nexport function storeIndexedDbDatabaseName(storePath: string): string {\n if (typeof storePath !== \"string\" || storePath.trim().length === 0) {\n throw new InvalidStorePathError(\n \"invalid storePath: storeIndexedDbDatabaseName expects a non-empty plain store name (ADR-0036).\",\n );\n }\n if (storePath.includes(\"://\")) {\n throw new InvalidStorePathError(\n `invalid storePath ${JSON.stringify(storePath)}: storeIndexedDbDatabaseName expects a plain name, not a storage URL (ADR-0036).`,\n );\n }\n return `/pglite/${storePath}`;\n}\n\n/**\n * Classify a PGlite instance's `dataDir` for the BYO refusal (ADR-0036 decision 4). Returns the offending\n * shape when the instance is PROVABLY non-persistent (`undefined` = PGlite's in-memory default; a\n * `memory://` prefix = an explicit memory store), or `null` when it passes — anything else present,\n * including exotic custom-VFS configs we cannot classify, is the caller's own call (the guard catches the\n * two accidental non-persistent shapes, it is not a storage-backend whitelist).\n */\nexport function classifyNonPersistentDataDir(\n dataDir: string | undefined,\n): \"in-memory-default\" | \"memory-scheme\" | null {\n if (dataDir == null) return \"in-memory-default\";\n if (dataDir.startsWith(\"memory://\")) return \"memory-scheme\";\n return null;\n}\n\n/**\n * Does the backend store a plain {@link storePath} resolves to ALREADY exist? The fresh-target gate for a\n * restore (ADR-0035 decision 6) — restore refuses a target that is already there. Per backend:\n *\n * - **memory** (`backendOverride === \"memory\"`) — a scheme-selected memory store is fresh by construction:\n * it lives only for the instance about to be created, so there is nothing to collide with. Always `false`\n * (the sanctioned test/ephemeral lane never blocks a restore).\n * - **`file://`** (Bun/Node) — filesystem existence of the datadir directory. `node:fs` is imported\n * DYNAMICALLY inside this branch, never at module top level, so a browser bundle (which only ever hits the\n * `idb://` branch below) never pulls `node:fs` in. Relative paths resolve against the working directory,\n * exactly as PGlite's filesystem backend and {@link resolveStoreDataDir} do.\n * - **`idb://`** (browser/worker) — `indexedDB.databases()` enumerated for the store's database name\n * ({@link storeIndexedDbDatabaseName}). BEST-EFFORT: `databases()` is unavailable on some engines (older\n * Firefox, certain worker contexts); when absent we CANNOT prove existence, so we report `false` and let\n * the restore proceed rather than fabricate a result — a real overlay collision would still surface as a\n * PGlite-level boot failure. We never fake a positive.\n */\nexport async function storeTargetExists(\n storePath: string,\n backendOverride?: \"memory\",\n env: StoreEnv = detectStoreEnv(),\n): Promise<boolean> {\n const dataDir = resolveStoreDataDir(storePath, backendOverride, env);\n if (dataDir.startsWith(\"memory://\")) return false;\n if (dataDir.startsWith(\"file://\")) {\n // The datadir path is everything after the `file://` scheme; `node:fs` handles absolute and\n // cwd-relative paths identically to PGlite's own filesystem backend.\n const path = dataDir.slice(\"file://\".length);\n const { existsSync } = await import(\"node:fs\");\n return existsSync(path);\n }\n // `idb://` — enumerate the IndexedDB databases for this store's database name. `databases()` is optional in\n // the spec, so guard it: when absent, best-effort `false` (documented above), never a fabricated positive.\n const idb = (globalThis as { indexedDB?: { databases?: () => Promise<Array<{ name?: string }>> } }).indexedDB;\n if (idb?.databases == null) return false;\n const target = storeIndexedDbDatabaseName(storePath);\n const databases = await idb.databases();\n return databases.some((db) => db.name === target);\n}\n",
6
+ "// `@pgxsinkit/client/testing` — the ONLY sanctioned door to a memory-backed store (ADR-0036 decision 3).\n//\n// pgxsinkit's durability semantics assume a persisted store, so the production API surface cannot express a\n// memory store: `createSyncClient`/`createClientPGlite` take a plain `storePath` whose backend is derived\n// (IndexedDB / filesystem), and the BYO seam refuses a provably non-persistent instance. Genuine memory\n// stores are needed in exactly two of OUR places — the unit-test lane (speed + isolation) and the export\n// machinery's throwaway clone — and this subpath serves the first: an import whose NAME says what it is, so\n// reaching a memory store is always a visible, deliberate act. App bundles never import it, so the whole\n// module (and any mention of memory) tree-shakes away.\n//\n// The helpers mint plain options objects that ALSO carry the module-internal {@link TEST_STORE_BACKEND}\n// marker at runtime — invisible in the public return type. Consumers SPREAD them into the client options:\n//\n// createSyncClient({ ...memoryStoreForTests(\"my-test\"), registry, electricUrl, writeUrl })\n// createSyncClient({ ...testStoreAcknowledgment(), pgliteInstance, registry, electricUrl, writeUrl })\n\nimport { TEST_STORE_BACKEND } from \"./store-path\";\n\n/**\n * The public shape of {@link memoryStoreForTests}'s output: just a `storePath`. The internal backend marker\n * rides alongside at runtime but is deliberately absent from this type, so no production type mentions memory.\n */\nexport interface MemoryStoreForTests {\n storePath: string;\n}\n\n/**\n * Mint client store options that resolve to a scheme-selected in-memory store — the unit-test / ephemeral\n * lane (ADR-0036 decision 3). Spread the result into `createSyncClient` (or `defineSyncWorker` where its\n * options accept `storePath`): the client reads the internal marker and selects the memory backend.\n *\n * DURABILITY CAVEAT: a memory store is session-scoped, so pgxsinkit's persistent-retention guarantee and the\n * optimistic Mutation journal's durability window are BOTH void on it — everything is lost when the instance\n * closes. Use it only for tests and throwaway/ephemeral flows, never for anything a user expects to persist.\n */\nexport function memoryStoreForTests(storePath: string): MemoryStoreForTests {\n // The marker is a symbol-keyed property, so it survives an object spread but is invisible to the public\n // type and to `Object.keys`. Cast because the return TYPE deliberately hides it (ADR-0036 decision 3).\n return { storePath, [TEST_STORE_BACKEND]: \"memory\" } as MemoryStoreForTests;\n}\n\n/**\n * Mint an options fragment that ACKNOWLEDGES a caller-owned test store, bypassing the BYO refusal\n * (ADR-0036 decision 4) WITHOUT selecting a backend — for when the test supplies its own non-persistent\n * PGlite via `pgliteInstance` / `precreatedPglite`. Spread it alongside that option.\n *\n * Same DURABILITY CAVEAT as {@link memoryStoreForTests}: only for tests / throwaway flows; a non-persistent\n * store voids the retention + journal durability guarantees.\n */\nexport function testStoreAcknowledgment(): Record<never, never> {\n // An empty public shape carrying only the internal marker — nothing for a consumer to configure.\n return { [TEST_STORE_BACKEND]: \"acknowledged\" } as Record<never, never>;\n}\n"
7
+ ],
8
+ "mappings": ";;AAiFO,IAAM,qBAAoC,OAAO,IAAI,qCAAqC;;;AC9C1F,SAAS,mBAAmB,CAAC,WAAwC;AAAA,EAG1E,OAAO,EAAE,YAAY,qBAAqB,SAAS;AAAA;AAW9C,SAAS,uBAAuB,GAAyB;AAAA,EAE9D,OAAO,GAAG,qBAAqB,eAAe;AAAA;",
9
+ "debugId": "7077823A374194F864756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,96 @@
1
+ import type { SyncRuntimeStatus, SyncTableRegistry } from "@pgxsinkit/contracts";
2
+ import type { BootReport } from "../boot-report";
3
+ import { type MutationDetail, type SyncClient } from "../index";
4
+ import type { LocalStoreVersionEvent } from "../local-store";
5
+ import { type AuthTokenSnapshot, type BridgeCodec, type BridgePort, type BridgeTransferable } from "./protocol";
6
+ /** A `Worker`/`SharedWorker`-shaped handle: a dedicated `Worker` IS the port; a `SharedWorker` carries `.port`. */
7
+ interface WorkerLike {
8
+ port?: BridgePort;
9
+ postMessage?: (message: unknown, transfer?: BridgeTransferable[]) => void;
10
+ addEventListener?: (type: "message", listener: (event: {
11
+ data: unknown;
12
+ }) => void) => void;
13
+ removeEventListener?: (type: "message", listener: (event: {
14
+ data: unknown;
15
+ }) => void) => void;
16
+ }
17
+ export interface AttachSyncClientOptions<TRegistry extends SyncTableRegistry> {
18
+ registry: TRegistry;
19
+ /** A native `Worker` or `SharedWorker` (or anything port-shaped). Provide this OR {@link port}. */
20
+ worker?: WorkerLike;
21
+ /** A raw transport port (a `MessageChannel` port in tests, a `SharedWorker.port` in a browser). */
22
+ port?: BridgePort;
23
+ /**
24
+ * The tab's token provider (ADR-0032 decision 3). Richer than `createSyncClient`'s string form: the
25
+ * worker needs the EXPIRY to apply its pull margin, so this yields `{accessToken, expiresAt}` (or null
26
+ * when unauthenticated). Pushed at attach and answered on every worker pull-request.
27
+ */
28
+ getToken?: () => Promise<AuthTokenSnapshot | null>;
29
+ /** The bound store id (resolved tab-side before attach — SharedWorker naming, ADR-0032 decision 5). */
30
+ storeId?: string;
31
+ /**
32
+ * The plain store PATH (ADR-0036) the worker opens if it must create its own store — a name, not a
33
+ * storage URL. Spread `memoryStoreForTests(...)` from `@pgxsinkit/client/testing` here for a memory store
34
+ * in tests (it also carries the internal marker forwarded to the worker as the memory-backend override).
35
+ */
36
+ storePath?: string;
37
+ syncEnabled?: boolean;
38
+ /**
39
+ * Which baked registry the worker boots (ADR-0032 S3) — forwarded in the attach `config.role`. A worker
40
+ * file that bakes multiple role variants (the board's admin/member) picks by this; single-registry
41
+ * workers ignore it.
42
+ */
43
+ role?: string;
44
+ /**
45
+ * Fresh-store prefetch-overlap hint (ADR-0032 S4), forwarded in the attach `config.freshStore`. Set true
46
+ * ONLY when the tab knows the store is a claimed schemaless spare (never for a mapped/returning store);
47
+ * the worker's `createSyncClient` then overlaps the shape catch-up with its local boot phases.
48
+ */
49
+ freshStore?: boolean;
50
+ /**
51
+ * Restore the worker's store from a backup on attach (ADR-0035 decision 6) — the worker-mode `restoreFrom`.
52
+ * A `File`/`Blob` as produced by {@link SyncClient.exportStore}; the facade decomposes it into a transferred
53
+ * `ArrayBuffer` + name/mime ({@link RestoreArtefactWire}) and the worker recomposes it for `createSyncClient`.
54
+ * Restore rides the FIRST (boot) attach: passing it when the worker's engine has ALREADY booted rejects the
55
+ * attach with a typed error (you cannot restore into a running store). The restored engine boots offline and
56
+ * its recovered journal is quarantined, exactly as in-process — see `restoreFrom` on `createSyncClient`.
57
+ */
58
+ restoreFrom?: File | Blob;
59
+ codec?: BridgeCodec;
60
+ onStatusChange?: (status: SyncRuntimeStatus) => void;
61
+ onConflict?: (details: MutationDetail[]) => void;
62
+ onQuarantine?: (details: MutationDetail[]) => void;
63
+ onReject?: (details: MutationDetail[]) => void;
64
+ onSchemaChange?: (event: LocalStoreVersionEvent) => void;
65
+ onSyncError?: (error: Error) => void;
66
+ /**
67
+ * Boot observability (ADR-0034): invoked once with the worker engine's finalized {@link BootReport} if the
68
+ * engine's boot finalizes WHILE this tab is attached (the one-shot `boot-report` broadcast). A tab that
69
+ * attaches AFTER the boot never receives the push — it reads the report via {@link SyncClient.bootReport}.
70
+ */
71
+ onBootReport?: (report: BootReport) => void;
72
+ }
73
+ /**
74
+ * The worker-attached client: `SyncClient`'s shape, worker-proxied, plus `notifyAuthChanged` (re-push the
75
+ * token after an app auth-state change, ADR-0032 decision 3). The unsupported one-shot-read members throw.
76
+ */
77
+ export type AttachedSyncClient<TRegistry extends SyncTableRegistry> = SyncClient<TRegistry> & {
78
+ notifyAuthChanged: () => void;
79
+ /**
80
+ * Forward the app's Offline toggle to the worker (ADR-0032 S3). The worker owns convergence, so the
81
+ * tab cannot gate a local trigger; this sends `set-online`, which suppresses/resumes the worker's flush
82
+ * passes (resuming fires one immediate pass). The in-process client gates its own `autoSync` instead.
83
+ */
84
+ setOnline: (online: boolean) => void;
85
+ };
86
+ export declare function attachSyncClient<const TRegistry extends SyncTableRegistry>(options: AttachSyncClientOptions<TRegistry>): Promise<AttachedSyncClient<TRegistry>>;
87
+ /**
88
+ * Pre-spawn a worker's store WITHOUT attaching (ADR-0032 decision 5). Sent at the board's login screen
89
+ * against a freshly-named spare `SharedWorker`: the worker runs PGlite `create`/initdb only and holds the
90
+ * raw store idle until the real {@link attachSyncClient} claim adopts it. Resolves when the worker acks the
91
+ * provision (its initdb settled); rejects only if the worker reports the create failed — the caller treats
92
+ * either outcome as best-effort, since attach falls back to a fresh create regardless.
93
+ */
94
+ export declare function provisionSyncWorker<TRegistry extends SyncTableRegistry>(options: Pick<AttachSyncClientOptions<TRegistry>, "worker" | "port" | "storeId" | "storePath" | "codec">): Promise<void>;
95
+ export {};
96
+ //# sourceMappingURL=attach-sync-client.d.ts.map
@@ -0,0 +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,EAYxB,MAAM,YAAY,CAAC;AAEpB,mHAAmH;AACnH,UAAU,UAAU;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAC1E,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,KAAK,IAAI,CAAC;IAC3F,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,KAAK,IAAI,CAAC;CAC/F;AAED,MAAM,WAAW,uBAAuB,CAAC,SAAS,SAAS,iBAAiB;IAC1E,QAAQ,EAAE,SAAS,CAAC;IACpB,mGAAmG;IACnG,MAAM,CAAC,EAAE,UAAU,CAAC;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B,gBAAgB,CAAC,KAAK,CAAC,SAAS,SAAS,iBAAiB,EAC9E,OAAO,EAAE,uBAAuB,CAAC,SAAS,CAAC,GAC1C,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAycxC;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"}
@@ -0,0 +1,76 @@
1
+ import type { SyncTableRegistry } from "@pgxsinkit/contracts";
2
+ import { type ClientPGlite, type CreateSyncClientOptions, type SyncClient } from "../index";
3
+ import { type BridgeCodec, type BridgePort } from "./protocol";
4
+ export interface DefineSyncWorkerOptions<TRegistry extends SyncTableRegistry> {
5
+ /**
6
+ * The sync registry — imported as CODE by the worker file, never cloned into it (ADR-0032 decision 4).
7
+ * When {@link resolveRegistry} is also given this is the DEFAULT (used when the attach carries no role
8
+ * or an unknown one).
9
+ */
10
+ registry: TRegistry;
11
+ /**
12
+ * Resolve the registry to boot from the attach's `config.role` (ADR-0032 S3). A single worker file can
13
+ * bake BOTH role variants (e.g. the board's admin/member registries — same TS shape, different write
14
+ * capability) and pick per-attach, which the spare flow needs: the spare is provisioned role-agnostic
15
+ * (before the user is known) and the role is only settled at claim/attach. Returns `undefined` to fall
16
+ * back to {@link registry}.
17
+ */
18
+ resolveRegistry?: (role: string | undefined) => TRegistry | undefined;
19
+ /**
20
+ * How the worker creates its raw PGlite store (provision + fresh-attach paths). Defaults to
21
+ * {@link createClientPGlite}, which loads PGlite's own boot assets — in a browser worker those hit the
22
+ * same-origin HTTP cache the tab's login-screen warm already primed (ADR-0032 S3). Injected in tests.
23
+ * Takes a plain store PATH (ADR-0036); the internal `backendOverride` is the test lane's memory selection.
24
+ */
25
+ createPglite?: (storePath: string, backendOverride?: "memory") => Promise<ClientPGlite>;
26
+ electricUrl: string;
27
+ writeUrl: string;
28
+ /** Static headers on every read + write request (e.g. a gateway `apikey`). See `createSyncClient`. */
29
+ requestHeaders?: Record<string, string>;
30
+ /** Write-only headers merged over {@link requestHeaders} (e.g. region/DB-affinity). See `createSyncClient`. */
31
+ writeRequestHeaders?: Record<string, string>;
32
+ /** Default plain store PATH (ADR-0036) if the first attach carries none — a name, not a storage URL. */
33
+ storePath?: string;
34
+ maxMutationAttempts?: number;
35
+ syncEnabled?: boolean;
36
+ /**
37
+ * How close to expiry (ms) a cached token may be before a read/write that needs it triggers a pull
38
+ * broadcast (ADR-0032 decision 3). Default 30s — comfortably ahead of a long-poll cycle.
39
+ */
40
+ tokenExpiryMarginMs?: number;
41
+ /**
42
+ * The worker's own convergence cadence (ms) — the interval trigger FALLBACK only. Local writes
43
+ * flush immediately via the event-driven `requestPass` seam and tab `wake` signals, so this
44
+ * interval exists purely for retry/recovery sweeps; each idle pass still costs real worker CPU
45
+ * (`flush` + `reconcile` queries). Default 15000.
46
+ */
47
+ convergenceIntervalMs?: number;
48
+ /** Injected transport binder. Defaults to auto-detecting the SharedWorker/dedicated-worker global scope. */
49
+ installGlobal?: boolean;
50
+ /** Injected codec (ADR-0032 S2 §1). Defaults to the v1 identity codec. */
51
+ codec?: BridgeCodec;
52
+ /**
53
+ * A raw PGlite the worker uses instead of creating its own (forwarded to `createSyncClient`'s
54
+ * {@link CreateSyncClientOptions.precreatedPglite}) — the client still applies schema/reconcile. In a
55
+ * browser worker the store is minted internally (`storePath`); this is the seam for a prepopulated store in
56
+ * tests, and the future spare-worker claim (ADR-0032 decision 5).
57
+ */
58
+ precreatedPglite?: CreateSyncClientOptions<TRegistry>["precreatedPglite"];
59
+ /** A fully-provisioned PGlite (forwarded to {@link CreateSyncClientOptions.pgliteInstance}; caller owns schema). */
60
+ pgliteInstance?: CreateSyncClientOptions<TRegistry>["pgliteInstance"];
61
+ }
62
+ /** The worker-side host: attach ports, await the boot, and (for tests) tear down. */
63
+ export interface SyncWorkerHost<TRegistry extends SyncTableRegistry> {
64
+ /** Bind a transport port (a SharedWorker connection, the dedicated-worker `self`, or a test channel port). */
65
+ connect: (port: BridgePort) => void;
66
+ /** Resolves with the booted in-process engine once the first attach's `createSyncClient` completes. */
67
+ whenBooted: () => Promise<SyncClient<TRegistry>>;
68
+ /** Detach every port and stop the underlying client — for tests and dedicated-worker teardown. */
69
+ close: () => Promise<void>;
70
+ }
71
+ /**
72
+ * Build a worker host over the given engine config. In a real worker file the consumer calls this at module
73
+ * top level and it auto-binds the global scope; a test constructs it and drives {@link SyncWorkerHost.connect}.
74
+ */
75
+ export declare function defineSyncWorker<const TRegistry extends SyncTableRegistry>(options: DefineSyncWorkerOptions<TRegistry>): SyncWorkerHost<TRegistry>;
76
+ //# sourceMappingURL=define-sync-worker.d.ts.map
@@ -0,0 +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;AAKlB,OAAO,EAEL,KAAK,WAAW,EAGhB,KAAK,UAAU,EAWhB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,uBAAuB,CAAC,SAAS,SAAS,iBAAiB;IAC1E;;;;OAIG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,KAAK,SAAS,GAAG,SAAS,CAAC;IACtE;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACxF,WAAW,EAAE,MAA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veDiffPayload } from "./protocol";
2
+ /**
3
+ * The stable key for a result row (§4). With `pkColumns`, join their values (composite-safe) — this is the
4
+ * diff-keying identity, so a row whose PK is unchanged is the SAME logical row even if other columns moved.
5
+ * Without `pkColumns` (a keyless query) fall back to the whole-row JSON value: still diff-shaped (never a
6
+ * full resend), but an update surfaces as remove+add rather than a `changed` — the documented keyless
7
+ * fallback. Duplicate identical keyless rows collapse under this scheme (accepted for the fallback).
8
+ */
9
+ export declare function rowKey(row: Record<string, unknown>, pkColumns: readonly string[] | undefined): string;
10
+ /** The worker's per-subscription memory: the last delivered rows keyed by {@link rowKey}, in delivered order. */
11
+ export interface LiveDiffState {
12
+ pkColumns?: readonly string[];
13
+ /** key → the exact row body last sent, so the next diff can detect `changed` and skip unchanged rows. */
14
+ previous: Map<string, Record<string, unknown>>;
15
+ }
16
+ /** Seed the diff state from the initial snapshot (which the worker sends verbatim, not as a diff). */
17
+ export declare function seedLiveDiffState(rows: readonly Record<string, unknown>[], pkColumns: readonly string[] | undefined): LiveDiffState;
18
+ /**
19
+ * Diff a fresh ordered result set against the state's previous set, MUTATING the state to the new set and
20
+ * returning the wire diff (§4). `order` is every key in the new ORDER BY order (keys only — cheap); `added`/
21
+ * `changed` carry the delta row BODIES; `removed` carries dropped keys. Never emits the full result set: a
22
+ * single-row change yields one `changed` and the (key-only) `order`.
23
+ */
24
+ export declare function computeLiveDiff(state: LiveDiffState, nextRows: readonly Record<string, unknown>[]): Omit<LiveDiffPayload, "queryId">;
25
+ /**
26
+ * The tab-side fold of live diffs into an ordered row array with STABLE object identity (§4). The initial
27
+ * snapshot seeds the cache; each diff rebuilds the array from `diff.order`, reusing the cached object for
28
+ * any key not in `added`/`changed` (so an unchanged row keeps `===` and a memoized React row skips its
29
+ * re-render), and installing a fresh object for added/changed keys. Order is exactly `diff.order` — the
30
+ * query's ORDER BY as delivered by the worker.
31
+ */
32
+ export declare class LiveRowsMaterializer<TRow extends Record<string, unknown> = Record<string, unknown>> {
33
+ private byKey;
34
+ private rows;
35
+ private readonly pkColumns;
36
+ constructor(pkColumns: readonly string[] | undefined);
37
+ /** Seed from the initial snapshot; returns the initial ordered rows (each a distinct cached object). */
38
+ seed(initialRows: readonly TRow[]): TRow[];
39
+ /** Apply a diff; returns the new ordered array (a fresh array, but unchanged rows keep their object identity). */
40
+ apply(diff: Omit<LiveDiffPayload, "queryId">): TRow[];
41
+ /** The current ordered rows (identity-stable across `apply` calls for unchanged rows). */
42
+ current(): TRow[];
43
+ }
44
+ //# sourceMappingURL=live-diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-diff.d.ts","sourceRoot":"","sources":["../../src/worker/live-diff.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAKlD;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAKrG;AAaD,iHAAiH;AACjH,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,yGAAyG;IACzG,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAChD;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EACxC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACvC,aAAa,CAIf;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAC3C,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,CA+BlC;AAED;;;;;;GAMG;AACH,qBAAa,oBAAo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