@azure/core-amqp 4.1.1-alpha.20240108.2 → 4.2.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.js CHANGED
@@ -105,6 +105,7 @@ const Constants = {
105
105
  minDurationValue: -922337203685477,
106
106
  // https://github.com/Azure/azure-amqp/blob/master/Microsoft.Azure.Amqp/Amqp/AmqpConstants.cs#L47
107
107
  maxAbsoluteExpiryTime: new Date("9999-12-31T07:59:59.000Z").getTime(),
108
+ maxUint32Value: 4294967295,
108
109
  aadTokenValidityMarginInMs: 5000,
109
110
  connectionReconnectDelay: 300,
110
111
  defaultMaxRetries: 3,
@@ -2127,7 +2128,7 @@ const AmqpAnnotatedMessage = {
2127
2128
  * Takes RheaMessage(`Message` type from "rhea") and returns it in the AmqpAnnotatedMessage format.
2128
2129
  */
2129
2130
  fromRheaMessage(msg) {
2130
- return {
2131
+ const amqpMsg = {
2131
2132
  header: AmqpMessageHeader.fromRheaMessageHeader(msg),
2132
2133
  footer: msg.footer,
2133
2134
  messageAnnotations: msg.message_annotations,
@@ -2136,13 +2137,37 @@ const AmqpAnnotatedMessage = {
2136
2137
  properties: AmqpMessageProperties.fromRheaMessageProperties(msg),
2137
2138
  body: msg.body,
2138
2139
  };
2140
+ if (msg.absolute_expiry_time) {
2141
+ const absoluteExpiryTime = msg.absolute_expiry_time.getTime();
2142
+ amqpMsg.properties.absoluteExpiryTime = Math.min(absoluteExpiryTime, Constants.maxAbsoluteExpiryTime);
2143
+ // The TTL from the header can be at most approximately 49 days (uint32
2144
+ // max value milliseconds) due to the AMQP spec. In order to allow for
2145
+ // larger TTLs set by the user, we take the difference of the
2146
+ // absolute_expiry_time and the creation_time (if both are set). If either of
2147
+ // those properties is not set, we fall back to the TTL from the header.
2148
+ if (msg.creation_time) {
2149
+ amqpMsg.header.timeToLive =
2150
+ amqpMsg.properties.absoluteExpiryTime - msg.creation_time.getTime();
2151
+ }
2152
+ }
2153
+ return amqpMsg;
2139
2154
  },
2140
2155
  /**
2141
2156
  * Takes AmqpAnnotatedMessage and returns it in the RheaMessage(`Message` type from "rhea") format.
2142
2157
  */
2143
2158
  toRheaMessage(msg) {
2144
- const message = Object.assign(Object.assign(Object.assign({}, AmqpMessageProperties.toRheaMessageProperties(msg.properties || {})), AmqpMessageHeader.toRheaMessageHeader(msg.header || {})), { body: msg.body, message_annotations: msg.messageAnnotations, delivery_annotations: msg.deliveryAnnotations, application_properties: msg.applicationProperties, footer: msg.footer });
2145
- return message;
2159
+ var _a, _b;
2160
+ const rhMsg = Object.assign(Object.assign(Object.assign({}, AmqpMessageProperties.toRheaMessageProperties(msg.properties || {})), AmqpMessageHeader.toRheaMessageHeader(msg.header || {})), { body: msg.body, message_annotations: msg.messageAnnotations, delivery_annotations: msg.deliveryAnnotations, application_properties: msg.applicationProperties, footer: msg.footer });
2161
+ // There is a loss of fidelity in the TTL header if larger than uint32 max value. As a workaround
2162
+ // we set the absolute_expiry_time and creation_time on the message based on the TTL. These
2163
+ // values are then used to reconstruct the accurate TTL for received messages.
2164
+ if ((_a = msg.header) === null || _a === void 0 ? void 0 : _a.timeToLive) {
2165
+ const ttl = msg.header.timeToLive;
2166
+ rhMsg.ttl = Math.min(ttl, Constants.maxUint32Value);
2167
+ rhMsg.creation_time = (_b = rhMsg.creation_time) !== null && _b !== void 0 ? _b : new Date();
2168
+ rhMsg.absolute_expiry_time = new Date(Math.min(rhMsg.creation_time.getTime() + ttl, Constants.maxAbsoluteExpiryTime));
2169
+ }
2170
+ return rhMsg;
2146
2171
  },
2147
2172
  };
2148
2173