**@amqp-contract/client**

***

# @amqp-contract/client

## Classes

### MessageValidationError

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

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`&lt;\{
  `issues`: `unknown`;
  `source`: `string`;
\}&gt;

#### Constructors

##### Constructor

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

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

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |
| `issues` | `unknown` |

###### Returns

[`MessageValidationError`](#messagevalidationerror)

###### Overrides

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

#### Properties

| Property | Modifier | Type | Inherited from | Defined in |
| ------ | ------ | ------ | ------ | ------ |
| <a id="_tag"></a> `_tag` | `readonly` | `"@amqp-contract/MessageValidationError"` | `MessageValidationError_base._tag` | node\_modules/.pnpm/unthrown@4.1.0/node\_modules/unthrown/dist/index.d.mts:1456 |
| <a id="cause"></a> `cause?` | `public` | `unknown` | `MessageValidationError_base.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
| <a id="issues"></a> `issues` | `readonly` | `unknown` | `MessageValidationError_base.issues` | packages/core/dist/index.d.mts:41 |
| <a id="message"></a> `message` | `public` | `string` | `MessageValidationError_base.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
| <a id="name"></a> `name` | `public` | `string` | `MessageValidationError_base.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
| <a id="source"></a> `source` | `readonly` | `string` | `MessageValidationError_base.source` | packages/core/dist/index.d.mts:40 |
| <a id="stack"></a> `stack?` | `public` | `string` | `MessageValidationError_base.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |

***

### RpcCancelledError

Defined in: [packages/client/src/errors.ts:34](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/errors.ts#L34)

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`&lt;`"@amqp-contract/RpcCancelledError"`, \{
  `rpcName`: `string`;
\}&gt;

#### Constructors

##### Constructor

```ts
new RpcCancelledError(rpcName): RpcCancelledError;
```

Defined in: [packages/client/src/errors.ts:39](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/errors.ts#L39)

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `rpcName` | `string` |

###### Returns

[`RpcCancelledError`](#rpccancellederror)

###### Overrides

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

#### Properties

| Property | Modifier | Type | Inherited from | Defined in |
| ------ | ------ | ------ | ------ | ------ |
| <a id="_tag-1"></a> `_tag` | `readonly` | `"@amqp-contract/RpcCancelledError"` | `TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", })._tag` | node\_modules/.pnpm/unthrown@4.1.0/node\_modules/unthrown/dist/index.d.mts:1456 |
| <a id="cause-1"></a> `cause?` | `public` | `unknown` | `TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
| <a id="message-1"></a> `message` | `public` | `string` | `TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
| <a id="name-1"></a> `name` | `public` | `string` | `TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
| <a id="rpcname"></a> `rpcName` | `readonly` | `string` | `TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).rpcName` | [packages/client/src/errors.ts:37](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/errors.ts#L37) |
| <a id="stack-1"></a> `stack?` | `public` | `string` | `TaggedError("@amqp-contract/RpcCancelledError", { name: "RpcCancelledError", }).stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |

***

### RpcError

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

A typed, contract-declared RPC error — the business-failure channel of an
RPC, as opposed to the transport failures modeled by TechnicalError.

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
`matchTags`; the `Error.name` is kept bare (`"RpcError"`). Discriminate
between codes on the `code` property.

#### Extends

- `RpcError_base`&lt;\{
  `code`: `string`;
  `data`: `unknown`;
\}&gt;

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TCode` *extends* `string` | `string` |
| `TData` | `unknown` |

#### Constructors

##### Constructor

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

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

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `code` | `TCode` |
| `data` | `TData` |
| `message?` | `string` |

###### Returns

[`RpcError`](#rpcerror)&lt;`TCode`, `TData`&gt;

###### Overrides

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

#### Properties

| Property | Modifier | Type | Overrides | Inherited from | Defined in |
| ------ | ------ | ------ | ------ | ------ | ------ |
| <a id="_tag-2"></a> `_tag` | `readonly` | `"@amqp-contract/RpcError"` | - | `RpcError_base._tag` | node\_modules/.pnpm/unthrown@4.1.0/node\_modules/unthrown/dist/index.d.mts:1456 |
| <a id="cause-2"></a> `cause?` | `public` | `unknown` | - | `RpcError_base.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
| <a id="code"></a> `code` | `readonly` | `TCode` | `RpcError_base.code` | - | packages/core/dist/index.d.mts:76 |
| <a id="data"></a> `data` | `readonly` | `TData` | `RpcError_base.data` | - | packages/core/dist/index.d.mts:77 |
| <a id="message-2"></a> `message` | `public` | `string` | - | `RpcError_base.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
| <a id="name-2"></a> `name` | `public` | `string` | - | `RpcError_base.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
| <a id="stack-2"></a> `stack?` | `public` | `string` | - | `RpcError_base.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |

***

### RpcTimeoutError

Defined in: [packages/client/src/errors.ts:15](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/errors.ts#L15)

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`&lt;`"@amqp-contract/RpcTimeoutError"`, \{
  `rpcName`: `string`;
  `timeoutMs`: `number`;
\}&gt;

#### Constructors

##### Constructor

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

Defined in: [packages/client/src/errors.ts:21](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/errors.ts#L21)

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `rpcName` | `string` |
| `timeoutMs` | `number` |

###### Returns

[`RpcTimeoutError`](#rpctimeouterror)

###### Overrides

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

#### Properties

| Property | Modifier | Type | Inherited from | Defined in |
| ------ | ------ | ------ | ------ | ------ |
| <a id="_tag-3"></a> `_tag` | `readonly` | `"@amqp-contract/RpcTimeoutError"` | `TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", })._tag` | node\_modules/.pnpm/unthrown@4.1.0/node\_modules/unthrown/dist/index.d.mts:1456 |
| <a id="cause-3"></a> `cause?` | `public` | `unknown` | `TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
| <a id="message-3"></a> `message` | `public` | `string` | `TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
| <a id="name-3"></a> `name` | `public` | `string` | `TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
| <a id="rpcname-1"></a> `rpcName` | `readonly` | `string` | `TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).rpcName` | [packages/client/src/errors.ts:18](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/errors.ts#L18) |
| <a id="stack-3"></a> `stack?` | `public` | `string` | `TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
| <a id="timeoutms"></a> `timeoutMs` | `readonly` | `number` | `TaggedError("@amqp-contract/RpcTimeoutError", { name: "RpcTimeoutError", }).timeoutMs` | [packages/client/src/errors.ts:19](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/errors.ts#L19) |

***

### TypedAmqpClient

Defined in: [packages/client/src/client.ts:166](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L166)

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>, 
  | TechnicalError
  | MessageValidationError
  | RpcTimeoutError
  | RpcCancelledError
  | ClientInferRpcErrors<TContract, TName>>;
```

Defined in: [packages/client/src/client.ts:565](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L565)

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

| Parameter | Type |
| ------ | ------ |
| `rpcName` | `TName` |
| `request` | [`ClientInferRpcRequestInput`](#clientinferrpcrequestinput)&lt;`TContract`, `TName`&gt; |
| `options` | [`CallOptions`](#calloptions) |

###### Returns

`AsyncResult`&lt;[`ClientInferRpcResponseOutput`](#clientinferrpcresponseoutput)&lt;`TContract`, `TName`&gt;, 
  \| `TechnicalError`
  \| [`MessageValidationError`](#messagevalidationerror)
  \| [`RpcTimeoutError`](#rpctimeouterror)
  \| [`RpcCancelledError`](#rpccancellederror)
  \| [`ClientInferRpcErrors`](#clientinferrpcerrors)&lt;`TContract`, `TName`&gt;&gt;

###### Example

```typescript
const result = await client.call('calculate', { a: 1, b: 2 }, { timeoutMs: 5_000 });
result.match({
  ok: (value) => console.log(value.sum), // 3
  err: (error) => console.error(error),
  defect: (cause) => console.error(cause),
});
```

##### close()

```ts
close(): AsyncResult<void, TechnicalError>;
```

Defined in: [packages/client/src/client.ts:765](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L765)

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

###### Returns

`AsyncResult`&lt;`void`, `TechnicalError`&gt;

##### publish()

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

Defined in: [packages/client/src/client.ts:431](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L431)

Publish a message using a defined publisher.

###### Type Parameters

| Type Parameter |
| ------ |
| `TName` *extends* `string` \| `number` \| `symbol` |

###### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `publisherName` | `TName` | The name of the publisher to use |
| `message` | [`ClientInferPublisherInput`](#clientinferpublisherinput)&lt;`TContract`, `TName`&gt; | The message to publish |
| `options?` | [`PublishOptions`](#publishoptions-1) | Optional publish options including compression, headers, priority, etc. |

###### Returns

`AsyncResult`&lt;`void`, `TechnicalError` \| [`MessageValidationError`](#messagevalidationerror)&gt;

###### 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): AsyncResult<TypedAmqpClient<TContract>, TechnicalError>;
```

Defined in: [packages/client/src/client.ts:199](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L199)

Create a type-safe AMQP client from a contract.

Connection management (including automatic reconnection) is handled internally
by amqp-connection-manager via the [AmqpClient](https://btravstack.github.io/amqp-contract/api/core#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`](#createclientoptions)&lt;`TContract`&gt; |

###### Returns

`AsyncResult`&lt;[`TypedAmqpClient`](#typedamqpclient)&lt;`TContract`&gt;, `TechnicalError`&gt;

## Type Aliases

### CallInterceptor

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

Defined in: [packages/client/src/interceptors.ts:106](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L106)

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

| Parameter | Type |
| ------ | ------ |
| `args` | [`CallInterceptorArgs`](#callinterceptorargs) |
| `next` | [`CallInterceptorNext`](#callinterceptornext) |

#### Returns

`AsyncResult`&lt;`unknown`, `CallError`&gt;

#### Example

**Retry timed-out calls once**

```typescript
const retryOnce: CallInterceptor = (args, next) =>
  next().flatMapErr((error) =>
    error instanceof RpcTimeoutError ? next() : ErrAsync(error),
  );
```

***

### CallInterceptorArgs

```ts
type CallInterceptorArgs = object;
```

Defined in: [packages/client/src/interceptors.ts:74](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L74)

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

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="options"></a> `options` | [`CallOptions`](#calloptions) | Per-call options (`timeoutMs`, `publishOptions`). | [packages/client/src/interceptors.ts:80](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L80) |
| <a id="request"></a> `request` | `unknown` | The (not yet validated) request payload. | [packages/client/src/interceptors.ts:78](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L78) |
| <a id="rpcname-2"></a> `rpcName` | `string` | The contract `rpcs` key being called. | [packages/client/src/interceptors.ts:76](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L76) |

***

### CallInterceptorNext

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

Defined in: [packages/client/src/interceptors.ts:87](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L87)

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

| Parameter | Type |
| ------ | ------ |
| `patch?` | \{ `options?`: [`CallOptions`](#calloptions); `request?`: `unknown`; \} |
| `patch.options?` | [`CallOptions`](#calloptions) |
| `patch.request?` | `unknown` |

#### Returns

`AsyncResult`&lt;`unknown`, `CallError`&gt;

***

### CallOptions

```ts
type CallOptions = object;
```

Defined in: [packages/client/src/client.ts:146](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L146)

Per-call options for `client.call()`.

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="publishoptions"></a> `publishOptions?` | `Omit`&lt;`AmqpClientPublishOptions`, `"replyTo"` \| `"correlationId"`&gt; | 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:160](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L160) |
| <a id="timeoutms-1"></a> `timeoutMs` | `number` | Maximum 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:154](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L154) |

***

### ClientInferPublisherInput

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

Defined in: [packages/client/src/types.ts:46](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/types.ts#L46)

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

#### Type Parameters

| Type Parameter |
| ------ |
| `TContract` *extends* `ContractDefinition` |
| `TName` *extends* `InferPublisherNames`&lt;`TContract`&gt; |

***

### ClientInferRpcErrors

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

Defined in: [packages/client/src/types.ts:94](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/types.ts#L94)

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`&lt;`TContract`&gt; |

***

### 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:64](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/types.ts#L64)

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

#### Type Parameters

| Type Parameter |
| ------ |
| `TContract` *extends* `ContractDefinition` |
| `TName` *extends* `InferRpcNames`&lt;`TContract`&gt; |

***

### 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:77](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/types.ts#L77)

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

#### Type Parameters

| Type Parameter |
| ------ |
| `TContract` *extends* `ContractDefinition` |
| `TName` *extends* `InferRpcNames`&lt;`TContract`&gt; |

***

### CreateClientOptions

```ts
type CreateClientOptions<TContract> = object;
```

Defined in: [packages/client/src/client.ts:105](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L105)

Options for creating a client

#### Type Parameters

| Type Parameter |
| ------ |
| `TContract` *extends* `ContractDefinition` |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="callinterceptors"></a> `callInterceptors?` | readonly [`CallInterceptor`](#callinterceptor)[] | Interceptors wrapping every `call(...)` round trip (request validation, publish, reply await): the first entry is the outermost. | [packages/client/src/client.ts:140](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L140) |
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | - | [packages/client/src/client.ts:108](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L108) |
| <a id="connecttimeoutms"></a> `connectTimeoutMs?` | `number` \| `null` | Maximum time in ms to wait for the AMQP connection to become ready before `create()` resolves to an `Err(TechnicalError)`. Defaults to 30s (the [AmqpClient](https://btravstack.github.io/amqp-contract/api/core#amqpclient)'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to disable the timeout and let amqp-connection-manager retry indefinitely. | [packages/client/src/client.ts:128](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L128) |
| <a id="contract"></a> `contract` | `TContract` | - | [packages/client/src/client.ts:106](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L106) |
| <a id="defaultpublishoptions"></a> `defaultPublishOptions?` | [`PublishOptions`](#publishoptions-1) | Default 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:121](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L121) |
| <a id="logger"></a> `logger?` | `Logger` | - | [packages/client/src/client.ts:109](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L109) |
| <a id="publishinterceptors"></a> `publishInterceptors?` | readonly [`PublishInterceptor`](#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:135](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L135) |
| <a id="telemetry"></a> `telemetry?` | `TelemetryProvider` | Optional 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:115](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L115) |
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | - | [packages/client/src/client.ts:107](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L107) |

***

### PublishInterceptor

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

Defined in: [packages/client/src/interceptors.ts:65](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L65)

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

| Parameter | Type |
| ------ | ------ |
| `args` | [`PublishInterceptorArgs`](#publishinterceptorargs) |
| `next` | [`PublishInterceptorNext`](#publishinterceptornext) |

#### Returns

`AsyncResult`&lt;`void`, `PublishError`&gt;

#### 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:29](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L29)

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

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="message-4"></a> `message` | `unknown` | The (not yet validated) message payload. | [packages/client/src/interceptors.ts:33](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L33) |
| <a id="options-1"></a> `options` | [`PublishOptions`](#publishoptions-1) | Per-call publish options (defaults are merged later, inside the client). | [packages/client/src/interceptors.ts:35](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L35) |
| <a id="publishername"></a> `publisherName` | `string` | The contract `publishers` key being published. | [packages/client/src/interceptors.ts:31](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L31) |

***

### PublishInterceptorNext

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

Defined in: [packages/client/src/interceptors.ts:43](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/interceptors.ts#L43)

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

| Parameter | Type |
| ------ | ------ |
| `patch?` | \{ `message?`: `unknown`; `options?`: [`PublishOptions`](#publishoptions-1); \} |
| `patch.message?` | `unknown` |
| `patch.options?` | [`PublishOptions`](#publishoptions-1) |

#### Returns

`AsyncResult`&lt;`void`, `PublishError`&gt;

***

### PublishOptions

```ts
type PublishOptions = AmqpClientPublishOptions & object;
```

Defined in: [packages/client/src/client.ts:93](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L93)

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

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `compression?` | `CompressionAlgorithm` | Optional 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:99](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/client/src/client.ts#L99) |

## Functions

### isRpcError()

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

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

Type guard to check if an error is an [RpcError](#rpcerror).

Narrowing to a specific code (and thus a typed `data`) is done on the
`code` property after the guard, or via `matchTags` on the `_tag`.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `error` | `unknown` |

#### Returns

`error is RpcError<string, unknown>`
