mongoose 6.13.11 → 6.13.12
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/dist/browser.umd.js +1 -1
- package/lib/cast.js +8 -4
- package/lib/document.js +11 -1
- package/lib/helpers/discriminator/getConstructor.js +4 -2
- package/lib/helpers/discriminator/getDiscriminatorByKey.js +17 -0
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -1
- package/lib/helpers/path/setDottedPath.js +5 -0
- package/lib/helpers/populate/getModelsMapForPopulate.js +2 -1
- package/lib/helpers/update/castArrayFilters.js +2 -1
- package/lib/model.js +3 -2
- package/lib/query.js +36 -9
- package/lib/queryhelpers.js +2 -1
- package/lib/schema/array.js +11 -7
- package/lib/schema.js +6 -1
- package/lib/types/DocumentArray/methods/index.js +11 -6
- package/lib/utils.js +6 -0
- package/package.json +2 -8
- package/deno.lock +0 -61
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');
|
|
@@ -29,6 +30,7 @@ const ALLOWED_GEOWITHIN_GEOJSON_TYPES = ['Polygon', 'MultiPolygon'];
|
|
|
29
30
|
* @param {Boolean|"throw"} [options.strict] Wheter to enable all strict options
|
|
30
31
|
* @param {Boolean|"throw"} [options.strictQuery] Enable strict Queries
|
|
31
32
|
* @param {Boolean} [options.upsert]
|
|
33
|
+
* @param {Boolean} [options.sanitizeFilter] avoid adding implicit query selectors ($in)
|
|
32
34
|
* @param {Query} [context] passed to setters
|
|
33
35
|
* @api private
|
|
34
36
|
*/
|
|
@@ -132,9 +134,11 @@ module.exports = function cast(schema, obj, options, context) {
|
|
|
132
134
|
discriminatorKey != null &&
|
|
133
135
|
pathLastHalf !== discriminatorKey) {
|
|
134
136
|
const discriminatorVal = get(obj, pathFirstHalf + '.' + discriminatorKey);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
const discriminator = discriminatorVal != null ?
|
|
138
|
+
getDiscriminatorByKey(_schematype.schema.discriminators, discriminatorVal) :
|
|
139
|
+
null;
|
|
140
|
+
if (discriminator != null) {
|
|
141
|
+
schematype = discriminator.path(pathLastHalf);
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
144
|
}
|
|
@@ -340,7 +344,7 @@ module.exports = function cast(schema, obj, options, context) {
|
|
|
340
344
|
}
|
|
341
345
|
}
|
|
342
346
|
}
|
|
343
|
-
} else if (Array.isArray(val) && ['Buffer', 'Array'].indexOf(schematype.instance) === -1) {
|
|
347
|
+
} else if (Array.isArray(val) && ['Buffer', 'Array'].indexOf(schematype.instance) === -1 && !options.sanitizeFilter) {
|
|
344
348
|
const casted = [];
|
|
345
349
|
const valuesArray = val;
|
|
346
350
|
|
package/lib/document.js
CHANGED
|
@@ -754,7 +754,11 @@ function init(self, obj, doc, opts, prefix) {
|
|
|
754
754
|
|
|
755
755
|
const value = obj[i];
|
|
756
756
|
if (!schemaType && utils.isPOJO(value)) {
|
|
757
|
-
// assume nested object
|
|
757
|
+
// assume nested object. Skip inherited properties like `Object.prototype.toString`
|
|
758
|
+
// to avoid setting properties on shared objects
|
|
759
|
+
if (!utils.object.hasOwnProperty(doc, i) && i in doc) {
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
758
762
|
if (!doc[i]) {
|
|
759
763
|
doc[i] = {};
|
|
760
764
|
if (!strict && !(i in docSchema.tree) && !(i in docSchema.methods) && !(i in docSchema.virtuals)) {
|
|
@@ -1722,6 +1726,12 @@ Document.prototype.$__set = function(pathToMark, path, options, constructing, pa
|
|
|
1722
1726
|
obj[parts[i]] = val;
|
|
1723
1727
|
}
|
|
1724
1728
|
} else {
|
|
1729
|
+
// Skip inherited properties like `Object.prototype.toString`, document methods,
|
|
1730
|
+
// or document internals like `$__schema` to avoid setting properties on shared
|
|
1731
|
+
// objects. Document properties are getters on the prototype, so check `_doc`.
|
|
1732
|
+
if (!utils.object.hasOwnProperty(obj.$__ == null ? obj : obj._doc, parts[i]) && parts[i] in obj) {
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1725
1735
|
if (utils.isPOJO(obj[parts[i]])) {
|
|
1726
1736
|
obj = obj[parts[i]];
|
|
1727
1737
|
} else if (obj[parts[i]] && obj[parts[i]] instanceof Embedded) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const getDiscriminatorByKey = require('./getDiscriminatorByKey');
|
|
3
4
|
const getDiscriminatorByValue = require('./getDiscriminatorByValue');
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -12,8 +13,9 @@ module.exports = function getConstructor(Constructor, value) {
|
|
|
12
13
|
if (value != null &&
|
|
13
14
|
Constructor.discriminators &&
|
|
14
15
|
value[discriminatorKey] != null) {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const discriminator = getDiscriminatorByKey(Constructor.discriminators, value[discriminatorKey]);
|
|
17
|
+
if (discriminator) {
|
|
18
|
+
Constructor = discriminator;
|
|
17
19
|
} else {
|
|
18
20
|
const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[discriminatorKey]);
|
|
19
21
|
if (constructorByValue) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the discriminator registered under `key`, ignoring inherited properties
|
|
5
|
+
* like `constructor` or `toString`, because `key` may come from user data.
|
|
6
|
+
*
|
|
7
|
+
* @param {object} discriminators
|
|
8
|
+
* @param {string} key
|
|
9
|
+
* @api private
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
module.exports = function getDiscriminatorByKey(discriminators, key) {
|
|
13
|
+
if (discriminators == null || key == null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(discriminators, key) ? discriminators[key] : null;
|
|
17
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const getDiscriminatorByKey = require('../discriminator/getDiscriminatorByKey');
|
|
3
4
|
const get = require('../get');
|
|
4
5
|
const getSchemaDiscriminatorByValue = require('../discriminator/getSchemaDiscriminatorByValue');
|
|
5
6
|
|
|
@@ -37,7 +38,7 @@ module.exports = function getEmbeddedDiscriminatorPath(doc, path, options) {
|
|
|
37
38
|
const discriminators = schemaType.schema.discriminators;
|
|
38
39
|
const discriminatorKey = doc.get(subpath + '.' +
|
|
39
40
|
get(schemaType, 'schema.options.discriminatorKey'));
|
|
40
|
-
if (discriminatorKey == null || discriminators
|
|
41
|
+
if (discriminatorKey == null || getDiscriminatorByKey(discriminators, discriminatorKey) == null) {
|
|
41
42
|
continue;
|
|
42
43
|
}
|
|
43
44
|
const rest = parts.slice(i + 1).join('.');
|
|
@@ -20,6 +20,11 @@ module.exports = function setDottedPath(obj, path, val) {
|
|
|
20
20
|
if (specialProperties.has(part)) {
|
|
21
21
|
continue;
|
|
22
22
|
}
|
|
23
|
+
// Skip inherited properties like `Object.prototype.toString` to avoid
|
|
24
|
+
// setting properties on shared objects
|
|
25
|
+
if (!Object.prototype.hasOwnProperty.call(cur, part) && part in cur) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
23
28
|
if (cur[part] == null) {
|
|
24
29
|
cur[part] = {};
|
|
25
30
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const MongooseError = require('../../error/index');
|
|
4
4
|
const SkipPopulateValue = require('./SkipPopulateValue');
|
|
5
5
|
const get = require('../get');
|
|
6
|
+
const getDiscriminatorByKey = require('../discriminator/getDiscriminatorByKey');
|
|
6
7
|
const getDiscriminatorByValue = require('../discriminator/getDiscriminatorByValue');
|
|
7
8
|
const getConstructorName = require('../getConstructorName');
|
|
8
9
|
const getSchemaTypes = require('./getSchemaTypes');
|
|
@@ -710,7 +711,7 @@ function _findRefPathForDiscriminators(doc, modelSchema, data, options, normaliz
|
|
|
710
711
|
modelNames = [];
|
|
711
712
|
for (const subdoc of subdocs) {
|
|
712
713
|
const discriminatorName = utils.getValue(discriminatorKey, subdoc);
|
|
713
|
-
const discriminator = schematype.caster.discriminators
|
|
714
|
+
const discriminator = getDiscriminatorByKey(schematype.caster.discriminators, discriminatorName);
|
|
714
715
|
const discriminatorSchema = discriminator && discriminator.schema;
|
|
715
716
|
if (discriminatorSchema == null) {
|
|
716
717
|
continue;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const getDiscriminatorByKey = require('../discriminator/getDiscriminatorByKey');
|
|
3
4
|
const castFilterPath = require('../query/castFilterPath');
|
|
4
5
|
const cleanPositionalOperators = require('../schema/cleanPositionalOperators');
|
|
5
6
|
const getPath = require('../schema/getPath');
|
|
@@ -63,7 +64,7 @@ function _castArrayFilters(arrayFilters, schema, strictQuery, updatedPathsByFilt
|
|
|
63
64
|
if (filterBaseSchema != null &&
|
|
64
65
|
filterBaseSchema.discriminators != null &&
|
|
65
66
|
filter[filterWildcardPath + '.' + filterBaseSchema.options.discriminatorKey]) {
|
|
66
|
-
filterBaseSchema = filterBaseSchema.discriminators
|
|
67
|
+
filterBaseSchema = getDiscriminatorByKey(filterBaseSchema.discriminators, filter[filterWildcardPath + '.' + filterBaseSchema.options.discriminatorKey]) || filterBaseSchema;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
for (const key of keys) {
|
package/lib/model.js
CHANGED
|
@@ -43,6 +43,7 @@ const firstKey = require('./helpers/firstKey');
|
|
|
43
43
|
const each = require('./helpers/each');
|
|
44
44
|
const get = require('./helpers/get');
|
|
45
45
|
const getConstructorName = require('./helpers/getConstructorName');
|
|
46
|
+
const getDiscriminatorByKey = require('./helpers/discriminator/getDiscriminatorByKey');
|
|
46
47
|
const getDiscriminatorByValue = require('./helpers/discriminator/getDiscriminatorByValue');
|
|
47
48
|
const getModelsMapForPopulate = require('./helpers/populate/getModelsMapForPopulate');
|
|
48
49
|
const immediate = require('./helpers/immediate');
|
|
@@ -3191,7 +3192,7 @@ Model.create = function create(doc, options, callback) {
|
|
|
3191
3192
|
args.forEach(doc => {
|
|
3192
3193
|
toExecute.push(callback => {
|
|
3193
3194
|
const Model = this.discriminators && doc[discriminatorKey] != null ?
|
|
3194
|
-
this.discriminators
|
|
3195
|
+
getDiscriminatorByKey(this.discriminators, doc[discriminatorKey]) || getDiscriminatorByValue(this.discriminators, doc[discriminatorKey]) :
|
|
3195
3196
|
this;
|
|
3196
3197
|
if (Model == null) {
|
|
3197
3198
|
throw new MongooseError(`Discriminator "${doc[discriminatorKey]}" not ` +
|
|
@@ -5241,7 +5242,7 @@ Model.compile = function compile(name, schema, collectionName, connection, base)
|
|
|
5241
5242
|
}
|
|
5242
5243
|
|
|
5243
5244
|
// If discriminator key is set, use the discriminator instead (gh-7586)
|
|
5244
|
-
const Discriminator = model.discriminators
|
|
5245
|
+
const Discriminator = getDiscriminatorByKey(model.discriminators, doc[discriminatorKey]) ||
|
|
5245
5246
|
getDiscriminatorByValue(model.discriminators, doc[discriminatorKey]);
|
|
5246
5247
|
if (Discriminator != null) {
|
|
5247
5248
|
return new Discriminator(doc, fields, skipId);
|
package/lib/query.js
CHANGED
|
@@ -20,6 +20,7 @@ const castNumber = require('./cast/number');
|
|
|
20
20
|
const castUpdate = require('./helpers/query/castUpdate');
|
|
21
21
|
const completeMany = require('./helpers/query/completeMany');
|
|
22
22
|
const promiseOrCallback = require('./helpers/promiseOrCallback');
|
|
23
|
+
const getDiscriminatorByKey = require('./helpers/discriminator/getDiscriminatorByKey');
|
|
23
24
|
const getDiscriminatorByValue = require('./helpers/discriminator/getDiscriminatorByValue');
|
|
24
25
|
const hasDollarKeys = require('./helpers/query/hasDollarKeys');
|
|
25
26
|
const helpers = require('./queryhelpers');
|
|
@@ -35,6 +36,7 @@ const sanitizeFilter = require('./helpers/query/sanitizeFilter');
|
|
|
35
36
|
const sanitizeProjection = require('./helpers/query/sanitizeProjection');
|
|
36
37
|
const selectPopulatedFields = require('./helpers/query/selectPopulatedFields');
|
|
37
38
|
const setDefaultsOnInsert = require('./helpers/setDefaultsOnInsert');
|
|
39
|
+
const specialProperties = require('./helpers/specialProperties');
|
|
38
40
|
const updateValidators = require('./helpers/updateValidators');
|
|
39
41
|
const util = require('util');
|
|
40
42
|
const utils = require('./utils');
|
|
@@ -365,6 +367,14 @@ Query.prototype.clone = function clone() {
|
|
|
365
367
|
* @api public
|
|
366
368
|
*/
|
|
367
369
|
|
|
370
|
+
Query.prototype.where = function where(path) {
|
|
371
|
+
if (typeof path === 'string' && specialProperties.has(path)) {
|
|
372
|
+
throw new MongooseError(`Cannot use \`${path}\` as a query path`);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return Query.base.where.apply(this, arguments);
|
|
376
|
+
};
|
|
377
|
+
|
|
368
378
|
/**
|
|
369
379
|
* Specifies a `$slice` projection for an array.
|
|
370
380
|
*
|
|
@@ -741,7 +751,13 @@ Query.prototype.mod = function() {
|
|
|
741
751
|
path = arguments[0];
|
|
742
752
|
}
|
|
743
753
|
|
|
744
|
-
|
|
754
|
+
if (path != null && specialProperties.has(String(path))) {
|
|
755
|
+
throw new MongooseError(`Cannot use \`${path}\` as a query path`);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// Avoid reusing inherited properties like `toString`
|
|
759
|
+
const conds = (utils.object.hasOwnProperty(this._conditions, path) && this._conditions[path]) ||
|
|
760
|
+
(this._conditions[path] = {});
|
|
745
761
|
conds.$mod = val;
|
|
746
762
|
return this;
|
|
747
763
|
};
|
|
@@ -2213,19 +2229,20 @@ Query.prototype.mongooseOptions = function(v) {
|
|
|
2213
2229
|
|
|
2214
2230
|
Query.prototype._castConditions = function() {
|
|
2215
2231
|
let sanitizeFilterOpt = undefined;
|
|
2216
|
-
if (this.model != null &&
|
|
2232
|
+
if (this.model != null && this.model.db.config != null && this.model.db.config.sanitizeFilter != null) {
|
|
2233
|
+
sanitizeFilterOpt = this.model.db.config.sanitizeFilter;
|
|
2234
|
+
} else if (this.model != null && this.model.db.options != null && this.model.db.options.sanitizeFilter != null) {
|
|
2217
2235
|
sanitizeFilterOpt = this.model.db.options.sanitizeFilter;
|
|
2218
|
-
} else if (this.model != null &&
|
|
2236
|
+
} else if (this.model != null && this.model.base.options != null && this.model.base.options.sanitizeFilter != null) {
|
|
2219
2237
|
sanitizeFilterOpt = this.model.base.options.sanitizeFilter;
|
|
2220
2238
|
} else {
|
|
2221
2239
|
sanitizeFilterOpt = this._mongooseOptions.sanitizeFilter;
|
|
2222
2240
|
}
|
|
2223
2241
|
|
|
2224
|
-
if (sanitizeFilterOpt) {
|
|
2225
|
-
sanitizeFilter(this._conditions);
|
|
2226
|
-
}
|
|
2227
|
-
|
|
2228
2242
|
try {
|
|
2243
|
+
if (sanitizeFilterOpt) {
|
|
2244
|
+
sanitizeFilter(this._conditions);
|
|
2245
|
+
}
|
|
2229
2246
|
this.cast(this.model);
|
|
2230
2247
|
this._unsetCastError();
|
|
2231
2248
|
} catch (err) {
|
|
@@ -5132,7 +5149,7 @@ Query.prototype._castUpdate = function _castUpdate(obj, overwrite) {
|
|
|
5132
5149
|
schema.discriminators != null) {
|
|
5133
5150
|
const discriminatorValue = filter[schema.options.discriminatorKey];
|
|
5134
5151
|
const byValue = getDiscriminatorByValue(this.model.discriminators, discriminatorValue);
|
|
5135
|
-
schema = schema.discriminators
|
|
5152
|
+
schema = getDiscriminatorByKey(schema.discriminators, discriminatorValue) ||
|
|
5136
5153
|
(byValue && byValue.schema) ||
|
|
5137
5154
|
schema;
|
|
5138
5155
|
}
|
|
@@ -5153,7 +5170,8 @@ Query.prototype._castUpdate = function _castUpdate(obj, overwrite) {
|
|
|
5153
5170
|
|
|
5154
5171
|
function castQuery(query) {
|
|
5155
5172
|
try {
|
|
5156
|
-
|
|
5173
|
+
query._castConditions();
|
|
5174
|
+
return query.error() || query._conditions;
|
|
5157
5175
|
} catch (err) {
|
|
5158
5176
|
return err;
|
|
5159
5177
|
}
|
|
@@ -5350,6 +5368,15 @@ Query.prototype.cast = function(model, obj) {
|
|
|
5350
5368
|
opts.strictQuery = this.options.strictQuery;
|
|
5351
5369
|
}
|
|
5352
5370
|
}
|
|
5371
|
+
if (model.db.config != null && model.db.config.sanitizeFilter != null) {
|
|
5372
|
+
opts.sanitizeFilter = model.db.config.sanitizeFilter;
|
|
5373
|
+
} else if (model.db.options != null && model.db.options.sanitizeFilter != null) {
|
|
5374
|
+
opts.sanitizeFilter = model.db.options.sanitizeFilter;
|
|
5375
|
+
} else if (model.base.options != null && model.base.options.sanitizeFilter != null) {
|
|
5376
|
+
opts.sanitizeFilter = model.base.options.sanitizeFilter;
|
|
5377
|
+
} else {
|
|
5378
|
+
opts.sanitizeFilter = this._mongooseOptions.sanitizeFilter;
|
|
5379
|
+
}
|
|
5353
5380
|
|
|
5354
5381
|
try {
|
|
5355
5382
|
return cast(model.schema, obj, opts, this);
|
package/lib/queryhelpers.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Module dependencies
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const getDiscriminatorByKey = require('./helpers/discriminator/getDiscriminatorByKey');
|
|
7
8
|
const checkEmbeddedDiscriminatorKeyProjection =
|
|
8
9
|
require('./helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection');
|
|
9
10
|
const get = require('./helpers/get');
|
|
@@ -104,7 +105,7 @@ exports.createModel = function createModel(model, doc, fields, userProvidedField
|
|
|
104
105
|
|
|
105
106
|
const value = doc[key];
|
|
106
107
|
if (key && value && model.discriminators) {
|
|
107
|
-
const discriminator = model.discriminators
|
|
108
|
+
const discriminator = getDiscriminatorByKey(model.discriminators, value) || getDiscriminatorByValue(model.discriminators, value);
|
|
108
109
|
if (discriminator) {
|
|
109
110
|
const _fields = clone(userProvidedFields);
|
|
110
111
|
exports.applyPaths(_fields, discriminator.schema);
|
package/lib/schema/array.js
CHANGED
|
@@ -18,6 +18,7 @@ const util = require('util');
|
|
|
18
18
|
const utils = require('../utils');
|
|
19
19
|
const castToNumber = require('./operators/helpers').castToNumber;
|
|
20
20
|
const geospatial = require('./operators/geospatial');
|
|
21
|
+
const getDiscriminatorByKey = require('../helpers/discriminator/getDiscriminatorByKey');
|
|
21
22
|
const getDiscriminatorByValue = require('../helpers/discriminator/getDiscriminatorByValue');
|
|
22
23
|
|
|
23
24
|
let MongooseArray;
|
|
@@ -506,9 +507,11 @@ SchemaArray.prototype.castForQuery = function($conditional, value) {
|
|
|
506
507
|
Constructor.schema &&
|
|
507
508
|
Constructor.schema.options &&
|
|
508
509
|
Constructor.schema.options.discriminatorKey) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
510
|
+
const discriminator = typeof val[Constructor.schema.options.discriminatorKey] === 'string' ?
|
|
511
|
+
getDiscriminatorByKey(Constructor.discriminators, val[Constructor.schema.options.discriminatorKey]) :
|
|
512
|
+
null;
|
|
513
|
+
if (discriminator) {
|
|
514
|
+
Constructor = discriminator;
|
|
512
515
|
} else {
|
|
513
516
|
const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, val[Constructor.schema.options.discriminatorKey]);
|
|
514
517
|
if (constructorByValue) {
|
|
@@ -595,10 +598,11 @@ function cast$elemMatch(val) {
|
|
|
595
598
|
this.casterConstructor &&
|
|
596
599
|
this.casterConstructor.schema &&
|
|
597
600
|
this.casterConstructor.schema.discriminators || {};
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
601
|
+
const discriminator = discriminatorKey != null && val[discriminatorKey] != null ?
|
|
602
|
+
getDiscriminatorByKey(discriminators, val[discriminatorKey]) :
|
|
603
|
+
null;
|
|
604
|
+
if (discriminator != null) {
|
|
605
|
+
return cast(discriminator, val, null, this && this.$$context);
|
|
602
606
|
}
|
|
603
607
|
|
|
604
608
|
return cast(this.casterConstructor.schema, val, null, this && this.$$context);
|
package/lib/schema.js
CHANGED
|
@@ -2142,6 +2142,12 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2142
2142
|
if (name instanceof VirtualType || getConstructorName(name) === 'VirtualType') {
|
|
2143
2143
|
return this.virtual(name.path, name.options);
|
|
2144
2144
|
}
|
|
2145
|
+
const parts = name.split('.');
|
|
2146
|
+
for (const part of parts) {
|
|
2147
|
+
if (utils.specialProperties.has(part)) {
|
|
2148
|
+
throw new MongooseError('Cannot set special property `' + part + '` on a schema');
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2145
2151
|
options = new VirtualOptions(options);
|
|
2146
2152
|
|
|
2147
2153
|
if (utils.hasUserDefinedProperty(options, ['ref', 'refPath'])) {
|
|
@@ -2224,7 +2230,6 @@ Schema.prototype.virtual = function(name, options) {
|
|
|
2224
2230
|
}
|
|
2225
2231
|
|
|
2226
2232
|
const virtuals = this.virtuals;
|
|
2227
|
-
const parts = name.split('.');
|
|
2228
2233
|
|
|
2229
2234
|
if (this.pathType(name) === 'real') {
|
|
2230
2235
|
throw new Error('Virtual path "' + name + '"' +
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const ArrayMethods = require('../../array/methods');
|
|
4
4
|
const Document = require('../../../document');
|
|
5
5
|
const castObjectId = require('../../../cast/objectid');
|
|
6
|
+
const getDiscriminatorByKey = require('../../../helpers/discriminator/getDiscriminatorByKey');
|
|
6
7
|
const getDiscriminatorByValue = require('../../../helpers/discriminator/getDiscriminatorByValue');
|
|
7
8
|
const internalToObjectOptions = require('../../../options').internalToObjectOptions;
|
|
8
9
|
const utils = require('../../../utils');
|
|
@@ -75,9 +76,11 @@ const methods = {
|
|
|
75
76
|
Constructor.schema &&
|
|
76
77
|
Constructor.schema.options &&
|
|
77
78
|
Constructor.schema.options.discriminatorKey) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const discriminator = typeof value[Constructor.schema.options.discriminatorKey] === 'string' ?
|
|
80
|
+
getDiscriminatorByKey(Constructor.discriminators, value[Constructor.schema.options.discriminatorKey]) :
|
|
81
|
+
null;
|
|
82
|
+
if (discriminator) {
|
|
83
|
+
Constructor = discriminator;
|
|
81
84
|
} else {
|
|
82
85
|
const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[Constructor.schema.options.discriminatorKey]);
|
|
83
86
|
if (constructorByValue) {
|
|
@@ -268,9 +271,11 @@ const methods = {
|
|
|
268
271
|
Constructor.schema &&
|
|
269
272
|
Constructor.schema.options &&
|
|
270
273
|
Constructor.schema.options.discriminatorKey) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
+
const discriminator = typeof obj[Constructor.schema.options.discriminatorKey] === 'string' ?
|
|
275
|
+
getDiscriminatorByKey(Constructor.discriminators, obj[Constructor.schema.options.discriminatorKey]) :
|
|
276
|
+
null;
|
|
277
|
+
if (discriminator) {
|
|
278
|
+
Constructor = discriminator;
|
|
274
279
|
} else {
|
|
275
280
|
const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, obj[Constructor.schema.options.discriminatorKey]);
|
|
276
281
|
if (constructorByValue) {
|
package/lib/utils.js
CHANGED
|
@@ -905,6 +905,12 @@ exports.mergeClone = function(to, fromObj) {
|
|
|
905
905
|
if (specialProperties.has(key)) {
|
|
906
906
|
continue;
|
|
907
907
|
}
|
|
908
|
+
// Skip inherited properties like `Object.prototype.toString` to avoid setting
|
|
909
|
+
// properties on shared objects. Document properties are getters on the
|
|
910
|
+
// prototype, so check `_doc`.
|
|
911
|
+
if (!exports.object.hasOwnProperty(to.$__ == null ? to : to._doc, key) && key in to) {
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
908
914
|
if (typeof to[key] === 'undefined') {
|
|
909
915
|
to[key] = exports.clone(fromObj[key], {
|
|
910
916
|
transform: false,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.13.
|
|
4
|
+
"version": "6.13.12",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"kareem": "2.5.1",
|
|
24
24
|
"mongodb": "4.17.2",
|
|
25
25
|
"mpath": "0.9.0",
|
|
26
|
-
"mquery": "4.0.
|
|
26
|
+
"mquery": "4.0.4",
|
|
27
27
|
"ms": "2.1.3",
|
|
28
28
|
"sift": "16.0.1"
|
|
29
29
|
},
|
|
@@ -78,25 +78,20 @@
|
|
|
78
78
|
"scripts": {
|
|
79
79
|
"docs:clean": "npm run docs:clean:stable",
|
|
80
80
|
"docs:clean:stable": "rimraf index.html && rimraf -rf ./docs/*.html && rimraf -rf ./docs/api && rimraf -rf ./docs/tutorials/*.html && rimraf -rf ./docs/typescript/*.html && rimraf -rf ./docs/*.html && rimraf -rf ./docs/source/_docs && rimraf -rf ./tmp",
|
|
81
|
-
"docs:clean:5x": "rimraf index.html && rimraf -rf ./docs/5.x && rimraf -rf ./docs/source/_docs && rimraf -rf ./tmp",
|
|
82
81
|
"docs:clean:6x": "rimraf index.html && rimraf -rf ./docs/6.x && rimraf -rf ./docs/source/_docs && rimraf -rf ./tmp",
|
|
83
82
|
"docs:copy:tmp": "mkdirp ./tmp/docs/css && mkdirp ./tmp/docs/js && mkdirp ./tmp/docs/images && mkdirp ./tmp/docs/tutorials && mkdirp ./tmp/docs/typescript && mkdirp ./tmp/docs/api && ncp ./docs/css ./tmp/docs/css --filter=.css$ && ncp ./docs/js ./tmp/docs/js --filter=.js$ && ncp ./docs/images ./tmp/docs/images && ncp ./docs/tutorials ./tmp/docs/tutorials && ncp ./docs/typescript ./tmp/docs/typescript && ncp ./docs/api ./tmp/docs/api && cp index.html ./tmp && cp docs/*.html ./tmp/docs/",
|
|
84
|
-
"docs:copy:tmp:5x": "rimraf ./docs/5.x && ncp ./tmp ./docs/5.x",
|
|
85
83
|
"docs:move:6x:tmp": "mv ./docs/6.x ./tmp",
|
|
86
84
|
"docs:copy:tmp:6x": "rimraf ./docs/6.x && ncp ./tmp ./docs/6.x",
|
|
87
85
|
"docs:checkout:gh-pages": "git checkout gh-pages",
|
|
88
|
-
"docs:checkout:5x": "git checkout 5.x",
|
|
89
86
|
"docs:checkout:6x": "git checkout 6.x",
|
|
90
87
|
"docs:generate": "node ./scripts/website.js",
|
|
91
88
|
"docs:generate:search": "node ./scripts/generateSearch.js",
|
|
92
89
|
"docs:generate:sponsorData": "node ./scripts/loadSponsorData.js",
|
|
93
90
|
"docs:merge:stable": "git merge master",
|
|
94
|
-
"docs:merge:5x": "git merge 5.x",
|
|
95
91
|
"docs:merge:6x": "git merge 6.x",
|
|
96
92
|
"docs:test": "npm run docs:generate && npm run docs:generate:search",
|
|
97
93
|
"docs:view": "node ./scripts/static.js",
|
|
98
94
|
"docs:prepare:publish:stable": "npm run docs:checkout:gh-pages && npm run docs:merge:stable && npm run docs:clean:stable && npm run docs:generate && npm run docs:generate:search",
|
|
99
|
-
"docs:prepare:publish:5x": "npm run docs:checkout:5x && npm run docs:merge:5x && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:5x",
|
|
100
95
|
"docs:prepare:publish:6x": "npm run docs:checkout:6x && npm run docs:merge:6x && npm run docs:clean:stable && env DOCS_DEPLOY=true npm run docs:generate && npm run docs:move:6x:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:6x",
|
|
101
96
|
"docs:check-links": "blc http://127.0.0.1:8089 -ro",
|
|
102
97
|
"lint": "eslint .",
|
|
@@ -106,7 +101,6 @@
|
|
|
106
101
|
"build-browser": "(rm ./dist/* || true) && node ./scripts/build-browser.js",
|
|
107
102
|
"prepublishOnly": "npm run build-browser",
|
|
108
103
|
"release": "git pull && git push origin master --tags && npm publish",
|
|
109
|
-
"release-5x": "git pull origin 5.x && git push origin 5.x && git push origin 5.x --tags && npm publish --tag 5x",
|
|
110
104
|
"release-6x": "git pull origin 6.x && git push origin 6.x && git push origin 6.x --tags && npm publish --tag 6x",
|
|
111
105
|
"mongo": "node ./tools/repl.js",
|
|
112
106
|
"test": "mocha --exit ./test/*.test.js",
|
package/deno.lock
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "5",
|
|
3
|
-
"redirects": {
|
|
4
|
-
"https://deno.land/std/flags/mod.ts": "https://deno.land/std@0.224.0/flags/mod.ts"
|
|
5
|
-
},
|
|
6
|
-
"remote": {
|
|
7
|
-
"https://deno.land/std@0.224.0/assert/assert_exists.ts": "43420cf7f956748ae6ed1230646567b3593cb7a36c5a5327269279c870c5ddfd",
|
|
8
|
-
"https://deno.land/std@0.224.0/assert/assertion_error.ts": "ba8752bd27ebc51f723702fac2f54d3e94447598f54264a6653d6413738a8917",
|
|
9
|
-
"https://deno.land/std@0.224.0/flags/mod.ts": "88553267f34519c8982212185339efdb2d2e62c159ec558f47eb50c8952a6be3"
|
|
10
|
-
},
|
|
11
|
-
"workspace": {
|
|
12
|
-
"packageJson": {
|
|
13
|
-
"dependencies": [
|
|
14
|
-
"npm:@ark/attest@0.56.3",
|
|
15
|
-
"npm:@eslint/js@^9.39.3",
|
|
16
|
-
"npm:@mongodb-js/mongodb-downloader@1",
|
|
17
|
-
"npm:@standard-schema/spec@^1.1.0",
|
|
18
|
-
"npm:@types/node@^20.19.0",
|
|
19
|
-
"npm:acquit-ignore@0.2.2",
|
|
20
|
-
"npm:acquit-require@0.1.1",
|
|
21
|
-
"npm:acquit@1.4.0",
|
|
22
|
-
"npm:ajv@8.20.0",
|
|
23
|
-
"npm:c8@11.0.0",
|
|
24
|
-
"npm:cheerio@1.2.0",
|
|
25
|
-
"npm:dox@1.0.0",
|
|
26
|
-
"npm:eslint-plugin-mocha-no-only@1.2.0",
|
|
27
|
-
"npm:eslint@10.8.0",
|
|
28
|
-
"npm:express@5.2.1",
|
|
29
|
-
"npm:fs-extra@11.4",
|
|
30
|
-
"npm:glob@^13.0.6",
|
|
31
|
-
"npm:globals@^17.4.0",
|
|
32
|
-
"npm:highlight.js@11.11.1",
|
|
33
|
-
"npm:kareem@3.3.0",
|
|
34
|
-
"npm:linkinator@8",
|
|
35
|
-
"npm:lodash.isequal@4.5.0",
|
|
36
|
-
"npm:lodash.isequalwith@4.4.0",
|
|
37
|
-
"npm:markdownlint-cli2@0.23.2",
|
|
38
|
-
"npm:marked@18.0.7",
|
|
39
|
-
"npm:mkdirp@^3.0.1",
|
|
40
|
-
"npm:mocha@12.0.0-rc.5",
|
|
41
|
-
"npm:moment@2.30.1",
|
|
42
|
-
"npm:mongodb-client-encryption@^7.2.0",
|
|
43
|
-
"npm:mongodb-memory-server@11.2.0",
|
|
44
|
-
"npm:mongodb-runner@6",
|
|
45
|
-
"npm:mongodb@7.5",
|
|
46
|
-
"npm:mpath@0.9.0",
|
|
47
|
-
"npm:mquery@6.0.0",
|
|
48
|
-
"npm:ms@2.1.3",
|
|
49
|
-
"npm:ncp@2",
|
|
50
|
-
"npm:pug@3.0.4",
|
|
51
|
-
"npm:sift@17.1.3",
|
|
52
|
-
"npm:sinon@22.1.0",
|
|
53
|
-
"npm:tstyche@7",
|
|
54
|
-
"npm:typescript-eslint@^8.31.1",
|
|
55
|
-
"npm:typescript@5.9.3",
|
|
56
|
-
"npm:uuid@14.0.1",
|
|
57
|
-
"npm:xss@1.0.15"
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|