Skip to content

@amqp-contract/client


@amqp-contract/client

Classes

MessageValidationError

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

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:86

Parameters
ParameterType
sourcestring
issuesunknown
Returns

MessageValidationError

Overrides
ts
Error.constructor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
cause?publicunknown-Error.causenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
issuesreadonlyunknown--packages/core/dist/index.d.mts:85
messagepublicstring-Error.messagenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077
namepublicstring-Error.namenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076
sourcereadonlystring--packages/core/dist/index.d.mts:84
stack?publicstring-Error.stacknode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078
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@25.3.2/node_modules/@types/node/globals.d.ts:67

Methods

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

Defined in: node_modules/.pnpm/@types+node@25.3.2/node_modules/@types/node/globals.d.ts:51

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@25.3.2/node_modules/@types/node/globals.d.ts:55

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:56

Type-safe AMQP client for publishing messages

Type Parameters

Type Parameter
TContract extends ContractDefinition

Methods

close()
ts
close(): Future<Result<void, TechnicalError>>;

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

Close the channel and connection

Returns

Future<Result<void, TechnicalError>>

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

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

Publish a message using a defined publisher. TypeScript guarantees publisher exists for valid publisher names.

Type Parameters
Type Parameter
TName extends string | number | symbol
Parameters
ParameterType
publisherNameTName
messageClientInferPublisherInput<TContract, TName>
options?PublishOptions
Returns

Future<Result<void, TechnicalError | MessageValidationError>>

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

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

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

Future<Result<TypedAmqpClient<TContract>, TechnicalError>>

Type Aliases

ClientInferPublisherInput

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

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

Infer publisher input type (message payload) for a specific publisher in a contract

Type Parameters

Type Parameter
TContract extends ContractDefinition
TName extends InferPublisherNames<TContract>

CreateClientOptions

ts
type CreateClientOptions<TContract> = object;

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

Options for creating a client

Type Parameters

Type Parameter
TContract extends ContractDefinition

Properties

PropertyTypeDescriptionDefined in
connectionOptions?AmqpConnectionManagerOptions-packages/client/src/client.ts:43
contractTContract-packages/client/src/client.ts:41
logger?Logger-packages/client/src/client.ts:44
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:50
urlsConnectionUrl[]-packages/client/src/client.ts:42

PublishOptions

ts
type PublishOptions = Options.Publish & object;

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

Publish options that extend amqplib's Options.Publish 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:34

Released under the MIT License.