@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,557 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongoClient = exports.ServerApiVersion = void 0;
4
+ const fs_1 = require("fs");
5
+ const _1 = require(".");
6
+ const bson_1 = require("./bson");
7
+ const change_stream_1 = require("./change_stream");
8
+ const mongo_credentials_1 = require("./cmap/auth/mongo_credentials");
9
+ const providers_1 = require("./cmap/auth/providers");
10
+ const client_metadata_1 = require("./cmap/handshake/client_metadata");
11
+ const connection_string_1 = require("./connection_string");
12
+ const constants_1 = require("./constants");
13
+ const db_1 = require("./db");
14
+ const error_1 = require("./error");
15
+ const mongo_client_auth_providers_1 = require("./mongo_client_auth_providers");
16
+ const mongo_logger_1 = require("./mongo_logger");
17
+ const mongo_types_1 = require("./mongo_types");
18
+ const executor_1 = require("./operations/client_bulk_write/executor");
19
+ const end_sessions_1 = require("./operations/end_sessions");
20
+ const execute_operation_1 = require("./operations/execute_operation");
21
+ const read_preference_1 = require("./read_preference");
22
+ const server_selection_1 = require("./sdam/server_selection");
23
+ const topology_1 = require("./sdam/topology");
24
+ const sessions_1 = require("./sessions");
25
+ const utils_1 = require("./utils");
26
+ /** @public */
27
+ exports.ServerApiVersion = Object.freeze({
28
+ v1: '1'
29
+ });
30
+ /**
31
+ * @public
32
+ *
33
+ * The **MongoClient** class is a class that allows for making Connections to MongoDB.
34
+ *
35
+ * **NOTE:** The programmatically provided options take precedence over the URI options.
36
+ *
37
+ * @remarks
38
+ *
39
+ * A MongoClient is the entry point to connecting to a MongoDB server.
40
+ *
41
+ * It handles a multitude of features on your application's behalf:
42
+ * - **Server Host Connection Configuration**: A MongoClient is responsible for reading TLS cert, ca, and crl files if provided.
43
+ * - **SRV Record Polling**: A "`mongodb+srv`" style connection string is used to have the MongoClient resolve DNS SRV records of all server hostnames which the driver periodically monitors for changes and adjusts its current view of hosts correspondingly.
44
+ * - **Server Monitoring**: The MongoClient automatically keeps monitoring the health of server nodes in your cluster to reach out to the correct and lowest latency one available.
45
+ * - **Connection Pooling**: To avoid paying the cost of rebuilding a connection to the server on every operation the MongoClient keeps idle connections preserved for reuse.
46
+ * - **Session Pooling**: The MongoClient creates logical sessions that enable retryable writes, causal consistency, and transactions. It handles pooling these sessions for reuse in subsequent operations.
47
+ * - **Cursor Operations**: A MongoClient's cursors use the health monitoring system to send the request for more documents to the same server the query began on.
48
+ * - **Mongocryptd process**: When using auto encryption, a MongoClient will launch a `mongocryptd` instance for handling encryption if the mongocrypt shared library isn't in use.
49
+ *
50
+ * There are many more features of a MongoClient that are not listed above.
51
+ *
52
+ * In order to enable these features, a number of asynchronous Node.js resources are established by the driver: Timers, FS Requests, Sockets, etc.
53
+ * For details on cleanup, please refer to the MongoClient `close()` documentation.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { MongoClient } from 'mongodb';
58
+ * // Enable command monitoring for debugging
59
+ * const client = new MongoClient('mongodb://localhost:27017?appName=mflix', { monitorCommands: true });
60
+ * ```
61
+ */
62
+ class MongoClient extends mongo_types_1.TypedEventEmitter {
63
+ constructor(url, options) {
64
+ super();
65
+ this.driverInfoList = [];
66
+ this.on('error', utils_1.noop);
67
+ this.options = (0, connection_string_1.parseOptions)(url, this, options);
68
+ this.appendMetadata(this.options.driverInfo);
69
+ const shouldSetLogger = Object.values(this.options.mongoLoggerOptions.componentSeverities).some(value => value !== mongo_logger_1.SeverityLevel.OFF);
70
+ this.mongoLogger = shouldSetLogger
71
+ ? new mongo_logger_1.MongoLogger(this.options.mongoLoggerOptions)
72
+ : undefined;
73
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
74
+ const client = this;
75
+ // The internal state
76
+ this.s = {
77
+ url,
78
+ bsonOptions: (0, bson_1.resolveBSONOptions)(this.options),
79
+ namespace: (0, utils_1.ns)('admin'),
80
+ hasBeenClosed: false,
81
+ sessionPool: new sessions_1.ServerSessionPool(this),
82
+ activeSessions: new Set(),
83
+ activeCursors: new Set(),
84
+ authProviders: new mongo_client_auth_providers_1.MongoClientAuthProviders(),
85
+ get options() {
86
+ return client.options;
87
+ },
88
+ get readConcern() {
89
+ return client.options.readConcern;
90
+ },
91
+ get writeConcern() {
92
+ return client.options.writeConcern;
93
+ },
94
+ get readPreference() {
95
+ return client.options.readPreference;
96
+ },
97
+ get isMongoClient() {
98
+ return true;
99
+ }
100
+ };
101
+ this.checkForNonGenuineHosts();
102
+ }
103
+ /**
104
+ * @experimental
105
+ * An alias for {@link MongoClient.close|MongoClient.close()}.
106
+ */
107
+ async [Symbol.asyncDispose]() {
108
+ await this.close();
109
+ }
110
+ /**
111
+ * Append metadata to the client metadata after instantiation.
112
+ * @param driverInfo - Information about the application or library.
113
+ */
114
+ appendMetadata(driverInfo) {
115
+ const isDuplicateDriverInfo = this.driverInfoList.some(info => (0, client_metadata_1.isDriverInfoEqual)(info, driverInfo));
116
+ if (isDuplicateDriverInfo)
117
+ return;
118
+ this.driverInfoList.push(driverInfo);
119
+ this.options.metadata = (0, client_metadata_1.makeClientMetadata)(this.driverInfoList, this.options)
120
+ .then(undefined, utils_1.squashError)
121
+ .then(result => result ?? {}); // ensure Promise<Document>
122
+ }
123
+ /** @internal */
124
+ checkForNonGenuineHosts() {
125
+ const documentDBHostnames = this.options.hosts.filter((hostAddress) => (0, utils_1.isHostMatch)(utils_1.DOCUMENT_DB_CHECK, hostAddress.host));
126
+ const srvHostIsDocumentDB = (0, utils_1.isHostMatch)(utils_1.DOCUMENT_DB_CHECK, this.options.srvHost);
127
+ const cosmosDBHostnames = this.options.hosts.filter((hostAddress) => (0, utils_1.isHostMatch)(utils_1.COSMOS_DB_CHECK, hostAddress.host));
128
+ const srvHostIsCosmosDB = (0, utils_1.isHostMatch)(utils_1.COSMOS_DB_CHECK, this.options.srvHost);
129
+ if (documentDBHostnames.length !== 0 || srvHostIsDocumentDB) {
130
+ this.mongoLogger?.info('client', utils_1.DOCUMENT_DB_MSG);
131
+ }
132
+ else if (cosmosDBHostnames.length !== 0 || srvHostIsCosmosDB) {
133
+ this.mongoLogger?.info('client', utils_1.COSMOS_DB_MSG);
134
+ }
135
+ }
136
+ get serverApi() {
137
+ return this.options.serverApi && Object.freeze({ ...this.options.serverApi });
138
+ }
139
+ /**
140
+ * Intended for APM use only
141
+ * @internal
142
+ */
143
+ get monitorCommands() {
144
+ return this.options.monitorCommands;
145
+ }
146
+ set monitorCommands(value) {
147
+ this.options.monitorCommands = value;
148
+ }
149
+ /** @internal */
150
+ get autoEncrypter() {
151
+ return this.options.autoEncrypter;
152
+ }
153
+ get readConcern() {
154
+ return this.s.readConcern;
155
+ }
156
+ get writeConcern() {
157
+ return this.s.writeConcern;
158
+ }
159
+ get readPreference() {
160
+ return this.s.readPreference;
161
+ }
162
+ get bsonOptions() {
163
+ return this.s.bsonOptions;
164
+ }
165
+ get timeoutMS() {
166
+ return this.s.options.timeoutMS;
167
+ }
168
+ /**
169
+ * Executes a client bulk write operation, available on server 8.0+.
170
+ * @param models - The client bulk write models.
171
+ * @param options - The client bulk write options.
172
+ * @returns A ClientBulkWriteResult for acknowledged writes and ok: 1 for unacknowledged writes.
173
+ */
174
+ async bulkWrite(models, options) {
175
+ if (this.autoEncrypter) {
176
+ throw new error_1.MongoInvalidArgumentError('MongoClient bulkWrite does not currently support automatic encryption.');
177
+ }
178
+ // We do not need schema type information past this point ("as any" is fine)
179
+ return await new executor_1.ClientBulkWriteExecutor(this, models, (0, utils_1.resolveOptions)(this, options)).execute();
180
+ }
181
+ /**
182
+ * An optional method to verify a handful of assumptions that are generally useful at application boot-time before using a MongoClient.
183
+ * For detailed information about the connect process see the MongoClient.connect static method documentation.
184
+ *
185
+ * @param url - The MongoDB connection string (supports `mongodb://` and `mongodb+srv://` schemes)
186
+ * @param options - Optional configuration options for the client
187
+ *
188
+ * @see https://www.mongodb.com/docs/manual/reference/connection-string/
189
+ */
190
+ async connect() {
191
+ if (this.connectionLock) {
192
+ return await this.connectionLock;
193
+ }
194
+ try {
195
+ this.connectionLock = this._connect();
196
+ await this.connectionLock;
197
+ }
198
+ finally {
199
+ // release
200
+ this.connectionLock = undefined;
201
+ }
202
+ return this;
203
+ }
204
+ /**
205
+ * Create a topology to open the connection, must be locked to avoid topology leaks in concurrency scenario.
206
+ * Locking is enforced by the connect method.
207
+ *
208
+ * @internal
209
+ */
210
+ async _connect() {
211
+ if (this.topology && this.topology.isConnected()) {
212
+ return this;
213
+ }
214
+ const options = this.options;
215
+ if (options.tls) {
216
+ if (typeof options.tlsCAFile === 'string') {
217
+ options.ca ??= await fs_1.promises.readFile(options.tlsCAFile);
218
+ }
219
+ if (typeof options.tlsCRLFile === 'string') {
220
+ options.crl ??= await fs_1.promises.readFile(options.tlsCRLFile);
221
+ }
222
+ if (typeof options.tlsCertificateKeyFile === 'string') {
223
+ if (!options.key || !options.cert) {
224
+ const contents = await fs_1.promises.readFile(options.tlsCertificateKeyFile);
225
+ options.key ??= contents;
226
+ options.cert ??= contents;
227
+ }
228
+ }
229
+ }
230
+ if (typeof options.srvHost === 'string') {
231
+ const hosts = await (0, connection_string_1.resolveSRVRecord)(options);
232
+ for (const [index, host] of hosts.entries()) {
233
+ options.hosts[index] = host;
234
+ }
235
+ }
236
+ // It is important to perform validation of hosts AFTER SRV resolution, to check the real hostname,
237
+ // but BEFORE we even attempt connecting with a potentially not allowed hostname
238
+ if (options.credentials?.mechanism === providers_1.AuthMechanism.MONGODB_OIDC) {
239
+ const allowedHosts = options.credentials?.mechanismProperties?.ALLOWED_HOSTS || mongo_credentials_1.DEFAULT_ALLOWED_HOSTS;
240
+ const isServiceAuth = !!options.credentials?.mechanismProperties?.ENVIRONMENT;
241
+ if (!isServiceAuth) {
242
+ for (const host of options.hosts) {
243
+ if (!(0, utils_1.hostMatchesWildcards)(host.toHostPort().host, allowedHosts)) {
244
+ throw new error_1.MongoInvalidArgumentError(`Host '${host}' is not valid for OIDC authentication with ALLOWED_HOSTS of '${allowedHosts.join(',')}'`);
245
+ }
246
+ }
247
+ }
248
+ }
249
+ this.topology = new topology_1.Topology(this, options.hosts, options);
250
+ // Events can be emitted before initialization is complete so we have to
251
+ // save the reference to the topology on the client ASAP if the event handlers need to access it
252
+ this.topology.once(topology_1.Topology.OPEN, () => this.emit('open', this));
253
+ for (const event of constants_1.MONGO_CLIENT_EVENTS) {
254
+ this.topology.on(event, (...args) => this.emit(event, ...args));
255
+ }
256
+ const topologyConnect = async () => {
257
+ try {
258
+ await this.topology?.connect(options);
259
+ }
260
+ catch (error) {
261
+ this.topology?.close();
262
+ throw error;
263
+ }
264
+ };
265
+ if (this.autoEncrypter) {
266
+ await this.autoEncrypter?.init();
267
+ await topologyConnect();
268
+ await options.encrypter.connectInternalClient();
269
+ }
270
+ else {
271
+ await topologyConnect();
272
+ }
273
+ return this;
274
+ }
275
+ /**
276
+ * Cleans up resources managed by the MongoClient.
277
+ *
278
+ * The close method clears and closes all resources whose lifetimes are managed by the MongoClient.
279
+ * Please refer to the `MongoClient` class documentation for a high level overview of the client's key features and responsibilities.
280
+ *
281
+ * **However,** the close method does not handle the cleanup of resources explicitly created by the user.
282
+ * Any user-created driver resource with its own `close()` method should be explicitly closed by the user before calling MongoClient.close().
283
+ * This method is written as a "best effort" attempt to leave behind the least amount of resources server-side when possible.
284
+ *
285
+ * The following list defines ideal preconditions and consequent pitfalls if they are not met.
286
+ * The MongoClient, ClientSession, Cursors and ChangeStreams all support [explicit resource management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html).
287
+ * By using explicit resource management to manage the lifetime of driver resources instead of manually managing their lifetimes, the pitfalls outlined below can be avoided.
288
+ *
289
+ * The close method performs the following in the order listed:
290
+ * - Client-side:
291
+ * - **Close in-use connections**: Any connections that are currently waiting on a response from the server will be closed.
292
+ * This is performed _first_ to avoid reaching the next step (server-side clean up) and having no available connections to check out.
293
+ * - _Ideal_: All operations have been awaited or cancelled, and the outcomes, regardless of success or failure, have been processed before closing the client servicing the operation.
294
+ * - _Pitfall_: When `client.close()` is called and all connections are in use, after closing them, the client must create new connections for cleanup operations, which comes at the cost of new TLS/TCP handshakes and authentication steps.
295
+ * - Server-side:
296
+ * - **Close active cursors**: All cursors that haven't been completed will have a `killCursor` operation sent to the server they were initialized on, freeing the server-side resource.
297
+ * - _Ideal_: Cursors are explicitly closed or completed before `client.close()` is called.
298
+ * - _Pitfall_: `killCursors` may have to build a new connection if the in-use closure ended all pooled connections.
299
+ * - **End active sessions**: In-use sessions created with `client.startSession()` or `client.withSession()` or implicitly by the driver will have their `.endSession()` method called.
300
+ * Contrary to the name of the method, `endSession()` returns the session to the client's pool of sessions rather than end them on the server.
301
+ * - _Ideal_: Transaction outcomes are awaited and their corresponding explicit sessions are ended before `client.close()` is called.
302
+ * - _Pitfall_: **This step aborts in-progress transactions**. It is advisable to observe the outcome of a transaction before closing your client.
303
+ * - **End all pooled sessions**: The `endSessions` command with all session IDs the client has pooled is sent to the server to inform the cluster it can clean them up.
304
+ * - _Ideal_: No user intervention is expected.
305
+ * - _Pitfall_: None.
306
+ *
307
+ * The remaining shutdown is of the MongoClient resources that are intended to be entirely internal but is documented here as their existence relates to the JS event loop.
308
+ *
309
+ * - Client-side (again):
310
+ * - **Stop all server monitoring**: Connections kept live for detecting cluster changes and roundtrip time measurements are shutdown.
311
+ * - **Close all pooled connections**: Each server node in the cluster has a corresponding connection pool and all connections in the pool are closed. Any operations waiting to check out a connection will have an error thrown instead of a connection returned.
312
+ * - **Clear out server selection queue**: Any operations that are in the process of waiting for a server to be selected will have an error thrown instead of a server returned.
313
+ * - **Close encryption-related resources**: An internal MongoClient created for communicating with `mongocryptd` or other encryption purposes is closed. (Using this same method of course!)
314
+ *
315
+ * After the close method completes there should be no MongoClient related resources [ref-ed in Node.js' event loop](https://docs.libuv.org/en/v1.x/handle.html#reference-counting).
316
+ * This should allow Node.js to exit gracefully if MongoClient resources were the only active handles in the event loop.
317
+ *
318
+ * @param _force - currently an unused flag that has no effect. Defaults to `false`.
319
+ */
320
+ async close(_force = false) {
321
+ if (this.closeLock) {
322
+ return await this.closeLock;
323
+ }
324
+ try {
325
+ this.closeLock = this._close();
326
+ await this.closeLock;
327
+ }
328
+ finally {
329
+ // release
330
+ this.closeLock = undefined;
331
+ }
332
+ }
333
+ /* @internal */
334
+ async _close() {
335
+ // There's no way to set hasBeenClosed back to false
336
+ Object.defineProperty(this.s, 'hasBeenClosed', {
337
+ value: true,
338
+ enumerable: true,
339
+ configurable: false,
340
+ writable: false
341
+ });
342
+ this.topology?.closeCheckedOutConnections();
343
+ const activeCursorCloses = Array.from(this.s.activeCursors, cursor => cursor.close());
344
+ this.s.activeCursors.clear();
345
+ await Promise.all(activeCursorCloses);
346
+ const activeSessionEnds = Array.from(this.s.activeSessions, session => session.endSession());
347
+ this.s.activeSessions.clear();
348
+ await Promise.all(activeSessionEnds);
349
+ if (this.topology == null) {
350
+ return;
351
+ }
352
+ const supportsSessions = this.topology.description.type === _1.TopologyType.LoadBalanced ||
353
+ this.topology.description.logicalSessionTimeoutMinutes != null;
354
+ if (supportsSessions) {
355
+ await endSessions(this, this.topology);
356
+ }
357
+ // clear out references to old topology
358
+ const topology = this.topology;
359
+ this.topology = undefined;
360
+ topology.close();
361
+ const { encrypter } = this.options;
362
+ if (encrypter) {
363
+ await encrypter.close(this);
364
+ }
365
+ async function endSessions(client, { description: topologyDescription }) {
366
+ // If we would attempt to select a server and get nothing back we short circuit
367
+ // to avoid the server selection timeout.
368
+ const selector = (0, server_selection_1.readPreferenceServerSelector)(read_preference_1.ReadPreference.primaryPreferred);
369
+ const serverDescriptions = Array.from(topologyDescription.servers.values());
370
+ const servers = selector(topologyDescription, serverDescriptions, new server_selection_1.DeprioritizedServers());
371
+ if (servers.length !== 0) {
372
+ const endSessions = Array.from(client.s.sessionPool.sessions, ({ id }) => id);
373
+ if (endSessions.length !== 0) {
374
+ try {
375
+ await (0, execute_operation_1.executeOperation)(client, new end_sessions_1.EndSessionsOperation(endSessions));
376
+ }
377
+ catch (error) {
378
+ (0, utils_1.squashError)(error);
379
+ }
380
+ }
381
+ }
382
+ }
383
+ }
384
+ /**
385
+ * Create a new Db instance sharing the current socket connections.
386
+ *
387
+ * @param dbName - The name of the database we want to use. If not provided, use database name from connection string.
388
+ * @param options - Optional settings for Db construction
389
+ */
390
+ db(dbName, options) {
391
+ options = options ?? {};
392
+ // Default to db from connection string if not provided
393
+ if (!dbName) {
394
+ dbName = this.s.options.dbName;
395
+ }
396
+ // Copy the options and add out internal override of the not shared flag
397
+ const finalOptions = Object.assign({}, this.options, options);
398
+ // Return the db object
399
+ const db = new db_1.Db(this, dbName, finalOptions);
400
+ // Return the database
401
+ return db;
402
+ }
403
+ /**
404
+ * Creates a new MongoClient instance and immediately connects it to MongoDB.
405
+ * This convenience method combines `new MongoClient(url, options)` and `client.connect()` in a single step.
406
+ *
407
+ * Connect can be helpful to detect configuration issues early by validating:
408
+ * - **DNS Resolution**: Verifies that SRV records and hostnames in the connection string resolve DNS entries
409
+ * - **Network Connectivity**: Confirms that host addresses are reachable and ports are open
410
+ * - **TLS Configuration**: Validates SSL/TLS certificates, CA files, and encryption settings are correct
411
+ * - **Authentication**: Verifies that provided credentials are valid
412
+ * - **Server Compatibility**: Ensures the MongoDB server version is supported by this driver version
413
+ * - **Load Balancer Setup**: For load-balanced deployments, confirms the service is properly configured
414
+ *
415
+ * @returns A promise that resolves to the same MongoClient instance once connected
416
+ *
417
+ * @remarks
418
+ * **Connection is Optional:** Calling `connect` is optional since any operation method (`find`, `insertOne`, etc.)
419
+ * will automatically perform these same validation steps if the client is not already connected.
420
+ * However, explicitly calling `connect` can make sense for:
421
+ * - **Fail-fast Error Detection**: Non-transient connection issues (hostname unresolved, port refused connection) are discovered immediately rather than during your first operation
422
+ * - **Predictable Performance**: Eliminates first connection overhead from your first database operation
423
+ *
424
+ * @remarks
425
+ * **Connection Pooling Impact:** Calling `connect` will populate the connection pool with one connection
426
+ * to a server selected by the client's configured `readPreference` (defaults to primary).
427
+ *
428
+ * @remarks
429
+ * **Timeout Behavior:** When using `timeoutMS`, the connection establishment time does not count against
430
+ * the timeout for subsequent operations. This means `connect` runs without a `timeoutMS` limit, while
431
+ * your database operations will still respect the configured timeout. If you need predictable operation
432
+ * timing with `timeoutMS`, call `connect` explicitly before performing operations.
433
+ *
434
+ * @see https://www.mongodb.com/docs/manual/reference/connection-string/
435
+ */
436
+ static async connect(url, options) {
437
+ const client = new this(url, options);
438
+ return await client.connect();
439
+ }
440
+ /**
441
+ * Creates a new ClientSession. When using the returned session in an operation
442
+ * a corresponding ServerSession will be created.
443
+ *
444
+ * @remarks
445
+ * A ClientSession instance may only be passed to operations being performed on the same
446
+ * MongoClient it was started from.
447
+ */
448
+ startSession(options) {
449
+ const session = new sessions_1.ClientSession(this, this.s.sessionPool, { explicit: true, ...options }, this.options);
450
+ this.s.activeSessions.add(session);
451
+ session.once('ended', () => {
452
+ this.s.activeSessions.delete(session);
453
+ });
454
+ return session;
455
+ }
456
+ async withSession(optionsOrExecutor, executor) {
457
+ const options = {
458
+ // Always define an owner
459
+ owner: Symbol(),
460
+ // If it's an object inherit the options
461
+ ...(typeof optionsOrExecutor === 'object' ? optionsOrExecutor : {})
462
+ };
463
+ const withSessionCallback = typeof optionsOrExecutor === 'function' ? optionsOrExecutor : executor;
464
+ if (withSessionCallback == null) {
465
+ throw new error_1.MongoInvalidArgumentError('Missing required callback parameter');
466
+ }
467
+ const session = this.startSession(options);
468
+ try {
469
+ return await withSessionCallback(session);
470
+ }
471
+ finally {
472
+ try {
473
+ await session.endSession();
474
+ }
475
+ catch (error) {
476
+ (0, utils_1.squashError)(error);
477
+ }
478
+ }
479
+ }
480
+ /**
481
+ * Create a new Change Stream, watching for new changes (insertions, updates,
482
+ * replacements, deletions, and invalidations) in this cluster. Will ignore all
483
+ * changes to system collections, as well as the local, admin, and config databases.
484
+ *
485
+ * @remarks
486
+ * watch() accepts two generic arguments for distinct use cases:
487
+ * - The first is to provide the schema that may be defined for all the data within the current cluster
488
+ * - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
489
+ *
490
+ * @remarks
491
+ * When `timeoutMS` is configured for a change stream, it will have different behaviour depending
492
+ * on whether the change stream is in iterator mode or emitter mode. In both cases, a change
493
+ * stream will time out if it does not receive a change event within `timeoutMS` of the last change
494
+ * event.
495
+ *
496
+ * Note that if a change stream is consistently timing out when watching a collection, database or
497
+ * client that is being changed, then this may be due to the server timing out before it can finish
498
+ * processing the existing oplog. To address this, restart the change stream with a higher
499
+ * `timeoutMS`.
500
+ *
501
+ * If the change stream times out the initial aggregate operation to establish the change stream on
502
+ * the server, then the client will close the change stream. If the getMore calls to the server
503
+ * time out, then the change stream will be left open, but will throw a MongoOperationTimeoutError
504
+ * when in iterator mode and emit an error event that returns a MongoOperationTimeoutError in
505
+ * emitter mode.
506
+ *
507
+ * To determine whether or not the change stream is still open following a timeout, check the
508
+ * {@link ChangeStream.closed} getter.
509
+ *
510
+ * @example
511
+ * In iterator mode, if a next() call throws a timeout error, it will attempt to resume the change stream.
512
+ * The next call can just be retried after this succeeds.
513
+ * ```ts
514
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
515
+ * try {
516
+ * await changeStream.next();
517
+ * } catch (e) {
518
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
519
+ * await changeStream.next();
520
+ * }
521
+ * throw e;
522
+ * }
523
+ * ```
524
+ *
525
+ * @example
526
+ * In emitter mode, if the change stream goes `timeoutMS` without emitting a change event, it will
527
+ * emit an error event that returns a MongoOperationTimeoutError, but will not close the change
528
+ * stream unless the resume attempt fails. There is no need to re-establish change listeners as
529
+ * this will automatically continue emitting change events once the resume attempt completes.
530
+ *
531
+ * ```ts
532
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
533
+ * changeStream.on('change', console.log);
534
+ * changeStream.on('error', e => {
535
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
536
+ * // do nothing
537
+ * } else {
538
+ * changeStream.close();
539
+ * }
540
+ * });
541
+ * ```
542
+ * @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
543
+ * @param options - Optional settings for the command
544
+ * @typeParam TSchema - Type of the data being detected by the change stream
545
+ * @typeParam TChange - Type of the whole change stream document emitted
546
+ */
547
+ watch(pipeline = [], options = {}) {
548
+ // Allow optionally not specifying a pipeline
549
+ if (!Array.isArray(pipeline)) {
550
+ options = pipeline;
551
+ pipeline = [];
552
+ }
553
+ return new change_stream_1.ChangeStream(this, pipeline, (0, utils_1.resolveOptions)(this, options));
554
+ }
555
+ }
556
+ exports.MongoClient = MongoClient;
557
+ //# sourceMappingURL=mongo_client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo_client.js","sourceRoot":"","sources":["../src/mongo_client.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AAIpC,wBAAiC;AACjC,iCAAsF;AACtF,mDAAoG;AAEpG,qEAIuC;AAEvC,qDAAsD;AAGtD,sEAI0C;AAE1C,2DAAqE;AACrE,2CAAkD;AAElD,6BAA0C;AAE1C,mCAAoD;AACpD,+EAAyE;AACzE,iDAMwB;AACxB,+CAAkD;AAMlD,sEAAkF;AAClF,4DAAiE;AACjE,sEAAkE;AAElE,uDAA4E;AAG5E,8DAA6F;AAE7F,8CAAgE;AAChE,yCAAyF;AACzF,mCAaiB;AAGjB,cAAc;AACD,QAAA,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,EAAE,EAAE,GAAG;CACC,CAAC,CAAC;AA8RZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,WAAY,SAAQ,+BAAoC;IAyBnE,YAAY,GAAW,EAAE,OAA4B;QACnD,KAAK,EAAE,CAAC;QAHF,mBAAc,GAAiB,EAAE,CAAC;QAIxC,IA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;OAkEG;IACH,KAAK,CAGH,WAAuB,EAAE,EAAE,UAA+B,EAAE;QAC5D,6CAA6C;QAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,OAAO,GAAG,QAAQ,CAAC;YACnB,QAAQ,GAAG,EAAE,CAAC;QAChB,CAAC;QAED,OAAO,IAAI,4BAAY,CAAmB,IAAI,EAAE,QAAQ,EAAE,IAAA,sBAAc,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3F,CAAC;CACF;AA5mBD,kCA4mBC"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongoClientAuthProviders = void 0;
4
+ const gssapi_1 = require("./cmap/auth/gssapi");
5
+ const mongodb_aws_1 = require("./cmap/auth/mongodb_aws");
6
+ const mongodb_oidc_1 = require("./cmap/auth/mongodb_oidc");
7
+ const automated_callback_workflow_1 = require("./cmap/auth/mongodb_oidc/automated_callback_workflow");
8
+ const human_callback_workflow_1 = require("./cmap/auth/mongodb_oidc/human_callback_workflow");
9
+ const token_cache_1 = require("./cmap/auth/mongodb_oidc/token_cache");
10
+ const plain_1 = require("./cmap/auth/plain");
11
+ const providers_1 = require("./cmap/auth/providers");
12
+ const scram_1 = require("./cmap/auth/scram");
13
+ const x509_1 = require("./cmap/auth/x509");
14
+ const error_1 = require("./error");
15
+ /** @internal */
16
+ const AUTH_PROVIDERS = new Map([
17
+ [
18
+ providers_1.AuthMechanism.MONGODB_AWS,
19
+ ({ AWS_CREDENTIAL_PROVIDER }) => new mongodb_aws_1.MongoDBAWS(AWS_CREDENTIAL_PROVIDER)
20
+ ],
21
+ [providers_1.AuthMechanism.MONGODB_GSSAPI, () => new gssapi_1.GSSAPI()],
22
+ [providers_1.AuthMechanism.MONGODB_OIDC, properties => new mongodb_oidc_1.MongoDBOIDC(getWorkflow(properties))],
23
+ [providers_1.AuthMechanism.MONGODB_PLAIN, () => new plain_1.Plain()],
24
+ [providers_1.AuthMechanism.MONGODB_SCRAM_SHA1, () => new scram_1.ScramSHA1()],
25
+ [providers_1.AuthMechanism.MONGODB_SCRAM_SHA256, () => new scram_1.ScramSHA256()],
26
+ [providers_1.AuthMechanism.MONGODB_X509, () => new x509_1.X509()]
27
+ ]);
28
+ /**
29
+ * Create a set of providers per client
30
+ * to avoid sharing the provider's cache between different clients.
31
+ * @internal
32
+ */
33
+ class MongoClientAuthProviders {
34
+ constructor() {
35
+ this.existingProviders = new Map();
36
+ }
37
+ /**
38
+ * Get or create an authentication provider based on the provided mechanism.
39
+ * We don't want to create all providers at once, as some providers may not be used.
40
+ * @param name - The name of the provider to get or create.
41
+ * @param credentials - The credentials.
42
+ * @returns The provider.
43
+ * @throws MongoInvalidArgumentError if the mechanism is not supported.
44
+ * @internal
45
+ */
46
+ getOrCreateProvider(name, authMechanismProperties) {
47
+ const authProvider = this.existingProviders.get(name);
48
+ if (authProvider) {
49
+ return authProvider;
50
+ }
51
+ const providerFunction = AUTH_PROVIDERS.get(name);
52
+ if (!providerFunction) {
53
+ throw new error_1.MongoInvalidArgumentError(`authMechanism ${name} not supported`);
54
+ }
55
+ const provider = providerFunction(authMechanismProperties);
56
+ this.existingProviders.set(name, provider);
57
+ return provider;
58
+ }
59
+ }
60
+ exports.MongoClientAuthProviders = MongoClientAuthProviders;
61
+ /**
62
+ * Gets either a device workflow or callback workflow.
63
+ */
64
+ function getWorkflow(authMechanismProperties) {
65
+ if (authMechanismProperties.OIDC_HUMAN_CALLBACK) {
66
+ return new human_callback_workflow_1.HumanCallbackWorkflow(new token_cache_1.TokenCache(), authMechanismProperties.OIDC_HUMAN_CALLBACK);
67
+ }
68
+ else if (authMechanismProperties.OIDC_CALLBACK) {
69
+ return new automated_callback_workflow_1.AutomatedCallbackWorkflow(new token_cache_1.TokenCache(), authMechanismProperties.OIDC_CALLBACK);
70
+ }
71
+ else {
72
+ const environment = authMechanismProperties.ENVIRONMENT;
73
+ const workflow = mongodb_oidc_1.OIDC_WORKFLOWS.get(environment)?.();
74
+ if (!workflow) {
75
+ throw new error_1.MongoInvalidArgumentError(`Could not load workflow for environment ${authMechanismProperties.ENVIRONMENT}`);
76
+ }
77
+ return workflow;
78
+ }
79
+ }
80
+ //# sourceMappingURL=mongo_client_auth_providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo_client_auth_providers.js","sourceRoot":"","sources":["../src/mongo_client_auth_providers.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAE5C,yDAAqD;AACrD,2DAAsF;AACtF,sGAAiG;AACjG,8FAAyF;AACzF,sEAAkE;AAClE,6CAA0C;AAC1C,qDAAsD;AACtD,6CAA2D;AAC3D,2CAAwC;AACxC,mCAAoD;AAEpD,gBAAgB;AAChB,MAAM,cAAc,GAAG,IAAI,GAAG,CAG5B;IACA;QACE,yBAAa,CAAC,WAAW;QACzB,CAAC,EAAE,uBAAuB,EAAE,EAAE,EAAE,CAAC,IAAI,wBAAU,CAAC,uBAAuB,CAAC;KACzE;IACD,CAAC,yBAAa,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI,eAAM,EAAE,CAAC;IAClD,CAAC,yBAAa,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,CAAC,IAAI,0BAAW,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;IACpF,CAAC,yBAAa,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,aAAK,EAAE,CAAC;IAChD,CAAC,yBAAa,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI,iBAAS,EAAE,CAAC;IACzD,CAAC,yBAAa,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,IAAI,mBAAW,EAAE,CAAC;IAC7D,CAAC,yBAAa,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,WAAI,EAAE,CAAC;CAC/C,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAa,wBAAwB;IAArC;QACU,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