@datatruck/cli 0.40.0 → 0.40.2
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.
- package/lib/actions/BackupAction.js +19 -12
- package/lib/actions/CopyAction.js +20 -12
- package/lib/actions/ExportAction.js +12 -5
- package/lib/actions/RestoreAction.js +12 -5
- package/lib/cli.js +2 -3
- package/lib/repositories/ResticRepository.d.ts +2 -2
- package/lib/tasks/MysqlDumpTask.js +12 -5
- package/lib/tasks/ScriptTask.js +2 -2
- package/lib/utils/async-process.d.ts +0 -5
- package/lib/utils/async.d.ts +0 -1
- package/lib/utils/async.js +1 -2
- package/lib/utils/bytes.js +2 -3
- package/lib/utils/cli.d.ts +0 -1
- package/lib/utils/cli.js +12 -12
- package/lib/utils/cron.js +1 -2
- package/lib/utils/crypto.js +2 -3
- package/lib/utils/datatruck/client.d.ts +1 -2
- package/lib/utils/datatruck/client.js +3 -3
- package/lib/utils/datatruck/command.js +3 -3
- package/lib/utils/datatruck/config.js +15 -15
- package/lib/utils/datatruck/cron-server.js +1 -2
- package/lib/utils/datatruck/job.js +4 -5
- package/lib/utils/datatruck/paths.js +2 -3
- package/lib/utils/datatruck/report-list.js +1 -2
- package/lib/utils/datatruck/repository-server.d.ts +0 -1
- package/lib/utils/datatruck/repository-server.js +7 -3
- package/lib/utils/datatruck/repository.js +4 -5
- package/lib/utils/datatruck/snapshot.js +1 -2
- package/lib/utils/datatruck/task.js +1 -2
- package/lib/utils/date.js +4 -5
- package/lib/utils/exit.js +4 -5
- package/lib/utils/fs.d.ts +0 -3
- package/lib/utils/fs.js +40 -40
- package/lib/utils/git.d.ts +1 -1
- package/lib/utils/http.d.ts +3 -7
- package/lib/utils/http.js +17 -17
- package/lib/utils/list.d.ts +2 -2
- package/lib/utils/list.js +36 -26
- package/lib/utils/logs.js +3 -3
- package/lib/utils/math.js +2 -2
- package/lib/utils/mongodb.js +2 -3
- package/lib/utils/mysql.d.ts +0 -1
- package/lib/utils/mysql.js +2 -3
- package/lib/utils/object.js +6 -6
- package/lib/utils/options.js +5 -4
- package/lib/utils/process.d.ts +0 -1
- package/lib/utils/process.js +3 -4
- package/lib/utils/progress.d.ts +0 -2
- package/lib/utils/progress.js +3 -3
- package/lib/utils/reportSteps.js +2 -3
- package/lib/utils/spawnSteps.js +2 -3
- package/lib/utils/stream.d.ts +0 -1
- package/lib/utils/stream.js +2 -3
- package/lib/utils/string.js +11 -12
- package/lib/utils/tar.js +6 -7
- package/lib/utils/temp.d.ts +0 -1
- package/lib/utils/temp.js +10 -10
- package/lib/utils/virtual-fs.js +2 -2
- package/lib/utils/watcher.js +1 -2
- package/package.json +14 -13
package/lib/utils/fs.js
CHANGED
|
@@ -3,7 +3,46 @@ 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.
|
|
6
|
+
exports.parseFileExtensions = exports.isWSLSystem = void 0;
|
|
7
|
+
exports.isEmptyDir = isEmptyDir;
|
|
8
|
+
exports.isLocalDir = isLocalDir;
|
|
9
|
+
exports.mkdirIfNotExists = mkdirIfNotExists;
|
|
10
|
+
exports.ensureEmptyDir = ensureEmptyDir;
|
|
11
|
+
exports.ensureSingleFile = ensureSingleFile;
|
|
12
|
+
exports.ensureExistsDir = ensureExistsDir;
|
|
13
|
+
exports.safeStat = safeStat;
|
|
14
|
+
exports.existsDir = existsDir;
|
|
15
|
+
exports.existsFile = existsFile;
|
|
16
|
+
exports.writeJSONFile = writeJSONFile;
|
|
17
|
+
exports.include = include;
|
|
18
|
+
exports.parseFile = parseFile;
|
|
19
|
+
exports.parsePackageFile = parsePackageFile;
|
|
20
|
+
exports.findFile = findFile;
|
|
21
|
+
exports.fastFolderSizeAsync = fastFolderSizeAsync;
|
|
22
|
+
exports.readPartialFile = readPartialFile;
|
|
23
|
+
exports.safeReaddir = safeReaddir;
|
|
24
|
+
exports.tryReaddir = tryReaddir;
|
|
25
|
+
exports.forEachFile = forEachFile;
|
|
26
|
+
exports.fastglobToGitIgnore = fastglobToGitIgnore;
|
|
27
|
+
exports.writeGitIgnoreList = writeGitIgnoreList;
|
|
28
|
+
exports.copyFileWithStreams = copyFileWithStreams;
|
|
29
|
+
exports.updateFileStats = updateFileStats;
|
|
30
|
+
exports.isNotFoundError = isNotFoundError;
|
|
31
|
+
exports.readTextFile = readTextFile;
|
|
32
|
+
exports.cpy = cpy;
|
|
33
|
+
exports.createProgress = createProgress;
|
|
34
|
+
exports.createFileScanner = createFileScanner;
|
|
35
|
+
exports.createWriteStreamPool = createWriteStreamPool;
|
|
36
|
+
exports.countFileLines = countFileLines;
|
|
37
|
+
exports.fetchData = fetchData;
|
|
38
|
+
exports.safeRename = safeRename;
|
|
39
|
+
exports.tryRm = tryRm;
|
|
40
|
+
exports.initEmptyDir = initEmptyDir;
|
|
41
|
+
exports.fetchDiskStats = fetchDiskStats;
|
|
42
|
+
exports.checkFreeDiskSpace = checkFreeDiskSpace;
|
|
43
|
+
exports.ensureFreeDiskSpace = ensureFreeDiskSpace;
|
|
44
|
+
exports.groupFiles = groupFiles;
|
|
45
|
+
exports.asFile = asFile;
|
|
7
46
|
const pkg_1 = require("../pkg");
|
|
8
47
|
const bytes_1 = require("./bytes");
|
|
9
48
|
const error_1 = require("./error");
|
|
@@ -38,25 +77,21 @@ async function isEmptyDir(path) {
|
|
|
38
77
|
}
|
|
39
78
|
}
|
|
40
79
|
}
|
|
41
|
-
exports.isEmptyDir = isEmptyDir;
|
|
42
80
|
function pathIterator(stream) {
|
|
43
81
|
return stream;
|
|
44
82
|
}
|
|
45
83
|
function isLocalDir(path) {
|
|
46
84
|
return /^[\/\.]|([A-Z]:)/i.test(path);
|
|
47
85
|
}
|
|
48
|
-
exports.isLocalDir = isLocalDir;
|
|
49
86
|
async function mkdirIfNotExists(path) {
|
|
50
87
|
if (!(await existsDir(path)))
|
|
51
88
|
await (0, promises_1.mkdir)(path, { recursive: true });
|
|
52
89
|
return path;
|
|
53
90
|
}
|
|
54
|
-
exports.mkdirIfNotExists = mkdirIfNotExists;
|
|
55
91
|
async function ensureEmptyDir(path) {
|
|
56
92
|
if (!(await isEmptyDir(path)))
|
|
57
93
|
throw new error_1.AppError(`Dir is not empty: ${path}`);
|
|
58
94
|
}
|
|
59
|
-
exports.ensureEmptyDir = ensureEmptyDir;
|
|
60
95
|
async function ensureSingleFile(path) {
|
|
61
96
|
const files = await safeReaddir(path);
|
|
62
97
|
if (files.length !== 1)
|
|
@@ -64,38 +99,31 @@ async function ensureSingleFile(path) {
|
|
|
64
99
|
const [file] = files;
|
|
65
100
|
return (0, path_1.join)(path, file);
|
|
66
101
|
}
|
|
67
|
-
exports.ensureSingleFile = ensureSingleFile;
|
|
68
102
|
async function ensureExistsDir(path) {
|
|
69
103
|
if (!(await existsDir(path)))
|
|
70
104
|
throw new error_1.AppError(`Dir is not created: ${path}`);
|
|
71
105
|
}
|
|
72
|
-
exports.ensureExistsDir = ensureExistsDir;
|
|
73
106
|
async function safeStat(path) {
|
|
74
107
|
try {
|
|
75
108
|
return await (0, promises_1.stat)(path);
|
|
76
109
|
}
|
|
77
110
|
catch (e) { }
|
|
78
111
|
}
|
|
79
|
-
exports.safeStat = safeStat;
|
|
80
112
|
async function existsDir(path) {
|
|
81
113
|
return (await safeStat(path))?.isDirectory() ?? false;
|
|
82
114
|
}
|
|
83
|
-
exports.existsDir = existsDir;
|
|
84
115
|
async function existsFile(path) {
|
|
85
116
|
return (await safeStat(path))?.isFile() ?? false;
|
|
86
117
|
}
|
|
87
|
-
exports.existsFile = existsFile;
|
|
88
118
|
async function writeJSONFile(path, json) {
|
|
89
119
|
await (0, promises_1.writeFile)(path, JSON.stringify(json));
|
|
90
120
|
}
|
|
91
|
-
exports.writeJSONFile = writeJSONFile;
|
|
92
121
|
exports.parseFileExtensions = ["json", "js", "ts", "yaml", "yml"];
|
|
93
122
|
function include(path) {
|
|
94
123
|
path = (0, path_1.resolve)(path);
|
|
95
124
|
delete require.cache[path];
|
|
96
125
|
return require(path);
|
|
97
126
|
}
|
|
98
|
-
exports.include = include;
|
|
99
127
|
async function parseFile(path, jsKey) {
|
|
100
128
|
if (!(0, path_2.isAbsolute)(path))
|
|
101
129
|
path = (0, path_1.join)(process.cwd(), path);
|
|
@@ -115,11 +143,9 @@ async function parseFile(path, jsKey) {
|
|
|
115
143
|
return typeof value === "function" ? await value() : value;
|
|
116
144
|
}
|
|
117
145
|
}
|
|
118
|
-
exports.parseFile = parseFile;
|
|
119
146
|
function parsePackageFile() {
|
|
120
147
|
return pkg_1.pkg;
|
|
121
148
|
}
|
|
122
|
-
exports.parsePackageFile = parsePackageFile;
|
|
123
149
|
async function findFile(sourcePath, baseName, extensions, errorMessage = "Path not found") {
|
|
124
150
|
const info = await (0, promises_1.stat)(sourcePath);
|
|
125
151
|
let path;
|
|
@@ -139,11 +165,9 @@ async function findFile(sourcePath, baseName, extensions, errorMessage = "Path n
|
|
|
139
165
|
throw new Error(errorMessage);
|
|
140
166
|
return path;
|
|
141
167
|
}
|
|
142
|
-
exports.findFile = findFile;
|
|
143
168
|
async function fastFolderSizeAsync(path) {
|
|
144
169
|
return (await (0, util_1.promisify)(fast_folder_size_1.default)(path)) || 0;
|
|
145
170
|
}
|
|
146
|
-
exports.fastFolderSizeAsync = fastFolderSizeAsync;
|
|
147
171
|
async function readPartialFile(path, positions) {
|
|
148
172
|
let result = "";
|
|
149
173
|
const statResult = await (0, promises_1.stat)(path);
|
|
@@ -170,7 +194,6 @@ async function readPartialFile(path, positions) {
|
|
|
170
194
|
.on("close", () => resolve(result));
|
|
171
195
|
});
|
|
172
196
|
}
|
|
173
|
-
exports.readPartialFile = readPartialFile;
|
|
174
197
|
async function safeReaddir(path) {
|
|
175
198
|
try {
|
|
176
199
|
return await (0, promises_1.readdir)(path);
|
|
@@ -187,7 +210,6 @@ async function safeReaddir(path) {
|
|
|
187
210
|
throw anyError;
|
|
188
211
|
}
|
|
189
212
|
}
|
|
190
|
-
exports.safeReaddir = safeReaddir;
|
|
191
213
|
async function tryReaddir(path) {
|
|
192
214
|
try {
|
|
193
215
|
return await safeReaddir(path);
|
|
@@ -198,7 +220,6 @@ async function tryReaddir(path) {
|
|
|
198
220
|
throw error;
|
|
199
221
|
}
|
|
200
222
|
}
|
|
201
|
-
exports.tryReaddir = tryReaddir;
|
|
202
223
|
async function forEachFile(dirPath, cb, includeDir) {
|
|
203
224
|
const files = await safeReaddir(dirPath);
|
|
204
225
|
for (const file of files) {
|
|
@@ -213,7 +234,6 @@ async function forEachFile(dirPath, cb, includeDir) {
|
|
|
213
234
|
}
|
|
214
235
|
}
|
|
215
236
|
}
|
|
216
|
-
exports.forEachFile = forEachFile;
|
|
217
237
|
/**
|
|
218
238
|
* @experimental
|
|
219
239
|
*/
|
|
@@ -222,7 +242,6 @@ function fastglobToGitIgnore(patterns, baseDir) {
|
|
|
222
242
|
// https://git-scm.com/docs/gitignore
|
|
223
243
|
return patterns.map((p) => `${baseDir}/${p}`);
|
|
224
244
|
}
|
|
225
|
-
exports.fastglobToGitIgnore = fastglobToGitIgnore;
|
|
226
245
|
async function writeGitIgnoreList(options) {
|
|
227
246
|
const { outDir } = options;
|
|
228
247
|
const path = (0, path_1.join)(outDir, `.gitignore`);
|
|
@@ -256,7 +275,6 @@ async function writeGitIgnoreList(options) {
|
|
|
256
275
|
});
|
|
257
276
|
return path;
|
|
258
277
|
}
|
|
259
|
-
exports.writeGitIgnoreList = writeGitIgnoreList;
|
|
260
278
|
async function copyFileWithStreams(source, target) {
|
|
261
279
|
const r = (0, fs_1.createReadStream)(source);
|
|
262
280
|
const w = (0, fs_2.createWriteStream)(target);
|
|
@@ -274,17 +292,14 @@ async function copyFileWithStreams(source, target) {
|
|
|
274
292
|
throw error;
|
|
275
293
|
}
|
|
276
294
|
}
|
|
277
|
-
exports.copyFileWithStreams = copyFileWithStreams;
|
|
278
295
|
async function updateFileStats(path, fileInfo) {
|
|
279
296
|
await (0, promises_1.utimes)(path, fileInfo.atime, fileInfo.mtime);
|
|
280
297
|
await (0, promises_1.chmod)(path, fileInfo.mode);
|
|
281
298
|
await (0, promises_1.chown)(path, fileInfo.uid, fileInfo.gid);
|
|
282
299
|
}
|
|
283
|
-
exports.updateFileStats = updateFileStats;
|
|
284
300
|
function isNotFoundError(error) {
|
|
285
301
|
return error.code === "ENOENT";
|
|
286
302
|
}
|
|
287
|
-
exports.isNotFoundError = isNotFoundError;
|
|
288
303
|
async function readTextFile(path, onlyIfExists) {
|
|
289
304
|
let buffer;
|
|
290
305
|
try {
|
|
@@ -297,7 +312,6 @@ async function readTextFile(path, onlyIfExists) {
|
|
|
297
312
|
}
|
|
298
313
|
return buffer.toString();
|
|
299
314
|
}
|
|
300
|
-
exports.readTextFile = readTextFile;
|
|
301
315
|
async function cpy(options) {
|
|
302
316
|
const stats = { paths: 0, files: 0, dirs: 0 };
|
|
303
317
|
const dirs = new Set();
|
|
@@ -403,7 +417,6 @@ async function cpy(options) {
|
|
|
403
417
|
});
|
|
404
418
|
return stats;
|
|
405
419
|
}
|
|
406
|
-
exports.cpy = cpy;
|
|
407
420
|
function createProgress(options) {
|
|
408
421
|
const progress = {
|
|
409
422
|
disposed: false,
|
|
@@ -447,7 +460,6 @@ function createProgress(options) {
|
|
|
447
460
|
};
|
|
448
461
|
return progress;
|
|
449
462
|
}
|
|
450
|
-
exports.createProgress = createProgress;
|
|
451
463
|
async function createFileScanner(options) {
|
|
452
464
|
const progress = createProgress(options);
|
|
453
465
|
Object.assign(progress, {
|
|
@@ -482,7 +494,6 @@ async function createFileScanner(options) {
|
|
|
482
494
|
});
|
|
483
495
|
return progress;
|
|
484
496
|
}
|
|
485
|
-
exports.createFileScanner = createFileScanner;
|
|
486
497
|
function createWriteStreamPool(options) {
|
|
487
498
|
const pool = {};
|
|
488
499
|
const create = (key) => {
|
|
@@ -545,7 +556,6 @@ function createWriteStreamPool(options) {
|
|
|
545
556
|
},
|
|
546
557
|
};
|
|
547
558
|
}
|
|
548
|
-
exports.createWriteStreamPool = createWriteStreamPool;
|
|
549
559
|
function countFileLines(path) {
|
|
550
560
|
let lines = 0;
|
|
551
561
|
const rl = (0, readline_1.createInterface)({
|
|
@@ -560,7 +570,6 @@ function countFileLines(path) {
|
|
|
560
570
|
rl.on("error", reject);
|
|
561
571
|
});
|
|
562
572
|
}
|
|
563
|
-
exports.countFileLines = countFileLines;
|
|
564
573
|
async function fetchData(input, onPath) {
|
|
565
574
|
if (typeof input === "string")
|
|
566
575
|
return input;
|
|
@@ -569,7 +578,6 @@ async function fetchData(input, onPath) {
|
|
|
569
578
|
return (await (0, promises_1.readFile)(path)).toString();
|
|
570
579
|
return null;
|
|
571
580
|
}
|
|
572
|
-
exports.fetchData = fetchData;
|
|
573
581
|
async function safeRename(oldPath, newPath) {
|
|
574
582
|
try {
|
|
575
583
|
await (0, promises_1.rename)(oldPath, newPath);
|
|
@@ -585,14 +593,12 @@ async function safeRename(oldPath, newPath) {
|
|
|
585
593
|
}
|
|
586
594
|
}
|
|
587
595
|
}
|
|
588
|
-
exports.safeRename = safeRename;
|
|
589
596
|
async function tryRm(path) {
|
|
590
597
|
try {
|
|
591
598
|
await (0, promises_1.rm)(path);
|
|
592
599
|
}
|
|
593
600
|
catch (_) { }
|
|
594
601
|
}
|
|
595
|
-
exports.tryRm = tryRm;
|
|
596
602
|
async function initEmptyDir(path) {
|
|
597
603
|
if (!path)
|
|
598
604
|
throw new Error(`Path is not defined`);
|
|
@@ -600,21 +606,18 @@ async function initEmptyDir(path) {
|
|
|
600
606
|
await ensureEmptyDir(path);
|
|
601
607
|
return path;
|
|
602
608
|
}
|
|
603
|
-
exports.initEmptyDir = initEmptyDir;
|
|
604
609
|
async function fetchDiskStats(path) {
|
|
605
610
|
const fs = await (0, promises_1.statfs)(path);
|
|
606
611
|
const total = fs.bsize * fs.blocks;
|
|
607
612
|
const free = fs.bsize * fs.bavail;
|
|
608
613
|
return { total, free };
|
|
609
614
|
}
|
|
610
|
-
exports.fetchDiskStats = fetchDiskStats;
|
|
611
615
|
async function checkFreeDiskSpace(stat, inSize) {
|
|
612
616
|
const humanSize = typeof inSize === "number" ? (0, bytes_1.formatBytes)(inSize) : inSize;
|
|
613
617
|
const size = typeof inSize === "number" ? inSize : (0, bytes_1.parseSize)(inSize);
|
|
614
618
|
if (stat.free < size)
|
|
615
619
|
throw new Error(`Free disk space is less than ${humanSize}: ${(0, bytes_1.formatBytes)(stat.free)}/${(0, bytes_1.formatBytes)(stat.total)}`);
|
|
616
620
|
}
|
|
617
|
-
exports.checkFreeDiskSpace = checkFreeDiskSpace;
|
|
618
621
|
async function ensureFreeDiskSpace(input, inSize) {
|
|
619
622
|
if (Array.isArray(input)) {
|
|
620
623
|
for (const path of input) {
|
|
@@ -626,7 +629,6 @@ async function ensureFreeDiskSpace(input, inSize) {
|
|
|
626
629
|
await checkFreeDiskSpace(input, inSize);
|
|
627
630
|
}
|
|
628
631
|
}
|
|
629
|
-
exports.ensureFreeDiskSpace = ensureFreeDiskSpace;
|
|
630
632
|
function groupFiles(inFiles, suffixes, gzSuffix = ".tar.gz") {
|
|
631
633
|
const compressed = {};
|
|
632
634
|
if (suffixes) {
|
|
@@ -650,7 +652,6 @@ function groupFiles(inFiles, suffixes, gzSuffix = ".tar.gz") {
|
|
|
650
652
|
}
|
|
651
653
|
return [Object.keys(grouped), compressed];
|
|
652
654
|
}
|
|
653
|
-
exports.groupFiles = groupFiles;
|
|
654
655
|
async function asFile(input) {
|
|
655
656
|
if (typeof input === "string") {
|
|
656
657
|
const dir = await (0, temp_1.mkTmpDir)("text-as-file");
|
|
@@ -667,4 +668,3 @@ async function asFile(input) {
|
|
|
667
668
|
return [input.path, undefined];
|
|
668
669
|
}
|
|
669
670
|
}
|
|
670
|
-
exports.asFile = asFile;
|
package/lib/utils/git.d.ts
CHANGED
package/lib/utils/http.d.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import { BasicProgress } from "./progress";
|
|
4
2
|
import { IncomingMessage, Server, ServerResponse } from "http";
|
|
3
|
+
import { fetch, type RequestInit } from "undici";
|
|
5
4
|
export declare function createHref(inUrl: string, query?: Record<string, string>): string;
|
|
6
5
|
export declare function closeServer(server: Server): Promise<void>;
|
|
7
6
|
export declare function readRequestData(req: IncomingMessage): Promise<string | undefined>;
|
|
8
7
|
export declare const safeFetch: typeof fetch;
|
|
9
8
|
export declare function fetchJson<T = any>(url: string, options?: RequestInit): Promise<T | undefined>;
|
|
10
|
-
export declare function post(url: string, data: string, options?: Omit<RequestInit, "method" | "body">): Promise<Response>;
|
|
9
|
+
export declare function post(url: string, data: string, options?: Omit<RequestInit, "method" | "body">): Promise<import("undici").Response>;
|
|
11
10
|
export declare function parseContentLength(value: string | undefined): number;
|
|
12
11
|
export declare function sendFile(req: IncomingMessage, res: ServerResponse, path: string, options?: {
|
|
13
12
|
contentLength?: boolean;
|
|
14
|
-
end?: boolean;
|
|
15
13
|
checksum?: boolean;
|
|
16
14
|
}): Promise<void>;
|
|
17
|
-
export declare function recvFile(req: IncomingMessage, res: ServerResponse, path: string
|
|
18
|
-
end?: boolean;
|
|
19
|
-
}): Promise<void>;
|
|
15
|
+
export declare function recvFile(req: IncomingMessage, res: ServerResponse, path: string): Promise<void>;
|
|
20
16
|
export declare function downloadFile(url: string, output: string, options?: Omit<RequestInit, "signal"> & {
|
|
21
17
|
timeout?: number;
|
|
22
18
|
onProgress?: (progress: BasicProgress) => void;
|
package/lib/utils/http.js
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.safeFetch = void 0;
|
|
4
|
+
exports.createHref = createHref;
|
|
5
|
+
exports.closeServer = closeServer;
|
|
6
|
+
exports.readRequestData = readRequestData;
|
|
7
|
+
exports.fetchJson = fetchJson;
|
|
8
|
+
exports.post = post;
|
|
9
|
+
exports.parseContentLength = parseContentLength;
|
|
10
|
+
exports.sendFile = sendFile;
|
|
11
|
+
exports.recvFile = recvFile;
|
|
12
|
+
exports.downloadFile = downloadFile;
|
|
13
|
+
exports.uploadFile = uploadFile;
|
|
4
14
|
const crypto_1 = require("./crypto");
|
|
5
15
|
const math_1 = require("./math");
|
|
6
16
|
const fs_1 = require("fs");
|
|
7
17
|
const promises_1 = require("fs/promises");
|
|
8
18
|
const stream_1 = require("stream");
|
|
9
19
|
const promises_2 = require("stream/promises");
|
|
20
|
+
const undici_1 = require("undici");
|
|
10
21
|
function createHref(inUrl, query) {
|
|
11
22
|
const url = new URL(inUrl);
|
|
12
23
|
for (const key in query || {})
|
|
13
24
|
url.searchParams.set(key, query[key]);
|
|
14
25
|
return url.href;
|
|
15
26
|
}
|
|
16
|
-
exports.createHref = createHref;
|
|
17
27
|
async function closeServer(server) {
|
|
18
28
|
await new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
|
|
19
29
|
}
|
|
20
|
-
exports.closeServer = closeServer;
|
|
21
30
|
function readRequestData(req) {
|
|
22
31
|
let data;
|
|
23
32
|
return new Promise((resolve, reject) => {
|
|
@@ -33,9 +42,8 @@ function readRequestData(req) {
|
|
|
33
42
|
});
|
|
34
43
|
});
|
|
35
44
|
}
|
|
36
|
-
exports.readRequestData = readRequestData;
|
|
37
45
|
const safeFetch = async (...args) => {
|
|
38
|
-
const res = await fetch(...args);
|
|
46
|
+
const res = await (0, undici_1.fetch)(...args);
|
|
39
47
|
if (res.status !== 200)
|
|
40
48
|
throw new Error(`Fetch request failed: ${res.status} ${res.statusText}`);
|
|
41
49
|
return res;
|
|
@@ -46,17 +54,14 @@ async function fetchJson(url, options = {}) {
|
|
|
46
54
|
const data = await res.text();
|
|
47
55
|
return data.length ? JSON.parse(data) : undefined;
|
|
48
56
|
}
|
|
49
|
-
exports.fetchJson = fetchJson;
|
|
50
57
|
async function post(url, data, options = {}) {
|
|
51
58
|
return await (0, exports.safeFetch)(url, { ...options, method: "POST", body: data });
|
|
52
59
|
}
|
|
53
|
-
exports.post = post;
|
|
54
60
|
function parseContentLength(value) {
|
|
55
61
|
if (!value || !/^\d+$/.test(value))
|
|
56
62
|
throw new Error(`Invalid 'content-length': ${value}`);
|
|
57
63
|
return Number(value);
|
|
58
64
|
}
|
|
59
|
-
exports.parseContentLength = parseContentLength;
|
|
60
65
|
async function sendFile(req, res, path, options = {}) {
|
|
61
66
|
let file;
|
|
62
67
|
try {
|
|
@@ -74,12 +79,11 @@ async function sendFile(req, res, path, options = {}) {
|
|
|
74
79
|
}
|
|
75
80
|
finally {
|
|
76
81
|
file?.close();
|
|
77
|
-
if (
|
|
82
|
+
if (!res.writableEnded)
|
|
78
83
|
res.end();
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
|
-
|
|
82
|
-
async function recvFile(req, res, path, options = {}) {
|
|
86
|
+
async function recvFile(req, res, path) {
|
|
83
87
|
let file;
|
|
84
88
|
try {
|
|
85
89
|
file = (0, fs_1.createWriteStream)(path);
|
|
@@ -95,11 +99,9 @@ async function recvFile(req, res, path, options = {}) {
|
|
|
95
99
|
}
|
|
96
100
|
finally {
|
|
97
101
|
file?.close();
|
|
98
|
-
|
|
99
|
-
res.end();
|
|
102
|
+
res.end();
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
|
-
exports.recvFile = recvFile;
|
|
103
105
|
async function downloadFile(url, output, options = {}) {
|
|
104
106
|
const { timeout, onProgress, ...fetchOptions } = options;
|
|
105
107
|
const file = (0, fs_1.createWriteStream)(output);
|
|
@@ -157,12 +159,11 @@ async function downloadFile(url, output, options = {}) {
|
|
|
157
159
|
throw requestError;
|
|
158
160
|
return { bytes: length.total };
|
|
159
161
|
}
|
|
160
|
-
exports.downloadFile = downloadFile;
|
|
161
162
|
async function uploadFile(url, path, options = {}) {
|
|
162
163
|
const { size } = await (0, promises_1.stat)(path);
|
|
163
164
|
const file = (0, fs_1.createReadStream)(path);
|
|
164
165
|
try {
|
|
165
|
-
const res = await fetch(url, {
|
|
166
|
+
const res = await (0, undici_1.fetch)(url, {
|
|
166
167
|
...options,
|
|
167
168
|
method: "POST",
|
|
168
169
|
duplex: "half",
|
|
@@ -182,4 +183,3 @@ async function uploadFile(url, path, options = {}) {
|
|
|
182
183
|
file.close();
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
|
-
exports.uploadFile = uploadFile;
|
package/lib/utils/list.d.ts
CHANGED
|
@@ -46,7 +46,6 @@ export declare class Listr3<T extends Listr3Context> extends Listr<void, "defaul
|
|
|
46
46
|
gargabeCollector?: GargabeCollector;
|
|
47
47
|
};
|
|
48
48
|
readonly resultMap: Record<string, Listr3TaskResult<T>>;
|
|
49
|
-
readonly resultList: Listr3TaskResult<T>[];
|
|
50
49
|
readonly logger: List3Logger;
|
|
51
50
|
protected execTimer: Timer;
|
|
52
51
|
constructor($options: {
|
|
@@ -56,12 +55,13 @@ export declare class Listr3<T extends Listr3Context> extends Listr<void, "defaul
|
|
|
56
55
|
});
|
|
57
56
|
private serializeKeyIndex;
|
|
58
57
|
private createResultIndex;
|
|
58
|
+
get resultList(): any[];
|
|
59
59
|
result(key: keyof T, keyIndex?: KeyIndex): Listr3TaskResult<T>;
|
|
60
60
|
$task<K extends keyof T>(item: Listr3Task<T, K>): ListrTask;
|
|
61
61
|
$tasks<K extends keyof T>(...items: (Listr3Task<T, K> | ListrTask | false)[]): ListrTask[];
|
|
62
62
|
add(tasks: ListrTask<void, ListrGetRendererClassFromValue<"default">> | ListrTask<void, ListrGetRendererClassFromValue<"default">>[]): this;
|
|
63
63
|
getSummaryResult(): List3SummaryResult;
|
|
64
|
-
getResult():
|
|
64
|
+
getResult(): any[];
|
|
65
65
|
protected release(): void;
|
|
66
66
|
execAndParse(verbose: boolean | undefined): Promise<{
|
|
67
67
|
result: (List3SummaryResult | Listr3TaskResult<T>)[];
|
package/lib/utils/list.js
CHANGED
|
@@ -18,7 +18,6 @@ exports.List3Logger = List3Logger;
|
|
|
18
18
|
class Listr3 extends listr2_1.Listr {
|
|
19
19
|
$options;
|
|
20
20
|
resultMap = {};
|
|
21
|
-
resultList = [];
|
|
22
21
|
logger;
|
|
23
22
|
execTimer;
|
|
24
23
|
constructor($options) {
|
|
@@ -56,6 +55,16 @@ class Listr3 extends listr2_1.Listr {
|
|
|
56
55
|
createResultIndex(key, keyIndex) {
|
|
57
56
|
return [key, ...this.serializeKeyIndex(keyIndex)].join(".");
|
|
58
57
|
}
|
|
58
|
+
get resultList() {
|
|
59
|
+
return this.tasks
|
|
60
|
+
.flatMap((task) => [task, ...(task.subtasks || [])])
|
|
61
|
+
.map((task) => {
|
|
62
|
+
const result = task.task.task["_result"];
|
|
63
|
+
if (!result)
|
|
64
|
+
throw new Error(`Task result is not defined: ${task.title}`);
|
|
65
|
+
return result;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
59
68
|
result(key, keyIndex) {
|
|
60
69
|
const index = this.createResultIndex(key, keyIndex);
|
|
61
70
|
const result = this.resultMap[index];
|
|
@@ -76,37 +85,38 @@ class Listr3 extends listr2_1.Listr {
|
|
|
76
85
|
error: undefined,
|
|
77
86
|
data: item.data,
|
|
78
87
|
};
|
|
79
|
-
this.resultList.push(this.resultMap[index]);
|
|
80
88
|
const title = typeof item.title === "string" ? { initial: item.title } : item.title;
|
|
89
|
+
const task = async (_, task) => {
|
|
90
|
+
const result = this.result(item.key, item.keyIndex);
|
|
91
|
+
if (title.started)
|
|
92
|
+
task.title = title.started;
|
|
93
|
+
const timer = (0, date_1.createTimer)();
|
|
94
|
+
if (title)
|
|
95
|
+
try {
|
|
96
|
+
const runResult = await item.run(task, result.data);
|
|
97
|
+
if (title.completed)
|
|
98
|
+
task.title = title.completed;
|
|
99
|
+
return Array.isArray(runResult)
|
|
100
|
+
? task.newListr(runResult)
|
|
101
|
+
: runResult;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
result.error = error;
|
|
105
|
+
if (title.failed)
|
|
106
|
+
task.title = title.failed;
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
result.elapsed = timer.elapsed();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
task["_result"] = this.resultMap[index];
|
|
81
114
|
return {
|
|
82
115
|
title: title.initial,
|
|
83
116
|
exitOnError: item.exitOnError,
|
|
84
117
|
enabled: item.enabled,
|
|
85
118
|
skip: item.skip,
|
|
86
|
-
task
|
|
87
|
-
const result = this.result(item.key, item.keyIndex);
|
|
88
|
-
if (title.started)
|
|
89
|
-
task.title = title.started;
|
|
90
|
-
const timer = (0, date_1.createTimer)();
|
|
91
|
-
if (title)
|
|
92
|
-
try {
|
|
93
|
-
const runResult = await item.run(task, result.data);
|
|
94
|
-
if (title.completed)
|
|
95
|
-
task.title = title.completed;
|
|
96
|
-
return Array.isArray(runResult)
|
|
97
|
-
? task.newListr(runResult)
|
|
98
|
-
: runResult;
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
result.error = error;
|
|
102
|
-
if (title.failed)
|
|
103
|
-
task.title = title.failed;
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
result.elapsed = timer.elapsed();
|
|
108
|
-
}
|
|
109
|
-
},
|
|
119
|
+
task,
|
|
110
120
|
};
|
|
111
121
|
}
|
|
112
122
|
$tasks(...items) {
|
package/lib/utils/logs.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.defaultsLogPath = void 0;
|
|
4
|
+
exports.maxAgeToMS = maxAgeToMS;
|
|
5
|
+
exports.removeOldLogs = removeOldLogs;
|
|
4
6
|
const fs_1 = require("./fs");
|
|
5
7
|
const promises_1 = require("fs/promises");
|
|
6
8
|
const os_1 = require("os");
|
|
@@ -21,7 +23,6 @@ function maxAgeToMS(input) {
|
|
|
21
23
|
}
|
|
22
24
|
return ms;
|
|
23
25
|
}
|
|
24
|
-
exports.maxAgeToMS = maxAgeToMS;
|
|
25
26
|
exports.defaultsLogPath = (0, os_1.platform)() === "win32"
|
|
26
27
|
? (0, path_1.join)(process.env.APPDATA ?? `${process.env.HOMEDRIVE ?? "C:"}\\ProgramData`, "datatruck\\logs")
|
|
27
28
|
: "/var/logs/datatruck";
|
|
@@ -44,4 +45,3 @@ async function removeOldLogs(path, inMaxAge) {
|
|
|
44
45
|
}
|
|
45
46
|
return paths;
|
|
46
47
|
}
|
|
47
|
-
exports.removeOldLogs = removeOldLogs;
|
package/lib/utils/math.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Counter =
|
|
3
|
+
exports.Counter = void 0;
|
|
4
|
+
exports.progressPercent = progressPercent;
|
|
4
5
|
function progressPercent(total, current) {
|
|
5
6
|
if (total === 0 && current === 0)
|
|
6
7
|
return 0;
|
|
7
8
|
return Number(((current / total) * 100).toFixed(2));
|
|
8
9
|
}
|
|
9
|
-
exports.progressPercent = progressPercent;
|
|
10
10
|
class Counter {
|
|
11
11
|
maxValue;
|
|
12
12
|
value = 0;
|
package/lib/utils/mongodb.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toMongoUri = toMongoUri;
|
|
4
|
+
exports.resolveMongoUri = resolveMongoUri;
|
|
4
5
|
const fs_1 = require("./fs");
|
|
5
6
|
function toMongoUri(object) {
|
|
6
7
|
const url = new URL(`mongodb://${object.host}`);
|
|
@@ -13,7 +14,6 @@ function toMongoUri(object) {
|
|
|
13
14
|
url.pathname = `/${object.database}`;
|
|
14
15
|
return url.href;
|
|
15
16
|
}
|
|
16
|
-
exports.toMongoUri = toMongoUri;
|
|
17
17
|
async function resolveMongoUri(input) {
|
|
18
18
|
let object;
|
|
19
19
|
if (typeof input === "string") {
|
|
@@ -36,4 +36,3 @@ async function resolveMongoUri(input) {
|
|
|
36
36
|
: "",
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
exports.resolveMongoUri = resolveMongoUri;
|
package/lib/utils/mysql.d.ts
CHANGED
package/lib/utils/mysql.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.assertDumpFile = assertDumpFile;
|
|
4
|
+
exports.createMysqlCli = createMysqlCli;
|
|
4
5
|
const async_process_1 = require("./async-process");
|
|
5
6
|
const cli_1 = require("./cli");
|
|
6
7
|
const error_1 = require("./error");
|
|
@@ -39,7 +40,6 @@ async function assertDumpFile(path) {
|
|
|
39
40
|
if (!successFooter)
|
|
40
41
|
throw new error_1.AppError("No end line found (incomplete backup)");
|
|
41
42
|
}
|
|
42
|
-
exports.assertDumpFile = assertDumpFile;
|
|
43
43
|
async function createMysqlCli(options) {
|
|
44
44
|
let sqlConfigPath;
|
|
45
45
|
const password = (await (0, fs_1.fetchData)(options.password, (p) => p.path)) ?? "";
|
|
@@ -279,4 +279,3 @@ async function createMysqlCli(options) {
|
|
|
279
279
|
fetchVariable,
|
|
280
280
|
};
|
|
281
281
|
}
|
|
282
|
-
exports.createMysqlCli = createMysqlCli;
|