@wocker/mongodb-plugin 1.0.2 → 1.0.4
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.
@@ -2,7 +2,8 @@ import { MongodbService } from "../services/MongodbService";
|
|
2
2
|
export declare class MongodbController {
|
3
3
|
protected readonly mongodbService: MongodbService;
|
4
4
|
constructor(mongodbService: MongodbService);
|
5
|
-
create(name?: string, imageName?: string, imageVersion?: string): Promise<void>;
|
5
|
+
create(name?: string, username?: string, password?: string, imageName?: string, imageVersion?: string): Promise<void>;
|
6
|
+
upgrade(name?: string, imageName?: string, imageVersion?: string): Promise<void>;
|
6
7
|
destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
|
7
8
|
use(name: string): Promise<void>;
|
8
9
|
start(name?: string, restart?: boolean): Promise<void>;
|
@@ -28,9 +28,20 @@ let MongodbController = class MongodbController {
|
|
28
28
|
constructor(mongodbService) {
|
29
29
|
this.mongodbService = mongodbService;
|
30
30
|
}
|
31
|
-
create(name, imageName, imageVersion) {
|
31
|
+
create(name, username, password, imageName, imageVersion) {
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
33
33
|
yield this.mongodbService.create({
|
34
|
+
name,
|
35
|
+
username,
|
36
|
+
password,
|
37
|
+
imageName,
|
38
|
+
imageVersion
|
39
|
+
});
|
40
|
+
});
|
41
|
+
}
|
42
|
+
upgrade(name, imageName, imageVersion) {
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
yield this.mongodbService.upgrade({
|
34
45
|
name,
|
35
46
|
imageName,
|
36
47
|
imageVersion
|
@@ -68,7 +79,7 @@ let MongodbController = class MongodbController {
|
|
68
79
|
}
|
69
80
|
getNames() {
|
70
81
|
return __awaiter(this, void 0, void 0, function* () {
|
71
|
-
return this.mongodbService.config.databases.
|
82
|
+
return this.mongodbService.config.databases.map((database) => {
|
72
83
|
return database.name;
|
73
84
|
});
|
74
85
|
});
|
@@ -79,11 +90,39 @@ __decorate([
|
|
79
90
|
(0, core_1.Command)("mongodb:create [name]"),
|
80
91
|
(0, core_1.Description)("Creates a MongoDB service with configurable credentials, host, and storage options."),
|
81
92
|
__param(0, (0, core_1.Param)("name")),
|
82
|
-
__param(1, (0, core_1.Option)("
|
93
|
+
__param(1, (0, core_1.Option)("user", {
|
94
|
+
type: "string",
|
95
|
+
alias: "u",
|
96
|
+
description: "The username to start the service with"
|
97
|
+
})),
|
98
|
+
__param(2, (0, core_1.Option)("password", {
|
99
|
+
type: "string",
|
100
|
+
alias: "p",
|
101
|
+
description: "The password to start the service with"
|
102
|
+
})),
|
103
|
+
__param(3, (0, core_1.Option)("image", {
|
83
104
|
type: "string",
|
84
105
|
alias: "i",
|
85
106
|
description: "The image name to start the service with",
|
86
107
|
})),
|
108
|
+
__param(4, (0, core_1.Option)("image-version", {
|
109
|
+
type: "string",
|
110
|
+
alias: "I",
|
111
|
+
description: "The image version to start the service with"
|
112
|
+
})),
|
113
|
+
__metadata("design:type", Function),
|
114
|
+
__metadata("design:paramtypes", [String, String, String, String, String]),
|
115
|
+
__metadata("design:returntype", Promise)
|
116
|
+
], MongodbController.prototype, "create", null);
|
117
|
+
__decorate([
|
118
|
+
(0, core_1.Command)("mongodb:upgrade [name]"),
|
119
|
+
(0, core_1.Description)("Upgrades a specified MongoDB service instance."),
|
120
|
+
__param(0, (0, core_1.Param)("name")),
|
121
|
+
__param(1, (0, core_1.Option)("image", {
|
122
|
+
type: "string",
|
123
|
+
alias: "i",
|
124
|
+
description: "The image name to start the service with"
|
125
|
+
})),
|
87
126
|
__param(2, (0, core_1.Option)("image-version", {
|
88
127
|
type: "string",
|
89
128
|
alias: "I",
|
@@ -92,7 +131,7 @@ __decorate([
|
|
92
131
|
__metadata("design:type", Function),
|
93
132
|
__metadata("design:paramtypes", [String, String, String]),
|
94
133
|
__metadata("design:returntype", Promise)
|
95
|
-
], MongodbController.prototype, "
|
134
|
+
], MongodbController.prototype, "upgrade", null);
|
96
135
|
__decorate([
|
97
136
|
(0, core_1.Command)("mongodb:destroy <name>"),
|
98
137
|
(0, core_1.Description)("Destroys a specified MongodbDB service instance with an option to force deletion."),
|
package/lib/makes/Config.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { ConfigCollection } from "@wocker/core";
|
2
1
|
import { Database, DatabaseProps } from "./Database";
|
3
2
|
export type ConfigProps = {
|
4
3
|
default?: string;
|
@@ -6,7 +5,7 @@ export type ConfigProps = {
|
|
6
5
|
};
|
7
6
|
export declare abstract class Config {
|
8
7
|
default?: string;
|
9
|
-
databases:
|
8
|
+
databases: Database[];
|
10
9
|
constructor(props: ConfigProps);
|
11
10
|
setDatabase(database: Database): void;
|
12
11
|
hasDatabase(name: string): boolean;
|
@@ -15,5 +14,5 @@ export declare abstract class Config {
|
|
15
14
|
getDatabase(name: string): Database;
|
16
15
|
removeDatabase(name: string): void;
|
17
16
|
abstract save(): void;
|
18
|
-
|
17
|
+
toObject(): ConfigProps;
|
19
18
|
}
|
package/lib/makes/Config.js
CHANGED
@@ -1,29 +1,37 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Config = void 0;
|
4
|
-
const core_1 = require("@wocker/core");
|
5
4
|
const Database_1 = require("./Database");
|
6
5
|
class Config {
|
7
6
|
constructor(props) {
|
8
7
|
const { default: defaultDatabase, databases = [] } = props;
|
9
8
|
this.default = defaultDatabase;
|
10
|
-
this.databases = new
|
9
|
+
this.databases = databases.map(database => new Database_1.Database(database));
|
11
10
|
}
|
12
11
|
setDatabase(database) {
|
13
|
-
|
12
|
+
let exists = false;
|
13
|
+
for (let i = 0; i < this.databases.length; i++) {
|
14
|
+
if (this.databases[i].name === database.name) {
|
15
|
+
exists = true;
|
16
|
+
this.databases[i] = database;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
if (!exists) {
|
20
|
+
this.databases.push(database);
|
21
|
+
}
|
22
|
+
if (!this.default) {
|
23
|
+
this.default = database.name;
|
24
|
+
}
|
14
25
|
}
|
15
26
|
hasDatabase(name) {
|
16
|
-
|
27
|
+
const database = this.databases.find(database => database.name === name);
|
28
|
+
return !!database;
|
17
29
|
}
|
18
30
|
getDefault() {
|
19
31
|
if (!this.default) {
|
20
32
|
throw new Error("Default database is not defined");
|
21
33
|
}
|
22
|
-
|
23
|
-
if (!database) {
|
24
|
-
throw new Error(`Default database "${this.default}" not found`);
|
25
|
-
}
|
26
|
-
return database;
|
34
|
+
return this.getDatabase(this.default);
|
27
35
|
}
|
28
36
|
getDatabaseOrDefault(name) {
|
29
37
|
if (!name) {
|
@@ -32,23 +40,28 @@ class Config {
|
|
32
40
|
return this.getDatabase(name);
|
33
41
|
}
|
34
42
|
getDatabase(name) {
|
35
|
-
const database = this.databases.
|
43
|
+
const database = this.databases.find((database) => {
|
44
|
+
return database.name === name;
|
45
|
+
});
|
36
46
|
if (!database) {
|
37
47
|
throw new Error(`Database "${name}" not found`);
|
38
48
|
}
|
39
49
|
return database;
|
40
50
|
}
|
41
51
|
removeDatabase(name) {
|
42
|
-
|
43
|
-
|
44
|
-
|
52
|
+
this.databases = this.databases.filter((database) => {
|
53
|
+
return database.name !== name;
|
54
|
+
});
|
55
|
+
if (this.default === name) {
|
56
|
+
delete this.default;
|
45
57
|
}
|
46
|
-
this.databases.removeConfig(name);
|
47
58
|
}
|
48
|
-
|
59
|
+
toObject() {
|
49
60
|
return {
|
50
61
|
default: this.default,
|
51
|
-
databases: this.databases.
|
62
|
+
databases: this.databases.length > 0
|
63
|
+
? this.databases.map((database) => database.toObject())
|
64
|
+
: []
|
52
65
|
};
|
53
66
|
}
|
54
67
|
}
|
@@ -11,7 +11,7 @@ export declare class MongodbService {
|
|
11
11
|
constructor(appConfigService: AppConfigService, pluginConfigService: PluginConfigService, dockerService: DockerService, proxyService: ProxyService);
|
12
12
|
get config(): Config;
|
13
13
|
create(props?: Partial<DatabaseProps>): Promise<void>;
|
14
|
-
upgrade(
|
14
|
+
upgrade(props: Partial<DatabaseProps>): Promise<void>;
|
15
15
|
destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
|
16
16
|
use(name: string): void;
|
17
17
|
start(name?: string, restart?: boolean): Promise<void>;
|
@@ -48,7 +48,7 @@ let MongodbService = class MongodbService {
|
|
48
48
|
recursive: true
|
49
49
|
});
|
50
50
|
}
|
51
|
-
fs.writeJSON("config.json", this.
|
51
|
+
fs.writeJSON("config.json", this.toObject());
|
52
52
|
}
|
53
53
|
}(data);
|
54
54
|
}
|
@@ -108,16 +108,16 @@ let MongodbService = class MongodbService {
|
|
108
108
|
this.config.save();
|
109
109
|
});
|
110
110
|
}
|
111
|
-
upgrade(
|
111
|
+
upgrade(props) {
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
113
|
-
const service = this.config.getDatabaseOrDefault(name);
|
113
|
+
const service = this.config.getDatabaseOrDefault(props.name);
|
114
114
|
let changed = false;
|
115
|
-
if (imageName) {
|
116
|
-
service.imageName = imageName;
|
115
|
+
if (props.imageName) {
|
116
|
+
service.imageName = props.imageName;
|
117
117
|
changed = true;
|
118
118
|
}
|
119
|
-
if (imageVersion) {
|
120
|
-
service.imageVersion = imageVersion;
|
119
|
+
if (props.imageVersion) {
|
120
|
+
service.imageVersion = props.imageVersion;
|
121
121
|
changed = true;
|
122
122
|
}
|
123
123
|
if (changed) {
|
@@ -200,7 +200,7 @@ let MongodbService = class MongodbService {
|
|
200
200
|
admin() {
|
201
201
|
return __awaiter(this, void 0, void 0, function* () {
|
202
202
|
const connections = [];
|
203
|
-
for (const database of this.config.databases
|
203
|
+
for (const database of this.config.databases) {
|
204
204
|
try {
|
205
205
|
const container = yield this.dockerService.getContainer(database.containerName);
|
206
206
|
if (!container) {
|
@@ -265,7 +265,7 @@ let MongodbService = class MongodbService {
|
|
265
265
|
"Storages"
|
266
266
|
]
|
267
267
|
});
|
268
|
-
for (const database of this.config.databases
|
268
|
+
for (const database of this.config.databases) {
|
269
269
|
table.push([
|
270
270
|
database.name + (database.name === this.config.default ? " (default)" : ""),
|
271
271
|
database.username,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wocker/mongodb-plugin",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.4",
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
5
5
|
"description": "Mongodb plugin for wocker",
|
6
6
|
"license": "MIT",
|
@@ -31,7 +31,7 @@
|
|
31
31
|
"cli-table3": "^0.6.5"
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
34
|
-
"@types/node": "^22.
|
34
|
+
"@types/node": "^22.13.4",
|
35
35
|
"typescript": "^5.7.3"
|
36
36
|
}
|
37
37
|
}
|