@amqp-contract/client 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -6
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +28 -28
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -157,13 +157,12 @@ var TypedAmqpClient = class TypedAmqpClient {
|
|
|
157
157
|
}
|
|
158
158
|
this.pendingCalls.delete(correlationId);
|
|
159
159
|
clearTimeout(pending.timer);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
} catch (error) {
|
|
164
|
-
pending.resolve((0, neverthrow.err)(new _amqp_contract_core.TechnicalError(`Failed to parse RPC reply JSON for "${pending.rpcName}"`, error)));
|
|
160
|
+
const parseResult = (0, _amqp_contract_core.safeJsonParse)(msg.content, (error) => new _amqp_contract_core.TechnicalError(`Failed to parse RPC reply JSON for "${pending.rpcName}"`, error));
|
|
161
|
+
if (parseResult.isErr()) {
|
|
162
|
+
pending.resolve((0, neverthrow.err)(parseResult.error));
|
|
165
163
|
return;
|
|
166
164
|
}
|
|
165
|
+
const parsed = parseResult.value;
|
|
167
166
|
let rawValidation;
|
|
168
167
|
try {
|
|
169
168
|
rawValidation = pending.responseSchema["~standard"].validate(parsed);
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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/client.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;EACAC,cAAAA;EACAC,gBAAAA;EACAC,WAAAA;IACIC,SAAAA;IACAC,QAAAA;IACAC,QAAAA;IACAC,QAAAA,QAAgBV,MAAAA;EAAAA;IAEhBO,SAAAA;IACAG,QAAAA,QAAgBV,MAAAA;EAAAA;AAAAA;AAAAA,UAGPW,4BAAAA;EATTJ;EAWJM,0BAAAA;EATIJ;;;;EAcJK,sBAAAA;EAVoBd;;;AAGxB;;;;EAeIe,WAAAA,KAAgBE,QAAAA,GAAWD,IAAAA,EAAM7B,aAAAA,GAAgBA,aAAAA,+BAA4CyB,OAAAA,CAAQzB,aAAAA,GAAgBA,aAAAA;EAAhBA;EAErGK,iBAAAA,GAAoBF,qBAAAA;AAAAA;;;;;;;;;;;cChCX,eAAA,SAAwB,KAAA;EAAA,SAEjB,OAAA;EAAA,SACA,SAAA;cADA,OAAA,UACA,SAAA;AAAA;;;;;;cAaP,iBAAA,SAA0B,KAAA;EAAA,SACT,OAAA;cAAA,OAAA;AAAA;;;;;;KC1BzB,gBAAA,iBAAiC,gBAAA,IACpC,OAAA,SAAgB,gBAAA,iBAAiC,MAAA;;;;KAK9C,iBAAA,iBAAkC,gBAAA,IACrC,OAAA,SAAgB,gBAAA,iCAAiD,OAAA;;;;;;KAO9D,mBAAA,oBAAuC,cAAA,IAAkB,UAAA;EAC5D,OAAA;IAAW,OAAA,EAAS,gBAAA;EAAA;AAAA,IAElB,gBAAA,CAAiB,UAAA;AAAA,KAGhB,eAAA,mBAAkC,kBAAA,IAAsB,WAAA,CAAY,SAAA;AAAA,KACpE,cAAA,mBACe,kBAAA,gBACJ,mBAAA,CAAoB,SAAA,KAChC,eAAA,CAAgB,SAAA,EAAW,KAAA;;;;KAKnB,yBAAA,mBACQ,kBAAA,gBACJ,mBAAA,CAAoB,SAAA,KAChC,mBAAA,CAAoB,cAAA,CAAe,SAAA,EAAW,KAAA;AAAA,KAM7C,SAAA,mBAA4B,kBAAA,IAAsB,WAAA,CAAY,SAAA;AAAA,KAC9D,QAAA,mBACe,kBAAA,gBACJ,aAAA,CAAc,SAAA,KAC1B,SAAA,CAAU,SAAA,EAAW,KAAA;;;;KAKb,0BAAA,mBACQ,kBAAA,gBACJ,aAAA,CAAc,SAAA,KAE5B,QAAA,CAAS,SAAA,EAAW,KAAA,UAAe,aAAA,iBAA8B,iBAAA,IAC7D,QAAA,SAAiB,iBAAA,GACf,gBAAA,CAAiB,QAAA;;;;KAOb,4BAAA,mBACQ,kBAAA,gBACJ,aAAA,CAAc,SAAA,KAE5B,QAAA,CAAS,SAAA,EAAW,KAAA,UAAe,aAAA,CAAc,iBAAA,qBAC7C,SAAA,SAAkB,iBAAA,GAChB,iBAAA,CAAkB,SAAA;;;;;;
|
|
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/client.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;EACAC,cAAAA;EACAC,gBAAAA;EACAC,WAAAA;IACIC,SAAAA;IACAC,QAAAA;IACAC,QAAAA;IACAC,QAAAA,QAAgBV,MAAAA;EAAAA;IAEhBO,SAAAA;IACAG,QAAAA,QAAgBV,MAAAA;EAAAA;AAAAA;AAAAA,UAGPW,4BAAAA;EATTJ;EAWJM,0BAAAA;EATIJ;;;;EAcJK,sBAAAA;EAVoBd;;;AAGxB;;;;EAeIe,WAAAA,KAAgBE,QAAAA,GAAWD,IAAAA,EAAM7B,aAAAA,GAAgBA,aAAAA,+BAA4CyB,OAAAA,CAAQzB,aAAAA,GAAgBA,aAAAA;EAAhBA;EAErGK,iBAAAA,GAAoBF,qBAAAA;AAAAA;;;;;;;;;;;cChCX,eAAA,SAAwB,KAAA;EAAA,SAEjB,OAAA;EAAA,SACA,SAAA;cADA,OAAA,UACA,SAAA;AAAA;;;;;;cAaP,iB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,cAAA,GAAiB,sBAAA,GAAyB,eAAA,GAAkB,iBAAA;ED7X3C;;;;EC6gBnB,KAAA,CAAA,GAAS,WAAA,OAAkB,cAAA;EAAA,QAkBnB,sBAAA;AAAA"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -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],"mappings":";;;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;EACAC,cAAAA;EACAC,gBAAAA;EACAC,WAAAA;IACIC,SAAAA;IACAC,QAAAA;IACAC,QAAAA;IACAC,QAAAA,QAAgBV,MAAAA;EAAAA;IAEhBO,SAAAA;IACAG,QAAAA,QAAgBV,MAAAA;EA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AW,KAAA,UAAe,aAAA,iBAA8B,iBAAA,IAC7D,QAAA,SAAiB,iBAAA,GACf,gBAAA,CAAiB,QAAA;;;;KAOb,4BAAA,mBACQ,kBAAA,gBACJ,aAAA,CAAc,SAAA,KAE5B,QAAA,CAAS,SAAA,EAAW,KAAA,UAAe,aAAA,CAAc,iBAAA,qBAC7C,SAAA,SAAkB,iBAAA,GAChB,iBAAA,CAAkB,SAAA;;;;;;
|
|
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],"mappings":";;;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;EACAC,cAAAA;EACAC,gBAAAA;EACAC,WAAAA;IACIC,SAAAA;IACAC,QAAAA;IACAC,QA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,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"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { extractQueue } from "@amqp-contract/contract";
|
|
2
|
-
import { AmqpClient, MessageValidationError, MessagingSemanticConventions, TechnicalError, defaultTelemetryProvider, endSpanError, endSpanSuccess, recordLateRpcReply, recordPublishMetric, startPublishSpan } from "@amqp-contract/core";
|
|
2
|
+
import { AmqpClient, MessageValidationError, MessagingSemanticConventions, TechnicalError, defaultTelemetryProvider, endSpanError, endSpanSuccess, recordLateRpcReply, recordPublishMetric, safeJsonParse, startPublishSpan } from "@amqp-contract/core";
|
|
3
3
|
import { ResultAsync, err, errAsync, ok, okAsync } from "neverthrow";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { deflate, gzip } from "node:zlib";
|
|
@@ -156,13 +156,12 @@ var TypedAmqpClient = class TypedAmqpClient {
|
|
|
156
156
|
}
|
|
157
157
|
this.pendingCalls.delete(correlationId);
|
|
158
158
|
clearTimeout(pending.timer);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
} catch (error) {
|
|
163
|
-
pending.resolve(err(new TechnicalError(`Failed to parse RPC reply JSON for "${pending.rpcName}"`, error)));
|
|
159
|
+
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));
|
|
164
162
|
return;
|
|
165
163
|
}
|
|
164
|
+
const parsed = parseResult.value;
|
|
166
165
|
let rawValidation;
|
|
167
166
|
try {
|
|
168
167
|
rawValidation = pending.responseSchema["~standard"].validate(parsed);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/compression.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["import type { CompressionAlgorithm } from \"@amqp-contract/contract\";\nimport { TechnicalError } from \"@amqp-contract/core\";\nimport { ResultAsync } from \"neverthrow\";\nimport { deflate, gzip } from \"node:zlib\";\nimport { promisify } from \"node:util\";\nimport { match } from \"ts-pattern\";\n\nconst gzipAsync = promisify(gzip);\nconst deflateAsync = promisify(deflate);\n\n/**\n * Compress a buffer using the specified compression algorithm.\n *\n * @param buffer - The buffer to compress\n * @param algorithm - The compression algorithm to use\n * @returns A ResultAsync resolving to the compressed buffer or a TechnicalError\n *\n * @internal\n */\nexport function compressBuffer(\n buffer: Buffer,\n algorithm: CompressionAlgorithm,\n): ResultAsync<Buffer, TechnicalError> {\n return match(algorithm)\n .with(\"gzip\", () =>\n ResultAsync.fromPromise(\n gzipAsync(buffer),\n (error) => new TechnicalError(\"Failed to compress with gzip\", error),\n ),\n )\n .with(\"deflate\", () =>\n ResultAsync.fromPromise(\n deflateAsync(buffer),\n (error) => new TechnicalError(\"Failed to compress with deflate\", error),\n ),\n )\n .exhaustive();\n}\n","export { MessageValidationError } from \"@amqp-contract/core\";\n\n/**\n * Captured `Error.captureStackTrace` shim — only present on Node.js.\n */\nfunction captureStack(target: object, ctor: Function): void {\n const ErrorConstructor = Error as unknown as {\n captureStackTrace?: (target: object, constructor: Function) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(target, ctor);\n }\n}\n\n/**\n * Returned from `TypedAmqpClient.call()` when the configured `timeoutMs` elapses\n * before the RPC server publishes a reply with the matching `correlationId`.\n *\n * The pending call is removed from the in-memory correlation map; if a reply\n * arrives after the timeout it is dropped (and a debug log is emitted by the\n * client if a logger is configured).\n */\nexport class RpcTimeoutError extends Error {\n constructor(\n public readonly rpcName: string,\n public readonly timeoutMs: number,\n ) {\n super(`RPC call to \"${rpcName}\" timed out after ${timeoutMs}ms with no reply received`);\n this.name = \"RpcTimeoutError\";\n captureStack(this, this.constructor);\n }\n}\n\n/**\n * Returned from any in-flight RPC call when the client is closed before the\n * reply is received. The correlation map is cleared on close and every pending\n * caller's promise resolves with `err(RpcCancelledError)`.\n */\nexport class RpcCancelledError extends Error {\n constructor(public readonly rpcName: string) {\n super(`RPC call to \"${rpcName}\" was cancelled because the client was closed`);\n this.name = \"RpcCancelledError\";\n captureStack(this, this.constructor);\n }\n}\n","import {\n extractQueue,\n type CompressionAlgorithm,\n type ContractDefinition,\n type InferPublisherNames,\n type InferRpcNames,\n} from \"@amqp-contract/contract\";\nimport {\n AmqpClient,\n PublishOptions as AmqpClientPublishOptions,\n type Logger,\n MessagingSemanticConventions,\n TechnicalError,\n type TelemetryProvider,\n defaultTelemetryProvider,\n endSpanError,\n endSpanSuccess,\n recordLateRpcReply,\n recordPublishMetric,\n startPublishSpan,\n} from \"@amqp-contract/core\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { AmqpConnectionManagerOptions, ConnectionUrl } from \"amqp-connection-manager\";\nimport { err, errAsync, ok, okAsync, Result, ResultAsync } from \"neverthrow\";\nimport { randomUUID } from \"node:crypto\";\nimport { compressBuffer } from \"./compression.js\";\nimport { MessageValidationError, RpcCancelledError, RpcTimeoutError } from \"./errors.js\";\nimport type {\n ClientInferPublisherInput,\n ClientInferRpcRequestInput,\n ClientInferRpcResponseOutput,\n} from \"./types.js\";\n\n/**\n * The RabbitMQ direct-reply-to pseudo-queue. Publishing with `replyTo` set to\n * this value tells the server to deliver the response back to the consumer\n * subscribed on this queue on the same channel — no real queue is created and\n * no setup is required beyond consuming from it once with `noAck: true`.\n *\n * @see https://www.rabbitmq.com/docs/direct-reply-to\n */\nconst DIRECT_REPLY_TO = \"amq.rabbitmq.reply-to\";\n\n/**\n * In-flight RPC call tracked by `TypedAmqpClient`. The reply consumer\n * looks up entries by `correlationId` when responses arrive.\n */\ntype PendingCall = {\n rpcName: string;\n responseSchema: StandardSchemaV1;\n resolve: (\n result: Result<\n unknown,\n TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError\n >,\n ) => void;\n timer: ReturnType<typeof setTimeout>;\n};\n\n/**\n * Publish options that extend amqp-client's PublishOptions with optional compression support.\n */\nexport type PublishOptions = AmqpClientPublishOptions & {\n /**\n * Optional compression algorithm to use for the message payload.\n * When specified, the message will be compressed using the chosen algorithm\n * and the contentEncoding header will be set automatically.\n */\n compression?: CompressionAlgorithm | undefined;\n};\n\n/**\n * Options for creating a client\n */\nexport type CreateClientOptions<TContract extends ContractDefinition> = {\n contract: TContract;\n urls: ConnectionUrl[];\n connectionOptions?: AmqpConnectionManagerOptions | undefined;\n logger?: Logger | undefined;\n /**\n * Optional telemetry provider for tracing and metrics.\n * If not provided, uses the default provider which attempts to load OpenTelemetry.\n * OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed.\n */\n telemetry?: TelemetryProvider | undefined;\n /**\n * Default publish options that will be applied to all publish operations.\n * These can be overridden by options passed to the publish method.\n * By default, persistent is set to true for message durability.\n */\n defaultPublishOptions?: PublishOptions | undefined;\n /**\n * Maximum time in ms to wait for the AMQP connection to become ready before\n * `create()` resolves to an `err(TechnicalError)`. Defaults to 30s\n * (the {@link AmqpClient}'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to\n * disable the timeout and let amqp-connection-manager retry indefinitely.\n */\n connectTimeoutMs?: number | null | undefined;\n};\n\n/**\n * Per-call options for `client.call()`.\n */\nexport type CallOptions = {\n /**\n * Maximum time in ms to wait for an RPC reply. If exceeded, the call resolves\n * to `err(RpcTimeoutError)` and the in-memory correlation entry is cleared.\n * A late reply arriving after the timeout is silently dropped.\n *\n * Required: RPC without a timeout is a footgun.\n */\n timeoutMs: number;\n\n /**\n * Optional AMQP message properties to merge into the request. `replyTo` and\n * `correlationId` are managed by the client and cannot be overridden.\n */\n publishOptions?: Omit<AmqpClientPublishOptions, \"replyTo\" | \"correlationId\">;\n};\n\n/**\n * Type-safe AMQP client for publishing messages\n */\nexport class TypedAmqpClient<TContract extends ContractDefinition> {\n /**\n * In-flight RPC calls keyed by `correlationId`. Cleared when a reply is\n * received, when the call times out, or when the client is closed.\n */\n private readonly pendingCalls = new Map<string, PendingCall>();\n\n /**\n * Consumer tag of the reply consumer subscribed on `amq.rabbitmq.reply-to`.\n * Set when the contract has at least one entry in `rpcs`; undefined otherwise.\n */\n private replyConsumerTag?: string;\n\n private constructor(\n private readonly contract: TContract,\n private readonly amqpClient: AmqpClient,\n private readonly defaultPublishOptions: PublishOptions,\n private readonly logger?: Logger,\n private readonly telemetry: TelemetryProvider = defaultTelemetryProvider,\n ) {}\n\n /**\n * Create a type-safe AMQP client from a contract.\n *\n * Connection management (including automatic reconnection) is handled internally\n * by amqp-connection-manager via the {@link AmqpClient}. The client establishes\n * infrastructure asynchronously in the background once the connection is ready.\n *\n * Connections are automatically shared across clients with the same URLs and\n * connection options, following RabbitMQ best practices.\n */\n static create<TContract extends ContractDefinition>({\n contract,\n urls,\n connectionOptions,\n defaultPublishOptions,\n logger,\n telemetry,\n connectTimeoutMs,\n }: CreateClientOptions<TContract>): ResultAsync<TypedAmqpClient<TContract>, TechnicalError> {\n const client = new TypedAmqpClient(\n contract,\n new AmqpClient(contract, { urls, connectionOptions, connectTimeoutMs }),\n { persistent: true, ...defaultPublishOptions },\n logger,\n telemetry ?? defaultTelemetryProvider,\n );\n\n const setup = client\n .waitForConnectionReady()\n .andThen(() => client.setupReplyConsumerIfNeeded());\n\n return new ResultAsync<TypedAmqpClient<TContract>, TechnicalError>(\n (async () => {\n const setupResult = await setup;\n if (setupResult.isOk()) {\n return ok(client);\n }\n const closeResult = await client.close();\n if (closeResult.isErr()) {\n logger?.warn(\"Failed to close client after connection failure\", {\n error: closeResult.error,\n });\n }\n return err(setupResult.error);\n })(),\n );\n }\n\n /**\n * If the contract has any RPC entry, subscribe to `amq.rabbitmq.reply-to`\n * once. Replies for every in-flight call arrive on this single consumer and\n * are demultiplexed by `correlationId`.\n */\n private setupReplyConsumerIfNeeded(): ResultAsync<void, TechnicalError> {\n const rpcs = this.contract.rpcs ?? {};\n if (Object.keys(rpcs).length === 0) {\n return okAsync(undefined);\n }\n\n return this.amqpClient\n .consume(DIRECT_REPLY_TO, (msg) => this.handleRpcReply(msg), { noAck: true })\n .andTee((tag) => {\n this.replyConsumerTag = tag;\n })\n .map(() => undefined);\n }\n\n /**\n * Demultiplex an RPC reply by `correlationId`, validate the body against the\n * call's response schema, and resolve the awaiting caller. Replies with no\n * matching pending call (the call already timed out, was cancelled, or the\n * correlationId is unknown) are logged at warn — a non-zero rate of these\n * usually indicates a tuning problem (handler latency exceeds caller\n * timeout). The `messaging.rpc.late_reply` counter lets dashboards alert on\n * sustained drift without parsing logs.\n */\n private handleRpcReply(msg: Parameters<Parameters<AmqpClient[\"consume\"]>[1]>[0]): void {\n if (!msg) return;\n const correlationId = msg.properties.correlationId;\n if (typeof correlationId !== \"string\") {\n this.logger?.warn(\"Received RPC reply without correlationId; dropping\", {\n deliveryTag: msg.fields.deliveryTag,\n });\n recordLateRpcReply(this.telemetry, \"missing-correlation-id\");\n return;\n }\n const pending = this.pendingCalls.get(correlationId);\n if (!pending) {\n this.logger?.warn(\n \"Received RPC reply for unknown correlationId (caller already timed out or cancelled)\",\n { correlationId },\n );\n recordLateRpcReply(this.telemetry, \"unknown-correlation-id\");\n return;\n }\n this.pendingCalls.delete(correlationId);\n clearTimeout(pending.timer);\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(msg.content.toString());\n } catch (error: unknown) {\n pending.resolve(\n err(new TechnicalError(`Failed to parse RPC reply JSON for \"${pending.rpcName}\"`, error)),\n );\n return;\n }\n\n // Wrap the validate call itself — a Standard Schema implementation may\n // throw synchronously, and the throw would otherwise escape the consume\n // callback and could crash the reply consumer.\n let rawValidation: ReturnType<StandardSchemaV1[\"~standard\"][\"validate\"]>;\n try {\n rawValidation = pending.responseSchema[\"~standard\"].validate(parsed);\n } catch (error: unknown) {\n pending.resolve(\n err(new TechnicalError(`RPC reply validation threw for \"${pending.rpcName}\"`, error)),\n );\n return;\n }\n const validationPromise =\n rawValidation instanceof Promise ? rawValidation : Promise.resolve(rawValidation);\n\n validationPromise.then(\n (validation) => {\n if (validation.issues) {\n pending.resolve(err(new MessageValidationError(pending.rpcName, validation.issues)));\n return;\n }\n pending.resolve(ok(validation.value));\n },\n (error: unknown) => {\n pending.resolve(\n err(new TechnicalError(`RPC reply validation threw for \"${pending.rpcName}\"`, error)),\n );\n },\n );\n }\n\n /**\n * Publish a message using a defined publisher.\n *\n * @param publisherName - The name of the publisher to use\n * @param message - The message to publish\n * @param options - Optional publish options including compression, headers, priority, etc.\n *\n * @remarks\n * If `options.compression` is specified, the message will be compressed before publishing\n * and the `contentEncoding` property will be set automatically. Any `contentEncoding`\n * value already in options will be overwritten by the compression algorithm.\n */\n publish<TName extends InferPublisherNames<TContract>>(\n publisherName: TName,\n message: ClientInferPublisherInput<TContract, TName>,\n options?: PublishOptions,\n ): ResultAsync<void, TechnicalError | MessageValidationError> {\n const startTime = Date.now();\n // Non-null assertions safe: TypeScript guarantees these exist for valid TName\n const publisher = this.contract.publishers![publisherName as string]!;\n const { exchange, routingKey } = publisher;\n\n // Start telemetry span\n const span = startPublishSpan(this.telemetry, exchange.name, routingKey, {\n [MessagingSemanticConventions.AMQP_PUBLISHER_NAME]: String(publisherName),\n });\n\n const validateMessage = (): ResultAsync<unknown, TechnicalError | MessageValidationError> => {\n const validationResult = publisher.message.payload[\"~standard\"].validate(message);\n const promise =\n validationResult instanceof Promise ? validationResult : Promise.resolve(validationResult);\n return ResultAsync.fromPromise(\n promise,\n (error): TechnicalError | MessageValidationError =>\n new TechnicalError(\"Validation failed\", error),\n ).andThen((validation) => {\n if (validation.issues) {\n return err<unknown, TechnicalError | MessageValidationError>(\n new MessageValidationError(String(publisherName), validation.issues),\n );\n }\n return ok<unknown, TechnicalError | MessageValidationError>(validation.value);\n });\n };\n\n const publishMessage = (validatedMessage: unknown): ResultAsync<void, TechnicalError> => {\n // Merge default options with provided options\n const mergedOptions = { ...this.defaultPublishOptions, ...options };\n\n // Extract compression from merged options and create publish options without it\n const { compression, ...restOptions } = mergedOptions;\n const publishOptions: AmqpClientPublishOptions = { ...restOptions };\n\n // Prepare payload and options based on compression configuration\n const preparePayload = (): ResultAsync<Buffer | unknown, TechnicalError> => {\n if (compression) {\n // Compress the message payload\n const messageBuffer = Buffer.from(JSON.stringify(validatedMessage));\n publishOptions.contentEncoding = compression;\n return compressBuffer(messageBuffer, compression);\n }\n\n // No compression: use the channel's built-in JSON serialization\n return okAsync(validatedMessage);\n };\n\n return preparePayload().andThen((payload) =>\n this.amqpClient\n .publish(publisher.exchange.name, publisher.routingKey ?? \"\", payload, publishOptions)\n .andThen((published) => {\n if (!published) {\n return err<void, TechnicalError>(\n new TechnicalError(\n `Failed to publish message for publisher \"${String(publisherName)}\": Channel rejected the message (buffer full or other channel issue)`,\n ),\n );\n }\n\n this.logger?.info(\"Message published successfully\", {\n publisherName: String(publisherName),\n exchange: publisher.exchange.name,\n routingKey: publisher.routingKey,\n compressed: !!compression,\n });\n\n return ok<void, TechnicalError>(undefined);\n }),\n );\n };\n\n return validateMessage()\n .andThen((validatedMessage) => publishMessage(validatedMessage))\n .andTee(() => {\n const durationMs = Date.now() - startTime;\n endSpanSuccess(span);\n recordPublishMetric(this.telemetry, exchange.name, routingKey, true, durationMs);\n })\n .orTee((error) => {\n const durationMs = Date.now() - startTime;\n endSpanError(span, error);\n recordPublishMetric(this.telemetry, exchange.name, routingKey, false, durationMs);\n });\n }\n\n /**\n * Invoke an RPC defined via `defineRpc` and await the typed response.\n *\n * The request payload is validated against the RPC's request schema, then\n * published to the AMQP default exchange with the server's queue name as\n * routing key, `replyTo` set to `amq.rabbitmq.reply-to`, and a fresh UUID\n * `correlationId`. The returned ResultAsync resolves once a matching reply\n * arrives and validates against the response schema, or once `timeoutMs`\n * elapses (whichever comes first).\n *\n * @example\n * ```typescript\n * const result = await client.call('calculate', { a: 1, b: 2 }, { timeoutMs: 5_000 });\n * if (result.isOk()) console.log(result.value.sum); // 3\n * ```\n */\n call<TName extends InferRpcNames<TContract>>(\n rpcName: TName,\n request: ClientInferRpcRequestInput<TContract, TName>,\n options: CallOptions,\n ): ResultAsync<\n ClientInferRpcResponseOutput<TContract, TName>,\n TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError\n > {\n type ResponseType = ClientInferRpcResponseOutput<TContract, TName>;\n type CallError = TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError;\n type CallResult = Result<ResponseType, CallError>;\n\n // setTimeout truncates fractional ms and clamps anything outside the\n // 32-bit signed integer range (~24.8 days) to 1ms, so reject those up\n // front as user errors rather than producing surprising behavior.\n const TIMEOUT_MAX_MS = 2_147_483_647;\n if (\n typeof options.timeoutMs !== \"number\" ||\n !Number.isFinite(options.timeoutMs) ||\n options.timeoutMs <= 0 ||\n options.timeoutMs > TIMEOUT_MAX_MS\n ) {\n return errAsync<ResponseType, CallError>(\n new TechnicalError(\n `Invalid timeoutMs for RPC call to \"${String(rpcName)}\": expected a finite positive number ≤ ${TIMEOUT_MAX_MS}, got ${String(options.timeoutMs)}`,\n ),\n );\n }\n\n const startTime = Date.now();\n // Non-null assertion safe: TName is constrained to RPC names in the contract.\n const rpc = this.contract.rpcs![rpcName as string]!;\n const requestSchema = rpc.request.payload;\n const responseSchema = rpc.response.payload;\n const queueName = extractQueue(rpc.queue).name;\n\n // RPC publishes to the default exchange with the queue name as routing key.\n const span = startPublishSpan(this.telemetry, \"\", queueName, {\n [MessagingSemanticConventions.AMQP_PUBLISHER_NAME]: String(rpcName),\n });\n\n const correlationId = randomUUID();\n\n // Set up the reply future + pending entry up front so a reply that arrives\n // racing the publish round-trip can find a slot. Cleanup on preflight\n // failure happens in the `.orElse` below.\n let resolveCall!: (result: CallResult) => void;\n const callPromise = new Promise<CallResult>((res) => {\n resolveCall = res;\n });\n const callResultAsync = new ResultAsync<ResponseType, CallError>(callPromise);\n\n const timer = setTimeout(() => {\n if (!this.pendingCalls.has(correlationId)) return;\n this.pendingCalls.delete(correlationId);\n resolveCall(err(new RpcTimeoutError(String(rpcName), options.timeoutMs)));\n }, options.timeoutMs);\n\n this.pendingCalls.set(correlationId, {\n rpcName: String(rpcName),\n responseSchema,\n resolve: resolveCall as PendingCall[\"resolve\"],\n timer,\n });\n\n const validateRequest = (): ResultAsync<unknown, TechnicalError | MessageValidationError> => {\n // Wrap the validate call — a Standard Schema implementation may throw\n // synchronously, and that throw would otherwise escape the chain and\n // leave the pending-call entry/timer dangling until timeout.\n let rawValidation: ReturnType<StandardSchemaV1[\"~standard\"][\"validate\"]>;\n try {\n rawValidation = requestSchema[\"~standard\"].validate(request);\n } catch (error: unknown) {\n return errAsync<unknown, TechnicalError | MessageValidationError>(\n new TechnicalError(\"RPC request validation threw\", error),\n );\n }\n const validationPromise =\n rawValidation instanceof Promise ? rawValidation : Promise.resolve(rawValidation);\n return ResultAsync.fromPromise(\n validationPromise,\n (error): TechnicalError | MessageValidationError =>\n new TechnicalError(\"RPC request validation threw\", error),\n ).andThen((validation) =>\n validation.issues\n ? err<unknown, TechnicalError | MessageValidationError>(\n new MessageValidationError(String(rpcName), validation.issues),\n )\n : ok<unknown, TechnicalError | MessageValidationError>(validation.value),\n );\n };\n\n const publishRequest = (validatedRequest: unknown): ResultAsync<void, TechnicalError> => {\n // Merge `defaultPublishOptions` (persistent, priority, headers, …) with\n // the per-call options, then layer the RPC-managed fields on top so they\n // cannot be overridden. `compression` is intentionally dropped: RPC v1\n // does not implement reply-side decompression, so request-side\n // compression would break the round-trip.\n const { compression: _ignoredCompression, ...defaultsWithoutCompression } =\n this.defaultPublishOptions;\n const publishOptions: AmqpClientPublishOptions = {\n ...defaultsWithoutCompression,\n ...options.publishOptions,\n replyTo: DIRECT_REPLY_TO,\n correlationId,\n contentType: \"application/json\",\n };\n return this.amqpClient\n .publish(\"\", queueName, validatedRequest, publishOptions)\n .andThen((published) =>\n published\n ? ok<void, TechnicalError>(undefined)\n : err<void, TechnicalError>(\n new TechnicalError(\n `Failed to publish RPC request for \"${String(rpcName)}\": channel buffer full`,\n ),\n ),\n );\n };\n\n return validateRequest()\n .andThen((validated) => publishRequest(validated))\n .andThen(() => callResultAsync)\n .orElse((error: CallError) => {\n // If preflight failed (validate or publish), the pending entry still\n // exists and the timer is alive. Clean both up so the call doesn't\n // leak. Timer-fired errors and reply-resolved errors have already\n // cleaned the entry, so the .has() check guards against double cleanup.\n if (this.pendingCalls.has(correlationId)) {\n clearTimeout(timer);\n this.pendingCalls.delete(correlationId);\n }\n return errAsync<ResponseType, CallError>(error);\n })\n .andTee(() => {\n const durationMs = Date.now() - startTime;\n endSpanSuccess(span);\n recordPublishMetric(this.telemetry, \"\", queueName, true, durationMs);\n })\n .orTee((error) => {\n const durationMs = Date.now() - startTime;\n endSpanError(span, error);\n recordPublishMetric(this.telemetry, \"\", queueName, false, durationMs);\n });\n }\n\n /**\n * Close the channel and connection. Cancels the reply consumer (if any) and\n * rejects every in-flight RPC call with `RpcCancelledError`.\n */\n close(): ResultAsync<void, TechnicalError> {\n // Reject pending calls first — once close() runs, no reply will arrive.\n for (const [, pending] of this.pendingCalls) {\n clearTimeout(pending.timer);\n pending.resolve(err(new RpcCancelledError(pending.rpcName)));\n }\n this.pendingCalls.clear();\n\n const cancelReply: ResultAsync<void, TechnicalError> = this.replyConsumerTag\n ? this.amqpClient.cancel(this.replyConsumerTag).orElse((error) => {\n this.logger?.warn(\"Failed to cancel RPC reply consumer during close\", { error });\n return ok<void, TechnicalError>(undefined);\n })\n : okAsync<void, TechnicalError>(undefined);\n\n return cancelReply.andThen(() => this.amqpClient.close());\n }\n\n private waitForConnectionReady(): ResultAsync<void, TechnicalError> {\n return this.amqpClient.waitForConnect();\n }\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,YAAY,UAAU,KAAK;AACjC,MAAM,eAAe,UAAU,QAAQ;;;;;;;;;;AAWvC,SAAgB,eACd,QACA,WACqC;AACrC,QAAO,MAAM,UAAU,CACpB,KAAK,cACJ,YAAY,YACV,UAAU,OAAO,GAChB,UAAU,IAAI,eAAe,gCAAgC,MAAM,CACrE,CACF,CACA,KAAK,iBACJ,YAAY,YACV,aAAa,OAAO,GACnB,UAAU,IAAI,eAAe,mCAAmC,MAAM,CACxE,CACF,CACA,YAAY;;;;;;;AC/BjB,SAAS,aAAa,QAAgB,MAAsB;CAC1D,MAAM,mBAAmB;AAGzB,KAAI,OAAO,iBAAiB,sBAAsB,WAChD,kBAAiB,kBAAkB,QAAQ,KAAK;;;;;;;;;;AAYpD,IAAa,kBAAb,cAAqC,MAAM;CACzC,YACE,SACA,WACA;AACA,QAAM,gBAAgB,QAAQ,oBAAoB,UAAU,2BAA2B;AAHvE,OAAA,UAAA;AACA,OAAA,YAAA;AAGhB,OAAK,OAAO;AACZ,eAAa,MAAM,KAAK,YAAY;;;;;;;;AASxC,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiC;AAC3C,QAAM,gBAAgB,QAAQ,+CAA+C;AADnD,OAAA,UAAA;AAE1B,OAAK,OAAO;AACZ,eAAa,MAAM,KAAK,YAAY;;;;;;;;;;;;;ACDxC,MAAM,kBAAkB;;;;A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AAI,kBAAkB,QAAQ,QAAQ,CAAC,CAAC;;AAE9D,OAAK,aAAa,OAAO;AASzB,UAPuD,KAAK,mBACxD,KAAK,WAAW,OAAO,KAAK,iBAAiB,CAAC,QAAQ,UAAU;AAC9D,QAAK,QAAQ,KAAK,oDAAoD,EAAE,OAAO,CAAC;AAChF,UAAO,GAAyB,KAAA,EAAU;IAC1C,GACF,QAA8B,KAAA,EAAU,EAEzB,cAAc,KAAK,WAAW,OAAO,CAAC;;CAG3D,yBAAoE;AAClE,SAAO,KAAK,WAAW,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/compression.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["import type { CompressionAlgorithm } from \"@amqp-contract/contract\";\nimport { TechnicalError } from \"@amqp-contract/core\";\nimport { ResultAsync } from \"neverthrow\";\nimport { deflate, gzip } from \"node:zlib\";\nimport { promisify } from \"node:util\";\nimport { match } from \"ts-pattern\";\n\nconst gzipAsync = promisify(gzip);\nconst deflateAsync = promisify(deflate);\n\n/**\n * Compress a buffer using the specified compression algorithm.\n *\n * @param buffer - The buffer to compress\n * @param algorithm - The compression algorithm to use\n * @returns A ResultAsync resolving to the compressed buffer or a TechnicalError\n *\n * @internal\n */\nexport function compressBuffer(\n buffer: Buffer,\n algorithm: CompressionAlgorithm,\n): ResultAsync<Buffer, TechnicalError> {\n return match(algorithm)\n .with(\"gzip\", () =>\n ResultAsync.fromPromise(\n gzipAsync(buffer),\n (error) => new TechnicalError(\"Failed to compress with gzip\", error),\n ),\n )\n .with(\"deflate\", () =>\n ResultAsync.fromPromise(\n deflateAsync(buffer),\n (error) => new TechnicalError(\"Failed to compress with deflate\", error),\n ),\n )\n .exhaustive();\n}\n","export { MessageValidationError } from \"@amqp-contract/core\";\n\n/**\n * Captured `Error.captureStackTrace` shim — only present on Node.js.\n */\nfunction captureStack(target: object, ctor: Function): void {\n const ErrorConstructor = Error as unknown as {\n captureStackTrace?: (target: object, constructor: Function) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(target, ctor);\n }\n}\n\n/**\n * Returned from `TypedAmqpClient.call()` when the configured `timeoutMs` elapses\n * before the RPC server publishes a reply with the matching `correlationId`.\n *\n * The pending call is removed from the in-memory correlation map; if a reply\n * arrives after the timeout it is dropped (and a debug log is emitted by the\n * client if a logger is configured).\n */\nexport class RpcTimeoutError extends Error {\n constructor(\n public readonly rpcName: string,\n public readonly timeoutMs: number,\n ) {\n super(`RPC call to \"${rpcName}\" timed out after ${timeoutMs}ms with no reply received`);\n this.name = \"RpcTimeoutError\";\n captureStack(this, this.constructor);\n }\n}\n\n/**\n * Returned from any in-flight RPC call when the client is closed before the\n * reply is received. The correlation map is cleared on close and every pending\n * caller's promise resolves with `err(RpcCancelledError)`.\n */\nexport class RpcCancelledError extends Error {\n constructor(public readonly rpcName: string) {\n super(`RPC call to \"${rpcName}\" was cancelled because the client was closed`);\n this.name = \"RpcCancelledError\";\n captureStack(this, this.constructor);\n }\n}\n","import {\n extractQueue,\n type CompressionAlgorithm,\n type ContractDefinition,\n type InferPublisherNames,\n type InferRpcNames,\n} from \"@amqp-contract/contract\";\nimport {\n AmqpClient,\n PublishOptions as AmqpClientPublishOptions,\n type Logger,\n MessagingSemanticConventions,\n TechnicalError,\n type TelemetryProvider,\n defaultTelemetryProvider,\n endSpanError,\n endSpanSuccess,\n recordLateRpcReply,\n recordPublishMetric,\n safeJsonParse,\n startPublishSpan,\n} from \"@amqp-contract/core\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { AmqpConnectionManagerOptions, ConnectionUrl } from \"amqp-connection-manager\";\nimport { err, errAsync, ok, okAsync, Result, ResultAsync } from \"neverthrow\";\nimport { randomUUID } from \"node:crypto\";\nimport { compressBuffer } from \"./compression.js\";\nimport { MessageValidationError, RpcCancelledError, RpcTimeoutError } from \"./errors.js\";\nimport type {\n ClientInferPublisherInput,\n ClientInferRpcRequestInput,\n ClientInferRpcResponseOutput,\n} from \"./types.js\";\n\n/**\n * The RabbitMQ direct-reply-to pseudo-queue. Publishing with `replyTo` set to\n * this value tells the server to deliver the response back to the consumer\n * subscribed on this queue on the same channel — no real queue is created and\n * no setup is required beyond consuming from it once with `noAck: true`.\n *\n * @see https://www.rabbitmq.com/docs/direct-reply-to\n */\nconst DIRECT_REPLY_TO = \"amq.rabbitmq.reply-to\";\n\n/**\n * In-flight RPC call tracked by `TypedAmqpClient`. The reply consumer\n * looks up entries by `correlationId` when responses arrive.\n */\ntype PendingCall = {\n rpcName: string;\n responseSchema: StandardSchemaV1;\n resolve: (\n result: Result<\n unknown,\n TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError\n >,\n ) => void;\n timer: ReturnType<typeof setTimeout>;\n};\n\n/**\n * Publish options that extend amqp-client's PublishOptions with optional compression support.\n */\nexport type PublishOptions = AmqpClientPublishOptions & {\n /**\n * Optional compression algorithm to use for the message payload.\n * When specified, the message will be compressed using the chosen algorithm\n * and the contentEncoding header will be set automatically.\n */\n compression?: CompressionAlgorithm | undefined;\n};\n\n/**\n * Options for creating a client\n */\nexport type CreateClientOptions<TContract extends ContractDefinition> = {\n contract: TContract;\n urls: ConnectionUrl[];\n connectionOptions?: AmqpConnectionManagerOptions | undefined;\n logger?: Logger | undefined;\n /**\n * Optional telemetry provider for tracing and metrics.\n * If not provided, uses the default provider which attempts to load OpenTelemetry.\n * OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed.\n */\n telemetry?: TelemetryProvider | undefined;\n /**\n * Default publish options that will be applied to all publish operations.\n * These can be overridden by options passed to the publish method.\n * By default, persistent is set to true for message durability.\n */\n defaultPublishOptions?: PublishOptions | undefined;\n /**\n * Maximum time in ms to wait for the AMQP connection to become ready before\n * `create()` resolves to an `err(TechnicalError)`. Defaults to 30s\n * (the {@link AmqpClient}'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to\n * disable the timeout and let amqp-connection-manager retry indefinitely.\n */\n connectTimeoutMs?: number | null | undefined;\n};\n\n/**\n * Per-call options for `client.call()`.\n */\nexport type CallOptions = {\n /**\n * Maximum time in ms to wait for an RPC reply. If exceeded, the call resolves\n * to `err(RpcTimeoutError)` and the in-memory correlation entry is cleared.\n * A late reply arriving after the timeout is silently dropped.\n *\n * Required: RPC without a timeout is a footgun.\n */\n timeoutMs: number;\n\n /**\n * Optional AMQP message properties to merge into the request. `replyTo` and\n * `correlationId` are managed by the client and cannot be overridden.\n */\n publishOptions?: Omit<AmqpClientPublishOptions, \"replyTo\" | \"correlationId\">;\n};\n\n/**\n * Type-safe AMQP client for publishing messages\n */\nexport class TypedAmqpClient<TContract extends ContractDefinition> {\n /**\n * In-flight RPC calls keyed by `correlationId`. Cleared when a reply is\n * received, when the call times out, or when the client is closed.\n */\n private readonly pendingCalls = new Map<string, PendingCall>();\n\n /**\n * Consumer tag of the reply consumer subscribed on `amq.rabbitmq.reply-to`.\n * Set when the contract has at least one entry in `rpcs`; undefined otherwise.\n */\n private replyConsumerTag?: string;\n\n private constructor(\n private readonly contract: TContract,\n private readonly amqpClient: AmqpClient,\n private readonly defaultPublishOptions: PublishOptions,\n private readonly logger?: Logger,\n private readonly telemetry: TelemetryProvider = defaultTelemetryProvider,\n ) {}\n\n /**\n * Create a type-safe AMQP client from a contract.\n *\n * Connection management (including automatic reconnection) is handled internally\n * by amqp-connection-manager via the {@link AmqpClient}. The client establishes\n * infrastructure asynchronously in the background once the connection is ready.\n *\n * Connections are automatically shared across clients with the same URLs and\n * connection options, following RabbitMQ best practices.\n */\n static create<TContract extends ContractDefinition>({\n contract,\n urls,\n connectionOptions,\n defaultPublishOptions,\n logger,\n telemetry,\n connectTimeoutMs,\n }: CreateClientOptions<TContract>): ResultAsync<TypedAmqpClient<TContract>, TechnicalError> {\n const client = new TypedAmqpClient(\n contract,\n new AmqpClient(contract, { urls, connectionOptions, connectTimeoutMs }),\n { persistent: true, ...defaultPublishOptions },\n logger,\n telemetry ?? defaultTelemetryProvider,\n );\n\n const setup = client\n .waitForConnectionReady()\n .andThen(() => client.setupReplyConsumerIfNeeded());\n\n return new ResultAsync<TypedAmqpClient<TContract>, TechnicalError>(\n (async () => {\n const setupResult = await setup;\n if (setupResult.isOk()) {\n return ok(client);\n }\n const closeResult = await client.close();\n if (closeResult.isErr()) {\n logger?.warn(\"Failed to close client after connection failure\", {\n error: closeResult.error,\n });\n }\n return err(setupResult.error);\n })(),\n );\n }\n\n /**\n * If the contract has any RPC entry, subscribe to `amq.rabbitmq.reply-to`\n * once. Replies for every in-flight call arrive on this single consumer and\n * are demultiplexed by `correlationId`.\n */\n private setupReplyConsumerIfNeeded(): ResultAsync<void, TechnicalError> {\n const rpcs = this.contract.rpcs ?? {};\n if (Object.keys(rpcs).length === 0) {\n return okAsync(undefined);\n }\n\n return this.amqpClient\n .consume(DIRECT_REPLY_TO, (msg) => this.handleRpcReply(msg), { noAck: true })\n .andTee((tag) => {\n this.replyConsumerTag = tag;\n })\n .map(() => undefined);\n }\n\n /**\n * Demultiplex an RPC reply by `correlationId`, validate the body against the\n * call's response schema, and resolve the awaiting caller. Replies with no\n * matching pending call (the call already timed out, was cancelled, or the\n * correlationId is unknown) are logged at warn — a non-zero rate of these\n * usually indicates a tuning problem (handler latency exceeds caller\n * timeout). The `messaging.rpc.late_reply` counter lets dashboards alert on\n * sustained drift without parsing logs.\n */\n private handleRpcReply(msg: Parameters<Parameters<AmqpClient[\"consume\"]>[1]>[0]): void {\n if (!msg) return;\n const correlationId = msg.properties.correlationId;\n if (typeof correlationId !== \"string\") {\n this.logger?.warn(\"Received RPC reply without correlationId; dropping\", {\n deliveryTag: msg.fields.deliveryTag,\n });\n recordLateRpcReply(this.telemetry, \"missing-correlation-id\");\n return;\n }\n const pending = this.pendingCalls.get(correlationId);\n if (!pending) {\n this.logger?.warn(\n \"Received RPC reply for unknown correlationId (caller already timed out or cancelled)\",\n { correlationId },\n );\n recordLateRpcReply(this.telemetry, \"unknown-correlation-id\");\n return;\n }\n this.pendingCalls.delete(correlationId);\n clearTimeout(pending.timer);\n\n const parseResult = safeJsonParse(\n msg.content,\n (error) =>\n new TechnicalError(`Failed to parse RPC reply JSON for \"${pending.rpcName}\"`, error),\n );\n if (parseResult.isErr()) {\n pending.resolve(err(parseResult.error));\n return;\n }\n const parsed = parseResult.value;\n\n // Wrap the validate call itself — a Standard Schema implementation may\n // throw synchronously, and the throw would otherwise escape the consume\n // callback and could crash the reply consumer.\n let rawValidation: ReturnType<StandardSchemaV1[\"~standard\"][\"validate\"]>;\n try {\n rawValidation = pending.responseSchema[\"~standard\"].validate(parsed);\n } catch (error: unknown) {\n pending.resolve(\n err(new TechnicalError(`RPC reply validation threw for \"${pending.rpcName}\"`, error)),\n );\n return;\n }\n const validationPromise =\n rawValidation instanceof Promise ? rawValidation : Promise.resolve(rawValidation);\n\n validationPromise.then(\n (validation) => {\n if (validation.issues) {\n pending.resolve(err(new MessageValidationError(pending.rpcName, validation.issues)));\n return;\n }\n pending.resolve(ok(validation.value));\n },\n (error: unknown) => {\n pending.resolve(\n err(new TechnicalError(`RPC reply validation threw for \"${pending.rpcName}\"`, error)),\n );\n },\n );\n }\n\n /**\n * Publish a message using a defined publisher.\n *\n * @param publisherName - The name of the publisher to use\n * @param message - The message to publish\n * @param options - Optional publish options including compression, headers, priority, etc.\n *\n * @remarks\n * If `options.compression` is specified, the message will be compressed before publishing\n * and the `contentEncoding` property will be set automatically. Any `contentEncoding`\n * value already in options will be overwritten by the compression algorithm.\n */\n publish<TName extends InferPublisherNames<TContract>>(\n publisherName: TName,\n message: ClientInferPublisherInput<TContract, TName>,\n options?: PublishOptions,\n ): ResultAsync<void, TechnicalError | MessageValidationError> {\n const startTime = Date.now();\n // Non-null assertions safe: TypeScript guarantees these exist for valid TName\n const publisher = this.contract.publishers![publisherName as string]!;\n const { exchange, routingKey } = publisher;\n\n // Start telemetry span\n const span = startPublishSpan(this.telemetry, exchange.name, routingKey, {\n [MessagingSemanticConventions.AMQP_PUBLISHER_NAME]: String(publisherName),\n });\n\n const validateMessage = (): ResultAsync<unknown, TechnicalError | MessageValidationError> => {\n const validationResult = publisher.message.payload[\"~standard\"].validate(message);\n const promise =\n validationResult instanceof Promise ? validationResult : Promise.resolve(validationResult);\n return ResultAsync.fromPromise(\n promise,\n (error): TechnicalError | MessageValidationError =>\n new TechnicalError(\"Validation failed\", error),\n ).andThen((validation) => {\n if (validation.issues) {\n return err<unknown, TechnicalError | MessageValidationError>(\n new MessageValidationError(String(publisherName), validation.issues),\n );\n }\n return ok<unknown, TechnicalError | MessageValidationError>(validation.value);\n });\n };\n\n const publishMessage = (validatedMessage: unknown): ResultAsync<void, TechnicalError> => {\n // Merge default options with provided options\n const mergedOptions = { ...this.defaultPublishOptions, ...options };\n\n // Extract compression from merged options and create publish options without it\n const { compression, ...restOptions } = mergedOptions;\n const publishOptions: AmqpClientPublishOptions = { ...restOptions };\n\n // Prepare payload and options based on compression configuration\n const preparePayload = (): ResultAsync<Buffer | unknown, TechnicalError> => {\n if (compression) {\n // Compress the message payload\n const messageBuffer = Buffer.from(JSON.stringify(validatedMessage));\n publishOptions.contentEncoding = compression;\n return compressBuffer(messageBuffer, compression);\n }\n\n // No compression: use the channel's built-in JSON serialization\n return okAsync(validatedMessage);\n };\n\n return preparePayload().andThen((payload) =>\n this.amqpClient\n .publish(publisher.exchange.name, publisher.routingKey ?? \"\", payload, publishOptions)\n .andThen((published) => {\n if (!published) {\n return err<void, TechnicalError>(\n new TechnicalError(\n `Failed to publish message for publisher \"${String(publisherName)}\": Channel rejected the message (buffer full or other channel issue)`,\n ),\n );\n }\n\n this.logger?.info(\"Message published successfully\", {\n publisherName: String(publisherName),\n exchange: publisher.exchange.name,\n routingKey: publisher.routingKey,\n compressed: !!compression,\n });\n\n return ok<void, TechnicalError>(undefined);\n }),\n );\n };\n\n return validateMessage()\n .andThen((validatedMessage) => publishMessage(validatedMessage))\n .andTee(() => {\n const durationMs = Date.now() - startTime;\n endSpanSuccess(span);\n recordPublishMetric(this.telemetry, exchange.name, routingKey, true, durationMs);\n })\n .orTee((error) => {\n const durationMs = Date.now() - startTime;\n endSpanError(span, error);\n recordPublishMetric(this.telemetry, exchange.name, routingKey, false, durationMs);\n });\n }\n\n /**\n * Invoke an RPC defined via `defineRpc` and await the typed response.\n *\n * The request payload is validated against the RPC's request schema, then\n * published to the AMQP default exchange with the server's queue name as\n * routing key, `replyTo` set to `amq.rabbitmq.reply-to`, and a fresh UUID\n * `correlationId`. The returned ResultAsync resolves once a matching reply\n * arrives and validates against the response schema, or once `timeoutMs`\n * elapses (whichever comes first).\n *\n * @example\n * ```typescript\n * const result = await client.call('calculate', { a: 1, b: 2 }, { timeoutMs: 5_000 });\n * if (result.isOk()) console.log(result.value.sum); // 3\n * ```\n */\n call<TName extends InferRpcNames<TContract>>(\n rpcName: TName,\n request: ClientInferRpcRequestInput<TContract, TName>,\n options: CallOptions,\n ): ResultAsync<\n ClientInferRpcResponseOutput<TContract, TName>,\n TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError\n > {\n type ResponseType = ClientInferRpcResponseOutput<TContract, TName>;\n type CallError = TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError;\n type CallResult = Result<ResponseType, CallError>;\n\n // setTimeout truncates fractional ms and clamps anything outside the\n // 32-bit signed integer range (~24.8 days) to 1ms, so reject those up\n // front as user errors rather than producing surprising behavior.\n const TIMEOUT_MAX_MS = 2_147_483_647;\n if (\n typeof options.timeoutMs !== \"number\" ||\n !Number.isFinite(options.timeoutMs) ||\n options.timeoutMs <= 0 ||\n options.timeoutMs > TIMEOUT_MAX_MS\n ) {\n return errAsync<ResponseType, CallError>(\n new TechnicalError(\n `Invalid timeoutMs for RPC call to \"${String(rpcName)}\": expected a finite positive number ≤ ${TIMEOUT_MAX_MS}, got ${String(options.timeoutMs)}`,\n ),\n );\n }\n\n const startTime = Date.now();\n // Non-null assertion safe: TName is constrained to RPC names in the contract.\n const rpc = this.contract.rpcs![rpcName as string]!;\n const requestSchema = rpc.request.payload;\n const responseSchema = rpc.response.payload;\n const queueName = extractQueue(rpc.queue).name;\n\n // RPC publishes to the default exchange with the queue name as routing key.\n const span = startPublishSpan(this.telemetry, \"\", queueName, {\n [MessagingSemanticConventions.AMQP_PUBLISHER_NAME]: String(rpcName),\n });\n\n const correlationId = randomUUID();\n\n // Set up the reply future + pending entry up front so a reply that arrives\n // racing the publish round-trip can find a slot. Cleanup on preflight\n // failure happens in the `.orElse` below.\n let resolveCall!: (result: CallResult) => void;\n const callPromise = new Promise<CallResult>((res) => {\n resolveCall = res;\n });\n const callResultAsync = new ResultAsync<ResponseType, CallError>(callPromise);\n\n const timer = setTimeout(() => {\n if (!this.pendingCalls.has(correlationId)) return;\n this.pendingCalls.delete(correlationId);\n resolveCall(err(new RpcTimeoutError(String(rpcName), options.timeoutMs)));\n }, options.timeoutMs);\n\n this.pendingCalls.set(correlationId, {\n rpcName: String(rpcName),\n responseSchema,\n resolve: resolveCall as PendingCall[\"resolve\"],\n timer,\n });\n\n const validateRequest = (): ResultAsync<unknown, TechnicalError | MessageValidationError> => {\n // Wrap the validate call — a Standard Schema implementation may throw\n // synchronously, and that throw would otherwise escape the chain and\n // leave the pending-call entry/timer dangling until timeout.\n let rawValidation: ReturnType<StandardSchemaV1[\"~standard\"][\"validate\"]>;\n try {\n rawValidation = requestSchema[\"~standard\"].validate(request);\n } catch (error: unknown) {\n return errAsync<unknown, TechnicalError | MessageValidationError>(\n new TechnicalError(\"RPC request validation threw\", error),\n );\n }\n const validationPromise =\n rawValidation instanceof Promise ? rawValidation : Promise.resolve(rawValidation);\n return ResultAsync.fromPromise(\n validationPromise,\n (error): TechnicalError | MessageValidationError =>\n new TechnicalError(\"RPC request validation threw\", error),\n ).andThen((validation) =>\n validation.issues\n ? err<unknown, TechnicalError | MessageValidationError>(\n new MessageValidationError(String(rpcName), validation.issues),\n )\n : ok<unknown, TechnicalError | MessageValidationError>(validation.value),\n );\n };\n\n const publishRequest = (validatedRequest: unknown): ResultAsync<void, TechnicalError> => {\n // Merge `defaultPublishOptions` (persistent, priority, headers, …) with\n // the per-call options, then layer the RPC-managed fields on top so they\n // cannot be overridden. `compression` is intentionally dropped: RPC v1\n // does not implement reply-side decompression, so request-side\n // compression would break the round-trip.\n const { compression: _ignoredCompression, ...defaultsWithoutCompression } =\n this.defaultPublishOptions;\n const publishOptions: AmqpClientPublishOptions = {\n ...defaultsWithoutCompression,\n ...options.publishOptions,\n replyTo: DIRECT_REPLY_TO,\n correlationId,\n contentType: \"application/json\",\n };\n return this.amqpClient\n .publish(\"\", queueName, validatedRequest, publishOptions)\n .andThen((published) =>\n published\n ? ok<void, TechnicalError>(undefined)\n : err<void, TechnicalError>(\n new TechnicalError(\n `Failed to publish RPC request for \"${String(rpcName)}\": channel buffer full`,\n ),\n ),\n );\n };\n\n return validateRequest()\n .andThen((validated) => publishRequest(validated))\n .andThen(() => callResultAsync)\n .orElse((error: CallError) => {\n // If preflight failed (validate or publish), the pending entry still\n // exists and the timer is alive. Clean both up so the call doesn't\n // leak. Timer-fired errors and reply-resolved errors have already\n // cleaned the entry, so the .has() check guards against double cleanup.\n if (this.pendingCalls.has(correlationId)) {\n clearTimeout(timer);\n this.pendingCalls.delete(correlationId);\n }\n return errAsync<ResponseType, CallError>(error);\n })\n .andTee(() => {\n const durationMs = Date.now() - startTime;\n endSpanSuccess(span);\n recordPublishMetric(this.telemetry, \"\", queueName, true, durationMs);\n })\n .orTee((error) => {\n const durationMs = Date.now() - startTime;\n endSpanError(span, error);\n recordPublishMetric(this.telemetry, \"\", queueName, false, durationMs);\n });\n }\n\n /**\n * Close the channel and connection. Cancels the reply consumer (if any) and\n * rejects every in-flight RPC call with `RpcCancelledError`.\n */\n close(): ResultAsync<void, TechnicalError> {\n // Reject pending calls first — once close() runs, no reply will arrive.\n for (const [, pending] of this.pendingCalls) {\n clearTimeout(pending.timer);\n pending.resolve(err(new RpcCancelledError(pending.rpcName)));\n }\n this.pendingCalls.clear();\n\n const cancelReply: ResultAsync<void, TechnicalError> = this.replyConsumerTag\n ? this.amqpClient.cancel(this.replyConsumerTag).orElse((error) => {\n this.logger?.warn(\"Failed to cancel RPC reply consumer during close\", { error });\n return ok<void, TechnicalError>(undefined);\n })\n : okAsync<void, TechnicalError>(undefined);\n\n return cancelReply.andThen(() => this.amqpClient.close());\n }\n\n private waitForConnectionReady(): ResultAsync<void, TechnicalError> {\n return this.amqpClient.waitForConnect();\n }\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,YAAY,UAAU,KAAK;AACjC,MAAM,eAAe,UAAU,QAAQ;;;;;;;;;;AAWvC,SAAgB,eACd,QACA,WACqC;AACrC,QAAO,MAAM,UAAU,CACpB,KAAK,cACJ,YAAY,YACV,UAAU,OAAO,GAChB,UAAU,IAAI,eAAe,gCAAgC,MAAM,CACrE,CACF,CACA,KAAK,iBACJ,YAAY,YACV,aAAa,OAAO,GACnB,UAAU,IAAI,eAAe,mCAAmC,MAAM,CACxE,CACF,CACA,YAAY;;;;;;;AC/BjB,SAAS,aAAa,QAAgB,MAAsB;CAC1D,MAAM,mBAAmB;AAGzB,KAAI,OAAO,iBAAiB,sBAAsB,WAChD,kBAAiB,kBAAkB,QAAQ,KAAK;;;;;;;;;;AAYpD,IAAa,kBAAb,cAAqC,MAAM;CACzC,YACE,SACA,WACA;AACA,QAAM,gBAAgB,QAAQ,oBAAoB,UAAU,2BAA2B;AAHvE,OAAA,UAAA;AACA,OAAA,YAAA;AAGhB,OAAK,OAAO;AACZ,eAAa,MAAM,KAAK,YAAY;;;;;;;;AASxC,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiC;AAC3C,QAAM,gBAAgB,QAAQ,+CAA+C;AADnD,OAAA,UAAA;AAE1B,OAAK,OAAO;AACZ,eAAa,MAAM,KAAK,YAAY;;;;;;;;;;;;;ACAxC,MAAM,kBAAkB;;;;AAkFxB,IAAa,kBAAb,MAAa,gBAAsD;;;;;CAKjE,+BAAgC,IAAI,KAA0B;;;;;CAM9D;CAEA,YACE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ASzB,UAPuD,KAAK,mBACxD,KAAK,WAAW,OAAO,KAAK,iBAAiB,CAAC,QAAQ,UAAU;AAC9D,QAAK,QAAQ,KAAK,oDAAoD,EAAE,OAAO,CAAC;AAChF,UAAO,GAAyB,KAAA,EAAU;IAC1C,GACF,QAA8B,KAAA,EAAU,EAEzB,cAAc,KAAK,WAAW,OAAO,CAAC;;CAG3D,yBAAoE;AAClE,SAAO,KAAK,WAAW,gBAAgB"}
|
package/docs/index.md
CHANGED
|
@@ -170,7 +170,7 @@ Error.prepareStackTrace
|
|
|
170
170
|
|
|
171
171
|
### RpcCancelledError
|
|
172
172
|
|
|
173
|
-
Defined in: [packages/client/src/errors.ts:39](https://github.com/btravers/amqp-contract/blob/
|
|
173
|
+
Defined in: [packages/client/src/errors.ts:39](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/errors.ts#L39)
|
|
174
174
|
|
|
175
175
|
Returned from any in-flight RPC call when the client is closed before the
|
|
176
176
|
reply is received. The correlation map is cleared on close and every pending
|
|
@@ -188,7 +188,7 @@ caller's promise resolves with `err(RpcCancelledError)`.
|
|
|
188
188
|
new RpcCancelledError(rpcName): RpcCancelledError;
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
Defined in: [packages/client/src/errors.ts:40](https://github.com/btravers/amqp-contract/blob/
|
|
191
|
+
Defined in: [packages/client/src/errors.ts:40](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/errors.ts#L40)
|
|
192
192
|
|
|
193
193
|
###### Parameters
|
|
194
194
|
|
|
@@ -213,7 +213,7 @@ Error.constructor
|
|
|
213
213
|
| <a id="cause-1"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
|
|
214
214
|
| <a id="message-1"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
215
215
|
| <a id="name-1"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
216
|
-
| <a id="rpcname"></a> `rpcName` | `readonly` | `string` | - | - | [packages/client/src/errors.ts:40](https://github.com/btravers/amqp-contract/blob/
|
|
216
|
+
| <a id="rpcname"></a> `rpcName` | `readonly` | `string` | - | - | [packages/client/src/errors.ts:40](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/errors.ts#L40) |
|
|
217
217
|
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
218
218
|
| <a id="stacktracelimit-1"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
219
219
|
|
|
@@ -321,7 +321,7 @@ Error.prepareStackTrace
|
|
|
321
321
|
|
|
322
322
|
### RpcTimeoutError
|
|
323
323
|
|
|
324
|
-
Defined in: [packages/client/src/errors.ts:23](https://github.com/btravers/amqp-contract/blob/
|
|
324
|
+
Defined in: [packages/client/src/errors.ts:23](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/errors.ts#L23)
|
|
325
325
|
|
|
326
326
|
Returned from `TypedAmqpClient.call()` when the configured `timeoutMs` elapses
|
|
327
327
|
before the RPC server publishes a reply with the matching `correlationId`.
|
|
@@ -342,7 +342,7 @@ client if a logger is configured).
|
|
|
342
342
|
new RpcTimeoutError(rpcName, timeoutMs): RpcTimeoutError;
|
|
343
343
|
```
|
|
344
344
|
|
|
345
|
-
Defined in: [packages/client/src/errors.ts:24](https://github.com/btravers/amqp-contract/blob/
|
|
345
|
+
Defined in: [packages/client/src/errors.ts:24](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/errors.ts#L24)
|
|
346
346
|
|
|
347
347
|
###### Parameters
|
|
348
348
|
|
|
@@ -368,9 +368,9 @@ Error.constructor
|
|
|
368
368
|
| <a id="cause-2"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
|
|
369
369
|
| <a id="message-2"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
370
370
|
| <a id="name-2"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
371
|
-
| <a id="rpcname-1"></a> `rpcName` | `readonly` | `string` | - | - | [packages/client/src/errors.ts:25](https://github.com/btravers/amqp-contract/blob/
|
|
371
|
+
| <a id="rpcname-1"></a> `rpcName` | `readonly` | `string` | - | - | [packages/client/src/errors.ts:25](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/errors.ts#L25) |
|
|
372
372
|
| <a id="stack-2"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
373
|
-
| <a id="timeoutms"></a> `timeoutMs` | `readonly` | `number` | - | - | [packages/client/src/errors.ts:26](https://github.com/btravers/amqp-contract/blob/
|
|
373
|
+
| <a id="timeoutms"></a> `timeoutMs` | `readonly` | `number` | - | - | [packages/client/src/errors.ts:26](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/errors.ts#L26) |
|
|
374
374
|
| <a id="stacktracelimit-2"></a> `stackTraceLimit` | `static` | `number` | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
|
|
375
375
|
|
|
376
376
|
#### Methods
|
|
@@ -477,7 +477,7 @@ Error.prepareStackTrace
|
|
|
477
477
|
|
|
478
478
|
### TypedAmqpClient
|
|
479
479
|
|
|
480
|
-
Defined in: [packages/client/src/client.ts:
|
|
480
|
+
Defined in: [packages/client/src/client.ts:125](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L125)
|
|
481
481
|
|
|
482
482
|
Type-safe AMQP client for publishing messages
|
|
483
483
|
|
|
@@ -502,7 +502,7 @@ call<TName>(
|
|
|
502
502
|
| RpcCancelledError>;
|
|
503
503
|
```
|
|
504
504
|
|
|
505
|
-
Defined in: [packages/client/src/client.ts:
|
|
505
|
+
Defined in: [packages/client/src/client.ts:406](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L406)
|
|
506
506
|
|
|
507
507
|
Invoke an RPC defined via `defineRpc` and await the typed response.
|
|
508
508
|
|
|
@@ -548,7 +548,7 @@ if (result.isOk()) console.log(result.value.sum); // 3
|
|
|
548
548
|
close(): ResultAsync<void, TechnicalError>;
|
|
549
549
|
```
|
|
550
550
|
|
|
551
|
-
Defined in: [packages/client/src/client.ts:
|
|
551
|
+
Defined in: [packages/client/src/client.ts:556](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L556)
|
|
552
552
|
|
|
553
553
|
Close the channel and connection. Cancels the reply consumer (if any) and
|
|
554
554
|
rejects every in-flight RPC call with `RpcCancelledError`.
|
|
@@ -566,7 +566,7 @@ publish<TName>(
|
|
|
566
566
|
options?): ResultAsync<void, TechnicalError | MessageValidationError>;
|
|
567
567
|
```
|
|
568
568
|
|
|
569
|
-
Defined in: [packages/client/src/client.ts:
|
|
569
|
+
Defined in: [packages/client/src/client.ts:298](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L298)
|
|
570
570
|
|
|
571
571
|
Publish a message using a defined publisher.
|
|
572
572
|
|
|
@@ -600,7 +600,7 @@ value already in options will be overwritten by the compression algorithm.
|
|
|
600
600
|
static create<TContract>(__namedParameters): ResultAsync<TypedAmqpClient<TContract>, TechnicalError>;
|
|
601
601
|
```
|
|
602
602
|
|
|
603
|
-
Defined in: [packages/client/src/client.ts:
|
|
603
|
+
Defined in: [packages/client/src/client.ts:156](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L156)
|
|
604
604
|
|
|
605
605
|
Create a type-safe AMQP client from a contract.
|
|
606
606
|
|
|
@@ -635,7 +635,7 @@ connection options, following RabbitMQ best practices.
|
|
|
635
635
|
type CallOptions = object;
|
|
636
636
|
```
|
|
637
637
|
|
|
638
|
-
Defined in: [packages/client/src/client.ts:
|
|
638
|
+
Defined in: [packages/client/src/client.ts:105](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L105)
|
|
639
639
|
|
|
640
640
|
Per-call options for `client.call()`.
|
|
641
641
|
|
|
@@ -643,8 +643,8 @@ Per-call options for `client.call()`.
|
|
|
643
643
|
|
|
644
644
|
| Property | Type | Description | Defined in |
|
|
645
645
|
| ------ | ------ | ------ | ------ |
|
|
646
|
-
| <a id="publishoptions"></a> `publishOptions?` | `Omit`<`AmqpClientPublishOptions`, `"replyTo"` \| `"correlationId"`> | Optional AMQP message properties to merge into the request. `replyTo` and `correlationId` are managed by the client and cannot be overridden. | [packages/client/src/client.ts:
|
|
647
|
-
| <a id="timeoutms-1"></a> `timeoutMs` | `number` | Maximum time in ms to wait for an RPC reply. If exceeded, the call resolves to `err(RpcTimeoutError)` and the in-memory correlation entry is cleared. A late reply arriving after the timeout is silently dropped. Required: RPC without a timeout is a footgun. | [packages/client/src/client.ts:
|
|
646
|
+
| <a id="publishoptions"></a> `publishOptions?` | `Omit`<`AmqpClientPublishOptions`, `"replyTo"` \| `"correlationId"`> | Optional AMQP message properties to merge into the request. `replyTo` and `correlationId` are managed by the client and cannot be overridden. | [packages/client/src/client.ts:119](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L119) |
|
|
647
|
+
| <a id="timeoutms-1"></a> `timeoutMs` | `number` | Maximum time in ms to wait for an RPC reply. If exceeded, the call resolves to `err(RpcTimeoutError)` and the in-memory correlation entry is cleared. A late reply arriving after the timeout is silently dropped. Required: RPC without a timeout is a footgun. | [packages/client/src/client.ts:113](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L113) |
|
|
648
648
|
|
|
649
649
|
***
|
|
650
650
|
|
|
@@ -654,7 +654,7 @@ Per-call options for `client.call()`.
|
|
|
654
654
|
type ClientInferPublisherInput<TContract, TName> = PublisherInferInput<InferPublisher<TContract, TName>>;
|
|
655
655
|
```
|
|
656
656
|
|
|
657
|
-
Defined in: [packages/client/src/types.ts:43](https://github.com/btravers/amqp-contract/blob/
|
|
657
|
+
Defined in: [packages/client/src/types.ts:43](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/types.ts#L43)
|
|
658
658
|
|
|
659
659
|
Input type accepted by `client.publish(name, ...)` for a specific publisher.
|
|
660
660
|
|
|
@@ -673,7 +673,7 @@ Input type accepted by `client.publish(name, ...)` for a specific publisher.
|
|
|
673
673
|
type ClientInferRpcRequestInput<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<infer TRequest, MessageDefinition> ? TRequest extends MessageDefinition ? InferSchemaInput<TRequest["payload"]> : never : never;
|
|
674
674
|
```
|
|
675
675
|
|
|
676
|
-
Defined in: [packages/client/src/types.ts:61](https://github.com/btravers/amqp-contract/blob/
|
|
676
|
+
Defined in: [packages/client/src/types.ts:61](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/types.ts#L61)
|
|
677
677
|
|
|
678
678
|
Input type accepted by `client.call(name, request, ...)`.
|
|
679
679
|
|
|
@@ -692,7 +692,7 @@ Input type accepted by `client.call(name, request, ...)`.
|
|
|
692
692
|
type ClientInferRpcResponseOutput<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<MessageDefinition, infer TResponse> ? TResponse extends MessageDefinition ? InferSchemaOutput<TResponse["payload"]> : never : never;
|
|
693
693
|
```
|
|
694
694
|
|
|
695
|
-
Defined in: [packages/client/src/types.ts:74](https://github.com/btravers/amqp-contract/blob/
|
|
695
|
+
Defined in: [packages/client/src/types.ts:74](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/types.ts#L74)
|
|
696
696
|
|
|
697
697
|
Output (validated) response type returned by `client.call(name, ...)`.
|
|
698
698
|
|
|
@@ -711,7 +711,7 @@ Output (validated) response type returned by `client.call(name, ...)`.
|
|
|
711
711
|
type CreateClientOptions<TContract> = object;
|
|
712
712
|
```
|
|
713
713
|
|
|
714
|
-
Defined in: [packages/client/src/client.ts:
|
|
714
|
+
Defined in: [packages/client/src/client.ts:76](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L76)
|
|
715
715
|
|
|
716
716
|
Options for creating a client
|
|
717
717
|
|
|
@@ -725,13 +725,13 @@ Options for creating a client
|
|
|
725
725
|
|
|
726
726
|
| Property | Type | Description | Defined in |
|
|
727
727
|
| ------ | ------ | ------ | ------ |
|
|
728
|
-
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | - | [packages/client/src/client.ts:
|
|
729
|
-
| <a id="connecttimeoutms"></a> `connectTimeoutMs?` | `number` \| `null` | Maximum time in ms to wait for the AMQP connection to become ready before `create()` resolves to an `err(TechnicalError)`. Defaults to 30s (the [AmqpClient](https://btravers.github.io/amqp-contract/api/core#amqpclient)'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to disable the timeout and let amqp-connection-manager retry indefinitely. | [packages/client/src/client.ts:
|
|
730
|
-
| <a id="contract"></a> `contract` | `TContract` | - | [packages/client/src/client.ts:
|
|
731
|
-
| <a id="defaultpublishoptions"></a> `defaultPublishOptions?` | [`PublishOptions`](#publishoptions-1) | Default publish options that will be applied to all publish operations. These can be overridden by options passed to the publish method. By default, persistent is set to true for message durability. | [packages/client/src/client.ts:
|
|
732
|
-
| <a id="logger"></a> `logger?` | `Logger` | - | [packages/client/src/client.ts:
|
|
733
|
-
| <a id="telemetry"></a> `telemetry?` | `TelemetryProvider` | Optional telemetry provider for tracing and metrics. If not provided, uses the default provider which attempts to load OpenTelemetry. OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed. | [packages/client/src/client.ts:
|
|
734
|
-
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | - | [packages/client/src/client.ts:
|
|
728
|
+
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | - | [packages/client/src/client.ts:79](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L79) |
|
|
729
|
+
| <a id="connecttimeoutms"></a> `connectTimeoutMs?` | `number` \| `null` | Maximum time in ms to wait for the AMQP connection to become ready before `create()` resolves to an `err(TechnicalError)`. Defaults to 30s (the [AmqpClient](https://btravers.github.io/amqp-contract/api/core#amqpclient)'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to disable the timeout and let amqp-connection-manager retry indefinitely. | [packages/client/src/client.ts:99](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L99) |
|
|
730
|
+
| <a id="contract"></a> `contract` | `TContract` | - | [packages/client/src/client.ts:77](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L77) |
|
|
731
|
+
| <a id="defaultpublishoptions"></a> `defaultPublishOptions?` | [`PublishOptions`](#publishoptions-1) | Default publish options that will be applied to all publish operations. These can be overridden by options passed to the publish method. By default, persistent is set to true for message durability. | [packages/client/src/client.ts:92](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L92) |
|
|
732
|
+
| <a id="logger"></a> `logger?` | `Logger` | - | [packages/client/src/client.ts:80](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L80) |
|
|
733
|
+
| <a id="telemetry"></a> `telemetry?` | `TelemetryProvider` | Optional telemetry provider for tracing and metrics. If not provided, uses the default provider which attempts to load OpenTelemetry. OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed. | [packages/client/src/client.ts:86](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L86) |
|
|
734
|
+
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | - | [packages/client/src/client.ts:78](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L78) |
|
|
735
735
|
|
|
736
736
|
***
|
|
737
737
|
|
|
@@ -741,7 +741,7 @@ Options for creating a client
|
|
|
741
741
|
type PublishOptions = AmqpClientPublishOptions & object;
|
|
742
742
|
```
|
|
743
743
|
|
|
744
|
-
Defined in: [packages/client/src/client.ts:
|
|
744
|
+
Defined in: [packages/client/src/client.ts:64](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L64)
|
|
745
745
|
|
|
746
746
|
Publish options that extend amqp-client's PublishOptions with optional compression support.
|
|
747
747
|
|
|
@@ -749,4 +749,4 @@ Publish options that extend amqp-client's PublishOptions with optional compressi
|
|
|
749
749
|
|
|
750
750
|
| Name | Type | Description | Defined in |
|
|
751
751
|
| ------ | ------ | ------ | ------ |
|
|
752
|
-
| `compression?` | `CompressionAlgorithm` | Optional compression algorithm to use for the message payload. When specified, the message will be compressed using the chosen algorithm and the contentEncoding header will be set automatically. | [packages/client/src/client.ts:
|
|
752
|
+
| `compression?` | `CompressionAlgorithm` | Optional compression algorithm to use for the message payload. When specified, the message will be compressed using the chosen algorithm and the contentEncoding header will be set automatically. | [packages/client/src/client.ts:70](https://github.com/btravers/amqp-contract/blob/a478140dbe88d884a96d8fcfb20743271fd43c3f/packages/client/src/client.ts#L70) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amqp-contract/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Client utilities for publishing messages using amqp-contract",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"amqp",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"@standard-schema/spec": "1.1.0",
|
|
54
54
|
"neverthrow": "8.2.0",
|
|
55
55
|
"ts-pattern": "5.9.0",
|
|
56
|
-
"@amqp-contract/contract": "0.
|
|
57
|
-
"@amqp-contract/core": "0.
|
|
56
|
+
"@amqp-contract/contract": "0.25.0",
|
|
57
|
+
"@amqp-contract/core": "0.25.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/amqplib": "0.10.8",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"typescript": "6.0.3",
|
|
69
69
|
"vitest": "4.1.5",
|
|
70
70
|
"zod": "4.4.3",
|
|
71
|
-
"@amqp-contract/
|
|
72
|
-
"@amqp-contract/
|
|
73
|
-
"@amqp-contract/
|
|
71
|
+
"@amqp-contract/tsconfig": "0.1.0",
|
|
72
|
+
"@amqp-contract/testing": "0.25.0",
|
|
73
|
+
"@amqp-contract/typedoc": "0.1.0"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"build": "tsdown src/index.ts --format cjs,esm --dts --clean",
|