@azure/core-amqp 2.2.0-alpha.20210326.1 → 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.
@@ -1,18 +1,39 @@
1
1
  /// <reference types="node" />
2
2
  import { AbortSignalLike } from '@azure/abort-controller';
3
+ import { AccessToken } from '@azure/core-auth';
3
4
  import { AmqpError } from 'rhea-promise';
4
- import AsyncLock from 'async-lock';
5
5
  import { Connection } from 'rhea-promise';
6
6
  import { Message } from 'rhea-promise';
7
7
  import { MessageHeader } from 'rhea-promise';
8
8
  import { MessageProperties } from 'rhea-promise';
9
+ import { NamedKeyCredential } from '@azure/core-auth';
9
10
  import { Receiver } from 'rhea-promise';
10
11
  import { ReceiverOptions } from 'rhea-promise';
11
12
  import { ReqResLink } from 'rhea-promise';
13
+ import { SASCredential } from '@azure/core-auth';
12
14
  import { Sender } from 'rhea-promise';
13
15
  import { SenderOptions } from 'rhea-promise';
14
16
  import { Session } from 'rhea-promise';
15
17
  import { WebSocketImpl } from 'rhea-promise';
18
+ /**
19
+ * Describes the properties that must be provided while acquiring a lock.
20
+ */
21
+ export declare interface AcquireLockProperties {
22
+ /**
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.
26
+ * This does not cancel running the task passed to `acquire()` if the lock has been acquired,
27
+ * but will prevent it from running if cancelled before the task is invoked.
28
+ */
29
+ abortSignal: AbortSignalLike | undefined;
30
+ /**
31
+ * The allowed amount of time in milliseconds to acquire a lock.
32
+ * If a lock isn't acquired within this time, the promise returned
33
+ * by `acquire()` will be rejected with an Error.
34
+ */
35
+ timeoutInMs: number | undefined;
36
+ }
16
37
  /**
17
38
  * Describes the AmqpAnnotatedMessage, part of the ServiceBusReceivedMessage(as `amqpAnnotatedMessage` property).
18
39
  */
@@ -54,6 +75,10 @@ export declare interface AmqpAnnotatedMessage {
54
75
  * The message body.
55
76
  */
56
77
  body: any;
78
+ /**
79
+ * The AMQP section where the data was decoded from.
80
+ */
81
+ bodyType?: "data" | "sequence" | "value";
57
82
  }
58
83
  /**
59
84
  * Describes the operations that can be performed on(or to get) the AmqpAnnotatedMessage.
@@ -63,6 +88,10 @@ export declare const AmqpAnnotatedMessage: {
63
88
  * Takes RheaMessage(`Message` type from "rhea") and returns it in the AmqpAnnotatedMessage format.
64
89
  */
65
90
  fromRheaMessage(msg: Message): AmqpAnnotatedMessage;
91
+ /**
92
+ * Takes AmqpAnnotatedMessage and returns it in the RheaMessage(`Message` type from "rhea") format.
93
+ */
94
+ toRheaMessage(msg: AmqpAnnotatedMessage): Message;
66
95
  };
67
96
  /**
68
97
  * Describes the defined set of standard header properties of the message.
@@ -184,7 +213,32 @@ export declare const AmqpMessageProperties: {
184
213
  */
185
214
  fromRheaMessageProperties(props: MessageProperties): AmqpMessageProperties;
186
215
  };
187
- export { AsyncLock };
216
+ /**
217
+ * CancellableAsyncLock provides a mechanism for forcing tasks using the same
218
+ * 'key' to be executed serially.
219
+ *
220
+ * Pending tasks can be manually cancelled via an abortSignal or automatically
221
+ * cancelled by reach a provided timeout value.
222
+ */
223
+ export declare interface CancellableAsyncLock {
224
+ /**
225
+ * Returns a promise that resolves to the value returned by the provided task function.
226
+ * Only 1 task can be invoked at a time for a given `key` value.
227
+ *
228
+ * An acquire call can be cancelled via an `abortSignal`.
229
+ * If cancelled, the promise will be rejected with an `AbortError`.
230
+ *
231
+ * `acquireTimeoutInMs` can also be provided to properties.
232
+ * If the timeout is reached before the provided `task` is invoked,
233
+ * then the promise will be rejected with an Error stating the task
234
+ * timed out waiting to acquire a lock.
235
+ *
236
+ * @param key - All `acquire` calls are grouped by the provided `key`.
237
+ * @param task - The function to invoke once the lock has been acquired.
238
+ * @param properties - Additional properties to control the behavior of `acquire`.
239
+ */
240
+ acquire<T = void>(key: string, task: (...args: any[]) => Promise<T>, properties: AcquireLockProperties): Promise<T>;
241
+ }
188
242
  /**
189
243
  * Describes the EventHub/ServiceBus Cbs client that talks to the $cbs endpoint over AMQP connection.
190
244
  */
@@ -229,6 +283,7 @@ export declare class CbsClient {
229
283
  */
230
284
  init(options?: {
231
285
  abortSignal?: AbortSignalLike;
286
+ timeoutInMs?: number;
232
287
  }): Promise<void>;
233
288
  /**
234
289
  * Negotiates the CBS claim with the EventHub/ServiceBus Service.
@@ -267,6 +322,7 @@ export declare class CbsClient {
267
322
  */
268
323
  negotiateClaim(audience: string, token: string, tokenType: TokenType, options?: {
269
324
  abortSignal?: AbortSignalLike;
325
+ timeoutInMs?: number;
270
326
  }): Promise<CbsResponse>;
271
327
  /**
272
328
  * Closes the AMQP cbs session to the EventHub/ServiceBus for this client,
@@ -283,7 +339,7 @@ export declare class CbsClient {
283
339
  * Indicates whether the cbs sender receiver link is open or closed.
284
340
  * @returns `true` open, `false` closed.
285
341
  */
286
- private _isCbsSenderReceiverLinkOpen;
342
+ isOpen(): boolean;
287
343
  private _fromRheaMessageResponse;
288
344
  }
289
345
  /**
@@ -804,9 +860,20 @@ export declare interface CreateConnectionContextBaseParameters {
804
860
  operationTimeoutInMs?: number;
805
861
  }
806
862
  /**
807
- * The async lock instance with default settings.
863
+ * Creates a token provider from the provided shared access data.
864
+ * @param data - The sharedAccessKeyName/sharedAccessKey pair or the sharedAccessSignature.
865
+ * @hidden
866
+ */
867
+ export declare function createSasTokenProvider(data: {
868
+ sharedAccessKeyName: string;
869
+ sharedAccessKey: string;
870
+ } | {
871
+ sharedAccessSignature: string;
872
+ } | NamedKeyCredential | SASCredential): SasTokenProvider;
873
+ /**
874
+ * The cancellable async lock instance.
808
875
  */
809
- export declare const defaultLock: AsyncLock;
876
+ export declare const defaultCancellableLock: CancellableAsyncLock;
810
877
  /**
811
878
  * A wrapper for setTimeout that resolves a promise after t milliseconds.
812
879
  * @param delayInMs - The number of milliseconds to be delayed.
@@ -1018,6 +1085,12 @@ export declare enum ErrorNameConditionMapper {
1018
1085
  * @param error - An error that can either be an Error or a MessagingError.
1019
1086
  */
1020
1087
  export declare function isMessagingError(error: Error | MessagingError): error is MessagingError;
1088
+ /**
1089
+ * Typeguard that checks if the input is a SasTokenProvider.
1090
+ * @param thing - Any object.
1091
+ * @hidden
1092
+ */
1093
+ export declare function isSasTokenProvider(thing: unknown): thing is SasTokenProvider;
1021
1094
  /**
1022
1095
  * Checks whether the provided error is a node.js SystemError.
1023
1096
  * @param err - An object that may contain error information.
@@ -1245,7 +1318,8 @@ export declare enum RetryOperationType {
1245
1318
  senderLink = "senderLink",
1246
1319
  sendMessage = "sendMessage",
1247
1320
  receiveMessage = "receiveMessage",
1248
- session = "session"
1321
+ session = "session",
1322
+ messageSettlement = "settlement"
1249
1323
  }
1250
1324
  /**
1251
1325
  * Retry policy options that determine the mode, number of retries, retry interval etc.
@@ -1278,6 +1352,24 @@ export declare interface RetryOptions {
1278
1352
  */
1279
1353
  maxRetryDelayInMs?: number;
1280
1354
  }
1355
+ /**
1356
+ * A SasTokenProvider provides an alternative to TokenCredential for providing an `AccessToken`.
1357
+ * @hidden
1358
+ */
1359
+ export declare interface SasTokenProvider {
1360
+ /**
1361
+ * Property used to distinguish SasTokenProvider from TokenCredential.
1362
+ */
1363
+ isSasTokenProvider: true;
1364
+ /**
1365
+ * Gets the token provided by this provider.
1366
+ *
1367
+ * This method is called automatically by Azure SDK client libraries.
1368
+ *
1369
+ * @param audience - The audience for which the token is desired.
1370
+ */
1371
+ getToken(audience: string): AccessToken;
1372
+ }
1281
1373
  /**
1282
1374
  * Describes the options that can be specified while sending a request.
1283
1375
  */
@@ -1296,6 +1388,11 @@ export declare interface SendRequestOptions {
1296
1388
  */
1297
1389
  requestName?: string;
1298
1390
  }
1391
+ /**
1392
+ * The standard error message accompanying an AbortError.
1393
+ * @hidden
1394
+ */
1395
+ export declare const StandardAbortMessage = "The operation was aborted.";
1299
1396
  /**
1300
1397
  * Maps some SystemErrors to amqp error conditions
1301
1398
  */
@@ -1,19 +1,41 @@
1
1
  /// <reference types="node" />
2
2
  import { AbortSignalLike } from '@azure/abort-controller';
3
+ import { AccessToken } from '@azure/core-auth';
3
4
  import { AmqpError } from 'rhea-promise';
4
- import AsyncLock from 'async-lock';
5
5
  import { Connection } from 'rhea-promise';
6
6
  import { Message } from 'rhea-promise';
7
7
  import { MessageHeader } from 'rhea-promise';
8
8
  import { MessageProperties } from 'rhea-promise';
9
+ import { NamedKeyCredential } from '@azure/core-auth';
9
10
  import { Receiver } from 'rhea-promise';
10
11
  import { ReceiverOptions } from 'rhea-promise';
11
12
  import { ReqResLink } from 'rhea-promise';
13
+ import { SASCredential } from '@azure/core-auth';
12
14
  import { Sender } from 'rhea-promise';
13
15
  import { SenderOptions } from 'rhea-promise';
14
16
  import { Session } from 'rhea-promise';
15
17
  import { WebSocketImpl } from 'rhea-promise';
16
18
 
19
+ /**
20
+ * Describes the properties that must be provided while acquiring a lock.
21
+ */
22
+ export declare interface AcquireLockProperties {
23
+ /**
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.
27
+ * This does not cancel running the task passed to `acquire()` if the lock has been acquired,
28
+ * but will prevent it from running if cancelled before the task is invoked.
29
+ */
30
+ abortSignal: AbortSignalLike | undefined;
31
+ /**
32
+ * The allowed amount of time in milliseconds to acquire a lock.
33
+ * If a lock isn't acquired within this time, the promise returned
34
+ * by `acquire()` will be rejected with an Error.
35
+ */
36
+ timeoutInMs: number | undefined;
37
+ }
38
+
17
39
  /**
18
40
  * Describes the AmqpAnnotatedMessage, part of the ServiceBusReceivedMessage(as `amqpAnnotatedMessage` property).
19
41
  */
@@ -55,6 +77,10 @@ export declare interface AmqpAnnotatedMessage {
55
77
  * The message body.
56
78
  */
57
79
  body: any;
80
+ /**
81
+ * The AMQP section where the data was decoded from.
82
+ */
83
+ bodyType?: "data" | "sequence" | "value";
58
84
  }
59
85
 
60
86
  /**
@@ -65,6 +91,10 @@ export declare const AmqpAnnotatedMessage: {
65
91
  * Takes RheaMessage(`Message` type from "rhea") and returns it in the AmqpAnnotatedMessage format.
66
92
  */
67
93
  fromRheaMessage(msg: Message): AmqpAnnotatedMessage;
94
+ /**
95
+ * Takes AmqpAnnotatedMessage and returns it in the RheaMessage(`Message` type from "rhea") format.
96
+ */
97
+ toRheaMessage(msg: AmqpAnnotatedMessage): Message;
68
98
  };
69
99
 
70
100
  /**
@@ -190,7 +220,33 @@ export declare const AmqpMessageProperties: {
190
220
  */
191
221
  fromRheaMessageProperties(props: MessageProperties): AmqpMessageProperties;
192
222
  };
193
- export { AsyncLock }
223
+
224
+ /**
225
+ * CancellableAsyncLock provides a mechanism for forcing tasks using the same
226
+ * 'key' to be executed serially.
227
+ *
228
+ * Pending tasks can be manually cancelled via an abortSignal or automatically
229
+ * cancelled by reach a provided timeout value.
230
+ */
231
+ export declare interface CancellableAsyncLock {
232
+ /**
233
+ * Returns a promise that resolves to the value returned by the provided task function.
234
+ * Only 1 task can be invoked at a time for a given `key` value.
235
+ *
236
+ * An acquire call can be cancelled via an `abortSignal`.
237
+ * If cancelled, the promise will be rejected with an `AbortError`.
238
+ *
239
+ * `acquireTimeoutInMs` can also be provided to properties.
240
+ * If the timeout is reached before the provided `task` is invoked,
241
+ * then the promise will be rejected with an Error stating the task
242
+ * timed out waiting to acquire a lock.
243
+ *
244
+ * @param key - All `acquire` calls are grouped by the provided `key`.
245
+ * @param task - The function to invoke once the lock has been acquired.
246
+ * @param properties - Additional properties to control the behavior of `acquire`.
247
+ */
248
+ acquire<T = void>(key: string, task: (...args: any[]) => Promise<T>, properties: AcquireLockProperties): Promise<T>;
249
+ }
194
250
 
195
251
  /**
196
252
  * Describes the EventHub/ServiceBus Cbs client that talks to the $cbs endpoint over AMQP connection.
@@ -236,6 +292,7 @@ export declare class CbsClient {
236
292
  */
237
293
  init(options?: {
238
294
  abortSignal?: AbortSignalLike;
295
+ timeoutInMs?: number;
239
296
  }): Promise<void>;
240
297
  /**
241
298
  * Negotiates the CBS claim with the EventHub/ServiceBus Service.
@@ -274,6 +331,7 @@ export declare class CbsClient {
274
331
  */
275
332
  negotiateClaim(audience: string, token: string, tokenType: TokenType, options?: {
276
333
  abortSignal?: AbortSignalLike;
334
+ timeoutInMs?: number;
277
335
  }): Promise<CbsResponse>;
278
336
  /**
279
337
  * Closes the AMQP cbs session to the EventHub/ServiceBus for this client,
@@ -290,7 +348,7 @@ export declare class CbsClient {
290
348
  * Indicates whether the cbs sender receiver link is open or closed.
291
349
  * @returns `true` open, `false` closed.
292
350
  */
293
- private _isCbsSenderReceiverLinkOpen;
351
+ isOpen(): boolean;
294
352
  private _fromRheaMessageResponse;
295
353
  }
296
354
 
@@ -822,9 +880,21 @@ export declare interface CreateConnectionContextBaseParameters {
822
880
  }
823
881
 
824
882
  /**
825
- * The async lock instance with default settings.
883
+ * Creates a token provider from the provided shared access data.
884
+ * @param data - The sharedAccessKeyName/sharedAccessKey pair or the sharedAccessSignature.
885
+ * @hidden
886
+ */
887
+ export declare function createSasTokenProvider(data: {
888
+ sharedAccessKeyName: string;
889
+ sharedAccessKey: string;
890
+ } | {
891
+ sharedAccessSignature: string;
892
+ } | NamedKeyCredential | SASCredential): SasTokenProvider;
893
+
894
+ /**
895
+ * The cancellable async lock instance.
826
896
  */
827
- export declare const defaultLock: AsyncLock;
897
+ export declare const defaultCancellableLock: CancellableAsyncLock;
828
898
 
829
899
  /**
830
900
  * A wrapper for setTimeout that resolves a promise after t milliseconds.
@@ -1040,6 +1110,13 @@ export declare enum ErrorNameConditionMapper {
1040
1110
  */
1041
1111
  export declare function isMessagingError(error: Error | MessagingError): error is MessagingError;
1042
1112
 
1113
+ /**
1114
+ * Typeguard that checks if the input is a SasTokenProvider.
1115
+ * @param thing - Any object.
1116
+ * @hidden
1117
+ */
1118
+ export declare function isSasTokenProvider(thing: unknown): thing is SasTokenProvider;
1119
+
1043
1120
  /**
1044
1121
  * Checks whether the provided error is a node.js SystemError.
1045
1122
  * @param err - An object that may contain error information.
@@ -1282,7 +1359,8 @@ export declare enum RetryOperationType {
1282
1359
  senderLink = "senderLink",
1283
1360
  sendMessage = "sendMessage",
1284
1361
  receiveMessage = "receiveMessage",
1285
- session = "session"
1362
+ session = "session",
1363
+ messageSettlement = "settlement"
1286
1364
  }
1287
1365
 
1288
1366
  /**
@@ -1317,6 +1395,25 @@ export declare interface RetryOptions {
1317
1395
  maxRetryDelayInMs?: number;
1318
1396
  }
1319
1397
 
1398
+ /**
1399
+ * A SasTokenProvider provides an alternative to TokenCredential for providing an `AccessToken`.
1400
+ * @hidden
1401
+ */
1402
+ export declare interface SasTokenProvider {
1403
+ /**
1404
+ * Property used to distinguish SasTokenProvider from TokenCredential.
1405
+ */
1406
+ isSasTokenProvider: true;
1407
+ /**
1408
+ * Gets the token provided by this provider.
1409
+ *
1410
+ * This method is called automatically by Azure SDK client libraries.
1411
+ *
1412
+ * @param audience - The audience for which the token is desired.
1413
+ */
1414
+ getToken(audience: string): AccessToken;
1415
+ }
1416
+
1320
1417
  /**
1321
1418
  * Describes the options that can be specified while sending a request.
1322
1419
  */
@@ -1336,6 +1433,12 @@ export declare interface SendRequestOptions {
1336
1433
  requestName?: string;
1337
1434
  }
1338
1435
 
1436
+ /**
1437
+ * The standard error message accompanying an AbortError.
1438
+ * @hidden
1439
+ */
1440
+ export declare const StandardAbortMessage = "The operation was aborted.";
1441
+
1339
1442
  /**
1340
1443
  * Maps some SystemErrors to amqp error conditions
1341
1444
  */