@azure/data-tables 13.0.2-alpha.20220214.1 → 13.0.2-alpha.20220217.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/CHANGELOG.md +2 -0
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/dist-esm/src/TableServiceClient.js +3 -1
- package/dist-esm/src/TableServiceClient.js.map +1 -1
- package/dist-esm/src/secondaryEndpointPolicy.js +46 -0
- package/dist-esm/src/secondaryEndpointPolicy.js.map +1 -0
- package/dist-esm/src/utils/connectionString.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -761,6 +761,52 @@ function generateTableSas(tableName, credential, options = {}) {
|
|
|
761
761
|
return sas;
|
|
762
762
|
}
|
|
763
763
|
|
|
764
|
+
// Copyright (c) Microsoft Corporation.
|
|
765
|
+
// Licensed under the MIT license.
|
|
766
|
+
/**
|
|
767
|
+
* The programmatic identifier of the tablesSecondaryEndpointPolicy.
|
|
768
|
+
*/
|
|
769
|
+
const tablesSecondaryEndpointPolicyName = "tablesSecondaryEndpointPolicy";
|
|
770
|
+
const SecondaryLocationHeaderName = "tables-secondary-endpoint";
|
|
771
|
+
const SecondaryLocationAccountSuffix = "-secondary";
|
|
772
|
+
/**
|
|
773
|
+
* Policy that would replace the Primary Endpoint with the secondary endpoint
|
|
774
|
+
* when the `tables-secondary-endpoint` is set in the request
|
|
775
|
+
*/
|
|
776
|
+
const tablesSecondaryEndpointPolicy = {
|
|
777
|
+
name: tablesSecondaryEndpointPolicyName,
|
|
778
|
+
sendRequest: async (req, next) => {
|
|
779
|
+
// Only replace the URL if the SecondaryLocationHeader is set
|
|
780
|
+
if (req.headers.get(SecondaryLocationHeaderName)) {
|
|
781
|
+
// Since the header is for internal use only, clean it up.
|
|
782
|
+
req.headers.delete(SecondaryLocationHeaderName);
|
|
783
|
+
// Calculate and update the secondary url
|
|
784
|
+
req.url = getSecondaryUrlFromPrimary(req.url);
|
|
785
|
+
}
|
|
786
|
+
return next(req);
|
|
787
|
+
},
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* Utility function that injects the SecondaryEndpointHeader into an operation options
|
|
791
|
+
*/
|
|
792
|
+
function injectSecondaryEndpointHeader(options) {
|
|
793
|
+
var _a;
|
|
794
|
+
const headerToInject = { [SecondaryLocationHeaderName]: "true" };
|
|
795
|
+
return Object.assign(Object.assign({}, options), { requestOptions: Object.assign(Object.assign({}, options.requestOptions), { customHeaders: Object.assign(Object.assign({}, (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.customHeaders), headerToInject) }) });
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Utility function that calculates the secondary URL for a table instance given the primary URL.
|
|
799
|
+
*/
|
|
800
|
+
function getSecondaryUrlFromPrimary(primaryUrl) {
|
|
801
|
+
const parsedPrimaryUrl = new URL(primaryUrl);
|
|
802
|
+
const host = parsedPrimaryUrl.hostname.split(".");
|
|
803
|
+
if (host.length > 1) {
|
|
804
|
+
host[0] = `${host[0]}${SecondaryLocationAccountSuffix}`;
|
|
805
|
+
}
|
|
806
|
+
parsedPrimaryUrl.hostname = host.join(".");
|
|
807
|
+
return parsedPrimaryUrl.toString();
|
|
808
|
+
}
|
|
809
|
+
|
|
764
810
|
/*
|
|
765
811
|
* Copyright (c) Microsoft Corporation.
|
|
766
812
|
* Licensed under the MIT License.
|
|
@@ -3462,6 +3508,7 @@ class TableServiceClient {
|
|
|
3462
3508
|
},
|
|
3463
3509
|
}), (coreAuth.isTokenCredential(credential) && { credential, credentialScopes: STORAGE_SCOPE }));
|
|
3464
3510
|
const client = new GeneratedClient(this.url, internalPipelineOptions);
|
|
3511
|
+
client.pipeline.addPolicy(tablesSecondaryEndpointPolicy);
|
|
3465
3512
|
if (coreAuth.isNamedKeyCredential(credential)) {
|
|
3466
3513
|
client.pipeline.addPolicy(tablesNamedKeyCredentialPolicy(credential));
|
|
3467
3514
|
}
|
|
@@ -3480,7 +3527,7 @@ class TableServiceClient {
|
|
|
3480
3527
|
async getStatistics(options = {}) {
|
|
3481
3528
|
const { span, updatedOptions } = createSpan("TableServiceClient-getStatistics", options);
|
|
3482
3529
|
try {
|
|
3483
|
-
return await this.service.getStatistics(updatedOptions);
|
|
3530
|
+
return await this.service.getStatistics(injectSecondaryEndpointHeader(updatedOptions));
|
|
3484
3531
|
}
|
|
3485
3532
|
catch (e) {
|
|
3486
3533
|
span.setStatus({ code: coreTracing.SpanStatusCode.ERROR, message: e.message });
|