@amqp-contract/worker 0.24.0 → 0.25.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 +166 -99
- package/dist/index.d.cts +88 -54
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +88 -54
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +168 -102
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +564 -158
- package/package.json +4 -4
package/docs/index.md
CHANGED
|
@@ -6,6 +6,164 @@
|
|
|
6
6
|
|
|
7
7
|
## Classes
|
|
8
8
|
|
|
9
|
+
### `abstract` HandlerError
|
|
10
|
+
|
|
11
|
+
Defined in: [packages/worker/src/errors.ts:10](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L10)
|
|
12
|
+
|
|
13
|
+
Abstract base class for all handler-signalled errors.
|
|
14
|
+
|
|
15
|
+
Concrete subclasses (`RetryableError`, `NonRetryableError`) discriminate on
|
|
16
|
+
the `name` property so exhaustive narrowing in user code keeps working.
|
|
17
|
+
`error instanceof HandlerError` is true for any handler error.
|
|
18
|
+
|
|
19
|
+
#### Extends
|
|
20
|
+
|
|
21
|
+
- `Error`
|
|
22
|
+
|
|
23
|
+
#### Extended by
|
|
24
|
+
|
|
25
|
+
- [`NonRetryableError`](#nonretryableerror)
|
|
26
|
+
- [`RetryableError`](#retryableerror)
|
|
27
|
+
|
|
28
|
+
#### Constructors
|
|
29
|
+
|
|
30
|
+
##### Constructor
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
new HandlerError(message, cause?): HandlerError;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Defined in: [packages/worker/src/errors.ts:13](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L13)
|
|
37
|
+
|
|
38
|
+
###### Parameters
|
|
39
|
+
|
|
40
|
+
| Parameter | Type |
|
|
41
|
+
| ------ | ------ |
|
|
42
|
+
| `message` | `string` |
|
|
43
|
+
| `cause?` | `unknown` |
|
|
44
|
+
|
|
45
|
+
###### Returns
|
|
46
|
+
|
|
47
|
+
[`HandlerError`](#abstract-handlererror)
|
|
48
|
+
|
|
49
|
+
###### Overrides
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
Error.constructor
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Properties
|
|
56
|
+
|
|
57
|
+
| Property | Modifier | Type | Description | Overrides | Inherited from | Defined in |
|
|
58
|
+
| ------ | ------ | ------ | ------ | ------ | ------ | ------ |
|
|
59
|
+
| <a id="cause"></a> `cause?` | `readonly` | `unknown` | - | - | `Error.cause` | [packages/worker/src/errors.ts:15](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L15) |
|
|
60
|
+
| <a id="message"></a> `message` | `public` | `string` | - | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
61
|
+
| <a id="name"></a> `name` | `abstract` | `"RetryableError"` \| `"NonRetryableError"` | - | `Error.name` | - | [packages/worker/src/errors.ts:11](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L11) |
|
|
62
|
+
| <a id="stack"></a> `stack?` | `public` | `string` | - | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
63
|
+
| <a id="stacktracelimit"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | - | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
64
|
+
|
|
65
|
+
#### Methods
|
|
66
|
+
|
|
67
|
+
##### captureStackTrace()
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:52
|
|
74
|
+
|
|
75
|
+
Creates a `.stack` property on `targetObject`, which when accessed returns
|
|
76
|
+
a string representing the location in the code at which
|
|
77
|
+
`Error.captureStackTrace()` was called.
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
const myObject = {};
|
|
81
|
+
Error.captureStackTrace(myObject);
|
|
82
|
+
myObject.stack; // Similar to `new Error().stack`
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The first line of the trace will be prefixed with
|
|
86
|
+
`${myObject.name}: ${myObject.message}`.
|
|
87
|
+
|
|
88
|
+
The optional `constructorOpt` argument accepts a function. If given, all frames
|
|
89
|
+
above `constructorOpt`, including `constructorOpt`, will be omitted from the
|
|
90
|
+
generated stack trace.
|
|
91
|
+
|
|
92
|
+
The `constructorOpt` argument is useful for hiding implementation
|
|
93
|
+
details of error generation from the user. For instance:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
function a() {
|
|
97
|
+
b();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function b() {
|
|
101
|
+
c();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function c() {
|
|
105
|
+
// Create an error without stack trace to avoid calculating the stack trace twice.
|
|
106
|
+
const { stackTraceLimit } = Error;
|
|
107
|
+
Error.stackTraceLimit = 0;
|
|
108
|
+
const error = new Error();
|
|
109
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
110
|
+
|
|
111
|
+
// Capture the stack trace above function b
|
|
112
|
+
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
a();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
###### Parameters
|
|
120
|
+
|
|
121
|
+
| Parameter | Type |
|
|
122
|
+
| ------ | ------ |
|
|
123
|
+
| `targetObject` | `object` |
|
|
124
|
+
| `constructorOpt?` | `Function` |
|
|
125
|
+
|
|
126
|
+
###### Returns
|
|
127
|
+
|
|
128
|
+
`void`
|
|
129
|
+
|
|
130
|
+
###### Inherited from
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
Error.captureStackTrace
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
##### prepareStackTrace()
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
static prepareStackTrace(err, stackTraces): any;
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:56
|
|
143
|
+
|
|
144
|
+
###### Parameters
|
|
145
|
+
|
|
146
|
+
| Parameter | Type |
|
|
147
|
+
| ------ | ------ |
|
|
148
|
+
| `err` | `Error` |
|
|
149
|
+
| `stackTraces` | `CallSite`[] |
|
|
150
|
+
|
|
151
|
+
###### Returns
|
|
152
|
+
|
|
153
|
+
`any`
|
|
154
|
+
|
|
155
|
+
###### See
|
|
156
|
+
|
|
157
|
+
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
158
|
+
|
|
159
|
+
###### Inherited from
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
Error.prepareStackTrace
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
***
|
|
166
|
+
|
|
9
167
|
### MessageValidationError
|
|
10
168
|
|
|
11
169
|
Defined in: packages/core/dist/index.d.mts:27
|
|
@@ -58,13 +216,13 @@ Error.constructor
|
|
|
58
216
|
|
|
59
217
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
60
218
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
61
|
-
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
|
|
219
|
+
| <a id="cause-1"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
|
|
62
220
|
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | packages/core/dist/index.d.mts:29 |
|
|
63
|
-
| <a id="message"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
64
|
-
| <a id="name"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
221
|
+
| <a id="message-1"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
222
|
+
| <a id="name-1"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
65
223
|
| <a id="source"></a> `source` | `readonly` | `string` | - | - | packages/core/dist/index.d.mts:28 |
|
|
66
|
-
| <a id="stack"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
67
|
-
| <a id="stacktracelimit"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
224
|
+
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
225
|
+
| <a id="stacktracelimit-1"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
68
226
|
|
|
69
227
|
#### Methods
|
|
70
228
|
|
|
@@ -170,7 +328,7 @@ Error.prepareStackTrace
|
|
|
170
328
|
|
|
171
329
|
### NonRetryableError
|
|
172
330
|
|
|
173
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
331
|
+
Defined in: [packages/worker/src/errors.ts:46](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L46)
|
|
174
332
|
|
|
175
333
|
Non-retryable errors - permanent failures that should not be retried
|
|
176
334
|
Examples: invalid data, business rule violations, permanent external failures
|
|
@@ -180,7 +338,7 @@ immediately sent to the dead letter queue (DLQ) if configured.
|
|
|
180
338
|
|
|
181
339
|
#### Extends
|
|
182
340
|
|
|
183
|
-
- `
|
|
341
|
+
- [`HandlerError`](#abstract-handlererror)
|
|
184
342
|
|
|
185
343
|
#### Constructors
|
|
186
344
|
|
|
@@ -190,7 +348,7 @@ immediately sent to the dead letter queue (DLQ) if configured.
|
|
|
190
348
|
new NonRetryableError(message, cause?): NonRetryableError;
|
|
191
349
|
```
|
|
192
350
|
|
|
193
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
351
|
+
Defined in: [packages/worker/src/errors.ts:13](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L13)
|
|
194
352
|
|
|
195
353
|
###### Parameters
|
|
196
354
|
|
|
@@ -203,21 +361,19 @@ Defined in: [packages/worker/src/errors.ts:35](https://github.com/btravers/amqp-
|
|
|
203
361
|
|
|
204
362
|
[`NonRetryableError`](#nonretryableerror)
|
|
205
363
|
|
|
206
|
-
######
|
|
364
|
+
###### Inherited from
|
|
207
365
|
|
|
208
|
-
|
|
209
|
-
Error.constructor
|
|
210
|
-
```
|
|
366
|
+
[`HandlerError`](#abstract-handlererror).[`constructor`](#constructor)
|
|
211
367
|
|
|
212
368
|
#### Properties
|
|
213
369
|
|
|
214
|
-
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
215
|
-
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
216
|
-
| <a id="cause-
|
|
217
|
-
| <a id="message-
|
|
218
|
-
| <a id="name-
|
|
219
|
-
| <a id="stack-
|
|
220
|
-
| <a id="stacktracelimit-
|
|
370
|
+
| Property | Modifier | Type | Description | Overrides | Inherited from | Defined in |
|
|
371
|
+
| ------ | ------ | ------ | ------ | ------ | ------ | ------ |
|
|
372
|
+
| <a id="cause-2"></a> `cause?` | `readonly` | `unknown` | - | - | [`HandlerError`](#abstract-handlererror).[`cause`](#cause) | [packages/worker/src/errors.ts:15](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L15) |
|
|
373
|
+
| <a id="message-2"></a> `message` | `public` | `string` | - | - | [`HandlerError`](#abstract-handlererror).[`message`](#message) | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
374
|
+
| <a id="name-2"></a> `name` | `readonly` | `"NonRetryableError"` | - | [`HandlerError`](#abstract-handlererror).[`name`](#name) | - | [packages/worker/src/errors.ts:47](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L47) |
|
|
375
|
+
| <a id="stack-2"></a> `stack?` | `public` | `string` | - | - | [`HandlerError`](#abstract-handlererror).[`stack`](#stack) | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
376
|
+
| <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. | - | [`HandlerError`](#abstract-handlererror).[`stackTraceLimit`](#stacktracelimit) | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
221
377
|
|
|
222
378
|
#### Methods
|
|
223
379
|
|
|
@@ -286,9 +442,7 @@ a();
|
|
|
286
442
|
|
|
287
443
|
###### Inherited from
|
|
288
444
|
|
|
289
|
-
|
|
290
|
-
Error.captureStackTrace
|
|
291
|
-
```
|
|
445
|
+
[`HandlerError`](#abstract-handlererror).[`captureStackTrace`](#capturestacktrace)
|
|
292
446
|
|
|
293
447
|
##### prepareStackTrace()
|
|
294
448
|
|
|
@@ -315,15 +469,13 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
315
469
|
|
|
316
470
|
###### Inherited from
|
|
317
471
|
|
|
318
|
-
|
|
319
|
-
Error.prepareStackTrace
|
|
320
|
-
```
|
|
472
|
+
[`HandlerError`](#abstract-handlererror).[`prepareStackTrace`](#preparestacktrace)
|
|
321
473
|
|
|
322
474
|
***
|
|
323
475
|
|
|
324
476
|
### RetryableError
|
|
325
477
|
|
|
326
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
478
|
+
Defined in: [packages/worker/src/errors.ts:35](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L35)
|
|
327
479
|
|
|
328
480
|
Retryable errors - transient failures that may succeed on retry
|
|
329
481
|
Examples: network timeouts, rate limiting, temporary service unavailability
|
|
@@ -333,7 +485,7 @@ The worker will apply exponential backoff and retry the message.
|
|
|
333
485
|
|
|
334
486
|
#### Extends
|
|
335
487
|
|
|
336
|
-
- `
|
|
488
|
+
- [`HandlerError`](#abstract-handlererror)
|
|
337
489
|
|
|
338
490
|
#### Constructors
|
|
339
491
|
|
|
@@ -343,7 +495,7 @@ The worker will apply exponential backoff and retry the message.
|
|
|
343
495
|
new RetryableError(message, cause?): RetryableError;
|
|
344
496
|
```
|
|
345
497
|
|
|
346
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
498
|
+
Defined in: [packages/worker/src/errors.ts:13](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L13)
|
|
347
499
|
|
|
348
500
|
###### Parameters
|
|
349
501
|
|
|
@@ -356,21 +508,19 @@ Defined in: [packages/worker/src/errors.ts:11](https://github.com/btravers/amqp-
|
|
|
356
508
|
|
|
357
509
|
[`RetryableError`](#retryableerror)
|
|
358
510
|
|
|
359
|
-
######
|
|
511
|
+
###### Inherited from
|
|
360
512
|
|
|
361
|
-
|
|
362
|
-
Error.constructor
|
|
363
|
-
```
|
|
513
|
+
[`HandlerError`](#abstract-handlererror).[`constructor`](#constructor)
|
|
364
514
|
|
|
365
515
|
#### Properties
|
|
366
516
|
|
|
367
|
-
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
368
|
-
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
369
|
-
| <a id="cause-
|
|
370
|
-
| <a id="message-
|
|
371
|
-
| <a id="name-
|
|
372
|
-
| <a id="stack-
|
|
373
|
-
| <a id="stacktracelimit-
|
|
517
|
+
| Property | Modifier | Type | Description | Overrides | Inherited from | Defined in |
|
|
518
|
+
| ------ | ------ | ------ | ------ | ------ | ------ | ------ |
|
|
519
|
+
| <a id="cause-3"></a> `cause?` | `readonly` | `unknown` | - | - | [`HandlerError`](#abstract-handlererror).[`cause`](#cause) | [packages/worker/src/errors.ts:15](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L15) |
|
|
520
|
+
| <a id="message-3"></a> `message` | `public` | `string` | - | - | [`HandlerError`](#abstract-handlererror).[`message`](#message) | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
521
|
+
| <a id="name-3"></a> `name` | `readonly` | `"RetryableError"` | - | [`HandlerError`](#abstract-handlererror).[`name`](#name) | - | [packages/worker/src/errors.ts:36](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L36) |
|
|
522
|
+
| <a id="stack-3"></a> `stack?` | `public` | `string` | - | - | [`HandlerError`](#abstract-handlererror).[`stack`](#stack) | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
523
|
+
| <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. | - | [`HandlerError`](#abstract-handlererror).[`stackTraceLimit`](#stacktracelimit) | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
374
524
|
|
|
375
525
|
#### Methods
|
|
376
526
|
|
|
@@ -439,9 +589,7 @@ a();
|
|
|
439
589
|
|
|
440
590
|
###### Inherited from
|
|
441
591
|
|
|
442
|
-
|
|
443
|
-
Error.captureStackTrace
|
|
444
|
-
```
|
|
592
|
+
[`HandlerError`](#abstract-handlererror).[`captureStackTrace`](#capturestacktrace)
|
|
445
593
|
|
|
446
594
|
##### prepareStackTrace()
|
|
447
595
|
|
|
@@ -468,15 +616,13 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
468
616
|
|
|
469
617
|
###### Inherited from
|
|
470
618
|
|
|
471
|
-
|
|
472
|
-
Error.prepareStackTrace
|
|
473
|
-
```
|
|
619
|
+
[`HandlerError`](#abstract-handlererror).[`prepareStackTrace`](#preparestacktrace)
|
|
474
620
|
|
|
475
621
|
***
|
|
476
622
|
|
|
477
623
|
### TypedAmqpWorker
|
|
478
624
|
|
|
479
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
625
|
+
Defined in: [packages/worker/src/worker.ts:182](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L182)
|
|
480
626
|
|
|
481
627
|
Type-safe AMQP worker for consuming messages from RabbitMQ.
|
|
482
628
|
|
|
@@ -535,7 +681,7 @@ await worker.close();
|
|
|
535
681
|
close(): ResultAsync<void, TechnicalError>;
|
|
536
682
|
```
|
|
537
683
|
|
|
538
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
684
|
+
Defined in: [packages/worker/src/worker.ts:342](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L342)
|
|
539
685
|
|
|
540
686
|
Close the AMQP channel and connection.
|
|
541
687
|
|
|
@@ -561,7 +707,7 @@ if (closeResult.isOk()) {
|
|
|
561
707
|
static create<TContract>(__namedParameters): ResultAsync<TypedAmqpWorker<TContract>, TechnicalError>;
|
|
562
708
|
```
|
|
563
709
|
|
|
564
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
710
|
+
Defined in: [packages/worker/src/worker.ts:281](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L281)
|
|
565
711
|
|
|
566
712
|
Create a type-safe AMQP worker from a contract.
|
|
567
713
|
|
|
@@ -611,7 +757,7 @@ const result = await TypedAmqpWorker.create({
|
|
|
611
757
|
type ConsumerOptions = AmqpClientConsumerOptions;
|
|
612
758
|
```
|
|
613
759
|
|
|
614
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
760
|
+
Defined in: [packages/worker/src/worker.ts:50](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L50)
|
|
615
761
|
|
|
616
762
|
***
|
|
617
763
|
|
|
@@ -621,7 +767,7 @@ Defined in: [packages/worker/src/worker.ts:49](https://github.com/btravers/amqp-
|
|
|
621
767
|
type CreateWorkerOptions<TContract> = object;
|
|
622
768
|
```
|
|
623
769
|
|
|
624
|
-
Defined in: [packages/worker/src/worker.ts:
|
|
770
|
+
Defined in: [packages/worker/src/worker.ts:97](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L97)
|
|
625
771
|
|
|
626
772
|
Options for creating a type-safe AMQP worker.
|
|
627
773
|
|
|
@@ -669,29 +815,14 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
|
|
|
669
815
|
|
|
670
816
|
| Property | Type | Description | Defined in |
|
|
671
817
|
| ------ | ------ | ------ | ------ |
|
|
672
|
-
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:
|
|
673
|
-
| <a id="connecttimeoutms"></a> `connectTimeoutMs?` | `number` \| `null` | Maximum time in ms to wait for the AMQP connection to become ready before `create()` resolves to an `err(TechnicalError)`. Defaults to 30s (the [AmqpClient](https://btravers.github.io/amqp-contract/api/core#amqpclient)'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to disable the timeout and let amqp-connection-manager retry indefinitely. | [packages/worker/src/worker.ts:
|
|
674
|
-
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:
|
|
675
|
-
| <a id="defaultconsumeroptions"></a> `defaultConsumerOptions?` | [`ConsumerOptions`](#consumeroptions) | Optional default consumer options applied to all consumer handlers. Handler-specific options provided in tuple form override these defaults. | [packages/worker/src/worker.ts:
|
|
676
|
-
| <a id="handlers"></a> `handlers` | `WorkerInferHandlers
|
|
677
|
-
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:
|
|
678
|
-
| <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:
|
|
679
|
-
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:
|
|
680
|
-
|
|
681
|
-
***
|
|
682
|
-
|
|
683
|
-
### HandlerError
|
|
684
|
-
|
|
685
|
-
```ts
|
|
686
|
-
type HandlerError =
|
|
687
|
-
| RetryableError
|
|
688
|
-
| NonRetryableError;
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
Defined in: [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/1ba3d51bb1d4a09c356afad101dc9e6e6d605185/packages/worker/src/errors.ts#L55)
|
|
692
|
-
|
|
693
|
-
Union type representing all handler errors.
|
|
694
|
-
Use this type when defining handlers that explicitly signal error outcomes.
|
|
818
|
+
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:114](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L114) |
|
|
819
|
+
| <a id="connecttimeoutms"></a> `connectTimeoutMs?` | `number` \| `null` | Maximum time in ms to wait for the AMQP connection to become ready before `create()` resolves to an `err(TechnicalError)`. Defaults to 30s (the [AmqpClient](https://btravers.github.io/amqp-contract/api/core#amqpclient)'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to disable the timeout and let amqp-connection-manager retry indefinitely. | [packages/worker/src/worker.ts:134](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L134) |
|
|
820
|
+
| <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:99](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L99) |
|
|
821
|
+
| <a id="defaultconsumeroptions"></a> `defaultConsumerOptions?` | [`ConsumerOptions`](#consumeroptions) | Optional default consumer options applied to all consumer handlers. Handler-specific options provided in tuple form override these defaults. | [packages/worker/src/worker.ts:127](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L127) |
|
|
822
|
+
| <a id="handlers"></a> `handlers` | [`WorkerInferHandlers`](#workerinferhandlers)<`TContract`> | Handlers for each `consumers` and `rpcs` entry in the contract. - Regular consumers return `ResultAsync<void, HandlerError>`. - RPC handlers return `ResultAsync<TResponse, HandlerError>` where `TResponse` is inferred from the RPC's response message schema. Use `defineHandler` / `defineHandlers` to create handlers with full type inference. | [packages/worker/src/worker.ts:110](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L110) |
|
|
823
|
+
| <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:116](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L116) |
|
|
824
|
+
| <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:122](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L122) |
|
|
825
|
+
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:112](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L112) |
|
|
695
826
|
|
|
696
827
|
***
|
|
697
828
|
|
|
@@ -701,7 +832,7 @@ Use this type when defining handlers that explicitly signal error outcomes.
|
|
|
701
832
|
type WorkerConsumedMessage<TPayload, THeaders> = object;
|
|
702
833
|
```
|
|
703
834
|
|
|
704
|
-
Defined in: [packages/worker/src/types.ts:156](https://github.com/btravers/amqp-contract/blob/
|
|
835
|
+
Defined in: [packages/worker/src/types.ts:156](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L156)
|
|
705
836
|
|
|
706
837
|
A consumed message containing parsed payload and headers.
|
|
707
838
|
|
|
@@ -730,8 +861,8 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
|
|
|
730
861
|
|
|
731
862
|
| Property | Type | Description | Defined in |
|
|
732
863
|
| ------ | ------ | ------ | ------ |
|
|
733
|
-
| <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:160](https://github.com/btravers/amqp-contract/blob/
|
|
734
|
-
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:158](https://github.com/btravers/amqp-contract/blob/
|
|
864
|
+
| <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:160](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L160) |
|
|
865
|
+
| <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:158](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L158) |
|
|
735
866
|
|
|
736
867
|
***
|
|
737
868
|
|
|
@@ -741,7 +872,7 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
|
|
|
741
872
|
type WorkerInferConsumedMessage<TContract, TName> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
|
|
742
873
|
```
|
|
743
874
|
|
|
744
|
-
Defined in: [packages/worker/src/types.ts:166](https://github.com/btravers/amqp-contract/blob/
|
|
875
|
+
Defined in: [packages/worker/src/types.ts:166](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L166)
|
|
745
876
|
|
|
746
877
|
Infer the full consumed message type for a regular consumer.
|
|
747
878
|
|
|
@@ -760,7 +891,7 @@ Infer the full consumed message type for a regular consumer.
|
|
|
760
891
|
type WorkerInferConsumerHandler<TContract, TName> = (message, rawMessage) => ResultAsync<void, HandlerError>;
|
|
761
892
|
```
|
|
762
893
|
|
|
763
|
-
Defined in: [packages/worker/src/types.ts:197](https://github.com/btravers/amqp-contract/blob/
|
|
894
|
+
Defined in: [packages/worker/src/types.ts:197](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L197)
|
|
764
895
|
|
|
765
896
|
Handler signature for a regular consumer (event/command). Returns
|
|
766
897
|
`ResultAsync<void, HandlerError>` — there is no response message.
|
|
@@ -781,7 +912,7 @@ Handler signature for a regular consumer (event/command). Returns
|
|
|
781
912
|
|
|
782
913
|
#### Returns
|
|
783
914
|
|
|
784
|
-
`ResultAsync`<`void`, [`HandlerError`](#handlererror)>
|
|
915
|
+
`ResultAsync`<`void`, [`HandlerError`](#abstract-handlererror)>
|
|
785
916
|
|
|
786
917
|
***
|
|
787
918
|
|
|
@@ -793,7 +924,7 @@ type WorkerInferConsumerHandlerEntry<TContract, TName> =
|
|
|
793
924
|
| readonly [WorkerInferConsumerHandler<TContract, TName>, ConsumerOptions];
|
|
794
925
|
```
|
|
795
926
|
|
|
796
|
-
Defined in: [packages/worker/src/types.ts:223](https://github.com/btravers/amqp-contract/blob/
|
|
927
|
+
Defined in: [packages/worker/src/types.ts:223](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L223)
|
|
797
928
|
|
|
798
929
|
Handler entry for a regular consumer — function or `[handler, options]`.
|
|
799
930
|
|
|
@@ -806,43 +937,190 @@ Handler entry for a regular consumer — function or `[handler, options]`.
|
|
|
806
937
|
|
|
807
938
|
***
|
|
808
939
|
|
|
809
|
-
###
|
|
940
|
+
### WorkerInferConsumerHeaders
|
|
941
|
+
|
|
942
|
+
```ts
|
|
943
|
+
type WorkerInferConsumerHeaders<TContract, TName> = ConsumerInferHeadersOutput<InferConsumer<TContract, TName>>;
|
|
944
|
+
```
|
|
945
|
+
|
|
946
|
+
Defined in: [packages/worker/src/types.ts:85](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L85)
|
|
947
|
+
|
|
948
|
+
Infer the headers type for a regular consumer.
|
|
949
|
+
Returns undefined if no headers schema is defined.
|
|
950
|
+
|
|
951
|
+
#### Type Parameters
|
|
952
|
+
|
|
953
|
+
| Type Parameter |
|
|
954
|
+
| ------ |
|
|
955
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
956
|
+
| `TName` *extends* `InferConsumerNames`<`TContract`> |
|
|
957
|
+
|
|
958
|
+
***
|
|
959
|
+
|
|
960
|
+
### WorkerInferHandlers
|
|
961
|
+
|
|
962
|
+
```ts
|
|
963
|
+
type WorkerInferHandlers<TContract> = [InferConsumerNames<TContract>] extends [never] ? object : { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> } & [InferRpcNames<TContract>] extends [never] ? object : { [K in InferRpcNames<TContract>]: WorkerInferRpcHandlerEntry<TContract, K> };
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
Defined in: [packages/worker/src/types.ts:257](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L257)
|
|
967
|
+
|
|
968
|
+
All handlers for a contract: one entry per `consumers` key plus one entry
|
|
969
|
+
per `rpcs` key. The two name spaces are disjoint so the resulting object
|
|
970
|
+
type is unambiguous.
|
|
971
|
+
|
|
972
|
+
#### Type Parameters
|
|
973
|
+
|
|
974
|
+
| Type Parameter |
|
|
975
|
+
| ------ |
|
|
976
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
977
|
+
|
|
978
|
+
#### Example
|
|
979
|
+
|
|
980
|
+
```typescript
|
|
981
|
+
const handlers: WorkerInferHandlers<typeof contract> = {
|
|
982
|
+
processOrder: ({ payload }) =>
|
|
983
|
+
ResultAsync.fromPromise(
|
|
984
|
+
processPayment(payload),
|
|
985
|
+
(error) => new RetryableError('Payment failed', error),
|
|
986
|
+
).map(() => undefined),
|
|
987
|
+
calculate: ({ payload }) => okAsync({ sum: payload.a + payload.b }),
|
|
988
|
+
};
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
***
|
|
992
|
+
|
|
993
|
+
### WorkerInferRpcConsumedMessage
|
|
810
994
|
|
|
811
995
|
```ts
|
|
812
|
-
type
|
|
996
|
+
type WorkerInferRpcConsumedMessage<TContract, TName> = WorkerConsumedMessage<WorkerInferRpcRequest<TContract, TName>, WorkerInferRpcHeaders<TContract, TName>>;
|
|
813
997
|
```
|
|
814
998
|
|
|
815
|
-
Defined in: [packages/worker/src/types.ts:
|
|
999
|
+
Defined in: [packages/worker/src/types.ts:178](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L178)
|
|
1000
|
+
|
|
1001
|
+
Infer the consumed message type for an RPC handler — payload + headers from
|
|
1002
|
+
the request side of the RPC.
|
|
816
1003
|
|
|
817
1004
|
#### Type Parameters
|
|
818
1005
|
|
|
819
1006
|
| Type Parameter |
|
|
820
1007
|
| ------ |
|
|
821
1008
|
| `TContract` *extends* `ContractDefinition` |
|
|
1009
|
+
| `TName` *extends* `InferRpcNames`<`TContract`> |
|
|
822
1010
|
|
|
823
|
-
|
|
1011
|
+
***
|
|
824
1012
|
|
|
825
|
-
|
|
1013
|
+
### WorkerInferRpcHandler
|
|
1014
|
+
|
|
1015
|
+
```ts
|
|
1016
|
+
type WorkerInferRpcHandler<TContract, TName> = (message, rawMessage) => ResultAsync<WorkerInferRpcResponse<TContract, TName>, HandlerError>;
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
Defined in: [packages/worker/src/types.ts:212](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L212)
|
|
1020
|
+
|
|
1021
|
+
Handler signature for an RPC. Returns
|
|
1022
|
+
`ResultAsync<TResponse, HandlerError>` where `TResponse` is the inferred
|
|
1023
|
+
response payload. The worker validates the response against the RPC's
|
|
1024
|
+
response schema and publishes it back to `msg.properties.replyTo` with the
|
|
1025
|
+
same `correlationId`.
|
|
1026
|
+
|
|
1027
|
+
#### Type Parameters
|
|
1028
|
+
|
|
1029
|
+
| Type Parameter |
|
|
1030
|
+
| ------ |
|
|
1031
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
1032
|
+
| `TName` *extends* `InferRpcNames`<`TContract`> |
|
|
1033
|
+
|
|
1034
|
+
#### Parameters
|
|
1035
|
+
|
|
1036
|
+
| Parameter | Type |
|
|
1037
|
+
| ------ | ------ |
|
|
1038
|
+
| `message` | [`WorkerInferRpcConsumedMessage`](#workerinferrpcconsumedmessage)<`TContract`, `TName`> |
|
|
1039
|
+
| `rawMessage` | `ConsumeMessage` |
|
|
1040
|
+
|
|
1041
|
+
#### Returns
|
|
1042
|
+
|
|
1043
|
+
`ResultAsync`<[`WorkerInferRpcResponse`](#workerinferrpcresponse)<`TContract`, `TName`>, [`HandlerError`](#abstract-handlererror)>
|
|
826
1044
|
|
|
827
1045
|
***
|
|
828
1046
|
|
|
829
|
-
###
|
|
1047
|
+
### WorkerInferRpcHandlerEntry
|
|
830
1048
|
|
|
831
1049
|
```ts
|
|
832
|
-
type
|
|
1050
|
+
type WorkerInferRpcHandlerEntry<TContract, TName> =
|
|
1051
|
+
| WorkerInferRpcHandler<TContract, TName>
|
|
1052
|
+
| readonly [WorkerInferRpcHandler<TContract, TName>, ConsumerOptions];
|
|
833
1053
|
```
|
|
834
1054
|
|
|
835
|
-
Defined in: [packages/worker/src/types.ts:
|
|
1055
|
+
Defined in: [packages/worker/src/types.ts:233](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L233)
|
|
836
1056
|
|
|
837
|
-
|
|
838
|
-
Returns undefined if no headers schema is defined.
|
|
1057
|
+
Handler entry for an RPC — function or `[handler, options]`.
|
|
839
1058
|
|
|
840
1059
|
#### Type Parameters
|
|
841
1060
|
|
|
842
1061
|
| Type Parameter |
|
|
843
1062
|
| ------ |
|
|
844
1063
|
| `TContract` *extends* `ContractDefinition` |
|
|
845
|
-
| `TName` *extends* `
|
|
1064
|
+
| `TName` *extends* `InferRpcNames`<`TContract`> |
|
|
1065
|
+
|
|
1066
|
+
***
|
|
1067
|
+
|
|
1068
|
+
### WorkerInferRpcHeaders
|
|
1069
|
+
|
|
1070
|
+
```ts
|
|
1071
|
+
type WorkerInferRpcHeaders<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<infer TRequest, MessageDefinition> ? TRequest extends MessageDefinition<infer _TPayload, infer THeaders> ? THeaders extends StandardSchemaV1<Record<string, unknown>> ? InferSchemaOutput<THeaders> : undefined : undefined : undefined;
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
Defined in: [packages/worker/src/types.ts:107](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L107)
|
|
1075
|
+
|
|
1076
|
+
Infer the request headers type for an RPC. Returns undefined unless the RPC's
|
|
1077
|
+
request `MessageDefinition` declares a headers schema.
|
|
1078
|
+
|
|
1079
|
+
#### Type Parameters
|
|
1080
|
+
|
|
1081
|
+
| Type Parameter |
|
|
1082
|
+
| ------ |
|
|
1083
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
1084
|
+
| `TName` *extends* `InferRpcNames`<`TContract`> |
|
|
1085
|
+
|
|
1086
|
+
***
|
|
1087
|
+
|
|
1088
|
+
### WorkerInferRpcRequest
|
|
1089
|
+
|
|
1090
|
+
```ts
|
|
1091
|
+
type WorkerInferRpcRequest<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<infer TRequest, MessageDefinition> ? TRequest extends MessageDefinition ? InferSchemaOutput<TRequest["payload"]> : never : never;
|
|
1092
|
+
```
|
|
1093
|
+
|
|
1094
|
+
Defined in: [packages/worker/src/types.ts:93](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L93)
|
|
1095
|
+
|
|
1096
|
+
Infer the request payload type for an RPC.
|
|
1097
|
+
|
|
1098
|
+
#### Type Parameters
|
|
1099
|
+
|
|
1100
|
+
| Type Parameter |
|
|
1101
|
+
| ------ |
|
|
1102
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
1103
|
+
| `TName` *extends* `InferRpcNames`<`TContract`> |
|
|
1104
|
+
|
|
1105
|
+
***
|
|
1106
|
+
|
|
1107
|
+
### WorkerInferRpcResponse
|
|
1108
|
+
|
|
1109
|
+
```ts
|
|
1110
|
+
type WorkerInferRpcResponse<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<MessageDefinition, infer TResponse> ? TResponse extends MessageDefinition ? InferSchemaOutput<TResponse["payload"]> : never : never;
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
Defined in: [packages/worker/src/types.ts:123](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L123)
|
|
1114
|
+
|
|
1115
|
+
Infer the response payload type for an RPC. The handler must return a
|
|
1116
|
+
`ResultAsync<TResponse, HandlerError>` matching this shape.
|
|
1117
|
+
|
|
1118
|
+
#### Type Parameters
|
|
1119
|
+
|
|
1120
|
+
| Type Parameter |
|
|
1121
|
+
| ------ |
|
|
1122
|
+
| `TContract` *extends* `ContractDefinition` |
|
|
1123
|
+
| `TName` *extends* `InferRpcNames`<`TContract`> |
|
|
846
1124
|
|
|
847
1125
|
## Functions
|
|
848
1126
|
|
|
@@ -853,35 +1131,37 @@ Returns undefined if no headers schema is defined.
|
|
|
853
1131
|
```ts
|
|
854
1132
|
function defineHandler<TContract, TName>(
|
|
855
1133
|
contract,
|
|
856
|
-
|
|
1134
|
+
name,
|
|
857
1135
|
handler): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
858
1136
|
```
|
|
859
1137
|
|
|
860
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
1138
|
+
Defined in: [packages/worker/src/handlers.ts:121](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/handlers.ts#L121)
|
|
861
1139
|
|
|
862
|
-
Define a type-safe handler for a specific consumer in a contract.
|
|
1140
|
+
Define a type-safe handler for a specific consumer or RPC in a contract.
|
|
863
1141
|
|
|
864
|
-
**Recommended:** This function creates handlers that return
|
|
865
|
-
|
|
1142
|
+
**Recommended:** This function creates handlers that return
|
|
1143
|
+
`ResultAsync<void, HandlerError>` (consumers) or
|
|
1144
|
+
`ResultAsync<TResponse, HandlerError>` (RPCs), providing explicit error
|
|
1145
|
+
handling and better control over retry behavior.
|
|
866
1146
|
|
|
867
1147
|
Supports two patterns:
|
|
868
1148
|
1. Simple handler: just the function
|
|
869
|
-
2. Handler with options: [handler,
|
|
1149
|
+
2. Handler with options: `[handler, { prefetch: 10 }]`
|
|
870
1150
|
|
|
871
1151
|
##### Type Parameters
|
|
872
1152
|
|
|
873
1153
|
| Type Parameter | Description |
|
|
874
1154
|
| ------ | ------ |
|
|
875
1155
|
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
876
|
-
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
1156
|
+
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer or RPC name from the contract |
|
|
877
1157
|
|
|
878
1158
|
##### Parameters
|
|
879
1159
|
|
|
880
1160
|
| Parameter | Type | Description |
|
|
881
1161
|
| ------ | ------ | ------ |
|
|
882
|
-
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
883
|
-
| `
|
|
884
|
-
| `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)<`TContract`, `TName`> | The handler function
|
|
1162
|
+
| `contract` | `TContract` | The contract definition containing the consumer or RPC |
|
|
1163
|
+
| `name` | `TName` | The name of the consumer or RPC from the contract |
|
|
1164
|
+
| `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)<`TContract`, `TName`> | The handler function — for consumers, returns `ResultAsync<void, HandlerError>`; for RPCs, returns `ResultAsync<TResponse, HandlerError>`. |
|
|
885
1165
|
|
|
886
1166
|
##### Returns
|
|
887
1167
|
|
|
@@ -889,14 +1169,12 @@ Supports two patterns:
|
|
|
889
1169
|
|
|
890
1170
|
A type-safe handler that can be used with TypedAmqpWorker
|
|
891
1171
|
|
|
892
|
-
#####
|
|
1172
|
+
##### Examples
|
|
893
1173
|
|
|
894
1174
|
```typescript
|
|
895
1175
|
import { defineHandler, RetryableError, NonRetryableError } from '@amqp-contract/worker';
|
|
896
1176
|
import { errAsync, okAsync, ResultAsync } from 'neverthrow';
|
|
897
|
-
import { orderContract } from './contract';
|
|
898
1177
|
|
|
899
|
-
// Simple handler with explicit error handling
|
|
900
1178
|
const processOrderHandler = defineHandler(
|
|
901
1179
|
orderContract,
|
|
902
1180
|
'processOrder',
|
|
@@ -906,18 +1184,13 @@ const processOrderHandler = defineHandler(
|
|
|
906
1184
|
(error) => new RetryableError('Payment failed', error),
|
|
907
1185
|
).map(() => undefined),
|
|
908
1186
|
);
|
|
1187
|
+
```
|
|
909
1188
|
|
|
910
|
-
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
'
|
|
914
|
-
({ payload }) => {
|
|
915
|
-
if (payload.amount < 1) {
|
|
916
|
-
// Won't be retried - goes directly to DLQ
|
|
917
|
-
return errAsync(new NonRetryableError('Invalid order amount'));
|
|
918
|
-
}
|
|
919
|
-
return okAsync(undefined);
|
|
920
|
-
},
|
|
1189
|
+
```typescript
|
|
1190
|
+
const calculateHandler = defineHandler(
|
|
1191
|
+
rpcContract,
|
|
1192
|
+
'calculate',
|
|
1193
|
+
({ payload }) => okAsync({ sum: payload.a + payload.b }),
|
|
921
1194
|
);
|
|
922
1195
|
```
|
|
923
1196
|
|
|
@@ -926,36 +1199,38 @@ const validateOrderHandler = defineHandler(
|
|
|
926
1199
|
```ts
|
|
927
1200
|
function defineHandler<TContract, TName>(
|
|
928
1201
|
contract,
|
|
929
|
-
|
|
1202
|
+
name,
|
|
930
1203
|
handler,
|
|
931
1204
|
options): WorkerInferConsumerHandlerEntry<TContract, TName>;
|
|
932
1205
|
```
|
|
933
1206
|
|
|
934
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
1207
|
+
Defined in: [packages/worker/src/handlers.ts:129](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/handlers.ts#L129)
|
|
935
1208
|
|
|
936
|
-
Define a type-safe handler for a specific consumer in a contract.
|
|
1209
|
+
Define a type-safe handler for a specific consumer or RPC in a contract.
|
|
937
1210
|
|
|
938
|
-
**Recommended:** This function creates handlers that return
|
|
939
|
-
|
|
1211
|
+
**Recommended:** This function creates handlers that return
|
|
1212
|
+
`ResultAsync<void, HandlerError>` (consumers) or
|
|
1213
|
+
`ResultAsync<TResponse, HandlerError>` (RPCs), providing explicit error
|
|
1214
|
+
handling and better control over retry behavior.
|
|
940
1215
|
|
|
941
1216
|
Supports two patterns:
|
|
942
1217
|
1. Simple handler: just the function
|
|
943
|
-
2. Handler with options: [handler,
|
|
1218
|
+
2. Handler with options: `[handler, { prefetch: 10 }]`
|
|
944
1219
|
|
|
945
1220
|
##### Type Parameters
|
|
946
1221
|
|
|
947
1222
|
| Type Parameter | Description |
|
|
948
1223
|
| ------ | ------ |
|
|
949
1224
|
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
950
|
-
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer name from the contract |
|
|
1225
|
+
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer or RPC name from the contract |
|
|
951
1226
|
|
|
952
1227
|
##### Parameters
|
|
953
1228
|
|
|
954
1229
|
| Parameter | Type | Description |
|
|
955
1230
|
| ------ | ------ | ------ |
|
|
956
|
-
| `contract` | `TContract` | The contract definition containing the consumer |
|
|
957
|
-
| `
|
|
958
|
-
| `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)<`TContract`, `TName`> | The handler function
|
|
1231
|
+
| `contract` | `TContract` | The contract definition containing the consumer or RPC |
|
|
1232
|
+
| `name` | `TName` | The name of the consumer or RPC from the contract |
|
|
1233
|
+
| `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)<`TContract`, `TName`> | The handler function — for consumers, returns `ResultAsync<void, HandlerError>`; for RPCs, returns `ResultAsync<TResponse, HandlerError>`. |
|
|
959
1234
|
| `options` | `ConsumerOptions` | Optional consumer options (prefetch) |
|
|
960
1235
|
|
|
961
1236
|
##### Returns
|
|
@@ -964,14 +1239,12 @@ Supports two patterns:
|
|
|
964
1239
|
|
|
965
1240
|
A type-safe handler that can be used with TypedAmqpWorker
|
|
966
1241
|
|
|
967
|
-
#####
|
|
1242
|
+
##### Examples
|
|
968
1243
|
|
|
969
1244
|
```typescript
|
|
970
1245
|
import { defineHandler, RetryableError, NonRetryableError } from '@amqp-contract/worker';
|
|
971
1246
|
import { errAsync, okAsync, ResultAsync } from 'neverthrow';
|
|
972
|
-
import { orderContract } from './contract';
|
|
973
1247
|
|
|
974
|
-
// Simple handler with explicit error handling
|
|
975
1248
|
const processOrderHandler = defineHandler(
|
|
976
1249
|
orderContract,
|
|
977
1250
|
'processOrder',
|
|
@@ -981,18 +1254,151 @@ const processOrderHandler = defineHandler(
|
|
|
981
1254
|
(error) => new RetryableError('Payment failed', error),
|
|
982
1255
|
).map(() => undefined),
|
|
983
1256
|
);
|
|
1257
|
+
```
|
|
1258
|
+
|
|
1259
|
+
```typescript
|
|
1260
|
+
const calculateHandler = defineHandler(
|
|
1261
|
+
rpcContract,
|
|
1262
|
+
'calculate',
|
|
1263
|
+
({ payload }) => okAsync({ sum: payload.a + payload.b }),
|
|
1264
|
+
);
|
|
1265
|
+
```
|
|
984
1266
|
|
|
985
|
-
|
|
986
|
-
|
|
1267
|
+
#### Call Signature
|
|
1268
|
+
|
|
1269
|
+
```ts
|
|
1270
|
+
function defineHandler<TContract, TName>(
|
|
1271
|
+
contract,
|
|
1272
|
+
name,
|
|
1273
|
+
handler): WorkerInferRpcHandlerEntry<TContract, TName>;
|
|
1274
|
+
```
|
|
1275
|
+
|
|
1276
|
+
Defined in: [packages/worker/src/handlers.ts:138](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/handlers.ts#L138)
|
|
1277
|
+
|
|
1278
|
+
Define a type-safe handler for a specific consumer or RPC in a contract.
|
|
1279
|
+
|
|
1280
|
+
**Recommended:** This function creates handlers that return
|
|
1281
|
+
`ResultAsync<void, HandlerError>` (consumers) or
|
|
1282
|
+
`ResultAsync<TResponse, HandlerError>` (RPCs), providing explicit error
|
|
1283
|
+
handling and better control over retry behavior.
|
|
1284
|
+
|
|
1285
|
+
Supports two patterns:
|
|
1286
|
+
1. Simple handler: just the function
|
|
1287
|
+
2. Handler with options: `[handler, { prefetch: 10 }]`
|
|
1288
|
+
|
|
1289
|
+
##### Type Parameters
|
|
1290
|
+
|
|
1291
|
+
| Type Parameter | Description |
|
|
1292
|
+
| ------ | ------ |
|
|
1293
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1294
|
+
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer or RPC name from the contract |
|
|
1295
|
+
|
|
1296
|
+
##### Parameters
|
|
1297
|
+
|
|
1298
|
+
| Parameter | Type | Description |
|
|
1299
|
+
| ------ | ------ | ------ |
|
|
1300
|
+
| `contract` | `TContract` | The contract definition containing the consumer or RPC |
|
|
1301
|
+
| `name` | `TName` | The name of the consumer or RPC from the contract |
|
|
1302
|
+
| `handler` | [`WorkerInferRpcHandler`](#workerinferrpchandler)<`TContract`, `TName`> | The handler function — for consumers, returns `ResultAsync<void, HandlerError>`; for RPCs, returns `ResultAsync<TResponse, HandlerError>`. |
|
|
1303
|
+
|
|
1304
|
+
##### Returns
|
|
1305
|
+
|
|
1306
|
+
[`WorkerInferRpcHandlerEntry`](#workerinferrpchandlerentry)<`TContract`, `TName`>
|
|
1307
|
+
|
|
1308
|
+
A type-safe handler that can be used with TypedAmqpWorker
|
|
1309
|
+
|
|
1310
|
+
##### Examples
|
|
1311
|
+
|
|
1312
|
+
```typescript
|
|
1313
|
+
import { defineHandler, RetryableError, NonRetryableError } from '@amqp-contract/worker';
|
|
1314
|
+
import { errAsync, okAsync, ResultAsync } from 'neverthrow';
|
|
1315
|
+
|
|
1316
|
+
const processOrderHandler = defineHandler(
|
|
987
1317
|
orderContract,
|
|
988
|
-
'
|
|
989
|
-
({ payload }) =>
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1318
|
+
'processOrder',
|
|
1319
|
+
({ payload }) =>
|
|
1320
|
+
ResultAsync.fromPromise(
|
|
1321
|
+
processPayment(payload),
|
|
1322
|
+
(error) => new RetryableError('Payment failed', error),
|
|
1323
|
+
).map(() => undefined),
|
|
1324
|
+
);
|
|
1325
|
+
```
|
|
1326
|
+
|
|
1327
|
+
```typescript
|
|
1328
|
+
const calculateHandler = defineHandler(
|
|
1329
|
+
rpcContract,
|
|
1330
|
+
'calculate',
|
|
1331
|
+
({ payload }) => okAsync({ sum: payload.a + payload.b }),
|
|
1332
|
+
);
|
|
1333
|
+
```
|
|
1334
|
+
|
|
1335
|
+
#### Call Signature
|
|
1336
|
+
|
|
1337
|
+
```ts
|
|
1338
|
+
function defineHandler<TContract, TName>(
|
|
1339
|
+
contract,
|
|
1340
|
+
name,
|
|
1341
|
+
handler,
|
|
1342
|
+
options): WorkerInferRpcHandlerEntry<TContract, TName>;
|
|
1343
|
+
```
|
|
1344
|
+
|
|
1345
|
+
Defined in: [packages/worker/src/handlers.ts:146](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/handlers.ts#L146)
|
|
1346
|
+
|
|
1347
|
+
Define a type-safe handler for a specific consumer or RPC in a contract.
|
|
1348
|
+
|
|
1349
|
+
**Recommended:** This function creates handlers that return
|
|
1350
|
+
`ResultAsync<void, HandlerError>` (consumers) or
|
|
1351
|
+
`ResultAsync<TResponse, HandlerError>` (RPCs), providing explicit error
|
|
1352
|
+
handling and better control over retry behavior.
|
|
1353
|
+
|
|
1354
|
+
Supports two patterns:
|
|
1355
|
+
1. Simple handler: just the function
|
|
1356
|
+
2. Handler with options: `[handler, { prefetch: 10 }]`
|
|
1357
|
+
|
|
1358
|
+
##### Type Parameters
|
|
1359
|
+
|
|
1360
|
+
| Type Parameter | Description |
|
|
1361
|
+
| ------ | ------ |
|
|
1362
|
+
| `TContract` *extends* `ContractDefinition` | The contract definition type |
|
|
1363
|
+
| `TName` *extends* `string` \| `number` \| `symbol` | The consumer or RPC name from the contract |
|
|
1364
|
+
|
|
1365
|
+
##### Parameters
|
|
1366
|
+
|
|
1367
|
+
| Parameter | Type | Description |
|
|
1368
|
+
| ------ | ------ | ------ |
|
|
1369
|
+
| `contract` | `TContract` | The contract definition containing the consumer or RPC |
|
|
1370
|
+
| `name` | `TName` | The name of the consumer or RPC from the contract |
|
|
1371
|
+
| `handler` | [`WorkerInferRpcHandler`](#workerinferrpchandler)<`TContract`, `TName`> | The handler function — for consumers, returns `ResultAsync<void, HandlerError>`; for RPCs, returns `ResultAsync<TResponse, HandlerError>`. |
|
|
1372
|
+
| `options` | `ConsumerOptions` | Optional consumer options (prefetch) |
|
|
1373
|
+
|
|
1374
|
+
##### Returns
|
|
1375
|
+
|
|
1376
|
+
[`WorkerInferRpcHandlerEntry`](#workerinferrpchandlerentry)<`TContract`, `TName`>
|
|
1377
|
+
|
|
1378
|
+
A type-safe handler that can be used with TypedAmqpWorker
|
|
1379
|
+
|
|
1380
|
+
##### Examples
|
|
1381
|
+
|
|
1382
|
+
```typescript
|
|
1383
|
+
import { defineHandler, RetryableError, NonRetryableError } from '@amqp-contract/worker';
|
|
1384
|
+
import { errAsync, okAsync, ResultAsync } from 'neverthrow';
|
|
1385
|
+
|
|
1386
|
+
const processOrderHandler = defineHandler(
|
|
1387
|
+
orderContract,
|
|
1388
|
+
'processOrder',
|
|
1389
|
+
({ payload }) =>
|
|
1390
|
+
ResultAsync.fromPromise(
|
|
1391
|
+
processPayment(payload),
|
|
1392
|
+
(error) => new RetryableError('Payment failed', error),
|
|
1393
|
+
).map(() => undefined),
|
|
1394
|
+
);
|
|
1395
|
+
```
|
|
1396
|
+
|
|
1397
|
+
```typescript
|
|
1398
|
+
const calculateHandler = defineHandler(
|
|
1399
|
+
rpcContract,
|
|
1400
|
+
'calculate',
|
|
1401
|
+
({ payload }) => okAsync({ sum: payload.a + payload.b }),
|
|
996
1402
|
);
|
|
997
1403
|
```
|
|
998
1404
|
|
|
@@ -1001,15 +1407,20 @@ const validateOrderHandler = defineHandler(
|
|
|
1001
1407
|
### defineHandlers()
|
|
1002
1408
|
|
|
1003
1409
|
```ts
|
|
1004
|
-
function defineHandlers<TContract>(contract, handlers):
|
|
1410
|
+
function defineHandlers<TContract>(contract, handlers): WorkerInferHandlers<TContract>;
|
|
1005
1411
|
```
|
|
1006
1412
|
|
|
1007
|
-
Defined in: [packages/worker/src/handlers.ts:
|
|
1413
|
+
Defined in: [packages/worker/src/handlers.ts:198](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/handlers.ts#L198)
|
|
1414
|
+
|
|
1415
|
+
Define multiple type-safe handlers for consumers and RPCs in a contract.
|
|
1008
1416
|
|
|
1009
|
-
|
|
1417
|
+
**Recommended:** This function creates handlers that return
|
|
1418
|
+
`ResultAsync<void, HandlerError>` (consumers) or
|
|
1419
|
+
`ResultAsync<TResponse, HandlerError>` (RPCs), providing explicit error
|
|
1420
|
+
handling and better control over retry behavior.
|
|
1010
1421
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1422
|
+
The handlers object must contain exactly one entry per `consumers` and
|
|
1423
|
+
`rpcs` key in the contract — see [WorkerInferHandlers](#workerinferhandlers).
|
|
1013
1424
|
|
|
1014
1425
|
#### Type Parameters
|
|
1015
1426
|
|
|
@@ -1021,12 +1432,12 @@ providing explicit error handling and better control over retry behavior.
|
|
|
1021
1432
|
|
|
1022
1433
|
| Parameter | Type | Description |
|
|
1023
1434
|
| ------ | ------ | ------ |
|
|
1024
|
-
| `contract` | `TContract` | The contract definition containing the consumers |
|
|
1025
|
-
| `handlers` | [`
|
|
1435
|
+
| `contract` | `TContract` | The contract definition containing the consumers and RPCs |
|
|
1436
|
+
| `handlers` | [`WorkerInferHandlers`](#workerinferhandlers)<`TContract`> | An object with handler functions for each consumer and RPC |
|
|
1026
1437
|
|
|
1027
1438
|
#### Returns
|
|
1028
1439
|
|
|
1029
|
-
[`
|
|
1440
|
+
[`WorkerInferHandlers`](#workerinferhandlers)<`TContract`>
|
|
1030
1441
|
|
|
1031
1442
|
A type-safe handlers object that can be used with TypedAmqpWorker
|
|
1032
1443
|
|
|
@@ -1034,8 +1445,7 @@ A type-safe handlers object that can be used with TypedAmqpWorker
|
|
|
1034
1445
|
|
|
1035
1446
|
```typescript
|
|
1036
1447
|
import { defineHandlers, RetryableError } from '@amqp-contract/worker';
|
|
1037
|
-
import { ResultAsync } from 'neverthrow';
|
|
1038
|
-
import { orderContract } from './contract';
|
|
1448
|
+
import { okAsync, ResultAsync } from 'neverthrow';
|
|
1039
1449
|
|
|
1040
1450
|
const handlers = defineHandlers(orderContract, {
|
|
1041
1451
|
processOrder: ({ payload }) =>
|
|
@@ -1043,11 +1453,7 @@ const handlers = defineHandlers(orderContract, {
|
|
|
1043
1453
|
processPayment(payload),
|
|
1044
1454
|
(error) => new RetryableError('Payment failed', error),
|
|
1045
1455
|
).map(() => undefined),
|
|
1046
|
-
|
|
1047
|
-
ResultAsync.fromPromise(
|
|
1048
|
-
sendNotification(payload),
|
|
1049
|
-
(error) => new RetryableError('Notification failed', error),
|
|
1050
|
-
).map(() => undefined),
|
|
1456
|
+
calculate: ({ payload }) => okAsync({ sum: payload.a + payload.b }),
|
|
1051
1457
|
});
|
|
1052
1458
|
```
|
|
1053
1459
|
|
|
@@ -1059,7 +1465,7 @@ const handlers = defineHandlers(orderContract, {
|
|
|
1059
1465
|
function isHandlerError(error): error is HandlerError;
|
|
1060
1466
|
```
|
|
1061
1467
|
|
|
1062
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
1468
|
+
Defined in: [packages/worker/src/errors.ts:124](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L124)
|
|
1063
1469
|
|
|
1064
1470
|
Type guard to check if an error is any HandlerError (RetryableError or NonRetryableError).
|
|
1065
1471
|
|
|
@@ -1096,7 +1502,7 @@ function handleError(error: unknown) {
|
|
|
1096
1502
|
function isNonRetryableError(error): error is NonRetryableError;
|
|
1097
1503
|
```
|
|
1098
1504
|
|
|
1099
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
1505
|
+
Defined in: [packages/worker/src/errors.ts:102](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L102)
|
|
1100
1506
|
|
|
1101
1507
|
Type guard to check if an error is a NonRetryableError.
|
|
1102
1508
|
|
|
@@ -1136,7 +1542,7 @@ try {
|
|
|
1136
1542
|
function isRetryableError(error): error is RetryableError;
|
|
1137
1543
|
```
|
|
1138
1544
|
|
|
1139
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
1545
|
+
Defined in: [packages/worker/src/errors.ts:77](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L77)
|
|
1140
1546
|
|
|
1141
1547
|
Type guard to check if an error is a RetryableError.
|
|
1142
1548
|
|
|
@@ -1178,7 +1584,7 @@ try {
|
|
|
1178
1584
|
function nonRetryable(message, cause?): NonRetryableError;
|
|
1179
1585
|
```
|
|
1180
1586
|
|
|
1181
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
1587
|
+
Defined in: [packages/worker/src/errors.ts:187](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L187)
|
|
1182
1588
|
|
|
1183
1589
|
Create a NonRetryableError with less verbosity.
|
|
1184
1590
|
|
|
@@ -1223,7 +1629,7 @@ const handler = ({ payload }) => {
|
|
|
1223
1629
|
function retryable(message, cause?): RetryableError;
|
|
1224
1630
|
```
|
|
1225
1631
|
|
|
1226
|
-
Defined in: [packages/worker/src/errors.ts:
|
|
1632
|
+
Defined in: [packages/worker/src/errors.ts:157](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L157)
|
|
1227
1633
|
|
|
1228
1634
|
Create a RetryableError with less verbosity.
|
|
1229
1635
|
|