@voltro/cli 0.43.1 → 0.44.0

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 (90) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/dist/{apiBuild-DF0f69Gf.js → apiBuild-DvWreIQP.js} +1 -1
  3. package/dist/apiBuild-XaW40W8x.js +2 -0
  4. package/dist/bin.js +1 -1
  5. package/dist/{build-LC_IJaHL.js → build-Ckc-FA7d.js} +6 -6
  6. package/dist/{checkCommand-DBpTSK8d.js → checkCommand-AlbawIal.js} +1 -1
  7. package/dist/{checkCommand-DDxwJCja.js → checkCommand-BNfEs4KG.js} +2 -2
  8. package/dist/{codegenCommand-LjxfK4Am.js → codegenCommand-iClXoRCW.js} +1 -1
  9. package/dist/{codemodRunner-Cnnz4-I7.js → codemodRunner-BKTnaGOz.js} +22 -0
  10. package/dist/{commands-CbQcuWsE.js → commands-fsnezHLH.js} +18 -18
  11. package/dist/{dashboardCommand-CAHjCe_9.js → dashboardCommand-DHDmlo9A.js} +1 -1
  12. package/dist/dataCommand-sfpGV694.js +867 -0
  13. package/dist/{dev-D0E5x2Ue.js → dev-BZO5aLdr.js} +1 -1
  14. package/dist/{dev-B2rZfqxw.js → dev-D-JZ6CGQ.js} +930 -916
  15. package/dist/doctorCommand-BeLOwq7S.js +2 -0
  16. package/dist/{doctorCommand-Ct_3BHgd.js → doctorCommand-BlUyESpD.js} +9 -9
  17. package/dist/{dormancyCommand-D1DKnYce.js → dormancyCommand-lQxdrU8C.js} +1 -1
  18. package/dist/{embeddingsCommand-1sZRBKlM.js → embeddingsCommand-ByBTju6X.js} +1 -1
  19. package/dist/{envCommand-7qjlQgLD.js → envCommand-CpCbYAgR.js} +1 -1
  20. package/dist/{evolveCommand-D5opB48I.js → evolveCommand-CBV3-TtK.js} +2 -2
  21. package/dist/index.js +1 -1
  22. package/dist/{infoCommand-Bs_8RU22.js → infoCommand-DJoA9cKD.js} +1 -1
  23. package/dist/{runtimeTrace-Wmi7V-wN.js → runtimeTrace-DJ9tPhrc.js} +1 -1
  24. package/dist/{sdkgen-DbTFGCjg.js → sdkgen-7dr8-Onw.js} +1 -1
  25. package/dist/serveCommand-BlnAlNQg.js +1891 -0
  26. package/dist/serveCommand-Dg_E1ev4.js +2 -0
  27. package/dist/serveEntry.js +1 -1
  28. package/dist/{updateCommand-CrI9B4d7.js → updateCommand-BvRidHp6.js} +1 -1
  29. package/dist/updateCommand-DcKVmLVN.js +2 -0
  30. package/dist/{webhooksCommand-BXUP5YjW.js → webhooksCommand-BfO_JF2b.js} +1 -1
  31. package/package.json +23 -17
  32. package/templates/AGENTS.md +1 -1
  33. package/templates/agent-docs/_index.md +1 -1
  34. package/templates/agent-docs/cli.md +144 -4
  35. package/templates/agent-docs/database/seedsdialects.md +12 -0
  36. package/templates/agent-docs/plugins/versioning.md +2 -0
  37. package/templates/agent-docs/whats-new.md +16 -51
  38. package/templates/apps/api-ai/package.json +7 -7
  39. package/templates/apps/api-auth/package.json +8 -8
  40. package/templates/apps/api-backend/package.json +7 -7
  41. package/templates/apps/api-backend-deactivation/package.json +7 -7
  42. package/templates/apps/api-backend-mail/package.json +8 -8
  43. package/templates/apps/api-backend-mariadb/package.json +9 -9
  44. package/templates/apps/api-backend-sqlite/package.json +8 -8
  45. package/templates/apps/api-backend-storage/package.json +8 -8
  46. package/templates/apps/api-cms/package.json +10 -10
  47. package/templates/apps/api-collab/package.json +8 -8
  48. package/templates/apps/api-data-advanced/package.json +8 -8
  49. package/templates/apps/api-durable/package.json +8 -8
  50. package/templates/apps/api-feature-flags/package.json +9 -9
  51. package/templates/apps/api-governance/package.json +8 -8
  52. package/templates/apps/api-kv/package.json +8 -8
  53. package/templates/apps/api-moderation/package.json +8 -8
  54. package/templates/apps/api-observability/package.json +8 -8
  55. package/templates/apps/api-ratelimit/package.json +8 -8
  56. package/templates/apps/api-rbac/package.json +8 -8
  57. package/templates/apps/api-rest/package.json +7 -7
  58. package/templates/apps/api-saas/package.json +11 -11
  59. package/templates/apps/api-saas-starter/package.json +10 -10
  60. package/templates/apps/api-search/package.json +8 -8
  61. package/templates/apps/api-status/package.json +8 -8
  62. package/templates/apps/api-versioning/package.json +8 -8
  63. package/templates/apps/api-webhooks/package.json +9 -9
  64. package/templates/apps/changelog/package.json +6 -6
  65. package/templates/apps/edge-functions/package.json +2 -2
  66. package/templates/apps/frontend-admin/package.json +8 -8
  67. package/templates/apps/frontend-app/package.json +9 -9
  68. package/templates/apps/frontend-auth/package.json +8 -8
  69. package/templates/apps/frontend-blank/package.json +7 -7
  70. package/templates/apps/frontend-cms/package.json +9 -9
  71. package/templates/apps/frontend-collab/package.json +10 -10
  72. package/templates/apps/frontend-contact/package.json +7 -7
  73. package/templates/apps/frontend-dashboard/package.json +7 -7
  74. package/templates/apps/frontend-docs/package.json +7 -7
  75. package/templates/apps/frontend-i18n/package.json +6 -6
  76. package/templates/apps/frontend-landing/package.json +7 -7
  77. package/templates/apps/frontend-portal/package.json +8 -8
  78. package/templates/apps/frontend-saas/package.json +8 -8
  79. package/templates/apps/frontend-spa/package.json +7 -7
  80. package/templates/apps/frontend-ssr/package.json +7 -7
  81. package/templates/apps/frontend-ssr-api/package.json +8 -8
  82. package/templates/apps/frontend-static-blog/package.json +6 -6
  83. package/templates/apps/frontend-status/package.json +8 -8
  84. package/templates/apps/mobile-app/package.json +4 -4
  85. package/dist/apiBuild-B7NgSMhX.js +0 -2
  86. package/dist/dataCommand-CrqvbVOv.js +0 -679
  87. package/dist/doctorCommand-CdsctSwg.js +0 -2
  88. package/dist/serveCommand-C8xzYCwa.js +0 -1776
  89. package/dist/serveCommand-CGNTXafv.js +0 -2
  90. package/dist/updateCommand-BvkKlV7D.js +0 -2
@@ -1,679 +0,0 @@
1
- import { t as e } from "./cliError-BmdYnghb.js";
2
- import { c as t, i as n, o as r } from "./dev-B2rZfqxw.js";
3
- import { n as i, t as a } from "./cliArgs-D4p8n7EE.js";
4
- import { r as o } from "./dialectDriver-czCHYpeH.js";
5
- import { t as s } from "./dataProfile-Cm0YVKSy.js";
6
- import { o as c, t as l } from "./inspectFetch-EMuhTG_9.js";
7
- import { r as u } from "./dbCommand-B237qI-j.js";
8
- import { createLogger as d } from "@voltro/logger";
9
- import { Effect as f, Stream as p } from "effect";
10
- import { SqlClient as m } from "@effect/sql";
11
- import { declaredSnapshot as h, fingerprintSchema as g, introspectSchema as _ } from "@voltro/database/sql";
12
- import { connectionIdentity as v, normaliseTarget as y, sameDatabase as b, streamTable as x } from "@voltro/database";
13
- import { STORAGE_REFS_TABLE as ee, resolveStorageProvider as S } from "@voltro/plugin-storage";
14
- import { assessLiveImport as te, backupArtifactName as C, backupCommand as ne, classificationFromSnapshot as re, decryptStream as w, encryptStream as ie, packBundle as T, peekBundle as E, previewMasking as ae, restoreCommand as D, runExport as O, runImport as k, runNativeStep as A, storageAssetSink as oe, storageAssetSource as se, storageBlobSink as ce, storageBlobSource as le, unpackBundle as ue, unpackBundleToDir as de } from "@voltro/data-transfer";
15
- //#region src/backupStamp.ts
16
- var j = "voltro-backup-stamp.json", fe = (e) => ({
17
- stampVersion: 1,
18
- dialect: e.dialect,
19
- schemaFingerprint: e.schemaFingerprint,
20
- voltroVersion: e.voltroVersion,
21
- createdAt: e.createdAt
22
- }), M = (e) => {
23
- let t;
24
- try {
25
- t = JSON.parse(e);
26
- } catch {
27
- return null;
28
- }
29
- if (typeof t != "object" || !t) return null;
30
- let n = t;
31
- if (n.stampVersion !== 1 || typeof n.dialect != "string" || typeof n.voltroVersion != "string" || typeof n.createdAt != "string") return null;
32
- let r = n.schemaFingerprint;
33
- return r !== null && typeof r != "string" ? null : {
34
- stampVersion: 1,
35
- dialect: n.dialect,
36
- schemaFingerprint: r,
37
- voltroVersion: n.voltroVersion,
38
- createdAt: n.createdAt
39
- };
40
- }, pe = (e) => {
41
- let { stamp: t, currentDialect: n, currentFingerprint: r } = e;
42
- if (t === null) return {
43
- warn: `no ${j} beside the dump — an older/handmade backup. Cannot verify dialect or schema version; make sure this dump is a ${n} dump.`,
44
- info: []
45
- };
46
- let i = [`backup produced by @voltro/cli ${t.voltroVersion} at ${t.createdAt}`, `schema fingerprint: ${t.schemaFingerprint ?? "<none recorded>"}`];
47
- return t.dialect === n ? t.schemaFingerprint !== null && r !== null && t.schemaFingerprint !== r ? {
48
- warn: `schema skew — the backup's schema (${t.schemaFingerprint.slice(0, 12)}) differs from what this code declares (${r.slice(0, 12)}). Run \`voltro db apply\` after the restore, or the app may boot against a schema it doesn't understand.`,
49
- info: i
50
- } : { info: i } : {
51
- refuse: `dialect mismatch — backup is a ${t.dialect} dump, but DB_DIALECT is ${n}. A cross-dialect restore is never valid.`,
52
- info: i
53
- };
54
- }, N = (e) => {
55
- try {
56
- let t = new URL(e), n = t.pathname.replace(/^\//, "");
57
- return `${t.hostname.toLowerCase()}:${t.port || "(default)"}/${n}`;
58
- } catch {
59
- return e.trim();
60
- }
61
- }, me = (e) => {
62
- let t = e.flagUrl ?? e.envUrl;
63
- if (t === void 0 || t.trim() === "") return {
64
- ok: !1,
65
- error: "no drill target — pass `--drill-url <url>` or set `DRILL_DB_URL`. The drill restores into a THROWAWAY database (never the live one), so it needs its own connection."
66
- };
67
- let n = N(t);
68
- return e.liveKeys.some((e) => e === n) ? {
69
- ok: !1,
70
- error: `drill target (${n}) is the LIVE database — a restore drill must target a throwaway DB, never production. It would --clean and overwrite it.`
71
- } : {
72
- ok: !0,
73
- url: t
74
- };
75
- }, he = (e) => {
76
- let { stampFingerprint: t, restoredFingerprint: n, restoredTableCount: r } = e;
77
- return r === 0 ? {
78
- pass: !1,
79
- lines: ["FAIL — the restore produced ZERO tables. The dump is empty or unreadable; this backup would NOT recover your app."]
80
- } : t !== null && n !== null && t !== n ? {
81
- pass: !1,
82
- lines: [`FAIL — restored ${r} table(s), but the schema fingerprint (${n.slice(0, 12)}) does NOT match the backup's stamp (${t.slice(0, 12)}).`, "The restore did not reproduce the schema that was backed up — the artifact is inconsistent."]
83
- } : t === null || n === null ? {
84
- pass: !0,
85
- lines: [`PASS (partial) — restored ${r} table(s) into the throwaway DB.`, "No stamped fingerprint to cross-check the schema shape (older/hand-made backup) — the bytes restore, but the shape was not verified."]
86
- } : {
87
- pass: !0,
88
- lines: [`PASS — restored ${r} table(s); schema fingerprint matches the backup stamp (${n.slice(0, 12)}).`]
89
- };
90
- }, P = d({ scope: "voltro:data" }), ge = async () => {
91
- try {
92
- let { createRequire: e } = await import("node:module"), { join: t } = await import("node:path"), { readFileSync: n } = await import("node:fs"), r = e(t(process.cwd(), "package.json")).resolve("@voltro/cli/package.json");
93
- return JSON.parse(n(r, "utf8")).version ?? "unknown";
94
- } catch {
95
- return "unknown";
96
- }
97
- }, F = async (e) => {
98
- try {
99
- return g(await H(e));
100
- } catch {
101
- return null;
102
- }
103
- }, I = (e) => {
104
- if (e.event !== "done") return;
105
- let t = e.total === void 0 ? "" : ` / ${e.total}`;
106
- P.info(`${e.phase} [${e.index + 1}/${e.tableCount}] ${e.table}`, { rows: `${e.rowsDone}${t}` });
107
- }, _e = async (e) => {
108
- let t = (e) => e?.meta?.databaseId;
109
- if (e) {
110
- let n = await l({
111
- name: "target",
112
- url: e
113
- }, "/_voltro/inspect/app");
114
- if (n.kind === "ok") return {
115
- label: e,
116
- databaseId: t(n.data)
117
- };
118
- }
119
- for (let e of await c()) {
120
- let n = await l(e, "/_voltro/inspect/app");
121
- if (n.kind === "ok") return {
122
- label: `${e.name} (${e.url})`,
123
- databaseId: t(n.data)
124
- };
125
- }
126
- return null;
127
- }, L = async (e) => {
128
- let t = e.includes("--allow-live"), n = t ? null : await _e(R(e, "--api-url")), i = v({
129
- dialect: B(),
130
- ...r()
131
- }), a = y({
132
- dialect: B(),
133
- ...r()
134
- }), { refuse: o, message: s } = te({
135
- liveInstance: n?.label ?? null,
136
- allowLive: t,
137
- sameTarget: b(i, n?.databaseId),
138
- ...a === void 0 ? {} : { targetLabel: `${a.host}:${a.port}/${a.database}` }
139
- });
140
- return !o || (P.error(s ?? "refusing: live instance detected"), !1);
141
- }, R = i, ve = [
142
- "--api-url",
143
- "--bundle-key",
144
- "--compression",
145
- "--consistency",
146
- "--drill-url",
147
- "--exclude",
148
- "--mode",
149
- "--on-conflict",
150
- "--passphrase",
151
- "--profile",
152
- "--tables",
153
- "--target",
154
- "--tenant",
155
- "--token"
156
- ], z = (e) => a(e, ve), B = () => {
157
- let t = (process.env.DB_DIALECT ?? "postgres").toLowerCase();
158
- if (t === "memory") throw new e("voltro data: requires a real dialect, not DB_DIALECT=memory.");
159
- return t;
160
- }, V = async (e, t) => {
161
- let n = (await o(e)).makeSqlLayer(t);
162
- return f.runPromise(m.SqlClient.pipe(f.flatMap(_), f.provide(n)));
163
- }, H = (e) => V(e, r()), ye = () => {
164
- let e = r(), t = [];
165
- return e.url && t.push(N(e.url)), (e.host || e.database) && t.push(`${(e.host ?? "localhost").toLowerCase()}:${e.port ?? "(default)"}/${e.database ?? ""}`), t;
166
- }, U = async () => {
167
- let r = process.cwd(), i = await t(r);
168
- if (!i) throw new e("voltro data: no app.config.ts found in the current directory.");
169
- let a = await n(i, void 0), o = B();
170
- return {
171
- store: a,
172
- snapshot: await H(o),
173
- dialect: o
174
- };
175
- }, W = (e) => x(e, {
176
- table: ee,
177
- chunkSize: 500
178
- }).pipe(p.map((e) => ({
179
- key: String(e.key),
180
- contentType: String(e.contentType ?? "application/octet-stream"),
181
- size: Number(e.size ?? 0)
182
- }))), G = (e) => !!e && e.endsWith(".vbundle"), K = (e) => R(e, "--passphrase") ?? process.env.VOLTRO_BUNDLE_KEY, be = (e) => e.includes("--encrypt") || R(e, "--passphrase") !== void 0 || process.env.VOLTRO_BUNDLE_KEY !== void 0, xe = async (e, t) => {
183
- let { createWriteStream: n } = await import("node:fs"), { pipeline: r } = await import("node:stream/promises"), { Readable: i } = await import("node:stream");
184
- await r(i.from(e), n(t));
185
- }, q = (e) => ({ async *[Symbol.asyncIterator]() {
186
- let { createReadStream: t } = await import("node:fs");
187
- for await (let n of t(e)) yield n instanceof Uint8Array ? n : new Uint8Array(n);
188
- } }), J = (e) => (e ?? "").split(",").map((e) => e.trim()).filter(Boolean), Se = (t, n) => {
189
- let r = R(t, "--tenant"), i = R(t, "--tables"), a = R(t, "--exclude");
190
- if (a !== void 0) {
191
- if (i !== void 0) throw new e("voltro data export: --exclude and --tables are two ways to say the same thing; use one.");
192
- if (r !== void 0) throw new e("voltro data export: --exclude does not apply to --tenant, whose table set is derived from the tenant closure.");
193
- let t = J(a), o = new Set(n), s = t.filter((e) => !o.has(e));
194
- if (s.length > 0) throw new e(`voltro data export: --exclude names ${s.length} table(s) that do not exist: ${s.join(", ")}. An exclusion that excludes nothing would leave the run looking like it worked.`);
195
- let c = new Set(t);
196
- return {
197
- kind: "tables",
198
- tables: n.filter((e) => !c.has(e))
199
- };
200
- }
201
- return r ? {
202
- kind: "tenant",
203
- tenantId: r
204
- } : i ? {
205
- kind: "tables",
206
- tables: J(i)
207
- } : { kind: "all" };
208
- }, Ce = async () => {
209
- let e = await u(process.cwd());
210
- return re(h(e));
211
- }, we = "voltro/tenant", Te = async () => {
212
- let e = (await u(process.cwd())).filter((e) => (e.appliedMixins ?? []).some((e) => e.id === we)).map((e) => e.tableName);
213
- return e.length > 0 ? e : void 0;
214
- }, Ee = (e) => {
215
- for (let t of e.tables) if (t.samples.length !== 0) {
216
- console.log(`\n ${t.table}`);
217
- for (let e of t.samples) console.log(` ${e.column} [${e.action}] ${JSON.stringify(e.before)} → ${JSON.stringify(e.after)}`);
218
- }
219
- if (e.leaks.length > 0) {
220
- console.log("\n ⚠ possible leaks in KEPT columns:");
221
- for (let t of e.leaks) console.log(` ${t.table}.${t.column} looks like ${t.pattern}: ${JSON.stringify(t.sample)}`);
222
- }
223
- if (e.unclassified.length > 0) {
224
- console.log("\n ✗ unclassified (would BLOCK a real export — add .sensitive()/.safe() or a policy override):");
225
- for (let t of e.unclassified) console.log(` ${t}`);
226
- } else console.log("\n ✓ every exported column is classified — safe to run.");
227
- }, De = async (e) => {
228
- let t = R(e, "--target") === "api", n = R(e, "--bundle-key"), r = z(e);
229
- if (!r && !(t && n)) return P.error("usage: voltro data export <outDir> [--target direct|api] [--api-url <url>] [--token <secret>] [--profile <name>] [--tenant <id>] [--tables a,b] [--exclude a,b] [--bundle-key <storage-key>] [--assets] [--compression zstd|gzip|none] [--consistency live|snapshot] [--dry-run]"), 1;
230
- if (t) {
231
- let t = R(e, "--api-url");
232
- if (!t) return P.error("--target api requires --api-url <url> (the running instance)"), 1;
233
- let i = R(e, "--token") ?? process.env.VOLTRO_DATA_TRANSFER_SECRET;
234
- if (!i) return P.error("--target api requires --token <secret> (or VOLTRO_DATA_TRANSFER_SECRET) matching the instance secret"), 1;
235
- if (R(e, "--exclude") !== void 0) return P.error("--exclude is a direct-target flag: it expands against the live table list, which --target api does not expose. Use --tables with the explicit set."), 1;
236
- let a = R(e, "--tables"), o = {
237
- ...R(e, "--profile") ? { profile: R(e, "--profile") } : {},
238
- ...R(e, "--tenant") ? { tenant: R(e, "--tenant") } : {},
239
- ...a ? { tables: a.split(",").map((e) => e.trim()).filter(Boolean) } : {},
240
- ...R(e, "--consistency") === "snapshot" ? { consistency: "snapshot" } : {},
241
- ...R(e, "--compression") ? { compression: R(e, "--compression") } : {},
242
- ...e.includes("--assets") ? { assets: !0 } : {},
243
- ...n ? { bundleKey: n } : {}
244
- }, s = await fetch(`${t.replace(/\/+$/, "")}/_voltro/admin/export`, {
245
- method: "POST",
246
- headers: {
247
- "content-type": "application/json",
248
- authorization: `Bearer ${i}`
249
- },
250
- body: JSON.stringify(o)
251
- });
252
- if (!s.ok) return P.error(`api export failed: HTTP ${s.status} — ${await s.text()}`), 1;
253
- if (n) return P.info("api export complete (pushed to storage)", {
254
- via: t,
255
- ...await s.json()
256
- }), 0;
257
- let { resolve: c } = await import("node:path"), l = new Uint8Array(await s.arrayBuffer());
258
- return await de((async function* () {
259
- yield l;
260
- })(), c(process.cwd(), r)), P.info("api export complete (downloaded from the running instance)", {
261
- outDir: r,
262
- tables: s.headers.get("x-export-tables") ?? void 0,
263
- rows: s.headers.get("x-export-rows") ?? void 0,
264
- masked: s.headers.get("x-export-masked") ?? void 0
265
- }), 0;
266
- }
267
- if (!r) return P.error("a <outDir> is required for a direct export"), 1;
268
- let i = R(e, "--profile"), a = i ? await s(i, { allowPath: !0 }) : {}, { store: o, snapshot: c, dialect: l } = await U(), u = e.includes("--assets") || a.assets === !0, d = u ? S({}) : void 0, p = R(e, "--compression") ?? a.compression, m = R(e, "--consistency") === "snapshot" ? "snapshot" : a.consistency ?? "live", h = a.masking, g = a.subset, _ = a.scope ?? Se(e, c.tables.map((e) => e.name)), v = h ? await Ce() : void 0, y = _.kind === "tenant" ? await Te() : void 0, b = y ? { tenantTables: y } : {};
269
- if (e.includes("--dry-run")) {
270
- let e = _.kind === "tables" && _.tables ? [..._.tables] : c.tables.map((e) => e.name);
271
- if (P.info("export DRY RUN — nothing was written", {
272
- outDir: r,
273
- tables: e.length,
274
- scope: _.kind,
275
- consistency: m,
276
- compression: p ?? "zstd",
277
- assets: u,
278
- masking: h ? "profile policy applies" : "none"
279
- }), P.info(`would export: ${e.join(", ")}`), !h) return 0;
280
- let t = await f.runPromise(ae({
281
- store: o,
282
- snapshot: c,
283
- masking: h,
284
- ...v ? { classification: v } : {},
285
- ...g ? {} : {
286
- scope: _,
287
- ...b
288
- }
289
- }));
290
- return Ee(t), +(t.unclassified.length > 0);
291
- }
292
- if (G(r)) {
293
- let t = await import("node:os"), n = await import("node:fs/promises"), { resolve: i, join: a } = await import("node:path"), s = await n.mkdtemp(a(t.tmpdir(), "voltro-export-"));
294
- try {
295
- let t = await f.runPromise(O({
296
- store: o,
297
- snapshot: c,
298
- dialect: l,
299
- outDir: s,
300
- ...g ? { subset: g } : {
301
- scope: _,
302
- ...b
303
- },
304
- consistency: m,
305
- ...p ? { compression: p } : {},
306
- ...h ? { masking: h } : {},
307
- ...v ? { classification: v } : {},
308
- onProgress: I
309
- })), n = T({
310
- dir: s,
311
- ...d ? { blobs: le(d, () => W(o)) } : {}
312
- }), a = be(e);
313
- if (a) {
314
- let t = K(e);
315
- if (!t) return P.error("--encrypt requires --passphrase <p> or VOLTRO_BUNDLE_KEY (a dedicated key, NOT the transfer secret)"), 1;
316
- n = ie(n, t);
317
- }
318
- return await xe(n, i(process.cwd(), r)), P.info("export complete (single file)", {
319
- file: r,
320
- encrypted: a,
321
- assets: u,
322
- tables: t.tables.length,
323
- rows: t.tables.reduce((e, t) => e + t.rowCount, 0)
324
- }), 0;
325
- } finally {
326
- await n.rm(s, {
327
- recursive: !0,
328
- force: !0
329
- });
330
- }
331
- }
332
- let x = await f.runPromise(O({
333
- store: o,
334
- snapshot: c,
335
- dialect: l,
336
- outDir: r,
337
- ...g ? { subset: g } : {
338
- scope: _,
339
- ...b
340
- },
341
- consistency: m,
342
- ...p ? { compression: p } : {},
343
- ...h ? { masking: h } : {},
344
- ...v ? { classification: v } : {},
345
- ...d ? { assets: se(d, () => W(o)) } : {},
346
- onProgress: I
347
- }));
348
- return P.info("export complete", {
349
- outDir: r,
350
- tables: x.tables.length,
351
- rows: x.tables.reduce((e, t) => e + t.rowCount, 0),
352
- assets: x.assets.count,
353
- compression: x.compression,
354
- ...x.masking ? { maskedColumns: x.masking.transformed.length } : {}
355
- }), 0;
356
- }, Y = () => "dry run checked: schema fit, cross-dialect portability, mode legality, the table selection. It did NOT read per-table checksums (those stream during the load) and cannot see conflicts that depend on the target's current rows.", X = (e) => {
357
- let t = R(e, "--tables");
358
- return {
359
- ...t ? { tables: t.split(",").map((e) => e.trim()).filter(Boolean) } : {},
360
- ...e.includes("--dry-run") ? { dryRun: !0 } : {}
361
- };
362
- }, Z = (e, t) => {
363
- if (e.includes("--dry-run")) {
364
- P.info("import DRY RUN — nothing was written", t), P.info(Y());
365
- return;
366
- }
367
- P.info("import complete", t);
368
- }, Oe = (e) => {
369
- let t = e;
370
- if (t?._tag !== "RowsRefusedError" || !Array.isArray(t.rows)) return;
371
- let n = t.rows, r = n.filter((e) => !e.derived), i = Number(t.totalCount ?? n.length), a = Number(t.primaryCount ?? r.length);
372
- P.error(`import refused ${i} row(s), of which ${a} are the actual failures — the rest could not land because a row they reference did not.`);
373
- for (let e of r) P.error(` ${e.table} ${e.id} ${e.reason}`);
374
- let o = i - a;
375
- o > 0 && P.error(` … and ${o} row(s) behind them. Fix the ${a} above and re-run; they resolve with their parents.`);
376
- }, ke = async (e) => {
377
- let t = R(e, "--target") === "api", n = R(e, "--bundle-key"), i = z(e);
378
- if (!i && !(t && n)) return P.error("usage: voltro data import <bundleDir> [--target direct|api] [--api-url <url>] [--token <secret>] [--bundle-key <storage-key>] [--tables a,b] [--mode upsert|append|replace] [--on-conflict skip|fail] [--atomic] [--assets] [--no-verify] [--force] [--allow-live] [--dry-run] (--force: import despite schema drift AND cross-dialect warnings; --dry-run: report what would move, write nothing)"), 1;
379
- let a = R(e, "--mode") ?? "upsert", o = R(e, "--on-conflict") ?? "skip";
380
- if (t) {
381
- let t = R(e, "--api-url");
382
- if (!t) return P.error("--target api requires --api-url <url> (the running instance)"), 1;
383
- let r = R(e, "--token") ?? process.env.VOLTRO_DATA_TRANSFER_SECRET;
384
- if (!r) return P.error("--target api requires --token <secret> (or VOLTRO_DATA_TRANSFER_SECRET) matching the instance secret"), 1;
385
- let s = R(e, "--tables"), c = {
386
- authorization: `Bearer ${r}`,
387
- "x-import-mode": a,
388
- "x-import-on-conflict": o,
389
- ...e.includes("--atomic") ? { "x-import-atomic": "1" } : {},
390
- ...e.includes("--force") ? { "x-import-force": "1" } : {},
391
- ...e.includes("--dry-run") ? { "x-import-dry-run": "1" } : {},
392
- ...s ? { "x-import-tables": s } : {}
393
- }, { resolve: l } = await import("node:path"), u;
394
- if (n) c["content-type"] = "application/json", u = JSON.stringify({ bundleKey: n });
395
- else if (G(i)) {
396
- let t = q(l(process.cwd(), i)), n = K(e);
397
- n && (t = w(t, n));
398
- let r = [];
399
- for await (let e of t) r.push(Buffer.from(e));
400
- c["content-type"] = "application/octet-stream", u = Buffer.concat(r);
401
- } else {
402
- await (await import("node:fs/promises")).access(l(process.cwd(), i, "assets", "index.ndjson")).then(() => !0, () => !1) && P.warn("this directory bundle has assets; --target api uploads DATA ONLY. Pack a single-file `.vbundle` (voltro data export <name>.vbundle --assets) to transfer assets over the API.");
403
- let e = [];
404
- for await (let t of T({ dir: l(process.cwd(), i) })) e.push(Buffer.from(t));
405
- c["content-type"] = "application/octet-stream", u = Buffer.concat(e);
406
- }
407
- let d = await fetch(`${t.replace(/\/+$/, "")}/_voltro/admin/import`, {
408
- method: "POST",
409
- body: u,
410
- headers: c
411
- });
412
- if (!d.ok) return P.error(`api import failed: HTTP ${d.status} — ${await d.text()}`), 1;
413
- let f = await d.json();
414
- return e.includes("--dry-run") ? (P.info("api import DRY RUN — nothing was written", {
415
- via: t,
416
- ...f
417
- }), P.info(Y()), 0) : (P.info("api import complete (imported by the running instance)", {
418
- via: t,
419
- ...f
420
- }), 0);
421
- }
422
- if (!i) return P.error("a <bundleDir> is required for a direct import"), 1;
423
- if (!await L(e)) return 1;
424
- let { store: s, snapshot: c } = await U(), l = e.includes("--force"), u = (e) => P.warn(e), d = e.includes("--assets") ? S({}) : void 0, p = B() === "postgres" ? (await import("@voltro/sql-postgres")).makePgCopySession(r()) : void 0;
425
- if (G(i)) {
426
- let t = await import("node:os"), n = await import("node:fs/promises"), { resolve: r, join: m } = await import("node:path"), h = await n.mkdtemp(m(t.tmpdir(), "voltro-import-"));
427
- try {
428
- let t = q(r(process.cwd(), i)), n = K(e);
429
- n && (t = w(t, n)), await ue(t, {
430
- dir: h,
431
- blobs: ce(d ?? S({}))
432
- });
433
- let m = await f.runPromise(k({
434
- store: s,
435
- bundleDir: h,
436
- mode: a,
437
- onConflict: o,
438
- atomic: e.includes("--atomic"),
439
- verify: !e.includes("--no-verify"),
440
- targetDialect: B(),
441
- allowIncompatible: l,
442
- targetSnapshot: c,
443
- force: l,
444
- onWarn: u,
445
- onProgress: I,
446
- assetsAlreadyRestored: !0,
447
- ...X(e),
448
- ...p ? { copyLoader: p } : {}
449
- }));
450
- return Z(e, {
451
- file: i,
452
- tables: m.tables.length,
453
- rows: m.tables.reduce((e, t) => e + t.rowCount, 0)
454
- }), 0;
455
- } finally {
456
- await p?.close(), await n.rm(h, {
457
- recursive: !0,
458
- force: !0
459
- });
460
- }
461
- }
462
- let m = await f.runPromise(k({
463
- store: s,
464
- bundleDir: i,
465
- mode: a,
466
- onConflict: o,
467
- atomic: e.includes("--atomic"),
468
- verify: !e.includes("--no-verify"),
469
- targetDialect: B(),
470
- allowIncompatible: l,
471
- targetSnapshot: c,
472
- force: l,
473
- onWarn: u,
474
- onProgress: I,
475
- ...X(e),
476
- ...d ? { assets: oe(d) } : {},
477
- ...p ? { copyLoader: p } : {}
478
- })).catch((e) => {
479
- throw Oe(e), e;
480
- }).finally(() => p?.close());
481
- return Z(e, {
482
- bundleDir: i,
483
- tables: m.tables.length,
484
- rows: m.tables.reduce((e, t) => e + t.rowCount, 0),
485
- assets: m.assets.count
486
- }), 0;
487
- }, Q = () => {
488
- let e = r();
489
- return {
490
- ...e.url ? { url: e.url } : {},
491
- ...e.host ? { host: e.host } : {},
492
- ...e.port ? { port: e.port } : {},
493
- ...e.username ? { username: e.username } : {},
494
- ...e.password ? { password: e.password } : {},
495
- ...e.database ? { database: e.database } : {}
496
- };
497
- }, Ae = async (e) => {
498
- let t = z(e);
499
- if (!t) return P.error("usage: voltro data backup <outDir> (native pg_dump/mysqldump/… + consistent artifact)"), 1;
500
- let n = B(), { mkdir: r, writeFile: i } = await import("node:fs/promises"), { join: a } = await import("node:path");
501
- await r(t, { recursive: !0 });
502
- let o = a(t, C(n));
503
- await f.runPromise(A(ne(n, Q(), o)));
504
- let s = fe({
505
- dialect: n,
506
- schemaFingerprint: await F(n),
507
- voltroVersion: await ge(),
508
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
509
- });
510
- return await i(a(t, j), `${JSON.stringify(s, null, 2)}\n`, "utf8"), P.info("native backup complete", {
511
- dialect: n,
512
- artifact: o,
513
- stamp: j,
514
- schemaFingerprint: s.schemaFingerprint ?? "<none>",
515
- assets: "NOT included — use `voltro data export --assets` for rows + blobs"
516
- }), 0;
517
- }, je = async (e, t) => {
518
- let n = B(), { join: r } = await import("node:path"), { readFile: i } = await import("node:fs/promises"), a = r(e, C(n)), o = me({
519
- flagUrl: R(t, "--drill-url"),
520
- envUrl: process.env.DRILL_DB_URL,
521
- liveKeys: ye()
522
- });
523
- if (!o.ok) return P.error(`restore --drill: ${o.error}`), 1;
524
- let s = await i(r(e, j), "utf8").then(M, () => null);
525
- if (s && s.dialect !== n) return P.error(`restore --drill: backup is a ${s.dialect} dump but DB_DIALECT is ${n} — cross-dialect restore is never valid.`), 1;
526
- P.info("restore drill: restoring into throwaway DB", {
527
- dialect: n,
528
- target: N(o.url)
529
- }), await f.runPromise(A(D(n, { url: o.url }, a)));
530
- let c = null, l = 0;
531
- try {
532
- let e = await V(n, { url: o.url });
533
- c = g(e), l = e.tables.length;
534
- } catch (e) {
535
- return P.error(`restore --drill: could not introspect the restored DB — ${String(e)}`), 1;
536
- }
537
- let u = he({
538
- stampFingerprint: s?.schemaFingerprint ?? null,
539
- restoredFingerprint: c,
540
- restoredTableCount: l
541
- });
542
- for (let e of u.lines) u.pass ? P.info(`restore drill: ${e}`) : P.error(`restore drill: ${e}`);
543
- return +!u.pass;
544
- }, Me = async (e) => {
545
- let t = z(e);
546
- if (!t) return P.error("usage: voltro data restore <backupDir> [--allow-live] [--api-url <url>] [--force] [--drill [--drill-url <url>]] (native pg_restore/mysql/…)"), 1;
547
- if (e.includes("--drill")) return je(t, e);
548
- if (!await L(e)) return 1;
549
- let n = B(), { join: r } = await import("node:path"), { readFile: i } = await import("node:fs/promises"), a = r(t, C(n)), o = pe({
550
- stamp: await i(r(t, j), "utf8").then(M, () => null),
551
- currentDialect: n,
552
- currentFingerprint: await F(n)
553
- });
554
- for (let e of o.info) P.info(`backup stamp: ${e}`);
555
- if (o.warn && P.warn(o.warn), o.refuse) {
556
- if (!e.includes("--force")) return P.error(`restore refused: ${o.refuse} (pass --force to override)`), 1;
557
- P.warn(`restore proceeding despite: ${o.refuse} (--force)`);
558
- }
559
- return await f.runPromise(A(D(n, Q(), a))), P.info("native restore complete", {
560
- dialect: n,
561
- artifact: a
562
- }), 0;
563
- }, Ne = async (e) => {
564
- let t = z(e);
565
- if (!t) return P.error("usage: voltro data inspect <file.vbundle|dir> [--json] [--passphrase <p>]"), 1;
566
- let { resolve: n, join: r } = await import("node:path"), i = await import("node:fs/promises"), a = n(process.cwd(), t);
567
- if ((await i.stat(a).catch(() => void 0))?.isDirectory()) {
568
- let n = r(a, "manifest.json"), o = r(a, "README.md");
569
- if (!e.includes("--json")) {
570
- let e = await i.readFile(o, "utf8").catch(() => void 0);
571
- if (e !== void 0) return console.log(e), 0;
572
- }
573
- let s = await i.readFile(n, "utf8").catch(() => void 0);
574
- return s === void 0 ? (P.error(`'${t}' is a directory but holds no manifest.json — is it an unpacked bundle? (a bundle exported with --target api is always unpacked into a directory, even when the path ends in .vbundle)`), 1) : (console.log(s), 0);
575
- }
576
- let o = K(e), s = () => {
577
- let e = q(a);
578
- return o ? w(e, o) : e;
579
- };
580
- if (e.includes("--json")) {
581
- let e = (await E(s(), ["manifest.json"])).get("manifest.json");
582
- return e ? (console.log(e.toString("utf8")), 0) : (P.error("no manifest.json found in the bundle"), 1);
583
- }
584
- let c = (await E(s(), ["README.md"])).get("README.md");
585
- if (c) return console.log(c.toString("utf8")), 0;
586
- let l = (await E(s(), ["manifest.json"])).get("manifest.json");
587
- return l ? (console.log(l.toString("utf8")), 0) : (P.error("bundle has no README.md or manifest.json"), 1);
588
- }, Pe = async (e) => {
589
- let t = z(e), n = z(e.filter((e) => e !== t));
590
- if (!t || !n) return P.error("usage: voltro data unpack <file.vbundle> <dir> [--passphrase <p>]"), 1;
591
- let { resolve: r } = await import("node:path"), i = q(r(process.cwd(), t)), a = K(e);
592
- return a && (i = w(i, a)), await de(i, r(process.cwd(), n)), P.info("unpack complete", {
593
- file: t,
594
- dir: n
595
- }), 0;
596
- }, $ = {
597
- export: {
598
- common: [
599
- "--target",
600
- "--tables",
601
- "--profile",
602
- "--tenant",
603
- "--assets",
604
- "--compression",
605
- "--consistency",
606
- "--json"
607
- ],
608
- directOnly: [
609
- "--exclude",
610
- "--passphrase",
611
- "--dry-run",
612
- "--encrypt"
613
- ],
614
- apiOnly: [
615
- "--api-url",
616
- "--token",
617
- "--bundle-key"
618
- ]
619
- },
620
- import: {
621
- common: [
622
- "--target",
623
- "--tables",
624
- "--mode",
625
- "--on-conflict",
626
- "--atomic",
627
- "--assets",
628
- "--force",
629
- "--dry-run",
630
- "--json"
631
- ],
632
- directOnly: [
633
- "--no-verify",
634
- "--allow-live",
635
- "--passphrase"
636
- ],
637
- apiOnly: [
638
- "--api-url",
639
- "--token",
640
- "--bundle-key"
641
- ]
642
- },
643
- unpack: { common: ["--passphrase", "--json"] },
644
- inspect: { common: ["--json", "--passphrase"] },
645
- backup: { common: ["--json", "--assets"] },
646
- restore: { common: [
647
- "--json",
648
- "--allow-live",
649
- "--force",
650
- "--drill",
651
- "--drill-url",
652
- "--api-url"
653
- ] }
654
- }, Fe = (e) => e.split("=")[0], Ie = (e, t) => {
655
- let n = $[e];
656
- if (!n) return;
657
- let r = R(t, "--target") === "api" ? "api" : "direct", i = /* @__PURE__ */ new Set([...n.common, ...r === "api" ? n.apiOnly ?? [] : n.directOnly ?? []]), a = new Set(r === "api" ? n.directOnly ?? [] : n.apiOnly ?? []);
658
- for (let n of t) {
659
- if (!n.startsWith("--")) continue;
660
- let t = Fe(n);
661
- if (i.has(t)) continue;
662
- if (a.has(t)) return `voltro data ${e}: ${t} is not read with --target ${r} (it is a --target ${r === "api" ? "direct" : "api"} flag). Remove it, or change --target.`;
663
- let o = Object.entries($).filter(([n, r]) => n !== e && [
664
- ...r.common,
665
- ...r.directOnly ?? [],
666
- ...r.apiOnly ?? []
667
- ].includes(t)).map(([e]) => e);
668
- return o.length > 0 ? `voltro data ${e}: ${t} is not a \`${e}\` flag (it belongs to \`voltro data ${o.join("` / `")}\`). Remove it.` : `voltro data ${e}: unknown flag ${t}. Run \`voltro data --help\` for the flags this command reads.`;
669
- }
670
- }, Le = async (e) => {
671
- let [t, ...n] = e;
672
- if (t !== void 0 && $[t] !== void 0) {
673
- let e = Ie(t, n);
674
- if (e) return P.error(e), 2;
675
- }
676
- return t === "export" ? De(n) : t === "import" ? ke(n) : t === "unpack" ? Pe(n) : t === "inspect" ? Ne(n) : t === "backup" ? Ae(n) : t === "restore" ? Me(n) : (P.error("usage: voltro data <export|import|unpack|inspect|backup|restore> … (logical: export/import; native: backup/restore)"), t ? 2 : 1);
677
- };
678
- //#endregion
679
- export { Le as runDataCommand };
@@ -1,2 +0,0 @@
1
- import { v as e, y as t } from "./doctorCommand-Ct_3BHgd.js";
2
- export { e as runDoctorCommand, t as runServePreflight };