oxygen-cli 1.40.2-beta.1 → 1.41.0

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 (442) hide show
  1. package/CHANGELOG.md +1755 -1742
  2. package/LICENSE +672 -672
  3. package/README.md +37 -37
  4. package/build/core/OxygenCore.js +1 -1
  5. package/build/core/OxygenEvents.js +1 -1
  6. package/build/core/OxygenModule.js +1 -1
  7. package/build/core/OxygenService.js +1 -1
  8. package/build/core/OxygenSubModule.js +1 -1
  9. package/build/core/WebDriverModule.js +1 -1
  10. package/build/core/utils.js +1 -1
  11. package/build/errors/HookError.js +1 -1
  12. package/build/errors/ModuleError.js +1 -1
  13. package/build/errors/ModuleUnavailableError.js +1 -1
  14. package/build/errors/OxygenError.js +1 -1
  15. package/build/errors/ScriptNotFound.js +1 -1
  16. package/build/errors/helper.js +1 -1
  17. package/build/index.js +1 -1
  18. package/build/lib/cli-util.js +1 -1
  19. package/build/lib/cli.js +1 -1
  20. package/build/lib/debugger.js +1 -1
  21. package/build/lib/img-merge.js +1 -1
  22. package/build/lib/launcher.js +1 -1
  23. package/build/lib/logger.js +43 -43
  24. package/build/lib/moduleRequire.js +1 -1
  25. package/build/lib/parallel-launcher.js +1 -1
  26. package/build/lib/param-manager.js +1 -1
  27. package/build/lib/param-reader-csv.js +1 -1
  28. package/build/lib/param-reader-excel.js +1 -1
  29. package/build/lib/param-reader-json.js +1 -1
  30. package/build/lib/text-to-image.js +1 -1
  31. package/build/lib/util.js +1 -1
  32. package/build/model/case-result.js +1 -1
  33. package/build/model/failure.js +1 -1
  34. package/build/model/status.js +1 -1
  35. package/build/model/step-result.js +1 -1
  36. package/build/model/suite-result.js +1 -1
  37. package/build/model/test-result.js +1 -1
  38. package/build/model/testcase.js +1 -1
  39. package/build/model/testsuite.js +1 -1
  40. package/build/ox_modules/index.js +1 -1
  41. package/build/ox_modules/module-assert.js +37 -37
  42. package/build/ox_modules/module-date.js +24 -24
  43. package/build/ox_modules/module-db.js +52 -52
  44. package/build/ox_modules/module-email.js +59 -59
  45. package/build/ox_modules/module-eyes.js +34 -34
  46. package/build/ox_modules/module-http/ntlm-util.js +10 -10
  47. package/build/ox_modules/module-http/ntlm.js +15 -15
  48. package/build/ox_modules/module-http.js +132 -132
  49. package/build/ox_modules/module-log.js +27 -27
  50. package/build/ox_modules/module-mailinator.js +87 -87
  51. package/build/ox_modules/module-mob/commands/alertAccept.js +17 -17
  52. package/build/ox_modules/module-mob/commands/alertDismiss.js +17 -17
  53. package/build/ox_modules/module-mob/commands/assertAlert.js +20 -20
  54. package/build/ox_modules/module-mob/commands/assertText.js +21 -21
  55. package/build/ox_modules/module-mob/commands/assertTitle.js +19 -19
  56. package/build/ox_modules/module-mob/commands/assertValue.js +18 -18
  57. package/build/ox_modules/module-mob/commands/back.js +16 -16
  58. package/build/ox_modules/module-mob/commands/clear.js +19 -19
  59. package/build/ox_modules/module-mob/commands/click.js +17 -17
  60. package/build/ox_modules/module-mob/commands/clickHidden.js +17 -17
  61. package/build/ox_modules/module-mob/commands/clickLong.js +18 -18
  62. package/build/ox_modules/module-mob/commands/clickMultipleTimes.js +18 -18
  63. package/build/ox_modules/module-mob/commands/closeApp.js +16 -16
  64. package/build/ox_modules/module-mob/commands/debug.js +16 -16
  65. package/build/ox_modules/module-mob/commands/dragAndDrop.js +19 -19
  66. package/build/ox_modules/module-mob/commands/enableNetwork.js +27 -27
  67. package/build/ox_modules/module-mob/commands/execute.js +21 -21
  68. package/build/ox_modules/module-mob/commands/findElement.js +20 -20
  69. package/build/ox_modules/module-mob/commands/findElements.js +23 -23
  70. package/build/ox_modules/module-mob/commands/getAlertText.js +17 -17
  71. package/build/ox_modules/module-mob/commands/getAppiumLogs.js +16 -16
  72. package/build/ox_modules/module-mob/commands/getBrowserLogs.js +16 -16
  73. package/build/ox_modules/module-mob/commands/getCurrentActivity.js +15 -15
  74. package/build/ox_modules/module-mob/commands/getCurrentPackage.js +15 -15
  75. package/build/ox_modules/module-mob/commands/getDeviceLogs.js +16 -16
  76. package/build/ox_modules/module-mob/commands/getDeviceTime.js +16 -16
  77. package/build/ox_modules/module-mob/commands/getLocation.js +20 -20
  78. package/build/ox_modules/module-mob/commands/getSource.js +16 -16
  79. package/build/ox_modules/module-mob/commands/getText.js +18 -18
  80. package/build/ox_modules/module-mob/commands/getTitle.js +13 -13
  81. package/build/ox_modules/module-mob/commands/getUrl.js +17 -17
  82. package/build/ox_modules/module-mob/commands/getValue.js +18 -18
  83. package/build/ox_modules/module-mob/commands/getWindowHandles.js +17 -17
  84. package/build/ox_modules/module-mob/commands/hideKeyboard.js +21 -21
  85. package/build/ox_modules/module-mob/commands/index.js +1 -1
  86. package/build/ox_modules/module-mob/commands/installApp.js +16 -16
  87. package/build/ox_modules/module-mob/commands/isAppInstalled.js +16 -16
  88. package/build/ox_modules/module-mob/commands/isCheckable.js +18 -18
  89. package/build/ox_modules/module-mob/commands/isChecked.js +18 -18
  90. package/build/ox_modules/module-mob/commands/isClickable.js +18 -18
  91. package/build/ox_modules/module-mob/commands/isExist.js +19 -19
  92. package/build/ox_modules/module-mob/commands/isSelected.js +23 -23
  93. package/build/ox_modules/module-mob/commands/isVisible.js +19 -19
  94. package/build/ox_modules/module-mob/commands/isWebViewContext.js +16 -16
  95. package/build/ox_modules/module-mob/commands/launchApp.js +15 -15
  96. package/build/ox_modules/module-mob/commands/longPressKeyCode.js +18 -18
  97. package/build/ox_modules/module-mob/commands/open.js +17 -17
  98. package/build/ox_modules/module-mob/commands/pause.js +16 -16
  99. package/build/ox_modules/module-mob/commands/removeApp.js +16 -16
  100. package/build/ox_modules/module-mob/commands/resetApp.js +15 -15
  101. package/build/ox_modules/module-mob/commands/scrollIntoElement.js +22 -22
  102. package/build/ox_modules/module-mob/commands/scrollIntoView.js +27 -27
  103. package/build/ox_modules/module-mob/commands/select.js +24 -24
  104. package/build/ox_modules/module-mob/commands/selectFrame.js +23 -23
  105. package/build/ox_modules/module-mob/commands/selectWindow.js +28 -28
  106. package/build/ox_modules/module-mob/commands/sendKeys.js +29 -29
  107. package/build/ox_modules/module-mob/commands/setContext.js +16 -16
  108. package/build/ox_modules/module-mob/commands/setNativeContext.js +15 -15
  109. package/build/ox_modules/module-mob/commands/setTimeout.js +21 -21
  110. package/build/ox_modules/module-mob/commands/setWebViewContext.js +16 -16
  111. package/build/ox_modules/module-mob/commands/shake.js +16 -16
  112. package/build/ox_modules/module-mob/commands/smsClickLink.js +19 -19
  113. package/build/ox_modules/module-mob/commands/smsGetText.js +20 -20
  114. package/build/ox_modules/module-mob/commands/swipe.js +20 -20
  115. package/build/ox_modules/module-mob/commands/swipeElement.js +20 -20
  116. package/build/ox_modules/module-mob/commands/swipeScreen.js +20 -20
  117. package/build/ox_modules/module-mob/commands/takeScreenshot.js +17 -17
  118. package/build/ox_modules/module-mob/commands/tap.js +17 -17
  119. package/build/ox_modules/module-mob/commands/type.js +20 -20
  120. package/build/ox_modules/module-mob/commands/unlockPattern.js +22 -22
  121. package/build/ox_modules/module-mob/commands/waitForExist.js +18 -18
  122. package/build/ox_modules/module-mob/commands/waitForInteractable.js +17 -17
  123. package/build/ox_modules/module-mob/commands/waitForVisible.js +17 -17
  124. package/build/ox_modules/module-mob.js +74 -74
  125. package/build/ox_modules/module-mongo.js +82 -82
  126. package/build/ox_modules/module-pdf.js +35 -35
  127. package/build/ox_modules/module-proxy.js +77 -77
  128. package/build/ox_modules/module-serial.js +55 -55
  129. package/build/ox_modules/module-shell.js +52 -33
  130. package/build/ox_modules/module-soap.js +72 -72
  131. package/build/ox_modules/module-twilio.js +41 -41
  132. package/build/ox_modules/module-utils.js +91 -91
  133. package/build/ox_modules/module-web/commands/alertAccept.js +17 -17
  134. package/build/ox_modules/module-web/commands/alertDismiss.js +17 -17
  135. package/build/ox_modules/module-web/commands/assertAlert.js +20 -20
  136. package/build/ox_modules/module-web/commands/assertExist.js +17 -17
  137. package/build/ox_modules/module-web/commands/assertSelectedLabel.js +21 -21
  138. package/build/ox_modules/module-web/commands/assertSelectedValue.js +21 -21
  139. package/build/ox_modules/module-web/commands/assertText.js +21 -21
  140. package/build/ox_modules/module-web/commands/assertTextNotPresent.js +18 -18
  141. package/build/ox_modules/module-web/commands/assertTextPresent.js +18 -18
  142. package/build/ox_modules/module-web/commands/assertTitle.js +19 -19
  143. package/build/ox_modules/module-web/commands/assertValue.js +20 -20
  144. package/build/ox_modules/module-web/commands/back.js +16 -16
  145. package/build/ox_modules/module-web/commands/clear.js +18 -18
  146. package/build/ox_modules/module-web/commands/click.js +25 -25
  147. package/build/ox_modules/module-web/commands/clickHidden.js +23 -23
  148. package/build/ox_modules/module-web/commands/closeWindow.js +15 -15
  149. package/build/ox_modules/module-web/commands/debug.js +15 -15
  150. package/build/ox_modules/module-web/commands/deleteCookies.js +12 -12
  151. package/build/ox_modules/module-web/commands/deselect.js +22 -22
  152. package/build/ox_modules/module-web/commands/doubleClick.js +17 -17
  153. package/build/ox_modules/module-web/commands/dragAndDrop.js +20 -20
  154. package/build/ox_modules/module-web/commands/execute.js +24 -24
  155. package/build/ox_modules/module-web/commands/fileBrowse.js +18 -18
  156. package/build/ox_modules/module-web/commands/findElement.js +19 -19
  157. package/build/ox_modules/module-web/commands/findElements.js +22 -22
  158. package/build/ox_modules/module-web/commands/fullscreenWindow.js +14 -14
  159. package/build/ox_modules/module-web/commands/getAlertText.js +16 -16
  160. package/build/ox_modules/module-web/commands/getAttribute.js +19 -19
  161. package/build/ox_modules/module-web/commands/getBrowserLogs.js +17 -17
  162. package/build/ox_modules/module-web/commands/getCookies.js +13 -13
  163. package/build/ox_modules/module-web/commands/getCssValue.js +19 -19
  164. package/build/ox_modules/module-web/commands/getElementCount.js +17 -17
  165. package/build/ox_modules/module-web/commands/getHTML.js +17 -17
  166. package/build/ox_modules/module-web/commands/getSource.js +16 -16
  167. package/build/ox_modules/module-web/commands/getText.js +18 -18
  168. package/build/ox_modules/module-web/commands/getTitle.js +12 -12
  169. package/build/ox_modules/module-web/commands/getUrl.js +16 -16
  170. package/build/ox_modules/module-web/commands/getValue.js +18 -18
  171. package/build/ox_modules/module-web/commands/getWindowHandles.js +16 -16
  172. package/build/ox_modules/module-web/commands/getWindowSize.js +16 -16
  173. package/build/ox_modules/module-web/commands/getXMLPageSource.js +16 -16
  174. package/build/ox_modules/module-web/commands/index.js +1 -1
  175. package/build/ox_modules/module-web/commands/isAlertPresent.js +16 -16
  176. package/build/ox_modules/module-web/commands/isChecked.js +18 -18
  177. package/build/ox_modules/module-web/commands/isExist.js +19 -19
  178. package/build/ox_modules/module-web/commands/isInteractable.js +22 -22
  179. package/build/ox_modules/module-web/commands/isSelected.js +23 -23
  180. package/build/ox_modules/module-web/commands/isVisible.js +19 -19
  181. package/build/ox_modules/module-web/commands/makeVisible.js +25 -25
  182. package/build/ox_modules/module-web/commands/maximizeWindow.js +14 -14
  183. package/build/ox_modules/module-web/commands/minimizeWindow.js +14 -14
  184. package/build/ox_modules/module-web/commands/mock.js +20 -20
  185. package/build/ox_modules/module-web/commands/mockClearAll.js +12 -12
  186. package/build/ox_modules/module-web/commands/mockRestoreAll.js +12 -12
  187. package/build/ox_modules/module-web/commands/newWindow.js +16 -16
  188. package/build/ox_modules/module-web/commands/open.js +16 -16
  189. package/build/ox_modules/module-web/commands/pause.js +15 -15
  190. package/build/ox_modules/module-web/commands/point.js +21 -21
  191. package/build/ox_modules/module-web/commands/pointJS.js +15 -15
  192. package/build/ox_modules/module-web/commands/refresh.js +15 -15
  193. package/build/ox_modules/module-web/commands/rightClick.js +17 -17
  194. package/build/ox_modules/module-web/commands/rightClickActions.js +19 -19
  195. package/build/ox_modules/module-web/commands/scrollToElement.js +21 -21
  196. package/build/ox_modules/module-web/commands/select.js +23 -23
  197. package/build/ox_modules/module-web/commands/selectFrame.js +24 -24
  198. package/build/ox_modules/module-web/commands/selectWindow.js +27 -27
  199. package/build/ox_modules/module-web/commands/sendKeys.js +22 -22
  200. package/build/ox_modules/module-web/commands/setAutoWaitForAngular.js +20 -20
  201. package/build/ox_modules/module-web/commands/setTimeout.js +21 -21
  202. package/build/ox_modules/module-web/commands/setWindowSize.js +17 -17
  203. package/build/ox_modules/module-web/commands/takeScreenshot.js +17 -17
  204. package/build/ox_modules/module-web/commands/type.js +20 -20
  205. package/build/ox_modules/module-web/commands/verifyAlert.js +20 -20
  206. package/build/ox_modules/module-web/commands/verifyExist.js +17 -17
  207. package/build/ox_modules/module-web/commands/verifySelectedLabel.js +21 -21
  208. package/build/ox_modules/module-web/commands/verifySelectedValue.js +21 -21
  209. package/build/ox_modules/module-web/commands/verifyText.js +21 -21
  210. package/build/ox_modules/module-web/commands/verifyTextNotPresent.js +18 -18
  211. package/build/ox_modules/module-web/commands/verifyTextPresent.js +18 -18
  212. package/build/ox_modules/module-web/commands/verifyTitle.js +19 -19
  213. package/build/ox_modules/module-web/commands/verifyValue.js +20 -20
  214. package/build/ox_modules/module-web/commands/waitForAngular.js +19 -19
  215. package/build/ox_modules/module-web/commands/waitForExist.js +17 -17
  216. package/build/ox_modules/module-web/commands/waitForInteractable.js +17 -17
  217. package/build/ox_modules/module-web/commands/waitForNotExist.js +17 -17
  218. package/build/ox_modules/module-web/commands/waitForNotText.js +20 -20
  219. package/build/ox_modules/module-web/commands/waitForNotValue.js +20 -20
  220. package/build/ox_modules/module-web/commands/waitForText.js +20 -20
  221. package/build/ox_modules/module-web/commands/waitForValue.js +20 -20
  222. package/build/ox_modules/module-web/commands/waitForVisible.js +17 -17
  223. package/build/ox_modules/module-web/commands/waitForWindow.js +22 -22
  224. package/build/ox_modules/module-web.js +94 -94
  225. package/build/ox_modules/module-win/commands/assertText.js +17 -17
  226. package/build/ox_modules/module-win/commands/assertTitle.js +15 -15
  227. package/build/ox_modules/module-win/commands/assertValue.js +14 -14
  228. package/build/ox_modules/module-win/commands/back.js +11 -11
  229. package/build/ox_modules/module-win/commands/clear.js +13 -13
  230. package/build/ox_modules/module-win/commands/click.js +13 -13
  231. package/build/ox_modules/module-win/commands/clickLong.js +14 -14
  232. package/build/ox_modules/module-win/commands/clickMultipleTimes.js +14 -14
  233. package/build/ox_modules/module-win/commands/findElement.js +15 -15
  234. package/build/ox_modules/module-win/commands/findElements.js +15 -15
  235. package/build/ox_modules/module-win/commands/getAppiumLogs.js +12 -12
  236. package/build/ox_modules/module-win/commands/getCurrentWindowHandle.js +15 -15
  237. package/build/ox_modules/module-win/commands/getLocation.js +14 -14
  238. package/build/ox_modules/module-win/commands/getSource.js +12 -12
  239. package/build/ox_modules/module-win/commands/getText.js +14 -14
  240. package/build/ox_modules/module-win/commands/getValue.js +14 -14
  241. package/build/ox_modules/module-win/commands/getWindowHandles.js +15 -15
  242. package/build/ox_modules/module-win/commands/index.js +1 -1
  243. package/build/ox_modules/module-win/commands/isCheckable.js +14 -14
  244. package/build/ox_modules/module-win/commands/isChecked.js +14 -14
  245. package/build/ox_modules/module-win/commands/isClickable.js +14 -14
  246. package/build/ox_modules/module-win/commands/isExist.js +15 -15
  247. package/build/ox_modules/module-win/commands/isSelected.js +14 -14
  248. package/build/ox_modules/module-win/commands/isVisible.js +15 -15
  249. package/build/ox_modules/module-win/commands/open.js +13 -13
  250. package/build/ox_modules/module-win/commands/pause.js +12 -12
  251. package/build/ox_modules/module-win/commands/rightClick.js +13 -13
  252. package/build/ox_modules/module-win/commands/selectWindow.js +23 -23
  253. package/build/ox_modules/module-win/commands/sendKeys.js +22 -22
  254. package/build/ox_modules/module-win/commands/setTimeout.js +17 -17
  255. package/build/ox_modules/module-win/commands/takeScreenshot.js +16 -16
  256. package/build/ox_modules/module-win/commands/tap.js +13 -13
  257. package/build/ox_modules/module-win/commands/type.js +16 -16
  258. package/build/ox_modules/module-win/commands/waitForExist.js +14 -14
  259. package/build/ox_modules/module-win/commands/waitForInteractable.js +16 -16
  260. package/build/ox_modules/module-win/commands/waitForVisible.js +13 -13
  261. package/build/ox_modules/module-win.js +47 -47
  262. package/build/ox_modules/utils.js +8 -8
  263. package/build/ox_reporters/excel/template.json +48 -48
  264. package/build/ox_reporters/html/index.ejs +163 -163
  265. package/build/ox_reporters/html/summary.ejs +77 -77
  266. package/build/ox_reporters/html/tests-details.ejs +134 -134
  267. package/build/ox_reporters/html/tests-devices-browsers.ejs +83 -83
  268. package/build/ox_reporters/reporter-excel.js +1 -1
  269. package/build/ox_reporters/reporter-html.js +1 -1
  270. package/build/ox_reporters/reporter-json.js +1 -1
  271. package/build/ox_reporters/reporter-junit.js +1 -1
  272. package/build/ox_reporters/reporter-pdf.js +1 -1
  273. package/build/ox_reporters/reporter-rp.js +73 -42
  274. package/build/ox_reporters/reporter-xml.js +1 -1
  275. package/build/ox_services/service-devtools/submodule-network.js +1 -1
  276. package/build/ox_services/service-devtools.js +1 -1
  277. package/build/reporter/FileReporterBase.js +1 -1
  278. package/build/reporter/ReportAggregator.js +1 -1
  279. package/build/reporter/ReporterBase.js +1 -1
  280. package/build/reporter/WebSocketReporter.js +1 -1
  281. package/build/runners/WorkerProcess.js +1 -1
  282. package/build/runners/cucumber/CucumberEventListener.js +1 -1
  283. package/build/runners/cucumber/CucumberReporter.js +1 -1
  284. package/build/runners/cucumber/CucumberWorker.js +1 -1
  285. package/build/runners/cucumber/index.js +1 -1
  286. package/build/runners/cucumber/worker.js +1 -1
  287. package/build/runners/index.js +1 -1
  288. package/build/runners/oxygen/OxygenWorker.js +1 -1
  289. package/build/runners/oxygen/index.js +1 -1
  290. package/build/runners/oxygen/worker.js +1 -1
  291. package/config/default.json +6 -6
  292. package/package.json +139 -139
  293. package/types/index.d.ts +70 -70
  294. package/types/module-eyes.d.ts +39 -39
  295. package/types/module-http.d.ts +163 -163
  296. package/types/module-log.d.ts +34 -34
  297. package/types/module-mob.d.ts +966 -966
  298. package/types/module-pdf.d.ts +40 -40
  299. package/types/module-proxy.d.ts +100 -100
  300. package/types/module-shell.d.ts +24 -24
  301. package/types/module-utils.d.ts +99 -99
  302. package/types/module-web.d.ts +1053 -1053
  303. package/types/module-win.d.ts +352 -352
  304. package/types/oxygen.d.ts +53 -53
  305. package/log.txt +0 -1614
  306. package/reports/2025-06-08_231627/report.html +0 -440
  307. package/reports/2025-06-09_223615/report.html +0 -440
  308. package/transpiled/mongodb/etc/prepare.js +0 -18
  309. package/transpiled/mongodb/lib/admin.js +0 -182
  310. package/transpiled/mongodb/lib/beta.js +0 -26
  311. package/transpiled/mongodb/lib/bson.js +0 -220
  312. package/transpiled/mongodb/lib/bulk/common.js +0 -1041
  313. package/transpiled/mongodb/lib/bulk/ordered.js +0 -76
  314. package/transpiled/mongodb/lib/bulk/unordered.js +0 -102
  315. package/transpiled/mongodb/lib/change_stream.js +0 -517
  316. package/transpiled/mongodb/lib/client-side-encryption/auto_encrypter.js +0 -329
  317. package/transpiled/mongodb/lib/client-side-encryption/client_encryption.js +0 -779
  318. package/transpiled/mongodb/lib/client-side-encryption/crypto_callbacks.js +0 -95
  319. package/transpiled/mongodb/lib/client-side-encryption/errors.js +0 -171
  320. package/transpiled/mongodb/lib/client-side-encryption/mongocryptd_manager.js +0 -98
  321. package/transpiled/mongodb/lib/client-side-encryption/providers/aws.js +0 -34
  322. package/transpiled/mongodb/lib/client-side-encryption/providers/azure.js +0 -186
  323. package/transpiled/mongodb/lib/client-side-encryption/providers/gcp.js +0 -29
  324. package/transpiled/mongodb/lib/client-side-encryption/providers/index.js +0 -58
  325. package/transpiled/mongodb/lib/client-side-encryption/state_machine.js +0 -505
  326. package/transpiled/mongodb/lib/cmap/auth/auth_provider.js +0 -63
  327. package/transpiled/mongodb/lib/cmap/auth/aws_temporary_credentials.js +0 -167
  328. package/transpiled/mongodb/lib/cmap/auth/gssapi.js +0 -207
  329. package/transpiled/mongodb/lib/cmap/auth/mongo_credentials.js +0 -193
  330. package/transpiled/mongodb/lib/cmap/auth/mongodb_aws.js +0 -181
  331. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +0 -101
  332. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +0 -81
  333. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/callback_workflow.js +0 -174
  334. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/command_builders.js +0 -59
  335. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +0 -58
  336. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +0 -138
  337. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +0 -42
  338. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/token_cache.js +0 -71
  339. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +0 -34
  340. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc.js +0 -111
  341. package/transpiled/mongodb/lib/cmap/auth/plain.js +0 -43
  342. package/transpiled/mongodb/lib/cmap/auth/providers.js +0 -22
  343. package/transpiled/mongodb/lib/cmap/auth/scram.js +0 -318
  344. package/transpiled/mongodb/lib/cmap/auth/x509.js +0 -61
  345. package/transpiled/mongodb/lib/cmap/command_monitoring_events.js +0 -266
  346. package/transpiled/mongodb/lib/cmap/commands.js +0 -605
  347. package/transpiled/mongodb/lib/cmap/connect.js +0 -418
  348. package/transpiled/mongodb/lib/cmap/connection.js +0 -673
  349. package/transpiled/mongodb/lib/cmap/connection_pool.js +0 -688
  350. package/transpiled/mongodb/lib/cmap/connection_pool_events.js +0 -254
  351. package/transpiled/mongodb/lib/cmap/errors.js +0 -128
  352. package/transpiled/mongodb/lib/cmap/handshake/client_metadata.js +0 -278
  353. package/transpiled/mongodb/lib/cmap/metrics.js +0 -67
  354. package/transpiled/mongodb/lib/cmap/stream_description.js +0 -74
  355. package/transpiled/mongodb/lib/cmap/wire_protocol/compression.js +0 -196
  356. package/transpiled/mongodb/lib/cmap/wire_protocol/constants.js +0 -19
  357. package/transpiled/mongodb/lib/cmap/wire_protocol/on_data.js +0 -144
  358. package/transpiled/mongodb/lib/cmap/wire_protocol/on_demand/document.js +0 -278
  359. package/transpiled/mongodb/lib/cmap/wire_protocol/responses.js +0 -376
  360. package/transpiled/mongodb/lib/cmap/wire_protocol/shared.js +0 -49
  361. package/transpiled/mongodb/lib/collection.js +0 -852
  362. package/transpiled/mongodb/lib/connection_string.js +0 -1452
  363. package/transpiled/mongodb/lib/constants.js +0 -162
  364. package/transpiled/mongodb/lib/cursor/abstract_cursor.js +0 -1082
  365. package/transpiled/mongodb/lib/cursor/aggregation_cursor.js +0 -227
  366. package/transpiled/mongodb/lib/cursor/change_stream_cursor.js +0 -136
  367. package/transpiled/mongodb/lib/cursor/client_bulk_write_cursor.js +0 -69
  368. package/transpiled/mongodb/lib/cursor/find_cursor.js +0 -476
  369. package/transpiled/mongodb/lib/cursor/list_collections_cursor.js +0 -48
  370. package/transpiled/mongodb/lib/cursor/list_indexes_cursor.js +0 -46
  371. package/transpiled/mongodb/lib/cursor/list_search_indexes_cursor.js +0 -30
  372. package/transpiled/mongodb/lib/cursor/run_command_cursor.js +0 -125
  373. package/transpiled/mongodb/lib/db.js +0 -467
  374. package/transpiled/mongodb/lib/deps.js +0 -174
  375. package/transpiled/mongodb/lib/encrypter.js +0 -129
  376. package/transpiled/mongodb/lib/error.js +0 -1550
  377. package/transpiled/mongodb/lib/explain.js +0 -122
  378. package/transpiled/mongodb/lib/gridfs/download.js +0 -369
  379. package/transpiled/mongodb/lib/gridfs/index.js +0 -240
  380. package/transpiled/mongodb/lib/gridfs/upload.js +0 -446
  381. package/transpiled/mongodb/lib/index.js +0 -975
  382. package/transpiled/mongodb/lib/mongo_client.js +0 -626
  383. package/transpiled/mongodb/lib/mongo_client_auth_providers.js +0 -98
  384. package/transpiled/mongodb/lib/mongo_logger.js +0 -812
  385. package/transpiled/mongodb/lib/mongo_types.js +0 -71
  386. package/transpiled/mongodb/lib/operations/aggregate.js +0 -129
  387. package/transpiled/mongodb/lib/operations/bulk_write.js +0 -48
  388. package/transpiled/mongodb/lib/operations/client_bulk_write/client_bulk_write.js +0 -96
  389. package/transpiled/mongodb/lib/operations/client_bulk_write/command_builder.js +0 -409
  390. package/transpiled/mongodb/lib/operations/client_bulk_write/common.js +0 -5
  391. package/transpiled/mongodb/lib/operations/client_bulk_write/executor.js +0 -144
  392. package/transpiled/mongodb/lib/operations/client_bulk_write/results_merger.js +0 -228
  393. package/transpiled/mongodb/lib/operations/collections.js +0 -49
  394. package/transpiled/mongodb/lib/operations/command.js +0 -102
  395. package/transpiled/mongodb/lib/operations/count.js +0 -60
  396. package/transpiled/mongodb/lib/operations/create_collection.js +0 -109
  397. package/transpiled/mongodb/lib/operations/delete.js +0 -134
  398. package/transpiled/mongodb/lib/operations/distinct.js +0 -77
  399. package/transpiled/mongodb/lib/operations/drop.js +0 -102
  400. package/transpiled/mongodb/lib/operations/estimated_document_count.js +0 -47
  401. package/transpiled/mongodb/lib/operations/execute_operation.js +0 -251
  402. package/transpiled/mongodb/lib/operations/find.js +0 -197
  403. package/transpiled/mongodb/lib/operations/find_and_modify.js +0 -191
  404. package/transpiled/mongodb/lib/operations/get_more.js +0 -84
  405. package/transpiled/mongodb/lib/operations/indexes.js +0 -197
  406. package/transpiled/mongodb/lib/operations/insert.js +0 -138
  407. package/transpiled/mongodb/lib/operations/is_capped.js +0 -44
  408. package/transpiled/mongodb/lib/operations/kill_cursors.js +0 -58
  409. package/transpiled/mongodb/lib/operations/list_collections.js +0 -66
  410. package/transpiled/mongodb/lib/operations/list_databases.js +0 -56
  411. package/transpiled/mongodb/lib/operations/operation.js +0 -88
  412. package/transpiled/mongodb/lib/operations/options_operation.js +0 -44
  413. package/transpiled/mongodb/lib/operations/profiling_level.js +0 -42
  414. package/transpiled/mongodb/lib/operations/remove_user.js +0 -35
  415. package/transpiled/mongodb/lib/operations/rename.js +0 -48
  416. package/transpiled/mongodb/lib/operations/run_command.js +0 -64
  417. package/transpiled/mongodb/lib/operations/search_indexes/create.js +0 -41
  418. package/transpiled/mongodb/lib/operations/search_indexes/drop.js +0 -51
  419. package/transpiled/mongodb/lib/operations/search_indexes/update.js +0 -40
  420. package/transpiled/mongodb/lib/operations/set_profiling_level.js +0 -70
  421. package/transpiled/mongodb/lib/operations/stats.js +0 -39
  422. package/transpiled/mongodb/lib/operations/update.js +0 -218
  423. package/transpiled/mongodb/lib/operations/validate_collection.js +0 -49
  424. package/transpiled/mongodb/lib/read_concern.js +0 -92
  425. package/transpiled/mongodb/lib/read_preference.js +0 -215
  426. package/transpiled/mongodb/lib/resource_management.js +0 -74
  427. package/transpiled/mongodb/lib/sdam/common.js +0 -53
  428. package/transpiled/mongodb/lib/sdam/events.js +0 -177
  429. package/transpiled/mongodb/lib/sdam/monitor.js +0 -656
  430. package/transpiled/mongodb/lib/sdam/server.js +0 -463
  431. package/transpiled/mongodb/lib/sdam/server_description.js +0 -196
  432. package/transpiled/mongodb/lib/sdam/server_selection.js +0 -283
  433. package/transpiled/mongodb/lib/sdam/server_selection_events.js +0 -112
  434. package/transpiled/mongodb/lib/sdam/srv_polling.js +0 -139
  435. package/transpiled/mongodb/lib/sdam/topology.js +0 -833
  436. package/transpiled/mongodb/lib/sdam/topology_description.js +0 -447
  437. package/transpiled/mongodb/lib/sessions.js +0 -988
  438. package/transpiled/mongodb/lib/sort.js +0 -123
  439. package/transpiled/mongodb/lib/timeout.js +0 -349
  440. package/transpiled/mongodb/lib/transactions.js +0 -149
  441. package/transpiled/mongodb/lib/utils.js +0 -1502
  442. package/transpiled/mongodb/lib/write_concern.js +0 -115
@@ -1,988 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ServerSessionPool = exports.ServerSession = exports.ClientSession = void 0;
7
- exports.maybeClearPinnedConnection = maybeClearPinnedConnection;
8
- exports.applySession = applySession;
9
- exports.updateSessionFromResponse = updateSessionFromResponse;
10
-
11
- const bson_1 = require("./bson");
12
-
13
- const metrics_1 = require("./cmap/metrics");
14
-
15
- const shared_1 = require("./cmap/wire_protocol/shared");
16
-
17
- const constants_1 = require("./constants");
18
-
19
- const error_1 = require("./error");
20
-
21
- const mongo_types_1 = require("./mongo_types");
22
-
23
- const execute_operation_1 = require("./operations/execute_operation");
24
-
25
- const run_command_1 = require("./operations/run_command");
26
-
27
- const read_concern_1 = require("./read_concern");
28
-
29
- const read_preference_1 = require("./read_preference");
30
-
31
- const resource_management_1 = require("./resource_management");
32
-
33
- const common_1 = require("./sdam/common");
34
-
35
- const timeout_1 = require("./timeout");
36
-
37
- const transactions_1 = require("./transactions");
38
-
39
- const utils_1 = require("./utils");
40
-
41
- const write_concern_1 = require("./write_concern");
42
-
43
- const minWireVersionForShardedTransactions = 8;
44
- /**
45
- * A class representing a client session on the server
46
- *
47
- * NOTE: not meant to be instantiated directly.
48
- * @public
49
- */
50
-
51
- class ClientSession extends mongo_types_1.TypedEventEmitter {
52
- /**
53
- * Create a client session.
54
- * @internal
55
- * @param client - The current client
56
- * @param sessionPool - The server session pool (Internal Class)
57
- * @param options - Optional settings
58
- * @param clientOptions - Optional settings provided when creating a MongoClient
59
- */
60
- constructor(client, sessionPool, options, clientOptions) {
61
- super();
62
- /** @internal */
63
-
64
- this.timeoutContext = null;
65
- this.on('error', utils_1.noop);
66
-
67
- if (client == null) {
68
- // TODO(NODE-3483)
69
- throw new error_1.MongoRuntimeError('ClientSession requires a MongoClient');
70
- }
71
-
72
- if (sessionPool == null || !(sessionPool instanceof ServerSessionPool)) {
73
- // TODO(NODE-3483)
74
- throw new error_1.MongoRuntimeError('ClientSession requires a ServerSessionPool');
75
- }
76
-
77
- options = options ?? {};
78
- this.snapshotEnabled = options.snapshot === true;
79
-
80
- if (options.causalConsistency === true && this.snapshotEnabled) {
81
- throw new error_1.MongoInvalidArgumentError('Properties "causalConsistency" and "snapshot" are mutually exclusive');
82
- }
83
-
84
- this.client = client;
85
- this.sessionPool = sessionPool;
86
- this.hasEnded = false;
87
- this.clientOptions = clientOptions;
88
- this.timeoutMS = options.defaultTimeoutMS ?? client.s.options?.timeoutMS;
89
- this.explicit = !!options.explicit;
90
- this._serverSession = this.explicit ? this.sessionPool.acquire() : null;
91
- this.txnNumberIncrement = 0;
92
- const defaultCausalConsistencyValue = this.explicit && options.snapshot !== true;
93
- this.supports = {
94
- // if we can enable causal consistency, do so by default
95
- causalConsistency: options.causalConsistency ?? defaultCausalConsistencyValue
96
- };
97
- this.clusterTime = options.initialClusterTime;
98
- this.operationTime = undefined;
99
- this.owner = options.owner;
100
- this.defaultTransactionOptions = { ...options.defaultTransactionOptions
101
- };
102
- this.transaction = new transactions_1.Transaction();
103
- }
104
- /** The server id associated with this session */
105
-
106
-
107
- get id() {
108
- return this.serverSession?.id;
109
- }
110
-
111
- get serverSession() {
112
- let serverSession = this._serverSession;
113
-
114
- if (serverSession == null) {
115
- if (this.explicit) {
116
- throw new error_1.MongoRuntimeError('Unexpected null serverSession for an explicit session');
117
- }
118
-
119
- if (this.hasEnded) {
120
- throw new error_1.MongoRuntimeError('Unexpected null serverSession for an ended implicit session');
121
- }
122
-
123
- serverSession = this.sessionPool.acquire();
124
- this._serverSession = serverSession;
125
- }
126
-
127
- return serverSession;
128
- }
129
-
130
- get loadBalanced() {
131
- return this.client.topology?.description.type === common_1.TopologyType.LoadBalanced;
132
- }
133
- /** @internal */
134
-
135
-
136
- pin(conn) {
137
- if (this.pinnedConnection) {
138
- throw TypeError('Cannot pin multiple connections to the same session');
139
- }
140
-
141
- this.pinnedConnection = conn;
142
- conn.emit(constants_1.PINNED, this.inTransaction() ? metrics_1.ConnectionPoolMetrics.TXN : metrics_1.ConnectionPoolMetrics.CURSOR);
143
- }
144
- /** @internal */
145
-
146
-
147
- unpin(options) {
148
- if (this.loadBalanced) {
149
- return maybeClearPinnedConnection(this, options);
150
- }
151
-
152
- this.transaction.unpinServer();
153
- }
154
-
155
- get isPinned() {
156
- return this.loadBalanced ? !!this.pinnedConnection : this.transaction.isPinned;
157
- }
158
- /**
159
- * Frees any client-side resources held by the current session. If a session is in a transaction,
160
- * the transaction is aborted.
161
- *
162
- * Does not end the session on the server.
163
- *
164
- * @param options - Optional settings. Currently reserved for future use
165
- */
166
-
167
-
168
- async endSession(options) {
169
- try {
170
- if (this.inTransaction()) {
171
- await this.abortTransaction({ ...options,
172
- throwTimeout: true
173
- });
174
- }
175
- } catch (error) {
176
- // spec indicates that we should ignore all errors for `endSessions`
177
- if (error.name === 'MongoOperationTimeoutError') throw error;
178
- (0, utils_1.squashError)(error);
179
- } finally {
180
- if (!this.hasEnded) {
181
- const serverSession = this.serverSession;
182
-
183
- if (serverSession != null) {
184
- // release the server session back to the pool
185
- this.sessionPool.release(serverSession); // Store a clone of the server session for reference (debugging)
186
-
187
- this._serverSession = new ServerSession(serverSession);
188
- } // mark the session as ended, and emit a signal
189
-
190
-
191
- this.hasEnded = true;
192
- this.emit('ended', this);
193
- }
194
-
195
- maybeClearPinnedConnection(this, {
196
- force: true,
197
- ...options
198
- });
199
- }
200
- }
201
- /** @internal */
202
-
203
-
204
- async asyncDispose() {
205
- await this.endSession({
206
- force: true
207
- });
208
- }
209
- /**
210
- * Advances the operationTime for a ClientSession.
211
- *
212
- * @param operationTime - the `BSON.Timestamp` of the operation type it is desired to advance to
213
- */
214
-
215
-
216
- advanceOperationTime(operationTime) {
217
- if (this.operationTime == null) {
218
- this.operationTime = operationTime;
219
- return;
220
- }
221
-
222
- if (operationTime.greaterThan(this.operationTime)) {
223
- this.operationTime = operationTime;
224
- }
225
- }
226
- /**
227
- * Advances the clusterTime for a ClientSession to the provided clusterTime of another ClientSession
228
- *
229
- * @param clusterTime - the $clusterTime returned by the server from another session in the form of a document containing the `BSON.Timestamp` clusterTime and signature
230
- */
231
-
232
-
233
- advanceClusterTime(clusterTime) {
234
- if (!clusterTime || typeof clusterTime !== 'object') {
235
- throw new error_1.MongoInvalidArgumentError('input cluster time must be an object');
236
- }
237
-
238
- if (!clusterTime.clusterTime || clusterTime.clusterTime._bsontype !== 'Timestamp') {
239
- throw new error_1.MongoInvalidArgumentError('input cluster time "clusterTime" property must be a valid BSON Timestamp');
240
- }
241
-
242
- if (!clusterTime.signature || clusterTime.signature.hash?._bsontype !== 'Binary' || typeof clusterTime.signature.keyId !== 'bigint' && typeof clusterTime.signature.keyId !== 'number' && clusterTime.signature.keyId?._bsontype !== 'Long' // apparently we decode the key to number?
243
- ) {
244
- throw new error_1.MongoInvalidArgumentError('input cluster time must have a valid "signature" property with BSON Binary hash and BSON Long keyId');
245
- }
246
-
247
- (0, common_1._advanceClusterTime)(this, clusterTime);
248
- }
249
- /**
250
- * Used to determine if this session equals another
251
- *
252
- * @param session - The session to compare to
253
- */
254
-
255
-
256
- equals(session) {
257
- if (!(session instanceof ClientSession)) {
258
- return false;
259
- }
260
-
261
- if (this.id == null || session.id == null) {
262
- return false;
263
- }
264
-
265
- return utils_1.ByteUtils.equals(this.id.id.buffer, session.id.id.buffer);
266
- }
267
- /**
268
- * Increment the transaction number on the internal ServerSession
269
- *
270
- * @privateRemarks
271
- * This helper increments a value stored on the client session that will be
272
- * added to the serverSession's txnNumber upon applying it to a command.
273
- * This is because the serverSession is lazily acquired after a connection is obtained
274
- */
275
-
276
-
277
- incrementTransactionNumber() {
278
- this.txnNumberIncrement += 1;
279
- }
280
- /** @returns whether this session is currently in a transaction or not */
281
-
282
-
283
- inTransaction() {
284
- return this.transaction.isActive;
285
- }
286
- /**
287
- * Starts a new transaction with the given options.
288
- *
289
- * @remarks
290
- * **IMPORTANT**: Running operations in parallel is not supported during a transaction. The use of `Promise.all`,
291
- * `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is
292
- * undefined behaviour.
293
- *
294
- * @param options - Options for the transaction
295
- */
296
-
297
-
298
- startTransaction(options) {
299
- if (this.snapshotEnabled) {
300
- throw new error_1.MongoCompatibilityError('Transactions are not supported in snapshot sessions');
301
- }
302
-
303
- if (this.inTransaction()) {
304
- throw new error_1.MongoTransactionError('Transaction already in progress');
305
- }
306
-
307
- if (this.isPinned && this.transaction.isCommitted) {
308
- this.unpin();
309
- }
310
-
311
- const topologyMaxWireVersion = (0, utils_1.maxWireVersion)(this.client.topology);
312
-
313
- if ((0, shared_1.isSharded)(this.client.topology) && topologyMaxWireVersion != null && topologyMaxWireVersion < minWireVersionForShardedTransactions) {
314
- throw new error_1.MongoCompatibilityError('Transactions are not supported on sharded clusters in MongoDB < 4.2.');
315
- }
316
-
317
- this.commitAttempted = false; // increment txnNumber
318
-
319
- this.incrementTransactionNumber(); // create transaction state
320
-
321
- this.transaction = new transactions_1.Transaction({
322
- readConcern: options?.readConcern ?? this.defaultTransactionOptions.readConcern ?? this.clientOptions?.readConcern,
323
- writeConcern: options?.writeConcern ?? this.defaultTransactionOptions.writeConcern ?? this.clientOptions?.writeConcern,
324
- readPreference: options?.readPreference ?? this.defaultTransactionOptions.readPreference ?? this.clientOptions?.readPreference,
325
- maxCommitTimeMS: options?.maxCommitTimeMS ?? this.defaultTransactionOptions.maxCommitTimeMS
326
- });
327
- this.transaction.transition(transactions_1.TxnState.STARTING_TRANSACTION);
328
- }
329
- /**
330
- * Commits the currently active transaction in this session.
331
- *
332
- * @param options - Optional options, can be used to override `defaultTimeoutMS`.
333
- */
334
-
335
-
336
- async commitTransaction(options) {
337
- if (this.transaction.state === transactions_1.TxnState.NO_TRANSACTION) {
338
- throw new error_1.MongoTransactionError('No transaction started');
339
- }
340
-
341
- if (this.transaction.state === transactions_1.TxnState.STARTING_TRANSACTION || this.transaction.state === transactions_1.TxnState.TRANSACTION_COMMITTED_EMPTY) {
342
- // the transaction was never started, we can safely exit here
343
- this.transaction.transition(transactions_1.TxnState.TRANSACTION_COMMITTED_EMPTY);
344
- return;
345
- }
346
-
347
- if (this.transaction.state === transactions_1.TxnState.TRANSACTION_ABORTED) {
348
- throw new error_1.MongoTransactionError('Cannot call commitTransaction after calling abortTransaction');
349
- }
350
-
351
- const command = {
352
- commitTransaction: 1
353
- };
354
- const timeoutMS = typeof options?.timeoutMS === 'number' ? options.timeoutMS : typeof this.timeoutMS === 'number' ? this.timeoutMS : null;
355
- const wc = this.transaction.options.writeConcern ?? this.clientOptions?.writeConcern;
356
-
357
- if (wc != null) {
358
- if (timeoutMS == null && this.timeoutContext == null) {
359
- write_concern_1.WriteConcern.apply(command, {
360
- wtimeoutMS: 10000,
361
- w: 'majority',
362
- ...wc
363
- });
364
- } else {
365
- const wcKeys = Object.keys(wc);
366
- if (wcKeys.length > 2 || !wcKeys.includes('wtimeoutMS') && !wcKeys.includes('wTimeoutMS')) // if the write concern was specified with wTimeoutMS, then we set both wtimeoutMS and wTimeoutMS, guaranteeing at least two keys, so if we have more than two keys, then we can automatically assume that we should add the write concern to the command. If it has 2 or fewer keys, we need to check that those keys aren't the wtimeoutMS or wTimeoutMS options before we add the write concern to the command
367
- write_concern_1.WriteConcern.apply(command, { ...wc,
368
- wtimeoutMS: undefined
369
- });
370
- }
371
- }
372
-
373
- if (this.transaction.state === transactions_1.TxnState.TRANSACTION_COMMITTED || this.commitAttempted) {
374
- if (timeoutMS == null && this.timeoutContext == null) {
375
- write_concern_1.WriteConcern.apply(command, {
376
- wtimeoutMS: 10000,
377
- ...wc,
378
- w: 'majority'
379
- });
380
- } else {
381
- write_concern_1.WriteConcern.apply(command, {
382
- w: 'majority',
383
- ...wc,
384
- wtimeoutMS: undefined
385
- });
386
- }
387
- }
388
-
389
- if (typeof this.transaction.options.maxTimeMS === 'number') {
390
- command.maxTimeMS = this.transaction.options.maxTimeMS;
391
- }
392
-
393
- if (this.transaction.recoveryToken) {
394
- command.recoveryToken = this.transaction.recoveryToken;
395
- }
396
-
397
- const operation = new run_command_1.RunAdminCommandOperation(command, {
398
- session: this,
399
- readPreference: read_preference_1.ReadPreference.primary,
400
- bypassPinningCheck: true
401
- });
402
- const timeoutContext = this.timeoutContext ?? (typeof timeoutMS === 'number' ? timeout_1.TimeoutContext.create({
403
- serverSelectionTimeoutMS: this.clientOptions.serverSelectionTimeoutMS,
404
- socketTimeoutMS: this.clientOptions.socketTimeoutMS,
405
- timeoutMS
406
- }) : null);
407
-
408
- try {
409
- await (0, execute_operation_1.executeOperation)(this.client, operation, timeoutContext);
410
- this.commitAttempted = undefined;
411
- return;
412
- } catch (firstCommitError) {
413
- this.commitAttempted = true;
414
-
415
- if (firstCommitError instanceof error_1.MongoError && (0, error_1.isRetryableWriteError)(firstCommitError)) {
416
- // SPEC-1185: apply majority write concern when retrying commitTransaction
417
- write_concern_1.WriteConcern.apply(command, {
418
- wtimeoutMS: 10000,
419
- ...wc,
420
- w: 'majority'
421
- }); // per txns spec, must unpin session in this case
422
-
423
- this.unpin({
424
- force: true
425
- });
426
-
427
- try {
428
- await (0, execute_operation_1.executeOperation)(this.client, new run_command_1.RunAdminCommandOperation(command, {
429
- session: this,
430
- readPreference: read_preference_1.ReadPreference.primary,
431
- bypassPinningCheck: true
432
- }), timeoutContext);
433
- return;
434
- } catch (retryCommitError) {
435
- // If the retry failed, we process that error instead of the original
436
- if (shouldAddUnknownTransactionCommitResultLabel(retryCommitError)) {
437
- retryCommitError.addErrorLabel(error_1.MongoErrorLabel.UnknownTransactionCommitResult);
438
- }
439
-
440
- if (shouldUnpinAfterCommitError(retryCommitError)) {
441
- this.unpin({
442
- error: retryCommitError
443
- });
444
- }
445
-
446
- throw retryCommitError;
447
- }
448
- }
449
-
450
- if (shouldAddUnknownTransactionCommitResultLabel(firstCommitError)) {
451
- firstCommitError.addErrorLabel(error_1.MongoErrorLabel.UnknownTransactionCommitResult);
452
- }
453
-
454
- if (shouldUnpinAfterCommitError(firstCommitError)) {
455
- this.unpin({
456
- error: firstCommitError
457
- });
458
- }
459
-
460
- throw firstCommitError;
461
- } finally {
462
- this.transaction.transition(transactions_1.TxnState.TRANSACTION_COMMITTED);
463
- }
464
- }
465
-
466
- async abortTransaction(options) {
467
- if (this.transaction.state === transactions_1.TxnState.NO_TRANSACTION) {
468
- throw new error_1.MongoTransactionError('No transaction started');
469
- }
470
-
471
- if (this.transaction.state === transactions_1.TxnState.STARTING_TRANSACTION) {
472
- // the transaction was never started, we can safely exit here
473
- this.transaction.transition(transactions_1.TxnState.TRANSACTION_ABORTED);
474
- return;
475
- }
476
-
477
- if (this.transaction.state === transactions_1.TxnState.TRANSACTION_ABORTED) {
478
- throw new error_1.MongoTransactionError('Cannot call abortTransaction twice');
479
- }
480
-
481
- if (this.transaction.state === transactions_1.TxnState.TRANSACTION_COMMITTED || this.transaction.state === transactions_1.TxnState.TRANSACTION_COMMITTED_EMPTY) {
482
- throw new error_1.MongoTransactionError('Cannot call abortTransaction after calling commitTransaction');
483
- }
484
-
485
- const command = {
486
- abortTransaction: 1
487
- };
488
- const timeoutMS = typeof options?.timeoutMS === 'number' ? options.timeoutMS : this.timeoutContext?.csotEnabled() ? this.timeoutContext.timeoutMS // refresh timeoutMS for abort operation
489
- : typeof this.timeoutMS === 'number' ? this.timeoutMS : null;
490
- const timeoutContext = timeoutMS != null ? timeout_1.TimeoutContext.create({
491
- timeoutMS,
492
- serverSelectionTimeoutMS: this.clientOptions.serverSelectionTimeoutMS,
493
- socketTimeoutMS: this.clientOptions.socketTimeoutMS
494
- }) : null;
495
- const wc = this.transaction.options.writeConcern ?? this.clientOptions?.writeConcern;
496
-
497
- if (wc != null && timeoutMS == null) {
498
- write_concern_1.WriteConcern.apply(command, {
499
- wtimeoutMS: 10000,
500
- w: 'majority',
501
- ...wc
502
- });
503
- }
504
-
505
- if (this.transaction.recoveryToken) {
506
- command.recoveryToken = this.transaction.recoveryToken;
507
- }
508
-
509
- const operation = new run_command_1.RunAdminCommandOperation(command, {
510
- session: this,
511
- readPreference: read_preference_1.ReadPreference.primary,
512
- bypassPinningCheck: true
513
- });
514
-
515
- try {
516
- await (0, execute_operation_1.executeOperation)(this.client, operation, timeoutContext);
517
- this.unpin();
518
- return;
519
- } catch (firstAbortError) {
520
- this.unpin();
521
- if (firstAbortError.name === 'MongoRuntimeError') throw firstAbortError;
522
-
523
- if (options?.throwTimeout && firstAbortError.name === 'MongoOperationTimeoutError') {
524
- throw firstAbortError;
525
- }
526
-
527
- if (firstAbortError instanceof error_1.MongoError && (0, error_1.isRetryableWriteError)(firstAbortError)) {
528
- try {
529
- await (0, execute_operation_1.executeOperation)(this.client, operation, timeoutContext);
530
- return;
531
- } catch (secondAbortError) {
532
- if (secondAbortError.name === 'MongoRuntimeError') throw secondAbortError;
533
-
534
- if (options?.throwTimeout && secondAbortError.name === 'MongoOperationTimeoutError') {
535
- throw secondAbortError;
536
- } // we do not retry the retry
537
-
538
- }
539
- } // The spec indicates that if the operation times out or fails with a non-retryable error, we should ignore all errors on `abortTransaction`
540
-
541
- } finally {
542
- this.transaction.transition(transactions_1.TxnState.TRANSACTION_ABORTED);
543
-
544
- if (this.loadBalanced) {
545
- maybeClearPinnedConnection(this, {
546
- force: false
547
- });
548
- }
549
- }
550
- }
551
- /**
552
- * This is here to ensure that ClientSession is never serialized to BSON.
553
- */
554
-
555
-
556
- toBSON() {
557
- throw new error_1.MongoRuntimeError('ClientSession cannot be serialized to BSON.');
558
- }
559
- /**
560
- * Starts a transaction and runs a provided function, ensuring the commitTransaction is always attempted when all operations run in the function have completed.
561
- *
562
- * **IMPORTANT:** This method requires the function passed in to return a Promise. That promise must be made by `await`-ing all operations in such a way that rejections are propagated to the returned promise.
563
- *
564
- * **IMPORTANT:** Running operations in parallel is not supported during a transaction. The use of `Promise.all`,
565
- * `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is
566
- * undefined behaviour.
567
- *
568
- * **IMPORTANT:** When running an operation inside a `withTransaction` callback, if it is not
569
- * provided the explicit session in its options, it will not be part of the transaction and it will not respect timeoutMS.
570
- *
571
- *
572
- * @remarks
573
- * - If all operations successfully complete and the `commitTransaction` operation is successful, then the provided function will return the result of the provided function.
574
- * - If the transaction is unable to complete or an error is thrown from within the provided function, then the provided function will throw an error.
575
- * - If the transaction is manually aborted within the provided function it will not throw.
576
- * - If the driver needs to attempt to retry the operations, the provided function may be called multiple times.
577
- *
578
- * Checkout a descriptive example here:
579
- * @see https://www.mongodb.com/blog/post/quick-start-nodejs--mongodb--how-to-implement-transactions
580
- *
581
- * If a command inside withTransaction fails:
582
- * - It may cause the transaction on the server to be aborted.
583
- * - This situation is normally handled transparently by the driver.
584
- * - However, if the application catches such an error and does not rethrow it, the driver will not be able to determine whether the transaction was aborted or not.
585
- * - The driver will then retry the transaction indefinitely.
586
- *
587
- * To avoid this situation, the application must not silently handle errors within the provided function.
588
- * If the application needs to handle errors within, it must await all operations such that if an operation is rejected it becomes the rejection of the callback function passed into withTransaction.
589
- *
590
- * @param fn - callback to run within a transaction
591
- * @param options - optional settings for the transaction
592
- * @returns A raw command response or undefined
593
- */
594
-
595
-
596
- async withTransaction(fn, options) {
597
- const MAX_TIMEOUT = 120000;
598
- const timeoutMS = options?.timeoutMS ?? this.timeoutMS ?? null;
599
- this.timeoutContext = timeoutMS != null ? timeout_1.TimeoutContext.create({
600
- timeoutMS,
601
- serverSelectionTimeoutMS: this.clientOptions.serverSelectionTimeoutMS,
602
- socketTimeoutMS: this.clientOptions.socketTimeoutMS
603
- }) : null;
604
- const startTime = this.timeoutContext?.csotEnabled() ? this.timeoutContext.start : (0, utils_1.now)();
605
- let committed = false;
606
- let result;
607
-
608
- try {
609
- while (!committed) {
610
- this.startTransaction(options); // may throw on error
611
-
612
- try {
613
- const promise = fn(this);
614
-
615
- if (!(0, utils_1.isPromiseLike)(promise)) {
616
- throw new error_1.MongoInvalidArgumentError('Function provided to `withTransaction` must return a Promise');
617
- }
618
-
619
- result = await promise;
620
-
621
- if (this.transaction.state === transactions_1.TxnState.NO_TRANSACTION || this.transaction.state === transactions_1.TxnState.TRANSACTION_COMMITTED || this.transaction.state === transactions_1.TxnState.TRANSACTION_ABORTED) {
622
- // Assume callback intentionally ended the transaction
623
- return result;
624
- }
625
- } catch (fnError) {
626
- if (!(fnError instanceof error_1.MongoError) || fnError instanceof error_1.MongoInvalidArgumentError) {
627
- await this.abortTransaction();
628
- throw fnError;
629
- }
630
-
631
- if (this.transaction.state === transactions_1.TxnState.STARTING_TRANSACTION || this.transaction.state === transactions_1.TxnState.TRANSACTION_IN_PROGRESS) {
632
- await this.abortTransaction();
633
- }
634
-
635
- if (fnError.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError) && (this.timeoutContext != null || (0, utils_1.now)() - startTime < MAX_TIMEOUT)) {
636
- continue;
637
- }
638
-
639
- throw fnError;
640
- }
641
-
642
- while (!committed) {
643
- try {
644
- /*
645
- * We will rely on ClientSession.commitTransaction() to
646
- * apply a majority write concern if commitTransaction is
647
- * being retried (see: DRIVERS-601)
648
- */
649
- await this.commitTransaction();
650
- committed = true;
651
- } catch (commitError) {
652
- /*
653
- * Note: a maxTimeMS error will have the MaxTimeMSExpired
654
- * code (50) and can be reported as a top-level error or
655
- * inside writeConcernError, ex.
656
- * { ok:0, code: 50, codeName: 'MaxTimeMSExpired' }
657
- * { ok:1, writeConcernError: { code: 50, codeName: 'MaxTimeMSExpired' } }
658
- */
659
- if (!isMaxTimeMSExpiredError(commitError) && commitError.hasErrorLabel(error_1.MongoErrorLabel.UnknownTransactionCommitResult) && (this.timeoutContext != null || (0, utils_1.now)() - startTime < MAX_TIMEOUT)) {
660
- continue;
661
- }
662
-
663
- if (commitError.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError) && (this.timeoutContext != null || (0, utils_1.now)() - startTime < MAX_TIMEOUT)) {
664
- break;
665
- }
666
-
667
- throw commitError;
668
- }
669
- }
670
- }
671
-
672
- return result;
673
- } finally {
674
- this.timeoutContext = null;
675
- }
676
- }
677
-
678
- }
679
-
680
- exports.ClientSession = ClientSession;
681
- (0, resource_management_1.configureResourceManagement)(ClientSession.prototype);
682
- const NON_DETERMINISTIC_WRITE_CONCERN_ERRORS = new Set(['CannotSatisfyWriteConcern', 'UnknownReplWriteConcern', 'UnsatisfiableWriteConcern']);
683
-
684
- function shouldUnpinAfterCommitError(commitError) {
685
- if (commitError instanceof error_1.MongoError) {
686
- if ((0, error_1.isRetryableWriteError)(commitError) || commitError instanceof error_1.MongoWriteConcernError || isMaxTimeMSExpiredError(commitError)) {
687
- if (isUnknownTransactionCommitResult(commitError)) {
688
- // per txns spec, must unpin session in this case
689
- return true;
690
- }
691
- } else if (commitError.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
692
- return true;
693
- }
694
- }
695
-
696
- return false;
697
- }
698
-
699
- function shouldAddUnknownTransactionCommitResultLabel(commitError) {
700
- let ok = (0, error_1.isRetryableWriteError)(commitError);
701
- ok ||= commitError instanceof error_1.MongoWriteConcernError;
702
- ok ||= isMaxTimeMSExpiredError(commitError);
703
- ok &&= isUnknownTransactionCommitResult(commitError);
704
- return ok;
705
- }
706
-
707
- function isUnknownTransactionCommitResult(err) {
708
- const isNonDeterministicWriteConcernError = err instanceof error_1.MongoServerError && err.codeName && NON_DETERMINISTIC_WRITE_CONCERN_ERRORS.has(err.codeName);
709
- return isMaxTimeMSExpiredError(err) || !isNonDeterministicWriteConcernError && err.code !== error_1.MONGODB_ERROR_CODES.UnsatisfiableWriteConcern && err.code !== error_1.MONGODB_ERROR_CODES.UnknownReplWriteConcern;
710
- }
711
-
712
- function maybeClearPinnedConnection(session, options) {
713
- // unpin a connection if it has been pinned
714
- const conn = session.pinnedConnection;
715
- const error = options?.error;
716
-
717
- if (session.inTransaction() && error && error instanceof error_1.MongoError && error.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
718
- return;
719
- }
720
-
721
- const topology = session.client.topology; // NOTE: the spec talks about what to do on a network error only, but the tests seem to
722
- // to validate that we don't unpin on _all_ errors?
723
-
724
- if (conn && topology != null) {
725
- const servers = Array.from(topology.s.servers.values());
726
- const loadBalancer = servers[0];
727
-
728
- if (options?.error == null || options?.force) {
729
- loadBalancer.pool.checkIn(conn);
730
- session.pinnedConnection = undefined;
731
- conn.emit(constants_1.UNPINNED, session.transaction.state !== transactions_1.TxnState.NO_TRANSACTION ? metrics_1.ConnectionPoolMetrics.TXN : metrics_1.ConnectionPoolMetrics.CURSOR);
732
-
733
- if (options?.forceClear) {
734
- loadBalancer.pool.clear({
735
- serviceId: conn.serviceId
736
- });
737
- }
738
- }
739
- }
740
- }
741
-
742
- function isMaxTimeMSExpiredError(err) {
743
- if (err == null || !(err instanceof error_1.MongoServerError)) {
744
- return false;
745
- }
746
-
747
- return err.code === error_1.MONGODB_ERROR_CODES.MaxTimeMSExpired || err.writeConcernError?.code === error_1.MONGODB_ERROR_CODES.MaxTimeMSExpired;
748
- }
749
- /**
750
- * Reflects the existence of a session on the server. Can be reused by the session pool.
751
- * WARNING: not meant to be instantiated directly. For internal use only.
752
- * @public
753
- */
754
-
755
-
756
- class ServerSession {
757
- /** @internal */
758
- constructor(cloned) {
759
- if (cloned != null) {
760
- const idBytes = Buffer.allocUnsafe(16);
761
- idBytes.set(cloned.id.id.buffer);
762
- this.id = {
763
- id: new bson_1.Binary(idBytes, cloned.id.id.sub_type)
764
- };
765
- this.lastUse = cloned.lastUse;
766
- this.txnNumber = cloned.txnNumber;
767
- this.isDirty = cloned.isDirty;
768
- return;
769
- }
770
-
771
- this.id = {
772
- id: new bson_1.Binary((0, utils_1.uuidV4)(), bson_1.Binary.SUBTYPE_UUID)
773
- };
774
- this.lastUse = (0, utils_1.now)();
775
- this.txnNumber = 0;
776
- this.isDirty = false;
777
- }
778
- /**
779
- * Determines if the server session has timed out.
780
- *
781
- * @param sessionTimeoutMinutes - The server's "logicalSessionTimeoutMinutes"
782
- */
783
-
784
-
785
- hasTimedOut(sessionTimeoutMinutes) {
786
- // Take the difference of the lastUse timestamp and now, which will result in a value in
787
- // milliseconds, and then convert milliseconds to minutes to compare to `sessionTimeoutMinutes`
788
- const idleTimeMinutes = Math.round((0, utils_1.calculateDurationInMs)(this.lastUse) % 86400000 % 3600000 / 60000);
789
- return idleTimeMinutes > sessionTimeoutMinutes - 1;
790
- }
791
-
792
- }
793
-
794
- exports.ServerSession = ServerSession;
795
- /**
796
- * Maintains a pool of Server Sessions.
797
- * For internal use only
798
- * @internal
799
- */
800
-
801
- class ServerSessionPool {
802
- constructor(client) {
803
- if (client == null) {
804
- throw new error_1.MongoRuntimeError('ServerSessionPool requires a MongoClient');
805
- }
806
-
807
- this.client = client;
808
- this.sessions = new utils_1.List();
809
- }
810
- /**
811
- * Acquire a Server Session from the pool.
812
- * Iterates through each session in the pool, removing any stale sessions
813
- * along the way. The first non-stale session found is removed from the
814
- * pool and returned. If no non-stale session is found, a new ServerSession is created.
815
- */
816
-
817
-
818
- acquire() {
819
- const sessionTimeoutMinutes = this.client.topology?.logicalSessionTimeoutMinutes ?? 10;
820
- let session = null; // Try to obtain from session pool
821
-
822
- while (this.sessions.length > 0) {
823
- const potentialSession = this.sessions.shift();
824
-
825
- if (potentialSession != null && (!!this.client.topology?.loadBalanced || !potentialSession.hasTimedOut(sessionTimeoutMinutes))) {
826
- session = potentialSession;
827
- break;
828
- }
829
- } // If nothing valid came from the pool make a new one
830
-
831
-
832
- if (session == null) {
833
- session = new ServerSession();
834
- }
835
-
836
- return session;
837
- }
838
- /**
839
- * Release a session to the session pool
840
- * Adds the session back to the session pool if the session has not timed out yet.
841
- * This method also removes any stale sessions from the pool.
842
- *
843
- * @param session - The session to release to the pool
844
- */
845
-
846
-
847
- release(session) {
848
- const sessionTimeoutMinutes = this.client.topology?.logicalSessionTimeoutMinutes ?? 10;
849
-
850
- if (this.client.topology?.loadBalanced && !sessionTimeoutMinutes) {
851
- this.sessions.unshift(session);
852
- }
853
-
854
- if (!sessionTimeoutMinutes) {
855
- return;
856
- }
857
-
858
- this.sessions.prune(session => session.hasTimedOut(sessionTimeoutMinutes));
859
-
860
- if (!session.hasTimedOut(sessionTimeoutMinutes)) {
861
- if (session.isDirty) {
862
- return;
863
- } // otherwise, readd this session to the session pool
864
-
865
-
866
- this.sessions.unshift(session);
867
- }
868
- }
869
-
870
- }
871
-
872
- exports.ServerSessionPool = ServerSessionPool;
873
- /**
874
- * Optionally decorate a command with sessions specific keys
875
- *
876
- * @param session - the session tracking transaction state
877
- * @param command - the command to decorate
878
- * @param options - Optional settings passed to calling operation
879
- *
880
- * @internal
881
- */
882
-
883
- function applySession(session, command, options) {
884
- if (session.hasEnded) {
885
- return new error_1.MongoExpiredSessionError();
886
- } // May acquire serverSession here
887
-
888
-
889
- const serverSession = session.serverSession;
890
-
891
- if (serverSession == null) {
892
- return new error_1.MongoRuntimeError('Unable to acquire server session');
893
- }
894
-
895
- if (options.writeConcern?.w === 0) {
896
- if (session && session.explicit) {
897
- // Error if user provided an explicit session to an unacknowledged write (SPEC-1019)
898
- return new error_1.MongoAPIError('Cannot have explicit session with unacknowledged writes');
899
- }
900
-
901
- return;
902
- } // mark the last use of this session, and apply the `lsid`
903
-
904
-
905
- serverSession.lastUse = (0, utils_1.now)();
906
- command.lsid = serverSession.id;
907
- const inTxnOrTxnCommand = session.inTransaction() || (0, transactions_1.isTransactionCommand)(command);
908
- const isRetryableWrite = !!options.willRetryWrite;
909
-
910
- if (isRetryableWrite || inTxnOrTxnCommand) {
911
- serverSession.txnNumber += session.txnNumberIncrement;
912
- session.txnNumberIncrement = 0; // TODO(NODE-2674): Preserve int64 sent from MongoDB
913
-
914
- command.txnNumber = bson_1.Long.fromNumber(serverSession.txnNumber);
915
- }
916
-
917
- if (!inTxnOrTxnCommand) {
918
- if (session.transaction.state !== transactions_1.TxnState.NO_TRANSACTION) {
919
- session.transaction.transition(transactions_1.TxnState.NO_TRANSACTION);
920
- }
921
-
922
- if (session.supports.causalConsistency && session.operationTime && (0, utils_1.commandSupportsReadConcern)(command)) {
923
- command.readConcern = command.readConcern || {};
924
- Object.assign(command.readConcern, {
925
- afterClusterTime: session.operationTime
926
- });
927
- } else if (session.snapshotEnabled) {
928
- command.readConcern = command.readConcern || {
929
- level: read_concern_1.ReadConcernLevel.snapshot
930
- };
931
-
932
- if (session.snapshotTime != null) {
933
- Object.assign(command.readConcern, {
934
- atClusterTime: session.snapshotTime
935
- });
936
- }
937
- }
938
-
939
- return;
940
- } // now attempt to apply transaction-specific sessions data
941
- // `autocommit` must always be false to differentiate from retryable writes
942
-
943
-
944
- command.autocommit = false;
945
-
946
- if (session.transaction.state === transactions_1.TxnState.STARTING_TRANSACTION) {
947
- session.transaction.transition(transactions_1.TxnState.TRANSACTION_IN_PROGRESS);
948
- command.startTransaction = true;
949
- const readConcern = session.transaction.options.readConcern || session?.clientOptions?.readConcern;
950
-
951
- if (readConcern) {
952
- command.readConcern = readConcern;
953
- }
954
-
955
- if (session.supports.causalConsistency && session.operationTime) {
956
- command.readConcern = command.readConcern || {};
957
- Object.assign(command.readConcern, {
958
- afterClusterTime: session.operationTime
959
- });
960
- }
961
- }
962
-
963
- return;
964
- }
965
-
966
- function updateSessionFromResponse(session, document) {
967
- if (document.$clusterTime) {
968
- (0, common_1._advanceClusterTime)(session, document.$clusterTime);
969
- }
970
-
971
- if (document.operationTime && session && session.supports.causalConsistency) {
972
- session.advanceOperationTime(document.operationTime);
973
- }
974
-
975
- if (document.recoveryToken && session && session.inTransaction()) {
976
- session.transaction._recoveryToken = document.recoveryToken;
977
- }
978
-
979
- if (session?.snapshotEnabled && session.snapshotTime == null) {
980
- // find and aggregate commands return atClusterTime on the cursor
981
- // distinct includes it in the response body
982
- const atClusterTime = document.atClusterTime;
983
-
984
- if (atClusterTime) {
985
- session.snapshotTime = atClusterTime;
986
- }
987
- }
988
- }