@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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServerCapabilities = exports.Topology = void 0;
3
+ exports.Topology = void 0;
4
4
  const connection_string_1 = require("../connection_string");
5
5
  const constants_1 = require("../constants");
6
6
  const error_1 = require("../error");
@@ -30,6 +30,28 @@ const stateTransition = (0, utils_1.makeStateMachine)({
30
30
  * @internal
31
31
  */
32
32
  class Topology extends mongo_types_1.TypedEventEmitter {
33
+ /** @event */
34
+ static { this.SERVER_OPENING = constants_1.SERVER_OPENING; }
35
+ /** @event */
36
+ static { this.SERVER_CLOSED = constants_1.SERVER_CLOSED; }
37
+ /** @event */
38
+ static { this.SERVER_DESCRIPTION_CHANGED = constants_1.SERVER_DESCRIPTION_CHANGED; }
39
+ /** @event */
40
+ static { this.TOPOLOGY_OPENING = constants_1.TOPOLOGY_OPENING; }
41
+ /** @event */
42
+ static { this.TOPOLOGY_CLOSED = constants_1.TOPOLOGY_CLOSED; }
43
+ /** @event */
44
+ static { this.TOPOLOGY_DESCRIPTION_CHANGED = constants_1.TOPOLOGY_DESCRIPTION_CHANGED; }
45
+ /** @event */
46
+ static { this.ERROR = constants_1.ERROR; }
47
+ /** @event */
48
+ static { this.OPEN = constants_1.OPEN; }
49
+ /** @event */
50
+ static { this.CONNECT = constants_1.CONNECT; }
51
+ /** @event */
52
+ static { this.CLOSE = constants_1.CLOSE; }
53
+ /** @event */
54
+ static { this.TIMEOUT = constants_1.TIMEOUT; }
33
55
  /**
34
56
  * @param seedlist - a list of HostAddress instances to connect to
35
57
  */
@@ -142,9 +164,6 @@ class Topology extends mongo_types_1.TypedEventEmitter {
142
164
  get serverApi() {
143
165
  return this.s.options.serverApi;
144
166
  }
145
- get capabilities() {
146
- return new ServerCapabilities(this.lastHello());
147
- }
148
167
  /** Initiate server connect */
149
168
  async connect(options) {
150
169
  this.connectionLock ??= this._connect(options);
@@ -194,12 +213,13 @@ class Topology extends mongo_types_1.TypedEventEmitter {
194
213
  const selectServerOptions = {
195
214
  operationName: 'handshake',
196
215
  ...options,
197
- timeoutContext
216
+ timeoutContext,
217
+ deprioritizedServers: new server_selection_1.DeprioritizedServers()
198
218
  };
199
219
  try {
200
220
  const server = await this.selectServer((0, server_selection_1.readPreferenceServerSelector)(readPreference), selectServerOptions);
201
221
  const skipPingOnConnect = this.s.options.__skipPingOnConnect === true;
202
- if (!skipPingOnConnect && this.s.credentials) {
222
+ if (!skipPingOnConnect) {
203
223
  const connection = await server.pool.checkOut({ timeoutContext: timeoutContext });
204
224
  server.pool.checkIn(connection);
205
225
  stateTransition(this, common_1.STATE_CONNECTED);
@@ -288,8 +308,9 @@ class Topology extends mongo_types_1.TypedEventEmitter {
288
308
  if (this.client.mongoLogger?.willLog(mongo_logger_1.MongoLoggableComponent.SERVER_SELECTION, mongo_logger_1.SeverityLevel.DEBUG)) {
289
309
  this.client.mongoLogger?.debug(mongo_logger_1.MongoLoggableComponent.SERVER_SELECTION, new server_selection_events_1.ServerSelectionSucceededEvent(selector, this.description, transaction.server.pool.address, options.operationName));
290
310
  }
291
- if (options.timeoutContext?.clearServerSelectionTimeout)
311
+ if (!options.timeoutContext || options.timeoutContext.clearServerSelectionTimeout) {
292
312
  timeout?.clear();
313
+ }
293
314
  return transaction.server;
294
315
  }
295
316
  const { promise: serverPromise, resolve, reject } = (0, utils_1.promiseWithResolvers)();
@@ -301,10 +322,10 @@ class Topology extends mongo_types_1.TypedEventEmitter {
301
322
  resolve,
302
323
  reject,
303
324
  cancelled: false,
304
- startTime: (0, utils_1.now)(),
325
+ startTime: (0, utils_1.processTimeMS)(),
305
326
  operationName: options.operationName,
306
327
  waitingLogged: false,
307
- previousServer: options.previousServer
328
+ deprioritizedServers: options.deprioritizedServers
308
329
  };
309
330
  const abortListener = (0, utils_1.addAbortListener)(options.signal, function () {
310
331
  waitQueueMember.cancelled = true;
@@ -340,8 +361,9 @@ class Topology extends mongo_types_1.TypedEventEmitter {
340
361
  }
341
362
  finally {
342
363
  abortListener?.[utils_1.kDispose]();
343
- if (options.timeoutContext?.clearServerSelectionTimeout)
364
+ if (!options.timeoutContext || options.timeoutContext.clearServerSelectionTimeout) {
344
365
  timeout?.clear();
366
+ }
345
367
  }
346
368
  }
347
369
  /**
@@ -406,9 +428,6 @@ class Topology extends mongo_types_1.TypedEventEmitter {
406
428
  if (typeof callback === 'function')
407
429
  callback(undefined, true);
408
430
  }
409
- get clientMetadata() {
410
- return this.s.options.metadata;
411
- }
412
431
  isConnected() {
413
432
  return this.s.state === common_1.STATE_CONNECTED;
414
433
  }
@@ -440,28 +459,6 @@ class Topology extends mongo_types_1.TypedEventEmitter {
440
459
  }
441
460
  }
442
461
  exports.Topology = Topology;
443
- /** @event */
444
- Topology.SERVER_OPENING = constants_1.SERVER_OPENING;
445
- /** @event */
446
- Topology.SERVER_CLOSED = constants_1.SERVER_CLOSED;
447
- /** @event */
448
- Topology.SERVER_DESCRIPTION_CHANGED = constants_1.SERVER_DESCRIPTION_CHANGED;
449
- /** @event */
450
- Topology.TOPOLOGY_OPENING = constants_1.TOPOLOGY_OPENING;
451
- /** @event */
452
- Topology.TOPOLOGY_CLOSED = constants_1.TOPOLOGY_CLOSED;
453
- /** @event */
454
- Topology.TOPOLOGY_DESCRIPTION_CHANGED = constants_1.TOPOLOGY_DESCRIPTION_CHANGED;
455
- /** @event */
456
- Topology.ERROR = constants_1.ERROR;
457
- /** @event */
458
- Topology.OPEN = constants_1.OPEN;
459
- /** @event */
460
- Topology.CONNECT = constants_1.CONNECT;
461
- /** @event */
462
- Topology.CLOSE = constants_1.CLOSE;
463
- /** @event */
464
- Topology.TIMEOUT = constants_1.TIMEOUT;
465
462
  /** Destroys a server, and removes all event listeners from the instance */
466
463
  function closeServer(server, topology) {
467
464
  for (const event of constants_1.LOCAL_SERVER_EVENTS) {
@@ -585,9 +582,9 @@ function processWaitQueue(topology) {
585
582
  let selectedDescriptions;
586
583
  try {
587
584
  const serverSelector = waitQueueMember.serverSelector;
588
- const previousServer = waitQueueMember.previousServer;
585
+ const deprioritizedServers = waitQueueMember.deprioritizedServers;
589
586
  selectedDescriptions = serverSelector
590
- ? serverSelector(topology.description, serverDescriptions, previousServer ? [previousServer] : [])
587
+ ? serverSelector(topology.description, serverDescriptions, deprioritizedServers)
591
588
  : serverDescriptions;
592
589
  }
593
590
  catch (selectorError) {
@@ -602,7 +599,8 @@ function processWaitQueue(topology) {
602
599
  if (!waitQueueMember.waitingLogged) {
603
600
  if (topology.client.mongoLogger?.willLog(mongo_logger_1.MongoLoggableComponent.SERVER_SELECTION, mongo_logger_1.SeverityLevel.INFORMATIONAL)) {
604
601
  topology.client.mongoLogger?.info(mongo_logger_1.MongoLoggableComponent.SERVER_SELECTION, new server_selection_events_1.WaitingForSuitableServerEvent(waitQueueMember.serverSelector, topology.description, topology.s.serverSelectionTimeoutMS !== 0
605
- ? topology.s.serverSelectionTimeoutMS - ((0, utils_1.now)() - waitQueueMember.startTime)
602
+ ? topology.s.serverSelectionTimeoutMS -
603
+ ((0, utils_1.processTimeMS)() - waitQueueMember.startTime)
606
604
  : -1, waitQueueMember.operationName));
607
605
  }
608
606
  waitQueueMember.waitingLogged = true;
@@ -642,7 +640,7 @@ function processWaitQueue(topology) {
642
640
  if (topology.waitQueue.length > 0) {
643
641
  // ensure all server monitors attempt monitoring soon
644
642
  for (const [, server] of topology.s.servers) {
645
- process.nextTick(function scheduleServerCheck() {
643
+ queueMicrotask(function scheduleServerCheck() {
646
644
  return server.requestCheck();
647
645
  });
648
646
  }
@@ -653,42 +651,4 @@ function isStaleServerDescription(topologyDescription, incomingServerDescription
653
651
  const currentTopologyVersion = currentServerDescription?.topologyVersion;
654
652
  return ((0, server_description_1.compareTopologyVersion)(currentTopologyVersion, incomingServerDescription.topologyVersion) > 0);
655
653
  }
656
- /**
657
- * @public
658
- * @deprecated This class will be removed as dead code in the next major version.
659
- */
660
- class ServerCapabilities {
661
- constructor(hello) {
662
- this.minWireVersion = hello.minWireVersion || 0;
663
- this.maxWireVersion = hello.maxWireVersion || 0;
664
- }
665
- get hasAggregationCursor() {
666
- return true;
667
- }
668
- get hasWriteCommands() {
669
- return true;
670
- }
671
- get hasTextSearch() {
672
- return true;
673
- }
674
- get hasAuthCommands() {
675
- return true;
676
- }
677
- get hasListCollectionsCommand() {
678
- return true;
679
- }
680
- get hasListIndexesCommand() {
681
- return true;
682
- }
683
- get supportsSnapshotReads() {
684
- return this.maxWireVersion >= 13;
685
- }
686
- get commandsTakeWriteConcern() {
687
- return true;
688
- }
689
- get commandsTakeCollation() {
690
- return true;
691
- }
692
- }
693
- exports.ServerCapabilities = ServerCapabilities;
694
654
  //# sourceMappingURL=topology.js.map
@@ -136,7 +136,7 @@ class TopologyDescription {
136
136
  const serverDescriptions = new Map(this.servers);
137
137
  // update common wire version
138
138
  if (serverDescription.maxWireVersion !== 0) {
139
- if (commonWireVersion == null) {
139
+ if (commonWireVersion === 0) {
140
140
  commonWireVersion = serverDescription.maxWireVersion;
141
141
  }
142
142
  else {
@@ -4,6 +4,7 @@ exports.ServerSessionPool = exports.ServerSession = exports.ClientSession = void
4
4
  exports.maybeClearPinnedConnection = maybeClearPinnedConnection;
5
5
  exports.applySession = applySession;
6
6
  exports.updateSessionFromResponse = updateSessionFromResponse;
7
+ const promises_1 = require("timers/promises");
7
8
  const bson_1 = require("./bson");
8
9
  const metrics_1 = require("./cmap/metrics");
9
10
  const constants_1 = require("./constants");
@@ -13,7 +14,6 @@ const execute_operation_1 = require("./operations/execute_operation");
13
14
  const run_command_1 = require("./operations/run_command");
14
15
  const read_concern_1 = require("./read_concern");
15
16
  const read_preference_1 = require("./read_preference");
16
- const resource_management_1 = require("./resource_management");
17
17
  const common_1 = require("./sdam/common");
18
18
  const timeout_1 = require("./timeout");
19
19
  const transactions_1 = require("./transactions");
@@ -146,8 +146,11 @@ class ClientSession extends mongo_types_1.TypedEventEmitter {
146
146
  maybeClearPinnedConnection(this, { force: true, ...options });
147
147
  }
148
148
  }
149
- /** @internal */
150
- async asyncDispose() {
149
+ /**
150
+ * @experimental
151
+ * An alias for {@link ClientSession.endSession|ClientSession.endSession()}.
152
+ */
153
+ async [Symbol.asyncDispose]() {
151
154
  await this.endSession({ force: true });
152
155
  }
153
156
  /**
@@ -198,7 +201,7 @@ class ClientSession extends mongo_types_1.TypedEventEmitter {
198
201
  if (this.id == null || session.id == null) {
199
202
  return false;
200
203
  }
201
- return utils_1.ByteUtils.equals(this.id.id.buffer, session.id.id.buffer);
204
+ return bson_1.ByteUtils.equals(this.id.id.buffer, session.id.id.buffer);
202
205
  }
203
206
  /**
204
207
  * Increment the transaction number on the internal ServerSession
@@ -285,7 +288,11 @@ class ClientSession extends mongo_types_1.TypedEventEmitter {
285
288
  else {
286
289
  const wcKeys = Object.keys(wc);
287
290
  if (wcKeys.length > 2 || (!wcKeys.includes('wtimeoutMS') && !wcKeys.includes('wTimeoutMS')))
288
- // if the write concern was specified with wTimeoutMS, then we set both wtimeoutMS and wTimeoutMS, guaranteeing at least two keys, so if we have more than two keys, then we can automatically assume that we should add the write concern to the command. If it has 2 or fewer keys, we need to check that those keys aren't the wtimeoutMS or wTimeoutMS options before we add the write concern to the command
291
+ // if the write concern was specified with wTimeoutMS, then we set both wtimeoutMS
292
+ // and wTimeoutMS, guaranteeing at least two keys, so if we have more than two keys,
293
+ // then we can automatically assume that we should add the write concern to the command.
294
+ // If it has 2 or fewer keys, we need to check that those keys aren't the wtimeoutMS
295
+ // or wTimeoutMS options before we add the write concern to the command
289
296
  write_concern_1.WriteConcern.apply(command, { ...wc, wtimeoutMS: undefined });
290
297
  }
291
298
  }
@@ -308,6 +315,7 @@ class ClientSession extends mongo_types_1.TypedEventEmitter {
308
315
  readPreference: read_preference_1.ReadPreference.primary,
309
316
  bypassPinningCheck: true
310
317
  });
318
+ operation.maxAttempts = this.clientOptions.maxAdaptiveRetries + 1;
311
319
  const timeoutContext = this.timeoutContext ??
312
320
  (typeof timeoutMS === 'number'
313
321
  ? timeout_1.TimeoutContext.create({
@@ -323,17 +331,23 @@ class ClientSession extends mongo_types_1.TypedEventEmitter {
323
331
  }
324
332
  catch (firstCommitError) {
325
333
  this.commitAttempted = true;
334
+ const remainingAttempts = this.clientOptions.maxAdaptiveRetries + 1 - operation.attemptsMade;
335
+ if (remainingAttempts <= 0) {
336
+ throw firstCommitError;
337
+ }
326
338
  if (firstCommitError instanceof error_1.MongoError && (0, error_1.isRetryableWriteError)(firstCommitError)) {
327
339
  // SPEC-1185: apply majority write concern when retrying commitTransaction
328
340
  write_concern_1.WriteConcern.apply(command, { wtimeoutMS: 10000, ...wc, w: 'majority' });
329
341
  // per txns spec, must unpin session in this case
330
342
  this.unpin({ force: true });
331
343
  try {
332
- await (0, execute_operation_1.executeOperation)(this.client, new run_command_1.RunCommandOperation(new utils_1.MongoDBNamespace('admin'), command, {
344
+ const op = new run_command_1.RunCommandOperation(new utils_1.MongoDBNamespace('admin'), command, {
333
345
  session: this,
334
346
  readPreference: read_preference_1.ReadPreference.primary,
335
347
  bypassPinningCheck: true
336
- }), timeoutContext);
348
+ });
349
+ op.maxAttempts = remainingAttempts;
350
+ await (0, execute_operation_1.executeOperation)(this.client, op, timeoutContext);
337
351
  return;
338
352
  }
339
353
  catch (retryCommitError) {
@@ -479,7 +493,7 @@ class ClientSession extends mongo_types_1.TypedEventEmitter {
479
493
  * @returns A raw command response or undefined
480
494
  */
481
495
  async withTransaction(fn, options) {
482
- const MAX_TIMEOUT = 120000;
496
+ const MAX_TIMEOUT = 120_000;
483
497
  const timeoutMS = options?.timeoutMS ?? this.timeoutMS ?? null;
484
498
  this.timeoutContext =
485
499
  timeoutMS != null
@@ -489,71 +503,139 @@ class ClientSession extends mongo_types_1.TypedEventEmitter {
489
503
  socketTimeoutMS: this.clientOptions.socketTimeoutMS
490
504
  })
491
505
  : null;
492
- const startTime = this.timeoutContext?.csotEnabled() ? this.timeoutContext.start : (0, utils_1.now)();
506
+ // 1. Define the following:
507
+ // 1.1 Record the current monotonic time, which will be used to enforce the 120-second / CSOT timeout before later retry attempts.
508
+ // 1.2 Set `transactionAttempt` to `0`.
509
+ // 1.3 Set `TIMEOUT_MS` to be `timeoutMS` if given, otherwise MAX_TIMEOUT (120-seconds).
510
+ // Timeout Error propagation
511
+ // When the previously encountered error needs to be propagated because there is no more time for another attempt,
512
+ // and it is not already a timeout error, then:
513
+ // - A timeout error MUST be propagated instead. It MUST expose the previously encountered error as specified in
514
+ // the "Errors" section of the CSOT specification.
515
+ // - If exposing the previously encountered error from a timeout error is impossible in a driver, then the driver
516
+ // is exempt from the requirement and MUST propagate the previously encountered error as is. The timeout error
517
+ // MUST copy all error labels from the previously encountered error.
518
+ // The spec describes timeout checks as "elapsed time < TIMEOUT_MS" (where elapsed = now - start).
519
+ // We precompute `deadline = now + remainingTimeMS` so each check becomes simply `now < deadline`.
520
+ const csotEnabled = !!this.timeoutContext?.csotEnabled();
521
+ const remainingTimeMS = this.timeoutContext?.csotEnabled()
522
+ ? this.timeoutContext.remainingTimeMS
523
+ : MAX_TIMEOUT;
524
+ const deadline = (0, utils_1.processTimeMS)() + remainingTimeMS;
493
525
  let committed = false;
494
526
  let result;
527
+ let lastError = null;
495
528
  try {
496
- while (!committed) {
497
- this.startTransaction(options); // may throw on error
529
+ retryTransaction: for (let transactionAttempt = 0, isRetry = false; !committed; ++transactionAttempt, isRetry = transactionAttempt > 0) {
530
+ // 2. If `transactionAttempt` > 0:
531
+ if (isRetry) {
532
+ // 2.1 Calculate backoffMS to be jitter * min(BACKOFF_INITIAL * 1.5 ** (transactionAttempt - 1), BACKOFF_MAX).
533
+ // If elapsed time + backoffMS > TIMEOUT_MS, then propagate the previously encountered error to the caller of
534
+ // withTransaction as per timeout error propagation and return immediately. Otherwise, sleep for backoffMS.
535
+ // 2.1.1 jitter is a random float between [0, 1), optionally including 1, depending on what is most natural
536
+ // for the given driver language.
537
+ // 2.1.2 transactionAttempt is the variable defined in step 1.
538
+ // 2.1.3 BACKOFF_INITIAL is 5ms
539
+ // 2.1.4 BACKOFF_MAX is 500ms
540
+ const BACKOFF_INITIAL_MS = 5;
541
+ const BACKOFF_MAX_MS = 500;
542
+ const BACKOFF_GROWTH = 1.5;
543
+ const jitter = Math.random();
544
+ const backoffMS = jitter *
545
+ Math.min(BACKOFF_INITIAL_MS * BACKOFF_GROWTH ** (transactionAttempt - 1), BACKOFF_MAX_MS);
546
+ if ((0, utils_1.processTimeMS)() + backoffMS >= deadline) {
547
+ throw makeTimeoutError(lastError ??
548
+ new error_1.MongoRuntimeError(`Transaction retry did not record an error: should never occur. Please file a bug.`), csotEnabled);
549
+ }
550
+ await (0, promises_1.setTimeout)(backoffMS);
551
+ }
552
+ // 3. Invoke startTransaction on the session and increment transactionAttempt. If TransactionOptions were
553
+ // specified in the call to withTransaction, those MUST be used for startTransaction. Note that
554
+ // ClientSession.defaultTransactionOptions will be used in the absence of any explicit TransactionOptions.
555
+ // 4. If startTransaction reported an error, propagate that error to the caller of withTransaction as is and
556
+ // return immediately.
557
+ this.startTransaction(options);
498
558
  try {
559
+ // 5. Invoke the callback. Drivers MUST ensure that the ClientSession can be accessed within the callback
560
+ // (e.g. pass ClientSession as the first parameter, rely on lexical scoping). Drivers MAY pass additional
561
+ // parameters as needed (e.g. user data solicited by withTransaction).
499
562
  const promise = fn(this);
500
563
  if (!(0, utils_1.isPromiseLike)(promise)) {
501
564
  throw new error_1.MongoInvalidArgumentError('Function provided to `withTransaction` must return a Promise');
502
565
  }
566
+ // 6. Control returns to withTransaction. Determine the current state of the ClientSession and whether the
567
+ // callback reported an error (e.g. thrown exception, error output parameter).
503
568
  result = await promise;
569
+ // 8. If the ClientSession is in the "no transaction", "transaction aborted", or "transaction committed"
570
+ // state, assume the callback intentionally aborted or committed the transaction and return immediately.
504
571
  if (this.transaction.state === transactions_1.TxnState.NO_TRANSACTION ||
505
572
  this.transaction.state === transactions_1.TxnState.TRANSACTION_COMMITTED ||
506
573
  this.transaction.state === transactions_1.TxnState.TRANSACTION_ABORTED) {
507
- // Assume callback intentionally ended the transaction
508
574
  return result;
509
575
  }
510
576
  }
511
577
  catch (fnError) {
578
+ // 7. If the callback reported an error
512
579
  if (!(fnError instanceof error_1.MongoError) || fnError instanceof error_1.MongoInvalidArgumentError) {
580
+ // This first preemptive abort regardless of TxnState isn't spec,
581
+ // and it's unclear whether it's serving a practical purpose, but this logic is OLD
513
582
  await this.abortTransaction();
514
583
  throw fnError;
515
584
  }
585
+ lastError = fnError;
586
+ // 7.1 If the ClientSession is in the "starting transaction" or "transaction in progress"
587
+ // state, invoke abortTransaction on the session.
516
588
  if (this.transaction.state === transactions_1.TxnState.STARTING_TRANSACTION ||
517
589
  this.transaction.state === transactions_1.TxnState.TRANSACTION_IN_PROGRESS) {
518
590
  await this.abortTransaction();
519
591
  }
520
- if (fnError.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError) &&
521
- (this.timeoutContext != null || (0, utils_1.now)() - startTime < MAX_TIMEOUT)) {
522
- continue;
592
+ // 7.2 If the callback's error includes a "TransientTransactionError" label, jump back to step two.
593
+ if (fnError.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
594
+ if ((0, utils_1.processTimeMS)() >= deadline) {
595
+ throw makeTimeoutError(lastError, csotEnabled);
596
+ }
597
+ continue retryTransaction;
523
598
  }
599
+ // 7.3 If the callback's error includes a "UnknownTransactionCommitResult" label, the callback must
600
+ // have manually committed a transaction, propagate the callback's error to the caller of withTransaction
601
+ // as is and return immediately.
602
+ // 7.4 Otherwise, propagate the callback's error to the caller of withTransaction as is and return immediately.
524
603
  throw fnError;
525
604
  }
526
- while (!committed) {
605
+ retryCommit: while (!committed) {
527
606
  try {
528
- /*
529
- * We will rely on ClientSession.commitTransaction() to
530
- * apply a majority write concern if commitTransaction is
531
- * being retried (see: DRIVERS-601)
532
- */
607
+ // 9. Invoke commitTransaction on the session.
533
608
  await this.commitTransaction();
534
609
  committed = true;
535
610
  }
536
611
  catch (commitError) {
537
- /*
538
- * Note: a maxTimeMS error will have the MaxTimeMSExpired
539
- * code (50) and can be reported as a top-level error or
540
- * inside writeConcernError, ex.
541
- * { ok:0, code: 50, codeName: 'MaxTimeMSExpired' }
542
- * { ok:1, writeConcernError: { code: 50, codeName: 'MaxTimeMSExpired' } }
543
- */
544
- if (!isMaxTimeMSExpiredError(commitError) &&
545
- commitError.hasErrorLabel(error_1.MongoErrorLabel.UnknownTransactionCommitResult) &&
546
- (this.timeoutContext != null || (0, utils_1.now)() - startTime < MAX_TIMEOUT)) {
547
- continue;
612
+ // 10. If commitTransaction reported an error:
613
+ lastError = commitError;
614
+ // 10.1 If the commitTransaction error includes a UnknownTransactionCommitResult label and the error is
615
+ // not MaxTimeMSExpired
616
+ if (commitError.hasErrorLabel(error_1.MongoErrorLabel.UnknownTransactionCommitResult) &&
617
+ !isMaxTimeMSExpiredError(commitError)) {
618
+ // 10.1.1 If the elapsed time of withTransaction exceeded TIMEOUT_MS, propagate the commitTransaction
619
+ // error to the caller of withTransaction as per timeout error propagation and return immediately.
620
+ if ((0, utils_1.processTimeMS)() >= deadline) {
621
+ throw makeTimeoutError(commitError, csotEnabled);
622
+ }
623
+ // 10.1.2 Otherwise, jump back to step nine. We will trust commitTransaction to apply a majority write
624
+ // concern on retry attempts (see: Majority write concern is used when retrying commitTransaction).
625
+ continue retryCommit;
548
626
  }
549
- if (commitError.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError) &&
550
- (this.timeoutContext != null || (0, utils_1.now)() - startTime < MAX_TIMEOUT)) {
551
- break;
627
+ // 10.2 If the commitTransaction error includes a TransientTransactionError label, jump back to step two.
628
+ if (commitError.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
629
+ continue retryTransaction;
552
630
  }
631
+ // 10.3 Otherwise, propagate the commitTransaction error to the caller of withTransaction as is and return
632
+ // immediately.
553
633
  throw commitError;
554
634
  }
555
635
  }
556
636
  }
637
+ // 11. The transaction was committed successfully. Return immediately.
638
+ // @ts-expect-error Result is always defined if we reach here, the for-loop above convinces TS it is not.
557
639
  return result;
558
640
  }
559
641
  finally {
@@ -562,7 +644,24 @@ class ClientSession extends mongo_types_1.TypedEventEmitter {
562
644
  }
563
645
  }
564
646
  exports.ClientSession = ClientSession;
565
- (0, resource_management_1.configureResourceManagement)(ClientSession.prototype);
647
+ function makeTimeoutError(cause, csotEnabled) {
648
+ // Async APIs know how to cancel themselves and might return CSOT error
649
+ if (cause instanceof error_1.MongoOperationTimeoutError) {
650
+ return cause;
651
+ }
652
+ if (csotEnabled) {
653
+ const timeoutError = new error_1.MongoOperationTimeoutError('Timed out during withTransaction', {
654
+ cause
655
+ });
656
+ if (cause instanceof error_1.MongoError) {
657
+ for (const label of cause.errorLabels) {
658
+ timeoutError.addErrorLabel(label);
659
+ }
660
+ }
661
+ return timeoutError;
662
+ }
663
+ return cause;
664
+ }
566
665
  const NON_DETERMINISTIC_WRITE_CONCERN_ERRORS = new Set([
567
666
  'CannotSatisfyWriteConcern',
568
667
  'UnknownReplWriteConcern',
@@ -644,7 +743,7 @@ class ServerSession {
644
743
  /** @internal */
645
744
  constructor(cloned) {
646
745
  if (cloned != null) {
647
- const idBytes = Buffer.allocUnsafe(16);
746
+ const idBytes = bson_1.ByteUtils.allocateUnsafe(16);
648
747
  idBytes.set(cloned.id.id.buffer);
649
748
  this.id = { id: new bson_1.Binary(idBytes, cloned.id.id.sub_type) };
650
749
  this.lastUse = cloned.lastUse;
@@ -653,7 +752,7 @@ class ServerSession {
653
752
  return;
654
753
  }
655
754
  this.id = { id: new bson_1.Binary((0, utils_1.uuidV4)(), bson_1.Binary.SUBTYPE_UUID) };
656
- this.lastUse = (0, utils_1.now)();
755
+ this.lastUse = (0, utils_1.processTimeMS)();
657
756
  this.txnNumber = 0;
658
757
  this.isDirty = false;
659
758
  }
@@ -760,7 +859,7 @@ function applySession(session, command, options) {
760
859
  return;
761
860
  }
762
861
  // mark the last use of this session, and apply the `lsid`
763
- serverSession.lastUse = (0, utils_1.now)();
862
+ serverSession.lastUse = (0, utils_1.processTimeMS)();
764
863
  command.lsid = serverSession.id;
765
864
  const inTxnOrTxnCommand = session.inTransaction() || (0, transactions_1.isTransactionCommand)(command);
766
865
  const isRetryableWrite = !!options.willRetryWrite;
@@ -792,7 +891,6 @@ function applySession(session, command, options) {
792
891
  // `autocommit` must always be false to differentiate from retryable writes
793
892
  command.autocommit = false;
794
893
  if (session.transaction.state === transactions_1.TxnState.STARTING_TRANSACTION) {
795
- session.transaction.transition(transactions_1.TxnState.TRANSACTION_IN_PROGRESS);
796
894
  command.startTransaction = true;
797
895
  const readConcern = session.transaction.options.readConcern || session?.clientOptions?.readConcern;
798
896
  if (readConcern) {
@@ -823,5 +921,17 @@ function updateSessionFromResponse(session, document) {
823
921
  session.snapshotTime = atClusterTime;
824
922
  }
825
923
  }
924
+ if (session.transaction.state === transactions_1.TxnState.STARTING_TRANSACTION) {
925
+ if (document.ok === 1) {
926
+ session.transaction.transition(transactions_1.TxnState.TRANSACTION_IN_PROGRESS);
927
+ }
928
+ else {
929
+ const error = new error_1.MongoServerError(document.toObject());
930
+ const isRetryableError = error.hasErrorLabel(error_1.MongoErrorLabel.RetryableError);
931
+ if (!isRetryableError) {
932
+ session.transaction.transition(transactions_1.TxnState.TRANSACTION_IN_PROGRESS);
933
+ }
934
+ }
935
+ }
826
936
  }
827
937
  //# sourceMappingURL=sessions.js.map
@@ -50,12 +50,10 @@ const COMMITTED_STATES = new Set([
50
50
  exports.TxnState.TRANSACTION_ABORTED
51
51
  ]);
52
52
  /**
53
- * @public
54
- * @deprecated - Will be made internal in a future major release.
55
- * A class maintaining state related to a server transaction. Internal Only
53
+ * @internal
56
54
  */
57
55
  class Transaction {
58
- /** Create a transaction @internal */
56
+ /** Create a transaction */
59
57
  constructor(options) {
60
58
  options = options ?? {};
61
59
  this.state = exports.TxnState.NO_TRANSACTION;
@@ -80,39 +78,32 @@ class Transaction {
80
78
  this._pinnedServer = undefined;
81
79
  this._recoveryToken = undefined;
82
80
  }
83
- /** @internal */
84
81
  get server() {
85
82
  return this._pinnedServer;
86
83
  }
87
- /** @deprecated - Will be made internal in a future major release. */
88
84
  get recoveryToken() {
89
85
  return this._recoveryToken;
90
86
  }
91
- /** @deprecated - Will be made internal in a future major release. */
92
87
  get isPinned() {
93
88
  return !!this.server;
94
89
  }
95
90
  /**
96
- * @deprecated - Will be made internal in a future major release.
97
91
  * @returns Whether the transaction has started
98
92
  */
99
93
  get isStarting() {
100
94
  return this.state === exports.TxnState.STARTING_TRANSACTION;
101
95
  }
102
96
  /**
103
- * @deprecated - Will be made internal in a future major release.
104
97
  * @returns Whether this session is presently in a transaction
105
98
  */
106
99
  get isActive() {
107
100
  return ACTIVE_STATES.has(this.state);
108
101
  }
109
- /** @deprecated - Will be made internal in a future major release. */
110
102
  get isCommitted() {
111
103
  return COMMITTED_STATES.has(this.state);
112
104
  }
113
105
  /**
114
106
  * Transition the transaction in the state machine
115
- * @internal
116
107
  * @param nextState - The new state to transition to
117
108
  */
118
109
  transition(nextState) {
@@ -128,13 +119,11 @@ class Transaction {
128
119
  }
129
120
  throw new error_1.MongoRuntimeError(`Attempted illegal state transition from [${this.state}] to [${nextState}]`);
130
121
  }
131
- /** @internal */
132
122
  pinServer(server) {
133
123
  if (this.isActive) {
134
124
  this._pinnedServer = server;
135
125
  }
136
126
  }
137
- /** @internal */
138
127
  unpinServer() {
139
128
  this._pinnedServer = undefined;
140
129
  }