zyket 1.0.29 → 1.0.31
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/index.js
CHANGED
|
@@ -7,6 +7,8 @@ const { Handler, Guard } = require("./src/services/socketio");
|
|
|
7
7
|
const Schedule = require("./src/services/scheduler/Schedule");
|
|
8
8
|
const Event = require("./src/services/events/Event");
|
|
9
9
|
const Worker = require("./src/services/bullmq/Worker");
|
|
10
|
+
const BullBoardExtension = require("./src/extensions/bullboard");
|
|
11
|
+
const Extension = require("./src/extensions/Extension");
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
module.exports = {
|
|
@@ -16,5 +18,6 @@ module.exports = {
|
|
|
16
18
|
Handler, Guard,
|
|
17
19
|
Schedule, Event,
|
|
18
20
|
Worker,
|
|
19
|
-
EnvManager
|
|
21
|
+
EnvManager,
|
|
22
|
+
BullBoardExtension, Extension
|
|
20
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zyket",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"description": "",
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"@bull-board/express": "^6.14.2",
|
|
16
17
|
"bullmq": "^5.63.0",
|
|
17
18
|
"colors": "^1.4.0",
|
|
18
19
|
"cors": "^2.8.5",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const Extension = require('../Extension');
|
|
2
|
+
const { createBullBoard } = require('@bull-board/api')
|
|
3
|
+
const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter')
|
|
4
|
+
const { ExpressAdapter } = require('@bull-board/express')
|
|
5
|
+
|
|
6
|
+
module.exports = class BullBoardExtension extends Extension {
|
|
7
|
+
path;
|
|
8
|
+
|
|
9
|
+
constructor({ path = '/bullboard' } = {}) {
|
|
10
|
+
super("BullBoardExtension");
|
|
11
|
+
this.path = path || '/bullboard';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
load(container) {
|
|
15
|
+
if (!container.get('bullmq')) return container.get('logger').warn('BullBoardExtension: bullmq service not found, skipping BullBoard setup');
|
|
16
|
+
const bull = container.get('bullmq')
|
|
17
|
+
const serverAdapter = new ExpressAdapter()
|
|
18
|
+
serverAdapter.setBasePath(this.path)
|
|
19
|
+
|
|
20
|
+
createBullBoard({
|
|
21
|
+
queues: Object.values(bull.queues).map(queue => new BullMQAdapter(queue)),
|
|
22
|
+
serverAdapter
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const app = container.get('express').app()
|
|
26
|
+
app.use(this.path, serverAdapter.getRouter())
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/kernel/index.js
CHANGED
|
@@ -3,18 +3,22 @@ const EnvManager = require("../utils/EnvManager");
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const HTTPServer = require("./HTTPServer");
|
|
6
|
+
const Extension = require("../extensions/Extension");
|
|
6
7
|
|
|
7
8
|
module.exports = class Kernel {
|
|
8
9
|
container;
|
|
9
10
|
#services;
|
|
10
11
|
#onSocketConnection;
|
|
11
12
|
#httpServer;
|
|
13
|
+
#extensions = [];
|
|
12
14
|
|
|
13
15
|
constructor({
|
|
14
|
-
services = []
|
|
16
|
+
services = [],
|
|
17
|
+
extensions = [],
|
|
15
18
|
} = { }) {
|
|
16
19
|
this.container = new ContainerBuilder();
|
|
17
20
|
this.#services = services;
|
|
21
|
+
this.#extensions = extensions;
|
|
18
22
|
|
|
19
23
|
// create src folder if not exists
|
|
20
24
|
if (!fs.existsSync(path.join(process.cwd(), "src"))) {
|
|
@@ -41,6 +45,16 @@ module.exports = class Kernel {
|
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
47
|
|
|
48
|
+
for (const extension of this.#extensions) {
|
|
49
|
+
if (!(extension instanceof Extension)) {
|
|
50
|
+
throw new Error(`Extension ${extension.name} is not an instance of Extension class`);
|
|
51
|
+
}
|
|
52
|
+
this.container.get('logger').debug(`Loading extension ${extension.name}`);
|
|
53
|
+
await extension.load(this.container);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
44
58
|
return this;
|
|
45
59
|
}
|
|
46
60
|
|
|
@@ -58,4 +72,8 @@ module.exports = class Kernel {
|
|
|
58
72
|
|
|
59
73
|
this.container.compile();
|
|
60
74
|
}
|
|
75
|
+
|
|
76
|
+
async #loadExtensions() {
|
|
77
|
+
// Load extensions if any
|
|
78
|
+
}
|
|
61
79
|
}
|
|
@@ -50,7 +50,6 @@ module.exports = class Express extends Service {
|
|
|
50
50
|
...Express.swaggerConfig,
|
|
51
51
|
apis: [path.join(process.cwd(), "src", "routes", "**", "*.js")],
|
|
52
52
|
};
|
|
53
|
-
console.log("Swagger Options:", swaggerOptions);
|
|
54
53
|
const swaggerDocs = swaggerJsDoc(swaggerOptions);
|
|
55
54
|
this.#app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
|
|
56
55
|
|
|
@@ -71,7 +70,14 @@ module.exports = class Express extends Service {
|
|
|
71
70
|
|
|
72
71
|
this.#app[methodName](
|
|
73
72
|
route.path,
|
|
74
|
-
...middlewares.map(mw => (req, res, next) =>
|
|
73
|
+
...middlewares.map(mw => async (req, res, next) => {
|
|
74
|
+
try {
|
|
75
|
+
await mw.handle({ container: this.#container, request: req, response: res, next })
|
|
76
|
+
} catch (error) {
|
|
77
|
+
this.#container.get('logger').error(`Error in middleware for route [${methodName}] ${route.path}: ${error.message}`);
|
|
78
|
+
return res.status(500).json({ success: false, message: error.message || 'Internal Server Error' });
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
75
81
|
async (req, res) => {
|
|
76
82
|
try {
|
|
77
83
|
const routeResponse = await route[methodName]({ container: this.#container, request: req, response: res });
|