@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
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatCronScheduleObject = void 0;
4
+ function formatCronScheduleObject(object) {
5
+ const keys = [
6
+ "minute",
7
+ "hour",
8
+ "day",
9
+ "month",
10
+ "weekDay",
11
+ ];
12
+ const result = [];
13
+ for (const key of keys) {
14
+ const value = object[key];
15
+ if (typeof value === "number") {
16
+ result.push(value.toString());
17
+ }
18
+ else if (!!value && typeof value === "object") {
19
+ result.push(`*/${value.each}`);
20
+ }
21
+ else {
22
+ result.push("*");
23
+ }
24
+ }
25
+ return result.join(" ");
26
+ }
27
+ exports.formatCronScheduleObject = formatCronScheduleObject;
@@ -23,7 +23,9 @@ export declare class RemoteFs extends AbstractFs {
23
23
  download(source: string, target: string, options?: {
24
24
  timeout?: number;
25
25
  onProgress?: (progress: BasicProgress) => void;
26
- }): Promise<void>;
26
+ }): Promise<{
27
+ bytes: number;
28
+ }>;
27
29
  }
28
30
  export declare function isRemoteBackend(backend: string): boolean;
29
31
  export declare function createFs(backend: string): AbstractFs;
@@ -80,7 +80,7 @@ class RemoteFs extends virtual_fs_1.AbstractFs {
80
80
  });
81
81
  }
82
82
  async download(source, target, options = {}) {
83
- await (0, http_1.downloadFile)(`${this.url}/download`, target, {
83
+ return await (0, http_1.downloadFile)(`${this.url}/download`, target, {
84
84
  ...options,
85
85
  headers: this.headers,
86
86
  query: { params: JSON.stringify([source]) },
@@ -0,0 +1,29 @@
1
+ import { BackupCommand } from "../../commands/BackupCommand";
2
+ import { CleanCacheCommand } from "../../commands/CleanCacheCommand";
3
+ import { GlobalOptions } from "../../commands/CommandAbstract";
4
+ import { ConfigCommand } from "../../commands/ConfigCommand";
5
+ import { CopyCommand } from "../../commands/CopyCommand";
6
+ import { InitCommand } from "../../commands/InitCommand";
7
+ import { PruneCommand } from "../../commands/PruneCommand";
8
+ import { RestoreCommand } from "../../commands/RestoreCommand";
9
+ import { SnapshotsCommand } from "../../commands/SnapshotsCommand";
10
+ import { StartServerCommand } from "../../commands/StartServerCommand";
11
+ import { Streams } from "../stream";
12
+ export declare const datatruckCommandMap: {
13
+ config: typeof ConfigCommand;
14
+ init: typeof InitCommand;
15
+ snapshots: typeof SnapshotsCommand;
16
+ prune: typeof PruneCommand;
17
+ backup: typeof BackupCommand;
18
+ restore: typeof RestoreCommand;
19
+ copy: typeof CopyCommand;
20
+ cleanCache: typeof CleanCacheCommand;
21
+ startServer: typeof StartServerCommand;
22
+ };
23
+ export type DatatruckCommandMap = typeof datatruckCommandMap;
24
+ export type InferDatatruckCommandOptions<T extends keyof DatatruckCommandMap> = InstanceType<DatatruckCommandMap[T]>["inputOptions"];
25
+ export type InferDatatruckCommandResult<T extends keyof DatatruckCommandMap, R = Awaited<ReturnType<InstanceType<DatatruckCommandMap[T]>["exec"]>>> = "result" extends keyof R ? R["result"] : undefined;
26
+ export declare function createCommand<T extends keyof DatatruckCommandMap>(name: T, globalOptions: GlobalOptions<true>, options: InferDatatruckCommandOptions<T>, streams?: Partial<Streams>, configPath?: string): BackupCommand | CopyCommand | PruneCommand | CleanCacheCommand | ConfigCommand | InitCommand | RestoreCommand | SnapshotsCommand | StartServerCommand;
27
+ export declare function createCommands(globalOptions: GlobalOptions<true>): {
28
+ [K in keyof DatatruckCommandMap as `${K}`]: (options: InferDatatruckCommandOptions<K>) => Promise<InferDatatruckCommandResult<K>>;
29
+ };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCommands = exports.createCommand = exports.datatruckCommandMap = void 0;
4
+ const BackupCommand_1 = require("../../commands/BackupCommand");
5
+ const CleanCacheCommand_1 = require("../../commands/CleanCacheCommand");
6
+ const ConfigCommand_1 = require("../../commands/ConfigCommand");
7
+ const CopyCommand_1 = require("../../commands/CopyCommand");
8
+ const InitCommand_1 = require("../../commands/InitCommand");
9
+ const PruneCommand_1 = require("../../commands/PruneCommand");
10
+ const RestoreCommand_1 = require("../../commands/RestoreCommand");
11
+ const SnapshotsCommand_1 = require("../../commands/SnapshotsCommand");
12
+ const StartServerCommand_1 = require("../../commands/StartServerCommand");
13
+ const error_1 = require("./error");
14
+ const stream_1 = require("stream");
15
+ exports.datatruckCommandMap = {
16
+ config: ConfigCommand_1.ConfigCommand,
17
+ init: InitCommand_1.InitCommand,
18
+ snapshots: SnapshotsCommand_1.SnapshotsCommand,
19
+ prune: PruneCommand_1.PruneCommand,
20
+ backup: BackupCommand_1.BackupCommand,
21
+ restore: RestoreCommand_1.RestoreCommand,
22
+ copy: CopyCommand_1.CopyCommand,
23
+ cleanCache: CleanCacheCommand_1.CleanCacheCommand,
24
+ startServer: StartServerCommand_1.StartServerCommand,
25
+ };
26
+ function createCommand(name, globalOptions, options, streams, configPath) {
27
+ const constructor = exports.datatruckCommandMap[name];
28
+ if (!constructor)
29
+ throw new error_1.AppError(`Invalid command name: ${name}`);
30
+ return new constructor(globalOptions, options, streams, configPath);
31
+ }
32
+ exports.createCommand = createCommand;
33
+ function createCommands(globalOptions) {
34
+ const object = {};
35
+ for (const name in exports.datatruckCommandMap) {
36
+ object[name] = async (options) => {
37
+ let stdoutData = "";
38
+ const stdout = new stream_1.Writable({
39
+ write(chunk, encoding, callback) {
40
+ stdoutData += chunk.toString();
41
+ process.stdout.write(chunk, encoding, callback);
42
+ },
43
+ }).on("data", (chunk) => (stdoutData += chunk.toString()));
44
+ const end = () => !stdout.closed &&
45
+ new Promise((resolve) => stdout.end().on("close", resolve));
46
+ try {
47
+ const command = createCommand(name, { ...globalOptions, outputFormat: "json", verbose: 1 }, options, { stdout });
48
+ const { exitCode } = await command.exec();
49
+ if (exitCode !== 0)
50
+ throw new Error(`Invalid exit code: ${exitCode}`);
51
+ await end();
52
+ return JSON.parse(stdoutData);
53
+ }
54
+ finally {
55
+ await end();
56
+ }
57
+ };
58
+ }
59
+ return object;
60
+ }
61
+ exports.createCommands = createCommands;
@@ -1,11 +1,18 @@
1
- import { DatatruckRepositoryConfig, datatruckRepositoryName } from "../Repository/DatatruckRepository";
2
- import { GitRepositoryConfig, gitRepositoryName } from "../Repository/GitRepository";
3
- import { ResticRepositoryConfig, resticRepositoryName } from "../Repository/ResticRepository";
4
- export type RepositoryConfigType = RepositoryConfig["type"];
5
- export type RepositoryConfigEnabledAction = "backup" | "init" | "prune" | "restore" | "snapshots";
6
- export type RepositoryEnabledObject = {
7
- [K in "defaults" | RepositoryConfigEnabledAction]?: boolean;
8
- };
1
+ import type { DatatruckPackageRepositoryConfig, DatatruckRepositoryConfig, datatruckRepositoryName } from "../../repositories/DatatruckRepository";
2
+ import type { GitPackageRepositoryConfig, GitRepositoryConfig, gitRepositoryName } from "../../repositories/GitRepository";
3
+ import type { ResticPackageRepositoryConfig, ResticRepositoryConfig, resticRepositoryName } from "../../repositories/ResticRepository";
4
+ export type PackageRepositoryConfig = {
5
+ names?: string[];
6
+ } & ({
7
+ type: typeof resticRepositoryName;
8
+ config: ResticPackageRepositoryConfig;
9
+ } | {
10
+ type: typeof datatruckRepositoryName;
11
+ config: DatatruckPackageRepositoryConfig;
12
+ } | {
13
+ type: typeof gitRepositoryName;
14
+ config: GitPackageRepositoryConfig;
15
+ });
9
16
  export type ResticRepositoryConfigItem = {
10
17
  type: typeof resticRepositoryName;
11
18
  config: ResticRepositoryConfig;
@@ -18,6 +25,10 @@ export type GitRepositoryConfigItem = {
18
25
  type: typeof gitRepositoryName;
19
26
  config: GitRepositoryConfig;
20
27
  };
28
+ export type RepositoryConfigEnabledAction = "backup" | "init" | "prune" | "restore" | "snapshots";
29
+ export type RepositoryEnabledObject = {
30
+ [K in "defaults" | RepositoryConfigEnabledAction]?: boolean;
31
+ };
21
32
  type CommonRepositoryConfig = {
22
33
  name: string;
23
34
  mirrorRepoNames?: string[];
@@ -1,9 +1,9 @@
1
- import { GitTaskConfig, gitTaskName } from "../Task/GitTask";
2
- import { MariadbTaskConfig, mariadbTaskName } from "../Task/MariadbTask";
3
- import { MssqlTaskConfig, mssqlTaskName } from "../Task/MssqlTask";
4
- import { MysqlDumpTaskConfig, mysqlDumpTaskName } from "../Task/MysqlDumpTask";
5
- import { PostgresqlDumpTaskConfig, postgresqlDumpTaskName } from "../Task/PostgresqlDumpTask";
6
- import { ScriptTaskConfig, scriptTaskName } from "../Task/ScriptTask";
1
+ import type { GitTaskConfig, gitTaskName } from "../../tasks/GitTask";
2
+ import type { MariadbTaskConfig, mariadbTaskName } from "../../tasks/MariadbTask";
3
+ import type { MssqlTaskConfig, mssqlTaskName } from "../../tasks/MssqlTask";
4
+ import type { MysqlDumpTaskConfig, mysqlDumpTaskName } from "../../tasks/MysqlDumpTask";
5
+ import type { PostgresqlDumpTaskConfig, postgresqlDumpTaskName } from "../../tasks/PostgresqlDumpTask";
6
+ import type { ScriptTaskConfig, scriptTaskName } from "../../tasks/ScriptTask";
7
7
  export type GitTaskConfigItem = {
8
8
  name: typeof gitTaskName;
9
9
  config: GitTaskConfig;
@@ -0,0 +1,51 @@
1
+ import type { PruneActionsOptions } from "../../actions/PruneAction";
2
+ import type { DataFormatType } from "../DataFormat";
3
+ import type { ReportStep } from "../reportSteps";
4
+ import type { SpawnStep } from "../spawnSteps";
5
+ import type { PackageRepositoryConfig, RepositoryConfigEnabledAction, RepositoryConfig } from "./config-repository-type";
6
+ import type { TaskConfig } from "./config-task-type";
7
+ import type { DatatruckCronServerOptions } from "./cron-server";
8
+ import type { DatatruckRepositoryServerOptions } from "./repository-server";
9
+ export { RepositoryConfig, RepositoryConfigEnabledAction, TaskConfig };
10
+ export type Config = {
11
+ $schema?: string;
12
+ hostname?: string;
13
+ tempDir?: string;
14
+ minFreeDiskSpace?: string | number;
15
+ repositories: RepositoryConfig[];
16
+ packages: PackageConfig[];
17
+ server?: DatatruckServerOptions;
18
+ reports?: DatatruckReportConfig[];
19
+ prunePolicy?: DatatruckPolicyConfig;
20
+ };
21
+ export type DatatruckServerOptions = {
22
+ log?: boolean;
23
+ repository?: DatatruckRepositoryServerOptions;
24
+ cron?: DatatruckCronServerOptions;
25
+ };
26
+ export type DatatruckReportConfig = {
27
+ when?: "success" | "error";
28
+ format?: Exclude<DataFormatType, "custom" | "tpl">;
29
+ run: SpawnStep | ReportStep;
30
+ };
31
+ export type DatatruckPolicyConfig = Pick<PruneActionsOptions, "keepDaily" | "keepHourly" | "keepMinutely" | "keepLast" | "keepMonthly" | "keepWeekly" | "keepYearly" | "groupBy" | "tags">;
32
+ export type PackageConfigMeta = {
33
+ [name: string]: any;
34
+ };
35
+ export type PackageConfig = {
36
+ name: string;
37
+ enabled?: boolean;
38
+ task?: TaskConfig;
39
+ path?: string;
40
+ restorePath?: string;
41
+ meta?: PackageConfigMeta;
42
+ restorePermissions?: {
43
+ uid: string | number;
44
+ gid: string | number;
45
+ };
46
+ include?: (string | SpawnStep)[];
47
+ exclude?: (string | SpawnStep)[];
48
+ repositoryNames?: string[];
49
+ prunePolicy?: DatatruckPolicyConfig;
50
+ repositoryConfigs?: PackageRepositoryConfig[];
51
+ };
@@ -1,10 +1,19 @@
1
- import { Config } from "../../Config/Config";
2
- import type { PackageConfig } from "../../Config/PackageConfig";
3
- import { RepositoryConfigEnabledAction, RepositoryConfig } from "../../Config/RepositoryConfig";
1
+ import type { Config } from "./config-type";
2
+ import type { PackageConfig, RepositoryConfigEnabledAction, RepositoryConfig } from "./config-type";
4
3
  export declare function findRepositoryOrFail(config: Config, repositoryName: string): RepositoryConfig;
5
4
  export declare function findPackageOrFail(config: Config, packageName: string): PackageConfig;
5
+ export declare function findPackageRepositoryConfig(pkg: PackageConfig, repo: RepositoryConfig): import("../../repositories/ResticRepository").ResticPackageRepositoryConfig | import("../../repositories/DatatruckRepository").DatatruckPackageRepositoryConfig | import("../../repositories/GitRepository").GitPackageRepositoryConfig | undefined;
6
+ export declare function filterRepository(repositories: RepositoryConfig[], options: {
7
+ include?: string[];
8
+ exclude?: string[];
9
+ action?: RepositoryConfigEnabledAction;
10
+ }): RepositoryConfig[];
11
+ export declare function sortReposByType<T extends {
12
+ name: string;
13
+ type: RepositoryConfig["type"];
14
+ }>(repositories: T[], types?: RepositoryConfig["type"][]): T[];
6
15
  export declare function ensureSameRepositoryType(a: RepositoryConfig, b: RepositoryConfig): void;
7
- export declare function filterRepository(repository: RepositoryConfig, action?: RepositoryConfigEnabledAction): boolean;
16
+ export declare function filterRepositoryByEnabled(repository: RepositoryConfig, action?: RepositoryConfigEnabledAction): boolean;
8
17
  export declare function filterPackages(config: Config, options: {
9
18
  packageNames?: string[];
10
19
  packageTaskNames?: string[];
@@ -34,17 +43,17 @@ export declare const pkgPathParams: {
34
43
  };
35
44
  export declare const pkgIncludeParams: {
36
45
  action: string;
37
- packageName: string;
38
46
  temp: string;
39
47
  snapshotId: string;
40
48
  snapshotDate: string;
49
+ packageName: string;
41
50
  };
42
51
  export declare const pkgExcludeParams: {
43
52
  action: string;
44
- packageName: string;
45
53
  temp: string;
46
54
  snapshotId: string;
47
55
  snapshotDate: string;
56
+ packageName: string;
48
57
  };
49
58
  export declare const pkgRestorePathParams: {
50
59
  [name in "temp" | keyof ResolvePackagePathParams]: string;
@@ -55,32 +64,32 @@ export declare const dbNameParams: {
55
64
  export declare const params: {
56
65
  pkgPath: {
57
66
  action: string;
58
- packageName: string;
59
67
  temp: string;
60
68
  snapshotId: string;
61
69
  snapshotDate: string;
70
+ packageName: string;
62
71
  };
63
72
  pkgRestorePath: {
64
73
  path: string;
65
74
  action: string;
66
- packageName: string;
67
75
  temp: string;
68
76
  snapshotId: string;
69
77
  snapshotDate: string;
78
+ packageName: string;
70
79
  };
71
80
  pkgInclude: {
72
81
  action: string;
73
- packageName: string;
74
82
  temp: string;
75
83
  snapshotId: string;
76
84
  snapshotDate: string;
85
+ packageName: string;
77
86
  };
78
87
  pkgExclude: {
79
88
  action: string;
80
- packageName: string;
81
89
  temp: string;
82
90
  snapshotId: string;
83
91
  snapshotDate: string;
92
+ packageName: string;
84
93
  };
85
94
  dbName: {
86
95
  snapshotId: string;
@@ -1,24 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.params = exports.dbNameParams = exports.pkgRestorePathParams = exports.pkgExcludeParams = exports.pkgIncludeParams = exports.pkgPathParams = exports.resolvePackages = exports.resolvePackage = exports.resolveDatabaseName = exports.resolvePackagePath = exports.filterPackages = exports.filterRepository = exports.ensureSameRepositoryType = exports.findPackageOrFail = exports.findRepositoryOrFail = void 0;
4
- const AppError_1 = require("../../Error/AppError");
3
+ exports.params = exports.dbNameParams = exports.pkgRestorePathParams = exports.pkgExcludeParams = exports.pkgIncludeParams = exports.pkgPathParams = exports.resolvePackages = exports.resolvePackage = exports.resolveDatabaseName = exports.resolvePackagePath = exports.filterPackages = exports.filterRepositoryByEnabled = exports.ensureSameRepositoryType = exports.sortReposByType = exports.filterRepository = exports.findPackageRepositoryConfig = exports.findPackageOrFail = exports.findRepositoryOrFail = void 0;
5
4
  const string_1 = require("../string");
6
5
  const temp_1 = require("../temp");
6
+ const error_1 = require("./error");
7
7
  const micromatch_1 = require("micromatch");
8
8
  function findRepositoryOrFail(config, repositoryName) {
9
9
  const repo = config.repositories.find((v) => v.name === repositoryName);
10
10
  if (!repo)
11
- throw new AppError_1.AppError(`Repository '${repositoryName}' not found`);
11
+ throw new error_1.AppError(`Repository '${repositoryName}' not found`);
12
12
  return repo;
13
13
  }
14
14
  exports.findRepositoryOrFail = findRepositoryOrFail;
15
15
  function findPackageOrFail(config, packageName) {
16
16
  const pkg = config.packages.find((v) => v.name === packageName);
17
17
  if (!pkg)
18
- throw new AppError_1.AppError(`Package '${packageName}' not found`);
18
+ throw new error_1.AppError(`Package '${packageName}' not found`);
19
19
  return pkg;
20
20
  }
21
21
  exports.findPackageOrFail = findPackageOrFail;
22
+ function findPackageRepositoryConfig(pkg, repo) {
23
+ return pkg.repositoryConfigs?.find((config) => config.type === repo.type &&
24
+ (!config.names || config.names.includes(repo.name)))?.config;
25
+ }
26
+ exports.findPackageRepositoryConfig = findPackageRepositoryConfig;
27
+ function filterRepository(repositories, options) {
28
+ return repositories.filter((r) => {
29
+ if (options.include && !options.include.includes(r.name))
30
+ return false;
31
+ if (options.exclude && options.exclude.includes(r.name))
32
+ return false;
33
+ if (options.action && !filterRepositoryByEnabled(r, options.action))
34
+ return false;
35
+ return true;
36
+ });
37
+ }
38
+ exports.filterRepository = filterRepository;
39
+ function sortReposByType(repositories, types) {
40
+ const groups = repositories.reduce((group, item) => {
41
+ if (!group[item.type])
42
+ group[item.type] = [];
43
+ group[item.type].push(item);
44
+ return group;
45
+ }, {});
46
+ const result = [];
47
+ const sortedTypes = [
48
+ ...new Set([...(types || []), ...Object.keys(groups)]),
49
+ ];
50
+ for (const type of sortedTypes) {
51
+ const group = groups[type];
52
+ if (group)
53
+ result.push(...group.sort((a, b) => a.name.localeCompare(b.name)));
54
+ }
55
+ return result;
56
+ }
57
+ exports.sortReposByType = sortReposByType;
22
58
  function ensureSameRepositoryType(a, b) {
23
59
  if (a.type !== b.type) {
24
60
  const names = [a.name, b.name].join(" and ");
@@ -27,14 +63,14 @@ function ensureSameRepositoryType(a, b) {
27
63
  }
28
64
  }
29
65
  exports.ensureSameRepositoryType = ensureSameRepositoryType;
30
- function filterRepository(repository, action) {
66
+ function filterRepositoryByEnabled(repository, action) {
31
67
  const enabled = repository.enabled ?? true;
32
68
  if (typeof enabled === "boolean")
33
69
  return enabled;
34
70
  const defaults = enabled["defaults"] ?? true;
35
71
  return action ? enabled[action] ?? defaults : true;
36
72
  }
37
- exports.filterRepository = filterRepository;
73
+ exports.filterRepositoryByEnabled = filterRepositoryByEnabled;
38
74
  function filterPackages(config, options) {
39
75
  const packagePatterns = (0, string_1.makePathPatterns)(options.packageNames);
40
76
  const taskNamePatterns = (0, string_1.makePathPatterns)(options.packageTaskNames);
@@ -43,7 +79,7 @@ function filterPackages(config, options) {
43
79
  pkg = Object.assign({}, pkg);
44
80
  pkg.repositoryNames = (pkg.repositoryNames ?? []).filter((name) => {
45
81
  const repo = findRepositoryOrFail(config, name);
46
- if (!filterRepository(repo, options?.sourceAction))
82
+ if (!filterRepositoryByEnabled(repo, options?.sourceAction))
47
83
  return false;
48
84
  return ((!options.repositoryNames ||
49
85
  options.repositoryNames.includes(name)) &&
@@ -1,14 +1,35 @@
1
- import { BackupCommandOptions } from "../../Command/BackupCommand";
2
- import { CopyCommandOptionsType } from "../../Command/CopyCommand";
1
+ import { BackupCommandOptions } from "../../commands/BackupCommand";
2
+ import { CopyCommandOptions } from "../../commands/CopyCommand";
3
+ import { PruneCommandOptions } from "../../commands/PruneCommand";
4
+ export type CronScheduleObject = {
5
+ minute?: number | {
6
+ each: number;
7
+ };
8
+ hour?: number | {
9
+ each: number;
10
+ };
11
+ day?: number | {
12
+ each: number;
13
+ };
14
+ month?: number | {
15
+ each: number;
16
+ };
17
+ weekDay?: number | {
18
+ each: number;
19
+ };
20
+ };
3
21
  export type CronAction = {
4
- schedule: string;
22
+ schedule: string | CronScheduleObject;
23
+ } & ({
5
24
  name: "backup";
6
25
  options: BackupCommandOptions;
7
26
  } | {
8
- schedule: string;
9
27
  name: "copy";
10
- options: CopyCommandOptionsType;
11
- };
28
+ options: CopyCommandOptions;
29
+ } | {
30
+ name: "prune";
31
+ options: PruneCommandOptions;
32
+ });
12
33
  export type DatatruckCronServerOptions = {
13
34
  enabled?: boolean;
14
35
  actions?: CronAction[];
@@ -1,28 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCronServer = void 0;
4
- const CommandFactory_1 = require("../../Factory/CommandFactory");
4
+ const ConfigAction_1 = require("../../actions/ConfigAction");
5
5
  const cli_1 = require("../cli");
6
+ const cron_1 = require("../cron");
6
7
  const process_1 = require("../process");
8
+ const string_1 = require("../string");
9
+ const watcher_1 = require("../watcher");
10
+ const command_1 = require("./command");
7
11
  const croner_1 = require("croner");
8
- function createJobs(actions, currentJobs = [], worker) {
12
+ function createJobs(actions, worker) {
9
13
  const jobs = [];
10
14
  for (const action of actions) {
11
15
  const index = actions.indexOf(action);
12
- const context = JSON.stringify({
13
- index: actions.indexOf(action),
14
- data: action,
15
- });
16
- const job = currentJobs.at(index);
17
- if (!job || job.options.context !== context) {
18
- job?.stop();
19
- jobs.push((0, croner_1.Cron)(action.schedule, {
20
- paused: true,
21
- context: JSON.stringify(action),
22
- catch: true,
23
- protect: true,
24
- }, () => worker(action, index)));
25
- }
16
+ jobs.push((0, croner_1.Cron)(typeof action.schedule === "string"
17
+ ? action.schedule
18
+ : (0, cron_1.formatCronScheduleObject)(action.schedule), {
19
+ paused: true,
20
+ context: index,
21
+ catch: true,
22
+ protect: true,
23
+ }, () => worker(action, index)));
26
24
  }
27
25
  return jobs;
28
26
  }
@@ -31,9 +29,9 @@ function createCronServer(options, config) {
31
29
  if (config.log)
32
30
  console.info(`> [job] ${index} - ${action.name}`);
33
31
  try {
34
- const Command = (0, CommandFactory_1.CommandConstructorFactory)(action.name);
32
+ const Command = command_1.datatruckCommandMap[action.name];
35
33
  const command = new Command({ config: { packages: [], repositories: [] } }, {});
36
- const cliOptions = (0, cli_1.stringifyOptions)(command.onOptions(), action.options);
34
+ const cliOptions = (0, cli_1.stringifyOptions)(command.optionsConfig(), action.options);
37
35
  const [node, bin] = process.argv;
38
36
  await (0, process_1.exec)(node, [bin, "-c", config.configPath, action.name, ...cliOptions], {}, { log: config.verbose });
39
37
  if (config.log)
@@ -44,16 +42,36 @@ function createCronServer(options, config) {
44
42
  console.error(`< [job] ${index} - ${action.name}`, error);
45
43
  }
46
44
  };
47
- const jobs = createJobs(options.actions || [], [], worker);
48
- return {
45
+ let jobs = createJobs(options.actions || [], worker);
46
+ const watcher = (0, watcher_1.createWatcher)({
47
+ onRead: () => ConfigAction_1.ConfigAction.findAndParseFile(config.configPath),
48
+ onCheck: (prev, current) => (0, string_1.compareJsons)(prev, current),
49
+ onError: (error) => {
50
+ if (config.log)
51
+ console.error(`< [jobs] update error`, error);
52
+ },
53
+ onChange: (data) => {
54
+ if (config.log)
55
+ console.info(`[jobs] updated`);
56
+ handler.stop();
57
+ const cron = data?.server?.cron;
58
+ const enabled = cron?.enabled ?? true;
59
+ jobs = enabled ? createJobs(cron?.actions || [], worker) : [];
60
+ handler.start();
61
+ },
62
+ });
63
+ const handler = {
49
64
  start: () => {
50
65
  for (const job of jobs)
51
66
  job.resume();
67
+ watcher.start();
52
68
  },
53
69
  stop: () => {
70
+ watcher.stop();
54
71
  for (const job of jobs)
55
72
  job.stop();
56
73
  },
57
74
  };
75
+ return handler;
58
76
  }
59
77
  exports.createCronServer = createCronServer;
@@ -1,6 +1,6 @@
1
- import { PackageConfig } from "../../Config/PackageConfig";
2
- import { PreSnapshot } from "../../Repository/RepositoryAbstract";
1
+ import { PreSnapshot } from "../../repositories/RepositoryAbstract";
3
2
  import { SpawnStep } from "../spawnSteps";
3
+ import type { PackageConfig } from "./config-type";
4
4
  export type ParsePathsOptions = {
5
5
  cwd?: string;
6
6
  verbose?: boolean;
@@ -0,0 +1,14 @@
1
+ import { Listr3, Listr3TaskResult, List3SummaryResult } from "../list";
2
+ import { DatatruckReportConfig } from "./config-type";
3
+ export type ReportListTaskContext = {
4
+ report: {
5
+ type: string;
6
+ };
7
+ };
8
+ export declare function createReportListTasks<T extends ReportListTaskContext>(list: Listr3<T>, options: {
9
+ action: string;
10
+ hostname: string;
11
+ reports: DatatruckReportConfig[];
12
+ onMessage: (result: (List3SummaryResult | Listr3TaskResult<T>)[], report: DatatruckReportConfig) => string;
13
+ verbose?: boolean;
14
+ }): import("listr2").ListrTask<any, any, any>[];
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createReportListTasks = void 0;
4
+ const reportSteps_1 = require("../reportSteps");
5
+ const spawnSteps_1 = require("../spawnSteps");
6
+ function createReportListTasks(list, options) {
7
+ return options.reports.map((report, index) => {
8
+ const reportIndex = index + 1;
9
+ return list.$task({
10
+ title: {
11
+ initial: `Send report ${reportIndex}`,
12
+ started: `Sending report ${reportIndex}`,
13
+ completed: `Report sent: ${reportIndex}`,
14
+ failed: `Report send failed: ${reportIndex}`,
15
+ },
16
+ key: "report",
17
+ keyIndex: index,
18
+ data: { type: report.run.type },
19
+ exitOnError: false,
20
+ run: async (task) => {
21
+ const result = list.getResult().filter((r) => r.key !== "report");
22
+ const success = result.every((r) => !r.error);
23
+ const enabled = !report.when ||
24
+ (report.when === "success" && success) ||
25
+ (report.when === "error" && !success);
26
+ if (!enabled)
27
+ return task.skip(`Report send skipped: ${reportIndex}`);
28
+ const message = options.onMessage(result, report);
29
+ if ((0, spawnSteps_1.isSpawnStep)(report.run)) {
30
+ await (0, spawnSteps_1.runSpawnSteps)(report.run, {
31
+ data: {
32
+ dtt: {
33
+ message,
34
+ result,
35
+ success,
36
+ },
37
+ },
38
+ verbose: options.verbose,
39
+ });
40
+ }
41
+ else if ((0, reportSteps_1.isReportStep)(report.run)) {
42
+ await (0, reportSteps_1.runReportSteps)(report.run, {
43
+ data: {
44
+ title: `[${options.hostname}] DTT ${options.action}`,
45
+ message,
46
+ success,
47
+ },
48
+ });
49
+ }
50
+ else {
51
+ throw new Error(`Invalid step type: ${report.run.type}`);
52
+ }
53
+ },
54
+ });
55
+ });
56
+ }
57
+ exports.createReportListTasks = createReportListTasks;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createDatatruckRepositoryServer = exports.headerKey = void 0;
4
- const ConfigAction_1 = require("../../Action/ConfigAction");
4
+ const ConfigAction_1 = require("../../actions/ConfigAction");
5
5
  const http_1 = require("../http");
6
6
  const virtual_fs_1 = require("../virtual-fs");
7
7
  const fs_1 = require("fs");
@@ -67,7 +67,8 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
67
67
  return res.end();
68
68
  }
69
69
  const fileOptions = config.configPath
70
- ? (await ConfigAction_1.ConfigAction.parseFile(config.configPath)).server?.repository
70
+ ? (await ConfigAction_1.ConfigAction.findAndParseFile(config.configPath)).server
71
+ ?.repository
71
72
  : undefined;
72
73
  const options = fileOptions ?? inOptions;
73
74
  const backend = findRepositoryBackend(req, repository, options);