@datatruck/cli 0.27.0 → 0.28.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.d.ts +69 -34
- package/Action/BackupAction.js +284 -244
- package/Action/CleanCacheAction.d.ts +8 -4
- package/Action/CleanCacheAction.js +8 -5
- package/Action/ConfigAction.d.ts +12 -5
- package/Action/ConfigAction.js +14 -18
- package/Action/CopyAction.d.ts +49 -0
- package/Action/CopyAction.js +144 -0
- package/Action/InitAction.d.ts +3 -3
- package/Action/InitAction.js +9 -9
- package/Action/PruneAction.d.ts +9 -9
- package/Action/PruneAction.js +39 -23
- package/Action/RestoreAction.d.ts +48 -23
- package/Action/RestoreAction.js +158 -195
- package/Action/SnapshotsAction.d.ts +8 -8
- package/Action/SnapshotsAction.js +8 -8
- package/CHANGELOG.md +495 -0
- package/Command/BackupCommand.d.ts +6 -4
- package/Command/BackupCommand.js +9 -26
- package/Command/CleanCacheCommand.d.ts +4 -4
- package/Command/CleanCacheCommand.js +26 -5
- package/Command/CommandAbstract.d.ts +10 -7
- package/Command/CommandAbstract.js +4 -1
- package/Command/ConfigCommand.d.ts +6 -9
- package/Command/ConfigCommand.js +13 -8
- package/Command/CopyCommand.d.ts +15 -0
- package/Command/CopyCommand.js +61 -0
- package/Command/InitCommand.d.ts +4 -4
- package/Command/InitCommand.js +11 -15
- package/Command/PruneCommand.d.ts +3 -3
- package/Command/PruneCommand.js +13 -12
- package/Command/RestoreCommand.js +9 -17
- package/Command/SnapshotsCommand.d.ts +4 -4
- package/Command/SnapshotsCommand.js +16 -15
- package/Command/StartServerCommand.d.ts +3 -3
- package/Config/Config.d.ts +9 -0
- package/Config/Config.js +17 -0
- package/Config/PrunePolicyConfig.d.ts +2 -2
- package/Factory/CommandFactory.d.ts +27 -34
- package/Factory/CommandFactory.js +27 -54
- package/Factory/RepositoryFactory.d.ts +1 -1
- package/Factory/RepositoryFactory.js +3 -3
- package/Factory/TaskFactory.d.ts +1 -1
- package/Factory/TaskFactory.js +3 -3
- package/Repository/DatatruckRepository.d.ts +9 -8
- package/Repository/DatatruckRepository.js +42 -25
- package/Repository/GitRepository.d.ts +9 -8
- package/Repository/GitRepository.js +22 -25
- package/Repository/RepositoryAbstract.d.ts +39 -37
- package/Repository/RepositoryAbstract.js +4 -5
- package/Repository/ResticRepository.d.ts +9 -8
- package/Repository/ResticRepository.js +30 -28
- package/Task/GitTask.d.ts +6 -7
- package/Task/GitTask.js +24 -30
- package/Task/MariadbTask.d.ts +4 -5
- package/Task/MariadbTask.js +26 -32
- package/Task/MssqlTask.d.ts +5 -3
- package/Task/MssqlTask.js +11 -12
- package/Task/MysqlDumpTask.d.ts +10 -3
- package/Task/MysqlDumpTask.js +107 -31
- package/Task/ScriptTask.d.ts +23 -18
- package/Task/ScriptTask.js +34 -24
- package/Task/SqlDumpTaskAbstract.d.ts +8 -3
- package/Task/SqlDumpTaskAbstract.js +31 -19
- package/Task/TaskAbstract.d.ts +24 -25
- package/Task/TaskAbstract.js +6 -10
- package/cli.js +13 -5
- package/config.schema.json +86 -1
- package/package.json +4 -5
- package/utils/DataFormat.d.ts +23 -12
- package/utils/DataFormat.js +36 -14
- package/utils/cli.d.ts +2 -9
- package/utils/cli.js +9 -52
- package/utils/datatruck/client.d.ts +2 -0
- package/utils/datatruck/client.js +3 -0
- package/utils/datatruck/config.d.ts +2 -0
- package/utils/datatruck/config.js +18 -3
- package/utils/datatruck/paths.d.ts +5 -9
- package/utils/datatruck/paths.js +2 -2
- package/utils/datatruck/snapshot.d.ts +2 -2
- package/utils/date.d.ts +7 -3
- package/utils/date.js +22 -14
- package/utils/fs.d.ts +16 -11
- package/utils/fs.js +81 -48
- package/utils/list.d.ts +64 -0
- package/utils/list.js +145 -0
- package/utils/mysql.d.ts +2 -0
- package/utils/mysql.js +21 -2
- package/utils/process.d.ts +1 -0
- package/utils/process.js +24 -31
- package/utils/progress.d.ts +33 -0
- package/utils/progress.js +113 -0
- package/utils/steps.d.ts +11 -0
- package/utils/steps.js +22 -10
- package/utils/stream.d.ts +7 -0
- package/utils/stream.js +10 -0
- package/utils/string.d.ts +0 -1
- package/utils/string.js +1 -13
- package/utils/tar.d.ts +10 -3
- package/utils/tar.js +70 -44
- package/utils/temp.d.ts +26 -0
- package/utils/temp.js +133 -0
- package/utils/virtual-fs.d.ts +6 -2
- package/utils/virtual-fs.js +6 -0
- package/Action/BackupSessionsAction.d.ts +0 -13
- package/Action/BackupSessionsAction.js +0 -18
- package/Action/RestoreSessionsAction.d.ts +0 -13
- package/Action/RestoreSessionsAction.js +0 -18
- package/Command/BackupSessionsCommand.d.ts +0 -12
- package/Command/BackupSessionsCommand.js +0 -92
- package/Command/RestoreSessionsCommand.d.ts +0 -12
- package/Command/RestoreSessionsCommand.js +0 -91
- package/Decorator/EntityDecorator.d.ts +0 -11
- package/Decorator/EntityDecorator.js +0 -17
- package/Entity/BackupSessionEntity.d.ts +0 -6
- package/Entity/BackupSessionEntity.js +0 -25
- package/Entity/BackupSessionRepositoryEntity.d.ts +0 -6
- package/Entity/BackupSessionRepositoryEntity.js +0 -25
- package/Entity/BackupSessionTaskEntity.d.ts +0 -5
- package/Entity/BackupSessionTaskEntity.js +0 -24
- package/Entity/CrudEntityAbstract.d.ts +0 -5
- package/Entity/CrudEntityAbstract.js +0 -9
- package/Entity/RestoreSessionEntity.d.ts +0 -5
- package/Entity/RestoreSessionEntity.js +0 -24
- package/Entity/RestoreSessionRepositoryEntity.d.ts +0 -6
- package/Entity/RestoreSessionRepositoryEntity.js +0 -25
- package/Entity/RestoreSessionTaskEntity.d.ts +0 -5
- package/Entity/RestoreSessionTaskEntity.js +0 -24
- package/Entity/StateEntityAbstract.d.ts +0 -9
- package/Entity/StateEntityAbstract.js +0 -12
- package/Factory/EntityFactory.d.ts +0 -6
- package/Factory/EntityFactory.js +0 -40
- package/SessionDriver/ConsoleSessionDriver.d.ts +0 -42
- package/SessionDriver/ConsoleSessionDriver.js +0 -208
- package/SessionDriver/SessionDriverAbstract.d.ts +0 -77
- package/SessionDriver/SessionDriverAbstract.js +0 -28
- package/SessionDriver/SqliteSessionDriver.d.ts +0 -20
- package/SessionDriver/SqliteSessionDriver.js +0 -173
- package/SessionManager/BackupSessionManager.d.ts +0 -45
- package/SessionManager/BackupSessionManager.js +0 -218
- package/SessionManager/RestoreSessionManager.d.ts +0 -47
- package/SessionManager/RestoreSessionManager.js +0 -218
- package/SessionManager/SessionManagerAbstract.d.ts +0 -18
- package/SessionManager/SessionManagerAbstract.js +0 -36
- package/migrations/001-initial.sql +0 -98
- package/utils/entity.d.ts +0 -4
- package/utils/entity.js +0 -10
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Progress } from "../utils/progress";
|
|
3
|
-
import { WriteDataType, ReadResultType, SessionDriverAbstract, SessionDriverOptions } from "./SessionDriverAbstract";
|
|
4
|
-
type BadgeType = {
|
|
5
|
-
name: string;
|
|
6
|
-
value: string;
|
|
7
|
-
color: (input: string) => string;
|
|
8
|
-
};
|
|
9
|
-
type MessageType = {
|
|
10
|
-
sessionId: number;
|
|
11
|
-
level?: number;
|
|
12
|
-
textPrefix?: string;
|
|
13
|
-
text?: string;
|
|
14
|
-
badges: BadgeType[];
|
|
15
|
-
errorBadge?: BadgeType;
|
|
16
|
-
progress?: Progress;
|
|
17
|
-
};
|
|
18
|
-
type ConsoleSessionDriverOptions = SessionDriverOptions & {
|
|
19
|
-
progress?: "auto" | "tty" | "plain";
|
|
20
|
-
};
|
|
21
|
-
export declare class ConsoleSessionDriver extends SessionDriverAbstract<ConsoleSessionDriverOptions> {
|
|
22
|
-
protected lastMessage: MessageType | undefined;
|
|
23
|
-
protected lastMessageText: string | undefined;
|
|
24
|
-
protected prints: number;
|
|
25
|
-
protected renderInterval: NodeJS.Timeout;
|
|
26
|
-
protected rendering?: boolean;
|
|
27
|
-
protected lastColumns?: number;
|
|
28
|
-
protected startTime: number;
|
|
29
|
-
protected chron: {
|
|
30
|
-
start: () => number;
|
|
31
|
-
elapsed: (formatted?: boolean | undefined) => string | number;
|
|
32
|
-
};
|
|
33
|
-
protected tty: boolean;
|
|
34
|
-
onInit(): Promise<void>;
|
|
35
|
-
onEnd(data?: Record<string, any>): Promise<void>;
|
|
36
|
-
onRead(): Promise<ReadResultType[]>;
|
|
37
|
-
protected printMessage(message: MessageType, endMessage: boolean): void;
|
|
38
|
-
protected renderSpinner(text: string): string;
|
|
39
|
-
protected renderMessage(message: MessageType): string;
|
|
40
|
-
onWrite(data: WriteDataType): Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
export {};
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ConsoleSessionDriver = void 0;
|
|
7
|
-
const AppError_1 = require("../Error/AppError");
|
|
8
|
-
const cli_1 = require("../utils/cli");
|
|
9
|
-
const date_1 = require("../utils/date");
|
|
10
|
-
const SessionDriverAbstract_1 = require("./SessionDriverAbstract");
|
|
11
|
-
const chalk_1 = require("chalk");
|
|
12
|
-
const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
|
|
13
|
-
const sep = (0, chalk_1.grey)(`|`);
|
|
14
|
-
const renderBadge = (badge) => `${badge.color(badge.name)}${(0, chalk_1.grey)(`:`)} ${(0, chalk_1.white)(badge.value)}`;
|
|
15
|
-
const renderBadges = (badges) => badges.map(renderBadge).join(` ${sep} `);
|
|
16
|
-
class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract {
|
|
17
|
-
lastMessage;
|
|
18
|
-
lastMessageText;
|
|
19
|
-
prints = 0;
|
|
20
|
-
renderInterval;
|
|
21
|
-
rendering;
|
|
22
|
-
lastColumns;
|
|
23
|
-
startTime;
|
|
24
|
-
chron = (0, date_1.createChron)();
|
|
25
|
-
tty;
|
|
26
|
-
async onInit() {
|
|
27
|
-
this.tty = this.options.verbose
|
|
28
|
-
? false
|
|
29
|
-
: this.options.progress === "auto"
|
|
30
|
-
? process.stdout.isTTY
|
|
31
|
-
: this.options.progress === "tty";
|
|
32
|
-
this.chron.start();
|
|
33
|
-
this.renderInterval = setInterval(() => {
|
|
34
|
-
if (this.lastMessage)
|
|
35
|
-
this.printMessage(this.lastMessage, false);
|
|
36
|
-
}, 100);
|
|
37
|
-
}
|
|
38
|
-
async onEnd(data) {
|
|
39
|
-
clearInterval(this.renderInterval);
|
|
40
|
-
if (this.tty)
|
|
41
|
-
process.stdout.write(cli_1.showCursorCommand);
|
|
42
|
-
(0, cli_1.logVars)({
|
|
43
|
-
...data,
|
|
44
|
-
elapsed: this.chron.elapsed(true),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
async onRead() {
|
|
48
|
-
throw new AppError_1.AppError("Method not implemented");
|
|
49
|
-
}
|
|
50
|
-
printMessage(message, endMessage) {
|
|
51
|
-
const text = this.renderMessage(message);
|
|
52
|
-
if (!this.tty && this.lastMessageText === text) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (!this.tty) {
|
|
56
|
-
process.stdout.write(`${this.renderSpinner(text)}\n`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const columns = process.stdout.columns;
|
|
60
|
-
const line = this.renderSpinner(text);
|
|
61
|
-
const [truncatedLine, truncated] = endMessage
|
|
62
|
-
? [line, false]
|
|
63
|
-
: (0, cli_1.truncate)(line, columns);
|
|
64
|
-
if (this.lastColumns && columns !== this.lastColumns && truncated)
|
|
65
|
-
process.stdout.write(`${cli_1.clearCommand}\n`);
|
|
66
|
-
process.stdout.write(`${cli_1.clearCommand}${truncatedLine}${cli_1.hideCursorCommand}`);
|
|
67
|
-
this.lastColumns = columns;
|
|
68
|
-
}
|
|
69
|
-
this.prints++;
|
|
70
|
-
this.lastMessage = message;
|
|
71
|
-
this.lastMessageText = text;
|
|
72
|
-
}
|
|
73
|
-
renderSpinner(text) {
|
|
74
|
-
return text.replace("{spinner}", (0, chalk_1.grey)(this.tty ? (0, cli_1.renderSpinner)(this.prints) : "?"));
|
|
75
|
-
}
|
|
76
|
-
renderMessage(message) {
|
|
77
|
-
const badges = renderBadges([
|
|
78
|
-
...message.badges,
|
|
79
|
-
...(message.errorBadge ? [message.errorBadge] : []),
|
|
80
|
-
]);
|
|
81
|
-
const padding = " ".repeat(message.level ?? 0);
|
|
82
|
-
const sessionId = message.sessionId.toString().padStart(2, "0");
|
|
83
|
-
let parts = [
|
|
84
|
-
`${padding}${message.textPrefix} [${(0, chalk_1.grey)(sessionId)}] ${message.text}`,
|
|
85
|
-
badges,
|
|
86
|
-
];
|
|
87
|
-
const progress = message.progress;
|
|
88
|
-
const absolute = progress?.absolute || {};
|
|
89
|
-
const relative = progress?.relative || {};
|
|
90
|
-
if (typeof absolute.percent === "number" ||
|
|
91
|
-
typeof relative.percent === "number") {
|
|
92
|
-
parts.push((0, cli_1.renderProgressBar)(absolute.percent ?? 0, 10, relative.percent ?? undefined));
|
|
93
|
-
}
|
|
94
|
-
const createProgressParts = (p) => {
|
|
95
|
-
const result = [];
|
|
96
|
-
if (typeof p.percent === "number")
|
|
97
|
-
result.push(`${p.percent.toFixed(2)}%`);
|
|
98
|
-
if (typeof p.current === "number" || typeof p.total === "number") {
|
|
99
|
-
const format = (value) => p.format === "size" ? (0, pretty_bytes_1.default)(value) : value;
|
|
100
|
-
if (typeof p.current === "number" && typeof p.total === "number") {
|
|
101
|
-
result.push(`${format(p.current)}/${format(p.total)}`);
|
|
102
|
-
}
|
|
103
|
-
else if (typeof p.current === "number") {
|
|
104
|
-
result.push(`${format(p.current)}`);
|
|
105
|
-
}
|
|
106
|
-
else if (typeof p.total === "number") {
|
|
107
|
-
result.push(`?/${format(p.total)}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (p.description && p.payload) {
|
|
111
|
-
result.push(`${p.description}: ${p.payload}`);
|
|
112
|
-
}
|
|
113
|
-
else if (p.description) {
|
|
114
|
-
result.push(p.description);
|
|
115
|
-
}
|
|
116
|
-
else if (p.payload) {
|
|
117
|
-
result.push(p.payload);
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
};
|
|
121
|
-
if (progress?.absolute)
|
|
122
|
-
parts.push(...createProgressParts(progress?.absolute));
|
|
123
|
-
if (progress?.relative) {
|
|
124
|
-
const relativeParts = createProgressParts(progress?.relative);
|
|
125
|
-
if (relativeParts.length) {
|
|
126
|
-
return (parts.join(` ${sep} `) +
|
|
127
|
-
` ${(0, chalk_1.cyan)("▷")} ` +
|
|
128
|
-
relativeParts.join(` ${sep} `));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return parts.join(` ${sep} `);
|
|
132
|
-
}
|
|
133
|
-
async onWrite(data) {
|
|
134
|
-
if (data.action === SessionDriverAbstract_1.ActionEnum.Init)
|
|
135
|
-
return;
|
|
136
|
-
const message = {
|
|
137
|
-
sessionId: "sessionId" in data.data ? data.data.sessionId : data.data.id,
|
|
138
|
-
badges: [],
|
|
139
|
-
};
|
|
140
|
-
const isHeader = data.entity === SessionDriverAbstract_1.EntityEnum.BackupSession ||
|
|
141
|
-
data.entity === SessionDriverAbstract_1.EntityEnum.RestoreSession;
|
|
142
|
-
const hasProgress = isHeader ||
|
|
143
|
-
data.entity === SessionDriverAbstract_1.EntityEnum.BackupSessionTask ||
|
|
144
|
-
data.entity === SessionDriverAbstract_1.EntityEnum.BackupSessionRepository ||
|
|
145
|
-
data.entity === SessionDriverAbstract_1.EntityEnum.RestoreSessionTask ||
|
|
146
|
-
data.entity === SessionDriverAbstract_1.EntityEnum.RestoreSessionRepository;
|
|
147
|
-
if (data.action === SessionDriverAbstract_1.ActionEnum.Start) {
|
|
148
|
-
if (isHeader) {
|
|
149
|
-
message.textPrefix = data.data.error ? (0, chalk_1.red)("⨉") : (0, chalk_1.green)("✓");
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
message.textPrefix = hasProgress ? "{spinner}" : (0, chalk_1.grey)("?");
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
else if (data.action === SessionDriverAbstract_1.ActionEnum.End) {
|
|
156
|
-
message.textPrefix = data.data.error ? (0, chalk_1.red)("⨉") : (0, chalk_1.green)("✓");
|
|
157
|
-
if (data.data.error)
|
|
158
|
-
message.errorBadge = {
|
|
159
|
-
name: "error",
|
|
160
|
-
value: this.tty && data.data.error.startsWith(`${AppError_1.AppError.name} :`)
|
|
161
|
-
? data.data.error.split("\n")[0]
|
|
162
|
-
: data.data.error,
|
|
163
|
-
color: chalk_1.red,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
else if (data.action === SessionDriverAbstract_1.ActionEnum.Progress) {
|
|
167
|
-
message.textPrefix = "{spinner}";
|
|
168
|
-
}
|
|
169
|
-
if (hasProgress) {
|
|
170
|
-
message.progress = data.data.progress;
|
|
171
|
-
}
|
|
172
|
-
if (data.entity === SessionDriverAbstract_1.EntityEnum.BackupSession ||
|
|
173
|
-
data.entity === SessionDriverAbstract_1.EntityEnum.RestoreSession) {
|
|
174
|
-
message.text = data.data.packageName;
|
|
175
|
-
message.badges.push({
|
|
176
|
-
name: "snap",
|
|
177
|
-
value: data.data.snapshotId.slice(0, 8),
|
|
178
|
-
color: chalk_1.cyan,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
else if (data.entity === SessionDriverAbstract_1.EntityEnum.BackupSessionTask ||
|
|
182
|
-
data.entity === SessionDriverAbstract_1.EntityEnum.RestoreSessionTask) {
|
|
183
|
-
message.text = data.sessionData.packageName;
|
|
184
|
-
message.badges.push({
|
|
185
|
-
name: "task",
|
|
186
|
-
value: data.data.taskName,
|
|
187
|
-
color: chalk_1.cyan,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
else if (data.entity === SessionDriverAbstract_1.EntityEnum.BackupSessionRepository ||
|
|
191
|
-
data.entity === SessionDriverAbstract_1.EntityEnum.RestoreSessionRepository) {
|
|
192
|
-
message.text = data.sessionData.packageName;
|
|
193
|
-
message.badges.push({
|
|
194
|
-
name: "repo",
|
|
195
|
-
value: data.data.repositoryName,
|
|
196
|
-
color: chalk_1.cyan,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
if (isHeader && data.action === SessionDriverAbstract_1.ActionEnum.End) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const endMessage = this.tty && (!hasProgress || data.action === SessionDriverAbstract_1.ActionEnum.End || isHeader);
|
|
203
|
-
this.printMessage(message, endMessage);
|
|
204
|
-
if (endMessage)
|
|
205
|
-
process.stdout.write("\n");
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
exports.ConsoleSessionDriver = ConsoleSessionDriver;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { BackupSessionEntity } from "../Entity/BackupSessionEntity";
|
|
2
|
-
import { BackupSessionRepositoryEntity } from "../Entity/BackupSessionRepositoryEntity";
|
|
3
|
-
import { BackupSessionTaskEntity } from "../Entity/BackupSessionTaskEntity";
|
|
4
|
-
import { RestoreSessionEntity } from "../Entity/RestoreSessionEntity";
|
|
5
|
-
import { RestoreSessionRepositoryEntity } from "../Entity/RestoreSessionRepositoryEntity";
|
|
6
|
-
import { RestoreSessionTaskEntity } from "../Entity/RestoreSessionTaskEntity";
|
|
7
|
-
export declare enum ActionEnum {
|
|
8
|
-
Init = 0,
|
|
9
|
-
Start = 1,
|
|
10
|
-
Progress = 2,
|
|
11
|
-
End = 3
|
|
12
|
-
}
|
|
13
|
-
export declare enum EntityEnum {
|
|
14
|
-
BackupSession = 0,
|
|
15
|
-
BackupSessionTask = 1,
|
|
16
|
-
BackupSessionRepository = 2,
|
|
17
|
-
RestoreSession = 3,
|
|
18
|
-
RestoreSessionTask = 4,
|
|
19
|
-
RestoreSessionRepository = 5
|
|
20
|
-
}
|
|
21
|
-
export type WriteDataType = {
|
|
22
|
-
action: ActionEnum;
|
|
23
|
-
entity: EntityEnum.BackupSession;
|
|
24
|
-
data: BackupSessionEntity;
|
|
25
|
-
} | {
|
|
26
|
-
action: ActionEnum;
|
|
27
|
-
entity: EntityEnum.BackupSessionRepository;
|
|
28
|
-
data: BackupSessionRepositoryEntity;
|
|
29
|
-
sessionData: BackupSessionEntity;
|
|
30
|
-
} | {
|
|
31
|
-
action: ActionEnum;
|
|
32
|
-
entity: EntityEnum.BackupSessionTask;
|
|
33
|
-
data: BackupSessionTaskEntity;
|
|
34
|
-
sessionData: BackupSessionEntity;
|
|
35
|
-
} | {
|
|
36
|
-
action: ActionEnum;
|
|
37
|
-
entity: EntityEnum.RestoreSession;
|
|
38
|
-
data: RestoreSessionEntity;
|
|
39
|
-
} | {
|
|
40
|
-
action: ActionEnum;
|
|
41
|
-
entity: EntityEnum.RestoreSessionTask;
|
|
42
|
-
data: RestoreSessionTaskEntity;
|
|
43
|
-
sessionData: RestoreSessionEntity;
|
|
44
|
-
} | {
|
|
45
|
-
action: ActionEnum;
|
|
46
|
-
entity: EntityEnum.RestoreSessionRepository;
|
|
47
|
-
data: RestoreSessionRepositoryEntity;
|
|
48
|
-
sessionData: RestoreSessionEntity;
|
|
49
|
-
};
|
|
50
|
-
export type ReadDataType = {
|
|
51
|
-
repositoryNames?: string[];
|
|
52
|
-
packageNames?: string[];
|
|
53
|
-
tags?: string[];
|
|
54
|
-
limit?: number | null;
|
|
55
|
-
verbose?: boolean;
|
|
56
|
-
};
|
|
57
|
-
export type ReadResultType = {
|
|
58
|
-
id: number;
|
|
59
|
-
snapshotId: string;
|
|
60
|
-
creationDate: string;
|
|
61
|
-
state: "started" | "ended";
|
|
62
|
-
packageName: string;
|
|
63
|
-
repositoryName: string;
|
|
64
|
-
repositoryType: string;
|
|
65
|
-
error: string | null;
|
|
66
|
-
};
|
|
67
|
-
export type SessionDriverOptions = {
|
|
68
|
-
verbose?: boolean;
|
|
69
|
-
};
|
|
70
|
-
export declare abstract class SessionDriverAbstract<TOptions extends SessionDriverOptions = SessionDriverOptions> {
|
|
71
|
-
readonly options: TOptions;
|
|
72
|
-
constructor(options: TOptions);
|
|
73
|
-
onInit(): Promise<void>;
|
|
74
|
-
abstract onWrite(data: WriteDataType): Promise<void>;
|
|
75
|
-
onEnd(data?: Record<string, any>): Promise<void>;
|
|
76
|
-
abstract onRead(data: ReadDataType, entity: EntityEnum): Promise<ReadResultType[]>;
|
|
77
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SessionDriverAbstract = exports.EntityEnum = exports.ActionEnum = void 0;
|
|
4
|
-
var ActionEnum;
|
|
5
|
-
(function (ActionEnum) {
|
|
6
|
-
ActionEnum[ActionEnum["Init"] = 0] = "Init";
|
|
7
|
-
ActionEnum[ActionEnum["Start"] = 1] = "Start";
|
|
8
|
-
ActionEnum[ActionEnum["Progress"] = 2] = "Progress";
|
|
9
|
-
ActionEnum[ActionEnum["End"] = 3] = "End";
|
|
10
|
-
})(ActionEnum || (exports.ActionEnum = ActionEnum = {}));
|
|
11
|
-
var EntityEnum;
|
|
12
|
-
(function (EntityEnum) {
|
|
13
|
-
EntityEnum[EntityEnum["BackupSession"] = 0] = "BackupSession";
|
|
14
|
-
EntityEnum[EntityEnum["BackupSessionTask"] = 1] = "BackupSessionTask";
|
|
15
|
-
EntityEnum[EntityEnum["BackupSessionRepository"] = 2] = "BackupSessionRepository";
|
|
16
|
-
EntityEnum[EntityEnum["RestoreSession"] = 3] = "RestoreSession";
|
|
17
|
-
EntityEnum[EntityEnum["RestoreSessionTask"] = 4] = "RestoreSessionTask";
|
|
18
|
-
EntityEnum[EntityEnum["RestoreSessionRepository"] = 5] = "RestoreSessionRepository";
|
|
19
|
-
})(EntityEnum || (exports.EntityEnum = EntityEnum = {}));
|
|
20
|
-
class SessionDriverAbstract {
|
|
21
|
-
options;
|
|
22
|
-
constructor(options) {
|
|
23
|
-
this.options = options;
|
|
24
|
-
}
|
|
25
|
-
async onInit() { }
|
|
26
|
-
async onEnd(data) { }
|
|
27
|
-
}
|
|
28
|
-
exports.SessionDriverAbstract = SessionDriverAbstract;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="./vendor-typings/sqlite3" />
|
|
2
|
-
import { WriteDataType, EntityEnum, ReadDataType, SessionDriverAbstract } from "./SessionDriverAbstract";
|
|
3
|
-
import { Database } from "sqlite";
|
|
4
|
-
import sqlite3 from "sqlite3";
|
|
5
|
-
export declare class SqliteSessionDriver extends SessionDriverAbstract {
|
|
6
|
-
protected idMap: {
|
|
7
|
-
[entity in EntityEnum]?: Record<number, number>;
|
|
8
|
-
};
|
|
9
|
-
protected db: Database<sqlite3.Database, sqlite3.Statement>;
|
|
10
|
-
onInit(): Promise<void>;
|
|
11
|
-
private buildInsertStm;
|
|
12
|
-
private buildUpdateStm;
|
|
13
|
-
private exec;
|
|
14
|
-
onRead(data: ReadDataType, type: EntityEnum): Promise<any[]>;
|
|
15
|
-
private setMapId;
|
|
16
|
-
private getMapId;
|
|
17
|
-
private static getEntityTable;
|
|
18
|
-
private static getParentEntity;
|
|
19
|
-
onWrite(data: WriteDataType): Promise<void>;
|
|
20
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SqliteSessionDriver = void 0;
|
|
7
|
-
const EntityDecorator_1 = require("../Decorator/EntityDecorator");
|
|
8
|
-
const BackupSessionEntity_1 = require("../Entity/BackupSessionEntity");
|
|
9
|
-
const BackupSessionRepositoryEntity_1 = require("../Entity/BackupSessionRepositoryEntity");
|
|
10
|
-
const RestoreSessionEntity_1 = require("../Entity/RestoreSessionEntity");
|
|
11
|
-
const RestoreSessionRepositoryEntity_1 = require("../Entity/RestoreSessionRepositoryEntity");
|
|
12
|
-
const cli_1 = require("../utils/cli");
|
|
13
|
-
const entity_1 = require("../utils/entity");
|
|
14
|
-
const path_1 = require("../utils/path");
|
|
15
|
-
const process_1 = require("../utils/process");
|
|
16
|
-
const SessionDriverAbstract_1 = require("./SessionDriverAbstract");
|
|
17
|
-
const assert_1 = require("assert");
|
|
18
|
-
const os_1 = require("os");
|
|
19
|
-
const path_2 = require("path");
|
|
20
|
-
const sqlite_1 = require("sqlite");
|
|
21
|
-
const sqlite3_1 = __importDefault(require("sqlite3"));
|
|
22
|
-
class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract {
|
|
23
|
-
idMap = {};
|
|
24
|
-
db;
|
|
25
|
-
async onInit() {
|
|
26
|
-
this.db = await (0, sqlite_1.open)({
|
|
27
|
-
filename: process.env["DATATRUCK_SQLITE_DB"] ??
|
|
28
|
-
(0, path_2.join)((0, os_1.homedir)(), "datatruck.sqlite"),
|
|
29
|
-
driver: sqlite3_1.default.Database,
|
|
30
|
-
});
|
|
31
|
-
await this.db.migrate({
|
|
32
|
-
migrationsPath: (0, path_2.join)(path_1.rootPath, "migrations"),
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
buildInsertStm(tableName, values) {
|
|
36
|
-
const keys = Object.keys(values);
|
|
37
|
-
const columnNames = keys.map((v) => `\`${v}\``).join(", ");
|
|
38
|
-
const paramNames = keys.map((v) => `:${v}`).join(", ");
|
|
39
|
-
return `INSERT INTO ${tableName} (${columnNames}) VALUES (${paramNames})`;
|
|
40
|
-
}
|
|
41
|
-
buildUpdateStm(tableName, values, pkColumnName = "id") {
|
|
42
|
-
const set = Object.keys(values)
|
|
43
|
-
.filter((v) => v !== pkColumnName)
|
|
44
|
-
.map((v) => `\`${v}\` = :${v}`)
|
|
45
|
-
.join(", ");
|
|
46
|
-
return `UPDATE ${tableName} SET ${set} WHERE ${pkColumnName} = :${pkColumnName}`;
|
|
47
|
-
}
|
|
48
|
-
async exec(query, cb) {
|
|
49
|
-
if (this.options.verbose) {
|
|
50
|
-
(0, cli_1.logExec)("query");
|
|
51
|
-
(0, process_1.logExecStdout)({ data: query, lineSalt: true });
|
|
52
|
-
}
|
|
53
|
-
const result = await cb();
|
|
54
|
-
if (this.options.verbose)
|
|
55
|
-
(0, process_1.logExecStdout)({ data: JSON.stringify(result, null, 2), lineSalt: true });
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
async onRead(data, type) {
|
|
59
|
-
const sessionMeta = (0, EntityDecorator_1.EntityDecoratorHandler)(type === SessionDriverAbstract_1.EntityEnum.BackupSession
|
|
60
|
-
? BackupSessionEntity_1.BackupSessionEntity
|
|
61
|
-
: RestoreSessionEntity_1.RestoreSessionEntity);
|
|
62
|
-
const sessionRepositoryMeta = (0, EntityDecorator_1.EntityDecoratorHandler)(type === SessionDriverAbstract_1.EntityEnum.BackupSession
|
|
63
|
-
? BackupSessionRepositoryEntity_1.BackupSessionRepositoryEntity
|
|
64
|
-
: RestoreSessionRepositoryEntity_1.RestoreSessionRepositoryEntity);
|
|
65
|
-
const sessionTable = (0, entity_1.makeTableSelector)(sessionMeta.get().tableName);
|
|
66
|
-
const repoTable = (0, entity_1.makeTableSelector)(sessionRepositoryMeta.get().tableName);
|
|
67
|
-
const where = {};
|
|
68
|
-
if (data.packageNames)
|
|
69
|
-
where[sessionTable("packageName")] = data.packageNames;
|
|
70
|
-
if (data.repositoryNames)
|
|
71
|
-
where[repoTable("repositoryName")] = data.repositoryNames;
|
|
72
|
-
if (data.packageNames)
|
|
73
|
-
where[sessionTable("packageName")] = data.packageNames;
|
|
74
|
-
if (type === SessionDriverAbstract_1.EntityEnum.BackupSession && data.tags)
|
|
75
|
-
data.tags.map((tag) => `(',' || ${sessionTable("tags")} || ',') LIKE '%,${tag},%' `);
|
|
76
|
-
let query = `
|
|
77
|
-
SELECT
|
|
78
|
-
${sessionTable("id")},
|
|
79
|
-
${sessionTable("snapshotId")},
|
|
80
|
-
${sessionTable("creationDate")},
|
|
81
|
-
${sessionTable("state")},
|
|
82
|
-
${sessionTable("packageName")},
|
|
83
|
-
${repoTable("repositoryName")},
|
|
84
|
-
${repoTable("repositoryType")},
|
|
85
|
-
COALESCE(${repoTable("error")}, ${sessionTable("error")}) AS error
|
|
86
|
-
FROM
|
|
87
|
-
${sessionTable}
|
|
88
|
-
LEFT JOIN ${repoTable} ON
|
|
89
|
-
${repoTable("sessionId")} = ${sessionTable("id")}
|
|
90
|
-
ORDER BY
|
|
91
|
-
${sessionTable("id")} DESC
|
|
92
|
-
`;
|
|
93
|
-
if (data.limit)
|
|
94
|
-
query += `LIMIT ${data.limit}`;
|
|
95
|
-
return await this.exec(query, async () => await this.db.all(query));
|
|
96
|
-
}
|
|
97
|
-
setMapId(entity, id, value) {
|
|
98
|
-
if (!this.idMap[entity])
|
|
99
|
-
this.idMap[entity] = {};
|
|
100
|
-
const map = this.idMap[entity];
|
|
101
|
-
(0, assert_1.ok)(map);
|
|
102
|
-
map[id] = value;
|
|
103
|
-
}
|
|
104
|
-
getMapId(entity, id) {
|
|
105
|
-
const result = this.idMap[entity]?.[id];
|
|
106
|
-
if (!result)
|
|
107
|
-
throw new Error(`Entity id not found: ${entity}-${id}`);
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
static getEntityTable(entity) {
|
|
111
|
-
return {
|
|
112
|
-
[SessionDriverAbstract_1.EntityEnum.BackupSession]: "backup_session",
|
|
113
|
-
[SessionDriverAbstract_1.EntityEnum.BackupSessionRepository]: "backup_session_repository",
|
|
114
|
-
[SessionDriverAbstract_1.EntityEnum.BackupSessionTask]: "backup_session_task",
|
|
115
|
-
[SessionDriverAbstract_1.EntityEnum.RestoreSession]: "restore_session",
|
|
116
|
-
[SessionDriverAbstract_1.EntityEnum.RestoreSessionRepository]: "restore_session_repository",
|
|
117
|
-
[SessionDriverAbstract_1.EntityEnum.RestoreSessionTask]: "restore_session_task",
|
|
118
|
-
}[entity];
|
|
119
|
-
}
|
|
120
|
-
static getParentEntity(entity) {
|
|
121
|
-
return {
|
|
122
|
-
[SessionDriverAbstract_1.EntityEnum.BackupSession]: SessionDriverAbstract_1.EntityEnum.BackupSession,
|
|
123
|
-
[SessionDriverAbstract_1.EntityEnum.BackupSessionRepository]: SessionDriverAbstract_1.EntityEnum.BackupSession,
|
|
124
|
-
[SessionDriverAbstract_1.EntityEnum.BackupSessionTask]: SessionDriverAbstract_1.EntityEnum.BackupSession,
|
|
125
|
-
[SessionDriverAbstract_1.EntityEnum.RestoreSession]: SessionDriverAbstract_1.EntityEnum.RestoreSession,
|
|
126
|
-
[SessionDriverAbstract_1.EntityEnum.RestoreSessionRepository]: SessionDriverAbstract_1.EntityEnum.RestoreSession,
|
|
127
|
-
[SessionDriverAbstract_1.EntityEnum.RestoreSessionTask]: SessionDriverAbstract_1.EntityEnum.RestoreSession,
|
|
128
|
-
}[entity];
|
|
129
|
-
}
|
|
130
|
-
async onWrite(data) {
|
|
131
|
-
const tableName = SqliteSessionDriver.getEntityTable(data.entity);
|
|
132
|
-
let stm;
|
|
133
|
-
let object = data.data;
|
|
134
|
-
const id = object.id;
|
|
135
|
-
object = {
|
|
136
|
-
...object,
|
|
137
|
-
// @ts-expect-error
|
|
138
|
-
progress: data.data.progress ? JSON.stringify(data.data.progress) : null,
|
|
139
|
-
};
|
|
140
|
-
if (data.action === SessionDriverAbstract_1.ActionEnum.Init) {
|
|
141
|
-
// @ts-expect-error
|
|
142
|
-
object = { ...object, id: null };
|
|
143
|
-
stm = this.buildInsertStm(tableName, object);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
object = { ...object, id: this.getMapId(data.entity, id) };
|
|
147
|
-
if ("sessionId" in object) {
|
|
148
|
-
const parentEntity = SqliteSessionDriver.getParentEntity(data.entity);
|
|
149
|
-
object.sessionId = this.getMapId(parentEntity, object.sessionId);
|
|
150
|
-
}
|
|
151
|
-
stm = this.buildUpdateStm(tableName, object);
|
|
152
|
-
}
|
|
153
|
-
const params = Object.keys(object).reduce((result, name) => {
|
|
154
|
-
result[`:${name}`] = object[name];
|
|
155
|
-
return result;
|
|
156
|
-
}, {});
|
|
157
|
-
try {
|
|
158
|
-
const result = await this.exec(stm, async () => await this.db.run(stm, params));
|
|
159
|
-
if (data.action === SessionDriverAbstract_1.ActionEnum.Init &&
|
|
160
|
-
typeof result.lastID === "number") {
|
|
161
|
-
this.setMapId(data.entity, id, result.lastID);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
console.error({
|
|
166
|
-
query: stm,
|
|
167
|
-
params: params,
|
|
168
|
-
});
|
|
169
|
-
throw new Error(error.message);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.SqliteSessionDriver = SqliteSessionDriver;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { BackupSessionsActionOptionsType } from "../Action/BackupSessionsAction";
|
|
2
|
-
import { BackupSessionEntity } from "../Entity/BackupSessionEntity";
|
|
3
|
-
import { BackupSessionRepositoryEntity } from "../Entity/BackupSessionRepositoryEntity";
|
|
4
|
-
import { BackupSessionTaskEntity } from "../Entity/BackupSessionTaskEntity";
|
|
5
|
-
import { WriteDataType } from "../SessionDriver/SessionDriverAbstract";
|
|
6
|
-
import { ObjectVault } from "../utils/ObjectVault";
|
|
7
|
-
import { Progress } from "../utils/progress";
|
|
8
|
-
import SessionManagerAbstract from "./SessionManagerAbstract";
|
|
9
|
-
export declare class BackupSessionManager extends SessionManagerAbstract {
|
|
10
|
-
sessionVault: ObjectVault<BackupSessionEntity>;
|
|
11
|
-
taskVault: ObjectVault<BackupSessionTaskEntity>;
|
|
12
|
-
repositoryVault: ObjectVault<BackupSessionRepositoryEntity>;
|
|
13
|
-
findId(data: {
|
|
14
|
-
packageName: string;
|
|
15
|
-
}): number;
|
|
16
|
-
findTaskId(data: {
|
|
17
|
-
packageName: string;
|
|
18
|
-
taskName: string;
|
|
19
|
-
}): number;
|
|
20
|
-
findRepositoryId(data: {
|
|
21
|
-
packageName: string;
|
|
22
|
-
repositoryName: string;
|
|
23
|
-
}): number;
|
|
24
|
-
initDrivers(): Promise<void>;
|
|
25
|
-
endDrivers(data?: Record<string, any>): Promise<void>;
|
|
26
|
-
protected alter(data: WriteDataType): Promise<number>;
|
|
27
|
-
readAll(options: BackupSessionsActionOptionsType): Promise<import("../SessionDriver/SessionDriverAbstract").ReadResultType[]>;
|
|
28
|
-
init(input: Pick<BackupSessionEntity, "packageName" | "snapshotId" | "tags">): Promise<number>;
|
|
29
|
-
initTask(input: Pick<BackupSessionTaskEntity, "sessionId" | "taskName">): Promise<number>;
|
|
30
|
-
initRepository(input: Pick<BackupSessionRepositoryEntity, "repositoryName" | "sessionId" | "repositoryType">): Promise<number>;
|
|
31
|
-
start(input: Pick<BackupSessionEntity, "id">): Promise<number>;
|
|
32
|
-
end(input: Pick<BackupSessionEntity, "id" | "error">): Promise<number>;
|
|
33
|
-
startTask(input: Pick<BackupSessionTaskEntity, "id">): Promise<number>;
|
|
34
|
-
progressTask(input: {
|
|
35
|
-
id: number;
|
|
36
|
-
progress: Progress;
|
|
37
|
-
}): Promise<number>;
|
|
38
|
-
endTask(input: Pick<BackupSessionTaskEntity, "id" | "error">): Promise<number>;
|
|
39
|
-
startRepository(input: Pick<BackupSessionRepositoryEntity, "id">): Promise<number>;
|
|
40
|
-
progressRepository(input: {
|
|
41
|
-
id: number;
|
|
42
|
-
progress: Progress;
|
|
43
|
-
}): Promise<number>;
|
|
44
|
-
endRepository(input: Pick<BackupSessionRepositoryEntity, "id" | "error">): Promise<number>;
|
|
45
|
-
}
|