@amqp-contract/worker-nestjs 0.3.1 → 0.3.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/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/docs/index.md +185 -14
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _nestjs_common0 from "@nestjs/common";
|
|
|
2
2
|
import { OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
3
3
|
import { ContractDefinition } from "@amqp-contract/contract";
|
|
4
4
|
import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
|
|
5
|
-
import { WorkerInferConsumerHandler, WorkerInferConsumerHandlers, WorkerInferConsumerHandlers as WorkerInferConsumerHandlers$1, WorkerInferConsumerInput } from "@amqp-contract/worker";
|
|
5
|
+
import { WorkerInferConsumerHandler, WorkerInferConsumerHandlers, WorkerInferConsumerHandlers as WorkerInferConsumerHandlers$1, WorkerInferConsumerInput, defineHandler, defineHandlers } from "@amqp-contract/worker";
|
|
6
6
|
|
|
7
7
|
//#region src/worker.service.d.ts
|
|
8
8
|
|
|
@@ -111,5 +111,5 @@ declare const ConfigurableModuleClass: _nestjs_common0.ConfigurableModuleCls<Amq
|
|
|
111
111
|
*/
|
|
112
112
|
declare class AmqpWorkerModule extends ConfigurableModuleClass {}
|
|
113
113
|
//#endregion
|
|
114
|
-
export { AmqpWorkerModule, type AmqpWorkerModuleOptions, AmqpWorkerService, MODULE_OPTIONS_TOKEN, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput };
|
|
114
|
+
export { AmqpWorkerModule, type AmqpWorkerModuleOptions, AmqpWorkerService, MODULE_OPTIONS_TOKEN, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput, type defineHandler, type defineHandlers };
|
|
115
115
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _nestjs_common0 from "@nestjs/common";
|
|
2
2
|
import { OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
3
|
-
import { WorkerInferConsumerHandler, WorkerInferConsumerHandlers, WorkerInferConsumerHandlers as WorkerInferConsumerHandlers$1, WorkerInferConsumerInput } from "@amqp-contract/worker";
|
|
3
|
+
import { WorkerInferConsumerHandler, WorkerInferConsumerHandlers, WorkerInferConsumerHandlers as WorkerInferConsumerHandlers$1, WorkerInferConsumerInput, defineHandler, defineHandlers } from "@amqp-contract/worker";
|
|
4
4
|
import { ContractDefinition } from "@amqp-contract/contract";
|
|
5
5
|
import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
|
|
6
6
|
|
|
@@ -111,5 +111,5 @@ declare const ConfigurableModuleClass: _nestjs_common0.ConfigurableModuleCls<Amq
|
|
|
111
111
|
*/
|
|
112
112
|
declare class AmqpWorkerModule extends ConfigurableModuleClass {}
|
|
113
113
|
//#endregion
|
|
114
|
-
export { AmqpWorkerModule, type AmqpWorkerModuleOptions, AmqpWorkerService, MODULE_OPTIONS_TOKEN, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput };
|
|
114
|
+
export { AmqpWorkerModule, type AmqpWorkerModuleOptions, AmqpWorkerService, MODULE_OPTIONS_TOKEN, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput, type defineHandler, type defineHandlers };
|
|
115
115
|
//# sourceMappingURL=index.d.mts.map
|
package/docs/index.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
### AmqpWorkerModule
|
|
10
10
|
|
|
11
|
-
Defined in: [packages/worker-nestjs/src/worker.module.ts:14](https://github.com/btravers/amqp-contract/blob/
|
|
11
|
+
Defined in: [packages/worker-nestjs/src/worker.module.ts:14](https://github.com/btravers/amqp-contract/blob/2e0e3a372088cd269fea97fb73812491d1fc5e14/packages/worker-nestjs/src/worker.module.ts#L14)
|
|
12
12
|
|
|
13
13
|
NestJS module for AMQP worker integration
|
|
14
14
|
This module provides type-safe AMQP worker functionality using @amqp-contract/worker
|
|
@@ -55,7 +55,7 @@ ConfigurableModuleClass.constructor
|
|
|
55
55
|
|
|
56
56
|
### AmqpWorkerService
|
|
57
57
|
|
|
58
|
-
Defined in: [packages/worker-nestjs/src/worker.service.ts:74](https://github.com/btravers/amqp-contract/blob/
|
|
58
|
+
Defined in: [packages/worker-nestjs/src/worker.service.ts:74](https://github.com/btravers/amqp-contract/blob/2e0e3a372088cd269fea97fb73812491d1fc5e14/packages/worker-nestjs/src/worker.service.ts#L74)
|
|
59
59
|
|
|
60
60
|
Type-safe AMQP worker service for NestJS applications.
|
|
61
61
|
|
|
@@ -108,7 +108,7 @@ export class AppModule {}
|
|
|
108
108
|
new AmqpWorkerService<TContract>(options): AmqpWorkerService<TContract>;
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
Defined in: [packages/worker-nestjs/src/worker.service.ts:79](https://github.com/btravers/amqp-contract/blob/
|
|
111
|
+
Defined in: [packages/worker-nestjs/src/worker.service.ts:79](https://github.com/btravers/amqp-contract/blob/2e0e3a372088cd269fea97fb73812491d1fc5e14/packages/worker-nestjs/src/worker.service.ts#L79)
|
|
112
112
|
|
|
113
113
|
###### Parameters
|
|
114
114
|
|
|
@@ -128,7 +128,7 @@ Defined in: [packages/worker-nestjs/src/worker.service.ts:79](https://github.com
|
|
|
128
128
|
onModuleDestroy(): Promise<void>;
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
Defined in: [packages/worker-nestjs/src/worker.service.ts:105](https://github.com/btravers/amqp-contract/blob/
|
|
131
|
+
Defined in: [packages/worker-nestjs/src/worker.service.ts:105](https://github.com/btravers/amqp-contract/blob/2e0e3a372088cd269fea97fb73812491d1fc5e14/packages/worker-nestjs/src/worker.service.ts#L105)
|
|
132
132
|
|
|
133
133
|
Close the AMQP worker when the NestJS module is destroyed.
|
|
134
134
|
|
|
@@ -152,7 +152,7 @@ OnModuleDestroy.onModuleDestroy
|
|
|
152
152
|
onModuleInit(): Promise<void>;
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
Defined in: [packages/worker-nestjs/src/worker.service.ts:94](https://github.com/btravers/amqp-contract/blob/
|
|
155
|
+
Defined in: [packages/worker-nestjs/src/worker.service.ts:94](https://github.com/btravers/amqp-contract/blob/2e0e3a372088cd269fea97fb73812491d1fc5e14/packages/worker-nestjs/src/worker.service.ts#L94)
|
|
156
156
|
|
|
157
157
|
Initialize the AMQP worker when the NestJS module starts.
|
|
158
158
|
|
|
@@ -179,7 +179,7 @@ OnModuleInit.onModuleInit
|
|
|
179
179
|
|
|
180
180
|
### AmqpWorkerModuleOptions
|
|
181
181
|
|
|
182
|
-
Defined in: [packages/worker-nestjs/src/worker.service.ts:28](https://github.com/btravers/amqp-contract/blob/
|
|
182
|
+
Defined in: [packages/worker-nestjs/src/worker.service.ts:28](https://github.com/btravers/amqp-contract/blob/2e0e3a372088cd269fea97fb73812491d1fc5e14/packages/worker-nestjs/src/worker.service.ts#L28)
|
|
183
183
|
|
|
184
184
|
Configuration options for the AMQP worker NestJS module.
|
|
185
185
|
|
|
@@ -210,20 +210,191 @@ const options: AmqpWorkerModuleOptions<typeof contract> = {
|
|
|
210
210
|
|
|
211
211
|
| Property | Type | Description | Defined in |
|
|
212
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/
|
|
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/
|
|
215
|
-
| <a id="handlers"></a> `handlers` | [`WorkerInferConsumerHandlers`](#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/
|
|
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/
|
|
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/2e0e3a372088cd269fea97fb73812491d1fc5e14/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/2e0e3a372088cd269fea97fb73812491d1fc5e14/packages/worker-nestjs/src/worker.service.ts#L30) |
|
|
215
|
+
| <a id="handlers"></a> `handlers` | [`WorkerInferConsumerHandlers`](#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/2e0e3a372088cd269fea97fb73812491d1fc5e14/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/2e0e3a372088cd269fea97fb73812491d1fc5e14/packages/worker-nestjs/src/worker.service.ts#L34) |
|
|
217
217
|
|
|
218
218
|
## Type Aliases
|
|
219
219
|
|
|
220
|
+
### defineHandler()
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
type defineHandler = <TContract, TName>(contract, consumerName, handler) => WorkerInferConsumerHandler<TContract, TName>;
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Defined in: packages/worker/dist/index.d.mts:273
|
|
227
|
+
|
|
228
|
+
Define a type-safe handler for a specific consumer in a contract.
|
|
229
|
+
|
|
230
|
+
This utility allows you to define handlers outside of the worker creation,
|
|
231
|
+
providing better code organization and reusability.
|
|
232
|
+
|
|
233
|
+
#### Type Parameters
|
|
234
|
+
|
|
235
|
+
| Type Parameter | Description |
|
|
236
|
+
| ------ | ------ |
|
|
237
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
238
|
+
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
239
|
+
|
|
240
|
+
#### Parameters
|
|
241
|
+
|
|
242
|
+
| Parameter | Type | Description |
|
|
243
|
+
| ------ | ------ | ------ |
|
|
244
|
+
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
245
|
+
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
246
|
+
| `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)\<`TContract`, `TName`\> | The async handler function that processes messages |
|
|
247
|
+
|
|
248
|
+
#### Returns
|
|
249
|
+
|
|
250
|
+
[`WorkerInferConsumerHandler`](#workerinferconsumerhandler)\<`TContract`, `TName`\>
|
|
251
|
+
|
|
252
|
+
A type-safe handler that can be used with TypedAmqpWorker
|
|
253
|
+
|
|
254
|
+
#### Examples
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { defineHandler } from '@amqp-contract/worker';
|
|
258
|
+
import { orderContract } from './contract';
|
|
259
|
+
|
|
260
|
+
// Define handler outside of worker creation
|
|
261
|
+
const processOrderHandler = defineHandler(
|
|
262
|
+
orderContract,
|
|
263
|
+
'processOrder',
|
|
264
|
+
async (message) => {
|
|
265
|
+
// message is fully typed based on the contract
|
|
266
|
+
console.log('Processing order:', message.orderId);
|
|
267
|
+
await processPayment(message);
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
// Use the handler in worker
|
|
272
|
+
const worker = await TypedAmqpWorker.create({
|
|
273
|
+
contract: orderContract,
|
|
274
|
+
handlers: {
|
|
275
|
+
processOrder: processOrderHandler,
|
|
276
|
+
},
|
|
277
|
+
connection: 'amqp://localhost',
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
// Define multiple handlers
|
|
283
|
+
const processOrderHandler = defineHandler(
|
|
284
|
+
orderContract,
|
|
285
|
+
'processOrder',
|
|
286
|
+
async (message) => {
|
|
287
|
+
await processOrder(message);
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
const notifyOrderHandler = defineHandler(
|
|
292
|
+
orderContract,
|
|
293
|
+
'notifyOrder',
|
|
294
|
+
async (message) => {
|
|
295
|
+
await sendNotification(message);
|
|
296
|
+
}
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// Compose handlers
|
|
300
|
+
const worker = await TypedAmqpWorker.create({
|
|
301
|
+
contract: orderContract,
|
|
302
|
+
handlers: {
|
|
303
|
+
processOrder: processOrderHandler,
|
|
304
|
+
notifyOrder: notifyOrderHandler,
|
|
305
|
+
},
|
|
306
|
+
connection: 'amqp://localhost',
|
|
307
|
+
});
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
***
|
|
311
|
+
|
|
312
|
+
### defineHandlers()
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
type defineHandlers = <TContract>(contract, handlers) => WorkerInferConsumerHandlers<TContract>;
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Defined in: packages/worker/dist/index.d.mts:330
|
|
319
|
+
|
|
320
|
+
Define multiple type-safe handlers for consumers in a contract.
|
|
321
|
+
|
|
322
|
+
This utility allows you to define all handlers at once outside of the worker creation,
|
|
323
|
+
ensuring type safety and providing better code organization.
|
|
324
|
+
|
|
325
|
+
#### Type Parameters
|
|
326
|
+
|
|
327
|
+
| Type Parameter | Description |
|
|
328
|
+
| ------ | ------ |
|
|
329
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
330
|
+
|
|
331
|
+
#### Parameters
|
|
332
|
+
|
|
333
|
+
| Parameter | Type | Description |
|
|
334
|
+
| ------ | ------ | ------ |
|
|
335
|
+
| `contract` | `TContract` | The contract definition containing the consumers |
|
|
336
|
+
| `handlers` | [`WorkerInferConsumerHandlers`](#workerinferconsumerhandlers)\<`TContract`\> | An object with async handler functions for each consumer |
|
|
337
|
+
|
|
338
|
+
#### Returns
|
|
339
|
+
|
|
340
|
+
[`WorkerInferConsumerHandlers`](#workerinferconsumerhandlers)\<`TContract`\>
|
|
341
|
+
|
|
342
|
+
A type-safe handlers object that can be used with TypedAmqpWorker
|
|
343
|
+
|
|
344
|
+
#### Examples
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
import { defineHandlers } from '@amqp-contract/worker';
|
|
348
|
+
import { orderContract } from './contract';
|
|
349
|
+
|
|
350
|
+
// Define all handlers at once
|
|
351
|
+
const handlers = defineHandlers(orderContract, {
|
|
352
|
+
processOrder: async (message) => {
|
|
353
|
+
// message is fully typed based on the contract
|
|
354
|
+
console.log('Processing order:', message.orderId);
|
|
355
|
+
await processPayment(message);
|
|
356
|
+
},
|
|
357
|
+
notifyOrder: async (message) => {
|
|
358
|
+
await sendNotification(message);
|
|
359
|
+
},
|
|
360
|
+
shipOrder: async (message) => {
|
|
361
|
+
await prepareShipment(message);
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// Use the handlers in worker
|
|
366
|
+
const worker = await TypedAmqpWorker.create({
|
|
367
|
+
contract: orderContract,
|
|
368
|
+
handlers,
|
|
369
|
+
connection: 'amqp://localhost',
|
|
370
|
+
});
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
// Separate handler definitions for better organization
|
|
375
|
+
async function handleProcessOrder(message: WorkerInferConsumerInput<typeof orderContract, 'processOrder'>) {
|
|
376
|
+
await processOrder(message);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function handleNotifyOrder(message: WorkerInferConsumerInput<typeof orderContract, 'notifyOrder'>) {
|
|
380
|
+
await sendNotification(message);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const handlers = defineHandlers(orderContract, {
|
|
384
|
+
processOrder: handleProcessOrder,
|
|
385
|
+
notifyOrder: handleNotifyOrder,
|
|
386
|
+
});
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
***
|
|
390
|
+
|
|
220
391
|
### WorkerInferConsumerHandler()
|
|
221
392
|
|
|
222
393
|
```ts
|
|
223
394
|
type WorkerInferConsumerHandler<TContract, TName> = (message) => Promise<void>;
|
|
224
395
|
```
|
|
225
396
|
|
|
226
|
-
Defined in: packages/worker/dist/index.d.mts:
|
|
397
|
+
Defined in: packages/worker/dist/index.d.mts:55
|
|
227
398
|
|
|
228
399
|
Infer consumer handler type for a specific consumer
|
|
229
400
|
|
|
@@ -252,7 +423,7 @@ Infer consumer handler type for a specific consumer
|
|
|
252
423
|
type WorkerInferConsumerHandlers<TContract> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandler<TContract, K> };
|
|
253
424
|
```
|
|
254
425
|
|
|
255
|
-
Defined in: packages/worker/dist/index.d.mts:
|
|
426
|
+
Defined in: packages/worker/dist/index.d.mts:59
|
|
256
427
|
|
|
257
428
|
Infer all consumer handlers for a contract
|
|
258
429
|
|
|
@@ -270,7 +441,7 @@ Infer all consumer handlers for a contract
|
|
|
270
441
|
type WorkerInferConsumerInput<TContract, TName> = ConsumerInferInput<InferConsumer<TContract, TName>>;
|
|
271
442
|
```
|
|
272
443
|
|
|
273
|
-
Defined in: packages/worker/dist/index.d.mts:
|
|
444
|
+
Defined in: packages/worker/dist/index.d.mts:51
|
|
274
445
|
|
|
275
446
|
Worker perspective types - for consuming messages
|
|
276
447
|
|
|
@@ -289,4 +460,4 @@ Worker perspective types - for consuming messages
|
|
|
289
460
|
MODULE_OPTIONS_TOKEN: string | symbol;
|
|
290
461
|
```
|
|
291
462
|
|
|
292
|
-
Defined in: [packages/worker-nestjs/src/worker.module-definition.ts:9](https://github.com/btravers/amqp-contract/blob/
|
|
463
|
+
Defined in: [packages/worker-nestjs/src/worker.module-definition.ts:9](https://github.com/btravers/amqp-contract/blob/2e0e3a372088cd269fea97fb73812491d1fc5e14/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.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "NestJS integration for @amqp-contract/worker",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"amqp",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"docs"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@amqp-contract/contract": "0.3.
|
|
47
|
-
"@amqp-contract/worker": "0.3.
|
|
46
|
+
"@amqp-contract/contract": "0.3.2",
|
|
47
|
+
"@amqp-contract/worker": "0.3.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@nestjs/common": "11.1.10",
|