@azure/event-hubs 6.0.2-alpha.20251014.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 (259) 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/util/timerLoop.d.ts.map +1 -1
  45. package/dist/commonjs/util/timerLoop.js +12 -5
  46. package/dist/commonjs/util/timerLoop.js.map +1 -1
  47. package/dist/esm/batchingPartitionChannel.d.ts.map +1 -1
  48. package/dist/esm/batchingPartitionChannel.js +2 -1
  49. package/dist/esm/batchingPartitionChannel.js.map +1 -1
  50. package/dist/esm/connectionContext.d.ts.map +1 -1
  51. package/dist/esm/connectionContext.js +10 -4
  52. package/dist/esm/connectionContext.js.map +1 -1
  53. package/dist/esm/eventHubBufferedProducerClient.d.ts.map +1 -1
  54. package/dist/esm/eventHubBufferedProducerClient.js +2 -1
  55. package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
  56. package/dist/esm/eventHubConsumerClient.d.ts.map +1 -1
  57. package/dist/esm/eventHubConsumerClient.js +3 -6
  58. package/dist/esm/eventHubConsumerClient.js.map +1 -1
  59. package/dist/esm/eventHubProducerClient.d.ts.map +1 -1
  60. package/dist/esm/eventHubProducerClient.js +3 -6
  61. package/dist/esm/eventHubProducerClient.js.map +1 -1
  62. package/dist/esm/eventHubSender.d.ts.map +1 -1
  63. package/dist/esm/eventHubSender.js +6 -4
  64. package/dist/esm/eventHubSender.js.map +1 -1
  65. package/dist/esm/partitionReceiver.js +4 -4
  66. package/dist/esm/partitionReceiver.js.map +1 -1
  67. package/dist/esm/util/timerLoop.d.ts.map +1 -1
  68. package/dist/esm/util/timerLoop.js +12 -5
  69. package/dist/esm/util/timerLoop.js.map +1 -1
  70. package/dist/react-native/batchingPartitionChannel.d.ts +94 -0
  71. package/dist/react-native/batchingPartitionChannel.d.ts.map +1 -0
  72. package/dist/react-native/batchingPartitionChannel.js +255 -0
  73. package/dist/react-native/batchingPartitionChannel.js.map +1 -0
  74. package/dist/react-native/connectionContext.d.ts +108 -0
  75. package/dist/react-native/connectionContext.d.ts.map +1 -0
  76. package/dist/react-native/connectionContext.js +310 -0
  77. package/dist/react-native/connectionContext.js.map +1 -0
  78. package/dist/react-native/dataTransformer.d.ts +53 -0
  79. package/dist/react-native/dataTransformer.d.ts.map +1 -0
  80. package/dist/react-native/dataTransformer.js +133 -0
  81. package/dist/react-native/dataTransformer.js.map +1 -0
  82. package/dist/react-native/diagnostics/instrumentEventData.d.ts +28 -0
  83. package/dist/react-native/diagnostics/instrumentEventData.d.ts.map +1 -0
  84. package/dist/react-native/diagnostics/instrumentEventData.js +67 -0
  85. package/dist/react-native/diagnostics/instrumentEventData.js.map +1 -0
  86. package/dist/react-native/diagnostics/tracing.d.ts +19 -0
  87. package/dist/react-native/diagnostics/tracing.d.ts.map +1 -0
  88. package/dist/react-native/diagnostics/tracing.js +40 -0
  89. package/dist/react-native/diagnostics/tracing.js.map +1 -0
  90. package/dist/react-native/eventData.d.ts +295 -0
  91. package/dist/react-native/eventData.d.ts.map +1 -0
  92. package/dist/react-native/eventData.js +247 -0
  93. package/dist/react-native/eventData.js.map +1 -0
  94. package/dist/react-native/eventDataAdapter.d.ts +69 -0
  95. package/dist/react-native/eventDataAdapter.d.ts.map +1 -0
  96. package/dist/react-native/eventDataAdapter.js +38 -0
  97. package/dist/react-native/eventDataAdapter.js.map +1 -0
  98. package/dist/react-native/eventDataBatch.d.ts +225 -0
  99. package/dist/react-native/eventDataBatch.d.ts.map +1 -0
  100. package/dist/react-native/eventDataBatch.js +301 -0
  101. package/dist/react-native/eventDataBatch.js.map +1 -0
  102. package/dist/react-native/eventHubBufferedProducerClient.d.ts +323 -0
  103. package/dist/react-native/eventHubBufferedProducerClient.d.ts.map +1 -0
  104. package/dist/react-native/eventHubBufferedProducerClient.js +301 -0
  105. package/dist/react-native/eventHubBufferedProducerClient.js.map +1 -0
  106. package/dist/react-native/eventHubConsumerClient.d.ts +293 -0
  107. package/dist/react-native/eventHubConsumerClient.d.ts.map +1 -0
  108. package/dist/react-native/eventHubConsumerClient.js +336 -0
  109. package/dist/react-native/eventHubConsumerClient.js.map +1 -0
  110. package/dist/react-native/eventHubConsumerClientModels.d.ts +218 -0
  111. package/dist/react-native/eventHubConsumerClientModels.d.ts.map +1 -0
  112. package/dist/react-native/eventHubConsumerClientModels.js +4 -0
  113. package/dist/react-native/eventHubConsumerClientModels.js.map +1 -0
  114. package/dist/react-native/eventHubProducerClient.d.ts +299 -0
  115. package/dist/react-native/eventHubProducerClient.d.ts.map +1 -0
  116. package/dist/react-native/eventHubProducerClient.js +366 -0
  117. package/dist/react-native/eventHubProducerClient.js.map +1 -0
  118. package/dist/react-native/eventHubSender.d.ts +227 -0
  119. package/dist/react-native/eventHubSender.d.ts.map +1 -0
  120. package/dist/react-native/eventHubSender.js +626 -0
  121. package/dist/react-native/eventHubSender.js.map +1 -0
  122. package/dist/react-native/eventPosition.d.ts +73 -0
  123. package/dist/react-native/eventPosition.d.ts.map +1 -0
  124. package/dist/react-native/eventPosition.js +121 -0
  125. package/dist/react-native/eventPosition.js.map +1 -0
  126. package/dist/react-native/eventProcessor.d.ts +232 -0
  127. package/dist/react-native/eventProcessor.d.ts.map +1 -0
  128. package/dist/react-native/eventProcessor.js +389 -0
  129. package/dist/react-native/eventProcessor.js.map +1 -0
  130. package/dist/react-native/eventhubConnectionConfig.d.ts +96 -0
  131. package/dist/react-native/eventhubConnectionConfig.d.ts.map +1 -0
  132. package/dist/react-native/eventhubConnectionConfig.js +98 -0
  133. package/dist/react-native/eventhubConnectionConfig.js.map +1 -0
  134. package/dist/react-native/impl/awaitableQueue.d.ts +25 -0
  135. package/dist/react-native/impl/awaitableQueue.d.ts.map +1 -0
  136. package/dist/react-native/impl/awaitableQueue.js +51 -0
  137. package/dist/react-native/impl/awaitableQueue.js.map +1 -0
  138. package/dist/react-native/impl/partitionAssigner.d.ts +29 -0
  139. package/dist/react-native/impl/partitionAssigner.d.ts.map +1 -0
  140. package/dist/react-native/impl/partitionAssigner.js +52 -0
  141. package/dist/react-native/impl/partitionAssigner.js.map +1 -0
  142. package/dist/react-native/impl/partitionGate.d.ts +27 -0
  143. package/dist/react-native/impl/partitionGate.d.ts.map +1 -0
  144. package/dist/react-native/impl/partitionGate.js +38 -0
  145. package/dist/react-native/impl/partitionGate.js.map +1 -0
  146. package/dist/react-native/impl/partitionKeyToIdMapper.d.ts +6 -0
  147. package/dist/react-native/impl/partitionKeyToIdMapper.d.ts.map +1 -0
  148. package/dist/react-native/impl/partitionKeyToIdMapper.js +111 -0
  149. package/dist/react-native/impl/partitionKeyToIdMapper.js.map +1 -0
  150. package/dist/react-native/inMemoryCheckpointStore.d.ts +44 -0
  151. package/dist/react-native/inMemoryCheckpointStore.d.ts.map +1 -0
  152. package/dist/react-native/inMemoryCheckpointStore.js +94 -0
  153. package/dist/react-native/inMemoryCheckpointStore.js.map +1 -0
  154. package/dist/react-native/index.d.ts +21 -0
  155. package/dist/react-native/index.d.ts.map +1 -0
  156. package/dist/react-native/index.js +12 -0
  157. package/dist/react-native/index.js.map +1 -0
  158. package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts +30 -0
  159. package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -0
  160. package/dist/react-native/loadBalancerStrategies/balancedStrategy.js +40 -0
  161. package/dist/react-native/loadBalancerStrategies/balancedStrategy.js.map +1 -0
  162. package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts +24 -0
  163. package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -0
  164. package/dist/react-native/loadBalancerStrategies/greedyStrategy.js +29 -0
  165. package/dist/react-native/loadBalancerStrategies/greedyStrategy.js.map +1 -0
  166. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts +28 -0
  167. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -0
  168. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js +245 -0
  169. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -0
  170. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts +20 -0
  171. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -0
  172. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js +22 -0
  173. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js.map +1 -0
  174. package/dist/react-native/logger.d.ts +37 -0
  175. package/dist/react-native/logger.d.ts.map +1 -0
  176. package/dist/react-native/logger.js +56 -0
  177. package/dist/react-native/logger.js.map +1 -0
  178. package/dist/react-native/managementClient.d.ts +145 -0
  179. package/dist/react-native/managementClient.d.ts.map +1 -0
  180. package/dist/react-native/managementClient.js +305 -0
  181. package/dist/react-native/managementClient.js.map +1 -0
  182. package/dist/react-native/models/private.d.ts +185 -0
  183. package/dist/react-native/models/private.d.ts.map +1 -0
  184. package/dist/react-native/models/private.js +4 -0
  185. package/dist/react-native/models/private.js.map +1 -0
  186. package/dist/react-native/models/public.d.ts +240 -0
  187. package/dist/react-native/models/public.d.ts.map +1 -0
  188. package/dist/react-native/models/public.js +18 -0
  189. package/dist/react-native/models/public.js.map +1 -0
  190. package/dist/react-native/package.json +3 -0
  191. package/dist/react-native/partitionProcessor.d.ts +134 -0
  192. package/dist/react-native/partitionProcessor.d.ts.map +1 -0
  193. package/dist/react-native/partitionProcessor.js +137 -0
  194. package/dist/react-native/partitionProcessor.js.map +1 -0
  195. package/dist/react-native/partitionPump.d.ts +38 -0
  196. package/dist/react-native/partitionPump.d.ts.map +1 -0
  197. package/dist/react-native/partitionPump.js +175 -0
  198. package/dist/react-native/partitionPump.js.map +1 -0
  199. package/dist/react-native/partitionReceiver.d.ts +82 -0
  200. package/dist/react-native/partitionReceiver.d.ts.map +1 -0
  201. package/dist/react-native/partitionReceiver.js +335 -0
  202. package/dist/react-native/partitionReceiver.js.map +1 -0
  203. package/dist/react-native/pumpManager.d.ts +72 -0
  204. package/dist/react-native/pumpManager.d.ts.map +1 -0
  205. package/dist/react-native/pumpManager.js +120 -0
  206. package/dist/react-native/pumpManager.js.map +1 -0
  207. package/dist/react-native/util/connectionStringUtils.d.ts +52 -0
  208. package/dist/react-native/util/connectionStringUtils.d.ts.map +1 -0
  209. package/dist/react-native/util/connectionStringUtils.js +48 -0
  210. package/dist/react-native/util/connectionStringUtils.js.map +1 -0
  211. package/dist/react-native/util/constants.d.ts +25 -0
  212. package/dist/react-native/util/constants.d.ts.map +1 -0
  213. package/dist/react-native/util/constants.js +27 -0
  214. package/dist/react-native/util/constants.js.map +1 -0
  215. package/dist/react-native/util/delayWithoutThrow.d.ts +8 -0
  216. package/dist/react-native/util/delayWithoutThrow.d.ts.map +1 -0
  217. package/dist/react-native/util/delayWithoutThrow.js +17 -0
  218. package/dist/react-native/util/delayWithoutThrow.js.map +1 -0
  219. package/dist/react-native/util/error.d.ts +39 -0
  220. package/dist/react-native/util/error.d.ts.map +1 -0
  221. package/dist/react-native/util/error.js +103 -0
  222. package/dist/react-native/util/error.js.map +1 -0
  223. package/dist/react-native/util/getPromiseParts.d.ts +10 -0
  224. package/dist/react-native/util/getPromiseParts.d.ts.map +1 -0
  225. package/dist/react-native/util/getPromiseParts.js +20 -0
  226. package/dist/react-native/util/getPromiseParts.js.map +1 -0
  227. package/dist/react-native/util/operationOptions.d.ts +16 -0
  228. package/dist/react-native/util/operationOptions.d.ts.map +1 -0
  229. package/dist/react-native/util/operationOptions.js +4 -0
  230. package/dist/react-native/util/operationOptions.js.map +1 -0
  231. package/dist/react-native/util/parseEndpoint.d.ts +11 -0
  232. package/dist/react-native/util/parseEndpoint.d.ts.map +1 -0
  233. package/dist/react-native/util/parseEndpoint.js +17 -0
  234. package/dist/react-native/util/parseEndpoint.js.map +1 -0
  235. package/dist/react-native/util/retries.d.ts +6 -0
  236. package/dist/react-native/util/retries.d.ts.map +1 -0
  237. package/dist/react-native/util/retries.js +13 -0
  238. package/dist/react-native/util/retries.js.map +1 -0
  239. package/dist/react-native/util/runtimeInfo-react-native.d.mts.map +1 -0
  240. package/dist/react-native/util/runtimeInfo-react-native.mjs.map +1 -0
  241. package/dist/react-native/util/runtimeInfo.d.ts +6 -0
  242. package/dist/react-native/util/runtimeInfo.js +20 -0
  243. package/dist/react-native/util/timerLoop.d.ts +26 -0
  244. package/dist/react-native/util/timerLoop.d.ts.map +1 -0
  245. package/dist/react-native/util/timerLoop.js +34 -0
  246. package/dist/react-native/util/timerLoop.js.map +1 -0
  247. package/dist/react-native/util/typeGuards.d.ts +8 -0
  248. package/dist/react-native/util/typeGuards.d.ts.map +1 -0
  249. package/dist/react-native/util/typeGuards.js +12 -0
  250. package/dist/react-native/util/typeGuards.js.map +1 -0
  251. package/dist/react-native/util/utils.d.ts +7 -0
  252. package/dist/react-native/util/utils.d.ts.map +1 -0
  253. package/dist/react-native/util/utils.js +13 -0
  254. package/dist/react-native/util/utils.js.map +1 -0
  255. package/dist/react-native/withAuth.d.ts +25 -0
  256. package/dist/react-native/withAuth.d.ts.map +1 -0
  257. package/dist/react-native/withAuth.js +84 -0
  258. package/dist/react-native/withAuth.js.map +1 -0
  259. package/package.json +16 -11
@@ -0,0 +1,98 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /* eslint-disable eqeqeq */
4
+ import { ConnectionConfig } from "@azure/core-amqp";
5
+ import { parseEndpoint } from "./util/parseEndpoint.js";
6
+ /**
7
+ * Describes the connection config object that is created after parsing an EventHub connection
8
+ * string. It also provides some convenience methods for getting the address and audience for
9
+ * different entities.
10
+ * @internal
11
+ */
12
+ // eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.
13
+ export const EventHubConnectionConfig = {
14
+ /**
15
+ * Creates the connection config.
16
+ * @param connectionString - The connection string for a given service like
17
+ * EventHub/ServiceBus.
18
+ * @param path - The name/path of the entity (hub name) to which the
19
+ * connection needs to happen. This will override the EntityPath in the connectionString
20
+ * if present.
21
+ * @returns EventHubConnectionConfig
22
+ */
23
+ create(connectionString, path) {
24
+ const config = ConnectionConfig.create(connectionString, path);
25
+ if (!config.entityPath) {
26
+ throw new TypeError(`Either provide "path" or the "connectionString": "${connectionString}", ` +
27
+ `must contain EntityPath="<path-to-the-entity>".`);
28
+ }
29
+ return EventHubConnectionConfig.createFromConnectionConfig(config);
30
+ },
31
+ /**
32
+ * Creates an EventHubConnectionConfig from the provided base ConnectionConfig.
33
+ * @param config - The base connection config from which the EventHubConnectionConfig needs to be
34
+ * created.
35
+ * @returns EventHubConnectionConfig
36
+ */
37
+ createFromConnectionConfig(config) {
38
+ ConnectionConfig.validate(config, { isEntityPathRequired: true });
39
+ config.getManagementAudience = () => {
40
+ return `${config.endpoint}${config.entityPath}/$management`;
41
+ };
42
+ config.getManagementAddress = () => {
43
+ return `${config.entityPath}/$management`;
44
+ };
45
+ config.getSenderAudience = (partitionId) => {
46
+ if (partitionId != undefined) {
47
+ return `${config.endpoint}${config.entityPath}/Partitions/${partitionId}`;
48
+ }
49
+ else {
50
+ return `${config.endpoint}${config.entityPath}`;
51
+ }
52
+ };
53
+ config.getSenderAddress = (partitionId) => {
54
+ if (partitionId != undefined) {
55
+ return `${config.entityPath}/Partitions/${partitionId}`;
56
+ }
57
+ else {
58
+ return `${config.entityPath}`;
59
+ }
60
+ };
61
+ config.getReceiverAudience = (partitionId, consumergroup) => {
62
+ if (!consumergroup)
63
+ consumergroup = "$default";
64
+ return (`${config.endpoint}${config.entityPath}/ConsumerGroups/${consumergroup}/` +
65
+ `Partitions/${partitionId}`);
66
+ };
67
+ config.getReceiverAddress = (partitionId, consumergroup) => {
68
+ if (!consumergroup)
69
+ consumergroup = "$default";
70
+ return `${config.entityPath}/ConsumerGroups/${consumergroup}/Partitions/${partitionId}`;
71
+ };
72
+ return config;
73
+ },
74
+ /**
75
+ * Updates the provided EventHubConnectionConfig to use the custom endpoint address.
76
+ * @param config - An existing connection configuration to be updated.
77
+ * @param customEndpointAddress - The custom endpoint address to use.
78
+ */
79
+ setCustomEndpointAddress(config, customEndpointAddress) {
80
+ // The amqpHostname should match the host prior to using the custom endpoint.
81
+ config.amqpHostname = config.host;
82
+ const { hostname, port } = parseEndpoint(customEndpointAddress);
83
+ // Since we specify the port separately, set host to the customEndpointAddress hostname.
84
+ config.host = hostname;
85
+ if (port) {
86
+ config.port = parseInt(port, 10);
87
+ }
88
+ },
89
+ /**
90
+ * Validates the properties of connection config.
91
+ * @param config - The connection config to be validated.
92
+ * @returns void
93
+ */
94
+ validate(config) {
95
+ return ConnectionConfig.validate(config, { isEntityPathRequired: true });
96
+ },
97
+ };
98
+ //# sourceMappingURL=eventhubConnectionConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventhubConnectionConfig.js","sourceRoot":"","sources":["../../src/eventhubConnectionConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,2BAA2B;AAE3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AA4DxD;;;;;GAKG;AACH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAwB,EAAE,IAAa;QAC5C,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;QAC/D,IAAI,C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AAE;YACF,IAAI,CAAC,aAAa;gBAAE,aAAa,GAAG,UAAU,CAAC;YAC/C,OAAO,CACL,GAAG,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,UAAU,mBAAmB,aAAa,GAAG;gBACzE,cAAc,WAAW,EAAE,CAC5B,CAAC;QACJ,CAAC,CAAC;QAED,MAAmC,CAAC,kBAAkB,GAAG,CACxD,WAA4B,EAC5B,aAAsB,EACtB,EAAE;YACF,IAAI,CAAC,aAAa;gBAAE,aAAa,GAAG,UAAU,CAAC;YAC/C,OAAO,GAAG,MAAM,CAAC,UAAU,mBAAmB,aAAa,eAAe,WAAW,EAAE,CAAC;QAC1F,CAAC,CAAC;QACF,OAAO,MAAkC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,wBAAwB,CAAC,MAAgC,EAAE,qBAA6B;QACtF,6EAA6E;QAC7E,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC;QAClC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC;QAChE,wFAAwF;QACxF,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC;QACvB,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,MAAgC;QACvC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3E,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n/* eslint-disable eqeqeq */\n\nimport { ConnectionConfig } from \"@azure/core-amqp\";\nimport { parseEndpoint } from \"./util/parseEndpoint.js\";\n\n/**\n * Describes the connection config object that is created after parsing an EventHub connection\n * string. It also provides some convenience methods for getting the address and audience for\n * different entities.\n * @internal\n */\nexport interface EventHubConnectionConfig extends ConnectionConfig {\n /**\n * The name/path of the entity (event hub name) to which the\n * connection needs to happen.\n */\n entityPath: string;\n /**\n * Provides the EventHub Sender address in one of the following forms based on the input:\n * - `\"<hubName>\"`\n * - `\"<hubName>/Partitions/<partitionId>\"`\n *\n * @param partitionId - The partitionId in the EventHub to which messages will be sent.\n */\n getSenderAddress(partitionId?: string | number): string;\n /**\n * Provides the EventHub Sender audience in one of the following forms based on the input:\n * - `\"sb://<yournamespace>.servicebus.windows.net/<hubName>\"`\n * - `\"sb://<yournamespace>.servicebus.windows.net/<hubName>/Partitions/<partitionId>\"`\n *\n * @param partitionId - The partitionId in the EventHub to which messages will be sent.\n */\n getSenderAudience(partitionId?: string | number): string;\n /**\n * Provides the EventHub Receiver address:\n * - `\"<hub-name>/ConsumerGroups/<consumer-group-name>/Partitions/<partition-id>\"`\n *\n * @param partitionId - The partitionId in the EventHub from which messages will be received.\n * @param consumergroup - The consumergroup in the EventHub from which the messages will\n * be received. Default: `$default`.\n */\n getReceiverAddress(partitionId: string | number, consumergroup?: string): string;\n /**\n * Provides the EventHub Receiver audience.\n * - `\"sb://<your-namespace>.servicebus.windows.net/<hub-name>/ConsumerGroups/<consumer-group-name>/Partitions/<partition-id>\"`\n *\n * @param partitionId - The partitionId in the EventHub from which messages will be received.\n * @param consumergroup - The consumergroup in the EventHub from which the messages will\n * be received. Default: `$default`.\n */\n getReceiverAudience(partitionId: string | number, consumergroup?: string): string;\n /**\n * Provides the EventHub Management address.\n * - `\"<hub-name>/$management\"`\n */\n getManagementAddress(): string;\n /**\n * Provides the EventHub Management audience.\n * - `\"sb://<your-namespace>.servicebus.windows.net/<hub-name>/$management\"`\n */\n getManagementAudience(): string;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub connection\n * string. It also provides some convenience methods for getting the address and audience for\n * different entities.\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const EventHubConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns EventHubConnectionConfig\n */\n create(connectionString: string, path?: string): EventHubConnectionConfig {\n const config = ConnectionConfig.create(connectionString, path);\n if (!config.entityPath) {\n throw new TypeError(\n `Either provide \"path\" or the \"connectionString\": \"${connectionString}\", ` +\n `must contain EntityPath=\"<path-to-the-entity>\".`,\n );\n }\n return EventHubConnectionConfig.createFromConnectionConfig(config);\n },\n\n /**\n * Creates an EventHubConnectionConfig from the provided base ConnectionConfig.\n * @param config - The base connection config from which the EventHubConnectionConfig needs to be\n * created.\n * @returns EventHubConnectionConfig\n */\n createFromConnectionConfig(config: ConnectionConfig): EventHubConnectionConfig {\n ConnectionConfig.validate(config, { isEntityPathRequired: true });\n\n (config as EventHubConnectionConfig).getManagementAudience = () => {\n return `${config.endpoint}${config.entityPath}/$management`;\n };\n (config as EventHubConnectionConfig).getManagementAddress = () => {\n return `${config.entityPath}/$management`;\n };\n\n (config as EventHubConnectionConfig).getSenderAudience = (partitionId?: string | number) => {\n if (partitionId != undefined) {\n return `${config.endpoint}${config.entityPath}/Partitions/${partitionId}`;\n } else {\n return `${config.endpoint}${config.entityPath}`;\n }\n };\n\n (config as EventHubConnectionConfig).getSenderAddress = (partitionId?: string | number) => {\n if (partitionId != undefined) {\n return `${config.entityPath}/Partitions/${partitionId}`;\n } else {\n return `${config.entityPath}`;\n }\n };\n\n (config as EventHubConnectionConfig).getReceiverAudience = (\n partitionId: string | number,\n consumergroup?: string,\n ) => {\n if (!consumergroup) consumergroup = \"$default\";\n return (\n `${config.endpoint}${config.entityPath}/ConsumerGroups/${consumergroup}/` +\n `Partitions/${partitionId}`\n );\n };\n\n (config as EventHubConnectionConfig).getReceiverAddress = (\n partitionId: string | number,\n consumergroup?: string,\n ) => {\n if (!consumergroup) consumergroup = \"$default\";\n return `${config.entityPath}/ConsumerGroups/${consumergroup}/Partitions/${partitionId}`;\n };\n return config as EventHubConnectionConfig;\n },\n\n /**\n * Updates the provided EventHubConnectionConfig to use the custom endpoint address.\n * @param config - An existing connection configuration to be updated.\n * @param customEndpointAddress - The custom endpoint address to use.\n */\n setCustomEndpointAddress(config: EventHubConnectionConfig, customEndpointAddress: string): void {\n // The amqpHostname should match the host prior to using the custom endpoint.\n config.amqpHostname = config.host;\n const { hostname, port } = parseEndpoint(customEndpointAddress);\n // Since we specify the port separately, set host to the customEndpointAddress hostname.\n config.host = hostname;\n if (port) {\n config.port = parseInt(port, 10);\n }\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: EventHubConnectionConfig): void {\n return ConnectionConfig.validate(config, { isEntityPathRequired: true });\n },\n};\n"]}
@@ -0,0 +1,25 @@
1
+ import type { AbortOptions } from "@azure/core-util";
2
+ /**
3
+ * `AwaitableQueue` stores items in the order that they are received.
4
+ *
5
+ * This differs from ordinary Queues in that `shift` returns a Promise for a value.
6
+ * This allows a consumer of the queue to request an item that the queue does not yet have.
7
+ *
8
+ * @internal
9
+ */
10
+ export declare class AwaitableQueue<T> {
11
+ private readonly _items;
12
+ private readonly _resolvers;
13
+ constructor();
14
+ size(): number;
15
+ /**
16
+ * Returns a Promise that will resolve with the next item in the queue.
17
+ */
18
+ shift(options?: AbortOptions): Promise<T>;
19
+ /**
20
+ * Appends new item to the queue.
21
+ */
22
+ push(item: T): void;
23
+ private _resolveNextItem;
24
+ }
25
+ //# sourceMappingURL=awaitableQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awaitableQueue.d.ts","sourceRoot":"","sources":["../../../src/impl/awaitableQueue.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;GAOG;AACH,qBAAa,cAAc,CAAC,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAM;IAE7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiC;;IAMrD,IAAI,IAAI,MAAM;IAIrB;;OAEG;IACI,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC;IAYhD;;OAEG;IACI,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAM1B,OAAO,CAAC,gBAAgB;CASzB"}
@@ -0,0 +1,51 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { createAbortablePromise } from "@azure/core-util";
4
+ /**
5
+ * `AwaitableQueue` stores items in the order that they are received.
6
+ *
7
+ * This differs from ordinary Queues in that `shift` returns a Promise for a value.
8
+ * This allows a consumer of the queue to request an item that the queue does not yet have.
9
+ *
10
+ * @internal
11
+ */
12
+ export class AwaitableQueue {
13
+ _items;
14
+ _resolvers = [];
15
+ constructor() {
16
+ this._items = [];
17
+ }
18
+ size() {
19
+ return this._items.length;
20
+ }
21
+ /**
22
+ * Returns a Promise that will resolve with the next item in the queue.
23
+ */
24
+ shift(options) {
25
+ const item = this._items.shift();
26
+ if (typeof item !== "undefined") {
27
+ return Promise.resolve(item);
28
+ }
29
+ return createAbortablePromise((resolve) => this._resolvers.push(resolve), {
30
+ ...options,
31
+ cleanupBeforeAbort: () => this._resolvers.pop(),
32
+ });
33
+ }
34
+ /**
35
+ * Appends new item to the queue.
36
+ */
37
+ push(item) {
38
+ if (!this._resolveNextItem(item)) {
39
+ this._items.push(item);
40
+ }
41
+ }
42
+ _resolveNextItem(item) {
43
+ const resolver = this._resolvers.shift();
44
+ if (!resolver) {
45
+ return false;
46
+ }
47
+ resolver(item);
48
+ return true;
49
+ }
50
+ }
51
+ //# sourceMappingURL=awaitableQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awaitableQueue.js","sourceRoot":"","sources":["../../../src/impl/awaitableQueue.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,OAAO,cAAc;IACR,MAAM,CAAM;IAEZ,UAAU,GAA8B,EAAE,CAAC;IAE5D;QACE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAsB;QACjC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACjC,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,sBAAsB,CAAI,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YAC3E,GAAG,OAAO;YACV,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;SAChD,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,IAAO;QACjB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,IAAO;QAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,KAAK,CAAC;QACf,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortOptions } from \"@azure/core-util\";\nimport { createAbortablePromise } from \"@azure/core-util\";\n\n/**\n * `AwaitableQueue` stores items in the order that they are received.\n *\n * This differs from ordinary Queues in that `shift` returns a Promise for a value.\n * This allows a consumer of the queue to request an item that the queue does not yet have.\n *\n * @internal\n */\nexport class AwaitableQueue<T> {\n private readonly _items: T[];\n\n private readonly _resolvers: Array<(value: T) => void> = [];\n\n constructor() {\n this._items = [];\n }\n\n public size(): number {\n return this._items.length;\n }\n\n /**\n * Returns a Promise that will resolve with the next item in the queue.\n */\n public shift(options?: AbortOptions): Promise<T> {\n const item = this._items.shift();\n if (typeof item !== \"undefined\") {\n return Promise.resolve(item);\n }\n\n return createAbortablePromise<T>((resolve) => this._resolvers.push(resolve), {\n ...options,\n cleanupBeforeAbort: () => this._resolvers.pop(),\n });\n }\n\n /**\n * Appends new item to the queue.\n */\n public push(item: T): void {\n if (!this._resolveNextItem(item)) {\n this._items.push(item);\n }\n }\n\n private _resolveNextItem(item: T) {\n const resolver = this._resolvers.shift();\n if (!resolver) {\n return false;\n }\n\n resolver(item);\n return true;\n }\n}\n"]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @internal
3
+ * Assigns a partition based on the partition ids it knows about and an optional partition id or partition key.
4
+ */
5
+ export declare class PartitionAssigner {
6
+ private _partitions;
7
+ private _lastRoundRobinPartitionIndex;
8
+ /**
9
+ * Set the partition ids that can be used when assigning a partition.
10
+ * @param partitionIds - All valid partition ids.
11
+ */
12
+ setPartitionIds(partitionIds: string[]): void;
13
+ /**
14
+ * Returns a partitionId from the list of partition ids set via `setPartitionIds`.
15
+ *
16
+ * If a partitionId is specified, then that will be returned directly.
17
+ * If a partitionKey is specified, then a partitionId will be calculated based on the partitionKey.
18
+ * Specifying both partitionId and partitionKey results in an error.
19
+ *
20
+ * If neither partitionId nor partitionKey are specified, then a partitionId will be selected
21
+ * based on a round-robin approach.
22
+ */
23
+ assignPartition({ partitionId, partitionKey, }: {
24
+ partitionId?: string;
25
+ partitionKey?: string;
26
+ }): string;
27
+ private _assignRoundRobinPartition;
28
+ }
29
+ //# sourceMappingURL=partitionAssigner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partitionAssigner.d.ts","sourceRoot":"","sources":["../../../src/impl/partitionAssigner.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,WAAW,CAAgB;IAEnC,OAAO,CAAC,6BAA6B,CAAc;IAEnD;;;OAGG;IACI,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI;IAIpD;;;;;;;;;OASG;IACH,eAAe,CAAC,EACd,WAAW,EACX,YAAY,GACb,EAAE;QACD,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,GAAG,MAAM;IAsBV,OAAO,CAAC,0BAA0B;CAUnC"}
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { isDefined } from "@azure/core-util";
4
+ import { mapPartitionKeyToId } from "./partitionKeyToIdMapper.js";
5
+ /**
6
+ * @internal
7
+ * Assigns a partition based on the partition ids it knows about and an optional partition id or partition key.
8
+ */
9
+ export class PartitionAssigner {
10
+ _partitions = [];
11
+ _lastRoundRobinPartitionIndex = -1;
12
+ /**
13
+ * Set the partition ids that can be used when assigning a partition.
14
+ * @param partitionIds - All valid partition ids.
15
+ */
16
+ setPartitionIds(partitionIds) {
17
+ this._partitions = partitionIds;
18
+ }
19
+ /**
20
+ * Returns a partitionId from the list of partition ids set via `setPartitionIds`.
21
+ *
22
+ * If a partitionId is specified, then that will be returned directly.
23
+ * If a partitionKey is specified, then a partitionId will be calculated based on the partitionKey.
24
+ * Specifying both partitionId and partitionKey results in an error.
25
+ *
26
+ * If neither partitionId nor partitionKey are specified, then a partitionId will be selected
27
+ * based on a round-robin approach.
28
+ */
29
+ assignPartition({ partitionId, partitionKey, }) {
30
+ if (isDefined(partitionId) && isDefined(partitionKey)) {
31
+ throw new Error(`The partitionId (${partitionId}) and partitionKey (${partitionKey}) cannot both be specified.`);
32
+ }
33
+ if (!this._partitions.length) {
34
+ throw new Error(`Unable to determine partitionIds, can't assign partitionId.`);
35
+ }
36
+ if (isDefined(partitionId) && this._partitions.includes(partitionId)) {
37
+ return partitionId;
38
+ }
39
+ if (isDefined(partitionKey)) {
40
+ return mapPartitionKeyToId(partitionKey, this._partitions.length).toString();
41
+ }
42
+ return this._assignRoundRobinPartition();
43
+ }
44
+ _assignRoundRobinPartition() {
45
+ const maxPartitionIndex = this._partitions.length - 1;
46
+ const proposedPartitionIndex = this._lastRoundRobinPartitionIndex + 1;
47
+ const nextPartitionIndex = proposedPartitionIndex > maxPartitionIndex ? 0 : proposedPartitionIndex;
48
+ this._lastRoundRobinPartitionIndex = nextPartitionIndex;
49
+ return this._partitions[nextPartitionIndex];
50
+ }
51
+ }
52
+ //# sourceMappingURL=partitionAssigner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partitionAssigner.js","sourceRoot":"","sources":["../../../src/impl/partitionAssigner.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACpB,WAAW,GAAa,EAAE,CAAC;IAE3B,6BAA6B,GAAW,CAAC,CAAC,CAAC;IAEnD;;;OAGG;IACI,eAAe,CAAC,YAAsB;QAC3C,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC;IAClC,CAAC;IAED;;;;;;;;;OASG;IACH,eAAe,CAAC,EACd,WAAW,EACX,YAAY,GAIb;QACC,IAAI,SAAS,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CACb,oBAAoB,WAAW,uBAAuB,YAAY,6BAA6B,CAChG,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QACjF,CAAC;QAED,IAAI,SAAS,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YACrE,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;YAC5B,OAAO,mBAAmB,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC/E,CAAC;QAED,OAAO,IAAI,CAAC,0BAA0B,EAAE,CAAC;IAC3C,CAAC;IAEO,0BAA0B;QAChC,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;QACtD,MAAM,sBAAsB,GAAG,IAAI,CAAC,6BAA6B,GAAG,CAAC,CAAC;QAEtE,MAAM,kBAAkB,GACtB,sBAAsB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC;QAE1E,IAAI,CAAC,6BAA6B,GAAG,kBAAkB,CAAC;QACxD,OAAO,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { isDefined } from \"@azure/core-util\";\nimport { mapPartitionKeyToId } from \"./partitionKeyToIdMapper.js\";\n\n/**\n * @internal\n * Assigns a partition based on the partition ids it knows about and an optional partition id or partition key.\n */\nexport class PartitionAssigner {\n private _partitions: string[] = [];\n\n private _lastRoundRobinPartitionIndex: number = -1;\n\n /**\n * Set the partition ids that can be used when assigning a partition.\n * @param partitionIds - All valid partition ids.\n */\n public setPartitionIds(partitionIds: string[]): void {\n this._partitions = partitionIds;\n }\n\n /**\n * Returns a partitionId from the list of partition ids set via `setPartitionIds`.\n *\n * If a partitionId is specified, then that will be returned directly.\n * If a partitionKey is specified, then a partitionId will be calculated based on the partitionKey.\n * Specifying both partitionId and partitionKey results in an error.\n *\n * If neither partitionId nor partitionKey are specified, then a partitionId will be selected\n * based on a round-robin approach.\n */\n assignPartition({\n partitionId,\n partitionKey,\n }: {\n partitionId?: string;\n partitionKey?: string;\n }): string {\n if (isDefined(partitionId) && isDefined(partitionKey)) {\n throw new Error(\n `The partitionId (${partitionId}) and partitionKey (${partitionKey}) cannot both be specified.`,\n );\n }\n\n if (!this._partitions.length) {\n throw new Error(`Unable to determine partitionIds, can't assign partitionId.`);\n }\n\n if (isDefined(partitionId) && this._partitions.includes(partitionId)) {\n return partitionId;\n }\n\n if (isDefined(partitionKey)) {\n return mapPartitionKeyToId(partitionKey, this._partitions.length).toString();\n }\n\n return this._assignRoundRobinPartition();\n }\n\n private _assignRoundRobinPartition(): string {\n const maxPartitionIndex = this._partitions.length - 1;\n const proposedPartitionIndex = this._lastRoundRobinPartitionIndex + 1;\n\n const nextPartitionIndex =\n proposedPartitionIndex > maxPartitionIndex ? 0 : proposedPartitionIndex;\n\n this._lastRoundRobinPartitionIndex = nextPartitionIndex;\n return this._partitions[nextPartitionIndex];\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Used by EventHubConsumerClient to prevent accidentally spinning up multiple
3
+ * subscriptions against the same set of partitions.
4
+ *
5
+ * This is needed now that EventHubConsumerClient only uses a single CheckpointStore
6
+ * instance - otherwise users will see unpredictable results as their event processor
7
+ * continually steals/overwrites checkpointing and ownership with itself.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare class PartitionGate {
12
+ private _partitions;
13
+ /**
14
+ * Adds a partition, throwing an Error if there is a conflict with partitions (including "all")
15
+ * that are already added.
16
+ *
17
+ * @param partitionId - A partition ID or the constant "all"
18
+ */
19
+ add(partitionId: string | "all"): void;
20
+ /**
21
+ * Removes a partition
22
+ *
23
+ * @param partitionId - A partition ID or the constant "all"
24
+ */
25
+ remove(partitionId: string | "all"): void;
26
+ }
27
+ //# sourceMappingURL=partitionGate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partitionGate.d.ts","sourceRoot":"","sources":["../../../src/impl/partitionGate.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,WAAW,CAAqB;IAExC;;;;;OAKG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAYtC;;;;OAIG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;CAG1C"}
@@ -0,0 +1,38 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Used by EventHubConsumerClient to prevent accidentally spinning up multiple
5
+ * subscriptions against the same set of partitions.
6
+ *
7
+ * This is needed now that EventHubConsumerClient only uses a single CheckpointStore
8
+ * instance - otherwise users will see unpredictable results as their event processor
9
+ * continually steals/overwrites checkpointing and ownership with itself.
10
+ *
11
+ * @internal
12
+ */
13
+ export class PartitionGate {
14
+ _partitions = new Set();
15
+ /**
16
+ * Adds a partition, throwing an Error if there is a conflict with partitions (including "all")
17
+ * that are already added.
18
+ *
19
+ * @param partitionId - A partition ID or the constant "all"
20
+ */
21
+ add(partitionId) {
22
+ if ((partitionId === "all" && this._partitions.size > 0) ||
23
+ this._partitions.has(partitionId) ||
24
+ this._partitions.has("all")) {
25
+ throw new Error(`Partition already has a subscriber.`);
26
+ }
27
+ this._partitions.add(partitionId);
28
+ }
29
+ /**
30
+ * Removes a partition
31
+ *
32
+ * @param partitionId - A partition ID or the constant "all"
33
+ */
34
+ remove(partitionId) {
35
+ this._partitions.delete(partitionId);
36
+ }
37
+ }
38
+ //# sourceMappingURL=partitionGate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partitionGate.js","sourceRoot":"","sources":["../../../src/impl/partitionGate.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAa;IAChB,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IAExC;;;;;OAKG;IACH,GAAG,CAAC,WAA2B;QAC7B,IACE,CAAC,WAAW,KAAK,KAAK,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,CAAC;YACpD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC;YACjC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAC3B,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WAA2B;QAChC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Used by EventHubConsumerClient to prevent accidentally spinning up multiple\n * subscriptions against the same set of partitions.\n *\n * This is needed now that EventHubConsumerClient only uses a single CheckpointStore\n * instance - otherwise users will see unpredictable results as their event processor\n * continually steals/overwrites checkpointing and ownership with itself.\n *\n * @internal\n */\nexport class PartitionGate {\n private _partitions = new Set<string>();\n\n /**\n * Adds a partition, throwing an Error if there is a conflict with partitions (including \"all\")\n * that are already added.\n *\n * @param partitionId - A partition ID or the constant \"all\"\n */\n add(partitionId: string | \"all\"): void {\n if (\n (partitionId === \"all\" && this._partitions.size > 0) ||\n this._partitions.has(partitionId) ||\n this._partitions.has(\"all\")\n ) {\n throw new Error(`Partition already has a subscriber.`);\n }\n\n this._partitions.add(partitionId);\n }\n\n /**\n * Removes a partition\n *\n * @param partitionId - A partition ID or the constant \"all\"\n */\n remove(partitionId: string | \"all\"): void {\n this._partitions.delete(partitionId);\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export declare function mapPartitionKeyToId(partitionKey: string, partitionCount: number): number;
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function hashPartitionKey(partitionKey: string): number;
6
+ //# sourceMappingURL=partitionKeyToIdMapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partitionKeyToIdMapper.d.ts","sourceRoot":"","sources":["../../../src/impl/partitionKeyToIdMapper.ts"],"names":[],"mappings":"AAKA,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAGxF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAG7D"}
@@ -0,0 +1,111 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /* eslint-disable no-fallthrough */
4
+ export function mapPartitionKeyToId(partitionKey, partitionCount) {
5
+ const hashedParitionKey = hashPartitionKey(partitionKey);
6
+ return Math.abs(hashedParitionKey % partitionCount);
7
+ }
8
+ /**
9
+ * @internal
10
+ */
11
+ export function hashPartitionKey(partitionKey) {
12
+ const hash = computeHash(Buffer.from(partitionKey, "utf8"));
13
+ return castToInt16(hash.c ^ hash.b);
14
+ }
15
+ function readUInt32(data, offset) {
16
+ return data.readUInt32LE(offset);
17
+ }
18
+ function castToInt16(n) {
19
+ return new Int16Array([n])[0];
20
+ }
21
+ function computeHash(data, seed1 = 0, seed2 = 0) {
22
+ let a, b, c;
23
+ a = b = c = 0xdeadbeef + data.length + seed1;
24
+ c += seed2;
25
+ let index = 0, size = data.length;
26
+ while (size > 12) {
27
+ a += readUInt32(data, index);
28
+ b += readUInt32(data, index + 4);
29
+ c += readUInt32(data, index + 8);
30
+ a -= c;
31
+ a ^= (c << 4) | (c >>> 28);
32
+ c += b;
33
+ b -= a;
34
+ b ^= (a << 6) | (a >>> 26);
35
+ a += c;
36
+ c -= b;
37
+ c ^= (b << 8) | (b >>> 24);
38
+ b += a;
39
+ a -= c;
40
+ a ^= (c << 16) | (c >>> 16);
41
+ c += b;
42
+ b -= a;
43
+ b ^= (a << 19) | (a >>> 13);
44
+ a += c;
45
+ c -= b;
46
+ c ^= (b << 4) | (b >>> 28);
47
+ b += a;
48
+ index += 12;
49
+ size -= 12;
50
+ }
51
+ let curr = size;
52
+ switch (curr) {
53
+ case 12:
54
+ a += readUInt32(data, index);
55
+ b += readUInt32(data, index + 4);
56
+ c += readUInt32(data, index + 8);
57
+ break;
58
+ case 11:
59
+ c += data[index + 10] << 16;
60
+ curr = 10;
61
+ case 10:
62
+ c += data[index + 9] << 8;
63
+ curr = 9;
64
+ case 9:
65
+ c += data[index + 8];
66
+ curr = 8;
67
+ case 8:
68
+ b += readUInt32(data, index + 4);
69
+ a += readUInt32(data, index);
70
+ break;
71
+ case 7:
72
+ b += data[index + 6] << 16;
73
+ curr = 6;
74
+ case 6:
75
+ b += data[index + 5] << 8;
76
+ curr = 5;
77
+ case 5:
78
+ b += data[index + 4];
79
+ curr = 4;
80
+ case 4:
81
+ a += readUInt32(data, index);
82
+ break;
83
+ case 3:
84
+ a += data[index + 2] << 16;
85
+ curr = 2;
86
+ case 2:
87
+ a += data[index + 1] << 8;
88
+ curr = 1;
89
+ case 1:
90
+ a += data[index];
91
+ break;
92
+ case 0:
93
+ return { b: b >>> 0, c: c >>> 0 };
94
+ }
95
+ c ^= b;
96
+ c -= (b << 14) | (b >>> 18);
97
+ a ^= c;
98
+ a -= (c << 11) | (c >>> 21);
99
+ b ^= a;
100
+ b -= (a << 25) | (a >>> 7);
101
+ c ^= b;
102
+ c -= (b << 16) | (b >>> 16);
103
+ a ^= c;
104
+ a -= (c << 4) | (c >>> 28);
105
+ b ^= a;
106
+ b -= (a << 14) | (a >>> 18);
107
+ c ^= b;
108
+ c -= (b << 24) | (b >>> 8);
109
+ return { b: b >>> 0, c: c >>> 0 };
110
+ }
111
+ //# sourceMappingURL=partitionKeyToIdMapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partitionKeyToIdMapper.js","sourceRoot":"","sources":["../../../src/impl/partitionKeyToIdMapper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,mCAAmC;AAEnC,MAAM,UAAU,mBAAmB,CAAC,YAAoB,EAAE,cAAsB;IAC9E,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACzD,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,GAAG,cAAc,CAAC,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAoB;IACnD,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5D,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,UAAU,CAAC,IAAY,EAAE,MAAc;IAC9C,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAAC,CAAS;IAC5B,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,WAAW,CAClB,IAAY,EACZ,QAAgB,CAAC,EACjB,QAAgB,CAAC;IAKjB,IAAI,CAAS,EAAE,CAAS,EAAE,CAAS,CAAC;IAEpC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IAC7C,CAAC,IAAI,KAAK,CAAC;IAEX,IAAI,KAAK,GAAG,CAAC,EACX,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;IACrB,OAAO,IAAI,GAAG,EAAE,EAAE,CAAC;QACjB,CAAC,IAAI,UAAU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AO,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;AACpC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable no-fallthrough */\n\nexport function mapPartitionKeyToId(partitionKey: string, partitionCount: number): number {\n const hashedParitionKey = hashPartitionKey(partitionKey);\n return Math.abs(hashedParitionKey % partitionCount);\n}\n\n/**\n * @internal\n */\nexport function hashPartitionKey(partitionKey: string): number {\n const hash = computeHash(Buffer.from(partitionKey, \"utf8\"));\n return castToInt16(hash.c ^ hash.b);\n}\n\nfunction readUInt32(data: Buffer, offset: number): number {\n return data.readUInt32LE(offset);\n}\n\nfunction castToInt16(n: number): number {\n return new Int16Array([n])[0];\n}\n\nfunction computeHash(\n data: Buffer,\n seed1: number = 0,\n seed2: number = 0,\n): {\n b: number;\n c: number;\n} {\n let a: number, b: number, c: number;\n\n a = b = c = 0xdeadbeef + data.length + seed1;\n c += seed2;\n\n let index = 0,\n size = data.length;\n while (size > 12) {\n a += readUInt32(data, index);\n b += readUInt32(data, index + 4);\n c += readUInt32(data, index + 8);\n\n a -= c;\n a ^= (c << 4) | (c >>> 28);\n c += b;\n\n b -= a;\n b ^= (a << 6) | (a >>> 26);\n a += c;\n\n c -= b;\n c ^= (b << 8) | (b >>> 24);\n b += a;\n\n a -= c;\n a ^= (c << 16) | (c >>> 16);\n c += b;\n\n b -= a;\n b ^= (a << 19) | (a >>> 13);\n a += c;\n\n c -= b;\n c ^= (b << 4) | (b >>> 28);\n b += a;\n\n index += 12;\n size -= 12;\n }\n\n let curr = size;\n switch (curr) {\n case 12:\n a += readUInt32(data, index);\n b += readUInt32(data, index + 4);\n c += readUInt32(data, index + 8);\n break;\n case 11:\n c += data[index + 10] << 16;\n curr = 10;\n case 10:\n c += data[index + 9] << 8;\n curr = 9;\n case 9:\n c += data[index + 8];\n curr = 8;\n case 8:\n b += readUInt32(data, index + 4);\n a += readUInt32(data, index);\n break;\n case 7:\n b += data[index + 6] << 16;\n curr = 6;\n case 6:\n b += data[index + 5] << 8;\n curr = 5;\n case 5:\n b += data[index + 4];\n curr = 4;\n case 4:\n a += readUInt32(data, index);\n break;\n case 3:\n a += data[index + 2] << 16;\n curr = 2;\n case 2:\n a += data[index + 1] << 8;\n curr = 1;\n case 1:\n a += data[index];\n break;\n case 0:\n return { b: b >>> 0, c: c >>> 0 };\n }\n\n c ^= b;\n c -= (b << 14) | (b >>> 18);\n\n a ^= c;\n a -= (c << 11) | (c >>> 21);\n\n b ^= a;\n b -= (a << 25) | (a >>> 7);\n\n c ^= b;\n c -= (b << 16) | (b >>> 16);\n\n a ^= c;\n a -= (c << 4) | (c >>> 28);\n\n b ^= a;\n b -= (a << 14) | (a >>> 18);\n\n c ^= b;\n c -= (b << 24) | (b >>> 8);\n\n return { b: b >>> 0, c: c >>> 0 };\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import type { CheckpointStore, PartitionOwnership } from "./eventProcessor.js";
2
+ import type { Checkpoint } from "./partitionProcessor.js";
3
+ /**
4
+ * The `EventProcessor` relies on a `CheckpointStore` to store checkpoints and handle partition
5
+ * ownerships. `InMemoryCheckpointStore` is simple partition manager that stores checkpoints and
6
+ * partition ownerships in memory of your program.
7
+ *
8
+ * You can use the `InMemoryCheckpointStore` to get started with using the `EventProcessor`.
9
+ * But in production, you should choose an implementation of the `CheckpointStore` interface that will
10
+ * store the checkpoints and partition ownerships to a durable store instead.
11
+ *
12
+ * @internal
13
+ */
14
+ export declare class InMemoryCheckpointStore implements CheckpointStore {
15
+ private _partitionOwnershipMap;
16
+ private _committedCheckpoints;
17
+ /**
18
+ * Get the list of all existing partition ownership from the underlying data store. Could return empty
19
+ * results if there are is no existing ownership information.
20
+ *
21
+ * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to
22
+ * <yournamespace>.servicebus.windows.net.
23
+ * @param eventHubName - The event hub name.
24
+ * @param consumerGroup - The consumer group name.
25
+ * @returns Partition ownership details of all the partitions that have/had an owner..
26
+ */
27
+ listOwnership(_fullyQualifiedNamespace: string, _eventHubName: string, _consumerGroup: string): Promise<PartitionOwnership[]>;
28
+ /**
29
+ * Claim ownership of a list of partitions. This will return the list of partitions that were owned
30
+ * successfully.
31
+ *
32
+ * @param partitionOwnership - The list of partition ownership this instance is claiming to own.
33
+ * @returns A list partitions this instance successfully claimed ownership.
34
+ */
35
+ claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]>;
36
+ /**
37
+ * Updates the checkpoint in the data store for a partition.
38
+ *
39
+ * @param checkpoint - The checkpoint.
40
+ */
41
+ updateCheckpoint(checkpoint: Checkpoint): Promise<void>;
42
+ listCheckpoints(fullyQualifiedNamespace: string, eventHubName: string, consumerGroup: string): Promise<Checkpoint[]>;
43
+ }
44
+ //# sourceMappingURL=inMemoryCheckpointStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inMemoryCheckpointStore.d.ts","sourceRoot":"","sources":["../../src/inMemoryCheckpointStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1D;;;;;;;;;;GAUG;AACH,qBAAa,uBAAwB,YAAW,eAAe;IAC7D,OAAO,CAAC,sBAAsB,CAA8C;IAC5E,OAAO,CAAC,qBAAqB,CAAmD;IAEhF;;;;;;;;;OASG;IACG,aAAa,CACjB,wBAAwB,EAAE,MAAM,EAChC,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAUhC;;;;;;OAMG;IACG,cAAc,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAuB7F;;;;OAIG;IACG,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BvD,eAAe,CACnB,uBAAuB,EAAE,MAAM,EAC/B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,UAAU,EAAE,CAAC;CAiBzB"}