@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.
@@ -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, ProgressManager } from "../utils/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?: "auto" | "interval" | boolean;
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[];
@@ -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
- enabled: options.progress,
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) => this.pm.update(p, (t) => (task.output = t)),
241
+ onProgress: (p) => pm.update(p, (t) => (task.output = t)),
250
242
  });
251
243
  },
252
244
  })), l.$task({
@@ -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?: "auto" | "interval" | boolean;
17
- progressInterval?: number;
17
+ progress?: ProgressMode;
18
18
  };
19
19
  export type CopyActionResult = {
20
20
  errors: Error[];
@@ -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
- enabled: options.progress,
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?: "auto" | "interval" | boolean;
23
- progressInterval?: number;
22
+ progress?: ProgressMode;
24
23
  streams?: Streams;
25
24
  };
26
25
  type RestoreSnapshot = Snapshot & {
@@ -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
- enabled: options.progress,
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
@@ -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, "auto" | boolean, "auto" | "true" | "false" | "interval">;
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>;
@@ -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
- remoteAddreses: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
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 === "auto" ? "auto" : result.tty === "true",
25
- progress: result.progress === "auto" || result.progress === "interval"
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");
@@ -1107,7 +1107,7 @@
1107
1107
  "enabled": {
1108
1108
  "type": "boolean"
1109
1109
  },
1110
- "remoteAddreses": {
1110
+ "remoteAddresses": {
1111
1111
  "$ref": "#/definitions/stringlist-util"
1112
1112
  }
1113
1113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "dependencies": {
5
5
  "@supercharge/promise-pool": "^3.1.0",
6
6
  "ajv": "^8.12.0",
@@ -20,7 +20,7 @@ export type DatatruckServerOptions = {
20
20
  * @default true
21
21
  */
22
22
  enabled?: boolean;
23
- remoteAddreses?: string[];
23
+ remoteAddresses?: string[];
24
24
  };
25
25
  };
26
26
  export declare const headerKey: {
@@ -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.remoteAddreses) {
29
+ if (list && (list.enabled ?? true) && list.remoteAddresses) {
30
30
  const remoteAddress = getRemoteAddress(req, options);
31
- if (!remoteAddress || list.remoteAddreses.includes(remoteAddress))
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
@@ -114,7 +114,10 @@ async function downloadFile(url, output, options = {}) {
114
114
  }
115
115
  res
116
116
  .on("error", async (error) => {
117
- file.destroy();
117
+ try {
118
+ file.destroy();
119
+ }
120
+ catch (_) { }
118
121
  try {
119
122
  await (0, promises_1.unlink)(output);
120
123
  }
@@ -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 true
26
+ * @default false
25
27
  */
26
- tty?: boolean | "auto";
27
- enabled?: boolean | "auto" | "interval";
28
- interval?: number;
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: boolean;
34
- readonly enabled: boolean | "interval";
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 true
43
+ * @default false
44
+ */
45
+ tty?: ProgressTty;
46
+ /**
47
+ * @default "interval"
39
48
  */
40
- tty?: boolean | "auto";
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
- enabled;
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
- this.enabled =
26
- options.enabled === "auto"
27
- ? this.tty
28
- ? true
29
- : "interval"
30
- : !!options.enabled;
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.enabled)
70
+ if (!this.mode)
61
71
  return;
62
- if (this.enabled === "interval") {
72
+ if (this.mode === "interval") {
63
73
  if (this.interval) {
64
- if (!this.interval.reset(this.options.interval ?? 5000))
74
+ if (!this.interval.reset(this.intervalMs))
65
75
  return;
66
76
  }
67
77
  else {