@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
new MessageValidationError(publisherName, issues): MessageValidationError;Defined in: packages/client/src/errors.ts:36
Parameters
| Parameter | Type |
|---|---|
publisherName | string |
issues | unknown |
Returns
Overrides
ClientError.constructorProperties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | public | unknown | - | ClientError.cause | node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26 |
issues | readonly | unknown | - | - | packages/client/src/errors.ts:38 |
message | public | string | - | ClientError.message | node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | ClientError.name | node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076 |
publisherName | readonly | string | - | - | packages/client/src/errors.ts:37 |
stack? | public | string | - | ClientError.stack | node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078 |
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. | ClientError.stackTraceLimit | node_modules/.pnpm/@types+node@25.0.3/node_modules/@types/node/globals.d.ts:67 |
Methods
captureStackTrace()
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.
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:
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
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
ClientError.captureStackTraceprepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/.pnpm/@types+node@25.0.3/node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
ClientError.prepareStackTraceTechnicalError
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
new TechnicalError(message, cause?): TechnicalError;Defined in: packages/client/src/errors.ts:23
Parameters
| Parameter | Type |
|---|---|
message | string |
cause? | unknown |
Returns
Overrides
ClientError.constructorProperties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | - | ClientError.cause | packages/client/src/errors.ts:25 |
message | public | string | - | ClientError.message | node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | ClientError.name | node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | ClientError.stack | node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078 |
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. | ClientError.stackTraceLimit | node_modules/.pnpm/@types+node@25.0.3/node_modules/@types/node/globals.d.ts:67 |
Methods
captureStackTrace()
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.
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:
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
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
ClientError.captureStackTraceprepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/.pnpm/@types+node@25.0.3/node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
ClientError.prepareStackTraceTypedAmqpClient
Defined in: packages/client/src/client.ts:22
Type-safe AMQP client for publishing messages
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
Methods
close()
close(): Future<Result<void, TechnicalError>>;Defined in: packages/client/src/client.ts:130
Close the channel and connection
Returns
Future<Result<void, TechnicalError>>
publish()
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
| Parameter | Type |
|---|---|
publisherName | TName |
message | ClientInferPublisherInput<TContract, TName> |
options? | Publish |
Returns
Future<Result<void, | TechnicalError | MessageValidationError>>
create()
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
| Parameter | Type |
|---|---|
__namedParameters | CreateClientOptions<TContract> |
Returns
Future<Result<TypedAmqpClient<TContract>, TechnicalError>>
Type Aliases
ClientInferPublisherInput
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
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
| Property | Type | Defined in |
|---|---|---|
connectionOptions? | AmqpConnectionManagerOptions | packages/client/src/client.ts:15 |
contract | TContract | packages/client/src/client.ts:13 |
logger? | Logger | packages/client/src/client.ts:16 |
urls | ConnectionUrl[] | packages/client/src/client.ts:14 |