@datatruck/cli 0.27.0 → 0.28.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 (147) hide show
  1. package/Action/BackupAction.d.ts +69 -34
  2. package/Action/BackupAction.js +284 -244
  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 +49 -0
  8. package/Action/CopyAction.js +144 -0
  9. package/Action/InitAction.d.ts +3 -3
  10. package/Action/InitAction.js +9 -9
  11. package/Action/PruneAction.d.ts +9 -9
  12. package/Action/PruneAction.js +39 -23
  13. package/Action/RestoreAction.d.ts +48 -23
  14. package/Action/RestoreAction.js +158 -195
  15. package/Action/SnapshotsAction.d.ts +8 -8
  16. package/Action/SnapshotsAction.js +8 -8
  17. package/CHANGELOG.md +495 -0
  18. package/Command/BackupCommand.d.ts +6 -4
  19. package/Command/BackupCommand.js +9 -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 +15 -0
  27. package/Command/CopyCommand.js +61 -0
  28. package/Command/InitCommand.d.ts +4 -4
  29. package/Command/InitCommand.js +11 -15
  30. package/Command/PruneCommand.d.ts +3 -3
  31. package/Command/PruneCommand.js +13 -12
  32. package/Command/RestoreCommand.js +9 -17
  33. package/Command/SnapshotsCommand.d.ts +4 -4
  34. package/Command/SnapshotsCommand.js +16 -15
  35. package/Command/StartServerCommand.d.ts +3 -3
  36. package/Config/Config.d.ts +9 -0
  37. package/Config/Config.js +17 -0
  38. package/Config/PrunePolicyConfig.d.ts +2 -2
  39. package/Factory/CommandFactory.d.ts +27 -34
  40. package/Factory/CommandFactory.js +27 -54
  41. package/Factory/RepositoryFactory.d.ts +1 -1
  42. package/Factory/RepositoryFactory.js +3 -3
  43. package/Factory/TaskFactory.d.ts +1 -1
  44. package/Factory/TaskFactory.js +3 -3
  45. package/Repository/DatatruckRepository.d.ts +9 -8
  46. package/Repository/DatatruckRepository.js +42 -25
  47. package/Repository/GitRepository.d.ts +9 -8
  48. package/Repository/GitRepository.js +22 -25
  49. package/Repository/RepositoryAbstract.d.ts +39 -37
  50. package/Repository/RepositoryAbstract.js +4 -5
  51. package/Repository/ResticRepository.d.ts +9 -8
  52. package/Repository/ResticRepository.js +30 -28
  53. package/Task/GitTask.d.ts +6 -7
  54. package/Task/GitTask.js +24 -30
  55. package/Task/MariadbTask.d.ts +4 -5
  56. package/Task/MariadbTask.js +26 -32
  57. package/Task/MssqlTask.d.ts +5 -3
  58. package/Task/MssqlTask.js +11 -12
  59. package/Task/MysqlDumpTask.d.ts +10 -3
  60. package/Task/MysqlDumpTask.js +107 -31
  61. package/Task/ScriptTask.d.ts +23 -18
  62. package/Task/ScriptTask.js +34 -24
  63. package/Task/SqlDumpTaskAbstract.d.ts +8 -3
  64. package/Task/SqlDumpTaskAbstract.js +31 -19
  65. package/Task/TaskAbstract.d.ts +24 -25
  66. package/Task/TaskAbstract.js +6 -10
  67. package/cli.js +13 -5
  68. package/config.schema.json +86 -1
  69. package/package.json +4 -5
  70. package/utils/DataFormat.d.ts +23 -12
  71. package/utils/DataFormat.js +36 -14
  72. package/utils/cli.d.ts +2 -9
  73. package/utils/cli.js +9 -52
  74. package/utils/datatruck/client.d.ts +2 -0
  75. package/utils/datatruck/client.js +3 -0
  76. package/utils/datatruck/config.d.ts +2 -0
  77. package/utils/datatruck/config.js +18 -3
  78. package/utils/datatruck/paths.d.ts +5 -9
  79. package/utils/datatruck/paths.js +2 -2
  80. package/utils/datatruck/snapshot.d.ts +2 -2
  81. package/utils/date.d.ts +7 -3
  82. package/utils/date.js +22 -14
  83. package/utils/fs.d.ts +16 -11
  84. package/utils/fs.js +81 -48
  85. package/utils/list.d.ts +64 -0
  86. package/utils/list.js +145 -0
  87. package/utils/mysql.d.ts +2 -0
  88. package/utils/mysql.js +21 -2
  89. package/utils/process.d.ts +1 -0
  90. package/utils/process.js +24 -31
  91. package/utils/progress.d.ts +33 -0
  92. package/utils/progress.js +113 -0
  93. package/utils/steps.d.ts +11 -0
  94. package/utils/steps.js +22 -10
  95. package/utils/stream.d.ts +7 -0
  96. package/utils/stream.js +10 -0
  97. package/utils/string.d.ts +0 -1
  98. package/utils/string.js +1 -13
  99. package/utils/tar.d.ts +10 -3
  100. package/utils/tar.js +70 -44
  101. package/utils/temp.d.ts +26 -0
  102. package/utils/temp.js +133 -0
  103. package/utils/virtual-fs.d.ts +6 -2
  104. package/utils/virtual-fs.js +6 -0
  105. package/Action/BackupSessionsAction.d.ts +0 -13
  106. package/Action/BackupSessionsAction.js +0 -18
  107. package/Action/RestoreSessionsAction.d.ts +0 -13
  108. package/Action/RestoreSessionsAction.js +0 -18
  109. package/Command/BackupSessionsCommand.d.ts +0 -12
  110. package/Command/BackupSessionsCommand.js +0 -92
  111. package/Command/RestoreSessionsCommand.d.ts +0 -12
  112. package/Command/RestoreSessionsCommand.js +0 -91
  113. package/Decorator/EntityDecorator.d.ts +0 -11
  114. package/Decorator/EntityDecorator.js +0 -17
  115. package/Entity/BackupSessionEntity.d.ts +0 -6
  116. package/Entity/BackupSessionEntity.js +0 -25
  117. package/Entity/BackupSessionRepositoryEntity.d.ts +0 -6
  118. package/Entity/BackupSessionRepositoryEntity.js +0 -25
  119. package/Entity/BackupSessionTaskEntity.d.ts +0 -5
  120. package/Entity/BackupSessionTaskEntity.js +0 -24
  121. package/Entity/CrudEntityAbstract.d.ts +0 -5
  122. package/Entity/CrudEntityAbstract.js +0 -9
  123. package/Entity/RestoreSessionEntity.d.ts +0 -5
  124. package/Entity/RestoreSessionEntity.js +0 -24
  125. package/Entity/RestoreSessionRepositoryEntity.d.ts +0 -6
  126. package/Entity/RestoreSessionRepositoryEntity.js +0 -25
  127. package/Entity/RestoreSessionTaskEntity.d.ts +0 -5
  128. package/Entity/RestoreSessionTaskEntity.js +0 -24
  129. package/Entity/StateEntityAbstract.d.ts +0 -9
  130. package/Entity/StateEntityAbstract.js +0 -12
  131. package/Factory/EntityFactory.d.ts +0 -6
  132. package/Factory/EntityFactory.js +0 -40
  133. package/SessionDriver/ConsoleSessionDriver.d.ts +0 -42
  134. package/SessionDriver/ConsoleSessionDriver.js +0 -208
  135. package/SessionDriver/SessionDriverAbstract.d.ts +0 -77
  136. package/SessionDriver/SessionDriverAbstract.js +0 -28
  137. package/SessionDriver/SqliteSessionDriver.d.ts +0 -20
  138. package/SessionDriver/SqliteSessionDriver.js +0 -173
  139. package/SessionManager/BackupSessionManager.d.ts +0 -45
  140. package/SessionManager/BackupSessionManager.js +0 -218
  141. package/SessionManager/RestoreSessionManager.d.ts +0 -47
  142. package/SessionManager/RestoreSessionManager.js +0 -218
  143. package/SessionManager/SessionManagerAbstract.d.ts +0 -18
  144. package/SessionManager/SessionManagerAbstract.js +0 -36
  145. package/migrations/001-initial.sql +0 -98
  146. package/utils/entity.d.ts +0 -4
  147. package/utils/entity.js +0 -10
@@ -1,17 +1,22 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.RestoreAction = void 0;
4
- const AppError_1 = require("../Error/AppError");
5
7
  const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
6
8
  const TaskFactory_1 = require("../Factory/TaskFactory");
9
+ const DataFormat_1 = require("../utils/DataFormat");
7
10
  const cli_1 = require("../utils/cli");
8
11
  const config_1 = require("../utils/datatruck/config");
12
+ const date_1 = require("../utils/date");
9
13
  const fs_1 = require("../utils/fs");
10
- const object_1 = require("../utils/object");
11
- const process_1 = require("../utils/process");
14
+ const list_1 = require("../utils/list");
15
+ const progress_1 = require("../utils/progress");
16
+ const temp_1 = require("../utils/temp");
12
17
  const SnapshotsAction_1 = require("./SnapshotsAction");
13
18
  const assert_1 = require("assert");
14
- const os_1 = require("os");
19
+ const chalk_1 = __importDefault(require("chalk"));
15
20
  class RestoreAction {
16
21
  config;
17
22
  options;
@@ -21,36 +26,6 @@ class RestoreAction {
21
26
  this.config = config;
22
27
  this.options = options;
23
28
  }
24
- assocConfigs(packages, snapshots) {
25
- return snapshots.map((snapshot) => {
26
- const pkg = packages.find((pkg) => pkg.name === snapshot.packageName) ?? null;
27
- return [snapshot, pkg];
28
- });
29
- }
30
- async init(session, snapshotId, snapshots) {
31
- await session.initDrivers();
32
- for (const [snapshot, pkg] of snapshots) {
33
- if (!pkg)
34
- throw new AppError_1.AppError(`Package config not found: ${snapshot.packageName}`);
35
- const sessionId = await session.init({
36
- snapshotId: snapshotId,
37
- packageName: pkg.name,
38
- });
39
- if (pkg.task)
40
- await session.initTask({
41
- sessionId: sessionId,
42
- taskName: pkg.task.name,
43
- });
44
- for (const repositoryName of pkg.repositoryNames ?? []) {
45
- const repo = (0, config_1.findRepositoryOrFail)(this.config, repositoryName);
46
- await session.initRepository({
47
- sessionId: sessionId,
48
- repositoryName: repositoryName,
49
- repositoryType: repo.type,
50
- });
51
- }
52
- }
53
- }
54
29
  async findSnapshots() {
55
30
  const result = [];
56
31
  for (const repository of this.config.repositories) {
@@ -90,178 +65,166 @@ class RestoreAction {
90
65
  return true;
91
66
  });
92
67
  }
93
- async task(session, pkg, task, snapshot, targetPath) {
94
- const taskId = session.findTaskId({
95
- packageName: pkg.name,
96
- taskName: pkg.task.name,
97
- });
98
- await session.startTask({
99
- id: taskId,
100
- });
101
- let error;
102
- if (this.repoErrors[pkg.name]?.length) {
103
- error = AppError_1.AppError.create("Repository failed", this.repoErrors[pkg.name]);
104
- }
105
- else if (this.taskErrors[pkg.name]?.length) {
106
- error = AppError_1.AppError.create("Previous task failed", this.taskErrors[pkg.name]);
107
- }
108
- else {
109
- try {
110
- await task.onRestore({
111
- package: pkg,
68
+ async restore(data) {
69
+ let { snapshot, pkg, task } = data;
70
+ const repoConfig = (0, config_1.findRepositoryOrFail)(this.config, snapshot.repositoryName);
71
+ const repo = (0, RepositoryFactory_1.createRepo)(repoConfig);
72
+ if (!this.options.restorePath)
73
+ pkg = { ...pkg, restorePath: pkg.path };
74
+ let snapshotPath = pkg.restorePath ?? pkg.path;
75
+ await data.gc.cleanupIfFail(async () => {
76
+ if (task) {
77
+ const taskResult = await task.prepareRestore({
112
78
  options: this.options,
79
+ package: pkg,
113
80
  snapshot,
114
- targetPath,
115
- onProgress: async (progress) => {
116
- await session.progressTask({
117
- id: taskId,
118
- progress,
119
- });
120
- },
121
81
  });
82
+ snapshotPath = taskResult?.snapshotPath;
122
83
  }
123
- catch (_) {
124
- if (!this.taskErrors[pkg.name])
125
- this.taskErrors[pkg.name] = [];
126
- this.taskErrors[pkg.name].push((error = _));
127
- }
128
- }
129
- await session.endTask({
130
- id: taskId,
131
- error: error?.stack,
132
- });
133
- return {
134
- error: error ? false : true,
135
- tmpDirs: task?.tmpDirs ?? [],
136
- };
137
- }
138
- async restore(session, pkg, repo, snapshot, targetPath) {
139
- const repositoryId = session.findRepositoryId({
140
- packageName: pkg.name,
141
- repositoryName: repo.name,
142
- });
143
- await session.startRepository({
144
- id: repositoryId,
145
- });
146
- let repoError;
147
- let repoInstance;
148
- if (!this.options.restorePath)
149
- pkg = {
150
- ...pkg,
151
- restorePath: pkg.path,
152
- };
153
- try {
154
- if (typeof pkg.restorePath !== "string")
155
- throw new AppError_1.AppError("Restore path is not defined");
156
- await (0, fs_1.mkdirIfNotExists)(pkg.restorePath);
157
- if (!(await (0, fs_1.isEmptyDir)(pkg.restorePath)))
158
- throw new AppError_1.AppError(`Restore path is not empty: ${pkg.restorePath}`);
159
- if (this.options.verbose)
160
- (0, cli_1.logExec)(`restorePath=${pkg.restorePath}`);
161
- repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
162
- await repoInstance.onRestore({
163
- package: pkg,
164
- targetPath,
165
- packageConfig: pkg.repositoryConfigs?.find((config) => config.type === repo.type &&
166
- (!config.names || config.names.includes(repo.name)))?.config,
84
+ await (0, fs_1.initEmptyDir)(snapshotPath);
85
+ if (this.config.minFreeDiskSpace)
86
+ await (0, fs_1.ensureFreeDiskSpace)([snapshotPath], this.config.minFreeDiskSpace);
87
+ await repo.restore({
167
88
  options: this.options,
168
- snapshot: snapshot,
169
- onProgress: async (progress) => {
170
- await session.progressRepository({
171
- id: repositoryId,
172
- progress,
173
- });
174
- },
89
+ snapshot: data.snapshot,
90
+ package: pkg,
91
+ snapshotPath: snapshotPath,
92
+ packageConfig: pkg.repositoryConfigs?.find((config) => config.type === repoConfig.type &&
93
+ (!config.names || config.names.includes(repoConfig.name)))?.config,
94
+ onProgress: data.onProgress,
175
95
  });
176
- if (pkg.restorePermissions && (0, os_1.platform)() !== "win32")
177
- await (0, process_1.exec)("chown", [
178
- "-R",
179
- `${pkg.restorePermissions.uid}:${pkg.restorePermissions.gid}`,
180
- pkg.restorePath,
181
- ], {}, {
182
- log: this.options.verbose,
183
- });
184
- }
185
- catch (error) {
186
- (0, object_1.push)(this.repoErrors, pkg.name, (repoError = error));
187
- }
188
- await session.endRepository({
189
- id: repositoryId,
190
- error: repoError?.stack,
191
96
  });
192
- return {
193
- error: repoError ? false : true,
194
- tmpDirs: repoInstance?.tmpDirs || [],
195
- };
97
+ return { snapshotPath };
196
98
  }
197
- getError(pkg) {
198
- const taskErrors = this.taskErrors[pkg.name] || [];
199
- const repoErrors = this.repoErrors[pkg.name] || [];
200
- const errors = [...taskErrors, ...repoErrors];
201
- if (!errors.length)
202
- return;
203
- return AppError_1.AppError.create(taskErrors.length && repoErrors.length
204
- ? "Task and repository failed"
205
- : taskErrors.length && !repoErrors.length
206
- ? "Task failed"
207
- : "Repository failed", errors);
99
+ dataFormat(result, options = {}) {
100
+ const renderTitle = (item, color) => {
101
+ let title = item.key.slice(0, 1).toUpperCase() + item.key.slice(1);
102
+ return item.key === "restore" && color ? chalk_1.default.cyan(title) : title;
103
+ };
104
+ const renderData = (item, color) => {
105
+ const g = (v) => (color ? `${chalk_1.default.gray(`(${v})`)}` : `(${v})`);
106
+ return item.key === "snapshots"
107
+ ? `${item.data.id.slice(0, 8)} ${g(`${item.data.packages} packages`)}`
108
+ : item.key === "task"
109
+ ? `${item.data.packageName} ${g(item.data.taskName)}`
110
+ : item.key === "restore"
111
+ ? `${item.data.packageName} ${g(item.data.repositoryName)}`
112
+ : "";
113
+ };
114
+ return new DataFormat_1.DataFormat({
115
+ streams: options.streams,
116
+ json: result,
117
+ table: {
118
+ headers: [
119
+ { value: "", width: 3 },
120
+ { value: "Title", width: 15 },
121
+ { value: "Data" },
122
+ { value: "Duration", width: 10 },
123
+ { value: "Error", width: 50 },
124
+ ],
125
+ rows: () => result.map((item) => [
126
+ (0, cli_1.resultColumn)(item.error),
127
+ renderTitle(item, true),
128
+ renderData(item, true),
129
+ (0, date_1.duration)(item.elapsed),
130
+ (0, cli_1.errorColumn)(item.error, options.verbose),
131
+ ]),
132
+ },
133
+ });
208
134
  }
209
- async exec(session) {
210
- if (!this.options.snapshotId)
211
- throw new AppError_1.AppError("Snapshot id is required");
212
- const snapshots = this.groupSnapshots(await this.findSnapshots());
213
- if (!snapshots.length)
214
- throw new AppError_1.AppError("None snapshot found");
215
- let packages = (0, config_1.filterPackages)(this.config, {
216
- ...this.options,
217
- sourceAction: "restore",
135
+ async exec() {
136
+ const { options } = this;
137
+ const pm = new progress_1.ProgressManager({
138
+ verbose: options.verbose,
139
+ tty: options.tty,
140
+ enabled: options.progress,
141
+ interval: options.progressInterval,
218
142
  });
219
- packages = (0, config_1.resolvePackages)(packages, {
220
- snapshotId: this.options.snapshotId,
221
- snapshotDate: snapshots[0].date,
222
- action: "restore",
143
+ const l = new list_1.Listr3({
144
+ streams: options.streams,
145
+ progressManager: pm,
223
146
  });
224
- const snapshotAndConfigs = this.assocConfigs(packages, snapshots);
225
- await this.init(session, this.options.snapshotId, snapshotAndConfigs);
226
- const errors = [];
227
- for (const [snapshot, pkg] of snapshotAndConfigs) {
228
- (0, assert_1.ok)(pkg);
229
- const repo = (0, config_1.findRepositoryOrFail)(this.config, snapshot.repositoryName);
230
- const id = session.findId({
231
- packageName: pkg.name,
232
- });
233
- await session.start({ id });
234
- let targetPath;
235
- let taskInstance;
236
- if (pkg.task) {
237
- taskInstance = (0, TaskFactory_1.TaskFactory)(pkg.task);
238
- const result = await taskInstance.onBeforeRestore({
239
- options: this.options,
240
- package: pkg,
241
- snapshot,
242
- });
243
- targetPath = result?.targetPath;
244
- }
245
- const { tmpDirs } = await this.restore(session, pkg, repo, snapshot, targetPath);
246
- if (taskInstance) {
247
- await this.task(session, pkg, taskInstance, snapshot, targetPath);
248
- }
249
- if (!this.options.verbose) {
250
- await (0, fs_1.rmTmpDir)(taskInstance?.tmpDirs || []);
251
- await (0, fs_1.rmTmpDir)(tmpDirs);
252
- if (pkg.restorePath && (0, fs_1.isTmpDir)(pkg.restorePath))
253
- await (0, fs_1.rmTmpDir)(pkg.restorePath);
254
- }
255
- const error = this.getError(pkg);
256
- await session.end({
257
- id,
258
- error: error?.message,
259
- });
260
- if (error)
261
- errors.push(error);
262
- }
263
- await session.endDrivers();
264
- return { errors };
147
+ return l
148
+ .add(l.$task({
149
+ key: "snapshots",
150
+ data: {
151
+ id: "",
152
+ packages: 0,
153
+ },
154
+ title: {
155
+ initial: "Fetch snapshots",
156
+ started: "Fetching snapshots",
157
+ completed: "Snapshots fetched",
158
+ failed: "Snapshot fetch failed",
159
+ },
160
+ run: async (_, data) => {
161
+ const { minFreeDiskSpace } = this.config;
162
+ if (minFreeDiskSpace)
163
+ await (0, temp_1.ensureFreeDiskTempSpace)(minFreeDiskSpace);
164
+ if (!options.snapshotId)
165
+ throw new Error("Snapshot id is required");
166
+ const snapshots = this.groupSnapshots(await this.findSnapshots());
167
+ if (!snapshots.length)
168
+ throw new Error("None snapshot found");
169
+ data.id = options.snapshotId;
170
+ data.packages = snapshots.length;
171
+ return snapshots.map((snapshot) => l.$task({
172
+ key: "restore",
173
+ keyIndex: snapshot.packageName,
174
+ data: snapshot,
175
+ title: {
176
+ initial: `Restore ${snapshot.packageName} snapshot`,
177
+ started: `Restoring ${snapshot.packageName} snapshot`,
178
+ completed: `Snapshot restored: ${snapshot.packageName}`,
179
+ failed: `Snapshot restore failed: ${snapshot.packageName}`,
180
+ },
181
+ exitOnError: false,
182
+ run: async (listTask) => {
183
+ const pkg = (0, config_1.resolvePackage)((0, config_1.findPackageOrFail)(this.config, snapshot.packageName), {
184
+ snapshotId: options.snapshotId,
185
+ snapshotDate: snapshot.date,
186
+ action: "restore",
187
+ });
188
+ const gc = new temp_1.GargabeCollector();
189
+ const task = pkg.task ? (0, TaskFactory_1.createTask)(pkg.task) : undefined;
190
+ const restore = await this.restore({
191
+ gc,
192
+ pkg,
193
+ task,
194
+ snapshot: snapshot,
195
+ onProgress: (p) => pm.update(p, (t) => (listTask.output = t)),
196
+ });
197
+ if (!task)
198
+ return await gc.cleanup();
199
+ return l.$tasks({
200
+ key: "task",
201
+ keyIndex: pkg.name,
202
+ data: { taskName: pkg.task.name, packageName: pkg.name },
203
+ title: {
204
+ initial: `Execute ${pkg.task?.name} task`,
205
+ started: `Executing ${pkg.task?.name} task`,
206
+ completed: `Task executed: ${pkg.task?.name}`,
207
+ failed: `Task execute failed: ${pkg.task?.name}`,
208
+ },
209
+ exitOnError: false,
210
+ runWrapper: gc.cleanup.bind(gc),
211
+ run: async (listTask) => {
212
+ const { snapshotPath } = restore;
213
+ (0, assert_1.ok)(snapshotPath);
214
+ await task.restore({
215
+ package: pkg,
216
+ options,
217
+ snapshot,
218
+ snapshotPath,
219
+ onProgress: (p) => pm.update(p, (t) => (listTask.output = t)),
220
+ });
221
+ },
222
+ });
223
+ },
224
+ }));
225
+ },
226
+ }))
227
+ .exec();
265
228
  }
266
229
  }
267
230
  exports.RestoreAction = RestoreAction;
@@ -1,9 +1,9 @@
1
1
  import type { ConfigType } from "../Config/Config";
2
2
  import { RepositoryConfigEnabledActionType } from "../Config/RepositoryConfig";
3
- import { SnapshotResultType } from "../Repository/RepositoryAbstract";
3
+ import { Snapshot } from "../Repository/RepositoryAbstract";
4
4
  import { IfRequireKeys } from "../utils/ts";
5
- export type SnapshotGroupByType = keyof Pick<SnapshotExtendedType, "packageName" | "repositoryName" | "repositoryType">;
6
- export type SnapshotsActionOptionsType = {
5
+ export type SnapshotGroupByType = keyof Pick<ExtendedSnapshot, "packageName" | "repositoryName" | "repositoryType">;
6
+ export type SnapshotsActionOptions = {
7
7
  ids?: string[];
8
8
  repositoryNames?: string[];
9
9
  packageNames?: string[];
@@ -21,14 +21,14 @@ export type SnapshotsActionOptionsType = {
21
21
  lastYearly?: number;
22
22
  groupBy?: SnapshotGroupByType[];
23
23
  };
24
- export type SnapshotExtendedType = {
24
+ export type ExtendedSnapshot = {
25
25
  shortId: string;
26
26
  repositoryName: string;
27
27
  repositoryType: string;
28
- } & SnapshotResultType;
28
+ } & Snapshot;
29
29
  export declare class SnapshotsAction<TRequired extends boolean = true> {
30
30
  readonly config: ConfigType;
31
- readonly options: IfRequireKeys<TRequired, SnapshotsActionOptionsType>;
32
- constructor(config: ConfigType, options: IfRequireKeys<TRequired, SnapshotsActionOptionsType>);
33
- exec(sourceAction?: RepositoryConfigEnabledActionType): Promise<SnapshotExtendedType[]>;
31
+ readonly options: IfRequireKeys<TRequired, SnapshotsActionOptions>;
32
+ constructor(config: ConfigType, options: IfRequireKeys<TRequired, SnapshotsActionOptions>);
33
+ exec(sourceAction?: RepositoryConfigEnabledActionType): Promise<ExtendedSnapshot[]>;
34
34
  }
@@ -15,21 +15,21 @@ class SnapshotsAction {
15
15
  if (!sourceAction)
16
16
  sourceAction = "snapshots";
17
17
  let result = [];
18
- for (const repo of this.config.repositories) {
19
- if (!(0, config_1.filterRepository)(repo, sourceAction))
18
+ for (const repoConfig of this.config.repositories) {
19
+ if (!(0, config_1.filterRepository)(repoConfig, sourceAction))
20
20
  continue;
21
21
  if (this.options.repositoryNames &&
22
- !this.options.repositoryNames.includes(repo.name))
22
+ !this.options.repositoryNames.includes(repoConfig.name))
23
23
  continue;
24
24
  if (this.options.repositoryTypes &&
25
- !this.options.repositoryTypes.includes(repo.type))
25
+ !this.options.repositoryTypes.includes(repoConfig.type))
26
26
  continue;
27
- const repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
27
+ const repo = (0, RepositoryFactory_1.createRepo)(repoConfig);
28
28
  const configPackageNames = this.config.packages.map((pkg) => pkg.name);
29
29
  const packageNames = this.options.packageConfig
30
30
  ? this.options.packageNames?.filter((name) => configPackageNames.includes(name)) || configPackageNames
31
31
  : this.options.packageNames;
32
- const snapshots = await repoInstance.onSnapshots({
32
+ const snapshots = await repo.fetchSnapshots({
33
33
  options: {
34
34
  ...this.options,
35
35
  packageNames,
@@ -38,8 +38,8 @@ class SnapshotsAction {
38
38
  const extentedItems = snapshots.map((ss) => ({
39
39
  ...ss,
40
40
  shortId: ss.id.slice(0, 8),
41
- repositoryName: repo.name,
42
- repositoryType: repo.type,
41
+ repositoryName: repoConfig.name,
42
+ repositoryType: repoConfig.type,
43
43
  }));
44
44
  result.push(...extentedItems);
45
45
  }