@amqp-contract/worker 0.23.1 → 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/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:34](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L34)
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
- - `Error`
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:35](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L35)
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
- ###### Overrides
364
+ ###### Inherited from
207
365
 
208
- ```ts
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-1"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:37](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L37) |
217
- | <a id="message-1"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
218
- | <a id="name-1"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
219
- | <a id="stack-1"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
220
- | <a id="stacktracelimit-1"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
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
- ```ts
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
- ```ts
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:10](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L10)
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
- - `Error`
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:11](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L11)
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
- ###### Overrides
511
+ ###### Inherited from
360
512
 
361
- ```ts
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-2"></a> `cause?` | `readonly` | `unknown` | - | `Error.cause` | [packages/worker/src/errors.ts:13](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L13) |
370
- | <a id="message-2"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
371
- | <a id="name-2"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
372
- | <a id="stack-2"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
373
- | <a id="stacktracelimit-2"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
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
- ```ts
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
- ```ts
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:177](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L177)
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
 
@@ -488,6 +634,7 @@ and error handling for consuming messages based on a contract definition.
488
634
  ```typescript
489
635
  import { TypedAmqpWorker } from '@amqp-contract/worker';
490
636
  import { defineQueue, defineMessage, defineContract, defineConsumer } from '@amqp-contract/contract';
637
+ import { okAsync } from 'neverthrow';
491
638
  import { z } from 'zod';
492
639
 
493
640
  const orderQueue = defineQueue('order-processing');
@@ -502,19 +649,22 @@ const contract = defineContract({
502
649
  }
503
650
  });
504
651
 
505
- const worker = await TypedAmqpWorker.create({
652
+ const result = await TypedAmqpWorker.create({
506
653
  contract,
507
654
  handlers: {
508
- processOrder: async (message) => {
509
- console.log('Processing order', message.orderId);
510
- // Process the order...
511
- }
655
+ processOrder: ({ payload }) => {
656
+ console.log('Processing order', payload.orderId);
657
+ return okAsync(undefined);
658
+ },
512
659
  },
513
- urls: ['amqp://localhost']
514
- }).resultToPromise();
660
+ urls: ['amqp://localhost'],
661
+ });
662
+
663
+ if (result.isErr()) throw result.error;
664
+ const worker = result.value;
515
665
 
516
666
  // Close when done
517
- await worker.close().resultToPromise();
667
+ await worker.close();
518
668
  ```
519
669
 
520
670
  #### Type Parameters
@@ -528,10 +678,10 @@ await worker.close().resultToPromise();
528
678
  ##### close()
529
679
 
530
680
  ```ts
531
- close(): Future<Result<void, TechnicalError>>;
681
+ close(): ResultAsync<void, TechnicalError>;
532
682
  ```
533
683
 
534
- Defined in: [packages/worker/src/worker.ts:339](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L339)
684
+ Defined in: [packages/worker/src/worker.ts:342](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L342)
535
685
 
536
686
  Close the AMQP channel and connection.
537
687
 
@@ -540,14 +690,12 @@ stopping all message consumption and cleaning up resources.
540
690
 
541
691
  ###### Returns
542
692
 
543
- `Future`&lt;`Result`&lt;`void`, `TechnicalError`&gt;&gt;
544
-
545
- A Future that resolves to a Result indicating success or failure
693
+ `ResultAsync`&lt;`void`, `TechnicalError`&gt;
546
694
 
547
695
  ###### Example
548
696
 
549
697
  ```typescript
550
- const closeResult = await worker.close().resultToPromise();
698
+ const closeResult = await worker.close();
551
699
  if (closeResult.isOk()) {
552
700
  console.log('Worker closed successfully');
553
701
  }
@@ -556,10 +704,10 @@ if (closeResult.isOk()) {
556
704
  ##### create()
557
705
 
558
706
  ```ts
559
- static create<TContract>(options): Future<Result<TypedAmqpWorker<TContract>, TechnicalError>>;
707
+ static create<TContract>(__namedParameters): ResultAsync<TypedAmqpWorker<TContract>, TechnicalError>;
560
708
  ```
561
709
 
562
- Defined in: [packages/worker/src/worker.ts:277](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L277)
710
+ Defined in: [packages/worker/src/worker.ts:281](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L281)
563
711
 
564
712
  Create a type-safe AMQP worker from a contract.
565
713
 
@@ -579,26 +727,26 @@ URLs and connection options, following RabbitMQ best practices.
579
727
 
580
728
  ###### Parameters
581
729
 
582
- | Parameter | Type | Description |
583
- | ------ | ------ | ------ |
584
- | `options` | [`CreateWorkerOptions`](#createworkeroptions)&lt;`TContract`&gt; | Configuration options for the worker |
730
+ | Parameter | Type |
731
+ | ------ | ------ |
732
+ | `__namedParameters` | [`CreateWorkerOptions`](#createworkeroptions)&lt;`TContract`&gt; |
585
733
 
586
734
  ###### Returns
587
735
 
588
- `Future`&lt;`Result`&lt;[`TypedAmqpWorker`](#typedamqpworker)&lt;`TContract`&gt;, `TechnicalError`&gt;&gt;
736
+ `ResultAsync`&lt;[`TypedAmqpWorker`](#typedamqpworker)&lt;`TContract`&gt;, `TechnicalError`&gt;
589
737
 
590
- A Future that resolves to a Result containing the worker or an error
738
+ A ResultAsync that resolves to the worker or a TechnicalError.
591
739
 
592
740
  ###### Example
593
741
 
594
742
  ```typescript
595
- const worker = await TypedAmqpWorker.create({
743
+ const result = await TypedAmqpWorker.create({
596
744
  contract: myContract,
597
745
  handlers: {
598
- processOrder: async ({ payload }) => console.log('Order:', payload.orderId)
746
+ processOrder: ({ payload }) => okAsync(undefined),
599
747
  },
600
- urls: ['amqp://localhost']
601
- }).resultToPromise();
748
+ urls: ['amqp://localhost'],
749
+ });
602
750
  ```
603
751
 
604
752
  ## Type Aliases
@@ -609,7 +757,7 @@ const worker = await TypedAmqpWorker.create({
609
757
  type ConsumerOptions = AmqpClientConsumerOptions;
610
758
  ```
611
759
 
612
- Defined in: [packages/worker/src/worker.ts:49](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L49)
760
+ Defined in: [packages/worker/src/worker.ts:50](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L50)
613
761
 
614
762
  ***
615
763
 
@@ -619,7 +767,7 @@ Defined in: [packages/worker/src/worker.ts:49](https://github.com/btravers/amqp-
619
767
  type CreateWorkerOptions<TContract> = object;
620
768
  ```
621
769
 
622
- Defined in: [packages/worker/src/worker.ts:96](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L96)
770
+ Defined in: [packages/worker/src/worker.ts:97](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/worker.ts#L97)
623
771
 
624
772
  Options for creating a type-safe AMQP worker.
625
773
 
@@ -632,13 +780,13 @@ const options: CreateWorkerOptions<typeof contract> = {
632
780
  // Simple handler
633
781
  processOrder: ({ payload }) => {
634
782
  console.log('Processing order:', payload.orderId);
635
- return Future.value(Result.Ok(undefined));
783
+ return okAsync(undefined);
636
784
  },
637
785
  // Handler with prefetch configuration
638
786
  processPayment: [
639
787
  ({ payload }) => {
640
788
  console.log('Processing payment:', payload.paymentId);
641
- return Future.value(Result.Ok(undefined));
789
+ return okAsync(undefined);
642
790
  },
643
791
  { prefetch: 10 }
644
792
  ]
@@ -667,29 +815,14 @@ not at the handler level. See `QueueDefinition.retry` for configuration options.
667
815
 
668
816
  | Property | Type | Description | Defined in |
669
817
  | ------ | ------ | ------ | ------ |
670
- | <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.) | [packages/worker/src/worker.ts:113](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L113) |
671
- | <a id="connecttimeoutms"></a> `connectTimeoutMs?` | `number` \| `null` | Maximum time in ms to wait for the AMQP connection to become ready before `create()` resolves to `Result.Error<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:133](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L133) |
672
- | <a id="contract"></a> `contract` | `TContract` | The AMQP contract definition specifying consumers and their message schemas | [packages/worker/src/worker.ts:98](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L98) |
673
- | <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:126](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L126) |
674
- | <a id="handlers"></a> `handlers` | `WorkerInferHandlers`&lt;`TContract`&gt; | Handlers for each `consumers` and `rpcs` entry in the contract. - Regular consumers return `Future<Result<void, HandlerError>>`. - RPC handlers return `Future<Result<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:109](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L109) |
675
- | <a id="logger"></a> `logger?` | `Logger` | Optional logger for logging message consumption and errors | [packages/worker/src/worker.ts:115](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L115) |
676
- | <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:121](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L121) |
677
- | <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support | [packages/worker/src/worker.ts:111](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/worker.ts#L111) |
678
-
679
- ***
680
-
681
- ### HandlerError
682
-
683
- ```ts
684
- type HandlerError =
685
- | RetryableError
686
- | NonRetryableError;
687
- ```
688
-
689
- Defined in: [packages/worker/src/errors.ts:55](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L55)
690
-
691
- Union type representing all handler errors.
692
- 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)&lt;`TContract`&gt; | 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) |
693
826
 
694
827
  ***
695
828
 
@@ -699,7 +832,7 @@ Use this type when defining handlers that explicitly signal error outcomes.
699
832
  type WorkerConsumedMessage<TPayload, THeaders> = object;
700
833
  ```
701
834
 
702
- Defined in: [packages/worker/src/types.ts:156](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/types.ts#L156)
835
+ Defined in: [packages/worker/src/types.ts:156](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L156)
703
836
 
704
837
  A consumed message containing parsed payload and headers.
705
838
 
@@ -713,7 +846,7 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
713
846
  console.log(message.payload.orderId); // Typed payload
714
847
  console.log(message.headers?.priority); // Typed headers (if defined)
715
848
  console.log(rawMessage.fields.deliveryTag); // Raw AMQP message
716
- return Future.value(Result.Ok(undefined));
849
+ return okAsync(undefined);
717
850
  });
718
851
  ```
719
852
 
@@ -728,8 +861,8 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
728
861
 
729
862
  | Property | Type | Description | Defined in |
730
863
  | ------ | ------ | ------ | ------ |
731
- | <a id="headers"></a> `headers` | `THeaders` *extends* `undefined` ? `undefined` : `THeaders` | The validated message headers (present only when headers schema is defined) | [packages/worker/src/types.ts:160](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/types.ts#L160) |
732
- | <a id="payload"></a> `payload` | `TPayload` | The validated message payload | [packages/worker/src/types.ts:158](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/types.ts#L158) |
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) |
733
866
 
734
867
  ***
735
868
 
@@ -739,7 +872,7 @@ const handler = defineHandler(contract, 'processOrder', (message, rawMessage) =>
739
872
  type WorkerInferConsumedMessage<TContract, TName> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
740
873
  ```
741
874
 
742
- Defined in: [packages/worker/src/types.ts:166](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/types.ts#L166)
875
+ Defined in: [packages/worker/src/types.ts:166](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L166)
743
876
 
744
877
  Infer the full consumed message type for a regular consumer.
745
878
 
@@ -755,13 +888,13 @@ Infer the full consumed message type for a regular consumer.
755
888
  ### WorkerInferConsumerHandler
756
889
 
757
890
  ```ts
758
- type WorkerInferConsumerHandler<TContract, TName> = (message, rawMessage) => Future<Result<void, HandlerError>>;
891
+ type WorkerInferConsumerHandler<TContract, TName> = (message, rawMessage) => ResultAsync<void, HandlerError>;
759
892
  ```
760
893
 
761
- Defined in: [packages/worker/src/types.ts:197](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/types.ts#L197)
894
+ Defined in: [packages/worker/src/types.ts:197](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L197)
762
895
 
763
896
  Handler signature for a regular consumer (event/command). Returns
764
- `Future<Result<void, HandlerError>>` — there is no response message.
897
+ `ResultAsync<void, HandlerError>` — there is no response message.
765
898
 
766
899
  #### Type Parameters
767
900
 
@@ -779,7 +912,7 @@ Handler signature for a regular consumer (event/command). Returns
779
912
 
780
913
  #### Returns
781
914
 
782
- `Future`&lt;`Result`&lt;`void`, [`HandlerError`](#handlererror)&gt;&gt;
915
+ `ResultAsync`&lt;`void`, [`HandlerError`](#abstract-handlererror)&gt;
783
916
 
784
917
  ***
785
918
 
@@ -791,7 +924,7 @@ type WorkerInferConsumerHandlerEntry<TContract, TName> =
791
924
  | readonly [WorkerInferConsumerHandler<TContract, TName>, ConsumerOptions];
792
925
  ```
793
926
 
794
- Defined in: [packages/worker/src/types.ts:223](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/types.ts#L223)
927
+ Defined in: [packages/worker/src/types.ts:223](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L223)
795
928
 
796
929
  Handler entry for a regular consumer — function or `[handler, options]`.
797
930
 
@@ -804,43 +937,190 @@ Handler entry for a regular consumer — function or `[handler, options]`.
804
937
 
805
938
  ***
806
939
 
807
- ### ~~WorkerInferConsumerHandlers~~
940
+ ### WorkerInferConsumerHeaders
808
941
 
809
942
  ```ts
810
- type WorkerInferConsumerHandlers<TContract> = WorkerInferHandlers<TContract>;
943
+ type WorkerInferConsumerHeaders<TContract, TName> = ConsumerInferHeadersOutput<InferConsumer<TContract, TName>>;
811
944
  ```
812
945
 
813
- Defined in: [packages/worker/src/types.ts:269](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/types.ts#L269)
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.
814
950
 
815
951
  #### Type Parameters
816
952
 
817
953
  | Type Parameter |
818
954
  | ------ |
819
955
  | `TContract` *extends* `ContractDefinition` |
956
+ | `TName` *extends* `InferConsumerNames`&lt;`TContract`&gt; |
820
957
 
821
- #### Deprecated
958
+ ***
959
+
960
+ ### WorkerInferHandlers
822
961
 
823
- Use `WorkerInferHandlers` — handlers now span consumers ∪ rpcs.
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
+ ```
824
990
 
825
991
  ***
826
992
 
827
- ### WorkerInferConsumerHeaders
993
+ ### WorkerInferRpcConsumedMessage
828
994
 
829
995
  ```ts
830
- type WorkerInferConsumerHeaders<TContract, TName> = ConsumerInferHeadersOutput<InferConsumer<TContract, TName>>;
996
+ type WorkerInferRpcConsumedMessage<TContract, TName> = WorkerConsumedMessage<WorkerInferRpcRequest<TContract, TName>, WorkerInferRpcHeaders<TContract, TName>>;
831
997
  ```
832
998
 
833
- Defined in: [packages/worker/src/types.ts:85](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/types.ts#L85)
999
+ Defined in: [packages/worker/src/types.ts:178](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L178)
834
1000
 
835
- Infer the headers type for a regular consumer.
836
- Returns undefined if no headers schema is defined.
1001
+ Infer the consumed message type for an RPC handler — payload + headers from
1002
+ the request side of the RPC.
837
1003
 
838
1004
  #### Type Parameters
839
1005
 
840
1006
  | Type Parameter |
841
1007
  | ------ |
842
1008
  | `TContract` *extends* `ContractDefinition` |
843
- | `TName` *extends* `InferConsumerNames`&lt;`TContract`&gt; |
1009
+ | `TName` *extends* `InferRpcNames`&lt;`TContract`&gt; |
1010
+
1011
+ ***
1012
+
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`&lt;`TContract`&gt; |
1033
+
1034
+ #### Parameters
1035
+
1036
+ | Parameter | Type |
1037
+ | ------ | ------ |
1038
+ | `message` | [`WorkerInferRpcConsumedMessage`](#workerinferrpcconsumedmessage)&lt;`TContract`, `TName`&gt; |
1039
+ | `rawMessage` | `ConsumeMessage` |
1040
+
1041
+ #### Returns
1042
+
1043
+ `ResultAsync`&lt;[`WorkerInferRpcResponse`](#workerinferrpcresponse)&lt;`TContract`, `TName`&gt;, [`HandlerError`](#abstract-handlererror)&gt;
1044
+
1045
+ ***
1046
+
1047
+ ### WorkerInferRpcHandlerEntry
1048
+
1049
+ ```ts
1050
+ type WorkerInferRpcHandlerEntry<TContract, TName> =
1051
+ | WorkerInferRpcHandler<TContract, TName>
1052
+ | readonly [WorkerInferRpcHandler<TContract, TName>, ConsumerOptions];
1053
+ ```
1054
+
1055
+ Defined in: [packages/worker/src/types.ts:233](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/types.ts#L233)
1056
+
1057
+ Handler entry for an RPC — function or `[handler, options]`.
1058
+
1059
+ #### Type Parameters
1060
+
1061
+ | Type Parameter |
1062
+ | ------ |
1063
+ | `TContract` *extends* `ContractDefinition` |
1064
+ | `TName` *extends* `InferRpcNames`&lt;`TContract`&gt; |
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`&lt;`TContract`&gt; |
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`&lt;`TContract`&gt; |
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`&lt;`TContract`&gt; |
844
1124
 
845
1125
  ## Functions
846
1126
 
@@ -851,35 +1131,37 @@ Returns undefined if no headers schema is defined.
851
1131
  ```ts
852
1132
  function defineHandler<TContract, TName>(
853
1133
  contract,
854
- consumerName,
1134
+ name,
855
1135
  handler): WorkerInferConsumerHandlerEntry<TContract, TName>;
856
1136
  ```
857
1137
 
858
- Defined in: [packages/worker/src/handlers.ts:104](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/handlers.ts#L104)
1138
+ Defined in: [packages/worker/src/handlers.ts:121](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/handlers.ts#L121)
859
1139
 
860
- 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.
861
1141
 
862
- **Recommended:** This function creates handlers that return `Future<Result<void, HandlerError>>`,
863
- providing explicit error handling and better control over retry behavior.
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.
864
1146
 
865
1147
  Supports two patterns:
866
1148
  1. Simple handler: just the function
867
- 2. Handler with options: [handler, \{ prefetch: 10 \}]
1149
+ 2. Handler with options: `[handler, { prefetch: 10 }]`
868
1150
 
869
1151
  ##### Type Parameters
870
1152
 
871
1153
  | Type Parameter | Description |
872
1154
  | ------ | ------ |
873
1155
  | `TContract` *extends* `ContractDefinition` | The contract definition type |
874
- | `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 |
875
1157
 
876
1158
  ##### Parameters
877
1159
 
878
1160
  | Parameter | Type | Description |
879
1161
  | ------ | ------ | ------ |
880
- | `contract` | `TContract` | The contract definition containing the consumer |
881
- | `consumerName` | `TName` | The name of the consumer from the contract |
882
- | `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)&lt;`TContract`, `TName`&gt; | The handler function that returns `Future<Result<void, HandlerError>>` |
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)&lt;`TContract`, `TName`&gt; | The handler function for consumers, returns `ResultAsync<void, HandlerError>`; for RPCs, returns `ResultAsync<TResponse, HandlerError>`. |
883
1165
 
884
1166
  ##### Returns
885
1167
 
@@ -887,34 +1169,28 @@ Supports two patterns:
887
1169
 
888
1170
  A type-safe handler that can be used with TypedAmqpWorker
889
1171
 
890
- ##### Example
1172
+ ##### Examples
891
1173
 
892
1174
  ```typescript
893
1175
  import { defineHandler, RetryableError, NonRetryableError } from '@amqp-contract/worker';
894
- import { Future, Result } from '@swan-io/boxed';
895
- import { orderContract } from './contract';
1176
+ import { errAsync, okAsync, ResultAsync } from 'neverthrow';
896
1177
 
897
- // Simple handler with explicit error handling using mapError
898
1178
  const processOrderHandler = defineHandler(
899
1179
  orderContract,
900
1180
  'processOrder',
901
1181
  ({ payload }) =>
902
- Future.fromPromise(processPayment(payload))
903
- .mapOk(() => undefined)
904
- .mapError((error) => new RetryableError('Payment failed', error))
1182
+ ResultAsync.fromPromise(
1183
+ processPayment(payload),
1184
+ (error) => new RetryableError('Payment failed', error),
1185
+ ).map(() => undefined),
905
1186
  );
1187
+ ```
906
1188
 
907
- // Handler with validation (non-retryable error)
908
- const validateOrderHandler = defineHandler(
909
- orderContract,
910
- 'validateOrder',
911
- ({ payload }) => {
912
- if (payload.amount < 1) {
913
- // Won't be retried - goes directly to DLQ
914
- return Future.value(Result.Error(new NonRetryableError('Invalid order amount')));
915
- }
916
- return Future.value(Result.Ok(undefined));
917
- }
1189
+ ```typescript
1190
+ const calculateHandler = defineHandler(
1191
+ rpcContract,
1192
+ 'calculate',
1193
+ ({ payload }) => okAsync({ sum: payload.a + payload.b }),
918
1194
  );
919
1195
  ```
920
1196
 
@@ -923,36 +1199,38 @@ const validateOrderHandler = defineHandler(
923
1199
  ```ts
924
1200
  function defineHandler<TContract, TName>(
925
1201
  contract,
926
- consumerName,
1202
+ name,
927
1203
  handler,
928
1204
  options): WorkerInferConsumerHandlerEntry<TContract, TName>;
929
1205
  ```
930
1206
 
931
- Defined in: [packages/worker/src/handlers.ts:112](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/handlers.ts#L112)
1207
+ Defined in: [packages/worker/src/handlers.ts:129](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/handlers.ts#L129)
932
1208
 
933
- 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.
934
1210
 
935
- **Recommended:** This function creates handlers that return `Future<Result<void, HandlerError>>`,
936
- providing explicit error handling and better control over retry behavior.
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.
937
1215
 
938
1216
  Supports two patterns:
939
1217
  1. Simple handler: just the function
940
- 2. Handler with options: [handler, \{ prefetch: 10 \}]
1218
+ 2. Handler with options: `[handler, { prefetch: 10 }]`
941
1219
 
942
1220
  ##### Type Parameters
943
1221
 
944
1222
  | Type Parameter | Description |
945
1223
  | ------ | ------ |
946
1224
  | `TContract` *extends* `ContractDefinition` | The contract definition type |
947
- | `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 |
948
1226
 
949
1227
  ##### Parameters
950
1228
 
951
1229
  | Parameter | Type | Description |
952
1230
  | ------ | ------ | ------ |
953
- | `contract` | `TContract` | The contract definition containing the consumer |
954
- | `consumerName` | `TName` | The name of the consumer from the contract |
955
- | `handler` | [`WorkerInferConsumerHandler`](#workerinferconsumerhandler)&lt;`TContract`, `TName`&gt; | The handler function that returns `Future<Result<void, HandlerError>>` |
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)&lt;`TContract`, `TName`&gt; | The handler function for consumers, returns `ResultAsync<void, HandlerError>`; for RPCs, returns `ResultAsync<TResponse, HandlerError>`. |
956
1234
  | `options` | `ConsumerOptions` | Optional consumer options (prefetch) |
957
1235
 
958
1236
  ##### Returns
@@ -961,34 +1239,166 @@ Supports two patterns:
961
1239
 
962
1240
  A type-safe handler that can be used with TypedAmqpWorker
963
1241
 
964
- ##### Example
1242
+ ##### Examples
965
1243
 
966
1244
  ```typescript
967
1245
  import { defineHandler, RetryableError, NonRetryableError } from '@amqp-contract/worker';
968
- import { Future, Result } from '@swan-io/boxed';
969
- import { orderContract } from './contract';
1246
+ import { errAsync, okAsync, ResultAsync } from 'neverthrow';
970
1247
 
971
- // Simple handler with explicit error handling using mapError
972
1248
  const processOrderHandler = defineHandler(
973
1249
  orderContract,
974
1250
  'processOrder',
975
1251
  ({ payload }) =>
976
- Future.fromPromise(processPayment(payload))
977
- .mapOk(() => undefined)
978
- .mapError((error) => new RetryableError('Payment failed', error))
1252
+ ResultAsync.fromPromise(
1253
+ processPayment(payload),
1254
+ (error) => new RetryableError('Payment failed', error),
1255
+ ).map(() => undefined),
979
1256
  );
1257
+ ```
1258
+
1259
+ ```typescript
1260
+ const calculateHandler = defineHandler(
1261
+ rpcContract,
1262
+ 'calculate',
1263
+ ({ payload }) => okAsync({ sum: payload.a + payload.b }),
1264
+ );
1265
+ ```
1266
+
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 }]`
980
1288
 
981
- // Handler with validation (non-retryable error)
982
- const validateOrderHandler = defineHandler(
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)&lt;`TContract`, `TName`&gt; | The handler function — for consumers, returns `ResultAsync<void, HandlerError>`; for RPCs, returns `ResultAsync<TResponse, HandlerError>`. |
1303
+
1304
+ ##### Returns
1305
+
1306
+ [`WorkerInferRpcHandlerEntry`](#workerinferrpchandlerentry)&lt;`TContract`, `TName`&gt;
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(
983
1317
  orderContract,
984
- 'validateOrder',
985
- ({ payload }) => {
986
- if (payload.amount < 1) {
987
- // Won't be retried - goes directly to DLQ
988
- return Future.value(Result.Error(new NonRetryableError('Invalid order amount')));
989
- }
990
- return Future.value(Result.Ok(undefined));
991
- }
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)&lt;`TContract`, `TName`&gt; | 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)&lt;`TContract`, `TName`&gt;
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 }),
992
1402
  );
993
1403
  ```
994
1404
 
@@ -997,15 +1407,20 @@ const validateOrderHandler = defineHandler(
997
1407
  ### defineHandlers()
998
1408
 
999
1409
  ```ts
1000
- function defineHandlers<TContract>(contract, handlers): WorkerInferConsumerHandlers<TContract>;
1410
+ function defineHandlers<TContract>(contract, handlers): WorkerInferHandlers<TContract>;
1001
1411
  ```
1002
1412
 
1003
- Defined in: [packages/worker/src/handlers.ts:167](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/handlers.ts#L167)
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.
1004
1416
 
1005
- Define multiple type-safe handlers for consumers in a contract.
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.
1006
1421
 
1007
- **Recommended:** This function creates handlers that return `Future<Result<void, HandlerError>>`,
1008
- providing explicit error handling and better control over retry behavior.
1422
+ The handlers object must contain exactly one entry per `consumers` and
1423
+ `rpcs` key in the contract see [WorkerInferHandlers](#workerinferhandlers).
1009
1424
 
1010
1425
  #### Type Parameters
1011
1426
 
@@ -1017,12 +1432,12 @@ providing explicit error handling and better control over retry behavior.
1017
1432
 
1018
1433
  | Parameter | Type | Description |
1019
1434
  | ------ | ------ | ------ |
1020
- | `contract` | `TContract` | The contract definition containing the consumers |
1021
- | `handlers` | [`WorkerInferConsumerHandlers`](#workerinferconsumerhandlers)&lt;`TContract`&gt; | An object with handler functions for each consumer |
1435
+ | `contract` | `TContract` | The contract definition containing the consumers and RPCs |
1436
+ | `handlers` | [`WorkerInferHandlers`](#workerinferhandlers)&lt;`TContract`&gt; | An object with handler functions for each consumer and RPC |
1022
1437
 
1023
1438
  #### Returns
1024
1439
 
1025
- [`WorkerInferConsumerHandlers`](#workerinferconsumerhandlers)&lt;`TContract`&gt;
1440
+ [`WorkerInferHandlers`](#workerinferhandlers)&lt;`TContract`&gt;
1026
1441
 
1027
1442
  A type-safe handlers object that can be used with TypedAmqpWorker
1028
1443
 
@@ -1030,18 +1445,15 @@ A type-safe handlers object that can be used with TypedAmqpWorker
1030
1445
 
1031
1446
  ```typescript
1032
1447
  import { defineHandlers, RetryableError } from '@amqp-contract/worker';
1033
- import { Future } from '@swan-io/boxed';
1034
- import { orderContract } from './contract';
1448
+ import { okAsync, ResultAsync } from 'neverthrow';
1035
1449
 
1036
1450
  const handlers = defineHandlers(orderContract, {
1037
1451
  processOrder: ({ payload }) =>
1038
- Future.fromPromise(processPayment(payload))
1039
- .mapOk(() => undefined)
1040
- .mapError((error) => new RetryableError('Payment failed', error)),
1041
- notifyOrder: ({ payload }) =>
1042
- Future.fromPromise(sendNotification(payload))
1043
- .mapOk(() => undefined)
1044
- .mapError((error) => new RetryableError('Notification failed', error)),
1452
+ ResultAsync.fromPromise(
1453
+ processPayment(payload),
1454
+ (error) => new RetryableError('Payment failed', error),
1455
+ ).map(() => undefined),
1456
+ calculate: ({ payload }) => okAsync({ sum: payload.a + payload.b }),
1045
1457
  });
1046
1458
  ```
1047
1459
 
@@ -1053,7 +1465,7 @@ const handlers = defineHandlers(orderContract, {
1053
1465
  function isHandlerError(error): error is HandlerError;
1054
1466
  ```
1055
1467
 
1056
- Defined in: [packages/worker/src/errors.ts:131](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L131)
1468
+ Defined in: [packages/worker/src/errors.ts:124](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L124)
1057
1469
 
1058
1470
  Type guard to check if an error is any HandlerError (RetryableError or NonRetryableError).
1059
1471
 
@@ -1090,7 +1502,7 @@ function handleError(error: unknown) {
1090
1502
  function isNonRetryableError(error): error is NonRetryableError;
1091
1503
  ```
1092
1504
 
1093
- Defined in: [packages/worker/src/errors.ts:109](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L109)
1505
+ Defined in: [packages/worker/src/errors.ts:102](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L102)
1094
1506
 
1095
1507
  Type guard to check if an error is a NonRetryableError.
1096
1508
 
@@ -1130,7 +1542,7 @@ try {
1130
1542
  function isRetryableError(error): error is RetryableError;
1131
1543
  ```
1132
1544
 
1133
- Defined in: [packages/worker/src/errors.ts:84](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L84)
1545
+ Defined in: [packages/worker/src/errors.ts:77](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L77)
1134
1546
 
1135
1547
  Type guard to check if an error is a RetryableError.
1136
1548
 
@@ -1172,7 +1584,7 @@ try {
1172
1584
  function nonRetryable(message, cause?): NonRetryableError;
1173
1585
  ```
1174
1586
 
1175
- Defined in: [packages/worker/src/errors.ts:193](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L193)
1587
+ Defined in: [packages/worker/src/errors.ts:187](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L187)
1176
1588
 
1177
1589
  Create a NonRetryableError with less verbosity.
1178
1590
 
@@ -1196,17 +1608,17 @@ A new NonRetryableError instance
1196
1608
 
1197
1609
  ```typescript
1198
1610
  import { nonRetryable } from '@amqp-contract/worker';
1199
- import { Future, Result } from '@swan-io/boxed';
1611
+ import { errAsync, okAsync } from 'neverthrow';
1200
1612
 
1201
1613
  const handler = ({ payload }) => {
1202
1614
  if (!isValidPayload(payload)) {
1203
- return Future.value(Result.Error(nonRetryable('Invalid payload format')));
1615
+ return errAsync(nonRetryable('Invalid payload format'));
1204
1616
  }
1205
- return Future.value(Result.Ok(undefined));
1617
+ return okAsync(undefined);
1206
1618
  };
1207
1619
 
1208
1620
  // Equivalent to:
1209
- // return Future.value(Result.Error(new NonRetryableError('Invalid payload format')));
1621
+ // return errAsync(new NonRetryableError('Invalid payload format'));
1210
1622
  ```
1211
1623
 
1212
1624
  ***
@@ -1217,7 +1629,7 @@ const handler = ({ payload }) => {
1217
1629
  function retryable(message, cause?): RetryableError;
1218
1630
  ```
1219
1631
 
1220
- Defined in: [packages/worker/src/errors.ts:163](https://github.com/btravers/amqp-contract/blob/dc096282cd7249a6b8148d35c3dfad011c9e9753/packages/worker/src/errors.ts#L163)
1632
+ Defined in: [packages/worker/src/errors.ts:157](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/worker/src/errors.ts#L157)
1221
1633
 
1222
1634
  Create a RetryableError with less verbosity.
1223
1635
 
@@ -1241,13 +1653,14 @@ A new RetryableError instance
1241
1653
 
1242
1654
  ```typescript
1243
1655
  import { retryable } from '@amqp-contract/worker';
1244
- import { Future, Result } from '@swan-io/boxed';
1656
+ import { ResultAsync } from 'neverthrow';
1245
1657
 
1246
1658
  const handler = ({ payload }) =>
1247
- Future.fromPromise(processPayment(payload))
1248
- .mapOk(() => undefined)
1249
- .mapError((e) => retryable('Payment service unavailable', e));
1659
+ ResultAsync.fromPromise(
1660
+ processPayment(payload),
1661
+ (e) => retryable('Payment service unavailable', e),
1662
+ ).map(() => undefined);
1250
1663
 
1251
1664
  // Equivalent to:
1252
- // .mapError((e) => new RetryableError('Payment service unavailable', e));
1665
+ // ResultAsync.fromPromise(processPayment(payload), (e) => new RetryableError('...', e))
1253
1666
  ```