orcaq 1.1.6 → 1.1.7

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 (154) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/_nuxt/{Lh0RfwhV.js → 1VXrIDkr.js} +1 -1
  3. package/.output/public/_nuxt/{ZVYA9HBl.js → 1fIGBJPQ.js} +1 -1
  4. package/.output/public/_nuxt/{BbawOYVr.js → 1kY3DHv7.js} +1 -1
  5. package/.output/public/_nuxt/{DDsaDrGo.js → 2TwRWQjG.js} +1 -1
  6. package/.output/public/_nuxt/{wrneOCBW.js → 39ZZCZCn.js} +1 -1
  7. package/.output/public/_nuxt/{BmEIj9l9.js → 3vYvhEat.js} +1 -1
  8. package/.output/public/_nuxt/{CEoM97rJ.js → 9bnMBg54.js} +1 -1
  9. package/.output/public/_nuxt/{ZNDxw-7x.js → B-u0WX5Q.js} +1 -1
  10. package/.output/public/_nuxt/{uDsvlLN0.js → B41tp0B8.js} +1 -1
  11. package/.output/public/_nuxt/{4LC09zKL.js → BCm7jnPt.js} +1 -1
  12. package/.output/public/_nuxt/{D29mzs5t.js → BFMjnjgH.js} +1 -1
  13. package/.output/public/_nuxt/{BEvswgw7.js → BGAd-CMD.js} +1 -1
  14. package/.output/public/_nuxt/{CP-7VdtS.js → BG_B-fo0.js} +1 -1
  15. package/.output/public/_nuxt/{Dd89Vyx8.js → BLEKzUmC.js} +1 -1
  16. package/.output/public/_nuxt/{DoNLWeqB.js → BN2mQ8OV.js} +1 -1
  17. package/.output/public/_nuxt/{DP6Az3fC.js → BNnChlxR.js} +1 -1
  18. package/.output/public/_nuxt/{BKAEFZqP.js → BNyWhB4W.js} +1 -1
  19. package/.output/public/_nuxt/{Bibtvqd8.js → BO-QgaRL.js} +1 -1
  20. package/.output/public/_nuxt/{DViCRsmA.js → BOVFFCPB.js} +1 -1
  21. package/.output/public/_nuxt/{BWg3wiuc.js → BRVpLa1E.js} +1 -1
  22. package/.output/public/_nuxt/{BJ8qQpib.js → BV4g1sVY.js} +1 -1
  23. package/.output/public/_nuxt/{_TExiQQQ.js → BXziI6Bt.js} +1 -1
  24. package/.output/public/_nuxt/{Df4wU3r0.js → BZQUF1W4.js} +1 -1
  25. package/.output/public/_nuxt/BZmEvFAZ.js +28 -0
  26. package/.output/public/_nuxt/B_G752SV.js +20 -0
  27. package/.output/public/_nuxt/{BusLuQ4Q.js → Ba_fqsW2.js} +1 -1
  28. package/.output/public/_nuxt/{DZFq5yqu.js → BbzZxPNQ.js} +1 -1
  29. package/.output/public/_nuxt/{BxZgIpkD.js → BhT0iBlH.js} +1 -1
  30. package/.output/public/_nuxt/{CoX1_N4R.js → Bhm1GL_M.js} +1 -1
  31. package/.output/public/_nuxt/{27ZsWTm2.js → BiSZmDoN.js} +1 -1
  32. package/.output/public/_nuxt/{DZVfXu09.js → BjK8Fug8.js} +1 -1
  33. package/.output/public/_nuxt/{G40WRC_L.js → BjpSpz5C.js} +1 -1
  34. package/.output/public/_nuxt/{Bok35x_B.js → BkqB6n0T.js} +1 -1
  35. package/.output/public/_nuxt/{6NXhlm49.js → BoPjUGS6.js} +1 -1
  36. package/.output/public/_nuxt/{B10QBDL6.js → BtwwqY0e.js} +1 -1
  37. package/.output/public/_nuxt/{FHx3Ejt6.js → BvD9dW-2.js} +1 -1
  38. package/.output/public/_nuxt/{Cvkyd5iW.js → Bw-4PosZ.js} +1 -1
  39. package/.output/public/_nuxt/C0l_59dE.js +1 -0
  40. package/.output/public/_nuxt/{__PEYcIB.js → C1TOiVRQ.js} +1 -1
  41. package/.output/public/_nuxt/{BoUZO_NV.js → C7A87LE3.js} +1 -1
  42. package/.output/public/_nuxt/{o60RgyTd.js → C80Zs8U0.js} +1 -1
  43. package/.output/public/_nuxt/{BnZ5qYkP.js → CB56S0b2.js} +9 -9
  44. package/.output/public/_nuxt/{CNPNWuzz.js → CBgbjsPd.js} +1 -1
  45. package/.output/public/_nuxt/{BCazdlgN.js → CCk2r9DD.js} +1 -1
  46. package/.output/public/_nuxt/{CCOlJAKS.js → CFZerEKx.js} +2 -2
  47. package/.output/public/_nuxt/{Bgj8Q52i.js → CG4v011f.js} +1 -1
  48. package/.output/public/_nuxt/{C4-wpUAK.js → CJnTtXrv.js} +1 -1
  49. package/.output/public/_nuxt/{DHyymmeR.js → CRDIOG8r.js} +1 -1
  50. package/.output/public/_nuxt/{XETGYn3c.js → CSPqdI4x.js} +1 -1
  51. package/.output/public/_nuxt/{DyDU0wFf.js → CTYqoFvv.js} +1 -1
  52. package/.output/public/_nuxt/{BbLqUOHs.js → CWGzL6OE.js} +1 -1
  53. package/.output/public/_nuxt/{CZLVBTJx.js → CYJEOEaU.js} +1 -1
  54. package/.output/public/_nuxt/{BTvOPFKG.js → CYu-xp_f.js} +1 -1
  55. package/.output/public/_nuxt/CZvnl0uO.js +52 -0
  56. package/.output/public/_nuxt/{DsPClaxV.js → CadjlDLt.js} +1 -1
  57. package/.output/public/_nuxt/{BJoSd_uV.js → CczQKYUP.js} +1 -1
  58. package/.output/public/_nuxt/{CHAVZu6b.js → CeXr_3vU.js} +2 -2
  59. package/.output/public/_nuxt/{BAasx5OS.js → Ch-A9iSC.js} +1 -1
  60. package/.output/public/_nuxt/{Bap1X7GD.js → Cj9tYr3P.js} +1 -1
  61. package/.output/public/_nuxt/Clm3Z8VL.js +1 -0
  62. package/.output/public/_nuxt/{F8eHh68O.js → CpkrwN3Q.js} +8 -8
  63. package/.output/public/_nuxt/{CO0Pa76w.js → CrwM3gOU.js} +1 -1
  64. package/.output/public/_nuxt/{DeVs4gEL.js → Culm7V2R.js} +1 -1
  65. package/.output/public/_nuxt/{Cl3VX8Um.js → CxZK-Vs6.js} +1 -1
  66. package/.output/public/_nuxt/{DLA-ioQ4.js → Cym7bWgs.js} +1 -1
  67. package/.output/public/_nuxt/CzBFxx8v.js +1 -0
  68. package/.output/public/_nuxt/{BCa-NKh0.js → D0oaRUYx.js} +1 -1
  69. package/.output/public/_nuxt/{DgGwe7jd.js → D7uoAo-G.js} +133 -133
  70. package/.output/public/_nuxt/{CvDZBOay.js → D8KJQqug.js} +1 -1
  71. package/.output/public/_nuxt/{DlymFQ5D.js → D8Z5BXgG.js} +3 -3
  72. package/.output/public/_nuxt/{DdbhVPqD.js → DDK9-_jm.js} +1 -1
  73. package/.output/public/_nuxt/{CnQob-tn.js → DDQU7vSH.js} +1 -1
  74. package/.output/public/_nuxt/{BuSZbOQO.js → DEjwIQuc.js} +1 -1
  75. package/.output/public/_nuxt/{yLATXAxG.js → DLIUYAz9.js} +1 -1
  76. package/.output/public/_nuxt/{DYPm3mWQ.js → DQdL5Jcl.js} +1 -1
  77. package/.output/public/_nuxt/{EZ0owjER.js → DRuCf0Sx.js} +1 -1
  78. package/.output/public/_nuxt/DSEkO8kW.js +1 -0
  79. package/.output/public/_nuxt/{DYqShb5v.js → DSOwr8Hs.js} +4 -4
  80. package/.output/public/_nuxt/{Cf6n9dsT.js → DStg2VwN.js} +1 -1
  81. package/.output/public/_nuxt/{Ci7hrFNN.js → DTlu-CJn.js} +1 -1
  82. package/.output/public/_nuxt/{CCK1so3F.js → DUvUg_V7.js} +1 -1
  83. package/.output/public/_nuxt/{CBjcd4cE.js → D_fdC3mJ.js} +1 -1
  84. package/.output/public/_nuxt/{BhzzQZRC.js → Da1F0IxL.js} +1 -1
  85. package/.output/public/_nuxt/{C6bwwZAc.js → DcXAnOS1.js} +1 -1
  86. package/.output/public/_nuxt/DdtQIDaq.js +1 -0
  87. package/.output/public/_nuxt/Dfz8k_Rn.js +1 -0
  88. package/.output/public/_nuxt/{Dpm6rnHk.js → DitYzGT4.js} +1 -1
  89. package/.output/public/_nuxt/{NMm6Vanu.js → Djh3G2Nf.js} +1 -1
  90. package/.output/public/_nuxt/DmWFeTaU.js +1 -0
  91. package/.output/public/_nuxt/{x85BV7y_.js → DtgJAz2h.js} +1 -1
  92. package/.output/public/_nuxt/{3jfBYqJb.js → DuKway_J.js} +1 -1
  93. package/.output/public/_nuxt/{7nPLTDFM.js → DxF9DsEl.js} +1 -1
  94. package/.output/public/_nuxt/{C9ZBCJdc.js → DyFXtlg0.js} +1 -1
  95. package/.output/public/_nuxt/DzN4YRfa.js +7 -0
  96. package/.output/public/_nuxt/{B_hWP06g.js → DzaPC1WB.js} +1 -1
  97. package/.output/public/_nuxt/{wH-P-_6A.js → DzjHXopz.js} +1 -1
  98. package/.output/public/_nuxt/{CE0zlNDo.js → LUfaevBS.js} +1 -1
  99. package/.output/public/_nuxt/{DRX1aIGD.js → RFRrMFyH.js} +1 -1
  100. package/.output/public/_nuxt/{CROH8wgk.js → RTN5rY4m.js} +1 -1
  101. package/.output/public/_nuxt/{Un5zjlKE.js → XVZ0obUR.js} +1 -1
  102. package/.output/public/_nuxt/{B5HZeat4.js → Z5g5B4NJ.js} +1 -1
  103. package/.output/public/_nuxt/_ltJfz1p.js +1 -0
  104. package/.output/public/_nuxt/builds/latest.json +1 -1
  105. package/.output/public/_nuxt/builds/meta/1cbed594-12e2-48e6-bea9-7a9159c3c1d3.json +1 -0
  106. package/.output/public/_nuxt/{DtOg0Asw.js → dkyHOJLf.js} +1 -1
  107. package/.output/public/_nuxt/entry.D1DMaixs.css +1 -0
  108. package/.output/public/_nuxt/{habs8oz6.js → gWmEw6BT.js} +1 -1
  109. package/.output/public/_nuxt/ixgiI20S.js +1 -0
  110. package/.output/public/_nuxt/{C6CFIGob.js → jJeqAxmP.js} +1 -1
  111. package/.output/public/_nuxt/{P_2SRa71.js → lisFd8W1.js} +2 -2
  112. package/.output/public/_nuxt/{CoQ_oOia.js → nrlEwpIH.js} +1 -1
  113. package/.output/public/_nuxt/{6wO6CbCo.js → uHyBIwWw.js} +1 -1
  114. package/.output/public/_nuxt/{dDqgUqt5.js → vGkKA7iH.js} +1 -1
  115. package/.output/public/_nuxt/{C445d10Z.js → z1xPtaLw.js} +1 -1
  116. package/.output/server/chunks/_/registry.mjs +116 -0
  117. package/.output/server/chunks/_/registry.mjs.map +1 -0
  118. package/.output/server/chunks/_/{native-backup.mjs → runtime.mjs} +325 -164
  119. package/.output/server/chunks/_/runtime.mjs.map +1 -0
  120. package/.output/server/chunks/_/{native-backup-jobs.mjs → service.mjs} +185 -248
  121. package/.output/server/chunks/_/service.mjs.map +1 -0
  122. package/.output/server/chunks/build/client.manifest.mjs +734 -723
  123. package/.output/server/chunks/build/client.manifest.mjs.map +1 -1
  124. package/.output/server/chunks/nitro/nitro.mjs +659 -652
  125. package/.output/server/chunks/routes/api/database-backup/capability.get.mjs +7 -2
  126. package/.output/server/chunks/routes/api/database-backup/capability.get.mjs.map +1 -1
  127. package/.output/server/chunks/routes/api/database-export/export-database.mjs +4 -3
  128. package/.output/server/chunks/routes/api/database-export/export-database.mjs.map +1 -1
  129. package/.output/server/chunks/routes/api/database-export/jobs/_jobId/download.get.mjs +1 -20
  130. package/.output/server/chunks/routes/api/database-export/jobs/_jobId/download.get.mjs.map +1 -1
  131. package/.output/server/chunks/routes/api/database-export/jobs/_jobId_.get.mjs +1 -20
  132. package/.output/server/chunks/routes/api/database-export/jobs/_jobId_.get.mjs.map +1 -1
  133. package/.output/server/chunks/routes/api/database-import/import-database.mjs +14 -3
  134. package/.output/server/chunks/routes/api/database-import/import-database.mjs.map +1 -1
  135. package/.output/server/chunks/routes/api/database-import/jobs/_jobId_.get.mjs +1 -20
  136. package/.output/server/chunks/routes/api/database-import/jobs/_jobId_.get.mjs.map +1 -1
  137. package/.output/server/package.json +1 -1
  138. package/package.json +1 -1
  139. package/.output/public/_nuxt/4OV_5qQE.js +0 -1
  140. package/.output/public/_nuxt/B3iNzG14.js +0 -1
  141. package/.output/public/_nuxt/Bf2bW_MY.js +0 -7
  142. package/.output/public/_nuxt/C7C1kq_N.js +0 -1
  143. package/.output/public/_nuxt/CN8b9qPP.js +0 -1
  144. package/.output/public/_nuxt/CUws2Uv7.js +0 -1
  145. package/.output/public/_nuxt/Cl5p4EQY.js +0 -1
  146. package/.output/public/_nuxt/D9MMtvTu.js +0 -52
  147. package/.output/public/_nuxt/DM8LJTsg.js +0 -1
  148. package/.output/public/_nuxt/ORit_vRp.js +0 -1
  149. package/.output/public/_nuxt/ZhP2FY6Y.js +0 -1
  150. package/.output/public/_nuxt/builds/meta/47c294b1-d6b3-4974-bd50-5046ae0a393e.json +0 -1
  151. package/.output/public/_nuxt/dSX5D8ur.js +0 -28
  152. package/.output/public/_nuxt/entry.CGwcggc4.css +0 -1
  153. package/.output/server/chunks/_/native-backup-jobs.mjs.map +0 -1
  154. package/.output/server/chunks/_/native-backup.mjs.map +0 -1
@@ -1,23 +1,22 @@
1
- import { c as createError, f as createSshTunnel } from '../nitro/nitro.mjs';
2
- import { spawn } from 'node:child_process';
3
1
  import { randomUUID } from 'node:crypto';
4
- import { once } from 'node:events';
5
- import { createWriteStream, createReadStream } from 'node:fs';
6
- import { mkdtemp, writeFile, stat, mkdir, readFile, rm } from 'node:fs/promises';
2
+ import { stat, mkdir, writeFile, readFile, rm, mkdtemp } from 'node:fs/promises';
7
3
  import { tmpdir } from 'node:os';
8
- import { join, basename } from 'node:path';
4
+ import { basename, join } from 'node:path';
9
5
  import { D as DatabaseClientType } from './database-client-type.mjs';
10
- import { e as ensureNativeBackupOperationAvailable, a as assertNativeBackupSupported, b as buildNativeBackupFileName, c as getNativeBackupFileKind, d as getNativeBackupCapability, f as getNativeBackupImportTool, r as resolveNativeExportFormat } from './native-backup.mjs';
6
+ import { c as createError, f as createSshTunnel } from '../nitro/nitro.mjs';
11
7
  import { c as createTableAdapter } from './tables.factory.mjs';
8
+ import { spawn } from 'node:child_process';
9
+ import { once } from 'node:events';
10
+ import { createWriteStream, createReadStream } from 'node:fs';
11
+ import { a as getNativeBackupCapability, r as resolveNativeExportFormat, e as ensureNativeBackupOperationAvailable, b as assertNativeBackupSupported, c as buildNativeBackupFileName, d as getNativeBackupFileKind, f as getNativeBackupImportTool } from './runtime.mjs';
12
+ import { c as createJobRecord, s as setJob, b as getJob, u as updateJob, d as scheduleCleanup } from './registry.mjs';
12
13
 
13
- const NATIVE_BACKUP_TTL_MS = 30 * 60 * 1e3;
14
14
  const DEFAULT_PORTS = {
15
15
  [DatabaseClientType.POSTGRES]: 5432,
16
16
  [DatabaseClientType.MYSQL]: 3306,
17
17
  [DatabaseClientType.MARIADB]: 3306,
18
18
  [DatabaseClientType.SQLITE3]: 0
19
19
  };
20
- const nativeBackupJobs = /* @__PURE__ */ new Map();
21
20
  function getDefaultPort(type) {
22
21
  var _a;
23
22
  return (_a = DEFAULT_PORTS[type]) != null ? _a : 5432;
@@ -235,6 +234,7 @@ function toDbProgress(bytesProcessed, bytesTotal, min = 15, max = 90) {
235
234
  const ratio = Math.max(0, Math.min(bytesProcessed / bytesTotal, 1));
236
235
  return Math.round(min + ratio * (max - min));
237
236
  }
237
+
238
238
  function createMissingCommandError(command) {
239
239
  const error = new Error(
240
240
  `${command} is not installed on the runtime host.`
@@ -399,77 +399,47 @@ async function runCommandCapture({
399
399
  }
400
400
  return { stdout: stdout.trim(), stderr: stderr.trim() };
401
401
  }
402
- function updateJob(jobId, patch) {
403
- const current = nativeBackupJobs.get(jobId);
404
- if (!current) {
405
- return;
406
- }
407
- nativeBackupJobs.set(jobId, {
408
- ...current,
409
- ...patch
410
- });
411
- }
412
- function getJob(jobId) {
413
- return nativeBackupJobs.get(jobId);
414
- }
415
- function scheduleCleanup(jobId) {
416
- var _a, _b, _c;
417
- const record = getJob(jobId);
418
- if (!record) {
419
- return;
420
- }
421
- (_b = (_a = record.cleanupTimer) == null ? void 0 : _a.refresh) == null ? void 0 : _b.call(_a);
422
- if (record.cleanupTimer) {
423
- clearTimeout(record.cleanupTimer);
424
- }
425
- const timer = setTimeout(() => {
426
- void destroyNativeBackupJob(jobId);
427
- }, NATIVE_BACKUP_TTL_MS);
428
- (_c = timer.unref) == null ? void 0 : _c.call(timer);
429
- updateJob(jobId, { cleanupTimer: timer });
430
- }
431
- async function destroyNativeBackupJob(jobId) {
432
- const record = getJob(jobId);
433
- if (!record) {
434
- return;
435
- }
436
- if (record.cleanupTimer) {
437
- clearTimeout(record.cleanupTimer);
438
- }
439
- nativeBackupJobs.delete(jobId);
440
- await rm(record.tempDir, { recursive: true, force: true });
441
- }
442
- function quoteMysqlIdentifier(identifier) {
443
- return `\`${identifier.replace(/`/g, "``")}\``;
444
- }
445
- async function maybeResetMysqlDatabase(connection, options) {
446
- if (!options.clean || options.dataOnly || !connection.database) {
447
- return;
402
+ async function withCommandFallback(candidates, run, requestedRuntime) {
403
+ var _a;
404
+ const requestedExecutablePath = (_a = requestedRuntime == null ? void 0 : requestedRuntime.executablePath) == null ? void 0 : _a.trim();
405
+ if (requestedExecutablePath) {
406
+ if (!(requestedRuntime == null ? void 0 : requestedRuntime.tool)) {
407
+ throw createError({
408
+ statusCode: 400,
409
+ statusMessage: "A native tool must be selected when a custom executable path is provided."
410
+ });
411
+ }
412
+ if (!candidates.includes(requestedRuntime.tool)) {
413
+ throw createError({
414
+ statusCode: 400,
415
+ statusMessage: `${requestedRuntime.tool} cannot be used for this request.`
416
+ });
417
+ }
418
+ return run({
419
+ tool: requestedRuntime.tool,
420
+ command: requestedExecutablePath,
421
+ displayName: requestedExecutablePath
422
+ });
448
423
  }
449
- const args = [
450
- "--protocol=TCP",
451
- "--host",
452
- connection.host || "127.0.0.1",
453
- "--port",
454
- String(connection.port || 3306),
455
- "--user",
456
- connection.username || "",
457
- "--execute",
458
- `DROP DATABASE IF EXISTS ${quoteMysqlIdentifier(connection.database)}; CREATE DATABASE ${quoteMysqlIdentifier(connection.database)};`
459
- ];
460
- appendMysqlSslArgs(args, connection);
461
- await runCommandCapture({
462
- command: "mysql",
463
- args,
464
- env: buildMysqlEnv(connection)
465
- });
466
- }
467
- async function maybeResetSqliteDatabase(connection, options) {
468
- if (!options.clean || options.dataOnly || !connection.filePath) {
469
- return;
424
+ let lastMissingError = null;
425
+ for (const command of candidates) {
426
+ try {
427
+ return await run({
428
+ tool: command,
429
+ command,
430
+ displayName: command
431
+ });
432
+ } catch (error) {
433
+ if (isMissingCommandError(error)) {
434
+ lastMissingError = error;
435
+ continue;
436
+ }
437
+ throw error;
438
+ }
470
439
  }
471
- await rm(connection.filePath, { force: true });
440
+ throw lastMissingError || new Error("No supported native backup tool is available.");
472
441
  }
442
+
473
443
  async function maybeFilterSqliteDumpForDataOnly(outputPath) {
474
444
  const content = await readFile(outputPath, "utf8");
475
445
  const filtered = content.split("\n").filter((line) => {
@@ -479,7 +449,7 @@ async function maybeFilterSqliteDumpForDataOnly(outputPath) {
479
449
  await writeFile(outputPath, `${filtered}
480
450
  `, "utf8");
481
451
  }
482
- async function runPostgresExport(command, connection, params, artifactPath, estimatedBytes, updateProgress) {
452
+ async function runPostgresExport(invocation, connection, params, artifactPath, estimatedBytes, updateProgress) {
483
453
  const exportFormat = resolveNativeExportFormat(
484
454
  DatabaseClientType.POSTGRES,
485
455
  params.options.format
@@ -522,14 +492,14 @@ async function runPostgresExport(command, connection, params, artifactPath, esti
522
492
  args.push("--create");
523
493
  }
524
494
  await runCommandToFile({
525
- command,
495
+ command: invocation.command,
526
496
  args,
527
497
  env: buildPostgresEnv(connection),
528
498
  outputPath: artifactPath,
529
499
  onBytes: (bytesWritten) => {
530
500
  updateProgress(
531
501
  toDbProgress(bytesWritten, estimatedBytes),
532
- `Streaming ${command} ${isPlainSql ? "SQL script" : "archive"}...`,
502
+ `Streaming ${invocation.tool} ${isPlainSql ? "SQL script" : "archive"}...`,
533
503
  bytesWritten
534
504
  );
535
505
  },
@@ -546,7 +516,7 @@ function getMysqlExportCandidates(params) {
546
516
  }
547
517
  return capability.exportToolCandidates;
548
518
  }
549
- async function runMysqlExport(command, connection, params, artifactPath, estimatedBytes, updateProgress) {
519
+ async function runMysqlExport(invocation, connection, params, artifactPath, estimatedBytes, updateProgress) {
550
520
  var _a;
551
521
  const database = connection.database || resolveDatabaseName(params);
552
522
  const args = [
@@ -559,7 +529,7 @@ async function runMysqlExport(command, connection, params, artifactPath, estimat
559
529
  connection.username || ""
560
530
  ];
561
531
  appendMysqlSslArgs(args, connection);
562
- if (command === "mysqlpump") {
532
+ if (invocation.tool === "mysqlpump") {
563
533
  args.push("--default-parallelism=2");
564
534
  } else {
565
535
  args.push("--single-transaction", "--routines", "--triggers", "--events");
@@ -582,14 +552,14 @@ async function runMysqlExport(command, connection, params, artifactPath, estimat
582
552
  args.push(table);
583
553
  });
584
554
  await runCommandToFile({
585
- command,
555
+ command: invocation.command,
586
556
  args,
587
557
  env: buildMysqlEnv(connection),
588
558
  outputPath: artifactPath,
589
559
  onBytes: (bytesWritten) => {
590
560
  updateProgress(
591
561
  toDbProgress(bytesWritten, estimatedBytes),
592
- `Streaming ${command} SQL dump...`,
562
+ `Streaming ${invocation.tool} SQL dump...`,
593
563
  bytesWritten
594
564
  );
595
565
  },
@@ -598,7 +568,7 @@ async function runMysqlExport(command, connection, params, artifactPath, estimat
598
568
  }
599
569
  });
600
570
  }
601
- async function runSqliteExport(command, connection, params, artifactPath, estimatedBytes, updateProgress) {
571
+ async function runSqliteExport(invocation, connection, params, artifactPath, estimatedBytes, updateProgress) {
602
572
  var _a;
603
573
  const dumpCommand = params.options.scope === "schema-only" ? ".schema" : ".dump";
604
574
  const args = [connection.filePath || "", dumpCommand];
@@ -606,7 +576,7 @@ async function runSqliteExport(command, connection, params, artifactPath, estima
606
576
  args.push(...params.options.tables);
607
577
  }
608
578
  await runCommandToFile({
609
- command,
579
+ command: invocation.command,
610
580
  args,
611
581
  env: process.env,
612
582
  outputPath: artifactPath,
@@ -623,9 +593,41 @@ async function runSqliteExport(command, connection, params, artifactPath, estima
623
593
  await maybeFilterSqliteDumpForDataOnly(artifactPath);
624
594
  }
625
595
  }
626
- async function runPostgresImport(command, connection, params, updateProgress) {
596
+
597
+ function quoteMysqlIdentifier(identifier) {
598
+ return `\`${identifier.replace(/`/g, "``")}\``;
599
+ }
600
+ async function maybeResetMysqlDatabase(invocation, connection, params) {
601
+ if (!params.options.clean || params.options.dataOnly || !connection.database) {
602
+ return;
603
+ }
604
+ const args = [
605
+ "--protocol=TCP",
606
+ "--host",
607
+ connection.host || "127.0.0.1",
608
+ "--port",
609
+ String(connection.port || 3306),
610
+ "--user",
611
+ connection.username || "",
612
+ "--execute",
613
+ `DROP DATABASE IF EXISTS ${quoteMysqlIdentifier(connection.database)}; CREATE DATABASE ${quoteMysqlIdentifier(connection.database)};`
614
+ ];
615
+ appendMysqlSslArgs(args, connection);
616
+ await runCommandCapture({
617
+ command: invocation.command,
618
+ args,
619
+ env: buildMysqlEnv(connection)
620
+ });
621
+ }
622
+ async function maybeResetSqliteDatabase(connection, params) {
623
+ if (!params.options.clean || params.options.dataOnly || !connection.filePath) {
624
+ return;
625
+ }
626
+ await rm(connection.filePath, { force: true });
627
+ }
628
+ async function runPostgresImport(invocation, connection, params, updateProgress) {
627
629
  const env = buildPostgresEnv(connection);
628
- if (command === "psql") {
630
+ if (invocation.tool === "psql") {
629
631
  const fileStat = await stat(params.uploadPath);
630
632
  const args2 = [
631
633
  "--host",
@@ -641,7 +643,7 @@ async function runPostgresImport(command, connection, params, updateProgress) {
641
643
  args2.push("--set", "ON_ERROR_STOP=1");
642
644
  }
643
645
  await runCommandWithInputFile({
644
- command,
646
+ command: invocation.command,
645
647
  args: args2,
646
648
  env,
647
649
  inputPath: params.uploadPath,
@@ -660,7 +662,7 @@ async function runPostgresImport(command, connection, params, updateProgress) {
660
662
  }
661
663
  const listArgs = ["--list", params.uploadPath];
662
664
  const { stdout } = await runCommandCapture({
663
- command: "pg_restore",
665
+ command: invocation.command,
664
666
  args: listArgs,
665
667
  env
666
668
  });
@@ -700,7 +702,7 @@ async function runPostgresImport(command, connection, params, updateProgress) {
700
702
  }
701
703
  args.push(params.uploadPath);
702
704
  await runCommandCapture({
703
- command: "pg_restore",
705
+ command: invocation.command,
704
706
  args,
705
707
  env,
706
708
  onStderrLine: (line) => {
@@ -713,8 +715,8 @@ async function runPostgresImport(command, connection, params, updateProgress) {
713
715
  });
714
716
  updateProgress(95, `Processed ${estimatedSteps} pg_restore entries.`);
715
717
  }
716
- async function runMysqlImport(connection, params, updateProgress) {
717
- await maybeResetMysqlDatabase(connection, params.options);
718
+ async function runMysqlImport(invocation, connection, params, updateProgress) {
719
+ await maybeResetMysqlDatabase(invocation, connection, params);
718
720
  const fileStat = await stat(params.uploadPath);
719
721
  const args = [
720
722
  "--protocol=TCP",
@@ -730,7 +732,7 @@ async function runMysqlImport(connection, params, updateProgress) {
730
732
  args.push(connection.database);
731
733
  }
732
734
  await runCommandWithInputFile({
733
- command: "mysql",
735
+ command: invocation.command,
734
736
  args,
735
737
  env: buildMysqlEnv(connection),
736
738
  inputPath: params.uploadPath,
@@ -746,11 +748,11 @@ async function runMysqlImport(connection, params, updateProgress) {
746
748
  }
747
749
  });
748
750
  }
749
- async function runSqliteImport(connection, params, updateProgress) {
750
- await maybeResetSqliteDatabase(connection, params.options);
751
+ async function runSqliteImport(invocation, connection, params, updateProgress) {
752
+ await maybeResetSqliteDatabase(connection, params);
751
753
  const fileStat = await stat(params.uploadPath);
752
754
  await runCommandWithInputFile({
753
- command: "sqlite3",
755
+ command: invocation.command,
754
756
  args: [connection.filePath || ""],
755
757
  env: process.env,
756
758
  inputPath: params.uploadPath,
@@ -766,35 +768,7 @@ async function runSqliteImport(connection, params, updateProgress) {
766
768
  }
767
769
  });
768
770
  }
769
- async function withCommandFallback(candidates, run) {
770
- let lastMissingError = null;
771
- for (const command of candidates) {
772
- try {
773
- return await run(command);
774
- } catch (error) {
775
- if (isMissingCommandError(error)) {
776
- lastMissingError = error;
777
- continue;
778
- }
779
- throw error;
780
- }
781
- }
782
- throw lastMissingError || new Error("No supported native backup tool is available.");
783
- }
784
- function createJobRecord(jobId, operation, type, tempDir, tool) {
785
- return {
786
- jobId,
787
- operation,
788
- status: "queued",
789
- stage: "queued",
790
- databaseType: type,
791
- tool,
792
- progress: 0,
793
- message: "Queued",
794
- startedAt: (/* @__PURE__ */ new Date()).toISOString(),
795
- tempDir
796
- };
797
- }
771
+
798
772
  async function runNativeExportJob(jobId, params) {
799
773
  var _a;
800
774
  const record = getJob(jobId);
@@ -815,16 +789,16 @@ async function runNativeExportJob(jobId, params) {
815
789
  const capability = getNativeBackupCapability(params.type);
816
790
  await withCommandFallback(
817
791
  params.type === DatabaseClientType.MYSQL || params.type === DatabaseClientType.MARIADB ? getMysqlExportCandidates(params) : capability.exportToolCandidates,
818
- async (command) => {
792
+ async (invocation) => {
819
793
  updateJob(jobId, {
820
794
  stage: "starting",
821
795
  progress: 10,
822
- tool: command,
823
- message: `Starting ${command}...`
796
+ tool: invocation.displayName,
797
+ message: `Starting ${invocation.displayName}...`
824
798
  });
825
799
  if (params.type === DatabaseClientType.POSTGRES) {
826
800
  await runPostgresExport(
827
- command,
801
+ invocation,
828
802
  connection,
829
803
  params,
830
804
  record.artifactPath || "",
@@ -845,7 +819,7 @@ async function runNativeExportJob(jobId, params) {
845
819
  }
846
820
  if (params.type === DatabaseClientType.MYSQL || params.type === DatabaseClientType.MARIADB) {
847
821
  await runMysqlExport(
848
- command,
822
+ invocation,
849
823
  connection,
850
824
  params,
851
825
  record.artifactPath || "",
@@ -866,7 +840,7 @@ async function runNativeExportJob(jobId, params) {
866
840
  }
867
841
  if (params.type === DatabaseClientType.SQLITE3) {
868
842
  await runSqliteExport(
869
- command,
843
+ invocation,
870
844
  connection,
871
845
  params,
872
846
  record.artifactPath || "",
@@ -883,9 +857,9 @@ async function runNativeExportJob(jobId, params) {
883
857
  });
884
858
  }
885
859
  );
886
- return;
887
860
  }
888
- }
861
+ },
862
+ params.runtime
889
863
  );
890
864
  const fileStat = await stat(record.artifactPath || "");
891
865
  updateJob(jobId, {
@@ -933,65 +907,71 @@ async function runNativeImportJob(jobId, params) {
933
907
  connection = await resolveCliConnection(params, record.tempDir);
934
908
  const capability = getNativeBackupCapability(params.type);
935
909
  const importToolCandidates = params.type === DatabaseClientType.POSTGRES ? [getNativeBackupImportTool(params.type, params.uploadFileName)] : capability.importToolCandidates;
936
- await withCommandFallback(importToolCandidates, async (command) => {
937
- updateJob(jobId, {
938
- stage: "starting",
939
- progress: 10,
940
- tool: command,
941
- message: `Starting ${command}...`
942
- });
943
- if (params.type === DatabaseClientType.POSTGRES) {
944
- await runPostgresImport(
945
- command,
946
- connection,
947
- params,
948
- (progress, message, bytes) => {
949
- var _a2, _b;
950
- const previousProgress = (_b = (_a2 = getJob(jobId)) == null ? void 0 : _a2.progress) != null ? _b : null;
951
- updateJob(jobId, {
952
- stage: "restoring",
953
- progress: progress != null ? progress : previousProgress,
954
- bytesProcessed: bytes,
955
- message
956
- });
957
- }
958
- );
959
- return;
960
- }
961
- if (params.type === DatabaseClientType.MYSQL || params.type === DatabaseClientType.MARIADB) {
962
- await runMysqlImport(
963
- connection,
964
- params,
965
- (progress, message, bytes) => {
966
- var _a2, _b;
967
- const previousProgress = (_b = (_a2 = getJob(jobId)) == null ? void 0 : _a2.progress) != null ? _b : null;
968
- updateJob(jobId, {
969
- stage: "restoring",
970
- progress: progress != null ? progress : previousProgress,
971
- bytesProcessed: bytes,
972
- message
973
- });
974
- }
975
- );
976
- return;
977
- }
978
- if (params.type === DatabaseClientType.SQLITE3) {
979
- await runSqliteImport(
980
- connection,
981
- params,
982
- (progress, message, bytes) => {
983
- var _a2, _b;
984
- const previousProgress = (_b = (_a2 = getJob(jobId)) == null ? void 0 : _a2.progress) != null ? _b : null;
985
- updateJob(jobId, {
986
- stage: "restoring",
987
- progress: progress != null ? progress : previousProgress,
988
- bytesProcessed: bytes,
989
- message
990
- });
991
- }
992
- );
993
- }
994
- });
910
+ await withCommandFallback(
911
+ importToolCandidates,
912
+ async (invocation) => {
913
+ updateJob(jobId, {
914
+ stage: "starting",
915
+ progress: 10,
916
+ tool: invocation.displayName,
917
+ message: `Starting ${invocation.displayName}...`
918
+ });
919
+ if (params.type === DatabaseClientType.POSTGRES) {
920
+ await runPostgresImport(
921
+ invocation,
922
+ connection,
923
+ params,
924
+ (progress, message, bytes) => {
925
+ var _a2, _b;
926
+ const previousProgress = (_b = (_a2 = getJob(jobId)) == null ? void 0 : _a2.progress) != null ? _b : null;
927
+ updateJob(jobId, {
928
+ stage: "restoring",
929
+ progress: progress != null ? progress : previousProgress,
930
+ bytesProcessed: bytes,
931
+ message
932
+ });
933
+ }
934
+ );
935
+ return;
936
+ }
937
+ if (params.type === DatabaseClientType.MYSQL || params.type === DatabaseClientType.MARIADB) {
938
+ await runMysqlImport(
939
+ invocation,
940
+ connection,
941
+ params,
942
+ (progress, message, bytes) => {
943
+ var _a2, _b;
944
+ const previousProgress = (_b = (_a2 = getJob(jobId)) == null ? void 0 : _a2.progress) != null ? _b : null;
945
+ updateJob(jobId, {
946
+ stage: "restoring",
947
+ progress: progress != null ? progress : previousProgress,
948
+ bytesProcessed: bytes,
949
+ message
950
+ });
951
+ }
952
+ );
953
+ return;
954
+ }
955
+ if (params.type === DatabaseClientType.SQLITE3) {
956
+ await runSqliteImport(
957
+ invocation,
958
+ connection,
959
+ params,
960
+ (progress, message, bytes) => {
961
+ var _a2, _b;
962
+ const previousProgress = (_b = (_a2 = getJob(jobId)) == null ? void 0 : _a2.progress) != null ? _b : null;
963
+ updateJob(jobId, {
964
+ stage: "restoring",
965
+ progress: progress != null ? progress : previousProgress,
966
+ bytesProcessed: bytes,
967
+ message
968
+ });
969
+ }
970
+ );
971
+ }
972
+ },
973
+ params.runtime
974
+ );
995
975
  updateJob(jobId, {
996
976
  status: "completed",
997
977
  stage: "completed",
@@ -1016,7 +996,12 @@ async function runNativeImportJob(jobId, params) {
1016
996
  }
1017
997
  }
1018
998
  async function startNativeExportJob(params) {
1019
- await ensureNativeBackupOperationAvailable(params.type, "export");
999
+ await ensureNativeBackupOperationAvailable(
1000
+ params.type,
1001
+ "export",
1002
+ void 0,
1003
+ params.runtime
1004
+ );
1020
1005
  assertNativeBackupSupported(params.type);
1021
1006
  const tempDir = await mkdtemp(join(tmpdir(), "heraq-native-export-"));
1022
1007
  const jobId = randomUUID();
@@ -1034,7 +1019,7 @@ async function startNativeExportJob(params) {
1034
1019
  tempDir,
1035
1020
  "pending"
1036
1021
  );
1037
- nativeBackupJobs.set(jobId, {
1022
+ setJob(jobId, {
1038
1023
  ...record,
1039
1024
  artifactPath: join(tempDir, artifactName),
1040
1025
  artifactContentType: fileKind === "sql" ? "application/sql; charset=utf-8" : "application/octet-stream",
@@ -1051,7 +1036,8 @@ async function startNativeImportJob(params) {
1051
1036
  await ensureNativeBackupOperationAvailable(
1052
1037
  params.type,
1053
1038
  "import",
1054
- params.uploadFileName
1039
+ params.uploadFileName,
1040
+ params.runtime
1055
1041
  );
1056
1042
  assertNativeBackupSupported(params.type);
1057
1043
  const tempDir = await mkdtemp(join(tmpdir(), "heraq-native-import-"));
@@ -1065,7 +1051,7 @@ async function startNativeImportJob(params) {
1065
1051
  "pending"
1066
1052
  );
1067
1053
  await writeFile(uploadPath, params.fileData);
1068
- nativeBackupJobs.set(jobId, {
1054
+ setJob(jobId, {
1069
1055
  ...record,
1070
1056
  uploadPath
1071
1057
  });
@@ -1078,55 +1064,6 @@ async function startNativeImportJob(params) {
1078
1064
  statusUrl: `/api/database-import/jobs/${jobId}`
1079
1065
  };
1080
1066
  }
1081
- function getNativeBackupJobSnapshot(jobId) {
1082
- const record = getJob(jobId);
1083
- if (!record) {
1084
- throw createError({
1085
- statusCode: 404,
1086
- statusMessage: "Backup job not found or has expired."
1087
- });
1088
- }
1089
- return {
1090
- jobId: record.jobId,
1091
- operation: record.operation,
1092
- status: record.status,
1093
- stage: record.stage,
1094
- databaseType: record.databaseType,
1095
- tool: record.tool,
1096
- progress: record.progress,
1097
- message: record.message,
1098
- bytesProcessed: record.bytesProcessed,
1099
- bytesTotal: record.bytesTotal,
1100
- startedAt: record.startedAt,
1101
- completedAt: record.completedAt,
1102
- duration: record.duration,
1103
- downloadReady: record.downloadReady,
1104
- downloadFileName: record.downloadFileName,
1105
- downloadUrl: record.downloadUrl,
1106
- warnings: record.warnings,
1107
- error: record.error
1108
- };
1109
- }
1110
- function getNativeExportDownload(jobId) {
1111
- const record = getJob(jobId);
1112
- if (!record || record.operation !== "export" || !record.artifactPath) {
1113
- throw createError({
1114
- statusCode: 404,
1115
- statusMessage: "Export artifact not found or has expired."
1116
- });
1117
- }
1118
- if (record.status !== "completed") {
1119
- throw createError({
1120
- statusCode: 409,
1121
- statusMessage: "Export artifact is not ready yet."
1122
- });
1123
- }
1124
- return {
1125
- filePath: record.artifactPath,
1126
- fileName: record.downloadFileName || basename(record.artifactPath),
1127
- contentType: record.artifactContentType || "application/octet-stream"
1128
- };
1129
- }
1130
1067
 
1131
- export { getNativeExportDownload as a, startNativeImportJob as b, getNativeBackupJobSnapshot as g, startNativeExportJob as s };
1132
- //# sourceMappingURL=native-backup-jobs.mjs.map
1068
+ export { startNativeImportJob as a, startNativeExportJob as s };
1069
+ //# sourceMappingURL=service.mjs.map