@datatruck/cli 0.32.1 → 0.32.3

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 (189) hide show
  1. package/config.schema.json +1224 -1271
  2. package/{Action → lib/Action}/BackupAction.d.ts +9 -9
  3. package/{Action → lib/Action}/BackupAction.js +27 -8
  4. package/{Action → lib/Action}/ConfigAction.d.ts +9 -9
  5. package/{Action → lib/Action}/ConfigAction.js +4 -2
  6. package/{Action → lib/Action}/CopyAction.d.ts +5 -5
  7. package/{Action → lib/Action}/InitAction.d.ts +3 -3
  8. package/{Action → lib/Action}/PruneAction.d.ts +5 -5
  9. package/{Action → lib/Action}/RestoreAction.d.ts +5 -5
  10. package/{Action → lib/Action}/SnapshotsAction.d.ts +5 -5
  11. package/{Command → lib/Command}/BackupCommand.d.ts +2 -2
  12. package/{Command → lib/Command}/CommandAbstract.d.ts +4 -4
  13. package/{Command → lib/Command}/ConfigCommand.d.ts +2 -2
  14. package/{Command → lib/Command}/InitCommand.d.ts +2 -2
  15. package/{Command → lib/Command}/PruneCommand.d.ts +2 -2
  16. package/{Command → lib/Command}/RestoreCommand.d.ts +2 -2
  17. package/{Command → lib/Command}/SnapshotsCommand.d.ts +2 -2
  18. package/lib/Config/Config.d.ts +28 -0
  19. package/lib/Config/PackageConfig.d.ts +24 -0
  20. package/lib/Config/PackageConfig.js +2 -0
  21. package/lib/Config/PackageRepositoryConfig.d.ts +15 -0
  22. package/lib/Config/PackageRepositoryConfig.js +2 -0
  23. package/lib/Config/PrunePolicyConfig.d.ts +2 -0
  24. package/lib/Config/PrunePolicyConfig.js +2 -0
  25. package/lib/Config/RepositoryConfig.d.ts +27 -0
  26. package/lib/Config/RepositoryConfig.js +2 -0
  27. package/lib/Config/TaskConfig.d.ts +31 -0
  28. package/lib/Config/TaskConfig.js +2 -0
  29. package/{Factory → lib/Factory}/CommandFactory.d.ts +5 -5
  30. package/lib/Factory/RepositoryFactory.d.ts +3 -0
  31. package/lib/Factory/TaskFactory.d.ts +3 -0
  32. package/{Repository → lib/Repository}/DatatruckRepository.d.ts +9 -12
  33. package/{Repository → lib/Repository}/DatatruckRepository.js +1 -38
  34. package/lib/Repository/GitRepository.d.ts +28 -0
  35. package/{Repository → lib/Repository}/GitRepository.js +1 -15
  36. package/{Repository → lib/Repository}/RepositoryAbstract.d.ts +8 -8
  37. package/{Repository → lib/Repository}/ResticRepository.d.ts +11 -14
  38. package/{Repository → lib/Repository}/ResticRepository.js +1 -63
  39. package/{Task → lib/Task}/GitTask.d.ts +2 -4
  40. package/{Task → lib/Task}/GitTask.js +1 -42
  41. package/{Task → lib/Task}/MariadbTask.d.ts +2 -4
  42. package/{Task → lib/Task}/MariadbTask.js +1 -54
  43. package/{Task → lib/Task}/MssqlTask.d.ts +2 -4
  44. package/{Task → lib/Task}/MssqlTask.js +1 -14
  45. package/{Task → lib/Task}/MysqlDumpTask.d.ts +4 -5
  46. package/{Task → lib/Task}/MysqlDumpTask.js +1 -11
  47. package/{Task → lib/Task}/PostgresqlDumpTask.d.ts +5 -7
  48. package/{Task → lib/Task}/PostgresqlDumpTask.js +1 -5
  49. package/lib/Task/ScriptTask.d.ts +30 -0
  50. package/lib/Task/ScriptTask.js +55 -0
  51. package/{Task → lib/Task}/SqlDumpTaskAbstract.d.ts +5 -7
  52. package/{Task → lib/Task}/SqlDumpTaskAbstract.js +1 -43
  53. package/{Task → lib/Task}/TaskAbstract.d.ts +2 -2
  54. package/lib/cli.d.ts +4 -0
  55. package/lib/config.schema.d.ts +2 -0
  56. package/lib/config.schema.js +10 -0
  57. package/lib/index.d.ts +24 -0
  58. package/lib/index.js +21 -0
  59. package/{utils → lib/utils}/DataFormat.d.ts +4 -4
  60. package/{utils → lib/utils}/Git.d.ts +6 -6
  61. package/{utils → lib/utils}/Restic.d.ts +14 -14
  62. package/{utils → lib/utils}/datatruck/config.d.ts +20 -20
  63. package/lib/utils/datatruck/paths.d.ts +17 -0
  64. package/{utils → lib/utils}/datatruck/paths.js +3 -3
  65. package/{utils → lib/utils}/datatruck/repository-server.d.ts +1 -1
  66. package/{utils → lib/utils}/datatruck/snapshot.d.ts +2 -2
  67. package/{utils → lib/utils}/date.d.ts +3 -3
  68. package/{utils → lib/utils}/exit.d.ts +3 -3
  69. package/{utils → lib/utils}/mysql.d.ts +5 -4
  70. package/{utils → lib/utils}/mysql.js +2 -2
  71. package/{utils → lib/utils}/process.d.ts +8 -5
  72. package/lib/utils/reportSteps.d.ts +26 -0
  73. package/lib/utils/reportSteps.js +41 -0
  74. package/lib/utils/spawnSteps.d.ts +36 -0
  75. package/lib/utils/spawnSteps.js +74 -0
  76. package/{utils → lib/utils}/string.d.ts +3 -3
  77. package/{utils → lib/utils}/string.js +3 -3
  78. package/{utils → lib/utils}/tar.d.ts +0 -8
  79. package/{utils → lib/utils}/tar.js +1 -18
  80. package/package.json +39 -25
  81. package/CHANGELOG.md +0 -569
  82. package/Config/Config.d.ts +0 -28
  83. package/Config/Config.js +0 -140
  84. package/Config/PackageConfig.d.ts +0 -23
  85. package/Config/PackageConfig.js +0 -51
  86. package/Config/PackageRepositoryConfig.d.ts +0 -17
  87. package/Config/PackageRepositoryConfig.js +0 -37
  88. package/Config/PrunePolicyConfig.d.ts +0 -4
  89. package/Config/PrunePolicyConfig.js +0 -28
  90. package/Config/RepositoryConfig.d.ts +0 -24
  91. package/Config/RepositoryConfig.js +0 -62
  92. package/Config/TaskConfig.d.ts +0 -27
  93. package/Config/TaskConfig.js +0 -41
  94. package/Factory/RepositoryFactory.d.ts +0 -3
  95. package/Factory/TaskFactory.d.ts +0 -3
  96. package/JsonSchema/DefinitionEnum.d.ts +0 -26
  97. package/JsonSchema/DefinitionEnum.js +0 -33
  98. package/JsonSchema/JsonSchema.d.ts +0 -4
  99. package/JsonSchema/JsonSchema.js +0 -65
  100. package/JsonSchema/backup-def.d.ts +0 -30
  101. package/JsonSchema/backup-def.js +0 -18
  102. package/JsonSchema/copy-def.d.ts +0 -24
  103. package/JsonSchema/copy-def.js +0 -15
  104. package/Repository/GitRepository.d.ts +0 -31
  105. package/Task/ScriptTask.d.ts +0 -38
  106. package/Task/ScriptTask.js +0 -163
  107. package/cli.d.ts +0 -4
  108. package/index.d.ts +0 -1
  109. package/utils/datatruck/paths.d.ts +0 -17
  110. package/utils/path.d.ts +0 -1
  111. package/utils/path.js +0 -8
  112. package/utils/schema.d.ts +0 -34
  113. package/utils/schema.js +0 -36
  114. package/utils/steps.d.ts +0 -43
  115. package/utils/steps.js +0 -97
  116. /package/{Action → lib/Action}/CleanCacheAction.d.ts +0 -0
  117. /package/{Action → lib/Action}/CleanCacheAction.js +0 -0
  118. /package/{Action → lib/Action}/CopyAction.js +0 -0
  119. /package/{Action → lib/Action}/InitAction.js +0 -0
  120. /package/{Action → lib/Action}/PruneAction.js +0 -0
  121. /package/{Action → lib/Action}/RestoreAction.js +0 -0
  122. /package/{Action → lib/Action}/SnapshotsAction.js +0 -0
  123. /package/{Command → lib/Command}/BackupCommand.js +0 -0
  124. /package/{Command → lib/Command}/CleanCacheCommand.d.ts +0 -0
  125. /package/{Command → lib/Command}/CleanCacheCommand.js +0 -0
  126. /package/{Command → lib/Command}/CommandAbstract.js +0 -0
  127. /package/{Command → lib/Command}/ConfigCommand.js +0 -0
  128. /package/{Command → lib/Command}/CopyCommand.d.ts +0 -0
  129. /package/{Command → lib/Command}/CopyCommand.js +0 -0
  130. /package/{Command → lib/Command}/InitCommand.js +0 -0
  131. /package/{Command → lib/Command}/PruneCommand.js +0 -0
  132. /package/{Command → lib/Command}/RestoreCommand.js +0 -0
  133. /package/{Command → lib/Command}/SnapshotsCommand.js +0 -0
  134. /package/{Command → lib/Command}/StartServerCommand.d.ts +0 -0
  135. /package/{Command → lib/Command}/StartServerCommand.js +0 -0
  136. /package/{index.js → lib/Config/Config.js} +0 -0
  137. /package/{Error → lib/Error}/AppError.d.ts +0 -0
  138. /package/{Error → lib/Error}/AppError.js +0 -0
  139. /package/{Factory → lib/Factory}/CommandFactory.js +0 -0
  140. /package/{Factory → lib/Factory}/RepositoryFactory.js +0 -0
  141. /package/{Factory → lib/Factory}/TaskFactory.js +0 -0
  142. /package/{Repository → lib/Repository}/RepositoryAbstract.js +0 -0
  143. /package/{Task → lib/Task}/TaskAbstract.js +0 -0
  144. /package/{bin.d.ts → lib/bin.d.ts} +0 -0
  145. /package/{bin.js → lib/bin.js} +0 -0
  146. /package/{cli.js → lib/cli.js} +0 -0
  147. /package/{globalData.d.ts → lib/globalData.d.ts} +0 -0
  148. /package/{globalData.js → lib/globalData.js} +0 -0
  149. /package/{pkg.d.ts → lib/pkg.d.ts} +0 -0
  150. /package/{pkg.js → lib/pkg.js} +0 -0
  151. /package/{utils → lib/utils}/DataFormat.js +0 -0
  152. /package/{utils → lib/utils}/Git.js +0 -0
  153. /package/{utils → lib/utils}/Restic.js +0 -0
  154. /package/{utils → lib/utils}/async.d.ts +0 -0
  155. /package/{utils → lib/utils}/async.js +0 -0
  156. /package/{utils → lib/utils}/bytes.d.ts +0 -0
  157. /package/{utils → lib/utils}/bytes.js +0 -0
  158. /package/{utils → lib/utils}/cli.d.ts +0 -0
  159. /package/{utils → lib/utils}/cli.js +0 -0
  160. /package/{utils → lib/utils}/crypto.d.ts +0 -0
  161. /package/{utils → lib/utils}/crypto.js +0 -0
  162. /package/{utils → lib/utils}/datatruck/client.d.ts +0 -0
  163. /package/{utils → lib/utils}/datatruck/client.js +0 -0
  164. /package/{utils → lib/utils}/datatruck/config.js +0 -0
  165. /package/{utils → lib/utils}/datatruck/cron-server.d.ts +0 -0
  166. /package/{utils → lib/utils}/datatruck/cron-server.js +0 -0
  167. /package/{utils → lib/utils}/datatruck/repository-server.js +0 -0
  168. /package/{utils → lib/utils}/datatruck/snapshot.js +0 -0
  169. /package/{utils → lib/utils}/date.js +0 -0
  170. /package/{utils → lib/utils}/exit.js +0 -0
  171. /package/{utils → lib/utils}/fs.d.ts +0 -0
  172. /package/{utils → lib/utils}/fs.js +0 -0
  173. /package/{utils → lib/utils}/http.d.ts +0 -0
  174. /package/{utils → lib/utils}/http.js +0 -0
  175. /package/{utils → lib/utils}/list.d.ts +0 -0
  176. /package/{utils → lib/utils}/list.js +0 -0
  177. /package/{utils → lib/utils}/math.d.ts +0 -0
  178. /package/{utils → lib/utils}/math.js +0 -0
  179. /package/{utils → lib/utils}/object.d.ts +0 -0
  180. /package/{utils → lib/utils}/object.js +0 -0
  181. /package/{utils → lib/utils}/process.js +0 -0
  182. /package/{utils → lib/utils}/progress.d.ts +0 -0
  183. /package/{utils → lib/utils}/progress.js +0 -0
  184. /package/{utils → lib/utils}/stream.d.ts +0 -0
  185. /package/{utils → lib/utils}/stream.js +0 -0
  186. /package/{utils → lib/utils}/temp.d.ts +0 -0
  187. /package/{utils → lib/utils}/temp.js +0 -0
  188. /package/{utils → lib/utils}/virtual-fs.d.ts +0 -0
  189. /package/{utils → lib/utils}/virtual-fs.js +0 -0
@@ -0,0 +1,30 @@
1
+ import { PackageConfig } from "../Config/PackageConfig";
2
+ import { PreSnapshot } from "../Repository/RepositoryAbstract";
3
+ import { ProcessEnv } from "../utils/process";
4
+ import { SpawnStep } from "../utils/spawnSteps";
5
+ import { TaskBackupData, TaskPrepareRestoreData, TaskRestoreData, TaskAbstract } from "./TaskAbstract";
6
+ type NodeData = {
7
+ dtt: {
8
+ snapshot: PreSnapshot;
9
+ package: PackageConfig;
10
+ snapshotPath: string;
11
+ };
12
+ };
13
+ export type ScriptTaskConfig = {
14
+ env?: ProcessEnv;
15
+ backupSteps: SpawnStep[];
16
+ restoreSteps: SpawnStep[];
17
+ };
18
+ export declare function scriptTaskCode<Data extends Record<string, any>>(cb: (data: NodeData & Data) => void): string;
19
+ export declare const scriptTaskName = "script";
20
+ export declare class ScriptTask extends TaskAbstract<ScriptTaskConfig> {
21
+ protected verbose?: boolean;
22
+ backup(data: TaskBackupData): Promise<{
23
+ snapshotPath: string;
24
+ }>;
25
+ prepareRestore(data: TaskPrepareRestoreData): Promise<{
26
+ snapshotPath: string;
27
+ }>;
28
+ restore(data: TaskRestoreData): Promise<void>;
29
+ }
30
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScriptTask = exports.scriptTaskName = exports.scriptTaskCode = void 0;
4
+ const spawnSteps_1 = require("../utils/spawnSteps");
5
+ const temp_1 = require("../utils/temp");
6
+ const TaskAbstract_1 = require("./TaskAbstract");
7
+ function scriptTaskCode(cb) {
8
+ return `(${cb.toString()})(...arguments);`;
9
+ }
10
+ exports.scriptTaskCode = scriptTaskCode;
11
+ exports.scriptTaskName = "script";
12
+ class ScriptTask extends TaskAbstract_1.TaskAbstract {
13
+ verbose;
14
+ async backup(data) {
15
+ const config = this.config;
16
+ const snapshotPath = data.package.path ??
17
+ (await (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "snapshot"));
18
+ await (0, spawnSteps_1.runSpawnSteps)(config.backupSteps, {
19
+ data: {
20
+ dtt: {
21
+ snapshot: data.snapshot,
22
+ snapshotPath: snapshotPath,
23
+ package: data.package,
24
+ },
25
+ },
26
+ env: config.env,
27
+ cwd: snapshotPath,
28
+ verbose: data.options.verbose,
29
+ tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "nodeStep"),
30
+ });
31
+ return { snapshotPath };
32
+ }
33
+ async prepareRestore(data) {
34
+ return {
35
+ snapshotPath: data.package.restorePath ??
36
+ (await (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "restore", "snapshot")),
37
+ };
38
+ }
39
+ async restore(data) {
40
+ const config = this.config;
41
+ await (0, spawnSteps_1.runSpawnSteps)(config.restoreSteps, {
42
+ data: {
43
+ dtt: {
44
+ snapshot: data.snapshot,
45
+ snapshotPath: data.snapshotPath,
46
+ package: data.package,
47
+ },
48
+ },
49
+ env: config.env,
50
+ verbose: data.options.verbose,
51
+ tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "restore", "nodeStep"),
52
+ });
53
+ }
54
+ }
55
+ exports.ScriptTask = ScriptTask;
@@ -1,12 +1,11 @@
1
1
  import { exec } from "../utils/process";
2
2
  import { TaskBackupData, TaskPrepareRestoreData, TaskRestoreData, TaskAbstract } from "./TaskAbstract";
3
- import { JSONSchema7, JSONSchema7Definition } from "json-schema";
4
- export type TargetDatabaseType = {
3
+ export type TargetDatabase = {
5
4
  name: string;
6
5
  charset?: string;
7
6
  collate?: string;
8
7
  };
9
- export type SqlDumpTaskConfigType = {
8
+ export type SqlDumpTaskConfig = {
10
9
  password: string | {
11
10
  path: string;
12
11
  };
@@ -18,17 +17,16 @@ export type SqlDumpTaskConfigType = {
18
17
  * @default true
19
18
  */
20
19
  storedPrograms?: boolean;
21
- targetDatabase?: TargetDatabaseType;
20
+ targetDatabase?: TargetDatabase;
22
21
  includeTables?: string[];
23
22
  excludeTables?: string[];
24
23
  oneFileByTable?: boolean;
25
24
  };
26
- export declare const sqlDumpTaskDefinition: (props?: Record<string, JSONSchema7Definition>) => JSONSchema7;
27
- export declare abstract class SqlDumpTaskAbstract<TConfig extends SqlDumpTaskConfigType> extends TaskAbstract<TConfig> {
25
+ export declare abstract class SqlDumpTaskAbstract<TConfig extends SqlDumpTaskConfig> extends TaskAbstract<TConfig> {
28
26
  protected verbose?: boolean;
29
27
  fetchPassword(): Promise<string | null>;
30
28
  fetchValues(query: string): Promise<string[]>;
31
- abstract onCreateDatabase(database: TargetDatabaseType): Promise<void>;
29
+ abstract onCreateDatabase(database: TargetDatabase): Promise<void>;
32
30
  abstract onDatabaseIsEmpty(databaseName: string): Promise<boolean>;
33
31
  abstract onFetchTableNames(database: string): Promise<string[]>;
34
32
  abstract onExecQuery(query: string): ReturnType<typeof exec>;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SqlDumpTaskAbstract = exports.sqlDumpTaskDefinition = void 0;
3
+ exports.SqlDumpTaskAbstract = void 0;
4
4
  const AppError_1 = require("../Error/AppError");
5
- const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
6
5
  const cli_1 = require("../utils/cli");
7
6
  const config_1 = require("../utils/datatruck/config");
8
7
  const fs_1 = require("../utils/fs");
@@ -13,47 +12,6 @@ const assert_1 = require("assert");
13
12
  const promises_1 = require("fs/promises");
14
13
  const micromatch_1 = require("micromatch");
15
14
  const path_1 = require("path");
16
- const sqlDumpTaskDefinition = (props = {}) => ({
17
- type: "object",
18
- required: ["password", "hostname", "username", "database"],
19
- additionalProperties: false,
20
- properties: {
21
- ...props,
22
- password: {
23
- anyOf: [
24
- {
25
- type: "string",
26
- },
27
- {
28
- type: "object",
29
- additionalProperties: false,
30
- required: ["path"],
31
- properties: {
32
- path: { type: "string" },
33
- },
34
- },
35
- ],
36
- },
37
- hostname: { type: "string" },
38
- port: { type: "integer" },
39
- username: { type: "string" },
40
- database: { type: "string" },
41
- targetDatabase: {
42
- type: "object",
43
- required: ["name"],
44
- properties: {
45
- name: { type: "string" },
46
- charset: { type: "string" },
47
- collate: { type: "string" },
48
- },
49
- },
50
- storedPrograms: { type: "boolean" },
51
- includeTables: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
52
- excludeTables: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
53
- oneFileByTable: { type: "boolean" },
54
- },
55
- });
56
- exports.sqlDumpTaskDefinition = sqlDumpTaskDefinition;
57
15
  function serializeSqlFile(input) {
58
16
  if (input.database && input.table) {
59
17
  return `${input.database}.${input.table}.table.sql`;
@@ -1,10 +1,10 @@
1
1
  import { BackupActionOptions } from "../Action/BackupAction";
2
2
  import { RestoreActionOptions } from "../Action/RestoreAction";
3
- import { PackageConfigType } from "../Config/PackageConfig";
3
+ import { PackageConfig } from "../Config/PackageConfig";
4
4
  import { PreSnapshot } from "../Repository/RepositoryAbstract";
5
5
  import { Progress } from "../utils/progress";
6
6
  type TaskCommonData = {
7
- package: PackageConfigType;
7
+ package: PackageConfig;
8
8
  snapshot: PreSnapshot;
9
9
  };
10
10
  export type TaskBackupData = TaskCommonData & {
package/lib/cli.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { OptionsMap } from "./Factory/CommandFactory";
2
+ export declare function buildArgs<TCommand extends keyof OptionsMap>(input: TCommand, options: OptionsMap[TCommand]): any[];
3
+ export declare function parseArgs(args: string[]): void;
4
+ export declare function exec<TCommand extends keyof OptionsMap>(input: TCommand, options: OptionsMap[TCommand]): Promise<void>;
@@ -0,0 +1,2 @@
1
+ declare const configSchema: any;
2
+ export { configSchema };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.configSchema = void 0;
7
+ // @ts-ignore
8
+ const config_schema_json_1 = __importDefault(require("../config.schema.json"));
9
+ const configSchema = config_schema_json_1.default;
10
+ exports.configSchema = configSchema;
package/lib/index.d.ts ADDED
@@ -0,0 +1,24 @@
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";
24
+ export { parseArgs } from "./cli";
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseArgs = exports.SnapshotsAction = exports.RestoreAction = exports.PruneAction = exports.InitAction = exports.CopyAction = exports.ConfigAction = exports.CleanCacheAction = exports.BackupAction = void 0;
4
+ var BackupAction_1 = require("./Action/BackupAction");
5
+ Object.defineProperty(exports, "BackupAction", { enumerable: true, get: function () { return BackupAction_1.BackupAction; } });
6
+ var CleanCacheAction_1 = require("./Action/CleanCacheAction");
7
+ Object.defineProperty(exports, "CleanCacheAction", { enumerable: true, get: function () { return CleanCacheAction_1.CleanCacheAction; } });
8
+ var ConfigAction_1 = require("./Action/ConfigAction");
9
+ Object.defineProperty(exports, "ConfigAction", { enumerable: true, get: function () { return ConfigAction_1.ConfigAction; } });
10
+ var CopyAction_1 = require("./Action/CopyAction");
11
+ Object.defineProperty(exports, "CopyAction", { enumerable: true, get: function () { return CopyAction_1.CopyAction; } });
12
+ var InitAction_1 = require("./Action/InitAction");
13
+ Object.defineProperty(exports, "InitAction", { enumerable: true, get: function () { return InitAction_1.InitAction; } });
14
+ var PruneAction_1 = require("./Action/PruneAction");
15
+ Object.defineProperty(exports, "PruneAction", { enumerable: true, get: function () { return PruneAction_1.PruneAction; } });
16
+ var RestoreAction_1 = require("./Action/RestoreAction");
17
+ Object.defineProperty(exports, "RestoreAction", { enumerable: true, get: function () { return RestoreAction_1.RestoreAction; } });
18
+ var SnapshotsAction_1 = require("./Action/SnapshotsAction");
19
+ Object.defineProperty(exports, "SnapshotsAction", { enumerable: true, get: function () { return SnapshotsAction_1.SnapshotsAction; } });
20
+ var cli_1 = require("./cli");
21
+ Object.defineProperty(exports, "parseArgs", { enumerable: true, get: function () { return cli_1.parseArgs; } });
@@ -1,7 +1,7 @@
1
1
  import { Streams } from "./stream";
2
2
  import { Header } from "tty-table";
3
- export type FormatType = "json" | "list" | "pjson" | "table" | "yaml" | "custom" | "tpl";
4
- export declare const dataFormats: FormatType[];
3
+ export type DataFormatType = "json" | "list" | "pjson" | "table" | "yaml" | "custom" | "tpl";
4
+ export declare const dataFormats: DataFormatType[];
5
5
  export declare class DataFormat {
6
6
  readonly options: {
7
7
  streams?: Partial<Streams>;
@@ -28,10 +28,10 @@ export declare class DataFormat {
28
28
  protected formatToYaml(): any;
29
29
  protected formatToTable(): string;
30
30
  protected formatToList(): string;
31
- log(format: FormatType, options?: {
31
+ log(format: DataFormatType, options?: {
32
32
  tpl?: Record<string, () => string>;
33
33
  }): void;
34
- format(format: FormatType, options?: {
34
+ format(format: DataFormatType, options?: {
35
35
  tpl?: Record<string, () => string>;
36
36
  }): any;
37
37
  }
@@ -8,22 +8,22 @@ export declare class Git {
8
8
  dir: string;
9
9
  log?: boolean;
10
10
  });
11
- exec(args: string[], settings?: ExecSettingsInterface, cwd?: boolean): Promise<import("./process").ExecResultType>;
11
+ exec(args: string[], settings?: ExecSettingsInterface, cwd?: boolean): Promise<import("./process").ExecResult>;
12
12
  canBeInit(repo: string): Promise<boolean>;
13
13
  clone(options: {
14
14
  repo: string;
15
15
  branch?: string;
16
16
  orphan?: boolean;
17
- }): Promise<import("./process").ExecResultType>;
17
+ }): Promise<import("./process").ExecResult>;
18
18
  checkout(options: {
19
19
  branchName: string;
20
20
  orphan?: boolean;
21
- }): Promise<import("./process").ExecResultType>;
21
+ }): Promise<import("./process").ExecResult>;
22
22
  checkBranch(options: {
23
23
  name: string;
24
24
  repo?: string;
25
25
  }): Promise<boolean>;
26
- removeAll(): Promise<import("./process").ExecResultType>;
26
+ removeAll(): Promise<import("./process").ExecResult>;
27
27
  haveChanges(): Promise<boolean>;
28
28
  fetchCommitId(tag: string): Promise<string>;
29
29
  getTags(names?: string[]): Promise<{
@@ -31,8 +31,8 @@ export declare class Git {
31
31
  message?: string | undefined;
32
32
  }[]>;
33
33
  addTag(name: string, message?: string): Promise<void>;
34
- pushTags(): Promise<import("./process").ExecResultType>;
34
+ pushTags(): Promise<import("./process").ExecResult>;
35
35
  push(options: {
36
36
  branchName: string;
37
- }): Promise<import("./process").ExecResultType>;
37
+ }): Promise<import("./process").ExecResult>;
38
38
  }
@@ -1,14 +1,14 @@
1
- import { ExecResultType, ExecSettingsInterface } from "./process";
2
- import { UriType } from "./string";
3
- export type RepositoryType = {
1
+ import { ExecResult, ExecSettingsInterface, ProcessEnv } from "./process";
2
+ import { Uri } from "./string";
3
+ export type ResticRepositoryUri = {
4
4
  name?: string;
5
- env?: Record<string, string>;
5
+ env?: ProcessEnv;
6
6
  password?: string | {
7
7
  path: string;
8
8
  };
9
9
  backend: "local" | "rest" | "sftp" | "s3" | "azure" | "gs" | "rclone";
10
- } & Omit<UriType, "password">;
11
- export type BackupStreamType = {
10
+ } & Omit<Uri, "password">;
11
+ export type ResticBackupStream = {
12
12
  message_type: "status";
13
13
  seconds_elapsed?: number;
14
14
  percent_done: number;
@@ -45,10 +45,10 @@ export declare class Restic {
45
45
  log?: boolean;
46
46
  env: Record<string, string>;
47
47
  });
48
- static formatRepository(input: RepositoryType, hidePassword?: boolean): Promise<string>;
48
+ static formatRepository(input: ResticRepositoryUri, hidePassword?: boolean): Promise<string>;
49
49
  exec(args: string[], settings?: ExecSettingsInterface, options?: {
50
50
  cwd?: string;
51
- }): Promise<ExecResultType>;
51
+ }): Promise<ExecResult>;
52
52
  checkRepository(): Promise<boolean>;
53
53
  forget(options: {
54
54
  snapshotId?: string;
@@ -89,13 +89,13 @@ export declare class Restic {
89
89
  excludeFile?: string[];
90
90
  parent?: string;
91
91
  allowEmptySnapshot?: boolean;
92
- onStream?: (data: BackupStreamType) => void;
92
+ onStream?: (data: ResticBackupStream) => void;
93
93
  createEmptyDir?: () => Promise<string>;
94
- }): Promise<ExecResultType>;
94
+ }): Promise<ExecResult>;
95
95
  copy(options: {
96
96
  id: string;
97
- onStream?: (data: BackupStreamType) => Promise<void>;
98
- }): Promise<ExecResultType>;
97
+ onStream?: (data: ResticBackupStream) => Promise<void>;
98
+ }): Promise<ExecResult>;
99
99
  restore(options: {
100
100
  id: string;
101
101
  target: string;
@@ -103,6 +103,6 @@ export declare class Restic {
103
103
  * @default 30_000
104
104
  */
105
105
  progressInterval?: number | false;
106
- onStream?: (data: BackupStreamType) => Promise<void>;
107
- }): Promise<ExecResultType>;
106
+ onStream?: (data: ResticBackupStream) => Promise<void>;
107
+ }): Promise<ExecResult>;
108
108
  }
@@ -1,36 +1,36 @@
1
- import { ConfigType } from "../../Config/Config";
2
- import type { PackageConfigType } from "../../Config/PackageConfig";
3
- import { RepositoryConfigEnabledActionType, RepositoryConfigType } from "../../Config/RepositoryConfig";
4
- export declare function findRepositoryOrFail(config: ConfigType, repositoryName: string): RepositoryConfigType;
5
- export declare function findPackageOrFail(config: ConfigType, packageName: string): PackageConfigType;
6
- export declare function ensureSameRepositoryType(a: RepositoryConfigType, b: RepositoryConfigType): void;
7
- export declare function filterRepository(repository: RepositoryConfigType, action?: RepositoryConfigEnabledActionType): boolean;
8
- export declare function filterPackages(config: ConfigType, options: {
1
+ import { Config } from "../../Config/Config";
2
+ import type { PackageConfig } from "../../Config/PackageConfig";
3
+ import { RepositoryConfigEnabledAction, RepositoryConfig } from "../../Config/RepositoryConfig";
4
+ export declare function findRepositoryOrFail(config: Config, repositoryName: string): RepositoryConfig;
5
+ export declare function findPackageOrFail(config: Config, packageName: string): PackageConfig;
6
+ export declare function ensureSameRepositoryType(a: RepositoryConfig, b: RepositoryConfig): void;
7
+ export declare function filterRepository(repository: RepositoryConfig, action?: RepositoryConfigEnabledAction): boolean;
8
+ export declare function filterPackages(config: Config, options: {
9
9
  packageNames?: string[];
10
10
  packageTaskNames?: string[];
11
11
  repositoryNames?: string[];
12
12
  repositoryTypes?: string[];
13
- sourceAction?: RepositoryConfigEnabledActionType;
14
- }): PackageConfigType[];
15
- type ResolvePackagePathParamsType = ResolvePackageParamsType & {
13
+ sourceAction?: RepositoryConfigEnabledAction;
14
+ }): PackageConfig[];
15
+ type ResolvePackagePathParams = ResolvePackageParams & {
16
16
  packageName: string;
17
17
  path: string | undefined;
18
18
  };
19
- export declare function resolvePackagePath(value: string, params: ResolvePackagePathParamsType): string;
20
- export type ResolveDatabaseNameParamsType = ResolvePackageParamsType & {
19
+ export declare function resolvePackagePath(value: string, params: ResolvePackagePathParams): string;
20
+ export type ResolveDatabaseNameParams = ResolvePackageParams & {
21
21
  packageName: string;
22
22
  database: string | undefined;
23
23
  };
24
- export declare function resolveDatabaseName(value: string, params: ResolveDatabaseNameParamsType): string;
25
- type ResolvePackageParamsType = {
24
+ export declare function resolveDatabaseName(value: string, params: ResolveDatabaseNameParams): string;
25
+ type ResolvePackageParams = {
26
26
  snapshotId: string;
27
27
  snapshotDate: string;
28
28
  action: "backup" | "restore";
29
29
  };
30
- export declare function resolvePackage(pkg: PackageConfigType, params: ResolvePackageParamsType): PackageConfigType;
31
- export declare function resolvePackages(packages: PackageConfigType[], params: ResolvePackageParamsType): PackageConfigType[];
30
+ export declare function resolvePackage(pkg: PackageConfig, params: ResolvePackageParams): PackageConfig;
31
+ export declare function resolvePackages(packages: PackageConfig[], params: ResolvePackageParams): PackageConfig[];
32
32
  export declare const pkgPathParams: {
33
- [name in "temp" | Exclude<keyof ResolvePackagePathParamsType, "path">]: string;
33
+ [name in "temp" | Exclude<keyof ResolvePackagePathParams, "path">]: string;
34
34
  };
35
35
  export declare const pkgIncludeParams: {
36
36
  action: string;
@@ -47,10 +47,10 @@ export declare const pkgExcludeParams: {
47
47
  snapshotDate: string;
48
48
  };
49
49
  export declare const pkgRestorePathParams: {
50
- [name in "temp" | keyof ResolvePackagePathParamsType]: string;
50
+ [name in "temp" | keyof ResolvePackagePathParams]: string;
51
51
  };
52
52
  export declare const dbNameParams: {
53
- [name in keyof ResolveDatabaseNameParamsType]: string;
53
+ [name in keyof ResolveDatabaseNameParams]: string;
54
54
  };
55
55
  export declare const params: {
56
56
  pkgPath: {
@@ -0,0 +1,17 @@
1
+ import { PackageConfig } from "../../Config/PackageConfig";
2
+ import { PreSnapshot } from "../../Repository/RepositoryAbstract";
3
+ import { SpawnStep } from "../spawnSteps";
4
+ export type ParsePathsOptions = {
5
+ cwd?: string;
6
+ verbose?: boolean;
7
+ data?: Record<string, any>;
8
+ tempDir?: () => Promise<string>;
9
+ };
10
+ export declare function parsePaths(values: (string | SpawnStep)[], options: ParsePathsOptions): Promise<string[]>;
11
+ export type BackupPathsOptions = {
12
+ package: PackageConfig;
13
+ snapshot: PreSnapshot;
14
+ path: string;
15
+ verbose?: boolean;
16
+ };
17
+ export declare function parseBackupPaths(paths: (string | SpawnStep)[], options: BackupPathsOptions): Promise<string[]>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseBackupPaths = exports.parsePaths = void 0;
4
- const steps_1 = require("../steps");
4
+ const spawnSteps_1 = require("../spawnSteps");
5
5
  async function parsePaths(values, options) {
6
6
  let paths = [];
7
7
  for (const value of values) {
@@ -9,7 +9,7 @@ async function parsePaths(values, options) {
9
9
  paths.push(value);
10
10
  }
11
11
  else {
12
- await (0, steps_1.runSteps)(value, {
12
+ await (0, spawnSteps_1.runSpawnSteps)(value, {
13
13
  tempDir: options.tempDir,
14
14
  verbose: options.verbose,
15
15
  onLine: (path) => paths.push(path),
@@ -23,7 +23,7 @@ async function parseBackupPaths(paths, options) {
23
23
  return parsePaths(paths, {
24
24
  cwd: options.path,
25
25
  verbose: options.verbose,
26
- vars: {
26
+ data: {
27
27
  package: options.package,
28
28
  snapshot: options.snapshot,
29
29
  path: options.path,
@@ -34,5 +34,5 @@ export declare const headerKey: {
34
34
  export declare function createDatatruckRepositoryServer(inOptions: Omit<DatatruckRepositoryServerOptions, "listen">, config?: {
35
35
  log?: boolean;
36
36
  configPath?: string;
37
- }): import("node:http").Server<typeof IncomingMessage, typeof import("node:http").ServerResponse>;
37
+ }): import("http").Server<typeof IncomingMessage, typeof import("http").ServerResponse>;
38
38
  export {};
@@ -1,7 +1,7 @@
1
1
  import { SnapshotGroupByType } from "../../Action/SnapshotsAction";
2
2
  import { Snapshot } from "../../Repository/RepositoryAbstract";
3
- import { FilterByLastOptionsType } from "../date";
4
- export declare function groupAndFilter<TSnapshot extends Snapshot>(snapshots: TSnapshot[], groupKeys?: SnapshotGroupByType[], inFilter?: FilterByLastOptionsType | ((group: TSnapshot[]) => FilterByLastOptionsType | string)): {
3
+ import { FilterByLastOptions } from "../date";
4
+ export declare function groupAndFilter<TSnapshot extends Snapshot>(snapshots: TSnapshot[], groupKeys?: SnapshotGroupByType[], inFilter?: FilterByLastOptions | ((group: TSnapshot[]) => FilterByLastOptions | string)): {
5
5
  item: TSnapshot;
6
6
  reasons: string[];
7
7
  }[];
@@ -1,4 +1,4 @@
1
- export type FilterByLastOptionsType = {
1
+ export type FilterByLastOptions = {
2
2
  last?: number;
3
3
  lastMinutely?: number;
4
4
  lastHourly?: number;
@@ -16,10 +16,10 @@ export type KeepObject = {
16
16
  keepMonthly?: number;
17
17
  keepYearly?: number;
18
18
  };
19
- export declare function createFilterByLastOptions(keep: KeepObject): FilterByLastOptionsType;
19
+ export declare function createFilterByLastOptions(keep: KeepObject): FilterByLastOptions;
20
20
  export declare function filterByLast<TItem extends {
21
21
  date: string;
22
- }>(items: TItem[], options: FilterByLastOptionsType): {
22
+ }>(items: TItem[], options: FilterByLastOptions): {
23
23
  item: TItem;
24
24
  reasons: string[];
25
25
  }[];
@@ -1,6 +1,6 @@
1
- type EventNameType = "exit" | "SIGINT" | "SIGUSR1" | "SIGUSR2" | "SIGTERM" | "uncaughtException";
2
- export declare function triggerExitEvent(eventName: EventNameType, ...args: any[]): void;
1
+ type ExitEventName = "exit" | "SIGINT" | "SIGUSR1" | "SIGUSR2" | "SIGTERM" | "uncaughtException";
2
+ export declare function triggerExitEvent(eventName: ExitEventName, ...args: any[]): void;
3
3
  export declare function enableExitEvents(): void;
4
4
  export declare function disableExitEvents(): void;
5
- export declare function onExit(cb: (eventName: EventNameType, ...args: any[]) => void, priority?: number): () => boolean;
5
+ export declare function onExit(cb: (eventName: ExitEventName, ...args: any[]) => void, priority?: number): () => boolean;
6
6
  export {};
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { ChildProcess } from "child_process";
2
3
  export type MysqlCliOptions = {
3
4
  password: string | {
@@ -14,7 +15,7 @@ export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
14
15
  options: MysqlCliOptions;
15
16
  initSharedDir: (sharedDir?: string) => Promise<string>;
16
17
  args: () => Promise<string[]>;
17
- run: (query: string, database?: string, extra?: string[], onSpawn?: ((p: ChildProcess) => void) | undefined) => Promise<import("./process").ExecResultType>;
18
+ run: (query: string, database?: string, extra?: string[], onSpawn?: ((p: ChildProcess) => void) | undefined) => Promise<import("./process").ExecResult>;
18
19
  execute: (query: string, params?: any[]) => Promise<void>;
19
20
  insert: (tableName: string, item: Record<string, any>) => Promise<void>;
20
21
  changeDatabase: (name: string) => Promise<void>;
@@ -28,14 +29,14 @@ export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
28
29
  onProgress?: ((data: {
29
30
  totalBytes: number;
30
31
  }) => void) | undefined;
31
- }) => Promise<[void, import("./process").ExecResultType]>;
32
+ }) => Promise<[void, import("./process").ExecResult]>;
32
33
  assertDumpFile: typeof assertDumpFile;
33
34
  fetchTableNames: (database: string, include?: string[], exclude?: string[]) => Promise<string[]>;
34
35
  importFile: (input: {
35
36
  path: string;
36
37
  database: string;
37
38
  onSpawn?: ((p: ChildProcess) => void) | undefined;
38
- }) => Promise<import("./process").ExecResultType>;
39
+ }) => Promise<import("./process").ExecResult>;
39
40
  isDatabaseEmpty: (database: string) => Promise<boolean>;
40
41
  createDatabase: (database: {
41
42
  name: string;
@@ -52,6 +53,6 @@ export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
52
53
  database: string;
53
54
  table: string;
54
55
  onSpawn?: ((p: ChildProcess) => void) | undefined;
55
- }) => Promise<import("./process").ExecResultType>;
56
+ }) => Promise<import("./process").ExecResult>;
56
57
  fetchVariable: (name: string) => Promise<string | undefined>;
57
58
  }>;
@@ -147,8 +147,8 @@ async function createMysqlCli(options) {
147
147
  input.database,
148
148
  "--lock-tables=false",
149
149
  "--skip-add-drop-table=false",
150
- "--fields-terminated-by=0x09",
151
- "--lines-terminated-by=0x0a",
150
+ "--fields-terminated-by=0x09", // \t
151
+ "--lines-terminated-by=0x0a", // \n
152
152
  "-T",
153
153
  input.sharedPath,
154
154
  ...(input.items || []),