@azure/core-amqp 2.3.1-alpha.20210518.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ export { AmqpMessageHeader } from "./messageHeader";
11
11
  export { AmqpMessageProperties } from "./messageProperties";
12
12
  export { ConnectionContextBase } from "./ConnectionContextBase";
13
13
  export { MessagingError, isMessagingError, ErrorNameConditionMapper, ConditionErrorNameMapper, translate, retryableErrors, isSystemError, SystemErrorConditionMapper, StandardAbortMessage } from "./errors";
14
- export { delay, parseConnectionString, defaultCancellableLock, defaultLock, AsyncLock } from "./util/utils";
14
+ export { delay, parseConnectionString, defaultCancellableLock } from "./util/utils";
15
15
  export { AmqpAnnotatedMessage } from "./amqpAnnotatedMessage";
16
16
  export { logger } from "./log";
17
17
  export * from "./internals";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,8BAA8B;AAE9B,OAAO,EAAE,mBAAmB,EAAsB,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,KAAK,EAA6B,kBAAkB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAA2B,MAAM,qCAAqC,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAe,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EACL,qBAAqB,EAGtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,SAAS,EACT,eAAe,EACf,aAAa,EACb,0BAA0B,EAE1B,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,KAAK,EACL,qBAAqB,EACrB,sBAAsB,EACtB,WAAW,EAEX,SAAS,EAEV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,cAAc,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/// <reference lib=\"es2015\" />\n\nexport { RequestResponseLink, SendRequestOptions } from \"./requestResponseLink\";\nexport { retry, RetryOptions, RetryConfig, RetryOperationType, RetryMode } from \"./retry\";\nexport { TokenType } from \"./auth/token\";\n\nexport { ConnectionConfig, ConnectionConfigOptions } from \"./connectionConfig/connectionConfig\";\n\nexport { CbsClient, CbsResponse } from \"./cbs\";\nexport { Constants } from \"./util/constants\";\nexport { AmqpMessageHeader } from \"./messageHeader\";\nexport { AmqpMessageProperties } from \"./messageProperties\";\nexport {\n ConnectionContextBase,\n ConnectionProperties,\n CreateConnectionContextBaseParameters\n} from \"./ConnectionContextBase\";\nexport {\n MessagingError,\n isMessagingError,\n ErrorNameConditionMapper,\n ConditionErrorNameMapper,\n translate,\n retryableErrors,\n isSystemError,\n SystemErrorConditionMapper,\n NetworkSystemError,\n StandardAbortMessage\n} from \"./errors\";\nexport {\n delay,\n parseConnectionString,\n defaultCancellableLock,\n defaultLock,\n ParsedOutput,\n AsyncLock,\n WebSocketOptions\n} from \"./util/utils\";\nexport { AmqpAnnotatedMessage } from \"./amqpAnnotatedMessage\";\nexport { logger } from \"./log\";\nexport * from \"./internals\";\nexport { AcquireLockProperties, CancellableAsyncLock } from \"./util/lock\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,8BAA8B;AAE9B,OAAO,EAAE,mBAAmB,EAAsB,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,KAAK,EAA6B,kBAAkB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAA2B,MAAM,qCAAqC,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAe,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EACL,qBAAqB,EAGtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,SAAS,EACT,eAAe,EACf,aAAa,EACb,0BAA0B,EAE1B,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,KAAK,EACL,qBAAqB,EACrB,sBAAsB,EAGvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,cAAc,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/// <reference lib=\"es2015\" />\n\nexport { RequestResponseLink, SendRequestOptions } from \"./requestResponseLink\";\nexport { retry, RetryOptions, RetryConfig, RetryOperationType, RetryMode } from \"./retry\";\nexport { TokenType } from \"./auth/token\";\n\nexport { ConnectionConfig, ConnectionConfigOptions } from \"./connectionConfig/connectionConfig\";\n\nexport { CbsClient, CbsResponse } from \"./cbs\";\nexport { Constants } from \"./util/constants\";\nexport { AmqpMessageHeader } from \"./messageHeader\";\nexport { AmqpMessageProperties } from \"./messageProperties\";\nexport {\n ConnectionContextBase,\n ConnectionProperties,\n CreateConnectionContextBaseParameters\n} from \"./ConnectionContextBase\";\nexport {\n MessagingError,\n isMessagingError,\n ErrorNameConditionMapper,\n ConditionErrorNameMapper,\n translate,\n retryableErrors,\n isSystemError,\n SystemErrorConditionMapper,\n NetworkSystemError,\n StandardAbortMessage\n} from \"./errors\";\nexport {\n delay,\n parseConnectionString,\n defaultCancellableLock,\n ParsedOutput,\n WebSocketOptions\n} from \"./util/utils\";\nexport { AmqpAnnotatedMessage } from \"./amqpAnnotatedMessage\";\nexport { logger } from \"./log\";\nexport * from \"./internals\";\nexport { AcquireLockProperties, CancellableAsyncLock } from \"./util/lock\";\n"]}
@@ -15,7 +15,7 @@ export const AmqpMessageProperties = {
15
15
  toRheaMessageProperties(props) {
16
16
  const amqpProperties = {};
17
17
  if (props.absoluteExpiryTime != undefined) {
18
- amqpProperties.absolute_expiry_time = props.absoluteExpiryTime;
18
+ amqpProperties.absolute_expiry_time = new Date(props.absoluteExpiryTime);
19
19
  }
20
20
  if (props.contentEncoding != undefined) {
21
21
  amqpProperties.content_encoding = props.contentEncoding;
@@ -27,7 +27,7 @@ export const AmqpMessageProperties = {
27
27
  amqpProperties.correlation_id = props.correlationId;
28
28
  }
29
29
  if (props.creationTime != undefined) {
30
- amqpProperties.creation_time = props.creationTime;
30
+ amqpProperties.creation_time = new Date(props.creationTime);
31
31
  }
32
32
  if (props.groupId != undefined) {
33
33
  amqpProperties.group_id = props.groupId;
@@ -64,7 +64,7 @@ export const AmqpMessageProperties = {
64
64
  fromRheaMessageProperties(props) {
65
65
  const msgProperties = {};
66
66
  if (props.absolute_expiry_time != undefined) {
67
- msgProperties.absoluteExpiryTime = props.absolute_expiry_time;
67
+ msgProperties.absoluteExpiryTime = props.absolute_expiry_time.getTime();
68
68
  }
69
69
  if (props.content_encoding != undefined) {
70
70
  msgProperties.contentEncoding = props.content_encoding;
@@ -76,7 +76,7 @@ export const AmqpMessageProperties = {
76
76
  msgProperties.correlationId = props.correlation_id;
77
77
  }
78
78
  if (props.creation_time != undefined) {
79
- msgProperties.creationTime = props.creation_time;
79
+ msgProperties.creationTime = props.creation_time.getTime();
80
80
  }
81
81
  if (props.group_id != undefined) {
82
82
  msgProperties.groupId = props.group_id;
@@ -1 +1 @@
1
- {"version":3,"file":"messageProperties.js","sourceRoot":"","sources":["../../src/messageProperties.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,2BAA2B;AAG3B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AA+D/B;;GAEG;AACH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC;;;;OAIG;IACH,uBAAuB,CAAC,KAA4B;QAClD,MAAM,cAAc,GAA0B,EAAE,CAAC;QACjD,IAAI,KAAK,CAAC,kBAAkB,IAAI,SAAS,EAAE;YACzC,cAAc,CAAC,oBAAoB,GAAG,KAAK,CAAC,kBAAkB,CAAC;SAChE;QACD,IAAI,KAAK,CAAC,eAAe,IAAI,SAAS,EAAE;YACtC,cAAc,CAAC,gBAAgB,GAAG,KAAK,CAAC,eAAe,CAAC;SACzD;QACD,IAAI,KAAK,CAAC,WAAW,IAAI,SAAS,EAAE;YAClC,cAAc,CAAC,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC;SACjD;QACD,IAAI,KAAK,CAAC,aAAa,IAAI,SAAS,EAAE;YACpC,cAAc,CAAC,cAAc,GAAG,KAAK,CAAC,aAAa,CAAC;SACrD;QACD,IAAI,KAAK,CAAC,YAAY,IAAI,SAAS,EAAE;YACnC,cAAc,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;SACnD;QACD,IAAI,KAAK,CAAC,OAAO,IAAI,SAAS,EAAE;YAC9B,cAAc,CAAC,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC;SACzC;QACD,IAAI,KAAK,CAAC,aAAa,IAAI,SAAS,EAAE;YACpC,cAAc,CAAC,cAAc,GAAG,KAAK,CAAC,aAA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,KAAK,CAAC,aAAa,IAAI,SAAS,EAAE;YACpC,aAAa,CAAC,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC;SAClD;QACD,IAAI,KAAK,CAAC,QAAQ,IAAI,SAAS,EAAE;YAC/B,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC;SACxC;QACD,IAAI,KAAK,CAAC,cAAc,IAAI,SAAS,EAAE;YACrC,aAAa,CAAC,aAAa,GAAG,KAAK,CAAC,cAAc,CAAC;SACpD;QACD,IAAI,KAAK,CAAC,UAAU,IAAI,SAAS,EAAE;YACjC,aAAa,CAAC,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC;SAC5C;QACD,IAAI,KAAK,CAAC,QAAQ,IAAI,SAAS,EAAE;YAC/B,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC;SACxC;QACD,IAAI,KAAK,CAAC,iBAAiB,IAAI,SAAS,EAAE;YACxC,aAAa,CAAC,cAAc,GAAG,KAAK,CAAC,iBAAiB,CAAC;SACxD;QACD,IAAI,KAAK,CAAC,OAAO,IAAI,SAAS,EAAE;YAC9B,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;SACvC;QACD,IAAI,KAAK,CAAC,EAAE,IAAI,SAAS,EAAE;YACzB,aAAa,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;SAC7B;QACD,oCAAoC;QACpC,0CAA0C;QAC1C,IAAI;QAEJ,MAAM,CAAC,OAAO,CAAC,gCAAgC,EAAE,aAAa,CAAC,CAAC;QAChE,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable eqeqeq */\n\nimport { MessageProperties as RheaMessageProperties } from \"rhea-promise\";\nimport { logger } from \"./log\";\n\n/**\n * Describes the defined set of standard properties of the message.\n */\nexport interface AmqpMessageProperties {\n /**\n * The application message identifier that uniquely identifies a message.\n * The user is responsible for making sure that this is unique in the given context. Guids usually make a good fit.\n */\n messageId?: string | number | Buffer;\n /**\n * The address of the node to send replies to.\n */\n replyTo?: string;\n /**\n * The address of the node the message is destined for.\n */\n to?: string;\n /**\n * The id that can be used to mark or identify messages between clients.\n */\n correlationId?: string | number | Buffer;\n /**\n * MIME type for the message.\n */\n contentType?: string;\n /**\n * The content-encoding property is used as a modifier to the content-type.\n * When present, its value indicates what additional content encodings have been applied to the application-data.\n */\n contentEncoding?: string;\n /**\n * The time when this message is considered expired.\n */\n absoluteExpiryTime?: number;\n /**\n * The time this message was created.\n */\n creationTime?: number;\n /**\n * The group this message belongs to.\n */\n groupId?: string;\n /**\n * The sequence number of this message with its group.\n */\n groupSequence?: number;\n /**\n * The group the reply message belongs to.\n */\n replyToGroupId?: string;\n /**\n * A common field for summary information about the message\n * content and purpose.\n */\n subject?: string;\n // /**\n // * The identity of the user responsible for producing the message.\n // */\n // userId?: string;\n}\n\n/**\n * Describes the operations that can be performed on the amqp message properties.\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const AmqpMessageProperties = {\n /**\n * Converts MessageProperties to RheaMessageProperties.\n * @param props - Message properties.\n * @returns RheaMessageProperties.\n */\n toRheaMessageProperties(props: AmqpMessageProperties): RheaMessageProperties {\n const amqpProperties: RheaMessageProperties = {};\n if (props.absoluteExpiryTime != undefined) {\n amqpProperties.absolute_expiry_time = props.absoluteExpiryTime;\n }\n if (props.contentEncoding != undefined) {\n amqpProperties.content_encoding = props.contentEncoding;\n }\n if (props.contentType != undefined) {\n amqpProperties.content_type = props.contentType;\n }\n if (props.correlationId != undefined) {\n amqpProperties.correlation_id = props.correlationId;\n }\n if (props.creationTime != undefined) {\n amqpProperties.creation_time = props.creationTime;\n }\n if (props.groupId != undefined) {\n amqpProperties.group_id = props.groupId;\n }\n if (props.groupSequence != undefined) {\n amqpProperties.group_sequence = props.groupSequence;\n }\n if (props.messageId != undefined) {\n amqpProperties.message_id = props.messageId;\n }\n if (props.replyTo != undefined) {\n amqpProperties.reply_to = props.replyTo;\n }\n if (props.replyToGroupId != undefined) {\n amqpProperties.reply_to_group_id = props.replyToGroupId;\n }\n if (props.subject != undefined) {\n amqpProperties.subject = props.subject;\n }\n if (props.to != undefined) {\n amqpProperties.to = props.to;\n }\n // if (props.userId != undefined) {\n // amqpProperties.user_id = props.userId;\n // }\n\n logger.verbose(\"To RheaMessageProperties: %O\", amqpProperties);\n return amqpProperties;\n },\n\n /**\n * Converts RheaMessageProperties to MessageProperties.\n * @param props - Amqp message properties.\n * @returns MessageProperties.\n */\n fromRheaMessageProperties(props: RheaMessageProperties): AmqpMessageProperties {\n const msgProperties: AmqpMessageProperties = {};\n if (props.absolute_expiry_time != undefined) {\n msgProperties.absoluteExpiryTime = props.absolute_expiry_time;\n }\n if (props.content_encoding != undefined) {\n msgProperties.contentEncoding = props.content_encoding;\n }\n if (props.content_type != undefined) {\n msgProperties.contentType = props.content_type;\n }\n if (props.correlation_id != undefined) {\n msgProperties.correlationId = props.correlation_id;\n }\n if (props.creation_time != undefined) {\n msgProperties.creationTime = props.creation_time;\n }\n if (props.group_id != undefined) {\n msgProperties.groupId = props.group_id;\n }\n if (props.group_sequence != undefined) {\n msgProperties.groupSequence = props.group_sequence;\n }\n if (props.message_id != undefined) {\n msgProperties.messageId = props.message_id;\n }\n if (props.reply_to != undefined) {\n msgProperties.replyTo = props.reply_to;\n }\n if (props.reply_to_group_id != undefined) {\n msgProperties.replyToGroupId = props.reply_to_group_id;\n }\n if (props.subject != undefined) {\n msgProperties.subject = props.subject;\n }\n if (props.to != undefined) {\n msgProperties.to = props.to;\n }\n // if (props.user_id != undefined) {\n // msgProperties.userId = props.user_id;\n // }\n\n logger.verbose(\"From RheaMessageProperties: %O\", msgProperties);\n return msgProperties;\n }\n};\n"]}
1
+ {"version":3,"file":"messageProperties.js","sourceRoot":"","sources":["../../src/messageProperties.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;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AC,QAAQ,CAAC;SACxC;QACD,IAAI,KAAK,CAAC,cAAc,IAAI,SAAS,EAAE;YACrC,aAAa,CAAC,aAAa,GAAG,KAAK,CAAC,cAAc,CAAC;SACpD;QACD,IAAI,KAAK,CAAC,UAAU,IAAI,SAAS,EAAE;YACjC,aAAa,CAAC,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC;SAC5C;QACD,IAAI,KAAK,CAAC,QAAQ,IAAI,SAAS,EAAE;YAC/B,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC;SACxC;QACD,IAAI,KAAK,CAAC,iBAAiB,IAAI,SAAS,EAAE;YACxC,aAAa,CAAC,cAAc,GAAG,KAAK,CAAC,iBAAiB,CAAC;SACxD;QACD,IAAI,KAAK,CAAC,OAAO,IAAI,SAAS,EAAE;YAC9B,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;SACvC;QACD,IAAI,KAAK,CAAC,EAAE,IAAI,SAAS,EAAE;YACzB,aAAa,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;SAC7B;QACD,oCAAoC;QACpC,0CAA0C;QAC1C,IAAI;QAEJ,MAAM,CAAC,OAAO,CAAC,gCAAgC,EAAE,aAAa,CAAC,CAAC;QAChE,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable eqeqeq */\n\nimport { MessageProperties as RheaMessageProperties } from \"rhea-promise\";\nimport { logger } from \"./log\";\n\n/**\n * Describes the defined set of standard properties of the message.\n */\nexport interface AmqpMessageProperties {\n /**\n * The application message identifier that uniquely identifies a message.\n * The user is responsible for making sure that this is unique in the given context. Guids usually make a good fit.\n */\n messageId?: string | number | Buffer;\n /**\n * The address of the node to send replies to.\n */\n replyTo?: string;\n /**\n * The address of the node the message is destined for.\n */\n to?: string;\n /**\n * The id that can be used to mark or identify messages between clients.\n */\n correlationId?: string | number | Buffer;\n /**\n * MIME type for the message.\n */\n contentType?: string;\n /**\n * The content-encoding property is used as a modifier to the content-type.\n * When present, its value indicates what additional content encodings have been applied to the application-data.\n */\n contentEncoding?: string;\n /**\n * The time when this message is considered expired.\n */\n absoluteExpiryTime?: number;\n /**\n * The time this message was created.\n */\n creationTime?: number;\n /**\n * The group this message belongs to.\n */\n groupId?: string;\n /**\n * The sequence number of this message with its group.\n */\n groupSequence?: number;\n /**\n * The group the reply message belongs to.\n */\n replyToGroupId?: string;\n /**\n * A common field for summary information about the message\n * content and purpose.\n */\n subject?: string;\n // /**\n // * The identity of the user responsible for producing the message.\n // */\n // userId?: string;\n}\n\n/**\n * Describes the operations that can be performed on the amqp message properties.\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const AmqpMessageProperties = {\n /**\n * Converts MessageProperties to RheaMessageProperties.\n * @param props - Message properties.\n * @returns RheaMessageProperties.\n */\n toRheaMessageProperties(props: AmqpMessageProperties): RheaMessageProperties {\n const amqpProperties: RheaMessageProperties = {};\n if (props.absoluteExpiryTime != undefined) {\n amqpProperties.absolute_expiry_time = new Date(props.absoluteExpiryTime);\n }\n if (props.contentEncoding != undefined) {\n amqpProperties.content_encoding = props.contentEncoding;\n }\n if (props.contentType != undefined) {\n amqpProperties.content_type = props.contentType;\n }\n if (props.correlationId != undefined) {\n amqpProperties.correlation_id = props.correlationId;\n }\n if (props.creationTime != undefined) {\n amqpProperties.creation_time = new Date(props.creationTime);\n }\n if (props.groupId != undefined) {\n amqpProperties.group_id = props.groupId;\n }\n if (props.groupSequence != undefined) {\n amqpProperties.group_sequence = props.groupSequence;\n }\n if (props.messageId != undefined) {\n amqpProperties.message_id = props.messageId;\n }\n if (props.replyTo != undefined) {\n amqpProperties.reply_to = props.replyTo;\n }\n if (props.replyToGroupId != undefined) {\n amqpProperties.reply_to_group_id = props.replyToGroupId;\n }\n if (props.subject != undefined) {\n amqpProperties.subject = props.subject;\n }\n if (props.to != undefined) {\n amqpProperties.to = props.to;\n }\n // if (props.userId != undefined) {\n // amqpProperties.user_id = props.userId;\n // }\n\n logger.verbose(\"To RheaMessageProperties: %O\", amqpProperties);\n return amqpProperties;\n },\n\n /**\n * Converts RheaMessageProperties to MessageProperties.\n * @param props - Amqp message properties.\n * @returns MessageProperties.\n */\n fromRheaMessageProperties(props: RheaMessageProperties): AmqpMessageProperties {\n const msgProperties: AmqpMessageProperties = {};\n if (props.absolute_expiry_time != undefined) {\n msgProperties.absoluteExpiryTime = props.absolute_expiry_time.getTime();\n }\n if (props.content_encoding != undefined) {\n msgProperties.contentEncoding = props.content_encoding;\n }\n if (props.content_type != undefined) {\n msgProperties.contentType = props.content_type;\n }\n if (props.correlation_id != undefined) {\n msgProperties.correlationId = props.correlation_id;\n }\n if (props.creation_time != undefined) {\n msgProperties.creationTime = props.creation_time.getTime();\n }\n if (props.group_id != undefined) {\n msgProperties.groupId = props.group_id;\n }\n if (props.group_sequence != undefined) {\n msgProperties.groupSequence = props.group_sequence;\n }\n if (props.message_id != undefined) {\n msgProperties.messageId = props.message_id;\n }\n if (props.reply_to != undefined) {\n msgProperties.replyTo = props.reply_to;\n }\n if (props.reply_to_group_id != undefined) {\n msgProperties.replyToGroupId = props.reply_to_group_id;\n }\n if (props.subject != undefined) {\n msgProperties.subject = props.subject;\n }\n if (props.to != undefined) {\n msgProperties.to = props.to;\n }\n // if (props.user_id != undefined) {\n // msgProperties.userId = props.user_id;\n // }\n\n logger.verbose(\"From RheaMessageProperties: %O\", msgProperties);\n return msgProperties;\n }\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../src/util/lock.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC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QACnB,QAAQ,GAAG,MAAM,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO;QACP,QAAQ,EAAE,QAAS;QACnB,QAAQ,EAAE,QAAS;KACpB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,WAAwB;IAClD,yCAAyC;IACzC,IAAI,WAAW,CAAC,GAAG;QAAE,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,WAAW,CAAC,WAAW,IAAI,WAAW,CAAC,aAAa,EAAE;QACxD,WAAW,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;KACjF;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortError, AbortSignalLike } from \"@azure/abort-controller\";\nimport { OperationTimeoutError } from \"rhea-promise\";\nimport { StandardAbortMessage } from \"../errors\";\nimport { logger } from \"../log\";\n\n/**\n * Describes the properties that must be provided while acquiring a lock.\n */\nexport interface AcquireLockProperties {\n /**\n * An implementation of the `AbortSignalLike` interface to signal the request to cancel lock acquisition.\n * This does not cancel running the task passed to `acquire()` if the lock has been acquired,\n * but will prevent it from running if cancelled before the task is invoked.\n */\n abortSignal: AbortSignalLike | undefined;\n /**\n * The allowed amount of time in milliseconds to acquire a lock.\n * If a lock isn't acquired within this time, the promise returned\n * by `acquire()` will be rejected with an Error.\n */\n timeoutInMs: number | undefined;\n}\n\n/**\n * Describes the components related to a specific task.\n * @internal\n */\ninterface TaskDetails {\n abortListener?: () => void;\n abortSignal?: AbortSignalLike;\n resolve: (value: unknown) => void;\n reject: (reason: Error) => void;\n task: (...args: any[]) => Promise<unknown>;\n tid?: ReturnType<typeof setTimeout>;\n}\n\n/**\n * CancellableAsyncLock provides a mechanism for forcing tasks using the same\n * 'key' to be executed serially.\n *\n * Pending tasks can be manually cancelled via an abortSignal or automatically\n * cancelled by reach a provided timeout value.\n */\nexport interface CancellableAsyncLock {\n /**\n * Returns a promise that resolves to the value returned by the provided task function.\n * Only 1 task can be invoked at a time for a given `key` value.\n *\n * An acquire call can be cancelled via an `abortSignal`.\n * If cancelled, the promise will be rejected with an `AbortError`.\n *\n * `acquireTimeoutInMs` can also be provided to properties.\n * If the timeout is reached before the provided `task` is invoked,\n * then the promise will be rejected with an Error stating the task\n * timed out waiting to acquire a lock.\n *\n * @param key - All `acquire` calls are grouped by the provided `key`.\n * @param task - The function to invoke once the lock has been acquired.\n * @param properties - Additional properties to control the behavior of `acquire`.\n */\n acquire<T = void>(\n key: string,\n task: (...args: any[]) => Promise<T>,\n properties: AcquireLockProperties\n ): Promise<T>;\n}\n\n/**\n * This class is used to coordinate executing tasks that should not be run in parallel.\n * @internal\n */\nexport class CancellableAsyncLockImpl {\n private _keyMap = new Map<string, TaskDetails[]>();\n private _executionRunningSet = new Set<string>();\n /**\n * Returns a promise that resolves to the value returned by the provided task function.\n * Only 1 task can be invoked at a time for a given `key` value.\n *\n * An acquire call can be cancelled via an `abortSignal`.\n * If cancelled, the promise will be rejected with an `AbortError`.\n *\n * `acquireTimeoutInMs` can also be provided to properties.\n * If the timeout is reached before the provided `task` is invoked,\n * then the promise will be rejected with an Error stating the task\n * timed out waiting to acquire a lock.\n *\n * @param key - All `acquire` calls are grouped by the provided `key`.\n * @param task - The function to invoke once the lock has been acquired.\n * @param properties - Additional properties to control the behavior of `acquire`.\n */\n acquire<T = void>(\n key: string,\n task: (...args: any[]) => Promise<T>,\n properties: AcquireLockProperties\n ): Promise<T> {\n const { abortSignal, timeoutInMs } = properties;\n // Fast exit if the operation is already cancelled.\n if (abortSignal?.aborted) {\n return Promise.reject(new AbortError(StandardAbortMessage));\n }\n\n // Ensure we've got a task queue for the given key.\n const taskQueue = this._keyMap.get(key) ?? [];\n this._keyMap.set(key, taskQueue);\n\n // This method will return a promise that will be fulfilled outside this function.\n const { promise, rejecter, resolver } = getPromiseParts();\n\n const taskDetails: TaskDetails = {\n reject: rejecter,\n resolve: resolver,\n task\n };\n\n // Handle timeouts by removing the task from the queue when hit.\n if (typeof timeoutInMs === \"number\") {\n const tid = setTimeout(() => {\n this._removeTaskDetails(key, taskDetails);\n rejecter(\n new OperationTimeoutError(`The task timed out waiting to acquire a lock for ${key}`)\n );\n }, timeoutInMs);\n taskDetails.tid = tid;\n }\n\n // Handle cancellation by removing the task from the queue when cancelled.\n if (abortSignal) {\n const abortListener = (): void => {\n this._removeTaskDetails(key, taskDetails);\n rejecter(new AbortError(StandardAbortMessage));\n };\n abortSignal.addEventListener(\"abort\", abortListener);\n taskDetails.abortSignal = abortSignal;\n taskDetails.abortListener = abortListener;\n }\n\n // Enqueue the task!\n taskQueue.push(taskDetails);\n logger.verbose(\n `Called acquire() for lock \"${key}\". Lock \"${key}\" has ${taskQueue.length} pending tasks.`\n );\n\n // Start a loop to iterate over the task queue.\n // This will run asynchronously and won't allow\n // more than 1 concurrent execution per key at a time.\n this._execute(key);\n\n return promise as Promise<T>;\n }\n\n /**\n * Iterates over all the pending tasks for a given `key` serially.\n *\n * Note: If the pending tasks are already being iterated by an early\n * _execute invocation, this returns immediately.\n * @returns\n */\n private async _execute(key: string): Promise<void> {\n // If the key already exists in the set, then exit because\n // tasks are already being processed.\n if (this._executionRunningSet.has(key)) {\n return;\n }\n\n const taskQueue = this._keyMap.get(key);\n // If the queue is empty, exit early!\n if (!taskQueue || !taskQueue.length) {\n return;\n }\n\n // Add the key to the set so we can tell the\n // task queue is already being processed.\n this._executionRunningSet.add(key);\n while (taskQueue.length) {\n // Remove tasks from the front of the queue.\n // Order matters!\n const taskDetails = taskQueue.shift();\n if (!taskDetails) {\n continue;\n }\n\n try {\n logger.verbose(`Acquired lock for \"${key}\", invoking task.`);\n cleanupTaskDetails(taskDetails);\n const value = await taskDetails.task();\n taskDetails.resolve(value);\n } catch (err) {\n taskDetails.reject(err);\n }\n logger.verbose(\n `Task completed for lock \"${key}\". Lock \"${key}\" has ${taskQueue.length} pending tasks.`\n );\n }\n\n // Indicate that the task queue for the key is empty\n // and we're done processing it.\n this._executionRunningSet.delete(key);\n }\n\n private _removeTaskDetails(key: string, taskDetails: TaskDetails): void {\n const taskQueue = this._keyMap.get(key);\n if (!taskQueue || !taskQueue.length) {\n // The task is already gone from the queue, so our work here is done!\n return;\n }\n\n const index = taskQueue.indexOf(taskDetails);\n if (index !== -1) {\n const [details] = taskQueue.splice(index, 1);\n // Cleanup the task rejection code paths.\n cleanupTaskDetails(details);\n }\n }\n}\n\n/**\n * @internal\n * Returns a promise and the promise's resolve and reject methods.\n */\nfunction getPromiseParts(): {\n promise: Promise<unknown>;\n resolver: (value: unknown) => void;\n rejecter: (reason: Error) => void;\n} {\n let resolver: (value: unknown) => void;\n let rejecter: (reason: Error) => void;\n\n const promise = new Promise<unknown>((resolve, reject) => {\n resolver = resolve;\n rejecter = reject;\n });\n\n return {\n promise,\n resolver: resolver!,\n rejecter: rejecter!\n };\n}\n\n/**\n * @internal\n * Removes any abort listener or pending timeout from a task.\n */\nfunction cleanupTaskDetails(taskDetails: TaskDetails): void {\n // Cleanup the task rejection code paths.\n if (taskDetails.tid) clearTimeout(taskDetails.tid);\n if (taskDetails.abortSignal && taskDetails.abortListener) {\n taskDetails.abortSignal.removeEventListener(\"abort\", taskDetails.abortListener);\n }\n}\n"]}
1
+ {"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../src/util/lock.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAkEhC;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IAArC;QACU,YAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC3C,yBAAoB,GAAG,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GAGG;AACH,SAAS,kBAAkB,CAAC,WAAwB;IAClD,yCAAyC;IACzC,IAAI,WAAW,CAAC,GAAG;QAAE,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,WAAW,CAAC,WAAW,IAAI,WAAW,CAAC,aAAa,EAAE;QACxD,WAAW,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;KACjF;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortError, AbortSignalLike } from \"@azure/abort-controller\";\nimport { OperationTimeoutError } from \"rhea-promise\";\nimport { StandardAbortMessage } from \"../errors\";\nimport { logger } from \"../log\";\n\n/**\n * Describes the properties that must be provided while acquiring a lock.\n */\nexport interface AcquireLockProperties {\n /**\n * An implementation of the `AbortSignalLike` interface to signal the request to cancel lock acquisition.\n * This only applies to the acquisition of a lock. Once the lock is acquired, the task is invoked and `acquire`\n * can no longer be cancelled.\n * This does not cancel running the task passed to `acquire()` if the lock has been acquired,\n * but will prevent it from running if cancelled before the task is invoked.\n */\n abortSignal: AbortSignalLike | undefined;\n /**\n * The allowed amount of time in milliseconds to acquire a lock.\n * If a lock isn't acquired within this time, the promise returned\n * by `acquire()` will be rejected with an Error.\n */\n timeoutInMs: number | undefined;\n}\n\n/**\n * Describes the components related to a specific task.\n * @internal\n */\ninterface TaskDetails {\n abortListener?: () => void;\n abortSignal?: AbortSignalLike;\n resolve: (value: unknown) => void;\n reject: (reason: Error) => void;\n task: (...args: any[]) => Promise<unknown>;\n tid?: ReturnType<typeof setTimeout>;\n}\n\n/**\n * CancellableAsyncLock provides a mechanism for forcing tasks using the same\n * 'key' to be executed serially.\n *\n * Pending tasks can be manually cancelled via an abortSignal or automatically\n * cancelled by reach a provided timeout value.\n */\nexport interface CancellableAsyncLock {\n /**\n * Returns a promise that resolves to the value returned by the provided task function.\n * Only 1 task can be invoked at a time for a given `key` value.\n *\n * An acquire call can be cancelled via an `abortSignal`.\n * If cancelled, the promise will be rejected with an `AbortError`.\n *\n * `acquireTimeoutInMs` can also be provided to properties.\n * If the timeout is reached before the provided `task` is invoked,\n * then the promise will be rejected with an Error stating the task\n * timed out waiting to acquire a lock.\n *\n * @param key - All `acquire` calls are grouped by the provided `key`.\n * @param task - The function to invoke once the lock has been acquired.\n * @param properties - Additional properties to control the behavior of `acquire`.\n */\n acquire<T = void>(\n key: string,\n task: (...args: any[]) => Promise<T>,\n properties: AcquireLockProperties\n ): Promise<T>;\n}\n\n/**\n * This class is used to coordinate executing tasks that should not be run in parallel.\n * @internal\n */\nexport class CancellableAsyncLockImpl {\n private _keyMap = new Map<string, TaskDetails[]>();\n private _executionRunningSet = new Set<string>();\n /**\n * Returns a promise that resolves to the value returned by the provided task function.\n * Only 1 task can be invoked at a time for a given `key` value.\n *\n * An acquire call can be cancelled via an `abortSignal`.\n * If cancelled, the promise will be rejected with an `AbortError`.\n *\n * `acquireTimeoutInMs` can also be provided to properties.\n * If the timeout is reached before the provided `task` is invoked,\n * then the promise will be rejected with an Error stating the task\n * timed out waiting to acquire a lock.\n *\n * @param key - All `acquire` calls are grouped by the provided `key`.\n * @param task - The function to invoke once the lock has been acquired.\n * @param properties - Additional properties to control the behavior of `acquire`.\n */\n acquire<T = void>(\n key: string,\n task: (...args: any[]) => Promise<T>,\n properties: AcquireLockProperties\n ): Promise<T> {\n const { abortSignal, timeoutInMs } = properties;\n // Fast exit if the operation is already cancelled.\n if (abortSignal?.aborted) {\n return Promise.reject(new AbortError(StandardAbortMessage));\n }\n\n // Ensure we've got a task queue for the given key.\n const taskQueue = this._keyMap.get(key) ?? [];\n this._keyMap.set(key, taskQueue);\n\n // This method will return a promise that will be fulfilled outside this function.\n const { promise, rejecter, resolver } = getPromiseParts();\n\n const taskDetails: TaskDetails = {\n reject: rejecter,\n resolve: resolver,\n task\n };\n\n // Handle timeouts by removing the task from the queue when hit.\n if (typeof timeoutInMs === \"number\") {\n const tid = setTimeout(() => {\n this._removeTaskDetails(key, taskDetails);\n rejecter(\n new OperationTimeoutError(`The task timed out waiting to acquire a lock for ${key}`)\n );\n }, timeoutInMs);\n taskDetails.tid = tid;\n }\n\n // Handle cancellation by removing the task from the queue when cancelled.\n if (abortSignal) {\n const abortListener = (): void => {\n this._removeTaskDetails(key, taskDetails);\n rejecter(new AbortError(StandardAbortMessage));\n };\n abortSignal.addEventListener(\"abort\", abortListener);\n taskDetails.abortSignal = abortSignal;\n taskDetails.abortListener = abortListener;\n }\n\n // Enqueue the task!\n taskQueue.push(taskDetails);\n logger.verbose(\n `Called acquire() for lock \"${key}\". Lock \"${key}\" has ${taskQueue.length} pending tasks.`\n );\n\n // Start a loop to iterate over the task queue.\n // This will run asynchronously and won't allow\n // more than 1 concurrent execution per key at a time.\n this._execute(key);\n\n return promise as Promise<T>;\n }\n\n /**\n * Iterates over all the pending tasks for a given `key` serially.\n *\n * Note: If the pending tasks are already being iterated by an early\n * _execute invocation, this returns immediately.\n * @returns\n */\n private async _execute(key: string): Promise<void> {\n // If the key already exists in the set, then exit because\n // tasks are already being processed.\n if (this._executionRunningSet.has(key)) {\n return;\n }\n\n const taskQueue = this._keyMap.get(key);\n // If the queue is empty, exit early!\n if (!taskQueue || !taskQueue.length) {\n return;\n }\n\n // Add the key to the set so we can tell the\n // task queue is already being processed.\n this._executionRunningSet.add(key);\n while (taskQueue.length) {\n // Remove tasks from the front of the queue.\n // Order matters!\n const taskDetails = taskQueue.shift();\n if (!taskDetails) {\n continue;\n }\n\n try {\n logger.verbose(`Acquired lock for \"${key}\", invoking task.`);\n cleanupTaskDetails(taskDetails);\n const value = await taskDetails.task();\n taskDetails.resolve(value);\n } catch (err) {\n taskDetails.reject(err);\n }\n logger.verbose(\n `Task completed for lock \"${key}\". Lock \"${key}\" has ${taskQueue.length} pending tasks.`\n );\n }\n\n // Indicate that the task queue for the key is empty\n // and we're done processing it.\n this._executionRunningSet.delete(key);\n }\n\n private _removeTaskDetails(key: string, taskDetails: TaskDetails): void {\n const taskQueue = this._keyMap.get(key);\n if (!taskQueue || !taskQueue.length) {\n // The task is already gone from the queue, so our work here is done!\n return;\n }\n\n const index = taskQueue.indexOf(taskDetails);\n if (index !== -1) {\n const [details] = taskQueue.splice(index, 1);\n // Cleanup the task rejection code paths.\n cleanupTaskDetails(details);\n }\n }\n}\n\n/**\n * @internal\n * Returns a promise and the promise's resolve and reject methods.\n */\nfunction getPromiseParts(): {\n promise: Promise<unknown>;\n resolver: (value: unknown) => void;\n rejecter: (reason: Error) => void;\n} {\n let resolver: (value: unknown) => void;\n let rejecter: (reason: Error) => void;\n\n const promise = new Promise<unknown>((resolve, reject) => {\n resolver = resolve;\n rejecter = reject;\n });\n\n return {\n promise,\n resolver: resolver!,\n rejecter: rejecter!\n };\n}\n\n/**\n * @internal\n * Removes any abort listener or pending timeout from a task.\n */\nfunction cleanupTaskDetails(taskDetails: TaskDetails): void {\n // Cleanup the task rejection code paths.\n if (taskDetails.tid) clearTimeout(taskDetails.tid);\n if (taskDetails.abortSignal && taskDetails.abortListener) {\n taskDetails.abortSignal.removeEventListener(\"abort\", taskDetails.abortListener);\n }\n}\n"]}
@@ -1,11 +1,9 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import AsyncLock from "async-lock";
4
3
  import { AbortError } from "@azure/abort-controller";
5
4
  import { isDefined } from "./typeGuards";
6
5
  import { StandardAbortMessage } from "../errors";
7
6
  import { CancellableAsyncLockImpl } from "./lock";
8
- export { AsyncLock };
9
7
  /**
10
8
  * @internal
11
9
  *
@@ -48,20 +46,6 @@ export function parseConnectionString(connectionString) {
48
46
  }
49
47
  return output;
50
48
  }
51
- /**
52
- * @internal
53
- *
54
- * Gets a new instance of the async lock with desired settings.
55
- * @param options - The async lock options.
56
- * @returns AsyncLock
57
- */
58
- export function getNewAsyncLock(options) {
59
- return new AsyncLock(options);
60
- }
61
- /**
62
- * The async lock instance with default settings.
63
- */
64
- export const defaultLock = new AsyncLock({ maxPending: 10000 });
65
49
  /**
66
50
  * The cancellable async lock instance.
67
51
  */
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/util/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAwB,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,CAAC;AA8CrB;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GACjB,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;AAOlF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CAAI,gBAAwB;IAC/D,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEjD,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;QACtB,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,IAAI,KAAK,EAAE,EAAE;YACf,qBAAqB;YACrB,SAAS;SACV;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE;YACrB,MAAM,IAAI,KAAK,CACb,8FAA8F,CAC/F,CAAC;SACH;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,C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AC,CAAC,cAAc,EAAE,EAAE;QAC1C,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,gBAAwB;IAC/D,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAE5C,IAAI,MAAM,GAAY,KAAK,CAAC;IAC5B,MAAM,KAAK,GAAQ,qBAAqB,CAAM,gBAAgB,CAAC,CAAC;IAChE,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,mBAAmB,EAAE;QACjF,MAAM,GAAG,IAAI,CAAC;KACf;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport AsyncLock from \"async-lock\";\nimport { AbortError, AbortSignalLike } from \"@azure/abort-controller\";\nimport { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"./typeGuards\";\nimport { StandardAbortMessage } from \"../errors\";\nimport { CancellableAsyncLock, CancellableAsyncLockImpl } from \"./lock\";\n\nexport { AsyncLock };\n/**\n * @internal\n *\n * Describes the options that can be provided to create an async lock.\n */\nexport interface AsyncLockOptions {\n /**\n * The max timeout. Default is: 0 (never timeout).\n */\n timeout?: number;\n /**\n * Maximum pending tasks. Default is: 1000.\n */\n maxPending?: number;\n /**\n * Whether lock can reenter in the same domain.\n * Default is: false.\n */\n domainReentrant?: boolean;\n /**\n * Your implementation of the promise. Default is: global promise.\n */\n Promise?: any;\n}\n\n/**\n * Options to configure the channelling of the AMQP connection over Web Sockets.\n */\nexport interface WebSocketOptions {\n /**\n * The WebSocket constructor used to create an AMQP connection over a WebSocket.\n * This option should be provided in the below scenarios:\n * - The TCP port 5671 which is that is used by the AMQP connection to Event Hubs is blocked in your environment.\n * - Your application needs to be run behind a proxy server.\n * - Your application needs to run in the browser and you want to provide your own choice of Websocket implementation\n * instead of the built-in WebSocket in the browser.\n */\n webSocket?: WebSocketImpl;\n /**\n * Options to be passed to the WebSocket constructor when the underlying `rhea` library instantiates\n * the WebSocket.\n */\n webSocketConstructorOptions?: any;\n}\n\n/**\n * @internal\n *\n * A constant that indicates whether the environment is node.js or browser based.\n */\nexport const isNode =\n !!process && !!process.version && !!process.versions && !!process.versions.node;\n\n/**\n * Defines an object with possible properties defined in T.\n */\nexport type ParsedOutput<T> = { [P in keyof T]: T[P] };\n\n/**\n * Parses the connection string and returns an object of type T.\n *\n * Connection strings have the following syntax:\n *\n * ConnectionString ::= `Part { \";\" Part } [ \";\" ] [ WhiteSpace ]`\n * Part ::= [ PartLiteral [ \"=\" PartLiteral ] ]\n * PartLiteral ::= [ WhiteSpace ] Literal [ WhiteSpace ]\n * Literal ::= ? any sequence of characters except ; or = or WhiteSpace ?\n * WhiteSpace ::= ? all whitespace characters including `\\r` and `\\n` ?\n *\n * @param connectionString - The connection string to be parsed.\n * @returns ParsedOutput<T>.\n */\nexport function parseConnectionString<T>(connectionString: string): ParsedOutput<T> {\n const output: { [k: string]: string } = {};\n const parts = connectionString.trim().split(\";\");\n\n for (let part of parts) {\n part = part.trim();\n\n if (part === \"\") {\n // parts can be empty\n continue;\n }\n\n const splitIndex = part.indexOf(\"=\");\n if (splitIndex === -1) {\n throw new Error(\n \"Connection string malformed: each part of the connection string must have an `=` assignment.\"\n );\n }\n\n const key = part.substring(0, splitIndex).trim();\n if (key === \"\") {\n throw new Error(\"Connection string malformed: missing key for assignment\");\n }\n\n const value = part.substring(splitIndex + 1).trim();\n\n output[key] = value;\n }\n\n return output as any;\n}\n\n/**\n * @internal\n *\n * Gets a new instance of the async lock with desired settings.\n * @param options - The async lock options.\n * @returns AsyncLock\n */\nexport function getNewAsyncLock(options?: AsyncLockOptions): AsyncLock {\n return new AsyncLock(options);\n}\n\n/**\n * The async lock instance with default settings.\n */\nexport const defaultLock: AsyncLock = new AsyncLock({ maxPending: 10000 });\n\n/**\n * The cancellable async lock instance.\n */\nexport const defaultCancellableLock: CancellableAsyncLock = new CancellableAsyncLockImpl();\n\n/**\n * @internal\n *\n * Describes a Timeout class that can wait for the specified amount of time and then resolve/reject\n * the promise with the given value.\n */\nexport class Timeout {\n // Node and browsers return different types from setTimeout\n // Any is the easiest way to avoid type errors in either platform\n private _timer?: any;\n\n set<T>(t: number, value?: T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.clear();\n const callback = value ? () => reject(new Error(`${value}`)) : resolve;\n this._timer = setTimeout(callback, t);\n });\n }\n\n clear(): void {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n }\n\n wrap<T>(promise: Promise<T>, t: number, value?: T): Promise<T> {\n const wrappedPromise = this._promiseFinally(promise, () => this.clear());\n const timer = this.set(t, value);\n return Promise.race([wrappedPromise, timer]);\n }\n\n private _promiseFinally<T>(promise: Promise<T>, fn: (...args: any[]) => void): Promise<T> {\n const success = (result: T): T => {\n fn();\n return result;\n };\n const error = (e: Error): Promise<never> => {\n fn();\n return Promise.reject(e);\n };\n return Promise.resolve(promise).then(success, error);\n }\n\n static set<T>(t: number, value?: T): Promise<T> {\n return new Timeout().set(t, value);\n }\n\n static wrap<T>(promise: Promise<T>, t: number, value?: T): Promise<T> {\n return new Timeout().wrap(promise, t, value);\n }\n}\n\n/**\n * A wrapper for setTimeout that resolves a promise after t milliseconds.\n * @param delayInMs - The number of milliseconds to be delayed.\n * @param abortSignal - The abortSignal associated with containing operation.\n * @param abortErrorMsg - The abort error message associated with containing operation.\n * @param value - The value to be resolved with after a timeout of t milliseconds.\n * @returns - Resolved promise\n */\nexport function delay<T>(\n delayInMs: number,\n abortSignal?: AbortSignalLike,\n abortErrorMsg?: string,\n value?: T\n): Promise<T | void> {\n return new Promise((resolve, reject) => {\n let timer: ReturnType<typeof setTimeout> | undefined = undefined;\n let onAborted: (() => void) | undefined = undefined;\n\n const rejectOnAbort = (): void => {\n return reject(new AbortError(abortErrorMsg ? abortErrorMsg : StandardAbortMessage));\n };\n\n const removeListeners = (): void => {\n if (abortSignal && onAborted) {\n abortSignal.removeEventListener(\"abort\", onAborted);\n }\n };\n\n onAborted = (): void => {\n if (isDefined(timer)) {\n clearTimeout(timer);\n }\n removeListeners();\n return rejectOnAbort();\n };\n\n if (abortSignal && abortSignal.aborted) {\n return rejectOnAbort();\n }\n\n timer = setTimeout(() => {\n removeListeners();\n resolve(value);\n }, delayInMs);\n\n if (abortSignal) {\n abortSignal.addEventListener(\"abort\", onAborted);\n }\n });\n}\n\n/**\n * @internal\n *\n * Generates a random number between the given interval\n * @param min - Min number of the range (inclusive).\n * @param max - Max number of the range (inclusive).\n */\nexport function randomNumberFromInterval(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n\n/**\n * @internal\n *\n * Type declaration for a Function type where T is the input to the function and V is the output\n * of the function.\n */\nexport type Func<T, V> = (a: T) => V;\n\n/**\n * @internal\n *\n * Executes an array of promises sequentially. Inspiration of this method is here:\n * https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html. An awesome blog on promises!\n *\n * @param promiseFactories - An array of promise factories(A function that return a promise)\n *\n * @param kickstart - Input to the first promise that is used to kickstart the promise chain.\n * If not provided then the promise chain starts with undefined.\n *\n * @returns A chain of resolved or rejected promises\n */\nexport function executePromisesSequentially(\n promiseFactories: Array<any>,\n kickstart?: unknown\n): Promise<any> {\n let result = Promise.resolve(kickstart);\n promiseFactories.forEach((promiseFactory) => {\n result = result.then(promiseFactory);\n });\n return result;\n}\n\n/**\n * @internal\n *\n * Determines whether the given connection string is an iothub connection string.\n * @param connectionString - The connection string.\n * @returns boolean.\n */\nexport function isIotHubConnectionString(connectionString: string): boolean {\n connectionString = String(connectionString);\n\n let result: boolean = false;\n const model: any = parseConnectionString<any>(connectionString);\n if (model && model.HostName && model.SharedAccessKey && model.SharedAccessKeyName) {\n result = true;\n }\n return result;\n}\n\n/**\n * @internal\n */\nexport function isString(s: unknown): s is string {\n return typeof s === \"string\";\n}\n\n/**\n * @internal\n */\nexport function isNumber(n: unknown): n is number {\n return typeof n === \"number\";\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/util/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAwB,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AA+CxE;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GACjB,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;AAOlF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CAAI,gBAAwB;IAC/D,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEjD,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;QACtB,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,IAAI,KAAK,EAAE,EAAE;YACf,qBAAqB;YACrB,SAAS;SACV;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAA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M,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,gBAAwB;IAC/D,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAE5C,IAAI,MAAM,GAAY,KAAK,CAAC;IAC5B,MAAM,KAAK,GAAQ,qBAAqB,CAAM,gBAAgB,CAAC,CAAC;IAChE,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,mBAAmB,EAAE;QACjF,MAAM,GAAG,IAAI,CAAC;KACf;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortError, AbortSignalLike } from \"@azure/abort-controller\";\nimport { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"./typeGuards\";\nimport { StandardAbortMessage } from \"../errors\";\nimport { CancellableAsyncLock, CancellableAsyncLockImpl } from \"./lock\";\n\n/**\n * @internal\n *\n * Describes the options that can be provided to create an async lock.\n */\nexport interface AsyncLockOptions {\n /**\n * The max timeout. Default is: 0 (never timeout).\n */\n timeout?: number;\n /**\n * Maximum pending tasks. Default is: 1000.\n */\n maxPending?: number;\n /**\n * Whether lock can reenter in the same domain.\n * Default is: false.\n */\n domainReentrant?: boolean;\n /**\n * Your implementation of the promise. Default is: global promise.\n */\n Promise?: any;\n}\n\n/**\n * Options to configure the channelling of the AMQP connection over Web Sockets.\n */\nexport interface WebSocketOptions {\n /**\n * The WebSocket constructor used to create an AMQP connection over a WebSocket.\n * This option should be provided in the below scenarios:\n * - The TCP port 5671 which is that is used by the AMQP connection to Event Hubs is blocked in your environment.\n * - Your application needs to be run behind a proxy server.\n * - Your application needs to run in the browser and you want to provide your own choice of Websocket implementation\n * instead of the built-in WebSocket in the browser.\n */\n webSocket?: WebSocketImpl;\n /**\n * Options to be passed to the WebSocket constructor when the underlying `rhea` library instantiates\n * the WebSocket.\n */\n webSocketConstructorOptions?: any;\n}\n\n/**\n * @internal\n *\n * A constant that indicates whether the environment is node.js or browser based.\n */\nexport const isNode =\n !!process && !!process.version && !!process.versions && !!process.versions.node;\n\n/**\n * Defines an object with possible properties defined in T.\n */\nexport type ParsedOutput<T> = { [P in keyof T]: T[P] };\n\n/**\n * Parses the connection string and returns an object of type T.\n *\n * Connection strings have the following syntax:\n *\n * ConnectionString ::= `Part { \";\" Part } [ \";\" ] [ WhiteSpace ]`\n * Part ::= [ PartLiteral [ \"=\" PartLiteral ] ]\n * PartLiteral ::= [ WhiteSpace ] Literal [ WhiteSpace ]\n * Literal ::= ? any sequence of characters except ; or = or WhiteSpace ?\n * WhiteSpace ::= ? all whitespace characters including `\\r` and `\\n` ?\n *\n * @param connectionString - The connection string to be parsed.\n * @returns ParsedOutput<T>.\n */\nexport function parseConnectionString<T>(connectionString: string): ParsedOutput<T> {\n const output: { [k: string]: string } = {};\n const parts = connectionString.trim().split(\";\");\n\n for (let part of parts) {\n part = part.trim();\n\n if (part === \"\") {\n // parts can be empty\n continue;\n }\n\n const splitIndex = part.indexOf(\"=\");\n if (splitIndex === -1) {\n throw new Error(\n \"Connection string malformed: each part of the connection string must have an `=` assignment.\"\n );\n }\n\n const key = part.substring(0, splitIndex).trim();\n if (key === \"\") {\n throw new Error(\"Connection string malformed: missing key for assignment\");\n }\n\n const value = part.substring(splitIndex + 1).trim();\n\n output[key] = value;\n }\n\n return output as any;\n}\n\n/**\n * The cancellable async lock instance.\n */\nexport const defaultCancellableLock: CancellableAsyncLock = new CancellableAsyncLockImpl();\n\n/**\n * @internal\n *\n * Describes a Timeout class that can wait for the specified amount of time and then resolve/reject\n * the promise with the given value.\n */\nexport class Timeout {\n // Node and browsers return different types from setTimeout\n // Any is the easiest way to avoid type errors in either platform\n private _timer?: any;\n\n set<T>(t: number, value?: T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.clear();\n const callback = value ? () => reject(new Error(`${value}`)) : resolve;\n this._timer = setTimeout(callback, t);\n });\n }\n\n clear(): void {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n }\n\n wrap<T>(promise: Promise<T>, t: number, value?: T): Promise<T> {\n const wrappedPromise = this._promiseFinally(promise, () => this.clear());\n const timer = this.set(t, value);\n return Promise.race([wrappedPromise, timer]);\n }\n\n private _promiseFinally<T>(promise: Promise<T>, fn: (...args: any[]) => void): Promise<T> {\n const success = (result: T): T => {\n fn();\n return result;\n };\n const error = (e: Error): Promise<never> => {\n fn();\n return Promise.reject(e);\n };\n return Promise.resolve(promise).then(success, error);\n }\n\n static set<T>(t: number, value?: T): Promise<T> {\n return new Timeout().set(t, value);\n }\n\n static wrap<T>(promise: Promise<T>, t: number, value?: T): Promise<T> {\n return new Timeout().wrap(promise, t, value);\n }\n}\n\n/**\n * A wrapper for setTimeout that resolves a promise after t milliseconds.\n * @param delayInMs - The number of milliseconds to be delayed.\n * @param abortSignal - The abortSignal associated with containing operation.\n * @param abortErrorMsg - The abort error message associated with containing operation.\n * @param value - The value to be resolved with after a timeout of t milliseconds.\n * @returns - Resolved promise\n */\nexport function delay<T>(\n delayInMs: number,\n abortSignal?: AbortSignalLike,\n abortErrorMsg?: string,\n value?: T\n): Promise<T | void> {\n return new Promise((resolve, reject) => {\n let timer: ReturnType<typeof setTimeout> | undefined = undefined;\n let onAborted: (() => void) | undefined = undefined;\n\n const rejectOnAbort = (): void => {\n return reject(new AbortError(abortErrorMsg ? abortErrorMsg : StandardAbortMessage));\n };\n\n const removeListeners = (): void => {\n if (abortSignal && onAborted) {\n abortSignal.removeEventListener(\"abort\", onAborted);\n }\n };\n\n onAborted = (): void => {\n if (isDefined(timer)) {\n clearTimeout(timer);\n }\n removeListeners();\n return rejectOnAbort();\n };\n\n if (abortSignal && abortSignal.aborted) {\n return rejectOnAbort();\n }\n\n timer = setTimeout(() => {\n removeListeners();\n resolve(value);\n }, delayInMs);\n\n if (abortSignal) {\n abortSignal.addEventListener(\"abort\", onAborted);\n }\n });\n}\n\n/**\n * @internal\n *\n * Generates a random number between the given interval\n * @param min - Min number of the range (inclusive).\n * @param max - Max number of the range (inclusive).\n */\nexport function randomNumberFromInterval(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n\n/**\n * @internal\n *\n * Type declaration for a Function type where T is the input to the function and V is the output\n * of the function.\n */\nexport type Func<T, V> = (a: T) => V;\n\n/**\n * @internal\n *\n * Executes an array of promises sequentially. Inspiration of this method is here:\n * https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html. An awesome blog on promises!\n *\n * @param promiseFactories - An array of promise factories(A function that return a promise)\n *\n * @param kickstart - Input to the first promise that is used to kickstart the promise chain.\n * If not provided then the promise chain starts with undefined.\n *\n * @returns A chain of resolved or rejected promises\n */\nexport function executePromisesSequentially(\n promiseFactories: Array<any>,\n kickstart?: unknown\n): Promise<any> {\n let result = Promise.resolve(kickstart);\n promiseFactories.forEach((promiseFactory) => {\n result = result.then(promiseFactory);\n });\n return result;\n}\n\n/**\n * @internal\n *\n * Determines whether the given connection string is an iothub connection string.\n * @param connectionString - The connection string.\n * @returns boolean.\n */\nexport function isIotHubConnectionString(connectionString: string): boolean {\n connectionString = String(connectionString);\n\n let result: boolean = false;\n const model: any = parseConnectionString<any>(connectionString);\n if (model && model.HostName && model.SharedAccessKey && model.SharedAccessKeyName) {\n result = true;\n }\n return result;\n}\n\n/**\n * @internal\n */\nexport function isString(s: unknown): s is string {\n return typeof s === \"string\";\n}\n\n/**\n * @internal\n */\nexport function isNumber(n: unknown): n is number {\n return typeof n === \"number\";\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@azure/core-amqp",
3
3
  "sdk-type": "client",
4
- "version": "2.3.1-alpha.20210518.2",
4
+ "version": "3.0.0",
5
5
  "description": "Common library for amqp based azure sdks like @azure/event-hubs.",
6
6
  "author": "Microsoft Corporation",
7
7
  "license": "MIT",
@@ -72,20 +72,18 @@
72
72
  "@azure/abort-controller": "^1.0.0",
73
73
  "@azure/core-auth": "^1.3.0",
74
74
  "@azure/logger": "^1.0.0",
75
- "@types/async-lock": "^1.1.0",
76
- "async-lock": "^1.1.3",
77
75
  "buffer": "^5.2.1",
78
76
  "events": "^3.0.0",
79
77
  "jssha": "^3.1.0",
80
78
  "process": "^0.11.10",
81
- "rhea": "^1.0.24",
82
- "rhea-promise": "^1.2.1",
79
+ "rhea": "^2.0.2",
80
+ "rhea-promise": "^2.0.0",
83
81
  "tslib": "^2.0.0",
84
82
  "url": "^0.11.0",
85
83
  "util": "^0.12.1"
86
84
  },
87
85
  "devDependencies": {
88
- "@azure/eslint-plugin-azure-sdk": "^3.0.0-alpha",
86
+ "@azure/eslint-plugin-azure-sdk": "^3.0.0",
89
87
  "@microsoft/api-extractor": "7.7.11",
90
88
  "@azure/identity": "^1.1.0",
91
89
  "@rollup/plugin-commonjs": "11.0.2",
@@ -2,7 +2,6 @@
2
2
  import { AbortSignalLike } from '@azure/abort-controller';
3
3
  import { AccessToken } from '@azure/core-auth';
4
4
  import { AmqpError } from 'rhea-promise';
5
- import AsyncLock from 'async-lock';
6
5
  import { Connection } from 'rhea-promise';
7
6
  import { Message } from 'rhea-promise';
8
7
  import { MessageHeader } from 'rhea-promise';
@@ -22,6 +21,8 @@ import { WebSocketImpl } from 'rhea-promise';
22
21
  export declare interface AcquireLockProperties {
23
22
  /**
24
23
  * An implementation of the `AbortSignalLike` interface to signal the request to cancel lock acquisition.
24
+ * This only applies to the acquisition of a lock. Once the lock is acquired, the task is invoked and `acquire`
25
+ * can no longer be cancelled.
25
26
  * This does not cancel running the task passed to `acquire()` if the lock has been acquired,
26
27
  * but will prevent it from running if cancelled before the task is invoked.
27
28
  */
@@ -212,7 +213,6 @@ export declare const AmqpMessageProperties: {
212
213
  */
213
214
  fromRheaMessageProperties(props: MessageProperties): AmqpMessageProperties;
214
215
  };
215
- export { AsyncLock };
216
216
  /**
217
217
  * CancellableAsyncLock provides a mechanism for forcing tasks using the same
218
218
  * 'key' to be executed serially.
@@ -874,10 +874,6 @@ export declare function createSasTokenProvider(data: {
874
874
  * The cancellable async lock instance.
875
875
  */
876
876
  export declare const defaultCancellableLock: CancellableAsyncLock;
877
- /**
878
- * The async lock instance with default settings.
879
- */
880
- export declare const defaultLock: AsyncLock;
881
877
  /**
882
878
  * A wrapper for setTimeout that resolves a promise after t milliseconds.
883
879
  * @param delayInMs - The number of milliseconds to be delayed.
@@ -2,7 +2,6 @@
2
2
  import { AbortSignalLike } from '@azure/abort-controller';
3
3
  import { AccessToken } from '@azure/core-auth';
4
4
  import { AmqpError } from 'rhea-promise';
5
- import AsyncLock from 'async-lock';
6
5
  import { Connection } from 'rhea-promise';
7
6
  import { Message } from 'rhea-promise';
8
7
  import { MessageHeader } from 'rhea-promise';
@@ -23,6 +22,8 @@ import { WebSocketImpl } from 'rhea-promise';
23
22
  export declare interface AcquireLockProperties {
24
23
  /**
25
24
  * An implementation of the `AbortSignalLike` interface to signal the request to cancel lock acquisition.
25
+ * This only applies to the acquisition of a lock. Once the lock is acquired, the task is invoked and `acquire`
26
+ * can no longer be cancelled.
26
27
  * This does not cancel running the task passed to `acquire()` if the lock has been acquired,
27
28
  * but will prevent it from running if cancelled before the task is invoked.
28
29
  */
@@ -219,7 +220,6 @@ export declare const AmqpMessageProperties: {
219
220
  */
220
221
  fromRheaMessageProperties(props: MessageProperties): AmqpMessageProperties;
221
222
  };
222
- export { AsyncLock }
223
223
 
224
224
  /**
225
225
  * CancellableAsyncLock provides a mechanism for forcing tasks using the same
@@ -896,11 +896,6 @@ export declare function createSasTokenProvider(data: {
896
896
  */
897
897
  export declare const defaultCancellableLock: CancellableAsyncLock;
898
898
 
899
- /**
900
- * The async lock instance with default settings.
901
- */
902
- export declare const defaultLock: AsyncLock;
903
-
904
899
  /**
905
900
  * A wrapper for setTimeout that resolves a promise after t milliseconds.
906
901
  * @param delayInMs - The number of milliseconds to be delayed.