@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,678 @@
1
+ import { EventEmitter } from 'events';
2
+
3
+ import type {
4
+ Binary,
5
+ BSONRegExp,
6
+ BSONType,
7
+ Decimal128,
8
+ Document,
9
+ Double,
10
+ Int32,
11
+ Long,
12
+ ObjectId,
13
+ ObjectIdLike,
14
+ Timestamp
15
+ } from './bson';
16
+ import { type CommandStartedEvent } from './cmap/command_monitoring_events';
17
+ import {
18
+ type LoggableCommandFailedEvent,
19
+ type LoggableCommandSucceededEvent,
20
+ type LoggableServerHeartbeatFailedEvent,
21
+ type LoggableServerHeartbeatStartedEvent,
22
+ type LoggableServerHeartbeatSucceededEvent,
23
+ MongoLoggableComponent,
24
+ type MongoLogger
25
+ } from './mongo_logger';
26
+ import type { Sort } from './sort';
27
+ import { noop } from './utils';
28
+
29
+ /** @internal */
30
+ export type TODO_NODE_3286 = any;
31
+
32
+ /** Given an object shaped type, return the type of the _id field or default to ObjectId @public */
33
+ export type InferIdType<TSchema> = TSchema extends { _id: infer IdType }
34
+ ? // user has defined a type for _id
35
+ Record<any, never> extends IdType
36
+ ? never // explicitly forbid empty objects as the type of _id
37
+ : IdType
38
+ : TSchema extends { _id?: infer IdType }
39
+ ? // optional _id defined - return ObjectId | IdType
40
+ unknown extends IdType
41
+ ? ObjectId // infer the _id type as ObjectId if the type of _id is unknown
42
+ : IdType
43
+ : ObjectId; // user has not defined _id on schema
44
+
45
+ /** Add an _id field to an object shaped type @public */
46
+ export type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & { _id: InferIdType<TSchema> };
47
+
48
+ /**
49
+ * Add an optional _id field to an object shaped type
50
+ * @public
51
+ */
52
+ export type OptionalId<TSchema> = EnhancedOmit<TSchema, '_id'> & { _id?: InferIdType<TSchema> };
53
+
54
+ /**
55
+ * Adds an optional _id field to an object shaped type, unless the _id field is required on that type.
56
+ * In the case _id is required, this method continues to require_id.
57
+ *
58
+ * @public
59
+ *
60
+ * @privateRemarks
61
+ * `ObjectId extends TSchema['_id']` is a confusing ordering at first glance. Rather than ask
62
+ * `TSchema['_id'] extends ObjectId` which translated to "Is the _id property ObjectId?"
63
+ * we instead ask "Does ObjectId look like (have the same shape) as the _id?"
64
+ */
65
+ export type OptionalUnlessRequiredId<TSchema> = TSchema extends { _id: any }
66
+ ? TSchema
67
+ : OptionalId<TSchema>;
68
+
69
+ /** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
70
+ export type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion
71
+ ? TRecordOrUnion // TRecordOrUnion has indexed type e.g. { _id: string; [k: string]: any; } or it is "any"
72
+ : TRecordOrUnion extends any
73
+ ? Pick<TRecordOrUnion, Exclude<keyof TRecordOrUnion, KeyUnion>> // discriminated unions
74
+ : never;
75
+
76
+ /** Remove the _id field from an object shaped type @public */
77
+ export type WithoutId<TSchema> = Omit<TSchema, '_id'>;
78
+
79
+ /** A MongoDB filter can be some portion of the schema or a set of operators @public */
80
+ export type Filter<TSchema> = {
81
+ [P in keyof WithId<TSchema>]?: Condition<WithId<TSchema>[P]>;
82
+ } & RootFilterOperators<WithId<TSchema>>;
83
+
84
+ /** @public */
85
+ export type Condition<T> = AlternativeType<T> | FilterOperators<AlternativeType<T>>;
86
+
87
+ /**
88
+ * It is possible to search using alternative types in mongodb e.g.
89
+ * string types can be searched using a regex in mongo
90
+ * array types can be searched using their element type
91
+ * @public
92
+ */
93
+ export type AlternativeType<T> =
94
+ T extends ReadonlyArray<infer U> ? T | RegExpOrString<U> : RegExpOrString<T>;
95
+
96
+ /** @public */
97
+ export type RegExpOrString<T> = T extends string ? BSONRegExp | RegExp | T : T;
98
+
99
+ /** @public */
100
+ export interface RootFilterOperators<TSchema> extends Document {
101
+ $and?: Filter<TSchema>[];
102
+ $nor?: Filter<TSchema>[];
103
+ $or?: Filter<TSchema>[];
104
+ $text?: {
105
+ $search: string;
106
+ $language?: string;
107
+ $caseSensitive?: boolean;
108
+ $diacriticSensitive?: boolean;
109
+ };
110
+ $where?: string | ((this: TSchema) => boolean);
111
+ $comment?: string | Document;
112
+ }
113
+
114
+ /**
115
+ * @public
116
+ * A type that extends Document but forbids anything that "looks like" an object id.
117
+ */
118
+ export type NonObjectIdLikeDocument = {
119
+ [key in keyof ObjectIdLike]?: never;
120
+ } & Document;
121
+
122
+ /** @public */
123
+ export interface FilterOperators<TValue> extends NonObjectIdLikeDocument {
124
+ // Comparison
125
+ $eq?: TValue;
126
+ $gt?: TValue;
127
+ $gte?: TValue;
128
+ $in?: ReadonlyArray<TValue>;
129
+ $lt?: TValue;
130
+ $lte?: TValue;
131
+ $ne?: TValue;
132
+ $nin?: ReadonlyArray<TValue>;
133
+ // Logical
134
+ $not?: TValue extends string ? FilterOperators<TValue> | RegExp : FilterOperators<TValue>;
135
+ // Element
136
+ /**
137
+ * When `true`, `$exists` matches the documents that contain the field,
138
+ * including documents where the field value is null.
139
+ */
140
+ $exists?: boolean;
141
+ $type?: BSONType | BSONTypeAlias;
142
+ // Evaluation
143
+ $expr?: Record<string, any>;
144
+ $jsonSchema?: Record<string, any>;
145
+ $mod?: TValue extends number ? [number, number] : never;
146
+ $regex?: TValue extends string ? RegExp | BSONRegExp | string : never;
147
+ $options?: TValue extends string ? string : never;
148
+ // Geospatial
149
+ $geoIntersects?: { $geometry: Document };
150
+ $geoWithin?: Document;
151
+ $near?: Document;
152
+ $nearSphere?: Document;
153
+ $maxDistance?: number;
154
+ // Array
155
+ $all?: ReadonlyArray<any>;
156
+ $elemMatch?: Document;
157
+ $size?: TValue extends ReadonlyArray<any> ? number : never;
158
+ // Bitwise
159
+ $bitsAllClear?: BitwiseFilter;
160
+ $bitsAllSet?: BitwiseFilter;
161
+ $bitsAnyClear?: BitwiseFilter;
162
+ $bitsAnySet?: BitwiseFilter;
163
+ $rand?: Record<string, never>;
164
+ }
165
+
166
+ /** @public */
167
+ export type BitwiseFilter =
168
+ | number /** numeric bit mask */
169
+ | Binary /** BinData bit mask */
170
+ | ReadonlyArray<number>; /** `[ <position1>, <position2>, ... ]` */
171
+
172
+ /** @public */
173
+ export type BSONTypeAlias = keyof typeof BSONType;
174
+
175
+ /** @public */
176
+ export type IsAny<Type, ResultIfAny, ResultIfNotAny> = true extends false & Type
177
+ ? ResultIfAny
178
+ : ResultIfNotAny;
179
+
180
+ /** @public */
181
+ export type Flatten<Type> = Type extends ReadonlyArray<infer Item> ? Item : Type;
182
+
183
+ /** @public */
184
+ export type ArrayElement<Type> = Type extends ReadonlyArray<infer Item> ? Item : never;
185
+
186
+ /** @public */
187
+ export type SchemaMember<T, V> = { [P in keyof T]?: V } | { [key: string]: V };
188
+
189
+ /** @public */
190
+ export type IntegerType = number | Int32 | Long | bigint;
191
+
192
+ /** @public */
193
+ export type NumericType = IntegerType | Decimal128 | Double;
194
+
195
+ /** @public */
196
+ export type FilterOperations<T> =
197
+ T extends Record<string, any>
198
+ ? { [key in keyof T]?: FilterOperators<T[key]> }
199
+ : FilterOperators<T>;
200
+
201
+ /** @public */
202
+ export type KeysOfAType<TSchema, Type> = {
203
+ [key in keyof TSchema]: NonNullable<TSchema[key]> extends Type ? key : never;
204
+ }[keyof TSchema];
205
+
206
+ /** @public */
207
+ export type KeysOfOtherType<TSchema, Type> = {
208
+ [key in keyof TSchema]: NonNullable<TSchema[key]> extends Type ? never : key;
209
+ }[keyof TSchema];
210
+
211
+ /** @public */
212
+ export type AcceptedFields<TSchema, FieldType, AssignableType> = {
213
+ readonly [key in KeysOfAType<TSchema, FieldType>]?: AssignableType;
214
+ };
215
+
216
+ /** It avoids using fields with not acceptable types @public */
217
+ export type NotAcceptedFields<TSchema, FieldType> = {
218
+ readonly [key in KeysOfOtherType<TSchema, FieldType>]?: never;
219
+ };
220
+
221
+ /** @public */
222
+ export type OnlyFieldsOfType<TSchema, FieldType = any, AssignableType = FieldType> = IsAny<
223
+ TSchema[keyof TSchema],
224
+ AssignableType extends FieldType ? Record<string, FieldType> : Record<string, AssignableType>,
225
+ AcceptedFields<TSchema, FieldType, AssignableType> &
226
+ NotAcceptedFields<TSchema, FieldType> &
227
+ Record<string, AssignableType>
228
+ >;
229
+
230
+ /** @public */
231
+ export type MatchKeysAndValues<TSchema> = Readonly<Partial<TSchema>> & Record<string, any>;
232
+
233
+ /** @public */
234
+ export type AddToSetOperators<Type> = {
235
+ $each?: Array<Flatten<Type>>;
236
+ };
237
+
238
+ /** @public */
239
+ export type ArrayOperator<Type> = {
240
+ $each?: Array<Flatten<Type>>;
241
+ $slice?: number;
242
+ $position?: number;
243
+ $sort?: Sort;
244
+ };
245
+
246
+ /** @public */
247
+ export type SetFields<TSchema> = ({
248
+ readonly [key in KeysOfAType<TSchema, ReadonlyArray<any> | undefined>]?:
249
+ | OptionalId<Flatten<TSchema[key]>>
250
+ | AddToSetOperators<Array<OptionalId<Flatten<TSchema[key]>>>>;
251
+ } & IsAny<
252
+ TSchema[keyof TSchema],
253
+ object,
254
+ NotAcceptedFields<TSchema, ReadonlyArray<any> | undefined>
255
+ >) & {
256
+ readonly [key: string]: AddToSetOperators<any> | any;
257
+ };
258
+
259
+ /** @public */
260
+ export type PushOperator<TSchema> = ({
261
+ readonly [key in KeysOfAType<TSchema, ReadonlyArray<any>>]?:
262
+ | Flatten<TSchema[key]>
263
+ | ArrayOperator<Array<Flatten<TSchema[key]>>>;
264
+ } & NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {
265
+ readonly [key: string]: ArrayOperator<any> | any;
266
+ };
267
+
268
+ /** @public */
269
+ export type PullOperator<TSchema> = ({
270
+ readonly [key in KeysOfAType<TSchema, ReadonlyArray<any>>]?:
271
+ | Partial<Flatten<TSchema[key]>>
272
+ | FilterOperations<Flatten<TSchema[key]>>;
273
+ } & NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {
274
+ readonly [key: string]: FilterOperators<any> | any;
275
+ };
276
+
277
+ /** @public */
278
+ export type PullAllOperator<TSchema> = ({
279
+ readonly [key in KeysOfAType<TSchema, ReadonlyArray<any>>]?: TSchema[key];
280
+ } & NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {
281
+ readonly [key: string]: ReadonlyArray<any>;
282
+ };
283
+
284
+ /** @public */
285
+ export type UpdateFilter<TSchema> = {
286
+ $currentDate?: OnlyFieldsOfType<
287
+ TSchema,
288
+ Date | Timestamp,
289
+ true | { $type: 'date' | 'timestamp' }
290
+ >;
291
+ $inc?: OnlyFieldsOfType<TSchema, NumericType | undefined>;
292
+ $min?: MatchKeysAndValues<TSchema>;
293
+ $max?: MatchKeysAndValues<TSchema>;
294
+ $mul?: OnlyFieldsOfType<TSchema, NumericType | undefined>;
295
+ $rename?: Record<string, string>;
296
+ $set?: MatchKeysAndValues<TSchema>;
297
+ $setOnInsert?: MatchKeysAndValues<TSchema>;
298
+ $unset?: OnlyFieldsOfType<TSchema, any, '' | true | 1>;
299
+ $addToSet?: SetFields<TSchema>;
300
+ $pop?: OnlyFieldsOfType<TSchema, ReadonlyArray<any>, 1 | -1>;
301
+ $pull?: PullOperator<TSchema>;
302
+ $push?: PushOperator<TSchema>;
303
+ $pullAll?: PullAllOperator<TSchema>;
304
+ $bit?: OnlyFieldsOfType<
305
+ TSchema,
306
+ NumericType | undefined,
307
+ { and: IntegerType } | { or: IntegerType } | { xor: IntegerType }
308
+ >;
309
+ } & Document;
310
+
311
+ /** @public */
312
+ export type Nullable<AnyType> = AnyType | null | undefined;
313
+
314
+ /** @public */
315
+ export type OneOrMore<T> = T | ReadonlyArray<T>;
316
+
317
+ /** @public */
318
+ export type GenericListener = (...args: any[]) => void;
319
+
320
+ /**
321
+ * Event description type
322
+ * @public
323
+ */
324
+ export type EventsDescription = Record<string, GenericListener>;
325
+
326
+ /** @public */
327
+ export type CommonEvents = 'newListener' | 'removeListener';
328
+
329
+ /**
330
+ * Typescript type safe event emitter
331
+ * @public
332
+ */
333
+ export declare interface TypedEventEmitter<Events extends EventsDescription> extends EventEmitter {
334
+ addListener<EventKey extends keyof Events>(event: EventKey, listener: Events[EventKey]): this;
335
+ addListener(
336
+ event: CommonEvents,
337
+ listener: (eventName: string | symbol, listener: GenericListener) => void
338
+ ): this;
339
+ addListener(event: string | symbol, listener: GenericListener): this;
340
+
341
+ on<EventKey extends keyof Events>(event: EventKey, listener: Events[EventKey]): this;
342
+ on(
343
+ event: CommonEvents,
344
+ listener: (eventName: string | symbol, listener: GenericListener) => void
345
+ ): this;
346
+ on(event: string | symbol, listener: GenericListener): this;
347
+
348
+ once<EventKey extends keyof Events>(event: EventKey, listener: Events[EventKey]): this;
349
+ once(
350
+ event: CommonEvents,
351
+ listener: (eventName: string | symbol, listener: GenericListener) => void
352
+ ): this;
353
+ once(event: string | symbol, listener: GenericListener): this;
354
+
355
+ removeListener<EventKey extends keyof Events>(event: EventKey, listener: Events[EventKey]): this;
356
+ removeListener(
357
+ event: CommonEvents,
358
+ listener: (eventName: string | symbol, listener: GenericListener) => void
359
+ ): this;
360
+ removeListener(event: string | symbol, listener: GenericListener): this;
361
+
362
+ off<EventKey extends keyof Events>(event: EventKey, listener: Events[EventKey]): this;
363
+ off(
364
+ event: CommonEvents,
365
+ listener: (eventName: string | symbol, listener: GenericListener) => void
366
+ ): this;
367
+ off(event: string | symbol, listener: GenericListener): this;
368
+
369
+ removeAllListeners<EventKey extends keyof Events>(
370
+ event?: EventKey | CommonEvents | symbol | string
371
+ ): this;
372
+
373
+ listeners<EventKey extends keyof Events>(
374
+ event: EventKey | CommonEvents | symbol | string
375
+ ): Events[EventKey][];
376
+
377
+ rawListeners<EventKey extends keyof Events>(
378
+ event: EventKey | CommonEvents | symbol | string
379
+ ): Events[EventKey][];
380
+
381
+ emit<EventKey extends keyof Events>(
382
+ event: EventKey | symbol,
383
+ ...args: Parameters<Events[EventKey]>
384
+ ): boolean;
385
+
386
+ listenerCount<EventKey extends keyof Events>(
387
+ type: EventKey | CommonEvents | symbol | string
388
+ ): number;
389
+
390
+ prependListener<EventKey extends keyof Events>(event: EventKey, listener: Events[EventKey]): this;
391
+ prependListener(
392
+ event: CommonEvents,
393
+ listener: (eventName: string | symbol, listener: GenericListener) => void
394
+ ): this;
395
+ prependListener(event: string | symbol, listener: GenericListener): this;
396
+
397
+ prependOnceListener<EventKey extends keyof Events>(
398
+ event: EventKey,
399
+ listener: Events[EventKey]
400
+ ): this;
401
+ prependOnceListener(
402
+ event: CommonEvents,
403
+ listener: (eventName: string | symbol, listener: GenericListener) => void
404
+ ): this;
405
+ prependOnceListener(event: string | symbol, listener: GenericListener): this;
406
+
407
+ eventNames(): string[];
408
+ getMaxListeners(): number;
409
+ setMaxListeners(n: number): this;
410
+ }
411
+
412
+ /**
413
+ * Typescript type safe event emitter
414
+ * @public
415
+ */
416
+
417
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
418
+ export class TypedEventEmitter<Events extends EventsDescription> extends EventEmitter {
419
+ /** @internal */
420
+ protected mongoLogger?: MongoLogger;
421
+ /** @internal */
422
+ protected component?: MongoLoggableComponent;
423
+ /** @internal */
424
+ emitAndLog<EventKey extends keyof Events>(
425
+ event: EventKey | symbol,
426
+ ...args: Parameters<Events[EventKey]>
427
+ ): void {
428
+ this.emit(event, ...args);
429
+ if (this.component) this.mongoLogger?.debug(this.component, args[0]);
430
+ }
431
+ /** @internal */
432
+ emitAndLogHeartbeat<EventKey extends keyof Events>(
433
+ event: EventKey | symbol,
434
+ topologyId: number,
435
+ serverConnectionId?: number | '<monitor>',
436
+ ...args: Parameters<Events[EventKey]>
437
+ ): void {
438
+ this.emit(event, ...args);
439
+ if (this.component) {
440
+ const loggableHeartbeatEvent:
441
+ | LoggableServerHeartbeatFailedEvent
442
+ | LoggableServerHeartbeatSucceededEvent
443
+ | LoggableServerHeartbeatStartedEvent = {
444
+ topologyId: topologyId,
445
+ serverConnectionId: serverConnectionId ?? null,
446
+ ...args[0]
447
+ };
448
+ this.mongoLogger?.debug(this.component, loggableHeartbeatEvent);
449
+ }
450
+ }
451
+ /** @internal */
452
+ emitAndLogCommand<EventKey extends keyof Events>(
453
+ monitorCommands: boolean,
454
+ event: EventKey | symbol,
455
+ databaseName: string,
456
+ connectionEstablished: boolean,
457
+ ...args: Parameters<Events[EventKey]>
458
+ ): void {
459
+ if (monitorCommands) {
460
+ this.emit(event, ...args);
461
+ }
462
+ if (connectionEstablished) {
463
+ const loggableCommandEvent:
464
+ | CommandStartedEvent
465
+ | LoggableCommandFailedEvent
466
+ | LoggableCommandSucceededEvent = {
467
+ databaseName: databaseName,
468
+ ...args[0]
469
+ };
470
+ this.mongoLogger?.debug(MongoLoggableComponent.COMMAND, loggableCommandEvent);
471
+ }
472
+ }
473
+ }
474
+
475
+ /**
476
+ * @internal
477
+ */
478
+ export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {
479
+ constructor(...args: any[]) {
480
+ super(...args);
481
+ this.on('error', noop);
482
+ }
483
+ }
484
+
485
+ /** @public */
486
+ export type Abortable = {
487
+ /**
488
+ * @experimental
489
+ * When provided, the corresponding `AbortController` can be used to abort an asynchronous action.
490
+ *
491
+ * The `signal.reason` value is used as the error thrown.
492
+ *
493
+ * @remarks
494
+ * **NOTE:** If an abort signal aborts an operation while the driver is writing to the underlying
495
+ * socket or reading the response from the server, the socket will be closed.
496
+ * If signals are aborted at a high rate during socket read/writes this can lead to a high rate of connection reestablishment.
497
+ *
498
+ * We plan to mitigate this in a future release, please follow NODE-6062 (`timeoutMS` expiration suffers the same limitation).
499
+ *
500
+ * AbortSignals are likely a best fit for human interactive interruption (ex. ctrl-C) where the frequency
501
+ * of cancellation is reasonably low. If a signal is programmatically aborted for 100s of operations you can empty
502
+ * the driver's connection pool.
503
+ *
504
+ * @example
505
+ * ```js
506
+ * const controller = new AbortController();
507
+ * const { signal } = controller;
508
+ * process.on('SIGINT', () => controller.abort(new Error('^C pressed')));
509
+ *
510
+ * try {
511
+ * const res = await fetch('...', { signal });
512
+ * await collection.findOne(await res.json(), { signal });
513
+ * catch (error) {
514
+ * if (error === signal.reason) {
515
+ * // signal abort error handling
516
+ * }
517
+ * }
518
+ * ```
519
+ */
520
+ signal?: AbortSignal | undefined;
521
+ };
522
+
523
+ /**
524
+ * Helper types for dot-notation filter attributes
525
+ */
526
+
527
+ /** @public */
528
+ export type Join<T extends unknown[], D extends string> = T extends []
529
+ ? ''
530
+ : T extends [string | number]
531
+ ? `${T[0]}`
532
+ : T extends [string | number, ...infer R]
533
+ ? `${T[0]}${D}${Join<R, D>}`
534
+ : string;
535
+
536
+ /** @public */
537
+ export type PropertyType<Type, Property extends string> = string extends Property
538
+ ? unknown
539
+ : Property extends keyof Type
540
+ ? Type[Property]
541
+ : Property extends `${number}`
542
+ ? Type extends ReadonlyArray<infer ArrayType>
543
+ ? ArrayType
544
+ : unknown
545
+ : Property extends `${infer Key}.${infer Rest}`
546
+ ? Key extends `${number}`
547
+ ? Type extends ReadonlyArray<infer ArrayType>
548
+ ? PropertyType<ArrayType, Rest>
549
+ : unknown
550
+ : Key extends keyof Type
551
+ ? Type[Key] extends Map<string, infer MapType>
552
+ ? MapType
553
+ : PropertyType<Type[Key], Rest>
554
+ : unknown
555
+ : unknown;
556
+
557
+ /**
558
+ * @public
559
+ * returns tuple of strings (keys to be joined on '.') that represent every path into a schema
560
+ * https://www.mongodb.com/docs/manual/tutorial/query-embedded-documents/
561
+ *
562
+ * @remarks
563
+ * Through testing we determined that a depth of 8 is safe for the typescript compiler
564
+ * and provides reasonable compilation times. This number is otherwise not special and
565
+ * should be changed if issues are found with this level of checking. Beyond this
566
+ * depth any helpers that make use of NestedPaths should devolve to not asserting any
567
+ * type safety on the input.
568
+ */
569
+ export type NestedPaths<Type, Depth extends number[]> = Depth['length'] extends 8
570
+ ? []
571
+ : Type extends
572
+ | string
573
+ | number
574
+ | bigint
575
+ | boolean
576
+ | Date
577
+ | RegExp
578
+ | Buffer
579
+ | Uint8Array
580
+ | ((...args: any[]) => any)
581
+ | { _bsontype: string }
582
+ ? []
583
+ : Type extends ReadonlyArray<infer ArrayType>
584
+ ? [] | [number, ...NestedPaths<ArrayType, [...Depth, 1]>]
585
+ : Type extends Map<string, any>
586
+ ? [string]
587
+ : Type extends object
588
+ ? {
589
+ [Key in Extract<keyof Type, string>]: Type[Key] extends Type // type of value extends the parent
590
+ ? [Key]
591
+ : // for a recursive union type, the child will never extend the parent type.
592
+ // but the parent will still extend the child
593
+ Type extends Type[Key]
594
+ ? [Key]
595
+ : Type[Key] extends ReadonlyArray<infer ArrayType> // handling recursive types with arrays
596
+ ? Type extends ArrayType // is the type of the parent the same as the type of the array?
597
+ ? [Key] // yes, it's a recursive array type
598
+ : // for unions, the child type extends the parent
599
+ ArrayType extends Type
600
+ ? [Key] // we have a recursive array union
601
+ : // child is an array, but it's not a recursive array
602
+ [Key, ...NestedPaths<Type[Key], [...Depth, 1]>]
603
+ : // child is not structured the same as the parent
604
+ [Key, ...NestedPaths<Type[Key], [...Depth, 1]>] | [Key];
605
+ }[Extract<keyof Type, string>]
606
+ : [];
607
+
608
+ /**
609
+ * @public
610
+ * returns keys (strings) for every path into a schema with a value of type
611
+ * https://www.mongodb.com/docs/manual/tutorial/query-embedded-documents/
612
+ */
613
+ export type NestedPathsOfType<TSchema, Type> = KeysOfAType<
614
+ {
615
+ [Property in Join<NestedPaths<TSchema, []>, '.'>]: PropertyType<TSchema, Property>;
616
+ },
617
+ Type
618
+ >;
619
+
620
+ /**
621
+ * @public
622
+ * @experimental
623
+ */
624
+ export type StrictFilter<TSchema> =
625
+ | Partial<TSchema>
626
+ | ({
627
+ [Property in Join<NestedPaths<WithId<TSchema>, []>, '.'>]?: Condition<
628
+ PropertyType<WithId<TSchema>, Property>
629
+ >;
630
+ } & RootFilterOperators<WithId<TSchema>>);
631
+
632
+ /**
633
+ * @public
634
+ * @experimental
635
+ */
636
+ export type StrictUpdateFilter<TSchema> = {
637
+ $currentDate?: OnlyFieldsOfType<
638
+ TSchema,
639
+ Date | Timestamp,
640
+ true | { $type: 'date' | 'timestamp' }
641
+ >;
642
+ $inc?: OnlyFieldsOfType<TSchema, NumericType | undefined>;
643
+ $min?: StrictMatchKeysAndValues<TSchema>;
644
+ $max?: StrictMatchKeysAndValues<TSchema>;
645
+ $mul?: OnlyFieldsOfType<TSchema, NumericType | undefined>;
646
+ $rename?: Record<string, string>;
647
+ $set?: StrictMatchKeysAndValues<TSchema>;
648
+ $setOnInsert?: StrictMatchKeysAndValues<TSchema>;
649
+ $unset?: OnlyFieldsOfType<TSchema, any, '' | true | 1>;
650
+ $addToSet?: SetFields<TSchema>;
651
+ $pop?: OnlyFieldsOfType<TSchema, ReadonlyArray<any>, 1 | -1>;
652
+ $pull?: PullOperator<TSchema>;
653
+ $push?: PushOperator<TSchema>;
654
+ $pullAll?: PullAllOperator<TSchema>;
655
+ $bit?: OnlyFieldsOfType<
656
+ TSchema,
657
+ NumericType | undefined,
658
+ { and: IntegerType } | { or: IntegerType } | { xor: IntegerType }
659
+ >;
660
+ } & Document;
661
+
662
+ /**
663
+ * @public
664
+ * @experimental
665
+ */
666
+ export type StrictMatchKeysAndValues<TSchema> = Readonly<
667
+ {
668
+ [Property in Join<NestedPaths<TSchema, []>, '.'>]?: PropertyType<TSchema, Property>;
669
+ } & {
670
+ [Property in `${NestedPathsOfType<TSchema, any[]>}.$${`[${string}]` | ''}`]?: ArrayElement<
671
+ PropertyType<TSchema, Property extends `${infer Key}.$${string}` ? Key : never>
672
+ >;
673
+ } & {
674
+ [Property in `${NestedPathsOfType<TSchema, Record<string, any>[]>}.$${
675
+ | `[${string}]`
676
+ | ''}.${string}`]?: any; // Could be further narrowed
677
+ } & Document
678
+ >;