@voltro/cli 0.47.0 → 0.49.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 (101) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/dist/{apiBuild-FpHCWiv6.js → apiBuild-QmYHaCF4.js} +1 -1
  3. package/dist/apiBuild-dZbHdqMg.js +2 -0
  4. package/dist/bin.js +1 -1
  5. package/dist/{build-zVygXxGB.js → build-Bi4O_g7T.js} +6 -6
  6. package/dist/{checkCommand-D0dAKciE.js → checkCommand-D8vjQXQt.js} +3 -3
  7. package/dist/{checkCommand-B2Fw73lu.js → checkCommand-udbQpphy.js} +1 -1
  8. package/dist/{codegenCommand-BTtsnRus.js → codegenCommand-DApSH7hK.js} +39 -46
  9. package/dist/{codemodRunner-DSZjgyCL.js → codemodRunner-De1_316I.js} +562 -492
  10. package/dist/{commands-BrFKxnYW.js → commands-a5PxCaIg.js} +68 -60
  11. package/dist/{dashboardCommand-D9SjDc8E.js → dashboardCommand-DaoUUqJS.js} +1 -1
  12. package/dist/dataCommand-CJv_OMoS.js +1156 -0
  13. package/dist/dataProfile-Du3ztYxv.js +51 -0
  14. package/dist/{dbCommand-jbrmzwW_.js → dbCommand-Bf7Cy0mn.js} +5 -5
  15. package/dist/dbCommand-Bnl7MSGC.js +2 -0
  16. package/dist/declaredSchemaGates-BlcwObhb.js +25 -0
  17. package/dist/{dev-RjB7eE_B.js → dev-C31Nvlbv.js} +31 -30
  18. package/dist/{dev-CaIfZnw5.js → dev-DFVuzOj7.js} +1 -1
  19. package/dist/{doctorCommand-D7X29cw6.js → doctorCommand-B3uraeAe.js} +32 -14
  20. package/dist/doctorCommand-CPL6EhrW.js +2 -0
  21. package/dist/doctorDecidedSchema-BlbWgCD_.js +23 -0
  22. package/dist/{dormancyCommand-BGOP27fz.js → dormancyCommand-QUXQ9yoz.js} +1 -1
  23. package/dist/{embeddingsCommand-D72E22bw.js → embeddingsCommand-Zw1-rYSF.js} +1 -1
  24. package/dist/{envCommand-BHSxz6wC.js → envCommand-DtaJ4xEf.js} +1 -1
  25. package/dist/{evolveCommand-C2ofGGlz.js → evolveCommand-JDD3hE1i.js} +2 -2
  26. package/dist/{frameworkTableAssembly-BvZ0Lil_.js → frameworkTableAssembly-BwJVEKLr.js} +96 -119
  27. package/dist/frameworkTableAssembly-CVDB2hCq.js +2 -0
  28. package/dist/index.js +1 -1
  29. package/dist/{infoCommand-CuNl9cbh.js → infoCommand-COsUC1DB.js} +1 -1
  30. package/dist/{migrate-odCPGHPq.js → migrate-D3MK9BpK.js} +4 -4
  31. package/dist/{runtimeTrace-C_OKr0jY.js → runtimeTrace-Di6fcndp.js} +1 -1
  32. package/dist/{sdkgen-D9trW7sl.js → sdkgen-CIi5gM17.js} +1 -1
  33. package/dist/serveCommand-CzSDngKm.js +2 -0
  34. package/dist/serveCommand-N3udT49p.js +2362 -0
  35. package/dist/serveEntry.js +5 -5
  36. package/dist/{subcommandNames-CKG5Dz3a.js → subcommandNames-DpYs3DXr.js} +12 -2
  37. package/dist/{updateCommand-BlyXavoG.js → updateCommand-2BfbeMvp.js} +1 -1
  38. package/dist/updateCommand-CtYm7aKH.js +2 -0
  39. package/dist/{webhooksCommand-BqcWcbuW.js → webhooksCommand-CwX9IzvJ.js} +1 -1
  40. package/package.json +29 -17
  41. package/templates/AGENTS.md +1 -1
  42. package/templates/agent-docs/_index.md +1 -1
  43. package/templates/agent-docs/cli.md +117 -4
  44. package/templates/agent-docs/database/migrations.md +19 -5
  45. package/templates/agent-docs/whats-new.md +51 -14
  46. package/templates/apps/api-ai/package.json +7 -7
  47. package/templates/apps/api-auth/package.json +8 -8
  48. package/templates/apps/api-backend/package.json +7 -7
  49. package/templates/apps/api-backend-deactivation/package.json +7 -7
  50. package/templates/apps/api-backend-mail/package.json +8 -8
  51. package/templates/apps/api-backend-mariadb/package.json +9 -9
  52. package/templates/apps/api-backend-sqlite/package.json +8 -8
  53. package/templates/apps/api-backend-storage/package.json +8 -8
  54. package/templates/apps/api-cms/package.json +10 -10
  55. package/templates/apps/api-collab/package.json +8 -8
  56. package/templates/apps/api-data-advanced/package.json +8 -8
  57. package/templates/apps/api-durable/package.json +8 -8
  58. package/templates/apps/api-feature-flags/package.json +9 -9
  59. package/templates/apps/api-governance/package.json +8 -8
  60. package/templates/apps/api-kv/package.json +8 -8
  61. package/templates/apps/api-moderation/package.json +8 -8
  62. package/templates/apps/api-observability/package.json +8 -8
  63. package/templates/apps/api-ratelimit/package.json +8 -8
  64. package/templates/apps/api-rbac/package.json +8 -8
  65. package/templates/apps/api-rest/package.json +7 -7
  66. package/templates/apps/api-saas/package.json +11 -11
  67. package/templates/apps/api-saas-starter/package.json +10 -10
  68. package/templates/apps/api-search/package.json +8 -8
  69. package/templates/apps/api-status/package.json +8 -8
  70. package/templates/apps/api-versioning/package.json +8 -8
  71. package/templates/apps/api-webhooks/package.json +9 -9
  72. package/templates/apps/changelog/package.json +6 -6
  73. package/templates/apps/edge-functions/package.json +2 -2
  74. package/templates/apps/frontend-admin/package.json +8 -8
  75. package/templates/apps/frontend-app/package.json +9 -9
  76. package/templates/apps/frontend-auth/package.json +8 -8
  77. package/templates/apps/frontend-blank/package.json +7 -7
  78. package/templates/apps/frontend-cms/package.json +9 -9
  79. package/templates/apps/frontend-collab/package.json +10 -10
  80. package/templates/apps/frontend-contact/package.json +7 -7
  81. package/templates/apps/frontend-dashboard/package.json +7 -7
  82. package/templates/apps/frontend-docs/package.json +7 -7
  83. package/templates/apps/frontend-i18n/package.json +6 -6
  84. package/templates/apps/frontend-landing/package.json +7 -7
  85. package/templates/apps/frontend-portal/package.json +8 -8
  86. package/templates/apps/frontend-saas/package.json +8 -8
  87. package/templates/apps/frontend-spa/package.json +7 -7
  88. package/templates/apps/frontend-ssr/package.json +7 -7
  89. package/templates/apps/frontend-ssr-api/package.json +8 -8
  90. package/templates/apps/frontend-static-blog/package.json +6 -6
  91. package/templates/apps/frontend-status/package.json +8 -8
  92. package/templates/apps/mobile-app/package.json +4 -4
  93. package/dist/apiBuild-BsooZpw2.js +0 -2
  94. package/dist/dataCommand-Dl11q14e.js +0 -975
  95. package/dist/dataProfile-Cm0YVKSy.js +0 -18
  96. package/dist/dbCommand-BUD4Fd8v.js +0 -2
  97. package/dist/doctorCommand-5zv6PN-G.js +0 -2
  98. package/dist/frameworkTableAssembly-DDKtwsy2.js +0 -2
  99. package/dist/serveCommand-BU0wfV6V.js +0 -1931
  100. package/dist/serveCommand-Bwrn_9Fn.js +0 -2
  101. package/dist/updateCommand-CT5AvVg7.js +0 -2
@@ -0,0 +1,1156 @@
1
+ import { i as e, t } from "./subcommandNames-DpYs3DXr.js";
2
+ import { t as n } from "./cliError-BmdYnghb.js";
3
+ import { c as r, i, o as a, z as o } from "./dev-C31Nvlbv.js";
4
+ import { n as s, t as c } from "./cliArgs-D4p8n7EE.js";
5
+ import { r as l } from "./dialectDriver-czCHYpeH.js";
6
+ import { i as u, n as d, r as f, t as p } from "./dataProfile-Du3ztYxv.js";
7
+ import { o as m, t as h } from "./inspectFetch-EMuhTG_9.js";
8
+ import { r as g } from "./dbCommand-Bf7Cy0mn.js";
9
+ import { resolve as _ } from "node:path";
10
+ import { createLogger as v } from "@voltro/logger";
11
+ import { DATA_TRANSFERS_TABLE as y, connectionIdentity as b, normaliseTarget as x, sameDatabase as S, streamTable as C } from "@voltro/database";
12
+ import { Effect as w, Stream as ee } from "effect";
13
+ import { SqlClient as te } from "@effect/sql";
14
+ import { declaredSnapshot as ne, fingerprintSchema as re, introspectSchema as ie } from "@voltro/database/sql";
15
+ import { STORAGE_REFS_TABLE as ae, resolveStorageProvider as T } from "@voltro/plugin-storage";
16
+ import { createHash as oe } from "node:crypto";
17
+ import { asImportError as se, assessLiveImport as ce, backupArtifactName as E, backupCommand as le, classificationFromSnapshot as ue, decryptStream as D, encryptStream as de, packBundle as fe, peekBundle as O, previewMasking as pe, restoreCommand as k, runExport as me, runImport as he, runNativeStep as A, storageAssetSink as ge, storageAssetSource as _e, storageBlobSink as ve, storageBlobSource as ye, unpackBundle as be, unpackBundleToDir as xe } from "@voltro/data-transfer";
18
+ import { request as Se } from "node:http";
19
+ import { request as Ce } from "node:https";
20
+ //#region src/longRequest.ts
21
+ var we = /* @__PURE__ */ new Set([
22
+ "ECONNREFUSED",
23
+ "ETIMEDOUT",
24
+ "EHOSTUNREACH",
25
+ "ENETUNREACH",
26
+ "ENOTFOUND",
27
+ "ECONNRESET",
28
+ "EAI_AGAIN"
29
+ ]), j = class extends Error {
30
+ url;
31
+ cause;
32
+ constructor(e, t) {
33
+ let n = (() => {
34
+ try {
35
+ return new URL(e).host;
36
+ } catch {
37
+ return e;
38
+ }
39
+ })();
40
+ super(`the instance at ${n} is not answering (${t.code ?? "connect failed"}).`), this.url = e, this.cause = t, this.name = "InstanceUnreachable";
41
+ }
42
+ }, M = class extends Error {
43
+ elapsedMs;
44
+ url;
45
+ constructor(e, t) {
46
+ super(`no response after ${Math.round(e / 1e3)}s`), this.elapsedMs = e, this.url = t, this.name = "LongRequestTimeout";
47
+ }
48
+ }, N = async (e, t, n, r) => {
49
+ let i = new URL(e), a = i.protocol === "https:" ? Ce : Se, o = Date.now();
50
+ return await new Promise((s, c) => {
51
+ let l = a({
52
+ protocol: i.protocol,
53
+ hostname: i.hostname,
54
+ port: i.port === "" ? void 0 : Number(i.port),
55
+ path: `${i.pathname}${i.search}`,
56
+ method: "POST",
57
+ headers: n
58
+ }, (e) => {
59
+ let t = [];
60
+ e.on("data", (e) => t.push(e)), e.on("end", () => s({
61
+ status: e.statusCode ?? 0,
62
+ headers: Object.fromEntries(Object.entries(e.headers).map(([e, t]) => [e, Array.isArray(t) ? t.join(", ") : String(t ?? "")])),
63
+ body: Buffer.concat(t)
64
+ })), e.on("error", c);
65
+ });
66
+ if (r?.timeoutMs !== void 0 && r.timeoutMs > 0 && l.setTimeout(r.timeoutMs, () => {
67
+ l.destroy(new M(Date.now() - o, e));
68
+ }), l.on("error", (t) => c(we.has(t.code ?? "") ? new j(e, t) : t)), typeof t == "string" || Buffer.isBuffer(t)) {
69
+ l.end(t);
70
+ return;
71
+ }
72
+ (async () => {
73
+ try {
74
+ for await (let e of t) l.write(Buffer.from(e)) || await new Promise((e) => l.once("drain", () => e()));
75
+ l.end();
76
+ } catch (e) {
77
+ l.destroy(e);
78
+ }
79
+ })();
80
+ });
81
+ }, P = (e) => `${e.message}\n That address came from --api-url (or VOLTRO_API_URL) — it is the running instance, not the database.\n Nothing was sent, so nothing was imported. Check the instance is up and reachable from here\n (a VPN, an ingress or a stopped deployment are the usual three), e.g. curl -sS ${e.url}/_voltro/inspect/app`, Te = (e, t) => `the instance did not answer within ${Math.round(e.elapsedMs / 1e3)}s. This is a client-side deadline, not a failure on the server: the upload itself finished long before, and the response arrives only when the import does. The instance is very probably STILL IMPORTING and will finish.\n` + (t === "replace" ? " Do NOT simply re-run: --mode replace empties the target first, so a second run started while the first is mid-flight would empty it under the first one. Check the instance's log for the import's completion, and check the target's row counts, before deciding." : ` Re-running the same bundle is safe once the first run has finished (--mode ${t} is idempotent), but check the instance's log first — the work may already be done.`) + "\n To keep a deadline anyway, pass --timeout <seconds>; the default is to wait.", Ee = 16777216, De = async function* (e, t) {
82
+ let n = [], r = 0, i = 0, a = function* (e) {
83
+ let t = Buffer.concat(n);
84
+ n = [], r = 0;
85
+ let a = {
86
+ bytes: t,
87
+ offset: i,
88
+ final: e
89
+ };
90
+ i += t.byteLength, yield a;
91
+ };
92
+ for await (let a of e) for (n.push(Buffer.from(a)), r += a.byteLength; r >= t;) {
93
+ let e = Buffer.concat(n), a = e.subarray(0, t), o = e.subarray(t);
94
+ n = o.byteLength > 0 ? [Buffer.from(o)] : [], r = o.byteLength;
95
+ let s = {
96
+ bytes: Buffer.from(a),
97
+ offset: i,
98
+ final: !1
99
+ };
100
+ i += a.byteLength, yield s;
101
+ }
102
+ yield* a(!0);
103
+ }, Oe = (e) => oe("sha256").update(Buffer.from(e)).digest("hex"), ke = async (e) => {
104
+ let t = 0, n = 0, r = {
105
+ status: 0,
106
+ body: {}
107
+ };
108
+ for await (let i of De(e.stream, e.chunkBytes)) {
109
+ if (i.offset + i.bytes.byteLength <= e.alreadyHeld && !i.final) {
110
+ n++;
111
+ continue;
112
+ }
113
+ let a = Math.max(0, e.alreadyHeld - i.offset), o = a > 0 ? i.bytes.subarray(a) : i.bytes, s = i.offset + a;
114
+ if (o.byteLength === 0 && !i.final) {
115
+ n++;
116
+ continue;
117
+ }
118
+ if (i.final && e.onFinalChunk?.(), r = await e.target.send(Buffer.from(o), {
119
+ ...e.baseHeaders,
120
+ "content-type": "application/octet-stream",
121
+ "x-import-upload-id": e.uploadId,
122
+ "x-import-upload-key": e.key,
123
+ "x-import-chunk-offset": String(s),
124
+ ...i.final ? { "x-import-chunk-final": "1" } : {}
125
+ }), n++, t += o.byteLength, e.onProgress?.(t), r.status >= 400) break;
126
+ }
127
+ return {
128
+ status: r.status,
129
+ body: r.body,
130
+ chunks: n,
131
+ bytes: t,
132
+ resumedFrom: e.alreadyHeld
133
+ };
134
+ }, F = "voltro-backup-stamp.json", Ae = (e) => ({
135
+ stampVersion: 1,
136
+ dialect: e.dialect,
137
+ schemaFingerprint: e.schemaFingerprint,
138
+ voltroVersion: e.voltroVersion,
139
+ createdAt: e.createdAt
140
+ }), je = (e) => {
141
+ let t;
142
+ try {
143
+ t = JSON.parse(e);
144
+ } catch {
145
+ return null;
146
+ }
147
+ if (typeof t != "object" || !t) return null;
148
+ let n = t;
149
+ if (n.stampVersion !== 1 || typeof n.dialect != "string" || typeof n.voltroVersion != "string" || typeof n.createdAt != "string") return null;
150
+ let r = n.schemaFingerprint;
151
+ return r !== null && typeof r != "string" ? null : {
152
+ stampVersion: 1,
153
+ dialect: n.dialect,
154
+ schemaFingerprint: r,
155
+ voltroVersion: n.voltroVersion,
156
+ createdAt: n.createdAt
157
+ };
158
+ }, Me = (e) => {
159
+ let { stamp: t, currentDialect: n, currentFingerprint: r } = e;
160
+ if (t === null) return {
161
+ warn: `no ${F} beside the dump — an older/handmade backup. Cannot verify dialect or schema version; make sure this dump is a ${n} dump.`,
162
+ info: []
163
+ };
164
+ let i = [`backup produced by @voltro/cli ${t.voltroVersion} at ${t.createdAt}`, `schema fingerprint: ${t.schemaFingerprint ?? "<none recorded>"}`];
165
+ return t.dialect === n ? t.schemaFingerprint !== null && r !== null && t.schemaFingerprint !== r ? {
166
+ 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.`,
167
+ info: i
168
+ } : { info: i } : {
169
+ refuse: `dialect mismatch — backup is a ${t.dialect} dump, but DB_DIALECT is ${n}. A cross-dialect restore is never valid.`,
170
+ info: i
171
+ };
172
+ }, I = (e) => {
173
+ try {
174
+ let t = new URL(e), n = t.pathname.replace(/^\//, "");
175
+ return `${t.hostname.toLowerCase()}:${t.port || "(default)"}/${n}`;
176
+ } catch {
177
+ return e.trim();
178
+ }
179
+ }, Ne = (e) => {
180
+ let t = e.flagUrl ?? e.envUrl;
181
+ if (t === void 0 || t.trim() === "") return {
182
+ ok: !1,
183
+ 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."
184
+ };
185
+ let n = I(t);
186
+ return e.liveKeys.some((e) => e === n) ? {
187
+ ok: !1,
188
+ error: `drill target (${n}) is the LIVE database — a restore drill must target a throwaway DB, never production. It would --clean and overwrite it.`
189
+ } : {
190
+ ok: !0,
191
+ url: t
192
+ };
193
+ }, Pe = (e) => {
194
+ let { stampFingerprint: t, restoredFingerprint: n, restoredTableCount: r } = e;
195
+ return r === 0 ? {
196
+ pass: !1,
197
+ lines: ["FAIL — the restore produced ZERO tables. The dump is empty or unreadable; this backup would NOT recover your app."]
198
+ } : t !== null && n !== null && t !== n ? {
199
+ pass: !1,
200
+ 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."]
201
+ } : t === null || n === null ? {
202
+ pass: !0,
203
+ 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."]
204
+ } : {
205
+ pass: !0,
206
+ lines: [`PASS — restored ${r} table(s); schema fingerprint matches the backup stamp (${n.slice(0, 12)}).`]
207
+ };
208
+ }, L = v({ scope: "voltro:data" }), Fe = async () => {
209
+ try {
210
+ 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");
211
+ return JSON.parse(n(r, "utf8")).version ?? "unknown";
212
+ } catch {
213
+ return "unknown";
214
+ }
215
+ }, R = async (e) => {
216
+ try {
217
+ return re(await Be(e));
218
+ } catch {
219
+ return null;
220
+ }
221
+ }, z = (e) => {
222
+ if (e.event !== "done") return;
223
+ let t = e.total === void 0 ? "" : ` / ${e.total}`;
224
+ L.info(`${e.phase} [${e.index + 1}/${e.tableCount}] ${e.table}`, { rows: `${e.rowsDone}${t}` });
225
+ }, Ie = async (e) => {
226
+ let t = (e) => e?.meta?.databaseId;
227
+ if (e) {
228
+ let n = await h({
229
+ name: "target",
230
+ url: e
231
+ }, "/_voltro/inspect/app");
232
+ if (n.kind === "ok") return {
233
+ label: e,
234
+ databaseId: t(n.data)
235
+ };
236
+ }
237
+ for (let e of await m()) {
238
+ let n = await h(e, "/_voltro/inspect/app");
239
+ if (n.kind === "ok") return {
240
+ label: `${e.name} (${e.url})`,
241
+ databaseId: t(n.data)
242
+ };
243
+ }
244
+ return null;
245
+ }, Le = async (e) => {
246
+ let t = e.includes("--allow-live"), n = t ? null : await Ie(B(e, "--api-url")), r = b({
247
+ dialect: H(),
248
+ ...a()
249
+ }), i = x({
250
+ dialect: H(),
251
+ ...a()
252
+ }), { refuse: o, message: s } = ce({
253
+ liveInstance: n?.label ?? null,
254
+ allowLive: t,
255
+ sameTarget: S(r, n?.databaseId),
256
+ ...i === void 0 ? {} : { targetLabel: `${i.host}:${i.port}/${i.database}` }
257
+ });
258
+ return !o || (L.error(s ?? "refusing: live instance detected"), !1);
259
+ }, B = s, Re = [
260
+ "--api-url",
261
+ "--bundle-key",
262
+ "--compression",
263
+ "--consistency",
264
+ "--drill-url",
265
+ "--chunk-size",
266
+ "--exclude",
267
+ "--limit",
268
+ "--max-request-seconds",
269
+ "--mode",
270
+ "--no-atomic",
271
+ "--on-conflict",
272
+ "--passphrase",
273
+ "--profile",
274
+ "--tables",
275
+ "--target",
276
+ "--timeout",
277
+ "--tenant",
278
+ "--token"
279
+ ], V = (e) => c(e, Re), H = () => {
280
+ let e = (process.env.DB_DIALECT ?? "postgres").toLowerCase();
281
+ if (e === "memory") throw new n("voltro data: requires a real dialect, not DB_DIALECT=memory.");
282
+ return e;
283
+ }, ze = async (e, t) => {
284
+ let n = (await l(e)).makeSqlLayer(t);
285
+ return w.runPromise(te.SqlClient.pipe(w.flatMap(ie), w.provide(n)));
286
+ }, Be = (e) => ze(e, a()), Ve = () => {
287
+ let e = a(), t = [];
288
+ return e.url && t.push(I(e.url)), (e.host || e.database) && t.push(`${(e.host ?? "localhost").toLowerCase()}:${e.port ?? "(default)"}/${e.database ?? ""}`), t;
289
+ }, U = async () => {
290
+ let e = process.cwd(), t = await r(e);
291
+ if (!t) throw new n("voltro data: no app.config.ts found in the current directory.");
292
+ let a = await i(t, void 0), o = H();
293
+ return {
294
+ store: a,
295
+ snapshot: await Be(o),
296
+ dialect: o
297
+ };
298
+ }, W = (e) => C(e, {
299
+ table: ae,
300
+ chunkSize: 500
301
+ }).pipe(ee.map((e) => ({
302
+ key: String(e.key),
303
+ contentType: String(e.contentType ?? "application/octet-stream"),
304
+ size: Number(e.size ?? 0)
305
+ }))), G = (e) => !!e && e.endsWith(".vbundle"), K = (e) => B(e, "--passphrase") ?? process.env.VOLTRO_BUNDLE_KEY, He = (e) => e.includes("--encrypt") || B(e, "--passphrase") !== void 0 || process.env.VOLTRO_BUNDLE_KEY !== void 0, Ue = async (e, t) => {
306
+ let { createWriteStream: n } = await import("node:fs"), { pipeline: r } = await import("node:stream/promises"), { Readable: i } = await import("node:stream");
307
+ await r(i.from(e), n(t));
308
+ }, q = (e) => ({ async *[Symbol.asyncIterator]() {
309
+ let { createReadStream: t } = await import("node:fs");
310
+ for await (let n of t(e)) yield n instanceof Uint8Array ? n : new Uint8Array(n);
311
+ } }), We = async (e, t) => {
312
+ if (t !== void 0 || e === void 0) return null;
313
+ try {
314
+ let { resolve: t, join: n } = await import("node:path"), r = await import("node:fs/promises"), i = t(process.cwd(), e), a = G(e) ? (await O(q(i), ["manifest.json"])).get("manifest.json") : await r.readFile(n(i, "manifest.json"));
315
+ if (a === void 0) return null;
316
+ let o = (JSON.parse(Buffer.from(a).toString("utf8")).tables ?? []).map((e) => e.name).filter((e) => typeof e == "string");
317
+ return o.length > 0 ? o : null;
318
+ } catch {
319
+ return null;
320
+ }
321
+ }, Ge = (e) => {
322
+ let t = B(e, "--max-request-seconds") ?? process.env.VOLTRO_MAX_REQUEST_SECONDS;
323
+ if (t === void 0) return { pollMs: 2e3 };
324
+ let r = Number(t);
325
+ if (!Number.isFinite(r) || r <= 0) throw new n(`--max-request-seconds expects a positive number of seconds, got '${t}'`);
326
+ let i = Math.round(r * 1e3);
327
+ return {
328
+ perRequest: { timeoutMs: i },
329
+ pollMs: Math.max(500, Math.min(2e3, Math.floor(i / 2)))
330
+ };
331
+ }, Ke = async (e, t, n) => {
332
+ let r = await fetch(`${e.replace(/\/+$/, "")}/_voltro/admin/imports?limit=50`, { headers: { authorization: `Bearer ${t}` } }).catch(() => null);
333
+ if (r === null || r.status !== 200) return null;
334
+ let i = ((await r.json().catch(() => null))?.runs ?? []).find((e) => e.id === n);
335
+ return i === void 0 ? null : {
336
+ ...i,
337
+ startedAt: new Date(String(i.startedAt)),
338
+ finishedAt: i.finishedAt === null || i.finishedAt === void 0 ? null : new Date(String(i.finishedAt))
339
+ };
340
+ }, qe = async (e) => {
341
+ let t = e.apiUrl.replace(/\/+$/, ""), n = [], r = 0, i;
342
+ for (;;) {
343
+ let a = `${t}/_voltro/admin/export/download?runId=${encodeURIComponent(e.runId)}&offset=${r}`, o = new AbortController(), s = e.perRequest === void 0 ? void 0 : setTimeout(() => {
344
+ o.abort();
345
+ }, e.perRequest.timeoutMs), c;
346
+ try {
347
+ c = await fetch(a, {
348
+ headers: { authorization: `Bearer ${e.secret}` },
349
+ signal: o.signal
350
+ });
351
+ } catch (t) {
352
+ return e.log.error(`api export: fetching bytes at offset ${r} failed — ${t?.message ?? String(t)}. The bundle is still on the instance; re-run to resume from here.`), null;
353
+ } finally {
354
+ s !== void 0 && clearTimeout(s);
355
+ }
356
+ if (c.status !== 200) return e.log.error(`api export: the instance answered HTTP ${c.status} for the bytes at offset ${r} — ${await c.text()}`), null;
357
+ let l = Buffer.from(await c.arrayBuffer());
358
+ if (i ??= Number(c.headers.get("x-export-total-bytes") ?? "0"), n.push(l), r += l.byteLength, l.byteLength === 0 || i !== void 0 && r >= i) break;
359
+ e.log.info(` downloading — ${r}/${i ?? "?"} bytes`);
360
+ }
361
+ return new Uint8Array(Buffer.concat(n));
362
+ }, J = "transfers", Je = (e) => (e ?? "").split(",").map((e) => e.trim()).filter(Boolean), Ye = (e, t) => {
363
+ let r = B(e, "--tenant"), i = B(e, "--tables"), a = B(e, "--exclude");
364
+ if (a !== void 0) {
365
+ if (i !== void 0) throw new n("voltro data export: --exclude and --tables are two ways to say the same thing; use one.");
366
+ if (r !== void 0) throw new n("voltro data export: --exclude does not apply to --tenant, whose table set is derived from the tenant closure.");
367
+ let e = Je(a), o = new Set(t), s = e.filter((e) => !o.has(e));
368
+ if (s.length > 0) throw new n(`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.`);
369
+ return {
370
+ kind: "all",
371
+ exclude: e
372
+ };
373
+ }
374
+ return r ? {
375
+ kind: "tenant",
376
+ tenantId: r
377
+ } : i ? {
378
+ kind: "tables",
379
+ tables: Je(i)
380
+ } : { kind: "all" };
381
+ }, Xe = async () => {
382
+ let e = await g(process.cwd());
383
+ return ue(ne(e));
384
+ }, Ze = "voltro/tenant", Qe = async () => {
385
+ let e = (await g(process.cwd())).filter((e) => (e.appliedMixins ?? []).some((e) => e.id === Ze)).map((e) => e.tableName);
386
+ return e.length > 0 ? e : void 0;
387
+ }, $e = (e) => {
388
+ for (let t of e.tables) if (t.samples.length !== 0) {
389
+ console.log(`\n ${t.table}`);
390
+ for (let e of t.samples) console.log(` ${e.column} [${e.action}] ${JSON.stringify(e.before)} → ${JSON.stringify(e.after)}`);
391
+ }
392
+ if (e.leaks.length > 0) {
393
+ console.log("\n ⚠ possible leaks in KEPT columns:");
394
+ for (let t of e.leaks) console.log(` ${t.table}.${t.column} looks like ${t.pattern}: ${JSON.stringify(t.sample)}`);
395
+ }
396
+ if (e.unclassified.length > 0) {
397
+ console.log("\n ✗ unclassified (would BLOCK a real export — add .sensitive()/.safe() or a policy override):");
398
+ for (let t of e.unclassified) console.log(` ${t}`);
399
+ } else console.log("\n ✓ every exported column is classified — safe to run.");
400
+ }, et = async (e) => {
401
+ let { resolve: t, join: r } = await import("node:path"), i = await import("node:fs/promises"), a = B(e.args, "--chunk-size"), o = a === void 0 ? Ee : Math.round(Number(a) * 1024 * 1024);
402
+ if (!Number.isFinite(o) || o <= 0) throw new n(`--chunk-size expects a positive number of megabytes, got '${String(a)}'`);
403
+ let s = e.stream[Symbol.asyncIterator](), c = [], l = 0, u = !1;
404
+ for (; l <= o;) {
405
+ let e = await s.next();
406
+ if (e.done === !0) {
407
+ u = !0;
408
+ break;
409
+ }
410
+ c.push(Buffer.from(e.value)), l += e.value.byteLength;
411
+ }
412
+ if (u && l <= o) return {
413
+ kind: "small",
414
+ body: Buffer.concat(c)
415
+ };
416
+ let d = t(process.cwd(), e.bundleDir), f = Oe(G(e.bundleDir) ? await i.readFile(d) : await i.readFile(r(d, "manifest.json"))), p = `up-${f.slice(0, 32)}`, m = await N(e.url, Buffer.alloc(0), {
417
+ ...e.headers,
418
+ "x-import-upload-id": p,
419
+ "x-import-probe": "1"
420
+ }, X(e.args)), h = m.status === 200 ? Number(JSON.parse(m.body.toString("utf8")).bytes ?? 0) : 0;
421
+ h > 0 && e.log.info("api import: resuming a chunked upload the instance already holds", { bytes: h });
422
+ let g = (async function* () {
423
+ for (let e of c) yield e;
424
+ for (;;) {
425
+ let e = await s.next();
426
+ if (e.done === !0) return;
427
+ yield e.value;
428
+ }
429
+ })(), _ = 0, v = await ke({
430
+ stream: g,
431
+ chunkBytes: o,
432
+ uploadId: p,
433
+ key: f,
434
+ alreadyHeld: h,
435
+ baseHeaders: e.headers,
436
+ onProgress: (t) => {
437
+ _++, e.log.info(`api import: uploading — chunk ${_}, ${Math.round(t / 1024)} KiB sent`);
438
+ },
439
+ onFinalChunk: () => {
440
+ e.log.info("api import: upload done — the instance is importing now. This request stays open until it finishes, which on a full bundle is minutes, and nothing more is printed until then. It is not a hang; the instance logs the import itself.");
441
+ },
442
+ target: { send: async (t, n) => {
443
+ let r = await N(e.url, t, n, X(e.args)), i = {};
444
+ try {
445
+ i = JSON.parse(r.body.toString("utf8") || "{}");
446
+ } catch {}
447
+ return {
448
+ status: r.status,
449
+ body: i
450
+ };
451
+ } }
452
+ });
453
+ return e.log.info("api import: uploaded in chunks", {
454
+ chunks: v.chunks,
455
+ bytes: v.bytes,
456
+ ...v.resumedFrom > 0 ? { resumedFrom: v.resumedFrom } : {}
457
+ }), {
458
+ kind: "sent",
459
+ res: {
460
+ status: v.status,
461
+ headers: {},
462
+ body: Buffer.from(JSON.stringify(v.body))
463
+ }
464
+ };
465
+ }, tt = (e) => `--mode replace with --no-atomic against a ${e ? "RUNNING instance" : "live database"}: the target is empty between the delete and the load, and anything the application writes in that window can collide with a row from the bundle — or survive the import as a row the bundle never carried. Drop --no-atomic to run the whole load in one transaction (concurrent writers then wait instead of racing), or stop the traffic for the duration.`, Y = (e, t) => e.includes("--no-atomic") ? !1 : e.includes("--atomic") || t === "replace", nt = (e, t, n) => {
466
+ if (t !== "replace" || e.includes("--no-rollback")) return;
467
+ let r = B(e, "--rollback-dir");
468
+ return r === void 0 ? o(n) : _(r);
469
+ }, rt = (e, t, n) => {
470
+ let r = nt(e, t, n);
471
+ return {
472
+ ...r === void 0 ? {} : { rollbackDir: r },
473
+ recordInterruption: !0,
474
+ via: "direct"
475
+ };
476
+ }, X = (e) => {
477
+ let t = B(e, "--timeout");
478
+ if (t === void 0) return {};
479
+ let r = Number(t);
480
+ if (!Number.isFinite(r) || r <= 0) throw new n(`--timeout expects a positive number of seconds, got '${t}'`);
481
+ return { timeoutMs: Math.round(r * 1e3) };
482
+ }, it = async (e) => {
483
+ let t = B(e, "--target") === "api", n = B(e, "--bundle-key"), r = V(e);
484
+ if (!r && !(t && n)) return L.error("usage: voltro data export <outDir> [--target direct|api] [--api-url <url>] [--token <secret>] [--timeout <seconds>] [--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;
485
+ if (t) {
486
+ let t = B(e, "--api-url");
487
+ if (!t) return L.error("--target api requires --api-url <url> (the running instance)"), 1;
488
+ let i = B(e, "--token") ?? process.env.VOLTRO_DATA_TRANSFER_SECRET;
489
+ if (!i) return L.error("--target api requires --token <secret> (or VOLTRO_DATA_TRANSFER_SECRET) matching the instance secret"), 1;
490
+ let a = B(e, "--tables"), o = B(e, "--exclude");
491
+ if (o !== void 0 && a !== void 0) return L.error("voltro data export: --exclude and --tables are two ways to say the same thing; use one."), 1;
492
+ let s = {
493
+ ...B(e, "--profile") ? { profile: B(e, "--profile") } : {},
494
+ ...B(e, "--tenant") ? { tenant: B(e, "--tenant") } : {},
495
+ ...a ? { tables: a.split(",").map((e) => e.trim()).filter(Boolean) } : {},
496
+ ...o ? { exclude: o.split(",").map((e) => e.trim()).filter(Boolean) } : {},
497
+ ...B(e, "--consistency") === "snapshot" ? { consistency: "snapshot" } : {},
498
+ ...B(e, "--compression") ? { compression: B(e, "--compression") } : {},
499
+ ...e.includes("--assets") ? { assets: !0 } : {},
500
+ ...n ? { bundleKey: n } : {}
501
+ }, c = Ge(e), l;
502
+ try {
503
+ let n = await N(`${t.replace(/\/+$/, "")}/_voltro/admin/export`, JSON.stringify(s), {
504
+ "content-type": "application/json",
505
+ authorization: `Bearer ${i}`
506
+ }, c.perRequest ?? X(e));
507
+ if (n.status < 200 || n.status >= 300) return L.error(`api export failed: HTTP ${n.status} — ${n.body.toString("utf8")}`), 1;
508
+ l = JSON.parse(n.body.toString("utf8"));
509
+ } catch (e) {
510
+ if (e instanceof M) return L.error(`api export: the instance did not answer within ${Math.round(e.elapsedMs / 1e3)}s. That is a client-side deadline. Nothing was written locally; re-run, or raise --timeout.`), 1;
511
+ if (e instanceof j) return L.error(`api export: ${P(e)}`), 1;
512
+ throw e;
513
+ }
514
+ if (e.includes("--detach")) return L.info(`api export: started as ${l.runId}. NOT waiting for it.\n The outcome is not known yet — read it with: voltro data ${J} --target api --api-url ${t}`), 0;
515
+ if (l.recorded === !1) return L.warn(`api export: started as ${l.runId}, but this instance could not record the run — so its outcome\n cannot be read back. Run \`voltro db apply\` against it so the next one is watchable.`), 0;
516
+ let p = await d({
517
+ read: () => Ke(t, i, l.runId),
518
+ onTick: (e) => {
519
+ L.info(f(e));
520
+ },
521
+ intervalMs: c.pollMs,
522
+ ...c.total === void 0 ? {} : { timeoutMs: c.total }
523
+ }), m = u(p);
524
+ if (m !== 0) return L.error(m === 1 ? `api export FAILED (${l.runId}): ${String(p?.failure ?? "no reason recorded")}` : `api export: no outcome visible for ${l.runId}. The run is not cancelled; it is simply not readable from here.`), m;
525
+ if (n) return L.info("api export complete (pushed to storage)", {
526
+ via: t,
527
+ runId: l.runId,
528
+ bundleKey: n,
529
+ tables: p?.tablesWritten ?? 0,
530
+ rows: p?.rowsWritten ?? 0
531
+ }), 0;
532
+ let { resolve: h } = await import("node:path"), g = await qe({
533
+ apiUrl: t,
534
+ secret: i,
535
+ runId: l.runId,
536
+ log: L,
537
+ ...c.perRequest ? { perRequest: c.perRequest } : {}
538
+ });
539
+ return g === null ? 1 : (await xe((async function* () {
540
+ yield g;
541
+ })(), h(process.cwd(), r)), L.info("api export complete (downloaded from the running instance)", {
542
+ outDir: r,
543
+ runId: l.runId,
544
+ tables: p?.tablesWritten ?? 0,
545
+ rows: p?.rowsWritten ?? 0,
546
+ bytes: g.byteLength
547
+ }), 0);
548
+ }
549
+ if (!r) return L.error("a <outDir> is required for a direct export"), 1;
550
+ let i = B(e, "--profile"), a = i ? await p(i, { allowPath: !0 }) : {}, { store: o, snapshot: s, dialect: c } = await U(), l = e.includes("--assets") || a.assets === !0, m = l ? T({}) : void 0, h = B(e, "--compression") ?? a.compression, g = B(e, "--consistency") === "snapshot" ? "snapshot" : a.consistency ?? "live", _ = a.masking, v = a.subset, y = a.scope ?? Ye(e, s.tables.map((e) => e.name)), b = _ ? await Xe() : void 0, x = y.kind === "tenant" ? await Qe() : void 0, S = x ? { tenantTables: x } : {};
551
+ if (e.includes("--dry-run")) {
552
+ let e = y.kind === "tables" && y.tables ? [...y.tables] : s.tables.map((e) => e.name);
553
+ if (L.info("export DRY RUN — nothing was written", {
554
+ outDir: r,
555
+ tables: e.length,
556
+ scope: y.kind,
557
+ consistency: g,
558
+ compression: h ?? "zstd",
559
+ assets: l,
560
+ masking: _ ? "profile policy applies" : "none"
561
+ }), L.info(`would export: ${e.join(", ")}`), !_) return 0;
562
+ let t = await w.runPromise(pe({
563
+ store: o,
564
+ snapshot: s,
565
+ masking: _,
566
+ ...b ? { classification: b } : {},
567
+ ...v ? {} : {
568
+ scope: y,
569
+ ...S
570
+ }
571
+ }));
572
+ return $e(t), +(t.unclassified.length > 0);
573
+ }
574
+ if (G(r)) {
575
+ let t = await import("node:os"), n = await import("node:fs/promises"), { resolve: i, join: a } = await import("node:path"), u = await n.mkdtemp(a(t.tmpdir(), "voltro-export-"));
576
+ try {
577
+ let t = await w.runPromise(me({
578
+ store: o,
579
+ snapshot: s,
580
+ dialect: c,
581
+ outDir: u,
582
+ ...v ? { subset: v } : {
583
+ scope: y,
584
+ ...S
585
+ },
586
+ consistency: g,
587
+ ...h ? { compression: h } : {},
588
+ ..._ ? { masking: _ } : {},
589
+ ...b ? { classification: b } : {},
590
+ onProgress: z
591
+ })), n = fe({
592
+ dir: u,
593
+ ...m ? { blobs: ye(m, () => W(o)) } : {}
594
+ }), a = He(e);
595
+ if (a) {
596
+ let t = K(e);
597
+ if (!t) return L.error("--encrypt requires --passphrase <p> or VOLTRO_BUNDLE_KEY (a dedicated key, NOT the transfer secret)"), 1;
598
+ n = de(n, t);
599
+ }
600
+ return await Ue(n, i(process.cwd(), r)), L.info("export complete (single file)", {
601
+ file: r,
602
+ encrypted: a,
603
+ assets: l,
604
+ tables: t.tables.length,
605
+ rows: t.tables.reduce((e, t) => e + t.rowCount, 0)
606
+ }), 0;
607
+ } finally {
608
+ await n.rm(u, {
609
+ recursive: !0,
610
+ force: !0
611
+ });
612
+ }
613
+ }
614
+ let C = await w.runPromise(me({
615
+ store: o,
616
+ snapshot: s,
617
+ dialect: c,
618
+ outDir: r,
619
+ ...v ? { subset: v } : {
620
+ scope: y,
621
+ ...S
622
+ },
623
+ consistency: g,
624
+ ...h ? { compression: h } : {},
625
+ ..._ ? { masking: _ } : {},
626
+ ...b ? { classification: b } : {},
627
+ ...m ? { assets: _e(m, () => W(o)) } : {},
628
+ onProgress: z
629
+ }));
630
+ return L.info("export complete", {
631
+ outDir: r,
632
+ tables: C.tables.length,
633
+ rows: C.tables.reduce((e, t) => e + t.rowCount, 0),
634
+ assets: C.assets.count,
635
+ compression: C.compression,
636
+ ...C.masking ? { maskedColumns: C.masking.transformed.length } : {}
637
+ }), 0;
638
+ }, Z = () => "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.", at = (e) => {
639
+ let t = B(e, "--tables");
640
+ return {
641
+ ...t ? { tables: t.split(",").map((e) => e.trim()).filter(Boolean) } : {},
642
+ ...e.includes("--dry-run") ? { dryRun: !0 } : {}
643
+ };
644
+ }, ot = (e) => ({
645
+ tables: e.tablesWritten,
646
+ rows: e.rowsWritten,
647
+ carried: e.manifest.tables.reduce((e, t) => e + t.rowCount, 0),
648
+ ...e.tablesSkipped > 0 ? {
649
+ skippedTables: e.tablesSkipped,
650
+ skippedRows: e.rowsSkipped
651
+ } : {}
652
+ }), st = (e, t) => {
653
+ if (e.includes("--dry-run")) {
654
+ L.info("import DRY RUN — nothing was written", t), L.info(Z());
655
+ return;
656
+ }
657
+ if (t.rows === 0 && typeof t.skippedRows == "number" && t.skippedRows !== 0) {
658
+ L.info("import complete — 0 rows written, every table was already applied by an earlier run of this bundle directory", t);
659
+ return;
660
+ }
661
+ L.info("import complete", t);
662
+ }, ct = Symbol("refused"), Q = (e) => {
663
+ let t = se(e) ?? e;
664
+ if (t?._tag !== "RowsRefusedError" || !Array.isArray(t.rows)) return !1;
665
+ let n = t.rows, r = n.filter((e) => !e.derived), i = Number(t.totalCount ?? n.length), a = Number(t.primaryCount ?? r.length);
666
+ L.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.`);
667
+ let o = Array.isArray(t.byTable) ? t.byTable : [];
668
+ o.length > 1 && L.error(` by table: ${o.map((e) => `${e.table} ${e.refused}`).join(", ")}`);
669
+ for (let e of r) L.error(` ${e.table} ${e.id} ${e.reason}`);
670
+ n.length < i && L.error(` (the list above is capped at ${n.length} of ${i} — the counts by table are complete)`);
671
+ let s = i - a;
672
+ return s > 0 && L.error(` … and ${s} row(s) behind them. Fix the ${a} above and re-run; they resolve with their parents.`), !0;
673
+ }, lt = (e) => {
674
+ let t = typeof e == "string" ? e : e.toString("utf8"), n = t;
675
+ try {
676
+ let e = JSON.parse(t), r = e.error ?? e.message;
677
+ typeof r == "string" && (n = r);
678
+ } catch {}
679
+ let r = n.indexOf("RowsRefusedError");
680
+ if (r < 0) return;
681
+ let i = n.indexOf("{", r);
682
+ if (i < 0) return;
683
+ let a = 0, o = !1, s = !1;
684
+ for (let e = i; e < n.length; e++) {
685
+ let t = n[e];
686
+ if (o) {
687
+ if (s) {
688
+ s = !1;
689
+ continue;
690
+ }
691
+ if (t === "\\") {
692
+ s = !0;
693
+ continue;
694
+ }
695
+ t === "\"" && (o = !1);
696
+ continue;
697
+ }
698
+ if (t === "\"") {
699
+ o = !0;
700
+ continue;
701
+ }
702
+ if (t === "{") a++;
703
+ else if (t === "}" && --a === 0) try {
704
+ let t = JSON.parse(n.slice(i, e + 1));
705
+ return Array.isArray(t.rows) ? {
706
+ _tag: "RowsRefusedError",
707
+ ...t
708
+ } : void 0;
709
+ } catch {
710
+ return;
711
+ }
712
+ }
713
+ }, ut = async (e) => {
714
+ let t = B(e, "--target") === "api", n = B(e, "--bundle-key"), r = V(e);
715
+ if (!r && !(t && n)) return L.error("usage: voltro data import <bundleDir> [--target direct|api] [--api-url <url>] [--token <secret>] [--timeout <seconds>] [--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;
716
+ let i = B(e, "--mode") ?? "upsert", o = B(e, "--on-conflict") ?? "skip";
717
+ if (t) {
718
+ let t = B(e, "--api-url");
719
+ if (!t) return L.error("--target api requires --api-url <url> (the running instance)"), 1;
720
+ let a = B(e, "--token") ?? process.env.VOLTRO_DATA_TRANSFER_SECRET;
721
+ if (!a) return L.error("--target api requires --token <secret> (or VOLTRO_DATA_TRANSFER_SECRET) matching the instance secret"), 1;
722
+ let s = B(e, "--tables"), c = B(e, "--rollback-key");
723
+ i === "replace" && c === void 0 && L.warn("api replace: no rollback capture — this run empties the target first and nothing was asked to be kept.\n Pass --rollback-key <storage-key> and the INSTANCE stores the target's current rows in its own\n object storage before deleting them, which is the one place that survives the pod going away.");
724
+ let l = {
725
+ authorization: `Bearer ${a}`,
726
+ "x-import-mode": i,
727
+ "x-import-on-conflict": o,
728
+ ...Y(e, i) ? { "x-import-atomic": "1" } : {},
729
+ ...e.includes("--no-atomic") ? { "x-import-atomic": "0" } : {},
730
+ ...c === void 0 ? {} : { "x-import-rollback-key": c },
731
+ ...e.includes("--force") ? { "x-import-force": "1" } : {},
732
+ ...e.includes("--dry-run") ? { "x-import-dry-run": "1" } : {},
733
+ ...s ? { "x-import-tables": s } : {}
734
+ }, { resolve: p } = await import("node:path"), m;
735
+ if (n) l["content-type"] = "application/json", m = JSON.stringify({ bundleKey: n });
736
+ else if (G(r)) {
737
+ let t = q(p(process.cwd(), r)), n = K(e);
738
+ n && (t = D(t, n)), l["content-type"] = "application/octet-stream", m = t;
739
+ } else await (await import("node:fs/promises")).access(p(process.cwd(), r, "assets", "index.ndjson")).then(() => !0, () => !1) && L.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."), l["content-type"] = "application/octet-stream", m = fe({ dir: p(process.cwd(), r) });
740
+ if (i === "replace") {
741
+ let i = await We(r, n);
742
+ {
743
+ let r = i === null ? { bundleKey: n } : { tables: i }, a = await N(`${t.replace(/\/+$/, "")}/_voltro/admin/import`, JSON.stringify(r), {
744
+ ...l,
745
+ "content-type": "application/json",
746
+ "x-import-preflight": "1"
747
+ }, X(e)).catch(() => null), o = a !== null && a.status === 200 ? JSON.parse(a.body.toString("utf8")) : null;
748
+ o === null ? L.warn("api replace: the instance did not answer the preflight (an older build does not have it). The run still works; the decision will only be visible in the pod log.") : o.staged === !0 ? L.info(`api replace: the instance WILL stage — ${o.stagedTables ?? 0} table(s) load into copies and the\n target keeps its rows until one short swap at the end. Interrupting the load leaves the target intact.`) : L.warn(`api replace: the instance will NOT stage — it empties the target first and refills it, so an
749
+ interrupted run leaves the target empty.\n Reason: ${o.reason ?? "not stated"}`);
750
+ }
751
+ }
752
+ i === "replace" && !Y(e, i) && L.warn(tt(!0));
753
+ let h = `${t.replace(/\/+$/, "")}/_voltro/admin/import`, g = Ge(e), _;
754
+ try {
755
+ let t = typeof m == "string" ? null : await et({
756
+ stream: m,
757
+ url: h,
758
+ headers: l,
759
+ bundleDir: r,
760
+ args: e,
761
+ log: L
762
+ }), n = t === null ? await N(h, m, l, g.perRequest ?? X(e)) : t.kind === "sent" ? t.res : await N(h, t.body, l, g.perRequest ?? X(e));
763
+ if (n.status < 200 || n.status >= 300) return Q(lt(n.body)) || L.error(`api import failed: HTTP ${n.status} — ${n.body.toString("utf8")}`), 1;
764
+ _ = JSON.parse(n.body.toString("utf8"));
765
+ } catch (e) {
766
+ if (e instanceof M) return L.error(`api import: ${Te(e, i)}`), 1;
767
+ if (e instanceof j) return L.error(`api import: ${P(e)}`), 1;
768
+ throw e;
769
+ }
770
+ let v = await N(`${t.replace(/\/+$/, "")}/_voltro/admin/import/start`, JSON.stringify(_.bundleKey === void 0 ? { uploadId: _.uploadId } : { bundleKey: _.bundleKey }), {
771
+ ...l,
772
+ "content-type": "application/json"
773
+ }, g.perRequest ?? X(e)).catch((e) => {
774
+ if (e instanceof j) return L.error(`api import: ${P(e)}`), null;
775
+ throw e;
776
+ });
777
+ if (v === null) return 1;
778
+ if (v.status < 200 || v.status >= 300) return Q(lt(v.body)) || L.error(`api import refused: HTTP ${v.status} — ${v.body.toString("utf8")}`), 1;
779
+ let y = JSON.parse(v.body.toString("utf8"));
780
+ if (y.alreadyStarted === !0 && L.info(`api import: this bundle is already being imported as ${y.runId} — watching that run instead of starting a second one`), e.includes("--detach")) return L.info(`api import: started as ${y.runId}. NOT waiting for it.\n The outcome is not known yet — read it with: voltro data ${J} --target api --api-url ${t}`), 0;
781
+ if (y.recorded === !1) return L.warn(`api import: started as ${y.runId}, but this instance could not record the run — so its outcome\n cannot be read back. Run \`voltro db apply\` against it so the next import is watchable.`), 0;
782
+ let b = await d({
783
+ read: () => Ke(t, a, y.runId),
784
+ onTick: (e) => {
785
+ L.info(f(e));
786
+ },
787
+ intervalMs: g.pollMs,
788
+ ...g.total === void 0 ? {} : { timeoutMs: g.total }
789
+ }), x = u(b);
790
+ return x === 2 ? (L.warn(b === null ? `api import: started as ${y.runId}, but its record could not be READ back from this instance.\n That is a channel problem, not a slow import — an older instance without the history route, a
791
+ proxy dropping the GET, or a target with no history table. The run itself is unaffected and
792
+ is NOT cancelled; its outcome is simply not visible from here.` : `api import: still running after the time allowed. The run is NOT cancelled — it is decoupled from\n this client by design. Watch it with: voltro data ${J} --target api --api-url ${t}`), 2) : x === 1 ? (L.error(`api import FAILED (${y.runId}): ${String(b?.failure ?? "no reason recorded")}`), 1) : e.includes("--dry-run") ? (L.info("api import DRY RUN — nothing was written", {
793
+ via: t,
794
+ runId: y.runId
795
+ }), L.info(Z()), 0) : (L.info("api import complete (imported by the running instance)", {
796
+ via: t,
797
+ runId: y.runId,
798
+ tables: b?.tablesWritten ?? 0,
799
+ rows: b?.rowsWritten ?? 0,
800
+ ...b?.staged !== null && b?.staged !== void 0 ? { staged: b.staged } : {}
801
+ }), 0);
802
+ }
803
+ if (!r) return L.error("a <bundleDir> is required for a direct import"), 1;
804
+ if (!await Le(e)) return 1;
805
+ i === "replace" && e.includes("--allow-live") && !Y(e, i) && L.warn(tt(!1));
806
+ let { store: s, snapshot: c } = await U();
807
+ c.tables.some((e) => e.name === y) || L.warn(`this target has no \`${y}\` table, so this import will not be recorded.\n The import itself is unaffected. \`voltro db apply\` creates it.`);
808
+ let l = e.includes("--force"), p = (e) => L.warn(e), m = e.includes("--assets") ? T({}) : void 0, h = H() === "postgres" ? (await import("@voltro/sql-postgres")).makePgCopySession(a()) : void 0;
809
+ if (G(r)) {
810
+ let t = await import("node:os"), n = await import("node:fs/promises"), { resolve: a, join: u } = await import("node:path"), d = await n.mkdtemp(u(t.tmpdir(), "voltro-import-"));
811
+ try {
812
+ let t = q(a(process.cwd(), r)), n = K(e);
813
+ return n && (t = D(t, n)), await be(t, {
814
+ dir: d,
815
+ blobs: ve(m ?? T({}))
816
+ }), st(e, {
817
+ file: r,
818
+ ...ot(await w.runPromise(he({
819
+ store: s,
820
+ bundleDir: d,
821
+ mode: i,
822
+ onConflict: o,
823
+ atomic: Y(e, i),
824
+ ...rt(e, i, r),
825
+ verify: !e.includes("--no-verify"),
826
+ targetDialect: H(),
827
+ allowIncompatible: l,
828
+ targetSnapshot: c,
829
+ force: l,
830
+ onWarn: p,
831
+ onProgress: z,
832
+ assetsAlreadyRestored: !0,
833
+ ...at(e),
834
+ ...h ? { copyLoader: h } : {}
835
+ })))
836
+ }), 0;
837
+ } finally {
838
+ await h?.close(), await n.rm(d, {
839
+ recursive: !0,
840
+ force: !0
841
+ });
842
+ }
843
+ }
844
+ let g = await w.runPromise(he({
845
+ ...rt(e, i, r),
846
+ store: s,
847
+ bundleDir: r,
848
+ mode: i,
849
+ onConflict: o,
850
+ atomic: Y(e, i),
851
+ verify: !e.includes("--no-verify"),
852
+ targetDialect: H(),
853
+ allowIncompatible: l,
854
+ targetSnapshot: c,
855
+ force: l,
856
+ onWarn: p,
857
+ onProgress: z,
858
+ ...at(e),
859
+ ...m ? { assets: ge(m) } : {},
860
+ ...h ? { copyLoader: h } : {}
861
+ })).catch((e) => {
862
+ if (Q(e)) return ct;
863
+ throw e;
864
+ }).finally(() => h?.close());
865
+ return typeof g == "symbol" ? 1 : (st(e, {
866
+ bundleDir: r,
867
+ ...ot(g),
868
+ assets: g.manifest.assets.count
869
+ }), 0);
870
+ }, dt = () => {
871
+ let e = a();
872
+ return {
873
+ ...e.url ? { url: e.url } : {},
874
+ ...e.host ? { host: e.host } : {},
875
+ ...e.port ? { port: e.port } : {},
876
+ ...e.username ? { username: e.username } : {},
877
+ ...e.password ? { password: e.password } : {},
878
+ ...e.database ? { database: e.database } : {}
879
+ };
880
+ }, ft = async (e) => {
881
+ let t = V(e);
882
+ if (!t) return L.error("usage: voltro data backup <outDir> (native pg_dump/mysqldump/… + consistent artifact)"), 1;
883
+ let n = H(), { mkdir: r, writeFile: i } = await import("node:fs/promises"), { join: a } = await import("node:path");
884
+ await r(t, { recursive: !0 });
885
+ let o = a(t, E(n));
886
+ await w.runPromise(A(le(n, dt(), o)));
887
+ let s = Ae({
888
+ dialect: n,
889
+ schemaFingerprint: await R(n),
890
+ voltroVersion: await Fe(),
891
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
892
+ });
893
+ return await i(a(t, F), `${JSON.stringify(s, null, 2)}\n`, "utf8"), L.info("native backup complete", {
894
+ dialect: n,
895
+ artifact: o,
896
+ stamp: F,
897
+ schemaFingerprint: s.schemaFingerprint ?? "<none>",
898
+ assets: "NOT included — use `voltro data export --assets` for rows + blobs"
899
+ }), 0;
900
+ }, pt = async (e, t) => {
901
+ let n = H(), { join: r } = await import("node:path"), { readFile: i } = await import("node:fs/promises"), a = r(e, E(n)), o = Ne({
902
+ flagUrl: B(t, "--drill-url"),
903
+ envUrl: process.env.DRILL_DB_URL,
904
+ liveKeys: Ve()
905
+ });
906
+ if (!o.ok) return L.error(`restore --drill: ${o.error}`), 1;
907
+ let s = await i(r(e, F), "utf8").then(je, () => null);
908
+ if (s && s.dialect !== n) return L.error(`restore --drill: backup is a ${s.dialect} dump but DB_DIALECT is ${n} — cross-dialect restore is never valid.`), 1;
909
+ L.info("restore drill: restoring into throwaway DB", {
910
+ dialect: n,
911
+ target: I(o.url)
912
+ }), await w.runPromise(A(k(n, { url: o.url }, a)));
913
+ let c = null, l = 0;
914
+ try {
915
+ let e = await ze(n, { url: o.url });
916
+ c = re(e), l = e.tables.length;
917
+ } catch (e) {
918
+ return L.error(`restore --drill: could not introspect the restored DB — ${String(e)}`), 1;
919
+ }
920
+ let u = Pe({
921
+ stampFingerprint: s?.schemaFingerprint ?? null,
922
+ restoredFingerprint: c,
923
+ restoredTableCount: l
924
+ });
925
+ for (let e of u.lines) u.pass ? L.info(`restore drill: ${e}`) : L.error(`restore drill: ${e}`);
926
+ return +!u.pass;
927
+ }, mt = async (e) => {
928
+ let t = V(e);
929
+ if (!t) return L.error("usage: voltro data restore <backupDir> [--allow-live] [--api-url <url>] [--force] [--drill [--drill-url <url>]] (native pg_restore/mysql/…)"), 1;
930
+ if (e.includes("--drill")) return pt(t, e);
931
+ if (!await Le(e)) return 1;
932
+ let n = H(), { join: r } = await import("node:path"), { readFile: i } = await import("node:fs/promises"), a = r(t, E(n)), o = Me({
933
+ stamp: await i(r(t, F), "utf8").then(je, () => null),
934
+ currentDialect: n,
935
+ currentFingerprint: await R(n)
936
+ });
937
+ for (let e of o.info) L.info(`backup stamp: ${e}`);
938
+ if (o.warn && L.warn(o.warn), o.refuse) {
939
+ if (!e.includes("--force")) return L.error(`restore refused: ${o.refuse} (pass --force to override)`), 1;
940
+ L.warn(`restore proceeding despite: ${o.refuse} (--force)`);
941
+ }
942
+ return await w.runPromise(A(k(n, dt(), a))), L.info("native restore complete", {
943
+ dialect: n,
944
+ artifact: a
945
+ }), 0;
946
+ }, ht = async (e) => {
947
+ let t = V(e);
948
+ if (!t) return L.error("usage: voltro data inspect <file.vbundle|dir> [--json] [--passphrase <p>]"), 1;
949
+ let { resolve: n, join: r } = await import("node:path"), i = await import("node:fs/promises"), a = n(process.cwd(), t);
950
+ if ((await i.stat(a).catch(() => void 0))?.isDirectory()) {
951
+ let n = r(a, "manifest.json"), o = r(a, "README.md");
952
+ if (!e.includes("--json")) {
953
+ let e = await i.readFile(o, "utf8").catch(() => void 0);
954
+ if (e !== void 0) return console.log(e), 0;
955
+ }
956
+ let s = await i.readFile(n, "utf8").catch(() => void 0);
957
+ return s === void 0 ? (L.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);
958
+ }
959
+ let o = K(e), s = () => {
960
+ let e = q(a);
961
+ return o ? D(e, o) : e;
962
+ };
963
+ if (e.includes("--json")) {
964
+ let e = (await O(s(), ["manifest.json"])).get("manifest.json");
965
+ return e ? (console.log(e.toString("utf8")), 0) : (L.error("no manifest.json found in the bundle"), 1);
966
+ }
967
+ let c = (await O(s(), ["README.md"])).get("README.md");
968
+ if (c) return console.log(c.toString("utf8")), 0;
969
+ let l = (await O(s(), ["manifest.json"])).get("manifest.json");
970
+ return l ? (console.log(l.toString("utf8")), 0) : (L.error("bundle has no README.md or manifest.json"), 1);
971
+ }, gt = async (e) => {
972
+ let { REPLACE_IN_PROGRESS_TABLE: t } = await import("@voltro/database"), { interruptedReplaceAtBoot: n } = await import("./interruptedReplace-DNJ7MKph.js"), { store: r } = await U(), i = await n(r);
973
+ if (i === void 0) return L.info("no interrupted replace is recorded — nothing to clear"), 0;
974
+ if (!e.includes("--yes")) return L.error(`${i}\n\n Re-run with --yes to clear it.`), 1;
975
+ let a = await r.query({
976
+ table: t,
977
+ predicate: void 0,
978
+ order: [],
979
+ take: void 0,
980
+ skip: void 0,
981
+ projection: void 0
982
+ });
983
+ for (let e of a) await r.delete(t, String(e.id));
984
+ return L.info(`cleared ${a.length} interrupted-replace marker(s) — the next boot will start`), 0;
985
+ }, _t = async (e) => {
986
+ let { STAGING_PREFIX: t, dropStagingSql: n, execStatements: r } = await import("@voltro/data-transfer"), { store: i } = await U(), a = H();
987
+ if (a !== "postgres" && a !== "mysql" && a !== "mariadb" && a !== "sqlite" && a !== "mssql") return L.error(`this store has no staging tables to clear (dialect: ${a})`), 1;
988
+ let { introspectSchema: o } = await import("@voltro/database/sql"), s = (await i.run((await import("@effect/sql")).SqlClient.SqlClient.pipe((await import("effect")).Effect.flatMap(o)))).tables.map((e) => e.name).filter((e) => e.startsWith(t));
989
+ return s.length === 0 ? (L.info("no staging tables are present — nothing to clear"), 0) : e.includes("--yes") ? (await r(i, s.map((e) => n(e.slice(t.length), a))), L.info(`dropped ${s.length} staging table(s)`), 0) : (L.error(`${s.length} staging table(s) from an earlier \`--mode replace\`:\n` + s.map((e) => ` ${e}`).join("\n") + "\n\n Each holds a copy of what a run was loading. Nothing else removes them.\n Make sure no import is running right now — this cannot tell a leftover from one in flight.\n Re-run with --yes to drop them."), 1);
990
+ }, vt = async (e) => {
991
+ let { describeTransferRun: t, DATA_TRANSFERS_TABLE: n } = await import("@voltro/database"), r = Number(B(e, "--limit") ?? "20"), i = Number.isFinite(r) ? Math.max(1, Math.min(200, Math.trunc(r))) : 20;
992
+ if (B(e, "--target") === "api") {
993
+ let t = B(e, "--api-url");
994
+ if (!t) return L.error("--target api requires --api-url <url> (the running instance)"), 1;
995
+ let n = B(e, "--token") ?? process.env.VOLTRO_DATA_TRANSFER_SECRET;
996
+ if (!n) return L.error("--target api requires --token <secret> (or VOLTRO_DATA_TRANSFER_SECRET)"), 1;
997
+ let r = await fetch(`${t.replace(/\/+$/, "")}/_voltro/admin/imports?limit=${i}`, { headers: { authorization: `Bearer ${n}` } }), a = await r.text();
998
+ if (r.status !== 200) return L.error(`api imports: ${r.status} ${a}`), 1;
999
+ let o = JSON.parse(a);
1000
+ if (e.includes("--json")) return console.log(a), 0;
1001
+ let s = o.runs ?? [];
1002
+ if (s.length === 0) return L.info("no imports recorded on this instance"), 0;
1003
+ (o.running ?? 0) > 0 && L.info(`${o.running} import(s) IN FLIGHT — re-run this to watch the counters move`);
1004
+ for (let e of s) L.info(` ${e.line ?? ""}`);
1005
+ return 0;
1006
+ }
1007
+ let { store: a } = await U(), o;
1008
+ try {
1009
+ o = await a.query({
1010
+ table: n,
1011
+ order: [{
1012
+ column: "startedAt",
1013
+ direction: "desc"
1014
+ }],
1015
+ predicate: void 0,
1016
+ projection: void 0,
1017
+ skip: 0,
1018
+ take: i
1019
+ });
1020
+ } catch {
1021
+ return L.error(`this target has no \`${n}\` table, so no import has been recorded here.\n Run \`voltro db apply\`; imports themselves are unaffected by its absence.`), 1;
1022
+ }
1023
+ if (o.length === 0) return L.info("no imports recorded against this target"), 0;
1024
+ for (let e of o) {
1025
+ let n = e;
1026
+ L.info(` ${t({
1027
+ ...e,
1028
+ startedAt: new Date(n.startedAt),
1029
+ finishedAt: n.finishedAt === null ? null : new Date(n.finishedAt)
1030
+ })}`);
1031
+ }
1032
+ return 0;
1033
+ }, yt = async (e) => {
1034
+ let t = V(e), n = V(e.filter((e) => e !== t));
1035
+ if (!t || !n) return L.error("usage: voltro data unpack <file.vbundle> <dir> [--passphrase <p>]"), 1;
1036
+ let { resolve: r } = await import("node:path"), i = q(r(process.cwd(), t)), a = K(e);
1037
+ return a && (i = D(i, a)), await xe(i, r(process.cwd(), n)), L.info("unpack complete", {
1038
+ file: t,
1039
+ dir: n
1040
+ }), 0;
1041
+ }, $ = {
1042
+ export: {
1043
+ common: [
1044
+ "--target",
1045
+ "--tables",
1046
+ "--exclude",
1047
+ "--profile",
1048
+ "--tenant",
1049
+ "--assets",
1050
+ "--compression",
1051
+ "--consistency",
1052
+ "--json"
1053
+ ],
1054
+ directOnly: [
1055
+ "--passphrase",
1056
+ "--dry-run",
1057
+ "--encrypt"
1058
+ ],
1059
+ apiOnly: [
1060
+ "--api-url",
1061
+ "--token",
1062
+ "--bundle-key",
1063
+ "--timeout",
1064
+ "--detach",
1065
+ "--max-request-seconds"
1066
+ ]
1067
+ },
1068
+ "clear-staging": { common: ["--yes"] },
1069
+ transfers: {
1070
+ common: [
1071
+ "--target",
1072
+ "--limit",
1073
+ "--json"
1074
+ ],
1075
+ apiOnly: ["--api-url", "--token"]
1076
+ },
1077
+ "clear-replace-marker": { common: ["--yes"] },
1078
+ import: {
1079
+ common: [
1080
+ "--target",
1081
+ "--tables",
1082
+ "--mode",
1083
+ "--on-conflict",
1084
+ "--atomic",
1085
+ "--no-atomic",
1086
+ "--assets",
1087
+ "--force",
1088
+ "--dry-run",
1089
+ "--json"
1090
+ ],
1091
+ directOnly: [
1092
+ "--no-verify",
1093
+ "--allow-live",
1094
+ "--passphrase",
1095
+ "--rollback-dir",
1096
+ "--no-rollback"
1097
+ ],
1098
+ apiOnly: [
1099
+ "--api-url",
1100
+ "--token",
1101
+ "--bundle-key",
1102
+ "--timeout",
1103
+ "--chunk-size",
1104
+ "--rollback-key",
1105
+ "--detach",
1106
+ "--max-request-seconds"
1107
+ ]
1108
+ },
1109
+ unpack: { common: ["--passphrase", "--json"] },
1110
+ inspect: { common: ["--json", "--passphrase"] },
1111
+ backup: { common: ["--json", "--assets"] },
1112
+ restore: { common: [
1113
+ "--json",
1114
+ "--allow-live",
1115
+ "--force",
1116
+ "--drill",
1117
+ "--drill-url",
1118
+ "--api-url"
1119
+ ] }
1120
+ }, bt = (e) => e.split("=")[0], xt = (e, t) => {
1121
+ let n = $[e];
1122
+ if (!n) return;
1123
+ let r = B(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 ?? []);
1124
+ for (let n of t) {
1125
+ if (!n.startsWith("--")) continue;
1126
+ let t = bt(n);
1127
+ if (i.has(t)) continue;
1128
+ 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.`;
1129
+ let o = Object.entries($).filter(([n, r]) => n !== e && [
1130
+ ...r.common,
1131
+ ...r.directOnly ?? [],
1132
+ ...r.apiOnly ?? []
1133
+ ].includes(t)).map(([e]) => e);
1134
+ 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.`;
1135
+ }
1136
+ }, St = {
1137
+ export: it,
1138
+ import: ut,
1139
+ transfers: vt,
1140
+ inspect: ht,
1141
+ unpack: yt,
1142
+ backup: ft,
1143
+ restore: mt,
1144
+ "clear-replace-marker": gt,
1145
+ "clear-staging": _t
1146
+ }, Ct = async (n) => {
1147
+ let [r, ...i] = n;
1148
+ if (r !== void 0 && $[r] !== void 0) {
1149
+ let e = xt(r, i);
1150
+ if (e) return L.error(e), 2;
1151
+ }
1152
+ let a = r === void 0 ? void 0 : St[r];
1153
+ return a === void 0 ? (L.error(`usage: voltro data ${e(t)} … (logical: export/import; native: backup/restore; \`imports\` reads the history, incl. a run in flight)`), r ? 2 : 1) : a(i);
1154
+ };
1155
+ //#endregion
1156
+ export { Ct as runDataCommand };