@datatruck/cli 0.40.0 → 0.40.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.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { DiskStats } from "../fs";
3
2
  import { BasicProgress } from "../progress";
4
3
  import { AbstractFs, FsOptions } from "../virtual-fs";
@@ -13,7 +12,7 @@ export declare class RemoteFs extends AbstractFs {
13
12
  });
14
13
  isLocal(): boolean;
15
14
  protected fetchJson(name: string, params: any[]): Promise<any>;
16
- protected post(name: string, params: any[], data: string): Promise<Response>;
15
+ protected post(name: string, params: any[], data: string): Promise<import("undici").Response>;
17
16
  existsDir(path: string): Promise<boolean>;
18
17
  rename(source: string, target: string): Promise<void>;
19
18
  mkdir(path: string): Promise<void>;
@@ -65,7 +65,8 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
65
65
  const id = counter.next();
66
66
  let requestError;
67
67
  let responseError;
68
- req.on("error", (error) => (requestError = error));
68
+ const requestErrorListener = (error) => (requestError = error);
69
+ req.on("error", requestErrorListener);
69
70
  res.on("error", (error) => (responseError = error));
70
71
  res.setHeader("X-Accel-Buffering", "no");
71
72
  try {
@@ -88,16 +89,19 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
88
89
  else if (action === "upload") {
89
90
  const [target] = params;
90
91
  const path = fs.resolvePath(target);
92
+ req.off("error", requestErrorListener);
91
93
  await (0, http_1.recvFile)(req, res, path);
92
94
  }
93
95
  else if (action === "download") {
94
96
  const [target] = params;
95
97
  const path = fs.resolvePath(target);
98
+ req.off("error", requestErrorListener);
96
99
  await (0, http_1.sendFile)(req, res, path, {
97
100
  contentLength: options.contentLength ?? true,
98
101
  });
99
102
  }
100
103
  else if (action === "writeFile") {
104
+ req.off("error", requestErrorListener);
101
105
  const data = await (0, http_1.readRequestData)(req);
102
106
  const [target] = params;
103
107
  await fs.writeFile(target, data);
@@ -1,22 +1,19 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { BasicProgress } from "./progress";
4
3
  import { IncomingMessage, Server, ServerResponse } from "http";
4
+ import { fetch, type RequestInit } from "undici";
5
5
  export declare function createHref(inUrl: string, query?: Record<string, string>): string;
6
6
  export declare function closeServer(server: Server): Promise<void>;
7
7
  export declare function readRequestData(req: IncomingMessage): Promise<string | undefined>;
8
8
  export declare const safeFetch: typeof fetch;
9
9
  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>;
10
+ export declare function post(url: string, data: string, options?: Omit<RequestInit, "method" | "body">): Promise<import("undici").Response>;
11
11
  export declare function parseContentLength(value: string | undefined): number;
12
12
  export declare function sendFile(req: IncomingMessage, res: ServerResponse, path: string, options?: {
13
13
  contentLength?: boolean;
14
- end?: boolean;
15
14
  checksum?: boolean;
16
15
  }): Promise<void>;
17
- export declare function recvFile(req: IncomingMessage, res: ServerResponse, path: string, options?: {
18
- end?: boolean;
19
- }): Promise<void>;
16
+ export declare function recvFile(req: IncomingMessage, res: ServerResponse, path: string): Promise<void>;
20
17
  export declare function downloadFile(url: string, output: string, options?: Omit<RequestInit, "signal"> & {
21
18
  timeout?: number;
22
19
  onProgress?: (progress: BasicProgress) => void;
package/lib/utils/http.js CHANGED
@@ -7,6 +7,7 @@ const fs_1 = require("fs");
7
7
  const promises_1 = require("fs/promises");
8
8
  const stream_1 = require("stream");
9
9
  const promises_2 = require("stream/promises");
10
+ const undici_1 = require("undici");
10
11
  function createHref(inUrl, query) {
11
12
  const url = new URL(inUrl);
12
13
  for (const key in query || {})
@@ -35,7 +36,7 @@ function readRequestData(req) {
35
36
  }
36
37
  exports.readRequestData = readRequestData;
37
38
  const safeFetch = async (...args) => {
38
- const res = await fetch(...args);
39
+ const res = await (0, undici_1.fetch)(...args);
39
40
  if (res.status !== 200)
40
41
  throw new Error(`Fetch request failed: ${res.status} ${res.statusText}`);
41
42
  return res;
@@ -74,12 +75,12 @@ async function sendFile(req, res, path, options = {}) {
74
75
  }
75
76
  finally {
76
77
  file?.close();
77
- if (options.end)
78
+ if (!res.writableEnded)
78
79
  res.end();
79
80
  }
80
81
  }
81
82
  exports.sendFile = sendFile;
82
- async function recvFile(req, res, path, options = {}) {
83
+ async function recvFile(req, res, path) {
83
84
  let file;
84
85
  try {
85
86
  file = (0, fs_1.createWriteStream)(path);
@@ -95,8 +96,7 @@ async function recvFile(req, res, path, options = {}) {
95
96
  }
96
97
  finally {
97
98
  file?.close();
98
- if (options.end)
99
- res.end();
99
+ res.end();
100
100
  }
101
101
  }
102
102
  exports.recvFile = recvFile;
@@ -162,7 +162,7 @@ async function uploadFile(url, path, options = {}) {
162
162
  const { size } = await (0, promises_1.stat)(path);
163
163
  const file = (0, fs_1.createReadStream)(path);
164
164
  try {
165
- const res = await fetch(url, {
165
+ const res = await (0, undici_1.fetch)(url, {
166
166
  ...options,
167
167
  method: "POST",
168
168
  duplex: "half",
@@ -49,7 +49,9 @@ function createCommand(config, action) {
49
49
  for (const name in config.options) {
50
50
  const option = config.options[name];
51
51
  if (option.flag !== false) {
52
- const parse = typeof option.value === "string" ? parsers[option.value] : undefined;
52
+ const parse = typeof option.value === "string"
53
+ ? parsers[option.value]
54
+ : option.value;
53
55
  const cliValue = cliOptions[option.flag ?? name] ?? option.defaults;
54
56
  if (cliValue !== undefined)
55
57
  commandOptions[name] = parse ? parse(cliValue) : cliValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.40.0",
3
+ "version": "0.40.1",
4
4
  "description": "Tool for creating and managing backups",
5
5
  "homepage": "https://github.com/swordev/datatruck#readme",
6
6
  "bugs": {
@@ -27,25 +27,26 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@supercharge/promise-pool": "^3.2.0",
30
- "ajv": "^8.12.0",
30
+ "ajv": "^8.13.0",
31
31
  "async": "^3.2.5",
32
32
  "chalk": "^4.1.2",
33
33
  "commander": "^12.0.0",
34
34
  "croner": "^8.0.2",
35
- "dayjs": "^1.11.10",
35
+ "dayjs": "^1.11.11",
36
36
  "fast-folder-size": "^2.2.0",
37
37
  "fast-glob": "^3.3.2",
38
38
  "listr2": "^8.2.1",
39
39
  "micromatch": "^4.0.5",
40
- "mongodb": "^6.5.0",
41
- "mysql2": "^3.9.4",
40
+ "mongodb": "^6.6.1",
41
+ "mysql2": "^3.9.7",
42
42
  "tty-table": "^4.2.3",
43
- "yaml": "^2.4.1"
43
+ "undici": "^6.15.0",
44
+ "yaml": "^2.4.2"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@types/async": "^3.2.24",
47
- "@types/micromatch": "^4.0.6",
48
- "mongodb-memory-server": "^9.1.8"
48
+ "@types/micromatch": "^4.0.7",
49
+ "mongodb-memory-server": "^9.2.0"
49
50
  },
50
51
  "optionalDependencies": {
51
52
  "ts-node": "^10.9.2"