@amqp-contract/client 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -1
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +20 -17
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
let _swan_io_boxed = require("@swan-io/boxed");
|
|
2
1
|
let _amqp_contract_core = require("@amqp-contract/core");
|
|
2
|
+
let _swan_io_boxed = require("@swan-io/boxed");
|
|
3
3
|
|
|
4
4
|
//#region src/errors.ts
|
|
5
5
|
/**
|
|
@@ -53,6 +53,9 @@ var TypedAmqpClient = class TypedAmqpClient {
|
|
|
53
53
|
* Connection management (including automatic reconnection) is handled internally
|
|
54
54
|
* by amqp-connection-manager via the {@link AmqpClient}. The client establishes
|
|
55
55
|
* infrastructure asynchronously in the background once the connection is ready.
|
|
56
|
+
*
|
|
57
|
+
* Connections are automatically shared across clients with the same URLs and
|
|
58
|
+
* connection options, following RabbitMQ best practices.
|
|
56
59
|
*/
|
|
57
60
|
static create({ contract, urls, connectionOptions, logger }) {
|
|
58
61
|
const client = new TypedAmqpClient(contract, new _amqp_contract_core.AmqpClient(contract, {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from "@amqp-contract/core";
|
|
2
|
+
import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
|
|
2
3
|
import { ContractDefinition, InferPublisherNames, PublisherDefinition } from "@amqp-contract/contract";
|
|
3
4
|
import { Future, Result } from "@swan-io/boxed";
|
|
4
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
|
-
import {
|
|
6
|
-
import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
|
|
6
|
+
import { Options } from "amqplib";
|
|
7
7
|
|
|
8
8
|
//#region src/errors.d.ts
|
|
9
9
|
/**
|
|
@@ -75,6 +75,9 @@ declare class TypedAmqpClient<TContract extends ContractDefinition> {
|
|
|
75
75
|
* Connection management (including automatic reconnection) is handled internally
|
|
76
76
|
* by amqp-connection-manager via the {@link AmqpClient}. The client establishes
|
|
77
77
|
* infrastructure asynchronously in the background once the connection is ready.
|
|
78
|
+
*
|
|
79
|
+
* Connections are automatically shared across clients with the same URLs and
|
|
80
|
+
* connection options, following RabbitMQ best practices.
|
|
78
81
|
*/
|
|
79
82
|
static create<TContract extends ContractDefinition>({
|
|
80
83
|
contract,
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;uBAGe,WAAA,SAAoB,KAAA;;;;;;AAkBnC;AAaa,cAbA,cAAA,SAAuB,WAAA,CAamB;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;uBAGe,WAAA,SAAoB,KAAA;;;;;;AAkBnC;AAaa,cAbA,cAAA,SAAuB,WAAA,CAamB;;;;AC7BO;;;AAM5C,cDuBL,sBAAA,SAA+B,WAAA,CCvB1B;EAAgB,SAAA,aAAA,EAAA,MAAA;EAK7B,SAAA,MAAA,EAAA,OAAmB;EAAoB,WAAA,CAAA,aAAA,EAAA,MAAA,EAAA,MAAA,EAAA,OAAA;;;;;;;KANvC,iCAAiC,oBACpC,gBAAgB;;;;ADUlB,KCLK,mBDKuB,CAAA,mBCLgB,mBDKG,CAAA,GCLoB,gBDKpB,CCJ7C,UDI6C,CAAA,SAAA,CAAA,CAAA,SAAA,CAAA,CAAA;AAa/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;EAApB;;;EACQ,KAAA,CAAA,CAAA,EC0Fb,MD1Fa,CC0FN,MD1FM,CAAA,IAAA,EC0FO,cD1FP,CAAA,CAAA;EAApB,QAAA,sBAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Future, Result } from "@swan-io/boxed";
|
|
2
1
|
import { Logger } from "@amqp-contract/core";
|
|
3
|
-
import {
|
|
2
|
+
import { Future, Result } from "@swan-io/boxed";
|
|
3
|
+
import { AmqpConnectionManagerOptions, ConnectionUrl } from "amqp-connection-manager";
|
|
4
4
|
import { ContractDefinition, InferPublisherNames, PublisherDefinition } from "@amqp-contract/contract";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
-
import {
|
|
6
|
+
import { Options } from "amqplib";
|
|
7
7
|
|
|
8
8
|
//#region src/errors.d.ts
|
|
9
9
|
/**
|
|
@@ -75,6 +75,9 @@ declare class TypedAmqpClient<TContract extends ContractDefinition> {
|
|
|
75
75
|
* Connection management (including automatic reconnection) is handled internally
|
|
76
76
|
* by amqp-connection-manager via the {@link AmqpClient}. The client establishes
|
|
77
77
|
* infrastructure asynchronously in the background once the connection is ready.
|
|
78
|
+
*
|
|
79
|
+
* Connections are automatically shared across clients with the same URLs and
|
|
80
|
+
* connection options, following RabbitMQ best practices.
|
|
78
81
|
*/
|
|
79
82
|
static create<TContract extends ContractDefinition>({
|
|
80
83
|
contract,
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;uBAGe,WAAA,SAAoB,KAAA;;;;;;AAkBnC;AAaa,cAbA,cAAA,SAAuB,WAAA,CAamB;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/client.ts"],"sourcesContent":[],"mappings":";;;;;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D,CCYqB,SDZrB,CAAA,CAAA,ECYkC,MDZlC,CCYyC,MDZzC,CCYgD,eDZhD,CCYgE,SDZhE,CAAA,ECY4E,cDZ5E,CAAA,CAAA;EAA2B;;AAK/B;;EAEoC,OAAA,CAAA,cCmBZ,mBDnBY,CCmBQ,SDnBR,CAAA,CAAA,CAAA,aAAA,ECoBjB,KDpBiB,EAAA,OAAA,ECqBvB,yBDrBuB,CCqBG,SDrBH,ECqBc,KDrBd,CAAA,EAAA,OAAA,CAAA,ECsBtB,OAAA,CAAQ,ODtBc,CAAA,ECuB/B,MDvB+B,CCuBxB,MDvBwB,CAAA,OAAA,ECuBR,cDvBQ,GCuBS,sBDvBT,CAAA,CAAA;EAApB;;;EACQ,KAAA,CAAA,CAAA,EC0Fb,MD1Fa,CC0FN,MD1FM,CAAA,IAAA,EC0FO,cD1FP,CAAA,CAAA;EAApB,QAAA,sBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Future, Result } from "@swan-io/boxed";
|
|
2
1
|
import { AmqpClient } from "@amqp-contract/core";
|
|
2
|
+
import { Future, Result } from "@swan-io/boxed";
|
|
3
3
|
|
|
4
4
|
//#region src/errors.ts
|
|
5
5
|
/**
|
|
@@ -53,6 +53,9 @@ var TypedAmqpClient = class TypedAmqpClient {
|
|
|
53
53
|
* Connection management (including automatic reconnection) is handled internally
|
|
54
54
|
* by amqp-connection-manager via the {@link AmqpClient}. The client establishes
|
|
55
55
|
* infrastructure asynchronously in the background once the connection is ready.
|
|
56
|
+
*
|
|
57
|
+
* Connections are automatically shared across clients with the same URLs and
|
|
58
|
+
* connection options, following RabbitMQ best practices.
|
|
56
59
|
*/
|
|
57
60
|
static create({ contract, urls, connectionOptions, logger }) {
|
|
58
61
|
const client = new TypedAmqpClient(contract, new AmqpClient(contract, {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["cause?: unknown","publisherName: string","issues: unknown","contract: TContract","amqpClient: AmqpClient","logger?: Logger"],"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["/**\n * Base error class for client errors\n */\nabstract class ClientError extends Error {\n protected constructor(message: string) {\n super(message);\n this.name = \"ClientError\";\n // Node.js specific stack trace capture\n const ErrorConstructor = Error as unknown as {\n captureStackTrace?: (target: object, constructor: Function) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(this, this.constructor);\n }\n }\n}\n\n/**\n * Error for technical/runtime failures that cannot be prevented by TypeScript\n * This includes validation failures and AMQP channel issues\n */\nexport class TechnicalError extends ClientError {\n constructor(\n message: string,\n public override readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"TechnicalError\";\n }\n}\n\n/**\n * Error thrown when message validation fails\n */\nexport class MessageValidationError extends ClientError {\n constructor(\n public readonly publisherName: string,\n public readonly issues: unknown,\n ) {\n super(`Message validation failed for publisher \"${publisherName}\"`);\n this.name = \"MessageValidationError\";\n }\n}\n","import type {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["cause?: unknown","publisherName: string","issues: unknown","contract: TContract","amqpClient: AmqpClient","logger?: Logger"],"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["/**\n * Base error class for client errors\n */\nabstract class ClientError extends Error {\n protected constructor(message: string) {\n super(message);\n this.name = \"ClientError\";\n // Node.js specific stack trace capture\n const ErrorConstructor = Error as unknown as {\n captureStackTrace?: (target: object, constructor: Function) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(this, this.constructor);\n }\n }\n}\n\n/**\n * Error for technical/runtime failures that cannot be prevented by TypeScript\n * This includes validation failures and AMQP channel issues\n */\nexport class TechnicalError extends ClientError {\n constructor(\n message: string,\n public override readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"TechnicalError\";\n }\n}\n\n/**\n * Error thrown when message validation fails\n */\nexport class MessageValidationError extends ClientError {\n constructor(\n public readonly publisherName: string,\n public readonly issues: unknown,\n ) {\n super(`Message validation failed for publisher \"${publisherName}\"`);\n this.name = \"MessageValidationError\";\n }\n}\n","import { AmqpClient, type Logger } from \"@amqp-contract/core\";\nimport type { AmqpConnectionManagerOptions, ConnectionUrl } from \"amqp-connection-manager\";\nimport type { ContractDefinition, InferPublisherNames } from \"@amqp-contract/contract\";\nimport { Future, Result } from \"@swan-io/boxed\";\nimport { MessageValidationError, TechnicalError } from \"./errors.js\";\nimport type { ClientInferPublisherInput } from \"./types.js\";\nimport type { Options } from \"amqplib\";\n\n/**\n * Options for creating a client\n */\nexport type CreateClientOptions<TContract extends ContractDefinition> = {\n contract: TContract;\n urls: ConnectionUrl[];\n connectionOptions?: AmqpConnectionManagerOptions | undefined;\n logger?: Logger | undefined;\n};\n\n/**\n * Type-safe AMQP client for publishing messages\n */\nexport class TypedAmqpClient<TContract extends ContractDefinition> {\n private constructor(\n private readonly contract: TContract,\n private readonly amqpClient: AmqpClient,\n private readonly logger?: Logger,\n ) {}\n\n /**\n * Create a type-safe AMQP client from a contract.\n *\n * Connection management (including automatic reconnection) is handled internally\n * by amqp-connection-manager via the {@link AmqpClient}. The client establishes\n * infrastructure asynchronously in the background once the connection is ready.\n *\n * Connections are automatically shared across clients with the same URLs and\n * connection options, following RabbitMQ best practices.\n */\n static create<TContract extends ContractDefinition>({\n contract,\n urls,\n connectionOptions,\n logger,\n }: CreateClientOptions<TContract>): Future<Result<TypedAmqpClient<TContract>, TechnicalError>> {\n const client = new TypedAmqpClient(\n contract,\n new AmqpClient(contract, { urls, connectionOptions }),\n logger,\n );\n\n return client.waitForConnectionReady().mapOk(() => client);\n }\n\n /**\n * Publish a message using a defined publisher\n * Returns Result.Ok(true) on success, or Result.Error with specific error on failure\n */\n publish<TName extends InferPublisherNames<TContract>>(\n publisherName: TName,\n message: ClientInferPublisherInput<TContract, TName>,\n options?: Options.Publish,\n ): Future<Result<boolean, TechnicalError | MessageValidationError>> {\n const publishers = this.contract.publishers;\n if (!publishers) {\n return Future.value(Result.Error(new TechnicalError(\"No publishers defined in contract\")));\n }\n\n const publisher = publishers[publisherName as string];\n if (!publisher) {\n return Future.value(\n Result.Error(\n new TechnicalError(`Publisher \"${String(publisherName)}\" not found in contract`),\n ),\n );\n }\n\n const validateMessage = () => {\n const validationResult = publisher.message.payload[\"~standard\"].validate(message);\n return Future.fromPromise(\n validationResult instanceof Promise ? validationResult : Promise.resolve(validationResult),\n )\n .mapError((error) => new TechnicalError(`Validation failed`, error))\n .mapOkToResult((validation) => {\n if (validation.issues) {\n return Result.Error(\n new MessageValidationError(String(publisherName), validation.issues),\n );\n }\n\n return Result.Ok(validation.value);\n });\n };\n\n const publishMessage = (validatedMessage: unknown) => {\n return Future.fromPromise(\n this.amqpClient.channel.publish(\n publisher.exchange.name,\n publisher.routingKey ?? \"\",\n validatedMessage,\n options,\n ),\n )\n .mapError((error) => new TechnicalError(`Failed to publish message`, error))\n .mapOkToResult((published) => {\n if (!published) {\n return Result.Error(\n new TechnicalError(\n `Failed to publish message for publisher \"${String(publisherName)}\": Channel rejected the message (buffer full or other channel issue)`,\n ),\n );\n }\n\n this.logger?.info(\"Message published successfully\", {\n publisherName: String(publisherName),\n exchange: publisher.exchange.name,\n routingKey: publisher.routingKey,\n });\n\n return Result.Ok(published);\n });\n };\n\n // Validate message using schema\n return validateMessage().flatMapOk((validatedMessage) => publishMessage(validatedMessage));\n }\n\n /**\n * Close the channel and connection\n */\n close(): Future<Result<void, TechnicalError>> {\n return Future.fromPromise(this.amqpClient.close())\n .mapError((error) => new TechnicalError(\"Failed to close AMQP connection\", error))\n .mapOk(() => undefined);\n }\n\n private waitForConnectionReady(): Future<Result<void, TechnicalError>> {\n return Future.fromPromise(this.amqpClient.channel.waitForConnect()).mapError(\n (error) => new TechnicalError(\"Failed to wait for connection ready\", error),\n );\n }\n}\n"],"mappings":";;;;;;;AAGA,IAAe,cAAf,cAAmC,MAAM;CACvC,AAAU,YAAY,SAAiB;AACrC,Q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OACb,QAAO,OAAO,MACZ,IAAI,uBAAuB,OAAO,cAAc,EAAE,WAAW,OAAO,CACrE;AAGH,WAAO,OAAO,GAAG,WAAW,MAAM;KAClC;;EAGN,MAAM,kBAAkB,qBAA8B;AACpD,UAAO,OAAO,YACZ,KAAK,WAAW,QAAQ,QACtB,UAAU,SAAS,MACnB,UAAU,cAAc,IACxB,kBACA,QACD,CACF,CACE,UAAU,UAAU,IAAI,eAAe,6BAA6B,MAAM,CAAC,CAC3E,eAAe,cAAc;AAC5B,QAAI,CAAC,UACH,QAAO,OAAO,MACZ,IAAI,eACF,4CAA4C,OAAO,cAAc,CAAC,sEACnE,CACF;AAGH,SAAK,QAAQ,KAAK,kCAAkC;KAClD,eAAe,OAAO,cAAc;KACpC,UAAU,UAAU,SAAS;KAC7B,YAAY,UAAU;KACvB,CAAC;AAEF,WAAO,OAAO,GAAG,UAAU;KAC3B;;AAIN,SAAO,iBAAiB,CAAC,WAAW,qBAAqB,eAAe,iBAAiB,CAAC;;;;;CAM5F,QAA8C;AAC5C,SAAO,OAAO,YAAY,KAAK,WAAW,OAAO,CAAC,CAC/C,UAAU,UAAU,IAAI,eAAe,mCAAmC,MAAM,CAAC,CACjF,YAAY,OAAU;;CAG3B,AAAQ,yBAA+D;AACrE,SAAO,OAAO,YAAY,KAAK,WAAW,QAAQ,gBAAgB,CAAC,CAAC,UACjE,UAAU,IAAI,eAAe,uCAAuC,MAAM,CAC5E"}
|
package/docs/index.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
### MessageValidationError
|
|
10
10
|
|
|
11
|
-
Defined in: [packages/client/src/errors.ts:35](https://github.com/btravers/amqp-contract/blob/
|
|
11
|
+
Defined in: [packages/client/src/errors.ts:35](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/errors.ts#L35)
|
|
12
12
|
|
|
13
13
|
Error thrown when message validation fails
|
|
14
14
|
|
|
@@ -24,7 +24,7 @@ Error thrown when message validation fails
|
|
|
24
24
|
new MessageValidationError(publisherName, issues): MessageValidationError;
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Defined in: [packages/client/src/errors.ts:36](https://github.com/btravers/amqp-contract/blob/
|
|
27
|
+
Defined in: [packages/client/src/errors.ts:36](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/errors.ts#L36)
|
|
28
28
|
|
|
29
29
|
###### Parameters
|
|
30
30
|
|
|
@@ -48,10 +48,10 @@ ClientError.constructor
|
|
|
48
48
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
49
49
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
50
50
|
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `ClientError.cause` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:26 |
|
|
51
|
-
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | [packages/client/src/errors.ts:38](https://github.com/btravers/amqp-contract/blob/
|
|
51
|
+
| <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | [packages/client/src/errors.ts:38](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/errors.ts#L38) |
|
|
52
52
|
| <a id="message"></a> `message` | `public` | `string` | - | `ClientError.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
53
53
|
| <a id="name"></a> `name` | `public` | `string` | - | `ClientError.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
54
|
-
| <a id="publishername"></a> `publisherName` | `readonly` | `string` | - | - | [packages/client/src/errors.ts:37](https://github.com/btravers/amqp-contract/blob/
|
|
54
|
+
| <a id="publishername"></a> `publisherName` | `readonly` | `string` | - | - | [packages/client/src/errors.ts:37](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/errors.ts#L37) |
|
|
55
55
|
| <a id="stack"></a> `stack?` | `public` | `string` | - | `ClientError.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
56
56
|
| <a id="stacktracelimit"></a> `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 |
|
|
57
57
|
|
|
@@ -159,7 +159,7 @@ ClientError.prepareStackTrace
|
|
|
159
159
|
|
|
160
160
|
### TechnicalError
|
|
161
161
|
|
|
162
|
-
Defined in: [packages/client/src/errors.ts:22](https://github.com/btravers/amqp-contract/blob/
|
|
162
|
+
Defined in: [packages/client/src/errors.ts:22](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/errors.ts#L22)
|
|
163
163
|
|
|
164
164
|
Error for technical/runtime failures that cannot be prevented by TypeScript
|
|
165
165
|
This includes validation failures and AMQP channel issues
|
|
@@ -176,7 +176,7 @@ This includes validation failures and AMQP channel issues
|
|
|
176
176
|
new TechnicalError(message, cause?): TechnicalError;
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
Defined in: [packages/client/src/errors.ts:23](https://github.com/btravers/amqp-contract/blob/
|
|
179
|
+
Defined in: [packages/client/src/errors.ts:23](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/errors.ts#L23)
|
|
180
180
|
|
|
181
181
|
###### Parameters
|
|
182
182
|
|
|
@@ -199,7 +199,7 @@ ClientError.constructor
|
|
|
199
199
|
|
|
200
200
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
201
201
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
202
|
-
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `ClientError.cause` | [packages/client/src/errors.ts:25](https://github.com/btravers/amqp-contract/blob/
|
|
202
|
+
| <a id="cause-1"></a> `cause?` | `readonly` | `unknown` | - | `ClientError.cause` | [packages/client/src/errors.ts:25](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/errors.ts#L25) |
|
|
203
203
|
| <a id="message-1"></a> `message` | `public` | `string` | - | `ClientError.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
|
|
204
204
|
| <a id="name-1"></a> `name` | `public` | `string` | - | `ClientError.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
205
205
|
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `ClientError.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
|
|
@@ -309,7 +309,7 @@ ClientError.prepareStackTrace
|
|
|
309
309
|
|
|
310
310
|
### TypedAmqpClient
|
|
311
311
|
|
|
312
|
-
Defined in: [packages/client/src/client.ts:22](https://github.com/btravers/amqp-contract/blob/
|
|
312
|
+
Defined in: [packages/client/src/client.ts:22](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L22)
|
|
313
313
|
|
|
314
314
|
Type-safe AMQP client for publishing messages
|
|
315
315
|
|
|
@@ -327,7 +327,7 @@ Type-safe AMQP client for publishing messages
|
|
|
327
327
|
close(): Future<Result<void, TechnicalError>>;
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
-
Defined in: [packages/client/src/client.ts:
|
|
330
|
+
Defined in: [packages/client/src/client.ts:130](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L130)
|
|
331
331
|
|
|
332
332
|
Close the channel and connection
|
|
333
333
|
|
|
@@ -346,7 +346,7 @@ publish<TName>(
|
|
|
346
346
|
| MessageValidationError>>;
|
|
347
347
|
```
|
|
348
348
|
|
|
349
|
-
Defined in: [packages/client/src/client.ts:
|
|
349
|
+
Defined in: [packages/client/src/client.ts:58](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L58)
|
|
350
350
|
|
|
351
351
|
Publish a message using a defined publisher
|
|
352
352
|
Returns Result.Ok(true) on success, or Result.Error with specific error on failure
|
|
@@ -377,7 +377,7 @@ Returns Result.Ok(true) on success, or Result.Error with specific error on failu
|
|
|
377
377
|
static create<TContract>(__namedParameters): Future<Result<TypedAmqpClient<TContract>, TechnicalError>>;
|
|
378
378
|
```
|
|
379
379
|
|
|
380
|
-
Defined in: [packages/client/src/client.ts:
|
|
380
|
+
Defined in: [packages/client/src/client.ts:39](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L39)
|
|
381
381
|
|
|
382
382
|
Create a type-safe AMQP client from a contract.
|
|
383
383
|
|
|
@@ -385,6 +385,9 @@ Connection management (including automatic reconnection) is handled internally
|
|
|
385
385
|
by amqp-connection-manager via the AmqpClient. The client establishes
|
|
386
386
|
infrastructure asynchronously in the background once the connection is ready.
|
|
387
387
|
|
|
388
|
+
Connections are automatically shared across clients with the same URLs and
|
|
389
|
+
connection options, following RabbitMQ best practices.
|
|
390
|
+
|
|
388
391
|
###### Type Parameters
|
|
389
392
|
|
|
390
393
|
| Type Parameter |
|
|
@@ -409,7 +412,7 @@ infrastructure asynchronously in the background once the connection is ready.
|
|
|
409
412
|
type ClientInferPublisherInput<TContract, TName> = PublisherInferInput<InferPublisher<TContract, TName>>;
|
|
410
413
|
```
|
|
411
414
|
|
|
412
|
-
Defined in: [packages/client/src/types.ts:37](https://github.com/btravers/amqp-contract/blob/
|
|
415
|
+
Defined in: [packages/client/src/types.ts:37](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/types.ts#L37)
|
|
413
416
|
|
|
414
417
|
Infer publisher input type (message payload) for a specific publisher in a contract
|
|
415
418
|
|
|
@@ -428,7 +431,7 @@ Infer publisher input type (message payload) for a specific publisher in a contr
|
|
|
428
431
|
type CreateClientOptions<TContract> = object;
|
|
429
432
|
```
|
|
430
433
|
|
|
431
|
-
Defined in: [packages/client/src/client.ts:12](https://github.com/btravers/amqp-contract/blob/
|
|
434
|
+
Defined in: [packages/client/src/client.ts:12](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L12)
|
|
432
435
|
|
|
433
436
|
Options for creating a client
|
|
434
437
|
|
|
@@ -442,7 +445,7 @@ Options for creating a client
|
|
|
442
445
|
|
|
443
446
|
| Property | Type | Defined in |
|
|
444
447
|
| ------ | ------ | ------ |
|
|
445
|
-
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | [packages/client/src/client.ts:15](https://github.com/btravers/amqp-contract/blob/
|
|
446
|
-
| <a id="contract"></a> `contract` | `TContract` | [packages/client/src/client.ts:13](https://github.com/btravers/amqp-contract/blob/
|
|
447
|
-
| <a id="logger"></a> `logger?` | `Logger` | [packages/client/src/client.ts:16](https://github.com/btravers/amqp-contract/blob/
|
|
448
|
-
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | [packages/client/src/client.ts:14](https://github.com/btravers/amqp-contract/blob/
|
|
448
|
+
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | [packages/client/src/client.ts:15](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L15) |
|
|
449
|
+
| <a id="contract"></a> `contract` | `TContract` | [packages/client/src/client.ts:13](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L13) |
|
|
450
|
+
| <a id="logger"></a> `logger?` | `Logger` | [packages/client/src/client.ts:16](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L16) |
|
|
451
|
+
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | [packages/client/src/client.ts:14](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/client/src/client.ts#L14) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amqp-contract/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Client utilities for publishing messages using amqp-contract",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"amqp",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@standard-schema/spec": "1.1.0",
|
|
46
46
|
"@swan-io/boxed": "3.2.1",
|
|
47
|
-
"@amqp-contract/contract": "0.
|
|
48
|
-
"@amqp-contract/core": "0.
|
|
47
|
+
"@amqp-contract/contract": "0.4.0",
|
|
48
|
+
"@amqp-contract/core": "0.4.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/amqplib": "0.10.8",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"typescript": "5.9.3",
|
|
60
60
|
"vitest": "4.0.16",
|
|
61
61
|
"zod": "4.2.1",
|
|
62
|
-
"@amqp-contract/testing": "0.
|
|
62
|
+
"@amqp-contract/testing": "0.4.0",
|
|
63
63
|
"@amqp-contract/tsconfig": "0.0.0",
|
|
64
64
|
"@amqp-contract/typedoc": "0.0.1"
|
|
65
65
|
},
|