@datatruck/cli 0.27.0 → 0.29.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 (151) hide show
  1. package/Action/BackupAction.d.ts +75 -34
  2. package/Action/BackupAction.js +302 -246
  3. package/Action/CleanCacheAction.d.ts +8 -4
  4. package/Action/CleanCacheAction.js +8 -5
  5. package/Action/ConfigAction.d.ts +12 -5
  6. package/Action/ConfigAction.js +14 -18
  7. package/Action/CopyAction.d.ts +51 -0
  8. package/Action/CopyAction.js +165 -0
  9. package/Action/InitAction.d.ts +3 -3
  10. package/Action/InitAction.js +9 -9
  11. package/Action/PruneAction.d.ts +10 -16
  12. package/Action/PruneAction.js +37 -34
  13. package/Action/RestoreAction.d.ts +49 -24
  14. package/Action/RestoreAction.js +164 -195
  15. package/Action/SnapshotsAction.d.ts +8 -8
  16. package/Action/SnapshotsAction.js +9 -9
  17. package/CHANGELOG.md +513 -0
  18. package/Command/BackupCommand.d.ts +7 -4
  19. package/Command/BackupCommand.js +14 -26
  20. package/Command/CleanCacheCommand.d.ts +4 -4
  21. package/Command/CleanCacheCommand.js +26 -5
  22. package/Command/CommandAbstract.d.ts +10 -7
  23. package/Command/CommandAbstract.js +4 -1
  24. package/Command/ConfigCommand.d.ts +6 -9
  25. package/Command/ConfigCommand.js +13 -8
  26. package/Command/CopyCommand.d.ts +16 -0
  27. package/Command/CopyCommand.js +66 -0
  28. package/Command/InitCommand.d.ts +4 -4
  29. package/Command/InitCommand.js +13 -17
  30. package/Command/PruneCommand.d.ts +4 -10
  31. package/Command/PruneCommand.js +13 -12
  32. package/Command/RestoreCommand.d.ts +1 -1
  33. package/Command/RestoreCommand.js +13 -21
  34. package/Command/SnapshotsCommand.d.ts +4 -4
  35. package/Command/SnapshotsCommand.js +16 -15
  36. package/Command/StartServerCommand.d.ts +3 -3
  37. package/Config/Config.d.ts +11 -0
  38. package/Config/Config.js +18 -0
  39. package/Config/PrunePolicyConfig.d.ts +2 -2
  40. package/Factory/CommandFactory.d.ts +27 -34
  41. package/Factory/CommandFactory.js +27 -54
  42. package/Factory/RepositoryFactory.d.ts +1 -1
  43. package/Factory/RepositoryFactory.js +3 -3
  44. package/Factory/TaskFactory.d.ts +1 -1
  45. package/Factory/TaskFactory.js +3 -3
  46. package/Repository/DatatruckRepository.d.ts +10 -8
  47. package/Repository/DatatruckRepository.js +47 -25
  48. package/Repository/GitRepository.d.ts +9 -8
  49. package/Repository/GitRepository.js +22 -25
  50. package/Repository/RepositoryAbstract.d.ts +39 -37
  51. package/Repository/RepositoryAbstract.js +4 -5
  52. package/Repository/ResticRepository.d.ts +9 -8
  53. package/Repository/ResticRepository.js +30 -28
  54. package/Task/GitTask.d.ts +6 -7
  55. package/Task/GitTask.js +24 -30
  56. package/Task/MariadbTask.d.ts +4 -5
  57. package/Task/MariadbTask.js +26 -32
  58. package/Task/MssqlTask.d.ts +5 -3
  59. package/Task/MssqlTask.js +11 -12
  60. package/Task/MysqlDumpTask.d.ts +10 -3
  61. package/Task/MysqlDumpTask.js +102 -32
  62. package/Task/ScriptTask.d.ts +23 -18
  63. package/Task/ScriptTask.js +34 -24
  64. package/Task/SqlDumpTaskAbstract.d.ts +8 -3
  65. package/Task/SqlDumpTaskAbstract.js +32 -20
  66. package/Task/TaskAbstract.d.ts +24 -25
  67. package/Task/TaskAbstract.js +6 -10
  68. package/cli.js +13 -5
  69. package/config.schema.json +89 -1
  70. package/package.json +4 -5
  71. package/utils/DataFormat.d.ts +23 -12
  72. package/utils/DataFormat.js +36 -14
  73. package/utils/cli.d.ts +3 -9
  74. package/utils/cli.js +19 -55
  75. package/utils/crypto.d.ts +1 -0
  76. package/utils/crypto.js +15 -0
  77. package/utils/datatruck/client.d.ts +2 -0
  78. package/utils/datatruck/client.js +3 -0
  79. package/utils/datatruck/config.d.ts +2 -0
  80. package/utils/datatruck/config.js +18 -3
  81. package/utils/datatruck/paths.d.ts +5 -9
  82. package/utils/datatruck/paths.js +2 -2
  83. package/utils/datatruck/snapshot.d.ts +5 -2
  84. package/utils/datatruck/snapshot.js +12 -22
  85. package/utils/date.d.ts +21 -4
  86. package/utils/date.js +46 -24
  87. package/utils/fs.d.ts +16 -11
  88. package/utils/fs.js +81 -48
  89. package/utils/list.d.ts +64 -0
  90. package/utils/list.js +145 -0
  91. package/utils/mysql.d.ts +2 -0
  92. package/utils/mysql.js +21 -2
  93. package/utils/process.d.ts +1 -0
  94. package/utils/process.js +24 -31
  95. package/utils/progress.d.ts +33 -0
  96. package/utils/progress.js +113 -0
  97. package/utils/steps.d.ts +11 -0
  98. package/utils/steps.js +22 -10
  99. package/utils/stream.d.ts +7 -0
  100. package/utils/stream.js +10 -0
  101. package/utils/string.d.ts +0 -1
  102. package/utils/string.js +1 -13
  103. package/utils/tar.d.ts +10 -3
  104. package/utils/tar.js +73 -45
  105. package/utils/temp.d.ts +26 -0
  106. package/utils/temp.js +133 -0
  107. package/utils/virtual-fs.d.ts +6 -2
  108. package/utils/virtual-fs.js +6 -0
  109. package/Action/BackupSessionsAction.d.ts +0 -13
  110. package/Action/BackupSessionsAction.js +0 -18
  111. package/Action/RestoreSessionsAction.d.ts +0 -13
  112. package/Action/RestoreSessionsAction.js +0 -18
  113. package/Command/BackupSessionsCommand.d.ts +0 -12
  114. package/Command/BackupSessionsCommand.js +0 -92
  115. package/Command/RestoreSessionsCommand.d.ts +0 -12
  116. package/Command/RestoreSessionsCommand.js +0 -91
  117. package/Decorator/EntityDecorator.d.ts +0 -11
  118. package/Decorator/EntityDecorator.js +0 -17
  119. package/Entity/BackupSessionEntity.d.ts +0 -6
  120. package/Entity/BackupSessionEntity.js +0 -25
  121. package/Entity/BackupSessionRepositoryEntity.d.ts +0 -6
  122. package/Entity/BackupSessionRepositoryEntity.js +0 -25
  123. package/Entity/BackupSessionTaskEntity.d.ts +0 -5
  124. package/Entity/BackupSessionTaskEntity.js +0 -24
  125. package/Entity/CrudEntityAbstract.d.ts +0 -5
  126. package/Entity/CrudEntityAbstract.js +0 -9
  127. package/Entity/RestoreSessionEntity.d.ts +0 -5
  128. package/Entity/RestoreSessionEntity.js +0 -24
  129. package/Entity/RestoreSessionRepositoryEntity.d.ts +0 -6
  130. package/Entity/RestoreSessionRepositoryEntity.js +0 -25
  131. package/Entity/RestoreSessionTaskEntity.d.ts +0 -5
  132. package/Entity/RestoreSessionTaskEntity.js +0 -24
  133. package/Entity/StateEntityAbstract.d.ts +0 -9
  134. package/Entity/StateEntityAbstract.js +0 -12
  135. package/Factory/EntityFactory.d.ts +0 -6
  136. package/Factory/EntityFactory.js +0 -40
  137. package/SessionDriver/ConsoleSessionDriver.d.ts +0 -42
  138. package/SessionDriver/ConsoleSessionDriver.js +0 -208
  139. package/SessionDriver/SessionDriverAbstract.d.ts +0 -77
  140. package/SessionDriver/SessionDriverAbstract.js +0 -28
  141. package/SessionDriver/SqliteSessionDriver.d.ts +0 -20
  142. package/SessionDriver/SqliteSessionDriver.js +0 -173
  143. package/SessionManager/BackupSessionManager.d.ts +0 -45
  144. package/SessionManager/BackupSessionManager.js +0 -218
  145. package/SessionManager/RestoreSessionManager.d.ts +0 -47
  146. package/SessionManager/RestoreSessionManager.js +0 -218
  147. package/SessionManager/SessionManagerAbstract.d.ts +0 -18
  148. package/SessionManager/SessionManagerAbstract.js +0 -36
  149. package/migrations/001-initial.sql +0 -98
  150. package/utils/entity.d.ts +0 -4
  151. package/utils/entity.js +0 -10
@@ -1,20 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ScriptTask = exports.scriptTaskDefinition = exports.scriptTaskName = exports.ScriptTaskDefinitionEnum = void 0;
3
+ exports.ScriptTask = exports.scriptTaskDefinition = exports.scriptTaskName = exports.ScriptTaskDefinitionEnum = exports.scriptTaskCode = void 0;
4
4
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
5
- const fs_1 = require("../utils/fs");
6
5
  const steps_1 = require("../utils/steps");
6
+ const temp_1 = require("../utils/temp");
7
7
  const TaskAbstract_1 = require("./TaskAbstract");
8
- const assert_1 = require("assert");
8
+ function scriptTaskCode(cb) {
9
+ return `(${cb.toString()})(...arguments);`;
10
+ }
11
+ exports.scriptTaskCode = scriptTaskCode;
9
12
  var ScriptTaskDefinitionEnum;
10
13
  (function (ScriptTaskDefinitionEnum) {
11
14
  ScriptTaskDefinitionEnum["step"] = "step";
12
15
  ScriptTaskDefinitionEnum["processStepConfig"] = "processStepConfig";
13
16
  ScriptTaskDefinitionEnum["nodeStepConfig"] = "nodeStepConfig";
17
+ ScriptTaskDefinitionEnum["telegramMessageStepConfig"] = "telegramMessageStepConfig";
14
18
  })(ScriptTaskDefinitionEnum || (exports.ScriptTaskDefinitionEnum = ScriptTaskDefinitionEnum = {}));
15
19
  const stepTypes = {
16
20
  process: ScriptTaskDefinitionEnum.processStepConfig,
17
21
  node: ScriptTaskDefinitionEnum.nodeStepConfig,
22
+ "telegram-message": ScriptTaskDefinitionEnum.telegramMessageStepConfig,
18
23
  };
19
24
  exports.scriptTaskName = "script";
20
25
  exports.scriptTaskDefinition = {
@@ -71,6 +76,15 @@ exports.scriptTaskDefinition = {
71
76
  },
72
77
  },
73
78
  },
79
+ telegramMessageStepConfig: {
80
+ type: "object",
81
+ required: ["bot", "chatId"],
82
+ properties: {
83
+ command: { type: "string" },
84
+ chatId: { type: "integer" },
85
+ text: { type: "string" },
86
+ },
87
+ },
74
88
  },
75
89
  type: "object",
76
90
  additionalProperties: false,
@@ -94,11 +108,6 @@ exports.scriptTaskDefinition = {
94
108
  };
95
109
  class ScriptTask extends TaskAbstract_1.TaskAbstract {
96
110
  verbose;
97
- async onBeforeBackup(data) {
98
- return {
99
- targetPath: data.package.path ?? (await this.mkTmpDir(`script-task_backup_target`)),
100
- };
101
- }
102
111
  getVars(data) {
103
112
  return {
104
113
  process: {
@@ -106,51 +115,52 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
106
115
  DTT_SNAPSHOT_DATE: data.snapshot.date,
107
116
  DTT_PACKAGE_NAME: data.package.name,
108
117
  DTT_PACKAGE_PATH: data.package.path,
109
- DTT_TARGET_PATH: data.targetPath,
118
+ DTT_SNAPSHOT_PATH: data.snapshotPath,
110
119
  },
111
120
  node: {
112
121
  dtt: {
113
122
  snapshot: data.snapshot,
114
123
  package: data.package,
115
- targetPath: data.targetPath,
124
+ snapshotPath: data.snapshotPath,
116
125
  },
117
126
  },
118
127
  };
119
128
  }
120
- async onBackup(data) {
129
+ async backup(data) {
121
130
  const config = this.config;
122
- const targetPath = data.targetPath;
123
- (0, assert_1.ok)(typeof targetPath === "string");
124
- const vars = this.getVars(data);
125
- await (0, fs_1.mkdirIfNotExists)(targetPath);
131
+ const snapshotPath = data.package.path ??
132
+ (await (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "snapshot"));
133
+ const vars = this.getVars({
134
+ ...data,
135
+ snapshotPath,
136
+ });
126
137
  await (0, steps_1.runSteps)(config.backupSteps, {
127
138
  env: config.env,
139
+ cwd: snapshotPath,
128
140
  verbose: data.options.verbose,
129
141
  process: { vars: vars.process },
130
142
  node: {
131
- tempDir: () => this.mkTmpDir("script-task_backup_node-step"),
143
+ tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "nodeStep"),
132
144
  vars: vars.node,
133
145
  },
134
146
  });
147
+ return { snapshotPath };
135
148
  }
136
- async onBeforeRestore(data) {
149
+ async prepareRestore(data) {
137
150
  return {
138
- targetPath: data.package.restorePath ??
139
- (await this.mkTmpDir(`script-task_restore_target`)),
151
+ snapshotPath: data.package.restorePath ??
152
+ (await (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "restore", "snapshot")),
140
153
  };
141
154
  }
142
- async onRestore(data) {
155
+ async restore(data) {
143
156
  const config = this.config;
144
- const targetPath = data.targetPath;
145
- (0, assert_1.ok)(typeof targetPath === "string");
146
- await (0, fs_1.mkdirIfNotExists)(targetPath);
147
157
  const vars = this.getVars(data);
148
158
  await (0, steps_1.runSteps)(config.restoreSteps, {
149
159
  env: config.env,
150
160
  verbose: data.options.verbose,
151
161
  process: { vars: vars.process },
152
162
  node: {
153
- tempDir: () => this.mkTmpDir("script-task_restore_node-step"),
163
+ tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "restore", "nodeStep"),
154
164
  vars: vars.node,
155
165
  },
156
166
  });
@@ -1,5 +1,5 @@
1
1
  import { exec } from "../utils/process";
2
- import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
2
+ import { TaskBackupData, TaskPrepareRestoreData, TaskRestoreData, TaskAbstract } from "./TaskAbstract";
3
3
  import { JSONSchema7, JSONSchema7Definition } from "json-schema";
4
4
  export type TargetDatabaseType = {
5
5
  name: string;
@@ -37,6 +37,11 @@ export declare abstract class SqlDumpTaskAbstract<TConfig extends SqlDumpTaskCon
37
37
  }) => void): Promise<void>;
38
38
  abstract onExportStoredPrograms(output: string): Promise<void>;
39
39
  abstract onImport(path: string, database: string): Promise<void>;
40
- onBackup(data: BackupDataType): Promise<void>;
41
- onRestore(data: RestoreDataType): Promise<void>;
40
+ backup(data: TaskBackupData): Promise<{
41
+ snapshotPath: string;
42
+ }>;
43
+ prepareRestore(data: TaskPrepareRestoreData): Promise<{
44
+ snapshotPath: string;
45
+ }>;
46
+ restore(data: TaskRestoreData): Promise<void>;
42
47
  }
@@ -7,6 +7,7 @@ const cli_1 = require("../utils/cli");
7
7
  const config_1 = require("../utils/datatruck/config");
8
8
  const fs_1 = require("../utils/fs");
9
9
  const math_1 = require("../utils/math");
10
+ const temp_1 = require("../utils/temp");
10
11
  const TaskAbstract_1 = require("./TaskAbstract");
11
12
  const assert_1 = require("assert");
12
13
  const promises_1 = require("fs/promises");
@@ -104,10 +105,13 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
104
105
  return result;
105
106
  }, []);
106
107
  }
107
- async onBackup(data) {
108
+ async backup(data) {
108
109
  this.verbose = data.options.verbose;
110
+ const snapshotPath = data.package.path ??
111
+ (await (0, temp_1.mkTmpDir)("sqldump", "task", "backup", "snapshot"));
112
+ await (0, fs_1.mkdirIfNotExists)(snapshotPath);
113
+ await (0, fs_1.ensureEmptyDir)(snapshotPath);
109
114
  const config = this.config;
110
- const outputPath = data.package.path;
111
115
  const allTableNames = await this.onFetchTableNames(this.config.database);
112
116
  const tableNames = allTableNames.filter((tableName) => {
113
117
  if (config.includeTables && !(0, micromatch_1.isMatch)(tableName, config.includeTables))
@@ -116,18 +120,18 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
116
120
  return false;
117
121
  return true;
118
122
  });
119
- (0, assert_1.ok)(typeof outputPath === "string");
120
- if (!(await (0, fs_1.existsDir)(outputPath)))
121
- await (0, promises_1.mkdir)(outputPath, { recursive: true });
123
+ (0, assert_1.ok)(typeof snapshotPath === "string");
124
+ if (!(await (0, fs_1.existsDir)(snapshotPath)))
125
+ await (0, promises_1.mkdir)(snapshotPath, { recursive: true });
122
126
  if (!this.config.oneFileByTable) {
123
- const outPath = (0, path_1.join)(outputPath, serializeSqlFile({ database: this.config.database }));
124
- await data.onProgress({
127
+ const outPath = (0, path_1.join)(snapshotPath, serializeSqlFile({ database: this.config.database }));
128
+ data.onProgress({
125
129
  relative: {
126
130
  description: "Exporting",
127
131
  },
128
132
  });
129
133
  await this.onExportTables(tableNames, outPath, async (progress) => {
130
- await data.onProgress({
134
+ data.onProgress({
131
135
  absolute: {
132
136
  description: "Exporting in single file",
133
137
  current: progress.totalBytes,
@@ -139,7 +143,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
139
143
  else {
140
144
  let current = 0;
141
145
  for (const tableName of tableNames) {
142
- await data.onProgress({
146
+ data.onProgress({
143
147
  relative: {
144
148
  description: "Exporting",
145
149
  payload: tableName,
@@ -150,9 +154,9 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
150
154
  percent: (0, math_1.progressPercent)(tableNames.length, current),
151
155
  },
152
156
  });
153
- const outPath = (0, path_1.join)(outputPath, serializeSqlFile({ table: tableName }));
157
+ const outPath = (0, path_1.join)(snapshotPath, serializeSqlFile({ table: tableName }));
154
158
  await this.onExportTables([tableName], outPath, async (progress) => {
155
- await data.onProgress({
159
+ data.onProgress({
156
160
  relative: {
157
161
  description: "Exporting",
158
162
  payload: tableName,
@@ -170,19 +174,27 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
170
174
  }
171
175
  }
172
176
  if (this.config.storedPrograms) {
173
- const outPath = (0, path_1.join)(outputPath, "stored-programs.sql");
174
- await data.onProgress({
177
+ const outPath = (0, path_1.join)(snapshotPath, "stored-programs.sql");
178
+ data.onProgress({
175
179
  relative: {
176
180
  description: "Exporting storaged programs",
177
181
  },
178
182
  });
179
183
  await this.onExportStoredPrograms(outPath);
180
184
  }
185
+ return {
186
+ snapshotPath: snapshotPath,
187
+ };
188
+ }
189
+ async prepareRestore(data) {
190
+ return {
191
+ snapshotPath: data.package.restorePath ??
192
+ (await (0, temp_1.mkTmpDir)("sqldump", "task", "restore", "snapshot")),
193
+ };
181
194
  }
182
- async onRestore(data) {
183
- const restorePath = data.package.restorePath;
195
+ async restore(data) {
196
+ const snapshotPath = data.snapshotPath;
184
197
  this.verbose = data.options.verbose;
185
- (0, assert_1.ok)(typeof restorePath === "string");
186
198
  const database = {
187
199
  name: (0, config_1.resolveDatabaseName)(this.config.database, {
188
200
  packageName: data.package.name,
@@ -192,7 +204,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
192
204
  database: undefined,
193
205
  }),
194
206
  };
195
- if (this.config.targetDatabase && data.options.restorePath) {
207
+ if (this.config.targetDatabase && !data.options.initial) {
196
208
  database.name = (0, config_1.resolveDatabaseName)(this.config.targetDatabase.name, {
197
209
  packageName: data.package.name,
198
210
  snapshotId: data.options.snapshotId,
@@ -201,7 +213,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
201
213
  database: database.name,
202
214
  });
203
215
  }
204
- const items = (await (0, fs_1.readDir)(restorePath))
216
+ const items = (await (0, fs_1.readDir)(snapshotPath))
205
217
  .map(parseSqlFile)
206
218
  .filter((v) => !!v);
207
219
  // Database check
@@ -219,10 +231,10 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
219
231
  }
220
232
  await this.onCreateDatabase(database);
221
233
  if (this.verbose)
222
- (0, cli_1.logExec)("readdir", [restorePath]);
234
+ (0, cli_1.logExec)("readdir", [snapshotPath]);
223
235
  let current = 0;
224
236
  for (const item of items) {
225
- const path = (0, path_1.join)(restorePath, item.fileName);
237
+ const path = (0, path_1.join)(snapshotPath, item.fileName);
226
238
  data.onProgress({
227
239
  relative: {
228
240
  description: "Importing",
@@ -1,34 +1,33 @@
1
- import { BackupActionOptionsType } from "../Action/BackupAction";
2
- import { RestoreActionOptionsType } from "../Action/RestoreAction";
1
+ import { BackupActionOptions } from "../Action/BackupAction";
2
+ import { RestoreActionOptions } from "../Action/RestoreAction";
3
3
  import { PackageConfigType } from "../Config/PackageConfig";
4
- import { SnapshotType } from "../Repository/RepositoryAbstract";
4
+ import { PreSnapshot } from "../Repository/RepositoryAbstract";
5
5
  import { Progress } from "../utils/progress";
6
- export type BackupDataType = {
7
- onProgress: (data: Progress) => Promise<void>;
8
- options: BackupActionOptionsType;
6
+ type TaskCommonData = {
9
7
  package: PackageConfigType;
10
- targetPath: string | undefined;
11
- snapshot: SnapshotType;
8
+ snapshot: PreSnapshot;
12
9
  };
13
- export type BeforeBackupDataType = Omit<BackupDataType, "onProgress" | "targetPath">;
14
- export type RestoreDataType = {
15
- onProgress: (data: Progress) => Promise<void>;
16
- options: RestoreActionOptionsType;
17
- package: PackageConfigType;
18
- targetPath: string | undefined;
19
- snapshot: SnapshotType;
10
+ export type TaskBackupData = TaskCommonData & {
11
+ onProgress: (data: Progress) => void;
12
+ options: BackupActionOptions;
13
+ snapshotPath?: string;
14
+ };
15
+ export type TaskRestoreData = TaskCommonData & {
16
+ onProgress: (data: Progress) => void;
17
+ options: RestoreActionOptions;
18
+ snapshotPath: string;
19
+ };
20
+ export type TaskPrepareRestoreData = TaskCommonData & {
21
+ options: RestoreActionOptions;
20
22
  };
21
- export type BeforeRestoreDataType = Omit<RestoreDataType, "onProgress" | "targetPath">;
22
- export type BeforeReturn = Promise<{
23
- targetPath?: string;
24
- } | undefined | void>;
23
+ export type TaskReturn = Promise<{
24
+ snapshotPath?: string;
25
+ } | undefined>;
25
26
  export declare abstract class TaskAbstract<TConfig = any> {
26
27
  readonly config: TConfig;
27
- readonly tmpDirs: string[];
28
28
  constructor(config: TConfig);
29
- mkTmpDir(prefix: string, id?: string): Promise<string>;
30
- onBeforeBackup(data: BeforeBackupDataType): BeforeReturn;
31
- onBackup(data: BackupDataType): Promise<void>;
32
- onBeforeRestore(data: BeforeRestoreDataType): BeforeReturn;
33
- onRestore(data: RestoreDataType): Promise<void>;
29
+ backup(data: TaskBackupData): TaskReturn;
30
+ prepareRestore(data: TaskPrepareRestoreData): TaskReturn;
31
+ restore(data: TaskRestoreData): Promise<void>;
34
32
  }
33
+ export {};
@@ -1,21 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TaskAbstract = void 0;
4
- const fs_1 = require("../utils/fs");
5
4
  class TaskAbstract {
6
5
  config;
7
- tmpDirs = [];
8
6
  constructor(config) {
9
7
  this.config = config;
10
8
  }
11
- async mkTmpDir(prefix, id) {
12
- const dir = await (0, fs_1.mkTmpDir)(prefix, id);
13
- this.tmpDirs.push(dir);
14
- return dir;
9
+ async backup(data) {
10
+ return;
15
11
  }
16
- async onBeforeBackup(data) { }
17
- async onBackup(data) { }
18
- async onBeforeRestore(data) { }
19
- async onRestore(data) { }
12
+ async prepareRestore(data) {
13
+ return;
14
+ }
15
+ async restore(data) { }
20
16
  }
21
17
  exports.TaskAbstract = TaskAbstract;
package/cli.js CHANGED
@@ -12,12 +12,20 @@ const cli_1 = require("./utils/cli");
12
12
  const fs_1 = require("./utils/fs");
13
13
  const process_1 = require("./utils/process");
14
14
  const string_1 = require("./utils/string");
15
+ const temp_1 = require("./utils/temp");
15
16
  const chalk_1 = require("chalk");
16
17
  const commander_1 = require("commander");
17
18
  const fs_2 = require("fs");
18
19
  const path_1 = require("path");
19
20
  function getGlobalOptions() {
20
- return program.opts();
21
+ const result = program.opts();
22
+ return {
23
+ ...result,
24
+ tty: result.tty === "auto" ? "auto" : result.tty === "true",
25
+ progress: result.progress === "auto" || result.progress === "interval"
26
+ ? result.progress
27
+ : result.progress === "true",
28
+ };
21
29
  }
22
30
  function makeCommand(command) {
23
31
  const programCommand = program.command(command);
@@ -80,7 +88,8 @@ program.description(description);
80
88
  program.usage("dtt");
81
89
  program.option("-v,--verbose", "Verbose", (_, previous) => previous + 1, 0);
82
90
  program.option("-c,--config <path>", "Config path", process.env["DATATRUCK_CONFIG"] ?? (cwd.endsWith(path_1.sep) ? cwd : `${cwd}${path_1.sep}`));
83
- program.option("--progress <value>", "Progress type (auto, plain, tty)", "auto");
91
+ program.option("--tty <value>", "TTY mode (auto, true, false)", "auto");
92
+ program.option("--progress <value>", "Progress type (auto, true, false, interval)", "auto");
84
93
  program.option("--progress-interval <ms>", "Progress interval", Number, 1000);
85
94
  program.option("-o,--output-format <format>", "Output format (json, pjson, yaml, table, custom=$, tpl=name)", "table");
86
95
  makeCommand(CommandFactory_1.CommandEnum.startServer).alias("start");
@@ -89,9 +98,8 @@ makeCommand(CommandFactory_1.CommandEnum.init).alias("i");
89
98
  makeCommand(CommandFactory_1.CommandEnum.snapshots).alias("s");
90
99
  makeCommand(CommandFactory_1.CommandEnum.prune).alias("p");
91
100
  makeCommand(CommandFactory_1.CommandEnum.backup).alias("b");
92
- makeCommand(CommandFactory_1.CommandEnum.backupSessions).alias("bs");
93
101
  makeCommand(CommandFactory_1.CommandEnum.restore).alias("r");
94
- makeCommand(CommandFactory_1.CommandEnum.restoreSessions).alias("rs");
102
+ makeCommand(CommandFactory_1.CommandEnum.copy).alias("cp");
95
103
  makeCommand(CommandFactory_1.CommandEnum.cleanCache).alias("cc");
96
104
  function buildArgs(input, options) {
97
105
  const optionsArray = Object.keys(options).flatMap((name) => [
@@ -113,7 +121,7 @@ function parseArgs(args) {
113
121
  }
114
122
  if (!verbose)
115
123
  try {
116
- (0, fs_2.rmSync)((0, fs_1.sessionTmpDir)(), {
124
+ (0, fs_2.rmSync)((0, temp_1.sessionTmpDir)(), {
117
125
  force: true,
118
126
  recursive: true,
119
127
  maxRetries: 5,
@@ -902,6 +902,16 @@
902
902
  "csvSharedPath": {
903
903
  "type": "string"
904
904
  },
905
+ "compress": {
906
+ "anyOf": [
907
+ {
908
+ "type": "boolean"
909
+ },
910
+ {
911
+ "$ref": "#/definitions/compress-util"
912
+ }
913
+ ]
914
+ },
905
915
  "password": {
906
916
  "anyOf": [
907
917
  {
@@ -985,6 +995,43 @@
985
995
  "tempDir": {
986
996
  "type": "string"
987
997
  },
998
+ "minFreeDiskSpace": {
999
+ "anyOf": [
1000
+ {
1001
+ "type": "integer"
1002
+ },
1003
+ {
1004
+ "type": "string"
1005
+ }
1006
+ ]
1007
+ },
1008
+ "reports": {
1009
+ "type": "array",
1010
+ "items": {
1011
+ "type": "object",
1012
+ "additionalProperties": false,
1013
+ "properties": {
1014
+ "when": {
1015
+ "enum": [
1016
+ "success",
1017
+ "error"
1018
+ ]
1019
+ },
1020
+ "format": {
1021
+ "enum": [
1022
+ "json",
1023
+ "list",
1024
+ "pjson",
1025
+ "table",
1026
+ "yaml"
1027
+ ]
1028
+ },
1029
+ "run": {
1030
+ "$ref": "#/definitions/script-task_step"
1031
+ }
1032
+ }
1033
+ }
1034
+ },
988
1035
  "repositories": {
989
1036
  "type": "array",
990
1037
  "items": {
@@ -1032,6 +1079,9 @@
1032
1079
  }
1033
1080
  }
1034
1081
  }
1082
+ },
1083
+ "prunePolicy": {
1084
+ "$ref": "#/definitions/prune-policy"
1035
1085
  }
1036
1086
  }
1037
1087
  },
@@ -1111,7 +1161,8 @@
1111
1161
  "type": {
1112
1162
  "enum": [
1113
1163
  "process",
1114
- "node"
1164
+ "node",
1165
+ "telegram-message"
1115
1166
  ]
1116
1167
  },
1117
1168
  "config": {}
@@ -1154,6 +1205,25 @@
1154
1205
  }
1155
1206
  },
1156
1207
  "else": false
1208
+ },
1209
+ {
1210
+ "if": {
1211
+ "type": "object",
1212
+ "properties": {
1213
+ "type": {
1214
+ "const": "telegram-message"
1215
+ }
1216
+ }
1217
+ },
1218
+ "then": {
1219
+ "type": "object",
1220
+ "properties": {
1221
+ "config": {
1222
+ "$ref": "#/definitions/script-task_telegramMessageStepConfig"
1223
+ }
1224
+ }
1225
+ },
1226
+ "else": false
1157
1227
  }
1158
1228
  ]
1159
1229
  },
@@ -1210,6 +1280,24 @@
1210
1280
  }
1211
1281
  }
1212
1282
  }
1283
+ },
1284
+ "script-task_telegramMessageStepConfig": {
1285
+ "type": "object",
1286
+ "required": [
1287
+ "bot",
1288
+ "chatId"
1289
+ ],
1290
+ "properties": {
1291
+ "command": {
1292
+ "type": "string"
1293
+ },
1294
+ "chatId": {
1295
+ "type": "integer"
1296
+ },
1297
+ "text": {
1298
+ "type": "string"
1299
+ }
1300
+ }
1213
1301
  }
1214
1302
  },
1215
1303
  "$ref": "#/definitions/config"
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "dependencies": {
5
5
  "@supercharge/promise-pool": "^3.1.0",
6
6
  "ajv": "^8.12.0",
7
7
  "async": "^3.2.4",
8
+ "bytes": "^3.1.2",
8
9
  "chalk": "^4.1.2",
9
- "cli-table3": "^0.6.3",
10
10
  "commander": "^11.0.0",
11
11
  "dayjs": "^1.11.10",
12
12
  "fast-folder-size": "^2.2.0",
13
13
  "fast-glob": "^3.3.1",
14
+ "listr2": "^7.0.1",
14
15
  "micromatch": "^4.0.5",
15
16
  "mysql2": "^3.6.1",
16
- "pretty-bytes": "^5.6.0",
17
- "sqlite": "^5.0.1",
18
- "sqlite3": "^5.1.6"
17
+ "tty-table": "^4.2.2"
19
18
  },
20
19
  "optionalDependencies": {
21
20
  "ts-node": "^10.9.1",
@@ -1,25 +1,36 @@
1
- export type FormatType = "json" | "pjson" | "table" | "yaml" | "custom" | "tpl";
2
- export declare class DataFormat<TItem extends Record<string, unknown>> {
1
+ import { Streams } from "./stream";
2
+ import { Header } from "tty-table";
3
+ export type FormatType = "json" | "list" | "pjson" | "table" | "yaml" | "custom" | "tpl";
4
+ export declare const dataFormats: FormatType[];
5
+ export declare class DataFormat {
3
6
  readonly options: {
4
- items: TItem[];
5
- json?: (item: TItem) => any;
6
- table: {
7
- labels: string[];
8
- handler: (item: TItem) => (string | number | null | undefined)[];
7
+ streams?: Partial<Streams>;
8
+ json: any;
9
+ list?: () => string[];
10
+ table?: {
11
+ headers: Header[];
12
+ rows: () => (string | number | null | undefined)[][];
9
13
  };
10
14
  };
15
+ protected streams: Streams;
11
16
  constructor(options: {
12
- items: TItem[];
13
- json?: (item: TItem) => any;
14
- table: {
15
- labels: string[];
16
- handler: (item: TItem) => (string | number | null | undefined)[];
17
+ streams?: Partial<Streams>;
18
+ json: any;
19
+ list?: () => string[];
20
+ table?: {
21
+ headers: Header[];
22
+ rows: () => (string | number | null | undefined)[][];
17
23
  };
18
24
  });
25
+ protected getJson(): any;
19
26
  protected formatToJson(): string;
20
27
  protected formatToPrettyJson(): string;
21
28
  protected formatToYaml(): any;
22
29
  protected formatToTable(): string;
30
+ protected formatToList(): string;
31
+ log(format: FormatType, options?: {
32
+ tpl?: Record<string, () => string>;
33
+ }): void;
23
34
  format(format: FormatType, options?: {
24
35
  tpl?: Record<string, () => string>;
25
36
  }): any;