@datatruck/cli 0.41.5 → 0.41.6
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/utils/bytes.d.ts +1 -1
- package/lib/utils/bytes.js +6 -5
- package/lib/utils/mysql.d.ts +2 -0
- package/lib/utils/mysql.js +2 -0
- package/lib/utils/restic.d.ts +14 -2
- package/lib/utils/restic.js +25 -3
- package/package.json +1 -1
package/lib/utils/bytes.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function formatBytes(
|
|
1
|
+
export declare function formatBytes(inBytes: number, sign?: boolean): string;
|
|
2
2
|
export declare function parseSize(size: string): number;
|
package/lib/utils/bytes.js
CHANGED
|
@@ -4,14 +4,15 @@ exports.formatBytes = formatBytes;
|
|
|
4
4
|
exports.parseSize = parseSize;
|
|
5
5
|
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
6
6
|
const sizeRegex = new RegExp(`^(\\d+(?:\\.\\d+)?)\\s*(${units.join("|")})$`, "i");
|
|
7
|
-
function formatBytes(
|
|
7
|
+
function formatBytes(inBytes, sign = false) {
|
|
8
8
|
let u = 0;
|
|
9
|
-
let n =
|
|
10
|
-
if (
|
|
11
|
-
throw new Error(`Invalid bytes: ${
|
|
9
|
+
let n = Math.abs(inBytes);
|
|
10
|
+
if (n < 0n)
|
|
11
|
+
throw new Error(`Invalid bytes: ${n.toString()}`);
|
|
12
12
|
while (n >= 1024n && ++u)
|
|
13
13
|
n = n / 1024;
|
|
14
|
-
|
|
14
|
+
const result = Number(n).toFixed(n < 10 && u > 0 ? 1 : 0) + units[u];
|
|
15
|
+
return inBytes < 0 ? `-${result}` : `${sign ? "+" : ""}${result}`;
|
|
15
16
|
}
|
|
16
17
|
function parseSize(size) {
|
|
17
18
|
const matches = sizeRegex.exec(size);
|
package/lib/utils/mysql.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type MysqlCliOptions = {
|
|
|
7
7
|
username: string;
|
|
8
8
|
verbose?: boolean;
|
|
9
9
|
database?: string;
|
|
10
|
+
ssl?: boolean;
|
|
11
|
+
vars?: Record<string, string | number>;
|
|
10
12
|
};
|
|
11
13
|
export declare function assertDumpFile(path: string): Promise<void>;
|
|
12
14
|
export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
|
package/lib/utils/mysql.js
CHANGED
|
@@ -66,9 +66,11 @@ async function createMysqlCli(options) {
|
|
|
66
66
|
const data = [
|
|
67
67
|
`[client]`,
|
|
68
68
|
`host = "${options.hostname}"`,
|
|
69
|
+
...(options.ssl === false ? [`skip-ssl`] : []),
|
|
69
70
|
...(options.port ? [`port = "${options.port}"`] : []),
|
|
70
71
|
`user = "${options.username}"`,
|
|
71
72
|
`password = "${password}"`,
|
|
73
|
+
...Object.entries(options.vars || {}).map(([key, value]) => `${key} = "${value}"`),
|
|
72
74
|
];
|
|
73
75
|
const path = (0, path_1.join)(dir, "mysql.conf");
|
|
74
76
|
await (0, promises_1.writeFile)(path, data.join("\n"));
|
package/lib/utils/restic.d.ts
CHANGED
|
@@ -58,8 +58,10 @@ export declare class Restic {
|
|
|
58
58
|
private createProcess;
|
|
59
59
|
exec(args: string[], options?: AsyncProcessOptions): Promise<number>;
|
|
60
60
|
json<T>(args: string[], options?: AsyncProcessOptions): Promise<T>;
|
|
61
|
+
init(): Promise<void>;
|
|
62
|
+
tryInit(): Promise<boolean>;
|
|
61
63
|
checkRepository(): Promise<boolean>;
|
|
62
|
-
forget(options: {
|
|
64
|
+
forget<JSON extends boolean = false>(options: {
|
|
63
65
|
snapshotId?: string;
|
|
64
66
|
keepLast?: number;
|
|
65
67
|
keepHourly?: number;
|
|
@@ -72,7 +74,17 @@ export declare class Restic {
|
|
|
72
74
|
tag?: string[];
|
|
73
75
|
prune?: boolean;
|
|
74
76
|
args?: string[];
|
|
75
|
-
|
|
77
|
+
json?: JSON;
|
|
78
|
+
}): Promise<[
|
|
79
|
+
true
|
|
80
|
+
] extends [JSON] ? {
|
|
81
|
+
tags: any;
|
|
82
|
+
host: any;
|
|
83
|
+
paths: any;
|
|
84
|
+
keep: any[] | null;
|
|
85
|
+
remove: any[] | null;
|
|
86
|
+
reason: any[] | null;
|
|
87
|
+
}[] : string>;
|
|
76
88
|
snapshots(options: {
|
|
77
89
|
ids?: string[];
|
|
78
90
|
tags?: string[];
|
package/lib/utils/restic.js
CHANGED
|
@@ -109,15 +109,27 @@ class Restic {
|
|
|
109
109
|
const stdout = await this.createProcess(args, options).stdout.fetch();
|
|
110
110
|
return JSON.parse(stdout);
|
|
111
111
|
}
|
|
112
|
+
async init() {
|
|
113
|
+
await this.exec(["init"]);
|
|
114
|
+
}
|
|
115
|
+
async tryInit() {
|
|
116
|
+
const exists = await this.checkRepository();
|
|
117
|
+
if ((0, fs_1.isLocalDir)(this.options.env.RESTIC_REPOSITORY) && !exists)
|
|
118
|
+
await this.init();
|
|
119
|
+
return exists;
|
|
120
|
+
}
|
|
112
121
|
async checkRepository() {
|
|
113
122
|
return ((await this.exec(["cat", "config"], {
|
|
114
123
|
$exitCode: false,
|
|
115
124
|
})) === 0);
|
|
116
125
|
}
|
|
117
126
|
async forget(options) {
|
|
118
|
-
|
|
127
|
+
const p = this.createProcess([
|
|
119
128
|
"forget",
|
|
120
|
-
...(options.
|
|
129
|
+
...(options.json ? ["--json"] : []),
|
|
130
|
+
...(options.keepLast
|
|
131
|
+
? ["--keep-last", options.keepLast.toString()]
|
|
132
|
+
: []),
|
|
121
133
|
...(options.keepHourly
|
|
122
134
|
? ["--keep-hourly", options.keepHourly.toString()]
|
|
123
135
|
: []),
|
|
@@ -143,7 +155,17 @@ class Restic {
|
|
|
143
155
|
...(options.prune ? ["--prune"] : []),
|
|
144
156
|
...(options.args || []),
|
|
145
157
|
...(options.snapshotId ? [options.snapshotId] : []),
|
|
146
|
-
]);
|
|
158
|
+
], {});
|
|
159
|
+
const stdout = await p.stdout.fetch();
|
|
160
|
+
if (options.json) {
|
|
161
|
+
if (stdout === "")
|
|
162
|
+
return [];
|
|
163
|
+
const [json] = stdout.split("\n");
|
|
164
|
+
return JSON.parse(json);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return stdout;
|
|
168
|
+
}
|
|
147
169
|
}
|
|
148
170
|
async snapshots(options) {
|
|
149
171
|
const json = options.json ?? true;
|