@nathapp/nestjs-queue 2.1.0 → 2.1.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/CLAUDE.md CHANGED
@@ -82,6 +82,22 @@ Multi-provider queue abstraction for NestJS (BullMQ, Kafka, RabbitMQ, Redis Pub/
82
82
  ## Quick Reference
83
83
 
84
84
  ```typescript
85
+ // Producer-only mode (no ProcessorExplorer, just QueueService)
86
+ // Sync
87
+ QueueModule.forProducer({
88
+ provider: QueueProviderType.BULLMQ,
89
+ options: { connection: { host: 'redis', port: 6379 } },
90
+ })
91
+
92
+ // Async
93
+ QueueModule.forProducerAsync({
94
+ useFactory: (config: ConfigService) => ({
95
+ provider: QueueProviderType.BULLMQ,
96
+ options: { connection: config.get('redis') },
97
+ }),
98
+ inject: [ConfigService],
99
+ })
100
+
85
101
  // Idempotency pattern (all providers)
86
102
  const canProcess = await store.markProcessing(job.id, lockTtl);
87
103
  if (!canProcess) return; // Skip duplicate
@@ -74,3 +74,11 @@ export interface QueueModuleOptions extends MultiInstanceOptions {
74
74
  export interface QueueModuleOptionsFactory {
75
75
  createQueueOptions(): Promise<QueueModuleOptions> | QueueModuleOptions;
76
76
  }
77
+ export interface QueueModuleAsyncOptions {
78
+ useFactory?: (...args: any[]) => Promise<QueueModuleOptions> | QueueModuleOptions;
79
+ useClass?: Type<QueueModuleOptionsFactory>;
80
+ useExisting?: Type<QueueModuleOptionsFactory>;
81
+ inject?: any[];
82
+ imports?: any[];
83
+ isGlobal?: boolean;
84
+ }
@@ -1,3 +1,8 @@
1
+ import { DynamicModule } from '@nestjs/common';
1
2
  import { ConfigurableModuleClass } from './queue.module-definition';
3
+ import { QueueModuleOptions, QueueModuleAsyncOptions } from '../interface/queue-options.interface';
2
4
  export declare class QueueModule extends ConfigurableModuleClass {
5
+ static forProducer(options: QueueModuleOptions): DynamicModule;
6
+ static forProducerAsync(options: QueueModuleAsyncOptions): DynamicModule;
7
+ private static createAsyncProviders;
3
8
  }
@@ -13,7 +13,71 @@ const queue_module_definition_1 = require("./queue.module-definition");
13
13
  const queue_provider_1 = require("./queue.provider");
14
14
  const queue_service_1 = require("../service/queue.service");
15
15
  const processor_explorer_1 = require("../explorer/processor.explorer");
16
+ class QueueProducerModule {
17
+ }
16
18
  let QueueModule = class QueueModule extends queue_module_definition_1.ConfigurableModuleClass {
19
+ static forProducer(options) {
20
+ return {
21
+ module: QueueProducerModule,
22
+ global: options.isGlobal,
23
+ providers: [
24
+ {
25
+ provide: queue_module_definition_1.MODULE_OPTIONS_TOKEN,
26
+ useValue: options,
27
+ },
28
+ (0, queue_provider_1.createQueueProvider)(),
29
+ queue_service_1.QueueService,
30
+ ],
31
+ exports: [queue_service_1.QueueService],
32
+ };
33
+ }
34
+ static forProducerAsync(options) {
35
+ return {
36
+ module: QueueProducerModule,
37
+ global: options.isGlobal,
38
+ imports: options.imports || [],
39
+ providers: [
40
+ ...this.createAsyncProviders(options),
41
+ (0, queue_provider_1.createQueueProvider)(),
42
+ queue_service_1.QueueService,
43
+ ],
44
+ exports: [queue_service_1.QueueService],
45
+ };
46
+ }
47
+ static createAsyncProviders(options) {
48
+ if (options.useFactory) {
49
+ return [
50
+ {
51
+ provide: queue_module_definition_1.MODULE_OPTIONS_TOKEN,
52
+ useFactory: options.useFactory,
53
+ inject: options.inject || [],
54
+ },
55
+ ];
56
+ }
57
+ if (options.useClass) {
58
+ return [
59
+ {
60
+ provide: queue_module_definition_1.MODULE_OPTIONS_TOKEN,
61
+ useFactory: async (optionsFactory) => await optionsFactory.createQueueOptions(),
62
+ inject: [options.useClass],
63
+ },
64
+ {
65
+ provide: options.useClass,
66
+ useClass: options.useClass,
67
+ },
68
+ ];
69
+ }
70
+ if (options.useExisting) {
71
+ return [
72
+ {
73
+ provide: queue_module_definition_1.MODULE_OPTIONS_TOKEN,
74
+ useFactory: async (optionsFactory) => await optionsFactory.createQueueOptions(),
75
+ inject: [options.useExisting],
76
+ },
77
+ ];
78
+ }
79
+ throw new Error('Invalid configuration. Must provide useFactory, useClass, or useExisting');
80
+ }
17
81
  };
18
82
  exports.QueueModule = QueueModule;
19
83
  exports.QueueModule = QueueModule = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"queue.module.js","sourceRoot":"","sources":["../../lib/module/queue.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uCAA+C;AAC/C,uEAAoE;AACpE,qDAAuD;AACvD,4DAAwD;AACxD,uEAAmE;AAO5D,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,iDAAuB;CAAG,CAAA;AAA9C,kCAAW;sBAAX,WAAW;IALvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAe,CAAC;QAC1B,SAAS,EAAE,CAAC,IAAA,oCAAmB,GAAE,EAAE,4BAAY,EAAE,sCAAiB,CAAC;QACnE,OAAO,EAAE,CAAC,4BAAY,EAAE,sCAAiB,CAAC;KAC3C,CAAC;GACW,WAAW,CAAmC"}
1
+ {"version":3,"file":"queue.module.js","sourceRoot":"","sources":["../../lib/module/queue.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAiE;AACjE,uCAA+C;AAC/C,uEAA0F;AAC1F,qDAAuD;AACvD,4DAAwD;AACxD,uEAAmE;AAWnE,MAAM,mBAAmB;CAAG;AAOrB,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,iDAAuB;IAStD,MAAM,CAAC,WAAW,CAAC,OAA2B;QAC5C,OAAO;YACL,MAAM,EAAE,mBAAmB;YAC3B,MAAM,EAAE,OAAO,CAAC,QAAQ;YACxB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,8CAAoB;oBAC7B,QAAQ,EAAE,OAAO;iBAClB;gBACD,IAAA,oCAAmB,GAAE;gBACrB,4BAAY;aACb;YACD,OAAO,EAAE,CAAC,4BAAY,CAAC;SACxB,CAAC;IACJ,CAAC;IASD,MAAM,CAAC,gBAAgB,CAAC,OAAgC;QACtD,OAAO;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;sBAAX,WAAW;IALvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAe,CAAC;QAC1B,SAAS,EAAE,CAAC,IAAA,oCAAmB,GAAE,EAAE,4BAAY,EAAE,sCAAiB,CAAC;QACnE,OAAO,EAAE,CAAC,4BAAY,EAAE,sCAAiB,CAAC;KAC3C,CAAC;GACW,WAAW,CA2FvB"}
@@ -0,0 +1,82 @@
1
+ # Implementation Plan: QueueModule.forProducer()
2
+
3
+ ## Overview
4
+ Add a lightweight producer-only registration mode to `QueueModule` that provides `QueueService` (for `add()`/`addBulk()`) without registering `ProcessorExplorer` or importing `DiscoveryModule`.
5
+
6
+ **Use case:** Service A (e.g. `account-api`) needs to enqueue jobs but has no processors. Service B (e.g. `notification-api`) uses full `QueueModule.register()` to consume those jobs.
7
+
8
+ ## Design
9
+
10
+ ### API Surface
11
+ ```typescript
12
+ // Sync
13
+ QueueModule.forProducer({
14
+ provider: QueueProviderType.BULLMQ,
15
+ options: { connection: { host: 'redis', port: 6379 } },
16
+ })
17
+
18
+ // Async
19
+ QueueModule.forProducerAsync({
20
+ useFactory: (config: ConfigService) => ({
21
+ provider: QueueProviderType.BULLMQ,
22
+ options: { connection: config.get('redis') },
23
+ }),
24
+ inject: [ConfigService],
25
+ })
26
+ ```
27
+
28
+ ### What forProducer registers
29
+ - `QUEUE_PROVIDER` (via `createQueueProvider()` factory)
30
+ - `MODULE_OPTIONS_TOKEN` (config token)
31
+ - `QueueService`
32
+
33
+ ### What forProducer does NOT register
34
+ - `ProcessorExplorer` (no decorator scanning)
35
+ - `DiscoveryModule` (not needed without explorer)
36
+
37
+ ## Tasks
38
+
39
+ ### Phase 1: Core Implementation
40
+
41
+ #### 1.1 Create `QueueProducerModule` or add static methods to `QueueModule`
42
+ **Decision: Add static methods to `QueueModule`** — keeps a single entry point, follows NestJS conventions (like `TypeOrmModule.forRoot()` vs `TypeOrmModule.forFeature()`).
43
+
44
+ **File: `lib/module/queue.module.ts`**
45
+ - Add `static forProducer(options: QueueModuleOptions): DynamicModule`
46
+ - Add `static forProducerAsync(options: QueueModuleAsyncOptions): DynamicModule`
47
+ - `forProducer` returns a `DynamicModule` with only the provider factory + QueueService
48
+ - `forProducerAsync` supports `useFactory`, `useClass`, `useExisting`, `inject`, `imports`
49
+
50
+ #### 1.2 Define `QueueModuleAsyncOptions` interface
51
+ **File: `lib/interface/queue-options.interface.ts`**
52
+ - Add `QueueModuleAsyncOptions` interface with:
53
+ - `useFactory?: (...args: any[]) => Promise<QueueModuleOptions> | QueueModuleOptions`
54
+ - `useClass?: Type<QueueModuleOptionsFactory>`
55
+ - `useExisting?: Type<QueueModuleOptionsFactory>`
56
+ - `inject?: any[]`
57
+ - `imports?: any[]`
58
+ - `isGlobal?: boolean`
59
+
60
+ ### Phase 2: Tests
61
+
62
+ #### 2.1 Unit tests for `forProducer()`
63
+ **File: `test/queue.module.spec.ts`** (add to existing)
64
+ - Test: `forProducer` registers `QueueService`
65
+ - Test: `forProducer` does NOT register `ProcessorExplorer`
66
+ - Test: `forProducerAsync` with `useFactory` registers `QueueService`
67
+ - Test: `forProducerAsync` does NOT register `ProcessorExplorer`
68
+ - Test: `QueueService.add()` works via `forProducer`
69
+ - Test: `isGlobal` option works with `forProducer`
70
+
71
+ ### Phase 3: Exports & Documentation
72
+
73
+ #### 3.1 Update barrel exports
74
+ **File: `lib/module/index.ts`** — ensure `QueueModuleAsyncOptions` is exported if it's a new interface
75
+
76
+ #### 3.2 Update CLAUDE.md
77
+ Add `forProducer()` usage to quick reference section.
78
+
79
+ ## Implementation Notes
80
+ - `ConfigurableModuleClass` (from `ConfigurableModuleBuilder`) gives us `register()` and `registerAsync()` for free. `forProducer()` and `forProducerAsync()` are **manually constructed** `DynamicModule` returns — they don't extend ConfigurableModuleClass.
81
+ - The `createQueueProvider()` factory already reads from `MODULE_OPTIONS_TOKEN`, so we reuse it.
82
+ - `QueueService` constructor has `@Optional()` on `moduleOptions`, so it works fine with or without the full module.
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-queue",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "NestJS Queue Module with multi-provider support (BullMQ, Kafka, RabbitMQ, Redis Pub/Sub)",
5
- "main": "index.js",
6
- "types": "index.d.ts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "clean": "rimraf dist/ .turbo/",
9
9
  "build": "rimraf dist && tsc -p tsconfig.json",
@@ -23,7 +23,7 @@
23
23
  "uuid": "^9.0.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "@nathapp/nestjs-common": "^2.1.0",
26
+ "@nathapp/nestjs-common": "^2.1.1",
27
27
  "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
28
28
  "@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
29
29
  "bullmq": "^5.0.0",
@@ -50,7 +50,7 @@
50
50
  }
51
51
  },
52
52
  "devDependencies": {
53
- "@nathapp/nestjs-common": "^2.1.0",
53
+ "@nathapp/nestjs-common": "^2.1.1",
54
54
  "@nestjs/testing": "^11.0.0",
55
55
  "@types/amqplib": "^0.10.0",
56
56
  "@types/jest": "^29.5.2",