@pgxsinkit/client 0.1.36 → 0.1.41
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/dist/boot-report.d.ts +134 -0
- package/dist/boot-report.d.ts.map +1 -0
- package/dist/export-data.d.ts +100 -0
- package/dist/export-data.d.ts.map +1 -0
- package/dist/export-dump.d.ts +92 -0
- package/dist/export-dump.d.ts.map +1 -0
- package/dist/export-store.d.ts +214 -0
- package/dist/export-store.d.ts.map +1 -0
- package/dist/index.d.ts +206 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1373 -8308
- package/dist/index.js.map +25 -131
- package/dist/lazy-guard.d.ts +4 -3
- package/dist/lazy-guard.d.ts.map +1 -1
- package/dist/lifecycle-slot.d.ts +31 -0
- package/dist/lifecycle-slot.d.ts.map +1 -0
- package/dist/live-rows-sql.d.ts +21 -0
- package/dist/live-rows-sql.d.ts.map +1 -0
- package/dist/mutation-state.d.ts +9 -2
- package/dist/mutation-state.d.ts.map +1 -1
- package/dist/mutation.d.ts +12 -0
- package/dist/mutation.d.ts.map +1 -1
- package/dist/schema.d.ts +33 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/shape-sync.d.ts +10 -0
- package/dist/shape-sync.d.ts.map +1 -1
- package/dist/store-path.d.ts +132 -0
- package/dist/store-path.d.ts.map +1 -0
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/types.d.ts +8 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/testing.d.ts +27 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +17 -0
- package/dist/testing.js.map +11 -0
- package/dist/worker/attach-sync-client.d.ts +23 -2
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +5 -4
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/protocol.d.ts +89 -8
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +9 -4
- package/skills/core/SKILL.md +14 -1
- package/skills/operating/SKILL.md +75 -15
- package/src/boot-report.ts +287 -0
- package/src/export-data.ts +300 -0
- package/src/export-dump.ts +239 -0
- package/src/export-store.ts +309 -0
- package/src/index.ts +623 -82
- package/src/lazy-guard.ts +23 -9
- package/src/lifecycle-slot.ts +66 -0
- package/src/live-rows-sql.ts +45 -0
- package/src/mutation-state.ts +11 -2
- package/src/mutation.ts +42 -0
- package/src/schema.ts +120 -1
- package/src/shape-sync.ts +21 -0
- package/src/store-path.ts +249 -0
- package/src/sync/index.ts +11 -0
- package/src/sync/types.ts +9 -0
- package/src/testing.ts +53 -0
- package/src/worker/attach-sync-client.ts +101 -6
- package/src/worker/define-sync-worker.ts +196 -30
- package/src/worker/protocol.ts +110 -10
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A structured, versioned record of one client boot (ADR-0034). `reportVersion` is a contract number:
|
|
3
|
+
* additive fields keep it, a breaking reshape bumps it. All durations are milliseconds; all `*AtMs` are
|
|
4
|
+
* offsets from boot start (the `startedAt` epoch anchor is the only wall-clock value).
|
|
5
|
+
*/
|
|
6
|
+
export interface BootReport {
|
|
7
|
+
reportVersion: 1;
|
|
8
|
+
/** How the engine booted: the in-process client (bun/Node/fallback) or inside `defineSyncWorker`. */
|
|
9
|
+
mode: "in-process" | "worker";
|
|
10
|
+
/** Whether the caller proved the store a schemaless spare (the ADR-0032 S4 fresh-store hint). */
|
|
11
|
+
freshStore: boolean;
|
|
12
|
+
/** Whether the ADR-0032 S4 fetch/schema overlap was active for this boot. */
|
|
13
|
+
overlapPrefetch: boolean;
|
|
14
|
+
/** The registry fingerprint the store is provisioned under — the same value store-version reconcile stamps. */
|
|
15
|
+
registryFingerprint: string;
|
|
16
|
+
/** Epoch anchor (`Date.now()`) at boot start; every other duration/offset is monotonic relative to it. */
|
|
17
|
+
startedAt: number;
|
|
18
|
+
/** Boot start → `onInitialSync` (all eager groups caught up). */
|
|
19
|
+
totalMs: number;
|
|
20
|
+
/**
|
|
21
|
+
* Present only when the store was pre-provisioned (a spare's initdb ran off-thread before this boot
|
|
22
|
+
* adopted it); `null` otherwise. When present, `phases.pgliteCreateMs` is `null` — the create cost is
|
|
23
|
+
* reported here instead.
|
|
24
|
+
*/
|
|
25
|
+
provision: {
|
|
26
|
+
/** The spare's PGlite create (initdb) cost, paid at provision time. */
|
|
27
|
+
initdbMs: number;
|
|
28
|
+
/** How long the provisioned store sat ready before this boot adopted it. */
|
|
29
|
+
provisionedMsBeforeBoot: number;
|
|
30
|
+
} | null;
|
|
31
|
+
phases: {
|
|
32
|
+
/** PGlite create cost, or `null` when the store was adopted from a spare (see {@link BootReport.provision}). */
|
|
33
|
+
pgliteCreateMs: number | null;
|
|
34
|
+
schemaExecMs: number;
|
|
35
|
+
journalRecoveryMs: number;
|
|
36
|
+
storeVersionReconcileMs: number;
|
|
37
|
+
/**
|
|
38
|
+
* `startConfiguredSync`: stream/group construction wall. On an overlap boot (ADR-0032 S4,
|
|
39
|
+
* {@link BootReport.overlapPrefetch}) the early-started segment runs concurrently with schema/journal/
|
|
40
|
+
* reconcile, so this includes that shared wall. Structurally 0 when the boot is ready inside the
|
|
41
|
+
* sync-start call itself (zero eager groups / instant catch-up) — finalize runs before the phase closes.
|
|
42
|
+
*/
|
|
43
|
+
syncStartMs: number;
|
|
44
|
+
/** Sync-start done → last eager boot group ready. */
|
|
45
|
+
catchupMs: number;
|
|
46
|
+
/**
|
|
47
|
+
* Cumulative time in configured prepare hooks (`prepareLocalDbBeforeSchema` + `prepareLocalDb`), present
|
|
48
|
+
* only when at least one hook is configured. Not part of the required v1 shape (ADR-0034).
|
|
49
|
+
*/
|
|
50
|
+
prepareMs?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Per consistency GROUP, for the eager + promoted boot groups only (a lazily-activated-later group never
|
|
54
|
+
* appears — nor mutates a finalized report). Groups run concurrently, so `fetchMs`/`applyMs` are per-group
|
|
55
|
+
* wall SEGMENTS, not a partition of `totalMs`.
|
|
56
|
+
*/
|
|
57
|
+
groups: Array<{
|
|
58
|
+
groupKey: string;
|
|
59
|
+
/** Number of member tables (shapes) in the group. */
|
|
60
|
+
tables: number;
|
|
61
|
+
/** Offset from boot start when the group's streams started. */
|
|
62
|
+
startedAtMs: number;
|
|
63
|
+
/** Offset from boot start when the group reached its initial sync. */
|
|
64
|
+
readyAtMs: number;
|
|
65
|
+
/** Number of batch deliveries the group's stream chain received during boot catch-up. */
|
|
66
|
+
requests: number;
|
|
67
|
+
/** Number of change rows ingested during boot catch-up. */
|
|
68
|
+
rows: number;
|
|
69
|
+
/**
|
|
70
|
+
* Settle→next-delivery wall within this group's chain. On the single-threaded WASM host this absorbs
|
|
71
|
+
* OTHER groups' apply transactions and main-thread work between deliveries — read it as "time this
|
|
72
|
+
* group spent not applying", an upper bound on its network wait, not pure network cost.
|
|
73
|
+
*/
|
|
74
|
+
fetchMs: number;
|
|
75
|
+
/**
|
|
76
|
+
* Wall around this group's batch commits into PGlite. Includes waiting behind another group's
|
|
77
|
+
* transaction on the shared connection (single writer), so concurrent groups' `applyMs` can overlap.
|
|
78
|
+
*/
|
|
79
|
+
applyMs: number;
|
|
80
|
+
}>;
|
|
81
|
+
}
|
|
82
|
+
/** The phase durations the builder captures by key; `catchupMs` is derived, not a captured phase. */
|
|
83
|
+
type PhaseKey = "schemaExec" | "journalRecovery" | "storeVersionReconcile" | "syncStart";
|
|
84
|
+
/**
|
|
85
|
+
* The per-group accumulator the engine stamps as a boot group's stream chain delivers and applies (ADR-0034).
|
|
86
|
+
* One per consistency group (one `syncShapesToTables` call). Frozen at the group's ready edge so later live
|
|
87
|
+
* traffic never mutates a finalized report.
|
|
88
|
+
*/
|
|
89
|
+
export interface GroupBootStamp {
|
|
90
|
+
/** A batch was delivered to the group's subscribe callback (one response). `changeCount` = its change rows. */
|
|
91
|
+
onBatchDelivered: (changeCount: number) => void;
|
|
92
|
+
/** A commit transaction applied `ms` of work into PGlite for this group. */
|
|
93
|
+
onApply: (ms: number) => void;
|
|
94
|
+
/** The group reached its initial sync — stamp `readyAtMs` and freeze accumulation. */
|
|
95
|
+
markReady: () => void;
|
|
96
|
+
}
|
|
97
|
+
/** The seam `startConfiguredSync` uses to open a boot group's accumulator (implemented by the builder). */
|
|
98
|
+
export interface BootStampCollector {
|
|
99
|
+
beginGroup: (groupKey: string, tables: number) => GroupBootStamp;
|
|
100
|
+
}
|
|
101
|
+
/** Builds a {@link BootReport} across a boot and finalizes it exactly once. Owned by `createSyncClient`. */
|
|
102
|
+
export interface BootReportBuilder extends BootStampCollector {
|
|
103
|
+
/** The monotonic anchor (`performance.now()` at boot start) every offset is relative to. */
|
|
104
|
+
readonly bootStartPerf: number;
|
|
105
|
+
/**
|
|
106
|
+
* Time `fn`, always measuring (unlike `timeAsync`, which only measures when the rail is on) and capturing
|
|
107
|
+
* the duration into the report, while emitting the SAME rail lines `timeAsync` would. `key` is `null` for
|
|
108
|
+
* a prepare hook (folded into the optional `prepareMs`).
|
|
109
|
+
*/
|
|
110
|
+
phase: <T>(key: PhaseKey | "prepare", event: string, fn: () => Promise<T>, data?: Record<string, unknown>) => Promise<T>;
|
|
111
|
+
setPgliteCreateMs: (ms: number | null) => void;
|
|
112
|
+
setProvision: (provision: BootReport["provision"]) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Record `phases.syncStartMs` directly — for the ADR-0032 S4 overlap path, where sync construction is
|
|
115
|
+
* kicked off before schema exec (not wrapped in {@link BootReportBuilder.phase}) and has no rail line.
|
|
116
|
+
*/
|
|
117
|
+
setSyncStartMs: (ms: number) => void;
|
|
118
|
+
/** Capture the offset at which sync construction completed — the base for `catchupMs`. */
|
|
119
|
+
markSyncStartDone: () => void;
|
|
120
|
+
/** Build + store the report once (idempotent). Returns the report, or the already-built one on a re-call. */
|
|
121
|
+
finalize: () => BootReport;
|
|
122
|
+
/** The finalized report, or `null` before the first boot completes / after an early stop. */
|
|
123
|
+
report: () => BootReport | null;
|
|
124
|
+
}
|
|
125
|
+
/** Inputs known at boot start — the flags and identity the report carries verbatim. */
|
|
126
|
+
export interface BootReportInit {
|
|
127
|
+
mode: BootReport["mode"];
|
|
128
|
+
freshStore: boolean;
|
|
129
|
+
overlapPrefetch: boolean;
|
|
130
|
+
registryFingerprint: string;
|
|
131
|
+
}
|
|
132
|
+
export declare function createBootReportBuilder(init: BootReportInit): BootReportBuilder;
|
|
133
|
+
export {};
|
|
134
|
+
//# sourceMappingURL=boot-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boot-report.d.ts","sourceRoot":"","sources":["../src/boot-report.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,CAAC,CAAC;IACjB,qGAAqG;IACrG,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC9B,iGAAiG;IACjG,UAAU,EAAE,OAAO,CAAC;IACpB,6EAA6E;IAC7E,eAAe,EAAE,OAAO,CAAC;IACzB,+GAA+G;IAC/G,mBAAmB,EAAE,MAAM,CAAC;IAC5B,0GAA0G;IAC1G,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,EAAE;QACT,uEAAuE;QACvE,QAAQ,EAAE,MAAM,CAAC;QACjB,4EAA4E;QAC5E,uBAAuB,EAAE,MAAM,CAAC;KACjC,GAAG,IAAI,CAAC;IACT,MAAM,EAAE;QACN,gHAAgH;QAChH,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9B,YAAY,EAAE,MAAM,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,uBAAuB,EAAE,MAAM,CAAC;QAChC;;;;;WAKG;QACH,WAAW,EAAE,MAAM,CAAC;QACpB,qDAAqD;QACrD,SAAS,EAAE,MAAM,CAAC;QAClB;;;WAGG;QACH,SAAS,CAAC,EAAE,M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AO,CAAC,KAC3B,OAAO,CAAC,CAAC,CAAC,CAAC;IAChB,iBAAiB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,YAAY,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IAC3D;;;OAGG;IACH,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,0FAA0F;IAC1F,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,6GAA6G;IAC7G,QAAQ,EAAE,MAAM,UAAU,CAAC;IAC3B,6FAA6F;IAC7F,MAAM,EAAE,MAAM,UAAU,GAAG,IAAI,CAAC;CACjC;AAED,uFAAuF;AACvF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,cAAc,GAAG,iBAAiB,CAyE/E"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { MutationDiagnostics } from "@pgxsinkit/contracts";
|
|
2
|
+
import { type DataExportReport } from "./export-store";
|
|
3
|
+
import type { ClientPGlite } from "./index";
|
|
4
|
+
/** The default drain budget: actively flush + await the convergence barrier for up to 15s before failing. */
|
|
5
|
+
export declare const DEFAULT_DRAIN_TIMEOUT_MS = 15000;
|
|
6
|
+
/** The drain guard's tuning: the wait budget for reaching a fully-drained journal. */
|
|
7
|
+
export interface DrainJournalOptions {
|
|
8
|
+
/** Milliseconds to flush + await convergence before throwing {@link DataExportDrainError}. */
|
|
9
|
+
timeoutMs: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `exportData`'s drain policy: the default `{ timeoutMs }` guard, or `false` — the explicit escape hatch
|
|
13
|
+
* that skips the drain and exports the SYNCED state as-is (unflushed local writes silently absent). A plain
|
|
14
|
+
* JSON shape, so it survives structured clone across the worker bridge unchanged.
|
|
15
|
+
*/
|
|
16
|
+
export type DrainJournalOption = DrainJournalOptions | false;
|
|
17
|
+
/** Options for {@link SyncClient.exportData}. Plain JSON — structured-clone-safe across the worker bridge. */
|
|
18
|
+
export interface DataExportOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Override the generated artefact file name. When omitted, the name is `<storeId>-<timestamp>-data.sql`,
|
|
21
|
+
* where `storeId` is a filesystem-safe derivation of the store path (see `deriveStoreId`).
|
|
22
|
+
*/
|
|
23
|
+
fileName?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The drain guard (ADR-0035 decision 3). Default `{ timeoutMs: 15_000 }`: fail fast on non-drainable
|
|
26
|
+
* states, else flush + await convergence up to the budget. `false` is the escape hatch — export synced
|
|
27
|
+
* state as-is, skipping the drain entirely.
|
|
28
|
+
*/
|
|
29
|
+
drainJournal?: DrainJournalOption;
|
|
30
|
+
}
|
|
31
|
+
/** The SQL artefact + its report — the resolved value of {@link SyncClient.exportData}. */
|
|
32
|
+
export interface DataExportResult {
|
|
33
|
+
/** The portable SQL as a named `File` (`application/sql`), loadable into a vanilla Postgres. */
|
|
34
|
+
file: File;
|
|
35
|
+
/** The structured record of the export (ADR-0035). */
|
|
36
|
+
report: DataExportReport;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Thrown when `exportData`'s strict drain cannot produce a drained journal (ADR-0035 decision 3). Carries
|
|
40
|
+
* the `MutationDiagnostics` snapshot at the moment of failure so the caller sees exactly what blocked the
|
|
41
|
+
* export, and a `reason` distinguishing the two failure modes:
|
|
42
|
+
*
|
|
43
|
+
* - `"non-drainable-state"` — `failed`/`quarantined`/`conflicted` rows are present (either pre-existing, so
|
|
44
|
+
* the failure is immediate with no waiting, or a mid-drain `flush()` failure that moved rows to `failed`);
|
|
45
|
+
* these terminal states never drain on their own, so waiting is pointless.
|
|
46
|
+
* - `"timeout"` — drainable rows (`pending`/`sending`/`acked`) did not reach fully-drained within the
|
|
47
|
+
* budget; most commonly `acked` writes whose synced echo never arrived (an offline device, a stalled
|
|
48
|
+
* read path).
|
|
49
|
+
*
|
|
50
|
+
* A distinct type — not a bare `Error` — so a caller can `instanceof`-branch a drain failure from a genuine
|
|
51
|
+
* export failure, inspect the diagnostics, and choose the escape hatch (`drainJournal: false`) or the
|
|
52
|
+
* lossless store backup instead.
|
|
53
|
+
*/
|
|
54
|
+
export declare class DataExportDrainError extends Error {
|
|
55
|
+
/** Which drain failure occurred (see the class doc). */
|
|
56
|
+
readonly reason: "non-drainable-state" | "timeout";
|
|
57
|
+
/** The mutation diagnostics at the moment the drain gave up — the evidence of what was unflushed. */
|
|
58
|
+
readonly diagnostics: MutationDiagnostics;
|
|
59
|
+
constructor(reason: "non-drainable-state" | "timeout", diagnostics: MutationDiagnostics);
|
|
60
|
+
}
|
|
61
|
+
/** The dependencies {@link performDataExport} needs from the owning client — narrow, so it is unit-testable. */
|
|
62
|
+
export interface DataExportDeps {
|
|
63
|
+
/** The live store to checkpoint and dump (the clone source; the live engine is never suspended). */
|
|
64
|
+
pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">;
|
|
65
|
+
/** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
|
|
66
|
+
readMutationStats: () => Promise<MutationDiagnostics>;
|
|
67
|
+
/** The optimistic flush (`client.flush()`), driven during the drain to send drainable rows. */
|
|
68
|
+
flush: () => Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* The `-t` allowlist: the schema-qualified physical synced table names, resolved from the registry by the
|
|
71
|
+
* SAME projection the DDL generator uses (`collectDataExportSyncedTableNames`) — never re-derived here.
|
|
72
|
+
*/
|
|
73
|
+
syncedTableNames: string[];
|
|
74
|
+
/**
|
|
75
|
+
* The generated enum DDL header (`buildDataExportEnumHeaderSql`) — the `CREATE TYPE` statements for the
|
|
76
|
+
* enums the exported tables reference, which `pg_dump -t` omits. `""` when no exported table uses an enum.
|
|
77
|
+
*/
|
|
78
|
+
enumHeaderSql: string;
|
|
79
|
+
/**
|
|
80
|
+
* The clone-cleanup SQL (`buildDataExportCloneCleanupSql`) run on the throwaway clone before `pg_dump -t`,
|
|
81
|
+
* dropping the reconcile triggers `-t` would otherwise pull into the artefact (referencing pgxsinkit
|
|
82
|
+
* functions the export excludes). `""` when the registry has no writable owning table.
|
|
83
|
+
*/
|
|
84
|
+
cloneCleanupSql: string;
|
|
85
|
+
/**
|
|
86
|
+
* The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default artefact
|
|
87
|
+
* file name. The resolved PGlite dataDir URL is deliberately NOT used: internal plumbing, never an
|
|
88
|
+
* artefact-name seed.
|
|
89
|
+
*/
|
|
90
|
+
storePath?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Run a data export (ADR-0035): drain the journal (unless the escape hatch is set) → throwaway-clone
|
|
94
|
+
* `pg_dump -t` per synced table → concatenate the comment + enum DDL header → assemble the report. The
|
|
95
|
+
* caller (`createSyncClient`) awaits engine-ready and enters the lifecycle slot BEFORE calling this, so the
|
|
96
|
+
* whole drain+dump runs under the store's single lifecycle slot (the drain must sit inside it — see the
|
|
97
|
+
* module header).
|
|
98
|
+
*/
|
|
99
|
+
export declare function performDataExport(deps: DataExportDeps, options?: DataExportOptions): Promise<DataExportResult>;
|
|
100
|
+
//# sourceMappingURL=export-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-data.d.ts","sourceRoot":"","sources":["../src/export-data.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,EAAoB,KAAK,gBAAgB,EAAwB,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,6GAA6G;AAC7G,eAAO,MAAM,wBAAwB,QAAS,CAA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,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,gBAAgB,CAAC,CA6D3B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import type { MutationDiagnostics } from "@pgxsinkit/contracts";
|
|
3
|
+
import { type DiagnosticDumpReport } from "./export-store";
|
|
4
|
+
import type { ClientPGlite } from "./index";
|
|
5
|
+
/** Options for {@link SyncClient.exportDiagnostics}. */
|
|
6
|
+
export interface DiagnosticExportOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Override the generated artefact file name. When omitted, the name is
|
|
9
|
+
* `<storeId>-<timestamp>-diagnostics.sql`, where `storeId` is a filesystem-safe derivation of the store
|
|
10
|
+
* path (see `deriveStoreId`).
|
|
11
|
+
*/
|
|
12
|
+
fileName?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The SQL artefact + its report — the resolved value of {@link SyncClient.exportDiagnostics}. */
|
|
15
|
+
export interface DiagnosticExportResult {
|
|
16
|
+
/** The `pg_dump` output as a named `File` (`application/sql`), loadable into a vanilla Postgres. */
|
|
17
|
+
file: File;
|
|
18
|
+
/** The structured record of the export (ADR-0035). */
|
|
19
|
+
report: DiagnosticDumpReport;
|
|
20
|
+
}
|
|
21
|
+
/** The dependencies {@link performDiagnosticExport} needs from the owning client — narrow, so it is unit-testable. */
|
|
22
|
+
export interface DiagnosticExportDeps {
|
|
23
|
+
/** The live store to checkpoint and dump (the clone source; the live engine is never suspended). */
|
|
24
|
+
pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">;
|
|
25
|
+
/** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
|
|
26
|
+
readMutationStats: () => Promise<MutationDiagnostics>;
|
|
27
|
+
/**
|
|
28
|
+
* The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default artefact
|
|
29
|
+
* file name. The resolved PGlite dataDir URL is deliberately NOT used: it is internal plumbing and must
|
|
30
|
+
* not leak into an artefact name as something to imitate.
|
|
31
|
+
*/
|
|
32
|
+
storePath?: string;
|
|
33
|
+
}
|
|
34
|
+
/** The four extra phase walls the throwaway-clone pipeline adds on top of the shared checkpoint/dump pair. */
|
|
35
|
+
export interface CloneDumpPhases {
|
|
36
|
+
/** Offset from `startPerf` when the internal `dumpDataDir` (the clone's source) began. */
|
|
37
|
+
dumpStartedAtMs: number;
|
|
38
|
+
/** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
|
|
39
|
+
dumpMs: number;
|
|
40
|
+
/** Offset from `startPerf` when the `CHECKPOINT` began. */
|
|
41
|
+
checkpointStartedAtMs: number;
|
|
42
|
+
/** `CHECKPOINT` wall — flushing dirty buffers before the internal datadir dump the clone consumes. */
|
|
43
|
+
checkpointMs: number;
|
|
44
|
+
/** Offset from `startPerf` when the throwaway clone's `PGlite.create({ loadDataDir })` began. */
|
|
45
|
+
cloneBootStartedAtMs: number;
|
|
46
|
+
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
47
|
+
cloneBootMs: number;
|
|
48
|
+
/** Offset from `startPerf` when `pg_dump` began running against the clone. */
|
|
49
|
+
pgDumpStartedAtMs: number;
|
|
50
|
+
/** `pg_dump` wall — the WASM `pg_dump` reading the clone out to SQL. */
|
|
51
|
+
pgDumpMs: number;
|
|
52
|
+
}
|
|
53
|
+
/** The raw SQL bytes plus the pipeline phase walls — {@link runThrowawayCloneDump}'s result. */
|
|
54
|
+
export interface CloneDumpResult {
|
|
55
|
+
/** The `pg_dump` output bytes (unwrapped from pglite-tools' `File` polyfill). */
|
|
56
|
+
sqlBytes: Uint8Array<ArrayBuffer>;
|
|
57
|
+
/** The pipeline phase timings, all offset from the caller's `startPerf` anchor. */
|
|
58
|
+
phases: CloneDumpPhases;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The throwaway-clone dump core shared by BOTH `pgDump` exports (ADR-0035 addendum): (1) a LIVE datadir dump
|
|
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 PGlite booted from it via `loadDataDir` — engine-less, no
|
|
64
|
+
* `live` extension, nothing `pg_dump`'s `DEALLOCATE ALL` can corrupt; (3) `pg_dump` against the throwaway
|
|
65
|
+
* with the caller's `args` (none for a diagnostic dump; the `-t` allowlist + `--no-owner` for a data
|
|
66
|
+
* export); (4) discard the clone in a `finally`. Factored out so `performDiagnosticExport` and
|
|
67
|
+
* `performDataExport` cannot drift on the clone plumbing, the memory-scheme selection, or the timing house
|
|
68
|
+
* style — the ONLY differences between the two dumps are the `pg_dump` args and the artefact assembly.
|
|
69
|
+
*
|
|
70
|
+
* `@electric-sql/pglite-tools` is loaded ONLY via the dynamic `import()` here (ADR-0035 decision 7): its
|
|
71
|
+
* ~700 kB `pg_dump.wasm` (+ ~100 kB JS) stays off boot and off every non-exporting bundle.
|
|
72
|
+
*/
|
|
73
|
+
export interface CloneDumpOptions {
|
|
74
|
+
/** The `pg_dump` args (none for a diagnostic dump; `-t` allowlist + `--no-owner` for a data export). */
|
|
75
|
+
pgDumpArgs?: string[];
|
|
76
|
+
/**
|
|
77
|
+
* A hook run on the throwaway clone AFTER boot, BEFORE `pg_dump` — its one legitimate window to mutate the
|
|
78
|
+
* clone (which is fully owned and discarded straight after). The data export uses it to drop the reconcile
|
|
79
|
+
* triggers `pg_dump -t` would otherwise pull into the artefact (see `buildDataExportCloneCleanupSql`); a
|
|
80
|
+
* diagnostic dump passes none (it wants the store verbatim).
|
|
81
|
+
*/
|
|
82
|
+
prepareClone?: (clone: PGlite) => Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export declare function runThrowawayCloneDump(pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">, startPerf: number, options?: CloneDumpOptions): Promise<CloneDumpResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Run a diagnostic dump (ADR-0035): live datadir dump → memory-backed throwaway clone → `pg_dump` → discard
|
|
87
|
+
* the clone → assemble the report. The caller (`createSyncClient`) awaits engine-ready and enters the
|
|
88
|
+
* lifecycle slot BEFORE calling this, exactly as it does for the store backup — kept out of here so the
|
|
89
|
+
* helper stays a pure "do the dump" unit.
|
|
90
|
+
*/
|
|
91
|
+
export declare function performDiagnosticExport(deps: DiagnosticExportDeps, options?: DiagnosticExportOptions): Promise<DiagnosticExportResult>;
|
|
92
|
+
//# sourceMappingURL=export-dump.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-dump.d.ts","sourceRoot":"","sources":["../src/export-dump.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAoB,KAAK,oBAAoB,EAA4C,MAAM,gBAAgB,CAAC;AACvH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,wDAAwD;AACxD,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,kGAAkG;AAClG,MAAM,WAAW,sBAAsB;IACrC,oGAAoG;IACpG,IAAI,EAAE,IAAI,CAAC;IACX,sDAAsD;IACtD,MAAM,EAAE,oBAAoB,CAAC;CAC9B;AAED,sHAAsH;AACtH,MAAM,WAAW,oBAAoB;IACnC,oGAAoG;IACpG,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC;IACnD,6FAA6F;IAC7F,iBAAiB,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACtD;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAsBD,8GAA8G;AAC9G,MAAM,WAAW,eAAe;IAC9B,0FAA0F;IAC1F,eAAe,EAAE,MAAM,CAAC;IACxB,qHAAqH;IACrH,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,qBAAqB,EAAE,MAAM,CAAC;IAC9B,sGAAsG;IACtG,YAAY,EAAE,MAAM,CAAC;IACrB,iGAAiG;IACjG,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oFAAoF;IACpF,WAAW,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,gGAAgG;AAChG,MAAM,WAAW,eAAe;IAC9B,iFAAiF;IACjF,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,CA6D1B;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,oBAAoB,EAC1B,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,sBAAsB,CAAC,CA+BjC"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { MutationDiagnostics } from "@pgxsinkit/contracts";
|
|
2
|
+
import type { ClientPGlite } from "./index";
|
|
3
|
+
/**
|
|
4
|
+
* Monotonic clock (ms) — `performance.now()` where available, else `Date.now()` (mirrors BootReport).
|
|
5
|
+
* Exported so the sibling diagnostic-dump path ({@link file://./export-dump.ts}) times its extra phases
|
|
6
|
+
* (clone boot, pg_dump) on the SAME clock as this module's checkpoint/dump pair.
|
|
7
|
+
*/
|
|
8
|
+
export declare const nowMs: () => number;
|
|
9
|
+
/** Options for {@link SyncClient.exportStore}. */
|
|
10
|
+
export interface StoreExportOptions {
|
|
11
|
+
/**
|
|
12
|
+
* How to compress the tarball, forwarded to PGlite's `dumpDataDir`. `"auto"` (the default) gzips when a
|
|
13
|
+
* `CompressionStream` is available and falls back to an uncompressed tar otherwise; `"gzip"` forces
|
|
14
|
+
* compression; `"none"` skips it. The report's `compression` records the compression that was actually
|
|
15
|
+
* applied (which, under `"auto"`, is resolved at runtime).
|
|
16
|
+
*/
|
|
17
|
+
compression?: "auto" | "gzip" | "none";
|
|
18
|
+
/**
|
|
19
|
+
* Override the generated artefact file name. When omitted, the name is
|
|
20
|
+
* `<storeId>-<timestamp>.pgdata.tar[.gz]`, where `storeId` is a filesystem-safe derivation of the store
|
|
21
|
+
* path and the extension reflects the applied compression.
|
|
22
|
+
*/
|
|
23
|
+
fileName?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The fields EVERY export report carries, whatever its kind — built in the BootReport house style
|
|
27
|
+
* (ADR-0034): `reportVersion` is a contract number (additive fields keep it, a breaking reshape bumps it);
|
|
28
|
+
* all `*Ms` are milliseconds; `startedAt` is the only wall-clock value and every `*AtMs` is a monotonic
|
|
29
|
+
* offset from it. The per-kind interfaces below add their `kind`/`scope`/`phases` discriminant on top.
|
|
30
|
+
*/
|
|
31
|
+
export interface ExportReportCommon {
|
|
32
|
+
reportVersion: 1;
|
|
33
|
+
/** Epoch anchor (`Date.now()`) at export start; every other duration/offset is monotonic relative to it. */
|
|
34
|
+
startedAt: number;
|
|
35
|
+
/** Export start → artefact ready. */
|
|
36
|
+
totalMs: number;
|
|
37
|
+
/** The artefact's byte length — the size the caller downloads / persists. */
|
|
38
|
+
byteLength: number;
|
|
39
|
+
/**
|
|
40
|
+
* The {@link MutationDiagnostics} snapshot at export time — the journal state captured alongside the
|
|
41
|
+
* artefact (for the store backup, the very journal that travels INSIDE the tarball; for the diagnostic
|
|
42
|
+
* dump, the live store's journal at dump time, whose rows the SQL also carries).
|
|
43
|
+
*/
|
|
44
|
+
diagnostics: MutationDiagnostics;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A live **store backup** (ADR-0035): the whole datadir as a PGlite-restorable tarball, journal and overlay
|
|
48
|
+
* included. `checkpoint`/`dump` are the only phases — a store backup is a `CHECKPOINT` + `dumpDataDir`, no
|
|
49
|
+
* clone. Slice-1 shape, kept unchanged (the union is additive).
|
|
50
|
+
*/
|
|
51
|
+
export interface StoreBackupReport extends ExportReportCommon {
|
|
52
|
+
/** Which export produced this artefact. */
|
|
53
|
+
kind: "store-backup";
|
|
54
|
+
/** What the artefact covers. A store backup is always the whole store, journal and overlay included. */
|
|
55
|
+
scope: "whole-store";
|
|
56
|
+
/** The compression actually applied to the tarball (resolved from `"auto"` at dump time). */
|
|
57
|
+
compression: "gzip" | "none";
|
|
58
|
+
phases: {
|
|
59
|
+
/** Offset from export start when the `CHECKPOINT` began. */
|
|
60
|
+
checkpointStartedAtMs: number;
|
|
61
|
+
/** `CHECKPOINT` wall — flushing dirty buffers to the datadir before it is tarred, serialised behind engine work. */
|
|
62
|
+
checkpointMs: number;
|
|
63
|
+
/** Offset from export start when `dumpDataDir` began. */
|
|
64
|
+
dumpStartedAtMs: number;
|
|
65
|
+
/** `dumpDataDir` wall — reading the datadir out and assembling (optionally compressing) the tarball. */
|
|
66
|
+
dumpMs: number;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A **diagnostic dump** (ADR-0035, via the throwaway clone of the addendum): human-readable SQL of
|
|
71
|
+
* EVERYTHING the store holds — synced tables, the `_overlay`/`_mutations` journal, the `pgxsinkit` metadata
|
|
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 PGlite via `loadDataDir`, against which `pg_dump` runs
|
|
74
|
+
* — so the live engine is never touched (the addendum's whole point). Its phases add the clone boot and the
|
|
75
|
+
* `pg_dump` walls to the shared checkpoint/dump pair.
|
|
76
|
+
*/
|
|
77
|
+
export interface DiagnosticDumpReport extends ExportReportCommon {
|
|
78
|
+
kind: "diagnostic-dump";
|
|
79
|
+
/** A diagnostic dump covers everything the store holds — synced data, journal, metadata, views, functions. */
|
|
80
|
+
scope: "everything";
|
|
81
|
+
phases: {
|
|
82
|
+
/** Offset from export start when the `CHECKPOINT` began. */
|
|
83
|
+
checkpointStartedAtMs: number;
|
|
84
|
+
/** `CHECKPOINT` wall — flushing dirty buffers before the internal datadir dump the clone consumes. */
|
|
85
|
+
checkpointMs: number;
|
|
86
|
+
/** Offset from export start when the internal `dumpDataDir` began. */
|
|
87
|
+
dumpStartedAtMs: number;
|
|
88
|
+
/** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
|
|
89
|
+
dumpMs: number;
|
|
90
|
+
/** Offset from export start when the throwaway clone's `PGlite.create({ loadDataDir })` began. */
|
|
91
|
+
cloneBootStartedAtMs: number;
|
|
92
|
+
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
93
|
+
cloneBootMs: number;
|
|
94
|
+
/** Offset from export start when `pg_dump` began running against the clone. */
|
|
95
|
+
pgDumpStartedAtMs: number;
|
|
96
|
+
/** `pg_dump` wall — the WASM `pg_dump` reading the clone out to SQL. */
|
|
97
|
+
pgDumpMs: number;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A **data export** (ADR-0035 decision 1, via the throwaway clone of the addendum): the PORTABLE artefact —
|
|
102
|
+
* the synced tables and the enum types they depend on, schema + data, nothing of pgxsinkit's machinery,
|
|
103
|
+
* loadable into a vanilla Postgres. It is a generated enum DDL header concatenated ahead of a `pg_dump -t`
|
|
104
|
+
* (per synced table) `--no-owner` run against the same memory-backed throwaway clone the diagnostic dump
|
|
105
|
+
* uses. Unlike the other two exports it GUARDS: it requires a drained Mutation journal (or the explicit
|
|
106
|
+
* `drainJournal: false` escape hatch), so its phases add the drain wall ahead of the clone pipeline, and it
|
|
107
|
+
* records its provenance (`tables` = the `-t` allowlist actually applied, `escapeHatch` = whether the drain
|
|
108
|
+
* was skipped).
|
|
109
|
+
*/
|
|
110
|
+
export interface DataExportReport extends ExportReportCommon {
|
|
111
|
+
kind: "data-export";
|
|
112
|
+
/** A data export covers the synced tables + their enum types only — never pgxsinkit's overlay/journal/metadata. */
|
|
113
|
+
scope: "synced-tables";
|
|
114
|
+
/**
|
|
115
|
+
* The schema-qualified physical synced tables the `-t` allowlist targeted, in registry order — the
|
|
116
|
+
* self-describing provenance of exactly what the artefact carries (ephemeral/read-projection entries
|
|
117
|
+
* excluded by construction). May be empty when the registry declares no owning persistent table.
|
|
118
|
+
*/
|
|
119
|
+
tables: string[];
|
|
120
|
+
/**
|
|
121
|
+
* `true` when `drainJournal: false` skipped the drain and the artefact reflects the SYNCED state as-is
|
|
122
|
+
* (unflushed local writes silently absent). `false` on the strict path (a drained or empty journal).
|
|
123
|
+
*/
|
|
124
|
+
escapeHatch: boolean;
|
|
125
|
+
phases: {
|
|
126
|
+
/** Offset from export start when the drain guard began (`0` when the escape hatch skipped it). */
|
|
127
|
+
drainStartedAtMs: number;
|
|
128
|
+
/** Drain wall — flushing + awaiting the journal reach fully-drained (`0` under the escape hatch). */
|
|
129
|
+
drainMs: number;
|
|
130
|
+
/** Offset from export start when the `CHECKPOINT` began. */
|
|
131
|
+
checkpointStartedAtMs: number;
|
|
132
|
+
/** `CHECKPOINT` wall — flushing dirty buffers before the internal datadir dump the clone consumes. */
|
|
133
|
+
checkpointMs: number;
|
|
134
|
+
/** Offset from export start when the internal `dumpDataDir` began. */
|
|
135
|
+
dumpStartedAtMs: number;
|
|
136
|
+
/** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
|
|
137
|
+
dumpMs: number;
|
|
138
|
+
/** Offset from export start when the throwaway clone's `PGlite.create({ loadDataDir })` began. */
|
|
139
|
+
cloneBootStartedAtMs: number;
|
|
140
|
+
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
141
|
+
cloneBootMs: number;
|
|
142
|
+
/** Offset from export start when `pg_dump -t` began running against the clone. */
|
|
143
|
+
pgDumpStartedAtMs: number;
|
|
144
|
+
/** `pg_dump -t` wall — the WASM `pg_dump` reading the allowlisted tables out to SQL. */
|
|
145
|
+
pgDumpMs: number;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A structured, versioned record of one local-store export (ADR-0035) — a discriminated union on `kind`.
|
|
150
|
+
* Every member shares {@link ExportReportCommon}; the `kind`/`scope`/`phases` discriminant tells the three
|
|
151
|
+
* exports apart. `exportStore` resolves a {@link StoreBackupReport}; `exportDiagnostics` a
|
|
152
|
+
* {@link DiagnosticDumpReport}; `exportData` a {@link DataExportReport}.
|
|
153
|
+
*/
|
|
154
|
+
export type ExportReport = StoreBackupReport | DiagnosticDumpReport | DataExportReport;
|
|
155
|
+
/** The artefact + its report — the resolved value of {@link SyncClient.exportStore}. */
|
|
156
|
+
export interface StoreExportResult {
|
|
157
|
+
/** The store-backup tarball as a named `File` (PGlite-restorable via `loadDataDir`, a later slice). */
|
|
158
|
+
file: File;
|
|
159
|
+
/** The structured record of the export (ADR-0035). */
|
|
160
|
+
report: StoreBackupReport;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
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 PGlite's own `dumpDataDir` does when it names the inner db), then keeps only
|
|
165
|
+
* `[A-Za-z0-9._-]`. No scheme stripping — the store path is a plain name, never a storage URL. Falls back
|
|
166
|
+
* to a fixed token for an empty path so the name is always well formed.
|
|
167
|
+
*/
|
|
168
|
+
export declare function deriveStoreId(storePath: string | undefined): string;
|
|
169
|
+
/**
|
|
170
|
+
* An ISO-ish, filesystem-safe timestamp (colons/dots → hyphens) for a default artefact file name. Exported
|
|
171
|
+
* so the diagnostic-dump path names its `.sql` artefact with the identical timestamp shape.
|
|
172
|
+
*/
|
|
173
|
+
export declare const compactTimestamp: () => string;
|
|
174
|
+
/**
|
|
175
|
+
* The datadir dump both exports share (ADR-0035): a `CHECKPOINT` through the store's normal query path,
|
|
176
|
+
* then `dumpDataDir`. The store backup keeps its bytes as the artefact; the diagnostic dump feeds them to a
|
|
177
|
+
* throwaway clone. Factored out so exactly one implementation of "flush + tar the live datadir" exists —
|
|
178
|
+
* `performStoreExport` and `performDiagnosticExport` cannot drift on the checkpoint ordering or the timing
|
|
179
|
+
* house style. Returns the raw `dumpDataDir` output plus the two phase walls, both offset from `startPerf`
|
|
180
|
+
* (the caller's export-start monotonic anchor) so the timings compose into either report.
|
|
181
|
+
*
|
|
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 `pglite.exec` serialises it behind any in-flight engine work on PGlite's
|
|
184
|
+
* single connection, flushing dirty buffers to the datadir the dump then reads — so the tarball reflects
|
|
185
|
+
* committed state, not a torn mid-write datadir.
|
|
186
|
+
*/
|
|
187
|
+
export declare function performDatadirDump(pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">, compression: "auto" | "gzip" | "none", startPerf: number): Promise<{
|
|
188
|
+
dumped: Awaited<ReturnType<ClientPGlite["dumpDataDir"]>>;
|
|
189
|
+
checkpointStartedAtMs: number;
|
|
190
|
+
checkpointMs: number;
|
|
191
|
+
dumpStartedAtMs: number;
|
|
192
|
+
dumpMs: number;
|
|
193
|
+
}>;
|
|
194
|
+
/** The dependencies {@link performStoreExport} needs from the owning client — narrow, so it is unit-testable. */
|
|
195
|
+
export interface StoreExportDeps {
|
|
196
|
+
/** The live store to checkpoint and dump. */
|
|
197
|
+
pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">;
|
|
198
|
+
/** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
|
|
199
|
+
readMutationStats: () => Promise<MutationDiagnostics>;
|
|
200
|
+
/**
|
|
201
|
+
* The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default backup
|
|
202
|
+
* file name (`deriveStoreId`). The resolved PGlite dataDir URL is deliberately NOT used here: it is
|
|
203
|
+
* internal plumbing and must not leak into an artefact name as something to imitate.
|
|
204
|
+
*/
|
|
205
|
+
storePath?: string;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Run a live store backup (ADR-0035): checkpoint → dump → snapshot diagnostics → assemble the report. The
|
|
209
|
+
* caller (`createSyncClient`) is responsible for awaiting engine-ready and entering the lifecycle slot
|
|
210
|
+
* BEFORE calling this — kept out of here so the helper stays a pure "do the dump" unit. No engine
|
|
211
|
+
* suspension: the backup is live by design.
|
|
212
|
+
*/
|
|
213
|
+
export declare function performStoreExport(deps: StoreExportDeps, options?: StoreExportOptions): Promise<StoreExportResult>;
|
|
214
|
+
//# sourceMappingURL=export-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-store.d.ts","sourceRoot":"","sources":["../src/export-store.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,KAAK,QAAO,MAA+E,CAAC;AAEzG,kDAAkD;AAClD,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,aA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