@nullix/zod-mongoose-studio 1.0.13 → 2.1.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 (268) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/_nuxt/builds/latest.json +1 -1
  3. package/.output/public/_nuxt/builds/meta/8b851c04-1848-472a-b5cd-0727aaaf90f4.json +1 -0
  4. package/.output/server/chunks/nitro/nitro.mjs +232 -232
  5. package/.output/server/chunks/routes/api/parse.post.mjs +54 -11
  6. package/.output/server/chunks/routes/api/parse.post.mjs.map +1 -1
  7. package/.output/server/node_modules/bson/lib/bson.cjs +157 -48
  8. package/.output/server/node_modules/bson/package.json +9 -11
  9. package/.output/server/node_modules/kareem/index.js +228 -343
  10. package/.output/server/node_modules/kareem/package.json +3 -3
  11. package/.output/server/node_modules/mongodb/lib/bson.js +27 -5
  12. package/.output/server/node_modules/mongodb/lib/bulk/common.js +7 -9
  13. package/.output/server/node_modules/mongodb/lib/change_stream.js +91 -39
  14. package/.output/server/node_modules/mongodb/lib/client-side-encryption/auto_encrypter.js +21 -14
  15. package/.output/server/node_modules/mongodb/lib/client-side-encryption/client_encryption.js +2 -5
  16. package/.output/server/node_modules/mongodb/lib/client-side-encryption/errors.js +3 -1
  17. package/.output/server/node_modules/mongodb/lib/client-side-encryption/mongocryptd_manager.js +1 -1
  18. package/.output/server/node_modules/mongodb/lib/client-side-encryption/state_machine.js +1 -0
  19. package/.output/server/node_modules/mongodb/lib/cmap/auth/aws4.js +161 -0
  20. package/.output/server/node_modules/mongodb/lib/cmap/auth/aws_temporary_credentials.js +11 -58
  21. package/.output/server/node_modules/mongodb/lib/cmap/auth/gssapi.js +4 -6
  22. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongo_credentials.js +2 -16
  23. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_aws.js +14 -23
  24. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +3 -3
  25. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +3 -3
  26. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +4 -3
  27. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +4 -3
  28. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc.js +4 -4
  29. package/.output/server/node_modules/mongodb/lib/cmap/auth/plain.js +1 -1
  30. package/.output/server/node_modules/mongodb/lib/cmap/auth/providers.js +0 -1
  31. package/.output/server/node_modules/mongodb/lib/cmap/auth/scram.js +53 -40
  32. package/.output/server/node_modules/mongodb/lib/cmap/commands.js +46 -39
  33. package/.output/server/node_modules/mongodb/lib/cmap/connect.js +35 -3
  34. package/.output/server/node_modules/mongodb/lib/cmap/connection.js +36 -32
  35. package/.output/server/node_modules/mongodb/lib/cmap/connection_pool.js +67 -67
  36. package/.output/server/node_modules/mongodb/lib/cmap/connection_pool_events.js +3 -3
  37. package/.output/server/node_modules/mongodb/lib/cmap/errors.js +1 -1
  38. package/.output/server/node_modules/mongodb/lib/cmap/handshake/client_metadata.js +15 -13
  39. package/.output/server/node_modules/mongodb/lib/cmap/metrics.js +3 -3
  40. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/compression.js +26 -10
  41. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/constants.js +3 -1
  42. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_data.js +0 -1
  43. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_demand/document.js +9 -9
  44. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/responses.js +2 -2
  45. package/.output/server/node_modules/mongodb/lib/collection.js +1 -1
  46. package/.output/server/node_modules/mongodb/lib/connection_string.js +30 -15
  47. package/.output/server/node_modules/mongodb/lib/cursor/abstract_cursor.js +17 -34
  48. package/.output/server/node_modules/mongodb/lib/cursor/change_stream_cursor.js +2 -2
  49. package/.output/server/node_modules/mongodb/lib/cursor/find_cursor.js +37 -26
  50. package/.output/server/node_modules/mongodb/lib/cursor/run_command_cursor.js +1 -1
  51. package/.output/server/node_modules/mongodb/lib/db.js +6 -7
  52. package/.output/server/node_modules/mongodb/lib/deps.js +0 -13
  53. package/.output/server/node_modules/mongodb/lib/error.js +7 -10
  54. package/.output/server/node_modules/mongodb/lib/gridfs/download.js +7 -6
  55. package/.output/server/node_modules/mongodb/lib/gridfs/index.js +9 -9
  56. package/.output/server/node_modules/mongodb/lib/gridfs/upload.js +17 -23
  57. package/.output/server/node_modules/mongodb/lib/index.js +2 -4
  58. package/.output/server/node_modules/mongodb/lib/mongo_client.js +58 -67
  59. package/.output/server/node_modules/mongodb/lib/mongo_client_auth_providers.js +0 -6
  60. package/.output/server/node_modules/mongodb/lib/mongo_logger.js +11 -5
  61. package/.output/server/node_modules/mongodb/lib/mongo_types.js +1 -2
  62. package/.output/server/node_modules/mongodb/lib/operations/aggregate.js +0 -3
  63. package/.output/server/node_modules/mongodb/lib/operations/create_collection.js +0 -1
  64. package/.output/server/node_modules/mongodb/lib/operations/drop.js +8 -9
  65. package/.output/server/node_modules/mongodb/lib/operations/end_sessions.js +34 -0
  66. package/.output/server/node_modules/mongodb/lib/operations/execute_operation.js +121 -45
  67. package/.output/server/node_modules/mongodb/lib/operations/operation.js +1 -0
  68. package/.output/server/node_modules/mongodb/lib/read_preference.js +10 -14
  69. package/.output/server/node_modules/mongodb/lib/runtime_adapters.js +32 -0
  70. package/.output/server/node_modules/mongodb/lib/sdam/monitor.js +8 -8
  71. package/.output/server/node_modules/mongodb/lib/sdam/server.js +55 -43
  72. package/.output/server/node_modules/mongodb/lib/sdam/server_description.js +1 -1
  73. package/.output/server/node_modules/mongodb/lib/sdam/server_selection.js +135 -72
  74. package/.output/server/node_modules/mongodb/lib/sdam/srv_polling.js +3 -3
  75. package/.output/server/node_modules/mongodb/lib/sdam/topology.js +37 -77
  76. package/.output/server/node_modules/mongodb/lib/sdam/topology_description.js +1 -1
  77. package/.output/server/node_modules/mongodb/lib/sessions.js +150 -40
  78. package/.output/server/node_modules/mongodb/lib/transactions.js +2 -13
  79. package/.output/server/node_modules/mongodb/lib/utils.js +42 -90
  80. package/.output/server/node_modules/mongodb/package.json +49 -45
  81. package/.output/server/node_modules/mongodb-connection-string-url/lib/index.js +45 -19
  82. package/.output/server/node_modules/mongodb-connection-string-url/lib/redact.js +30 -19
  83. package/.output/server/node_modules/mongodb-connection-string-url/package.json +25 -16
  84. package/.output/server/node_modules/mongoose/lib/aggregate.js +108 -127
  85. package/.output/server/node_modules/mongoose/lib/cast/bigint.js +3 -3
  86. package/.output/server/node_modules/mongoose/lib/cast/boolean.js +3 -3
  87. package/.output/server/node_modules/mongoose/lib/cast/double.js +4 -4
  88. package/.output/server/node_modules/mongoose/lib/cast/int32.js +2 -2
  89. package/.output/server/node_modules/mongoose/lib/cast/number.js +6 -6
  90. package/.output/server/node_modules/mongoose/lib/cast/string.js +3 -3
  91. package/.output/server/node_modules/mongoose/lib/cast/uuid.js +5 -48
  92. package/.output/server/node_modules/mongoose/lib/cast.js +16 -24
  93. package/.output/server/node_modules/mongoose/lib/collection.js +6 -6
  94. package/.output/server/node_modules/mongoose/lib/connection.js +108 -105
  95. package/.output/server/node_modules/mongoose/lib/cursor/aggregationCursor.js +23 -33
  96. package/.output/server/node_modules/mongoose/lib/cursor/changeStream.js +60 -40
  97. package/.output/server/node_modules/mongoose/lib/cursor/queryCursor.js +21 -25
  98. package/.output/server/node_modules/mongoose/lib/document.js +712 -531
  99. package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js +85 -130
  100. package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js +32 -41
  101. package/.output/server/node_modules/mongoose/lib/error/cast.js +21 -12
  102. package/.output/server/node_modules/mongoose/lib/error/createCollectionsError.js +2 -2
  103. package/.output/server/node_modules/mongoose/lib/error/divergentArray.js +1 -1
  104. package/.output/server/node_modules/mongoose/lib/error/eachAsyncMultiError.js +1 -1
  105. package/.output/server/node_modules/mongoose/lib/error/index.js +3 -3
  106. package/.output/server/node_modules/mongoose/lib/error/invalidSchemaOption.js +1 -1
  107. package/.output/server/node_modules/mongoose/lib/error/messages.js +1 -0
  108. package/.output/server/node_modules/mongoose/lib/error/missingSchema.js +1 -1
  109. package/.output/server/node_modules/mongoose/lib/error/objectParameter.js +4 -5
  110. package/.output/server/node_modules/mongoose/lib/error/overwriteModel.js +1 -1
  111. package/.output/server/node_modules/mongoose/lib/error/setOptionError.js +3 -3
  112. package/.output/server/node_modules/mongoose/lib/error/strict.js +3 -3
  113. package/.output/server/node_modules/mongoose/lib/error/strictPopulate.js +2 -2
  114. package/.output/server/node_modules/mongoose/lib/error/syncIndexes.js +2 -2
  115. package/.output/server/node_modules/mongoose/lib/error/validation.js +2 -10
  116. package/.output/server/node_modules/mongoose/lib/error/validator.js +1 -1
  117. package/.output/server/node_modules/mongoose/lib/error/version.js +2 -2
  118. package/.output/server/node_modules/mongoose/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
  119. package/.output/server/node_modules/mongoose/lib/helpers/buildMiddlewareFilter.js +24 -0
  120. package/.output/server/node_modules/mongoose/lib/helpers/clone.js +35 -18
  121. package/.output/server/node_modules/mongoose/lib/helpers/common.js +5 -5
  122. package/.output/server/node_modules/mongoose/lib/helpers/cursor/eachAsync.js +4 -4
  123. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getConstructor.js +1 -1
  124. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  125. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
  126. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js +10 -5
  127. package/.output/server/node_modules/mongoose/lib/helpers/document/applyDefaults.js +1 -1
  128. package/.output/server/node_modules/mongoose/lib/helpers/document/applyTimestamps.js +11 -10
  129. package/.output/server/node_modules/mongoose/lib/helpers/document/applyVirtuals.js +10 -9
  130. package/.output/server/node_modules/mongoose/lib/helpers/document/cleanModifiedSubpaths.js +1 -1
  131. package/.output/server/node_modules/mongoose/lib/helpers/document/compile.js +17 -14
  132. package/.output/server/node_modules/mongoose/lib/helpers/document/getDeepestSubdocumentForPath.js +3 -3
  133. package/.output/server/node_modules/mongoose/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
  134. package/.output/server/node_modules/mongoose/lib/helpers/document/isInPathsToSave.js +24 -0
  135. package/.output/server/node_modules/mongoose/lib/helpers/get.js +1 -1
  136. package/.output/server/node_modules/mongoose/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
  137. package/.output/server/node_modules/mongoose/lib/helpers/indexes/getRelatedIndexes.js +3 -3
  138. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexEqual.js +3 -4
  139. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
  140. package/.output/server/node_modules/mongoose/lib/helpers/isBsonType.js +1 -1
  141. package/.output/server/node_modules/mongoose/lib/helpers/isMongooseObject.js +1 -1
  142. package/.output/server/node_modules/mongoose/lib/helpers/isObject.js +2 -2
  143. package/.output/server/node_modules/mongoose/lib/helpers/isSimpleValidator.js +2 -2
  144. package/.output/server/node_modules/mongoose/lib/helpers/minimize.js +2 -2
  145. package/.output/server/node_modules/mongoose/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
  146. package/.output/server/node_modules/mongoose/lib/helpers/model/applyHooks.js +55 -54
  147. package/.output/server/node_modules/mongoose/lib/helpers/model/applyMethods.js +2 -2
  148. package/.output/server/node_modules/mongoose/lib/helpers/model/applyStaticHooks.js +1 -48
  149. package/.output/server/node_modules/mongoose/lib/helpers/model/castBulkWrite.js +8 -12
  150. package/.output/server/node_modules/mongoose/lib/helpers/model/discriminator.js +1 -1
  151. package/.output/server/node_modules/mongoose/lib/helpers/parallelLimit.js +18 -36
  152. package/.output/server/node_modules/mongoose/lib/helpers/pluralize.js +4 -4
  153. package/.output/server/node_modules/mongoose/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -11
  154. package/.output/server/node_modules/mongoose/lib/helpers/populate/assignVals.js +10 -10
  155. package/.output/server/node_modules/mongoose/lib/helpers/populate/createPopulateQueryFilter.js +3 -3
  156. package/.output/server/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js +197 -69
  157. package/.output/server/node_modules/mongoose/lib/helpers/populate/getSchemaTypes.js +15 -15
  158. package/.output/server/node_modules/mongoose/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  159. package/.output/server/node_modules/mongoose/lib/helpers/populate/modelNamesFromRefPath.js +10 -2
  160. package/.output/server/node_modules/mongoose/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
  161. package/.output/server/node_modules/mongoose/lib/helpers/printJestWarning.js +1 -1
  162. package/.output/server/node_modules/mongoose/lib/helpers/processConnectionOptions.js +1 -1
  163. package/.output/server/node_modules/mongoose/lib/helpers/projection/hasIncludedChildren.js +1 -1
  164. package/.output/server/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js +3 -3
  165. package/.output/server/node_modules/mongoose/lib/helpers/projection/isSubpath.js +1 -1
  166. package/.output/server/node_modules/mongoose/lib/helpers/projection/parseProjection.js +9 -4
  167. package/.output/server/node_modules/mongoose/lib/helpers/query/cast$expr.js +8 -10
  168. package/.output/server/node_modules/mongoose/lib/helpers/query/castFilterPath.js +1 -1
  169. package/.output/server/node_modules/mongoose/lib/helpers/query/castUpdate.js +44 -38
  170. package/.output/server/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js +8 -8
  171. package/.output/server/node_modules/mongoose/lib/helpers/query/handleImmutable.js +8 -8
  172. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyPlugins.js +2 -2
  173. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyReadConcern.js +1 -1
  174. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyWriteConcern.js +4 -2
  175. package/.output/server/node_modules/mongoose/lib/helpers/schema/getIndexes.js +5 -11
  176. package/.output/server/node_modules/mongoose/lib/helpers/schema/getSubdocumentStrictValue.js +2 -2
  177. package/.output/server/node_modules/mongoose/lib/helpers/schema/handleIdOption.js +1 -1
  178. package/.output/server/node_modules/mongoose/lib/helpers/schema/idGetter.js +1 -1
  179. package/.output/server/node_modules/mongoose/lib/helpers/schematype/handleImmutable.js +1 -1
  180. package/.output/server/node_modules/mongoose/lib/helpers/setDefaultsOnInsert.js +26 -13
  181. package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
  182. package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setupTimestamps.js +60 -38
  183. package/.output/server/node_modules/mongoose/lib/helpers/update/applyTimestampsToUpdate.js +13 -10
  184. package/.output/server/node_modules/mongoose/lib/helpers/update/castArrayFilters.js +4 -4
  185. package/.output/server/node_modules/mongoose/lib/helpers/update/decorateUpdateWithVersionKey.js +1 -1
  186. package/.output/server/node_modules/mongoose/lib/helpers/update/modifiedPaths.js +2 -2
  187. package/.output/server/node_modules/mongoose/lib/helpers/update/removeUnusedArrayFilters.js +7 -2
  188. package/.output/server/node_modules/mongoose/lib/helpers/updateValidators.js +58 -119
  189. package/.output/server/node_modules/mongoose/lib/model.js +940 -946
  190. package/.output/server/node_modules/mongoose/lib/mongoose.js +131 -79
  191. package/.output/server/node_modules/mongoose/lib/options/schemaArrayOptions.js +2 -2
  192. package/.output/server/node_modules/mongoose/lib/options/schemaBufferOptions.js +1 -1
  193. package/.output/server/node_modules/mongoose/lib/options/schemaDocumentArrayOptions.js +23 -0
  194. package/.output/server/node_modules/mongoose/lib/options/schemaNumberOptions.js +3 -3
  195. package/.output/server/node_modules/mongoose/lib/options/schemaObjectIdOptions.js +2 -2
  196. package/.output/server/node_modules/mongoose/lib/options/schemaStringOptions.js +6 -6
  197. package/.output/server/node_modules/mongoose/lib/options/schemaSubdocumentOptions.js +23 -0
  198. package/.output/server/node_modules/mongoose/lib/options/schemaTypeOptions.js +27 -13
  199. package/.output/server/node_modules/mongoose/lib/options/virtualOptions.js +12 -12
  200. package/.output/server/node_modules/mongoose/lib/plugins/index.js +0 -1
  201. package/.output/server/node_modules/mongoose/lib/plugins/saveSubdocs.js +84 -92
  202. package/.output/server/node_modules/mongoose/lib/plugins/sharding.js +33 -15
  203. package/.output/server/node_modules/mongoose/lib/plugins/trackTransaction.js +29 -25
  204. package/.output/server/node_modules/mongoose/lib/query.js +700 -548
  205. package/.output/server/node_modules/mongoose/lib/queryHelpers.js +34 -32
  206. package/.output/server/node_modules/mongoose/lib/schema/array.js +69 -113
  207. package/.output/server/node_modules/mongoose/lib/schema/bigint.js +18 -20
  208. package/.output/server/node_modules/mongoose/lib/schema/boolean.js +20 -22
  209. package/.output/server/node_modules/mongoose/lib/schema/buffer.js +23 -25
  210. package/.output/server/node_modules/mongoose/lib/schema/date.js +19 -21
  211. package/.output/server/node_modules/mongoose/lib/schema/decimal128.js +16 -18
  212. package/.output/server/node_modules/mongoose/lib/schema/documentArray.js +94 -131
  213. package/.output/server/node_modules/mongoose/lib/schema/documentArrayElement.js +50 -16
  214. package/.output/server/node_modules/mongoose/lib/schema/double.js +16 -18
  215. package/.output/server/node_modules/mongoose/lib/schema/index.js +1 -0
  216. package/.output/server/node_modules/mongoose/lib/schema/int32.js +17 -19
  217. package/.output/server/node_modules/mongoose/lib/schema/map.js +17 -24
  218. package/.output/server/node_modules/mongoose/lib/schema/mixed.js +14 -14
  219. package/.output/server/node_modules/mongoose/lib/schema/number.js +38 -28
  220. package/.output/server/node_modules/mongoose/lib/schema/objectId.js +18 -20
  221. package/.output/server/node_modules/mongoose/lib/schema/operators/exists.js +1 -1
  222. package/.output/server/node_modules/mongoose/lib/schema/operators/geospatial.js +1 -1
  223. package/.output/server/node_modules/mongoose/lib/schema/operators/text.js +4 -4
  224. package/.output/server/node_modules/mongoose/lib/schema/string.js +42 -27
  225. package/.output/server/node_modules/mongoose/lib/schema/subdocument.js +47 -58
  226. package/.output/server/node_modules/mongoose/lib/schema/union.js +54 -4
  227. package/.output/server/node_modules/mongoose/lib/schema/uuid.js +17 -40
  228. package/.output/server/node_modules/mongoose/lib/schema.js +235 -176
  229. package/.output/server/node_modules/mongoose/lib/schemaType.js +227 -158
  230. package/.output/server/node_modules/mongoose/lib/stateMachine.js +5 -8
  231. package/.output/server/node_modules/mongoose/lib/types/array/index.js +5 -5
  232. package/.output/server/node_modules/mongoose/lib/types/array/methods/index.js +27 -28
  233. package/.output/server/node_modules/mongoose/lib/types/arraySubdocument.js +11 -11
  234. package/.output/server/node_modules/mongoose/lib/types/buffer.js +15 -15
  235. package/.output/server/node_modules/mongoose/lib/types/decimal128.js +1 -1
  236. package/.output/server/node_modules/mongoose/lib/types/documentArray/index.js +4 -4
  237. package/.output/server/node_modules/mongoose/lib/types/documentArray/methods/index.js +15 -13
  238. package/.output/server/node_modules/mongoose/lib/types/double.js +1 -1
  239. package/.output/server/node_modules/mongoose/lib/types/map.js +20 -71
  240. package/.output/server/node_modules/mongoose/lib/types/objectid.js +1 -1
  241. package/.output/server/node_modules/mongoose/lib/types/subdocument.js +32 -81
  242. package/.output/server/node_modules/mongoose/lib/types/uuid.js +1 -1
  243. package/.output/server/node_modules/mongoose/lib/utils.js +91 -70
  244. package/.output/server/node_modules/mongoose/lib/validOptions.js +4 -3
  245. package/.output/server/node_modules/mongoose/lib/virtualType.js +18 -18
  246. package/.output/server/node_modules/mongoose/package.json +46 -63
  247. package/.output/server/node_modules/mquery/lib/collection/collection.js +3 -1
  248. package/.output/server/node_modules/mquery/lib/collection/node.js +17 -3
  249. package/.output/server/node_modules/mquery/lib/mquery.js +136 -93
  250. package/.output/server/node_modules/mquery/lib/permissions.js +21 -6
  251. package/.output/server/node_modules/mquery/package.json +4 -7
  252. package/.output/server/package.json +7 -9
  253. package/package.json +3 -3
  254. package/.output/public/_nuxt/builds/meta/0d6006db-fbb0-4297-85cf-bf92ceafcb79.json +0 -1
  255. package/.output/server/node_modules/debug/package.json +0 -64
  256. package/.output/server/node_modules/debug/src/browser.js +0 -272
  257. package/.output/server/node_modules/debug/src/common.js +0 -292
  258. package/.output/server/node_modules/debug/src/index.js +0 -10
  259. package/.output/server/node_modules/debug/src/node.js +0 -263
  260. package/.output/server/node_modules/mongodb/lib/client-side-encryption/crypto_callbacks.js +0 -81
  261. package/.output/server/node_modules/mongodb/lib/resource_management.js +0 -58
  262. package/.output/server/node_modules/mongoose/lib/browserDocument.js +0 -101
  263. package/.output/server/node_modules/mongoose/lib/documentProvider.js +0 -30
  264. package/.output/server/node_modules/mongoose/lib/helpers/createJSONSchemaTypeDefinition.js +0 -24
  265. package/.output/server/node_modules/mongoose/lib/helpers/promiseOrCallback.js +0 -54
  266. package/.output/server/node_modules/mongoose/lib/plugins/validateBeforeSave.js +0 -51
  267. package/.output/server/node_modules/supports-color/index.js +0 -202
  268. package/.output/server/node_modules/supports-color/package.json +0 -64
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MongoClient = exports.ServerApiVersion = void 0;
4
4
  const fs_1 = require("fs");
5
+ const _1 = require(".");
5
6
  const bson_1 = require("./bson");
6
7
  const change_stream_1 = require("./change_stream");
7
8
  const mongo_credentials_1 = require("./cmap/auth/mongo_credentials");
8
9
  const providers_1 = require("./cmap/auth/providers");
9
10
  const client_metadata_1 = require("./cmap/handshake/client_metadata");
10
- const responses_1 = require("./cmap/wire_protocol/responses");
11
11
  const connection_string_1 = require("./connection_string");
12
12
  const constants_1 = require("./constants");
13
13
  const db_1 = require("./db");
@@ -16,10 +16,9 @@ const mongo_client_auth_providers_1 = require("./mongo_client_auth_providers");
16
16
  const mongo_logger_1 = require("./mongo_logger");
17
17
  const mongo_types_1 = require("./mongo_types");
18
18
  const executor_1 = require("./operations/client_bulk_write/executor");
19
+ const end_sessions_1 = require("./operations/end_sessions");
19
20
  const execute_operation_1 = require("./operations/execute_operation");
20
- const operation_1 = require("./operations/operation");
21
21
  const read_preference_1 = require("./read_preference");
22
- const resource_management_1 = require("./resource_management");
23
22
  const server_selection_1 = require("./sdam/server_selection");
24
23
  const topology_1 = require("./sdam/topology");
25
24
  const sessions_1 = require("./sessions");
@@ -101,8 +100,11 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
101
100
  };
102
101
  this.checkForNonGenuineHosts();
103
102
  }
104
- /** @internal */
105
- async asyncDispose() {
103
+ /**
104
+ * @experimental
105
+ * An alias for {@link MongoClient.close|MongoClient.close()}.
106
+ */
107
+ async [Symbol.asyncDispose]() {
106
108
  await this.close();
107
109
  }
108
110
  /**
@@ -114,8 +116,7 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
114
116
  if (isDuplicateDriverInfo)
115
117
  return;
116
118
  this.driverInfoList.push(driverInfo);
117
- this.options.metadata = (0, client_metadata_1.makeClientMetadata)(this.driverInfoList, this.options);
118
- this.options.extendedMetadata = (0, client_metadata_1.addContainerMetadata)(this.options.metadata)
119
+ this.options.metadata = (0, client_metadata_1.makeClientMetadata)(this.driverInfoList, this.options)
119
120
  .then(undefined, utils_1.squashError)
120
121
  .then(result => result ?? {}); // ensure Promise<Document>
121
122
  }
@@ -178,20 +179,13 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
178
179
  return await new executor_1.ClientBulkWriteExecutor(this, models, (0, utils_1.resolveOptions)(this, options)).execute();
179
180
  }
180
181
  /**
181
- * Connect to MongoDB using a url
182
+ * An optional method to verify a handful of assumptions that are generally useful at application boot-time before using a MongoClient.
183
+ * For detailed information about the connect process see the MongoClient.connect static method documentation.
182
184
  *
183
- * @remarks
184
- * Calling `connect` is optional since the first operation you perform will call `connect` if it's needed.
185
- * `timeoutMS` will bound the time any operation can take before throwing a timeout error.
186
- * However, when the operation being run is automatically connecting your `MongoClient` the `timeoutMS` will not apply to the time taken to connect the MongoClient.
187
- * This means the time to setup the `MongoClient` does not count against `timeoutMS`.
188
- * If you are using `timeoutMS` we recommend connecting your client explicitly in advance of any operation to avoid this inconsistent execution time.
185
+ * @param url - The MongoDB connection string (supports `mongodb://` and `mongodb+srv://` schemes)
186
+ * @param options - Optional configuration options for the client
189
187
  *
190
- * @remarks
191
- * The driver will look up corresponding SRV and TXT records if the connection string starts with `mongodb+srv://`.
192
- * If those look ups throw a DNS Timeout error, the driver will retry the look up once.
193
- *
194
- * @see docs.mongodb.org/manual/reference/connection-string/
188
+ * @see https://www.mongodb.com/docs/manual/reference/connection-string/
195
189
  */
196
190
  async connect() {
197
191
  if (this.connectionLock) {
@@ -355,44 +349,10 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
355
349
  if (this.topology == null) {
356
350
  return;
357
351
  }
358
- // If we would attempt to select a server and get nothing back we short circuit
359
- // to avoid the server selection timeout.
360
- const selector = (0, server_selection_1.readPreferenceServerSelector)(read_preference_1.ReadPreference.primaryPreferred);
361
- const topologyDescription = this.topology.description;
362
- const serverDescriptions = Array.from(topologyDescription.servers.values());
363
- const servers = selector(topologyDescription, serverDescriptions);
364
- if (servers.length !== 0) {
365
- const endSessions = Array.from(this.s.sessionPool.sessions, ({ id }) => id);
366
- if (endSessions.length !== 0) {
367
- try {
368
- class EndSessionsOperation extends operation_1.AbstractOperation {
369
- constructor() {
370
- super(...arguments);
371
- this.ns = utils_1.MongoDBNamespace.fromString('admin.$cmd');
372
- this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
373
- }
374
- buildCommand(_connection, _session) {
375
- return {
376
- endSessions
377
- };
378
- }
379
- buildOptions(timeoutContext) {
380
- return {
381
- timeoutContext,
382
- readPreference: read_preference_1.ReadPreference.primaryPreferred,
383
- noResponse: true
384
- };
385
- }
386
- get commandName() {
387
- return 'endSessions';
388
- }
389
- }
390
- await (0, execute_operation_1.executeOperation)(this, new EndSessionsOperation());
391
- }
392
- catch (error) {
393
- (0, utils_1.squashError)(error);
394
- }
395
- }
352
+ const supportsSessions = this.topology.description.type === _1.TopologyType.LoadBalanced ||
353
+ this.topology.description.logicalSessionTimeoutMinutes != null;
354
+ if (supportsSessions) {
355
+ await endSessions(this, this.topology);
396
356
  }
397
357
  // clear out references to old topology
398
358
  const topology = this.topology;
@@ -402,6 +362,24 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
402
362
  if (encrypter) {
403
363
  await encrypter.close(this);
404
364
  }
365
+ async function endSessions(client, { description: topologyDescription }) {
366
+ // If we would attempt to select a server and get nothing back we short circuit
367
+ // to avoid the server selection timeout.
368
+ const selector = (0, server_selection_1.readPreferenceServerSelector)(read_preference_1.ReadPreference.primaryPreferred);
369
+ const serverDescriptions = Array.from(topologyDescription.servers.values());
370
+ const servers = selector(topologyDescription, serverDescriptions, new server_selection_1.DeprioritizedServers());
371
+ if (servers.length !== 0) {
372
+ const endSessions = Array.from(client.s.sessionPool.sessions, ({ id }) => id);
373
+ if (endSessions.length !== 0) {
374
+ try {
375
+ await (0, execute_operation_1.executeOperation)(client, new end_sessions_1.EndSessionsOperation(endSessions));
376
+ }
377
+ catch (error) {
378
+ (0, utils_1.squashError)(error);
379
+ }
380
+ }
381
+ }
382
+ }
405
383
  }
406
384
  /**
407
385
  * Create a new Db instance sharing the current socket connections.
@@ -423,21 +401,35 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
423
401
  return db;
424
402
  }
425
403
  /**
426
- * Connect to MongoDB using a url
404
+ * Creates a new MongoClient instance and immediately connects it to MongoDB.
405
+ * This convenience method combines `new MongoClient(url, options)` and `client.connect()` in a single step.
406
+ *
407
+ * Connect can be helpful to detect configuration issues early by validating:
408
+ * - **DNS Resolution**: Verifies that SRV records and hostnames in the connection string resolve DNS entries
409
+ * - **Network Connectivity**: Confirms that host addresses are reachable and ports are open
410
+ * - **TLS Configuration**: Validates SSL/TLS certificates, CA files, and encryption settings are correct
411
+ * - **Authentication**: Verifies that provided credentials are valid
412
+ * - **Server Compatibility**: Ensures the MongoDB server version is supported by this driver version
413
+ * - **Load Balancer Setup**: For load-balanced deployments, confirms the service is properly configured
414
+ *
415
+ * @returns A promise that resolves to the same MongoClient instance once connected
427
416
  *
428
417
  * @remarks
429
- * Calling `connect` is optional since the first operation you perform will call `connect` if it's needed.
430
- * `timeoutMS` will bound the time any operation can take before throwing a timeout error.
431
- * However, when the operation being run is automatically connecting your `MongoClient` the `timeoutMS` will not apply to the time taken to connect the MongoClient.
432
- * This means the time to setup the `MongoClient` does not count against `timeoutMS`.
433
- * If you are using `timeoutMS` we recommend connecting your client explicitly in advance of any operation to avoid this inconsistent execution time.
418
+ * **Connection is Optional:** Calling `connect` is optional since any operation method (`find`, `insertOne`, etc.)
419
+ * will automatically perform these same validation steps if the client is not already connected.
420
+ * However, explicitly calling `connect` can make sense for:
421
+ * - **Fail-fast Error Detection**: Non-transient connection issues (hostname unresolved, port refused connection) are discovered immediately rather than during your first operation
422
+ * - **Predictable Performance**: Eliminates first connection overhead from your first database operation
434
423
  *
435
424
  * @remarks
436
- * The programmatically provided options take precedence over the URI options.
425
+ * **Connection Pooling Impact:** Calling `connect` will populate the connection pool with one connection
426
+ * to a server selected by the client's configured `readPreference` (defaults to primary).
437
427
  *
438
428
  * @remarks
439
- * The driver will look up corresponding SRV and TXT records if the connection string starts with `mongodb+srv://`.
440
- * If those look ups throw a DNS Timeout error, the driver will retry the look up once.
429
+ * **Timeout Behavior:** When using `timeoutMS`, the connection establishment time does not count against
430
+ * the timeout for subsequent operations. This means `connect` runs without a `timeoutMS` limit, while
431
+ * your database operations will still respect the configured timeout. If you need predictable operation
432
+ * timing with `timeoutMS`, call `connect` explicitly before performing operations.
441
433
  *
442
434
  * @see https://www.mongodb.com/docs/manual/reference/connection-string/
443
435
  */
@@ -562,5 +554,4 @@ class MongoClient extends mongo_types_1.TypedEventEmitter {
562
554
  }
563
555
  }
564
556
  exports.MongoClient = MongoClient;
565
- (0, resource_management_1.configureResourceManagement)(MongoClient.prototype);
566
557
  //# sourceMappingURL=mongo_client.js.map
@@ -18,12 +18,6 @@ const AUTH_PROVIDERS = new Map([
18
18
  providers_1.AuthMechanism.MONGODB_AWS,
19
19
  ({ AWS_CREDENTIAL_PROVIDER }) => new mongodb_aws_1.MongoDBAWS(AWS_CREDENTIAL_PROVIDER)
20
20
  ],
21
- [
22
- providers_1.AuthMechanism.MONGODB_CR,
23
- () => {
24
- throw new error_1.MongoInvalidArgumentError('MONGODB-CR is no longer a supported auth mechanism in MongoDB 4.0+');
25
- }
26
- ],
27
21
  [providers_1.AuthMechanism.MONGODB_GSSAPI, () => new gssapi_1.GSSAPI()],
28
22
  [providers_1.AuthMechanism.MONGODB_OIDC, properties => new mongodb_oidc_1.MongoDBOIDC(getWorkflow(properties))],
29
23
  [providers_1.AuthMechanism.MONGODB_PLAIN, () => new plain_1.Plain()],
@@ -5,6 +5,7 @@ exports.parseSeverityFromString = parseSeverityFromString;
5
5
  exports.createStdioLogger = createStdioLogger;
6
6
  exports.stringifyWithMaxLen = stringifyWithMaxLen;
7
7
  exports.defaultLogTransform = defaultLogTransform;
8
+ const process = require("process");
8
9
  const util_1 = require("util");
9
10
  const bson_1 = require("./bson");
10
11
  const constants_1 = require("./constants");
@@ -84,11 +85,16 @@ function parseSeverityFromString(s) {
84
85
  /** @internal */
85
86
  function createStdioLogger(stream) {
86
87
  return {
87
- write: (0, util_1.promisify)((log, cb) => {
88
- const logLine = (0, util_1.inspect)(log, { compact: true, breakLength: Infinity });
89
- stream.write(`${logLine}\n`, 'utf-8', cb);
90
- return;
91
- })
88
+ write: (log) => {
89
+ return new Promise((resolve, reject) => {
90
+ const logLine = (0, util_1.inspect)(log, { compact: true, breakLength: Infinity });
91
+ stream.write(`${logLine}\n`, 'utf-8', error => {
92
+ if (error)
93
+ return reject(error);
94
+ resolve(true);
95
+ });
96
+ });
97
+ }
92
98
  };
93
99
  }
94
100
  /**
@@ -44,8 +44,7 @@ class TypedEventEmitter extends events_1.EventEmitter {
44
44
  }
45
45
  exports.TypedEventEmitter = TypedEventEmitter;
46
46
  /**
47
- * @public
48
- * @deprecated Will be removed in favor of `AbortSignal` in the next major release.
47
+ * @internal
49
48
  */
50
49
  class CancellationToken extends TypedEventEmitter {
51
50
  constructor(...args) {
@@ -32,9 +32,6 @@ class AggregateOperation extends command_1.CommandOperation {
32
32
  if (!this.hasWriteStage) {
33
33
  delete this.options.writeConcern;
34
34
  }
35
- if (this.explain && this.writeConcern) {
36
- throw new error_1.MongoInvalidArgumentError('Option "explain" cannot be used on an aggregate call with writeConcern');
37
- }
38
35
  if (options?.cursor != null && typeof options.cursor !== 'object') {
39
36
  throw new error_1.MongoInvalidArgumentError('Cursor options must be an object');
40
37
  }
@@ -18,7 +18,6 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
18
18
  'timeoutMS',
19
19
  'j',
20
20
  'fsync',
21
- 'autoIndexId',
22
21
  'pkFactory',
23
22
  'raw',
24
23
  'readPreference',
@@ -27,6 +27,13 @@ class DropCollectionOperation extends command_1.CommandOperation {
27
27
  handleOk(_response) {
28
28
  return true;
29
29
  }
30
+ handleError(error) {
31
+ if (!(error instanceof __1.MongoServerError))
32
+ throw error;
33
+ if (Number(error.code) !== error_1.MONGODB_ERROR_CODES.NamespaceNotFound)
34
+ throw error;
35
+ return false;
36
+ }
30
37
  }
31
38
  exports.DropCollectionOperation = DropCollectionOperation;
32
39
  async function dropCollections(db, name, options) {
@@ -58,15 +65,7 @@ async function dropCollections(db, name, options) {
58
65
  for (const collectionName of [escCollection, ecocCollection]) {
59
66
  // Drop auxilliary collections, ignoring potential NamespaceNotFound errors.
60
67
  const dropOp = new DropCollectionOperation(db, collectionName, options);
61
- try {
62
- await (0, execute_operation_1.executeOperation)(db.client, dropOp, timeoutContext);
63
- }
64
- catch (err) {
65
- if (!(err instanceof __1.MongoServerError) ||
66
- err.code !== error_1.MONGODB_ERROR_CODES.NamespaceNotFound) {
67
- throw err;
68
- }
69
- }
68
+ await (0, execute_operation_1.executeOperation)(db.client, dropOp, timeoutContext);
70
69
  }
71
70
  }
72
71
  return await (0, execute_operation_1.executeOperation)(db.client, new DropCollectionOperation(db, name, options), timeoutContext);
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EndSessionsOperation = void 0;
4
+ const responses_1 = require("../cmap/wire_protocol/responses");
5
+ const command_1 = require("../operations/command");
6
+ const read_preference_1 = require("../read_preference");
7
+ const utils_1 = require("../utils");
8
+ const operation_1 = require("./operation");
9
+ class EndSessionsOperation extends command_1.CommandOperation {
10
+ constructor(sessions) {
11
+ super();
12
+ this.writeConcern = { w: 0 };
13
+ this.ns = utils_1.MongoDBNamespace.fromString('admin.$cmd');
14
+ this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
15
+ this.sessions = sessions;
16
+ }
17
+ buildCommandDocument(_connection, _session) {
18
+ return {
19
+ endSessions: this.sessions
20
+ };
21
+ }
22
+ buildOptions(timeoutContext) {
23
+ return {
24
+ timeoutContext,
25
+ readPreference: read_preference_1.ReadPreference.primaryPreferred
26
+ };
27
+ }
28
+ get commandName() {
29
+ return 'endSessions';
30
+ }
31
+ }
32
+ exports.EndSessionsOperation = EndSessionsOperation;
33
+ (0, operation_1.defineAspects)(EndSessionsOperation, operation_1.Aspect.WRITE_OPERATION);
34
+ //# sourceMappingURL=end_sessions.js.map
@@ -2,13 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeOperation = executeOperation;
4
4
  exports.autoConnect = autoConnect;
5
+ const promises_1 = require("timers/promises");
6
+ const constants_1 = require("../cmap/wire_protocol/constants");
5
7
  const error_1 = require("../error");
6
8
  const read_preference_1 = require("../read_preference");
9
+ const common_1 = require("../sdam/common");
7
10
  const server_selection_1 = require("../sdam/server_selection");
8
11
  const timeout_1 = require("../timeout");
9
12
  const utils_1 = require("../utils");
10
13
  const aggregate_1 = require("./aggregate");
11
14
  const operation_1 = require("./operation");
15
+ const run_command_1 = require("./run_command");
12
16
  const MMAPv1_RETRY_WRITES_ERROR_CODE = error_1.MONGODB_ERROR_CODES.IllegalOperation;
13
17
  const MMAPv1_RETRY_WRITES_ERROR_MESSAGE = 'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.';
14
18
  /**
@@ -23,7 +27,7 @@ const MMAPv1_RETRY_WRITES_ERROR_MESSAGE = 'This MongoDB deployment does not supp
23
27
  * The expectation is that this function:
24
28
  * - Connects the MongoClient if it has not already been connected, see {@link autoConnect}
25
29
  * - Creates a session if none is provided and cleans up the session it creates
26
- * - Tries an operation and retries under certain conditions, see {@link tryOperation}
30
+ * - Tries an operation and retries under certain conditions, see {@link executeOperationWithRetries}
27
31
  *
28
32
  * @typeParam T - The operation's type
29
33
  * @typeParam TResult - The type of the operation's result, calculated from T
@@ -50,7 +54,8 @@ async function executeOperation(client, operation, timeoutContext) {
50
54
  else if (session.hasEnded) {
51
55
  throw new error_1.MongoExpiredSessionError('Use of expired sessions is not permitted');
52
56
  }
53
- else if (session.snapshotEnabled && !topology.capabilities.supportsSnapshotReads) {
57
+ else if (session.snapshotEnabled &&
58
+ (0, utils_1.maxWireVersion)(topology) < constants_1.MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION) {
54
59
  throw new error_1.MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later');
55
60
  }
56
61
  else if (session.client !== client) {
@@ -75,7 +80,7 @@ async function executeOperation(client, operation, timeoutContext) {
75
80
  timeoutMS: operation.options.timeoutMS
76
81
  });
77
82
  try {
78
- return await tryOperation(operation, {
83
+ return await executeOperationWithRetries(operation, {
79
84
  topology,
80
85
  timeoutContext,
81
86
  session,
@@ -111,6 +116,10 @@ async function autoConnect(client) {
111
116
  }
112
117
  return client.topology;
113
118
  }
119
+ /** @internal The base backoff duration in milliseconds */
120
+ const BASE_BACKOFF_MS = 100;
121
+ /** @internal The maximum backoff duration in milliseconds */
122
+ const MAX_BACKOFF_MS = 10_000;
114
123
  /**
115
124
  * Executes an operation and retries as appropriate
116
125
  * @internal
@@ -128,8 +137,8 @@ async function autoConnect(client) {
128
137
  * @typeParam TResult - The type of the operation's result, calculated from T
129
138
  *
130
139
  * @param operation - The operation to execute
131
- * */
132
- async function tryOperation(operation, { topology, timeoutContext, session, readPreference }) {
140
+ */
141
+ async function executeOperationWithRetries(operation, { topology, timeoutContext, session, readPreference }) {
133
142
  let selector;
134
143
  if (operation.hasAspect(operation_1.Aspect.MUST_SELECT_SAME_SERVER)) {
135
144
  // GetMore and KillCursor operations must always select the same server, but run through
@@ -149,7 +158,8 @@ async function tryOperation(operation, { topology, timeoutContext, session, read
149
158
  session,
150
159
  operationName: operation.commandName,
151
160
  timeoutContext,
152
- signal: operation.options.signal
161
+ signal: operation.options.signal,
162
+ deprioritizedServers: new server_selection_1.DeprioritizedServers()
153
163
  });
154
164
  const hasReadAspect = operation.hasAspect(operation_1.Aspect.READ_OPERATION);
155
165
  const hasWriteAspect = operation.hasAspect(operation_1.Aspect.WRITE_OPERATION);
@@ -166,71 +176,137 @@ async function tryOperation(operation, { topology, timeoutContext, session, read
166
176
  operation.options.willRetryWrite = true;
167
177
  session.incrementTransactionNumber();
168
178
  }
169
- const maxTries = willRetry ? (timeoutContext.csotEnabled() ? Infinity : 2) : 1;
170
- let previousOperationError;
171
- let previousServer;
172
- for (let tries = 0; tries < maxTries; tries++) {
173
- if (previousOperationError) {
174
- if (hasWriteAspect && previousOperationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
179
+ const deprioritizedServers = new server_selection_1.DeprioritizedServers();
180
+ let maxAttempts = typeof operation.maxAttempts === 'number'
181
+ ? operation.maxAttempts
182
+ : willRetry
183
+ ? timeoutContext.csotEnabled()
184
+ ? Infinity
185
+ : 2
186
+ : 1;
187
+ let error = null;
188
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
189
+ operation.attemptsMade = attempt + 1;
190
+ operation.server = server;
191
+ try {
192
+ try {
193
+ const result = await server.command(operation, timeoutContext);
194
+ return operation.handleOk(result);
195
+ }
196
+ catch (error) {
197
+ return operation.handleError(error);
198
+ }
199
+ }
200
+ catch (operationError) {
201
+ // Should never happen but if it does - propagate the error.
202
+ if (!(operationError instanceof error_1.MongoError))
203
+ throw operationError;
204
+ // Preserve the original error once a write has been performed.
205
+ // Only update to the latest error if no writes were performed.
206
+ if (error == null) {
207
+ error = operationError;
208
+ }
209
+ else {
210
+ if (!operationError.hasErrorLabel(error_1.MongoErrorLabel.NoWritesPerformed)) {
211
+ error = operationError;
212
+ }
213
+ }
214
+ // Reset timeouts
215
+ timeoutContext.clear();
216
+ if (hasWriteAspect && operationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
175
217
  throw new error_1.MongoServerError({
176
218
  message: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
177
219
  errmsg: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
178
- originalError: previousOperationError
220
+ originalError: operationError
179
221
  });
180
222
  }
181
- if (operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING) && !operation.canRetryWrite) {
182
- throw previousOperationError;
223
+ if (!canRetry(operation, operationError)) {
224
+ throw error;
225
+ }
226
+ if (operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError)) {
227
+ const maxOverloadAttempts = topology.s.options.maxAdaptiveRetries + 1;
228
+ maxAttempts = Math.min(maxOverloadAttempts, operation.maxAttempts ?? maxOverloadAttempts);
183
229
  }
184
- if (hasWriteAspect && !(0, error_1.isRetryableWriteError)(previousOperationError))
185
- throw previousOperationError;
186
- if (hasReadAspect && !(0, error_1.isRetryableReadError)(previousOperationError)) {
187
- throw previousOperationError;
230
+ if (attempt + 1 >= maxAttempts) {
231
+ throw error;
188
232
  }
189
- if (previousOperationError instanceof error_1.MongoNetworkError &&
233
+ if (operationError instanceof error_1.MongoNetworkError &&
190
234
  operation.hasAspect(operation_1.Aspect.CURSOR_CREATING) &&
191
235
  session != null &&
192
236
  session.isPinned &&
193
237
  !session.inTransaction()) {
194
238
  session.unpin({ force: true, forceClear: true });
195
239
  }
240
+ if (operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError) &&
241
+ operation.hasAspect(operation_1.Aspect.CURSOR_CREATING) &&
242
+ session != null &&
243
+ session.isPinned &&
244
+ !session.inTransaction()) {
245
+ session.unpin({ force: true });
246
+ }
247
+ if (operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError)) {
248
+ const backoffMS = Math.random() * Math.min(MAX_BACKOFF_MS, BASE_BACKOFF_MS * 2 ** attempt);
249
+ // if the backoff would exhaust the CSOT timeout, short-circuit.
250
+ if (timeoutContext.csotEnabled() && backoffMS > timeoutContext.remainingTimeMS) {
251
+ throw error;
252
+ }
253
+ await (0, promises_1.setTimeout)(backoffMS);
254
+ }
255
+ if (topology.description.type === common_1.TopologyType.Sharded ||
256
+ (operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError) &&
257
+ topology.s.options.enableOverloadRetargeting)) {
258
+ deprioritizedServers.add(server.description);
259
+ }
196
260
  server = await topology.selectServer(selector, {
197
261
  session,
198
262
  operationName: operation.commandName,
199
- previousServer,
263
+ deprioritizedServers,
200
264
  signal: operation.options.signal
201
265
  });
202
- if (hasWriteAspect && !(0, utils_1.supportsRetryableWrites)(server)) {
266
+ if (hasWriteAspect &&
267
+ !(0, utils_1.supportsRetryableWrites)(server) &&
268
+ !operationError.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError)) {
203
269
  throw new error_1.MongoUnexpectedServerResponseError('Selected server does not support retryable writes');
204
270
  }
205
- }
206
- operation.server = server;
207
- try {
208
- // If tries > 0 and we are command batching we need to reset the batch.
209
- if (tries > 0 && operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING)) {
271
+ // Batched operations must reset the batch before retry,
272
+ // otherwise building a command will build the _next_ batch, not the current batch.
273
+ if (operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING)) {
210
274
  operation.resetBatch();
211
275
  }
212
- try {
213
- const result = await server.command(operation, timeoutContext);
214
- return operation.handleOk(result);
276
+ }
277
+ }
278
+ throw (error ??
279
+ new error_1.MongoRuntimeError('Should never happen: operation execution loop terminated but no error was recorded.'));
280
+ function canRetry(operation, error) {
281
+ // SystemOverloadedError is retryable, but must respect retryReads/retryWrites settings
282
+ // Check topology options directly (not operation.canRetryRead/Write) because backpressure
283
+ // expands retry support beyond traditional retryable reads/writes
284
+ // NOTE: Unlike traditional retries, backpressure retries ARE allowed inside transactions
285
+ if (error.hasErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError) &&
286
+ error.hasErrorLabel(error_1.MongoErrorLabel.RetryableError)) {
287
+ // runCommand requires BOTH retryReads and retryWrites to be enabled (per spec step 2.4)
288
+ if (operation instanceof run_command_1.RunCommandOperation) {
289
+ return topology.s.options.retryReads && topology.s.options.retryWrites;
215
290
  }
216
- catch (error) {
217
- return operation.handleError(error);
291
+ // Write-stage aggregates ($out/$merge) require retryWrites
292
+ if (operation instanceof aggregate_1.AggregateOperation && operation.hasWriteStage) {
293
+ return topology.s.options.retryWrites;
218
294
  }
295
+ // For other operations, check if retries are enabled based on operation type
296
+ const canRetryAsRead = hasReadAspect && topology.s.options.retryReads;
297
+ const canRetryAsWrite = hasWriteAspect && topology.s.options.retryWrites;
298
+ return canRetryAsRead || canRetryAsWrite;
219
299
  }
220
- catch (operationError) {
221
- if (!(operationError instanceof error_1.MongoError))
222
- throw operationError;
223
- if (previousOperationError != null &&
224
- operationError.hasErrorLabel(error_1.MongoErrorLabel.NoWritesPerformed)) {
225
- throw previousOperationError;
226
- }
227
- previousServer = server.description;
228
- previousOperationError = operationError;
229
- // Reset timeouts
230
- timeoutContext.clear();
300
+ // run command is only retryable if we get retryable overload errors
301
+ if (operation instanceof run_command_1.RunCommandOperation) {
302
+ return false;
303
+ }
304
+ // batch operations are only retryable if the batch is retryable
305
+ if (operation.hasAspect(operation_1.Aspect.COMMAND_BATCHING)) {
306
+ return operation.canRetryWrite && (0, error_1.isRetryableWriteError)(error);
231
307
  }
308
+ return ((hasWriteAspect && willRetryWrite && (0, error_1.isRetryableWriteError)(error)) ||
309
+ (hasReadAspect && willRetryRead && (0, error_1.isRetryableReadError)(error)));
232
310
  }
233
- throw (previousOperationError ??
234
- new error_1.MongoRuntimeError('Tried to propagate retryability error, but no error was found.'));
235
311
  }
236
312
  //# sourceMappingURL=execute_operation.js.map
@@ -32,6 +32,7 @@ class AbstractOperation {
32
32
  this._session = options.session != null ? options.session : undefined;
33
33
  this.options = options;
34
34
  this.bypassPinningCheck = !!options.bypassPinningCheck;
35
+ this.attemptsMade = 0;
35
36
  }
36
37
  hasAspect(aspect) {
37
38
  const ctor = this.constructor;