@azure/storage-queue 12.20.0-alpha.20230615.1 → 12.20.0-alpha.20230616.2

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.
@@ -2,13 +2,12 @@
2
2
  // Licensed under the MIT license.
3
3
  import { isTokenCredential } from "@azure/core-auth";
4
4
  import { isNode } from "@azure/core-util";
5
- import { SpanStatusCode } from "@azure/core-tracing";
6
5
  import { newPipeline, Pipeline } from "../../storage-blob/src/Pipeline";
7
6
  import { StorageClient, getStorageClientContext } from "./StorageClient";
8
7
  import { appendToURLPath, extractConnectionStringParts, isIpEndpointStyle, truncatedISO8061Date, appendToURLQuery, assertResponse, } from "./utils/utils.common";
9
8
  import { StorageSharedKeyCredential } from "../../storage-blob/src/credentials/StorageSharedKeyCredential";
10
9
  import { AnonymousCredential } from "../../storage-blob/src/credentials/AnonymousCredential";
11
- import { createSpan } from "./utils/tracing";
10
+ import { tracingClient } from "./utils/tracing";
12
11
  import { generateQueueSASQueryParameters } from "./QueueSASSignatureValues";
13
12
  import { getDefaultProxySettings } from "@azure/core-rest-pipeline";
14
13
  /**
@@ -111,20 +110,9 @@ export class QueueClient extends StorageClient {
111
110
  * ```
112
111
  */
113
112
  async create(options = {}) {
114
- const { span, updatedOptions } = createSpan("QueueClient-create", options);
115
- try {
113
+ return tracingClient.withSpan("QueueClient-create", options, async (updatedOptions) => {
116
114
  return assertResponse(await this.queueContext.create(updatedOptions));
117
- }
118
- catch (e) {
119
- span.setStatus({
120
- code: SpanStatusCode.ERROR,
121
- message: e.message,
122
- });
123
- throw e;
124
- }
125
- finally {
126
- span.end();
127
- }
115
+ });
128
116
  }
129
117
  /**
130
118
  * Creates a new queue under the specified account if it doesn't already exist.
@@ -134,35 +122,25 @@ export class QueueClient extends StorageClient {
134
122
  * @param options -
135
123
  */
136
124
  async createIfNotExists(options = {}) {
137
- var _a, _b;
138
- const { span, updatedOptions } = createSpan("QueueClient-createIfNotExists", options);
139
- try {
140
- const response = await this.create(updatedOptions);
141
- // When a queue with the specified name already exists, the Queue service checks the metadata associated with the existing queue.
142
- // If the existing metadata is identical to the metadata specified on the Create Queue request, status code 204 (No Content) is returned.
143
- // If the existing metadata does not match, the operation fails and status code 409 (Conflict) is returned.
144
- if (response._response.status === 204) {
145
- return Object.assign({ succeeded: false }, response);
125
+ return tracingClient.withSpan("QueueClient-createIfNotExists", options, async (updatedOptions) => {
126
+ var _a, _b;
127
+ try {
128
+ const response = await this.create(updatedOptions);
129
+ // When a queue with the specified name already exists, the Queue service checks the metadata associated with the existing queue.
130
+ // If the existing metadata is identical to the metadata specified on the Create Queue request, status code 204 (No Content) is returned.
131
+ // If the existing metadata does not match, the operation fails and status code 409 (Conflict) is returned.
132
+ if (response._response.status === 204) {
133
+ return Object.assign({ succeeded: false }, response);
134
+ }
135
+ return Object.assign({ succeeded: true }, response);
146
136
  }
147
- return Object.assign({ succeeded: true }, response);
148
- }
149
- catch (e) {
150
- if (((_a = e.details) === null || _a === void 0 ? void 0 : _a.errorCode) === "QueueAlreadyExists") {
151
- span.setStatus({
152
- code: SpanStatusCode.ERROR,
153
- message: "Expected exception when creating a queue only if it does not already exist.",
154
- });
155
- return Object.assign(Object.assign({ succeeded: false }, (_b = e.response) === null || _b === void 0 ? void 0 : _b.parsedHeaders), { _response: e.response });
137
+ catch (e) {
138
+ if (((_a = e.details) === null || _a === void 0 ? void 0 : _a.errorCode) === "QueueAlreadyExists") {
139
+ return Object.assign(Object.assign({ succeeded: false }, (_b = e.response) === null || _b === void 0 ? void 0 : _b.parsedHeaders), { _response: e.response });
140
+ }
141
+ throw e;
156
142
  }
157
- span.setStatus({
158
- code: SpanStatusCode.ERROR,
159
- message: e.message,
160
- });
161
- throw e;
162
- }
163
- finally {
164
- span.end();
165
- }
143
+ });
166
144
  }
167
145
  /**
168
146
  * Deletes the specified queue permanently if it exists.
@@ -171,29 +149,19 @@ export class QueueClient extends StorageClient {
171
149
  * @param options -
172
150
  */
173
151
  async deleteIfExists(options = {}) {
174
- var _a, _b;
175
- const { span, updatedOptions } = createSpan("QueueClient-deleteIfExists", options);
176
- try {
177
- const res = await this.delete(updatedOptions);
178
- return Object.assign({ succeeded: true }, res);
179
- }
180
- catch (e) {
181
- if (((_a = e.details) === null || _a === void 0 ? void 0 : _a.errorCode) === "QueueNotFound") {
182
- span.setStatus({
183
- code: SpanStatusCode.ERROR,
184
- message: "Expected exception when deleting a queue only if it exists.",
185
- });
186
- return Object.assign(Object.assign({ succeeded: false }, (_b = e.response) === null || _b === void 0 ? void 0 : _b.parsedHeaders), { _response: e.response });
152
+ return tracingClient.withSpan("QueueClient-deleteIfExists", options, async (updatedOptions) => {
153
+ var _a, _b;
154
+ try {
155
+ const res = await this.delete(updatedOptions);
156
+ return Object.assign({ succeeded: true }, res);
187
157
  }
188
- span.setStatus({
189
- code: SpanStatusCode.ERROR,
190
- message: e.message,
191
- });
192
- throw e;
193
- }
194
- finally {
195
- span.end();
196
- }
158
+ catch (e) {
159
+ if (((_a = e.details) === null || _a === void 0 ? void 0 : _a.errorCode) === "QueueNotFound") {
160
+ return Object.assign(Object.assign({ succeeded: false }, (_b = e.response) === null || _b === void 0 ? void 0 : _b.parsedHeaders), { _response: e.response });
161
+ }
162
+ throw e;
163
+ }
164
+ });
197
165
  }
198
166
  /**
199
167
  * Deletes the specified queue permanently.
@@ -212,23 +180,12 @@ export class QueueClient extends StorageClient {
212
180
  * ```
213
181
  */
214
182
  async delete(options = {}) {
215
- const { span, updatedOptions } = createSpan("QueueClient-delete", options);
216
- try {
183
+ return tracingClient.withSpan("QueueClient-delete", options, async (updatedOptions) => {
217
184
  return assertResponse(await this.queueContext.delete({
218
185
  abortSignal: options.abortSignal,
219
186
  tracingOptions: updatedOptions.tracingOptions,
220
187
  }));
221
- }
222
- catch (e) {
223
- span.setStatus({
224
- code: SpanStatusCode.ERROR,
225
- message: e.message,
226
- });
227
- throw e;
228
- }
229
- finally {
230
- span.end();
231
- }
188
+ });
232
189
  }
233
190
  /**
234
191
  * Returns true if the specified queue exists; false otherwise.
@@ -240,31 +197,18 @@ export class QueueClient extends StorageClient {
240
197
  * @param options - options to Exists operation.
241
198
  */
242
199
  async exists(options = {}) {
243
- const { span, updatedOptions } = createSpan("QueueClient-exists", options);
244
- try {
245
- await this.getProperties({
246
- abortSignal: options.abortSignal,
247
- tracingOptions: updatedOptions.tracingOptions,
248
- });
249
- return true;
250
- }
251
- catch (e) {
252
- if (e.statusCode === 404) {
253
- span.setStatus({
254
- code: SpanStatusCode.ERROR,
255
- message: "Expected exception when checking queue existence",
256
- });
257
- return false;
200
+ return tracingClient.withSpan("QueueClient-exists", options, async (updatedOptions) => {
201
+ try {
202
+ await this.getProperties(updatedOptions);
203
+ return true;
258
204
  }
259
- span.setStatus({
260
- code: SpanStatusCode.ERROR,
261
- message: e.message,
262
- });
263
- throw e;
264
- }
265
- finally {
266
- span.end();
267
- }
205
+ catch (e) {
206
+ if (e.statusCode === 404) {
207
+ return false;
208
+ }
209
+ throw e;
210
+ }
211
+ });
268
212
  }
269
213
  /**
270
214
  * Gets all user-defined metadata and system properties for the specified
@@ -280,23 +224,9 @@ export class QueueClient extends StorageClient {
280
224
  * @returns Response data for the Queue get properties operation.
281
225
  */
282
226
  async getProperties(options = {}) {
283
- const { span, updatedOptions } = createSpan("QueueClient-getProperties", options);
284
- try {
285
- return assertResponse(await this.queueContext.getProperties({
286
- abortSignal: options.abortSignal,
287
- tracingOptions: updatedOptions.tracingOptions,
288
- }));
289
- }
290
- catch (e) {
291
- span.setStatus({
292
- code: SpanStatusCode.ERROR,
293
- message: e.message,
294
- });
295
- throw e;
296
- }
297
- finally {
298
- span.end();
299
- }
227
+ return tracingClient.withSpan("QueueClient-getProperties", options, async (updatedOptions) => {
228
+ return assertResponse(await this.queueContext.getProperties(updatedOptions));
229
+ });
300
230
  }
301
231
  /**
302
232
  * Sets one or more user-defined name-value pairs for the specified queue.
@@ -310,24 +240,9 @@ export class QueueClient extends StorageClient {
310
240
  * @returns Response data for the Queue set metadata operation.
311
241
  */
312
242
  async setMetadata(metadata, options = {}) {
313
- const { span, updatedOptions } = createSpan("QueueClient-setMetadata", options);
314
- try {
315
- return assertResponse(await this.queueContext.setMetadata({
316
- abortSignal: options.abortSignal,
317
- metadata,
318
- tracingOptions: updatedOptions.tracingOptions,
319
- }));
320
- }
321
- catch (e) {
322
- span.setStatus({
323
- code: SpanStatusCode.ERROR,
324
- message: e.message,
325
- });
326
- throw e;
327
- }
328
- finally {
329
- span.end();
330
- }
243
+ return tracingClient.withSpan("QueueClient-setMetadata", options, async (updatedOptions) => {
244
+ return assertResponse(await this.queueContext.setMetadata(Object.assign(Object.assign({}, updatedOptions), { metadata })));
245
+ });
331
246
  }
332
247
  /**
333
248
  * Gets details about any stored access policies specified on the queue that may be used with Shared Access Signatures.
@@ -341,8 +256,7 @@ export class QueueClient extends StorageClient {
341
256
  * @returns Response data for the Queue get access policy operation.
342
257
  */
343
258
  async getAccessPolicy(options = {}) {
344
- const { span, updatedOptions } = createSpan("QueueClient-getAccessPolicy", options);
345
- try {
259
+ return tracingClient.withSpan("QueueClient-getAccessPolicy", options, async (updatedOptions) => {
346
260
  const response = assertResponse(await this.queueContext.getAccessPolicy({
347
261
  abortSignal: options.abortSignal,
348
262
  tracingOptions: updatedOptions.tracingOptions,
@@ -375,17 +289,7 @@ export class QueueClient extends StorageClient {
375
289
  });
376
290
  }
377
291
  return res;
378
- }
379
- catch (e) {
380
- span.setStatus({
381
- code: SpanStatusCode.ERROR,
382
- message: e.message,
383
- });
384
- throw e;
385
- }
386
- finally {
387
- span.end();
388
- }
292
+ });
389
293
  }
390
294
  /**
391
295
  * Sets stored access policies for the queue that may be used with Shared Access Signatures.
@@ -396,8 +300,7 @@ export class QueueClient extends StorageClient {
396
300
  * @returns Response data for the Queue set access policy operation.
397
301
  */
398
302
  async setAccessPolicy(queueAcl, options = {}) {
399
- const { span, updatedOptions } = createSpan("QueueClient-setAccessPolicy", options);
400
- try {
303
+ return tracingClient.withSpan("QueueClient-setAccessPolicy", options, async (updatedOptions) => {
401
304
  const acl = [];
402
305
  for (const identifier of queueAcl || []) {
403
306
  acl.push({
@@ -413,22 +316,8 @@ export class QueueClient extends StorageClient {
413
316
  id: identifier.id,
414
317
  });
415
318
  }
416
- return assertResponse(await this.queueContext.setAccessPolicy({
417
- abortSignal: options.abortSignal,
418
- queueAcl: acl,
419
- tracingOptions: updatedOptions.tracingOptions,
420
- }));
421
- }
422
- catch (e) {
423
- span.setStatus({
424
- code: SpanStatusCode.ERROR,
425
- message: e.message,
426
- });
427
- throw e;
428
- }
429
- finally {
430
- span.end();
431
- }
319
+ return assertResponse(await this.queueContext.setAccessPolicy(Object.assign(Object.assign({}, updatedOptions), { queueAcl: acl })));
320
+ });
432
321
  }
433
322
  /**
434
323
  * Clear deletes all messages from a queue.
@@ -438,23 +327,9 @@ export class QueueClient extends StorageClient {
438
327
  * @returns Response data for the clear messages operation.
439
328
  */
440
329
  async clearMessages(options = {}) {
441
- const { span, updatedOptions } = createSpan("QueueClient-clearMessages", options);
442
- try {
443
- return assertResponse(await this.messagesContext.clear({
444
- abortSignal: options.abortSignal,
445
- tracingOptions: updatedOptions.tracingOptions,
446
- }));
447
- }
448
- catch (e) {
449
- span.setStatus({
450
- code: SpanStatusCode.ERROR,
451
- message: e.message,
452
- });
453
- throw e;
454
- }
455
- finally {
456
- span.end();
457
- }
330
+ return tracingClient.withSpan("QueueClient-clearMessages", options, async (updatedOptions) => {
331
+ return assertResponse(await this.messagesContext.clear(updatedOptions));
332
+ });
458
333
  }
459
334
  /**
460
335
  * sendMessage adds a new message to the back of a queue. The visibility timeout specifies how long
@@ -478,8 +353,7 @@ export class QueueClient extends StorageClient {
478
353
  * ```
479
354
  */
480
355
  async sendMessage(messageText, options = {}) {
481
- const { span, updatedOptions } = createSpan("QueueClient-sendMessage", options);
482
- try {
356
+ return tracingClient.withSpan("QueueClient-sendMessage", options, async (updatedOptions) => {
483
357
  const response = assertResponse(await this.messagesContext.enqueue({
484
358
  messageText: messageText,
485
359
  }, updatedOptions));
@@ -497,17 +371,7 @@ export class QueueClient extends StorageClient {
497
371
  insertedOn: item.insertedOn,
498
372
  expiresOn: item.expiresOn,
499
373
  };
500
- }
501
- catch (e) {
502
- span.setStatus({
503
- code: SpanStatusCode.ERROR,
504
- message: e.message,
505
- });
506
- throw e;
507
- }
508
- finally {
509
- span.end();
510
- }
374
+ });
511
375
  }
512
376
  /**
513
377
  * receiveMessages retrieves one or more messages from the front of the queue.
@@ -535,8 +399,7 @@ export class QueueClient extends StorageClient {
535
399
  * ```
536
400
  */
537
401
  async receiveMessages(options = {}) {
538
- const { span, updatedOptions } = createSpan("QueueClient-receiveMessages", options);
539
- try {
402
+ return tracingClient.withSpan("QueueClient-receiveMessages", options, async (updatedOptions) => {
540
403
  const response = assertResponse(await this.messagesContext.dequeue(updatedOptions));
541
404
  const res = {
542
405
  _response: response._response,
@@ -551,17 +414,7 @@ export class QueueClient extends StorageClient {
551
414
  res.receivedMessageItems.push(item);
552
415
  }
553
416
  return res;
554
- }
555
- catch (e) {
556
- span.setStatus({
557
- code: SpanStatusCode.ERROR,
558
- message: e.message,
559
- });
560
- throw e;
561
- }
562
- finally {
563
- span.end();
564
- }
417
+ });
565
418
  }
566
419
  /**
567
420
  * peekMessages retrieves one or more messages from the front of the queue but does not alter the visibility of the message.
@@ -578,8 +431,7 @@ export class QueueClient extends StorageClient {
578
431
  * ```
579
432
  */
580
433
  async peekMessages(options = {}) {
581
- const { span, updatedOptions } = createSpan("QueueClient-peekMessages", options);
582
- try {
434
+ return tracingClient.withSpan("QueueClient-peekMessages", options, async (updatedOptions) => {
583
435
  const response = assertResponse(await this.messagesContext.peek(updatedOptions));
584
436
  const res = {
585
437
  _response: response._response,
@@ -594,17 +446,7 @@ export class QueueClient extends StorageClient {
594
446
  res.peekedMessageItems.push(item);
595
447
  }
596
448
  return res;
597
- }
598
- catch (e) {
599
- span.setStatus({
600
- code: SpanStatusCode.ERROR,
601
- message: e.message,
602
- });
603
- throw e;
604
- }
605
- finally {
606
- span.end();
607
- }
449
+ });
608
450
  }
609
451
  /**
610
452
  * deleteMessage permanently removes the specified message from its queue.
@@ -616,23 +458,9 @@ export class QueueClient extends StorageClient {
616
458
  * @returns Response data for the delete message operation.
617
459
  */
618
460
  async deleteMessage(messageId, popReceipt, options = {}) {
619
- const { span, updatedOptions } = createSpan("QueueClient-deleteMessage", options);
620
- try {
621
- return assertResponse(await this.getMessageIdContext(messageId).delete(popReceipt, {
622
- abortSignal: options.abortSignal,
623
- tracingOptions: updatedOptions.tracingOptions,
624
- }));
625
- }
626
- catch (e) {
627
- span.setStatus({
628
- code: SpanStatusCode.ERROR,
629
- message: e.message,
630
- });
631
- throw e;
632
- }
633
- finally {
634
- span.end();
635
- }
461
+ return tracingClient.withSpan("QueueClient-deleteMessage", options, async (updatedOptions) => {
462
+ return assertResponse(await this.getMessageIdContext(messageId).delete(popReceipt, updatedOptions));
463
+ });
636
464
  }
637
465
  /**
638
466
  * Update changes a message's visibility timeout and contents.
@@ -652,28 +480,17 @@ export class QueueClient extends StorageClient {
652
480
  * @returns Response data for the update message operation.
653
481
  */
654
482
  async updateMessage(messageId, popReceipt, message, visibilityTimeout, options = {}) {
655
- const { span, updatedOptions } = createSpan("QueueClient-updateMessage", options);
656
- let queueMessage = undefined;
657
- if (message !== undefined) {
658
- queueMessage = { messageText: message };
659
- }
660
- try {
483
+ return tracingClient.withSpan("QueueClient-updateMessage", options, async (updatedOptions) => {
484
+ let queueMessage = undefined;
485
+ if (message !== undefined) {
486
+ queueMessage = { messageText: message };
487
+ }
661
488
  return assertResponse(await this.getMessageIdContext(messageId).update(popReceipt, visibilityTimeout || 0, {
662
489
  abortSignal: options.abortSignal,
663
490
  tracingOptions: updatedOptions.tracingOptions,
664
491
  queueMessage,
665
492
  }));
666
- }
667
- catch (e) {
668
- span.setStatus({
669
- code: SpanStatusCode.ERROR,
670
- message: e.message,
671
- });
672
- throw e;
673
- }
674
- finally {
675
- span.end();
676
- }
493
+ });
677
494
  }
678
495
  getQueueNameFromUrl() {
679
496
  let queueName;