@wocker/mongodb-plugin 1.0.0 → 1.0.2
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/controllers/MongodbController.d.ts +1 -1
- package/lib/controllers/MongodbController.js +42 -8
- package/lib/makes/Config.d.ts +6 -2
- package/lib/makes/Config.js +23 -11
- package/lib/makes/Database.d.ts +5 -0
- package/lib/makes/Database.js +7 -1
- package/lib/services/MongodbService.d.ts +5 -3
- package/lib/services/MongodbService.js +65 -53
- package/package.json +8 -8
@@ -2,7 +2,7 @@ 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): Promise<void>;
|
5
|
+
create(name?: string, imageName?: string, imageVersion?: string): Promise<void>;
|
6
6
|
destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
|
7
7
|
use(name: string): Promise<void>;
|
8
8
|
start(name?: string, restart?: boolean): Promise<void>;
|
@@ -28,9 +28,13 @@ let MongodbController = class MongodbController {
|
|
28
28
|
constructor(mongodbService) {
|
29
29
|
this.mongodbService = mongodbService;
|
30
30
|
}
|
31
|
-
create(name) {
|
31
|
+
create(name, imageName, imageVersion) {
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
33
|
-
yield this.mongodbService.create(
|
33
|
+
yield this.mongodbService.create({
|
34
|
+
name,
|
35
|
+
imageName,
|
36
|
+
imageVersion
|
37
|
+
});
|
34
38
|
});
|
35
39
|
}
|
36
40
|
destroy(name, yes, force) {
|
@@ -42,7 +46,7 @@ let MongodbController = class MongodbController {
|
|
42
46
|
}
|
43
47
|
use(name) {
|
44
48
|
return __awaiter(this, void 0, void 0, function* () {
|
45
|
-
|
49
|
+
this.mongodbService.use(name);
|
46
50
|
});
|
47
51
|
}
|
48
52
|
start(name, restart) {
|
@@ -64,29 +68,52 @@ let MongodbController = class MongodbController {
|
|
64
68
|
}
|
65
69
|
getNames() {
|
66
70
|
return __awaiter(this, void 0, void 0, function* () {
|
67
|
-
return
|
71
|
+
return this.mongodbService.config.databases.items.map((database) => {
|
72
|
+
return database.name;
|
73
|
+
});
|
68
74
|
});
|
69
75
|
}
|
70
76
|
};
|
71
77
|
exports.MongodbController = MongodbController;
|
72
78
|
__decorate([
|
73
79
|
(0, core_1.Command)("mongodb:create [name]"),
|
80
|
+
(0, core_1.Description)("Creates a MongoDB service with configurable credentials, host, and storage options."),
|
74
81
|
__param(0, (0, core_1.Param)("name")),
|
82
|
+
__param(1, (0, core_1.Option)("image", {
|
83
|
+
type: "string",
|
84
|
+
alias: "i",
|
85
|
+
description: "The image name to start the service with",
|
86
|
+
})),
|
87
|
+
__param(2, (0, core_1.Option)("image-version", {
|
88
|
+
type: "string",
|
89
|
+
alias: "I",
|
90
|
+
description: "The image version to start the service with"
|
91
|
+
})),
|
75
92
|
__metadata("design:type", Function),
|
76
|
-
__metadata("design:paramtypes", [String]),
|
93
|
+
__metadata("design:paramtypes", [String, String, String]),
|
77
94
|
__metadata("design:returntype", Promise)
|
78
95
|
], MongodbController.prototype, "create", null);
|
79
96
|
__decorate([
|
80
97
|
(0, core_1.Command)("mongodb:destroy <name>"),
|
98
|
+
(0, core_1.Description)("Destroys a specified MongodbDB service instance with an option to force deletion."),
|
81
99
|
__param(0, (0, core_1.Param)("name")),
|
82
|
-
__param(1, (0, core_1.Option)("yes", {
|
83
|
-
|
100
|
+
__param(1, (0, core_1.Option)("yes", {
|
101
|
+
type: "boolean",
|
102
|
+
alias: "y",
|
103
|
+
description: "Skip confirmation"
|
104
|
+
})),
|
105
|
+
__param(2, (0, core_1.Option)("force", {
|
106
|
+
type: "boolean",
|
107
|
+
alias: "f",
|
108
|
+
description: "Force deletion"
|
109
|
+
})),
|
84
110
|
__metadata("design:type", Function),
|
85
111
|
__metadata("design:paramtypes", [String, Boolean, Boolean]),
|
86
112
|
__metadata("design:returntype", Promise)
|
87
113
|
], MongodbController.prototype, "destroy", null);
|
88
114
|
__decorate([
|
89
115
|
(0, core_1.Command)("mongodb:use <name>"),
|
116
|
+
(0, core_1.Description)("Sets a specified MongoDB service as the default."),
|
90
117
|
__param(0, (0, core_1.Param)("name")),
|
91
118
|
__metadata("design:type", Function),
|
92
119
|
__metadata("design:paramtypes", [String]),
|
@@ -94,14 +121,20 @@ __decorate([
|
|
94
121
|
], MongodbController.prototype, "use", null);
|
95
122
|
__decorate([
|
96
123
|
(0, core_1.Command)("mongodb:start [name]"),
|
124
|
+
(0, core_1.Description)("Starts a specified MongoDB service and optionally restarts it if already running."),
|
97
125
|
__param(0, (0, core_1.Param)("name")),
|
98
|
-
__param(1, (0, core_1.Option)("restart", {
|
126
|
+
__param(1, (0, core_1.Option)("restart", {
|
127
|
+
type: "boolean",
|
128
|
+
alias: "r",
|
129
|
+
description: "Restart the service if already running"
|
130
|
+
})),
|
99
131
|
__metadata("design:type", Function),
|
100
132
|
__metadata("design:paramtypes", [String, Boolean]),
|
101
133
|
__metadata("design:returntype", Promise)
|
102
134
|
], MongodbController.prototype, "start", null);
|
103
135
|
__decorate([
|
104
136
|
(0, core_1.Command)("mongodb:stop [name]"),
|
137
|
+
(0, core_1.Description)("Stops a specified MongoDB service instance."),
|
105
138
|
__param(0, (0, core_1.Param)("name")),
|
106
139
|
__metadata("design:type", Function),
|
107
140
|
__metadata("design:paramtypes", [String]),
|
@@ -109,6 +142,7 @@ __decorate([
|
|
109
142
|
], MongodbController.prototype, "stop", null);
|
110
143
|
__decorate([
|
111
144
|
(0, core_1.Command)("mongodb:ls"),
|
145
|
+
(0, core_1.Description)("Lists all available MongoDB services."),
|
112
146
|
__metadata("design:type", Function),
|
113
147
|
__metadata("design:paramtypes", []),
|
114
148
|
__metadata("design:returntype", Promise)
|
package/lib/makes/Config.d.ts
CHANGED
@@ -8,8 +8,12 @@ export declare abstract class Config {
|
|
8
8
|
default?: string;
|
9
9
|
databases: ConfigCollection<Database, DatabaseProps>;
|
10
10
|
constructor(props: ConfigProps);
|
11
|
-
|
11
|
+
setDatabase(database: Database): void;
|
12
|
+
hasDatabase(name: string): boolean;
|
13
|
+
getDefault(): Database;
|
14
|
+
getDatabaseOrDefault(name?: string): Database;
|
15
|
+
getDatabase(name: string): Database;
|
12
16
|
removeDatabase(name: string): void;
|
13
|
-
abstract save():
|
17
|
+
abstract save(): void;
|
14
18
|
toJSON(): ConfigProps;
|
15
19
|
}
|
package/lib/makes/Config.js
CHANGED
@@ -9,27 +9,39 @@ class Config {
|
|
9
9
|
this.default = defaultDatabase;
|
10
10
|
this.databases = new core_1.ConfigCollection(Database_1.Database, databases);
|
11
11
|
}
|
12
|
-
|
12
|
+
setDatabase(database) {
|
13
|
+
this.databases.setConfig(database);
|
14
|
+
}
|
15
|
+
hasDatabase(name) {
|
16
|
+
return !!this.databases.getConfig(name);
|
17
|
+
}
|
18
|
+
getDefault() {
|
19
|
+
if (!this.default) {
|
20
|
+
throw new Error("Default database is not defined");
|
21
|
+
}
|
22
|
+
const database = this.databases.getConfig(this.default);
|
23
|
+
if (!database) {
|
24
|
+
throw new Error(`Default database "${this.default}" not found`);
|
25
|
+
}
|
26
|
+
return database;
|
27
|
+
}
|
28
|
+
getDatabaseOrDefault(name) {
|
13
29
|
if (!name) {
|
14
|
-
|
15
|
-
throw new Error("Default database is not defined");
|
16
|
-
}
|
17
|
-
const database = this.databases.getConfig(this.default);
|
18
|
-
if (!database) {
|
19
|
-
throw new Error(`Default database ${this.default} not found`);
|
20
|
-
}
|
21
|
-
return database;
|
30
|
+
return this.getDefault();
|
22
31
|
}
|
32
|
+
return this.getDatabase(name);
|
33
|
+
}
|
34
|
+
getDatabase(name) {
|
23
35
|
const database = this.databases.getConfig(name);
|
24
36
|
if (!database) {
|
25
|
-
throw new Error(`Database ${name} not found`);
|
37
|
+
throw new Error(`Database "${name}" not found`);
|
26
38
|
}
|
27
39
|
return database;
|
28
40
|
}
|
29
41
|
removeDatabase(name) {
|
30
42
|
const database = this.databases.getConfig(name);
|
31
43
|
if (!database) {
|
32
|
-
throw new Error(`
|
44
|
+
throw new Error(`Database "${name}" not found`);
|
33
45
|
}
|
34
46
|
this.databases.removeConfig(name);
|
35
47
|
}
|
package/lib/makes/Database.d.ts
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
import { Config, ConfigProperties } from "@wocker/core";
|
2
2
|
export type DatabaseProps = ConfigProperties & {
|
3
|
+
imageName?: string;
|
4
|
+
imageVersion?: string;
|
3
5
|
username: string;
|
4
6
|
password: string;
|
5
7
|
configStorage?: string;
|
6
8
|
storage?: string;
|
7
9
|
};
|
8
10
|
export declare class Database extends Config<DatabaseProps> {
|
11
|
+
imageName?: string;
|
12
|
+
imageVersion?: string;
|
9
13
|
username: string;
|
10
14
|
password: string;
|
11
15
|
configStorage: string;
|
12
16
|
storage: string;
|
13
17
|
constructor(props: DatabaseProps);
|
14
18
|
get containerName(): string;
|
19
|
+
get image(): string;
|
15
20
|
get defaultStorage(): string;
|
16
21
|
get defaultConfigStorage(): string;
|
17
22
|
}
|
package/lib/makes/Database.js
CHANGED
@@ -5,7 +5,9 @@ const core_1 = require("@wocker/core");
|
|
5
5
|
class Database extends core_1.Config {
|
6
6
|
constructor(props) {
|
7
7
|
super(props);
|
8
|
-
const { username, password, configStorage, storage } = props;
|
8
|
+
const { imageName, imageVersion, username, password, configStorage, storage } = props;
|
9
|
+
this.imageName = imageName;
|
10
|
+
this.imageVersion = imageVersion;
|
9
11
|
this.username = username;
|
10
12
|
this.password = password;
|
11
13
|
this.configStorage = configStorage || this.defaultConfigStorage;
|
@@ -14,6 +16,10 @@ class Database extends core_1.Config {
|
|
14
16
|
get containerName() {
|
15
17
|
return `mongodb-${this.name}.ws`;
|
16
18
|
}
|
19
|
+
get image() {
|
20
|
+
const imageName = this.imageName || "mongo", imageVersion = this.imageVersion || "latest";
|
21
|
+
return `${imageName}:${imageVersion}`;
|
22
|
+
}
|
17
23
|
get defaultStorage() {
|
18
24
|
return `wocker-mongodb-${this.name}`;
|
19
25
|
}
|
@@ -1,17 +1,19 @@
|
|
1
1
|
import { AppConfigService, PluginConfigService, DockerService, ProxyService } from "@wocker/core";
|
2
2
|
import { Config } from "../makes/Config";
|
3
|
+
import { DatabaseProps } from "../makes/Database";
|
3
4
|
export declare class MongodbService {
|
4
5
|
protected readonly appConfigService: AppConfigService;
|
5
6
|
protected readonly pluginConfigService: PluginConfigService;
|
6
7
|
protected readonly dockerService: DockerService;
|
7
8
|
protected readonly proxyService: ProxyService;
|
9
|
+
protected _config?: Config;
|
8
10
|
adminContainerName: string;
|
9
11
|
constructor(appConfigService: AppConfigService, pluginConfigService: PluginConfigService, dockerService: DockerService, proxyService: ProxyService);
|
10
|
-
protected _config?: Config;
|
11
12
|
get config(): Config;
|
12
|
-
create(
|
13
|
+
create(props?: Partial<DatabaseProps>): Promise<void>;
|
14
|
+
upgrade(name?: string, imageName?: string, imageVersion?: string): Promise<void>;
|
13
15
|
destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
|
14
|
-
use(name: string):
|
16
|
+
use(name: string): void;
|
15
17
|
start(name?: string, restart?: boolean): Promise<void>;
|
16
18
|
admin(): Promise<void>;
|
17
19
|
stop(name?: string): Promise<void>;
|
@@ -37,90 +37,98 @@ let MongodbService = class MongodbService {
|
|
37
37
|
}
|
38
38
|
get config() {
|
39
39
|
if (!this._config) {
|
40
|
-
const data = this.pluginConfigService.fs.exists("config.json")
|
41
|
-
? this.pluginConfigService.fs.readJSON("config.json")
|
42
|
-
: {
|
43
|
-
default: "default",
|
44
|
-
databases: [
|
45
|
-
{
|
46
|
-
name: "default",
|
47
|
-
username: "root",
|
48
|
-
password: "toor",
|
49
|
-
configStorage: "wocker-mongoconfig-default",
|
50
|
-
storage: "wocker-mongodb-default"
|
51
|
-
}
|
52
|
-
]
|
53
|
-
};
|
54
40
|
const fs = this.pluginConfigService.fs;
|
41
|
+
const data = fs.exists("config.json")
|
42
|
+
? fs.readJSON("config.json")
|
43
|
+
: {};
|
55
44
|
this._config = new class extends Config_1.Config {
|
56
45
|
save() {
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
yield fs.writeJSON("config.json", this.toJSON());
|
64
|
-
});
|
46
|
+
if (!fs.exists()) {
|
47
|
+
fs.mkdir("", {
|
48
|
+
recursive: true
|
49
|
+
});
|
50
|
+
}
|
51
|
+
fs.writeJSON("config.json", this.toJSON());
|
65
52
|
}
|
66
53
|
}(data);
|
67
54
|
}
|
68
55
|
return this._config;
|
69
56
|
}
|
70
|
-
create(
|
71
|
-
return __awaiter(this, arguments, void 0, function* (
|
72
|
-
if (name && this.config.
|
73
|
-
|
57
|
+
create() {
|
58
|
+
return __awaiter(this, arguments, void 0, function* (props = {}) {
|
59
|
+
if (props.name && this.config.hasDatabase(props.name)) {
|
60
|
+
console.info(`Database name "${props.name}" is already taken`);
|
61
|
+
delete props.name;
|
74
62
|
}
|
75
|
-
if (!name) {
|
76
|
-
name = (yield (0, utils_1.promptText)({
|
63
|
+
if (!props.name) {
|
64
|
+
props.name = (yield (0, utils_1.promptText)({
|
77
65
|
message: "Mongodb name:",
|
78
66
|
type: "string",
|
79
67
|
validate: (name) => {
|
80
68
|
if (!name) {
|
81
69
|
return "Name is required";
|
82
70
|
}
|
83
|
-
if (this.config.
|
71
|
+
if (this.config.hasDatabase(name)) {
|
84
72
|
return `Database name "${name}" is already taken`;
|
85
73
|
}
|
86
74
|
return true;
|
87
75
|
}
|
88
76
|
}));
|
89
77
|
}
|
90
|
-
if (!username) {
|
91
|
-
username = yield (0, utils_1.promptText)({
|
78
|
+
if (!props.username) {
|
79
|
+
props.username = yield (0, utils_1.promptText)({
|
92
80
|
message: "Username:",
|
93
81
|
type: "string",
|
94
82
|
required: true
|
95
83
|
});
|
96
84
|
}
|
97
|
-
if (!password) {
|
98
|
-
password = yield (0, utils_1.promptText)({
|
85
|
+
if (!props.password) {
|
86
|
+
props.password = (yield (0, utils_1.promptText)({
|
99
87
|
message: "Password:",
|
100
88
|
type: "password",
|
101
89
|
required: true
|
102
|
-
});
|
90
|
+
}));
|
103
91
|
const confirmPassword = yield (0, utils_1.promptText)({
|
104
92
|
message: "Confirm password:",
|
105
93
|
type: "password",
|
106
94
|
required: true
|
107
95
|
});
|
108
|
-
if (password !== confirmPassword) {
|
96
|
+
if (props.password !== confirmPassword) {
|
109
97
|
throw new Error("Passwords do not match");
|
110
98
|
}
|
111
99
|
}
|
112
100
|
const database = new Database_1.Database({
|
113
|
-
name,
|
114
|
-
|
115
|
-
|
101
|
+
name: props.name,
|
102
|
+
imageName: props.imageName,
|
103
|
+
imageVersion: props.imageVersion,
|
104
|
+
username: props.username,
|
105
|
+
password: props.password
|
116
106
|
});
|
117
|
-
this.config.
|
118
|
-
|
107
|
+
this.config.setDatabase(database);
|
108
|
+
this.config.save();
|
109
|
+
});
|
110
|
+
}
|
111
|
+
upgrade(name, imageName, imageVersion) {
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
113
|
+
const service = this.config.getDatabaseOrDefault(name);
|
114
|
+
let changed = false;
|
115
|
+
if (imageName) {
|
116
|
+
service.imageName = imageName;
|
117
|
+
changed = true;
|
118
|
+
}
|
119
|
+
if (imageVersion) {
|
120
|
+
service.imageVersion = imageVersion;
|
121
|
+
changed = true;
|
122
|
+
}
|
123
|
+
if (changed) {
|
124
|
+
this.config.setDatabase(service);
|
125
|
+
this.config.save();
|
126
|
+
}
|
119
127
|
});
|
120
128
|
}
|
121
129
|
destroy(name, yes, force) {
|
122
130
|
return __awaiter(this, void 0, void 0, function* () {
|
123
|
-
if (!this.
|
131
|
+
if (!this.pluginConfigService.isVersionGTE("1.0.19")) {
|
124
132
|
throw new Error("Please update @wocker/ws");
|
125
133
|
}
|
126
134
|
const database = this.config.getDatabase(name);
|
@@ -143,31 +151,33 @@ let MongodbService = class MongodbService {
|
|
143
151
|
yield this.dockerService.rmVolume(database.storage);
|
144
152
|
}
|
145
153
|
this.config.removeDatabase(database.name);
|
146
|
-
|
154
|
+
this.config.save();
|
147
155
|
});
|
148
156
|
}
|
149
157
|
use(name) {
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
yield this.config.save();
|
154
|
-
});
|
158
|
+
const database = this.config.getDatabase(name);
|
159
|
+
this.config.default = database.name;
|
160
|
+
this.config.save();
|
155
161
|
}
|
156
162
|
start(name, restart) {
|
157
163
|
return __awaiter(this, void 0, void 0, function* () {
|
158
|
-
if (!this.
|
164
|
+
if (!this.pluginConfigService.isVersionGTE("1.0.19")) {
|
159
165
|
throw new Error("Please update @wocker/ws");
|
160
166
|
}
|
161
|
-
|
162
|
-
|
163
|
-
yield this.dockerService.removeContainer(database.containerName);
|
167
|
+
if (!name || !this.config.default) {
|
168
|
+
yield this.create();
|
164
169
|
}
|
170
|
+
const database = this.config.getDatabaseOrDefault(name);
|
165
171
|
let container = yield this.dockerService.getContainer(database.containerName);
|
172
|
+
if (restart && container) {
|
173
|
+
yield this.dockerService.removeContainer(database.containerName);
|
174
|
+
container = null;
|
175
|
+
}
|
166
176
|
if (!container) {
|
167
177
|
container = yield this.dockerService.createContainer({
|
168
178
|
name: database.containerName,
|
169
179
|
restart: "always",
|
170
|
-
image:
|
180
|
+
image: database.image,
|
171
181
|
env: {
|
172
182
|
MONGO_INITDB_ROOT_USERNAME: database.username,
|
173
183
|
MONGO_INITDB_ROOT_PASSWORD: database.password,
|
@@ -239,7 +249,7 @@ let MongodbService = class MongodbService {
|
|
239
249
|
}
|
240
250
|
stop(name) {
|
241
251
|
return __awaiter(this, void 0, void 0, function* () {
|
242
|
-
const database = this.config.
|
252
|
+
const database = this.config.getDatabaseOrDefault(name);
|
243
253
|
console.info(`Stopping ${database.name}...`);
|
244
254
|
yield this.dockerService.removeContainer(database.containerName);
|
245
255
|
});
|
@@ -251,6 +261,7 @@ let MongodbService = class MongodbService {
|
|
251
261
|
"Name",
|
252
262
|
"Username",
|
253
263
|
"Host",
|
264
|
+
"Image",
|
254
265
|
"Storages"
|
255
266
|
]
|
256
267
|
});
|
@@ -259,6 +270,7 @@ let MongodbService = class MongodbService {
|
|
259
270
|
database.name + (database.name === this.config.default ? " (default)" : ""),
|
260
271
|
database.username,
|
261
272
|
database.containerName,
|
273
|
+
database.image,
|
262
274
|
`${database.configStorage}\n${database.storage}`
|
263
275
|
]);
|
264
276
|
}
|
package/package.json
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wocker/mongodb-plugin",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
5
5
|
"description": "Mongodb plugin for wocker",
|
6
6
|
"license": "MIT",
|
7
|
-
"main": "lib/index.js",
|
8
|
-
"types": "lib/index.d.ts",
|
7
|
+
"main": "./lib/index.js",
|
8
|
+
"types": "./lib/index.d.ts",
|
9
9
|
"keywords": [
|
10
10
|
"wocker",
|
11
11
|
"plugin",
|
12
12
|
"mongodb"
|
13
13
|
],
|
14
|
-
"homepage": "https://kearisp.github.io/wocker/plugins/mongodb",
|
14
|
+
"homepage": "https://kearisp.github.io/wocker/docs/plugins/mongodb",
|
15
15
|
"repository": {
|
16
16
|
"type": "git",
|
17
17
|
"url": "git+https://github.com/kearisp/wocker-mongodb-plugin.git"
|
@@ -26,12 +26,12 @@
|
|
26
26
|
"test": "echo \"Error: no test specified\" && exit 1"
|
27
27
|
},
|
28
28
|
"dependencies": {
|
29
|
-
"@wocker/core": "^1.0.
|
30
|
-
"@wocker/utils": "^1.0.
|
29
|
+
"@wocker/core": "^1.0.21",
|
30
|
+
"@wocker/utils": "^1.0.9",
|
31
31
|
"cli-table3": "^0.6.5"
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
34
|
-
"@types/node": "
|
35
|
-
"typescript": "^5.
|
34
|
+
"@types/node": "^22.12.0",
|
35
|
+
"typescript": "^5.7.3"
|
36
36
|
}
|
37
37
|
}
|