@wocker/mongodb-plugin 1.0.2 → 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.
@@ -68,7 +68,7 @@ let MongodbController = class MongodbController {
|
|
68
68
|
}
|
69
69
|
getNames() {
|
70
70
|
return __awaiter(this, void 0, void 0, function* () {
|
71
|
-
return this.mongodbService.config.databases.
|
71
|
+
return this.mongodbService.config.databases.map((database) => {
|
72
72
|
return database.name;
|
73
73
|
});
|
74
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
|
}
|
@@ -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
|
}
|
@@ -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.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.
|
34
|
+
"@types/node": "^22.13.4",
|
35
35
|
"typescript": "^5.7.3"
|
36
36
|
}
|
37
37
|
}
|