@amqp-contract/worker 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @amqp-contract/worker
2
2
 
3
- **Type-safe AMQP worker for consuming messages using amqp-contract with standard async/await error handling.**
3
+ **Type-safe AMQP worker for consuming messages using amqp-contract with Future/Result error handling.**
4
4
 
5
5
  [![CI](https://github.com/btravers/amqp-contract/actions/workflows/ci.yml/badge.svg)](https://github.com/btravers/amqp-contract/actions/workflows/ci.yml)
6
6
  [![npm version](https://img.shields.io/npm/v/@amqp-contract/worker.svg?logo=npm)](https://www.npmjs.com/package/@amqp-contract/worker)
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
2
  let _amqp_contract_core = require("@amqp-contract/core");
2
3
  let _amqp_contract_contract = require("@amqp-contract/contract");
3
4
  let _swan_io_boxed = require("@swan-io/boxed");
@@ -230,17 +231,18 @@ function isHandlerTuple(entry) {
230
231
  * @example
231
232
  * ```typescript
232
233
  * import { TypedAmqpWorker } from '@amqp-contract/worker';
234
+ * import { defineQueue, defineMessage, defineContract, defineConsumer } from '@amqp-contract/contract';
233
235
  * import { z } from 'zod';
234
236
  *
237
+ * const orderQueue = defineQueue('order-processing', { durable: true });
238
+ * const orderMessage = defineMessage(z.object({
239
+ * orderId: z.string(),
240
+ * amount: z.number()
241
+ * }));
242
+ *
235
243
  * const contract = defineContract({
236
- * queues: {
237
- * orderProcessing: defineQueue('order-processing', { durable: true })
238
- * },
239
244
  * consumers: {
240
- * processOrder: defineConsumer('order-processing', z.object({
241
- * orderId: z.string(),
242
- * amount: z.number()
243
- * }))
245
+ * processOrder: defineConsumer(orderQueue, orderMessage)
244
246
  * }
245
247
  * });
246
248
  *
package/dist/index.d.cts CHANGED
@@ -1,10 +1,53 @@
1
1
  import { Logger, TechnicalError, TelemetryProvider } from "@amqp-contract/core";
2
- import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
3
- import { ConsumerDefinition, ConsumerEntry, ContractDefinitionInput, InferConsumerNames, MessageDefinition } from "@amqp-contract/contract";
4
- import { Future, Result } from "@swan-io/boxed";
2
+ import * as amqp from "amqplib";
5
3
  import { ConsumeMessage } from "amqplib";
4
+ import { TcpSocketConnectOpts } from "net";
5
+ import { ConnectionOptions } from "tls";
6
+ import { ConsumerDefinition, ConsumerEntry, ContractDefinition, InferConsumerNames, MessageDefinition } from "@amqp-contract/contract";
7
+ import { Future, Result } from "@swan-io/boxed";
6
8
  import { StandardSchemaV1 } from "@standard-schema/spec";
7
9
 
10
+ //#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
11
+ type ConnectionUrl = string | amqp.Options.Connect | {
12
+ url: string;
13
+ connectionOptions?: AmqpConnectionOptions;
14
+ };
15
+ type AmqpConnectionOptions = (ConnectionOptions | TcpSocketConnectOpts) & {
16
+ noDelay?: boolean;
17
+ timeout?: number;
18
+ keepAlive?: boolean;
19
+ keepAliveDelay?: number;
20
+ clientProperties?: any;
21
+ credentials?: {
22
+ mechanism: string;
23
+ username: string;
24
+ password: string;
25
+ response: () => Buffer;
26
+ } | {
27
+ mechanism: string;
28
+ response: () => Buffer;
29
+ } | undefined;
30
+ };
31
+ interface AmqpConnectionManagerOptions {
32
+ /** Interval to send heartbeats to broker. Defaults to 5 seconds. */
33
+ heartbeatIntervalInSeconds?: number;
34
+ /**
35
+ * The time to wait before trying to reconnect. If not specified, defaults
36
+ * to `heartbeatIntervalInSeconds`.
37
+ */
38
+ reconnectTimeInSeconds?: number | undefined;
39
+ /**
40
+ * `findServers` is a function that which returns one or more servers to
41
+ * connect to. This should return either a single URL or an array of URLs.
42
+ * This is handy when you're using a service discovery mechanism such as
43
+ * Consul or etcd. Instead of taking a callback, this can also return a
44
+ * Promise. Note that if this is supplied, then `urls` is ignored.
45
+ */
46
+ findServers?: ((callback: (urls: ConnectionUrl | ConnectionUrl[]) => void) => void) | (() => Promise<ConnectionUrl | ConnectionUrl[]>) | undefined;
47
+ /** Connection options, passed as options to the amqplib.connect() method. */
48
+ connectionOptions?: AmqpConnectionOptions;
49
+ }
50
+ //#endregion
8
51
  //#region src/errors.d.ts
9
52
  /**
10
53
  * Error thrown when message validation fails
@@ -184,20 +227,20 @@ type ConsumerInferHeadersInput<TConsumer extends ConsumerEntry> = ExtractConsume
184
227
  /**
185
228
  * Infer all consumers from contract
186
229
  */
187
- type InferConsumers<TContract extends ContractDefinitionInput> = NonNullable<TContract["consumers"]>;
230
+ type InferConsumers<TContract extends ContractDefinition> = NonNullable<TContract["consumers"]>;
188
231
  /**
189
232
  * Get specific consumer entry from contract
190
233
  */
191
- type InferConsumer<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
234
+ type InferConsumer<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
192
235
  /**
193
236
  * Infer the payload type for a specific consumer
194
237
  */
195
- type WorkerInferConsumerPayload<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = ConsumerInferPayloadInput<InferConsumer<TContract, TName>>;
238
+ type WorkerInferConsumerPayload<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferPayloadInput<InferConsumer<TContract, TName>>;
196
239
  /**
197
240
  * Infer the headers type for a specific consumer
198
241
  * Returns undefined if no headers schema is defined
199
242
  */
200
- type WorkerInferConsumerHeaders<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = ConsumerInferHeadersInput<InferConsumer<TContract, TName>>;
243
+ type WorkerInferConsumerHeaders<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferHeadersInput<InferConsumer<TContract, TName>>;
201
244
  /**
202
245
  * A consumed message containing parsed payload and headers.
203
246
  *
@@ -218,17 +261,15 @@ type WorkerInferConsumerHeaders<TContract extends ContractDefinitionInput, TName
218
261
  * });
219
262
  * ```
220
263
  */
221
- type WorkerConsumedMessage<TPayload, THeaders$1 = undefined> = {
222
- /** The validated message payload */
223
- payload: TPayload;
224
- /** The validated message headers (present only when headers schema is defined) */
225
- headers: THeaders$1 extends undefined ? undefined : THeaders$1;
264
+ type WorkerConsumedMessage<TPayload, THeaders = undefined> = {
265
+ /** The validated message payload */payload: TPayload; /** The validated message headers (present only when headers schema is defined) */
266
+ headers: THeaders extends undefined ? undefined : THeaders;
226
267
  };
227
268
  /**
228
269
  * Infer the full consumed message type for a specific consumer.
229
270
  * Includes both payload and headers (if defined).
230
271
  */
231
- type WorkerInferConsumedMessage<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
272
+ type WorkerInferConsumedMessage<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
232
273
  /**
233
274
  * Consumer handler type for a specific consumer.
234
275
  * Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
@@ -253,7 +294,7 @@ type WorkerInferConsumedMessage<TContract extends ContractDefinitionInput, TName
253
294
  * };
254
295
  * ```
255
296
  */
256
- type WorkerInferConsumerHandler<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumedMessage<TContract, TName>, rawMessage: ConsumeMessage) => Future<Result<void, HandlerError>>;
297
+ type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumedMessage<TContract, TName>, rawMessage: ConsumeMessage) => Future<Result<void, HandlerError>>;
257
298
  /**
258
299
  * Handler entry for a consumer - either a function or a tuple of [handler, options].
259
300
  *
@@ -264,7 +305,7 @@ type WorkerInferConsumerHandler<TContract extends ContractDefinitionInput, TName
264
305
  * Note: Retry configuration is now defined at the queue level in the contract,
265
306
  * not at the handler level. See `QueueDefinition.retry` for configuration options.
266
307
  */
267
- type WorkerInferConsumerHandlerEntry<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName> | readonly [WorkerInferConsumerHandler<TContract, TName>, {
308
+ type WorkerInferConsumerHandlerEntry<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName> | readonly [WorkerInferConsumerHandler<TContract, TName>, {
268
309
  prefetch?: number;
269
310
  }];
270
311
  /**
@@ -281,19 +322,19 @@ type WorkerInferConsumerHandlerEntry<TContract extends ContractDefinitionInput,
281
322
  * };
282
323
  * ```
283
324
  */
284
- type WorkerInferConsumerHandlers<TContract extends ContractDefinitionInput> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> };
325
+ type WorkerInferConsumerHandlers<TContract extends ContractDefinition> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> };
285
326
  /**
286
327
  * @deprecated Use `WorkerInferConsumerHandler` instead. Will be removed in next major version.
287
328
  */
288
- type WorkerInferSafeConsumerHandler<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName>;
329
+ type WorkerInferSafeConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName>;
289
330
  /**
290
331
  * @deprecated Use `WorkerInferConsumerHandlerEntry` instead. Will be removed in next major version.
291
332
  */
292
- type WorkerInferSafeConsumerHandlerEntry<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandlerEntry<TContract, TName>;
333
+ type WorkerInferSafeConsumerHandlerEntry<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandlerEntry<TContract, TName>;
293
334
  /**
294
335
  * @deprecated Use `WorkerInferConsumerHandlers` instead. Will be removed in next major version.
295
336
  */
296
- type WorkerInferSafeConsumerHandlers<TContract extends ContractDefinitionInput> = WorkerInferConsumerHandlers<TContract>;
337
+ type WorkerInferSafeConsumerHandlers<TContract extends ContractDefinition> = WorkerInferConsumerHandlers<TContract>;
297
338
  //#endregion
298
339
  //#region src/worker.d.ts
299
340
  /**
@@ -331,20 +372,16 @@ type WorkerInferSafeConsumerHandlers<TContract extends ContractDefinitionInput>
331
372
  * Note: Retry configuration is defined at the queue level in the contract,
332
373
  * not at the handler level. See `QueueDefinition.retry` for configuration options.
333
374
  */
334
- type CreateWorkerOptions<TContract extends ContractDefinitionInput> = {
335
- /** The AMQP contract definition specifying consumers and their message schemas */
336
- contract: TContract;
375
+ type CreateWorkerOptions<TContract extends ContractDefinition> = {
376
+ /** The AMQP contract definition specifying consumers and their message schemas */contract: TContract;
337
377
  /**
338
378
  * Handlers for each consumer defined in the contract.
339
379
  * Handlers must return `Future<Result<void, HandlerError>>` for explicit error handling.
340
380
  * Use defineHandler() to create handlers.
341
381
  */
342
- handlers: WorkerInferConsumerHandlers<TContract>;
343
- /** AMQP broker URL(s). Multiple URLs provide failover support */
344
- urls: ConnectionUrl[];
345
- /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
346
- connectionOptions?: AmqpConnectionManagerOptions | undefined;
347
- /** Optional logger for logging message consumption and errors */
382
+ handlers: WorkerInferConsumerHandlers<TContract>; /** AMQP broker URL(s). Multiple URLs provide failover support */
383
+ urls: ConnectionUrl[]; /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
384
+ connectionOptions?: AmqpConnectionManagerOptions | undefined; /** Optional logger for logging message consumption and errors */
348
385
  logger?: Logger | undefined;
349
386
  /**
350
387
  * Optional telemetry provider for tracing and metrics.
@@ -364,17 +401,18 @@ type CreateWorkerOptions<TContract extends ContractDefinitionInput> = {
364
401
  * @example
365
402
  * ```typescript
366
403
  * import { TypedAmqpWorker } from '@amqp-contract/worker';
404
+ * import { defineQueue, defineMessage, defineContract, defineConsumer } from '@amqp-contract/contract';
367
405
  * import { z } from 'zod';
368
406
  *
407
+ * const orderQueue = defineQueue('order-processing', { durable: true });
408
+ * const orderMessage = defineMessage(z.object({
409
+ * orderId: z.string(),
410
+ * amount: z.number()
411
+ * }));
412
+ *
369
413
  * const contract = defineContract({
370
- * queues: {
371
- * orderProcessing: defineQueue('order-processing', { durable: true })
372
- * },
373
414
  * consumers: {
374
- * processOrder: defineConsumer('order-processing', z.object({
375
- * orderId: z.string(),
376
- * amount: z.number()
377
- * }))
415
+ * processOrder: defineConsumer(orderQueue, orderMessage)
378
416
  * }
379
417
  * });
380
418
  *
@@ -393,7 +431,7 @@ type CreateWorkerOptions<TContract extends ContractDefinitionInput> = {
393
431
  * await worker.close().resultToPromise();
394
432
  * ```
395
433
  */
396
- declare class TypedAmqpWorker<TContract extends ContractDefinitionInput> {
434
+ declare class TypedAmqpWorker<TContract extends ContractDefinition> {
397
435
  private readonly contract;
398
436
  private readonly amqpClient;
399
437
  private readonly logger?;
@@ -430,7 +468,7 @@ declare class TypedAmqpWorker<TContract extends ContractDefinitionInput> {
430
468
  * }).resultToPromise();
431
469
  * ```
432
470
  */
433
- static create<TContract extends ContractDefinitionInput>({
471
+ static create<TContract extends ContractDefinition>({
434
472
  contract,
435
473
  handlers,
436
474
  urls,
@@ -607,8 +645,8 @@ declare class TypedAmqpWorker<TContract extends ContractDefinitionInput> {
607
645
  * );
608
646
  * ```
609
647
  */
610
- declare function defineHandler<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>>(contract: TContract, consumerName: TName, handler: WorkerInferConsumerHandler<TContract, TName>): WorkerInferConsumerHandlerEntry<TContract, TName>;
611
- declare function defineHandler<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>>(contract: TContract, consumerName: TName, handler: WorkerInferConsumerHandler<TContract, TName>, options: {
648
+ declare function defineHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>>(contract: TContract, consumerName: TName, handler: WorkerInferConsumerHandler<TContract, TName>): WorkerInferConsumerHandlerEntry<TContract, TName>;
649
+ declare function defineHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>>(contract: TContract, consumerName: TName, handler: WorkerInferConsumerHandler<TContract, TName>, options: {
612
650
  prefetch?: number;
613
651
  }): WorkerInferConsumerHandlerEntry<TContract, TName>;
614
652
  /**
@@ -640,7 +678,7 @@ declare function defineHandler<TContract extends ContractDefinitionInput, TName
640
678
  * });
641
679
  * ```
642
680
  */
643
- declare function defineHandlers<TContract extends ContractDefinitionInput>(contract: TContract, handlers: WorkerInferConsumerHandlers<TContract>): WorkerInferConsumerHandlers<TContract>;
681
+ declare function defineHandlers<TContract extends ContractDefinition>(contract: TContract, handlers: WorkerInferConsumerHandlers<TContract>): WorkerInferConsumerHandlers<TContract>;
644
682
  //#endregion
645
683
  export { type CreateWorkerOptions, type HandlerError, MessageValidationError, NonRetryableError, RetryableError, TypedAmqpWorker, type WorkerConsumedMessage, type WorkerInferConsumedMessage, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlerEntry, type WorkerInferConsumerHandlers, type WorkerInferConsumerHeaders, type WorkerInferSafeConsumerHandler, type WorkerInferSafeConsumerHandlerEntry, type WorkerInferSafeConsumerHandlers, defineHandler, defineHandlers, isHandlerError, isNonRetryableError, isRetryableError, nonRetryable, retryable };
646
684
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/worker.ts","../src/handlers.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;cAGa,sBAAA,SAA+B,KAAA;;;;;AAA5C;AAwBA;AAwBA;AAqBA;AA6BA;AAyBA;AAsBA;AAgCgB,cAzJH,cAAA,SAAuB,KAAA,CAyJuC;EA8B3D,SAAA,KAAA,CAAY,EAAA,OAAA,GAAoC,SAAA;;;;ACxMF;;;;;AAM5B;AAMO,cD6B5B,iB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jEO,CAAA,CAAA,CAAA,QAAA,EEmE9B,SFnE8B,EAAA,YAAA,EEoE1B,KFpE0B,EAAA,OAAA,EEqE/B,0BFrE+B,CEqEJ,SFrEI,EEqEO,KFrEP,CAAA,EAAA,OAAA,EAAA;EAAjB,QAAA,CAAA,EAAA,MAAA;CACE,CAAA,EEsExB,+BFtEwB,CEsEQ,SFtER,EEsEmB,KFtEnB,CAAA;;;AAAD;;;;;AAQkD;;;;;;;;AAUzC;;;;;;;;;AAcnC;;;;;AAGuD,iBEkFvC,cFlFuC,CAAA,kBEkFN,uBFlFM,CAAA,CAAA,QAAA,EEmF3C,SFnF2C,EAAA,QAAA,EEoF3C,2BFpF2C,CEoFf,SFpFe,CAAA,CAAA,EEqFpD,2BFrFoD,CEqFxB,SFrFwB,CAAA"}
1
+ {"version":3,"file":"index.d.cts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts","../src/errors.ts","../src/types.ts","../src/worker.ts","../src/handlers.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAA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A,gBACJ,kBAAA,CAAmB,SAAA,EAAA,CAEjC,QAAA,EAAU,SAAA,EACV,YAAA,EAAc,KAAA,EACd,OAAA,EAAS,0BAAA,CAA2B,SAAA,EAAW,KAAA,IAC9C,+BAAA,CAAgC,SAAA,EAAW,KAAA;AAAA,iBAC9B,aAAA,mBACI,kBAAA,gBACJ,kBAAA,CAAmB,SAAA,EAAA,CAEjC,QAAA,EAAU,SAAA,EACV,YAAA,EAAc,KAAA,EACd,OAAA,EAAS,0BAAA,CAA2B,SAAA,EAAW,KAAA,GAC/C,OAAA;EAAW,QAAA;AAAA,IACV,+BAAA,CAAgC,SAAA,EAAW,KAAA;;;;;;;;;;;;;;;;;;;;;;;;AHnH9C;;;;;;iBGkKgB,cAAA,mBAAiC,kBAAA,CAAA,CAC/C,QAAA,EAAU,SAAA,EACV,QAAA,EAAU,2BAAA,CAA4B,SAAA,IACrC,2BAAA,CAA4B,SAAA"}
package/dist/index.d.mts CHANGED
@@ -1,10 +1,53 @@
1
1
  import { Logger, TechnicalError, TelemetryProvider } from "@amqp-contract/core";
2
- import { ConsumerDefinition, ConsumerEntry, ContractDefinitionInput, InferConsumerNames, MessageDefinition } from "@amqp-contract/contract";
2
+ import { ConsumerDefinition, ConsumerEntry, ContractDefinition, InferConsumerNames, MessageDefinition } from "@amqp-contract/contract";
3
3
  import { Future, Result } from "@swan-io/boxed";
4
- import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
4
+ import * as amqp from "amqplib";
5
5
  import { ConsumeMessage } from "amqplib";
6
+ import { TcpSocketConnectOpts } from "net";
7
+ import { ConnectionOptions } from "tls";
6
8
  import { StandardSchemaV1 } from "@standard-schema/spec";
7
9
 
10
+ //#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
11
+ type ConnectionUrl = string | amqp.Options.Connect | {
12
+ url: string;
13
+ connectionOptions?: AmqpConnectionOptions;
14
+ };
15
+ type AmqpConnectionOptions = (ConnectionOptions | TcpSocketConnectOpts) & {
16
+ noDelay?: boolean;
17
+ timeout?: number;
18
+ keepAlive?: boolean;
19
+ keepAliveDelay?: number;
20
+ clientProperties?: any;
21
+ credentials?: {
22
+ mechanism: string;
23
+ username: string;
24
+ password: string;
25
+ response: () => Buffer;
26
+ } | {
27
+ mechanism: string;
28
+ response: () => Buffer;
29
+ } | undefined;
30
+ };
31
+ interface AmqpConnectionManagerOptions {
32
+ /** Interval to send heartbeats to broker. Defaults to 5 seconds. */
33
+ heartbeatIntervalInSeconds?: number;
34
+ /**
35
+ * The time to wait before trying to reconnect. If not specified, defaults
36
+ * to `heartbeatIntervalInSeconds`.
37
+ */
38
+ reconnectTimeInSeconds?: number | undefined;
39
+ /**
40
+ * `findServers` is a function that which returns one or more servers to
41
+ * connect to. This should return either a single URL or an array of URLs.
42
+ * This is handy when you're using a service discovery mechanism such as
43
+ * Consul or etcd. Instead of taking a callback, this can also return a
44
+ * Promise. Note that if this is supplied, then `urls` is ignored.
45
+ */
46
+ findServers?: ((callback: (urls: ConnectionUrl | ConnectionUrl[]) => void) => void) | (() => Promise<ConnectionUrl | ConnectionUrl[]>) | undefined;
47
+ /** Connection options, passed as options to the amqplib.connect() method. */
48
+ connectionOptions?: AmqpConnectionOptions;
49
+ }
50
+ //#endregion
8
51
  //#region src/errors.d.ts
9
52
  /**
10
53
  * Error thrown when message validation fails
@@ -184,20 +227,20 @@ type ConsumerInferHeadersInput<TConsumer extends ConsumerEntry> = ExtractConsume
184
227
  /**
185
228
  * Infer all consumers from contract
186
229
  */
187
- type InferConsumers<TContract extends ContractDefinitionInput> = NonNullable<TContract["consumers"]>;
230
+ type InferConsumers<TContract extends ContractDefinition> = NonNullable<TContract["consumers"]>;
188
231
  /**
189
232
  * Get specific consumer entry from contract
190
233
  */
191
- type InferConsumer<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
234
+ type InferConsumer<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
192
235
  /**
193
236
  * Infer the payload type for a specific consumer
194
237
  */
195
- type WorkerInferConsumerPayload<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = ConsumerInferPayloadInput<InferConsumer<TContract, TName>>;
238
+ type WorkerInferConsumerPayload<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferPayloadInput<InferConsumer<TContract, TName>>;
196
239
  /**
197
240
  * Infer the headers type for a specific consumer
198
241
  * Returns undefined if no headers schema is defined
199
242
  */
200
- type WorkerInferConsumerHeaders<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = ConsumerInferHeadersInput<InferConsumer<TContract, TName>>;
243
+ type WorkerInferConsumerHeaders<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferHeadersInput<InferConsumer<TContract, TName>>;
201
244
  /**
202
245
  * A consumed message containing parsed payload and headers.
203
246
  *
@@ -218,17 +261,15 @@ type WorkerInferConsumerHeaders<TContract extends ContractDefinitionInput, TName
218
261
  * });
219
262
  * ```
220
263
  */
221
- type WorkerConsumedMessage<TPayload, THeaders$1 = undefined> = {
222
- /** The validated message payload */
223
- payload: TPayload;
224
- /** The validated message headers (present only when headers schema is defined) */
225
- headers: THeaders$1 extends undefined ? undefined : THeaders$1;
264
+ type WorkerConsumedMessage<TPayload, THeaders = undefined> = {
265
+ /** The validated message payload */payload: TPayload; /** The validated message headers (present only when headers schema is defined) */
266
+ headers: THeaders extends undefined ? undefined : THeaders;
226
267
  };
227
268
  /**
228
269
  * Infer the full consumed message type for a specific consumer.
229
270
  * Includes both payload and headers (if defined).
230
271
  */
231
- type WorkerInferConsumedMessage<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
272
+ type WorkerInferConsumedMessage<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
232
273
  /**
233
274
  * Consumer handler type for a specific consumer.
234
275
  * Returns a `Future<Result<void, HandlerError>>` for explicit error handling.
@@ -253,7 +294,7 @@ type WorkerInferConsumedMessage<TContract extends ContractDefinitionInput, TName
253
294
  * };
254
295
  * ```
255
296
  */
256
- type WorkerInferConsumerHandler<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumedMessage<TContract, TName>, rawMessage: ConsumeMessage) => Future<Result<void, HandlerError>>;
297
+ type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumedMessage<TContract, TName>, rawMessage: ConsumeMessage) => Future<Result<void, HandlerError>>;
257
298
  /**
258
299
  * Handler entry for a consumer - either a function or a tuple of [handler, options].
259
300
  *
@@ -264,7 +305,7 @@ type WorkerInferConsumerHandler<TContract extends ContractDefinitionInput, TName
264
305
  * Note: Retry configuration is now defined at the queue level in the contract,
265
306
  * not at the handler level. See `QueueDefinition.retry` for configuration options.
266
307
  */
267
- type WorkerInferConsumerHandlerEntry<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName> | readonly [WorkerInferConsumerHandler<TContract, TName>, {
308
+ type WorkerInferConsumerHandlerEntry<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName> | readonly [WorkerInferConsumerHandler<TContract, TName>, {
268
309
  prefetch?: number;
269
310
  }];
270
311
  /**
@@ -281,19 +322,19 @@ type WorkerInferConsumerHandlerEntry<TContract extends ContractDefinitionInput,
281
322
  * };
282
323
  * ```
283
324
  */
284
- type WorkerInferConsumerHandlers<TContract extends ContractDefinitionInput> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> };
325
+ type WorkerInferConsumerHandlers<TContract extends ContractDefinition> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> };
285
326
  /**
286
327
  * @deprecated Use `WorkerInferConsumerHandler` instead. Will be removed in next major version.
287
328
  */
288
- type WorkerInferSafeConsumerHandler<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName>;
329
+ type WorkerInferSafeConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName>;
289
330
  /**
290
331
  * @deprecated Use `WorkerInferConsumerHandlerEntry` instead. Will be removed in next major version.
291
332
  */
292
- type WorkerInferSafeConsumerHandlerEntry<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandlerEntry<TContract, TName>;
333
+ type WorkerInferSafeConsumerHandlerEntry<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandlerEntry<TContract, TName>;
293
334
  /**
294
335
  * @deprecated Use `WorkerInferConsumerHandlers` instead. Will be removed in next major version.
295
336
  */
296
- type WorkerInferSafeConsumerHandlers<TContract extends ContractDefinitionInput> = WorkerInferConsumerHandlers<TContract>;
337
+ type WorkerInferSafeConsumerHandlers<TContract extends ContractDefinition> = WorkerInferConsumerHandlers<TContract>;
297
338
  //#endregion
298
339
  //#region src/worker.d.ts
299
340
  /**
@@ -331,20 +372,16 @@ type WorkerInferSafeConsumerHandlers<TContract extends ContractDefinitionInput>
331
372
  * Note: Retry configuration is defined at the queue level in the contract,
332
373
  * not at the handler level. See `QueueDefinition.retry` for configuration options.
333
374
  */
334
- type CreateWorkerOptions<TContract extends ContractDefinitionInput> = {
335
- /** The AMQP contract definition specifying consumers and their message schemas */
336
- contract: TContract;
375
+ type CreateWorkerOptions<TContract extends ContractDefinition> = {
376
+ /** The AMQP contract definition specifying consumers and their message schemas */contract: TContract;
337
377
  /**
338
378
  * Handlers for each consumer defined in the contract.
339
379
  * Handlers must return `Future<Result<void, HandlerError>>` for explicit error handling.
340
380
  * Use defineHandler() to create handlers.
341
381
  */
342
- handlers: WorkerInferConsumerHandlers<TContract>;
343
- /** AMQP broker URL(s). Multiple URLs provide failover support */
344
- urls: ConnectionUrl[];
345
- /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
346
- connectionOptions?: AmqpConnectionManagerOptions | undefined;
347
- /** Optional logger for logging message consumption and errors */
382
+ handlers: WorkerInferConsumerHandlers<TContract>; /** AMQP broker URL(s). Multiple URLs provide failover support */
383
+ urls: ConnectionUrl[]; /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
384
+ connectionOptions?: AmqpConnectionManagerOptions | undefined; /** Optional logger for logging message consumption and errors */
348
385
  logger?: Logger | undefined;
349
386
  /**
350
387
  * Optional telemetry provider for tracing and metrics.
@@ -364,17 +401,18 @@ type CreateWorkerOptions<TContract extends ContractDefinitionInput> = {
364
401
  * @example
365
402
  * ```typescript
366
403
  * import { TypedAmqpWorker } from '@amqp-contract/worker';
404
+ * import { defineQueue, defineMessage, defineContract, defineConsumer } from '@amqp-contract/contract';
367
405
  * import { z } from 'zod';
368
406
  *
407
+ * const orderQueue = defineQueue('order-processing', { durable: true });
408
+ * const orderMessage = defineMessage(z.object({
409
+ * orderId: z.string(),
410
+ * amount: z.number()
411
+ * }));
412
+ *
369
413
  * const contract = defineContract({
370
- * queues: {
371
- * orderProcessing: defineQueue('order-processing', { durable: true })
372
- * },
373
414
  * consumers: {
374
- * processOrder: defineConsumer('order-processing', z.object({
375
- * orderId: z.string(),
376
- * amount: z.number()
377
- * }))
415
+ * processOrder: defineConsumer(orderQueue, orderMessage)
378
416
  * }
379
417
  * });
380
418
  *
@@ -393,7 +431,7 @@ type CreateWorkerOptions<TContract extends ContractDefinitionInput> = {
393
431
  * await worker.close().resultToPromise();
394
432
  * ```
395
433
  */
396
- declare class TypedAmqpWorker<TContract extends ContractDefinitionInput> {
434
+ declare class TypedAmqpWorker<TContract extends ContractDefinition> {
397
435
  private readonly contract;
398
436
  private readonly amqpClient;
399
437
  private readonly logger?;
@@ -430,7 +468,7 @@ declare class TypedAmqpWorker<TContract extends ContractDefinitionInput> {
430
468
  * }).resultToPromise();
431
469
  * ```
432
470
  */
433
- static create<TContract extends ContractDefinitionInput>({
471
+ static create<TContract extends ContractDefinition>({
434
472
  contract,
435
473
  handlers,
436
474
  urls,
@@ -607,8 +645,8 @@ declare class TypedAmqpWorker<TContract extends ContractDefinitionInput> {
607
645
  * );
608
646
  * ```
609
647
  */
610
- declare function defineHandler<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>>(contract: TContract, consumerName: TName, handler: WorkerInferConsumerHandler<TContract, TName>): WorkerInferConsumerHandlerEntry<TContract, TName>;
611
- declare function defineHandler<TContract extends ContractDefinitionInput, TName extends InferConsumerNames<TContract>>(contract: TContract, consumerName: TName, handler: WorkerInferConsumerHandler<TContract, TName>, options: {
648
+ declare function defineHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>>(contract: TContract, consumerName: TName, handler: WorkerInferConsumerHandler<TContract, TName>): WorkerInferConsumerHandlerEntry<TContract, TName>;
649
+ declare function defineHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>>(contract: TContract, consumerName: TName, handler: WorkerInferConsumerHandler<TContract, TName>, options: {
612
650
  prefetch?: number;
613
651
  }): WorkerInferConsumerHandlerEntry<TContract, TName>;
614
652
  /**
@@ -640,7 +678,7 @@ declare function defineHandler<TContract extends ContractDefinitionInput, TName
640
678
  * });
641
679
  * ```
642
680
  */
643
- declare function defineHandlers<TContract extends ContractDefinitionInput>(contract: TContract, handlers: WorkerInferConsumerHandlers<TContract>): WorkerInferConsumerHandlers<TContract>;
681
+ declare function defineHandlers<TContract extends ContractDefinition>(contract: TContract, handlers: WorkerInferConsumerHandlers<TContract>): WorkerInferConsumerHandlers<TContract>;
644
682
  //#endregion
645
683
  export { type CreateWorkerOptions, type HandlerError, MessageValidationError, NonRetryableError, RetryableError, TypedAmqpWorker, type WorkerConsumedMessage, type WorkerInferConsumedMessage, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlerEntry, type WorkerInferConsumerHandlers, type WorkerInferConsumerHeaders, type WorkerInferSafeConsumerHandler, type WorkerInferSafeConsumerHandlerEntry, type WorkerInferSafeConsumerHandlers, defineHandler, defineHandlers, isHandlerError, isNonRetryableError, isRetryableError, nonRetryable, retryable };
646
684
  //# sourceMappingURL=index.d.mts.map