@akal/supaforge 0.0.31 → 0.0.32
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 +1 -1
- package/dist/base-command.d.ts +1 -0
- package/dist/base-command.js +2 -2
- package/dist/{chunk-BHYLBKYD.js → chunk-2SELREHW.js} +5 -5
- package/dist/{chunk-5Z3SAIQS.js → chunk-3HGAV5CC.js} +97 -831
- package/dist/chunk-3HGAV5CC.js.map +1 -0
- package/dist/{chunk-XMYMIURR.js → chunk-4IVN7QVY.js} +119 -39
- package/dist/chunk-4IVN7QVY.js.map +1 -0
- package/dist/{chunk-NXRSAVRU.js → chunk-6LJERPUN.js} +28 -7
- package/dist/chunk-6LJERPUN.js.map +1 -0
- package/dist/{chunk-4OU7KO5Y.js → chunk-6Q7MHFBM.js} +2 -2
- package/dist/{chunk-PARSNTBD.js → chunk-7NAZGZPV.js} +56 -25
- package/dist/chunk-7NAZGZPV.js.map +1 -0
- package/dist/{chunk-VOXZWQ3N.js → chunk-BUOWHE36.js} +372 -9
- package/dist/chunk-BUOWHE36.js.map +1 -0
- package/dist/{chunk-TQJSQLWA.js → chunk-DMIWAJRB.js} +38 -10
- package/dist/chunk-DMIWAJRB.js.map +1 -0
- package/dist/{chunk-LQXF65MC.js → chunk-GEHPTPNZ.js} +3 -3
- package/dist/chunk-GEHPTPNZ.js.map +1 -0
- package/dist/chunk-GZREXCQZ.js +207 -0
- package/dist/chunk-GZREXCQZ.js.map +1 -0
- package/dist/{chunk-YVDSR4GM.js → chunk-MIRLB5JM.js} +51 -23
- package/dist/chunk-MIRLB5JM.js.map +1 -0
- package/dist/{chunk-KIFJGON5.js → chunk-NTUASFQ3.js} +2 -2
- package/dist/{chunk-5QQBTLWO.js → chunk-ORQJVE57.js} +3 -3
- package/dist/{chunk-VMTBLHN2.js → chunk-SC2XHGIS.js} +2 -2
- package/dist/{chunk-X6V2GGDZ.js → chunk-SQPCWGQO.js} +388 -64
- package/dist/chunk-SQPCWGQO.js.map +1 -0
- package/dist/chunk-UWAVXC57.js +916 -0
- package/dist/chunk-UWAVXC57.js.map +1 -0
- package/dist/commands/clone.js +10 -10
- package/dist/commands/diff.d.ts +16 -0
- package/dist/commands/diff.js +11 -12
- package/dist/commands/hukam.js +11 -12
- package/dist/commands/hukam.js.map +1 -1
- package/dist/commands/mcp.js +7 -8
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/migrate/baseline.js +3 -3
- package/dist/commands/migrate/create.js +5 -6
- package/dist/commands/migrate/create.js.map +1 -1
- package/dist/commands/migrate/list.js +4 -4
- package/dist/commands/migrate/list.js.map +1 -1
- package/dist/commands/migrate/run.js +5 -6
- package/dist/commands/report.js +3 -3
- package/dist/commands/restore.js +11 -13
- package/dist/commands/restore.js.map +1 -1
- package/dist/commands/snapshot.js +6 -8
- package/dist/commands/snapshot.js.map +1 -1
- package/dist/commands/sync.js +11 -12
- package/dist/commands/sync.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -16
- package/package.json +2 -2
- package/dist/chunk-5Z3SAIQS.js.map +0 -1
- package/dist/chunk-H5MJ5DFX.js +0 -16
- package/dist/chunk-H5MJ5DFX.js.map +0 -1
- package/dist/chunk-LQXF65MC.js.map +0 -1
- package/dist/chunk-NXRSAVRU.js.map +0 -1
- package/dist/chunk-PARSNTBD.js.map +0 -1
- package/dist/chunk-RRMI5CZD.js +0 -376
- package/dist/chunk-RRMI5CZD.js.map +0 -1
- package/dist/chunk-SF3YA42C.js +0 -506
- package/dist/chunk-SF3YA42C.js.map +0 -1
- package/dist/chunk-TQJSQLWA.js.map +0 -1
- package/dist/chunk-VOXZWQ3N.js.map +0 -1
- package/dist/chunk-X6V2GGDZ.js.map +0 -1
- package/dist/chunk-XMYMIURR.js.map +0 -1
- package/dist/chunk-YVDSR4GM.js.map +0 -1
- /package/dist/{chunk-BHYLBKYD.js.map → chunk-2SELREHW.js.map} +0 -0
- /package/dist/{chunk-4OU7KO5Y.js.map → chunk-6Q7MHFBM.js.map} +0 -0
- /package/dist/{chunk-KIFJGON5.js.map → chunk-NTUASFQ3.js.map} +0 -0
- /package/dist/{chunk-5QQBTLWO.js.map → chunk-ORQJVE57.js.map} +0 -0
- /package/dist/{chunk-VMTBLHN2.js.map → chunk-SC2XHGIS.js.map} +0 -0
package/dist/chunk-SF3YA42C.js
DELETED
|
@@ -1,506 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_MIGRATIONS_DIR,
|
|
3
|
-
describeFailure,
|
|
4
|
-
pgClientConfig,
|
|
5
|
-
redactUrls,
|
|
6
|
-
resolveConnectTimeoutMs
|
|
7
|
-
} from "./chunk-X6V2GGDZ.js";
|
|
8
|
-
import {
|
|
9
|
-
CONTAINER_RM_TIMEOUT_MS,
|
|
10
|
-
CONTAINER_START_TIMEOUT_MS,
|
|
11
|
-
DB_PROBE_TIMEOUT_MS,
|
|
12
|
-
RUNTIME_DETECT_TIMEOUT_MS,
|
|
13
|
-
RUN_LOG_DIR,
|
|
14
|
-
RUN_LOG_FILE,
|
|
15
|
-
RUN_LOG_MAX_ENTRIES,
|
|
16
|
-
bold,
|
|
17
|
-
cmd,
|
|
18
|
-
dim,
|
|
19
|
-
loadConfig,
|
|
20
|
-
ok,
|
|
21
|
-
validateConfig,
|
|
22
|
-
validateSingleEnvConfig,
|
|
23
|
-
warn
|
|
24
|
-
} from "./chunk-6WAMNZLO.js";
|
|
25
|
-
|
|
26
|
-
// src/base-command.ts
|
|
27
|
-
import { formatWithOptions } from "util";
|
|
28
|
-
import { Command } from "@oclif/core";
|
|
29
|
-
|
|
30
|
-
// src/preflight.ts
|
|
31
|
-
import pg2 from "pg";
|
|
32
|
-
|
|
33
|
-
// src/local-pg.ts
|
|
34
|
-
import { execFile } from "child_process";
|
|
35
|
-
import { promisify } from "util";
|
|
36
|
-
import pg from "pg";
|
|
37
|
-
var defaultExecFile = promisify(execFile);
|
|
38
|
-
var PG_IMAGE = "docker.io/library/postgres:17";
|
|
39
|
-
var DEFAULT_LOCAL_PORT = 5432;
|
|
40
|
-
var CONTAINER_NAME = "supaforge-local-pg";
|
|
41
|
-
var LOCAL_PG_USER = "postgres";
|
|
42
|
-
var LOCAL_PG_PASSWORD = "postgres";
|
|
43
|
-
var READINESS_RETRIES = 30;
|
|
44
|
-
var READINESS_INTERVAL_MS = 2e3;
|
|
45
|
-
async function defaultConnectFn(url) {
|
|
46
|
-
const client = new pg.Client(pgClientConfig(url));
|
|
47
|
-
await client.connect();
|
|
48
|
-
await client.end();
|
|
49
|
-
}
|
|
50
|
-
async function detectRuntime(execFn = defaultExecFile) {
|
|
51
|
-
for (const rt of ["podman", "docker"]) {
|
|
52
|
-
try {
|
|
53
|
-
await execFn(rt, ["--version"], { timeout: RUNTIME_DETECT_TIMEOUT_MS });
|
|
54
|
-
return rt;
|
|
55
|
-
} catch {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
async function startLocalPg(options = {}) {
|
|
62
|
-
const exec = options.execFn ?? defaultExecFile;
|
|
63
|
-
const connect = options.connectFn ?? defaultConnectFn;
|
|
64
|
-
const runtime = options.runtime ?? await detectRuntime(exec);
|
|
65
|
-
if (!runtime) {
|
|
66
|
-
throw new Error(
|
|
67
|
-
"No container runtime found. Install Podman (recommended) or Docker.\n Podman: https://podman.io/docs/installation\n Docker: https://docs.docker.com/engine/install/"
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
const port = options.port ?? DEFAULT_LOCAL_PORT;
|
|
71
|
-
const password = options.password ?? LOCAL_PG_PASSWORD;
|
|
72
|
-
const name = options.name ?? CONTAINER_NAME;
|
|
73
|
-
const image = options.image ?? PG_IMAGE;
|
|
74
|
-
const existing = await getContainerStatus(runtime, name, exec);
|
|
75
|
-
if (existing === "running") {
|
|
76
|
-
return {
|
|
77
|
-
runtime,
|
|
78
|
-
containerName: name,
|
|
79
|
-
port,
|
|
80
|
-
url: buildLocalUrl(port, password)
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
if (existing === "stopped") {
|
|
84
|
-
await exec(runtime, ["rm", "-f", name], { timeout: CONTAINER_RM_TIMEOUT_MS });
|
|
85
|
-
}
|
|
86
|
-
const args = [
|
|
87
|
-
"run",
|
|
88
|
-
"-d",
|
|
89
|
-
"--name",
|
|
90
|
-
name,
|
|
91
|
-
"-p",
|
|
92
|
-
`${port}:5432`,
|
|
93
|
-
"-e",
|
|
94
|
-
`POSTGRES_PASSWORD=${password}`,
|
|
95
|
-
"-e",
|
|
96
|
-
`POSTGRES_USER=${LOCAL_PG_USER}`,
|
|
97
|
-
"--tmpfs",
|
|
98
|
-
"/var/lib/postgresql/data",
|
|
99
|
-
"--health-cmd",
|
|
100
|
-
`pg_isready -U ${LOCAL_PG_USER}`,
|
|
101
|
-
"--health-interval",
|
|
102
|
-
"5s",
|
|
103
|
-
"--health-timeout",
|
|
104
|
-
"5s",
|
|
105
|
-
"--health-retries",
|
|
106
|
-
"20",
|
|
107
|
-
"--health-start-period",
|
|
108
|
-
"10s",
|
|
109
|
-
image
|
|
110
|
-
];
|
|
111
|
-
try {
|
|
112
|
-
await exec(runtime, args, { timeout: CONTAINER_START_TIMEOUT_MS });
|
|
113
|
-
} catch (err) {
|
|
114
|
-
throw new Error(
|
|
115
|
-
`Failed to start PostgreSQL container via ${runtime}: ${err.message}`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
const url = buildLocalUrl(port, password);
|
|
119
|
-
await waitForPg(url, connect);
|
|
120
|
-
return { runtime, containerName: name, port, url };
|
|
121
|
-
}
|
|
122
|
-
async function getContainerStatus(runtime, name, execFn) {
|
|
123
|
-
try {
|
|
124
|
-
const { stdout } = await execFn(
|
|
125
|
-
runtime,
|
|
126
|
-
["inspect", "--format", "{{.State.Running}}", name],
|
|
127
|
-
{ timeout: RUNTIME_DETECT_TIMEOUT_MS }
|
|
128
|
-
);
|
|
129
|
-
return stdout.trim() === "true" ? "running" : "stopped";
|
|
130
|
-
} catch {
|
|
131
|
-
return "none";
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function buildLocalUrl(port, password) {
|
|
135
|
-
return `postgres://${LOCAL_PG_USER}:${password}@localhost:${port}/postgres`;
|
|
136
|
-
}
|
|
137
|
-
async function waitForPg(url, connectFn) {
|
|
138
|
-
for (let i = 0; i < READINESS_RETRIES; i++) {
|
|
139
|
-
try {
|
|
140
|
-
await connectFn(url);
|
|
141
|
-
return;
|
|
142
|
-
} catch {
|
|
143
|
-
await sleep(READINESS_INTERVAL_MS);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
throw new Error(
|
|
147
|
-
`PostgreSQL at ${url} did not become ready within ${READINESS_RETRIES * READINESS_INTERVAL_MS / 1e3}s`
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
function sleep(ms) {
|
|
151
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// src/preflight.ts
|
|
155
|
-
var SUPABASE_LOCAL_PORT = "54322";
|
|
156
|
-
var DEFAULT_PG_PORT = "5432";
|
|
157
|
-
var CONNECT_TIMEOUT_RE = /timeout expired|connection timeout/i;
|
|
158
|
-
var QUERY_TIMEOUT_RE = /query read timeout/i;
|
|
159
|
-
function describeTimeout(message, connectTimeoutMs, probeTimeoutMs) {
|
|
160
|
-
if (CONNECT_TIMEOUT_RE.test(message)) {
|
|
161
|
-
return `timed out after ${Math.round(connectTimeoutMs / 1e3)}s connecting \u2014 the host accepted the connection but never completed the handshake`;
|
|
162
|
-
}
|
|
163
|
-
if (QUERY_TIMEOUT_RE.test(message)) {
|
|
164
|
-
return `timed out after ${Math.round(probeTimeoutMs / 1e3)}s waiting for server response \u2014 connected, but the server did not answer`;
|
|
165
|
-
}
|
|
166
|
-
return message;
|
|
167
|
-
}
|
|
168
|
-
async function checkConnection(dbUrl) {
|
|
169
|
-
const connectTimeoutMs = resolveConnectTimeoutMs();
|
|
170
|
-
let client;
|
|
171
|
-
try {
|
|
172
|
-
client = new pg2.Client(pgClientConfig(dbUrl, DB_PROBE_TIMEOUT_MS));
|
|
173
|
-
await client.connect();
|
|
174
|
-
const { rows } = await client.query("SHOW server_version");
|
|
175
|
-
const version = rows[0].server_version;
|
|
176
|
-
return { reachable: true, version };
|
|
177
|
-
} catch (err) {
|
|
178
|
-
return {
|
|
179
|
-
reachable: false,
|
|
180
|
-
error: describeTimeout(describeFailure(err), connectTimeoutMs, DB_PROBE_TIMEOUT_MS)
|
|
181
|
-
};
|
|
182
|
-
} finally {
|
|
183
|
-
try {
|
|
184
|
-
await client?.end();
|
|
185
|
-
} catch {
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
var SERVER_REACHABLE_RE = /password authentication failed|does not exist|database .* does not exist|SSL.*required|no pg_hba\.conf entry/i;
|
|
190
|
-
async function buildLocalHints(dbUrl, error) {
|
|
191
|
-
const hints = [];
|
|
192
|
-
try {
|
|
193
|
-
const urlObj = new URL(dbUrl);
|
|
194
|
-
const isSupabasePort = urlObj.port === SUPABASE_LOCAL_PORT;
|
|
195
|
-
const isLocal = ["localhost", "127.0.0.1", "::1", ""].includes(urlObj.hostname);
|
|
196
|
-
if (!isLocal) return hints;
|
|
197
|
-
if (error && SERVER_REACHABLE_RE.test(error)) {
|
|
198
|
-
hints.push(`Check the username and password in your database URL.`);
|
|
199
|
-
if (isSupabasePort) {
|
|
200
|
-
hints.push(`Port ${SUPABASE_LOCAL_PORT} is the Supabase CLI default. The default password is "postgres".`);
|
|
201
|
-
}
|
|
202
|
-
return hints;
|
|
203
|
-
}
|
|
204
|
-
if (isSupabasePort) {
|
|
205
|
-
hints.push(`Port ${SUPABASE_LOCAL_PORT} is the Supabase CLI default. Run ${cmd('"supabase start"')} to start your local Supabase instance.`);
|
|
206
|
-
}
|
|
207
|
-
const runtime = await detectRuntime();
|
|
208
|
-
if (runtime) {
|
|
209
|
-
hints.push(`${bold(runtime)} detected \u2014 you can start a PostgreSQL container manually.`);
|
|
210
|
-
}
|
|
211
|
-
if (!isSupabasePort) {
|
|
212
|
-
hints.push(`Start PostgreSQL manually on port ${urlObj.port || DEFAULT_PG_PORT}.`);
|
|
213
|
-
}
|
|
214
|
-
} catch {
|
|
215
|
-
}
|
|
216
|
-
return hints;
|
|
217
|
-
}
|
|
218
|
-
function buildTimeoutHints() {
|
|
219
|
-
return [
|
|
220
|
-
"The host is listening but the database did not answer.",
|
|
221
|
-
"Check the database process is running and not paused, restarting, or overloaded.",
|
|
222
|
-
"Over a VPN or tunnel, check the connection is still up.",
|
|
223
|
-
`Raise the bound with ${cmd("SUPAFORGE_CONNECT_TIMEOUT")} (in seconds) if the link is simply slow.`
|
|
224
|
-
];
|
|
225
|
-
}
|
|
226
|
-
async function buildConnectionHints(dbUrl, error) {
|
|
227
|
-
if (error && /timed out after \d+s/.test(error)) return buildTimeoutHints();
|
|
228
|
-
return buildLocalHints(dbUrl, error);
|
|
229
|
-
}
|
|
230
|
-
var defaultPending = (msg) => {
|
|
231
|
-
if (!process.stdout.isTTY) return;
|
|
232
|
-
process.stdout.write(msg === null ? "\r\x1B[2K" : `\r\x1B[2K${msg}`);
|
|
233
|
-
};
|
|
234
|
-
var Preflight = class {
|
|
235
|
-
title;
|
|
236
|
-
log;
|
|
237
|
-
pending;
|
|
238
|
-
databases = [];
|
|
239
|
-
customs = [];
|
|
240
|
-
infoLines = [];
|
|
241
|
-
constructor(title, log, pending = defaultPending) {
|
|
242
|
-
this.title = title;
|
|
243
|
-
this.log = log;
|
|
244
|
-
this.pending = pending;
|
|
245
|
-
}
|
|
246
|
-
/** Register a database connectivity check. */
|
|
247
|
-
addDatabase(label, envName, dbUrl) {
|
|
248
|
-
this.databases.push({ label, envName, dbUrl });
|
|
249
|
-
return this;
|
|
250
|
-
}
|
|
251
|
-
/** Add an informational line to the header (displayed after database lines). */
|
|
252
|
-
addInfo(label, value) {
|
|
253
|
-
this.infoLines.push({ label, value });
|
|
254
|
-
return this;
|
|
255
|
-
}
|
|
256
|
-
/** Register a custom check (runs after all DB connectivity checks). */
|
|
257
|
-
addCheck(label, fn) {
|
|
258
|
-
this.customs.push({ label, fn });
|
|
259
|
-
return this;
|
|
260
|
-
}
|
|
261
|
-
/** Execute all registered checks, render results, and return the report. */
|
|
262
|
-
async run() {
|
|
263
|
-
const entries = [];
|
|
264
|
-
const log = this.log;
|
|
265
|
-
log(`
|
|
266
|
-
${bold(this.title)}
|
|
267
|
-
`);
|
|
268
|
-
for (const db of this.databases) {
|
|
269
|
-
log(` ${db.label}: ${db.envName} ${dim(`(${redactUrls(db.dbUrl)})`)}`);
|
|
270
|
-
}
|
|
271
|
-
for (const info of this.infoLines) {
|
|
272
|
-
log(` ${info.label}: ${info.value}`);
|
|
273
|
-
}
|
|
274
|
-
log("");
|
|
275
|
-
log(" Checks:");
|
|
276
|
-
for (const db of this.databases) {
|
|
277
|
-
this.pending(` ${dim(`\u2026 connecting to ${db.label.toLowerCase()}`)}`);
|
|
278
|
-
const result = await checkConnection(db.dbUrl);
|
|
279
|
-
this.pending(null);
|
|
280
|
-
if (result.reachable) {
|
|
281
|
-
log(` ${ok("\u2713")} ${db.label} reachable ${dim(`(PostgreSQL ${result.version})`)}`);
|
|
282
|
-
entries.push({ label: db.label, passed: true, detail: `PostgreSQL ${result.version}` });
|
|
283
|
-
} else {
|
|
284
|
-
log(` ${warn("\u2717")} ${db.label} not reachable: ${redactUrls(describeFailure(result.error))}`);
|
|
285
|
-
const hints = await buildConnectionHints(db.dbUrl, result.error);
|
|
286
|
-
if (hints.length > 0) {
|
|
287
|
-
log(`
|
|
288
|
-
${dim("Hints:")}`);
|
|
289
|
-
for (const h of hints) log(` ${dim("\u2022")} ${h}`);
|
|
290
|
-
}
|
|
291
|
-
entries.push({ label: db.label, passed: false, error: result.error, hints });
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
for (const custom of this.customs) {
|
|
295
|
-
this.pending(` ${dim(`\u2026 ${custom.label}`)}`);
|
|
296
|
-
const result = await custom.fn();
|
|
297
|
-
this.pending(null);
|
|
298
|
-
if (!result.error) {
|
|
299
|
-
const suffix = result.detail ? ` ${dim(result.detail)}` : "";
|
|
300
|
-
log(` ${ok("\u2713")} ${custom.label}${suffix}`);
|
|
301
|
-
entries.push({ label: custom.label, passed: true, detail: result.detail });
|
|
302
|
-
} else {
|
|
303
|
-
log(` ${warn("\u2717")} ${custom.label}: ${redactUrls(describeFailure(result.error))}`);
|
|
304
|
-
if (result.hints?.length) {
|
|
305
|
-
log(`
|
|
306
|
-
${dim("Hints:")}`);
|
|
307
|
-
for (const h of result.hints) log(` ${dim("\u2022")} ${h}`);
|
|
308
|
-
}
|
|
309
|
-
entries.push({ label: custom.label, passed: false, error: result.error, hints: result.hints });
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
const passed = entries.every((e) => e.passed);
|
|
313
|
-
log("");
|
|
314
|
-
if (!passed) {
|
|
315
|
-
log(` ${warn("Some checks failed.")} Fix the issues above first.
|
|
316
|
-
`);
|
|
317
|
-
} else {
|
|
318
|
-
log(` ${ok("All checks passed.")}
|
|
319
|
-
`);
|
|
320
|
-
}
|
|
321
|
-
return { passed, checks: entries };
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
// src/run-log.ts
|
|
326
|
-
import { readFile, writeFile, mkdir, appendFile } from "fs/promises";
|
|
327
|
-
import { homedir } from "os";
|
|
328
|
-
import { join } from "path";
|
|
329
|
-
function runLogPath() {
|
|
330
|
-
return join(homedir(), RUN_LOG_DIR, RUN_LOG_FILE);
|
|
331
|
-
}
|
|
332
|
-
function runLogDir() {
|
|
333
|
-
return join(homedir(), RUN_LOG_DIR);
|
|
334
|
-
}
|
|
335
|
-
async function appendRunLog(entry) {
|
|
336
|
-
const dir = runLogDir();
|
|
337
|
-
await mkdir(dir, { recursive: true });
|
|
338
|
-
const path = runLogPath();
|
|
339
|
-
const line = JSON.stringify(entry) + "\n";
|
|
340
|
-
await appendFile(path, line, "utf8");
|
|
341
|
-
pruneRunLog(path).catch(() => {
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
async function readRunLog() {
|
|
345
|
-
try {
|
|
346
|
-
const raw = await readFile(runLogPath(), "utf8");
|
|
347
|
-
return raw.split("\n").filter(Boolean).map((line) => {
|
|
348
|
-
try {
|
|
349
|
-
return JSON.parse(line);
|
|
350
|
-
} catch {
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
}).filter((e) => e !== null);
|
|
354
|
-
} catch {
|
|
355
|
-
return [];
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
async function pruneRunLog(path) {
|
|
359
|
-
try {
|
|
360
|
-
const raw = await readFile(path, "utf8");
|
|
361
|
-
const lines = raw.split("\n").filter(Boolean);
|
|
362
|
-
if (lines.length <= RUN_LOG_MAX_ENTRIES) return;
|
|
363
|
-
const trimmed = lines.slice(lines.length - RUN_LOG_MAX_ENTRIES);
|
|
364
|
-
await writeFile(path, trimmed.join("\n") + "\n", "utf8");
|
|
365
|
-
} catch {
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
function redactArgs(argv) {
|
|
369
|
-
return argv.map(redactUrls);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// src/base-command.ts
|
|
373
|
-
var BaseCommand = class extends Command {
|
|
374
|
-
_startTime = 0;
|
|
375
|
-
_logWritten = false;
|
|
376
|
-
_checkSummaries;
|
|
377
|
-
/**
|
|
378
|
-
* Under --json, stdout carries the JSON and nothing else: every other line a
|
|
379
|
-
* command prints — preflight checks, progress — goes to stderr. Before, the
|
|
380
|
-
* text came first and the output did not parse.
|
|
381
|
-
*/
|
|
382
|
-
log(message = "", ...args) {
|
|
383
|
-
if (this.argv.includes("--json")) {
|
|
384
|
-
process.stderr.write(formatWithOptions({ colors: false }, message, ...args) + "\n");
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
super.log(message, ...args);
|
|
388
|
-
}
|
|
389
|
-
/** The command's result as JSON, on stdout. */
|
|
390
|
-
json(value) {
|
|
391
|
-
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
392
|
-
}
|
|
393
|
-
/** Call after scan() to attach per-check metadata to the run log entry. */
|
|
394
|
-
setCheckSummaries(summaries) {
|
|
395
|
-
this._checkSummaries = summaries;
|
|
396
|
-
}
|
|
397
|
-
async init() {
|
|
398
|
-
await super.init();
|
|
399
|
-
this._startTime = Date.now();
|
|
400
|
-
}
|
|
401
|
-
async catch(err) {
|
|
402
|
-
this._logWritten = true;
|
|
403
|
-
await this._writeRunLog("error", err.message);
|
|
404
|
-
return super.catch(err);
|
|
405
|
-
}
|
|
406
|
-
async finally(err) {
|
|
407
|
-
if (!this._logWritten) {
|
|
408
|
-
await this._writeRunLog(err ? "error" : "success", err?.message);
|
|
409
|
-
}
|
|
410
|
-
return super.finally(err);
|
|
411
|
-
}
|
|
412
|
-
async _writeRunLog(exitStatus, error) {
|
|
413
|
-
try {
|
|
414
|
-
const version = this.config?.version;
|
|
415
|
-
const argv = this.argv ?? [];
|
|
416
|
-
await appendRunLog({
|
|
417
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
418
|
-
command: this.id ?? "unknown",
|
|
419
|
-
args: redactArgs(argv),
|
|
420
|
-
durationMs: Date.now() - this._startTime,
|
|
421
|
-
exitStatus,
|
|
422
|
-
error,
|
|
423
|
-
version,
|
|
424
|
-
checkSummaries: this._checkSummaries
|
|
425
|
-
});
|
|
426
|
-
} catch {
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
/** Load config or exit with a helpful error. */
|
|
430
|
-
async loadConfigOrFail() {
|
|
431
|
-
try {
|
|
432
|
-
return await loadConfig();
|
|
433
|
-
} catch {
|
|
434
|
-
this.error(
|
|
435
|
-
'Could not load supaforge.config.json. Run "supaforge init" first.'
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Resolve a single environment by name.
|
|
441
|
-
* Accepts an explicit flag value or falls back to config.source.
|
|
442
|
-
*/
|
|
443
|
-
resolveEnv(config, envFlag) {
|
|
444
|
-
const envName = envFlag ?? config.source;
|
|
445
|
-
if (!envName) {
|
|
446
|
-
this.error('No environment specified. Use --env=<name> or set "source" in your config.');
|
|
447
|
-
}
|
|
448
|
-
const errors = validateSingleEnvConfig(config, envName);
|
|
449
|
-
if (errors.length > 0) {
|
|
450
|
-
this.error(`Invalid configuration:
|
|
451
|
-
${errors.join("\n ")}`);
|
|
452
|
-
}
|
|
453
|
-
return { envName, env: config.environments[envName] };
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Validate a two-env (source + target) config.
|
|
457
|
-
* Applies flag overrides before validation.
|
|
458
|
-
*/
|
|
459
|
-
validateDualEnvConfig(config, sourceFlag, targetFlag) {
|
|
460
|
-
if (sourceFlag) config.source = sourceFlag;
|
|
461
|
-
if (targetFlag) config.target = targetFlag;
|
|
462
|
-
const errors = validateConfig(config);
|
|
463
|
-
if (errors.length > 0) {
|
|
464
|
-
this.error(`Invalid configuration:
|
|
465
|
-
${errors.join("\n ")}`);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
/** Redact password from a database URL for display. */
|
|
469
|
-
redactUrl(url) {
|
|
470
|
-
return url.replace(/:([^@/]{1,})@/, ":***@");
|
|
471
|
-
}
|
|
472
|
-
/** Resolve the migrations directory from config (with default fallback). */
|
|
473
|
-
resolveMigrationsDir(config) {
|
|
474
|
-
return config.checks?.migrations?.dir ?? DEFAULT_MIGRATIONS_DIR;
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Create, run, and enforce a preflight check.
|
|
478
|
-
* Returns the Preflight instance for commands that need to add custom checks.
|
|
479
|
-
* When `abortMessage` is provided, exits with an error if checks fail.
|
|
480
|
-
*/
|
|
481
|
-
createPreflight(title) {
|
|
482
|
-
return new Preflight(title, (m) => this.log(m));
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Run a preflight and abort with a user-friendly message if it fails.
|
|
486
|
-
* Returns the report for commands that inspect individual check results.
|
|
487
|
-
*/
|
|
488
|
-
async runPreflight(preflight, commandName) {
|
|
489
|
-
const report = await preflight.run();
|
|
490
|
-
if (!report.passed) {
|
|
491
|
-
this.error(`${commandName} aborted \u2014 fix the issues above first.`, { exit: 1 });
|
|
492
|
-
}
|
|
493
|
-
return report;
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
export {
|
|
498
|
-
DEFAULT_LOCAL_PORT,
|
|
499
|
-
LOCAL_PG_USER,
|
|
500
|
-
LOCAL_PG_PASSWORD,
|
|
501
|
-
startLocalPg,
|
|
502
|
-
runLogPath,
|
|
503
|
-
readRunLog,
|
|
504
|
-
BaseCommand
|
|
505
|
-
};
|
|
506
|
-
//# sourceMappingURL=chunk-SF3YA42C.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/base-command.ts","../src/preflight.ts","../src/local-pg.ts","../src/run-log.ts"],"sourcesContent":["import { formatWithOptions } from 'node:util'\nimport { Command } from '@oclif/core'\nimport { loadConfig, validateConfig, validateSingleEnvConfig } from './config.js'\nimport { Preflight } from './preflight.js'\nimport { DEFAULT_MIGRATIONS_DIR } from './checks/migrations.js'\nimport type { SupaForgeConfig, EnvironmentConfig } from './types/config.js'\nimport type { PreflightReport } from './preflight.js'\nimport { appendRunLog, redactArgs, type RunLogCheckSummary } from './run-log.js'\n\n/**\n * Shared base for all supaforge commands.\n * Extracts config loading, env resolution, URL redaction, and run logging.\n */\nexport abstract class BaseCommand extends Command {\n\n private _startTime = 0\n private _logWritten = false\n private _checkSummaries?: RunLogCheckSummary[]\n\n /**\n * Under --json, stdout carries the JSON and nothing else: every other line a\n * command prints — preflight checks, progress — goes to stderr. Before, the\n * text came first and the output did not parse.\n */\n override log(message = '', ...args: unknown[]): void {\n if (this.argv.includes('--json')) {\n process.stderr.write(formatWithOptions({ colors: false }, message, ...args) + '\\n')\n return\n }\n super.log(message, ...args)\n }\n\n /** The command's result as JSON, on stdout. */\n protected json(value: unknown): void {\n process.stdout.write(JSON.stringify(value, null, 2) + '\\n')\n }\n\n /** Call after scan() to attach per-check metadata to the run log entry. */\n protected setCheckSummaries(summaries: RunLogCheckSummary[]): void {\n this._checkSummaries = summaries\n }\n\n override async init(): Promise<void> {\n await super.init()\n this._startTime = Date.now()\n }\n\n override async catch(err: Error): Promise<void> {\n this._logWritten = true\n await this._writeRunLog('error', err.message)\n return super.catch(err)\n }\n\n override async finally(err: Error | undefined): Promise<void> {\n if (!this._logWritten) {\n await this._writeRunLog(err ? 'error' : 'success', err?.message)\n }\n return super.finally(err)\n }\n\n private async _writeRunLog(exitStatus: 'success' | 'error', error?: string): Promise<void> {\n try {\n const version = this.config?.version\n const argv = this.argv ?? []\n await appendRunLog({\n timestamp: new Date().toISOString(),\n command: this.id ?? 'unknown',\n args: redactArgs(argv),\n durationMs: Date.now() - this._startTime,\n exitStatus,\n error,\n version,\n checkSummaries: this._checkSummaries,\n })\n } catch {\n // Never let logging failures surface to users\n }\n }\n\n /** Load config or exit with a helpful error. */\n protected async loadConfigOrFail(): Promise<SupaForgeConfig> {\n try {\n return await loadConfig()\n } catch {\n this.error(\n 'Could not load supaforge.config.json. Run \"supaforge init\" first.',\n )\n }\n }\n\n /**\n * Resolve a single environment by name.\n * Accepts an explicit flag value or falls back to config.source.\n */\n protected resolveEnv(\n config: SupaForgeConfig,\n envFlag?: string,\n ): { envName: string; env: EnvironmentConfig } {\n const envName = envFlag ?? config.source\n if (!envName) {\n this.error('No environment specified. Use --env=<name> or set \"source\" in your config.')\n }\n\n const errors = validateSingleEnvConfig(config, envName)\n if (errors.length > 0) {\n this.error(`Invalid configuration:\\n ${errors.join('\\n ')}`)\n }\n\n return { envName, env: config.environments[envName] }\n }\n\n /**\n * Validate a two-env (source + target) config.\n * Applies flag overrides before validation.\n */\n protected validateDualEnvConfig(\n config: SupaForgeConfig,\n sourceFlag?: string,\n targetFlag?: string,\n ): void {\n if (sourceFlag) config.source = sourceFlag\n if (targetFlag) config.target = targetFlag\n\n const errors = validateConfig(config)\n if (errors.length > 0) {\n this.error(`Invalid configuration:\\n ${errors.join('\\n ')}`)\n }\n }\n\n /** Redact password from a database URL for display. */\n protected redactUrl(url: string): string {\n return url.replace(/:([^@/]{1,})@/, ':***@')\n }\n\n /** Resolve the migrations directory from config (with default fallback). */\n protected resolveMigrationsDir(config: SupaForgeConfig): string {\n return config.checks?.migrations?.dir ?? DEFAULT_MIGRATIONS_DIR\n }\n\n /**\n * Create, run, and enforce a preflight check.\n * Returns the Preflight instance for commands that need to add custom checks.\n * When `abortMessage` is provided, exits with an error if checks fail.\n */\n protected createPreflight(title: string): Preflight {\n return new Preflight(title, (m) => this.log(m))\n }\n\n /**\n * Run a preflight and abort with a user-friendly message if it fails.\n * Returns the report for commands that inspect individual check results.\n */\n protected async runPreflight(preflight: Preflight, commandName: string): Promise<PreflightReport> {\n const report = await preflight.run()\n if (!report.passed) {\n this.error(`${commandName} aborted — fix the issues above first.`, { exit: 1 })\n }\n return report\n }\n}\n","import pg from 'pg'\nimport { detectRuntime } from './local-pg.js'\nimport { pgClientConfig, resolveConnectTimeoutMs } from './db.js'\nimport { DB_PROBE_TIMEOUT_MS } from './constants.js'\nimport { ok, warn, dim, cmd, bold } from './ui.js'\nimport { redactUrls, describeFailure } from './utils/error.js'\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Result of a single connectivity check. */\nexport interface ConnCheckResult {\n reachable: boolean\n version?: string\n error?: string\n}\n\n/** Outcome of a single preflight check (DB connectivity or custom). */\nexport interface CheckEntry {\n label: string\n passed: boolean\n detail?: string\n error?: string\n hints?: string[]\n}\n\n/** Full report returned by Preflight.run(). */\nexport interface PreflightReport {\n passed: boolean\n checks: CheckEntry[]\n}\n\n/** Supabase CLI default PostgreSQL port. */\nconst SUPABASE_LOCAL_PORT = '54322'\n\n/** Standard PostgreSQL port. */\nconst DEFAULT_PG_PORT = '5432'\n\n// ─── Standalone helpers (remain exported for direct use / tests) ─────────────\n\n/**\n * `pg`'s messages for the two bounds this module sets. Neither says what was\n * being waited for, and \"timeout expired\" in particular reads like a bug\n * rather than a diagnosis.\n */\nconst CONNECT_TIMEOUT_RE = /timeout expired|connection timeout/i\nconst QUERY_TIMEOUT_RE = /query read timeout/i\n\n/**\n * Replace a bare driver timeout with something that says which wait elapsed.\n *\n * Left untouched when it is not one of ours: a server-side `statement_timeout`\n * or an OS-level ETIMEDOUT is a different failure and already reads clearly.\n */\nexport function describeTimeout(message: string, connectTimeoutMs: number, probeTimeoutMs: number): string {\n if (CONNECT_TIMEOUT_RE.test(message)) {\n return `timed out after ${Math.round(connectTimeoutMs / 1000)}s connecting — the host accepted the connection but never completed the handshake`\n }\n if (QUERY_TIMEOUT_RE.test(message)) {\n return `timed out after ${Math.round(probeTimeoutMs / 1000)}s waiting for server response — connected, but the server did not answer`\n }\n return message\n}\n\n/**\n * Test that a PostgreSQL database is reachable and return the server version.\n *\n * Both waits are bounded. Without that, a host that accepts the connection and\n * then goes silent blocks here forever, and the command produces no output at\n * all past the `Checks:` header (issue #44).\n */\nexport async function checkConnection(dbUrl: string): Promise<ConnCheckResult> {\n const connectTimeoutMs = resolveConnectTimeoutMs()\n let client: pg.Client | undefined\n try {\n client = new pg.Client(pgClientConfig(dbUrl, DB_PROBE_TIMEOUT_MS))\n await client.connect()\n const { rows } = await client.query('SHOW server_version')\n const version = (rows[0] as Record<string, string>).server_version\n return { reachable: true, version }\n } catch (err) {\n return {\n reachable: false,\n error: describeTimeout(describeFailure(err), connectTimeoutMs, DB_PROBE_TIMEOUT_MS),\n }\n } finally {\n // A client that timed out mid-handshake still holds an open socket, which\n // keeps the event loop alive and hangs the process after the report has\n // already printed. end() on a never-connected client is a no-op, and a\n // failure closing it must not mask the real error above.\n try {\n await client?.end()\n } catch {\n // ignore\n }\n }\n}\n\n/** Errors that indicate the server IS running but rejecting the connection. */\nconst SERVER_REACHABLE_RE = /password authentication failed|does not exist|database .* does not exist|SSL.*required|no pg_hba\\.conf entry/i\n\n/**\n * Build context-aware hints when a local PostgreSQL is not reachable.\n * Detects Supabase CLI port, available container runtimes, etc.\n *\n * When `error` is provided and indicates the server IS running (auth failure,\n * missing database, SSL rejection), startup hints are suppressed in favour of\n * configuration hints.\n */\nexport async function buildLocalHints(dbUrl: string, error?: string): Promise<string[]> {\n const hints: string[] = []\n try {\n const urlObj = new URL(dbUrl)\n const isSupabasePort = urlObj.port === SUPABASE_LOCAL_PORT\n const isLocal = ['localhost', '127.0.0.1', '::1', ''].includes(urlObj.hostname)\n\n if (!isLocal) return hints\n\n // Server is reachable but rejecting — suggest config fixes, not startup.\n if (error && SERVER_REACHABLE_RE.test(error)) {\n hints.push(`Check the username and password in your database URL.`)\n if (isSupabasePort) {\n hints.push(`Port ${SUPABASE_LOCAL_PORT} is the Supabase CLI default. The default password is \"postgres\".`)\n }\n return hints\n }\n\n if (isSupabasePort) {\n hints.push(`Port ${SUPABASE_LOCAL_PORT} is the Supabase CLI default. Run ${cmd('\"supabase start\"')} to start your local Supabase instance.`)\n }\n\n const runtime = await detectRuntime()\n if (runtime) {\n hints.push(`${bold(runtime)} detected — you can start a PostgreSQL container manually.`)\n }\n\n if (!isSupabasePort) {\n hints.push(`Start PostgreSQL manually on port ${urlObj.port || DEFAULT_PG_PORT}.`)\n }\n } catch {\n // Invalid URL — no hints\n }\n return hints\n}\n\n/**\n * Hints for a connection that was bounded rather than refused.\n *\n * These apply to any host, unlike the local-startup hints — a stalled server\n * is just as likely to be a remote one behind a dropped tunnel, which is the\n * case that motivated bounding the wait at all (issue #44).\n */\nexport function buildTimeoutHints(): string[] {\n return [\n 'The host is listening but the database did not answer.',\n 'Check the database process is running and not paused, restarting, or overloaded.',\n 'Over a VPN or tunnel, check the connection is still up.',\n `Raise the bound with ${cmd('SUPAFORGE_CONNECT_TIMEOUT')} (in seconds) if the link is simply slow.`,\n ]\n}\n\n/**\n * Pick the right hints for a failed connection.\n *\n * A timeout and a refusal need different advice, and the local-startup hints\n * are actively misleading for a remote host that stalled.\n */\nexport async function buildConnectionHints(dbUrl: string, error?: string): Promise<string[]> {\n if (error && /timed out after \\d+s/.test(error)) return buildTimeoutHints()\n return buildLocalHints(dbUrl, error)\n}\n\n// ─── Preflight class ─────────────────────────────────────────────────────────\n\ntype LogFn = (msg: string) => void\n\n/**\n * Render a transient \"in progress\" line, or clear it when passed null.\n *\n * Separate from LogFn because these lines are overwritten rather than kept:\n * on a TTY the finished result replaces them, and off a TTY they are dropped\n * entirely so piped output and CI logs stay one line per check.\n */\nexport type PendingFn = (msg: string | null) => void\n\nconst defaultPending: PendingFn = (msg) => {\n if (!process.stdout.isTTY) return\n process.stdout.write(msg === null ? '\\r\\u001b[2K' : `\\r\\u001b[2K${msg}`)\n}\n\n/** Queued database to check during run(). */\ninterface DbEntry {\n label: string\n envName: string\n dbUrl: string\n}\n\n/** Custom check callback. Return null on success, or an error string on failure. */\nexport type CustomCheckFn = () => Promise<{ error?: string; detail?: string; hints?: string[] }>\n\n/** Queued custom check. */\ninterface CustomEntry {\n label: string\n fn: CustomCheckFn\n}\n\n/**\n * Composable preflight check runner.\n *\n * Usage:\n * ```ts\n * const pre = new Preflight('Diff preflight checks', (m) => this.log(m))\n * pre.addDatabase('Source', 'local', sourceUrl)\n * pre.addDatabase('Target', 'prod', targetUrl)\n * const report = await pre.run()\n * if (!report.passed) this.error('Aborted.', { exit: 1 })\n * ```\n *\n * For commands with extra checks (e.g. clone's pg_dump compat):\n * ```ts\n * pre.addCheck('pg_dump compatibility', async () => { ... })\n * ```\n */\nexport class Preflight {\n private readonly title: string\n private readonly log: LogFn\n private readonly pending: PendingFn\n private readonly databases: DbEntry[] = []\n private readonly customs: CustomEntry[] = []\n private readonly infoLines: Array<{ label: string; value: string }> = []\n\n constructor(title: string, log: LogFn, pending: PendingFn = defaultPending) {\n this.title = title\n this.log = log\n this.pending = pending\n }\n\n /** Register a database connectivity check. */\n addDatabase(label: string, envName: string, dbUrl: string): this {\n this.databases.push({ label, envName, dbUrl })\n return this\n }\n\n /** Add an informational line to the header (displayed after database lines). */\n addInfo(label: string, value: string): this {\n this.infoLines.push({ label, value })\n return this\n }\n\n /** Register a custom check (runs after all DB connectivity checks). */\n addCheck(label: string, fn: CustomCheckFn): this {\n this.customs.push({ label, fn })\n return this\n }\n\n /** Execute all registered checks, render results, and return the report. */\n async run(): Promise<PreflightReport> {\n const entries: CheckEntry[] = []\n const log = this.log\n\n // Header\n log(`\\n ${bold(this.title)}\\n`)\n for (const db of this.databases) {\n log(` ${db.label}: ${db.envName} ${dim(`(${redactUrls(db.dbUrl)})`)}`)\n }\n for (const info of this.infoLines) {\n log(` ${info.label}: ${info.value}`)\n }\n log('')\n log(' Checks:')\n\n // Database connectivity checks\n for (const db of this.databases) {\n // Named before the wait, not after: a connection that is merely slow\n // otherwise leaves the header on screen with no clue which of the two\n // environments is holding things up (issue #44).\n // The label is already the noun — \"Database\", \"Target\", \"Source\" — so\n // appending \"database\" gave \"Database database reachable\" (issue #97).\n this.pending(` ${dim(`… connecting to ${db.label.toLowerCase()}`)}`)\n const result = await checkConnection(db.dbUrl)\n this.pending(null)\n if (result.reachable) {\n log(` ${ok('✓')} ${db.label} reachable ${dim(`(PostgreSQL ${result.version})`)}`)\n entries.push({ label: db.label, passed: true, detail: `PostgreSQL ${result.version}` })\n } else {\n log(` ${warn('✗')} ${db.label} not reachable: ${redactUrls(describeFailure(result.error))}`)\n const hints = await buildConnectionHints(db.dbUrl, result.error)\n if (hints.length > 0) {\n log(`\\n ${dim('Hints:')}`)\n for (const h of hints) log(` ${dim('•')} ${h}`)\n }\n entries.push({ label: db.label, passed: false, error: result.error, hints })\n }\n }\n\n // Custom checks\n for (const custom of this.customs) {\n this.pending(` ${dim(`… ${custom.label}`)}`)\n const result = await custom.fn()\n this.pending(null)\n if (!result.error) {\n const suffix = result.detail ? ` ${dim(result.detail)}` : ''\n log(` ${ok('✓')} ${custom.label}${suffix}`)\n entries.push({ label: custom.label, passed: true, detail: result.detail })\n } else {\n log(` ${warn('✗')} ${custom.label}: ${redactUrls(describeFailure(result.error))}`)\n if (result.hints?.length) {\n log(`\\n ${dim('Hints:')}`)\n for (const h of result.hints) log(` ${dim('•')} ${h}`)\n }\n entries.push({ label: custom.label, passed: false, error: result.error, hints: result.hints })\n }\n }\n\n const passed = entries.every(e => e.passed)\n log('')\n if (!passed) {\n log(` ${warn('Some checks failed.')} Fix the issues above first.\\n`)\n } else {\n log(` ${ok('All checks passed.')}\\n`)\n }\n\n return { passed, checks: entries }\n }\n}\n","import { execFile } from 'node:child_process'\nimport { promisify } from 'node:util'\nimport pg from 'pg'\nimport { pgClientConfig } from './db.js'\nimport { RUNTIME_DETECT_TIMEOUT_MS, CONTAINER_RM_TIMEOUT_MS, CONTAINER_START_TIMEOUT_MS } from './constants'\n\nconst defaultExecFile = promisify(execFile)\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Injected exec function for testability. */\nexport type ExecFn = (\n cmd: string,\n args: string[],\n opts?: { timeout?: number },\n) => Promise<{ stdout: string; stderr: string }>\n\n/** Injected PostgreSQL connect function for readiness polling. */\nexport type ConnectFn = (url: string) => Promise<void>\n\n// ─── Constants ───────────────────────────────────────────────────────────────\n\n/** Default PostgreSQL image used for local containers. */\nexport const PG_IMAGE = 'docker.io/library/postgres:17'\n\n/** Default host port for the local PostgreSQL container. */\nexport const DEFAULT_LOCAL_PORT = 5432\n\n/** Default container name. */\nexport const CONTAINER_NAME = 'supaforge-local-pg'\n\n/** Default credentials for the local container. */\nexport const LOCAL_PG_USER = 'postgres'\nexport const LOCAL_PG_PASSWORD = 'postgres'\n\n/** Maximum retries when waiting for PostgreSQL readiness. */\nexport const READINESS_RETRIES = 30\n\n/** Delay between readiness checks (ms). */\nexport const READINESS_INTERVAL_MS = 2000\n\n// ─── Default implementations ────────────────────────────────────────────────\n\nasync function defaultConnectFn(url: string): Promise<void> {\n const client = new pg.Client(pgClientConfig(url))\n await client.connect()\n await client.end()\n}\n\n// ─── Container Runtime Detection ─────────────────────────────────────────────\n\nexport type ContainerRuntime = 'podman' | 'docker'\n\n/**\n * Detect the available container runtime.\n * Prefers podman (rootless, daemonless) over docker.\n * Returns null if neither is available.\n */\nexport async function detectRuntime(execFn: ExecFn = defaultExecFile): Promise<ContainerRuntime | null> {\n for (const rt of ['podman', 'docker'] as const) {\n try {\n await execFn(rt, ['--version'], { timeout: RUNTIME_DETECT_TIMEOUT_MS })\n return rt\n } catch {\n continue\n }\n }\n return null\n}\n\n// ─── Container Lifecycle ─────────────────────────────────────────────────────\n\nexport interface StartLocalPgOptions {\n /** Container runtime to use. Auto-detected if not provided. */\n runtime?: ContainerRuntime\n /** Host port to bind (default: 5432). */\n port?: number\n /** PostgreSQL password (default: 'postgres'). */\n password?: string\n /** Container name (default: 'supaforge-local-pg'). */\n name?: string\n /** PostgreSQL image (default: PG_IMAGE). */\n image?: string\n /** Injected exec function for testability. */\n execFn?: ExecFn\n /** Injected connect function for testability. */\n connectFn?: ConnectFn\n}\n\nexport interface LocalPgInfo {\n runtime: ContainerRuntime\n containerName: string\n port: number\n url: string\n}\n\n/**\n * Start a local PostgreSQL container using the detected runtime.\n *\n * Uses tmpfs for ephemeral storage (fast, no disk writes).\n * Waits for PostgreSQL to accept connections before returning.\n */\nexport async function startLocalPg(options: StartLocalPgOptions = {}): Promise<LocalPgInfo> {\n const exec = options.execFn ?? defaultExecFile\n const connect = options.connectFn ?? defaultConnectFn\n const runtime = options.runtime ?? await detectRuntime(exec)\n if (!runtime) {\n throw new Error(\n 'No container runtime found. Install Podman (recommended) or Docker.\\n' +\n ' Podman: https://podman.io/docs/installation\\n' +\n ' Docker: https://docs.docker.com/engine/install/',\n )\n }\n\n const port = options.port ?? DEFAULT_LOCAL_PORT\n const password = options.password ?? LOCAL_PG_PASSWORD\n const name = options.name ?? CONTAINER_NAME\n const image = options.image ?? PG_IMAGE\n\n // Check if container already exists and is running\n const existing = await getContainerStatus(runtime, name, exec)\n if (existing === 'running') {\n return {\n runtime,\n containerName: name,\n port,\n url: buildLocalUrl(port, password),\n }\n }\n\n // Remove stopped container with same name\n if (existing === 'stopped') {\n await exec(runtime, ['rm', '-f', name], { timeout: CONTAINER_RM_TIMEOUT_MS })\n }\n\n // Start the container\n const args = [\n 'run', '-d',\n '--name', name,\n '-p', `${port}:5432`,\n '-e', `POSTGRES_PASSWORD=${password}`,\n '-e', `POSTGRES_USER=${LOCAL_PG_USER}`,\n '--tmpfs', '/var/lib/postgresql/data',\n '--health-cmd', `pg_isready -U ${LOCAL_PG_USER}`,\n '--health-interval', '5s',\n '--health-timeout', '5s',\n '--health-retries', '20',\n '--health-start-period', '10s',\n image,\n ]\n\n try {\n await exec(runtime, args, { timeout: CONTAINER_START_TIMEOUT_MS })\n } catch (err) {\n throw new Error(\n `Failed to start PostgreSQL container via ${runtime}: ${(err as Error).message}`,\n )\n }\n\n // Wait for readiness using actual pg connection\n const url = buildLocalUrl(port, password)\n await waitForPg(url, connect)\n\n return { runtime, containerName: name, port, url }\n}\n\n/**\n * Stop and remove the local PostgreSQL container.\n */\nexport async function stopLocalPg(\n runtime?: ContainerRuntime,\n name: string = CONTAINER_NAME,\n execFn: ExecFn = defaultExecFile,\n): Promise<void> {\n const rt = runtime ?? await detectRuntime(execFn)\n if (!rt) return\n\n try {\n await execFn(rt, ['rm', '-f', name], { timeout: CONTAINER_RM_TIMEOUT_MS })\n } catch {\n // Container may not exist — ignore\n }\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\nasync function getContainerStatus(\n runtime: ContainerRuntime,\n name: string,\n execFn: ExecFn,\n): Promise<'running' | 'stopped' | 'none'> {\n try {\n const { stdout } = await execFn(\n runtime,\n ['inspect', '--format', '{{.State.Running}}', name],\n { timeout: RUNTIME_DETECT_TIMEOUT_MS },\n )\n return stdout.trim() === 'true' ? 'running' : 'stopped'\n } catch {\n return 'none'\n }\n}\n\nfunction buildLocalUrl(port: number, password: string): string {\n return `postgres://${LOCAL_PG_USER}:${password}@localhost:${port}/postgres`\n}\n\n/**\n * Poll PostgreSQL until it accepts connections.\n * Uses actual pg.Client connection rather than relying on container health checks\n * (which may not work on all runtimes).\n */\nasync function waitForPg(url: string, connectFn: ConnectFn): Promise<void> {\n for (let i = 0; i < READINESS_RETRIES; i++) {\n try {\n await connectFn(url)\n return\n } catch {\n await sleep(READINESS_INTERVAL_MS)\n }\n }\n throw new Error(\n `PostgreSQL at ${url} did not become ready within ${READINESS_RETRIES * READINESS_INTERVAL_MS / 1000}s`,\n )\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms))\n}\n","/**\n * Persistent command run log stored at ~/.supaforge/run-log.jsonl.\n *\n * Each entry is one JSON object per line (JSONL format) recording:\n * timestamp, command, args (with URLs redacted), duration, exitStatus, error.\n *\n * Used by `supaforge report` to show recent command history.\n * Entries older than RUN_LOG_MAX_ENTRIES are pruned automatically on append.\n */\nimport { readFile, writeFile, mkdir, appendFile } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport { redactUrls } from './utils/error.js'\nimport { RUN_LOG_MAX_ENTRIES, RUN_LOG_DIR, RUN_LOG_FILE } from './constants.js'\n\n/**\n * Per-check summary attached to diff/apply run log entries.\n * Contains only operational metadata — never SQL, table names, or data values.\n * Error strings are sanitized (URLs and file paths stripped) before storage.\n */\nexport interface RunLogCheckSummary {\n check: string\n status: string\n issueCount: number\n durationMs: number\n error?: string\n}\n\nexport interface RunLogEntry {\n timestamp: string\n command: string\n args: string[]\n durationMs: number\n exitStatus: 'success' | 'error'\n error?: string\n /** supaforge version that produced this entry */\n version?: string\n /** Populated by diff/apply: per-check status and counts, no SQL content. */\n checkSummaries?: RunLogCheckSummary[]\n}\n\n/** Full path to the run log file. */\nexport function runLogPath(): string {\n return join(homedir(), RUN_LOG_DIR, RUN_LOG_FILE)\n}\n\n/** Full path to the run log directory. */\nexport function runLogDir(): string {\n return join(homedir(), RUN_LOG_DIR)\n}\n\n/** Append a single run entry to the log. Prunes old entries if needed. */\nexport async function appendRunLog(entry: RunLogEntry): Promise<void> {\n const dir = runLogDir()\n await mkdir(dir, { recursive: true })\n const path = runLogPath()\n const line = JSON.stringify(entry) + '\\n'\n await appendFile(path, line, 'utf8')\n // Prune asynchronously — don't block command output\n pruneRunLog(path).catch(() => {})\n}\n\n/** Read all run log entries (most recent last). Returns [] if file doesn't exist. */\nexport async function readRunLog(): Promise<RunLogEntry[]> {\n try {\n const raw = await readFile(runLogPath(), 'utf8')\n return raw\n .split('\\n')\n .filter(Boolean)\n .map(line => {\n try { return JSON.parse(line) as RunLogEntry }\n catch { return null }\n })\n .filter((e): e is RunLogEntry => e !== null)\n } catch {\n return []\n }\n}\n\n/** Remove oldest entries, keeping at most RUN_LOG_MAX_ENTRIES. */\nasync function pruneRunLog(path: string): Promise<void> {\n try {\n const raw = await readFile(path, 'utf8')\n const lines = raw.split('\\n').filter(Boolean)\n if (lines.length <= RUN_LOG_MAX_ENTRIES) return\n const trimmed = lines.slice(lines.length - RUN_LOG_MAX_ENTRIES)\n await writeFile(path, trimmed.join('\\n') + '\\n', 'utf8')\n } catch {\n // Non-fatal\n }\n}\n\n/** Build a redacted args list safe for logging. Strips passwords from URLs. */\nexport function redactArgs(argv: string[]): string[] {\n return argv.map(redactUrls)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,yBAAyB;AAClC,SAAS,eAAe;;;ACDxB,OAAOA,SAAQ;;;ACAf,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,OAAO,QAAQ;AAIf,IAAM,kBAAkB,UAAU,QAAQ;AAiBnC,IAAM,WAAW;AAGjB,IAAM,qBAAqB;AAG3B,IAAM,iBAAiB;AAGvB,IAAM,gBAAgB;AACtB,IAAM,oBAAoB;AAG1B,IAAM,oBAAoB;AAG1B,IAAM,wBAAwB;AAIrC,eAAe,iBAAi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