@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,497 @@
1
+ import { type Document } from '../bson';
2
+ import { CursorResponse } from '../cmap/wire_protocol/responses';
3
+ import { MongoAPIError, MongoInvalidArgumentError, MongoTailableCursorError } from '../error';
4
+ import {
5
+ Explain,
6
+ type ExplainCommandOptions,
7
+ type ExplainVerbosityLike,
8
+ validateExplainTimeoutOptions
9
+ } from '../explain';
10
+ import type { MongoClient } from '../mongo_client';
11
+ import { type Abortable } from '../mongo_types';
12
+ import type { CollationOptions } from '../operations/command';
13
+ import { CountOperation, type CountOptions } from '../operations/count';
14
+ import { executeOperation } from '../operations/execute_operation';
15
+ import { FindOperation, type FindOptions } from '../operations/find';
16
+ import type { Hint } from '../operations/operation';
17
+ import type { ClientSession } from '../sessions';
18
+ import { formatSort, type Sort, type SortDirection } from '../sort';
19
+ import { emitWarningOnce, mergeOptions, type MongoDBNamespace, noop, squashError } from '../utils';
20
+ import { type InitialCursorResponse } from './abstract_cursor';
21
+ import { ExplainableCursor } from './explainable_cursor';
22
+
23
+ /** @public Flags allowed for cursor */
24
+ export const FLAGS = [
25
+ 'tailable',
26
+ 'oplogReplay',
27
+ 'noCursorTimeout',
28
+ 'awaitData',
29
+ 'exhaust',
30
+ 'partial'
31
+ ] as const;
32
+
33
+ /** @public */
34
+ export class FindCursor<TSchema = any> extends ExplainableCursor<TSchema> {
35
+ /** @internal */
36
+ private cursorFilter: Document;
37
+ /** @internal */
38
+ private numReturned = 0;
39
+ /** @internal */
40
+ private readonly findOptions: FindOptions & Abortable;
41
+
42
+ /** @internal */
43
+ constructor(
44
+ client: MongoClient,
45
+ namespace: MongoDBNamespace,
46
+ filter: Document = {},
47
+ options: FindOptions & Abortable = {}
48
+ ) {
49
+ super(client, namespace, options);
50
+
51
+ this.cursorFilter = filter;
52
+ this.findOptions = options;
53
+
54
+ if (options.sort != null) {
55
+ this.findOptions.sort = formatSort(options.sort);
56
+ }
57
+ }
58
+
59
+ clone(): FindCursor<TSchema> {
60
+ const clonedOptions = mergeOptions({}, this.findOptions);
61
+ delete clonedOptions.session;
62
+ return new FindCursor(this.client, this.namespace, this.cursorFilter, {
63
+ ...clonedOptions
64
+ });
65
+ }
66
+
67
+ override map<T>(transform: (doc: TSchema) => T): FindCursor<T> {
68
+ return super.map(transform) as FindCursor<T>;
69
+ }
70
+
71
+ /** @internal */
72
+ async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
73
+ const options = {
74
+ ...this.findOptions, // NOTE: order matters here, we may need to refine this
75
+ ...this.cursorOptions,
76
+ session,
77
+ signal: this.signal
78
+ };
79
+
80
+ if (options.explain) {
81
+ try {
82
+ validateExplainTimeoutOptions(options, Explain.fromOptions(options));
83
+ } catch {
84
+ throw new MongoAPIError(
85
+ 'timeoutMS cannot be used with explain when explain is specified in findOptions'
86
+ );
87
+ }
88
+ }
89
+
90
+ const findOperation = new FindOperation(this.namespace, this.cursorFilter, options);
91
+
92
+ const response = await executeOperation(this.client, findOperation, this.timeoutContext);
93
+
94
+ // the response is not a cursor when `explain` is enabled
95
+ this.numReturned = response.batchSize;
96
+
97
+ return { server: findOperation.server, session, response };
98
+ }
99
+
100
+ /** @internal */
101
+ override async getMore(): Promise<CursorResponse> {
102
+ const numReturned = this.numReturned;
103
+ const limit = this.findOptions.limit ?? Infinity;
104
+ const remaining = limit - numReturned;
105
+
106
+ if (numReturned === limit && !this.id?.isZero()) {
107
+ // this is an optimization for the special case of a limit for a find command to avoid an
108
+ // extra getMore when the limit has been reached and the limit is a multiple of the batchSize.
109
+ // This is a consequence of the new query engine in 5.0 having no knowledge of the limit as it
110
+ // produces results for the find command. Once a batch is filled up, it is returned and only
111
+ // on the subsequent getMore will the query framework consider the limit, determine the cursor
112
+ // is exhausted and return a cursorId of zero.
113
+ // instead, if we determine there are no more documents to request from the server, we preemptively
114
+ // close the cursor
115
+ try {
116
+ await this.close();
117
+ } catch (error) {
118
+ squashError(error);
119
+ }
120
+ return CursorResponse.emptyGetMore;
121
+ }
122
+
123
+ // TODO(DRIVERS-1448): Remove logic to enforce `limit` in the driver
124
+ let cleanup: () => void = noop;
125
+ const { batchSize } = this.cursorOptions;
126
+ if (batchSize != null && batchSize > remaining) {
127
+ this.cursorOptions.batchSize = remaining;
128
+
129
+ // After executing the final getMore, re-assign the batchSize back to its original value so that
130
+ // if the cursor is rewound and executed, the batchSize is still correct.
131
+ cleanup = () => {
132
+ this.cursorOptions.batchSize = batchSize;
133
+ };
134
+ }
135
+
136
+ try {
137
+ const response = await super.getMore();
138
+
139
+ this.numReturned = this.numReturned + response.batchSize;
140
+
141
+ return response;
142
+ } finally {
143
+ cleanup?.();
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Get the count of documents for this cursor
149
+ * @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead
150
+ */
151
+ async count(options?: CountOptions): Promise<number> {
152
+ emitWarningOnce(
153
+ 'cursor.count is deprecated and will be removed in the next major version, please use `collection.estimatedDocumentCount` or `collection.countDocuments` instead '
154
+ );
155
+ if (typeof options === 'boolean') {
156
+ throw new MongoInvalidArgumentError('Invalid first parameter to count');
157
+ }
158
+ return await executeOperation(
159
+ this.client,
160
+ new CountOperation(this.namespace, this.cursorFilter, {
161
+ ...this.findOptions, // NOTE: order matters here, we may need to refine this
162
+ ...this.cursorOptions,
163
+ ...options
164
+ })
165
+ );
166
+ }
167
+
168
+ /** Execute the explain for the cursor */
169
+ async explain(): Promise<Document>;
170
+ async explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
171
+ async explain(options: { timeoutMS?: number }): Promise<Document>;
172
+ async explain(
173
+ verbosity: ExplainVerbosityLike | ExplainCommandOptions,
174
+ options: { timeoutMS?: number }
175
+ ): Promise<Document>;
176
+ async explain(
177
+ verbosity?: ExplainVerbosityLike | ExplainCommandOptions | { timeoutMS?: number },
178
+ options?: { timeoutMS?: number }
179
+ ): Promise<Document> {
180
+ const { explain, timeout } = this.resolveExplainTimeoutOptions(verbosity, options);
181
+
182
+ return (
183
+ await executeOperation(
184
+ this.client,
185
+ new FindOperation(this.namespace, this.cursorFilter, {
186
+ ...this.findOptions, // NOTE: order matters here, we may need to refine this
187
+ ...this.cursorOptions,
188
+ ...timeout,
189
+ explain: explain ?? true
190
+ })
191
+ )
192
+ ).shift(this.deserializationOptions);
193
+ }
194
+
195
+ /** Set the cursor query */
196
+ filter(filter: Document): this {
197
+ this.throwIfInitialized();
198
+ this.cursorFilter = filter;
199
+ return this;
200
+ }
201
+
202
+ /**
203
+ * Set the cursor hint
204
+ *
205
+ * @param hint - If specified, then the query system will only consider plans using the hinted index.
206
+ */
207
+ hint(hint: Hint): this {
208
+ this.throwIfInitialized();
209
+ this.findOptions.hint = hint;
210
+ return this;
211
+ }
212
+
213
+ /**
214
+ * Set the cursor min
215
+ *
216
+ * @param min - Specify a $min value to specify the inclusive lower bound for a specific index in order to constrain the results of find(). The $min specifies the lower bound for all keys of a specific index in order.
217
+ */
218
+ min(min: Document): this {
219
+ this.throwIfInitialized();
220
+ this.findOptions.min = min;
221
+ return this;
222
+ }
223
+
224
+ /**
225
+ * Set the cursor max
226
+ *
227
+ * @param max - Specify a $max value to specify the exclusive upper bound for a specific index in order to constrain the results of find(). The $max specifies the upper bound for all keys of a specific index in order.
228
+ */
229
+ max(max: Document): this {
230
+ this.throwIfInitialized();
231
+ this.findOptions.max = max;
232
+ return this;
233
+ }
234
+
235
+ /**
236
+ * Set the cursor returnKey.
237
+ * If set to true, modifies the cursor to only return the index field or fields for the results of the query, rather than documents.
238
+ * If set to true and the query does not use an index to perform the read operation, the returned documents will not contain any fields.
239
+ *
240
+ * @param value - the returnKey value.
241
+ */
242
+ returnKey(value: boolean): this {
243
+ this.throwIfInitialized();
244
+ this.findOptions.returnKey = value;
245
+ return this;
246
+ }
247
+
248
+ /**
249
+ * Modifies the output of a query by adding a field $recordId to matching documents. $recordId is the internal key which uniquely identifies a document in a collection.
250
+ *
251
+ * @param value - The $showDiskLoc option has now been deprecated and replaced with the showRecordId field. $showDiskLoc will still be accepted for OP_QUERY stye find.
252
+ */
253
+ showRecordId(value: boolean): this {
254
+ this.throwIfInitialized();
255
+ this.findOptions.showRecordId = value;
256
+ return this;
257
+ }
258
+
259
+ /**
260
+ * Add a query modifier to the cursor query
261
+ *
262
+ * @param name - The query modifier (must start with $, such as $orderby etc)
263
+ * @param value - The modifier value.
264
+ */
265
+ addQueryModifier(name: string, value: string | boolean | number | Document): this {
266
+ this.throwIfInitialized();
267
+ if (name[0] !== '$') {
268
+ throw new MongoInvalidArgumentError(`${name} is not a valid query modifier`);
269
+ }
270
+
271
+ // Strip of the $
272
+ const field = name.substr(1);
273
+
274
+ // NOTE: consider some TS magic for this
275
+ switch (field) {
276
+ case 'comment':
277
+ this.findOptions.comment = value as string | Document;
278
+ break;
279
+
280
+ case 'explain':
281
+ this.findOptions.explain = value as boolean;
282
+ break;
283
+
284
+ case 'hint':
285
+ this.findOptions.hint = value as string | Document;
286
+ break;
287
+
288
+ case 'max':
289
+ this.findOptions.max = value as Document;
290
+ break;
291
+
292
+ case 'maxTimeMS':
293
+ this.findOptions.maxTimeMS = value as number;
294
+ break;
295
+
296
+ case 'min':
297
+ this.findOptions.min = value as Document;
298
+ break;
299
+
300
+ case 'orderby':
301
+ this.findOptions.sort = formatSort(value as string | Document);
302
+ break;
303
+
304
+ case 'query':
305
+ this.cursorFilter = value as Document;
306
+ break;
307
+
308
+ case 'returnKey':
309
+ this.findOptions.returnKey = value as boolean;
310
+ break;
311
+
312
+ case 'showDiskLoc':
313
+ this.findOptions.showRecordId = value as boolean;
314
+ break;
315
+
316
+ default:
317
+ throw new MongoInvalidArgumentError(`Invalid query modifier: ${name}`);
318
+ }
319
+
320
+ return this;
321
+ }
322
+
323
+ /**
324
+ * Add a comment to the cursor query allowing for tracking the comment in the log.
325
+ *
326
+ * @param value - The comment attached to this query.
327
+ */
328
+ comment(value: string): this {
329
+ this.throwIfInitialized();
330
+ this.findOptions.comment = value;
331
+ return this;
332
+ }
333
+
334
+ /**
335
+ * Set a maxAwaitTimeMS on a tailing cursor query to allow to customize the timeout value for the option awaitData (Only supported on MongoDB 3.2 or higher, ignored otherwise)
336
+ *
337
+ * @param value - Number of milliseconds to wait before aborting the tailed query.
338
+ */
339
+ maxAwaitTimeMS(value: number): this {
340
+ this.throwIfInitialized();
341
+ if (typeof value !== 'number') {
342
+ throw new MongoInvalidArgumentError('Argument for maxAwaitTimeMS must be a number');
343
+ }
344
+
345
+ this.findOptions.maxAwaitTimeMS = value;
346
+ return this;
347
+ }
348
+
349
+ /**
350
+ * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher)
351
+ *
352
+ * @param value - Number of milliseconds to wait before aborting the query.
353
+ */
354
+ override maxTimeMS(value: number): this {
355
+ this.throwIfInitialized();
356
+ if (typeof value !== 'number') {
357
+ throw new MongoInvalidArgumentError('Argument for maxTimeMS must be a number');
358
+ }
359
+
360
+ this.findOptions.maxTimeMS = value;
361
+ return this;
362
+ }
363
+
364
+ /**
365
+ * Add a project stage to the aggregation pipeline
366
+ *
367
+ * @remarks
368
+ * In order to strictly type this function you must provide an interface
369
+ * that represents the effect of your projection on the result documents.
370
+ *
371
+ * By default chaining a projection to your cursor changes the returned type to the generic
372
+ * {@link Document} type.
373
+ * You should specify a parameterized type to have assertions on your final results.
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * // Best way
378
+ * const docs: FindCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
379
+ * // Flexible way
380
+ * const docs: FindCursor<Document> = cursor.project({ _id: 0, a: true });
381
+ * ```
382
+ *
383
+ * @remarks
384
+ *
385
+ * **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
386
+ * it **does not** return a new instance of a cursor. This means when calling project,
387
+ * you should always assign the result to a new variable in order to get a correctly typed cursor variable.
388
+ * Take note of the following example:
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * const cursor: FindCursor<{ a: number; b: string }> = coll.find();
393
+ * const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
394
+ * const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
395
+ *
396
+ * // or always use chaining and save the final cursor
397
+ *
398
+ * const cursor = coll.find().project<{ a: string }>({
399
+ * _id: 0,
400
+ * a: { $convert: { input: '$a', to: 'string' }
401
+ * }});
402
+ * ```
403
+ */
404
+ project<T extends Document = Document>(value: Document): FindCursor<T> {
405
+ this.throwIfInitialized();
406
+ this.findOptions.projection = value;
407
+ return this as unknown as FindCursor<T>;
408
+ }
409
+
410
+ /**
411
+ * Sets the sort order of the cursor query.
412
+ *
413
+ * @param sort - The key or keys set for the sort.
414
+ * @param direction - The direction of the sorting (1 or -1).
415
+ */
416
+ sort(sort: Sort | string, direction?: SortDirection): this {
417
+ this.throwIfInitialized();
418
+ if (this.findOptions.tailable) {
419
+ throw new MongoTailableCursorError('Tailable cursor does not support sorting');
420
+ }
421
+
422
+ this.findOptions.sort = formatSort(sort, direction);
423
+ return this;
424
+ }
425
+
426
+ /**
427
+ * Allows disk use for blocking sort operations exceeding 100MB memory. (MongoDB 3.2 or higher)
428
+ *
429
+ * @remarks
430
+ * {@link https://www.mongodb.com/docs/manual/reference/command/find/#find-cmd-allowdiskuse | find command allowDiskUse documentation}
431
+ */
432
+ allowDiskUse(allow = true): this {
433
+ this.throwIfInitialized();
434
+
435
+ if (!this.findOptions.sort) {
436
+ throw new MongoInvalidArgumentError('Option "allowDiskUse" requires a sort specification');
437
+ }
438
+
439
+ // As of 6.0 the default is true. This allows users to get back to the old behavior.
440
+ if (!allow) {
441
+ this.findOptions.allowDiskUse = false;
442
+ return this;
443
+ }
444
+
445
+ this.findOptions.allowDiskUse = true;
446
+ return this;
447
+ }
448
+
449
+ /**
450
+ * Set the collation options for the cursor.
451
+ *
452
+ * @param value - The cursor collation options (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
453
+ */
454
+ collation(value: CollationOptions): this {
455
+ this.throwIfInitialized();
456
+ this.findOptions.collation = value;
457
+ return this;
458
+ }
459
+
460
+ /**
461
+ * Set the limit for the cursor.
462
+ *
463
+ * @param value - The limit for the cursor query.
464
+ */
465
+ limit(value: number): this {
466
+ this.throwIfInitialized();
467
+ if (this.findOptions.tailable) {
468
+ throw new MongoTailableCursorError('Tailable cursor does not support limit');
469
+ }
470
+
471
+ if (typeof value !== 'number') {
472
+ throw new MongoInvalidArgumentError('Operation "limit" requires an integer');
473
+ }
474
+
475
+ this.findOptions.limit = value;
476
+ return this;
477
+ }
478
+
479
+ /**
480
+ * Set the skip for the cursor.
481
+ *
482
+ * @param value - The skip for the cursor query.
483
+ */
484
+ skip(value: number): this {
485
+ this.throwIfInitialized();
486
+ if (this.findOptions.tailable) {
487
+ throw new MongoTailableCursorError('Tailable cursor does not support skip');
488
+ }
489
+
490
+ if (typeof value !== 'number') {
491
+ throw new MongoInvalidArgumentError('Operation "skip" requires an integer');
492
+ }
493
+
494
+ this.findOptions.skip = value;
495
+ return this;
496
+ }
497
+ }
@@ -0,0 +1,50 @@
1
+ import type { Document } from '../bson';
2
+ import type { Db } from '../db';
3
+ import { type Abortable } from '../mongo_types';
4
+ import { executeOperation } from '../operations/execute_operation';
5
+ import {
6
+ type CollectionInfo,
7
+ ListCollectionsOperation,
8
+ type ListCollectionsOptions
9
+ } from '../operations/list_collections';
10
+ import type { ClientSession } from '../sessions';
11
+ import { AbstractCursor, type InitialCursorResponse } from './abstract_cursor';
12
+
13
+ /** @public */
14
+ export class ListCollectionsCursor<
15
+ T extends Pick<CollectionInfo, 'name' | 'type'> | CollectionInfo =
16
+ | Pick<CollectionInfo, 'name' | 'type'>
17
+ | CollectionInfo
18
+ > extends AbstractCursor<T> {
19
+ parent: Db;
20
+ filter: Document;
21
+ options?: ListCollectionsOptions & Abortable;
22
+
23
+ constructor(db: Db, filter: Document, options?: ListCollectionsOptions & Abortable) {
24
+ super(db.client, db.s.namespace, options);
25
+ this.parent = db;
26
+ this.filter = filter;
27
+ this.options = options;
28
+ }
29
+
30
+ clone(): ListCollectionsCursor<T> {
31
+ return new ListCollectionsCursor(this.parent, this.filter, {
32
+ ...this.options,
33
+ ...this.cursorOptions
34
+ });
35
+ }
36
+
37
+ /** @internal */
38
+ async _initialize(session: ClientSession | undefined): Promise<InitialCursorResponse> {
39
+ const operation = new ListCollectionsOperation(this.parent, this.filter, {
40
+ ...this.cursorOptions,
41
+ ...this.options,
42
+ session,
43
+ signal: this.signal
44
+ });
45
+
46
+ const response = await executeOperation(this.parent.client, operation, this.timeoutContext);
47
+
48
+ return { server: operation.server, session, response };
49
+ }
50
+ }
@@ -0,0 +1,37 @@
1
+ import type { Collection } from '../collection';
2
+ import { executeOperation } from '../operations/execute_operation';
3
+ import { ListIndexesOperation, type ListIndexesOptions } from '../operations/indexes';
4
+ import type { ClientSession } from '../sessions';
5
+ import { AbstractCursor, type InitialCursorResponse } from './abstract_cursor';
6
+
7
+ /** @public */
8
+ export class ListIndexesCursor extends AbstractCursor {
9
+ parent: Collection;
10
+ options?: ListIndexesOptions;
11
+
12
+ constructor(collection: Collection, options?: ListIndexesOptions) {
13
+ super(collection.client, collection.s.namespace, options);
14
+ this.parent = collection;
15
+ this.options = options;
16
+ }
17
+
18
+ clone(): ListIndexesCursor {
19
+ return new ListIndexesCursor(this.parent, {
20
+ ...this.options,
21
+ ...this.cursorOptions
22
+ });
23
+ }
24
+
25
+ /** @internal */
26
+ async _initialize(session: ClientSession | undefined): Promise<InitialCursorResponse> {
27
+ const operation = new ListIndexesOperation(this.parent, {
28
+ ...this.cursorOptions,
29
+ ...this.options,
30
+ session
31
+ });
32
+
33
+ const response = await executeOperation(this.parent.client, operation, this.timeoutContext);
34
+
35
+ return { server: operation.server, session, response };
36
+ }
37
+ }
@@ -0,0 +1,20 @@
1
+ import type { Collection } from '../collection';
2
+ import type { AggregateOptions } from '../operations/aggregate';
3
+ import { AggregationCursor } from './aggregation_cursor';
4
+
5
+ /** @public */
6
+ export type ListSearchIndexesOptions = Omit<AggregateOptions, 'readConcern' | 'writeConcern'>;
7
+
8
+ /** @public */
9
+ export class ListSearchIndexesCursor extends AggregationCursor<{ name: string }> {
10
+ /** @internal */
11
+ constructor(
12
+ { fullNamespace: ns, client }: Collection,
13
+ name: string | null,
14
+ options: ListSearchIndexesOptions = {}
15
+ ) {
16
+ const pipeline =
17
+ name == null ? [{ $listSearchIndexes: {} }] : [{ $listSearchIndexes: { name } }];
18
+ super(client, ns, pipeline, options);
19
+ }
20
+ }