@azure/event-hubs 6.0.1-alpha.20250619.1 → 6.0.1-alpha.20250730.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 (140) hide show
  1. package/dist/browser/batchingPartitionChannel.js +23 -17
  2. package/dist/browser/batchingPartitionChannel.js.map +1 -1
  3. package/dist/browser/connectionContext.js +18 -32
  4. package/dist/browser/connectionContext.js.map +1 -1
  5. package/dist/browser/diagnostics/instrumentEventData.js +6 -7
  6. package/dist/browser/diagnostics/instrumentEventData.js.map +1 -1
  7. package/dist/browser/eventData.js +6 -4
  8. package/dist/browser/eventData.js.map +1 -1
  9. package/dist/browser/eventDataAdapter.js +5 -2
  10. package/dist/browser/eventDataAdapter.js.map +1 -1
  11. package/dist/browser/eventDataBatch.js +61 -9
  12. package/dist/browser/eventDataBatch.js.map +1 -1
  13. package/dist/browser/eventHubBufferedProducerClient.js +65 -50
  14. package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
  15. package/dist/browser/eventHubConsumerClient.js +70 -24
  16. package/dist/browser/eventHubConsumerClient.js.map +1 -1
  17. package/dist/browser/eventHubProducerClient.js +58 -15
  18. package/dist/browser/eventHubProducerClient.js.map +1 -1
  19. package/dist/browser/eventHubSender.js +118 -35
  20. package/dist/browser/eventHubSender.js.map +1 -1
  21. package/dist/browser/eventProcessor.js +27 -5
  22. package/dist/browser/eventProcessor.js.map +1 -1
  23. package/dist/browser/impl/awaitableQueue.js +6 -2
  24. package/dist/browser/impl/awaitableQueue.js.map +1 -1
  25. package/dist/browser/impl/partitionAssigner.js +2 -4
  26. package/dist/browser/impl/partitionAssigner.js.map +1 -1
  27. package/dist/browser/impl/partitionGate.js +1 -3
  28. package/dist/browser/impl/partitionGate.js.map +1 -1
  29. package/dist/browser/inMemoryCheckpointStore.js +10 -8
  30. package/dist/browser/inMemoryCheckpointStore.js.map +1 -1
  31. package/dist/browser/loadBalancerStrategies/balancedStrategy.js +1 -0
  32. package/dist/browser/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  33. package/dist/browser/loadBalancerStrategies/greedyStrategy.js +1 -0
  34. package/dist/browser/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  35. package/dist/browser/managementClient.js +53 -19
  36. package/dist/browser/managementClient.js.map +1 -1
  37. package/dist/browser/partitionProcessor.js +5 -2
  38. package/dist/browser/partitionProcessor.js.map +1 -1
  39. package/dist/browser/partitionPump.js +15 -6
  40. package/dist/browser/partitionPump.js.map +1 -1
  41. package/dist/browser/partitionReceiver.js +30 -25
  42. package/dist/browser/partitionReceiver.js.map +1 -1
  43. package/dist/browser/pumpManager.js +3 -1
  44. package/dist/browser/pumpManager.js.map +1 -1
  45. package/dist/browser/util/delayWithoutThrow.js +1 -1
  46. package/dist/browser/util/delayWithoutThrow.js.map +1 -1
  47. package/dist/commonjs/batchingPartitionChannel.js +23 -17
  48. package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
  49. package/dist/commonjs/connectionContext.js +18 -32
  50. package/dist/commonjs/connectionContext.js.map +1 -1
  51. package/dist/commonjs/diagnostics/instrumentEventData.js +6 -7
  52. package/dist/commonjs/diagnostics/instrumentEventData.js.map +1 -1
  53. package/dist/commonjs/eventData.js +6 -4
  54. package/dist/commonjs/eventData.js.map +1 -1
  55. package/dist/commonjs/eventDataAdapter.js +5 -2
  56. package/dist/commonjs/eventDataAdapter.js.map +1 -1
  57. package/dist/commonjs/eventDataBatch.js +61 -9
  58. package/dist/commonjs/eventDataBatch.js.map +1 -1
  59. package/dist/commonjs/eventHubBufferedProducerClient.js +65 -50
  60. package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
  61. package/dist/commonjs/eventHubConsumerClient.js +70 -24
  62. package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
  63. package/dist/commonjs/eventHubProducerClient.js +58 -15
  64. package/dist/commonjs/eventHubProducerClient.js.map +1 -1
  65. package/dist/commonjs/eventHubSender.js +118 -35
  66. package/dist/commonjs/eventHubSender.js.map +1 -1
  67. package/dist/commonjs/eventProcessor.js +27 -5
  68. package/dist/commonjs/eventProcessor.js.map +1 -1
  69. package/dist/commonjs/impl/awaitableQueue.js +6 -2
  70. package/dist/commonjs/impl/awaitableQueue.js.map +1 -1
  71. package/dist/commonjs/impl/partitionAssigner.js +2 -4
  72. package/dist/commonjs/impl/partitionAssigner.js.map +1 -1
  73. package/dist/commonjs/impl/partitionGate.js +1 -3
  74. package/dist/commonjs/impl/partitionGate.js.map +1 -1
  75. package/dist/commonjs/inMemoryCheckpointStore.js +10 -8
  76. package/dist/commonjs/inMemoryCheckpointStore.js.map +1 -1
  77. package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js +1 -0
  78. package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  79. package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js +1 -0
  80. package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  81. package/dist/commonjs/managementClient.js +53 -19
  82. package/dist/commonjs/managementClient.js.map +1 -1
  83. package/dist/commonjs/partitionProcessor.js +5 -2
  84. package/dist/commonjs/partitionProcessor.js.map +1 -1
  85. package/dist/commonjs/partitionPump.js +15 -6
  86. package/dist/commonjs/partitionPump.js.map +1 -1
  87. package/dist/commonjs/partitionReceiver.js +30 -25
  88. package/dist/commonjs/partitionReceiver.js.map +1 -1
  89. package/dist/commonjs/pumpManager.js +3 -1
  90. package/dist/commonjs/pumpManager.js.map +1 -1
  91. package/dist/commonjs/tsdoc-metadata.json +11 -11
  92. package/dist/commonjs/util/delayWithoutThrow.js +1 -1
  93. package/dist/commonjs/util/delayWithoutThrow.js.map +1 -1
  94. package/dist/esm/batchingPartitionChannel.js +23 -17
  95. package/dist/esm/batchingPartitionChannel.js.map +1 -1
  96. package/dist/esm/connectionContext.js +18 -32
  97. package/dist/esm/connectionContext.js.map +1 -1
  98. package/dist/esm/diagnostics/instrumentEventData.js +6 -7
  99. package/dist/esm/diagnostics/instrumentEventData.js.map +1 -1
  100. package/dist/esm/eventData.js +6 -4
  101. package/dist/esm/eventData.js.map +1 -1
  102. package/dist/esm/eventDataAdapter.js +5 -2
  103. package/dist/esm/eventDataAdapter.js.map +1 -1
  104. package/dist/esm/eventDataBatch.js +61 -9
  105. package/dist/esm/eventDataBatch.js.map +1 -1
  106. package/dist/esm/eventHubBufferedProducerClient.js +65 -50
  107. package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
  108. package/dist/esm/eventHubConsumerClient.js +70 -24
  109. package/dist/esm/eventHubConsumerClient.js.map +1 -1
  110. package/dist/esm/eventHubProducerClient.js +58 -15
  111. package/dist/esm/eventHubProducerClient.js.map +1 -1
  112. package/dist/esm/eventHubSender.js +118 -35
  113. package/dist/esm/eventHubSender.js.map +1 -1
  114. package/dist/esm/eventProcessor.js +27 -5
  115. package/dist/esm/eventProcessor.js.map +1 -1
  116. package/dist/esm/impl/awaitableQueue.js +6 -2
  117. package/dist/esm/impl/awaitableQueue.js.map +1 -1
  118. package/dist/esm/impl/partitionAssigner.js +2 -4
  119. package/dist/esm/impl/partitionAssigner.js.map +1 -1
  120. package/dist/esm/impl/partitionGate.js +1 -3
  121. package/dist/esm/impl/partitionGate.js.map +1 -1
  122. package/dist/esm/inMemoryCheckpointStore.js +10 -8
  123. package/dist/esm/inMemoryCheckpointStore.js.map +1 -1
  124. package/dist/esm/loadBalancerStrategies/balancedStrategy.js +1 -0
  125. package/dist/esm/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  126. package/dist/esm/loadBalancerStrategies/greedyStrategy.js +1 -0
  127. package/dist/esm/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  128. package/dist/esm/managementClient.js +53 -19
  129. package/dist/esm/managementClient.js.map +1 -1
  130. package/dist/esm/partitionProcessor.js +5 -2
  131. package/dist/esm/partitionProcessor.js.map +1 -1
  132. package/dist/esm/partitionPump.js +15 -6
  133. package/dist/esm/partitionPump.js.map +1 -1
  134. package/dist/esm/partitionReceiver.js +30 -25
  135. package/dist/esm/partitionReceiver.js.map +1 -1
  136. package/dist/esm/pumpManager.js +3 -1
  137. package/dist/esm/pumpManager.js.map +1 -1
  138. package/dist/esm/util/delayWithoutThrow.js +1 -1
  139. package/dist/esm/util/delayWithoutThrow.js.map +1 -1
  140. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"connectionContext.js","sourceRoot":"","sources":["../../src/connectionContext.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,SAAS,EACT,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGzE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAwG1D;;GAEG;AACH,MAAM,KAAW,iBAAiB,CAkUjC;AAlUD,WAAiB,iBAAiB;IAChC;;;OAGG;IACH,MAAM,SAAS,GAAW,2BACxB,eAAe,CAAC,OAClB,KAAK,cAAc,EAAE,GAAG,CAAC;IAEzB,SAAgB,YAAY,CAAC,OAAiC;QAC5D,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,OAAO,CAAC,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AI,oBAAoB,CAAC,mBAAmB,CAAC,IAAI,eAAe,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACtF,UAAU,GAAG,sBAAsB,CAAC,mBAAmB,CAAC,CAAC;QAC3D,CAAC;aAAM,CAAC;YACN,UAAU,GAAG,mBAAmB,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;QACnD,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,IAAI,IAAI,GAAG,CAAC;QACrC,gBAAgB,GAAG,iBAAiB,IAAI,kFAAkF,YAAY,EAAE,CAAC;QACzI,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,qBAAqB,EAAE,CAAC;QACnC,wBAAwB,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC3F,CAAC;IAED,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable @typescript-eslint/no-namespace */\n/* eslint-disable no-inner-declarations */\n\nimport type { Connection, Dictionary, EventContext, OnAmqpEvent } from \"rhea-promise\";\nimport { ConnectionEvents } from \"rhea-promise\";\nimport type { CreateConnectionContextBaseParameters, SasTokenProvider } from \"@azure/core-amqp\";\nimport {\n ConnectionConfig,\n ConnectionContextBase,\n Constants,\n createSasTokenProvider,\n} from \"@azure/core-amqp\";\nimport type { EventHubConnectionStringProperties } from \"./util/connectionStringUtils.js\";\nimport { parseEventHubConnectionString } from \"./util/connectionStringUtils.js\";\nimport type { ManagementClientOptions } from \"./managementClient.js\";\nimport { ManagementClient } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isNamedKeyCredential, isSASCredential } from \"@azure/core-auth\";\nimport { logErrorStackTrace, logger } from \"./logger.js\";\nimport type { EventHubClientOptions } from \"./models/public.js\";\nimport { EventHubConnectionConfig } from \"./eventhubConnectionConfig.js\";\nimport type { PartitionReceiver } from \"./partitionReceiver.js\";\nimport type { EventHubSender } from \"./eventHubSender.js\";\nimport { getRuntimeInfo } from \"./util/runtimeInfo.js\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { packageJsonInfo } from \"./util/constants.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { createAbortablePromise } from \"@azure/core-util\";\n\n/**\n * @internal\n * Provides contextual information like the underlying amqp connection, cbs session, management session,\n * tokenProvider, senders, receivers, etc. about the EventHub client.\n */\nexport interface ConnectionContext extends ConnectionContextBase {\n /**\n * The EventHub connection config that is created after\n * parsing the connection string.\n */\n readonly config: EventHubConnectionConfig;\n /**\n * The credential to be used for Authentication.\n * Default value: SasTokenProvider.\n */\n tokenCredential: SasTokenProvider | TokenCredential;\n /**\n * Indicates whether the close() method was\n * called on theconnection object.\n */\n wasConnectionCloseCalled: boolean;\n /**\n * A dictionary of the EventHub Receivers associated with this client.\n */\n receivers: Dictionary<PartitionReceiver>;\n /**\n * A dictionary of the EventHub Senders associated with this client.\n */\n senders: Dictionary<EventHubSender>;\n /**\n * A reference to the management session ($management endpoint) on\n * the underlying amqp connection for the EventHub Client.\n */\n managementSession?: ManagementClient;\n /**\n * Function returning a promise that resolves once the connectionContext is ready to open an AMQP link.\n * ConnectionContext will be ready to open an AMQP link when:\n * - The AMQP connection is already open on both sides.\n * - The AMQP connection has been closed or disconnected. In this case, a new AMQP connection is expected\n * to be created first.\n * An AMQP link cannot be opened if the AMQP connection\n * is in the process of closing or disconnecting.\n */\n readyToOpenLink(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Closes all AMQP links, sessions and connection.\n */\n close(): Promise<void>;\n}\n\n/**\n * Describes the members on the ConnectionContext that are only\n * used by it internally.\n * @internal\n */\nexport interface ConnectionContextInternalMembers extends ConnectionContext {\n /**\n * Indicates whether the connection is in the process of closing.\n * When this returns `true`, a `disconnected` event will be received\n * after the connection is closed.\n *\n */\n isConnectionClosing(): boolean;\n /**\n * Resolves once the context's connection emits a `disconnected` event.\n */\n waitForDisconnectedEvent(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Resolves once the connection has finished being reset.\n * Connections are reset as part of reacting to a `disconnected` event.\n */\n waitForConnectionReset(): Promise<void>;\n}\n\n/**\n * @internal\n */\nexport interface ConnectionContextOptions extends EventHubClientOptions {\n managementSessionAddress?: string;\n managementSessionAudience?: string;\n}\n\n/**\n * Helper type to get the names of all the functions on an object.\n */\ntype FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]; // eslint-disable-line @typescript-eslint/no-unsafe-function-type\n/**\n * Helper type to get the types of all the functions on an object.\n */\ntype FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;\n/**\n * Helper type to get the types of all the functions on ConnectionContext\n * and the internal methods from ConnectionContextInternalMembers.\n * Note that this excludes the functions that ConnectionContext inherits.\n * Each function also has its `this` type set as `ConnectionContext`.\n */\ntype ConnectionContextMethods = Omit<\n FunctionProperties<ConnectionContextInternalMembers>,\n FunctionPropertyNames<ConnectionContextBase>\n> &\n ThisType<ConnectionContextInternalMembers>;\n\n/**\n * @internal\n */\nexport namespace ConnectionContext {\n /**\n * The user agent string for the EventHubs client.\n * See guideline at https://github.com/Azure/azure-sdk/blob/main/docs/design/Telemetry.mdk\n */\n const userAgent: string = `azsdk-js-azureeventhubs/${\n packageJsonInfo.version\n } (${getRuntimeInfo()})`;\n\n export function getUserAgent(options: ConnectionContextOptions): string {\n const finalUserAgent = options.userAgent ? `${userAgent},${options.userAgent}` : userAgent;\n if (finalUserAgent.length > Constants.maxUserAgentLength) {\n throw new Error(\n `The user-agent string cannot be more than ${Constants.maxUserAgentLength} characters in length.` +\n `The given user-agent string is: ${finalUserAgent} with length: ${finalUserAgent.length}`,\n );\n }\n return finalUserAgent;\n }\n\n export function create(\n config: EventHubConnectionConfig,\n tokenCredential: SasTokenProvider | TokenCredential,\n options?: ConnectionContextOptions,\n ): ConnectionContext {\n if (!options) options = {};\n\n config.webSocket = options.webSocketOptions && options.webSocketOptions.webSocket;\n config.webSocketEndpointPath = \"$servicebus/websocket\";\n config.webSocketConstructorOptions =\n options.webSocketOptions && options.webSocketOptions.webSocketConstructorOptions;\n\n const parameters: CreateConnectionContextBaseParameters = {\n config: config,\n // re-enabling this will be a post-GA discussion.\n // dataTransformer: options.dataTransformer,\n isEntityPathRequired: true,\n connectionProperties: {\n product: \"MSJSClient\",\n userAgent: getUserAgent(options),\n version: packageJsonInfo.version,\n },\n };\n // Let us create the base context and then add EventHub specific ConnectionContext properties.\n const connectionContext = ConnectionContextBase.create(parameters) as ConnectionContext;\n connectionContext.tokenCredential = tokenCredential;\n connectionContext.wasConnectionCloseCalled = false;\n connectionContext.senders = {};\n connectionContext.receivers = {};\n const mOptions: ManagementClientOptions = {\n address: options.managementSessionAddress,\n audience: options.managementSessionAudience,\n };\n connectionContext.managementSession = new ManagementClient(connectionContext, mOptions);\n\n let waitForConnectionRefreshResolve: () => void;\n let waitForConnectionRefreshPromise: Promise<void> | undefined;\n\n Object.assign<ConnectionContext, ConnectionContextMethods>(connectionContext, {\n isConnectionClosing() {\n // When the connection is not open, but the remote end is open,\n // then the rhea connection is in the process of terminating.\n return Boolean(!this.connection.isOpen() && this.connection.isRemoteOpen());\n },\n async readyToOpenLink(optionsArg?: { abortSignal?: AbortSignalLike }) {\n // Check that the connection isn't in the process of closing.\n // This can happen when the idle timeout has been reached but\n // the underlying socket is waiting to be destroyed.\n if (this.isConnectionClosing()) {\n // Wait for the disconnected event that indicates the underlying socket has closed.\n await this.waitForDisconnectedEvent(optionsArg);\n }\n\n // Wait for the connection to be reset.\n await this.waitForConnectionReset();\n },\n waitForDisconnectedEvent(optionsArg?: { abortSignal?: AbortSignalLike }) {\n return createAbortablePromise((resolve) => {\n logger.verbose(\n `[${this.connectionId}] Attempting to reinitialize connection` +\n ` but the connection is in the process of closing.` +\n ` Waiting for the disconnect event before continuing.`,\n );\n this.connection.once(ConnectionEvents.disconnected, resolve);\n }, optionsArg);\n },\n waitForConnectionReset() {\n // Check if the connection is currently in the process of disconnecting.\n if (waitForConnectionRefreshPromise) {\n return waitForConnectionRefreshPromise;\n }\n return Promise.resolve();\n },\n async close() {\n try {\n if (this.connection.isOpen()) {\n // Close all the senders.\n await Promise.all(\n Object.keys(connectionContext.senders).map((name) =>\n connectionContext.senders[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n // Close all the receivers.\n await Promise.all(\n Object.keys(connectionContext.receivers).map((name) =>\n connectionContext.receivers[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n // Close the cbs session;\n await this.cbsSession.close();\n // Close the management session\n await this.managementSession?.close();\n await this.connection.close();\n this.wasConnectionCloseCalled = true;\n logger.info(\"Closed the amqp connection '%s' on the client.\", this.connectionId);\n }\n } catch (err: any) {\n const errorDescription =\n err instanceof Error ? `${err.name}: ${err.message}` : JSON.stringify(err);\n logger.warning(\n `An error occurred while closing the connection \"${this.connectionId}\":\\n${errorDescription}`,\n );\n logErrorStackTrace(err);\n throw err;\n }\n },\n });\n\n // Define listeners to be added to the connection object for\n // \"connection_open\" and \"connection_error\" events.\n const onConnectionOpen: OnAmqpEvent = () => {\n connectionContext.wasConnectionCloseCalled = false;\n logger.verbose(\n \"[%s] setting 'wasConnectionCloseCalled' property of connection context to %s.\",\n connectionContext.connection.id,\n connectionContext.wasConnectionCloseCalled,\n );\n };\n\n const onDisconnected: OnAmqpEvent = async (context: EventContext) => {\n if (waitForConnectionRefreshPromise) {\n return;\n }\n waitForConnectionRefreshPromise = new Promise((resolve) => {\n waitForConnectionRefreshResolve = resolve;\n });\n try {\n logger.verbose(\n \"[%s] 'disconnected' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n const state: Readonly<{\n wasConnectionCloseCalled: boolean;\n numSenders: number;\n numReceivers: number;\n }> = {\n wasConnectionCloseCalled: connectionContext.wasConnectionCloseCalled,\n numSenders: Object.keys(connectionContext.senders).length,\n numReceivers: Object.keys(connectionContext.receivers).length,\n };\n logger.verbose(\n \"[%s] Closing all open senders and receivers in the state: %O\",\n connectionContext.connection.id,\n state,\n );\n\n // Clear internal map maintained by rhea to avoid reconnecting of old links once the\n // connection is back up.\n connectionContext.connection.removeAllSessions();\n\n // Close the cbs session to ensure all the event handlers are released.\n await connectionContext.cbsSession?.close().catch(() => {\n /* error already logged, swallow it here */\n });\n // Close the management session to ensure all the event handlers are released.\n await connectionContext.managementSession?.close().catch(() => {\n /* error already logged, swallow it here */\n });\n\n // Close all senders and receivers to ensure clean up of timers & other resources.\n if (state.numSenders || state.numReceivers) {\n await Promise.all(\n Object.keys(connectionContext.senders).map((name) =>\n connectionContext.senders[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n\n await Promise.all(\n Object.keys(connectionContext.receivers).map((name) =>\n connectionContext.receivers[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n }\n } catch (err: any) {\n logger.verbose(\n `[${connectionContext.connectionId}] An error occurred while closing the connection in 'disconnected'. %O`,\n err,\n );\n }\n\n try {\n await refreshConnection(connectionContext);\n } catch (err: any) {\n logger.verbose(\n `[${connectionContext.connectionId}] An error occurred while refreshing the connection in 'disconnected'. %O`,\n err,\n );\n } finally {\n waitForConnectionRefreshResolve();\n waitForConnectionRefreshPromise = undefined;\n }\n };\n\n const protocolError: OnAmqpEvent = async (context: EventContext) => {\n logger.verbose(\n \"[%s] 'protocol_error' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n };\n\n const error: OnAmqpEvent = async (context: EventContext) => {\n logger.verbose(\n \"[%s] 'error' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n };\n\n function addConnectionListeners(connection: Connection): void {\n // Add listeners on the connection object.\n connection.on(ConnectionEvents.connectionOpen, onConnectionOpen);\n connection.on(ConnectionEvents.disconnected, onDisconnected);\n connection.on(ConnectionEvents.protocolError, protocolError);\n connection.on(ConnectionEvents.error, error);\n }\n\n function cleanConnectionContext(context: ConnectionContext): Promise<void> {\n // Remove listeners from the connection object.\n context.connection.removeListener(ConnectionEvents.connectionOpen, onConnectionOpen);\n context.connection.removeListener(ConnectionEvents.disconnected, onDisconnected);\n context.connection.removeListener(ConnectionEvents.protocolError, protocolError);\n context.connection.removeListener(ConnectionEvents.error, error);\n // Close the connection\n return context.connection.close();\n }\n\n async function refreshConnection(context: ConnectionContext): Promise<void> {\n const originalConnectionId = context.connectionId;\n try {\n await cleanConnectionContext(context);\n } catch (err: any) {\n logger.verbose(\n `[${context.connectionId}] There was an error closing the connection before reconnecting: %O`,\n err,\n );\n }\n\n // Create a new connection, id, locks, and cbs client.\n context.refreshConnection();\n addConnectionListeners(context.connection);\n logger.verbose(\n `The connection \"${originalConnectionId}\" has been updated to \"${context.connectionId}\".`,\n );\n }\n\n addConnectionListeners(connectionContext.connection);\n\n logger.verbose(\"[%s] Created connection context successfully.\", connectionContext.connectionId);\n return connectionContext;\n }\n}\n\n/**\n * Helper method to create a ConnectionContext from the input passed to either\n * EventHubProducerClient or EventHubConsumerClient constructors\n *\n * @internal\n */\nexport function createConnectionContext(\n hostOrConnectionString: string,\n eventHubNameOrOptions?: string | EventHubClientOptions,\n credentialOrOptions?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubClientOptions,\n options?: EventHubClientOptions,\n): ConnectionContext {\n let connectionString;\n let config;\n let credential: TokenCredential | SasTokenProvider;\n hostOrConnectionString = String(hostOrConnectionString);\n\n if (!isCredential(credentialOrOptions)) {\n const parsedCS = parseEventHubConnectionString(hostOrConnectionString);\n if (\n !(\n parsedCS.eventHubName ||\n (typeof eventHubNameOrOptions === \"string\" && eventHubNameOrOptions)\n )\n ) {\n throw new TypeError(\n `Either provide \"eventHubName\" or the \"connectionString\": \"${hostOrConnectionString}\", ` +\n `must contain \"EntityPath=<your-event-hub-name>\".`,\n );\n }\n if (\n parsedCS.eventHubName &&\n typeof eventHubNameOrOptions === \"string\" &&\n eventHubNameOrOptions &&\n parsedCS.eventHubName !== eventHubNameOrOptions\n ) {\n throw new TypeError(\n `The entity path \"${parsedCS.eventHubName}\" in connectionString: \"${hostOrConnectionString}\" ` +\n `doesn't match with eventHubName: \"${eventHubNameOrOptions}\".`,\n );\n }\n connectionString = hostOrConnectionString;\n if (typeof eventHubNameOrOptions !== \"string\") {\n // connectionstring and/or options were passed to constructor\n config = EventHubConnectionConfig.create(connectionString);\n options = eventHubNameOrOptions;\n } else {\n // connectionstring, eventHubName and/or options were passed to constructor\n const eventHubName = eventHubNameOrOptions;\n config = EventHubConnectionConfig.create(connectionString, eventHubName);\n options = credentialOrOptions;\n }\n\n const parsed = parseEventHubConnectionString(connectionString) as Required<\n | Pick<EventHubConnectionStringProperties, \"sharedAccessKey\" | \"sharedAccessKeyName\">\n | Pick<EventHubConnectionStringProperties, \"sharedAccessSignature\">\n >;\n // Since connectionString was passed, create a TokenProvider.\n credential = createSasTokenProvider(parsed);\n } else {\n // host, eventHubName, a TokenCredential and/or options were passed to constructor\n const eventHubName = eventHubNameOrOptions;\n let host = hostOrConnectionString;\n if (isNamedKeyCredential(credentialOrOptions) || isSASCredential(credentialOrOptions)) {\n credential = createSasTokenProvider(credentialOrOptions);\n } else {\n credential = credentialOrOptions;\n }\n if (!eventHubName) {\n throw new TypeError(`\"eventHubName\" is missing`);\n }\n\n if (!host.endsWith(\"/\")) host += \"/\";\n connectionString = `Endpoint=sb://${host};SharedAccessKeyName=defaultKeyName;SharedAccessKey=defaultKeyValue;EntityPath=${eventHubName}`;\n config = EventHubConnectionConfig.create(connectionString);\n }\n\n if (options?.customEndpointAddress) {\n EventHubConnectionConfig.setCustomEndpointAddress(config, options.customEndpointAddress);\n }\n\n ConnectionConfig.validate(config);\n\n return ConnectionContext.create(config, credential, options);\n}\n"]}
1
+ {"version":3,"file":"connectionContext.js","sourceRoot":"","sources":["../../src/connectionContext.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,SAAS,EACT,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGzE,O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/* eslint-disable no-inner-declarations */\n\nimport type { Connection, Dictionary, EventContext, OnAmqpEvent } from \"rhea-promise\";\nimport { ConnectionEvents } from \"rhea-promise\";\nimport type { CreateConnectionContextBaseParameters, SasTokenProvider } from \"@azure/core-amqp\";\nimport {\n ConnectionConfig,\n ConnectionContextBase,\n Constants,\n createSasTokenProvider,\n} from \"@azure/core-amqp\";\nimport type { EventHubConnectionStringProperties } from \"./util/connectionStringUtils.js\";\nimport { parseEventHubConnectionString } from \"./util/connectionStringUtils.js\";\nimport type { ManagementClientOptions } from \"./managementClient.js\";\nimport { ManagementClient } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isNamedKeyCredential, isSASCredential } from \"@azure/core-auth\";\nimport { logErrorStackTrace, logger } from \"./logger.js\";\nimport type { EventHubClientOptions } from \"./models/public.js\";\nimport { EventHubConnectionConfig } from \"./eventhubConnectionConfig.js\";\nimport type { PartitionReceiver } from \"./partitionReceiver.js\";\nimport type { EventHubSender } from \"./eventHubSender.js\";\nimport { getRuntimeInfo } from \"./util/runtimeInfo.js\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { packageJsonInfo } from \"./util/constants.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { createAbortablePromise } from \"@azure/core-util\";\n\n/**\n * @internal\n * Provides contextual information like the underlying amqp connection, cbs session, management session,\n * tokenProvider, senders, receivers, etc. about the EventHub client.\n */\nexport interface ConnectionContext extends ConnectionContextBase {\n /**\n * The EventHub connection config that is created after\n * parsing the connection string.\n */\n readonly config: EventHubConnectionConfig;\n /**\n * The credential to be used for Authentication.\n * Default value: SasTokenProvider.\n */\n tokenCredential: SasTokenProvider | TokenCredential;\n /**\n * Indicates whether the close() method was\n * called on theconnection object.\n */\n wasConnectionCloseCalled: boolean;\n /**\n * A dictionary of the EventHub Receivers associated with this client.\n */\n receivers: Dictionary<PartitionReceiver>;\n /**\n * A dictionary of the EventHub Senders associated with this client.\n */\n senders: Dictionary<EventHubSender>;\n /**\n * A reference to the management session ($management endpoint) on\n * the underlying amqp connection for the EventHub Client.\n */\n managementSession?: ManagementClient;\n /**\n * Function returning a promise that resolves once the connectionContext is ready to open an AMQP link.\n * ConnectionContext will be ready to open an AMQP link when:\n * - The AMQP connection is already open on both sides.\n * - The AMQP connection has been closed or disconnected. In this case, a new AMQP connection is expected\n * to be created first.\n * An AMQP link cannot be opened if the AMQP connection\n * is in the process of closing or disconnecting.\n */\n readyToOpenLink(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Closes all AMQP links, sessions and connection.\n */\n close(): Promise<void>;\n}\n\n/**\n * Describes the members on the ConnectionContext that are only\n * used by it internally.\n * @internal\n */\nexport interface ConnectionContextInternalMembers extends ConnectionContext {\n /**\n * Indicates whether the connection is in the process of closing.\n * When this returns `true`, a `disconnected` event will be received\n * after the connection is closed.\n *\n */\n isConnectionClosing(): boolean;\n /**\n * Resolves once the context's connection emits a `disconnected` event.\n */\n waitForDisconnectedEvent(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Resolves once the connection has finished being reset.\n * Connections are reset as part of reacting to a `disconnected` event.\n */\n waitForConnectionReset(): Promise<void>;\n}\n\n/**\n * @internal\n */\nexport interface ConnectionContextOptions extends EventHubClientOptions {\n managementSessionAddress?: string;\n managementSessionAudience?: string;\n}\n\n/**\n * Helper type to get the names of all the functions on an object.\n */\ntype FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]; // eslint-disable-line @typescript-eslint/no-unsafe-function-type\n/**\n * Helper type to get the types of all the functions on an object.\n */\ntype FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;\n/**\n * Helper type to get the types of all the functions on ConnectionContext\n * and the internal methods from ConnectionContextInternalMembers.\n * Note that this excludes the functions that ConnectionContext inherits.\n * Each function also has its `this` type set as `ConnectionContext`.\n */\ntype ConnectionContextMethods = Omit<\n FunctionProperties<ConnectionContextInternalMembers>,\n FunctionPropertyNames<ConnectionContextBase>\n> &\n ThisType<ConnectionContextInternalMembers>;\n\n/**\n * @internal\n */\nexport namespace ConnectionContext {\n /**\n * The user agent string for the EventHubs client.\n * See guideline at https://github.com/Azure/azure-sdk/blob/main/docs/design/Telemetry.mdk\n */\n const userAgent: string = `azsdk-js-azureeventhubs/${\n packageJsonInfo.version\n } (${getRuntimeInfo()})`;\n\n export function getUserAgent(options: ConnectionContextOptions): string {\n const finalUserAgent = options.userAgent ? `${userAgent},${options.userAgent}` : userAgent;\n if (finalUserAgent.length > Constants.maxUserAgentLength) {\n throw new Error(\n `The user-agent string cannot be more than ${Constants.maxUserAgentLength} characters in length.` +\n `The given user-agent string is: ${finalUserAgent} with length: ${finalUserAgent.length}`,\n );\n }\n return finalUserAgent;\n }\n\n export function create(\n config: EventHubConnectionConfig,\n tokenCredential: SasTokenProvider | TokenCredential,\n options?: ConnectionContextOptions,\n ): ConnectionContext {\n if (!options) options = {};\n\n config.webSocket = options.webSocketOptions && options.webSocketOptions.webSocket;\n config.webSocketEndpointPath = \"$servicebus/websocket\";\n config.webSocketConstructorOptions =\n options.webSocketOptions && options.webSocketOptions.webSocketConstructorOptions;\n\n const parameters: CreateConnectionContextBaseParameters = {\n config: config,\n // re-enabling this will be a post-GA discussion.\n // dataTransformer: options.dataTransformer,\n isEntityPathRequired: true,\n connectionProperties: {\n product: \"MSJSClient\",\n userAgent: getUserAgent(options),\n version: packageJsonInfo.version,\n },\n };\n // Let us create the base context and then add EventHub specific ConnectionContext properties.\n const connectionContext = ConnectionContextBase.create(parameters) as ConnectionContext;\n connectionContext.tokenCredential = tokenCredential;\n connectionContext.wasConnectionCloseCalled = false;\n connectionContext.senders = {};\n connectionContext.receivers = {};\n const mOptions: ManagementClientOptions = {\n address: options.managementSessionAddress,\n audience: options.managementSessionAudience,\n };\n connectionContext.managementSession = new ManagementClient(connectionContext, mOptions);\n\n let waitForConnectionRefreshResolve: () => void;\n let waitForConnectionRefreshPromise: Promise<void> | undefined;\n\n Object.assign<ConnectionContext, ConnectionContextMethods>(connectionContext, {\n isConnectionClosing() {\n // When the connection is not open, but the remote end is open,\n // then the rhea connection is in the process of terminating.\n return Boolean(!this.connection.isOpen() && this.connection.isRemoteOpen());\n },\n async readyToOpenLink(optionsArg?: { abortSignal?: AbortSignalLike }) {\n // Check that the connection isn't in the process of closing.\n // This can happen when the idle timeout has been reached but\n // the underlying socket is waiting to be destroyed.\n if (this.isConnectionClosing()) {\n // Wait for the disconnected event that indicates the underlying socket has closed.\n await this.waitForDisconnectedEvent(optionsArg);\n }\n\n // Wait for the connection to be reset.\n await this.waitForConnectionReset();\n },\n waitForDisconnectedEvent(optionsArg?: { abortSignal?: AbortSignalLike }) {\n return createAbortablePromise((resolve) => {\n logger.verbose(\n `[${this.connectionId}] Attempting to reinitialize connection` +\n ` but the connection is in the process of closing.` +\n ` Waiting for the disconnect event before continuing.`,\n );\n this.connection.once(ConnectionEvents.disconnected, resolve);\n }, optionsArg);\n },\n waitForConnectionReset() {\n // Check if the connection is currently in the process of disconnecting.\n if (waitForConnectionRefreshPromise) {\n return waitForConnectionRefreshPromise;\n }\n return Promise.resolve();\n },\n async close() {\n try {\n if (this.connection.isOpen()) {\n // Close all the senders.\n await Promise.all(\n Object.keys(connectionContext.senders).map((name) =>\n connectionContext.senders[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n // Close all the receivers.\n await Promise.all(\n Object.keys(connectionContext.receivers).map((name) =>\n connectionContext.receivers[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n // Close the cbs session;\n await this.cbsSession.close();\n // Close the management session\n await this.managementSession?.close();\n await this.connection.close();\n this.wasConnectionCloseCalled = true;\n logger.info(\"Closed the amqp connection '%s' on the client.\", this.connectionId);\n }\n } catch (err: any) {\n const errorDescription =\n err instanceof Error ? `${err.name}: ${err.message}` : JSON.stringify(err);\n logger.warning(\n `An error occurred while closing the connection \"${this.connectionId}\":\\n${errorDescription}`,\n );\n logErrorStackTrace(err);\n throw err;\n }\n },\n });\n\n // Define listeners to be added to the connection object for\n // \"connection_open\" and \"connection_error\" events.\n const onConnectionOpen: OnAmqpEvent = () => {\n connectionContext.wasConnectionCloseCalled = false;\n logger.verbose(\n \"[%s] setting 'wasConnectionCloseCalled' property of connection context to %s.\",\n connectionContext.connection.id,\n connectionContext.wasConnectionCloseCalled,\n );\n };\n\n const onDisconnected: OnAmqpEvent = async (context: EventContext) => {\n if (waitForConnectionRefreshPromise) {\n return;\n }\n waitForConnectionRefreshPromise = new Promise((resolve) => {\n waitForConnectionRefreshResolve = resolve;\n });\n try {\n logger.verbose(\n \"[%s] 'disconnected' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n const state: Readonly<{\n wasConnectionCloseCalled: boolean;\n numSenders: number;\n numReceivers: number;\n }> = {\n wasConnectionCloseCalled: connectionContext.wasConnectionCloseCalled,\n numSenders: Object.keys(connectionContext.senders).length,\n numReceivers: Object.keys(connectionContext.receivers).length,\n };\n logger.verbose(\n \"[%s] Closing all open senders and receivers in the state: %O\",\n connectionContext.connection.id,\n state,\n );\n\n // Clear internal map maintained by rhea to avoid reconnecting of old links once the\n // connection is back up.\n connectionContext.connection.removeAllSessions();\n\n // Close the cbs session to ensure all the event handlers are released.\n await connectionContext.cbsSession?.close().catch(() => {\n /* error already logged, swallow it here */\n });\n // Close the management session to ensure all the event handlers are released.\n await connectionContext.managementSession?.close().catch(() => {\n /* error already logged, swallow it here */\n });\n\n // Close all senders and receivers to ensure clean up of timers & other resources.\n if (state.numSenders || state.numReceivers) {\n await Promise.all(\n Object.keys(connectionContext.senders).map((name) =>\n connectionContext.senders[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n\n await Promise.all(\n Object.keys(connectionContext.receivers).map((name) =>\n connectionContext.receivers[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n }\n } catch (err: any) {\n logger.verbose(\n `[${connectionContext.connectionId}] An error occurred while closing the connection in 'disconnected'. %O`,\n err,\n );\n }\n\n try {\n await refreshConnection(connectionContext);\n } catch (err: any) {\n logger.verbose(\n `[${connectionContext.connectionId}] An error occurred while refreshing the connection in 'disconnected'. %O`,\n err,\n );\n } finally {\n waitForConnectionRefreshResolve();\n waitForConnectionRefreshPromise = undefined;\n }\n };\n\n const protocolError: OnAmqpEvent = async (context: EventContext) => {\n logger.verbose(\n \"[%s] 'protocol_error' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n };\n\n const error: OnAmqpEvent = async (context: EventContext) => {\n logger.verbose(\n \"[%s] 'error' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n };\n\n function addConnectionListeners(connection: Connection): void {\n // Add listeners on the connection object.\n connection.on(ConnectionEvents.connectionOpen, onConnectionOpen);\n connection.on(ConnectionEvents.disconnected, onDisconnected);\n connection.on(ConnectionEvents.protocolError, protocolError);\n connection.on(ConnectionEvents.error, error);\n }\n\n function cleanConnectionContext(context: ConnectionContext): Promise<void> {\n // Remove listeners from the connection object.\n context.connection.removeListener(ConnectionEvents.connectionOpen, onConnectionOpen);\n context.connection.removeListener(ConnectionEvents.disconnected, onDisconnected);\n context.connection.removeListener(ConnectionEvents.protocolError, protocolError);\n context.connection.removeListener(ConnectionEvents.error, error);\n // Close the connection\n return context.connection.close();\n }\n\n async function refreshConnection(context: ConnectionContext): Promise<void> {\n const originalConnectionId = context.connectionId;\n try {\n await cleanConnectionContext(context);\n } catch (err: any) {\n logger.verbose(\n `[${context.connectionId}] There was an error closing the connection before reconnecting: %O`,\n err,\n );\n }\n\n // Create a new connection, id, locks, and cbs client.\n context.refreshConnection();\n addConnectionListeners(context.connection);\n logger.verbose(\n `The connection \"${originalConnectionId}\" has been updated to \"${context.connectionId}\".`,\n );\n }\n\n addConnectionListeners(connectionContext.connection);\n\n logger.verbose(\"[%s] Created connection context successfully.\", connectionContext.connectionId);\n return connectionContext;\n }\n}\n\n/**\n * Helper method to create a ConnectionContext from the input passed to either\n * EventHubProducerClient or EventHubConsumerClient constructors\n *\n * @internal\n */\nexport function createConnectionContext(\n hostOrConnectionString: string,\n eventHubNameOrOptions?: string | EventHubClientOptions,\n credentialOrOptions?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubClientOptions,\n options?: EventHubClientOptions,\n): ConnectionContext {\n let connectionString;\n let config;\n let credential: TokenCredential | SasTokenProvider;\n hostOrConnectionString = String(hostOrConnectionString);\n\n if (!isCredential(credentialOrOptions)) {\n const parsedCS = parseEventHubConnectionString(hostOrConnectionString);\n if (\n !(\n parsedCS.eventHubName ||\n (typeof eventHubNameOrOptions === \"string\" && eventHubNameOrOptions)\n )\n ) {\n throw new TypeError(\n `Either provide \"eventHubName\" or the \"connectionString\": \"${hostOrConnectionString}\", ` +\n `must contain \"EntityPath=<your-event-hub-name>\".`,\n );\n }\n if (\n parsedCS.eventHubName &&\n typeof eventHubNameOrOptions === \"string\" &&\n eventHubNameOrOptions &&\n parsedCS.eventHubName !== eventHubNameOrOptions\n ) {\n throw new TypeError(\n `The entity path \"${parsedCS.eventHubName}\" in connectionString: \"${hostOrConnectionString}\" ` +\n `doesn't match with eventHubName: \"${eventHubNameOrOptions}\".`,\n );\n }\n connectionString = hostOrConnectionString;\n if (typeof eventHubNameOrOptions !== \"string\") {\n // connectionstring and/or options were passed to constructor\n config = EventHubConnectionConfig.create(connectionString);\n options = eventHubNameOrOptions;\n } else {\n // connectionstring, eventHubName and/or options were passed to constructor\n const eventHubName = eventHubNameOrOptions;\n config = EventHubConnectionConfig.create(connectionString, eventHubName);\n options = credentialOrOptions;\n }\n\n const parsed = parseEventHubConnectionString(connectionString) as Required<\n | Pick<EventHubConnectionStringProperties, \"sharedAccessKey\" | \"sharedAccessKeyName\">\n | Pick<EventHubConnectionStringProperties, \"sharedAccessSignature\">\n >;\n // Since connectionString was passed, create a TokenProvider.\n credential = createSasTokenProvider(parsed);\n } else {\n // host, eventHubName, a TokenCredential and/or options were passed to constructor\n const eventHubName = eventHubNameOrOptions;\n let host = hostOrConnectionString;\n if (isNamedKeyCredential(credentialOrOptions) || isSASCredential(credentialOrOptions)) {\n credential = createSasTokenProvider(credentialOrOptions);\n } else {\n credential = credentialOrOptions;\n }\n if (!eventHubName) {\n throw new TypeError(`\"eventHubName\" is missing`);\n }\n\n if (!host.endsWith(\"/\")) host += \"/\";\n connectionString = `Endpoint=sb://${host};SharedAccessKeyName=defaultKeyName;SharedAccessKey=defaultKeyValue;EntityPath=${eventHubName}`;\n config = EventHubConnectionConfig.create(connectionString);\n }\n\n if (options?.customEndpointAddress) {\n EventHubConnectionConfig.setCustomEndpointAddress(config, options.customEndpointAddress);\n }\n\n ConnectionConfig.validate(config);\n\n return ConnectionContext.create(config, credential, options);\n}\n"]}
@@ -15,12 +15,11 @@ export const TRACEPARENT_PROPERTY = "Diagnostic-Id";
15
15
  * @param operation - The type of the operation being performed.
16
16
  */
17
17
  export function instrumentEventData(eventData, options, entityPath, host, operation) {
18
- var _a, _b;
19
18
  const props = isAmqpAnnotatedMessage(eventData)
20
19
  ? eventData.applicationProperties
21
20
  : eventData.properties;
22
21
  // check if the event has already been instrumented
23
- const previouslyInstrumented = Boolean(props === null || props === void 0 ? void 0 : props[TRACEPARENT_PROPERTY]);
22
+ const previouslyInstrumented = Boolean(props?.[TRACEPARENT_PROPERTY]);
24
23
  if (previouslyInstrumented) {
25
24
  return { event: eventData, spanContext: undefined };
26
25
  }
@@ -32,21 +31,21 @@ export function instrumentEventData(eventData, options, entityPath, host, operat
32
31
  spanContext: undefined,
33
32
  };
34
33
  }
35
- const traceParent = tracingClient.createRequestHeaders((_a = updatedOptions.tracingOptions) === null || _a === void 0 ? void 0 : _a.tracingContext)["traceparent"];
34
+ const traceParent = tracingClient.createRequestHeaders(updatedOptions.tracingOptions?.tracingContext)["traceparent"];
36
35
  if (traceParent) {
37
- const copiedProps = Object.assign({}, props);
36
+ const copiedProps = { ...props };
38
37
  // create a copy so the original isn't modified
39
38
  if (isAmqpAnnotatedMessage(eventData)) {
40
- eventData = Object.assign(Object.assign({}, eventData), { applicationProperties: copiedProps });
39
+ eventData = { ...eventData, applicationProperties: copiedProps };
41
40
  }
42
41
  else {
43
- eventData = Object.assign(Object.assign({}, eventData), { properties: copiedProps });
42
+ eventData = { ...eventData, properties: copiedProps };
44
43
  }
45
44
  copiedProps[TRACEPARENT_PROPERTY] = traceParent;
46
45
  }
47
46
  return {
48
47
  event: eventData,
49
- spanContext: (_b = updatedOptions.tracingOptions) === null || _b === void 0 ? void 0 : _b.tracingContext,
48
+ spanContext: updatedOptions.tracingOptions?.tracingContext,
50
49
  };
51
50
  }
52
51
  finally {
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentEventData.js","sourceRoot":"","sources":["../../../src/diagnostics/instrumentEventData.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAKzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG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,EAAE,WAAW,GAAE,CAAC;YACxD,CAAC;YACD,WAAW,CAAC,oBAAoB,CAAC,GAAG,WAAW,CAAC;QAClD,CAAC;QAED,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,MAAA,cAAc,CAAC,cAAc,0CAAE,cAAc;SAC3D,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,SAAoB;IAClE,IAAI,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC;QACzE,OAAO;IACT,CAAC;IAED,MAAM,YAAY,GAAG,SAAS,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAChE,OAAO,aAAa,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { EventData } from \"../eventData.js\";\nimport { isAmqpAnnotatedMessage } from \"../eventData.js\";\nimport type { TracingContext } from \"@azure/core-tracing\";\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport type { OperationOptions } from \"../util/operationOptions.js\";\nimport type { MessagingOperationNames } from \"./tracing.js\";\nimport { toSpanOptions, tracingClient } from \"./tracing.js\";\n\n/**\n * @internal\n */\nexport const TRACEPARENT_PROPERTY = \"Diagnostic-Id\";\n\n/**\n * Populates the `EventData` with `SpanContext` info to support trace propagation.\n * Creates and returns a copy of the passed in `EventData` unless the `EventData`\n * has already been instrumented.\n * @param eventData - The `EventData` or `AmqpAnnotatedMessage` to instrument.\n * @param span - The `Span` containing the context to propagate tracing information.\n * @param operation - The type of the operation being performed.\n */\nexport function instrumentEventData(\n eventData: EventData | AmqpAnnotatedMessage,\n options: OperationOptions,\n entityPath: string,\n host: string,\n operation?: MessagingOperationNames,\n): { event: EventData; spanContext: TracingContext | undefined } {\n const props = isAmqpAnnotatedMessage(eventData)\n ? eventData.applicationProperties\n : eventData.properties;\n\n // check if the event has already been instrumented\n const previouslyInstrumented = Boolean(props?.[TRACEPARENT_PROPERTY]);\n\n if (previouslyInstrumented) {\n return { event: eventData, spanContext: undefined };\n }\n\n const { span: messageSpan, updatedOptions } = tracingClient.startSpan(\n \"message\",\n options,\n toSpanOptions({ entityPath, host }, operation, \"producer\"),\n );\n try {\n if (!messageSpan.isRecording()) {\n return {\n event: eventData,\n spanContext: undefined,\n };\n }\n\n const traceParent = tracingClient.createRequestHeaders(\n updatedOptions.tracingOptions?.tracingContext,\n )[\"traceparent\"];\n if (traceParent) {\n const copiedProps = { ...props };\n\n // create a copy so the original isn't modified\n if (isAmqpAnnotatedMessage(eventData)) {\n eventData = { ...eventData, applicationProperties: copiedProps };\n } else {\n eventData = { ...eventData, properties: copiedProps };\n }\n copiedProps[TRACEPARENT_PROPERTY] = traceParent;\n }\n\n return {\n event: eventData,\n spanContext: updatedOptions.tracingOptions?.tracingContext,\n };\n } finally {\n messageSpan.end();\n }\n}\n\n/**\n * Extracts the `SpanContext` from an `EventData` if the context exists.\n * @param eventData - An individual `EventData` object.\n * @internal\n */\nexport function extractSpanContextFromEventData(eventData: EventData): TracingContext | undefined {\n if (!eventData.properties || !eventData.properties[TRACEPARENT_PROPERTY]) {\n return;\n }\n\n const diagnosticId = eventData.properties[TRACEPARENT_PROPERTY];\n return tracingClient.parseTraceparentHeader(diagnosticId);\n}\n"]}
1
+ {"version":3,"file":"instrumentEventData.js","sourceRoot":"","sources":["../../../src/diagnostics/instrumentEventData.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAKzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAA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AE,WAAW,EAAE,CAAC;YACxD,CAAC;YACD,WAAW,CAAC,oBAAoB,CAAC,GAAG,WAAW,CAAC;QAClD,CAAC;QAED,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,cAAc,CAAC,cAAc,EAAE,cAAc;SAC3D,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,SAAoB;IAClE,IAAI,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC;QACzE,OAAO;IACT,CAAC;IAED,MAAM,YAAY,GAAG,SAAS,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAChE,OAAO,aAAa,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { EventData } from \"../eventData.js\";\nimport { isAmqpAnnotatedMessage } from \"../eventData.js\";\nimport type { TracingContext } from \"@azure/core-tracing\";\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport type { OperationOptions } from \"../util/operationOptions.js\";\nimport type { MessagingOperationNames } from \"./tracing.js\";\nimport { toSpanOptions, tracingClient } from \"./tracing.js\";\n\n/**\n * @internal\n */\nexport const TRACEPARENT_PROPERTY = \"Diagnostic-Id\";\n\n/**\n * Populates the `EventData` with `SpanContext` info to support trace propagation.\n * Creates and returns a copy of the passed in `EventData` unless the `EventData`\n * has already been instrumented.\n * @param eventData - The `EventData` or `AmqpAnnotatedMessage` to instrument.\n * @param span - The `Span` containing the context to propagate tracing information.\n * @param operation - The type of the operation being performed.\n */\nexport function instrumentEventData(\n eventData: EventData | AmqpAnnotatedMessage,\n options: OperationOptions,\n entityPath: string,\n host: string,\n operation?: MessagingOperationNames,\n): { event: EventData; spanContext: TracingContext | undefined } {\n const props = isAmqpAnnotatedMessage(eventData)\n ? eventData.applicationProperties\n : eventData.properties;\n\n // check if the event has already been instrumented\n const previouslyInstrumented = Boolean(props?.[TRACEPARENT_PROPERTY]);\n\n if (previouslyInstrumented) {\n return { event: eventData, spanContext: undefined };\n }\n\n const { span: messageSpan, updatedOptions } = tracingClient.startSpan(\n \"message\",\n options,\n toSpanOptions({ entityPath, host }, operation, \"producer\"),\n );\n try {\n if (!messageSpan.isRecording()) {\n return {\n event: eventData,\n spanContext: undefined,\n };\n }\n\n const traceParent = tracingClient.createRequestHeaders(\n updatedOptions.tracingOptions?.tracingContext,\n )[\"traceparent\"];\n if (traceParent) {\n const copiedProps = { ...props };\n\n // create a copy so the original isn't modified\n if (isAmqpAnnotatedMessage(eventData)) {\n eventData = { ...eventData, applicationProperties: copiedProps };\n } else {\n eventData = { ...eventData, properties: copiedProps };\n }\n copiedProps[TRACEPARENT_PROPERTY] = traceParent;\n }\n\n return {\n event: eventData,\n spanContext: updatedOptions.tracingOptions?.tracingContext,\n };\n } finally {\n messageSpan.end();\n }\n}\n\n/**\n * Extracts the `SpanContext` from an `EventData` if the context exists.\n * @param eventData - An individual `EventData` object.\n * @internal\n */\nexport function extractSpanContextFromEventData(eventData: EventData): TracingContext | undefined {\n if (!eventData.properties || !eventData.properties[TRACEPARENT_PROPERTY]) {\n return;\n }\n\n const diagnosticId = eventData.properties[TRACEPARENT_PROPERTY];\n return tracingClient.parseTraceparentHeader(diagnosticId);\n}\n"]}
@@ -97,10 +97,12 @@ export function fromRheaMessage(msg, skipParsingBodyAsJson) {
97
97
  * @internal
98
98
  */
99
99
  export function toRheaMessage(data, partitionKey) {
100
- var _a, _b;
101
100
  let rheaMessage;
102
101
  if (isAmqpAnnotatedMessage(data)) {
103
- rheaMessage = Object.assign(Object.assign({}, AmqpAnnotatedMessage.toRheaMessage(data)), { body: defaultDataTransformer.encode(data.body, (_a = data.bodyType) !== null && _a !== void 0 ? _a : "data") });
102
+ rheaMessage = {
103
+ ...AmqpAnnotatedMessage.toRheaMessage(data),
104
+ body: defaultDataTransformer.encode(data.body, data.bodyType ?? "data"),
105
+ };
104
106
  }
105
107
  else {
106
108
  let bodyType = "data";
@@ -109,7 +111,7 @@ export function toRheaMessage(data, partitionKey) {
109
111
  If the event is being round-tripped, then we respect the `bodyType` of the
110
112
  underlying AMQP message.
111
113
  */
112
- bodyType = (_b = data.getRawAmqpMessage().bodyType) !== null && _b !== void 0 ? _b : "data";
114
+ bodyType = data.getRawAmqpMessage().bodyType ?? "data";
113
115
  }
114
116
  rheaMessage = {
115
117
  body: defaultDataTransformer.encode(data.body, bodyType),
@@ -210,7 +212,7 @@ function convertDatesToNumbers(thing) {
210
212
  { foo: new Date(), children: { nested: new Date() }}
211
213
  */
212
214
  if (typeof thing === "object" && isDefined(thing)) {
213
- const thingShallowCopy = Object.assign({}, thing);
215
+ const thingShallowCopy = { ...thing };
214
216
  for (const key of Object.keys(thingShallowCopy)) {
215
217
  thingShallowCopy[key] = convertDatesToNumbers(thingShallowCopy[key]);
216
218
  }
@@ -1 +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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AC,mCAAmC,CAAC,KAAK,CAAC,GAAG,KAAK,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"]}
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,EAAE,eAAe;IAC/B,YAAY,EAAE,aAAa;IAC3B,gBAAgB,EAAE,iBAAiB;IACnC,oBAAoB,EAAE,oBAAoB;IAC1C,aAAa,EAAE,cAAc;IAC7B,QAAQ,E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AAU,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"]}
@@ -10,8 +10,11 @@
10
10
  export function createEventDataAdapter(params = {}) {
11
11
  return {
12
12
  produce: ({ data: body, contentType }) => {
13
- return Object.assign(Object.assign({}, params), { body,
14
- contentType });
13
+ return {
14
+ ...params,
15
+ body,
16
+ contentType,
17
+ };
15
18
  },
16
19
  consume: (message) => {
17
20
  const { body, contentType } = message;
@@ -1 +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,uCACK,MAAM,KACT,IAAI;gBACJ,WAAW,IACX;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"]}
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"]}
@@ -34,20 +34,70 @@ export function isEventDataBatch(eventDataBatch) {
34
34
  * @internal
35
35
  */
36
36
  export class EventDataBatchImpl {
37
+ /**
38
+ * Describes the amqp connection context for the Client.
39
+ */
40
+ _context;
41
+ /**
42
+ * The Id of the partition to which the batch is expected to be sent to.
43
+ * Specifying this will throw an error if the batch was created using a `partitionKey`.
44
+ */
45
+ _partitionId;
46
+ /**
47
+ * A value that is hashed to produce a partition assignment.
48
+ * It guarantees that messages with the same partitionKey end up in the same partition.
49
+ * Specifying this will throw an error if the batch was created using a `partitionId`.
50
+ */
51
+ _partitionKey;
52
+ /**
53
+ * The maximum size allowed for the batch.
54
+ */
55
+ _maxSizeInBytes;
56
+ /**
57
+ * Current size of the batch in bytes.
58
+ */
59
+ _sizeInBytes;
60
+ /**
61
+ * Encoded amqp messages.
62
+ */
63
+ _encodedMessages = [];
64
+ /**
65
+ * Number of events in the batch.
66
+ */
67
+ _count;
68
+ /**
69
+ * List of 'message' span contexts.
70
+ */
71
+ _spanContexts = [];
72
+ /**
73
+ * The message annotations to apply on the batch envelope.
74
+ * This will reflect the message annotations on the first event
75
+ * that was added to the batch.
76
+ * A common annotation is the partition key.
77
+ */
78
+ _batchAnnotations;
79
+ /**
80
+ * Indicates that the batch should be treated as idempotent.
81
+ */
82
+ _isIdempotent;
83
+ /**
84
+ * The sequence number assigned to the first event in the batch while
85
+ * the batch is being sent to the service.
86
+ */
87
+ _pendingStartingSequenceNumber;
88
+ /**
89
+ * The publishing sequence number assigned to the first event in the batch at the time
90
+ * the batch was successfully published.
91
+ * If the producer was not configured to apply sequence numbering or if the batch
92
+ * has not yet been successfully published, the value will be `undefined`.
93
+ */
94
+ _startingPublishSequenceNumber;
37
95
  /**
38
96
  * EventDataBatch should not be constructed using `new EventDataBatch()`
39
97
  * Use the `createBatch()` method on your `EventHubProducer` instead.
40
98
  * @internal
41
99
  */
42
100
  constructor(context, maxSizeInBytes, isIdempotent, partitionKey, partitionId) {
43
- /**
44
- * Encoded amqp messages.
45
- */
46
- this._encodedMessages = [];
47
- /**
48
- * List of 'message' span contexts.
49
- */
50
- this._spanContexts = [];
51
101
  this._context = context;
52
102
  this._maxSizeInBytes = maxSizeInBytes;
53
103
  this._isIdempotent = isIdempotent;
@@ -213,7 +263,9 @@ export class EventDataBatchImpl {
213
263
  const { event: instrumentedEvent, spanContext } = instrumentEventData(eventData, options, entityPath, host);
214
264
  // Convert EventData to RheaMessage.
215
265
  const amqpMessage = toRheaMessage(instrumentedEvent, this._partitionKey);
216
- const originalAnnotations = amqpMessage.message_annotations && Object.assign({}, amqpMessage.message_annotations);
266
+ const originalAnnotations = amqpMessage.message_annotations && {
267
+ ...amqpMessage.message_annotations,
268
+ };
217
269
  this._decorateRheaMessageWithPlaceholderIdempotencyProps(amqpMessage);
218
270
  const encodedMessage = message.encode(amqpMessage);
219
271
  let currentSize = this._sizeInBytes;