mongoose 9.11.3 → 9.12.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.
- package/lib/cast.js +4 -2
- package/lib/document.js +197 -288
- package/lib/helpers/discriminator/getConstructor.js +4 -2
- package/lib/helpers/discriminator/getDiscriminatorByKey.js +17 -0
- package/lib/helpers/document/applyDefaults.js +6 -11
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -1
- package/lib/helpers/model/discriminator.js +3 -0
- package/lib/helpers/path/setDottedPath.js +5 -0
- package/lib/helpers/populate/getModelsMapForPopulate.js +2 -1
- package/lib/helpers/query/castUpdate.js +4 -3
- package/lib/helpers/schema/getPath.js +3 -1
- package/lib/helpers/update/applyTimestampsToUpdate.js +1 -1
- package/lib/helpers/update/castArrayFilters.js +2 -1
- package/lib/model.js +18 -10
- package/lib/query.js +24 -38
- package/lib/queryHelpers.js +8 -2
- package/lib/schema/array.js +4 -2
- package/lib/schema/documentArray.js +20 -7
- package/lib/schema/number.js +3 -1
- package/lib/schema/string.js +3 -1
- package/lib/schema/subdocument.js +9 -1
- package/lib/schema.js +120 -5
- package/lib/stateMachine.js +5 -2
- package/lib/types/array/methods/index.js +4 -1
- package/lib/types/arraySubdocument.js +11 -9
- package/lib/types/documentArray/methods/index.js +11 -6
- package/lib/types/map.js +16 -0
- package/lib/types/subdocument.js +5 -1
- package/lib/utils.js +6 -0
- package/package.json +15 -16
- package/types/types.d.ts +12 -0
package/lib/cast.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Module dependencies.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const getDiscriminatorByKey = require('./helpers/discriminator/getDiscriminatorByKey');
|
|
7
8
|
const CastError = require('./error/cast');
|
|
8
9
|
const StrictModeError = require('./error/strict');
|
|
9
10
|
const Types = require('./schema/index');
|
|
@@ -138,8 +139,9 @@ module.exports = function cast(schema, obj, options, context) {
|
|
|
138
139
|
pathLastHalf !== discriminatorKey) {
|
|
139
140
|
const discriminatorVal = getDiscriminatorValueFromFilter(get(obj, pathFirstHalf + '.' + discriminatorKey));
|
|
140
141
|
const discriminators = _schematype.schema.discriminators;
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
const discriminator = typeof discriminatorVal === 'string' ? getDiscriminatorByKey(discriminators, discriminatorVal) : null;
|
|
143
|
+
if (discriminator != null) {
|
|
144
|
+
schematype = discriminator.path(pathLastHalf);
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
}
|