@amqp-contract/client 0.19.0 → 0.21.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 CHANGED
@@ -1,10 +1,9 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _amqp_contract_core = require("@amqp-contract/core");
3
3
  let _swan_io_boxed = require("@swan-io/boxed");
4
4
  let node_zlib = require("node:zlib");
5
5
  let ts_pattern = require("ts-pattern");
6
6
  let node_util = require("node:util");
7
-
8
7
  //#region src/compression.ts
9
8
  const gzipAsync = (0, node_util.promisify)(node_zlib.gzip);
10
9
  const deflateAsync = (0, node_util.promisify)(node_zlib.deflate);
@@ -20,16 +19,16 @@ const deflateAsync = (0, node_util.promisify)(node_zlib.deflate);
20
19
  function compressBuffer(buffer, algorithm) {
21
20
  return (0, ts_pattern.match)(algorithm).with("gzip", () => _swan_io_boxed.Future.fromPromise(gzipAsync(buffer)).mapError((error) => new _amqp_contract_core.TechnicalError("Failed to compress with gzip", error))).with("deflate", () => _swan_io_boxed.Future.fromPromise(deflateAsync(buffer)).mapError((error) => new _amqp_contract_core.TechnicalError("Failed to compress with deflate", error))).exhaustive();
22
21
  }
23
-
24
22
  //#endregion
25
23
  //#region src/client.ts
26
24
  /**
27
25
  * Type-safe AMQP client for publishing messages
28
26
  */
29
27
  var TypedAmqpClient = class TypedAmqpClient {
30
- constructor(contract, amqpClient, logger, telemetry = _amqp_contract_core.defaultTelemetryProvider) {
28
+ constructor(contract, amqpClient, defaultPublishOptions, logger, telemetry = _amqp_contract_core.defaultTelemetryProvider) {
31
29
  this.contract = contract;
32
30
  this.amqpClient = amqpClient;
31
+ this.defaultPublishOptions = defaultPublishOptions;
33
32
  this.logger = logger;
34
33
  this.telemetry = telemetry;
35
34
  }
@@ -43,11 +42,14 @@ var TypedAmqpClient = class TypedAmqpClient {
43
42
  * Connections are automatically shared across clients with the same URLs and
44
43
  * connection options, following RabbitMQ best practices.
45
44
  */
46
- static create({ contract, urls, connectionOptions, logger, telemetry }) {
45
+ static create({ contract, urls, connectionOptions, defaultPublishOptions, logger, telemetry }) {
47
46
  const client = new TypedAmqpClient(contract, new _amqp_contract_core.AmqpClient(contract, {
48
47
  urls,
49
48
  connectionOptions
50
- }), logger, telemetry ?? _amqp_contract_core.defaultTelemetryProvider);
49
+ }), {
50
+ persistent: true,
51
+ ...defaultPublishOptions
52
+ }, logger, telemetry ?? _amqp_contract_core.defaultTelemetryProvider);
51
53
  return client.waitForConnectionReady().mapOk(() => client);
52
54
  }
53
55
  /**
@@ -81,7 +83,10 @@ var TypedAmqpClient = class TypedAmqpClient {
81
83
  });
82
84
  };
83
85
  const publishMessage = (validatedMessage) => {
84
- const { compression, ...restOptions } = options ?? {};
86
+ const { compression, ...restOptions } = {
87
+ ...this.defaultPublishOptions,
88
+ ...options
89
+ };
85
90
  const publishOptions = { ...restOptions };
86
91
  const preparePayload = () => {
87
92
  if (compression) {
@@ -122,12 +127,11 @@ var TypedAmqpClient = class TypedAmqpClient {
122
127
  return this.amqpClient.waitForConnect();
123
128
  }
124
129
  };
125
-
126
130
  //#endregion
127
- Object.defineProperty(exports, 'MessageValidationError', {
128
- enumerable: true,
129
- get: function () {
130
- return _amqp_contract_core.MessageValidationError;
131
- }
131
+ Object.defineProperty(exports, "MessageValidationError", {
132
+ enumerable: true,
133
+ get: function() {
134
+ return _amqp_contract_core.MessageValidationError;
135
+ }
132
136
  });
133
- exports.TypedAmqpClient = TypedAmqpClient;
137
+ exports.TypedAmqpClient = TypedAmqpClient;
package/dist/index.d.cts CHANGED
@@ -1,13 +1,12 @@
1
- import { Logger, MessageValidationError, TechnicalError, TelemetryProvider } from "@amqp-contract/core";
1
+ import { CompressionAlgorithm, ContractDefinition, InferPublisherNames, PublisherEntry } from "@amqp-contract/contract";
2
+ import { Logger, MessageValidationError, PublishOptions as PublishOptions$1, TechnicalError, TelemetryProvider } from "@amqp-contract/core";
3
+ import { Future, Result } from "@swan-io/boxed";
2
4
  import * as amqp from "amqplib";
3
- import { Options } from "amqplib";
4
5
  import { TcpSocketConnectOpts } from "net";
5
6
  import { ConnectionOptions } from "tls";
6
- import { CompressionAlgorithm, ContractDefinition, InferPublisherNames, PublisherEntry } from "@amqp-contract/contract";
7
- import { Future, Result } from "@swan-io/boxed";
8
7
  import { StandardSchemaV1 } from "@standard-schema/spec";
9
8
 
10
- //#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
9
+ //#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@1.0.3/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
11
10
  type ConnectionUrl = string | amqp.Options.Connect | {
12
11
  url: string;
13
12
  connectionOptions?: AmqpConnectionOptions;
@@ -78,9 +77,9 @@ type ClientInferPublisherInput<TContract extends ContractDefinition, TName exten
78
77
  //#endregion
79
78
  //#region src/client.d.ts
80
79
  /**
81
- * Publish options that extend amqplib's Options.Publish with optional compression support.
80
+ * Publish options that extend amqp-client's PublishOptions with optional compression support.
82
81
  */
83
- type PublishOptions = Options.Publish & {
82
+ type PublishOptions = PublishOptions$1 & {
84
83
  /**
85
84
  * Optional compression algorithm to use for the message payload.
86
85
  * When specified, the message will be compressed using the chosen algorithm
@@ -102,6 +101,12 @@ type CreateClientOptions<TContract extends ContractDefinition> = {
102
101
  * OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed.
103
102
  */
104
103
  telemetry?: TelemetryProvider | undefined;
104
+ /**
105
+ * Default publish options that will be applied to all publish operations.
106
+ * These can be overridden by options passed to the publish method.
107
+ * By default, persistent is set to true for message durability.
108
+ */
109
+ defaultPublishOptions?: PublishOptions | undefined;
105
110
  };
106
111
  /**
107
112
  * Type-safe AMQP client for publishing messages
@@ -109,6 +114,7 @@ type CreateClientOptions<TContract extends ContractDefinition> = {
109
114
  declare class TypedAmqpClient<TContract extends ContractDefinition> {
110
115
  private readonly contract;
111
116
  private readonly amqpClient;
117
+ private readonly defaultPublishOptions;
112
118
  private readonly logger?;
113
119
  private readonly telemetry;
114
120
  private constructor();
@@ -126,6 +132,7 @@ declare class TypedAmqpClient<TContract extends ContractDefinition> {
126
132
  contract,
127
133
  urls,
128
134
  connectionOptions,
135
+ defaultPublishOptions,
129
136
  logger,
130
137
  telemetry
131
138
  }: CreateClientOptions<TContract>): Future<Result<TypedAmqpClient<TContract>, TechnicalError>>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts","../src/types.ts","../src/client.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;E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B,QAAA;EAAA,iBACA,UAAA;EAAA,iBACA,MAAA;EAAA,iBACA,SAAA;EAAA,QAJZ,WAAA,CAAA;EFzBD2B;;;;;;;AAMR;;;EANQA,OE0CC,MAAA,mBAAyB,kBAAA,CAAA,CAAA;IAC9B,QAAA;IACA,IAAA;IACA,iBAAA;IACA,MAAA;IACA;EAAA,GACC,mBAAA,CAAoB,SAAA,IAAa,MAAA,CAAO,MAAA,CAAO,eAAA,CAAgB,SAAA,GAAY,cAAA;EF3B3BvB;;;;;;;;;;;;;;EAA4CyB;;;;EEwD/F,OAAA,eAAsB,mBAAA,CAAoB,SAAA,EAAA,CACxC,aAAA,EAAe,KAAA,EACf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,KAAA,GAC9C,OAAA,GAAU,cAAA,GACT,MAAA,CAAO,MAAA,OAAa,cAAA,GAAiB,sBAAA;EF1DG;;;EEoJ3C,KAAA,CAAA,GAAS,MAAA,CAAO,MAAA,OAAa,cAAA;EAAA,QAIrB,sBAAA;AAAA"}
1
+ {"version":3,"file":"index.d.cts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@1.0.3/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d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;;;;EE4BvB,WAAA,GAAc,oBAAA;AAAA;;;;KAMJ,mBAAA,mBAAsC,kBAAA;EAChD,QAAA,EAAU,SAAA;EACV,IAAA,EAAM,aAAA;EACN,iBAAA,GAAoB,4BAAA;EACpB,MAAA,GAAS,MAAA;EFtB8CP;;;;;EE4BvD,SAAA,GAAY,iBAAA;EF5B2CA;;;;;EEkCvD,qBAAA,GAAwB,cAAA;AAAA;;;;cAMb,eAAA,mBAAkC,kBAAA;EAAA,iBAE1B,QAAA;EAAA,iBACA,UAAA;EAAA,iBACA,qBAAA;EAAA,iBACA,MAAA;EAAA,iBACA,SAAA;EAAA,QALZ,WAAA,CAAA;EFzBQ4B;;;;;;;;;;EAAAA,OE2CR,MAAA,mBAAyB,kBAAA,CAAA,CAAA;IAC9B,QAAA;IACA,IAAA;IACA,iBAAA;IACA,qBAAA;IACA,MAAA;IACA;EAAA,GACC,mBAAA,CAAoB,SAAA,IAAa,MAAA,CAAO,MAAA,CAAO,eAAA,CAAgB,SAAA,GAAY,cAAA;EFhD5EE;;;;;;;;;;;;;;;;;AClC0D;ECgH5D,OAAA,eAAsB,mBAAA,CAAoB,SAAA,EAAA,CACxC,aAAA,EAAe,KAAA,EACf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,KAAA,GAC9C,OAAA,GAAU,cAAA,GACT,MAAA,CAAO,MAAA,OAAa,cAAA,GAAiB,sBAAA;ED/GrB;;;EC4MnB,KAAA,CAAA,GAAS,MAAA,CAAO,MAAA,OAAa,cAAA;EAAA,QAIrB,sBAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -1,13 +1,12 @@
1
- import { Logger, MessageValidationError, TechnicalError, TelemetryProvider } from "@amqp-contract/core";
1
+ import { Logger, MessageValidationError, PublishOptions as PublishOptions$1, TechnicalError, TelemetryProvider } from "@amqp-contract/core";
2
2
  import { Future, Result } from "@swan-io/boxed";
3
+ import { CompressionAlgorithm, ContractDefinition, InferPublisherNames, PublisherEntry } from "@amqp-contract/contract";
3
4
  import * as amqp from "amqplib";
4
- import { Options } from "amqplib";
5
5
  import { TcpSocketConnectOpts } from "net";
6
6
  import { ConnectionOptions } from "tls";
7
- import { CompressionAlgorithm, ContractDefinition, InferPublisherNames, PublisherEntry } from "@amqp-contract/contract";
8
7
  import { StandardSchemaV1 } from "@standard-schema/spec";
9
8
 
10
- //#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
9
+ //#region ../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@1.0.3/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts
11
10
  type ConnectionUrl = string | amqp.Options.Connect | {
12
11
  url: string;
13
12
  connectionOptions?: AmqpConnectionOptions;
@@ -78,9 +77,9 @@ type ClientInferPublisherInput<TContract extends ContractDefinition, TName exten
78
77
  //#endregion
79
78
  //#region src/client.d.ts
80
79
  /**
81
- * Publish options that extend amqplib's Options.Publish with optional compression support.
80
+ * Publish options that extend amqp-client's PublishOptions with optional compression support.
82
81
  */
83
- type PublishOptions = Options.Publish & {
82
+ type PublishOptions = PublishOptions$1 & {
84
83
  /**
85
84
  * Optional compression algorithm to use for the message payload.
86
85
  * When specified, the message will be compressed using the chosen algorithm
@@ -102,6 +101,12 @@ type CreateClientOptions<TContract extends ContractDefinition> = {
102
101
  * OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed.
103
102
  */
104
103
  telemetry?: TelemetryProvider | undefined;
104
+ /**
105
+ * Default publish options that will be applied to all publish operations.
106
+ * These can be overridden by options passed to the publish method.
107
+ * By default, persistent is set to true for message durability.
108
+ */
109
+ defaultPublishOptions?: PublishOptions | undefined;
105
110
  };
106
111
  /**
107
112
  * Type-safe AMQP client for publishing messages
@@ -109,6 +114,7 @@ type CreateClientOptions<TContract extends ContractDefinition> = {
109
114
  declare class TypedAmqpClient<TContract extends ContractDefinition> {
110
115
  private readonly contract;
111
116
  private readonly amqpClient;
117
+ private readonly defaultPublishOptions;
112
118
  private readonly logger?;
113
119
  private readonly telemetry;
114
120
  private constructor();
@@ -126,6 +132,7 @@ declare class TypedAmqpClient<TContract extends ContractDefinition> {
126
132
  contract,
127
133
  urls,
128
134
  connectionOptions,
135
+ defaultPublishOptions,
129
136
  logger,
130
137
  telemetry
131
138
  }: CreateClientOptions<TContract>): Future<Result<TypedAmqpClient<TContract>, TechnicalError>>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@0.10.9/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts","../src/types.ts","../src/client.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;EACAC,cAAAA;EACAC,gBAAAA;EACAC,WAAAA;IACIC,SAAAA;IACAC,QAAAA;IACAC,QAAAA;IAC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CAAA;EFzBD2B;;;;;;;AAMR;;;EANQA,OE0CC,MAAA,mBAAyB,kBAAA,CAAA,CAAA;IAC9B,QAAA;IACA,IAAA;IACA,iBAAA;IACA,MAAA;IACA;EAAA,GACC,mBAAA,CAAoB,SAAA,IAAa,MAAA,CAAO,MAAA,CAAO,eAAA,CAAgB,SAAA,GAAY,cAAA;EF3B3BvB;;;;;;;;;;;;;;EAA4CyB;;;;EEwD/F,OAAA,eAAsB,mBAAA,CAAoB,SAAA,EAAA,CACxC,aAAA,EAAe,KAAA,EACf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,KAAA,GAC9C,OAAA,GAAU,cAAA,GACT,MAAA,CAAO,MAAA,OAAa,cAAA,GAAiB,sBAAA;EF1DG;;;EEoJ3C,KAAA,CAAA,GAAS,MAAA,CAAO,MAAA,OAAa,cAAA;EAAA,QAIrB,sBAAA;AAAA"}
1
+ {"version":3,"file":"index.d.mts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@1.0.3/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts","../src/types.ts","../src/client.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;KAKYM,aAAAA,YAAyBN,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A,EAAU,SAAA;EACV,IAAA,EAAM,aAAA;EACN,iBAAA,GAAoB,4BAAA;EACpB,MAAA,GAAS,MAAA;EFtB8CP;;;;;EE4BvD,SAAA,GAAY,iBAAA;EF5B2CA;;;;;EEkCvD,qBAAA,GAAwB,cAAA;AAAA;;;;cAMb,eAAA,mBAAkC,kBAAA;EAAA,iBAE1B,QAAA;EAAA,iBACA,UAAA;EAAA,iBACA,qBAAA;EAAA,iBACA,MAAA;EAAA,iBACA,SAAA;EAAA,QALZ,WAAA,CAAA;EFzBQ4B;;;;;;;;;;EAAAA,OE2CR,MAAA,mBAAyB,kBAAA,CAAA,CAAA;IAC9B,QAAA;IACA,IAAA;IACA,iBAAA;IACA,qBAAA;IACA,MAAA;IACA;EAAA,GACC,mBAAA,CAAoB,SAAA,IAAa,MAAA,CAAO,MAAA,CAAO,eAAA,CAAgB,SAAA,GAAY,cAAA;EFhD5EE;;;;;;;;;;;;;;;;;AClC0D;ECgH5D,OAAA,eAAsB,mBAAA,CAAoB,SAAA,EAAA,CACxC,aAAA,EAAe,KAAA,EACf,OAAA,EAAS,yBAAA,CAA0B,SAAA,EAAW,KAAA,GAC9C,OAAA,GAAU,cAAA,GACT,MAAA,CAAO,MAAA,OAAa,cAAA,GAAiB,sBAAA;ED/GrB;;;EC4MnB,KAAA,CAAA,GAAS,MAAA,CAAO,MAAA,OAAa,cAAA;EAAA,QAIrB,sBAAA;AAAA"}
package/dist/index.mjs CHANGED
@@ -3,7 +3,6 @@ import { Future, Result } from "@swan-io/boxed";
3
3
  import { deflate, gzip } from "node:zlib";
4
4
  import { match } from "ts-pattern";
5
5
  import { promisify } from "node:util";
6
-
7
6
  //#region src/compression.ts
8
7
  const gzipAsync = promisify(gzip);
9
8
  const deflateAsync = promisify(deflate);
@@ -19,16 +18,16 @@ const deflateAsync = promisify(deflate);
19
18
  function compressBuffer(buffer, algorithm) {
20
19
  return match(algorithm).with("gzip", () => Future.fromPromise(gzipAsync(buffer)).mapError((error) => new TechnicalError("Failed to compress with gzip", error))).with("deflate", () => Future.fromPromise(deflateAsync(buffer)).mapError((error) => new TechnicalError("Failed to compress with deflate", error))).exhaustive();
21
20
  }
22
-
23
21
  //#endregion
24
22
  //#region src/client.ts
25
23
  /**
26
24
  * Type-safe AMQP client for publishing messages
27
25
  */
28
26
  var TypedAmqpClient = class TypedAmqpClient {
29
- constructor(contract, amqpClient, logger, telemetry = defaultTelemetryProvider) {
27
+ constructor(contract, amqpClient, defaultPublishOptions, logger, telemetry = defaultTelemetryProvider) {
30
28
  this.contract = contract;
31
29
  this.amqpClient = amqpClient;
30
+ this.defaultPublishOptions = defaultPublishOptions;
32
31
  this.logger = logger;
33
32
  this.telemetry = telemetry;
34
33
  }
@@ -42,11 +41,14 @@ var TypedAmqpClient = class TypedAmqpClient {
42
41
  * Connections are automatically shared across clients with the same URLs and
43
42
  * connection options, following RabbitMQ best practices.
44
43
  */
45
- static create({ contract, urls, connectionOptions, logger, telemetry }) {
44
+ static create({ contract, urls, connectionOptions, defaultPublishOptions, logger, telemetry }) {
46
45
  const client = new TypedAmqpClient(contract, new AmqpClient(contract, {
47
46
  urls,
48
47
  connectionOptions
49
- }), logger, telemetry ?? defaultTelemetryProvider);
48
+ }), {
49
+ persistent: true,
50
+ ...defaultPublishOptions
51
+ }, logger, telemetry ?? defaultTelemetryProvider);
50
52
  return client.waitForConnectionReady().mapOk(() => client);
51
53
  }
52
54
  /**
@@ -80,7 +82,10 @@ var TypedAmqpClient = class TypedAmqpClient {
80
82
  });
81
83
  };
82
84
  const publishMessage = (validatedMessage) => {
83
- const { compression, ...restOptions } = options ?? {};
85
+ const { compression, ...restOptions } = {
86
+ ...this.defaultPublishOptions,
87
+ ...options
88
+ };
84
89
  const publishOptions = { ...restOptions };
85
90
  const preparePayload = () => {
86
91
  if (compression) {
@@ -121,7 +126,7 @@ var TypedAmqpClient = class TypedAmqpClient {
121
126
  return this.amqpClient.waitForConnect();
122
127
  }
123
128
  };
124
-
125
129
  //#endregion
126
130
  export { MessageValidationError, TypedAmqpClient };
131
+
127
132
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/compression.ts","../src/client.ts"],"sourcesContent":["import { Future, Result } from \"@swan-io/boxed\";\nimport { deflate, gzip } from \"node:zlib\";\nimport type { CompressionAlgorithm } from \"@amqp-contract/contract\";\nimport { TechnicalError } from \"@amqp-contract/core\";\nimport { match } from \"ts-pattern\";\nimport { promisify } from \"node:util\";\n\nconst gzipAsync = promisify(gzip);\nconst deflateAsync = promisify(deflate);\n\n/**\n * Compress a buffer using the specified compression algorithm.\n *\n * @param buffer - The buffer to compress\n * @param algorithm - The compression algorithm to use\n * @returns A Future with the compressed buffer or a TechnicalError\n *\n * @internal\n */\nexport function compressBuffer(\n buffer: Buffer,\n algorithm: CompressionAlgorithm,\n): Future<Result<Buffer, TechnicalError>> {\n return match(algorithm)\n .with(\"gzip\", () =>\n Future.fromPromise(gzipAsync(buffer)).mapError(\n (error) => new TechnicalError(\"Failed to compress with gzip\", error),\n ),\n )\n .with(\"deflate\", () =>\n Future.fromPromise(deflateAsync(buffer)).mapError(\n (error) => new TechnicalError(\"Failed to compress with deflate\", error),\n ),\n )\n .exhaustive();\n}\n","import {\n AmqpClient,\n type Logger,\n MessagingSemanticConventions,\n TechnicalError,\n type TelemetryProvider,\n defaultTelemetryProvider,\n endSpanError,\n endSpanSuccess,\n recordPublishMetric,\n startPublishSpan,\n} from \"@amqp-contract/core\";\nimport type { AmqpConnectionManagerOptions, ConnectionUrl } from \"amqp-connection-manager\";\nimport type {\n CompressionAlgorithm,\n ContractDefinition,\n InferPublisherNames,\n} from \"@amqp-contract/contract\";\nimport { Future, Result } from \"@swan-io/boxed\";\nimport type { ClientInferPublisherInput } from \"./types.js\";\nimport { MessageValidationError } from \"./errors.js\";\nimport type { Options } from \"amqplib\";\nimport { compressBuffer } from \"./compression.js\";\n\n/**\n * Publish options that extend amqplib's Options.Publish with optional compression support.\n */\nexport type PublishOptions = Options.Publish & {\n /**\n * Optional compression algorithm to use for the message payload.\n * When specified, the message will be compressed using the chosen algorithm\n * and the contentEncoding header will be set automatically.\n */\n compression?: CompressionAlgorithm | undefined;\n};\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 * Optional telemetry provider for tracing and metrics.\n * If not provided, uses the default provider which attempts to load OpenTelemetry.\n * OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed.\n */\n telemetry?: TelemetryProvider | 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 private readonly telemetry: TelemetryProvider = defaultTelemetryProvider,\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 telemetry,\n }: CreateClientOptions<TContract>): Future<Result<TypedAmqpClient<TContract>, TechnicalError>> {\n const client = new TypedAmqpClient(\n contract,\n new AmqpClient(contract, { urls, connectionOptions }),\n logger,\n telemetry ?? defaultTelemetryProvider,\n );\n\n return client.waitForConnectionReady().mapOk(() => client);\n }\n\n /**\n * Publish a message using a defined publisher\n *\n * @param publisherName - The name of the publisher to use\n * @param message - The message to publish\n * @param options - Optional publish options including compression, headers, priority, etc.\n *\n * @remarks\n * If `options.compression` is specified, the message will be compressed before publishing\n * and the `contentEncoding` property will be set automatically. Any `contentEncoding`\n * value already in options will be overwritten by the compression algorithm.\n *\n * @returns Result.Ok(void) on success, or Result.Error with specific error on failure\n */\n /**\n * Publish a message using a defined publisher.\n * TypeScript guarantees publisher exists for valid publisher names.\n */\n publish<TName extends InferPublisherNames<TContract>>(\n publisherName: TName,\n message: ClientInferPublisherInput<TContract, TName>,\n options?: PublishOptions,\n ): Future<Result<void, TechnicalError | MessageValidationError>> {\n const startTime = Date.now();\n // Non-null assertions safe: TypeScript guarantees these exist for valid TName\n const publisher = this.contract.publishers![publisherName as string]!;\n const { exchange, routingKey } = publisher;\n\n // Start telemetry span\n const span = startPublishSpan(this.telemetry, exchange.name, routingKey, {\n [MessagingSemanticConventions.AMQP_PUBLISHER_NAME]: String(publisherName),\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): Future<Result<void, TechnicalError>> => {\n // Extract compression from options and create publish options without it\n const { compression, ...restOptions } = options ?? {};\n const publishOptions: Options.Publish = { ...restOptions };\n\n // Prepare payload and options based on compression configuration\n const preparePayload = (): Future<Result<Buffer | unknown, TechnicalError>> => {\n if (compression) {\n // Compress the message payload\n const messageBuffer = Buffer.from(JSON.stringify(validatedMessage));\n publishOptions.contentEncoding = compression;\n\n return compressBuffer(messageBuffer, compression);\n }\n\n // No compression: use the channel's built-in JSON serialization\n return Future.value(Result.Ok(validatedMessage));\n };\n\n // Publish the prepared payload\n return preparePayload().flatMapOk((payload) =>\n this.amqpClient\n .publish(publisher.exchange.name, publisher.routingKey ?? \"\", payload, publishOptions)\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 compressed: !!compression,\n });\n\n return Result.Ok(undefined);\n }),\n );\n };\n\n // Validate message using schema\n return validateMessage()\n .flatMapOk((validatedMessage) => publishMessage(validatedMessage))\n .tapOk(() => {\n const durationMs = Date.now() - startTime;\n endSpanSuccess(span);\n recordPublishMetric(this.telemetry, exchange.name, routingKey, true, durationMs);\n })\n .tapError((error) => {\n const durationMs = Date.now() - startTime;\n endSpanError(span, error);\n recordPublishMetric(this.telemetry, exchange.name, routingKey, false, durationMs);\n });\n }\n\n /**\n * Close the channel and connection\n */\n close(): Future<Result<void, TechnicalError>> {\n return this.amqpClient.close().mapOk(() => undefined);\n }\n\n private waitForConnectionReady(): Future<Result<void, TechnicalError>> {\n return this.amqpClient.waitForConnect();\n }\n}\n"],"mappings":";;;;;;;AAOA,MAAM,YAAY,UAAU,KAAK;AACjC,MAAM,eAAe,UAAU,QAAQ;;;;;;;;;;AAWvC,SAAgB,eACd,QACA,WACwC;AACxC,QAAO,MAAM,UAAU,CACpB,KAAK,cACJ,OAAO,YAAY,UAAU,OAAO,CAAC,CAAC,UACnC,UAAU,IAAI,eAAe,gCAAgC,MAAM,CACrE,CACF,CACA,KAAK,iBACJ,OAAO,YAAY,aAAa,OAAO,CAAC,CAAC,UACtC,UAAU,IAAI,eAAe,mCAAmC,MAAM,CACxE,CACF,CACA,YAAY;;;;;;;;ACqBjB,IAAa,kBAAb,MAAa,gBAAsD;CACjE,AAAQ,YACN,AAAiB,UACjB,AAAiB,YACjB,AAAiB,QACjB,AAAiB,YAA+B,0BAChD;EAJiB;EACA;EACA;EACA;;;;;;;;;;;;CAanB,OAAO,OAA6C,EAClD,UACA,MACA,mBACA,QACA,aAC6F;EAC7F,MAAM,SAAS,IAAI,gBACjB,UACA,IAAI,WAAW,UAAU;GAAE;GAAM;GAAmB,CAAC,EACrD,QACA,a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,KAAK,kCAAkC;KAClD,eAAe,OAAO,cAAc;KACpC,UAAU,UAAU,SAAS;KAC7B,YAAY,UAAU;KACtB,YAAY,CAAC,CAAC;KACf,CAAC;AAEF,WAAO,OAAO,GAAG,OAAU;KAC3B,CACL;;AAIH,SAAO,iBAAiB,CACrB,WAAW,qBAAqB,eAAe,iBAAiB,CAAC,CACjE,YAAY;GACX,MAAM,aAAa,KAAK,KAAK,GAAG;AAChC,kBAAe,KAAK;AACpB,uBAAoB,KAAK,WAAW,SAAS,MAAM,YAAY,MAAM,WAAW;IAChF,CACD,UAAU,UAAU;GACnB,MAAM,aAAa,KAAK,KAAK,GAAG;AAChC,gBAAa,MAAM,MAAM;AACzB,uBAAoB,KAAK,WAAW,SAAS,MAAM,YAAY,OAAO,WAAW;IACjF;;;;;CAMN,QAA8C;AAC5C,SAAO,KAAK,WAAW,OAAO,CAAC,YAAY,OAAU;;CAGvD,AAAQ,yBAA+D;AACrE,SAAO,KAAK,WAAW,gBAAgB"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/compression.ts","../src/client.ts"],"sourcesContent":["import { Future, Result } from \"@swan-io/boxed\";\nimport { deflate, gzip } from \"node:zlib\";\nimport type { CompressionAlgorithm } from \"@amqp-contract/contract\";\nimport { TechnicalError } from \"@amqp-contract/core\";\nimport { match } from \"ts-pattern\";\nimport { promisify } from \"node:util\";\n\nconst gzipAsync = promisify(gzip);\nconst deflateAsync = promisify(deflate);\n\n/**\n * Compress a buffer using the specified compression algorithm.\n *\n * @param buffer - The buffer to compress\n * @param algorithm - The compression algorithm to use\n * @returns A Future with the compressed buffer or a TechnicalError\n *\n * @internal\n */\nexport function compressBuffer(\n buffer: Buffer,\n algorithm: CompressionAlgorithm,\n): Future<Result<Buffer, TechnicalError>> {\n return match(algorithm)\n .with(\"gzip\", () =>\n Future.fromPromise(gzipAsync(buffer)).mapError(\n (error) => new TechnicalError(\"Failed to compress with gzip\", error),\n ),\n )\n .with(\"deflate\", () =>\n Future.fromPromise(deflateAsync(buffer)).mapError(\n (error) => new TechnicalError(\"Failed to compress with deflate\", error),\n ),\n )\n .exhaustive();\n}\n","import type {\n CompressionAlgorithm,\n ContractDefinition,\n InferPublisherNames,\n} from \"@amqp-contract/contract\";\nimport {\n AmqpClient,\n PublishOptions as AmqpClientPublishOptions,\n type Logger,\n MessagingSemanticConventions,\n TechnicalError,\n type TelemetryProvider,\n defaultTelemetryProvider,\n endSpanError,\n endSpanSuccess,\n recordPublishMetric,\n startPublishSpan,\n} from \"@amqp-contract/core\";\nimport { Future, Result } from \"@swan-io/boxed\";\nimport type { AmqpConnectionManagerOptions, ConnectionUrl } from \"amqp-connection-manager\";\nimport { compressBuffer } from \"./compression.js\";\nimport { MessageValidationError } from \"./errors.js\";\nimport type { ClientInferPublisherInput } from \"./types.js\";\n\n/**\n * Publish options that extend amqp-client's PublishOptions with optional compression support.\n */\nexport type PublishOptions = AmqpClientPublishOptions & {\n /**\n * Optional compression algorithm to use for the message payload.\n * When specified, the message will be compressed using the chosen algorithm\n * and the contentEncoding header will be set automatically.\n */\n compression?: CompressionAlgorithm | undefined;\n};\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 * Optional telemetry provider for tracing and metrics.\n * If not provided, uses the default provider which attempts to load OpenTelemetry.\n * OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed.\n */\n telemetry?: TelemetryProvider | undefined;\n /**\n * Default publish options that will be applied to all publish operations.\n * These can be overridden by options passed to the publish method.\n * By default, persistent is set to true for message durability.\n */\n defaultPublishOptions?: PublishOptions | 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 defaultPublishOptions: PublishOptions,\n private readonly logger?: Logger,\n private readonly telemetry: TelemetryProvider = defaultTelemetryProvider,\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 defaultPublishOptions,\n logger,\n telemetry,\n }: CreateClientOptions<TContract>): Future<Result<TypedAmqpClient<TContract>, TechnicalError>> {\n const client = new TypedAmqpClient(\n contract,\n new AmqpClient(contract, { urls, connectionOptions }),\n { persistent: true, ...defaultPublishOptions },\n logger,\n telemetry ?? defaultTelemetryProvider,\n );\n\n return client.waitForConnectionReady().mapOk(() => client);\n }\n\n /**\n * Publish a message using a defined publisher\n *\n * @param publisherName - The name of the publisher to use\n * @param message - The message to publish\n * @param options - Optional publish options including compression, headers, priority, etc.\n *\n * @remarks\n * If `options.compression` is specified, the message will be compressed before publishing\n * and the `contentEncoding` property will be set automatically. Any `contentEncoding`\n * value already in options will be overwritten by the compression algorithm.\n *\n * @returns Result.Ok(void) on success, or Result.Error with specific error on failure\n */\n /**\n * Publish a message using a defined publisher.\n * TypeScript guarantees publisher exists for valid publisher names.\n */\n publish<TName extends InferPublisherNames<TContract>>(\n publisherName: TName,\n message: ClientInferPublisherInput<TContract, TName>,\n options?: PublishOptions,\n ): Future<Result<void, TechnicalError | MessageValidationError>> {\n const startTime = Date.now();\n // Non-null assertions safe: TypeScript guarantees these exist for valid TName\n const publisher = this.contract.publishers![publisherName as string]!;\n const { exchange, routingKey } = publisher;\n\n // Start telemetry span\n const span = startPublishSpan(this.telemetry, exchange.name, routingKey, {\n [MessagingSemanticConventions.AMQP_PUBLISHER_NAME]: String(publisherName),\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): Future<Result<void, TechnicalError>> => {\n // Merge default options with provided options\n const mergedOptions = { ...this.defaultPublishOptions, ...options };\n\n // Extract compression from merged options and create publish options without it\n const { compression, ...restOptions } = mergedOptions;\n const publishOptions: AmqpClientPublishOptions = { ...restOptions };\n\n // Prepare payload and options based on compression configuration\n const preparePayload = (): Future<Result<Buffer | unknown, TechnicalError>> => {\n if (compression) {\n // Compress the message payload\n const messageBuffer = Buffer.from(JSON.stringify(validatedMessage));\n publishOptions.contentEncoding = compression;\n\n return compressBuffer(messageBuffer, compression);\n }\n\n // No compression: use the channel's built-in JSON serialization\n return Future.value(Result.Ok(validatedMessage));\n };\n\n // Publish the prepared payload\n return preparePayload().flatMapOk((payload) =>\n this.amqpClient\n .publish(publisher.exchange.name, publisher.routingKey ?? \"\", payload, publishOptions)\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 compressed: !!compression,\n });\n\n return Result.Ok(undefined);\n }),\n );\n };\n\n // Validate message using schema\n return validateMessage()\n .flatMapOk((validatedMessage) => publishMessage(validatedMessage))\n .tapOk(() => {\n const durationMs = Date.now() - startTime;\n endSpanSuccess(span);\n recordPublishMetric(this.telemetry, exchange.name, routingKey, true, durationMs);\n })\n .tapError((error) => {\n const durationMs = Date.now() - startTime;\n endSpanError(span, error);\n recordPublishMetric(this.telemetry, exchange.name, routingKey, false, durationMs);\n });\n }\n\n /**\n * Close the channel and connection\n */\n close(): Future<Result<void, TechnicalError>> {\n return this.amqpClient.close().mapOk(() => undefined);\n }\n\n private waitForConnectionReady(): Future<Result<void, TechnicalError>> {\n return this.amqpClient.waitForConnect();\n }\n}\n"],"mappings":";;;;;;AAOA,MAAM,YAAY,UAAU,KAAK;AACjC,MAAM,eAAe,UAAU,QAAQ;;;;;;;;;;AAWvC,SAAgB,eACd,QACA,WACwC;AACxC,QAAO,MAAM,UAAU,CACpB,KAAK,cACJ,OAAO,YAAY,UAAU,OAAO,CAAC,CAAC,UACnC,UAAU,IAAI,eAAe,gCAAgC,MAAM,CACrE,CACF,CACA,KAAK,iBACJ,OAAO,YAAY,aAAa,OAAO,CAAC,CAAC,UACtC,UAAU,IAAI,eAAe,mCAAmC,MAAM,CACxE,CACF,CACA,YAAY;;;;;;;AC2BjB,IAAa,kBAAb,MAAa,gBAAsD;CACjE,YACE,UACA,YACA,uBACA,QACA,YAAgD,0BAChD;AALiB,OAAA,WAAA;AACA,OAAA,aAAA;AACA,OAAA,wBAAA;AACA,OAAA,SAAA;AACA,OAAA,YAAA;;;;;;;;;;;;CAanB,OAAO,OAA6C,EAClD,UACA,MACA,mBACA,uBACA,QACA,aAC6F;EAC7F,MAAM,SAAS,IAAI,gBACjB,UACA,IAAI,WAAW,UAAU;GAAE;GAAM;GAAmB,CAAC,EACrD;GAAE,YAAY;GAAM,GAAG;GAAuB,EAC9C,QACA,aAAa,yBACd;AAED,SAAO,OAAO,wBAAwB,CAAC,YAAY,OAAO;;;;;;;;;;;;;;;;;;;;CAqB5D,QACE,eACA,SACA,SAC+D;EAC/D,MAAM,YAAY,KAAK,KAAK;EAE5B,MAAM,YAAY,KAAK,SAAS,WAAY;EAC5C,MAAM,EAAE,UAAU,eAAe;EAGjC,MAAM,OAAO,iBAAiB,KAAK,WAAW,SAAS,MAAM,YAAY,GACtE,6BAA6B,sBAAsB,OAAO,cAAc,EAC1E,CAAC;EAEF,MAAM,wBAAwB;GAC5B,MAAM,mBAAmB,UAAU,QA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,MAAM,WAAW;IAChF,CACD,UAAU,UAAU;GACnB,MAAM,aAAa,KAAK,KAAK,GAAG;AAChC,gBAAa,MAAM,MAAM;AACzB,uBAAoB,KAAK,WAAW,SAAS,MAAM,YAAY,OAAO,WAAW;IACjF;;;;;CAMN,QAA8C;AAC5C,SAAO,KAAK,WAAW,OAAO,CAAC,YAAY,KAAA,EAAU;;CAGvD,yBAAuE;AACrE,SAAO,KAAK,WAAW,gBAAgB"}
package/docs/index.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ### MessageValidationError
10
10
 
11
- Defined in: packages/core/dist/index.d.mts:83
11
+ Defined in: packages/core/dist/index.d.mts:27
12
12
 
13
13
  Error thrown when message validation fails (payload or headers).
14
14
 
@@ -35,7 +35,7 @@ The validation issues from the Standard Schema validation
35
35
  new MessageValidationError(source, issues): MessageValidationError;
36
36
  ```
37
37
 
38
- Defined in: packages/core/dist/index.d.mts:86
38
+ Defined in: packages/core/dist/index.d.mts:30
39
39
 
40
40
  ###### Parameters
41
41
 
@@ -58,13 +58,13 @@ Error.constructor
58
58
 
59
59
  | Property | Modifier | Type | Description | Inherited from | Defined in |
60
60
  | ------ | ------ | ------ | ------ | ------ | ------ |
61
- | <a id="cause"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:26 |
62
- | <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | packages/core/dist/index.d.mts:85 |
63
- | <a id="message"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077 |
64
- | <a id="name"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
65
- | <a id="source"></a> `source` | `readonly` | `string` | - | - | packages/core/dist/index.d.mts:84 |
66
- | <a id="stack"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078 |
67
- | <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. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@25.2.3/node\_modules/@types/node/globals.d.ts:67 |
61
+ | <a id="cause"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
62
+ | <a id="issues"></a> `issues` | `readonly` | `unknown` | - | - | packages/core/dist/index.d.mts:29 |
63
+ | <a id="message"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
64
+ | <a id="name"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
65
+ | <a id="source"></a> `source` | `readonly` | `string` | - | - | packages/core/dist/index.d.mts:28 |
66
+ | <a id="stack"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
67
+ | <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. | `Error.stackTraceLimit` | node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:68 |
68
68
 
69
69
  #### Methods
70
70
 
@@ -74,7 +74,7 @@ Error.constructor
74
74
  static captureStackTrace(targetObject, constructorOpt?): void;
75
75
  ```
76
76
 
77
- Defined in: node\_modules/.pnpm/@types+node@25.2.3/node\_modules/@types/node/globals.d.ts:51
77
+ Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:52
78
78
 
79
79
  Creates a `.stack` property on `targetObject`, which when accessed returns
80
80
  a string representing the location in the code at which
@@ -143,7 +143,7 @@ Error.captureStackTrace
143
143
  static prepareStackTrace(err, stackTraces): any;
144
144
  ```
145
145
 
146
- Defined in: node\_modules/.pnpm/@types+node@25.2.3/node\_modules/@types/node/globals.d.ts:55
146
+ Defined in: node\_modules/.pnpm/@types+node@24.12.2/node\_modules/@types/node/globals.d.ts:56
147
147
 
148
148
  ###### Parameters
149
149
 
@@ -170,7 +170,7 @@ Error.prepareStackTrace
170
170
 
171
171
  ### TypedAmqpClient
172
172
 
173
- Defined in: [packages/client/src/client.ts:56](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L56)
173
+ Defined in: [packages/client/src/client.ts:62](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L62)
174
174
 
175
175
  Type-safe AMQP client for publishing messages
176
176
 
@@ -188,7 +188,7 @@ Type-safe AMQP client for publishing messages
188
188
  close(): Future<Result<void, TechnicalError>>;
189
189
  ```
190
190
 
191
- Defined in: [packages/client/src/client.ts:203](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L203)
191
+ Defined in: [packages/client/src/client.ts:215](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L215)
192
192
 
193
193
  Close the channel and connection
194
194
 
@@ -205,7 +205,7 @@ publish<TName>(
205
205
  options?): Future<Result<void, TechnicalError | MessageValidationError>>;
206
206
  ```
207
207
 
208
- Defined in: [packages/client/src/client.ts:109](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L109)
208
+ Defined in: [packages/client/src/client.ts:118](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L118)
209
209
 
210
210
  Publish a message using a defined publisher.
211
211
  TypeScript guarantees publisher exists for valid publisher names.
@@ -234,7 +234,7 @@ TypeScript guarantees publisher exists for valid publisher names.
234
234
  static create<TContract>(__namedParameters): Future<Result<TypedAmqpClient<TContract>, TechnicalError>>;
235
235
  ```
236
236
 
237
- Defined in: [packages/client/src/client.ts:74](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L74)
237
+ Defined in: [packages/client/src/client.ts:81](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L81)
238
238
 
239
239
  Create a type-safe AMQP client from a contract.
240
240
 
@@ -269,7 +269,7 @@ connection options, following RabbitMQ best practices.
269
269
  type ClientInferPublisherInput<TContract, TName> = PublisherInferInput<InferPublisher<TContract, TName>>;
270
270
  ```
271
271
 
272
- Defined in: [packages/client/src/types.ts:41](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/types.ts#L41)
272
+ Defined in: [packages/client/src/types.ts:41](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/types.ts#L41)
273
273
 
274
274
  Infer publisher input type (message payload) for a specific publisher in a contract
275
275
 
@@ -288,7 +288,7 @@ Infer publisher input type (message payload) for a specific publisher in a contr
288
288
  type CreateClientOptions<TContract> = object;
289
289
  ```
290
290
 
291
- Defined in: [packages/client/src/client.ts:40](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L40)
291
+ Defined in: [packages/client/src/client.ts:40](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L40)
292
292
 
293
293
  Options for creating a client
294
294
 
@@ -302,26 +302,27 @@ Options for creating a client
302
302
 
303
303
  | Property | Type | Description | Defined in |
304
304
  | ------ | ------ | ------ | ------ |
305
- | <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | - | [packages/client/src/client.ts:43](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L43) |
306
- | <a id="contract"></a> `contract` | `TContract` | - | [packages/client/src/client.ts:41](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L41) |
307
- | <a id="logger"></a> `logger?` | `Logger` | - | [packages/client/src/client.ts:44](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L44) |
308
- | <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:50](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L50) |
309
- | <a id="urls"></a> `urls` | `ConnectionUrl`[] | - | [packages/client/src/client.ts:42](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L42) |
305
+ | <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | - | [packages/client/src/client.ts:43](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L43) |
306
+ | <a id="contract"></a> `contract` | `TContract` | - | [packages/client/src/client.ts:41](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L41) |
307
+ | <a id="defaultpublishoptions"></a> `defaultPublishOptions?` | [`PublishOptions`](#publishoptions) | 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:56](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L56) |
308
+ | <a id="logger"></a> `logger?` | `Logger` | - | [packages/client/src/client.ts:44](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L44) |
309
+ | <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:50](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L50) |
310
+ | <a id="urls"></a> `urls` | `ConnectionUrl`[] | - | [packages/client/src/client.ts:42](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L42) |
310
311
 
311
312
  ***
312
313
 
313
314
  ### PublishOptions
314
315
 
315
316
  ```ts
316
- type PublishOptions = Options.Publish & object;
317
+ type PublishOptions = AmqpClientPublishOptions & object;
317
318
  ```
318
319
 
319
- Defined in: [packages/client/src/client.ts:28](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L28)
320
+ Defined in: [packages/client/src/client.ts:28](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L28)
320
321
 
321
- Publish options that extend amqplib's Options.Publish with optional compression support.
322
+ Publish options that extend amqp-client's PublishOptions with optional compression support.
322
323
 
323
324
  #### Type Declaration
324
325
 
325
326
  | Name | Type | Description | Defined in |
326
327
  | ------ | ------ | ------ | ------ |
327
- | `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:34](https://github.com/btravers/amqp-contract/blob/a5ff0e58db355e3410ea3b765884871c3b44c87d/packages/client/src/client.ts#L34) |
328
+ | `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:34](https://github.com/btravers/amqp-contract/blob/c4431c816689353f677718608623c58fd1757388/packages/client/src/client.ts#L34) |
package/package.json CHANGED
@@ -1,34 +1,41 @@
1
1
  {
2
2
  "name": "@amqp-contract/client",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "Client utilities for publishing messages using amqp-contract",
5
5
  "keywords": [
6
6
  "amqp",
7
7
  "client",
8
8
  "contract",
9
- "rabbitmq",
10
- "typescript",
11
- "nodejs",
12
- "messaging",
13
- "type-safe",
14
- "schema",
15
- "validation",
16
9
  "message-broker",
17
10
  "message-queue",
18
- "publisher"
11
+ "messaging",
12
+ "nodejs",
13
+ "publisher",
14
+ "rabbitmq",
15
+ "schema",
16
+ "type-safe",
17
+ "typescript",
18
+ "validation"
19
19
  ],
20
20
  "homepage": "https://github.com/btravers/amqp-contract#readme",
21
21
  "bugs": {
22
22
  "url": "https://github.com/btravers/amqp-contract/issues"
23
23
  },
24
+ "license": "MIT",
25
+ "author": "Benoit TRAVERS <benoit.travers.fr@gmail.com>",
24
26
  "repository": {
25
27
  "type": "git",
26
28
  "url": "https://github.com/btravers/amqp-contract.git",
27
29
  "directory": "packages/client"
28
30
  },
29
- "license": "MIT",
30
- "author": "Benoit TRAVERS <benoit.travers.fr@gmail.com>",
31
+ "files": [
32
+ "dist",
33
+ "docs"
34
+ ],
31
35
  "type": "module",
36
+ "main": "./dist/index.cjs",
37
+ "module": "./dist/index.mjs",
38
+ "types": "./dist/index.d.mts",
32
39
  "exports": {
33
40
  ".": {
34
41
  "import": {
@@ -42,33 +49,26 @@
42
49
  },
43
50
  "./package.json": "./package.json"
44
51
  },
45
- "main": "./dist/index.cjs",
46
- "module": "./dist/index.mjs",
47
- "types": "./dist/index.d.mts",
48
- "files": [
49
- "dist",
50
- "docs"
51
- ],
52
52
  "dependencies": {
53
53
  "@standard-schema/spec": "1.1.0",
54
54
  "@swan-io/boxed": "3.2.1",
55
55
  "ts-pattern": "5.9.0",
56
- "@amqp-contract/contract": "0.19.0",
57
- "@amqp-contract/core": "0.19.0"
56
+ "@amqp-contract/contract": "0.21.0",
57
+ "@amqp-contract/core": "0.21.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/amqplib": "0.10.8",
61
- "@types/node": "25.2.3",
62
- "@vitest/coverage-v8": "4.0.18",
61
+ "@types/node": "24.12.2",
62
+ "@vitest/coverage-v8": "4.1.5",
63
63
  "amqp-connection-manager": "5.0.0",
64
- "amqplib": "0.10.9",
65
- "tsdown": "0.20.3",
66
- "typedoc": "0.28.16",
67
- "typedoc-plugin-markdown": "4.10.0",
68
- "typescript": "5.9.3",
69
- "vitest": "4.0.18",
64
+ "amqplib": "1.0.3",
65
+ "tsdown": "0.21.9",
66
+ "typedoc": "0.28.19",
67
+ "typedoc-plugin-markdown": "4.11.0",
68
+ "typescript": "6.0.3",
69
+ "vitest": "4.1.5",
70
70
  "zod": "4.3.6",
71
- "@amqp-contract/testing": "0.19.0",
71
+ "@amqp-contract/testing": "0.21.0",
72
72
  "@amqp-contract/tsconfig": "0.1.0",
73
73
  "@amqp-contract/typedoc": "0.1.0"
74
74
  },