@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/src/export-store.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Local store export (ADR-0035). Slice 1 ships the **store backup**: a full-fidelity,
|
|
1
|
+
// Local store export (ADR-0035). Slice 1 ships the **store backup**: a full-fidelity, pgwasm-restorable
|
|
2
2
|
// tarball of the whole local store, taken LIVE (no engine suspension). It is a `CHECKPOINT` — run through
|
|
3
3
|
// the engine's normal query serialisation so it orders behind in-flight engine work — followed by
|
|
4
|
-
//
|
|
4
|
+
// pgwasm's `dumpDataDir`. Because the dump is of the datadir itself, the Mutation journal and Overlay
|
|
5
5
|
// travel INSIDE the artefact: a store backup is the lossless option, the only export an offline device
|
|
6
6
|
// with unflushed writes can take (CONTEXT.md → Store backup).
|
|
7
7
|
//
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import type { MutationDiagnostics } from "@pgxsinkit/contracts";
|
|
14
14
|
|
|
15
|
-
import type {
|
|
15
|
+
import type { PgwasmClient } from "./index";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Monotonic clock (ms) — `performance.now()` where available, else `Date.now()` (mirrors BootReport).
|
|
@@ -24,7 +24,7 @@ export const nowMs = (): number => (typeof performance !== "undefined" ? perform
|
|
|
24
24
|
/** Options for {@link SyncClient.exportStore}. */
|
|
25
25
|
export interface StoreExportOptions {
|
|
26
26
|
/**
|
|
27
|
-
* How to compress the tarball, forwarded to
|
|
27
|
+
* How to compress the tarball, forwarded to pgwasm's `dumpDataDir`. `"auto"` (the default) gzips when a
|
|
28
28
|
* `CompressionStream` is available and falls back to an uncompressed tar otherwise; `"gzip"` forces
|
|
29
29
|
* compression; `"none"` skips it. The report's `compression` records the compression that was actually
|
|
30
30
|
* applied (which, under `"auto"`, is resolved at runtime).
|
|
@@ -61,7 +61,7 @@ export interface ExportReportCommon {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
* A live **store backup** (ADR-0035): the whole datadir as a
|
|
64
|
+
* A live **store backup** (ADR-0035): the whole datadir as a pgwasm-restorable tarball, journal and overlay
|
|
65
65
|
* included. `checkpoint`/`dump` are the only phases — a store backup is a `CHECKPOINT` + `dumpDataDir`, no
|
|
66
66
|
* clone. Slice-1 shape, kept unchanged (the union is additive).
|
|
67
67
|
*/
|
|
@@ -88,7 +88,7 @@ export interface StoreBackupReport extends ExportReportCommon {
|
|
|
88
88
|
* A **diagnostic dump** (ADR-0035, via the throwaway clone of the addendum): human-readable SQL of
|
|
89
89
|
* EVERYTHING the store holds — synced tables, the `_overlay`/`_mutations` journal, the `pgxsinkit` metadata
|
|
90
90
|
* schema, the read-model views, and the reconcile functions/triggers. It is a live datadir dump (checkpoint
|
|
91
|
-
* + `dumpDataDir`) fed into a memory-backed throwaway
|
|
91
|
+
* + `dumpDataDir`) fed into a memory-backed throwaway pgwasm via `loadDataDir`, against which `pg_dump` runs
|
|
92
92
|
* — so the live engine is never touched (the addendum's whole point). Its phases add the clone boot and the
|
|
93
93
|
* `pg_dump` walls to the shared checkpoint/dump pair.
|
|
94
94
|
*/
|
|
@@ -105,7 +105,7 @@ export interface DiagnosticDumpReport extends ExportReportCommon {
|
|
|
105
105
|
dumpStartedAtMs: number;
|
|
106
106
|
/** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
|
|
107
107
|
dumpMs: number;
|
|
108
|
-
/** Offset from export start when the throwaway clone's `
|
|
108
|
+
/** Offset from export start when the throwaway clone's `pgwasm.create({ loadDataDir })` began. */
|
|
109
109
|
cloneBootStartedAtMs: number;
|
|
110
110
|
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
111
111
|
cloneBootMs: number;
|
|
@@ -154,7 +154,7 @@ export interface DataExportReport extends ExportReportCommon {
|
|
|
154
154
|
dumpStartedAtMs: number;
|
|
155
155
|
/** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
|
|
156
156
|
dumpMs: number;
|
|
157
|
-
/** Offset from export start when the throwaway clone's `
|
|
157
|
+
/** Offset from export start when the throwaway clone's `pgwasm.create({ loadDataDir })` began. */
|
|
158
158
|
cloneBootStartedAtMs: number;
|
|
159
159
|
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
160
160
|
cloneBootMs: number;
|
|
@@ -175,7 +175,7 @@ export type ExportReport = StoreBackupReport | DiagnosticDumpReport | DataExport
|
|
|
175
175
|
|
|
176
176
|
/** The artefact + its report — the resolved value of {@link SyncClient.exportStore}. */
|
|
177
177
|
export interface StoreExportResult {
|
|
178
|
-
/** The store-backup tarball as a named `File`, restorable by
|
|
178
|
+
/** The store-backup tarball as a named `File`, restorable by pgwasm via `loadDataDir`. */
|
|
179
179
|
file: File;
|
|
180
180
|
/** The structured record of the export (ADR-0035). */
|
|
181
181
|
report: StoreBackupReport;
|
|
@@ -183,7 +183,7 @@ export interface StoreExportResult {
|
|
|
183
183
|
|
|
184
184
|
/**
|
|
185
185
|
* Reduce a plain store PATH (ADR-0036) to a filesystem-safe token for the backup file name. Takes the
|
|
186
|
-
* path's LAST segment (as
|
|
186
|
+
* path's LAST segment (as pgwasm's own `dumpDataDir` does when it names the inner db), then keeps only
|
|
187
187
|
* `[A-Za-z0-9._-]`. No scheme stripping — the store path is a plain name, never a storage URL. Falls back
|
|
188
188
|
* to a fixed token for an empty path so the name is always well formed.
|
|
189
189
|
*/
|
|
@@ -209,16 +209,16 @@ export const compactTimestamp = (): string => new Date().toISOString().replace(/
|
|
|
209
209
|
* (the caller's export-start monotonic anchor) so the timings compose into either report.
|
|
210
210
|
*
|
|
211
211
|
* The `CHECKPOINT` is a utility statement — Drizzle has no builder for it, so a raw `exec` is the justified
|
|
212
|
-
* tier-③ form here. Running it via `pglite.exec` serialises it behind any in-flight engine work on
|
|
212
|
+
* tier-③ form here. Running it via `pglite.exec` serialises it behind any in-flight engine work on pgwasm's
|
|
213
213
|
* single connection, flushing dirty buffers to the datadir the dump then reads — so the tarball reflects
|
|
214
214
|
* committed state, not a torn mid-write datadir.
|
|
215
215
|
*/
|
|
216
216
|
export async function performDatadirDump(
|
|
217
|
-
pglite: Pick<
|
|
217
|
+
pglite: Pick<PgwasmClient, "exec" | "dumpDataDir">,
|
|
218
218
|
compression: "auto" | "gzip" | "none",
|
|
219
219
|
startPerf: number,
|
|
220
220
|
): Promise<{
|
|
221
|
-
dumped: Awaited<ReturnType<
|
|
221
|
+
dumped: Awaited<ReturnType<PgwasmClient["dumpDataDir"]>>;
|
|
222
222
|
checkpointStartedAtMs: number;
|
|
223
223
|
checkpointMs: number;
|
|
224
224
|
dumpStartedAtMs: number;
|
|
@@ -240,12 +240,12 @@ export async function performDatadirDump(
|
|
|
240
240
|
/** The dependencies {@link performStoreExport} needs from the owning client — narrow, so it is unit-testable. */
|
|
241
241
|
export interface StoreExportDeps {
|
|
242
242
|
/** The live store to checkpoint and dump. */
|
|
243
|
-
pglite: Pick<
|
|
243
|
+
pglite: Pick<PgwasmClient, "exec" | "dumpDataDir">;
|
|
244
244
|
/** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
|
|
245
245
|
readMutationStats: () => Promise<MutationDiagnostics>;
|
|
246
246
|
/**
|
|
247
247
|
* The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default backup
|
|
248
|
-
* file name (`deriveStoreId`). The resolved
|
|
248
|
+
* file name (`deriveStoreId`). The resolved pgwasm dataDir URL is deliberately NOT used here: it is
|
|
249
249
|
* internal plumbing and must not leak into an artefact name as something to imitate.
|
|
250
250
|
*/
|
|
251
251
|
storePath?: string;
|
|
@@ -273,7 +273,7 @@ export async function performStoreExport(
|
|
|
273
273
|
startPerf,
|
|
274
274
|
);
|
|
275
275
|
|
|
276
|
-
//
|
|
276
|
+
// pgwasm names its dump `<db>.tar.gz` (type `application/x-gzip`) when it compressed, `<db>.tar`
|
|
277
277
|
// (`application/x-tar`) otherwise — so the RESULT, not the requested option, tells us what `"auto"`
|
|
278
278
|
// resolved to. Detect from whichever of name/type the runtime populated (its `File` is a polyfill in
|
|
279
279
|
// non-browser hosts, so trust both).
|
|
@@ -284,7 +284,7 @@ export async function performStoreExport(
|
|
|
284
284
|
const mimeType = gzipped ? "application/x-gzip" : "application/x-tar";
|
|
285
285
|
const storeId = deriveStoreId(deps.storePath);
|
|
286
286
|
const fileName = options.fileName ?? `${storeId}-${compactTimestamp()}${extension}`;
|
|
287
|
-
// Build the artefact `File` from the raw bytes, NOT by re-wrapping `dumped`:
|
|
287
|
+
// Build the artefact `File` from the raw bytes, NOT by re-wrapping `dumped`: pgwasm's dump is a File
|
|
288
288
|
// polyfill in non-browser hosts, and `new File([polyfillFile], name)` keeps the polyfill's own name
|
|
289
289
|
// rather than the one we pass. Extracting the bytes first guarantees the store-scoped name sticks.
|
|
290
290
|
const bytes = new Uint8Array(await dumped.arrayBuffer());
|