@azure/event-hubs 6.0.2-alpha.20251015.1 → 6.0.2-alpha.20251021.1

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.
Files changed (260) hide show
  1. package/dist/browser/batchingPartitionChannel.d.ts.map +1 -1
  2. package/dist/browser/batchingPartitionChannel.js +2 -1
  3. package/dist/browser/batchingPartitionChannel.js.map +1 -1
  4. package/dist/browser/connectionContext.d.ts.map +1 -1
  5. package/dist/browser/connectionContext.js +10 -4
  6. package/dist/browser/connectionContext.js.map +1 -1
  7. package/dist/browser/eventHubBufferedProducerClient.d.ts.map +1 -1
  8. package/dist/browser/eventHubBufferedProducerClient.js +2 -1
  9. package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
  10. package/dist/browser/eventHubConsumerClient.d.ts.map +1 -1
  11. package/dist/browser/eventHubConsumerClient.js +3 -6
  12. package/dist/browser/eventHubConsumerClient.js.map +1 -1
  13. package/dist/browser/eventHubProducerClient.d.ts.map +1 -1
  14. package/dist/browser/eventHubProducerClient.js +3 -6
  15. package/dist/browser/eventHubProducerClient.js.map +1 -1
  16. package/dist/browser/eventHubSender.d.ts.map +1 -1
  17. package/dist/browser/eventHubSender.js +6 -4
  18. package/dist/browser/eventHubSender.js.map +1 -1
  19. package/dist/browser/partitionReceiver.js +4 -4
  20. package/dist/browser/partitionReceiver.js.map +1 -1
  21. package/dist/browser/util/timerLoop.d.ts.map +1 -1
  22. package/dist/browser/util/timerLoop.js +12 -5
  23. package/dist/browser/util/timerLoop.js.map +1 -1
  24. package/dist/commonjs/batchingPartitionChannel.d.ts.map +1 -1
  25. package/dist/commonjs/batchingPartitionChannel.js +2 -1
  26. package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
  27. package/dist/commonjs/connectionContext.d.ts.map +1 -1
  28. package/dist/commonjs/connectionContext.js +10 -4
  29. package/dist/commonjs/connectionContext.js.map +1 -1
  30. package/dist/commonjs/eventHubBufferedProducerClient.d.ts.map +1 -1
  31. package/dist/commonjs/eventHubBufferedProducerClient.js +2 -1
  32. package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
  33. package/dist/commonjs/eventHubConsumerClient.d.ts.map +1 -1
  34. package/dist/commonjs/eventHubConsumerClient.js +3 -6
  35. package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
  36. package/dist/commonjs/eventHubProducerClient.d.ts.map +1 -1
  37. package/dist/commonjs/eventHubProducerClient.js +3 -6
  38. package/dist/commonjs/eventHubProducerClient.js.map +1 -1
  39. package/dist/commonjs/eventHubSender.d.ts.map +1 -1
  40. package/dist/commonjs/eventHubSender.js +6 -4
  41. package/dist/commonjs/eventHubSender.js.map +1 -1
  42. package/dist/commonjs/partitionReceiver.js +4 -4
  43. package/dist/commonjs/partitionReceiver.js.map +1 -1
  44. package/dist/commonjs/tsdoc-metadata.json +1 -1
  45. package/dist/commonjs/util/timerLoop.d.ts.map +1 -1
  46. package/dist/commonjs/util/timerLoop.js +12 -5
  47. package/dist/commonjs/util/timerLoop.js.map +1 -1
  48. package/dist/esm/batchingPartitionChannel.d.ts.map +1 -1
  49. package/dist/esm/batchingPartitionChannel.js +2 -1
  50. package/dist/esm/batchingPartitionChannel.js.map +1 -1
  51. package/dist/esm/connectionContext.d.ts.map +1 -1
  52. package/dist/esm/connectionContext.js +10 -4
  53. package/dist/esm/connectionContext.js.map +1 -1
  54. package/dist/esm/eventHubBufferedProducerClient.d.ts.map +1 -1
  55. package/dist/esm/eventHubBufferedProducerClient.js +2 -1
  56. package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
  57. package/dist/esm/eventHubConsumerClient.d.ts.map +1 -1
  58. package/dist/esm/eventHubConsumerClient.js +3 -6
  59. package/dist/esm/eventHubConsumerClient.js.map +1 -1
  60. package/dist/esm/eventHubProducerClient.d.ts.map +1 -1
  61. package/dist/esm/eventHubProducerClient.js +3 -6
  62. package/dist/esm/eventHubProducerClient.js.map +1 -1
  63. package/dist/esm/eventHubSender.d.ts.map +1 -1
  64. package/dist/esm/eventHubSender.js +6 -4
  65. package/dist/esm/eventHubSender.js.map +1 -1
  66. package/dist/esm/partitionReceiver.js +4 -4
  67. package/dist/esm/partitionReceiver.js.map +1 -1
  68. package/dist/esm/util/timerLoop.d.ts.map +1 -1
  69. package/dist/esm/util/timerLoop.js +12 -5
  70. package/dist/esm/util/timerLoop.js.map +1 -1
  71. package/dist/react-native/batchingPartitionChannel.d.ts +94 -0
  72. package/dist/react-native/batchingPartitionChannel.d.ts.map +1 -0
  73. package/dist/react-native/batchingPartitionChannel.js +255 -0
  74. package/dist/react-native/batchingPartitionChannel.js.map +1 -0
  75. package/dist/react-native/connectionContext.d.ts +108 -0
  76. package/dist/react-native/connectionContext.d.ts.map +1 -0
  77. package/dist/react-native/connectionContext.js +310 -0
  78. package/dist/react-native/connectionContext.js.map +1 -0
  79. package/dist/react-native/dataTransformer.d.ts +53 -0
  80. package/dist/react-native/dataTransformer.d.ts.map +1 -0
  81. package/dist/react-native/dataTransformer.js +133 -0
  82. package/dist/react-native/dataTransformer.js.map +1 -0
  83. package/dist/react-native/diagnostics/instrumentEventData.d.ts +28 -0
  84. package/dist/react-native/diagnostics/instrumentEventData.d.ts.map +1 -0
  85. package/dist/react-native/diagnostics/instrumentEventData.js +67 -0
  86. package/dist/react-native/diagnostics/instrumentEventData.js.map +1 -0
  87. package/dist/react-native/diagnostics/tracing.d.ts +19 -0
  88. package/dist/react-native/diagnostics/tracing.d.ts.map +1 -0
  89. package/dist/react-native/diagnostics/tracing.js +40 -0
  90. package/dist/react-native/diagnostics/tracing.js.map +1 -0
  91. package/dist/react-native/eventData.d.ts +295 -0
  92. package/dist/react-native/eventData.d.ts.map +1 -0
  93. package/dist/react-native/eventData.js +247 -0
  94. package/dist/react-native/eventData.js.map +1 -0
  95. package/dist/react-native/eventDataAdapter.d.ts +69 -0
  96. package/dist/react-native/eventDataAdapter.d.ts.map +1 -0
  97. package/dist/react-native/eventDataAdapter.js +38 -0
  98. package/dist/react-native/eventDataAdapter.js.map +1 -0
  99. package/dist/react-native/eventDataBatch.d.ts +225 -0
  100. package/dist/react-native/eventDataBatch.d.ts.map +1 -0
  101. package/dist/react-native/eventDataBatch.js +301 -0
  102. package/dist/react-native/eventDataBatch.js.map +1 -0
  103. package/dist/react-native/eventHubBufferedProducerClient.d.ts +323 -0
  104. package/dist/react-native/eventHubBufferedProducerClient.d.ts.map +1 -0
  105. package/dist/react-native/eventHubBufferedProducerClient.js +301 -0
  106. package/dist/react-native/eventHubBufferedProducerClient.js.map +1 -0
  107. package/dist/react-native/eventHubConsumerClient.d.ts +293 -0
  108. package/dist/react-native/eventHubConsumerClient.d.ts.map +1 -0
  109. package/dist/react-native/eventHubConsumerClient.js +336 -0
  110. package/dist/react-native/eventHubConsumerClient.js.map +1 -0
  111. package/dist/react-native/eventHubConsumerClientModels.d.ts +218 -0
  112. package/dist/react-native/eventHubConsumerClientModels.d.ts.map +1 -0
  113. package/dist/react-native/eventHubConsumerClientModels.js +4 -0
  114. package/dist/react-native/eventHubConsumerClientModels.js.map +1 -0
  115. package/dist/react-native/eventHubProducerClient.d.ts +299 -0
  116. package/dist/react-native/eventHubProducerClient.d.ts.map +1 -0
  117. package/dist/react-native/eventHubProducerClient.js +366 -0
  118. package/dist/react-native/eventHubProducerClient.js.map +1 -0
  119. package/dist/react-native/eventHubSender.d.ts +227 -0
  120. package/dist/react-native/eventHubSender.d.ts.map +1 -0
  121. package/dist/react-native/eventHubSender.js +626 -0
  122. package/dist/react-native/eventHubSender.js.map +1 -0
  123. package/dist/react-native/eventPosition.d.ts +73 -0
  124. package/dist/react-native/eventPosition.d.ts.map +1 -0
  125. package/dist/react-native/eventPosition.js +121 -0
  126. package/dist/react-native/eventPosition.js.map +1 -0
  127. package/dist/react-native/eventProcessor.d.ts +232 -0
  128. package/dist/react-native/eventProcessor.d.ts.map +1 -0
  129. package/dist/react-native/eventProcessor.js +389 -0
  130. package/dist/react-native/eventProcessor.js.map +1 -0
  131. package/dist/react-native/eventhubConnectionConfig.d.ts +96 -0
  132. package/dist/react-native/eventhubConnectionConfig.d.ts.map +1 -0
  133. package/dist/react-native/eventhubConnectionConfig.js +98 -0
  134. package/dist/react-native/eventhubConnectionConfig.js.map +1 -0
  135. package/dist/react-native/impl/awaitableQueue.d.ts +25 -0
  136. package/dist/react-native/impl/awaitableQueue.d.ts.map +1 -0
  137. package/dist/react-native/impl/awaitableQueue.js +51 -0
  138. package/dist/react-native/impl/awaitableQueue.js.map +1 -0
  139. package/dist/react-native/impl/partitionAssigner.d.ts +29 -0
  140. package/dist/react-native/impl/partitionAssigner.d.ts.map +1 -0
  141. package/dist/react-native/impl/partitionAssigner.js +52 -0
  142. package/dist/react-native/impl/partitionAssigner.js.map +1 -0
  143. package/dist/react-native/impl/partitionGate.d.ts +27 -0
  144. package/dist/react-native/impl/partitionGate.d.ts.map +1 -0
  145. package/dist/react-native/impl/partitionGate.js +38 -0
  146. package/dist/react-native/impl/partitionGate.js.map +1 -0
  147. package/dist/react-native/impl/partitionKeyToIdMapper.d.ts +6 -0
  148. package/dist/react-native/impl/partitionKeyToIdMapper.d.ts.map +1 -0
  149. package/dist/react-native/impl/partitionKeyToIdMapper.js +111 -0
  150. package/dist/react-native/impl/partitionKeyToIdMapper.js.map +1 -0
  151. package/dist/react-native/inMemoryCheckpointStore.d.ts +44 -0
  152. package/dist/react-native/inMemoryCheckpointStore.d.ts.map +1 -0
  153. package/dist/react-native/inMemoryCheckpointStore.js +94 -0
  154. package/dist/react-native/inMemoryCheckpointStore.js.map +1 -0
  155. package/dist/react-native/index.d.ts +21 -0
  156. package/dist/react-native/index.d.ts.map +1 -0
  157. package/dist/react-native/index.js +12 -0
  158. package/dist/react-native/index.js.map +1 -0
  159. package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts +30 -0
  160. package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -0
  161. package/dist/react-native/loadBalancerStrategies/balancedStrategy.js +40 -0
  162. package/dist/react-native/loadBalancerStrategies/balancedStrategy.js.map +1 -0
  163. package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts +24 -0
  164. package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -0
  165. package/dist/react-native/loadBalancerStrategies/greedyStrategy.js +29 -0
  166. package/dist/react-native/loadBalancerStrategies/greedyStrategy.js.map +1 -0
  167. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts +28 -0
  168. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -0
  169. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js +245 -0
  170. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -0
  171. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts +20 -0
  172. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -0
  173. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js +22 -0
  174. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js.map +1 -0
  175. package/dist/react-native/logger.d.ts +37 -0
  176. package/dist/react-native/logger.d.ts.map +1 -0
  177. package/dist/react-native/logger.js +56 -0
  178. package/dist/react-native/logger.js.map +1 -0
  179. package/dist/react-native/managementClient.d.ts +145 -0
  180. package/dist/react-native/managementClient.d.ts.map +1 -0
  181. package/dist/react-native/managementClient.js +305 -0
  182. package/dist/react-native/managementClient.js.map +1 -0
  183. package/dist/react-native/models/private.d.ts +185 -0
  184. package/dist/react-native/models/private.d.ts.map +1 -0
  185. package/dist/react-native/models/private.js +4 -0
  186. package/dist/react-native/models/private.js.map +1 -0
  187. package/dist/react-native/models/public.d.ts +240 -0
  188. package/dist/react-native/models/public.d.ts.map +1 -0
  189. package/dist/react-native/models/public.js +18 -0
  190. package/dist/react-native/models/public.js.map +1 -0
  191. package/dist/react-native/package.json +3 -0
  192. package/dist/react-native/partitionProcessor.d.ts +134 -0
  193. package/dist/react-native/partitionProcessor.d.ts.map +1 -0
  194. package/dist/react-native/partitionProcessor.js +137 -0
  195. package/dist/react-native/partitionProcessor.js.map +1 -0
  196. package/dist/react-native/partitionPump.d.ts +38 -0
  197. package/dist/react-native/partitionPump.d.ts.map +1 -0
  198. package/dist/react-native/partitionPump.js +175 -0
  199. package/dist/react-native/partitionPump.js.map +1 -0
  200. package/dist/react-native/partitionReceiver.d.ts +82 -0
  201. package/dist/react-native/partitionReceiver.d.ts.map +1 -0
  202. package/dist/react-native/partitionReceiver.js +335 -0
  203. package/dist/react-native/partitionReceiver.js.map +1 -0
  204. package/dist/react-native/pumpManager.d.ts +72 -0
  205. package/dist/react-native/pumpManager.d.ts.map +1 -0
  206. package/dist/react-native/pumpManager.js +120 -0
  207. package/dist/react-native/pumpManager.js.map +1 -0
  208. package/dist/react-native/util/connectionStringUtils.d.ts +52 -0
  209. package/dist/react-native/util/connectionStringUtils.d.ts.map +1 -0
  210. package/dist/react-native/util/connectionStringUtils.js +48 -0
  211. package/dist/react-native/util/connectionStringUtils.js.map +1 -0
  212. package/dist/react-native/util/constants.d.ts +25 -0
  213. package/dist/react-native/util/constants.d.ts.map +1 -0
  214. package/dist/react-native/util/constants.js +27 -0
  215. package/dist/react-native/util/constants.js.map +1 -0
  216. package/dist/react-native/util/delayWithoutThrow.d.ts +8 -0
  217. package/dist/react-native/util/delayWithoutThrow.d.ts.map +1 -0
  218. package/dist/react-native/util/delayWithoutThrow.js +17 -0
  219. package/dist/react-native/util/delayWithoutThrow.js.map +1 -0
  220. package/dist/react-native/util/error.d.ts +39 -0
  221. package/dist/react-native/util/error.d.ts.map +1 -0
  222. package/dist/react-native/util/error.js +103 -0
  223. package/dist/react-native/util/error.js.map +1 -0
  224. package/dist/react-native/util/getPromiseParts.d.ts +10 -0
  225. package/dist/react-native/util/getPromiseParts.d.ts.map +1 -0
  226. package/dist/react-native/util/getPromiseParts.js +20 -0
  227. package/dist/react-native/util/getPromiseParts.js.map +1 -0
  228. package/dist/react-native/util/operationOptions.d.ts +16 -0
  229. package/dist/react-native/util/operationOptions.d.ts.map +1 -0
  230. package/dist/react-native/util/operationOptions.js +4 -0
  231. package/dist/react-native/util/operationOptions.js.map +1 -0
  232. package/dist/react-native/util/parseEndpoint.d.ts +11 -0
  233. package/dist/react-native/util/parseEndpoint.d.ts.map +1 -0
  234. package/dist/react-native/util/parseEndpoint.js +17 -0
  235. package/dist/react-native/util/parseEndpoint.js.map +1 -0
  236. package/dist/react-native/util/retries.d.ts +6 -0
  237. package/dist/react-native/util/retries.d.ts.map +1 -0
  238. package/dist/react-native/util/retries.js +13 -0
  239. package/dist/react-native/util/retries.js.map +1 -0
  240. package/dist/react-native/util/runtimeInfo-react-native.d.mts.map +1 -0
  241. package/dist/react-native/util/runtimeInfo-react-native.mjs.map +1 -0
  242. package/dist/react-native/util/runtimeInfo.d.ts +6 -0
  243. package/dist/react-native/util/runtimeInfo.js +20 -0
  244. package/dist/react-native/util/timerLoop.d.ts +26 -0
  245. package/dist/react-native/util/timerLoop.d.ts.map +1 -0
  246. package/dist/react-native/util/timerLoop.js +34 -0
  247. package/dist/react-native/util/timerLoop.js.map +1 -0
  248. package/dist/react-native/util/typeGuards.d.ts +8 -0
  249. package/dist/react-native/util/typeGuards.d.ts.map +1 -0
  250. package/dist/react-native/util/typeGuards.js +12 -0
  251. package/dist/react-native/util/typeGuards.js.map +1 -0
  252. package/dist/react-native/util/utils.d.ts +7 -0
  253. package/dist/react-native/util/utils.d.ts.map +1 -0
  254. package/dist/react-native/util/utils.js +13 -0
  255. package/dist/react-native/util/utils.js.map +1 -0
  256. package/dist/react-native/withAuth.d.ts +25 -0
  257. package/dist/react-native/withAuth.d.ts.map +1 -0
  258. package/dist/react-native/withAuth.js +84 -0
  259. package/dist/react-native/withAuth.js.map +1 -0
  260. package/package.json +16 -11
@@ -0,0 +1,247 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { AmqpAnnotatedMessage, Constants } from "@azure/core-amqp";
4
+ import { defaultDataTransformer } from "./dataTransformer.js";
5
+ import { types } from "rhea-promise";
6
+ import { isDefined, isObjectWithProperties, objectHasProperty } from "@azure/core-util";
7
+ import { idempotentProducerAmqpPropertyNames } from "./util/constants.js";
8
+ import isBuffer from "is-buffer";
9
+ const messagePropertiesMap = {
10
+ message_id: "messageId",
11
+ user_id: "userId",
12
+ to: "to",
13
+ subject: "subject",
14
+ reply_to: "replyTo",
15
+ correlation_id: "correlationId",
16
+ content_type: "contentType",
17
+ content_encoding: "contentEncoding",
18
+ absolute_expiry_time: "absoluteExpiryTime",
19
+ creation_time: "creationTime",
20
+ group_id: "groupId",
21
+ group_sequence: "groupSequence",
22
+ reply_to_group_id: "replyToGroupId",
23
+ };
24
+ /**
25
+ * Converts the AMQP message to an EventData.
26
+ * @param msg - The AMQP message that needs to be converted to EventData.
27
+ * @param skipParsingBodyAsJson - Boolean to skip running JSON.parse() on message body when body type is `content`.
28
+ * @internal
29
+ */
30
+ export function fromRheaMessage(msg, skipParsingBodyAsJson) {
31
+ const rawMessage = AmqpAnnotatedMessage.fromRheaMessage(msg);
32
+ const { body, bodyType } = defaultDataTransformer.decode(msg.body, skipParsingBodyAsJson);
33
+ rawMessage.bodyType = bodyType;
34
+ const data = {
35
+ body,
36
+ getRawAmqpMessage() {
37
+ return rawMessage;
38
+ },
39
+ };
40
+ if (msg.message_annotations) {
41
+ for (const annotationKey of Object.keys(msg.message_annotations)) {
42
+ switch (annotationKey) {
43
+ case Constants.partitionKey:
44
+ data.partitionKey = msg.message_annotations[annotationKey];
45
+ break;
46
+ case Constants.sequenceNumber:
47
+ data.sequenceNumber = msg.message_annotations[annotationKey];
48
+ break;
49
+ case Constants.enqueuedTime:
50
+ data.enqueuedTimeUtc = new Date(msg.message_annotations[annotationKey]);
51
+ break;
52
+ case Constants.offset:
53
+ data.offset = msg.message_annotations[annotationKey];
54
+ break;
55
+ default:
56
+ if (!data.systemProperties) {
57
+ data.systemProperties = {};
58
+ }
59
+ data.systemProperties[annotationKey] = convertDatesToNumbers(msg.message_annotations[annotationKey]);
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ if (msg.application_properties) {
65
+ data.properties = convertDatesToNumbers(msg.application_properties);
66
+ }
67
+ if (msg.delivery_annotations) {
68
+ data.lastEnqueuedOffset = msg.delivery_annotations.last_enqueued_offset;
69
+ data.lastSequenceNumber = msg.delivery_annotations.last_enqueued_sequence_number;
70
+ data.lastEnqueuedTime = new Date(msg.delivery_annotations.last_enqueued_time_utc);
71
+ data.retrievalTime = new Date(msg.delivery_annotations.runtime_info_retrieval_time_utc);
72
+ }
73
+ const messageProperties = Object.keys(messagePropertiesMap);
74
+ for (const messageProperty of messageProperties) {
75
+ if (!data.systemProperties) {
76
+ data.systemProperties = {};
77
+ }
78
+ if (msg[messageProperty] != null) {
79
+ data.systemProperties[messagePropertiesMap[messageProperty]] = convertDatesToNumbers(msg[messageProperty]);
80
+ }
81
+ }
82
+ if (msg.content_type != null) {
83
+ data.contentType = msg.content_type;
84
+ }
85
+ if (msg.correlation_id != null) {
86
+ data.correlationId = msg.correlation_id;
87
+ }
88
+ if (msg.message_id != null) {
89
+ data.messageId = msg.message_id;
90
+ }
91
+ return data;
92
+ }
93
+ /**
94
+ * Converts an EventData object to an AMQP message.
95
+ * @param data - The EventData object that needs to be converted to an AMQP message.
96
+ * @param partitionKey - An optional key to determine the partition that this event should land in.
97
+ * @internal
98
+ */
99
+ export function toRheaMessage(data, partitionKey) {
100
+ let rheaMessage;
101
+ if (isAmqpAnnotatedMessage(data)) {
102
+ rheaMessage = {
103
+ ...AmqpAnnotatedMessage.toRheaMessage(data),
104
+ body: defaultDataTransformer.encode(data.body, data.bodyType ?? "data"),
105
+ };
106
+ }
107
+ else {
108
+ let bodyType = "data";
109
+ if (typeof data.getRawAmqpMessage === "function") {
110
+ /*
111
+ If the event is being round-tripped, then we respect the `bodyType` of the
112
+ underlying AMQP message.
113
+ */
114
+ bodyType = data.getRawAmqpMessage().bodyType ?? "data";
115
+ }
116
+ rheaMessage = {
117
+ body: defaultDataTransformer.encode(data.body, bodyType),
118
+ };
119
+ // As per the AMQP 1.0 spec If the message-annotations or delivery-annotations section is omitted,
120
+ // it is equivalent to a message-annotations section containing empty map of annotations.
121
+ rheaMessage.message_annotations = {};
122
+ if (data.properties) {
123
+ rheaMessage.application_properties = data.properties;
124
+ }
125
+ if (isDefined(partitionKey)) {
126
+ rheaMessage.message_annotations[Constants.partitionKey] = partitionKey;
127
+ // Event Hub service cannot route messages to a specific partition based on the partition key
128
+ // if AMQP message header is an empty object. Hence we make sure that header is always present
129
+ // with atleast one property. Setting durable to true, helps us achieve that.
130
+ rheaMessage.durable = true;
131
+ }
132
+ if (data.contentType != null) {
133
+ rheaMessage.content_type = data.contentType;
134
+ }
135
+ if (data.correlationId != null) {
136
+ rheaMessage.correlation_id = data.correlationId;
137
+ }
138
+ if (data.messageId != null) {
139
+ if (typeof data.messageId === "string" &&
140
+ data.messageId.length > Constants.maxMessageIdLength) {
141
+ throw new Error(`Length of 'messageId' property on the event cannot be greater than ${Constants.maxMessageIdLength} characters.`);
142
+ }
143
+ rheaMessage.message_id = data.messageId;
144
+ }
145
+ }
146
+ return rheaMessage;
147
+ }
148
+ /**
149
+ * Asserts that the provided data conforms to the `EventData` interface.
150
+ *
151
+ * This function performs runtime checks on the `data` object to ensure it matches the expected
152
+ * structure and types defined in the `EventData` interface. If any of the checks fail, it throws
153
+ * an error with a descriptive message indicating the mismatch.
154
+ *
155
+ * @param data - The data object to validate as `EventData`.
156
+ * @throws \{Error\} Throws an error if the data does not conform to the `EventData` interface.
157
+ */
158
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
159
+ export function assertIsEventData(data) {
160
+ if (data.contentType != null && typeof data.contentType !== "string") {
161
+ throw new Error(`Invalid 'contentType': expected 'string' or 'undefined', but received '${typeof data.contentType}'.`);
162
+ }
163
+ if (data.correlationId != null &&
164
+ typeof data.correlationId !== "string" &&
165
+ typeof data.correlationId !== "number" &&
166
+ !isBuffer(data.correlationId)) {
167
+ throw new Error(`Invalid 'correlationId': expected 'string', 'number', 'Buffer', or 'undefined', but received '${typeof data.correlationId}'.`);
168
+ }
169
+ if (data.messageId != null &&
170
+ typeof data.messageId !== "string" &&
171
+ typeof data.messageId !== "number" &&
172
+ !isBuffer(data.messageId)) {
173
+ throw new Error(`Invalid 'messageId': expected 'string', 'number', 'Buffer', or 'undefined', but received '${typeof data.messageId}'.`);
174
+ }
175
+ if (data.properties !== undefined &&
176
+ (typeof data.properties !== "object" || Array.isArray(data.properties))) {
177
+ const actualType = Array.isArray(data.properties) ? "array" : typeof data.properties;
178
+ throw new Error(`Invalid 'properties': expected an object or 'undefined', but received '${actualType}'.`);
179
+ }
180
+ }
181
+ /**
182
+ * @internal
183
+ */
184
+ export function isAmqpAnnotatedMessage(possible) {
185
+ return (isObjectWithProperties(possible, ["body", "bodyType"]) &&
186
+ !objectHasProperty(possible, "getRawAmqpMessage"));
187
+ }
188
+ /**
189
+ * Converts any Date objects into a number representing date.getTime().
190
+ * Recursively checks for any Date objects in arrays and objects.
191
+ * @internal
192
+ */
193
+ function convertDatesToNumbers(thing) {
194
+ // fast exit
195
+ if (!isDefined(thing))
196
+ return thing;
197
+ // When 'thing' is a Date, return the number representation
198
+ if (typeof thing === "object" &&
199
+ objectHasProperty(thing, "getTime") &&
200
+ typeof thing.getTime === "function") {
201
+ return thing.getTime();
202
+ }
203
+ /*
204
+ Examples:
205
+ [0, 'foo', new Date(), { nested: new Date()}]
206
+ */
207
+ if (Array.isArray(thing)) {
208
+ return thing.map(convertDatesToNumbers);
209
+ }
210
+ /*
211
+ Examples:
212
+ { foo: new Date(), children: { nested: new Date() }}
213
+ */
214
+ if (typeof thing === "object" && isDefined(thing)) {
215
+ const thingShallowCopy = { ...thing };
216
+ for (const key of Object.keys(thingShallowCopy)) {
217
+ thingShallowCopy[key] = convertDatesToNumbers(thingShallowCopy[key]);
218
+ }
219
+ return thingShallowCopy;
220
+ }
221
+ return thing;
222
+ }
223
+ /**
224
+ * Populates a rhea message with idempotent producer properties.
225
+ * @internal
226
+ */
227
+ export function populateIdempotentMessageAnnotations(rheaMessage, { isIdempotentPublishingEnabled, ownerLevel, producerGroupId, publishSequenceNumber, }) {
228
+ if (!isIdempotentPublishingEnabled) {
229
+ return;
230
+ }
231
+ const messageAnnotations = rheaMessage.message_annotations || {};
232
+ if (!rheaMessage.message_annotations) {
233
+ rheaMessage.message_annotations = messageAnnotations;
234
+ }
235
+ if (isDefined(ownerLevel)) {
236
+ messageAnnotations[idempotentProducerAmqpPropertyNames.epoch] = types.wrap_short(ownerLevel);
237
+ }
238
+ if (isDefined(producerGroupId)) {
239
+ messageAnnotations[idempotentProducerAmqpPropertyNames.producerId] =
240
+ types.wrap_long(producerGroupId);
241
+ }
242
+ if (isDefined(publishSequenceNumber)) {
243
+ messageAnnotations[idempotentProducerAmqpPropertyNames.producerSequenceNumber] =
244
+ types.wrap_int(publishSequenceNumber);
245
+ }
246
+ }
247
+ //# sourceMappingURL=eventData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventData.js","sourceRoot":"","sources":["../../src/eventData.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,mCAAmC,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,QAAQ,MAAM,WAAW,CAAC;AA+IjC,MAAM,oBAAoB,GAAG;IAC3B,UAAU,EAAE,WAAW;IACvB,OAAO,EAAE,QAAQ;IACjB,EAAE,EAAE,IAAI;IACR,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,SAAS;IACnB,cAAc,EAA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CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC;QAC/B,kBAAkB,CAAC,mCAAmC,CAAC,UAAU,CAAC;YAChE,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,SAAS,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACrC,kBAAkB,CAAC,mCAAmC,CAAC,sBAAsB,CAAC;YAC5E,KAAK,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AmqpAnnotatedMessage, Constants } from \"@azure/core-amqp\";\nimport type { BodyTypes } from \"./dataTransformer.js\";\nimport { defaultDataTransformer } from \"./dataTransformer.js\";\nimport type { DeliveryAnnotations, MessageAnnotations, Message as RheaMessage } from \"rhea-promise\";\nimport { types } from \"rhea-promise\";\nimport { isDefined, isObjectWithProperties, objectHasProperty } from \"@azure/core-util\";\nimport type { PENDING_PUBLISH_SEQ_NUM_SYMBOL } from \"./util/constants.js\";\nimport { idempotentProducerAmqpPropertyNames } from \"./util/constants.js\";\nimport isBuffer from \"is-buffer\";\n\n/**\n * Describes the delivery annotations.\n * @internal\n */\nexport interface EventHubDeliveryAnnotations extends DeliveryAnnotations {\n /**\n * The offset of the last event.\n */\n last_enqueued_offset?: string;\n /**\n * The sequence number of the last event.\n */\n last_enqueued_sequence_number?: number;\n /**\n * The enqueued time of the last event.\n */\n last_enqueued_time_utc?: number;\n /**\n * The retrieval time of the last event.\n */\n runtime_info_retrieval_time_utc?: number;\n /**\n * Any unknown delivery annotations.\n */\n [x: string]: any;\n}\n\n/**\n * Map containing message attributes that will be held in the message header.\n * @internal\n */\nexport interface EventHubMessageAnnotations extends MessageAnnotations {\n /**\n * Annotation for the partition key set for the event.\n */\n \"x-opt-partition-key\"?: string | null;\n /**\n * Annotation for the sequence number of the event.\n */\n \"x-opt-sequence-number\"?: number;\n /**\n * Annotation for the enqueued time of the event.\n */\n \"x-opt-enqueued-time\"?: number;\n /**\n * Annotation for the offset of the event.\n */\n \"x-opt-offset\"?: string;\n /**\n * Any other annotation that can be added to the message.\n */\n [x: string]: any;\n}\n\n/**\n * Describes the structure of an event to be sent or received from the EventHub.\n * @internal\n */\nexport interface EventDataInternal {\n /**\n * The message body that needs to be sent or is received.\n */\n body: any;\n /**\n * The enqueued time of the event.\n */\n enqueuedTimeUtc?: Date;\n /**\n * If specified EventHub will hash this to a partitionId.\n * It guarantees that messages end up in a specific partition on the event hub.\n */\n partitionKey?: string | null;\n /**\n * The offset of the event.\n */\n offset?: string;\n /**\n * The sequence number of the event.\n */\n sequenceNumber?: number;\n /**\n * The application specific properties.\n */\n properties?: { [property: string]: any };\n /**\n * The last sequence number of the event within the partition stream of the Event Hub.\n */\n lastSequenceNumber?: number;\n /**\n * The offset of the last enqueued event.\n */\n lastEnqueuedOffset?: string;\n /**\n * The enqueued UTC time of the last event.\n */\n lastEnqueuedTime?: Date;\n /**\n * The time when the runtime info was retrieved\n */\n retrievalTime?: Date;\n /**\n * The properties set by the service.\n */\n systemProperties?: { [property: string]: any };\n /**\n * The content type of the message. Optionally describes\n * the payload of the message, with a descriptor following the format of RFC2045, Section 5, for\n * example \"application/json\".\n */\n contentType?: string;\n\n /**\n * The correlation identifier that allows an\n * application to specify a context for the message for the purposes of correlation, for example\n * reflecting the MessageId of a message that is being replied to.\n */\n correlationId?: string | number | Buffer;\n\n /**\n * The message identifier is an\n * application-defined value that uniquely identifies the message and its payload.\n *\n * Note: Numbers that are not whole integers are not allowed.\n */\n messageId?: string | number | Buffer;\n /**\n * Returns the underlying raw amqp message.\n */\n getRawAmqpMessage(): AmqpAnnotatedMessage;\n /**\n * The pending publish sequence number, set while the event\n * is being published with idempotent partitions enabled.\n */\n [PENDING_PUBLISH_SEQ_NUM_SYMBOL]?: number;\n /**\n * The sequence number the event was published with\n * when idempotent partitions are enabled.\n */\n _publishedSequenceNumber?: number;\n}\n\nconst messagePropertiesMap = {\n message_id: \"messageId\",\n user_id: \"userId\",\n to: \"to\",\n subject: \"subject\",\n reply_to: \"replyTo\",\n correlation_id: \"correlationId\",\n content_type: \"contentType\",\n content_encoding: \"contentEncoding\",\n absolute_expiry_time: \"absoluteExpiryTime\",\n creation_time: \"creationTime\",\n group_id: \"groupId\",\n group_sequence: \"groupSequence\",\n reply_to_group_id: \"replyToGroupId\",\n} as const;\n\n/**\n * Converts the AMQP message to an EventData.\n * @param msg - The AMQP message that needs to be converted to EventData.\n * @param skipParsingBodyAsJson - Boolean to skip running JSON.parse() on message body when body type is `content`.\n * @internal\n */\nexport function fromRheaMessage(\n msg: RheaMessage,\n skipParsingBodyAsJson: boolean,\n): EventDataInternal {\n const rawMessage = AmqpAnnotatedMessage.fromRheaMessage(msg);\n const { body, bodyType } = defaultDataTransformer.decode(msg.body, skipParsingBodyAsJson);\n rawMessage.bodyType = bodyType;\n\n const data: EventDataInternal = {\n body,\n getRawAmqpMessage() {\n return rawMessage;\n },\n };\n\n if (msg.message_annotations) {\n for (const annotationKey of Object.keys(msg.message_annotations)) {\n switch (annotationKey) {\n case Constants.partitionKey:\n data.partitionKey = msg.message_annotations[annotationKey];\n break;\n case Constants.sequenceNumber:\n data.sequenceNumber = msg.message_annotations[annotationKey];\n break;\n case Constants.enqueuedTime:\n data.enqueuedTimeUtc = new Date(msg.message_annotations[annotationKey]);\n break;\n case Constants.offset:\n data.offset = msg.message_annotations[annotationKey];\n break;\n default:\n if (!data.systemProperties) {\n data.systemProperties = {};\n }\n data.systemProperties[annotationKey] = convertDatesToNumbers(\n msg.message_annotations[annotationKey],\n );\n break;\n }\n }\n }\n if (msg.application_properties) {\n data.properties = convertDatesToNumbers(msg.application_properties);\n }\n if (msg.delivery_annotations) {\n data.lastEnqueuedOffset = msg.delivery_annotations.last_enqueued_offset;\n data.lastSequenceNumber = msg.delivery_annotations.last_enqueued_sequence_number;\n data.lastEnqueuedTime = new Date(msg.delivery_annotations.last_enqueued_time_utc as number);\n data.retrievalTime = new Date(\n msg.delivery_annotations.runtime_info_retrieval_time_utc as number,\n );\n }\n\n const messageProperties = Object.keys(messagePropertiesMap) as Array<\n keyof typeof messagePropertiesMap\n >;\n for (const messageProperty of messageProperties) {\n if (!data.systemProperties) {\n data.systemProperties = {};\n }\n if (msg[messageProperty] != null) {\n data.systemProperties[messagePropertiesMap[messageProperty]] = convertDatesToNumbers(\n msg[messageProperty],\n );\n }\n }\n\n if (msg.content_type != null) {\n data.contentType = msg.content_type;\n }\n if (msg.correlation_id != null) {\n data.correlationId = msg.correlation_id;\n }\n if (msg.message_id != null) {\n data.messageId = msg.message_id;\n }\n\n return data;\n}\n\n/**\n * Converts an EventData object to an AMQP message.\n * @param data - The EventData object that needs to be converted to an AMQP message.\n * @param partitionKey - An optional key to determine the partition that this event should land in.\n * @internal\n */\nexport function toRheaMessage(\n data: EventData | AmqpAnnotatedMessage,\n partitionKey?: string,\n): RheaMessage {\n let rheaMessage: RheaMessage;\n if (isAmqpAnnotatedMessage(data)) {\n rheaMessage = {\n ...AmqpAnnotatedMessage.toRheaMessage(data),\n body: defaultDataTransformer.encode(data.body, data.bodyType ?? \"data\"),\n };\n } else {\n let bodyType: BodyTypes = \"data\";\n if (typeof (data as EventDataInternal).getRawAmqpMessage === \"function\") {\n /*\n If the event is being round-tripped, then we respect the `bodyType` of the\n underlying AMQP message.\n */\n bodyType = (data as EventDataInternal).getRawAmqpMessage().bodyType ?? \"data\";\n }\n\n rheaMessage = {\n body: defaultDataTransformer.encode(data.body, bodyType),\n };\n // As per the AMQP 1.0 spec If the message-annotations or delivery-annotations section is omitted,\n // it is equivalent to a message-annotations section containing empty map of annotations.\n rheaMessage.message_annotations = {};\n\n if (data.properties) {\n rheaMessage.application_properties = data.properties;\n }\n\n if (isDefined(partitionKey)) {\n rheaMessage.message_annotations[Constants.partitionKey] = partitionKey;\n // Event Hub service cannot route messages to a specific partition based on the partition key\n // if AMQP message header is an empty object. Hence we make sure that header is always present\n // with atleast one property. Setting durable to true, helps us achieve that.\n rheaMessage.durable = true;\n }\n\n if (data.contentType != null) {\n rheaMessage.content_type = data.contentType;\n }\n if (data.correlationId != null) {\n rheaMessage.correlation_id = data.correlationId;\n }\n if (data.messageId != null) {\n if (\n typeof data.messageId === \"string\" &&\n data.messageId.length > Constants.maxMessageIdLength\n ) {\n throw new Error(\n `Length of 'messageId' property on the event cannot be greater than ${Constants.maxMessageIdLength} characters.`,\n );\n }\n rheaMessage.message_id = data.messageId;\n }\n }\n\n return rheaMessage;\n}\n\n/**\n * The interface that describes the data to be sent to Event Hub.\n * Use this as a reference when creating the object to be sent when using the `EventHubProducerClient`.\n * For example, `{ body: \"your-data\" }` or\n * ```\n * {\n * body: \"your-data\",\n * properties: {\n * propertyName: \"property value\"\n * }\n * }\n * ```\n */\nexport interface EventData {\n /**\n * The message body that needs to be sent.\n * If the application reading the events is not using this SDK,\n * convert your body payload to a byte array or Buffer for better\n * cross-language compatibility.\n */\n body: any;\n\n /**\n * The content type of the message. Optionally describes\n * the payload of the message, with a descriptor following the format of RFC2045, Section 5, for\n * example \"application/json\".\n */\n contentType?: string;\n\n /**\n * The correlation identifier that allows an\n * application to specify a context for the message for the purposes of correlation, for example\n * reflecting the MessageId of a message that is being replied to.\n */\n correlationId?: string | number | Buffer;\n\n /**\n * The message identifier is an\n * application-defined value that uniquely identifies the message and its payload.\n *\n * Note: Numbers that are not whole integers are not allowed.\n */\n messageId?: string | number | Buffer;\n\n /**\n * Set of key value pairs that can be used to set properties specific to user application.\n */\n properties?: {\n [key: string]: any;\n };\n}\n\n/**\n * Asserts that the provided data conforms to the `EventData` interface.\n *\n * This function performs runtime checks on the `data` object to ensure it matches the expected\n * structure and types defined in the `EventData` interface. If any of the checks fail, it throws\n * an error with a descriptive message indicating the mismatch.\n *\n * @param data - The data object to validate as `EventData`.\n * @throws \\{Error\\} Throws an error if the data does not conform to the `EventData` interface.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function assertIsEventData(data: any): asserts data is EventData {\n if (data.contentType != null && typeof data.contentType !== \"string\") {\n throw new Error(\n `Invalid 'contentType': expected 'string' or 'undefined', but received '${typeof data.contentType}'.`,\n );\n }\n\n if (\n data.correlationId != null &&\n typeof data.correlationId !== \"string\" &&\n typeof data.correlationId !== \"number\" &&\n !isBuffer(data.correlationId)\n ) {\n throw new Error(\n `Invalid 'correlationId': expected 'string', 'number', 'Buffer', or 'undefined', but received '${typeof data.correlationId}'.`,\n );\n }\n\n if (\n data.messageId != null &&\n typeof data.messageId !== \"string\" &&\n typeof data.messageId !== \"number\" &&\n !isBuffer(data.messageId)\n ) {\n throw new Error(\n `Invalid 'messageId': expected 'string', 'number', 'Buffer', or 'undefined', but received '${typeof data.messageId}'.`,\n );\n }\n\n if (\n data.properties !== undefined &&\n (typeof data.properties !== \"object\" || Array.isArray(data.properties))\n ) {\n const actualType = Array.isArray(data.properties) ? \"array\" : typeof data.properties;\n throw new Error(\n `Invalid 'properties': expected an object or 'undefined', but received '${actualType}'.`,\n );\n }\n}\n\n/**\n * The interface that describes the structure of the event received from Event Hub.\n * Use this as a reference when creating the `processEvents` function to process the events\n * received from an Event Hub when using the `EventHubConsumerClient`.\n */\nexport interface ReceivedEventData {\n /**\n * The message body that needs to be sent or is received.\n */\n body: any;\n /**\n * The application specific properties.\n */\n properties?: {\n [key: string]: any;\n };\n /**\n * The enqueued time of the event.\n */\n enqueuedTimeUtc: Date;\n /**\n * When specified Event Hub will hash this to a partitionId.\n * It guarantees that messages end up in a specific partition on the event hub.\n */\n partitionKey: string | null;\n /**\n * The offset of the event.\n */\n offset: string;\n /**\n * The sequence number of the event.\n */\n sequenceNumber: number;\n /**\n * The properties set by the service.\n */\n systemProperties?: {\n [key: string]: any;\n };\n\n /**\n * The content type of the message. Optionally describes\n * the payload of the message, with a descriptor following the format of RFC2045, Section 5, for\n * example \"application/json\".\n */\n contentType?: string;\n\n /**\n * The correlation identifier that allows an\n * application to specify a context for the message for the purposes of correlation, for example\n * reflecting the MessageId of a message that is being replied to.\n */\n correlationId?: string | number | Buffer;\n\n /**\n * The message identifier is an\n * application-defined value that uniquely identifies the message and its payload.\n */\n messageId?: string | number | Buffer;\n\n /**\n * Returns the underlying raw amqp message.\n */\n getRawAmqpMessage(): AmqpAnnotatedMessage;\n}\n\n/**\n * @internal\n */\nexport function isAmqpAnnotatedMessage(possible: unknown): possible is AmqpAnnotatedMessage {\n return (\n isObjectWithProperties(possible, [\"body\", \"bodyType\"]) &&\n !objectHasProperty(possible, \"getRawAmqpMessage\")\n );\n}\n\n/**\n * Converts any Date objects into a number representing date.getTime().\n * Recursively checks for any Date objects in arrays and objects.\n * @internal\n */\nfunction convertDatesToNumbers<T = unknown>(thing: T): T {\n // fast exit\n if (!isDefined(thing)) return thing;\n\n // When 'thing' is a Date, return the number representation\n if (\n typeof thing === \"object\" &&\n objectHasProperty(thing, \"getTime\") &&\n typeof thing.getTime === \"function\"\n ) {\n return thing.getTime();\n }\n\n /*\n Examples:\n [0, 'foo', new Date(), { nested: new Date()}]\n */\n if (Array.isArray(thing)) {\n return thing.map(convertDatesToNumbers) as unknown as T;\n }\n\n /*\n Examples:\n { foo: new Date(), children: { nested: new Date() }}\n */\n if (typeof thing === \"object\" && isDefined<object>(thing)) {\n const thingShallowCopy = { ...thing };\n for (const key of Object.keys(thingShallowCopy)) {\n (thingShallowCopy as any)[key] = convertDatesToNumbers((thingShallowCopy as any)[key]);\n }\n return thingShallowCopy;\n }\n\n return thing;\n}\n\n/**\n * @internal\n */\nexport interface PopulateIdempotentMessageAnnotationsParameters {\n isIdempotentPublishingEnabled: boolean;\n ownerLevel?: number;\n producerGroupId?: number;\n publishSequenceNumber?: number;\n}\n\n/**\n * Populates a rhea message with idempotent producer properties.\n * @internal\n */\nexport function populateIdempotentMessageAnnotations(\n rheaMessage: RheaMessage,\n {\n isIdempotentPublishingEnabled,\n ownerLevel,\n producerGroupId,\n publishSequenceNumber,\n }: PopulateIdempotentMessageAnnotationsParameters,\n): void {\n if (!isIdempotentPublishingEnabled) {\n return;\n }\n\n const messageAnnotations = rheaMessage.message_annotations || {};\n if (!rheaMessage.message_annotations) {\n rheaMessage.message_annotations = messageAnnotations;\n }\n\n if (isDefined(ownerLevel)) {\n messageAnnotations[idempotentProducerAmqpPropertyNames.epoch] = types.wrap_short(ownerLevel);\n }\n if (isDefined(producerGroupId)) {\n messageAnnotations[idempotentProducerAmqpPropertyNames.producerId] =\n types.wrap_long(producerGroupId);\n }\n if (isDefined(publishSequenceNumber)) {\n messageAnnotations[idempotentProducerAmqpPropertyNames.producerSequenceNumber] =\n types.wrap_int(publishSequenceNumber);\n }\n}\n"]}
@@ -0,0 +1,69 @@
1
+ import type { EventData } from "./eventData.js";
2
+ /**
3
+ * A message with payload and content type fields
4
+ *
5
+ * This interface is hidden because it is already exported by `@azure/schema-registry-avro`
6
+ *
7
+ * @hidden
8
+ */
9
+ export interface MessageContent {
10
+ /**
11
+ * The message's binary data
12
+ */
13
+ data: Uint8Array;
14
+ /**
15
+ * The message's content type
16
+ */
17
+ contentType: string;
18
+ }
19
+ /**
20
+ * A message adapter interface that specifies methods for producing and consuming
21
+ * messages with payloads and content type fields.
22
+ *
23
+ * This interface is hidden because it is already exported by `@azure/schema-registry-avro`
24
+ *
25
+ * @hidden
26
+ */
27
+ export interface MessageAdapter<MessageT> {
28
+ /**
29
+ * defines how to create a message from a payload and a content type
30
+ */
31
+ produce: (MessageContent: MessageContent) => MessageT;
32
+ /**
33
+ * defines how to access the payload and the content type of a message
34
+ */
35
+ consume: (message: MessageT) => MessageContent;
36
+ }
37
+ /**
38
+ * Parameters to the `createEventDataAdapter` function that creates an event data adapter.
39
+ */
40
+ export interface EventDataAdapterParameters {
41
+ /**
42
+ * The correlation identifier that allows an
43
+ * application to specify a context for the message for the purposes of correlation, for example
44
+ * reflecting the MessageId of a message that is being replied to.
45
+ */
46
+ correlationId?: string | number | Buffer;
47
+ /**
48
+ * The message identifier is an
49
+ * application-defined value that uniquely identifies the message and its payload.
50
+ *
51
+ * Note: Numbers that are not whole integers are not allowed.
52
+ */
53
+ messageId?: string | number | Buffer;
54
+ /**
55
+ * Set of key value pairs that can be used to set properties specific to user application.
56
+ */
57
+ properties?: {
58
+ [key: string]: any;
59
+ };
60
+ }
61
+ /**
62
+ * A function that constructs an event data adapter. That adapter can be used
63
+ * with `@azure/schema-registry-avro` to encode and decode body in event data.
64
+ *
65
+ * @param params - parameters to create the event data
66
+ * @returns An event data adapter that can produce and consume event data
67
+ */
68
+ export declare function createEventDataAdapter(params?: EventDataAdapterParameters): MessageAdapter<EventData>;
69
+ //# sourceMappingURL=eventDataAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventDataAdapter.d.ts","sourceRoot":"","sources":["../../src/eventDataAdapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;IACjB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,QAAQ;IACtC;;OAEG;IACH,OAAO,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,QAAQ,CAAC;IACtD;;OAEG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,cAAc,CAAC;CAChD;AAGD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAEzC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAErC;;OAEG;IACH,UAAU,CAAC,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,GAAE,0BAA+B,GACtC,cAAc,CAAC,SAAS,CAAC,CA2B3B"}
@@ -0,0 +1,38 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * A function that constructs an event data adapter. That adapter can be used
5
+ * with `@azure/schema-registry-avro` to encode and decode body in event data.
6
+ *
7
+ * @param params - parameters to create the event data
8
+ * @returns An event data adapter that can produce and consume event data
9
+ */
10
+ export function createEventDataAdapter(params = {}) {
11
+ return {
12
+ produce: ({ data: body, contentType }) => {
13
+ return {
14
+ ...params,
15
+ body,
16
+ contentType,
17
+ };
18
+ },
19
+ consume: (message) => {
20
+ const { body, contentType } = message;
21
+ if (body === undefined) {
22
+ throw new Error("Expected the body field to be defined");
23
+ }
24
+ if (contentType === undefined) {
25
+ throw new Error("Expected the contentType field to be defined");
26
+ }
27
+ return {
28
+ /**
29
+ * If the raw response was parsed as JSON, we need to convert it to a Uint8Array,
30
+ * otherwise, leave the payload as is.
31
+ */
32
+ data: typeof body === "object" ? Uint8Array.from(Object.values(body)) : body,
33
+ contentType,
34
+ };
35
+ },
36
+ };
37
+ }
38
+ //# sourceMappingURL=eventDataAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventDataAdapter.js","sourceRoot":"","sources":["../../src/eventDataAdapter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAqElC;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAAqC,EAAE;IAEvC,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAkB,EAAE,EAAE;YACvD,OAAO;gBACL,GAAG,MAAM;gBACT,IAAI;gBACJ,WAAW;aACZ,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC,OAAkB,EAAkB,EAAE;YAC9C,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;YACtC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;YACD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAClE,CAAC;YACD,OAAO;gBACL;;;mBAGG;gBACH,IAAI,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;gBAC5E,WAAW;aACZ,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { EventData } from \"./eventData.js\";\n\n/**\n * A message with payload and content type fields\n *\n * This interface is hidden because it is already exported by `@azure/schema-registry-avro`\n *\n * @hidden\n */\nexport interface MessageContent {\n /**\n * The message's binary data\n */\n data: Uint8Array;\n /**\n * The message's content type\n */\n contentType: string;\n}\n\n/**\n * A message adapter interface that specifies methods for producing and consuming\n * messages with payloads and content type fields.\n *\n * This interface is hidden because it is already exported by `@azure/schema-registry-avro`\n *\n * @hidden\n */\nexport interface MessageAdapter<MessageT> {\n /**\n * defines how to create a message from a payload and a content type\n */\n produce: (MessageContent: MessageContent) => MessageT;\n /**\n * defines how to access the payload and the content type of a message\n */\n consume: (message: MessageT) => MessageContent;\n}\n\n// This type should always be equivalent to Omit<Omit<EventData, \"body\">, \"contentType\">\n/**\n * Parameters to the `createEventDataAdapter` function that creates an event data adapter.\n */\nexport interface EventDataAdapterParameters {\n /**\n * The correlation identifier that allows an\n * application to specify a context for the message for the purposes of correlation, for example\n * reflecting the MessageId of a message that is being replied to.\n */\n correlationId?: string | number | Buffer;\n\n /**\n * The message identifier is an\n * application-defined value that uniquely identifies the message and its payload.\n *\n * Note: Numbers that are not whole integers are not allowed.\n */\n messageId?: string | number | Buffer;\n\n /**\n * Set of key value pairs that can be used to set properties specific to user application.\n */\n properties?: {\n [key: string]: any;\n };\n}\n\n/**\n * A function that constructs an event data adapter. That adapter can be used\n * with `@azure/schema-registry-avro` to encode and decode body in event data.\n *\n * @param params - parameters to create the event data\n * @returns An event data adapter that can produce and consume event data\n */\nexport function createEventDataAdapter(\n params: EventDataAdapterParameters = {},\n): MessageAdapter<EventData> {\n return {\n produce: ({ data: body, contentType }: MessageContent) => {\n return {\n ...params,\n body,\n contentType,\n };\n },\n consume: (message: EventData): MessageContent => {\n const { body, contentType } = message;\n if (body === undefined) {\n throw new Error(\"Expected the body field to be defined\");\n }\n if (contentType === undefined) {\n throw new Error(\"Expected the contentType field to be defined\");\n }\n return {\n /**\n * If the raw response was parsed as JSON, we need to convert it to a Uint8Array,\n * otherwise, leave the payload as is.\n */\n data: typeof body === \"object\" ? Uint8Array.from(Object.values(body)) : body,\n contentType,\n };\n },\n };\n}\n"]}
@@ -0,0 +1,225 @@
1
+ import type { AmqpAnnotatedMessage } from "@azure/core-amqp";
2
+ import type { EventData } from "./eventData.js";
3
+ import type { ConnectionContext } from "./connectionContext.js";
4
+ import type { OperationTracingOptions, TracingContext } from "@azure/core-tracing";
5
+ import type { PartitionPublishingProperties } from "./models/private.js";
6
+ /**
7
+ * Checks if the provided eventDataBatch is an instance of `EventDataBatch`.
8
+ * @param eventDataBatch - The instance of `EventDataBatch` to verify.
9
+ * @internal
10
+ */
11
+ export declare function isEventDataBatch(eventDataBatch: unknown): eventDataBatch is EventDataBatch;
12
+ /**
13
+ * Options to configure the behavior of the `tryAdd` method on the `EventDataBatch` class.
14
+ */
15
+ export interface TryAddOptions {
16
+ /**
17
+ * The options to use when creating Spans for tracing.
18
+ */
19
+ tracingOptions?: OperationTracingOptions;
20
+ }
21
+ /**
22
+ * An interface representing a batch of events which can be used to send events to Event Hub.
23
+ *
24
+ * To create the batch, use the `createBatch()` method on the `EventHubProducerClient`.
25
+ * To send the batch, use the `sendBatch()` method on the same client.
26
+ * To fill the batch, use the `tryAdd()` method on the batch itself.
27
+ *
28
+ */
29
+ export interface EventDataBatch {
30
+ /**
31
+ * A value that is hashed and used by the Azure Event Hubs service to determine the partition to
32
+ * which the events are sent. Use the `createBatch()` method on the `EventHubProducerClient` to
33
+ * set the partitionKey.
34
+ * @readonly
35
+ * @internal
36
+ */
37
+ readonly partitionKey?: string;
38
+ /**
39
+ * Id of the partition to which the batch of events are sent. Use the `createBatch()` method on
40
+ * the `EventHubProducerClient` to set the partitionId.
41
+ * @readonly
42
+ * @internal
43
+ */
44
+ readonly partitionId?: string;
45
+ /**
46
+ * Size of the batch in bytes after the events added to it have been encoded into a single AMQP
47
+ * message.
48
+ * @readonly
49
+ */
50
+ readonly sizeInBytes: number;
51
+ /**
52
+ * Number of events added to the batch.
53
+ * @readonly
54
+ */
55
+ readonly count: number;
56
+ /**
57
+ * The maximum size of the batch, in bytes. The `tryAdd` function on the batch will return `false`
58
+ * if the event being added causes the size of the batch to exceed this limit. Use the `createBatch()` method on
59
+ * the `EventHubProducerClient` to set the maxSizeInBytes.
60
+ * @readonly
61
+ */
62
+ readonly maxSizeInBytes: number;
63
+ /**
64
+ * Adds an event to the batch if permitted by the batch's size limit.
65
+ * **NOTE**: Always remember to check the return value of this method, before calling it again
66
+ * for the next event.
67
+ *
68
+ * @param eventData - An individual event data object or AmqpAnnotatedMessage.
69
+ * @returns A boolean value indicating if the event data has been added to the batch or not.
70
+ */
71
+ tryAdd(eventData: EventData | AmqpAnnotatedMessage, options?: TryAddOptions): boolean;
72
+ }
73
+ /**
74
+ * An internal class representing a batch of events which can be used to send events to Event Hub.
75
+ *
76
+ * @internal
77
+ */
78
+ export declare class EventDataBatchImpl implements EventDataBatch {
79
+ /**
80
+ * Describes the amqp connection context for the Client.
81
+ */
82
+ private _context;
83
+ /**
84
+ * The Id of the partition to which the batch is expected to be sent to.
85
+ * Specifying this will throw an error if the batch was created using a `partitionKey`.
86
+ */
87
+ private _partitionId?;
88
+ /**
89
+ * A value that is hashed to produce a partition assignment.
90
+ * It guarantees that messages with the same partitionKey end up in the same partition.
91
+ * Specifying this will throw an error if the batch was created using a `partitionId`.
92
+ */
93
+ private _partitionKey?;
94
+ /**
95
+ * The maximum size allowed for the batch.
96
+ */
97
+ private _maxSizeInBytes;
98
+ /**
99
+ * Current size of the batch in bytes.
100
+ */
101
+ private _sizeInBytes;
102
+ /**
103
+ * Encoded amqp messages.
104
+ */
105
+ private _encodedMessages;
106
+ /**
107
+ * Number of events in the batch.
108
+ */
109
+ private _count;
110
+ /**
111
+ * List of 'message' span contexts.
112
+ */
113
+ private _spanContexts;
114
+ /**
115
+ * The message annotations to apply on the batch envelope.
116
+ * This will reflect the message annotations on the first event
117
+ * that was added to the batch.
118
+ * A common annotation is the partition key.
119
+ */
120
+ private _batchAnnotations?;
121
+ /**
122
+ * Indicates that the batch should be treated as idempotent.
123
+ */
124
+ private _isIdempotent;
125
+ /**
126
+ * The sequence number assigned to the first event in the batch while
127
+ * the batch is being sent to the service.
128
+ */
129
+ private _pendingStartingSequenceNumber?;
130
+ /**
131
+ * The publishing sequence number assigned to the first event in the batch at the time
132
+ * the batch was successfully published.
133
+ * If the producer was not configured to apply sequence numbering or if the batch
134
+ * has not yet been successfully published, the value will be `undefined`.
135
+ */
136
+ private _startingPublishSequenceNumber?;
137
+ /**
138
+ * EventDataBatch should not be constructed using `new EventDataBatch()`
139
+ * Use the `createBatch()` method on your `EventHubProducer` instead.
140
+ * @internal
141
+ */
142
+ constructor(context: ConnectionContext, maxSizeInBytes: number, isIdempotent: boolean, partitionKey?: string, partitionId?: string);
143
+ /**
144
+ * The maximum size of the batch, in bytes.
145
+ * @readonly
146
+ */
147
+ get maxSizeInBytes(): number;
148
+ /**
149
+ * The partitionKey set during `EventDataBatch` creation. This value is hashed to
150
+ * produce a partition assignment when the producer is created without a `partitionId`
151
+ * @readonly
152
+ */
153
+ get partitionKey(): string | undefined;
154
+ /**
155
+ * The partitionId set during `EventDataBatch` creation.
156
+ * If this value is set then partitionKey can not be set.
157
+ * @readonly
158
+ */
159
+ get partitionId(): string | undefined;
160
+ /**
161
+ * Size of the `EventDataBatch` instance after the events added to it have been
162
+ * encoded into a single AMQP message.
163
+ * @readonly
164
+ */
165
+ get sizeInBytes(): number;
166
+ /**
167
+ * Number of events in the `EventDataBatch` instance.
168
+ * @readonly
169
+ */
170
+ get count(): number;
171
+ /**
172
+ * The publishing sequence number assigned to the first event in the batch at the time
173
+ * the batch was successfully published.
174
+ * If the producer was not configured to apply sequence numbering or if the batch
175
+ * has not yet been successfully published, the value will be `undefined`.
176
+ */
177
+ get startingPublishedSequenceNumber(): number | undefined;
178
+ /**
179
+ * Gets the "message" span contexts that were created when adding events to the batch.
180
+ * @internal
181
+ */
182
+ get _messageSpanContexts(): TracingContext[];
183
+ /**
184
+ * Generates an AMQP message that contains the provided encoded events and annotations.
185
+ * @param encodedEvents - The already encoded events to include in the AMQP batch.
186
+ * @param annotations - The message annotations to set on the batch.
187
+ * @param publishingProps - Idempotent publishing properties used to decorate the events in the batch while sending.
188
+ */
189
+ private _generateBatch;
190
+ /**
191
+ * Uses the publishingProps to add idempotent properties as message annotations to rhea messages.
192
+ */
193
+ private _decorateRheaMessagesWithPublishingProps;
194
+ /**
195
+ * Annotates a rhea message with placeholder idempotent properties if the batch is idempotent.
196
+ * This is necessary so that we can accurately calculate the size of the batch while adding events.
197
+ * Placeholder values are used because real values won't be known until we attempt to send the batch.
198
+ */
199
+ private _decorateRheaMessageWithPlaceholderIdempotencyProps;
200
+ /**
201
+ * Generates the single AMQP message which is the result of encoding all the events
202
+ * added into the `EventDataBatch` instance.
203
+ *
204
+ * This is not meant for the user to use directly.
205
+ *
206
+ * When the `EventDataBatch` instance is passed to the `send()` method on the `EventHubProducer`,
207
+ * this single batched AMQP message is what gets sent over the wire to the service.
208
+ * @readonly
209
+ */
210
+ _generateMessage(publishingProps?: PartitionPublishingProperties): Buffer;
211
+ /**
212
+ * Sets startingPublishSequenceNumber to the pending publish sequence number.
213
+ */
214
+ _commitPublish(): void;
215
+ /**
216
+ * Tries to add an event data to the batch if permitted by the batch's size limit.
217
+ * **NOTE**: Always remember to check the return value of this method, before calling it again
218
+ * for the next event.
219
+ *
220
+ * @param eventData - An individual event data object.
221
+ * @returns A boolean value indicating if the event data has been added to the batch or not.
222
+ */
223
+ tryAdd(eventData: EventData | AmqpAnnotatedMessage, options?: TryAddOptions): boolean;
224
+ }
225
+ //# sourceMappingURL=eventDataBatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventDataBatch.d.ts","sourceRoot":"","sources":["../../src/eventDataBatch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAIhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGnF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAezE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,OAAO,GAAG,cAAc,IAAI,cAAc,CAO1F;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;;;;O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