@amqp-contract/core 0.23.1 → 0.24.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
@@ -5,7 +5,7 @@
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/core.svg?logo=npm)](https://www.npmjs.com/package/@amqp-contract/core)
7
7
  [![npm downloads](https://img.shields.io/npm/dm/@amqp-contract/core.svg)](https://www.npmjs.com/package/@amqp-contract/core)
8
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue?logo=typescript)](https://www.typescriptlang.org/)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-6.0-blue?logo=typescript)](https://www.typescriptlang.org/)
9
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
10
 
11
11
  This package provides centralized functionality for establishing AMQP topology (exchanges, queues, and bindings) from contract definitions, and defines the `Logger` interface used across amqp-contract packages.
@@ -87,11 +87,13 @@ const logger: Logger = {
87
87
  // Pass the logger to client or worker
88
88
  import { TypedAmqpClient } from "@amqp-contract/client";
89
89
 
90
- const client = await TypedAmqpClient.create({
91
- contract,
92
- urls: ["amqp://localhost"],
93
- logger, // Optional: logs published messages
94
- });
90
+ const client = (
91
+ await TypedAmqpClient.create({
92
+ contract,
93
+ urls: ["amqp://localhost"],
94
+ logger, // Optional: logs published messages
95
+ })
96
+ )._unsafeUnwrap();
95
97
  ```
96
98
 
97
99
  ## API
package/dist/index.cjs CHANGED
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
- let _swan_io_boxed = require("@swan-io/boxed");
24
+ let neverthrow = require("neverthrow");
25
25
  let amqp_connection_manager = require("amqp-connection-manager");
26
26
  amqp_connection_manager = __toESM(amqp_connection_manager, 1);
27
27
  let _amqp_contract_contract = require("@amqp-contract/contract");
@@ -321,7 +321,7 @@ function callSetupFunc(setup, channel) {
321
321
  * Default time `waitForConnect` will wait for the broker before erroring out.
322
322
  * Defaulting to a finite value (rather than waiting forever) means a fail-fast
323
323
  * developer experience: a misconfigured URL, a down broker, or wrong
324
- * credentials surface as a Result.Error within 30 seconds. Pass `null`
324
+ * credentials surface as an `err` within 30 seconds. Pass `null`
325
325
  * explicitly to disable the timeout — `Infinity` and other non-finite values
326
326
  * are also coerced to "no timeout" because Node's `setTimeout` clamps large
327
327
  * delays to ~24.8 days and silently fires near-immediately on `Infinity`.
@@ -348,7 +348,7 @@ function resolveConnectTimeoutMs(input) {
348
348
  * - Automatic AMQP topology setup (exchanges, queues, bindings) from contract
349
349
  * - Channel creation with JSON serialization enabled by default
350
350
  *
351
- * All operations return `Future<Result<T, TechnicalError>>` for consistent error handling.
351
+ * All operations return `ResultAsync<T, TechnicalError>` for consistent error handling.
352
352
  *
353
353
  * @example
354
354
  * ```typescript
@@ -357,14 +357,14 @@ function resolveConnectTimeoutMs(input) {
357
357
  * connectionOptions: { heartbeatIntervalInSeconds: 30 }
358
358
  * });
359
359
  *
360
- * // Wait for connection
361
- * await client.waitForConnect().resultToPromise();
360
+ * // Wait for connection (ResultAsync is thenable)
361
+ * await client.waitForConnect();
362
362
  *
363
363
  * // Publish a message
364
- * const result = await client.publish('exchange', 'routingKey', { data: 'value' }).resultToPromise();
364
+ * const result = await client.publish('exchange', 'routingKey', { data: 'value' });
365
365
  *
366
366
  * // Close when done
367
- * await client.close().resultToPromise();
367
+ * await client.close();
368
368
  * ```
369
369
  */
370
370
  var AmqpClient = class {
@@ -422,7 +422,7 @@ var AmqpClient = class {
422
422
  * Wait for the channel to be connected and ready.
423
423
  *
424
424
  * If `connectTimeoutMs` was provided in the constructor options, the returned
425
- * Future resolves to `Result.Error<TechnicalError>` once the timeout elapses.
425
+ * ResultAsync resolves to `err(TechnicalError)` once the timeout elapses.
426
426
  * Without a timeout, this waits forever — amqp-connection-manager retries
427
427
  * connections indefinitely and never errors on its own.
428
428
  *
@@ -431,9 +431,6 @@ var AmqpClient = class {
431
431
  * connection's reference count. Callers must invoke `close()` on the error
432
432
  * path to release the connection — `waitForConnect` does not do this
433
433
  * automatically. The typed factories handle this cleanup for you.
434
- *
435
- * @returns A Future resolving to `Result.Ok(void)` on connect, or
436
- * `Result.Error(TechnicalError)` on timeout / connection failure.
437
434
  */
438
435
  waitForConnect() {
439
436
  const connectPromise = this.channelWrapper.waitForConnect();
@@ -450,50 +447,37 @@ var AmqpClient = class {
450
447
  reject(error);
451
448
  });
452
449
  });
453
- return _swan_io_boxed.Future.fromPromise(racedPromise).mapError((error) => new TechnicalError("Failed to connect to AMQP broker", error));
450
+ return neverthrow.ResultAsync.fromPromise(racedPromise, (error) => new TechnicalError("Failed to connect to AMQP broker", error));
454
451
  }
455
452
  /**
456
453
  * Publish a message to an exchange.
457
454
  *
458
- * @param exchange - The exchange name
459
- * @param routingKey - The routing key
460
- * @param content - The message content (will be JSON serialized if json: true)
461
- * @param options - Optional publish options
462
- * @returns A Future with `Result<boolean>` - true if message was sent, false if channel buffer is full
455
+ * @returns ResultAsync resolving to `true` if the message was sent, `false` if the channel buffer is full.
463
456
  */
464
457
  publish(exchange, routingKey, content, options) {
465
- return _swan_io_boxed.Future.fromPromise(this.channelWrapper.publish(exchange, routingKey, content, options)).mapError((error) => new TechnicalError("Failed to publish message", error));
458
+ return neverthrow.ResultAsync.fromPromise(this.channelWrapper.publish(exchange, routingKey, content, options), (error) => new TechnicalError("Failed to publish message", error));
466
459
  }
467
460
  /**
468
461
  * Publish a message directly to a queue.
469
462
  *
470
- * @param queue - The queue name
471
- * @param content - The message content (will be JSON serialized if json: true)
472
- * @param options - Optional publish options
473
- * @returns A Future with `Result<boolean>` - true if message was sent, false if channel buffer is full
463
+ * @returns ResultAsync resolving to `true` if the message was sent, `false` if the channel buffer is full.
474
464
  */
475
465
  sendToQueue(queue, content, options) {
476
- return _swan_io_boxed.Future.fromPromise(this.channelWrapper.sendToQueue(queue, content, options)).mapError((error) => new TechnicalError("Failed to publish message to queue", error));
466
+ return neverthrow.ResultAsync.fromPromise(this.channelWrapper.sendToQueue(queue, content, options), (error) => new TechnicalError("Failed to publish message to queue", error));
477
467
  }
478
468
  /**
479
469
  * Start consuming messages from a queue.
480
470
  *
481
- * @param queue - The queue name
482
- * @param callback - The callback to invoke for each message
483
- * @param options - Optional consume options
484
- * @returns A Future with `Result<string>` - the consumer tag
471
+ * @returns ResultAsync resolving to the consumer tag.
485
472
  */
486
473
  consume(queue, callback, options) {
487
- return _swan_io_boxed.Future.fromPromise(this.channelWrapper.consume(queue, callback, options)).mapError((error) => new TechnicalError("Failed to start consuming messages", error)).mapOk((reply) => reply.consumerTag);
474
+ return neverthrow.ResultAsync.fromPromise(this.channelWrapper.consume(queue, callback, options), (error) => new TechnicalError("Failed to start consuming messages", error)).map((reply) => reply.consumerTag);
488
475
  }
489
476
  /**
490
477
  * Cancel a consumer by its consumer tag.
491
- *
492
- * @param consumerTag - The consumer tag to cancel
493
- * @returns A Future that resolves when the consumer is cancelled
494
478
  */
495
479
  cancel(consumerTag) {
496
- return _swan_io_boxed.Future.fromPromise(this.channelWrapper.cancel(consumerTag)).mapError((error) => new TechnicalError("Failed to cancel consumer", error)).mapOk(() => void 0);
480
+ return neverthrow.ResultAsync.fromPromise(this.channelWrapper.cancel(consumerTag), (error) => new TechnicalError("Failed to cancel consumer", error)).map(() => void 0);
497
481
  }
498
482
  /**
499
483
  * Acknowledge a message.
@@ -546,13 +530,18 @@ var AmqpClient = class {
546
530
  * - Decrease the reference count on the shared connection
547
531
  * - Close the connection if this was the last client using it
548
532
  *
549
- * @returns A Future that resolves when the channel and connection are closed
533
+ * Both steps run regardless of each other's outcome; if both fail, the
534
+ * errors are wrapped in an AggregateError.
550
535
  */
551
536
  close() {
552
- return _swan_io_boxed.Future.fromPromise(this.channelWrapper.close()).mapError((error) => new TechnicalError("Failed to close channel", error)).flatMap((channelResult) => _swan_io_boxed.Future.fromPromise(ConnectionManagerSingleton.getInstance().releaseConnection(this.urls, this.connectionOptions)).mapError((error) => new TechnicalError("Failed to release connection", error)).map((releaseResult) => {
553
- if (channelResult.isError() && releaseResult.isError()) return _swan_io_boxed.Result.Error(new TechnicalError("Failed to close channel and release connection", new AggregateError([channelResult.error, releaseResult.error], "Failed to close channel and release connection")));
554
- return channelResult.isError() ? channelResult : releaseResult;
555
- }));
537
+ return new neverthrow.ResultAsync((async () => {
538
+ const channelResult = await neverthrow.ResultAsync.fromPromise(this.channelWrapper.close(), (error) => new TechnicalError("Failed to close channel", error));
539
+ const releaseResult = await neverthrow.ResultAsync.fromPromise(ConnectionManagerSingleton.getInstance().releaseConnection(this.urls, this.connectionOptions), (error) => new TechnicalError("Failed to release connection", error));
540
+ if (channelResult.isErr() && releaseResult.isErr()) return (0, neverthrow.err)(new TechnicalError("Failed to close channel and release connection", new AggregateError([channelResult.error, releaseResult.error], "Failed to close channel and release connection")));
541
+ if (channelResult.isErr()) return channelResult;
542
+ if (releaseResult.isErr()) return releaseResult;
543
+ return (0, neverthrow.ok)(void 0);
544
+ })());
556
545
  }
557
546
  /**
558
547
  * Reset connection singleton cache (for testing only)
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ContractDefinition } from "@amqp-contract/contract";
2
- import { Future, Result } from "@swan-io/boxed";
3
2
  import { AmqpConnectionManager, AmqpConnectionManagerOptions, ConnectionUrl, CreateChannelOpts } from "amqp-connection-manager";
4
3
  import { Channel, ConsumeMessage, Options } from "amqplib";
4
+ import { ResultAsync } from "neverthrow";
5
5
  import { Attributes, Counter, Histogram, Span, Tracer } from "@opentelemetry/api";
6
6
 
7
7
  //#region src/errors.d.ts
@@ -35,7 +35,7 @@ declare class MessageValidationError extends Error {
35
35
  * Default time `waitForConnect` will wait for the broker before erroring out.
36
36
  * Defaulting to a finite value (rather than waiting forever) means a fail-fast
37
37
  * developer experience: a misconfigured URL, a down broker, or wrong
38
- * credentials surface as a Result.Error within 30 seconds. Pass `null`
38
+ * credentials surface as an `err` within 30 seconds. Pass `null`
39
39
  * explicitly to disable the timeout — `Infinity` and other non-finite values
40
40
  * are also coerced to "no timeout" because Node's `setTimeout` clamps large
41
41
  * delays to ~24.8 days and silently fires near-immediately on `Infinity`.
@@ -83,7 +83,7 @@ type ConsumerOptions = Options.Consume & {
83
83
  * - Automatic AMQP topology setup (exchanges, queues, bindings) from contract
84
84
  * - Channel creation with JSON serialization enabled by default
85
85
  *
86
- * All operations return `Future<Result<T, TechnicalError>>` for consistent error handling.
86
+ * All operations return `ResultAsync<T, TechnicalError>` for consistent error handling.
87
87
  *
88
88
  * @example
89
89
  * ```typescript
@@ -92,14 +92,14 @@ type ConsumerOptions = Options.Consume & {
92
92
  * connectionOptions: { heartbeatIntervalInSeconds: 30 }
93
93
  * });
94
94
  *
95
- * // Wait for connection
96
- * await client.waitForConnect().resultToPromise();
95
+ * // Wait for connection (ResultAsync is thenable)
96
+ * await client.waitForConnect();
97
97
  *
98
98
  * // Publish a message
99
- * const result = await client.publish('exchange', 'routingKey', { data: 'value' }).resultToPromise();
99
+ * const result = await client.publish('exchange', 'routingKey', { data: 'value' });
100
100
  *
101
101
  * // Close when done
102
- * await client.close().resultToPromise();
102
+ * await client.close();
103
103
  * ```
104
104
  */
105
105
  declare class AmqpClient {
@@ -136,7 +136,7 @@ declare class AmqpClient {
136
136
  * Wait for the channel to be connected and ready.
137
137
  *
138
138
  * If `connectTimeoutMs` was provided in the constructor options, the returned
139
- * Future resolves to `Result.Error<TechnicalError>` once the timeout elapses.
139
+ * ResultAsync resolves to `err(TechnicalError)` once the timeout elapses.
140
140
  * Without a timeout, this waits forever — amqp-connection-manager retries
141
141
  * connections indefinitely and never errors on its own.
142
142
  *
@@ -145,46 +145,30 @@ declare class AmqpClient {
145
145
  * connection's reference count. Callers must invoke `close()` on the error
146
146
  * path to release the connection — `waitForConnect` does not do this
147
147
  * automatically. The typed factories handle this cleanup for you.
148
- *
149
- * @returns A Future resolving to `Result.Ok(void)` on connect, or
150
- * `Result.Error(TechnicalError)` on timeout / connection failure.
151
148
  */
152
- waitForConnect(): Future<Result<void, TechnicalError>>;
149
+ waitForConnect(): ResultAsync<void, TechnicalError>;
153
150
  /**
154
151
  * Publish a message to an exchange.
155
152
  *
156
- * @param exchange - The exchange name
157
- * @param routingKey - The routing key
158
- * @param content - The message content (will be JSON serialized if json: true)
159
- * @param options - Optional publish options
160
- * @returns A Future with `Result<boolean>` - true if message was sent, false if channel buffer is full
153
+ * @returns ResultAsync resolving to `true` if the message was sent, `false` if the channel buffer is full.
161
154
  */
162
- publish(exchange: string, routingKey: string, content: Buffer | unknown, options?: PublishOptions): Future<Result<boolean, TechnicalError>>;
155
+ publish(exchange: string, routingKey: string, content: Buffer | unknown, options?: PublishOptions): ResultAsync<boolean, TechnicalError>;
163
156
  /**
164
157
  * Publish a message directly to a queue.
165
158
  *
166
- * @param queue - The queue name
167
- * @param content - The message content (will be JSON serialized if json: true)
168
- * @param options - Optional publish options
169
- * @returns A Future with `Result<boolean>` - true if message was sent, false if channel buffer is full
159
+ * @returns ResultAsync resolving to `true` if the message was sent, `false` if the channel buffer is full.
170
160
  */
171
- sendToQueue(queue: string, content: Buffer | unknown, options?: PublishOptions): Future<Result<boolean, TechnicalError>>;
161
+ sendToQueue(queue: string, content: Buffer | unknown, options?: PublishOptions): ResultAsync<boolean, TechnicalError>;
172
162
  /**
173
163
  * Start consuming messages from a queue.
174
164
  *
175
- * @param queue - The queue name
176
- * @param callback - The callback to invoke for each message
177
- * @param options - Optional consume options
178
- * @returns A Future with `Result<string>` - the consumer tag
165
+ * @returns ResultAsync resolving to the consumer tag.
179
166
  */
180
- consume(queue: string, callback: ConsumeCallback, options?: ConsumerOptions): Future<Result<string, TechnicalError>>;
167
+ consume(queue: string, callback: ConsumeCallback, options?: ConsumerOptions): ResultAsync<string, TechnicalError>;
181
168
  /**
182
169
  * Cancel a consumer by its consumer tag.
183
- *
184
- * @param consumerTag - The consumer tag to cancel
185
- * @returns A Future that resolves when the consumer is cancelled
186
170
  */
187
- cancel(consumerTag: string): Future<Result<void, TechnicalError>>;
171
+ cancel(consumerTag: string): ResultAsync<void, TechnicalError>;
188
172
  /**
189
173
  * Acknowledge a message.
190
174
  *
@@ -228,9 +212,10 @@ declare class AmqpClient {
228
212
  * - Decrease the reference count on the shared connection
229
213
  * - Close the connection if this was the last client using it
230
214
  *
231
- * @returns A Future that resolves when the channel and connection are closed
215
+ * Both steps run regardless of each other's outcome; if both fail, the
216
+ * errors are wrapped in an AggregateError.
232
217
  */
233
- close(): Future<Result<void, TechnicalError>>;
218
+ close(): ResultAsync<void, TechnicalError>;
234
219
  /**
235
220
  * Reset connection singleton cache (for testing only)
236
221
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/amqp-client.ts","../src/connection-manager.ts","../src/logger.ts","../src/setup.ts","../src/telemetry.ts"],"mappings":";;;;;;;;;;;;;cAMa,cAAA,SAAuB,KAAA;EAAA,SAGP,KAAA;cADzB,OAAA,UACyB,KAAA;AAAA;;;;;;;;;AAuB7B;cAAa,sBAAA,SAA+B,KAAA;EAAA,SAExB,MAAA;EAAA,SACA,MAAA;cADA,MAAA,UACA,MAAA;AAAA;;;;;AA7BpB;;;;;;;cCwCa,0BAAA;;;;ADdb;;;;;;;;KCwCY,iBAAA;EACV,IAAA,EAAM,aAAA;EACN,iBAAA,GAAoB,4BAAA;EACpB,cAAA,GAAiB,OAAA,CAAQ,iBAAA;EACzB,gBAAA;AAAA;;AA9BF;;KAoCY,eAAA,IAAmB,GAAA,EAAK,cAAA,mBAAiC,OAAA;;;AAVrE;KAeY,cAAA,GAAiB,OAAA,CAAQ,OAAA;kDAEnC,OAAA;AAAA;;;;KAMU,eAAA,GAAkB,OAAA,CAAQ,OAAA;EAtBpC,qCAwBA,QAAA;A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AA;;;;iBAiB5C,mBAAA,CACd,QAAA,EAAU,iBAAA,EACV,YAAA,UACA,UAAA,sBACA,OAAA,WACA,UAAA;AJzNF;;;AAAA,iBI+OgB,mBAAA,CACd,QAAA,EAAU,iBAAA,EACV,SAAA,UACA,YAAA,UACA,OAAA,WACA,UAAA;;;;;;;;;iBAyBc,kBAAA,CACd,QAAA,EAAU,iBAAA,EACV,MAAA;;;;;;iBAkBc,8BAAA,CAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/amqp-client.ts","../src/connection-manager.ts","../src/logger.ts","../src/setup.ts","../src/telemetry.ts"],"mappings":";;;;;;;;;;;;;cAMa,cAAA,SAAuB,KAAA;EAAA,SAGP,KAAA;cADzB,OAAA,UACyB,KAAA;AAAA;;;;;;;;;AAuB7B;cAAa,sBAAA,SAA+B,KAAA;EAAA,SAExB,MAAA;EAAA,SACA,MAAA;cADA,MAAA,UACA,MAAA;AAAA;;;;;AA7BpB;;;;;;;cCwCa,0BAAA;;;;ADdb;;;;;;;;KCwCY,iBAAA;EACV,IAAA,EAAM,aAAA;EACN,iBAAA,GAAoB,4BAAA;EACpB,cAAA,GAAiB,OAAA,CAAQ,iBAAA;EACzB,gBAAA;AAAA;;AA9BF;;KAoCY,eAAA,IAAmB,GAAA,EAAK,cAAA,mBAAiC,OAAA;;;AAVrE;KAeY,cAAA,GAAiB,OAAA,CAAQ,OAAA;kDAEnC,OAAA;AAAA;;;;KAMU,eAAA,GAAkB,OAAA,CAAQ,OAAA;EAtBpC,qCAwBA,QAAA;AAAA;;;;;;;;AAfF;;;;;;;;;AAKA;;;;;;;;;AAQA;;;cAiCa,UAAA;EAAA,iBAoBQ,QAAA;EAAA,iBAnBF,UAAA;EAAA,iBACA,cAAA;EAAA,iBACA,IAAA;EAAA,iBACA,iBAAA;EAJN;EAAA,iBAMM,gBAAA;;;;;;;;;;;;cAcE,QAAA,EAAU,kBAAA,EAC3B,OAAA,EAAS,iBAAA;EA8Ha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Future, Result } from "@swan-io/boxed";
1
+ import { ResultAsync } from "neverthrow";
2
2
  import { AmqpConnectionManager, AmqpConnectionManagerOptions, ConnectionUrl, CreateChannelOpts } from "amqp-connection-manager";
3
3
  import { ContractDefinition } from "@amqp-contract/contract";
4
4
  import { Attributes, Counter, Histogram, Span, Tracer } from "@opentelemetry/api";
@@ -35,7 +35,7 @@ declare class MessageValidationError extends Error {
35
35
  * Default time `waitForConnect` will wait for the broker before erroring out.
36
36
  * Defaulting to a finite value (rather than waiting forever) means a fail-fast
37
37
  * developer experience: a misconfigured URL, a down broker, or wrong
38
- * credentials surface as a Result.Error within 30 seconds. Pass `null`
38
+ * credentials surface as an `err` within 30 seconds. Pass `null`
39
39
  * explicitly to disable the timeout — `Infinity` and other non-finite values
40
40
  * are also coerced to "no timeout" because Node's `setTimeout` clamps large
41
41
  * delays to ~24.8 days and silently fires near-immediately on `Infinity`.
@@ -83,7 +83,7 @@ type ConsumerOptions = Options.Consume & {
83
83
  * - Automatic AMQP topology setup (exchanges, queues, bindings) from contract
84
84
  * - Channel creation with JSON serialization enabled by default
85
85
  *
86
- * All operations return `Future<Result<T, TechnicalError>>` for consistent error handling.
86
+ * All operations return `ResultAsync<T, TechnicalError>` for consistent error handling.
87
87
  *
88
88
  * @example
89
89
  * ```typescript
@@ -92,14 +92,14 @@ type ConsumerOptions = Options.Consume & {
92
92
  * connectionOptions: { heartbeatIntervalInSeconds: 30 }
93
93
  * });
94
94
  *
95
- * // Wait for connection
96
- * await client.waitForConnect().resultToPromise();
95
+ * // Wait for connection (ResultAsync is thenable)
96
+ * await client.waitForConnect();
97
97
  *
98
98
  * // Publish a message
99
- * const result = await client.publish('exchange', 'routingKey', { data: 'value' }).resultToPromise();
99
+ * const result = await client.publish('exchange', 'routingKey', { data: 'value' });
100
100
  *
101
101
  * // Close when done
102
- * await client.close().resultToPromise();
102
+ * await client.close();
103
103
  * ```
104
104
  */
105
105
  declare class AmqpClient {
@@ -136,7 +136,7 @@ declare class AmqpClient {
136
136
  * Wait for the channel to be connected and ready.
137
137
  *
138
138
  * If `connectTimeoutMs` was provided in the constructor options, the returned
139
- * Future resolves to `Result.Error<TechnicalError>` once the timeout elapses.
139
+ * ResultAsync resolves to `err(TechnicalError)` once the timeout elapses.
140
140
  * Without a timeout, this waits forever — amqp-connection-manager retries
141
141
  * connections indefinitely and never errors on its own.
142
142
  *
@@ -145,46 +145,30 @@ declare class AmqpClient {
145
145
  * connection's reference count. Callers must invoke `close()` on the error
146
146
  * path to release the connection — `waitForConnect` does not do this
147
147
  * automatically. The typed factories handle this cleanup for you.
148
- *
149
- * @returns A Future resolving to `Result.Ok(void)` on connect, or
150
- * `Result.Error(TechnicalError)` on timeout / connection failure.
151
148
  */
152
- waitForConnect(): Future<Result<void, TechnicalError>>;
149
+ waitForConnect(): ResultAsync<void, TechnicalError>;
153
150
  /**
154
151
  * Publish a message to an exchange.
155
152
  *
156
- * @param exchange - The exchange name
157
- * @param routingKey - The routing key
158
- * @param content - The message content (will be JSON serialized if json: true)
159
- * @param options - Optional publish options
160
- * @returns A Future with `Result<boolean>` - true if message was sent, false if channel buffer is full
153
+ * @returns ResultAsync resolving to `true` if the message was sent, `false` if the channel buffer is full.
161
154
  */
162
- publish(exchange: string, routingKey: string, content: Buffer | unknown, options?: PublishOptions): Future<Result<boolean, TechnicalError>>;
155
+ publish(exchange: string, routingKey: string, content: Buffer | unknown, options?: PublishOptions): ResultAsync<boolean, TechnicalError>;
163
156
  /**
164
157
  * Publish a message directly to a queue.
165
158
  *
166
- * @param queue - The queue name
167
- * @param content - The message content (will be JSON serialized if json: true)
168
- * @param options - Optional publish options
169
- * @returns A Future with `Result<boolean>` - true if message was sent, false if channel buffer is full
159
+ * @returns ResultAsync resolving to `true` if the message was sent, `false` if the channel buffer is full.
170
160
  */
171
- sendToQueue(queue: string, content: Buffer | unknown, options?: PublishOptions): Future<Result<boolean, TechnicalError>>;
161
+ sendToQueue(queue: string, content: Buffer | unknown, options?: PublishOptions): ResultAsync<boolean, TechnicalError>;
172
162
  /**
173
163
  * Start consuming messages from a queue.
174
164
  *
175
- * @param queue - The queue name
176
- * @param callback - The callback to invoke for each message
177
- * @param options - Optional consume options
178
- * @returns A Future with `Result<string>` - the consumer tag
165
+ * @returns ResultAsync resolving to the consumer tag.
179
166
  */
180
- consume(queue: string, callback: ConsumeCallback, options?: ConsumerOptions): Future<Result<string, TechnicalError>>;
167
+ consume(queue: string, callback: ConsumeCallback, options?: ConsumerOptions): ResultAsync<string, TechnicalError>;
181
168
  /**
182
169
  * Cancel a consumer by its consumer tag.
183
- *
184
- * @param consumerTag - The consumer tag to cancel
185
- * @returns A Future that resolves when the consumer is cancelled
186
170
  */
187
- cancel(consumerTag: string): Future<Result<void, TechnicalError>>;
171
+ cancel(consumerTag: string): ResultAsync<void, TechnicalError>;
188
172
  /**
189
173
  * Acknowledge a message.
190
174
  *
@@ -228,9 +212,10 @@ declare class AmqpClient {
228
212
  * - Decrease the reference count on the shared connection
229
213
  * - Close the connection if this was the last client using it
230
214
  *
231
- * @returns A Future that resolves when the channel and connection are closed
215
+ * Both steps run regardless of each other's outcome; if both fail, the
216
+ * errors are wrapped in an AggregateError.
232
217
  */
233
- close(): Future<Result<void, TechnicalError>>;
218
+ close(): ResultAsync<void, TechnicalError>;
234
219
  /**
235
220
  * Reset connection singleton cache (for testing only)
236
221
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/amqp-client.ts","../src/connection-manager.ts","../src/logger.ts","../src/setup.ts","../src/telemetry.ts"],"mappings":";;;;;;;;;;;;;cAMa,cAAA,SAAuB,KAAA;EAAA,SAGP,KAAA;cADzB,OAAA,UACyB,KAAA;AAAA;;;;;;;;;AAuB7B;cAAa,sBAAA,SAA+B,KAAA;EAAA,SAExB,MAAA;EAAA,SACA,MAAA;cADA,MAAA,UACA,MAAA;AAAA;;;;;AA7BpB;;;;;;;cCwCa,0BAAA;;;;ADdb;;;;;;;;KCwCY,iB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;;;;;iBAavB,gBAAA,CACd,QAAA,EAAU,iBAAA,EACV,YAAA,UACA,UAAA,sBACA,UAAA,GAAa,UAAA,GACZ,IAAA;;;;;iBA8Ba,gBAAA,CACd,QAAA,EAAU,iBAAA,EACV,SAAA,UACA,YAAA,UACA,UAAA,GAAa,UAAA,GACZ,IAAA;;;;iBA2Ba,cAAA,CAAe,IAAA,EAAM,IAAA;;;;iBAerB,YAAA,CAAa,IAAA,EAAM,IAAA,cAAkB,KAAA,EAAO,KAAA;;;;iBAiB5C,mBAAA,CACd,QAAA,EAAU,iBAAA,EACV,YAAA,UACA,UAAA,sBACA,OAAA,WACA,UAAA;AJzNF;;;AAAA,iBI+OgB,mBAAA,CACd,QAAA,EAAU,iBAAA,EACV,SAAA,UACA,YAAA,UACA,OAAA,WACA,UAAA;;;;;;;;;iBAyBc,kBAAA,CACd,QAAA,EAAU,iBAAA,EACV,MAAA;;;;;;iBAkBc,8BAAA,CAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/amqp-client.ts","../src/connection-manager.ts","../src/logger.ts","../src/setup.ts","../src/telemetry.ts"],"mappings":";;;;;;;;;;;;;cAMa,cAAA,SAAuB,KAAA;EAAA,SAGP,KAAA;cADzB,OAAA,UACyB,KAAA;AAAA;;;;;;;;;AAuB7B;cAAa,sBAAA,SAA+B,KAAA;EAAA,SAExB,MAAA;EAAA,SACA,MAAA;cADA,MAAA,UACA,MAAA;AAAA;;;;;AA7BpB;;;;;;;cCwCa,0BAAA;;;;ADdb;;;;;;;;KCwCY,iBAAA;EACV,IAAA,EAAM,aAAA;EACN,iBAAA,GAAoB,4BAAA;EACpB,cAAA,GAAiB,OAAA,CAAQ,iBAAA;EACzB,gBAAA;AAAA;;AA9BF;;KAoCY,eAAA,IAAmB,GAAA,EAAK,cAAA,mBAAiC,OAAA;;;AAVrE;KAeY,cAAA,GAAiB,OAAA,CAAQ,OAAA;kDAEnC,OAAA;AAAA;;;;KAMU,eAAA,GA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BAAA,CACd,QAAA,EAAU,iBAAA,EACV,YAAA,UACA,UAAA,sBACA,OAAA,WACA,UAAA;AJzNF;;;AAAA,iBI+OgB,mBAAA,CACd,QAAA,EAAU,iBAAA,EACV,SAAA,UACA,YAAA,UACA,OAAA,WACA,UAAA;;;;;;;;;iBAyBc,kBAAA,CACd,QAAA,EAAU,iBAAA,EACV,MAAA;;;;;;iBAkBc,8BAAA,CAAA"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { Future, Result } from "@swan-io/boxed";
2
+ import { ResultAsync, err, ok } from "neverthrow";
3
3
  import amqp from "amqp-connection-manager";
4
4
  import { extractQueue } from "@amqp-contract/contract";
5
5
  //#region \0rolldown/runtime.js
@@ -300,7 +300,7 @@ function callSetupFunc(setup, channel) {
300
300
  * Default time `waitForConnect` will wait for the broker before erroring out.
301
301
  * Defaulting to a finite value (rather than waiting forever) means a fail-fast
302
302
  * developer experience: a misconfigured URL, a down broker, or wrong
303
- * credentials surface as a Result.Error within 30 seconds. Pass `null`
303
+ * credentials surface as an `err` within 30 seconds. Pass `null`
304
304
  * explicitly to disable the timeout — `Infinity` and other non-finite values
305
305
  * are also coerced to "no timeout" because Node's `setTimeout` clamps large
306
306
  * delays to ~24.8 days and silently fires near-immediately on `Infinity`.
@@ -327,7 +327,7 @@ function resolveConnectTimeoutMs(input) {
327
327
  * - Automatic AMQP topology setup (exchanges, queues, bindings) from contract
328
328
  * - Channel creation with JSON serialization enabled by default
329
329
  *
330
- * All operations return `Future<Result<T, TechnicalError>>` for consistent error handling.
330
+ * All operations return `ResultAsync<T, TechnicalError>` for consistent error handling.
331
331
  *
332
332
  * @example
333
333
  * ```typescript
@@ -336,14 +336,14 @@ function resolveConnectTimeoutMs(input) {
336
336
  * connectionOptions: { heartbeatIntervalInSeconds: 30 }
337
337
  * });
338
338
  *
339
- * // Wait for connection
340
- * await client.waitForConnect().resultToPromise();
339
+ * // Wait for connection (ResultAsync is thenable)
340
+ * await client.waitForConnect();
341
341
  *
342
342
  * // Publish a message
343
- * const result = await client.publish('exchange', 'routingKey', { data: 'value' }).resultToPromise();
343
+ * const result = await client.publish('exchange', 'routingKey', { data: 'value' });
344
344
  *
345
345
  * // Close when done
346
- * await client.close().resultToPromise();
346
+ * await client.close();
347
347
  * ```
348
348
  */
349
349
  var AmqpClient = class {
@@ -401,7 +401,7 @@ var AmqpClient = class {
401
401
  * Wait for the channel to be connected and ready.
402
402
  *
403
403
  * If `connectTimeoutMs` was provided in the constructor options, the returned
404
- * Future resolves to `Result.Error<TechnicalError>` once the timeout elapses.
404
+ * ResultAsync resolves to `err(TechnicalError)` once the timeout elapses.
405
405
  * Without a timeout, this waits forever — amqp-connection-manager retries
406
406
  * connections indefinitely and never errors on its own.
407
407
  *
@@ -410,9 +410,6 @@ var AmqpClient = class {
410
410
  * connection's reference count. Callers must invoke `close()` on the error
411
411
  * path to release the connection — `waitForConnect` does not do this
412
412
  * automatically. The typed factories handle this cleanup for you.
413
- *
414
- * @returns A Future resolving to `Result.Ok(void)` on connect, or
415
- * `Result.Error(TechnicalError)` on timeout / connection failure.
416
413
  */
417
414
  waitForConnect() {
418
415
  const connectPromise = this.channelWrapper.waitForConnect();
@@ -429,50 +426,37 @@ var AmqpClient = class {
429
426
  reject(error);
430
427
  });
431
428
  });
432
- return Future.fromPromise(racedPromise).mapError((error) => new TechnicalError("Failed to connect to AMQP broker", error));
429
+ return ResultAsync.fromPromise(racedPromise, (error) => new TechnicalError("Failed to connect to AMQP broker", error));
433
430
  }
434
431
  /**
435
432
  * Publish a message to an exchange.
436
433
  *
437
- * @param exchange - The exchange name
438
- * @param routingKey - The routing key
439
- * @param content - The message content (will be JSON serialized if json: true)
440
- * @param options - Optional publish options
441
- * @returns A Future with `Result<boolean>` - true if message was sent, false if channel buffer is full
434
+ * @returns ResultAsync resolving to `true` if the message was sent, `false` if the channel buffer is full.
442
435
  */
443
436
  publish(exchange, routingKey, content, options) {
444
- return Future.fromPromise(this.channelWrapper.publish(exchange, routingKey, content, options)).mapError((error) => new TechnicalError("Failed to publish message", error));
437
+ return ResultAsync.fromPromise(this.channelWrapper.publish(exchange, routingKey, content, options), (error) => new TechnicalError("Failed to publish message", error));
445
438
  }
446
439
  /**
447
440
  * Publish a message directly to a queue.
448
441
  *
449
- * @param queue - The queue name
450
- * @param content - The message content (will be JSON serialized if json: true)
451
- * @param options - Optional publish options
452
- * @returns A Future with `Result<boolean>` - true if message was sent, false if channel buffer is full
442
+ * @returns ResultAsync resolving to `true` if the message was sent, `false` if the channel buffer is full.
453
443
  */
454
444
  sendToQueue(queue, content, options) {
455
- return Future.fromPromise(this.channelWrapper.sendToQueue(queue, content, options)).mapError((error) => new TechnicalError("Failed to publish message to queue", error));
445
+ return ResultAsync.fromPromise(this.channelWrapper.sendToQueue(queue, content, options), (error) => new TechnicalError("Failed to publish message to queue", error));
456
446
  }
457
447
  /**
458
448
  * Start consuming messages from a queue.
459
449
  *
460
- * @param queue - The queue name
461
- * @param callback - The callback to invoke for each message
462
- * @param options - Optional consume options
463
- * @returns A Future with `Result<string>` - the consumer tag
450
+ * @returns ResultAsync resolving to the consumer tag.
464
451
  */
465
452
  consume(queue, callback, options) {
466
- return Future.fromPromise(this.channelWrapper.consume(queue, callback, options)).mapError((error) => new TechnicalError("Failed to start consuming messages", error)).mapOk((reply) => reply.consumerTag);
453
+ return ResultAsync.fromPromise(this.channelWrapper.consume(queue, callback, options), (error) => new TechnicalError("Failed to start consuming messages", error)).map((reply) => reply.consumerTag);
467
454
  }
468
455
  /**
469
456
  * Cancel a consumer by its consumer tag.
470
- *
471
- * @param consumerTag - The consumer tag to cancel
472
- * @returns A Future that resolves when the consumer is cancelled
473
457
  */
474
458
  cancel(consumerTag) {
475
- return Future.fromPromise(this.channelWrapper.cancel(consumerTag)).mapError((error) => new TechnicalError("Failed to cancel consumer", error)).mapOk(() => void 0);
459
+ return ResultAsync.fromPromise(this.channelWrapper.cancel(consumerTag), (error) => new TechnicalError("Failed to cancel consumer", error)).map(() => void 0);
476
460
  }
477
461
  /**
478
462
  * Acknowledge a message.
@@ -525,13 +509,18 @@ var AmqpClient = class {
525
509
  * - Decrease the reference count on the shared connection
526
510
  * - Close the connection if this was the last client using it
527
511
  *
528
- * @returns A Future that resolves when the channel and connection are closed
512
+ * Both steps run regardless of each other's outcome; if both fail, the
513
+ * errors are wrapped in an AggregateError.
529
514
  */
530
515
  close() {
531
- return Future.fromPromise(this.channelWrapper.close()).mapError((error) => new TechnicalError("Failed to close channel", error)).flatMap((channelResult) => Future.fromPromise(ConnectionManagerSingleton.getInstance().releaseConnection(this.urls, this.connectionOptions)).mapError((error) => new TechnicalError("Failed to release connection", error)).map((releaseResult) => {
532
- if (channelResult.isError() && releaseResult.isError()) return Result.Error(new TechnicalError("Failed to close channel and release connection", new AggregateError([channelResult.error, releaseResult.error], "Failed to close channel and release connection")));
533
- return channelResult.isError() ? channelResult : releaseResult;
534
- }));
516
+ return new ResultAsync((async () => {
517
+ const channelResult = await ResultAsync.fromPromise(this.channelWrapper.close(), (error) => new TechnicalError("Failed to close channel", error));
518
+ const releaseResult = await ResultAsync.fromPromise(ConnectionManagerSingleton.getInstance().releaseConnection(this.urls, this.connectionOptions), (error) => new TechnicalError("Failed to release connection", error));
519
+ if (channelResult.isErr() && releaseResult.isErr()) return err(new TechnicalError("Failed to close channel and release connection", new AggregateError([channelResult.error, releaseResult.error], "Failed to close channel and release connection")));
520
+ if (channelResult.isErr()) return channelResult;
521
+ if (releaseResult.isErr()) return releaseResult;
522
+ return ok(void 0);
523
+ })());
535
524
  }
536
525
  /**
537
526
  * Reset connection singleton cache (for testing only)