@azure/cosmos 4.4.1-alpha.20250708.2 → 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 (395) 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.map +1 -1
  20. package/dist/browser/client/Item/Items.js +19 -3
  21. package/dist/browser/client/Item/Items.js.map +1 -1
  22. package/dist/browser/common/constants.d.ts +20 -0
  23. package/dist/browser/common/constants.d.ts.map +1 -1
  24. package/dist/browser/common/constants.js +23 -1
  25. package/dist/browser/common/constants.js.map +1 -1
  26. package/dist/browser/common/platform.d.ts +6 -1
  27. package/dist/browser/common/platform.d.ts.map +1 -1
  28. package/dist/browser/common/platform.js +23 -4
  29. package/dist/browser/common/platform.js.map +1 -1
  30. package/dist/browser/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
  31. package/dist/browser/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
  32. package/dist/browser/diagnostics/DiagnosticNodeInternal.js.map +1 -1
  33. package/dist/browser/documents/ConnectionPolicy.d.ts +6 -0
  34. package/dist/browser/documents/ConnectionPolicy.d.ts.map +1 -1
  35. package/dist/browser/documents/ConnectionPolicy.js +2 -0
  36. package/dist/browser/documents/ConnectionPolicy.js.map +1 -1
  37. package/dist/browser/documents/DatabaseAccount.d.ts.map +1 -1
  38. package/dist/browser/documents/DatabaseAccount.js +3 -0
  39. package/dist/browser/documents/DatabaseAccount.js.map +1 -1
  40. package/dist/browser/extractPartitionKey.d.ts.map +1 -1
  41. package/dist/browser/extractPartitionKey.js +33 -20
  42. package/dist/browser/extractPartitionKey.js.map +1 -1
  43. package/dist/browser/globalEndpointManager.d.ts +6 -0
  44. package/dist/browser/globalEndpointManager.d.ts.map +1 -1
  45. package/dist/browser/globalEndpointManager.js +9 -4
  46. package/dist/browser/globalEndpointManager.js.map +1 -1
  47. package/dist/browser/globalPartitionEndpointManager.d.ts +79 -0
  48. package/dist/browser/globalPartitionEndpointManager.d.ts.map +1 -0
  49. package/dist/browser/globalPartitionEndpointManager.js +279 -0
  50. package/dist/browser/globalPartitionEndpointManager.js.map +1 -0
  51. package/dist/browser/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
  52. package/dist/browser/queryExecutionContext/Aggregators/index.js +1 -0
  53. package/dist/browser/queryExecutionContext/Aggregators/index.js.map +1 -1
  54. package/dist/browser/queryExecutionContext/documentProducer.d.ts +2 -3
  55. package/dist/browser/queryExecutionContext/documentProducer.d.ts.map +1 -1
  56. package/dist/browser/queryExecutionContext/documentProducer.js +16 -21
  57. package/dist/browser/queryExecutionContext/documentProducer.js.map +1 -1
  58. package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
  59. package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
  60. package/dist/browser/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
  61. package/dist/browser/queryIterator.js +1 -2
  62. package/dist/browser/queryIterator.js.map +1 -1
  63. package/dist/browser/request/ErrorResponse.d.ts +1 -1
  64. package/dist/browser/request/ErrorResponse.d.ts.map +1 -1
  65. package/dist/browser/request/ErrorResponse.js.map +1 -1
  66. package/dist/browser/request/RequestContext.d.ts +5 -0
  67. package/dist/browser/request/RequestContext.d.ts.map +1 -1
  68. package/dist/browser/request/RequestContext.js.map +1 -1
  69. package/dist/browser/request/RequestHandler.d.ts.map +1 -1
  70. package/dist/browser/request/RequestHandler.js +14 -4
  71. package/dist/browser/request/RequestHandler.js.map +1 -1
  72. package/dist/browser/retry/RetryPolicy.d.ts +2 -2
  73. package/dist/browser/retry/RetryPolicy.d.ts.map +1 -1
  74. package/dist/browser/retry/RetryPolicy.js.map +1 -1
  75. package/dist/browser/retry/defaultRetryPolicy.d.ts.map +1 -1
  76. package/dist/browser/retry/defaultRetryPolicy.js +4 -8
  77. package/dist/browser/retry/defaultRetryPolicy.js.map +1 -1
  78. package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
  79. package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
  80. package/dist/browser/retry/endpointDiscoveryRetryPolicy.js +9 -2
  81. package/dist/browser/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
  82. package/dist/browser/retry/retryUtility.d.ts.map +1 -1
  83. package/dist/browser/retry/retryUtility.js +11 -5
  84. package/dist/browser/retry/retryUtility.js.map +1 -1
  85. package/dist/browser/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
  86. package/dist/browser/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
  87. package/dist/browser/retry/timeoutFailoverRetryPolicy.js +12 -4
  88. package/dist/browser/retry/timeoutFailoverRetryPolicy.js.map +1 -1
  89. package/dist/browser/routing/partitionKeyRangeCache.d.ts.map +1 -1
  90. package/dist/browser/routing/partitionKeyRangeCache.js +11 -0
  91. package/dist/browser/routing/partitionKeyRangeCache.js.map +1 -1
  92. package/dist/browser/utils/checkURL.js +6 -0
  93. package/dist/browser/utils/checkURL.js.map +1 -1
  94. package/dist/browser/utils/hashing/hash.d.ts +2 -0
  95. package/dist/browser/utils/hashing/hash.d.ts.map +1 -1
  96. package/dist/browser/utils/hashing/hash.js +19 -0
  97. package/dist/browser/utils/hashing/hash.js.map +1 -1
  98. package/dist/commonjs/ClientContext.d.ts +19 -10
  99. package/dist/commonjs/ClientContext.d.ts.map +1 -1
  100. package/dist/commonjs/ClientContext.js +30 -11
  101. package/dist/commonjs/ClientContext.js.map +1 -1
  102. package/dist/commonjs/CosmosClient.d.ts.map +1 -1
  103. package/dist/commonjs/CosmosClient.js +10 -2
  104. package/dist/commonjs/CosmosClient.js.map +1 -1
  105. package/dist/commonjs/PartitionKeyRangeFailoverInfo.d.ts +49 -0
  106. package/dist/commonjs/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
  107. package/dist/commonjs/PartitionKeyRangeFailoverInfo.js +135 -0
  108. package/dist/commonjs/PartitionKeyRangeFailoverInfo.js.map +1 -0
  109. package/dist/commonjs/client/ClientUtils.d.ts +3 -1
  110. package/dist/commonjs/client/ClientUtils.d.ts.map +1 -1
  111. package/dist/commonjs/client/ClientUtils.js +11 -0
  112. package/dist/commonjs/client/ClientUtils.js.map +1 -1
  113. package/dist/commonjs/client/Item/Item.d.ts.map +1 -1
  114. package/dist/commonjs/client/Item/Item.js +13 -0
  115. package/dist/commonjs/client/Item/Item.js.map +1 -1
  116. package/dist/commonjs/client/Item/Items.d.ts.map +1 -1
  117. package/dist/commonjs/client/Item/Items.js +17 -1
  118. package/dist/commonjs/client/Item/Items.js.map +1 -1
  119. package/dist/commonjs/common/constants.d.ts +20 -0
  120. package/dist/commonjs/common/constants.d.ts.map +1 -1
  121. package/dist/commonjs/common/constants.js +24 -2
  122. package/dist/commonjs/common/constants.js.map +1 -1
  123. package/dist/commonjs/common/platform.d.ts +6 -1
  124. package/dist/commonjs/common/platform.d.ts.map +1 -1
  125. package/dist/commonjs/common/platform.js +23 -3
  126. package/dist/commonjs/common/platform.js.map +1 -1
  127. package/dist/commonjs/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
  128. package/dist/commonjs/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
  129. package/dist/commonjs/diagnostics/DiagnosticNodeInternal.js.map +1 -1
  130. package/dist/commonjs/documents/ConnectionPolicy.d.ts +6 -0
  131. package/dist/commonjs/documents/ConnectionPolicy.d.ts.map +1 -1
  132. package/dist/commonjs/documents/ConnectionPolicy.js +2 -0
  133. package/dist/commonjs/documents/ConnectionPolicy.js.map +1 -1
  134. package/dist/commonjs/documents/DatabaseAccount.d.ts.map +1 -1
  135. package/dist/commonjs/documents/DatabaseAccount.js +3 -0
  136. package/dist/commonjs/documents/DatabaseAccount.js.map +1 -1
  137. package/dist/commonjs/extractPartitionKey.d.ts.map +1 -1
  138. package/dist/commonjs/extractPartitionKey.js +33 -20
  139. package/dist/commonjs/extractPartitionKey.js.map +1 -1
  140. package/dist/commonjs/globalEndpointManager.d.ts +6 -0
  141. package/dist/commonjs/globalEndpointManager.d.ts.map +1 -1
  142. package/dist/commonjs/globalEndpointManager.js +10 -5
  143. package/dist/commonjs/globalEndpointManager.js.map +1 -1
  144. package/dist/commonjs/globalPartitionEndpointManager.d.ts +79 -0
  145. package/dist/commonjs/globalPartitionEndpointManager.d.ts.map +1 -0
  146. package/dist/commonjs/globalPartitionEndpointManager.js +283 -0
  147. package/dist/commonjs/globalPartitionEndpointManager.js.map +1 -0
  148. package/dist/commonjs/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
  149. package/dist/commonjs/queryExecutionContext/Aggregators/index.js +1 -0
  150. package/dist/commonjs/queryExecutionContext/Aggregators/index.js.map +1 -1
  151. package/dist/commonjs/queryExecutionContext/documentProducer.d.ts +2 -3
  152. package/dist/commonjs/queryExecutionContext/documentProducer.d.ts.map +1 -1
  153. package/dist/commonjs/queryExecutionContext/documentProducer.js +15 -20
  154. package/dist/commonjs/queryExecutionContext/documentProducer.js.map +1 -1
  155. package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
  156. package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
  157. package/dist/commonjs/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
  158. package/dist/commonjs/queryIterator.js +1 -2
  159. package/dist/commonjs/queryIterator.js.map +1 -1
  160. package/dist/commonjs/request/ErrorResponse.d.ts +1 -1
  161. package/dist/commonjs/request/ErrorResponse.d.ts.map +1 -1
  162. package/dist/commonjs/request/ErrorResponse.js.map +1 -1
  163. package/dist/commonjs/request/RequestContext.d.ts +5 -0
  164. package/dist/commonjs/request/RequestContext.d.ts.map +1 -1
  165. package/dist/commonjs/request/RequestContext.js.map +1 -1
  166. package/dist/commonjs/request/RequestHandler.d.ts.map +1 -1
  167. package/dist/commonjs/request/RequestHandler.js +12 -2
  168. package/dist/commonjs/request/RequestHandler.js.map +1 -1
  169. package/dist/commonjs/request/defaultAgent.js +4 -4
  170. package/dist/commonjs/request/defaultAgent.js.map +1 -1
  171. package/dist/commonjs/retry/RetryPolicy.d.ts +2 -2
  172. package/dist/commonjs/retry/RetryPolicy.d.ts.map +1 -1
  173. package/dist/commonjs/retry/RetryPolicy.js.map +1 -1
  174. package/dist/commonjs/retry/defaultRetryPolicy.d.ts.map +1 -1
  175. package/dist/commonjs/retry/defaultRetryPolicy.js +3 -7
  176. package/dist/commonjs/retry/defaultRetryPolicy.js.map +1 -1
  177. package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
  178. package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
  179. package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js +9 -2
  180. package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
  181. package/dist/commonjs/retry/retryUtility.d.ts.map +1 -1
  182. package/dist/commonjs/retry/retryUtility.js +11 -5
  183. package/dist/commonjs/retry/retryUtility.js.map +1 -1
  184. package/dist/commonjs/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
  185. package/dist/commonjs/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
  186. package/dist/commonjs/retry/timeoutFailoverRetryPolicy.js +12 -4
  187. package/dist/commonjs/retry/timeoutFailoverRetryPolicy.js.map +1 -1
  188. package/dist/commonjs/routing/partitionKeyRangeCache.d.ts.map +1 -1
  189. package/dist/commonjs/routing/partitionKeyRangeCache.js +11 -0
  190. package/dist/commonjs/routing/partitionKeyRangeCache.js.map +1 -1
  191. package/dist/commonjs/utils/checkURL.js +7 -0
  192. package/dist/commonjs/utils/checkURL.js.map +1 -1
  193. package/dist/commonjs/utils/hashing/hash.d.ts +2 -0
  194. package/dist/commonjs/utils/hashing/hash.d.ts.map +1 -1
  195. package/dist/commonjs/utils/hashing/hash.js +20 -0
  196. package/dist/commonjs/utils/hashing/hash.js.map +1 -1
  197. package/dist/esm/ClientContext.d.ts +19 -10
  198. package/dist/esm/ClientContext.d.ts.map +1 -1
  199. package/dist/esm/ClientContext.js +30 -11
  200. package/dist/esm/ClientContext.js.map +1 -1
  201. package/dist/esm/CosmosClient.d.ts.map +1 -1
  202. package/dist/esm/CosmosClient.js +10 -2
  203. package/dist/esm/CosmosClient.js.map +1 -1
  204. package/dist/esm/PartitionKeyRangeFailoverInfo.d.ts +49 -0
  205. package/dist/esm/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
  206. package/dist/esm/PartitionKeyRangeFailoverInfo.js +130 -0
  207. package/dist/esm/PartitionKeyRangeFailoverInfo.js.map +1 -0
  208. package/dist/esm/client/ClientUtils.d.ts +3 -1
  209. package/dist/esm/client/ClientUtils.d.ts.map +1 -1
  210. package/dist/esm/client/ClientUtils.js +10 -0
  211. package/dist/esm/client/ClientUtils.js.map +1 -1
  212. package/dist/esm/client/Item/Item.d.ts.map +1 -1
  213. package/dist/esm/client/Item/Item.js +13 -0
  214. package/dist/esm/client/Item/Item.js.map +1 -1
  215. package/dist/esm/client/Item/Items.d.ts.map +1 -1
  216. package/dist/esm/client/Item/Items.js +19 -3
  217. package/dist/esm/client/Item/Items.js.map +1 -1
  218. package/dist/esm/common/constants.d.ts +20 -0
  219. package/dist/esm/common/constants.d.ts.map +1 -1
  220. package/dist/esm/common/constants.js +23 -1
  221. package/dist/esm/common/constants.js.map +1 -1
  222. package/dist/esm/common/platform.d.ts +6 -1
  223. package/dist/esm/common/platform.d.ts.map +1 -1
  224. package/dist/esm/common/platform.js +23 -4
  225. package/dist/esm/common/platform.js.map +1 -1
  226. package/dist/esm/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
  227. package/dist/esm/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
  228. package/dist/esm/diagnostics/DiagnosticNodeInternal.js.map +1 -1
  229. package/dist/esm/documents/ConnectionPolicy.d.ts +6 -0
  230. package/dist/esm/documents/ConnectionPolicy.d.ts.map +1 -1
  231. package/dist/esm/documents/ConnectionPolicy.js +2 -0
  232. package/dist/esm/documents/ConnectionPolicy.js.map +1 -1
  233. package/dist/esm/documents/DatabaseAccount.d.ts.map +1 -1
  234. package/dist/esm/documents/DatabaseAccount.js +3 -0
  235. package/dist/esm/documents/DatabaseAccount.js.map +1 -1
  236. package/dist/esm/extractPartitionKey.d.ts.map +1 -1
  237. package/dist/esm/extractPartitionKey.js +33 -20
  238. package/dist/esm/extractPartitionKey.js.map +1 -1
  239. package/dist/esm/globalEndpointManager.d.ts +6 -0
  240. package/dist/esm/globalEndpointManager.d.ts.map +1 -1
  241. package/dist/esm/globalEndpointManager.js +9 -4
  242. package/dist/esm/globalEndpointManager.js.map +1 -1
  243. package/dist/esm/globalPartitionEndpointManager.d.ts +79 -0
  244. package/dist/esm/globalPartitionEndpointManager.d.ts.map +1 -0
  245. package/dist/esm/globalPartitionEndpointManager.js +279 -0
  246. package/dist/esm/globalPartitionEndpointManager.js.map +1 -0
  247. package/dist/esm/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
  248. package/dist/esm/queryExecutionContext/Aggregators/index.js +1 -0
  249. package/dist/esm/queryExecutionContext/Aggregators/index.js.map +1 -1
  250. package/dist/esm/queryExecutionContext/documentProducer.d.ts +2 -3
  251. package/dist/esm/queryExecutionContext/documentProducer.d.ts.map +1 -1
  252. package/dist/esm/queryExecutionContext/documentProducer.js +16 -21
  253. package/dist/esm/queryExecutionContext/documentProducer.js.map +1 -1
  254. package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
  255. package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
  256. package/dist/esm/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
  257. package/dist/esm/queryIterator.js +1 -2
  258. package/dist/esm/queryIterator.js.map +1 -1
  259. package/dist/esm/request/ErrorResponse.d.ts +1 -1
  260. package/dist/esm/request/ErrorResponse.d.ts.map +1 -1
  261. package/dist/esm/request/ErrorResponse.js.map +1 -1
  262. package/dist/esm/request/RequestContext.d.ts +5 -0
  263. package/dist/esm/request/RequestContext.d.ts.map +1 -1
  264. package/dist/esm/request/RequestContext.js.map +1 -1
  265. package/dist/esm/request/RequestHandler.d.ts.map +1 -1
  266. package/dist/esm/request/RequestHandler.js +14 -4
  267. package/dist/esm/request/RequestHandler.js.map +1 -1
  268. package/dist/esm/request/defaultAgent.js +2 -2
  269. package/dist/esm/request/defaultAgent.js.map +1 -1
  270. package/dist/esm/retry/RetryPolicy.d.ts +2 -2
  271. package/dist/esm/retry/RetryPolicy.d.ts.map +1 -1
  272. package/dist/esm/retry/RetryPolicy.js.map +1 -1
  273. package/dist/esm/retry/defaultRetryPolicy.d.ts.map +1 -1
  274. package/dist/esm/retry/defaultRetryPolicy.js +4 -8
  275. package/dist/esm/retry/defaultRetryPolicy.js.map +1 -1
  276. package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
  277. package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
  278. package/dist/esm/retry/endpointDiscoveryRetryPolicy.js +9 -2
  279. package/dist/esm/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
  280. package/dist/esm/retry/retryUtility.d.ts.map +1 -1
  281. package/dist/esm/retry/retryUtility.js +11 -5
  282. package/dist/esm/retry/retryUtility.js.map +1 -1
  283. package/dist/esm/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
  284. package/dist/esm/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
  285. package/dist/esm/retry/timeoutFailoverRetryPolicy.js +12 -4
  286. package/dist/esm/retry/timeoutFailoverRetryPolicy.js.map +1 -1
  287. package/dist/esm/routing/partitionKeyRangeCache.d.ts.map +1 -1
  288. package/dist/esm/routing/partitionKeyRangeCache.js +11 -0
  289. package/dist/esm/routing/partitionKeyRangeCache.js.map +1 -1
  290. package/dist/esm/utils/checkURL.js +6 -0
  291. package/dist/esm/utils/checkURL.js.map +1 -1
  292. package/dist/esm/utils/hashing/hash.d.ts +2 -0
  293. package/dist/esm/utils/hashing/hash.d.ts.map +1 -1
  294. package/dist/esm/utils/hashing/hash.js +19 -0
  295. package/dist/esm/utils/hashing/hash.js.map +1 -1
  296. package/dist/react-native/ClientContext.d.ts +19 -10
  297. package/dist/react-native/ClientContext.d.ts.map +1 -1
  298. package/dist/react-native/ClientContext.js +30 -11
  299. package/dist/react-native/ClientContext.js.map +1 -1
  300. package/dist/react-native/CosmosClient.d.ts.map +1 -1
  301. package/dist/react-native/CosmosClient.js +10 -2
  302. package/dist/react-native/CosmosClient.js.map +1 -1
  303. package/dist/react-native/PartitionKeyRangeFailoverInfo.d.ts +49 -0
  304. package/dist/react-native/PartitionKeyRangeFailoverInfo.d.ts.map +1 -0
  305. package/dist/react-native/PartitionKeyRangeFailoverInfo.js +130 -0
  306. package/dist/react-native/PartitionKeyRangeFailoverInfo.js.map +1 -0
  307. package/dist/react-native/client/ClientUtils.d.ts +3 -1
  308. package/dist/react-native/client/ClientUtils.d.ts.map +1 -1
  309. package/dist/react-native/client/ClientUtils.js +10 -0
  310. package/dist/react-native/client/ClientUtils.js.map +1 -1
  311. package/dist/react-native/client/Item/Item.d.ts.map +1 -1
  312. package/dist/react-native/client/Item/Item.js +13 -0
  313. package/dist/react-native/client/Item/Item.js.map +1 -1
  314. package/dist/react-native/client/Item/Items.d.ts.map +1 -1
  315. package/dist/react-native/client/Item/Items.js +19 -3
  316. package/dist/react-native/client/Item/Items.js.map +1 -1
  317. package/dist/react-native/common/constants.d.ts +20 -0
  318. package/dist/react-native/common/constants.d.ts.map +1 -1
  319. package/dist/react-native/common/constants.js +23 -1
  320. package/dist/react-native/common/constants.js.map +1 -1
  321. package/dist/react-native/common/platform.d.ts +6 -1
  322. package/dist/react-native/common/platform.d.ts.map +1 -1
  323. package/dist/react-native/common/platform.js +23 -4
  324. package/dist/react-native/common/platform.js.map +1 -1
  325. package/dist/react-native/diagnostics/DiagnosticNodeInternal.d.ts +1 -0
  326. package/dist/react-native/diagnostics/DiagnosticNodeInternal.d.ts.map +1 -1
  327. package/dist/react-native/diagnostics/DiagnosticNodeInternal.js.map +1 -1
  328. package/dist/react-native/documents/ConnectionPolicy.d.ts +6 -0
  329. package/dist/react-native/documents/ConnectionPolicy.d.ts.map +1 -1
  330. package/dist/react-native/documents/ConnectionPolicy.js +2 -0
  331. package/dist/react-native/documents/ConnectionPolicy.js.map +1 -1
  332. package/dist/react-native/documents/DatabaseAccount.d.ts.map +1 -1
  333. package/dist/react-native/documents/DatabaseAccount.js +3 -0
  334. package/dist/react-native/documents/DatabaseAccount.js.map +1 -1
  335. package/dist/react-native/extractPartitionKey.d.ts.map +1 -1
  336. package/dist/react-native/extractPartitionKey.js +33 -20
  337. package/dist/react-native/extractPartitionKey.js.map +1 -1
  338. package/dist/react-native/globalEndpointManager.d.ts +6 -0
  339. package/dist/react-native/globalEndpointManager.d.ts.map +1 -1
  340. package/dist/react-native/globalEndpointManager.js +9 -4
  341. package/dist/react-native/globalEndpointManager.js.map +1 -1
  342. package/dist/react-native/globalPartitionEndpointManager.d.ts +79 -0
  343. package/dist/react-native/globalPartitionEndpointManager.d.ts.map +1 -0
  344. package/dist/react-native/globalPartitionEndpointManager.js +279 -0
  345. package/dist/react-native/globalPartitionEndpointManager.js.map +1 -0
  346. package/dist/react-native/queryExecutionContext/Aggregators/index.d.ts.map +1 -1
  347. package/dist/react-native/queryExecutionContext/Aggregators/index.js +1 -0
  348. package/dist/react-native/queryExecutionContext/Aggregators/index.js.map +1 -1
  349. package/dist/react-native/queryExecutionContext/documentProducer.d.ts +2 -3
  350. package/dist/react-native/queryExecutionContext/documentProducer.d.ts.map +1 -1
  351. package/dist/react-native/queryExecutionContext/documentProducer.js +16 -21
  352. package/dist/react-native/queryExecutionContext/documentProducer.js.map +1 -1
  353. package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.d.ts.map +1 -1
  354. package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.js +2 -1
  355. package/dist/react-native/queryExecutionContext/parallelQueryExecutionContextBase.js.map +1 -1
  356. package/dist/react-native/queryIterator.js +1 -2
  357. package/dist/react-native/queryIterator.js.map +1 -1
  358. package/dist/react-native/request/ErrorResponse.d.ts +1 -1
  359. package/dist/react-native/request/ErrorResponse.d.ts.map +1 -1
  360. package/dist/react-native/request/ErrorResponse.js.map +1 -1
  361. package/dist/react-native/request/RequestContext.d.ts +5 -0
  362. package/dist/react-native/request/RequestContext.d.ts.map +1 -1
  363. package/dist/react-native/request/RequestContext.js.map +1 -1
  364. package/dist/react-native/request/RequestHandler.d.ts.map +1 -1
  365. package/dist/react-native/request/RequestHandler.js +14 -4
  366. package/dist/react-native/request/RequestHandler.js.map +1 -1
  367. package/dist/react-native/request/defaultAgent.js +2 -2
  368. package/dist/react-native/request/defaultAgent.js.map +1 -1
  369. package/dist/react-native/retry/RetryPolicy.d.ts +2 -2
  370. package/dist/react-native/retry/RetryPolicy.d.ts.map +1 -1
  371. package/dist/react-native/retry/RetryPolicy.js.map +1 -1
  372. package/dist/react-native/retry/defaultRetryPolicy.d.ts.map +1 -1
  373. package/dist/react-native/retry/defaultRetryPolicy.js +4 -8
  374. package/dist/react-native/retry/defaultRetryPolicy.js.map +1 -1
  375. package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts +5 -3
  376. package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
  377. package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js +9 -2
  378. package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
  379. package/dist/react-native/retry/retryUtility.d.ts.map +1 -1
  380. package/dist/react-native/retry/retryUtility.js +11 -5
  381. package/dist/react-native/retry/retryUtility.js.map +1 -1
  382. package/dist/react-native/retry/timeoutFailoverRetryPolicy.d.ts +6 -3
  383. package/dist/react-native/retry/timeoutFailoverRetryPolicy.d.ts.map +1 -1
  384. package/dist/react-native/retry/timeoutFailoverRetryPolicy.js +12 -4
  385. package/dist/react-native/retry/timeoutFailoverRetryPolicy.js.map +1 -1
  386. package/dist/react-native/routing/partitionKeyRangeCache.d.ts.map +1 -1
  387. package/dist/react-native/routing/partitionKeyRangeCache.js +11 -0
  388. package/dist/react-native/routing/partitionKeyRangeCache.js.map +1 -1
  389. package/dist/react-native/utils/checkURL.js +6 -0
  390. package/dist/react-native/utils/checkURL.js.map +1 -1
  391. package/dist/react-native/utils/hashing/hash.d.ts +2 -0
  392. package/dist/react-native/utils/hashing/hash.d.ts.map +1 -1
  393. package/dist/react-native/utils/hashing/hash.js +19 -0
  394. package/dist/react-native/utils/hashing/hash.js.map +1 -1
  395. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"CosmosClient.js","sourceRoot":"","sources":["../../src/CosmosClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,a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CACzC,qBAA4C,EAC5C,WAAmB;QAEnB,IAAI,CAAC,iBAAiB,GAAG,WAAW,CAAC,GAAG,EAAE;YACxC,IAAI,CAAC;gBACH,OAAO,eAAe,CACpB,KAAK,EAAE,cAAsC,EAAE,EAAE;oBAC/C,OAAO,qBAAqB,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;gBACnE,CAAC,EACD,IAAI,CAAC,aAAa,EAClB,kBAAkB,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","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,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAE7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAA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AqB,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;gBACnE,CAAC,EACD,IAAI,CAAC,aAAa,EAClB,kBAAkB,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","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,130 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { Constants } from "./index.js";
4
+ import semaphore from "semaphore";
5
+ /**
6
+ * @hidden
7
+ * This class manages the failover information for partition key ranges in Cosmos DB.
8
+ * It tracks the current endpoint, failed endpoints, and the number of consecutive read/write request failures.
9
+ */
10
+ export class PartitionKeyRangeFailoverInfo {
11
+ /**
12
+ * @internal
13
+ */
14
+ constructor(currentEndpoint) {
15
+ this.failedEndPoints = [];
16
+ this.consecutiveReadRequestFailureCount = 0;
17
+ this.consecutiveWriteRequestFailureCount = 0;
18
+ this.firstRequestFailureTime = Date.now();
19
+ this.lastRequestFailureTime = Date.now();
20
+ this.currentEndPoint = currentEndpoint;
21
+ this.failureCountSemaphore = semaphore(1);
22
+ this.tryMoveNextLocationSemaphore = semaphore(1);
23
+ }
24
+ /**
25
+ * Checks if the circuit breaker can trigger a partition failover based on the failure counts.
26
+ * Returns true if the number of consecutive failures exceeds the defined thresholds for read or write requests.
27
+ */
28
+ async canCircuitBreakerTriggerPartitionFailOver(isReadOnlyRequest) {
29
+ const { consecutiveReadRequestFailureCount, consecutiveWriteRequestFailureCount } = await this.snapshotConsecutiveRequestFailureCount();
30
+ return isReadOnlyRequest
31
+ ? consecutiveReadRequestFailureCount > Constants.ReadRequestFailureCountThreshold
32
+ : consecutiveWriteRequestFailureCount > Constants.WriteRequestFailureCountThreshold;
33
+ }
34
+ /**
35
+ * Increments the failure counts for read or write requests and updates the timestamps.
36
+ * If the time since the last failure exceeds the reset window, it resets the failure counts.
37
+ */
38
+ async incrementRequestFailureCounts(isReadOnlyRequest, currentTimeInMilliseconds) {
39
+ return new Promise((resolve, reject) => {
40
+ this.failureCountSemaphore.take(async () => {
41
+ try {
42
+ const { lastRequestFailureTime } = await this.snapshotPartitionFailoverTimestamps();
43
+ if (currentTimeInMilliseconds - lastRequestFailureTime >
44
+ Constants.ConsecutiveFailureCountResetIntervalInMS) {
45
+ this.consecutiveReadRequestFailureCount = 0;
46
+ this.consecutiveWriteRequestFailureCount = 0;
47
+ }
48
+ if (isReadOnlyRequest) {
49
+ this.consecutiveReadRequestFailureCount++;
50
+ }
51
+ else {
52
+ this.consecutiveWriteRequestFailureCount++;
53
+ }
54
+ this.lastRequestFailureTime = currentTimeInMilliseconds;
55
+ return resolve();
56
+ }
57
+ catch (error) {
58
+ reject(error);
59
+ }
60
+ finally {
61
+ // Release the semaphore lock
62
+ this.failureCountSemaphore.leave();
63
+ }
64
+ });
65
+ });
66
+ }
67
+ /**
68
+ * Returns a snapshot of the first and last request failure timestamps.
69
+ * This method is used to retrieve the current state of failure timestamps without modifying them.
70
+ */
71
+ async snapshotPartitionFailoverTimestamps() {
72
+ return {
73
+ firstRequestFailureTime: this.firstRequestFailureTime,
74
+ lastRequestFailureTime: this.lastRequestFailureTime,
75
+ };
76
+ }
77
+ /**
78
+ * Attempts to move to the next available location for the partition key range.
79
+ * If the current endpoint is the same as the failed endpoint, it tries to find a new endpoint
80
+ * from the provided list of endpoints. If a new endpoint is found, it updates the current endpoint
81
+ * and returns true. If no new endpoint is found, it returns false.
82
+ */
83
+ async tryMoveNextLocation(endPoints, failedEndPoint, diagnosticNode, partitionKeyRangeId) {
84
+ if (failedEndPoint !== this.currentEndPoint) {
85
+ return true;
86
+ }
87
+ return new Promise((resolve, reject) => {
88
+ this.tryMoveNextLocationSemaphore.take(() => {
89
+ try {
90
+ for (const endpoint of endPoints) {
91
+ if (this.currentEndPoint === endpoint) {
92
+ continue;
93
+ }
94
+ if (this.failedEndPoints.includes(endpoint)) {
95
+ continue;
96
+ }
97
+ this.failedEndPoints.push(failedEndPoint);
98
+ this.currentEndPoint = endpoint;
99
+ return resolve(true);
100
+ }
101
+ diagnosticNode.addData({
102
+ partitionKeyRangeFailoverInfo: `PartitionKeyRangeId: ${partitionKeyRangeId}, failedLocations: ${this.failedEndPoints}, newLocation: ${this.currentEndPoint}`,
103
+ });
104
+ return resolve(false);
105
+ }
106
+ catch (err) {
107
+ reject(err);
108
+ }
109
+ finally {
110
+ this.tryMoveNextLocationSemaphore.leave();
111
+ }
112
+ });
113
+ });
114
+ }
115
+ /** Returns the current endpoint being used for partition key range operations.*/
116
+ getCurrentEndPoint() {
117
+ return this.currentEndPoint;
118
+ }
119
+ /**
120
+ * Returns a snapshot of the current consecutive request failure counts for read and write requests.
121
+ * This method is used to retrieve the current state of failure counts without modifying them.
122
+ */
123
+ async snapshotConsecutiveRequestFailureCount() {
124
+ return {
125
+ consecutiveReadRequestFailureCount: this.consecutiveReadRequestFailureCount,
126
+ consecutiveWriteRequestFailureCount: this.consecutiveWriteRequestFailureCount,
127
+ };
128
+ }
129
+ }
130
+ //# 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,OAAO,EAAE,SAAS,EAA0B,MAAM,YAAY,CAAC;AAC/D,OAAO,SAAS,MAAM,WAAW,CAAC;AA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c,CAAC,CAAC;wBAC1C,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;wBAChC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;oBACvB,CAAC;oBACD,cAAc,CAAC,OAAO,CAAC;wBACrB,6BAA6B,EAAE,wBAAwB,mBAAmB,sBAAsB,IAAI,CAAC,eAAe,kBAAkB,IAAI,CAAC,eAAe,EAAE;qBAC7J,CAAC,CAAC;oBACH,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;gBACxB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC;wBAAS,CAAC;oBACT,IAAI,CAAC,4BAA4B,CAAC,KAAK,EAAE,CAAC;gBAC5C,CAAC;YACH,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","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"}
@@ -4,4 +4,14 @@ export async function readPartitionKeyDefinition(diagnosticNode, container) {
4
4
  const partitionKeyDefinition = await container.readPartitionKeyDefinition(diagnosticNode);
5
5
  return partitionKeyDefinition.resource;
6
6
  }
7
+ export async function computePartitionKeyRangeId(diagnosticNode, partitionKey, partitionKeyRangeCache, isPartitionLevelFailOverEnabled, container, pKDefinition) {
8
+ let partitionKeyRangeId = undefined;
9
+ if (isPartitionLevelFailOverEnabled) {
10
+ const partitionKeyDefinition = pKDefinition !== null && pKDefinition !== void 0 ? pKDefinition : (await readPartitionKeyDefinition(diagnosticNode, container));
11
+ if (partitionKeyDefinition && partitionKey && partitionKey.length > 0) {
12
+ partitionKeyRangeId = await partitionKeyRangeCache.getPartitionKeyRangeIdFromPartitionKey(container.url, partitionKey, partitionKeyDefinition, diagnosticNode);
13
+ }
14
+ }
15
+ return partitionKeyRangeId;
16
+ }
7
17
  //# 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,MAAM,CAAC,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,MAAM,CAAC,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;AAED,MAAM,CAAC,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,C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,EACrC,IAAI,EAAE,CAAC,EACP,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IA8G3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACU,MAAM,CAAC,CAAC,SAAS,cAAc,GAAG,GAAG,EAChD,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAyE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -5,6 +5,7 @@ import { PatchOperationType } from "../../utils/patch.js";
5
5
  import { ItemResponse } from "./ItemResponse.js";
6
6
  import { getEmptyCosmosDiagnostics, withDiagnostics } from "../../utils/diagnostics.js";
7
7
  import { setPartitionKeyIfUndefined } from "../../extractPartitionKey.js";
8
+ import { computePartitionKeyRangeId } from "../ClientUtils.js";
8
9
  /**
9
10
  * Used to perform operations on a specific item.
10
11
  *
@@ -86,6 +87,8 @@ export class Item {
86
87
  }
87
88
  const path = getPathFromLink(url);
88
89
  const id = getIdFromLink(url);
90
+ const isPartitionLevelFailOverEnabled = this.clientContext.isPartitionLevelFailOverEnabled();
91
+ const partitionKeyRangeId = await computePartitionKeyRangeId(diagnosticNode, partitionKey, this.clientContext.partitionKeyRangeCache, isPartitionLevelFailOverEnabled, this.container);
89
92
  response = await this.clientContext.read({
90
93
  path,
91
94
  resourceType: ResourceType.item,
@@ -93,6 +96,7 @@ export class Item {
93
96
  options,
94
97
  partitionKey: partitionKey,
95
98
  diagnosticNode,
99
+ partitionKeyRangeId,
96
100
  });
97
101
  }
98
102
  catch (error) {
@@ -146,6 +150,8 @@ export class Item {
146
150
  }
147
151
  const path = getPathFromLink(url);
148
152
  const id = getIdFromLink(url);
153
+ const isPartitionLevelFailOverEnabled = this.clientContext.isPartitionLevelFailOverEnabled();
154
+ const partitionKeyRangeId = await computePartitionKeyRangeId(diagnosticNode, partitionKey, this.clientContext.partitionKeyRangeCache, isPartitionLevelFailOverEnabled, this.container);
149
155
  response = await this.clientContext.replace({
150
156
  body,
151
157
  path,
@@ -154,6 +160,7 @@ export class Item {
154
160
  options,
155
161
  partitionKey: partitionKey,
156
162
  diagnosticNode,
163
+ partitionKeyRangeId,
157
164
  });
158
165
  }
159
166
  catch (error) {
@@ -232,6 +239,8 @@ export class Item {
232
239
  }
233
240
  const path = getPathFromLink(url);
234
241
  const id = getIdFromLink(url);
242
+ const isPartitionLevelFailOverEnabled = this.clientContext.isPartitionLevelFailOverEnabled();
243
+ const partitionKeyRangeId = await computePartitionKeyRangeId(diagnosticNode, partitionKey, this.clientContext.partitionKeyRangeCache, isPartitionLevelFailOverEnabled, this.container);
235
244
  response = await this.clientContext.delete({
236
245
  path,
237
246
  resourceType: ResourceType.item,
@@ -239,6 +248,7 @@ export class Item {
239
248
  options,
240
249
  partitionKey: partitionKey,
241
250
  diagnosticNode,
251
+ partitionKeyRangeId,
242
252
  });
243
253
  }
244
254
  catch (error) {
@@ -332,6 +342,8 @@ export class Item {
332
342
  }
333
343
  const path = getPathFromLink(url);
334
344
  const id = getIdFromLink(url);
345
+ const isPartitionLevelFailOverEnabled = this.clientContext.isPartitionLevelFailOverEnabled();
346
+ const partitionKeyRangeId = await computePartitionKeyRangeId(diagnosticNode, partitionKey, this.clientContext.partitionKeyRangeCache, isPartitionLevelFailOverEnabled, this.container);
335
347
  response = await this.clientContext.patch({
336
348
  body,
337
349
  path,
@@ -340,6 +352,7 @@ export class Item {
340
352
  options,
341
353
  partitionKey: partitionKey,
342
354
  diagnosticNode,
355
+ partitionKeyRangeId,
343
356
  });
344
357
  }
345
358
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"Item.js","sourceRoot":"","sources":["../../../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AC,CAAC;IACzB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { ClientContext } from \"../../ClientContext.js\";\nimport type { DiagnosticNodeInternal } from \"../../diagnostics/DiagnosticNodeInternal.js\";\nimport {\n Constants,\n copyObject,\n createDocumentUri,\n getIdFromLink,\n getPathFromLink,\n isItemResourceValid,\n ResourceType,\n StatusCodes,\n} from \"../../common/index.js\";\nimport type { PartitionKey, PartitionKeyInternal } from \"../../documents/index.js\";\nimport { convertToInternalPartitionKey } from \"../../documents/index.js\";\nimport type { RequestOptions, Response } from \"../../request/index.js\";\nimport { ErrorResponse } from \"../../request/index.js\";\nimport type { PatchRequestBody } from \"../../utils/patch.js\";\nimport { PatchOperationType } from \"../../utils/patch.js\";\nimport type { Container } from \"../Container/index.js\";\nimport type { Resource } from \"../Resource.js\";\nimport type { ItemDefinition } from \"./ItemDefinition.js\";\nimport { ItemResponse } from \"./ItemResponse.js\";\nimport { getEmptyCosmosDiagnostics, withDiagnostics } from \"../../utils/diagnostics.js\";\nimport { setPartitionKeyIfUndefined } from \"../../extractPartitionKey.js\";\n\n/**\n * Used to perform operations on a specific item.\n *\n * @see {@link Items} for operations on all items; see `container.items`.\n */\nexport class Item {\n private partitionKey: PartitionKeyInternal;\n /**\n * Returns a reference URL to the resource. Used for linking in Permissions.\n */\n public get url(): string {\n return createDocumentUri(this.container.database.id, this.container.id, this.id);\n }\n\n /**\n * @hidden\n * @param container - The parent {@link Container}.\n * @param id - The id of the given {@link Item}.\n * @param partitionKey - The primary key of the given {@link Item} (only for partitioned containers).\n */\n constructor(\n public readonly container: Container,\n public readonly id: string,\n private readonly clientContext: ClientContext,\n partitionKey?: PartitionKey,\n ) {\n this.partitionKey =\n partitionKey === undefined ? undefined : convertToInternalPartitionKey(partitionKey);\n }\n\n /**\n * Read the item's definition.\n *\n * Any provided type, T, is not necessarily enforced by the SDK.\n * You may get more or less properties and it's up to your logic to enforce it.\n * If the type, T, is a class, it won't pass `typeof` comparisons, because it won't have a match prototype.\n * It's recommended to only use interfaces.\n *\n * There is no set schema for JSON items. They may contain any number of custom properties.\n *\n * @param options - Additional options for the request\n *\n * @example Using custom type for response\n * ```ts snippet:ItemRead\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 * const { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n *\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * interface TodoItem {\n * title: string;\n * done: boolean;\n * id: string;\n * }\n *\n * const { resource: item } = await container.item(\"id\", \"<pkValue>\").read<TodoItem>();\n * ```\n */\n public async read<T extends ItemDefinition = any>(\n options: RequestOptions = {},\n ): Promise<ItemResponse<T>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n this.partitionKey = await setPartitionKeyIfUndefined(\n diagnosticNode,\n this.container,\n this.partitionKey,\n );\n let url = this.url;\n let partitionKey = this.partitionKey;\n let response: Response<T & Resource>;\n try {\n if (this.clientContext.enableEncryption) {\n await this.container.checkAndInitializeEncryption();\n options.containerRid = this.container._rid;\n let count = 0;\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n );\n const { partitionKeyList: encryptedPartitionKey, encryptedCount } =\n await this.container.encryptionProcessor.getEncryptedPartitionKeyValue(\n this.partitionKey,\n );\n partitionKey = encryptedPartitionKey;\n count += encryptedCount;\n if (await this.container.encryptionProcessor.isPathEncrypted(\"/id\")) {\n url = await this.container.encryptionProcessor.getEncryptedUrl(this.url);\n count++;\n }\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n count,\n );\n }\n const path = getPathFromLink(url);\n const id = getIdFromLink(url);\n\n response = await this.clientContext.read<T>({\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n options,\n partitionKey: partitionKey,\n diagnosticNode,\n });\n } catch (error: any) {\n if (this.clientContext.enableEncryption) {\n await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);\n }\n if (error.code !== StatusCodes.NotFound) {\n throw error;\n }\n response = error;\n }\n if (this.clientContext.enableEncryption) {\n diagnosticNode.beginEncryptionDiagnostics(Constants.Encryption.DiagnosticsDecryptOperation);\n const { body, propertiesDecryptedCount } = await this.container.encryptionProcessor.decrypt(\n response.result,\n );\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n propertiesDecryptedCount,\n );\n response.result = body;\n }\n return new ItemResponse(\n response.result,\n response.headers,\n response.code,\n response.substatus,\n this,\n getEmptyCosmosDiagnostics(),\n );\n }, this.clientContext);\n }\n\n /**\n * Replace the item's definition.\n *\n * There is no set schema for JSON items. They may contain any number of custom properties.\n *\n * @param body - The definition to replace the existing {@link Item}'s definition with.\n * @param options - Additional options for the request\n * @example\n * ```ts snippet:ItemReplaceItemDefinition\n * import { CosmosClient, ItemDefinition } 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 { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * const item: ItemDefinition = {\n * id: \"id\",\n * title: \"new_title\",\n * };\n *\n * const { resource: replacedItem } = await container.item(\"id\").replace(item);\n * ```\n */\n\n public replace(\n body: ItemDefinition,\n options?: RequestOptions,\n ): Promise<ItemResponse<ItemDefinition>>;\n /**\n * Replace the item's definition.\n *\n * Any provided type, T, is not necessarily enforced by the SDK.\n * You may get more or less properties and it's up to your logic to enforce it.\n *\n * There is no set schema for JSON items. They may contain any number of custom properties.\n *\n * @param body - The definition to replace the existing {@link Item}'s definition with.\n * @param options - Additional options for the request\n * @example\n * ```ts snippet:ItemReplace\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 * const { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n *\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * interface TodoItem {\n * title: string;\n * done: boolean;\n * id: string;\n * }\n *\n * const { resource: item } = await container.item(\"id\", \"<pkValue>\").read<TodoItem>();\n *\n * item.done = true;\n * const { resource: replacedItem } = await container.item(\"id\").replace<TodoItem>(item);\n * ```\n */\n public replace<T extends ItemDefinition>(\n body: T,\n options?: RequestOptions,\n ): Promise<ItemResponse<T>>;\n public async replace<T extends ItemDefinition>(\n body: T,\n options: RequestOptions = {},\n ): Promise<ItemResponse<T>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n this.partitionKey = await setPartitionKeyIfUndefined(\n diagnosticNode,\n this.container,\n this.partitionKey,\n );\n let partitionKey = this.partitionKey;\n const err = {};\n if (!isItemResourceValid(body, err)) {\n throw err;\n }\n let url = this.url;\n\n let response: Response<T & Resource>;\n try {\n if (this.clientContext.enableEncryption) {\n // returns copy to avoid encryption of original body passed\n body = copyObject(body);\n options = options || {};\n await this.container.checkAndInitializeEncryption();\n options.containerRid = this.container._rid;\n let count = 0;\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n );\n const { body: encryptedBody, propertiesEncryptedCount } =\n await this.container.encryptionProcessor.encrypt(body);\n body = encryptedBody;\n count += propertiesEncryptedCount;\n const { partitionKeyList: encryptedPartitionKeyList, encryptedCount } =\n await this.container.encryptionProcessor.getEncryptedPartitionKeyValue(\n this.partitionKey,\n );\n partitionKey = encryptedPartitionKeyList;\n count += encryptedCount;\n if (await this.container.encryptionProcessor.isPathEncrypted(\"/id\")) {\n url = await this.container.encryptionProcessor.getEncryptedUrl(this.url);\n count++;\n }\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n count,\n );\n }\n const path = getPathFromLink(url);\n const id = getIdFromLink(url);\n\n response = await this.clientContext.replace<T>({\n body,\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n options,\n partitionKey: partitionKey,\n diagnosticNode,\n });\n } catch (error: any) {\n if (this.clientContext.enableEncryption) {\n await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);\n }\n throw error;\n }\n if (this.clientContext.enableEncryption) {\n try {\n // try block for decrypting response. This is done so that we can throw special error message in case of decryption failure\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n );\n const { body: result, propertiesDecryptedCount } =\n await this.container.encryptionProcessor.decrypt(response.result);\n response.result = result;\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n propertiesDecryptedCount,\n );\n } catch (error) {\n const decryptionError = new ErrorResponse(\n `Item replace operation was successful but response decryption failed: + ${error.message}`,\n );\n decryptionError.code = StatusCodes.ServiceUnavailable;\n throw decryptionError;\n }\n }\n return new ItemResponse(\n response.result,\n response.headers,\n response.code,\n response.substatus,\n this,\n getEmptyCosmosDiagnostics(),\n );\n }, this.clientContext);\n }\n\n /**\n * Delete the item.\n *\n * Any provided type, T, is not necessarily enforced by the SDK.\n * You may get more or less properties and it's up to your logic to enforce it.\n *\n * @param options - Additional options for the request\n * @example\n * ```ts snippet:ItemDelete\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 * const { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n *\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * interface TodoItem {\n * title: string;\n * done: boolean;\n * id: string;\n * }\n *\n * const { resource: item } = await container.item(\"id\", \"<pkValue>\").read<TodoItem>();\n *\n * await container.item(\"id\").delete<TodoItem>();\n * ```\n */\n public async delete<T extends ItemDefinition = any>(\n options: RequestOptions = {},\n ): Promise<ItemResponse<T>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n this.partitionKey = await setPartitionKeyIfUndefined(\n diagnosticNode,\n this.container,\n this.partitionKey,\n );\n let partitionKey = this.partitionKey;\n let url = this.url;\n let response: Response<T & Resource>;\n try {\n if (this.clientContext.enableEncryption) {\n await this.container.checkAndInitializeEncryption();\n options.containerRid = this.container._rid;\n let count = 0;\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n );\n const { partitionKeyList, encryptedCount } =\n await this.container.encryptionProcessor.getEncryptedPartitionKeyValue(\n this.partitionKey,\n );\n partitionKey = partitionKeyList;\n count += encryptedCount;\n if (await this.container.encryptionProcessor.isPathEncrypted(\"/id\")) {\n url = await this.container.encryptionProcessor.getEncryptedUrl(this.url);\n count++;\n }\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n count,\n );\n }\n const path = getPathFromLink(url);\n const id = getIdFromLink(url);\n\n response = await this.clientContext.delete<T>({\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n options,\n partitionKey: partitionKey,\n diagnosticNode,\n });\n } catch (error: any) {\n if (this.clientContext.enableEncryption) {\n await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);\n }\n throw error;\n }\n\n return new ItemResponse(\n response.result,\n response.headers,\n response.code,\n response.substatus,\n this,\n getEmptyCosmosDiagnostics(),\n );\n }, this.clientContext);\n }\n\n /**\n * Perform a JSONPatch on the item.\n *\n * Any provided type, T, is not necessarily enforced by the SDK.\n * You may get more or less properties and it's up to your logic to enforce it.\n *\n * @param options - Additional options for the request\n * @example\n * ```ts snippet:ItemPatch\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 * interface TodoItem {\n * title: string;\n * done: boolean;\n * id: string;\n * }\n *\n * const { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n *\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * const { resource: item } = await container.item(\"id\", \"<pkValue>\").read<TodoItem>();\n *\n * const { resource: patchedItem } = await container.item(\"id\").patch<TodoItem>([\n * {\n * op: \"replace\", // Operation type (can be replace, add, remove, set, incr)\n * path: \"/title\", // The path to the property to update\n * value: \"new-title\", // New value for the property\n * },\n * {\n * op: \"remove\",\n * path: \"/done\",\n * },\n * ]);\n * ```\n */\n public async patch<T extends ItemDefinition = any>(\n body: PatchRequestBody,\n options: RequestOptions = {},\n ): Promise<ItemResponse<T>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n this.partitionKey = await setPartitionKeyIfUndefined(\n diagnosticNode,\n this.container,\n this.partitionKey,\n );\n let url = this.url;\n let partitionKey = this.partitionKey;\n let response: Response<T & Resource>;\n try {\n if (this.clientContext.enableEncryption) {\n await this.container.checkAndInitializeEncryption();\n options.containerRid = this.container._rid;\n // returns copy to avoid encryption of original body passed\n body = copyObject(body);\n const operations = Array.isArray(body) ? body : body.operations;\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n );\n let propertiesEncryptedCount = 0;\n for (const operation of operations) {\n if (operation.op === PatchOperationType.remove) {\n continue;\n }\n const isPathEncrypted = await this.container.encryptionProcessor.isPathEncrypted(\n operation.path,\n );\n if (!isPathEncrypted) {\n continue;\n }\n if (operation.op === PatchOperationType.incr) {\n throw new ErrorResponse(\n `Increment patch operation is not allowed for encrypted path '${operation.path}'`,\n );\n }\n if (\"value\" in operation) {\n operation.value = await this.container.encryptionProcessor.encryptProperty(\n operation.path,\n operation.value,\n );\n }\n propertiesEncryptedCount++;\n }\n const { partitionKeyList, encryptedCount } =\n await this.container.encryptionProcessor.getEncryptedPartitionKeyValue(partitionKey);\n partitionKey = partitionKeyList;\n propertiesEncryptedCount += encryptedCount;\n if (await this.container.encryptionProcessor.isPathEncrypted(\"/id\")) {\n url = await this.container.encryptionProcessor.getEncryptedUrl(this.url);\n propertiesEncryptedCount++;\n }\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n propertiesEncryptedCount,\n );\n }\n const path = getPathFromLink(url);\n const id = getIdFromLink(url);\n response = await this.clientContext.patch<T>({\n body,\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n options,\n partitionKey: partitionKey,\n diagnosticNode,\n });\n } catch (error: any) {\n if (this.clientContext.enableEncryption) {\n await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);\n }\n throw error;\n }\n if (this.clientContext.enableEncryption) {\n try {\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n );\n const { body: result, propertiesDecryptedCount } =\n await this.container.encryptionProcessor.decrypt(response.result);\n response.result = result;\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n propertiesDecryptedCount,\n );\n } catch (error) {\n const decryptionError = new ErrorResponse(\n `Item patch operation was successful but response decryption failed: + ${error.message}`,\n );\n decryptionError.code = StatusCodes.ServiceUnavailable;\n throw decryptionError;\n }\n }\n\n return new ItemResponse(\n response.result,\n response.headers,\n response.code,\n response.substatus,\n this,\n getEmptyCosmosDiagnostics(),\n );\n }, this.clientContext);\n }\n}\n"]}
1
+ {"version":3,"file":"Item.js","sourceRoot":"","sources":["../../../../src/client/Item/Item.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OA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E,wBAAwB,EAAE,GAC9C,MAAM,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBACpE,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;oBACzB,cAAc,CAAC,wBAAwB,CACrC,SAAS,CAAC,UAAU,CAAC,2BAA2B,EAChD,wBAAwB,CACzB,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,eAAe,GAAG,IAAI,aAAa,CACvC,yEAAyE,KAAK,CAAC,OAAO,EAAE,CACzF,CAAC;oBACF,eAAe,CAAC,IAAI,GAAG,WAAW,CAAC,kBAAkB,CAAC;oBACtD,MAAM,eAAe,CAAC;gBACxB,CAAC;YACH,CAAC;YAED,OAAO,IAAI,YAAY,CACrB,QAAQ,CAAC,MAAM,EACf,QAAQ,CAAC,OAAO,EAChB,QAAQ,CAAC,IAAI,EACb,QAAQ,CAAC,SAAS,EAClB,IAAI,EACJ,yBAAyB,EAAE,CAC5B,CAAC;QACJ,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACzB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { ClientContext } from \"../../ClientContext.js\";\nimport type { DiagnosticNodeInternal } from \"../../diagnostics/DiagnosticNodeInternal.js\";\nimport {\n Constants,\n copyObject,\n createDocumentUri,\n getIdFromLink,\n getPathFromLink,\n isItemResourceValid,\n ResourceType,\n StatusCodes,\n} from \"../../common/index.js\";\nimport type { PartitionKey, PartitionKeyInternal } from \"../../documents/index.js\";\nimport { convertToInternalPartitionKey } from \"../../documents/index.js\";\nimport type { RequestOptions, Response } from \"../../request/index.js\";\nimport { ErrorResponse } from \"../../request/index.js\";\nimport type { PatchRequestBody } from \"../../utils/patch.js\";\nimport { PatchOperationType } from \"../../utils/patch.js\";\nimport type { Container } from \"../Container/index.js\";\nimport type { Resource } from \"../Resource.js\";\nimport type { ItemDefinition } from \"./ItemDefinition.js\";\nimport { ItemResponse } from \"./ItemResponse.js\";\nimport { getEmptyCosmosDiagnostics, withDiagnostics } from \"../../utils/diagnostics.js\";\nimport { setPartitionKeyIfUndefined } from \"../../extractPartitionKey.js\";\nimport { computePartitionKeyRangeId } from \"../ClientUtils.js\";\n\n/**\n * Used to perform operations on a specific item.\n *\n * @see {@link Items} for operations on all items; see `container.items`.\n */\nexport class Item {\n private partitionKey: PartitionKeyInternal;\n /**\n * Returns a reference URL to the resource. Used for linking in Permissions.\n */\n public get url(): string {\n return createDocumentUri(this.container.database.id, this.container.id, this.id);\n }\n\n /**\n * @hidden\n * @param container - The parent {@link Container}.\n * @param id - The id of the given {@link Item}.\n * @param partitionKey - The primary key of the given {@link Item} (only for partitioned containers).\n */\n constructor(\n public readonly container: Container,\n public readonly id: string,\n private readonly clientContext: ClientContext,\n partitionKey?: PartitionKey,\n ) {\n this.partitionKey =\n partitionKey === undefined ? undefined : convertToInternalPartitionKey(partitionKey);\n }\n\n /**\n * Read the item's definition.\n *\n * Any provided type, T, is not necessarily enforced by the SDK.\n * You may get more or less properties and it's up to your logic to enforce it.\n * If the type, T, is a class, it won't pass `typeof` comparisons, because it won't have a match prototype.\n * It's recommended to only use interfaces.\n *\n * There is no set schema for JSON items. They may contain any number of custom properties.\n *\n * @param options - Additional options for the request\n *\n * @example Using custom type for response\n * ```ts snippet:ItemRead\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 * const { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n *\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * interface TodoItem {\n * title: string;\n * done: boolean;\n * id: string;\n * }\n *\n * const { resource: item } = await container.item(\"id\", \"<pkValue>\").read<TodoItem>();\n * ```\n */\n public async read<T extends ItemDefinition = any>(\n options: RequestOptions = {},\n ): Promise<ItemResponse<T>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n this.partitionKey = await setPartitionKeyIfUndefined(\n diagnosticNode,\n this.container,\n this.partitionKey,\n );\n let url = this.url;\n let partitionKey = this.partitionKey;\n let response: Response<T & Resource>;\n try {\n if (this.clientContext.enableEncryption) {\n await this.container.checkAndInitializeEncryption();\n options.containerRid = this.container._rid;\n let count = 0;\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n );\n const { partitionKeyList: encryptedPartitionKey, encryptedCount } =\n await this.container.encryptionProcessor.getEncryptedPartitionKeyValue(\n this.partitionKey,\n );\n partitionKey = encryptedPartitionKey;\n count += encryptedCount;\n if (await this.container.encryptionProcessor.isPathEncrypted(\"/id\")) {\n url = await this.container.encryptionProcessor.getEncryptedUrl(this.url);\n count++;\n }\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n count,\n );\n }\n const path = getPathFromLink(url);\n const id = getIdFromLink(url);\n\n const isPartitionLevelFailOverEnabled =\n this.clientContext.isPartitionLevelFailOverEnabled();\n const partitionKeyRangeId = await computePartitionKeyRangeId(\n diagnosticNode,\n partitionKey,\n this.clientContext.partitionKeyRangeCache,\n isPartitionLevelFailOverEnabled,\n this.container,\n );\n\n response = await this.clientContext.read<T>({\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n options,\n partitionKey: partitionKey,\n diagnosticNode,\n partitionKeyRangeId,\n });\n } catch (error: any) {\n if (this.clientContext.enableEncryption) {\n await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);\n }\n if (error.code !== StatusCodes.NotFound) {\n throw error;\n }\n response = error;\n }\n if (this.clientContext.enableEncryption) {\n diagnosticNode.beginEncryptionDiagnostics(Constants.Encryption.DiagnosticsDecryptOperation);\n const { body, propertiesDecryptedCount } = await this.container.encryptionProcessor.decrypt(\n response.result,\n );\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n propertiesDecryptedCount,\n );\n response.result = body;\n }\n return new ItemResponse(\n response.result,\n response.headers,\n response.code,\n response.substatus,\n this,\n getEmptyCosmosDiagnostics(),\n );\n }, this.clientContext);\n }\n\n /**\n * Replace the item's definition.\n *\n * There is no set schema for JSON items. They may contain any number of custom properties.\n *\n * @param body - The definition to replace the existing {@link Item}'s definition with.\n * @param options - Additional options for the request\n * @example\n * ```ts snippet:ItemReplaceItemDefinition\n * import { CosmosClient, ItemDefinition } 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 { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * const item: ItemDefinition = {\n * id: \"id\",\n * title: \"new_title\",\n * };\n *\n * const { resource: replacedItem } = await container.item(\"id\").replace(item);\n * ```\n */\n\n public replace(\n body: ItemDefinition,\n options?: RequestOptions,\n ): Promise<ItemResponse<ItemDefinition>>;\n /**\n * Replace the item's definition.\n *\n * Any provided type, T, is not necessarily enforced by the SDK.\n * You may get more or less properties and it's up to your logic to enforce it.\n *\n * There is no set schema for JSON items. They may contain any number of custom properties.\n *\n * @param body - The definition to replace the existing {@link Item}'s definition with.\n * @param options - Additional options for the request\n * @example\n * ```ts snippet:ItemReplace\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 * const { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n *\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * interface TodoItem {\n * title: string;\n * done: boolean;\n * id: string;\n * }\n *\n * const { resource: item } = await container.item(\"id\", \"<pkValue>\").read<TodoItem>();\n *\n * item.done = true;\n * const { resource: replacedItem } = await container.item(\"id\").replace<TodoItem>(item);\n * ```\n */\n public replace<T extends ItemDefinition>(\n body: T,\n options?: RequestOptions,\n ): Promise<ItemResponse<T>>;\n public async replace<T extends ItemDefinition>(\n body: T,\n options: RequestOptions = {},\n ): Promise<ItemResponse<T>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n this.partitionKey = await setPartitionKeyIfUndefined(\n diagnosticNode,\n this.container,\n this.partitionKey,\n );\n let partitionKey = this.partitionKey;\n const err = {};\n if (!isItemResourceValid(body, err)) {\n throw err;\n }\n let url = this.url;\n\n let response: Response<T & Resource>;\n try {\n if (this.clientContext.enableEncryption) {\n // returns copy to avoid encryption of original body passed\n body = copyObject(body);\n options = options || {};\n await this.container.checkAndInitializeEncryption();\n options.containerRid = this.container._rid;\n let count = 0;\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n );\n const { body: encryptedBody, propertiesEncryptedCount } =\n await this.container.encryptionProcessor.encrypt(body);\n body = encryptedBody;\n count += propertiesEncryptedCount;\n const { partitionKeyList: encryptedPartitionKeyList, encryptedCount } =\n await this.container.encryptionProcessor.getEncryptedPartitionKeyValue(\n this.partitionKey,\n );\n partitionKey = encryptedPartitionKeyList;\n count += encryptedCount;\n if (await this.container.encryptionProcessor.isPathEncrypted(\"/id\")) {\n url = await this.container.encryptionProcessor.getEncryptedUrl(this.url);\n count++;\n }\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n count,\n );\n }\n const path = getPathFromLink(url);\n const id = getIdFromLink(url);\n\n const isPartitionLevelFailOverEnabled =\n this.clientContext.isPartitionLevelFailOverEnabled();\n const partitionKeyRangeId = await computePartitionKeyRangeId(\n diagnosticNode,\n partitionKey,\n this.clientContext.partitionKeyRangeCache,\n isPartitionLevelFailOverEnabled,\n this.container,\n );\n\n response = await this.clientContext.replace<T>({\n body,\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n options,\n partitionKey: partitionKey,\n diagnosticNode,\n partitionKeyRangeId,\n });\n } catch (error: any) {\n if (this.clientContext.enableEncryption) {\n await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);\n }\n throw error;\n }\n if (this.clientContext.enableEncryption) {\n try {\n // try block for decrypting response. This is done so that we can throw special error message in case of decryption failure\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n );\n const { body: result, propertiesDecryptedCount } =\n await this.container.encryptionProcessor.decrypt(response.result);\n response.result = result;\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n propertiesDecryptedCount,\n );\n } catch (error) {\n const decryptionError = new ErrorResponse(\n `Item replace operation was successful but response decryption failed: + ${error.message}`,\n );\n decryptionError.code = StatusCodes.ServiceUnavailable;\n throw decryptionError;\n }\n }\n return new ItemResponse(\n response.result,\n response.headers,\n response.code,\n response.substatus,\n this,\n getEmptyCosmosDiagnostics(),\n );\n }, this.clientContext);\n }\n\n /**\n * Delete the item.\n *\n * Any provided type, T, is not necessarily enforced by the SDK.\n * You may get more or less properties and it's up to your logic to enforce it.\n *\n * @param options - Additional options for the request\n * @example\n * ```ts snippet:ItemDelete\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 * const { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n *\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * interface TodoItem {\n * title: string;\n * done: boolean;\n * id: string;\n * }\n *\n * const { resource: item } = await container.item(\"id\", \"<pkValue>\").read<TodoItem>();\n *\n * await container.item(\"id\").delete<TodoItem>();\n * ```\n */\n public async delete<T extends ItemDefinition = any>(\n options: RequestOptions = {},\n ): Promise<ItemResponse<T>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n this.partitionKey = await setPartitionKeyIfUndefined(\n diagnosticNode,\n this.container,\n this.partitionKey,\n );\n let partitionKey = this.partitionKey;\n let url = this.url;\n let response: Response<T & Resource>;\n try {\n if (this.clientContext.enableEncryption) {\n await this.container.checkAndInitializeEncryption();\n options.containerRid = this.container._rid;\n let count = 0;\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n );\n const { partitionKeyList, encryptedCount } =\n await this.container.encryptionProcessor.getEncryptedPartitionKeyValue(\n this.partitionKey,\n );\n partitionKey = partitionKeyList;\n count += encryptedCount;\n if (await this.container.encryptionProcessor.isPathEncrypted(\"/id\")) {\n url = await this.container.encryptionProcessor.getEncryptedUrl(this.url);\n count++;\n }\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n count,\n );\n }\n const path = getPathFromLink(url);\n const id = getIdFromLink(url);\n\n const isPartitionLevelFailOverEnabled =\n this.clientContext.isPartitionLevelFailOverEnabled();\n const partitionKeyRangeId = await computePartitionKeyRangeId(\n diagnosticNode,\n partitionKey,\n this.clientContext.partitionKeyRangeCache,\n isPartitionLevelFailOverEnabled,\n this.container,\n );\n\n response = await this.clientContext.delete<T>({\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n options,\n partitionKey: partitionKey,\n diagnosticNode,\n partitionKeyRangeId,\n });\n } catch (error: any) {\n if (this.clientContext.enableEncryption) {\n await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);\n }\n throw error;\n }\n\n return new ItemResponse(\n response.result,\n response.headers,\n response.code,\n response.substatus,\n this,\n getEmptyCosmosDiagnostics(),\n );\n }, this.clientContext);\n }\n\n /**\n * Perform a JSONPatch on the item.\n *\n * Any provided type, T, is not necessarily enforced by the SDK.\n * You may get more or less properties and it's up to your logic to enforce it.\n *\n * @param options - Additional options for the request\n * @example\n * ```ts snippet:ItemPatch\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 * interface TodoItem {\n * title: string;\n * done: boolean;\n * id: string;\n * }\n *\n * const { database } = await client.databases.createIfNotExists({ id: \"Test Database\" });\n *\n * const { container } = await database.containers.createIfNotExists({ id: \"Test Container\" });\n *\n * const { resource: item } = await container.item(\"id\", \"<pkValue>\").read<TodoItem>();\n *\n * const { resource: patchedItem } = await container.item(\"id\").patch<TodoItem>([\n * {\n * op: \"replace\", // Operation type (can be replace, add, remove, set, incr)\n * path: \"/title\", // The path to the property to update\n * value: \"new-title\", // New value for the property\n * },\n * {\n * op: \"remove\",\n * path: \"/done\",\n * },\n * ]);\n * ```\n */\n public async patch<T extends ItemDefinition = any>(\n body: PatchRequestBody,\n options: RequestOptions = {},\n ): Promise<ItemResponse<T>> {\n return withDiagnostics(async (diagnosticNode: DiagnosticNodeInternal) => {\n this.partitionKey = await setPartitionKeyIfUndefined(\n diagnosticNode,\n this.container,\n this.partitionKey,\n );\n let url = this.url;\n let partitionKey = this.partitionKey;\n let response: Response<T & Resource>;\n try {\n if (this.clientContext.enableEncryption) {\n await this.container.checkAndInitializeEncryption();\n options.containerRid = this.container._rid;\n // returns copy to avoid encryption of original body passed\n body = copyObject(body);\n const operations = Array.isArray(body) ? body : body.operations;\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n );\n let propertiesEncryptedCount = 0;\n for (const operation of operations) {\n if (operation.op === PatchOperationType.remove) {\n continue;\n }\n const isPathEncrypted = await this.container.encryptionProcessor.isPathEncrypted(\n operation.path,\n );\n if (!isPathEncrypted) {\n continue;\n }\n if (operation.op === PatchOperationType.incr) {\n throw new ErrorResponse(\n `Increment patch operation is not allowed for encrypted path '${operation.path}'`,\n );\n }\n if (\"value\" in operation) {\n operation.value = await this.container.encryptionProcessor.encryptProperty(\n operation.path,\n operation.value,\n );\n }\n propertiesEncryptedCount++;\n }\n const { partitionKeyList, encryptedCount } =\n await this.container.encryptionProcessor.getEncryptedPartitionKeyValue(partitionKey);\n partitionKey = partitionKeyList;\n propertiesEncryptedCount += encryptedCount;\n if (await this.container.encryptionProcessor.isPathEncrypted(\"/id\")) {\n url = await this.container.encryptionProcessor.getEncryptedUrl(this.url);\n propertiesEncryptedCount++;\n }\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsEncryptOperation,\n propertiesEncryptedCount,\n );\n }\n const path = getPathFromLink(url);\n const id = getIdFromLink(url);\n\n const isPartitionLevelFailOverEnabled =\n this.clientContext.isPartitionLevelFailOverEnabled();\n const partitionKeyRangeId = await computePartitionKeyRangeId(\n diagnosticNode,\n partitionKey,\n this.clientContext.partitionKeyRangeCache,\n isPartitionLevelFailOverEnabled,\n this.container,\n );\n\n response = await this.clientContext.patch<T>({\n body,\n path,\n resourceType: ResourceType.item,\n resourceId: id,\n options,\n partitionKey: partitionKey,\n diagnosticNode,\n partitionKeyRangeId,\n });\n } catch (error: any) {\n if (this.clientContext.enableEncryption) {\n await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);\n }\n throw error;\n }\n if (this.clientContext.enableEncryption) {\n try {\n diagnosticNode.beginEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n );\n const { body: result, propertiesDecryptedCount } =\n await this.container.encryptionProcessor.decrypt(response.result);\n response.result = result;\n diagnosticNode.endEncryptionDiagnostics(\n Constants.Encryption.DiagnosticsDecryptOperation,\n propertiesDecryptedCount,\n );\n } catch (error) {\n const decryptionError = new ErrorResponse(\n `Item patch operation was successful but response decryption failed: + ${error.message}`,\n );\n decryptionError.code = StatusCodes.ServiceUnavailable;\n throw decryptionError;\n }\n }\n\n return new ItemResponse(\n response.result,\n response.headers,\n response.code,\n response.substatus,\n this,\n getEmptyCosmosDiagnostics(),\n );\n }, this.clientContext);\n }\n}\n"]}