Skip to content

@amqp-contract/client


@amqp-contract/client

Classes

MessageValidationError

Defined in: packages/core/dist/index.d.mts:27

Error thrown when message validation fails (payload or headers).

Used by both the client (publish-time payload validation) and the worker (consume-time payload and headers validation).

Param

The name of the publisher or consumer that triggered the validation

Param

The validation issues from the Standard Schema validation

Extends

  • Error

Constructors

Constructor
ts
new MessageValidationError(source, issues): MessageValidationError;

Defined in: packages/core/dist/index.d.mts:30

Parameters
ParameterType
sourcestring
issuesunknown
Returns

MessageValidationError

Overrides
ts
Error.constructor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
cause?publicunknown-Error.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
issuesreadonlyunknown--packages/core/dist/index.d.mts:29
messagepublicstring-Error.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstring-Error.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
sourcereadonlystring--packages/core/dist/index.d.mts:28
stack?publicstring-Error.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
stackTraceLimitstaticnumberThe 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.stackTraceLimitnode_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:68

Methods

captureStackTrace()
ts
static captureStackTrace(targetObject, constructorOpt?): void;

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

js
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters
ParameterType
targetObjectobject
constructorOpt?Function
Returns

void

Inherited from
ts
Error.captureStackTrace
prepareStackTrace()
ts
static prepareStackTrace(err, stackTraces): any;

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:56

Parameters
ParameterType
errError
stackTracesCallSite[]
Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from
ts
Error.prepareStackTrace

RpcCancelledError

Defined in: packages/client/src/errors.ts:39

Returned from any in-flight RPC call when the client is closed before the reply is received. The correlation map is cleared on close and every pending caller's promise resolves with err(RpcCancelledError).

Extends

  • Error

Constructors

Constructor
ts
new RpcCancelledError(rpcName): RpcCancelledError;

Defined in: packages/client/src/errors.ts:40

Parameters
ParameterType
rpcNamestring
Returns

RpcCancelledError

Overrides
ts
Error.constructor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
cause?publicunknown-Error.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
messagepublicstring-Error.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstring-Error.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
rpcNamereadonlystring--packages/client/src/errors.ts:40
stack?publicstring-Error.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
stackTraceLimitstaticnumberThe 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.stackTraceLimitnode_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:68

Methods

captureStackTrace()
ts
static captureStackTrace(targetObject, constructorOpt?): void;

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

js
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters
ParameterType
targetObjectobject
constructorOpt?Function
Returns

void

Inherited from
ts
Error.captureStackTrace
prepareStackTrace()
ts
static prepareStackTrace(err, stackTraces): any;

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:56

Parameters
ParameterType
errError
stackTracesCallSite[]
Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from
ts
Error.prepareStackTrace

RpcTimeoutError

Defined in: packages/client/src/errors.ts:23

Returned from TypedAmqpClient.call() when the configured timeoutMs elapses before the RPC server publishes a reply with the matching correlationId.

The pending call is removed from the in-memory correlation map; if a reply arrives after the timeout it is dropped (and a debug log is emitted by the client if a logger is configured).

Extends

  • Error

Constructors

Constructor
ts
new RpcTimeoutError(rpcName, timeoutMs): RpcTimeoutError;

Defined in: packages/client/src/errors.ts:24

Parameters
ParameterType
rpcNamestring
timeoutMsnumber
Returns

RpcTimeoutError

Overrides
ts
Error.constructor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
cause?publicunknown-Error.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
messagepublicstring-Error.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstring-Error.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
rpcNamereadonlystring--packages/client/src/errors.ts:25
stack?publicstring-Error.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
timeoutMsreadonlynumber--packages/client/src/errors.ts:26
stackTraceLimitstaticnumberThe 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.stackTraceLimitnode_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:68

Methods

captureStackTrace()
ts
static captureStackTrace(targetObject, constructorOpt?): void;

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

js
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters
ParameterType
targetObjectobject
constructorOpt?Function
Returns

void

Inherited from
ts
Error.captureStackTrace
prepareStackTrace()
ts
static prepareStackTrace(err, stackTraces): any;

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:56

Parameters
ParameterType
errError
stackTracesCallSite[]
Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from
ts
Error.prepareStackTrace

TypedAmqpClient

Defined in: packages/client/src/client.ts:125

Type-safe AMQP client for publishing messages

Type Parameters

Type Parameter
TContract extends ContractDefinition

Methods

call()
ts
call<TName>(
   rpcName, 
   request, 
   options): ResultAsync<ClientInferRpcResponseOutput<TContract, TName>, 
  | TechnicalError
  | MessageValidationError
  | RpcTimeoutError
  | RpcCancelledError>;

Defined in: packages/client/src/client.ts:406

Invoke an RPC defined via defineRpc and await the typed response.

The request payload is validated against the RPC's request schema, then published to the AMQP default exchange with the server's queue name as routing key, replyTo set to amq.rabbitmq.reply-to, and a fresh UUID correlationId. The returned ResultAsync resolves once a matching reply arrives and validates against the response schema, or once timeoutMs elapses (whichever comes first).

Type Parameters
Type Parameter
TName extends string | number | symbol
Parameters
ParameterType
rpcNameTName
requestClientInferRpcRequestInput<TContract, TName>
optionsCallOptions
Returns

ResultAsync<ClientInferRpcResponseOutput<TContract, TName>, | TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError>

Example
typescript
const result = await client.call('calculate', { a: 1, b: 2 }, { timeoutMs: 5_000 });
if (result.isOk()) console.log(result.value.sum); // 3
close()
ts
close(): ResultAsync<void, TechnicalError>;

Defined in: packages/client/src/client.ts:556

Close the channel and connection. Cancels the reply consumer (if any) and rejects every in-flight RPC call with RpcCancelledError.

Returns

ResultAsync<void, TechnicalError>

publish()
ts
publish<TName>(
   publisherName, 
   message, 
   options?): ResultAsync<void, TechnicalError | MessageValidationError>;

Defined in: packages/client/src/client.ts:298

Publish a message using a defined publisher.

Type Parameters
Type Parameter
TName extends string | number | symbol
Parameters
ParameterTypeDescription
publisherNameTNameThe name of the publisher to use
messageClientInferPublisherInput<TContract, TName>The message to publish
options?PublishOptionsOptional publish options including compression, headers, priority, etc.
Returns

ResultAsync<void, TechnicalError | MessageValidationError>

Remarks

If options.compression is specified, the message will be compressed before publishing and the contentEncoding property will be set automatically. Any contentEncoding value already in options will be overwritten by the compression algorithm.

create()
ts
static create<TContract>(__namedParameters): ResultAsync<TypedAmqpClient<TContract>, TechnicalError>;

Defined in: packages/client/src/client.ts:156

Create a type-safe AMQP client from a contract.

Connection management (including automatic reconnection) is handled internally by amqp-connection-manager via the AmqpClient. The client establishes infrastructure asynchronously in the background once the connection is ready.

Connections are automatically shared across clients with the same URLs and connection options, following RabbitMQ best practices.

Type Parameters
Type Parameter
TContract extends ContractDefinition
Parameters
ParameterType
__namedParametersCreateClientOptions<TContract>
Returns

ResultAsync<TypedAmqpClient<TContract>, TechnicalError>

Type Aliases

CallOptions

ts
type CallOptions = object;

Defined in: packages/client/src/client.ts:105

Per-call options for client.call().

Properties

PropertyTypeDescriptionDefined in
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
timeoutMsnumberMaximum 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

ClientInferPublisherInput

ts
type ClientInferPublisherInput<TContract, TName> = PublisherInferInput<InferPublisher<TContract, TName>>;

Defined in: packages/client/src/types.ts:43

Input type accepted by client.publish(name, ...) for a specific publisher.

Type Parameters

Type Parameter
TContract extends ContractDefinition
TName extends InferPublisherNames<TContract>

ClientInferRpcRequestInput

ts
type ClientInferRpcRequestInput<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<infer TRequest, MessageDefinition> ? TRequest extends MessageDefinition ? InferSchemaInput<TRequest["payload"]> : never : never;

Defined in: packages/client/src/types.ts:61

Input type accepted by client.call(name, request, ...).

Type Parameters

Type Parameter
TContract extends ContractDefinition
TName extends InferRpcNames<TContract>

ClientInferRpcResponseOutput

ts
type ClientInferRpcResponseOutput<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<MessageDefinition, infer TResponse> ? TResponse extends MessageDefinition ? InferSchemaOutput<TResponse["payload"]> : never : never;

Defined in: packages/client/src/types.ts:74

Output (validated) response type returned by client.call(name, ...).

Type Parameters

Type Parameter
TContract extends ContractDefinition
TName extends InferRpcNames<TContract>

CreateClientOptions

ts
type CreateClientOptions<TContract> = object;

Defined in: packages/client/src/client.ts:76

Options for creating a client

Type Parameters

Type Parameter
TContract extends ContractDefinition

Properties

PropertyTypeDescriptionDefined in
connectionOptions?AmqpConnectionManagerOptions-packages/client/src/client.ts:79
connectTimeoutMs?number | nullMaximum time in ms to wait for the AMQP connection to become ready before create() resolves to an err(TechnicalError). Defaults to 30s (the 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
contractTContract-packages/client/src/client.ts:77
defaultPublishOptions?PublishOptionsDefault 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
logger?Logger-packages/client/src/client.ts:80
telemetry?TelemetryProviderOptional 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
urlsConnectionUrl[]-packages/client/src/client.ts:78

PublishOptions

ts
type PublishOptions = AmqpClientPublishOptions & object;

Defined in: packages/client/src/client.ts:64

Publish options that extend amqp-client's PublishOptions with optional compression support.

Type Declaration

NameTypeDescriptionDefined in
compression?CompressionAlgorithmOptional 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

Released under the MIT License.