@amqp-contract/worker 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +237 -233
- package/dist/index.d.cts +172 -56
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +172 -56
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +231 -231
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +391 -258
- package/package.json +4 -4
package/docs/index.md
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
### MessageValidationError
|
|
10
10
|
|
|
11
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
11
|
+
Defined in: [packages/worker/src/errors.ts:4](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L4)
|
|
12
12
|
|
|
13
13
|
Error thrown when message validation fails
|
|
14
14
|
|
|
15
15
|
#### Extends
|
|
16
16
|
|
|
17
|
-
- `
|
|
17
|
+
- `Error`
|
|
18
18
|
|
|
19
19
|
#### Constructors
|
|
20
20
|
|
|
@@ -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:
|
|
27
|
+
Defined in: [packages/worker/src/errors.ts:5](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L5)
|
|
28
28
|
|
|
29
29
|
###### Parameters
|
|
30
30
|
|
|
@@ -40,20 +40,20 @@ Defined in: [packages/worker/src/errors.ts:36](https://github.com/btravers/amqp-
|
|
|
40
40
|
###### Overrides
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
|
-
|
|
43
|
+
Error.constructor
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
#### Properties
|
|
47
47
|
|
|
48
48
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
49
49
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
50
|
-
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `
|
|
51
|
-
| <a id="consumername"></a> `consumerName` | `readonly` | `string` | - | - | [packages/worker/src/errors.ts:
|
|
52
|
-
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | [packages/worker/src/errors.ts:
|
|
53
|
-
| <a id="message"></a> `message` | `public` | `string` | - | `
|
|
54
|
-
| <a id="name"></a> `name` | `public` | `string` | - | `
|
|
55
|
-
| <a id="stack"></a> `stack?` | `public` | `string` | - | `
|
|
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. | `
|
|
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/69a6467d137997be809af2ea5c4332c378579b49/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/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L7) |
|
|
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
|
+
| <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
|
+
| <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.0.9/node\_modules/@types/node/globals.d.ts:67 |
|
|
57
57
|
|
|
58
58
|
#### Methods
|
|
59
59
|
|
|
@@ -123,7 +123,7 @@ a();
|
|
|
123
123
|
###### Inherited from
|
|
124
124
|
|
|
125
125
|
```ts
|
|
126
|
-
|
|
126
|
+
Error.captureStackTrace
|
|
127
127
|
```
|
|
128
128
|
|
|
129
129
|
##### prepareStackTrace()
|
|
@@ -152,14 +152,14 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
152
152
|
###### Inherited from
|
|
153
153
|
|
|
154
154
|
```ts
|
|
155
|
-
|
|
155
|
+
Error.prepareStackTrace
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
***
|
|
159
159
|
|
|
160
160
|
### NonRetryableError
|
|
161
161
|
|
|
162
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
162
|
+
Defined in: [packages/worker/src/errors.ts:52](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/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
|
|
@@ -169,7 +169,7 @@ immediately sent to the dead letter queue (DLQ) if configured.
|
|
|
169
169
|
|
|
170
170
|
#### Extends
|
|
171
171
|
|
|
172
|
-
- `
|
|
172
|
+
- `Error`
|
|
173
173
|
|
|
174
174
|
#### Constructors
|
|
175
175
|
|
|
@@ -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:
|
|
182
|
+
Defined in: [packages/worker/src/errors.ts:53](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L53)
|
|
183
183
|
|
|
184
184
|
###### Parameters
|
|
185
185
|
|
|
@@ -195,18 +195,18 @@ Defined in: [packages/worker/src/errors.ts:70](https://github.com/btravers/amqp-
|
|
|
195
195
|
###### Overrides
|
|
196
196
|
|
|
197
197
|
```ts
|
|
198
|
-
|
|
198
|
+
Error.constructor
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
#### Properties
|
|
202
202
|
|
|
203
203
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
204
204
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
205
|
-
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `
|
|
206
|
-
| <a id="message-1"></a> `message` | `public` | `string` | - | `
|
|
207
|
-
| <a id="name-1"></a> `name` | `public` | `string` | - | `
|
|
208
|
-
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `
|
|
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. | `
|
|
205
|
+
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L55) |
|
|
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
|
+
| <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
|
+
| <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.0.9/node\_modules/@types/node/globals.d.ts:67 |
|
|
210
210
|
|
|
211
211
|
#### Methods
|
|
212
212
|
|
|
@@ -276,7 +276,7 @@ a();
|
|
|
276
276
|
###### Inherited from
|
|
277
277
|
|
|
278
278
|
```ts
|
|
279
|
-
|
|
279
|
+
Error.captureStackTrace
|
|
280
280
|
```
|
|
281
281
|
|
|
282
282
|
##### prepareStackTrace()
|
|
@@ -305,14 +305,14 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
305
305
|
###### Inherited from
|
|
306
306
|
|
|
307
307
|
```ts
|
|
308
|
-
|
|
308
|
+
Error.prepareStackTrace
|
|
309
309
|
```
|
|
310
310
|
|
|
311
311
|
***
|
|
312
312
|
|
|
313
313
|
### RetryableError
|
|
314
314
|
|
|
315
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
315
|
+
Defined in: [packages/worker/src/errors.ts:28](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/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
|
|
@@ -322,7 +322,7 @@ The worker will apply exponential backoff and retry the message.
|
|
|
322
322
|
|
|
323
323
|
#### Extends
|
|
324
324
|
|
|
325
|
-
- `
|
|
325
|
+
- `Error`
|
|
326
326
|
|
|
327
327
|
#### Constructors
|
|
328
328
|
|
|
@@ -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:
|
|
335
|
+
Defined in: [packages/worker/src/errors.ts:29](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L29)
|
|
336
336
|
|
|
337
337
|
###### Parameters
|
|
338
338
|
|
|
@@ -348,18 +348,18 @@ Defined in: [packages/worker/src/errors.ts:53](https://github.com/btravers/amqp-
|
|
|
348
348
|
###### Overrides
|
|
349
349
|
|
|
350
350
|
```ts
|
|
351
|
-
|
|
351
|
+
Error.constructor
|
|
352
352
|
```
|
|
353
353
|
|
|
354
354
|
#### Properties
|
|
355
355
|
|
|
356
356
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
357
357
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
358
|
-
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | `
|
|
359
|
-
| <a id="message-2"></a> `message` | `public` | `string` | - | `
|
|
360
|
-
| <a id="name-2"></a> `name` | `public` | `string` | - | `
|
|
361
|
-
| <a id="stack-2"></a> `stack?` | `public` | `string` | - | `
|
|
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. | `
|
|
358
|
+
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:31](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L31) |
|
|
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
|
+
| <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
|
+
| <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.0.9/node\_modules/@types/node/globals.d.ts:67 |
|
|
363
363
|
|
|
364
364
|
#### Methods
|
|
365
365
|
|
|
@@ -429,7 +429,7 @@ a();
|
|
|
429
429
|
###### Inherited from
|
|
430
430
|
|
|
431
431
|
```ts
|
|
432
|
-
|
|
432
|
+
Error.captureStackTrace
|
|
433
433
|
```
|
|
434
434
|
|
|
435
435
|
##### prepareStackTrace()
|
|
@@ -458,164 +458,14 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
458
458
|
###### Inherited from
|
|
459
459
|
|
|
460
460
|
```ts
|
|
461
|
-
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
***
|
|
465
|
-
|
|
466
|
-
### TechnicalError
|
|
467
|
-
|
|
468
|
-
Defined in: [packages/worker/src/errors.ts:22](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L22)
|
|
469
|
-
|
|
470
|
-
Error for technical/runtime failures in worker operations
|
|
471
|
-
This includes validation failures, parsing failures, and processing failures
|
|
472
|
-
|
|
473
|
-
#### Extends
|
|
474
|
-
|
|
475
|
-
- `WorkerError`
|
|
476
|
-
|
|
477
|
-
#### Constructors
|
|
478
|
-
|
|
479
|
-
##### Constructor
|
|
480
|
-
|
|
481
|
-
```ts
|
|
482
|
-
new TechnicalError(message, cause?): TechnicalError;
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
Defined in: [packages/worker/src/errors.ts:23](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L23)
|
|
486
|
-
|
|
487
|
-
###### Parameters
|
|
488
|
-
|
|
489
|
-
| Parameter | Type |
|
|
490
|
-
| ------ | ------ |
|
|
491
|
-
| `message` | `string` |
|
|
492
|
-
| `cause?` | `unknown` |
|
|
493
|
-
|
|
494
|
-
###### Returns
|
|
495
|
-
|
|
496
|
-
[`TechnicalError`](#technicalerror)
|
|
497
|
-
|
|
498
|
-
###### Overrides
|
|
499
|
-
|
|
500
|
-
```ts
|
|
501
|
-
WorkerError.constructor
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
#### Properties
|
|
505
|
-
|
|
506
|
-
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
507
|
-
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
508
|
-
| <a id="cause-3"></a> `cause?` | `readonly` | `unknown` | - | `WorkerError.cause` | [packages/worker/src/errors.ts:25](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/errors.ts#L25) |
|
|
509
|
-
| <a id="message-3"></a> `message` | `public` | `string` | - | `WorkerError.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
510
|
-
| <a id="name-3"></a> `name` | `public` | `string` | - | `WorkerError.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
511
|
-
| <a id="stack-3"></a> `stack?` | `public` | `string` | - | `WorkerError.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
512
|
-
| <a id="stacktracelimit-3"></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. | `WorkerError.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:67 |
|
|
513
|
-
|
|
514
|
-
#### Methods
|
|
515
|
-
|
|
516
|
-
##### captureStackTrace()
|
|
517
|
-
|
|
518
|
-
```ts
|
|
519
|
-
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:51
|
|
523
|
-
|
|
524
|
-
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
525
|
-
a string representing the location in the code at which
|
|
526
|
-
`Error.captureStackTrace()` was called.
|
|
527
|
-
|
|
528
|
-
```js
|
|
529
|
-
const myObject = {};
|
|
530
|
-
Error.captureStackTrace(myObject);
|
|
531
|
-
myObject.stack; // Similar to `new Error().stack`
|
|
532
|
-
```
|
|
533
|
-
|
|
534
|
-
The first line of the trace will be prefixed with
|
|
535
|
-
`${myObject.name}: ${myObject.message}`.
|
|
536
|
-
|
|
537
|
-
The optional `constructorOpt` argument accepts a function. If given, all frames
|
|
538
|
-
above `constructorOpt`, including `constructorOpt`, will be omitted from the
|
|
539
|
-
generated stack trace.
|
|
540
|
-
|
|
541
|
-
The `constructorOpt` argument is useful for hiding implementation
|
|
542
|
-
details of error generation from the user. For instance:
|
|
543
|
-
|
|
544
|
-
```js
|
|
545
|
-
function a() {
|
|
546
|
-
b();
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
function b() {
|
|
550
|
-
c();
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function c() {
|
|
554
|
-
// Create an error without stack trace to avoid calculating the stack trace twice.
|
|
555
|
-
const { stackTraceLimit } = Error;
|
|
556
|
-
Error.stackTraceLimit = 0;
|
|
557
|
-
const error = new Error();
|
|
558
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
559
|
-
|
|
560
|
-
// Capture the stack trace above function b
|
|
561
|
-
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
|
|
562
|
-
throw error;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
a();
|
|
566
|
-
```
|
|
567
|
-
|
|
568
|
-
###### Parameters
|
|
569
|
-
|
|
570
|
-
| Parameter | Type |
|
|
571
|
-
| ------ | ------ |
|
|
572
|
-
| `targetObject` | `object` |
|
|
573
|
-
| `constructorOpt?` | `Function` |
|
|
574
|
-
|
|
575
|
-
###### Returns
|
|
576
|
-
|
|
577
|
-
`void`
|
|
578
|
-
|
|
579
|
-
###### Inherited from
|
|
580
|
-
|
|
581
|
-
```ts
|
|
582
|
-
WorkerError.captureStackTrace
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
##### prepareStackTrace()
|
|
586
|
-
|
|
587
|
-
```ts
|
|
588
|
-
static prepareStackTrace(err, stackTraces): any;
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
Defined in: node\_modules/.pnpm/@types+node@25.0.9/node\_modules/@types/node/globals.d.ts:55
|
|
592
|
-
|
|
593
|
-
###### Parameters
|
|
594
|
-
|
|
595
|
-
| Parameter | Type |
|
|
596
|
-
| ------ | ------ |
|
|
597
|
-
| `err` | `Error` |
|
|
598
|
-
| `stackTraces` | `CallSite`[] |
|
|
599
|
-
|
|
600
|
-
###### Returns
|
|
601
|
-
|
|
602
|
-
`any`
|
|
603
|
-
|
|
604
|
-
###### See
|
|
605
|
-
|
|
606
|
-
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
607
|
-
|
|
608
|
-
###### Inherited from
|
|
609
|
-
|
|
610
|
-
```ts
|
|
611
|
-
WorkerError.prepareStackTrace
|
|
461
|
+
Error.prepareStackTrace
|
|
612
462
|
```
|
|
613
463
|
|
|
614
464
|
***
|
|
615
465
|
|
|
616
466
|
### TypedAmqpWorker
|
|
617
467
|
|
|
618
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
468
|
+
Defined in: [packages/worker/src/worker.ts:156](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L156)
|
|
619
469
|
|
|
620
470
|
Type-safe AMQP worker for consuming messages from RabbitMQ.
|
|
621
471
|
|
|
@@ -669,7 +519,7 @@ await worker.close().resultToPromise();
|
|
|
669
519
|
close(): Future<Result<void, TechnicalError>>;
|
|
670
520
|
```
|
|
671
521
|
|
|
672
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
522
|
+
Defined in: [packages/worker/src/worker.ts:276](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L276)
|
|
673
523
|
|
|
674
524
|
Close the AMQP channel and connection.
|
|
675
525
|
|
|
@@ -678,7 +528,7 @@ stopping all message consumption and cleaning up resources.
|
|
|
678
528
|
|
|
679
529
|
###### Returns
|
|
680
530
|
|
|
681
|
-
`Future
|
|
531
|
+
`Future`<`Result`<`void`, `TechnicalError`>>
|
|
682
532
|
|
|
683
533
|
A Future that resolves to a Result indicating success or failure
|
|
684
534
|
|
|
@@ -697,7 +547,7 @@ if (closeResult.isOk()) {
|
|
|
697
547
|
static create<TContract>(options): Future<Result<TypedAmqpWorker<TContract>, TechnicalError>>;
|
|
698
548
|
```
|
|
699
549
|
|
|
700
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
550
|
+
Defined in: [packages/worker/src/worker.ts:233](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L233)
|
|
701
551
|
|
|
702
552
|
Create a type-safe AMQP worker from a contract.
|
|
703
553
|
|
|
@@ -719,11 +569,11 @@ URLs and connection options, following RabbitMQ best practices.
|
|
|
719
569
|
|
|
720
570
|
| Parameter | Type | Description |
|
|
721
571
|
| ------ | ------ | ------ |
|
|
722
|
-
| `options` | [`CreateWorkerOptions`](#createworkeroptions)
|
|
572
|
+
| `options` | [`CreateWorkerOptions`](#createworkeroptions)<`TContract`> | Configuration options for the worker |
|
|
723
573
|
|
|
724
574
|
###### Returns
|
|
725
575
|
|
|
726
|
-
`Future
|
|
576
|
+
`Future`<`Result`<[`TypedAmqpWorker`](#typedamqpworker)<`TContract`>, `TechnicalError`>>
|
|
727
577
|
|
|
728
578
|
A Future that resolves to a Result containing the worker or an error
|
|
729
579
|
|
|
@@ -747,7 +597,7 @@ const worker = await TypedAmqpWorker.create({
|
|
|
747
597
|
type CreateWorkerOptions<TContract> = object;
|
|
748
598
|
```
|
|
749
599
|
|
|
750
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
600
|
+
Defined in: [packages/worker/src/worker.ts:93](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L93)
|
|
751
601
|
|
|
752
602
|
Options for creating a type-safe AMQP worker.
|
|
753
603
|
|
|
@@ -792,12 +642,12 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
|
792
642
|
|
|
793
643
|
| Property | Type | Description | Defined in |
|
|
794
644
|
| ------ | ------ | ------ | ------ |
|
|
795
|
-
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:
|
|
796
|
-
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:
|
|
797
|
-
| <a id="handlers"></a> `handlers` | [`
|
|
798
|
-
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:
|
|
799
|
-
| <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:
|
|
800
|
-
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:
|
|
645
|
+
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:105](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L105) |
|
|
646
|
+
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:95](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L95) |
|
|
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:101](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L101) |
|
|
648
|
+
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:107](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L107) |
|
|
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:113](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L113) |
|
|
650
|
+
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:103](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/worker.ts#L103) |
|
|
801
651
|
|
|
802
652
|
***
|
|
803
653
|
|
|
@@ -809,7 +659,7 @@ type HandlerError =
|
|
|
809
659
|
| NonRetryableError;
|
|
810
660
|
```
|
|
811
661
|
|
|
812
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
662
|
+
Defined in: [packages/worker/src/errors.ts:73](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L73)
|
|
813
663
|
|
|
814
664
|
Union type representing all handler errors.
|
|
815
665
|
Use this type when defining handlers that explicitly signal error outcomes.
|
|
@@ -822,7 +672,7 @@ Use this type when defining handlers that explicitly signal error outcomes.
|
|
|
822
672
|
type WorkerConsumedMessage<TPayload, THeaders> = object;
|
|
823
673
|
```
|
|
824
674
|
|
|
825
|
-
Defined in: [packages/worker/src/types.ts:86](https://github.com/btravers/amqp-contract/blob/
|
|
675
|
+
Defined in: [packages/worker/src/types.ts:86](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L86)
|
|
826
676
|
|
|
827
677
|
A consumed message containing parsed payload and headers.
|
|
828
678
|
|
|
@@ -852,8 +702,8 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
|
|
|
852
702
|
|
|
853
703
|
| Property | Type | Description | Defined in |
|
|
854
704
|
| ------ | ------ | ------ | ------ |
|
|
855
|
-
| <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:90](https://github.com/btravers/amqp-contract/blob/
|
|
856
|
-
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:88](https://github.com/btravers/amqp-contract/blob/
|
|
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:90](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L90) |
|
|
706
|
+
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:88](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L88) |
|
|
857
707
|
|
|
858
708
|
***
|
|
859
709
|
|
|
@@ -863,7 +713,7 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
|
|
|
863
713
|
type WorkerInferConsumedMessage<TContract, TName> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
|
|
864
714
|
```
|
|
865
715
|
|
|
866
|
-
Defined in: [packages/worker/src/types.ts:97](https://github.com/btravers/amqp-contract/blob/
|
|
716
|
+
Defined in: [packages/worker/src/types.ts:97](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L97)
|
|
867
717
|
|
|
868
718
|
Infer the full consumed message type for a specific consumer.
|
|
869
719
|
Includes both payload and headers (if defined).
|
|
@@ -873,67 +723,50 @@ Includes both payload and headers (if defined).
|
|
|
873
723
|
| Type Parameter |
|
|
874
724
|
| ------ |
|
|
875
725
|
| `TContract` *extends* `ContractDefinition` |
|
|
876
|
-
| `TName` *extends* `InferConsumerNames
|
|
877
|
-
|
|
878
|
-
***
|
|
879
|
-
|
|
880
|
-
### WorkerInferConsumerHeaders
|
|
881
|
-
|
|
882
|
-
```ts
|
|
883
|
-
type WorkerInferConsumerHeaders<TContract, TName> = ConsumerInferHeadersInput<InferConsumer<TContract, TName>>;
|
|
884
|
-
```
|
|
885
|
-
|
|
886
|
-
Defined in: [packages/worker/src/types.ts:61](https://github.com/btravers/amqp-contract/blob/ed05e43c04fa526b751d45622ccc1ac53b2e96f9/packages/worker/src/types.ts#L61)
|
|
887
|
-
|
|
888
|
-
Infer the headers type for a specific consumer
|
|
889
|
-
Returns undefined if no headers schema is defined
|
|
890
|
-
|
|
891
|
-
#### Type Parameters
|
|
892
|
-
|
|
893
|
-
| Type Parameter |
|
|
894
|
-
| ------ |
|
|
895
|
-
| `TContract` *extends* `ContractDefinition` |
|
|
896
|
-
| `TName` *extends* `InferConsumerNames`\<`TContract`\> |
|
|
726
|
+
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
897
727
|
|
|
898
728
|
***
|
|
899
729
|
|
|
900
|
-
###
|
|
730
|
+
### WorkerInferConsumerHandler()
|
|
901
731
|
|
|
902
732
|
```ts
|
|
903
|
-
type
|
|
733
|
+
type WorkerInferConsumerHandler<TContract, TName> = (message, rawMessage) => Future<Result<void, HandlerError>>;
|
|
904
734
|
```
|
|
905
735
|
|
|
906
|
-
Defined in: [packages/worker/src/types.ts:
|
|
736
|
+
Defined in: [packages/worker/src/types.ts:136](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L136)
|
|
907
737
|
|
|
908
|
-
|
|
738
|
+
Consumer handler type for a specific consumer.
|
|
909
739
|
Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
|
|
910
740
|
|
|
911
|
-
|
|
741
|
+
Error handling:
|
|
912
742
|
- RetryableError: Message will be retried with exponential backoff
|
|
913
743
|
- NonRetryableError: Message will be immediately sent to DLQ
|
|
914
744
|
|
|
745
|
+
The `WorkerInfer*` naming pattern indicates type inference helpers that extract
|
|
746
|
+
types from a contract definition at compile time.
|
|
747
|
+
|
|
915
748
|
#### Type Parameters
|
|
916
749
|
|
|
917
750
|
| Type Parameter |
|
|
918
751
|
| ------ |
|
|
919
752
|
| `TContract` *extends* `ContractDefinition` |
|
|
920
|
-
| `TName` *extends* `InferConsumerNames
|
|
753
|
+
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
921
754
|
|
|
922
755
|
#### Parameters
|
|
923
756
|
|
|
924
757
|
| Parameter | Type | Description |
|
|
925
758
|
| ------ | ------ | ------ |
|
|
926
|
-
| `message` | [`WorkerInferConsumedMessage`](#workerinferconsumedmessage)
|
|
759
|
+
| `message` | [`WorkerInferConsumedMessage`](#workerinferconsumedmessage)<`TContract`, `TName`> | The parsed message containing validated payload and headers |
|
|
927
760
|
| `rawMessage` | `ConsumeMessage` | The raw AMQP message with all metadata (fields, properties, content) |
|
|
928
761
|
|
|
929
762
|
#### Returns
|
|
930
763
|
|
|
931
|
-
`Future
|
|
764
|
+
`Future`<`Result`<`void`, [`HandlerError`](#handlererror)>>
|
|
932
765
|
|
|
933
766
|
#### Example
|
|
934
767
|
|
|
935
768
|
```typescript
|
|
936
|
-
const handler:
|
|
769
|
+
const handler: WorkerInferConsumerHandler<typeof contract, 'processOrder'> =
|
|
937
770
|
({ payload }, rawMessage) => {
|
|
938
771
|
console.log(payload.orderId); // Typed payload
|
|
939
772
|
console.log(rawMessage.fields.deliveryTag); // Raw AMQP message
|
|
@@ -943,19 +776,19 @@ const handler: WorkerInferSafeConsumerHandler<typeof contract, 'processOrder'> =
|
|
|
943
776
|
|
|
944
777
|
***
|
|
945
778
|
|
|
946
|
-
###
|
|
779
|
+
### WorkerInferConsumerHandlerEntry
|
|
947
780
|
|
|
948
781
|
```ts
|
|
949
|
-
type
|
|
950
|
-
|
|
|
951
|
-
| readonly [
|
|
782
|
+
type WorkerInferConsumerHandlerEntry<TContract, TName> =
|
|
783
|
+
| WorkerInferConsumerHandler<TContract, TName>
|
|
784
|
+
| readonly [WorkerInferConsumerHandler<TContract, TName>, {
|
|
952
785
|
prefetch?: number;
|
|
953
786
|
}];
|
|
954
787
|
```
|
|
955
788
|
|
|
956
|
-
Defined in: [packages/worker/src/types.ts:
|
|
789
|
+
Defined in: [packages/worker/src/types.ts:154](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L154)
|
|
957
790
|
|
|
958
|
-
|
|
791
|
+
Handler entry for a consumer - either a function or a tuple of [handler, options].
|
|
959
792
|
|
|
960
793
|
Two patterns are supported:
|
|
961
794
|
1. Simple handler: `({ payload }, rawMessage) => Future.value(Result.Ok(undefined))`
|
|
@@ -969,19 +802,19 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
|
969
802
|
| Type Parameter |
|
|
970
803
|
| ------ |
|
|
971
804
|
| `TContract` *extends* `ContractDefinition` |
|
|
972
|
-
| `TName` *extends* `InferConsumerNames
|
|
805
|
+
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
973
806
|
|
|
974
807
|
***
|
|
975
808
|
|
|
976
|
-
###
|
|
809
|
+
### WorkerInferConsumerHandlers
|
|
977
810
|
|
|
978
811
|
```ts
|
|
979
|
-
type
|
|
812
|
+
type WorkerInferConsumerHandlers<TContract> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> };
|
|
980
813
|
```
|
|
981
814
|
|
|
982
|
-
Defined in: [packages/worker/src/types.ts:
|
|
815
|
+
Defined in: [packages/worker/src/types.ts:175](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L175)
|
|
983
816
|
|
|
984
|
-
|
|
817
|
+
Consumer handlers for a contract.
|
|
985
818
|
All handlers return `Future<Result<void, HandlerError>>` for explicit error control.
|
|
986
819
|
|
|
987
820
|
#### Type Parameters
|
|
@@ -990,6 +823,99 @@ All handlers return `Future<Result<void, HandlerError>>` for explicit error cont
|
|
|
990
823
|
| ------ |
|
|
991
824
|
| `TContract` *extends* `ContractDefinition` |
|
|
992
825
|
|
|
826
|
+
#### Example
|
|
827
|
+
|
|
828
|
+
```typescript
|
|
829
|
+
const handlers: WorkerInferConsumerHandlers<typeof contract> = {
|
|
830
|
+
processOrder: ({ payload }) =>
|
|
831
|
+
Future.fromPromise(processPayment(payload))
|
|
832
|
+
.mapOk(() => undefined)
|
|
833
|
+
.mapError((error) => new RetryableError('Payment failed', error)),
|
|
834
|
+
};
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
***
|
|
838
|
+
|
|
839
|
+
### WorkerInferConsumerHeaders
|
|
840
|
+
|
|
841
|
+
```ts
|
|
842
|
+
type WorkerInferConsumerHeaders<TContract, TName> = ConsumerInferHeadersInput<InferConsumer<TContract, TName>>;
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
Defined in: [packages/worker/src/types.ts:61](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L61)
|
|
846
|
+
|
|
847
|
+
Infer the headers type for a specific consumer
|
|
848
|
+
Returns undefined if no headers schema is defined
|
|
849
|
+
|
|
850
|
+
#### Type Parameters
|
|
851
|
+
|
|
852
|
+
| Type Parameter |
|
|
853
|
+
| ------ |
|
|
854
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
855
|
+
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
856
|
+
|
|
857
|
+
***
|
|
858
|
+
|
|
859
|
+
### ~~WorkerInferSafeConsumerHandler~~
|
|
860
|
+
|
|
861
|
+
```ts
|
|
862
|
+
type WorkerInferSafeConsumerHandler<TContract, TName> = WorkerInferConsumerHandler<TContract, TName>;
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
Defined in: [packages/worker/src/types.ts:187](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L187)
|
|
866
|
+
|
|
867
|
+
#### Type Parameters
|
|
868
|
+
|
|
869
|
+
| Type Parameter |
|
|
870
|
+
| ------ |
|
|
871
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
872
|
+
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
873
|
+
|
|
874
|
+
#### Deprecated
|
|
875
|
+
|
|
876
|
+
Use `WorkerInferConsumerHandler` instead. Will be removed in next major version.
|
|
877
|
+
|
|
878
|
+
***
|
|
879
|
+
|
|
880
|
+
### ~~WorkerInferSafeConsumerHandlerEntry~~
|
|
881
|
+
|
|
882
|
+
```ts
|
|
883
|
+
type WorkerInferSafeConsumerHandlerEntry<TContract, TName> = WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
Defined in: [packages/worker/src/types.ts:195](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L195)
|
|
887
|
+
|
|
888
|
+
#### Type Parameters
|
|
889
|
+
|
|
890
|
+
| Type Parameter |
|
|
891
|
+
| ------ |
|
|
892
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
893
|
+
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
894
|
+
|
|
895
|
+
#### Deprecated
|
|
896
|
+
|
|
897
|
+
Use `WorkerInferConsumerHandlerEntry` instead. Will be removed in next major version.
|
|
898
|
+
|
|
899
|
+
***
|
|
900
|
+
|
|
901
|
+
### ~~WorkerInferSafeConsumerHandlers~~
|
|
902
|
+
|
|
903
|
+
```ts
|
|
904
|
+
type WorkerInferSafeConsumerHandlers<TContract> = WorkerInferConsumerHandlers<TContract>;
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
Defined in: [packages/worker/src/types.ts:203](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/types.ts#L203)
|
|
908
|
+
|
|
909
|
+
#### Type Parameters
|
|
910
|
+
|
|
911
|
+
| Type Parameter |
|
|
912
|
+
| ------ |
|
|
913
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
914
|
+
|
|
915
|
+
#### Deprecated
|
|
916
|
+
|
|
917
|
+
Use `WorkerInferConsumerHandlers` instead. Will be removed in next major version.
|
|
918
|
+
|
|
993
919
|
## Functions
|
|
994
920
|
|
|
995
921
|
### defineHandler()
|
|
@@ -1000,10 +926,10 @@ All handlers return `Future<Result<void, HandlerError>>` for explicit error cont
|
|
|
1000
926
|
function defineHandler<TContract, TName>(
|
|
1001
927
|
contract,
|
|
1002
928
|
consumerName,
|
|
1003
|
-
handler):
|
|
929
|
+
handler): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
1004
930
|
```
|
|
1005
931
|
|
|
1006
|
-
Defined in: [packages/worker/src/handlers.ts:103](https://github.com/btravers/amqp-contract/blob/
|
|
932
|
+
Defined in: [packages/worker/src/handlers.ts:103](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/handlers.ts#L103)
|
|
1007
933
|
|
|
1008
934
|
Define a type-safe handler for a specific consumer in a contract.
|
|
1009
935
|
|
|
@@ -1012,7 +938,7 @@ providing explicit error handling and better control over retry behavior.
|
|
|
1012
938
|
|
|
1013
939
|
Supports two patterns:
|
|
1014
940
|
1. Simple handler: just the function
|
|
1015
|
-
2. Handler with options: [handler, { prefetch: 10 }]
|
|
941
|
+
2. Handler with options: [handler, \{ prefetch: 10 \}]
|
|
1016
942
|
|
|
1017
943
|
##### Type Parameters
|
|
1018
944
|
|
|
@@ -1027,11 +953,11 @@ Supports two patterns:
|
|
|
1027
953
|
| ------ | ------ | ------ |
|
|
1028
954
|
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
1029
955
|
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
1030
|
-
| `handler` | [`
|
|
956
|
+
| `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)<`TContract`, `TName`> | The handler function that returns `Future<Result<void, HandlerError>>` |
|
|
1031
957
|
|
|
1032
958
|
##### Returns
|
|
1033
959
|
|
|
1034
|
-
[`
|
|
960
|
+
[`WorkerInferConsumerHandlerEntry`](#workerinferconsumerhandlerentry)<`TContract`, `TName`>
|
|
1035
961
|
|
|
1036
962
|
A type-safe handler that can be used with TypedAmqpWorker
|
|
1037
963
|
|
|
@@ -1073,10 +999,10 @@ function defineHandler<TContract, TName>(
|
|
|
1073
999
|
contract,
|
|
1074
1000
|
consumerName,
|
|
1075
1001
|
handler,
|
|
1076
|
-
options):
|
|
1002
|
+
options): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
1077
1003
|
```
|
|
1078
1004
|
|
|
1079
|
-
Defined in: [packages/worker/src/handlers.ts:111](https://github.com/btravers/amqp-contract/blob/
|
|
1005
|
+
Defined in: [packages/worker/src/handlers.ts:111](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/handlers.ts#L111)
|
|
1080
1006
|
|
|
1081
1007
|
Define a type-safe handler for a specific consumer in a contract.
|
|
1082
1008
|
|
|
@@ -1085,7 +1011,7 @@ providing explicit error handling and better control over retry behavior.
|
|
|
1085
1011
|
|
|
1086
1012
|
Supports two patterns:
|
|
1087
1013
|
1. Simple handler: just the function
|
|
1088
|
-
2. Handler with options: [handler, { prefetch: 10 }]
|
|
1014
|
+
2. Handler with options: [handler, \{ prefetch: 10 \}]
|
|
1089
1015
|
|
|
1090
1016
|
##### Type Parameters
|
|
1091
1017
|
|
|
@@ -1100,13 +1026,13 @@ Supports two patterns:
|
|
|
1100
1026
|
| ------ | ------ | ------ |
|
|
1101
1027
|
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
1102
1028
|
| `consumerName` | `TName` | The name of the consumer from the contract |
|
|
1103
|
-
| `handler` | [`
|
|
1029
|
+
| `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)<`TContract`, `TName`> | The handler function that returns `Future<Result<void, HandlerError>>` |
|
|
1104
1030
|
| `options` | \{ `prefetch?`: `number`; \} | Optional consumer options (prefetch) |
|
|
1105
1031
|
| `options.prefetch?` | `number` | - |
|
|
1106
1032
|
|
|
1107
1033
|
##### Returns
|
|
1108
1034
|
|
|
1109
|
-
[`
|
|
1035
|
+
[`WorkerInferConsumerHandlerEntry`](#workerinferconsumerhandlerentry)<`TContract`, `TName`>
|
|
1110
1036
|
|
|
1111
1037
|
A type-safe handler that can be used with TypedAmqpWorker
|
|
1112
1038
|
|
|
@@ -1146,10 +1072,10 @@ const validateOrderHandler = defineHandler(
|
|
|
1146
1072
|
### defineHandlers()
|
|
1147
1073
|
|
|
1148
1074
|
```ts
|
|
1149
|
-
function defineHandlers<TContract>(contract, handlers):
|
|
1075
|
+
function defineHandlers<TContract>(contract, handlers): WorkerInferConsumerHandlers<TContract>;
|
|
1150
1076
|
```
|
|
1151
1077
|
|
|
1152
|
-
Defined in: [packages/worker/src/handlers.ts:166](https://github.com/btravers/amqp-contract/blob/
|
|
1078
|
+
Defined in: [packages/worker/src/handlers.ts:166](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/handlers.ts#L166)
|
|
1153
1079
|
|
|
1154
1080
|
Define multiple type-safe handlers for consumers in a contract.
|
|
1155
1081
|
|
|
@@ -1167,11 +1093,11 @@ providing explicit error handling and better control over retry behavior.
|
|
|
1167
1093
|
| Parameter | Type | Description |
|
|
1168
1094
|
| ------ | ------ | ------ |
|
|
1169
1095
|
| `contract` | `TContract` | The contract definition containing the consumers |
|
|
1170
|
-
| `handlers` | [`
|
|
1096
|
+
| `handlers` | [`WorkerInferConsumerHandlers`](#workerinferconsumerhandlers)<`TContract`> | An object with handler functions for each consumer |
|
|
1171
1097
|
|
|
1172
1098
|
#### Returns
|
|
1173
1099
|
|
|
1174
|
-
[`
|
|
1100
|
+
[`WorkerInferConsumerHandlers`](#workerinferconsumerhandlers)<`TContract`>
|
|
1175
1101
|
|
|
1176
1102
|
A type-safe handlers object that can be used with TypedAmqpWorker
|
|
1177
1103
|
|
|
@@ -1193,3 +1119,210 @@ const handlers = defineHandlers(orderContract, {
|
|
|
1193
1119
|
.mapError((error) => new RetryableError('Notification failed', error)),
|
|
1194
1120
|
});
|
|
1195
1121
|
```
|
|
1122
|
+
|
|
1123
|
+
***
|
|
1124
|
+
|
|
1125
|
+
### isHandlerError()
|
|
1126
|
+
|
|
1127
|
+
```ts
|
|
1128
|
+
function isHandlerError(error): error is HandlerError;
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1131
|
+
Defined in: [packages/worker/src/errors.ts:149](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L149)
|
|
1132
|
+
|
|
1133
|
+
Type guard to check if an error is any HandlerError (RetryableError or NonRetryableError).
|
|
1134
|
+
|
|
1135
|
+
#### Parameters
|
|
1136
|
+
|
|
1137
|
+
| Parameter | Type | Description |
|
|
1138
|
+
| ------ | ------ | ------ |
|
|
1139
|
+
| `error` | `unknown` | The error to check |
|
|
1140
|
+
|
|
1141
|
+
#### Returns
|
|
1142
|
+
|
|
1143
|
+
`error is HandlerError`
|
|
1144
|
+
|
|
1145
|
+
True if the error is a HandlerError
|
|
1146
|
+
|
|
1147
|
+
#### Example
|
|
1148
|
+
|
|
1149
|
+
```typescript
|
|
1150
|
+
import { isHandlerError } from '@amqp-contract/worker';
|
|
1151
|
+
|
|
1152
|
+
function handleError(error: unknown) {
|
|
1153
|
+
if (isHandlerError(error)) {
|
|
1154
|
+
// error is RetryableError | NonRetryableError
|
|
1155
|
+
console.log('Handler error:', error.name, error.message);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
```
|
|
1159
|
+
|
|
1160
|
+
***
|
|
1161
|
+
|
|
1162
|
+
### isNonRetryableError()
|
|
1163
|
+
|
|
1164
|
+
```ts
|
|
1165
|
+
function isNonRetryableError(error): error is NonRetryableError;
|
|
1166
|
+
```
|
|
1167
|
+
|
|
1168
|
+
Defined in: [packages/worker/src/errors.ts:127](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L127)
|
|
1169
|
+
|
|
1170
|
+
Type guard to check if an error is a NonRetryableError.
|
|
1171
|
+
|
|
1172
|
+
Use this to check error types in catch blocks or error handlers.
|
|
1173
|
+
|
|
1174
|
+
#### Parameters
|
|
1175
|
+
|
|
1176
|
+
| Parameter | Type | Description |
|
|
1177
|
+
| ------ | ------ | ------ |
|
|
1178
|
+
| `error` | `unknown` | The error to check |
|
|
1179
|
+
|
|
1180
|
+
#### Returns
|
|
1181
|
+
|
|
1182
|
+
`error is NonRetryableError`
|
|
1183
|
+
|
|
1184
|
+
True if the error is a NonRetryableError
|
|
1185
|
+
|
|
1186
|
+
#### Example
|
|
1187
|
+
|
|
1188
|
+
```typescript
|
|
1189
|
+
import { isNonRetryableError } from '@amqp-contract/worker';
|
|
1190
|
+
|
|
1191
|
+
try {
|
|
1192
|
+
await processMessage();
|
|
1193
|
+
} catch (error) {
|
|
1194
|
+
if (isNonRetryableError(error)) {
|
|
1195
|
+
console.log('Will not retry:', error.message);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
```
|
|
1199
|
+
|
|
1200
|
+
***
|
|
1201
|
+
|
|
1202
|
+
### isRetryableError()
|
|
1203
|
+
|
|
1204
|
+
```ts
|
|
1205
|
+
function isRetryableError(error): error is RetryableError;
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
Defined in: [packages/worker/src/errors.ts:102](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L102)
|
|
1209
|
+
|
|
1210
|
+
Type guard to check if an error is a RetryableError.
|
|
1211
|
+
|
|
1212
|
+
Use this to check error types in catch blocks or error handlers.
|
|
1213
|
+
|
|
1214
|
+
#### Parameters
|
|
1215
|
+
|
|
1216
|
+
| Parameter | Type | Description |
|
|
1217
|
+
| ------ | ------ | ------ |
|
|
1218
|
+
| `error` | `unknown` | The error to check |
|
|
1219
|
+
|
|
1220
|
+
#### Returns
|
|
1221
|
+
|
|
1222
|
+
`error is RetryableError`
|
|
1223
|
+
|
|
1224
|
+
True if the error is a RetryableError
|
|
1225
|
+
|
|
1226
|
+
#### Example
|
|
1227
|
+
|
|
1228
|
+
```typescript
|
|
1229
|
+
import { isRetryableError } from '@amqp-contract/worker';
|
|
1230
|
+
|
|
1231
|
+
try {
|
|
1232
|
+
await processMessage();
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
if (isRetryableError(error)) {
|
|
1235
|
+
console.log('Will retry:', error.message);
|
|
1236
|
+
} else {
|
|
1237
|
+
console.log('Permanent failure:', error);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
```
|
|
1241
|
+
|
|
1242
|
+
***
|
|
1243
|
+
|
|
1244
|
+
### nonRetryable()
|
|
1245
|
+
|
|
1246
|
+
```ts
|
|
1247
|
+
function nonRetryable(message, cause?): NonRetryableError;
|
|
1248
|
+
```
|
|
1249
|
+
|
|
1250
|
+
Defined in: [packages/worker/src/errors.ts:211](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L211)
|
|
1251
|
+
|
|
1252
|
+
Create a NonRetryableError with less verbosity.
|
|
1253
|
+
|
|
1254
|
+
This is a shorthand factory function for creating NonRetryableError instances.
|
|
1255
|
+
Use it for cleaner error creation in handlers.
|
|
1256
|
+
|
|
1257
|
+
#### Parameters
|
|
1258
|
+
|
|
1259
|
+
| Parameter | Type | Description |
|
|
1260
|
+
| ------ | ------ | ------ |
|
|
1261
|
+
| `message` | `string` | Error message describing the failure |
|
|
1262
|
+
| `cause?` | `unknown` | Optional underlying error that caused this failure |
|
|
1263
|
+
|
|
1264
|
+
#### Returns
|
|
1265
|
+
|
|
1266
|
+
[`NonRetryableError`](#nonretryableerror)
|
|
1267
|
+
|
|
1268
|
+
A new NonRetryableError instance
|
|
1269
|
+
|
|
1270
|
+
#### Example
|
|
1271
|
+
|
|
1272
|
+
```typescript
|
|
1273
|
+
import { nonRetryable } from '@amqp-contract/worker';
|
|
1274
|
+
import { Future, Result } from '@swan-io/boxed';
|
|
1275
|
+
|
|
1276
|
+
const handler = ({ payload }) => {
|
|
1277
|
+
if (!isValidPayload(payload)) {
|
|
1278
|
+
return Future.value(Result.Error(nonRetryable('Invalid payload format')));
|
|
1279
|
+
}
|
|
1280
|
+
return Future.value(Result.Ok(undefined));
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
// Equivalent to:
|
|
1284
|
+
// return Future.value(Result.Error(new NonRetryableError('Invalid payload format')));
|
|
1285
|
+
```
|
|
1286
|
+
|
|
1287
|
+
***
|
|
1288
|
+
|
|
1289
|
+
### retryable()
|
|
1290
|
+
|
|
1291
|
+
```ts
|
|
1292
|
+
function retryable(message, cause?): RetryableError;
|
|
1293
|
+
```
|
|
1294
|
+
|
|
1295
|
+
Defined in: [packages/worker/src/errors.ts:181](https://github.com/btravers/amqp-contract/blob/69a6467d137997be809af2ea5c4332c378579b49/packages/worker/src/errors.ts#L181)
|
|
1296
|
+
|
|
1297
|
+
Create a RetryableError with less verbosity.
|
|
1298
|
+
|
|
1299
|
+
This is a shorthand factory function for creating RetryableError instances.
|
|
1300
|
+
Use it for cleaner error creation in handlers.
|
|
1301
|
+
|
|
1302
|
+
#### Parameters
|
|
1303
|
+
|
|
1304
|
+
| Parameter | Type | Description |
|
|
1305
|
+
| ------ | ------ | ------ |
|
|
1306
|
+
| `message` | `string` | Error message describing the failure |
|
|
1307
|
+
| `cause?` | `unknown` | Optional underlying error that caused this failure |
|
|
1308
|
+
|
|
1309
|
+
#### Returns
|
|
1310
|
+
|
|
1311
|
+
[`RetryableError`](#retryableerror)
|
|
1312
|
+
|
|
1313
|
+
A new RetryableError instance
|
|
1314
|
+
|
|
1315
|
+
#### Example
|
|
1316
|
+
|
|
1317
|
+
```typescript
|
|
1318
|
+
import { retryable } from '@amqp-contract/worker';
|
|
1319
|
+
import { Future, Result } from '@swan-io/boxed';
|
|
1320
|
+
|
|
1321
|
+
const handler = ({ payload }) =>
|
|
1322
|
+
Future.fromPromise(processPayment(payload))
|
|
1323
|
+
.mapOk(() => undefined)
|
|
1324
|
+
.mapError((e) => retryable('Payment service unavailable', e));
|
|
1325
|
+
|
|
1326
|
+
// Equivalent to:
|
|
1327
|
+
// .mapError((e) => new RetryableError('Payment service unavailable', e));
|
|
1328
|
+
```
|