@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
package/lib/db.js ADDED
@@ -0,0 +1,419 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Db = void 0;
4
+ const admin_1 = require("./admin");
5
+ const bson_1 = require("./bson");
6
+ const change_stream_1 = require("./change_stream");
7
+ const collection_1 = require("./collection");
8
+ const CONSTANTS = require("./constants");
9
+ const aggregation_cursor_1 = require("./cursor/aggregation_cursor");
10
+ const list_collections_cursor_1 = require("./cursor/list_collections_cursor");
11
+ const run_command_cursor_1 = require("./cursor/run_command_cursor");
12
+ const error_1 = require("./error");
13
+ const create_collection_1 = require("./operations/create_collection");
14
+ const drop_1 = require("./operations/drop");
15
+ const execute_operation_1 = require("./operations/execute_operation");
16
+ const indexes_1 = require("./operations/indexes");
17
+ const profiling_level_1 = require("./operations/profiling_level");
18
+ const remove_user_1 = require("./operations/remove_user");
19
+ const rename_1 = require("./operations/rename");
20
+ const run_command_1 = require("./operations/run_command");
21
+ const set_profiling_level_1 = require("./operations/set_profiling_level");
22
+ const stats_1 = require("./operations/stats");
23
+ const read_concern_1 = require("./read_concern");
24
+ const read_preference_1 = require("./read_preference");
25
+ const utils_1 = require("./utils");
26
+ const write_concern_1 = require("./write_concern");
27
+ // Allowed parameters
28
+ const DB_OPTIONS_ALLOW_LIST = [
29
+ 'writeConcern',
30
+ 'readPreference',
31
+ 'readPreferenceTags',
32
+ 'native_parser',
33
+ 'forceServerObjectId',
34
+ 'pkFactory',
35
+ 'serializeFunctions',
36
+ 'raw',
37
+ 'authSource',
38
+ 'ignoreUndefined',
39
+ 'readConcern',
40
+ 'retryMiliSeconds',
41
+ 'numberOfRetries',
42
+ 'useBigInt64',
43
+ 'promoteBuffers',
44
+ 'promoteLongs',
45
+ 'bsonRegExp',
46
+ 'enableUtf8Validation',
47
+ 'promoteValues',
48
+ 'compression',
49
+ 'retryWrites',
50
+ 'timeoutMS'
51
+ ];
52
+ /**
53
+ * The **Db** class is a class that represents a MongoDB Database.
54
+ * @public
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { MongoClient } from 'mongodb';
59
+ *
60
+ * interface Pet {
61
+ * name: string;
62
+ * kind: 'dog' | 'cat' | 'fish';
63
+ * }
64
+ *
65
+ * const client = new MongoClient('mongodb://localhost:27017');
66
+ * const db = client.db();
67
+ *
68
+ * // Create a collection that validates our union
69
+ * await db.createCollection<Pet>('pets', {
70
+ * validator: { $expr: { $in: ['$kind', ['dog', 'cat', 'fish']] } }
71
+ * })
72
+ * ```
73
+ */
74
+ class Db {
75
+ static { this.SYSTEM_NAMESPACE_COLLECTION = CONSTANTS.SYSTEM_NAMESPACE_COLLECTION; }
76
+ static { this.SYSTEM_INDEX_COLLECTION = CONSTANTS.SYSTEM_INDEX_COLLECTION; }
77
+ static { this.SYSTEM_PROFILE_COLLECTION = CONSTANTS.SYSTEM_PROFILE_COLLECTION; }
78
+ static { this.SYSTEM_USER_COLLECTION = CONSTANTS.SYSTEM_USER_COLLECTION; }
79
+ static { this.SYSTEM_COMMAND_COLLECTION = CONSTANTS.SYSTEM_COMMAND_COLLECTION; }
80
+ static { this.SYSTEM_JS_COLLECTION = CONSTANTS.SYSTEM_JS_COLLECTION; }
81
+ /**
82
+ * Creates a new Db instance.
83
+ *
84
+ * Db name cannot contain a dot, the server may apply more restrictions when an operation is run.
85
+ *
86
+ * @param client - The MongoClient for the database.
87
+ * @param databaseName - The name of the database this instance represents.
88
+ * @param options - Optional settings for Db construction.
89
+ */
90
+ constructor(client, databaseName, options) {
91
+ options = options ?? {};
92
+ // Filter the options
93
+ options = (0, utils_1.filterOptions)(options, DB_OPTIONS_ALLOW_LIST);
94
+ // Ensure there are no dots in database name
95
+ if (typeof databaseName === 'string' && databaseName.includes('.')) {
96
+ throw new error_1.MongoInvalidArgumentError(`Database names cannot contain the character '.'`);
97
+ }
98
+ // Internal state of the db object
99
+ this.s = {
100
+ // Options
101
+ options,
102
+ // Unpack read preference
103
+ readPreference: read_preference_1.ReadPreference.fromOptions(options),
104
+ // Merge bson options
105
+ bsonOptions: (0, bson_1.resolveBSONOptions)(options, client),
106
+ // Set up the primary key factory or fallback to ObjectId
107
+ pkFactory: options?.pkFactory ?? utils_1.DEFAULT_PK_FACTORY,
108
+ // ReadConcern
109
+ readConcern: read_concern_1.ReadConcern.fromOptions(options),
110
+ writeConcern: write_concern_1.WriteConcern.fromOptions(options),
111
+ // Namespace
112
+ namespace: new utils_1.MongoDBNamespace(databaseName)
113
+ };
114
+ this.client = client;
115
+ }
116
+ get databaseName() {
117
+ return this.s.namespace.db;
118
+ }
119
+ // Options
120
+ get options() {
121
+ return this.s.options;
122
+ }
123
+ /**
124
+ * Check if a secondary can be used (because the read preference is *not* set to primary)
125
+ */
126
+ get secondaryOk() {
127
+ return this.s.readPreference?.preference !== 'primary' || false;
128
+ }
129
+ get readConcern() {
130
+ return this.s.readConcern;
131
+ }
132
+ /**
133
+ * The current readPreference of the Db. If not explicitly defined for
134
+ * this Db, will be inherited from the parent MongoClient
135
+ */
136
+ get readPreference() {
137
+ if (this.s.readPreference == null) {
138
+ return this.client.readPreference;
139
+ }
140
+ return this.s.readPreference;
141
+ }
142
+ get bsonOptions() {
143
+ return this.s.bsonOptions;
144
+ }
145
+ // get the write Concern
146
+ get writeConcern() {
147
+ return this.s.writeConcern;
148
+ }
149
+ get namespace() {
150
+ return this.s.namespace.toString();
151
+ }
152
+ get timeoutMS() {
153
+ return this.s.options?.timeoutMS;
154
+ }
155
+ /**
156
+ * Create a new collection on a server with the specified options. Use this to create capped collections.
157
+ * More information about command options available at https://www.mongodb.com/docs/manual/reference/command/create/
158
+ *
159
+ * Collection namespace validation is performed server-side.
160
+ *
161
+ * @param name - The name of the collection to create
162
+ * @param options - Optional settings for the command
163
+ */
164
+ async createCollection(name, options) {
165
+ options = (0, utils_1.resolveOptions)(this, options);
166
+ return await (0, create_collection_1.createCollections)(this, name, options);
167
+ }
168
+ /**
169
+ * Execute a command
170
+ *
171
+ * @remarks
172
+ * This command does not inherit options from the MongoClient.
173
+ *
174
+ * The driver will ensure the following fields are attached to the command sent to the server:
175
+ * - `lsid` - sourced from an implicit session or options.session
176
+ * - `$readPreference` - defaults to primary or can be configured by options.readPreference
177
+ * - `$db` - sourced from the name of this database
178
+ *
179
+ * If the client has a serverApi setting:
180
+ * - `apiVersion`
181
+ * - `apiStrict`
182
+ * - `apiDeprecationErrors`
183
+ *
184
+ * When in a transaction:
185
+ * - `readConcern` - sourced from readConcern set on the TransactionOptions
186
+ * - `writeConcern` - sourced from writeConcern set on the TransactionOptions
187
+ *
188
+ * Attaching any of the above fields to the command will have no effect as the driver will overwrite the value.
189
+ *
190
+ * @param command - The command to run
191
+ * @param options - Optional settings for the command
192
+ */
193
+ async command(command, options) {
194
+ // Intentionally, we do not inherit options from parent for this operation.
195
+ return await (0, execute_operation_1.executeOperation)(this.client, new run_command_1.RunCommandOperation(this.s.namespace, command, (0, utils_1.resolveOptions)(undefined, {
196
+ ...(0, bson_1.resolveBSONOptions)(options),
197
+ timeoutMS: options?.timeoutMS ?? this.timeoutMS,
198
+ session: options?.session,
199
+ readPreference: options?.readPreference,
200
+ signal: options?.signal
201
+ })));
202
+ }
203
+ /**
204
+ * Execute an aggregation framework pipeline against the database.
205
+ *
206
+ * @param pipeline - An array of aggregation stages to be executed
207
+ * @param options - Optional settings for the command
208
+ */
209
+ aggregate(pipeline = [], options) {
210
+ return new aggregation_cursor_1.AggregationCursor(this.client, this.s.namespace, pipeline, (0, utils_1.resolveOptions)(this, options));
211
+ }
212
+ /** Return the Admin db instance */
213
+ admin() {
214
+ return new admin_1.Admin(this);
215
+ }
216
+ /**
217
+ * Returns a reference to a MongoDB Collection. If it does not exist it will be created implicitly.
218
+ *
219
+ * Collection namespace validation is performed server-side.
220
+ *
221
+ * @param name - the collection name we wish to access.
222
+ * @returns return the new Collection instance
223
+ */
224
+ collection(name, options = {}) {
225
+ if (typeof options === 'function') {
226
+ throw new error_1.MongoInvalidArgumentError('The callback form of this helper has been removed.');
227
+ }
228
+ return new collection_1.Collection(this, name, (0, utils_1.resolveOptions)(this, options));
229
+ }
230
+ /**
231
+ * Get all the db statistics.
232
+ *
233
+ * @param options - Optional settings for the command
234
+ */
235
+ async stats(options) {
236
+ return await (0, execute_operation_1.executeOperation)(this.client, new stats_1.DbStatsOperation(this, (0, utils_1.resolveOptions)(this, options)));
237
+ }
238
+ listCollections(filter = {}, options = {}) {
239
+ return new list_collections_cursor_1.ListCollectionsCursor(this, filter, (0, utils_1.resolveOptions)(this, options));
240
+ }
241
+ /**
242
+ * Rename a collection.
243
+ *
244
+ * @remarks
245
+ * This operation does not inherit options from the MongoClient.
246
+ *
247
+ * @param fromCollection - Name of current collection to rename
248
+ * @param toCollection - New name of of the collection
249
+ * @param options - Optional settings for the command
250
+ */
251
+ async renameCollection(fromCollection, toCollection, options) {
252
+ // Intentionally, we do not inherit options from parent for this operation.
253
+ return await (0, execute_operation_1.executeOperation)(this.client, new rename_1.RenameOperation(this.collection(fromCollection), toCollection, (0, utils_1.resolveOptions)(undefined, {
254
+ ...options,
255
+ readPreference: read_preference_1.ReadPreference.primary
256
+ })));
257
+ }
258
+ /**
259
+ * Drop a collection from the database, removing it permanently. New accesses will create a new collection.
260
+ *
261
+ * @param name - Name of collection to drop
262
+ * @param options - Optional settings for the command
263
+ */
264
+ async dropCollection(name, options) {
265
+ options = (0, utils_1.resolveOptions)(this, options);
266
+ return await (0, drop_1.dropCollections)(this, name, options);
267
+ }
268
+ /**
269
+ * Drop a database, removing it permanently from the server.
270
+ *
271
+ * @param options - Optional settings for the command
272
+ */
273
+ async dropDatabase(options) {
274
+ return await (0, execute_operation_1.executeOperation)(this.client, new drop_1.DropDatabaseOperation(this, (0, utils_1.resolveOptions)(this, options)));
275
+ }
276
+ /**
277
+ * Fetch all collections for the current db.
278
+ *
279
+ * @param options - Optional settings for the command
280
+ */
281
+ async collections(options) {
282
+ options = (0, utils_1.resolveOptions)(this, options);
283
+ const collections = await this.listCollections({}, { ...options, nameOnly: true }).toArray();
284
+ return collections
285
+ .filter(
286
+ // Filter collections removing any illegal ones
287
+ ({ name }) => !name.includes('$'))
288
+ .map(({ name }) => new collection_1.Collection(this, name, this.s.options));
289
+ }
290
+ /**
291
+ * Creates an index on the db and collection.
292
+ *
293
+ * @param name - Name of the collection to create the index on.
294
+ * @param indexSpec - Specify the field to index, or an index specification
295
+ * @param options - Optional settings for the command
296
+ */
297
+ async createIndex(name, indexSpec, options) {
298
+ const indexes = await (0, execute_operation_1.executeOperation)(this.client, indexes_1.CreateIndexesOperation.fromIndexSpecification(this, name, indexSpec, options));
299
+ return indexes[0];
300
+ }
301
+ /**
302
+ * Remove a user from a database
303
+ *
304
+ * @param username - The username to remove
305
+ * @param options - Optional settings for the command
306
+ */
307
+ async removeUser(username, options) {
308
+ return await (0, execute_operation_1.executeOperation)(this.client, new remove_user_1.RemoveUserOperation(this, username, (0, utils_1.resolveOptions)(this, options)));
309
+ }
310
+ /**
311
+ * Set the current profiling level of MongoDB
312
+ *
313
+ * @param level - The new profiling level (off, slow_only, all).
314
+ * @param options - Optional settings for the command
315
+ */
316
+ async setProfilingLevel(level, options) {
317
+ return await (0, execute_operation_1.executeOperation)(this.client, new set_profiling_level_1.SetProfilingLevelOperation(this, level, (0, utils_1.resolveOptions)(this, options)));
318
+ }
319
+ /**
320
+ * Retrieve the current profiling Level for MongoDB
321
+ *
322
+ * @param options - Optional settings for the command
323
+ */
324
+ async profilingLevel(options) {
325
+ return await (0, execute_operation_1.executeOperation)(this.client, new profiling_level_1.ProfilingLevelOperation(this, (0, utils_1.resolveOptions)(this, options)));
326
+ }
327
+ async indexInformation(name, options) {
328
+ return await this.collection(name).indexInformation((0, utils_1.resolveOptions)(this, options));
329
+ }
330
+ /**
331
+ * Create a new Change Stream, watching for new changes (insertions, updates,
332
+ * replacements, deletions, and invalidations) in this database. Will ignore all
333
+ * changes to system collections.
334
+ *
335
+ * @remarks
336
+ * watch() accepts two generic arguments for distinct use cases:
337
+ * - The first is to provide the schema that may be defined for all the collections within this database
338
+ * - 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
339
+ *
340
+ * @remarks
341
+ * When `timeoutMS` is configured for a change stream, it will have different behaviour depending
342
+ * on whether the change stream is in iterator mode or emitter mode. In both cases, a change
343
+ * stream will time out if it does not receive a change event within `timeoutMS` of the last change
344
+ * event.
345
+ *
346
+ * Note that if a change stream is consistently timing out when watching a collection, database or
347
+ * client that is being changed, then this may be due to the server timing out before it can finish
348
+ * processing the existing oplog. To address this, restart the change stream with a higher
349
+ * `timeoutMS`.
350
+ *
351
+ * If the change stream times out the initial aggregate operation to establish the change stream on
352
+ * the server, then the client will close the change stream. If the getMore calls to the server
353
+ * time out, then the change stream will be left open, but will throw a MongoOperationTimeoutError
354
+ * when in iterator mode and emit an error event that returns a MongoOperationTimeoutError in
355
+ * emitter mode.
356
+ *
357
+ * To determine whether or not the change stream is still open following a timeout, check the
358
+ * {@link ChangeStream.closed} getter.
359
+ *
360
+ * @example
361
+ * In iterator mode, if a next() call throws a timeout error, it will attempt to resume the change stream.
362
+ * The next call can just be retried after this succeeds.
363
+ * ```ts
364
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
365
+ * try {
366
+ * await changeStream.next();
367
+ * } catch (e) {
368
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
369
+ * await changeStream.next();
370
+ * }
371
+ * throw e;
372
+ * }
373
+ * ```
374
+ *
375
+ * @example
376
+ * In emitter mode, if the change stream goes `timeoutMS` without emitting a change event, it will
377
+ * emit an error event that returns a MongoOperationTimeoutError, but will not close the change
378
+ * stream unless the resume attempt fails. There is no need to re-establish change listeners as
379
+ * this will automatically continue emitting change events once the resume attempt completes.
380
+ *
381
+ * ```ts
382
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
383
+ * changeStream.on('change', console.log);
384
+ * changeStream.on('error', e => {
385
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
386
+ * // do nothing
387
+ * } else {
388
+ * changeStream.close();
389
+ * }
390
+ * });
391
+ * ```
392
+ * @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.
393
+ * @param options - Optional settings for the command
394
+ * @typeParam TSchema - Type of the data being detected by the change stream
395
+ * @typeParam TChange - Type of the whole change stream document emitted
396
+ */
397
+ watch(pipeline = [], options = {}) {
398
+ // Allow optionally not specifying a pipeline
399
+ if (!Array.isArray(pipeline)) {
400
+ options = pipeline;
401
+ pipeline = [];
402
+ }
403
+ return new change_stream_1.ChangeStream(this, pipeline, (0, utils_1.resolveOptions)(this, options));
404
+ }
405
+ /**
406
+ * A low level cursor API providing basic driver functionality:
407
+ * - ClientSession management
408
+ * - ReadPreference for server selection
409
+ * - Running getMores automatically when a local batch is exhausted
410
+ *
411
+ * @param command - The command that will start a cursor on the server.
412
+ * @param options - Configurations for running the command, bson options will apply to getMores
413
+ */
414
+ runCursorCommand(command, options) {
415
+ return new run_command_cursor_1.RunCommandCursor(this, command, options);
416
+ }
417
+ }
418
+ exports.Db = Db;
419
+ //# sourceMappingURL=db.js.map
package/lib/db.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,iCAAsF;AACtF,mDAAoG;AACpG,6CAAkE;AAClE,yCAAyC;AACzC,oEAAgE;AAChE,8EAAyE;AACzE,oEAA6F;AAC7F,mCAAoD;AAIpD,sEAAiG;AACjG,4CAK2B;AAC3B,sEAAkE;AAClE,kDAO8B;AAE9B,kEAAmG;AACnG,0DAAuF;AACvF,gDAA0E;AAC1E,0DAAuF;AACvF,0EAI0C;AAC1C,8CAA2E;AAC3E,iD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iC;QACnE,OAAO,IAAI,qCAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;;AA/eH,gBAgfC"}
package/lib/deps.js ADDED
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getKerberos = getKerberos;
4
+ exports.getZstdLibrary = getZstdLibrary;
5
+ exports.getAwsCredentialProvider = getAwsCredentialProvider;
6
+ exports.getGcpMetadata = getGcpMetadata;
7
+ exports.getSnappy = getSnappy;
8
+ exports.getSocks = getSocks;
9
+ exports.getMongoDBClientEncryption = getMongoDBClientEncryption;
10
+ const error_1 = require("./error");
11
+ function makeErrorModule(error) {
12
+ const props = error ? { kModuleError: error } : {};
13
+ return new Proxy(props, {
14
+ get: (_, key) => {
15
+ if (key === 'kModuleError') {
16
+ return error;
17
+ }
18
+ throw error;
19
+ },
20
+ set: () => {
21
+ throw error;
22
+ }
23
+ });
24
+ }
25
+ function getKerberos() {
26
+ let kerberos;
27
+ try {
28
+ // Ensure you always wrap an optional require in the try block NODE-3199
29
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
30
+ kerberos = require('kerberos');
31
+ }
32
+ catch (error) {
33
+ kerberos = makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `kerberos` not found. Please install it to enable kerberos authentication', { cause: error, dependencyName: 'kerberos' }));
34
+ }
35
+ return kerberos;
36
+ }
37
+ function getZstdLibrary() {
38
+ let ZStandard;
39
+ try {
40
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
41
+ ZStandard = require('@mongodb-js/zstd');
42
+ }
43
+ catch (error) {
44
+ ZStandard = makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `@mongodb-js/zstd` not found. Please install it to enable zstd compression', { cause: error, dependencyName: 'zstd' }));
45
+ }
46
+ return ZStandard;
47
+ }
48
+ function getAwsCredentialProvider() {
49
+ try {
50
+ // Ensure you always wrap an optional require in the try block NODE-3199
51
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
52
+ const credentialProvider = require('@aws-sdk/credential-providers');
53
+ return credentialProvider;
54
+ }
55
+ catch (error) {
56
+ return makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `@aws-sdk/credential-providers` not found.' +
57
+ ' Please install it to enable getting aws credentials via the official sdk.', { cause: error, dependencyName: '@aws-sdk/credential-providers' }));
58
+ }
59
+ }
60
+ function getGcpMetadata() {
61
+ try {
62
+ // Ensure you always wrap an optional require in the try block NODE-3199
63
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
64
+ const credentialProvider = require('gcp-metadata');
65
+ return credentialProvider;
66
+ }
67
+ catch (error) {
68
+ return makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `gcp-metadata` not found.' +
69
+ ' Please install it to enable getting gcp credentials via the official sdk.', { cause: error, dependencyName: 'gcp-metadata' }));
70
+ }
71
+ }
72
+ function getSnappy() {
73
+ try {
74
+ // Ensure you always wrap an optional require in the try block NODE-3199
75
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
76
+ const value = require('snappy');
77
+ return value;
78
+ }
79
+ catch (error) {
80
+ const kModuleError = new error_1.MongoMissingDependencyError('Optional module `snappy` not found. Please install it to enable snappy compression', { cause: error, dependencyName: 'snappy' });
81
+ return { kModuleError };
82
+ }
83
+ }
84
+ function getSocks() {
85
+ try {
86
+ // Ensure you always wrap an optional require in the try block NODE-3199
87
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
88
+ const value = require('socks');
89
+ return value;
90
+ }
91
+ catch (error) {
92
+ const kModuleError = new error_1.MongoMissingDependencyError('Optional module `socks` not found. Please install it to connections over a SOCKS5 proxy', { cause: error, dependencyName: 'socks' });
93
+ return { kModuleError };
94
+ }
95
+ }
96
+ /** A utility function to get the instance of mongodb-client-encryption, if it exists. */
97
+ function getMongoDBClientEncryption() {
98
+ let mongodbClientEncryption = null;
99
+ try {
100
+ // NOTE(NODE-3199): Ensure you always wrap an optional require literally in the try block
101
+ // Cannot be moved to helper utility function, bundlers search and replace the actual require call
102
+ // in a way that makes this line throw at bundle time, not runtime, catching here will make bundling succeed
103
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
104
+ mongodbClientEncryption = require('mongodb-client-encryption');
105
+ }
106
+ catch (error) {
107
+ const kModuleError = new error_1.MongoMissingDependencyError('Optional module `mongodb-client-encryption` not found. Please install it to use auto encryption or ClientEncryption.', { cause: error, dependencyName: 'mongodb-client-encryption' });
108
+ return { kModuleError };
109
+ }
110
+ return mongodbClientEncryption;
111
+ }
112
+ //# sourceMappingURL=deps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deps.js","sourceRoot":"","sources":["../src/deps.ts"],"names":[],"mappings":";;AAqBA,kCAeC;AA0BD,wCAeC;AAsBD,4DAiBC;AAOD,wCAeC;AAiBD,8BAaC;AAsBD,4BAaC;AAGD,gEAoBC;AAjOD,mCAAsD;AAGtD,SAAS,eAAe,CAAC,KAAU;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnD,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE;QACtB,GAAG,EAAE,CAAC,CAAM,EAAE,GAAQ,EAAE,EAAE;YACxB,IAAI,GAAG,KAAK,cAAc,EAAE,CAAC;gBAC3B,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QACD,GAAG,EAAE,GAAG,EAAE;YACR,MAAM,KAAK,CAAC;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAID,SAAgB,WAAW;IACzB,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,wEAAwE;QACxE,iEAAiE;QACjE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,QAAQ,GAAG,eAAe,CACxB,IAAI,mCAA2B,CAC7B,2FAA2F,EA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ty(exports, "__esModule", { value: true });
3
+ exports.Encrypter = void 0;
4
+ const auto_encrypter_1 = require("./client-side-encryption/auto_encrypter");
5
+ const constants_1 = require("./constants");
6
+ const deps_1 = require("./deps");
7
+ const error_1 = require("./error");
8
+ const mongo_client_1 = require("./mongo_client");
9
+ /** @internal */
10
+ class Encrypter {
11
+ constructor(client, uri, options) {
12
+ if (typeof options.autoEncryption !== 'object') {
13
+ throw new error_1.MongoInvalidArgumentError('Option "autoEncryption" must be specified');
14
+ }
15
+ // initialize to null, if we call getInternalClient, we may set this it is important to not overwrite those function calls.
16
+ this.internalClient = null;
17
+ this.bypassAutoEncryption = !!options.autoEncryption.bypassAutoEncryption;
18
+ this.needsConnecting = false;
19
+ if (options.maxPoolSize === 0 && options.autoEncryption.keyVaultClient == null) {
20
+ options.autoEncryption.keyVaultClient = client;
21
+ }
22
+ else if (options.autoEncryption.keyVaultClient == null) {
23
+ options.autoEncryption.keyVaultClient = this.getInternalClient(client, uri, options);
24
+ }
25
+ if (this.bypassAutoEncryption) {
26
+ options.autoEncryption.metadataClient = undefined;
27
+ }
28
+ else if (options.maxPoolSize === 0) {
29
+ options.autoEncryption.metadataClient = client;
30
+ }
31
+ else {
32
+ options.autoEncryption.metadataClient = this.getInternalClient(client, uri, options);
33
+ }
34
+ if (options.proxyHost) {
35
+ options.autoEncryption.proxyOptions = {
36
+ proxyHost: options.proxyHost,
37
+ proxyPort: options.proxyPort,
38
+ proxyUsername: options.proxyUsername,
39
+ proxyPassword: options.proxyPassword
40
+ };
41
+ }
42
+ this.autoEncrypter = new auto_encrypter_1.AutoEncrypter(client, options.autoEncryption);
43
+ }
44
+ getInternalClient(client, uri, options) {
45
+ let internalClient = this.internalClient;
46
+ if (internalClient == null) {
47
+ const clonedOptions = {};
48
+ for (const key of [
49
+ ...Object.getOwnPropertyNames(options),
50
+ ...Object.getOwnPropertySymbols(options)
51
+ ]) {
52
+ if (['autoEncryption', 'minPoolSize', 'servers', 'caseTranslate', 'dbName'].includes(key))
53
+ continue;
54
+ Reflect.set(clonedOptions, key, Reflect.get(options, key));
55
+ }
56
+ clonedOptions.minPoolSize = 0;
57
+ internalClient = new mongo_client_1.MongoClient(uri, clonedOptions);
58
+ this.internalClient = internalClient;
59
+ for (const eventName of constants_1.MONGO_CLIENT_EVENTS) {
60
+ for (const listener of client.listeners(eventName)) {
61
+ internalClient.on(eventName, listener);
62
+ }
63
+ }
64
+ client.on('newListener', (eventName, listener) => {
65
+ internalClient?.on(eventName, listener);
66
+ });
67
+ this.needsConnecting = true;
68
+ }
69
+ return internalClient;
70
+ }
71
+ async connectInternalClient() {
72
+ const internalClient = this.internalClient;
73
+ if (this.needsConnecting && internalClient != null) {
74
+ this.needsConnecting = false;
75
+ await internalClient.connect();
76
+ }
77
+ }
78
+ async close(client) {
79
+ let error;
80
+ try {
81
+ await this.autoEncrypter.close();
82
+ }
83
+ catch (autoEncrypterError) {
84
+ error = autoEncrypterError;
85
+ }
86
+ const internalClient = this.internalClient;
87
+ if (internalClient != null && client !== internalClient) {
88
+ return await internalClient.close();
89
+ }
90
+ if (error != null) {
91
+ throw error;
92
+ }
93
+ }
94
+ static checkForMongoCrypt() {
95
+ const mongodbClientEncryption = (0, deps_1.getMongoDBClientEncryption)();
96
+ if ('kModuleError' in mongodbClientEncryption) {
97
+ throw new error_1.MongoMissingDependencyError('Auto-encryption requested, but the module is not installed. ' +
98
+ 'Please add `mongodb-client-encryption` as a dependency of your project', {
99
+ cause: mongodbClientEncryption['kModuleError'],
100
+ dependencyName: 'mongodb-client-encryption'
101
+ });
102
+ }
103
+ }
104
+ }
105
+ exports.Encrypter = Encrypter;
106
+ //# sourceMappingURL=encrypter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypter.js","sourceRoot":"","sources":["../src/encrypter.ts"],"names":[],"mappings":";;;AAAA,4EAAoG;AACpG,2CAAkD;AAClD,iCAAoD;AACpD,mCAAiF;AACjF,iDAAsE;AAQtE,gBAAgB;AAChB,MAAa,SAAS;I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