mongoose 7.6.3 → 7.6.4
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/connection.js +4 -0
- package/lib/document.js +11 -1
- package/lib/helpers/populate/getModelsMapForPopulate.js +2 -1
- package/lib/model.js +0 -2
- package/lib/query.js +0 -1
- package/lib/schema/SubdocumentPath.js +6 -3
- package/lib/schema/array.js +2 -2
- package/lib/schema.js +3 -1
- package/lib/schematype.js +2 -0
- package/package.json +1 -1
- package/types/validation.d.ts +1 -0
package/lib/connection.js
CHANGED
|
@@ -563,6 +563,10 @@ function _resetSessionDocuments(session) {
|
|
|
563
563
|
doc.$__.activePaths.states.modify = {};
|
|
564
564
|
}
|
|
565
565
|
for (const path of state.modifiedPaths) {
|
|
566
|
+
const currentState = doc.$__.activePaths.paths[path];
|
|
567
|
+
if (currentState != null) {
|
|
568
|
+
delete doc.$__.activePaths[currentState][path];
|
|
569
|
+
}
|
|
566
570
|
doc.$__.activePaths.paths[path] = 'modify';
|
|
567
571
|
doc.$__.activePaths.states.modify[path] = true;
|
|
568
572
|
}
|
package/lib/document.js
CHANGED
|
@@ -53,6 +53,7 @@ const scopeSymbol = require('./helpers/symbols').scopeSymbol;
|
|
|
53
53
|
const schemaMixedSymbol = require('./schema/symbols').schemaMixedSymbol;
|
|
54
54
|
const parentPaths = require('./helpers/path/parentPaths');
|
|
55
55
|
const getDeepestSubdocumentForPath = require('./helpers/document/getDeepestSubdocumentForPath');
|
|
56
|
+
const sessionNewDocuments = require('./helpers/symbols').sessionNewDocuments;
|
|
56
57
|
|
|
57
58
|
let DocumentArray;
|
|
58
59
|
let MongooseArray;
|
|
@@ -1474,7 +1475,16 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1474
1475
|
|
|
1475
1476
|
this.$__set(pathToMark, path, options, constructing, parts, schema, val, priorVal);
|
|
1476
1477
|
|
|
1477
|
-
|
|
1478
|
+
const isInTransaction = !!this.$__.session?.transaction;
|
|
1479
|
+
const isModifiedWithinTransaction = this.$__.session &&
|
|
1480
|
+
this.$__.session[sessionNewDocuments] &&
|
|
1481
|
+
this.$__.session[sessionNewDocuments].has(this) &&
|
|
1482
|
+
this.$__.session[sessionNewDocuments].get(this).modifiedPaths &&
|
|
1483
|
+
!this.$__.session[sessionNewDocuments].get(this).modifiedPaths.has(savedStatePath);
|
|
1484
|
+
if (savedState != null &&
|
|
1485
|
+
savedState.hasOwnProperty(savedStatePath) &&
|
|
1486
|
+
(!isInTransaction || isModifiedWithinTransaction) &&
|
|
1487
|
+
utils.deepEqual(val, savedState[savedStatePath])) {
|
|
1478
1488
|
this.unmarkModified(path);
|
|
1479
1489
|
}
|
|
1480
1490
|
}
|
|
@@ -45,7 +45,8 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
|
|
|
45
45
|
let allSchemaTypes = getSchemaTypes(model, modelSchema, null, options.path);
|
|
46
46
|
allSchemaTypes = Array.isArray(allSchemaTypes) ? allSchemaTypes : [allSchemaTypes].filter(v => v != null);
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const isStrictPopulateDisabled = options.strictPopulate === false || options.options?.strictPopulate === false;
|
|
49
|
+
if (!isStrictPopulateDisabled && allSchemaTypes.length === 0 && options._localModel != null) {
|
|
49
50
|
return new StrictPopulate(options._fullPath || options.path);
|
|
50
51
|
}
|
|
51
52
|
|
package/lib/model.js
CHANGED
|
@@ -4263,9 +4263,7 @@ Model.populate = async function populate(docs, paths) {
|
|
|
4263
4263
|
if (typeof paths === 'function' || typeof arguments[2] === 'function') {
|
|
4264
4264
|
throw new MongooseError('Model.populate() no longer accepts a callback');
|
|
4265
4265
|
}
|
|
4266
|
-
|
|
4267
4266
|
const _this = this;
|
|
4268
|
-
|
|
4269
4267
|
// normalized paths
|
|
4270
4268
|
paths = utils.populate(paths);
|
|
4271
4269
|
// data that should persist across subPopulate calls
|
package/lib/query.js
CHANGED
|
@@ -2305,7 +2305,6 @@ Query.prototype._find = async function _find() {
|
|
|
2305
2305
|
_completeManyLean(_this.model.schema, docs, null, completeManyOptions) :
|
|
2306
2306
|
completeMany(_this.model, docs, fields, userProvidedFields, completeManyOptions);
|
|
2307
2307
|
}
|
|
2308
|
-
|
|
2309
2308
|
const pop = helpers.preparePopulationOptionsMQ(_this, mongooseOptions);
|
|
2310
2309
|
|
|
2311
2310
|
if (mongooseOptions.lean) {
|
|
@@ -56,7 +56,7 @@ function SubdocumentPath(schema, path, options) {
|
|
|
56
56
|
this.base = schema.base;
|
|
57
57
|
SchemaType.call(this, path, options, 'Embedded');
|
|
58
58
|
|
|
59
|
-
if (schema._applyDiscriminators != null) {
|
|
59
|
+
if (schema._applyDiscriminators != null && !options?._skipApplyDiscriminators) {
|
|
60
60
|
for (const disc of schema._applyDiscriminators.keys()) {
|
|
61
61
|
this.discriminator(disc, schema._applyDiscriminators.get(disc));
|
|
62
62
|
}
|
|
@@ -388,8 +388,11 @@ SubdocumentPath.prototype.toJSON = function toJSON() {
|
|
|
388
388
|
*/
|
|
389
389
|
|
|
390
390
|
SubdocumentPath.prototype.clone = function() {
|
|
391
|
-
const
|
|
392
|
-
|
|
391
|
+
const schematype = new this.constructor(
|
|
392
|
+
this.schema,
|
|
393
|
+
this.path,
|
|
394
|
+
{ ...this.options, _skipApplyDiscriminators: true }
|
|
395
|
+
);
|
|
393
396
|
schematype.validators = this.validators.slice();
|
|
394
397
|
if (this.requiredValidator !== undefined) {
|
|
395
398
|
schematype.requiredValidator = this.requiredValidator;
|
package/lib/schema/array.js
CHANGED
|
@@ -623,8 +623,8 @@ function cast$elemMatch(val, context) {
|
|
|
623
623
|
discriminators[val[discriminatorKey]] != null) {
|
|
624
624
|
return cast(discriminators[val[discriminatorKey]], val, null, this && this.$$context);
|
|
625
625
|
}
|
|
626
|
-
|
|
627
|
-
return cast(
|
|
626
|
+
const schema = this.casterConstructor.schema ?? context.schema;
|
|
627
|
+
return cast(schema, val, null, this && this.$$context);
|
|
628
628
|
}
|
|
629
629
|
|
|
630
630
|
const handle = SchemaArray.prototype.$conditionalHandlers = {};
|
package/lib/schema.js
CHANGED
|
@@ -412,7 +412,9 @@ Schema.prototype._clone = function _clone(Constructor) {
|
|
|
412
412
|
s.s.hooks = this.s.hooks.clone();
|
|
413
413
|
|
|
414
414
|
s.tree = clone(this.tree);
|
|
415
|
-
s.paths =
|
|
415
|
+
s.paths = Object.fromEntries(
|
|
416
|
+
Object.entries(this.paths).map(([key, value]) => ([key, value.clone()]))
|
|
417
|
+
);
|
|
416
418
|
s.nested = clone(this.nested);
|
|
417
419
|
s.subpaths = clone(this.subpaths);
|
|
418
420
|
for (const schemaType of Object.values(s.paths)) {
|
package/lib/schematype.js
CHANGED
|
@@ -1305,6 +1305,7 @@ SchemaType.prototype.doValidate = function(value, fn, scope, options) {
|
|
|
1305
1305
|
|
|
1306
1306
|
const validatorProperties = isSimpleValidator(v) ? Object.assign({}, v) : clone(v);
|
|
1307
1307
|
validatorProperties.path = options && options.path ? options.path : path;
|
|
1308
|
+
validatorProperties.fullPath = this.$fullPath;
|
|
1308
1309
|
validatorProperties.value = value;
|
|
1309
1310
|
|
|
1310
1311
|
if (validator instanceof RegExp) {
|
|
@@ -1426,6 +1427,7 @@ SchemaType.prototype.doValidateSync = function(value, scope, options) {
|
|
|
1426
1427
|
const validator = v.validator;
|
|
1427
1428
|
const validatorProperties = isSimpleValidator(v) ? Object.assign({}, v) : clone(v);
|
|
1428
1429
|
validatorProperties.path = options && options.path ? options.path : path;
|
|
1430
|
+
validatorProperties.fullPath = this.$fullPath;
|
|
1429
1431
|
validatorProperties.value = value;
|
|
1430
1432
|
let ok = false;
|
|
1431
1433
|
|
package/package.json
CHANGED