@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,655 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongoLogger = exports.MongoLoggableComponent = exports.SEVERITY_LEVEL_MAP = exports.DEFAULT_MAX_DOCUMENT_LENGTH = exports.SeverityLevel = void 0;
4
+ exports.parseSeverityFromString = parseSeverityFromString;
5
+ exports.createStdioLogger = createStdioLogger;
6
+ exports.stringifyWithMaxLen = stringifyWithMaxLen;
7
+ exports.defaultLogTransform = defaultLogTransform;
8
+ const process = require("process");
9
+ const util_1 = require("util");
10
+ const bson_1 = require("./bson");
11
+ const constants_1 = require("./constants");
12
+ const utils_1 = require("./utils");
13
+ /**
14
+ * @public
15
+ * Severity levels align with unix syslog.
16
+ * Most typical driver functions will log to debug.
17
+ */
18
+ exports.SeverityLevel = Object.freeze({
19
+ EMERGENCY: 'emergency',
20
+ ALERT: 'alert',
21
+ CRITICAL: 'critical',
22
+ ERROR: 'error',
23
+ WARNING: 'warn',
24
+ NOTICE: 'notice',
25
+ INFORMATIONAL: 'info',
26
+ DEBUG: 'debug',
27
+ TRACE: 'trace',
28
+ OFF: 'off'
29
+ });
30
+ /** @internal */
31
+ exports.DEFAULT_MAX_DOCUMENT_LENGTH = 1000;
32
+ /** @internal */
33
+ class SeverityLevelMap extends Map {
34
+ constructor(entries) {
35
+ const newEntries = [];
36
+ for (const [level, value] of entries) {
37
+ newEntries.push([value, level]);
38
+ }
39
+ newEntries.push(...entries);
40
+ super(newEntries);
41
+ }
42
+ getNumericSeverityLevel(severity) {
43
+ return this.get(severity);
44
+ }
45
+ getSeverityLevelName(level) {
46
+ return this.get(level);
47
+ }
48
+ }
49
+ /** @internal */
50
+ exports.SEVERITY_LEVEL_MAP = new SeverityLevelMap([
51
+ [exports.SeverityLevel.OFF, -Infinity],
52
+ [exports.SeverityLevel.EMERGENCY, 0],
53
+ [exports.SeverityLevel.ALERT, 1],
54
+ [exports.SeverityLevel.CRITICAL, 2],
55
+ [exports.SeverityLevel.ERROR, 3],
56
+ [exports.SeverityLevel.WARNING, 4],
57
+ [exports.SeverityLevel.NOTICE, 5],
58
+ [exports.SeverityLevel.INFORMATIONAL, 6],
59
+ [exports.SeverityLevel.DEBUG, 7],
60
+ [exports.SeverityLevel.TRACE, 8]
61
+ ]);
62
+ /** @public */
63
+ exports.MongoLoggableComponent = Object.freeze({
64
+ COMMAND: 'command',
65
+ TOPOLOGY: 'topology',
66
+ SERVER_SELECTION: 'serverSelection',
67
+ CONNECTION: 'connection',
68
+ CLIENT: 'client'
69
+ });
70
+ /**
71
+ * Parses a string as one of SeverityLevel
72
+ * @internal
73
+ *
74
+ * @param s - the value to be parsed
75
+ * @returns one of SeverityLevel if value can be parsed as such, otherwise null
76
+ */
77
+ function parseSeverityFromString(s) {
78
+ const validSeverities = Object.values(exports.SeverityLevel);
79
+ const lowerSeverity = s?.toLowerCase();
80
+ if (lowerSeverity != null && validSeverities.includes(lowerSeverity)) {
81
+ return lowerSeverity;
82
+ }
83
+ return null;
84
+ }
85
+ /** @internal */
86
+ function createStdioLogger(stream) {
87
+ return {
88
+ write: (log) => {
89
+ return new Promise((resolve, reject) => {
90
+ const logLine = (0, util_1.inspect)(log, { compact: true, breakLength: Infinity });
91
+ stream.write(`${logLine}\n`, 'utf-8', error => {
92
+ if (error)
93
+ return reject(error);
94
+ resolve(true);
95
+ });
96
+ });
97
+ }
98
+ };
99
+ }
100
+ /**
101
+ * resolves the MONGODB_LOG_PATH and mongodbLogPath options from the environment and the
102
+ * mongo client options respectively. The mongodbLogPath can be either 'stdout', 'stderr', a NodeJS
103
+ * Writable or an object which has a `write` method with the signature:
104
+ * ```ts
105
+ * write(log: Log): void
106
+ * ```
107
+ *
108
+ * @returns the MongoDBLogWritable object to write logs to
109
+ */
110
+ function resolveLogPath({ MONGODB_LOG_PATH }, { mongodbLogPath }) {
111
+ if (typeof mongodbLogPath === 'string' && /^stderr$/i.test(mongodbLogPath)) {
112
+ return { mongodbLogPath: createStdioLogger(process.stderr), mongodbLogPathIsStdErr: true };
113
+ }
114
+ if (typeof mongodbLogPath === 'string' && /^stdout$/i.test(mongodbLogPath)) {
115
+ return { mongodbLogPath: createStdioLogger(process.stdout), mongodbLogPathIsStdErr: false };
116
+ }
117
+ if (typeof mongodbLogPath === 'object' && typeof mongodbLogPath?.write === 'function') {
118
+ return { mongodbLogPath: mongodbLogPath, mongodbLogPathIsStdErr: false };
119
+ }
120
+ if (MONGODB_LOG_PATH && /^stderr$/i.test(MONGODB_LOG_PATH)) {
121
+ return { mongodbLogPath: createStdioLogger(process.stderr), mongodbLogPathIsStdErr: true };
122
+ }
123
+ if (MONGODB_LOG_PATH && /^stdout$/i.test(MONGODB_LOG_PATH)) {
124
+ return { mongodbLogPath: createStdioLogger(process.stdout), mongodbLogPathIsStdErr: false };
125
+ }
126
+ return { mongodbLogPath: createStdioLogger(process.stderr), mongodbLogPathIsStdErr: true };
127
+ }
128
+ function resolveSeverityConfiguration(clientOption, environmentOption, defaultSeverity) {
129
+ return (parseSeverityFromString(clientOption) ??
130
+ parseSeverityFromString(environmentOption) ??
131
+ defaultSeverity);
132
+ }
133
+ function compareSeverity(s0, s1) {
134
+ const s0Num = exports.SEVERITY_LEVEL_MAP.getNumericSeverityLevel(s0);
135
+ const s1Num = exports.SEVERITY_LEVEL_MAP.getNumericSeverityLevel(s1);
136
+ return s0Num < s1Num ? -1 : s0Num > s1Num ? 1 : 0;
137
+ }
138
+ /** @internal */
139
+ function stringifyWithMaxLen(value, maxDocumentLength, options = {}) {
140
+ let strToTruncate = '';
141
+ let currentLength = 0;
142
+ const maxDocumentLengthEnsurer = function maxDocumentLengthEnsurer(key, value) {
143
+ if (currentLength >= maxDocumentLength) {
144
+ return undefined;
145
+ }
146
+ // Account for root document
147
+ if (key === '') {
148
+ // Account for starting brace
149
+ currentLength += 1;
150
+ return value;
151
+ }
152
+ // +4 accounts for 2 quotation marks, colon and comma after value
153
+ // Note that this potentially undercounts since it does not account for escape sequences which
154
+ // will have an additional backslash added to them once passed through JSON.stringify.
155
+ currentLength += key.length + 4;
156
+ if (value == null)
157
+ return value;
158
+ switch (typeof value) {
159
+ case 'string':
160
+ // +2 accounts for quotes
161
+ // Note that this potentially undercounts similarly to the key length calculation
162
+ currentLength += value.length + 2;
163
+ break;
164
+ case 'number':
165
+ case 'bigint':
166
+ currentLength += String(value).length;
167
+ break;
168
+ case 'boolean':
169
+ currentLength += value ? 4 : 5;
170
+ break;
171
+ case 'object':
172
+ if ((0, utils_1.isUint8Array)(value)) {
173
+ // '{"$binary":{"base64":"<base64 string>","subType":"XX"}}'
174
+ // This is an estimate based on the fact that the base64 is approximately 1.33x the length of
175
+ // the actual binary sequence https://en.wikipedia.org/wiki/Base64
176
+ currentLength += (22 + value.byteLength + value.byteLength * 0.33 + 18) | 0;
177
+ }
178
+ else if ('_bsontype' in value) {
179
+ const v = value;
180
+ switch (v._bsontype) {
181
+ case 'Int32':
182
+ currentLength += String(v.value).length;
183
+ break;
184
+ case 'Double':
185
+ // Account for representing integers as <value>.0
186
+ currentLength +=
187
+ (v.value | 0) === v.value ? String(v.value).length + 2 : String(v.value).length;
188
+ break;
189
+ case 'Long':
190
+ currentLength += v.toString().length;
191
+ break;
192
+ case 'ObjectId':
193
+ // '{"$oid":"XXXXXXXXXXXXXXXXXXXXXXXX"}'
194
+ currentLength += 35;
195
+ break;
196
+ case 'MaxKey':
197
+ case 'MinKey':
198
+ // '{"$maxKey":1}' or '{"$minKey":1}'
199
+ currentLength += 13;
200
+ break;
201
+ case 'Binary':
202
+ // '{"$binary":{"base64":"<base64 string>","subType":"XX"}}'
203
+ // This is an estimate based on the fact that the base64 is approximately 1.33x the length of
204
+ // the actual binary sequence https://en.wikipedia.org/wiki/Base64
205
+ currentLength += (22 + value.position + value.position * 0.33 + 18) | 0;
206
+ break;
207
+ case 'Timestamp':
208
+ // '{"$timestamp":{"t":<t>,"i":<i>}}'
209
+ currentLength += 19 + String(v.t).length + 5 + String(v.i).length + 2;
210
+ break;
211
+ case 'Code':
212
+ // '{"$code":"<code>"}' or '{"$code":"<code>","$scope":<scope>}'
213
+ if (v.scope == null) {
214
+ currentLength += v.code.length + 10 + 2;
215
+ }
216
+ else {
217
+ // Ignoring actual scope object, so this undercounts by a significant amount
218
+ currentLength += v.code.length + 10 + 11;
219
+ }
220
+ break;
221
+ case 'BSONRegExp':
222
+ // '{"$regularExpression":{"pattern":"<pattern>","options":"<options>"}}'
223
+ currentLength += 34 + v.pattern.length + 13 + v.options.length + 3;
224
+ break;
225
+ }
226
+ }
227
+ }
228
+ return value;
229
+ };
230
+ if (typeof value === 'string') {
231
+ strToTruncate = value;
232
+ }
233
+ else if (typeof value === 'function') {
234
+ strToTruncate = value.name;
235
+ }
236
+ else {
237
+ try {
238
+ if (maxDocumentLength !== 0) {
239
+ strToTruncate = bson_1.EJSON.stringify(value, maxDocumentLengthEnsurer, 0, options);
240
+ }
241
+ else {
242
+ strToTruncate = bson_1.EJSON.stringify(value, options);
243
+ }
244
+ }
245
+ catch (e) {
246
+ strToTruncate = `Extended JSON serialization failed with: ${e.message}`;
247
+ }
248
+ }
249
+ // handle truncation that occurs in the middle of multi-byte codepoints
250
+ if (maxDocumentLength !== 0 &&
251
+ strToTruncate.length > maxDocumentLength &&
252
+ strToTruncate.charCodeAt(maxDocumentLength - 1) !==
253
+ strToTruncate.codePointAt(maxDocumentLength - 1)) {
254
+ maxDocumentLength--;
255
+ if (maxDocumentLength === 0) {
256
+ return '';
257
+ }
258
+ }
259
+ return maxDocumentLength !== 0 && strToTruncate.length > maxDocumentLength
260
+ ? `${strToTruncate.slice(0, maxDocumentLength)}...`
261
+ : strToTruncate;
262
+ }
263
+ function isLogConvertible(obj) {
264
+ const objAsLogConvertible = obj;
265
+ // eslint-disable-next-line no-restricted-syntax
266
+ return objAsLogConvertible.toLog !== undefined && typeof objAsLogConvertible.toLog === 'function';
267
+ }
268
+ function attachServerSelectionFields(log, serverSelectionEvent, maxDocumentLength = exports.DEFAULT_MAX_DOCUMENT_LENGTH) {
269
+ const { selector, operation, topologyDescription, message } = serverSelectionEvent;
270
+ log.selector = stringifyWithMaxLen(selector, maxDocumentLength);
271
+ log.operation = operation;
272
+ log.topologyDescription = stringifyWithMaxLen(topologyDescription, maxDocumentLength);
273
+ log.message = message;
274
+ return log;
275
+ }
276
+ function attachCommandFields(log, commandEvent) {
277
+ log.commandName = commandEvent.commandName;
278
+ log.requestId = commandEvent.requestId;
279
+ log.driverConnectionId = commandEvent.connectionId;
280
+ const { host, port } = utils_1.HostAddress.fromString(commandEvent.address).toHostPort();
281
+ log.serverHost = host;
282
+ log.serverPort = port;
283
+ if (commandEvent?.serviceId) {
284
+ log.serviceId = commandEvent.serviceId.toHexString();
285
+ }
286
+ log.databaseName = commandEvent.databaseName;
287
+ log.serverConnectionId = commandEvent.serverConnectionId;
288
+ return log;
289
+ }
290
+ function attachConnectionFields(log, event) {
291
+ const { host, port } = utils_1.HostAddress.fromString(event.address).toHostPort();
292
+ log.serverHost = host;
293
+ log.serverPort = port;
294
+ return log;
295
+ }
296
+ function attachSDAMFields(log, sdamEvent) {
297
+ log.topologyId = sdamEvent.topologyId;
298
+ return log;
299
+ }
300
+ function attachServerHeartbeatFields(log, serverHeartbeatEvent) {
301
+ const { awaited, connectionId } = serverHeartbeatEvent;
302
+ log.awaited = awaited;
303
+ log.driverConnectionId = serverHeartbeatEvent.connectionId;
304
+ const { host, port } = utils_1.HostAddress.fromString(connectionId).toHostPort();
305
+ log.serverHost = host;
306
+ log.serverPort = port;
307
+ return log;
308
+ }
309
+ /** @internal */
310
+ function defaultLogTransform(logObject, maxDocumentLength = exports.DEFAULT_MAX_DOCUMENT_LENGTH) {
311
+ let log = Object.create(null);
312
+ switch (logObject.name) {
313
+ case constants_1.SERVER_SELECTION_STARTED:
314
+ log = attachServerSelectionFields(log, logObject, maxDocumentLength);
315
+ return log;
316
+ case constants_1.SERVER_SELECTION_FAILED:
317
+ log = attachServerSelectionFields(log, logObject, maxDocumentLength);
318
+ log.failure = logObject.failure?.message;
319
+ return log;
320
+ case constants_1.SERVER_SELECTION_SUCCEEDED:
321
+ log = attachServerSelectionFields(log, logObject, maxDocumentLength);
322
+ log.serverHost = logObject.serverHost;
323
+ log.serverPort = logObject.serverPort;
324
+ return log;
325
+ case constants_1.WAITING_FOR_SUITABLE_SERVER:
326
+ log = attachServerSelectionFields(log, logObject, maxDocumentLength);
327
+ log.remainingTimeMS = logObject.remainingTimeMS;
328
+ return log;
329
+ case constants_1.COMMAND_STARTED:
330
+ log = attachCommandFields(log, logObject);
331
+ log.message = 'Command started';
332
+ log.command = stringifyWithMaxLen(logObject.command, maxDocumentLength, { relaxed: true });
333
+ log.databaseName = logObject.databaseName;
334
+ return log;
335
+ case constants_1.COMMAND_SUCCEEDED:
336
+ log = attachCommandFields(log, logObject);
337
+ log.message = 'Command succeeded';
338
+ log.durationMS = logObject.duration;
339
+ log.reply = stringifyWithMaxLen(logObject.reply, maxDocumentLength, { relaxed: true });
340
+ return log;
341
+ case constants_1.COMMAND_FAILED:
342
+ log = attachCommandFields(log, logObject);
343
+ log.message = 'Command failed';
344
+ log.durationMS = logObject.duration;
345
+ log.failure = logObject.failure?.message ?? '(redacted)';
346
+ return log;
347
+ case constants_1.CONNECTION_POOL_CREATED:
348
+ log = attachConnectionFields(log, logObject);
349
+ log.message = 'Connection pool created';
350
+ if (logObject.options) {
351
+ const { maxIdleTimeMS, minPoolSize, maxPoolSize, maxConnecting, waitQueueTimeoutMS } = logObject.options;
352
+ log = {
353
+ ...log,
354
+ maxIdleTimeMS,
355
+ minPoolSize,
356
+ maxPoolSize,
357
+ maxConnecting,
358
+ waitQueueTimeoutMS
359
+ };
360
+ }
361
+ return log;
362
+ case constants_1.CONNECTION_POOL_READY:
363
+ log = attachConnectionFields(log, logObject);
364
+ log.message = 'Connection pool ready';
365
+ return log;
366
+ case constants_1.CONNECTION_POOL_CLEARED:
367
+ log = attachConnectionFields(log, logObject);
368
+ log.message = 'Connection pool cleared';
369
+ if (logObject.serviceId?._bsontype === 'ObjectId') {
370
+ log.serviceId = logObject.serviceId?.toHexString();
371
+ }
372
+ return log;
373
+ case constants_1.CONNECTION_POOL_CLOSED:
374
+ log = attachConnectionFields(log, logObject);
375
+ log.message = 'Connection pool closed';
376
+ return log;
377
+ case constants_1.CONNECTION_CREATED:
378
+ log = attachConnectionFields(log, logObject);
379
+ log.message = 'Connection created';
380
+ log.driverConnectionId = logObject.connectionId;
381
+ return log;
382
+ case constants_1.CONNECTION_READY:
383
+ log = attachConnectionFields(log, logObject);
384
+ log.message = 'Connection ready';
385
+ log.driverConnectionId = logObject.connectionId;
386
+ log.durationMS = logObject.durationMS;
387
+ return log;
388
+ case constants_1.CONNECTION_CLOSED:
389
+ log = attachConnectionFields(log, logObject);
390
+ log.message = 'Connection closed';
391
+ log.driverConnectionId = logObject.connectionId;
392
+ switch (logObject.reason) {
393
+ case 'stale':
394
+ log.reason = 'Connection became stale because the pool was cleared';
395
+ break;
396
+ case 'idle':
397
+ log.reason =
398
+ 'Connection has been available but unused for longer than the configured max idle time';
399
+ break;
400
+ case 'error':
401
+ log.reason = 'An error occurred while using the connection';
402
+ if (logObject.error) {
403
+ log.error = logObject.error;
404
+ }
405
+ break;
406
+ case 'poolClosed':
407
+ log.reason = 'Connection pool was closed';
408
+ break;
409
+ default:
410
+ log.reason = `Unknown close reason: ${logObject.reason}`;
411
+ }
412
+ return log;
413
+ case constants_1.CONNECTION_CHECK_OUT_STARTED:
414
+ log = attachConnectionFields(log, logObject);
415
+ log.message = 'Connection checkout started';
416
+ return log;
417
+ case constants_1.CONNECTION_CHECK_OUT_FAILED:
418
+ log = attachConnectionFields(log, logObject);
419
+ log.message = 'Connection checkout failed';
420
+ switch (logObject.reason) {
421
+ case 'poolClosed':
422
+ log.reason = 'Connection pool was closed';
423
+ break;
424
+ case 'timeout':
425
+ log.reason = 'Wait queue timeout elapsed without a connection becoming available';
426
+ break;
427
+ case 'connectionError':
428
+ log.reason = 'An error occurred while trying to establish a new connection';
429
+ if (logObject.error) {
430
+ log.error = logObject.error;
431
+ }
432
+ break;
433
+ default:
434
+ log.reason = `Unknown close reason: ${logObject.reason}`;
435
+ }
436
+ log.durationMS = logObject.durationMS;
437
+ return log;
438
+ case constants_1.CONNECTION_CHECKED_OUT:
439
+ log = attachConnectionFields(log, logObject);
440
+ log.message = 'Connection checked out';
441
+ log.driverConnectionId = logObject.connectionId;
442
+ log.durationMS = logObject.durationMS;
443
+ return log;
444
+ case constants_1.CONNECTION_CHECKED_IN:
445
+ log = attachConnectionFields(log, logObject);
446
+ log.message = 'Connection checked in';
447
+ log.driverConnectionId = logObject.connectionId;
448
+ return log;
449
+ case constants_1.SERVER_OPENING:
450
+ log = attachSDAMFields(log, logObject);
451
+ log = attachConnectionFields(log, logObject);
452
+ log.message = 'Starting server monitoring';
453
+ return log;
454
+ case constants_1.SERVER_CLOSED:
455
+ log = attachSDAMFields(log, logObject);
456
+ log = attachConnectionFields(log, logObject);
457
+ log.message = 'Stopped server monitoring';
458
+ return log;
459
+ case constants_1.SERVER_HEARTBEAT_STARTED:
460
+ log = attachSDAMFields(log, logObject);
461
+ log = attachServerHeartbeatFields(log, logObject);
462
+ log.message = 'Server heartbeat started';
463
+ return log;
464
+ case constants_1.SERVER_HEARTBEAT_SUCCEEDED:
465
+ log = attachSDAMFields(log, logObject);
466
+ log = attachServerHeartbeatFields(log, logObject);
467
+ log.message = 'Server heartbeat succeeded';
468
+ log.durationMS = logObject.duration;
469
+ log.serverConnectionId = logObject.serverConnectionId;
470
+ log.reply = stringifyWithMaxLen(logObject.reply, maxDocumentLength, { relaxed: true });
471
+ return log;
472
+ case constants_1.SERVER_HEARTBEAT_FAILED:
473
+ log = attachSDAMFields(log, logObject);
474
+ log = attachServerHeartbeatFields(log, logObject);
475
+ log.message = 'Server heartbeat failed';
476
+ log.durationMS = logObject.duration;
477
+ log.failure = logObject.failure?.message;
478
+ return log;
479
+ case constants_1.TOPOLOGY_OPENING:
480
+ log = attachSDAMFields(log, logObject);
481
+ log.message = 'Starting topology monitoring';
482
+ return log;
483
+ case constants_1.TOPOLOGY_CLOSED:
484
+ log = attachSDAMFields(log, logObject);
485
+ log.message = 'Stopped topology monitoring';
486
+ return log;
487
+ case constants_1.TOPOLOGY_DESCRIPTION_CHANGED:
488
+ log = attachSDAMFields(log, logObject);
489
+ log.message = 'Topology description changed';
490
+ log.previousDescription = log.reply = stringifyWithMaxLen(logObject.previousDescription, maxDocumentLength);
491
+ log.newDescription = log.reply = stringifyWithMaxLen(logObject.newDescription, maxDocumentLength);
492
+ return log;
493
+ default:
494
+ for (const [key, value] of Object.entries(logObject)) {
495
+ if (value != null)
496
+ log[key] = value;
497
+ }
498
+ }
499
+ return log;
500
+ }
501
+ /** @internal */
502
+ class MongoLogger {
503
+ constructor(options) {
504
+ this.pendingLog = null;
505
+ /**
506
+ * This method should be used when logging errors that do not have a public driver API for
507
+ * reporting errors.
508
+ */
509
+ this.error = this.log.bind(this, 'error');
510
+ /**
511
+ * This method should be used to log situations where undesirable application behaviour might
512
+ * occur. For example, failing to end sessions on `MongoClient.close`.
513
+ */
514
+ this.warn = this.log.bind(this, 'warn');
515
+ /**
516
+ * This method should be used to report high-level information about normal driver behaviour.
517
+ * For example, the creation of a `MongoClient`.
518
+ */
519
+ this.info = this.log.bind(this, 'info');
520
+ /**
521
+ * This method should be used to report information that would be helpful when debugging an
522
+ * application. For example, a command starting, succeeding or failing.
523
+ */
524
+ this.debug = this.log.bind(this, 'debug');
525
+ /**
526
+ * This method should be used to report fine-grained details related to logic flow. For example,
527
+ * entering and exiting a function body.
528
+ */
529
+ this.trace = this.log.bind(this, 'trace');
530
+ this.componentSeverities = options.componentSeverities;
531
+ this.maxDocumentLength = options.maxDocumentLength;
532
+ this.logDestination = options.logDestination;
533
+ this.logDestinationIsStdErr = options.logDestinationIsStdErr;
534
+ this.severities = this.createLoggingSeverities();
535
+ }
536
+ createLoggingSeverities() {
537
+ const severities = Object();
538
+ for (const component of Object.values(exports.MongoLoggableComponent)) {
539
+ severities[component] = {};
540
+ for (const severityLevel of Object.values(exports.SeverityLevel)) {
541
+ severities[component][severityLevel] =
542
+ compareSeverity(severityLevel, this.componentSeverities[component]) <= 0;
543
+ }
544
+ }
545
+ return severities;
546
+ }
547
+ turnOffSeverities() {
548
+ for (const component of Object.values(exports.MongoLoggableComponent)) {
549
+ this.componentSeverities[component] = exports.SeverityLevel.OFF;
550
+ for (const severityLevel of Object.values(exports.SeverityLevel)) {
551
+ this.severities[component][severityLevel] = false;
552
+ }
553
+ }
554
+ }
555
+ logWriteFailureHandler(error) {
556
+ if (this.logDestinationIsStdErr) {
557
+ this.turnOffSeverities();
558
+ this.clearPendingLog();
559
+ return;
560
+ }
561
+ this.logDestination = createStdioLogger(process.stderr);
562
+ this.logDestinationIsStdErr = true;
563
+ this.clearPendingLog();
564
+ this.error(exports.MongoLoggableComponent.CLIENT, {
565
+ toLog: function () {
566
+ return {
567
+ message: 'User input for mongodbLogPath is now invalid. Logging is halted.',
568
+ error: error.message
569
+ };
570
+ }
571
+ });
572
+ this.turnOffSeverities();
573
+ this.clearPendingLog();
574
+ }
575
+ clearPendingLog() {
576
+ this.pendingLog = null;
577
+ }
578
+ willLog(component, severity) {
579
+ if (severity === exports.SeverityLevel.OFF)
580
+ return false;
581
+ return this.severities[component][severity];
582
+ }
583
+ log(severity, component, message) {
584
+ if (!this.willLog(component, severity))
585
+ return;
586
+ let logMessage = { t: new Date(), c: component, s: severity };
587
+ if (typeof message === 'string') {
588
+ logMessage.message = message;
589
+ }
590
+ else if (typeof message === 'object') {
591
+ if (isLogConvertible(message)) {
592
+ logMessage = { ...logMessage, ...message.toLog() };
593
+ }
594
+ else {
595
+ logMessage = { ...logMessage, ...defaultLogTransform(message, this.maxDocumentLength) };
596
+ }
597
+ }
598
+ if ((0, utils_1.isPromiseLike)(this.pendingLog)) {
599
+ this.pendingLog = this.pendingLog
600
+ .then(() => this.logDestination.write(logMessage))
601
+ .then(this.clearPendingLog.bind(this), this.logWriteFailureHandler.bind(this));
602
+ return;
603
+ }
604
+ try {
605
+ const logResult = this.logDestination.write(logMessage);
606
+ if ((0, utils_1.isPromiseLike)(logResult)) {
607
+ this.pendingLog = logResult.then(this.clearPendingLog.bind(this), this.logWriteFailureHandler.bind(this));
608
+ }
609
+ }
610
+ catch (error) {
611
+ this.logWriteFailureHandler(error);
612
+ }
613
+ }
614
+ /**
615
+ * Merges options set through environment variables and the MongoClient, preferring environment
616
+ * variables when both are set, and substituting defaults for values not set. Options set in
617
+ * constructor take precedence over both environment variables and MongoClient options.
618
+ *
619
+ * @remarks
620
+ * When parsing component severity levels, invalid values are treated as unset and replaced with
621
+ * the default severity.
622
+ *
623
+ * @param envOptions - options set for the logger from the environment
624
+ * @param clientOptions - options set for the logger in the MongoClient options
625
+ * @returns a MongoLoggerOptions object to be used when instantiating a new MongoLogger
626
+ */
627
+ static resolveOptions(envOptions, clientOptions) {
628
+ // client options take precedence over env options
629
+ const resolvedLogPath = resolveLogPath(envOptions, clientOptions);
630
+ const combinedOptions = {
631
+ ...envOptions,
632
+ ...clientOptions,
633
+ mongodbLogPath: resolvedLogPath.mongodbLogPath,
634
+ mongodbLogPathIsStdErr: resolvedLogPath.mongodbLogPathIsStdErr
635
+ };
636
+ const defaultSeverity = resolveSeverityConfiguration(combinedOptions.mongodbLogComponentSeverities?.default, combinedOptions.MONGODB_LOG_ALL, exports.SeverityLevel.OFF);
637
+ return {
638
+ componentSeverities: {
639
+ command: resolveSeverityConfiguration(combinedOptions.mongodbLogComponentSeverities?.command, combinedOptions.MONGODB_LOG_COMMAND, defaultSeverity),
640
+ topology: resolveSeverityConfiguration(combinedOptions.mongodbLogComponentSeverities?.topology, combinedOptions.MONGODB_LOG_TOPOLOGY, defaultSeverity),
641
+ serverSelection: resolveSeverityConfiguration(combinedOptions.mongodbLogComponentSeverities?.serverSelection, combinedOptions.MONGODB_LOG_SERVER_SELECTION, defaultSeverity),
642
+ connection: resolveSeverityConfiguration(combinedOptions.mongodbLogComponentSeverities?.connection, combinedOptions.MONGODB_LOG_CONNECTION, defaultSeverity),
643
+ client: resolveSeverityConfiguration(combinedOptions.mongodbLogComponentSeverities?.client, combinedOptions.MONGODB_LOG_CLIENT, defaultSeverity),
644
+ default: defaultSeverity
645
+ },
646
+ maxDocumentLength: combinedOptions.mongodbLogMaxDocumentLength ??
647
+ (0, utils_1.parseUnsignedInteger)(combinedOptions.MONGODB_LOG_MAX_DOCUMENT_LENGTH) ??
648
+ 1000,
649
+ logDestination: combinedOptions.mongodbLogPath,
650
+ logDestinationIsStdErr: combinedOptions.mongodbLogPathIsStdErr
651
+ };
652
+ }
653
+ }
654
+ exports.MongoLogger = MongoLogger;
655
+ //# sourceMappingURL=mongo_logger.js.map