@datatruck/cli 0.32.3 → 0.34.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 (133) hide show
  1. package/config.schema.json +377 -31
  2. package/lib/{Action → actions}/BackupAction.d.ts +13 -19
  3. package/lib/{Action → actions}/BackupAction.js +52 -91
  4. package/lib/{Action → actions}/ConfigAction.d.ts +4 -2
  5. package/lib/{Action → actions}/ConfigAction.js +16 -8
  6. package/lib/{Action → actions}/CopyAction.d.ts +20 -13
  7. package/lib/actions/CopyAction.js +296 -0
  8. package/lib/{Action → actions}/InitAction.d.ts +1 -1
  9. package/lib/{Action → actions}/InitAction.js +3 -3
  10. package/lib/{Action → actions}/PruneAction.d.ts +1 -2
  11. package/lib/{Action → actions}/PruneAction.js +2 -2
  12. package/lib/{Action → actions}/RestoreAction.d.ts +4 -13
  13. package/lib/{Action → actions}/RestoreAction.js +17 -17
  14. package/lib/{Action → actions}/SnapshotsAction.d.ts +2 -3
  15. package/lib/{Action → actions}/SnapshotsAction.js +3 -3
  16. package/lib/cli.d.ts +3 -3
  17. package/lib/cli.js +18 -17
  18. package/lib/commands/BackupCommand.d.ts +45 -0
  19. package/lib/{Command → commands}/BackupCommand.js +7 -6
  20. package/lib/{Command → commands}/CleanCacheCommand.d.ts +4 -2
  21. package/lib/{Command → commands}/CleanCacheCommand.js +6 -5
  22. package/lib/{Command → commands}/CommandAbstract.d.ts +10 -6
  23. package/lib/{Command → commands}/CommandAbstract.js +5 -3
  24. package/lib/commands/ConfigCommand.d.ts +22 -0
  25. package/lib/{Command → commands}/ConfigCommand.js +5 -5
  26. package/lib/commands/CopyCommand.d.ts +17 -0
  27. package/lib/{Command → commands}/CopyCommand.js +7 -6
  28. package/lib/commands/InitCommand.d.ts +19 -0
  29. package/lib/{Command → commands}/InitCommand.js +9 -9
  30. package/lib/{Command → commands}/PruneCommand.d.ts +7 -4
  31. package/lib/{Command → commands}/PruneCommand.js +11 -11
  32. package/lib/commands/RestoreCommand.d.ts +38 -0
  33. package/lib/{Command → commands}/RestoreCommand.js +7 -6
  34. package/lib/{Command → commands}/SnapshotsCommand.d.ts +8 -6
  35. package/lib/{Command → commands}/SnapshotsCommand.js +12 -12
  36. package/lib/{Command → commands}/StartServerCommand.d.ts +4 -2
  37. package/lib/{Command → commands}/StartServerCommand.js +5 -5
  38. package/lib/index.d.ts +20 -23
  39. package/lib/index.js +8 -8
  40. package/lib/{Repository → repositories}/DatatruckRepository.d.ts +6 -2
  41. package/lib/{Repository → repositories}/DatatruckRepository.js +13 -5
  42. package/lib/{Repository → repositories}/GitRepository.d.ts +6 -2
  43. package/lib/{Repository → repositories}/GitRepository.js +8 -3
  44. package/lib/{Repository → repositories}/RepositoryAbstract.d.ts +13 -9
  45. package/lib/{Repository → repositories}/ResticRepository.d.ts +6 -2
  46. package/lib/{Repository → repositories}/ResticRepository.js +17 -10
  47. package/lib/{Task → tasks}/MssqlTask.js +2 -2
  48. package/lib/{Task → tasks}/MysqlDumpTask.js +4 -4
  49. package/lib/{Task → tasks}/ScriptTask.d.ts +2 -2
  50. package/lib/{Task → tasks}/SqlDumpTaskAbstract.js +4 -4
  51. package/lib/{Task → tasks}/TaskAbstract.d.ts +4 -4
  52. package/lib/utils/DataFormat.js +3 -3
  53. package/lib/utils/Restic.d.ts +2 -2
  54. package/lib/utils/Restic.js +12 -10
  55. package/lib/utils/cli.d.ts +9 -3
  56. package/lib/utils/cli.js +17 -1
  57. package/lib/utils/cron.d.ts +11 -0
  58. package/lib/utils/cron.js +27 -0
  59. package/lib/utils/datatruck/client.d.ts +3 -1
  60. package/lib/utils/datatruck/client.js +1 -1
  61. package/lib/utils/datatruck/command.d.ts +29 -0
  62. package/lib/utils/datatruck/command.js +61 -0
  63. package/lib/{Config/RepositoryConfig.d.ts → utils/datatruck/config-repository-type.d.ts} +19 -8
  64. package/lib/{Config/TaskConfig.d.ts → utils/datatruck/config-task-type.d.ts} +6 -6
  65. package/lib/utils/datatruck/config-type.d.ts +51 -0
  66. package/lib/utils/datatruck/config.d.ts +19 -10
  67. package/lib/utils/datatruck/config.js +43 -7
  68. package/lib/utils/datatruck/cron-server.d.ts +27 -6
  69. package/lib/utils/datatruck/cron-server.js +38 -20
  70. package/lib/utils/datatruck/paths.d.ts +2 -2
  71. package/lib/utils/datatruck/report-list.d.ts +14 -0
  72. package/lib/utils/datatruck/report-list.js +57 -0
  73. package/lib/utils/datatruck/repository-server.js +3 -2
  74. package/lib/utils/datatruck/repository.d.ts +16 -0
  75. package/lib/utils/datatruck/repository.js +30 -0
  76. package/lib/utils/datatruck/snapshot.d.ts +2 -2
  77. package/lib/utils/datatruck/task.d.ts +3 -0
  78. package/lib/{Factory/TaskFactory.js → utils/datatruck/task.js} +8 -8
  79. package/lib/utils/date.js +6 -2
  80. package/lib/utils/fs.d.ts +3 -0
  81. package/lib/utils/fs.js +24 -4
  82. package/lib/utils/http.d.ts +3 -1
  83. package/lib/utils/http.js +6 -1
  84. package/lib/utils/list.d.ts +5 -5
  85. package/lib/utils/mysql.js +5 -5
  86. package/lib/utils/object.d.ts +13 -0
  87. package/lib/utils/object.js +32 -1
  88. package/lib/utils/process.js +4 -1
  89. package/lib/utils/string.d.ts +1 -0
  90. package/lib/utils/string.js +7 -3
  91. package/lib/utils/ts.d.ts +16 -0
  92. package/lib/utils/virtual-fs.d.ts +6 -2
  93. package/lib/utils/virtual-fs.js +4 -1
  94. package/lib/utils/watcher.d.ts +10 -0
  95. package/lib/utils/watcher.js +34 -0
  96. package/package.json +4 -4
  97. package/lib/Action/CopyAction.js +0 -164
  98. package/lib/Command/BackupCommand.d.ts +0 -19
  99. package/lib/Command/ConfigCommand.d.ts +0 -15
  100. package/lib/Command/CopyCommand.d.ts +0 -16
  101. package/lib/Command/InitCommand.d.ts +0 -13
  102. package/lib/Command/RestoreCommand.d.ts +0 -17
  103. package/lib/Config/Config.d.ts +0 -28
  104. package/lib/Config/PackageConfig.d.ts +0 -24
  105. package/lib/Config/PackageRepositoryConfig.d.ts +0 -15
  106. package/lib/Config/PrunePolicyConfig.d.ts +0 -2
  107. package/lib/Config/RepositoryConfig.js +0 -2
  108. package/lib/Config/TaskConfig.js +0 -2
  109. package/lib/Factory/CommandFactory.d.ts +0 -45
  110. package/lib/Factory/CommandFactory.js +0 -96
  111. package/lib/Factory/RepositoryFactory.d.ts +0 -3
  112. package/lib/Factory/RepositoryFactory.js +0 -23
  113. package/lib/Factory/TaskFactory.d.ts +0 -3
  114. /package/lib/{Action → actions}/CleanCacheAction.d.ts +0 -0
  115. /package/lib/{Action → actions}/CleanCacheAction.js +0 -0
  116. /package/lib/{Repository → repositories}/RepositoryAbstract.js +0 -0
  117. /package/lib/{Task → tasks}/GitTask.d.ts +0 -0
  118. /package/lib/{Task → tasks}/GitTask.js +0 -0
  119. /package/lib/{Task → tasks}/MariadbTask.d.ts +0 -0
  120. /package/lib/{Task → tasks}/MariadbTask.js +0 -0
  121. /package/lib/{Task → tasks}/MssqlTask.d.ts +0 -0
  122. /package/lib/{Task → tasks}/MysqlDumpTask.d.ts +0 -0
  123. /package/lib/{Task → tasks}/PostgresqlDumpTask.d.ts +0 -0
  124. /package/lib/{Task → tasks}/PostgresqlDumpTask.js +0 -0
  125. /package/lib/{Task → tasks}/ScriptTask.js +0 -0
  126. /package/lib/{Task → tasks}/SqlDumpTaskAbstract.d.ts +0 -0
  127. /package/lib/{Task → tasks}/TaskAbstract.js +0 -0
  128. /package/lib/{Config/Config.js → utils/datatruck/config-repository-type.js} +0 -0
  129. /package/lib/{Config/PackageConfig.js → utils/datatruck/config-task-type.js} +0 -0
  130. /package/lib/{Config/PackageRepositoryConfig.js → utils/datatruck/config-type.js} +0 -0
  131. /package/lib/{Error/AppError.d.ts → utils/datatruck/error.d.ts} +0 -0
  132. /package/lib/{Error/AppError.js → utils/datatruck/error.js} +0 -0
  133. /package/lib/{Config/PrunePolicyConfig.js → utils/ts.js} +0 -0
@@ -1,6 +1,8 @@
1
1
  import { CommandAbstract } from "./CommandAbstract";
2
2
  export type CleanCacheCommandOptions<TResolved = false> = {};
3
3
  export declare class CleanCacheCommand extends CommandAbstract<CleanCacheCommandOptions<false>, CleanCacheCommandOptions<true>> {
4
- onOptions(): import("../utils/cli").OptionsType<CleanCacheCommandOptions<false>, CleanCacheCommandOptions<true>>;
5
- onExec(): Promise<1 | 0>;
4
+ optionsConfig(): import("../utils/cli").OptionsConfig<CleanCacheCommandOptions<false>, CleanCacheCommandOptions<true>>;
5
+ exec(): Promise<{
6
+ exitCode: number;
7
+ }>;
6
8
  }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CleanCacheCommand = void 0;
4
- const CleanCacheAction_1 = require("../Action/CleanCacheAction");
4
+ const CleanCacheAction_1 = require("../actions/CleanCacheAction");
5
5
  const DataFormat_1 = require("../utils/DataFormat");
6
6
  const bytes_1 = require("../utils/bytes");
7
7
  const CommandAbstract_1 = require("./CommandAbstract");
8
8
  class CleanCacheCommand extends CommandAbstract_1.CommandAbstract {
9
- onOptions() {
10
- return this.returnsOptions({});
9
+ optionsConfig() {
10
+ return this.castOptionsConfig({});
11
11
  }
12
- async onExec() {
12
+ async exec() {
13
13
  const cleanCache = new CleanCacheAction_1.CleanCacheAction({
14
14
  verbose: !!this.globalOptions.verbose,
15
15
  });
@@ -32,7 +32,8 @@ class CleanCacheCommand extends CommandAbstract_1.CommandAbstract {
32
32
  await cleanCache.exec();
33
33
  if (this.globalOptions.outputFormat)
34
34
  dataFormat.log(this.globalOptions.outputFormat);
35
- return result.errors.length ? 1 : 0;
35
+ const exitCode = result.errors.length ? 1 : 0;
36
+ return { exitCode };
36
37
  }
37
38
  }
38
39
  exports.CleanCacheCommand = CleanCacheCommand;
@@ -1,6 +1,6 @@
1
- import { Config } from "../Config/Config";
2
1
  import { DataFormatType } from "../utils/DataFormat";
3
- import { OptionsType } from "../utils/cli";
2
+ import { OptionsConfig } from "../utils/cli";
3
+ import type { Config } from "../utils/datatruck/config-type";
4
4
  import { ProgressMode } from "../utils/progress";
5
5
  import { Streams } from "../utils/stream";
6
6
  import { If, SimilarObject } from "../utils/ts";
@@ -16,11 +16,15 @@ export type CommandConstructor<TUnresolvedOptions, TOptions extends SimilarObjec
16
16
  };
17
17
  export declare abstract class CommandAbstract<TUnresolvedOptions, TOptions extends SimilarObject<TUnresolvedOptions>> {
18
18
  readonly globalOptions: GlobalOptions<true>;
19
+ readonly inputOptions: TUnresolvedOptions;
19
20
  readonly configPath?: string | undefined;
20
21
  readonly options: TOptions;
21
22
  readonly streams: Streams;
22
- constructor(globalOptions: GlobalOptions<true>, options: TUnresolvedOptions, streams?: Partial<Streams>, configPath?: string | undefined);
23
- abstract onOptions(): OptionsType<TUnresolvedOptions, TOptions>;
24
- protected returnsOptions(options: OptionsType<TUnresolvedOptions, TOptions>): OptionsType<TUnresolvedOptions, TOptions>;
25
- abstract onExec(): Promise<number>;
23
+ constructor(globalOptions: GlobalOptions<true>, inputOptions: TUnresolvedOptions, streams?: Partial<Streams>, configPath?: string | undefined);
24
+ abstract optionsConfig(): OptionsConfig<TUnresolvedOptions, TOptions>;
25
+ protected castOptionsConfig(options: OptionsConfig<TUnresolvedOptions, TOptions>): OptionsConfig<TUnresolvedOptions, TOptions>;
26
+ abstract exec(): Promise<{
27
+ exitCode: number;
28
+ result?: any;
29
+ }>;
26
30
  }
@@ -5,16 +5,18 @@ const cli_1 = require("../utils/cli");
5
5
  const stream_1 = require("../utils/stream");
6
6
  class CommandAbstract {
7
7
  globalOptions;
8
+ inputOptions;
8
9
  configPath;
9
10
  options;
10
11
  streams;
11
- constructor(globalOptions, options, streams = {}, configPath) {
12
+ constructor(globalOptions, inputOptions, streams = {}, configPath) {
12
13
  this.globalOptions = globalOptions;
14
+ this.inputOptions = inputOptions;
13
15
  this.configPath = configPath;
14
- this.options = (0, cli_1.parseOptions)(options, this.onOptions());
16
+ this.options = (0, cli_1.parseOptions)(inputOptions, this.optionsConfig());
15
17
  this.streams = (0, stream_1.createStreams)(streams);
16
18
  }
17
- returnsOptions(options) {
19
+ castOptionsConfig(options) {
18
20
  return options;
19
21
  }
20
22
  }
@@ -0,0 +1,22 @@
1
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
2
+ import { If } from "../utils/ts";
3
+ import { CommandAbstract } from "./CommandAbstract";
4
+ export type ConfigCommandOptions<TResolved = false> = {
5
+ package?: If<TResolved, string[]>;
6
+ packageTask?: If<TResolved, string[]>;
7
+ repository?: If<TResolved, string[]>;
8
+ repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
9
+ };
10
+ export declare class ConfigCommand extends CommandAbstract<ConfigCommandOptions<false>, ConfigCommandOptions<true>> {
11
+ optionsConfig(): import("../utils/cli").OptionsConfig<ConfigCommandOptions<false>, ConfigCommandOptions<true>>;
12
+ exec(): Promise<{
13
+ result: {
14
+ path: string;
15
+ data: import("../utils/datatruck/config-type").Config;
16
+ } | {
17
+ path: null;
18
+ data: import("../utils/datatruck/config-type").Config;
19
+ };
20
+ exitCode: number;
21
+ }>;
22
+ }
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
5
  const DataFormat_1 = require("../utils/DataFormat");
6
6
  const config_1 = require("../utils/datatruck/config");
7
7
  const string_1 = require("../utils/string");
8
8
  const CommandAbstract_1 = require("./CommandAbstract");
9
9
  class ConfigCommand extends CommandAbstract_1.CommandAbstract {
10
- onOptions() {
11
- return this.returnsOptions({
10
+ optionsConfig() {
11
+ return this.castOptionsConfig({
12
12
  package: {
13
13
  description: "Filter by package names",
14
14
  option: "-p,--package <values>",
@@ -31,7 +31,7 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
31
31
  },
32
32
  });
33
33
  }
34
- async onExec() {
34
+ async exec() {
35
35
  const result = await ConfigAction_1.ConfigAction.fromGlobalOptionsWithPath(this.globalOptions);
36
36
  const packages = (0, config_1.filterPackages)(result.data, {
37
37
  packageNames: this.options.package,
@@ -66,7 +66,7 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
66
66
  pkgNames: () => summaryConfig.map((i) => i.packageName).join(),
67
67
  },
68
68
  });
69
- return 0;
69
+ return { result, exitCode: 0 };
70
70
  }
71
71
  }
72
72
  exports.ConfigCommand = ConfigCommand;
@@ -0,0 +1,17 @@
1
+ import { If } from "../utils/ts";
2
+ import { CommandAbstract } from "./CommandAbstract";
3
+ export type CopyCommandOptions<TResolved = false> = {
4
+ id?: If<TResolved, string[]>;
5
+ last?: number;
6
+ package?: If<TResolved, string[]>;
7
+ packageTask?: If<TResolved, string[]>;
8
+ repository: string;
9
+ repository2?: If<TResolved, string[]>;
10
+ };
11
+ export declare class CopyCommand extends CommandAbstract<CopyCommandOptions<false>, CopyCommandOptions<true>> {
12
+ optionsConfig(): import("../utils/cli").OptionsConfig<CopyCommandOptions<false>, CopyCommandOptions<true>>;
13
+ exec(): Promise<{
14
+ result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<import("../actions/CopyAction").Context>)[];
15
+ exitCode: number;
16
+ }>;
17
+ }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CopyCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
5
- const CopyAction_1 = require("../Action/CopyAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
+ const CopyAction_1 = require("../actions/CopyAction");
6
6
  const string_1 = require("../utils/string");
7
7
  const CommandAbstract_1 = require("./CommandAbstract");
8
8
  class CopyCommand extends CommandAbstract_1.CommandAbstract {
9
- onOptions() {
10
- return this.returnsOptions({
9
+ optionsConfig() {
10
+ return this.castOptionsConfig({
11
11
  id: {
12
12
  option: "-i,--id <ids>",
13
13
  description: "Filter by identifiers",
@@ -40,7 +40,7 @@ class CopyCommand extends CommandAbstract_1.CommandAbstract {
40
40
  },
41
41
  });
42
42
  }
43
- async onExec() {
43
+ async exec() {
44
44
  const verbose = this.globalOptions.verbose ?? 0;
45
45
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
46
46
  const copy = new CopyAction_1.CopyAction(config, {
@@ -59,7 +59,8 @@ class CopyCommand extends CommandAbstract_1.CommandAbstract {
59
59
  copy
60
60
  .dataFormat(result, { streams: this.streams, verbose })
61
61
  .log(this.globalOptions.outputFormat);
62
- return result.some((item) => item.error) ? 1 : 0;
62
+ const exitCode = result.some((item) => item.error) ? 1 : 0;
63
+ return { result, exitCode };
63
64
  }
64
65
  }
65
66
  exports.CopyCommand = CopyCommand;
@@ -0,0 +1,19 @@
1
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
2
+ import { If } from "../utils/ts";
3
+ import { CommandAbstract } from "./CommandAbstract";
4
+ export type InitCommandOptions<TResolved = false> = {
5
+ repository?: If<TResolved, string[]>;
6
+ repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
7
+ };
8
+ export declare class InitCommand extends CommandAbstract<InitCommandOptions<false>, InitCommandOptions<true>> {
9
+ optionsConfig(): import("../utils/cli").OptionsConfig<InitCommandOptions<false>, InitCommandOptions<true>>;
10
+ exec(): Promise<{
11
+ result: {
12
+ repositoryName: string;
13
+ repositoryType: string;
14
+ repositorySource: string;
15
+ error: Error | null;
16
+ }[];
17
+ exitCode: number;
18
+ }>;
19
+ }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InitCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
5
- const InitAction_1 = require("../Action/InitAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
+ const InitAction_1 = require("../actions/InitAction");
6
6
  const DataFormat_1 = require("../utils/DataFormat");
7
7
  const cli_1 = require("../utils/cli");
8
8
  const string_1 = require("../utils/string");
9
9
  const CommandAbstract_1 = require("./CommandAbstract");
10
10
  class InitCommand extends CommandAbstract_1.CommandAbstract {
11
- onOptions() {
12
- return this.returnsOptions({
11
+ optionsConfig() {
12
+ return this.castOptionsConfig({
13
13
  repository: {
14
14
  description: "Filter by repository names",
15
15
  option: "-r,--repository <values>",
@@ -22,7 +22,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
22
22
  },
23
23
  });
24
24
  }
25
- async onExec() {
25
+ async exec() {
26
26
  const verbose = this.globalOptions.verbose ?? 0;
27
27
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
28
28
  const init = new InitAction_1.InitAction(config, {
@@ -30,10 +30,10 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
30
30
  repositoryTypes: this.options.repositoryType,
31
31
  verbose: verbose > 0,
32
32
  });
33
- const response = await init.exec();
33
+ const result = await init.exec();
34
34
  const dataFormat = new DataFormat_1.DataFormat({
35
35
  streams: this.streams,
36
- json: response,
36
+ json: result,
37
37
  table: {
38
38
  headers: [
39
39
  { value: "", width: 3 },
@@ -42,7 +42,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
42
42
  { value: "Repository source" },
43
43
  { value: "Error", width: 50 },
44
44
  ],
45
- rows: () => response.map((item) => [
45
+ rows: () => result.map((item) => [
46
46
  (0, cli_1.renderResult)(item.error),
47
47
  item.repositoryName,
48
48
  item.repositoryType,
@@ -53,7 +53,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
53
53
  });
54
54
  if (this.globalOptions.outputFormat)
55
55
  dataFormat.log(this.globalOptions.outputFormat);
56
- return 0;
56
+ return { result, exitCode: 0 };
57
57
  }
58
58
  }
59
59
  exports.InitCommand = InitCommand;
@@ -1,5 +1,5 @@
1
- import { SnapshotGroupByType } from "../Action/SnapshotsAction";
2
- import { RepositoryConfig } from "../Config/RepositoryConfig";
1
+ import { SnapshotGroupByType } from "../actions/SnapshotsAction";
2
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
3
3
  import { KeepObject } from "../utils/date";
4
4
  import { If } from "../utils/ts";
5
5
  import { CommandAbstract } from "./CommandAbstract";
@@ -16,6 +16,9 @@ export type PruneCommandOptions<TResolved = false> = KeepObject & {
16
16
  confirm?: boolean;
17
17
  };
18
18
  export declare class PruneCommand extends CommandAbstract<PruneCommandOptions<false>, PruneCommandOptions<true>> {
19
- onOptions(): import("../utils/cli").OptionsType<PruneCommandOptions<false>, PruneCommandOptions<true>>;
20
- onExec(): Promise<number>;
19
+ optionsConfig(): import("../utils/cli").OptionsConfig<PruneCommandOptions<false>, PruneCommandOptions<true>>;
20
+ exec(): Promise<{
21
+ result: import("../actions/PruneAction").PruneResult;
22
+ exitCode: number;
23
+ }>;
21
24
  }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PruneCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
5
- const PruneAction_1 = require("../Action/PruneAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
+ const PruneAction_1 = require("../actions/PruneAction");
6
6
  const DataFormat_1 = require("../utils/DataFormat");
7
7
  const cli_1 = require("../utils/cli");
8
8
  const string_1 = require("../utils/string");
9
9
  const CommandAbstract_1 = require("./CommandAbstract");
10
10
  class PruneCommand extends CommandAbstract_1.CommandAbstract {
11
- onOptions() {
12
- return this.returnsOptions({
11
+ optionsConfig() {
12
+ return this.castOptionsConfig({
13
13
  dryRun: {
14
14
  description: "",
15
15
  option: "--dry-run",
@@ -99,7 +99,7 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
99
99
  },
100
100
  });
101
101
  }
102
- async onExec() {
102
+ async exec() {
103
103
  const verbose = this.globalOptions.verbose ?? 0;
104
104
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
105
105
  const prune = new PruneAction_1.PruneAction(config, {
@@ -121,10 +121,10 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
121
121
  longId: this.options.longId,
122
122
  returnsAll: this.options.showAll,
123
123
  });
124
- const pruneResult = await prune.exec();
124
+ const result = await prune.exec();
125
125
  const dataFormat = new DataFormat_1.DataFormat({
126
126
  streams: this.streams,
127
- json: pruneResult,
127
+ json: result,
128
128
  table: {
129
129
  headers: [
130
130
  { value: "Id.", width: (this.options.longId ? 32 : 8) + 2 },
@@ -134,7 +134,7 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
134
134
  { value: "Repository type" },
135
135
  { value: "Exclusion reasons" },
136
136
  ],
137
- rows: () => pruneResult.snapshots.map((item) => [
137
+ rows: () => result.snapshots.map((item) => [
138
138
  this.options.longId ? item.id : item.id.slice(0, 8),
139
139
  item.date.replace("T", " ").replace("Z", ""),
140
140
  item.packageName,
@@ -147,11 +147,11 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
147
147
  if (this.globalOptions.outputFormat)
148
148
  dataFormat.log(this.globalOptions.outputFormat);
149
149
  if (!this.options.confirm && !this.options.dryRun) {
150
- const answer = await (0, cli_1.confirm)(`Delete ${pruneResult.prune}/${pruneResult.total} snapshots?`);
150
+ const answer = await (0, cli_1.confirm)(`Delete ${result.prune}/${result.total} snapshots?`);
151
151
  if (answer)
152
- await prune.confirm(pruneResult.snapshots);
152
+ await prune.confirm(result.snapshots);
153
153
  }
154
- return 0;
154
+ return { result, exitCode: 0 };
155
155
  }
156
156
  }
157
157
  exports.PruneCommand = PruneCommand;
@@ -0,0 +1,38 @@
1
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
2
+ import { If } from "../utils/ts";
3
+ import { CommandAbstract } from "./CommandAbstract";
4
+ export type RestoreCommandOptions<TResolved = false> = {
5
+ id: string;
6
+ package?: If<TResolved, string[]>;
7
+ packageTask?: If<TResolved, string[]>;
8
+ packageConfig?: boolean;
9
+ repository?: If<TResolved, string[]>;
10
+ repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
11
+ tag?: If<TResolved, string[]>;
12
+ initial?: boolean;
13
+ };
14
+ export declare class RestoreCommand extends CommandAbstract<RestoreCommandOptions<false>, RestoreCommandOptions<true>> {
15
+ optionsConfig(): import("../utils/cli").OptionsConfig<RestoreCommandOptions<false>, RestoreCommandOptions<true>>;
16
+ exec(): Promise<{
17
+ result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<{
18
+ snapshots: {
19
+ id: string;
20
+ packages: number;
21
+ };
22
+ task: {
23
+ taskName: string;
24
+ packageName: string;
25
+ };
26
+ restore: import("../repositories/RepositoryAbstract").PreSnapshot & {
27
+ originalId: string;
28
+ packageName: string;
29
+ packageTaskName: string | undefined;
30
+ tags: string[];
31
+ size: number;
32
+ } & {
33
+ repositoryName: string;
34
+ };
35
+ }>)[];
36
+ exitCode: number;
37
+ }>;
38
+ }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RestoreCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
5
- const RestoreAction_1 = require("../Action/RestoreAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
+ const RestoreAction_1 = require("../actions/RestoreAction");
6
6
  const string_1 = require("../utils/string");
7
7
  const CommandAbstract_1 = require("./CommandAbstract");
8
8
  class RestoreCommand extends CommandAbstract_1.CommandAbstract {
9
- onOptions() {
10
- return this.returnsOptions({
9
+ optionsConfig() {
10
+ return this.castOptionsConfig({
11
11
  id: {
12
12
  description: "Filter by snapshot id",
13
13
  option: "-i,--id <id>",
@@ -48,7 +48,7 @@ class RestoreCommand extends CommandAbstract_1.CommandAbstract {
48
48
  },
49
49
  });
50
50
  }
51
- async onExec() {
51
+ async exec() {
52
52
  const verbose = this.globalOptions.verbose ?? 0;
53
53
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
54
54
  const restore = new RestoreAction_1.RestoreAction(config, {
@@ -70,7 +70,8 @@ class RestoreCommand extends CommandAbstract_1.CommandAbstract {
70
70
  restore
71
71
  .dataFormat(result, { streams: this.streams, verbose })
72
72
  .log(this.globalOptions.outputFormat);
73
- return result.some((item) => item.error) ? 1 : 0;
73
+ const exitCode = result.some((item) => item.error) ? 1 : 0;
74
+ return { result, exitCode };
74
75
  }
75
76
  }
76
77
  exports.RestoreCommand = RestoreCommand;
@@ -1,6 +1,6 @@
1
- import { SnapshotsAction } from "../Action/SnapshotsAction";
2
- import { RepositoryConfig } from "../Config/RepositoryConfig";
3
- import { If, Unwrap } from "../utils/ts";
1
+ import { SnapshotsAction } from "../actions/SnapshotsAction";
2
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
3
+ import { If } from "../utils/ts";
4
4
  import { CommandAbstract } from "./CommandAbstract";
5
5
  export type SnapshotsCommandOptions<TResolved = false> = {
6
6
  id?: If<TResolved, string[]>;
@@ -20,8 +20,10 @@ export type SnapshotsCommandOptions<TResolved = false> = {
20
20
  groupBy?: If<TResolved, SnapshotsAction["options"]["groupBy"]>;
21
21
  tag?: If<TResolved, string[]>;
22
22
  };
23
- export type SnapshotsCommandResult = Unwrap<SnapshotsAction["exec"]>;
24
23
  export declare class SnapshotsCommand extends CommandAbstract<SnapshotsCommandOptions<false>, SnapshotsCommandOptions<true>> {
25
- onOptions(): import("../utils/cli").OptionsType<SnapshotsCommandOptions<false>, SnapshotsCommandOptions<true>>;
26
- onExec(): Promise<number>;
24
+ optionsConfig(): import("../utils/cli").OptionsConfig<SnapshotsCommandOptions<false>, SnapshotsCommandOptions<true>>;
25
+ exec(): Promise<{
26
+ result: import("../actions/SnapshotsAction").ExtendedSnapshot[];
27
+ exitCode: number;
28
+ }>;
27
29
  }
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SnapshotsCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
5
- const SnapshotsAction_1 = require("../Action/SnapshotsAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
+ const SnapshotsAction_1 = require("../actions/SnapshotsAction");
6
6
  const DataFormat_1 = require("../utils/DataFormat");
7
7
  const bytes_1 = require("../utils/bytes");
8
8
  const string_1 = require("../utils/string");
9
9
  const CommandAbstract_1 = require("./CommandAbstract");
10
10
  class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
11
- onOptions() {
11
+ optionsConfig() {
12
12
  const groupByValues = [
13
13
  "id",
14
14
  "packageName",
15
15
  "repositoryName",
16
16
  "repositoryType",
17
17
  ];
18
- return this.returnsOptions({
18
+ return this.castOptionsConfig({
19
19
  groupBy: {
20
20
  option: "-g,--group-by <values>",
21
21
  description: `Group by values (${groupByValues.join(", ")})`,
@@ -96,7 +96,7 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
96
96
  },
97
97
  });
98
98
  }
99
- async onExec() {
99
+ async exec() {
100
100
  const verbose = this.globalOptions.verbose ?? 0;
101
101
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
102
102
  const snapshots = new SnapshotsAction_1.SnapshotsAction(config, {
@@ -117,10 +117,10 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
117
117
  verbose: verbose > 0,
118
118
  tags: this.options.tag,
119
119
  });
120
- const items = await snapshots.exec();
120
+ const result = await snapshots.exec();
121
121
  const dataFormat = new DataFormat_1.DataFormat({
122
122
  streams: this.streams,
123
- json: items,
123
+ json: result,
124
124
  table: {
125
125
  headers: [
126
126
  { value: "Id.", width: (this.options.longId ? 32 : 8) + 2 },
@@ -131,7 +131,7 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
131
131
  { value: "Repository" },
132
132
  { value: "Repository type" },
133
133
  ],
134
- rows: () => items.map((item) => [
134
+ rows: () => result.map((item) => [
135
135
  this.options.longId ? item.id : item.id.slice(0, 8),
136
136
  item.date.replace("T", " ").replace("Z", ""),
137
137
  item.packageName,
@@ -145,12 +145,12 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
145
145
  if (this.globalOptions.outputFormat)
146
146
  dataFormat.log(this.globalOptions.outputFormat, {
147
147
  tpl: {
148
- sids: () => items.map((i) => i.id).join(),
149
- ssids: () => items.map((i) => i.shortId).join(),
150
- pkgNames: () => items.map((i) => i.packageName).join(),
148
+ sids: () => result.map((i) => i.id).join(),
149
+ ssids: () => result.map((i) => i.shortId).join(),
150
+ pkgNames: () => result.map((i) => i.packageName).join(),
151
151
  },
152
152
  });
153
- return 0;
153
+ return { result, exitCode: 0 };
154
154
  }
155
155
  }
156
156
  exports.SnapshotsCommand = SnapshotsCommand;
@@ -1,6 +1,8 @@
1
1
  import { CommandAbstract } from "./CommandAbstract";
2
2
  export type StartServerCommandOptions<TResolved = false> = {};
3
3
  export declare class StartServerCommand extends CommandAbstract<StartServerCommandOptions<false>, StartServerCommandOptions<true>> {
4
- onOptions(): import("../utils/cli").OptionsType<StartServerCommandOptions<false>, StartServerCommandOptions<true>>;
5
- onExec(): Promise<number>;
4
+ optionsConfig(): import("../utils/cli").OptionsConfig<StartServerCommandOptions<false>, StartServerCommandOptions<true>>;
5
+ exec(): Promise<{
6
+ exitCode: number;
7
+ }>;
6
8
  }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StartServerCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
5
  const cron_server_1 = require("../utils/datatruck/cron-server");
6
6
  const repository_server_1 = require("../utils/datatruck/repository-server");
7
7
  const CommandAbstract_1 = require("./CommandAbstract");
8
8
  class StartServerCommand extends CommandAbstract_1.CommandAbstract {
9
- onOptions() {
10
- return this.returnsOptions({});
9
+ optionsConfig() {
10
+ return this.castOptionsConfig({});
11
11
  }
12
- async onExec() {
12
+ async exec() {
13
13
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
14
14
  const verbose = !!this.globalOptions.verbose;
15
15
  const log = config.server?.log ?? true;
@@ -43,7 +43,7 @@ class StartServerCommand extends CommandAbstract_1.CommandAbstract {
43
43
  process.on("SIGINT", () => process.exit(1));
44
44
  process.on("SIGTERM", () => process.exit(1));
45
45
  await new Promise(() => setInterval(() => { }, 60000));
46
- return 0;
46
+ return { exitCode: 0 };
47
47
  }
48
48
  }
49
49
  exports.StartServerCommand = StartServerCommand;
package/lib/index.d.ts CHANGED
@@ -1,24 +1,21 @@
1
- export type { Config } from "./Config/Config";
2
- export type { PackageConfig } from "./Config/PackageConfig";
3
- export type { PackageRepositoryConfig } from "./Config/PackageRepositoryConfig";
4
- export type { PrunePolicyConfig } from "./Config/PrunePolicyConfig";
5
- export type { RepositoryConfig } from "./Config/RepositoryConfig";
6
- export { type ResticRepositoryConfig } from "./Repository/ResticRepository";
7
- export { type DatatruckRepositoryConfig } from "./Repository/DatatruckRepository";
8
- export { type GitRepositoryConfig } from "./Repository/GitRepository";
9
- export type { TaskConfig } from "./Config/TaskConfig";
10
- export { type GitTaskConfig } from "./Task/GitTask";
11
- export { type MariadbTaskConfig } from "./Task/MariadbTask";
12
- export { type MssqlTaskConfig } from "./Task/MssqlTask";
13
- export { type MysqlDumpTaskConfig } from "./Task/MysqlDumpTask";
14
- export { type PostgresqlDumpTaskConfig } from "./Task/PostgresqlDumpTask";
15
- export { type ScriptTaskConfig } from "./Task/ScriptTask";
16
- export { BackupAction, type BackupActionOptions } from "./Action/BackupAction";
17
- export { CleanCacheAction, type CleanCacheActionOptions, } from "./Action/CleanCacheAction";
18
- export { ConfigAction, type ConfigActionOptions } from "./Action/ConfigAction";
19
- export { CopyAction, type CopyActionOptions } from "./Action/CopyAction";
20
- export { InitAction, type InitActionOptions } from "./Action/InitAction";
21
- export { PruneAction, type PruneActionsOptions } from "./Action/PruneAction";
22
- export { RestoreAction, type RestoreActionOptions, } from "./Action/RestoreAction";
23
- export { SnapshotsAction, type SnapshotsActionOptions, } from "./Action/SnapshotsAction";
1
+ export type { Config, PackageConfig, PackageConfigMeta, DatatruckPolicyConfig, DatatruckReportConfig, DatatruckServerOptions, } from "./utils/datatruck/config-type";
2
+ export type { PackageRepositoryConfig, RepositoryConfig, } from "./utils/datatruck/config-repository-type";
3
+ export type { TaskConfig } from "./utils/datatruck/config-task-type";
4
+ export { type ResticRepositoryConfig } from "./repositories/ResticRepository";
5
+ export { type DatatruckRepositoryConfig } from "./repositories/DatatruckRepository";
6
+ export { type GitRepositoryConfig } from "./repositories/GitRepository";
7
+ export { type GitTaskConfig } from "./tasks/GitTask";
8
+ export { type MariadbTaskConfig } from "./tasks/MariadbTask";
9
+ export { type MssqlTaskConfig } from "./tasks/MssqlTask";
10
+ export { type MysqlDumpTaskConfig } from "./tasks/MysqlDumpTask";
11
+ export { type PostgresqlDumpTaskConfig } from "./tasks/PostgresqlDumpTask";
12
+ export { type ScriptTaskConfig } from "./tasks/ScriptTask";
13
+ export { BackupAction, type BackupActionOptions } from "./actions/BackupAction";
14
+ export { CleanCacheAction, type CleanCacheActionOptions, } from "./actions/CleanCacheAction";
15
+ export { ConfigAction, type ConfigActionOptions } from "./actions/ConfigAction";
16
+ export { CopyAction, type CopyActionOptions } from "./actions/CopyAction";
17
+ export { InitAction, type InitActionOptions } from "./actions/InitAction";
18
+ export { PruneAction, type PruneActionsOptions } from "./actions/PruneAction";
19
+ export { RestoreAction, type RestoreActionOptions, } from "./actions/RestoreAction";
20
+ export { SnapshotsAction, type SnapshotsActionOptions, } from "./actions/SnapshotsAction";
24
21
  export { parseArgs } from "./cli";