@datatruck/cli 0.30.1 → 0.32.0
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.js +4 -8
- package/Action/ConfigAction.d.ts +1 -0
- package/Action/ConfigAction.js +8 -7
- package/Action/CopyAction.js +1 -1
- package/Action/RestoreAction.js +1 -1
- package/CHANGELOG.md +22 -0
- package/Command/BackupCommand.d.ts +1 -1
- package/Command/CleanCacheCommand.d.ts +1 -1
- package/Command/CommandAbstract.d.ts +2 -1
- package/Command/CommandAbstract.js +3 -1
- package/Command/CopyCommand.d.ts +1 -1
- package/Command/RestoreCommand.d.ts +1 -1
- package/Command/StartServerCommand.js +31 -8
- package/Config/Config.d.ts +7 -1
- package/Config/Config.js +79 -26
- package/Config/RepositoryConfig.d.ts +1 -0
- package/Config/RepositoryConfig.js +6 -1
- package/Factory/CommandFactory.d.ts +1 -1
- package/Factory/CommandFactory.js +2 -2
- package/JsonSchema/backup-def.d.ts +30 -0
- package/JsonSchema/backup-def.js +18 -0
- package/JsonSchema/copy-def.d.ts +24 -0
- package/JsonSchema/copy-def.js +15 -0
- package/Task/ScriptTask.d.ts +2 -11
- package/Task/ScriptTask.js +27 -33
- package/cli.js +1 -1
- package/config.schema.json +227 -40
- package/package.json +5 -4
- package/pkg.d.ts +6 -0
- package/pkg.js +10 -0
- package/utils/cli.d.ts +4 -1
- package/utils/cli.js +23 -3
- package/utils/datatruck/client.js +3 -3
- package/utils/datatruck/cron-server.d.ts +23 -0
- package/utils/datatruck/cron-server.js +59 -0
- package/utils/datatruck/paths.js +4 -6
- package/utils/datatruck/{server.d.ts → repository-server.d.ts} +12 -5
- package/utils/datatruck/{server.js → repository-server.js} +48 -26
- package/utils/fs.js +19 -18
- package/utils/http.d.ts +8 -2
- package/utils/http.js +12 -14
- package/utils/object.d.ts +1 -1
- package/utils/object.js +6 -6
- package/utils/schema.d.ts +34 -0
- package/utils/schema.js +36 -0
- package/utils/steps.d.ts +10 -10
- package/utils/steps.js +22 -8
- package/utils/string.d.ts +0 -3
- package/utils/string.js +22 -42
- package/utils/ObjectVault.d.ts +0 -13
- package/utils/ObjectVault.js +0 -29
package/utils/string.js
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.undefIfEmpty = exports.
|
|
3
|
+
exports.undefIfEmpty = exports.checkMatch = exports.createMatchFilter = exports.endsWith = exports.match = exports.makePathPatterns = exports.formatUri = exports.parseStringList = exports.render = exports.snakeCase = void 0;
|
|
4
4
|
const AppError_1 = require("../Error/AppError");
|
|
5
5
|
const micromatch_1 = require("micromatch");
|
|
6
|
-
function serialize(message, data) {
|
|
7
|
-
if (data)
|
|
8
|
-
return `${message} (${JSON.stringify(data, null, 2)})`;
|
|
9
|
-
return message;
|
|
10
|
-
}
|
|
11
|
-
exports.serialize = serialize;
|
|
12
6
|
function snakeCase(value, char = "_") {
|
|
13
7
|
return value.replace(/[A-Z]/g, (letter) => `${char}${letter.toLowerCase()}`);
|
|
14
8
|
}
|
|
15
9
|
exports.snakeCase = snakeCase;
|
|
16
10
|
function render(subject, vars) {
|
|
17
|
-
return subject.replace(/{([\w
|
|
11
|
+
return subject.replace(/{([\w\./]*)}/g, function (match, name) {
|
|
18
12
|
if (!name.length) {
|
|
19
13
|
return "{";
|
|
20
14
|
}
|
|
21
15
|
else if (name === "/") {
|
|
22
16
|
return "}";
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
let ref = vars;
|
|
19
|
+
for (const key of name.split(".")) {
|
|
20
|
+
if (!!ref && typeof ref === "object") {
|
|
21
|
+
ref = ref[key];
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
ref = undefined;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (typeof ref !== "string" &&
|
|
29
|
+
typeof ref !== "number" &&
|
|
30
|
+
typeof ref !== "boolean")
|
|
31
|
+
throw new Error(`Variable is not valid: ${name}`, {
|
|
32
|
+
cause: {
|
|
33
|
+
vars,
|
|
34
|
+
value: ref,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
return ref.toString();
|
|
28
38
|
});
|
|
29
39
|
}
|
|
30
40
|
exports.render = render;
|
|
@@ -61,26 +71,6 @@ function formatUri(input, hidePassword) {
|
|
|
61
71
|
return uri;
|
|
62
72
|
}
|
|
63
73
|
exports.formatUri = formatUri;
|
|
64
|
-
function formatSeconds(seconds) {
|
|
65
|
-
let unit;
|
|
66
|
-
let value;
|
|
67
|
-
if (seconds > 60 * 60) {
|
|
68
|
-
value = seconds / 60 / 60;
|
|
69
|
-
unit = `hour`;
|
|
70
|
-
}
|
|
71
|
-
else if (seconds > 60) {
|
|
72
|
-
value = seconds / 60;
|
|
73
|
-
unit = `minute`;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
value = seconds;
|
|
77
|
-
unit = `second`;
|
|
78
|
-
}
|
|
79
|
-
if (value !== 1)
|
|
80
|
-
unit += `s`;
|
|
81
|
-
return `${value.toFixed(2)} ${unit}`;
|
|
82
|
-
}
|
|
83
|
-
exports.formatSeconds = formatSeconds;
|
|
84
74
|
function makePathPatterns(values) {
|
|
85
75
|
return values?.flatMap((v) => {
|
|
86
76
|
if (v === "*" || v === "**" || v === "<empty>" || v === "!<empty>") {
|
|
@@ -111,16 +101,6 @@ function checkMatch(subject, patterns) {
|
|
|
111
101
|
return (0, micromatch_1.isMatch)(subject, patterns);
|
|
112
102
|
}
|
|
113
103
|
exports.checkMatch = checkMatch;
|
|
114
|
-
function formatDateTime(datetime) {
|
|
115
|
-
const date = new Date(datetime);
|
|
116
|
-
const [result] = new Date(date.getTime() - date.getTimezoneOffset() * 60000)
|
|
117
|
-
.toISOString()
|
|
118
|
-
.replace("Z", "")
|
|
119
|
-
.replace("T", " ")
|
|
120
|
-
.split(".");
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
exports.formatDateTime = formatDateTime;
|
|
124
104
|
function undefIfEmpty(input) {
|
|
125
105
|
return input.length ? input : undefined;
|
|
126
106
|
}
|
package/utils/ObjectVault.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type KeysType = (string | number)[];
|
|
2
|
-
export declare class ObjectVault<TObject> {
|
|
3
|
-
protected counter: number;
|
|
4
|
-
protected readonly ids: Record<string, number>;
|
|
5
|
-
protected readonly objects: Record<number, TObject>;
|
|
6
|
-
static serializeKeys(keys: KeysType): string;
|
|
7
|
-
get(id: number): TObject;
|
|
8
|
-
getId(keys: KeysType): number;
|
|
9
|
-
add(options: {
|
|
10
|
-
keys: KeysType;
|
|
11
|
-
handler: (id: number) => TObject;
|
|
12
|
-
}): TObject;
|
|
13
|
-
}
|
package/utils/ObjectVault.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObjectVault = void 0;
|
|
4
|
-
class ObjectVault {
|
|
5
|
-
counter = 0;
|
|
6
|
-
ids = {};
|
|
7
|
-
objects = {};
|
|
8
|
-
static serializeKeys(keys) {
|
|
9
|
-
return JSON.stringify(keys);
|
|
10
|
-
}
|
|
11
|
-
get(id) {
|
|
12
|
-
if (!(id in this.objects))
|
|
13
|
-
throw new Error(`Object not found: ${id}`);
|
|
14
|
-
return this.objects[id];
|
|
15
|
-
}
|
|
16
|
-
getId(keys) {
|
|
17
|
-
const key = ObjectVault.serializeKeys(keys);
|
|
18
|
-
const id = this.ids[key];
|
|
19
|
-
if (!id)
|
|
20
|
-
throw new Error(`Id not found: ${JSON.stringify(keys)}`);
|
|
21
|
-
return id;
|
|
22
|
-
}
|
|
23
|
-
add(options) {
|
|
24
|
-
const key = ObjectVault.serializeKeys(options.keys);
|
|
25
|
-
const id = (this.ids[key] = ++this.counter);
|
|
26
|
-
return (this.objects[id] = options.handler(id));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.ObjectVault = ObjectVault;
|