Skip to content

@amqp-contract/client


@amqp-contract/client ​

Classes ​

ConnectionError ​

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:63

The broker could not be reached: refused, unresolvable, unauthorized, or still not ready when connectTimeoutMs elapsed.

Modeled, not a defect — unlike TechnicalError. An unreachable broker is the anticipated failure of dialing one: it is what a wrong URL, a rotated credential or a cluster that has not come up yet look like, every one of them an operator's business rather than a bug in the caller. So TypedAmqpWorker.create and TypedAmqpClient.create report it on the E channel, where a start-up path can triage it by tag and turn it into an exit code, a retry, or a health probe — and the defect channel keeps its meaning: the failures nobody anticipated.

Carries a _tag of "@amqp-contract/ConnectionError"; the human-facing Error.name is kept bare ("ConnectionError"). The underlying amqplib rejection is on cause.

Extends ​

  • ConnectionError_base<{ cause?: unknown; }>

Constructors ​

Constructor ​
ts
new ConnectionError(message, cause?): ConnectionError;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:68

Parameters ​
ParameterType
messagestring
cause?unknown
Returns ​

ConnectionError

Overrides ​

ConnectionError_base<{ cause?: unknown; }>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_tagreadonly"@amqp-contract/ConnectionError"undefined-ConnectionError_base._tagnode_modules/.pnpm/unthrown@5.12.2/node_modules/unthrown/dist/index.d.mts:2363
cause?publicunknownundefined-MessageValidationError.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
messagepublicstringundefined-ConnectionError_base.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringundefined-ConnectionError_base.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringundefined-ConnectionError_base.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tagstatic readonly"@amqp-contract/ConnectionError""@amqp-contract/ConnectionError"The _tag, for P.tag(ConnectionError.tag) without a raw string.-packages/core/dist/telemetry-U0DumV05.d.mts:67

MessageValidationError ​

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:126

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). Carries a _tag of "@amqp-contract/MessageValidationError" (namespaced to avoid collisions); the Error.name is kept bare ("MessageValidationError").

Param ​

source

The name of the publisher or consumer that triggered the validation

Param ​

issues

The validation issues from the Standard Schema validation

Extends ​

  • MessageValidationError_base<{ issues: unknown; source: string; }>

Constructors ​

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

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:132

Parameters ​
ParameterType
sourcestring
issuesunknown
Returns ​

MessageValidationError

Overrides ​

MessageValidationError_base<{ source: string; issues: unknown; }>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_tagreadonly"@amqp-contract/MessageValidationError"undefined-MessageValidationError_base._tagnode_modules/.pnpm/unthrown@5.12.2/node_modules/unthrown/dist/index.d.mts:2363
cause?publicunknownundefined-MessageValidationError_base.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
issuesreadonlyunknownundefined-MessageValidationError_base.issuespackages/core/dist/telemetry-U0DumV05.d.mts:128
messagepublicstringundefined-MessageValidationError_base.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringundefined-MessageValidationError_base.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
sourcereadonlystringundefined-MessageValidationError_base.sourcepackages/core/dist/telemetry-U0DumV05.d.mts:127
stack?publicstringundefined-MessageValidationError_base.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tagstatic readonly"@amqp-contract/MessageValidationError""@amqp-contract/MessageValidationError"The _tag, for P.tag(MessageValidationError.tag) without a raw string.-packages/core/dist/telemetry-U0DumV05.d.mts:131

PublishError ​

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:100

The broker side of a publish failed: timed out, nacked, or the channel closed under it. (A full write buffer is NOT one: on the confirm channel the wrapper only reports it after the broker confirmed the message.)

Modeled, not a defect — a broker that is down, overloaded or refusing a message is an operational condition a publisher is expected to handle (buffer, retry, shed load, surface a 503), not a bug. Returned on the E channel of AmqpClient.publish, TypedAmqpClient.publish and TypedAmqpClient.call; switch on PublishError.reason. A failure core cannot classify (an unencodable payload, an unknown rejection) stays a Defect with a TechnicalError cause.

Carries a _tag of "@amqp-contract/PublishError"; the Error.name is kept bare ("PublishError"). The underlying rejection, if any, is on cause.

Extends ​

Constructors ​

Constructor ​
ts
new PublishError(props): PublishError;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:108

Parameters ​
ParameterType
props{ cause?: unknown; reason: PublishFailureReason; target: string; }
props.cause?unknown
props.reasonPublishFailureReason
props.targetstring
Returns ​

PublishError

Overrides ​

PublishError_base<{ reason: PublishFailureReason; /** Where the message was going, e.g. `exchange "orders" (routing key "order.created")`. */ target: string; cause?: unknown; }>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_tagreadonly"@amqp-contract/PublishError"undefined-PublishError_base._tagnode_modules/.pnpm/unthrown@5.12.2/node_modules/unthrown/dist/index.d.mts:2363
cause?publicunknownundefined-MessageValidationError.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
messagepublicstringundefined-PublishError_base.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringundefined-PublishError_base.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
reasonreadonlyPublishFailureReasonundefined-PublishError_base.reasonpackages/core/dist/telemetry-U0DumV05.d.mts:101
stack?publicstringundefined-PublishError_base.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
targetreadonlystringundefinedWhere the message was going, e.g. exchange "orders" (routing key "order.created").PublishError_base.targetpackages/core/dist/telemetry-U0DumV05.d.mts:103
tagstatic readonly"@amqp-contract/PublishError""@amqp-contract/PublishError"The _tag, for P.tag(PublishError.tag) without a raw string.-packages/core/dist/telemetry-U0DumV05.d.mts:107

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). Carries a namespaced _tag of "@amqp-contract/RpcCancelledError"; the Error.name is kept bare ("RpcCancelledError").

Extends ​

  • TaggedErrorInstance<"@amqp-contract/RpcCancelledError", { rpcName: string; }>

Constructors ​

Constructor ​
ts
new RpcCancelledError(rpcName): RpcCancelledError;

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

Parameters ​
ParameterType
rpcNamestring
Returns ​

RpcCancelledError

Overrides ​

TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", })<{ rpcName: string; }>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_tagreadonly"@amqp-contract/RpcCancelledError"undefined-TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", })._tagnode_modules/.pnpm/unthrown@5.12.2/node_modules/unthrown/dist/index.d.mts:2363
cause?publicunknownundefined-TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
messagepublicstringundefined-TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringundefined-TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
rpcNamereadonlystringundefined-TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).rpcNamepackages/client/src/errors.ts:42
stack?publicstringundefined-TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tagstatic readonly"@amqp-contract/RpcCancelledError""@amqp-contract/RpcCancelledError"The _tag, for P.tag(RpcCancelledError.tag) without a raw string.-packages/client/src/errors.ts:45

RpcError ​

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:177

A typed, contract-declared RPC error — the business-failure channel of an RPC, as opposed to transport failures (which surface as a Defect with a TechnicalError cause).

Declared per-RPC via defineRpc(queue, { request, response, errors }), where each error code maps to a message definition validating the error's data payload. A worker handler surfaces one by returning Err(rpcError(code, data)); the worker validates data against the declared schema, publishes an error reply, and acks the request (business errors are not retried). The caller's client.call(...) resolves to Err(RpcError<code, data>) with data re-validated on arrival.

Carries a _tag of "@amqp-contract/RpcError" for exhaustive dispatch via the error matcher (result.match({ ok, defect, errCases: (matcher) => matcher.with(P.tag("@amqp-contract/RpcError"), …) })); the Error.name is kept bare ("RpcError"). Discriminate between codes on the code property.

Extends ​

  • RpcError_base<{ code: string; data: unknown; }>

Type Parameters ​

Type ParameterDefault type
TCode extends stringstring
TDataunknown

Constructors ​

Constructor ​
ts
new RpcError<TCode, TData>(
   code, 
   data, 
   message?
): RpcError<TCode, TData>;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:185

Parameters ​
ParameterType
codeTCode
dataTData
message?string
Returns ​

RpcError<TCode, TData>

Overrides ​

RpcError_base<{ code: string; data: unknown; }>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_tagreadonly"@amqp-contract/RpcError"undefined--RpcError_base._tagnode_modules/.pnpm/unthrown@5.12.2/node_modules/unthrown/dist/index.d.mts:2363
cause?publicunknownundefined--RpcError_base.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
codereadonlyTCodeundefined-RpcError_base.code-packages/core/dist/telemetry-U0DumV05.d.mts:183
datareadonlyTDataundefined-RpcError_base.data-packages/core/dist/telemetry-U0DumV05.d.mts:184
messagepublicstringundefined--RpcError_base.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringundefined--RpcError_base.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringundefined--RpcError_base.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tagstatic readonly"@amqp-contract/RpcError""@amqp-contract/RpcError"The _tag, for P.tag(RpcError.tag) without a raw string.--packages/core/dist/telemetry-U0DumV05.d.mts:182

RpcTimeoutError ​

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

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). Carries a namespaced _tag of "@amqp-contract/RpcTimeoutError"; the Error.name is kept bare ("RpcTimeoutError").

Extends ​

  • TaggedErrorInstance<"@amqp-contract/RpcTimeoutError", { rpcName: string; timeoutMs: number; }>

Constructors ​

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

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

Parameters ​
ParameterType
rpcNamestring
timeoutMsnumber
Returns ​

RpcTimeoutError

Overrides ​

TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", })<{ rpcName: string; timeoutMs: number; }>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_tagreadonly"@amqp-contract/RpcTimeoutError"undefined-TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", })._tagnode_modules/.pnpm/unthrown@5.12.2/node_modules/unthrown/dist/index.d.mts:2363
cause?publicunknownundefined-TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
messagepublicstringundefined-TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringundefined-TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
rpcNamereadonlystringundefined-TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).rpcNamepackages/client/src/errors.ts:19
stack?publicstringundefined-TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
timeoutMsreadonlynumberundefined-TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).timeoutMspackages/client/src/errors.ts:20
tagstatic readonly"@amqp-contract/RpcTimeoutError""@amqp-contract/RpcTimeoutError"The _tag, for P.tag(RpcTimeoutError.tag) without a raw string.-packages/client/src/errors.ts:23

TechnicalError ​

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:38

Error for technical/runtime failures that cannot be prevented by TypeScript.

This includes channel issues, compression/parse faults, and other unexpected runtime errors. Shared across core, worker, and client packages. Dialing the broker is NOT one of them any more — that failure is anticipated, and it is modeled as ConnectionError.

These failures are unexpected, so @amqp-contract surfaces them through unthrown's defect channel, not the modeled E channel: a TechnicalError instance is carried as the cause of a Defect (so its message/cause survive for logging), and is handled in the defect arm of result.match({ ok, errCases, defect }) — or via recoverDefect / tapDefect — never matched in errCases. It is deliberately absent from every operation's E (only anticipated domain failures live there).

Built on unthrown's TaggedError, so it carries a _tag of "@amqp-contract/TechnicalError" (namespaced to avoid colliding with other libraries' tags); the human-facing Error.name is kept bare ("TechnicalError"). Remains a real Error.

Extends ​

  • TechnicalError_base<{ cause?: unknown; }>

Constructors ​

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

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:43

Parameters ​
ParameterType
messagestring
cause?unknown
Returns ​

TechnicalError

Overrides ​

TechnicalError_base<{ cause?: unknown; }>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_tagreadonly"@amqp-contract/TechnicalError"undefined-TechnicalError_base._tagnode_modules/.pnpm/unthrown@5.12.2/node_modules/unthrown/dist/index.d.mts:2363
cause?publicunknownundefined-MessageValidationError.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
messagepublicstringundefined-TechnicalError_base.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringundefined-TechnicalError_base.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringundefined-TechnicalError_base.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tagstatic readonly"@amqp-contract/TechnicalError""@amqp-contract/TechnicalError"The _tag, for P.tag(TechnicalError.tag) without a raw string.-packages/core/dist/telemetry-U0DumV05.d.mts:42

TypedAmqpClient ​

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

Type-safe AMQP client for publishing messages

Type Parameters ​

Type Parameter
TContract extends ContractDefinition

Methods ​

call() ​
ts
call<TName>(
   rpcName, 
   request, 
   options
): AsyncResult<ClientInferRpcResponseOutput<TContract, TName>, 
  | MessageValidationError
  | PublishError
  | RpcTimeoutError
  | RpcCancelledError
  | ClientInferRpcErrors<TContract, TName>>;

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

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 AsyncResult 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 ​

AsyncResult<ClientInferRpcResponseOutput<TContract, TName>, | MessageValidationError | PublishError | RpcTimeoutError | RpcCancelledError | ClientInferRpcErrors<TContract, TName>>

Example ​
typescript
const result = await client.call('calculate', { a: 1, b: 2 }, { timeoutMs: 5_000 });
result.match({
  ok: (value) => console.log(value.sum), // 3
  errCases: (matcher) =>
    matcher.with(
      P.tag("@amqp-contract/MessageValidationError"),
      P.tag("@amqp-contract/PublishError"),
      P.tag("@amqp-contract/RpcTimeoutError"),
      P.tag("@amqp-contract/RpcCancelledError"),
      P.tag("@amqp-contract/RpcError"),
      (error) => console.error(error),
    ),
  // Transport/infrastructure failures surface here, never in `errCases`.
  defect: (cause) => console.error(cause),
});
close() ​
ts
close(): AsyncResult<void, never>;

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

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

Returns ​

AsyncResult<void, never>

isConnected() ​
ts
isConnected(): boolean;

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

Whether the broker connection is up and the client is not closed — for a readiness/health probe. false while reconnecting; publishes issued then are buffered up to publishTimeoutMs.

Returns ​

boolean

publish() ​
ts
publish<TName>(
   publisherName, 
   message, 
   options?
): AsyncResult<void, 
  | MessageValidationError
  | PublishError>;

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

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 ​

AsyncResult<void, | MessageValidationError | PublishError>

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>(options): AsyncResult<TypedAmqpClient<TContract>, ConnectionError>;

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

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 shared across clients with the same URLs and connection options — but never with a worker, which draws from a separate pool. Pass connection to use (and share) a connection you own instead.

Type Parameters ​
Type Parameter
TContract extends ContractDefinition
Parameters ​
ParameterType
optionsCreateClientOptions<TContract>
Returns ​

AsyncResult<TypedAmqpClient<TContract>, ConnectionError>

Type Aliases ​

CallError ​

ts
type CallError = 
  | MessageValidationError
  | PublishError
  | RpcTimeoutError
  | RpcCancelledError
  | RpcError;

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

Error union a call interceptor chain resolves with. The RpcError member is the widened (untyped) form; the public client.call(...) signature narrows it to the RPC's declared error union. A failed request publish is the modeled PublishError; other infrastructure failures surface through the Defect channel.


CallInterceptor ​

ts
type CallInterceptor = (args, next) => AsyncResult<unknown, CallError>;

Defined in: packages/client/src/interceptors.ts:120

Intercepts client.call(...): wraps the full request/reply round trip, so it can adjust timeouts, stamp request headers, observe replies and typed errors, or retry by calling next again. The first interceptor in the array is the outermost.

Parameters ​

ParameterType
argsCallInterceptorArgs
nextCallInterceptorNext

Returns ​

AsyncResult<unknown, CallError>

Example ​

Retry timed-out calls once

typescript
import { ErrAsync, P } from "unthrown";

const retryOnce: CallInterceptor = (args, next) =>
  next().flatMapErrCases((matcher) =>
    matcher.with(
      P.tag("@amqp-contract/MessageValidationError"),
      P.tag("@amqp-contract/PublishError"),
      P.tag("@amqp-contract/RpcTimeoutError"),
      P.tag("@amqp-contract/RpcCancelledError"),
      P.tag("@amqp-contract/RpcError"),
      (error) => (error instanceof RpcTimeoutError ? next() : ErrAsync(error)),
    ),
  );

CallInterceptorArgs ​

ts
type CallInterceptorArgs = object;

Defined in: packages/client/src/interceptors.ts:79

Arguments a call interceptor observes. request is the pre-validation request payload.

Properties ​

PropertyTypeDescriptionDefined in
optionsCallOptionsPer-call options (timeoutMs, publishOptions).packages/client/src/interceptors.ts:85
requestunknownThe (not yet validated) request payload.packages/client/src/interceptors.ts:83
rpcNamestringThe contract rpcs key being called.packages/client/src/interceptors.ts:81

CallInterceptorNext ​

ts
type CallInterceptorNext = (patch?) => AsyncResult<unknown, CallError>;

Defined in: packages/client/src/interceptors.ts:92

Continuation a call interceptor calls to run the rest of the chain. The resolved value is the RPC response (typed at the public call() boundary).

Parameters ​

ParameterType
patch?{ options?: CallOptions; request?: unknown; }
patch.options?CallOptions
patch.request?unknown

Returns ​

AsyncResult<unknown, CallError>


CallOptions ​

ts
type CallOptions = object;

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

Per-call options for client.call().

Properties ​

PropertyTypeDescriptionDefined in
publishOptions?Omit<AmqpPublishOptions, "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:202
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:196

ClientInferCallError ​

ts
type ClientInferCallError<TContract, TName> = 
  | MessageValidationError
  | PublishError
  | RpcTimeoutError
  | RpcCancelledError
  | ClientInferRpcErrors<TContract, TName>;

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

The complete error union of client.call(name, ...) for a given RPC: MessageValidationError | PublishError | RpcTimeoutError | RpcCancelledError plus the RPC's declared typed errors (ClientInferRpcErrors). Use it to name a call's result in wrappers and helper signatures:

typescript
function callWithRetry<TName extends InferRpcNames<typeof contract>>(
  name: TName,
): AsyncResult<ClientInferRpcResponseOutput<typeof contract, TName>, ClientInferCallError<typeof contract, TName>> { ... }

Type Parameters ​

Type Parameter
TContract extends ContractDefinition
TName extends InferRpcNames<TContract>

ClientInferPublisherInput ​

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

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

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

Type Parameters ​

Type Parameter
TContract extends ContractDefinition
TName extends InferPublisherNames<TContract>

ClientInferRpcErrors ​

ts
type ClientInferRpcErrors<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<MessageDefinition, MessageDefinition, QueueDefinition, infer TErrors> ? TErrors extends RpcErrorMap ? { [K in keyof TErrors & string]: RpcError<K, InferSchemaOutput<TErrors[K]["data"]>> }[keyof TErrors & string] : never : never;

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

Typed error union for client.call(name, ...) — one RpcError<code, data> member per entry in the RPC's declared errors map, with data typed as the declared schema's output (the client re-validates error data when the reply arrives). Resolves to never when the RPC declares no errors, so the call's error union stays purely transport-level.

Type Parameters ​

Type Parameter
TContract extends ContractDefinition
TName extends InferRpcNames<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:56

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

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

Type Parameters ​

Type Parameter
TContract extends ContractDefinition
TName extends InferRpcNames<TContract>

ClientPublishError ​

ts
type ClientPublishError = 
  | MessageValidationError
  | PublishError;

Defined in: packages/client/src/interceptors.ts:13

Error union a publish interceptor chain resolves with — identical to the error channel of client.publish(...): the payload failed its schema, or the broker side of the publish failed (PublishError). Every other infrastructure failure surfaces through the Defect channel.


ConnectionSource ​

ts
type ConnectionSource = object;

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

Where a client's connection comes from — exactly one of (checked at construction; passing both or neither is a defect):

  • urls (+ optional connectionOptions): a connection dialled and pooled by amqp-contract, released when the last client using it closes. Multiple URLs provide failover.
  • connection: an AmqpConnectionManager the caller created and owns. The client only opens a channel on it; close() never closes it. Pass the same one to a client and a worker to share a TCP connection explicitly.

A flat type rather than a union so Omit<…>-style wrappers keep working.

Properties ​

PropertyTypeDefined in
connection?AmqpConnectionManagerpackages/core/dist/index.d.mts:50
connectionOptions?AmqpConnectionManagerOptionspackages/core/dist/index.d.mts:49
urls?ConnectionUrl[]packages/core/dist/index.d.mts:48

CreateClientOptions ​

ts
type CreateClientOptions<TContract> = ConnectionSource & object;

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

Options for creating a client. The connection comes from urls (dialled and pooled — in a pool of its own, never shared with a worker) or from an explicit, caller-owned connection (see ConnectionSource).

Type Parameters ​

Type Parameter
TContract extends ContractDefinition

Type Declaration ​

NameTypeDescriptionDefined in
callInterceptors?readonly CallInterceptor[]Interceptors wrapping every call(...) round trip (request validation, publish, reply await): the first entry is the outermost.packages/client/src/client.ts:167
connectTimeoutMs?number | nullMaximum time in ms to wait for the AMQP connection to become ready before create() answers Err(ConnectionError). 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:144
contractTContract-packages/client/src/client.ts:124
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:137
logger?Logger-packages/client/src/client.ts:125
publishInterceptors?readonly PublishInterceptor[]Interceptors wrapping every publish(...): the first entry is the outermost. Each can patch the message/options, observe the outcome, retry by calling next again, or short-circuit. A patched message is validated exactly like the caller's original.packages/client/src/client.ts:162
publishTimeoutMs?number | nullMaximum time in ms a publish may sit buffered waiting for the broker before it fails with PublishError (reason "timeout", on the E channel). Maps to amqp-connection-manager's channel-level publishTimeout. Defaults to 30s (the AmqpClient's DEFAULT_PUBLISH_TIMEOUT_MS). Pass null to disable, restoring unbounded buffering — a publish issued during an outage then never settles. Applies to publish(...) and to the request publish of call(...) alike.packages/client/src/client.ts:155
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:131
topology?TopologyModeWhat the client does with its topology on every (re)connect. The client only touches what its publishes need to be routed AND retained: its publishers' exchanges, everything they route to (exchange-to-exchange bindings, transitively), every queue reachable that way with its binding, and the RPC request queues — so a message published before the worker started is kept, not dropped. Those queues get the worker's exact arguments but none of its infrastructure (no dead-letter exchange, no retry wait queues); unrelated and exclusive queues are never touched. - "assert" (default) — declare them. - "passive" — only check they exist; create() fails if one is missing. - "none" — touch nothing (topology is provisioned elsewhere).packages/client/src/client.ts:182

Logger ​

ts
type Logger = object;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:249

Logger interface for amqp-contract packages.

Provides a simple logging abstraction that can be implemented by users to integrate with their preferred logging framework.

Example ​

typescript
// Simple console logger implementation
const logger: Logger = {
  debug: (message, context) => console.debug(message, context),
  info: (message, context) => console.info(message, context),
  warn: (message, context) => console.warn(message, context),
  error: (message, context) => console.error(message, context),
};

Methods ​

debug() ​
ts
debug(message, context?): void;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:255

Log debug level messages

Parameters ​
ParameterTypeDescription
messagestringThe log message
context?LoggerContextOptional context to include with the log
Returns ​

void

error() ​
ts
error(message, context?): void;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:273

Log error level messages

Parameters ​
ParameterTypeDescription
messagestringThe log message
context?LoggerContextOptional context to include with the log
Returns ​

void

info() ​
ts
info(message, context?): void;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:261

Log info level messages

Parameters ​
ParameterTypeDescription
messagestringThe log message
context?LoggerContextOptional context to include with the log
Returns ​

void

warn() ​
ts
warn(message, context?): void;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:267

Log warning level messages

Parameters ​
ParameterTypeDescription
messagestringThe log message
context?LoggerContextOptional context to include with the log
Returns ​

void


LoggerContext ​

ts
type LoggerContext = Record<string, unknown> & object;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:229

Context object for logger methods.

This type includes reserved keys that provide consistent naming for common logging context properties.

Type Declaration ​

NameTypeDefined in
error?unknownpackages/core/dist/telemetry-U0DumV05.d.mts:230

PublishFailureReason ​

ts
type PublishFailureReason = "timeout" | "nacked" | "channel-closed";

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:82

Why the broker side of a publish failed — each one something core can actually observe on amqp-connection-manager's confirm channel:

  • "timeout" — no confirm arrived within publishTimeoutMs. Ambiguous: the message may have been written and be confirmed late, so republishing it can produce a duplicate. The worker's retry path accepts that (at-least-once): it requeues the original, and if the late copy did land in the wait queue, the handler runs twice.
  • "nacked" — the broker refused the message (basic.nack).
  • "channel-closed" — the channel closed before the message was confirmed.

PublishInterceptor ​

ts
type PublishInterceptor = (args, next) => AsyncResult<void, ClientPublishError>;

Defined in: packages/client/src/interceptors.ts:70

Intercepts client.publish(...): runs outside validation and publishing, so it can stamp headers (e.g. trace context), transform the payload, retry by calling next again, or short-circuit by returning without calling next. The first interceptor in the array is the outermost.

Parameters ​

ParameterType
argsPublishInterceptorArgs
nextPublishInterceptorNext

Returns ​

AsyncResult<void, ClientPublishError>

Example ​

Stamp a correlation header on every outgoing message

typescript
const stampTenant: PublishInterceptor = (args, next) =>
  next({
    options: {
      ...args.options,
      headers: { ...args.options.headers, 'x-tenant-id': currentTenant() },
    },
  });

PublishInterceptorArgs ​

ts
type PublishInterceptorArgs = object;

Defined in: packages/client/src/interceptors.ts:34

Arguments a publish interceptor observes. message is the pre-validation payload — a patched message goes through schema validation exactly like the caller's original.

Properties ​

PropertyTypeDescriptionDefined in
messageunknownThe (not yet validated) message payload.packages/client/src/interceptors.ts:38
optionsPublishOptionsPer-call publish options (defaults are merged later, inside the client).packages/client/src/interceptors.ts:40
publisherNamestringThe contract publishers key being published.packages/client/src/interceptors.ts:36

PublishInterceptorNext ​

ts
type PublishInterceptorNext = (patch?) => AsyncResult<void, ClientPublishError>;

Defined in: packages/client/src/interceptors.ts:48

Continuation a publish interceptor calls to run the rest of the chain. The optional patch replaces message and/or options for everything downstream (inner interceptors, validation, and the publish itself).

Parameters ​

ParameterType
patch?{ message?: unknown; options?: PublishOptions; }
patch.message?unknown
patch.options?PublishOptions

Returns ​

AsyncResult<void, ClientPublishError>


PublishOptions ​

ts
type PublishOptions = AmqpPublishOptions & object;

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

Publish options that extend core's AmqpPublishOptions 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:112

TelemetryProvider ​

ts
type TelemetryProvider = object;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:417

Telemetry provider for AMQP operations. Uses lazy loading to gracefully handle cases where OpenTelemetry is not installed.

Properties ​

PropertyTypeDescriptionDefined in
getConsumeCounter() => Counter | undefinedGet a counter for messages consumed. Returns undefined if OpenTelemetry is not available.packages/core/dist/telemetry-U0DumV05.d.mts:432
getConsumeLatencyHistogram() => Histogram | undefinedGet a histogram for consume/process latency. Returns undefined if OpenTelemetry is not available.packages/core/dist/telemetry-U0DumV05.d.mts:442
getLateRpcReplyCounter() => Counter | undefinedGet a counter for RPC replies that arrive after the caller has gone away (timeout, cancellation, or unknown correlationId). Returns undefined if OpenTelemetry is not available.packages/core/dist/telemetry-U0DumV05.d.mts:448
getPublishCounter() => Counter | undefinedGet a counter for messages published. Returns undefined if OpenTelemetry is not available.packages/core/dist/telemetry-U0DumV05.d.mts:427
getPublishLatencyHistogram() => Histogram | undefinedGet a histogram for publish latency. Returns undefined if OpenTelemetry is not available.packages/core/dist/telemetry-U0DumV05.d.mts:437
getRpcCallLatencyHistogram?() => Histogram | undefinedGet a histogram for RPC round-trip duration (request publish → validated reply), kept apart from the publish histogram so a slow handler does not read as a slow broker. Optional so an existing custom provider keeps compiling; omitted means "not recorded".packages/core/dist/telemetry-U0DumV05.d.mts:455
getTracer() => Tracer | undefinedGet a tracer instance for creating spans. Returns undefined if OpenTelemetry is not available.packages/core/dist/telemetry-U0DumV05.d.mts:422

TopologyMode ​

ts
type TopologyMode = "assert" | "passive" | "none";

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:287

What topology setup does with the contract's resources on (re)connect:

  • "assert" (default) — declare them (assertExchange / assertQueue, plus bindings): the broker creates what is missing and refuses a mismatch.
  • "passive" — only check they exist (checkExchange / checkQueue) and declare nothing, for an application whose credentials may not configure the broker; bindings cannot be checked passively and are skipped. A missing resource fails create().
  • "none" — touch nothing: topology is owned elsewhere (IaC, definitions import, another service).

Functions ​

isConnectionError() ​

ts
function isConnectionError(error): error is ConnectionError;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:143

Type guard to check if an error is a ConnectionError — the modeled failure of dialing the broker.

Parameters ​

ParameterType
errorunknown

Returns ​

error is ConnectionError


isMessageValidationError() ​

ts
function isMessageValidationError(error): error is MessageValidationError;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:147

Type guard to check if an error is a MessageValidationError.

Parameters ​

ParameterType
errorunknown

Returns ​

error is MessageValidationError


isRpcError() ​

ts
function isRpcError(error): error is RpcError<string, unknown>;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:194

Type guard to check if an error is an RpcError.

Narrowing to a specific code (and thus a typed data) is done on the code property after the guard, or via the error matcher on the _tag (matcher.with(P.tag("@amqp-contract/RpcError"), …)).

Parameters ​

ParameterType
errorunknown

Returns ​

error is RpcError<string, unknown>


isTechnicalError() ​

ts
function isTechnicalError(error): error is TechnicalError;

Defined in: packages/core/dist/telemetry-U0DumV05.d.mts:138

Type guard to check if an error is a TechnicalError — the cause carried by every infrastructure Defect this library produces.

Parameters ​

ParameterType
errorunknown

Returns ​

error is TechnicalError

Released under the MIT License.