@amqp-contract/worker-nestjs 0.14.0 → 0.16.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/dist/index.cjs +6 -5
- package/dist/index.d.cts +60 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +60 -21
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +36 -35
- package/package.json +14 -14
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
let _nestjs_common = require("@nestjs/common");
|
|
2
3
|
let _amqp_contract_worker = require("@amqp-contract/worker");
|
|
3
4
|
|
|
@@ -9,13 +10,13 @@ let _amqp_contract_worker = require("@amqp-contract/worker");
|
|
|
9
10
|
const MODULE_OPTIONS_TOKEN = Symbol("AMQP_WORKER_MODULE_OPTIONS");
|
|
10
11
|
|
|
11
12
|
//#endregion
|
|
12
|
-
//#region \0@oxc-project+runtime@0.
|
|
13
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorateMetadata.js
|
|
13
14
|
function __decorateMetadata(k, v) {
|
|
14
15
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
//#endregion
|
|
18
|
-
//#region \0@oxc-project+runtime@0.
|
|
19
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorateParam.js
|
|
19
20
|
function __decorateParam(paramIndex, decorator) {
|
|
20
21
|
return function(target, key) {
|
|
21
22
|
decorator(target, key, paramIndex);
|
|
@@ -23,7 +24,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
//#endregion
|
|
26
|
-
//#region \0@oxc-project+runtime@0.
|
|
27
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorate.js
|
|
27
28
|
function __decorate(decorators, target, key, desc) {
|
|
28
29
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
30
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -33,7 +34,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
33
34
|
|
|
34
35
|
//#endregion
|
|
35
36
|
//#region src/worker.service.ts
|
|
36
|
-
let AmqpWorkerService = class AmqpWorkerService
|
|
37
|
+
let AmqpWorkerService = class AmqpWorkerService {
|
|
37
38
|
worker = null;
|
|
38
39
|
constructor(options) {
|
|
39
40
|
this.options = options;
|
|
@@ -74,7 +75,7 @@ AmqpWorkerService = __decorate([
|
|
|
74
75
|
//#endregion
|
|
75
76
|
//#region src/worker.module.ts
|
|
76
77
|
var _AmqpWorkerModule;
|
|
77
|
-
let AmqpWorkerModule = _AmqpWorkerModule = class AmqpWorkerModule
|
|
78
|
+
let AmqpWorkerModule = _AmqpWorkerModule = class AmqpWorkerModule {
|
|
78
79
|
/**
|
|
79
80
|
* Register the AMQP worker module with synchronous configuration
|
|
80
81
|
*
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as amqp from "amqplib";
|
|
2
|
+
import { TcpSocketConnectOpts } from "net";
|
|
3
|
+
import { ConnectionOptions } from "tls";
|
|
2
4
|
import { DynamicModule, ModuleMetadata, OnModuleDestroy, OnModuleInit, Type } from "@nestjs/common";
|
|
3
5
|
import { WorkerInferSafeConsumerHandlers, WorkerInferSafeConsumerHandlers as WorkerInferSafeConsumerHandlers$1, defineHandler, defineHandlers } from "@amqp-contract/worker";
|
|
4
|
-
import {
|
|
6
|
+
import { ContractDefinition } from "@amqp-contract/contract";
|
|
5
7
|
|
|
8
|
+
//#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
|
|
9
|
+
type ConnectionUrl = string | amqp.Options.Connect | {
|
|
10
|
+
url: string;
|
|
11
|
+
connectionOptions?: AmqpConnectionOptions;
|
|
12
|
+
};
|
|
13
|
+
type AmqpConnectionOptions = (ConnectionOptions | TcpSocketConnectOpts) & {
|
|
14
|
+
noDelay?: boolean;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
keepAlive?: boolean;
|
|
17
|
+
keepAliveDelay?: number;
|
|
18
|
+
clientProperties?: any;
|
|
19
|
+
credentials?: {
|
|
20
|
+
mechanism: string;
|
|
21
|
+
username: string;
|
|
22
|
+
password: string;
|
|
23
|
+
response: () => Buffer;
|
|
24
|
+
} | {
|
|
25
|
+
mechanism: string;
|
|
26
|
+
response: () => Buffer;
|
|
27
|
+
} | undefined;
|
|
28
|
+
};
|
|
29
|
+
interface AmqpConnectionManagerOptions {
|
|
30
|
+
/** Interval to send heartbeats to broker. Defaults to 5 seconds. */
|
|
31
|
+
heartbeatIntervalInSeconds?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The time to wait before trying to reconnect. If not specified, defaults
|
|
34
|
+
* to `heartbeatIntervalInSeconds`.
|
|
35
|
+
*/
|
|
36
|
+
reconnectTimeInSeconds?: number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* `findServers` is a function that which returns one or more servers to
|
|
39
|
+
* connect to. This should return either a single URL or an array of URLs.
|
|
40
|
+
* This is handy when you're using a service discovery mechanism such as
|
|
41
|
+
* Consul or etcd. Instead of taking a callback, this can also return a
|
|
42
|
+
* Promise. Note that if this is supplied, then `urls` is ignored.
|
|
43
|
+
*/
|
|
44
|
+
findServers?: ((callback: (urls: ConnectionUrl | ConnectionUrl[]) => void) => void) | (() => Promise<ConnectionUrl | ConnectionUrl[]>) | undefined;
|
|
45
|
+
/** Connection options, passed as options to the amqplib.connect() method. */
|
|
46
|
+
connectionOptions?: AmqpConnectionOptions;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
6
49
|
//#region src/worker.service.d.ts
|
|
7
|
-
|
|
8
50
|
/**
|
|
9
51
|
* Configuration options for the AMQP worker NestJS module.
|
|
10
52
|
*
|
|
@@ -27,14 +69,10 @@ import { ContractDefinitionInput } from "@amqp-contract/contract";
|
|
|
27
69
|
* };
|
|
28
70
|
* ```
|
|
29
71
|
*/
|
|
30
|
-
type AmqpWorkerModuleOptions<TContract extends
|
|
31
|
-
/** The AMQP contract definition specifying consumers and their message schemas */
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
handlers: WorkerInferSafeConsumerHandlers$1<TContract>;
|
|
35
|
-
/** AMQP broker URL(s). Multiple URLs provide failover support */
|
|
36
|
-
urls: ConnectionUrl[];
|
|
37
|
-
/** Optional connection configuration (heartbeat, reconnect settings, etc.) */
|
|
72
|
+
type AmqpWorkerModuleOptions<TContract extends ContractDefinition> = {
|
|
73
|
+
/** The AMQP contract definition specifying consumers and their message schemas */contract: TContract; /** Message handlers for each consumer defined in the contract. Use defineHandlers to create type-safe handlers. */
|
|
74
|
+
handlers: WorkerInferSafeConsumerHandlers$1<TContract>; /** AMQP broker URL(s). Multiple URLs provide failover support */
|
|
75
|
+
urls: ConnectionUrl[]; /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
|
|
38
76
|
connectionOptions?: AmqpConnectionManagerOptions | undefined;
|
|
39
77
|
};
|
|
40
78
|
/**
|
|
@@ -71,7 +109,7 @@ type AmqpWorkerModuleOptions<TContract extends ContractDefinitionInput> = {
|
|
|
71
109
|
* // and stops gracefully when the application shuts down
|
|
72
110
|
* ```
|
|
73
111
|
*/
|
|
74
|
-
declare class AmqpWorkerService<TContract extends
|
|
112
|
+
declare class AmqpWorkerService<TContract extends ContractDefinition> implements OnModuleInit, OnModuleDestroy {
|
|
75
113
|
private readonly options;
|
|
76
114
|
private worker;
|
|
77
115
|
constructor(options: AmqpWorkerModuleOptions<TContract>);
|
|
@@ -100,11 +138,11 @@ declare class AmqpWorkerService<TContract extends ContractDefinitionInput> imple
|
|
|
100
138
|
/**
|
|
101
139
|
* Factory function return type for async module configuration
|
|
102
140
|
*/
|
|
103
|
-
type AmqpWorkerModuleOptionsFactory<TContract extends
|
|
141
|
+
type AmqpWorkerModuleOptionsFactory<TContract extends ContractDefinition> = AmqpWorkerModuleOptions<TContract> | Promise<AmqpWorkerModuleOptions<TContract>>;
|
|
104
142
|
/**
|
|
105
143
|
* Options for async module configuration using factory pattern
|
|
106
144
|
*/
|
|
107
|
-
type AmqpWorkerModuleAsyncOptions<TContract extends
|
|
145
|
+
type AmqpWorkerModuleAsyncOptions<TContract extends ContractDefinition> = {
|
|
108
146
|
/**
|
|
109
147
|
* Factory function that returns the module options.
|
|
110
148
|
* Can use injected dependencies to create configuration.
|
|
@@ -135,9 +173,9 @@ type AmqpWorkerModuleAsyncOptions<TContract extends ContractDefinitionInput> = {
|
|
|
135
173
|
* AmqpWorkerModule.forRoot({
|
|
136
174
|
* contract: myContract,
|
|
137
175
|
* handlers: {
|
|
138
|
-
* processOrder:
|
|
139
|
-
*
|
|
140
|
-
*
|
|
176
|
+
* processOrder: ({ payload }) => {
|
|
177
|
+
* console.log('Order:', payload.orderId);
|
|
178
|
+
* return Future.value(Result.Ok(undefined));
|
|
141
179
|
* }
|
|
142
180
|
* },
|
|
143
181
|
* urls: ['amqp://localhost']
|
|
@@ -154,8 +192,9 @@ type AmqpWorkerModuleAsyncOptions<TContract extends ContractDefinitionInput> = {
|
|
|
154
192
|
* useFactory: (configService: ConfigService) => ({
|
|
155
193
|
* contract: myContract,
|
|
156
194
|
* handlers: {
|
|
157
|
-
* processOrder:
|
|
158
|
-
* console.log('Order:',
|
|
195
|
+
* processOrder: ({ payload }) => {
|
|
196
|
+
* console.log('Order:', payload.orderId);
|
|
197
|
+
* return Future.value(Result.Ok(undefined));
|
|
159
198
|
* }
|
|
160
199
|
* },
|
|
161
200
|
* urls: configService.get('AMQP_URLS')
|
|
@@ -174,14 +213,14 @@ declare class AmqpWorkerModule {
|
|
|
174
213
|
* @param options - The worker configuration options with contract and handlers
|
|
175
214
|
* @returns A dynamic module for NestJS
|
|
176
215
|
*/
|
|
177
|
-
static forRoot<TContract extends
|
|
216
|
+
static forRoot<TContract extends ContractDefinition>(options: AmqpWorkerModuleOptions<TContract>): DynamicModule;
|
|
178
217
|
/**
|
|
179
218
|
* Register the AMQP worker module with asynchronous configuration
|
|
180
219
|
*
|
|
181
220
|
* @param options - Async configuration options with factory function
|
|
182
221
|
* @returns A dynamic module for NestJS
|
|
183
222
|
*/
|
|
184
|
-
static forRootAsync<TContract extends
|
|
223
|
+
static forRootAsync<TContract extends ContractDefinition>(options: AmqpWorkerModuleAsyncOptions<TContract>): DynamicModule;
|
|
185
224
|
}
|
|
186
225
|
//#endregion
|
|
187
226
|
//#region src/worker.module-definition.d.ts
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/worker.service.ts","../src/worker.module.ts","../src/worker.module-definition.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts","../src/worker.service.ts","../src/worker.module.ts","../src/worker.module-definition.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;EACAC,cAAAA;EACAC,gBAAAA;EACAC,WAAAA;IACIC,SAAAA;IACAC,QAAAA;IACAC,QAAAA;IACAC,QAAAA,QAAgBV,MAAAA;EAAAA;IAEhBO,SAAAA;IACAG,QAAAA,QAAgBV,MAAAA;EAAAA;AAAAA;AAAAA,UAGPW,4BAAAA;EARTH;EAUJK,0BAAAA;EARIH;;;;EAaJI,sBAAAA;EAV0B;;AAG9B;;;;;EAeIC,WAAAA,KAAgBE,QAAAA,GAAWD,IAAAA,EAAM7B,aAAAA,GAAgBA,aAAAA,+BAA4CyB,OAAAA,CAAQzB,aAAAA,GAAgBA,aAAAA;EAAAA;EAErHK,iBAAAA,GAAoBF,qBAAAA;AAAAA;;;;;;;AAjDxB;;;;;;;;;;;;AAgBA;;;;;;KCOY,uBAAA,mBAA0C,kBAAA;EDMxB,kFCJ5B,QAAA,EAAU,SAAA,EDTyBN;ECWnC,QAAA,EAAU,iCAAA,CAAgC,SAAA,GDVxCiB;ECYF,IAAA,EAAM,aAAA,IDVJE;ECYF,iBAAA,GAAoB,4BAAA;AAAA;;;;;;;;;;;;ADCtB;;;;;;;;;;;;;;;;;;;;;;;cCqCa,iBAAA,mBAAoC,kBAAA,aACpC,YAAA,EAAc,eAAA;EAAA,iBAMN,OAAA;EAAA,QAJX,MAAA;cAIW,OAAA,EAAS,uBAAA,CAAwB,SAAA;;AArDtD;;;;;;;;;EAkEQ,YAAA,CAAA,GAAgB,OAAA;EA1D0B;;;;;;;EAqE1C,eAAA,CAAA,GAAmB,OAAA;AAAA;;;;;;KC3FtB,8BAAA,mBAAiD,kBAAA,IAClD,uBAAA,CAAwB,SAAA,IACxB,OAAA,CAAQ,uBAAA,CAAwB,SAAA;;AFXpC;;KEgBY,4BAAA,mBAA+C,kBAAA;EFdd;;;;EEoB3C,UAAA,MAAgB,IAAA,YAAgB,8BAAA,CAA+B,SAAA;EFpB7DX;;;;EEyBF,MAAA,sBAA4B,IAAA;EFXG;;;EEe/B,OAAA,GAAU,cAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;AFCZ;;;;;;;;;;;;;;;;;;;;;;;;;;;cEmDa,gBAAA;ED5DD;;;;;;EAAA,OCmEH,OAAA,mBAA0B,kBAAA,CAAA,CAC/B,OAAA,EAAS,uBAAA,CAAwB,SAAA,IAChC,aAAA;ED/DG;;;;;;EAAA,OCmFC,YAAA,mBAA+B,kBAAA,CAAA,CACpC,OAAA,EAAS,4BAAA,CAA6B,SAAA,IACrC,aAAA;AAAA;;;;;;;cCnHQ,oBAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
1
|
import { DynamicModule, ModuleMetadata, OnModuleDestroy, OnModuleInit, Type } from "@nestjs/common";
|
|
2
2
|
import { WorkerInferSafeConsumerHandlers, WorkerInferSafeConsumerHandlers as WorkerInferSafeConsumerHandlers$1, defineHandler, defineHandlers } from "@amqp-contract/worker";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import * as amqp from "amqplib";
|
|
4
|
+
import { TcpSocketConnectOpts } from "net";
|
|
5
|
+
import { ConnectionOptions } from "tls";
|
|
6
|
+
import { ContractDefinition } from "@amqp-contract/contract";
|
|
5
7
|
|
|
8
|
+
//#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
|
|
9
|
+
type ConnectionUrl = string | amqp.Options.Connect | {
|
|
10
|
+
url: string;
|
|
11
|
+
connectionOptions?: AmqpConnectionOptions;
|
|
12
|
+
};
|
|
13
|
+
type AmqpConnectionOptions = (ConnectionOptions | TcpSocketConnectOpts) & {
|
|
14
|
+
noDelay?: boolean;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
keepAlive?: boolean;
|
|
17
|
+
keepAliveDelay?: number;
|
|
18
|
+
clientProperties?: any;
|
|
19
|
+
credentials?: {
|
|
20
|
+
mechanism: string;
|
|
21
|
+
username: string;
|
|
22
|
+
password: string;
|
|
23
|
+
response: () => Buffer;
|
|
24
|
+
} | {
|
|
25
|
+
mechanism: string;
|
|
26
|
+
response: () => Buffer;
|
|
27
|
+
} | undefined;
|
|
28
|
+
};
|
|
29
|
+
interface AmqpConnectionManagerOptions {
|
|
30
|
+
/** Interval to send heartbeats to broker. Defaults to 5 seconds. */
|
|
31
|
+
heartbeatIntervalInSeconds?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The time to wait before trying to reconnect. If not specified, defaults
|
|
34
|
+
* to `heartbeatIntervalInSeconds`.
|
|
35
|
+
*/
|
|
36
|
+
reconnectTimeInSeconds?: number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* `findServers` is a function that which returns one or more servers to
|
|
39
|
+
* connect to. This should return either a single URL or an array of URLs.
|
|
40
|
+
* This is handy when you're using a service discovery mechanism such as
|
|
41
|
+
* Consul or etcd. Instead of taking a callback, this can also return a
|
|
42
|
+
* Promise. Note that if this is supplied, then `urls` is ignored.
|
|
43
|
+
*/
|
|
44
|
+
findServers?: ((callback: (urls: ConnectionUrl | ConnectionUrl[]) => void) => void) | (() => Promise<ConnectionUrl | ConnectionUrl[]>) | undefined;
|
|
45
|
+
/** Connection options, passed as options to the amqplib.connect() method. */
|
|
46
|
+
connectionOptions?: AmqpConnectionOptions;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
6
49
|
//#region src/worker.service.d.ts
|
|
7
|
-
|
|
8
50
|
/**
|
|
9
51
|
* Configuration options for the AMQP worker NestJS module.
|
|
10
52
|
*
|
|
@@ -27,14 +69,10 @@ import { ContractDefinitionInput } from "@amqp-contract/contract";
|
|
|
27
69
|
* };
|
|
28
70
|
* ```
|
|
29
71
|
*/
|
|
30
|
-
type AmqpWorkerModuleOptions<TContract extends
|
|
31
|
-
/** The AMQP contract definition specifying consumers and their message schemas */
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
handlers: WorkerInferSafeConsumerHandlers$1<TContract>;
|
|
35
|
-
/** AMQP broker URL(s). Multiple URLs provide failover support */
|
|
36
|
-
urls: ConnectionUrl[];
|
|
37
|
-
/** Optional connection configuration (heartbeat, reconnect settings, etc.) */
|
|
72
|
+
type AmqpWorkerModuleOptions<TContract extends ContractDefinition> = {
|
|
73
|
+
/** The AMQP contract definition specifying consumers and their message schemas */contract: TContract; /** Message handlers for each consumer defined in the contract. Use defineHandlers to create type-safe handlers. */
|
|
74
|
+
handlers: WorkerInferSafeConsumerHandlers$1<TContract>; /** AMQP broker URL(s). Multiple URLs provide failover support */
|
|
75
|
+
urls: ConnectionUrl[]; /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
|
|
38
76
|
connectionOptions?: AmqpConnectionManagerOptions | undefined;
|
|
39
77
|
};
|
|
40
78
|
/**
|
|
@@ -71,7 +109,7 @@ type AmqpWorkerModuleOptions<TContract extends ContractDefinitionInput> = {
|
|
|
71
109
|
* // and stops gracefully when the application shuts down
|
|
72
110
|
* ```
|
|
73
111
|
*/
|
|
74
|
-
declare class AmqpWorkerService<TContract extends
|
|
112
|
+
declare class AmqpWorkerService<TContract extends ContractDefinition> implements OnModuleInit, OnModuleDestroy {
|
|
75
113
|
private readonly options;
|
|
76
114
|
private worker;
|
|
77
115
|
constructor(options: AmqpWorkerModuleOptions<TContract>);
|
|
@@ -100,11 +138,11 @@ declare class AmqpWorkerService<TContract extends ContractDefinitionInput> imple
|
|
|
100
138
|
/**
|
|
101
139
|
* Factory function return type for async module configuration
|
|
102
140
|
*/
|
|
103
|
-
type AmqpWorkerModuleOptionsFactory<TContract extends
|
|
141
|
+
type AmqpWorkerModuleOptionsFactory<TContract extends ContractDefinition> = AmqpWorkerModuleOptions<TContract> | Promise<AmqpWorkerModuleOptions<TContract>>;
|
|
104
142
|
/**
|
|
105
143
|
* Options for async module configuration using factory pattern
|
|
106
144
|
*/
|
|
107
|
-
type AmqpWorkerModuleAsyncOptions<TContract extends
|
|
145
|
+
type AmqpWorkerModuleAsyncOptions<TContract extends ContractDefinition> = {
|
|
108
146
|
/**
|
|
109
147
|
* Factory function that returns the module options.
|
|
110
148
|
* Can use injected dependencies to create configuration.
|
|
@@ -135,9 +173,9 @@ type AmqpWorkerModuleAsyncOptions<TContract extends ContractDefinitionInput> = {
|
|
|
135
173
|
* AmqpWorkerModule.forRoot({
|
|
136
174
|
* contract: myContract,
|
|
137
175
|
* handlers: {
|
|
138
|
-
* processOrder:
|
|
139
|
-
*
|
|
140
|
-
*
|
|
176
|
+
* processOrder: ({ payload }) => {
|
|
177
|
+
* console.log('Order:', payload.orderId);
|
|
178
|
+
* return Future.value(Result.Ok(undefined));
|
|
141
179
|
* }
|
|
142
180
|
* },
|
|
143
181
|
* urls: ['amqp://localhost']
|
|
@@ -154,8 +192,9 @@ type AmqpWorkerModuleAsyncOptions<TContract extends ContractDefinitionInput> = {
|
|
|
154
192
|
* useFactory: (configService: ConfigService) => ({
|
|
155
193
|
* contract: myContract,
|
|
156
194
|
* handlers: {
|
|
157
|
-
* processOrder:
|
|
158
|
-
* console.log('Order:',
|
|
195
|
+
* processOrder: ({ payload }) => {
|
|
196
|
+
* console.log('Order:', payload.orderId);
|
|
197
|
+
* return Future.value(Result.Ok(undefined));
|
|
159
198
|
* }
|
|
160
199
|
* },
|
|
161
200
|
* urls: configService.get('AMQP_URLS')
|
|
@@ -174,14 +213,14 @@ declare class AmqpWorkerModule {
|
|
|
174
213
|
* @param options - The worker configuration options with contract and handlers
|
|
175
214
|
* @returns A dynamic module for NestJS
|
|
176
215
|
*/
|
|
177
|
-
static forRoot<TContract extends
|
|
216
|
+
static forRoot<TContract extends ContractDefinition>(options: AmqpWorkerModuleOptions<TContract>): DynamicModule;
|
|
178
217
|
/**
|
|
179
218
|
* Register the AMQP worker module with asynchronous configuration
|
|
180
219
|
*
|
|
181
220
|
* @param options - Async configuration options with factory function
|
|
182
221
|
* @returns A dynamic module for NestJS
|
|
183
222
|
*/
|
|
184
|
-
static forRootAsync<TContract extends
|
|
223
|
+
static forRootAsync<TContract extends ContractDefinition>(options: AmqpWorkerModuleAsyncOptions<TContract>): DynamicModule;
|
|
185
224
|
}
|
|
186
225
|
//#endregion
|
|
187
226
|
//#region src/worker.module-definition.d.ts
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/worker.service.ts","../src/worker.module.ts","../src/worker.module-definition.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts","../src/worker.service.ts","../src/worker.module.ts","../src/worker.module-definition.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;EACAC,cAAAA;EACAC,gBAAAA;EACAC,WAAAA;IACIC,SAAAA;IACAC,QAAAA;IACAC,QAAAA;IACAC,QAAAA,QAAgBV,MAAAA;EAAAA;IAEhBO,SAAAA;IACAG,QAAAA,QAAgBV,MAAAA;EAAAA;AAAAA;AAAAA,UAGPW,4BAAAA;EARTH;EAUJK,0BAAAA;EARIH;;;;EAaJI,sBAAAA;EAV0B;;AAG9B;;;;;EAeIC,WAAAA,KAAgBE,QAAAA,GAAWD,IAAAA,EAAM7B,aAAAA,GAAgBA,aAAAA,+BAA4CyB,OAAAA,CAAQzB,aAAAA,GAAgBA,aAAAA;EAAAA;EAErHK,iBAAAA,GAAoBF,qBAAAA;AAAAA;;;;;;;AAjDxB;;;;;;;;;;;;AAgBA;;;;;;KCOY,uBAAA,mBAA0C,kBAAA;EDMxB,kFCJ5B,QAAA,EAAU,SAAA,EDTyBN;ECWnC,QAAA,EAAU,iCAAA,CAAgC,SAAA,GDVxCiB;ECYF,IAAA,EAAM,aAAA,IDVJE;ECYF,iBAAA,GAAoB,4BAAA;AAAA;;;;;;;;;;;;ADCtB;;;;;;;;;;;;;;;;;;;;;;;cCqCa,iBAAA,mBAAoC,kBAAA,aACpC,YAAA,EAAc,eAAA;EAAA,iBAMN,OAAA;EAAA,QAJX,MAAA;cAIW,OAAA,EAAS,uBAAA,CAAwB,SAAA;;AArDtD;;;;;;;;;EAkEQ,YAAA,CAAA,GAAgB,OAAA;EA1D0B;;;;;;;EAqE1C,eAAA,CAAA,GAAmB,OAAA;AAAA;;;;;;KC3FtB,8BAAA,mBAAiD,kBAAA,IAClD,uBAAA,CAAwB,SAAA,IACxB,OAAA,CAAQ,uBAAA,CAAwB,SAAA;;AFXpC;;KEgBY,4BAAA,mBAA+C,kBAAA;EFdd;;;;EEoB3C,UAAA,MAAgB,IAAA,YAAgB,8BAAA,CAA+B,SAAA;EFpB7DX;;;;EEyBF,MAAA,sBAA4B,IAAA;EFXG;;;EEe/B,OAAA,GAAU,cAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;AFCZ;;;;;;;;;;;;;;;;;;;;;;;;;;;cEmDa,gBAAA;ED5DD;;;;;;EAAA,OCmEH,OAAA,mBAA0B,kBAAA,CAAA,CAC/B,OAAA,EAAS,uBAAA,CAAwB,SAAA,IAChC,aAAA;ED/DG;;;;;;EAAA,OCmFC,YAAA,mBAA+B,kBAAA,CAAA,CACpC,OAAA,EAAS,4BAAA,CAA6B,SAAA,IACrC,aAAA;AAAA;;;;;;;cCnHQ,oBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -9,13 +9,13 @@ import { TypedAmqpWorker, defineHandler, defineHandlers } from "@amqp-contract/w
|
|
|
9
9
|
const MODULE_OPTIONS_TOKEN = Symbol("AMQP_WORKER_MODULE_OPTIONS");
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
|
-
//#region \0@oxc-project+runtime@0.
|
|
12
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorateMetadata.js
|
|
13
13
|
function __decorateMetadata(k, v) {
|
|
14
14
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
|
-
//#region \0@oxc-project+runtime@0.
|
|
18
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorateParam.js
|
|
19
19
|
function __decorateParam(paramIndex, decorator) {
|
|
20
20
|
return function(target, key) {
|
|
21
21
|
decorator(target, key, paramIndex);
|
|
@@ -23,7 +23,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region \0@oxc-project+runtime@0.
|
|
26
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorate.js
|
|
27
27
|
function __decorate(decorators, target, key, desc) {
|
|
28
28
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
29
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -33,7 +33,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
33
33
|
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/worker.service.ts
|
|
36
|
-
let AmqpWorkerService = class AmqpWorkerService
|
|
36
|
+
let AmqpWorkerService = class AmqpWorkerService {
|
|
37
37
|
worker = null;
|
|
38
38
|
constructor(options) {
|
|
39
39
|
this.options = options;
|
|
@@ -74,7 +74,7 @@ AmqpWorkerService = __decorate([
|
|
|
74
74
|
//#endregion
|
|
75
75
|
//#region src/worker.module.ts
|
|
76
76
|
var _AmqpWorkerModule;
|
|
77
|
-
let AmqpWorkerModule = _AmqpWorkerModule = class AmqpWorkerModule
|
|
77
|
+
let AmqpWorkerModule = _AmqpWorkerModule = class AmqpWorkerModule {
|
|
78
78
|
/**
|
|
79
79
|
* Register the AMQP worker module with synchronous configuration
|
|
80
80
|
*
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/worker.module-definition.ts","../src/worker.service.ts","../src/worker.module.ts"],"sourcesContent":["/**\n * Injection token for AMQP worker module options\n * Used by NestJS DI system to inject configuration into AmqpWorkerService\n */\nexport const MODULE_OPTIONS_TOKEN = Symbol(\"AMQP_WORKER_MODULE_OPTIONS\");\n","import type { AmqpConnectionManagerOptions, ConnectionUrl } from \"amqp-connection-manager\";\nimport { Inject, Injectable, type OnModuleDestroy, type OnModuleInit } from \"@nestjs/common\";\nimport { TypedAmqpWorker, type WorkerInferSafeConsumerHandlers } from \"@amqp-contract/worker\";\nimport type { ContractDefinition } from \"@amqp-contract/contract\";\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 * import { defineHandlers, RetryableError } from '@amqp-contract/worker';\n * import { Future } from '@swan-io/boxed';\n *\n * const options: AmqpWorkerModuleOptions<typeof contract> = {\n * contract: myContract,\n * handlers: defineHandlers(myContract, {\n * processOrder: ({ payload }) =>\n * Future.fromPromise(processPayment(payload))\n * .mapOk(() => undefined)\n * .mapError((error) => new RetryableError('Payment failed', error))\n * }),\n * urls: ['amqp://localhost'],\n * };\n * ```\n */\nexport type 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. Use defineHandlers to create type-safe handlers. */\n handlers: WorkerInferSafeConsumerHandlers<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 { type AmqpWorkerModuleOptions, AmqpWorkerService } from \"./worker.service.js\";\nimport {\n type DynamicModule,\n Module,\n type ModuleMetadata,\n type Provider,\n type Type,\n} from \"@nestjs/common\";\nimport type { ContractDefinition } from \"@amqp-contract/contract\";\nimport { MODULE_OPTIONS_TOKEN } from \"./worker.module-definition.js\";\n\n/**\n * Factory function return type for async module configuration\n */\ntype AmqpWorkerModuleOptionsFactory<TContract extends ContractDefinition> =\n | AmqpWorkerModuleOptions<TContract>\n | Promise<AmqpWorkerModuleOptions<TContract>>;\n\n/**\n * Options for async module configuration using factory pattern\n */\nexport type AmqpWorkerModuleAsyncOptions<TContract extends ContractDefinition> = {\n /**\n * Factory function that returns the module options.\n * Can use injected dependencies to create configuration.\n */\n // oxlint-disable-next-line no-explicit-any\n useFactory: (...args: any[]) => AmqpWorkerModuleOptionsFactory<TContract>;\n /**\n * Optional dependencies to inject into the factory function.\n * Can be a token (string/symbol) a class or a reference to a provider.\n */\n inject?: (string | symbol | Type<unknown>)[];\n /**\n * Optional list of imported modules that export providers needed by the factory\n */\n imports?: ModuleMetadata[\"imports\"];\n};\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 * @typeParam TContract - The contract definition type for type-safe handlers\n *\n * @example\n * ```typescript\n * // Synchronous configuration\n * @Module({\n * imports: [\n * AmqpWorkerModule.forRoot({\n * contract: myContract,\n * handlers: {\n * processOrder: ({ payload }) => {\n * console.log('Order:', payload.orderId);\n * return Future.value(Result.Ok(undefined));\n * }\n * },\n * urls: ['amqp://localhost']\n * })\n * ]\n * })\n * export class AppModule {}\n *\n * // Asynchronous configuration\n * @Module({\n * imports: [\n * AmqpWorkerModule.forRootAsync({\n * imports: [ConfigModule],\n * useFactory: (configService: ConfigService) => ({\n * contract: myContract,\n * handlers: {\n * processOrder: ({ payload }) => {\n * console.log('Order:', payload.orderId);\n * return Future.value(Result.Ok(undefined));\n * }\n * },\n * urls: configService.get('AMQP_URLS')\n * }),\n * inject: [ConfigService]\n * })\n * ]\n * })\n * export class AppModule {}\n * ```\n */\n@Module({})\nexport class AmqpWorkerModule {\n /**\n * Register the AMQP worker module with synchronous configuration\n *\n * @param options - The worker configuration options with contract and handlers\n * @returns A dynamic module for NestJS\n */\n static forRoot<TContract extends ContractDefinition>(\n options: AmqpWorkerModuleOptions<TContract>,\n ): DynamicModule {\n return {\n module: AmqpWorkerModule,\n providers: [\n {\n provide: MODULE_OPTIONS_TOKEN,\n useValue: options,\n },\n AmqpWorkerService,\n ],\n exports: [AmqpWorkerService],\n };\n }\n\n /**\n * Register the AMQP worker module with asynchronous configuration\n *\n * @param options - Async configuration options with factory function\n * @returns A dynamic module for NestJS\n */\n static forRootAsync<TContract extends ContractDefinition>(\n options: AmqpWorkerModuleAsyncOptions<TContract>,\n ): DynamicModule {\n const providers: Provider[] = [\n {\n provide: MODULE_OPTIONS_TOKEN,\n useFactory: options.useFactory,\n inject: options.inject ?? [],\n },\n AmqpWorkerService,\n ];\n\n return {\n module: AmqpWorkerModule,\n imports: options.imports ?? [],\n providers,\n exports: [AmqpWorkerService],\n };\n }\n}\n"],"mappings":";;;;;;;;AAIA,MAAa,uBAAuB,OAAO,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;ACsEjE,8BAAM,kBAEb;CACE,AAAQ,SAA4C;CAEpD,YACE,AACiB,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;;;;;;;ACQ1B,iDAAM,iBAAiB;;;;;;;CAO5B,OAAO,QACL,SACe;AACf,SAAO;GACL;GACA,WAAW,CACT;IACE,SAAS;IACT,UAAU;IACX,EACD,kBACD;GACD,SAAS,CAAC,kBAAkB;GAC7B;;;;;;;;CASH,OAAO,aACL,SACe;EACf,MAAM,YAAwB,CAC5B;GACE,SAAS;GACT,YAAY,QAAQ;GACpB,QAAQ,QAAQ,UAAU,EAAE;GAC7B,EACD,kBACD;AAED,SAAO;GACL;GACA,SAAS,QAAQ,WAAW,EAAE;GAC9B;GACA,SAAS,CAAC,kBAAkB;GAC7B;;;mDA/CJ,OAAO,EAAE,CAAC"}
|
package/docs/index.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
### AmqpWorkerModule
|
|
10
10
|
|
|
11
|
-
Defined in: [worker-nestjs/src/worker.module.ts:
|
|
11
|
+
Defined in: [worker-nestjs/src/worker.module.ts:89](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.module.ts#L89)
|
|
12
12
|
|
|
13
13
|
NestJS module for AMQP worker integration
|
|
14
14
|
This module provides type-safe AMQP worker functionality using @amqp-contract/worker
|
|
@@ -27,9 +27,9 @@ The contract definition type for type-safe handlers
|
|
|
27
27
|
AmqpWorkerModule.forRoot({
|
|
28
28
|
contract: myContract,
|
|
29
29
|
handlers: {
|
|
30
|
-
processOrder:
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
processOrder: ({ payload }) => {
|
|
31
|
+
console.log('Order:', payload.orderId);
|
|
32
|
+
return Future.value(Result.Ok(undefined));
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
urls: ['amqp://localhost']
|
|
@@ -46,8 +46,9 @@ export class AppModule {}
|
|
|
46
46
|
useFactory: (configService: ConfigService) => ({
|
|
47
47
|
contract: myContract,
|
|
48
48
|
handlers: {
|
|
49
|
-
processOrder:
|
|
50
|
-
console.log('Order:',
|
|
49
|
+
processOrder: ({ payload }) => {
|
|
50
|
+
console.log('Order:', payload.orderId);
|
|
51
|
+
return Future.value(Result.Ok(undefined));
|
|
51
52
|
}
|
|
52
53
|
},
|
|
53
54
|
urls: configService.get('AMQP_URLS')
|
|
@@ -79,7 +80,7 @@ new AmqpWorkerModule(): AmqpWorkerModule;
|
|
|
79
80
|
static forRoot<TContract>(options): DynamicModule;
|
|
80
81
|
```
|
|
81
82
|
|
|
82
|
-
Defined in: [worker-nestjs/src/worker.module.ts:
|
|
83
|
+
Defined in: [worker-nestjs/src/worker.module.ts:96](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.module.ts#L96)
|
|
83
84
|
|
|
84
85
|
Register the AMQP worker module with synchronous configuration
|
|
85
86
|
|
|
@@ -87,7 +88,7 @@ Register the AMQP worker module with synchronous configuration
|
|
|
87
88
|
|
|
88
89
|
| Type Parameter |
|
|
89
90
|
| ------ |
|
|
90
|
-
| `TContract` *extends* `
|
|
91
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
91
92
|
|
|
92
93
|
###### Parameters
|
|
93
94
|
|
|
@@ -107,7 +108,7 @@ A dynamic module for NestJS
|
|
|
107
108
|
static forRootAsync<TContract>(options): DynamicModule;
|
|
108
109
|
```
|
|
109
110
|
|
|
110
|
-
Defined in: [worker-nestjs/src/worker.module.ts:
|
|
111
|
+
Defined in: [worker-nestjs/src/worker.module.ts:118](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.module.ts#L118)
|
|
111
112
|
|
|
112
113
|
Register the AMQP worker module with asynchronous configuration
|
|
113
114
|
|
|
@@ -115,7 +116,7 @@ Register the AMQP worker module with asynchronous configuration
|
|
|
115
116
|
|
|
116
117
|
| Type Parameter |
|
|
117
118
|
| ------ |
|
|
118
|
-
| `TContract` *extends* `
|
|
119
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
119
120
|
|
|
120
121
|
###### Parameters
|
|
121
122
|
|
|
@@ -133,7 +134,7 @@ A dynamic module for NestJS
|
|
|
133
134
|
|
|
134
135
|
### AmqpWorkerService
|
|
135
136
|
|
|
136
|
-
Defined in: [worker-nestjs/src/worker.service.ts:75](https://github.com/btravers/amqp-contract/blob/
|
|
137
|
+
Defined in: [worker-nestjs/src/worker.service.ts:75](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L75)
|
|
137
138
|
|
|
138
139
|
Type-safe AMQP worker service for NestJS applications.
|
|
139
140
|
|
|
@@ -171,7 +172,7 @@ export class AppModule {}
|
|
|
171
172
|
|
|
172
173
|
| Type Parameter | Description |
|
|
173
174
|
| ------ | ------ |
|
|
174
|
-
| `TContract` *extends* `
|
|
175
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
175
176
|
|
|
176
177
|
#### Implements
|
|
177
178
|
|
|
@@ -186,7 +187,7 @@ export class AppModule {}
|
|
|
186
187
|
new AmqpWorkerService<TContract>(options): AmqpWorkerService<TContract>;
|
|
187
188
|
```
|
|
188
189
|
|
|
189
|
-
Defined in: [worker-nestjs/src/worker.service.ts:80](https://github.com/btravers/amqp-contract/blob/
|
|
190
|
+
Defined in: [worker-nestjs/src/worker.service.ts:80](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L80)
|
|
190
191
|
|
|
191
192
|
###### Parameters
|
|
192
193
|
|
|
@@ -206,7 +207,7 @@ Defined in: [worker-nestjs/src/worker.service.ts:80](https://github.com/btravers
|
|
|
206
207
|
onModuleDestroy(): Promise<void>;
|
|
207
208
|
```
|
|
208
209
|
|
|
209
|
-
Defined in: [worker-nestjs/src/worker.service.ts:106](https://github.com/btravers/amqp-contract/blob/
|
|
210
|
+
Defined in: [worker-nestjs/src/worker.service.ts:106](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L106)
|
|
210
211
|
|
|
211
212
|
Close the AMQP worker when the NestJS module is destroyed.
|
|
212
213
|
|
|
@@ -230,7 +231,7 @@ OnModuleDestroy.onModuleDestroy
|
|
|
230
231
|
onModuleInit(): Promise<void>;
|
|
231
232
|
```
|
|
232
233
|
|
|
233
|
-
Defined in: [worker-nestjs/src/worker.service.ts:95](https://github.com/btravers/amqp-contract/blob/
|
|
234
|
+
Defined in: [worker-nestjs/src/worker.service.ts:95](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L95)
|
|
234
235
|
|
|
235
236
|
Initialize the AMQP worker when the NestJS module starts.
|
|
236
237
|
|
|
@@ -261,7 +262,7 @@ OnModuleInit.onModuleInit
|
|
|
261
262
|
type AmqpWorkerModuleAsyncOptions<TContract> = object;
|
|
262
263
|
```
|
|
263
264
|
|
|
264
|
-
Defined in: [worker-nestjs/src/worker.module.ts:22](https://github.com/btravers/amqp-contract/blob/
|
|
265
|
+
Defined in: [worker-nestjs/src/worker.module.ts:22](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.module.ts#L22)
|
|
265
266
|
|
|
266
267
|
Options for async module configuration using factory pattern
|
|
267
268
|
|
|
@@ -269,15 +270,15 @@ Options for async module configuration using factory pattern
|
|
|
269
270
|
|
|
270
271
|
| Type Parameter |
|
|
271
272
|
| ------ |
|
|
272
|
-
| `TContract` *extends* `
|
|
273
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
273
274
|
|
|
274
275
|
#### Properties
|
|
275
276
|
|
|
276
277
|
| Property | Type | Description | Defined in |
|
|
277
278
|
| ------ | ------ | ------ | ------ |
|
|
278
|
-
| <a id="imports"></a> `imports?` | `ModuleMetadata`\[`"imports"`\] | Optional list of imported modules that export providers needed by the factory | [worker-nestjs/src/worker.module.ts:37](https://github.com/btravers/amqp-contract/blob/
|
|
279
|
-
| <a id="inject"></a> `inject?` | (`string` \| `symbol` \| `Type`<`unknown`>)[] | Optional dependencies to inject into the factory function. Can be a token (string/symbol) a class or a reference to a provider. | [worker-nestjs/src/worker.module.ts:33](https://github.com/btravers/amqp-contract/blob/
|
|
280
|
-
| <a id="usefactory"></a> `useFactory` | (...`args`) => `AmqpWorkerModuleOptionsFactory`<`TContract`> | Factory function that returns the module options. Can use injected dependencies to create configuration. | [worker-nestjs/src/worker.module.ts:28](https://github.com/btravers/amqp-contract/blob/
|
|
279
|
+
| <a id="imports"></a> `imports?` | `ModuleMetadata`\[`"imports"`\] | Optional list of imported modules that export providers needed by the factory | [worker-nestjs/src/worker.module.ts:37](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.module.ts#L37) |
|
|
280
|
+
| <a id="inject"></a> `inject?` | (`string` \| `symbol` \| `Type`<`unknown`>)[] | Optional dependencies to inject into the factory function. Can be a token (string/symbol) a class or a reference to a provider. | [worker-nestjs/src/worker.module.ts:33](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.module.ts#L33) |
|
|
281
|
+
| <a id="usefactory"></a> `useFactory` | (...`args`) => `AmqpWorkerModuleOptionsFactory`<`TContract`> | Factory function that returns the module options. Can use injected dependencies to create configuration. | [worker-nestjs/src/worker.module.ts:28](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.module.ts#L28) |
|
|
281
282
|
|
|
282
283
|
***
|
|
283
284
|
|
|
@@ -287,7 +288,7 @@ Options for async module configuration using factory pattern
|
|
|
287
288
|
type AmqpWorkerModuleOptions<TContract> = object;
|
|
288
289
|
```
|
|
289
290
|
|
|
290
|
-
Defined in: [worker-nestjs/src/worker.service.ts:29](https://github.com/btravers/amqp-contract/blob/
|
|
291
|
+
Defined in: [worker-nestjs/src/worker.service.ts:29](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L29)
|
|
291
292
|
|
|
292
293
|
Configuration options for the AMQP worker NestJS module.
|
|
293
294
|
|
|
@@ -313,16 +314,16 @@ const options: AmqpWorkerModuleOptions<typeof contract> = {
|
|
|
313
314
|
|
|
314
315
|
| Type Parameter | Description |
|
|
315
316
|
| ------ | ------ |
|
|
316
|
-
| `TContract` *extends* `
|
|
317
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
317
318
|
|
|
318
319
|
#### Properties
|
|
319
320
|
|
|
320
321
|
| Property | Type | Description | Defined in |
|
|
321
322
|
| ------ | ------ | ------ | ------ |
|
|
322
|
-
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [worker-nestjs/src/worker.service.ts:37](https://github.com/btravers/amqp-contract/blob/
|
|
323
|
-
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [worker-nestjs/src/worker.service.ts:31](https://github.com/btravers/amqp-contract/blob/
|
|
324
|
-
| <a id="handlers"></a> `handlers` | [`WorkerInferSafeConsumerHandlers`](#workerinfersafeconsumerhandlers)<`TContract`> | Message handlers for each consumer defined in the contract. Use defineHandlers to create type-safe handlers. | [worker-nestjs/src/worker.service.ts:33](https://github.com/btravers/amqp-contract/blob/
|
|
325
|
-
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [worker-nestjs/src/worker.service.ts:35](https://github.com/btravers/amqp-contract/blob/
|
|
323
|
+
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [worker-nestjs/src/worker.service.ts:37](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L37) |
|
|
324
|
+
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [worker-nestjs/src/worker.service.ts:31](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L31) |
|
|
325
|
+
| <a id="handlers"></a> `handlers` | [`WorkerInferSafeConsumerHandlers`](#workerinfersafeconsumerhandlers)<`TContract`> | Message handlers for each consumer defined in the contract. Use defineHandlers to create type-safe handlers. | [worker-nestjs/src/worker.service.ts:33](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L33) |
|
|
326
|
+
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [worker-nestjs/src/worker.service.ts:35](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.service.ts#L35) |
|
|
326
327
|
|
|
327
328
|
***
|
|
328
329
|
|
|
@@ -332,13 +333,13 @@ const options: AmqpWorkerModuleOptions<typeof contract> = {
|
|
|
332
333
|
type WorkerInferSafeConsumerHandlers<TContract> = WorkerInferConsumerHandlers<TContract>;
|
|
333
334
|
```
|
|
334
335
|
|
|
335
|
-
Defined in: worker/dist/index.d.mts:
|
|
336
|
+
Defined in: worker/dist/index.d.mts:337
|
|
336
337
|
|
|
337
338
|
#### Type Parameters
|
|
338
339
|
|
|
339
340
|
| Type Parameter |
|
|
340
341
|
| ------ |
|
|
341
|
-
| `TContract` *extends* `
|
|
342
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
342
343
|
|
|
343
344
|
#### Deprecated
|
|
344
345
|
|
|
@@ -352,7 +353,7 @@ Use `WorkerInferConsumerHandlers` instead. Will be removed in next major version
|
|
|
352
353
|
const MODULE_OPTIONS_TOKEN: typeof MODULE_OPTIONS_TOKEN;
|
|
353
354
|
```
|
|
354
355
|
|
|
355
|
-
Defined in: [worker-nestjs/src/worker.module-definition.ts:5](https://github.com/btravers/amqp-contract/blob/
|
|
356
|
+
Defined in: [worker-nestjs/src/worker.module-definition.ts:5](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker-nestjs/src/worker.module-definition.ts#L5)
|
|
356
357
|
|
|
357
358
|
Injection token for AMQP worker module options
|
|
358
359
|
Used by NestJS DI system to inject configuration into AmqpWorkerService
|
|
@@ -370,7 +371,7 @@ function defineHandler<TContract, TName>(
|
|
|
370
371
|
handler): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
371
372
|
```
|
|
372
373
|
|
|
373
|
-
Defined in: worker/dist/index.d.mts:
|
|
374
|
+
Defined in: worker/dist/index.d.mts:648
|
|
374
375
|
|
|
375
376
|
Define a type-safe handler for a specific consumer in a contract.
|
|
376
377
|
|
|
@@ -385,7 +386,7 @@ Supports two patterns:
|
|
|
385
386
|
|
|
386
387
|
| Type Parameter | Description |
|
|
387
388
|
| ------ | ------ |
|
|
388
|
-
| `TContract` *extends* `
|
|
389
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
389
390
|
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
390
391
|
|
|
391
392
|
##### Parameters
|
|
@@ -443,7 +444,7 @@ function defineHandler<TContract, TName>(
|
|
|
443
444
|
options): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
444
445
|
```
|
|
445
446
|
|
|
446
|
-
Defined in: worker/dist/index.d.mts:
|
|
447
|
+
Defined in: worker/dist/index.d.mts:649
|
|
447
448
|
|
|
448
449
|
Define a type-safe handler for a specific consumer in a contract.
|
|
449
450
|
|
|
@@ -458,7 +459,7 @@ Supports two patterns:
|
|
|
458
459
|
|
|
459
460
|
| Type Parameter | Description |
|
|
460
461
|
| ------ | ------ |
|
|
461
|
-
| `TContract` *extends* `
|
|
462
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
462
463
|
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
463
464
|
|
|
464
465
|
##### Parameters
|
|
@@ -516,7 +517,7 @@ const validateOrderHandler = defineHandler(
|
|
|
516
517
|
function defineHandlers<TContract>(contract, handlers): WorkerInferConsumerHandlers<TContract>;
|
|
517
518
|
```
|
|
518
519
|
|
|
519
|
-
Defined in: worker/dist/index.d.mts:
|
|
520
|
+
Defined in: worker/dist/index.d.mts:681
|
|
520
521
|
|
|
521
522
|
Define multiple type-safe handlers for consumers in a contract.
|
|
522
523
|
|
|
@@ -527,7 +528,7 @@ providing explicit error handling and better control over retry behavior.
|
|
|
527
528
|
|
|
528
529
|
| Type Parameter | Description |
|
|
529
530
|
| ------ | ------ |
|
|
530
|
-
| `TContract` *extends* `
|
|
531
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
531
532
|
|
|
532
533
|
#### Parameters
|
|
533
534
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amqp-contract/worker-nestjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "NestJS integration for @amqp-contract/worker",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"amqp",
|
|
@@ -52,33 +52,33 @@
|
|
|
52
52
|
"docs"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@amqp-contract/contract": "0.
|
|
56
|
-
"@amqp-contract/worker": "0.
|
|
55
|
+
"@amqp-contract/contract": "0.16.0",
|
|
56
|
+
"@amqp-contract/worker": "0.16.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@nestjs/common": "11.1.
|
|
60
|
-
"@nestjs/core": "11.1.
|
|
61
|
-
"@nestjs/testing": "11.1.
|
|
59
|
+
"@nestjs/common": "11.1.13",
|
|
60
|
+
"@nestjs/core": "11.1.13",
|
|
61
|
+
"@nestjs/testing": "11.1.13",
|
|
62
62
|
"@swan-io/boxed": "3.2.1",
|
|
63
|
-
"@types/node": "25.
|
|
64
|
-
"@vitest/coverage-v8": "4.0.
|
|
63
|
+
"@types/node": "25.2.1",
|
|
64
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
65
65
|
"amqp-connection-manager": "5.0.0",
|
|
66
66
|
"amqplib": "0.10.9",
|
|
67
67
|
"reflect-metadata": "0.2.2",
|
|
68
68
|
"rxjs": "7.8.2",
|
|
69
|
-
"tsdown": "0.
|
|
69
|
+
"tsdown": "0.20.3",
|
|
70
70
|
"typedoc": "0.28.16",
|
|
71
71
|
"typedoc-plugin-markdown": "4.9.0",
|
|
72
72
|
"typescript": "5.9.3",
|
|
73
|
-
"vitest": "4.0.
|
|
74
|
-
"zod": "4.3.
|
|
75
|
-
"@amqp-contract/testing": "0.
|
|
73
|
+
"vitest": "4.0.18",
|
|
74
|
+
"zod": "4.3.6",
|
|
75
|
+
"@amqp-contract/testing": "0.16.0",
|
|
76
76
|
"@amqp-contract/tsconfig": "0.1.0",
|
|
77
77
|
"@amqp-contract/typedoc": "0.1.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@nestjs/common": "
|
|
81
|
-
"@nestjs/core": "
|
|
80
|
+
"@nestjs/common": ">=11.0.0",
|
|
81
|
+
"@nestjs/core": ">=11.0.0",
|
|
82
82
|
"reflect-metadata": ">=0.1.13",
|
|
83
83
|
"rxjs": ">=7.0.0"
|
|
84
84
|
},
|