@azure/data-tables 13.1.0-alpha.20220216.2 → 13.1.0-alpha.20220218.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 CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  ### Bugs Fixed
10
10
 
11
+ - Fix issue with `getStatistics()` operation consistently failing and added test. [#20398](https://github.com/Azure/azure-sdk-for-js/pull/20398)
12
+
11
13
  ### Other Changes
12
14
 
13
15
  - Updated our `@azure/core-tracing` dependency to the latest version (1.0.0-preview.14)
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.
@@ -3463,6 +3509,7 @@ class TableServiceClient {
3463
3509
  },
3464
3510
  }), (coreAuth.isTokenCredential(credential) && { credential, credentialScopes: STORAGE_SCOPE }));
3465
3511
  const client = new GeneratedClient(this.url, internalPipelineOptions);
3512
+ client.pipeline.addPolicy(tablesSecondaryEndpointPolicy);
3466
3513
  if (coreAuth.isNamedKeyCredential(credential)) {
3467
3514
  client.pipeline.addPolicy(tablesNamedKeyCredentialPolicy(credential));
3468
3515
  }
@@ -3478,8 +3525,8 @@ class TableServiceClient {
3478
3525
  * secondary location endpoint when read-access geo-redundant replication is enabled for the account.
3479
3526
  * @param options - The options parameters.
3480
3527
  */
3481
- getStatistics(options = {}) {
3482
- return tracingClient.withSpan("TableServiceClient.getStatistics", options, (updatedOptions) => this.service.getStatistics(updatedOptions));
3528
+ async getStatistics(options = {}) {
3529
+ return tracingClient.withSpan("TableServiceClient.getStatistics", options, (updatedOptions) => this.service.getStatistics(injectSecondaryEndpointHeader(updatedOptions)));
3483
3530
  }
3484
3531
  /**
3485
3532
  * Gets the properties of an account's Table service, including properties for Analytics and CORS
@@ -3525,7 +3572,7 @@ class TableServiceClient {
3525
3572
  }
3526
3573
  catch (e) {
3527
3574
  if (e.statusCode === 404) {
3528
- logger.info("TableServiceClient-deleteTable: Table doesn't exist");
3575
+ logger.info("TableServiceClient.deleteTable: Table doesn't exist");
3529
3576
  }
3530
3577
  else {
3531
3578
  throw e;