@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
@@ -129,11 +129,11 @@ module.exports = function assignVals(o) {
129
129
 
130
130
  if (isDoc && Array.isArray(valueToSet)) {
131
131
  for (const val of valueToSet) {
132
- if (val != null && val.$__ != null) {
132
+ if (val?.$__ != null) {
133
133
  val.$__.parent = docs[i];
134
134
  }
135
135
  }
136
- } else if (isDoc && valueToSet != null && valueToSet.$__ != null) {
136
+ } else if (isDoc && valueToSet?.$__ != null) {
137
137
  valueToSet.$__.parent = docs[i];
138
138
  }
139
139
 
@@ -184,7 +184,7 @@ module.exports = function assignVals(o) {
184
184
  // See gh-8342, gh-8455
185
185
  const curPath = parts.slice(0, j + 1).join('.');
186
186
  const schematype = originalSchema._getSchema(curPath);
187
- if (valueToSet == null && schematype != null && schematype.$isMongooseArray) {
187
+ if (valueToSet == null && schematype?.$isMongooseArray) {
188
188
  break;
189
189
  }
190
190
  cur[parts[j]] = {};
@@ -200,7 +200,7 @@ module.exports = function assignVals(o) {
200
200
  o.allOptions.options[populateModelSymbol] = o.allOptions.model;
201
201
  docs[i].$populated(_path, o.unpopulatedValues[i], o.allOptions.options);
202
202
 
203
- if (valueToSet != null && valueToSet.$__ != null) {
203
+ if (valueToSet?.$__ != null) {
204
204
  valueToSet.$__.wasPopulated = { value: o.unpopulatedValues[i] };
205
205
  }
206
206
 
@@ -256,11 +256,11 @@ function numDocs(v) {
256
256
  * background:
257
257
  * _ids are left in the query even when user excludes them so
258
258
  * that population mapping can occur.
259
- * @param {Any} val
260
- * @param {Object} assignmentOpts
261
- * @param {Object} populateOptions
259
+ * @param {any} val
260
+ * @param {object} assignmentOpts
261
+ * @param {object} populateOptions
262
262
  * @param {Function} [populateOptions.transform]
263
- * @param {Boolean} allIds
263
+ * @param {boolean} allIds
264
264
  * @api private
265
265
  */
266
266
 
@@ -327,7 +327,7 @@ function valueFilter(val, assignmentOpts, populateOptions, allIds) {
327
327
  /**
328
328
  * Remove _id from `subdoc` if user specified "lean" query option
329
329
  * @param {Document} subdoc
330
- * @param {Object} assignmentOpts
330
+ * @param {object} assignmentOpts
331
331
  * @api private
332
332
  */
333
333
 
@@ -344,7 +344,7 @@ function maybeRemoveId(subdoc, assignmentOpts) {
344
344
  /**
345
345
  * Determine if `obj` is something we can set a populated path to. Can be a
346
346
  * document, a lean document, or an array/map that contains docs.
347
- * @param {Any} obj
347
+ * @param {any} obj
348
348
  * @api private
349
349
  */
350
350
 
@@ -60,7 +60,7 @@ module.exports = function createPopulateQueryFilter(ids, _match, _foreignField,
60
60
  * to avoid cast errors (gh-7706)
61
61
  * @param {Array} ids
62
62
  * @param {SchemaType} foreignSchemaType
63
- * @param {Boolean} [skipInvalidIds]
63
+ * @param {boolean} [skipInvalidIds]
64
64
  * @api private
65
65
  */
66
66
 
@@ -73,7 +73,7 @@ function _filterInvalidIds(ids, foreignSchemaType, skipInvalidIds) {
73
73
  try {
74
74
  foreignSchemaType.cast(id);
75
75
  return true;
76
- } catch (err) {
76
+ } catch {
77
77
  return false;
78
78
  }
79
79
  });
@@ -82,7 +82,7 @@ function _filterInvalidIds(ids, foreignSchemaType, skipInvalidIds) {
82
82
  /**
83
83
  * Format `mod.match` given that it may be an array that we need to $or if
84
84
  * the client has multiple docs with match functions
85
- * @param {Array|Any} match
85
+ * @param {Array|any} match
86
86
  * @api private
87
87
  */
88
88
 
@@ -17,15 +17,19 @@ const modelSymbol = require('../symbols').modelSymbol;
17
17
  const populateModelSymbol = require('../symbols').populateModelSymbol;
18
18
  const schemaMixedSymbol = require('../../schema/symbols').schemaMixedSymbol;
19
19
  const StrictPopulate = require('../../error/strictPopulate');
20
+ const numericPathSegmentPattern = '\\.\\d+(?=\\.|$)';
21
+ const hasNumericPathSegmentRE = new RegExp(numericPathSegmentPattern);
22
+ const numericPathSegmentRE = new RegExp(numericPathSegmentPattern, 'g');
20
23
 
21
24
  module.exports = function getModelsMapForPopulate(model, docs, options) {
22
25
  let doc;
23
26
  const len = docs.length;
24
27
  const map = [];
25
- const modelNameFromQuery = options.model && options.model.modelName || options.model;
28
+ const modelNameFromQuery = options.model?.modelName || options.model;
26
29
  let schema;
27
30
  let refPath;
28
31
  let modelNames;
32
+ let modelNamesSet;
29
33
  const available = {};
30
34
 
31
35
  const modelSchema = model.schema;
@@ -42,7 +46,8 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
42
46
  return _virtualPopulate(model, docs, options, _virtualRes);
43
47
  }
44
48
 
45
- let allSchemaTypes = getSchemaTypes(model, modelSchema, null, options.path);
49
+ const parts = modelSchema.paths[options.path]?.splitPath() ?? options.path.split('.');
50
+ let allSchemaTypes = getSchemaTypes(model, modelSchema, null, options.path, parts);
46
51
  allSchemaTypes = Array.isArray(allSchemaTypes) ? allSchemaTypes : [allSchemaTypes].filter(v => v != null);
47
52
 
48
53
  const isStrictPopulateDisabled = options.strictPopulate === false || options.options?.strictPopulate === false;
@@ -55,14 +60,14 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
55
60
  let justOne = null;
56
61
 
57
62
  if (doc.$__ != null && doc.populated(options.path)) {
58
- const forceRepopulate = options.forceRepopulate != null ? options.forceRepopulate : doc.constructor.base.options.forceRepopulate;
63
+ const forceRepopulate = options.forceRepopulate ?? doc.constructor.base.options.forceRepopulate;
59
64
  if (forceRepopulate === false) {
60
65
  continue;
61
66
  }
62
67
  }
63
68
 
64
- const docSchema = doc != null && doc.$__ != null ? doc.$__schema : modelSchema;
65
- schema = getSchemaTypes(model, docSchema, doc, options.path);
69
+ const docSchema = doc?.$__ != null ? doc.$__schema : modelSchema;
70
+ schema = getSchemaTypes(model, docSchema, doc, options.path, parts);
66
71
 
67
72
  // Special case: populating a path that's a DocumentArray unless
68
73
  // there's an explicit `ref` or `refPath` re: gh-8946
@@ -72,7 +77,7 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
72
77
  schema.options.refPath == null) {
73
78
  continue;
74
79
  }
75
- const isUnderneathDocArray = schema && schema.$parentSchemaDocArray;
80
+ const isUnderneathDocArray = schema?.$parentSchemaDocArray;
76
81
  if (isUnderneathDocArray && get(options, 'options.sort') != null) {
77
82
  return new MongooseError('Cannot populate with `sort` on path ' + options.path +
78
83
  ' because it is a subproperty of a document array');
@@ -84,7 +89,7 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
84
89
  let schemaOptions = null;
85
90
  let modelNamesInOrder = null;
86
91
 
87
- if (schema != null && schema.instance === 'Embedded') {
92
+ if (schema?.instance === 'Embedded') {
88
93
  if (schema.options.ref) {
89
94
  const data = {
90
95
  localField: options.path + '._id',
@@ -123,8 +128,10 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
123
128
  continue;
124
129
  }
125
130
  modelNames = modelNames || [];
131
+ modelNamesSet = modelNamesSet || new Set();
126
132
  for (const modelName of _modelNames) {
127
- if (modelNames.indexOf(modelName) === -1) {
133
+ if (modelNamesSet.has(modelName) === false) {
134
+ modelNamesSet.add(modelName);
128
135
  modelNames.push(modelName);
129
136
  }
130
137
  }
@@ -198,8 +205,11 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
198
205
  data.modelNamesInOrder = modelNamesInOrder;
199
206
 
200
207
  if (isRefPath) {
208
+ const normalizedRefPathForDiscriminators = typeof normalizedRefPath === 'string' ?
209
+ normalizedRefPath.replace(numericPathSegmentRE, '') :
210
+ normalizedRefPath;
201
211
  const embeddedDiscriminatorModelNames = _findRefPathForDiscriminators(doc,
202
- modelSchema, data, options, normalizedRefPath, ret);
212
+ modelSchema, data, options, normalizedRefPathForDiscriminators, ret);
203
213
 
204
214
  modelNames = embeddedDiscriminatorModelNames || modelNames;
205
215
  }
@@ -212,23 +222,23 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
212
222
  }
213
223
  return map;
214
224
 
215
- function _getModelNames(doc, schema, modelNameFromQuery, model) {
225
+ function _getModelNames(doc, schemaType, modelNameFromQuery, model) {
216
226
  let modelNames;
217
227
  let isRefPath = false;
218
228
  let justOne = null;
219
229
 
220
- const originalSchema = schema;
221
- if (schema && schema.instance === 'Array') {
222
- schema = schema.caster;
230
+ const originalSchema = schemaType;
231
+ if (schemaType?.instance === 'Array') {
232
+ schemaType = schemaType.embeddedSchemaType;
223
233
  }
224
- if (schema && schema.$isSchemaMap) {
225
- schema = schema.$__schemaType;
234
+ if (schemaType?.$isSchemaMap) {
235
+ schemaType = schemaType.$__schemaType;
226
236
  }
227
237
 
228
- const ref = schema && schema.options && schema.options.ref;
229
- refPath = schema && schema.options && schema.options.refPath;
230
- if (schema != null &&
231
- schema[schemaMixedSymbol] &&
238
+ const ref = schemaType?.options?.ref;
239
+ refPath = schemaType?.options?.refPath;
240
+ if (schemaType != null &&
241
+ schemaType[schemaMixedSymbol] &&
232
242
  !ref &&
233
243
  !refPath &&
234
244
  !modelNameFromQuery) {
@@ -239,19 +249,9 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
239
249
  modelNames = [modelNameFromQuery]; // query options
240
250
  } else if (refPath != null) {
241
251
  if (typeof refPath === 'function') {
242
- const subdocPath = options.path.slice(0, options.path.length - schema.path.length - 1);
243
- const vals = mpath.get(subdocPath, doc, lookupLocalFields);
244
- const subdocsBeingPopulated = Array.isArray(vals) ?
245
- utils.array.flatten(vals) :
246
- (vals ? [vals] : []);
247
-
248
- modelNames = new Set();
249
- for (const subdoc of subdocsBeingPopulated) {
250
- refPath = refPath.call(subdoc, subdoc, options.path);
251
- modelNamesFromRefPath(refPath, doc, options.path, modelSchema, options._queryProjection).
252
- forEach(name => modelNames.add(name));
253
- }
254
- modelNames = Array.from(modelNames);
252
+ const res = _getModelNamesFromFunctionRefPath(refPath, doc, schemaType, options.path, modelSchema, options._queryProjection);
253
+ modelNames = res.modelNames;
254
+ refPath = res.refPath;
255
255
  } else {
256
256
  modelNames = modelNamesFromRefPath(refPath, doc, options.path, modelSchema, options._queryProjection);
257
257
  }
@@ -265,7 +265,7 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
265
265
  let modelForCurrentDoc = model;
266
266
  const discriminatorKey = model.schema.options.discriminatorKey;
267
267
 
268
- if (!schema && discriminatorKey && (discriminatorValue = utils.getValue(discriminatorKey, doc))) {
268
+ if (!schemaType && discriminatorKey && (discriminatorValue = utils.getValue(discriminatorKey, doc))) {
269
269
  // `modelNameForFind` is the discriminator value, so we might need
270
270
  // find the discriminated model name
271
271
  const discriminatorModel = getDiscriminatorByValue(model.discriminators, discriminatorValue) || model;
@@ -281,11 +281,11 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
281
281
 
282
282
  schemaForCurrentDoc = modelForCurrentDoc.schema._getSchema(options.path);
283
283
 
284
- if (schemaForCurrentDoc && schemaForCurrentDoc.caster) {
285
- schemaForCurrentDoc = schemaForCurrentDoc.caster;
284
+ if (schemaForCurrentDoc?.embeddedSchemaType) {
285
+ schemaForCurrentDoc = schemaForCurrentDoc.embeddedSchemaType;
286
286
  }
287
287
  } else {
288
- schemaForCurrentDoc = schema;
288
+ schemaForCurrentDoc = schemaType;
289
289
  }
290
290
 
291
291
  if (originalSchema && originalSchema.path.endsWith('.$*')) {
@@ -319,22 +319,12 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
319
319
  ref = handleRefFunction(ref, doc);
320
320
  modelNames = [ref];
321
321
  }
322
- } else if ((schemaForCurrentDoc = get(schema, 'options.refPath')) != null) {
322
+ } else if ((refPath = get(schemaForCurrentDoc, 'options.refPath')) != null) {
323
323
  isRefPath = true;
324
324
  if (typeof refPath === 'function') {
325
- const subdocPath = options.path.slice(0, options.path.length - schemaForCurrentDoc.path.length - 1);
326
- const vals = mpath.get(subdocPath, doc, lookupLocalFields);
327
- const subdocsBeingPopulated = Array.isArray(vals) ?
328
- utils.array.flatten(vals) :
329
- (vals ? [vals] : []);
330
-
331
- modelNames = new Set();
332
- for (const subdoc of subdocsBeingPopulated) {
333
- refPath = refPath.call(subdoc, subdoc, options.path);
334
- modelNamesFromRefPath(refPath, doc, options.path, modelSchema, options._queryProjection).
335
- forEach(name => modelNames.add(name));
336
- }
337
- modelNames = Array.from(modelNames);
325
+ const res = _getModelNamesFromFunctionRefPath(refPath, doc, schemaForCurrentDoc, options.path, modelSchema, options._queryProjection);
326
+ modelNames = res.modelNames;
327
+ refPath = res.refPath;
338
328
  } else {
339
329
  modelNames = modelNamesFromRefPath(refPath, doc, options.path, modelSchema, options._queryProjection);
340
330
  }
@@ -358,6 +348,137 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
358
348
  }
359
349
  };
360
350
 
351
+ /**
352
+ * Resolve model names for function-style `refPath` and return the first
353
+ * resolved refPath value so discriminator handling can inspect it later.
354
+ *
355
+ * @param {Function} refPath
356
+ * @param {Document|object} doc
357
+ * @param {SchemaType} schema
358
+ * @param {string} populatePath
359
+ * @param {Schema} modelSchema
360
+ * @param {object} queryProjection
361
+ * @returns {{modelNames: string[], refPath: string|null}}
362
+ * @private
363
+ */
364
+ function _getModelNamesFromFunctionRefPath(refPath, doc, schemaType, populatePath, modelSchema, queryProjection) {
365
+ const modelNames = [];
366
+ let normalizedRefPath = null;
367
+ const schemaPath = schemaType?.path;
368
+
369
+ if (schemaPath != null &&
370
+ populatePath.length > schemaPath.length + 1 &&
371
+ populatePath.charAt(populatePath.length - schemaPath.length - 1) === '.' &&
372
+ populatePath.slice(populatePath.length - schemaPath.length) === schemaPath
373
+ ) {
374
+ const subdocPath = populatePath.slice(0, populatePath.length - schemaPath.length - 1);
375
+ const segments = subdocPath.indexOf('.') === -1 ? [subdocPath] : subdocPath.split('.');
376
+ let hasSubdoc = false;
377
+
378
+ walkSubdocs(doc, '', 0);
379
+ if (hasSubdoc) {
380
+ return { modelNames, refPath: normalizedRefPath };
381
+ }
382
+
383
+ function walkSubdocs(currentSubdoc, indexedPathPrefix, segmentIndex) {
384
+ if (currentSubdoc == null) {
385
+ return;
386
+ }
387
+
388
+ if (segmentIndex >= segments.length) {
389
+ hasSubdoc = true;
390
+ const indexedPath = indexedPathPrefix + '.' + schemaPath;
391
+ const subdocRefPath = refPath.call(currentSubdoc, currentSubdoc, indexedPath);
392
+ normalizedRefPath = normalizedRefPath || subdocRefPath;
393
+ modelNames.push(..._getModelNamesFromRefPath(subdocRefPath, doc, populatePath, indexedPath, modelSchema, queryProjection));
394
+ return;
395
+ }
396
+
397
+ const segment = segments[segmentIndex];
398
+ const source = currentSubdoc?._doc ?? currentSubdoc;
399
+
400
+ if (segment === '$*') {
401
+ if (source instanceof Map) {
402
+ for (const [key, value] of source.entries()) {
403
+ if (value != null) {
404
+ const valuePath = indexedPathPrefix.length === 0 ?
405
+ key :
406
+ indexedPathPrefix + '.' + key;
407
+ walkSubdocs(value, valuePath, segmentIndex + 1);
408
+ }
409
+ }
410
+ return;
411
+ }
412
+
413
+ if (source != null && typeof source === 'object') {
414
+ for (const key of Object.keys(source)) {
415
+ const value = source[key];
416
+ if (value != null) {
417
+ const valuePath = indexedPathPrefix.length === 0 ?
418
+ key :
419
+ indexedPathPrefix + '.' + key;
420
+ walkSubdocs(value, valuePath, segmentIndex + 1);
421
+ }
422
+ }
423
+ }
424
+ return;
425
+ }
426
+
427
+ const child = source[segment];
428
+ const childPath = indexedPathPrefix.length === 0 ?
429
+ segment :
430
+ indexedPathPrefix + '.' + segment;
431
+
432
+ if (Array.isArray(child)) {
433
+ for (let i = 0; i < child.length; ++i) {
434
+ if (child[i] != null) {
435
+ walkSubdocs(child[i], childPath + '.' + i, segmentIndex + 1);
436
+ }
437
+ }
438
+ } else if (child != null) {
439
+ walkSubdocs(child, childPath, segmentIndex + 1);
440
+ }
441
+ }
442
+ }
443
+
444
+ const topLevelRefPath = refPath.call(doc, doc, populatePath);
445
+ normalizedRefPath = normalizedRefPath || topLevelRefPath;
446
+ modelNames.push(...modelNamesFromRefPath(topLevelRefPath, doc, populatePath, modelSchema, queryProjection));
447
+
448
+ return { modelNames, refPath: normalizedRefPath };
449
+ }
450
+
451
+ /**
452
+ * Resolve model names from a refPath, preferring the indexed populated path
453
+ * for array subdocuments and falling back to the original populate path if
454
+ * normalization fails.
455
+ *
456
+ * @param {string|Function} refPath
457
+ * @param {Document|object} doc
458
+ * @param {string} populatePath
459
+ * @param {string} indexedPath
460
+ * @param {Schema} modelSchema
461
+ * @param {object} queryProjection
462
+ * @returns {string[]}
463
+ * @private
464
+ */
465
+ function _getModelNamesFromRefPath(refPath, doc, populatePath, indexedPath, modelSchema, queryProjection) {
466
+ const populatedPath = typeof refPath === 'string' && hasNumericPathSegmentRE.test(refPath) ?
467
+ populatePath :
468
+ indexedPath;
469
+
470
+ try {
471
+ return modelNamesFromRefPath(refPath, doc, populatedPath, modelSchema, queryProjection);
472
+ } catch (error) {
473
+ if (populatedPath === indexedPath &&
474
+ typeof error?.message === 'string' &&
475
+ error.message.startsWith('Could not normalize ref path')) {
476
+ return modelNamesFromRefPath(refPath, doc, populatePath, modelSchema, queryProjection);
477
+ }
478
+ throw error;
479
+ }
480
+ }
481
+
361
482
  /*!
362
483
  * ignore
363
484
  */
@@ -418,7 +539,15 @@ function _virtualPopulate(model, docs, options, _virtualRes) {
418
539
  justOne = options.justOne;
419
540
  }
420
541
 
421
- modelNames = virtual._getModelNamesForPopulate(doc);
542
+ // Use the correct target doc/sub-doc for dynamic ref on nested schema. See gh-12363
543
+ if (_virtualRes.nestedSchemaPath && typeof virtual.options.ref === 'function') {
544
+ const subdocs = utils.getValue(_virtualRes.nestedSchemaPath, doc);
545
+ modelNames = Array.isArray(subdocs)
546
+ ? subdocs.flatMap(subdoc => virtual._getModelNamesForPopulate(subdoc))
547
+ : virtual._getModelNamesForPopulate(subdocs);
548
+ } else {
549
+ modelNames = virtual._getModelNamesForPopulate(doc);
550
+ }
422
551
  if (virtual.options.refPath) {
423
552
  justOne = !!virtual.options.justOne;
424
553
  data.isRefPath = true;
@@ -477,7 +606,7 @@ function _virtualPopulate(model, docs, options, _virtualRes) {
477
606
  function addModelNamesToMap(model, map, available, modelNames, options, data, ret, doc, schemaOptions, unpopulatedValue) {
478
607
  // `PopulateOptions#connection`: if the model is passed as a string, the
479
608
  // connection matters because different connections have different models.
480
- const connection = options.connection != null ? options.connection : model.db;
609
+ const connection = options.connection ?? model.db;
481
610
 
482
611
  unpopulatedValue = unpopulatedValue === void 0 ? ret : unpopulatedValue;
483
612
  if (Array.isArray(unpopulatedValue)) {
@@ -515,7 +644,7 @@ function addModelNamesToMap(model, map, available, modelNames, options, data, re
515
644
 
516
645
  let ids = ret;
517
646
 
518
- const modelNamesForRefPath = data.modelNamesInOrder ? data.modelNamesInOrder : modelNames;
647
+ const modelNamesForRefPath = data.modelNamesInOrder || modelNames;
519
648
  if (data.isRefPath && Array.isArray(ret) && ret.length === modelNamesForRefPath.length) {
520
649
  ids = matchIdsToRefPaths(ret, modelNamesForRefPath, modelName);
521
650
  }
@@ -614,10 +743,9 @@ function _getLocalFieldValues(doc, localField, model, options, virtual, schema)
614
743
  const localFieldPath = localFieldPathType === 'real' ?
615
744
  model.schema.path(localField) :
616
745
  localFieldPathType.schema;
617
- const localFieldGetters = localFieldPath && localFieldPath.getters ?
618
- localFieldPath.getters : [];
746
+ const localFieldGetters = localFieldPath?.getters || [];
619
747
 
620
- localField = localFieldPath != null && localFieldPath.instance === 'Embedded' ? localField + '._id' : localField;
748
+ localField = localFieldPath?.instance === 'Embedded' ? localField + '._id' : localField;
621
749
 
622
750
  const _populateOptions = get(options, 'options', {});
623
751
 
@@ -642,24 +770,24 @@ function _getLocalFieldValues(doc, localField, model, options, virtual, schema)
642
770
  /**
643
771
  * Retrieve the _id of `val` if a Document or Array of Documents.
644
772
  *
645
- * @param {Array|Document|Any} val
773
+ * @param {Array|Document|any} val
646
774
  * @param {Schema} schema
647
- * @return {Array|Document|Any}
775
+ * @return {Array|Document|any}
648
776
  * @api private
649
777
  */
650
778
 
651
779
  function convertTo_id(val, schema) {
652
- if (val != null && val.$__ != null) {
780
+ if (val?.$__ != null) {
653
781
  return val._doc._id;
654
782
  }
655
- if (val != null && val._id != null && (schema == null || !schema.$isSchemaMap)) {
783
+ if (val?._id != null && !schema?.$isSchemaMap) {
656
784
  return val._id;
657
785
  }
658
786
 
659
787
  if (Array.isArray(val)) {
660
- const rawVal = val.__array != null ? val.__array : val;
788
+ const rawVal = val.__array ?? val;
661
789
  for (let i = 0; i < rawVal.length; ++i) {
662
- if (rawVal[i] != null && rawVal[i].$__ != null) {
790
+ if (rawVal[i]?.$__ != null) {
663
791
  rawVal[i] = rawVal[i]._doc._id;
664
792
  }
665
793
  }
@@ -675,7 +803,7 @@ function convertTo_id(val, schema) {
675
803
  if (getConstructorName(val) === 'Object' &&
676
804
  // The intent here is we should only flatten the object if we expect
677
805
  // to get a Map in the end. Avoid doing this for mixed types.
678
- (schema == null || schema[schemaMixedSymbol] == null)) {
806
+ schema?.[schemaMixedSymbol] == null) {
679
807
  const ret = [];
680
808
  for (const key of Object.keys(val)) {
681
809
  ret.push(val[key]);
@@ -711,17 +839,17 @@ function _findRefPathForDiscriminators(doc, modelSchema, data, options, normaliz
711
839
  cur = cur + (cur.length === 0 ? '' : '.') + piece;
712
840
  const schematype = modelSchema.path(cur);
713
841
  if (schematype != null &&
714
- schematype.$isMongooseArray &&
715
- schematype.caster.discriminators != null &&
716
- Object.keys(schematype.caster.discriminators).length !== 0) {
842
+ schematype.$isMongooseDocumentArray &&
843
+ schematype.Constructor.discriminators != null &&
844
+ utils.hasOwnKeys(schematype.Constructor.discriminators)) {
717
845
  const subdocs = utils.getValue(cur, doc);
718
846
  const remnant = options.path.substring(cur.length + 1);
719
- const discriminatorKey = schematype.caster.schema.options.discriminatorKey;
847
+ const discriminatorKey = schematype.Constructor.schema.options.discriminatorKey;
720
848
  modelNames = [];
721
849
  for (const subdoc of subdocs) {
722
850
  const discriminatorName = utils.getValue(discriminatorKey, subdoc);
723
- const discriminator = schematype.caster.discriminators[discriminatorName];
724
- const discriminatorSchema = discriminator && discriminator.schema;
851
+ const discriminator = schematype.Constructor.discriminators[discriminatorName];
852
+ const discriminatorSchema = discriminator?.schema;
725
853
  if (discriminatorSchema == null) {
726
854
  continue;
727
855
  }
@@ -20,24 +20,24 @@ const populateModelSymbol = require('../symbols').populateModelSymbol;
20
20
  *
21
21
  * @param {Model} model
22
22
  * @param {Schema} schema
23
- * @param {Object} doc POJO
23
+ * @param {object} doc POJO
24
24
  * @param {string} path
25
+ * @param {string[]} [parts] pass in pre-split `path` to avoid extra splitting
25
26
  * @api private
26
27
  */
27
28
 
28
- module.exports = function getSchemaTypes(model, schema, doc, path) {
29
+ module.exports = function getSchemaTypes(model, schema, doc, path, parts) {
29
30
  const pathschema = schema.path(path);
30
31
  const topLevelDoc = doc;
31
32
  if (pathschema) {
32
33
  return pathschema;
33
34
  }
34
35
 
35
- const discriminatorKey = schema.discriminatorMapping &&
36
- schema.discriminatorMapping.key;
36
+ const discriminatorKey = schema.discriminatorMapping?.key;
37
37
  if (discriminatorKey && model != null) {
38
- if (doc != null && doc[discriminatorKey] != null) {
38
+ if (doc?.[discriminatorKey] != null) {
39
39
  const discriminator = getDiscriminatorByValue(model.discriminators, doc[discriminatorKey]);
40
- schema = discriminator ? discriminator.schema : schema;
40
+ schema = discriminator?.schema || schema;
41
41
  } else if (model.discriminators != null) {
42
42
  return Object.keys(model.discriminators).reduce((arr, name) => {
43
43
  const disc = model.discriminators[name];
@@ -58,14 +58,14 @@ module.exports = function getSchemaTypes(model, schema, doc, path) {
58
58
  continue;
59
59
  }
60
60
 
61
- if (foundschema.caster) {
61
+ if (foundschema.embeddedSchemaType || foundschema.schema) {
62
62
  // array of Mixed?
63
- if (foundschema.caster instanceof Mixed) {
64
- return foundschema.caster;
63
+ if (foundschema.embeddedSchemaType instanceof Mixed) {
64
+ return foundschema.embeddedSchemaType;
65
65
  }
66
66
 
67
67
  let schemas = null;
68
- if (foundschema.schema != null && foundschema.schema.discriminators != null) {
68
+ if (foundschema.schema?.discriminators != null) {
69
69
  const discriminators = foundschema.schema.discriminators;
70
70
  const discriminatorKeyPath = trypath + '.' +
71
71
  foundschema.schema.options.discriminatorKey;
@@ -142,11 +142,11 @@ module.exports = function getSchemaTypes(model, schema, doc, path) {
142
142
  }
143
143
  } else if (p !== parts.length &&
144
144
  foundschema.$isMongooseArray &&
145
- foundschema.casterConstructor.$isMongooseArray) {
145
+ foundschema.embeddedSchemaType.$isMongooseArray) {
146
146
  // Nested arrays. Drill down to the bottom of the nested array.
147
147
  let type = foundschema;
148
148
  while (type.$isMongooseArray && !type.$isMongooseDocumentArray) {
149
- type = type.casterConstructor;
149
+ type = type.embeddedSchemaType;
150
150
  }
151
151
 
152
152
  const ret = search(
@@ -178,7 +178,7 @@ module.exports = function getSchemaTypes(model, schema, doc, path) {
178
178
  }
179
179
 
180
180
  const fullPath = nestedPath.concat([trypath]).join('.');
181
- if (topLevelDoc != null && topLevelDoc.$__ && topLevelDoc.$populated(fullPath, true) && p < parts.length) {
181
+ if (topLevelDoc?.$__ && topLevelDoc.$populated(fullPath, true) && p < parts.length) {
182
182
  const model = topLevelDoc.$populated(fullPath, true).options[populateModelSymbol];
183
183
  if (model != null) {
184
184
  const ret = search(
@@ -198,7 +198,7 @@ module.exports = function getSchemaTypes(model, schema, doc, path) {
198
198
  leanPopulateMap.get(_val[0]) :
199
199
  leanPopulateMap.get(_val);
200
200
  // Populated using lean, `leanPopulateMap` value is the foreign model
201
- const schema = model != null ? model.schema : null;
201
+ const schema = model?.schema ?? null;
202
202
  if (schema != null) {
203
203
  const ret = search(
204
204
  parts.slice(p),
@@ -218,7 +218,7 @@ module.exports = function getSchemaTypes(model, schema, doc, path) {
218
218
  }
219
219
  }
220
220
  // look for arrays
221
- const parts = path.split('.');
221
+ parts = parts || path.split('.');
222
222
  for (let i = 0; i < parts.length; ++i) {
223
223
  if (parts[i] === '$') {
224
224
  // Re: gh-5628, because `schema.path()` doesn't take $ into account.
@@ -12,7 +12,7 @@ const utils = require('../../utils');
12
12
  * doc.comments[0].populated('author'); // Should be set
13
13
  *
14
14
  * @param {Document} doc
15
- * @param {Object} [populated]
15
+ * @param {object} [populated]
16
16
  * @api private
17
17
  */
18
18
 
@@ -14,7 +14,11 @@ module.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, mod
14
14
  return [];
15
15
  }
16
16
 
17
- if (typeof refPath === 'string' && queryProjection != null && isPathExcluded(queryProjection, refPath)) {
17
+ if (typeof refPath !== 'string') {
18
+ throw new MongooseError('`refPath` must be a string or a function that returns a string, got ' + util.inspect(refPath));
19
+ }
20
+
21
+ if (queryProjection != null && isPathExcluded(queryProjection, refPath)) {
18
22
  throw new MongooseError('refPath `' + refPath + '` must not be excluded in projection, got ' +
19
23
  util.inspect(queryProjection));
20
24
  }
@@ -35,7 +39,11 @@ module.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, mod
35
39
  // 2nd, 4th, etc. will be numeric props. For example: `[ 'a', '.0.', 'b' ]`
36
40
  for (let i = 0; i < chunks.length; i += 2) {
37
41
  const chunk = chunks[i];
38
- if (_remaining.startsWith(chunk + '.')) {
42
+ if (
43
+ _remaining.length >= chunk.length + 1 &&
44
+ _remaining.charAt(chunk.length) === '.' &&
45
+ _remaining.slice(0, chunk.length) === chunk
46
+ ) {
39
47
  _refPath += _remaining.substring(0, chunk.length) + chunks[i + 1];
40
48
  _remaining = _remaining.substring(chunk.length + 1);
41
49
  } else if (i === chunks.length - 1) {