@datatruck/cli 0.30.0 → 0.30.1
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/Action/BackupAction.d.ts +2 -4
- package/Action/BackupAction.js +2 -10
- package/Action/CopyAction.d.ts +2 -2
- package/Action/CopyAction.js +1 -2
- package/Action/RestoreAction.d.ts +2 -3
- package/Action/RestoreAction.js +1 -2
- package/CHANGELOG.md +8 -0
- package/Command/BackupCommand.js +0 -1
- package/Command/CommandAbstract.d.ts +2 -2
- package/Command/CopyCommand.js +0 -1
- package/Command/RestoreCommand.js +0 -1
- package/Config/Config.js +1 -1
- package/Repository/DatatruckRepository.js +2 -0
- package/cli.js +4 -6
- package/config.schema.json +1 -1
- package/package.json +1 -1
- package/utils/datatruck/server.d.ts +1 -1
- package/utils/datatruck/server.js +2 -2
- package/utils/http.js +4 -1
- package/utils/progress.d.ts +17 -10
- package/utils/progress.js +20 -10
package/Action/BackupAction.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { RepositoryConfigType } from "../Config/RepositoryConfig";
|
|
|
4
4
|
import { PreSnapshot } from "../Repository/RepositoryAbstract";
|
|
5
5
|
import { DataFormat } from "../utils/DataFormat";
|
|
6
6
|
import { Listr3TaskResultEnd } from "../utils/list";
|
|
7
|
-
import { Progress,
|
|
7
|
+
import { Progress, ProgressMode } from "../utils/progress";
|
|
8
8
|
import { Streams } from "../utils/stream";
|
|
9
9
|
import { IfRequireKeys } from "../utils/ts";
|
|
10
10
|
export type BackupActionOptions = {
|
|
@@ -17,8 +17,7 @@ export type BackupActionOptions = {
|
|
|
17
17
|
verbose?: boolean;
|
|
18
18
|
date?: string;
|
|
19
19
|
tty?: "auto" | boolean;
|
|
20
|
-
progress?:
|
|
21
|
-
progressInterval?: number;
|
|
20
|
+
progress?: ProgressMode;
|
|
22
21
|
streams?: Streams;
|
|
23
22
|
prune?: boolean;
|
|
24
23
|
};
|
|
@@ -51,7 +50,6 @@ type Context = {
|
|
|
51
50
|
export declare class BackupAction<TRequired extends boolean = true> {
|
|
52
51
|
readonly config: ConfigType;
|
|
53
52
|
readonly options: IfRequireKeys<TRequired, BackupActionOptions>;
|
|
54
|
-
protected pm: ProgressManager;
|
|
55
53
|
constructor(config: ConfigType, options?: IfRequireKeys<TRequired, BackupActionOptions>);
|
|
56
54
|
protected prepareSnapshot(): PreSnapshot;
|
|
57
55
|
protected getPackages(snapshot: PreSnapshot): PackageConfigType[];
|
package/Action/BackupAction.js
CHANGED
|
@@ -22,16 +22,9 @@ const dayjs_1 = __importDefault(require("dayjs"));
|
|
|
22
22
|
class BackupAction {
|
|
23
23
|
config;
|
|
24
24
|
options;
|
|
25
|
-
pm;
|
|
26
25
|
constructor(config, options = {}) {
|
|
27
26
|
this.config = config;
|
|
28
27
|
this.options = options;
|
|
29
|
-
this.pm = new progress_1.ProgressManager({
|
|
30
|
-
verbose: options.verbose,
|
|
31
|
-
tty: options.tty,
|
|
32
|
-
enabled: options.progress,
|
|
33
|
-
interval: options.progressInterval,
|
|
34
|
-
});
|
|
35
28
|
}
|
|
36
29
|
prepareSnapshot() {
|
|
37
30
|
const date = this.options.date ?? new Date().toISOString();
|
|
@@ -165,8 +158,7 @@ class BackupAction {
|
|
|
165
158
|
const pm = new progress_1.ProgressManager({
|
|
166
159
|
verbose: options.verbose,
|
|
167
160
|
tty: options.tty,
|
|
168
|
-
|
|
169
|
-
interval: options.progressInterval,
|
|
161
|
+
mode: options.progress,
|
|
170
162
|
});
|
|
171
163
|
const l = new list_1.Listr3({
|
|
172
164
|
streams: this.options.streams,
|
|
@@ -246,7 +238,7 @@ class BackupAction {
|
|
|
246
238
|
repositoryName,
|
|
247
239
|
snapshot,
|
|
248
240
|
snapshotPath: taskResult?.snapshotPath,
|
|
249
|
-
onProgress: (p) =>
|
|
241
|
+
onProgress: (p) => pm.update(p, (t) => (task.output = t)),
|
|
250
242
|
});
|
|
251
243
|
},
|
|
252
244
|
})), l.$task({
|
package/Action/CopyAction.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ConfigType } from "../Config/Config";
|
|
|
2
2
|
import { Snapshot } from "../Repository/RepositoryAbstract";
|
|
3
3
|
import { DataFormat } from "../utils/DataFormat";
|
|
4
4
|
import { Listr3TaskResultEnd } from "../utils/list";
|
|
5
|
+
import { ProgressMode } from "../utils/progress";
|
|
5
6
|
import { Streams } from "../utils/stream";
|
|
6
7
|
import { IfRequireKeys } from "../utils/ts";
|
|
7
8
|
export type CopyActionOptionsType = {
|
|
@@ -13,8 +14,7 @@ export type CopyActionOptionsType = {
|
|
|
13
14
|
repositoryNames2?: string[];
|
|
14
15
|
verbose?: boolean;
|
|
15
16
|
tty?: "auto" | boolean;
|
|
16
|
-
progress?:
|
|
17
|
-
progressInterval?: number;
|
|
17
|
+
progress?: ProgressMode;
|
|
18
18
|
};
|
|
19
19
|
export type CopyActionResult = {
|
|
20
20
|
errors: Error[];
|
package/Action/CopyAction.js
CHANGED
|
@@ -69,8 +69,7 @@ class CopyAction {
|
|
|
69
69
|
const pm = new progress_1.ProgressManager({
|
|
70
70
|
verbose: options.verbose,
|
|
71
71
|
tty: options.tty,
|
|
72
|
-
|
|
73
|
-
interval: options.progressInterval,
|
|
72
|
+
mode: options.progress,
|
|
74
73
|
});
|
|
75
74
|
const l = new list_1.Listr3({ progressManager: pm });
|
|
76
75
|
return l
|
|
@@ -4,7 +4,7 @@ import { Snapshot } from "../Repository/RepositoryAbstract";
|
|
|
4
4
|
import { TaskAbstract } from "../Task/TaskAbstract";
|
|
5
5
|
import { DataFormat } from "../utils/DataFormat";
|
|
6
6
|
import { Listr3TaskResultEnd } from "../utils/list";
|
|
7
|
-
import { Progress } from "../utils/progress";
|
|
7
|
+
import { Progress, ProgressMode } from "../utils/progress";
|
|
8
8
|
import { Streams } from "../utils/stream";
|
|
9
9
|
import { GargabeCollector } from "../utils/temp";
|
|
10
10
|
import { IfRequireKeys } from "../utils/ts";
|
|
@@ -19,8 +19,7 @@ export type RestoreActionOptions = {
|
|
|
19
19
|
verbose?: boolean;
|
|
20
20
|
initial?: boolean;
|
|
21
21
|
tty?: "auto" | boolean;
|
|
22
|
-
progress?:
|
|
23
|
-
progressInterval?: number;
|
|
22
|
+
progress?: ProgressMode;
|
|
24
23
|
streams?: Streams;
|
|
25
24
|
};
|
|
26
25
|
type RestoreSnapshot = Snapshot & {
|
package/Action/RestoreAction.js
CHANGED
|
@@ -143,8 +143,7 @@ class RestoreAction {
|
|
|
143
143
|
const pm = new progress_1.ProgressManager({
|
|
144
144
|
verbose: options.verbose,
|
|
145
145
|
tty: options.tty,
|
|
146
|
-
|
|
147
|
-
interval: options.progressInterval,
|
|
146
|
+
mode: options.progress,
|
|
148
147
|
});
|
|
149
148
|
const l = new list_1.Listr3({
|
|
150
149
|
streams: options.streams,
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @datatruck/cli
|
|
2
2
|
|
|
3
|
+
## 0.30.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`68e991b`](https://github.com/swordev/datatruck/commit/68e991b862ee3793e6b31d1fd5d6cebdf59524a4) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix allowlist in datatruck server
|
|
8
|
+
|
|
9
|
+
- [`16f982c`](https://github.com/swordev/datatruck/commit/16f982c7da0d44cbbb691d5552da77fb27366f82) Thanks [@juanrgm](https://github.com/juanrgm)! - Reduce progress interval to 300 ms in auto progress mode
|
|
10
|
+
|
|
3
11
|
## 0.30.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/Command/BackupCommand.js
CHANGED
|
@@ -61,7 +61,6 @@ class BackupCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
61
61
|
date: this.options.date,
|
|
62
62
|
tty: this.globalOptions.tty,
|
|
63
63
|
progress: this.globalOptions.progress,
|
|
64
|
-
progressInterval: this.globalOptions.progressInterval,
|
|
65
64
|
streams: this.streams,
|
|
66
65
|
prune: this.options.prune,
|
|
67
66
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConfigType } from "../Config/Config";
|
|
2
2
|
import { FormatType } from "../utils/DataFormat";
|
|
3
3
|
import { OptionsType } from "../utils/cli";
|
|
4
|
+
import { ProgressMode } from "../utils/progress";
|
|
4
5
|
import { Streams } from "../utils/stream";
|
|
5
6
|
import { If, SimilarObject } from "../utils/ts";
|
|
6
7
|
export type GlobalOptions<TResolved = false> = {
|
|
@@ -8,8 +9,7 @@ export type GlobalOptions<TResolved = false> = {
|
|
|
8
9
|
outputFormat?: FormatType;
|
|
9
10
|
verbose?: number;
|
|
10
11
|
tty?: If<TResolved, "auto" | boolean, "auto" | "true" | "false">;
|
|
11
|
-
progress?: If<TResolved,
|
|
12
|
-
progressInterval?: number;
|
|
12
|
+
progress?: If<TResolved, ProgressMode, Exclude<ProgressMode, boolean> | "true" | "false">;
|
|
13
13
|
};
|
|
14
14
|
export type CommandConstructor<TUnresolvedOptions, TOptions extends SimilarObject<TUnresolvedOptions>> = {
|
|
15
15
|
new (globalOptions: GlobalOptions<true>, options: TOptions): CommandAbstract<TUnresolvedOptions, TOptions>;
|
package/Command/CopyCommand.js
CHANGED
|
@@ -53,7 +53,6 @@ class CopyCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
53
53
|
verbose: verbose > 0,
|
|
54
54
|
tty: this.globalOptions.tty,
|
|
55
55
|
progress: this.globalOptions.progress,
|
|
56
|
-
progressInterval: this.globalOptions.progressInterval,
|
|
57
56
|
});
|
|
58
57
|
const result = await copy.exec();
|
|
59
58
|
if (this.globalOptions.outputFormat)
|
|
@@ -63,7 +63,6 @@ class RestoreCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
63
63
|
initial: this.options.initial,
|
|
64
64
|
tty: this.globalOptions.tty,
|
|
65
65
|
progress: this.globalOptions.progress,
|
|
66
|
-
progressInterval: this.globalOptions.progressInterval,
|
|
67
66
|
streams: this.streams,
|
|
68
67
|
});
|
|
69
68
|
const result = await restore.exec();
|
package/Config/Config.js
CHANGED
|
@@ -77,7 +77,7 @@ exports.configDefinition = {
|
|
|
77
77
|
additionalProperties: false,
|
|
78
78
|
properties: {
|
|
79
79
|
enabled: { type: "boolean" },
|
|
80
|
-
|
|
80
|
+
remoteAddresses: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
|
|
81
81
|
},
|
|
82
82
|
},
|
|
83
83
|
},
|
|
@@ -292,6 +292,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
292
292
|
absolute,
|
|
293
293
|
relative: {
|
|
294
294
|
description: "Downloading",
|
|
295
|
+
format: "size",
|
|
295
296
|
...progress,
|
|
296
297
|
},
|
|
297
298
|
}),
|
|
@@ -306,6 +307,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
306
307
|
absolute,
|
|
307
308
|
relative: {
|
|
308
309
|
description: "Downloading",
|
|
310
|
+
format: "size",
|
|
309
311
|
...progress,
|
|
310
312
|
},
|
|
311
313
|
}),
|
package/cli.js
CHANGED
|
@@ -19,12 +19,11 @@ const fs_2 = require("fs");
|
|
|
19
19
|
const path_1 = require("path");
|
|
20
20
|
function getGlobalOptions() {
|
|
21
21
|
const result = program.opts();
|
|
22
|
+
const parseBool = (v) => v === "true" ? true : v === "false" ? false : v;
|
|
22
23
|
return {
|
|
23
24
|
...result,
|
|
24
|
-
tty: result.tty
|
|
25
|
-
progress: result.progress
|
|
26
|
-
? result.progress
|
|
27
|
-
: result.progress === "true",
|
|
25
|
+
tty: parseBool(result.tty),
|
|
26
|
+
progress: parseBool(result.progress),
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
29
|
function makeCommand(command) {
|
|
@@ -89,8 +88,7 @@ program.usage("dtt");
|
|
|
89
88
|
program.option("-v,--verbose", "Verbose", (_, previous) => previous + 1, 0);
|
|
90
89
|
program.option("-c,--config <path>", "Config path", process.env["DATATRUCK_CONFIG"] ?? (cwd.endsWith(path_1.sep) ? cwd : `${cwd}${path_1.sep}`));
|
|
91
90
|
program.option("--tty <value>", "TTY mode (auto, true, false)", "auto");
|
|
92
|
-
program.option("--progress <value>", "Progress type (auto, true, false, interval)", "auto");
|
|
93
|
-
program.option("--progress-interval <ms>", "Progress interval", Number, 1000);
|
|
91
|
+
program.option("--progress <value>", "Progress type (auto, true, false, interval, interval:[ms])", "auto");
|
|
94
92
|
program.option("-o,--output-format <format>", "Output format (json, pjson, yaml, table, custom=$, tpl=name)", "table");
|
|
95
93
|
makeCommand(CommandFactory_1.CommandEnum.startServer).alias("start");
|
|
96
94
|
makeCommand(CommandFactory_1.CommandEnum.config).alias("c");
|
package/config.schema.json
CHANGED
package/package.json
CHANGED
|
@@ -26,9 +26,9 @@ exports.headerKey = {
|
|
|
26
26
|
};
|
|
27
27
|
function validateRequest(req, options) {
|
|
28
28
|
const list = options.allowlist;
|
|
29
|
-
if (list && (list.enabled ?? true) && list.
|
|
29
|
+
if (list && (list.enabled ?? true) && list.remoteAddresses) {
|
|
30
30
|
const remoteAddress = getRemoteAddress(req, options);
|
|
31
|
-
if (!remoteAddress || list.
|
|
31
|
+
if (!remoteAddress || !list.remoteAddresses.includes(remoteAddress))
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
const name = req.headers[exports.headerKey.user]?.toString().trim();
|
package/utils/http.js
CHANGED
package/utils/progress.d.ts
CHANGED
|
@@ -17,29 +17,36 @@ export type Progress = {
|
|
|
17
17
|
absolute?: ProgressStats;
|
|
18
18
|
relative?: ProgressStats;
|
|
19
19
|
};
|
|
20
|
+
export type ProgressTty = "auto" | boolean;
|
|
21
|
+
export type ProgressMode = "auto" | "interval" | `interval:${number}` | boolean;
|
|
20
22
|
export declare class ProgressManager {
|
|
21
23
|
readonly options: {
|
|
22
24
|
verbose?: boolean;
|
|
23
25
|
/**
|
|
24
|
-
* @default
|
|
26
|
+
* @default false
|
|
25
27
|
*/
|
|
26
|
-
tty?:
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
tty?: ProgressTty;
|
|
29
|
+
/**
|
|
30
|
+
* @default "interval"
|
|
31
|
+
*/
|
|
32
|
+
mode?: ProgressMode;
|
|
29
33
|
};
|
|
30
34
|
protected timer: Timer;
|
|
31
35
|
protected interval: Timer | undefined;
|
|
36
|
+
protected intervalMs: number;
|
|
32
37
|
protected keydownListener: ((data: Buffer | undefined) => void) | undefined;
|
|
33
|
-
readonly tty:
|
|
34
|
-
readonly
|
|
38
|
+
readonly tty: Exclude<ProgressTty, "auto">;
|
|
39
|
+
readonly mode: Exclude<ProgressMode, "auto" | `interval:${number}`>;
|
|
35
40
|
constructor(options: {
|
|
36
41
|
verbose?: boolean;
|
|
37
42
|
/**
|
|
38
|
-
* @default
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
tty?: ProgressTty;
|
|
46
|
+
/**
|
|
47
|
+
* @default "interval"
|
|
39
48
|
*/
|
|
40
|
-
|
|
41
|
-
enabled?: boolean | "auto" | "interval";
|
|
42
|
-
interval?: number;
|
|
49
|
+
mode?: ProgressMode;
|
|
43
50
|
});
|
|
44
51
|
elapsed(): number;
|
|
45
52
|
start(): void;
|
package/utils/progress.js
CHANGED
|
@@ -11,9 +11,10 @@ class ProgressManager {
|
|
|
11
11
|
options;
|
|
12
12
|
timer = (0, date_1.createTimer)();
|
|
13
13
|
interval = (0, date_1.createTimer)();
|
|
14
|
+
intervalMs;
|
|
14
15
|
keydownListener;
|
|
15
16
|
tty;
|
|
16
|
-
|
|
17
|
+
mode;
|
|
17
18
|
constructor(options) {
|
|
18
19
|
this.options = options;
|
|
19
20
|
this.tty =
|
|
@@ -22,12 +23,21 @@ class ProgressManager {
|
|
|
22
23
|
? false
|
|
23
24
|
: process.stdout.isTTY
|
|
24
25
|
: !!options.tty;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
?
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
const mode = options.mode === "auto"
|
|
27
|
+
? this.tty
|
|
28
|
+
? `interval:${300}`
|
|
29
|
+
: "interval"
|
|
30
|
+
: options.mode ?? "interval";
|
|
31
|
+
this.intervalMs = 1000;
|
|
32
|
+
if (typeof mode === "string" && mode.startsWith("interval:")) {
|
|
33
|
+
const [, ms] = mode.split(":");
|
|
34
|
+
this.mode = "interval";
|
|
35
|
+
if (/^\d+$/.test(ms))
|
|
36
|
+
this.intervalMs = Number(ms);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.mode = mode;
|
|
40
|
+
}
|
|
31
41
|
}
|
|
32
42
|
elapsed() {
|
|
33
43
|
return this.timer.elapsed();
|
|
@@ -57,11 +67,11 @@ class ProgressManager {
|
|
|
57
67
|
}
|
|
58
68
|
}
|
|
59
69
|
update(progress, cb) {
|
|
60
|
-
if (!this.
|
|
70
|
+
if (!this.mode)
|
|
61
71
|
return;
|
|
62
|
-
if (this.
|
|
72
|
+
if (this.mode === "interval") {
|
|
63
73
|
if (this.interval) {
|
|
64
|
-
if (!this.interval.reset(this.
|
|
74
|
+
if (!this.interval.reset(this.intervalMs))
|
|
65
75
|
return;
|
|
66
76
|
}
|
|
67
77
|
else {
|