@wocker/mongodb-plugin 1.0.0-beta.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.

Potentially problematic release.


This version of @wocker/mongodb-plugin might be problematic. Click here for more details.

File without changes
File without changes
File without changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Kris Papercut
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
File without changes
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @wocker/mongodb-plugin
2
+
3
+ ###### Docker workspace for web projects
4
+
5
+ ## Installation
6
+
7
+ **Note:** It is recommended to install Wocker globally to ensure accessibility from any directory in your terminal.
8
+
9
+ ```shell
10
+ npm i -g @wocker/ws
11
+ ```
12
+
13
+ ```shell
14
+ ws plugin:add mongodb
15
+ ```
16
+
17
+
18
+ ### Completion
19
+
20
+ Wocker comes with shell completion support to enhance your development workflow. To enable shell completion, run the following command:
21
+
22
+ ```bash
23
+ source <(ws completion script)
24
+ ```
25
+
26
+ This will enable tab completion for `ws` commands, providing a more convenient and efficient way to interact with the tool.
27
+
28
+
29
+ ## Documentation
30
+
31
+ Wocker is a powerful tool for managing your web project's Docker workspace. It provides a convenient and efficient way to set up and manage your Docker containers.
32
+
33
+ For more information and detailed usage, please refer to the [documentation](https://kearisp.github.io/wocker).
File without changes
@@ -0,0 +1,11 @@
1
+ import { MongodbService } from "../services/MongodbService";
2
+ export declare class MongodbController {
3
+ protected readonly mongodbService: MongodbService;
4
+ constructor(mongodbService: MongodbService);
5
+ create(name?: string): Promise<void>;
6
+ destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
7
+ start(name?: string, restart?: boolean): Promise<void>;
8
+ stop(name?: string): Promise<void>;
9
+ list(): Promise<string>;
10
+ getNames(): Promise<string[]>;
11
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.MongodbController = void 0;
25
+ const core_1 = require("@wocker/core");
26
+ const MongodbService_1 = require("../services/MongodbService");
27
+ let MongodbController = class MongodbController {
28
+ constructor(mongodbService) {
29
+ this.mongodbService = mongodbService;
30
+ }
31
+ create(name) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ yield this.mongodbService.create(name);
34
+ });
35
+ }
36
+ destroy(name, yes, force) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ yield this.mongodbService.stop(name);
39
+ yield this.mongodbService.destroy(name, yes, force);
40
+ yield this.mongodbService.admin();
41
+ });
42
+ }
43
+ start(name, restart) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ yield this.mongodbService.start(name, restart);
46
+ yield this.mongodbService.admin();
47
+ });
48
+ }
49
+ stop(name) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ yield this.mongodbService.stop(name);
52
+ yield this.mongodbService.admin();
53
+ });
54
+ }
55
+ list() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ return this.mongodbService.list();
58
+ });
59
+ }
60
+ getNames() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ return [];
63
+ });
64
+ }
65
+ };
66
+ exports.MongodbController = MongodbController;
67
+ __decorate([
68
+ (0, core_1.Command)("mongodb:create [name]"),
69
+ __param(0, (0, core_1.Param)("name")),
70
+ __metadata("design:type", Function),
71
+ __metadata("design:paramtypes", [String]),
72
+ __metadata("design:returntype", Promise)
73
+ ], MongodbController.prototype, "create", null);
74
+ __decorate([
75
+ (0, core_1.Command)("mongodb:destroy <name>"),
76
+ __param(0, (0, core_1.Param)("name")),
77
+ __param(1, (0, core_1.Option)("yes", { alias: "y" })),
78
+ __param(2, (0, core_1.Option)("force", { alias: "f" })),
79
+ __metadata("design:type", Function),
80
+ __metadata("design:paramtypes", [String, Boolean, Boolean]),
81
+ __metadata("design:returntype", Promise)
82
+ ], MongodbController.prototype, "destroy", null);
83
+ __decorate([
84
+ (0, core_1.Command)("mongodb:start [name]"),
85
+ __param(0, (0, core_1.Param)("name")),
86
+ __param(1, (0, core_1.Option)("restart", { alias: "r" })),
87
+ __metadata("design:type", Function),
88
+ __metadata("design:paramtypes", [String, Boolean]),
89
+ __metadata("design:returntype", Promise)
90
+ ], MongodbController.prototype, "start", null);
91
+ __decorate([
92
+ (0, core_1.Command)("mongodb:stop [name]"),
93
+ __param(0, (0, core_1.Param)("name")),
94
+ __metadata("design:type", Function),
95
+ __metadata("design:paramtypes", [String]),
96
+ __metadata("design:returntype", Promise)
97
+ ], MongodbController.prototype, "stop", null);
98
+ __decorate([
99
+ (0, core_1.Command)("mongodb:ls"),
100
+ __metadata("design:type", Function),
101
+ __metadata("design:paramtypes", []),
102
+ __metadata("design:returntype", Promise)
103
+ ], MongodbController.prototype, "list", null);
104
+ __decorate([
105
+ (0, core_1.Completion)("name", "mongodb:start [name]"),
106
+ (0, core_1.Completion)("name", "mongodb:stop [name]"),
107
+ __metadata("design:type", Function),
108
+ __metadata("design:paramtypes", []),
109
+ __metadata("design:returntype", Promise)
110
+ ], MongodbController.prototype, "getNames", null);
111
+ exports.MongodbController = MongodbController = __decorate([
112
+ (0, core_1.Controller)(),
113
+ __metadata("design:paramtypes", [MongodbService_1.MongodbService])
114
+ ], MongodbController);
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export default class MongodbPlugin {
2
+ load(): Promise<void>;
3
+ }
File without changes
package/lib/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const core_1 = require("@wocker/core");
19
+ const MongodbController_1 = require("./controllers/MongodbController");
20
+ const MongodbService_1 = require("./services/MongodbService");
21
+ let MongodbPlugin = class MongodbPlugin {
22
+ load() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ console.log(">_<");
25
+ });
26
+ }
27
+ };
28
+ MongodbPlugin = __decorate([
29
+ (0, core_1.Plugin)({
30
+ name: "mongodb",
31
+ controllers: [MongodbController_1.MongodbController],
32
+ providers: [
33
+ core_1.PluginConfigService,
34
+ MongodbService_1.MongodbService
35
+ ]
36
+ })
37
+ ], MongodbPlugin);
38
+ exports.default = MongodbPlugin;
File without changes
@@ -0,0 +1,15 @@
1
+ import { ConfigCollection } from "@wocker/core";
2
+ import { Database, DatabaseProps } from "./Database";
3
+ export type ConfigProps = {
4
+ default?: string;
5
+ databases?: DatabaseProps[];
6
+ };
7
+ export declare abstract class Config {
8
+ default?: string;
9
+ databases: ConfigCollection<Database, DatabaseProps>;
10
+ constructor(props: ConfigProps);
11
+ getDatabase(name?: string): Database;
12
+ removeDatabase(name: string): void;
13
+ abstract save(): Promise<void>;
14
+ toJSON(): ConfigProps;
15
+ }
File without changes
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Config = void 0;
4
+ const core_1 = require("@wocker/core");
5
+ const Database_1 = require("./Database");
6
+ class Config {
7
+ constructor(props) {
8
+ const { default: defaultDatabase, databases = [] } = props;
9
+ this.default = defaultDatabase;
10
+ this.databases = new core_1.ConfigCollection(Database_1.Database, databases);
11
+ }
12
+ getDatabase(name) {
13
+ if (!name) {
14
+ if (!this.default) {
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;
22
+ }
23
+ const database = this.databases.getConfig(name);
24
+ if (!database) {
25
+ throw new Error(`Database ${name} not found`);
26
+ }
27
+ return database;
28
+ }
29
+ removeDatabase(name) {
30
+ const database = this.databases.getConfig(name);
31
+ if (!database) {
32
+ throw new Error(`Storage ${name} not found`);
33
+ }
34
+ this.databases.removeConfig(name);
35
+ }
36
+ toJSON() {
37
+ return {
38
+ default: this.default,
39
+ databases: this.databases.toArray()
40
+ };
41
+ }
42
+ }
43
+ exports.Config = Config;
File without changes
@@ -0,0 +1,17 @@
1
+ import { Config, ConfigProperties } from "@wocker/core";
2
+ export type DatabaseProps = ConfigProperties & {
3
+ username: string;
4
+ password: string;
5
+ configStorage?: string;
6
+ storage?: string;
7
+ };
8
+ export declare class Database extends Config<DatabaseProps> {
9
+ username: string;
10
+ password: string;
11
+ configStorage: string;
12
+ storage: string;
13
+ constructor(props: DatabaseProps);
14
+ get containerName(): string;
15
+ get defaultStorage(): string;
16
+ get defaultConfigStorage(): string;
17
+ }
File without changes
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Database = void 0;
4
+ const core_1 = require("@wocker/core");
5
+ class Database extends core_1.Config {
6
+ constructor(props) {
7
+ super(props);
8
+ const { username, password, configStorage, storage } = props;
9
+ this.username = username;
10
+ this.password = password;
11
+ this.configStorage = configStorage || this.defaultConfigStorage;
12
+ this.storage = storage || this.defaultStorage;
13
+ }
14
+ get containerName() {
15
+ return `mongodb-${this.name}.ws`;
16
+ }
17
+ get defaultStorage() {
18
+ return `wocker-mongodb-${this.name}`;
19
+ }
20
+ get defaultConfigStorage() {
21
+ return `wocker-mongodb-config-${this.name}`;
22
+ }
23
+ }
24
+ exports.Database = Database;
File without changes
@@ -0,0 +1,18 @@
1
+ import { AppConfigService, PluginConfigService, DockerService, ProxyService } from "@wocker/core";
2
+ import { Config } from "../makes/Config";
3
+ export declare class MongodbService {
4
+ protected readonly appConfigService: AppConfigService;
5
+ protected readonly pluginConfigService: PluginConfigService;
6
+ protected readonly dockerService: DockerService;
7
+ protected readonly proxyService: ProxyService;
8
+ adminContainerName: string;
9
+ constructor(appConfigService: AppConfigService, pluginConfigService: PluginConfigService, dockerService: DockerService, proxyService: ProxyService);
10
+ protected _config?: Config;
11
+ get config(): Config;
12
+ create(name?: string): Promise<void>;
13
+ destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
14
+ start(name?: string, restart?: boolean): Promise<void>;
15
+ admin(): Promise<void>;
16
+ stop(name?: string): Promise<void>;
17
+ list(): Promise<string>;
18
+ }
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.MongodbService = void 0;
25
+ const core_1 = require("@wocker/core");
26
+ const utils_1 = require("@wocker/utils");
27
+ const cli_table3_1 = __importDefault(require("cli-table3"));
28
+ const Config_1 = require("../makes/Config");
29
+ const Database_1 = require("../makes/Database");
30
+ let MongodbService = class MongodbService {
31
+ constructor(appConfigService, pluginConfigService, dockerService, proxyService) {
32
+ this.appConfigService = appConfigService;
33
+ this.pluginConfigService = pluginConfigService;
34
+ this.dockerService = dockerService;
35
+ this.proxyService = proxyService;
36
+ this.adminContainerName = "dbadmin-mongodb.workspace";
37
+ }
38
+ get config() {
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
+ const fs = this.pluginConfigService.fs;
55
+ this._config = new class extends Config_1.Config {
56
+ save() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ if (!fs.exists()) {
59
+ fs.mkdir("", {
60
+ recursive: true
61
+ });
62
+ }
63
+ yield fs.writeJSON("config.json", this.toJSON());
64
+ });
65
+ }
66
+ }(data);
67
+ }
68
+ return this._config;
69
+ }
70
+ create(name) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (name && this.config.databases.getConfig(name)) {
73
+ throw new Error(`${name}`);
74
+ }
75
+ if (!name) {
76
+ name = (yield (0, utils_1.promptText)({
77
+ message: "Mongodb name:",
78
+ type: "string",
79
+ validate: (name) => {
80
+ if (!name) {
81
+ return "Name is required";
82
+ }
83
+ if (this.config.databases.getConfig(name)) {
84
+ return `Database name "${name}" is already taken`;
85
+ }
86
+ return true;
87
+ }
88
+ }));
89
+ }
90
+ let username = "";
91
+ if (!username) {
92
+ username = yield (0, utils_1.promptText)({
93
+ message: "Username:",
94
+ type: "string"
95
+ });
96
+ }
97
+ let password = "";
98
+ if (!password) {
99
+ password = yield (0, utils_1.promptText)({
100
+ message: "Password:",
101
+ type: "string"
102
+ });
103
+ }
104
+ const database = new Database_1.Database({
105
+ name,
106
+ username,
107
+ password
108
+ });
109
+ this.config.databases.setConfig(database);
110
+ yield this.config.save();
111
+ });
112
+ }
113
+ destroy(name, yes, force) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ if (!this.appConfigService.isVersionGTE || !this.appConfigService.isVersionGTE("1.0.19")) {
116
+ throw new Error("Please update @wocker/ws");
117
+ }
118
+ const database = this.config.getDatabase(name);
119
+ if (!force && database.name === this.config.default) {
120
+ throw new Error(`Can't delete default database.`);
121
+ }
122
+ if (!yes) {
123
+ const confirm = yield (0, utils_1.promptConfirm)({
124
+ message: `Are you sure you want to delete the "${database.name}" database? This action cannot be undone and all data will be lost.`,
125
+ default: false
126
+ });
127
+ if (!confirm) {
128
+ throw new Error("Aborted");
129
+ }
130
+ }
131
+ if (database.configStorage === database.defaultConfigStorage && (yield this.dockerService.hasVolume(database.configStorage))) {
132
+ yield this.dockerService.rmVolume(database.configStorage);
133
+ }
134
+ if (database.storage === database.defaultStorage && (yield this.dockerService.hasVolume(database.storage))) {
135
+ yield this.dockerService.rmVolume(database.storage);
136
+ }
137
+ this.config.removeDatabase(database.name);
138
+ yield this.config.save();
139
+ });
140
+ }
141
+ start(name, restart) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ if (!this.appConfigService.isVersionGTE || !this.appConfigService.isVersionGTE("1.0.19")) {
144
+ throw new Error("Please update @wocker/ws");
145
+ }
146
+ const database = this.config.getDatabase(name);
147
+ if (restart) {
148
+ yield this.dockerService.removeContainer(database.containerName);
149
+ }
150
+ let container = yield this.dockerService.getContainer(database.containerName);
151
+ if (!container) {
152
+ container = yield this.dockerService.createContainer({
153
+ name: database.containerName,
154
+ restart: "always",
155
+ image: "mongo:latest",
156
+ env: {
157
+ MONGO_INITDB_ROOT_USERNAME: database.username,
158
+ MONGO_INITDB_ROOT_PASSWORD: database.password,
159
+ MONGO_ROOT_USER: database.username,
160
+ MONGO_ROOT_PASSWORD: database.password
161
+ },
162
+ volumes: [
163
+ `${database.configStorage}:/data/configdb`,
164
+ `${database.storage}:/data/db`
165
+ ]
166
+ });
167
+ }
168
+ const { State: { Running } } = yield container.inspect();
169
+ if (!Running) {
170
+ console.info(`Starting ${database.name} service...`);
171
+ yield container.start();
172
+ }
173
+ });
174
+ }
175
+ admin() {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ const connections = [];
178
+ for (const database of this.config.databases.items) {
179
+ try {
180
+ const container = yield this.dockerService.getContainer(database.containerName);
181
+ if (!container) {
182
+ continue;
183
+ }
184
+ const { State: { Running } } = yield container.inspect();
185
+ if (Running) {
186
+ connections.push(`mongodb://${database.username}:${database.password}@${database.containerName}:27017`);
187
+ // Multiple servers are not supported by mongo-express
188
+ break;
189
+ }
190
+ }
191
+ catch (ignore) { }
192
+ }
193
+ yield this.dockerService.removeContainer(this.adminContainerName);
194
+ if (connections.length === 0) {
195
+ return;
196
+ }
197
+ let container = yield this.dockerService.getContainer(this.adminContainerName);
198
+ if (!container) {
199
+ console.info("Mongodb Admin starting...");
200
+ yield this.dockerService.pullImage("mongo-express:latest");
201
+ container = yield this.dockerService.createContainer({
202
+ name: this.adminContainerName,
203
+ image: "mongo-express:latest",
204
+ restart: "always",
205
+ env: {
206
+ VIRTUAL_HOST: this.adminContainerName,
207
+ VIRTUAL_PORT: "80",
208
+ VCAP_APP_HOST: this.adminContainerName,
209
+ PORT: "80",
210
+ ME_CONFIG_BASICAUTH: "false",
211
+ ME_CONFIG_BASICAUTH_USERNAME: "",
212
+ ME_CONFIG_BASICAUTH_PASSWORD: "",
213
+ ME_CONFIG_MONGODB_ENABLE_ADMIN: "true",
214
+ ME_CONFIG_MONGODB_URL: connections.join(",")
215
+ }
216
+ });
217
+ }
218
+ const { State: { Running } } = yield container.inspect();
219
+ if (!Running) {
220
+ yield container.start();
221
+ yield this.proxyService.start();
222
+ }
223
+ });
224
+ }
225
+ stop(name) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ const database = this.config.getDatabase(name);
228
+ console.info(`Stopping ${database.name}...`);
229
+ yield this.dockerService.removeContainer(database.containerName);
230
+ });
231
+ }
232
+ list() {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ const table = new cli_table3_1.default({
235
+ head: [
236
+ "Name",
237
+ "Username",
238
+ "Host",
239
+ "Storages"
240
+ ]
241
+ });
242
+ for (const database of this.config.databases.items) {
243
+ table.push([
244
+ database.name,
245
+ database.username,
246
+ database.containerName,
247
+ `${database.configStorage}\n${database.storage}`
248
+ ]);
249
+ }
250
+ return table.toString();
251
+ });
252
+ }
253
+ };
254
+ exports.MongodbService = MongodbService;
255
+ exports.MongodbService = MongodbService = __decorate([
256
+ (0, core_1.Injectable)(),
257
+ __metadata("design:paramtypes", [core_1.AppConfigService,
258
+ core_1.PluginConfigService,
259
+ core_1.DockerService,
260
+ core_1.ProxyService])
261
+ ], MongodbService);
File without changes
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@wocker/mongodb-plugin",
3
+ "version": "1.0.0-beta.0",
4
+ "author": "Kris Papercut <krispcut@gmail.com>",
5
+ "description": "Mongodb plugin for wocker",
6
+ "license": "MIT",
7
+ "main": "lib/index.js",
8
+ "types": "lib/index.d.ts",
9
+ "keywords": [
10
+ "wocker",
11
+ "plugin",
12
+ "mongodb"
13
+ ],
14
+ "homepage": "https://kearisp.github.io/wocker/plugins/mongodb",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/kearisp/wocker-mongodb-plugin.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/kearisp/wocker-mongodb-plugin/issues"
21
+ },
22
+ "scripts": {
23
+ "prepare": "npm run build",
24
+ "watch": "tsc -w",
25
+ "build": "tsc",
26
+ "test": "echo \"Error: no test specified\" && exit 1"
27
+ },
28
+ "dependencies": {
29
+ "@wocker/core": "^1.0.20",
30
+ "@wocker/utils": "^1.0.8",
31
+ "cli-table3": "^0.6.5"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": ">=20.17.6",
35
+ "typescript": "^5.6.3"
36
+ }
37
+ }
File without changes
File without changes