@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
@@ -19,7 +19,7 @@ const isPathSelectedInclusive = require('./helpers/projection/isPathSelectedIncl
19
19
  * version
20
20
  *
21
21
  * @param {Query} query
22
- * @param {Object} options
22
+ * @param {object} options
23
23
  * @return {Array}
24
24
  */
25
25
 
@@ -30,11 +30,11 @@ exports.preparePopulationOptionsMQ = function preparePopulationOptionsMQ(query,
30
30
  // lean options should trickle through all queries
31
31
  if (options.lean != null) {
32
32
  pop
33
- .filter(p => (p && p.options && p.options.lean) == null)
33
+ .filter(p => p?.options?.lean == null)
34
34
  .forEach(makeLean(options.lean));
35
35
  }
36
36
 
37
- const session = query && query.options && query.options.session || null;
37
+ const session = query?.options?.session || null;
38
38
  if (session != null) {
39
39
  pop.forEach(path => {
40
40
  if (path.options == null) {
@@ -69,8 +69,8 @@ exports.preparePopulationOptionsMQ = function preparePopulationOptionsMQ(query,
69
69
  * it returns an instance of the given model.
70
70
  *
71
71
  * @param {Model} model
72
- * @param {Object} doc
73
- * @param {Object} fields
72
+ * @param {object} doc
73
+ * @param {object} fields
74
74
  *
75
75
  * @return {Document}
76
76
  */
@@ -80,32 +80,33 @@ exports.createModel = function createModel(model, doc, fields, userProvidedField
80
80
  model.schema.discriminatorMapping :
81
81
  null;
82
82
 
83
- const key = discriminatorMapping && discriminatorMapping.isRoot ?
83
+ const key = discriminatorMapping?.isRoot ?
84
84
  discriminatorMapping.key :
85
85
  null;
86
86
 
87
+ const _opts = {
88
+ skipId: true,
89
+ isNew: false,
90
+ willInit: true
91
+ };
92
+ if (options?.defaults != null) {
93
+ _opts.defaults = options.defaults;
94
+ }
95
+ if (options?.strict != null) {
96
+ _opts.strict = options.strict;
97
+ }
98
+
87
99
  const value = doc[key];
88
100
  if (key && value && model.discriminators) {
89
101
  const discriminator = model.discriminators[value] || getDiscriminatorByValue(model.discriminators, value);
90
102
  if (discriminator) {
91
103
  const _fields = clone(userProvidedFields);
92
104
  exports.applyPaths(_fields, discriminator.schema);
93
- const _opts = { strict: options?.strict };
105
+
94
106
  return new discriminator(undefined, _fields, _opts);
95
107
  }
96
108
  }
97
109
 
98
- const _opts = {
99
- skipId: true,
100
- isNew: false,
101
- willInit: true
102
- };
103
- if (options != null && 'defaults' in options) {
104
- _opts.defaults = options.defaults;
105
- }
106
- if (options != null && 'strict' in options) {
107
- _opts.strict = options.strict;
108
- }
109
110
  return new model(undefined, fields, _opts);
110
111
  };
111
112
 
@@ -114,9 +115,13 @@ exports.createModel = function createModel(model, doc, fields, userProvidedField
114
115
  */
115
116
 
116
117
  exports.createModelAndInit = function createModelAndInit(model, doc, fields, userProvidedFields, options, populatedIds, callback) {
117
- const initOpts = populatedIds ?
118
- { populated: populatedIds } :
119
- undefined;
118
+ const initOpts = {};
119
+ if (populatedIds) {
120
+ initOpts.populated = populatedIds;
121
+ }
122
+ if (options?.middleware != null) {
123
+ initOpts.middleware = options.middleware;
124
+ }
120
125
 
121
126
  const casted = exports.createModel(model, doc, fields, userProvidedFields, options);
122
127
  try {
@@ -183,10 +188,10 @@ exports.applyPaths = function applyPaths(fields, schema, sanitizeProjection) {
183
188
  // inclusive, minus path is treated as equivalent to `key: 0`.
184
189
  // But we also allow using `-name` to remove `name` from an inclusive
185
190
  // projection if `name` has schema-level `select: true`.
186
- if ((!type || !type.selected) || exclude !== false) {
191
+ if (!type?.selected || exclude !== false) {
187
192
  fields[path] = 0;
188
193
  exclude = true;
189
- } else if (type && type.selected && exclude === false) {
194
+ } else if (type?.selected && exclude === false) {
190
195
  // Make a note of minus paths that are overwriting paths that are
191
196
  // included by default.
192
197
  minusPathsToSkip.add(path);
@@ -208,10 +213,7 @@ exports.applyPaths = function applyPaths(fields, schema, sanitizeProjection) {
208
213
  }
209
214
  break;
210
215
  case false:
211
- if (schema &&
212
- schema.paths['_id'] &&
213
- schema.paths['_id'].options &&
214
- schema.paths['_id'].options.select === false) {
216
+ if (schema?.paths['_id']?.options?.select === false) {
215
217
  fields._id = 0;
216
218
  }
217
219
 
@@ -264,7 +266,7 @@ exports.applyPaths = function applyPaths(fields, schema, sanitizeProjection) {
264
266
  if (type.$isSchemaMap || path.endsWith('.$*')) {
265
267
  const plusPath = '+' + path;
266
268
  const hasPlusPath = fields && plusPath in fields;
267
- if (type.options && type.options.select === false && !hasPlusPath) {
269
+ if (type.options?.select === false && !hasPlusPath) {
268
270
  excluded.push(path);
269
271
  }
270
272
  return;
@@ -272,7 +274,7 @@ exports.applyPaths = function applyPaths(fields, schema, sanitizeProjection) {
272
274
  let addedPath = analyzePath(path, type);
273
275
  // arrays
274
276
  if (addedPath == null && !Array.isArray(type) && type.$isMongooseArray && !type.$isMongooseDocumentArray) {
275
- addedPath = analyzePath(path, type.caster);
277
+ addedPath = analyzePath(path, type.embeddedSchemaType);
276
278
  }
277
279
  if (addedPath != null) {
278
280
  addedPaths.push(addedPath);
@@ -356,7 +358,7 @@ exports.applyPaths = function applyPaths(fields, schema, sanitizeProjection) {
356
358
  // Special case: if user has included a parent path of a discriminator key,
357
359
  // don't explicitly project in the discriminator key because that will
358
360
  // project out everything else under the parent path
359
- if (!exclude && (type && type.options && type.options.$skipDiscriminatorCheck || false)) {
361
+ if (!exclude && (type?.options?.$skipDiscriminatorCheck || false)) {
360
362
  let cur = '';
361
363
  for (let i = 0; i < pieces.length; ++i) {
362
364
  cur += (cur.length === 0 ? '' : '.') + pieces[i];
@@ -375,14 +377,14 @@ exports.applyPaths = function applyPaths(fields, schema, sanitizeProjection) {
375
377
  /**
376
378
  * Set each path query option to lean
377
379
  *
378
- * @param {Object} option
380
+ * @param {object} option
379
381
  */
380
382
 
381
383
  function makeLean(val) {
382
384
  return function(option) {
383
385
  option.options || (option.options = {});
384
386
 
385
- if (val != null && Array.isArray(val.virtuals)) {
387
+ if (Array.isArray(val?.virtuals)) {
386
388
  val = Object.assign({}, val);
387
389
  val.virtuals = val.virtuals.
388
390
  filter(path => typeof path === 'string' && path.startsWith(option.path + '.')).
@@ -21,23 +21,21 @@ const isOperator = require('../helpers/query/isOperator');
21
21
  const util = require('util');
22
22
  const utils = require('../utils');
23
23
  const castToNumber = require('./operators/helpers').castToNumber;
24
- const createJSONSchemaTypeDefinition = require('../helpers/createJSONSchemaTypeDefinition');
25
24
  const geospatial = require('./operators/geospatial');
26
25
  const getDiscriminatorByValue = require('../helpers/discriminator/getDiscriminatorByValue');
27
26
 
28
27
  let MongooseArray;
29
28
  let EmbeddedDoc;
30
29
 
31
- const isNestedArraySymbol = Symbol('mongoose#isNestedArray');
32
30
  const emptyOpts = Object.freeze({});
33
31
 
34
32
  /**
35
33
  * Array SchemaType constructor
36
34
  *
37
- * @param {String} key
35
+ * @param {string} key
38
36
  * @param {SchemaType} cast
39
- * @param {Object} options
40
- * @param {Object} schemaOptions
37
+ * @param {object} options
38
+ * @param {object} schemaOptions
41
39
  * @param {Schema} parentSchema
42
40
  * @inherits SchemaType
43
41
  * @api public
@@ -48,7 +46,7 @@ function SchemaArray(key, cast, options, schemaOptions, parentSchema) {
48
46
  EmbeddedDoc || (EmbeddedDoc = require('../types').Embedded);
49
47
 
50
48
  let typeKey = 'type';
51
- if (schemaOptions && schemaOptions.typeKey) {
49
+ if (schemaOptions?.typeKey) {
52
50
  typeKey = schemaOptions.typeKey;
53
51
  }
54
52
  this.schemaOptions = schemaOptions;
@@ -67,7 +65,7 @@ function SchemaArray(key, cast, options, schemaOptions, parentSchema) {
67
65
  }
68
66
  }
69
67
 
70
- if (options != null && options.ref != null && castOptions.ref == null) {
68
+ if (options?.ref != null && castOptions.ref == null) {
71
69
  castOptions.ref = options.ref;
72
70
  }
73
71
 
@@ -81,31 +79,21 @@ function SchemaArray(key, cast, options, schemaOptions, parentSchema) {
81
79
  : utils.getFunctionName(cast);
82
80
 
83
81
  const Types = require('./index.js');
84
- const caster = Object.hasOwn(Types, name) ? Types[name] : cast;
82
+ const schemaTypeDefinition = Object.hasOwn(Types, name) ? Types[name] : cast;
85
83
 
86
- this.casterConstructor = caster;
87
-
88
- if (this.casterConstructor instanceof SchemaArray) {
89
- this.casterConstructor[isNestedArraySymbol] = true;
90
- }
91
-
92
- if (typeof caster === 'function' &&
93
- !caster.$isArraySubdocument &&
94
- !caster.$isSchemaMap) {
95
- const path = this.caster instanceof EmbeddedDoc ? null : key;
96
- if (caster === SchemaArray) {
97
- this.caster = new caster(path, castOptions, schemaOptions, null, parentSchema);
84
+ if (typeof schemaTypeDefinition === 'function') {
85
+ if (schemaTypeDefinition === SchemaArray) {
86
+ this.embeddedSchemaType = new schemaTypeDefinition(key, castOptions, schemaOptions, null, parentSchema);
98
87
  } else {
99
- this.caster = new caster(path, castOptions, schemaOptions, parentSchema);
88
+ this.embeddedSchemaType = new schemaTypeDefinition(key, castOptions, schemaOptions, parentSchema);
100
89
  }
101
- } else {
102
- this.caster = caster;
103
- if (!(this.caster instanceof EmbeddedDoc)) {
104
- this.caster.path = key;
90
+ } else if (schemaTypeDefinition instanceof SchemaType) {
91
+ this.embeddedSchemaType = schemaTypeDefinition;
92
+ if (!(this.embeddedSchemaType instanceof EmbeddedDoc)) {
93
+ this.embeddedSchemaType.path = key;
105
94
  }
106
95
  }
107
96
 
108
- this.$embeddedSchemaType = this.caster;
109
97
  }
110
98
 
111
99
  this.$isMongooseArray = true;
@@ -166,13 +154,13 @@ SchemaArray.defaultOptions = {};
166
154
  * #### Example:
167
155
  *
168
156
  * // Make all Array instances have `required` of true by default.
169
- * mongoose.Schema.Array.set('required', true);
157
+ * mongoose.Schema.Types.Array.set('required', true);
170
158
  *
171
159
  * const User = mongoose.model('User', new Schema({ test: Array }));
172
160
  * new User({ }).validateSync().errors.test.message; // Path `test` is required.
173
161
  *
174
- * @param {String} option The option you'd like to set the value for
175
- * @param {Any} value value for option
162
+ * @param {string} option The option you'd like to set the value for
163
+ * @param {any} value value for option
176
164
  * @return {undefined}
177
165
  * @function set
178
166
  * @api public
@@ -235,9 +223,9 @@ SchemaArray.prototype.virtuals = null;
235
223
  /**
236
224
  * Check if the given value satisfies the `required` validator.
237
225
  *
238
- * @param {Any} value
226
+ * @param {any} value
239
227
  * @param {Document} doc
240
- * @return {Boolean}
228
+ * @return {boolean}
241
229
  * @api public
242
230
  */
243
231
 
@@ -259,18 +247,16 @@ SchemaArray.prototype.checkRequired = function checkRequired(value, doc) {
259
247
  * Adds an enum validator if this is an array of strings or numbers. Equivalent to
260
248
  * `SchemaString.prototype.enum()` or `SchemaNumber.prototype.enum()`
261
249
  *
262
- * @param {...String|Object} [args] enumeration values
250
+ * @param {...string|object} [args] enumeration values
263
251
  * @return {SchemaArray} this
264
252
  */
265
253
 
266
254
  SchemaArray.prototype.enum = function() {
267
255
  let arr = this;
268
256
  while (true) {
269
- const instance = arr &&
270
- arr.caster &&
271
- arr.caster.instance;
257
+ const instance = arr?.embeddedSchemaType?.instance;
272
258
  if (instance === 'Array') {
273
- arr = arr.caster;
259
+ arr = arr.embeddedSchemaType;
274
260
  continue;
275
261
  }
276
262
  if (instance !== 'String' && instance !== 'Number') {
@@ -285,20 +271,20 @@ SchemaArray.prototype.enum = function() {
285
271
  enumArray = utils.object.vals(enumArray);
286
272
  }
287
273
 
288
- arr.caster.enum.apply(arr.caster, enumArray);
274
+ arr.embeddedSchemaType.enum.apply(arr.embeddedSchemaType, enumArray);
289
275
  return this;
290
276
  };
291
277
 
292
278
  /**
293
279
  * Overrides the getters application for the population special-case
294
280
  *
295
- * @param {Object} value
296
- * @param {Object} scope
281
+ * @param {object} value
282
+ * @param {object} scope
297
283
  * @api private
298
284
  */
299
285
 
300
286
  SchemaArray.prototype.applyGetters = function(value, scope) {
301
- if (scope != null && scope.$__ != null && scope.$populated(this.path)) {
287
+ if (scope?.$__ != null && scope.$populated(this.path)) {
302
288
  // means the object id was populated
303
289
  return value;
304
290
  }
@@ -308,9 +294,8 @@ SchemaArray.prototype.applyGetters = function(value, scope) {
308
294
  };
309
295
 
310
296
  SchemaArray.prototype._applySetters = function(value, scope, init, priorVal) {
311
- if (this.casterConstructor.$isMongooseArray &&
312
- SchemaArray.options.castNonArrays &&
313
- !this[isNestedArraySymbol]) {
297
+ if (this.embeddedSchemaType.$isMongooseArray &&
298
+ SchemaArray.options.castNonArrays) {
314
299
  // Check nesting levels and wrap in array if necessary
315
300
  let depth = 0;
316
301
  let arr = this;
@@ -318,7 +303,7 @@ SchemaArray.prototype._applySetters = function(value, scope, init, priorVal) {
318
303
  arr.$isMongooseArray &&
319
304
  !arr.$isMongooseDocumentArray) {
320
305
  ++depth;
321
- arr = arr.casterConstructor;
306
+ arr = arr.embeddedSchemaType;
322
307
  }
323
308
 
324
309
  // No need to wrap empty arrays
@@ -338,9 +323,9 @@ SchemaArray.prototype._applySetters = function(value, scope, init, priorVal) {
338
323
  /**
339
324
  * Casts values for set().
340
325
  *
341
- * @param {Object} value
326
+ * @param {object} value
342
327
  * @param {Document} doc document that triggers the casting
343
- * @param {Boolean} init whether this is an initialization cast
328
+ * @param {boolean} init whether this is an initialization cast
344
329
  * @api private
345
330
  */
346
331
 
@@ -388,13 +373,13 @@ SchemaArray.prototype.cast = function(value, doc, init, prev, options) {
388
373
  value = MongooseArray(rawValue, path, doc, this);
389
374
  rawValue = value.__array;
390
375
 
391
- if (init && doc != null && doc.$__ != null && doc.$populated(this.path)) {
376
+ if (init && doc?.$__ != null && doc.$populated(this.path)) {
392
377
  return value;
393
378
  }
394
379
 
395
- const caster = this.caster;
380
+ const caster = this.embeddedSchemaType;
396
381
  const isMongooseArray = caster.$isMongooseArray;
397
- if (caster && this.casterConstructor !== Mixed) {
382
+ if (caster && this.embeddedSchemaType.constructor !== Mixed) {
398
383
  try {
399
384
  const len = rawValue.length;
400
385
  for (i = 0; i < len; i++) {
@@ -412,6 +397,9 @@ SchemaArray.prototype.cast = function(value, doc, init, prev, options) {
412
397
  if (options.hydratedPopulatedDocs) {
413
398
  opts.hydratedPopulatedDocs = options.hydratedPopulatedDocs;
414
399
  }
400
+ if (options.virtuals) {
401
+ opts.virtuals = options.virtuals;
402
+ }
415
403
  rawValue[i] = caster.applySetters(rawValue[i], doc, init, void 0, opts);
416
404
  }
417
405
  } catch (e) {
@@ -423,11 +411,11 @@ SchemaArray.prototype.cast = function(value, doc, init, prev, options) {
423
411
  return value;
424
412
  }
425
413
 
426
- const castNonArraysOption = this.options.castNonArrays != null ? this.options.castNonArrays : SchemaArray.options.castNonArrays;
414
+ const castNonArraysOption = this.options.castNonArrays ?? SchemaArray.options.castNonArrays;
427
415
  if (init || castNonArraysOption) {
428
416
  // gh-2442: if we're loading this from the db and its not an array, mark
429
417
  // the whole array as modified.
430
- if (!!doc && !!init) {
418
+ if (doc && init) {
431
419
  doc.markModified(this.path);
432
420
  }
433
421
  return this.cast([value], doc, init);
@@ -449,19 +437,18 @@ SchemaArray.prototype._castForPopulate = function _castForPopulate(value, doc) {
449
437
  const rawValue = value.__array ? value.__array : value;
450
438
  const len = rawValue.length;
451
439
 
452
- const caster = this.caster;
453
- if (caster && this.casterConstructor !== Mixed) {
440
+ if (this.embeddedSchemaType && this.embeddedSchemaType.constructor !== Mixed) {
454
441
  try {
455
442
  for (i = 0; i < len; i++) {
456
443
  const opts = {};
457
444
  // Perf: creating `arrayPath` is expensive for large arrays.
458
445
  // We only need `arrayPath` if this is a nested array, so
459
446
  // skip if possible.
460
- if (caster.$isMongooseArray && caster._arrayParentPath != null) {
447
+ if (this.embeddedSchemaType.$isMongooseArray && this.embeddedSchemaType._arrayParentPath != null) {
461
448
  opts.arrayPathIndex = i;
462
449
  }
463
450
 
464
- rawValue[i] = caster.cast(rawValue[i], doc, false, void 0, opts);
451
+ rawValue[i] = this.embeddedSchemaType.cast(rawValue[i], doc, false, void 0, opts);
465
452
  }
466
453
  } catch (e) {
467
454
  // rethrow
@@ -484,11 +471,10 @@ SchemaArray.prototype.$toObject = SchemaArray.prototype.toObject;
484
471
  SchemaArray.prototype.discriminator = function(...args) {
485
472
  let arr = this;
486
473
  while (arr.$isMongooseArray && !arr.$isMongooseDocumentArray) {
487
- arr = arr.casterConstructor;
488
- if (arr == null || typeof arr === 'function') {
489
- throw new MongooseError('You can only add an embedded discriminator on ' +
490
- 'a document array, ' + this.path + ' is a plain array');
491
- }
474
+ arr = arr.embeddedSchemaType;
475
+ }
476
+ if (!arr.$isMongooseDocumentArray) {
477
+ throw new MongooseError('You can only add an embedded discriminator on a document array, ' + this.path + ' is a plain array');
492
478
  }
493
479
  return arr.discriminator(...args);
494
480
  };
@@ -499,7 +485,7 @@ SchemaArray.prototype.discriminator = function(...args) {
499
485
 
500
486
  SchemaArray.prototype.clone = function() {
501
487
  const options = Object.assign({}, this.options);
502
- const schematype = new this.constructor(this.path, this.caster, options, this.schemaOptions, this.parentSchema);
488
+ const schematype = new this.constructor(this.path, this.embeddedSchemaType, options, this.schemaOptions, this.parentSchema);
503
489
  schematype.validators = this.validators.slice();
504
490
  if (this.requiredValidator !== undefined) {
505
491
  schematype.requiredValidator = this.requiredValidator;
@@ -508,30 +494,21 @@ SchemaArray.prototype.clone = function() {
508
494
  };
509
495
 
510
496
  SchemaArray.prototype._castForQuery = function(val, context) {
511
- let Constructor = this.casterConstructor;
512
-
513
- if (val &&
514
- Constructor.discriminators &&
515
- Constructor.schema &&
516
- Constructor.schema.options &&
517
- Constructor.schema.options.discriminatorKey) {
518
- if (typeof val[Constructor.schema.options.discriminatorKey] === 'string' &&
519
- Constructor.discriminators[val[Constructor.schema.options.discriminatorKey]]) {
520
- Constructor = Constructor.discriminators[val[Constructor.schema.options.discriminatorKey]];
497
+ let embeddedSchemaType = this.embeddedSchemaType;
498
+ const discriminatorKey = embeddedSchemaType?.schema?.options?.discriminatorKey;
499
+ const discriminators = embeddedSchemaType?.discriminators;
500
+
501
+ if (val && discriminators && typeof discriminatorKey === 'string') {
502
+ if (discriminators[val[discriminatorKey]]) {
503
+ embeddedSchemaType = discriminators[val[discriminatorKey]];
521
504
  } else {
522
- const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, val[Constructor.schema.options.discriminatorKey]);
505
+ const constructorByValue = getDiscriminatorByValue(discriminators, val[discriminatorKey]);
523
506
  if (constructorByValue) {
524
- Constructor = constructorByValue;
507
+ embeddedSchemaType = constructorByValue;
525
508
  }
526
509
  }
527
510
  }
528
511
 
529
- const proto = this.casterConstructor.prototype;
530
- const protoCastForQuery = proto && proto.castForQuery;
531
- const protoCast = proto && proto.cast;
532
- const constructorCastForQuery = Constructor.castForQuery;
533
- const caster = this.caster;
534
-
535
512
  if (Array.isArray(val)) {
536
513
  this.setters.reverse().forEach(setter => {
537
514
  val = setter.call(this, val, this);
@@ -540,30 +517,10 @@ SchemaArray.prototype._castForQuery = function(val, context) {
540
517
  if (utils.isObject(v) && v.$elemMatch) {
541
518
  return v;
542
519
  }
543
- if (protoCastForQuery) {
544
- v = protoCastForQuery.call(caster, null, v, context);
545
- return v;
546
- } else if (protoCast) {
547
- v = protoCast.call(caster, v);
548
- return v;
549
- } else if (constructorCastForQuery) {
550
- v = constructorCastForQuery.call(caster, null, v, context);
551
- return v;
552
- }
553
- if (v != null) {
554
- v = new Constructor(v);
555
- return v;
556
- }
557
- return v;
520
+ return embeddedSchemaType.castForQuery(null, v, context);
558
521
  });
559
- } else if (protoCastForQuery) {
560
- val = protoCastForQuery.call(caster, null, val, context);
561
- } else if (protoCast) {
562
- val = protoCast.call(caster, val);
563
- } else if (constructorCastForQuery) {
564
- val = constructorCastForQuery.call(caster, null, val, context);
565
- } else if (val != null) {
566
- val = new Constructor(val);
522
+ } else {
523
+ val = embeddedSchemaType.castForQuery(null, val, context);
567
524
  }
568
525
 
569
526
  return val;
@@ -572,7 +529,7 @@ SchemaArray.prototype._castForQuery = function(val, context) {
572
529
  /**
573
530
  * Casts values for queries.
574
531
  *
575
- * @param {String} $conditional
532
+ * @param {string} $conditional
576
533
  * @param {any} [value]
577
534
  * @api private
578
535
  */
@@ -596,8 +553,8 @@ SchemaArray.prototype.castForQuery = function($conditional, val, context) {
596
553
  /**
597
554
  * Add a virtual to this array. Specifically to this array, not the individual elements.
598
555
  *
599
- * @param {String} name
600
- * @param {Object} [options]
556
+ * @param {string} name
557
+ * @param {object} [options]
601
558
  * @api private
602
559
  */
603
560
 
@@ -629,12 +586,12 @@ function cast$all(val, context) {
629
586
  return v;
630
587
  }
631
588
  if (v.$elemMatch != null) {
632
- return { $elemMatch: cast(this.casterConstructor.schema, v.$elemMatch, null, this && this.$$context) };
589
+ return { $elemMatch: cast(this.embeddedSchemaType.schema, v.$elemMatch, null, this?.$$context) };
633
590
  }
634
591
 
635
592
  const o = {};
636
593
  o[this.path] = v;
637
- return cast(this.casterConstructor.schema, o, null, this && this.$$context)[this.path];
594
+ return cast(this.embeddedSchemaType.schema, o, null, this?.$$context)[this.path];
638
595
  }, this);
639
596
 
640
597
  return this.castForQuery(null, val, context);
@@ -682,7 +639,7 @@ function createLogicalQueryOperatorHandler(op) {
682
639
 
683
640
  const ret = [];
684
641
  for (const obj of val) {
685
- ret.push(cast(this.casterConstructor.schema ?? context.schema, obj, null, this && this.$$context));
642
+ ret.push(cast(this.embeddedSchemaType.schema ?? context.schema, obj, null, this?.$$context));
686
643
  }
687
644
 
688
645
  return ret;
@@ -719,16 +676,15 @@ handle.$in = SchemaType.prototype.$conditionalHandlers.$in;
719
676
  /**
720
677
  * Returns this schema type's representation in a JSON schema.
721
678
  *
722
- * @param [options]
723
- * @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
724
- * @returns {Object} JSON schema properties
679
+ * @param {object} [options]
680
+ * @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
681
+ * @returns {object} JSON schema properties
725
682
  */
726
683
 
727
684
  SchemaArray.prototype.toJSONSchema = function toJSONSchema(options) {
728
685
  const embeddedSchemaType = this.getEmbeddedSchemaType();
729
- const isRequired = this.options.required && typeof this.options.required !== 'function';
730
686
  return {
731
- ...createJSONSchemaTypeDefinition('array', 'array', options?.useBsonType, isRequired),
687
+ ...this._createJSONSchemaTypeDefinition('array', 'array', options),
732
688
  items: embeddedSchemaType.toJSONSchema(options)
733
689
  };
734
690
  };