@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,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionPoolClearedEvent = exports.ConnectionCheckedInEvent = exports.ConnectionCheckedOutEvent = exports.ConnectionCheckOutFailedEvent = exports.ConnectionCheckOutStartedEvent = exports.ConnectionClosedEvent = exports.ConnectionReadyEvent = exports.ConnectionCreatedEvent = exports.ConnectionPoolClosedEvent = exports.ConnectionPoolReadyEvent = exports.ConnectionPoolCreatedEvent = exports.ConnectionPoolMonitoringEvent = void 0;
4
+ const constants_1 = require("../constants");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * The base export class for all monitoring events published from the connection pool
8
+ * @public
9
+ * @category Event
10
+ */
11
+ class ConnectionPoolMonitoringEvent {
12
+ /** @internal */
13
+ constructor(pool) {
14
+ this.time = new Date();
15
+ this.address = pool.address;
16
+ }
17
+ }
18
+ exports.ConnectionPoolMonitoringEvent = ConnectionPoolMonitoringEvent;
19
+ /**
20
+ * An event published when a connection pool is created
21
+ * @public
22
+ * @category Event
23
+ */
24
+ class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
25
+ /** @internal */
26
+ constructor(pool) {
27
+ super(pool);
28
+ /** @internal */
29
+ this.name = constants_1.CONNECTION_POOL_CREATED;
30
+ const { maxConnecting, maxPoolSize, minPoolSize, maxIdleTimeMS, waitQueueTimeoutMS } = pool.options;
31
+ this.options = { maxConnecting, maxPoolSize, minPoolSize, maxIdleTimeMS, waitQueueTimeoutMS };
32
+ }
33
+ }
34
+ exports.ConnectionPoolCreatedEvent = ConnectionPoolCreatedEvent;
35
+ /**
36
+ * An event published when a connection pool is ready
37
+ * @public
38
+ * @category Event
39
+ */
40
+ class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
41
+ /** @internal */
42
+ constructor(pool) {
43
+ super(pool);
44
+ /** @internal */
45
+ this.name = constants_1.CONNECTION_POOL_READY;
46
+ }
47
+ }
48
+ exports.ConnectionPoolReadyEvent = ConnectionPoolReadyEvent;
49
+ /**
50
+ * An event published when a connection pool is closed
51
+ * @public
52
+ * @category Event
53
+ */
54
+ class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
55
+ /** @internal */
56
+ constructor(pool) {
57
+ super(pool);
58
+ /** @internal */
59
+ this.name = constants_1.CONNECTION_POOL_CLOSED;
60
+ }
61
+ }
62
+ exports.ConnectionPoolClosedEvent = ConnectionPoolClosedEvent;
63
+ /**
64
+ * An event published when a connection pool creates a new connection
65
+ * @public
66
+ * @category Event
67
+ */
68
+ class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
69
+ /** @internal */
70
+ constructor(pool, connection) {
71
+ super(pool);
72
+ /** @internal */
73
+ this.name = constants_1.CONNECTION_CREATED;
74
+ this.connectionId = connection.id;
75
+ }
76
+ }
77
+ exports.ConnectionCreatedEvent = ConnectionCreatedEvent;
78
+ /**
79
+ * An event published when a connection is ready for use
80
+ * @public
81
+ * @category Event
82
+ */
83
+ class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
84
+ /** @internal */
85
+ constructor(pool, connection, connectionCreatedEventTime) {
86
+ super(pool);
87
+ /** @internal */
88
+ this.name = constants_1.CONNECTION_READY;
89
+ this.durationMS = (0, utils_1.processTimeMS)() - connectionCreatedEventTime;
90
+ this.connectionId = connection.id;
91
+ }
92
+ }
93
+ exports.ConnectionReadyEvent = ConnectionReadyEvent;
94
+ /**
95
+ * An event published when a connection is closed
96
+ * @public
97
+ * @category Event
98
+ */
99
+ class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
100
+ /** @internal */
101
+ constructor(pool, connection, reason, error) {
102
+ super(pool);
103
+ /** @internal */
104
+ this.name = constants_1.CONNECTION_CLOSED;
105
+ this.connectionId = connection.id;
106
+ this.reason = reason;
107
+ this.serviceId = connection.serviceId;
108
+ this.error = error ?? null;
109
+ }
110
+ }
111
+ exports.ConnectionClosedEvent = ConnectionClosedEvent;
112
+ /**
113
+ * An event published when a request to check a connection out begins
114
+ * @public
115
+ * @category Event
116
+ */
117
+ class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
118
+ /** @internal */
119
+ constructor(pool) {
120
+ super(pool);
121
+ /** @internal */
122
+ this.name = constants_1.CONNECTION_CHECK_OUT_STARTED;
123
+ }
124
+ }
125
+ exports.ConnectionCheckOutStartedEvent = ConnectionCheckOutStartedEvent;
126
+ /**
127
+ * An event published when a request to check a connection out fails
128
+ * @public
129
+ * @category Event
130
+ */
131
+ class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
132
+ /** @internal */
133
+ constructor(pool, reason, checkoutTime, error) {
134
+ super(pool);
135
+ /** @internal */
136
+ this.name = constants_1.CONNECTION_CHECK_OUT_FAILED;
137
+ this.durationMS = (0, utils_1.processTimeMS)() - checkoutTime;
138
+ this.reason = reason;
139
+ this.error = error;
140
+ }
141
+ }
142
+ exports.ConnectionCheckOutFailedEvent = ConnectionCheckOutFailedEvent;
143
+ /**
144
+ * An event published when a connection is checked out of the connection pool
145
+ * @public
146
+ * @category Event
147
+ */
148
+ class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
149
+ /** @internal */
150
+ constructor(pool, connection, checkoutTime) {
151
+ super(pool);
152
+ /** @internal */
153
+ this.name = constants_1.CONNECTION_CHECKED_OUT;
154
+ this.durationMS = (0, utils_1.processTimeMS)() - checkoutTime;
155
+ this.connectionId = connection.id;
156
+ }
157
+ }
158
+ exports.ConnectionCheckedOutEvent = ConnectionCheckedOutEvent;
159
+ /**
160
+ * An event published when a connection is checked into the connection pool
161
+ * @public
162
+ * @category Event
163
+ */
164
+ class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
165
+ /** @internal */
166
+ constructor(pool, connection) {
167
+ super(pool);
168
+ /** @internal */
169
+ this.name = constants_1.CONNECTION_CHECKED_IN;
170
+ this.connectionId = connection.id;
171
+ }
172
+ }
173
+ exports.ConnectionCheckedInEvent = ConnectionCheckedInEvent;
174
+ /**
175
+ * An event published when a connection pool is cleared
176
+ * @public
177
+ * @category Event
178
+ */
179
+ class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
180
+ /** @internal */
181
+ constructor(pool, options = {}) {
182
+ super(pool);
183
+ /** @internal */
184
+ this.name = constants_1.CONNECTION_POOL_CLEARED;
185
+ this.serviceId = options.serviceId;
186
+ this.interruptInUseConnections = options.interruptInUseConnections;
187
+ }
188
+ }
189
+ exports.ConnectionPoolClearedEvent = ConnectionPoolClearedEvent;
190
+ //# sourceMappingURL=connection_pool_events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection_pool_events.js","sourceRoot":"","sources":["../../src/cmap/connection_pool_events.ts"],"names":[],"mappings":";;;AACA,4CAYsB;AAEtB,oCAAyC;AAIzC;;;;GAIG;AACH,MAAsB,6BAA6B;IAmBjD,gBAAgB;IAChB,YAAY,IAAoB;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;CACF;AAxBD,sEAwBC;AAED;;;;GAIG;AACH,MAAa,0BAA2B,SAAQ,6BAA6B;IAS3E,gBAAgB;IAChB,YAAY,IAAoB;QAC9B,KAAK,CAAC,IAAI,CAAC,CAAC;QALd,gBAAgB;QAChB,SAAI,GAAG,mCAAuB,CAAC;QAK7B,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,GAClF,IAAI,CAAC,OAAO,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC;IAChG,CAAC;CACF;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IAMzE,gBAAgB;IAChB,YAAY,IAAoB,EAAE,UAAsB;QACtD,KAAK,CAAC,IAAI,CAAC,CAAC;QALd,gBAAgB;QAChB,SAAI,GAAG,iCAAqB,CAAC;QAK3B,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,EAAE,CAAC;IACpC,CAAC;CACF;AAXD,4DAWC;AAED;;;;GAIG;AACH,MAAa,0BAA2B,SAAQ,6BAA6B;IAQ3E,gBAAgB;IAChB,YACE,IAAoB,EACpB,UAAyE,EAAE;QAE3E,KAAK,CAAC,IAAI,CAAC,CAAC;QARd,gBAAgB;QAChB,SAAI,GAAG,mCAAuB,CAAC;QAQ7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,yBAAyB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IACrE,CAAC;CACF;AAjBD,gEAiBC"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WaitQueueTimeoutError = exports.PoolClearedOnNetworkError = exports.PoolClearedError = exports.PoolClosedError = void 0;
4
+ const error_1 = require("../error");
5
+ /**
6
+ * An error indicating a connection pool is closed
7
+ * @category Error
8
+ */
9
+ class PoolClosedError extends error_1.MongoDriverError {
10
+ /**
11
+ * **Do not use this constructor!**
12
+ *
13
+ * Meant for internal use only.
14
+ *
15
+ * @remarks
16
+ * This class is only meant to be constructed within the driver. This constructor is
17
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
18
+ *
19
+ * @public
20
+ **/
21
+ constructor(pool) {
22
+ super('Attempted to check out a connection from closed connection pool');
23
+ this.address = pool.address;
24
+ }
25
+ get name() {
26
+ return 'MongoPoolClosedError';
27
+ }
28
+ }
29
+ exports.PoolClosedError = PoolClosedError;
30
+ /**
31
+ * An error indicating a connection pool is currently paused
32
+ * @category Error
33
+ */
34
+ class PoolClearedError extends error_1.MongoNetworkError {
35
+ /**
36
+ * **Do not use this constructor!**
37
+ *
38
+ * Meant for internal use only.
39
+ *
40
+ * @remarks
41
+ * This class is only meant to be constructed within the driver. This constructor is
42
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
43
+ *
44
+ * @public
45
+ **/
46
+ constructor(pool, message) {
47
+ const errorMessage = message
48
+ ? message
49
+ : `Connection pool for ${pool.address} was cleared because another operation failed with: "${pool.serverError?.message}"`;
50
+ super(errorMessage, pool.serverError ? { cause: pool.serverError } : undefined);
51
+ this.address = pool.address;
52
+ this.addErrorLabel(error_1.MongoErrorLabel.PoolRequestedRetry);
53
+ }
54
+ get name() {
55
+ return 'MongoPoolClearedError';
56
+ }
57
+ }
58
+ exports.PoolClearedError = PoolClearedError;
59
+ /**
60
+ * An error indicating that a connection pool has been cleared after the monitor for that server timed out.
61
+ * @category Error
62
+ */
63
+ class PoolClearedOnNetworkError extends PoolClearedError {
64
+ /**
65
+ * **Do not use this constructor!**
66
+ *
67
+ * Meant for internal use only.
68
+ *
69
+ * @remarks
70
+ * This class is only meant to be constructed within the driver. This constructor is
71
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
72
+ *
73
+ * @public
74
+ **/
75
+ constructor(pool) {
76
+ super(pool, `Connection to ${pool.address} interrupted due to server monitor timeout`);
77
+ }
78
+ get name() {
79
+ return 'PoolClearedOnNetworkError';
80
+ }
81
+ }
82
+ exports.PoolClearedOnNetworkError = PoolClearedOnNetworkError;
83
+ /**
84
+ * An error thrown when a request to check out a connection times out
85
+ * @category Error
86
+ */
87
+ class WaitQueueTimeoutError extends error_1.MongoDriverError {
88
+ /**
89
+ * **Do not use this constructor!**
90
+ *
91
+ * Meant for internal use only.
92
+ *
93
+ * @remarks
94
+ * This class is only meant to be constructed within the driver. This constructor is
95
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
96
+ *
97
+ * @public
98
+ **/
99
+ constructor(message, address) {
100
+ super(message);
101
+ this.address = address;
102
+ }
103
+ get name() {
104
+ return 'MongoWaitQueueTimeoutError';
105
+ }
106
+ }
107
+ exports.WaitQueueTimeoutError = WaitQueueTimeoutError;
108
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/cmap/errors.ts"],"names":[],"mappings":";;;AAAA,oCAAgF;AAGhF;;;GAGG;AACH,MAAa,eAAgB,SAAQ,wBAAgB;IAInD;;;;;;;;;;QAUI;IACJ,YAAY,IAAoB;QAC9B,KAAK,CAAC,iEAAiE,CAAC,CAAC;QACzE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED,IAAa,IAAI;QACf,OAAO,sBAAsB,CAAC;IAChC,CAAC;CACF;AAvBD,0CAuBC;AAED;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,yBAAiB;IAIrD;;;;;;;;;;QAUI;IACJ,YAAY,IAAoB,EAAE,OAAgB;QAChD,MAAM,YAAY,GAAG,OAAO;YAC1B,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,uBAAuB,IAAI,CAAC,OAAO,wDAAwD,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,CAAC;QAC5H,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAE5B,IAAI,CAAC,aAAa,CAAC,uBAAe,CAAC,kBAAkB,CAAC,CAAC;IACzD,CAAC;IAED,IAAa,IAAI;QACf,OAAO,uBAAuB,CAAC;IACjC,CAAC;CACF;AA5BD,4CA4BC;AAED;;;GAGG;AACH,MAAa,yBAA0B,SAAQ,gBAAgB;IAC7D;;;;;;;;;;QAUI;IACJ,YAAY,IAAoB;QAC9B,KAAK,CAAC,IAAI,EAAE,iBAAiB,IAAI,CAAC,OAAO,4CAA4C,CAAC,CAAC;IACzF,CAAC;IAED,IAAa,IAAI;QACf,OAAO,2BAA2B,CAAC;IACrC,CAAC;CACF;AAnBD,8DAmBC;AAED;;;GAGG;AACH,MAAa,qBAAsB,SAAQ,wBAAgB;IAIzD;;;;;;;;;;QAUI;IACJ,YAAY,OAAe,EAAE,OAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAa,IAAI;QACf,OAAO,4BAA4B,CAAC;IACtC,CAAC;CACF;AAvBD,sDAuBC"}
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LimitedSizeDocument = void 0;
4
+ exports.isDriverInfoEqual = isDriverInfoEqual;
5
+ exports.makeClientMetadata = makeClientMetadata;
6
+ exports.getFAASEnv = getFAASEnv;
7
+ const os = require("os");
8
+ const process = require("process");
9
+ const bson_1 = require("../../bson");
10
+ const error_1 = require("../../error");
11
+ const utils_1 = require("../../utils");
12
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
13
+ const NODE_DRIVER_VERSION = require('../../../package.json').version;
14
+ /** @internal */
15
+ function isDriverInfoEqual(info1, info2) {
16
+ /** for equality comparison, we consider "" as unset */
17
+ const nonEmptyCmp = (s1, s2) => {
18
+ s1 ||= undefined;
19
+ s2 ||= undefined;
20
+ return s1 === s2;
21
+ };
22
+ return (nonEmptyCmp(info1.name, info2.name) &&
23
+ nonEmptyCmp(info1.platform, info2.platform) &&
24
+ nonEmptyCmp(info1.version, info2.version));
25
+ }
26
+ /** @internal */
27
+ class LimitedSizeDocument {
28
+ constructor(maxSize) {
29
+ this.document = new Map();
30
+ /** BSON overhead: Int32 + Null byte */
31
+ this.documentSize = 5;
32
+ this.maxSize = maxSize;
33
+ }
34
+ /** Only adds key/value if the bsonByteLength is less than MAX_SIZE */
35
+ ifItFitsItSits(key, value) {
36
+ // The BSON byteLength of the new element is the same as serializing it to its own document
37
+ // subtracting the document size int32 and the null terminator.
38
+ const newElementSize = bson_1.BSON.serialize(new Map().set(key, value)).byteLength - 5;
39
+ if (newElementSize + this.documentSize > this.maxSize) {
40
+ return false;
41
+ }
42
+ this.documentSize += newElementSize;
43
+ this.document.set(key, value);
44
+ return true;
45
+ }
46
+ toObject() {
47
+ return bson_1.BSON.deserialize(bson_1.BSON.serialize(this.document), {
48
+ promoteLongs: false,
49
+ promoteBuffers: false,
50
+ promoteValues: false,
51
+ useBigInt64: false
52
+ });
53
+ }
54
+ }
55
+ exports.LimitedSizeDocument = LimitedSizeDocument;
56
+ /**
57
+ * From the specs:
58
+ * Implementors SHOULD cumulatively update fields in the following order until the document is under the size limit:
59
+ * 1. Omit fields from `env` except `env.name`.
60
+ * 2. Omit fields from `os` except `os.type`.
61
+ * 3. Omit the `env` document entirely.
62
+ * 4. Truncate `platform`. -- special we do not truncate this field
63
+ */
64
+ async function makeClientMetadata(driverInfoList, { appName = '' }) {
65
+ const metadataDocument = new LimitedSizeDocument(512);
66
+ // Add app name first, it must be sent
67
+ if (appName.length > 0) {
68
+ const name = Buffer.byteLength(appName, 'utf8') <= 128
69
+ ? appName
70
+ : Buffer.from(appName, 'utf8').subarray(0, 128).toString('utf8');
71
+ metadataDocument.ifItFitsItSits('application', { name });
72
+ }
73
+ const driverInfo = {
74
+ name: 'nodejs',
75
+ version: NODE_DRIVER_VERSION
76
+ };
77
+ // This is where we handle additional driver info added after client construction.
78
+ for (const { name: n = '', version: v = '' } of driverInfoList) {
79
+ if (n.length > 0) {
80
+ driverInfo.name = `${driverInfo.name}|${n}`;
81
+ }
82
+ if (v.length > 0) {
83
+ driverInfo.version = `${driverInfo.version}|${v}`;
84
+ }
85
+ }
86
+ if (!metadataDocument.ifItFitsItSits('driver', driverInfo)) {
87
+ throw new error_1.MongoInvalidArgumentError('Unable to include driverInfo name and version, metadata cannot exceed 512 bytes');
88
+ }
89
+ let runtimeInfo = getRuntimeInfo();
90
+ // This is where we handle additional driver info added after client construction.
91
+ for (const { platform = '' } of driverInfoList) {
92
+ if (platform.length > 0) {
93
+ runtimeInfo = `${runtimeInfo}|${platform}`;
94
+ }
95
+ }
96
+ if (!metadataDocument.ifItFitsItSits('platform', runtimeInfo)) {
97
+ throw new error_1.MongoInvalidArgumentError('Unable to include driverInfo platform, metadata cannot exceed 512 bytes');
98
+ }
99
+ // Note: order matters, os.type is last so it will be removed last if we're at maxSize
100
+ const osInfo = new Map()
101
+ .set('name', os.platform())
102
+ .set('architecture', os.arch())
103
+ .set('version', os.release())
104
+ .set('type', os.type());
105
+ if (!metadataDocument.ifItFitsItSits('os', osInfo)) {
106
+ for (const key of osInfo.keys()) {
107
+ osInfo.delete(key);
108
+ if (osInfo.size === 0)
109
+ break;
110
+ if (metadataDocument.ifItFitsItSits('os', osInfo))
111
+ break;
112
+ }
113
+ }
114
+ const faasEnv = getFAASEnv();
115
+ if (faasEnv != null) {
116
+ if (!metadataDocument.ifItFitsItSits('env', faasEnv)) {
117
+ for (const key of faasEnv.keys()) {
118
+ faasEnv.delete(key);
119
+ if (faasEnv.size === 0)
120
+ break;
121
+ if (metadataDocument.ifItFitsItSits('env', faasEnv))
122
+ break;
123
+ }
124
+ }
125
+ }
126
+ return await addContainerMetadata(metadataDocument.toObject());
127
+ }
128
+ let dockerPromise;
129
+ /** @internal */
130
+ async function getContainerMetadata() {
131
+ dockerPromise ??= (0, utils_1.fileIsAccessible)('/.dockerenv');
132
+ const isDocker = await dockerPromise;
133
+ const { KUBERNETES_SERVICE_HOST = '' } = process.env;
134
+ const isKubernetes = KUBERNETES_SERVICE_HOST.length > 0 ? true : false;
135
+ const containerMetadata = {};
136
+ if (isDocker)
137
+ containerMetadata.runtime = 'docker';
138
+ if (isKubernetes)
139
+ containerMetadata.orchestrator = 'kubernetes';
140
+ return containerMetadata;
141
+ }
142
+ /**
143
+ * @internal
144
+ * Re-add each metadata value.
145
+ * Attempt to add new env container metadata, but keep old data if it does not fit.
146
+ */
147
+ async function addContainerMetadata(originalMetadata) {
148
+ const containerMetadata = await getContainerMetadata();
149
+ if (Object.keys(containerMetadata).length === 0)
150
+ return originalMetadata;
151
+ const extendedMetadata = new LimitedSizeDocument(512);
152
+ const extendedEnvMetadata = {
153
+ ...originalMetadata?.env,
154
+ container: containerMetadata
155
+ };
156
+ for (const [key, val] of Object.entries(originalMetadata)) {
157
+ if (key !== 'env') {
158
+ extendedMetadata.ifItFitsItSits(key, val);
159
+ }
160
+ else {
161
+ if (!extendedMetadata.ifItFitsItSits('env', extendedEnvMetadata)) {
162
+ // add in old data if newer / extended metadata does not fit
163
+ extendedMetadata.ifItFitsItSits('env', val);
164
+ }
165
+ }
166
+ }
167
+ if (!('env' in originalMetadata)) {
168
+ extendedMetadata.ifItFitsItSits('env', extendedEnvMetadata);
169
+ }
170
+ return extendedMetadata.toObject();
171
+ }
172
+ /**
173
+ * Collects FaaS metadata.
174
+ * - `name` MUST be the last key in the Map returned.
175
+ */
176
+ function getFAASEnv() {
177
+ const { AWS_EXECUTION_ENV = '', AWS_LAMBDA_RUNTIME_API = '', FUNCTIONS_WORKER_RUNTIME = '', K_SERVICE = '', FUNCTION_NAME = '', VERCEL = '', AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '', AWS_REGION = '', FUNCTION_MEMORY_MB = '', FUNCTION_REGION = '', FUNCTION_TIMEOUT_SEC = '', VERCEL_REGION = '' } = process.env;
178
+ const isAWSFaaS = AWS_EXECUTION_ENV.startsWith('AWS_Lambda_') || AWS_LAMBDA_RUNTIME_API.length > 0;
179
+ const isAzureFaaS = FUNCTIONS_WORKER_RUNTIME.length > 0;
180
+ const isGCPFaaS = K_SERVICE.length > 0 || FUNCTION_NAME.length > 0;
181
+ const isVercelFaaS = VERCEL.length > 0;
182
+ // Note: order matters, name must always be the last key
183
+ const faasEnv = new Map();
184
+ // When isVercelFaaS is true so is isAWSFaaS; Vercel inherits the AWS env
185
+ if (isVercelFaaS && !(isAzureFaaS || isGCPFaaS)) {
186
+ if (VERCEL_REGION.length > 0) {
187
+ faasEnv.set('region', VERCEL_REGION);
188
+ }
189
+ faasEnv.set('name', 'vercel');
190
+ return faasEnv;
191
+ }
192
+ if (isAWSFaaS && !(isAzureFaaS || isGCPFaaS || isVercelFaaS)) {
193
+ if (AWS_REGION.length > 0) {
194
+ faasEnv.set('region', AWS_REGION);
195
+ }
196
+ if (AWS_LAMBDA_FUNCTION_MEMORY_SIZE.length > 0 &&
197
+ Number.isInteger(+AWS_LAMBDA_FUNCTION_MEMORY_SIZE)) {
198
+ faasEnv.set('memory_mb', new bson_1.Int32(AWS_LAMBDA_FUNCTION_MEMORY_SIZE));
199
+ }
200
+ faasEnv.set('name', 'aws.lambda');
201
+ return faasEnv;
202
+ }
203
+ if (isAzureFaaS && !(isGCPFaaS || isAWSFaaS || isVercelFaaS)) {
204
+ faasEnv.set('name', 'azure.func');
205
+ return faasEnv;
206
+ }
207
+ if (isGCPFaaS && !(isAzureFaaS || isAWSFaaS || isVercelFaaS)) {
208
+ if (FUNCTION_REGION.length > 0) {
209
+ faasEnv.set('region', FUNCTION_REGION);
210
+ }
211
+ if (FUNCTION_MEMORY_MB.length > 0 && Number.isInteger(+FUNCTION_MEMORY_MB)) {
212
+ faasEnv.set('memory_mb', new bson_1.Int32(FUNCTION_MEMORY_MB));
213
+ }
214
+ if (FUNCTION_TIMEOUT_SEC.length > 0 && Number.isInteger(+FUNCTION_TIMEOUT_SEC)) {
215
+ faasEnv.set('timeout_sec', new bson_1.Int32(FUNCTION_TIMEOUT_SEC));
216
+ }
217
+ faasEnv.set('name', 'gcp.func');
218
+ return faasEnv;
219
+ }
220
+ return null;
221
+ }
222
+ /**
223
+ * @internal
224
+ * Get current JavaScript runtime platform
225
+ *
226
+ * NOTE: The version information fetching is intentionally written defensively
227
+ * to avoid having a released driver version that becomes incompatible
228
+ * with a future change to these global objects.
229
+ */
230
+ function getRuntimeInfo() {
231
+ const endianness = bson_1.NumberUtils.isBigEndian ? 'BE' : 'LE';
232
+ if ('Deno' in globalThis) {
233
+ const version = typeof Deno?.version?.deno === 'string' ? Deno?.version?.deno : '0.0.0-unknown';
234
+ return `Deno v${version}, ${endianness}`;
235
+ }
236
+ if ('Bun' in globalThis) {
237
+ const version = typeof Bun?.version === 'string' ? Bun?.version : '0.0.0-unknown';
238
+ return `Bun v${version}, ${endianness}`;
239
+ }
240
+ return `Node.js ${process.version}, ${endianness}`;
241
+ }
242
+ //# sourceMappingURL=client_metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client_metadata.js","sourceRoot":"","sources":["../../../src/cmap/handshake/client_metadata.ts"],"names":[],"mappings":";;;AAYA,8CAcC;AAiFD,gDA4EC;AA0DD,gCA0EC;AA3TD,yBAAyB;AACzB,mCAAmC;AAEnC,qCAAqE;AACrE,uCAAwD;AAExD,uCAA+C;AAE/C,iEAAiE;AACjE,MAAM,mBAAmB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC,OAAO,CAAC;AAErE,gBAAgB;AAChB,SAAgB,iBAAiB,CAAC,KAAiB,EAAE,KAAiB;IACpE,uDAAuD;IACvD,MAAM,WAAW,GAAG,CAAC,EAAsB,EAAE,EAAsB,EAAW,EAAE;QAC9E,EAAE,KAAK,SAAS,CAAC;QACjB,EAAE,KAAK,SAAS,CAAC;QAEjB,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,CACL,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC;QACnC,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;QAC3C,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAC1C,CAAC;AACJ,CAAC;AAkCD,gBAAgB;AAChB,MAAa,mBAAmB;IAM9B,YAAY,OAAe;QALnB,aAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,uCAAuC;QAC/B,iBAAY,GAAG,CAAC,CAAC;QAIvB,IAAI,CAAC,OAAO,GAAG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AAoB,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAC/E,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,YAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAcD;;;;;;;GAOG;AACH,SAAS,cAAc;IACrB,MAAM,UAAU,GAAG,kBAAW,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACzD,IAAI,MAAM,IAAI,UAAU,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,OAAO,IAAI,EAAE,OAAO,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC;QAEhG,OAAO,SAAS,OAAO,KAAK,UAAU,EAAE,CAAC;IAC3C,CAAC;IAED,IAAI,KAAK,IAAI,UAAU,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,OAAO,GAAG,EAAE,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QAElF,OAAO,QAAQ,OAAO,KAAK,UAAU,EAAE,CAAC;IAC1C,CAAC;IAED,OAAO,WAAW,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionPoolMetrics = void 0;
4
+ /** @internal */
5
+ class ConnectionPoolMetrics {
6
+ constructor() {
7
+ this.txnConnections = 0;
8
+ this.cursorConnections = 0;
9
+ this.otherConnections = 0;
10
+ }
11
+ static { this.TXN = 'txn'; }
12
+ static { this.CURSOR = 'cursor'; }
13
+ static { this.OTHER = 'other'; }
14
+ /**
15
+ * Mark a connection as pinned for a specific operation.
16
+ */
17
+ markPinned(pinType) {
18
+ if (pinType === ConnectionPoolMetrics.TXN) {
19
+ this.txnConnections += 1;
20
+ }
21
+ else if (pinType === ConnectionPoolMetrics.CURSOR) {
22
+ this.cursorConnections += 1;
23
+ }
24
+ else {
25
+ this.otherConnections += 1;
26
+ }
27
+ }
28
+ /**
29
+ * Unmark a connection as pinned for an operation.
30
+ */
31
+ markUnpinned(pinType) {
32
+ if (pinType === ConnectionPoolMetrics.TXN) {
33
+ this.txnConnections -= 1;
34
+ }
35
+ else if (pinType === ConnectionPoolMetrics.CURSOR) {
36
+ this.cursorConnections -= 1;
37
+ }
38
+ else {
39
+ this.otherConnections -= 1;
40
+ }
41
+ }
42
+ /**
43
+ * Return information about the cmap metrics as a string.
44
+ */
45
+ info(maxPoolSize) {
46
+ return ('Timed out while checking out a connection from connection pool: ' +
47
+ `maxPoolSize: ${maxPoolSize}, ` +
48
+ `connections in use by cursors: ${this.cursorConnections}, ` +
49
+ `connections in use by transactions: ${this.txnConnections}, ` +
50
+ `connections in use by other operations: ${this.otherConnections}`);
51
+ }
52
+ /**
53
+ * Reset the metrics to the initial values.
54
+ */
55
+ reset() {
56
+ this.txnConnections = 0;
57
+ this.cursorConnections = 0;
58
+ this.otherConnections = 0;
59
+ }
60
+ }
61
+ exports.ConnectionPoolMetrics = ConnectionPoolMetrics;
62
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/cmap/metrics.ts"],"names":[],"mappings":";;;AAAA,gBAAgB;AAChB,MAAa,qBAAqB;IAAlC;QAKE,mBAAc,GAAG,CAAC,CAAC;QACnB,sBAAiB,GAAG,CAAC,CAAC;QACtB,qBAAgB,GAAG,CAAC,CAAC;IAiDvB,CAAC;aAvDiB,QAAG,GAAG,K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