@amqp-contract/worker 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/README.md +1 -1
- package/dist/index.cjs +9 -7
- package/dist/index.d.cts +78 -40
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +77 -39
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +8 -7
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +71 -70
- package/package.json +9 -9
package/docs/index.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
### MessageValidationError
|
|
10
10
|
|
|
11
|
-
Defined in: [packages/worker/src/errors.ts:4](https://github.com/btravers/amqp-contract/blob/
|
|
11
|
+
Defined in: [packages/worker/src/errors.ts:4](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L4)
|
|
12
12
|
|
|
13
13
|
Error thrown when message validation fails
|
|
14
14
|
|
|
@@ -24,7 +24,7 @@ Error thrown when message validation fails
|
|
|
24
24
|
new MessageValidationError(consumerName, issues): MessageValidationError;
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Defined in: [packages/worker/src/errors.ts:5](https://github.com/btravers/amqp-contract/blob/
|
|
27
|
+
Defined in: [packages/worker/src/errors.ts:5](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L5)
|
|
28
28
|
|
|
29
29
|
###### Parameters
|
|
30
30
|
|
|
@@ -48,12 +48,12 @@ Error.constructor
|
|
|
48
48
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
49
49
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
50
50
|
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:26 |
|
|
51
|
-
| <a id="consumername"></a> `consumerName` | `readonly` | `string` | - | - | [packages/worker/src/errors.ts:6](https://github.com/btravers/amqp-contract/blob/
|
|
52
|
-
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | [packages/worker/src/errors.ts:7](https://github.com/btravers/amqp-contract/blob/
|
|
51
|
+
| <a id="consumername"></a> `consumerName` | `readonly` | `string` | - | - | [packages/worker/src/errors.ts:6](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L6) |
|
|
52
|
+
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | [packages/worker/src/errors.ts:7](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L7) |
|
|
53
53
|
| <a id="message"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
54
54
|
| <a id="name"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
55
55
|
| <a id="stack"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
56
|
-
| <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@25.
|
|
56
|
+
| <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@25.2.1/node\_modules/@types/node/globals.d.ts:67 |
|
|
57
57
|
|
|
58
58
|
#### Methods
|
|
59
59
|
|
|
@@ -63,7 +63,7 @@ Error.constructor
|
|
|
63
63
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
Defined in: node\_modules/.pnpm/@types+node@25.
|
|
66
|
+
Defined in: node\_modules/.pnpm/@types+node@25.2.1/node\_modules/@types/node/globals.d.ts:51
|
|
67
67
|
|
|
68
68
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
69
69
|
a string representing the location in the code at which
|
|
@@ -132,7 +132,7 @@ Error.captureStackTrace
|
|
|
132
132
|
static prepareStackTrace(err, stackTraces): any;
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
Defined in: node\_modules/.pnpm/@types+node@25.
|
|
135
|
+
Defined in: node\_modules/.pnpm/@types+node@25.2.1/node\_modules/@types/node/globals.d.ts:55
|
|
136
136
|
|
|
137
137
|
###### Parameters
|
|
138
138
|
|
|
@@ -159,7 +159,7 @@ Error.prepareStackTrace
|
|
|
159
159
|
|
|
160
160
|
### NonRetryableError
|
|
161
161
|
|
|
162
|
-
Defined in: [packages/worker/src/errors.ts:52](https://github.com/btravers/amqp-contract/blob/
|
|
162
|
+
Defined in: [packages/worker/src/errors.ts:52](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L52)
|
|
163
163
|
|
|
164
164
|
Non-retryable errors - permanent failures that should not be retried
|
|
165
165
|
Examples: invalid data, business rule violations, permanent external failures
|
|
@@ -179,7 +179,7 @@ immediately sent to the dead letter queue (DLQ) if configured.
|
|
|
179
179
|
new NonRetryableError(message, cause?): NonRetryableError;
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
-
Defined in: [packages/worker/src/errors.ts:53](https://github.com/btravers/amqp-contract/blob/
|
|
182
|
+
Defined in: [packages/worker/src/errors.ts:53](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L53)
|
|
183
183
|
|
|
184
184
|
###### Parameters
|
|
185
185
|
|
|
@@ -202,11 +202,11 @@ Error.constructor
|
|
|
202
202
|
|
|
203
203
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
204
204
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
205
|
-
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/
|
|
205
|
+
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L55) |
|
|
206
206
|
| <a id="message-1"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
207
207
|
| <a id="name-1"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
208
208
|
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
209
|
-
| <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@25.
|
|
209
|
+
| <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@25.2.1/node\_modules/@types/node/globals.d.ts:67 |
|
|
210
210
|
|
|
211
211
|
#### Methods
|
|
212
212
|
|
|
@@ -216,7 +216,7 @@ Error.constructor
|
|
|
216
216
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
-
Defined in: node\_modules/.pnpm/@types+node@25.
|
|
219
|
+
Defined in: node\_modules/.pnpm/@types+node@25.2.1/node\_modules/@types/node/globals.d.ts:51
|
|
220
220
|
|
|
221
221
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
222
222
|
a string representing the location in the code at which
|
|
@@ -285,7 +285,7 @@ Error.captureStackTrace
|
|
|
285
285
|
static prepareStackTrace(err, stackTraces): any;
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
-
Defined in: node\_modules/.pnpm/@types+node@25.
|
|
288
|
+
Defined in: node\_modules/.pnpm/@types+node@25.2.1/node\_modules/@types/node/globals.d.ts:55
|
|
289
289
|
|
|
290
290
|
###### Parameters
|
|
291
291
|
|
|
@@ -312,7 +312,7 @@ Error.prepareStackTrace
|
|
|
312
312
|
|
|
313
313
|
### RetryableError
|
|
314
314
|
|
|
315
|
-
Defined in: [packages/worker/src/errors.ts:28](https://github.com/btravers/amqp-contract/blob/
|
|
315
|
+
Defined in: [packages/worker/src/errors.ts:28](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L28)
|
|
316
316
|
|
|
317
317
|
Retryable errors - transient failures that may succeed on retry
|
|
318
318
|
Examples: network timeouts, rate limiting, temporary service unavailability
|
|
@@ -332,7 +332,7 @@ The worker will apply exponential backoff and retry the message.
|
|
|
332
332
|
new RetryableError(message, cause?): RetryableError;
|
|
333
333
|
```
|
|
334
334
|
|
|
335
|
-
Defined in: [packages/worker/src/errors.ts:29](https://github.com/btravers/amqp-contract/blob/
|
|
335
|
+
Defined in: [packages/worker/src/errors.ts:29](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L29)
|
|
336
336
|
|
|
337
337
|
###### Parameters
|
|
338
338
|
|
|
@@ -355,11 +355,11 @@ Error.constructor
|
|
|
355
355
|
|
|
356
356
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
357
357
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
358
|
-
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:31](https://github.com/btravers/amqp-contract/blob/
|
|
358
|
+
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:31](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L31) |
|
|
359
359
|
| <a id="message-2"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
360
360
|
| <a id="name-2"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
361
361
|
| <a id="stack-2"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
362
|
-
| <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@25.
|
|
362
|
+
| <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@25.2.1/node\_modules/@types/node/globals.d.ts:67 |
|
|
363
363
|
|
|
364
364
|
#### Methods
|
|
365
365
|
|
|
@@ -369,7 +369,7 @@ Error.constructor
|
|
|
369
369
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
370
370
|
```
|
|
371
371
|
|
|
372
|
-
Defined in: node\_modules/.pnpm/@types+node@25.
|
|
372
|
+
Defined in: node\_modules/.pnpm/@types+node@25.2.1/node\_modules/@types/node/globals.d.ts:51
|
|
373
373
|
|
|
374
374
|
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
375
375
|
a string representing the location in the code at which
|
|
@@ -438,7 +438,7 @@ Error.captureStackTrace
|
|
|
438
438
|
static prepareStackTrace(err, stackTraces): any;
|
|
439
439
|
```
|
|
440
440
|
|
|
441
|
-
Defined in: node\_modules/.pnpm/@types+node@25.
|
|
441
|
+
Defined in: node\_modules/.pnpm/@types+node@25.2.1/node\_modules/@types/node/globals.d.ts:55
|
|
442
442
|
|
|
443
443
|
###### Parameters
|
|
444
444
|
|
|
@@ -465,7 +465,7 @@ Error.prepareStackTrace
|
|
|
465
465
|
|
|
466
466
|
### TypedAmqpWorker
|
|
467
467
|
|
|
468
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
468
|
+
Defined in: [packages/worker/src/worker.ts:158](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L158)
|
|
469
469
|
|
|
470
470
|
Type-safe AMQP worker for consuming messages from RabbitMQ.
|
|
471
471
|
|
|
@@ -476,17 +476,18 @@ and error handling for consuming messages based on a contract definition.
|
|
|
476
476
|
|
|
477
477
|
```typescript
|
|
478
478
|
import { TypedAmqpWorker } from '@amqp-contract/worker';
|
|
479
|
+
import { defineQueue, defineMessage, defineContract, defineConsumer } from '@amqp-contract/contract';
|
|
479
480
|
import { z } from 'zod';
|
|
480
481
|
|
|
482
|
+
const orderQueue = defineQueue('order-processing', { durable: true });
|
|
483
|
+
const orderMessage = defineMessage(z.object({
|
|
484
|
+
orderId: z.string(),
|
|
485
|
+
amount: z.number()
|
|
486
|
+
}));
|
|
487
|
+
|
|
481
488
|
const contract = defineContract({
|
|
482
|
-
queues: {
|
|
483
|
-
orderProcessing: defineQueue('order-processing', { durable: true })
|
|
484
|
-
},
|
|
485
489
|
consumers: {
|
|
486
|
-
processOrder: defineConsumer(
|
|
487
|
-
orderId: z.string(),
|
|
488
|
-
amount: z.number()
|
|
489
|
-
}))
|
|
490
|
+
processOrder: defineConsumer(orderQueue, orderMessage)
|
|
490
491
|
}
|
|
491
492
|
});
|
|
492
493
|
|
|
@@ -509,7 +510,7 @@ await worker.close().resultToPromise();
|
|
|
509
510
|
|
|
510
511
|
| Type Parameter | Description |
|
|
511
512
|
| ------ | ------ |
|
|
512
|
-
| `TContract` *extends* `
|
|
513
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
513
514
|
|
|
514
515
|
#### Methods
|
|
515
516
|
|
|
@@ -519,7 +520,7 @@ await worker.close().resultToPromise();
|
|
|
519
520
|
close(): Future<Result<void, TechnicalError>>;
|
|
520
521
|
```
|
|
521
522
|
|
|
522
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
523
|
+
Defined in: [packages/worker/src/worker.ts:278](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L278)
|
|
523
524
|
|
|
524
525
|
Close the AMQP channel and connection.
|
|
525
526
|
|
|
@@ -547,7 +548,7 @@ if (closeResult.isOk()) {
|
|
|
547
548
|
static create<TContract>(options): Future<Result<TypedAmqpWorker<TContract>, TechnicalError>>;
|
|
548
549
|
```
|
|
549
550
|
|
|
550
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
551
|
+
Defined in: [packages/worker/src/worker.ts:235](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L235)
|
|
551
552
|
|
|
552
553
|
Create a type-safe AMQP worker from a contract.
|
|
553
554
|
|
|
@@ -563,7 +564,7 @@ URLs and connection options, following RabbitMQ best practices.
|
|
|
563
564
|
|
|
564
565
|
| Type Parameter |
|
|
565
566
|
| ------ |
|
|
566
|
-
| `TContract` *extends* `
|
|
567
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
567
568
|
|
|
568
569
|
###### Parameters
|
|
569
570
|
|
|
@@ -597,7 +598,7 @@ const worker = await TypedAmqpWorker.create({
|
|
|
597
598
|
type CreateWorkerOptions<TContract> = object;
|
|
598
599
|
```
|
|
599
600
|
|
|
600
|
-
Defined in: [packages/worker/src/worker.ts:94](https://github.com/btravers/amqp-contract/blob/
|
|
601
|
+
Defined in: [packages/worker/src/worker.ts:94](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L94)
|
|
601
602
|
|
|
602
603
|
Options for creating a type-safe AMQP worker.
|
|
603
604
|
|
|
@@ -636,18 +637,18 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
|
636
637
|
|
|
637
638
|
| Type Parameter | Description |
|
|
638
639
|
| ------ | ------ |
|
|
639
|
-
| `TContract` *extends* `
|
|
640
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
640
641
|
|
|
641
642
|
#### Properties
|
|
642
643
|
|
|
643
644
|
| Property | Type | Description | Defined in |
|
|
644
645
|
| ------ | ------ | ------ | ------ |
|
|
645
|
-
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:106](https://github.com/btravers/amqp-contract/blob/
|
|
646
|
-
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:96](https://github.com/btravers/amqp-contract/blob/
|
|
647
|
-
| <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:102](https://github.com/btravers/amqp-contract/blob/
|
|
648
|
-
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:108](https://github.com/btravers/amqp-contract/blob/
|
|
649
|
-
| <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:114](https://github.com/btravers/amqp-contract/blob/
|
|
650
|
-
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:104](https://github.com/btravers/amqp-contract/blob/
|
|
646
|
+
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:106](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L106) |
|
|
647
|
+
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:96](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L96) |
|
|
648
|
+
| <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:102](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L102) |
|
|
649
|
+
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:108](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L108) |
|
|
650
|
+
| <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:114](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L114) |
|
|
651
|
+
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:104](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/worker.ts#L104) |
|
|
651
652
|
|
|
652
653
|
***
|
|
653
654
|
|
|
@@ -659,7 +660,7 @@ type HandlerError =
|
|
|
659
660
|
| NonRetryableError;
|
|
660
661
|
```
|
|
661
662
|
|
|
662
|
-
Defined in: [packages/worker/src/errors.ts:73](https://github.com/btravers/amqp-contract/blob/
|
|
663
|
+
Defined in: [packages/worker/src/errors.ts:73](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L73)
|
|
663
664
|
|
|
664
665
|
Union type representing all handler errors.
|
|
665
666
|
Use this type when defining handlers that explicitly signal error outcomes.
|
|
@@ -672,7 +673,7 @@ Use this type when defining handlers that explicitly signal error outcomes.
|
|
|
672
673
|
type WorkerConsumedMessage<TPayload, THeaders> = object;
|
|
673
674
|
```
|
|
674
675
|
|
|
675
|
-
Defined in: [packages/worker/src/types.ts:
|
|
676
|
+
Defined in: [packages/worker/src/types.ts:104](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L104)
|
|
676
677
|
|
|
677
678
|
A consumed message containing parsed payload and headers.
|
|
678
679
|
|
|
@@ -702,8 +703,8 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
|
|
|
702
703
|
|
|
703
704
|
| Property | Type | Description | Defined in |
|
|
704
705
|
| ------ | ------ | ------ | ------ |
|
|
705
|
-
| <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:
|
|
706
|
-
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:
|
|
706
|
+
| <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:108](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L108) |
|
|
707
|
+
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:106](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L106) |
|
|
707
708
|
|
|
708
709
|
***
|
|
709
710
|
|
|
@@ -713,7 +714,7 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
|
|
|
713
714
|
type WorkerInferConsumedMessage<TContract, TName> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
|
|
714
715
|
```
|
|
715
716
|
|
|
716
|
-
Defined in: [packages/worker/src/types.ts:
|
|
717
|
+
Defined in: [packages/worker/src/types.ts:115](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L115)
|
|
717
718
|
|
|
718
719
|
Infer the full consumed message type for a specific consumer.
|
|
719
720
|
Includes both payload and headers (if defined).
|
|
@@ -722,7 +723,7 @@ Includes both payload and headers (if defined).
|
|
|
722
723
|
|
|
723
724
|
| Type Parameter |
|
|
724
725
|
| ------ |
|
|
725
|
-
| `TContract` *extends* `
|
|
726
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
726
727
|
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
727
728
|
|
|
728
729
|
***
|
|
@@ -733,7 +734,7 @@ Includes both payload and headers (if defined).
|
|
|
733
734
|
type WorkerInferConsumerHandler<TContract, TName> = (message, rawMessage) => Future<Result<void, HandlerError>>;
|
|
734
735
|
```
|
|
735
736
|
|
|
736
|
-
Defined in: [packages/worker/src/types.ts:
|
|
737
|
+
Defined in: [packages/worker/src/types.ts:154](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L154)
|
|
737
738
|
|
|
738
739
|
Consumer handler type for a specific consumer.
|
|
739
740
|
Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
|
|
@@ -749,7 +750,7 @@ types from a contract definition at compile time.
|
|
|
749
750
|
|
|
750
751
|
| Type Parameter |
|
|
751
752
|
| ------ |
|
|
752
|
-
| `TContract` *extends* `
|
|
753
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
753
754
|
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
754
755
|
|
|
755
756
|
#### Parameters
|
|
@@ -786,7 +787,7 @@ type WorkerInferConsumerHandlerEntry<TContract, TName> =
|
|
|
786
787
|
}];
|
|
787
788
|
```
|
|
788
789
|
|
|
789
|
-
Defined in: [packages/worker/src/types.ts:
|
|
790
|
+
Defined in: [packages/worker/src/types.ts:172](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L172)
|
|
790
791
|
|
|
791
792
|
Handler entry for a consumer - either a function or a tuple of [handler, options].
|
|
792
793
|
|
|
@@ -801,7 +802,7 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
|
801
802
|
|
|
802
803
|
| Type Parameter |
|
|
803
804
|
| ------ |
|
|
804
|
-
| `TContract` *extends* `
|
|
805
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
805
806
|
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
806
807
|
|
|
807
808
|
***
|
|
@@ -812,7 +813,7 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
|
812
813
|
type WorkerInferConsumerHandlers<TContract> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> };
|
|
813
814
|
```
|
|
814
815
|
|
|
815
|
-
Defined in: [packages/worker/src/types.ts:
|
|
816
|
+
Defined in: [packages/worker/src/types.ts:193](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L193)
|
|
816
817
|
|
|
817
818
|
Consumer handlers for a contract.
|
|
818
819
|
All handlers return `Future<Result<void, HandlerError>>` for explicit error control.
|
|
@@ -821,7 +822,7 @@ All handlers return `Future<Result<void, HandlerError>>` for explicit error cont
|
|
|
821
822
|
|
|
822
823
|
| Type Parameter |
|
|
823
824
|
| ------ |
|
|
824
|
-
| `TContract` *extends* `
|
|
825
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
825
826
|
|
|
826
827
|
#### Example
|
|
827
828
|
|
|
@@ -842,7 +843,7 @@ const handlers: WorkerInferConsumerHandlers<typeof contract> = {
|
|
|
842
843
|
type WorkerInferConsumerHeaders<TContract, TName> = ConsumerInferHeadersInput<InferConsumer<TContract, TName>>;
|
|
843
844
|
```
|
|
844
845
|
|
|
845
|
-
Defined in: [packages/worker/src/types.ts:
|
|
846
|
+
Defined in: [packages/worker/src/types.ts:79](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L79)
|
|
846
847
|
|
|
847
848
|
Infer the headers type for a specific consumer
|
|
848
849
|
Returns undefined if no headers schema is defined
|
|
@@ -851,7 +852,7 @@ Returns undefined if no headers schema is defined
|
|
|
851
852
|
|
|
852
853
|
| Type Parameter |
|
|
853
854
|
| ------ |
|
|
854
|
-
| `TContract` *extends* `
|
|
855
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
855
856
|
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
856
857
|
|
|
857
858
|
***
|
|
@@ -862,13 +863,13 @@ Returns undefined if no headers schema is defined
|
|
|
862
863
|
type WorkerInferSafeConsumerHandler<TContract, TName> = WorkerInferConsumerHandler<TContract, TName>;
|
|
863
864
|
```
|
|
864
865
|
|
|
865
|
-
Defined in: [packages/worker/src/types.ts:
|
|
866
|
+
Defined in: [packages/worker/src/types.ts:205](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L205)
|
|
866
867
|
|
|
867
868
|
#### Type Parameters
|
|
868
869
|
|
|
869
870
|
| Type Parameter |
|
|
870
871
|
| ------ |
|
|
871
|
-
| `TContract` *extends* `
|
|
872
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
872
873
|
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
873
874
|
|
|
874
875
|
#### Deprecated
|
|
@@ -883,13 +884,13 @@ Use `WorkerInferConsumerHandler` instead. Will be removed in next major version.
|
|
|
883
884
|
type WorkerInferSafeConsumerHandlerEntry<TContract, TName> = WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
884
885
|
```
|
|
885
886
|
|
|
886
|
-
Defined in: [packages/worker/src/types.ts:
|
|
887
|
+
Defined in: [packages/worker/src/types.ts:213](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L213)
|
|
887
888
|
|
|
888
889
|
#### Type Parameters
|
|
889
890
|
|
|
890
891
|
| Type Parameter |
|
|
891
892
|
| ------ |
|
|
892
|
-
| `TContract` *extends* `
|
|
893
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
893
894
|
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
894
895
|
|
|
895
896
|
#### Deprecated
|
|
@@ -904,13 +905,13 @@ Use `WorkerInferConsumerHandlerEntry` instead. Will be removed in next major ver
|
|
|
904
905
|
type WorkerInferSafeConsumerHandlers<TContract> = WorkerInferConsumerHandlers<TContract>;
|
|
905
906
|
```
|
|
906
907
|
|
|
907
|
-
Defined in: [packages/worker/src/types.ts:
|
|
908
|
+
Defined in: [packages/worker/src/types.ts:221](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/types.ts#L221)
|
|
908
909
|
|
|
909
910
|
#### Type Parameters
|
|
910
911
|
|
|
911
912
|
| Type Parameter |
|
|
912
913
|
| ------ |
|
|
913
|
-
| `TContract` *extends* `
|
|
914
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
914
915
|
|
|
915
916
|
#### Deprecated
|
|
916
917
|
|
|
@@ -929,7 +930,7 @@ function defineHandler<TContract, TName>(
|
|
|
929
930
|
handler): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
930
931
|
```
|
|
931
932
|
|
|
932
|
-
Defined in: [packages/worker/src/handlers.ts:103](https://github.com/btravers/amqp-contract/blob/
|
|
933
|
+
Defined in: [packages/worker/src/handlers.ts:103](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/handlers.ts#L103)
|
|
933
934
|
|
|
934
935
|
Define a type-safe handler for a specific consumer in a contract.
|
|
935
936
|
|
|
@@ -944,7 +945,7 @@ Supports two patterns:
|
|
|
944
945
|
|
|
945
946
|
| Type Parameter | Description |
|
|
946
947
|
| ------ | ------ |
|
|
947
|
-
| `TContract` *extends* `
|
|
948
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
948
949
|
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
949
950
|
|
|
950
951
|
##### Parameters
|
|
@@ -1002,7 +1003,7 @@ function defineHandler<TContract, TName>(
|
|
|
1002
1003
|
options): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
1003
1004
|
```
|
|
1004
1005
|
|
|
1005
|
-
Defined in: [packages/worker/src/handlers.ts:111](https://github.com/btravers/amqp-contract/blob/
|
|
1006
|
+
Defined in: [packages/worker/src/handlers.ts:111](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/handlers.ts#L111)
|
|
1006
1007
|
|
|
1007
1008
|
Define a type-safe handler for a specific consumer in a contract.
|
|
1008
1009
|
|
|
@@ -1017,7 +1018,7 @@ Supports two patterns:
|
|
|
1017
1018
|
|
|
1018
1019
|
| Type Parameter | Description |
|
|
1019
1020
|
| ------ | ------ |
|
|
1020
|
-
| `TContract` *extends* `
|
|
1021
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1021
1022
|
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
1022
1023
|
|
|
1023
1024
|
##### Parameters
|
|
@@ -1075,7 +1076,7 @@ const validateOrderHandler = defineHandler(
|
|
|
1075
1076
|
function defineHandlers<TContract>(contract, handlers): WorkerInferConsumerHandlers<TContract>;
|
|
1076
1077
|
```
|
|
1077
1078
|
|
|
1078
|
-
Defined in: [packages/worker/src/handlers.ts:166](https://github.com/btravers/amqp-contract/blob/
|
|
1079
|
+
Defined in: [packages/worker/src/handlers.ts:166](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/handlers.ts#L166)
|
|
1079
1080
|
|
|
1080
1081
|
Define multiple type-safe handlers for consumers in a contract.
|
|
1081
1082
|
|
|
@@ -1086,7 +1087,7 @@ providing explicit error handling and better control over retry behavior.
|
|
|
1086
1087
|
|
|
1087
1088
|
| Type Parameter | Description |
|
|
1088
1089
|
| ------ | ------ |
|
|
1089
|
-
| `TContract` *extends* `
|
|
1090
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1090
1091
|
|
|
1091
1092
|
#### Parameters
|
|
1092
1093
|
|
|
@@ -1128,7 +1129,7 @@ const handlers = defineHandlers(orderContract, {
|
|
|
1128
1129
|
function isHandlerError(error): error is HandlerError;
|
|
1129
1130
|
```
|
|
1130
1131
|
|
|
1131
|
-
Defined in: [packages/worker/src/errors.ts:149](https://github.com/btravers/amqp-contract/blob/
|
|
1132
|
+
Defined in: [packages/worker/src/errors.ts:149](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L149)
|
|
1132
1133
|
|
|
1133
1134
|
Type guard to check if an error is any HandlerError (RetryableError or NonRetryableError).
|
|
1134
1135
|
|
|
@@ -1165,7 +1166,7 @@ function handleError(error: unknown) {
|
|
|
1165
1166
|
function isNonRetryableError(error): error is NonRetryableError;
|
|
1166
1167
|
```
|
|
1167
1168
|
|
|
1168
|
-
Defined in: [packages/worker/src/errors.ts:127](https://github.com/btravers/amqp-contract/blob/
|
|
1169
|
+
Defined in: [packages/worker/src/errors.ts:127](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L127)
|
|
1169
1170
|
|
|
1170
1171
|
Type guard to check if an error is a NonRetryableError.
|
|
1171
1172
|
|
|
@@ -1205,7 +1206,7 @@ try {
|
|
|
1205
1206
|
function isRetryableError(error): error is RetryableError;
|
|
1206
1207
|
```
|
|
1207
1208
|
|
|
1208
|
-
Defined in: [packages/worker/src/errors.ts:102](https://github.com/btravers/amqp-contract/blob/
|
|
1209
|
+
Defined in: [packages/worker/src/errors.ts:102](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L102)
|
|
1209
1210
|
|
|
1210
1211
|
Type guard to check if an error is a RetryableError.
|
|
1211
1212
|
|
|
@@ -1247,7 +1248,7 @@ try {
|
|
|
1247
1248
|
function nonRetryable(message, cause?): NonRetryableError;
|
|
1248
1249
|
```
|
|
1249
1250
|
|
|
1250
|
-
Defined in: [packages/worker/src/errors.ts:211](https://github.com/btravers/amqp-contract/blob/
|
|
1251
|
+
Defined in: [packages/worker/src/errors.ts:211](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L211)
|
|
1251
1252
|
|
|
1252
1253
|
Create a NonRetryableError with less verbosity.
|
|
1253
1254
|
|
|
@@ -1292,7 +1293,7 @@ const handler = ({ payload }) => {
|
|
|
1292
1293
|
function retryable(message, cause?): RetryableError;
|
|
1293
1294
|
```
|
|
1294
1295
|
|
|
1295
|
-
Defined in: [packages/worker/src/errors.ts:181](https://github.com/btravers/amqp-contract/blob/
|
|
1296
|
+
Defined in: [packages/worker/src/errors.ts:181](https://github.com/btravers/amqp-contract/blob/14b3465c61d25678b908341226a86fc481470ac6/packages/worker/src/errors.ts#L181)
|
|
1296
1297
|
|
|
1297
1298
|
Create a RetryableError with less verbosity.
|
|
1298
1299
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amqp-contract/worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Worker utilities for consuming messages using amqp-contract",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"amqp",
|
|
@@ -52,22 +52,22 @@
|
|
|
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.16.0",
|
|
56
|
+
"@amqp-contract/core": "0.16.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/amqplib": "0.10.8",
|
|
60
|
-
"@types/node": "25.
|
|
61
|
-
"@vitest/coverage-v8": "4.0.
|
|
60
|
+
"@types/node": "25.2.1",
|
|
61
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
62
62
|
"amqp-connection-manager": "5.0.0",
|
|
63
63
|
"amqplib": "0.10.9",
|
|
64
|
-
"tsdown": "0.
|
|
64
|
+
"tsdown": "0.20.3",
|
|
65
65
|
"typedoc": "0.28.16",
|
|
66
66
|
"typedoc-plugin-markdown": "4.9.0",
|
|
67
67
|
"typescript": "5.9.3",
|
|
68
|
-
"vitest": "4.0.
|
|
69
|
-
"zod": "4.3.
|
|
70
|
-
"@amqp-contract/testing": "0.
|
|
68
|
+
"vitest": "4.0.18",
|
|
69
|
+
"zod": "4.3.6",
|
|
70
|
+
"@amqp-contract/testing": "0.16.0",
|
|
71
71
|
"@amqp-contract/tsconfig": "0.1.0",
|
|
72
72
|
"@amqp-contract/typedoc": "0.1.0"
|
|
73
73
|
},
|