@wocker/mongodb-plugin 1.0.1 → 1.0.3
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,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,
|
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) {
|
@@ -64,7 +68,7 @@ let MongodbController = class MongodbController {
|
|
64
68
|
}
|
65
69
|
getNames() {
|
66
70
|
return __awaiter(this, void 0, void 0, function* () {
|
67
|
-
return this.mongodbService.config.databases.
|
71
|
+
return this.mongodbService.config.databases.map((database) => {
|
68
72
|
return database.name;
|
69
73
|
});
|
70
74
|
});
|
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
|
}
|
@@ -1,5 +1,6 @@
|
|
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;
|
@@ -9,7 +10,7 @@ export declare class MongodbService {
|
|
9
10
|
adminContainerName: string;
|
10
11
|
constructor(appConfigService: AppConfigService, pluginConfigService: PluginConfigService, dockerService: DockerService, proxyService: ProxyService);
|
11
12
|
get config(): Config;
|
12
|
-
create(
|
13
|
+
create(props?: Partial<DatabaseProps>): Promise<void>;
|
13
14
|
upgrade(name?: string, imageName?: string, imageVersion?: string): Promise<void>;
|
14
15
|
destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
|
15
16
|
use(name: string): void;
|
@@ -48,19 +48,20 @@ 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
|
}
|
55
55
|
return this._config;
|
56
56
|
}
|
57
|
-
create(
|
58
|
-
return __awaiter(this, arguments, void 0, function* (
|
59
|
-
if (name && this.config.hasDatabase(name)) {
|
60
|
-
|
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;
|
61
62
|
}
|
62
|
-
if (!name) {
|
63
|
-
name = (yield (0, utils_1.promptText)({
|
63
|
+
if (!props.name) {
|
64
|
+
props.name = (yield (0, utils_1.promptText)({
|
64
65
|
message: "Mongodb name:",
|
65
66
|
type: "string",
|
66
67
|
validate: (name) => {
|
@@ -74,34 +75,34 @@ let MongodbService = class MongodbService {
|
|
74
75
|
}
|
75
76
|
}));
|
76
77
|
}
|
77
|
-
if (!username) {
|
78
|
-
username = yield (0, utils_1.promptText)({
|
78
|
+
if (!props.username) {
|
79
|
+
props.username = yield (0, utils_1.promptText)({
|
79
80
|
message: "Username:",
|
80
81
|
type: "string",
|
81
82
|
required: true
|
82
83
|
});
|
83
84
|
}
|
84
|
-
if (!password) {
|
85
|
-
password = yield (0, utils_1.promptText)({
|
85
|
+
if (!props.password) {
|
86
|
+
props.password = (yield (0, utils_1.promptText)({
|
86
87
|
message: "Password:",
|
87
88
|
type: "password",
|
88
89
|
required: true
|
89
|
-
});
|
90
|
+
}));
|
90
91
|
const confirmPassword = yield (0, utils_1.promptText)({
|
91
92
|
message: "Confirm password:",
|
92
93
|
type: "password",
|
93
94
|
required: true
|
94
95
|
});
|
95
|
-
if (password !== confirmPassword) {
|
96
|
+
if (props.password !== confirmPassword) {
|
96
97
|
throw new Error("Passwords do not match");
|
97
98
|
}
|
98
99
|
}
|
99
100
|
const database = new Database_1.Database({
|
100
|
-
name,
|
101
|
-
imageName,
|
102
|
-
imageVersion,
|
103
|
-
username,
|
104
|
-
password
|
101
|
+
name: props.name,
|
102
|
+
imageName: props.imageName,
|
103
|
+
imageVersion: props.imageVersion,
|
104
|
+
username: props.username,
|
105
|
+
password: props.password
|
105
106
|
});
|
106
107
|
this.config.setDatabase(database);
|
107
108
|
this.config.save();
|
@@ -199,7 +200,7 @@ let MongodbService = class MongodbService {
|
|
199
200
|
admin() {
|
200
201
|
return __awaiter(this, void 0, void 0, function* () {
|
201
202
|
const connections = [];
|
202
|
-
for (const database of this.config.databases
|
203
|
+
for (const database of this.config.databases) {
|
203
204
|
try {
|
204
205
|
const container = yield this.dockerService.getContainer(database.containerName);
|
205
206
|
if (!container) {
|
@@ -264,7 +265,7 @@ let MongodbService = class MongodbService {
|
|
264
265
|
"Storages"
|
265
266
|
]
|
266
267
|
});
|
267
|
-
for (const database of this.config.databases
|
268
|
+
for (const database of this.config.databases) {
|
268
269
|
table.push([
|
269
270
|
database.name + (database.name === this.config.default ? " (default)" : ""),
|
270
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.3",
|
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.
|
35
|
-
"typescript": "^5.
|
34
|
+
"@types/node": "^22.13.4",
|
35
|
+
"typescript": "^5.7.3"
|
36
36
|
}
|
37
37
|
}
|