@amqp-contract/worker-nestjs 0.2.0 → 0.2.1

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
@@ -1,6 +1,14 @@
1
1
  # @amqp-contract/worker-nestjs
2
2
 
3
- NestJS integration for [@amqp-contract/worker](../worker). Type-safe AMQP message consumption with automatic lifecycle management.
3
+ **NestJS integration for [@amqp-contract/worker](../worker). Type-safe AMQP message consumption with automatic lifecycle management.**
4
+
5
+ [![CI](https://github.com/btravers/amqp-contract/actions/workflows/ci.yml/badge.svg)](https://github.com/btravers/amqp-contract/actions/workflows/ci.yml)
6
+ [![npm version](https://img.shields.io/npm/v/@amqp-contract/worker-nestjs.svg?logo=npm)](https://www.npmjs.com/package/@amqp-contract/worker-nestjs)
7
+ [![npm downloads](https://img.shields.io/npm/dm/@amqp-contract/worker-nestjs.svg)](https://www.npmjs.com/package/@amqp-contract/worker-nestjs)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue?logo=typescript)](https://www.typescriptlang.org/)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
+
11
+ 📖 **[Full documentation →](https://btravers.github.io/amqp-contract/guide/worker-nestjs-usage)**
4
12
 
5
13
  ## Installation
6
14
 
@@ -33,6 +41,10 @@ export class AppModule {}
33
41
 
34
42
  The worker automatically starts consuming messages when the module initializes and cleans up on shutdown.
35
43
 
44
+ ## Documentation
45
+
46
+ 📖 **[Read the full documentation →](https://btravers.github.io/amqp-contract)**
47
+
36
48
  ## License
37
49
 
38
50
  MIT
package/dist/index.cjs CHANGED
@@ -39,21 +39,28 @@ let AmqpWorkerService = class AmqpWorkerService$1 {
39
39
  this.options = options;
40
40
  }
41
41
  /**
42
- * Initialize the worker when the NestJS module starts
42
+ * Initialize the AMQP worker when the NestJS module starts.
43
+ *
44
+ * This lifecycle hook automatically creates and starts the worker,
45
+ * beginning message consumption from all configured consumers.
46
+ * The connection will be established in the background with
47
+ * automatic reconnection handling.
48
+ *
49
+ * @throws Error if the worker fails to start
43
50
  */
44
51
  async onModuleInit() {
45
- this.worker = await _amqp_contract_worker.TypedAmqpWorker.create({
46
- contract: this.options.contract,
47
- handlers: this.options.handlers,
48
- connection: this.options.connection
49
- });
52
+ this.worker = await _amqp_contract_worker.TypedAmqpWorker.create(this.options).resultToPromise();
50
53
  }
51
54
  /**
52
- * Close the worker when the NestJS module is destroyed
55
+ * Close the AMQP worker when the NestJS module is destroyed.
56
+ *
57
+ * This lifecycle hook ensures proper cleanup of resources when the
58
+ * NestJS application shuts down, gracefully stopping message consumption
59
+ * and closing the connection.
53
60
  */
54
61
  async onModuleDestroy() {
55
62
  if (this.worker) {
56
- await this.worker.close();
63
+ await this.worker.close().resultToPromise();
57
64
  this.worker = null;
58
65
  }
59
66
  }
package/dist/index.d.cts CHANGED
@@ -1,31 +1,97 @@
1
1
  import * as _nestjs_common0 from "@nestjs/common";
2
2
  import { OnModuleDestroy, OnModuleInit } from "@nestjs/common";
3
- import { Options } from "amqplib";
4
- import { ContractDefinition, WorkerInferConsumerHandlers } from "@amqp-contract/contract";
3
+ import { ContractDefinition } from "@amqp-contract/contract";
4
+ import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
5
+ import { WorkerInferConsumerHandlers } from "@amqp-contract/worker";
5
6
 
6
7
  //#region src/worker.service.d.ts
8
+
7
9
  /**
8
- * Options for creating a NestJS worker service
10
+ * Configuration options for the AMQP worker NestJS module.
11
+ *
12
+ * @typeParam TContract - The contract definition type
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const options: AmqpWorkerModuleOptions<typeof contract> = {
17
+ * contract: myContract,
18
+ * handlers: {
19
+ * processOrder: async (message) => {
20
+ * console.log('Processing order:', message.orderId);
21
+ * }
22
+ * },
23
+ * urls: ['amqp://localhost'],
24
+ * connectionOptions: {
25
+ * heartbeatIntervalInSeconds: 30
26
+ * }
27
+ * };
28
+ * ```
9
29
  */
10
30
  interface AmqpWorkerModuleOptions<TContract extends ContractDefinition> {
31
+ /** The AMQP contract definition specifying consumers and their message schemas */
11
32
  contract: TContract;
33
+ /** Message handlers for each consumer defined in the contract */
12
34
  handlers: WorkerInferConsumerHandlers<TContract>;
13
- connection: string | Options.Connect;
35
+ /** AMQP broker URL(s). Multiple URLs provide failover support */
36
+ urls: ConnectionUrl[];
37
+ /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
38
+ connectionOptions?: AmqpConnectionManagerOptions | undefined;
14
39
  }
15
40
  /**
16
- * Type-safe AMQP worker service for NestJS
17
- * This service integrates @amqp-contract/worker with NestJS lifecycle
41
+ * Type-safe AMQP worker service for NestJS applications.
42
+ *
43
+ * This service wraps {@link TypedAmqpWorker} and integrates it with the NestJS
44
+ * lifecycle, automatically starting message consumption on module init and
45
+ * cleaning up resources on module destroy.
46
+ *
47
+ * @typeParam TContract - The contract definition type
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // In your module
52
+ * import { AmqpWorkerModule } from '@amqp-contract/worker-nestjs';
53
+ *
54
+ * @Module({
55
+ * imports: [
56
+ * AmqpWorkerModule.forRoot({
57
+ * contract: myContract,
58
+ * handlers: {
59
+ * processOrder: async (message) => {
60
+ * console.log('Received order:', message.orderId);
61
+ * // Process the order...
62
+ * }
63
+ * },
64
+ * urls: ['amqp://localhost']
65
+ * })
66
+ * ]
67
+ * })
68
+ * export class AppModule {}
69
+ *
70
+ * // The worker automatically starts consuming messages when the module initializes
71
+ * // and stops gracefully when the application shuts down
72
+ * ```
18
73
  */
19
74
  declare class AmqpWorkerService<TContract extends ContractDefinition> implements OnModuleInit, OnModuleDestroy {
20
75
  private readonly options;
21
76
  private worker;
22
77
  constructor(options: AmqpWorkerModuleOptions<TContract>);
23
78
  /**
24
- * Initialize the worker when the NestJS module starts
79
+ * Initialize the AMQP worker when the NestJS module starts.
80
+ *
81
+ * This lifecycle hook automatically creates and starts the worker,
82
+ * beginning message consumption from all configured consumers.
83
+ * The connection will be established in the background with
84
+ * automatic reconnection handling.
85
+ *
86
+ * @throws Error if the worker fails to start
25
87
  */
26
88
  onModuleInit(): Promise<void>;
27
89
  /**
28
- * Close the worker when the NestJS module is destroyed
90
+ * Close the AMQP worker when the NestJS module is destroyed.
91
+ *
92
+ * This lifecycle hook ensures proper cleanup of resources when the
93
+ * NestJS application shuts down, gracefully stopping message consumption
94
+ * and closing the connection.
29
95
  */
30
96
  onModuleDestroy(): Promise<void>;
31
97
  }
@@ -35,7 +101,7 @@ declare class AmqpWorkerService<TContract extends ContractDefinition> implements
35
101
  * ConfigurableModuleBuilder for AMQP worker module
36
102
  * This creates forRoot and forRootAsync methods automatically
37
103
  */
38
- declare const ConfigurableModuleClass: _nestjs_common0.ConfigurableModuleCls<AmqpWorkerModuleOptions<never>, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
104
+ declare const ConfigurableModuleClass: _nestjs_common0.ConfigurableModuleCls<AmqpWorkerModuleOptions<ContractDefinition>, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
39
105
  //#endregion
40
106
  //#region src/worker.module.d.ts
41
107
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/worker.service.ts","../src/worker.module-definition.ts","../src/worker.module.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AASiB,UAAA,uBAAuB,CAAA,kBAAmB,kBAAnB,CAAA,CAAA;EAAmB,QAAA,EAC/C,SAD+C;EAC/C,QAAA,EACA,2BADA,CAC4B,SAD5B,CAAA;EAC4B,UAAA,EAAA,MAAA,GACjB,OAAA,CAAQ,OADS;;;;AAQxC;;AAQsD,cAPzC,iBAOyC,CAAA,kBAPL,kBAOK,CAAA,YANzC,YAMyC,EAN3B,eAM2B,CAAA;EAAxB,iBAAA,OAAA;EAMN,QAAA,MAAA;EAWG,WAAA,CAAA,OAAA,EAjBG,uBAiBH,CAjB2B,SAiB3B,CAAA;EAvBd;;;kBAYW;;;AC1BxB;EAAwC,eAAA,CAAA,CAAA,EDqCb,OCrCa,CAAA,IAAA,CAAA;;;;;;;;cAAzB,yBAAuB,eAAA,CAAA,sBAAA;;;;;;;;ADErB,cEIJ,gBAAA,SAAyB,uBAAA,CFJE"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/worker.service.ts","../src/worker.module-definition.ts","../src/worker.module.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AA2BA;;;;;;;;AA6CA;;;;;;;;;;UA7CiB,0CAA0C;;ECnB5C,QAAA,EDqBH,SCrBG;EAAuB;EAAA,QAAA,EDuB1B,2BCvB0B,CDuBE,SCvBF,CAAA;EAAA;EAAA,IAAA,EDyB9B,aCzB8B,EAAA;EAAE;sBD2BlB;;;AE1BtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cFgEa,oCAAoC,+BACpC,cAAc;;;uBAMG,wBAAwB;;;;;;;;;;;kBAa9B;;;;;;;;qBAWG;;;;;;;;cChGZ,yBAAuB,eAAA,CAAA,sBAAA,wBAAA;;;;;;;;cCKzB,gBAAA,SAAyB,uBAAA"}
package/dist/index.d.mts CHANGED
@@ -1,31 +1,97 @@
1
1
  import * as _nestjs_common0 from "@nestjs/common";
2
2
  import { OnModuleDestroy, OnModuleInit } from "@nestjs/common";
3
- import { Options } from "amqplib";
4
- import { ContractDefinition, WorkerInferConsumerHandlers } from "@amqp-contract/contract";
3
+ import { WorkerInferConsumerHandlers } from "@amqp-contract/worker";
4
+ import { ContractDefinition } from "@amqp-contract/contract";
5
+ import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
5
6
 
6
7
  //#region src/worker.service.d.ts
8
+
7
9
  /**
8
- * Options for creating a NestJS worker service
10
+ * Configuration options for the AMQP worker NestJS module.
11
+ *
12
+ * @typeParam TContract - The contract definition type
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const options: AmqpWorkerModuleOptions<typeof contract> = {
17
+ * contract: myContract,
18
+ * handlers: {
19
+ * processOrder: async (message) => {
20
+ * console.log('Processing order:', message.orderId);
21
+ * }
22
+ * },
23
+ * urls: ['amqp://localhost'],
24
+ * connectionOptions: {
25
+ * heartbeatIntervalInSeconds: 30
26
+ * }
27
+ * };
28
+ * ```
9
29
  */
10
30
  interface AmqpWorkerModuleOptions<TContract extends ContractDefinition> {
31
+ /** The AMQP contract definition specifying consumers and their message schemas */
11
32
  contract: TContract;
33
+ /** Message handlers for each consumer defined in the contract */
12
34
  handlers: WorkerInferConsumerHandlers<TContract>;
13
- connection: string | Options.Connect;
35
+ /** AMQP broker URL(s). Multiple URLs provide failover support */
36
+ urls: ConnectionUrl[];
37
+ /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
38
+ connectionOptions?: AmqpConnectionManagerOptions | undefined;
14
39
  }
15
40
  /**
16
- * Type-safe AMQP worker service for NestJS
17
- * This service integrates @amqp-contract/worker with NestJS lifecycle
41
+ * Type-safe AMQP worker service for NestJS applications.
42
+ *
43
+ * This service wraps {@link TypedAmqpWorker} and integrates it with the NestJS
44
+ * lifecycle, automatically starting message consumption on module init and
45
+ * cleaning up resources on module destroy.
46
+ *
47
+ * @typeParam TContract - The contract definition type
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // In your module
52
+ * import { AmqpWorkerModule } from '@amqp-contract/worker-nestjs';
53
+ *
54
+ * @Module({
55
+ * imports: [
56
+ * AmqpWorkerModule.forRoot({
57
+ * contract: myContract,
58
+ * handlers: {
59
+ * processOrder: async (message) => {
60
+ * console.log('Received order:', message.orderId);
61
+ * // Process the order...
62
+ * }
63
+ * },
64
+ * urls: ['amqp://localhost']
65
+ * })
66
+ * ]
67
+ * })
68
+ * export class AppModule {}
69
+ *
70
+ * // The worker automatically starts consuming messages when the module initializes
71
+ * // and stops gracefully when the application shuts down
72
+ * ```
18
73
  */
19
74
  declare class AmqpWorkerService<TContract extends ContractDefinition> implements OnModuleInit, OnModuleDestroy {
20
75
  private readonly options;
21
76
  private worker;
22
77
  constructor(options: AmqpWorkerModuleOptions<TContract>);
23
78
  /**
24
- * Initialize the worker when the NestJS module starts
79
+ * Initialize the AMQP worker when the NestJS module starts.
80
+ *
81
+ * This lifecycle hook automatically creates and starts the worker,
82
+ * beginning message consumption from all configured consumers.
83
+ * The connection will be established in the background with
84
+ * automatic reconnection handling.
85
+ *
86
+ * @throws Error if the worker fails to start
25
87
  */
26
88
  onModuleInit(): Promise<void>;
27
89
  /**
28
- * Close the worker when the NestJS module is destroyed
90
+ * Close the AMQP worker when the NestJS module is destroyed.
91
+ *
92
+ * This lifecycle hook ensures proper cleanup of resources when the
93
+ * NestJS application shuts down, gracefully stopping message consumption
94
+ * and closing the connection.
29
95
  */
30
96
  onModuleDestroy(): Promise<void>;
31
97
  }
@@ -35,7 +101,7 @@ declare class AmqpWorkerService<TContract extends ContractDefinition> implements
35
101
  * ConfigurableModuleBuilder for AMQP worker module
36
102
  * This creates forRoot and forRootAsync methods automatically
37
103
  */
38
- declare const ConfigurableModuleClass: _nestjs_common0.ConfigurableModuleCls<AmqpWorkerModuleOptions<never>, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
104
+ declare const ConfigurableModuleClass: _nestjs_common0.ConfigurableModuleCls<AmqpWorkerModuleOptions<ContractDefinition>, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
39
105
  //#endregion
40
106
  //#region src/worker.module.d.ts
41
107
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/worker.service.ts","../src/worker.module-definition.ts","../src/worker.module.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AASiB,UAAA,uBAAuB,CAAA,kBAAmB,kBAAnB,CAAA,CAAA;EAAmB,QAAA,EAC/C,SAD+C;EAC/C,QAAA,EACA,2BADA,CAC4B,SAD5B,CAAA;EAC4B,UAAA,EAAA,MAAA,GACjB,OAAA,CAAQ,OADS;;;;AAQxC;;AAQsD,cAPzC,iBAOyC,CAAA,kBAPL,kBAOK,CAAA,YANzC,YAMyC,EAN3B,eAM2B,CAAA;EAAxB,iBAAA,OAAA;EAMN,QAAA,MAAA;EAWG,WAAA,CAAA,OAAA,EAjBG,uBAiBH,CAjB2B,SAiB3B,CAAA;EAvBd;;;kBAYW;;;AC1BxB;EAAwC,eAAA,CAAA,CAAA,EDqCb,OCrCa,CAAA,IAAA,CAAA;;;;;;;;cAAzB,yBAAuB,eAAA,CAAA,sBAAA;;;;;;;;ADErB,cEIJ,gBAAA,SAAyB,uBAAA,CFJE"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/worker.service.ts","../src/worker.module-definition.ts","../src/worker.module.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AA2BA;;;;;;;;AA6CA;;;;;;;;;;UA7CiB,0CAA0C;;ECnB5C,QAAA,EDqBH,SCrBG;EAAuB;EAAA,QAAA,EDuB1B,2BCvB0B,CDuBE,SCvBF,CAAA;EAAA;EAAA,IAAA,EDyB9B,aCzB8B,EAAA;EAAE;sBD2BlB;;;AE1BtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cFgEa,oCAAoC,+BACpC,cAAc;;;uBAMG,wBAAwB;;;;;;;;;;;kBAa9B;;;;;;;;qBAWG;;;;;;;;cChGZ,yBAAuB,eAAA,CAAA,sBAAA,wBAAA;;;;;;;;cCKzB,gBAAA,SAAyB,uBAAA"}
package/dist/index.mjs CHANGED
@@ -39,21 +39,28 @@ let AmqpWorkerService = class AmqpWorkerService$1 {
39
39
  this.options = options;
40
40
  }
41
41
  /**
42
- * Initialize the worker when the NestJS module starts
42
+ * Initialize the AMQP worker when the NestJS module starts.
43
+ *
44
+ * This lifecycle hook automatically creates and starts the worker,
45
+ * beginning message consumption from all configured consumers.
46
+ * The connection will be established in the background with
47
+ * automatic reconnection handling.
48
+ *
49
+ * @throws Error if the worker fails to start
43
50
  */
44
51
  async onModuleInit() {
45
- this.worker = await TypedAmqpWorker.create({
46
- contract: this.options.contract,
47
- handlers: this.options.handlers,
48
- connection: this.options.connection
49
- });
52
+ this.worker = await TypedAmqpWorker.create(this.options).resultToPromise();
50
53
  }
51
54
  /**
52
- * Close the worker when the NestJS module is destroyed
55
+ * Close the AMQP worker when the NestJS module is destroyed.
56
+ *
57
+ * This lifecycle hook ensures proper cleanup of resources when the
58
+ * NestJS application shuts down, gracefully stopping message consumption
59
+ * and closing the connection.
53
60
  */
54
61
  async onModuleDestroy() {
55
62
  if (this.worker) {
56
- await this.worker.close();
63
+ await this.worker.close().resultToPromise();
57
64
  this.worker = null;
58
65
  }
59
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["AmqpWorkerService","options: AmqpWorkerModuleOptions<TContract>","AmqpWorkerModule"],"sources":["../src/worker.module-definition.ts","../src/worker.service.ts","../src/worker.module.ts"],"sourcesContent":["import { ConfigurableModuleBuilder } from \"@nestjs/common\";\nimport type { AmqpWorkerModuleOptions } from \"./worker.service.js\";\n\n/**\n * ConfigurableModuleBuilder for AMQP worker module\n * This creates forRoot and forRootAsync methods automatically\n */\nexport const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder<\n AmqpWorkerModuleOptions<never>\n>()\n .setClassMethodName(\"forRoot\")\n .build();\n","import { Inject, Injectable, type OnModuleDestroy, type OnModuleInit } from \"@nestjs/common\";\nimport type { Options } from \"amqplib\";\nimport type { ContractDefinition, WorkerInferConsumerHandlers } from \"@amqp-contract/contract\";\nimport { TypedAmqpWorker } from \"@amqp-contract/worker\";\nimport { MODULE_OPTIONS_TOKEN } from \"./worker.module-definition.js\";\n\n/**\n * Options for creating a NestJS worker service\n */\nexport interface AmqpWorkerModuleOptions<TContract extends ContractDefinition> {\n contract: TContract;\n handlers: WorkerInferConsumerHandlers<TContract>;\n connection: string | Options.Connect;\n}\n\n/**\n * Type-safe AMQP worker service for NestJS\n * This service integrates @amqp-contract/worker with NestJS lifecycle\n */\n@Injectable()\nexport class AmqpWorkerService<TContract extends ContractDefinition>\n implements OnModuleInit, OnModuleDestroy\n{\n private worker: TypedAmqpWorker<TContract> | null = null;\n\n constructor(\n @Inject(MODULE_OPTIONS_TOKEN)\n private readonly options: AmqpWorkerModuleOptions<TContract>,\n ) {}\n\n /**\n * Initialize the worker when the NestJS module starts\n */\n async onModuleInit(): Promise<void> {\n this.worker = await TypedAmqpWorker.create({\n contract: this.options.contract,\n handlers: this.options.handlers,\n connection: this.options.connection,\n });\n }\n\n /**\n * Close the worker when the NestJS module is destroyed\n */\n async onModuleDestroy(): Promise<void> {\n if (this.worker) {\n await this.worker.close();\n this.worker = null;\n }\n }\n}\n","import { Module } from \"@nestjs/common\";\nimport { ConfigurableModuleClass } from \"./worker.module-definition.js\";\nimport { AmqpWorkerService } from \"./worker.service.js\";\n\n/**\n * NestJS module for AMQP worker integration\n * This module provides type-safe AMQP worker functionality using @amqp-contract/worker\n * without relying on NestJS decorators (except for dependency injection)\n */\n@Module({\n providers: [AmqpWorkerService],\n exports: [AmqpWorkerService],\n})\nexport class AmqpWorkerModule extends ConfigurableModuleClass {}\n"],"mappings":";;;;;;;;AAOA,MAAa,EAAE,yBAAyB,yBAAyB,IAAI,2BAElE,CACA,mBAAmB,UAAU,CAC7B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;ACSH,8BAAMA,oBAEb;CACE,AAAQ,SAA4C;CAEpD,YACE,AACiBC,SACjB;EADiB;;;;;CAMnB,MAAM,eAA8B;AAClC,OAAK,SAAS,MAAM,gBAAgB,OAAO;GACzC,UAAU,KAAK,QAAQ;GACvB,UAAU,KAAK,QAAQ;GACvB,YAAY,KAAK,QAAQ;GAC1B,CAAC;;;;;CAMJ,MAAM,kBAAiC;AACrC,MAAI,KAAK,QAAQ;AACf,SAAM,KAAK,OAAO,OAAO;AACzB,QAAK,SAAS;;;;;CA5BnB,YAAY;oBAOR,OAAO,qBAAqB;;;;;;ACb1B,6BAAMC,2BAAyB,wBAAwB;+BAJ7D,OAAO;CACN,WAAW,CAAC,kBAAkB;CAC9B,SAAS,CAAC,kBAAkB;CAC7B,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":["AmqpWorkerService","options: AmqpWorkerModuleOptions<TContract>","AmqpWorkerModule"],"sources":["../src/worker.module-definition.ts","../src/worker.service.ts","../src/worker.module.ts"],"sourcesContent":["import { ConfigurableModuleBuilder } from \"@nestjs/common\";\nimport type { ContractDefinition } from \"@amqp-contract/contract\";\nimport type { AmqpWorkerModuleOptions } from \"./worker.service.js\";\n\n/**\n * ConfigurableModuleBuilder for AMQP worker module\n * This creates forRoot and forRootAsync methods automatically\n */\nexport const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder<\n AmqpWorkerModuleOptions<ContractDefinition>\n>()\n .setClassMethodName(\"forRoot\")\n .build();\n","import { Inject, Injectable, type OnModuleDestroy, type OnModuleInit } from \"@nestjs/common\";\nimport type { ContractDefinition } from \"@amqp-contract/contract\";\nimport type { AmqpConnectionManagerOptions, ConnectionUrl } from \"amqp-connection-manager\";\nimport { TypedAmqpWorker, type WorkerInferConsumerHandlers } from \"@amqp-contract/worker\";\nimport { MODULE_OPTIONS_TOKEN } from \"./worker.module-definition.js\";\n\n/**\n * Configuration options for the AMQP worker NestJS module.\n *\n * @typeParam TContract - The contract definition type\n *\n * @example\n * ```typescript\n * const options: AmqpWorkerModuleOptions<typeof contract> = {\n * contract: myContract,\n * handlers: {\n * processOrder: async (message) => {\n * console.log('Processing order:', message.orderId);\n * }\n * },\n * urls: ['amqp://localhost'],\n * connectionOptions: {\n * heartbeatIntervalInSeconds: 30\n * }\n * };\n * ```\n */\nexport interface AmqpWorkerModuleOptions<TContract extends ContractDefinition> {\n /** The AMQP contract definition specifying consumers and their message schemas */\n contract: TContract;\n /** Message handlers for each consumer defined in the contract */\n handlers: WorkerInferConsumerHandlers<TContract>;\n /** AMQP broker URL(s). Multiple URLs provide failover support */\n urls: ConnectionUrl[];\n /** Optional connection configuration (heartbeat, reconnect settings, etc.) */\n connectionOptions?: AmqpConnectionManagerOptions | undefined;\n}\n\n/**\n * Type-safe AMQP worker service for NestJS applications.\n *\n * This service wraps {@link TypedAmqpWorker} and integrates it with the NestJS\n * lifecycle, automatically starting message consumption on module init and\n * cleaning up resources on module destroy.\n *\n * @typeParam TContract - The contract definition type\n *\n * @example\n * ```typescript\n * // In your module\n * import { AmqpWorkerModule } from '@amqp-contract/worker-nestjs';\n *\n * @Module({\n * imports: [\n * AmqpWorkerModule.forRoot({\n * contract: myContract,\n * handlers: {\n * processOrder: async (message) => {\n * console.log('Received order:', message.orderId);\n * // Process the order...\n * }\n * },\n * urls: ['amqp://localhost']\n * })\n * ]\n * })\n * export class AppModule {}\n *\n * // The worker automatically starts consuming messages when the module initializes\n * // and stops gracefully when the application shuts down\n * ```\n */\n@Injectable()\nexport class AmqpWorkerService<TContract extends ContractDefinition>\n implements OnModuleInit, OnModuleDestroy\n{\n private worker: TypedAmqpWorker<TContract> | null = null;\n\n constructor(\n @Inject(MODULE_OPTIONS_TOKEN)\n private readonly options: AmqpWorkerModuleOptions<TContract>,\n ) {}\n\n /**\n * Initialize the AMQP worker when the NestJS module starts.\n *\n * This lifecycle hook automatically creates and starts the worker,\n * beginning message consumption from all configured consumers.\n * The connection will be established in the background with\n * automatic reconnection handling.\n *\n * @throws Error if the worker fails to start\n */\n async onModuleInit(): Promise<void> {\n this.worker = await TypedAmqpWorker.create(this.options).resultToPromise();\n }\n\n /**\n * Close the AMQP worker when the NestJS module is destroyed.\n *\n * This lifecycle hook ensures proper cleanup of resources when the\n * NestJS application shuts down, gracefully stopping message consumption\n * and closing the connection.\n */\n async onModuleDestroy(): Promise<void> {\n if (this.worker) {\n await this.worker.close().resultToPromise();\n this.worker = null;\n }\n }\n}\n","import { Module } from \"@nestjs/common\";\nimport { ConfigurableModuleClass } from \"./worker.module-definition.js\";\nimport { AmqpWorkerService } from \"./worker.service.js\";\n\n/**\n * NestJS module for AMQP worker integration\n * This module provides type-safe AMQP worker functionality using @amqp-contract/worker\n * without relying on NestJS decorators (except for dependency injection)\n */\n@Module({\n providers: [AmqpWorkerService],\n exports: [AmqpWorkerService],\n})\nexport class AmqpWorkerModule extends ConfigurableModuleClass {}\n"],"mappings":";;;;;;;;AAQA,MAAa,EAAE,yBAAyB,yBAAyB,IAAI,2BAElE,CACA,mBAAmB,UAAU,CAC7B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;AC6DH,8BAAMA,oBAEb;CACE,AAAQ,SAA4C;CAEpD,YACE,AACiBC,SACjB;EADiB;;;;;;;;;;;;CAanB,MAAM,eAA8B;AAClC,OAAK,SAAS,MAAM,gBAAgB,OAAO,KAAK,QAAQ,CAAC,iBAAiB;;;;;;;;;CAU5E,MAAM,kBAAiC;AACrC,MAAI,KAAK,QAAQ;AACf,SAAM,KAAK,OAAO,OAAO,CAAC,iBAAiB;AAC3C,QAAK,SAAS;;;;;CAnCnB,YAAY;oBAOR,OAAO,qBAAqB;;;;;;AClE1B,6BAAMC,2BAAyB,wBAAwB;+BAJ7D,OAAO;CACN,WAAW,CAAC,kBAAkB;CAC9B,SAAS,CAAC,kBAAkB;CAC7B,CAAC"}
package/docs/index.md ADDED
@@ -0,0 +1,226 @@
1
+ **@amqp-contract/worker-nestjs**
2
+
3
+ ***
4
+
5
+ # @amqp-contract/worker-nestjs
6
+
7
+ ## Classes
8
+
9
+ ### AmqpWorkerModule
10
+
11
+ Defined in: [packages/worker-nestjs/src/worker.module.ts:14](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.module.ts#L14)
12
+
13
+ NestJS module for AMQP worker integration
14
+ This module provides type-safe AMQP worker functionality using @amqp-contract/worker
15
+ without relying on NestJS decorators (except for dependency injection)
16
+
17
+ #### Extends
18
+
19
+ - `ConfigurableModuleClass`
20
+
21
+ #### Indexable
22
+
23
+ ```ts
24
+ [key: string]: any
25
+ ```
26
+
27
+ #### Constructors
28
+
29
+ ##### Constructor
30
+
31
+ ```ts
32
+ new AmqpWorkerModule(): AmqpWorkerModule;
33
+ ```
34
+
35
+ Defined in: node\_modules/.pnpm/@nestjs+common@11.1.10\_reflect-metadata@0.2.2\_rxjs@7.8.2/node\_modules/@nestjs/common/module-utils/interfaces/configurable-module-cls.interface.d.ts:12
36
+
37
+ ###### Returns
38
+
39
+ [`AmqpWorkerModule`](#amqpworkermodule)
40
+
41
+ ###### Inherited from
42
+
43
+ ```ts
44
+ ConfigurableModuleClass.constructor
45
+ ```
46
+
47
+ #### Properties
48
+
49
+ | Property | Modifier | Type | Inherited from | Defined in |
50
+ | ------ | ------ | ------ | ------ | ------ |
51
+ | <a id="forroot"></a> `forRoot` | `static` | (`options`) => `DynamicModule` | `ConfigurableModuleClass.forRoot` | |
52
+ | <a id="forrootasync"></a> `forRootAsync` | `static` | (`options`) => `DynamicModule` | `ConfigurableModuleClass.forRootAsync` | |
53
+
54
+ ***
55
+
56
+ ### AmqpWorkerService
57
+
58
+ Defined in: [packages/worker-nestjs/src/worker.service.ts:74](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L74)
59
+
60
+ Type-safe AMQP worker service for NestJS applications.
61
+
62
+ This service wraps TypedAmqpWorker and integrates it with the NestJS
63
+ lifecycle, automatically starting message consumption on module init and
64
+ cleaning up resources on module destroy.
65
+
66
+ #### Example
67
+
68
+ ```typescript
69
+ // In your module
70
+ import { AmqpWorkerModule } from '@amqp-contract/worker-nestjs';
71
+
72
+ @Module({
73
+ imports: [
74
+ AmqpWorkerModule.forRoot({
75
+ contract: myContract,
76
+ handlers: {
77
+ processOrder: async (message) => {
78
+ console.log('Received order:', message.orderId);
79
+ // Process the order...
80
+ }
81
+ },
82
+ urls: ['amqp://localhost']
83
+ })
84
+ ]
85
+ })
86
+ export class AppModule {}
87
+
88
+ // The worker automatically starts consuming messages when the module initializes
89
+ // and stops gracefully when the application shuts down
90
+ ```
91
+
92
+ #### Type Parameters
93
+
94
+ | Type Parameter | Description |
95
+ | ------ | ------ |
96
+ | `TContract` *extends* `ContractDefinition` | The contract definition type |
97
+
98
+ #### Implements
99
+
100
+ - `OnModuleInit`
101
+ - `OnModuleDestroy`
102
+
103
+ #### Constructors
104
+
105
+ ##### Constructor
106
+
107
+ ```ts
108
+ new AmqpWorkerService<TContract>(options): AmqpWorkerService<TContract>;
109
+ ```
110
+
111
+ Defined in: [packages/worker-nestjs/src/worker.service.ts:79](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L79)
112
+
113
+ ###### Parameters
114
+
115
+ | Parameter | Type |
116
+ | ------ | ------ |
117
+ | `options` | [`AmqpWorkerModuleOptions`](#amqpworkermoduleoptions)\<`TContract`\> |
118
+
119
+ ###### Returns
120
+
121
+ [`AmqpWorkerService`](#amqpworkerservice)\<`TContract`\>
122
+
123
+ #### Methods
124
+
125
+ ##### onModuleDestroy()
126
+
127
+ ```ts
128
+ onModuleDestroy(): Promise<void>;
129
+ ```
130
+
131
+ Defined in: [packages/worker-nestjs/src/worker.service.ts:105](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L105)
132
+
133
+ Close the AMQP worker when the NestJS module is destroyed.
134
+
135
+ This lifecycle hook ensures proper cleanup of resources when the
136
+ NestJS application shuts down, gracefully stopping message consumption
137
+ and closing the connection.
138
+
139
+ ###### Returns
140
+
141
+ `Promise`\<`void`\>
142
+
143
+ ###### Implementation of
144
+
145
+ ```ts
146
+ OnModuleDestroy.onModuleDestroy
147
+ ```
148
+
149
+ ##### onModuleInit()
150
+
151
+ ```ts
152
+ onModuleInit(): Promise<void>;
153
+ ```
154
+
155
+ Defined in: [packages/worker-nestjs/src/worker.service.ts:94](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L94)
156
+
157
+ Initialize the AMQP worker when the NestJS module starts.
158
+
159
+ This lifecycle hook automatically creates and starts the worker,
160
+ beginning message consumption from all configured consumers.
161
+ The connection will be established in the background with
162
+ automatic reconnection handling.
163
+
164
+ ###### Returns
165
+
166
+ `Promise`\<`void`\>
167
+
168
+ ###### Throws
169
+
170
+ Error if the worker fails to start
171
+
172
+ ###### Implementation of
173
+
174
+ ```ts
175
+ OnModuleInit.onModuleInit
176
+ ```
177
+
178
+ ## Interfaces
179
+
180
+ ### AmqpWorkerModuleOptions
181
+
182
+ Defined in: [packages/worker-nestjs/src/worker.service.ts:28](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L28)
183
+
184
+ Configuration options for the AMQP worker NestJS module.
185
+
186
+ #### Example
187
+
188
+ ```typescript
189
+ const options: AmqpWorkerModuleOptions<typeof contract> = {
190
+ contract: myContract,
191
+ handlers: {
192
+ processOrder: async (message) => {
193
+ console.log('Processing order:', message.orderId);
194
+ }
195
+ },
196
+ urls: ['amqp://localhost'],
197
+ connectionOptions: {
198
+ heartbeatIntervalInSeconds: 30
199
+ }
200
+ };
201
+ ```
202
+
203
+ #### Type Parameters
204
+
205
+ | Type Parameter | Description |
206
+ | ------ | ------ |
207
+ | `TContract` *extends* `ContractDefinition` | The contract definition type |
208
+
209
+ #### Properties
210
+
211
+ | Property | Type | Description | Defined in |
212
+ | ------ | ------ | ------ | ------ |
213
+ | <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker-nestjs/src/worker.service.ts:36](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L36) |
214
+ | <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker-nestjs/src/worker.service.ts:30](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L30) |
215
+ | <a id="handlers"></a> `handlers` | `WorkerInferConsumerHandlers`\<`TContract`\> | Message handlers for each consumer defined in the contract | [packages/worker-nestjs/src/worker.service.ts:32](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L32) |
216
+ | <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker-nestjs/src/worker.service.ts:34](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.service.ts#L34) |
217
+
218
+ ## Variables
219
+
220
+ ### MODULE\_OPTIONS\_TOKEN
221
+
222
+ ```ts
223
+ MODULE_OPTIONS_TOKEN: string | symbol;
224
+ ```
225
+
226
+ Defined in: [packages/worker-nestjs/src/worker.module-definition.ts:9](https://github.com/btravers/amqp-contract/blob/f0945f098387fd3a6a40beac8cbe2ed7a4de210a/packages/worker-nestjs/src/worker.module-definition.ts#L9)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amqp-contract/worker-nestjs",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "NestJS integration for @amqp-contract/worker",
5
5
  "keywords": [
6
6
  "amqp",
@@ -39,35 +39,40 @@
39
39
  "module": "./dist/index.mjs",
40
40
  "types": "./dist/index.d.mts",
41
41
  "files": [
42
- "dist"
42
+ "dist",
43
+ "docs"
43
44
  ],
44
45
  "dependencies": {
45
- "@amqp-contract/contract": "0.2.0",
46
- "@amqp-contract/worker": "0.2.0"
46
+ "@amqp-contract/contract": "0.2.1",
47
+ "@amqp-contract/worker": "0.2.1"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@nestjs/common": "11.1.10",
50
- "@types/amqplib": "0.10.8",
51
+ "@swan-io/boxed": "3.2.1",
51
52
  "@types/node": "25.0.3",
52
53
  "@vitest/coverage-v8": "4.0.16",
54
+ "amqp-connection-manager": "5.0.0",
53
55
  "amqplib": "0.10.9",
54
56
  "reflect-metadata": "0.2.2",
55
57
  "rxjs": "7.8.2",
56
58
  "tsdown": "0.18.2",
59
+ "typedoc": "0.28.3",
60
+ "typedoc-plugin-markdown": "4.9.0",
57
61
  "typescript": "5.9.3",
58
62
  "vitest": "4.0.16",
59
63
  "zod": "4.2.1",
60
- "@amqp-contract/tsconfig": "0.0.0"
64
+ "@amqp-contract/tsconfig": "0.0.0",
65
+ "@amqp-contract/typedoc": "0.0.1"
61
66
  },
62
67
  "peerDependencies": {
63
68
  "@nestjs/common": "^11.0.0",
64
69
  "@nestjs/core": "^11.0.0",
65
- "amqplib": ">=0.10.0",
66
70
  "reflect-metadata": ">=0.1.13",
67
71
  "rxjs": ">=7.0.0"
68
72
  },
69
73
  "scripts": {
70
74
  "build": "tsdown src/index.ts --format cjs,esm --dts --clean",
75
+ "build:docs": "typedoc",
71
76
  "dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
72
77
  "test": "vitest run --project unit",
73
78
  "test:watch": "vitest --project unit",