@pgxsinkit/client 0.3.0 → 0.5.1

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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-APACHE-2.0 +202 -0
  3. package/NOTICE +81 -0
  4. package/README.md +10 -3
  5. package/dist/boot-report.d.ts +8 -8
  6. package/dist/circuits/envelope-to-change.d.ts +9 -5
  7. package/dist/circuits/envelope-to-change.d.ts.map +1 -1
  8. package/dist/circuits/group-sync.d.ts +2 -2
  9. package/dist/circuits/group-sync.d.ts.map +1 -1
  10. package/dist/circuits/stream-source.d.ts +6 -0
  11. package/dist/circuits/stream-source.d.ts.map +1 -1
  12. package/dist/circuits/sync-engine.d.ts +2 -2
  13. package/dist/circuits/sync-engine.d.ts.map +1 -1
  14. package/dist/event-lane.d.ts +32 -1
  15. package/dist/event-lane.d.ts.map +1 -1
  16. package/dist/export-data.d.ts +3 -3
  17. package/dist/export-dump.d.ts +10 -10
  18. package/dist/export-dump.d.ts.map +1 -1
  19. package/dist/export-store.d.ts +13 -13
  20. package/dist/index.d.ts +196 -100
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +1044 -487
  23. package/dist/index.js.map +39 -36
  24. package/dist/local-store.d.ts +1 -1
  25. package/dist/local-store.d.ts.map +1 -1
  26. package/dist/local-tables.d.ts +58 -0
  27. package/dist/local-tables.d.ts.map +1 -1
  28. package/dist/mutation.d.ts +2 -2
  29. package/dist/mutation.d.ts.map +1 -1
  30. package/dist/mutations-api.d.ts +1 -1
  31. package/dist/mutations-api.d.ts.map +1 -1
  32. package/dist/opfs-effects.d.ts +30 -2
  33. package/dist/opfs-effects.d.ts.map +1 -1
  34. package/dist/schema.d.ts +12 -1
  35. package/dist/schema.d.ts.map +1 -1
  36. package/dist/store-boot.d.ts +30 -2
  37. package/dist/store-boot.d.ts.map +1 -1
  38. package/dist/store-build.d.ts +19 -0
  39. package/dist/store-build.d.ts.map +1 -0
  40. package/dist/store-engine.d.ts +22 -0
  41. package/dist/store-engine.d.ts.map +1 -0
  42. package/dist/store-meta.d.ts +29 -3
  43. package/dist/store-meta.d.ts.map +1 -1
  44. package/dist/store-ownership-lock.d.ts +33 -0
  45. package/dist/store-ownership-lock.d.ts.map +1 -0
  46. package/dist/store-path.d.ts +43 -31
  47. package/dist/store-path.d.ts.map +1 -1
  48. package/dist/sync/apply.d.ts +5 -5
  49. package/dist/sync/apply.d.ts.map +1 -1
  50. package/dist/sync/copy.d.ts +82 -6
  51. package/dist/sync/copy.d.ts.map +1 -1
  52. package/dist/sync/drizzle-executor.d.ts +4 -4
  53. package/dist/sync/drizzle-executor.d.ts.map +1 -1
  54. package/dist/sync/subscription-state.d.ts +5 -5
  55. package/dist/sync/subscription-state.d.ts.map +1 -1
  56. package/dist/testing.d.ts +1 -1
  57. package/dist/testing.js +2 -1
  58. package/dist/testing.js.map +4 -4
  59. package/dist/worker/attach-sync-client.d.ts +24 -13
  60. package/dist/worker/attach-sync-client.d.ts.map +1 -1
  61. package/dist/worker/define-sync-worker.d.ts +35 -18
  62. package/dist/worker/define-sync-worker.d.ts.map +1 -1
  63. package/dist/worker/live-query-manager.d.ts +3 -3
  64. package/dist/worker/live-query-manager.d.ts.map +1 -1
  65. package/dist/worker/live-query-params-guard.d.ts +5 -5
  66. package/dist/worker/live-query-params-guard.d.ts.map +1 -1
  67. package/dist/worker/protocol.d.ts +26 -7
  68. package/dist/worker/protocol.d.ts.map +1 -1
  69. package/package.json +11 -8
  70. package/skills/core/SKILL.md +80 -15
  71. package/skills/operating/SKILL.md +129 -129
  72. package/skills/operating/references/postgres-builds.md +48 -0
  73. package/src/boot-report.ts +12 -12
  74. package/src/circuits/envelope-to-change.ts +121 -12
  75. package/src/circuits/group-sync.ts +2 -2
  76. package/src/circuits/stream-source.ts +35 -9
  77. package/src/circuits/sync-engine.ts +6 -4
  78. package/src/event-lane.ts +132 -14
  79. package/src/export-data.ts +4 -4
  80. package/src/export-dump.ts +31 -36
  81. package/src/export-store.ts +20 -20
  82. package/src/index.ts +576 -340
  83. package/src/live-rows-sql.ts +1 -1
  84. package/src/local-store.ts +2 -2
  85. package/src/local-tables.ts +70 -6
  86. package/src/mutation.ts +9 -8
  87. package/src/mutations-api.ts +4 -4
  88. package/src/opfs-effects.ts +74 -10
  89. package/src/schema.ts +124 -18
  90. package/src/store-boot.ts +71 -7
  91. package/src/store-build.ts +37 -0
  92. package/src/store-engine.ts +94 -0
  93. package/src/store-lifecycle.ts +1 -1
  94. package/src/store-meta.ts +155 -4
  95. package/src/store-ownership-lock.ts +109 -0
  96. package/src/store-path.ts +59 -43
  97. package/src/sync/apply.ts +32 -46
  98. package/src/sync/copy.ts +108 -13
  99. package/src/sync/drizzle-executor.ts +18 -19
  100. package/src/sync/metadata-tables.ts +1 -1
  101. package/src/sync/subscription-state.ts +7 -7
  102. package/src/testing.ts +3 -3
  103. package/src/worker/attach-sync-client.ts +146 -60
  104. package/src/worker/define-sync-worker.ts +212 -83
  105. package/src/worker/engine-router.ts +1 -1
  106. package/src/worker/live-query-fingerprint.ts +4 -4
  107. package/src/worker/live-query-manager.ts +12 -12
  108. package/src/worker/live-query-params-guard.ts +16 -15
  109. package/src/worker/protocol.ts +38 -7
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { type QueryOptions, type Results } from "@electric-sql/pglite";
2
- import { type PGliteWithLive } from "@electric-sql/pglite/live";
3
- import type { PgliteDatabase } from "drizzle-orm/pglite";
4
- import type { MutationAck, MutationDiagnostics, MutationSummary, RegistryRelations, RegistryViews, SyncRuntimeStatus, SyncTableCreateInput, SyncStorageDeclaration, SyncTableName, SyncTableRegistry, SyncTableUpdateInput, StorageDurability, WriteMode } from "@pgxsinkit/contracts";
5
- import type { CreateOpfsRepackedPGliteOptions, OpfsRepackedPGlite } from "@pgxsinkit/pglite-opfs-repacked";
1
+ import type { MutationAck, MutationDiagnostics, MutationSummary, RegistryRelations, RegistryViews, SyncRuntimeStatus, SyncTableCreateInput, SyncStorageDeclaration, SyncTableName, SyncTableRegistry, SyncTableUpdateInput, StorageBuild, StorageDurability, StoreBuildCheckSite, WriteMode } from "@pgxsinkit/contracts";
2
+ import { type PostgresBuild, type QueryOptions, type Results } from "@pgxsinkit/pgwasm";
3
+ import type { PgwasmDatabase } from "@pgxsinkit/pgwasm/drizzle";
4
+ import { live, type PgwasmWithLive } from "@pgxsinkit/pgwasm/live";
5
+ import type { CreateOpfsPgwasmOptions, OpfsPgwasm } from "@pgxsinkit/pgwasm/opfs";
6
6
  import { type BootReport } from "./boot-report";
7
7
  import { type ConvergenceTrigger } from "./convergence";
8
8
  import { type EventAppendResult, type EventLaneOptions, type EventLaneReport, type OutboxStatus } from "./event-lane";
@@ -29,7 +29,9 @@ export { classifyEventBatchFailure, computeEventBackoffMs, createEventFlushDrive
29
29
  export { destroyStoreArtifacts, type ElectedEngineWorker, ElectedEngineUnconstructibleError, ProvisionExpiredError, quiesceStoreWorker, StoreDestroyRefusedError, type StoreDestructionRetryOptions, type StoreWorkerQuiesceOptions, type StoreWorkerQuiesceOutcome, wrapEngineWorker, } from "./worker/attach-sync-client";
30
30
  export { ENGINE_RELOCATED_CODE, EngineRelocatedError, type EngineRelocatedOutcome, type ExecutionLimitConfig, ExecutionLimitMismatchError, PROVISION_STALLED_CODE, ProvisionStalledError, provisionStalledFromWire, type ProvisionStalledWire, } from "./worker/engine-control";
31
31
  export { createOpfsEffects, type OpfsEffects, type OpfsEffectsDeps } from "./opfs-effects";
32
+ export { STORE_OWNERSHIP_WAIT_MS, StoreOwnershipWaitError } from "./store-ownership-lock";
32
33
  export { COMMITTED_STORE_UNREACHABLE_CODE, CommittedStoreUnreachableError, committedStoreUnreachableFromWire, type CommittedStoreUnreachableWire, resolveStoreBoot, type ResolvedStorageBackend, type ResolveStoreBootOptions, type StoreBootResolution, } from "./store-boot";
34
+ export { createStoreEngineResolver, loadStoreEngineFactory, type StoreEngineFactory, type StoreEngineModuleLoader, } from "./store-engine";
33
35
  export { InvalidStorePathError, NonPersistentStoreError, resolveStoreDataDir, RestoreTargetExistsError, storeIndexedDbDatabaseName, storeTargetExists, } from "./store-path";
34
36
  export { type ConvergenceClient, type ConvergenceDriver, type ConvergenceDriverOptions, type ConvergenceTrigger, createBrowserConvergenceTrigger, createConvergenceDriver, createIntervalConvergenceTrigger, } from "./convergence";
35
37
  export { setSyncDebugSink, syncDebug, timeAsync } from "./debug";
@@ -41,6 +43,7 @@ export { createWorkerTokenCache, type WorkerTokenCache } from "./worker/token-ca
41
43
  export { type AttachAckPayload, type AttachPayload, type AuthTokenSnapshot, BRIDGE_CHANNEL, BRIDGE_PROTOCOL_VERSION, type BridgeCodec, type BridgeEnvelope, type BridgeEvent, type BridgeMessageType, type BridgePort, type BridgeTransferable, encodeEnvelope, type ExportArtefactWire, identityCodec, isBridgeEnvelope, type LiveDiffPayload, type LiveInitialPayload, postBridgeMessage, type ProvisionAckPayload, type ProvisionPayload, type RpcOp, type RpcPayload, type RpcResultPayload, type SetOnlinePayload, type SubscribePayload, type TokenRequestPayload, type TokenResponsePayload, type WakePayload, } from "./worker/protocol";
42
44
  export { assertLazyRefsActivated, buildLazyGuardIndex, findReferencedLazyKeysInSql, findReferencedSyncedKeysInSql, type LazyGuardIndex, LazyRelationNotActivatedError, } from "./lazy-guard";
43
45
  export { OUTBOX_SEQUENCE, OUTBOX_TABLE } from "./schema";
46
+ export { buildCopyFromBlobStatement, type CopyFromBlobStatementOptions, generateCopyData, serializeCopyValue, } from "./sync/copy";
44
47
  export { createTokenRecovery, readShapeStream, STREAM_START } from "./circuits/stream-source";
45
48
  export type { ShapeStreamSubscription, StreamBatch, StreamSourceOptions } from "./circuits/stream-source";
46
49
  export { createShapeGroup } from "./circuits/shape-group";
@@ -77,34 +80,34 @@ export declare class WriteNotReadyError extends Error {
77
80
  export declare class ClientDisposedError extends Error {
78
81
  constructor();
79
82
  }
80
- export type ClientPGlite = PGliteWithLive;
81
- /**
82
- * The pre-warmed PGlite boot assets (the WASM modules + filesystem bundle), consumed by
83
- * {@link createClientPGlite} / {@link CreateSyncClientOptions.pgliteBootAssets}. The host fetches +
84
- * compiles these on an earlier screen and hands the promise in, so `PGlite.create` skips its own lazy
85
- * asset load — see the field's JSDoc for the accelerator geometry.
86
- */
87
- export interface PgliteBootAssets {
88
- pgliteWasmModule?: WebAssembly.Module;
89
- initdbWasmModule?: WebAssembly.Module;
90
- fsBundle?: Blob;
91
- }
92
- /** Options for {@link createClientPGlite}. */
93
- export interface CreateClientPGliteOptions {
83
+ export type PgwasmClient = PgwasmWithLive;
84
+ /** Options for {@link createPgwasmClient}. */
85
+ export interface CreatePgwasmClientOptions {
86
+ /**
87
+ * The Postgres build the store runs on (see {@link CreateSyncClientOptions.build}); defaults to `cBuild`.
88
+ * Pass `createCBuild({ assets })` to hand in pre-warmed WASM modules and filesystem bundle: a rejected warm
89
+ * falls back to the build's own asset load, so it never fails the create.
90
+ */
91
+ build?: PostgresBuild;
92
+ /**
93
+ * @internal Toolkit-internal declared-build carrier (ADR-0063), NOT a public per-open knob: the registry's
94
+ * resolved `storage.build`, threaded by the sites that resolve a declaration (`createSyncClient`'s mints,
95
+ * the worker's provision and spare mints). When present, the supplied {@link build} must be that build
96
+ * ({@link StorageBuildMismatchError}, thrown before the store is touched); absent, no declaration is checked.
97
+ */
98
+ declaredBuild?: StorageBuild;
94
99
  /**
95
- * Pre-warmed PGlite boot assets (see {@link CreateSyncClientOptions.pgliteBootAssets}). Awaited and
96
- * passed into `PGlite.create`; a rejected warm is caught to `undefined` (falls back to PGlite's own
97
- * asset load), so it never fails the create.
100
+ * @internal The site the {@link declaredBuild} check reports; defaults to `"createPgwasmClient"`.
98
101
  */
99
- bootAssets?: Promise<PgliteBootAssets>;
102
+ buildCheckSite?: StoreBuildCheckSite;
100
103
  /**
101
104
  * @internal Toolkit-internal durability carrier (ADR-0047), NOT a public per-open knob. Durability is
102
105
  * registry-declared: {@link createSyncClient} resolves `storage.durability ?? "relaxed"` off its registry
103
106
  * and threads the resolved mode in here — the ONE resolution point — for every mint it funnels through this
104
107
  * factory (its own boot, the worker provision/spare mint, the pre-expose idb drain read). Defaults to
105
- * `"relaxed"` when absent and is stamped onto the `boot pglite.create` rail (ADR-0047 D3). On idb, relaxed
108
+ * `"relaxed"` when absent and is stamped onto the `boot pgwasm.create` rail (ADR-0047 D3). On idb, relaxed
106
109
  * returns before the whole-datadir snapshot flush and schedules it asynchronously; strict keeps that
107
- * synchronous snapshot (~100–200ms per statement). On OPFS-repacked the package factory keeps PGlite on its
110
+ * synchronous snapshot (~100–200ms per statement). On OPFS-repacked the package factory keeps pgwasm on its
108
111
  * awaited host path: relaxed routine sync asserts health without an ordinary physical flush, while strict
109
112
  * flushes arena data before metadata. Initialization, activation, and open-state close retain strict
110
113
  * ordering in both OPFS modes.
@@ -118,10 +121,10 @@ export interface CreateClientPGliteOptions {
118
121
  backendOverride?: "memory";
119
122
  /**
120
123
  * A store-backup tarball to seed the new store from (ADR-0035 decision 6, restore) — a `File`/`Blob` as
121
- * produced by {@link SyncClient.exportStore}. Passed straight to PGlite's `loadDataDir`, so the created
124
+ * produced by {@link SyncClient.exportStore}. Passed straight to pgwasm's `loadDataDir`, so the created
122
125
  * store boots ON the backup's datadir. Restore is a CREATION-path feature: the caller (`createSyncClient`)
123
126
  * has already proven the target does not yet exist ({@link storeTargetExists}); this option carries no
124
- * freshness check of its own. A corrupt/foreign tarball surfaces as a PGlite boot failure here.
127
+ * freshness check of its own. A corrupt/foreign tarball surfaces as a pgwasm boot failure here.
125
128
  */
126
129
  restoreFrom?: File | Blob;
127
130
  /**
@@ -134,12 +137,16 @@ export interface CreateClientPGliteOptions {
134
137
  /**
135
138
  * @internal ADR-0049 step 10a: the opfs-repacked factory + store-directory seam, injectable so Bun unit
136
139
  * tests exercise the `opfs://` branch WITHOUT loading real WASM/OPFS. In production both default to the real
137
- * implementations (`createOpfsRepackedPGlite` via a lazy `import()`, and the OPFS effects' store directory
140
+ * implementations (`createOpfsPgwasm` via a lazy `import()`, and the OPFS effects' store directory
138
141
  * handle). Never consumer-facing.
139
142
  */
140
- pgliteFactories?: {
141
- /** The opfs-repacked PGlite factory; defaults to a lazily-imported `createOpfsRepackedPGlite`. */
142
- createOpfsRepacked?: (options: CreateOpfsRepackedPGliteOptions) => Promise<OpfsRepackedPGlite>;
143
+ opfsFactories?: {
144
+ /** The OPFS store factory; defaults to a lazily-imported `createOpfsPgwasm` from `@pgxsinkit/pgwasm/opfs`. */
145
+ createOpfsPgwasm?: (options: CreateOpfsPgwasmOptions<{
146
+ live: typeof live;
147
+ }>) => Promise<OpfsPgwasm<{
148
+ live: typeof live;
149
+ }>>;
143
150
  /** The create-if-absent store directory handle for the factory; defaults to the real OPFS effects. */
144
151
  getStoreDirectoryHandle?: () => Promise<unknown>;
145
152
  /** Backoff between bounded open retries (ms); defaults to a small real delay. Tests pass `0`. */
@@ -147,27 +154,27 @@ export interface CreateClientPGliteOptions {
147
154
  };
148
155
  }
149
156
  /**
150
- * Create the raw local PGlite store the sync client runs on — the SAME `PGlite.create` call
157
+ * Create the raw local pgwasm store the sync client runs on — the SAME `pgwasm.create` call
151
158
  * {@link createSyncClient} makes internally (the `live` extension, pre-warmed boot-asset
152
- * consumption, and the `boot pglite.create` rail stamp), extracted so exactly one implementation exists
159
+ * consumption, and the `boot pgwasm.create` rail stamp), extracted so exactly one implementation exists
153
160
  * and a host can create the store EAGERLY on an earlier screen. Hand the returned (still-pending)
154
- * instance to {@link CreateSyncClientOptions.precreatedPglite}: the client then owns schema exec, prepare
161
+ * instance to {@link CreateSyncClientOptions.precreatedPgwasm}: the client then owns schema exec, prepare
155
162
  * hooks, journal recovery, and registry reconciliation, exactly as its own `storePath` path does.
156
163
  *
157
164
  * Takes a plain store path (ADR-0036), never a storage URL — the backend is DERIVED from the engine home
158
165
  * (capability-selected opfs-repacked with IndexedDB fallback in a browser, or the filesystem on Bun/Node);
159
166
  * a scheme-bearing path throws {@link InvalidStorePathError}.
160
- * Also accepts the testing helper's output (`createClientPGlite(memoryStoreForTests("x"))`) so a test can
167
+ * Also accepts the testing helper's output (`createPgwasmClient(memoryStoreForTests("x"))`) so a test can
161
168
  * mint a memory store without naming a backend.
162
169
  *
163
170
  * The instance is deliberately **schemaless** — the registry-derived local schema is role/registry
164
171
  * dependent, so it is applied post-create by `createSyncClient`. The eager create buys only the expensive
165
172
  * initdb (+ persistent-store open), which is the dominant cold-boot cost once the WASM is pre-warmed.
166
173
  *
167
- * `bootAssets` is the pre-warmed WASM/fs bundle (see {@link CreateSyncClientOptions.pgliteBootAssets}); a
168
- * rejected warm is caught to `undefined`, so PGlite falls back to loading its own assets — never a failure.
174
+ * `build` is the Postgres build (see {@link CreateSyncClientOptions.build}); a `createCBuild({ assets })` whose
175
+ * warm rejects loads its own assets — never a failure.
169
176
  */
170
- export declare function createClientPGlite(store: StorePathInput, options?: CreateClientPGliteOptions): Promise<ClientPGlite>;
177
+ export declare function createPgwasmClient(store: StorePathInput, options?: CreatePgwasmClientOptions): Promise<PgwasmClient>;
171
178
  /**
172
179
  * @internal Injectable seams for the FRESH/RESTORE commitment boot wiring (step 11c). Real defaults in
173
180
  * production (`globalThis.indexedDB` / `navigator.storage`); unit tests inject fakes so the phase machine and
@@ -216,11 +223,11 @@ export interface FreshBootResolution {
216
223
  export declare function resolveFreshBoot(storePath: string, hasOpfsSyncAccess: boolean, backendOverride: "memory" | undefined, seams?: FreshCommitmentSeams): Promise<FreshBootResolution>;
217
224
  export declare function runFreshCommitmentBarrier(storePath: string, strictSyncReturns: () => Promise<void>, seams?: FreshCommitmentSeams): Promise<void>;
218
225
  /**
219
- * @internal The ADOPTED-boot commitment gate. A boot that ADOPTS an instance (`pgliteInstance` /
220
- * `precreatedPglite` — the provision→adopt accelerator, ADR-0032 decision 5) never enters `openOwnedStore`, so
226
+ * @internal The ADOPTED-boot commitment gate. A boot that ADOPTS an instance (`pgwasmInstance` /
227
+ * `precreatedPgwasm` — the provision→adopt accelerator, ADR-0032 decision 5) never enters `openOwnedStore`, so
221
228
  * {@link resolveFreshBoot} never runs and nothing flags the barrier. Left alone, an adopted OPFS store therefore
222
229
  * stays UNCOMMITTED for its whole life: no sentinel, and a record still at `opfs-candidate` (or absent, when the
223
- * adopted instance was built outside the mint seam — a BYO `pgliteInstance`). That state is INDISTINGUISHABLE
230
+ * adopted instance was built outside the mint seam — a BYO `pgwasmInstance`). That state is INDISTINGUISHABLE
224
231
  * from a torn candidate, so the next client-owned boot classifies `delete-candidate-and-rebuild` and DESTROYS a
225
232
  * populated store — offline, with nothing to rebuild from. An adopted opfs boot therefore owes the SAME barrier
226
233
  * ({@link runFreshCommitmentBarrier}) a fresh one does, pre-expose (invariant 3).
@@ -314,7 +321,7 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
314
321
  */
315
322
  readSilenceMs?: number;
316
323
  /**
317
- * The local store's name (ADR-0036) — a PLAIN path/name, never a PGlite storage URL. The storage backend
324
+ * The local store's name (ADR-0036) — a PLAIN path/name, never a pgwasm storage URL. The storage backend
318
325
  * is DERIVED from the engine home (capability-selected opfs-repacked with IndexedDB fallback in a browser,
319
326
  * or the filesystem on Bun/Node); a
320
327
  * scheme-bearing string (anything containing `://`) is rejected with {@link InvalidStorePathError}
@@ -336,68 +343,73 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
336
343
  * ADR-0049 D1: the placement probe's OPFS-sync-access grant, threaded from the SharedWorker's engine home
337
344
  * (`defineSyncWorker`'s SW-direct bootstrap) into this boot so the client-owned create opens the OPFS-repacked
338
345
  * backend. Absent/false is the honest IDBFS home — the declared `backend: "idbfs"` mode or a capability-absence
339
- * fallback (a main thread can never hold handles either). Forwarded verbatim to {@link createClientPGlite}, which
346
+ * fallback (a main thread can never hold handles either). Forwarded verbatim to {@link createPgwasmClient}, which
340
347
  * resolves the actual dataDir from it.
341
348
  */
342
349
  hasOpfsSyncAccess?: boolean;
343
350
  /**
344
- * Pre-warmed PGlite boot assets (the WASM modules + filesystem bundle), awaited and passed straight
345
- * into `PGlite.create`. The intent is to hide PGlite's ~2.5s cold `boot pglite.create` cost —
346
- * dominated by the WASM fetch+compile — behind user think-time: the host starts fetching/compiling
347
- * these on an earlier screen (e.g. the login/identity picker) and hands the still-pending promise
348
- * here, so by the time a store is opened the assets are already resolved and `PGlite.create` skips
349
- * its own lazy asset load. Ignored when {@link pgliteInstance} is supplied (the caller owns that
350
- * instance's boot). A rejected/failed warm is caught to `undefined` and never fails the boot — PGlite
351
- * falls back to loading its own assets, so this is a pure best-effort accelerator.
351
+ * The Postgres build a client-owned store runs on; defaults to `cBuild`. To hide the ~2.5s cold
352
+ * `boot pgwasm.create` cost — dominated by the WASM fetch+compile — behind user think-time, pass
353
+ * `createCBuild({ assets })` from `@pgxsinkit/pgwasm-c`, where `assets` is a `Promise<CBuildAssets>` the host
354
+ * started fetching/compiling on an earlier screen (e.g. the login/identity picker): by the time a store is
355
+ * opened the assets are resolved and the build skips its own lazy asset load. Ignored when
356
+ * {@link pgwasmInstance} is supplied (the caller owns that instance's boot). A rejected/failed warm never
357
+ * fails the boot — the build falls back to loading its own assets, so the warm is a pure best-effort
358
+ * accelerator. The boot waits for the build's `prepare()` (the warm) before its `boot pgwasm.create` stamp,
359
+ * so `pgwasmCreateMs` measures the create alone.
360
+ *
361
+ * The build must be the registry's declared `storage.build` (default `"c"`, ADR-0063): a mismatch throws
362
+ * `StorageBuildMismatchError` before any store is touched. An adopted {@link pgwasmInstance} /
363
+ * {@link precreatedPgwasm} is checked the same way, against its own `pg.build`.
352
364
  */
353
- pgliteBootAssets?: Promise<PgliteBootAssets>;
365
+ build?: PostgresBuild;
354
366
  resetSubscriptionKeys?: string[];
355
- prepareLocalDbBeforeSchema?: (pglite: ClientPGlite) => Promise<void>;
356
- prepareLocalDbAfterSchema?: (pglite: ClientPGlite) => Promise<void>;
367
+ prepareLocalDbBeforeSchema?: (pgwasm: PgwasmClient) => Promise<void>;
368
+ prepareLocalDbAfterSchema?: (pgwasm: PgwasmClient) => Promise<void>;
357
369
  onStatusChange?: (status: SyncRuntimeStatus) => void;
358
370
  onTableInitialSync?: (tableKey: string) => void;
359
371
  /**
360
- * A fully-provisioned PGlite instance the CALLER owns end-to-end. The client runs NONE of its
372
+ * A fully-provisioned pgwasm instance the CALLER owns end-to-end. The client runs NONE of its
361
373
  * post-create boot steps against it — no schema exec, prepare hooks, or registry reconciliation
362
374
  * (journal recovery still runs, as it does on every path). Use it only when the caller has already
363
- * applied the registry schema itself. Contrast the three PGlite-provenance seams:
375
+ * applied the registry schema itself. Contrast the three store-provenance seams:
364
376
  * - {@link storePath} (default) — the client creates the store AND runs every post-create step.
365
- * - {@link precreatedPglite} — the caller creates the raw store (via {@link createClientPGlite}), but
377
+ * - {@link precreatedPgwasm} — the caller creates the raw store (via {@link createPgwasmClient}), but
366
378
  * the client still runs every post-create step (schema, prepare hooks, and reconciliation), exactly as
367
379
  * `storePath` does.
368
- * - `pgliteInstance` — the caller creates AND provisions the store; the client runs none of them.
380
+ * - `pgwasmInstance` — the caller creates AND provisions the store; the client runs none of them.
369
381
  *
370
382
  * A caller-owned instance is REFUSED with {@link NonPersistentStoreError} if it is provably
371
- * non-persistent (a `new PGlite()` default, or an in-memory store) — pgxsinkit's durability semantics
383
+ * non-persistent (a `new pgwasm()` default, or an in-memory store) — pgxsinkit's durability semantics
372
384
  * assume a persisted store (ADR-0036). Acknowledge a deliberate test store by spreading
373
385
  * `testStoreAcknowledgment()` from `@pgxsinkit/client/testing`.
374
386
  *
375
- * Mutually exclusive with {@link precreatedPglite} (supplying both throws).
387
+ * Mutually exclusive with {@link precreatedPgwasm} (supplying both throws).
376
388
  */
377
- pgliteInstance?: ClientPGlite;
389
+ pgwasmInstance?: PgwasmClient;
378
390
  /**
379
- * A raw PGlite instance the caller created EAGERLY (via {@link createClientPGlite}) — typically on an
391
+ * A raw pgwasm instance the caller created EAGERLY (via {@link createPgwasmClient}) — typically on an
380
392
  * earlier screen, to hide the ~1.9s cold `initdb`/IDBFS open behind user think-time — but for which the
381
393
  * client still owns EVERYTHING else: schema exec, prepare hooks, journal recovery, and registry
382
394
  * reconciliation all run exactly as on the {@link storePath} path. This is the difference from
383
- * {@link pgliteInstance} (which skips schema, prepare hooks, and reconciliation because the caller owns
395
+ * {@link pgwasmInstance} (which skips schema, prepare hooks, and reconciliation because the caller owns
384
396
  * them); see that
385
397
  * option's JSDoc for the three-way distinction.
386
398
  *
387
399
  * The promise form lets the still-pending eager create be handed straight in. Precedence/validation:
388
- * - Supplying both this and {@link pgliteInstance} throws — they claim different ownership.
400
+ * - Supplying both this and {@link pgwasmInstance} throws — they claim different ownership.
389
401
  * - {@link storePath} is used ONLY as the fallback store name if this promise REJECTS: a failed eager
390
402
  * create is caught, logged on the boot rail, and the normal `storePath` create path runs instead (also
391
- * consuming {@link pgliteBootAssets} if provided). The pattern is a pure accelerator, never a boot
403
+ * consuming {@link build} if provided). The pattern is a pure accelerator, never a boot
392
404
  * dependency.
393
405
  * - A successfully-adopted instance is subject to the same {@link NonPersistentStoreError} refusal as
394
- * {@link pgliteInstance} (checked after resolution, so the refusal propagates rather than being
406
+ * {@link pgwasmInstance} (checked after resolution, so the refusal propagates rather than being
395
407
  * swallowed by the reject-fallback).
396
408
  */
397
- precreatedPglite?: Promise<ClientPGlite>;
409
+ precreatedPgwasm?: Promise<PgwasmClient>;
398
410
  /**
399
411
  * Restore the store from a **store backup** (ADR-0035 decision 6) — a `File`/`Blob` tarball as produced by
400
- * {@link SyncClient.exportStore}. The client creates its store with the backup handed to PGlite's
412
+ * {@link SyncClient.exportStore}. The client creates its store with the backup handed to pgwasm's
401
413
  * `loadDataDir`, so it boots ON the backup's datadir (synced cache + Overlay + Mutation journal, all the
402
414
  * bytes that travelled inside it). Three restore-only rules apply, none of them optional:
403
415
  *
@@ -416,7 +428,7 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
416
428
  * ledger, so replay is unsafe on last-write-wins tables). Release (`retryFailed`) or discard
417
429
  * (`discardQuarantined`) them explicitly. When this pass quarantines nothing, the restore comes online (above).
418
430
  *
419
- * Mutually exclusive with {@link pgliteInstance} AND {@link precreatedPglite} — restore owns the store's
431
+ * Mutually exclusive with {@link pgwasmInstance} AND {@link precreatedPgwasm} — restore owns the store's
420
432
  * creation (`loadDataDir` is a create-time seed), so a caller-supplied instance conflicts (supplying either
421
433
  * with `restoreFrom` throws).
422
434
  */
@@ -424,7 +436,7 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
424
436
  /**
425
437
  * PROVABLY-fresh store hint (ADR-0032 S4 / backlog-0003): the caller guarantees this store is brand-new
426
438
  * and schemaless — no prior schema, no synced rows, no persisted subscription state. When set (and sync
427
- * is enabled, and the client owns schema exec — i.e. not the {@link pgliteInstance} path), the shape
439
+ * is enabled, and the client owns schema exec — i.e. not the {@link pgwasmInstance} path), the shape
428
440
  * catch-up is started BEFORE the local boot phases (schema exec, journal recovery, and registry
429
441
  * reconciliation) and buffered in memory, with commits gated until those phases finish — so the network
430
442
  * catch-up overlaps them instead of running strictly after. On a far-from-database caller this collapses
@@ -485,9 +497,10 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
485
497
  batchEventUrl?: string;
486
498
  /**
487
499
  * The Event lane's client-level flush policy (ADR-0053): batch caps, the fallback interval, backoff
488
- * tuning, and per-Event-stream overrides. NEVER on the registry — the registry is the contract, cadence is
489
- * deployment tuning, and a batch-size tweak must not surface as a registry diff. Client batching is
490
- * additionally clamped by the contracts-level request-shape limits the server enforces independently.
500
+ * tuning, the acked ledger's retention (ADR-0060), and per-Event-stream overrides. NEVER on the registry —
501
+ * the registry is the contract, cadence is deployment tuning, and a batch-size tweak must not surface as a
502
+ * registry diff. Client batching is additionally clamped by the contracts-level request-shape limits the
503
+ * server enforces independently.
491
504
  */
492
505
  events?: EventLaneOptions;
493
506
  /**
@@ -527,8 +540,8 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
527
540
  /**
528
541
  * @internal Provision timing for a boot that ADOPTS a pre-provisioned store (ADR-0034). When the store was
529
542
  * minted ahead of boot (a spare's off-thread initdb), the provisioner stamps its create cost and ready
530
- * time here; the boot reports them as {@link BootReport.provision} and sets `phases.pgliteCreateMs = null`.
531
- * A promise because the stamp settles with the spare's `create`. Only honoured on the {@link precreatedPglite}
543
+ * time here; the boot reports them as {@link BootReport.provision} and sets `phases.pgwasmCreateMs = null`.
544
+ * A promise because the stamp settles with the spare's `create`. Only honoured on the {@link precreatedPgwasm}
532
545
  * adoption path (ignored on a fallback create). `provisionReadyAt` must share this process's monotonic clock.
533
546
  */
534
547
  provisionStamp?: Promise<{
@@ -634,7 +647,7 @@ export interface PrepareQueryInput<TRegistry extends SyncTableRegistry> {
634
647
  * The narrow live-rows seam (ADR-0032 S2 §4) both client modes implement so the `@pgxsinkit/react` hooks
635
648
  * work against either. Input for a reactive subscription: the compiled SQL + params (from a Drizzle
636
649
  * builder's `.toSQL()` or a raw string) and the result's `pkColumns` (drives worker-side diff keying;
637
- * omit for a keyless query). The in-process client runs it directly over `pglite.live`; the worker-attached
650
+ * omit for a keyless query). The in-process client runs it directly over `pgwasm.live`; the worker-attached
638
651
  * client runs the live query in the worker and streams DIFFs across the bridge.
639
652
  */
640
653
  export interface SubscribeLiveRowsInput {
@@ -643,7 +656,7 @@ export interface SubscribeLiveRowsInput {
643
656
  /**
644
657
  * The unique output aliases to render the query's columns under so it is SAFE TO MATERIALISE, in the
645
658
  * compiled SQL's column order (one per output column). Drizzle emits no output aliases, so a JOIN whose
646
- * tables share a column name compiles to duplicate output names — which PGlite's `live` extension
659
+ * tables share a column name compiles to duplicate output names — which pgwasm's `live` extension
647
660
  * refuses to materialise (`column "title" specified more than once`) and which silently collapse
648
661
  * same-named columns even in a plain query. When supplied, the seam wraps the query so every output
649
662
  * column gets its alias and rows come back KEYED BY THESE ALIASES; the consumer's row-mapper must read
@@ -708,14 +721,14 @@ export interface PreparedQueryResult<TTable extends string = string> {
708
721
  lazyTables: readonly TTable[];
709
722
  }
710
723
  export interface SyncClient<TRegistry extends SyncTableRegistry> {
711
- drizzle: PgliteDatabase<RegistryRelations<TRegistry>>;
712
- pglite: ClientPGlite;
724
+ drizzle: PgwasmDatabase<RegistryRelations<TRegistry>>;
725
+ pgwasm: PgwasmClient;
713
726
  views: RegistryViews<TRegistry>;
714
727
  tables: {
715
728
  [TKey in SyncTableName<TRegistry>]: SyncClientTableHandle<TRegistry, TKey>;
716
729
  };
717
730
  /**
718
- * Local-read readiness (ADR-0041): resolves once PGlite is open, the durable schema is ready, registry
731
+ * Local-read readiness (ADR-0041): resolves once pgwasm is open, the durable schema is ready, registry
719
732
  * reconciliation has completed, and the drizzle read
720
733
  * facade is built — so cached rows are queryable. Resolving this stage requires NO write runtime, NO sync
721
734
  * start, and NO network I/O, so an offline boot resolves it promptly. Under the ADR-0041 Option B contract
@@ -746,7 +759,7 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
746
759
  * scheduling) without awaiting. Idempotent. The first action of every teardown path — stop()/destroy() call it,
747
760
  * and the SharedWorker host calls it before draining subscribes / disposing live queries so no teardown step
748
761
  * races a still-live engine. Not a substitute for stop()/destroy(): the awaited teardown (unsubscribe, dispose,
749
- * pglite.close) still follows. Callers rarely invoke it directly.
762
+ * pgwasm.close) still follows. Callers rarely invoke it directly.
750
763
  */
751
764
  haltActivity: () => void;
752
765
  stop: () => Promise<void>;
@@ -863,7 +876,8 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
863
876
  * The store's owed-state diagnostics: the mutation journal's per-status counts, plus — when this client has
864
877
  * an Event lane — the Outbox's drain signal (ADR-0053 decision 8: the Event lane's durable state takes a
865
878
  * position on every lifecycle surface). `outbox` is the boolean signal rather than a count, for the reason
866
- * {@link onOutboxStatus} carries none; it is absent on a client with no lane.
879
+ * {@link onOutboxStatus} carries none; it is absent on a client with no lane. It reports what is OWED, so
880
+ * acked rows held by the ledger's retention (ADR-0060) read as empty.
867
881
  */
868
882
  diagnostics: (table?: SyncTableName<TRegistry>) => Promise<{
869
883
  mutation: MutationDiagnostics;
@@ -884,17 +898,45 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
884
898
  * issues stays local and will NOT converge. For app data reads prefer the live-rows hooks /
885
899
  * {@link subscribeLiveRows} (or the guarded {@link query} family); reach for this only to look at the
886
900
  * store, not to read app state or mutate it.
901
+ *
902
+ * `options.blob` makes it the single-statement BULK-LOAD seam too: pass a `COPY … FROM '/dev/blob'`
903
+ * statement plus its COPY TEXT bytes ({@link buildCopyFromBlobStatement}) to load a chunk of rows into a
904
+ * LOCAL-ONLY table the app owns without a transaction around it. Use {@link rawTransaction} when the load
905
+ * must land together with other statements.
887
906
  */
888
907
  rawQuery: (sql: string, params?: unknown[], options?: RawQueryOptions) => Promise<Results>;
889
- /** {@link rawQuery} for multi-statement SQL, returning one {@link Results} per statement. */
908
+ /** {@link rawQuery} for multi-statement SQL, returning one {@link Results} per statement. Takes no `blob`. */
890
909
  rawExec: (sql: string, options?: RawQueryOptions) => Promise<Results[]>;
910
+ /**
911
+ * {@link rawQuery}'s ATOMIC form: run the given statements, in order, inside ONE local transaction and
912
+ * resolve one {@link Results} per statement. All-or-nothing — a statement that throws rolls the whole list
913
+ * back and rejects with its error; an empty list resolves `[]` without opening a transaction at all.
914
+ *
915
+ * The seam exists for a consumer that owns LOCAL-ONLY tables pgxsinkit does not manage (a definition cache,
916
+ * a personal dictionary — anything that must delete-then-insert without a torn intermediate state). It is
917
+ * the ONLY way to get that atomicity on a worker-attached client, where the tab has no pgwasm of its own,
918
+ * and it behaves identically on both client forms rather than making atomicity depend on where the engine
919
+ * happens to live.
920
+ *
921
+ * Every {@link rawQuery} caveat still holds, transaction or not: the statements run raw against the local
922
+ * store, BYPASSING the mutation journal and optimistic overlay, so a write through here stays local and
923
+ * will NEVER converge. Use it for the tables the consumer owns — never for a synced table, whose only
924
+ * write path is `mutate` / `tables.*`.
925
+ *
926
+ * A statement may carry {@link RawStatement.blob}: the bytes of a `COPY … FROM '/dev/blob'` BULK load
927
+ * ({@link buildCopyFromBlobStatement} renders the pair). That is how a chunk of thousands of rows lands
928
+ * in one statement instead of one INSERT per row — and, in a list, atomically alongside whatever must
929
+ * land with it. On a worker-attached client those bytes are TRANSFERRED, never copied, so the caller's
930
+ * buffer is detached when the call dispatches.
931
+ */
932
+ rawTransaction: (statements: readonly RawStatement[], options?: RawQueryOptions) => Promise<Results[]>;
891
933
  /**
892
934
  * @internal The worker host's guarded one-shot read seam (ADR-0032 decision 4): {@link rawQuery} PLUS the
893
935
  * ADR-0041 read gate and the ADR-0021 lazy-group guard, sharing one gate+guard core with the in-process
894
936
  * `query`/`queryRaw` builder path so the two entry points can never drift on guard semantics.
895
937
  * `defineSyncWorker` dispatches the `guardedQuery` RpcOp to this on its owned in-process client; the attach
896
938
  * client's Drizzle-over-bridge compiles the SQL on the tab and routes the read here so the guard runs
897
- * worker-side. Accepts the full PGlite {@link QueryOptions} (the worker re-applies drizzle's identity
939
+ * worker-side. Accepts the full pgwasm {@link QueryOptions} (the worker re-applies drizzle's identity
898
940
  * parsers here — temporal OIDs + numeric[]) plus the raw-fragment `use` list. NOT part of the app-facing
899
941
  * read surface — reach for {@link query} / {@link queryRaw} instead; kept `@internal` (above) and excluded
900
942
  * from the generated API docs (typedoc excludeInternal).
@@ -931,8 +973,19 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
931
973
  */
932
974
  ensureSynced: (keys: readonly SyncTableName<TRegistry>[]) => Promise<void>;
933
975
  /**
934
- * Whether a relation's group has started and hydrated (ADR-0021). False for a still-dormant `lazy`
935
- * relation; true for eager relations once boot completes (and always when sync is disabled).
976
+ * Whether a relation's consistency group is STARTED (ADR-0021) — a durable subscription for it exists,
977
+ * so reads of it are meaningful. The synchronous peek, for guards and render paths that cannot await.
978
+ *
979
+ * For an ordinary group that coincides with caught up: it reads `false` while the group is activated but
980
+ * still catching up, and `true` once its catch-up lands. A **promoted** `lazy + persistent` group (one a
981
+ * previous session activated, so boot starts it) reads `true` from boot — including offline, while its
982
+ * subscribe is still retrying — because its local table is durable and populated, which is what "started"
983
+ * asks. A dormant `lazy` relation reads `false`, as does every relation while sync is PENDING (enabled but
984
+ * not yet wired, ADR-0041); every key reads `true` when sync is DISABLED (local-only — nothing is dormant).
985
+ *
986
+ * Catch-up COMPLETION is the separate, strictly stronger question {@link groupReady} answers. A
987
+ * worker-attached client answers this from a snapshot the worker computes with this same method on its own
988
+ * client (ADR-0059), so the two modes cannot diverge.
936
989
  */
937
990
  isSynced: (key: SyncTableName<TRegistry>) => boolean;
938
991
  /**
@@ -1013,9 +1066,9 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
1013
1066
  }) => readonly string[];
1014
1067
  /**
1015
1068
  * The live-rows seam (ADR-0032 S2 §4): register a reactive query and receive its initial ordered
1016
- * snapshot plus subsequent updates via `onRows`. The React live hooks consume THIS (not `pglite.live`
1069
+ * snapshot plus subsequent updates via `onRows`. The React live hooks consume THIS (not `pgwasm.live`
1017
1070
  * directly), so they run unchanged against both the in-process client (which implements it over
1018
- * `pglite.live`) and the worker-attached client (which implements it over the bridge). Prefer the
1071
+ * `pgwasm.live`) and the worker-attached client (which implements it over the bridge). Prefer the
1019
1072
  * higher-level `@pgxsinkit/react` hooks; this is the lower-level primitive they build on.
1020
1073
  */
1021
1074
  subscribeLiveRows: <TRow extends Record<string, unknown> = Record<string, unknown>>(input: SubscribeLiveRowsInput, onRows: (rows: TRow[]) => void) => Promise<LiveRowsSubscription<TRow>>;
@@ -1034,8 +1087,8 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
1034
1087
  */
1035
1088
  liveQueryDiagnostics: () => Promise<LiveQueryDiagnostics[]>;
1036
1089
  /**
1037
- * Take a **store backup** (ADR-0035): a full-fidelity, PGlite-restorable tarball of the whole local
1038
- * store — synced cache, Overlay, and Mutation journal (unflushed writes included) — via PGlite's
1090
+ * Take a **store backup** (ADR-0035): a full-fidelity, pgwasm-restorable tarball of the whole local
1091
+ * store — synced cache, Overlay, and Mutation journal (unflushed writes included) — via pgwasm's
1039
1092
  * `dumpDataDir`. Taken LIVE (a `CHECKPOINT` serialised behind engine work, then the dump; no engine
1040
1093
  * suspension, no tab disruption), so it never blocks and is the only lossless export an offline device
1041
1094
  * with unflushed writes can take. Awaits engine-ready rather than rejecting during boot, then runs under
@@ -1082,24 +1135,67 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
1082
1135
  }
1083
1136
  export type { MutationBatchItem, MutationDetail, MutationDiagnostics, MutationKind, MutationSummary };
1084
1137
  /**
1085
- * The structured-clone-safe subset of PGlite's `QueryOptions` the inspection surface carries. Kept
1138
+ * The structured-clone-safe subset of pgwasm's `QueryOptions` the inspection surface carries. Kept
1086
1139
  * narrow ON PURPOSE: on a worker-attached client the options object crosses the bridge via
1087
1140
  * `postMessage`, so function-valued options (`parsers`, `serializers`, `onNotice`) can never be part
1088
- * of this contract. `rowMode: "array"` is what `@electric-sql/pglite-repl` asks for on every exec.
1141
+ * of this contract. `rowMode: "array"` is what `@pgxsinkit/pgwasm-repl` asks for on every exec.
1142
+ *
1143
+ * `blob` diverges from pgwasm's own type for the same reason: pgwasm takes a `Blob`, which is neither
1144
+ * transferable nor (usefully) clonable, so this contract carries BYTES and wraps them into the `Blob` at
1145
+ * the pgwasm call (ADR-0061).
1089
1146
  */
1090
1147
  export interface RawQueryOptions {
1091
1148
  rowMode?: "object" | "array";
1149
+ /**
1150
+ * The bytes pgwasm reads when the statement is a `COPY … FROM '/dev/blob'` — the single-statement form
1151
+ * of {@link RawStatement.blob}, for a bulk load that needs no surrounding transaction. Build the
1152
+ * statement AND these bytes together with {@link buildCopyFromBlobStatement}; any other statement
1153
+ * ignores this option.
1154
+ *
1155
+ * On a worker-attached client the buffer is **TRANSFERRED**, not copied: it is detached the moment the
1156
+ * call dispatches, so the caller must NOT read or reuse it afterwards (build a fresh one per chunk).
1157
+ *
1158
+ * Typed over a real `ArrayBuffer` (not the default `ArrayBufferLike`) because that IS the contract: a
1159
+ * `SharedArrayBuffer`-backed view can neither be transferred nor read as a `Blob` part.
1160
+ */
1161
+ blob?: Uint8Array<ArrayBuffer>;
1162
+ }
1163
+ /**
1164
+ * One statement of a {@link SyncClient.rawTransaction} list: the SQL plus its bound params, and optionally
1165
+ * the `blob` bytes a `COPY` statement ingests. Structured-clone safe by construction (a string, plain
1166
+ * values and a `Uint8Array`), because on a worker-attached client the whole list crosses the bridge in a
1167
+ * single RPC.
1168
+ */
1169
+ export interface RawStatement {
1170
+ readonly sql: string;
1171
+ readonly params?: readonly unknown[];
1172
+ /**
1173
+ * The bytes pgwasm reads for this statement's `/dev/blob` — how a LOCAL-ONLY table an app owns is
1174
+ * BULK-LOADED with `COPY` instead of one INSERT per row. It rides ONLY with a `COPY … FROM '/dev/blob'`
1175
+ * statement; any other statement ignores it. Build the pair with {@link buildCopyFromBlobStatement},
1176
+ * which renders the statement and serializes the rows from ONE column list (and with the same COPY TEXT
1177
+ * serializer the sync applier uses), so the SQL and the bytes cannot disagree.
1178
+ *
1179
+ * **On a worker-attached client the buffer is TRANSFERRED, not copied.** It is listed on the RPC's
1180
+ * `postMessage` transfer list, so it is DETACHED (`byteLength === 0`) the moment the call dispatches:
1181
+ * the caller must not read, reuse or re-send it afterwards — serialize a fresh chunk for each call.
1182
+ * Zero-copy is the point: a 1000-row chunk crosses the bridge without a structured-clone copy.
1183
+ *
1184
+ * Typed over a real `ArrayBuffer` (not the default `ArrayBufferLike`) because that IS the contract: a
1185
+ * `SharedArrayBuffer`-backed view can neither be transferred nor read as a `Blob` part.
1186
+ */
1187
+ readonly blob?: Uint8Array<ArrayBuffer>;
1092
1188
  }
1093
- /** The `{ query, exec }` duck `@electric-sql/pglite-repl` drives, backed by a client's inspection surface. */
1189
+ /** The `{ query, exec }` duck `@pgxsinkit/pgwasm-repl` drives, backed by a client's inspection surface. */
1094
1190
  export interface ReplInspectionSurface {
1095
1191
  query: (sql: string, params?: unknown[], options?: RawQueryOptions) => Promise<Results>;
1096
1192
  exec: (sql: string, options?: RawQueryOptions) => Promise<Results[]>;
1097
1193
  }
1098
1194
  /**
1099
1195
  * Shape a {@link SyncClient}'s inspection surface (`rawQuery`/`rawExec`) as the `{ query, exec }` duck
1100
- * `@electric-sql/pglite-repl` needs. Identical on the in-process and worker-attached client — on the latter
1101
- * each statement routes through the worker bridge, so the REPL works even though `client.pglite` is
1102
- * unavailable. Cast the result at the `<Repl pg={...}>` prop (the REPL types the prop as a full `PGlite`).
1196
+ * `@pgxsinkit/pgwasm-repl` needs. Identical on the in-process and worker-attached client — on the latter
1197
+ * each statement routes through the worker bridge, so the REPL works even though `client.pgwasm` is
1198
+ * unavailable. Cast the result at the `<Repl pg={...}>` prop (the REPL types the prop as a full `pgwasm`).
1103
1199
  * The surface is registry-independent, so it accepts any client's `rawQuery`/`rawExec` pair.
1104
1200
  */
1105
1201
  export declare function replAdapter(client: Pick<SyncClient<SyncTableRegistry>, "rawQuery" | "rawExec">): ReplInspectionSurface;
@@ -1110,12 +1206,12 @@ export declare function createSyncClient<const TRegistry extends SyncTableRegist
1110
1206
  * identically. The `client` argument is the executor Drizzle runs against:
1111
1207
  * - Omit it (the default `{}` stub) for a BUILD-ONLY instance — Drizzle only compiles to SQL (`.toSQL()`)
1112
1208
  * and the stub is never invoked; used where execution happens elsewhere (e.g. the live-rows bridge).
1113
- * - Pass a `ClientPGlite`-shaped BRIDGE executor (its `query` routes to the worker's `guardedQuery` RPC) so
1209
+ * - Pass a `PgwasmClient`-shaped BRIDGE executor (its `query` routes to the worker's `guardedQuery` RPC) so
1114
1210
  * that awaiting a builder executes through the bridge and Drizzle's own result mapping (relational/nested
1115
1211
  * queries included) runs on the tab — the one-shot read path `attachSyncClient` wires (ADR-0032 decision 4).
1116
1212
  */
1117
- export declare function buildRegistryReadHandles<TRegistry extends SyncTableRegistry>(registry: TRegistry, client?: ClientPGlite): {
1118
- drizzle: PgliteDatabase<RegistryRelations<TRegistry>>;
1213
+ export declare function buildRegistryReadHandles<TRegistry extends SyncTableRegistry>(registry: TRegistry, client?: PgwasmClient): {
1214
+ drizzle: PgwasmDatabase<RegistryRelations<TRegistry>>;
1119
1215
  views: RegistryViews<TRegistry>;
1120
1216
  /**
1121
1217
  * A drizzle-database FACTORY over this registry's schema (ADR-0032 decision 4): `(client) => db`, reusing
@@ -1123,6 +1219,6 @@ export declare function buildRegistryReadHandles<TRegistry extends SyncTableRegi
1123
1219
  * without recomputing them. `attachSyncClient` uses it to give each `queryRaw`/`queryRawRow` its OWN
1124
1220
  * bridge executor carrying that call's `use` — a scoped db, never a shared mutable stash (no read races).
1125
1221
  */
1126
- drizzleFor: (client: ClientPGlite) => PgliteDatabase<RegistryRelations<TRegistry>>;
1222
+ drizzleFor: (client: PgwasmClient) => PgwasmDatabase<RegistryRelations<TRegistry>>;
1127
1223
  };
1128
1224
  //# sourceMappingURL=index.d.ts.map