@azure/cosmos 4.4.1 → 4.5.0-alpha.20250718.3
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/ClientContext.d.ts +19 -10
- package/dist/browser/ClientContext.d.ts.map +1 -1
- package/dist/browser/ClientContext.js +30 -11
- package/dist/browser/ClientContext.js.map +1 -1
- package/dist/browser/CosmosClient.d.ts.map +1 -1
- package/dist/browser/CosmosClient.js +13 -2
- package/dist/browser/CosmosClient.js.map +1 -1
- package/dist/browser/PartitionKeyRangeFailoverInfo.d.ts +49 -0
- package/dist/browser/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
- package/dist/browser/PartitionKeyRangeFailoverInfo.js +130 -0
- package/dist/browser/PartitionKeyRangeFailoverInfo.js.map +1 -0
- package/dist/browser/client/ChangeFeed/ChangeFeedForPartitionKey.d.ts.map +1 -1
- package/dist/browser/client/ChangeFeed/ChangeFeedForPartitionKey.js +4 -0
- package/dist/browser/client/ChangeFeed/ChangeFeedForPartitionKey.js.map +1 -1
- package/dist/browser/client/ClientUtils.d.ts +3 -1
- package/dist/browser/client/ClientUtils.d.ts.map +1 -1
- package/dist/browser/client/ClientUtils.js +10 -0
- package/dist/browser/client/ClientUtils.js.map +1 -1
- package/dist/browser/client/Item/Item.d.ts.map +1 -1
- package/dist/browser/client/Item/Item.js +13 -0
- package/dist/browser/client/Item/Item.js.map +1 -1
- package/dist/browser/client/Item/Items.d.ts +1 -0
- package/dist/browser/client/Item/Items.d.ts.map +1 -1
- package/dist/browser/client/Item/Items.js +29 -3
- package/dist/browser/client/Item/Items.js.map +1 -1
- package/dist/browser/common/constants.d.ts +20 -0
- package/dist/browser/common/constants.d.ts.map +1 -1
- package/dist/browser/common/constants.js +23 -1
- package/dist/browser/common/constants.js.map +1 -1
- package/dist/browser/common/platform.d.ts +6 -1
- package/dist/browser/common/platform.d.ts.map +1 -1
- package/dist/browser/common/platform.js +23 -4
- package/dist/browser/common/platform.js.map +1 -1
- package/dist/browser/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
- package/dist/browser/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
- package/dist/browser/diagnostics/DiagnosticNodeInternal.js.map +1 -1
- package/dist/browser/documents/ConnectionPolicy.d.ts +6 -0
- package/dist/browser/documents/ConnectionPolicy.d.ts.map +1 -1
- package/dist/browser/documents/ConnectionPolicy.js +2 -0
- package/dist/browser/documents/ConnectionPolicy.js.map +1 -1
- package/dist/browser/documents/DatabaseAccount.d.ts.map +1 -1
- package/dist/browser/documents/DatabaseAccount.js +3 -0
- package/dist/browser/documents/DatabaseAccount.js.map +1 -1
- package/dist/browser/documents/PartitionKeyDefinition.d.ts +1 -1
- package/dist/browser/documents/PartitionKeyDefinition.js.map +1 -1
- package/dist/browser/encryption/EncryptionKeyStoreProvider.d.ts.map +1 -1
- package/dist/browser/encryption/EncryptionKeyStoreProvider.js +2 -1
- package/dist/browser/encryption/EncryptionKeyStoreProvider.js.map +1 -1
- package/dist/browser/extractPartitionKey.d.ts.map +1 -1
- package/dist/browser/extractPartitionKey.js +33 -20
- package/dist/browser/extractPartitionKey.js.map +1 -1
- package/dist/browser/globalEndpointManager.d.ts +6 -0
- package/dist/browser/globalEndpointManager.d.ts.map +1 -1
- package/dist/browser/globalEndpointManager.js +9 -4
- package/dist/browser/globalEndpointManager.js.map +1 -1
- package/dist/browser/globalPartitionEndpointManager.d.ts +79 -0
- package/dist/browser/globalPartitionEndpointManager.d.ts.map +1 -0
- package/dist/browser/globalPartitionEndpointManager.js +278 -0
- package/dist/browser/globalPartitionEndpointManager.js.map +1 -0
- package/dist/browser/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
- package/dist/browser/queryExecutionContext/Aggregators/index.js +1 -0
- package/dist/browser/queryExecutionContext/Aggregators/index.js.map +1 -1
- package/dist/browser/queryExecutionContext/documentProducer.d.ts +2 -3
- package/dist/browser/queryExecutionContext/documentProducer.d.ts.map +1 -1
- package/dist/browser/queryExecutionContext/documentProducer.js +16 -21
- package/dist/browser/queryExecutionContext/documentProducer.js.map +1 -1
- package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
- package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
- package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
- package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
- package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
- package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
- package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
- package/dist/browser/queryIterator.d.ts.map +1 -1
- package/dist/browser/queryIterator.js +2 -3
- package/dist/browser/queryIterator.js.map +1 -1
- package/dist/browser/request/ErrorResponse.d.ts +1 -1
- package/dist/browser/request/ErrorResponse.d.ts.map +1 -1
- package/dist/browser/request/ErrorResponse.js.map +1 -1
- package/dist/browser/request/RequestContext.d.ts +5 -0
- package/dist/browser/request/RequestContext.d.ts.map +1 -1
- package/dist/browser/request/RequestContext.js.map +1 -1
- package/dist/browser/request/RequestHandler.d.ts.map +1 -1
- package/dist/browser/request/RequestHandler.js +14 -4
- package/dist/browser/request/RequestHandler.js.map +1 -1
- package/dist/browser/request/request.d.ts.map +1 -1
- package/dist/browser/request/request.js +3 -3
- package/dist/browser/request/request.js.map +1 -1
- package/dist/browser/retry/RetryPolicy.d.ts +2 -2
- package/dist/browser/retry/RetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/RetryPolicy.js.map +1 -1
- package/dist/browser/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/defaultRetryPolicy.js +4 -8
- package/dist/browser/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.js +9 -2
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/browser/retry/retryUtility.d.ts.map +1 -1
- package/dist/browser/retry/retryUtility.js +11 -5
- package/dist/browser/retry/retryUtility.js.map +1 -1
- package/dist/browser/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
- package/dist/browser/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/timeoutFailoverRetryPolicy.js +15 -7
- package/dist/browser/retry/timeoutFailoverRetryPolicy.js.map +1 -1
- package/dist/browser/routing/partitionKeyRangeCache.d.ts.map +1 -1
- package/dist/browser/routing/partitionKeyRangeCache.js +11 -0
- package/dist/browser/routing/partitionKeyRangeCache.js.map +1 -1
- package/dist/browser/utils/checkURL.js +6 -0
- package/dist/browser/utils/checkURL.js.map +1 -1
- package/dist/browser/utils/hashing/hash.d.ts +2 -0
- package/dist/browser/utils/hashing/hash.d.ts.map +1 -1
- package/dist/browser/utils/hashing/hash.js +19 -0
- package/dist/browser/utils/hashing/hash.js.map +1 -1
- package/dist/browser/utils/time.d.ts +8 -0
- package/dist/browser/utils/time.d.ts.map +1 -1
- package/dist/browser/utils/time.js +19 -0
- package/dist/browser/utils/time.js.map +1 -1
- package/dist/commonjs/ClientContext.d.ts +19 -10
- package/dist/commonjs/ClientContext.d.ts.map +1 -1
- package/dist/commonjs/ClientContext.js +30 -11
- package/dist/commonjs/ClientContext.js.map +1 -1
- package/dist/commonjs/CosmosClient.d.ts.map +1 -1
- package/dist/commonjs/CosmosClient.js +13 -2
- package/dist/commonjs/CosmosClient.js.map +1 -1
- package/dist/commonjs/PartitionKeyRangeFailoverInfo.d.ts +49 -0
- package/dist/commonjs/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
- package/dist/commonjs/PartitionKeyRangeFailoverInfo.js +135 -0
- package/dist/commonjs/PartitionKeyRangeFailoverInfo.js.map +1 -0
- package/dist/commonjs/client/ChangeFeed/ChangeFeedForPartitionKey.d.ts.map +1 -1
- package/dist/commonjs/client/ChangeFeed/ChangeFeedForPartitionKey.js +4 -0
- package/dist/commonjs/client/ChangeFeed/ChangeFeedForPartitionKey.js.map +1 -1
- package/dist/commonjs/client/ClientUtils.d.ts +3 -1
- package/dist/commonjs/client/ClientUtils.d.ts.map +1 -1
- package/dist/commonjs/client/ClientUtils.js +11 -0
- package/dist/commonjs/client/ClientUtils.js.map +1 -1
- package/dist/commonjs/client/Item/Item.d.ts.map +1 -1
- package/dist/commonjs/client/Item/Item.js +13 -0
- package/dist/commonjs/client/Item/Item.js.map +1 -1
- package/dist/commonjs/client/Item/Items.d.ts +1 -0
- package/dist/commonjs/client/Item/Items.d.ts.map +1 -1
- package/dist/commonjs/client/Item/Items.js +27 -1
- package/dist/commonjs/client/Item/Items.js.map +1 -1
- package/dist/commonjs/common/constants.d.ts +20 -0
- package/dist/commonjs/common/constants.d.ts.map +1 -1
- package/dist/commonjs/common/constants.js +24 -2
- package/dist/commonjs/common/constants.js.map +1 -1
- package/dist/commonjs/common/platform.d.ts +6 -1
- package/dist/commonjs/common/platform.d.ts.map +1 -1
- package/dist/commonjs/common/platform.js +23 -3
- package/dist/commonjs/common/platform.js.map +1 -1
- package/dist/commonjs/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
- package/dist/commonjs/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
- package/dist/commonjs/diagnostics/DiagnosticNodeInternal.js.map +1 -1
- package/dist/commonjs/documents/ConnectionPolicy.d.ts +6 -0
- package/dist/commonjs/documents/ConnectionPolicy.d.ts.map +1 -1
- package/dist/commonjs/documents/ConnectionPolicy.js +2 -0
- package/dist/commonjs/documents/ConnectionPolicy.js.map +1 -1
- package/dist/commonjs/documents/DatabaseAccount.d.ts.map +1 -1
- package/dist/commonjs/documents/DatabaseAccount.js +3 -0
- package/dist/commonjs/documents/DatabaseAccount.js.map +1 -1
- package/dist/commonjs/documents/PartitionKeyDefinition.d.ts +1 -1
- package/dist/commonjs/documents/PartitionKeyDefinition.js.map +1 -1
- package/dist/commonjs/encryption/Cache/ProtectedDataEncryptionKeyCache.d.ts.map +1 -1
- package/dist/commonjs/encryption/Cache/ProtectedDataEncryptionKeyCache.js +2 -1
- package/dist/commonjs/encryption/Cache/ProtectedDataEncryptionKeyCache.js.map +1 -1
- package/dist/commonjs/encryption/EncryptionKeyStoreProvider.d.ts.map +1 -1
- package/dist/commonjs/encryption/EncryptionKeyStoreProvider.js +2 -1
- package/dist/commonjs/encryption/EncryptionKeyStoreProvider.js.map +1 -1
- package/dist/commonjs/extractPartitionKey.d.ts.map +1 -1
- package/dist/commonjs/extractPartitionKey.js +33 -20
- package/dist/commonjs/extractPartitionKey.js.map +1 -1
- package/dist/commonjs/globalEndpointManager.d.ts +6 -0
- package/dist/commonjs/globalEndpointManager.d.ts.map +1 -1
- package/dist/commonjs/globalEndpointManager.js +10 -5
- package/dist/commonjs/globalEndpointManager.js.map +1 -1
- package/dist/commonjs/globalPartitionEndpointManager.d.ts +79 -0
- package/dist/commonjs/globalPartitionEndpointManager.d.ts.map +1 -0
- package/dist/commonjs/globalPartitionEndpointManager.js +282 -0
- package/dist/commonjs/globalPartitionEndpointManager.js.map +1 -0
- package/dist/commonjs/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
- package/dist/commonjs/queryExecutionContext/Aggregators/index.js +1 -0
- package/dist/commonjs/queryExecutionContext/Aggregators/index.js.map +1 -1
- package/dist/commonjs/queryExecutionContext/documentProducer.d.ts +2 -3
- package/dist/commonjs/queryExecutionContext/documentProducer.d.ts.map +1 -1
- package/dist/commonjs/queryExecutionContext/documentProducer.js +15 -20
- package/dist/commonjs/queryExecutionContext/documentProducer.js.map +1 -1
- package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
- package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
- package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
- package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
- package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
- package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
- package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
- package/dist/commonjs/queryIterator.d.ts.map +1 -1
- package/dist/commonjs/queryIterator.js +2 -3
- package/dist/commonjs/queryIterator.js.map +1 -1
- package/dist/commonjs/request/ErrorResponse.d.ts +1 -1
- package/dist/commonjs/request/ErrorResponse.d.ts.map +1 -1
- package/dist/commonjs/request/ErrorResponse.js.map +1 -1
- package/dist/commonjs/request/RequestContext.d.ts +5 -0
- package/dist/commonjs/request/RequestContext.d.ts.map +1 -1
- package/dist/commonjs/request/RequestContext.js.map +1 -1
- package/dist/commonjs/request/RequestHandler.d.ts.map +1 -1
- package/dist/commonjs/request/RequestHandler.js +12 -2
- package/dist/commonjs/request/RequestHandler.js.map +1 -1
- package/dist/commonjs/request/defaultAgent.js +4 -4
- package/dist/commonjs/request/defaultAgent.js.map +1 -1
- package/dist/commonjs/request/request.d.ts.map +1 -1
- package/dist/commonjs/request/request.js +3 -3
- package/dist/commonjs/request/request.js.map +1 -1
- package/dist/commonjs/retry/RetryPolicy.d.ts +2 -2
- package/dist/commonjs/retry/RetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/RetryPolicy.js.map +1 -1
- package/dist/commonjs/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/defaultRetryPolicy.js +3 -7
- package/dist/commonjs/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js +9 -2
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/commonjs/retry/retryUtility.d.ts.map +1 -1
- package/dist/commonjs/retry/retryUtility.js +11 -5
- package/dist/commonjs/retry/retryUtility.js.map +1 -1
- package/dist/commonjs/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
- package/dist/commonjs/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/timeoutFailoverRetryPolicy.js +15 -7
- package/dist/commonjs/retry/timeoutFailoverRetryPolicy.js.map +1 -1
- package/dist/commonjs/routing/partitionKeyRangeCache.d.ts.map +1 -1
- package/dist/commonjs/routing/partitionKeyRangeCache.js +11 -0
- package/dist/commonjs/routing/partitionKeyRangeCache.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/utils/checkURL.js +7 -0
- package/dist/commonjs/utils/checkURL.js.map +1 -1
- package/dist/commonjs/utils/hashing/hash.d.ts +2 -0
- package/dist/commonjs/utils/hashing/hash.d.ts.map +1 -1
- package/dist/commonjs/utils/hashing/hash.js +20 -0
- package/dist/commonjs/utils/hashing/hash.js.map +1 -1
- package/dist/commonjs/utils/time.d.ts +8 -0
- package/dist/commonjs/utils/time.d.ts.map +1 -1
- package/dist/commonjs/utils/time.js +20 -0
- package/dist/commonjs/utils/time.js.map +1 -1
- package/dist/esm/ClientContext.d.ts +19 -10
- package/dist/esm/ClientContext.d.ts.map +1 -1
- package/dist/esm/ClientContext.js +30 -11
- package/dist/esm/ClientContext.js.map +1 -1
- package/dist/esm/CosmosClient.d.ts.map +1 -1
- package/dist/esm/CosmosClient.js +13 -2
- package/dist/esm/CosmosClient.js.map +1 -1
- package/dist/esm/PartitionKeyRangeFailoverInfo.d.ts +49 -0
- package/dist/esm/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
- package/dist/esm/PartitionKeyRangeFailoverInfo.js +130 -0
- package/dist/esm/PartitionKeyRangeFailoverInfo.js.map +1 -0
- package/dist/esm/client/ChangeFeed/ChangeFeedForPartitionKey.d.ts.map +1 -1
- package/dist/esm/client/ChangeFeed/ChangeFeedForPartitionKey.js +4 -0
- package/dist/esm/client/ChangeFeed/ChangeFeedForPartitionKey.js.map +1 -1
- package/dist/esm/client/ClientUtils.d.ts +3 -1
- package/dist/esm/client/ClientUtils.d.ts.map +1 -1
- package/dist/esm/client/ClientUtils.js +10 -0
- package/dist/esm/client/ClientUtils.js.map +1 -1
- package/dist/esm/client/Item/Item.d.ts.map +1 -1
- package/dist/esm/client/Item/Item.js +13 -0
- package/dist/esm/client/Item/Item.js.map +1 -1
- package/dist/esm/client/Item/Items.d.ts +1 -0
- package/dist/esm/client/Item/Items.d.ts.map +1 -1
- package/dist/esm/client/Item/Items.js +29 -3
- package/dist/esm/client/Item/Items.js.map +1 -1
- package/dist/esm/common/constants.d.ts +20 -0
- package/dist/esm/common/constants.d.ts.map +1 -1
- package/dist/esm/common/constants.js +23 -1
- package/dist/esm/common/constants.js.map +1 -1
- package/dist/esm/common/platform.d.ts +6 -1
- package/dist/esm/common/platform.d.ts.map +1 -1
- package/dist/esm/common/platform.js +23 -4
- package/dist/esm/common/platform.js.map +1 -1
- package/dist/esm/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
- package/dist/esm/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
- package/dist/esm/diagnostics/DiagnosticNodeInternal.js.map +1 -1
- package/dist/esm/documents/ConnectionPolicy.d.ts +6 -0
- package/dist/esm/documents/ConnectionPolicy.d.ts.map +1 -1
- package/dist/esm/documents/ConnectionPolicy.js +2 -0
- package/dist/esm/documents/ConnectionPolicy.js.map +1 -1
- package/dist/esm/documents/DatabaseAccount.d.ts.map +1 -1
- package/dist/esm/documents/DatabaseAccount.js +3 -0
- package/dist/esm/documents/DatabaseAccount.js.map +1 -1
- package/dist/esm/documents/PartitionKeyDefinition.d.ts +1 -1
- package/dist/esm/documents/PartitionKeyDefinition.js.map +1 -1
- package/dist/esm/encryption/Cache/ProtectedDataEncryptionKeyCache.d.ts.map +1 -1
- package/dist/esm/encryption/Cache/ProtectedDataEncryptionKeyCache.js +2 -1
- package/dist/esm/encryption/Cache/ProtectedDataEncryptionKeyCache.js.map +1 -1
- package/dist/esm/encryption/EncryptionKeyStoreProvider.d.ts.map +1 -1
- package/dist/esm/encryption/EncryptionKeyStoreProvider.js +2 -1
- package/dist/esm/encryption/EncryptionKeyStoreProvider.js.map +1 -1
- package/dist/esm/extractPartitionKey.d.ts.map +1 -1
- package/dist/esm/extractPartitionKey.js +33 -20
- package/dist/esm/extractPartitionKey.js.map +1 -1
- package/dist/esm/globalEndpointManager.d.ts +6 -0
- package/dist/esm/globalEndpointManager.d.ts.map +1 -1
- package/dist/esm/globalEndpointManager.js +9 -4
- package/dist/esm/globalEndpointManager.js.map +1 -1
- package/dist/esm/globalPartitionEndpointManager.d.ts +79 -0
- package/dist/esm/globalPartitionEndpointManager.d.ts.map +1 -0
- package/dist/esm/globalPartitionEndpointManager.js +278 -0
- package/dist/esm/globalPartitionEndpointManager.js.map +1 -0
- package/dist/esm/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
- package/dist/esm/queryExecutionContext/Aggregators/index.js +1 -0
- package/dist/esm/queryExecutionContext/Aggregators/index.js.map +1 -1
- package/dist/esm/queryExecutionContext/documentProducer.d.ts +2 -3
- package/dist/esm/queryExecutionContext/documentProducer.d.ts.map +1 -1
- package/dist/esm/queryExecutionContext/documentProducer.js +16 -21
- package/dist/esm/queryExecutionContext/documentProducer.js.map +1 -1
- package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
- package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
- package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
- package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
- package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
- package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
- package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
- package/dist/esm/queryIterator.d.ts.map +1 -1
- package/dist/esm/queryIterator.js +2 -3
- package/dist/esm/queryIterator.js.map +1 -1
- package/dist/esm/request/ErrorResponse.d.ts +1 -1
- package/dist/esm/request/ErrorResponse.d.ts.map +1 -1
- package/dist/esm/request/ErrorResponse.js.map +1 -1
- package/dist/esm/request/RequestContext.d.ts +5 -0
- package/dist/esm/request/RequestContext.d.ts.map +1 -1
- package/dist/esm/request/RequestContext.js.map +1 -1
- package/dist/esm/request/RequestHandler.d.ts.map +1 -1
- package/dist/esm/request/RequestHandler.js +14 -4
- package/dist/esm/request/RequestHandler.js.map +1 -1
- package/dist/esm/request/defaultAgent.js +2 -2
- package/dist/esm/request/defaultAgent.js.map +1 -1
- package/dist/esm/request/request.d.ts.map +1 -1
- package/dist/esm/request/request.js +3 -3
- package/dist/esm/request/request.js.map +1 -1
- package/dist/esm/retry/RetryPolicy.d.ts +2 -2
- package/dist/esm/retry/RetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/RetryPolicy.js.map +1 -1
- package/dist/esm/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/defaultRetryPolicy.js +4 -8
- package/dist/esm/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.js +9 -2
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/esm/retry/retryUtility.d.ts.map +1 -1
- package/dist/esm/retry/retryUtility.js +11 -5
- package/dist/esm/retry/retryUtility.js.map +1 -1
- package/dist/esm/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
- package/dist/esm/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/timeoutFailoverRetryPolicy.js +15 -7
- package/dist/esm/retry/timeoutFailoverRetryPolicy.js.map +1 -1
- package/dist/esm/routing/partitionKeyRangeCache.d.ts.map +1 -1
- package/dist/esm/routing/partitionKeyRangeCache.js +11 -0
- package/dist/esm/routing/partitionKeyRangeCache.js.map +1 -1
- package/dist/esm/utils/checkURL.js +6 -0
- package/dist/esm/utils/checkURL.js.map +1 -1
- package/dist/esm/utils/hashing/hash.d.ts +2 -0
- package/dist/esm/utils/hashing/hash.d.ts.map +1 -1
- package/dist/esm/utils/hashing/hash.js +19 -0
- package/dist/esm/utils/hashing/hash.js.map +1 -1
- package/dist/esm/utils/time.d.ts +8 -0
- package/dist/esm/utils/time.d.ts.map +1 -1
- package/dist/esm/utils/time.js +19 -0
- package/dist/esm/utils/time.js.map +1 -1
- package/dist/react-native/ClientContext.d.ts +19 -10
- package/dist/react-native/ClientContext.d.ts.map +1 -1
- package/dist/react-native/ClientContext.js +30 -11
- package/dist/react-native/ClientContext.js.map +1 -1
- package/dist/react-native/CosmosClient.d.ts.map +1 -1
- package/dist/react-native/CosmosClient.js +13 -2
- package/dist/react-native/CosmosClient.js.map +1 -1
- package/dist/react-native/PartitionKeyRangeFailoverInfo.d.ts +49 -0
- package/dist/react-native/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
- package/dist/react-native/PartitionKeyRangeFailoverInfo.js +130 -0
- package/dist/react-native/PartitionKeyRangeFailoverInfo.js.map +1 -0
- package/dist/react-native/client/ChangeFeed/ChangeFeedForPartitionKey.d.ts.map +1 -1
- package/dist/react-native/client/ChangeFeed/ChangeFeedForPartitionKey.js +4 -0
- package/dist/react-native/client/ChangeFeed/ChangeFeedForPartitionKey.js.map +1 -1
- package/dist/react-native/client/ClientUtils.d.ts +3 -1
- package/dist/react-native/client/ClientUtils.d.ts.map +1 -1
- package/dist/react-native/client/ClientUtils.js +10 -0
- package/dist/react-native/client/ClientUtils.js.map +1 -1
- package/dist/react-native/client/Item/Item.d.ts.map +1 -1
- package/dist/react-native/client/Item/Item.js +13 -0
- package/dist/react-native/client/Item/Item.js.map +1 -1
- package/dist/react-native/client/Item/Items.d.ts +1 -0
- package/dist/react-native/client/Item/Items.d.ts.map +1 -1
- package/dist/react-native/client/Item/Items.js +29 -3
- package/dist/react-native/client/Item/Items.js.map +1 -1
- package/dist/react-native/common/constants.d.ts +20 -0
- package/dist/react-native/common/constants.d.ts.map +1 -1
- package/dist/react-native/common/constants.js +23 -1
- package/dist/react-native/common/constants.js.map +1 -1
- package/dist/react-native/common/platform.d.ts +6 -1
- package/dist/react-native/common/platform.d.ts.map +1 -1
- package/dist/react-native/common/platform.js +23 -4
- package/dist/react-native/common/platform.js.map +1 -1
- package/dist/react-native/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
- package/dist/react-native/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
- package/dist/react-native/diagnostics/DiagnosticNodeInternal.js.map +1 -1
- package/dist/react-native/documents/ConnectionPolicy.d.ts +6 -0
- package/dist/react-native/documents/ConnectionPolicy.d.ts.map +1 -1
- package/dist/react-native/documents/ConnectionPolicy.js +2 -0
- package/dist/react-native/documents/ConnectionPolicy.js.map +1 -1
- package/dist/react-native/documents/DatabaseAccount.d.ts.map +1 -1
- package/dist/react-native/documents/DatabaseAccount.js +3 -0
- package/dist/react-native/documents/DatabaseAccount.js.map +1 -1
- package/dist/react-native/documents/PartitionKeyDefinition.d.ts +1 -1
- package/dist/react-native/documents/PartitionKeyDefinition.js.map +1 -1
- package/dist/react-native/encryption/Cache/ProtectedDataEncryptionKeyCache.d.ts.map +1 -1
- package/dist/react-native/encryption/Cache/ProtectedDataEncryptionKeyCache.js +2 -1
- package/dist/react-native/encryption/Cache/ProtectedDataEncryptionKeyCache.js.map +1 -1
- package/dist/react-native/encryption/EncryptionKeyStoreProvider.d.ts.map +1 -1
- package/dist/react-native/encryption/EncryptionKeyStoreProvider.js +2 -1
- package/dist/react-native/encryption/EncryptionKeyStoreProvider.js.map +1 -1
- package/dist/react-native/extractPartitionKey.d.ts.map +1 -1
- package/dist/react-native/extractPartitionKey.js +33 -20
- package/dist/react-native/extractPartitionKey.js.map +1 -1
- package/dist/react-native/globalEndpointManager.d.ts +6 -0
- package/dist/react-native/globalEndpointManager.d.ts.map +1 -1
- package/dist/react-native/globalEndpointManager.js +9 -4
- package/dist/react-native/globalEndpointManager.js.map +1 -1
- package/dist/react-native/globalPartitionEndpointManager.d.ts +79 -0
- package/dist/react-native/globalPartitionEndpointManager.d.ts.map +1 -0
- package/dist/react-native/globalPartitionEndpointManager.js +278 -0
- package/dist/react-native/globalPartitionEndpointManager.js.map +1 -0
- package/dist/react-native/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
- package/dist/react-native/queryExecutionContext/Aggregators/index.js +1 -0
- package/dist/react-native/queryExecutionContext/Aggregators/index.js.map +1 -1
- package/dist/react-native/queryExecutionContext/documentProducer.d.ts +2 -3
- package/dist/react-native/queryExecutionContext/documentProducer.d.ts.map +1 -1
- package/dist/react-native/queryExecutionContext/documentProducer.js +16 -21
- package/dist/react-native/queryExecutionContext/documentProducer.js.map +1 -1
- package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
- package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
- package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
- package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
- package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
- package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
- package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
- package/dist/react-native/queryIterator.d.ts.map +1 -1
- package/dist/react-native/queryIterator.js +2 -3
- package/dist/react-native/queryIterator.js.map +1 -1
- package/dist/react-native/request/ErrorResponse.d.ts +1 -1
- package/dist/react-native/request/ErrorResponse.d.ts.map +1 -1
- package/dist/react-native/request/ErrorResponse.js.map +1 -1
- package/dist/react-native/request/RequestContext.d.ts +5 -0
- package/dist/react-native/request/RequestContext.d.ts.map +1 -1
- package/dist/react-native/request/RequestContext.js.map +1 -1
- package/dist/react-native/request/RequestHandler.d.ts.map +1 -1
- package/dist/react-native/request/RequestHandler.js +14 -4
- package/dist/react-native/request/RequestHandler.js.map +1 -1
- package/dist/react-native/request/defaultAgent.js +2 -2
- package/dist/react-native/request/defaultAgent.js.map +1 -1
- package/dist/react-native/request/request.d.ts.map +1 -1
- package/dist/react-native/request/request.js +3 -3
- package/dist/react-native/request/request.js.map +1 -1
- package/dist/react-native/retry/RetryPolicy.d.ts +2 -2
- package/dist/react-native/retry/RetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/RetryPolicy.js.map +1 -1
- package/dist/react-native/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/defaultRetryPolicy.js +4 -8
- package/dist/react-native/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js +9 -2
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/react-native/retry/retryUtility.d.ts.map +1 -1
- package/dist/react-native/retry/retryUtility.js +11 -5
- package/dist/react-native/retry/retryUtility.js.map +1 -1
- package/dist/react-native/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
- package/dist/react-native/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/timeoutFailoverRetryPolicy.js +15 -7
- package/dist/react-native/retry/timeoutFailoverRetryPolicy.js.map +1 -1
- package/dist/react-native/routing/partitionKeyRangeCache.d.ts.map +1 -1
- package/dist/react-native/routing/partitionKeyRangeCache.js +11 -0
- package/dist/react-native/routing/partitionKeyRangeCache.js.map +1 -1
- package/dist/react-native/utils/checkURL.js +6 -0
- package/dist/react-native/utils/checkURL.js.map +1 -1
- package/dist/react-native/utils/hashing/hash.d.ts +2 -0
- package/dist/react-native/utils/hashing/hash.d.ts.map +1 -1
- package/dist/react-native/utils/hashing/hash.js +19 -0
- package/dist/react-native/utils/hashing/hash.js.map +1 -1
- package/dist/react-native/utils/time.d.ts +8 -0
- package/dist/react-native/utils/time.d.ts.map +1 -1
- package/dist/react-native/utils/time.js +19 -0
- package/dist/react-native/utils/time.js.map +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionKeyStoreProvider.js","sourceRoot":"","sources":["../../../src/encryption/EncryptionKeyStoreProvider.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,iDAA+C;
|
|
1
|
+
{"version":3,"file":"EncryptionKeyStoreProvider.js","sourceRoot":"","sources":["../../../src/encryption/EncryptionKeyStoreProvider.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,iDAA+C;AAC/C,8CAAuD;AAGvD;;GAEG;AACH,MAAa,0BAA0B;IAQrC,YACU,wBAA+C,EAC/C,eAAuB;QADvB,6BAAwB,GAAxB,wBAAwB,CAAuB;QAC/C,oBAAe,GAAf,eAAe,CAAQ;QAT1B,+BAA0B,GAAW,UAAU,CAAC;QAWrD,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;QACzD,IAAI,CAAC,YAAY,GAAG,wBAAwB,CAAC,yBAAyB,CAAC;QACvE,IAAI,CAAC,2BAA2B,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,qBAAqB,EAAE,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAC,OAAO,CAClB,eAAuB,EACvB,SAAiC,EACjC,GAAW;QAEX,MAAM,aAAa,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CACtE,eAAe,EACf,SAAS,EACT,aAAa,CACd,CAAC;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,oBA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C,GAAG,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;QACH,CAAC,EAAE,oBAAS,CAAC,kCAAkC,CAAC,CAAC;IACnD,CAAC;CACF;AAxED,gEAwEC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { Constants } from \"../common/index.js\";\nimport { startBackgroundTask } from \"../utils/time.js\";\nimport type { EncryptionKeyResolver } from \"./EncryptionKeyResolver/index.js\";\nimport type { KeyEncryptionAlgorithm } from \"./enums/index.js\";\n/**\n * Class to store encryption keys in unwrapped form and provide an interface for wrapping and unwrapping the keys.\n */\nexport class EncryptionKeyStoreProvider {\n public RsaOaepEncryptionAlgorithm: string = \"RSA-OAEP\";\n // interval for clear cache to run\n cacheRefresher: NodeJS.Timeout;\n\n // cache to store the unwrapped encryption key. Key is the path of the encryption key\n public unwrappedEncryptionKeyCache: { [key: string]: [Date, Buffer] };\n public providerName: string;\n constructor(\n private keyEncryptionKeyResolver: EncryptionKeyResolver,\n private cacheTimeToLive: number,\n ) {\n this.keyEncryptionKeyResolver = keyEncryptionKeyResolver;\n this.providerName = keyEncryptionKeyResolver.encryptionKeyResolverName;\n this.unwrappedEncryptionKeyCache = {};\n this.cacheTimeToLive = cacheTimeToLive;\n this.clearCacheOnTtlExpiry();\n }\n\n public async wrapKey(\n encryptionKeyId: string,\n algorithm: KeyEncryptionAlgorithm,\n key: Buffer,\n ): Promise<Buffer> {\n const uInt8ArrayKey = new Uint8Array(key);\n const wrappedEncryptionKey = await this.keyEncryptionKeyResolver.wrapKey(\n encryptionKeyId,\n algorithm,\n uInt8ArrayKey,\n );\n return Buffer.from(wrappedEncryptionKey);\n }\n\n public async unwrapKey(\n encryptionKeyId: string,\n algorithm: KeyEncryptionAlgorithm,\n wrappedKey: Buffer,\n ): Promise<Buffer> {\n if (this.cacheTimeToLive === 0) {\n const res = await this.keyEncryptionKeyResolver.unwrapKey(\n encryptionKeyId,\n algorithm,\n wrappedKey,\n );\n return Buffer.from(res);\n }\n if (!this.unwrappedEncryptionKeyCache[encryptionKeyId]) {\n const wrappedKeyUint8Array = new Uint8Array(wrappedKey);\n const plainEncryptionKey = await this.keyEncryptionKeyResolver.unwrapKey(\n encryptionKeyId,\n algorithm,\n wrappedKeyUint8Array,\n );\n const plainEncryptionKeyBuffer = Buffer.from(plainEncryptionKey);\n this.unwrappedEncryptionKeyCache[encryptionKeyId] = [new Date(), plainEncryptionKeyBuffer];\n }\n return this.unwrappedEncryptionKeyCache[encryptionKeyId][1];\n }\n\n private async clearCacheOnTtlExpiry(): Promise<void> {\n this.cacheRefresher = startBackgroundTask(async () => {\n const now = new Date();\n for (const key in this.unwrappedEncryptionKeyCache) {\n if (\n now.getTime() - this.unwrappedEncryptionKeyCache[key][0].getTime() >\n this.cacheTimeToLive\n ) {\n delete this.unwrappedEncryptionKeyCache[key];\n }\n }\n }, Constants.EncryptionCacheRefreshIntervalInMs);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractPartitionKey.d.ts","sourceRoot":"","sources":["../../src/extractPartitionKey.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,EAErB,MAAM,sBAAsB,CAAC;AAO9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AAItF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EACjB,sBAAsB,CAAC,EAAE,sBAAsB,GAC9C,oBAAoB,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"extractPartitionKey.d.ts","sourceRoot":"","sources":["../../src/extractPartitionKey.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,EAErB,MAAM,sBAAsB,CAAC;AAO9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AAItF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EACjB,sBAAsB,CAAC,EAAE,sBAAsB,GAC9C,oBAAoB,GAAG,SAAS,CA0ClC;AAsBD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,sBAAsB,EAAE,sBAAsB,GAC7C,oBAAoB,CAMtB;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,cAAc,EAAE,sBAAsB,EACtC,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,oBAAoB,CAAC,CAM/B"}
|
|
@@ -19,29 +19,42 @@ const logger = (0, logger_1.createClientLogger)("extractPartitionKey");
|
|
|
19
19
|
* @hidden
|
|
20
20
|
*/
|
|
21
21
|
function extractPartitionKeys(document, partitionKeyDefinition) {
|
|
22
|
-
if (partitionKeyDefinition
|
|
23
|
-
partitionKeyDefinition.paths
|
|
24
|
-
partitionKeyDefinition.paths.length
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
if (!partitionKeyDefinition ||
|
|
23
|
+
!partitionKeyDefinition.paths ||
|
|
24
|
+
partitionKeyDefinition.paths.length <= 0) {
|
|
25
|
+
logger.error("Unexpected Partition Key Definition Found.");
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
if (partitionKeyDefinition.paths.length === 1 &&
|
|
29
|
+
partitionKeyDefinition.paths[0] === partitionKeys_js_1.DEFAULT_PARTITION_KEY_PATH) {
|
|
30
|
+
const defaultKey = extractPartitionKey(partitionKeys_js_1.DEFAULT_PARTITION_KEY_PATH, document);
|
|
31
|
+
if (defaultKey === undefined) {
|
|
32
|
+
if (partitionKeyDefinition.systemKey === true) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
logger.warning("Unsupported PartitionKey found.");
|
|
36
|
+
return undefined;
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (obj === undefined) {
|
|
36
|
-
logger.warning("Unsupported PartitionKey found.");
|
|
37
|
-
return undefined;
|
|
38
|
+
else if (defaultKey === index_js_2.NullPartitionKeyLiteral || defaultKey === index_js_2.NonePartitionKeyLiteral) {
|
|
39
|
+
if (partitionKeyDefinition.systemKey === true) {
|
|
40
|
+
return [];
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return partitionKeys;
|
|
42
|
+
}
|
|
43
|
+
return [defaultKey];
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
if (partitionKeyDefinition.systemKey === true) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const partitionKeys = [];
|
|
49
|
+
partitionKeyDefinition.paths.forEach((path) => {
|
|
50
|
+
const obj = extractPartitionKey(path, document);
|
|
51
|
+
if (obj === undefined) {
|
|
52
|
+
logger.warning("Unsupported PartitionKey found.");
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
partitionKeys.push(obj);
|
|
56
|
+
});
|
|
57
|
+
return partitionKeys;
|
|
45
58
|
}
|
|
46
59
|
function extractPartitionKey(path, obj) {
|
|
47
60
|
const pathParts = (0, index_js_1.parsePath)(path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractPartitionKey.js","sourceRoot":"","sources":["../../src/extractPartitionKey.ts"],"names":[],"mappings":";;AAgCA,
|
|
1
|
+
{"version":3,"file":"extractPartitionKey.js","sourceRoot":"","sources":["../../src/extractPartitionKey.ts"],"names":[],"mappings":";;AAgCA,oDA6CC;AAyBD,sDAQC;AAKD,gEAUC;AA1HD,0CAAmD;AACnD,gDAA8C;AAO9C,mDAI8B;AAC9B,gEAAuE;AAEvE,4DAAqE;AAGrE,MAAM,MAAM,GAAgB,IAAA,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OAAO,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,CAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,kCAAuB,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,0BAA0B,CAC9C,cAAsC,EACtC,SAAoB,EACpB,YAA0B;IAE1B,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,sBAAsB,GAAG,MAAM,IAAA,2CAA0B,EAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QAC3F,YAAY,GAAG,qBAAqB,CAAC,sBAAsB,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,IAAA,wCAA6B,EAAC,YAAY,CAAC,CAAC;AACrD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { AzureLogger } from \"@azure/logger\";\nimport { createClientLogger } from \"@azure/logger\";\nimport { parsePath } from \"./common/index.js\";\nimport type {\n PartitionKey,\n PartitionKeyDefinition,\n PartitionKeyInternal,\n PrimitivePartitionKeyValue,\n} from \"./documents/index.js\";\nimport {\n convertToInternalPartitionKey,\n NonePartitionKeyLiteral,\n NullPartitionKeyLiteral,\n} from \"./documents/index.js\";\nimport { DEFAULT_PARTITION_KEY_PATH } from \"./common/partitionKeys.js\";\nimport type { Container } from \"./client/index.js\";\nimport { readPartitionKeyDefinition } from \"./client/ClientUtils.js\";\nimport type { DiagnosticNodeInternal } from \"./diagnostics/DiagnosticNodeInternal.js\";\n\nconst logger: AzureLogger = createClientLogger(\"extractPartitionKey\");\n\n/**\n * Function to extract PartitionKey based on {@link PartitionKeyDefinition}\n * from an object.\n * Retuns\n * 1. PartitionKeyInternal[] if extraction is successful.\n * 2. undefined if either {@link partitionKeyDefinition} is not well formed\n * or an unsupported partitionkey type is encountered.\n * @hidden\n */\nexport function extractPartitionKeys(\n document: unknown,\n partitionKeyDefinition?: PartitionKeyDefinition,\n): PartitionKeyInternal | undefined {\n if (\n !partitionKeyDefinition ||\n !partitionKeyDefinition.paths ||\n partitionKeyDefinition.paths.length <= 0\n ) {\n logger.error(\"Unexpected Partition Key Definition Found.\");\n return undefined;\n }\n\n if (\n partitionKeyDefinition.paths.length === 1 &&\n partitionKeyDefinition.paths[0] === DEFAULT_PARTITION_KEY_PATH\n ) {\n const defaultKey = extractPartitionKey(DEFAULT_PARTITION_KEY_PATH, document);\n if (defaultKey === undefined) {\n if (partitionKeyDefinition.systemKey === true) {\n return [];\n }\n logger.warning(\"Unsupported PartitionKey found.\");\n return undefined;\n } else if (defaultKey === NullPartitionKeyLiteral || defaultKey === NonePartitionKeyLiteral) {\n if (partitionKeyDefinition.systemKey === true) {\n return [];\n }\n }\n return [defaultKey];\n }\n\n if (partitionKeyDefinition.systemKey === true) {\n return [];\n }\n const partitionKeys: PrimitivePartitionKeyValue[] = [];\n partitionKeyDefinition.paths.forEach((path: string) => {\n const obj = extractPartitionKey(path, document);\n if (obj === undefined) {\n logger.warning(\"Unsupported PartitionKey found.\");\n return undefined;\n }\n partitionKeys.push(obj);\n });\n return partitionKeys;\n}\n\nfunction extractPartitionKey(path: string, obj: unknown): any {\n const pathParts: string[] = parsePath(path);\n for (const part of pathParts) {\n if (typeof obj === \"object\" && obj !== null && part in obj) {\n obj = (obj as Record<string, unknown>)[part];\n } else {\n obj = undefined;\n break;\n }\n }\n if (typeof obj === \"string\" || typeof obj === \"number\" || typeof obj === \"boolean\") {\n return obj;\n } else if (obj === NullPartitionKeyLiteral) {\n return NullPartitionKeyLiteral;\n } else if (obj === undefined || JSON.stringify(obj) === JSON.stringify(NonePartitionKeyLiteral)) {\n return NonePartitionKeyLiteral;\n }\n return undefined;\n}\n\n/**\n * @hidden\n */\nexport function undefinedPartitionKey(\n partitionKeyDefinition: PartitionKeyDefinition,\n): PartitionKeyInternal {\n if (partitionKeyDefinition?.systemKey) {\n return [];\n } else {\n return partitionKeyDefinition?.paths.map(() => NonePartitionKeyLiteral);\n }\n}\n\n/**\n * @hidden\n */\nexport async function setPartitionKeyIfUndefined(\n diagnosticNode: DiagnosticNodeInternal,\n container: Container,\n partitionKey: PartitionKey,\n): Promise<PartitionKeyInternal> {\n if (partitionKey === undefined) {\n const partitionKeyDefinition = await readPartitionKeyDefinition(diagnosticNode, container);\n partitionKey = undefinedPartitionKey(partitionKeyDefinition);\n }\n return convertToInternalPartitionKey(partitionKey);\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OperationType, ResourceType } from "./common/index.js";
|
|
2
|
+
import type { Location } from "./documents/index.js";
|
|
2
3
|
import type { DiagnosticNodeInternal } from "./diagnostics/DiagnosticNodeInternal.js";
|
|
3
4
|
/**
|
|
4
5
|
* @hidden
|
|
@@ -24,6 +25,7 @@ export declare class GlobalEndpointManager {
|
|
|
24
25
|
private readableLocations;
|
|
25
26
|
private unavailableReadableLocations;
|
|
26
27
|
private unavailableWriteableLocations;
|
|
28
|
+
private enableMultipleWriteLocations;
|
|
27
29
|
preferredLocationsCount: number;
|
|
28
30
|
/**
|
|
29
31
|
* Gets the current read endpoint from the endpoint cache.
|
|
@@ -35,6 +37,10 @@ export declare class GlobalEndpointManager {
|
|
|
35
37
|
getWriteEndpoint(diagnosticNode: DiagnosticNodeInternal): Promise<string>;
|
|
36
38
|
getReadEndpoints(): Promise<ReadonlyArray<string>>;
|
|
37
39
|
getWriteEndpoints(): Promise<ReadonlyArray<string>>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the read locations from the endpoint cache.
|
|
42
|
+
*/
|
|
43
|
+
getReadLocations(): Promise<ReadonlyArray<Location>>;
|
|
38
44
|
markCurrentLocationUnavailableForRead(diagnosticNode: DiagnosticNodeInternal, endpoint: string): Promise<void>;
|
|
39
45
|
markCurrentLocationUnavailableForWrite(diagnosticNode: DiagnosticNodeInternal, endpoint: string): Promise<void>;
|
|
40
46
|
canUseMultipleWriteLocations(resourceType?: ResourceType, operationType?: OperationType): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalEndpointManager.d.ts","sourceRoot":"","sources":["../../src/globalEndpointManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAiB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"globalEndpointManager.d.ts","sourceRoot":"","sources":["../../src/globalEndpointManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAiB,MAAM,mBAAmB,CAAC;AAE/E,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAKtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AAItF;;;GAGG;AACH,qBAAa,qBAAqB;IA4B9B,OAAO,CAAC,mBAAmB;IA3B7B;;OAEG;IACH,OAAO,CAAC,eAAe,CAAS;IAChC;;OAEG;IACI,uBAAuB,EAAE,OAAO,CAAC;IACxC,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,OAAO,CAAsB;IACrC;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAAW;IACrC,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,iBAAiB,CAAkB;IAC3C,OAAO,CAAC,4BAA4B,CAAkB;IACtD,OAAO,CAAC,6BAA6B,CAAkB;IACvD,OAAO,CAAC,4BAA4B,CAAU;IAEvC,uBAAuB,EAAE,MAAM,CAAC;IAoBvC;;OAEG;IACU,eAAe,CAAC,cAAc,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrF;;OAEG;IACU,gBAAgB,CAAC,cAAc,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzE,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAIlD,iBAAiB,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAIhE;;OAEG;IACU,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAIpD,qCAAqC,CAChD,cAAc,EAAE,sBAAsB,EACtC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAUH,sCAAsC,CACjD,cAAc,EAAE,sBAAsB,EACtC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAYT,4BAA4B,CACjC,YAAY,CAAC,EAAE,YAAY,EAC3B,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO;IAcG,sBAAsB,CACjC,cAAc,EAAE,sBAAsB,EACtC,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,EAC5B,yBAAyB,GAAE,MAAU,GACpC,OAAO,CAAC,MAAM,CAAC;IAyElB;;;;;OAKG;IACU,mBAAmB,CAAC,cAAc,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvF,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,gCAAgC;IAexC;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAiBtB,OAAO,CAAC,4BAA4B;IAYpC;;;;OAIG;YACW,iCAAiC;IAuC/C;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;CA4BrC"}
|
|
@@ -7,6 +7,7 @@ const index_js_1 = require("./common/index.js");
|
|
|
7
7
|
const constants_js_1 = require("./common/constants.js");
|
|
8
8
|
const CosmosDiagnostics_js_1 = require("./CosmosDiagnostics.js");
|
|
9
9
|
const diagnostics_js_1 = require("./utils/diagnostics.js");
|
|
10
|
+
const checkURL_js_1 = require("./utils/checkURL.js");
|
|
10
11
|
/**
|
|
11
12
|
* @hidden
|
|
12
13
|
* This internal class implements the logic for endpoint management for geo-replicated database accounts.
|
|
@@ -47,6 +48,12 @@ class GlobalEndpointManager {
|
|
|
47
48
|
async getWriteEndpoints() {
|
|
48
49
|
return this.writeableLocations.map((loc) => loc.databaseAccountEndpoint);
|
|
49
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets the read locations from the endpoint cache.
|
|
53
|
+
*/
|
|
54
|
+
async getReadLocations() {
|
|
55
|
+
return this.readableLocations;
|
|
56
|
+
}
|
|
50
57
|
async markCurrentLocationUnavailableForRead(diagnosticNode, endpoint) {
|
|
51
58
|
await this.refreshEndpointList(diagnosticNode);
|
|
52
59
|
const location = this.readableLocations.find((loc) => loc.databaseAccountEndpoint === endpoint);
|
|
@@ -66,7 +73,7 @@ class GlobalEndpointManager {
|
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
canUseMultipleWriteLocations(resourceType, operationType) {
|
|
69
|
-
let canUse = this.options.connectionPolicy.useMultipleWriteLocations;
|
|
76
|
+
let canUse = this.options.connectionPolicy.useMultipleWriteLocations && this.enableMultipleWriteLocations;
|
|
70
77
|
if (resourceType) {
|
|
71
78
|
canUse =
|
|
72
79
|
canUse &&
|
|
@@ -96,6 +103,7 @@ class GlobalEndpointManager {
|
|
|
96
103
|
}, diagnosticNode, CosmosDiagnostics_js_1.MetadataLookUpType.DatabaseAccountLookUp);
|
|
97
104
|
this.writeableLocations = resourceResponse.resource.writableLocations;
|
|
98
105
|
this.readableLocations = resourceResponse.resource.readableLocations;
|
|
106
|
+
this.enableMultipleWriteLocations = resourceResponse.resource.enableMultipleWritableLocations;
|
|
99
107
|
}
|
|
100
108
|
const locations = (0, index_js_1.isReadRequest)(operationType)
|
|
101
109
|
? this.readableLocations
|
|
@@ -108,7 +116,7 @@ class GlobalEndpointManager {
|
|
|
108
116
|
for (let i = startServiceEndpointIndex; i < this.preferredLocations.length; i++) {
|
|
109
117
|
const preferredLocation = this.preferredLocations[i];
|
|
110
118
|
location = locations.find((loc) => loc.unavailable !== true &&
|
|
111
|
-
normalizeEndpoint(loc.name) === normalizeEndpoint(preferredLocation));
|
|
119
|
+
(0, checkURL_js_1.normalizeEndpoint)(loc.name) === (0, checkURL_js_1.normalizeEndpoint)(preferredLocation));
|
|
112
120
|
if (location) {
|
|
113
121
|
break;
|
|
114
122
|
}
|
|
@@ -258,7 +266,4 @@ class GlobalEndpointManager {
|
|
|
258
266
|
}
|
|
259
267
|
}
|
|
260
268
|
exports.GlobalEndpointManager = GlobalEndpointManager;
|
|
261
|
-
function normalizeEndpoint(endpoint) {
|
|
262
|
-
return endpoint.split(" ").join("").toLowerCase();
|
|
263
|
-
}
|
|
264
269
|
//# sourceMappingURL=globalEndpointManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalEndpointManager.js","sourceRoot":"","sources":["../../src/globalEndpointManager.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,gDAA+E;AAI/E,wDAAkD;AAElD,iEAA4D;AAE5D,2DAAiE;AAEjE;;;GAGG;AACH,MAAa,qBAAqB;IAqBhC;;;OAGG;IACH,YACE,OAA4B,EACpB,mBAGuC;QAHvC,wBAAmB,GAAnB,mBAAmB,CAGoB;QAfzC,uBAAkB,GAAe,EAAE,CAAC;QACpC,sBAAiB,GAAe,EAAE,CAAC;QACnC,iCAA4B,GAAe,EAAE,CAAC;QAC9C,kCAA6B,GAAe,EAAE,CAAC;QAcrD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;QACxC,IAAI,CAAC,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,CAAC;QAChF,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,kBAAkB,CAAC;QAC3E,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9F,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,eAAe,CAAC,cAAsC;QACjE,OAAO,IAAI,CAAC,sBAAsB,CAAC,cA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A6B,CAAC,CAAC;gBACrE,OAAO,kBAAkB,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAxVD,sDAwVC;AAED,SAAS,iBAAiB,CAAC,QAAgB;IACzC,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AACpD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { OperationType, ResourceType, isReadRequest } from \"./common/index.js\";\nimport type { CosmosClientOptions } from \"./CosmosClientOptions.js\";\nimport type { Location, DatabaseAccount } from \"./documents/index.js\";\nimport type { RequestOptions } from \"./index.js\";\nimport { Constants } from \"./common/constants.js\";\nimport type { ResourceResponse } from \"./request/index.js\";\nimport { MetadataLookUpType } from \"./CosmosDiagnostics.js\";\nimport type { DiagnosticNodeInternal } from \"./diagnostics/DiagnosticNodeInternal.js\";\nimport { withMetadataDiagnostics } from \"./utils/diagnostics.js\";\n\n/**\n * @hidden\n * This internal class implements the logic for endpoint management for geo-replicated database accounts.\n */\nexport class GlobalEndpointManager {\n /**\n * The endpoint used to create the client instance.\n */\n private defaultEndpoint: string;\n /**\n * Flag to enable/disable automatic redirecting of requests based on read/write operations.\n */\n public enableEndpointDiscovery: boolean;\n private isRefreshing: boolean;\n private options: CosmosClientOptions;\n /**\n * List of azure regions to be used as preferred locations for read requests.\n */\n private preferredLocations: string[];\n private writeableLocations: Location[] = [];\n private readableLocations: Location[] = [];\n private unavailableReadableLocations: Location[] = [];\n private unavailableWriteableLocations: Location[] = [];\n\n public preferredLocationsCount: number;\n /**\n * @param options - The document client instance.\n * @internal\n */\n constructor(\n options: CosmosClientOptions,\n private readDatabaseAccount: (\n diagnosticNode: DiagnosticNodeInternal,\n opts: RequestOptions,\n ) => Promise<ResourceResponse<DatabaseAccount>>,\n ) {\n this.options = options;\n this.defaultEndpoint = options.endpoint;\n this.enableEndpointDiscovery = options.connectionPolicy.enableEndpointDiscovery;\n this.isRefreshing = false;\n this.preferredLocations = this.options.connectionPolicy.preferredLocations;\n this.preferredLocationsCount = this.preferredLocations ? this.preferredLocations.length : 0;\n }\n\n /**\n * Gets the current read endpoint from the endpoint cache.\n */\n public async getReadEndpoint(diagnosticNode: DiagnosticNodeInternal): Promise<string> {\n return this.resolveServiceEndpoint(diagnosticNode, ResourceType.item, OperationType.Read);\n }\n\n /**\n * Gets the current write endpoint from the endpoint cache.\n */\n public async getWriteEndpoint(diagnosticNode: DiagnosticNodeInternal): Promise<string> {\n return this.resolveServiceEndpoint(diagnosticNode, ResourceType.item, OperationType.Replace);\n }\n\n public async getReadEndpoints(): Promise<ReadonlyArray<string>> {\n return this.readableLocations.map((loc) => loc.databaseAccountEndpoint);\n }\n\n public async getWriteEndpoints(): Promise<ReadonlyArray<string>> {\n return this.writeableLocations.map((loc) => loc.databaseAccountEndpoint);\n }\n\n public async markCurrentLocationUnavailableForRead(\n diagnosticNode: DiagnosticNodeInternal,\n endpoint: string,\n ): Promise<void> {\n await this.refreshEndpointList(diagnosticNode);\n const location = this.readableLocations.find((loc) => loc.databaseAccountEndpoint === endpoint);\n if (location) {\n location.unavailable = true;\n location.lastUnavailabilityTimestampInMs = Date.now();\n this.unavailableReadableLocations.push(location);\n }\n }\n\n public async markCurrentLocationUnavailableForWrite(\n diagnosticNode: DiagnosticNodeInternal,\n endpoint: string,\n ): Promise<void> {\n await this.refreshEndpointList(diagnosticNode);\n const location = this.writeableLocations.find(\n (loc) => loc.databaseAccountEndpoint === endpoint,\n );\n if (location) {\n location.unavailable = true;\n location.lastUnavailabilityTimestampInMs = Date.now();\n this.unavailableWriteableLocations.push(location);\n }\n }\n\n public canUseMultipleWriteLocations(\n resourceType?: ResourceType,\n operationType?: OperationType,\n ): boolean {\n let canUse = this.options.connectionPolicy.useMultipleWriteLocations;\n\n if (resourceType) {\n canUse =\n canUse &&\n (resourceType === ResourceType.item ||\n (resourceType === ResourceType.sproc && operationType === OperationType.Execute));\n }\n\n return canUse;\n }\n\n public async resolveServiceEndpoint(\n diagnosticNode: DiagnosticNodeInternal,\n resourceType: ResourceType,\n operationType: OperationType,\n startServiceEndpointIndex: number = 0, // Represents the starting index for selecting servers.\n ): Promise<string> {\n // If endpoint discovery is disabled, always use the user provided endpoint\n\n if (!this.options.connectionPolicy.enableEndpointDiscovery) {\n diagnosticNode.addData({ readFromCache: true }, \"default_endpoint\");\n diagnosticNode.recordEndpointResolution(this.defaultEndpoint);\n return this.defaultEndpoint;\n }\n\n // If getting the database account, always use the user provided endpoint\n if (resourceType === ResourceType.none) {\n diagnosticNode.addData({ readFromCache: true }, \"none_resource\");\n diagnosticNode.recordEndpointResolution(this.defaultEndpoint);\n return this.defaultEndpoint;\n }\n\n if (this.readableLocations.length === 0 || this.writeableLocations.length === 0) {\n const resourceResponse = await withMetadataDiagnostics(\n async (metadataNode: DiagnosticNodeInternal) => {\n return this.readDatabaseAccount(metadataNode, {\n urlConnection: this.defaultEndpoint,\n });\n },\n diagnosticNode,\n MetadataLookUpType.DatabaseAccountLookUp,\n );\n\n this.writeableLocations = resourceResponse.resource.writableLocations;\n this.readableLocations = resourceResponse.resource.readableLocations;\n }\n\n const locations = isReadRequest(operationType)\n ? this.readableLocations\n : this.writeableLocations;\n\n let location;\n // If we have preferred locations, try each one in order and use the first available one\n if (\n this.preferredLocations &&\n this.preferredLocations.length > 0 &&\n startServiceEndpointIndex < this.preferredLocations.length\n ) {\n for (let i = startServiceEndpointIndex; i < this.preferredLocations.length; i++) {\n const preferredLocation = this.preferredLocations[i];\n location = locations.find(\n (loc) =>\n loc.unavailable !== true &&\n normalizeEndpoint(loc.name) === normalizeEndpoint(preferredLocation),\n );\n if (location) {\n break;\n }\n }\n }\n\n // If no preferred locations or one did not match, just grab the first one that is available\n if (!location) {\n const startIndexValid =\n startServiceEndpointIndex >= 0 && startServiceEndpointIndex < locations.length;\n const locationsToSearch = startIndexValid\n ? locations.slice(startServiceEndpointIndex)\n : locations;\n location = locationsToSearch.find((loc) => {\n return loc.unavailable !== true;\n });\n }\n\n location = location ? location : { name: \"\", databaseAccountEndpoint: this.defaultEndpoint };\n diagnosticNode.recordEndpointResolution(location.databaseAccountEndpoint);\n return location.databaseAccountEndpoint;\n }\n\n /**\n * Refreshes the endpoint list by clearning stale unavailability and then\n * retrieving the writable and readable locations from the geo-replicated database account\n * and then updating the locations cache.\n * We skip the refreshing if enableEndpointDiscovery is set to False\n */\n public async refreshEndpointList(diagnosticNode: DiagnosticNodeInternal): Promise<void> {\n if (!this.isRefreshing && this.enableEndpointDiscovery) {\n this.isRefreshing = true;\n const databaseAccount = await this.getDatabaseAccountFromAnyEndpoint(diagnosticNode);\n if (databaseAccount) {\n this.refreshStaleUnavailableLocations();\n this.refreshEndpoints(databaseAccount);\n }\n this.isRefreshing = false;\n }\n }\n\n private refreshEndpoints(databaseAccount: DatabaseAccount): void {\n for (const location of databaseAccount.writableLocations) {\n const existingLocation = this.writeableLocations.find((loc) => loc.name === location.name);\n if (!existingLocation) {\n this.writeableLocations.push(location);\n }\n }\n for (const location of databaseAccount.readableLocations) {\n const existingLocation = this.readableLocations.find((loc) => loc.name === location.name);\n if (!existingLocation) {\n this.readableLocations.push(location);\n }\n }\n }\n\n private refreshStaleUnavailableLocations(): void {\n const now = Date.now();\n this.updateLocation(now, this.unavailableReadableLocations, this.readableLocations);\n this.unavailableReadableLocations = this.cleanUnavailableLocationList(\n now,\n this.unavailableReadableLocations,\n );\n\n this.updateLocation(now, this.unavailableWriteableLocations, this.writeableLocations);\n this.unavailableWriteableLocations = this.cleanUnavailableLocationList(\n now,\n this.unavailableWriteableLocations,\n );\n }\n\n /**\n * update the locationUnavailability to undefined if the location is available again\n * @param now - current time\n * @param unavailableLocations - list of unavailable locations\n * @param allLocations - list of all locations\n */\n private updateLocation(\n now: number,\n unavailableLocations: Location[],\n allLocations: Location[],\n ): void {\n for (const location of unavailableLocations) {\n const unavaialableLocation = allLocations.find((loc) => loc.name === location.name);\n if (\n unavaialableLocation &&\n now - unavaialableLocation.lastUnavailabilityTimestampInMs >\n Constants.LocationUnavailableExpirationTimeInMs\n ) {\n unavaialableLocation.unavailable = false;\n }\n }\n }\n\n private cleanUnavailableLocationList(now: number, unavailableLocations: Location[]): Location[] {\n return unavailableLocations.filter((loc) => {\n if (\n loc &&\n now - loc.lastUnavailabilityTimestampInMs >= Constants.LocationUnavailableExpirationTimeInMs\n ) {\n return false;\n }\n return true;\n });\n }\n\n /**\n * Gets the database account first by using the default endpoint, and if that doesn't returns\n * use the endpoints for the preferred locations in the order they are specified to get\n * the database account.\n */\n private async getDatabaseAccountFromAnyEndpoint(\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<DatabaseAccount> {\n try {\n const options = { urlConnection: this.defaultEndpoint };\n const { resource: databaseAccount } = await this.readDatabaseAccount(diagnosticNode, options);\n return databaseAccount;\n // If for any reason(non - globaldb related), we are not able to get the database\n // account from the above call to readDatabaseAccount,\n // we would try to get this information from any of the preferred locations that the user\n // might have specified (by creating a locational endpoint)\n // and keeping eating the exception until we get the database account and return None at the end,\n // if we are not able to get that info from any endpoints\n } catch (err: any) {\n // TODO: Tracing\n }\n\n if (this.preferredLocations) {\n for (const location of this.preferredLocations) {\n try {\n const locationalEndpoint = GlobalEndpointManager.getLocationalEndpoint(\n this.defaultEndpoint,\n location,\n );\n const options = { urlConnection: locationalEndpoint };\n const { resource: databaseAccount } = await this.readDatabaseAccount(\n diagnosticNode,\n options,\n );\n if (databaseAccount) {\n return databaseAccount;\n }\n } catch (err: any) {\n // TODO: Tracing\n }\n }\n }\n }\n\n /**\n * Gets the locational endpoint using the location name passed to it using the default endpoint.\n *\n * @param defaultEndpoint - The default endpoint to use for the endpoint.\n * @param locationName - The location name for the azure region like \"East US\".\n */\n private static getLocationalEndpoint(defaultEndpoint: string, locationName: string): string {\n // For defaultEndpoint like 'https://contoso.documents.azure.com:443/' parse it to generate URL format\n // This defaultEndpoint should be global endpoint(and cannot be a locational endpoint)\n // and we agreed to document that\n const endpointUrl = new URL(defaultEndpoint);\n\n // hostname attribute in endpointUrl will return 'contoso.documents.azure.com'\n if (endpointUrl.hostname) {\n const hostnameParts = endpointUrl.hostname.toString().toLowerCase().split(\".\");\n if (hostnameParts) {\n // globalDatabaseAccountName will return 'contoso'\n const globalDatabaseAccountName = hostnameParts[0];\n\n // Prepare the locationalDatabaseAccountName as contoso-EastUS for location_name 'East US'\n const locationalDatabaseAccountName =\n globalDatabaseAccountName + \"-\" + locationName.replace(\" \", \"\");\n\n // Replace 'contoso' with 'contoso-EastUS' and\n // return locationalEndpoint as https://contoso-EastUS.documents.azure.com:443/\n const locationalEndpoint = defaultEndpoint\n .toLowerCase()\n .replace(globalDatabaseAccountName, locationalDatabaseAccountName);\n return locationalEndpoint;\n }\n }\n\n return null;\n }\n}\n\nfunction normalizeEndpoint(endpoint: string): string {\n return endpoint.split(\" \").join(\"\").toLowerCase();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"globalEndpointManager.js","sourceRoot":"","sources":["../../src/globalEndpointManager.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,gDAA+E;AAI/E,wDAAkD;AAElD,iEAA4D;AAE5D,2DAAiE;AACjE,qDAAwD;AAExD;;;GAGG;AACH,MAAa,qBAAqB;IAsBhC;;;OAGG;IACH,YACE,OAA4B,EACpB,mBAGuC;QAHvC,wBAAmB,GAAnB,mBAAmB,CAGoB;QAhBzC,uBAAkB,GAAe,EAAE,CAAC;QACpC,sBAAiB,GAAe,EAAE,CAAC;QACnC,iCAA4B,GAAe,EAAE,CAAC;QAC9C,kCAA6B,GAAe,EAAE,CAAC;QAerD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;QACxC,IAAI,CAAC,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,CAAC;QAChF,IAAI,CAAC,YAAY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e,CAAC,CAAC;QAE7C,8EAA8E;QAC9E,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,aAAa,GAAG,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC/E,IAAI,aAAa,EAAE,CAAC;gBAClB,kDAAkD;gBAClD,MAAM,yBAAyB,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;gBAEnD,0FAA0F;gBAC1F,MAAM,6BAA6B,GACjC,yBAAyB,GAAG,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBAElE,8CAA8C;gBAC9C,+EAA+E;gBAC/E,MAAM,kBAAkB,GAAG,eAAe;qBACvC,WAAW,EAAE;qBACb,OAAO,CAAC,yBAAyB,EAAE,6BAA6B,CAAC,CAAC;gBACrE,OAAO,kBAAkB,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlWD,sDAkWC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { OperationType, ResourceType, isReadRequest } from \"./common/index.js\";\nimport type { CosmosClientOptions } from \"./CosmosClientOptions.js\";\nimport type { Location, DatabaseAccount } from \"./documents/index.js\";\nimport type { RequestOptions } from \"./index.js\";\nimport { Constants } from \"./common/constants.js\";\nimport type { ResourceResponse } from \"./request/index.js\";\nimport { MetadataLookUpType } from \"./CosmosDiagnostics.js\";\nimport type { DiagnosticNodeInternal } from \"./diagnostics/DiagnosticNodeInternal.js\";\nimport { withMetadataDiagnostics } from \"./utils/diagnostics.js\";\nimport { normalizeEndpoint } from \"./utils/checkURL.js\";\n\n/**\n * @hidden\n * This internal class implements the logic for endpoint management for geo-replicated database accounts.\n */\nexport class GlobalEndpointManager {\n /**\n * The endpoint used to create the client instance.\n */\n private defaultEndpoint: string;\n /**\n * Flag to enable/disable automatic redirecting of requests based on read/write operations.\n */\n public enableEndpointDiscovery: boolean;\n private isRefreshing: boolean;\n private options: CosmosClientOptions;\n /**\n * List of azure regions to be used as preferred locations for read requests.\n */\n private preferredLocations: string[];\n private writeableLocations: Location[] = [];\n private readableLocations: Location[] = [];\n private unavailableReadableLocations: Location[] = [];\n private unavailableWriteableLocations: Location[] = [];\n private enableMultipleWriteLocations: boolean;\n\n public preferredLocationsCount: number;\n /**\n * @param options - The document client instance.\n * @internal\n */\n constructor(\n options: CosmosClientOptions,\n private readDatabaseAccount: (\n diagnosticNode: DiagnosticNodeInternal,\n opts: RequestOptions,\n ) => Promise<ResourceResponse<DatabaseAccount>>,\n ) {\n this.options = options;\n this.defaultEndpoint = options.endpoint;\n this.enableEndpointDiscovery = options.connectionPolicy.enableEndpointDiscovery;\n this.isRefreshing = false;\n this.preferredLocations = this.options.connectionPolicy.preferredLocations;\n this.preferredLocationsCount = this.preferredLocations ? this.preferredLocations.length : 0;\n }\n\n /**\n * Gets the current read endpoint from the endpoint cache.\n */\n public async getReadEndpoint(diagnosticNode: DiagnosticNodeInternal): Promise<string> {\n return this.resolveServiceEndpoint(diagnosticNode, ResourceType.item, OperationType.Read);\n }\n\n /**\n * Gets the current write endpoint from the endpoint cache.\n */\n public async getWriteEndpoint(diagnosticNode: DiagnosticNodeInternal): Promise<string> {\n return this.resolveServiceEndpoint(diagnosticNode, ResourceType.item, OperationType.Replace);\n }\n\n public async getReadEndpoints(): Promise<ReadonlyArray<string>> {\n return this.readableLocations.map((loc) => loc.databaseAccountEndpoint);\n }\n\n public async getWriteEndpoints(): Promise<ReadonlyArray<string>> {\n return this.writeableLocations.map((loc) => loc.databaseAccountEndpoint);\n }\n\n /**\n * Gets the read locations from the endpoint cache.\n */\n public async getReadLocations(): Promise<ReadonlyArray<Location>> {\n return this.readableLocations;\n }\n\n public async markCurrentLocationUnavailableForRead(\n diagnosticNode: DiagnosticNodeInternal,\n endpoint: string,\n ): Promise<void> {\n await this.refreshEndpointList(diagnosticNode);\n const location = this.readableLocations.find((loc) => loc.databaseAccountEndpoint === endpoint);\n if (location) {\n location.unavailable = true;\n location.lastUnavailabilityTimestampInMs = Date.now();\n this.unavailableReadableLocations.push(location);\n }\n }\n\n public async markCurrentLocationUnavailableForWrite(\n diagnosticNode: DiagnosticNodeInternal,\n endpoint: string,\n ): Promise<void> {\n await this.refreshEndpointList(diagnosticNode);\n const location = this.writeableLocations.find(\n (loc) => loc.databaseAccountEndpoint === endpoint,\n );\n if (location) {\n location.unavailable = true;\n location.lastUnavailabilityTimestampInMs = Date.now();\n this.unavailableWriteableLocations.push(location);\n }\n }\n\n public canUseMultipleWriteLocations(\n resourceType?: ResourceType,\n operationType?: OperationType,\n ): boolean {\n let canUse =\n this.options.connectionPolicy.useMultipleWriteLocations && this.enableMultipleWriteLocations;\n\n if (resourceType) {\n canUse =\n canUse &&\n (resourceType === ResourceType.item ||\n (resourceType === ResourceType.sproc && operationType === OperationType.Execute));\n }\n\n return canUse;\n }\n\n public async resolveServiceEndpoint(\n diagnosticNode: DiagnosticNodeInternal,\n resourceType: ResourceType,\n operationType: OperationType,\n startServiceEndpointIndex: number = 0, // Represents the starting index for selecting servers.\n ): Promise<string> {\n // If endpoint discovery is disabled, always use the user provided endpoint\n\n if (!this.options.connectionPolicy.enableEndpointDiscovery) {\n diagnosticNode.addData({ readFromCache: true }, \"default_endpoint\");\n diagnosticNode.recordEndpointResolution(this.defaultEndpoint);\n return this.defaultEndpoint;\n }\n\n // If getting the database account, always use the user provided endpoint\n if (resourceType === ResourceType.none) {\n diagnosticNode.addData({ readFromCache: true }, \"none_resource\");\n diagnosticNode.recordEndpointResolution(this.defaultEndpoint);\n return this.defaultEndpoint;\n }\n\n if (this.readableLocations.length === 0 || this.writeableLocations.length === 0) {\n const resourceResponse = await withMetadataDiagnostics(\n async (metadataNode: DiagnosticNodeInternal) => {\n return this.readDatabaseAccount(metadataNode, {\n urlConnection: this.defaultEndpoint,\n });\n },\n diagnosticNode,\n MetadataLookUpType.DatabaseAccountLookUp,\n );\n\n this.writeableLocations = resourceResponse.resource.writableLocations;\n this.readableLocations = resourceResponse.resource.readableLocations;\n this.enableMultipleWriteLocations = resourceResponse.resource.enableMultipleWritableLocations;\n }\n\n const locations = isReadRequest(operationType)\n ? this.readableLocations\n : this.writeableLocations;\n\n let location;\n // If we have preferred locations, try each one in order and use the first available one\n if (\n this.preferredLocations &&\n this.preferredLocations.length > 0 &&\n startServiceEndpointIndex < this.preferredLocations.length\n ) {\n for (let i = startServiceEndpointIndex; i < this.preferredLocations.length; i++) {\n const preferredLocation = this.preferredLocations[i];\n location = locations.find(\n (loc) =>\n loc.unavailable !== true &&\n normalizeEndpoint(loc.name) === normalizeEndpoint(preferredLocation),\n );\n if (location) {\n break;\n }\n }\n }\n\n // If no preferred locations or one did not match, just grab the first one that is available\n if (!location) {\n const startIndexValid =\n startServiceEndpointIndex >= 0 && startServiceEndpointIndex < locations.length;\n const locationsToSearch = startIndexValid\n ? locations.slice(startServiceEndpointIndex)\n : locations;\n location = locationsToSearch.find((loc) => {\n return loc.unavailable !== true;\n });\n }\n\n location = location ? location : { name: \"\", databaseAccountEndpoint: this.defaultEndpoint };\n diagnosticNode.recordEndpointResolution(location.databaseAccountEndpoint);\n return location.databaseAccountEndpoint;\n }\n\n /**\n * Refreshes the endpoint list by clearning stale unavailability and then\n * retrieving the writable and readable locations from the geo-replicated database account\n * and then updating the locations cache.\n * We skip the refreshing if enableEndpointDiscovery is set to False\n */\n public async refreshEndpointList(diagnosticNode: DiagnosticNodeInternal): Promise<void> {\n if (!this.isRefreshing && this.enableEndpointDiscovery) {\n this.isRefreshing = true;\n const databaseAccount = await this.getDatabaseAccountFromAnyEndpoint(diagnosticNode);\n if (databaseAccount) {\n this.refreshStaleUnavailableLocations();\n this.refreshEndpoints(databaseAccount);\n }\n this.isRefreshing = false;\n }\n }\n\n private refreshEndpoints(databaseAccount: DatabaseAccount): void {\n for (const location of databaseAccount.writableLocations) {\n const existingLocation = this.writeableLocations.find((loc) => loc.name === location.name);\n if (!existingLocation) {\n this.writeableLocations.push(location);\n }\n }\n for (const location of databaseAccount.readableLocations) {\n const existingLocation = this.readableLocations.find((loc) => loc.name === location.name);\n if (!existingLocation) {\n this.readableLocations.push(location);\n }\n }\n }\n\n private refreshStaleUnavailableLocations(): void {\n const now = Date.now();\n this.updateLocation(now, this.unavailableReadableLocations, this.readableLocations);\n this.unavailableReadableLocations = this.cleanUnavailableLocationList(\n now,\n this.unavailableReadableLocations,\n );\n\n this.updateLocation(now, this.unavailableWriteableLocations, this.writeableLocations);\n this.unavailableWriteableLocations = this.cleanUnavailableLocationList(\n now,\n this.unavailableWriteableLocations,\n );\n }\n\n /**\n * update the locationUnavailability to undefined if the location is available again\n * @param now - current time\n * @param unavailableLocations - list of unavailable locations\n * @param allLocations - list of all locations\n */\n private updateLocation(\n now: number,\n unavailableLocations: Location[],\n allLocations: Location[],\n ): void {\n for (const location of unavailableLocations) {\n const unavaialableLocation = allLocations.find((loc) => loc.name === location.name);\n if (\n unavaialableLocation &&\n now - unavaialableLocation.lastUnavailabilityTimestampInMs >\n Constants.LocationUnavailableExpirationTimeInMs\n ) {\n unavaialableLocation.unavailable = false;\n }\n }\n }\n\n private cleanUnavailableLocationList(now: number, unavailableLocations: Location[]): Location[] {\n return unavailableLocations.filter((loc) => {\n if (\n loc &&\n now - loc.lastUnavailabilityTimestampInMs >= Constants.LocationUnavailableExpirationTimeInMs\n ) {\n return false;\n }\n return true;\n });\n }\n\n /**\n * Gets the database account first by using the default endpoint, and if that doesn't returns\n * use the endpoints for the preferred locations in the order they are specified to get\n * the database account.\n */\n private async getDatabaseAccountFromAnyEndpoint(\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<DatabaseAccount> {\n try {\n const options = { urlConnection: this.defaultEndpoint };\n const { resource: databaseAccount } = await this.readDatabaseAccount(diagnosticNode, options);\n return databaseAccount;\n // If for any reason(non - globaldb related), we are not able to get the database\n // account from the above call to readDatabaseAccount,\n // we would try to get this information from any of the preferred locations that the user\n // might have specified (by creating a locational endpoint)\n // and keeping eating the exception until we get the database account and return None at the end,\n // if we are not able to get that info from any endpoints\n } catch (err: any) {\n // TODO: Tracing\n }\n\n if (this.preferredLocations) {\n for (const location of this.preferredLocations) {\n try {\n const locationalEndpoint = GlobalEndpointManager.getLocationalEndpoint(\n this.defaultEndpoint,\n location,\n );\n const options = { urlConnection: locationalEndpoint };\n const { resource: databaseAccount } = await this.readDatabaseAccount(\n diagnosticNode,\n options,\n );\n if (databaseAccount) {\n return databaseAccount;\n }\n } catch (err: any) {\n // TODO: Tracing\n }\n }\n }\n }\n\n /**\n * Gets the locational endpoint using the location name passed to it using the default endpoint.\n *\n * @param defaultEndpoint - The default endpoint to use for the endpoint.\n * @param locationName - The location name for the azure region like \"East US\".\n */\n private static getLocationalEndpoint(defaultEndpoint: string, locationName: string): string {\n // For defaultEndpoint like 'https://contoso.documents.azure.com:443/' parse it to generate URL format\n // This defaultEndpoint should be global endpoint(and cannot be a locational endpoint)\n // and we agreed to document that\n const endpointUrl = new URL(defaultEndpoint);\n\n // hostname attribute in endpointUrl will return 'contoso.documents.azure.com'\n if (endpointUrl.hostname) {\n const hostnameParts = endpointUrl.hostname.toString().toLowerCase().split(\".\");\n if (hostnameParts) {\n // globalDatabaseAccountName will return 'contoso'\n const globalDatabaseAccountName = hostnameParts[0];\n\n // Prepare the locationalDatabaseAccountName as contoso-EastUS for location_name 'East US'\n const locationalDatabaseAccountName =\n globalDatabaseAccountName + \"-\" + locationName.replace(\" \", \"\");\n\n // Replace 'contoso' with 'contoso-EastUS' and\n // return locationalEndpoint as https://contoso-EastUS.documents.azure.com:443/\n const locationalEndpoint = defaultEndpoint\n .toLowerCase()\n .replace(globalDatabaseAccountName, locationalDatabaseAccountName);\n return locationalEndpoint;\n }\n }\n\n return null;\n }\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { DiagnosticNodeInternal, type RequestContext } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* @hidden
|
|
4
|
+
* This class is used to failover single partitions to different regions.
|
|
5
|
+
*/
|
|
6
|
+
export declare class GlobalPartitionEndpointManager {
|
|
7
|
+
private globalEndpointManager;
|
|
8
|
+
private readonly partitionKeyRangeToLocationForWrite;
|
|
9
|
+
private readonly partitionKeyRangeToLocationForReadAndWrite;
|
|
10
|
+
private enablePartitionLevelFailover;
|
|
11
|
+
private enablePartitionLevelCircuitBreaker;
|
|
12
|
+
private preferredLocations;
|
|
13
|
+
preferredLocationsCount: number;
|
|
14
|
+
private circuitBreakerFailbackBackgroundRefresher;
|
|
15
|
+
/**
|
|
16
|
+
* Checks eligibility of the request for partition failover and
|
|
17
|
+
* tries to mark the endpoint unavailable for the partition key range. Future
|
|
18
|
+
* requests will be routed to the next location if available.
|
|
19
|
+
*/
|
|
20
|
+
tryPartitionLevelFailover(requestContext: RequestContext, diagnosticNode: DiagnosticNodeInternal): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Updates the DocumentServiceRequest routing location to point
|
|
23
|
+
* new a location based if a partition level failover occurred.
|
|
24
|
+
*/
|
|
25
|
+
tryAddPartitionLevelLocationOverride(requestContext: RequestContext, diagnosticNode: DiagnosticNodeInternal): Promise<RequestContext>;
|
|
26
|
+
/**
|
|
27
|
+
* This method clears the background refresher for circuit breaker failback
|
|
28
|
+
* and stops the periodic checks for unhealthy endpoints.
|
|
29
|
+
*/
|
|
30
|
+
dispose(): void;
|
|
31
|
+
private tryMarkEndpointUnavailableForPartitionKeyRange;
|
|
32
|
+
/**
|
|
33
|
+
* Increments the failure counter for the specified partition and checks if the partition can fail over.
|
|
34
|
+
* This method is used to determine if a partition should be failed over based on the number of request failures.
|
|
35
|
+
*/
|
|
36
|
+
private incrementFailureCounterAndCheckFailover;
|
|
37
|
+
/** Validates if the given request is eligible for partition failover. */
|
|
38
|
+
private isRequestEligibleForPartitionFailover;
|
|
39
|
+
/** Determines if partition level failover locations can be used for the given request. */
|
|
40
|
+
private canUsePartitionLevelFailoverLocations;
|
|
41
|
+
/**
|
|
42
|
+
* Determines if a request is eligible for per-partition automatic failover.
|
|
43
|
+
* A request is eligible if it is a write request, partition level failover is enabled,
|
|
44
|
+
* and the global endpoint manager cannot use multiple write locations for the request.
|
|
45
|
+
*/
|
|
46
|
+
private isRequestEligibleForPerPartitionAutomaticFailover;
|
|
47
|
+
/**
|
|
48
|
+
* Determines if a request is eligible for partition-level circuit breaker.
|
|
49
|
+
* This method checks if partition-level circuit breaker is enabled, and if the request is a read-only request or
|
|
50
|
+
* the global endpoint manager can use multiple write locations for the request.
|
|
51
|
+
*/
|
|
52
|
+
private isRequestEligibleForPartitionLevelCircuitBreaker;
|
|
53
|
+
/**
|
|
54
|
+
* Attempts to add or update the partition failover information and move to the next available location.
|
|
55
|
+
* This method checks if the current location for the partition key range has failed and updates the failover
|
|
56
|
+
* information to route the request to the next available location. If all locations have been tried, it removes
|
|
57
|
+
* the failover information for the partition key range. Return True if the failover information was successfully
|
|
58
|
+
* updated and the request was routed to a new location, otherwise false.
|
|
59
|
+
*/
|
|
60
|
+
private tryAddOrUpdatePartitionFailoverInfoAndMoveToNextLocation;
|
|
61
|
+
/**
|
|
62
|
+
* Initiates a background loop that periodically checks for unhealthy endpoints
|
|
63
|
+
* and attempts to open connections to them. If a connection is successfully
|
|
64
|
+
* established, it initiates a failback to the original location for the partition key range.
|
|
65
|
+
* This is useful for scenarios where a partition key range has been marked as unavailable
|
|
66
|
+
* due to a circuit breaker, and we want to periodically check if the original location
|
|
67
|
+
* has become healthy again.
|
|
68
|
+
* The loop runs at a defined interval specified by Constants.StalePartitionUnavailabilityRefreshIntervalInMs.
|
|
69
|
+
*/
|
|
70
|
+
private initiateCircuitBreakerFailbackLoop;
|
|
71
|
+
/**
|
|
72
|
+
* Attempts to open connections to unhealthy endpoints and initiates failback if the connections are successful.
|
|
73
|
+
* This method checks the partition key ranges that have failed locations and tries to re-establish connections
|
|
74
|
+
* to those locations. If a connection is successfully re-established, it initiates a failback to the original
|
|
75
|
+
* location for the partition key range.
|
|
76
|
+
*/
|
|
77
|
+
private openConnectionToUnhealthyEndpointsWithFailback;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=globalPartitionEndpointManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globalPartitionEndpointManager.d.ts","sourceRoot":"","sources":["../../src/globalPartitionEndpointManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,sBAAsB,EAGtB,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AAMpB;;;GAGG;AACH,qBAAa,8BAA8B;IAiBvC,OAAO,CAAC,qBAAqB;IAhB/B,OAAO,CAAC,QAAQ,CAAC,mCAAmC,CAA6C;IACjG,OAAO,CAAC,QAAQ,CAAC,0CAA0C,CAGzD;IACF,OAAO,CAAC,4BAA4B,CAAU;IAC9C,OAAO,CAAC,kCAAkC,CAAU;IACpD,OAAO,CAAC,kBAAkB,CAAW;IAC9B,uBAAuB,EAAE,MAAM,CAAC;IACvC,OAAO,CAAC,yCAAyC,CAAiB;IA2BlE;;;;OAIG;IACU,yBAAyB,CACpC,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,sBAAsB,GACrC,OAAO,CAAC,OAAO,CAAC;IA6BnB;;;OAGG;IACU,oCAAoC,CAC/C,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,sBAAsB,GACrC,OAAO,CAAC,cAAc,CAAC;IAiC1B;;;OAGG;IACI,OAAO,IAAI,IAAI;YAMR,8CAA8C;IA2D5D;;;OAGG;YACW,uCAAuC;IA6CrD,yEAAyE;YAC3D,qCAAqC;IA2BnD,0FAA0F;YAC5E,qCAAqC;IAmBnD;;;;OAIG;IACH,OAAO,CAAC,iDAAiD;IAazD;;;;OAIG;IACH,OAAO,CAAC,gDAAgD;IAexD;;;;;;OAMG;YACW,wDAAwD;IA8BtE;;;;;;;;OAQG;IACH,OAAO,CAAC,kCAAkC;IAU1C;;;;;OAKG;YACW,8CAA8C;CAmB7D"}
|