@datatruck/cli 0.36.3 → 0.36.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.
- package/lib/actions/CopyAction.js +3 -4
- package/lib/repositories/RepositoryAbstract.d.ts +6 -5
- package/lib/utils/cli.js +5 -4
- package/lib/utils/datatruck/paths.d.ts +1 -1
- package/lib/utils/datatruck/paths.js +1 -0
- package/lib/utils/datatruck/repository-server.js +40 -41
- package/lib/utils/math.d.ts +6 -0
- package/lib/utils/math.js +14 -1
- package/package.json +1 -1
|
@@ -151,9 +151,8 @@ class CopyAction {
|
|
|
151
151
|
async copyCrossRepository(options) {
|
|
152
152
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
153
153
|
try {
|
|
154
|
-
const { repo,
|
|
154
|
+
const { repo, mirrorRepo, mirrorConfig, snapshot } = options;
|
|
155
155
|
const tmp = __addDisposableResource(env_1, await (0, temp_1.useTempDir)("copy", "restore"), true);
|
|
156
|
-
const pkg = (0, config_1.findPackageOrFail)(this.config, snapshot.packageName);
|
|
157
156
|
await repo.restore({
|
|
158
157
|
options: {
|
|
159
158
|
verbose: this.options.verbose,
|
|
@@ -161,7 +160,7 @@ class CopyAction {
|
|
|
161
160
|
},
|
|
162
161
|
snapshot: { id: snapshot.id, date: snapshot.date },
|
|
163
162
|
package: { name: snapshot.packageName },
|
|
164
|
-
packageConfig:
|
|
163
|
+
packageConfig: undefined,
|
|
165
164
|
snapshotPath: tmp.path,
|
|
166
165
|
onProgress: options.onProgress,
|
|
167
166
|
});
|
|
@@ -178,7 +177,7 @@ class CopyAction {
|
|
|
178
177
|
name: snapshot.packageName,
|
|
179
178
|
path: tmp.path,
|
|
180
179
|
},
|
|
181
|
-
packageConfig:
|
|
180
|
+
packageConfig: undefined,
|
|
182
181
|
onProgress: options.onProgress,
|
|
183
182
|
});
|
|
184
183
|
}
|
|
@@ -27,7 +27,7 @@ export type RepoFetchSnapshotsData = {
|
|
|
27
27
|
export type RepoCopyData<TRepositoryConfig> = {
|
|
28
28
|
options: BackupActionOptions;
|
|
29
29
|
snapshot: PreSnapshot;
|
|
30
|
-
package: PackageConfig
|
|
30
|
+
package: Pick<PackageConfig, "name">;
|
|
31
31
|
mirrorRepositoryConfig: TRepositoryConfig;
|
|
32
32
|
onProgress: (data: Progress) => void;
|
|
33
33
|
};
|
|
@@ -35,8 +35,9 @@ export type RepoBackupData<TPackageConfig> = {
|
|
|
35
35
|
options: BackupActionOptions;
|
|
36
36
|
snapshot: PreSnapshot;
|
|
37
37
|
hostname: string;
|
|
38
|
-
package:
|
|
39
|
-
path:
|
|
38
|
+
package: Pick<PackageConfig, "name" | "include" | "exclude"> & {
|
|
39
|
+
path: NonNullable<PackageConfig["path"]>;
|
|
40
|
+
task?: Pick<NonNullable<PackageConfig["task"]>, "name">;
|
|
40
41
|
};
|
|
41
42
|
packageConfig: TPackageConfig | undefined;
|
|
42
43
|
onProgress: (data: Progress) => void;
|
|
@@ -44,9 +45,9 @@ export type RepoBackupData<TPackageConfig> = {
|
|
|
44
45
|
export type RepoRestoreData<TPackageConfig> = {
|
|
45
46
|
options: RestoreActionOptions;
|
|
46
47
|
snapshot: PreSnapshot;
|
|
47
|
-
package: PackageConfig
|
|
48
|
+
package: Pick<PackageConfig, "name">;
|
|
48
49
|
snapshotPath: string;
|
|
49
|
-
packageConfig: TPackageConfig;
|
|
50
|
+
packageConfig: TPackageConfig | undefined;
|
|
50
51
|
onProgress: (data: Progress) => void;
|
|
51
52
|
};
|
|
52
53
|
export type RepoPruneData = {
|
package/lib/utils/cli.js
CHANGED
|
@@ -173,10 +173,11 @@ function colorizeObject(input) {
|
|
|
173
173
|
const object = {};
|
|
174
174
|
for (const key in input) {
|
|
175
175
|
const value = input[key];
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
if (value !== undefined)
|
|
177
|
+
object[colorizeValue(key)] =
|
|
178
|
+
typeof value === "object" && !!value && !Array.isArray(value)
|
|
179
|
+
? colorizeObject(value)
|
|
180
|
+
: colorizeValue(value, "green");
|
|
180
181
|
}
|
|
181
182
|
const values = Object.entries(object)
|
|
182
183
|
.map(([key, value]) => `${key}: ${value}`)
|
|
@@ -9,7 +9,7 @@ export type ParsePathsOptions = {
|
|
|
9
9
|
};
|
|
10
10
|
export declare function parsePaths(values: (string | SpawnStep)[], options: ParsePathsOptions): Promise<string[]>;
|
|
11
11
|
export type BackupPathsOptions = {
|
|
12
|
-
package: PackageConfig
|
|
12
|
+
package: Pick<PackageConfig, "name" | "path" | "include" | "exclude">;
|
|
13
13
|
snapshot: PreSnapshot;
|
|
14
14
|
path: string;
|
|
15
15
|
verbose?: boolean;
|
|
@@ -4,10 +4,12 @@ exports.createDatatruckRepositoryServer = exports.headerKey = void 0;
|
|
|
4
4
|
const ConfigAction_1 = require("../../actions/ConfigAction");
|
|
5
5
|
const cli_1 = require("../cli");
|
|
6
6
|
const http_1 = require("../http");
|
|
7
|
+
const math_1 = require("../math");
|
|
7
8
|
const virtual_fs_1 = require("../virtual-fs");
|
|
8
9
|
const fs_1 = require("fs");
|
|
9
10
|
const promises_1 = require("fs/promises");
|
|
10
11
|
const http_2 = require("http");
|
|
12
|
+
const promises_2 = require("stream/promises");
|
|
11
13
|
exports.headerKey = {
|
|
12
14
|
user: "x-dtt-user",
|
|
13
15
|
password: "x-dtt-password",
|
|
@@ -58,33 +60,31 @@ const getRemoteAddress = (req, options) => {
|
|
|
58
60
|
: undefined) ?? req.socket.remoteAddress);
|
|
59
61
|
};
|
|
60
62
|
function createDatatruckRepositoryServer(inOptions, config = {}) {
|
|
63
|
+
const counter = new math_1.Counter();
|
|
61
64
|
return (0, http_2.createServer)(async (req, res) => {
|
|
65
|
+
const url = req.url || "";
|
|
66
|
+
if (url === "/" || url === "/favicon.ico")
|
|
67
|
+
return res.end();
|
|
68
|
+
const id = counter.next();
|
|
69
|
+
let requestError;
|
|
70
|
+
let responseError;
|
|
71
|
+
req.on("error", (error) => (requestError = error));
|
|
72
|
+
res.on("error", (error) => (responseError = error));
|
|
62
73
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!repository || !action) {
|
|
67
|
-
res.statusCode = 404;
|
|
68
|
-
return res.end();
|
|
69
|
-
}
|
|
74
|
+
const { repository, action, params } = parseUrl(url);
|
|
75
|
+
if (!repository || !action)
|
|
76
|
+
return res.writeHead(404);
|
|
70
77
|
const fileOptions = config.configPath
|
|
71
78
|
? (await ConfigAction_1.ConfigAction.findAndParseFile(config.configPath)).server
|
|
72
79
|
?.repository
|
|
73
80
|
: undefined;
|
|
74
81
|
const options = fileOptions ?? inOptions;
|
|
75
82
|
const backend = findRepositoryBackend(req, repository, options);
|
|
76
|
-
if (!backend)
|
|
77
|
-
res.
|
|
78
|
-
return res.end();
|
|
79
|
-
}
|
|
83
|
+
if (!backend)
|
|
84
|
+
return res.writeHead(401);
|
|
80
85
|
if (config.log)
|
|
81
|
-
(0, cli_1.logJson)("repository-server", "request", {
|
|
82
|
-
|
|
83
|
-
url: req.url,
|
|
84
|
-
});
|
|
85
|
-
const fs = new virtual_fs_1.LocalFs({
|
|
86
|
-
backend: backend.path,
|
|
87
|
-
});
|
|
86
|
+
(0, cli_1.logJson)("repository-server", "request", { id, repository, url });
|
|
87
|
+
const fs = new virtual_fs_1.LocalFs({ backend: backend.path });
|
|
88
88
|
if (action === "comcheck") {
|
|
89
89
|
res.write(JSON.stringify({ success: true }));
|
|
90
90
|
}
|
|
@@ -92,12 +92,7 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
|
|
|
92
92
|
const [target] = params;
|
|
93
93
|
const path = fs.resolvePath(target);
|
|
94
94
|
const file = (0, fs_1.createWriteStream)(path);
|
|
95
|
-
|
|
96
|
-
await new Promise((resolve, reject) => {
|
|
97
|
-
req.on("error", reject);
|
|
98
|
-
file.on("error", reject);
|
|
99
|
-
file.on("close", resolve);
|
|
100
|
-
});
|
|
95
|
+
await (0, promises_2.pipeline)(req, file);
|
|
101
96
|
}
|
|
102
97
|
else if (action === "download") {
|
|
103
98
|
const [target] = params;
|
|
@@ -105,13 +100,7 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
|
|
|
105
100
|
const file = (0, fs_1.createReadStream)(path);
|
|
106
101
|
const fileStat = await (0, promises_1.stat)(path);
|
|
107
102
|
res.setHeader("Content-Length", fileStat.size);
|
|
108
|
-
|
|
109
|
-
await new Promise((resolve, reject) => {
|
|
110
|
-
req.on("error", reject);
|
|
111
|
-
file.on("error", reject);
|
|
112
|
-
res.on("error", reject);
|
|
113
|
-
res.on("close", resolve);
|
|
114
|
-
});
|
|
103
|
+
await (0, promises_2.pipeline)(file, res, { end: false });
|
|
115
104
|
}
|
|
116
105
|
else if (action === "writeFile") {
|
|
117
106
|
const data = await (0, http_1.readRequestData)(req);
|
|
@@ -127,21 +116,31 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
|
|
|
127
116
|
res.write(JSON.stringify(json));
|
|
128
117
|
}
|
|
129
118
|
if (config.log)
|
|
130
|
-
(0, cli_1.logJson)("repository-server", "request finished", {
|
|
131
|
-
url: req.url,
|
|
132
|
-
});
|
|
133
|
-
res.end();
|
|
119
|
+
(0, cli_1.logJson)("repository-server", "request finished", { id });
|
|
134
120
|
}
|
|
135
121
|
catch (error) {
|
|
136
122
|
if (config.log) {
|
|
137
|
-
(0, cli_1.logJson)("repository-server", "request failed", {
|
|
138
|
-
url: req.url,
|
|
139
|
-
});
|
|
123
|
+
(0, cli_1.logJson)("repository-server", "request failed", { id });
|
|
140
124
|
console.error(error);
|
|
141
125
|
}
|
|
142
|
-
res.
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
if (!res.headersSent)
|
|
127
|
+
res.writeHead(500, error.message);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
if (requestError) {
|
|
131
|
+
(0, cli_1.logJson)("repository-server", "request error", { id });
|
|
132
|
+
console.error(requestError);
|
|
133
|
+
}
|
|
134
|
+
if (responseError) {
|
|
135
|
+
(0, cli_1.logJson)("repository-server", "response error", { id });
|
|
136
|
+
console.error(responseError);
|
|
137
|
+
}
|
|
138
|
+
if (requestError || responseError) {
|
|
139
|
+
res.destroy();
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
res.end();
|
|
143
|
+
}
|
|
145
144
|
}
|
|
146
145
|
});
|
|
147
146
|
}
|
package/lib/utils/math.d.ts
CHANGED
package/lib/utils/math.js
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.progressPercent = void 0;
|
|
3
|
+
exports.Counter = exports.progressPercent = void 0;
|
|
4
4
|
function progressPercent(total, current) {
|
|
5
5
|
if (total === 0 && current === 0)
|
|
6
6
|
return 0;
|
|
7
7
|
return Number(((current / total) * 100).toFixed(2));
|
|
8
8
|
}
|
|
9
9
|
exports.progressPercent = progressPercent;
|
|
10
|
+
class Counter {
|
|
11
|
+
maxValue;
|
|
12
|
+
value = 0;
|
|
13
|
+
constructor(maxValue = 4294967295) {
|
|
14
|
+
this.maxValue = maxValue;
|
|
15
|
+
}
|
|
16
|
+
next() {
|
|
17
|
+
if (this.maxValue && this.value >= this.maxValue)
|
|
18
|
+
this.value = 0;
|
|
19
|
+
return ++this.value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.Counter = Counter;
|