@nullix/zod-mongoose-studio 1.0.13 → 2.0.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 (314) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/_nuxt/{Db4IAypj.js → 0J_bLG6U.js} +1 -1
  3. package/.output/public/_nuxt/{Y39o1QEi.js → 5KLjKHc1.js} +1 -1
  4. package/.output/public/_nuxt/{B4zoPYF-.js → B2UrsJHg.js} +1 -1
  5. package/.output/public/_nuxt/{BSqjh6Vk.js → BC5hGokz.js} +1 -1
  6. package/.output/public/_nuxt/{BS4yU4O0.js → BJwN20Xm.js} +1 -1
  7. package/.output/public/_nuxt/{D8_n84hl.js → BMgDPqps.js} +1 -1
  8. package/.output/public/_nuxt/{CqNsQbt9.js → B_sGF2qN.js} +1 -1
  9. package/.output/public/_nuxt/{NAqlztEN.js → BeaJ7I-K.js} +10 -10
  10. package/.output/public/_nuxt/{WZ0WK9cR.js → BkE1sm_1.js} +1 -1
  11. package/.output/public/_nuxt/{kBtP64Rx.js → CADbZwE5.js} +1 -1
  12. package/.output/public/_nuxt/{B8qGaxNm.js → CB0WRoVi.js} +1 -1
  13. package/.output/public/_nuxt/{BV6uALfO.js → CCh0PVV0.js} +1 -1
  14. package/.output/public/_nuxt/{CP9Z7-_9.js → Cr0GW7rA.js} +1 -1
  15. package/.output/public/_nuxt/{DeCqoVOS.js → DJe7Wxdv.js} +1 -1
  16. package/.output/public/_nuxt/{dBZQW7JD.js → DRBrUaE5.js} +1 -1
  17. package/.output/public/_nuxt/{Db19R32y.js → DV2n9B6m.js} +1 -1
  18. package/.output/public/_nuxt/{CvnpbYw0.js → DVD-jGiv.js} +1 -1
  19. package/.output/public/_nuxt/{BWajNATZ.js → Dk9qGA5X.js} +3 -3
  20. package/.output/public/_nuxt/builds/latest.json +1 -1
  21. package/.output/public/_nuxt/builds/meta/dc761332-547d-4953-b51d-b2d453009b48.json +1 -0
  22. package/.output/public/_nuxt/error-404.64pZEiDn.css +1 -0
  23. package/.output/public/_nuxt/error-500.DHOpI0Ir.css +1 -0
  24. package/.output/public/_nuxt/{BoHhCIKW.js → koEZfutw.js} +3 -3
  25. package/.output/public/_nuxt/{B_782F4p.js → r6LdR7DN.js} +1 -1
  26. package/.output/public/_nuxt/{BEI71c6K.js → rEfOp38p.js} +1 -1
  27. package/.output/server/chunks/_/error-500.mjs.map +1 -1
  28. package/.output/server/chunks/build/client.precomputed.mjs +1 -1
  29. package/.output/server/chunks/build/{error-404-8tbBXju4.mjs → error-404-BN-7rNE4.mjs} +4 -4
  30. package/.output/server/chunks/build/error-404-BN-7rNE4.mjs.map +1 -0
  31. package/.output/server/chunks/build/error-404-styles.Byx46oLR.mjs +8 -0
  32. package/.output/server/chunks/build/error-404-styles.Byx46oLR.mjs.map +1 -0
  33. package/.output/server/chunks/build/{error-500-DxFsom1i.mjs → error-500-DhIQ-2yt.mjs} +4 -4
  34. package/.output/server/chunks/build/error-500-DhIQ-2yt.mjs.map +1 -0
  35. package/.output/server/chunks/build/error-500-styles.BL3UT0Wa.mjs +8 -0
  36. package/.output/server/chunks/build/error-500-styles.BL3UT0Wa.mjs.map +1 -0
  37. package/.output/server/chunks/build/{index-BB-Clavm.mjs → index-Dnrh1ePF.mjs} +1 -1
  38. package/.output/server/chunks/build/index-Dnrh1ePF.mjs.map +1 -0
  39. package/.output/server/chunks/build/server.mjs +9 -9
  40. package/.output/server/chunks/build/styles.mjs +4 -4
  41. package/.output/server/chunks/nitro/nitro.mjs +333 -333
  42. package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
  43. package/.output/server/chunks/routes/renderer.mjs.map +1 -1
  44. package/.output/server/node_modules/bson/lib/bson.cjs +157 -48
  45. package/.output/server/node_modules/bson/package.json +9 -11
  46. package/.output/server/node_modules/kareem/index.js +228 -343
  47. package/.output/server/node_modules/kareem/package.json +3 -3
  48. package/.output/server/node_modules/mongodb/lib/bson.js +27 -5
  49. package/.output/server/node_modules/mongodb/lib/bulk/common.js +7 -9
  50. package/.output/server/node_modules/mongodb/lib/change_stream.js +91 -39
  51. package/.output/server/node_modules/mongodb/lib/client-side-encryption/auto_encrypter.js +21 -14
  52. package/.output/server/node_modules/mongodb/lib/client-side-encryption/client_encryption.js +2 -5
  53. package/.output/server/node_modules/mongodb/lib/client-side-encryption/errors.js +3 -1
  54. package/.output/server/node_modules/mongodb/lib/client-side-encryption/mongocryptd_manager.js +1 -1
  55. package/.output/server/node_modules/mongodb/lib/client-side-encryption/state_machine.js +1 -0
  56. package/.output/server/node_modules/mongodb/lib/cmap/auth/aws4.js +161 -0
  57. package/.output/server/node_modules/mongodb/lib/cmap/auth/aws_temporary_credentials.js +11 -58
  58. package/.output/server/node_modules/mongodb/lib/cmap/auth/gssapi.js +4 -6
  59. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongo_credentials.js +2 -16
  60. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_aws.js +14 -23
  61. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +3 -3
  62. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +3 -3
  63. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +4 -3
  64. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +4 -3
  65. package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc.js +4 -4
  66. package/.output/server/node_modules/mongodb/lib/cmap/auth/plain.js +1 -1
  67. package/.output/server/node_modules/mongodb/lib/cmap/auth/providers.js +0 -1
  68. package/.output/server/node_modules/mongodb/lib/cmap/auth/scram.js +53 -40
  69. package/.output/server/node_modules/mongodb/lib/cmap/commands.js +46 -39
  70. package/.output/server/node_modules/mongodb/lib/cmap/connect.js +35 -3
  71. package/.output/server/node_modules/mongodb/lib/cmap/connection.js +36 -32
  72. package/.output/server/node_modules/mongodb/lib/cmap/connection_pool.js +67 -67
  73. package/.output/server/node_modules/mongodb/lib/cmap/connection_pool_events.js +3 -3
  74. package/.output/server/node_modules/mongodb/lib/cmap/errors.js +1 -1
  75. package/.output/server/node_modules/mongodb/lib/cmap/handshake/client_metadata.js +15 -13
  76. package/.output/server/node_modules/mongodb/lib/cmap/metrics.js +3 -3
  77. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/compression.js +26 -10
  78. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/constants.js +3 -1
  79. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_data.js +0 -1
  80. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_demand/document.js +9 -9
  81. package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/responses.js +2 -2
  82. package/.output/server/node_modules/mongodb/lib/collection.js +1 -1
  83. package/.output/server/node_modules/mongodb/lib/connection_string.js +30 -15
  84. package/.output/server/node_modules/mongodb/lib/cursor/abstract_cursor.js +17 -34
  85. package/.output/server/node_modules/mongodb/lib/cursor/change_stream_cursor.js +2 -2
  86. package/.output/server/node_modules/mongodb/lib/cursor/find_cursor.js +37 -26
  87. package/.output/server/node_modules/mongodb/lib/cursor/run_command_cursor.js +1 -1
  88. package/.output/server/node_modules/mongodb/lib/db.js +6 -7
  89. package/.output/server/node_modules/mongodb/lib/deps.js +0 -13
  90. package/.output/server/node_modules/mongodb/lib/error.js +7 -10
  91. package/.output/server/node_modules/mongodb/lib/gridfs/download.js +7 -6
  92. package/.output/server/node_modules/mongodb/lib/gridfs/index.js +9 -9
  93. package/.output/server/node_modules/mongodb/lib/gridfs/upload.js +17 -23
  94. package/.output/server/node_modules/mongodb/lib/index.js +2 -4
  95. package/.output/server/node_modules/mongodb/lib/mongo_client.js +58 -67
  96. package/.output/server/node_modules/mongodb/lib/mongo_client_auth_providers.js +0 -6
  97. package/.output/server/node_modules/mongodb/lib/mongo_logger.js +11 -5
  98. package/.output/server/node_modules/mongodb/lib/mongo_types.js +1 -2
  99. package/.output/server/node_modules/mongodb/lib/operations/aggregate.js +0 -3
  100. package/.output/server/node_modules/mongodb/lib/operations/create_collection.js +0 -1
  101. package/.output/server/node_modules/mongodb/lib/operations/drop.js +8 -9
  102. package/.output/server/node_modules/mongodb/lib/operations/end_sessions.js +34 -0
  103. package/.output/server/node_modules/mongodb/lib/operations/execute_operation.js +121 -45
  104. package/.output/server/node_modules/mongodb/lib/operations/operation.js +1 -0
  105. package/.output/server/node_modules/mongodb/lib/read_preference.js +10 -14
  106. package/.output/server/node_modules/mongodb/lib/runtime_adapters.js +32 -0
  107. package/.output/server/node_modules/mongodb/lib/sdam/monitor.js +8 -8
  108. package/.output/server/node_modules/mongodb/lib/sdam/server.js +55 -43
  109. package/.output/server/node_modules/mongodb/lib/sdam/server_description.js +1 -1
  110. package/.output/server/node_modules/mongodb/lib/sdam/server_selection.js +135 -72
  111. package/.output/server/node_modules/mongodb/lib/sdam/srv_polling.js +3 -3
  112. package/.output/server/node_modules/mongodb/lib/sdam/topology.js +37 -77
  113. package/.output/server/node_modules/mongodb/lib/sdam/topology_description.js +1 -1
  114. package/.output/server/node_modules/mongodb/lib/sessions.js +150 -40
  115. package/.output/server/node_modules/mongodb/lib/transactions.js +2 -13
  116. package/.output/server/node_modules/mongodb/lib/utils.js +42 -90
  117. package/.output/server/node_modules/mongodb/package.json +49 -45
  118. package/.output/server/node_modules/mongodb-connection-string-url/lib/index.js +45 -19
  119. package/.output/server/node_modules/mongodb-connection-string-url/lib/redact.js +30 -19
  120. package/.output/server/node_modules/mongodb-connection-string-url/package.json +25 -16
  121. package/.output/server/node_modules/mongoose/lib/aggregate.js +108 -127
  122. package/.output/server/node_modules/mongoose/lib/cast/bigint.js +3 -3
  123. package/.output/server/node_modules/mongoose/lib/cast/boolean.js +3 -3
  124. package/.output/server/node_modules/mongoose/lib/cast/double.js +4 -4
  125. package/.output/server/node_modules/mongoose/lib/cast/int32.js +2 -2
  126. package/.output/server/node_modules/mongoose/lib/cast/number.js +6 -6
  127. package/.output/server/node_modules/mongoose/lib/cast/string.js +3 -3
  128. package/.output/server/node_modules/mongoose/lib/cast/uuid.js +5 -48
  129. package/.output/server/node_modules/mongoose/lib/cast.js +16 -24
  130. package/.output/server/node_modules/mongoose/lib/collection.js +6 -6
  131. package/.output/server/node_modules/mongoose/lib/connection.js +108 -105
  132. package/.output/server/node_modules/mongoose/lib/cursor/aggregationCursor.js +23 -33
  133. package/.output/server/node_modules/mongoose/lib/cursor/changeStream.js +60 -40
  134. package/.output/server/node_modules/mongoose/lib/cursor/queryCursor.js +21 -25
  135. package/.output/server/node_modules/mongoose/lib/document.js +712 -531
  136. package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js +85 -130
  137. package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js +32 -41
  138. package/.output/server/node_modules/mongoose/lib/error/cast.js +21 -12
  139. package/.output/server/node_modules/mongoose/lib/error/createCollectionsError.js +2 -2
  140. package/.output/server/node_modules/mongoose/lib/error/divergentArray.js +1 -1
  141. package/.output/server/node_modules/mongoose/lib/error/eachAsyncMultiError.js +1 -1
  142. package/.output/server/node_modules/mongoose/lib/error/index.js +3 -3
  143. package/.output/server/node_modules/mongoose/lib/error/invalidSchemaOption.js +1 -1
  144. package/.output/server/node_modules/mongoose/lib/error/messages.js +1 -0
  145. package/.output/server/node_modules/mongoose/lib/error/missingSchema.js +1 -1
  146. package/.output/server/node_modules/mongoose/lib/error/objectParameter.js +4 -5
  147. package/.output/server/node_modules/mongoose/lib/error/overwriteModel.js +1 -1
  148. package/.output/server/node_modules/mongoose/lib/error/setOptionError.js +3 -3
  149. package/.output/server/node_modules/mongoose/lib/error/strict.js +3 -3
  150. package/.output/server/node_modules/mongoose/lib/error/strictPopulate.js +2 -2
  151. package/.output/server/node_modules/mongoose/lib/error/syncIndexes.js +2 -2
  152. package/.output/server/node_modules/mongoose/lib/error/validation.js +2 -10
  153. package/.output/server/node_modules/mongoose/lib/error/validator.js +1 -1
  154. package/.output/server/node_modules/mongoose/lib/error/version.js +2 -2
  155. package/.output/server/node_modules/mongoose/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
  156. package/.output/server/node_modules/mongoose/lib/helpers/buildMiddlewareFilter.js +24 -0
  157. package/.output/server/node_modules/mongoose/lib/helpers/clone.js +35 -18
  158. package/.output/server/node_modules/mongoose/lib/helpers/common.js +5 -5
  159. package/.output/server/node_modules/mongoose/lib/helpers/cursor/eachAsync.js +4 -4
  160. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getConstructor.js +1 -1
  161. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  162. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
  163. package/.output/server/node_modules/mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js +10 -5
  164. package/.output/server/node_modules/mongoose/lib/helpers/document/applyDefaults.js +1 -1
  165. package/.output/server/node_modules/mongoose/lib/helpers/document/applyTimestamps.js +11 -10
  166. package/.output/server/node_modules/mongoose/lib/helpers/document/applyVirtuals.js +10 -9
  167. package/.output/server/node_modules/mongoose/lib/helpers/document/cleanModifiedSubpaths.js +1 -1
  168. package/.output/server/node_modules/mongoose/lib/helpers/document/compile.js +17 -14
  169. package/.output/server/node_modules/mongoose/lib/helpers/document/getDeepestSubdocumentForPath.js +3 -3
  170. package/.output/server/node_modules/mongoose/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
  171. package/.output/server/node_modules/mongoose/lib/helpers/document/isInPathsToSave.js +24 -0
  172. package/.output/server/node_modules/mongoose/lib/helpers/get.js +1 -1
  173. package/.output/server/node_modules/mongoose/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
  174. package/.output/server/node_modules/mongoose/lib/helpers/indexes/getRelatedIndexes.js +3 -3
  175. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexEqual.js +3 -4
  176. package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
  177. package/.output/server/node_modules/mongoose/lib/helpers/isBsonType.js +1 -1
  178. package/.output/server/node_modules/mongoose/lib/helpers/isMongooseObject.js +1 -1
  179. package/.output/server/node_modules/mongoose/lib/helpers/isObject.js +2 -2
  180. package/.output/server/node_modules/mongoose/lib/helpers/isSimpleValidator.js +2 -2
  181. package/.output/server/node_modules/mongoose/lib/helpers/minimize.js +2 -2
  182. package/.output/server/node_modules/mongoose/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
  183. package/.output/server/node_modules/mongoose/lib/helpers/model/applyHooks.js +55 -54
  184. package/.output/server/node_modules/mongoose/lib/helpers/model/applyMethods.js +2 -2
  185. package/.output/server/node_modules/mongoose/lib/helpers/model/applyStaticHooks.js +1 -48
  186. package/.output/server/node_modules/mongoose/lib/helpers/model/castBulkWrite.js +8 -12
  187. package/.output/server/node_modules/mongoose/lib/helpers/model/discriminator.js +1 -1
  188. package/.output/server/node_modules/mongoose/lib/helpers/parallelLimit.js +18 -36
  189. package/.output/server/node_modules/mongoose/lib/helpers/pluralize.js +4 -4
  190. package/.output/server/node_modules/mongoose/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -11
  191. package/.output/server/node_modules/mongoose/lib/helpers/populate/assignVals.js +10 -10
  192. package/.output/server/node_modules/mongoose/lib/helpers/populate/createPopulateQueryFilter.js +3 -3
  193. package/.output/server/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js +197 -69
  194. package/.output/server/node_modules/mongoose/lib/helpers/populate/getSchemaTypes.js +15 -15
  195. package/.output/server/node_modules/mongoose/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  196. package/.output/server/node_modules/mongoose/lib/helpers/populate/modelNamesFromRefPath.js +10 -2
  197. package/.output/server/node_modules/mongoose/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
  198. package/.output/server/node_modules/mongoose/lib/helpers/printJestWarning.js +1 -1
  199. package/.output/server/node_modules/mongoose/lib/helpers/processConnectionOptions.js +1 -1
  200. package/.output/server/node_modules/mongoose/lib/helpers/projection/hasIncludedChildren.js +1 -1
  201. package/.output/server/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js +3 -3
  202. package/.output/server/node_modules/mongoose/lib/helpers/projection/isSubpath.js +1 -1
  203. package/.output/server/node_modules/mongoose/lib/helpers/projection/parseProjection.js +9 -4
  204. package/.output/server/node_modules/mongoose/lib/helpers/query/cast$expr.js +8 -10
  205. package/.output/server/node_modules/mongoose/lib/helpers/query/castFilterPath.js +1 -1
  206. package/.output/server/node_modules/mongoose/lib/helpers/query/castUpdate.js +44 -38
  207. package/.output/server/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js +8 -8
  208. package/.output/server/node_modules/mongoose/lib/helpers/query/handleImmutable.js +8 -8
  209. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyPlugins.js +2 -2
  210. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyReadConcern.js +1 -1
  211. package/.output/server/node_modules/mongoose/lib/helpers/schema/applyWriteConcern.js +4 -2
  212. package/.output/server/node_modules/mongoose/lib/helpers/schema/getIndexes.js +5 -11
  213. package/.output/server/node_modules/mongoose/lib/helpers/schema/getSubdocumentStrictValue.js +2 -2
  214. package/.output/server/node_modules/mongoose/lib/helpers/schema/handleIdOption.js +1 -1
  215. package/.output/server/node_modules/mongoose/lib/helpers/schema/idGetter.js +1 -1
  216. package/.output/server/node_modules/mongoose/lib/helpers/schematype/handleImmutable.js +1 -1
  217. package/.output/server/node_modules/mongoose/lib/helpers/setDefaultsOnInsert.js +26 -13
  218. package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
  219. package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setupTimestamps.js +60 -38
  220. package/.output/server/node_modules/mongoose/lib/helpers/update/applyTimestampsToUpdate.js +13 -10
  221. package/.output/server/node_modules/mongoose/lib/helpers/update/castArrayFilters.js +4 -4
  222. package/.output/server/node_modules/mongoose/lib/helpers/update/decorateUpdateWithVersionKey.js +1 -1
  223. package/.output/server/node_modules/mongoose/lib/helpers/update/modifiedPaths.js +2 -2
  224. package/.output/server/node_modules/mongoose/lib/helpers/update/removeUnusedArrayFilters.js +7 -2
  225. package/.output/server/node_modules/mongoose/lib/helpers/updateValidators.js +58 -119
  226. package/.output/server/node_modules/mongoose/lib/model.js +940 -946
  227. package/.output/server/node_modules/mongoose/lib/mongoose.js +131 -79
  228. package/.output/server/node_modules/mongoose/lib/options/schemaArrayOptions.js +2 -2
  229. package/.output/server/node_modules/mongoose/lib/options/schemaBufferOptions.js +1 -1
  230. package/.output/server/node_modules/mongoose/lib/options/schemaDocumentArrayOptions.js +23 -0
  231. package/.output/server/node_modules/mongoose/lib/options/schemaNumberOptions.js +3 -3
  232. package/.output/server/node_modules/mongoose/lib/options/schemaObjectIdOptions.js +2 -2
  233. package/.output/server/node_modules/mongoose/lib/options/schemaStringOptions.js +6 -6
  234. package/.output/server/node_modules/mongoose/lib/options/schemaSubdocumentOptions.js +23 -0
  235. package/.output/server/node_modules/mongoose/lib/options/schemaTypeOptions.js +27 -13
  236. package/.output/server/node_modules/mongoose/lib/options/virtualOptions.js +12 -12
  237. package/.output/server/node_modules/mongoose/lib/plugins/index.js +0 -1
  238. package/.output/server/node_modules/mongoose/lib/plugins/saveSubdocs.js +84 -92
  239. package/.output/server/node_modules/mongoose/lib/plugins/sharding.js +33 -15
  240. package/.output/server/node_modules/mongoose/lib/plugins/trackTransaction.js +29 -25
  241. package/.output/server/node_modules/mongoose/lib/query.js +700 -548
  242. package/.output/server/node_modules/mongoose/lib/queryHelpers.js +34 -32
  243. package/.output/server/node_modules/mongoose/lib/schema/array.js +69 -113
  244. package/.output/server/node_modules/mongoose/lib/schema/bigint.js +18 -20
  245. package/.output/server/node_modules/mongoose/lib/schema/boolean.js +20 -22
  246. package/.output/server/node_modules/mongoose/lib/schema/buffer.js +23 -25
  247. package/.output/server/node_modules/mongoose/lib/schema/date.js +19 -21
  248. package/.output/server/node_modules/mongoose/lib/schema/decimal128.js +16 -18
  249. package/.output/server/node_modules/mongoose/lib/schema/documentArray.js +94 -131
  250. package/.output/server/node_modules/mongoose/lib/schema/documentArrayElement.js +50 -16
  251. package/.output/server/node_modules/mongoose/lib/schema/double.js +16 -18
  252. package/.output/server/node_modules/mongoose/lib/schema/index.js +1 -0
  253. package/.output/server/node_modules/mongoose/lib/schema/int32.js +17 -19
  254. package/.output/server/node_modules/mongoose/lib/schema/map.js +17 -24
  255. package/.output/server/node_modules/mongoose/lib/schema/mixed.js +14 -14
  256. package/.output/server/node_modules/mongoose/lib/schema/number.js +38 -28
  257. package/.output/server/node_modules/mongoose/lib/schema/objectId.js +18 -20
  258. package/.output/server/node_modules/mongoose/lib/schema/operators/exists.js +1 -1
  259. package/.output/server/node_modules/mongoose/lib/schema/operators/geospatial.js +1 -1
  260. package/.output/server/node_modules/mongoose/lib/schema/operators/text.js +4 -4
  261. package/.output/server/node_modules/mongoose/lib/schema/string.js +42 -27
  262. package/.output/server/node_modules/mongoose/lib/schema/subdocument.js +47 -58
  263. package/.output/server/node_modules/mongoose/lib/schema/union.js +54 -4
  264. package/.output/server/node_modules/mongoose/lib/schema/uuid.js +17 -40
  265. package/.output/server/node_modules/mongoose/lib/schema.js +235 -176
  266. package/.output/server/node_modules/mongoose/lib/schemaType.js +227 -158
  267. package/.output/server/node_modules/mongoose/lib/stateMachine.js +5 -8
  268. package/.output/server/node_modules/mongoose/lib/types/array/index.js +5 -5
  269. package/.output/server/node_modules/mongoose/lib/types/array/methods/index.js +27 -28
  270. package/.output/server/node_modules/mongoose/lib/types/arraySubdocument.js +11 -11
  271. package/.output/server/node_modules/mongoose/lib/types/buffer.js +15 -15
  272. package/.output/server/node_modules/mongoose/lib/types/decimal128.js +1 -1
  273. package/.output/server/node_modules/mongoose/lib/types/documentArray/index.js +4 -4
  274. package/.output/server/node_modules/mongoose/lib/types/documentArray/methods/index.js +15 -13
  275. package/.output/server/node_modules/mongoose/lib/types/double.js +1 -1
  276. package/.output/server/node_modules/mongoose/lib/types/map.js +20 -71
  277. package/.output/server/node_modules/mongoose/lib/types/objectid.js +1 -1
  278. package/.output/server/node_modules/mongoose/lib/types/subdocument.js +32 -81
  279. package/.output/server/node_modules/mongoose/lib/types/uuid.js +1 -1
  280. package/.output/server/node_modules/mongoose/lib/utils.js +91 -70
  281. package/.output/server/node_modules/mongoose/lib/validOptions.js +4 -3
  282. package/.output/server/node_modules/mongoose/lib/virtualType.js +18 -18
  283. package/.output/server/node_modules/mongoose/package.json +46 -63
  284. package/.output/server/node_modules/mquery/lib/collection/collection.js +3 -1
  285. package/.output/server/node_modules/mquery/lib/collection/node.js +17 -3
  286. package/.output/server/node_modules/mquery/lib/mquery.js +136 -93
  287. package/.output/server/node_modules/mquery/lib/permissions.js +21 -6
  288. package/.output/server/node_modules/mquery/package.json +4 -7
  289. package/.output/server/package.json +7 -9
  290. package/package.json +3 -3
  291. package/.output/public/_nuxt/builds/meta/0d6006db-fbb0-4297-85cf-bf92ceafcb79.json +0 -1
  292. package/.output/public/_nuxt/error-404.CTWLHxjC.css +0 -1
  293. package/.output/public/_nuxt/error-500.UBfk8-QP.css +0 -1
  294. package/.output/server/chunks/build/error-404-8tbBXju4.mjs.map +0 -1
  295. package/.output/server/chunks/build/error-404-styles.BeWfK6Py.mjs +0 -8
  296. package/.output/server/chunks/build/error-404-styles.BeWfK6Py.mjs.map +0 -1
  297. package/.output/server/chunks/build/error-500-DxFsom1i.mjs.map +0 -1
  298. package/.output/server/chunks/build/error-500-styles.CPUUvoY-.mjs +0 -8
  299. package/.output/server/chunks/build/error-500-styles.CPUUvoY-.mjs.map +0 -1
  300. package/.output/server/chunks/build/index-BB-Clavm.mjs.map +0 -1
  301. package/.output/server/node_modules/debug/package.json +0 -64
  302. package/.output/server/node_modules/debug/src/browser.js +0 -272
  303. package/.output/server/node_modules/debug/src/common.js +0 -292
  304. package/.output/server/node_modules/debug/src/index.js +0 -10
  305. package/.output/server/node_modules/debug/src/node.js +0 -263
  306. package/.output/server/node_modules/mongodb/lib/client-side-encryption/crypto_callbacks.js +0 -81
  307. package/.output/server/node_modules/mongodb/lib/resource_management.js +0 -58
  308. package/.output/server/node_modules/mongoose/lib/browserDocument.js +0 -101
  309. package/.output/server/node_modules/mongoose/lib/documentProvider.js +0 -30
  310. package/.output/server/node_modules/mongoose/lib/helpers/createJSONSchemaTypeDefinition.js +0 -24
  311. package/.output/server/node_modules/mongoose/lib/helpers/promiseOrCallback.js +0 -54
  312. package/.output/server/node_modules/mongoose/lib/plugins/validateBeforeSave.js +0 -51
  313. package/.output/server/node_modules/supports-color/index.js +0 -202
  314. package/.output/server/node_modules/supports-color/package.json +0 -64
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpCompressedRequest = exports.OpMsgResponse = exports.OpMsgRequest = exports.DocumentSequence = exports.OpReply = exports.OpQueryRequest = void 0;
4
- const BSON = require("../bson");
4
+ const bson_1 = require("../bson");
5
5
  const error_1 = require("../error");
6
6
  const compression_1 = require("./wire_protocol/compression");
7
7
  const constants_1 = require("./wire_protocol/constants");
@@ -20,7 +20,7 @@ const CURSOR_NOT_FOUND = 1;
20
20
  const QUERY_FAILURE = 2;
21
21
  const SHARD_CONFIG_STALE = 4;
22
22
  const AWAIT_CAPABLE = 8;
23
- const encodeUTF8Into = BSON.BSON.onDemand.ByteUtils.encodeUTF8Into;
23
+ const encodeUTF8Into = bson_1.ByteUtils.encodeUTF8Into;
24
24
  /** @internal */
25
25
  class OpQueryRequest {
26
26
  constructor(databaseName, query, options) {
@@ -111,9 +111,9 @@ class OpQueryRequest {
111
111
  if (this.batchSize !== this.numberToReturn)
112
112
  this.numberToReturn = this.batchSize;
113
113
  // Allocate write protocol header buffer
114
- const header = Buffer.alloc(4 * 4 + // Header
114
+ const header = bson_1.ByteUtils.allocate(4 * 4 + // Header
115
115
  4 + // Flags
116
- Buffer.byteLength(this.ns) +
116
+ bson_1.ByteUtils.utf8ByteLength(this.ns) +
117
117
  1 + // namespace
118
118
  4 + // numberToSkip
119
119
  4 // numberToReturn
@@ -121,7 +121,7 @@ class OpQueryRequest {
121
121
  // Add header to buffers
122
122
  buffers.push(header);
123
123
  // Serialize the query
124
- const query = BSON.serialize(this.query, {
124
+ const query = bson_1.BSON.serialize(this.query, {
125
125
  checkKeys: this.checkKeys,
126
126
  serializeFunctions: this.serializeFunctions,
127
127
  ignoreUndefined: this.ignoreUndefined
@@ -130,7 +130,7 @@ class OpQueryRequest {
130
130
  buffers.push(query);
131
131
  if (this.returnFieldSelector && Object.keys(this.returnFieldSelector).length > 0) {
132
132
  // Serialize the projection document
133
- projection = BSON.serialize(this.returnFieldSelector, {
133
+ projection = bson_1.BSON.serialize(this.returnFieldSelector, {
134
134
  checkKeys: this.checkKeys,
135
135
  serializeFunctions: this.serializeFunctions,
136
136
  ignoreUndefined: this.ignoreUndefined
@@ -172,7 +172,7 @@ class OpQueryRequest {
172
172
  header[index] = flags & 0xff;
173
173
  index = index + 4;
174
174
  // Write collection name
175
- index = index + header.write(this.ns, index, 'utf8') + 1;
175
+ index = index + encodeUTF8Into(header, this.ns, index) + 1;
176
176
  header[index - 1] = 0;
177
177
  // Write header information flags numberToSkip
178
178
  header[index + 3] = (this.numberToSkip >> 24) & 0xff;
@@ -234,10 +234,10 @@ class OpReply {
234
234
  // (See https://www.mongodb.com/docs/manual/reference/mongodb-wire-protocol/#wire-op-reply)
235
235
  this.index = 20;
236
236
  // Read the message body
237
- this.responseFlags = this.data.readInt32LE(0);
238
- this.cursorId = new BSON.Long(this.data.readInt32LE(4), this.data.readInt32LE(8));
239
- this.startingFrom = this.data.readInt32LE(12);
240
- this.numberReturned = this.data.readInt32LE(16);
237
+ this.responseFlags = (0, bson_1.readInt32LE)(this.data, 0);
238
+ this.cursorId = new bson_1.BSON.Long((0, bson_1.readInt32LE)(this.data, 4), (0, bson_1.readInt32LE)(this.data, 8));
239
+ this.startingFrom = (0, bson_1.readInt32LE)(this.data, 12);
240
+ this.numberReturned = (0, bson_1.readInt32LE)(this.data, 16);
241
241
  if (this.numberReturned < 0 || this.numberReturned > 2 ** 32 - 1) {
242
242
  throw new RangeError(`OP_REPLY numberReturned is an invalid array length ${this.numberReturned}`);
243
243
  }
@@ -279,7 +279,7 @@ class DocumentSequence {
279
279
  this.serializedDocumentsLength = 0;
280
280
  // Document sequences starts with type 1 at the first byte.
281
281
  // Field strings must always be UTF-8.
282
- const buffer = Buffer.allocUnsafe(1 + 4 + this.field.length + 1);
282
+ const buffer = bson_1.ByteUtils.allocateUnsafe(1 + 4 + this.field.length + 1);
283
283
  buffer[0] = 1;
284
284
  // Third part is the field name at offset 5 with trailing null byte.
285
285
  encodeUTF8Into(buffer, `${this.field}\0`, 5);
@@ -287,7 +287,7 @@ class DocumentSequence {
287
287
  this.header = buffer;
288
288
  if (documents) {
289
289
  for (const doc of documents) {
290
- this.push(doc, BSON.serialize(doc));
290
+ this.push(doc, bson_1.BSON.serialize(doc));
291
291
  }
292
292
  }
293
293
  }
@@ -305,7 +305,9 @@ class DocumentSequence {
305
305
  // Push the document raw bson.
306
306
  this.chunks.push(buffer);
307
307
  // Write the new length.
308
- this.header?.writeInt32LE(4 + this.field.length + 1 + this.serializedDocumentsLength, 1);
308
+ if (this.header) {
309
+ bson_1.NumberUtils.setInt32LE(this.header, 1, 4 + this.field.length + 1 + this.serializedDocumentsLength);
310
+ }
309
311
  return this.serializedDocumentsLength + this.header.length;
310
312
  }
311
313
  /**
@@ -313,7 +315,7 @@ class DocumentSequence {
313
315
  * @returns The section bytes.
314
316
  */
315
317
  toBin() {
316
- return Buffer.concat(this.chunks);
318
+ return bson_1.ByteUtils.concat(this.chunks);
317
319
  }
318
320
  }
319
321
  exports.DocumentSequence = DocumentSequence;
@@ -356,18 +358,20 @@ class OpMsgRequest {
356
358
  if (this.exhaustAllowed) {
357
359
  flags |= OPTS_EXHAUST_ALLOWED;
358
360
  }
359
- const header = Buffer.alloc(4 * 4 + // Header
361
+ const header = bson_1.ByteUtils.allocate(4 * 4 + // Header
360
362
  4 // Flags
361
363
  );
362
364
  buffers.push(header);
363
365
  let totalLength = header.length;
364
366
  const command = this.command;
365
367
  totalLength += this.makeSections(buffers, command);
366
- header.writeInt32LE(totalLength, 0); // messageLength
367
- header.writeInt32LE(this.requestId, 4); // requestID
368
- header.writeInt32LE(0, 8); // responseTo
369
- header.writeInt32LE(constants_1.OP_MSG, 12); // opCode
370
- header.writeUInt32LE(flags, 16); // flags
368
+ bson_1.NumberUtils.setInt32LE(header, 0, totalLength); // messageLength
369
+ bson_1.NumberUtils.setInt32LE(header, 4, this.requestId); // requestID
370
+ bson_1.NumberUtils.setInt32LE(header, 8, 0); // responseTo
371
+ bson_1.NumberUtils.setInt32LE(header, 12, constants_1.OP_MSG); // opCode
372
+ // The OP_MSG spec calls out that flags is uint32:
373
+ // https://github.com/mongodb/specifications/blob/master/source/message/OP_MSG.md#op_msg-1
374
+ (0, bson_1.setUint32LE)(header, 16, flags); // flags
371
375
  return buffers;
372
376
  }
373
377
  /**
@@ -375,7 +379,7 @@ class OpMsgRequest {
375
379
  */
376
380
  makeSections(buffers, document) {
377
381
  const sequencesBuffer = this.extractDocumentSequences(document);
378
- const payloadTypeBuffer = Buffer.allocUnsafe(1);
382
+ const payloadTypeBuffer = bson_1.ByteUtils.allocateUnsafe(1);
379
383
  payloadTypeBuffer[0] = 0;
380
384
  const documentBuffer = this.serializeBson(document);
381
385
  // First section, type 0
@@ -407,14 +411,14 @@ class OpMsgRequest {
407
411
  }
408
412
  }
409
413
  if (chunks.length > 0) {
410
- return Buffer.concat(chunks);
414
+ return bson_1.ByteUtils.concat(chunks);
411
415
  }
412
416
  // If we have no document sequences we return an empty buffer for nothing to add
413
417
  // to the payload.
414
- return Buffer.alloc(0);
418
+ return bson_1.ByteUtils.allocate(0);
415
419
  }
416
420
  serializeBson(document) {
417
- return BSON.serialize(document, {
421
+ return bson_1.BSON.serialize(document, {
418
422
  checkKeys: this.checkKeys,
419
423
  serializeFunctions: this.serializeFunctions,
420
424
  ignoreUndefined: this.ignoreUndefined
@@ -448,7 +452,7 @@ class OpMsgResponse {
448
452
  this.opCode = msgHeader.opCode;
449
453
  this.fromCompressed = msgHeader.fromCompressed;
450
454
  // Read response flags
451
- this.responseFlags = msgBody.readInt32LE(0);
455
+ this.responseFlags = (0, bson_1.readInt32LE)(msgBody, 0);
452
456
  this.checksumPresent = (this.responseFlags & OPTS_CHECKSUM_PRESENT) !== 0;
453
457
  this.moreToCome = (this.responseFlags & OPTS_MORE_TO_COME) !== 0;
454
458
  this.exhaustAllowed = (this.responseFlags & OPTS_EXHAUST_ALLOWED) !== 0;
@@ -469,9 +473,12 @@ class OpMsgResponse {
469
473
  return this.sections[0];
470
474
  this.index = 4;
471
475
  while (this.index < this.data.length) {
472
- const payloadType = this.data.readUInt8(this.index++);
476
+ const payloadType = this.data[this.index++];
473
477
  if (payloadType === 0) {
474
- const bsonSize = this.data.readUInt32LE(this.index);
478
+ // BSON spec specifies that this is a 32-bit signed integer: https://bsonspec.org/spec.html#:~:text=%3A%3A%3D-,int32,-e_list%20unsigned_byte(0
479
+ // While allowing negative sizes seems odd, in practice we never expect a negative size. Also, the server's 16mb limit for BSON documents leaves plenty
480
+ // of room in an int32 to store a document of the max BSON size that the server supports
481
+ const bsonSize = (0, bson_1.readInt32LE)(this.data, this.index);
475
482
  const bin = this.data.subarray(this.index, this.index + bsonSize);
476
483
  this.sections.push(bin);
477
484
  this.index += bsonSize;
@@ -510,24 +517,24 @@ class OpCompressedRequest {
510
517
  return !compression_1.uncompressibleCommands.has(commandName);
511
518
  }
512
519
  async toBin() {
513
- const concatenatedOriginalCommandBuffer = Buffer.concat(this.command.toBin());
520
+ const concatenatedOriginalCommandBuffer = bson_1.ByteUtils.concat(this.command.toBin());
514
521
  // otherwise, compress the message
515
522
  const messageToBeCompressed = concatenatedOriginalCommandBuffer.slice(MESSAGE_HEADER_SIZE);
516
523
  // Extract information needed for OP_COMPRESSED from the uncompressed message
517
- const originalCommandOpCode = concatenatedOriginalCommandBuffer.readInt32LE(12);
524
+ const originalCommandOpCode = (0, bson_1.readInt32LE)(concatenatedOriginalCommandBuffer, 12);
518
525
  // Compress the message body
519
526
  const compressedMessage = await (0, compression_1.compress)(this.options, messageToBeCompressed);
520
527
  // Create the msgHeader of OP_COMPRESSED
521
- const msgHeader = Buffer.alloc(MESSAGE_HEADER_SIZE);
522
- msgHeader.writeInt32LE(MESSAGE_HEADER_SIZE + COMPRESSION_DETAILS_SIZE + compressedMessage.length, 0); // messageLength
523
- msgHeader.writeInt32LE(this.command.requestId, 4); // requestID
524
- msgHeader.writeInt32LE(0, 8); // responseTo (zero)
525
- msgHeader.writeInt32LE(constants_1.OP_COMPRESSED, 12); // opCode
528
+ const msgHeader = bson_1.ByteUtils.allocate(MESSAGE_HEADER_SIZE);
529
+ bson_1.NumberUtils.setInt32LE(msgHeader, 0, MESSAGE_HEADER_SIZE + COMPRESSION_DETAILS_SIZE + compressedMessage.length); // messageLength
530
+ bson_1.NumberUtils.setInt32LE(msgHeader, 4, this.command.requestId); // requestID
531
+ bson_1.NumberUtils.setInt32LE(msgHeader, 8, 0); // responseTo (zero)
532
+ bson_1.NumberUtils.setInt32LE(msgHeader, 12, constants_1.OP_COMPRESSED); // opCode
526
533
  // Create the compression details of OP_COMPRESSED
527
- const compressionDetails = Buffer.alloc(COMPRESSION_DETAILS_SIZE);
528
- compressionDetails.writeInt32LE(originalCommandOpCode, 0); // originalOpcode
529
- compressionDetails.writeInt32LE(messageToBeCompressed.length, 4); // Size of the uncompressed compressedMessage, excluding the MsgHeader
530
- compressionDetails.writeUInt8(compression_1.Compressor[this.options.agreedCompressor], 8); // compressorID
534
+ const compressionDetails = bson_1.ByteUtils.allocate(COMPRESSION_DETAILS_SIZE);
535
+ bson_1.NumberUtils.setInt32LE(compressionDetails, 0, originalCommandOpCode); // originalOpcode
536
+ bson_1.NumberUtils.setInt32LE(compressionDetails, 4, messageToBeCompressed.length); // Size of the uncompressed compressedMessage, excluding the MsgHeader
537
+ compressionDetails[8] = compression_1.Compressor[this.options.agreedCompressor]; // compressorID
531
538
  return [msgHeader, compressionDetails, compressedMessage];
532
539
  }
533
540
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LEGAL_TCP_SOCKET_OPTIONS = exports.LEGAL_TLS_SOCKET_OPTIONS = void 0;
3
+ exports.LEGAL_TCP_SOCKET_OPTIONS = exports.LEGAL_TLS_SOCKET_OPTIONS = exports.DEFAULT_KEEP_ALIVE_INITIAL_DELAY_MS = void 0;
4
4
  exports.connect = connect;
5
5
  exports.makeConnection = makeConnection;
6
6
  exports.performInitialHandshake = performInitialHandshake;
@@ -16,6 +16,10 @@ const auth_provider_1 = require("./auth/auth_provider");
16
16
  const providers_1 = require("./auth/providers");
17
17
  const connection_1 = require("./connection");
18
18
  const constants_2 = require("./wire_protocol/constants");
19
+ function applyBackpressureLabels(error) {
20
+ error.addErrorLabel(error_1.MongoErrorLabel.SystemOverloadedError);
21
+ error.addErrorLabel(error_1.MongoErrorLabel.RetryableError);
22
+ }
19
23
  async function connect(options) {
20
24
  let connection = null;
21
25
  try {
@@ -61,6 +65,8 @@ async function performInitialHandshake(conn, options) {
61
65
  }
62
66
  const authContext = new auth_provider_1.AuthContext(conn, credentials, options);
63
67
  conn.authContext = authContext;
68
+ // If we encounter an error preparing the handshake document, do NOT apply backpressure labels. Errors
69
+ // encountered building the handshake document are all client-side, and do not indicate an overloaded server.
64
70
  const handshakeDoc = await prepareHandshakeDocument(authContext);
65
71
  // @ts-expect-error: TODO(NODE-5141): The options need to be filtered properly, Connection options differ from Command options
66
72
  const handshakeOptions = { ...options, raw: false };
@@ -104,6 +110,7 @@ async function performInitialHandshake(conn, options) {
104
110
  await provider.auth(authContext);
105
111
  }
106
112
  catch (error) {
113
+ // NOTE: If we encounter an error authenticating a connection, do NOT apply backpressure labels.
107
114
  if (error instanceof error_1.MongoError) {
108
115
  error.addErrorLabel(error_1.MongoErrorLabel.HandshakeError);
109
116
  if ((0, error_1.needsRetryableWriteLabel)(error, response.maxWireVersion, conn.description.type)) {
@@ -125,6 +132,10 @@ async function performInitialHandshake(conn, options) {
125
132
  if (error instanceof error_1.MongoError) {
126
133
  error.addErrorLabel(error_1.MongoErrorLabel.HandshakeError);
127
134
  }
135
+ // If we encounter a network error executing the initial handshake, apply backpressure labels.
136
+ if (error instanceof error_1.MongoNetworkError) {
137
+ applyBackpressureLabels(error);
138
+ }
128
139
  throw error;
129
140
  }
130
141
  }
@@ -138,9 +149,10 @@ async function prepareHandshakeDocument(authContext) {
138
149
  const options = authContext.options;
139
150
  const compressors = options.compressors ? options.compressors : [];
140
151
  const { serverApi } = authContext.connection;
141
- const clientMetadata = await options.extendedMetadata;
152
+ const clientMetadata = await options.metadata;
142
153
  const handshakeDoc = {
143
154
  [serverApi?.version || options.loadBalanced === true ? 'hello' : constants_1.LEGACY_HELLO_COMMAND]: 1,
155
+ backpressure: true,
144
156
  helloOk: true,
145
157
  client: clientMetadata,
146
158
  compression: compressors
@@ -167,6 +179,14 @@ async function prepareHandshakeDocument(authContext) {
167
179
  }
168
180
  return handshakeDoc;
169
181
  }
182
+ /**
183
+ * @internal
184
+ * Default TCP keepAlive initial delay in milliseconds.
185
+ * Set to half the Azure load balancer idle timeout (240s) to ensure
186
+ * probes fire well before cloud LBs (Azure, AWS PrivateLink/NLB)
187
+ * drop idle connections.
188
+ */
189
+ exports.DEFAULT_KEEP_ALIVE_INITIAL_DELAY_MS = 120_000;
170
190
  /** @public */
171
191
  exports.LEGAL_TLS_SOCKET_OPTIONS = [
172
192
  'allowPartialTrustChain',
@@ -208,7 +228,7 @@ function parseConnectOptions(options) {
208
228
  result[name] = options[name];
209
229
  }
210
230
  }
211
- result.keepAliveInitialDelay ??= 120000;
231
+ result.keepAliveInitialDelay ??= exports.DEFAULT_KEEP_ALIVE_INITIAL_DELAY_MS;
212
232
  result.keepAlive = true;
213
233
  result.noDelay = options.noDelay ?? true;
214
234
  if (typeof hostAddress.socketPath === 'string') {
@@ -248,6 +268,8 @@ async function makeSocket(options) {
248
268
  const useTLS = options.tls ?? false;
249
269
  const connectTimeoutMS = options.connectTimeoutMS ?? 30000;
250
270
  const existingSocket = options.existingSocket;
271
+ const keepAliveInitialDelay = options.keepAliveInitialDelay ?? exports.DEFAULT_KEEP_ALIVE_INITIAL_DELAY_MS;
272
+ const noDelay = options.noDelay ?? true;
251
273
  let socket;
252
274
  if (options.proxyHost != null) {
253
275
  // Currently, only Socks5 is supported.
@@ -272,6 +294,12 @@ async function makeSocket(options) {
272
294
  else {
273
295
  socket = net.createConnection(parseConnectOptions(options));
274
296
  }
297
+ // Explicit setKeepAlive/setNoDelay are required because tls.connect() silently
298
+ // ignores these constructor options due to a Node.js bug.
299
+ // See: https://github.com/nodejs/node/issues/62003
300
+ // TODO(NODE-7474): remove this fix once the underlying Node.js issue is resolved.
301
+ socket.setKeepAlive(true, keepAliveInitialDelay);
302
+ socket.setNoDelay(noDelay);
275
303
  socket.setTimeout(connectTimeoutMS);
276
304
  let cancellationHandler = null;
277
305
  const { promise: connectedSocket, resolve, reject } = (0, utils_1.promiseWithResolvers)();
@@ -298,6 +326,10 @@ async function makeSocket(options) {
298
326
  return socket;
299
327
  }
300
328
  catch (error) {
329
+ // If we encounter an error while establishing a socket, apply the backpressure labels to it. We cannot
330
+ // differentiate between DNS, TLS errors and network errors without refactoring our connection establishment to
331
+ // handle all three steps separately.
332
+ applyBackpressureLabels(error);
301
333
  socket.destroy();
302
334
  throw error;
303
335
  }
@@ -36,10 +36,24 @@ function streamIdentifier(stream, options) {
36
36
  if (typeof remoteAddress === 'string' && typeof remotePort === 'number') {
37
37
  return utils_1.HostAddress.fromHostPort(remoteAddress, remotePort).toString();
38
38
  }
39
- return (0, utils_1.uuidV4)().toString('hex');
39
+ return bson_1.ByteUtils.toHex((0, utils_1.uuidV4)());
40
40
  }
41
41
  /** @internal */
42
42
  class Connection extends mongo_types_1.TypedEventEmitter {
43
+ /** @event */
44
+ static { this.COMMAND_STARTED = constants_1.COMMAND_STARTED; }
45
+ /** @event */
46
+ static { this.COMMAND_SUCCEEDED = constants_1.COMMAND_SUCCEEDED; }
47
+ /** @event */
48
+ static { this.COMMAND_FAILED = constants_1.COMMAND_FAILED; }
49
+ /** @event */
50
+ static { this.CLUSTER_TIME_RECEIVED = constants_1.CLUSTER_TIME_RECEIVED; }
51
+ /** @event */
52
+ static { this.CLOSE = constants_1.CLOSE; }
53
+ /** @event */
54
+ static { this.PINNED = constants_1.PINNED; }
55
+ /** @event */
56
+ static { this.UNPINNED = constants_1.UNPINNED; }
43
57
  constructor(stream, options) {
44
58
  super();
45
59
  this.lastHelloMS = -1;
@@ -61,7 +75,7 @@ class Connection extends mongo_types_1.TypedEventEmitter {
61
75
  this.established = false;
62
76
  this.description = new stream_description_1.StreamDescription(this.address, options);
63
77
  this.generation = options.generation;
64
- this.lastUseTime = (0, utils_1.now)();
78
+ this.lastUseTime = (0, utils_1.processTimeMS)();
65
79
  this.messageStream = this.socket
66
80
  .on('error', this.onSocketError.bind(this))
67
81
  .pipe(new SizedMessageTransform({ connection: this }))
@@ -104,7 +118,7 @@ class Connection extends mongo_types_1.TypedEventEmitter {
104
118
  false);
105
119
  }
106
120
  markAvailable() {
107
- this.lastUseTime = (0, utils_1.now)();
121
+ this.lastUseTime = (0, utils_1.processTimeMS)();
108
122
  }
109
123
  onSocketError(cause) {
110
124
  this.onError(new error_1.MongoNetworkError(cause.message, { cause }));
@@ -242,7 +256,7 @@ class Connection extends mongo_types_1.TypedEventEmitter {
242
256
  timeoutContext: options.timeoutContext,
243
257
  signal: options.signal
244
258
  });
245
- if (options.noResponse || message.moreToCome) {
259
+ if (message.moreToCome) {
246
260
  yield responses_1.MongoDBResponse.empty;
247
261
  return;
248
262
  }
@@ -270,7 +284,7 @@ class Connection extends mongo_types_1.TypedEventEmitter {
270
284
  const message = this.prepareCommand(ns.db, command, options);
271
285
  let started = 0;
272
286
  if (this.shouldEmitAndLogCommand) {
273
- started = (0, utils_1.now)();
287
+ started = (0, utils_1.processTimeMS)();
274
288
  this.emitAndLogCommand(this.monitorCommands, Connection.COMMAND_STARTED, message.databaseName, this.established, new command_monitoring_events_1.CommandStartedEvent(this, message, this.description.serverConnectionId));
275
289
  }
276
290
  // If `documentsReturnedIn` not set or raw is not enabled, use input bson options
@@ -306,11 +320,7 @@ class Connection extends mongo_types_1.TypedEventEmitter {
306
320
  throw new error_1.MongoServerError((object ??= document.toObject(bsonOptions)));
307
321
  }
308
322
  if (this.shouldEmitAndLogCommand) {
309
- this.emitAndLogCommand(this.monitorCommands, Connection.COMMAND_SUCCEEDED, message.databaseName, this.established, new command_monitoring_events_1.CommandSucceededEvent(this, message, options.noResponse
310
- ? undefined
311
- : message.moreToCome
312
- ? { ok: 1 }
313
- : (object ??= document.toObject(bsonOptions)), started, this.description.serverConnectionId));
323
+ this.emitAndLogCommand(this.monitorCommands, Connection.COMMAND_SUCCEEDED, message.databaseName, this.established, new command_monitoring_events_1.CommandSucceededEvent(this, message, message.moreToCome ? { ok: 1 } : (object ??= document.toObject(bsonOptions)), started, this.description.serverConnectionId));
314
324
  }
315
325
  if (responseType == null) {
316
326
  yield (object ??= document.toObject(bsonOptions));
@@ -322,6 +332,9 @@ class Connection extends mongo_types_1.TypedEventEmitter {
322
332
  }
323
333
  }
324
334
  catch (error) {
335
+ if (options.session != null && !(error instanceof error_1.MongoServerError)) {
336
+ (0, sessions_1.updateSessionFromResponse)(options.session, responses_1.MongoDBResponse.empty);
337
+ }
325
338
  if (this.shouldEmitAndLogCommand) {
326
339
  this.emitAndLogCommand(this.monitorCommands, Connection.COMMAND_FAILED, message.databaseName, this.established, new command_monitoring_events_1.CommandFailedEvent(this, message, error, started, this.description.serverConnectionId));
327
340
  }
@@ -382,15 +395,24 @@ class Connection extends mongo_types_1.TypedEventEmitter {
382
395
  agreedCompressor: options.agreedCompressor ?? 'none',
383
396
  zlibCompressionLevel: options.zlibCompressionLevel ?? 0
384
397
  });
385
- const buffer = Buffer.concat(await finalCommand.toBin());
398
+ const buffer = bson_1.ByteUtils.concat(await finalCommand.toBin());
386
399
  if (options.timeoutContext?.csotEnabled()) {
387
400
  if (options.timeoutContext.minRoundTripTime != null &&
388
401
  options.timeoutContext.remainingTimeMS < options.timeoutContext.minRoundTripTime) {
389
402
  throw new error_1.MongoOperationTimeoutError('Server roundtrip time is greater than the time remaining');
390
403
  }
391
404
  }
392
- if (this.socket.write(buffer))
393
- return;
405
+ try {
406
+ if (this.socket.write(buffer))
407
+ return;
408
+ }
409
+ catch (writeError) {
410
+ const networkError = new error_1.MongoNetworkError('unexpected error writing to socket', {
411
+ cause: writeError
412
+ });
413
+ this.onError(networkError);
414
+ throw networkError;
415
+ }
394
416
  const drainEvent = (0, utils_1.once)(this.socket, 'drain', options);
395
417
  const timeout = options?.timeoutContext?.timeoutForSocketWrite;
396
418
  const drained = timeout ? Promise.race([drainEvent, timeout]) : drainEvent;
@@ -452,20 +474,6 @@ class Connection extends mongo_types_1.TypedEventEmitter {
452
474
  }
453
475
  }
454
476
  exports.Connection = Connection;
455
- /** @event */
456
- Connection.COMMAND_STARTED = constants_1.COMMAND_STARTED;
457
- /** @event */
458
- Connection.COMMAND_SUCCEEDED = constants_1.COMMAND_SUCCEEDED;
459
- /** @event */
460
- Connection.COMMAND_FAILED = constants_1.COMMAND_FAILED;
461
- /** @event */
462
- Connection.CLUSTER_TIME_RECEIVED = constants_1.CLUSTER_TIME_RECEIVED;
463
- /** @event */
464
- Connection.CLOSE = constants_1.CLOSE;
465
- /** @event */
466
- Connection.PINNED = constants_1.PINNED;
467
- /** @event */
468
- Connection.UNPINNED = constants_1.UNPINNED;
469
477
  /** @internal */
470
478
  class SizedMessageTransform extends stream_1.Transform {
471
479
  constructor({ connection }) {
@@ -516,11 +524,7 @@ class CryptoConnection extends Connection {
516
524
  async command(ns, cmd, options, responseType) {
517
525
  const { autoEncrypter } = this;
518
526
  if (!autoEncrypter) {
519
- // TODO(NODE-6065): throw a MongoRuntimeError in Node V7
520
- // @ts-expect-error No cause provided because there is no underlying error.
521
- throw new error_1.MongoMissingDependencyError('No AutoEncrypter available for encryption', {
522
- dependencyName: 'n/a'
523
- });
527
+ throw new error_1.MongoRuntimeError('No AutoEncrypter available for encryption');
524
528
  }
525
529
  const serverWireVersion = (0, utils_1.maxWireVersion)(this);
526
530
  if (serverWireVersion === 0) {