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,1502 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.kDispose = exports.randomBytes = exports.COSMOS_DB_MSG = exports.DOCUMENT_DB_MSG = exports.COSMOS_DB_CHECK = exports.DOCUMENT_DB_CHECK = exports.MONGODB_WARNING_CODE = exports.DEFAULT_PK_FACTORY = exports.HostAddress = exports.BufferPool = exports.List = exports.MongoDBCollectionNamespace = exports.MongoDBNamespace = exports.ByteUtils = void 0;
7
- exports.isUint8Array = isUint8Array;
8
- exports.hostMatchesWildcards = hostMatchesWildcards;
9
- exports.normalizeHintField = normalizeHintField;
10
- exports.isObject = isObject;
11
- exports.mergeOptions = mergeOptions;
12
- exports.filterOptions = filterOptions;
13
- exports.applyRetryableWrites = applyRetryableWrites;
14
- exports.isPromiseLike = isPromiseLike;
15
- exports.decorateWithCollation = decorateWithCollation;
16
- exports.decorateWithReadConcern = decorateWithReadConcern;
17
- exports.getTopology = getTopology;
18
- exports.ns = ns;
19
- exports.makeCounter = makeCounter;
20
- exports.uuidV4 = uuidV4;
21
- exports.maxWireVersion = maxWireVersion;
22
- exports.arrayStrictEqual = arrayStrictEqual;
23
- exports.errorStrictEqual = errorStrictEqual;
24
- exports.makeStateMachine = makeStateMachine;
25
- exports.now = now;
26
- exports.calculateDurationInMs = calculateDurationInMs;
27
- exports.hasAtomicOperators = hasAtomicOperators;
28
- exports.resolveTimeoutOptions = resolveTimeoutOptions;
29
- exports.resolveOptions = resolveOptions;
30
- exports.isSuperset = isSuperset;
31
- exports.isHello = isHello;
32
- exports.setDifference = setDifference;
33
- exports.isRecord = isRecord;
34
- exports.emitWarning = emitWarning;
35
- exports.emitWarningOnce = emitWarningOnce;
36
- exports.enumToString = enumToString;
37
- exports.supportsRetryableWrites = supportsRetryableWrites;
38
- exports.shuffle = shuffle;
39
- exports.commandSupportsReadConcern = commandSupportsReadConcern;
40
- exports.compareObjectId = compareObjectId;
41
- exports.parseInteger = parseInteger;
42
- exports.parseUnsignedInteger = parseUnsignedInteger;
43
- exports.checkParentDomainMatch = checkParentDomainMatch;
44
- exports.get = get;
45
- exports.request = request;
46
- exports.isHostMatch = isHostMatch;
47
- exports.promiseWithResolvers = promiseWithResolvers;
48
- exports.squashError = squashError;
49
- exports.once = once;
50
- exports.maybeAddIdToDocuments = maybeAddIdToDocuments;
51
- exports.fileIsAccessible = fileIsAccessible;
52
- exports.csotMin = csotMin;
53
- exports.noop = noop;
54
- exports.decorateDecryptionResult = decorateDecryptionResult;
55
- exports.addAbortListener = addAbortListener;
56
- exports.abortable = abortable;
57
-
58
- const crypto = require("crypto");
59
-
60
- const fs_1 = require("fs");
61
-
62
- const http = require("http");
63
-
64
- const timers_1 = require("timers");
65
-
66
- const url = require("url");
67
-
68
- const url_1 = require("url");
69
-
70
- const util_1 = require("util");
71
-
72
- const bson_1 = require("./bson");
73
-
74
- const constants_1 = require("./cmap/wire_protocol/constants");
75
-
76
- const constants_2 = require("./constants");
77
-
78
- const error_1 = require("./error");
79
-
80
- const read_concern_1 = require("./read_concern");
81
-
82
- const read_preference_1 = require("./read_preference");
83
-
84
- const common_1 = require("./sdam/common");
85
-
86
- const write_concern_1 = require("./write_concern");
87
-
88
- exports.ByteUtils = {
89
- toLocalBufferType(buffer) {
90
- return Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
91
- },
92
-
93
- equals(seqA, seqB) {
94
- return exports.ByteUtils.toLocalBufferType(seqA).equals(seqB);
95
- },
96
-
97
- compare(seqA, seqB) {
98
- return exports.ByteUtils.toLocalBufferType(seqA).compare(seqB);
99
- },
100
-
101
- toBase64(uint8array) {
102
- return exports.ByteUtils.toLocalBufferType(uint8array).toString('base64');
103
- }
104
-
105
- };
106
- /**
107
- * Returns true if value is a Uint8Array or a Buffer
108
- * @param value - any value that may be a Uint8Array
109
- */
110
-
111
- function isUint8Array(value) {
112
- return value != null && typeof value === 'object' && Symbol.toStringTag in value && value[Symbol.toStringTag] === 'Uint8Array';
113
- }
114
- /**
115
- * Determines if a connection's address matches a user provided list
116
- * of domain wildcards.
117
- */
118
-
119
-
120
- function hostMatchesWildcards(host, wildcards) {
121
- for (const wildcard of wildcards) {
122
- if (host === wildcard || wildcard.startsWith('*.') && host?.endsWith(wildcard.substring(2, wildcard.length)) || wildcard.startsWith('*/') && host?.endsWith(wildcard.substring(2, wildcard.length))) {
123
- return true;
124
- }
125
- }
126
-
127
- return false;
128
- }
129
- /**
130
- * Ensure Hint field is in a shape we expect:
131
- * - object of index names mapping to 1 or -1
132
- * - just an index name
133
- * @internal
134
- */
135
-
136
-
137
- function normalizeHintField(hint) {
138
- let finalHint = undefined;
139
-
140
- if (typeof hint === 'string') {
141
- finalHint = hint;
142
- } else if (Array.isArray(hint)) {
143
- finalHint = {};
144
- hint.forEach(param => {
145
- finalHint[param] = 1;
146
- });
147
- } else if (hint != null && typeof hint === 'object') {
148
- finalHint = {};
149
-
150
- for (const name in hint) {
151
- finalHint[name] = hint[name];
152
- }
153
- }
154
-
155
- return finalHint;
156
- }
157
-
158
- const TO_STRING = object => Object.prototype.toString.call(object);
159
- /**
160
- * Checks if arg is an Object:
161
- * - **NOTE**: the check is based on the `[Symbol.toStringTag]() === 'Object'`
162
- * @internal
163
- */
164
-
165
-
166
- function isObject(arg) {
167
- return '[object Object]' === TO_STRING(arg);
168
- }
169
- /** @internal */
170
-
171
-
172
- function mergeOptions(target, source) {
173
- return { ...target,
174
- ...source
175
- };
176
- }
177
- /** @internal */
178
-
179
-
180
- function filterOptions(options, names) {
181
- const filterOptions = {};
182
-
183
- for (const name in options) {
184
- if (names.includes(name)) {
185
- filterOptions[name] = options[name];
186
- }
187
- } // Filtered options
188
-
189
-
190
- return filterOptions;
191
- }
192
- /**
193
- * Applies retryWrites: true to a command if retryWrites is set on the command's database.
194
- * @internal
195
- *
196
- * @param target - The target command to which we will apply retryWrites.
197
- * @param db - The database from which we can inherit a retryWrites value.
198
- */
199
-
200
-
201
- function applyRetryableWrites(target, db) {
202
- if (db && db.s.options?.retryWrites) {
203
- target.retryWrites = true;
204
- }
205
-
206
- return target;
207
- }
208
- /**
209
- * Applies a write concern to a command based on well defined inheritance rules, optionally
210
- * detecting support for the write concern in the first place.
211
- * @internal
212
- *
213
- * @param target - the target command we will be applying the write concern to
214
- * @param sources - sources where we can inherit default write concerns from
215
- * @param options - optional settings passed into a command for write concern overrides
216
- */
217
-
218
- /**
219
- * Checks if a given value is a Promise
220
- *
221
- * @typeParam T - The resolution type of the possible promise
222
- * @param value - An object that could be a promise
223
- * @returns true if the provided value is a Promise
224
- */
225
-
226
-
227
- function isPromiseLike(value) {
228
- return value != null && typeof value === 'object' && 'then' in value && typeof value.then === 'function';
229
- }
230
- /**
231
- * Applies collation to a given command.
232
- * @internal
233
- *
234
- * @param command - the command on which to apply collation
235
- * @param target - target of command
236
- * @param options - options containing collation settings
237
- */
238
-
239
-
240
- function decorateWithCollation(command, target, options) {
241
- const capabilities = getTopology(target).capabilities;
242
-
243
- if (options.collation && typeof options.collation === 'object') {
244
- if (capabilities && capabilities.commandsTakeCollation) {
245
- command.collation = options.collation;
246
- } else {
247
- throw new error_1.MongoCompatibilityError(`Current topology does not support collation`);
248
- }
249
- }
250
- }
251
- /**
252
- * Applies a read concern to a given command.
253
- * @internal
254
- *
255
- * @param command - the command on which to apply the read concern
256
- * @param coll - the parent collection of the operation calling this method
257
- */
258
-
259
-
260
- function decorateWithReadConcern(command, coll, options) {
261
- if (options && options.session && options.session.inTransaction()) {
262
- return;
263
- }
264
-
265
- const readConcern = Object.assign({}, command.readConcern || {});
266
-
267
- if (coll.s.readConcern) {
268
- Object.assign(readConcern, coll.s.readConcern);
269
- }
270
-
271
- if (Object.keys(readConcern).length > 0) {
272
- Object.assign(command, {
273
- readConcern: readConcern
274
- });
275
- }
276
- }
277
- /**
278
- * A helper function to get the topology from a given provider. Throws
279
- * if the topology cannot be found.
280
- * @throws MongoNotConnectedError
281
- * @internal
282
- */
283
-
284
-
285
- function getTopology(provider) {
286
- // MongoClient or ClientSession or AbstractCursor
287
- if ('topology' in provider && provider.topology) {
288
- return provider.topology;
289
- } else if ('client' in provider && provider.client.topology) {
290
- return provider.client.topology;
291
- }
292
-
293
- throw new error_1.MongoNotConnectedError('MongoClient must be connected to perform this operation');
294
- }
295
- /** @internal */
296
-
297
-
298
- function ns(ns) {
299
- return MongoDBNamespace.fromString(ns);
300
- }
301
- /** @public */
302
-
303
-
304
- class MongoDBNamespace {
305
- /**
306
- * Create a namespace object
307
- *
308
- * @param db - database name
309
- * @param collection - collection name
310
- */
311
- constructor(db, collection) {
312
- this.db = db;
313
- this.collection = collection;
314
- this.collection = collection === '' ? undefined : collection;
315
- }
316
-
317
- toString() {
318
- return this.collection ? `${this.db}.${this.collection}` : this.db;
319
- }
320
-
321
- withCollection(collection) {
322
- return new MongoDBCollectionNamespace(this.db, collection);
323
- }
324
-
325
- static fromString(namespace) {
326
- if (typeof namespace !== 'string' || namespace === '') {
327
- // TODO(NODE-3483): Replace with MongoNamespaceError
328
- throw new error_1.MongoRuntimeError(`Cannot parse namespace from "${namespace}"`);
329
- }
330
-
331
- const [db, ...collectionParts] = namespace.split('.');
332
- const collection = collectionParts.join('.');
333
- return new MongoDBNamespace(db, collection === '' ? undefined : collection);
334
- }
335
-
336
- }
337
-
338
- exports.MongoDBNamespace = MongoDBNamespace;
339
- /**
340
- * @public
341
- *
342
- * A class representing a collection's namespace. This class enforces (through Typescript) that
343
- * the `collection` portion of the namespace is defined and should only be
344
- * used in scenarios where this can be guaranteed.
345
- */
346
-
347
- class MongoDBCollectionNamespace extends MongoDBNamespace {
348
- constructor(db, collection) {
349
- super(db, collection);
350
- this.collection = collection;
351
- }
352
-
353
- static fromString(namespace) {
354
- return super.fromString(namespace);
355
- }
356
-
357
- }
358
-
359
- exports.MongoDBCollectionNamespace = MongoDBCollectionNamespace;
360
- /** @internal */
361
-
362
- function* makeCounter(seed = 0) {
363
- let count = seed;
364
-
365
- while (true) {
366
- const newCount = count;
367
- count += 1;
368
- yield newCount;
369
- }
370
- }
371
- /**
372
- * Synchronously Generate a UUIDv4
373
- * @internal
374
- */
375
-
376
-
377
- function uuidV4() {
378
- const result = crypto.randomBytes(16);
379
- result[6] = result[6] & 0x0f | 0x40;
380
- result[8] = result[8] & 0x3f | 0x80;
381
- return result;
382
- }
383
- /**
384
- * A helper function for determining `maxWireVersion` between legacy and new topology instances
385
- * @internal
386
- */
387
-
388
-
389
- function maxWireVersion(topologyOrServer) {
390
- if (topologyOrServer) {
391
- if (topologyOrServer.loadBalanced || topologyOrServer.serverApi?.version) {
392
- // Since we do not have a monitor in the load balanced mode,
393
- // we assume the load-balanced server is always pointed at the latest mongodb version.
394
- // There is a risk that for on-prem deployments
395
- // that don't upgrade immediately that this could alert to the
396
- // application that a feature is available that is actually not.
397
- // We also return the max supported wire version for serverAPI.
398
- return constants_1.MAX_SUPPORTED_WIRE_VERSION;
399
- }
400
-
401
- if (topologyOrServer.hello) {
402
- return topologyOrServer.hello.maxWireVersion;
403
- }
404
-
405
- if ('lastHello' in topologyOrServer && typeof topologyOrServer.lastHello === 'function') {
406
- const lastHello = topologyOrServer.lastHello();
407
-
408
- if (lastHello) {
409
- return lastHello.maxWireVersion;
410
- }
411
- }
412
-
413
- if (topologyOrServer.description && 'maxWireVersion' in topologyOrServer.description && topologyOrServer.description.maxWireVersion != null) {
414
- return topologyOrServer.description.maxWireVersion;
415
- }
416
- }
417
-
418
- return 0;
419
- }
420
- /** @internal */
421
-
422
-
423
- function arrayStrictEqual(arr, arr2) {
424
- if (!Array.isArray(arr) || !Array.isArray(arr2)) {
425
- return false;
426
- }
427
-
428
- return arr.length === arr2.length && arr.every((elt, idx) => elt === arr2[idx]);
429
- }
430
- /** @internal */
431
-
432
-
433
- function errorStrictEqual(lhs, rhs) {
434
- if (lhs === rhs) {
435
- return true;
436
- }
437
-
438
- if (!lhs || !rhs) {
439
- return lhs === rhs;
440
- }
441
-
442
- if (lhs == null && rhs != null || lhs != null && rhs == null) {
443
- return false;
444
- }
445
-
446
- if (lhs.constructor.name !== rhs.constructor.name) {
447
- return false;
448
- }
449
-
450
- if (lhs.message !== rhs.message) {
451
- return false;
452
- }
453
-
454
- return true;
455
- }
456
- /** @internal */
457
-
458
-
459
- function makeStateMachine(stateTable) {
460
- return function stateTransition(target, newState) {
461
- const legalStates = stateTable[target.s.state];
462
-
463
- if (legalStates && legalStates.indexOf(newState) < 0) {
464
- throw new error_1.MongoRuntimeError(`illegal state transition from [${target.s.state}] => [${newState}], allowed: [${legalStates}]`);
465
- }
466
-
467
- target.emit('stateChanged', target.s.state, newState);
468
- target.s.state = newState;
469
- };
470
- }
471
- /** @internal */
472
-
473
-
474
- function now() {
475
- const hrtime = process.hrtime();
476
- return Math.floor(hrtime[0] * 1000 + hrtime[1] / 1000000);
477
- }
478
- /** @internal */
479
-
480
-
481
- function calculateDurationInMs(started) {
482
- if (typeof started !== 'number') {
483
- return -1;
484
- }
485
-
486
- const elapsed = now() - started;
487
- return elapsed < 0 ? 0 : elapsed;
488
- }
489
- /** @internal */
490
-
491
-
492
- function hasAtomicOperators(doc, options) {
493
- if (Array.isArray(doc)) {
494
- for (const document of doc) {
495
- if (hasAtomicOperators(document)) {
496
- return true;
497
- }
498
- }
499
-
500
- return false;
501
- }
502
-
503
- const keys = Object.keys(doc); // In this case we need to throw if all the atomic operators are undefined.
504
-
505
- if (options?.ignoreUndefined) {
506
- let allUndefined = true;
507
-
508
- for (const key of keys) {
509
- // eslint-disable-next-line no-restricted-syntax
510
- if (doc[key] !== undefined) {
511
- allUndefined = false;
512
- break;
513
- }
514
- }
515
-
516
- if (allUndefined) {
517
- throw new error_1.MongoInvalidArgumentError('Update operations require that all atomic operators have defined values, but none were provided.');
518
- }
519
- }
520
-
521
- return keys.length > 0 && keys[0][0] === '$';
522
- }
523
-
524
- function resolveTimeoutOptions(client, options) {
525
- const {
526
- socketTimeoutMS,
527
- serverSelectionTimeoutMS,
528
- waitQueueTimeoutMS,
529
- timeoutMS
530
- } = client.s.options;
531
- return {
532
- socketTimeoutMS,
533
- serverSelectionTimeoutMS,
534
- waitQueueTimeoutMS,
535
- timeoutMS,
536
- ...options
537
- };
538
- }
539
- /**
540
- * Merge inherited properties from parent into options, prioritizing values from options,
541
- * then values from parent.
542
- *
543
- * @param parent - An optional owning class of the operation being run. ex. Db/Collection/MongoClient.
544
- * @param options - The options passed to the operation method.
545
- *
546
- * @internal
547
- */
548
-
549
-
550
- function resolveOptions(parent, options) {
551
- const result = Object.assign({}, options, (0, bson_1.resolveBSONOptions)(options, parent));
552
- const timeoutMS = options?.timeoutMS ?? parent?.timeoutMS; // Users cannot pass a readConcern/writeConcern to operations in a transaction
553
-
554
- const session = options?.session;
555
-
556
- if (!session?.inTransaction()) {
557
- const readConcern = read_concern_1.ReadConcern.fromOptions(options) ?? parent?.readConcern;
558
-
559
- if (readConcern) {
560
- result.readConcern = readConcern;
561
- }
562
-
563
- let writeConcern = write_concern_1.WriteConcern.fromOptions(options) ?? parent?.writeConcern;
564
-
565
- if (writeConcern) {
566
- if (timeoutMS != null) {
567
- writeConcern = write_concern_1.WriteConcern.fromOptions({
568
- writeConcern: { ...writeConcern,
569
- wtimeout: undefined,
570
- wtimeoutMS: undefined
571
- }
572
- });
573
- }
574
-
575
- result.writeConcern = writeConcern;
576
- }
577
- }
578
-
579
- result.timeoutMS = timeoutMS;
580
- const readPreference = read_preference_1.ReadPreference.fromOptions(options) ?? parent?.readPreference;
581
-
582
- if (readPreference) {
583
- result.readPreference = readPreference;
584
- }
585
-
586
- const isConvenientTransaction = session?.explicit && session?.timeoutContext != null;
587
-
588
- if (isConvenientTransaction && options?.timeoutMS != null) {
589
- throw new error_1.MongoInvalidArgumentError('An operation cannot be given a timeoutMS setting when inside a withTransaction call that has a timeoutMS setting');
590
- }
591
-
592
- return result;
593
- }
594
-
595
- function isSuperset(set, subset) {
596
- set = Array.isArray(set) ? new Set(set) : set;
597
- subset = Array.isArray(subset) ? new Set(subset) : subset;
598
-
599
- for (const elem of subset) {
600
- if (!set.has(elem)) {
601
- return false;
602
- }
603
- }
604
-
605
- return true;
606
- }
607
- /**
608
- * Checks if the document is a Hello request
609
- * @internal
610
- */
611
-
612
-
613
- function isHello(doc) {
614
- return doc[constants_2.LEGACY_HELLO_COMMAND] || doc.hello ? true : false;
615
- }
616
- /** Returns the items that are uniquely in setA */
617
-
618
-
619
- function setDifference(setA, setB) {
620
- const difference = new Set(setA);
621
-
622
- for (const elem of setB) {
623
- difference.delete(elem);
624
- }
625
-
626
- return difference;
627
- }
628
-
629
- const HAS_OWN = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
630
-
631
- function isRecord(value, requiredKeys = undefined) {
632
- if (!isObject(value)) {
633
- return false;
634
- }
635
-
636
- const ctor = value.constructor;
637
-
638
- if (ctor && ctor.prototype) {
639
- if (!isObject(ctor.prototype)) {
640
- return false;
641
- } // Check to see if some method exists from the Object exists
642
-
643
-
644
- if (!HAS_OWN(ctor.prototype, 'isPrototypeOf')) {
645
- return false;
646
- }
647
- }
648
-
649
- if (requiredKeys) {
650
- const keys = Object.keys(value);
651
- return isSuperset(keys, requiredKeys);
652
- }
653
-
654
- return true;
655
- }
656
- /**
657
- * A sequential list of items in a circularly linked list
658
- * @remarks
659
- * The head node is special, it is always defined and has a value of null.
660
- * It is never "included" in the list, in that, it is not returned by pop/shift or yielded by the iterator.
661
- * The circular linkage and always defined head node are to reduce checks for null next/prev references to zero.
662
- * New nodes are declared as object literals with keys always in the same order: next, prev, value.
663
- * @internal
664
- */
665
-
666
-
667
- class List {
668
- get length() {
669
- return this.count;
670
- }
671
-
672
- get [Symbol.toStringTag]() {
673
- return 'List';
674
- }
675
-
676
- constructor() {
677
- this.count = 0; // this is carefully crafted:
678
- // declaring a complete and consistently key ordered
679
- // object is beneficial to the runtime optimizations
680
-
681
- this.head = {
682
- next: null,
683
- prev: null,
684
- value: null
685
- };
686
- this.head.next = this.head;
687
- this.head.prev = this.head;
688
- }
689
-
690
- toArray() {
691
- return Array.from(this);
692
- }
693
-
694
- toString() {
695
- return `head <=> ${this.toArray().join(' <=> ')} <=> head`;
696
- }
697
-
698
- *[Symbol.iterator]() {
699
- for (const node of this.nodes()) {
700
- yield node.value;
701
- }
702
- }
703
-
704
- *nodes() {
705
- let ptr = this.head.next;
706
-
707
- while (ptr !== this.head) {
708
- // Save next before yielding so that we make removing within iteration safe
709
- const {
710
- next
711
- } = ptr;
712
- yield ptr;
713
- ptr = next;
714
- }
715
- }
716
- /** Insert at end of list */
717
-
718
-
719
- push(value) {
720
- this.count += 1;
721
- const newNode = {
722
- next: this.head,
723
- prev: this.head.prev,
724
- value
725
- };
726
- this.head.prev.next = newNode;
727
- this.head.prev = newNode;
728
- }
729
- /** Inserts every item inside an iterable instead of the iterable itself */
730
-
731
-
732
- pushMany(iterable) {
733
- for (const value of iterable) {
734
- this.push(value);
735
- }
736
- }
737
- /** Insert at front of list */
738
-
739
-
740
- unshift(value) {
741
- this.count += 1;
742
- const newNode = {
743
- next: this.head.next,
744
- prev: this.head,
745
- value
746
- };
747
- this.head.next.prev = newNode;
748
- this.head.next = newNode;
749
- }
750
-
751
- remove(node) {
752
- if (node === this.head || this.length === 0) {
753
- return null;
754
- }
755
-
756
- this.count -= 1;
757
- const prevNode = node.prev;
758
- const nextNode = node.next;
759
- prevNode.next = nextNode;
760
- nextNode.prev = prevNode;
761
- return node.value;
762
- }
763
- /** Removes the first node at the front of the list */
764
-
765
-
766
- shift() {
767
- return this.remove(this.head.next);
768
- }
769
- /** Removes the last node at the end of the list */
770
-
771
-
772
- pop() {
773
- return this.remove(this.head.prev);
774
- }
775
- /** Iterates through the list and removes nodes where filter returns true */
776
-
777
-
778
- prune(filter) {
779
- for (const node of this.nodes()) {
780
- if (filter(node.value)) {
781
- this.remove(node);
782
- }
783
- }
784
- }
785
-
786
- clear() {
787
- this.count = 0;
788
- this.head.next = this.head;
789
- this.head.prev = this.head;
790
- }
791
- /** Returns the first item in the list, does not remove */
792
-
793
-
794
- first() {
795
- // If the list is empty, value will be the head's null
796
- return this.head.next.value;
797
- }
798
- /** Returns the last item in the list, does not remove */
799
-
800
-
801
- last() {
802
- // If the list is empty, value will be the head's null
803
- return this.head.prev.value;
804
- }
805
-
806
- }
807
-
808
- exports.List = List;
809
- /**
810
- * A pool of Buffers which allow you to read them as if they were one
811
- * @internal
812
- */
813
-
814
- class BufferPool {
815
- constructor() {
816
- this.buffers = new List();
817
- this.totalByteLength = 0;
818
- }
819
-
820
- get length() {
821
- return this.totalByteLength;
822
- }
823
- /** Adds a buffer to the internal buffer pool list */
824
-
825
-
826
- append(buffer) {
827
- this.buffers.push(buffer);
828
- this.totalByteLength += buffer.length;
829
- }
830
- /**
831
- * If BufferPool contains 4 bytes or more construct an int32 from the leading bytes,
832
- * otherwise return null. Size can be negative, caller should error check.
833
- */
834
-
835
-
836
- getInt32() {
837
- if (this.totalByteLength < 4) {
838
- return null;
839
- }
840
-
841
- const firstBuffer = this.buffers.first();
842
-
843
- if (firstBuffer != null && firstBuffer.byteLength >= 4) {
844
- return firstBuffer.readInt32LE(0);
845
- } // Unlikely case: an int32 is split across buffers.
846
- // Use read and put the returned buffer back on top
847
-
848
-
849
- const top4Bytes = this.read(4);
850
- const value = top4Bytes.readInt32LE(0); // Put it back.
851
-
852
- this.totalByteLength += 4;
853
- this.buffers.unshift(top4Bytes);
854
- return value;
855
- }
856
- /** Reads the requested number of bytes, optionally consuming them */
857
-
858
-
859
- read(size) {
860
- if (typeof size !== 'number' || size < 0) {
861
- throw new error_1.MongoInvalidArgumentError('Argument "size" must be a non-negative number');
862
- } // oversized request returns empty buffer
863
-
864
-
865
- if (size > this.totalByteLength) {
866
- return Buffer.alloc(0);
867
- } // We know we have enough, we just don't know how it is spread across chunks
868
- // TODO(NODE-4732): alloc API should change based on raw option
869
-
870
-
871
- const result = Buffer.allocUnsafe(size);
872
-
873
- for (let bytesRead = 0; bytesRead < size;) {
874
- const buffer = this.buffers.shift();
875
-
876
- if (buffer == null) {
877
- break;
878
- }
879
-
880
- const bytesRemaining = size - bytesRead;
881
- const bytesReadable = Math.min(bytesRemaining, buffer.byteLength);
882
- const bytes = buffer.subarray(0, bytesReadable);
883
- result.set(bytes, bytesRead);
884
- bytesRead += bytesReadable;
885
- this.totalByteLength -= bytesReadable;
886
-
887
- if (bytesReadable < buffer.byteLength) {
888
- this.buffers.unshift(buffer.subarray(bytesReadable));
889
- }
890
- }
891
-
892
- return result;
893
- }
894
-
895
- }
896
-
897
- exports.BufferPool = BufferPool;
898
- /** @public */
899
-
900
- class HostAddress {
901
- constructor(hostString) {
902
- this.host = undefined;
903
- this.port = undefined;
904
- this.socketPath = undefined;
905
- this.isIPv6 = false;
906
- const escapedHost = hostString.split(' ').join('%20'); // escape spaces, for socket path hosts
907
-
908
- if (escapedHost.endsWith('.sock')) {
909
- // heuristically determine if we're working with a domain socket
910
- this.socketPath = decodeURIComponent(escapedHost);
911
- return;
912
- }
913
-
914
- const urlString = `iLoveJS://${escapedHost}`;
915
- let url;
916
-
917
- try {
918
- url = new url_1.URL(urlString);
919
- } catch (urlError) {
920
- const runtimeError = new error_1.MongoRuntimeError(`Unable to parse ${escapedHost} with URL`);
921
- runtimeError.cause = urlError;
922
- throw runtimeError;
923
- }
924
-
925
- const hostname = url.hostname;
926
- const port = url.port;
927
- let normalized = decodeURIComponent(hostname).toLowerCase();
928
-
929
- if (normalized.startsWith('[') && normalized.endsWith(']')) {
930
- this.isIPv6 = true;
931
- normalized = normalized.substring(1, hostname.length - 1);
932
- }
933
-
934
- this.host = normalized.toLowerCase();
935
-
936
- if (typeof port === 'number') {
937
- this.port = port;
938
- } else if (typeof port === 'string' && port !== '') {
939
- this.port = Number.parseInt(port, 10);
940
- } else {
941
- this.port = 27017;
942
- }
943
-
944
- if (this.port === 0) {
945
- throw new error_1.MongoParseError('Invalid port (zero) with hostname');
946
- }
947
-
948
- Object.freeze(this);
949
- }
950
-
951
- [Symbol.for('nodejs.util.inspect.custom')]() {
952
- return this.inspect();
953
- }
954
-
955
- inspect() {
956
- return `new HostAddress('${this.toString()}')`;
957
- }
958
-
959
- toString() {
960
- if (typeof this.host === 'string') {
961
- if (this.isIPv6) {
962
- return `[${this.host}]:${this.port}`;
963
- }
964
-
965
- return `${this.host}:${this.port}`;
966
- }
967
-
968
- return `${this.socketPath}`;
969
- }
970
-
971
- static fromString(s) {
972
- return new HostAddress(s);
973
- }
974
-
975
- static fromHostPort(host, port) {
976
- if (host.includes(':')) {
977
- host = `[${host}]`; // IPv6 address
978
- }
979
-
980
- return HostAddress.fromString(`${host}:${port}`);
981
- }
982
-
983
- static fromSrvRecord({
984
- name,
985
- port
986
- }) {
987
- return HostAddress.fromHostPort(name, port);
988
- }
989
-
990
- toHostPort() {
991
- if (this.socketPath) {
992
- return {
993
- host: this.socketPath,
994
- port: 0
995
- };
996
- }
997
-
998
- const host = this.host ?? '';
999
- const port = this.port ?? 0;
1000
- return {
1001
- host,
1002
- port
1003
- };
1004
- }
1005
-
1006
- }
1007
-
1008
- exports.HostAddress = HostAddress;
1009
- exports.DEFAULT_PK_FACTORY = {
1010
- // We prefer not to rely on ObjectId having a createPk method
1011
- createPk() {
1012
- return new bson_1.ObjectId();
1013
- }
1014
-
1015
- };
1016
- /**
1017
- * When the driver used emitWarning the code will be equal to this.
1018
- * @public
1019
- *
1020
- * @example
1021
- * ```ts
1022
- * process.on('warning', (warning) => {
1023
- * if (warning.code === MONGODB_WARNING_CODE) console.error('Ah an important warning! :)')
1024
- * })
1025
- * ```
1026
- */
1027
-
1028
- exports.MONGODB_WARNING_CODE = 'MONGODB DRIVER';
1029
- /** @internal */
1030
-
1031
- function emitWarning(message) {
1032
- return process.emitWarning(message, {
1033
- code: exports.MONGODB_WARNING_CODE
1034
- });
1035
- }
1036
-
1037
- const emittedWarnings = new Set();
1038
- /**
1039
- * Will emit a warning once for the duration of the application.
1040
- * Uses the message to identify if it has already been emitted
1041
- * so using string interpolation can cause multiple emits
1042
- * @internal
1043
- */
1044
-
1045
- function emitWarningOnce(message) {
1046
- if (!emittedWarnings.has(message)) {
1047
- emittedWarnings.add(message);
1048
- return emitWarning(message);
1049
- }
1050
- }
1051
- /**
1052
- * Takes a JS object and joins the values into a string separated by ', '
1053
- */
1054
-
1055
-
1056
- function enumToString(en) {
1057
- return Object.values(en).join(', ');
1058
- }
1059
- /**
1060
- * Determine if a server supports retryable writes.
1061
- *
1062
- * @internal
1063
- */
1064
-
1065
-
1066
- function supportsRetryableWrites(server) {
1067
- if (!server) {
1068
- return false;
1069
- }
1070
-
1071
- if (server.loadBalanced) {
1072
- // Loadbalanced topologies will always support retry writes
1073
- return true;
1074
- }
1075
-
1076
- if (server.description.logicalSessionTimeoutMinutes != null) {
1077
- // that supports sessions
1078
- if (server.description.type !== common_1.ServerType.Standalone) {
1079
- // and that is not a standalone
1080
- return true;
1081
- }
1082
- }
1083
-
1084
- return false;
1085
- }
1086
- /**
1087
- * Fisher–Yates Shuffle
1088
- *
1089
- * Reference: https://bost.ocks.org/mike/shuffle/
1090
- * @param sequence - items to be shuffled
1091
- * @param limit - Defaults to `0`. If nonzero shuffle will slice the randomized array e.g, `.slice(0, limit)` otherwise will return the entire randomized array.
1092
- */
1093
-
1094
-
1095
- function shuffle(sequence, limit = 0) {
1096
- const items = Array.from(sequence); // shallow copy in order to never shuffle the input
1097
-
1098
- if (limit > items.length) {
1099
- throw new error_1.MongoRuntimeError('Limit must be less than the number of items');
1100
- }
1101
-
1102
- let remainingItemsToShuffle = items.length;
1103
- const lowerBound = limit % items.length === 0 ? 1 : items.length - limit;
1104
-
1105
- while (remainingItemsToShuffle > lowerBound) {
1106
- // Pick a remaining element
1107
- const randomIndex = Math.floor(Math.random() * remainingItemsToShuffle);
1108
- remainingItemsToShuffle -= 1; // And swap it with the current element
1109
-
1110
- const swapHold = items[remainingItemsToShuffle];
1111
- items[remainingItemsToShuffle] = items[randomIndex];
1112
- items[randomIndex] = swapHold;
1113
- }
1114
-
1115
- return limit % items.length === 0 ? items : items.slice(lowerBound);
1116
- }
1117
- /**
1118
- * TODO(NODE-4936): read concern eligibility for commands should be codified in command construction
1119
- * @internal
1120
- * @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.md#read-concern
1121
- */
1122
-
1123
-
1124
- function commandSupportsReadConcern(command) {
1125
- if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
1126
- return true;
1127
- }
1128
-
1129
- return false;
1130
- }
1131
- /**
1132
- * Compare objectIds. `null` is always less
1133
- * - `+1 = oid1 is greater than oid2`
1134
- * - `-1 = oid1 is less than oid2`
1135
- * - `+0 = oid1 is equal oid2`
1136
- */
1137
-
1138
-
1139
- function compareObjectId(oid1, oid2) {
1140
- if (oid1 == null && oid2 == null) {
1141
- return 0;
1142
- }
1143
-
1144
- if (oid1 == null) {
1145
- return -1;
1146
- }
1147
-
1148
- if (oid2 == null) {
1149
- return 1;
1150
- }
1151
-
1152
- return exports.ByteUtils.compare(oid1.id, oid2.id);
1153
- }
1154
-
1155
- function parseInteger(value) {
1156
- if (typeof value === 'number') return Math.trunc(value);
1157
- const parsedValue = Number.parseInt(String(value), 10);
1158
- return Number.isNaN(parsedValue) ? null : parsedValue;
1159
- }
1160
-
1161
- function parseUnsignedInteger(value) {
1162
- const parsedInt = parseInteger(value);
1163
- return parsedInt != null && parsedInt >= 0 ? parsedInt : null;
1164
- }
1165
- /**
1166
- * This function throws a MongoAPIError in the event that either of the following is true:
1167
- * * If the provided address domain does not match the provided parent domain
1168
- * * If the parent domain contains less than three `.` separated parts and the provided address does not contain at least one more domain level than its parent
1169
- *
1170
- * If a DNS server were to become compromised SRV records would still need to
1171
- * advertise addresses that are under the same domain as the srvHost.
1172
- *
1173
- * @param address - The address to check against a domain
1174
- * @param srvHost - The domain to check the provided address against
1175
- * @returns void
1176
- */
1177
-
1178
-
1179
- function checkParentDomainMatch(address, srvHost) {
1180
- // Remove trailing dot if exists on either the resolved address or the srv hostname
1181
- const normalizedAddress = address.endsWith('.') ? address.slice(0, address.length - 1) : address;
1182
- const normalizedSrvHost = srvHost.endsWith('.') ? srvHost.slice(0, srvHost.length - 1) : srvHost;
1183
- const allCharacterBeforeFirstDot = /^.*?\./;
1184
- const srvIsLessThanThreeParts = normalizedSrvHost.split('.').length < 3; // Remove all characters before first dot
1185
- // Add leading dot back to string so
1186
- // an srvHostDomain = '.trusted.site'
1187
- // will not satisfy an addressDomain that endsWith '.fake-trusted.site'
1188
-
1189
- const addressDomain = `.${normalizedAddress.replace(allCharacterBeforeFirstDot, '')}`;
1190
- let srvHostDomain = srvIsLessThanThreeParts ? normalizedSrvHost : `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
1191
-
1192
- if (!srvHostDomain.startsWith('.')) {
1193
- srvHostDomain = '.' + srvHostDomain;
1194
- }
1195
-
1196
- if (srvIsLessThanThreeParts && normalizedAddress.split('.').length <= normalizedSrvHost.split('.').length) {
1197
- throw new error_1.MongoAPIError('Server record does not have at least one more domain level than parent URI');
1198
- }
1199
-
1200
- if (!addressDomain.endsWith(srvHostDomain)) {
1201
- throw new error_1.MongoAPIError('Server record does not share hostname with parent URI');
1202
- }
1203
- }
1204
- /**
1205
- * Perform a get request that returns status and body.
1206
- * @internal
1207
- */
1208
-
1209
-
1210
- function get(url, options = {}) {
1211
- return new Promise((resolve, reject) => {
1212
- /* eslint-disable prefer-const */
1213
- let timeoutId;
1214
- const request = http.get(url, options, response => {
1215
- response.setEncoding('utf8');
1216
- let body = '';
1217
- response.on('data', chunk => body += chunk);
1218
- response.on('end', () => {
1219
- (0, timers_1.clearTimeout)(timeoutId);
1220
- resolve({
1221
- status: response.statusCode,
1222
- body
1223
- });
1224
- });
1225
- }).on('error', error => {
1226
- (0, timers_1.clearTimeout)(timeoutId);
1227
- reject(error);
1228
- }).end();
1229
- timeoutId = (0, timers_1.setTimeout)(() => {
1230
- request.destroy(new error_1.MongoNetworkTimeoutError(`request timed out after 10 seconds`));
1231
- }, 10000);
1232
- });
1233
- }
1234
-
1235
- async function request(uri, options = {}) {
1236
- return await new Promise((resolve, reject) => {
1237
- const requestOptions = {
1238
- method: 'GET',
1239
- timeout: 10000,
1240
- json: true,
1241
- ...url.parse(uri),
1242
- ...options
1243
- };
1244
- const req = http.request(requestOptions, res => {
1245
- res.setEncoding('utf8');
1246
- let data = '';
1247
- res.on('data', d => {
1248
- data += d;
1249
- });
1250
- res.once('end', () => {
1251
- if (options.json === false) {
1252
- resolve(data);
1253
- return;
1254
- }
1255
-
1256
- try {
1257
- const parsed = JSON.parse(data);
1258
- resolve(parsed);
1259
- } catch {
1260
- // TODO(NODE-3483)
1261
- reject(new error_1.MongoRuntimeError(`Invalid JSON response: "${data}"`));
1262
- }
1263
- });
1264
- });
1265
- req.once('timeout', () => req.destroy(new error_1.MongoNetworkTimeoutError(`Network request to ${uri} timed out after ${options.timeout} ms`)));
1266
- req.once('error', error => reject(error));
1267
- req.end();
1268
- });
1269
- }
1270
- /** @internal */
1271
-
1272
-
1273
- exports.DOCUMENT_DB_CHECK = /(\.docdb\.amazonaws\.com$)|(\.docdb-elastic\.amazonaws\.com$)/;
1274
- /** @internal */
1275
-
1276
- exports.COSMOS_DB_CHECK = /\.cosmos\.azure\.com$/;
1277
- /** @internal */
1278
-
1279
- exports.DOCUMENT_DB_MSG = 'You appear to be connected to a DocumentDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/documentdb';
1280
- /** @internal */
1281
-
1282
- exports.COSMOS_DB_MSG = 'You appear to be connected to a CosmosDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/cosmosdb';
1283
- /** @internal */
1284
-
1285
- function isHostMatch(match, host) {
1286
- return host && match.test(host.toLowerCase()) ? true : false;
1287
- }
1288
-
1289
- function promiseWithResolvers() {
1290
- let resolve;
1291
- let reject;
1292
- const promise = new Promise(function withResolversExecutor(promiseResolve, promiseReject) {
1293
- resolve = promiseResolve;
1294
- reject = promiseReject;
1295
- });
1296
- return {
1297
- promise,
1298
- resolve,
1299
- reject
1300
- };
1301
- }
1302
- /**
1303
- * A noop function intended for use in preventing unhandled rejections.
1304
- *
1305
- * @example
1306
- * ```js
1307
- * const promise = myAsyncTask();
1308
- * // eslint-disable-next-line github/no-then
1309
- * promise.then(undefined, squashError);
1310
- * ```
1311
- */
1312
-
1313
-
1314
- function squashError(_error) {
1315
- return;
1316
- }
1317
-
1318
- exports.randomBytes = (0, util_1.promisify)(crypto.randomBytes);
1319
- /**
1320
- * Replicates the events.once helper.
1321
- *
1322
- * Removes unused signal logic and It **only** supports 0 or 1 argument events.
1323
- *
1324
- * @param ee - An event emitter that may emit `ev`
1325
- * @param name - An event name to wait for
1326
- */
1327
-
1328
- async function once(ee, name, options) {
1329
- options?.signal?.throwIfAborted();
1330
- const {
1331
- promise,
1332
- resolve,
1333
- reject
1334
- } = promiseWithResolvers();
1335
-
1336
- const onEvent = data => resolve(data);
1337
-
1338
- const onError = error => reject(error);
1339
-
1340
- const abortListener = addAbortListener(options?.signal, function () {
1341
- reject(this.reason);
1342
- });
1343
- ee.once(name, onEvent).once('error', onError);
1344
-
1345
- try {
1346
- return await promise;
1347
- } finally {
1348
- ee.off(name, onEvent);
1349
- ee.off('error', onError);
1350
- abortListener?.[exports.kDispose]();
1351
- }
1352
- }
1353
-
1354
- function maybeAddIdToDocuments(coll, docOrDocs, options) {
1355
- const forceServerObjectId = typeof options.forceServerObjectId === 'boolean' ? options.forceServerObjectId : coll.s.db.options?.forceServerObjectId; // no need to modify the docs if server sets the ObjectId
1356
-
1357
- if (forceServerObjectId === true) {
1358
- return docOrDocs;
1359
- }
1360
-
1361
- const transform = doc => {
1362
- if (doc._id == null) {
1363
- doc._id = coll.s.pkFactory.createPk();
1364
- }
1365
-
1366
- return doc;
1367
- };
1368
-
1369
- return Array.isArray(docOrDocs) ? docOrDocs.map(transform) : transform(docOrDocs);
1370
- }
1371
-
1372
- async function fileIsAccessible(fileName, mode) {
1373
- try {
1374
- await fs_1.promises.access(fileName, mode);
1375
- return true;
1376
- } catch {
1377
- return false;
1378
- }
1379
- }
1380
-
1381
- function csotMin(duration1, duration2) {
1382
- if (duration1 === 0) return duration2;
1383
- if (duration2 === 0) return duration1;
1384
- return Math.min(duration1, duration2);
1385
- }
1386
-
1387
- function noop() {
1388
- return;
1389
- }
1390
- /**
1391
- * Recurse through the (identically-shaped) `decrypted` and `original`
1392
- * objects and attach a `decryptedKeys` property on each sub-object that
1393
- * contained encrypted fields. Because we only call this on BSON responses,
1394
- * we do not need to worry about circular references.
1395
- *
1396
- * @internal
1397
- */
1398
-
1399
-
1400
- function decorateDecryptionResult(decrypted, original, isTopLevelDecorateCall = true) {
1401
- if (isTopLevelDecorateCall) {
1402
- // The original value could have been either a JS object or a BSON buffer
1403
- if (Buffer.isBuffer(original)) {
1404
- original = (0, bson_1.deserialize)(original);
1405
- }
1406
-
1407
- if (Buffer.isBuffer(decrypted)) {
1408
- throw new error_1.MongoRuntimeError('Expected result of decryption to be deserialized BSON object');
1409
- }
1410
- }
1411
-
1412
- if (!decrypted || typeof decrypted !== 'object') return;
1413
-
1414
- for (const k of Object.keys(decrypted)) {
1415
- const originalValue = original[k]; // An object was decrypted by libmongocrypt if and only if it was
1416
- // a BSON Binary object with subtype 6.
1417
-
1418
- if (originalValue && originalValue._bsontype === 'Binary' && originalValue.sub_type === 6) {
1419
- if (!decrypted[constants_2.kDecoratedKeys]) {
1420
- Object.defineProperty(decrypted, constants_2.kDecoratedKeys, {
1421
- value: [],
1422
- configurable: true,
1423
- enumerable: false,
1424
- writable: false
1425
- });
1426
- } // this is defined in the preceding if-statement
1427
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1428
-
1429
-
1430
- decrypted[constants_2.kDecoratedKeys].push(k); // Do not recurse into this decrypted value. It could be a sub-document/array,
1431
- // in which case there is no original value associated with its subfields.
1432
-
1433
- continue;
1434
- }
1435
-
1436
- decorateDecryptionResult(decrypted[k], originalValue, false);
1437
- }
1438
- }
1439
- /** @internal */
1440
-
1441
-
1442
- exports.kDispose = Symbol.dispose ?? Symbol('dispose');
1443
- /**
1444
- * A utility that helps with writing listener code idiomatically
1445
- *
1446
- * @example
1447
- * ```js
1448
- * using listener = addAbortListener(signal, function () {
1449
- * console.log('aborted', this.reason);
1450
- * });
1451
- * ```
1452
- *
1453
- * @param signal - if exists adds an abort listener
1454
- * @param listener - the listener to be added to signal
1455
- * @returns A disposable that will remove the abort listener
1456
- */
1457
-
1458
- function addAbortListener(signal, listener) {
1459
- if (signal == null) return;
1460
- signal.addEventListener('abort', listener, {
1461
- once: true
1462
- });
1463
- return {
1464
- [exports.kDispose]: () => signal.removeEventListener('abort', listener)
1465
- };
1466
- }
1467
- /**
1468
- * Takes a promise and races it with a promise wrapping the abort event of the optionally provided signal.
1469
- * The given promise is _always_ ordered before the signal's abort promise.
1470
- * When given an already rejected promise and an already aborted signal, the promise's rejection takes precedence.
1471
- *
1472
- * Any asynchronous processing in `promise` will continue even after the abort signal has fired,
1473
- * but control will be returned to the caller
1474
- *
1475
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race
1476
- *
1477
- * @param promise - A promise to discard if the signal aborts
1478
- * @param options - An options object carrying an optional signal
1479
- */
1480
-
1481
-
1482
- async function abortable(promise, {
1483
- signal
1484
- }) {
1485
- if (signal == null) {
1486
- return await promise;
1487
- }
1488
-
1489
- const {
1490
- promise: aborted,
1491
- reject
1492
- } = promiseWithResolvers();
1493
- const abortListener = signal.aborted ? reject(signal.reason) : addAbortListener(signal, function () {
1494
- reject(this.reason);
1495
- });
1496
-
1497
- try {
1498
- return await Promise.race([promise, aborted]);
1499
- } finally {
1500
- abortListener?.[exports.kDispose]();
1501
- }
1502
- }