@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,358 @@
1
+ import {
2
+ Binary,
3
+ type BSONElement,
4
+ BSONError,
5
+ BSONType,
6
+ deserialize,
7
+ type DeserializeOptions,
8
+ getBigInt64LE,
9
+ getFloat64LE,
10
+ getInt32LE,
11
+ ObjectId,
12
+ parseToElementsToArray,
13
+ Timestamp,
14
+ toUTF8
15
+ } from '../../../bson';
16
+
17
+ const BSONElementOffset = {
18
+ type: 0,
19
+ nameOffset: 1,
20
+ nameLength: 2,
21
+ offset: 3,
22
+ length: 4
23
+ } as const;
24
+
25
+ /** @internal */
26
+ export type JSTypeOf = {
27
+ [BSONType.null]: null;
28
+ [BSONType.undefined]: null;
29
+ [BSONType.double]: number;
30
+ [BSONType.int]: number;
31
+ [BSONType.long]: bigint;
32
+ [BSONType.timestamp]: Timestamp;
33
+ [BSONType.binData]: Binary;
34
+ [BSONType.bool]: boolean;
35
+ [BSONType.objectId]: ObjectId;
36
+ [BSONType.string]: string;
37
+ [BSONType.date]: Date;
38
+ [BSONType.object]: OnDemandDocument;
39
+ [BSONType.array]: OnDemandDocument;
40
+ };
41
+
42
+ /** @internal */
43
+ type CachedBSONElement = { element: BSONElement; value: any | undefined };
44
+
45
+ /**
46
+ * @internal
47
+ *
48
+ * Options for `OnDemandDocument.toObject()`. Validation is required to ensure
49
+ * that callers provide utf8 validation options. */
50
+ export type OnDemandDocumentDeserializeOptions = Omit<DeserializeOptions, 'validation'> &
51
+ Required<Pick<DeserializeOptions, 'validation'>>;
52
+
53
+ /** @internal */
54
+ export class OnDemandDocument {
55
+ /**
56
+ * Maps JS strings to elements and jsValues for speeding up subsequent lookups.
57
+ * - If `false` then name does not exist in the BSON document
58
+ * - If `CachedBSONElement` instance name exists
59
+ * - If `cache[name].value == null` jsValue has not yet been parsed
60
+ * - Null/Undefined values do not get cached because they are zero-length values.
61
+ */
62
+ private readonly cache: Record<string, CachedBSONElement | false | undefined> =
63
+ Object.create(null);
64
+ /** Caches the index of elements that have been named */
65
+ private readonly indexFound: Record<number, boolean> = Object.create(null);
66
+
67
+ /** All bson elements in this document */
68
+ private readonly elements: ReadonlyArray<BSONElement>;
69
+ /** BSON bytes, this document begins at offset */
70
+ protected readonly bson: Uint8Array;
71
+ /** The start of the document */
72
+ private readonly offset: number;
73
+ /** If this is an embedded document, indicates if this was a BSON array */
74
+ public readonly isArray: boolean;
75
+
76
+ constructor(
77
+ bson: Uint8Array,
78
+ offset = 0,
79
+ isArray = false,
80
+ /** If elements was already calculated */
81
+ elements?: BSONElement[]
82
+ ) {
83
+ this.bson = bson;
84
+ this.offset = offset;
85
+ this.isArray = isArray;
86
+ this.elements = elements ?? parseToElementsToArray(this.bson, offset);
87
+ }
88
+
89
+ /** Only supports basic latin strings */
90
+ private isElementName(name: string, element: BSONElement): boolean {
91
+ const nameLength = element[BSONElementOffset.nameLength];
92
+ const nameOffset = element[BSONElementOffset.nameOffset];
93
+
94
+ if (name.length !== nameLength) return false;
95
+
96
+ const nameEnd = nameOffset + nameLength;
97
+ for (
98
+ let byteIndex = nameOffset, charIndex = 0;
99
+ charIndex < name.length && byteIndex < nameEnd;
100
+ charIndex++, byteIndex++
101
+ ) {
102
+ if (this.bson[byteIndex] !== name.charCodeAt(charIndex)) return false;
103
+ }
104
+
105
+ return true;
106
+ }
107
+
108
+ /**
109
+ * Seeks into the elements array for an element matching the given name.
110
+ *
111
+ * @remarks
112
+ * Caching:
113
+ * - Caches the existence of a property making subsequent look ups for non-existent properties return immediately
114
+ * - Caches names mapped to elements to avoid reiterating the array and comparing the name again
115
+ * - Caches the index at which an element has been found to prevent rechecking against elements already determined to belong to another name
116
+ *
117
+ * @param name - a basic latin string name of a BSON element
118
+ * @returns
119
+ */
120
+ private getElement(name: string | number): CachedBSONElement | null {
121
+ const cachedElement = this.cache[name];
122
+ if (cachedElement === false) return null;
123
+
124
+ if (cachedElement != null) {
125
+ return cachedElement;
126
+ }
127
+
128
+ if (typeof name === 'number') {
129
+ if (this.isArray) {
130
+ if (name < this.elements.length) {
131
+ const element = this.elements[name];
132
+ const cachedElement = { element, value: undefined };
133
+ this.cache[name] = cachedElement;
134
+ this.indexFound[name] = true;
135
+ return cachedElement;
136
+ } else {
137
+ return null;
138
+ }
139
+ } else {
140
+ return null;
141
+ }
142
+ }
143
+
144
+ for (let index = 0; index < this.elements.length; index++) {
145
+ const element = this.elements[index];
146
+
147
+ // skip this element if it has already been associated with a name
148
+ if (!(index in this.indexFound) && this.isElementName(name, element)) {
149
+ const cachedElement = { element, value: undefined };
150
+ this.cache[name] = cachedElement;
151
+ this.indexFound[index] = true;
152
+ return cachedElement;
153
+ }
154
+ }
155
+
156
+ this.cache[name] = false;
157
+ return null;
158
+ }
159
+
160
+ /**
161
+ * Translates BSON bytes into a javascript value. Checking `as` against the BSON element's type
162
+ * this methods returns the small subset of BSON types that the driver needs to function.
163
+ *
164
+ * @remarks
165
+ * - BSONType.null and BSONType.undefined always return null
166
+ * - If the type requested does not match this returns null
167
+ *
168
+ * @param element - The element to revive to a javascript value
169
+ * @param as - A type byte expected to be returned
170
+ */
171
+ private toJSValue<T extends keyof JSTypeOf>(element: BSONElement, as: T): JSTypeOf[T];
172
+ private toJSValue(element: BSONElement, as: keyof JSTypeOf): any {
173
+ const type = element[BSONElementOffset.type];
174
+ const offset = element[BSONElementOffset.offset];
175
+ const length = element[BSONElementOffset.length];
176
+
177
+ if (as !== type) {
178
+ return null;
179
+ }
180
+
181
+ switch (as) {
182
+ case BSONType.null:
183
+ case BSONType.undefined:
184
+ return null;
185
+ case BSONType.double:
186
+ return getFloat64LE(this.bson, offset);
187
+ case BSONType.int:
188
+ return getInt32LE(this.bson, offset);
189
+ case BSONType.long:
190
+ return getBigInt64LE(this.bson, offset);
191
+ case BSONType.bool:
192
+ return Boolean(this.bson[offset]);
193
+ case BSONType.objectId:
194
+ return new ObjectId(this.bson.subarray(offset, offset + 12));
195
+ case BSONType.timestamp:
196
+ return new Timestamp(getBigInt64LE(this.bson, offset));
197
+ case BSONType.string:
198
+ return toUTF8(this.bson, offset + 4, offset + length - 1, false);
199
+ case BSONType.binData: {
200
+ const totalBinarySize = getInt32LE(this.bson, offset);
201
+ const subType = this.bson[offset + 4];
202
+
203
+ if (subType === 2) {
204
+ const subType2BinarySize = getInt32LE(this.bson, offset + 1 + 4);
205
+ if (subType2BinarySize < 0)
206
+ throw new BSONError('Negative binary type element size found for subtype 0x02');
207
+ if (subType2BinarySize > totalBinarySize - 4)
208
+ throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
209
+ if (subType2BinarySize < totalBinarySize - 4)
210
+ throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
211
+ return new Binary(
212
+ this.bson.subarray(offset + 1 + 4 + 4, offset + 1 + 4 + 4 + subType2BinarySize),
213
+ 2
214
+ );
215
+ }
216
+
217
+ return new Binary(
218
+ this.bson.subarray(offset + 1 + 4, offset + 1 + 4 + totalBinarySize),
219
+ subType
220
+ );
221
+ }
222
+ case BSONType.date:
223
+ // Pretend this is correct.
224
+ return new Date(Number(getBigInt64LE(this.bson, offset)));
225
+
226
+ case BSONType.object:
227
+ return new OnDemandDocument(this.bson, offset);
228
+ case BSONType.array:
229
+ return new OnDemandDocument(this.bson, offset, true);
230
+
231
+ default:
232
+ throw new BSONError(`Unsupported BSON type: ${as}`);
233
+ }
234
+ }
235
+
236
+ /**
237
+ * Returns the number of elements in this BSON document
238
+ */
239
+ public size() {
240
+ return this.elements.length;
241
+ }
242
+
243
+ /**
244
+ * Checks for the existence of an element by name.
245
+ *
246
+ * @remarks
247
+ * Uses `getElement` with the expectation that will populate caches such that a `has` call
248
+ * followed by a `getElement` call will not repeat the cost paid by the first look up.
249
+ *
250
+ * @param name - element name
251
+ */
252
+ public has(name: string): boolean {
253
+ const cachedElement = this.cache[name];
254
+ if (cachedElement === false) return false;
255
+ if (cachedElement != null) return true;
256
+ return this.getElement(name) != null;
257
+ }
258
+
259
+ /**
260
+ * Turns BSON element with `name` into a javascript value.
261
+ *
262
+ * @typeParam T - must be one of the supported BSON types determined by `JSTypeOf` this will determine the return type of this function.
263
+ * @param name - the element name
264
+ * @param as - the bson type expected
265
+ * @param required - whether or not the element is expected to exist, if true this function will throw if it is not present
266
+ */
267
+ public get<const T extends keyof JSTypeOf>(
268
+ name: string | number,
269
+ as: T,
270
+ required?: boolean
271
+ ): JSTypeOf[T] | null;
272
+
273
+ /** `required` will make `get` throw if name does not exist or is null/undefined */
274
+ public get<const T extends keyof JSTypeOf>(
275
+ name: string | number,
276
+ as: T,
277
+ required: true
278
+ ): JSTypeOf[T];
279
+
280
+ public get<const T extends keyof JSTypeOf>(
281
+ name: string | number,
282
+ as: T,
283
+ required?: boolean
284
+ ): JSTypeOf[T] | null {
285
+ const element = this.getElement(name);
286
+ if (element == null) {
287
+ if (required === true) {
288
+ throw new BSONError(`BSON element "${name}" is missing`);
289
+ } else {
290
+ return null;
291
+ }
292
+ }
293
+
294
+ if (element.value == null) {
295
+ const value = this.toJSValue(element.element, as);
296
+ if (value == null) {
297
+ if (required === true) {
298
+ throw new BSONError(`BSON element "${name}" is missing`);
299
+ } else {
300
+ return null;
301
+ }
302
+ }
303
+ // It is important to never store null
304
+ element.value = value;
305
+ }
306
+
307
+ return element.value;
308
+ }
309
+
310
+ /**
311
+ * Supports returning int, double, long, and bool as javascript numbers
312
+ *
313
+ * @remarks
314
+ * **NOTE:**
315
+ * - Use this _only_ when you believe the potential precision loss of an int64 is acceptable
316
+ * - This method does not cache the result as Longs or booleans would be stored incorrectly
317
+ *
318
+ * @param name - element name
319
+ * @param required - throws if name does not exist
320
+ */
321
+ public getNumber<const Req extends boolean = false>(
322
+ name: string,
323
+ required?: Req
324
+ ): Req extends true ? number : number | null;
325
+ public getNumber(name: string, required: boolean): number | null {
326
+ const maybeBool = this.get(name, BSONType.bool);
327
+ const bool = maybeBool == null ? null : maybeBool ? 1 : 0;
328
+
329
+ const maybeLong = this.get(name, BSONType.long);
330
+ const long = maybeLong == null ? null : Number(maybeLong);
331
+
332
+ const result = bool ?? long ?? this.get(name, BSONType.int) ?? this.get(name, BSONType.double);
333
+
334
+ if (required === true && result == null) {
335
+ throw new BSONError(`BSON element "${name}" is missing`);
336
+ }
337
+
338
+ return result;
339
+ }
340
+
341
+ /**
342
+ * Deserialize this object, DOES NOT cache result so avoid multiple invocations
343
+ * @param options - BSON deserialization options
344
+ */
345
+ public toObject(options?: OnDemandDocumentDeserializeOptions): Record<string, any> {
346
+ return deserialize(this.bson, {
347
+ ...options,
348
+ index: this.offset,
349
+ allowObjectSmallerThanBufferSize: true
350
+ });
351
+ }
352
+
353
+ /** Returns this document's bytes only */
354
+ toBytes() {
355
+ const size = getInt32LE(this.bson, this.offset);
356
+ return this.bson.subarray(this.offset, this.offset + size);
357
+ }
358
+ }