@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.
- package/LICENSE +21 -0
- package/LICENSE-APACHE-2.0 +202 -0
- package/NOTICE +81 -0
- package/README.md +10 -3
- package/dist/boot-report.d.ts +8 -8
- package/dist/circuits/envelope-to-change.d.ts +9 -5
- package/dist/circuits/envelope-to-change.d.ts.map +1 -1
- package/dist/circuits/group-sync.d.ts +2 -2
- package/dist/circuits/group-sync.d.ts.map +1 -1
- package/dist/circuits/stream-source.d.ts +6 -0
- package/dist/circuits/stream-source.d.ts.map +1 -1
- package/dist/circuits/sync-engine.d.ts +2 -2
- package/dist/circuits/sync-engine.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 +10 -10
- package/dist/export-dump.d.ts.map +1 -1
- package/dist/export-store.d.ts +13 -13
- package/dist/index.d.ts +196 -100
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1044 -487
- package/dist/index.js.map +39 -36
- package/dist/local-store.d.ts +1 -1
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-tables.d.ts +58 -0
- 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 +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 +43 -31
- package/dist/store-path.d.ts.map +1 -1
- package/dist/sync/apply.d.ts +5 -5
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/copy.d.ts +82 -6
- 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/subscription-state.d.ts +5 -5
- package/dist/sync/subscription-state.d.ts.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +2 -1
- package/dist/testing.js.map +4 -4
- package/dist/worker/attach-sync-client.d.ts +24 -13
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +35 -18
- package/dist/worker/define-sync-worker.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/live-query-params-guard.d.ts.map +1 -1
- package/dist/worker/protocol.d.ts +26 -7
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +11 -8
- package/skills/core/SKILL.md +80 -15
- package/skills/operating/SKILL.md +129 -129
- package/skills/operating/references/postgres-builds.md +48 -0
- package/src/boot-report.ts +12 -12
- package/src/circuits/envelope-to-change.ts +121 -12
- package/src/circuits/group-sync.ts +2 -2
- package/src/circuits/stream-source.ts +35 -9
- package/src/circuits/sync-engine.ts +6 -4
- package/src/event-lane.ts +132 -14
- package/src/export-data.ts +4 -4
- package/src/export-dump.ts +31 -36
- package/src/export-store.ts +20 -20
- package/src/index.ts +576 -340
- package/src/live-rows-sql.ts +1 -1
- package/src/local-store.ts +2 -2
- package/src/local-tables.ts +70 -6
- package/src/mutation.ts +9 -8
- package/src/mutations-api.ts +4 -4
- package/src/opfs-effects.ts +74 -10
- package/src/schema.ts +124 -18
- 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 +59 -43
- package/src/sync/apply.ts +32 -46
- package/src/sync/copy.ts +108 -13
- package/src/sync/drizzle-executor.ts +18 -19
- package/src/sync/metadata-tables.ts +1 -1
- package/src/sync/subscription-state.ts +7 -7
- package/src/testing.ts +3 -3
- package/src/worker/attach-sync-client.ts +146 -60
- package/src/worker/define-sync-worker.ts +212 -83
- 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 +16 -15
- package/src/worker/protocol.ts +38 -7
package/dist/export-dump.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PGlite } from "@electric-sql/pglite";
|
|
2
1
|
import type { MutationDiagnostics } from "@pgxsinkit/contracts";
|
|
2
|
+
import { type Pgwasm } from "@pgxsinkit/pgwasm";
|
|
3
3
|
import { type DiagnosticDumpReport } from "./export-store";
|
|
4
|
-
import type {
|
|
4
|
+
import type { PgwasmClient } from "./index";
|
|
5
5
|
/** Options for {@link SyncClient.exportDiagnostics}. */
|
|
6
6
|
export interface DiagnosticExportOptions {
|
|
7
7
|
/**
|
|
@@ -21,12 +21,12 @@ export interface DiagnosticExportResult {
|
|
|
21
21
|
/** The dependencies {@link performDiagnosticExport} needs from the owning client — narrow, so it is unit-testable. */
|
|
22
22
|
export interface DiagnosticExportDeps {
|
|
23
23
|
/** The live store to checkpoint and dump (the clone source; the live engine is never suspended). */
|
|
24
|
-
|
|
24
|
+
pgwasm: Pick<PgwasmClient, "exec" | "dumpDataDir">;
|
|
25
25
|
/** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
|
|
26
26
|
readMutationStats: () => Promise<MutationDiagnostics>;
|
|
27
27
|
/**
|
|
28
28
|
* The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default artefact
|
|
29
|
-
* file name. The resolved
|
|
29
|
+
* file name. The resolved pgwasm dataDir URL is deliberately NOT used: it is internal plumbing and must
|
|
30
30
|
* not leak into an artefact name as something to imitate.
|
|
31
31
|
*/
|
|
32
32
|
storePath?: string;
|
|
@@ -41,7 +41,7 @@ export interface CloneDumpPhases {
|
|
|
41
41
|
checkpointStartedAtMs: number;
|
|
42
42
|
/** `CHECKPOINT` wall — flushing dirty buffers before the internal datadir dump the clone consumes. */
|
|
43
43
|
checkpointMs: number;
|
|
44
|
-
/** Offset from `startPerf` when the throwaway clone's `
|
|
44
|
+
/** Offset from `startPerf` when the throwaway clone's `pgwasm.create({ loadDataDir })` began. */
|
|
45
45
|
cloneBootStartedAtMs: number;
|
|
46
46
|
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
47
47
|
cloneBootMs: number;
|
|
@@ -52,7 +52,7 @@ export interface CloneDumpPhases {
|
|
|
52
52
|
}
|
|
53
53
|
/** The raw SQL bytes plus the pipeline phase walls — {@link runThrowawayCloneDump}'s result. */
|
|
54
54
|
export interface CloneDumpResult {
|
|
55
|
-
/** The `pg_dump` output bytes (unwrapped from
|
|
55
|
+
/** The `pg_dump` output bytes (unwrapped from the `File` `pgDump` returns). */
|
|
56
56
|
sqlBytes: Uint8Array<ArrayBuffer>;
|
|
57
57
|
/** The pipeline phase timings, all offset from the caller's `startPerf` anchor. */
|
|
58
58
|
phases: CloneDumpPhases;
|
|
@@ -60,14 +60,14 @@ export interface CloneDumpResult {
|
|
|
60
60
|
/**
|
|
61
61
|
* The throwaway-clone dump core shared by BOTH `pgDump` exports (ADR-0035 addendum): (1) a LIVE datadir dump
|
|
62
62
|
* of the running store (`compression: "none"` — the clone consumes the bytes immediately, so gzip+gunzip is
|
|
63
|
-
* pure waste); (2) a memory-backed THROWAWAY
|
|
63
|
+
* pure waste); (2) a memory-backed THROWAWAY pgwasm booted from it via `loadDataDir` — engine-less, no
|
|
64
64
|
* `live` extension, nothing `pg_dump`'s `DEALLOCATE ALL` can corrupt; (3) `pg_dump` against the throwaway
|
|
65
65
|
* with the caller's `args` (none for a diagnostic dump; the `-t` allowlist + `--no-owner` for a data
|
|
66
66
|
* export); (4) discard the clone in a `finally`. Factored out so `performDiagnosticExport` and
|
|
67
67
|
* `performDataExport` cannot drift on the clone plumbing, the memory-scheme selection, or the timing house
|
|
68
68
|
* style — the ONLY differences between the two dumps are the `pg_dump` args and the artefact assembly.
|
|
69
69
|
*
|
|
70
|
-
* `@
|
|
70
|
+
* `@pgxsinkit/pgwasm-pg-dump` is loaded ONLY via the dynamic `import()` here (ADR-0035 decision 7): its
|
|
71
71
|
* ~700 kB `pg_dump.wasm` (+ ~100 kB JS) stays off boot and off every non-exporting bundle.
|
|
72
72
|
*/
|
|
73
73
|
export interface CloneDumpOptions {
|
|
@@ -79,9 +79,9 @@ export interface CloneDumpOptions {
|
|
|
79
79
|
* triggers `pg_dump -t` would otherwise pull into the artefact (see `buildDataExportCloneCleanupSql`); a
|
|
80
80
|
* diagnostic dump passes none (it wants the store verbatim).
|
|
81
81
|
*/
|
|
82
|
-
prepareClone?: (clone:
|
|
82
|
+
prepareClone?: (clone: Pgwasm) => Promise<void>;
|
|
83
83
|
}
|
|
84
|
-
export declare function runThrowawayCloneDump(
|
|
84
|
+
export declare function runThrowawayCloneDump(pgwasm: Pick<PgwasmClient, "exec" | "dumpDataDir">, startPerf: number, options?: CloneDumpOptions): Promise<CloneDumpResult>;
|
|
85
85
|
/**
|
|
86
86
|
* Run a diagnostic dump (ADR-0035): live datadir dump → memory-backed throwaway clone → `pg_dump` → discard
|
|
87
87
|
* the clone → assemble the report. The caller (`createSyncClient`) awaits engine-ready and enters the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-dump.d.ts","sourceRoot":"","sources":["../src/export-dump.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,
|
|
1
|
+
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,MAAM,WAAW,eAAe;IAC9B,+EAA+E;IAC/E,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAClC,mFAAmF;IACnF,MAAM,EAAE,eAAe,CAAC;CACzB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wGAAwG;IACxG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,CAAC,EAClD,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAuE1B;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,oBAAoB,EAC1B,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,sBAAsB,CAAC,CA+BjC"}
|
package/dist/export-store.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MutationDiagnostics } from "@pgxsinkit/contracts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { PgwasmClient } from "./index";
|
|
3
3
|
/**
|
|
4
4
|
* Monotonic clock (ms) — `performance.now()` where available, else `Date.now()` (mirrors BootReport).
|
|
5
5
|
* Exported so the sibling diagnostic-dump path ({@link file://./export-dump.ts}) times its extra phases
|
|
@@ -9,7 +9,7 @@ export declare const nowMs: () => number;
|
|
|
9
9
|
/** Options for {@link SyncClient.exportStore}. */
|
|
10
10
|
export interface StoreExportOptions {
|
|
11
11
|
/**
|
|
12
|
-
* How to compress the tarball, forwarded to
|
|
12
|
+
* How to compress the tarball, forwarded to pgwasm's `dumpDataDir`. `"auto"` (the default) gzips when a
|
|
13
13
|
* `CompressionStream` is available and falls back to an uncompressed tar otherwise; `"gzip"` forces
|
|
14
14
|
* compression; `"none"` skips it. The report's `compression` records the compression that was actually
|
|
15
15
|
* applied (which, under `"auto"`, is resolved at runtime).
|
|
@@ -44,7 +44,7 @@ export interface ExportReportCommon {
|
|
|
44
44
|
diagnostics: MutationDiagnostics;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* A live **store backup** (ADR-0035): the whole datadir as a
|
|
47
|
+
* A live **store backup** (ADR-0035): the whole datadir as a pgwasm-restorable tarball, journal and overlay
|
|
48
48
|
* included. `checkpoint`/`dump` are the only phases — a store backup is a `CHECKPOINT` + `dumpDataDir`, no
|
|
49
49
|
* clone. Slice-1 shape, kept unchanged (the union is additive).
|
|
50
50
|
*/
|
|
@@ -70,7 +70,7 @@ export interface StoreBackupReport extends ExportReportCommon {
|
|
|
70
70
|
* A **diagnostic dump** (ADR-0035, via the throwaway clone of the addendum): human-readable SQL of
|
|
71
71
|
* EVERYTHING the store holds — synced tables, the `_overlay`/`_mutations` journal, the `pgxsinkit` metadata
|
|
72
72
|
* schema, the read-model views, and the reconcile functions/triggers. It is a live datadir dump (checkpoint
|
|
73
|
-
* + `dumpDataDir`) fed into a memory-backed throwaway
|
|
73
|
+
* + `dumpDataDir`) fed into a memory-backed throwaway pgwasm via `loadDataDir`, against which `pg_dump` runs
|
|
74
74
|
* — so the live engine is never touched (the addendum's whole point). Its phases add the clone boot and the
|
|
75
75
|
* `pg_dump` walls to the shared checkpoint/dump pair.
|
|
76
76
|
*/
|
|
@@ -87,7 +87,7 @@ export interface DiagnosticDumpReport extends ExportReportCommon {
|
|
|
87
87
|
dumpStartedAtMs: number;
|
|
88
88
|
/** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
|
|
89
89
|
dumpMs: number;
|
|
90
|
-
/** Offset from export start when the throwaway clone's `
|
|
90
|
+
/** Offset from export start when the throwaway clone's `pgwasm.create({ loadDataDir })` began. */
|
|
91
91
|
cloneBootStartedAtMs: number;
|
|
92
92
|
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
93
93
|
cloneBootMs: number;
|
|
@@ -135,7 +135,7 @@ export interface DataExportReport extends ExportReportCommon {
|
|
|
135
135
|
dumpStartedAtMs: number;
|
|
136
136
|
/** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
|
|
137
137
|
dumpMs: number;
|
|
138
|
-
/** Offset from export start when the throwaway clone's `
|
|
138
|
+
/** Offset from export start when the throwaway clone's `pgwasm.create({ loadDataDir })` began. */
|
|
139
139
|
cloneBootStartedAtMs: number;
|
|
140
140
|
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
141
141
|
cloneBootMs: number;
|
|
@@ -154,14 +154,14 @@ export interface DataExportReport extends ExportReportCommon {
|
|
|
154
154
|
export type ExportReport = StoreBackupReport | DiagnosticDumpReport | DataExportReport;
|
|
155
155
|
/** The artefact + its report — the resolved value of {@link SyncClient.exportStore}. */
|
|
156
156
|
export interface StoreExportResult {
|
|
157
|
-
/** The store-backup tarball as a named `File`, restorable by
|
|
157
|
+
/** The store-backup tarball as a named `File`, restorable by pgwasm via `loadDataDir`. */
|
|
158
158
|
file: File;
|
|
159
159
|
/** The structured record of the export (ADR-0035). */
|
|
160
160
|
report: StoreBackupReport;
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
163
|
* Reduce a plain store PATH (ADR-0036) to a filesystem-safe token for the backup file name. Takes the
|
|
164
|
-
* path's LAST segment (as
|
|
164
|
+
* path's LAST segment (as pgwasm's own `dumpDataDir` does when it names the inner db), then keeps only
|
|
165
165
|
* `[A-Za-z0-9._-]`. No scheme stripping — the store path is a plain name, never a storage URL. Falls back
|
|
166
166
|
* to a fixed token for an empty path so the name is always well formed.
|
|
167
167
|
*/
|
|
@@ -180,12 +180,12 @@ export declare const compactTimestamp: () => string;
|
|
|
180
180
|
* (the caller's export-start monotonic anchor) so the timings compose into either report.
|
|
181
181
|
*
|
|
182
182
|
* The `CHECKPOINT` is a utility statement — Drizzle has no builder for it, so a raw `exec` is the justified
|
|
183
|
-
* tier-③ form here. Running it via `
|
|
183
|
+
* tier-③ form here. Running it via `pgwasm.exec` serialises it behind any in-flight engine work on pgwasm's
|
|
184
184
|
* single connection, flushing dirty buffers to the datadir the dump then reads — so the tarball reflects
|
|
185
185
|
* committed state, not a torn mid-write datadir.
|
|
186
186
|
*/
|
|
187
|
-
export declare function performDatadirDump(
|
|
188
|
-
dumped: Awaited<ReturnType<
|
|
187
|
+
export declare function performDatadirDump(pgwasm: Pick<PgwasmClient, "exec" | "dumpDataDir">, compression: "auto" | "gzip" | "none", startPerf: number): Promise<{
|
|
188
|
+
dumped: Awaited<ReturnType<PgwasmClient["dumpDataDir"]>>;
|
|
189
189
|
checkpointStartedAtMs: number;
|
|
190
190
|
checkpointMs: number;
|
|
191
191
|
dumpStartedAtMs: number;
|
|
@@ -194,12 +194,12 @@ export declare function performDatadirDump(pglite: Pick<ClientPGlite, "exec" | "
|
|
|
194
194
|
/** The dependencies {@link performStoreExport} needs from the owning client — narrow, so it is unit-testable. */
|
|
195
195
|
export interface StoreExportDeps {
|
|
196
196
|
/** The live store to checkpoint and dump. */
|
|
197
|
-
|
|
197
|
+
pgwasm: Pick<PgwasmClient, "exec" | "dumpDataDir">;
|
|
198
198
|
/** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
|
|
199
199
|
readMutationStats: () => Promise<MutationDiagnostics>;
|
|
200
200
|
/**
|
|
201
201
|
* The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default backup
|
|
202
|
-
* file name (`deriveStoreId`). The resolved
|
|
202
|
+
* file name (`deriveStoreId`). The resolved pgwasm dataDir URL is deliberately NOT used here: it is
|
|
203
203
|
* internal plumbing and must not leak into an artefact name as something to imitate.
|
|
204
204
|
*/
|
|
205
205
|
storePath?: string;
|