@akal/supaforge 0.0.33 → 0.0.35

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.
Files changed (55) hide show
  1. package/README.md +67 -14
  2. package/dist/base-command.d.ts +1 -1
  3. package/dist/base-command.js +4 -3
  4. package/dist/{branch-C4ndfoj5.d.ts → branch-BppjQBv_.d.ts} +1 -1
  5. package/dist/{chunk-4IVN7QVY.js → chunk-44UVQJV2.js} +159 -18
  6. package/dist/{chunk-3HGAV5CC.js → chunk-4AGJRRBT.js} +390 -43
  7. package/dist/{chunk-SQPCWGQO.js → chunk-4M6OQLPO.js} +22 -121
  8. package/dist/{chunk-2SELREHW.js → chunk-5Q6LSLA3.js} +56 -9
  9. package/dist/{chunk-7NAZGZPV.js → chunk-7N63OPFN.js} +28 -21
  10. package/dist/chunk-AGONS5JJ.js +242 -0
  11. package/dist/chunk-GQPGH6YR.js +50 -0
  12. package/dist/{chunk-GEHPTPNZ.js → chunk-H2D3YSKM.js} +7 -3
  13. package/dist/{chunk-6Q7MHFBM.js → chunk-HNJ6BNNZ.js} +2 -2
  14. package/dist/{chunk-6WAMNZLO.js → chunk-KNXHLVF7.js} +126 -4
  15. package/dist/{chunk-DMIWAJRB.js → chunk-NEM5AEPQ.js} +172 -22
  16. package/dist/{chunk-6LJERPUN.js → chunk-NX2KKUS7.js} +20 -12
  17. package/dist/{chunk-SC2XHGIS.js → chunk-O5ERC2SE.js} +3 -3
  18. package/dist/{chunk-MIRLB5JM.js → chunk-SM7HP6EP.js} +64 -182
  19. package/dist/{chunk-BUOWHE36.js → chunk-T7GMPGUO.js} +613 -66
  20. package/dist/{chunk-G2DIPIYU.js → chunk-WK5YTINL.js} +29 -2
  21. package/dist/{chunk-UWAVXC57.js → chunk-WNTCZM2J.js} +34 -482
  22. package/dist/{chunk-GZREXCQZ.js → chunk-XLZCX6R2.js} +17 -10
  23. package/dist/{chunk-ORQJVE57.js → chunk-YWERIWFD.js} +18 -17
  24. package/dist/{chunk-NTUASFQ3.js → chunk-YZM76W22.js} +5 -5
  25. package/dist/{chunk-BLKJWDTL.js → chunk-ZI435CAU.js} +2 -2
  26. package/dist/commands/clone.d.ts +2 -2
  27. package/dist/commands/clone.js +14 -13
  28. package/dist/commands/diff.d.ts +37 -23
  29. package/dist/commands/diff.js +20 -17
  30. package/dist/commands/hukam.d.ts +2 -3
  31. package/dist/commands/hukam.js +16 -15
  32. package/dist/commands/init.d.ts +1 -1
  33. package/dist/commands/init.js +5 -1
  34. package/dist/commands/mcp.js +16 -10
  35. package/dist/commands/migrate/baseline.d.ts +1 -1
  36. package/dist/commands/migrate/baseline.js +5 -4
  37. package/dist/commands/migrate/create.d.ts +1 -1
  38. package/dist/commands/migrate/create.js +15 -9
  39. package/dist/commands/migrate/list.d.ts +1 -1
  40. package/dist/commands/migrate/list.js +6 -5
  41. package/dist/commands/migrate/run.d.ts +4 -1
  42. package/dist/commands/migrate/run.js +10 -8
  43. package/dist/commands/report.d.ts +1 -1
  44. package/dist/commands/report.js +5 -4
  45. package/dist/commands/restore.d.ts +1 -1
  46. package/dist/commands/restore.js +14 -13
  47. package/dist/commands/snapshot.d.ts +8 -1
  48. package/dist/commands/snapshot.js +37 -9
  49. package/dist/commands/sync.d.ts +2 -3
  50. package/dist/commands/sync.js +16 -15
  51. package/dist/{config-CTbeRlJk.d.ts → config-l3ggjw9r.d.ts} +2 -0
  52. package/dist/index.d.ts +21 -4
  53. package/dist/index.js +15 -15
  54. package/package.json +2 -2
  55. package/dist/chunk-DQQ5E563.js +0 -64
@@ -1,17 +1,21 @@
1
1
  import {
2
- normalizeRoles
3
- } from "./chunk-DQQ5E563.js";
2
+ assertPgBinUsable,
3
+ describeMissingPgDump,
4
+ getServerMajorVersion,
5
+ normalizeRoles,
6
+ resolvePgDumpPath
7
+ } from "./chunk-AGONS5JJ.js";
4
8
  import {
5
9
  Check,
6
- errMsg,
7
10
  inRolledBackTransaction,
11
+ newPgPool,
8
12
  pgClientConfig,
9
13
  pgQuery,
10
14
  quoteIdent,
11
15
  quoteLiteral,
12
16
  quoteName,
13
17
  readOrAbsent
14
- } from "./chunk-SQPCWGQO.js";
18
+ } from "./chunk-4M6OQLPO.js";
15
19
  import {
16
20
  DEFAULT_IGNORE_SCHEMAS,
17
21
  MIGRATIONS_SUBDIR,
@@ -21,171 +25,10 @@ import {
21
25
  SUPABASE_PLATFORM_SCHEMAS,
22
26
  SUPAFORGE_DIR,
23
27
  dim,
28
+ errMsg,
24
29
  ok,
25
30
  warn
26
- } from "./chunk-6WAMNZLO.js";
27
-
28
- // src/pg-tools.ts
29
- import { execFile } from "child_process";
30
- import { platform } from "os";
31
- import { existsSync } from "fs";
32
- import pg from "pg";
33
- function parsePgDumpVersion(output) {
34
- const m = output.match(/(\d+)(?:\.\d+)?/);
35
- return m ? Number(m[1]) : null;
36
- }
37
- function parseServerVersion(versionStr) {
38
- const m = versionStr.match(/^(\d+)/);
39
- return m ? Number(m[1]) : null;
40
- }
41
- async function getLocalPgDumpVersion() {
42
- return new Promise((resolve2) => {
43
- execFile("pg_dump", ["--version"], (err, stdout) => {
44
- if (err) return resolve2(null);
45
- resolve2(parsePgDumpVersion(stdout));
46
- });
47
- });
48
- }
49
- function getPgDumpVersionAt(path) {
50
- return new Promise((resolve2) => {
51
- execFile(path, ["--version"], (err, stdout) => {
52
- if (err) return resolve2(null);
53
- resolve2(parsePgDumpVersion(stdout));
54
- });
55
- });
56
- }
57
- var VERSIONED_PG_DIRS = [
58
- "/usr/lib/postgresql/{v}/bin",
59
- // Debian / Ubuntu (PGDG)
60
- "/opt/homebrew/opt/postgresql@{v}/bin",
61
- // macOS Homebrew (Apple Silicon)
62
- "/usr/local/opt/postgresql@{v}/bin",
63
- // macOS Homebrew (Intel)
64
- "/usr/pgsql-{v}/bin"
65
- // RHEL / CentOS (PGDG)
66
- ];
67
- async function resolvePgDumpPath(serverMajor) {
68
- const named = process.env.SUPAFORGE_PG_BIN?.trim();
69
- if (named) {
70
- if (!existsSync(`${named}/pg_dump`)) {
71
- throw new Error(`SUPAFORGE_PG_BIN is set to "${named}", which has no pg_dump`);
72
- }
73
- const major = await getPgDumpVersionAt(`${named}/pg_dump`);
74
- if (major !== null && major >= serverMajor) return { path: `${named}/pg_dump`, major };
75
- }
76
- const defaultMajor = await getLocalPgDumpVersion();
77
- if (defaultMajor !== null && defaultMajor >= serverMajor) {
78
- return { path: "pg_dump", major: defaultMajor };
79
- }
80
- for (const v of versionsToCheck(serverMajor)) {
81
- for (const tmpl of VERSIONED_PG_DIRS) {
82
- const dir = tmpl.replace("{v}", String(v));
83
- const candidate = `${dir}/pg_dump`;
84
- if (!existsSync(candidate)) continue;
85
- const major = await getPgDumpVersionAt(candidate);
86
- if (major !== null && major >= serverMajor) {
87
- return { path: candidate, major };
88
- }
89
- }
90
- }
91
- return null;
92
- }
93
- async function describeMissingPgDump(neededMajor) {
94
- const onPath = await getLocalPgDumpVersion();
95
- const named = process.env.SUPAFORGE_PG_BIN?.trim();
96
- const namedMajor = named ? await getPgDumpVersionAt(`${named}/pg_dump`) : null;
97
- const found = [
98
- onPath === null ? "none on PATH" : `${onPath} on PATH`,
99
- ...named ? [`${namedMajor ?? "none"} in SUPAFORGE_PG_BIN`] : []
100
- ].join(", ");
101
- return `no pg_dump ${neededMajor} or newer (found: ${found}); set SUPAFORGE_PG_BIN to a directory of PostgreSQL ${neededMajor}+ client tools`;
102
- }
103
- function resolvePgRestorePath(pgDumpPath) {
104
- if (pgDumpPath === "pg_dump") return "pg_restore";
105
- return pgDumpPath.replace(/pg_dump$/, "pg_restore");
106
- }
107
- function versionsToCheck(required) {
108
- const versions = [];
109
- for (let v = required + 3; v >= required; v--) {
110
- versions.push(v);
111
- }
112
- return versions;
113
- }
114
- async function getServerMajorVersion(dbUrl) {
115
- const client = new pg.Client(pgClientConfig(dbUrl));
116
- try {
117
- await client.connect();
118
- const { rows } = await client.query("SHOW server_version");
119
- const raw = rows[0].server_version;
120
- const major = parseServerVersion(raw);
121
- if (!major) throw new Error(`Could not parse server version: ${raw}`);
122
- return major;
123
- } finally {
124
- await client.end();
125
- }
126
- }
127
- async function checkPgDumpCompat(dbUrl) {
128
- const serverMajor = await getServerMajorVersion(dbUrl);
129
- const resolved = await resolvePgDumpPath(serverMajor);
130
- if (resolved) {
131
- return {
132
- localMajor: resolved.major,
133
- serverMajor,
134
- compatible: true,
135
- message: "",
136
- pgDumpPath: resolved.path,
137
- pgRestorePath: resolvePgRestorePath(resolved.path)
138
- };
139
- }
140
- const localMajor = await getLocalPgDumpVersion();
141
- const message = buildInstallMessage(localMajor, serverMajor);
142
- return {
143
- localMajor,
144
- serverMajor,
145
- compatible: false,
146
- message,
147
- pgDumpPath: "pg_dump",
148
- pgRestorePath: "pg_restore"
149
- };
150
- }
151
- function buildInstallMessage(localMajor, serverMajor) {
152
- const header = localMajor === null ? `pg_dump not found. The server is PostgreSQL ${serverMajor} \u2014 install postgresql-client-${serverMajor}:` : `pg_dump version mismatch: local v${localMajor}, server v${serverMajor}. Install postgresql-client-${serverMajor}:`;
153
- const instructions = getInstallInstructions(serverMajor);
154
- return `${header}
155
-
156
- ${instructions}`;
157
- }
158
- function getInstallInstructions(majorVersion) {
159
- const os = platform();
160
- const v = majorVersion;
161
- switch (os) {
162
- case "darwin":
163
- return [
164
- ` brew install postgresql@${v}`,
165
- ` # Then add to PATH:`,
166
- ` export PATH="/opt/homebrew/opt/postgresql@${v}/bin:$PATH"`
167
- ].join("\n");
168
- case "linux":
169
- return [
170
- ` # Debian / Ubuntu:`,
171
- ` sudo apt-get install -y postgresql-client-${v}`,
172
- ` # If the package is not found, add the PGDG repository first:`,
173
- ` # https://www.postgresql.org/download/linux/ubuntu/`,
174
- ``,
175
- ` # RHEL / Fedora:`,
176
- ` sudo dnf install -y postgresql${v}`
177
- ].join("\n");
178
- case "win32":
179
- return [
180
- ` # Download the installer from:`,
181
- ` # https://www.postgresql.org/download/windows/`,
182
- ` # Or use Chocolatey:`,
183
- ` choco install postgresql${v} --params '/Password:postgres'`
184
- ].join("\n");
185
- default:
186
- return ` Download PostgreSQL ${v} client tools from: https://www.postgresql.org/download/`;
187
- }
188
- }
31
+ } from "./chunk-KNXHLVF7.js";
189
32
 
190
33
  // src/snapshot.ts
191
34
  import { mkdir, writeFile, readFile, readdir, rm } from "fs/promises";
@@ -194,14 +37,13 @@ import { execFile as execFileCb } from "child_process";
194
37
  import { promisify } from "util";
195
38
 
196
39
  // src/schema-introspect.ts
197
- import pg2 from "pg";
198
40
  async function introspectSchema(dbUrl, ignoreSchemas, clientQueryFn) {
199
41
  let queryFn;
200
42
  let pool;
201
43
  if (clientQueryFn) {
202
44
  queryFn = clientQueryFn;
203
45
  } else {
204
- pool = new pg2.Pool({ ...pgClientConfig(dbUrl), max: 6 });
46
+ pool = newPgPool({ ...pgClientConfig(dbUrl), max: 6 });
205
47
  queryFn = async (sql, params) => {
206
48
  const { rows } = await pool.query(sql, params);
207
49
  return rows;
@@ -695,8 +537,41 @@ function diffPublications(source, target) {
695
537
  return issues;
696
538
  }
697
539
 
540
+ // src/utils/http.ts
541
+ function httpStatus(res) {
542
+ return [res.status, res.statusText].filter(Boolean).join(" ") || "with no status";
543
+ }
544
+ async function readJson(res, what) {
545
+ try {
546
+ return await res.json();
547
+ } catch {
548
+ throw new Error(`${what} answered HTTP ${httpStatus(res)} with a body that is not JSON`);
549
+ }
550
+ }
551
+ async function readJsonArray(res, what) {
552
+ const value = await readJson(res, what);
553
+ if (!Array.isArray(value)) throw new Error(`${what} answered with ${shapeOf(value)} where a list was expected`);
554
+ return value;
555
+ }
556
+ async function readJsonObject(res, what) {
557
+ const value = await readJson(res, what);
558
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
559
+ throw new Error(`${what} answered with ${shapeOf(value)} where an object was expected`);
560
+ }
561
+ return value;
562
+ }
563
+ function shapeOf(value) {
564
+ if (value === null) return "null";
565
+ if (Array.isArray(value)) return "a list";
566
+ if (typeof value === "object") {
567
+ const message = value.message;
568
+ return typeof message === "string" ? `an object saying "${message.slice(0, 120)}"` : "an object";
569
+ }
570
+ return `a ${typeof value}`;
571
+ }
572
+
698
573
  // src/snapshot.ts
699
- var execFile2 = promisify(execFileCb);
574
+ var execFile = promisify(execFileCb);
700
575
  function generateTimestamp() {
701
576
  return (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
702
577
  }
@@ -707,6 +582,7 @@ function snapshotDir(cwd, timestamp) {
707
582
  return join(snapshotsBaseDir(cwd), timestamp);
708
583
  }
709
584
  async function captureSnapshot(options) {
585
+ assertPgBinUsable();
710
586
  const cwd = options.cwd ?? process.cwd();
711
587
  const timestamp = generateTimestamp();
712
588
  const dir = options.outputDir ? join(resolve(options.outputDir), timestamp) : snapshotDir(cwd, timestamp);
@@ -738,11 +614,17 @@ async function captureSnapshot(options) {
738
614
  await writeFile(join(dir, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
739
615
  return { manifest, dir, timestamp };
740
616
  }
617
+ function unrestorableSchema(manifest) {
618
+ const schema = manifest.layers.schema;
619
+ return schema?.captured && schema.sqlSkipReason ? schema.sqlSkipReason : void 0;
620
+ }
741
621
  function formatSnapshotLayers(manifest) {
742
622
  const layers = manifest.layers;
743
623
  const lines = [];
744
624
  for (const [name, info] of Object.entries(layers)) {
745
- if (info.captured) {
625
+ if (info.captured && info.sqlSkipReason) {
626
+ lines.push(`${warn("\u26A0")} ${name.padEnd(16)} ${info.itemCount} item(s) ${warn(`\u2014 no schema.sql, so restore cannot recreate the schema: ${info.sqlSkipReason}`)}`);
627
+ } else if (info.captured) {
746
628
  lines.push(`${ok("\u2713")} ${name.padEnd(16)} ${info.itemCount} item(s)`);
747
629
  } else if (info.error) {
748
630
  lines.push(`${warn("\u2717")} ${name.padEnd(16)} ${warn(`error: ${info.error}`)}`);
@@ -801,10 +683,10 @@ async function captureSchemaSql(dir, dbUrl, schemas) {
801
683
  const resolved = await resolvePgDumpPath(serverMajor);
802
684
  if (!resolved) {
803
685
  return {
804
- sqlSkipReason: `no pg_dump new enough for this server (needs ${serverMajor} or later) \u2014 schema.json was still captured, but restore cannot replay the schema`
686
+ sqlSkipReason: `${await describeMissingPgDump(serverMajor)} \u2014 schema.json was still captured, but restore cannot replay the schema`
805
687
  };
806
688
  }
807
- const { stdout } = await execFile2(resolved.path, [
689
+ const { stdout } = await execFile(resolved.path, [
808
690
  dbUrl,
809
691
  "--schema-only",
810
692
  "--no-owner",
@@ -857,8 +739,8 @@ async function captureEdgeFunctions(dir, env, fetchFn) {
857
739
  const res = await fetchFn(url, {
858
740
  headers: { Authorization: `Bearer ${token}` }
859
741
  });
860
- if (!res.ok) throw new Error(res.statusText);
861
- const functions = await res.json();
742
+ if (!res.ok) throw new Error(`HTTP ${httpStatus(res)}`);
743
+ const functions = await readJsonArray(res, "The Edge Function list");
862
744
  await writeFile(join(dir, file), JSON.stringify(functions, null, 2) + "\n");
863
745
  return { captured: true, file, itemCount: functions.length };
864
746
  } catch (err) {
@@ -919,8 +801,8 @@ async function captureAuthConfig(dir, env, fetchFn) {
919
801
  const res = await fetchFn(url, {
920
802
  headers: { Authorization: `Bearer ${token}` }
921
803
  });
922
- if (!res.ok) throw new Error(res.statusText);
923
- const config = await res.json();
804
+ if (!res.ok) throw new Error(`HTTP ${httpStatus(res)}`);
805
+ const config = await readJsonObject(res, "The auth config");
924
806
  await writeFile(join(dir, file), JSON.stringify(config, null, 2) + "\n");
925
807
  return { captured: true, file, itemCount: Object.keys(config).length };
926
808
  } catch (err) {
@@ -1276,12 +1158,12 @@ export {
1276
1158
  diffSchemaPolicies,
1277
1159
  defaultCanonicalizer,
1278
1160
  dropEquivalentPolicyChanges,
1161
+ httpStatus,
1162
+ readJsonArray,
1163
+ readJsonObject,
1279
1164
  RealtimeCheck,
1280
- resolvePgDumpPath,
1281
- describeMissingPgDump,
1282
- getServerMajorVersion,
1283
- checkPgDumpCompat,
1284
1165
  captureSnapshot,
1166
+ unrestorableSchema,
1285
1167
  formatSnapshotLayers,
1286
1168
  loadSnapshot,
1287
1169
  findLatestSnapshot,
@@ -1289,4 +1171,4 @@ export {
1289
1171
  DEFAULT_KEEP_COUNT,
1290
1172
  pruneSnapshots
1291
1173
  };
1292
- //# sourceMappingURL=chunk-MIRLB5JM.js.map
1174
+ //# sourceMappingURL=chunk-SM7HP6EP.js.map