@datatruck/cli 0.37.0 → 0.38.1

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 (70) hide show
  1. package/config.schema.json +130 -74
  2. package/lib/actions/BackupAction.d.ts +55 -19
  3. package/lib/actions/BackupAction.js +31 -7
  4. package/lib/actions/CleanCacheAction.d.ts +6 -7
  5. package/lib/actions/CleanCacheAction.js +2 -1
  6. package/lib/actions/ConfigAction.d.ts +3 -5
  7. package/lib/actions/ConfigAction.js +0 -1
  8. package/lib/actions/CopyAction.d.ts +37 -11
  9. package/lib/actions/CopyAction.js +29 -2
  10. package/lib/actions/ExportAction.d.ts +94 -0
  11. package/lib/actions/ExportAction.js +236 -0
  12. package/lib/actions/InitAction.d.ts +17 -7
  13. package/lib/actions/InitAction.js +9 -1
  14. package/lib/actions/PruneAction.d.ts +76 -17
  15. package/lib/actions/PruneAction.js +62 -2
  16. package/lib/actions/RestoreAction.d.ts +55 -21
  17. package/lib/actions/RestoreAction.js +44 -56
  18. package/lib/actions/SnapshotsAction.d.ts +80 -21
  19. package/lib/actions/SnapshotsAction.js +82 -1
  20. package/lib/cli.d.ts +0 -3
  21. package/lib/cli.js +14 -93
  22. package/lib/commands/BackupCommand.d.ts +120 -13
  23. package/lib/commands/BackupCommand.js +22 -50
  24. package/lib/commands/CleanCacheCommand.d.ts +10 -3
  25. package/lib/commands/CleanCacheCommand.js +14 -6
  26. package/lib/commands/CommandAbstract.d.ts +10 -10
  27. package/lib/commands/CommandAbstract.js +6 -9
  28. package/lib/commands/ConfigCommand.d.ts +72 -9
  29. package/lib/commands/ConfigCommand.js +36 -28
  30. package/lib/commands/CopyCommand.d.ts +102 -10
  31. package/lib/commands/CopyCommand.js +18 -40
  32. package/lib/commands/ExportCommand.d.ts +143 -0
  33. package/lib/commands/ExportCommand.js +50 -0
  34. package/lib/commands/InitCommand.d.ts +42 -7
  35. package/lib/commands/InitCommand.js +15 -17
  36. package/lib/commands/PruneCommand.d.ts +237 -17
  37. package/lib/commands/PruneCommand.js +27 -99
  38. package/lib/commands/RestoreCommand.d.ts +126 -13
  39. package/lib/commands/RestoreCommand.js +20 -49
  40. package/lib/commands/RunCommand.d.ts +23 -4
  41. package/lib/commands/RunCommand.js +21 -12
  42. package/lib/commands/SnapshotsCommand.d.ts +240 -23
  43. package/lib/commands/SnapshotsCommand.js +23 -101
  44. package/lib/commands/StartServerCommand.d.ts +10 -3
  45. package/lib/commands/StartServerCommand.js +11 -3
  46. package/lib/repositories/DatatruckRepository.js +1 -1
  47. package/lib/repositories/GitRepository.js +5 -2
  48. package/lib/tasks/MssqlTask.js +1 -1
  49. package/lib/tasks/MysqlDumpTask.js +1 -1
  50. package/lib/tasks/SqlDumpTaskAbstract.js +2 -2
  51. package/lib/utils/cli.d.ts +0 -17
  52. package/lib/utils/cli.js +1 -47
  53. package/lib/utils/datatruck/command.d.ts +6 -5
  54. package/lib/utils/datatruck/command.js +9 -5
  55. package/lib/utils/datatruck/job.js +17 -12
  56. package/lib/utils/datatruck/repository.d.ts +1 -0
  57. package/lib/utils/datatruck/repository.js +8 -1
  58. package/lib/utils/git.d.ts +5 -1
  59. package/lib/utils/git.js +7 -3
  60. package/lib/utils/math.js +1 -1
  61. package/lib/utils/object.d.ts +5 -0
  62. package/lib/utils/object.js +10 -1
  63. package/lib/utils/options.d.ts +24 -0
  64. package/lib/utils/options.js +94 -0
  65. package/lib/utils/progress.js +1 -1
  66. package/lib/utils/restic.js +1 -1
  67. package/lib/utils/string.d.ts +2 -1
  68. package/lib/utils/string.js +5 -1
  69. package/lib/utils/watcher.js +1 -1
  70. package/package.json +4 -4
@@ -1,112 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PruneCommand = void 0;
3
+ exports.PruneCommand = exports.pruneCommandOptions = void 0;
4
4
  const ConfigAction_1 = require("../actions/ConfigAction");
5
5
  const PruneAction_1 = require("../actions/PruneAction");
6
6
  const cli_1 = require("../utils/cli");
7
7
  const data_format_1 = require("../utils/data-format");
8
- const string_1 = require("../utils/string");
9
8
  const CommandAbstract_1 = require("./CommandAbstract");
9
+ exports.pruneCommandOptions = {
10
+ ...PruneAction_1.pruneActionOptions,
11
+ longId: {
12
+ description: "Show long snapshot id",
13
+ value: "boolean",
14
+ },
15
+ confirm: {
16
+ description: "Confirm action",
17
+ value: "boolean",
18
+ },
19
+ };
10
20
  class PruneCommand extends CommandAbstract_1.CommandAbstract {
11
- optionsConfig() {
12
- return this.castOptionsConfig({
13
- dryRun: {
14
- description: "",
15
- option: "--dry-run",
16
- parser: undefined,
17
- },
18
- groupBy: {
19
- description: "Group by values (packageName, repositoryName, repositoryType)",
20
- option: "-g,--group-by <values>",
21
- defaults: "packageName, repositoryName",
22
- parser: (v) => (0, string_1.parseStringList)(v, [
23
- "packageName",
24
- "repositoryName",
25
- "repositoryType",
26
- ]),
27
- },
28
- id: {
29
- description: "Filter by snapshot id",
30
- option: "-i,--id <snapshotId>",
31
- parser: string_1.parseStringList,
32
- },
33
- keepMinutely: {
34
- description: "Keep last N minutely snapshots",
35
- option: "--keepMinutely <number>",
36
- parser: Number,
37
- },
38
- keepDaily: {
39
- description: "Keep last N daily snapshots",
40
- option: "--keepDaily <number>",
41
- parser: Number,
42
- },
43
- keepHourly: {
44
- description: "Keep last N hourly snapshots",
45
- option: "--keepHourly <number>",
46
- parser: Number,
47
- },
48
- keepLast: {
49
- description: "Keep last N snapshots",
50
- option: "--keepLast <number>",
51
- parser: Number,
52
- },
53
- keepMonthly: {
54
- description: "Keep last N monthly snapshots",
55
- option: "--keepMonthly <number>",
56
- parser: Number,
57
- },
58
- keepWeekly: {
59
- description: "Keep last N weekly snapshots",
60
- option: "--keepWeekly <number>",
61
- parser: Number,
62
- },
63
- keepYearly: {
64
- description: "Keep last N yearly snapshots",
65
- option: "--keepYearly <number>",
66
- parser: Number,
67
- },
68
- longId: {
69
- description: "Show long snapshot id",
70
- option: "--longId",
71
- },
72
- package: {
73
- description: "Filter by package names",
74
- option: "-p,--package <values>",
75
- parser: string_1.parseStringList,
76
- },
77
- repository: {
78
- description: "Filter by repository names",
79
- option: "-r,--repository <values>",
80
- parser: string_1.parseStringList,
81
- },
82
- repositoryType: {
83
- description: "Filter by repository types",
84
- option: "-rt,--repository-type <values>",
85
- parser: (v) => (0, string_1.parseStringList)(v),
86
- },
87
- tag: {
88
- description: "Filter by tags",
89
- option: "-t,--tag <values>",
90
- parser: string_1.parseStringList,
91
- },
92
- showAll: {
93
- description: "Show all",
94
- option: "-a,--showAll",
95
- },
96
- confirm: {
97
- description: "Confirm action",
98
- option: "--confirm",
99
- },
100
- });
21
+ static config() {
22
+ return {
23
+ name: "prune",
24
+ alias: "p",
25
+ options: exports.pruneCommandOptions,
26
+ };
27
+ }
28
+ get optionsConfig() {
29
+ return exports.pruneCommandOptions;
101
30
  }
102
31
  async exec() {
103
32
  const verbose = this.globalOptions.verbose ?? 0;
104
33
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
105
34
  const prune = new PruneAction_1.PruneAction(config, {
106
- ids: this.options.id,
107
- packageNames: this.options.package,
108
- repositoryNames: this.options.repository,
109
- repositoryTypes: this.options.repositoryType,
35
+ ids: this.options.ids,
36
+ packageNames: this.options.packageNames,
37
+ repositoryNames: this.options.repositoryNames,
38
+ repositoryTypes: this.options.repositoryTypes,
110
39
  verbose: verbose > 0,
111
40
  dryRun: this.options.dryRun || !this.options.confirm,
112
41
  groupBy: this.options.groupBy,
@@ -117,9 +46,8 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
117
46
  keepMonthly: this.options.keepMonthly,
118
47
  keepWeekly: this.options.keepWeekly,
119
48
  keepYearly: this.options.keepYearly,
120
- tags: this.options.tag,
121
- longId: this.options.longId,
122
- returnsAll: this.options.showAll,
49
+ tags: this.options.tags,
50
+ showAll: this.options.showAll,
123
51
  });
124
52
  const result = await prune.exec();
125
53
  const dataFormat = new data_format_1.DataFormat({
@@ -1,18 +1,131 @@
1
- import type { RepositoryConfig } from "../utils/datatruck/config-type";
2
- import { If } from "../utils/ts";
1
+ import { InferOptions } from "../utils/options";
3
2
  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;
3
+ export declare const restoreCommandOptions: {
4
+ initial: {
5
+ description: string;
6
+ value: "boolean";
7
+ };
8
+ repositoryNames: {
9
+ description: string;
10
+ shortFlag: string;
11
+ value: "array";
12
+ };
13
+ repositoryTypes: {
14
+ description: string;
15
+ shortFlag: string;
16
+ value: "array";
17
+ };
18
+ packageNames: {
19
+ description: string;
20
+ shortFlag: string;
21
+ value: "array";
22
+ };
23
+ packageTaskNames: {
24
+ description: string;
25
+ shortFlag: string;
26
+ value: "array";
27
+ };
28
+ tags: {
29
+ description: string;
30
+ shortFlag: string;
31
+ value: "array";
32
+ };
33
+ packageConfig: {
34
+ description: string;
35
+ shortFlag: string;
36
+ };
37
+ id: {
38
+ description: string;
39
+ shortFlag: string;
40
+ required: true;
41
+ };
13
42
  };
14
- export declare class RestoreCommand extends CommandAbstract<RestoreCommandOptions<false>, RestoreCommandOptions<true>> {
15
- optionsConfig(): import("../utils/cli").OptionsConfig<RestoreCommandOptions<false>, RestoreCommandOptions<true>>;
43
+ export type RestoreCommandOptions = InferOptions<typeof restoreCommandOptions>;
44
+ export declare class RestoreCommand extends CommandAbstract<typeof restoreCommandOptions> {
45
+ static config(): {
46
+ name: string;
47
+ alias: string;
48
+ options: {
49
+ initial: {
50
+ description: string;
51
+ value: "boolean";
52
+ };
53
+ repositoryNames: {
54
+ description: string;
55
+ shortFlag: string;
56
+ value: "array";
57
+ };
58
+ repositoryTypes: {
59
+ description: string;
60
+ shortFlag: string;
61
+ value: "array";
62
+ };
63
+ packageNames: {
64
+ description: string;
65
+ shortFlag: string;
66
+ value: "array";
67
+ };
68
+ packageTaskNames: {
69
+ description: string;
70
+ shortFlag: string;
71
+ value: "array";
72
+ };
73
+ tags: {
74
+ description: string;
75
+ shortFlag: string;
76
+ value: "array";
77
+ };
78
+ packageConfig: {
79
+ description: string;
80
+ shortFlag: string;
81
+ };
82
+ id: {
83
+ description: string;
84
+ shortFlag: string;
85
+ required: true;
86
+ };
87
+ };
88
+ };
89
+ get optionsConfig(): {
90
+ initial: {
91
+ description: string;
92
+ value: "boolean";
93
+ };
94
+ repositoryNames: {
95
+ description: string;
96
+ shortFlag: string;
97
+ value: "array";
98
+ };
99
+ repositoryTypes: {
100
+ description: string;
101
+ shortFlag: string;
102
+ value: "array";
103
+ };
104
+ packageNames: {
105
+ description: string;
106
+ shortFlag: string;
107
+ value: "array";
108
+ };
109
+ packageTaskNames: {
110
+ description: string;
111
+ shortFlag: string;
112
+ value: "array";
113
+ };
114
+ tags: {
115
+ description: string;
116
+ shortFlag: string;
117
+ value: "array";
118
+ };
119
+ packageConfig: {
120
+ description: string;
121
+ shortFlag: string;
122
+ };
123
+ id: {
124
+ description: string;
125
+ shortFlag: string;
126
+ required: true;
127
+ };
128
+ };
16
129
  exec(): Promise<{
17
130
  result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<{
18
131
  snapshots: {
@@ -1,66 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RestoreCommand = void 0;
3
+ exports.RestoreCommand = exports.restoreCommandOptions = void 0;
4
4
  const ConfigAction_1 = require("../actions/ConfigAction");
5
5
  const RestoreAction_1 = require("../actions/RestoreAction");
6
- const string_1 = require("../utils/string");
7
6
  const CommandAbstract_1 = require("./CommandAbstract");
7
+ exports.restoreCommandOptions = {
8
+ ...RestoreAction_1.restoreActionOptions,
9
+ };
8
10
  class RestoreCommand extends CommandAbstract_1.CommandAbstract {
9
- optionsConfig() {
10
- return this.castOptionsConfig({
11
- id: {
12
- description: "Filter by snapshot id",
13
- option: "-i,--id <id>",
14
- required: true,
15
- },
16
- package: {
17
- description: "Filter by package names",
18
- option: "-p,--package <values>",
19
- parser: string_1.parseStringList,
20
- },
21
- initial: {
22
- description: "Initial restoring (disables restore path)",
23
- option: "--initial",
24
- },
25
- packageTask: {
26
- description: "Filter by package task names",
27
- option: "-pt,--package-task <values>",
28
- parser: string_1.parseStringList,
29
- },
30
- packageConfig: {
31
- description: "Filter by package config",
32
- option: "-pc,--package-config",
33
- },
34
- repository: {
35
- description: "Filter by repository names",
36
- option: "-r,--repository <values>",
37
- parser: string_1.parseStringList,
38
- },
39
- repositoryType: {
40
- description: "Filter by repository types",
41
- option: "-rt,--repository-type <values>",
42
- parser: (v) => (0, string_1.parseStringList)(v),
43
- },
44
- tag: {
45
- description: "Filter by tags",
46
- option: "-t,--tag <values>",
47
- parser: string_1.parseStringList,
48
- },
49
- });
11
+ static config() {
12
+ return {
13
+ name: "restore",
14
+ alias: "r",
15
+ options: exports.restoreCommandOptions,
16
+ };
17
+ }
18
+ get optionsConfig() {
19
+ return exports.restoreCommandOptions;
50
20
  }
51
21
  async exec() {
52
22
  const verbose = this.globalOptions.verbose ?? 0;
53
23
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
54
24
  const restore = new RestoreAction_1.RestoreAction(config, {
55
- snapshotId: this.options.id,
56
- packageNames: this.options.package,
57
- packageTaskNames: this.options.packageTask,
25
+ id: this.options.id,
26
+ packageNames: this.options.packageNames,
27
+ packageTaskNames: this.options.packageTaskNames,
58
28
  packageConfig: this.options.packageConfig,
59
- repositoryNames: this.options.repository,
60
- repositoryTypes: this.options.repositoryType,
61
- tags: this.options.tag,
29
+ repositoryNames: this.options.repositoryNames,
30
+ repositoryTypes: this.options.repositoryTypes,
31
+ tags: this.options.tags,
62
32
  verbose: verbose > 0,
63
33
  initial: this.options.initial,
34
+ }, {
64
35
  tty: this.globalOptions.tty,
65
36
  progress: this.globalOptions.progress,
66
37
  streams: this.streams,
@@ -1,9 +1,28 @@
1
+ import { InferOptions } from "../utils/options";
1
2
  import { CommandAbstract } from "./CommandAbstract";
2
- export type RunCommandOptions<TResolved = false> = {
3
- jobName: string;
3
+ export declare const runCommandOptions: {
4
+ jobName: {
5
+ description: string;
6
+ flag: false;
7
+ };
4
8
  };
5
- export declare class RunCommand extends CommandAbstract<RunCommandOptions<false>, RunCommandOptions<true>> {
6
- optionsConfig(): import("../utils/cli").OptionsConfig<RunCommandOptions<false>, RunCommandOptions<true>>;
9
+ export type RunCommandOptions = InferOptions<typeof runCommandOptions>;
10
+ export declare class RunCommand extends CommandAbstract<typeof runCommandOptions> {
11
+ static config(): {
12
+ name: string;
13
+ options: {
14
+ jobName: {
15
+ description: string;
16
+ flag: false;
17
+ };
18
+ };
19
+ };
20
+ get optionsConfig(): {
21
+ jobName: {
22
+ description: string;
23
+ flag: false;
24
+ };
25
+ };
7
26
  exec(): Promise<{
8
27
  exitCode: number;
9
28
  }>;
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RunCommand = void 0;
3
+ exports.RunCommand = exports.runCommandOptions = void 0;
4
4
  const ConfigAction_1 = require("../actions/ConfigAction");
5
5
  const job_1 = require("../utils/datatruck/job");
6
- const error_1 = require("../utils/error");
7
6
  const CommandAbstract_1 = require("./CommandAbstract");
7
+ exports.runCommandOptions = {
8
+ jobName: {
9
+ description: "Job name",
10
+ flag: false,
11
+ },
12
+ };
8
13
  class RunCommand extends CommandAbstract_1.CommandAbstract {
9
- optionsConfig() {
10
- return this.castOptionsConfig({
11
- jobName: {
12
- description: "Job name",
13
- required: true,
14
- },
15
- });
14
+ static config() {
15
+ return {
16
+ name: "run",
17
+ options: exports.runCommandOptions,
18
+ };
19
+ }
20
+ get optionsConfig() {
21
+ return exports.runCommandOptions;
16
22
  }
17
23
  async exec() {
18
24
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptionsWithPath(this.globalOptions);
@@ -20,9 +26,12 @@ class RunCommand extends CommandAbstract_1.CommandAbstract {
20
26
  const log = config.data.server?.log ?? true;
21
27
  const jobs = config.data.jobs || {};
22
28
  const jobName = this.options.jobName;
23
- const job = jobs[jobName];
24
- if (!job)
25
- throw new error_1.AppError(`Job not found: ${jobName}`);
29
+ const job = jobName ? jobs[jobName] : undefined;
30
+ if (!job || !jobName) {
31
+ const jobNames = Object.keys(config.data.jobs || {});
32
+ console.error(`error: missing required argument 'jobName' (values: ${jobNames.join(", ")})`);
33
+ return { exitCode: 1 };
34
+ }
26
35
  await (0, job_1.runJob)(job, jobName, {
27
36
  log,
28
37
  verbose: verbose,