@nest-boot/bullmq 7.0.2 → 7.1.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.
@@ -1,4 +1,6 @@
1
1
  import { ConnectionOptions, type QueueOptions } from "bullmq";
2
+ /** Configuration options for the BullMQ module. */
2
3
  export interface BullModuleOptions extends Omit<QueueOptions, "connection"> {
4
+ /** Redis connection options for BullMQ queues and workers. */
3
5
  connection?: ConnectionOptions;
4
6
  }
@@ -2,4 +2,4 @@ import { BullModuleOptions } from "./bullmq-module-options.interface";
2
2
  export declare const SCHEDULE_QUEUE_NAME = "schedule";
3
3
  export declare const SCHEDULE_METADATA_KEY: `${string}-${string}-${string}-${string}-${string}`;
4
4
  export declare const MODULE_OPTIONS_TOKEN: unique symbol;
5
- export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<BullModuleOptions, "forRoot", "create", {}>, BASE_MODULE_OPTIONS_TOKEN: string | symbol;
5
+ export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<BullModuleOptions, "forRoot", "create", {}>, BASE_MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: BullModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<BullModuleOptions, "create"> & Partial<{}>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BASE_MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.MODULE_OPTIONS_TOKEN = exports.SCHEDULE_METADATA_KEY = exports.SCHEDULE_QUEUE_NAME = void 0;
4
+ exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.BASE_MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.MODULE_OPTIONS_TOKEN = exports.SCHEDULE_METADATA_KEY = exports.SCHEDULE_QUEUE_NAME = void 0;
5
5
  const common_1 = require("@nestjs/common");
6
6
  const crypto_1 = require("crypto");
7
7
  exports.SCHEDULE_QUEUE_NAME = "schedule";
@@ -9,5 +9,5 @@ exports.SCHEDULE_METADATA_KEY = (0, crypto_1.randomUUID)();
9
9
  exports.MODULE_OPTIONS_TOKEN = Symbol("BullModuleOptions");
10
10
  _a = new common_1.ConfigurableModuleBuilder()
11
11
  .setClassMethodName("forRoot")
12
- .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.BASE_MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
12
+ .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.BASE_MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
13
13
  //# sourceMappingURL=bullmq.module-definition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bullmq.module-definition.js","sourceRoot":"","sources":["../src/bullmq.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAC3D,mCAAoC;AAIvB,QAAA,mBAAmB,GAAG,UAAU,CAAC;AAEjC,QAAA,qBAAqB,GAAG,IAAA,mBAAU,GAAE,CAAC;AAErC,QAAA,oBAAoB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAEnD,KAGT,IAAI,kCAAyB,EAAqB;KACnD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EAJR,+BAAuB,+BACD,iCAAyB,2BAGtC"}
1
+ {"version":3,"file":"bullmq.module-definition.js","sourceRoot":"","sources":["../src/bullmq.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAC3D,mCAAoC;AAIvB,QAAA,mBAAmB,GAAG,UAAU,CAAC;AAEjC,QAAA,qBAAqB,GAAG,IAAA,mBAAU,GAAE,CAAC;AAErC,QAAA,oBAAoB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAEnD,KAKT,IAAI,kCAAyB,EAAqB;KACnD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EANR,+BAAuB,+BACD,iCAAyB,4BAC/C,oBAAY,oBACZ,0BAAkB,yBAGT"}
@@ -1,7 +1,36 @@
1
1
  import { BullModule as BaseBullModule } from "@nestjs/bullmq";
2
2
  import { type DynamicModule } from "@nestjs/common";
3
- import { ConfigurableModuleClass } from "./bullmq.module-definition";
3
+ import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./bullmq.module-definition";
4
+ /**
5
+ * BullMQ integration module for job queue processing.
6
+ *
7
+ * @remarks
8
+ * Wraps `@nestjs/bullmq` with automatic Redis connection configuration
9
+ * from environment variables. Supports registering queues and flow producers.
10
+ */
4
11
  export declare class BullModule extends ConfigurableModuleClass {
12
+ /**
13
+ * Registers the BullModule with the given options.
14
+ * @param options - Configuration options including Redis connection
15
+ * @returns Dynamic module configuration
16
+ */
17
+ static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
18
+ /**
19
+ * Registers the BullModule asynchronously with factory functions.
20
+ * @param options - Async configuration options
21
+ * @returns Dynamic module configuration
22
+ */
23
+ static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
24
+ /**
25
+ * Registers a BullMQ queue.
26
+ * @param args - registerQueue arguments
27
+ * @returns Dynamic module configuration
28
+ */
5
29
  static registerQueue(...args: Parameters<typeof BaseBullModule.registerQueue>): DynamicModule;
30
+ /**
31
+ * Registers a BullMQ queue asynchronously.
32
+ * @param args - registerQueueAsync arguments
33
+ * @returns Dynamic module configuration
34
+ */
6
35
  static registerQueueAsync(...args: Parameters<typeof BaseBullModule.registerQueueAsync>): DynamicModule;
7
36
  }
@@ -11,10 +11,43 @@ const bullmq_1 = require("@nestjs/bullmq");
11
11
  const common_1 = require("@nestjs/common");
12
12
  const bullmq_module_definition_1 = require("./bullmq.module-definition");
13
13
  const load_config_from_env_util_1 = require("./utils/load-config-from-env.util");
14
+ /**
15
+ * BullMQ integration module for job queue processing.
16
+ *
17
+ * @remarks
18
+ * Wraps `@nestjs/bullmq` with automatic Redis connection configuration
19
+ * from environment variables. Supports registering queues and flow producers.
20
+ */
14
21
  let BullModule = class BullModule extends bullmq_module_definition_1.ConfigurableModuleClass {
22
+ /**
23
+ * Registers the BullModule with the given options.
24
+ * @param options - Configuration options including Redis connection
25
+ * @returns Dynamic module configuration
26
+ */
27
+ static forRoot(options) {
28
+ return super.forRoot(options);
29
+ }
30
+ /**
31
+ * Registers the BullModule asynchronously with factory functions.
32
+ * @param options - Async configuration options
33
+ * @returns Dynamic module configuration
34
+ */
35
+ static forRootAsync(options) {
36
+ return super.forRootAsync(options);
37
+ }
38
+ /**
39
+ * Registers a BullMQ queue.
40
+ * @param args - registerQueue arguments
41
+ * @returns Dynamic module configuration
42
+ */
15
43
  static registerQueue(...args) {
16
44
  return bullmq_1.BullModule.registerQueue(...args);
17
45
  }
46
+ /**
47
+ * Registers a BullMQ queue asynchronously.
48
+ * @param args - registerQueueAsync arguments
49
+ * @returns Dynamic module configuration
50
+ */
18
51
  static registerQueueAsync(...args) {
19
52
  return bullmq_1.BullModule.registerQueueAsync(...args);
20
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bullmq.module.js","sourceRoot":"","sources":["../src/bullmq.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8D;AAC9D,2CAAoE;AAEpE,yEAIoC;AAEpC,iFAAsE;AAwB/D,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,kDAAuB;IACrD,MAAM,CAAC,aAAa,CAClB,GAAG,IAAqD;QAExD,OAAO,mBAAc,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,kBAAkB,CACvB,GAAG,IAA0D;QAE7D,OAAO,mBAAc,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC,CAAC;IACpD,CAAC;CACF,C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;OAIG;IACH,MAAM,CAAC,kBAAkB,CACvB,GAAG,IAA0D;QAE7D,OAAO,mBAAc,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC,CAAC;IACpD,CAAC;CACF,CAAA;AA1CY,gCAAU;qBAAV,UAAU;IAtBtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,mBAAc,CAAC,YAAY,CAAC;gBAC1B,MAAM,EAAE,CAAC,+CAAoB,CAAC;gBAC9B,UAAU,EAAE,CAAC,OAA0B,EAAE,EAAE;oBACzC,OAAO;wBACL,GAAG,OAAO;wBACV,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,IAAA,6CAAiB,GAAE;qBACtD,CAAC;gBACJ,CAAC;aACF,CAAC;SACH;QACD,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,+CAAoB;gBAC7B,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,oDAAyB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gBAC9D,UAAU,EAAE,CAAC,OAA2B,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE;aAC3D;SACF;QACD,OAAO,EAAE,CAAC,+CAAoB,CAAC;KAChC,CAAC;GACW,UAAU,CA0CtB"}
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1,37 +1,117 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- require("dotenv/config");
4
- const testing_1 = require("@nestjs/testing");
5
- const _1 = require(".");
3
+ const constants_1 = require("@nestjs/common/constants");
4
+ let mockForRootAsyncOptions;
5
+ const mockBaseBullModule = {
6
+ forRootAsync: jest.fn((options) => {
7
+ mockForRootAsyncOptions = options;
8
+ return {
9
+ module: class BaseRootModule {
10
+ },
11
+ };
12
+ }),
13
+ registerQueue: jest.fn(),
14
+ registerQueueAsync: jest.fn(),
15
+ };
16
+ jest.mock("@nestjs/bullmq", () => ({
17
+ BullModule: mockBaseBullModule,
18
+ QueueEventsListener: class QueueEventsListener {
19
+ },
20
+ }));
21
+ const bullmq_module_1 = require("./bullmq.module");
22
+ const bullmq_module_definition_1 = require("./bullmq.module-definition");
23
+ const load_config_from_env_util_1 = require("./utils/load-config-from-env.util");
24
+ jest.mock("./utils/load-config-from-env.util", () => ({
25
+ loadConfigFromEnv: jest.fn(() => ({
26
+ host: "redis.local",
27
+ })),
28
+ }));
6
29
  describe("BullModule", () => {
7
- let app;
8
- it(`BullModule`, async () => {
9
- const moduleRef = await testing_1.Test.createTestingModule({
10
- imports: [_1.BullModule],
11
- }).compile();
12
- app = moduleRef.createNestApplication();
13
- await app.init();
14
- await app.close();
30
+ beforeEach(() => {
31
+ jest.clearAllMocks();
15
32
  });
16
- it(`BullModule.forRoot`, async () => {
17
- const moduleRef = await testing_1.Test.createTestingModule({
18
- imports: [_1.BullModule.forRoot({})],
19
- }).compile();
20
- app = moduleRef.createNestApplication();
21
- await app.init();
22
- await app.close();
33
+ it("should register synchronous and asynchronous options", () => {
34
+ const options = {
35
+ connection: {
36
+ host: "redis.local",
37
+ },
38
+ };
39
+ const dynamicModule = bullmq_module_1.BullModule.forRoot(options);
40
+ const useFactory = () => options;
41
+ const asyncModule = bullmq_module_1.BullModule.forRootAsync({
42
+ useFactory,
43
+ });
44
+ expect(dynamicModule.module).toBe(bullmq_module_1.BullModule);
45
+ expect(dynamicModule.providers).toEqual(expect.arrayContaining([
46
+ {
47
+ provide: bullmq_module_definition_1.BASE_MODULE_OPTIONS_TOKEN,
48
+ useValue: options,
49
+ },
50
+ ]));
51
+ expect(asyncModule.providers).toEqual(expect.arrayContaining([
52
+ {
53
+ inject: [],
54
+ provide: bullmq_module_definition_1.BASE_MODULE_OPTIONS_TOKEN,
55
+ useFactory,
56
+ },
57
+ ]));
23
58
  });
24
- it(`BullModule.forRootAsync`, async () => {
25
- const moduleRef = await testing_1.Test.createTestingModule({
26
- imports: [
27
- _1.BullModule.forRootAsync({
28
- useFactory: () => ({}),
29
- }),
30
- ],
31
- }).compile();
32
- app = moduleRef.createNestApplication();
33
- await app.init();
34
- await app.close();
59
+ it("should provide empty options when base options are missing", () => {
60
+ const providers = Reflect.getMetadata(constants_1.MODULE_METADATA.PROVIDERS, bullmq_module_1.BullModule);
61
+ const optionsProvider = providers.find((provider) => provider.provide === bullmq_module_definition_1.MODULE_OPTIONS_TOKEN);
62
+ expect(optionsProvider).toBeDefined();
63
+ expect(optionsProvider?.useFactory(undefined)).toEqual({});
64
+ expect(optionsProvider?.useFactory({
65
+ prefix: "jobs",
66
+ })).toEqual({
67
+ prefix: "jobs",
68
+ });
69
+ });
70
+ it("should merge module options with environment Redis config", () => {
71
+ const imports = Reflect.getMetadata(constants_1.MODULE_METADATA.IMPORTS, bullmq_module_1.BullModule);
72
+ expect(mockForRootAsyncOptions).toEqual(expect.objectContaining({
73
+ inject: [bullmq_module_definition_1.MODULE_OPTIONS_TOKEN],
74
+ }));
75
+ expect(mockForRootAsyncOptions.useFactory({
76
+ prefix: "jobs",
77
+ })).toEqual({
78
+ connection: {
79
+ host: "redis.local",
80
+ },
81
+ prefix: "jobs",
82
+ });
83
+ expect(mockForRootAsyncOptions.useFactory({
84
+ connection: {
85
+ host: "custom.redis",
86
+ },
87
+ })).toEqual({
88
+ connection: {
89
+ host: "custom.redis",
90
+ },
91
+ });
92
+ expect(load_config_from_env_util_1.loadConfigFromEnv).toHaveBeenCalledTimes(1);
93
+ expect(imports).toEqual([
94
+ {
95
+ module: expect.any(Function),
96
+ },
97
+ ]);
98
+ });
99
+ it("should delegate queue registration to the base Bull module", () => {
100
+ const queueModule = {
101
+ module: class QueueModule {
102
+ },
103
+ };
104
+ const asyncQueueModule = {
105
+ module: class AsyncQueueModule {
106
+ },
107
+ };
108
+ mockBaseBullModule.registerQueue.mockReturnValue(queueModule);
109
+ mockBaseBullModule.registerQueueAsync.mockReturnValue(asyncQueueModule);
110
+ expect(bullmq_module_1.BullModule.registerQueue({ name: "email" })).toBe(queueModule);
111
+ expect(bullmq_module_1.BullModule.registerQueueAsync({
112
+ name: "email",
113
+ useFactory: () => ({}),
114
+ })).toBe(asyncQueueModule);
35
115
  });
36
116
  });
37
117
  //# sourceMappingURL=bullmq.module.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bullmq.module.spec.js","sourceRoot":"","sources":["../src/bullmq.module.spec.ts"],"names":[],"mappings":";;AAAA,yBAAuB;AAGvB,6CAAuC;AAEvC,wBAA+B;AAE/B,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,IAAI,GAAqB,CAAC;IAE1B,EAAE,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE;QAC1B,MAAM,SAAS,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC/C,OAAO,EAAE,CAAC,aAAU,CAAC;SACtB,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,GAAG,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oBAAoB,EAAE,KAAK,IAAI,EAAE;QAClC,MAAM,SAAS,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC/C,OAAO,EAAE,CAAC,aAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;SAClC,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,GAAG,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;QACvC,MAAM,SAAS,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC/C,OAAO,EAAE;gBACP,aAAU,CAAC,YAAY,CAAC;oBACtB,UAAU,EAAE,GAAG,EAAE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AC,eAAe,CAAC,WAAW,CAAC,CAAC;QAC9D,kBAAkB,CAAC,kBAAkB,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC;QAExE,MAAM,CAAC,0BAAU,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACtE,MAAM,CACJ,0BAAU,CAAC,kBAAkB,CAAC;YAC5B,IAAI,EAAE,OAAO;YACb,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;SACvB,CAAC,CACH,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,4 +3,3 @@ export * from "./bullmq-module-options.interface";
3
3
  export { Processor } from "./processor.decorator";
4
4
  export * from "@nestjs/bullmq";
5
5
  export { QueueEventsListener } from "@nestjs/bullmq";
6
- export * from "bullmq";
package/dist/index.js CHANGED
@@ -23,5 +23,4 @@ Object.defineProperty(exports, "Processor", { enumerable: true, get: function ()
23
23
  __exportStar(require("@nestjs/bullmq"), exports);
24
24
  var bullmq_1 = require("@nestjs/bullmq");
25
25
  Object.defineProperty(exports, "QueueEventsListener", { enumerable: true, get: function () { return bullmq_1.QueueEventsListener; } });
26
- __exportStar(require("bullmq"), exports);
27
26
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA6C;AAApC,2GAAA,UAAU,OAAA;AACnB,oEAAkD;AAClD,6DAAkD;AAAzC,gHAAA,SAAS,OAAA;AAClB,iDAA+B;AAC/B,yCAAqD;AAA5C,6GAAA,mBAAmB,OAAA;AAC5B,yCAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA6C;AAApC,2GAAA,UAAU,OAAA;AACnB,oEAAkD;AAClD,6DAAkD;AAAzC,gHAAA,SAAS,OAAA;AAClB,iDAA+B;AAC/B,yCAAqD;AAA5C,6GAAA,mBAAmB,OAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const publicApi = __importStar(require("."));
37
+ const bullmq_module_1 = require("./bullmq.module");
38
+ const processor_decorator_1 = require("./processor.decorator");
39
+ describe("public API", () => {
40
+ it("should export Bull module and upstream BullMQ helpers", () => {
41
+ expect(publicApi.BullModule).toBe(bullmq_module_1.BullModule);
42
+ expect(publicApi.Processor).toBe(processor_decorator_1.Processor);
43
+ expect(publicApi.WorkerHost).toBeDefined();
44
+ expect(publicApi.QueueEventsListener).toBeDefined();
45
+ });
46
+ });
47
+ //# sourceMappingURL=index.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,mDAA6C;AAC7C,+DAAkD;AAElD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE;QAC/D,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,0BAAU,CAAC,CAAC;QAC9C,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,+BAAS,CAAC,CAAC;QAC5C,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC,WAAW,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,6 +1,32 @@
1
1
  import { ProcessorOptions } from "@nestjs/bullmq";
2
2
  import { NestWorkerOptions } from "@nestjs/bullmq/dist/interfaces/worker-options.interface";
3
+ /**
4
+ * Decorator that marks a class as a BullMQ queue processor.
5
+ *
6
+ * @remarks
7
+ * Wraps the `@nestjs/bullmq` `Processor` decorator to automatically
8
+ * create a {@link RequestContext} for each processed job.
9
+ *
10
+ * @param queueName - The name of the queue to process
11
+ */
3
12
  export declare function Processor(queueName: string): ClassDecorator;
13
+ /**
14
+ * Decorator that marks a class as a BullMQ queue processor with worker options.
15
+ *
16
+ * @param queueName - The name of the queue to process
17
+ * @param workerOptions - Worker configuration options
18
+ */
4
19
  export declare function Processor(queueName: string, workerOptions: NestWorkerOptions): ClassDecorator;
20
+ /**
21
+ * Decorator that marks a class as a BullMQ queue processor with processor options.
22
+ *
23
+ * @param processorOptions - Processor configuration options
24
+ */
5
25
  export declare function Processor(processorOptions: ProcessorOptions): ClassDecorator;
26
+ /**
27
+ * Decorator that marks a class as a BullMQ queue processor with processor and worker options.
28
+ *
29
+ * @param processorOptions - Processor configuration options
30
+ * @param workerOptions - Worker configuration options
31
+ */
6
32
  export declare function Processor(processorOptions: ProcessorOptions, workerOptions: NestWorkerOptions): ClassDecorator;
@@ -1 +1 @@
1
- {"version":3,"file":"processor.decorator.js","sourceRoot":"","sources":["../src/processor.decorator.ts"],"names":[],"mappings":";AAAA,0DAA0D;;AA2B1D,8BAuBC;AAhDD,gEAA4D;AAC5D,2CAKwB;AAmBxB,SAAgB,SAAS,CACvB,kBAA8C,EAC9C,kBAAsC;IAEtC,OAAO,CAAC,MAA2B,EAAE,EAAE;QACrC,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC;QACjD,IAAI,eAAe,EAAE,CAAC;YACpB,MAAM,CAAC,SAAS,CAAC,OAAO,GAAG,KAAK,WAAW,GAAQ;gBACjD,MAAM,GAAG,GAAG,IAAI,gCAAc,CAAC;oBAC7B,EAAE,EAAE,GAAG,CAAC,EAAE;oBACV,IAAI,EAAE,OAAO;iBACd,CAAC,CAAC;gBAEH,GAAG,CAAC,GAAG,CAAC,gBAAO,EAAE,GAAG,CAAC,CAAC;gBAEtB,OAAO,MAAM,gCAAc,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CACxC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAChC,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC;QAED,IAAA,kBAAa,EAAC,kBAAyB,EAAE,kBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"processor.decorator.js","sourceRoot":"","sources":["../src/processor.decorator.ts"],"names":[],"mappings":";AAAA,0DAA0D;;AAqD1D,8BAuBC;AA1ED,gEAA4D;AAC5D,2CAKwB;AA6CxB,SAAgB,SAAS,CACvB,kBAA8C,EAC9C,kBAAsC;IAEtC,OAAO,CAAC,MAA2B,EAAE,EAAE;QACrC,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC;QACjD,IAAI,eAAe,EAAE,CAAC;YACpB,MAAM,CAAC,SAAS,CAAC,OAAO,GAAG,KAAK,WAAW,GAAQ;gBACjD,MAAM,GAAG,GAAG,IAAI,gCAAc,CAAC;oBAC7B,EAAE,EAAE,GAAG,CAAC,EAAE;oBACV,IAAI,EAAE,OAAO;iBACd,CAAC,CAAC;gBAEH,GAAG,CAAC,GAAG,CAAC,gBAAO,EAAE,GAAG,CAAC,CAAC;gBAEtB,OAAO,MAAM,gCAAc,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CACxC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAChC,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC;QAED,IAAA,kBAAa,EAAC,kBAAyB,EAAE,kBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mockJobRef = Symbol("JOB_REF");
4
+ const mockBaseProcessorDecorator = jest.fn();
5
+ const mockBaseProcessor = jest.fn(() => mockBaseProcessorDecorator);
6
+ jest.mock("@nestjs/bullmq", () => ({
7
+ JOB_REF: mockJobRef,
8
+ Processor: mockBaseProcessor,
9
+ WorkerHost: class WorkerHost {
10
+ },
11
+ }));
12
+ const request_context_1 = require("@nest-boot/request-context");
13
+ const processor_decorator_1 = require("./processor.decorator");
14
+ describe("Processor", () => {
15
+ afterEach(() => {
16
+ jest.restoreAllMocks();
17
+ jest.clearAllMocks();
18
+ });
19
+ it("should wrap process in a queue request context and apply the base decorator", async () => {
20
+ const set = jest.spyOn(request_context_1.RequestContext.prototype, "set");
21
+ const run = jest
22
+ .spyOn(request_context_1.RequestContext, "run")
23
+ .mockImplementation(async (ctx, callback) => await callback(ctx));
24
+ const job = {
25
+ id: "job-1",
26
+ };
27
+ class EmailProcessor {
28
+ async process(input) {
29
+ await Promise.resolve();
30
+ return `processed:${input.id}`;
31
+ }
32
+ }
33
+ (0, processor_decorator_1.Processor)("email")(EmailProcessor);
34
+ await expect(new EmailProcessor().process(job)).resolves.toBe("processed:job-1");
35
+ expect(set).toHaveBeenCalledWith(mockJobRef, job);
36
+ expect(run).toHaveBeenCalledWith(expect.objectContaining({
37
+ id: "job-1",
38
+ type: "queue",
39
+ }), expect.any(Function));
40
+ expect(mockBaseProcessor).toHaveBeenCalledWith("email", undefined);
41
+ expect(mockBaseProcessorDecorator).toHaveBeenCalledWith(EmailProcessor);
42
+ });
43
+ it("should apply the base decorator when no process method exists", () => {
44
+ class EmptyProcessor {
45
+ }
46
+ const processorOptions = {
47
+ name: "email",
48
+ };
49
+ const workerOptions = {
50
+ concurrency: 2,
51
+ };
52
+ (0, processor_decorator_1.Processor)(processorOptions, workerOptions)(EmptyProcessor);
53
+ expect(mockBaseProcessor).toHaveBeenCalledWith(processorOptions, workerOptions);
54
+ expect(mockBaseProcessorDecorator).toHaveBeenCalledWith(EmptyProcessor);
55
+ });
56
+ });
57
+ //# sourceMappingURL=processor.decorator.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.decorator.spec.js","sourceRoot":"","sources":["../src/processor.decorator.spec.ts"],"names":[],"mappings":";;AAAA,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AACrC,MAAM,0BAA0B,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAC7C,MAAM,iBAAiB,GAAG,IAAI,CAAC,EAAE,CAAC,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