@datatruck/cli 0.34.3 → 0.34.5

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 (48) hide show
  1. package/lib/actions/BackupAction.js +125 -39
  2. package/lib/actions/ConfigAction.js +1 -1
  3. package/lib/actions/CopyAction.js +110 -74
  4. package/lib/actions/InitAction.js +1 -1
  5. package/lib/actions/PruneAction.js +3 -2
  6. package/lib/actions/RestoreAction.d.ts +0 -2
  7. package/lib/actions/RestoreAction.js +131 -62
  8. package/lib/cli.js +1 -1
  9. package/lib/commands/StartServerCommand.js +2 -1
  10. package/lib/repositories/DatatruckRepository.d.ts +1 -1
  11. package/lib/repositories/DatatruckRepository.js +31 -18
  12. package/lib/repositories/GitRepository.js +11 -3
  13. package/lib/repositories/RepositoryAbstract.d.ts +2 -1
  14. package/lib/repositories/RepositoryAbstract.js +3 -1
  15. package/lib/repositories/ResticRepository.js +1 -1
  16. package/lib/tasks/GitTask.js +2 -1
  17. package/lib/tasks/MssqlTask.js +2 -2
  18. package/lib/tasks/MysqlDumpTask.js +1 -1
  19. package/lib/tasks/SqlDumpTaskAbstract.js +2 -2
  20. package/lib/utils/async-process.js +3 -2
  21. package/lib/utils/cli.js +10 -10
  22. package/lib/utils/data-format.js +3 -3
  23. package/lib/utils/datatruck/client.d.ts +7 -3
  24. package/lib/utils/datatruck/client.js +9 -2
  25. package/lib/utils/datatruck/command.js +1 -1
  26. package/lib/utils/datatruck/config.js +4 -4
  27. package/lib/utils/datatruck/report-list.js +2 -1
  28. package/lib/utils/datatruck/repository.d.ts +3 -3
  29. package/lib/utils/datatruck/repository.js +4 -4
  30. package/lib/utils/datatruck/task.js +1 -1
  31. package/lib/utils/{datatruck/error.d.ts → error.d.ts} +1 -1
  32. package/lib/utils/{datatruck/error.js → error.js} +2 -2
  33. package/lib/utils/fs.d.ts +2 -1
  34. package/lib/utils/fs.js +22 -3
  35. package/lib/utils/git.d.ts +5 -0
  36. package/lib/utils/git.js +10 -0
  37. package/lib/utils/list.d.ts +3 -1
  38. package/lib/utils/list.js +2 -3
  39. package/lib/utils/mysql.js +1 -1
  40. package/lib/utils/object.d.ts +1 -1
  41. package/lib/utils/object.js +1 -1
  42. package/lib/utils/progress.d.ts +8 -1
  43. package/lib/utils/progress.js +38 -5
  44. package/lib/utils/reportSteps.js +3 -2
  45. package/lib/utils/string.js +1 -1
  46. package/lib/utils/temp.d.ts +13 -10
  47. package/lib/utils/temp.js +47 -40
  48. package/package.json +1 -1
package/lib/utils/temp.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.GargabeCollector = exports.CleanupListener = exports.useTempFile = exports.useTempDir = exports.mkTmpDir = exports.tmpDir = exports.rmTmpDir = exports.isTmpDir = exports.ensureFreeDiskTempSpace = exports.sessionTmpDir = exports.parentTmpDir = void 0;
6
+ exports.GargabeCollector = exports.useTempFile = exports.useTempDir = exports.mkTmpDir = exports.collectors = exports.tmpDir = exports.rmTmpDir = exports.isTmpDir = exports.ensureFreeDiskTempSpace = exports.sessionTmpDir = exports.parentTmpDir = void 0;
7
7
  const globalData_1 = __importDefault(require("../globalData"));
8
8
  const fs_1 = require("./fs");
9
9
  const crypto_1 = require("crypto");
@@ -44,12 +44,15 @@ exports.rmTmpDir = rmTmpDir;
44
44
  function tmpDir(...keys) {
45
45
  const id = (0, crypto_1.randomUUID)().slice(0, 8);
46
46
  const path = (0, path_1.join)(sessionTmpDir(), [...keys, id].map(encodeURIComponent).join("-"));
47
- for (const listener of listeners)
48
- listener.paths.push(path);
47
+ if (exports.collectors.size) {
48
+ const lastListener = [...exports.collectors.values()].at(exports.collectors.size - 1);
49
+ if (lastListener)
50
+ lastListener.paths.add(path);
51
+ }
49
52
  return path;
50
53
  }
51
54
  exports.tmpDir = tmpDir;
52
- const listeners = new Set();
55
+ exports.collectors = new Set();
53
56
  async function mkTmpDir(...keys) {
54
57
  const path = tmpDir(...keys);
55
58
  await (0, promises_1.mkdir)(path, { recursive: true });
@@ -81,53 +84,57 @@ function useTempFile(path) {
81
84
  };
82
85
  }
83
86
  exports.useTempFile = useTempFile;
84
- class CleanupListener {
85
- paths = [];
86
- stop() {
87
- listeners.delete(this);
88
- }
89
- async dispose() {
90
- this.stop();
91
- await rmTmpDir(this.paths);
92
- }
93
- }
94
- exports.CleanupListener = CleanupListener;
95
87
  class GargabeCollector {
96
- listeners = new Set();
97
- get pending() {
98
- return this.listeners.size > 0;
88
+ parent;
89
+ paths = new Set();
90
+ children = new Set();
91
+ constructor(parent) {
92
+ this.parent = parent;
93
+ exports.collectors.add(this);
99
94
  }
100
- async cleanup(cb) {
101
- try {
102
- await cb?.();
103
- }
104
- finally {
105
- for (const listener of this.listeners) {
106
- this.listeners.delete(listener);
107
- await listener.dispose();
95
+ pending() {
96
+ if (this.paths.size)
97
+ return true;
98
+ for (const child of this.children)
99
+ if (child.pending())
100
+ return true;
101
+ return false;
102
+ }
103
+ async cleanup() {
104
+ for (const path of this.paths) {
105
+ try {
106
+ await rmTmpDir(path);
107
+ this.paths.delete(path);
108
108
  }
109
+ catch (_) { }
109
110
  }
111
+ for (const child of this.children)
112
+ await child.cleanup();
110
113
  }
111
- async cleanupOnFinish(cb) {
112
- const cleanup = new CleanupListener();
113
- try {
114
- await cb();
115
- }
116
- finally {
117
- cleanup.dispose();
118
- }
114
+ async dispose() {
115
+ await this.cleanup();
116
+ exports.collectors.delete(this);
119
117
  }
120
- async cleanupIfFail(cb) {
121
- const cleanup = new CleanupListener();
118
+ async disposeIfFail(cb) {
122
119
  try {
123
- await cb();
120
+ return await cb();
124
121
  }
125
122
  catch (error) {
126
- await cleanup.dispose();
123
+ await this.dispose();
127
124
  throw error;
128
125
  }
129
- this.listeners.add(cleanup);
130
- return cleanup;
126
+ }
127
+ disposeOnFinish() {
128
+ return {
129
+ [Symbol.asyncDispose]: async () => {
130
+ return this.dispose();
131
+ },
132
+ };
133
+ }
134
+ create() {
135
+ const gc = new GargabeCollector();
136
+ this.children.add(gc);
137
+ return gc;
131
138
  }
132
139
  }
133
140
  exports.GargabeCollector = GargabeCollector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.34.3",
3
+ "version": "0.34.5",
4
4
  "description": "Tool for creating and managing backups",
5
5
  "homepage": "https://github.com/swordev/datatruck#readme",
6
6
  "bugs": {