@amqp-contract/worker 0.19.0 → 0.21.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/README.md +6 -7
- package/dist/index.cjs +161 -134
- package/dist/index.d.cts +62 -53
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +60 -51
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +155 -127
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +75 -64
- package/package.json +29 -29
package/docs/index.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
### MessageValidationError
|
|
10
10
|
|
|
11
|
-
Defined in: packages/core/dist/index.d.mts:
|
|
11
|
+
Defined in: packages/core/dist/index.d.mts:27
|
|
12
12
|
|
|
13
13
|
Error thrown when message validation fails (payload or headers).
|
|
14
14
|
|
|
@@ -35,7 +35,7 @@ The validation issues from the Standard Schema validation
|
|
|
35
35
|
new MessageValidationError(source, issues): MessageValidationError;
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Defined in: packages/core/dist/index.d.mts:
|
|
38
|
+
Defined in: packages/core/dist/index.d.mts:30
|
|
39
39
|
|
|
40
40
|
###### Parameters
|
|
41
41
|
|
|
@@ -58,13 +58,13 @@ Error.constructor
|
|
|
58
58
|
|
|
59
59
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
60
60
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
61
|
-
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@
|
|
62
|
-
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | packages/core/dist/index.d.mts:
|
|
63
|
-
| <a id="message"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@
|
|
64
|
-
| <a id="name"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@
|
|
65
|
-
| <a id="source"></a> `source` | `readonly` | `string` | - | - | packages/core/dist/index.d.mts:
|
|
66
|
-
| <a id="stack"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@
|
|
67
|
-
| <a id="stacktracelimit"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@
|
|
61
|
+
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
|
|
62
|
+
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | packages/core/dist/index.d.mts:29 |
|
|
63
|
+
| <a id="message"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
64
|
+
| <a id="name"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
65
|
+
| <a id="source"></a> `source` | `readonly` | `string` | - | - | packages/core/dist/index.d.mts:28 |
|
|
66
|
+
| <a id="stack"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
67
|
+
| <a id="stacktracelimit"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
68
68
|
|
|
69
69
|
#### Methods
|
|
70
70
|
|
|
@@ -74,7 +74,7 @@ Error.constructor
|
|
|
74
74
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Defined in: node\_modules/.pnpm/@types+node@
|
|
77
|
+
Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:52
|
|
78
78
|
|
|
79
79
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
80
80
|
a string representing the location in the code at which
|
|
@@ -143,7 +143,7 @@ Error.captureStackTrace
|
|
|
143
143
|
static prepareStackTrace(err, stackTraces): any;
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
Defined in: node\_modules/.pnpm/@types+node@
|
|
146
|
+
Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:56
|
|
147
147
|
|
|
148
148
|
###### Parameters
|
|
149
149
|
|
|
@@ -170,7 +170,7 @@ Error.prepareStackTrace
|
|
|
170
170
|
|
|
171
171
|
### NonRetryableError
|
|
172
172
|
|
|
173
|
-
Defined in: [packages/worker/src/errors.ts:34](https://github.com/btravers/amqp-contract/blob/
|
|
173
|
+
Defined in: [packages/worker/src/errors.ts:34](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L34)
|
|
174
174
|
|
|
175
175
|
Non-retryable errors - permanent failures that should not be retried
|
|
176
176
|
Examples: invalid data, business rule violations, permanent external failures
|
|
@@ -190,7 +190,7 @@ immediately sent to the dead letter queue (DLQ) if configured.
|
|
|
190
190
|
new NonRetryableError(message, cause?): NonRetryableError;
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
-
Defined in: [packages/worker/src/errors.ts:35](https://github.com/btravers/amqp-contract/blob/
|
|
193
|
+
Defined in: [packages/worker/src/errors.ts:35](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L35)
|
|
194
194
|
|
|
195
195
|
###### Parameters
|
|
196
196
|
|
|
@@ -213,11 +213,11 @@ Error.constructor
|
|
|
213
213
|
|
|
214
214
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
215
215
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
216
|
-
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:37](https://github.com/btravers/amqp-contract/blob/
|
|
217
|
-
| <a id="message-1"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@
|
|
218
|
-
| <a id="name-1"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@
|
|
219
|
-
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@
|
|
220
|
-
| <a id="stacktracelimit-1"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@
|
|
216
|
+
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:37](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L37) |
|
|
217
|
+
| <a id="message-1"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
218
|
+
| <a id="name-1"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
219
|
+
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
220
|
+
| <a id="stacktracelimit-1"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
221
221
|
|
|
222
222
|
#### Methods
|
|
223
223
|
|
|
@@ -227,7 +227,7 @@ Error.constructor
|
|
|
227
227
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
228
228
|
```
|
|
229
229
|
|
|
230
|
-
Defined in: node\_modules/.pnpm/@types+node@
|
|
230
|
+
Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:52
|
|
231
231
|
|
|
232
232
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
233
233
|
a string representing the location in the code at which
|
|
@@ -296,7 +296,7 @@ Error.captureStackTrace
|
|
|
296
296
|
static prepareStackTrace(err, stackTraces): any;
|
|
297
297
|
```
|
|
298
298
|
|
|
299
|
-
Defined in: node\_modules/.pnpm/@types+node@
|
|
299
|
+
Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:56
|
|
300
300
|
|
|
301
301
|
###### Parameters
|
|
302
302
|
|
|
@@ -323,7 +323,7 @@ Error.prepareStackTrace
|
|
|
323
323
|
|
|
324
324
|
### RetryableError
|
|
325
325
|
|
|
326
|
-
Defined in: [packages/worker/src/errors.ts:10](https://github.com/btravers/amqp-contract/blob/
|
|
326
|
+
Defined in: [packages/worker/src/errors.ts:10](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L10)
|
|
327
327
|
|
|
328
328
|
Retryable errors - transient failures that may succeed on retry
|
|
329
329
|
Examples: network timeouts, rate limiting, temporary service unavailability
|
|
@@ -343,7 +343,7 @@ The worker will apply exponential backoff and retry the message.
|
|
|
343
343
|
new RetryableError(message, cause?): RetryableError;
|
|
344
344
|
```
|
|
345
345
|
|
|
346
|
-
Defined in: [packages/worker/src/errors.ts:11](https://github.com/btravers/amqp-contract/blob/
|
|
346
|
+
Defined in: [packages/worker/src/errors.ts:11](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L11)
|
|
347
347
|
|
|
348
348
|
###### Parameters
|
|
349
349
|
|
|
@@ -366,11 +366,11 @@ Error.constructor
|
|
|
366
366
|
|
|
367
367
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
368
368
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
369
|
-
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:13](https://github.com/btravers/amqp-contract/blob/
|
|
370
|
-
| <a id="message-2"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@
|
|
371
|
-
| <a id="name-2"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@
|
|
372
|
-
| <a id="stack-2"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@
|
|
373
|
-
| <a id="stacktracelimit-2"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@
|
|
369
|
+
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:13](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L13) |
|
|
370
|
+
| <a id="message-2"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
371
|
+
| <a id="name-2"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
372
|
+
| <a id="stack-2"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
373
|
+
| <a id="stacktracelimit-2"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
374
374
|
|
|
375
375
|
#### Methods
|
|
376
376
|
|
|
@@ -380,7 +380,7 @@ Error.constructor
|
|
|
380
380
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
381
381
|
```
|
|
382
382
|
|
|
383
|
-
Defined in: node\_modules/.pnpm/@types+node@
|
|
383
|
+
Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:52
|
|
384
384
|
|
|
385
385
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
386
386
|
a string representing the location in the code at which
|
|
@@ -449,7 +449,7 @@ Error.captureStackTrace
|
|
|
449
449
|
static prepareStackTrace(err, stackTraces): any;
|
|
450
450
|
```
|
|
451
451
|
|
|
452
|
-
Defined in: node\_modules/.pnpm/@types+node@
|
|
452
|
+
Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:56
|
|
453
453
|
|
|
454
454
|
###### Parameters
|
|
455
455
|
|
|
@@ -476,7 +476,7 @@ Error.prepareStackTrace
|
|
|
476
476
|
|
|
477
477
|
### TypedAmqpWorker
|
|
478
478
|
|
|
479
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
479
|
+
Defined in: [packages/worker/src/worker.ts:153](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L153)
|
|
480
480
|
|
|
481
481
|
Type-safe AMQP worker for consuming messages from RabbitMQ.
|
|
482
482
|
|
|
@@ -490,7 +490,7 @@ import { TypedAmqpWorker } from '@amqp-contract/worker';
|
|
|
490
490
|
import { defineQueue, defineMessage, defineContract, defineConsumer } from '@amqp-contract/contract';
|
|
491
491
|
import { z } from 'zod';
|
|
492
492
|
|
|
493
|
-
const orderQueue = defineQueue('order-processing'
|
|
493
|
+
const orderQueue = defineQueue('order-processing');
|
|
494
494
|
const orderMessage = defineMessage(z.object({
|
|
495
495
|
orderId: z.string(),
|
|
496
496
|
amount: z.number()
|
|
@@ -531,7 +531,7 @@ await worker.close().resultToPromise();
|
|
|
531
531
|
close(): Future<Result<void, TechnicalError>>;
|
|
532
532
|
```
|
|
533
533
|
|
|
534
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
534
|
+
Defined in: [packages/worker/src/worker.ts:280](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L280)
|
|
535
535
|
|
|
536
536
|
Close the AMQP channel and connection.
|
|
537
537
|
|
|
@@ -559,7 +559,7 @@ if (closeResult.isOk()) {
|
|
|
559
559
|
static create<TContract>(options): Future<Result<TypedAmqpWorker<TContract>, TechnicalError>>;
|
|
560
560
|
```
|
|
561
561
|
|
|
562
|
-
Defined in: [packages/worker/src/worker.ts:235](https://github.com/btravers/amqp-contract/blob/
|
|
562
|
+
Defined in: [packages/worker/src/worker.ts:235](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L235)
|
|
563
563
|
|
|
564
564
|
Create a type-safe AMQP worker from a contract.
|
|
565
565
|
|
|
@@ -603,13 +603,23 @@ const worker = await TypedAmqpWorker.create({
|
|
|
603
603
|
|
|
604
604
|
## Type Aliases
|
|
605
605
|
|
|
606
|
+
### ConsumerOptions
|
|
607
|
+
|
|
608
|
+
```ts
|
|
609
|
+
type ConsumerOptions = AmqpClientConsumerOptions;
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
Defined in: [packages/worker/src/worker.ts:37](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L37)
|
|
613
|
+
|
|
614
|
+
***
|
|
615
|
+
|
|
606
616
|
### CreateWorkerOptions
|
|
607
617
|
|
|
608
618
|
```ts
|
|
609
619
|
type CreateWorkerOptions<TContract> = object;
|
|
610
620
|
```
|
|
611
621
|
|
|
612
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
622
|
+
Defined in: [packages/worker/src/worker.ts:84](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L84)
|
|
613
623
|
|
|
614
624
|
Options for creating a type-safe AMQP worker.
|
|
615
625
|
|
|
@@ -634,6 +644,9 @@ const options: CreateWorkerOptions<typeof contract> = {
|
|
|
634
644
|
]
|
|
635
645
|
},
|
|
636
646
|
urls: ['amqp://localhost'],
|
|
647
|
+
defaultConsumerOptions: {
|
|
648
|
+
prefetch: 5,
|
|
649
|
+
},
|
|
637
650
|
connectionOptions: {
|
|
638
651
|
heartbeatIntervalInSeconds: 30
|
|
639
652
|
},
|
|
@@ -654,12 +667,13 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
|
654
667
|
|
|
655
668
|
| Property | Type | Description | Defined in |
|
|
656
669
|
| ------ | ------ | ------ | ------ |
|
|
657
|
-
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:
|
|
658
|
-
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:
|
|
659
|
-
| <a id="
|
|
660
|
-
| <a id="
|
|
661
|
-
| <a id="
|
|
662
|
-
| <a id="
|
|
670
|
+
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:96](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L96) |
|
|
671
|
+
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:86](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L86) |
|
|
672
|
+
| <a id="defaultconsumeroptions"></a> `defaultConsumerOptions?` | [`ConsumerOptions`](#consumeroptions) | Optional default consumer options applied to all consumer handlers. Handler-specific options provided in tuple form override these defaults. | [packages/worker/src/worker.ts:109](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L109) |
|
|
673
|
+
| <a id="handlers"></a> `handlers` | [`WorkerInferConsumerHandlers`](#workerinferconsumerhandlers)<`TContract`> | Handlers for each consumer defined in the contract. Handlers must return `Future<Result<void, HandlerError>>` for explicit error handling. Use defineHandler() to create handlers. | [packages/worker/src/worker.ts:92](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L92) |
|
|
674
|
+
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:98](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L98) |
|
|
675
|
+
| <a id="telemetry"></a> `telemetry?` | `TelemetryProvider` | Optional telemetry provider for tracing and metrics. If not provided, uses the default provider which attempts to load OpenTelemetry. OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed. | [packages/worker/src/worker.ts:104](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L104) |
|
|
676
|
+
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:94](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/worker.ts#L94) |
|
|
663
677
|
|
|
664
678
|
***
|
|
665
679
|
|
|
@@ -671,7 +685,7 @@ type HandlerError =
|
|
|
671
685
|
| NonRetryableError;
|
|
672
686
|
```
|
|
673
687
|
|
|
674
|
-
Defined in: [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/
|
|
688
|
+
Defined in: [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L55)
|
|
675
689
|
|
|
676
690
|
Union type representing all handler errors.
|
|
677
691
|
Use this type when defining handlers that explicitly signal error outcomes.
|
|
@@ -684,7 +698,7 @@ Use this type when defining handlers that explicitly signal error outcomes.
|
|
|
684
698
|
type WorkerConsumedMessage<TPayload, THeaders> = object;
|
|
685
699
|
```
|
|
686
700
|
|
|
687
|
-
Defined in: [packages/worker/src/types.ts:
|
|
701
|
+
Defined in: [packages/worker/src/types.ts:105](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/types.ts#L105)
|
|
688
702
|
|
|
689
703
|
A consumed message containing parsed payload and headers.
|
|
690
704
|
|
|
@@ -714,8 +728,8 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
|
|
|
714
728
|
|
|
715
729
|
| Property | Type | Description | Defined in |
|
|
716
730
|
| ------ | ------ | ------ | ------ |
|
|
717
|
-
| <a id="headers"></a> `headers` | `THeaders` *extends* `undefined` ? `undefined` : `THeaders` | The validated message headers (present only when headers schema is defined) | [packages/worker/src/types.ts:
|
|
718
|
-
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:
|
|
731
|
+
| <a id="headers"></a> `headers` | `THeaders` *extends* `undefined` ? `undefined` : `THeaders` | The validated message headers (present only when headers schema is defined) | [packages/worker/src/types.ts:109](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/types.ts#L109) |
|
|
732
|
+
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:107](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/types.ts#L107) |
|
|
719
733
|
|
|
720
734
|
***
|
|
721
735
|
|
|
@@ -725,7 +739,7 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
|
|
|
725
739
|
type WorkerInferConsumedMessage<TContract, TName> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
|
|
726
740
|
```
|
|
727
741
|
|
|
728
|
-
Defined in: [packages/worker/src/types.ts:
|
|
742
|
+
Defined in: [packages/worker/src/types.ts:116](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/types.ts#L116)
|
|
729
743
|
|
|
730
744
|
Infer the full consumed message type for a specific consumer.
|
|
731
745
|
Includes both payload and headers (if defined).
|
|
@@ -739,13 +753,13 @@ Includes both payload and headers (if defined).
|
|
|
739
753
|
|
|
740
754
|
***
|
|
741
755
|
|
|
742
|
-
### WorkerInferConsumerHandler
|
|
756
|
+
### WorkerInferConsumerHandler
|
|
743
757
|
|
|
744
758
|
```ts
|
|
745
759
|
type WorkerInferConsumerHandler<TContract, TName> = (message, rawMessage) => Future<Result<void, HandlerError>>;
|
|
746
760
|
```
|
|
747
761
|
|
|
748
|
-
Defined in: [packages/worker/src/types.ts:
|
|
762
|
+
Defined in: [packages/worker/src/types.ts:155](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/types.ts#L155)
|
|
749
763
|
|
|
750
764
|
Consumer handler type for a specific consumer.
|
|
751
765
|
Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
|
|
@@ -793,12 +807,10 @@ const handler: WorkerInferConsumerHandler<typeof contract, 'processOrder'> =
|
|
|
793
807
|
```ts
|
|
794
808
|
type WorkerInferConsumerHandlerEntry<TContract, TName> =
|
|
795
809
|
| WorkerInferConsumerHandler<TContract, TName>
|
|
796
|
-
| readonly [WorkerInferConsumerHandler<TContract, TName>,
|
|
797
|
-
prefetch?: number;
|
|
798
|
-
}];
|
|
810
|
+
| readonly [WorkerInferConsumerHandler<TContract, TName>, ConsumerOptions];
|
|
799
811
|
```
|
|
800
812
|
|
|
801
|
-
Defined in: [packages/worker/src/types.ts:
|
|
813
|
+
Defined in: [packages/worker/src/types.ts:173](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/types.ts#L173)
|
|
802
814
|
|
|
803
815
|
Handler entry for a consumer - either a function or a tuple of [handler, options].
|
|
804
816
|
|
|
@@ -824,7 +836,7 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
|
824
836
|
type WorkerInferConsumerHandlers<TContract> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> };
|
|
825
837
|
```
|
|
826
838
|
|
|
827
|
-
Defined in: [packages/worker/src/types.ts:
|
|
839
|
+
Defined in: [packages/worker/src/types.ts:194](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/types.ts#L194)
|
|
828
840
|
|
|
829
841
|
Consumer handlers for a contract.
|
|
830
842
|
All handlers return `Future<Result<void, HandlerError>>` for explicit error control.
|
|
@@ -851,10 +863,10 @@ const handlers: WorkerInferConsumerHandlers<typeof contract> = {
|
|
|
851
863
|
### WorkerInferConsumerHeaders
|
|
852
864
|
|
|
853
865
|
```ts
|
|
854
|
-
type WorkerInferConsumerHeaders<TContract, TName> =
|
|
866
|
+
type WorkerInferConsumerHeaders<TContract, TName> = ConsumerInferHeadersOutput<InferConsumer<TContract, TName>>;
|
|
855
867
|
```
|
|
856
868
|
|
|
857
|
-
Defined in: [packages/worker/src/types.ts:
|
|
869
|
+
Defined in: [packages/worker/src/types.ts:80](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/types.ts#L80)
|
|
858
870
|
|
|
859
871
|
Infer the headers type for a specific consumer
|
|
860
872
|
Returns undefined if no headers schema is defined
|
|
@@ -879,7 +891,7 @@ function defineHandler<TContract, TName>(
|
|
|
879
891
|
handler): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
880
892
|
```
|
|
881
893
|
|
|
882
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
894
|
+
Defined in: [packages/worker/src/handlers.ts:104](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/handlers.ts#L104)
|
|
883
895
|
|
|
884
896
|
Define a type-safe handler for a specific consumer in a contract.
|
|
885
897
|
|
|
@@ -952,7 +964,7 @@ function defineHandler<TContract, TName>(
|
|
|
952
964
|
options): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
953
965
|
```
|
|
954
966
|
|
|
955
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
967
|
+
Defined in: [packages/worker/src/handlers.ts:112](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/handlers.ts#L112)
|
|
956
968
|
|
|
957
969
|
Define a type-safe handler for a specific consumer in a contract.
|
|
958
970
|
|
|
@@ -977,8 +989,7 @@ Supports two patterns:
|
|
|
977
989
|
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
978
990
|
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
979
991
|
| `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)<`TContract`, `TName`> | The handler function that returns `Future<Result<void, HandlerError>>` |
|
|
980
|
-
| `options` |
|
|
981
|
-
| `options.prefetch?` | `number` | - |
|
|
992
|
+
| `options` | `ConsumerOptions` | Optional consumer options (prefetch) |
|
|
982
993
|
|
|
983
994
|
##### Returns
|
|
984
995
|
|
|
@@ -1025,7 +1036,7 @@ const validateOrderHandler = defineHandler(
|
|
|
1025
1036
|
function defineHandlers<TContract>(contract, handlers): WorkerInferConsumerHandlers<TContract>;
|
|
1026
1037
|
```
|
|
1027
1038
|
|
|
1028
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
1039
|
+
Defined in: [packages/worker/src/handlers.ts:167](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/handlers.ts#L167)
|
|
1029
1040
|
|
|
1030
1041
|
Define multiple type-safe handlers for consumers in a contract.
|
|
1031
1042
|
|
|
@@ -1078,7 +1089,7 @@ const handlers = defineHandlers(orderContract, {
|
|
|
1078
1089
|
function isHandlerError(error): error is HandlerError;
|
|
1079
1090
|
```
|
|
1080
1091
|
|
|
1081
|
-
Defined in: [packages/worker/src/errors.ts:131](https://github.com/btravers/amqp-contract/blob/
|
|
1092
|
+
Defined in: [packages/worker/src/errors.ts:131](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L131)
|
|
1082
1093
|
|
|
1083
1094
|
Type guard to check if an error is any HandlerError (RetryableError or NonRetryableError).
|
|
1084
1095
|
|
|
@@ -1115,7 +1126,7 @@ function handleError(error: unknown) {
|
|
|
1115
1126
|
function isNonRetryableError(error): error is NonRetryableError;
|
|
1116
1127
|
```
|
|
1117
1128
|
|
|
1118
|
-
Defined in: [packages/worker/src/errors.ts:109](https://github.com/btravers/amqp-contract/blob/
|
|
1129
|
+
Defined in: [packages/worker/src/errors.ts:109](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L109)
|
|
1119
1130
|
|
|
1120
1131
|
Type guard to check if an error is a NonRetryableError.
|
|
1121
1132
|
|
|
@@ -1155,7 +1166,7 @@ try {
|
|
|
1155
1166
|
function isRetryableError(error): error is RetryableError;
|
|
1156
1167
|
```
|
|
1157
1168
|
|
|
1158
|
-
Defined in: [packages/worker/src/errors.ts:84](https://github.com/btravers/amqp-contract/blob/
|
|
1169
|
+
Defined in: [packages/worker/src/errors.ts:84](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L84)
|
|
1159
1170
|
|
|
1160
1171
|
Type guard to check if an error is a RetryableError.
|
|
1161
1172
|
|
|
@@ -1197,7 +1208,7 @@ try {
|
|
|
1197
1208
|
function nonRetryable(message, cause?): NonRetryableError;
|
|
1198
1209
|
```
|
|
1199
1210
|
|
|
1200
|
-
Defined in: [packages/worker/src/errors.ts:193](https://github.com/btravers/amqp-contract/blob/
|
|
1211
|
+
Defined in: [packages/worker/src/errors.ts:193](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L193)
|
|
1201
1212
|
|
|
1202
1213
|
Create a NonRetryableError with less verbosity.
|
|
1203
1214
|
|
|
@@ -1242,7 +1253,7 @@ const handler = ({ payload }) => {
|
|
|
1242
1253
|
function retryable(message, cause?): RetryableError;
|
|
1243
1254
|
```
|
|
1244
1255
|
|
|
1245
|
-
Defined in: [packages/worker/src/errors.ts:163](https://github.com/btravers/amqp-contract/blob/
|
|
1256
|
+
Defined in: [packages/worker/src/errors.ts:163](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/worker/src/errors.ts#L163)
|
|
1246
1257
|
|
|
1247
1258
|
Create a RetryableError with less verbosity.
|
|
1248
1259
|
|
package/package.json
CHANGED
|
@@ -1,34 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amqp-contract/worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Worker utilities for consuming messages using amqp-contract",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"amqp",
|
|
7
|
+
"consumer",
|
|
7
8
|
"contract",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"worker",
|
|
11
|
-
"nodejs",
|
|
9
|
+
"message-broker",
|
|
10
|
+
"message-queue",
|
|
12
11
|
"messaging",
|
|
13
|
-
"
|
|
12
|
+
"nodejs",
|
|
13
|
+
"rabbitmq",
|
|
14
14
|
"schema",
|
|
15
|
+
"type-safe",
|
|
16
|
+
"typescript",
|
|
15
17
|
"validation",
|
|
16
|
-
"
|
|
17
|
-
"message-queue",
|
|
18
|
-
"consumer"
|
|
18
|
+
"worker"
|
|
19
19
|
],
|
|
20
20
|
"homepage": "https://github.com/btravers/amqp-contract#readme",
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/btravers/amqp-contract/issues"
|
|
23
23
|
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Benoit TRAVERS <benoit.travers.fr@gmail.com>",
|
|
24
26
|
"repository": {
|
|
25
27
|
"type": "git",
|
|
26
28
|
"url": "https://github.com/btravers/amqp-contract.git",
|
|
27
29
|
"directory": "packages/worker"
|
|
28
30
|
},
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"docs"
|
|
34
|
+
],
|
|
31
35
|
"type": "module",
|
|
36
|
+
"main": "./dist/index.cjs",
|
|
37
|
+
"module": "./dist/index.mjs",
|
|
38
|
+
"types": "./dist/index.d.mts",
|
|
32
39
|
"exports": {
|
|
33
40
|
".": {
|
|
34
41
|
"import": {
|
|
@@ -42,32 +49,25 @@
|
|
|
42
49
|
},
|
|
43
50
|
"./package.json": "./package.json"
|
|
44
51
|
},
|
|
45
|
-
"main": "./dist/index.cjs",
|
|
46
|
-
"module": "./dist/index.mjs",
|
|
47
|
-
"types": "./dist/index.d.mts",
|
|
48
|
-
"files": [
|
|
49
|
-
"dist",
|
|
50
|
-
"docs"
|
|
51
|
-
],
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@standard-schema/spec": "1.1.0",
|
|
54
54
|
"@swan-io/boxed": "3.2.1",
|
|
55
|
-
"@amqp-contract/contract": "0.
|
|
56
|
-
"@amqp-contract/core": "0.
|
|
55
|
+
"@amqp-contract/contract": "0.21.0",
|
|
56
|
+
"@amqp-contract/core": "0.21.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/amqplib": "0.10.8",
|
|
60
|
-
"@types/node": "
|
|
61
|
-
"@vitest/coverage-v8": "4.
|
|
60
|
+
"@types/node": "24.12.2",
|
|
61
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
62
62
|
"amqp-connection-manager": "5.0.0",
|
|
63
|
-
"amqplib": "0.
|
|
64
|
-
"tsdown": "0.
|
|
65
|
-
"typedoc": "0.28.
|
|
66
|
-
"typedoc-plugin-markdown": "4.
|
|
67
|
-
"typescript": "
|
|
68
|
-
"vitest": "4.
|
|
63
|
+
"amqplib": "1.0.3",
|
|
64
|
+
"tsdown": "0.21.9",
|
|
65
|
+
"typedoc": "0.28.19",
|
|
66
|
+
"typedoc-plugin-markdown": "4.11.0",
|
|
67
|
+
"typescript": "6.0.3",
|
|
68
|
+
"vitest": "4.1.5",
|
|
69
69
|
"zod": "4.3.6",
|
|
70
|
-
"@amqp-contract/testing": "0.
|
|
70
|
+
"@amqp-contract/testing": "0.21.0",
|
|
71
71
|
"@amqp-contract/tsconfig": "0.1.0",
|
|
72
72
|
"@amqp-contract/typedoc": "0.1.0"
|
|
73
73
|
},
|