@azure/storage-queue 12.29.0 → 12.30.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Pipeline.d.ts +2 -3
- package/dist/browser/Pipeline.d.ts.map +1 -1
- package/dist/browser/Pipeline.js.map +1 -1
- package/dist/browser/QueueClient.d.ts +2 -1
- package/dist/browser/QueueClient.d.ts.map +1 -1
- package/dist/browser/QueueClient.js.map +1 -1
- package/dist/browser/QueueSASSignatureValues.d.ts +2 -1
- package/dist/browser/QueueSASSignatureValues.d.ts.map +1 -1
- package/dist/browser/QueueSASSignatureValues.js +2 -2
- package/dist/browser/QueueSASSignatureValues.js.map +1 -1
- package/dist/browser/QueueServiceClient.d.ts +28 -0
- package/dist/browser/QueueServiceClient.d.ts.map +1 -1
- package/dist/browser/QueueServiceClient.js +21 -13
- package/dist/browser/QueueServiceClient.js.map +1 -1
- package/dist/browser/SASQueryParameters.d.ts +6 -1
- package/dist/browser/SASQueryParameters.d.ts.map +1 -1
- package/dist/browser/SASQueryParameters.js +10 -0
- package/dist/browser/SASQueryParameters.js.map +1 -1
- package/dist/browser/generated/src/models/index.d.ts +4 -0
- package/dist/browser/generated/src/models/index.d.ts.map +1 -1
- package/dist/browser/generated/src/models/index.js.map +1 -1
- package/dist/browser/generated/src/models/mappers.d.ts.map +1 -1
- package/dist/browser/generated/src/models/mappers.js +14 -0
- package/dist/browser/generated/src/models/mappers.js.map +1 -1
- package/dist/browser/generated/src/models/parameters.js +1 -1
- package/dist/browser/generated/src/models/parameters.js.map +1 -1
- package/dist/browser/generated/src/storageClient.js +2 -2
- package/dist/browser/generated/src/storageClient.js.map +1 -1
- package/dist/browser/generatedModels.d.ts +2 -2
- package/dist/browser/generatedModels.d.ts.map +1 -1
- package/dist/browser/generatedModels.js.map +1 -1
- package/dist/browser/index.d.ts +8 -8
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +1 -2
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/utils/constants.d.ts.map +1 -1
- package/dist/browser/utils/constants.js +2 -2
- package/dist/browser/utils/constants.js.map +1 -1
- package/dist/commonjs/AccountSASPermissions.js +133 -126
- package/dist/commonjs/AccountSASPermissions.js.map +7 -1
- package/dist/commonjs/AccountSASResourceTypes.js +80 -70
- package/dist/commonjs/AccountSASResourceTypes.js.map +7 -1
- package/dist/commonjs/AccountSASServices.js +88 -78
- package/dist/commonjs/AccountSASServices.js.map +7 -1
- package/dist/commonjs/AccountSASSignatureValues.js +91 -72
- package/dist/commonjs/AccountSASSignatureValues.js.map +7 -1
- package/dist/commonjs/Pipeline.d.ts +2 -3
- package/dist/commonjs/Pipeline.d.ts.map +1 -1
- package/dist/commonjs/Pipeline.js +244 -244
- package/dist/commonjs/Pipeline.js.map +7 -1
- package/dist/commonjs/QueueClient.d.ts +2 -1
- package/dist/commonjs/QueueClient.d.ts.map +1 -1
- package/dist/commonjs/QueueClient.js +710 -683
- package/dist/commonjs/QueueClient.js.map +7 -1
- package/dist/commonjs/QueueSASPermissions.js +90 -80
- package/dist/commonjs/QueueSASPermissions.js.map +7 -1
- package/dist/commonjs/QueueSASSignatureValues.d.ts +2 -1
- package/dist/commonjs/QueueSASSignatureValues.d.ts.map +1 -1
- package/dist/commonjs/QueueSASSignatureValues.js +151 -111
- package/dist/commonjs/QueueSASSignatureValues.js.map +7 -1
- package/dist/commonjs/QueueServiceClient.d.ts +28 -0
- package/dist/commonjs/QueueServiceClient.d.ts.map +1 -1
- package/dist/commonjs/QueueServiceClient.js +532 -472
- package/dist/commonjs/QueueServiceClient.js.map +7 -1
- package/dist/commonjs/SASQueryParameters.d.ts +6 -1
- package/dist/commonjs/SASQueryParameters.d.ts.map +1 -1
- package/dist/commonjs/SASQueryParameters.js +308 -267
- package/dist/commonjs/SASQueryParameters.js.map +7 -1
- package/dist/commonjs/SasIPRange.js +27 -14
- package/dist/commonjs/SasIPRange.js.map +7 -1
- package/dist/commonjs/StorageClient.js +75 -65
- package/dist/commonjs/StorageClient.js.map +7 -1
- package/dist/commonjs/StorageContextClient.js +34 -20
- package/dist/commonjs/StorageContextClient.js.map +7 -1
- package/dist/commonjs/generated/src/index.js +32 -16
- package/dist/commonjs/generated/src/index.js.map +7 -1
- package/dist/commonjs/generated/src/models/index.d.ts +4 -0
- package/dist/commonjs/generated/src/models/index.d.ts.map +1 -1
- package/dist/commonjs/generated/src/models/index.js +86 -129
- package/dist/commonjs/generated/src/models/index.js.map +7 -1
- package/dist/commonjs/generated/src/models/mappers.d.ts.map +1 -1
- package/dist/commonjs/generated/src/models/mappers.js +1947 -1817
- package/dist/commonjs/generated/src/models/mappers.js.map +7 -1
- package/dist/commonjs/generated/src/models/parameters.js +378 -305
- package/dist/commonjs/generated/src/models/parameters.js.map +7 -1
- package/dist/commonjs/generated/src/operations/index.js +27 -15
- package/dist/commonjs/generated/src/operations/index.js.map +7 -1
- package/dist/commonjs/generated/src/operations/messageId.js +130 -99
- package/dist/commonjs/generated/src/operations/messageId.js.map +7 -1
- package/dist/commonjs/generated/src/operations/messages.js +213 -185
- package/dist/commonjs/generated/src/operations/messages.js.map +7 -1
- package/dist/commonjs/generated/src/operations/queue.js +243 -206
- package/dist/commonjs/generated/src/operations/queue.js.map +7 -1
- package/dist/commonjs/generated/src/operations/service.js +239 -199
- package/dist/commonjs/generated/src/operations/service.js.map +7 -1
- package/dist/commonjs/generated/src/operationsInterfaces/index.js +27 -15
- package/dist/commonjs/generated/src/operationsInterfaces/index.js.map +7 -1
- package/dist/commonjs/generated/src/operationsInterfaces/messageId.js +15 -10
- package/dist/commonjs/generated/src/operationsInterfaces/messageId.js.map +7 -1
- package/dist/commonjs/generated/src/operationsInterfaces/messages.js +15 -10
- package/dist/commonjs/generated/src/operationsInterfaces/messages.js.map +7 -1
- package/dist/commonjs/generated/src/operationsInterfaces/queue.js +15 -10
- package/dist/commonjs/generated/src/operationsInterfaces/queue.js.map +7 -1
- package/dist/commonjs/generated/src/operationsInterfaces/service.js +15 -10
- package/dist/commonjs/generated/src/operationsInterfaces/service.js.map +7 -1
- package/dist/commonjs/generated/src/storageClient.js +77 -59
- package/dist/commonjs/generated/src/storageClient.js.map +7 -1
- package/dist/commonjs/generatedModels.d.ts +2 -2
- package/dist/commonjs/generatedModels.d.ts.map +1 -1
- package/dist/commonjs/generatedModels.js +15 -5
- package/dist/commonjs/generatedModels.js.map +7 -1
- package/dist/commonjs/index.d.ts +9 -9
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +88 -43
- package/dist/commonjs/index.js.map +7 -1
- package/dist/commonjs/log.js +28 -11
- package/dist/commonjs/log.js.map +7 -1
- package/dist/commonjs/models.js +33 -21
- package/dist/commonjs/models.js.map +7 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/utils/constants.d.ts.map +1 -1
- package/dist/commonjs/utils/constants.js +151 -114
- package/dist/commonjs/utils/constants.js.map +7 -1
- package/dist/commonjs/utils/tracing.js +32 -16
- package/dist/commonjs/utils/tracing.js.map +7 -1
- package/dist/commonjs/utils/utils.common.js +242 -338
- package/dist/commonjs/utils/utils.common.js.map +7 -1
- package/dist/esm/AccountSASPermissions.js +111 -123
- package/dist/esm/AccountSASPermissions.js.map +7 -1
- package/dist/esm/AccountSASResourceTypes.js +58 -67
- package/dist/esm/AccountSASResourceTypes.js.map +7 -1
- package/dist/esm/AccountSASServices.js +66 -75
- package/dist/esm/AccountSASServices.js.map +7 -1
- package/dist/esm/AccountSASSignatureValues.js +62 -63
- package/dist/esm/AccountSASSignatureValues.js.map +7 -1
- package/dist/esm/Pipeline.d.ts +2 -3
- package/dist/esm/Pipeline.d.ts.map +1 -1
- package/dist/esm/Pipeline.js +239 -239
- package/dist/esm/Pipeline.js.map +7 -1
- package/dist/esm/QueueClient.d.ts +2 -1
- package/dist/esm/QueueClient.d.ts.map +1 -1
- package/dist/esm/QueueClient.js +689 -671
- package/dist/esm/QueueClient.js.map +7 -1
- package/dist/esm/QueueSASPermissions.js +68 -77
- package/dist/esm/QueueSASPermissions.js.map +7 -1
- package/dist/esm/QueueSASSignatureValues.d.ts +2 -1
- package/dist/esm/QueueSASSignatureValues.d.ts.map +1 -1
- package/dist/esm/QueueSASSignatureValues.js +124 -104
- package/dist/esm/QueueSASSignatureValues.js.map +7 -1
- package/dist/esm/QueueServiceClient.d.ts +28 -0
- package/dist/esm/QueueServiceClient.d.ts.map +1 -1
- package/dist/esm/QueueServiceClient.js +507 -457
- package/dist/esm/QueueServiceClient.js.map +7 -1
- package/dist/esm/SASQueryParameters.d.ts +6 -1
- package/dist/esm/SASQueryParameters.d.ts.map +1 -1
- package/dist/esm/SASQueryParameters.js +283 -262
- package/dist/esm/SASQueryParameters.js.map +7 -1
- package/dist/esm/SasIPRange.js +5 -12
- package/dist/esm/SasIPRange.js.map +7 -1
- package/dist/esm/StorageClient.js +50 -59
- package/dist/esm/StorageClient.js.map +7 -1
- package/dist/esm/StorageContextClient.js +10 -15
- package/dist/esm/StorageContextClient.js.map +7 -1
- package/dist/esm/generated/src/index.js +4 -9
- package/dist/esm/generated/src/index.js.map +7 -1
- package/dist/esm/generated/src/models/index.d.ts +4 -0
- package/dist/esm/generated/src/models/index.d.ts.map +1 -1
- package/dist/esm/generated/src/models/index.js +63 -126
- package/dist/esm/generated/src/models/index.js.map +7 -1
- package/dist/esm/generated/src/models/mappers.d.ts.map +1 -1
- package/dist/esm/generated/src/models/mappers.js +1873 -1813
- package/dist/esm/generated/src/models/mappers.js.map +7 -1
- package/dist/esm/generated/src/models/parameters.js +330 -302
- package/dist/esm/generated/src/models/parameters.js.map +7 -1
- package/dist/esm/generated/src/operations/index.js +0 -8
- package/dist/esm/generated/src/operations/index.js.map +7 -1
- package/dist/esm/generated/src/operations/messageId.js +95 -92
- package/dist/esm/generated/src/operations/messageId.js.map +7 -1
- package/dist/esm/generated/src/operations/messages.js +178 -178
- package/dist/esm/generated/src/operations/messages.js.map +7 -1
- package/dist/esm/generated/src/operations/queue.js +208 -199
- package/dist/esm/generated/src/operations/queue.js.map +7 -1
- package/dist/esm/generated/src/operations/service.js +204 -192
- package/dist/esm/generated/src/operations/service.js.map +7 -1
- package/dist/esm/generated/src/operationsInterfaces/index.js +0 -8
- package/dist/esm/generated/src/operationsInterfaces/index.js.map +7 -1
- package/dist/esm/generated/src/operationsInterfaces/messageId.js +0 -9
- package/dist/esm/generated/src/operationsInterfaces/messageId.js.map +7 -1
- package/dist/esm/generated/src/operationsInterfaces/messages.js +0 -9
- package/dist/esm/generated/src/operationsInterfaces/messages.js.map +7 -1
- package/dist/esm/generated/src/operationsInterfaces/queue.js +0 -9
- package/dist/esm/generated/src/operationsInterfaces/queue.js.map +7 -1
- package/dist/esm/generated/src/operationsInterfaces/service.js +0 -9
- package/dist/esm/generated/src/operationsInterfaces/service.js.map +7 -1
- package/dist/esm/generated/src/storageClient.js +49 -54
- package/dist/esm/generated/src/storageClient.js.map +7 -1
- package/dist/esm/generatedModels.d.ts +2 -2
- package/dist/esm/generatedModels.d.ts.map +1 -1
- package/dist/esm/generatedModels.js +0 -4
- package/dist/esm/generatedModels.js.map +7 -1
- package/dist/esm/index.d.ts +9 -9
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +50 -11
- package/dist/esm/index.js.map +7 -1
- package/dist/esm/log.js +4 -7
- package/dist/esm/log.js.map +7 -1
- package/dist/esm/models.js +10 -18
- package/dist/esm/models.js.map +7 -1
- package/dist/esm/utils/constants.d.ts.map +1 -1
- package/dist/esm/utils/constants.js +117 -111
- package/dist/esm/utils/constants.js.map +7 -1
- package/dist/esm/utils/tracing.js +7 -11
- package/dist/esm/utils/tracing.js.map +7 -1
- package/dist/esm/utils/utils.common.js +247 -358
- package/dist/esm/utils/utils.common.js.map +7 -1
- package/dist/react-native/Pipeline.d.ts +2 -3
- package/dist/react-native/Pipeline.d.ts.map +1 -1
- package/dist/react-native/Pipeline.js.map +1 -1
- package/dist/react-native/QueueClient.d.ts +2 -1
- package/dist/react-native/QueueClient.d.ts.map +1 -1
- package/dist/react-native/QueueClient.js.map +1 -1
- package/dist/react-native/QueueSASSignatureValues.d.ts +2 -1
- package/dist/react-native/QueueSASSignatureValues.d.ts.map +1 -1
- package/dist/react-native/QueueSASSignatureValues.js +2 -2
- package/dist/react-native/QueueSASSignatureValues.js.map +1 -1
- package/dist/react-native/QueueServiceClient.d.ts +28 -0
- package/dist/react-native/QueueServiceClient.d.ts.map +1 -1
- package/dist/react-native/QueueServiceClient.js +21 -13
- package/dist/react-native/QueueServiceClient.js.map +1 -1
- package/dist/react-native/SASQueryParameters.d.ts +6 -1
- package/dist/react-native/SASQueryParameters.d.ts.map +1 -1
- package/dist/react-native/SASQueryParameters.js +10 -0
- package/dist/react-native/SASQueryParameters.js.map +1 -1
- package/dist/react-native/generated/src/models/index.d.ts +4 -0
- package/dist/react-native/generated/src/models/index.d.ts.map +1 -1
- package/dist/react-native/generated/src/models/index.js.map +1 -1
- package/dist/react-native/generated/src/models/mappers.d.ts.map +1 -1
- package/dist/react-native/generated/src/models/mappers.js +14 -0
- package/dist/react-native/generated/src/models/mappers.js.map +1 -1
- package/dist/react-native/generated/src/models/parameters.js +1 -1
- package/dist/react-native/generated/src/models/parameters.js.map +1 -1
- package/dist/react-native/generated/src/storageClient.js +2 -2
- package/dist/react-native/generated/src/storageClient.js.map +1 -1
- package/dist/react-native/generatedModels.d.ts +2 -2
- package/dist/react-native/generatedModels.d.ts.map +1 -1
- package/dist/react-native/generatedModels.js.map +1 -1
- package/dist/react-native/index.d.ts +9 -9
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +0 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/utils/constants.d.ts.map +1 -1
- package/dist/react-native/utils/constants.js +2 -2
- package/dist/react-native/utils/constants.js.map +1 -1
- package/package.json +2 -19
- package/dist/browser/index-browser.d.mts.map +0 -1
- package/dist/browser/index-browser.mjs.map +0 -1
package/dist/esm/QueueClient.js
CHANGED
|
@@ -1,694 +1,712 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
1
|
import { isTokenCredential } from "@azure/core-auth";
|
|
4
2
|
import { isNode } from "@azure/core-util";
|
|
5
3
|
import { newPipeline, isPipelineLike } from "./Pipeline.js";
|
|
6
4
|
import { StorageClient, getStorageClientContext } from "./StorageClient.js";
|
|
7
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
appendToURLPath,
|
|
7
|
+
extractConnectionStringParts,
|
|
8
|
+
isIpEndpointStyle,
|
|
9
|
+
truncatedISO8061Date,
|
|
10
|
+
appendToURLQuery,
|
|
11
|
+
assertResponse
|
|
12
|
+
} from "./utils/utils.common.js";
|
|
8
13
|
import { StorageSharedKeyCredential } from "@azure/storage-common";
|
|
9
14
|
import { AnonymousCredential } from "@azure/storage-common";
|
|
10
15
|
import { tracingClient } from "./utils/tracing.js";
|
|
11
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
generateQueueSASQueryParameters,
|
|
18
|
+
generateQueueSASQueryParametersInternal
|
|
19
|
+
} from "./QueueSASSignatureValues.js";
|
|
12
20
|
import { getDefaultProxySettings } from "@azure/core-rest-pipeline";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
else if (credentialOrPipelineOrQueueName &&
|
|
60
|
-
typeof credentialOrPipelineOrQueueName === "string") {
|
|
61
|
-
// (connectionString: string, containerName: string, queueName: string, options?: StoragePipelineOptions)
|
|
62
|
-
const extractedCreds = extractConnectionStringParts(urlOrConnectionString);
|
|
63
|
-
if (extractedCreds.kind === "AccountConnString") {
|
|
64
|
-
if (isNode) {
|
|
65
|
-
const queueName = credentialOrPipelineOrQueueName;
|
|
66
|
-
const sharedKeyCredential = new StorageSharedKeyCredential(extractedCreds.accountName, extractedCreds.accountKey);
|
|
67
|
-
url = appendToURLPath(extractedCreds.url, queueName);
|
|
68
|
-
if (!options.proxyOptions) {
|
|
69
|
-
options.proxyOptions = getDefaultProxySettings(extractedCreds.proxyUri);
|
|
70
|
-
}
|
|
71
|
-
pipeline = newPipeline(sharedKeyCredential, options);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new Error("Account connection string is only supported in Node.js environment");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else if (extractedCreds.kind === "SASConnString") {
|
|
78
|
-
const queueName = credentialOrPipelineOrQueueName;
|
|
79
|
-
url = appendToURLPath(extractedCreds.url, queueName) + "?" + extractedCreds.accountSas;
|
|
80
|
-
pipeline = newPipeline(new AnonymousCredential(), options);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
throw new Error("Connection string must be either an Account connection string or a SAS connection string");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
throw new Error("Expecting non-empty strings for queueName parameter");
|
|
21
|
+
class QueueClient extends StorageClient {
|
|
22
|
+
/**
|
|
23
|
+
* messagesContext provided by protocol layer.
|
|
24
|
+
*/
|
|
25
|
+
messagesContext;
|
|
26
|
+
/**
|
|
27
|
+
* queueContext provided by protocol layer.
|
|
28
|
+
*/
|
|
29
|
+
queueContext;
|
|
30
|
+
_name;
|
|
31
|
+
_messagesUrl;
|
|
32
|
+
/**
|
|
33
|
+
* The name of the queue.
|
|
34
|
+
*/
|
|
35
|
+
get name() {
|
|
36
|
+
return this._name;
|
|
37
|
+
}
|
|
38
|
+
constructor(urlOrConnectionString, credentialOrPipelineOrQueueName, options) {
|
|
39
|
+
options = options || {};
|
|
40
|
+
let pipeline;
|
|
41
|
+
let url;
|
|
42
|
+
if (isPipelineLike(credentialOrPipelineOrQueueName)) {
|
|
43
|
+
url = urlOrConnectionString;
|
|
44
|
+
pipeline = credentialOrPipelineOrQueueName;
|
|
45
|
+
} else if (isNode && credentialOrPipelineOrQueueName instanceof StorageSharedKeyCredential || credentialOrPipelineOrQueueName instanceof AnonymousCredential || isTokenCredential(credentialOrPipelineOrQueueName)) {
|
|
46
|
+
url = urlOrConnectionString;
|
|
47
|
+
pipeline = newPipeline(credentialOrPipelineOrQueueName, options);
|
|
48
|
+
} else if (!credentialOrPipelineOrQueueName && typeof credentialOrPipelineOrQueueName !== "string") {
|
|
49
|
+
url = urlOrConnectionString;
|
|
50
|
+
pipeline = newPipeline(new AnonymousCredential(), options);
|
|
51
|
+
} else if (credentialOrPipelineOrQueueName && typeof credentialOrPipelineOrQueueName === "string") {
|
|
52
|
+
const extractedCreds = extractConnectionStringParts(urlOrConnectionString);
|
|
53
|
+
if (extractedCreds.kind === "AccountConnString") {
|
|
54
|
+
if (isNode) {
|
|
55
|
+
const queueName = credentialOrPipelineOrQueueName;
|
|
56
|
+
const sharedKeyCredential = new StorageSharedKeyCredential(
|
|
57
|
+
extractedCreds.accountName,
|
|
58
|
+
extractedCreds.accountKey
|
|
59
|
+
);
|
|
60
|
+
url = appendToURLPath(extractedCreds.url, queueName);
|
|
61
|
+
if (!options.proxyOptions) {
|
|
62
|
+
options.proxyOptions = getDefaultProxySettings(extractedCreds.proxyUri);
|
|
63
|
+
}
|
|
64
|
+
pipeline = newPipeline(sharedKeyCredential, options);
|
|
65
|
+
} else {
|
|
66
|
+
throw new Error("Account connection string is only supported in Node.js environment");
|
|
88
67
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
getMessageIdContext(messageId) {
|
|
101
|
-
// Build the url with messageId
|
|
102
|
-
const partsOfUrl = this._messagesUrl.split("?");
|
|
103
|
-
const urlWithMessageId = partsOfUrl[1]
|
|
104
|
-
? appendToURLPath(partsOfUrl[0], messageId) + "?" + partsOfUrl[1]
|
|
105
|
-
: appendToURLPath(partsOfUrl[0], messageId);
|
|
106
|
-
return getStorageClientContext(urlWithMessageId, this.pipeline).messageId;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Creates a new queue under the specified account.
|
|
110
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/create-queue4
|
|
111
|
-
*
|
|
112
|
-
* @param options - Options to Queue create operation.
|
|
113
|
-
* @returns Response data for the Queue create operation.
|
|
114
|
-
*
|
|
115
|
-
* Example usage:
|
|
116
|
-
*
|
|
117
|
-
* ```ts snippet:ReadmeSampleCreateQueue
|
|
118
|
-
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
119
|
-
* import { DefaultAzureCredential } from "@azure/identity";
|
|
120
|
-
*
|
|
121
|
-
* const account = "<account>";
|
|
122
|
-
* const queueServiceClient = new QueueServiceClient(
|
|
123
|
-
* `https://${account}.queue.core.windows.net`,
|
|
124
|
-
* new DefaultAzureCredential(),
|
|
125
|
-
* );
|
|
126
|
-
*
|
|
127
|
-
* const queueName = "<valid queue name>";
|
|
128
|
-
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
129
|
-
* const createQueueResponse = await queueClient.create();
|
|
130
|
-
* console.log(
|
|
131
|
-
* `Created queue ${queueName} successfully, service assigned request Id: ${createQueueResponse.requestId}`,
|
|
132
|
-
* );
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
async create(options = {}) {
|
|
136
|
-
return tracingClient.withSpan("QueueClient-create", options, async (updatedOptions) => {
|
|
137
|
-
return assertResponse(await this.queueContext.create(updatedOptions));
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Creates a new queue under the specified account if it doesn't already exist.
|
|
142
|
-
* If the queue already exists, it is not changed.
|
|
143
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/create-queue4
|
|
144
|
-
*
|
|
145
|
-
* @param options -
|
|
146
|
-
*/
|
|
147
|
-
async createIfNotExists(options = {}) {
|
|
148
|
-
return tracingClient.withSpan("QueueClient-createIfNotExists", options, async (updatedOptions) => {
|
|
149
|
-
try {
|
|
150
|
-
const response = await this.create(updatedOptions);
|
|
151
|
-
// When a queue with the specified name already exists, the Queue service checks the metadata associated with the existing queue.
|
|
152
|
-
// If the existing metadata is identical to the metadata specified on the Create Queue request, status code 204 (No Content) is returned.
|
|
153
|
-
// If the existing metadata does not match, the operation fails and status code 409 (Conflict) is returned.
|
|
154
|
-
if (response._response.status === 204) {
|
|
155
|
-
return {
|
|
156
|
-
succeeded: false,
|
|
157
|
-
...response,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
succeeded: true,
|
|
162
|
-
...response,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
catch (e) {
|
|
166
|
-
if (e.details?.errorCode === "QueueAlreadyExists") {
|
|
167
|
-
return {
|
|
168
|
-
succeeded: false,
|
|
169
|
-
...e.response?.parsedHeaders,
|
|
170
|
-
_response: e.response,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
throw e;
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Deletes the specified queue permanently if it exists.
|
|
179
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/delete-queue3
|
|
180
|
-
*
|
|
181
|
-
* @param options -
|
|
182
|
-
*/
|
|
183
|
-
async deleteIfExists(options = {}) {
|
|
184
|
-
return tracingClient.withSpan("QueueClient-deleteIfExists", options, async (updatedOptions) => {
|
|
185
|
-
try {
|
|
186
|
-
const res = await this.delete(updatedOptions);
|
|
187
|
-
return {
|
|
188
|
-
succeeded: true,
|
|
189
|
-
...res,
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
catch (e) {
|
|
193
|
-
if (e.details?.errorCode === "QueueNotFound") {
|
|
194
|
-
return {
|
|
195
|
-
succeeded: false,
|
|
196
|
-
...e.response?.parsedHeaders,
|
|
197
|
-
_response: e.response,
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
throw e;
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Deletes the specified queue permanently.
|
|
206
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/delete-queue3
|
|
207
|
-
*
|
|
208
|
-
* @param options - Options to Queue delete operation.
|
|
209
|
-
* @returns Response data for the Queue delete operation.
|
|
210
|
-
*
|
|
211
|
-
* Example usage:
|
|
212
|
-
*
|
|
213
|
-
* ```ts snippet:ReadmeSampleDeleteQueue
|
|
214
|
-
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
215
|
-
* import { DefaultAzureCredential } from "@azure/identity";
|
|
216
|
-
*
|
|
217
|
-
* const account = "<account>";
|
|
218
|
-
* const queueServiceClient = new QueueServiceClient(
|
|
219
|
-
* `https://${account}.queue.core.windows.net`,
|
|
220
|
-
* new DefaultAzureCredential(),
|
|
221
|
-
* );
|
|
222
|
-
*
|
|
223
|
-
* const queueName = "<valid queue name>";
|
|
224
|
-
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
225
|
-
* const deleteQueueResponse = await queueClient.delete();
|
|
226
|
-
* console.log(
|
|
227
|
-
* `Deleted queue successfully, service assigned request Id: ${deleteQueueResponse.requestId}`,
|
|
228
|
-
* );
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
async delete(options = {}) {
|
|
232
|
-
return tracingClient.withSpan("QueueClient-delete", options, async (updatedOptions) => {
|
|
233
|
-
return assertResponse(await this.queueContext.delete({
|
|
234
|
-
abortSignal: options.abortSignal,
|
|
235
|
-
tracingOptions: updatedOptions.tracingOptions,
|
|
236
|
-
}));
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Returns true if the specified queue exists; false otherwise.
|
|
241
|
-
*
|
|
242
|
-
* NOTE: use this function with care since an existing queue might be deleted by other clients or
|
|
243
|
-
* applications. Vice versa new queues might be added by other clients or applications after this
|
|
244
|
-
* function completes.
|
|
245
|
-
*
|
|
246
|
-
* @param options - options to Exists operation.
|
|
247
|
-
*/
|
|
248
|
-
async exists(options = {}) {
|
|
249
|
-
return tracingClient.withSpan("QueueClient-exists", options, async (updatedOptions) => {
|
|
250
|
-
try {
|
|
251
|
-
await this.getProperties(updatedOptions);
|
|
252
|
-
return true;
|
|
253
|
-
}
|
|
254
|
-
catch (e) {
|
|
255
|
-
if (e.statusCode === 404) {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
throw e;
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Gets all user-defined metadata and system properties for the specified
|
|
264
|
-
* queue. Metadata is associated with the queue as name-values pairs.
|
|
265
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/get-queue-metadata
|
|
266
|
-
*
|
|
267
|
-
* WARNING: The `metadata` object returned in the response will have its keys in lowercase, even if
|
|
268
|
-
* they originally contained uppercase characters. This differs from the metadata keys returned by
|
|
269
|
-
* the `listQueues` method of {@link QueueServiceClient} using the `includeMetadata` option, which
|
|
270
|
-
* will retain their original casing.
|
|
271
|
-
*
|
|
272
|
-
* @param options - Options to Queue get properties operation.
|
|
273
|
-
* @returns Response data for the Queue get properties operation.
|
|
274
|
-
*/
|
|
275
|
-
async getProperties(options = {}) {
|
|
276
|
-
return tracingClient.withSpan("QueueClient-getProperties", options, async (updatedOptions) => {
|
|
277
|
-
return assertResponse(await this.queueContext.getProperties(updatedOptions));
|
|
278
|
-
});
|
|
68
|
+
} else if (extractedCreds.kind === "SASConnString") {
|
|
69
|
+
const queueName = credentialOrPipelineOrQueueName;
|
|
70
|
+
url = appendToURLPath(extractedCreds.url, queueName) + "?" + extractedCreds.accountSas;
|
|
71
|
+
pipeline = newPipeline(new AnonymousCredential(), options);
|
|
72
|
+
} else {
|
|
73
|
+
throw new Error(
|
|
74
|
+
"Connection string must be either an Account connection string or a SAS connection string"
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error("Expecting non-empty strings for queueName parameter");
|
|
279
79
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
return res;
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Sets stored access policies for the queue that may be used with Shared Access Signatures.
|
|
348
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/set-queue-acl
|
|
349
|
-
*
|
|
350
|
-
* @param queueAcl -
|
|
351
|
-
* @param options - Options to Queue set access policy operation.
|
|
352
|
-
* @returns Response data for the Queue set access policy operation.
|
|
353
|
-
*/
|
|
354
|
-
async setAccessPolicy(queueAcl, options = {}) {
|
|
355
|
-
return tracingClient.withSpan("QueueClient-setAccessPolicy", options, async (updatedOptions) => {
|
|
356
|
-
const acl = [];
|
|
357
|
-
for (const identifier of queueAcl || []) {
|
|
358
|
-
acl.push({
|
|
359
|
-
accessPolicy: {
|
|
360
|
-
expiresOn: identifier.accessPolicy.expiresOn
|
|
361
|
-
? truncatedISO8061Date(identifier.accessPolicy.expiresOn)
|
|
362
|
-
: undefined,
|
|
363
|
-
permissions: identifier.accessPolicy.permissions,
|
|
364
|
-
startsOn: identifier.accessPolicy.startsOn
|
|
365
|
-
? truncatedISO8061Date(identifier.accessPolicy.startsOn)
|
|
366
|
-
: undefined,
|
|
367
|
-
},
|
|
368
|
-
id: identifier.id,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
return assertResponse(await this.queueContext.setAccessPolicy({
|
|
372
|
-
...updatedOptions,
|
|
373
|
-
queueAcl: acl,
|
|
374
|
-
}));
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Clear deletes all messages from a queue.
|
|
379
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/clear-messages
|
|
380
|
-
*
|
|
381
|
-
* @param options - Options to clear messages operation.
|
|
382
|
-
* @returns Response data for the clear messages operation.
|
|
383
|
-
*/
|
|
384
|
-
async clearMessages(options = {}) {
|
|
385
|
-
return tracingClient.withSpan("QueueClient-clearMessages", options, async (updatedOptions) => {
|
|
386
|
-
return assertResponse(await this.messagesContext.clear(updatedOptions));
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* sendMessage adds a new message to the back of a queue. The visibility timeout specifies how long
|
|
391
|
-
* the message should be invisible to Dequeue and Peek operations.
|
|
392
|
-
* The message content is up to 64KB in size, and must be in a format that can be included in an XML request with UTF-8 encoding.
|
|
393
|
-
* To include markup in the message, the contents of the message must either be XML-escaped or Base64-encode.
|
|
394
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/put-message
|
|
395
|
-
*
|
|
396
|
-
* @param messageText - Text of the message to send
|
|
397
|
-
* @param options - Options to send messages operation.
|
|
398
|
-
* @returns Response data for the send messages operation.
|
|
399
|
-
*
|
|
400
|
-
* Example usage:
|
|
401
|
-
*
|
|
402
|
-
* ```ts snippet:ReadmeSampleSendMessage
|
|
403
|
-
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
404
|
-
* import { DefaultAzureCredential } from "@azure/identity";
|
|
405
|
-
*
|
|
406
|
-
* const account = "<account>";
|
|
407
|
-
* const queueServiceClient = new QueueServiceClient(
|
|
408
|
-
* `https://${account}.queue.core.windows.net`,
|
|
409
|
-
* new DefaultAzureCredential(),
|
|
410
|
-
* );
|
|
411
|
-
*
|
|
412
|
-
* const queueName = "<valid queue name>";
|
|
413
|
-
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
414
|
-
* // Send a message into the queue using the sendMessage method.
|
|
415
|
-
* const sendMessageResponse = await queueClient.sendMessage("Hello World!");
|
|
416
|
-
* console.log(
|
|
417
|
-
* `Sent message successfully, service assigned message Id: ${sendMessageResponse.messageId}, service assigned request Id: ${sendMessageResponse.requestId}`,
|
|
418
|
-
* );
|
|
419
|
-
* ```
|
|
420
|
-
*/
|
|
421
|
-
async sendMessage(messageText, options = {}) {
|
|
422
|
-
return tracingClient.withSpan("QueueClient-sendMessage", options, async (updatedOptions) => {
|
|
423
|
-
const response = assertResponse(await this.messagesContext.enqueue({
|
|
424
|
-
messageText: messageText,
|
|
425
|
-
}, updatedOptions));
|
|
426
|
-
const item = response[0];
|
|
80
|
+
super(url, pipeline);
|
|
81
|
+
this._name = this.getQueueNameFromUrl();
|
|
82
|
+
this.queueContext = this.storageClientContext.queue;
|
|
83
|
+
const partsOfUrl = this.url.split("?");
|
|
84
|
+
this._messagesUrl = partsOfUrl[1] ? appendToURLPath(partsOfUrl[0], "messages") + "?" + partsOfUrl[1] : appendToURLPath(partsOfUrl[0], "messages");
|
|
85
|
+
this.messagesContext = getStorageClientContext(this._messagesUrl, this.pipeline).messages;
|
|
86
|
+
}
|
|
87
|
+
getMessageIdContext(messageId) {
|
|
88
|
+
const partsOfUrl = this._messagesUrl.split("?");
|
|
89
|
+
const urlWithMessageId = partsOfUrl[1] ? appendToURLPath(partsOfUrl[0], messageId) + "?" + partsOfUrl[1] : appendToURLPath(partsOfUrl[0], messageId);
|
|
90
|
+
return getStorageClientContext(urlWithMessageId, this.pipeline).messageId;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Creates a new queue under the specified account.
|
|
94
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/create-queue4
|
|
95
|
+
*
|
|
96
|
+
* @param options - Options to Queue create operation.
|
|
97
|
+
* @returns Response data for the Queue create operation.
|
|
98
|
+
*
|
|
99
|
+
* Example usage:
|
|
100
|
+
*
|
|
101
|
+
* ```ts snippet:ReadmeSampleCreateQueue
|
|
102
|
+
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
103
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
104
|
+
*
|
|
105
|
+
* const account = "<account>";
|
|
106
|
+
* const queueServiceClient = new QueueServiceClient(
|
|
107
|
+
* `https://${account}.queue.core.windows.net`,
|
|
108
|
+
* new DefaultAzureCredential(),
|
|
109
|
+
* );
|
|
110
|
+
*
|
|
111
|
+
* const queueName = "<valid queue name>";
|
|
112
|
+
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
113
|
+
* const createQueueResponse = await queueClient.create();
|
|
114
|
+
* console.log(
|
|
115
|
+
* `Created queue ${queueName} successfully, service assigned request Id: ${createQueueResponse.requestId}`,
|
|
116
|
+
* );
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
async create(options = {}) {
|
|
120
|
+
return tracingClient.withSpan("QueueClient-create", options, async (updatedOptions) => {
|
|
121
|
+
return assertResponse(
|
|
122
|
+
await this.queueContext.create(updatedOptions)
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new queue under the specified account if it doesn't already exist.
|
|
128
|
+
* If the queue already exists, it is not changed.
|
|
129
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/create-queue4
|
|
130
|
+
*
|
|
131
|
+
* @param options -
|
|
132
|
+
*/
|
|
133
|
+
async createIfNotExists(options = {}) {
|
|
134
|
+
return tracingClient.withSpan(
|
|
135
|
+
"QueueClient-createIfNotExists",
|
|
136
|
+
options,
|
|
137
|
+
async (updatedOptions) => {
|
|
138
|
+
try {
|
|
139
|
+
const response = await this.create(updatedOptions);
|
|
140
|
+
if (response._response.status === 204) {
|
|
427
141
|
return {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
requestId: response.requestId,
|
|
431
|
-
clientRequestId: response.clientRequestId,
|
|
432
|
-
version: response.version,
|
|
433
|
-
errorCode: response.errorCode,
|
|
434
|
-
messageId: item.messageId,
|
|
435
|
-
popReceipt: item.popReceipt,
|
|
436
|
-
nextVisibleOn: item.nextVisibleOn,
|
|
437
|
-
insertedOn: item.insertedOn,
|
|
438
|
-
expiresOn: item.expiresOn,
|
|
142
|
+
succeeded: false,
|
|
143
|
+
...response
|
|
439
144
|
};
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
* ```ts snippet:ReadmeSampleReceiveMessage
|
|
452
|
-
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
453
|
-
* import { DefaultAzureCredential } from "@azure/identity";
|
|
454
|
-
*
|
|
455
|
-
* const account = "<account>";
|
|
456
|
-
* const queueServiceClient = new QueueServiceClient(
|
|
457
|
-
* `https://${account}.queue.core.windows.net`,
|
|
458
|
-
* new DefaultAzureCredential(),
|
|
459
|
-
* );
|
|
460
|
-
*
|
|
461
|
-
* const queueName = "<valid queue name>";
|
|
462
|
-
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
463
|
-
* const response = await queueClient.receiveMessages();
|
|
464
|
-
* if (response.receivedMessageItems.length === 1) {
|
|
465
|
-
* const receivedMessageItem = response.receivedMessageItems[0];
|
|
466
|
-
* console.log(`Processing & deleting message with content: ${receivedMessageItem.messageText}`);
|
|
467
|
-
* const deleteMessageResponse = await queueClient.deleteMessage(
|
|
468
|
-
* receivedMessageItem.messageId,
|
|
469
|
-
* receivedMessageItem.popReceipt,
|
|
470
|
-
* );
|
|
471
|
-
* console.log(
|
|
472
|
-
* `Delete message successfully, service assigned request Id: ${deleteMessageResponse.requestId}`,
|
|
473
|
-
* );
|
|
474
|
-
* }
|
|
475
|
-
* ```
|
|
476
|
-
*/
|
|
477
|
-
async receiveMessages(options = {}) {
|
|
478
|
-
return tracingClient.withSpan("QueueClient-receiveMessages", options, async (updatedOptions) => {
|
|
479
|
-
const response = assertResponse(await this.messagesContext.dequeue(updatedOptions));
|
|
480
|
-
const res = {
|
|
481
|
-
_response: response._response,
|
|
482
|
-
date: response.date,
|
|
483
|
-
requestId: response.requestId,
|
|
484
|
-
clientRequestId: response.clientRequestId,
|
|
485
|
-
receivedMessageItems: [],
|
|
486
|
-
version: response.version,
|
|
487
|
-
errorCode: response.errorCode,
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
succeeded: true,
|
|
148
|
+
...response
|
|
149
|
+
};
|
|
150
|
+
} catch (e) {
|
|
151
|
+
if (e.details?.errorCode === "QueueAlreadyExists") {
|
|
152
|
+
return {
|
|
153
|
+
succeeded: false,
|
|
154
|
+
...e.response?.parsedHeaders,
|
|
155
|
+
_response: e.response
|
|
488
156
|
};
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
157
|
+
}
|
|
158
|
+
throw e;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Deletes the specified queue permanently if it exists.
|
|
165
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/delete-queue3
|
|
166
|
+
*
|
|
167
|
+
* @param options -
|
|
168
|
+
*/
|
|
169
|
+
async deleteIfExists(options = {}) {
|
|
170
|
+
return tracingClient.withSpan("QueueClient-deleteIfExists", options, async (updatedOptions) => {
|
|
171
|
+
try {
|
|
172
|
+
const res = await this.delete(updatedOptions);
|
|
173
|
+
return {
|
|
174
|
+
succeeded: true,
|
|
175
|
+
...res
|
|
176
|
+
};
|
|
177
|
+
} catch (e) {
|
|
178
|
+
if (e.details?.errorCode === "QueueNotFound") {
|
|
179
|
+
return {
|
|
180
|
+
succeeded: false,
|
|
181
|
+
...e.response?.parsedHeaders,
|
|
182
|
+
_response: e.response
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
throw e;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Deletes the specified queue permanently.
|
|
191
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/delete-queue3
|
|
192
|
+
*
|
|
193
|
+
* @param options - Options to Queue delete operation.
|
|
194
|
+
* @returns Response data for the Queue delete operation.
|
|
195
|
+
*
|
|
196
|
+
* Example usage:
|
|
197
|
+
*
|
|
198
|
+
* ```ts snippet:ReadmeSampleDeleteQueue
|
|
199
|
+
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
200
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
201
|
+
*
|
|
202
|
+
* const account = "<account>";
|
|
203
|
+
* const queueServiceClient = new QueueServiceClient(
|
|
204
|
+
* `https://${account}.queue.core.windows.net`,
|
|
205
|
+
* new DefaultAzureCredential(),
|
|
206
|
+
* );
|
|
207
|
+
*
|
|
208
|
+
* const queueName = "<valid queue name>";
|
|
209
|
+
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
210
|
+
* const deleteQueueResponse = await queueClient.delete();
|
|
211
|
+
* console.log(
|
|
212
|
+
* `Deleted queue successfully, service assigned request Id: ${deleteQueueResponse.requestId}`,
|
|
213
|
+
* );
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
async delete(options = {}) {
|
|
217
|
+
return tracingClient.withSpan("QueueClient-delete", options, async (updatedOptions) => {
|
|
218
|
+
return assertResponse(
|
|
219
|
+
await this.queueContext.delete({
|
|
220
|
+
abortSignal: options.abortSignal,
|
|
221
|
+
tracingOptions: updatedOptions.tracingOptions
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Returns true if the specified queue exists; false otherwise.
|
|
228
|
+
*
|
|
229
|
+
* NOTE: use this function with care since an existing queue might be deleted by other clients or
|
|
230
|
+
* applications. Vice versa new queues might be added by other clients or applications after this
|
|
231
|
+
* function completes.
|
|
232
|
+
*
|
|
233
|
+
* @param options - options to Exists operation.
|
|
234
|
+
*/
|
|
235
|
+
async exists(options = {}) {
|
|
236
|
+
return tracingClient.withSpan("QueueClient-exists", options, async (updatedOptions) => {
|
|
237
|
+
try {
|
|
238
|
+
await this.getProperties(updatedOptions);
|
|
239
|
+
return true;
|
|
240
|
+
} catch (e) {
|
|
241
|
+
if (e.statusCode === 404) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
throw e;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Gets all user-defined metadata and system properties for the specified
|
|
250
|
+
* queue. Metadata is associated with the queue as name-values pairs.
|
|
251
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/get-queue-metadata
|
|
252
|
+
*
|
|
253
|
+
* WARNING: The `metadata` object returned in the response will have its keys in lowercase, even if
|
|
254
|
+
* they originally contained uppercase characters. This differs from the metadata keys returned by
|
|
255
|
+
* the `listQueues` method of {@link QueueServiceClient} using the `includeMetadata` option, which
|
|
256
|
+
* will retain their original casing.
|
|
257
|
+
*
|
|
258
|
+
* @param options - Options to Queue get properties operation.
|
|
259
|
+
* @returns Response data for the Queue get properties operation.
|
|
260
|
+
*/
|
|
261
|
+
async getProperties(options = {}) {
|
|
262
|
+
return tracingClient.withSpan("QueueClient-getProperties", options, async (updatedOptions) => {
|
|
263
|
+
return assertResponse(
|
|
264
|
+
await this.queueContext.getProperties(updatedOptions)
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Sets one or more user-defined name-value pairs for the specified queue.
|
|
270
|
+
*
|
|
271
|
+
* If no option provided, or no metadata defined in the option parameter, the queue
|
|
272
|
+
* metadata will be removed.
|
|
273
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/set-queue-metadata
|
|
274
|
+
*
|
|
275
|
+
* @param metadata - If no metadata provided, all existing metadata will be removed.
|
|
276
|
+
* @param options - Options to Queue set metadata operation.
|
|
277
|
+
* @returns Response data for the Queue set metadata operation.
|
|
278
|
+
*/
|
|
279
|
+
async setMetadata(metadata, options = {}) {
|
|
280
|
+
return tracingClient.withSpan("QueueClient-setMetadata", options, async (updatedOptions) => {
|
|
281
|
+
return assertResponse(
|
|
282
|
+
await this.queueContext.setMetadata({
|
|
283
|
+
...updatedOptions,
|
|
284
|
+
metadata
|
|
285
|
+
})
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Gets details about any stored access policies specified on the queue that may be used with Shared Access Signatures.
|
|
291
|
+
*
|
|
292
|
+
* WARNING: JavaScript Date will potential lost precision when parsing start and expiry string.
|
|
293
|
+
* For example, new Date("2018-12-31T03:44:23.8827891Z").toISOString() will get "2018-12-31T03:44:23.882Z".
|
|
294
|
+
*
|
|
295
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/get-queue-acl
|
|
296
|
+
*
|
|
297
|
+
* @param options - Options to Queue get access policy operation.
|
|
298
|
+
* @returns Response data for the Queue get access policy operation.
|
|
299
|
+
*/
|
|
300
|
+
async getAccessPolicy(options = {}) {
|
|
301
|
+
return tracingClient.withSpan(
|
|
302
|
+
"QueueClient-getAccessPolicy",
|
|
303
|
+
options,
|
|
304
|
+
async (updatedOptions) => {
|
|
305
|
+
const response = assertResponse(
|
|
306
|
+
await this.queueContext.getAccessPolicy({
|
|
307
|
+
abortSignal: options.abortSignal,
|
|
308
|
+
tracingOptions: updatedOptions.tracingOptions
|
|
309
|
+
})
|
|
310
|
+
);
|
|
311
|
+
const res = {
|
|
312
|
+
_response: response._response,
|
|
313
|
+
date: response.date,
|
|
314
|
+
requestId: response.requestId,
|
|
315
|
+
clientRequestId: response.clientRequestId,
|
|
316
|
+
signedIdentifiers: [],
|
|
317
|
+
version: response.version,
|
|
318
|
+
errorCode: response.errorCode
|
|
319
|
+
};
|
|
320
|
+
for (const identifier of response) {
|
|
321
|
+
let accessPolicy = void 0;
|
|
322
|
+
if (identifier.accessPolicy) {
|
|
323
|
+
accessPolicy = {
|
|
324
|
+
permissions: identifier.accessPolicy.permissions
|
|
531
325
|
};
|
|
532
|
-
|
|
533
|
-
|
|
326
|
+
if (identifier.accessPolicy.expiresOn) {
|
|
327
|
+
accessPolicy.expiresOn = new Date(identifier.accessPolicy.expiresOn);
|
|
534
328
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* deleteMessage permanently removes the specified message from its queue.
|
|
540
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/delete-message2
|
|
541
|
-
*
|
|
542
|
-
* @param messageId - Id of the message.
|
|
543
|
-
* @param popReceipt - A valid pop receipt value returned from an earlier call to the receive messages or update message operation.
|
|
544
|
-
* @param options - Options to delete message operation.
|
|
545
|
-
* @returns Response data for the delete message operation.
|
|
546
|
-
*/
|
|
547
|
-
async deleteMessage(messageId, popReceipt, options = {}) {
|
|
548
|
-
return tracingClient.withSpan("QueueClient-deleteMessage", options, async (updatedOptions) => {
|
|
549
|
-
return assertResponse(await this.getMessageIdContext(messageId).delete(popReceipt, updatedOptions));
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
/**
|
|
553
|
-
* Update changes a message's visibility timeout and contents.
|
|
554
|
-
* The message content is up to 64KB in size, and must be in a format that can be included in an XML request with UTF-8 encoding.
|
|
555
|
-
* To include markup in the message, the contents of the message must either be XML-escaped or Base64-encode.
|
|
556
|
-
* @see https://learn.microsoft.com/rest/api/storageservices/update-message
|
|
557
|
-
*
|
|
558
|
-
* @param messageId - Id of the message
|
|
559
|
-
* @param popReceipt - A valid pop receipt value returned from an earlier call to the receive messages or update message operation.
|
|
560
|
-
* @param message - Message to update. If this parameter is undefined, then the content of the message won't be updated.
|
|
561
|
-
* @param visibilityTimeout - Specifies the new visibility timeout value, in seconds,
|
|
562
|
-
* relative to server time. The new value must be larger than or equal to 0,
|
|
563
|
-
* and cannot be larger than 7 days. The visibility timeout of a message cannot
|
|
564
|
-
* be set to a value later than the expiry time.
|
|
565
|
-
* A message can be updated until it has been deleted or has expired.
|
|
566
|
-
* @param options - Options to update message operation.
|
|
567
|
-
* @returns Response data for the update message operation.
|
|
568
|
-
*/
|
|
569
|
-
async updateMessage(messageId, popReceipt, message, visibilityTimeout, options = {}) {
|
|
570
|
-
return tracingClient.withSpan("QueueClient-updateMessage", options, async (updatedOptions) => {
|
|
571
|
-
let queueMessage = undefined;
|
|
572
|
-
if (message !== undefined) {
|
|
573
|
-
queueMessage = { messageText: message };
|
|
574
|
-
}
|
|
575
|
-
return assertResponse(await this.getMessageIdContext(messageId).update(popReceipt, visibilityTimeout || 0, {
|
|
576
|
-
abortSignal: options.abortSignal,
|
|
577
|
-
tracingOptions: updatedOptions.tracingOptions,
|
|
578
|
-
queueMessage,
|
|
579
|
-
}));
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
getQueueNameFromUrl() {
|
|
583
|
-
let queueName;
|
|
584
|
-
try {
|
|
585
|
-
// URL may look like the following
|
|
586
|
-
// "https://myaccount.queue.core.windows.net/myqueue?sasString".
|
|
587
|
-
// "https://myaccount.queue.core.windows.net/myqueue".
|
|
588
|
-
// IPv4/IPv6 address hosts, Endpoints - `http://127.0.0.1:10001/devstoreaccount1/myqueue`
|
|
589
|
-
// http://localhost:10001/devstoreaccount1/queuename
|
|
590
|
-
const parsedUrl = new URL(this.url);
|
|
591
|
-
if (parsedUrl.hostname.split(".")[1] === "queue") {
|
|
592
|
-
// "https://myaccount.queue.core.windows.net/queuename".
|
|
593
|
-
// .getPath() -> /queuename
|
|
594
|
-
queueName = parsedUrl.pathname.split("/")[1];
|
|
595
|
-
}
|
|
596
|
-
else if (isIpEndpointStyle(parsedUrl)) {
|
|
597
|
-
// IPv4/IPv6 address hosts... Example - http://192.0.0.10:10001/devstoreaccount1/queuename
|
|
598
|
-
// Single word domain without a [dot] in the endpoint... Example - http://localhost:10001/devstoreaccount1/queuename
|
|
599
|
-
// .getPath() -> /devstoreaccount1/queuename
|
|
600
|
-
queueName = parsedUrl.pathname.split("/")[2];
|
|
329
|
+
if (identifier.accessPolicy.startsOn) {
|
|
330
|
+
accessPolicy.startsOn = new Date(identifier.accessPolicy.startsOn);
|
|
601
331
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
if (!queueName) {
|
|
608
|
-
throw new Error("Provided queueName is invalid.");
|
|
609
|
-
}
|
|
610
|
-
return queueName;
|
|
332
|
+
}
|
|
333
|
+
res.signedIdentifiers.push({
|
|
334
|
+
accessPolicy,
|
|
335
|
+
id: identifier.id
|
|
336
|
+
});
|
|
611
337
|
}
|
|
612
|
-
|
|
613
|
-
|
|
338
|
+
return res;
|
|
339
|
+
}
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Sets stored access policies for the queue that may be used with Shared Access Signatures.
|
|
344
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/set-queue-acl
|
|
345
|
+
*
|
|
346
|
+
* @param queueAcl -
|
|
347
|
+
* @param options - Options to Queue set access policy operation.
|
|
348
|
+
* @returns Response data for the Queue set access policy operation.
|
|
349
|
+
*/
|
|
350
|
+
async setAccessPolicy(queueAcl, options = {}) {
|
|
351
|
+
return tracingClient.withSpan(
|
|
352
|
+
"QueueClient-setAccessPolicy",
|
|
353
|
+
options,
|
|
354
|
+
async (updatedOptions) => {
|
|
355
|
+
const acl = [];
|
|
356
|
+
for (const identifier of queueAcl || []) {
|
|
357
|
+
acl.push({
|
|
358
|
+
accessPolicy: {
|
|
359
|
+
expiresOn: identifier.accessPolicy.expiresOn ? truncatedISO8061Date(identifier.accessPolicy.expiresOn) : void 0,
|
|
360
|
+
permissions: identifier.accessPolicy.permissions,
|
|
361
|
+
startsOn: identifier.accessPolicy.startsOn ? truncatedISO8061Date(identifier.accessPolicy.startsOn) : void 0
|
|
362
|
+
},
|
|
363
|
+
id: identifier.id
|
|
364
|
+
});
|
|
614
365
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
366
|
+
return assertResponse(
|
|
367
|
+
await this.queueContext.setAccessPolicy({
|
|
368
|
+
...updatedOptions,
|
|
369
|
+
queueAcl: acl
|
|
370
|
+
})
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Clear deletes all messages from a queue.
|
|
377
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/clear-messages
|
|
378
|
+
*
|
|
379
|
+
* @param options - Options to clear messages operation.
|
|
380
|
+
* @returns Response data for the clear messages operation.
|
|
381
|
+
*/
|
|
382
|
+
async clearMessages(options = {}) {
|
|
383
|
+
return tracingClient.withSpan("QueueClient-clearMessages", options, async (updatedOptions) => {
|
|
384
|
+
return assertResponse(
|
|
385
|
+
await this.messagesContext.clear(updatedOptions)
|
|
386
|
+
);
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* sendMessage adds a new message to the back of a queue. The visibility timeout specifies how long
|
|
391
|
+
* the message should be invisible to Dequeue and Peek operations.
|
|
392
|
+
* The message content is up to 64KB in size, and must be in a format that can be included in an XML request with UTF-8 encoding.
|
|
393
|
+
* To include markup in the message, the contents of the message must either be XML-escaped or Base64-encode.
|
|
394
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/put-message
|
|
395
|
+
*
|
|
396
|
+
* @param messageText - Text of the message to send
|
|
397
|
+
* @param options - Options to send messages operation.
|
|
398
|
+
* @returns Response data for the send messages operation.
|
|
399
|
+
*
|
|
400
|
+
* Example usage:
|
|
401
|
+
*
|
|
402
|
+
* ```ts snippet:ReadmeSampleSendMessage
|
|
403
|
+
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
404
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
405
|
+
*
|
|
406
|
+
* const account = "<account>";
|
|
407
|
+
* const queueServiceClient = new QueueServiceClient(
|
|
408
|
+
* `https://${account}.queue.core.windows.net`,
|
|
409
|
+
* new DefaultAzureCredential(),
|
|
410
|
+
* );
|
|
411
|
+
*
|
|
412
|
+
* const queueName = "<valid queue name>";
|
|
413
|
+
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
414
|
+
* // Send a message into the queue using the sendMessage method.
|
|
415
|
+
* const sendMessageResponse = await queueClient.sendMessage("Hello World!");
|
|
416
|
+
* console.log(
|
|
417
|
+
* `Sent message successfully, service assigned message Id: ${sendMessageResponse.messageId}, service assigned request Id: ${sendMessageResponse.requestId}`,
|
|
418
|
+
* );
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
async sendMessage(messageText, options = {}) {
|
|
422
|
+
return tracingClient.withSpan("QueueClient-sendMessage", options, async (updatedOptions) => {
|
|
423
|
+
const response = assertResponse(
|
|
424
|
+
await this.messagesContext.enqueue(
|
|
425
|
+
{
|
|
426
|
+
messageText
|
|
427
|
+
},
|
|
428
|
+
updatedOptions
|
|
429
|
+
)
|
|
430
|
+
);
|
|
431
|
+
const item = response[0];
|
|
432
|
+
return {
|
|
433
|
+
_response: response._response,
|
|
434
|
+
date: response.date,
|
|
435
|
+
requestId: response.requestId,
|
|
436
|
+
clientRequestId: response.clientRequestId,
|
|
437
|
+
version: response.version,
|
|
438
|
+
errorCode: response.errorCode,
|
|
439
|
+
messageId: item.messageId,
|
|
440
|
+
popReceipt: item.popReceipt,
|
|
441
|
+
nextVisibleOn: item.nextVisibleOn,
|
|
442
|
+
insertedOn: item.insertedOn,
|
|
443
|
+
expiresOn: item.expiresOn
|
|
444
|
+
};
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* receiveMessages retrieves one or more messages from the front of the queue.
|
|
449
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/get-messages
|
|
450
|
+
*
|
|
451
|
+
* @param options - Options to receive messages operation.
|
|
452
|
+
* @returns Response data for the receive messages operation.
|
|
453
|
+
*
|
|
454
|
+
* Example usage:
|
|
455
|
+
*
|
|
456
|
+
* ```ts snippet:ReadmeSampleReceiveMessage
|
|
457
|
+
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
458
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
459
|
+
*
|
|
460
|
+
* const account = "<account>";
|
|
461
|
+
* const queueServiceClient = new QueueServiceClient(
|
|
462
|
+
* `https://${account}.queue.core.windows.net`,
|
|
463
|
+
* new DefaultAzureCredential(),
|
|
464
|
+
* );
|
|
465
|
+
*
|
|
466
|
+
* const queueName = "<valid queue name>";
|
|
467
|
+
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
468
|
+
* const response = await queueClient.receiveMessages();
|
|
469
|
+
* if (response.receivedMessageItems.length === 1) {
|
|
470
|
+
* const receivedMessageItem = response.receivedMessageItems[0];
|
|
471
|
+
* console.log(`Processing & deleting message with content: ${receivedMessageItem.messageText}`);
|
|
472
|
+
* const deleteMessageResponse = await queueClient.deleteMessage(
|
|
473
|
+
* receivedMessageItem.messageId,
|
|
474
|
+
* receivedMessageItem.popReceipt,
|
|
475
|
+
* );
|
|
476
|
+
* console.log(
|
|
477
|
+
* `Delete message successfully, service assigned request Id: ${deleteMessageResponse.requestId}`,
|
|
478
|
+
* );
|
|
479
|
+
* }
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
async receiveMessages(options = {}) {
|
|
483
|
+
return tracingClient.withSpan(
|
|
484
|
+
"QueueClient-receiveMessages",
|
|
485
|
+
options,
|
|
486
|
+
async (updatedOptions) => {
|
|
487
|
+
const response = assertResponse(await this.messagesContext.dequeue(updatedOptions));
|
|
488
|
+
const res = {
|
|
489
|
+
_response: response._response,
|
|
490
|
+
date: response.date,
|
|
491
|
+
requestId: response.requestId,
|
|
492
|
+
clientRequestId: response.clientRequestId,
|
|
493
|
+
receivedMessageItems: [],
|
|
494
|
+
version: response.version,
|
|
495
|
+
errorCode: response.errorCode
|
|
496
|
+
};
|
|
497
|
+
for (const item of response) {
|
|
498
|
+
res.receivedMessageItems.push(item);
|
|
652
499
|
}
|
|
653
|
-
return
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
500
|
+
return res;
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* peekMessages retrieves one or more messages from the front of the queue but does not alter the visibility of the message.
|
|
506
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/peek-messages
|
|
507
|
+
*
|
|
508
|
+
* @param options - Options to peek messages operation.
|
|
509
|
+
* @returns Response data for the peek messages operation.
|
|
510
|
+
*
|
|
511
|
+
* Example usage:
|
|
512
|
+
*
|
|
513
|
+
* ```ts snippet:ReadmeSamplePeekMessage
|
|
514
|
+
* import { QueueServiceClient } from "@azure/storage-queue";
|
|
515
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
516
|
+
*
|
|
517
|
+
* const account = "<account>";
|
|
518
|
+
* const queueServiceClient = new QueueServiceClient(
|
|
519
|
+
* `https://${account}.queue.core.windows.net`,
|
|
520
|
+
* new DefaultAzureCredential(),
|
|
521
|
+
* );
|
|
522
|
+
*
|
|
523
|
+
* const queueName = "<valid queue name>";
|
|
524
|
+
* const queueClient = queueServiceClient.getQueueClient(queueName);
|
|
525
|
+
* const peekMessagesResponse = await queueClient.peekMessages();
|
|
526
|
+
* console.log(`The peeked message is: ${peekMessagesResponse.peekedMessageItems[0].messageText}`);
|
|
527
|
+
* ```
|
|
528
|
+
*/
|
|
529
|
+
async peekMessages(options = {}) {
|
|
530
|
+
return tracingClient.withSpan("QueueClient-peekMessages", options, async (updatedOptions) => {
|
|
531
|
+
const response = assertResponse(await this.messagesContext.peek(updatedOptions));
|
|
532
|
+
const res = {
|
|
533
|
+
_response: response._response,
|
|
534
|
+
date: response.date,
|
|
535
|
+
requestId: response.requestId,
|
|
536
|
+
clientRequestId: response.clientRequestId,
|
|
537
|
+
peekedMessageItems: [],
|
|
538
|
+
version: response.version,
|
|
539
|
+
errorCode: response.errorCode
|
|
540
|
+
};
|
|
541
|
+
for (const item of response) {
|
|
542
|
+
res.peekedMessageItems.push(item);
|
|
543
|
+
}
|
|
544
|
+
return res;
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* deleteMessage permanently removes the specified message from its queue.
|
|
549
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/delete-message2
|
|
550
|
+
*
|
|
551
|
+
* @param messageId - Id of the message.
|
|
552
|
+
* @param popReceipt - A valid pop receipt value returned from an earlier call to the receive messages or update message operation.
|
|
553
|
+
* @param options - Options to delete message operation.
|
|
554
|
+
* @returns Response data for the delete message operation.
|
|
555
|
+
*/
|
|
556
|
+
async deleteMessage(messageId, popReceipt, options = {}) {
|
|
557
|
+
return tracingClient.withSpan("QueueClient-deleteMessage", options, async (updatedOptions) => {
|
|
558
|
+
return assertResponse(
|
|
559
|
+
await this.getMessageIdContext(messageId).delete(popReceipt, updatedOptions)
|
|
560
|
+
);
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Update changes a message's visibility timeout and contents.
|
|
565
|
+
* The message content is up to 64KB in size, and must be in a format that can be included in an XML request with UTF-8 encoding.
|
|
566
|
+
* To include markup in the message, the contents of the message must either be XML-escaped or Base64-encode.
|
|
567
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/update-message
|
|
568
|
+
*
|
|
569
|
+
* @param messageId - Id of the message
|
|
570
|
+
* @param popReceipt - A valid pop receipt value returned from an earlier call to the receive messages or update message operation.
|
|
571
|
+
* @param message - Message to update. If this parameter is undefined, then the content of the message won't be updated.
|
|
572
|
+
* @param visibilityTimeout - Specifies the new visibility timeout value, in seconds,
|
|
573
|
+
* relative to server time. The new value must be larger than or equal to 0,
|
|
574
|
+
* and cannot be larger than 7 days. The visibility timeout of a message cannot
|
|
575
|
+
* be set to a value later than the expiry time.
|
|
576
|
+
* A message can be updated until it has been deleted or has expired.
|
|
577
|
+
* @param options - Options to update message operation.
|
|
578
|
+
* @returns Response data for the update message operation.
|
|
579
|
+
*/
|
|
580
|
+
async updateMessage(messageId, popReceipt, message, visibilityTimeout, options = {}) {
|
|
581
|
+
return tracingClient.withSpan("QueueClient-updateMessage", options, async (updatedOptions) => {
|
|
582
|
+
let queueMessage = void 0;
|
|
583
|
+
if (message !== void 0) {
|
|
584
|
+
queueMessage = { messageText: message };
|
|
585
|
+
}
|
|
586
|
+
return assertResponse(
|
|
587
|
+
await this.getMessageIdContext(messageId).update(popReceipt, visibilityTimeout || 0, {
|
|
588
|
+
abortSignal: options.abortSignal,
|
|
589
|
+
tracingOptions: updatedOptions.tracingOptions,
|
|
590
|
+
queueMessage
|
|
591
|
+
})
|
|
592
|
+
);
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
getQueueNameFromUrl() {
|
|
596
|
+
let queueName;
|
|
597
|
+
try {
|
|
598
|
+
const parsedUrl = new URL(this.url);
|
|
599
|
+
if (parsedUrl.hostname.split(".")[1] === "queue") {
|
|
600
|
+
queueName = parsedUrl.pathname.split("/")[1];
|
|
601
|
+
} else if (isIpEndpointStyle(parsedUrl)) {
|
|
602
|
+
queueName = parsedUrl.pathname.split("/")[2];
|
|
603
|
+
} else {
|
|
604
|
+
queueName = parsedUrl.pathname.split("/")[1];
|
|
605
|
+
}
|
|
606
|
+
if (!queueName) {
|
|
607
|
+
throw new Error("Provided queueName is invalid.");
|
|
608
|
+
}
|
|
609
|
+
return queueName;
|
|
610
|
+
} catch (error) {
|
|
611
|
+
throw new Error("Unable to extract queueName with provided information.");
|
|
657
612
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Only available for QueueClient constructed with a shared key credential.
|
|
616
|
+
*
|
|
617
|
+
* Generates a Service Shared Access Signature (SAS) URI based on the client properties
|
|
618
|
+
* and parameters passed in. The SAS is signed by the shared key credential of the client.
|
|
619
|
+
*
|
|
620
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
|
|
621
|
+
*
|
|
622
|
+
* @param options - Optional parameters.
|
|
623
|
+
* @returns The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
|
|
624
|
+
*/
|
|
625
|
+
generateSasUrl(options) {
|
|
626
|
+
if (!(this.credential instanceof StorageSharedKeyCredential)) {
|
|
627
|
+
throw RangeError(
|
|
628
|
+
"Can only generate the SAS when the client is initialized with a shared key credential"
|
|
629
|
+
);
|
|
675
630
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
631
|
+
const sas = generateQueueSASQueryParameters(
|
|
632
|
+
{
|
|
633
|
+
queueName: this.name,
|
|
634
|
+
...options
|
|
635
|
+
},
|
|
636
|
+
this.credential
|
|
637
|
+
).toString();
|
|
638
|
+
return appendToURLQuery(this.url, sas);
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Only available for QueueClient constructed with a shared key credential.
|
|
642
|
+
*
|
|
643
|
+
* Generates string to sign for a Service Shared Access Signature (SAS) URI based on the client properties
|
|
644
|
+
* and parameters passed in. The SAS is signed by the shared key credential of the client.
|
|
645
|
+
*
|
|
646
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
|
|
647
|
+
*
|
|
648
|
+
* @param options - Optional parameters.
|
|
649
|
+
* @returns The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
|
|
650
|
+
*/
|
|
651
|
+
/* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/
|
|
652
|
+
generateSasStringToSign(options) {
|
|
653
|
+
if (!(this.credential instanceof StorageSharedKeyCredential)) {
|
|
654
|
+
throw RangeError(
|
|
655
|
+
"Can only generate the SAS when the client is initialized with a shared key credential"
|
|
656
|
+
);
|
|
692
657
|
}
|
|
658
|
+
return generateQueueSASQueryParametersInternal(
|
|
659
|
+
{
|
|
660
|
+
queueName: this.name,
|
|
661
|
+
...options
|
|
662
|
+
},
|
|
663
|
+
this.credential
|
|
664
|
+
).stringToSign;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
*
|
|
668
|
+
* Generates a Service Shared Access Signature (SAS) URI based on the client properties
|
|
669
|
+
* and parameters passed in. The SAS is signed by the user delegation key credential input.
|
|
670
|
+
*
|
|
671
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
|
|
672
|
+
*
|
|
673
|
+
* @param options - Optional parameters.
|
|
674
|
+
* @param userDelegationKey - user delegation key used to sign the SAS URI
|
|
675
|
+
* @returns The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
|
|
676
|
+
*/
|
|
677
|
+
generateUserDelegationSasUrl(options, userDelegationKey) {
|
|
678
|
+
const sas = generateQueueSASQueryParameters(
|
|
679
|
+
{
|
|
680
|
+
queueName: this.name,
|
|
681
|
+
...options
|
|
682
|
+
},
|
|
683
|
+
userDelegationKey,
|
|
684
|
+
this.accountName
|
|
685
|
+
).toString();
|
|
686
|
+
return appendToURLQuery(this.url, sas);
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
*
|
|
690
|
+
* Generates a Service Shared Access Signature (SAS) URI based on the client properties
|
|
691
|
+
* and parameters passed in. The SAS is signed by the user delegation key credential input.
|
|
692
|
+
*
|
|
693
|
+
* @see https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
|
|
694
|
+
*
|
|
695
|
+
* @param options - Optional parameters.
|
|
696
|
+
* @param userDelegationKey - user delegation key used to sign the SAS URI
|
|
697
|
+
* @returns The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
|
|
698
|
+
*/
|
|
699
|
+
generateUserDelegationStringToSign(options, userDelegationKey) {
|
|
700
|
+
return generateQueueSASQueryParametersInternal(
|
|
701
|
+
{
|
|
702
|
+
queueName: this.name,
|
|
703
|
+
...options
|
|
704
|
+
},
|
|
705
|
+
userDelegationKey,
|
|
706
|
+
this.accountName
|
|
707
|
+
).stringToSign;
|
|
708
|
+
}
|
|
693
709
|
}
|
|
694
|
-
|
|
710
|
+
export {
|
|
711
|
+
QueueClient
|
|
712
|
+
};
|