@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
@@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B,CAC7B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAM7C;;OAEG;IACU,0BAA0B,CACrC,cAAc,EAAE,sBAAsB,EACtC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAW7C;;;;OAIG;IACU,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMhD;;;;OAIG;IACU,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAM/C;;;;OAIG;IACI,iBAAiB,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAItD;;;;OAIG;IACI,gBAAgB,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAIrD;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACI,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ;IAIrC;;;OAGG;IACI,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK;IAI/B;;OAEG;IACI,OAAO,IAAI,IAAI;YAWR,6BAA6B;CA8B5C"}
@@ -17,6 +17,7 @@ const globalEndpointManager_js_1 = require("./globalEndpointManager.js");
17
17
  const index_js_6 = require("./request/index.js");
18
18
  const checkURL_js_1 = require("./utils/checkURL.js");
19
19
  const diagnostics_js_1 = require("./utils/diagnostics.js");
20
+ const globalPartitionEndpointManager_js_1 = require("./globalPartitionEndpointManager.js");
20
21
  /**
21
22
  * Provides a client-side logical representation of the Azure Cosmos DB database account.
22
23
  * This client is used to configure and execute requests in the Azure Cosmos DB database service.
@@ -82,11 +83,15 @@ class CosmosClient {
82
83
  optionsOrConnectionString.defaultHeaders[constants_js_1.Constants.HttpHeaders.ThroughputBucket] =
83
84
  optionsOrConnectionString.throughputBucket;
84
85
  }
85
- const userAgent = (0, platform_js_1.getUserAgent)(optionsOrConnectionString.userAgentSuffix);
86
+ const userAgent = (0, platform_js_1.getUserAgent)(optionsOrConnectionString);
86
87
  optionsOrConnectionString.defaultHeaders[constants_js_1.Constants.HttpHeaders.UserAgent] = userAgent;
87
88
  optionsOrConnectionString.defaultHeaders[constants_js_1.Constants.HttpHeaders.CustomUserAgent] = userAgent;
88
89
  const globalEndpointManager = new globalEndpointManager_js_1.GlobalEndpointManager(optionsOrConnectionString, async (diagnosticNode, opts) => this.getDatabaseAccountInternal(diagnosticNode, opts));
89
- this.clientContext = new ClientContext_js_1.ClientContext(optionsOrConnectionString, globalEndpointManager, clientConfig, (0, index_js_4.determineDiagnosticLevel)(optionsOrConnectionString.diagnosticLevel, (0, index_js_4.getDiagnosticLevelFromEnvironment)()));
90
+ if (optionsOrConnectionString.connectionPolicy.enablePartitionLevelFailover ||
91
+ optionsOrConnectionString.connectionPolicy.enablePartitionLevelCircuitBreaker) {
92
+ this.globalPartitionEndpointManager = new globalPartitionEndpointManager_js_1.GlobalPartitionEndpointManager(optionsOrConnectionString, globalEndpointManager);
93
+ }
94
+ this.clientContext = new ClientContext_js_1.ClientContext(optionsOrConnectionString, globalEndpointManager, clientConfig, (0, index_js_4.determineDiagnosticLevel)(optionsOrConnectionString.diagnosticLevel, (0, index_js_4.getDiagnosticLevelFromEnvironment)()), this.globalPartitionEndpointManager);
90
95
  if (((_a = optionsOrConnectionString.connectionPolicy) === null || _a === void 0 ? void 0 : _a.enableEndpointDiscovery) &&
91
96
  ((_b = optionsOrConnectionString.connectionPolicy) === null || _b === void 0 ? void 0 : _b.enableBackgroundEndpointRefreshing)) {
92
97
  this.backgroundRefreshEndpointList(globalEndpointManager, optionsOrConnectionString.connectionPolicy.endpointRefreshRateInMs ||
@@ -209,6 +214,9 @@ class CosmosClient {
209
214
  clearTimeout(this.encryptionManager.encryptionKeyStoreProvider.cacheRefresher);
210
215
  clearTimeout(this.encryptionManager.protectedDataEncryptionKeyCache.cacheRefresher);
211
216
  }
217
+ if (this.globalPartitionEndpointManager) {
218
+ this.globalPartitionEndpointManager.dispose();
219
+ }
212
220
  }
213
221
  async backgroundRefreshEndpointList(globalEndpointManager, refreshRate) {
214
222
  this.endpointRefresher = setInterval(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"CosmosClient.js","sourceRoot":"","sources":["../../src/CosmosClient.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,yDAAiE;AACjE,sDAAwD;AACxD,yDAAmD;AACnD,gDAA0D;AAC1D,wDAAkD;AAClD,sDAAoD;AAGpD,qDAGgC;AAEhC,uFAA6E;AAE7E,mDAA+D;AAC/D,4EAAsE;AACtE,yEAAmE;AAEnE,iDAAsD;AACtD,qDAA+C;AAC/C,2DAAoF;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,YAAY;IAwCvB,YAAY,yBAAuD;;QACjE,IAAI,OAAO,yBAAyB,KAAK,QAAQ,EAAE,CAAC;YAClD,yBAAyB,GAAG,IAAA,gCAAqB,EAAC,yBAAyB,CAAC,CAAC;QAC/E,CAAC;aAAM,IAAI,yBAAyB,CAAC,gBAAgB,EAAE,CAAC;YACtD,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAA,gCAAqB,EAAC,yBAAyB,CAAC,gBAAgB,CAAC,CAAC;YAC5F,yBAAyB,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAC9C,yBAAyB,CAAC,GAAG,GAAG,GAAG,CAAC;QACtC,CAAC;QAED,MAAM,QAAQ,GAAG,IAAA,sBAAQ,EAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,yBAAyB,CAAC,uBAAuB,EAAE,CAAC;YACtD,IAAI,CAAC,yBAAyB,CAAC,uBAAuB,CAAC,wBAAwB,EAAE,CAAC;gBAChF,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;YACJ,CAAC;YACD,IACE,yBA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BAC/C,OAAO,qBAAqB,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;gBACnE,CAAC,EACD,IAAI,CAAC,aAAa,EAClB,8CAAkB,CAAC,yBAAyB,CAC7C,CAAC;YACJ,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,CAAC,CAAC,CAAC;YACjD,CAAC;QACH,CAAC,EAAE,WAAW,CAAC,CAAC;QAChB,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YACvF,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;QACjC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,mBAAmB,CAAC,aAAqB;QACpD,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;CACF;AAzSD,oCAySC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { Database, Databases } from \"./client/Database/index.js\";\nimport { Offer, Offers } from \"./client/Offer/index.js\";\nimport { ClientContext } from \"./ClientContext.js\";\nimport { parseConnectionString } from \"./common/index.js\";\nimport { Constants } from \"./common/constants.js\";\nimport { getUserAgent } from \"./common/platform.js\";\nimport type { CosmosClientOptions } from \"./CosmosClientOptions.js\";\nimport type { ClientConfigDiagnostic } from \"./CosmosDiagnostics.js\";\nimport {\n determineDiagnosticLevel,\n getDiagnosticLevelFromEnvironment,\n} from \"./diagnostics/index.js\";\nimport type { DiagnosticNodeInternal } from \"./diagnostics/DiagnosticNodeInternal.js\";\nimport { DiagnosticNodeType } from \"./diagnostics/DiagnosticNodeInternal.js\";\nimport type { DatabaseAccount } from \"./documents/index.js\";\nimport { defaultConnectionPolicy } from \"./documents/index.js\";\nimport { EncryptionManager } from \"./encryption/EncryptionManager.js\";\nimport { GlobalEndpointManager } from \"./globalEndpointManager.js\";\nimport type { RequestOptions } from \"./request/index.js\";\nimport { ResourceResponse } from \"./request/index.js\";\nimport { checkURL } from \"./utils/checkURL.js\";\nimport { getEmptyCosmosDiagnostics, withDiagnostics } from \"./utils/diagnostics.js\";\n\n/**\n * Provides a client-side logical representation of the Azure Cosmos DB database account.\n * This client is used to configure and execute requests in the Azure Cosmos DB database service.\n * @example Instantiate a client and create a new database\n * ```ts snippet:CosmosClientCreate\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({ endpoint, key });\n * ```\n * @example Instantiate a client with custom Connection Policy\n * ```ts snippet:CosmosClientWithConnectionPolicy\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({\n * endpoint,\n * key,\n * connectionPolicy: {\n * requestTimeout: 10000,\n * },\n * });\n * ```\n */\nexport class CosmosClient {\n /**\n * Used for creating new databases, or querying/reading all databases.\n *\n * Use `.database(id)` to read, replace, or delete a specific, existing database by id.\n *\n * @example Create a new database\n * ```ts snippet:CosmosClientDatabases\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({ endpoint, key });\n * const { resource: databaseDefinition, database } = await client.databases.create({\n * id: \"<name here>\",\n * });\n * ```\n */\n public readonly databases: Databases;\n /**\n * Used for querying & reading all offers.\n *\n * Use `.offer(id)` to read, or replace existing offers.\n */\n public readonly offers: Offers;\n private clientContext: ClientContext;\n private endpointRefresher: NodeJS.Timeout;\n /**\n * @internal\n */\n private encryptionManager: EncryptionManager;\n /**\n * Creates a new {@link CosmosClient} object from a connection string. Your database connection string can be found in the Azure Portal\n */\n constructor(connectionString: string);\n /**\n * Creates a new {@link CosmosClient} object. See {@link CosmosClientOptions} for more details on what options you can use.\n * @param options - bag of options; require at least endpoint and auth to be configured\n */\n constructor(options: CosmosClientOptions);\n constructor(optionsOrConnectionString: string | CosmosClientOptions) {\n if (typeof optionsOrConnectionString === \"string\") {\n optionsOrConnectionString = parseConnectionString(optionsOrConnectionString);\n } else if (optionsOrConnectionString.connectionString) {\n const { endpoint, key } = parseConnectionString(optionsOrConnectionString.connectionString);\n optionsOrConnectionString.endpoint = endpoint;\n optionsOrConnectionString.key = key;\n }\n\n const endpoint = checkURL(optionsOrConnectionString.endpoint);\n if (!endpoint) {\n throw new Error(\"Invalid endpoint specified\");\n }\n\n if (optionsOrConnectionString.clientEncryptionOptions) {\n if (!optionsOrConnectionString.clientEncryptionOptions.keyEncryptionKeyResolver) {\n throw new Error(\n \"KeyEncryptionKeyResolver needs to be provided to enable client-side encryption.\",\n );\n }\n if (\n optionsOrConnectionString.clientEncryptionOptions.encryptionKeyTimeToLiveInSeconds &&\n optionsOrConnectionString.clientEncryptionOptions.encryptionKeyTimeToLiveInSeconds < 60\n ) {\n throw new Error(\"EncryptionKeyTimeToLiveInSeconds needs to be >= 60 seconds.\");\n }\n this.encryptionManager = new EncryptionManager(\n optionsOrConnectionString.clientEncryptionOptions.keyEncryptionKeyResolver,\n optionsOrConnectionString.clientEncryptionOptions.encryptionKeyTimeToLiveInSeconds,\n );\n }\n\n const clientConfig: ClientConfigDiagnostic =\n this.initializeClientConfigDiagnostic(optionsOrConnectionString);\n\n optionsOrConnectionString.connectionPolicy = Object.assign(\n {},\n defaultConnectionPolicy,\n optionsOrConnectionString.connectionPolicy,\n );\n\n optionsOrConnectionString.defaultHeaders = optionsOrConnectionString.defaultHeaders || {};\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.CacheControl] = \"no-cache\";\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.Version] =\n Constants.CurrentVersion;\n if (optionsOrConnectionString.consistencyLevel !== undefined) {\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.ConsistencyLevel] =\n optionsOrConnectionString.consistencyLevel;\n }\n\n if (optionsOrConnectionString.throughputBucket !== undefined) {\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.ThroughputBucket] =\n optionsOrConnectionString.throughputBucket;\n }\n\n const userAgent = getUserAgent(optionsOrConnectionString.userAgentSuffix);\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.UserAgent] = userAgent;\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.CustomUserAgent] = userAgent;\n\n const globalEndpointManager = new GlobalEndpointManager(\n optionsOrConnectionString,\n async (diagnosticNode: DiagnosticNodeInternal, opts: RequestOptions) =>\n this.getDatabaseAccountInternal(diagnosticNode, opts),\n );\n\n this.clientContext = new ClientContext(\n optionsOrConnectionString,\n globalEndpointManager,\n clientConfig,\n determineDiagnosticLevel(\n optionsOrConnectionString.diagnosticLevel,\n getDiagnosticLevelFromEnvironment(),\n ),\n );\n if (\n optionsOrConnectionString.connectionPolicy?.enableEndpointDiscovery &&\n optionsOrConnectionString.connectionPolicy?.enableBackgroundEndpointRefreshing\n ) {\n this.backgroundRefreshEndpointList(\n globalEndpointManager,\n optionsOrConnectionString.connectionPolicy.endpointRefreshRateInMs ||\n defaultConnectionPolicy.endpointRefreshRateInMs,\n );\n }\n\n this.databases = new Databases(this, this.clientContext, this.encryptionManager);\n this.offers = new Offers(this, this.clientContext);\n }\n\n private initializeClientConfigDiagnostic(\n optionsOrConnectionString: CosmosClientOptions,\n ): ClientConfigDiagnostic {\n return {\n endpoint: optionsOrConnectionString.endpoint,\n resourceTokensConfigured: optionsOrConnectionString.resourceTokens !== undefined,\n tokenProviderConfigured: optionsOrConnectionString.tokenProvider !== undefined,\n aadCredentialsConfigured: optionsOrConnectionString.aadCredentials !== undefined,\n connectionPolicyConfigured: optionsOrConnectionString.connectionPolicy !== undefined,\n consistencyLevel: optionsOrConnectionString.consistencyLevel,\n defaultHeaders: optionsOrConnectionString.defaultHeaders,\n agentConfigured: optionsOrConnectionString.agent !== undefined,\n userAgentSuffix: optionsOrConnectionString.userAgentSuffix,\n diagnosticLevel: optionsOrConnectionString.diagnosticLevel,\n pluginsConfigured: optionsOrConnectionString.plugins !== undefined,\n sDKVersion: Constants.SDKVersion,\n };\n }\n\n /**\n * Get information about the current {@link DatabaseAccount} (including which regions are supported, etc.)\n */\n public async getDatabaseAccount(\n options?: RequestOptions,\n ): Promise<ResourceResponse<DatabaseAccount>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n return this.getDatabaseAccountInternal(diagnosticNode, options);\n }, this.clientContext);\n }\n\n /**\n * @hidden\n */\n public async getDatabaseAccountInternal(\n diagnosticNode: DiagnosticNodeInternal,\n options?: RequestOptions,\n ): Promise<ResourceResponse<DatabaseAccount>> {\n const response = await this.clientContext.getDatabaseAccount(diagnosticNode, options);\n return new ResourceResponse<DatabaseAccount>(\n response.result,\n response.headers,\n response.code,\n getEmptyCosmosDiagnostics(),\n response.substatus,\n );\n }\n\n /**\n * Gets the currently used write endpoint url. Useful for troubleshooting purposes.\n *\n * The url may contain a region suffix (e.g. \"-eastus\") if we're using location specific endpoints.\n */\n public async getWriteEndpoint(): Promise<string> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n return this.clientContext.getWriteEndpoint(diagnosticNode);\n }, this.clientContext);\n }\n\n /**\n * Gets the currently used read endpoint. Useful for troubleshooting purposes.\n *\n * The url may contain a region suffix (e.g. \"-eastus\") if we're using location specific endpoints.\n */\n public async getReadEndpoint(): Promise<string> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n return this.clientContext.getReadEndpoint(diagnosticNode);\n }, this.clientContext);\n }\n\n /**\n * Gets the known write endpoints. Useful for troubleshooting purposes.\n *\n * The urls may contain a region suffix (e.g. \"-eastus\") if we're using location specific endpoints.\n */\n public getWriteEndpoints(): Promise<readonly string[]> {\n return this.clientContext.getWriteEndpoints();\n }\n\n /**\n * Gets the currently used read endpoint. Useful for troubleshooting purposes.\n *\n * The url may contain a region suffix (e.g. \"-eastus\") if we're using location specific endpoints.\n */\n public getReadEndpoints(): Promise<readonly string[]> {\n return this.clientContext.getReadEndpoints();\n }\n\n /**\n * Used for reading, updating, or deleting a existing database by id or accessing containers belonging to that database.\n *\n * This does not make a network call. Use `.read` to get info about the database after getting the {@link Database} object.\n *\n * @param id - The id of the database.\n * @example Create a new container off of an existing database\n * ```ts snippet:CosmosClientDatabaseCreateContainer\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({ endpoint, key });\n * const container = client.database(\"<database id>\").containers.create({\n * id: \"<name here>\",\n * });\n * ```\n *\n * @example Delete an existing database\n * ```ts snippet:CosmosClientDatabaseDelete\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({ endpoint, key });\n * await client.database(\"<id here>\").delete();\n * ```\n */\n public database(id: string): Database {\n return new Database(this, id, this.clientContext, this.encryptionManager);\n }\n\n /**\n * Used for reading, or updating a existing offer by id.\n * @param id - The id of the offer.\n */\n public offer(id: string): Offer {\n return new Offer(this, id, this.clientContext);\n }\n\n /**\n * Clears background endpoint refresher. Use client.dispose() when destroying the CosmosClient within another process.\n */\n public dispose(): void {\n clearTimeout(this.endpointRefresher);\n if (this.clientContext.enableEncryption) {\n clearTimeout(this.encryptionManager.encryptionKeyStoreProvider.cacheRefresher);\n clearTimeout(this.encryptionManager.protectedDataEncryptionKeyCache.cacheRefresher);\n }\n }\n\n private async backgroundRefreshEndpointList(\n globalEndpointManager: GlobalEndpointManager,\n refreshRate: number,\n ) {\n this.endpointRefresher = setInterval(() => {\n try {\n return withDiagnostics(\n async (diagnosticNode: DiagnosticNodeInternal) => {\n return globalEndpointManager.refreshEndpointList(diagnosticNode);\n },\n this.clientContext,\n DiagnosticNodeType.BACKGROUND_REFRESH_THREAD,\n );\n } catch (e: any) {\n console.warn(\"Failed to refresh endpoints\", e);\n }\n }, refreshRate);\n if (this.endpointRefresher.unref && typeof this.endpointRefresher.unref === \"function\") {\n this.endpointRefresher.unref();\n }\n }\n\n /**\n * Update the host framework. If provided host framework will be used to generate the defualt SDK user agent.\n * @param hostFramework - A custom string.\n * @internal\n */\n public async updateHostFramework(hostFramework: string): Promise<void> {\n this.clientContext.refreshUserAgent(hostFramework);\n }\n}\n"]}
1
+ {"version":3,"file":"CosmosClient.js","sourceRoot":"","sources":["../../src/CosmosClient.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,yDAAiE;AACjE,sDAAwD;AACxD,yDAAmD;AACnD,gDAA0D;AAC1D,wDAAkD;AAClD,sDAAoD;AAGpD,qDAGgC;AAEhC,uFAA6E;AAE7E,mDAA+D;AAC/D,4EAAsE;AACtE,yEAAmE;AAEnE,iDAAsD;AACtD,qDAA+C;AAC/C,2DAAoF;AACpF,2FAAqF;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,YAAY;IA0CvB,YAAY,yBAAuD;;QACjE,IAAI,OAAO,yBAAyB,KAAK,QAAQ,EAAE,CAAC;YAClD,yBAAyB,GAAG,IAAA,gCAAqB,EAAC,yBAAyB,CAAC,CAAC;QAC/E,CAAC;aAAM,IAAI,yBAAyB,CAAC,gBAAgB,EAAE,CAAC;YACtD,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAA,gCAAqB,EAAC,yBAAyB,CAAC,gBAAgB,CAAC,CAAC;YAC5F,yBAAyB,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAC9C,yBAAyB,CAAC,GAAG,GAAG,GAAG,CAAC;QACtC,CAAC;QAED,MAAM,QAAQ,GAAG,IAAA,sBAAQ,EAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,4BAA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AC;QACrC,IAAI,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;YACxC,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,cAAc,CAAC,CAAC;YAC/E,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,+BAA+B,CAAC,cAAc,CAAC,CAAC;QACtF,CAAC;QACD,IAAI,IAAI,CAAC,8BAA8B,EAAE,CAAC;YACxC,IAAI,CAAC,8BAA8B,CAAC,OAAO,EAAE,CAAC;QAChD,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,6BAA6B,CACzC,qBAA4C,EAC5C,WAAmB;QAEnB,IAAI,CAAC,iBAAiB,GAAG,WAAW,CAAC,GAAG,EAAE;YACxC,IAAI,CAAC;gBACH,OAAO,IAAA,gCAAe,EACpB,KAAK,EAAE,cAAsC,EAAE,EAAE;oBAC/C,OAAO,qBAAqB,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;gBACnE,CAAC,EACD,IAAI,CAAC,aAAa,EAClB,8CAAkB,CAAC,yBAAyB,CAC7C,CAAC;YACJ,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,CAAC,CAAC,CAAC;YACjD,CAAC;QACH,CAAC,EAAE,WAAW,CAAC,CAAC;QAChB,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YACvF,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;QACjC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,mBAAmB,CAAC,aAAqB;QACpD,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;CACF;AAzTD,oCAyTC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { Database, Databases } from \"./client/Database/index.js\";\nimport { Offer, Offers } from \"./client/Offer/index.js\";\nimport { ClientContext } from \"./ClientContext.js\";\nimport { parseConnectionString } from \"./common/index.js\";\nimport { Constants } from \"./common/constants.js\";\nimport { getUserAgent } from \"./common/platform.js\";\nimport type { CosmosClientOptions } from \"./CosmosClientOptions.js\";\nimport type { ClientConfigDiagnostic } from \"./CosmosDiagnostics.js\";\nimport {\n determineDiagnosticLevel,\n getDiagnosticLevelFromEnvironment,\n} from \"./diagnostics/index.js\";\nimport type { DiagnosticNodeInternal } from \"./diagnostics/DiagnosticNodeInternal.js\";\nimport { DiagnosticNodeType } from \"./diagnostics/DiagnosticNodeInternal.js\";\nimport type { DatabaseAccount } from \"./documents/index.js\";\nimport { defaultConnectionPolicy } from \"./documents/index.js\";\nimport { EncryptionManager } from \"./encryption/EncryptionManager.js\";\nimport { GlobalEndpointManager } from \"./globalEndpointManager.js\";\nimport type { RequestOptions } from \"./request/index.js\";\nimport { ResourceResponse } from \"./request/index.js\";\nimport { checkURL } from \"./utils/checkURL.js\";\nimport { getEmptyCosmosDiagnostics, withDiagnostics } from \"./utils/diagnostics.js\";\nimport { GlobalPartitionEndpointManager } from \"./globalPartitionEndpointManager.js\";\n\n/**\n * Provides a client-side logical representation of the Azure Cosmos DB database account.\n * This client is used to configure and execute requests in the Azure Cosmos DB database service.\n * @example Instantiate a client and create a new database\n * ```ts snippet:CosmosClientCreate\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({ endpoint, key });\n * ```\n * @example Instantiate a client with custom Connection Policy\n * ```ts snippet:CosmosClientWithConnectionPolicy\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({\n * endpoint,\n * key,\n * connectionPolicy: {\n * requestTimeout: 10000,\n * },\n * });\n * ```\n */\nexport class CosmosClient {\n /**\n * Used for creating new databases, or querying/reading all databases.\n *\n * Use `.database(id)` to read, replace, or delete a specific, existing database by id.\n *\n * @example Create a new database\n * ```ts snippet:CosmosClientDatabases\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({ endpoint, key });\n * const { resource: databaseDefinition, database } = await client.databases.create({\n * id: \"<name here>\",\n * });\n * ```\n */\n public readonly databases: Databases;\n /**\n * Used for querying & reading all offers.\n *\n * Use `.offer(id)` to read, or replace existing offers.\n */\n public readonly offers: Offers;\n private clientContext: ClientContext;\n private endpointRefresher: NodeJS.Timeout;\n /**\n * @internal\n */\n private encryptionManager: EncryptionManager;\n /** @internal */\n private globalPartitionEndpointManager: GlobalPartitionEndpointManager;\n /**\n * Creates a new {@link CosmosClient} object from a connection string. Your database connection string can be found in the Azure Portal\n */\n constructor(connectionString: string);\n /**\n * Creates a new {@link CosmosClient} object. See {@link CosmosClientOptions} for more details on what options you can use.\n * @param options - bag of options; require at least endpoint and auth to be configured\n */\n constructor(options: CosmosClientOptions);\n constructor(optionsOrConnectionString: string | CosmosClientOptions) {\n if (typeof optionsOrConnectionString === \"string\") {\n optionsOrConnectionString = parseConnectionString(optionsOrConnectionString);\n } else if (optionsOrConnectionString.connectionString) {\n const { endpoint, key } = parseConnectionString(optionsOrConnectionString.connectionString);\n optionsOrConnectionString.endpoint = endpoint;\n optionsOrConnectionString.key = key;\n }\n\n const endpoint = checkURL(optionsOrConnectionString.endpoint);\n if (!endpoint) {\n throw new Error(\"Invalid endpoint specified\");\n }\n\n if (optionsOrConnectionString.clientEncryptionOptions) {\n if (!optionsOrConnectionString.clientEncryptionOptions.keyEncryptionKeyResolver) {\n throw new Error(\n \"KeyEncryptionKeyResolver needs to be provided to enable client-side encryption.\",\n );\n }\n if (\n optionsOrConnectionString.clientEncryptionOptions.encryptionKeyTimeToLiveInSeconds &&\n optionsOrConnectionString.clientEncryptionOptions.encryptionKeyTimeToLiveInSeconds < 60\n ) {\n throw new Error(\"EncryptionKeyTimeToLiveInSeconds needs to be >= 60 seconds.\");\n }\n this.encryptionManager = new EncryptionManager(\n optionsOrConnectionString.clientEncryptionOptions.keyEncryptionKeyResolver,\n optionsOrConnectionString.clientEncryptionOptions.encryptionKeyTimeToLiveInSeconds,\n );\n }\n\n const clientConfig: ClientConfigDiagnostic =\n this.initializeClientConfigDiagnostic(optionsOrConnectionString);\n\n optionsOrConnectionString.connectionPolicy = Object.assign(\n {},\n defaultConnectionPolicy,\n optionsOrConnectionString.connectionPolicy,\n );\n\n optionsOrConnectionString.defaultHeaders = optionsOrConnectionString.defaultHeaders || {};\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.CacheControl] = \"no-cache\";\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.Version] =\n Constants.CurrentVersion;\n if (optionsOrConnectionString.consistencyLevel !== undefined) {\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.ConsistencyLevel] =\n optionsOrConnectionString.consistencyLevel;\n }\n\n if (optionsOrConnectionString.throughputBucket !== undefined) {\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.ThroughputBucket] =\n optionsOrConnectionString.throughputBucket;\n }\n\n const userAgent = getUserAgent(optionsOrConnectionString);\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.UserAgent] = userAgent;\n optionsOrConnectionString.defaultHeaders[Constants.HttpHeaders.CustomUserAgent] = userAgent;\n\n const globalEndpointManager = new GlobalEndpointManager(\n optionsOrConnectionString,\n async (diagnosticNode: DiagnosticNodeInternal, opts: RequestOptions) =>\n this.getDatabaseAccountInternal(diagnosticNode, opts),\n );\n\n if (\n optionsOrConnectionString.connectionPolicy.enablePartitionLevelFailover ||\n optionsOrConnectionString.connectionPolicy.enablePartitionLevelCircuitBreaker\n ) {\n this.globalPartitionEndpointManager = new GlobalPartitionEndpointManager(\n optionsOrConnectionString,\n globalEndpointManager,\n );\n }\n\n this.clientContext = new ClientContext(\n optionsOrConnectionString,\n globalEndpointManager,\n clientConfig,\n determineDiagnosticLevel(\n optionsOrConnectionString.diagnosticLevel,\n getDiagnosticLevelFromEnvironment(),\n ),\n this.globalPartitionEndpointManager,\n );\n if (\n optionsOrConnectionString.connectionPolicy?.enableEndpointDiscovery &&\n optionsOrConnectionString.connectionPolicy?.enableBackgroundEndpointRefreshing\n ) {\n this.backgroundRefreshEndpointList(\n globalEndpointManager,\n optionsOrConnectionString.connectionPolicy.endpointRefreshRateInMs ||\n defaultConnectionPolicy.endpointRefreshRateInMs,\n );\n }\n\n this.databases = new Databases(this, this.clientContext, this.encryptionManager);\n this.offers = new Offers(this, this.clientContext);\n }\n\n private initializeClientConfigDiagnostic(\n optionsOrConnectionString: CosmosClientOptions,\n ): ClientConfigDiagnostic {\n return {\n endpoint: optionsOrConnectionString.endpoint,\n resourceTokensConfigured: optionsOrConnectionString.resourceTokens !== undefined,\n tokenProviderConfigured: optionsOrConnectionString.tokenProvider !== undefined,\n aadCredentialsConfigured: optionsOrConnectionString.aadCredentials !== undefined,\n connectionPolicyConfigured: optionsOrConnectionString.connectionPolicy !== undefined,\n consistencyLevel: optionsOrConnectionString.consistencyLevel,\n defaultHeaders: optionsOrConnectionString.defaultHeaders,\n agentConfigured: optionsOrConnectionString.agent !== undefined,\n userAgentSuffix: optionsOrConnectionString.userAgentSuffix,\n diagnosticLevel: optionsOrConnectionString.diagnosticLevel,\n pluginsConfigured: optionsOrConnectionString.plugins !== undefined,\n sDKVersion: Constants.SDKVersion,\n };\n }\n\n /**\n * Get information about the current {@link DatabaseAccount} (including which regions are supported, etc.)\n */\n public async getDatabaseAccount(\n options?: RequestOptions,\n ): Promise<ResourceResponse<DatabaseAccount>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n return this.getDatabaseAccountInternal(diagnosticNode, options);\n }, this.clientContext);\n }\n\n /**\n * @hidden\n */\n public async getDatabaseAccountInternal(\n diagnosticNode: DiagnosticNodeInternal,\n options?: RequestOptions,\n ): Promise<ResourceResponse<DatabaseAccount>> {\n const response = await this.clientContext.getDatabaseAccount(diagnosticNode, options);\n return new ResourceResponse<DatabaseAccount>(\n response.result,\n response.headers,\n response.code,\n getEmptyCosmosDiagnostics(),\n response.substatus,\n );\n }\n\n /**\n * Gets the currently used write endpoint url. Useful for troubleshooting purposes.\n *\n * The url may contain a region suffix (e.g. \"-eastus\") if we're using location specific endpoints.\n */\n public async getWriteEndpoint(): Promise<string> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n return this.clientContext.getWriteEndpoint(diagnosticNode);\n }, this.clientContext);\n }\n\n /**\n * Gets the currently used read endpoint. Useful for troubleshooting purposes.\n *\n * The url may contain a region suffix (e.g. \"-eastus\") if we're using location specific endpoints.\n */\n public async getReadEndpoint(): Promise<string> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n return this.clientContext.getReadEndpoint(diagnosticNode);\n }, this.clientContext);\n }\n\n /**\n * Gets the known write endpoints. Useful for troubleshooting purposes.\n *\n * The urls may contain a region suffix (e.g. \"-eastus\") if we're using location specific endpoints.\n */\n public getWriteEndpoints(): Promise<readonly string[]> {\n return this.clientContext.getWriteEndpoints();\n }\n\n /**\n * Gets the currently used read endpoint. Useful for troubleshooting purposes.\n *\n * The url may contain a region suffix (e.g. \"-eastus\") if we're using location specific endpoints.\n */\n public getReadEndpoints(): Promise<readonly string[]> {\n return this.clientContext.getReadEndpoints();\n }\n\n /**\n * Used for reading, updating, or deleting a existing database by id or accessing containers belonging to that database.\n *\n * This does not make a network call. Use `.read` to get info about the database after getting the {@link Database} object.\n *\n * @param id - The id of the database.\n * @example Create a new container off of an existing database\n * ```ts snippet:CosmosClientDatabaseCreateContainer\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({ endpoint, key });\n * const container = client.database(\"<database id>\").containers.create({\n * id: \"<name here>\",\n * });\n * ```\n *\n * @example Delete an existing database\n * ```ts snippet:CosmosClientDatabaseDelete\n * import { CosmosClient } from \"@azure/cosmos\";\n *\n * const endpoint = \"https://your-account.documents.azure.com\";\n * const key = \"<database account masterkey>\";\n * const client = new CosmosClient({ endpoint, key });\n * await client.database(\"<id here>\").delete();\n * ```\n */\n public database(id: string): Database {\n return new Database(this, id, this.clientContext, this.encryptionManager);\n }\n\n /**\n * Used for reading, or updating a existing offer by id.\n * @param id - The id of the offer.\n */\n public offer(id: string): Offer {\n return new Offer(this, id, this.clientContext);\n }\n\n /**\n * Clears background endpoint refresher. Use client.dispose() when destroying the CosmosClient within another process.\n */\n public dispose(): void {\n clearTimeout(this.endpointRefresher);\n if (this.clientContext.enableEncryption) {\n clearTimeout(this.encryptionManager.encryptionKeyStoreProvider.cacheRefresher);\n clearTimeout(this.encryptionManager.protectedDataEncryptionKeyCache.cacheRefresher);\n }\n if (this.globalPartitionEndpointManager) {\n this.globalPartitionEndpointManager.dispose();\n }\n }\n\n private async backgroundRefreshEndpointList(\n globalEndpointManager: GlobalEndpointManager,\n refreshRate: number,\n ) {\n this.endpointRefresher = setInterval(() => {\n try {\n return withDiagnostics(\n async (diagnosticNode: DiagnosticNodeInternal) => {\n return globalEndpointManager.refreshEndpointList(diagnosticNode);\n },\n this.clientContext,\n DiagnosticNodeType.BACKGROUND_REFRESH_THREAD,\n );\n } catch (e: any) {\n console.warn(\"Failed to refresh endpoints\", e);\n }\n }, refreshRate);\n if (this.endpointRefresher.unref && typeof this.endpointRefresher.unref === \"function\") {\n this.endpointRefresher.unref();\n }\n }\n\n /**\n * Update the host framework. If provided host framework will be used to generate the defualt SDK user agent.\n * @param hostFramework - A custom string.\n * @internal\n */\n public async updateHostFramework(hostFramework: string): Promise<void> {\n this.clientContext.refreshUserAgent(hostFramework);\n }\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import { DiagnosticNodeInternal } from "./index.js";
2
+ /**
3
+ * @hidden
4
+ * This class manages the failover information for partition key ranges in Cosmos DB.
5
+ * It tracks the current endpoint, failed endpoints, and the number of consecutive read/write request failures.
6
+ */
7
+ export declare class PartitionKeyRangeFailoverInfo {
8
+ private failedEndPoints;
9
+ private currentEndPoint;
10
+ private consecutiveReadRequestFailureCount;
11
+ private consecutiveWriteRequestFailureCount;
12
+ private firstRequestFailureTime;
13
+ private lastRequestFailureTime;
14
+ private failureCountSemaphore;
15
+ private tryMoveNextLocationSemaphore;
16
+ /**
17
+ * Checks if the circuit breaker can trigger a partition failover based on the failure counts.
18
+ * Returns true if the number of consecutive failures exceeds the defined thresholds for read or write requests.
19
+ */
20
+ canCircuitBreakerTriggerPartitionFailOver(isReadOnlyRequest: boolean): Promise<boolean>;
21
+ /**
22
+ * Increments the failure counts for read or write requests and updates the timestamps.
23
+ * If the time since the last failure exceeds the reset window, it resets the failure counts.
24
+ */
25
+ incrementRequestFailureCounts(isReadOnlyRequest: boolean, currentTimeInMilliseconds: number): Promise<void>;
26
+ /**
27
+ * Returns a snapshot of the first and last request failure timestamps.
28
+ * This method is used to retrieve the current state of failure timestamps without modifying them.
29
+ */
30
+ snapshotPartitionFailoverTimestamps(): Promise<{
31
+ firstRequestFailureTime: number;
32
+ lastRequestFailureTime: number;
33
+ }>;
34
+ /**
35
+ * Attempts to move to the next available location for the partition key range.
36
+ * If the current endpoint is the same as the failed endpoint, it tries to find a new endpoint
37
+ * from the provided list of endpoints. If a new endpoint is found, it updates the current endpoint
38
+ * and returns true. If no new endpoint is found, it returns false.
39
+ */
40
+ tryMoveNextLocation(endPoints: readonly string[], failedEndPoint: string, diagnosticNode: DiagnosticNodeInternal, partitionKeyRangeId: string): Promise<boolean>;
41
+ /** Returns the current endpoint being used for partition key range operations.*/
42
+ getCurrentEndPoint(): string;
43
+ /**
44
+ * Returns a snapshot of the current consecutive request failure counts for read and write requests.
45
+ * This method is used to retrieve the current state of failure counts without modifying them.
46
+ */
47
+ private snapshotConsecutiveRequestFailureCount;
48
+ }
49
+ //# sourceMappingURL=PartitionKeyRangeFailoverInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionKeyRangeFailoverInfo.d.ts","sourceRoot":"","sources":["../../src/PartitionKeyRangeFailoverInfo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAG/D;;;;GAIG;AACH,qBAAa,6BAA6B;IACxC,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,eAAe,CAAS;IAEhC,OAAO,CAAC,kCAAkC,CAAa;IACvD,OAAO,CAAC,mCAAmC,CAAa;IACxD,OAAO,CAAC,uBAAuB,CAAsB;IACrD,OAAO,CAAC,sBAAsB,CAAsB;IAEpD,OAAO,CAAC,qBAAqB,CAAsB;IACnD,OAAO,CAAC,4BAA4B,CAAsB;IAW1D;;;OAGG;IACU,yCAAyC,CACpD,iBAAiB,EAAE,OAAO,GACzB,OAAO,CAAC,OAAO,CAAC;IASnB;;;OAGG;IACU,6BAA6B,CACxC,iBAAiB,EAAE,OAAO,EAC1B,yBAAyB,EAAE,MAAM,GAChC,OAAO,CAAC,IAAI,CAAC;IA+BhB;;;OAGG;IACU,mCAAmC,IAAI,OAAO,CAAC;QAC1D,uBAAuB,EAAE,MAAM,CAAC;QAChC,sBAAsB,EAAE,MAAM,CAAC;KAChC,CAAC;IAOF;;;;;OAKG;IACU,mBAAmB,CAC9B,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,sBAAsB,EACtC,mBAAmB,EAAE,MAAM,GAC1B,OAAO,CAAC,OAAO,CAAC;IAiCnB,iFAAiF;IAC1E,kBAAkB,IAAI,MAAM;IAInC;;;OAGG;YACW,sCAAsC;CASrD"}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PartitionKeyRangeFailoverInfo = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Copyright (c) Microsoft Corporation.
6
+ // Licensed under the MIT License.
7
+ const index_js_1 = require("./index.js");
8
+ const semaphore_1 = tslib_1.__importDefault(require("semaphore"));
9
+ /**
10
+ * @hidden
11
+ * This class manages the failover information for partition key ranges in Cosmos DB.
12
+ * It tracks the current endpoint, failed endpoints, and the number of consecutive read/write request failures.
13
+ */
14
+ class PartitionKeyRangeFailoverInfo {
15
+ /**
16
+ * @internal
17
+ */
18
+ constructor(currentEndpoint) {
19
+ this.failedEndPoints = [];
20
+ this.consecutiveReadRequestFailureCount = 0;
21
+ this.consecutiveWriteRequestFailureCount = 0;
22
+ this.firstRequestFailureTime = Date.now();
23
+ this.lastRequestFailureTime = Date.now();
24
+ this.currentEndPoint = currentEndpoint;
25
+ this.failureCountSemaphore = (0, semaphore_1.default)(1);
26
+ this.tryMoveNextLocationSemaphore = (0, semaphore_1.default)(1);
27
+ }
28
+ /**
29
+ * Checks if the circuit breaker can trigger a partition failover based on the failure counts.
30
+ * Returns true if the number of consecutive failures exceeds the defined thresholds for read or write requests.
31
+ */
32
+ async canCircuitBreakerTriggerPartitionFailOver(isReadOnlyRequest) {
33
+ const { consecutiveReadRequestFailureCount, consecutiveWriteRequestFailureCount } = await this.snapshotConsecutiveRequestFailureCount();
34
+ return isReadOnlyRequest
35
+ ? consecutiveReadRequestFailureCount > index_js_1.Constants.ReadRequestFailureCountThreshold
36
+ : consecutiveWriteRequestFailureCount > index_js_1.Constants.WriteRequestFailureCountThreshold;
37
+ }
38
+ /**
39
+ * Increments the failure counts for read or write requests and updates the timestamps.
40
+ * If the time since the last failure exceeds the reset window, it resets the failure counts.
41
+ */
42
+ async incrementRequestFailureCounts(isReadOnlyRequest, currentTimeInMilliseconds) {
43
+ return new Promise((resolve, reject) => {
44
+ this.failureCountSemaphore.take(async () => {
45
+ try {
46
+ const { lastRequestFailureTime } = await this.snapshotPartitionFailoverTimestamps();
47
+ if (currentTimeInMilliseconds - lastRequestFailureTime >
48
+ index_js_1.Constants.ConsecutiveFailureCountResetIntervalInMS) {
49
+ this.consecutiveReadRequestFailureCount = 0;
50
+ this.consecutiveWriteRequestFailureCount = 0;
51
+ }
52
+ if (isReadOnlyRequest) {
53
+ this.consecutiveReadRequestFailureCount++;
54
+ }
55
+ else {
56
+ this.consecutiveWriteRequestFailureCount++;
57
+ }
58
+ this.lastRequestFailureTime = currentTimeInMilliseconds;
59
+ return resolve();
60
+ }
61
+ catch (error) {
62
+ reject(error);
63
+ }
64
+ finally {
65
+ // Release the semaphore lock
66
+ this.failureCountSemaphore.leave();
67
+ }
68
+ });
69
+ });
70
+ }
71
+ /**
72
+ * Returns a snapshot of the first and last request failure timestamps.
73
+ * This method is used to retrieve the current state of failure timestamps without modifying them.
74
+ */
75
+ async snapshotPartitionFailoverTimestamps() {
76
+ return {
77
+ firstRequestFailureTime: this.firstRequestFailureTime,
78
+ lastRequestFailureTime: this.lastRequestFailureTime,
79
+ };
80
+ }
81
+ /**
82
+ * Attempts to move to the next available location for the partition key range.
83
+ * If the current endpoint is the same as the failed endpoint, it tries to find a new endpoint
84
+ * from the provided list of endpoints. If a new endpoint is found, it updates the current endpoint
85
+ * and returns true. If no new endpoint is found, it returns false.
86
+ */
87
+ async tryMoveNextLocation(endPoints, failedEndPoint, diagnosticNode, partitionKeyRangeId) {
88
+ if (failedEndPoint !== this.currentEndPoint) {
89
+ return true;
90
+ }
91
+ return new Promise((resolve, reject) => {
92
+ this.tryMoveNextLocationSemaphore.take(() => {
93
+ try {
94
+ for (const endpoint of endPoints) {
95
+ if (this.currentEndPoint === endpoint) {
96
+ continue;
97
+ }
98
+ if (this.failedEndPoints.includes(endpoint)) {
99
+ continue;
100
+ }
101
+ this.failedEndPoints.push(failedEndPoint);
102
+ this.currentEndPoint = endpoint;
103
+ return resolve(true);
104
+ }
105
+ diagnosticNode.addData({
106
+ partitionKeyRangeFailoverInfo: `PartitionKeyRangeId: ${partitionKeyRangeId}, failedLocations: ${this.failedEndPoints}, newLocation: ${this.currentEndPoint}`,
107
+ });
108
+ return resolve(false);
109
+ }
110
+ catch (err) {
111
+ reject(err);
112
+ }
113
+ finally {
114
+ this.tryMoveNextLocationSemaphore.leave();
115
+ }
116
+ });
117
+ });
118
+ }
119
+ /** Returns the current endpoint being used for partition key range operations.*/
120
+ getCurrentEndPoint() {
121
+ return this.currentEndPoint;
122
+ }
123
+ /**
124
+ * Returns a snapshot of the current consecutive request failure counts for read and write requests.
125
+ * This method is used to retrieve the current state of failure counts without modifying them.
126
+ */
127
+ async snapshotConsecutiveRequestFailureCount() {
128
+ return {
129
+ consecutiveReadRequestFailureCount: this.consecutiveReadRequestFailureCount,
130
+ consecutiveWriteRequestFailureCount: this.consecutiveWriteRequestFailureCount,
131
+ };
132
+ }
133
+ }
134
+ exports.PartitionKeyRangeFailoverInfo = PartitionKeyRangeFailoverInfo;
135
+ //# sourceMappingURL=PartitionKeyRangeFailoverInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionKeyRangeFailoverInfo.js","sourceRoot":"","sources":["../../src/PartitionKeyRangeFailoverInfo.ts"],"names":[],"mappings":";;;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,yCAA+D;AAC/D,kEAAkC;AAElC;;;;GAIG;AACH,MAAa,6BAA6B;IAYxC;;OAEG;IACH,YAAY,eAAuB;QAd3B,oBAAe,GAAa,EAAE,CAAC;QAG/B,uCAAkC,GAAW,CAAC,CAAC;QAC/C,wCAAmC,GAAW,CAAC,CAAC;QAChD,4BAAuB,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7C,2BAAsB,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QASlD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,qBAAqB,GAAG,IAAA,mBAAS,EAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,CAAC,4BAA4B,GAAG,IAAA,mBAAS,EAAC,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,y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,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,iFAAiF;IAC1E,kBAAkB;QACvB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,sCAAsC;QAIlD,OAAO;YACL,kCAAkC,EAAE,IAAI,CAAC,kCAAkC;YAC3E,mCAAmC,EAAE,IAAI,CAAC,mCAAmC;SAC9E,CAAC;IACJ,CAAC;CACF;AAtJD,sEAsJC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { Constants, DiagnosticNodeInternal } from \"./index.js\";\nimport semaphore from \"semaphore\";\n\n/**\n * @hidden\n * This class manages the failover information for partition key ranges in Cosmos DB.\n * It tracks the current endpoint, failed endpoints, and the number of consecutive read/write request failures.\n */\nexport class PartitionKeyRangeFailoverInfo {\n private failedEndPoints: string[] = [];\n private currentEndPoint: string;\n\n private consecutiveReadRequestFailureCount: number = 0;\n private consecutiveWriteRequestFailureCount: number = 0;\n private firstRequestFailureTime: number = Date.now();\n private lastRequestFailureTime: number = Date.now();\n\n private failureCountSemaphore: semaphore.Semaphore;\n private tryMoveNextLocationSemaphore: semaphore.Semaphore;\n\n /**\n * @internal\n */\n constructor(currentEndpoint: string) {\n this.currentEndPoint = currentEndpoint;\n this.failureCountSemaphore = semaphore(1);\n this.tryMoveNextLocationSemaphore = semaphore(1);\n }\n\n /**\n * Checks if the circuit breaker can trigger a partition failover based on the failure counts.\n * Returns true if the number of consecutive failures exceeds the defined thresholds for read or write requests.\n */\n public async canCircuitBreakerTriggerPartitionFailOver(\n isReadOnlyRequest: boolean,\n ): Promise<boolean> {\n const { consecutiveReadRequestFailureCount, consecutiveWriteRequestFailureCount } =\n await this.snapshotConsecutiveRequestFailureCount();\n\n return isReadOnlyRequest\n ? consecutiveReadRequestFailureCount > Constants.ReadRequestFailureCountThreshold\n : consecutiveWriteRequestFailureCount > Constants.WriteRequestFailureCountThreshold;\n }\n\n /**\n * Increments the failure counts for read or write requests and updates the timestamps.\n * If the time since the last failure exceeds the reset window, it resets the failure counts.\n */\n public async incrementRequestFailureCounts(\n isReadOnlyRequest: boolean,\n currentTimeInMilliseconds: number,\n ): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n this.failureCountSemaphore.take(async () => {\n try {\n const { lastRequestFailureTime } = await this.snapshotPartitionFailoverTimestamps();\n\n if (\n currentTimeInMilliseconds - lastRequestFailureTime >\n Constants.ConsecutiveFailureCountResetIntervalInMS\n ) {\n this.consecutiveReadRequestFailureCount = 0;\n this.consecutiveWriteRequestFailureCount = 0;\n }\n\n if (isReadOnlyRequest) {\n this.consecutiveReadRequestFailureCount++;\n } else {\n this.consecutiveWriteRequestFailureCount++;\n }\n this.lastRequestFailureTime = currentTimeInMilliseconds;\n return resolve();\n } catch (error) {\n reject(error);\n } finally {\n // Release the semaphore lock\n this.failureCountSemaphore.leave();\n }\n });\n });\n }\n\n /**\n * Returns a snapshot of the first and last request failure timestamps.\n * This method is used to retrieve the current state of failure timestamps without modifying them.\n */\n public async snapshotPartitionFailoverTimestamps(): Promise<{\n firstRequestFailureTime: number;\n lastRequestFailureTime: number;\n }> {\n return {\n firstRequestFailureTime: this.firstRequestFailureTime,\n lastRequestFailureTime: this.lastRequestFailureTime,\n };\n }\n\n /**\n * Attempts to move to the next available location for the partition key range.\n * If the current endpoint is the same as the failed endpoint, it tries to find a new endpoint\n * from the provided list of endpoints. If a new endpoint is found, it updates the current endpoint\n * and returns true. If no new endpoint is found, it returns false.\n */\n public async tryMoveNextLocation(\n endPoints: readonly string[],\n failedEndPoint: string,\n diagnosticNode: DiagnosticNodeInternal,\n partitionKeyRangeId: string,\n ): Promise<boolean> {\n if (failedEndPoint !== this.currentEndPoint) {\n return true;\n }\n return new Promise((resolve, reject) => {\n this.tryMoveNextLocationSemaphore.take(() => {\n try {\n for (const endpoint of endPoints) {\n if (this.currentEndPoint === endpoint) {\n continue;\n }\n\n if (this.failedEndPoints.includes(endpoint)) {\n continue;\n }\n\n this.failedEndPoints.push(failedEndPoint);\n this.currentEndPoint = endpoint;\n return resolve(true);\n }\n diagnosticNode.addData({\n partitionKeyRangeFailoverInfo: `PartitionKeyRangeId: ${partitionKeyRangeId}, failedLocations: ${this.failedEndPoints}, newLocation: ${this.currentEndPoint}`,\n });\n return resolve(false);\n } catch (err) {\n reject(err);\n } finally {\n this.tryMoveNextLocationSemaphore.leave();\n }\n });\n });\n }\n\n /** Returns the current endpoint being used for partition key range operations.*/\n public getCurrentEndPoint(): string {\n return this.currentEndPoint;\n }\n\n /**\n * Returns a snapshot of the current consecutive request failure counts for read and write requests.\n * This method is used to retrieve the current state of failure counts without modifying them.\n */\n private async snapshotConsecutiveRequestFailureCount(): Promise<{\n consecutiveReadRequestFailureCount: number;\n consecutiveWriteRequestFailureCount: number;\n }> {\n return {\n consecutiveReadRequestFailureCount: this.consecutiveReadRequestFailureCount,\n consecutiveWriteRequestFailureCount: this.consecutiveWriteRequestFailureCount,\n };\n }\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { DiagnosticNodeInternal } from "../diagnostics/DiagnosticNodeInternal.js";
2
- import type { PartitionKeyDefinition } from "../documents/index.js";
2
+ import type { PartitionKeyDefinition, PartitionKeyInternal } from "../documents/index.js";
3
+ import { PartitionKeyRangeCache } from "../routing/partitionKeyRangeCache.js";
3
4
  import type { Container } from "./Container/index.js";
4
5
  export declare function readPartitionKeyDefinition(diagnosticNode: DiagnosticNodeInternal, container: Container): Promise<PartitionKeyDefinition>;
6
+ export declare function computePartitionKeyRangeId(diagnosticNode: DiagnosticNodeInternal, partitionKey: PartitionKeyInternal, partitionKeyRangeCache: PartitionKeyRangeCache, isPartitionLevelFailOverEnabled: boolean, container: Container, pKDefinition?: PartitionKeyDefinition): Promise<string | undefined>;
5
7
  //# sourceMappingURL=ClientUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClientUtils.d.ts","sourceRoot":"","sources":["../../../src/client/ClientUtils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,wBAAsB,0BAA0B,CAC9C,cAAc,EAAE,sBAAsB,EACtC,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,sBAAsB,CAAC,CAGjC"}
1
+ {"version":3,"file":"ClientUtils.d.ts","sourceRoot":"","sources":["../../../src/client/ClientUtils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,wBAAsB,0BAA0B,CAC9C,cAAc,EAAE,sBAAsB,EACtC,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,sBAAsB,CAAC,CAGjC;AAED,wBAAsB,0BAA0B,CAC9C,cAAc,EAAE,sBAAsB,EACtC,YAAY,EAAE,oBAAoB,EAClC,sBAAsB,EAAE,sBAAsB,EAC9C,+BAA+B,EAAE,OAAO,EACxC,SAAS,EAAE,SAAS,EACpB,YAAY,CAAC,EAAE,sBAAsB,GACpC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAe7B"}
@@ -3,8 +3,19 @@
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.readPartitionKeyDefinition = readPartitionKeyDefinition;
6
+ exports.computePartitionKeyRangeId = computePartitionKeyRangeId;
6
7
  async function readPartitionKeyDefinition(diagnosticNode, container) {
7
8
  const partitionKeyDefinition = await container.readPartitionKeyDefinition(diagnosticNode);
8
9
  return partitionKeyDefinition.resource;
9
10
  }
11
+ async function computePartitionKeyRangeId(diagnosticNode, partitionKey, partitionKeyRangeCache, isPartitionLevelFailOverEnabled, container, pKDefinition) {
12
+ let partitionKeyRangeId = undefined;
13
+ if (isPartitionLevelFailOverEnabled) {
14
+ const partitionKeyDefinition = pKDefinition !== null && pKDefinition !== void 0 ? pKDefinition : (await readPartitionKeyDefinition(diagnosticNode, container));
15
+ if (partitionKeyDefinition && partitionKey && partitionKey.length > 0) {
16
+ partitionKeyRangeId = await partitionKeyRangeCache.getPartitionKeyRangeIdFromPartitionKey(container.url, partitionKey, partitionKeyDefinition, diagnosticNode);
17
+ }
18
+ }
19
+ return partitionKeyRangeId;
20
+ }
10
21
  //# sourceMappingURL=ClientUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClientUtils.js","sourceRoot":"","sources":["../../../src/client/ClientUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAMlC,gEAMC;AANM,KAAK,UAAU,0BAA0B,CAC9C,cAAsC,EACtC,SAAoB;IAEpB,MAAM,sBAAsB,GAAG,MAAM,SAAS,CAAC,0BAA0B,CAAC,cAAc,CAAC,CAAC;IAC1F,OAAO,sBAAsB,CAAC,QAAQ,CAAC;AACzC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { PartitionKeyDefinition } from \"../documents/index.js\";\nimport type { Container } from \"./Container/index.js\";\n\nexport async function readPartitionKeyDefinition(\n diagnosticNode: DiagnosticNodeInternal,\n container: Container,\n): Promise<PartitionKeyDefinition> {\n const partitionKeyDefinition = await container.readPartitionKeyDefinition(diagnosticNode);\n return partitionKeyDefinition.resource;\n}\n"]}
1
+ {"version":3,"file":"ClientUtils.js","sourceRoot":"","sources":["../../../src/client/ClientUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAOlC,gEAMC;AAED,gEAsBC;AA9BM,KAAK,UAAU,0BAA0B,CAC9C,cAAsC,EACtC,SAAoB;IAEpB,MAAM,sBAAsB,GAAG,MAAM,SAAS,CAAC,0BAA0B,CAAC,cAAc,CAAC,CAAC;IAC1F,OAAO,sBAAsB,CAAC,QAAQ,CAAC;AACzC,CAAC;AAEM,KAAK,UAAU,0BAA0B,CAC9C,cAAsC,EACtC,YAAkC,EAClC,sBAA8C,EAC9C,+BAAwC,EACxC,SAAoB,EACpB,YAAqC;IAErC,IAAI,mBAAmB,GAAuB,SAAS,CAAC;IACxD,IAAI,+BAA+B,EAAE,CAAC;QACpC,MAAM,sBAAsB,GAC1B,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,CAAC,MAAM,0BAA0B,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC;QAChF,IAAI,sBAAsB,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtE,mBAAmB,GAAG,MAAM,sBAAsB,CAAC,sCAAsC,CACvF,SAAS,CAAC,GAAG,EACb,YAAY,EACZ,sBAAsB,EACtB,cAAc,CACf,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { PartitionKeyDefinition, PartitionKeyInternal } from \"../documents/index.js\";\nimport { PartitionKeyRangeCache } from \"../routing/partitionKeyRangeCache.js\";\nimport type { Container } from \"./Container/index.js\";\n\nexport async function readPartitionKeyDefinition(\n diagnosticNode: DiagnosticNodeInternal,\n container: Container,\n): Promise<PartitionKeyDefinition> {\n const partitionKeyDefinition = await container.readPartitionKeyDefinition(diagnosticNode);\n return partitionKeyDefinition.resource;\n}\n\nexport async function computePartitionKeyRangeId(\n diagnosticNode: DiagnosticNodeInternal,\n partitionKey: PartitionKeyInternal,\n partitionKeyRangeCache: PartitionKeyRangeCache,\n isPartitionLevelFailOverEnabled: boolean,\n container: Container,\n pKDefinition?: PartitionKeyDefinition,\n): Promise<string | undefined> {\n let partitionKeyRangeId: string | undefined = undefined;\n if (isPartitionLevelFailOverEnabled) {\n const partitionKeyDefinition =\n pKDefinition ?? (await readPartitionKeyDefinition(diagnosticNode, container));\n if (partitionKeyDefinition && partitionKey && partitionKey.length > 0) {\n partitionKeyRangeId = await partitionKeyRangeCache.getPartitionKeyRangeIdFromPartitionKey(\n container.url,\n partitionKey,\n partitionKeyDefinition,\n diagnosticNode,\n );\n }\n }\n return partitionKeyRangeId;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../../../src/client/Item/Item.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAY5D,OAAO,KAAK,EAAE,YAAY,EAAwB,MAAM,0BAA0B,CAAC;AAEnF,OAAO,KAAK,EAAE,cAAc,EAAY,MAAM,wBAAwB,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIjD;;;;GAIG;AACH,qBAAa,IAAI;aAgBG,SAAS,EAAE,SAAS;aACpB,EAAE,EAAE,MAAM;IAC1B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAjBhC,OAAO,CAAC,YAAY,CAAuB;IAC3C;;OAEG;IACH,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED;;;;;OAKG;gBAEe,SAAS,EAAE,SAAS,EACpB,EAAE,EAAE,MAAM,EACT,aAAa,EAAE,aAAa,EAC7C,YAAY,CA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;;;;;;;;;;OAuCG;IACU,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,GAAG,EAC/C,IAAI,EAAE,gBAAgB,EACtB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAqH5B"}
@@ -8,6 +8,7 @@ const patch_js_1 = require("../../utils/patch.js");
8
8
  const ItemResponse_js_1 = require("./ItemResponse.js");
9
9
  const diagnostics_js_1 = require("../../utils/diagnostics.js");
10
10
  const extractPartitionKey_js_1 = require("../../extractPartitionKey.js");
11
+ const ClientUtils_js_1 = require("../ClientUtils.js");
11
12
  /**
12
13
  * Used to perform operations on a specific item.
13
14
  *
@@ -89,6 +90,8 @@ class Item {
89
90
  }
90
91
  const path = (0, index_js_1.getPathFromLink)(url);
91
92
  const id = (0, index_js_1.getIdFromLink)(url);
93
+ const isPartitionLevelFailOverEnabled = this.clientContext.isPartitionLevelFailOverEnabled();
94
+ const partitionKeyRangeId = await (0, ClientUtils_js_1.computePartitionKeyRangeId)(diagnosticNode, partitionKey, this.clientContext.partitionKeyRangeCache, isPartitionLevelFailOverEnabled, this.container);
92
95
  response = await this.clientContext.read({
93
96
  path,
94
97
  resourceType: index_js_1.ResourceType.item,
@@ -96,6 +99,7 @@ class Item {
96
99
  options,
97
100
  partitionKey: partitionKey,
98
101
  diagnosticNode,
102
+ partitionKeyRangeId,
99
103
  });
100
104
  }
101
105
  catch (error) {
@@ -149,6 +153,8 @@ class Item {
149
153
  }
150
154
  const path = (0, index_js_1.getPathFromLink)(url);
151
155
  const id = (0, index_js_1.getIdFromLink)(url);
156
+ const isPartitionLevelFailOverEnabled = this.clientContext.isPartitionLevelFailOverEnabled();
157
+ const partitionKeyRangeId = await (0, ClientUtils_js_1.computePartitionKeyRangeId)(diagnosticNode, partitionKey, this.clientContext.partitionKeyRangeCache, isPartitionLevelFailOverEnabled, this.container);
152
158
  response = await this.clientContext.replace({
153
159
  body,
154
160
  path,
@@ -157,6 +163,7 @@ class Item {
157
163
  options,
158
164
  partitionKey: partitionKey,
159
165
  diagnosticNode,
166
+ partitionKeyRangeId,
160
167
  });
161
168
  }
162
169
  catch (error) {
@@ -235,6 +242,8 @@ class Item {
235
242
  }
236
243
  const path = (0, index_js_1.getPathFromLink)(url);
237
244
  const id = (0, index_js_1.getIdFromLink)(url);
245
+ const isPartitionLevelFailOverEnabled = this.clientContext.isPartitionLevelFailOverEnabled();
246
+ const partitionKeyRangeId = await (0, ClientUtils_js_1.computePartitionKeyRangeId)(diagnosticNode, partitionKey, this.clientContext.partitionKeyRangeCache, isPartitionLevelFailOverEnabled, this.container);
238
247
  response = await this.clientContext.delete({
239
248
  path,
240
249
  resourceType: index_js_1.ResourceType.item,
@@ -242,6 +251,7 @@ class Item {
242
251
  options,
243
252
  partitionKey: partitionKey,
244
253
  diagnosticNode,
254
+ partitionKeyRangeId,
245
255
  });
246
256
  }
247
257
  catch (error) {
@@ -335,6 +345,8 @@ class Item {
335
345
  }
336
346
  const path = (0, index_js_1.getPathFromLink)(url);
337
347
  const id = (0, index_js_1.getIdFromLink)(url);
348
+ const isPartitionLevelFailOverEnabled = this.clientContext.isPartitionLevelFailOverEnabled();
349
+ const partitionKeyRangeId = await (0, ClientUtils_js_1.computePartitionKeyRangeId)(diagnosticNode, partitionKey, this.clientContext.partitionKeyRangeCache, isPartitionLevelFailOverEnabled, this.container);
338
350
  response = await this.clientContext.patch({
339
351
  body,
340
352
  path,
@@ -343,6 +355,7 @@ class Item {
343
355
  options,
344
356
  partitionKey: partitionKey,
345
357
  diagnosticNode,
358
+ partitionKeyRangeId,
346
359
  });
347
360
  }
348
361
  catch (error) {