oxygen-cli 1.40.1 → 1.40.2-beta.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 (441) hide show
  1. package/CHANGELOG.md +1742 -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 +2 -1
  17. package/build/index.js +1 -1
  18. package/build/lib/cli-util.js +5 -1
  19. package/build/lib/debugger.js +1 -1
  20. package/build/lib/img-merge.js +1 -1
  21. package/build/lib/launcher.js +1 -1
  22. package/build/lib/logger.js +43 -43
  23. package/build/lib/moduleRequire.js +1 -1
  24. package/build/lib/parallel-launcher.js +1 -1
  25. package/build/lib/param-manager.js +1 -1
  26. package/build/lib/param-reader-csv.js +1 -1
  27. package/build/lib/param-reader-excel.js +1 -1
  28. package/build/lib/param-reader-json.js +1 -1
  29. package/build/lib/text-to-image.js +1 -1
  30. package/build/lib/util.js +1 -1
  31. package/build/model/case-result.js +1 -1
  32. package/build/model/failure.js +1 -1
  33. package/build/model/status.js +1 -1
  34. package/build/model/step-result.js +1 -1
  35. package/build/model/suite-result.js +1 -1
  36. package/build/model/test-result.js +1 -1
  37. package/build/model/testcase.js +1 -1
  38. package/build/model/testsuite.js +1 -1
  39. package/build/ox_modules/index.js +9 -1
  40. package/build/ox_modules/module-assert.js +37 -37
  41. package/build/ox_modules/module-date.js +24 -24
  42. package/build/ox_modules/module-db.js +52 -52
  43. package/build/ox_modules/module-email.js +59 -59
  44. package/build/ox_modules/module-eyes.js +34 -34
  45. package/build/ox_modules/module-http/ntlm-util.js +10 -10
  46. package/build/ox_modules/module-http/ntlm.js +15 -15
  47. package/build/ox_modules/module-http.js +132 -132
  48. package/build/ox_modules/module-log.js +27 -27
  49. package/build/ox_modules/module-mailinator.js +87 -87
  50. package/build/ox_modules/module-mob/commands/alertAccept.js +17 -17
  51. package/build/ox_modules/module-mob/commands/alertDismiss.js +17 -17
  52. package/build/ox_modules/module-mob/commands/assertAlert.js +20 -20
  53. package/build/ox_modules/module-mob/commands/assertText.js +21 -21
  54. package/build/ox_modules/module-mob/commands/assertTitle.js +19 -19
  55. package/build/ox_modules/module-mob/commands/assertValue.js +18 -18
  56. package/build/ox_modules/module-mob/commands/back.js +16 -16
  57. package/build/ox_modules/module-mob/commands/clear.js +19 -19
  58. package/build/ox_modules/module-mob/commands/click.js +17 -17
  59. package/build/ox_modules/module-mob/commands/clickHidden.js +17 -17
  60. package/build/ox_modules/module-mob/commands/clickLong.js +18 -18
  61. package/build/ox_modules/module-mob/commands/clickMultipleTimes.js +18 -18
  62. package/build/ox_modules/module-mob/commands/closeApp.js +16 -16
  63. package/build/ox_modules/module-mob/commands/debug.js +16 -16
  64. package/build/ox_modules/module-mob/commands/dragAndDrop.js +19 -19
  65. package/build/ox_modules/module-mob/commands/enableNetwork.js +27 -27
  66. package/build/ox_modules/module-mob/commands/execute.js +21 -21
  67. package/build/ox_modules/module-mob/commands/findElement.js +20 -20
  68. package/build/ox_modules/module-mob/commands/findElements.js +23 -23
  69. package/build/ox_modules/module-mob/commands/getAlertText.js +17 -17
  70. package/build/ox_modules/module-mob/commands/getAppiumLogs.js +16 -16
  71. package/build/ox_modules/module-mob/commands/getBrowserLogs.js +16 -16
  72. package/build/ox_modules/module-mob/commands/getCurrentActivity.js +15 -15
  73. package/build/ox_modules/module-mob/commands/getCurrentPackage.js +15 -15
  74. package/build/ox_modules/module-mob/commands/getDeviceLogs.js +16 -16
  75. package/build/ox_modules/module-mob/commands/getDeviceTime.js +16 -16
  76. package/build/ox_modules/module-mob/commands/getLocation.js +20 -20
  77. package/build/ox_modules/module-mob/commands/getSource.js +16 -16
  78. package/build/ox_modules/module-mob/commands/getText.js +18 -18
  79. package/build/ox_modules/module-mob/commands/getTitle.js +13 -13
  80. package/build/ox_modules/module-mob/commands/getUrl.js +17 -17
  81. package/build/ox_modules/module-mob/commands/getValue.js +18 -18
  82. package/build/ox_modules/module-mob/commands/getWindowHandles.js +17 -17
  83. package/build/ox_modules/module-mob/commands/hideKeyboard.js +21 -21
  84. package/build/ox_modules/module-mob/commands/index.js +1 -1
  85. package/build/ox_modules/module-mob/commands/installApp.js +16 -16
  86. package/build/ox_modules/module-mob/commands/isAppInstalled.js +16 -16
  87. package/build/ox_modules/module-mob/commands/isCheckable.js +18 -18
  88. package/build/ox_modules/module-mob/commands/isChecked.js +18 -18
  89. package/build/ox_modules/module-mob/commands/isClickable.js +18 -18
  90. package/build/ox_modules/module-mob/commands/isExist.js +19 -19
  91. package/build/ox_modules/module-mob/commands/isSelected.js +23 -23
  92. package/build/ox_modules/module-mob/commands/isVisible.js +19 -19
  93. package/build/ox_modules/module-mob/commands/isWebViewContext.js +16 -16
  94. package/build/ox_modules/module-mob/commands/launchApp.js +15 -15
  95. package/build/ox_modules/module-mob/commands/longPressKeyCode.js +18 -18
  96. package/build/ox_modules/module-mob/commands/open.js +17 -17
  97. package/build/ox_modules/module-mob/commands/pause.js +16 -16
  98. package/build/ox_modules/module-mob/commands/removeApp.js +16 -16
  99. package/build/ox_modules/module-mob/commands/resetApp.js +15 -15
  100. package/build/ox_modules/module-mob/commands/scrollIntoElement.js +22 -22
  101. package/build/ox_modules/module-mob/commands/scrollIntoView.js +27 -27
  102. package/build/ox_modules/module-mob/commands/select.js +24 -24
  103. package/build/ox_modules/module-mob/commands/selectFrame.js +23 -23
  104. package/build/ox_modules/module-mob/commands/selectWindow.js +28 -28
  105. package/build/ox_modules/module-mob/commands/sendKeys.js +29 -29
  106. package/build/ox_modules/module-mob/commands/setContext.js +16 -16
  107. package/build/ox_modules/module-mob/commands/setNativeContext.js +15 -15
  108. package/build/ox_modules/module-mob/commands/setTimeout.js +21 -21
  109. package/build/ox_modules/module-mob/commands/setWebViewContext.js +16 -16
  110. package/build/ox_modules/module-mob/commands/shake.js +16 -16
  111. package/build/ox_modules/module-mob/commands/smsClickLink.js +19 -19
  112. package/build/ox_modules/module-mob/commands/smsGetText.js +20 -20
  113. package/build/ox_modules/module-mob/commands/swipe.js +20 -20
  114. package/build/ox_modules/module-mob/commands/swipeElement.js +20 -20
  115. package/build/ox_modules/module-mob/commands/swipeScreen.js +20 -20
  116. package/build/ox_modules/module-mob/commands/takeScreenshot.js +17 -17
  117. package/build/ox_modules/module-mob/commands/tap.js +17 -17
  118. package/build/ox_modules/module-mob/commands/type.js +20 -20
  119. package/build/ox_modules/module-mob/commands/unlockPattern.js +22 -22
  120. package/build/ox_modules/module-mob/commands/waitForExist.js +18 -18
  121. package/build/ox_modules/module-mob/commands/waitForInteractable.js +17 -17
  122. package/build/ox_modules/module-mob/commands/waitForVisible.js +17 -17
  123. package/build/ox_modules/module-mob.js +74 -74
  124. package/build/ox_modules/module-mongo.js +302 -0
  125. package/build/ox_modules/module-pdf.js +35 -35
  126. package/build/ox_modules/module-proxy.js +77 -77
  127. package/build/ox_modules/module-serial.js +55 -55
  128. package/build/ox_modules/module-shell.js +25 -25
  129. package/build/ox_modules/module-soap.js +72 -72
  130. package/build/ox_modules/module-twilio.js +41 -41
  131. package/build/ox_modules/module-utils.js +91 -91
  132. package/build/ox_modules/module-web/commands/alertAccept.js +17 -17
  133. package/build/ox_modules/module-web/commands/alertDismiss.js +17 -17
  134. package/build/ox_modules/module-web/commands/assertAlert.js +20 -20
  135. package/build/ox_modules/module-web/commands/assertExist.js +17 -17
  136. package/build/ox_modules/module-web/commands/assertSelectedLabel.js +21 -21
  137. package/build/ox_modules/module-web/commands/assertSelectedValue.js +21 -21
  138. package/build/ox_modules/module-web/commands/assertText.js +21 -21
  139. package/build/ox_modules/module-web/commands/assertTextNotPresent.js +18 -18
  140. package/build/ox_modules/module-web/commands/assertTextPresent.js +18 -18
  141. package/build/ox_modules/module-web/commands/assertTitle.js +19 -19
  142. package/build/ox_modules/module-web/commands/assertValue.js +20 -20
  143. package/build/ox_modules/module-web/commands/back.js +16 -16
  144. package/build/ox_modules/module-web/commands/clear.js +18 -18
  145. package/build/ox_modules/module-web/commands/click.js +25 -25
  146. package/build/ox_modules/module-web/commands/clickHidden.js +23 -23
  147. package/build/ox_modules/module-web/commands/closeWindow.js +15 -15
  148. package/build/ox_modules/module-web/commands/debug.js +15 -15
  149. package/build/ox_modules/module-web/commands/deleteCookies.js +12 -12
  150. package/build/ox_modules/module-web/commands/deselect.js +22 -22
  151. package/build/ox_modules/module-web/commands/doubleClick.js +17 -17
  152. package/build/ox_modules/module-web/commands/dragAndDrop.js +20 -20
  153. package/build/ox_modules/module-web/commands/execute.js +24 -24
  154. package/build/ox_modules/module-web/commands/fileBrowse.js +18 -18
  155. package/build/ox_modules/module-web/commands/findElement.js +19 -19
  156. package/build/ox_modules/module-web/commands/findElements.js +22 -22
  157. package/build/ox_modules/module-web/commands/fullscreenWindow.js +14 -14
  158. package/build/ox_modules/module-web/commands/getAlertText.js +16 -16
  159. package/build/ox_modules/module-web/commands/getAttribute.js +19 -19
  160. package/build/ox_modules/module-web/commands/getBrowserLogs.js +17 -17
  161. package/build/ox_modules/module-web/commands/getCookies.js +13 -13
  162. package/build/ox_modules/module-web/commands/getCssValue.js +19 -19
  163. package/build/ox_modules/module-web/commands/getElementCount.js +17 -17
  164. package/build/ox_modules/module-web/commands/getHTML.js +17 -17
  165. package/build/ox_modules/module-web/commands/getSource.js +16 -16
  166. package/build/ox_modules/module-web/commands/getText.js +18 -18
  167. package/build/ox_modules/module-web/commands/getTitle.js +12 -12
  168. package/build/ox_modules/module-web/commands/getUrl.js +16 -16
  169. package/build/ox_modules/module-web/commands/getValue.js +18 -18
  170. package/build/ox_modules/module-web/commands/getWindowHandles.js +16 -16
  171. package/build/ox_modules/module-web/commands/getWindowSize.js +16 -16
  172. package/build/ox_modules/module-web/commands/getXMLPageSource.js +16 -16
  173. package/build/ox_modules/module-web/commands/index.js +1 -1
  174. package/build/ox_modules/module-web/commands/isAlertPresent.js +16 -16
  175. package/build/ox_modules/module-web/commands/isChecked.js +18 -18
  176. package/build/ox_modules/module-web/commands/isExist.js +19 -19
  177. package/build/ox_modules/module-web/commands/isInteractable.js +22 -22
  178. package/build/ox_modules/module-web/commands/isSelected.js +23 -23
  179. package/build/ox_modules/module-web/commands/isVisible.js +19 -19
  180. package/build/ox_modules/module-web/commands/makeVisible.js +25 -25
  181. package/build/ox_modules/module-web/commands/maximizeWindow.js +14 -14
  182. package/build/ox_modules/module-web/commands/minimizeWindow.js +14 -14
  183. package/build/ox_modules/module-web/commands/mock.js +20 -20
  184. package/build/ox_modules/module-web/commands/mockClearAll.js +12 -12
  185. package/build/ox_modules/module-web/commands/mockRestoreAll.js +12 -12
  186. package/build/ox_modules/module-web/commands/newWindow.js +16 -16
  187. package/build/ox_modules/module-web/commands/open.js +16 -16
  188. package/build/ox_modules/module-web/commands/pause.js +15 -15
  189. package/build/ox_modules/module-web/commands/point.js +21 -21
  190. package/build/ox_modules/module-web/commands/pointJS.js +15 -15
  191. package/build/ox_modules/module-web/commands/refresh.js +15 -15
  192. package/build/ox_modules/module-web/commands/rightClick.js +17 -17
  193. package/build/ox_modules/module-web/commands/rightClickActions.js +19 -19
  194. package/build/ox_modules/module-web/commands/scrollToElement.js +21 -21
  195. package/build/ox_modules/module-web/commands/select.js +23 -23
  196. package/build/ox_modules/module-web/commands/selectFrame.js +24 -24
  197. package/build/ox_modules/module-web/commands/selectWindow.js +27 -27
  198. package/build/ox_modules/module-web/commands/sendKeys.js +22 -22
  199. package/build/ox_modules/module-web/commands/setAutoWaitForAngular.js +20 -20
  200. package/build/ox_modules/module-web/commands/setTimeout.js +21 -21
  201. package/build/ox_modules/module-web/commands/setWindowSize.js +17 -17
  202. package/build/ox_modules/module-web/commands/takeScreenshot.js +17 -17
  203. package/build/ox_modules/module-web/commands/type.js +20 -20
  204. package/build/ox_modules/module-web/commands/verifyAlert.js +20 -20
  205. package/build/ox_modules/module-web/commands/verifyExist.js +17 -17
  206. package/build/ox_modules/module-web/commands/verifySelectedLabel.js +21 -21
  207. package/build/ox_modules/module-web/commands/verifySelectedValue.js +21 -21
  208. package/build/ox_modules/module-web/commands/verifyText.js +21 -21
  209. package/build/ox_modules/module-web/commands/verifyTextNotPresent.js +18 -18
  210. package/build/ox_modules/module-web/commands/verifyTextPresent.js +18 -18
  211. package/build/ox_modules/module-web/commands/verifyTitle.js +19 -19
  212. package/build/ox_modules/module-web/commands/verifyValue.js +20 -20
  213. package/build/ox_modules/module-web/commands/waitForAngular.js +19 -19
  214. package/build/ox_modules/module-web/commands/waitForExist.js +17 -17
  215. package/build/ox_modules/module-web/commands/waitForInteractable.js +17 -17
  216. package/build/ox_modules/module-web/commands/waitForNotExist.js +17 -17
  217. package/build/ox_modules/module-web/commands/waitForNotText.js +20 -20
  218. package/build/ox_modules/module-web/commands/waitForNotValue.js +20 -20
  219. package/build/ox_modules/module-web/commands/waitForText.js +20 -20
  220. package/build/ox_modules/module-web/commands/waitForValue.js +20 -20
  221. package/build/ox_modules/module-web/commands/waitForVisible.js +17 -17
  222. package/build/ox_modules/module-web/commands/waitForWindow.js +22 -22
  223. package/build/ox_modules/module-web.js +94 -94
  224. package/build/ox_modules/module-win/commands/assertText.js +17 -17
  225. package/build/ox_modules/module-win/commands/assertTitle.js +15 -15
  226. package/build/ox_modules/module-win/commands/assertValue.js +14 -14
  227. package/build/ox_modules/module-win/commands/back.js +11 -11
  228. package/build/ox_modules/module-win/commands/clear.js +13 -13
  229. package/build/ox_modules/module-win/commands/click.js +13 -13
  230. package/build/ox_modules/module-win/commands/clickLong.js +14 -14
  231. package/build/ox_modules/module-win/commands/clickMultipleTimes.js +14 -14
  232. package/build/ox_modules/module-win/commands/findElement.js +15 -15
  233. package/build/ox_modules/module-win/commands/findElements.js +15 -15
  234. package/build/ox_modules/module-win/commands/getAppiumLogs.js +12 -12
  235. package/build/ox_modules/module-win/commands/getCurrentWindowHandle.js +15 -15
  236. package/build/ox_modules/module-win/commands/getLocation.js +14 -14
  237. package/build/ox_modules/module-win/commands/getSource.js +12 -12
  238. package/build/ox_modules/module-win/commands/getText.js +14 -14
  239. package/build/ox_modules/module-win/commands/getValue.js +14 -14
  240. package/build/ox_modules/module-win/commands/getWindowHandles.js +15 -15
  241. package/build/ox_modules/module-win/commands/index.js +1 -1
  242. package/build/ox_modules/module-win/commands/isCheckable.js +14 -14
  243. package/build/ox_modules/module-win/commands/isChecked.js +14 -14
  244. package/build/ox_modules/module-win/commands/isClickable.js +14 -14
  245. package/build/ox_modules/module-win/commands/isExist.js +15 -15
  246. package/build/ox_modules/module-win/commands/isSelected.js +14 -14
  247. package/build/ox_modules/module-win/commands/isVisible.js +15 -15
  248. package/build/ox_modules/module-win/commands/open.js +13 -13
  249. package/build/ox_modules/module-win/commands/pause.js +12 -12
  250. package/build/ox_modules/module-win/commands/rightClick.js +13 -13
  251. package/build/ox_modules/module-win/commands/selectWindow.js +23 -23
  252. package/build/ox_modules/module-win/commands/sendKeys.js +22 -22
  253. package/build/ox_modules/module-win/commands/setTimeout.js +17 -17
  254. package/build/ox_modules/module-win/commands/takeScreenshot.js +16 -16
  255. package/build/ox_modules/module-win/commands/tap.js +13 -13
  256. package/build/ox_modules/module-win/commands/type.js +16 -16
  257. package/build/ox_modules/module-win/commands/waitForExist.js +14 -14
  258. package/build/ox_modules/module-win/commands/waitForInteractable.js +16 -16
  259. package/build/ox_modules/module-win/commands/waitForVisible.js +13 -13
  260. package/build/ox_modules/module-win.js +47 -47
  261. package/build/ox_modules/utils.js +8 -8
  262. package/build/ox_reporters/excel/template.json +48 -48
  263. package/build/ox_reporters/html/index.ejs +163 -163
  264. package/build/ox_reporters/html/summary.ejs +77 -77
  265. package/build/ox_reporters/html/tests-details.ejs +134 -134
  266. package/build/ox_reporters/html/tests-devices-browsers.ejs +83 -83
  267. package/build/ox_reporters/reporter-excel.js +1 -1
  268. package/build/ox_reporters/reporter-html.js +1 -1
  269. package/build/ox_reporters/reporter-json.js +1 -1
  270. package/build/ox_reporters/reporter-junit.js +1 -1
  271. package/build/ox_reporters/reporter-pdf.js +1 -1
  272. package/build/ox_reporters/reporter-rp.js +1 -1
  273. package/build/ox_reporters/reporter-xml.js +1 -1
  274. package/build/ox_services/service-devtools/submodule-network.js +1 -1
  275. package/build/ox_services/service-devtools.js +1 -1
  276. package/build/reporter/FileReporterBase.js +1 -1
  277. package/build/reporter/ReportAggregator.js +13 -5
  278. package/build/reporter/ReporterBase.js +1 -1
  279. package/build/reporter/WebSocketReporter.js +1 -1
  280. package/build/runners/WorkerProcess.js +1 -1
  281. package/build/runners/cucumber/CucumberEventListener.js +1 -1
  282. package/build/runners/cucumber/CucumberReporter.js +1 -1
  283. package/build/runners/cucumber/CucumberWorker.js +1 -1
  284. package/build/runners/cucumber/index.js +1 -1
  285. package/build/runners/cucumber/worker.js +1 -1
  286. package/build/runners/index.js +1 -1
  287. package/build/runners/oxygen/OxygenWorker.js +1 -1
  288. package/build/runners/oxygen/index.js +1 -1
  289. package/build/runners/oxygen/worker.js +1 -1
  290. package/config/default.json +6 -6
  291. package/log.txt +1614 -0
  292. package/package.json +139 -137
  293. package/reports/2025-06-08_231627/report.html +440 -0
  294. package/reports/2025-06-09_223615/report.html +440 -0
  295. package/transpiled/mongodb/etc/prepare.js +18 -0
  296. package/transpiled/mongodb/lib/admin.js +182 -0
  297. package/transpiled/mongodb/lib/beta.js +26 -0
  298. package/transpiled/mongodb/lib/bson.js +220 -0
  299. package/transpiled/mongodb/lib/bulk/common.js +1041 -0
  300. package/transpiled/mongodb/lib/bulk/ordered.js +76 -0
  301. package/transpiled/mongodb/lib/bulk/unordered.js +102 -0
  302. package/transpiled/mongodb/lib/change_stream.js +517 -0
  303. package/transpiled/mongodb/lib/client-side-encryption/auto_encrypter.js +329 -0
  304. package/transpiled/mongodb/lib/client-side-encryption/client_encryption.js +779 -0
  305. package/transpiled/mongodb/lib/client-side-encryption/crypto_callbacks.js +95 -0
  306. package/transpiled/mongodb/lib/client-side-encryption/errors.js +171 -0
  307. package/transpiled/mongodb/lib/client-side-encryption/mongocryptd_manager.js +98 -0
  308. package/transpiled/mongodb/lib/client-side-encryption/providers/aws.js +34 -0
  309. package/transpiled/mongodb/lib/client-side-encryption/providers/azure.js +186 -0
  310. package/transpiled/mongodb/lib/client-side-encryption/providers/gcp.js +29 -0
  311. package/transpiled/mongodb/lib/client-side-encryption/providers/index.js +58 -0
  312. package/transpiled/mongodb/lib/client-side-encryption/state_machine.js +505 -0
  313. package/transpiled/mongodb/lib/cmap/auth/auth_provider.js +63 -0
  314. package/transpiled/mongodb/lib/cmap/auth/aws_temporary_credentials.js +167 -0
  315. package/transpiled/mongodb/lib/cmap/auth/gssapi.js +207 -0
  316. package/transpiled/mongodb/lib/cmap/auth/mongo_credentials.js +193 -0
  317. package/transpiled/mongodb/lib/cmap/auth/mongodb_aws.js +181 -0
  318. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +101 -0
  319. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +81 -0
  320. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/callback_workflow.js +174 -0
  321. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/command_builders.js +59 -0
  322. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +58 -0
  323. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +138 -0
  324. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +42 -0
  325. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/token_cache.js +71 -0
  326. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +34 -0
  327. package/transpiled/mongodb/lib/cmap/auth/mongodb_oidc.js +111 -0
  328. package/transpiled/mongodb/lib/cmap/auth/plain.js +43 -0
  329. package/transpiled/mongodb/lib/cmap/auth/providers.js +22 -0
  330. package/transpiled/mongodb/lib/cmap/auth/scram.js +318 -0
  331. package/transpiled/mongodb/lib/cmap/auth/x509.js +61 -0
  332. package/transpiled/mongodb/lib/cmap/command_monitoring_events.js +266 -0
  333. package/transpiled/mongodb/lib/cmap/commands.js +605 -0
  334. package/transpiled/mongodb/lib/cmap/connect.js +418 -0
  335. package/transpiled/mongodb/lib/cmap/connection.js +673 -0
  336. package/transpiled/mongodb/lib/cmap/connection_pool.js +688 -0
  337. package/transpiled/mongodb/lib/cmap/connection_pool_events.js +254 -0
  338. package/transpiled/mongodb/lib/cmap/errors.js +128 -0
  339. package/transpiled/mongodb/lib/cmap/handshake/client_metadata.js +278 -0
  340. package/transpiled/mongodb/lib/cmap/metrics.js +67 -0
  341. package/transpiled/mongodb/lib/cmap/stream_description.js +74 -0
  342. package/transpiled/mongodb/lib/cmap/wire_protocol/compression.js +196 -0
  343. package/transpiled/mongodb/lib/cmap/wire_protocol/constants.js +19 -0
  344. package/transpiled/mongodb/lib/cmap/wire_protocol/on_data.js +144 -0
  345. package/transpiled/mongodb/lib/cmap/wire_protocol/on_demand/document.js +278 -0
  346. package/transpiled/mongodb/lib/cmap/wire_protocol/responses.js +376 -0
  347. package/transpiled/mongodb/lib/cmap/wire_protocol/shared.js +49 -0
  348. package/transpiled/mongodb/lib/collection.js +852 -0
  349. package/transpiled/mongodb/lib/connection_string.js +1452 -0
  350. package/transpiled/mongodb/lib/constants.js +162 -0
  351. package/transpiled/mongodb/lib/cursor/abstract_cursor.js +1082 -0
  352. package/transpiled/mongodb/lib/cursor/aggregation_cursor.js +227 -0
  353. package/transpiled/mongodb/lib/cursor/change_stream_cursor.js +136 -0
  354. package/transpiled/mongodb/lib/cursor/client_bulk_write_cursor.js +69 -0
  355. package/transpiled/mongodb/lib/cursor/find_cursor.js +476 -0
  356. package/transpiled/mongodb/lib/cursor/list_collections_cursor.js +48 -0
  357. package/transpiled/mongodb/lib/cursor/list_indexes_cursor.js +46 -0
  358. package/transpiled/mongodb/lib/cursor/list_search_indexes_cursor.js +30 -0
  359. package/transpiled/mongodb/lib/cursor/run_command_cursor.js +125 -0
  360. package/transpiled/mongodb/lib/db.js +467 -0
  361. package/transpiled/mongodb/lib/deps.js +174 -0
  362. package/transpiled/mongodb/lib/encrypter.js +129 -0
  363. package/transpiled/mongodb/lib/error.js +1550 -0
  364. package/transpiled/mongodb/lib/explain.js +122 -0
  365. package/transpiled/mongodb/lib/gridfs/download.js +369 -0
  366. package/transpiled/mongodb/lib/gridfs/index.js +240 -0
  367. package/transpiled/mongodb/lib/gridfs/upload.js +446 -0
  368. package/transpiled/mongodb/lib/index.js +975 -0
  369. package/transpiled/mongodb/lib/mongo_client.js +626 -0
  370. package/transpiled/mongodb/lib/mongo_client_auth_providers.js +98 -0
  371. package/transpiled/mongodb/lib/mongo_logger.js +812 -0
  372. package/transpiled/mongodb/lib/mongo_types.js +71 -0
  373. package/transpiled/mongodb/lib/operations/aggregate.js +129 -0
  374. package/transpiled/mongodb/lib/operations/bulk_write.js +48 -0
  375. package/transpiled/mongodb/lib/operations/client_bulk_write/client_bulk_write.js +96 -0
  376. package/transpiled/mongodb/lib/operations/client_bulk_write/command_builder.js +409 -0
  377. package/transpiled/mongodb/lib/operations/client_bulk_write/common.js +5 -0
  378. package/transpiled/mongodb/lib/operations/client_bulk_write/executor.js +144 -0
  379. package/transpiled/mongodb/lib/operations/client_bulk_write/results_merger.js +228 -0
  380. package/transpiled/mongodb/lib/operations/collections.js +49 -0
  381. package/transpiled/mongodb/lib/operations/command.js +102 -0
  382. package/transpiled/mongodb/lib/operations/count.js +60 -0
  383. package/transpiled/mongodb/lib/operations/create_collection.js +109 -0
  384. package/transpiled/mongodb/lib/operations/delete.js +134 -0
  385. package/transpiled/mongodb/lib/operations/distinct.js +77 -0
  386. package/transpiled/mongodb/lib/operations/drop.js +102 -0
  387. package/transpiled/mongodb/lib/operations/estimated_document_count.js +47 -0
  388. package/transpiled/mongodb/lib/operations/execute_operation.js +251 -0
  389. package/transpiled/mongodb/lib/operations/find.js +197 -0
  390. package/transpiled/mongodb/lib/operations/find_and_modify.js +191 -0
  391. package/transpiled/mongodb/lib/operations/get_more.js +84 -0
  392. package/transpiled/mongodb/lib/operations/indexes.js +197 -0
  393. package/transpiled/mongodb/lib/operations/insert.js +138 -0
  394. package/transpiled/mongodb/lib/operations/is_capped.js +44 -0
  395. package/transpiled/mongodb/lib/operations/kill_cursors.js +58 -0
  396. package/transpiled/mongodb/lib/operations/list_collections.js +66 -0
  397. package/transpiled/mongodb/lib/operations/list_databases.js +56 -0
  398. package/transpiled/mongodb/lib/operations/operation.js +88 -0
  399. package/transpiled/mongodb/lib/operations/options_operation.js +44 -0
  400. package/transpiled/mongodb/lib/operations/profiling_level.js +42 -0
  401. package/transpiled/mongodb/lib/operations/remove_user.js +35 -0
  402. package/transpiled/mongodb/lib/operations/rename.js +48 -0
  403. package/transpiled/mongodb/lib/operations/run_command.js +64 -0
  404. package/transpiled/mongodb/lib/operations/search_indexes/create.js +41 -0
  405. package/transpiled/mongodb/lib/operations/search_indexes/drop.js +51 -0
  406. package/transpiled/mongodb/lib/operations/search_indexes/update.js +40 -0
  407. package/transpiled/mongodb/lib/operations/set_profiling_level.js +70 -0
  408. package/transpiled/mongodb/lib/operations/stats.js +39 -0
  409. package/transpiled/mongodb/lib/operations/update.js +218 -0
  410. package/transpiled/mongodb/lib/operations/validate_collection.js +49 -0
  411. package/transpiled/mongodb/lib/read_concern.js +92 -0
  412. package/transpiled/mongodb/lib/read_preference.js +215 -0
  413. package/transpiled/mongodb/lib/resource_management.js +74 -0
  414. package/transpiled/mongodb/lib/sdam/common.js +53 -0
  415. package/transpiled/mongodb/lib/sdam/events.js +177 -0
  416. package/transpiled/mongodb/lib/sdam/monitor.js +656 -0
  417. package/transpiled/mongodb/lib/sdam/server.js +463 -0
  418. package/transpiled/mongodb/lib/sdam/server_description.js +196 -0
  419. package/transpiled/mongodb/lib/sdam/server_selection.js +283 -0
  420. package/transpiled/mongodb/lib/sdam/server_selection_events.js +112 -0
  421. package/transpiled/mongodb/lib/sdam/srv_polling.js +139 -0
  422. package/transpiled/mongodb/lib/sdam/topology.js +833 -0
  423. package/transpiled/mongodb/lib/sdam/topology_description.js +447 -0
  424. package/transpiled/mongodb/lib/sessions.js +988 -0
  425. package/transpiled/mongodb/lib/sort.js +123 -0
  426. package/transpiled/mongodb/lib/timeout.js +349 -0
  427. package/transpiled/mongodb/lib/transactions.js +149 -0
  428. package/transpiled/mongodb/lib/utils.js +1502 -0
  429. package/transpiled/mongodb/lib/write_concern.js +115 -0
  430. package/types/index.d.ts +70 -70
  431. package/types/module-eyes.d.ts +39 -39
  432. package/types/module-http.d.ts +163 -163
  433. package/types/module-log.d.ts +34 -34
  434. package/types/module-mob.d.ts +966 -966
  435. package/types/module-pdf.d.ts +40 -40
  436. package/types/module-proxy.d.ts +100 -100
  437. package/types/module-shell.d.ts +24 -24
  438. package/types/module-utils.d.ts +99 -99
  439. package/types/module-web.d.ts +1053 -1053
  440. package/types/module-win.d.ts +352 -352
  441. package/types/oxygen.d.ts +53 -53
@@ -0,0 +1,656 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RTTSampler = exports.MonitorInterval = exports.RTTPinger = exports.Monitor = exports.ServerMonitoringMode = void 0;
7
+
8
+ const timers_1 = require("timers");
9
+
10
+ const bson_1 = require("../bson");
11
+
12
+ const connect_1 = require("../cmap/connect");
13
+
14
+ const client_metadata_1 = require("../cmap/handshake/client_metadata");
15
+
16
+ const constants_1 = require("../constants");
17
+
18
+ const error_1 = require("../error");
19
+
20
+ const mongo_logger_1 = require("../mongo_logger");
21
+
22
+ const mongo_types_1 = require("../mongo_types");
23
+
24
+ const utils_1 = require("../utils");
25
+
26
+ const common_1 = require("./common");
27
+
28
+ const events_1 = require("./events");
29
+
30
+ const server_1 = require("./server");
31
+
32
+ const STATE_IDLE = 'idle';
33
+ const STATE_MONITORING = 'monitoring';
34
+ const stateTransition = (0, utils_1.makeStateMachine)({
35
+ [common_1.STATE_CLOSING]: [common_1.STATE_CLOSING, STATE_IDLE, common_1.STATE_CLOSED],
36
+ [common_1.STATE_CLOSED]: [common_1.STATE_CLOSED, STATE_MONITORING],
37
+ [STATE_IDLE]: [STATE_IDLE, STATE_MONITORING, common_1.STATE_CLOSING],
38
+ [STATE_MONITORING]: [STATE_MONITORING, STATE_IDLE, common_1.STATE_CLOSING]
39
+ });
40
+ const INVALID_REQUEST_CHECK_STATES = new Set([common_1.STATE_CLOSING, common_1.STATE_CLOSED, STATE_MONITORING]);
41
+
42
+ function isInCloseState(monitor) {
43
+ return monitor.s.state === common_1.STATE_CLOSED || monitor.s.state === common_1.STATE_CLOSING;
44
+ }
45
+ /** @public */
46
+
47
+
48
+ exports.ServerMonitoringMode = Object.freeze({
49
+ auto: 'auto',
50
+ poll: 'poll',
51
+ stream: 'stream'
52
+ });
53
+ /** @internal */
54
+
55
+ class Monitor extends mongo_types_1.TypedEventEmitter {
56
+ constructor(server, options) {
57
+ super();
58
+ /** @internal */
59
+
60
+ this.component = mongo_logger_1.MongoLoggableComponent.TOPOLOGY;
61
+ this.on('error', utils_1.noop);
62
+ this.server = server;
63
+ this.connection = null;
64
+ this.cancellationToken = new mongo_types_1.CancellationToken();
65
+ this.cancellationToken.setMaxListeners(Infinity);
66
+ this.monitorId = undefined;
67
+ this.s = {
68
+ state: common_1.STATE_CLOSED
69
+ };
70
+ this.address = server.description.address;
71
+ this.options = Object.freeze({
72
+ connectTimeoutMS: options.connectTimeoutMS ?? 10000,
73
+ heartbeatFrequencyMS: options.heartbeatFrequencyMS ?? 10000,
74
+ minHeartbeatFrequencyMS: options.minHeartbeatFrequencyMS ?? 500,
75
+ serverMonitoringMode: options.serverMonitoringMode
76
+ });
77
+ this.isRunningInFaasEnv = (0, client_metadata_1.getFAASEnv)() != null;
78
+ this.mongoLogger = this.server.topology.client?.mongoLogger;
79
+ this.rttSampler = new RTTSampler(10);
80
+ const cancellationToken = this.cancellationToken; // TODO: refactor this to pull it directly from the pool, requires new ConnectionPool integration
81
+
82
+ const connectOptions = {
83
+ id: '<monitor>',
84
+ generation: server.pool.generation,
85
+ cancellationToken,
86
+ hostAddress: server.description.hostAddress,
87
+ ...options,
88
+ // force BSON serialization options
89
+ raw: false,
90
+ useBigInt64: false,
91
+ promoteLongs: true,
92
+ promoteValues: true,
93
+ promoteBuffers: true
94
+ }; // ensure no authentication is used for monitoring
95
+
96
+ delete connectOptions.credentials;
97
+
98
+ if (connectOptions.autoEncrypter) {
99
+ delete connectOptions.autoEncrypter;
100
+ }
101
+
102
+ this.connectOptions = Object.freeze(connectOptions);
103
+ }
104
+
105
+ connect() {
106
+ if (this.s.state !== common_1.STATE_CLOSED) {
107
+ return;
108
+ } // start
109
+
110
+
111
+ const heartbeatFrequencyMS = this.options.heartbeatFrequencyMS;
112
+ const minHeartbeatFrequencyMS = this.options.minHeartbeatFrequencyMS;
113
+ this.monitorId = new MonitorInterval(monitorServer(this), {
114
+ heartbeatFrequencyMS: heartbeatFrequencyMS,
115
+ minHeartbeatFrequencyMS: minHeartbeatFrequencyMS,
116
+ immediate: true
117
+ });
118
+ }
119
+
120
+ requestCheck() {
121
+ if (INVALID_REQUEST_CHECK_STATES.has(this.s.state)) {
122
+ return;
123
+ }
124
+
125
+ this.monitorId?.wake();
126
+ }
127
+
128
+ reset() {
129
+ const topologyVersion = this.server.description.topologyVersion;
130
+
131
+ if (isInCloseState(this) || topologyVersion == null) {
132
+ return;
133
+ }
134
+
135
+ stateTransition(this, common_1.STATE_CLOSING);
136
+ resetMonitorState(this); // restart monitor
137
+
138
+ stateTransition(this, STATE_IDLE); // restart monitoring
139
+
140
+ const heartbeatFrequencyMS = this.options.heartbeatFrequencyMS;
141
+ const minHeartbeatFrequencyMS = this.options.minHeartbeatFrequencyMS;
142
+ this.monitorId = new MonitorInterval(monitorServer(this), {
143
+ heartbeatFrequencyMS: heartbeatFrequencyMS,
144
+ minHeartbeatFrequencyMS: minHeartbeatFrequencyMS
145
+ });
146
+ }
147
+
148
+ close() {
149
+ if (isInCloseState(this)) {
150
+ return;
151
+ }
152
+
153
+ stateTransition(this, common_1.STATE_CLOSING);
154
+ resetMonitorState(this); // close monitor
155
+
156
+ this.emit('close');
157
+ stateTransition(this, common_1.STATE_CLOSED);
158
+ }
159
+
160
+ get roundTripTime() {
161
+ return this.rttSampler.average();
162
+ }
163
+
164
+ get minRoundTripTime() {
165
+ return this.rttSampler.min();
166
+ }
167
+
168
+ get latestRtt() {
169
+ return this.rttSampler.last;
170
+ }
171
+
172
+ addRttSample(rtt) {
173
+ this.rttSampler.addSample(rtt);
174
+ }
175
+
176
+ clearRttSamples() {
177
+ this.rttSampler.clear();
178
+ }
179
+
180
+ }
181
+
182
+ exports.Monitor = Monitor;
183
+
184
+ function resetMonitorState(monitor) {
185
+ monitor.monitorId?.stop();
186
+ monitor.monitorId = undefined;
187
+ monitor.rttPinger?.close();
188
+ monitor.rttPinger = undefined;
189
+ monitor.cancellationToken.emit('cancel');
190
+ monitor.connection?.destroy();
191
+ monitor.connection = null;
192
+ monitor.clearRttSamples();
193
+ }
194
+
195
+ function useStreamingProtocol(monitor, topologyVersion) {
196
+ // If we have no topology version we always poll no matter
197
+ // what the user provided, since the server does not support
198
+ // the streaming protocol.
199
+ if (topologyVersion == null) return false;
200
+ const serverMonitoringMode = monitor.options.serverMonitoringMode;
201
+ if (serverMonitoringMode === exports.ServerMonitoringMode.poll) return false;
202
+ if (serverMonitoringMode === exports.ServerMonitoringMode.stream) return true; // If we are in auto mode, we need to figure out if we're in a FaaS
203
+ // environment or not and choose the appropriate mode.
204
+
205
+ if (monitor.isRunningInFaasEnv) return false;
206
+ return true;
207
+ }
208
+
209
+ function checkServer(monitor, callback) {
210
+ let start;
211
+ let awaited;
212
+ const topologyVersion = monitor.server.description.topologyVersion;
213
+ const isAwaitable = useStreamingProtocol(monitor, topologyVersion);
214
+ monitor.emitAndLogHeartbeat(server_1.Server.SERVER_HEARTBEAT_STARTED, monitor.server.topology.s.id, undefined, new events_1.ServerHeartbeatStartedEvent(monitor.address, isAwaitable));
215
+
216
+ function onHeartbeatFailed(err) {
217
+ monitor.connection?.destroy();
218
+ monitor.connection = null;
219
+ monitor.emitAndLogHeartbeat(server_1.Server.SERVER_HEARTBEAT_FAILED, monitor.server.topology.s.id, undefined, new events_1.ServerHeartbeatFailedEvent(monitor.address, (0, utils_1.calculateDurationInMs)(start), err, awaited));
220
+ const error = !(err instanceof error_1.MongoError) ? new error_1.MongoError(error_1.MongoError.buildErrorMessage(err), {
221
+ cause: err
222
+ }) : err;
223
+ error.addErrorLabel(error_1.MongoErrorLabel.ResetPool);
224
+
225
+ if (error instanceof error_1.MongoNetworkTimeoutError) {
226
+ error.addErrorLabel(error_1.MongoErrorLabel.InterruptInUseConnections);
227
+ }
228
+
229
+ monitor.emit('resetServer', error);
230
+ callback(err);
231
+ }
232
+
233
+ function onHeartbeatSucceeded(hello) {
234
+ if (!('isWritablePrimary' in hello)) {
235
+ // Provide hello-style response document.
236
+ hello.isWritablePrimary = hello[constants_1.LEGACY_HELLO_COMMAND];
237
+ } // NOTE: here we use the latestRtt as this measurement corresponds with the value
238
+ // obtained for this successful heartbeat, if there is no latestRtt, then we calculate the
239
+ // duration
240
+
241
+
242
+ const duration = isAwaitable && monitor.rttPinger ? monitor.rttPinger.latestRtt ?? (0, utils_1.calculateDurationInMs)(start) : (0, utils_1.calculateDurationInMs)(start);
243
+ monitor.addRttSample(duration);
244
+ monitor.emitAndLogHeartbeat(server_1.Server.SERVER_HEARTBEAT_SUCCEEDED, monitor.server.topology.s.id, hello.connectionId, new events_1.ServerHeartbeatSucceededEvent(monitor.address, duration, hello, isAwaitable));
245
+
246
+ if (isAwaitable) {
247
+ // If we are using the streaming protocol then we immediately issue another 'started'
248
+ // event, otherwise the "check" is complete and return to the main monitor loop
249
+ monitor.emitAndLogHeartbeat(server_1.Server.SERVER_HEARTBEAT_STARTED, monitor.server.topology.s.id, undefined, new events_1.ServerHeartbeatStartedEvent(monitor.address, true)); // We have not actually sent an outgoing handshake, but when we get the next response we
250
+ // want the duration to reflect the time since we last heard from the server
251
+
252
+ start = (0, utils_1.now)();
253
+ } else {
254
+ monitor.rttPinger?.close();
255
+ monitor.rttPinger = undefined;
256
+ callback(undefined, hello);
257
+ }
258
+ }
259
+
260
+ const {
261
+ connection
262
+ } = monitor;
263
+
264
+ if (connection && !connection.closed) {
265
+ const {
266
+ serverApi,
267
+ helloOk
268
+ } = connection;
269
+ const connectTimeoutMS = monitor.options.connectTimeoutMS;
270
+ const maxAwaitTimeMS = monitor.options.heartbeatFrequencyMS;
271
+ const cmd = {
272
+ [serverApi?.version || helloOk ? 'hello' : constants_1.LEGACY_HELLO_COMMAND]: 1,
273
+ ...(isAwaitable && topologyVersion ? {
274
+ maxAwaitTimeMS,
275
+ topologyVersion: makeTopologyVersion(topologyVersion)
276
+ } : {})
277
+ };
278
+ const options = isAwaitable ? {
279
+ socketTimeoutMS: connectTimeoutMS ? connectTimeoutMS + maxAwaitTimeMS : 0,
280
+ exhaustAllowed: true
281
+ } : {
282
+ socketTimeoutMS: connectTimeoutMS
283
+ };
284
+
285
+ if (isAwaitable && monitor.rttPinger == null) {
286
+ monitor.rttPinger = new RTTPinger(monitor);
287
+ } // Record new start time before sending handshake
288
+
289
+
290
+ start = (0, utils_1.now)();
291
+
292
+ if (isAwaitable) {
293
+ awaited = true;
294
+ return connection.exhaustCommand((0, utils_1.ns)('admin.$cmd'), cmd, options, (error, hello) => {
295
+ if (error) return onHeartbeatFailed(error);
296
+ return onHeartbeatSucceeded(hello);
297
+ });
298
+ }
299
+
300
+ awaited = false;
301
+ connection.command((0, utils_1.ns)('admin.$cmd'), cmd, options).then(onHeartbeatSucceeded, onHeartbeatFailed);
302
+ return;
303
+ } // connecting does an implicit `hello`
304
+
305
+
306
+ (async () => {
307
+ const socket = await (0, connect_1.makeSocket)(monitor.connectOptions);
308
+ const connection = (0, connect_1.makeConnection)(monitor.connectOptions, socket); // The start time is after socket creation but before the handshake
309
+
310
+ start = (0, utils_1.now)();
311
+
312
+ try {
313
+ await (0, connect_1.performInitialHandshake)(connection, monitor.connectOptions);
314
+ return connection;
315
+ } catch (error) {
316
+ connection.destroy();
317
+ throw error;
318
+ }
319
+ })().then(connection => {
320
+ if (isInCloseState(monitor)) {
321
+ connection.destroy();
322
+ return;
323
+ }
324
+
325
+ const duration = (0, utils_1.calculateDurationInMs)(start);
326
+ monitor.addRttSample(duration);
327
+ monitor.connection = connection;
328
+ monitor.emitAndLogHeartbeat(server_1.Server.SERVER_HEARTBEAT_SUCCEEDED, monitor.server.topology.s.id, connection.hello?.connectionId, new events_1.ServerHeartbeatSucceededEvent(monitor.address, duration, connection.hello, useStreamingProtocol(monitor, connection.hello?.topologyVersion)));
329
+ callback(undefined, connection.hello);
330
+ }, error => {
331
+ monitor.connection = null;
332
+ awaited = false;
333
+ onHeartbeatFailed(error);
334
+ });
335
+ }
336
+
337
+ function monitorServer(monitor) {
338
+ return callback => {
339
+ if (monitor.s.state === STATE_MONITORING) {
340
+ process.nextTick(callback);
341
+ return;
342
+ }
343
+
344
+ stateTransition(monitor, STATE_MONITORING);
345
+
346
+ function done() {
347
+ if (!isInCloseState(monitor)) {
348
+ stateTransition(monitor, STATE_IDLE);
349
+ }
350
+
351
+ callback();
352
+ }
353
+
354
+ checkServer(monitor, (err, hello) => {
355
+ if (err) {
356
+ // otherwise an error occurred on initial discovery, also bail
357
+ if (monitor.server.description.type === common_1.ServerType.Unknown) {
358
+ return done();
359
+ }
360
+ } // if the check indicates streaming is supported, immediately reschedule monitoring
361
+
362
+
363
+ if (useStreamingProtocol(monitor, hello?.topologyVersion)) {
364
+ (0, timers_1.setTimeout)(() => {
365
+ if (!isInCloseState(monitor)) {
366
+ monitor.monitorId?.wake();
367
+ }
368
+ }, 0);
369
+ }
370
+
371
+ done();
372
+ });
373
+ };
374
+ }
375
+
376
+ function makeTopologyVersion(tv) {
377
+ return {
378
+ processId: tv.processId,
379
+ // tests mock counter as just number, but in a real situation counter should always be a Long
380
+ // TODO(NODE-2674): Preserve int64 sent from MongoDB
381
+ counter: bson_1.Long.isLong(tv.counter) ? tv.counter : bson_1.Long.fromNumber(tv.counter)
382
+ };
383
+ }
384
+ /** @internal */
385
+
386
+
387
+ class RTTPinger {
388
+ constructor(monitor) {
389
+ this.connection = undefined;
390
+ this.cancellationToken = monitor.cancellationToken;
391
+ this.closed = false;
392
+ this.monitor = monitor;
393
+ this.latestRtt = monitor.latestRtt ?? undefined;
394
+ const heartbeatFrequencyMS = monitor.options.heartbeatFrequencyMS;
395
+ this.monitorId = (0, timers_1.setTimeout)(() => this.measureRoundTripTime(), heartbeatFrequencyMS);
396
+ }
397
+
398
+ get roundTripTime() {
399
+ return this.monitor.roundTripTime;
400
+ }
401
+
402
+ get minRoundTripTime() {
403
+ return this.monitor.minRoundTripTime;
404
+ }
405
+
406
+ close() {
407
+ this.closed = true;
408
+ (0, timers_1.clearTimeout)(this.monitorId);
409
+ this.connection?.destroy();
410
+ this.connection = undefined;
411
+ }
412
+
413
+ measureAndReschedule(start, conn) {
414
+ if (this.closed) {
415
+ conn?.destroy();
416
+ return;
417
+ }
418
+
419
+ if (this.connection == null) {
420
+ this.connection = conn;
421
+ }
422
+
423
+ this.latestRtt = (0, utils_1.calculateDurationInMs)(start);
424
+ this.monitorId = (0, timers_1.setTimeout)(() => this.measureRoundTripTime(), this.monitor.options.heartbeatFrequencyMS);
425
+ }
426
+
427
+ measureRoundTripTime() {
428
+ const start = (0, utils_1.now)();
429
+
430
+ if (this.closed) {
431
+ return;
432
+ }
433
+
434
+ const connection = this.connection;
435
+
436
+ if (connection == null) {
437
+ (0, connect_1.connect)(this.monitor.connectOptions).then(connection => {
438
+ this.measureAndReschedule(start, connection);
439
+ }, () => {
440
+ this.connection = undefined;
441
+ });
442
+ return;
443
+ }
444
+
445
+ const commandName = connection.serverApi?.version || connection.helloOk ? 'hello' : constants_1.LEGACY_HELLO_COMMAND;
446
+ connection.command((0, utils_1.ns)('admin.$cmd'), {
447
+ [commandName]: 1
448
+ }, undefined).then(() => this.measureAndReschedule(start), () => {
449
+ this.connection?.destroy();
450
+ this.connection = undefined;
451
+ return;
452
+ });
453
+ }
454
+
455
+ }
456
+
457
+ exports.RTTPinger = RTTPinger;
458
+ /**
459
+ * @internal
460
+ */
461
+
462
+ class MonitorInterval {
463
+ constructor(fn, options = {}) {
464
+ this.isExpeditedCallToFnScheduled = false;
465
+ this.stopped = false;
466
+ this.isExecutionInProgress = false;
467
+ this.hasExecutedOnce = false;
468
+
469
+ this._executeAndReschedule = () => {
470
+ if (this.stopped) return;
471
+
472
+ if (this.timerId) {
473
+ (0, timers_1.clearTimeout)(this.timerId);
474
+ }
475
+
476
+ this.isExpeditedCallToFnScheduled = false;
477
+ this.isExecutionInProgress = true;
478
+ this.fn(() => {
479
+ this.lastExecutionEnded = (0, utils_1.now)();
480
+ this.isExecutionInProgress = false;
481
+
482
+ this._reschedule(this.heartbeatFrequencyMS);
483
+ });
484
+ };
485
+
486
+ this.fn = fn;
487
+ this.lastExecutionEnded = -Infinity;
488
+ this.heartbeatFrequencyMS = options.heartbeatFrequencyMS ?? 1000;
489
+ this.minHeartbeatFrequencyMS = options.minHeartbeatFrequencyMS ?? 500;
490
+
491
+ if (options.immediate) {
492
+ this._executeAndReschedule();
493
+ } else {
494
+ this._reschedule(undefined);
495
+ }
496
+ }
497
+
498
+ wake() {
499
+ const currentTime = (0, utils_1.now)();
500
+ const timeSinceLastCall = currentTime - this.lastExecutionEnded; // TODO(NODE-4674): Add error handling and logging to the monitor
501
+
502
+ if (timeSinceLastCall < 0) {
503
+ return this._executeAndReschedule();
504
+ }
505
+
506
+ if (this.isExecutionInProgress) {
507
+ return;
508
+ } // debounce multiple calls to wake within the `minInterval`
509
+
510
+
511
+ if (this.isExpeditedCallToFnScheduled) {
512
+ return;
513
+ } // reschedule a call as soon as possible, ensuring the call never happens
514
+ // faster than the `minInterval`
515
+
516
+
517
+ if (timeSinceLastCall < this.minHeartbeatFrequencyMS) {
518
+ this.isExpeditedCallToFnScheduled = true;
519
+
520
+ this._reschedule(this.minHeartbeatFrequencyMS - timeSinceLastCall);
521
+
522
+ return;
523
+ }
524
+
525
+ this._executeAndReschedule();
526
+ }
527
+
528
+ stop() {
529
+ this.stopped = true;
530
+
531
+ if (this.timerId) {
532
+ (0, timers_1.clearTimeout)(this.timerId);
533
+ this.timerId = undefined;
534
+ }
535
+
536
+ this.lastExecutionEnded = -Infinity;
537
+ this.isExpeditedCallToFnScheduled = false;
538
+ }
539
+
540
+ toString() {
541
+ return JSON.stringify(this);
542
+ }
543
+
544
+ toJSON() {
545
+ const currentTime = (0, utils_1.now)();
546
+ const timeSinceLastCall = currentTime - this.lastExecutionEnded;
547
+ return {
548
+ timerId: this.timerId != null ? 'set' : 'cleared',
549
+ lastCallTime: this.lastExecutionEnded,
550
+ isExpeditedCheckScheduled: this.isExpeditedCallToFnScheduled,
551
+ stopped: this.stopped,
552
+ heartbeatFrequencyMS: this.heartbeatFrequencyMS,
553
+ minHeartbeatFrequencyMS: this.minHeartbeatFrequencyMS,
554
+ currentTime,
555
+ timeSinceLastCall
556
+ };
557
+ }
558
+
559
+ _reschedule(ms) {
560
+ if (this.stopped) return;
561
+
562
+ if (this.timerId) {
563
+ (0, timers_1.clearTimeout)(this.timerId);
564
+ }
565
+
566
+ this.timerId = (0, timers_1.setTimeout)(this._executeAndReschedule, ms || this.heartbeatFrequencyMS);
567
+ }
568
+
569
+ }
570
+
571
+ exports.MonitorInterval = MonitorInterval;
572
+ /** @internal
573
+ * This class implements the RTT sampling logic specified for [CSOT](https://github.com/mongodb/specifications/blob/bbb335e60cd7ea1e0f7cd9a9443cb95fc9d3b64d/source/client-side-operations-timeout/client-side-operations-timeout.md#drivers-use-minimum-rtt-to-short-circuit-operations)
574
+ *
575
+ * This is implemented as a [circular buffer](https://en.wikipedia.org/wiki/Circular_buffer) keeping
576
+ * the most recent `windowSize` samples
577
+ * */
578
+
579
+ class RTTSampler {
580
+ constructor(windowSize = 10) {
581
+ this.rttSamples = new Float64Array(windowSize);
582
+ this.length = 0;
583
+ this.writeIndex = 0;
584
+ }
585
+ /**
586
+ * Adds an rtt sample to the end of the circular buffer
587
+ * When `windowSize` samples have been collected, `addSample` overwrites the least recently added
588
+ * sample
589
+ */
590
+
591
+
592
+ addSample(sample) {
593
+ this.rttSamples[this.writeIndex++] = sample;
594
+
595
+ if (this.length < this.rttSamples.length) {
596
+ this.length++;
597
+ }
598
+
599
+ this.writeIndex %= this.rttSamples.length;
600
+ }
601
+ /**
602
+ * When \< 2 samples have been collected, returns 0
603
+ * Otherwise computes the minimum value samples contained in the buffer
604
+ */
605
+
606
+
607
+ min() {
608
+ if (this.length < 2) return 0;
609
+ let min = this.rttSamples[0];
610
+
611
+ for (let i = 1; i < this.length; i++) {
612
+ if (this.rttSamples[i] < min) min = this.rttSamples[i];
613
+ }
614
+
615
+ return min;
616
+ }
617
+ /**
618
+ * Returns mean of samples contained in the buffer
619
+ */
620
+
621
+
622
+ average() {
623
+ if (this.length === 0) return 0;
624
+ let sum = 0;
625
+
626
+ for (let i = 0; i < this.length; i++) {
627
+ sum += this.rttSamples[i];
628
+ }
629
+
630
+ return sum / this.length;
631
+ }
632
+ /**
633
+ * Returns most recently inserted element in the buffer
634
+ * Returns null if the buffer is empty
635
+ * */
636
+
637
+
638
+ get last() {
639
+ if (this.length === 0) return null;
640
+ return this.rttSamples[this.writeIndex === 0 ? this.length - 1 : this.writeIndex - 1];
641
+ }
642
+ /**
643
+ * Clear the buffer
644
+ * NOTE: this does not overwrite the data held in the internal array, just the pointers into
645
+ * this array
646
+ */
647
+
648
+
649
+ clear() {
650
+ this.length = 0;
651
+ this.writeIndex = 0;
652
+ }
653
+
654
+ }
655
+
656
+ exports.RTTSampler = RTTSampler;