@midwayjs/bull-board 4.0.0-alpha.1 → 4.0.0-beta.2

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 CHANGED
@@ -6,4 +6,4 @@ Document: [https://midwayjs.org](https://midwayjs.org)
6
6
 
7
7
  ## License
8
8
 
9
- [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
9
+ [MIT]((https://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -1,7 +1,18 @@
1
+ import { IMidwayContainer, MidwayFrameworkService } from '@midwayjs/core';
1
2
  import { createBullBoard } from '@bull-board/api';
2
3
  import { BaseAdapter } from '@bull-board/api/dist/src/queueAdapters/base';
4
+ import { MidwayAdapter } from './adapter';
5
+ import { BullBoardOption } from './interface';
3
6
  export declare class BullBoardManager {
4
7
  private bullBoard;
8
+ protected bullBoardConfig: BullBoardOption;
9
+ protected frameworkService: MidwayFrameworkService;
10
+ protected applicationContext: IMidwayContainer;
11
+ private basePath;
12
+ private serverAdapter;
13
+ protected init(): Promise<void>;
14
+ getBasePath(): string;
15
+ getServerAdapter(): MidwayAdapter;
5
16
  setBullBoard(bullBoard: ReturnType<typeof createBullBoard>): void;
6
17
  getBullBoardOrigin(): ReturnType<typeof createBullBoard>;
7
18
  addQueue(queue: BaseAdapter): void;
@@ -5,10 +5,51 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
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
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.BullBoardManager = void 0;
10
13
  const core_1 = require("@midwayjs/core");
14
+ const api_1 = require("@bull-board/api");
15
+ const bullAdapter_1 = require("@bull-board/api/bullAdapter");
16
+ const bullMQAdapter_1 = require("@bull-board/api/bullMQAdapter");
17
+ const adapter_1 = require("./adapter");
11
18
  let BullBoardManager = class BullBoardManager {
19
+ async init() {
20
+ let framework = this.frameworkService.getFramework('bull');
21
+ if (!framework) {
22
+ framework = this.frameworkService.getFramework('bullmq');
23
+ }
24
+ if (!framework) {
25
+ return;
26
+ }
27
+ const queueList = framework.getQueueList();
28
+ const wrapQueues = queueList.map(queue => {
29
+ if (this.applicationContext.hasNamespace('bull')) {
30
+ return new bullAdapter_1.BullAdapter(queue);
31
+ }
32
+ else if (this.applicationContext.hasNamespace('bullmq')) {
33
+ return new bullMQAdapter_1.BullMQAdapter(queue);
34
+ }
35
+ });
36
+ this.basePath = this.bullBoardConfig.basePath;
37
+ this.serverAdapter = new adapter_1.MidwayAdapter();
38
+ this.bullBoard = (0, api_1.createBullBoard)({
39
+ queues: wrapQueues,
40
+ serverAdapter: this.serverAdapter,
41
+ options: {
42
+ uiConfig: this.bullBoardConfig.uiConfig,
43
+ },
44
+ });
45
+ this.serverAdapter.setBasePath(this.basePath);
46
+ }
47
+ getBasePath() {
48
+ return this.basePath;
49
+ }
50
+ getServerAdapter() {
51
+ return this.serverAdapter;
52
+ }
12
53
  setBullBoard(bullBoard) {
13
54
  this.bullBoard = bullBoard;
14
55
  }
@@ -29,6 +70,24 @@ let BullBoardManager = class BullBoardManager {
29
70
  }
30
71
  };
31
72
  exports.BullBoardManager = BullBoardManager;
73
+ __decorate([
74
+ (0, core_1.Config)('bullBoard'),
75
+ __metadata("design:type", Object)
76
+ ], BullBoardManager.prototype, "bullBoardConfig", void 0);
77
+ __decorate([
78
+ (0, core_1.Inject)(),
79
+ __metadata("design:type", core_1.MidwayFrameworkService)
80
+ ], BullBoardManager.prototype, "frameworkService", void 0);
81
+ __decorate([
82
+ (0, core_1.ApplicationContext)(),
83
+ __metadata("design:type", Object)
84
+ ], BullBoardManager.prototype, "applicationContext", void 0);
85
+ __decorate([
86
+ (0, core_1.Init)(),
87
+ __metadata("design:type", Function),
88
+ __metadata("design:paramtypes", []),
89
+ __metadata("design:returntype", Promise)
90
+ ], BullBoardManager.prototype, "init", null);
32
91
  exports.BullBoardManager = BullBoardManager = __decorate([
33
92
  (0, core_1.Singleton)()
34
93
  ], BullBoardManager);
@@ -1,14 +1,11 @@
1
1
  import { IMiddleware, IMidwayApplication, IMidwayContext, NextFunction } from '@midwayjs/core';
2
- import * as bull from '@midwayjs/bull';
3
2
  import { BullBoardOption } from './interface';
4
3
  import { BullBoardManager } from './board.manager';
5
4
  export declare class BoardMiddleware implements IMiddleware<IMidwayContext, NextFunction, unknown> {
6
- protected framework: bull.Framework;
7
5
  protected bullBoardConfig: BullBoardOption;
8
6
  protected bullBoardManager: BullBoardManager;
9
7
  private basePath;
10
8
  private serverAdapter;
11
- protected init(): Promise<void>;
12
9
  resolve(app: IMidwayApplication): (req: any, res: any, next: NextFunction) => Promise<any>;
13
10
  static getName(): string;
14
11
  }
@@ -12,10 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BoardMiddleware = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  const path_1 = require("path");
15
- const bull = require("@midwayjs/bull");
16
- const api_1 = require("@bull-board/api");
17
- const bullAdapter_1 = require("@bull-board/api/bullAdapter");
18
- const adapter_1 = require("./adapter");
19
15
  const board_manager_1 = require("./board.manager");
20
16
  const MIME_MAP = {
21
17
  '.html': 'text/html',
@@ -36,22 +32,9 @@ const MIME_MAP = {
36
32
  '.otf': 'application/x-font-opentype',
37
33
  };
38
34
  let BoardMiddleware = class BoardMiddleware {
39
- async init() {
40
- const queueList = this.framework.getQueueList();
41
- const wrapQueues = queueList.map(queue => new bullAdapter_1.BullAdapter(queue));
42
- this.basePath = this.bullBoardConfig.basePath;
43
- this.serverAdapter = new adapter_1.MidwayAdapter();
44
- const bullBoard = (0, api_1.createBullBoard)({
45
- queues: wrapQueues,
46
- serverAdapter: this.serverAdapter,
47
- options: {
48
- uiConfig: this.bullBoardConfig.uiConfig,
49
- },
50
- });
51
- this.serverAdapter.setBasePath(this.basePath);
52
- this.bullBoardManager.setBullBoard(bullBoard);
53
- }
54
35
  resolve(app) {
36
+ this.basePath = this.bullBoardManager.getBasePath();
37
+ this.serverAdapter = this.bullBoardManager.getServerAdapter();
55
38
  if ('express' === app.getNamespace()) {
56
39
  return async (req, res, next) => {
57
40
  const pathname = req.path;
@@ -138,10 +121,6 @@ let BoardMiddleware = class BoardMiddleware {
138
121
  }
139
122
  };
140
123
  exports.BoardMiddleware = BoardMiddleware;
141
- __decorate([
142
- (0, core_1.Inject)(),
143
- __metadata("design:type", bull.Framework)
144
- ], BoardMiddleware.prototype, "framework", void 0);
145
124
  __decorate([
146
125
  (0, core_1.Config)('bullBoard'),
147
126
  __metadata("design:type", Object)
@@ -150,12 +129,6 @@ __decorate([
150
129
  (0, core_1.Inject)(),
151
130
  __metadata("design:type", board_manager_1.BullBoardManager)
152
131
  ], BoardMiddleware.prototype, "bullBoardManager", void 0);
153
- __decorate([
154
- (0, core_1.Init)(),
155
- __metadata("design:type", Function),
156
- __metadata("design:paramtypes", []),
157
- __metadata("design:returntype", Promise)
158
- ], BoardMiddleware.prototype, "init", null);
159
132
  exports.BoardMiddleware = BoardMiddleware = __decorate([
160
133
  (0, core_1.Provide)(),
161
134
  (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
@@ -1,7 +1,8 @@
1
- import { MidwayApplicationManager, MidwayConfigService } from '@midwayjs/core';
1
+ import { IMidwayContainer, MidwayApplicationManager, MidwayConfigService } from '@midwayjs/core';
2
2
  export declare class BullBoardConfiguration {
3
3
  applicationManager: MidwayApplicationManager;
4
4
  configService: MidwayConfigService;
5
- onReady(): Promise<void>;
5
+ onReady(container: IMidwayContainer): Promise<void>;
6
+ onServerReady(container: IMidwayContainer): Promise<void>;
6
7
  }
7
8
  //# sourceMappingURL=configuration.d.ts.map
@@ -10,11 +10,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BullBoardConfiguration = void 0;
13
- const bull = require("@midwayjs/bull");
14
13
  const core_1 = require("@midwayjs/core");
15
14
  const board_middleware_1 = require("./board.middleware");
15
+ const board_manager_1 = require("./board.manager");
16
16
  let BullBoardConfiguration = class BullBoardConfiguration {
17
- async onReady() {
17
+ async onReady(container) {
18
18
  const apps = this.applicationManager.getApplications([
19
19
  'express',
20
20
  'egg',
@@ -22,10 +22,16 @@ let BullBoardConfiguration = class BullBoardConfiguration {
22
22
  ]);
23
23
  if (apps.length) {
24
24
  apps.forEach(app => {
25
- app.useMiddleware(board_middleware_1.BoardMiddleware);
25
+ if (container.hasNamespace('bull') ||
26
+ container.hasNamespace('bullmq')) {
27
+ app.useMiddleware(board_middleware_1.BoardMiddleware);
28
+ }
26
29
  });
27
30
  }
28
31
  }
32
+ async onServerReady(container) {
33
+ await container.getAsync(board_manager_1.BullBoardManager);
34
+ }
29
35
  };
30
36
  exports.BullBoardConfiguration = BullBoardConfiguration;
31
37
  __decorate([
@@ -39,7 +45,6 @@ __decorate([
39
45
  exports.BullBoardConfiguration = BullBoardConfiguration = __decorate([
40
46
  (0, core_1.Configuration)({
41
47
  namespace: 'bull-board',
42
- imports: [bull],
43
48
  importConfigs: [
44
49
  {
45
50
  default: {
package/dist/index.d.ts CHANGED
@@ -3,4 +3,7 @@ export * from './board.middleware';
3
3
  export * from './board.manager';
4
4
  export * from './interface';
5
5
  export * as BullBoard from '@bull-board/api';
6
+ export { MidwayAdapter } from './adapter';
7
+ export { BullAdapter } from '@bull-board/api/bullAdapter';
8
+ export { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
6
9
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,11 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.BullBoard = exports.Configuration = void 0;
17
+ exports.BullMQAdapter = exports.BullAdapter = exports.MidwayAdapter = exports.BullBoard = exports.Configuration = void 0;
18
18
  var configuration_1 = require("./configuration");
19
19
  Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.BullBoardConfiguration; } });
20
20
  __exportStar(require("./board.middleware"), exports);
21
21
  __exportStar(require("./board.manager"), exports);
22
22
  __exportStar(require("./interface"), exports);
23
23
  exports.BullBoard = require("@bull-board/api");
24
+ var adapter_1 = require("./adapter");
25
+ Object.defineProperty(exports, "MidwayAdapter", { enumerable: true, get: function () { return adapter_1.MidwayAdapter; } });
26
+ var bullAdapter_1 = require("@bull-board/api/bullAdapter");
27
+ Object.defineProperty(exports, "BullAdapter", { enumerable: true, get: function () { return bullAdapter_1.BullAdapter; } });
28
+ var bullMQAdapter_1 = require("@bull-board/api/bullMQAdapter");
29
+ Object.defineProperty(exports, "BullMQAdapter", { enumerable: true, get: function () { return bullMQAdapter_1.BullMQAdapter; } });
24
30
  //# sourceMappingURL=index.js.map
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import '@midwayjs/bull';
2
1
  import { BullBoardOption } from './dist/index';
3
2
  export * from './dist/index';
4
3
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/bull-board",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "midway component for bull",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -13,6 +13,7 @@
13
13
  "midway",
14
14
  "IoC",
15
15
  "bull",
16
+ "bullmq",
16
17
  "bull-ui",
17
18
  "plugin"
18
19
  ],
@@ -24,19 +25,20 @@
24
25
  ],
25
26
  "license": "MIT",
26
27
  "devDependencies": {
27
- "@midwayjs/core": "^4.0.0-alpha.1",
28
- "@midwayjs/express": "^4.0.0-alpha.1",
29
- "@midwayjs/koa": "^4.0.0-alpha.1",
30
- "@midwayjs/mock": "^4.0.0-alpha.1"
28
+ "@midwayjs/bull": "^4.0.0-beta.2",
29
+ "@midwayjs/bullmq": "^4.0.0-beta.2",
30
+ "@midwayjs/core": "^4.0.0-beta.2",
31
+ "@midwayjs/express": "^4.0.0-beta.2",
32
+ "@midwayjs/koa": "^4.0.0-beta.2",
33
+ "@midwayjs/mock": "^4.0.0-beta.2"
31
34
  },
32
35
  "dependencies": {
33
36
  "@bull-board/api": "5.23.0",
34
37
  "@bull-board/ui": "5.23.0",
35
- "@midwayjs/bull": "^4.0.0-alpha.1",
36
38
  "ejs": "3.1.10"
37
39
  },
38
40
  "engines": {
39
- "node": ">=12"
41
+ "node": ">=20"
40
42
  },
41
- "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
43
+ "gitHead": "53bfef4c5279da5f09025e4610bdbf64f94f60bd"
42
44
  }