@azure/cosmos 4.4.1 → 4.5.0-alpha.20250717.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.
Files changed (428) hide show
  1. package/dist/browser/ClientContext.d.ts +19 -10
  2. package/dist/browser/ClientContext.d.ts.map +1 -1
  3. package/dist/browser/ClientContext.js +30 -11
  4. package/dist/browser/ClientContext.js.map +1 -1
  5. package/dist/browser/CosmosClient.d.ts.map +1 -1
  6. package/dist/browser/CosmosClient.js +10 -2
  7. package/dist/browser/CosmosClient.js.map +1 -1
  8. package/dist/browser/PartitionKeyRangeFailoverInfo.d.ts +49 -0
  9. package/dist/browser/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
  10. package/dist/browser/PartitionKeyRangeFailoverInfo.js +130 -0
  11. package/dist/browser/PartitionKeyRangeFailoverInfo.js.map +1 -0
  12. package/dist/browser/client/ClientUtils.d.ts +3 -1
  13. package/dist/browser/client/ClientUtils.d.ts.map +1 -1
  14. package/dist/browser/client/ClientUtils.js +10 -0
  15. package/dist/browser/client/ClientUtils.js.map +1 -1
  16. package/dist/browser/client/Item/Item.d.ts.map +1 -1
  17. package/dist/browser/client/Item/Item.js +13 -0
  18. package/dist/browser/client/Item/Item.js.map +1 -1
  19. package/dist/browser/client/Item/Items.d.ts +1 -0
  20. package/dist/browser/client/Item/Items.d.ts.map +1 -1
  21. package/dist/browser/client/Item/Items.js +20 -3
  22. package/dist/browser/client/Item/Items.js.map +1 -1
  23. package/dist/browser/common/constants.d.ts +20 -0
  24. package/dist/browser/common/constants.d.ts.map +1 -1
  25. package/dist/browser/common/constants.js +23 -1
  26. package/dist/browser/common/constants.js.map +1 -1
  27. package/dist/browser/common/platform.d.ts +6 -1
  28. package/dist/browser/common/platform.d.ts.map +1 -1
  29. package/dist/browser/common/platform.js +23 -4
  30. package/dist/browser/common/platform.js.map +1 -1
  31. package/dist/browser/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
  32. package/dist/browser/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
  33. package/dist/browser/diagnostics/DiagnosticNodeInternal.js.map +1 -1
  34. package/dist/browser/documents/ConnectionPolicy.d.ts +6 -0
  35. package/dist/browser/documents/ConnectionPolicy.d.ts.map +1 -1
  36. package/dist/browser/documents/ConnectionPolicy.js +2 -0
  37. package/dist/browser/documents/ConnectionPolicy.js.map +1 -1
  38. package/dist/browser/documents/DatabaseAccount.d.ts.map +1 -1
  39. package/dist/browser/documents/DatabaseAccount.js +3 -0
  40. package/dist/browser/documents/DatabaseAccount.js.map +1 -1
  41. package/dist/browser/documents/PartitionKeyDefinition.d.ts +1 -1
  42. package/dist/browser/documents/PartitionKeyDefinition.js.map +1 -1
  43. package/dist/browser/extractPartitionKey.d.ts.map +1 -1
  44. package/dist/browser/extractPartitionKey.js +33 -20
  45. package/dist/browser/extractPartitionKey.js.map +1 -1
  46. package/dist/browser/globalEndpointManager.d.ts +6 -0
  47. package/dist/browser/globalEndpointManager.d.ts.map +1 -1
  48. package/dist/browser/globalEndpointManager.js +9 -4
  49. package/dist/browser/globalEndpointManager.js.map +1 -1
  50. package/dist/browser/globalPartitionEndpointManager.d.ts +79 -0
  51. package/dist/browser/globalPartitionEndpointManager.d.ts.map +1 -0
  52. package/dist/browser/globalPartitionEndpointManager.js +279 -0
  53. package/dist/browser/globalPartitionEndpointManager.js.map +1 -0
  54. package/dist/browser/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
  55. package/dist/browser/queryExecutionContext/Aggregators/index.js +1 -0
  56. package/dist/browser/queryExecutionContext/Aggregators/index.js.map +1 -1
  57. package/dist/browser/queryExecutionContext/documentProducer.d.ts +2 -3
  58. package/dist/browser/queryExecutionContext/documentProducer.d.ts.map +1 -1
  59. package/dist/browser/queryExecutionContext/documentProducer.js +16 -21
  60. package/dist/browser/queryExecutionContext/documentProducer.js.map +1 -1
  61. package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
  62. package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
  63. package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
  64. package/dist/browser/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
  65. package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
  66. package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
  67. package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
  68. package/dist/browser/queryIterator.d.ts.map +1 -1
  69. package/dist/browser/queryIterator.js +2 -3
  70. package/dist/browser/queryIterator.js.map +1 -1
  71. package/dist/browser/request/ErrorResponse.d.ts +1 -1
  72. package/dist/browser/request/ErrorResponse.d.ts.map +1 -1
  73. package/dist/browser/request/ErrorResponse.js.map +1 -1
  74. package/dist/browser/request/RequestContext.d.ts +5 -0
  75. package/dist/browser/request/RequestContext.d.ts.map +1 -1
  76. package/dist/browser/request/RequestContext.js.map +1 -1
  77. package/dist/browser/request/RequestHandler.d.ts.map +1 -1
  78. package/dist/browser/request/RequestHandler.js +14 -4
  79. package/dist/browser/request/RequestHandler.js.map +1 -1
  80. package/dist/browser/retry/RetryPolicy.d.ts +2 -2
  81. package/dist/browser/retry/RetryPolicy.d.ts.map +1 -1
  82. package/dist/browser/retry/RetryPolicy.js.map +1 -1
  83. package/dist/browser/retry/defaultRetryPolicy.d.ts.map +1 -1
  84. package/dist/browser/retry/defaultRetryPolicy.js +4 -8
  85. package/dist/browser/retry/defaultRetryPolicy.js.map +1 -1
  86. package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
  87. package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
  88. package/dist/browser/retry/endpointDiscoveryRetryPolicy.js +9 -2
  89. package/dist/browser/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
  90. package/dist/browser/retry/retryUtility.d.ts.map +1 -1
  91. package/dist/browser/retry/retryUtility.js +11 -5
  92. package/dist/browser/retry/retryUtility.js.map +1 -1
  93. package/dist/browser/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
  94. package/dist/browser/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
  95. package/dist/browser/retry/timeoutFailoverRetryPolicy.js +12 -4
  96. package/dist/browser/retry/timeoutFailoverRetryPolicy.js.map +1 -1
  97. package/dist/browser/routing/partitionKeyRangeCache.d.ts.map +1 -1
  98. package/dist/browser/routing/partitionKeyRangeCache.js +11 -0
  99. package/dist/browser/routing/partitionKeyRangeCache.js.map +1 -1
  100. package/dist/browser/utils/checkURL.js +6 -0
  101. package/dist/browser/utils/checkURL.js.map +1 -1
  102. package/dist/browser/utils/hashing/hash.d.ts +2 -0
  103. package/dist/browser/utils/hashing/hash.d.ts.map +1 -1
  104. package/dist/browser/utils/hashing/hash.js +19 -0
  105. package/dist/browser/utils/hashing/hash.js.map +1 -1
  106. package/dist/commonjs/ClientContext.d.ts +19 -10
  107. package/dist/commonjs/ClientContext.d.ts.map +1 -1
  108. package/dist/commonjs/ClientContext.js +30 -11
  109. package/dist/commonjs/ClientContext.js.map +1 -1
  110. package/dist/commonjs/CosmosClient.d.ts.map +1 -1
  111. package/dist/commonjs/CosmosClient.js +10 -2
  112. package/dist/commonjs/CosmosClient.js.map +1 -1
  113. package/dist/commonjs/PartitionKeyRangeFailoverInfo.d.ts +49 -0
  114. package/dist/commonjs/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
  115. package/dist/commonjs/PartitionKeyRangeFailoverInfo.js +135 -0
  116. package/dist/commonjs/PartitionKeyRangeFailoverInfo.js.map +1 -0
  117. package/dist/commonjs/client/ClientUtils.d.ts +3 -1
  118. package/dist/commonjs/client/ClientUtils.d.ts.map +1 -1
  119. package/dist/commonjs/client/ClientUtils.js +11 -0
  120. package/dist/commonjs/client/ClientUtils.js.map +1 -1
  121. package/dist/commonjs/client/Item/Item.d.ts.map +1 -1
  122. package/dist/commonjs/client/Item/Item.js +13 -0
  123. package/dist/commonjs/client/Item/Item.js.map +1 -1
  124. package/dist/commonjs/client/Item/Items.d.ts +1 -0
  125. package/dist/commonjs/client/Item/Items.d.ts.map +1 -1
  126. package/dist/commonjs/client/Item/Items.js +18 -1
  127. package/dist/commonjs/client/Item/Items.js.map +1 -1
  128. package/dist/commonjs/common/constants.d.ts +20 -0
  129. package/dist/commonjs/common/constants.d.ts.map +1 -1
  130. package/dist/commonjs/common/constants.js +24 -2
  131. package/dist/commonjs/common/constants.js.map +1 -1
  132. package/dist/commonjs/common/platform.d.ts +6 -1
  133. package/dist/commonjs/common/platform.d.ts.map +1 -1
  134. package/dist/commonjs/common/platform.js +23 -3
  135. package/dist/commonjs/common/platform.js.map +1 -1
  136. package/dist/commonjs/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
  137. package/dist/commonjs/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
  138. package/dist/commonjs/diagnostics/DiagnosticNodeInternal.js.map +1 -1
  139. package/dist/commonjs/documents/ConnectionPolicy.d.ts +6 -0
  140. package/dist/commonjs/documents/ConnectionPolicy.d.ts.map +1 -1
  141. package/dist/commonjs/documents/ConnectionPolicy.js +2 -0
  142. package/dist/commonjs/documents/ConnectionPolicy.js.map +1 -1
  143. package/dist/commonjs/documents/DatabaseAccount.d.ts.map +1 -1
  144. package/dist/commonjs/documents/DatabaseAccount.js +3 -0
  145. package/dist/commonjs/documents/DatabaseAccount.js.map +1 -1
  146. package/dist/commonjs/documents/PartitionKeyDefinition.d.ts +1 -1
  147. package/dist/commonjs/documents/PartitionKeyDefinition.js.map +1 -1
  148. package/dist/commonjs/extractPartitionKey.d.ts.map +1 -1
  149. package/dist/commonjs/extractPartitionKey.js +33 -20
  150. package/dist/commonjs/extractPartitionKey.js.map +1 -1
  151. package/dist/commonjs/globalEndpointManager.d.ts +6 -0
  152. package/dist/commonjs/globalEndpointManager.d.ts.map +1 -1
  153. package/dist/commonjs/globalEndpointManager.js +10 -5
  154. package/dist/commonjs/globalEndpointManager.js.map +1 -1
  155. package/dist/commonjs/globalPartitionEndpointManager.d.ts +79 -0
  156. package/dist/commonjs/globalPartitionEndpointManager.d.ts.map +1 -0
  157. package/dist/commonjs/globalPartitionEndpointManager.js +283 -0
  158. package/dist/commonjs/globalPartitionEndpointManager.js.map +1 -0
  159. package/dist/commonjs/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
  160. package/dist/commonjs/queryExecutionContext/Aggregators/index.js +1 -0
  161. package/dist/commonjs/queryExecutionContext/Aggregators/index.js.map +1 -1
  162. package/dist/commonjs/queryExecutionContext/documentProducer.d.ts +2 -3
  163. package/dist/commonjs/queryExecutionContext/documentProducer.d.ts.map +1 -1
  164. package/dist/commonjs/queryExecutionContext/documentProducer.js +15 -20
  165. package/dist/commonjs/queryExecutionContext/documentProducer.js.map +1 -1
  166. package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
  167. package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
  168. package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
  169. package/dist/commonjs/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
  170. package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
  171. package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
  172. package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
  173. package/dist/commonjs/queryIterator.d.ts.map +1 -1
  174. package/dist/commonjs/queryIterator.js +2 -3
  175. package/dist/commonjs/queryIterator.js.map +1 -1
  176. package/dist/commonjs/request/ErrorResponse.d.ts +1 -1
  177. package/dist/commonjs/request/ErrorResponse.d.ts.map +1 -1
  178. package/dist/commonjs/request/ErrorResponse.js.map +1 -1
  179. package/dist/commonjs/request/RequestContext.d.ts +5 -0
  180. package/dist/commonjs/request/RequestContext.d.ts.map +1 -1
  181. package/dist/commonjs/request/RequestContext.js.map +1 -1
  182. package/dist/commonjs/request/RequestHandler.d.ts.map +1 -1
  183. package/dist/commonjs/request/RequestHandler.js +12 -2
  184. package/dist/commonjs/request/RequestHandler.js.map +1 -1
  185. package/dist/commonjs/request/defaultAgent.js +4 -4
  186. package/dist/commonjs/request/defaultAgent.js.map +1 -1
  187. package/dist/commonjs/retry/RetryPolicy.d.ts +2 -2
  188. package/dist/commonjs/retry/RetryPolicy.d.ts.map +1 -1
  189. package/dist/commonjs/retry/RetryPolicy.js.map +1 -1
  190. package/dist/commonjs/retry/defaultRetryPolicy.d.ts.map +1 -1
  191. package/dist/commonjs/retry/defaultRetryPolicy.js +3 -7
  192. package/dist/commonjs/retry/defaultRetryPolicy.js.map +1 -1
  193. package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
  194. package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
  195. package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js +9 -2
  196. package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
  197. package/dist/commonjs/retry/retryUtility.d.ts.map +1 -1
  198. package/dist/commonjs/retry/retryUtility.js +11 -5
  199. package/dist/commonjs/retry/retryUtility.js.map +1 -1
  200. package/dist/commonjs/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
  201. package/dist/commonjs/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
  202. package/dist/commonjs/retry/timeoutFailoverRetryPolicy.js +12 -4
  203. package/dist/commonjs/retry/timeoutFailoverRetryPolicy.js.map +1 -1
  204. package/dist/commonjs/routing/partitionKeyRangeCache.d.ts.map +1 -1
  205. package/dist/commonjs/routing/partitionKeyRangeCache.js +11 -0
  206. package/dist/commonjs/routing/partitionKeyRangeCache.js.map +1 -1
  207. package/dist/commonjs/tsdoc-metadata.json +1 -1
  208. package/dist/commonjs/utils/checkURL.js +7 -0
  209. package/dist/commonjs/utils/checkURL.js.map +1 -1
  210. package/dist/commonjs/utils/hashing/hash.d.ts +2 -0
  211. package/dist/commonjs/utils/hashing/hash.d.ts.map +1 -1
  212. package/dist/commonjs/utils/hashing/hash.js +20 -0
  213. package/dist/commonjs/utils/hashing/hash.js.map +1 -1
  214. package/dist/esm/ClientContext.d.ts +19 -10
  215. package/dist/esm/ClientContext.d.ts.map +1 -1
  216. package/dist/esm/ClientContext.js +30 -11
  217. package/dist/esm/ClientContext.js.map +1 -1
  218. package/dist/esm/CosmosClient.d.ts.map +1 -1
  219. package/dist/esm/CosmosClient.js +10 -2
  220. package/dist/esm/CosmosClient.js.map +1 -1
  221. package/dist/esm/PartitionKeyRangeFailoverInfo.d.ts +49 -0
  222. package/dist/esm/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
  223. package/dist/esm/PartitionKeyRangeFailoverInfo.js +130 -0
  224. package/dist/esm/PartitionKeyRangeFailoverInfo.js.map +1 -0
  225. package/dist/esm/client/ClientUtils.d.ts +3 -1
  226. package/dist/esm/client/ClientUtils.d.ts.map +1 -1
  227. package/dist/esm/client/ClientUtils.js +10 -0
  228. package/dist/esm/client/ClientUtils.js.map +1 -1
  229. package/dist/esm/client/Item/Item.d.ts.map +1 -1
  230. package/dist/esm/client/Item/Item.js +13 -0
  231. package/dist/esm/client/Item/Item.js.map +1 -1
  232. package/dist/esm/client/Item/Items.d.ts +1 -0
  233. package/dist/esm/client/Item/Items.d.ts.map +1 -1
  234. package/dist/esm/client/Item/Items.js +20 -3
  235. package/dist/esm/client/Item/Items.js.map +1 -1
  236. package/dist/esm/common/constants.d.ts +20 -0
  237. package/dist/esm/common/constants.d.ts.map +1 -1
  238. package/dist/esm/common/constants.js +23 -1
  239. package/dist/esm/common/constants.js.map +1 -1
  240. package/dist/esm/common/platform.d.ts +6 -1
  241. package/dist/esm/common/platform.d.ts.map +1 -1
  242. package/dist/esm/common/platform.js +23 -4
  243. package/dist/esm/common/platform.js.map +1 -1
  244. package/dist/esm/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
  245. package/dist/esm/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
  246. package/dist/esm/diagnostics/DiagnosticNodeInternal.js.map +1 -1
  247. package/dist/esm/documents/ConnectionPolicy.d.ts +6 -0
  248. package/dist/esm/documents/ConnectionPolicy.d.ts.map +1 -1
  249. package/dist/esm/documents/ConnectionPolicy.js +2 -0
  250. package/dist/esm/documents/ConnectionPolicy.js.map +1 -1
  251. package/dist/esm/documents/DatabaseAccount.d.ts.map +1 -1
  252. package/dist/esm/documents/DatabaseAccount.js +3 -0
  253. package/dist/esm/documents/DatabaseAccount.js.map +1 -1
  254. package/dist/esm/documents/PartitionKeyDefinition.d.ts +1 -1
  255. package/dist/esm/documents/PartitionKeyDefinition.js.map +1 -1
  256. package/dist/esm/extractPartitionKey.d.ts.map +1 -1
  257. package/dist/esm/extractPartitionKey.js +33 -20
  258. package/dist/esm/extractPartitionKey.js.map +1 -1
  259. package/dist/esm/globalEndpointManager.d.ts +6 -0
  260. package/dist/esm/globalEndpointManager.d.ts.map +1 -1
  261. package/dist/esm/globalEndpointManager.js +9 -4
  262. package/dist/esm/globalEndpointManager.js.map +1 -1
  263. package/dist/esm/globalPartitionEndpointManager.d.ts +79 -0
  264. package/dist/esm/globalPartitionEndpointManager.d.ts.map +1 -0
  265. package/dist/esm/globalPartitionEndpointManager.js +279 -0
  266. package/dist/esm/globalPartitionEndpointManager.js.map +1 -0
  267. package/dist/esm/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
  268. package/dist/esm/queryExecutionContext/Aggregators/index.js +1 -0
  269. package/dist/esm/queryExecutionContext/Aggregators/index.js.map +1 -1
  270. package/dist/esm/queryExecutionContext/documentProducer.d.ts +2 -3
  271. package/dist/esm/queryExecutionContext/documentProducer.d.ts.map +1 -1
  272. package/dist/esm/queryExecutionContext/documentProducer.js +16 -21
  273. package/dist/esm/queryExecutionContext/documentProducer.js.map +1 -1
  274. package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
  275. package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
  276. package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
  277. package/dist/esm/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
  278. package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
  279. package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
  280. package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
  281. package/dist/esm/queryIterator.d.ts.map +1 -1
  282. package/dist/esm/queryIterator.js +2 -3
  283. package/dist/esm/queryIterator.js.map +1 -1
  284. package/dist/esm/request/ErrorResponse.d.ts +1 -1
  285. package/dist/esm/request/ErrorResponse.d.ts.map +1 -1
  286. package/dist/esm/request/ErrorResponse.js.map +1 -1
  287. package/dist/esm/request/RequestContext.d.ts +5 -0
  288. package/dist/esm/request/RequestContext.d.ts.map +1 -1
  289. package/dist/esm/request/RequestContext.js.map +1 -1
  290. package/dist/esm/request/RequestHandler.d.ts.map +1 -1
  291. package/dist/esm/request/RequestHandler.js +14 -4
  292. package/dist/esm/request/RequestHandler.js.map +1 -1
  293. package/dist/esm/request/defaultAgent.js +2 -2
  294. package/dist/esm/request/defaultAgent.js.map +1 -1
  295. package/dist/esm/retry/RetryPolicy.d.ts +2 -2
  296. package/dist/esm/retry/RetryPolicy.d.ts.map +1 -1
  297. package/dist/esm/retry/RetryPolicy.js.map +1 -1
  298. package/dist/esm/retry/defaultRetryPolicy.d.ts.map +1 -1
  299. package/dist/esm/retry/defaultRetryPolicy.js +4 -8
  300. package/dist/esm/retry/defaultRetryPolicy.js.map +1 -1
  301. package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
  302. package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
  303. package/dist/esm/retry/endpointDiscoveryRetryPolicy.js +9 -2
  304. package/dist/esm/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
  305. package/dist/esm/retry/retryUtility.d.ts.map +1 -1
  306. package/dist/esm/retry/retryUtility.js +11 -5
  307. package/dist/esm/retry/retryUtility.js.map +1 -1
  308. package/dist/esm/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
  309. package/dist/esm/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
  310. package/dist/esm/retry/timeoutFailoverRetryPolicy.js +12 -4
  311. package/dist/esm/retry/timeoutFailoverRetryPolicy.js.map +1 -1
  312. package/dist/esm/routing/partitionKeyRangeCache.d.ts.map +1 -1
  313. package/dist/esm/routing/partitionKeyRangeCache.js +11 -0
  314. package/dist/esm/routing/partitionKeyRangeCache.js.map +1 -1
  315. package/dist/esm/utils/checkURL.js +6 -0
  316. package/dist/esm/utils/checkURL.js.map +1 -1
  317. package/dist/esm/utils/hashing/hash.d.ts +2 -0
  318. package/dist/esm/utils/hashing/hash.d.ts.map +1 -1
  319. package/dist/esm/utils/hashing/hash.js +19 -0
  320. package/dist/esm/utils/hashing/hash.js.map +1 -1
  321. package/dist/react-native/ClientContext.d.ts +19 -10
  322. package/dist/react-native/ClientContext.d.ts.map +1 -1
  323. package/dist/react-native/ClientContext.js +30 -11
  324. package/dist/react-native/ClientContext.js.map +1 -1
  325. package/dist/react-native/CosmosClient.d.ts.map +1 -1
  326. package/dist/react-native/CosmosClient.js +10 -2
  327. package/dist/react-native/CosmosClient.js.map +1 -1
  328. package/dist/react-native/PartitionKeyRangeFailoverInfo.d.ts +49 -0
  329. package/dist/react-native/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
  330. package/dist/react-native/PartitionKeyRangeFailoverInfo.js +130 -0
  331. package/dist/react-native/PartitionKeyRangeFailoverInfo.js.map +1 -0
  332. package/dist/react-native/client/ClientUtils.d.ts +3 -1
  333. package/dist/react-native/client/ClientUtils.d.ts.map +1 -1
  334. package/dist/react-native/client/ClientUtils.js +10 -0
  335. package/dist/react-native/client/ClientUtils.js.map +1 -1
  336. package/dist/react-native/client/Item/Item.d.ts.map +1 -1
  337. package/dist/react-native/client/Item/Item.js +13 -0
  338. package/dist/react-native/client/Item/Item.js.map +1 -1
  339. package/dist/react-native/client/Item/Items.d.ts +1 -0
  340. package/dist/react-native/client/Item/Items.d.ts.map +1 -1
  341. package/dist/react-native/client/Item/Items.js +20 -3
  342. package/dist/react-native/client/Item/Items.js.map +1 -1
  343. package/dist/react-native/common/constants.d.ts +20 -0
  344. package/dist/react-native/common/constants.d.ts.map +1 -1
  345. package/dist/react-native/common/constants.js +23 -1
  346. package/dist/react-native/common/constants.js.map +1 -1
  347. package/dist/react-native/common/platform.d.ts +6 -1
  348. package/dist/react-native/common/platform.d.ts.map +1 -1
  349. package/dist/react-native/common/platform.js +23 -4
  350. package/dist/react-native/common/platform.js.map +1 -1
  351. package/dist/react-native/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
  352. package/dist/react-native/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
  353. package/dist/react-native/diagnostics/DiagnosticNodeInternal.js.map +1 -1
  354. package/dist/react-native/documents/ConnectionPolicy.d.ts +6 -0
  355. package/dist/react-native/documents/ConnectionPolicy.d.ts.map +1 -1
  356. package/dist/react-native/documents/ConnectionPolicy.js +2 -0
  357. package/dist/react-native/documents/ConnectionPolicy.js.map +1 -1
  358. package/dist/react-native/documents/DatabaseAccount.d.ts.map +1 -1
  359. package/dist/react-native/documents/DatabaseAccount.js +3 -0
  360. package/dist/react-native/documents/DatabaseAccount.js.map +1 -1
  361. package/dist/react-native/documents/PartitionKeyDefinition.d.ts +1 -1
  362. package/dist/react-native/documents/PartitionKeyDefinition.js.map +1 -1
  363. package/dist/react-native/extractPartitionKey.d.ts.map +1 -1
  364. package/dist/react-native/extractPartitionKey.js +33 -20
  365. package/dist/react-native/extractPartitionKey.js.map +1 -1
  366. package/dist/react-native/globalEndpointManager.d.ts +6 -0
  367. package/dist/react-native/globalEndpointManager.d.ts.map +1 -1
  368. package/dist/react-native/globalEndpointManager.js +9 -4
  369. package/dist/react-native/globalEndpointManager.js.map +1 -1
  370. package/dist/react-native/globalPartitionEndpointManager.d.ts +79 -0
  371. package/dist/react-native/globalPartitionEndpointManager.d.ts.map +1 -0
  372. package/dist/react-native/globalPartitionEndpointManager.js +279 -0
  373. package/dist/react-native/globalPartitionEndpointManager.js.map +1 -0
  374. package/dist/react-native/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
  375. package/dist/react-native/queryExecutionContext/Aggregators/index.js +1 -0
  376. package/dist/react-native/queryExecutionContext/Aggregators/index.js.map +1 -1
  377. package/dist/react-native/queryExecutionContext/documentProducer.d.ts +2 -3
  378. package/dist/react-native/queryExecutionContext/documentProducer.d.ts.map +1 -1
  379. package/dist/react-native/queryExecutionContext/documentProducer.js +16 -21
  380. package/dist/react-native/queryExecutionContext/documentProducer.js.map +1 -1
  381. package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.d.ts +3 -1
  382. package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.d.ts.map +1 -1
  383. package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.js +10 -2
  384. package/dist/react-native/queryExecutionContext/hybridQueryExecutionContext.js.map +1 -1
  385. package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
  386. package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
  387. package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
  388. package/dist/react-native/queryIterator.d.ts.map +1 -1
  389. package/dist/react-native/queryIterator.js +2 -3
  390. package/dist/react-native/queryIterator.js.map +1 -1
  391. package/dist/react-native/request/ErrorResponse.d.ts +1 -1
  392. package/dist/react-native/request/ErrorResponse.d.ts.map +1 -1
  393. package/dist/react-native/request/ErrorResponse.js.map +1 -1
  394. package/dist/react-native/request/RequestContext.d.ts +5 -0
  395. package/dist/react-native/request/RequestContext.d.ts.map +1 -1
  396. package/dist/react-native/request/RequestContext.js.map +1 -1
  397. package/dist/react-native/request/RequestHandler.d.ts.map +1 -1
  398. package/dist/react-native/request/RequestHandler.js +14 -4
  399. package/dist/react-native/request/RequestHandler.js.map +1 -1
  400. package/dist/react-native/request/defaultAgent.js +2 -2
  401. package/dist/react-native/request/defaultAgent.js.map +1 -1
  402. package/dist/react-native/retry/RetryPolicy.d.ts +2 -2
  403. package/dist/react-native/retry/RetryPolicy.d.ts.map +1 -1
  404. package/dist/react-native/retry/RetryPolicy.js.map +1 -1
  405. package/dist/react-native/retry/defaultRetryPolicy.d.ts.map +1 -1
  406. package/dist/react-native/retry/defaultRetryPolicy.js +4 -8
  407. package/dist/react-native/retry/defaultRetryPolicy.js.map +1 -1
  408. package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
  409. package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
  410. package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js +9 -2
  411. package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
  412. package/dist/react-native/retry/retryUtility.d.ts.map +1 -1
  413. package/dist/react-native/retry/retryUtility.js +11 -5
  414. package/dist/react-native/retry/retryUtility.js.map +1 -1
  415. package/dist/react-native/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
  416. package/dist/react-native/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
  417. package/dist/react-native/retry/timeoutFailoverRetryPolicy.js +12 -4
  418. package/dist/react-native/retry/timeoutFailoverRetryPolicy.js.map +1 -1
  419. package/dist/react-native/routing/partitionKeyRangeCache.d.ts.map +1 -1
  420. package/dist/react-native/routing/partitionKeyRangeCache.js +11 -0
  421. package/dist/react-native/routing/partitionKeyRangeCache.js.map +1 -1
  422. package/dist/react-native/utils/checkURL.js +6 -0
  423. package/dist/react-native/utils/checkURL.js.map +1 -1
  424. package/dist/react-native/utils/hashing/hash.d.ts +2 -0
  425. package/dist/react-native/utils/hashing/hash.d.ts.map +1 -1
  426. package/dist/react-native/utils/hashing/hash.js +19 -0
  427. package/dist/react-native/utils/hashing/hash.js.map +1 -1
  428. package/package.json +11 -11
@@ -1,4 +1,4 @@
1
- import { OperationType } from "../common/index.js";
1
+ import { OperationType, StatusCodes } from "../common/index.js";
2
2
  import { TimeoutErrorCode } from "../request/TimeoutError.js";
3
3
  /**
4
4
  * @hidden
@@ -101,13 +101,9 @@ const CONNECTION_ERROR_CODES = [
101
101
  * @hidden
102
102
  */
103
103
  function needsRetry(operationType, code) {
104
- if ((operationType === OperationType.Read || operationType === OperationType.Query) &&
105
- CONNECTION_ERROR_CODES.indexOf(code) !== -1) {
106
- return true;
107
- }
108
- else {
109
- return false;
110
- }
104
+ return (code === StatusCodes.ENOTFOUND ||
105
+ ((operationType === OperationType.Read || operationType === OperationType.Query) &&
106
+ CONNECTION_ERROR_CODES.includes(code)));
111
107
  }
112
108
  /**
113
109
  * This class implements the default connection retry policy for requests.
@@ -1 +1 @@
1
- {"version":3,"file":"defaultRetryPolicy.js","sourceRoot":"","sources":["../../../src/retry/defaultRetryPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D;;GAEG;AACH,6BAA6B;AAC7B,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAC7C;;GAEG;AACH,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC;;GAEG;AACH,MAAM,uBAAuB,GAAG,KAAK,CAAC;AACtC;;GAEG;AACH,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAChC;;GAEG;AACH,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC;;GAEG;AACH,MAAM,qCAAqC,GAAG,KAAK,CAAC;AACpD;;GAEG;AACH,MAAM,6BAA6B,GAAG,KAAK,CAAC;AAC5C;;GAEG;AACH,MAAM,0BAA0B,GAAG,KAAK,CAAC;AACzC;;GAEG;AACH,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAC3C;;GAEG;AACH,MAAM,oCAAoC,GAAG,KAAK,CAAC;AACnD;;GA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KAAK,CAAC,WAAW,CACtB,GAAkB,EAClB,cAAsC;QAEtC,IAAI,GAAG,EAAE,CAAC;YACR,IACE,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC,QAAQ;gBAC7C,UAAU,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,IAAI,CAAC,EACxC,CAAC;gBACD,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,EAAE,SAAS,EAAE,CAAC,CAAC;gBAC7D,IAAI,CAAC,wBAAwB,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { OperationType } from \"../common/index.js\";\nimport type { ErrorResponse } from \"../request/index.js\";\nimport { TimeoutErrorCode } from \"../request/TimeoutError.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\n\n/**\n * @hidden\n */\n// Windows Socket Error Codes\nconst WindowsInterruptedFunctionCall = 10004;\n/**\n * @hidden\n */\nconst WindowsFileHandleNotValid = 10009;\n/**\n * @hidden\n */\nconst WindowsPermissionDenied = 10013;\n/**\n * @hidden\n */\nconst WindowsBadAddress = 10014;\n/**\n * @hidden\n */\nconst WindowsInvalidArgumnet = 10022;\n/**\n * @hidden\n */\nconst WindowsResourceTemporarilyUnavailable = 10035;\n/**\n * @hidden\n */\nconst WindowsOperationNowInProgress = 10036;\n/**\n * @hidden\n */\nconst WindowsAddressAlreadyInUse = 10048;\n/**\n * @hidden\n */\nconst WindowsConnectionResetByPeer = 10054;\n/**\n * @hidden\n */\nconst WindowsCannotSendAfterSocketShutdown = 10058;\n/**\n * @hidden\n */\nconst WindowsConnectionTimedOut = 10060;\n/**\n * @hidden\n */\nconst WindowsConnectionRefused = 10061;\n/**\n * @hidden\n */\nconst WindowsNameTooLong = 10063;\n/**\n * @hidden\n */\nconst WindowsHostIsDown = 10064;\n/**\n * @hidden\n */\nconst WindowsNoRouteTohost = 10065;\n/**\n * @hidden\n */\n\n// Linux Error Codes\n/**\n * @hidden\n */\nconst LinuxConnectionReset = \"ECONNRESET\";\n\n// Node Error Codes\n/**\n * @hidden\n */\nconst BrokenPipe = \"EPIPE\";\n\n/**\n * @hidden\n */\nconst CONNECTION_ERROR_CODES = [\n WindowsInterruptedFunctionCall,\n WindowsFileHandleNotValid,\n WindowsPermissionDenied,\n WindowsBadAddress,\n WindowsInvalidArgumnet,\n WindowsResourceTemporarilyUnavailable,\n WindowsOperationNowInProgress,\n WindowsAddressAlreadyInUse,\n WindowsConnectionResetByPeer,\n WindowsCannotSendAfterSocketShutdown,\n WindowsConnectionTimedOut,\n WindowsConnectionRefused,\n WindowsNameTooLong,\n WindowsHostIsDown,\n WindowsNoRouteTohost,\n LinuxConnectionReset,\n TimeoutErrorCode,\n BrokenPipe,\n];\n\n/**\n * @hidden\n */\nfunction needsRetry(operationType: OperationType, code: number | string): boolean {\n if (\n (operationType === OperationType.Read || operationType === OperationType.Query) &&\n CONNECTION_ERROR_CODES.indexOf(code) !== -1\n ) {\n return true;\n } else {\n return false;\n }\n}\n\n/**\n * This class implements the default connection retry policy for requests.\n * @hidden\n */\nexport class DefaultRetryPolicy implements RetryPolicy {\n private maxTries: number = 10;\n private currentRetryAttemptCount: number = 0;\n public retryAfterInMs: number = 1000;\n\n constructor(private operationType: OperationType) {}\n /**\n * Determines whether the request should be retried or not.\n * @param err - Error returned by the request.\n */\n public async shouldRetry(\n err: ErrorResponse,\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<boolean> {\n if (err) {\n if (\n this.currentRetryAttemptCount < this.maxTries &&\n needsRetry(this.operationType, err.code)\n ) {\n diagnosticNode.addData({ successfulRetryPolicy: \"default\" });\n this.currentRetryAttemptCount++;\n return true;\n }\n }\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"defaultRetryPolicy.js","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A6B;IAC7B,0BAA0B;IAC1B,4BAA4B;IAC5B,oCAAoC;IACpC,yBAAyB;IACzB,wBAAwB;IACxB,kBAAkB;IAClB,iBAAiB;IACjB,oBAAoB;IACpB,oBAAoB;IACpB,gBAAgB;IAChB,UAAU;CACX,CAAC;AAEF;;GAEG;AACH,SAAS,UAAU,CAAC,aAA4B,EAAE,IAAqB;IACrE,OAAO,CACL,IAAI,KAAK,WAAW,CAAC,SAAS;QAC9B,CAAC,CAAC,aAAa,KAAK,aAAa,CAAC,IAAI,IAAI,aAAa,KAAK,aAAa,CAAC,KAAK,CAAC;YAC9E,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACzC,CAAC;AACJ,CAAC;AACD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAK7B,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAJxC,aAAQ,GAAW,EAAE,CAAC;QACtB,6BAAwB,GAAW,CAAC,CAAC;QACtC,mBAAc,GAAW,IAAI,CAAC;IAEc,CAAC;IACpD;;;OAGG;IACI,KAAK,CAAC,WAAW,CACtB,GAAkB,EAClB,cAAsC;QAEtC,IAAI,GAAG,EAAE,CAAC;YACR,IACE,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC,QAAQ;gBAC7C,UAAU,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,IAAI,CAAC,EACxC,CAAC;gBACD,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,EAAE,SAAS,EAAE,CAAC,CAAC;gBAC7D,IAAI,CAAC,wBAAwB,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { OperationType, StatusCodes } from \"../common/index.js\";\nimport type { ErrorResponse } from \"../request/index.js\";\nimport { TimeoutErrorCode } from \"../request/TimeoutError.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\n\n/**\n * @hidden\n */\n// Windows Socket Error Codes\nconst WindowsInterruptedFunctionCall = 10004;\n/**\n * @hidden\n */\nconst WindowsFileHandleNotValid = 10009;\n/**\n * @hidden\n */\nconst WindowsPermissionDenied = 10013;\n/**\n * @hidden\n */\nconst WindowsBadAddress = 10014;\n/**\n * @hidden\n */\nconst WindowsInvalidArgumnet = 10022;\n/**\n * @hidden\n */\nconst WindowsResourceTemporarilyUnavailable = 10035;\n/**\n * @hidden\n */\nconst WindowsOperationNowInProgress = 10036;\n/**\n * @hidden\n */\nconst WindowsAddressAlreadyInUse = 10048;\n/**\n * @hidden\n */\nconst WindowsConnectionResetByPeer = 10054;\n/**\n * @hidden\n */\nconst WindowsCannotSendAfterSocketShutdown = 10058;\n/**\n * @hidden\n */\nconst WindowsConnectionTimedOut = 10060;\n/**\n * @hidden\n */\nconst WindowsConnectionRefused = 10061;\n/**\n * @hidden\n */\nconst WindowsNameTooLong = 10063;\n/**\n * @hidden\n */\nconst WindowsHostIsDown = 10064;\n/**\n * @hidden\n */\nconst WindowsNoRouteTohost = 10065;\n/**\n * @hidden\n */\n\n// Linux Error Codes\n/**\n * @hidden\n */\nconst LinuxConnectionReset = \"ECONNRESET\";\n\n// Node Error Codes\n/**\n * @hidden\n */\nconst BrokenPipe = \"EPIPE\";\n\n/**\n * @hidden\n */\nconst CONNECTION_ERROR_CODES = [\n WindowsInterruptedFunctionCall,\n WindowsFileHandleNotValid,\n WindowsPermissionDenied,\n WindowsBadAddress,\n WindowsInvalidArgumnet,\n WindowsResourceTemporarilyUnavailable,\n WindowsOperationNowInProgress,\n WindowsAddressAlreadyInUse,\n WindowsConnectionResetByPeer,\n WindowsCannotSendAfterSocketShutdown,\n WindowsConnectionTimedOut,\n WindowsConnectionRefused,\n WindowsNameTooLong,\n WindowsHostIsDown,\n WindowsNoRouteTohost,\n LinuxConnectionReset,\n TimeoutErrorCode,\n BrokenPipe,\n];\n\n/**\n * @hidden\n */\nfunction needsRetry(operationType: OperationType, code: number | string): boolean {\n return (\n code === StatusCodes.ENOTFOUND ||\n ((operationType === OperationType.Read || operationType === OperationType.Query) &&\n CONNECTION_ERROR_CODES.includes(code))\n );\n}\n/**\n * This class implements the default connection retry policy for requests.\n * @hidden\n */\nexport class DefaultRetryPolicy implements RetryPolicy {\n private maxTries: number = 10;\n private currentRetryAttemptCount: number = 0;\n public retryAfterInMs: number = 1000;\n\n constructor(private operationType: OperationType) {}\n /**\n * Determines whether the request should be retried or not.\n * @param err - Error returned by the request.\n */\n public async shouldRetry(\n err: ErrorResponse,\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<boolean> {\n if (err) {\n if (\n this.currentRetryAttemptCount < this.maxTries &&\n needsRetry(this.operationType, err.code)\n ) {\n diagnosticNode.addData({ successfulRetryPolicy: \"default\" });\n this.currentRetryAttemptCount++;\n return true;\n }\n }\n return false;\n }\n}\n"]}
@@ -1,9 +1,10 @@
1
1
  import type { DiagnosticNodeInternal } from "../diagnostics/DiagnosticNodeInternal.js";
2
2
  import type { OperationType } from "../common/index.js";
3
3
  import type { GlobalEndpointManager } from "../globalEndpointManager.js";
4
- import type { ErrorResponse } from "../request/index.js";
4
+ import type { ErrorResponse, RequestContext } from "../request/index.js";
5
5
  import type { RetryContext } from "./RetryContext.js";
6
6
  import type { RetryPolicy } from "./RetryPolicy.js";
7
+ import { GlobalPartitionEndpointManager } from "../globalPartitionEndpointManager.js";
7
8
  /**
8
9
  * This class implements the retry policy for endpoint discovery.
9
10
  * @hidden
@@ -11,6 +12,7 @@ import type { RetryPolicy } from "./RetryPolicy.js";
11
12
  export declare class EndpointDiscoveryRetryPolicy implements RetryPolicy {
12
13
  private globalEndpointManager;
13
14
  private operationType;
15
+ private globalPartitionEndpointManager?;
14
16
  /** Current retry attempt count. */
15
17
  currentRetryAttemptCount: number;
16
18
  /** Retry interval in milliseconds. */
@@ -22,11 +24,11 @@ export declare class EndpointDiscoveryRetryPolicy implements RetryPolicy {
22
24
  /**
23
25
  * @param globalEndpointManager - The GlobalEndpointManager instance.
24
26
  */
25
- constructor(globalEndpointManager: GlobalEndpointManager, operationType: OperationType);
27
+ constructor(globalEndpointManager: GlobalEndpointManager, operationType: OperationType, globalPartitionEndpointManager?: GlobalPartitionEndpointManager);
26
28
  /**
27
29
  * Determines whether the request should be retried or not.
28
30
  * @param err - Error returned by the request.
29
31
  */
30
- shouldRetry(err: ErrorResponse, diagnosticNode: DiagnosticNodeInternal, retryContext?: RetryContext, locationEndpoint?: string): Promise<boolean | [boolean, string]>;
32
+ shouldRetry(err: ErrorResponse, diagnosticNode: DiagnosticNodeInternal, retryContext?: RetryContext, locationEndpoint?: string, requestContext?: RequestContext): Promise<boolean | [boolean, string]>;
31
33
  }
32
34
  //# sourceMappingURL=endpointDiscoveryRetryPolicy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpointDiscoveryRetryPolicy.d.ts","sourceRoot":"","sources":["../../../src/retry/endpointDiscoveryRetryPolicy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,qBAAa,4BAA6B,YAAW,WAAW;IAe5D,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,aAAa;IAfvB,mCAAmC;IAC5B,wBAAwB,EAAE,MAAM,CAAC;IACxC,sCAAsC;IAC/B,cAAc,EAAE,MAAM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AAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAO;IACvC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAQ;IAE9C;;OAEG;gBAEO,qBAAqB,EAAE,qBAAqB,EAC5C,aAAa,EAAE,aAAa,EAC5B,8BAA8B,CAAC,EAAE,8BAA8B;IAOzE;;;OAGG;IACU,WAAW,CACtB,GAAG,EAAE,aAAa,EAClB,cAAc,EAAE,sBAAsB,EACtC,YAAY,CAAC,EAAE,YAAY,EAC3B,gBAAgB,CAAC,EAAE,MAAM,EACzB,cAAc,CAAC,EAAE,cAAc,GAC9B,OAAO,CAAC,OAAO,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CA+CxC"}
@@ -7,9 +7,10 @@ export class EndpointDiscoveryRetryPolicy {
7
7
  /**
8
8
  * @param globalEndpointManager - The GlobalEndpointManager instance.
9
9
  */
10
- constructor(globalEndpointManager, operationType) {
10
+ constructor(globalEndpointManager, operationType, globalPartitionEndpointManager) {
11
11
  this.globalEndpointManager = globalEndpointManager;
12
12
  this.operationType = operationType;
13
+ this.globalPartitionEndpointManager = globalPartitionEndpointManager;
13
14
  this.maxTries = EndpointDiscoveryRetryPolicy.maxTries;
14
15
  this.currentRetryAttemptCount = 0;
15
16
  this.retryAfterInMs = EndpointDiscoveryRetryPolicy.retryAfterInMs;
@@ -18,7 +19,7 @@ export class EndpointDiscoveryRetryPolicy {
18
19
  * Determines whether the request should be retried or not.
19
20
  * @param err - Error returned by the request.
20
21
  */
21
- async shouldRetry(err, diagnosticNode, retryContext, locationEndpoint) {
22
+ async shouldRetry(err, diagnosticNode, retryContext, locationEndpoint, requestContext) {
22
23
  if (!err) {
23
24
  return false;
24
25
  }
@@ -28,6 +29,12 @@ export class EndpointDiscoveryRetryPolicy {
28
29
  if (!this.globalEndpointManager.enableEndpointDiscovery) {
29
30
  return false;
30
31
  }
32
+ if (this.globalPartitionEndpointManager) {
33
+ const didFailover = await this.globalPartitionEndpointManager.tryPartitionLevelFailover(requestContext, diagnosticNode);
34
+ if (didFailover) {
35
+ return true;
36
+ }
37
+ }
31
38
  if (this.currentRetryAttemptCount >= this.maxTries) {
32
39
  return false;
33
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"endpointDiscoveryRetryPolicy.js","sourceRoot":"","sources":["../../../src/retry/endpointDiscoveryRetryPolicy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMpD;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IAWvC;;OAEG;IACH,YACU,qBAA4C,EAC5C,aAA4B;QAD5B,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,kBAAa,GAAb,aAAa,CAAe;QAEpC,IAAI,CAAC,QAAQ,GAAG,4BAA4B,CAAC,QAAQ,CAAC;QACtD,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,cAAc,GAAG,4BAA4B,CAAC,cAAc,CAAC;IACpE,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,WAAW,CACtB,GAAkB,EAClB,cAAsC,EACtC,YAA2B,EAC3B,gBAAyB;QAEzB,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,YAAY,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,uBAAuB,EAAE,CAAC;YACxD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,CAAC,wBAAwB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAEhC,IAAI,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,CAAC,qBAAqB,CAAC,qCAAqC,CACpE,cAAc,EACd,gBAAgB,CACjB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,qBAAqB,CAAC,sCAAsC,CACrE,cAAc,EACd,gBAAgB,CACjB,CAAC;QACJ,CAAC;QAED,YAAY,CAAC,UAAU,GAAG,IAAI,CAAC,wBAAwB,CAAC;QACxD,YAAY,CAAC,6BAA6B,GAAG,KAAK,CAAC;QACnD,YAAY,CAAC,gCAAgC,GAAG,KAAK,CAAC;QACtD,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC;IACd,CAAC;;AA5DuB,qCAAQ,GAAG,GAAG,CAAC,CAAC,kBAAkB;AAClC,2CAAc,GAAG,IAAI,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { OperationType } from \"../common/index.js\";\nimport { isReadRequest } from \"../common/helper.js\";\nimport type { GlobalEndpointManager } from \"../globalEndpointManager.js\";\nimport type { ErrorResponse } from \"../request/index.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\n\n/**\n * This class implements the retry policy for endpoint discovery.\n * @hidden\n */\nexport class EndpointDiscoveryRetryPolicy implements RetryPolicy {\n /** Current retry attempt count. */\n public currentRetryAttemptCount: number;\n /** Retry interval in milliseconds. */\n public retryAfterInMs: number;\n\n /** Max number of retry attempts to perform. */\n private maxTries: number;\n private static readonly maxTries = 120; // TODO: Constant?\n private static readonly retryAfterInMs = 1000;\n\n /**\n * @param globalEndpointManager - The GlobalEndpointManager instance.\n */\n constructor(\n private globalEndpointManager: GlobalEndpointManager,\n private operationType: OperationType,\n ) {\n this.maxTries = EndpointDiscoveryRetryPolicy.maxTries;\n this.currentRetryAttemptCount = 0;\n this.retryAfterInMs = EndpointDiscoveryRetryPolicy.retryAfterInMs;\n }\n\n /**\n * Determines whether the request should be retried or not.\n * @param err - Error returned by the request.\n */\n public async shouldRetry(\n err: ErrorResponse,\n diagnosticNode: DiagnosticNodeInternal,\n retryContext?: RetryContext,\n locationEndpoint?: string,\n ): Promise<boolean | [boolean, string]> {\n if (!err) {\n return false;\n }\n\n if (!retryContext || !locationEndpoint) {\n return false;\n }\n\n if (!this.globalEndpointManager.enableEndpointDiscovery) {\n return false;\n }\n\n if (this.currentRetryAttemptCount >= this.maxTries) {\n return false;\n }\n\n this.currentRetryAttemptCount++;\n\n if (isReadRequest(this.operationType)) {\n await this.globalEndpointManager.markCurrentLocationUnavailableForRead(\n diagnosticNode,\n locationEndpoint,\n );\n } else {\n await this.globalEndpointManager.markCurrentLocationUnavailableForWrite(\n diagnosticNode,\n locationEndpoint,\n );\n }\n\n retryContext.retryCount = this.currentRetryAttemptCount;\n retryContext.clearSessionTokenNotAvailable = false;\n retryContext.retryRequestOnPreferredLocations = false;\n diagnosticNode.addData({ successfulRetryPolicy: \"endpointDiscovery\" });\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"endpointDiscoveryRetryPolicy.js","sourceRoot":"","sources":["../../../src/retry/endpointDiscoveryRetryPolicy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAOpD;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IAWvC;;OAEG;IACH,YACU,qBAA4C,EAC5C,aAA4B,EAC5B,8BAA+D;QAF/D,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,kBAAa,GAAb,aAAa,CAAe;QAC5B,mCAA8B,GAA9B,8BAA8B,CAAiC;QAEvE,IAAI,CAAC,QAAQ,GAAG,4BAA4B,CAAC,QAAQ,CAAC;QACtD,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,cAAc,GAAG,4BAA4B,CAAC,cAAc,CAAC;IACpE,CAA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AC;IACd,CAAC;;AAxEuB,qCAAQ,GAAG,GAAG,CAAC,CAAC,kBAAkB;AAClC,2CAAc,GAAG,IAAI,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { OperationType } from \"../common/index.js\";\nimport { isReadRequest } from \"../common/helper.js\";\nimport type { GlobalEndpointManager } from \"../globalEndpointManager.js\";\nimport type { ErrorResponse, RequestContext } from \"../request/index.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\nimport { GlobalPartitionEndpointManager } from \"../globalPartitionEndpointManager.js\";\n\n/**\n * This class implements the retry policy for endpoint discovery.\n * @hidden\n */\nexport class EndpointDiscoveryRetryPolicy implements RetryPolicy {\n /** Current retry attempt count. */\n public currentRetryAttemptCount: number;\n /** Retry interval in milliseconds. */\n public retryAfterInMs: number;\n\n /** Max number of retry attempts to perform. */\n private maxTries: number;\n private static readonly maxTries = 120; // TODO: Constant?\n private static readonly retryAfterInMs = 1000;\n\n /**\n * @param globalEndpointManager - The GlobalEndpointManager instance.\n */\n constructor(\n private globalEndpointManager: GlobalEndpointManager,\n private operationType: OperationType,\n private globalPartitionEndpointManager?: GlobalPartitionEndpointManager,\n ) {\n this.maxTries = EndpointDiscoveryRetryPolicy.maxTries;\n this.currentRetryAttemptCount = 0;\n this.retryAfterInMs = EndpointDiscoveryRetryPolicy.retryAfterInMs;\n }\n\n /**\n * Determines whether the request should be retried or not.\n * @param err - Error returned by the request.\n */\n public async shouldRetry(\n err: ErrorResponse,\n diagnosticNode: DiagnosticNodeInternal,\n retryContext?: RetryContext,\n locationEndpoint?: string,\n requestContext?: RequestContext,\n ): Promise<boolean | [boolean, string]> {\n if (!err) {\n return false;\n }\n\n if (!retryContext || !locationEndpoint) {\n return false;\n }\n\n if (!this.globalEndpointManager.enableEndpointDiscovery) {\n return false;\n }\n\n if (this.globalPartitionEndpointManager) {\n const didFailover = await this.globalPartitionEndpointManager.tryPartitionLevelFailover(\n requestContext,\n diagnosticNode,\n );\n if (didFailover) {\n return true;\n }\n }\n\n if (this.currentRetryAttemptCount >= this.maxTries) {\n return false;\n }\n\n this.currentRetryAttemptCount++;\n\n if (isReadRequest(this.operationType)) {\n await this.globalEndpointManager.markCurrentLocationUnavailableForRead(\n diagnosticNode,\n locationEndpoint,\n );\n } else {\n await this.globalEndpointManager.markCurrentLocationUnavailableForWrite(\n diagnosticNode,\n locationEndpoint,\n );\n }\n\n retryContext.retryCount = this.currentRetryAttemptCount;\n retryContext.clearSessionTokenNotAvailable = false;\n retryContext.retryRequestOnPreferredLocations = false;\n diagnosticNode.addData({ successfulRetryPolicy: \"endpointDiscovery\" });\n return true;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"retryUtility.d.ts","sourceRoot":"","sources":["../../../src/retry/retryUtility.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAEvF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAInE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E;;GAEG;AACH,UAAU,WAAW;IACnB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,cAAc,EAAE,sBAAsB,CAAC;IACvC,aAAa,CAAC,EAAE,aAAa,CAA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IACvC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,cAAc,EAAE,cAAc,CAAC;IAC/B,cAAc,EAAE,CACd,cAAc,EAAE,sBAAsB,EACtC,cAAc,EAAE,cAAc,KAC3B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,UAAU,aAAa;IACrB,4BAA4B,EAAE,4BAA4B,CAAC;IAC3D,2BAA2B,EAAE,2BAA2B,CAAC;IACzD,sBAAsB,EAAE,kBAAkB,CAAC;IAC3C,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,0BAA0B,EAAE,0BAA0B,CAAC;CACxD;AAED;;GAEG;AACH,wBAAsB,OAAO,CAAC,EAC5B,cAAc,EACd,YAAgC,EAChC,aAAa,EACb,cAAc,EACd,cAAc,GACf,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAkJtC"}
@@ -22,11 +22,11 @@ export async function execute({ diagnosticNode, retryContext = { retryCount: 0 }
22
22
  localDiagnosticNode.addData({ requestAttempNumber: retryContext.retryCount });
23
23
  if (!retryPolicies) {
24
24
  retryPolicies = {
25
- endpointDiscoveryRetryPolicy: new EndpointDiscoveryRetryPolicy(requestContext.globalEndpointManager, requestContext.operationType),
25
+ endpointDiscoveryRetryPolicy: new EndpointDiscoveryRetryPolicy(requestContext.globalEndpointManager, requestContext.operationType, requestContext.globalPartitionEndpointManager),
26
26
  resourceThrottleRetryPolicy: new ResourceThrottleRetryPolicy((_a = requestContext.connectionPolicy.retryOptions) !== null && _a !== void 0 ? _a : {}),
27
27
  sessionReadRetryPolicy: new SessionRetryPolicy(requestContext.globalEndpointManager, requestContext.resourceType, requestContext.operationType, requestContext.connectionPolicy),
28
28
  defaultRetryPolicy: new DefaultRetryPolicy(requestContext.operationType),
29
- timeoutFailoverRetryPolicy: new TimeoutFailoverRetryPolicy(requestContext.globalEndpointManager, requestContext.headers, requestContext.method, requestContext.resourceType, requestContext.operationType, requestContext.connectionPolicy.enableEndpointDiscovery),
29
+ timeoutFailoverRetryPolicy: new TimeoutFailoverRetryPolicy(requestContext.globalEndpointManager, requestContext.headers, requestContext.method, requestContext.resourceType, requestContext.operationType, requestContext.connectionPolicy.enableEndpointDiscovery, requestContext.connectionPolicy.enablePartitionLevelFailover, requestContext.globalPartitionEndpointManager),
30
30
  };
31
31
  }
32
32
  if (retryContext && retryContext.clearSessionTokenNotAvailable) {
@@ -41,6 +41,13 @@ export async function execute({ diagnosticNode, retryContext = { retryCount: 0 }
41
41
  }
42
42
  const startTimeUTCInMs = getCurrentTimestampInMs();
43
43
  const correlatedActivityId = requestContext.headers[Constants.HttpHeaders.CorrelatedActivityId];
44
+ if (requestContext.globalPartitionEndpointManager) {
45
+ // Try partition level location override
46
+ // This is used to override the partition level location for the request
47
+ // if there has been a partition level failover
48
+ requestContext =
49
+ await requestContext.globalPartitionEndpointManager.tryAddPartitionLevelLocationOverride(requestContext, localDiagnosticNode);
50
+ }
44
51
  try {
45
52
  const response = await executeRequest(localDiagnosticNode, requestContext);
46
53
  response.headers[Constants.ThrottleRetryCount] =
@@ -59,8 +66,7 @@ export async function execute({ diagnosticNode, retryContext = { retryCount: 0 }
59
66
  if (correlatedActivityId) {
60
67
  headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;
61
68
  }
62
- if (err.code === StatusCodes.ENOTFOUND ||
63
- err.code === "REQUEST_SEND_ERROR" ||
69
+ if (err.code === "REQUEST_SEND_ERROR" ||
64
70
  (err.code === StatusCodes.Forbidden &&
65
71
  (err.substatus === SubStatusCodes.DatabaseAccountNotFound ||
66
72
  err.substatus === SubStatusCodes.WriteForbidden))) {
@@ -79,7 +85,7 @@ export async function execute({ diagnosticNode, retryContext = { retryCount: 0 }
79
85
  else {
80
86
  retryPolicy = retryPolicies.defaultRetryPolicy;
81
87
  }
82
- const results = await retryPolicy.shouldRetry(err, localDiagnosticNode, retryContext, requestContext.endpoint);
88
+ const results = await retryPolicy.shouldRetry(err, localDiagnosticNode, retryContext, requestContext.endpoint, requestContext);
83
89
  if (!results) {
84
90
  headers[Constants.ThrottleRetryCount] =
85
91
  retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;
@@ -1 +1 @@
1
- {"version":3,"file":"retryUtility.js","sourceRoot":"","sources":["../../../src/retry/retryUtility.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAG9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAG/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AA2B7E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,EAC5B,cAAc,EACd,YAAY,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,EAChC,aAAa,EACb,cAAc,EACd,cAAc,GACF;IACZ,qBAAqB;IACrB,OAAO,kBAAkB,CACvB,KAAK,EAAE,mBAA2C,EAAE,EAAE;;QACpD,mBAAmB,CAAC,OAAO,CAAC,EAAE,mBAAmB,EAAE,YAAY,CAAC,UAAU,EAAE,CAAC,CAAC;Q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MAAM,KAAK,SAAS,EAAE,CAAC;oBACzB,cAAc,CAAC,QAAQ,GAAG,MAAM,CAAC;gBACnC,CAAC;gBACD,mBAAmB,CAAC,uBAAuB,CACzC,gBAAgB,EAChB,cAAc,EACd,YAAY,CAAC,UAAU,EACvB,GAAG,CAAC,IAAI,EACR,GAAG,CAAC,cAAc,EAClB,OAAO,CACR,CAAC;gBACF,MAAM,KAAK,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;gBACxC,OAAO,OAAO,CAAC;oBACb,cAAc;oBACd,cAAc;oBACd,cAAc;oBACd,YAAY;oBACZ,aAAa;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,EACD,cAAc,EACd,kBAAkB,CAAC,YAAY,CAChC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,cAA8B;IACnD,OAAO,CACL,cAAc,CAAC,aAAa,KAAK,OAAO;QACxC,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { Constants } from \"../common/constants.js\";\nimport { sleep } from \"../common/helper.js\";\nimport { StatusCodes, SubStatusCodes } from \"../common/statusCodes.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { DiagnosticNodeType } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { Response } from \"../request/index.js\";\nimport type { RequestContext } from \"../request/RequestContext.js\";\nimport { TimeoutErrorCode } from \"../request/TimeoutError.js\";\nimport { addDiagnosticChild } from \"../utils/diagnostics.js\";\nimport { getCurrentTimestampInMs } from \"../utils/time.js\";\nimport { DefaultRetryPolicy } from \"./defaultRetryPolicy.js\";\nimport { EndpointDiscoveryRetryPolicy } from \"./endpointDiscoveryRetryPolicy.js\";\nimport { ResourceThrottleRetryPolicy } from \"./resourceThrottleRetryPolicy.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\nimport { SessionRetryPolicy } from \"./sessionRetryPolicy.js\";\nimport { TimeoutFailoverRetryPolicy } from \"./timeoutFailoverRetryPolicy.js\";\n\n/**\n * @hidden\n */\ninterface ExecuteArgs {\n retryContext?: RetryContext;\n diagnosticNode: DiagnosticNodeInternal;\n retryPolicies?: RetryPolicies;\n requestContext: RequestContext;\n executeRequest: (\n diagnosticNode: DiagnosticNodeInternal,\n requestContext: RequestContext,\n ) => Promise<Response<any>>;\n}\n\n/**\n * @hidden\n */\ninterface RetryPolicies {\n endpointDiscoveryRetryPolicy: EndpointDiscoveryRetryPolicy;\n resourceThrottleRetryPolicy: ResourceThrottleRetryPolicy;\n sessionReadRetryPolicy: SessionRetryPolicy;\n defaultRetryPolicy: DefaultRetryPolicy;\n timeoutFailoverRetryPolicy: TimeoutFailoverRetryPolicy;\n}\n\n/**\n * @hidden\n */\nexport async function execute({\n diagnosticNode,\n retryContext = { retryCount: 0 },\n retryPolicies,\n requestContext,\n executeRequest,\n}: ExecuteArgs): Promise<Response<any>> {\n // TODO: any response\n return addDiagnosticChild(\n async (localDiagnosticNode: DiagnosticNodeInternal) => {\n localDiagnosticNode.addData({ requestAttempNumber: retryContext.retryCount });\n if (!retryPolicies) {\n retryPolicies = {\n endpointDiscoveryRetryPolicy: new EndpointDiscoveryRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.operationType,\n ),\n resourceThrottleRetryPolicy: new ResourceThrottleRetryPolicy(\n requestContext.connectionPolicy.retryOptions ?? {},\n ),\n sessionReadRetryPolicy: new SessionRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.connectionPolicy,\n ),\n defaultRetryPolicy: new DefaultRetryPolicy(requestContext.operationType),\n timeoutFailoverRetryPolicy: new TimeoutFailoverRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.headers,\n requestContext.method,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.connectionPolicy.enableEndpointDiscovery,\n ),\n };\n }\n if (retryContext && retryContext.clearSessionTokenNotAvailable) {\n requestContext.client.clearSessionToken(requestContext.path);\n delete requestContext.headers[\"x-ms-session-token\"];\n }\n if (retryContext && retryContext.retryLocationServerIndex) {\n requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(\n localDiagnosticNode,\n requestContext.resourceType,\n requestContext.operationType,\n retryContext.retryLocationServerIndex,\n );\n } else {\n requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(\n localDiagnosticNode,\n requestContext.resourceType,\n requestContext.operationType,\n );\n }\n const startTimeUTCInMs = getCurrentTimestampInMs();\n const correlatedActivityId =\n requestContext.headers[Constants.HttpHeaders.CorrelatedActivityId];\n try {\n const response = await executeRequest(localDiagnosticNode, requestContext);\n response.headers[Constants.ThrottleRetryCount] =\n retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;\n response.headers[Constants.ThrottleRetryWaitTimeInMs] =\n retryPolicies.resourceThrottleRetryPolicy.cummulativeWaitTimeinMs;\n if (correlatedActivityId) {\n response.headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;\n }\n return response;\n } catch (err: any) {\n // TODO: any error\n let retryPolicy: RetryPolicy = null;\n const headers = err.headers || {};\n if (correlatedActivityId) {\n headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;\n }\n if (\n err.code === StatusCodes.ENOTFOUND ||\n err.code === \"REQUEST_SEND_ERROR\" ||\n (err.code === StatusCodes.Forbidden &&\n (err.substatus === SubStatusCodes.DatabaseAccountNotFound ||\n err.substatus === SubStatusCodes.WriteForbidden))\n ) {\n retryPolicy = retryPolicies.endpointDiscoveryRetryPolicy;\n } else if (err.code === StatusCodes.TooManyRequests && !isBulkRequest(requestContext)) {\n retryPolicy = retryPolicies.resourceThrottleRetryPolicy;\n } else if (\n err.code === StatusCodes.NotFound &&\n err.substatus === SubStatusCodes.ReadSessionNotAvailable\n ) {\n retryPolicy = retryPolicies.sessionReadRetryPolicy;\n } else if (err.code === StatusCodes.ServiceUnavailable || err.code === TimeoutErrorCode) {\n retryPolicy = retryPolicies.timeoutFailoverRetryPolicy;\n } else {\n retryPolicy = retryPolicies.defaultRetryPolicy;\n }\n const results = await retryPolicy.shouldRetry(\n err,\n localDiagnosticNode,\n retryContext,\n requestContext.endpoint,\n );\n if (!results) {\n headers[Constants.ThrottleRetryCount] =\n retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;\n headers[Constants.ThrottleRetryWaitTimeInMs] =\n retryPolicies.resourceThrottleRetryPolicy.cummulativeWaitTimeinMs;\n err.headers = { ...err.headers, ...headers };\n throw err;\n } else {\n requestContext.retryCount++;\n const newUrl = (results as any)[1]; // TODO: any hack\n if (newUrl !== undefined) {\n requestContext.endpoint = newUrl;\n }\n localDiagnosticNode.recordFailedNetworkCall(\n startTimeUTCInMs,\n requestContext,\n retryContext.retryCount,\n err.code,\n err.subsstatusCode,\n headers,\n );\n await sleep(retryPolicy.retryAfterInMs);\n return execute({\n diagnosticNode,\n executeRequest,\n requestContext,\n retryContext,\n retryPolicies,\n });\n }\n }\n },\n diagnosticNode,\n DiagnosticNodeType.HTTP_REQUEST,\n );\n}\n\n/**\n * @hidden\n */\nfunction isBulkRequest(requestContext: RequestContext): boolean {\n return (\n requestContext.operationType === \"batch\" &&\n !requestContext.headers[Constants.HttpHeaders.IsBatchAtomic]\n );\n}\n"]}
1
+ {"version":3,"file":"retryUtility.js","sourceRoot":"","sources":["../../../src/retry/retryUtility.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,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C,cAAc,EAClB,OAAO,CACR,CAAC;gBACF,MAAM,KAAK,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;gBACxC,OAAO,OAAO,CAAC;oBACb,cAAc;oBACd,cAAc;oBACd,cAAc;oBACd,YAAY;oBACZ,aAAa;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,EACD,cAAc,EACd,kBAAkB,CAAC,YAAY,CAChC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,cAA8B;IACnD,OAAO,CACL,cAAc,CAAC,aAAa,KAAK,OAAO;QACxC,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { Constants } from \"../common/constants.js\";\nimport { sleep } from \"../common/helper.js\";\nimport { StatusCodes, SubStatusCodes } from \"../common/statusCodes.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { DiagnosticNodeType } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { Response } from \"../request/index.js\";\nimport type { RequestContext } from \"../request/RequestContext.js\";\nimport { TimeoutErrorCode } from \"../request/TimeoutError.js\";\nimport { addDiagnosticChild } from \"../utils/diagnostics.js\";\nimport { getCurrentTimestampInMs } from \"../utils/time.js\";\nimport { DefaultRetryPolicy } from \"./defaultRetryPolicy.js\";\nimport { EndpointDiscoveryRetryPolicy } from \"./endpointDiscoveryRetryPolicy.js\";\nimport { ResourceThrottleRetryPolicy } from \"./resourceThrottleRetryPolicy.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\nimport { SessionRetryPolicy } from \"./sessionRetryPolicy.js\";\nimport { TimeoutFailoverRetryPolicy } from \"./timeoutFailoverRetryPolicy.js\";\n\n/**\n * @hidden\n */\ninterface ExecuteArgs {\n retryContext?: RetryContext;\n diagnosticNode: DiagnosticNodeInternal;\n retryPolicies?: RetryPolicies;\n requestContext: RequestContext;\n executeRequest: (\n diagnosticNode: DiagnosticNodeInternal,\n requestContext: RequestContext,\n ) => Promise<Response<any>>;\n}\n\n/**\n * @hidden\n */\ninterface RetryPolicies {\n endpointDiscoveryRetryPolicy: EndpointDiscoveryRetryPolicy;\n resourceThrottleRetryPolicy: ResourceThrottleRetryPolicy;\n sessionReadRetryPolicy: SessionRetryPolicy;\n defaultRetryPolicy: DefaultRetryPolicy;\n timeoutFailoverRetryPolicy: TimeoutFailoverRetryPolicy;\n}\n\n/**\n * @hidden\n */\nexport async function execute({\n diagnosticNode,\n retryContext = { retryCount: 0 },\n retryPolicies,\n requestContext,\n executeRequest,\n}: ExecuteArgs): Promise<Response<any>> {\n // TODO: any response\n return addDiagnosticChild(\n async (localDiagnosticNode: DiagnosticNodeInternal) => {\n localDiagnosticNode.addData({ requestAttempNumber: retryContext.retryCount });\n if (!retryPolicies) {\n retryPolicies = {\n endpointDiscoveryRetryPolicy: new EndpointDiscoveryRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.operationType,\n requestContext.globalPartitionEndpointManager,\n ),\n resourceThrottleRetryPolicy: new ResourceThrottleRetryPolicy(\n requestContext.connectionPolicy.retryOptions ?? {},\n ),\n sessionReadRetryPolicy: new SessionRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.connectionPolicy,\n ),\n defaultRetryPolicy: new DefaultRetryPolicy(requestContext.operationType),\n timeoutFailoverRetryPolicy: new TimeoutFailoverRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.headers,\n requestContext.method,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.connectionPolicy.enableEndpointDiscovery,\n requestContext.connectionPolicy.enablePartitionLevelFailover,\n requestContext.globalPartitionEndpointManager,\n ),\n };\n }\n if (retryContext && retryContext.clearSessionTokenNotAvailable) {\n requestContext.client.clearSessionToken(requestContext.path);\n delete requestContext.headers[\"x-ms-session-token\"];\n }\n if (retryContext && retryContext.retryLocationServerIndex) {\n requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(\n localDiagnosticNode,\n requestContext.resourceType,\n requestContext.operationType,\n retryContext.retryLocationServerIndex,\n );\n } else {\n requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(\n localDiagnosticNode,\n requestContext.resourceType,\n requestContext.operationType,\n );\n }\n const startTimeUTCInMs = getCurrentTimestampInMs();\n const correlatedActivityId =\n requestContext.headers[Constants.HttpHeaders.CorrelatedActivityId];\n\n if (requestContext.globalPartitionEndpointManager) {\n // Try partition level location override\n // This is used to override the partition level location for the request\n // if there has been a partition level failover\n requestContext =\n await requestContext.globalPartitionEndpointManager.tryAddPartitionLevelLocationOverride(\n requestContext,\n localDiagnosticNode,\n );\n }\n\n try {\n const response = await executeRequest(localDiagnosticNode, requestContext);\n response.headers[Constants.ThrottleRetryCount] =\n retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;\n response.headers[Constants.ThrottleRetryWaitTimeInMs] =\n retryPolicies.resourceThrottleRetryPolicy.cummulativeWaitTimeinMs;\n if (correlatedActivityId) {\n response.headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;\n }\n return response;\n } catch (err: any) {\n // TODO: any error\n let retryPolicy: RetryPolicy = null;\n const headers = err.headers || {};\n if (correlatedActivityId) {\n headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;\n }\n\n if (\n err.code === \"REQUEST_SEND_ERROR\" ||\n (err.code === StatusCodes.Forbidden &&\n (err.substatus === SubStatusCodes.DatabaseAccountNotFound ||\n err.substatus === SubStatusCodes.WriteForbidden))\n ) {\n retryPolicy = retryPolicies.endpointDiscoveryRetryPolicy;\n } else if (err.code === StatusCodes.TooManyRequests && !isBulkRequest(requestContext)) {\n retryPolicy = retryPolicies.resourceThrottleRetryPolicy;\n } else if (\n err.code === StatusCodes.NotFound &&\n err.substatus === SubStatusCodes.ReadSessionNotAvailable\n ) {\n retryPolicy = retryPolicies.sessionReadRetryPolicy;\n } else if (err.code === StatusCodes.ServiceUnavailable || err.code === TimeoutErrorCode) {\n retryPolicy = retryPolicies.timeoutFailoverRetryPolicy;\n } else {\n retryPolicy = retryPolicies.defaultRetryPolicy;\n }\n const results = await retryPolicy.shouldRetry(\n err,\n localDiagnosticNode,\n retryContext,\n requestContext.endpoint,\n requestContext,\n );\n if (!results) {\n headers[Constants.ThrottleRetryCount] =\n retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;\n headers[Constants.ThrottleRetryWaitTimeInMs] =\n retryPolicies.resourceThrottleRetryPolicy.cummulativeWaitTimeinMs;\n err.headers = { ...err.headers, ...headers };\n throw err;\n } else {\n requestContext.retryCount++;\n const newUrl = (results as any)[1]; // TODO: any hack\n if (newUrl !== undefined) {\n requestContext.endpoint = newUrl;\n }\n localDiagnosticNode.recordFailedNetworkCall(\n startTimeUTCInMs,\n requestContext,\n retryContext.retryCount,\n err.code,\n err.subsstatusCode,\n headers,\n );\n await sleep(retryPolicy.retryAfterInMs);\n return execute({\n diagnosticNode,\n executeRequest,\n requestContext,\n retryContext,\n retryPolicies,\n });\n }\n }\n },\n diagnosticNode,\n DiagnosticNodeType.HTTP_REQUEST,\n );\n}\n\n/**\n * @hidden\n */\nfunction isBulkRequest(requestContext: RequestContext): boolean {\n return (\n requestContext.operationType === \"batch\" &&\n !requestContext.headers[Constants.HttpHeaders.IsBatchAtomic]\n );\n}\n"]}
@@ -4,8 +4,9 @@ import { HTTPMethod } from "../common/index.js";
4
4
  import type { OperationType, ResourceType } from "../common/constants.js";
5
5
  import type { RetryContext } from "./RetryContext.js";
6
6
  import type { CosmosHeaders } from "../queryExecutionContext/CosmosHeaders.js";
7
- import type { ErrorResponse } from "../request/index.js";
7
+ import type { ErrorResponse, RequestContext } from "../request/index.js";
8
8
  import type { DiagnosticNodeInternal } from "../diagnostics/DiagnosticNodeInternal.js";
9
+ import { GlobalPartitionEndpointManager } from "../globalPartitionEndpointManager.js";
9
10
  /**
10
11
  * This class TimeoutFailoverRetryPolicy handles retries for read operations
11
12
  * (including data plane,metadata, and query plan) in case of request timeouts
@@ -20,20 +21,22 @@ export declare class TimeoutFailoverRetryPolicy implements RetryPolicy {
20
21
  private resourceType;
21
22
  private operationType;
22
23
  private enableEndPointDiscovery;
24
+ private enablePartitionLevelFailover;
25
+ private globalPartitionEndpointManager?;
23
26
  private maxRetryAttemptCount;
24
27
  private maxServiceUnavailableRetryCount;
25
28
  retryAfterInMs: number;
26
29
  failoverRetryCount: number;
27
30
  request: any;
28
31
  locationEndpoint: any;
29
- constructor(globalEndpointManager: GlobalEndpointManager, headers: CosmosHeaders, methodType: HTTPMethod, resourceType: ResourceType, operationType: OperationType, enableEndPointDiscovery: boolean);
32
+ constructor(globalEndpointManager: GlobalEndpointManager, headers: CosmosHeaders, methodType: HTTPMethod, resourceType: ResourceType, operationType: OperationType, enableEndPointDiscovery: boolean, enablePartitionLevelFailover: boolean, globalPartitionEndpointManager?: GlobalPartitionEndpointManager);
30
33
  /**
31
34
  * Checks if a timeout request is valid for the timeout failover retry policy.
32
35
  * A valid request should be a data plane, metadata, or query plan request.
33
36
  * @returns
34
37
  */
35
38
  private isValidRequestForTimeoutError;
36
- shouldRetry(err: ErrorResponse, diagnosticNode: DiagnosticNodeInternal, retryContext?: RetryContext, locationEndpoint?: string): Promise<boolean>;
39
+ shouldRetry(err: ErrorResponse, diagnosticNode: DiagnosticNodeInternal, retryContext?: RetryContext, locationEndpoint?: string, requestContext?: RequestContext): Promise<boolean>;
37
40
  /**
38
41
  * Determines index of endpoint to be used for retry based upon failoverRetryCount and avalable locations
39
42
  * @param failoverRetryCount - count of failovers
@@ -1 +1 @@
1
- {"version":3,"file":"timeoutFailoverRetryPolicy.d.ts","sourceRoot":"","sources":["../../../src/retry/timeoutFailoverRetryPolicy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW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8BAA8B,CAAC,EAAE,8BAA8B;IAGzE;;;;OAIG;IACH,OAAO,CAAC,6BAA6B;IASxB,WAAW,CACtB,GAAG,EAAE,aAAa,EAClB,cAAc,EAAE,sBAAsB,EACtC,YAAY,CAAC,EAAE,YAAY,EAC3B,gBAAgB,CAAC,EAAE,MAAM,EACzB,cAAc,CAAC,EAAE,cAAc,GAC9B,OAAO,CAAC,OAAO,CAAC;IAoDnB;;;;OAIG;YACW,iBAAiB;CAyBhC"}
@@ -10,13 +10,15 @@ import { TimeoutErrorCode } from "../request/TimeoutError.js";
10
10
  * @hidden
11
11
  */
12
12
  export class TimeoutFailoverRetryPolicy {
13
- constructor(globalEndpointManager, headers, methodType, resourceType, operationType, enableEndPointDiscovery) {
13
+ constructor(globalEndpointManager, headers, methodType, resourceType, operationType, enableEndPointDiscovery, enablePartitionLevelFailover, globalPartitionEndpointManager) {
14
14
  this.globalEndpointManager = globalEndpointManager;
15
15
  this.headers = headers;
16
16
  this.methodType = methodType;
17
17
  this.resourceType = resourceType;
18
18
  this.operationType = operationType;
19
19
  this.enableEndPointDiscovery = enableEndPointDiscovery;
20
+ this.enablePartitionLevelFailover = enablePartitionLevelFailover;
21
+ this.globalPartitionEndpointManager = globalPartitionEndpointManager;
20
22
  this.maxRetryAttemptCount = 120;
21
23
  this.maxServiceUnavailableRetryCount = 1;
22
24
  this.retryAfterInMs = 0;
@@ -35,13 +37,18 @@ export class TimeoutFailoverRetryPolicy {
35
37
  }
36
38
  return false;
37
39
  }
38
- async shouldRetry(err, diagnosticNode, retryContext, locationEndpoint) {
40
+ async shouldRetry(err, diagnosticNode, retryContext, locationEndpoint, requestContext) {
39
41
  if (!err) {
40
42
  return false;
41
43
  }
42
44
  if (!retryContext || !locationEndpoint) {
43
45
  return false;
44
46
  }
47
+ // Mark the partition as unavailable.
48
+ // Let the Retry logic decide if the request should be retried
49
+ if (requestContext && this.globalPartitionEndpointManager) {
50
+ await this.globalPartitionEndpointManager.tryPartitionLevelFailover(requestContext, diagnosticNode);
51
+ }
45
52
  // Check if the error is a timeout error (TimeoutErrorCode) and if it is not a valid HTTP network timeout request
46
53
  if (err.code === TimeoutErrorCode && !this.isValidRequestForTimeoutError()) {
47
54
  return false;
@@ -58,8 +65,9 @@ export class TimeoutFailoverRetryPolicy {
58
65
  }
59
66
  const canUseMultipleWriteLocations = this.globalEndpointManager.canUseMultipleWriteLocations(this.resourceType, this.operationType);
60
67
  const readRequest = isReadRequest(this.operationType);
61
- if (!canUseMultipleWriteLocations && !readRequest) {
62
- // Write requests on single master cannot be retried, no other regions available
68
+ if (!canUseMultipleWriteLocations && !readRequest && !this.enablePartitionLevelFailover) {
69
+ // Write requests on single master cannot be retried if partition level failover is disabled.
70
+ // This means there are no other regions available to serve the writes.
63
71
  return false;
64
72
  }
65
73
  this.failoverRetryCount++;
@@ -1 +1 @@
1
- {"version":3,"file":"timeoutFailoverRetryPolicy.js","sourceRoot":"","sources":["../../../src/retry/timeoutFailoverRetryPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI9D;;;;;;GAMG;AACH,MAAM,OAAO,0BAA0B;IAQrC,YACU,qBAA4C,EAC5C,OAAsB,EACtB,UAAsB,EACtB,YAA0B,EAC1B,aAA4B,EAC5B,uBAAgC;QALhC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,YAAO,GAAP,OAAO,CAAe;QACtB,eAAU,GAAV,UAAU,CAAY;QACtB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,kBAAa,GAAb,aAAa,CAAe;QAC5B,4BAAuB,GAAvB,uBAAuB,CAAS;QAblC,yBAAoB,GAAG,GAAG,CAAC;QAC3B,oCAA+B,GA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M,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,EAAE,CAAC;gBAC/E,IAAI,iBAAiB,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtD,aAAa,GAAG,kBAAkB,GAAG,iBAAiB,CAAC,MAAM,CAAC;gBAChE,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\nimport { StatusCodes } from \"../common/statusCodes.js\";\nimport type { GlobalEndpointManager } from \"../globalEndpointManager.js\";\nimport { HTTPMethod, isReadRequest } from \"../common/index.js\";\nimport type { OperationType, ResourceType } from \"../common/constants.js\";\nimport { Constants } from \"../common/constants.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { CosmosHeaders } from \"../queryExecutionContext/CosmosHeaders.js\";\nimport { TimeoutErrorCode } from \"../request/TimeoutError.js\";\nimport type { ErrorResponse } from \"../request/index.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\n\n/**\n * This class TimeoutFailoverRetryPolicy handles retries for read operations\n * (including data plane,metadata, and query plan) in case of request timeouts\n * (TimeoutError) or service unavailability (503 status code) by performing failover\n * and retrying on other regions.\n * @hidden\n */\nexport class TimeoutFailoverRetryPolicy implements RetryPolicy {\n private maxRetryAttemptCount = 120;\n private maxServiceUnavailableRetryCount = 1;\n public retryAfterInMs = 0;\n public failoverRetryCount = 0;\n public request: any;\n public locationEndpoint: any;\n\n constructor(\n private globalEndpointManager: GlobalEndpointManager,\n private headers: CosmosHeaders,\n private methodType: HTTPMethod,\n private resourceType: ResourceType,\n private operationType: OperationType,\n private enableEndPointDiscovery: boolean,\n ) {}\n\n /**\n * Checks if a timeout request is valid for the timeout failover retry policy.\n * A valid request should be a data plane, metadata, or query plan request.\n * @returns\n */\n private isValidRequestForTimeoutError(): boolean {\n const isQuery = Constants.HttpHeaders.IsQuery in this.headers;\n const isQueryPlan = Constants.HttpHeaders.IsQueryPlan in this.headers;\n if (this.methodType === HTTPMethod.get || isQuery || isQueryPlan) {\n return true;\n }\n return false;\n }\n\n public async shouldRetry(\n err: ErrorResponse,\n diagnosticNode: DiagnosticNodeInternal,\n retryContext?: RetryContext,\n locationEndpoint?: string,\n ): Promise<boolean> {\n if (!err) {\n return false;\n }\n if (!retryContext || !locationEndpoint) {\n return false;\n }\n // Check if the error is a timeout error (TimeoutErrorCode) and if it is not a valid HTTP network timeout request\n if (err.code === TimeoutErrorCode && !this.isValidRequestForTimeoutError()) {\n return false;\n }\n if (!this.enableEndPointDiscovery) {\n return false;\n }\n if (\n err.code === StatusCodes.ServiceUnavailable &&\n this.failoverRetryCount >= this.maxServiceUnavailableRetryCount\n ) {\n return false;\n }\n if (this.failoverRetryCount >= this.maxRetryAttemptCount) {\n return false;\n }\n const canUseMultipleWriteLocations = this.globalEndpointManager.canUseMultipleWriteLocations(\n this.resourceType,\n this.operationType,\n );\n const readRequest = isReadRequest(this.operationType);\n\n if (!canUseMultipleWriteLocations && !readRequest) {\n // Write requests on single master cannot be retried, no other regions available\n return false;\n }\n this.failoverRetryCount++;\n // Setting the retryLocationIndex to the next available location for retry.\n // The retryLocationIndex is determined based on the failoverRetryCount, starting from zero.\n retryContext.retryLocationServerIndex = await this.findEndpointIndex(this.failoverRetryCount);\n diagnosticNode.addData({ successfulRetryPolicy: \"timeout-failover\" });\n return true;\n }\n\n /**\n * Determines index of endpoint to be used for retry based upon failoverRetryCount and avalable locations\n * @param failoverRetryCount - count of failovers\n * @returns\n */\n private async findEndpointIndex(failoverRetryCount: number): Promise<number> {\n // count of preferred locations specified by user\n const preferredLocationsCount = this.globalEndpointManager.preferredLocationsCount;\n const readRequest = isReadRequest(this.operationType);\n let endpointIndex = 0;\n // If preferredLocationsCount is not zero, it indicates that the user has specified preferred locations.\n if (preferredLocationsCount !== 0) {\n // The endpointIndex is set based on the preferred location and the failover retry count.\n endpointIndex = failoverRetryCount % preferredLocationsCount;\n } else {\n // In the absence of preferred locations, the endpoint selection is based on the failover count and the number of available locations.\n if (readRequest) {\n const getReadEndpoints = await this.globalEndpointManager.getReadEndpoints();\n if (getReadEndpoints && getReadEndpoints.length > 0) {\n endpointIndex = failoverRetryCount % getReadEndpoints.length;\n }\n } else {\n const getWriteEndpoints = await this.globalEndpointManager.getWriteEndpoints();\n if (getWriteEndpoints && getWriteEndpoints.length > 0) {\n endpointIndex = failoverRetryCount % getWriteEndpoints.length;\n }\n }\n }\n return endpointIndex;\n }\n}\n"]}
1
+ {"version":3,"file":"timeoutFailoverRetryPolicy.js","sourceRoot":"","sources":["../../../src/retry/timeoutFailoverRetryPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAK9D;;;;;;GAMG;AACH,MAAM,OAAO,0BAA0B;IAQrC,YACU,qBAA4C,EAC5C,OAAsB,EACtB,UAAsB,EACtB,YAA0B,EAC1B,aAA4B,EAC5B,uBAAgC,EAChC,4BAAqC,EACrC,8BAA+D;QAP/D,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,YAAO,GAAP,OAAO,CAAe;QACtB,eAAU,GAAV,UAAU,CAAY;QACtB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,kBAAa,GAAb,aAAa,CAAe;QAC5B,4BAAuB,GAAvB,uBAAuB,CAAS;QAChC,iCAA4B,GAA5B,4BAA4B,CAAS;QACrC,mCAA8B,GAA9B,8BAA8B,CAAiC;QAfjE,yBAAoB,GAAG,GAAG,CAAC;QAC3B,oCAA+B,GAAG,CAAC,CAAC;QACrC,mBAAc,GAAG,CAAC,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AC7E,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACpD,aAAa,GAAG,kBAAkB,GAAG,gBAAgB,CAAC,MAAM,CAAC;gBAC/D,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,EAAE,CAAC;gBAC/E,IAAI,iBAAiB,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtD,aAAa,GAAG,kBAAkB,GAAG,iBAAiB,CAAC,MAAM,CAAC;gBAChE,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\nimport { StatusCodes } from \"../common/statusCodes.js\";\nimport type { GlobalEndpointManager } from \"../globalEndpointManager.js\";\nimport { HTTPMethod, isReadRequest } from \"../common/index.js\";\nimport type { OperationType, ResourceType } from \"../common/constants.js\";\nimport { Constants } from \"../common/constants.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { CosmosHeaders } from \"../queryExecutionContext/CosmosHeaders.js\";\nimport { TimeoutErrorCode } from \"../request/TimeoutError.js\";\nimport type { ErrorResponse, RequestContext } from \"../request/index.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { GlobalPartitionEndpointManager } from \"../globalPartitionEndpointManager.js\";\n\n/**\n * This class TimeoutFailoverRetryPolicy handles retries for read operations\n * (including data plane,metadata, and query plan) in case of request timeouts\n * (TimeoutError) or service unavailability (503 status code) by performing failover\n * and retrying on other regions.\n * @hidden\n */\nexport class TimeoutFailoverRetryPolicy implements RetryPolicy {\n private maxRetryAttemptCount = 120;\n private maxServiceUnavailableRetryCount = 1;\n public retryAfterInMs = 0;\n public failoverRetryCount = 0;\n public request: any;\n public locationEndpoint: any;\n\n constructor(\n private globalEndpointManager: GlobalEndpointManager,\n private headers: CosmosHeaders,\n private methodType: HTTPMethod,\n private resourceType: ResourceType,\n private operationType: OperationType,\n private enableEndPointDiscovery: boolean,\n private enablePartitionLevelFailover: boolean,\n private globalPartitionEndpointManager?: GlobalPartitionEndpointManager,\n ) {}\n\n /**\n * Checks if a timeout request is valid for the timeout failover retry policy.\n * A valid request should be a data plane, metadata, or query plan request.\n * @returns\n */\n private isValidRequestForTimeoutError(): boolean {\n const isQuery = Constants.HttpHeaders.IsQuery in this.headers;\n const isQueryPlan = Constants.HttpHeaders.IsQueryPlan in this.headers;\n if (this.methodType === HTTPMethod.get || isQuery || isQueryPlan) {\n return true;\n }\n return false;\n }\n\n public async shouldRetry(\n err: ErrorResponse,\n diagnosticNode: DiagnosticNodeInternal,\n retryContext?: RetryContext,\n locationEndpoint?: string,\n requestContext?: RequestContext,\n ): Promise<boolean> {\n if (!err) {\n return false;\n }\n if (!retryContext || !locationEndpoint) {\n return false;\n }\n\n // Mark the partition as unavailable.\n // Let the Retry logic decide if the request should be retried\n if (requestContext && this.globalPartitionEndpointManager) {\n await this.globalPartitionEndpointManager.tryPartitionLevelFailover(\n requestContext,\n diagnosticNode,\n );\n }\n\n // Check if the error is a timeout error (TimeoutErrorCode) and if it is not a valid HTTP network timeout request\n if (err.code === TimeoutErrorCode && !this.isValidRequestForTimeoutError()) {\n return false;\n }\n if (!this.enableEndPointDiscovery) {\n return false;\n }\n if (\n err.code === StatusCodes.ServiceUnavailable &&\n this.failoverRetryCount >= this.maxServiceUnavailableRetryCount\n ) {\n return false;\n }\n if (this.failoverRetryCount >= this.maxRetryAttemptCount) {\n return false;\n }\n const canUseMultipleWriteLocations = this.globalEndpointManager.canUseMultipleWriteLocations(\n this.resourceType,\n this.operationType,\n );\n const readRequest = isReadRequest(this.operationType);\n\n if (!canUseMultipleWriteLocations && !readRequest && !this.enablePartitionLevelFailover) {\n // Write requests on single master cannot be retried if partition level failover is disabled.\n // This means there are no other regions available to serve the writes.\n return false;\n }\n this.failoverRetryCount++;\n // Setting the retryLocationIndex to the next available location for retry.\n // The retryLocationIndex is determined based on the failoverRetryCount, starting from zero.\n retryContext.retryLocationServerIndex = await this.findEndpointIndex(this.failoverRetryCount);\n diagnosticNode.addData({ successfulRetryPolicy: \"timeout-failover\" });\n return true;\n }\n\n /**\n * Determines index of endpoint to be used for retry based upon failoverRetryCount and avalable locations\n * @param failoverRetryCount - count of failovers\n * @returns\n */\n private async findEndpointIndex(failoverRetryCount: number): Promise<number> {\n // count of preferred locations specified by user\n const preferredLocationsCount = this.globalEndpointManager.preferredLocationsCount;\n const readRequest = isReadRequest(this.operationType);\n let endpointIndex = 0;\n // If preferredLocationsCount is not zero, it indicates that the user has specified preferred locations.\n if (preferredLocationsCount !== 0) {\n // The endpointIndex is set based on the preferred location and the failover retry count.\n endpointIndex = failoverRetryCount % preferredLocationsCount;\n } else {\n // In the absence of preferred locations, the endpoint selection is based on the failover count and the number of available locations.\n if (readRequest) {\n const getReadEndpoints = await this.globalEndpointManager.getReadEndpoints();\n if (getReadEndpoints && getReadEndpoints.length > 0) {\n endpointIndex = failoverRetryCount % getReadEndpoints.length;\n }\n } else {\n const getWriteEndpoints = await this.globalEndpointManager.getWriteEndpoints();\n if (getWriteEndpoints && getWriteEndpoints.length > 0) {\n endpointIndex = failoverRetryCount % getWriteEndpoints.length;\n }\n }\n }\n return endpointIndex;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"partitionKeyRangeCache.d.ts","sourceRoot":"","sources":["../../../src/routing/partitionKeyRangeCache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAGvF,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM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,EAAE,UAAU,EACtB,cAAc,EAAE,sBAAsB,EACtC,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAKjB,2BAA2B;CAqC1C"}
@@ -4,6 +4,7 @@ import { MetadataLookUpType } from "../CosmosDiagnostics.js";
4
4
  import { getIdFromLink } from "../common/helper.js";
5
5
  import { withMetadataDiagnostics } from "../utils/diagnostics.js";
6
6
  import { createCompleteRoutingMap } from "./CollectionRoutingMapFactory.js";
7
+ import { hashPartitionKey, binarySearchOnPartitionKeyRanges } from "../utils/hashing/hash.js";
7
8
  /** @hidden */
8
9
  export class PartitionKeyRangeCache {
9
10
  constructor(clientContext) {
@@ -38,5 +39,15 @@ export class PartitionKeyRangeCache {
38
39
  }, diagnosticNode, MetadataLookUpType.PartitionKeyRangeLookUp);
39
40
  return createCompleteRoutingMap(resources.map((r) => [r, true]));
40
41
  }
42
+ /**
43
+ * Given a partition key, returns the partition key range id
44
+ * @internal
45
+ */
46
+ async getPartitionKeyRangeIdFromPartitionKey(collectionLink, partitionKey, partitionKeyDefinition, diagnosticNode) {
47
+ const hashedPartitionKey = hashPartitionKey(partitionKey, partitionKeyDefinition);
48
+ const partitionKeyRanges = (await this.onCollectionRoutingMap(collectionLink, diagnosticNode)).getOrderedParitionKeyRanges();
49
+ const partitionKeyRangeId = binarySearchOnPartitionKeyRanges(partitionKeyRanges, hashedPartitionKey);
50
+ return partitionKeyRangeId;
51
+ }
41
52
  }
42
53
  //# sourceMappingURL=partitionKeyRangeCache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"partitionKeyRangeCache.js","sourceRoot":"","sources":["../../../src/routing/partitionKeyRangeCache.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAy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C,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { MetadataLookUpType } from \"../CosmosDiagnostics.js\";\nimport type { PartitionKeyRange } from \"../client/Container/PartitionKeyRange.js\";\nimport type { ClientContext } from \"../ClientContext.js\";\nimport { getIdFromLink } from \"../common/helper.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { withMetadataDiagnostics } from \"../utils/diagnostics.js\";\nimport { createCompleteRoutingMap } from \"./CollectionRoutingMapFactory.js\";\nimport type { InMemoryCollectionRoutingMap } from \"./inMemoryCollectionRoutingMap.js\";\nimport type { QueryRange } from \"./QueryRange.js\";\n\n/** @hidden */\nexport class PartitionKeyRangeCache {\n private collectionRoutingMapByCollectionId: {\n [key: string]: Promise<InMemoryCollectionRoutingMap>;\n };\n\n constructor(private clientContext: ClientContext) {\n this.collectionRoutingMapByCollectionId = {};\n }\n /**\n * Finds or Instantiates the requested Collection Routing Map\n * @param collectionLink - Requested collectionLink\n * @hidden\n */\n public async onCollectionRoutingMap(\n collectionLink: string,\n diagnosticNode: DiagnosticNodeInternal,\n forceRefresh: boolean = false,\n ): Promise<InMemoryCollectionRoutingMap> {\n const collectionId = getIdFromLink(collectionLink);\n if (this.collectionRoutingMapByCollectionId[collectionId] === undefined || forceRefresh) {\n this.collectionRoutingMapByCollectionId[collectionId] = this.requestCollectionRoutingMap(\n collectionLink,\n diagnosticNode,\n );\n }\n return this.collectionRoutingMapByCollectionId[collectionId];\n }\n\n /**\n * Given the query ranges and a collection, invokes the callback on the list of overlapping partition key ranges\n * @hidden\n */\n public async getOverlappingRanges(\n collectionLink: string,\n queryRange: QueryRange,\n diagnosticNode: DiagnosticNodeInternal,\n forceRefresh: boolean = false,\n ): Promise<PartitionKeyRange[]> {\n const crm = await this.onCollectionRoutingMap(collectionLink, diagnosticNode, forceRefresh);\n return crm.getOverlappingRanges(queryRange);\n }\n\n private async requestCollectionRoutingMap(\n collectionLink: string,\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<InMemoryCollectionRoutingMap> {\n const { resources } = await withMetadataDiagnostics(\n async (metadataDiagnostics: DiagnosticNodeInternal) => {\n return this.clientContext\n .queryPartitionKeyRanges(collectionLink)\n .fetchAllInternal(metadataDiagnostics);\n },\n diagnosticNode,\n MetadataLookUpType.PartitionKeyRangeLookUp,\n );\n return createCompleteRoutingMap(resources.map((r) => [r, true]));\n }\n}\n"]}
1
+ {"version":3,"file":"partitionKeyRangeCache.js","sourceRoot":"","sources":["../../../src/routing/partitionKeyRangeCache.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAK5E,OAAO,EAAE,gBAAgB,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAC;AAE9F,cAAc;AACd,MAAM,OAAO,sBAAsB;IAKjC,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAC9C,IAAI,CAAC,kCAAkC,GAAG,EAAE,CAAC;IAC/C,CAAC;IACD;;;;OAIG;IACI,KAAK,CAAC,sBAAsB,CACjC,cAAsB,EACtB,cAAsC,EACtC,eAAwB,KAAK;QAE7B,MAAM,YAAY,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;QACnD,IAAI,IAAI,CAAC,kCAAkC,CAAC,YAAY,CAAC,KAAK,SAAS,IAAI,YAAY,EAAE,CAAC;YACxF,IAAI,CAAC,kCAAkC,CAAC,YAAY,CAAC,GAAG,IAAI,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BAAmB,CAAC;IAC7B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { MetadataLookUpType } from \"../CosmosDiagnostics.js\";\nimport type { PartitionKeyRange } from \"../client/Container/PartitionKeyRange.js\";\nimport type { ClientContext } from \"../ClientContext.js\";\nimport { getIdFromLink } from \"../common/helper.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { withMetadataDiagnostics } from \"../utils/diagnostics.js\";\nimport { createCompleteRoutingMap } from \"./CollectionRoutingMapFactory.js\";\nimport type { InMemoryCollectionRoutingMap } from \"./inMemoryCollectionRoutingMap.js\";\nimport type { QueryRange } from \"./QueryRange.js\";\nimport type { PartitionKeyDefinition } from \"../documents/PartitionKeyDefinition.js\";\nimport type { PartitionKeyInternal } from \"../documents/PartitionKeyInternal.js\";\nimport { hashPartitionKey, binarySearchOnPartitionKeyRanges } from \"../utils/hashing/hash.js\";\n\n/** @hidden */\nexport class PartitionKeyRangeCache {\n private collectionRoutingMapByCollectionId: {\n [key: string]: Promise<InMemoryCollectionRoutingMap>;\n };\n\n constructor(private clientContext: ClientContext) {\n this.collectionRoutingMapByCollectionId = {};\n }\n /**\n * Finds or Instantiates the requested Collection Routing Map\n * @param collectionLink - Requested collectionLink\n * @hidden\n */\n public async onCollectionRoutingMap(\n collectionLink: string,\n diagnosticNode: DiagnosticNodeInternal,\n forceRefresh: boolean = false,\n ): Promise<InMemoryCollectionRoutingMap> {\n const collectionId = getIdFromLink(collectionLink);\n if (this.collectionRoutingMapByCollectionId[collectionId] === undefined || forceRefresh) {\n this.collectionRoutingMapByCollectionId[collectionId] = this.requestCollectionRoutingMap(\n collectionLink,\n diagnosticNode,\n );\n }\n return this.collectionRoutingMapByCollectionId[collectionId];\n }\n\n /**\n * Given the query ranges and a collection, invokes the callback on the list of overlapping partition key ranges\n * @hidden\n */\n public async getOverlappingRanges(\n collectionLink: string,\n queryRange: QueryRange,\n diagnosticNode: DiagnosticNodeInternal,\n forceRefresh: boolean = false,\n ): Promise<PartitionKeyRange[]> {\n const crm = await this.onCollectionRoutingMap(collectionLink, diagnosticNode, forceRefresh);\n return crm.getOverlappingRanges(queryRange);\n }\n\n private async requestCollectionRoutingMap(\n collectionLink: string,\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<InMemoryCollectionRoutingMap> {\n const { resources } = await withMetadataDiagnostics(\n async (metadataDiagnostics: DiagnosticNodeInternal) => {\n return this.clientContext\n .queryPartitionKeyRanges(collectionLink)\n .fetchAllInternal(metadataDiagnostics);\n },\n diagnosticNode,\n MetadataLookUpType.PartitionKeyRangeLookUp,\n );\n return createCompleteRoutingMap(resources.map((r) => [r, true]));\n }\n\n /**\n * Given a partition key, returns the partition key range id\n * @internal\n */\n public async getPartitionKeyRangeIdFromPartitionKey(\n collectionLink: string,\n partitionKey: PartitionKeyInternal,\n partitionKeyDefinition: PartitionKeyDefinition,\n diagnosticNode: DiagnosticNodeInternal,\n ): Promise<string | undefined> {\n const hashedPartitionKey = hashPartitionKey(partitionKey, partitionKeyDefinition);\n const partitionKeyRanges = (\n await this.onCollectionRoutingMap(collectionLink, diagnosticNode)\n ).getOrderedParitionKeyRanges();\n\n const partitionKeyRangeId = binarySearchOnPartitionKeyRanges(\n partitionKeyRanges,\n hashedPartitionKey,\n );\n return partitionKeyRangeId;\n }\n}\n"]}
@@ -6,4 +6,10 @@ export function checkURL(testString) {
6
6
  export function sanitizeEndpoint(url) {
7
7
  return new URL(url).href.replace(/\/$/, "");
8
8
  }
9
+ /**
10
+ * @internal
11
+ */
12
+ export function normalizeEndpoint(endpoint) {
13
+ return endpoint.replace(/\s+/g, "").toLowerCase();
14
+ }
9
15
  //# sourceMappingURL=checkURL.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkURL.js","sourceRoot":"","sources":["../../../src/utils/checkURL.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,UAAU,QAAQ,CAAC,UAAkB;IACzC,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport function checkURL(testString: string): URL {\n return new URL(testString);\n}\n\nexport function sanitizeEndpoint(url: string): string {\n return new URL(url).href.replace(/\\/$/, \"\");\n}\n"]}
1
+ {"version":3,"file":"checkURL.js","sourceRoot":"","sources":["../../../src/utils/checkURL.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,UAAU,QAAQ,CAAC,UAAkB;IACzC,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AACpD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport function checkURL(testString: string): URL {\n return new URL(testString);\n}\n\nexport function sanitizeEndpoint(url: string): string {\n return new URL(url).href.replace(/\\/$/, \"\");\n}\n\n/**\n * @internal\n */\nexport function normalizeEndpoint(endpoint: string): string {\n return endpoint.replace(/\\s+/g, \"\").toLowerCase();\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { PartitionKeyRange } from "../../client/index.js";
1
2
  import type { PartitionKeyDefinition, PrimitivePartitionKeyValue } from "../../documents/index.js";
2
3
  /**
3
4
  * Generate hash of a PartitonKey based on it PartitionKeyDefinition.
@@ -6,4 +7,5 @@ import type { PartitionKeyDefinition, PrimitivePartitionKeyValue } from "../../d
6
7
  * @returns
7
8
  */
8
9
  export declare function hashPartitionKey(partitionKey: PrimitivePartitionKeyValue[], partitionDefinition: PartitionKeyDefinition): string;
10
+ export declare function binarySearchOnPartitionKeyRanges(partitionKeyRanges: PartitionKeyRange[], hashedPartitionKey: string): string | undefined;
9
11
  //# sourceMappingURL=hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../../src/utils/hashing/hash.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAMnG;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,0BAA0B,EAAE,EAC1C,mBAAmB,EAAE,sBAAsB,GAC1C,MAAM,CAYR"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../../src/utils/hashing/hash.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAOnG;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,0BAA0B,EAAE,EAC1C,mBAAmB,EAAE,sBAAsB,GAC1C,MAAM,CAYR;AAED,wBAAgB,gCAAgC,CAC9C,kBAAkB,EAAE,iBAAiB,EAAE,EACvC,kBAAkB,EAAE,MAAM,GACzB,MAAM,GAAG,SAAS,CAiBpB"}
@@ -1,6 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  import { PartitionKeyDefinitionVersion, PartitionKeyKind } from "../../documents/index.js";
4
+ import { isKeyInRange } from "../batch.js";
4
5
  import { hashMultiHashPartitionKey } from "./multiHash.js";
5
6
  import { hashV1PartitionKey } from "./v1.js";
6
7
  import { hashV2PartitionKey } from "./v2.js";
@@ -22,4 +23,22 @@ export function hashPartitionKey(partitionKey, partitionDefinition) {
22
23
  return hashMultiHashPartitionKey(partitionKey);
23
24
  }
24
25
  }
26
+ export function binarySearchOnPartitionKeyRanges(partitionKeyRanges, hashedPartitionKey) {
27
+ let low = 0;
28
+ let high = partitionKeyRanges.length - 1;
29
+ while (low <= high) {
30
+ const mid = Math.floor((low + high) / 2);
31
+ const range = partitionKeyRanges[mid];
32
+ if (isKeyInRange(range.minInclusive, range.maxExclusive, hashedPartitionKey)) {
33
+ return range.id;
34
+ }
35
+ else if (hashedPartitionKey.localeCompare(range.minInclusive) < 0) {
36
+ high = mid - 1;
37
+ }
38
+ else {
39
+ low = mid + 1;
40
+ }
41
+ }
42
+ return undefined;
43
+ }
25
44
  //# sourceMappingURL=hash.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../../src/utils/hashing/hash.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,YAA0C,EAC1C,mBAA2C;IAE3C,MAAM,IAAI,GAAqB,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,IAAI,KAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,iBAAiB;IACpG,MAAM,IAAI,GACR,mBAAmB;QACnB,mBAAmB,CAAC,OAAO;QAC3B,mBAAmB,CAAC,OAAO,KAAK,6BAA6B,CAAC,EAAE,CAAC;IACnE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,gBAAgB,CAAC,IAAI;YACxB,OAAO,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;QACpF,KAAK,gBAAgB,CAAC,SAAS;YAC7B,OAAO,yBAAyB,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PartitionKeyDefinition, PrimitivePartitionKeyValue } from \"../../documents/index.js\";\nimport { PartitionKeyDefinitionVersion, PartitionKeyKind } from \"../../documents/index.js\";\nimport { hashMultiHashPartitionKey } from \"./multiHash.js\";\nimport { hashV1PartitionKey } from \"./v1.js\";\nimport { hashV2PartitionKey } from \"./v2.js\";\n\n/**\n * Generate hash of a PartitonKey based on it PartitionKeyDefinition.\n * @param partitionKey - to be hashed.\n * @param partitionDefinition - container's partitionKey definition\n * @returns\n */\nexport function hashPartitionKey(\n partitionKey: PrimitivePartitionKeyValue[],\n partitionDefinition: PartitionKeyDefinition,\n): string {\n const kind: PartitionKeyKind = partitionDefinition?.kind || PartitionKeyKind.Hash; // Default value.\n const isV2 =\n partitionDefinition &&\n partitionDefinition.version &&\n partitionDefinition.version === PartitionKeyDefinitionVersion.V2;\n switch (kind) {\n case PartitionKeyKind.Hash:\n return isV2 ? hashV2PartitionKey(partitionKey) : hashV1PartitionKey(partitionKey);\n case PartitionKeyKind.MultiHash:\n return hashMultiHashPartitionKey(partitionKey);\n }\n}\n"]}
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../../src/utils/hashing/hash.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,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O,KAAK,CAAC,EAAE,CAAC;QAClB,CAAC;aAAM,IAAI,kBAAkB,CAAC,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;YACpE,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC;QACjB,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { PartitionKeyRange } from \"../../client/index.js\";\nimport type { PartitionKeyDefinition, PrimitivePartitionKeyValue } from \"../../documents/index.js\";\nimport { PartitionKeyDefinitionVersion, PartitionKeyKind } from \"../../documents/index.js\";\nimport { isKeyInRange } from \"../batch.js\";\nimport { hashMultiHashPartitionKey } from \"./multiHash.js\";\nimport { hashV1PartitionKey } from \"./v1.js\";\nimport { hashV2PartitionKey } from \"./v2.js\";\n\n/**\n * Generate hash of a PartitonKey based on it PartitionKeyDefinition.\n * @param partitionKey - to be hashed.\n * @param partitionDefinition - container's partitionKey definition\n * @returns\n */\nexport function hashPartitionKey(\n partitionKey: PrimitivePartitionKeyValue[],\n partitionDefinition: PartitionKeyDefinition,\n): string {\n const kind: PartitionKeyKind = partitionDefinition?.kind || PartitionKeyKind.Hash; // Default value.\n const isV2 =\n partitionDefinition &&\n partitionDefinition.version &&\n partitionDefinition.version === PartitionKeyDefinitionVersion.V2;\n switch (kind) {\n case PartitionKeyKind.Hash:\n return isV2 ? hashV2PartitionKey(partitionKey) : hashV1PartitionKey(partitionKey);\n case PartitionKeyKind.MultiHash:\n return hashMultiHashPartitionKey(partitionKey);\n }\n}\n\nexport function binarySearchOnPartitionKeyRanges(\n partitionKeyRanges: PartitionKeyRange[],\n hashedPartitionKey: string,\n): string | undefined {\n let low = 0;\n let high = partitionKeyRanges.length - 1;\n\n while (low <= high) {\n const mid = Math.floor((low + high) / 2);\n const range = partitionKeyRanges[mid];\n\n if (isKeyInRange(range.minInclusive, range.maxExclusive, hashedPartitionKey)) {\n return range.id;\n } else if (hashedPartitionKey.localeCompare(range.minInclusive) < 0) {\n high = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n return undefined;\n}\n"]}