@powerhousedao/reactor-api 6.2.3-dev.1 → 6.2.3-dev.100
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/README.md +7 -2
- package/dist/{adapter-gateway-apollo-DdamNLPT.mjs → adapter-gateway-apollo-D-EdZ4e-.mjs} +23 -24
- package/dist/adapter-gateway-apollo-D-EdZ4e-.mjs.map +1 -0
- package/dist/{adapter-gateway-mercurius-CLmTtNJC.mjs → adapter-gateway-mercurius-CdxLge5p.mjs} +4 -11
- package/dist/adapter-gateway-mercurius-CdxLge5p.mjs.map +1 -0
- package/dist/{adapter-http-express-54gdI9bu.mjs → adapter-http-express-78KD77cI.mjs} +11 -11
- package/dist/adapter-http-express-78KD77cI.mjs.map +1 -0
- package/dist/{adapter-http-fastify-DmccBVOe.mjs → adapter-http-fastify-Dk7aT_xw.mjs} +14 -13
- package/dist/adapter-http-fastify-Dk7aT_xw.mjs.map +1 -0
- package/dist/base-document-models-caJpqTLw.mjs +2083 -0
- package/dist/base-document-models-caJpqTLw.mjs.map +1 -0
- package/dist/create-schema-BCArFBv9.d.mts +167 -0
- package/dist/create-schema-BCArFBv9.d.mts.map +1 -0
- package/dist/error-info-Cr6oQACe.mjs +601 -0
- package/dist/error-info-Cr6oQACe.mjs.map +1 -0
- package/dist/index.d.mts +3410 -1028
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +7549 -2724
- package/dist/index.mjs.map +1 -1
- package/dist/package-subgraph-check-BxKx9kcQ.mjs +138 -0
- package/dist/package-subgraph-check-BxKx9kcQ.mjs.map +1 -0
- package/dist/pglite-like-CKQEL_Q0.d.mts +27 -0
- package/dist/pglite-like-CKQEL_Q0.d.mts.map +1 -0
- package/dist/pglite-node-CcX2YT-l.mjs +744 -0
- package/dist/pglite-node-CcX2YT-l.mjs.map +1 -0
- package/dist/rolldown-runtime-8H4AJuhK.mjs +16 -0
- package/dist/run-node-handler-CQjyjOuN.mjs +52 -0
- package/dist/run-node-handler-CQjyjOuN.mjs.map +1 -0
- package/dist/src/graphql/subgraph-types.d.mts +43 -0
- package/dist/src/graphql/subgraph-types.d.mts.map +1 -0
- package/dist/src/graphql/subgraph-types.mjs +14 -0
- package/dist/src/graphql/subgraph-types.mjs.map +1 -0
- package/dist/src/packages/https-hooks.d.mts +4 -4
- package/dist/src/packages/https-hooks.d.mts.map +1 -1
- package/dist/src/packages/https-hooks.mjs +2 -2
- package/dist/src/packages/https-hooks.mjs.map +1 -1
- package/dist/src/packages/vite-loader.d.mts +30 -9
- package/dist/src/packages/vite-loader.d.mts.map +1 -1
- package/dist/src/packages/vite-loader.mjs +208 -88
- package/dist/src/packages/vite-loader.mjs.map +1 -1
- package/dist/src/pglite/pglite-node.d.mts +434 -0
- package/dist/src/pglite/pglite-node.d.mts.map +1 -0
- package/dist/src/pglite/pglite-node.mjs +5 -0
- package/dist/src/pglite/worker/entry.d.mts +2 -0
- package/dist/src/pglite/worker/entry.mjs +298 -0
- package/dist/src/pglite/worker/entry.mjs.map +1 -0
- package/dist/subgraph-extraction-C_hFvSaS.mjs +1884 -0
- package/dist/subgraph-extraction-C_hFvSaS.mjs.map +1 -0
- package/dist/subgraph-schema-owner-BEjuk2Xv.mjs +10 -0
- package/dist/subgraph-schema-owner-BEjuk2Xv.mjs.map +1 -0
- package/dist/types-Bz_xjf8j.d.mts +105 -0
- package/dist/types-Bz_xjf8j.d.mts.map +1 -0
- package/package.json +42 -26
- package/dist/adapter-gateway-apollo-DdamNLPT.mjs.map +0 -1
- package/dist/adapter-gateway-mercurius-CLmTtNJC.mjs.map +0 -1
- package/dist/adapter-http-express-54gdI9bu.mjs.map +0 -1
- package/dist/adapter-http-fastify-DmccBVOe.mjs.map +0 -1
- package/dist/path-normalize-DWWFLiy6.mjs +0 -23
- package/dist/path-normalize-DWWFLiy6.mjs.map +0 -1
- package/dist/types-Bz2niABC.d.mts +0 -48
- package/dist/types-Bz2niABC.d.mts.map +0 -1
- package/dist/utils-XWVecaNn.mjs +0 -653
- package/dist/utils-XWVecaNn.mjs.map +0 -1
- package/dist/websocket-DncAB9XK.mjs +0 -18
- package/dist/websocket-DncAB9XK.mjs.map +0 -1
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { n as PGLITE_UTC_PARSERS, t as PGliteLike } from "../../pglite-like-CKQEL_Q0.mjs";
|
|
2
|
+
import { ILogger } from "document-model";
|
|
3
|
+
import { IStoreMaintenance, TableRewriteRequest, TableRewriteResult, WorkerMemorySample } from "@powerhousedao/reactor";
|
|
4
|
+
import nodeFs from "node:fs";
|
|
5
|
+
import { PGlite, QueryOptions, Results } from "@electric-sql/pglite";
|
|
6
|
+
import { NodeFS } from "@electric-sql/pglite/nodefs";
|
|
7
|
+
import { ResourceLimits } from "node:worker_threads";
|
|
8
|
+
//#region src/pglite/maintenance.d.ts
|
|
9
|
+
export declare const DEFAULT_MAINTENANCE_INTERVAL_MS: number;
|
|
10
|
+
export declare const DEFAULT_VACUUM_FULL_ABOVE_BYTES: number;
|
|
11
|
+
export declare const DEFAULT_VACUUM_FULL_QUIET_MS: number;
|
|
12
|
+
/**
|
|
13
|
+
* How long a pending VACUUM FULL waits for a quiet store before it runs
|
|
14
|
+
* anyway: by default it never does (0), because a forced rewrite of a large
|
|
15
|
+
* store under load holds the only connection for minutes, every caller times
|
|
16
|
+
* out, and the dir needs about twice its size in free space meanwhile.
|
|
17
|
+
* `PH_PGLITE_VACUUM_FULL=forced` restores a deadline.
|
|
18
|
+
*/
|
|
19
|
+
export declare const DEFAULT_VACUUM_FULL_MAX_DEFER_MS = 0;
|
|
20
|
+
/** The deadline `PH_PGLITE_VACUUM_FULL=forced` sets. */
|
|
21
|
+
export declare const FORCED_VACUUM_FULL_MAX_DEFER_MS: number;
|
|
22
|
+
/**
|
|
23
|
+
* A table rewrite waits for this long a gap between the store's statements.
|
|
24
|
+
* Short, because PGlite syncs after every statement and an idle reactor still
|
|
25
|
+
* reads every 2 s (catch-up, sync polls), so a longer gap never comes.
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEFAULT_REWRITE_QUIET_MS = 1000;
|
|
28
|
+
/** How long a table rewrite waits for that gap before it reports the store busy. */
|
|
29
|
+
export declare const DEFAULT_REWRITE_MAX_WAIT_MS: number;
|
|
30
|
+
type MaintenanceOutcome = "vacuum" | "vacuum-full" | "idle" | "not-ready" | "in-transaction" | "failed";
|
|
31
|
+
interface MaintenanceLogger {
|
|
32
|
+
warn(message: string): void;
|
|
33
|
+
/** A finished VACUUM FULL is reported here; `warn` when absent. */
|
|
34
|
+
info?(message: string): void;
|
|
35
|
+
}
|
|
36
|
+
/** Runs a maintenance pass in the owner's turn; see {@link MaintenanceOptions.gate}. */
|
|
37
|
+
type MaintenanceGate = <T>(task: () => Promise<T>) => Promise<T>;
|
|
38
|
+
interface MaintenanceOptions {
|
|
39
|
+
/** VACUUM + CHECKPOINT cadence; PGlite has no autovacuum. Default 5 min; 0 disables. */
|
|
40
|
+
intervalMs?: number;
|
|
41
|
+
/** First pass runs VACUUM FULL when `base/` exceeds this at open. Default 256 MB; 0 disables. */
|
|
42
|
+
vacuumFullAboveBytes?: number;
|
|
43
|
+
/**
|
|
44
|
+
* VACUUM FULL holds the store for minutes on a large dir, so it waits for a
|
|
45
|
+
* store with no synced statement (no write, no catch-up) for this long,
|
|
46
|
+
* counted from open; until then a pass runs plain VACUUM and keeps the
|
|
47
|
+
* VACUUM FULL pending. Default 60 s; 0 runs it on the first pass.
|
|
48
|
+
*/
|
|
49
|
+
vacuumFullQuietMs?: number;
|
|
50
|
+
/**
|
|
51
|
+
* The longest a pending VACUUM FULL waits for that quiet window, counted
|
|
52
|
+
* from open; past it the next pass runs VACUUM FULL anyway. Default 0,
|
|
53
|
+
* which waits for the quiet window however long it takes.
|
|
54
|
+
*/
|
|
55
|
+
vacuumFullMaxDeferMs?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Queues each pass with the store's other work, e.g. behind a worker's
|
|
58
|
+
* pending requests, so a pass never starts ahead of a statement already
|
|
59
|
+
* admitted. A pass still waiting here when the store closes is skipped.
|
|
60
|
+
*/
|
|
61
|
+
gate?: MaintenanceGate;
|
|
62
|
+
logger?: MaintenanceLogger;
|
|
63
|
+
/** Clock for the quiet window; tests pass their own. */
|
|
64
|
+
now?: () => number;
|
|
65
|
+
/** The gap between statements a table rewrite waits for. Default 1 s. */
|
|
66
|
+
rewriteQuietMs?: number;
|
|
67
|
+
/** How long a table rewrite waits for that gap. Default 15 min. */
|
|
68
|
+
rewriteMaxWaitMs?: number;
|
|
69
|
+
}
|
|
70
|
+
export declare class PgliteMaintenance implements IStoreMaintenance {
|
|
71
|
+
private readonly intervalMs;
|
|
72
|
+
private readonly vacuumFullAboveBytes;
|
|
73
|
+
private readonly vacuumFullQuietMs;
|
|
74
|
+
private readonly vacuumFullMaxDeferMs;
|
|
75
|
+
private readonly gate?;
|
|
76
|
+
private readonly logger?;
|
|
77
|
+
private readonly now;
|
|
78
|
+
private readonly rewriteQuietMs;
|
|
79
|
+
private readonly rewriteMaxWaitMs;
|
|
80
|
+
private pg?;
|
|
81
|
+
private label;
|
|
82
|
+
private closing;
|
|
83
|
+
private syncsSinceMaintenance;
|
|
84
|
+
private vacuumFullPending;
|
|
85
|
+
private timer?;
|
|
86
|
+
private inFlight?;
|
|
87
|
+
private active;
|
|
88
|
+
private deferralLogged;
|
|
89
|
+
private lastSyncAt;
|
|
90
|
+
private openedAt;
|
|
91
|
+
private rewriting?;
|
|
92
|
+
constructor(options?: MaintenanceOptions);
|
|
93
|
+
get scheduled(): boolean;
|
|
94
|
+
get running(): boolean;
|
|
95
|
+
start(pg: PGlite, label: string, baseBytes: number): void;
|
|
96
|
+
noteSync(): void;
|
|
97
|
+
/** Waits for a pass that has started; one still queued at the gate is left to skip itself. */
|
|
98
|
+
stop(): Promise<void>;
|
|
99
|
+
run(): Promise<MaintenanceOutcome>;
|
|
100
|
+
/**
|
|
101
|
+
* Rewrites one table with VACUUM FULL and a CHECKPOINT, in the turn of the
|
|
102
|
+
* store's other work, never the whole store. Waits for a gap in the store's
|
|
103
|
+
* statements first; nothing else runs on it while the table is rewritten.
|
|
104
|
+
*/
|
|
105
|
+
rewriteTable(request: TableRewriteRequest): Promise<TableRewriteResult>;
|
|
106
|
+
private runNow;
|
|
107
|
+
private pass;
|
|
108
|
+
/** Undefined when a transaction is open, so the caller waits and tries again. */
|
|
109
|
+
private rewriteNow;
|
|
110
|
+
/** Why the disk cannot hold the rewrite; undefined when it can or nobody can tell. */
|
|
111
|
+
private diskShortage;
|
|
112
|
+
private schedule;
|
|
113
|
+
private cancel;
|
|
114
|
+
}
|
|
115
|
+
/** The maintenance of a store opened on DurableNodeFs; undefined for any other. */
|
|
116
|
+
export declare function maintenanceOf(store: {
|
|
117
|
+
fs?: unknown;
|
|
118
|
+
}): PgliteMaintenance | undefined;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/pglite/durable-node-fs.d.ts
|
|
121
|
+
type NodeFsClass = typeof NodeFS;
|
|
122
|
+
interface DurableNodeFsOptions {
|
|
123
|
+
/** Default true; `PH_PGLITE_FSYNC=0` turns it off (power-loss durability off). */
|
|
124
|
+
fsync?: boolean;
|
|
125
|
+
/** Default 5 min; 0 disables. */
|
|
126
|
+
maintenanceIntervalMs?: number;
|
|
127
|
+
/** `base/` size at open; default 256 MB; 0 disables. */
|
|
128
|
+
vacuumFullAboveBytes?: number;
|
|
129
|
+
/** See `MaintenanceOptions.vacuumFullQuietMs`; default 60 s. */
|
|
130
|
+
vacuumFullQuietMs?: number;
|
|
131
|
+
/** See `MaintenanceOptions.vacuumFullMaxDeferMs`; default 0 (quiet window only). */
|
|
132
|
+
vacuumFullMaxDeferMs?: number;
|
|
133
|
+
/** See `MaintenanceOptions.gate`. */
|
|
134
|
+
maintenanceGate?: MaintenanceGate;
|
|
135
|
+
/** The gap between statements a table rewrite waits for. Default 1 s. */
|
|
136
|
+
rewriteQuietMs?: number;
|
|
137
|
+
/** How long a table rewrite waits for that gap. Default 15 min. */
|
|
138
|
+
rewriteMaxWaitMs?: number;
|
|
139
|
+
/** Clock for the maintenance quiet window; tests pass their own. */
|
|
140
|
+
now?: () => number;
|
|
141
|
+
logger?: {
|
|
142
|
+
warn(message: string): void;
|
|
143
|
+
info?(message: string): void;
|
|
144
|
+
};
|
|
145
|
+
/** Emscripten abort (a Postgres PANIC, e.g. ENOSPC on WAL). */
|
|
146
|
+
onAbort?: (what: unknown) => void;
|
|
147
|
+
hostFs?: Pick<typeof nodeFs, "fsyncSync" | "fdatasyncSync">;
|
|
148
|
+
}
|
|
149
|
+
type DurableNodeFs = InstanceType<NodeFsClass> & {
|
|
150
|
+
readonly maintenance: PgliteMaintenance;
|
|
151
|
+
};
|
|
152
|
+
export declare function resolvePgliteFsync(env: Record<string, string | undefined>): boolean;
|
|
153
|
+
/** `PH_PGLITE_VACUUM_FULL`: when an oversized store's one-time VACUUM FULL may run. */
|
|
154
|
+
type PgliteVacuumFullMode = "off" | "quiet" | "forced";
|
|
155
|
+
/** The VACUUM FULL settings an environment selects; see {@link resolvePgliteMaintenance}. */
|
|
156
|
+
type PgliteMaintenanceSettings = Pick<DurableNodeFsOptions, "vacuumFullAboveBytes" | "vacuumFullQuietMs" | "vacuumFullMaxDeferMs">;
|
|
157
|
+
/**
|
|
158
|
+
* Reads the VACUUM FULL knobs. `PH_PGLITE_VACUUM_FULL` is `off` (the
|
|
159
|
+
* default: never), `quiet` (only after the quiet window, however long that
|
|
160
|
+
* takes) or `forced` (a deadline of 30 min from open, after which it runs
|
|
161
|
+
* under load). Off is the default because a full rewrite of a large store
|
|
162
|
+
* needs about twice its size in free disk and holds the only connection for
|
|
163
|
+
* minutes, and on a store that is live data rather than bloat it reclaims
|
|
164
|
+
* nothing; a quiet window of a minute arrives naturally between jobs, so
|
|
165
|
+
* `quiet` is an opt-in for stores known to be small or bloated.
|
|
166
|
+
* `PH_PGLITE_VACUUM_FULL_ABOVE_MB` sets the size that makes a store
|
|
167
|
+
* eligible; `PH_PGLITE_VACUUM_FULL_QUIET_MS` and
|
|
168
|
+
* `PH_PGLITE_VACUUM_FULL_MAX_DEFER_MS` override the mode's timings. A value
|
|
169
|
+
* that is not a non-negative number is left to the default; an unknown mode
|
|
170
|
+
* throws, since silently running a rewrite is what this guards against.
|
|
171
|
+
*/
|
|
172
|
+
export declare function resolvePgliteMaintenance(env: Record<string, string | undefined>): PgliteMaintenanceSettings;
|
|
173
|
+
/** Built over the passed-in class so PG16 dirs on `pglite-legacy-02` get the same behaviour. */
|
|
174
|
+
export declare function createDurableNodeFs(Base: NodeFsClass, dataDir: string, options?: DurableNodeFsOptions): DurableNodeFs;
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/pglite/sync-tree.d.ts
|
|
177
|
+
interface SyncTreeHostFs {
|
|
178
|
+
fsyncSync(fd: number): void;
|
|
179
|
+
}
|
|
180
|
+
interface SyncTreeResult {
|
|
181
|
+
files: number;
|
|
182
|
+
dirs: number;
|
|
183
|
+
}
|
|
184
|
+
/** One pass over a finished tree; interleaving fsync with writes costs seconds. */
|
|
185
|
+
export declare function syncTree(root: string, hostFs?: SyncTreeHostFs): SyncTreeResult;
|
|
186
|
+
/** fsyncs a directory's entries; false where the platform refuses (Windows). */
|
|
187
|
+
export declare function syncDirectory(dir: string, hostFs?: SyncTreeHostFs): boolean;
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/pglite/snapshot-reader.d.ts
|
|
190
|
+
export declare const SNAPSHOT_FILE_NAME = "snapshot.bin";
|
|
191
|
+
interface ExtractSnapshotOptions {
|
|
192
|
+
chunkSize?: number;
|
|
193
|
+
/** Default true: one fsync pass over the tree after the last write. */
|
|
194
|
+
sync?: boolean;
|
|
195
|
+
hostFs?: SyncTreeHostFs;
|
|
196
|
+
}
|
|
197
|
+
interface ExtractedSnapshot {
|
|
198
|
+
pgVersionMajor: number;
|
|
199
|
+
/** `global/pg_control` bytes; absent only in synthetic trees. */
|
|
200
|
+
pgControl?: Buffer;
|
|
201
|
+
/** Entries written to disk; skipped entries are not counted. */
|
|
202
|
+
entries: number;
|
|
203
|
+
/** Size of the snapshot file. */
|
|
204
|
+
bytes: number;
|
|
205
|
+
}
|
|
206
|
+
/** Unpacks a snapshot into the existing `outDir`. */
|
|
207
|
+
export declare function extractSnapshot(snapshotPath: string, outDir: string, options?: ExtractSnapshotOptions): Promise<ExtractedSnapshot>;
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/pglite/convert-snapshot-dir.d.ts
|
|
210
|
+
interface VerifyHandle {
|
|
211
|
+
query<T>(sql: string): Promise<{
|
|
212
|
+
rows: T[];
|
|
213
|
+
}>;
|
|
214
|
+
close(): Promise<void>;
|
|
215
|
+
}
|
|
216
|
+
type ConversionStep = "extract" | "verify" | "renameOld" | "renameNew" | "removeOld";
|
|
217
|
+
interface ConversionDeps {
|
|
218
|
+
/** Opens `dataDir` with the stock NodeFS of the PGlite module for `major`. */
|
|
219
|
+
openForVerify: (major: number, dataDir: string) => Promise<VerifyHandle>;
|
|
220
|
+
logger: ILogger;
|
|
221
|
+
/** Test hook: throw after a named step to simulate a crash there. */
|
|
222
|
+
afterStep?: (step: ConversionStep) => void | Promise<void>;
|
|
223
|
+
hostFs?: SyncTreeHostFs;
|
|
224
|
+
}
|
|
225
|
+
/** Settles the debris of an interrupted conversion; runs before it at boot. */
|
|
226
|
+
export declare function recoverConversion(dir: string, deps: ConversionDeps): Promise<void>;
|
|
227
|
+
/** Extracts into `.converting`, verifies by opening it, swaps through `.old`. */
|
|
228
|
+
export declare function convertSnapshotDir(dir: string, deps: ConversionDeps): Promise<"converted" | "none">;
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/pglite/preflight.d.ts
|
|
231
|
+
/** PG major of the pinned @electric-sql/pglite; it exports none, so the test checks initdb. */
|
|
232
|
+
export declare const CURRENT_PGLITE_MAJOR = 17;
|
|
233
|
+
/** `openForVerify` over the loaded PGlite module only. */
|
|
234
|
+
export declare function openCurrentPgliteForVerify(major: number, dataDir: string): Promise<VerifyHandle>;
|
|
235
|
+
/** Converts a snapshot store and clears the files a previous run leaves behind. */
|
|
236
|
+
export declare function preparePgliteDataDir(dir: string, deps: ConversionDeps): Promise<void>;
|
|
237
|
+
/** PGlite leaves `postmaster.pid` after every close and `pg_wal/xlogtemp.*` after some. */
|
|
238
|
+
export declare function removeStalePgliteFiles(dir: string, logger: Pick<ILogger, "debug">): Promise<void>;
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/pglite/wasm-wrapper-tiering.d.ts
|
|
241
|
+
export declare const WASM_WRAPPER_TIERING_FLAG = "--wasm-wrapper-tiering-budget=1000000000";
|
|
242
|
+
/** Node 24 V8 double-frees tiered wasm wrappers as instances die (#66366). */
|
|
243
|
+
export declare function disableWasmWrapperTiering(): boolean;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/pglite/worker/protocol.d.ts
|
|
246
|
+
/**
|
|
247
|
+
* Wire protocol between a {@link ThreadedPGlite} stand-in on the main thread
|
|
248
|
+
* and the worker thread that owns one PGlite store.
|
|
249
|
+
*
|
|
250
|
+
* Every payload is structured-cloned, so it holds data only: functions such as
|
|
251
|
+
* row parsers are named by preset and built inside the worker.
|
|
252
|
+
*/
|
|
253
|
+
/** Module specifiers the worker imports PGlite and its NodeFS from. */
|
|
254
|
+
type PGliteModuleSpec = {
|
|
255
|
+
/** Specifier or file URL of the PGlite package entry, e.g. `@electric-sql/pglite`. */
|
|
256
|
+
pglite: string;
|
|
257
|
+
/** Specifier or file URL of the matching NodeFS entry, e.g. `@electric-sql/pglite/nodefs`. */
|
|
258
|
+
nodefs: string;
|
|
259
|
+
};
|
|
260
|
+
export declare const CURRENT_PGLITE_MODULE: PGliteModuleSpec;
|
|
261
|
+
/** Row parser sets the worker knows how to build. */
|
|
262
|
+
type PGliteParserPreset = "none" | "utc-timestamps";
|
|
263
|
+
/** DurableNodeFs settings; see `DurableNodeFsOptions`. */
|
|
264
|
+
type PGliteWorkerDurableFsOptions = {
|
|
265
|
+
fsync: boolean;
|
|
266
|
+
/** Undefined keeps the DurableNodeFs default (5 min); 0 disables. */
|
|
267
|
+
maintenanceIntervalMs?: number;
|
|
268
|
+
/** Undefined keeps the DurableNodeFs default (256 MB); 0 disables. */
|
|
269
|
+
vacuumFullAboveBytes?: number;
|
|
270
|
+
/** Undefined keeps the DurableNodeFs default (60 s); 0 runs VACUUM FULL on the first pass. */
|
|
271
|
+
vacuumFullQuietMs?: number;
|
|
272
|
+
/** Undefined keeps the DurableNodeFs default (0: the quiet window only); a deadline in ms forces the run past it. */
|
|
273
|
+
vacuumFullMaxDeferMs?: number;
|
|
274
|
+
/** Undefined keeps the DurableNodeFs default (1 s). */
|
|
275
|
+
rewriteQuietMs?: number;
|
|
276
|
+
};
|
|
277
|
+
/** What the worker opens. */
|
|
278
|
+
type PGliteWorkerStoreOptions = {
|
|
279
|
+
/** Names the store in logs and errors, e.g. `read-storage`. */
|
|
280
|
+
label: string;
|
|
281
|
+
/** PGlite data dir; null opens an in-memory store. */
|
|
282
|
+
dataDir: string | null;
|
|
283
|
+
module: PGliteModuleSpec;
|
|
284
|
+
/** DurableNodeFs over `dataDir`; null uses the module's stock NodeFS. Ignored in memory. */
|
|
285
|
+
durableFs: PGliteWorkerDurableFsOptions | null;
|
|
286
|
+
parsers: PGliteParserPreset;
|
|
287
|
+
};
|
|
288
|
+
type PGliteErrorInfo = {
|
|
289
|
+
name: string;
|
|
290
|
+
message: string;
|
|
291
|
+
stack?: string;
|
|
292
|
+
cause?: PGliteErrorInfo;
|
|
293
|
+
/** Postgres error fields, copied when present. */
|
|
294
|
+
fields: Record<string, string>;
|
|
295
|
+
};
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/pglite/worker/error-info.d.ts
|
|
298
|
+
/** Flattens an error and its cause chain into a structured-clonable shape. */
|
|
299
|
+
export declare function toPGliteErrorInfo(err: unknown, depth?: number): PGliteErrorInfo;
|
|
300
|
+
/** Rebuilds an `Error` carrying the original name, stack, Postgres fields and cause chain. */
|
|
301
|
+
export declare function fromPGliteErrorInfo(info: PGliteErrorInfo): Error;
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/pglite/worker/errors.d.ts
|
|
304
|
+
/** Base class for failures of the worker itself, as opposed to SQL errors. */
|
|
305
|
+
export declare class PGliteWorkerError extends Error {
|
|
306
|
+
readonly label: string;
|
|
307
|
+
constructor(label: string, message: string, options?: {
|
|
308
|
+
cause?: unknown;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/** The worker could not open its store; every call on the stand-in fails with this. */
|
|
312
|
+
export declare class PGliteWorkerInitError extends PGliteWorkerError {
|
|
313
|
+
constructor(label: string, options?: {
|
|
314
|
+
cause?: unknown;
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/** The worker thread exited (crash, terminate, out of memory) before answering. */
|
|
318
|
+
export declare class PGliteWorkerExitedError extends PGliteWorkerError {
|
|
319
|
+
readonly exitCode: number;
|
|
320
|
+
constructor(label: string, exitCode: number, options?: {
|
|
321
|
+
cause?: unknown;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/** A call was made after `close()` started. */
|
|
325
|
+
export declare class PGliteWorkerClosedError extends PGliteWorkerError {
|
|
326
|
+
constructor(label: string);
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/pglite/worker/threaded-pglite.d.ts
|
|
330
|
+
export declare const DEFAULT_PGLITE_WORKER_MEMORY_MB = 1024;
|
|
331
|
+
export declare const DEFAULT_PGLITE_WORKER_CLOSE_GRACE_MS = 60000;
|
|
332
|
+
type ThreadedPGliteOptions = {
|
|
333
|
+
store: PGliteWorkerStoreOptions;
|
|
334
|
+
/** Caps the worker's JS heap; defaults to {@link resolvePgliteWorkerMemoryMb}. WebAssembly memory is outside it. */
|
|
335
|
+
memoryLimitMb?: number;
|
|
336
|
+
/** The worker script; defaults to the built entry next to this module. Tests pass a tsx bootstrap. */
|
|
337
|
+
workerScript?: string | URL;
|
|
338
|
+
/** Bound on PGlite's own close (its shutdown checkpoint) before the thread is terminated. */
|
|
339
|
+
closeGraceMs?: number;
|
|
340
|
+
logger?: ILogger;
|
|
341
|
+
};
|
|
342
|
+
/** Called once, when the worker reports that the wasm runtime aborted. */
|
|
343
|
+
type PGliteAbortListener = (reason: string) => void;
|
|
344
|
+
/** Called once, when the worker thread is gone; `error` is null after a clean close. */
|
|
345
|
+
type PGliteExitListener = (error: Error | null) => void;
|
|
346
|
+
/** `PH_PGLITE_WORKER_MEMORY_MB`, else {@link DEFAULT_PGLITE_WORKER_MEMORY_MB}. */
|
|
347
|
+
export declare function resolvePgliteWorkerMemoryMb(env: Record<string, string | undefined>): number;
|
|
348
|
+
/**
|
|
349
|
+
* Main-thread stand-in for a PGlite instance whose store lives in a worker
|
|
350
|
+
* thread. It has the surface knex-pglite, kysely-pglite-dialect and
|
|
351
|
+
* `HardenedPGliteDialect` use: `waitReady`, `query`, `exec`, a synchronous
|
|
352
|
+
* `isInTransaction()`, `closed` and `close()`.
|
|
353
|
+
*
|
|
354
|
+
* Construction is synchronous and starts the worker; calls made before the
|
|
355
|
+
* worker is ready are queued behind its open. The worker runs requests one at
|
|
356
|
+
* a time in arrival order, and every answer carries the transaction status.
|
|
357
|
+
* The instance is a plain extensible object, since knex stores its own
|
|
358
|
+
* bookkeeping on the connection.
|
|
359
|
+
*/
|
|
360
|
+
export declare class ThreadedPGlite implements PGliteLike, IStoreMaintenance {
|
|
361
|
+
readonly label: string;
|
|
362
|
+
/** Settles once the worker has opened the store; rejects with {@link PGliteWorkerInitError}. */
|
|
363
|
+
readonly waitReady: Promise<void>;
|
|
364
|
+
private readonly worker;
|
|
365
|
+
private readonly logger;
|
|
366
|
+
private readonly closeGraceMs;
|
|
367
|
+
private readonly pending;
|
|
368
|
+
/** The reservation an `admit` run is executing under, carried through its async calls. */
|
|
369
|
+
private readonly admission;
|
|
370
|
+
private readonly abortListeners;
|
|
371
|
+
private readonly exitListeners;
|
|
372
|
+
private nextId;
|
|
373
|
+
private phase;
|
|
374
|
+
private inTransaction;
|
|
375
|
+
private terminalError;
|
|
376
|
+
private workerError;
|
|
377
|
+
private abortReason;
|
|
378
|
+
private closePromise;
|
|
379
|
+
private readonly forgetTelemetry;
|
|
380
|
+
constructor(options: ThreadedPGliteOptions);
|
|
381
|
+
/** JS heap of the worker and the WASM linear memory, which only grows. */
|
|
382
|
+
memoryStats(): Promise<WorkerMemorySample>;
|
|
383
|
+
/** True once the store is open and until close starts. */
|
|
384
|
+
get ready(): boolean;
|
|
385
|
+
/** True once close has started or the worker is gone. */
|
|
386
|
+
get closed(): boolean;
|
|
387
|
+
/** The reason the worker reported for a wasm abort, or null. */
|
|
388
|
+
get aborted(): string | null;
|
|
389
|
+
/** The limits the worker thread runs under (empty once it has exited). */
|
|
390
|
+
get resourceLimits(): ResourceLimits;
|
|
391
|
+
/** The worker's thread id, for diagnostics. */
|
|
392
|
+
get threadId(): number;
|
|
393
|
+
query<T = Record<string, unknown>>(sql: string, params?: unknown[], options?: QueryOptions): Promise<Results<T>>;
|
|
394
|
+
exec(sql: string, options?: QueryOptions): Promise<Results[]>;
|
|
395
|
+
/**
|
|
396
|
+
* `HardenedPGliteDialect`'s admission hook: `run` starts only once the worker
|
|
397
|
+
* can run its statements at once, with nothing queued ahead and no
|
|
398
|
+
* maintenance pass in progress, so the dialect's statement deadline (which
|
|
399
|
+
* starts inside `run`) never counts time spent waiting behind other work.
|
|
400
|
+
* Statements `run` issues bypass the queue until it settles; everything
|
|
401
|
+
* else waits behind them.
|
|
402
|
+
*/
|
|
403
|
+
admit<T>(run: () => Promise<T>): Promise<T>;
|
|
404
|
+
/** Rewrites one table through the store's maintenance inside the worker. */
|
|
405
|
+
rewriteTable(request: TableRewriteRequest): Promise<TableRewriteResult>;
|
|
406
|
+
/** The status after the most recently answered request, as PGlite reported it. */
|
|
407
|
+
isInTransaction(): boolean;
|
|
408
|
+
/** Closes PGlite inside the worker (its shutdown checkpoint), then terminates the thread. */
|
|
409
|
+
close(): Promise<void>;
|
|
410
|
+
/** Stops the thread at once, without PGlite's close; pending calls reject. */
|
|
411
|
+
terminate(): Promise<void>;
|
|
412
|
+
onAbort(listener: PGliteAbortListener): () => void;
|
|
413
|
+
onExit(listener: PGliteExitListener): () => void;
|
|
414
|
+
private closeWorker;
|
|
415
|
+
private currentAdmission;
|
|
416
|
+
private release;
|
|
417
|
+
private request;
|
|
418
|
+
private handleMessage;
|
|
419
|
+
private settle;
|
|
420
|
+
private settleError;
|
|
421
|
+
private handleAbort;
|
|
422
|
+
private handleLog;
|
|
423
|
+
private handleWorkerError;
|
|
424
|
+
private handleExit;
|
|
425
|
+
/** Records a fatal error and stops the thread; the exit rejects what is pending. */
|
|
426
|
+
private fail;
|
|
427
|
+
private rejectPending;
|
|
428
|
+
}
|
|
429
|
+
/** Absolute path of the worker script for `new Worker(...)`; null when none can run here. */
|
|
430
|
+
export declare const pgliteWorkerEntryPath: string | null;
|
|
431
|
+
//#endregion
|
|
432
|
+
export { type ConversionDeps, type ConversionStep, type DurableNodeFs, type DurableNodeFsOptions, type ExtractSnapshotOptions, type ExtractedSnapshot, type MaintenanceGate, type MaintenanceLogger, type MaintenanceOptions, type MaintenanceOutcome, type NodeFsClass, PGLITE_UTC_PARSERS, type PGliteAbortListener, type PGliteErrorInfo, type PGliteExitListener, type PGliteLike, type PGliteModuleSpec, type PGliteParserPreset, type PGliteWorkerDurableFsOptions, type PGliteWorkerStoreOptions, type PgliteMaintenanceSettings, type PgliteVacuumFullMode, type SyncTreeHostFs, type SyncTreeResult, type ThreadedPGliteOptions, type VerifyHandle };
|
|
433
|
+
export {};
|
|
434
|
+
//# sourceMappingURL=pglite-node.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pglite-node.d.mts","names":[],"sources":["../../../src/pglite/maintenance.ts","../../../src/pglite/durable-node-fs.ts","../../../src/pglite/sync-tree.ts","../../../src/pglite/snapshot-reader.ts","../../../src/pglite/convert-snapshot-dir.ts","../../../src/pglite/preflight.ts","../../../src/pglite/wasm-wrapper-tiering.ts","../../../src/pglite/worker/protocol.ts","../../../src/pglite/worker/error-info.ts","../../../src/pglite/worker/errors.ts","../../../src/pglite/worker/threaded-pglite.ts"],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { _ as PGLITE_UTC_PARSERS, a as resolvePgliteMaintenance, c as DEFAULT_MAINTENANCE_INTERVAL_MS, d as DEFAULT_VACUUM_FULL_ABOVE_BYTES, f as DEFAULT_VACUUM_FULL_MAX_DEFER_MS, g as maintenanceOf, h as PgliteMaintenance, i as resolvePgliteFsync, l as DEFAULT_REWRITE_MAX_WAIT_MS, m as FORCED_VACUUM_FULL_MAX_DEFER_MS, n as toPGliteErrorInfo, o as syncDirectory, p as DEFAULT_VACUUM_FULL_QUIET_MS, r as createDurableNodeFs, s as syncTree, t as fromPGliteErrorInfo, u as DEFAULT_REWRITE_QUIET_MS } from "../../error-info-Cr6oQACe.mjs";
|
|
2
|
+
import { _ as convertSnapshotDir, a as resolvePgliteWorkerMemoryMb, b as extractSnapshot, c as PGliteWorkerError, d as WASM_WRAPPER_TIERING_FLAG, f as disableWasmWrapperTiering, g as removeStalePgliteFiles, h as preparePgliteDataDir, i as pgliteWorkerEntryPath, l as PGliteWorkerExitedError, m as openCurrentPgliteForVerify, n as DEFAULT_PGLITE_WORKER_MEMORY_MB, o as CURRENT_PGLITE_MODULE, p as CURRENT_PGLITE_MAJOR, r as ThreadedPGlite, s as PGliteWorkerClosedError, t as DEFAULT_PGLITE_WORKER_CLOSE_GRACE_MS, u as PGliteWorkerInitError, v as recoverConversion, y as SNAPSHOT_FILE_NAME } from "../../pglite-node-CcX2YT-l.mjs";
|
|
3
|
+
export { CURRENT_PGLITE_MAJOR, CURRENT_PGLITE_MODULE, DEFAULT_MAINTENANCE_INTERVAL_MS, DEFAULT_PGLITE_WORKER_CLOSE_GRACE_MS, DEFAULT_PGLITE_WORKER_MEMORY_MB, DEFAULT_REWRITE_MAX_WAIT_MS, DEFAULT_REWRITE_QUIET_MS, DEFAULT_VACUUM_FULL_ABOVE_BYTES, DEFAULT_VACUUM_FULL_MAX_DEFER_MS, DEFAULT_VACUUM_FULL_QUIET_MS, FORCED_VACUUM_FULL_MAX_DEFER_MS, PGLITE_UTC_PARSERS, PGliteWorkerClosedError, PGliteWorkerError, PGliteWorkerExitedError, PGliteWorkerInitError, PgliteMaintenance, SNAPSHOT_FILE_NAME, ThreadedPGlite, WASM_WRAPPER_TIERING_FLAG, convertSnapshotDir, createDurableNodeFs, disableWasmWrapperTiering, extractSnapshot, fromPGliteErrorInfo, maintenanceOf, openCurrentPgliteForVerify, pgliteWorkerEntryPath, preparePgliteDataDir, recoverConversion, removeStalePgliteFiles, resolvePgliteFsync, resolvePgliteMaintenance, resolvePgliteWorkerMemoryMb, syncDirectory, syncTree, toPGliteErrorInfo };
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="afdaa565-b941-5b93-a8c8-f1f4270baa52")}catch(e){}}();
|
|
5
|
+
//# debugId=afdaa565-b941-5b93-a8c8-f1f4270baa52
|