Skip to content

@amqp-contract/client


@amqp-contract/client

Classes

MessageValidationError

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

Error thrown when message validation fails

Extends

  • ClientError

Constructors

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

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

Parameters
ParameterType
publisherNamestring
issuesunknown
Returns

MessageValidationError

Overrides
ts
ClientError.constructor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
cause?publicunknown-ClientError.causenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
issuesreadonlyunknown--packages/client/src/errors.ts:38
messagepublicstring-ClientError.messagenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077
namepublicstring-ClientError.namenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076
publisherNamereadonlystring--packages/client/src/errors.ts:37
stack?publicstring-ClientError.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.ClientError.stackTraceLimitnode_modules/.pnpm/@types+node@25.0.3/node_modules/@types/node/globals.d.ts:67

Methods

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

Defined in: node_modules/.pnpm/@types+node@25.0.3/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
ClientError.captureStackTrace
prepareStackTrace()
ts
static prepareStackTrace(err, stackTraces): any;

Defined in: node_modules/.pnpm/@types+node@25.0.3/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
ClientError.prepareStackTrace

TechnicalError

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

Error for technical/runtime failures that cannot be prevented by TypeScript This includes validation failures and AMQP channel issues

Extends

  • ClientError

Constructors

Constructor
ts
new TechnicalError(message, cause?): TechnicalError;

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

Parameters
ParameterType
messagestring
cause?unknown
Returns

TechnicalError

Overrides
ts
ClientError.constructor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
cause?readonlyunknown-ClientError.causepackages/client/src/errors.ts:25
messagepublicstring-ClientError.messagenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077
namepublicstring-ClientError.namenode_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076
stack?publicstring-ClientError.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.ClientError.stackTraceLimitnode_modules/.pnpm/@types+node@25.0.3/node_modules/@types/node/globals.d.ts:67

Methods

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

Defined in: node_modules/.pnpm/@types+node@25.0.3/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
ClientError.captureStackTrace
prepareStackTrace()
ts
static prepareStackTrace(err, stackTraces): any;

Defined in: node_modules/.pnpm/@types+node@25.0.3/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
ClientError.prepareStackTrace

TypedAmqpClient

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

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

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

Publish a message using a defined publisher Returns Result.Ok(true) on success, or Result.Error with specific error on failure

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

Future<Result<void, | TechnicalError | MessageValidationError>>

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

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

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

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

Options for creating a client

Type Parameters

Type Parameter
TContract extends ContractDefinition

Properties

PropertyTypeDefined in
connectionOptions?AmqpConnectionManagerOptionspackages/client/src/client.ts:15
contractTContractpackages/client/src/client.ts:13
logger?Loggerpackages/client/src/client.ts:16
urlsConnectionUrl[]packages/client/src/client.ts:14

Released under the MIT License.