@powerhousedao/reactor-api 6.2.3-dev.74 → 6.2.3-dev.76
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/{base-document-models-D3aAUB7E.mjs → base-document-models-BGt__Ctn.mjs} +47 -3
- package/dist/{base-document-models-D3aAUB7E.mjs.map → base-document-models-BGt__Ctn.mjs.map} +1 -1
- package/dist/error-info-CCQcLAcW.mjs +424 -0
- package/dist/error-info-CCQcLAcW.mjs.map +1 -0
- package/dist/index.d.mts +54 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +154 -12
- package/dist/index.mjs.map +1 -1
- package/dist/{package-subgraph-check-C0hGBt4N.mjs → package-subgraph-check-C5S8yvBI.mjs} +4 -4
- package/dist/{package-subgraph-check-C0hGBt4N.mjs.map → package-subgraph-check-C5S8yvBI.mjs.map} +1 -1
- 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-BOFT_yUj.mjs +702 -0
- package/dist/pglite-node-BOFT_yUj.mjs.map +1 -0
- package/dist/src/graphql/subgraph-types.mjs +1 -1
- package/dist/src/packages/vite-loader.d.mts +7 -0
- package/dist/src/packages/vite-loader.d.mts.map +1 -1
- package/dist/src/packages/vite-loader.mjs +21 -4
- package/dist/src/packages/vite-loader.mjs.map +1 -1
- package/dist/src/pglite/pglite-node.d.mts +227 -2
- package/dist/src/pglite/pglite-node.d.mts.map +1 -1
- package/dist/src/pglite/pglite-node.mjs +5 -4
- package/dist/src/pglite/worker/entry.d.mts +2 -0
- package/dist/src/pglite/worker/entry.mjs +251 -0
- package/dist/src/pglite/worker/entry.mjs.map +1 -0
- package/package.json +13 -13
- package/dist/pglite-node-C-UQXrjU.mjs +0 -576
- package/dist/pglite-node-C-UQXrjU.mjs.map +0 -1
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
|
|
2
|
+
!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]="ba1434c3-ef59-57f0-ae3b-f32e4a59c605")}catch(e){}}();
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import nodeFs, { promises } from "node:fs";
|
|
5
|
+
import { protocol } from "@electric-sql/pglite";
|
|
6
|
+
import { ERRNO_CODES } from "@electric-sql/pglite/basefs";
|
|
7
|
+
//#region src/pglite/parsers.ts
|
|
8
|
+
const PGLITE_UTC_PARSERS = { 1114: (value) => /* @__PURE__ */ new Date(`${value.replace(" ", "T")}Z`) };
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/pglite/maintenance.ts
|
|
11
|
+
const DEFAULT_MAINTENANCE_INTERVAL_MS = 3e5;
|
|
12
|
+
const DEFAULT_VACUUM_FULL_ABOVE_BYTES = 268435456;
|
|
13
|
+
const DEFAULT_VACUUM_FULL_QUIET_MS = 6e4;
|
|
14
|
+
const MAINTENANCE_RETRY_MS = 1e3;
|
|
15
|
+
var PgliteMaintenance = class {
|
|
16
|
+
intervalMs;
|
|
17
|
+
vacuumFullAboveBytes;
|
|
18
|
+
vacuumFullQuietMs;
|
|
19
|
+
vacuumFullMaxDeferMs;
|
|
20
|
+
gate;
|
|
21
|
+
logger;
|
|
22
|
+
now;
|
|
23
|
+
pg;
|
|
24
|
+
label = "";
|
|
25
|
+
closing = false;
|
|
26
|
+
syncsSinceMaintenance = 0;
|
|
27
|
+
vacuumFullPending = false;
|
|
28
|
+
timer;
|
|
29
|
+
inFlight;
|
|
30
|
+
active = false;
|
|
31
|
+
deferralLogged = false;
|
|
32
|
+
lastSyncAt = 0;
|
|
33
|
+
openedAt = 0;
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
this.intervalMs = Math.max(0, options.intervalMs ?? 3e5);
|
|
36
|
+
this.vacuumFullAboveBytes = Math.max(0, options.vacuumFullAboveBytes ?? 268435456);
|
|
37
|
+
this.vacuumFullQuietMs = Math.max(0, options.vacuumFullQuietMs ?? 6e4);
|
|
38
|
+
this.vacuumFullMaxDeferMs = Math.max(0, options.vacuumFullMaxDeferMs ?? 18e5);
|
|
39
|
+
this.gate = options.gate;
|
|
40
|
+
this.logger = options.logger;
|
|
41
|
+
this.now = options.now ?? Date.now;
|
|
42
|
+
}
|
|
43
|
+
get scheduled() {
|
|
44
|
+
return this.timer !== void 0;
|
|
45
|
+
}
|
|
46
|
+
get running() {
|
|
47
|
+
return this.inFlight !== void 0;
|
|
48
|
+
}
|
|
49
|
+
start(pg, label, baseBytes) {
|
|
50
|
+
this.pg = pg;
|
|
51
|
+
this.label = label;
|
|
52
|
+
this.vacuumFullPending = this.vacuumFullAboveBytes > 0 && baseBytes > this.vacuumFullAboveBytes;
|
|
53
|
+
this.lastSyncAt = this.now();
|
|
54
|
+
this.openedAt = this.lastSyncAt;
|
|
55
|
+
this.schedule(this.intervalMs);
|
|
56
|
+
}
|
|
57
|
+
noteSync() {
|
|
58
|
+
this.syncsSinceMaintenance++;
|
|
59
|
+
this.lastSyncAt = this.now();
|
|
60
|
+
}
|
|
61
|
+
/** Waits for a pass that has started; one still queued at the gate is left to skip itself. */
|
|
62
|
+
async stop() {
|
|
63
|
+
this.closing = true;
|
|
64
|
+
this.cancel();
|
|
65
|
+
if (this.active) await this.inFlight;
|
|
66
|
+
}
|
|
67
|
+
async run() {
|
|
68
|
+
if (this.gate) return this.gate(() => this.runNow());
|
|
69
|
+
return this.runNow();
|
|
70
|
+
}
|
|
71
|
+
async runNow() {
|
|
72
|
+
this.active = true;
|
|
73
|
+
try {
|
|
74
|
+
return await this.pass();
|
|
75
|
+
} finally {
|
|
76
|
+
this.active = false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async pass() {
|
|
80
|
+
const pg = this.pg;
|
|
81
|
+
if (this.closing || !pg?.ready) return "not-ready";
|
|
82
|
+
const isReady = () => pg.ready && !this.closing;
|
|
83
|
+
const now = this.now();
|
|
84
|
+
const overdue = this.vacuumFullMaxDeferMs > 0 && now - this.openedAt >= this.vacuumFullMaxDeferMs;
|
|
85
|
+
const full = this.vacuumFullPending && (now - this.lastSyncAt >= this.vacuumFullQuietMs || overdue);
|
|
86
|
+
if (this.vacuumFullPending && !full && !this.deferralLogged) {
|
|
87
|
+
this.deferralLogged = true;
|
|
88
|
+
this.logger?.warn(`DurableNodeFs: ${this.label}/base exceeds ${this.vacuumFullAboveBytes} bytes; VACUUM FULL waits until the store has had no writes for ${this.vacuumFullQuietMs} ms${this.vacuumFullMaxDeferMs > 0 ? `, or at most ${this.vacuumFullMaxDeferMs} ms from open` : ""}`);
|
|
89
|
+
}
|
|
90
|
+
if (!full && this.syncsSinceMaintenance === 0) return "idle";
|
|
91
|
+
let outcome;
|
|
92
|
+
try {
|
|
93
|
+
outcome = await pg._runExclusiveQuery(async () => {
|
|
94
|
+
if (!isReady()) return "not-ready";
|
|
95
|
+
const { messages } = await pg.execProtocol(protocol.serialize.query(""), { syncToFs: false });
|
|
96
|
+
if (transactionStatus(messages) !== "I") return "in-transaction";
|
|
97
|
+
if (full) this.logger?.warn(`DurableNodeFs: ${this.label}/base exceeds ${this.vacuumFullAboveBytes} bytes; running VACUUM FULL`);
|
|
98
|
+
for (const statement of [full ? "VACUUM FULL" : "VACUUM", "CHECKPOINT"]) {
|
|
99
|
+
if (!isReady()) return "not-ready";
|
|
100
|
+
await pg.execProtocol(protocol.serialize.query(statement), { syncToFs: false });
|
|
101
|
+
}
|
|
102
|
+
return full ? "vacuum-full" : "vacuum";
|
|
103
|
+
});
|
|
104
|
+
} catch (err) {
|
|
105
|
+
this.logger?.warn(`DurableNodeFs maintenance failed: ${errorMessage(err)}`);
|
|
106
|
+
return "failed";
|
|
107
|
+
}
|
|
108
|
+
if (outcome !== "vacuum" && outcome !== "vacuum-full") return outcome;
|
|
109
|
+
this.syncsSinceMaintenance = 0;
|
|
110
|
+
if (full) this.vacuumFullPending = false;
|
|
111
|
+
return outcome;
|
|
112
|
+
}
|
|
113
|
+
schedule(delayMs) {
|
|
114
|
+
if (this.intervalMs === 0 || this.closing) return;
|
|
115
|
+
this.timer = setTimeout(() => {
|
|
116
|
+
this.timer = void 0;
|
|
117
|
+
this.inFlight = this.run().then((outcome) => {
|
|
118
|
+
this.schedule(outcome === "in-transaction" ? Math.min(MAINTENANCE_RETRY_MS, this.intervalMs) : this.intervalMs);
|
|
119
|
+
return outcome;
|
|
120
|
+
}).finally(() => {
|
|
121
|
+
this.inFlight = void 0;
|
|
122
|
+
});
|
|
123
|
+
}, delayMs);
|
|
124
|
+
this.timer.unref();
|
|
125
|
+
}
|
|
126
|
+
cancel() {
|
|
127
|
+
if (!this.timer) return;
|
|
128
|
+
clearTimeout(this.timer);
|
|
129
|
+
this.timer = void 0;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
/** Total size of the regular files under `dir`; 0 when `dir` is missing. */
|
|
133
|
+
async function dirBytes(dir) {
|
|
134
|
+
let entries;
|
|
135
|
+
try {
|
|
136
|
+
entries = await promises.readdir(dir, { withFileTypes: true });
|
|
137
|
+
} catch (err) {
|
|
138
|
+
if (err.code === "ENOENT") return 0;
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
let total = 0;
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
const full = path.join(dir, entry.name);
|
|
144
|
+
if (entry.isDirectory()) total += await dirBytes(full);
|
|
145
|
+
else if (entry.isFile()) total += (await promises.stat(full)).size;
|
|
146
|
+
}
|
|
147
|
+
return total;
|
|
148
|
+
}
|
|
149
|
+
function transactionStatus(messages) {
|
|
150
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
151
|
+
const m = messages[i];
|
|
152
|
+
if (m.name === "readyForQuery") return m.status;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function errorMessage(err) {
|
|
156
|
+
return err instanceof Error ? err.message : String(err);
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/pglite/sync-tree.ts
|
|
160
|
+
/** One pass over a finished tree; interleaving fsync with writes costs seconds. */
|
|
161
|
+
function syncTree(root, hostFs = nodeFs) {
|
|
162
|
+
const result = {
|
|
163
|
+
files: 0,
|
|
164
|
+
dirs: 0
|
|
165
|
+
};
|
|
166
|
+
const pending = [path.resolve(root)];
|
|
167
|
+
while (pending.length > 0) {
|
|
168
|
+
const dir = pending.pop();
|
|
169
|
+
for (const entry of nodeFs.readdirSync(dir, { withFileTypes: true })) {
|
|
170
|
+
const full = path.join(dir, entry.name);
|
|
171
|
+
if (entry.isDirectory()) pending.push(full);
|
|
172
|
+
else if (entry.isFile()) {
|
|
173
|
+
syncFile(full, hostFs);
|
|
174
|
+
result.files++;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
syncDirectory(dir, hostFs);
|
|
178
|
+
result.dirs++;
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
function syncFile(file, hostFs) {
|
|
183
|
+
const fd = nodeFs.openSync(file, "r+");
|
|
184
|
+
try {
|
|
185
|
+
hostFs.fsyncSync(fd);
|
|
186
|
+
} finally {
|
|
187
|
+
nodeFs.closeSync(fd);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** fsyncs a directory's entries; false where the platform refuses (Windows). */
|
|
191
|
+
function syncDirectory(dir, hostFs = nodeFs) {
|
|
192
|
+
let fd;
|
|
193
|
+
try {
|
|
194
|
+
fd = nodeFs.openSync(dir, "r");
|
|
195
|
+
} catch {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
hostFs.fsyncSync(fd);
|
|
200
|
+
return true;
|
|
201
|
+
} catch {
|
|
202
|
+
return false;
|
|
203
|
+
} finally {
|
|
204
|
+
nodeFs.closeSync(fd);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/pglite/durable-node-fs.ts
|
|
209
|
+
const EIO = 29;
|
|
210
|
+
function resolvePgliteFsync(env) {
|
|
211
|
+
return env.PH_PGLITE_FSYNC !== "0";
|
|
212
|
+
}
|
|
213
|
+
function isReadOnly(stream) {
|
|
214
|
+
return stream.flags !== void 0 && (stream.flags & 3) === 0;
|
|
215
|
+
}
|
|
216
|
+
const WASM_ENTRY_POINTS = [
|
|
217
|
+
"_interactive_one",
|
|
218
|
+
"_interactive_write",
|
|
219
|
+
"_pgl_backend",
|
|
220
|
+
"_pgl_initdb",
|
|
221
|
+
"_pgl_shutdown"
|
|
222
|
+
];
|
|
223
|
+
function poisonAfterAbort(mod, what) {
|
|
224
|
+
if (!mod) return;
|
|
225
|
+
const message = `PGlite aborted: ${String(what) || "wasm runtime abort"}`;
|
|
226
|
+
for (const name of WASM_ENTRY_POINTS) {
|
|
227
|
+
if (typeof mod[name] !== "function") continue;
|
|
228
|
+
mod[name] = () => {
|
|
229
|
+
throw new Error(message);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
mod.FS.quit();
|
|
234
|
+
} catch {}
|
|
235
|
+
}
|
|
236
|
+
/** Built over the passed-in class so PG16 dirs on `pglite-legacy-02` get the same behaviour. */
|
|
237
|
+
function createDurableNodeFs(Base, dataDir, options = {}) {
|
|
238
|
+
const fsync = options.fsync ?? true;
|
|
239
|
+
const hostFs = options.hostFs ?? nodeFs;
|
|
240
|
+
const logger = options.logger;
|
|
241
|
+
const onAbort = options.onAbort;
|
|
242
|
+
const resolvedDir = path.resolve(dataDir);
|
|
243
|
+
const maintenance = new PgliteMaintenance({
|
|
244
|
+
intervalMs: options.maintenanceIntervalMs,
|
|
245
|
+
vacuumFullAboveBytes: options.vacuumFullAboveBytes,
|
|
246
|
+
vacuumFullQuietMs: options.vacuumFullQuietMs,
|
|
247
|
+
vacuumFullMaxDeferMs: options.vacuumFullMaxDeferMs,
|
|
248
|
+
gate: options.maintenanceGate,
|
|
249
|
+
now: options.now,
|
|
250
|
+
logger
|
|
251
|
+
});
|
|
252
|
+
class Durable extends Base {
|
|
253
|
+
maintenance = maintenance;
|
|
254
|
+
mod;
|
|
255
|
+
hostSyncs = fsync;
|
|
256
|
+
freshInit = false;
|
|
257
|
+
async init(pg, opts) {
|
|
258
|
+
const { emscriptenOpts: base } = await super.init(pg, opts);
|
|
259
|
+
const baseOpts = base;
|
|
260
|
+
const inner = baseOpts.instantiateWasm;
|
|
261
|
+
if (fsync && !inner) throw new Error("PGlite did not supply instantiateWasm");
|
|
262
|
+
return { emscriptenOpts: {
|
|
263
|
+
...baseOpts,
|
|
264
|
+
onAbort: (what) => {
|
|
265
|
+
poisonAfterAbort(this.mod, what);
|
|
266
|
+
maintenance.stop();
|
|
267
|
+
onAbort?.(what);
|
|
268
|
+
},
|
|
269
|
+
preRun: [...baseOpts.preRun ?? [], (mod) => {
|
|
270
|
+
this.mod = mod;
|
|
271
|
+
if (!fsync) return;
|
|
272
|
+
mod.FS.filesystems.NODEFS.stream_ops.fsync = (stream) => this.fsyncStream(stream);
|
|
273
|
+
}],
|
|
274
|
+
instantiateWasm: fsync && inner ? (imports, done) => {
|
|
275
|
+
const original = imports.env.__syscall_fdatasync;
|
|
276
|
+
const replacement = (fd) => this.fdatasync(fd);
|
|
277
|
+
replacement.sig = original?.sig;
|
|
278
|
+
imports.env.__syscall_fdatasync = replacement;
|
|
279
|
+
return inner(imports, done);
|
|
280
|
+
} : inner
|
|
281
|
+
} };
|
|
282
|
+
}
|
|
283
|
+
async initialSyncFs() {
|
|
284
|
+
await super.initialSyncFs();
|
|
285
|
+
this.freshInit = fsync && !nodeFs.existsSync(path.join(resolvedDir, "PG_VERSION"));
|
|
286
|
+
if (this.freshInit) this.hostSyncs = false;
|
|
287
|
+
const baseBytes = await dirBytes(path.join(resolvedDir, "base"));
|
|
288
|
+
maintenance.start(this.pg, resolvedDir, baseBytes);
|
|
289
|
+
}
|
|
290
|
+
async syncToFs(relaxedDurability) {
|
|
291
|
+
maintenance.noteSync();
|
|
292
|
+
await super.syncToFs(relaxedDurability);
|
|
293
|
+
if (!this.freshInit) return;
|
|
294
|
+
this.freshInit = false;
|
|
295
|
+
this.hostSyncs = true;
|
|
296
|
+
syncTree(resolvedDir, hostFs);
|
|
297
|
+
}
|
|
298
|
+
async closeFs() {
|
|
299
|
+
try {
|
|
300
|
+
await maintenance.stop();
|
|
301
|
+
} finally {
|
|
302
|
+
await super.closeFs();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
fsyncStream(stream) {
|
|
306
|
+
if (!this.hostSyncs) return 0;
|
|
307
|
+
if (typeof stream.nfd !== "number" || isReadOnly(stream)) return 0;
|
|
308
|
+
try {
|
|
309
|
+
hostFs.fsyncSync(stream.nfd);
|
|
310
|
+
} catch (err) {
|
|
311
|
+
logger?.warn(`DurableNodeFs fsync failed: ${String(err)}`);
|
|
312
|
+
return EIO;
|
|
313
|
+
}
|
|
314
|
+
return 0;
|
|
315
|
+
}
|
|
316
|
+
fdatasync(fd) {
|
|
317
|
+
if (!this.hostSyncs) return 0;
|
|
318
|
+
let stream;
|
|
319
|
+
try {
|
|
320
|
+
stream = this.mod.FS.getStreamChecked(fd);
|
|
321
|
+
} catch {
|
|
322
|
+
return -ERRNO_CODES.EBADF;
|
|
323
|
+
}
|
|
324
|
+
if (typeof stream.nfd !== "number" || isReadOnly(stream)) return 0;
|
|
325
|
+
try {
|
|
326
|
+
hostFs.fdatasyncSync(stream.nfd);
|
|
327
|
+
} catch (err) {
|
|
328
|
+
logger?.warn(`DurableNodeFs fdatasync failed: ${String(err)}`);
|
|
329
|
+
return -29;
|
|
330
|
+
}
|
|
331
|
+
return 0;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return new Durable(dataDir);
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/pglite/worker/error-info.ts
|
|
338
|
+
const MAX_STACK_LENGTH = 8192;
|
|
339
|
+
const MAX_CAUSE_DEPTH = 8;
|
|
340
|
+
/** The string fields of PGlite's `DatabaseError`, plus the query PGlite attaches. */
|
|
341
|
+
const PG_ERROR_FIELDS = [
|
|
342
|
+
"code",
|
|
343
|
+
"severity",
|
|
344
|
+
"detail",
|
|
345
|
+
"hint",
|
|
346
|
+
"position",
|
|
347
|
+
"internalPosition",
|
|
348
|
+
"internalQuery",
|
|
349
|
+
"where",
|
|
350
|
+
"schema",
|
|
351
|
+
"table",
|
|
352
|
+
"column",
|
|
353
|
+
"dataType",
|
|
354
|
+
"constraint",
|
|
355
|
+
"file",
|
|
356
|
+
"line",
|
|
357
|
+
"routine",
|
|
358
|
+
"query"
|
|
359
|
+
];
|
|
360
|
+
/** Flattens an error and its cause chain into a structured-clonable shape. */
|
|
361
|
+
function toPGliteErrorInfo(err, depth = 0) {
|
|
362
|
+
if (depth > MAX_CAUSE_DEPTH) return {
|
|
363
|
+
name: "Error",
|
|
364
|
+
message: "cause chain truncated",
|
|
365
|
+
fields: {}
|
|
366
|
+
};
|
|
367
|
+
if (!(err instanceof Error)) return {
|
|
368
|
+
name: "Error",
|
|
369
|
+
message: describe(err),
|
|
370
|
+
fields: {}
|
|
371
|
+
};
|
|
372
|
+
const info = {
|
|
373
|
+
name: err.name || "Error",
|
|
374
|
+
message: err.message,
|
|
375
|
+
fields: pgFieldsOf(err)
|
|
376
|
+
};
|
|
377
|
+
if (typeof err.stack === "string") info.stack = err.stack.slice(0, MAX_STACK_LENGTH);
|
|
378
|
+
if (err.cause !== void 0) info.cause = toPGliteErrorInfo(err.cause, depth + 1);
|
|
379
|
+
return info;
|
|
380
|
+
}
|
|
381
|
+
/** Rebuilds an `Error` carrying the original name, stack, Postgres fields and cause chain. */
|
|
382
|
+
function fromPGliteErrorInfo(info) {
|
|
383
|
+
const err = new Error(info.message);
|
|
384
|
+
define(err, "name", info.name);
|
|
385
|
+
if (info.stack !== void 0) err.stack = info.stack;
|
|
386
|
+
for (const [key, value] of Object.entries(info.fields)) define(err, key, value);
|
|
387
|
+
if (info.cause !== void 0) define(err, "cause", fromPGliteErrorInfo(info.cause));
|
|
388
|
+
return err;
|
|
389
|
+
}
|
|
390
|
+
function pgFieldsOf(err) {
|
|
391
|
+
const fields = {};
|
|
392
|
+
const record = err;
|
|
393
|
+
for (const key of PG_ERROR_FIELDS) {
|
|
394
|
+
const value = record[key];
|
|
395
|
+
if (typeof value === "string") fields[key] = value;
|
|
396
|
+
}
|
|
397
|
+
return fields;
|
|
398
|
+
}
|
|
399
|
+
function define(err, key, value) {
|
|
400
|
+
Object.defineProperty(err, key, {
|
|
401
|
+
value,
|
|
402
|
+
configurable: true,
|
|
403
|
+
writable: true,
|
|
404
|
+
enumerable: key !== "name" && key !== "cause"
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
function describe(value) {
|
|
408
|
+
if (typeof value === "string") return value;
|
|
409
|
+
if (value && typeof value === "object") {
|
|
410
|
+
const message = value.message;
|
|
411
|
+
if (typeof message === "string") return message;
|
|
412
|
+
}
|
|
413
|
+
if (value === void 0 || typeof value === "function") return String(value);
|
|
414
|
+
try {
|
|
415
|
+
return JSON.stringify(value);
|
|
416
|
+
} catch {
|
|
417
|
+
return "[unserializable]";
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//#endregion
|
|
421
|
+
export { syncDirectory as a, DEFAULT_VACUUM_FULL_ABOVE_BYTES as c, PGLITE_UTC_PARSERS as d, resolvePgliteFsync as i, DEFAULT_VACUUM_FULL_QUIET_MS as l, toPGliteErrorInfo as n, syncTree as o, createDurableNodeFs as r, DEFAULT_MAINTENANCE_INTERVAL_MS as s, fromPGliteErrorInfo as t, PgliteMaintenance as u };
|
|
422
|
+
|
|
423
|
+
//# sourceMappingURL=error-info-CCQcLAcW.mjs.map
|
|
424
|
+
//# debugId=ba1434c3-ef59-57f0-ae3b-f32e4a59c605
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-info-CCQcLAcW.mjs","sources":["../src/pglite/parsers.ts","../src/pglite/maintenance.ts","../src/pglite/sync-tree.ts","../src/pglite/durable-node-fs.ts","../src/pglite/worker/error-info.ts"],"sourcesContent":["// PGlite parses `timestamp` (no tz) columns as local time; read-model columns\n// store UTC, so parse them as UTC or values shift by the host's TZ offset.\nexport const PGLITE_UTC_PARSERS = {\n // 1114 = timestamp without time zone\n 1114: (value: string) => new Date(`${value.replace(\" \", \"T\")}Z`),\n} as const;\n","import { protocol, type PGlite } from \"@electric-sql/pglite\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\n\nexport const DEFAULT_MAINTENANCE_INTERVAL_MS = 5 * 60 * 1000;\nexport const DEFAULT_VACUUM_FULL_ABOVE_BYTES = 256 * 1024 * 1024;\nexport const DEFAULT_VACUUM_FULL_QUIET_MS = 60 * 1000;\n/** A VACUUM FULL waits for a quiet store at most this long from open. */\nexport const DEFAULT_VACUUM_FULL_MAX_DEFER_MS = 30 * 60_000;\nconst MAINTENANCE_RETRY_MS = 1000;\n\nexport type MaintenanceOutcome =\n | \"vacuum\"\n | \"vacuum-full\"\n | \"idle\"\n | \"not-ready\"\n | \"in-transaction\"\n | \"failed\";\n\nexport interface MaintenanceLogger {\n warn(message: string): void;\n}\n\n/** Runs a maintenance pass in the owner's turn; see {@link MaintenanceOptions.gate}. */\nexport type MaintenanceGate = <T>(task: () => Promise<T>) => Promise<T>;\n\nexport interface MaintenanceOptions {\n /** VACUUM + CHECKPOINT cadence; PGlite has no autovacuum. Default 5 min; 0 disables. */\n intervalMs?: number;\n /** First pass runs VACUUM FULL when `base/` exceeds this at open. Default 256 MB; 0 disables. */\n vacuumFullAboveBytes?: number;\n /**\n * VACUUM FULL holds the store for minutes on a large dir, so it waits for a\n * store with no synced statement (no write, no catch-up) for this long,\n * counted from open; until then a pass runs plain VACUUM and keeps the\n * VACUUM FULL pending. Default 60 s; 0 runs it on the first pass.\n */\n vacuumFullQuietMs?: number;\n /**\n * The longest a pending VACUUM FULL waits for that quiet window, counted\n * from open; past it the next pass runs VACUUM FULL anyway. Default 30 min;\n * 0 waits for the quiet window however long it takes.\n */\n vacuumFullMaxDeferMs?: number;\n /**\n * Queues each pass with the store's other work, e.g. behind a worker's\n * pending requests, so a pass never starts ahead of a statement already\n * admitted. A pass still waiting here when the store closes is skipped.\n */\n gate?: MaintenanceGate;\n logger?: MaintenanceLogger;\n /** Clock for the quiet window; tests pass their own. */\n now?: () => number;\n}\n\nexport class PgliteMaintenance {\n private readonly intervalMs: number;\n private readonly vacuumFullAboveBytes: number;\n private readonly vacuumFullQuietMs: number;\n private readonly vacuumFullMaxDeferMs: number;\n private readonly gate?: MaintenanceGate;\n private readonly logger?: MaintenanceLogger;\n private readonly now: () => number;\n\n private pg?: PGlite;\n private label = \"\";\n private closing = false;\n private syncsSinceMaintenance = 0;\n private vacuumFullPending = false;\n private timer?: ReturnType<typeof setTimeout>;\n private inFlight?: Promise<MaintenanceOutcome>;\n private active = false;\n private deferralLogged = false;\n private lastSyncAt = 0;\n private openedAt = 0;\n\n constructor(options: MaintenanceOptions = {}) {\n this.intervalMs = Math.max(\n 0,\n options.intervalMs ?? DEFAULT_MAINTENANCE_INTERVAL_MS,\n );\n this.vacuumFullAboveBytes = Math.max(\n 0,\n options.vacuumFullAboveBytes ?? DEFAULT_VACUUM_FULL_ABOVE_BYTES,\n );\n this.vacuumFullQuietMs = Math.max(\n 0,\n options.vacuumFullQuietMs ?? DEFAULT_VACUUM_FULL_QUIET_MS,\n );\n this.vacuumFullMaxDeferMs = Math.max(\n 0,\n options.vacuumFullMaxDeferMs ?? DEFAULT_VACUUM_FULL_MAX_DEFER_MS,\n );\n this.gate = options.gate;\n this.logger = options.logger;\n this.now = options.now ?? Date.now;\n }\n\n get scheduled(): boolean {\n return this.timer !== undefined;\n }\n\n get running(): boolean {\n return this.inFlight !== undefined;\n }\n\n start(pg: PGlite, label: string, baseBytes: number): void {\n this.pg = pg;\n this.label = label;\n this.vacuumFullPending =\n this.vacuumFullAboveBytes > 0 && baseBytes > this.vacuumFullAboveBytes;\n this.lastSyncAt = this.now();\n this.openedAt = this.lastSyncAt;\n this.schedule(this.intervalMs);\n }\n\n noteSync(): void {\n this.syncsSinceMaintenance++;\n this.lastSyncAt = this.now();\n }\n\n /** Waits for a pass that has started; one still queued at the gate is left to skip itself. */\n async stop(): Promise<void> {\n this.closing = true;\n this.cancel();\n if (this.active) await this.inFlight;\n }\n\n async run(): Promise<MaintenanceOutcome> {\n if (this.gate) return this.gate(() => this.runNow());\n return this.runNow();\n }\n\n private async runNow(): Promise<MaintenanceOutcome> {\n this.active = true;\n try {\n return await this.pass();\n } finally {\n this.active = false;\n }\n }\n\n private async pass(): Promise<MaintenanceOutcome> {\n const pg = this.pg;\n if (this.closing || !pg?.ready) return \"not-ready\";\n // pg.close() does not take the query mutex; recheck before each statement.\n const isReady = (): boolean => pg.ready && !this.closing;\n const now = this.now();\n const overdue =\n this.vacuumFullMaxDeferMs > 0 &&\n now - this.openedAt >= this.vacuumFullMaxDeferMs;\n const full =\n this.vacuumFullPending &&\n (now - this.lastSyncAt >= this.vacuumFullQuietMs || overdue);\n if (this.vacuumFullPending && !full && !this.deferralLogged) {\n this.deferralLogged = true;\n this.logger?.warn(\n `DurableNodeFs: ${this.label}/base exceeds ${this.vacuumFullAboveBytes} bytes; VACUUM FULL waits until the store has had no writes for ${this.vacuumFullQuietMs} ms${this.vacuumFullMaxDeferMs > 0 ? `, or at most ${this.vacuumFullMaxDeferMs} ms from open` : \"\"}`,\n );\n }\n if (!full && this.syncsSinceMaintenance === 0) {\n return \"idle\";\n }\n let outcome: MaintenanceOutcome;\n try {\n outcome = await pg._runExclusiveQuery(async () => {\n // isInTransaction() misses START TRANSACTION; ReadyForQuery status does not.\n if (!isReady()) return \"not-ready\";\n const { messages } = await pg.execProtocol(\n protocol.serialize.query(\"\"),\n { syncToFs: false },\n );\n if (transactionStatus(messages) !== \"I\") return \"in-transaction\";\n if (full) {\n this.logger?.warn(\n `DurableNodeFs: ${this.label}/base exceeds ${this.vacuumFullAboveBytes} bytes; running VACUUM FULL`,\n );\n }\n for (const statement of [\n full ? \"VACUUM FULL\" : \"VACUUM\",\n \"CHECKPOINT\",\n ]) {\n if (!isReady()) return \"not-ready\";\n await pg.execProtocol(protocol.serialize.query(statement), {\n syncToFs: false,\n });\n }\n return full ? \"vacuum-full\" : \"vacuum\";\n });\n } catch (err) {\n this.logger?.warn(\n `DurableNodeFs maintenance failed: ${errorMessage(err)}`,\n );\n return \"failed\";\n }\n if (outcome !== \"vacuum\" && outcome !== \"vacuum-full\") return outcome;\n this.syncsSinceMaintenance = 0;\n if (full) this.vacuumFullPending = false;\n return outcome;\n }\n\n private schedule(delayMs: number): void {\n if (this.intervalMs === 0 || this.closing) return;\n this.timer = setTimeout(() => {\n this.timer = undefined;\n this.inFlight = this.run()\n .then((outcome) => {\n this.schedule(\n outcome === \"in-transaction\"\n ? Math.min(MAINTENANCE_RETRY_MS, this.intervalMs)\n : this.intervalMs,\n );\n return outcome;\n })\n .finally(() => {\n this.inFlight = undefined;\n });\n }, delayMs);\n this.timer.unref();\n }\n\n private cancel(): void {\n if (!this.timer) return;\n clearTimeout(this.timer);\n this.timer = undefined;\n }\n}\n\n/** Total size of the regular files under `dir`; 0 when `dir` is missing. */\nexport async function dirBytes(dir: string): Promise<number> {\n let entries;\n try {\n entries = await fs.readdir(dir, { withFileTypes: true });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return 0;\n throw err;\n }\n let total = 0;\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n total += await dirBytes(full);\n } else if (entry.isFile()) {\n total += (await fs.stat(full)).size;\n }\n }\n return total;\n}\n\nfunction transactionStatus(messages: readonly { name: string }[]): unknown {\n for (let i = messages.length - 1; i >= 0; i--) {\n const m = messages[i];\n if (m.name === \"readyForQuery\") return (m as { status?: unknown }).status;\n }\n return undefined;\n}\n\nfunction errorMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n","import nodeFs from \"node:fs\";\nimport path from \"node:path\";\n\nexport interface SyncTreeHostFs {\n fsyncSync(fd: number): void;\n}\n\nexport interface SyncTreeResult {\n files: number;\n dirs: number;\n}\n\n/** One pass over a finished tree; interleaving fsync with writes costs seconds. */\nexport function syncTree(\n root: string,\n hostFs: SyncTreeHostFs = nodeFs,\n): SyncTreeResult {\n const result: SyncTreeResult = { files: 0, dirs: 0 };\n const pending = [path.resolve(root)];\n while (pending.length > 0) {\n const dir = pending.pop()!;\n for (const entry of nodeFs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n pending.push(full);\n } else if (entry.isFile()) {\n syncFile(full, hostFs);\n result.files++;\n }\n }\n syncDirectory(dir, hostFs);\n result.dirs++;\n }\n return result;\n}\n\n// Windows refuses FlushFileBuffers on a read-only handle (EPERM).\nfunction syncFile(file: string, hostFs: SyncTreeHostFs): void {\n const fd = nodeFs.openSync(file, \"r+\");\n try {\n hostFs.fsyncSync(fd);\n } finally {\n nodeFs.closeSync(fd);\n }\n}\n\n/** fsyncs a directory's entries; false where the platform refuses (Windows). */\nexport function syncDirectory(\n dir: string,\n hostFs: SyncTreeHostFs = nodeFs,\n): boolean {\n let fd: number;\n try {\n fd = nodeFs.openSync(dir, \"r\");\n } catch {\n return false;\n }\n try {\n hostFs.fsyncSync(fd);\n return true;\n } catch {\n return false;\n } finally {\n nodeFs.closeSync(fd);\n }\n}\n","import type { PGlite } from \"@electric-sql/pglite\";\nimport { ERRNO_CODES } from \"@electric-sql/pglite/basefs\";\nimport type { NodeFS } from \"@electric-sql/pglite/nodefs\";\nimport nodeFs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n dirBytes,\n PgliteMaintenance,\n type MaintenanceGate,\n} from \"./maintenance.js\";\nimport { syncTree } from \"./sync-tree.js\";\n\nexport type NodeFsClass = typeof NodeFS;\n\n// Emscripten/WASI errno; the basefs ERRNO_CODES export lacks it.\nconst EIO = 29;\n\nexport interface DurableNodeFsOptions {\n /** Default true; `PH_PGLITE_FSYNC=0` turns it off (power-loss durability off). */\n fsync?: boolean;\n /** Default 5 min; 0 disables. */\n maintenanceIntervalMs?: number;\n /** `base/` size at open; default 256 MB; 0 disables. */\n vacuumFullAboveBytes?: number;\n /** See `MaintenanceOptions.vacuumFullQuietMs`; default 60 s. */\n vacuumFullQuietMs?: number;\n /** See `MaintenanceOptions.vacuumFullMaxDeferMs`; default 30 min. */\n vacuumFullMaxDeferMs?: number;\n /** See `MaintenanceOptions.gate`. */\n maintenanceGate?: MaintenanceGate;\n /** Clock for the maintenance quiet window; tests pass their own. */\n now?: () => number;\n logger?: { warn(message: string): void };\n /** Emscripten abort (a Postgres PANIC, e.g. ENOSPC on WAL). */\n onAbort?: (what: unknown) => void;\n hostFs?: Pick<typeof nodeFs, \"fsyncSync\" | \"fdatasyncSync\">;\n}\n\nexport type DurableNodeFs = InstanceType<NodeFsClass> & {\n readonly maintenance: PgliteMaintenance;\n};\n\nexport function resolvePgliteFsync(\n env: Record<string, string | undefined>,\n): boolean {\n return env.PH_PGLITE_FSYNC !== \"0\";\n}\n\ninterface NodeFsStream {\n nfd?: number;\n /** Emscripten open flags; NODEFS opens the host fd with the same access mode. */\n flags?: number;\n}\n\n// Only PGlite's pg_flush_data (fsync on pre_sync_fname's O_RDONLY fd) syncs a\n// read-only fd: the result is discarded and an O_RDWR fsync of the same file\n// follows. Skipped, as Windows refuses FlushFileBuffers without write access.\nfunction isReadOnly(stream: NodeFsStream): boolean {\n return stream.flags !== undefined && (stream.flags & 3) === 0;\n}\n\ninterface EmscriptenFs {\n filesystems: { NODEFS: { stream_ops: Record<string, unknown> } };\n getStreamChecked(fd: number): NodeFsStream;\n quit(): void;\n}\n\ninterface EmscriptenMod {\n FS: EmscriptenFs;\n [wasmExport: string]: unknown;\n}\n\n// PGlite re-enters wasm from its own error handler after a query fails; on an\n// aborted runtime that spins forever, so every entry point is cut off first.\nconst WASM_ENTRY_POINTS = [\n \"_interactive_one\",\n \"_interactive_write\",\n \"_pgl_backend\",\n \"_pgl_initdb\",\n \"_pgl_shutdown\",\n];\n\nfunction poisonAfterAbort(mod: EmscriptenMod | undefined, what: unknown): void {\n if (!mod) return;\n const message = `PGlite aborted: ${String(what) || \"wasm runtime abort\"}`;\n for (const name of WASM_ENTRY_POINTS) {\n if (typeof mod[name] !== \"function\") continue;\n mod[name] = () => {\n throw new Error(message);\n };\n }\n // pg.close() rejects before closeFs(), so release the host fds here.\n try {\n mod.FS.quit();\n } catch {\n // already quit by an earlier abort\n }\n}\n\ntype SyscallImport = ((fd: number) => number) & { sig?: string };\n\ninterface WasmImports {\n env: Record<string, unknown> & { __syscall_fdatasync?: SyscallImport };\n}\n\ntype InstantiateWasm = (\n imports: WasmImports,\n done: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void,\n) => unknown;\n\ninterface EmscriptenOpts {\n preRun?: ((mod: EmscriptenMod) => void)[];\n instantiateWasm?: InstantiateWasm;\n onAbort?: (what: unknown) => void;\n}\n\ntype InitOpts = Parameters<InstanceType<NodeFsClass>[\"init\"]>[1];\n\n/** Built over the passed-in class so PG16 dirs on `pglite-legacy-02` get the same behaviour. */\nexport function createDurableNodeFs(\n Base: NodeFsClass,\n dataDir: string,\n options: DurableNodeFsOptions = {},\n): DurableNodeFs {\n const fsync = options.fsync ?? true;\n const hostFs = options.hostFs ?? nodeFs;\n const logger = options.logger;\n const onAbort = options.onAbort;\n const resolvedDir = path.resolve(dataDir);\n const maintenance = new PgliteMaintenance({\n intervalMs: options.maintenanceIntervalMs,\n vacuumFullAboveBytes: options.vacuumFullAboveBytes,\n vacuumFullQuietMs: options.vacuumFullQuietMs,\n vacuumFullMaxDeferMs: options.vacuumFullMaxDeferMs,\n gate: options.maintenanceGate,\n now: options.now,\n logger,\n });\n\n class Durable extends Base {\n readonly maintenance = maintenance;\n private mod?: EmscriptenMod;\n // Off from initialSyncFs of a fresh dir until PGlite's first syncToFs.\n private hostSyncs = fsync;\n private freshInit = false;\n\n async init(\n pg: PGlite,\n opts: InitOpts,\n ): Promise<{ emscriptenOpts: InitOpts }> {\n const { emscriptenOpts: base } = await super.init(pg, opts);\n const baseOpts = base as EmscriptenOpts;\n const inner = baseOpts.instantiateWasm;\n if (fsync && !inner) {\n throw new Error(\"PGlite did not supply instantiateWasm\");\n }\n const emscriptenOpts: EmscriptenOpts = {\n ...baseOpts,\n onAbort: (what) => {\n poisonAfterAbort(this.mod, what);\n void maintenance.stop();\n onAbort?.(what);\n },\n preRun: [\n ...(baseOpts.preRun ?? []),\n (mod) => {\n this.mod = mod;\n if (!fsync) return;\n mod.FS.filesystems.NODEFS.stream_ops.fsync = (\n stream: NodeFsStream,\n ) => this.fsyncStream(stream);\n },\n ],\n instantiateWasm:\n fsync && inner\n ? (imports, done) => {\n const original = imports.env.__syscall_fdatasync;\n const replacement: SyscallImport = (fd) => this.fdatasync(fd);\n replacement.sig = original?.sig;\n imports.env.__syscall_fdatasync = replacement;\n return inner(imports, done);\n }\n : inner,\n };\n return { emscriptenOpts: emscriptenOpts as InitOpts };\n }\n\n async initialSyncFs(): Promise<void> {\n await super.initialSyncFs();\n // No PG_VERSION: initdb runs next; PGlite calls syncToFs once before ready.\n this.freshInit =\n fsync && !nodeFs.existsSync(path.join(resolvedDir, \"PG_VERSION\"));\n if (this.freshInit) this.hostSyncs = false;\n const baseBytes = await dirBytes(path.join(resolvedDir, \"base\"));\n maintenance.start(this.pg!, resolvedDir, baseBytes);\n }\n\n async syncToFs(relaxedDurability?: boolean): Promise<void> {\n maintenance.noteSync();\n await super.syncToFs(relaxedDurability);\n if (!this.freshInit) return;\n this.freshInit = false;\n this.hostSyncs = true;\n syncTree(resolvedDir, hostFs);\n }\n\n async closeFs(): Promise<void> {\n try {\n await maintenance.stop();\n } finally {\n await super.closeFs();\n }\n }\n\n // WASI fd_sync convention: 0 or a positive errno.\n private fsyncStream(stream: NodeFsStream): number {\n if (!this.hostSyncs) return 0;\n // Directory streams carry no host fd; only regular files do.\n if (typeof stream.nfd !== \"number\" || isReadOnly(stream)) return 0;\n try {\n hostFs.fsyncSync(stream.nfd);\n } catch (err) {\n logger?.warn(`DurableNodeFs fsync failed: ${String(err)}`);\n return EIO;\n }\n return 0;\n }\n\n // Linux syscall convention: 0 or a negative errno.\n private fdatasync(fd: number): number {\n if (!this.hostSyncs) return 0;\n let stream: NodeFsStream;\n try {\n stream = this.mod!.FS.getStreamChecked(fd);\n } catch {\n return -ERRNO_CODES.EBADF;\n }\n if (typeof stream.nfd !== \"number\" || isReadOnly(stream)) return 0;\n try {\n hostFs.fdatasyncSync(stream.nfd);\n } catch (err) {\n logger?.warn(`DurableNodeFs fdatasync failed: ${String(err)}`);\n return -EIO;\n }\n return 0;\n }\n }\n\n return new Durable(dataDir) as DurableNodeFs;\n}\n","import type { PGliteErrorInfo } from \"./protocol.js\";\n\nconst MAX_STACK_LENGTH = 8 * 1024;\nconst MAX_CAUSE_DEPTH = 8;\n\n/** The string fields of PGlite's `DatabaseError`, plus the query PGlite attaches. */\nexport const PG_ERROR_FIELDS = [\n \"code\",\n \"severity\",\n \"detail\",\n \"hint\",\n \"position\",\n \"internalPosition\",\n \"internalQuery\",\n \"where\",\n \"schema\",\n \"table\",\n \"column\",\n \"dataType\",\n \"constraint\",\n \"file\",\n \"line\",\n \"routine\",\n \"query\",\n] as const;\n\n/** Flattens an error and its cause chain into a structured-clonable shape. */\nexport function toPGliteErrorInfo(err: unknown, depth = 0): PGliteErrorInfo {\n if (depth > MAX_CAUSE_DEPTH) {\n return { name: \"Error\", message: \"cause chain truncated\", fields: {} };\n }\n if (!(err instanceof Error)) {\n return { name: \"Error\", message: describe(err), fields: {} };\n }\n const info: PGliteErrorInfo = {\n name: err.name || \"Error\",\n message: err.message,\n fields: pgFieldsOf(err),\n };\n if (typeof err.stack === \"string\") {\n info.stack = err.stack.slice(0, MAX_STACK_LENGTH);\n }\n if (err.cause !== undefined) {\n info.cause = toPGliteErrorInfo(err.cause, depth + 1);\n }\n return info;\n}\n\n/** Rebuilds an `Error` carrying the original name, stack, Postgres fields and cause chain. */\nexport function fromPGliteErrorInfo(info: PGliteErrorInfo): Error {\n const err = new Error(info.message);\n define(err, \"name\", info.name);\n if (info.stack !== undefined) {\n err.stack = info.stack;\n }\n for (const [key, value] of Object.entries(info.fields)) {\n define(err, key, value);\n }\n if (info.cause !== undefined) {\n define(err, \"cause\", fromPGliteErrorInfo(info.cause));\n }\n return err;\n}\n\nfunction pgFieldsOf(err: Error): Record<string, string> {\n const fields: Record<string, string> = {};\n const record = err as unknown as Record<string, unknown>;\n for (const key of PG_ERROR_FIELDS) {\n const value = record[key];\n if (typeof value === \"string\") {\n fields[key] = value;\n }\n }\n return fields;\n}\n\nfunction define(err: Error, key: string, value: unknown): void {\n Object.defineProperty(err, key, {\n value,\n configurable: true,\n writable: true,\n enumerable: key !== \"name\" && key !== \"cause\",\n });\n}\n\nfunction describe(value: unknown): string {\n if (typeof value === \"string\") {\n return value;\n }\n if (value && typeof value === \"object\") {\n const message = (value as { message?: unknown }).message;\n if (typeof message === \"string\") {\n return message;\n }\n }\n if (value === undefined || typeof value === \"function\") {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return \"[unserializable]\";\n }\n}\n"],"names":["fs"],"mappings":";;;;;;;AAEA,MAAa,qBAAqB,EAEhC,OAAO,0BAAkB,IAAI,KAAK,GAAG,MAAM,QAAQ,KAAK,GAAG,EAAE,EAAE,EACjE;;;ACDA,MAAa,kCAAkC;AAC/C,MAAa,kCAAkC;AAC/C,MAAa,+BAA+B;AAG5C,MAAM,uBAAuB;AA8C7B,IAAa,oBAAb,MAA+B;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA,QAAgB;CAChB,UAAkB;CAClB,wBAAgC;CAChC,oBAA4B;CAC5B;CACA;CACA,SAAiB;CACjB,iBAAyB;CACzB,aAAqB;CACrB,WAAmB;CAEnB,YAAY,UAA8B,CAAC,GAAG;EAC5C,KAAK,aAAa,KAAK,IACrB,GACA,QAAQ,cAAA,GACV;EACA,K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OAAO,UAAU,UACnB,OAAO;CAET,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,UAAW,MAAgC;EACjD,IAAI,OAAO,YAAY,UACrB,OAAO;CAEX;CACA,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,YAC1C,OAAO,OAAO,KAAK;CAErB,IAAI;EACF,OAAO,KAAK,UAAU,KAAK;CAC7B,QAAQ;EACN,OAAO;CACT;AACF","debug_id":"ba1434c3-ef59-57f0-ae3b-f32e4a59c605"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { n as PGLITE_UTC_PARSERS, t as PGliteLike } from "./pglite-like-CKQEL_Q0.mjs";
|
|
1
2
|
import { a as IPackagePieceSource, c as PackageManagerResult, d as ReportError, f as RunDetachedOptions, i as IPackageManagerOptions, l as PackagePiece, m as runDetached, n as IPackageLoaderOptions, p as reportFailure, r as IPackageManager, t as IPackageLoader, u as PackagePieceEntry } from "./types-CCI5IDgT.mjs";
|
|
2
3
|
import { C as hasOperationSchemas, E as typeDefinitionNames, S as getGeneratedDocumentModelTypes, T as reservedTypeNamesTaken, _ as generateDocumentModelSchema, a as GeneratedDocumentModelTypes, b as getDocumentModelSubgraphName, c as SubgraphSchemaOptions, d as buildDocumentModelSchema, f as buildSubgraphSchemaModule, g as findSubgraphTypeCollisions, h as documentModelSubgraphTypes, i as DocumentModelSource, l as SubgraphTypeCollisionError, m as createSchema, n as DocumentModelSchemaCache, o as ReservedTypeNames, p as createMergedSchema, r as DocumentModelSchemaOptions, s as ResolvedDocumentModelSchema, t as DocumentModelSchema, u as assembleSubgraphTypeDefs, v as generatedTypesOf, w as reservedTypeNames, x as getDocumentModelTypeDefs, y as getDocumentModelSchemaName } from "./create-schema-BUk-IQCT.mjs";
|
|
3
4
|
import { IAnalyticsStore } from "@powerhousedao/analytics-engine-core";
|
|
4
5
|
import { AnalyticsModel } from "@powerhousedao/analytics-engine-graphql";
|
|
5
6
|
import { DocumentNode, GraphQLError, GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig, GraphQLSchema } from "graphql";
|
|
6
|
-
import { AttachmentRef, DocumentModelSource as DocumentModelSource$1, IDocumentModelLoader, IDocumentModelRegistry, IDriveClient, IInspectableAttachmentStore, IInspector, IInspectorAdmin, IInspectorStorageHealthProvider, INSPECTOR_OPS, IReactorClient, IReactorFactsSink, IReactorProcessorHostModuleBase, IRelationalDb, ISyncInspector, ISyncManager, InProcessReactorClientModule, InProcessReactorModule, InspectorDocumentReader, InspectorReadOpKey, PagedResults, ParsedDriveUrl, ProcessorFactoryBuilder as ProcessorFactoryBuilder$1, Remote, SYNC_INSPECTION_OPS, SearchFilter, SyncInspectionReadOpKey, SyncScopeGate, ViewFilter, driveIdFromUrl, parseDriveUrl } from "@powerhousedao/reactor";
|
|
7
|
+
import { AttachmentRef, CatchUpLoadSample, DocumentModelSource as DocumentModelSource$1, ICatchUpLoadSource, IDocumentModelLoader, IDocumentModelRegistry, IDriveClient, IInspectableAttachmentStore, IInspector, IInspectorAdmin, IInspectorStorageHealthProvider, INSPECTOR_OPS, IReactorClient, IReactorFactsSink, IReactorProcessorHostModuleBase, IRelationalDb, ISyncInspector, ISyncManager, InProcessReactorClientModule, InProcessReactorModule, InspectorDocumentReader, InspectorReadOpKey, PagedResults, ParsedDriveUrl, ProcessorFactoryBuilder as ProcessorFactoryBuilder$1, Remote, SYNC_INSPECTION_OPS, SearchFilter, SyncInspectionReadOpKey, SyncScopeGate, ViewFilter, driveIdFromUrl, parseDriveUrl } from "@powerhousedao/reactor";
|
|
7
8
|
import { AuthSubject, DocumentModelModule, Operation, PHDocument, UpgradeManifest } from "@powerhousedao/shared/document-model";
|
|
8
9
|
import { ILogger } from "document-model";
|
|
9
10
|
import { GraphQLResolverMap } from "@apollo/subgraph";
|
|
@@ -64,21 +65,18 @@ export interface OperationUserPermissionTable {
|
|
|
64
65
|
createdAt: Date;
|
|
65
66
|
}
|
|
66
67
|
type Db = Kysely<any>;
|
|
67
|
-
export declare const PGLITE_UTC_PARSERS: {
|
|
68
|
-
readonly 1114: (value: string) => Date;
|
|
69
|
-
};
|
|
70
68
|
export declare function isPostgresConnectionString(connectionString: string): boolean;
|
|
71
69
|
/**
|
|
72
70
|
* Optional factory used by callers (e.g. Switchboard) to inject a
|
|
73
71
|
* version-specific PGLite instance — e.g. `pglite-legacy-02` when an existing
|
|
74
|
-
* data dir was created with an older PG major
|
|
75
|
-
*
|
|
72
|
+
* data dir was created with an older PG major, or a worker-backed
|
|
73
|
+
* `ThreadedPGlite`. Anything meeting {@link PGliteLike} works.
|
|
76
74
|
*/
|
|
77
|
-
export type PgliteFactory = (connectionString: string | undefined) =>
|
|
75
|
+
export type PgliteFactory = (connectionString: string | undefined) => PGliteLike;
|
|
78
76
|
export interface DbClient {
|
|
79
77
|
db: Db;
|
|
80
78
|
knex: Knex;
|
|
81
|
-
pglite:
|
|
79
|
+
pglite: PGliteLike | undefined;
|
|
82
80
|
}
|
|
83
81
|
export declare function getDbClient(connectionString?: string | undefined, pgliteFactory?: PgliteFactory): DbClient;
|
|
84
82
|
export declare const initAnalyticsStoreSql: string[];
|
|
@@ -789,6 +787,51 @@ export declare function redactHeaders(headers: Record<string, string>, extra?: s
|
|
|
789
787
|
* XML or CSV payload is still reachable downstream. */
|
|
790
788
|
export declare function parseWebhookBody(raw: Buffer, contentType?: string): unknown;
|
|
791
789
|
//#endregion
|
|
790
|
+
//#region src/http/request-load.d.ts
|
|
791
|
+
/**
|
|
792
|
+
* Whether a request counts as user load: not the monitor's inspection calls,
|
|
793
|
+
* not a health probe, not a static asset and not a long-lived stream.
|
|
794
|
+
*/
|
|
795
|
+
export declare function isCountedRequest(url: string, accept?: string): boolean;
|
|
796
|
+
/** Main-thread event-loop delay, as the recorder reads it once per sample. */
|
|
797
|
+
interface IEventLoopDelaySource {
|
|
798
|
+
/** p99 delay since the last call, in ms. */
|
|
799
|
+
takeP99Ms(): number;
|
|
800
|
+
stop(): void;
|
|
801
|
+
}
|
|
802
|
+
/** `perf_hooks.monitorEventLoopDelay`, reset on every read. */
|
|
803
|
+
export declare class NodeEventLoopDelay implements IEventLoopDelaySource {
|
|
804
|
+
private readonly histogram;
|
|
805
|
+
constructor(resolutionMs?: number);
|
|
806
|
+
takeP99Ms(): number;
|
|
807
|
+
stop(): void;
|
|
808
|
+
}
|
|
809
|
+
type RequestLoadRecorderOptions = {
|
|
810
|
+
windowMs?: number;
|
|
811
|
+
now?: () => number;
|
|
812
|
+
eventLoopDelay?: IEventLoopDelaySource;
|
|
813
|
+
};
|
|
814
|
+
/**
|
|
815
|
+
* Counts completed user requests and their latency over a sliding window, and
|
|
816
|
+
* reads the main thread's event-loop delay, as the catch-up controller's load
|
|
817
|
+
* source. Loop delay over the window is the highest per-sample p99 in it.
|
|
818
|
+
*/
|
|
819
|
+
export declare class RequestLoadRecorder implements ICatchUpLoadSource {
|
|
820
|
+
private readonly windowMs;
|
|
821
|
+
private readonly now;
|
|
822
|
+
private readonly eventLoopDelay;
|
|
823
|
+
private readonly completions;
|
|
824
|
+
private readonly loopReadings;
|
|
825
|
+
private lastCompletedAt;
|
|
826
|
+
private readonly detachers;
|
|
827
|
+
constructor(options?: RequestLoadRecorderOptions);
|
|
828
|
+
/** Records every counted request `server` completes, until `stop`. */
|
|
829
|
+
attach(server: http.Server): void;
|
|
830
|
+
record(durationMs: number): void;
|
|
831
|
+
sample(): CatchUpLoadSample;
|
|
832
|
+
stop(): void;
|
|
833
|
+
}
|
|
834
|
+
//#endregion
|
|
792
835
|
//#region src/services/canonical-document-id.d.ts
|
|
793
836
|
/**
|
|
794
837
|
* Raised when a caller-supplied identifier cannot be resolved to a canonical
|
|
@@ -1825,6 +1868,8 @@ export type ReadinessGate = {
|
|
|
1825
1868
|
};
|
|
1826
1869
|
export type API = {
|
|
1827
1870
|
httpAdapter: IHttpAdapter;
|
|
1871
|
+
/** The listening server, for host-side observers such as request load. */
|
|
1872
|
+
httpServer: http.Server;
|
|
1828
1873
|
/** Hands each package a namespaced slice of the HTTP surface. */
|
|
1829
1874
|
httpRoutes: HttpRouteService;
|
|
1830
1875
|
graphqlManager: GraphQLManager$1;
|
|
@@ -4973,6 +5018,6 @@ export declare class PrivacyPermissionAdapter {
|
|
|
4973
5018
|
erasePermissions(documentId: string): Promise<Record<string, number>>;
|
|
4974
5019
|
}
|
|
4975
5020
|
//#endregion
|
|
4976
|
-
export { type AttachmentReadGate, type AuthorizationConfig, type AuthorizerResult, type CanonicalDocumentId, DocumentModelSchema, DocumentModelSchemaCache, DocumentModelSchemaOptions, DocumentModelSource, GeneratedDocumentModelTypes, type HttpRouteServiceOptions, type IAuthorizationService, type IDocumentScopeGate, type IHttpScope, type IPackageLoader, type IPackageLoaderOptions, type IPackagePieceSource, type IReactorInspectionSource, type IWebhookEndpoints, type IWebhookScope, type IWebhookStore, type InspectionCallerGate, type InspectionReadField, type InspectionThrottleConfig, type NodeRouteSpec, type PackagePiece, type PackagePieceEntry, type PackagesSubgraphArgs, type ParsedDriveUrl, type ReactorInspectionOptions, ReportError, ReservedTypeNames, ResolvedDocumentModelSchema, type RouteActor, type RouteAuth, type RouteAuthorizer, type RouteBody, type RouteContext, type RouteHandler, type RouteMethod, type RouteOptions, type RouteSpec, type RouteTransport, type RouteUser, RunDetachedOptions, type ScopedRouteHandle, SubgraphSchemaOptions, SubgraphTypeCollisionError, type WebhookEndpointInfo, type WebhookEndpointRow, type WebhookField, type WebhookHashAlgorithm, type WebhookPolicy, type WebhookReply, type WebhookRequest, type WebhookScheme, type WebhookSignatureEncoding, type WebhookSpec, type WebhookVerification, assembleSubgraphTypeDefs, buildDocumentModelSchema, buildSubgraphSchemaModule, createMergedSchema, createSchema, documentModelSubgraphTypes, driveIdFromUrl, findSubgraphTypeCollisions, generateDocumentModelSchema, generatedTypesOf, getDocumentModelSchemaName, getDocumentModelSubgraphName, getDocumentModelTypeDefs, getGeneratedDocumentModelTypes, hasOperationSchemas, parseDriveUrl, reportFailure, reservedTypeNames, reservedTypeNamesTaken, runDetached, typeDefinitionNames };
|
|
5021
|
+
export { type AttachmentReadGate, type AuthorizationConfig, type AuthorizerResult, type CanonicalDocumentId, DocumentModelSchema, DocumentModelSchemaCache, DocumentModelSchemaOptions, DocumentModelSource, GeneratedDocumentModelTypes, type HttpRouteServiceOptions, type IAuthorizationService, type IDocumentScopeGate, type IEventLoopDelaySource, type IHttpScope, type IPackageLoader, type IPackageLoaderOptions, type IPackagePieceSource, type IReactorInspectionSource, type IWebhookEndpoints, type IWebhookScope, type IWebhookStore, type InspectionCallerGate, type InspectionReadField, type InspectionThrottleConfig, type NodeRouteSpec, PGLITE_UTC_PARSERS, type PackagePiece, type PackagePieceEntry, type PackagesSubgraphArgs, type ParsedDriveUrl, type ReactorInspectionOptions, ReportError, type RequestLoadRecorderOptions, ReservedTypeNames, ResolvedDocumentModelSchema, type RouteActor, type RouteAuth, type RouteAuthorizer, type RouteBody, type RouteContext, type RouteHandler, type RouteMethod, type RouteOptions, type RouteSpec, type RouteTransport, type RouteUser, RunDetachedOptions, type ScopedRouteHandle, SubgraphSchemaOptions, SubgraphTypeCollisionError, type WebhookEndpointInfo, type WebhookEndpointRow, type WebhookField, type WebhookHashAlgorithm, type WebhookPolicy, type WebhookReply, type WebhookRequest, type WebhookScheme, type WebhookSignatureEncoding, type WebhookSpec, type WebhookVerification, assembleSubgraphTypeDefs, buildDocumentModelSchema, buildSubgraphSchemaModule, createMergedSchema, createSchema, documentModelSubgraphTypes, driveIdFromUrl, findSubgraphTypeCollisions, generateDocumentModelSchema, generatedTypesOf, getDocumentModelSchemaName, getDocumentModelSubgraphName, getDocumentModelTypeDefs, getGeneratedDocumentModelTypes, hasOperationSchemas, parseDriveUrl, reportFailure, reservedTypeNames, reservedTypeNamesTaken, runDetached, typeDefinitionNames };
|
|
4977
5022
|
export {};
|
|
4978
5023
|
//# sourceMappingURL=index.d.mts.map
|