@bull-board/elysia 6.5.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.
- package/README.md +23 -0
- package/dist/ElysiaAdapter.d.ts +41 -0
- package/dist/ElysiaAdapter.js +119 -0
- package/dist/ElysiaAdapter.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# <img alt="@bull-board" src="https://raw.githubusercontent.com/felixmosh/bull-board/master/packages/ui/src/static/images/logo.svg" width="35px" /> @bull-board/elysia
|
|
2
|
+
|
|
3
|
+
[Elysia](https://expressjs.com/) server adapter for `bull-board`.
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@bull-board/express">
|
|
7
|
+
<img alt="npm version" src="https://img.shields.io/npm/v/@bull-board/express">
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/bull-board">
|
|
10
|
+
<img alt="npm downloads" src="https://img.shields.io/npm/dw/bull-board">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://github.com/vcapretz/bull-board/blob/master/LICENSE">
|
|
13
|
+
<img alt="licence" src="https://img.shields.io/github/license/vcapretz/bull-board">
|
|
14
|
+
</a>
|
|
15
|
+
<p>
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
# Usage examples
|
|
21
|
+
1. [Simple express setup](https://github.com/felixmosh/bull-board/tree/master/examples/with-elysia)
|
|
22
|
+
|
|
23
|
+
For more info visit the main [README](https://github.com/felixmosh/bull-board#readme)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AppControllerRoute, AppViewRoute, BullBoardQueues, ControllerHandlerReturnType, IServerAdapter, UIConfig } from '@bull-board/api/dist/typings/app';
|
|
2
|
+
import { Elysia } from 'elysia';
|
|
3
|
+
export declare class ElysiaAdapter implements IServerAdapter {
|
|
4
|
+
private plugin;
|
|
5
|
+
private basePath;
|
|
6
|
+
private entryRoute;
|
|
7
|
+
private statics;
|
|
8
|
+
private bullBoardQueues;
|
|
9
|
+
private viewPath;
|
|
10
|
+
private uiConfig;
|
|
11
|
+
constructor(basePath?: string);
|
|
12
|
+
setStaticPath(staticsRoute: string, staticsPath: string): ElysiaAdapter;
|
|
13
|
+
setViewsPath(viewPath: string): ElysiaAdapter;
|
|
14
|
+
setErrorHandler(handler: (error: Error) => ControllerHandlerReturnType): this;
|
|
15
|
+
setApiRoutes(routes: AppControllerRoute[]): ElysiaAdapter;
|
|
16
|
+
setEntryRoute(routeDef: AppViewRoute): ElysiaAdapter;
|
|
17
|
+
setQueues(bullBoardQueues: BullBoardQueues): ElysiaAdapter;
|
|
18
|
+
setUIConfig(config?: UIConfig): ElysiaAdapter;
|
|
19
|
+
registerPlugin(): Elysia<"", false, {
|
|
20
|
+
decorator: {};
|
|
21
|
+
store: {};
|
|
22
|
+
derive: {};
|
|
23
|
+
resolve: {};
|
|
24
|
+
}, {
|
|
25
|
+
type: {};
|
|
26
|
+
error: {};
|
|
27
|
+
}, {
|
|
28
|
+
schema: {};
|
|
29
|
+
macro: {};
|
|
30
|
+
macroFn: {};
|
|
31
|
+
}, {}, {
|
|
32
|
+
derive: {};
|
|
33
|
+
resolve: {};
|
|
34
|
+
schema: import("elysia").MergeSchema<{}, import("elysia").MergeSchema<{}, {}>>;
|
|
35
|
+
}, {
|
|
36
|
+
derive: {};
|
|
37
|
+
resolve: {};
|
|
38
|
+
schema: {};
|
|
39
|
+
}>;
|
|
40
|
+
private registerRoute;
|
|
41
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ElysiaAdapter = void 0;
|
|
7
|
+
const ejs_1 = __importDefault(require("ejs"));
|
|
8
|
+
const elysia_1 = require("elysia");
|
|
9
|
+
class ElysiaAdapter {
|
|
10
|
+
constructor(basePath = '') {
|
|
11
|
+
this.plugin = new elysia_1.Elysia({
|
|
12
|
+
name: '@bull-board/elysia',
|
|
13
|
+
}).as('plugin');
|
|
14
|
+
this.basePath = '';
|
|
15
|
+
this.uiConfig = {};
|
|
16
|
+
if (basePath.length) {
|
|
17
|
+
// it shows prefix is "" in types
|
|
18
|
+
this.basePath = basePath;
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
this.plugin.config.prefix = this.basePath;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
setStaticPath(staticsRoute, staticsPath) {
|
|
25
|
+
this.statics = { route: staticsRoute, path: staticsPath };
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
setViewsPath(viewPath) {
|
|
29
|
+
this.viewPath = viewPath;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
setErrorHandler(handler) {
|
|
33
|
+
this.plugin.onError(({ error, set }) => {
|
|
34
|
+
const response = handler(error);
|
|
35
|
+
set.status = response.status || 500;
|
|
36
|
+
return response.body;
|
|
37
|
+
});
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
setApiRoutes(routes) {
|
|
41
|
+
for (const { route, handler, method } of routes) {
|
|
42
|
+
const methods = Array.isArray(method) ? method : [method];
|
|
43
|
+
for (const method of methods) {
|
|
44
|
+
this.registerRoute(route, method, handler);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
setEntryRoute(routeDef) {
|
|
50
|
+
this.entryRoute = routeDef;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
setQueues(bullBoardQueues) {
|
|
54
|
+
this.bullBoardQueues = bullBoardQueues;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
setUIConfig(config = {}) {
|
|
58
|
+
this.uiConfig = config;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
registerPlugin() {
|
|
62
|
+
if (!this.statics) {
|
|
63
|
+
throw new Error(`Please call 'setStaticPath' before using 'registerHandlers'`);
|
|
64
|
+
}
|
|
65
|
+
if (!this.entryRoute) {
|
|
66
|
+
throw new Error(`Please call 'setEntryRoute' before using 'registerHandlers'`);
|
|
67
|
+
}
|
|
68
|
+
if (!this.viewPath) {
|
|
69
|
+
throw new Error(`Please call 'setViewsPath' before using 'registerHandlers'`);
|
|
70
|
+
}
|
|
71
|
+
if (!this.uiConfig) {
|
|
72
|
+
throw new Error(`Please call 'setUIConfig' before using 'registerHandlers'`);
|
|
73
|
+
}
|
|
74
|
+
const { method, route, handler } = this.entryRoute;
|
|
75
|
+
const routes = Array.isArray(route) ? route : [route];
|
|
76
|
+
for (const route of routes) {
|
|
77
|
+
this.plugin.route(method.toUpperCase(), route, async () => {
|
|
78
|
+
const { name: filename, params } = handler({
|
|
79
|
+
basePath: this.basePath,
|
|
80
|
+
uiConfig: this.uiConfig,
|
|
81
|
+
});
|
|
82
|
+
return new Response(await ejs_1.default.renderFile(`${this.viewPath}/${filename}`, params), {
|
|
83
|
+
headers: {
|
|
84
|
+
'content-type': 'text/html',
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const glob = new Bun.Glob(`${this.statics.path}/**/*`);
|
|
90
|
+
for (const path of glob.scanSync()) {
|
|
91
|
+
this.plugin.get(
|
|
92
|
+
// TODO: maybe recode this
|
|
93
|
+
path.substring(path.indexOf('dist') + 4).replaceAll('\\', '/'), () => new Response(Bun.file(path)));
|
|
94
|
+
}
|
|
95
|
+
return this.plugin.as('plugin');
|
|
96
|
+
}
|
|
97
|
+
registerRoute(routeOrRoutes, method, handler) {
|
|
98
|
+
const { bullBoardQueues } = this;
|
|
99
|
+
if (!bullBoardQueues) {
|
|
100
|
+
throw new Error(`Please call 'setQueues' before using 'registerHandlers'`);
|
|
101
|
+
}
|
|
102
|
+
const routes = Array.isArray(routeOrRoutes) ? routeOrRoutes : [routeOrRoutes];
|
|
103
|
+
for (const route of routes) {
|
|
104
|
+
this.plugin.route(method.toUpperCase(), route, async ({ params, body, query, set }) => {
|
|
105
|
+
const response = await handler({
|
|
106
|
+
queues: this.bullBoardQueues,
|
|
107
|
+
params,
|
|
108
|
+
body: body,
|
|
109
|
+
query,
|
|
110
|
+
});
|
|
111
|
+
if (response.status)
|
|
112
|
+
set.status = response.status;
|
|
113
|
+
return response.body;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.ElysiaAdapter = ElysiaAdapter;
|
|
119
|
+
//# sourceMappingURL=ElysiaAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElysiaAdapter.js","sourceRoot":"","sources":["../src/ElysiaAdapter.ts"],"names":[],"mappings":";;;;;;AASA,8CAAsB;AACtB,mCAAgC;AAEhC,MAAa,aAAa;IAWxB,YAAY,QAAQ,GAAG,EAAE;QAVjB,WAAM,GAAG,IAAI,eAAM,CAAC;YAC1B,IAAI,EAAE,oBAAoB;SAC3B,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;QACR,aAAQ,GAAG,EAAE,CAAC;QAKd,aAAQ,GAAa,EAAE,CAAC;QAG9B,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,iCAAiC;YACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,6DAA6D;YAC7D,aAAa;YACb,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC5C,CAAC;IACH,CAAC;IAEM,aAAa,CAAC,YAAoB,EAAE,WAAmB;QAC5D,IAA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MAAM;oBACN,IAAI,EAAE,IAA+B;oBACrC,KAAK;iBACN,CAAC,CAAC;gBAEH,IAAI,QAAQ,CAAC,MAAM;oBAAE,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;gBAElD,OAAO,QAAQ,CAAC,IAAI,CAAC;YACvB,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAnJD,sCAmJC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ElysiaAdapter } from './ElysiaAdapter';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ElysiaAdapter = void 0;
|
|
4
|
+
var ElysiaAdapter_1 = require("./ElysiaAdapter");
|
|
5
|
+
Object.defineProperty(exports, "ElysiaAdapter", { enumerable: true, get: function () { return ElysiaAdapter_1.ElysiaAdapter; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bull-board/elysia",
|
|
3
|
+
"type": "commonjs",
|
|
4
|
+
"version": "6.5.0",
|
|
5
|
+
"description": "A Elysia server adapter for Bull-Board dashboard.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"bull",
|
|
8
|
+
"bullmq",
|
|
9
|
+
"redis",
|
|
10
|
+
"elysia",
|
|
11
|
+
"elysia-plugin",
|
|
12
|
+
"adapter",
|
|
13
|
+
"queue",
|
|
14
|
+
"monitoring",
|
|
15
|
+
"dashboard"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/felixmosh/bull-board.git",
|
|
20
|
+
"directory": "packages/elysia"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "kravetsone",
|
|
25
|
+
"url": "https://github.com/kravetsone"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"clean": "rm -rf dist"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@bull-board/api": "6.5.0",
|
|
38
|
+
"@bull-board/ui": "6.5.0",
|
|
39
|
+
"ejs": "^3.1.10"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"elysia": "^1.1.0"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/bun": "^1.1.13",
|
|
49
|
+
"@types/ejs": "^3.1.5",
|
|
50
|
+
"elysia": "^1.1.24"
|
|
51
|
+
}
|
|
52
|
+
}
|