@depup/mongodb 7.1.0-depup.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 (396) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +33 -0
  3. package/etc/prepare.js +12 -0
  4. package/lib/admin.js +136 -0
  5. package/lib/admin.js.map +1 -0
  6. package/lib/bson.js +85 -0
  7. package/lib/bson.js.map +1 -0
  8. package/lib/bulk/common.js +835 -0
  9. package/lib/bulk/common.js.map +1 -0
  10. package/lib/bulk/ordered.js +67 -0
  11. package/lib/bulk/ordered.js.map +1 -0
  12. package/lib/bulk/unordered.js +92 -0
  13. package/lib/bulk/unordered.js.map +1 -0
  14. package/lib/change_stream.js +513 -0
  15. package/lib/change_stream.js.map +1 -0
  16. package/lib/client-side-encryption/auto_encrypter.js +272 -0
  17. package/lib/client-side-encryption/auto_encrypter.js.map +1 -0
  18. package/lib/client-side-encryption/client_encryption.js +609 -0
  19. package/lib/client-side-encryption/client_encryption.js.map +1 -0
  20. package/lib/client-side-encryption/errors.js +138 -0
  21. package/lib/client-side-encryption/errors.js.map +1 -0
  22. package/lib/client-side-encryption/mongocryptd_manager.js +85 -0
  23. package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -0
  24. package/lib/client-side-encryption/providers/aws.js +23 -0
  25. package/lib/client-side-encryption/providers/aws.js.map +1 -0
  26. package/lib/client-side-encryption/providers/azure.js +132 -0
  27. package/lib/client-side-encryption/providers/azure.js.map +1 -0
  28. package/lib/client-side-encryption/providers/gcp.js +16 -0
  29. package/lib/client-side-encryption/providers/gcp.js.map +1 -0
  30. package/lib/client-side-encryption/providers/index.js +43 -0
  31. package/lib/client-side-encryption/providers/index.js.map +1 -0
  32. package/lib/client-side-encryption/state_machine.js +427 -0
  33. package/lib/client-side-encryption/state_machine.js.map +1 -0
  34. package/lib/cmap/auth/auth_provider.js +51 -0
  35. package/lib/cmap/auth/auth_provider.js.map +1 -0
  36. package/lib/cmap/auth/aws4.js +161 -0
  37. package/lib/cmap/auth/aws4.js.map +1 -0
  38. package/lib/cmap/auth/aws_temporary_credentials.js +103 -0
  39. package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
  40. package/lib/cmap/auth/gssapi.js +155 -0
  41. package/lib/cmap/auth/gssapi.js.map +1 -0
  42. package/lib/cmap/auth/mongo_credentials.js +169 -0
  43. package/lib/cmap/auth/mongo_credentials.js.map +1 -0
  44. package/lib/cmap/auth/mongodb_aws.js +128 -0
  45. package/lib/cmap/auth/mongodb_aws.js.map +1 -0
  46. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +84 -0
  47. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -0
  48. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +62 -0
  49. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -0
  50. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +141 -0
  51. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
  52. package/lib/cmap/auth/mongodb_oidc/command_builders.js +44 -0
  53. package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -0
  54. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +39 -0
  55. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -0
  56. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +122 -0
  57. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -0
  58. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +32 -0
  59. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -0
  60. package/lib/cmap/auth/mongodb_oidc/token_cache.js +52 -0
  61. package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -0
  62. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +23 -0
  63. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -0
  64. package/lib/cmap/auth/mongodb_oidc.js +73 -0
  65. package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
  66. package/lib/cmap/auth/plain.js +26 -0
  67. package/lib/cmap/auth/plain.js.map +1 -0
  68. package/lib/cmap/auth/providers.js +22 -0
  69. package/lib/cmap/auth/providers.js.map +1 -0
  70. package/lib/cmap/auth/scram.js +254 -0
  71. package/lib/cmap/auth/scram.js.map +1 -0
  72. package/lib/cmap/auth/x509.js +36 -0
  73. package/lib/cmap/auth/x509.js.map +1 -0
  74. package/lib/cmap/command_monitoring_events.js +223 -0
  75. package/lib/cmap/command_monitoring_events.js.map +1 -0
  76. package/lib/cmap/commands.js +535 -0
  77. package/lib/cmap/commands.js.map +1 -0
  78. package/lib/cmap/connect.js +381 -0
  79. package/lib/cmap/connect.js.map +1 -0
  80. package/lib/cmap/connection.js +571 -0
  81. package/lib/cmap/connection.js.map +1 -0
  82. package/lib/cmap/connection_pool.js +558 -0
  83. package/lib/cmap/connection_pool.js.map +1 -0
  84. package/lib/cmap/connection_pool_events.js +190 -0
  85. package/lib/cmap/connection_pool_events.js.map +1 -0
  86. package/lib/cmap/errors.js +108 -0
  87. package/lib/cmap/errors.js.map +1 -0
  88. package/lib/cmap/handshake/client_metadata.js +242 -0
  89. package/lib/cmap/handshake/client_metadata.js.map +1 -0
  90. package/lib/cmap/metrics.js +62 -0
  91. package/lib/cmap/metrics.js.map +1 -0
  92. package/lib/cmap/stream_description.js +70 -0
  93. package/lib/cmap/stream_description.js.map +1 -0
  94. package/lib/cmap/wire_protocol/compression.js +178 -0
  95. package/lib/cmap/wire_protocol/compression.js.map +1 -0
  96. package/lib/cmap/wire_protocol/constants.js +21 -0
  97. package/lib/cmap/wire_protocol/constants.js.map +1 -0
  98. package/lib/cmap/wire_protocol/on_data.js +111 -0
  99. package/lib/cmap/wire_protocol/on_data.js.map +1 -0
  100. package/lib/cmap/wire_protocol/on_demand/document.js +222 -0
  101. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
  102. package/lib/cmap/wire_protocol/responses.js +315 -0
  103. package/lib/cmap/wire_protocol/responses.js.map +1 -0
  104. package/lib/cmap/wire_protocol/shared.js +35 -0
  105. package/lib/cmap/wire_protocol/shared.js.map +1 -0
  106. package/lib/collection.js +751 -0
  107. package/lib/collection.js.map +1 -0
  108. package/lib/connection_string.js +1090 -0
  109. package/lib/connection_string.js.map +1 -0
  110. package/lib/constants.js +170 -0
  111. package/lib/constants.js.map +1 -0
  112. package/lib/cursor/abstract_cursor.js +924 -0
  113. package/lib/cursor/abstract_cursor.js.map +1 -0
  114. package/lib/cursor/aggregation_cursor.js +164 -0
  115. package/lib/cursor/aggregation_cursor.js.map +1 -0
  116. package/lib/cursor/change_stream_cursor.js +104 -0
  117. package/lib/cursor/change_stream_cursor.js.map +1 -0
  118. package/lib/cursor/client_bulk_write_cursor.js +52 -0
  119. package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
  120. package/lib/cursor/explainable_cursor.js +36 -0
  121. package/lib/cursor/explainable_cursor.js.map +1 -0
  122. package/lib/cursor/find_cursor.js +399 -0
  123. package/lib/cursor/find_cursor.js.map +1 -0
  124. package/lib/cursor/list_collections_cursor.js +34 -0
  125. package/lib/cursor/list_collections_cursor.js.map +1 -0
  126. package/lib/cursor/list_indexes_cursor.js +32 -0
  127. package/lib/cursor/list_indexes_cursor.js.map +1 -0
  128. package/lib/cursor/list_search_indexes_cursor.js +14 -0
  129. package/lib/cursor/list_search_indexes_cursor.js.map +1 -0
  130. package/lib/cursor/run_command_cursor.js +94 -0
  131. package/lib/cursor/run_command_cursor.js.map +1 -0
  132. package/lib/db.js +419 -0
  133. package/lib/db.js.map +1 -0
  134. package/lib/deps.js +112 -0
  135. package/lib/deps.js.map +1 -0
  136. package/lib/encrypter.js +106 -0
  137. package/lib/encrypter.js.map +1 -0
  138. package/lib/error.js +1380 -0
  139. package/lib/error.js.map +1 -0
  140. package/lib/explain.js +59 -0
  141. package/lib/explain.js.map +1 -0
  142. package/lib/gridfs/download.js +305 -0
  143. package/lib/gridfs/download.js.map +1 -0
  144. package/lib/gridfs/index.js +164 -0
  145. package/lib/gridfs/index.js.map +1 -0
  146. package/lib/gridfs/upload.js +358 -0
  147. package/lib/gridfs/upload.js.map +1 -0
  148. package/lib/index.js +193 -0
  149. package/lib/index.js.map +1 -0
  150. package/lib/mongo_client.js +557 -0
  151. package/lib/mongo_client.js.map +1 -0
  152. package/lib/mongo_client_auth_providers.js +80 -0
  153. package/lib/mongo_client_auth_providers.js.map +1 -0
  154. package/lib/mongo_logger.js +655 -0
  155. package/lib/mongo_logger.js.map +1 -0
  156. package/lib/mongo_types.js +56 -0
  157. package/lib/mongo_types.js.map +1 -0
  158. package/lib/operations/aggregate.js +90 -0
  159. package/lib/operations/aggregate.js.map +1 -0
  160. package/lib/operations/client_bulk_write/client_bulk_write.js +51 -0
  161. package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
  162. package/lib/operations/client_bulk_write/command_builder.js +340 -0
  163. package/lib/operations/client_bulk_write/command_builder.js.map +1 -0
  164. package/lib/operations/client_bulk_write/common.js +3 -0
  165. package/lib/operations/client_bulk_write/common.js.map +1 -0
  166. package/lib/operations/client_bulk_write/executor.js +120 -0
  167. package/lib/operations/client_bulk_write/executor.js.map +1 -0
  168. package/lib/operations/client_bulk_write/results_merger.js +204 -0
  169. package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
  170. package/lib/operations/command.js +83 -0
  171. package/lib/operations/command.js.map +1 -0
  172. package/lib/operations/count.js +45 -0
  173. package/lib/operations/count.js.map +1 -0
  174. package/lib/operations/create_collection.js +109 -0
  175. package/lib/operations/create_collection.js.map +1 -0
  176. package/lib/operations/delete.js +125 -0
  177. package/lib/operations/delete.js.map +1 -0
  178. package/lib/operations/distinct.js +61 -0
  179. package/lib/operations/distinct.js.map +1 -0
  180. package/lib/operations/drop.js +93 -0
  181. package/lib/operations/drop.js.map +1 -0
  182. package/lib/operations/end_sessions.js +34 -0
  183. package/lib/operations/end_sessions.js.map +1 -0
  184. package/lib/operations/estimated_document_count.js +41 -0
  185. package/lib/operations/estimated_document_count.js.map +1 -0
  186. package/lib/operations/execute_operation.js +239 -0
  187. package/lib/operations/execute_operation.js.map +1 -0
  188. package/lib/operations/find.js +148 -0
  189. package/lib/operations/find.js.map +1 -0
  190. package/lib/operations/find_and_modify.js +158 -0
  191. package/lib/operations/find_and_modify.js.map +1 -0
  192. package/lib/operations/get_more.js +62 -0
  193. package/lib/operations/get_more.js.map +1 -0
  194. package/lib/operations/indexes.js +186 -0
  195. package/lib/operations/indexes.js.map +1 -0
  196. package/lib/operations/insert.js +70 -0
  197. package/lib/operations/insert.js.map +1 -0
  198. package/lib/operations/kill_cursors.js +43 -0
  199. package/lib/operations/kill_cursors.js.map +1 -0
  200. package/lib/operations/list_collections.js +53 -0
  201. package/lib/operations/list_collections.js.map +1 -0
  202. package/lib/operations/list_databases.js +40 -0
  203. package/lib/operations/list_databases.js.map +1 -0
  204. package/lib/operations/operation.js +102 -0
  205. package/lib/operations/operation.js.map +1 -0
  206. package/lib/operations/profiling_level.js +43 -0
  207. package/lib/operations/profiling_level.js.map +1 -0
  208. package/lib/operations/remove_user.js +27 -0
  209. package/lib/operations/remove_user.js.map +1 -0
  210. package/lib/operations/rename.js +38 -0
  211. package/lib/operations/rename.js.map +1 -0
  212. package/lib/operations/run_command.js +47 -0
  213. package/lib/operations/run_command.js.map +1 -0
  214. package/lib/operations/search_indexes/create.js +33 -0
  215. package/lib/operations/search_indexes/create.js.map +1 -0
  216. package/lib/operations/search_indexes/drop.js +43 -0
  217. package/lib/operations/search_indexes/drop.js.map +1 -0
  218. package/lib/operations/search_indexes/update.js +35 -0
  219. package/lib/operations/search_indexes/update.js.map +1 -0
  220. package/lib/operations/set_profiling_level.js +53 -0
  221. package/lib/operations/set_profiling_level.js.map +1 -0
  222. package/lib/operations/stats.js +27 -0
  223. package/lib/operations/stats.js.map +1 -0
  224. package/lib/operations/update.js +188 -0
  225. package/lib/operations/update.js.map +1 -0
  226. package/lib/operations/validate_collection.js +37 -0
  227. package/lib/operations/validate_collection.js.map +1 -0
  228. package/lib/read_concern.js +73 -0
  229. package/lib/read_concern.js.map +1 -0
  230. package/lib/read_preference.js +191 -0
  231. package/lib/read_preference.js.map +1 -0
  232. package/lib/sdam/common.js +49 -0
  233. package/lib/sdam/common.js.map +1 -0
  234. package/lib/sdam/events.js +146 -0
  235. package/lib/sdam/events.js.map +1 -0
  236. package/lib/sdam/monitor.js +544 -0
  237. package/lib/sdam/monitor.js.map +1 -0
  238. package/lib/sdam/server.js +404 -0
  239. package/lib/sdam/server.js.map +1 -0
  240. package/lib/sdam/server_description.js +204 -0
  241. package/lib/sdam/server_description.js.map +1 -0
  242. package/lib/sdam/server_selection.js +294 -0
  243. package/lib/sdam/server_selection.js.map +1 -0
  244. package/lib/sdam/server_selection_events.js +85 -0
  245. package/lib/sdam/server_selection_events.js.map +1 -0
  246. package/lib/sdam/srv_polling.js +108 -0
  247. package/lib/sdam/srv_polling.js.map +1 -0
  248. package/lib/sdam/topology.js +652 -0
  249. package/lib/sdam/topology.js.map +1 -0
  250. package/lib/sdam/topology_description.js +383 -0
  251. package/lib/sdam/topology_description.js.map +1 -0
  252. package/lib/sessions.js +892 -0
  253. package/lib/sessions.js.map +1 -0
  254. package/lib/sort.js +103 -0
  255. package/lib/sort.js.map +1 -0
  256. package/lib/timeout.js +296 -0
  257. package/lib/timeout.js.map +1 -0
  258. package/lib/transactions.js +135 -0
  259. package/lib/transactions.js.map +1 -0
  260. package/lib/utils.js +1163 -0
  261. package/lib/utils.js.map +1 -0
  262. package/lib/write_concern.js +100 -0
  263. package/lib/write_concern.js.map +1 -0
  264. package/mongodb.d.ts +9018 -0
  265. package/package.json +197 -0
  266. package/src/admin.ts +173 -0
  267. package/src/bson.ts +149 -0
  268. package/src/bulk/common.ts +1251 -0
  269. package/src/bulk/ordered.ts +83 -0
  270. package/src/bulk/unordered.ts +115 -0
  271. package/src/change_stream.ts +1160 -0
  272. package/src/client-side-encryption/auto_encrypter.ts +469 -0
  273. package/src/client-side-encryption/client_encryption.ts +1150 -0
  274. package/src/client-side-encryption/errors.ts +144 -0
  275. package/src/client-side-encryption/mongocryptd_manager.ts +100 -0
  276. package/src/client-side-encryption/providers/aws.ts +33 -0
  277. package/src/client-side-encryption/providers/azure.ts +181 -0
  278. package/src/client-side-encryption/providers/gcp.ts +16 -0
  279. package/src/client-side-encryption/providers/index.ts +207 -0
  280. package/src/client-side-encryption/state_machine.ts +651 -0
  281. package/src/cmap/auth/auth_provider.ts +77 -0
  282. package/src/cmap/auth/aws4.ts +207 -0
  283. package/src/cmap/auth/aws_temporary_credentials.ts +129 -0
  284. package/src/cmap/auth/gssapi.ts +203 -0
  285. package/src/cmap/auth/mongo_credentials.ts +292 -0
  286. package/src/cmap/auth/mongodb_aws.ts +179 -0
  287. package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +88 -0
  288. package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +73 -0
  289. package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +188 -0
  290. package/src/cmap/auth/mongodb_oidc/command_builders.ts +53 -0
  291. package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +46 -0
  292. package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +141 -0
  293. package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +31 -0
  294. package/src/cmap/auth/mongodb_oidc/token_cache.ts +62 -0
  295. package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +22 -0
  296. package/src/cmap/auth/mongodb_oidc.ts +185 -0
  297. package/src/cmap/auth/plain.ts +25 -0
  298. package/src/cmap/auth/providers.ts +22 -0
  299. package/src/cmap/auth/scram.ts +344 -0
  300. package/src/cmap/auth/x509.ts +43 -0
  301. package/src/cmap/command_monitoring_events.ts +316 -0
  302. package/src/cmap/commands.ts +788 -0
  303. package/src/cmap/connect.ts +518 -0
  304. package/src/cmap/connection.ts +931 -0
  305. package/src/cmap/connection_pool.ts +831 -0
  306. package/src/cmap/connection_pool_events.ts +300 -0
  307. package/src/cmap/errors.ts +119 -0
  308. package/src/cmap/handshake/client_metadata.ts +353 -0
  309. package/src/cmap/metrics.ts +58 -0
  310. package/src/cmap/stream_description.ts +96 -0
  311. package/src/cmap/wire_protocol/compression.ts +211 -0
  312. package/src/cmap/wire_protocol/constants.ts +17 -0
  313. package/src/cmap/wire_protocol/on_data.ts +139 -0
  314. package/src/cmap/wire_protocol/on_demand/document.ts +358 -0
  315. package/src/cmap/wire_protocol/responses.ts +393 -0
  316. package/src/cmap/wire_protocol/shared.ts +48 -0
  317. package/src/collection.ts +1314 -0
  318. package/src/connection_string.ts +1297 -0
  319. package/src/constants.ts +176 -0
  320. package/src/cursor/abstract_cursor.ts +1247 -0
  321. package/src/cursor/aggregation_cursor.ts +245 -0
  322. package/src/cursor/change_stream_cursor.ts +171 -0
  323. package/src/cursor/client_bulk_write_cursor.ts +83 -0
  324. package/src/cursor/explainable_cursor.ts +51 -0
  325. package/src/cursor/find_cursor.ts +497 -0
  326. package/src/cursor/list_collections_cursor.ts +50 -0
  327. package/src/cursor/list_indexes_cursor.ts +37 -0
  328. package/src/cursor/list_search_indexes_cursor.ts +20 -0
  329. package/src/cursor/run_command_cursor.ts +178 -0
  330. package/src/db.ts +621 -0
  331. package/src/deps.ts +227 -0
  332. package/src/encrypter.ts +127 -0
  333. package/src/error.ts +1567 -0
  334. package/src/explain.ts +124 -0
  335. package/src/gridfs/download.ts +483 -0
  336. package/src/gridfs/index.ts +264 -0
  337. package/src/gridfs/upload.ts +537 -0
  338. package/src/index.ts +633 -0
  339. package/src/mongo_client.ts +1155 -0
  340. package/src/mongo_client_auth_providers.ts +87 -0
  341. package/src/mongo_logger.ts +1081 -0
  342. package/src/mongo_types.ts +678 -0
  343. package/src/operations/aggregate.ts +153 -0
  344. package/src/operations/client_bulk_write/client_bulk_write.ts +72 -0
  345. package/src/operations/client_bulk_write/command_builder.ts +487 -0
  346. package/src/operations/client_bulk_write/common.ts +276 -0
  347. package/src/operations/client_bulk_write/executor.ts +149 -0
  348. package/src/operations/client_bulk_write/results_merger.ts +260 -0
  349. package/src/operations/command.ts +171 -0
  350. package/src/operations/count.ts +74 -0
  351. package/src/operations/create_collection.ts +218 -0
  352. package/src/operations/delete.ts +183 -0
  353. package/src/operations/distinct.ts +92 -0
  354. package/src/operations/drop.ts +130 -0
  355. package/src/operations/end_sessions.ts +44 -0
  356. package/src/operations/estimated_document_count.ts +61 -0
  357. package/src/operations/execute_operation.ts +319 -0
  358. package/src/operations/find.ts +254 -0
  359. package/src/operations/find_and_modify.ts +319 -0
  360. package/src/operations/get_more.ts +108 -0
  361. package/src/operations/indexes.ts +418 -0
  362. package/src/operations/insert.ts +108 -0
  363. package/src/operations/kill_cursors.ts +64 -0
  364. package/src/operations/list_collections.ts +108 -0
  365. package/src/operations/list_databases.ts +68 -0
  366. package/src/operations/operation.ts +181 -0
  367. package/src/operations/profiling_level.ts +46 -0
  368. package/src/operations/remove_user.ts +36 -0
  369. package/src/operations/rename.ts +60 -0
  370. package/src/operations/run_command.ts +79 -0
  371. package/src/operations/search_indexes/create.ts +56 -0
  372. package/src/operations/search_indexes/drop.ts +58 -0
  373. package/src/operations/search_indexes/update.ts +45 -0
  374. package/src/operations/set_profiling_level.ts +74 -0
  375. package/src/operations/stats.ts +37 -0
  376. package/src/operations/update.ts +318 -0
  377. package/src/operations/validate_collection.ts +50 -0
  378. package/src/read_concern.ts +88 -0
  379. package/src/read_preference.ts +256 -0
  380. package/src/sdam/common.ts +74 -0
  381. package/src/sdam/events.ts +219 -0
  382. package/src/sdam/monitor.ts +771 -0
  383. package/src/sdam/server.ts +595 -0
  384. package/src/sdam/server_description.ts +297 -0
  385. package/src/sdam/server_selection.ts +415 -0
  386. package/src/sdam/server_selection_events.ts +142 -0
  387. package/src/sdam/srv_polling.ts +146 -0
  388. package/src/sdam/topology.ts +1100 -0
  389. package/src/sdam/topology_description.ts +548 -0
  390. package/src/sessions.ts +1244 -0
  391. package/src/sort.ts +141 -0
  392. package/src/timeout.ts +405 -0
  393. package/src/transactions.ts +181 -0
  394. package/src/utils.ts +1434 -0
  395. package/src/write_concern.ts +183 -0
  396. package/tsconfig.json +46 -0
@@ -0,0 +1,1090 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_OPTIONS = exports.OPTIONS = void 0;
4
+ exports.resolveSRVRecord = resolveSRVRecord;
5
+ exports.parseOptions = parseOptions;
6
+ const dns = require("dns");
7
+ const mongodb_connection_string_url_1 = require("mongodb-connection-string-url");
8
+ const process = require("process");
9
+ const url_1 = require("url");
10
+ const mongo_credentials_1 = require("./cmap/auth/mongo_credentials");
11
+ const providers_1 = require("./cmap/auth/providers");
12
+ const compression_1 = require("./cmap/wire_protocol/compression");
13
+ const encrypter_1 = require("./encrypter");
14
+ const error_1 = require("./error");
15
+ const mongo_client_1 = require("./mongo_client");
16
+ const mongo_logger_1 = require("./mongo_logger");
17
+ const read_concern_1 = require("./read_concern");
18
+ const read_preference_1 = require("./read_preference");
19
+ const monitor_1 = require("./sdam/monitor");
20
+ const utils_1 = require("./utils");
21
+ const write_concern_1 = require("./write_concern");
22
+ const VALID_TXT_RECORDS = ['authSource', 'replicaSet', 'loadBalanced'];
23
+ const LB_SINGLE_HOST_ERROR = 'loadBalanced option only supported with a single host in the URI';
24
+ const LB_REPLICA_SET_ERROR = 'loadBalanced option not supported with a replicaSet option';
25
+ const LB_DIRECT_CONNECTION_ERROR = 'loadBalanced option not supported when directConnection is provided';
26
+ function retryDNSTimeoutFor(api) {
27
+ return async function dnsReqRetryTimeout(lookupAddress) {
28
+ try {
29
+ return await dns.promises[api](lookupAddress);
30
+ }
31
+ catch (firstDNSError) {
32
+ if (firstDNSError.code === dns.TIMEOUT) {
33
+ return await dns.promises[api](lookupAddress);
34
+ }
35
+ else {
36
+ throw firstDNSError;
37
+ }
38
+ }
39
+ };
40
+ }
41
+ const resolveSrv = retryDNSTimeoutFor('resolveSrv');
42
+ const resolveTxt = retryDNSTimeoutFor('resolveTxt');
43
+ /**
44
+ * Lookup a `mongodb+srv` connection string, combine the parts and reparse it as a normal
45
+ * connection string.
46
+ *
47
+ * @param uri - The connection string to parse
48
+ * @param options - Optional user provided connection string options
49
+ */
50
+ async function resolveSRVRecord(options) {
51
+ if (typeof options.srvHost !== 'string') {
52
+ throw new error_1.MongoAPIError('Option "srvHost" must not be empty');
53
+ }
54
+ // Asynchronously start TXT resolution so that we do not have to wait until
55
+ // the SRV record is resolved before starting a second DNS query.
56
+ const lookupAddress = options.srvHost;
57
+ const txtResolutionPromise = resolveTxt(lookupAddress);
58
+ txtResolutionPromise.then(undefined, utils_1.squashError); // rejections will be handled later
59
+ const hostname = `_${options.srvServiceName}._tcp.${lookupAddress}`;
60
+ // Resolve the SRV record and use the result as the list of hosts to connect to.
61
+ const addresses = await resolveSrv(hostname);
62
+ if (addresses.length === 0) {
63
+ throw new error_1.MongoAPIError('No addresses found at host');
64
+ }
65
+ for (const { name } of addresses) {
66
+ (0, utils_1.checkParentDomainMatch)(name, lookupAddress);
67
+ }
68
+ const hostAddresses = addresses.map(r => utils_1.HostAddress.fromString(`${r.name}:${r.port ?? 27017}`));
69
+ validateLoadBalancedOptions(hostAddresses, options, true);
70
+ // Use the result of resolving the TXT record and add options from there if they exist.
71
+ let record;
72
+ try {
73
+ record = await txtResolutionPromise;
74
+ }
75
+ catch (error) {
76
+ if (error.code !== 'ENODATA' && error.code !== 'ENOTFOUND') {
77
+ throw error;
78
+ }
79
+ return hostAddresses;
80
+ }
81
+ if (record.length > 1) {
82
+ throw new error_1.MongoParseError('Multiple text records not allowed');
83
+ }
84
+ const txtRecordOptions = new url_1.URLSearchParams(record[0].join(''));
85
+ const txtRecordOptionKeys = [...txtRecordOptions.keys()];
86
+ if (txtRecordOptionKeys.some(key => !VALID_TXT_RECORDS.includes(key))) {
87
+ throw new error_1.MongoParseError(`Text record may only set any of: ${VALID_TXT_RECORDS.join(', ')}`);
88
+ }
89
+ if (VALID_TXT_RECORDS.some(option => txtRecordOptions.get(option) === '')) {
90
+ throw new error_1.MongoParseError('Cannot have empty URI params in DNS TXT Record');
91
+ }
92
+ const source = txtRecordOptions.get('authSource') ?? undefined;
93
+ const replicaSet = txtRecordOptions.get('replicaSet') ?? undefined;
94
+ const loadBalanced = txtRecordOptions.get('loadBalanced') ?? undefined;
95
+ if (!options.userSpecifiedAuthSource &&
96
+ source &&
97
+ options.credentials &&
98
+ !providers_1.AUTH_MECHS_AUTH_SRC_EXTERNAL.has(options.credentials.mechanism)) {
99
+ options.credentials = mongo_credentials_1.MongoCredentials.merge(options.credentials, { source });
100
+ }
101
+ if (!options.userSpecifiedReplicaSet && replicaSet) {
102
+ options.replicaSet = replicaSet;
103
+ }
104
+ if (loadBalanced === 'true') {
105
+ options.loadBalanced = true;
106
+ }
107
+ if (options.replicaSet && options.srvMaxHosts > 0) {
108
+ throw new error_1.MongoParseError('Cannot combine replicaSet option with srvMaxHosts');
109
+ }
110
+ validateLoadBalancedOptions(hostAddresses, options, true);
111
+ return hostAddresses;
112
+ }
113
+ /**
114
+ * Checks if TLS options are valid
115
+ *
116
+ * @param allOptions - All options provided by user or included in default options map
117
+ * @throws MongoAPIError if TLS options are invalid
118
+ */
119
+ function checkTLSOptions(allOptions) {
120
+ if (!allOptions)
121
+ return;
122
+ const check = (a, b) => {
123
+ if (allOptions.has(a) && allOptions.has(b)) {
124
+ throw new error_1.MongoAPIError(`The '${a}' option cannot be used with the '${b}' option`);
125
+ }
126
+ };
127
+ check('tlsInsecure', 'tlsAllowInvalidCertificates');
128
+ check('tlsInsecure', 'tlsAllowInvalidHostnames');
129
+ }
130
+ function getBoolean(name, value) {
131
+ if (typeof value === 'boolean')
132
+ return value;
133
+ switch (value) {
134
+ case 'true':
135
+ return true;
136
+ case 'false':
137
+ return false;
138
+ default:
139
+ throw new error_1.MongoParseError(`${name} must be either "true" or "false"`);
140
+ }
141
+ }
142
+ function getIntFromOptions(name, value) {
143
+ const parsedInt = (0, utils_1.parseInteger)(value);
144
+ if (parsedInt != null) {
145
+ return parsedInt;
146
+ }
147
+ throw new error_1.MongoParseError(`Expected ${name} to be stringified int value, got: ${value}`);
148
+ }
149
+ function getUIntFromOptions(name, value) {
150
+ const parsedValue = getIntFromOptions(name, value);
151
+ if (parsedValue < 0) {
152
+ throw new error_1.MongoParseError(`${name} can only be a positive int value, got: ${value}`);
153
+ }
154
+ return parsedValue;
155
+ }
156
+ function* entriesFromString(value) {
157
+ if (value === '') {
158
+ return;
159
+ }
160
+ const keyValuePairs = value.split(',');
161
+ for (const keyValue of keyValuePairs) {
162
+ const [key, value] = keyValue.split(/:(.*)/);
163
+ if (value == null) {
164
+ throw new error_1.MongoParseError('Cannot have undefined values in key value pairs');
165
+ }
166
+ yield [key, value];
167
+ }
168
+ }
169
+ class CaseInsensitiveMap extends Map {
170
+ constructor(entries = []) {
171
+ super(entries.map(([k, v]) => [k.toLowerCase(), v]));
172
+ }
173
+ has(k) {
174
+ return super.has(k.toLowerCase());
175
+ }
176
+ get(k) {
177
+ return super.get(k.toLowerCase());
178
+ }
179
+ set(k, v) {
180
+ return super.set(k.toLowerCase(), v);
181
+ }
182
+ delete(k) {
183
+ return super.delete(k.toLowerCase());
184
+ }
185
+ }
186
+ function parseOptions(uri, mongoClient = undefined, options = {}) {
187
+ if (mongoClient != null && !(mongoClient instanceof mongo_client_1.MongoClient)) {
188
+ options = mongoClient;
189
+ mongoClient = undefined;
190
+ }
191
+ // validate BSONOptions
192
+ if (options.useBigInt64 && typeof options.promoteLongs === 'boolean' && !options.promoteLongs) {
193
+ throw new error_1.MongoAPIError('Must request either bigint or Long for int64 deserialization');
194
+ }
195
+ if (options.useBigInt64 && typeof options.promoteValues === 'boolean' && !options.promoteValues) {
196
+ throw new error_1.MongoAPIError('Must request either bigint or Long for int64 deserialization');
197
+ }
198
+ const url = new mongodb_connection_string_url_1.default(uri);
199
+ const { hosts, isSRV } = url;
200
+ const mongoOptions = Object.create(null);
201
+ mongoOptions.hosts = isSRV ? [] : hosts.map(utils_1.HostAddress.fromString);
202
+ const urlOptions = new CaseInsensitiveMap();
203
+ if (url.pathname !== '/' && url.pathname !== '') {
204
+ const dbName = decodeURIComponent(url.pathname[0] === '/' ? url.pathname.slice(1) : url.pathname);
205
+ if (dbName) {
206
+ urlOptions.set('dbName', [dbName]);
207
+ }
208
+ }
209
+ if (url.username !== '') {
210
+ const auth = {
211
+ username: decodeURIComponent(url.username)
212
+ };
213
+ if (typeof url.password === 'string') {
214
+ auth.password = decodeURIComponent(url.password);
215
+ }
216
+ urlOptions.set('auth', [auth]);
217
+ }
218
+ for (const key of url.searchParams.keys()) {
219
+ const values = url.searchParams.getAll(key);
220
+ const isReadPreferenceTags = /readPreferenceTags/i.test(key);
221
+ if (!isReadPreferenceTags && values.length > 1) {
222
+ throw new error_1.MongoInvalidArgumentError(`URI option "${key}" cannot appear more than once in the connection string`);
223
+ }
224
+ if (!isReadPreferenceTags && values.includes('')) {
225
+ throw new error_1.MongoAPIError(`URI option "${key}" cannot be specified with no value`);
226
+ }
227
+ if (!urlOptions.has(key)) {
228
+ urlOptions.set(key, values);
229
+ }
230
+ }
231
+ const objectOptions = new CaseInsensitiveMap(Object.entries(options).filter(([, v]) => v != null));
232
+ // Validate options that can only be provided by one of uri or object
233
+ if (urlOptions.has('serverApi')) {
234
+ throw new error_1.MongoParseError('URI cannot contain `serverApi`, it can only be passed to the client');
235
+ }
236
+ const uriMechanismProperties = urlOptions.get('authMechanismProperties');
237
+ if (uriMechanismProperties) {
238
+ for (const property of uriMechanismProperties) {
239
+ if (/(^|,)ALLOWED_HOSTS:/.test(property)) {
240
+ throw new error_1.MongoParseError('Auth mechanism property ALLOWED_HOSTS is not allowed in the connection string.');
241
+ }
242
+ }
243
+ }
244
+ if (objectOptions.has('loadBalanced')) {
245
+ throw new error_1.MongoParseError('loadBalanced is only a valid option in the URI');
246
+ }
247
+ // All option collection
248
+ const allProvidedOptions = new CaseInsensitiveMap();
249
+ const allProvidedKeys = new Set([...urlOptions.keys(), ...objectOptions.keys()]);
250
+ for (const key of allProvidedKeys) {
251
+ const values = [];
252
+ const objectOptionValue = objectOptions.get(key);
253
+ if (objectOptionValue != null) {
254
+ values.push(objectOptionValue);
255
+ }
256
+ const urlValues = urlOptions.get(key) ?? [];
257
+ values.push(...urlValues);
258
+ allProvidedOptions.set(key, values);
259
+ }
260
+ if (allProvidedOptions.has('tls') || allProvidedOptions.has('ssl')) {
261
+ const tlsAndSslOpts = (allProvidedOptions.get('tls') || [])
262
+ .concat(allProvidedOptions.get('ssl') || [])
263
+ .map(getBoolean.bind(null, 'tls/ssl'));
264
+ if (new Set(tlsAndSslOpts).size !== 1) {
265
+ throw new error_1.MongoParseError('All values of tls/ssl must be the same.');
266
+ }
267
+ }
268
+ checkTLSOptions(allProvidedOptions);
269
+ const unsupportedOptions = (0, utils_1.setDifference)(allProvidedKeys, Array.from(Object.keys(exports.OPTIONS)).map(s => s.toLowerCase()));
270
+ if (unsupportedOptions.size !== 0) {
271
+ const optionWord = unsupportedOptions.size > 1 ? 'options' : 'option';
272
+ const isOrAre = unsupportedOptions.size > 1 ? 'are' : 'is';
273
+ throw new error_1.MongoParseError(`${optionWord} ${Array.from(unsupportedOptions).join(', ')} ${isOrAre} not supported`);
274
+ }
275
+ // Option parsing and setting
276
+ for (const [key, descriptor] of Object.entries(exports.OPTIONS)) {
277
+ const values = allProvidedOptions.get(key);
278
+ if (!values || values.length === 0) {
279
+ if (exports.DEFAULT_OPTIONS.has(key)) {
280
+ setOption(mongoOptions, key, descriptor, [exports.DEFAULT_OPTIONS.get(key)]);
281
+ }
282
+ }
283
+ else {
284
+ const { deprecated } = descriptor;
285
+ if (deprecated) {
286
+ const deprecatedMsg = typeof deprecated === 'string' ? `: ${deprecated}` : '';
287
+ (0, utils_1.emitWarning)(`${key} is a deprecated option${deprecatedMsg}`);
288
+ }
289
+ setOption(mongoOptions, key, descriptor, values);
290
+ }
291
+ }
292
+ if (mongoOptions.credentials) {
293
+ const isGssapi = mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_GSSAPI;
294
+ const isX509 = mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_X509;
295
+ const isAws = mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_AWS;
296
+ const isOidc = mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_OIDC;
297
+ if ((isGssapi || isX509) &&
298
+ allProvidedOptions.has('authSource') &&
299
+ mongoOptions.credentials.source !== '$external') {
300
+ // If authSource was explicitly given and its incorrect, we error
301
+ throw new error_1.MongoParseError(`authMechanism ${mongoOptions.credentials.mechanism} requires an authSource of '$external'`);
302
+ }
303
+ if (!(isGssapi || isX509 || isAws || isOidc) &&
304
+ mongoOptions.dbName &&
305
+ !allProvidedOptions.has('authSource')) {
306
+ // inherit the dbName unless GSSAPI or X509, then silently ignore dbName
307
+ // and there was no specific authSource given
308
+ mongoOptions.credentials = mongo_credentials_1.MongoCredentials.merge(mongoOptions.credentials, {
309
+ source: mongoOptions.dbName
310
+ });
311
+ }
312
+ if (isAws) {
313
+ const { username, password } = mongoOptions.credentials;
314
+ if (username || password) {
315
+ throw new error_1.MongoAPIError('username and password cannot be provided when using MONGODB-AWS. Credentials must be provided in a manner that can be read by the AWS SDK.');
316
+ }
317
+ if (mongoOptions.credentials.mechanismProperties.AWS_SESSION_TOKEN) {
318
+ throw new error_1.MongoAPIError('AWS_SESSION_TOKEN cannot be provided when using MONGODB-AWS. Credentials must be provided in a manner that can be read by the AWS SDK.');
319
+ }
320
+ }
321
+ mongoOptions.credentials.validate();
322
+ // Check if the only auth related option provided was authSource, if so we can remove credentials
323
+ if (mongoOptions.credentials.password === '' &&
324
+ mongoOptions.credentials.username === '' &&
325
+ mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_DEFAULT &&
326
+ Object.keys(mongoOptions.credentials.mechanismProperties).length === 0) {
327
+ delete mongoOptions.credentials;
328
+ }
329
+ }
330
+ if (!mongoOptions.dbName) {
331
+ // dbName default is applied here because of the credential validation above
332
+ mongoOptions.dbName = 'test';
333
+ }
334
+ validateLoadBalancedOptions(hosts, mongoOptions, isSRV);
335
+ if (mongoClient && mongoOptions.autoEncryption) {
336
+ encrypter_1.Encrypter.checkForMongoCrypt();
337
+ mongoOptions.encrypter = new encrypter_1.Encrypter(mongoClient, uri, options);
338
+ mongoOptions.autoEncrypter = mongoOptions.encrypter.autoEncrypter;
339
+ }
340
+ // Potential SRV Overrides and SRV connection string validations
341
+ mongoOptions.userSpecifiedAuthSource =
342
+ objectOptions.has('authSource') || urlOptions.has('authSource');
343
+ mongoOptions.userSpecifiedReplicaSet =
344
+ objectOptions.has('replicaSet') || urlOptions.has('replicaSet');
345
+ if (isSRV) {
346
+ // SRV Record is resolved upon connecting
347
+ mongoOptions.srvHost = hosts[0];
348
+ if (mongoOptions.directConnection) {
349
+ throw new error_1.MongoAPIError('SRV URI does not support directConnection');
350
+ }
351
+ if (mongoOptions.srvMaxHosts > 0 && typeof mongoOptions.replicaSet === 'string') {
352
+ throw new error_1.MongoParseError('Cannot use srvMaxHosts option with replicaSet');
353
+ }
354
+ // SRV turns on TLS by default, but users can override and turn it off
355
+ const noUserSpecifiedTLS = !objectOptions.has('tls') && !urlOptions.has('tls');
356
+ const noUserSpecifiedSSL = !objectOptions.has('ssl') && !urlOptions.has('ssl');
357
+ if (noUserSpecifiedTLS && noUserSpecifiedSSL) {
358
+ mongoOptions.tls = true;
359
+ }
360
+ }
361
+ else {
362
+ const userSpecifiedSrvOptions = urlOptions.has('srvMaxHosts') ||
363
+ objectOptions.has('srvMaxHosts') ||
364
+ urlOptions.has('srvServiceName') ||
365
+ objectOptions.has('srvServiceName');
366
+ if (userSpecifiedSrvOptions) {
367
+ throw new error_1.MongoParseError('Cannot use srvMaxHosts or srvServiceName with a non-srv connection string');
368
+ }
369
+ }
370
+ if (mongoOptions.directConnection && mongoOptions.hosts.length !== 1) {
371
+ throw new error_1.MongoParseError('directConnection option requires exactly one host');
372
+ }
373
+ if (!mongoOptions.proxyHost &&
374
+ (mongoOptions.proxyPort || mongoOptions.proxyUsername || mongoOptions.proxyPassword)) {
375
+ throw new error_1.MongoParseError('Must specify proxyHost if other proxy options are passed');
376
+ }
377
+ if ((mongoOptions.proxyUsername && !mongoOptions.proxyPassword) ||
378
+ (!mongoOptions.proxyUsername && mongoOptions.proxyPassword)) {
379
+ throw new error_1.MongoParseError('Can only specify both of proxy username/password or neither');
380
+ }
381
+ const proxyOptions = ['proxyHost', 'proxyPort', 'proxyUsername', 'proxyPassword'].map(key => urlOptions.get(key) ?? []);
382
+ if (proxyOptions.some(options => options.length > 1)) {
383
+ throw new error_1.MongoParseError('Proxy options cannot be specified multiple times in the connection string');
384
+ }
385
+ mongoOptions.mongoLoggerOptions = mongo_logger_1.MongoLogger.resolveOptions({
386
+ MONGODB_LOG_COMMAND: process.env.MONGODB_LOG_COMMAND,
387
+ MONGODB_LOG_TOPOLOGY: process.env.MONGODB_LOG_TOPOLOGY,
388
+ MONGODB_LOG_SERVER_SELECTION: process.env.MONGODB_LOG_SERVER_SELECTION,
389
+ MONGODB_LOG_CONNECTION: process.env.MONGODB_LOG_CONNECTION,
390
+ MONGODB_LOG_CLIENT: process.env.MONGODB_LOG_CLIENT,
391
+ MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL,
392
+ MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH,
393
+ MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH
394
+ }, {
395
+ mongodbLogPath: mongoOptions.mongodbLogPath,
396
+ mongodbLogComponentSeverities: mongoOptions.mongodbLogComponentSeverities,
397
+ mongodbLogMaxDocumentLength: mongoOptions.mongodbLogMaxDocumentLength
398
+ });
399
+ return mongoOptions;
400
+ }
401
+ /**
402
+ * #### Throws if LB mode is true:
403
+ * - hosts contains more than one host
404
+ * - there is a replicaSet name set
405
+ * - directConnection is set
406
+ * - if srvMaxHosts is used when an srv connection string is passed in
407
+ *
408
+ * @throws MongoParseError
409
+ */
410
+ function validateLoadBalancedOptions(hosts, mongoOptions, isSrv) {
411
+ if (mongoOptions.loadBalanced) {
412
+ if (hosts.length > 1) {
413
+ throw new error_1.MongoParseError(LB_SINGLE_HOST_ERROR);
414
+ }
415
+ if (mongoOptions.replicaSet) {
416
+ throw new error_1.MongoParseError(LB_REPLICA_SET_ERROR);
417
+ }
418
+ if (mongoOptions.directConnection) {
419
+ throw new error_1.MongoParseError(LB_DIRECT_CONNECTION_ERROR);
420
+ }
421
+ if (isSrv && mongoOptions.srvMaxHosts > 0) {
422
+ throw new error_1.MongoParseError('Cannot limit srv hosts with loadBalanced enabled');
423
+ }
424
+ }
425
+ return;
426
+ }
427
+ function setOption(mongoOptions, key, descriptor, values) {
428
+ const { target, type, transform } = descriptor;
429
+ const name = target ?? key;
430
+ switch (type) {
431
+ case 'boolean':
432
+ mongoOptions[name] = getBoolean(name, values[0]);
433
+ break;
434
+ case 'int':
435
+ mongoOptions[name] = getIntFromOptions(name, values[0]);
436
+ break;
437
+ case 'uint':
438
+ mongoOptions[name] = getUIntFromOptions(name, values[0]);
439
+ break;
440
+ case 'string':
441
+ if (values[0] == null) {
442
+ break;
443
+ }
444
+ // The value should always be a string here, but since the array is typed as unknown
445
+ // there still needs to be an explicit cast.
446
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
447
+ mongoOptions[name] = String(values[0]);
448
+ break;
449
+ case 'record':
450
+ if (!(0, utils_1.isRecord)(values[0])) {
451
+ throw new error_1.MongoParseError(`${name} must be an object`);
452
+ }
453
+ mongoOptions[name] = values[0];
454
+ break;
455
+ case 'any':
456
+ mongoOptions[name] = values[0];
457
+ break;
458
+ default: {
459
+ if (!transform) {
460
+ throw new error_1.MongoParseError('Descriptors missing a type must define a transform');
461
+ }
462
+ const transformValue = transform({ name, options: mongoOptions, values });
463
+ mongoOptions[name] = transformValue;
464
+ break;
465
+ }
466
+ }
467
+ }
468
+ exports.OPTIONS = {
469
+ appName: {
470
+ type: 'string'
471
+ },
472
+ auth: {
473
+ target: 'credentials',
474
+ transform({ name, options, values: [value] }) {
475
+ if (!(0, utils_1.isRecord)(value, ['username', 'password'])) {
476
+ throw new error_1.MongoParseError(`${name} must be an object with 'username' and 'password' properties`);
477
+ }
478
+ return mongo_credentials_1.MongoCredentials.merge(options.credentials, {
479
+ username: value.username,
480
+ password: value.password
481
+ });
482
+ }
483
+ },
484
+ authMechanism: {
485
+ target: 'credentials',
486
+ transform({ options, values: [value] }) {
487
+ const mechanisms = Object.values(providers_1.AuthMechanism);
488
+ const [mechanism] = mechanisms.filter(m => m.match(RegExp(String.raw `\b${value}\b`, 'i')));
489
+ if (!mechanism) {
490
+ throw new error_1.MongoParseError(`authMechanism one of ${mechanisms}, got ${value}`);
491
+ }
492
+ let source = options.credentials?.source;
493
+ if (mechanism === providers_1.AuthMechanism.MONGODB_PLAIN ||
494
+ providers_1.AUTH_MECHS_AUTH_SRC_EXTERNAL.has(mechanism)) {
495
+ // some mechanisms have '$external' as the Auth Source
496
+ source = '$external';
497
+ }
498
+ let password = options.credentials?.password;
499
+ if (mechanism === providers_1.AuthMechanism.MONGODB_X509 && password === '') {
500
+ password = undefined;
501
+ }
502
+ return mongo_credentials_1.MongoCredentials.merge(options.credentials, {
503
+ mechanism,
504
+ source,
505
+ password
506
+ });
507
+ }
508
+ },
509
+ // Note that if the authMechanismProperties contain a TOKEN_RESOURCE that has a
510
+ // comma in it, it MUST be supplied as a MongoClient option instead of in the
511
+ // connection string.
512
+ authMechanismProperties: {
513
+ target: 'credentials',
514
+ transform({ options, values }) {
515
+ // We can have a combination of options passed in the URI and options passed
516
+ // as an object to the MongoClient. So we must transform the string options
517
+ // as well as merge them together with a potentially provided object.
518
+ let mechanismProperties = Object.create(null);
519
+ for (const optionValue of values) {
520
+ if (typeof optionValue === 'string') {
521
+ for (const [key, value] of entriesFromString(optionValue)) {
522
+ try {
523
+ mechanismProperties[key] = getBoolean(key, value);
524
+ }
525
+ catch {
526
+ mechanismProperties[key] = value;
527
+ }
528
+ }
529
+ }
530
+ else {
531
+ if (!(0, utils_1.isRecord)(optionValue)) {
532
+ throw new error_1.MongoParseError('AuthMechanismProperties must be an object');
533
+ }
534
+ mechanismProperties = { ...optionValue };
535
+ }
536
+ }
537
+ return mongo_credentials_1.MongoCredentials.merge(options.credentials, {
538
+ mechanismProperties
539
+ });
540
+ }
541
+ },
542
+ authSource: {
543
+ target: 'credentials',
544
+ transform({ options, values: [value] }) {
545
+ const source = String(value);
546
+ return mongo_credentials_1.MongoCredentials.merge(options.credentials, { source });
547
+ }
548
+ },
549
+ autoEncryption: {
550
+ type: 'record'
551
+ },
552
+ autoSelectFamily: {
553
+ type: 'boolean',
554
+ default: true
555
+ },
556
+ autoSelectFamilyAttemptTimeout: {
557
+ type: 'uint'
558
+ },
559
+ bsonRegExp: {
560
+ type: 'boolean'
561
+ },
562
+ serverApi: {
563
+ target: 'serverApi',
564
+ transform({ values: [version] }) {
565
+ const serverApiToValidate = typeof version === 'string' ? { version } : version;
566
+ const versionToValidate = serverApiToValidate && serverApiToValidate.version;
567
+ if (!versionToValidate) {
568
+ throw new error_1.MongoParseError(`Invalid \`serverApi\` property; must specify a version from the following enum: ["${Object.values(mongo_client_1.ServerApiVersion).join('", "')}"]`);
569
+ }
570
+ if (!Object.values(mongo_client_1.ServerApiVersion).some(v => v === versionToValidate)) {
571
+ throw new error_1.MongoParseError(`Invalid server API version=${versionToValidate}; must be in the following enum: ["${Object.values(mongo_client_1.ServerApiVersion).join('", "')}"]`);
572
+ }
573
+ return serverApiToValidate;
574
+ }
575
+ },
576
+ checkKeys: {
577
+ type: 'boolean'
578
+ },
579
+ compressors: {
580
+ default: 'none',
581
+ target: 'compressors',
582
+ transform({ values }) {
583
+ const compressionList = new Set();
584
+ for (const compVal of values) {
585
+ const compValArray = typeof compVal === 'string' ? compVal.split(',') : compVal;
586
+ if (!Array.isArray(compValArray)) {
587
+ throw new error_1.MongoInvalidArgumentError('compressors must be an array or a comma-delimited list of strings');
588
+ }
589
+ for (const c of compValArray) {
590
+ if (Object.keys(compression_1.Compressor).includes(String(c))) {
591
+ compressionList.add(String(c));
592
+ }
593
+ else {
594
+ throw new error_1.MongoInvalidArgumentError(`${c} is not a valid compression mechanism. Must be one of: ${Object.keys(compression_1.Compressor)}.`);
595
+ }
596
+ }
597
+ }
598
+ return [...compressionList];
599
+ }
600
+ },
601
+ connectTimeoutMS: {
602
+ default: 30000,
603
+ type: 'uint'
604
+ },
605
+ dbName: {
606
+ type: 'string'
607
+ },
608
+ directConnection: {
609
+ default: false,
610
+ type: 'boolean'
611
+ },
612
+ driverInfo: {
613
+ default: {},
614
+ type: 'record'
615
+ },
616
+ enableUtf8Validation: { type: 'boolean', default: true },
617
+ family: {
618
+ transform({ name, values: [value] }) {
619
+ const transformValue = getIntFromOptions(name, value);
620
+ if (transformValue === 4 || transformValue === 6) {
621
+ return transformValue;
622
+ }
623
+ throw new error_1.MongoParseError(`Option 'family' must be 4 or 6 got ${transformValue}.`);
624
+ }
625
+ },
626
+ fieldsAsRaw: {
627
+ type: 'record'
628
+ },
629
+ forceServerObjectId: {
630
+ default: false,
631
+ type: 'boolean'
632
+ },
633
+ fsync: {
634
+ deprecated: 'Please use journal instead',
635
+ target: 'writeConcern',
636
+ transform({ name, options, values: [value] }) {
637
+ const wc = write_concern_1.WriteConcern.fromOptions({
638
+ writeConcern: {
639
+ ...options.writeConcern,
640
+ fsync: getBoolean(name, value)
641
+ }
642
+ });
643
+ if (!wc)
644
+ throw new error_1.MongoParseError(`Unable to make a writeConcern from fsync=${value}`);
645
+ return wc;
646
+ }
647
+ },
648
+ heartbeatFrequencyMS: {
649
+ default: 10000,
650
+ type: 'uint'
651
+ },
652
+ ignoreUndefined: {
653
+ type: 'boolean'
654
+ },
655
+ j: {
656
+ deprecated: 'Please use journal instead',
657
+ target: 'writeConcern',
658
+ transform({ name, options, values: [value] }) {
659
+ const wc = write_concern_1.WriteConcern.fromOptions({
660
+ writeConcern: {
661
+ ...options.writeConcern,
662
+ journal: getBoolean(name, value)
663
+ }
664
+ });
665
+ if (!wc)
666
+ throw new error_1.MongoParseError(`Unable to make a writeConcern from journal=${value}`);
667
+ return wc;
668
+ }
669
+ },
670
+ journal: {
671
+ target: 'writeConcern',
672
+ transform({ name, options, values: [value] }) {
673
+ const wc = write_concern_1.WriteConcern.fromOptions({
674
+ writeConcern: {
675
+ ...options.writeConcern,
676
+ journal: getBoolean(name, value)
677
+ }
678
+ });
679
+ if (!wc)
680
+ throw new error_1.MongoParseError(`Unable to make a writeConcern from journal=${value}`);
681
+ return wc;
682
+ }
683
+ },
684
+ loadBalanced: {
685
+ default: false,
686
+ type: 'boolean'
687
+ },
688
+ localThresholdMS: {
689
+ default: 15,
690
+ type: 'uint'
691
+ },
692
+ maxConnecting: {
693
+ default: 2,
694
+ transform({ name, values: [value] }) {
695
+ const maxConnecting = getUIntFromOptions(name, value);
696
+ if (maxConnecting === 0) {
697
+ throw new error_1.MongoInvalidArgumentError('maxConnecting must be > 0 if specified');
698
+ }
699
+ return maxConnecting;
700
+ }
701
+ },
702
+ maxIdleTimeMS: {
703
+ default: 0,
704
+ type: 'uint'
705
+ },
706
+ maxPoolSize: {
707
+ default: 100,
708
+ type: 'uint'
709
+ },
710
+ maxStalenessSeconds: {
711
+ target: 'readPreference',
712
+ transform({ name, options, values: [value] }) {
713
+ const maxStalenessSeconds = getUIntFromOptions(name, value);
714
+ if (options.readPreference) {
715
+ return read_preference_1.ReadPreference.fromOptions({
716
+ readPreference: { ...options.readPreference, maxStalenessSeconds }
717
+ });
718
+ }
719
+ else {
720
+ return new read_preference_1.ReadPreference('secondary', undefined, { maxStalenessSeconds });
721
+ }
722
+ }
723
+ },
724
+ minInternalBufferSize: {
725
+ type: 'uint'
726
+ },
727
+ minPoolSize: {
728
+ default: 0,
729
+ type: 'uint'
730
+ },
731
+ minHeartbeatFrequencyMS: {
732
+ default: 500,
733
+ type: 'uint'
734
+ },
735
+ monitorCommands: {
736
+ default: false,
737
+ type: 'boolean'
738
+ },
739
+ name: {
740
+ target: 'driverInfo',
741
+ transform({ values: [value], options }) {
742
+ return { ...options.driverInfo, name: String(value) };
743
+ }
744
+ },
745
+ noDelay: {
746
+ default: true,
747
+ type: 'boolean'
748
+ },
749
+ pkFactory: {
750
+ default: utils_1.DEFAULT_PK_FACTORY,
751
+ transform({ values: [value] }) {
752
+ if ((0, utils_1.isRecord)(value, ['createPk']) && typeof value.createPk === 'function') {
753
+ return value;
754
+ }
755
+ throw new error_1.MongoParseError(`Option pkFactory must be an object with a createPk function, got ${value}`);
756
+ }
757
+ },
758
+ promoteBuffers: {
759
+ type: 'boolean'
760
+ },
761
+ promoteLongs: {
762
+ type: 'boolean'
763
+ },
764
+ promoteValues: {
765
+ type: 'boolean'
766
+ },
767
+ useBigInt64: {
768
+ type: 'boolean'
769
+ },
770
+ proxyHost: {
771
+ type: 'string'
772
+ },
773
+ proxyPassword: {
774
+ type: 'string'
775
+ },
776
+ proxyPort: {
777
+ type: 'uint'
778
+ },
779
+ proxyUsername: {
780
+ type: 'string'
781
+ },
782
+ raw: {
783
+ default: false,
784
+ type: 'boolean'
785
+ },
786
+ readConcern: {
787
+ transform({ values: [value], options }) {
788
+ if (value instanceof read_concern_1.ReadConcern || (0, utils_1.isRecord)(value, ['level'])) {
789
+ return read_concern_1.ReadConcern.fromOptions({ ...options.readConcern, ...value });
790
+ }
791
+ throw new error_1.MongoParseError(`ReadConcern must be an object, got ${JSON.stringify(value)}`);
792
+ }
793
+ },
794
+ readConcernLevel: {
795
+ target: 'readConcern',
796
+ transform({ values: [level], options }) {
797
+ return read_concern_1.ReadConcern.fromOptions({
798
+ ...options.readConcern,
799
+ level: level
800
+ });
801
+ }
802
+ },
803
+ readPreference: {
804
+ default: read_preference_1.ReadPreference.primary,
805
+ transform({ values: [value], options }) {
806
+ if (value instanceof read_preference_1.ReadPreference) {
807
+ return read_preference_1.ReadPreference.fromOptions({
808
+ readPreference: { ...options.readPreference, ...value },
809
+ ...value
810
+ });
811
+ }
812
+ if ((0, utils_1.isRecord)(value, ['mode'])) {
813
+ const rp = read_preference_1.ReadPreference.fromOptions({
814
+ readPreference: { ...options.readPreference, ...value },
815
+ ...value
816
+ });
817
+ if (rp)
818
+ return rp;
819
+ else
820
+ throw new error_1.MongoParseError(`Cannot make read preference from ${JSON.stringify(value)}`);
821
+ }
822
+ if (typeof value === 'string') {
823
+ const rpOpts = {
824
+ hedge: options.readPreference?.hedge,
825
+ maxStalenessSeconds: options.readPreference?.maxStalenessSeconds
826
+ };
827
+ return new read_preference_1.ReadPreference(value, options.readPreference?.tags, rpOpts);
828
+ }
829
+ throw new error_1.MongoParseError(`Unknown ReadPreference value: ${value}`);
830
+ }
831
+ },
832
+ readPreferenceTags: {
833
+ target: 'readPreference',
834
+ transform({ values, options }) {
835
+ const tags = Array.isArray(values[0])
836
+ ? values[0]
837
+ : values;
838
+ const readPreferenceTags = [];
839
+ for (const tag of tags) {
840
+ const readPreferenceTag = Object.create(null);
841
+ if (typeof tag === 'string') {
842
+ for (const [k, v] of entriesFromString(tag)) {
843
+ readPreferenceTag[k] = v;
844
+ }
845
+ }
846
+ if ((0, utils_1.isRecord)(tag)) {
847
+ for (const [k, v] of Object.entries(tag)) {
848
+ readPreferenceTag[k] = v;
849
+ }
850
+ }
851
+ readPreferenceTags.push(readPreferenceTag);
852
+ }
853
+ return read_preference_1.ReadPreference.fromOptions({
854
+ readPreference: options.readPreference,
855
+ readPreferenceTags
856
+ });
857
+ }
858
+ },
859
+ replicaSet: {
860
+ type: 'string'
861
+ },
862
+ retryReads: {
863
+ default: true,
864
+ type: 'boolean'
865
+ },
866
+ retryWrites: {
867
+ default: true,
868
+ type: 'boolean'
869
+ },
870
+ serializeFunctions: {
871
+ type: 'boolean'
872
+ },
873
+ serverMonitoringMode: {
874
+ default: 'auto',
875
+ transform({ values: [value] }) {
876
+ if (!Object.values(monitor_1.ServerMonitoringMode).includes(value)) {
877
+ throw new error_1.MongoParseError('serverMonitoringMode must be one of `auto`, `poll`, or `stream`');
878
+ }
879
+ return value;
880
+ }
881
+ },
882
+ serverSelectionTimeoutMS: {
883
+ default: 30000,
884
+ type: 'uint'
885
+ },
886
+ servername: {
887
+ type: 'string'
888
+ },
889
+ socketTimeoutMS: {
890
+ // TODO(NODE-6491): deprecated: 'Please use timeoutMS instead',
891
+ default: 0,
892
+ type: 'uint'
893
+ },
894
+ srvMaxHosts: {
895
+ type: 'uint',
896
+ default: 0
897
+ },
898
+ srvServiceName: {
899
+ type: 'string',
900
+ default: 'mongodb'
901
+ },
902
+ ssl: {
903
+ target: 'tls',
904
+ type: 'boolean'
905
+ },
906
+ timeoutMS: {
907
+ type: 'uint'
908
+ },
909
+ tls: {
910
+ type: 'boolean'
911
+ },
912
+ tlsAllowInvalidCertificates: {
913
+ target: 'rejectUnauthorized',
914
+ transform({ name, values: [value] }) {
915
+ // allowInvalidCertificates is the inverse of rejectUnauthorized
916
+ return !getBoolean(name, value);
917
+ }
918
+ },
919
+ tlsAllowInvalidHostnames: {
920
+ target: 'checkServerIdentity',
921
+ transform({ name, values: [value] }) {
922
+ // tlsAllowInvalidHostnames means setting the checkServerIdentity function to a noop
923
+ return getBoolean(name, value) ? () => undefined : undefined;
924
+ }
925
+ },
926
+ tlsCAFile: {
927
+ type: 'string'
928
+ },
929
+ tlsCRLFile: {
930
+ type: 'string'
931
+ },
932
+ tlsCertificateKeyFile: {
933
+ type: 'string'
934
+ },
935
+ tlsCertificateKeyFilePassword: {
936
+ target: 'passphrase',
937
+ type: 'any'
938
+ },
939
+ tlsInsecure: {
940
+ transform({ name, options, values: [value] }) {
941
+ const tlsInsecure = getBoolean(name, value);
942
+ if (tlsInsecure) {
943
+ options.checkServerIdentity = () => undefined;
944
+ options.rejectUnauthorized = false;
945
+ }
946
+ else {
947
+ options.checkServerIdentity = options.tlsAllowInvalidHostnames
948
+ ? () => undefined
949
+ : undefined;
950
+ options.rejectUnauthorized = options.tlsAllowInvalidCertificates ? false : true;
951
+ }
952
+ return tlsInsecure;
953
+ }
954
+ },
955
+ w: {
956
+ target: 'writeConcern',
957
+ transform({ values: [value], options }) {
958
+ return write_concern_1.WriteConcern.fromOptions({ writeConcern: { ...options.writeConcern, w: value } });
959
+ }
960
+ },
961
+ waitQueueTimeoutMS: {
962
+ // TODO(NODE-6491): deprecated: 'Please use timeoutMS instead',
963
+ default: 0,
964
+ type: 'uint'
965
+ },
966
+ writeConcern: {
967
+ target: 'writeConcern',
968
+ transform({ values: [value], options }) {
969
+ if ((0, utils_1.isRecord)(value) || value instanceof write_concern_1.WriteConcern) {
970
+ return write_concern_1.WriteConcern.fromOptions({
971
+ writeConcern: {
972
+ ...options.writeConcern,
973
+ ...value
974
+ }
975
+ });
976
+ }
977
+ else if (value === 'majority' || typeof value === 'number') {
978
+ return write_concern_1.WriteConcern.fromOptions({
979
+ writeConcern: {
980
+ ...options.writeConcern,
981
+ w: value
982
+ }
983
+ });
984
+ }
985
+ throw new error_1.MongoParseError(`Invalid WriteConcern cannot parse: ${JSON.stringify(value)}`);
986
+ }
987
+ },
988
+ wtimeout: {
989
+ deprecated: 'Please use wtimeoutMS instead',
990
+ target: 'writeConcern',
991
+ transform({ values: [value], options }) {
992
+ const wc = write_concern_1.WriteConcern.fromOptions({
993
+ writeConcern: {
994
+ ...options.writeConcern,
995
+ wtimeout: getUIntFromOptions('wtimeout', value)
996
+ }
997
+ });
998
+ if (wc)
999
+ return wc;
1000
+ throw new error_1.MongoParseError(`Cannot make WriteConcern from wtimeout`);
1001
+ }
1002
+ },
1003
+ wtimeoutMS: {
1004
+ target: 'writeConcern',
1005
+ transform({ values: [value], options }) {
1006
+ const wc = write_concern_1.WriteConcern.fromOptions({
1007
+ writeConcern: {
1008
+ ...options.writeConcern,
1009
+ wtimeoutMS: getUIntFromOptions('wtimeoutMS', value)
1010
+ }
1011
+ });
1012
+ if (wc)
1013
+ return wc;
1014
+ throw new error_1.MongoParseError(`Cannot make WriteConcern from wtimeout`);
1015
+ }
1016
+ },
1017
+ zlibCompressionLevel: {
1018
+ default: 0,
1019
+ type: 'int'
1020
+ },
1021
+ mongodbLogPath: {
1022
+ transform({ values: [value] }) {
1023
+ if (!((typeof value === 'string' && ['stderr', 'stdout'].includes(value)) ||
1024
+ (value &&
1025
+ typeof value === 'object' &&
1026
+ 'write' in value &&
1027
+ typeof value.write === 'function'))) {
1028
+ throw new error_1.MongoAPIError(`Option 'mongodbLogPath' must be of type 'stderr' | 'stdout' | MongoDBLogWritable`);
1029
+ }
1030
+ return value;
1031
+ }
1032
+ },
1033
+ mongodbLogComponentSeverities: {
1034
+ transform({ values: [value] }) {
1035
+ if (typeof value !== 'object' || !value) {
1036
+ throw new error_1.MongoAPIError(`Option 'mongodbLogComponentSeverities' must be a non-null object`);
1037
+ }
1038
+ for (const [k, v] of Object.entries(value)) {
1039
+ if (typeof v !== 'string' || typeof k !== 'string') {
1040
+ throw new error_1.MongoAPIError(`User input for option 'mongodbLogComponentSeverities' object cannot include a non-string key or value`);
1041
+ }
1042
+ if (!Object.values(mongo_logger_1.MongoLoggableComponent).some(val => val === k) && k !== 'default') {
1043
+ throw new error_1.MongoAPIError(`User input for option 'mongodbLogComponentSeverities' contains invalid key: ${k}`);
1044
+ }
1045
+ if (!Object.values(mongo_logger_1.SeverityLevel).some(val => val === v)) {
1046
+ throw new error_1.MongoAPIError(`Option 'mongodbLogComponentSeverities' does not support ${v} as a value for ${k}`);
1047
+ }
1048
+ }
1049
+ return value;
1050
+ }
1051
+ },
1052
+ mongodbLogMaxDocumentLength: { type: 'uint' },
1053
+ // Custom types for modifying core behavior
1054
+ connectionType: { type: 'any' },
1055
+ srvPoller: { type: 'any' },
1056
+ // Accepted Node.js Options
1057
+ allowPartialTrustChain: { type: 'any' },
1058
+ minDHSize: { type: 'any' },
1059
+ pskCallback: { type: 'any' },
1060
+ secureContext: { type: 'any' },
1061
+ enableTrace: { type: 'any' },
1062
+ requestCert: { type: 'any' },
1063
+ rejectUnauthorized: { type: 'any' },
1064
+ checkServerIdentity: { type: 'any' },
1065
+ keepAliveInitialDelay: { type: 'any' },
1066
+ ALPNProtocols: { type: 'any' },
1067
+ SNICallback: { type: 'any' },
1068
+ session: { type: 'any' },
1069
+ requestOCSP: { type: 'any' },
1070
+ localAddress: { type: 'any' },
1071
+ localPort: { type: 'any' },
1072
+ hints: { type: 'any' },
1073
+ lookup: { type: 'any' },
1074
+ ca: { type: 'any' },
1075
+ cert: { type: 'any' },
1076
+ ciphers: { type: 'any' },
1077
+ crl: { type: 'any' },
1078
+ ecdhCurve: { type: 'any' },
1079
+ key: { type: 'any' },
1080
+ passphrase: { type: 'any' },
1081
+ pfx: { type: 'any' },
1082
+ secureProtocol: { type: 'any' },
1083
+ index: { type: 'any' },
1084
+ // Legacy options from v3 era
1085
+ __skipPingOnConnect: { type: 'boolean' }
1086
+ };
1087
+ exports.DEFAULT_OPTIONS = new CaseInsensitiveMap(Object.entries(exports.OPTIONS)
1088
+ .filter(([, descriptor]) => descriptor.default != null)
1089
+ .map(([k, d]) => [k, d.default]));
1090
+ //# sourceMappingURL=connection_string.js.map