@amqp-contract/client 0.25.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,13 +1,92 @@
1
1
  import { CompressionAlgorithm, ContractDefinition, InferPublisherNames, InferRpcNames, MessageDefinition, PublisherEntry, RpcDefinition } from "@amqp-contract/contract";
2
2
  import { Logger, MessageValidationError, PublishOptions as PublishOptions$1, TechnicalError, TelemetryProvider } from "@amqp-contract/core";
3
- import { ResultAsync } from "neverthrow";
4
- import * as amqp from "amqplib";
5
- import { TcpSocketConnectOpts } from "net";
3
+ import { AsyncResult } from "unthrown";
6
4
  import { ConnectionOptions } from "tls";
5
+ import { TcpSocketConnectOpts } from "net";
7
6
  import { StandardSchemaV1 } from "@standard-schema/spec";
8
7
 
9
- //#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
10
- type ConnectionUrl = string | amqp.Options.Connect | {
8
+ //#region ../../node_modules/.pnpm/amqplib@2.0.1/node_modules/amqplib/lib/properties.d.ts
9
+ declare namespace Options {
10
+ interface Connect {
11
+ protocol?: string;
12
+ hostname?: string;
13
+ port?: number;
14
+ username?: string;
15
+ password?: string;
16
+ locale?: string;
17
+ frameMax?: number;
18
+ heartbeat?: number;
19
+ vhost?: string;
20
+ channelMax?: number;
21
+ credentials?: {
22
+ mechanism: string;
23
+ response(): Buffer;
24
+ username?: string;
25
+ password?: string;
26
+ };
27
+ }
28
+ interface AssertQueue {
29
+ exclusive?: boolean;
30
+ durable?: boolean;
31
+ autoDelete?: boolean;
32
+ arguments?: any;
33
+ messageTtl?: number;
34
+ expires?: number;
35
+ deadLetterExchange?: string;
36
+ deadLetterRoutingKey?: string;
37
+ maxLength?: number;
38
+ maxPriority?: number;
39
+ overflow?: string;
40
+ queueMode?: string;
41
+ }
42
+ interface DeleteQueue {
43
+ ifUnused?: boolean;
44
+ ifEmpty?: boolean;
45
+ }
46
+ interface AssertExchange {
47
+ durable?: boolean;
48
+ internal?: boolean;
49
+ autoDelete?: boolean;
50
+ alternateExchange?: string;
51
+ arguments?: any;
52
+ }
53
+ interface DeleteExchange {
54
+ ifUnused?: boolean;
55
+ }
56
+ interface Publish {
57
+ expiration?: string | number;
58
+ userId?: string;
59
+ CC?: string | string[];
60
+ mandatory?: boolean;
61
+ persistent?: boolean;
62
+ deliveryMode?: boolean | number;
63
+ BCC?: string | string[];
64
+ contentType?: string;
65
+ contentEncoding?: string;
66
+ headers?: any;
67
+ priority?: number;
68
+ correlationId?: string;
69
+ replyTo?: string;
70
+ messageId?: string;
71
+ timestamp?: number;
72
+ type?: string;
73
+ appId?: string;
74
+ }
75
+ interface Consume {
76
+ consumerTag?: string;
77
+ noLocal?: boolean;
78
+ noAck?: boolean;
79
+ exclusive?: boolean;
80
+ priority?: number;
81
+ arguments?: any;
82
+ }
83
+ interface Get {
84
+ noAck?: boolean;
85
+ }
86
+ }
87
+ //#endregion
88
+ //#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@2.0.1/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
89
+ type ConnectionUrl = string | Options.Connect | {
11
90
  url: string;
12
91
  connectionOptions?: AmqpConnectionOptions;
13
92
  };
@@ -48,26 +127,36 @@ interface AmqpConnectionManagerOptions {
48
127
  }
49
128
  //#endregion
50
129
  //#region src/errors.d.ts
130
+ declare const RpcTimeoutError_base: import("unthrown").TaggedErrorConstructor<"@amqp-contract/RpcTimeoutError">;
51
131
  /**
52
132
  * Returned from `TypedAmqpClient.call()` when the configured `timeoutMs` elapses
53
133
  * before the RPC server publishes a reply with the matching `correlationId`.
54
134
  *
55
135
  * The pending call is removed from the in-memory correlation map; if a reply
56
136
  * arrives after the timeout it is dropped (and a debug log is emitted by the
57
- * client if a logger is configured).
137
+ * client if a logger is configured). Carries a namespaced `_tag` of
138
+ * `"@amqp-contract/RpcTimeoutError"`; the `Error.name` is kept bare
139
+ * (`"RpcTimeoutError"`).
58
140
  */
59
- declare class RpcTimeoutError extends Error {
60
- readonly rpcName: string;
61
- readonly timeoutMs: number;
141
+ declare class RpcTimeoutError extends RpcTimeoutError_base<{
142
+ message: string;
143
+ rpcName: string;
144
+ timeoutMs: number;
145
+ }> {
62
146
  constructor(rpcName: string, timeoutMs: number);
63
147
  }
148
+ declare const RpcCancelledError_base: import("unthrown").TaggedErrorConstructor<"@amqp-contract/RpcCancelledError">;
64
149
  /**
65
150
  * Returned from any in-flight RPC call when the client is closed before the
66
151
  * reply is received. The correlation map is cleared on close and every pending
67
- * caller's promise resolves with `err(RpcCancelledError)`.
152
+ * caller's promise resolves with `Err(RpcCancelledError)`. Carries a namespaced
153
+ * `_tag` of `"@amqp-contract/RpcCancelledError"`; the `Error.name` is kept bare
154
+ * (`"RpcCancelledError"`).
68
155
  */
69
- declare class RpcCancelledError extends Error {
70
- readonly rpcName: string;
156
+ declare class RpcCancelledError extends RpcCancelledError_base<{
157
+ message: string;
158
+ rpcName: string;
159
+ }> {
71
160
  constructor(rpcName: string);
72
161
  }
73
162
  //#endregion
@@ -141,7 +230,7 @@ type CreateClientOptions<TContract extends ContractDefinition> = {
141
230
  defaultPublishOptions?: PublishOptions | undefined;
142
231
  /**
143
232
  * Maximum time in ms to wait for the AMQP connection to become ready before
144
- * `create()` resolves to an `err(TechnicalError)`. Defaults to 30s
233
+ * `create()` resolves to an `Err(TechnicalError)`. Defaults to 30s
145
234
  * (the {@link AmqpClient}'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to
146
235
  * disable the timeout and let amqp-connection-manager retry indefinitely.
147
236
  */
@@ -153,7 +242,7 @@ type CreateClientOptions<TContract extends ContractDefinition> = {
153
242
  type CallOptions = {
154
243
  /**
155
244
  * Maximum time in ms to wait for an RPC reply. If exceeded, the call resolves
156
- * to `err(RpcTimeoutError)` and the in-memory correlation entry is cleared.
245
+ * to `Err(RpcTimeoutError)` and the in-memory correlation entry is cleared.
157
246
  * A late reply arriving after the timeout is silently dropped.
158
247
  *
159
248
  * Required: RPC without a timeout is a footgun.
@@ -203,7 +292,7 @@ declare class TypedAmqpClient<TContract extends ContractDefinition> {
203
292
  logger,
204
293
  telemetry,
205
294
  connectTimeoutMs
206
- }: CreateClientOptions<TContract>): ResultAsync<TypedAmqpClient<TContract>, TechnicalError>;
295
+ }: CreateClientOptions<TContract>): AsyncResult<TypedAmqpClient<TContract>, TechnicalError>;
207
296
  /**
208
297
  * If the contract has any RPC entry, subscribe to `amq.rabbitmq.reply-to`
209
298
  * once. Replies for every in-flight call arrive on this single consumer and
@@ -232,29 +321,33 @@ declare class TypedAmqpClient<TContract extends ContractDefinition> {
232
321
  * and the `contentEncoding` property will be set automatically. Any `contentEncoding`
233
322
  * value already in options will be overwritten by the compression algorithm.
234
323
  */
235
- publish<TName extends InferPublisherNames<TContract>>(publisherName: TName, message: ClientInferPublisherInput<TContract, TName>, options?: PublishOptions): ResultAsync<void, TechnicalError | MessageValidationError>;
324
+ publish<TName extends InferPublisherNames<TContract>>(publisherName: TName, message: ClientInferPublisherInput<TContract, TName>, options?: PublishOptions): AsyncResult<void, TechnicalError | MessageValidationError>;
236
325
  /**
237
326
  * Invoke an RPC defined via `defineRpc` and await the typed response.
238
327
  *
239
328
  * The request payload is validated against the RPC's request schema, then
240
329
  * published to the AMQP default exchange with the server's queue name as
241
330
  * routing key, `replyTo` set to `amq.rabbitmq.reply-to`, and a fresh UUID
242
- * `correlationId`. The returned ResultAsync resolves once a matching reply
331
+ * `correlationId`. The returned AsyncResult resolves once a matching reply
243
332
  * arrives and validates against the response schema, or once `timeoutMs`
244
333
  * elapses (whichever comes first).
245
334
  *
246
335
  * @example
247
336
  * ```typescript
248
337
  * const result = await client.call('calculate', { a: 1, b: 2 }, { timeoutMs: 5_000 });
249
- * if (result.isOk()) console.log(result.value.sum); // 3
338
+ * result.match({
339
+ * ok: (value) => console.log(value.sum), // 3
340
+ * err: (error) => console.error(error),
341
+ * defect: (cause) => console.error(cause),
342
+ * });
250
343
  * ```
251
344
  */
252
- call<TName extends InferRpcNames<TContract>>(rpcName: TName, request: ClientInferRpcRequestInput<TContract, TName>, options: CallOptions): ResultAsync<ClientInferRpcResponseOutput<TContract, TName>, TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError>;
345
+ call<TName extends InferRpcNames<TContract>>(rpcName: TName, request: ClientInferRpcRequestInput<TContract, TName>, options: CallOptions): AsyncResult<ClientInferRpcResponseOutput<TContract, TName>, TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError>;
253
346
  /**
254
347
  * Close the channel and connection. Cancels the reply consumer (if any) and
255
348
  * rejects every in-flight RPC call with `RpcCancelledError`.
256
349
  */
257
- close(): ResultAsync<void, TechnicalError>;
350
+ close(): AsyncResult<void, TechnicalError>;
258
351
  private waitForConnectionReady;
259
352
  }
260
353
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","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/client.ts"],"x_google_ignoreList":[0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;EAAA,iBG2E1B,YAAA;EF3GU;;;;EAAA,QEiHnB,gBAAA;EAAA,QAED,WAAA,CAAA;;;;;;AFnGT;;;;;SEqHS,MAAA,mBAAyB,kBAAA,CAAA,CAAA;IAC9B,QAAA;IACA,IAAA;IACA,iBAAA;IACA,qBAAA;IACA,MAAA;IACA,SAAA;IACA;EAAA,GACC,mBAAA,CAAoB,SAAA,IAAa,WAAA,CAAY,eAAA,CAAgB,SAAA,GAAY,cAAA;;;;;;UAmCpE,0BAAA;;AD9LoD;;;;;;;;UCqNpD,cAAA;EDhN4B;;;;;;;AACmB;;;;;EC2RvD,OAAA,eAAsB,mBAAA,CAAoB,SAAA,EAAA,CACxC,aAAA,EAAe,KAAA,EACf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,KAAA,GAC9C,OAAA,GAAU,cAAA,GACT,WAAA,OAAkB,cAAA,GAAiB,sBAAA;EDzRN;;;;;;;;;;;AAAwC;;;;;ECiYxE,IAAA,eAAmB,aAAA,CAAc,SAAA,EAAA,CAC/B,OAAA,EAAS,KAAA,EACT,OAAA,EAAS,0BAAA,CAA2B,SAAA,EAAW,KAAA,GAC/C,OAAA,EAAS,WAAA,GACR,WAAA,CACD,4BAAA,CAA6B,SAAA,EAAW,KAAA,GACxC,cAAA,GAAiB,sBAAA,GAAyB,eAAA,GAAkB,iBAAA;ED7X3C;;;;EC6gBnB,KAAA,CAAA,GAAS,WAAA,OAAkB,cAAA;EAAA,QAkBnB,sBAAA;AAAA"}
1
+ {"version":3,"file":"index.d.mts","names":["Empty","AssertQueue","queue","messageCount","consumerCount","PurgeQueue","DeleteQueue","AssertExchange","exchange","Consume","consumerTag","Connect","protocol","hostname","port","username","password","locale","frameMax","heartbeat","vhost","channelMax","credentials","mechanism","response","Buffer","exclusive","durable","autoDelete","arguments","messageTtl","expires","deadLetterExchange","deadLetterRoutingKey","maxLength","maxPriority","overflow","queueMode","ifUnused","ifEmpty","internal","alternateExchange","DeleteExchange","Publish","expiration","userId","CC","mandatory","persistent","deliveryMode","BCC","contentType","contentEncoding","headers","priority","correlationId","replyTo","messageId","timestamp","type","appId","noLocal","noAck","Get","tls","ConnectionOptions","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","Record","highWaterMark","content","fields","MessageFields","properties","MessageProperties","Message","GetMessageFields","ConsumeMessageFields","deliveryTag","redelivered","routingKey","CommonMessageFields","MessagePropertyHeaders","clusterId","XDeath","key","count","reason","time","value","host","product","version","platform","copyright","information","amqp","Options","Connect","url","connectionOptions","AmqpConnectionOptions","connection","Connection","arg","err","Error","ConnectionOptions","TcpSocketConnectOpts","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","Buffer","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","ConnectionUrl","urls","callback","Promise","EventEmitter","addListener","event","args","listener","ConnectListener","ConnectFailedListener","reason","listeners","eventName","Function","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","CreateChannelOpts","ChannelWrapper","close","isConnected","ChannelModel","channelCount","IAmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","AmqpConnectionManagerOptions","_connect"],"sources":["../../../node_modules/.pnpm/amqplib@2.0.1/node_modules/amqplib/lib/properties.d.ts","../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@2.0.1/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts","../src/errors.ts","../src/types.ts","../src/client.ts"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;;kBAuBiB,OAAA;EAAA,UACLW,OAAAA;IACRC,QAAAA;IACAC,QAAAA;IACAC,IAAAA;IACAC,QAAAA;IACAC,QAAAA;IACAC,MAAAA;IACAC,QAAAA;IACAC,SAAAA;IACAC,KAAAA;IACAC,UAAAA;IACAC,WAAAA;MACEC,SAAAA;MACAC,QAAAA,IAAY,MAAM;MAClBT,QAAAA;MACAC,QAAAA;IAAAA;EAAAA;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,CAAoB,SAAA,GACxC,aAAA,EAAe,KAAA,EACf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,KAAA,GAC9C,OAAA,GAAU,cAAA,GACT,WAAA,OAAkB,cAAA,GAAiB,sBAAA;EHrRV;AAG9B;;;;;;;;;;;;;;;;;;;EG8XE,IAAA,eAAmB,aAAA,CAAc,SAAA,GAC/B,OAAA,EAAS,KAAA,EACT,OAAA,EAAS,0BAAA,CAA2B,SAAA,EAAW,KAAA,GAC/C,OAAA,EAAS,WAAA,GACR,WAAA,CACD,4BAAA,CAA6B,SAAA,EAAW,KAAA,GACxC,cAAA,GAAiB,sBAAA,GAAyB,eAAA,GAAkB,iBAAA;EHrXyDY;;;;EGygBvH,KAAA,IAAS,WAAA,OAAkB,cAAA;EAAA,QAkBnB,sBAAA;AAAA"}
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { extractQueue } from "@amqp-contract/contract";
2
2
  import { AmqpClient, MessageValidationError, MessagingSemanticConventions, TechnicalError, defaultTelemetryProvider, endSpanError, endSpanSuccess, recordLateRpcReply, recordPublishMetric, safeJsonParse, startPublishSpan } from "@amqp-contract/core";
3
- import { ResultAsync, err, errAsync, ok, okAsync } from "neverthrow";
3
+ import { Err, Ok, TaggedError, fromPromise, fromSafePromise } from "unthrown";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { deflate, gzip } from "node:zlib";
6
6
  import { promisify } from "node:util";
@@ -13,50 +13,47 @@ const deflateAsync = promisify(deflate);
13
13
  *
14
14
  * @param buffer - The buffer to compress
15
15
  * @param algorithm - The compression algorithm to use
16
- * @returns A ResultAsync resolving to the compressed buffer or a TechnicalError
16
+ * @returns An AsyncResult resolving to the compressed buffer or a TechnicalError
17
17
  *
18
18
  * @internal
19
19
  */
20
20
  function compressBuffer(buffer, algorithm) {
21
- return match(algorithm).with("gzip", () => ResultAsync.fromPromise(gzipAsync(buffer), (error) => new TechnicalError("Failed to compress with gzip", error))).with("deflate", () => ResultAsync.fromPromise(deflateAsync(buffer), (error) => new TechnicalError("Failed to compress with deflate", error))).exhaustive();
21
+ return match(algorithm).with("gzip", () => fromPromise(gzipAsync(buffer), (error) => new TechnicalError("Failed to compress with gzip", error))).with("deflate", () => fromPromise(deflateAsync(buffer), (error) => new TechnicalError("Failed to compress with deflate", error))).exhaustive();
22
22
  }
23
23
  //#endregion
24
24
  //#region src/errors.ts
25
25
  /**
26
- * Captured `Error.captureStackTrace` shim — only present on Node.js.
27
- */
28
- function captureStack(target, ctor) {
29
- const ErrorConstructor = Error;
30
- if (typeof ErrorConstructor.captureStackTrace === "function") ErrorConstructor.captureStackTrace(target, ctor);
31
- }
32
- /**
33
26
  * Returned from `TypedAmqpClient.call()` when the configured `timeoutMs` elapses
34
27
  * before the RPC server publishes a reply with the matching `correlationId`.
35
28
  *
36
29
  * The pending call is removed from the in-memory correlation map; if a reply
37
30
  * arrives after the timeout it is dropped (and a debug log is emitted by the
38
- * client if a logger is configured).
31
+ * client if a logger is configured). Carries a namespaced `_tag` of
32
+ * `"@amqp-contract/RpcTimeoutError"`; the `Error.name` is kept bare
33
+ * (`"RpcTimeoutError"`).
39
34
  */
40
- var RpcTimeoutError = class extends Error {
35
+ var RpcTimeoutError = class extends TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError" }) {
41
36
  constructor(rpcName, timeoutMs) {
42
- super(`RPC call to "${rpcName}" timed out after ${timeoutMs}ms with no reply received`);
43
- this.rpcName = rpcName;
44
- this.timeoutMs = timeoutMs;
45
- this.name = "RpcTimeoutError";
46
- captureStack(this, this.constructor);
37
+ super({
38
+ message: `RPC call to "${rpcName}" timed out after ${timeoutMs}ms with no reply received`,
39
+ rpcName,
40
+ timeoutMs
41
+ });
47
42
  }
48
43
  };
49
44
  /**
50
45
  * Returned from any in-flight RPC call when the client is closed before the
51
46
  * reply is received. The correlation map is cleared on close and every pending
52
- * caller's promise resolves with `err(RpcCancelledError)`.
47
+ * caller's promise resolves with `Err(RpcCancelledError)`. Carries a namespaced
48
+ * `_tag` of `"@amqp-contract/RpcCancelledError"`; the `Error.name` is kept bare
49
+ * (`"RpcCancelledError"`).
53
50
  */
54
- var RpcCancelledError = class extends Error {
51
+ var RpcCancelledError = class extends TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError" }) {
55
52
  constructor(rpcName) {
56
- super(`RPC call to "${rpcName}" was cancelled because the client was closed`);
57
- this.rpcName = rpcName;
58
- this.name = "RpcCancelledError";
59
- captureStack(this, this.constructor);
53
+ super({
54
+ message: `RPC call to "${rpcName}" was cancelled because the client was closed`,
55
+ rpcName
56
+ });
60
57
  }
61
58
  };
62
59
  //#endregion
@@ -74,6 +71,11 @@ const DIRECT_REPLY_TO = "amq.rabbitmq.reply-to";
74
71
  * Type-safe AMQP client for publishing messages
75
72
  */
76
73
  var TypedAmqpClient = class TypedAmqpClient {
74
+ contract;
75
+ amqpClient;
76
+ defaultPublishOptions;
77
+ logger;
78
+ telemetry;
77
79
  /**
78
80
  * In-flight RPC calls keyed by `correlationId`. Cleared when a reply is
79
81
  * received, when the call times out, or when the client is closed.
@@ -110,14 +112,15 @@ var TypedAmqpClient = class TypedAmqpClient {
110
112
  persistent: true,
111
113
  ...defaultPublishOptions
112
114
  }, logger, telemetry ?? defaultTelemetryProvider);
113
- const setup = client.waitForConnectionReady().andThen(() => client.setupReplyConsumerIfNeeded());
114
- return new ResultAsync((async () => {
115
+ const setup = client.waitForConnectionReady().flatMap(() => client.setupReplyConsumerIfNeeded());
116
+ return fromSafePromise((async () => {
115
117
  const setupResult = await setup;
116
- if (setupResult.isOk()) return ok(client);
117
- const closeResult = await client.close();
118
- if (closeResult.isErr()) logger?.warn("Failed to close client after connection failure", { error: closeResult.error });
119
- return err(setupResult.error);
120
- })());
118
+ if (!setupResult.isOk()) {
119
+ const closeResult = await client.close();
120
+ if (closeResult.isErr()) logger?.warn("Failed to close client after connection failure", { error: closeResult.error });
121
+ }
122
+ return setupResult.map(() => client);
123
+ })()).flatMap((result) => result);
121
124
  }
122
125
  /**
123
126
  * If the contract has any RPC entry, subscribe to `amq.rabbitmq.reply-to`
@@ -126,8 +129,8 @@ var TypedAmqpClient = class TypedAmqpClient {
126
129
  */
127
130
  setupReplyConsumerIfNeeded() {
128
131
  const rpcs = this.contract.rpcs ?? {};
129
- if (Object.keys(rpcs).length === 0) return okAsync(void 0);
130
- return this.amqpClient.consume(DIRECT_REPLY_TO, (msg) => this.handleRpcReply(msg), { noAck: true }).andTee((tag) => {
132
+ if (Object.keys(rpcs).length === 0) return Ok(void 0).toAsync();
133
+ return this.amqpClient.consume(DIRECT_REPLY_TO, (msg) => this.handleRpcReply(msg), { noAck: true }).tap((tag) => {
131
134
  this.replyConsumerTag = tag;
132
135
  }).map(() => void 0);
133
136
  }
@@ -157,8 +160,8 @@ var TypedAmqpClient = class TypedAmqpClient {
157
160
  this.pendingCalls.delete(correlationId);
158
161
  clearTimeout(pending.timer);
159
162
  const parseResult = safeJsonParse(msg.content, (error) => new TechnicalError(`Failed to parse RPC reply JSON for "${pending.rpcName}"`, error));
160
- if (parseResult.isErr()) {
161
- pending.resolve(err(parseResult.error));
163
+ if (!parseResult.isOk()) {
164
+ pending.resolve(Err(parseResult.isErr() ? parseResult.error : new TechnicalError(`Failed to parse RPC reply JSON for "${pending.rpcName}"`, parseResult.cause)));
162
165
  return;
163
166
  }
164
167
  const parsed = parseResult.value;
@@ -166,17 +169,17 @@ var TypedAmqpClient = class TypedAmqpClient {
166
169
  try {
167
170
  rawValidation = pending.responseSchema["~standard"].validate(parsed);
168
171
  } catch (error) {
169
- pending.resolve(err(new TechnicalError(`RPC reply validation threw for "${pending.rpcName}"`, error)));
172
+ pending.resolve(Err(new TechnicalError(`RPC reply validation threw for "${pending.rpcName}"`, error)));
170
173
  return;
171
174
  }
172
175
  (rawValidation instanceof Promise ? rawValidation : Promise.resolve(rawValidation)).then((validation) => {
173
176
  if (validation.issues) {
174
- pending.resolve(err(new MessageValidationError(pending.rpcName, validation.issues)));
177
+ pending.resolve(Err(new MessageValidationError(pending.rpcName, validation.issues)));
175
178
  return;
176
179
  }
177
- pending.resolve(ok(validation.value));
180
+ pending.resolve(Ok(validation.value));
178
181
  }, (error) => {
179
- pending.resolve(err(new TechnicalError(`RPC reply validation threw for "${pending.rpcName}"`, error)));
182
+ pending.resolve(Err(new TechnicalError(`RPC reply validation threw for "${pending.rpcName}"`, error)));
180
183
  });
181
184
  }
182
185
  /**
@@ -198,10 +201,9 @@ var TypedAmqpClient = class TypedAmqpClient {
198
201
  const span = startPublishSpan(this.telemetry, exchange.name, routingKey, { [MessagingSemanticConventions.AMQP_PUBLISHER_NAME]: String(publisherName) });
199
202
  const validateMessage = () => {
200
203
  const validationResult = publisher.message.payload["~standard"].validate(message);
201
- const promise = validationResult instanceof Promise ? validationResult : Promise.resolve(validationResult);
202
- return ResultAsync.fromPromise(promise, (error) => new TechnicalError("Validation failed", error)).andThen((validation) => {
203
- if (validation.issues) return err(new MessageValidationError(String(publisherName), validation.issues));
204
- return ok(validation.value);
204
+ return fromPromise(validationResult instanceof Promise ? validationResult : Promise.resolve(validationResult), (error) => new TechnicalError("Validation failed", error)).flatMap((validation) => {
205
+ if (validation.issues) return Err(new MessageValidationError(String(publisherName), validation.issues));
206
+ return Ok(validation.value);
205
207
  });
206
208
  };
207
209
  const publishMessage = (validatedMessage) => {
@@ -216,24 +218,24 @@ var TypedAmqpClient = class TypedAmqpClient {
216
218
  publishOptions.contentEncoding = compression;
217
219
  return compressBuffer(messageBuffer, compression);
218
220
  }
219
- return okAsync(validatedMessage);
221
+ return Ok(validatedMessage).toAsync();
220
222
  };
221
- return preparePayload().andThen((payload) => this.amqpClient.publish(publisher.exchange.name, publisher.routingKey ?? "", payload, publishOptions).andThen((published) => {
222
- if (!published) return err(new TechnicalError(`Failed to publish message for publisher "${String(publisherName)}": Channel rejected the message (buffer full or other channel issue)`));
223
+ return preparePayload().flatMap((payload) => this.amqpClient.publish(publisher.exchange.name, publisher.routingKey ?? "", payload, publishOptions).flatMap((published) => {
224
+ if (!published) return Err(new TechnicalError(`Failed to publish message for publisher "${String(publisherName)}": Channel rejected the message (buffer full or other channel issue)`));
223
225
  this.logger?.info("Message published successfully", {
224
226
  publisherName: String(publisherName),
225
227
  exchange: publisher.exchange.name,
226
228
  routingKey: publisher.routingKey,
227
229
  compressed: !!compression
228
230
  });
229
- return ok(void 0);
231
+ return Ok(void 0);
230
232
  }));
231
233
  };
232
- return validateMessage().andThen((validatedMessage) => publishMessage(validatedMessage)).andTee(() => {
234
+ return validateMessage().flatMap((validatedMessage) => publishMessage(validatedMessage)).tap(() => {
233
235
  const durationMs = Date.now() - startTime;
234
236
  endSpanSuccess(span);
235
237
  recordPublishMetric(this.telemetry, exchange.name, routingKey, true, durationMs);
236
- }).orTee((error) => {
238
+ }).tapErr((error) => {
237
239
  const durationMs = Date.now() - startTime;
238
240
  endSpanError(span, error);
239
241
  recordPublishMetric(this.telemetry, exchange.name, routingKey, false, durationMs);
@@ -245,19 +247,23 @@ var TypedAmqpClient = class TypedAmqpClient {
245
247
  * The request payload is validated against the RPC's request schema, then
246
248
  * published to the AMQP default exchange with the server's queue name as
247
249
  * routing key, `replyTo` set to `amq.rabbitmq.reply-to`, and a fresh UUID
248
- * `correlationId`. The returned ResultAsync resolves once a matching reply
250
+ * `correlationId`. The returned AsyncResult resolves once a matching reply
249
251
  * arrives and validates against the response schema, or once `timeoutMs`
250
252
  * elapses (whichever comes first).
251
253
  *
252
254
  * @example
253
255
  * ```typescript
254
256
  * const result = await client.call('calculate', { a: 1, b: 2 }, { timeoutMs: 5_000 });
255
- * if (result.isOk()) console.log(result.value.sum); // 3
257
+ * result.match({
258
+ * ok: (value) => console.log(value.sum), // 3
259
+ * err: (error) => console.error(error),
260
+ * defect: (cause) => console.error(cause),
261
+ * });
256
262
  * ```
257
263
  */
258
264
  call(rpcName, request, options) {
259
265
  const TIMEOUT_MAX_MS = 2147483647;
260
- if (typeof options.timeoutMs !== "number" || !Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0 || options.timeoutMs > TIMEOUT_MAX_MS) return errAsync(new TechnicalError(`Invalid timeoutMs for RPC call to "${String(rpcName)}": expected a finite positive number ≤ ${TIMEOUT_MAX_MS}, got ${String(options.timeoutMs)}`));
266
+ if (typeof options.timeoutMs !== "number" || !Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0 || options.timeoutMs > TIMEOUT_MAX_MS) return Err(new TechnicalError(`Invalid timeoutMs for RPC call to "${String(rpcName)}": expected a finite positive number ≤ ${TIMEOUT_MAX_MS}, got ${String(options.timeoutMs)}`)).toAsync();
261
267
  const startTime = Date.now();
262
268
  const rpc = this.contract.rpcs[rpcName];
263
269
  const requestSchema = rpc.request.payload;
@@ -266,13 +272,13 @@ var TypedAmqpClient = class TypedAmqpClient {
266
272
  const span = startPublishSpan(this.telemetry, "", queueName, { [MessagingSemanticConventions.AMQP_PUBLISHER_NAME]: String(rpcName) });
267
273
  const correlationId = randomUUID();
268
274
  let resolveCall;
269
- const callResultAsync = new ResultAsync(new Promise((res) => {
275
+ const callResultAsync = fromSafePromise(new Promise((res) => {
270
276
  resolveCall = res;
271
- }));
277
+ })).flatMap((result) => result);
272
278
  const timer = setTimeout(() => {
273
279
  if (!this.pendingCalls.has(correlationId)) return;
274
280
  this.pendingCalls.delete(correlationId);
275
- resolveCall(err(new RpcTimeoutError(String(rpcName), options.timeoutMs)));
281
+ resolveCall(Err(new RpcTimeoutError(String(rpcName), options.timeoutMs)));
276
282
  }, options.timeoutMs);
277
283
  this.pendingCalls.set(correlationId, {
278
284
  rpcName: String(rpcName),
@@ -285,10 +291,9 @@ var TypedAmqpClient = class TypedAmqpClient {
285
291
  try {
286
292
  rawValidation = requestSchema["~standard"].validate(request);
287
293
  } catch (error) {
288
- return errAsync(new TechnicalError("RPC request validation threw", error));
294
+ return Err(new TechnicalError("RPC request validation threw", error)).toAsync();
289
295
  }
290
- const validationPromise = rawValidation instanceof Promise ? rawValidation : Promise.resolve(rawValidation);
291
- return ResultAsync.fromPromise(validationPromise, (error) => new TechnicalError("RPC request validation threw", error)).andThen((validation) => validation.issues ? err(new MessageValidationError(String(rpcName), validation.issues)) : ok(validation.value));
296
+ return fromPromise(rawValidation instanceof Promise ? rawValidation : Promise.resolve(rawValidation), (error) => new TechnicalError("RPC request validation threw", error)).flatMap((validation) => validation.issues ? Err(new MessageValidationError(String(rpcName), validation.issues)) : Ok(validation.value));
292
297
  };
293
298
  const publishRequest = (validatedRequest) => {
294
299
  const { compression: _ignoredCompression, ...defaultsWithoutCompression } = this.defaultPublishOptions;
@@ -299,19 +304,19 @@ var TypedAmqpClient = class TypedAmqpClient {
299
304
  correlationId,
300
305
  contentType: "application/json"
301
306
  };
302
- return this.amqpClient.publish("", queueName, validatedRequest, publishOptions).andThen((published) => published ? ok(void 0) : err(new TechnicalError(`Failed to publish RPC request for "${String(rpcName)}": channel buffer full`)));
307
+ return this.amqpClient.publish("", queueName, validatedRequest, publishOptions).flatMap((published) => published ? Ok(void 0) : Err(new TechnicalError(`Failed to publish RPC request for "${String(rpcName)}": channel buffer full`)));
303
308
  };
304
- return validateRequest().andThen((validated) => publishRequest(validated)).andThen(() => callResultAsync).orElse((error) => {
309
+ return validateRequest().flatMap((validated) => publishRequest(validated)).flatMap(() => callResultAsync).orElse((error) => {
305
310
  if (this.pendingCalls.has(correlationId)) {
306
311
  clearTimeout(timer);
307
312
  this.pendingCalls.delete(correlationId);
308
313
  }
309
- return errAsync(error);
310
- }).andTee(() => {
314
+ return Err(error).toAsync();
315
+ }).tap(() => {
311
316
  const durationMs = Date.now() - startTime;
312
317
  endSpanSuccess(span);
313
318
  recordPublishMetric(this.telemetry, "", queueName, true, durationMs);
314
- }).orTee((error) => {
319
+ }).tapErr((error) => {
315
320
  const durationMs = Date.now() - startTime;
316
321
  endSpanError(span, error);
317
322
  recordPublishMetric(this.telemetry, "", queueName, false, durationMs);
@@ -324,13 +329,13 @@ var TypedAmqpClient = class TypedAmqpClient {
324
329
  close() {
325
330
  for (const [, pending] of this.pendingCalls) {
326
331
  clearTimeout(pending.timer);
327
- pending.resolve(err(new RpcCancelledError(pending.rpcName)));
332
+ pending.resolve(Err(new RpcCancelledError(pending.rpcName)));
328
333
  }
329
334
  this.pendingCalls.clear();
330
335
  return (this.replyConsumerTag ? this.amqpClient.cancel(this.replyConsumerTag).orElse((error) => {
331
336
  this.logger?.warn("Failed to cancel RPC reply consumer during close", { error });
332
- return ok(void 0);
333
- }) : okAsync(void 0)).andThen(() => this.amqpClient.close());
337
+ return Ok(void 0);
338
+ }) : Ok(void 0).toAsync()).flatMap(() => this.amqpClient.close());
334
339
  }
335
340
  waitForConnectionReady() {
336
341
  return this.amqpClient.waitForConnect();