@datatruck/cli 0.17.0 → 0.17.2

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/Action/BackupAction.d.ts +1 -1
  2. package/Action/BackupAction.js +14 -14
  3. package/Action/BackupSessionsAction.d.ts +1 -1
  4. package/Action/CleanCacheAction.d.ts +1 -1
  5. package/Action/CleanCacheAction.js +3 -3
  6. package/Action/ConfigAction.d.ts +1 -1
  7. package/Action/ConfigAction.js +5 -5
  8. package/Action/InitAction.d.ts +1 -1
  9. package/Action/InitAction.js +2 -2
  10. package/Action/PruneAction.d.ts +1 -1
  11. package/Action/PruneAction.js +4 -4
  12. package/Action/RestoreAction.d.ts +1 -1
  13. package/Action/RestoreAction.js +18 -18
  14. package/Action/RestoreSessionsAction.d.ts +1 -1
  15. package/Action/SnapshotsAction.d.ts +1 -1
  16. package/Action/SnapshotsAction.js +4 -4
  17. package/Command/BackupCommand.d.ts +2 -2
  18. package/Command/BackupCommand.js +6 -6
  19. package/Command/BackupSessionsCommand.d.ts +2 -2
  20. package/Command/BackupSessionsCommand.js +9 -9
  21. package/Command/CleanCacheCommand.d.ts +1 -1
  22. package/Command/CleanCacheCommand.js +2 -2
  23. package/Command/CommandAbstract.d.ts +3 -3
  24. package/Command/CommandAbstract.js +2 -2
  25. package/Command/ConfigCommand.d.ts +2 -2
  26. package/Command/ConfigCommand.js +8 -8
  27. package/Command/InitCommand.d.ts +2 -2
  28. package/Command/InitCommand.js +9 -9
  29. package/Command/PruneCommand.d.ts +2 -2
  30. package/Command/PruneCommand.js +10 -10
  31. package/Command/RestoreCommand.d.ts +2 -2
  32. package/Command/RestoreCommand.js +6 -6
  33. package/Command/RestoreSessionsCommand.d.ts +2 -2
  34. package/Command/RestoreSessionsCommand.js +9 -9
  35. package/Command/SnapshotsCommand.d.ts +2 -2
  36. package/Command/SnapshotsCommand.js +9 -9
  37. package/Entity/StateEntityAbstract.d.ts +1 -1
  38. package/Repository/DatatruckRepository.d.ts +1 -1
  39. package/Repository/DatatruckRepository.js +56 -52
  40. package/Repository/GitRepository.js +23 -23
  41. package/Repository/RepositoryAbstract.d.ts +1 -1
  42. package/Repository/RepositoryAbstract.js +2 -2
  43. package/Repository/ResticRepository.d.ts +1 -1
  44. package/Repository/ResticRepository.js +27 -27
  45. package/SessionDriver/ConsoleSessionDriver.d.ts +1 -1
  46. package/SessionDriver/ConsoleSessionDriver.js +10 -10
  47. package/SessionDriver/SqliteSessionDriver.js +12 -12
  48. package/SessionManager/BackupSessionManager.d.ts +2 -2
  49. package/SessionManager/BackupSessionManager.js +1 -1
  50. package/SessionManager/RestoreSessionManager.d.ts +2 -2
  51. package/SessionManager/RestoreSessionManager.js +1 -1
  52. package/Task/GitTask.js +21 -21
  53. package/Task/MariadbTask.js +11 -11
  54. package/Task/MssqlTask.js +8 -8
  55. package/Task/MysqlDumpTask.d.ts +1 -1
  56. package/Task/MysqlDumpTask.js +13 -13
  57. package/Task/PostgresqlDumpTask.d.ts +1 -1
  58. package/Task/PostgresqlDumpTask.js +4 -4
  59. package/Task/ScriptTask.js +7 -7
  60. package/Task/SqlDumpTaskAbstract.d.ts +1 -1
  61. package/Task/SqlDumpTaskAbstract.js +12 -12
  62. package/Task/TaskAbstract.d.ts +1 -1
  63. package/Task/TaskAbstract.js +2 -2
  64. package/cli.js +11 -11
  65. package/package.json +1 -1
  66. package/{util → utils}/DataFormat.d.ts +0 -0
  67. package/{util → utils}/DataFormat.js +5 -1
  68. package/{util/GitUtil.d.ts → utils/Git.d.ts} +8 -8
  69. package/{util/GitUtil.js → utils/Git.js} +8 -8
  70. package/{util → utils}/ObjectVault.d.ts +0 -0
  71. package/{util → utils}/ObjectVault.js +0 -0
  72. package/{util/ResticUtil.d.ts → utils/Restic.d.ts} +3 -3
  73. package/{util/ResticUtil.js → utils/Restic.js} +9 -9
  74. package/{util/cli-util.d.ts → utils/cli.d.ts} +0 -0
  75. package/{util/cli-util.js → utils/cli.js} +0 -0
  76. package/{util/datatruck/config-util.d.ts → utils/datatruck/config.d.ts} +0 -0
  77. package/{util/datatruck/config-util.js → utils/datatruck/config.js} +10 -10
  78. package/{util/datatruck/paths-util.d.ts → utils/datatruck/paths.d.ts} +0 -0
  79. package/{util/datatruck/paths-util.js → utils/datatruck/paths.js} +2 -2
  80. package/{util/datatruck/snapshot-util.d.ts → utils/datatruck/snapshot.d.ts} +1 -1
  81. package/{util/datatruck/snapshot-util.js → utils/datatruck/snapshot.js} +4 -4
  82. package/{util/date-util.d.ts → utils/date.d.ts} +0 -0
  83. package/{util/date-util.js → utils/date.js} +2 -2
  84. package/{util/entity-util.d.ts → utils/entity.d.ts} +0 -0
  85. package/{util/entity-util.js → utils/entity.js} +0 -0
  86. package/{util/fs-util.d.ts → utils/fs.d.ts} +0 -0
  87. package/{util/fs-util.js → utils/fs.js} +17 -17
  88. package/{util/math-util.d.ts → utils/math.d.ts} +0 -0
  89. package/{util/math-util.js → utils/math.js} +0 -0
  90. package/{util/object-util.d.ts → utils/object.d.ts} +0 -0
  91. package/{util/object-util.js → utils/object.js} +0 -0
  92. package/{util/path-util.d.ts → utils/path.d.ts} +0 -0
  93. package/{util/path-util.js → utils/path.js} +0 -0
  94. package/{util/process-util.d.ts → utils/process.d.ts} +0 -0
  95. package/{util/process-util.js → utils/process.js} +13 -13
  96. package/{util → utils}/progress.d.ts +0 -0
  97. package/{util → utils}/progress.js +0 -0
  98. package/{util/string-util.d.ts → utils/string.d.ts} +0 -0
  99. package/{util/string-util.js → utils/string.js} +0 -0
  100. package/{util/zip-util.d.ts → utils/zip.d.ts} +0 -0
  101. package/{util/zip-util.js → utils/zip.js} +5 -5
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ConsoleSessionDriver = void 0;
7
7
  const AppError_1 = require("../Error/AppError");
8
- const cli_util_1 = require("../util/cli-util");
9
- const date_util_1 = require("../util/date-util");
8
+ const cli_1 = require("../utils/cli");
9
+ const date_1 = require("../utils/date");
10
10
  const SessionDriverAbstract_1 = require("./SessionDriverAbstract");
11
11
  const chalk_1 = require("chalk");
12
12
  const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
@@ -17,7 +17,7 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
17
17
  constructor() {
18
18
  super(...arguments);
19
19
  this.prints = 0;
20
- this.chron = (0, date_util_1.createChron)();
20
+ this.chron = (0, date_1.createChron)();
21
21
  }
22
22
  async onInit() {
23
23
  this.tty = this.options.verbose
@@ -34,8 +34,8 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
34
34
  async onEnd(data) {
35
35
  clearInterval(this.renderInterval);
36
36
  if (this.tty)
37
- process.stdout.write(cli_util_1.showCursorCommand);
38
- (0, cli_util_1.logVars)({
37
+ process.stdout.write(cli_1.showCursorCommand);
38
+ (0, cli_1.logVars)({
39
39
  ...data,
40
40
  elapsed: this.chron.elapsed(true),
41
41
  });
@@ -56,10 +56,10 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
56
56
  const line = this.renderSpinner(text);
57
57
  const [truncatedLine, truncated] = endMessage
58
58
  ? [line, false]
59
- : (0, cli_util_1.truncate)(line, columns);
59
+ : (0, cli_1.truncate)(line, columns);
60
60
  if (this.lastColumns && columns !== this.lastColumns && truncated)
61
- process.stdout.write(`${cli_util_1.clearCommand}\n`);
62
- process.stdout.write(`${cli_util_1.clearCommand}${truncatedLine}${cli_util_1.hideCursorCommand}`);
61
+ process.stdout.write(`${cli_1.clearCommand}\n`);
62
+ process.stdout.write(`${cli_1.clearCommand}${truncatedLine}${cli_1.hideCursorCommand}`);
63
63
  this.lastColumns = columns;
64
64
  }
65
65
  this.prints++;
@@ -67,7 +67,7 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
67
67
  this.lastMessageText = text;
68
68
  }
69
69
  renderSpinner(text) {
70
- return text.replace("{spinner}", (0, chalk_1.grey)(this.tty ? (0, cli_util_1.renderSpinner)(this.prints) : "?"));
70
+ return text.replace("{spinner}", (0, chalk_1.grey)(this.tty ? (0, cli_1.renderSpinner)(this.prints) : "?"));
71
71
  }
72
72
  renderMessage(message) {
73
73
  const badges = renderBadges([
@@ -85,7 +85,7 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
85
85
  const relative = progress?.relative || {};
86
86
  if (typeof absolute.percent === "number" ||
87
87
  typeof relative.percent === "number") {
88
- parts.push((0, cli_util_1.renderProgressBar)(absolute.percent ?? 0, 10, relative.percent ?? undefined));
88
+ parts.push((0, cli_1.renderProgressBar)(absolute.percent ?? 0, 10, relative.percent ?? undefined));
89
89
  }
90
90
  const createProgressParts = (p) => {
91
91
  const result = [];
@@ -9,14 +9,14 @@ const BackupSessionEntity_1 = require("../Entity/BackupSessionEntity");
9
9
  const BackupSessionRepositoryEntity_1 = require("../Entity/BackupSessionRepositoryEntity");
10
10
  const RestoreSessionEntity_1 = require("../Entity/RestoreSessionEntity");
11
11
  const RestoreSessionRepositoryEntity_1 = require("../Entity/RestoreSessionRepositoryEntity");
12
- const cli_util_1 = require("../util/cli-util");
13
- const entity_util_1 = require("../util/entity-util");
14
- const path_util_1 = require("../util/path-util");
15
- const process_util_1 = require("../util/process-util");
12
+ const cli_1 = require("../utils/cli");
13
+ const entity_1 = require("../utils/entity");
14
+ const path_1 = require("../utils/path");
15
+ const process_1 = require("../utils/process");
16
16
  const SessionDriverAbstract_1 = require("./SessionDriverAbstract");
17
17
  const assert_1 = require("assert");
18
18
  const os_1 = require("os");
19
- const path_1 = require("path");
19
+ const path_2 = require("path");
20
20
  const sqlite_1 = require("sqlite");
21
21
  const sqlite3_1 = __importDefault(require("sqlite3"));
22
22
  class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract {
@@ -27,11 +27,11 @@ class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
27
27
  async onInit() {
28
28
  this.db = await (0, sqlite_1.open)({
29
29
  filename: process.env["DATATRUCK_SQLITE_DB"] ??
30
- (0, path_1.join)((0, os_1.homedir)(), "datatruck.sqlite"),
30
+ (0, path_2.join)((0, os_1.homedir)(), "datatruck.sqlite"),
31
31
  driver: sqlite3_1.default.Database,
32
32
  });
33
33
  await this.db.migrate({
34
- migrationsPath: (0, path_1.join)(path_util_1.rootPath, "migrations"),
34
+ migrationsPath: (0, path_2.join)(path_1.rootPath, "migrations"),
35
35
  });
36
36
  }
37
37
  buildInsertStm(tableName, values) {
@@ -49,12 +49,12 @@ class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
49
49
  }
50
50
  async exec(query, cb) {
51
51
  if (this.options.verbose) {
52
- (0, cli_util_1.logExec)("query");
53
- (0, process_util_1.logExecStdout)({ data: query, lineSalt: true });
52
+ (0, cli_1.logExec)("query");
53
+ (0, process_1.logExecStdout)({ data: query, lineSalt: true });
54
54
  }
55
55
  const result = await cb();
56
56
  if (this.options.verbose)
57
- (0, process_util_1.logExecStdout)({ data: JSON.stringify(result, null, 2), lineSalt: true });
57
+ (0, process_1.logExecStdout)({ data: JSON.stringify(result, null, 2), lineSalt: true });
58
58
  return result;
59
59
  }
60
60
  async onRead(data, type) {
@@ -64,8 +64,8 @@ class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
64
64
  const sessionRepositoryMeta = (0, EntityDecorator_1.EntityDecoratorHandler)(type === SessionDriverAbstract_1.EntityEnum.BackupSession
65
65
  ? BackupSessionRepositoryEntity_1.BackupSessionRepositoryEntity
66
66
  : RestoreSessionRepositoryEntity_1.RestoreSessionRepositoryEntity);
67
- const sessionTable = (0, entity_util_1.makeTableSelector)(sessionMeta.get().tableName);
68
- const repoTable = (0, entity_util_1.makeTableSelector)(sessionRepositoryMeta.get().tableName);
67
+ const sessionTable = (0, entity_1.makeTableSelector)(sessionMeta.get().tableName);
68
+ const repoTable = (0, entity_1.makeTableSelector)(sessionRepositoryMeta.get().tableName);
69
69
  const where = {};
70
70
  if (data.packageNames)
71
71
  where[sessionTable("packageName")] = data.packageNames;
@@ -3,8 +3,8 @@ import { BackupSessionEntity } from "../Entity/BackupSessionEntity";
3
3
  import { BackupSessionRepositoryEntity } from "../Entity/BackupSessionRepositoryEntity";
4
4
  import { BackupSessionTaskEntity } from "../Entity/BackupSessionTaskEntity";
5
5
  import { WriteDataType } from "../SessionDriver/SessionDriverAbstract";
6
- import { ObjectVault } from "../util/ObjectVault";
7
- import { Progress } from "../util/progress";
6
+ import { ObjectVault } from "../utils/ObjectVault";
7
+ import { Progress } from "../utils/progress";
8
8
  import SessionManagerAbstract from "./SessionManagerAbstract";
9
9
  export declare class BackupSessionManager extends SessionManagerAbstract {
10
10
  sessionVault: ObjectVault<BackupSessionEntity>;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BackupSessionManager = void 0;
7
7
  const SessionDriverAbstract_1 = require("../SessionDriver/SessionDriverAbstract");
8
- const ObjectVault_1 = require("../util/ObjectVault");
8
+ const ObjectVault_1 = require("../utils/ObjectVault");
9
9
  const SessionManagerAbstract_1 = __importDefault(require("./SessionManagerAbstract"));
10
10
  class BackupSessionManager extends SessionManagerAbstract_1.default {
11
11
  constructor() {
@@ -3,8 +3,8 @@ import { RestoreSessionEntity } from "../Entity/RestoreSessionEntity";
3
3
  import { RestoreSessionRepositoryEntity } from "../Entity/RestoreSessionRepositoryEntity";
4
4
  import { RestoreSessionTaskEntity } from "../Entity/RestoreSessionTaskEntity";
5
5
  import { WriteDataType } from "../SessionDriver/SessionDriverAbstract";
6
- import { ObjectVault } from "../util/ObjectVault";
7
- import { Progress } from "../util/progress";
6
+ import { ObjectVault } from "../utils/ObjectVault";
7
+ import { Progress } from "../utils/progress";
8
8
  import SessionManagerAbstract from "./SessionManagerAbstract";
9
9
  export declare class RestoreSessionManager extends SessionManagerAbstract {
10
10
  sessionVault: ObjectVault<RestoreSessionEntity>;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RestoreSessionManager = void 0;
7
7
  const SessionDriverAbstract_1 = require("../SessionDriver/SessionDriverAbstract");
8
- const ObjectVault_1 = require("../util/ObjectVault");
8
+ const ObjectVault_1 = require("../utils/ObjectVault");
9
9
  const SessionManagerAbstract_1 = __importDefault(require("./SessionManagerAbstract"));
10
10
  class RestoreSessionManager extends SessionManagerAbstract_1.default {
11
11
  constructor() {
package/Task/GitTask.js CHANGED
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GitTask = exports.gitTaskDefinition = exports.gitTaskName = void 0;
4
4
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
5
- const cli_util_1 = require("../util/cli-util");
6
- const fs_util_1 = require("../util/fs-util");
7
- const math_util_1 = require("../util/math-util");
8
- const process_util_1 = require("../util/process-util");
5
+ const cli_1 = require("../utils/cli");
6
+ const fs_1 = require("../utils/fs");
7
+ const math_1 = require("../utils/math");
8
+ const process_1 = require("../utils/process");
9
9
  const TaskAbstract_1 = require("./TaskAbstract");
10
10
  const assert_1 = require("assert");
11
- const fs_1 = require("fs");
11
+ const fs_2 = require("fs");
12
12
  const promises_1 = require("fs/promises");
13
13
  const micromatch_1 = require("micromatch");
14
14
  const path_1 = require("path");
@@ -77,7 +77,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
77
77
  description: "Creating bundle",
78
78
  },
79
79
  });
80
- await (0, process_util_1.exec)(this.command, ["bundle", "create", bundlePath, "--all"], {
80
+ await (0, process_1.exec)(this.command, ["bundle", "create", bundlePath, "--all"], {
81
81
  cwd: path,
82
82
  }, {
83
83
  log: this.verbose,
@@ -112,11 +112,11 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
112
112
  if (!option.include)
113
113
  continue;
114
114
  option.pathsPath = (0, path_1.join)(targetPath, `repo.${option.name}-paths.txt`);
115
- const stream = (0, fs_1.createWriteStream)(option.pathsPath);
115
+ const stream = (0, fs_2.createWriteStream)(option.pathsPath);
116
116
  let streamError;
117
117
  stream.on("error", (e) => (streamError = e));
118
118
  try {
119
- await (0, process_util_1.exec)(this.command, [
119
+ await (0, process_1.exec)(this.command, [
120
120
  "-c",
121
121
  "core.quotepath=off",
122
122
  "ls-files",
@@ -161,10 +161,10 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
161
161
  if (!option.include)
162
162
  continue;
163
163
  const outPath = (0, path_1.join)(targetPath, `repo.${option.name}`);
164
- await (0, fs_util_1.mkdirIfNotExists)(outPath);
164
+ await (0, fs_1.mkdirIfNotExists)(outPath);
165
165
  if (data.options.verbose)
166
- (0, cli_util_1.logExec)(`Copying ${option.name} files to ${outPath}`);
167
- await (0, fs_util_1.cpy)({
166
+ (0, cli_1.logExec)(`Copying ${option.name} files to ${outPath}`);
167
+ await (0, fs_1.cpy)({
168
168
  input: {
169
169
  type: "pathList",
170
170
  path: option.pathsPath,
@@ -183,7 +183,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
183
183
  absolute: {
184
184
  total,
185
185
  current: currentFiles,
186
- percent: (0, math_util_1.progressPercent)(total, currentFiles),
186
+ percent: (0, math_1.progressPercent)(total, currentFiles),
187
187
  },
188
188
  });
189
189
  },
@@ -202,18 +202,18 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
202
202
  const targetPath = data.targetPath;
203
203
  (0, assert_1.ok)(typeof restorePath === "string");
204
204
  (0, assert_1.ok)(typeof targetPath === "string");
205
- await (0, fs_util_1.mkdirIfNotExists)(restorePath);
206
- await (0, fs_util_1.ensureEmptyDir)(restorePath);
205
+ await (0, fs_1.mkdirIfNotExists)(restorePath);
206
+ await (0, fs_1.ensureEmptyDir)(restorePath);
207
207
  // Stats
208
208
  let totalFiles = 0;
209
209
  let currentFiles = 0;
210
- await (0, fs_util_1.forEachFile)(targetPath, () => totalFiles++, true);
210
+ await (0, fs_1.forEachFile)(targetPath, () => totalFiles++, true);
211
211
  const incrementProgress = async (description, item, count = true) => {
212
212
  await data.onProgress({
213
213
  absolute: {
214
214
  total: totalFiles,
215
215
  current: Math.max(currentFiles, 0),
216
- percent: (0, math_util_1.progressPercent)(totalFiles, Math.max(currentFiles, 0)),
216
+ percent: (0, math_1.progressPercent)(totalFiles, Math.max(currentFiles, 0)),
217
217
  },
218
218
  relative: { description, payload: item },
219
219
  });
@@ -222,7 +222,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
222
222
  };
223
223
  // Bundle
224
224
  const bundlePath = (0, path_1.join)(targetPath, "repo.bundle");
225
- await (0, process_util_1.exec)(this.command, ["clone", bundlePath, "."], {
225
+ await (0, process_1.exec)(this.command, ["clone", bundlePath, "."], {
226
226
  cwd: restorePath,
227
227
  }, {
228
228
  log: this.verbose,
@@ -230,17 +230,17 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
230
230
  await incrementProgress();
231
231
  // Config
232
232
  const configPath = (0, path_1.join)(targetPath, "repo.config");
233
- if (await (0, fs_util_1.checkFile)(configPath)) {
233
+ if (await (0, fs_1.checkFile)(configPath)) {
234
234
  await (0, promises_1.copyFile)(configPath, (0, path_1.join)(restorePath, ".git", "config"));
235
235
  await incrementProgress();
236
236
  }
237
237
  // ls-files
238
238
  for (const name of ["untracked", "modified", "ignored"]) {
239
239
  const sourcePath = (0, path_1.join)(targetPath, `repo.${name}`);
240
- if (await (0, fs_util_1.checkDir)(sourcePath)) {
240
+ if (await (0, fs_1.checkDir)(sourcePath)) {
241
241
  if (data.options.verbose)
242
- (0, cli_util_1.logExec)(`Copying ${name} files to ${restorePath}`);
243
- await (0, fs_util_1.cpy)({
242
+ (0, cli_1.logExec)(`Copying ${name} files to ${restorePath}`);
243
+ await (0, fs_1.cpy)({
244
244
  input: {
245
245
  type: "glob",
246
246
  sourcePath,
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MariadbTask = exports.mariadbTaskDefinition = exports.mariadbTaskName = void 0;
4
4
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
5
- const cli_util_1 = require("../util/cli-util");
6
- const fs_util_1 = require("../util/fs-util");
7
- const math_util_1 = require("../util/math-util");
8
- const process_util_1 = require("../util/process-util");
5
+ const cli_1 = require("../utils/cli");
6
+ const fs_1 = require("../utils/fs");
7
+ const math_1 = require("../utils/math");
8
+ const process_1 = require("../utils/process");
9
9
  const TaskAbstract_1 = require("./TaskAbstract");
10
10
  const assert_1 = require("assert");
11
11
  const promises_1 = require("fs/promises");
@@ -80,7 +80,7 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
80
80
  args.push(`--tables-exclude=^(${config.excludeTables.join("|")})$`);
81
81
  let total = 0;
82
82
  let current = 0;
83
- await (0, fs_util_1.forEachFile)(sourcePath, () => {
83
+ await (0, fs_1.forEachFile)(sourcePath, () => {
84
84
  total++;
85
85
  });
86
86
  let childProcess;
@@ -114,13 +114,13 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
114
114
  },
115
115
  absolute: {
116
116
  current,
117
- percent: (0, math_util_1.progressPercent)(total, current),
117
+ percent: (0, math_1.progressPercent)(total, current),
118
118
  total,
119
119
  },
120
120
  });
121
121
  }
122
122
  };
123
- await (0, process_util_1.exec)(command, args, undefined, {
123
+ await (0, process_1.exec)(command, args, undefined, {
124
124
  log: this.verbose,
125
125
  onSpawn: (p) => {
126
126
  childProcess = p;
@@ -132,7 +132,7 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
132
132
  onData,
133
133
  },
134
134
  });
135
- await (0, process_util_1.exec)(command, [`--prepare`, `--target-dir=${targetPath}`], undefined, {
135
+ await (0, process_1.exec)(command, [`--prepare`, `--target-dir=${targetPath}`], undefined, {
136
136
  log: this.verbose,
137
137
  stderr: { onData: () => { } },
138
138
  });
@@ -141,13 +141,13 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
141
141
  this.verbose = data.options.verbose;
142
142
  const restorePath = data.package.restorePath;
143
143
  (0, assert_1.ok)(typeof restorePath === "string");
144
- await (0, fs_util_1.mkdirIfNotExists)(restorePath);
145
- const files = await (0, fs_util_1.readDir)(restorePath);
144
+ await (0, fs_1.mkdirIfNotExists)(restorePath);
145
+ const files = await (0, fs_1.readDir)(restorePath);
146
146
  for (const file of files) {
147
147
  if (file.startsWith("ib_logfile")) {
148
148
  const filePath = (0, path_1.join)(restorePath, file);
149
149
  if (this.verbose)
150
- (0, cli_util_1.logExec)("rm", [filePath]);
150
+ (0, cli_1.logExec)("rm", [filePath]);
151
151
  await (0, promises_1.rm)(filePath);
152
152
  }
153
153
  }
package/Task/MssqlTask.js CHANGED
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MssqlTask = exports.mssqlTaskDefinition = exports.mssqlTaskName = void 0;
4
4
  const AppError_1 = require("../Error/AppError");
5
5
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
6
- const config_util_1 = require("../util/datatruck/config-util");
7
- const fs_util_1 = require("../util/fs-util");
8
- const process_util_1 = require("../util/process-util");
6
+ const config_1 = require("../utils/datatruck/config");
7
+ const fs_1 = require("../utils/fs");
8
+ const process_1 = require("../utils/process");
9
9
  const TaskAbstract_1 = require("./TaskAbstract");
10
10
  const assert_1 = require("assert");
11
11
  const promises_1 = require("fs/promises");
@@ -29,7 +29,7 @@ class MssqlTask extends TaskAbstract_1.TaskAbstract {
29
29
  return this.config.command ?? "sqlcmd";
30
30
  }
31
31
  async exec(query) {
32
- const result = await (0, process_util_1.exec)(this.command, [
32
+ const result = await (0, process_1.exec)(this.command, [
33
33
  ...(this.config.hostname ? ["-S", this.config.hostname] : []),
34
34
  ...(this.config.username ? ["-U", this.config.username] : []),
35
35
  ...(this.config.passwordFile
@@ -73,7 +73,7 @@ class MssqlTask extends TaskAbstract_1.TaskAbstract {
73
73
  (0, micromatch_1.isMatch)(databaseName, this.config.includeDatabases)) &&
74
74
  (!this.config.excludeDatabases ||
75
75
  !(0, micromatch_1.isMatch)(databaseName, this.config.excludeDatabases)));
76
- await (0, fs_util_1.mkdirIfNotExists)(targetPath);
76
+ await (0, fs_1.mkdirIfNotExists)(targetPath);
77
77
  for (const databaseName of databaseNames) {
78
78
  const databasePath = (0, path_1.join)(targetPath, `${databaseName}${MssqlTask.SUFFIX}`);
79
79
  await this.exec(`BACKUP DATABASE [${databaseName}] TO DISK='${databasePath}' WITH FORMAT`);
@@ -83,14 +83,14 @@ class MssqlTask extends TaskAbstract_1.TaskAbstract {
83
83
  this.verbose = data.options.verbose;
84
84
  const restorePath = data.package.restorePath;
85
85
  (0, assert_1.ok)(typeof restorePath === "string");
86
- await (0, fs_util_1.mkdirIfNotExists)(restorePath);
87
- const files = await (0, fs_util_1.readDir)(restorePath);
86
+ await (0, fs_1.mkdirIfNotExists)(restorePath);
87
+ const files = await (0, fs_1.readDir)(restorePath);
88
88
  for (const file of files) {
89
89
  if (!file.endsWith(MssqlTask.SUFFIX))
90
90
  continue;
91
91
  let databaseName = file.slice(0, MssqlTask.SUFFIX.length * -1);
92
92
  if (this.config.targetDatabase)
93
- databaseName = (0, config_util_1.resolveDatabaseName)(this.config.targetDatabase, {
93
+ databaseName = (0, config_1.resolveDatabaseName)(this.config.targetDatabase, {
94
94
  action: "restore",
95
95
  database: databaseName,
96
96
  packageName: data.package.name,
@@ -7,7 +7,7 @@ export declare class MysqlDumpTask extends SqlDumpTaskAbstract<MysqlDumpTaskConf
7
7
  buildConnectionArgs(database?: boolean): Promise<string[]>;
8
8
  onDatabaseIsEmpty(name: string): Promise<boolean>;
9
9
  onCreateDatabase(database: TargetDatabaseType): Promise<void>;
10
- onExecQuery(query: string): Promise<import("../util/process-util").ExecResultType>;
10
+ onExecQuery(query: string): Promise<import("../utils/process").ExecResultType>;
11
11
  onFetchTableNames(database: string): Promise<string[]>;
12
12
  onExportTables(tableNames: string[], output: string, onProgress: (progress: {
13
13
  totalBytes: number;
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MysqlDumpTask = exports.mysqlDumpTaskDefinition = exports.mysqlDumpTaskName = void 0;
4
4
  const AppError_1 = require("../Error/AppError");
5
5
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
6
- const fs_util_1 = require("../util/fs-util");
7
- const process_util_1 = require("../util/process-util");
6
+ const fs_1 = require("../utils/fs");
7
+ const process_1 = require("../utils/process");
8
8
  const SqlDumpTaskAbstract_1 = require("./SqlDumpTaskAbstract");
9
- const fs_1 = require("fs");
10
9
  const fs_2 = require("fs");
10
+ const fs_3 = require("fs");
11
11
  exports.mysqlDumpTaskName = "mysql-dump";
12
12
  exports.mysqlDumpTaskDefinition = {
13
13
  allOf: [(0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.sqlDumpTask)],
@@ -43,7 +43,7 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
43
43
  await this.onExecQuery(query);
44
44
  }
45
45
  async onExecQuery(query) {
46
- return await (0, process_util_1.exec)("mysql", [
46
+ return await (0, process_1.exec)("mysql", [
47
47
  ...(await this.buildConnectionArgs()),
48
48
  "-e",
49
49
  query.replace(/\s{1,}/g, " "),
@@ -71,13 +71,13 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
71
71
  `);
72
72
  }
73
73
  async onExportTables(tableNames, output, onProgress) {
74
- const stream = (0, fs_1.createWriteStream)(output);
74
+ const stream = (0, fs_2.createWriteStream)(output);
75
75
  await Promise.all([
76
76
  new Promise((resolve, reject) => {
77
77
  stream.on("close", resolve);
78
78
  stream.on("error", reject);
79
79
  }),
80
- await (0, process_util_1.exec)("mysqldump", [
80
+ await (0, process_1.exec)("mysqldump", [
81
81
  ...(await this.buildConnectionArgs()),
82
82
  "--lock-tables=false",
83
83
  "--skip-add-drop-table=false",
@@ -97,8 +97,8 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
97
97
  },
98
98
  }),
99
99
  ]);
100
- const headerContents = await (0, fs_util_1.readPartialFile)(output, [0, 100]);
101
- const footerContents = await (0, fs_util_1.readPartialFile)(output, [-100]);
100
+ const headerContents = await (0, fs_1.readPartialFile)(output, [0, 100]);
101
+ const footerContents = await (0, fs_1.readPartialFile)(output, [-100]);
102
102
  const successHeader = headerContents.split(/\r?\n/).some((line) => {
103
103
  const firstLine = line.trim().toLowerCase();
104
104
  return (firstLine.startsWith("-- mysql dump") ||
@@ -113,13 +113,13 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
113
113
  throw new AppError_1.AppError("No end line found (incomplete backup)");
114
114
  }
115
115
  async onExportStoredPrograms(output) {
116
- const stream = (0, fs_1.createWriteStream)(output);
116
+ const stream = (0, fs_2.createWriteStream)(output);
117
117
  await Promise.all([
118
118
  new Promise((resolve, reject) => {
119
119
  stream.on("close", resolve);
120
120
  stream.on("error", reject);
121
121
  }),
122
- await (0, process_util_1.exec)("mysqldump", [
122
+ await (0, process_1.exec)("mysqldump", [
123
123
  ...(await this.buildConnectionArgs()),
124
124
  "--lock-tables=false",
125
125
  "--routines",
@@ -143,12 +143,12 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
143
143
  ]);
144
144
  }
145
145
  async onImport(path, database) {
146
- await (0, process_util_1.exec)("mysql", [...(await this.buildConnectionArgs(false)), database], null, {
146
+ await (0, process_1.exec)("mysql", [...(await this.buildConnectionArgs(false)), database], null, {
147
147
  pipe: {
148
- stream: (0, fs_2.createReadStream)(path),
148
+ stream: (0, fs_3.createReadStream)(path),
149
149
  onReadProgress: (data) => {
150
150
  if (this.verbose)
151
- (0, process_util_1.logExecStdout)({
151
+ (0, process_1.logExecStdout)({
152
152
  data: JSON.stringify(data),
153
153
  colorize: true,
154
154
  stderr: true,
@@ -7,7 +7,7 @@ export declare class PostgresqlDumpTask extends SqlDumpTaskAbstract<PostgresqlDu
7
7
  buildConnectionArgs(database?: string): Promise<string[]>;
8
8
  onDatabaseIsEmpty(name: string): Promise<boolean>;
9
9
  onCreateDatabase(database: TargetDatabaseType): Promise<void>;
10
- onExecQuery(query: string): Promise<import("../util/process-util").ExecResultType>;
10
+ onExecQuery(query: string): Promise<import("../utils/process").ExecResultType>;
11
11
  onFetchTableNames(database: string): Promise<string[]>;
12
12
  onExportTables(tableNames: string[], output: string, onProgress: (progress: {
13
13
  totalBytes: number;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostgresqlDumpTask = exports.postgresqlDumpTaskDefinition = exports.postgresqlDumpTaskName = void 0;
4
4
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
5
- const process_util_1 = require("../util/process-util");
5
+ const process_1 = require("../utils/process");
6
6
  const SqlDumpTaskAbstract_1 = require("./SqlDumpTaskAbstract");
7
7
  const fs_1 = require("fs");
8
8
  const path_1 = require("path");
@@ -45,7 +45,7 @@ class PostgresqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
45
45
  await this.onExecQuery(query);
46
46
  }
47
47
  async onExecQuery(query) {
48
- return await (0, process_util_1.exec)("psql", [
48
+ return await (0, process_1.exec)("psql", [
49
49
  ...(await this.buildConnectionArgs()),
50
50
  "-t",
51
51
  "-c",
@@ -80,7 +80,7 @@ class PostgresqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
80
80
  stream.on("close", resolve);
81
81
  stream.on("error", reject);
82
82
  }),
83
- (0, process_util_1.exec)("pg_dump", [
83
+ (0, process_1.exec)("pg_dump", [
84
84
  ...(await this.buildConnectionArgs()),
85
85
  ...(tableNames?.flatMap((v) => ["-t", v]) ?? []),
86
86
  ], null, {
@@ -96,7 +96,7 @@ class PostgresqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
96
96
  throw new Error(`Method not implemented: onExportStoredPrograms`);
97
97
  }
98
98
  async onImport(path, database) {
99
- await (0, process_util_1.exec)("psql", [...(await this.buildConnectionArgs(database)), "-f", (0, path_1.normalize)(path)], undefined, {
99
+ await (0, process_1.exec)("psql", [...(await this.buildConnectionArgs(database)), "-f", (0, path_1.normalize)(path)], undefined, {
100
100
  log: this.verbose,
101
101
  });
102
102
  }
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ScriptTask = exports.scriptTaskDefinition = exports.scriptTaskName = void 0;
4
4
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
5
- const fs_util_1 = require("../util/fs-util");
6
- const process_util_1 = require("../util/process-util");
7
- const string_util_1 = require("../util/string-util");
5
+ const fs_1 = require("../utils/fs");
6
+ const process_1 = require("../utils/process");
7
+ const string_1 = require("../utils/string");
8
8
  const TaskAbstract_1 = require("./TaskAbstract");
9
9
  const assert_1 = require("assert");
10
10
  const promises_1 = require("fs/promises");
@@ -110,7 +110,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
110
110
  const steps = Array.isArray(input) ? input : [input];
111
111
  for (const step of steps) {
112
112
  if (step.type === "process") {
113
- await (0, process_util_1.exec)(step.config.command, (step.config.args || []).map((v) => (0, string_util_1.render)(v, options.vars)), {
113
+ await (0, process_1.exec)(step.config.command, (step.config.args || []).map((v) => (0, string_1.render)(v, options.vars)), {
114
114
  env: {
115
115
  ...process.env,
116
116
  ...options.vars,
@@ -127,7 +127,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
127
127
  await (0, promises_1.writeFile)(scriptPath, Array.isArray(step.config.code)
128
128
  ? step.config.code.join("\n")
129
129
  : step.config.code);
130
- await (0, process_util_1.exec)("node", [scriptPath], {
130
+ await (0, process_1.exec)("node", [scriptPath], {
131
131
  env: {
132
132
  ...process.env,
133
133
  ...options.vars,
@@ -168,8 +168,8 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
168
168
  const targetPath = data.targetPath;
169
169
  (0, assert_1.ok)(typeof restorePath === "string");
170
170
  (0, assert_1.ok)(typeof targetPath === "string");
171
- await (0, fs_util_1.mkdirIfNotExists)(restorePath);
172
- await (0, fs_util_1.ensureEmptyDir)(restorePath);
171
+ await (0, fs_1.mkdirIfNotExists)(restorePath);
172
+ await (0, fs_1.ensureEmptyDir)(restorePath);
173
173
  await this.processSteps(config.restoreSteps, {
174
174
  env: config.env,
175
175
  vars: this.getVars(data),
@@ -1,4 +1,4 @@
1
- import { exec } from "../util/process-util";
1
+ import { exec } from "../utils/process";
2
2
  import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
3
3
  import { JSONSchema7 } from "json-schema";
4
4
  export type TargetDatabaseType = {