@pgxsinkit/client 0.2.7 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LICENSE-APACHE-2.0 +202 -0
- package/NOTICE +81 -0
- package/README.md +11 -3
- package/dist/boot-report.d.ts +11 -8
- package/dist/boot-report.d.ts.map +1 -1
- package/dist/circuits/envelope-to-change.d.ts +39 -0
- package/dist/circuits/envelope-to-change.d.ts.map +1 -0
- package/dist/circuits/group-sync.d.ts +123 -0
- package/dist/circuits/group-sync.d.ts.map +1 -0
- package/dist/circuits/shape-group.d.ts +77 -0
- package/dist/circuits/shape-group.d.ts.map +1 -0
- package/dist/circuits/stream-inbox.d.ts +126 -0
- package/dist/circuits/stream-inbox.d.ts.map +1 -0
- package/dist/circuits/stream-source.d.ts +96 -0
- package/dist/circuits/stream-source.d.ts.map +1 -0
- package/dist/circuits/subscription-client.d.ts +143 -0
- package/dist/circuits/subscription-client.d.ts.map +1 -0
- package/dist/circuits/sync-engine.d.ts +131 -0
- package/dist/circuits/sync-engine.d.ts.map +1 -0
- package/dist/debug.d.ts +0 -10
- package/dist/debug.d.ts.map +1 -1
- package/dist/event-lane.d.ts +32 -1
- package/dist/event-lane.d.ts.map +1 -1
- package/dist/export-data.d.ts +3 -3
- package/dist/export-dump.d.ts +9 -9
- package/dist/export-dump.d.ts.map +1 -1
- package/dist/export-store.d.ts +13 -13
- package/dist/index.d.ts +237 -113
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7037 -6665
- package/dist/index.js.map +46 -43
- package/dist/local-store.d.ts +1 -1
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-tables.d.ts +59 -1
- package/dist/local-tables.d.ts.map +1 -1
- package/dist/mutation.d.ts +2 -2
- package/dist/mutation.d.ts.map +1 -1
- package/dist/mutations-api.d.ts.map +1 -1
- package/dist/opfs-effects.d.ts +30 -2
- package/dist/opfs-effects.d.ts.map +1 -1
- package/dist/schema.d.ts +12 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/store-boot.d.ts +30 -2
- package/dist/store-boot.d.ts.map +1 -1
- package/dist/store-build.d.ts +19 -0
- package/dist/store-build.d.ts.map +1 -0
- package/dist/store-engine.d.ts +22 -0
- package/dist/store-engine.d.ts.map +1 -0
- package/dist/store-meta.d.ts +29 -3
- package/dist/store-meta.d.ts.map +1 -1
- package/dist/store-ownership-lock.d.ts +33 -0
- package/dist/store-ownership-lock.d.ts.map +1 -0
- package/dist/store-path.d.ts +40 -28
- package/dist/store-path.d.ts.map +1 -1
- package/dist/sync/apply.d.ts +17 -25
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/copy.d.ts +84 -8
- package/dist/sync/copy.d.ts.map +1 -1
- package/dist/sync/drizzle-executor.d.ts +4 -4
- package/dist/sync/drizzle-executor.d.ts.map +1 -1
- package/dist/sync/fold.d.ts +40 -0
- package/dist/sync/fold.d.ts.map +1 -0
- package/dist/sync/metadata-tables.d.ts +25 -1
- package/dist/sync/metadata-tables.d.ts.map +1 -1
- package/dist/sync/subscription-state.d.ts +26 -7
- package/dist/sync/subscription-state.d.ts.map +1 -1
- package/dist/sync/types.d.ts +9 -129
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +4 -3
- package/dist/testing.js.map +4 -4
- package/dist/worker/attach-sync-client.d.ts +27 -14
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +52 -19
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/engine-control.d.ts +53 -0
- package/dist/worker/engine-control.d.ts.map +1 -1
- package/dist/worker/live-query-manager.d.ts +3 -3
- package/dist/worker/live-query-manager.d.ts.map +1 -1
- package/dist/worker/live-query-params-guard.d.ts +5 -5
- package/dist/worker/protocol.d.ts +26 -7
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +11 -9
- package/skills/core/SKILL.md +145 -63
- package/skills/operating/SKILL.md +221 -221
- package/skills/operating/references/postgres-builds.md +48 -0
- package/src/boot-report.ts +13 -12
- package/src/circuits/envelope-to-change.ts +211 -0
- package/src/circuits/group-sync.ts +1047 -0
- package/src/circuits/shape-group.ts +158 -0
- package/src/circuits/stream-inbox.ts +225 -0
- package/src/circuits/stream-source.ts +191 -0
- package/src/circuits/subscription-client.ts +353 -0
- package/src/circuits/sync-engine.ts +643 -0
- package/src/debug.ts +1 -85
- package/src/event-lane.ts +132 -14
- package/src/export-data.ts +4 -4
- package/src/export-dump.ts +24 -28
- package/src/export-store.ts +17 -17
- package/src/index.ts +797 -544
- package/src/lazy-guard.ts +1 -1
- package/src/live-rows-sql.ts +1 -1
- package/src/local-store.ts +2 -2
- package/src/local-tables.ts +76 -5
- package/src/mutation.ts +9 -8
- package/src/mutations-api.ts +2 -2
- package/src/opfs-effects.ts +74 -10
- package/src/schema.ts +126 -29
- package/src/store-boot.ts +71 -7
- package/src/store-build.ts +37 -0
- package/src/store-engine.ts +94 -0
- package/src/store-lifecycle.ts +1 -1
- package/src/store-meta.ts +155 -4
- package/src/store-ownership-lock.ts +109 -0
- package/src/store-path.ts +56 -40
- package/src/sync/apply.ts +104 -156
- package/src/sync/copy.ts +116 -21
- package/src/sync/drizzle-executor.ts +13 -14
- package/src/sync/fold.ts +94 -0
- package/src/sync/metadata-tables.ts +43 -2
- package/src/sync/subscription-state.ts +28 -10
- package/src/sync/types.ts +13 -141
- package/src/testing.ts +4 -4
- package/src/worker/attach-sync-client.ts +150 -57
- package/src/worker/define-sync-worker.ts +325 -87
- package/src/worker/engine-control.ts +89 -0
- package/src/worker/engine-router.ts +1 -1
- package/src/worker/live-query-fingerprint.ts +4 -4
- package/src/worker/live-query-manager.ts +12 -12
- package/src/worker/live-query-params-guard.ts +10 -10
- package/src/worker/protocol.ts +38 -7
- package/dist/read-stream-stall.d.ts +0 -54
- package/dist/read-stream-stall.d.ts.map +0 -1
- package/dist/shape-sync.d.ts +0 -207
- package/dist/shape-sync.d.ts.map +0 -1
- package/dist/sync/index.d.ts +0 -32
- package/dist/sync/index.d.ts.map +0 -1
- package/dist/sync/nudge.d.ts +0 -49
- package/dist/sync/nudge.d.ts.map +0 -1
- package/dist/sync/shape-inbox.d.ts +0 -215
- package/dist/sync/shape-inbox.d.ts.map +0 -1
- package/dist/sync/tags.d.ts +0 -142
- package/dist/sync/tags.d.ts.map +0 -1
- package/dist/sync-auth.d.ts +0 -53
- package/dist/sync-auth.d.ts.map +0 -1
- package/src/read-stream-stall.ts +0 -102
- package/src/shape-sync.ts +0 -533
- package/src/sync/index.ts +0 -1124
- package/src/sync/nudge.ts +0 -110
- package/src/sync/shape-inbox.ts +0 -566
- package/src/sync/tags.ts +0 -390
- package/src/sync-auth.ts +0 -117
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
5
|
-
import type {
|
|
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";
|
|
@@ -17,7 +17,6 @@ import { generateLocalSchemaSql } from "./schema";
|
|
|
17
17
|
import { type ResolvedStorageBackend, type StoreBootResolution } from "./store-boot";
|
|
18
18
|
import { type StoreBootVerdict, type StoreMetaDeps } from "./store-meta";
|
|
19
19
|
import { type StorePathInput } from "./store-path";
|
|
20
|
-
import { type SyncEngine } from "./sync";
|
|
21
20
|
import { type LiveQueryDiagnostics } from "./worker/live-query-manager";
|
|
22
21
|
export { generateLocalSchemaSql };
|
|
23
22
|
export { wrapLiveQueryForMaterialization } from "./live-rows-sql";
|
|
@@ -28,12 +27,14 @@ export { type DataExportReport, deriveStoreId, type DiagnosticDumpReport, type E
|
|
|
28
27
|
export { createLifecycleSlot, LifecycleBusyError, type LifecycleSlot } from "./lifecycle-slot";
|
|
29
28
|
export { classifyEventBatchFailure, computeEventBackoffMs, createEventFlushDriver, createEventLaneRuntime, DEFAULT_EVENT_BACKOFF_BASE_MS, DEFAULT_EVENT_BACKOFF_CEILING_MS, DEFAULT_EVENT_BATCH_SIZE, DEFAULT_EVENT_FLUSH_INTERVAL_MS, deriveBatchEventUrl, type EventAppendResult, type EventBackoffOptions, type EventFlushDriver, type EventFlushDriverOptions, type EventFlushGate, type EventLaneBackoffTransition, type EventLaneDb, type EventLaneOptions, type EventLaneReport, type EventLaneRuntime, type EventLaneVerdict, EventPayloadInvalidError, EventPayloadTooLargeError, type EventStreamFlushOptions, EventStreamsNotRegisteredError, type OutboxStatus, parseRetryAfterMs, resolveBatchEventUrl, UnknownEventStreamError, } from "./event-lane";
|
|
30
29
|
export { destroyStoreArtifacts, type ElectedEngineWorker, ElectedEngineUnconstructibleError, ProvisionExpiredError, quiesceStoreWorker, StoreDestroyRefusedError, type StoreDestructionRetryOptions, type StoreWorkerQuiesceOptions, type StoreWorkerQuiesceOutcome, wrapEngineWorker, } from "./worker/attach-sync-client";
|
|
31
|
-
export { ENGINE_RELOCATED_CODE, EngineRelocatedError, type EngineRelocatedOutcome, type ExecutionLimitConfig, ExecutionLimitMismatchError, } from "./worker/engine-control";
|
|
30
|
+
export { ENGINE_RELOCATED_CODE, EngineRelocatedError, type EngineRelocatedOutcome, type ExecutionLimitConfig, ExecutionLimitMismatchError, PROVISION_STALLED_CODE, ProvisionStalledError, provisionStalledFromWire, type ProvisionStalledWire, } from "./worker/engine-control";
|
|
32
31
|
export { createOpfsEffects, type OpfsEffects, type OpfsEffectsDeps } from "./opfs-effects";
|
|
32
|
+
export { STORE_OWNERSHIP_WAIT_MS, StoreOwnershipWaitError } from "./store-ownership-lock";
|
|
33
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";
|
|
34
35
|
export { InvalidStorePathError, NonPersistentStoreError, resolveStoreDataDir, RestoreTargetExistsError, storeIndexedDbDatabaseName, storeTargetExists, } from "./store-path";
|
|
35
36
|
export { type ConvergenceClient, type ConvergenceDriver, type ConvergenceDriverOptions, type ConvergenceTrigger, createBrowserConvergenceTrigger, createConvergenceDriver, createIntervalConvergenceTrigger, } from "./convergence";
|
|
36
|
-
export {
|
|
37
|
+
export { setSyncDebugSink, syncDebug, timeAsync } from "./debug";
|
|
37
38
|
export { type AttachedSyncClient, attachSyncClient, type AttachSyncClientOptions, provisionSyncWorker, } from "./worker/attach-sync-client";
|
|
38
39
|
export { defineSyncWorker, type DefineSyncWorkerOptions, type SyncWorkerHost } from "./worker/define-sync-worker";
|
|
39
40
|
export { computeLiveDiff, type LiveDiffState, LiveRowsMaterializer, rowKey, seedLiveDiffState, } from "./worker/live-diff";
|
|
@@ -42,6 +43,21 @@ export { createWorkerTokenCache, type WorkerTokenCache } from "./worker/token-ca
|
|
|
42
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";
|
|
43
44
|
export { assertLazyRefsActivated, buildLazyGuardIndex, findReferencedLazyKeysInSql, findReferencedSyncedKeysInSql, type LazyGuardIndex, LazyRelationNotActivatedError, } from "./lazy-guard";
|
|
44
45
|
export { OUTBOX_SEQUENCE, OUTBOX_TABLE } from "./schema";
|
|
46
|
+
export { buildCopyFromBlobStatement, type CopyFromBlobStatementOptions, generateCopyData, serializeCopyValue, } from "./sync/copy";
|
|
47
|
+
export { createTokenRecovery, readShapeStream, STREAM_START } from "./circuits/stream-source";
|
|
48
|
+
export type { ShapeStreamSubscription, StreamBatch, StreamSourceOptions } from "./circuits/stream-source";
|
|
49
|
+
export { createShapeGroup } from "./circuits/shape-group";
|
|
50
|
+
export type { GroupShapeSpec, ShapeGroup, ShapeGroupBatch, ShapeGroupOptions } from "./circuits/shape-group";
|
|
51
|
+
export { envelopeToChange, primaryKeyFromStreamKey } from "./circuits/envelope-to-change";
|
|
52
|
+
export type { ChangeLike } from "./circuits/envelope-to-change";
|
|
53
|
+
export { StreamInbox } from "./circuits/stream-inbox";
|
|
54
|
+
export type { BufferedBatch } from "./circuits/stream-inbox";
|
|
55
|
+
export { createBarrierReader, openSubscriptionSession } from "./circuits/subscription-client";
|
|
56
|
+
export type { GrantedStream, RefusedStream, ShapeSubscriptionRequest, SubscriptionClientOptions, SubscriptionSession, } from "./circuits/subscription-client";
|
|
57
|
+
export { startCircuitsSync } from "./circuits/group-sync";
|
|
58
|
+
export type { CircuitsGroupSyncOptions, CircuitsGroupSyncResult, CircuitsTableSyncResult } from "./circuits/group-sync";
|
|
59
|
+
export { syncCircuitsShapes } from "./circuits/sync-engine";
|
|
60
|
+
export type { CircuitsShapeSpec, CircuitsSyncHandle, CircuitsSyncOptions, ConvergenceBarrier, } from "./circuits/sync-engine";
|
|
45
61
|
export { type AllMutationsView, getAllMutationsView, getJournalTable, getLocalMetaTable, getOutboxTable, getOverlayTable, getReadModelView, getSyncedLocalTable, getSyncStateView, type JournalTable, type LocalMetaTable, type OutboxTable, type OverlayTable, type ReadModelView, type SyncStateView, } from "./local-tables";
|
|
46
62
|
export { createMutationsApi, type MutationListOptions, type MutationListSubscription, type MutationsApi, type MutationsApiDeps, type MutationSummaryDetail, type MutationSummarySubscription, } from "./mutations-api";
|
|
47
63
|
export type { LocalStoreVersionEvent };
|
|
@@ -64,36 +80,34 @@ export declare class WriteNotReadyError extends Error {
|
|
|
64
80
|
export declare class ClientDisposedError extends Error {
|
|
65
81
|
constructor();
|
|
66
82
|
}
|
|
67
|
-
export type
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* The pre-warmed PGlite boot assets (the WASM modules + filesystem bundle), consumed by
|
|
72
|
-
* {@link createClientPGlite} / {@link CreateSyncClientOptions.pgliteBootAssets}. The host fetches +
|
|
73
|
-
* compiles these on an earlier screen and hands the promise in, so `PGlite.create` skips its own lazy
|
|
74
|
-
* asset load — see the field's JSDoc for the accelerator geometry.
|
|
75
|
-
*/
|
|
76
|
-
export interface PgliteBootAssets {
|
|
77
|
-
pgliteWasmModule?: WebAssembly.Module;
|
|
78
|
-
initdbWasmModule?: WebAssembly.Module;
|
|
79
|
-
fsBundle?: Blob;
|
|
80
|
-
}
|
|
81
|
-
/** Options for {@link createClientPGlite}. */
|
|
82
|
-
export interface CreateClientPGliteOptions {
|
|
83
|
+
export type PgwasmClient = PgwasmWithLive;
|
|
84
|
+
/** Options for {@link createPgwasmClient}. */
|
|
85
|
+
export interface CreatePgwasmClientOptions {
|
|
83
86
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* asset load
|
|
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.
|
|
87
90
|
*/
|
|
88
|
-
|
|
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;
|
|
99
|
+
/**
|
|
100
|
+
* @internal The site the {@link declaredBuild} check reports; defaults to `"createPgwasmClient"`.
|
|
101
|
+
*/
|
|
102
|
+
buildCheckSite?: StoreBuildCheckSite;
|
|
89
103
|
/**
|
|
90
104
|
* @internal Toolkit-internal durability carrier (ADR-0047), NOT a public per-open knob. Durability is
|
|
91
105
|
* registry-declared: {@link createSyncClient} resolves `storage.durability ?? "relaxed"` off its registry
|
|
92
106
|
* and threads the resolved mode in here — the ONE resolution point — for every mint it funnels through this
|
|
93
107
|
* factory (its own boot, the worker provision/spare mint, the pre-expose idb drain read). Defaults to
|
|
94
|
-
* `"relaxed"` when absent and is stamped onto the `boot
|
|
108
|
+
* `"relaxed"` when absent and is stamped onto the `boot pgwasm.create` rail (ADR-0047 D3). On idb, relaxed
|
|
95
109
|
* returns before the whole-datadir snapshot flush and schedules it asynchronously; strict keeps that
|
|
96
|
-
* synchronous snapshot (~100–200ms per statement). On OPFS-repacked the package factory keeps
|
|
110
|
+
* synchronous snapshot (~100–200ms per statement). On OPFS-repacked the package factory keeps pgwasm on its
|
|
97
111
|
* awaited host path: relaxed routine sync asserts health without an ordinary physical flush, while strict
|
|
98
112
|
* flushes arena data before metadata. Initialization, activation, and open-state close retain strict
|
|
99
113
|
* ordering in both OPFS modes.
|
|
@@ -107,10 +121,10 @@ export interface CreateClientPGliteOptions {
|
|
|
107
121
|
backendOverride?: "memory";
|
|
108
122
|
/**
|
|
109
123
|
* A store-backup tarball to seed the new store from (ADR-0035 decision 6, restore) — a `File`/`Blob` as
|
|
110
|
-
* produced by {@link SyncClient.exportStore}. Passed straight to
|
|
124
|
+
* produced by {@link SyncClient.exportStore}. Passed straight to pgwasm's `loadDataDir`, so the created
|
|
111
125
|
* store boots ON the backup's datadir. Restore is a CREATION-path feature: the caller (`createSyncClient`)
|
|
112
126
|
* has already proven the target does not yet exist ({@link storeTargetExists}); this option carries no
|
|
113
|
-
* freshness check of its own. A corrupt/foreign tarball surfaces as a
|
|
127
|
+
* freshness check of its own. A corrupt/foreign tarball surfaces as a pgwasm boot failure here.
|
|
114
128
|
*/
|
|
115
129
|
restoreFrom?: File | Blob;
|
|
116
130
|
/**
|
|
@@ -123,12 +137,16 @@ export interface CreateClientPGliteOptions {
|
|
|
123
137
|
/**
|
|
124
138
|
* @internal ADR-0049 step 10a: the opfs-repacked factory + store-directory seam, injectable so Bun unit
|
|
125
139
|
* tests exercise the `opfs://` branch WITHOUT loading real WASM/OPFS. In production both default to the real
|
|
126
|
-
* implementations (`
|
|
140
|
+
* implementations (`createOpfsPgwasm` via a lazy `import()`, and the OPFS effects' store directory
|
|
127
141
|
* handle). Never consumer-facing.
|
|
128
142
|
*/
|
|
129
|
-
|
|
130
|
-
/** The
|
|
131
|
-
|
|
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
|
+
}>>;
|
|
132
150
|
/** The create-if-absent store directory handle for the factory; defaults to the real OPFS effects. */
|
|
133
151
|
getStoreDirectoryHandle?: () => Promise<unknown>;
|
|
134
152
|
/** Backoff between bounded open retries (ms); defaults to a small real delay. Tests pass `0`. */
|
|
@@ -136,27 +154,27 @@ export interface CreateClientPGliteOptions {
|
|
|
136
154
|
};
|
|
137
155
|
}
|
|
138
156
|
/**
|
|
139
|
-
* Create the raw local
|
|
140
|
-
* {@link createSyncClient} makes internally (the `
|
|
141
|
-
* consumption, and the `boot
|
|
157
|
+
* Create the raw local pgwasm store the sync client runs on — the SAME `pgwasm.create` call
|
|
158
|
+
* {@link createSyncClient} makes internally (the `live` extension, pre-warmed boot-asset
|
|
159
|
+
* consumption, and the `boot pgwasm.create` rail stamp), extracted so exactly one implementation exists
|
|
142
160
|
* and a host can create the store EAGERLY on an earlier screen. Hand the returned (still-pending)
|
|
143
|
-
* instance to {@link CreateSyncClientOptions.
|
|
161
|
+
* instance to {@link CreateSyncClientOptions.precreatedPgwasm}: the client then owns schema exec, prepare
|
|
144
162
|
* hooks, journal recovery, and registry reconciliation, exactly as its own `storePath` path does.
|
|
145
163
|
*
|
|
146
164
|
* Takes a plain store path (ADR-0036), never a storage URL — the backend is DERIVED from the engine home
|
|
147
165
|
* (capability-selected opfs-repacked with IndexedDB fallback in a browser, or the filesystem on Bun/Node);
|
|
148
166
|
* a scheme-bearing path throws {@link InvalidStorePathError}.
|
|
149
|
-
* Also accepts the testing helper's output (`
|
|
167
|
+
* Also accepts the testing helper's output (`createPgwasmClient(memoryStoreForTests("x"))`) so a test can
|
|
150
168
|
* mint a memory store without naming a backend.
|
|
151
169
|
*
|
|
152
170
|
* The instance is deliberately **schemaless** — the registry-derived local schema is role/registry
|
|
153
171
|
* dependent, so it is applied post-create by `createSyncClient`. The eager create buys only the expensive
|
|
154
172
|
* initdb (+ persistent-store open), which is the dominant cold-boot cost once the WASM is pre-warmed.
|
|
155
173
|
*
|
|
156
|
-
* `
|
|
157
|
-
*
|
|
174
|
+
* `build` is the Postgres build (see {@link CreateSyncClientOptions.build}); a `createCBuild({ assets })` whose
|
|
175
|
+
* warm rejects loads its own assets — never a failure.
|
|
158
176
|
*/
|
|
159
|
-
export declare function
|
|
177
|
+
export declare function createPgwasmClient(store: StorePathInput, options?: CreatePgwasmClientOptions): Promise<PgwasmClient>;
|
|
160
178
|
/**
|
|
161
179
|
* @internal Injectable seams for the FRESH/RESTORE commitment boot wiring (step 11c). Real defaults in
|
|
162
180
|
* production (`globalThis.indexedDB` / `navigator.storage`); unit tests inject fakes so the phase machine and
|
|
@@ -205,11 +223,11 @@ export interface FreshBootResolution {
|
|
|
205
223
|
export declare function resolveFreshBoot(storePath: string, hasOpfsSyncAccess: boolean, backendOverride: "memory" | undefined, seams?: FreshCommitmentSeams): Promise<FreshBootResolution>;
|
|
206
224
|
export declare function runFreshCommitmentBarrier(storePath: string, strictSyncReturns: () => Promise<void>, seams?: FreshCommitmentSeams): Promise<void>;
|
|
207
225
|
/**
|
|
208
|
-
* @internal The ADOPTED-boot commitment gate. A boot that ADOPTS an instance (`
|
|
209
|
-
* `
|
|
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
|
|
210
228
|
* {@link resolveFreshBoot} never runs and nothing flags the barrier. Left alone, an adopted OPFS store therefore
|
|
211
229
|
* stays UNCOMMITTED for its whole life: no sentinel, and a record still at `opfs-candidate` (or absent, when the
|
|
212
|
-
* adopted instance was built outside the mint seam — a BYO `
|
|
230
|
+
* adopted instance was built outside the mint seam — a BYO `pgwasmInstance`). That state is INDISTINGUISHABLE
|
|
213
231
|
* from a torn candidate, so the next client-owned boot classifies `delete-candidate-and-rebuild` and DESTROYS a
|
|
214
232
|
* populated store — offline, with nothing to rebuild from. An adopted opfs boot therefore owes the SAME barrier
|
|
215
233
|
* ({@link runFreshCommitmentBarrier}) a fresh one does, pre-expose (invariant 3).
|
|
@@ -254,7 +272,23 @@ export declare function resolveAdoptedCommitmentBarrier(storePath: string, seams
|
|
|
254
272
|
export declare function fallbackVirginCandidateToIdb(storePath: string, openError: unknown, seams?: FreshCommitmentSeams): Promise<string>;
|
|
255
273
|
export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
256
274
|
registry: TRegistry;
|
|
257
|
-
|
|
275
|
+
/**
|
|
276
|
+
* The pgxsinkit control plane: where a client subscribes, re-mints its stream token, and reads the
|
|
277
|
+
* engine convergence barrier (ADR-0055). Required, with {@link streamBaseUrl}.
|
|
278
|
+
*
|
|
279
|
+
* The client does not CONSTRUCT stream URLs, it **asks** and is told. Which shapes a subject may
|
|
280
|
+
* read — and, on the shared tier, which scopes each expands to — is not something the client can
|
|
281
|
+
* express at all, which is what removes shape selection from the wire.
|
|
282
|
+
*/
|
|
283
|
+
controlPlaneUrl: string;
|
|
284
|
+
/**
|
|
285
|
+
* The edge that serves durable-streams reads. Granted stream paths are appended to it.
|
|
286
|
+
*
|
|
287
|
+
* Separate from {@link controlPlaneUrl} because they are different deployments: the control plane
|
|
288
|
+
* is a small authenticated origin, and this is the CDN-frontable read surface the shared tier
|
|
289
|
+
* exists to make cacheable.
|
|
290
|
+
*/
|
|
291
|
+
streamBaseUrl: string;
|
|
258
292
|
batchWriteUrl: string;
|
|
259
293
|
getAuthToken?: () => Promise<string | undefined>;
|
|
260
294
|
/**
|
|
@@ -266,27 +300,28 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
266
300
|
requestHeaders?: Record<string, string>;
|
|
267
301
|
/**
|
|
268
302
|
* Extra static headers sent on the **write** path only (the mutation-flush POST), merged over
|
|
269
|
-
* {@link requestHeaders} (`{...requestHeaders, ...writeRequestHeaders}`).
|
|
270
|
-
* see these. The seam exists because the two ingress points have opposite geometry:
|
|
271
|
-
* function is DB-bound, so pinning it to the database's region (e.g. an `x-region` header)
|
|
272
|
-
* chatty function→DB protocol on a ~1ms loop; the read
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* (e.g. `apikey`) in
|
|
303
|
+
* {@link requestHeaders} (`{...requestHeaders, ...writeRequestHeaders}`). Control-plane and stream
|
|
304
|
+
* requests never see these. The seam exists because the two ingress points have opposite geometry:
|
|
305
|
+
* the write function is DB-bound, so pinning it to the database's region (e.g. an `x-region` header)
|
|
306
|
+
* keeps its chatty function→DB protocol on a ~1ms loop; the read path terminates on the stream edge
|
|
307
|
+
* in front of durable-streams, so pinning reads to the database's region rather than the caller's
|
|
308
|
+
* pays an intercontinental round trip on every catch-up hop and every long-poll cycle. Put
|
|
309
|
+
* region/DB-affinity headers here; keep gateway credentials the reads also need (e.g. `apikey`) in
|
|
310
|
+
* the shared {@link requestHeaders}.
|
|
276
311
|
*/
|
|
277
312
|
writeRequestHeaders?: Record<string, string>;
|
|
278
313
|
syncEnabled?: boolean;
|
|
279
314
|
/**
|
|
280
315
|
* The read-silence window (ms) after which a runtime claiming `ready` drops to `degraded` (reason
|
|
281
|
-
* "stream"). A pulled cable HANGS the live long-poll — nothing fails
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
316
|
+
* "stream"). A pulled cable HANGS the live long-poll — nothing fails, nothing delivers — so without this
|
|
317
|
+
* a session that once reached `ready` would report "up to date" for as long as the outage lasts. A
|
|
318
|
+
* healthy stream is never silent: durable-streams answers every long-poll hold that times out with a
|
|
319
|
+
* bare up-to-date response, so the default of 45s spans several cycles. Self-recovering: the next delivered batch
|
|
285
320
|
* returns `ready`. Status honesty only — nothing is retired or torn down.
|
|
286
321
|
*/
|
|
287
322
|
readSilenceMs?: number;
|
|
288
323
|
/**
|
|
289
|
-
* The local store's name (ADR-0036) — a PLAIN path/name, never a
|
|
324
|
+
* The local store's name (ADR-0036) — a PLAIN path/name, never a pgwasm storage URL. The storage backend
|
|
290
325
|
* is DERIVED from the engine home (capability-selected opfs-repacked with IndexedDB fallback in a browser,
|
|
291
326
|
* or the filesystem on Bun/Node); a
|
|
292
327
|
* scheme-bearing string (anything containing `://`) is rejected with {@link InvalidStorePathError}
|
|
@@ -308,68 +343,73 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
308
343
|
* ADR-0049 D1: the placement probe's OPFS-sync-access grant, threaded from the SharedWorker's engine home
|
|
309
344
|
* (`defineSyncWorker`'s SW-direct bootstrap) into this boot so the client-owned create opens the OPFS-repacked
|
|
310
345
|
* backend. Absent/false is the honest IDBFS home — the declared `backend: "idbfs"` mode or a capability-absence
|
|
311
|
-
* fallback (a main thread can never hold handles either). Forwarded verbatim to {@link
|
|
346
|
+
* fallback (a main thread can never hold handles either). Forwarded verbatim to {@link createPgwasmClient}, which
|
|
312
347
|
* resolves the actual dataDir from it.
|
|
313
348
|
*/
|
|
314
349
|
hasOpfsSyncAccess?: boolean;
|
|
315
350
|
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
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`.
|
|
324
364
|
*/
|
|
325
|
-
|
|
365
|
+
build?: PostgresBuild;
|
|
326
366
|
resetSubscriptionKeys?: string[];
|
|
327
|
-
prepareLocalDbBeforeSchema?: (pglite:
|
|
328
|
-
prepareLocalDbAfterSchema?: (pglite:
|
|
367
|
+
prepareLocalDbBeforeSchema?: (pglite: PgwasmClient) => Promise<void>;
|
|
368
|
+
prepareLocalDbAfterSchema?: (pglite: PgwasmClient) => Promise<void>;
|
|
329
369
|
onStatusChange?: (status: SyncRuntimeStatus) => void;
|
|
330
370
|
onTableInitialSync?: (tableKey: string) => void;
|
|
331
371
|
/**
|
|
332
|
-
* A fully-provisioned
|
|
372
|
+
* A fully-provisioned pgwasm instance the CALLER owns end-to-end. The client runs NONE of its
|
|
333
373
|
* post-create boot steps against it — no schema exec, prepare hooks, or registry reconciliation
|
|
334
374
|
* (journal recovery still runs, as it does on every path). Use it only when the caller has already
|
|
335
375
|
* applied the registry schema itself. Contrast the three PGlite-provenance seams:
|
|
336
376
|
* - {@link storePath} (default) — the client creates the store AND runs every post-create step.
|
|
337
|
-
* - {@link
|
|
377
|
+
* - {@link precreatedPgwasm} — the caller creates the raw store (via {@link createPgwasmClient}), but
|
|
338
378
|
* the client still runs every post-create step (schema, prepare hooks, and reconciliation), exactly as
|
|
339
379
|
* `storePath` does.
|
|
340
|
-
* - `
|
|
380
|
+
* - `pgwasmInstance` — the caller creates AND provisions the store; the client runs none of them.
|
|
341
381
|
*
|
|
342
382
|
* A caller-owned instance is REFUSED with {@link NonPersistentStoreError} if it is provably
|
|
343
|
-
* non-persistent (a `new
|
|
383
|
+
* non-persistent (a `new pgwasm()` default, or an in-memory store) — pgxsinkit's durability semantics
|
|
344
384
|
* assume a persisted store (ADR-0036). Acknowledge a deliberate test store by spreading
|
|
345
385
|
* `testStoreAcknowledgment()` from `@pgxsinkit/client/testing`.
|
|
346
386
|
*
|
|
347
|
-
* Mutually exclusive with {@link
|
|
387
|
+
* Mutually exclusive with {@link precreatedPgwasm} (supplying both throws).
|
|
348
388
|
*/
|
|
349
|
-
|
|
389
|
+
pgwasmInstance?: PgwasmClient;
|
|
350
390
|
/**
|
|
351
|
-
* A raw
|
|
391
|
+
* A raw pgwasm instance the caller created EAGERLY (via {@link createPgwasmClient}) — typically on an
|
|
352
392
|
* earlier screen, to hide the ~1.9s cold `initdb`/IDBFS open behind user think-time — but for which the
|
|
353
393
|
* client still owns EVERYTHING else: schema exec, prepare hooks, journal recovery, and registry
|
|
354
394
|
* reconciliation all run exactly as on the {@link storePath} path. This is the difference from
|
|
355
|
-
* {@link
|
|
395
|
+
* {@link pgwasmInstance} (which skips schema, prepare hooks, and reconciliation because the caller owns
|
|
356
396
|
* them); see that
|
|
357
397
|
* option's JSDoc for the three-way distinction.
|
|
358
398
|
*
|
|
359
399
|
* The promise form lets the still-pending eager create be handed straight in. Precedence/validation:
|
|
360
|
-
* - Supplying both this and {@link
|
|
400
|
+
* - Supplying both this and {@link pgwasmInstance} throws — they claim different ownership.
|
|
361
401
|
* - {@link storePath} is used ONLY as the fallback store name if this promise REJECTS: a failed eager
|
|
362
402
|
* create is caught, logged on the boot rail, and the normal `storePath` create path runs instead (also
|
|
363
|
-
* consuming {@link
|
|
403
|
+
* consuming {@link build} if provided). The pattern is a pure accelerator, never a boot
|
|
364
404
|
* dependency.
|
|
365
405
|
* - A successfully-adopted instance is subject to the same {@link NonPersistentStoreError} refusal as
|
|
366
|
-
* {@link
|
|
406
|
+
* {@link pgwasmInstance} (checked after resolution, so the refusal propagates rather than being
|
|
367
407
|
* swallowed by the reject-fallback).
|
|
368
408
|
*/
|
|
369
|
-
|
|
409
|
+
precreatedPgwasm?: Promise<PgwasmClient>;
|
|
370
410
|
/**
|
|
371
411
|
* Restore the store from a **store backup** (ADR-0035 decision 6) — a `File`/`Blob` tarball as produced by
|
|
372
|
-
* {@link SyncClient.exportStore}. The client creates its store with the backup handed to
|
|
412
|
+
* {@link SyncClient.exportStore}. The client creates its store with the backup handed to pgwasm's
|
|
373
413
|
* `loadDataDir`, so it boots ON the backup's datadir (synced cache + Overlay + Mutation journal, all the
|
|
374
414
|
* bytes that travelled inside it). Three restore-only rules apply, none of them optional:
|
|
375
415
|
*
|
|
@@ -388,7 +428,7 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
388
428
|
* ledger, so replay is unsafe on last-write-wins tables). Release (`retryFailed`) or discard
|
|
389
429
|
* (`discardQuarantined`) them explicitly. When this pass quarantines nothing, the restore comes online (above).
|
|
390
430
|
*
|
|
391
|
-
* Mutually exclusive with {@link
|
|
431
|
+
* Mutually exclusive with {@link pgwasmInstance} AND {@link precreatedPgwasm} — restore owns the store's
|
|
392
432
|
* creation (`loadDataDir` is a create-time seed), so a caller-supplied instance conflicts (supplying either
|
|
393
433
|
* with `restoreFrom` throws).
|
|
394
434
|
*/
|
|
@@ -396,7 +436,7 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
396
436
|
/**
|
|
397
437
|
* PROVABLY-fresh store hint (ADR-0032 S4 / backlog-0003): the caller guarantees this store is brand-new
|
|
398
438
|
* and schemaless — no prior schema, no synced rows, no persisted subscription state. When set (and sync
|
|
399
|
-
* is enabled, and the client owns schema exec — i.e. not the {@link
|
|
439
|
+
* is enabled, and the client owns schema exec — i.e. not the {@link pgwasmInstance} path), the shape
|
|
400
440
|
* catch-up is started BEFORE the local boot phases (schema exec, journal recovery, and registry
|
|
401
441
|
* reconciliation) and buffered in memory, with commits gated until those phases finish — so the network
|
|
402
442
|
* catch-up overlaps them instead of running strictly after. On a far-from-database caller this collapses
|
|
@@ -457,9 +497,10 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
457
497
|
batchEventUrl?: string;
|
|
458
498
|
/**
|
|
459
499
|
* The Event lane's client-level flush policy (ADR-0053): batch caps, the fallback interval, backoff
|
|
460
|
-
* tuning, and per-Event-stream overrides. NEVER on the registry —
|
|
461
|
-
* deployment tuning, and a batch-size tweak must not surface as a
|
|
462
|
-
* additionally clamped by the contracts-level request-shape limits the
|
|
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.
|
|
463
504
|
*/
|
|
464
505
|
events?: EventLaneOptions;
|
|
465
506
|
/**
|
|
@@ -499,8 +540,8 @@ export interface CreateSyncClientOptions<TRegistry extends SyncTableRegistry> {
|
|
|
499
540
|
/**
|
|
500
541
|
* @internal Provision timing for a boot that ADOPTS a pre-provisioned store (ADR-0034). When the store was
|
|
501
542
|
* minted ahead of boot (a spare's off-thread initdb), the provisioner stamps its create cost and ready
|
|
502
|
-
* time here; the boot reports them as {@link BootReport.provision} and sets `phases.
|
|
503
|
-
* A promise because the stamp settles with the spare's `create`. Only honoured on the {@link
|
|
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}
|
|
504
545
|
* adoption path (ignored on a fallback create). `provisionReadyAt` must share this process's monotonic clock.
|
|
505
546
|
*/
|
|
506
547
|
provisionStamp?: Promise<{
|
|
@@ -615,7 +656,7 @@ export interface SubscribeLiveRowsInput {
|
|
|
615
656
|
/**
|
|
616
657
|
* The unique output aliases to render the query's columns under so it is SAFE TO MATERIALISE, in the
|
|
617
658
|
* compiled SQL's column order (one per output column). Drizzle emits no output aliases, so a JOIN whose
|
|
618
|
-
* tables share a column name compiles to duplicate output names — which
|
|
659
|
+
* tables share a column name compiles to duplicate output names — which pgwasm's `live` extension
|
|
619
660
|
* refuses to materialise (`column "title" specified more than once`) and which silently collapse
|
|
620
661
|
* same-named columns even in a plain query. When supplied, the seam wraps the query so every output
|
|
621
662
|
* column gets its alias and rows come back KEYED BY THESE ALIASES; the consumer's row-mapper must read
|
|
@@ -680,14 +721,14 @@ export interface PreparedQueryResult<TTable extends string = string> {
|
|
|
680
721
|
lazyTables: readonly TTable[];
|
|
681
722
|
}
|
|
682
723
|
export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
683
|
-
drizzle:
|
|
684
|
-
|
|
724
|
+
drizzle: PgwasmDatabase<RegistryRelations<TRegistry>>;
|
|
725
|
+
pgwasm: PgwasmClient;
|
|
685
726
|
views: RegistryViews<TRegistry>;
|
|
686
727
|
tables: {
|
|
687
728
|
[TKey in SyncTableName<TRegistry>]: SyncClientTableHandle<TRegistry, TKey>;
|
|
688
729
|
};
|
|
689
730
|
/**
|
|
690
|
-
* Local-read readiness (ADR-0041): resolves once
|
|
731
|
+
* Local-read readiness (ADR-0041): resolves once pgwasm is open, the durable schema is ready, registry
|
|
691
732
|
* reconciliation has completed, and the drizzle read
|
|
692
733
|
* facade is built — so cached rows are queryable. Resolving this stage requires NO write runtime, NO sync
|
|
693
734
|
* start, and NO network I/O, so an offline boot resolves it promptly. Under the ADR-0041 Option B contract
|
|
@@ -835,7 +876,8 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
|
835
876
|
* The store's owed-state diagnostics: the mutation journal's per-status counts, plus — when this client has
|
|
836
877
|
* an Event lane — the Outbox's drain signal (ADR-0053 decision 8: the Event lane's durable state takes a
|
|
837
878
|
* position on every lifecycle surface). `outbox` is the boolean signal rather than a count, for the reason
|
|
838
|
-
* {@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.
|
|
839
881
|
*/
|
|
840
882
|
diagnostics: (table?: SyncTableName<TRegistry>) => Promise<{
|
|
841
883
|
mutation: MutationDiagnostics;
|
|
@@ -856,17 +898,45 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
|
856
898
|
* issues stays local and will NOT converge. For app data reads prefer the live-rows hooks /
|
|
857
899
|
* {@link subscribeLiveRows} (or the guarded {@link query} family); reach for this only to look at the
|
|
858
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.
|
|
859
906
|
*/
|
|
860
907
|
rawQuery: (sql: string, params?: unknown[], options?: RawQueryOptions) => Promise<Results>;
|
|
861
|
-
/** {@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`. */
|
|
862
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[]>;
|
|
863
933
|
/**
|
|
864
934
|
* @internal The worker host's guarded one-shot read seam (ADR-0032 decision 4): {@link rawQuery} PLUS the
|
|
865
935
|
* ADR-0041 read gate and the ADR-0021 lazy-group guard, sharing one gate+guard core with the in-process
|
|
866
936
|
* `query`/`queryRaw` builder path so the two entry points can never drift on guard semantics.
|
|
867
937
|
* `defineSyncWorker` dispatches the `guardedQuery` RpcOp to this on its owned in-process client; the attach
|
|
868
938
|
* client's Drizzle-over-bridge compiles the SQL on the tab and routes the read here so the guard runs
|
|
869
|
-
* worker-side. Accepts the full
|
|
939
|
+
* worker-side. Accepts the full pgwasm {@link QueryOptions} (the worker re-applies drizzle's identity
|
|
870
940
|
* parsers here — temporal OIDs + numeric[]) plus the raw-fragment `use` list. NOT part of the app-facing
|
|
871
941
|
* read surface — reach for {@link query} / {@link queryRaw} instead; kept `@internal` (above) and excluded
|
|
872
942
|
* from the generated API docs (typedoc excludeInternal).
|
|
@@ -903,8 +973,19 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
|
903
973
|
*/
|
|
904
974
|
ensureSynced: (keys: readonly SyncTableName<TRegistry>[]) => Promise<void>;
|
|
905
975
|
/**
|
|
906
|
-
* Whether a relation's group
|
|
907
|
-
*
|
|
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.
|
|
908
989
|
*/
|
|
909
990
|
isSynced: (key: SyncTableName<TRegistry>) => boolean;
|
|
910
991
|
/**
|
|
@@ -1006,8 +1087,8 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
|
1006
1087
|
*/
|
|
1007
1088
|
liveQueryDiagnostics: () => Promise<LiveQueryDiagnostics[]>;
|
|
1008
1089
|
/**
|
|
1009
|
-
* Take a **store backup** (ADR-0035): a full-fidelity,
|
|
1010
|
-
* store — synced cache, Overlay, and Mutation journal (unflushed writes included) — via
|
|
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
|
|
1011
1092
|
* `dumpDataDir`. Taken LIVE (a `CHECKPOINT` serialised behind engine work, then the dump; no engine
|
|
1012
1093
|
* suspension, no tab disruption), so it never blocks and is the only lossless export an offline device
|
|
1013
1094
|
* with unflushed writes can take. Awaits engine-ready rather than rejecting during boot, then runs under
|
|
@@ -1054,24 +1135,67 @@ export interface SyncClient<TRegistry extends SyncTableRegistry> {
|
|
|
1054
1135
|
}
|
|
1055
1136
|
export type { MutationBatchItem, MutationDetail, MutationDiagnostics, MutationKind, MutationSummary };
|
|
1056
1137
|
/**
|
|
1057
|
-
* The structured-clone-safe subset of
|
|
1138
|
+
* The structured-clone-safe subset of pgwasm's `QueryOptions` the inspection surface carries. Kept
|
|
1058
1139
|
* narrow ON PURPOSE: on a worker-attached client the options object crosses the bridge via
|
|
1059
1140
|
* `postMessage`, so function-valued options (`parsers`, `serializers`, `onNotice`) can never be part
|
|
1060
|
-
* of this contract. `rowMode: "array"` is what `@
|
|
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).
|
|
1061
1146
|
*/
|
|
1062
1147
|
export interface RawQueryOptions {
|
|
1063
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>;
|
|
1064
1188
|
}
|
|
1065
|
-
/** The `{ query, exec }` duck `@
|
|
1189
|
+
/** The `{ query, exec }` duck `@pgxsinkit/pgwasm-repl` drives, backed by a client's inspection surface. */
|
|
1066
1190
|
export interface ReplInspectionSurface {
|
|
1067
1191
|
query: (sql: string, params?: unknown[], options?: RawQueryOptions) => Promise<Results>;
|
|
1068
1192
|
exec: (sql: string, options?: RawQueryOptions) => Promise<Results[]>;
|
|
1069
1193
|
}
|
|
1070
1194
|
/**
|
|
1071
1195
|
* Shape a {@link SyncClient}'s inspection surface (`rawQuery`/`rawExec`) as the `{ query, exec }` duck
|
|
1072
|
-
* `@
|
|
1073
|
-
* each statement routes through the worker bridge, so the REPL works even though `client.
|
|
1074
|
-
* unavailable. Cast the result at the `<Repl pg={...}>` prop (the REPL types the prop as a full `
|
|
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`).
|
|
1075
1199
|
* The surface is registry-independent, so it accepts any client's `rawQuery`/`rawExec` pair.
|
|
1076
1200
|
*/
|
|
1077
1201
|
export declare function replAdapter(client: Pick<SyncClient<SyncTableRegistry>, "rawQuery" | "rawExec">): ReplInspectionSurface;
|
|
@@ -1082,12 +1206,12 @@ export declare function createSyncClient<const TRegistry extends SyncTableRegist
|
|
|
1082
1206
|
* identically. The `client` argument is the executor Drizzle runs against:
|
|
1083
1207
|
* - Omit it (the default `{}` stub) for a BUILD-ONLY instance — Drizzle only compiles to SQL (`.toSQL()`)
|
|
1084
1208
|
* and the stub is never invoked; used where execution happens elsewhere (e.g. the live-rows bridge).
|
|
1085
|
-
* - Pass a `
|
|
1209
|
+
* - Pass a `PgwasmClient`-shaped BRIDGE executor (its `query` routes to the worker's `guardedQuery` RPC) so
|
|
1086
1210
|
* that awaiting a builder executes through the bridge and Drizzle's own result mapping (relational/nested
|
|
1087
1211
|
* queries included) runs on the tab — the one-shot read path `attachSyncClient` wires (ADR-0032 decision 4).
|
|
1088
1212
|
*/
|
|
1089
|
-
export declare function buildRegistryReadHandles<TRegistry extends SyncTableRegistry>(registry: TRegistry, client?:
|
|
1090
|
-
drizzle:
|
|
1213
|
+
export declare function buildRegistryReadHandles<TRegistry extends SyncTableRegistry>(registry: TRegistry, client?: PgwasmClient): {
|
|
1214
|
+
drizzle: PgwasmDatabase<RegistryRelations<TRegistry>>;
|
|
1091
1215
|
views: RegistryViews<TRegistry>;
|
|
1092
1216
|
/**
|
|
1093
1217
|
* A drizzle-database FACTORY over this registry's schema (ADR-0032 decision 4): `(client) => db`, reusing
|
|
@@ -1095,6 +1219,6 @@ export declare function buildRegistryReadHandles<TRegistry extends SyncTableRegi
|
|
|
1095
1219
|
* without recomputing them. `attachSyncClient` uses it to give each `queryRaw`/`queryRawRow` its OWN
|
|
1096
1220
|
* bridge executor carrying that call's `use` — a scoped db, never a shared mutable stash (no read races).
|
|
1097
1221
|
*/
|
|
1098
|
-
drizzleFor: (client:
|
|
1222
|
+
drizzleFor: (client: PgwasmClient) => PgwasmDatabase<RegistryRelations<TRegistry>>;
|
|
1099
1223
|
};
|
|
1100
1224
|
//# sourceMappingURL=index.d.ts.map
|