@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,548 @@
1
+ import { EJSON, type ObjectId } from '../bson';
2
+ import * as WIRE_CONSTANTS from '../cmap/wire_protocol/constants';
3
+ import { type MongoError, MongoRuntimeError, MongoStalePrimaryError } from '../error';
4
+ import { compareObjectId, shuffle } from '../utils';
5
+ import { ServerType, TopologyType } from './common';
6
+ import { ServerDescription } from './server_description';
7
+ import type { SrvPollingEvent } from './srv_polling';
8
+
9
+ // constants related to compatibility checks
10
+ const MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION;
11
+ const MAX_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MAX_SUPPORTED_SERVER_VERSION;
12
+ const MIN_SUPPORTED_WIRE_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_WIRE_VERSION;
13
+ const MAX_SUPPORTED_WIRE_VERSION = WIRE_CONSTANTS.MAX_SUPPORTED_WIRE_VERSION;
14
+
15
+ const MONGOS_OR_UNKNOWN = new Set<ServerType>([ServerType.Mongos, ServerType.Unknown]);
16
+ const MONGOS_OR_STANDALONE = new Set<ServerType>([ServerType.Mongos, ServerType.Standalone]);
17
+ const NON_PRIMARY_RS_MEMBERS = new Set<ServerType>([
18
+ ServerType.RSSecondary,
19
+ ServerType.RSArbiter,
20
+ ServerType.RSOther
21
+ ]);
22
+
23
+ /** @public */
24
+ export interface TopologyDescriptionOptions {
25
+ heartbeatFrequencyMS?: number;
26
+ localThresholdMS?: number;
27
+ }
28
+
29
+ /**
30
+ * Representation of a deployment of servers
31
+ * @public
32
+ */
33
+ export class TopologyDescription {
34
+ type: TopologyType;
35
+ setName: string | null;
36
+ maxSetVersion: number | null;
37
+ maxElectionId: ObjectId | null;
38
+ servers: Map<string, ServerDescription>;
39
+ stale: boolean;
40
+ compatible: boolean;
41
+ compatibilityError?: string;
42
+ logicalSessionTimeoutMinutes: number | null;
43
+ heartbeatFrequencyMS: number;
44
+ localThresholdMS: number;
45
+ commonWireVersion: number;
46
+ /**
47
+ * Create a TopologyDescription
48
+ */
49
+ constructor(
50
+ topologyType: TopologyType,
51
+ serverDescriptions: Map<string, ServerDescription> | null = null,
52
+ setName: string | null = null,
53
+ maxSetVersion: number | null = null,
54
+ maxElectionId: ObjectId | null = null,
55
+ commonWireVersion: number | null = null,
56
+ options: TopologyDescriptionOptions | null = null
57
+ ) {
58
+ options = options ?? {};
59
+
60
+ this.type = topologyType ?? TopologyType.Unknown;
61
+ this.servers = serverDescriptions ?? new Map();
62
+ this.stale = false;
63
+ this.compatible = true;
64
+ this.heartbeatFrequencyMS = options.heartbeatFrequencyMS ?? 0;
65
+ this.localThresholdMS = options.localThresholdMS ?? 15;
66
+ this.setName = setName ?? null;
67
+ this.maxElectionId = maxElectionId ?? null;
68
+ this.maxSetVersion = maxSetVersion ?? null;
69
+ this.commonWireVersion = commonWireVersion ?? 0;
70
+
71
+ // determine server compatibility
72
+ for (const serverDescription of this.servers.values()) {
73
+ // Load balancer mode is always compatible.
74
+ if (
75
+ serverDescription.type === ServerType.Unknown ||
76
+ serverDescription.type === ServerType.LoadBalancer
77
+ ) {
78
+ continue;
79
+ }
80
+
81
+ if (serverDescription.minWireVersion > MAX_SUPPORTED_WIRE_VERSION) {
82
+ this.compatible = false;
83
+ this.compatibilityError = `Server at ${serverDescription.address} requires wire version ${serverDescription.minWireVersion}, but this version of the driver only supports up to ${MAX_SUPPORTED_WIRE_VERSION} (MongoDB ${MAX_SUPPORTED_SERVER_VERSION})`;
84
+ }
85
+
86
+ if (serverDescription.maxWireVersion < MIN_SUPPORTED_WIRE_VERSION) {
87
+ this.compatible = false;
88
+ this.compatibilityError = `Server at ${serverDescription.address} reports wire version ${serverDescription.maxWireVersion}, but this version of the driver requires at least ${MIN_SUPPORTED_WIRE_VERSION} (MongoDB ${MIN_SUPPORTED_SERVER_VERSION}).`;
89
+ break;
90
+ }
91
+ }
92
+
93
+ // Whenever a client updates the TopologyDescription from a hello response, it MUST set
94
+ // TopologyDescription.logicalSessionTimeoutMinutes to the smallest logicalSessionTimeoutMinutes
95
+ // value among ServerDescriptions of all data-bearing server types. If any have a null
96
+ // logicalSessionTimeoutMinutes, then TopologyDescription.logicalSessionTimeoutMinutes MUST be
97
+ // set to null.
98
+ this.logicalSessionTimeoutMinutes = null;
99
+ for (const [, server] of this.servers) {
100
+ if (server.isReadable) {
101
+ if (server.logicalSessionTimeoutMinutes == null) {
102
+ // If any of the servers have a null logicalSessionsTimeout, then the whole topology does
103
+ this.logicalSessionTimeoutMinutes = null;
104
+ break;
105
+ }
106
+
107
+ if (this.logicalSessionTimeoutMinutes == null) {
108
+ // First server with a non null logicalSessionsTimeout
109
+ this.logicalSessionTimeoutMinutes = server.logicalSessionTimeoutMinutes;
110
+ continue;
111
+ }
112
+
113
+ // Always select the smaller of the:
114
+ // current server logicalSessionsTimeout and the topologies logicalSessionsTimeout
115
+ this.logicalSessionTimeoutMinutes = Math.min(
116
+ this.logicalSessionTimeoutMinutes,
117
+ server.logicalSessionTimeoutMinutes
118
+ );
119
+ }
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Returns a new TopologyDescription based on the SrvPollingEvent
125
+ * @internal
126
+ */
127
+ updateFromSrvPollingEvent(ev: SrvPollingEvent, srvMaxHosts = 0): TopologyDescription {
128
+ /** The SRV addresses defines the set of addresses we should be using */
129
+ const incomingHostnames = ev.hostnames();
130
+ const currentHostnames = new Set(this.servers.keys());
131
+
132
+ const hostnamesToAdd = new Set<string>(incomingHostnames);
133
+ const hostnamesToRemove = new Set<string>();
134
+ for (const hostname of currentHostnames) {
135
+ // filter hostnamesToAdd (made from incomingHostnames) down to what is *not* present in currentHostnames
136
+ hostnamesToAdd.delete(hostname);
137
+ if (!incomingHostnames.has(hostname)) {
138
+ // If the SRV Records no longer include this hostname
139
+ // we have to stop using it
140
+ hostnamesToRemove.add(hostname);
141
+ }
142
+ }
143
+
144
+ if (hostnamesToAdd.size === 0 && hostnamesToRemove.size === 0) {
145
+ // No new hosts to add and none to remove
146
+ return this;
147
+ }
148
+
149
+ const serverDescriptions = new Map(this.servers);
150
+ for (const removedHost of hostnamesToRemove) {
151
+ serverDescriptions.delete(removedHost);
152
+ }
153
+
154
+ if (hostnamesToAdd.size > 0) {
155
+ if (srvMaxHosts === 0) {
156
+ // Add all!
157
+ for (const hostToAdd of hostnamesToAdd) {
158
+ serverDescriptions.set(hostToAdd, new ServerDescription(hostToAdd));
159
+ }
160
+ } else if (serverDescriptions.size < srvMaxHosts) {
161
+ // Add only the amount needed to get us back to srvMaxHosts
162
+ const selectedHosts = shuffle(hostnamesToAdd, srvMaxHosts - serverDescriptions.size);
163
+ for (const selectedHostToAdd of selectedHosts) {
164
+ serverDescriptions.set(selectedHostToAdd, new ServerDescription(selectedHostToAdd));
165
+ }
166
+ }
167
+ }
168
+
169
+ return new TopologyDescription(
170
+ this.type,
171
+ serverDescriptions,
172
+ this.setName,
173
+ this.maxSetVersion,
174
+ this.maxElectionId,
175
+ this.commonWireVersion,
176
+ { heartbeatFrequencyMS: this.heartbeatFrequencyMS, localThresholdMS: this.localThresholdMS }
177
+ );
178
+ }
179
+
180
+ /**
181
+ * Returns a copy of this description updated with a given ServerDescription
182
+ * @internal
183
+ */
184
+ update(serverDescription: ServerDescription): TopologyDescription {
185
+ const address = serverDescription.address;
186
+
187
+ // potentially mutated values
188
+ let { type: topologyType, setName, maxSetVersion, maxElectionId, commonWireVersion } = this;
189
+
190
+ const serverType = serverDescription.type;
191
+ const serverDescriptions = new Map(this.servers);
192
+
193
+ // update common wire version
194
+ if (serverDescription.maxWireVersion !== 0) {
195
+ if (commonWireVersion === 0) {
196
+ commonWireVersion = serverDescription.maxWireVersion;
197
+ } else {
198
+ commonWireVersion = Math.min(commonWireVersion, serverDescription.maxWireVersion);
199
+ }
200
+ }
201
+
202
+ if (
203
+ typeof serverDescription.setName === 'string' &&
204
+ typeof setName === 'string' &&
205
+ serverDescription.setName !== setName
206
+ ) {
207
+ if (topologyType === TopologyType.Single) {
208
+ // "Single" Topology with setName mismatch is direct connection usage, mark unknown do not remove
209
+ serverDescription = new ServerDescription(address);
210
+ } else {
211
+ serverDescriptions.delete(address);
212
+ }
213
+ }
214
+
215
+ // update the actual server description
216
+ serverDescriptions.set(address, serverDescription);
217
+
218
+ if (topologyType === TopologyType.Single) {
219
+ // once we are defined as single, that never changes
220
+ return new TopologyDescription(
221
+ TopologyType.Single,
222
+ serverDescriptions,
223
+ setName,
224
+ maxSetVersion,
225
+ maxElectionId,
226
+ commonWireVersion,
227
+ { heartbeatFrequencyMS: this.heartbeatFrequencyMS, localThresholdMS: this.localThresholdMS }
228
+ );
229
+ }
230
+
231
+ if (topologyType === TopologyType.Unknown) {
232
+ if (serverType === ServerType.Standalone && this.servers.size !== 1) {
233
+ serverDescriptions.delete(address);
234
+ } else {
235
+ topologyType = topologyTypeForServerType(serverType);
236
+ }
237
+ }
238
+
239
+ if (topologyType === TopologyType.Sharded) {
240
+ if (!MONGOS_OR_UNKNOWN.has(serverType)) {
241
+ serverDescriptions.delete(address);
242
+ }
243
+ }
244
+
245
+ if (topologyType === TopologyType.ReplicaSetNoPrimary) {
246
+ if (MONGOS_OR_STANDALONE.has(serverType)) {
247
+ serverDescriptions.delete(address);
248
+ }
249
+
250
+ if (serverType === ServerType.RSPrimary) {
251
+ const result = updateRsFromPrimary(
252
+ serverDescriptions,
253
+ serverDescription,
254
+ setName,
255
+ maxSetVersion,
256
+ maxElectionId
257
+ );
258
+
259
+ topologyType = result[0];
260
+ setName = result[1];
261
+ maxSetVersion = result[2];
262
+ maxElectionId = result[3];
263
+ } else if (NON_PRIMARY_RS_MEMBERS.has(serverType)) {
264
+ const result = updateRsNoPrimaryFromMember(serverDescriptions, serverDescription, setName);
265
+ topologyType = result[0];
266
+ setName = result[1];
267
+ }
268
+ }
269
+
270
+ if (topologyType === TopologyType.ReplicaSetWithPrimary) {
271
+ if (MONGOS_OR_STANDALONE.has(serverType)) {
272
+ serverDescriptions.delete(address);
273
+ topologyType = checkHasPrimary(serverDescriptions);
274
+ } else if (serverType === ServerType.RSPrimary) {
275
+ const result = updateRsFromPrimary(
276
+ serverDescriptions,
277
+ serverDescription,
278
+ setName,
279
+ maxSetVersion,
280
+ maxElectionId
281
+ );
282
+
283
+ topologyType = result[0];
284
+ setName = result[1];
285
+ maxSetVersion = result[2];
286
+ maxElectionId = result[3];
287
+ } else if (NON_PRIMARY_RS_MEMBERS.has(serverType)) {
288
+ topologyType = updateRsWithPrimaryFromMember(
289
+ serverDescriptions,
290
+ serverDescription,
291
+ setName
292
+ );
293
+ } else {
294
+ topologyType = checkHasPrimary(serverDescriptions);
295
+ }
296
+ }
297
+
298
+ return new TopologyDescription(
299
+ topologyType,
300
+ serverDescriptions,
301
+ setName,
302
+ maxSetVersion,
303
+ maxElectionId,
304
+ commonWireVersion,
305
+ { heartbeatFrequencyMS: this.heartbeatFrequencyMS, localThresholdMS: this.localThresholdMS }
306
+ );
307
+ }
308
+
309
+ get error(): MongoError | null {
310
+ const descriptionsWithError = Array.from(this.servers.values()).filter(
311
+ (sd: ServerDescription) => sd.error
312
+ );
313
+
314
+ if (descriptionsWithError.length > 0) {
315
+ return descriptionsWithError[0].error;
316
+ }
317
+
318
+ return null;
319
+ }
320
+
321
+ /**
322
+ * Determines if the topology description has any known servers
323
+ */
324
+ get hasKnownServers(): boolean {
325
+ return Array.from(this.servers.values()).some(
326
+ (sd: ServerDescription) => sd.type !== ServerType.Unknown
327
+ );
328
+ }
329
+
330
+ /**
331
+ * Determines if this topology description has a data-bearing server available.
332
+ */
333
+ get hasDataBearingServers(): boolean {
334
+ return Array.from(this.servers.values()).some((sd: ServerDescription) => sd.isDataBearing);
335
+ }
336
+
337
+ /**
338
+ * Determines if the topology has a definition for the provided address
339
+ * @internal
340
+ */
341
+ hasServer(address: string): boolean {
342
+ return this.servers.has(address);
343
+ }
344
+
345
+ /**
346
+ * Returns a JSON-serializable representation of the TopologyDescription. This is primarily
347
+ * intended for use with JSON.stringify().
348
+ *
349
+ * This method will not throw.
350
+ */
351
+ toJSON() {
352
+ return EJSON.serialize(this);
353
+ }
354
+ }
355
+
356
+ function topologyTypeForServerType(serverType: ServerType): TopologyType {
357
+ switch (serverType) {
358
+ case ServerType.Standalone:
359
+ return TopologyType.Single;
360
+ case ServerType.Mongos:
361
+ return TopologyType.Sharded;
362
+ case ServerType.RSPrimary:
363
+ return TopologyType.ReplicaSetWithPrimary;
364
+ case ServerType.RSOther:
365
+ case ServerType.RSSecondary:
366
+ return TopologyType.ReplicaSetNoPrimary;
367
+ default:
368
+ return TopologyType.Unknown;
369
+ }
370
+ }
371
+
372
+ function updateRsFromPrimary(
373
+ serverDescriptions: Map<string, ServerDescription>,
374
+ serverDescription: ServerDescription,
375
+ setName: string | null = null,
376
+ maxSetVersion: number | null = null,
377
+ maxElectionId: ObjectId | null = null
378
+ ): [TopologyType, string | null, number | null, ObjectId | null] {
379
+ const setVersionElectionIdMismatch = (
380
+ serverDescription: ServerDescription,
381
+ maxSetVersion: number | null,
382
+ maxElectionId: ObjectId | null
383
+ ) => {
384
+ return (
385
+ `primary marked stale due to electionId/setVersion mismatch:` +
386
+ ` server setVersion: ${serverDescription.setVersion},` +
387
+ ` server electionId: ${serverDescription.electionId},` +
388
+ ` topology setVersion: ${maxSetVersion},` +
389
+ ` topology electionId: ${maxElectionId}`
390
+ );
391
+ };
392
+ setName = setName || serverDescription.setName;
393
+ if (setName !== serverDescription.setName) {
394
+ serverDescriptions.delete(serverDescription.address);
395
+ return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
396
+ }
397
+
398
+ if (serverDescription.maxWireVersion >= 17) {
399
+ const electionIdComparison = compareObjectId(maxElectionId, serverDescription.electionId);
400
+ const maxElectionIdIsEqual = electionIdComparison === 0;
401
+ const maxElectionIdIsLess = electionIdComparison === -1;
402
+ const maxSetVersionIsLessOrEqual =
403
+ (maxSetVersion ?? -1) <= (serverDescription.setVersion ?? -1);
404
+
405
+ if (maxElectionIdIsLess || (maxElectionIdIsEqual && maxSetVersionIsLessOrEqual)) {
406
+ // The reported electionId was greater
407
+ // or the electionId was equal and reported setVersion was greater
408
+ // Always update both values, they are a tuple
409
+ maxElectionId = serverDescription.electionId;
410
+ maxSetVersion = serverDescription.setVersion;
411
+ } else {
412
+ // Stale primary
413
+ // replace serverDescription with a default ServerDescription of type "Unknown"
414
+ serverDescriptions.set(
415
+ serverDescription.address,
416
+ new ServerDescription(serverDescription.address, undefined, {
417
+ error: new MongoStalePrimaryError(
418
+ setVersionElectionIdMismatch(serverDescription, maxSetVersion, maxElectionId)
419
+ )
420
+ })
421
+ );
422
+
423
+ return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
424
+ }
425
+ } else {
426
+ const electionId = serverDescription.electionId ? serverDescription.electionId : null;
427
+ if (serverDescription.setVersion && electionId) {
428
+ if (maxSetVersion && maxElectionId) {
429
+ if (
430
+ maxSetVersion > serverDescription.setVersion ||
431
+ compareObjectId(maxElectionId, electionId) > 0
432
+ ) {
433
+ // this primary is stale, we must remove it
434
+ serverDescriptions.set(
435
+ serverDescription.address,
436
+ new ServerDescription(serverDescription.address, undefined, {
437
+ error: new MongoStalePrimaryError(
438
+ setVersionElectionIdMismatch(serverDescription, maxSetVersion, maxElectionId)
439
+ )
440
+ })
441
+ );
442
+
443
+ return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
444
+ }
445
+ }
446
+
447
+ maxElectionId = serverDescription.electionId;
448
+ }
449
+
450
+ if (
451
+ serverDescription.setVersion != null &&
452
+ (maxSetVersion == null || serverDescription.setVersion > maxSetVersion)
453
+ ) {
454
+ maxSetVersion = serverDescription.setVersion;
455
+ }
456
+ }
457
+
458
+ // We've heard from the primary. Is it the same primary as before?
459
+ for (const [address, server] of serverDescriptions) {
460
+ if (server.type === ServerType.RSPrimary && server.address !== serverDescription.address) {
461
+ // Reset old primary's type to Unknown.
462
+ serverDescriptions.set(
463
+ address,
464
+ new ServerDescription(server.address, undefined, {
465
+ error: new MongoStalePrimaryError(
466
+ 'primary marked stale due to discovery of newer primary'
467
+ )
468
+ })
469
+ );
470
+
471
+ // There can only be one primary
472
+ break;
473
+ }
474
+ }
475
+
476
+ // Discover new hosts from this primary's response.
477
+ serverDescription.allHosts.forEach((address: string) => {
478
+ if (!serverDescriptions.has(address)) {
479
+ serverDescriptions.set(address, new ServerDescription(address));
480
+ }
481
+ });
482
+
483
+ // Remove hosts not in the response.
484
+ const currentAddresses = Array.from(serverDescriptions.keys());
485
+ const responseAddresses = serverDescription.allHosts;
486
+ currentAddresses
487
+ .filter((addr: string) => responseAddresses.indexOf(addr) === -1)
488
+ .forEach((address: string) => {
489
+ serverDescriptions.delete(address);
490
+ });
491
+
492
+ return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
493
+ }
494
+
495
+ function updateRsWithPrimaryFromMember(
496
+ serverDescriptions: Map<string, ServerDescription>,
497
+ serverDescription: ServerDescription,
498
+ setName: string | null = null
499
+ ): TopologyType {
500
+ if (setName == null) {
501
+ // TODO(NODE-3483): should be an appropriate runtime error
502
+ throw new MongoRuntimeError('Argument "setName" is required if connected to a replica set');
503
+ }
504
+
505
+ if (
506
+ setName !== serverDescription.setName ||
507
+ (serverDescription.me && serverDescription.address !== serverDescription.me)
508
+ ) {
509
+ serverDescriptions.delete(serverDescription.address);
510
+ }
511
+
512
+ return checkHasPrimary(serverDescriptions);
513
+ }
514
+
515
+ function updateRsNoPrimaryFromMember(
516
+ serverDescriptions: Map<string, ServerDescription>,
517
+ serverDescription: ServerDescription,
518
+ setName: string | null = null
519
+ ): [TopologyType, string | null] {
520
+ const topologyType = TopologyType.ReplicaSetNoPrimary;
521
+ setName = setName ?? serverDescription.setName;
522
+ if (setName !== serverDescription.setName) {
523
+ serverDescriptions.delete(serverDescription.address);
524
+ return [topologyType, setName];
525
+ }
526
+
527
+ serverDescription.allHosts.forEach((address: string) => {
528
+ if (!serverDescriptions.has(address)) {
529
+ serverDescriptions.set(address, new ServerDescription(address));
530
+ }
531
+ });
532
+
533
+ if (serverDescription.me && serverDescription.address !== serverDescription.me) {
534
+ serverDescriptions.delete(serverDescription.address);
535
+ }
536
+
537
+ return [topologyType, setName];
538
+ }
539
+
540
+ function checkHasPrimary(serverDescriptions: Map<string, ServerDescription>): TopologyType {
541
+ for (const serverDescription of serverDescriptions.values()) {
542
+ if (serverDescription.type === ServerType.RSPrimary) {
543
+ return TopologyType.ReplicaSetWithPrimary;
544
+ }
545
+ }
546
+
547
+ return TopologyType.ReplicaSetNoPrimary;
548
+ }