mongoose 7.4.1 → 7.4.2
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/document.js +17 -8
- package/lib/helpers/model/castBulkWrite.js +6 -4
- package/lib/helpers/schema/idGetter.js +3 -0
- package/lib/model.js +18 -13
- package/lib/schema.js +19 -1
- package/package.json +6 -6
package/lib/document.js
CHANGED
|
@@ -2216,7 +2216,7 @@ Document.prototype.isModified = function(paths, modifiedPaths) {
|
|
|
2216
2216
|
}
|
|
2217
2217
|
|
|
2218
2218
|
if (typeof paths === 'string') {
|
|
2219
|
-
paths = [paths];
|
|
2219
|
+
paths = paths.indexOf(' ') === -1 ? [paths] : paths.split(' ');
|
|
2220
2220
|
}
|
|
2221
2221
|
|
|
2222
2222
|
for (const path of paths) {
|
|
@@ -2619,7 +2619,7 @@ function _evaluateRequiredFunctions(doc) {
|
|
|
2619
2619
|
*/
|
|
2620
2620
|
|
|
2621
2621
|
function _getPathsToValidate(doc, pathsToValidate, pathsToSkip) {
|
|
2622
|
-
const
|
|
2622
|
+
const doValidateOptions = {};
|
|
2623
2623
|
|
|
2624
2624
|
_evaluateRequiredFunctions(doc);
|
|
2625
2625
|
// only validate required fields when necessary
|
|
@@ -2656,8 +2656,17 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip) {
|
|
|
2656
2656
|
!doc.isDirectModified(fullPathToSubdoc) &&
|
|
2657
2657
|
!doc.$isDefault(fullPathToSubdoc)) {
|
|
2658
2658
|
paths.add(fullPathToSubdoc);
|
|
2659
|
+
if (doc.$__.pathsToScopes == null) {
|
|
2660
|
+
doc.$__.pathsToScopes = {};
|
|
2661
|
+
}
|
|
2662
|
+
doc.$__.pathsToScopes[fullPathToSubdoc] = subdoc.$isDocumentArrayElement ?
|
|
2663
|
+
subdoc.__parentArray :
|
|
2664
|
+
subdoc.$parent();
|
|
2659
2665
|
|
|
2660
|
-
|
|
2666
|
+
doValidateOptions[fullPathToSubdoc] = { skipSchemaValidators: true };
|
|
2667
|
+
if (subdoc.$isDocumentArrayElement && subdoc.__index != null) {
|
|
2668
|
+
doValidateOptions[fullPathToSubdoc].index = subdoc.__index;
|
|
2669
|
+
}
|
|
2661
2670
|
}
|
|
2662
2671
|
}
|
|
2663
2672
|
}
|
|
@@ -2791,7 +2800,7 @@ function _getPathsToValidate(doc, pathsToValidate, pathsToSkip) {
|
|
|
2791
2800
|
}
|
|
2792
2801
|
|
|
2793
2802
|
paths = Array.from(paths);
|
|
2794
|
-
return [paths,
|
|
2803
|
+
return [paths, doValidateOptions];
|
|
2795
2804
|
}
|
|
2796
2805
|
|
|
2797
2806
|
/*!
|
|
@@ -2862,7 +2871,7 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
|
|
|
2862
2871
|
const paths = shouldValidateModifiedOnly ?
|
|
2863
2872
|
pathDetails[0].filter((path) => this.$isModified(path)) :
|
|
2864
2873
|
pathDetails[0];
|
|
2865
|
-
const
|
|
2874
|
+
const doValidateOptionsByPath = pathDetails[1];
|
|
2866
2875
|
if (typeof pathsToValidate === 'string') {
|
|
2867
2876
|
pathsToValidate = pathsToValidate.split(' ');
|
|
2868
2877
|
}
|
|
@@ -2930,7 +2939,7 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
|
|
|
2930
2939
|
_this;
|
|
2931
2940
|
|
|
2932
2941
|
const doValidateOptions = {
|
|
2933
|
-
|
|
2942
|
+
...doValidateOptionsByPath[path],
|
|
2934
2943
|
path: path,
|
|
2935
2944
|
validateModifiedOnly: shouldValidateModifiedOnly
|
|
2936
2945
|
};
|
|
@@ -2938,8 +2947,8 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
|
|
|
2938
2947
|
schemaType.doValidate(val, function(err) {
|
|
2939
2948
|
if (err) {
|
|
2940
2949
|
const isSubdoc = schemaType.$isSingleNested ||
|
|
2941
|
-
|
|
2942
|
-
|
|
2950
|
+
schemaType.$isArraySubdocument ||
|
|
2951
|
+
schemaType.$isMongooseDocumentArray;
|
|
2943
2952
|
if (isSubdoc && err instanceof ValidationError) {
|
|
2944
2953
|
return --total || complete();
|
|
2945
2954
|
}
|
|
@@ -20,7 +20,6 @@ const setDefaultsOnInsert = require('../setDefaultsOnInsert');
|
|
|
20
20
|
|
|
21
21
|
module.exports = function castBulkWrite(originalModel, op, options) {
|
|
22
22
|
const now = originalModel.base.now();
|
|
23
|
-
|
|
24
23
|
if (op['insertOne']) {
|
|
25
24
|
return (callback) => {
|
|
26
25
|
const model = decideModelByObject(originalModel, op['insertOne']['document']);
|
|
@@ -66,7 +65,9 @@ module.exports = function castBulkWrite(originalModel, op, options) {
|
|
|
66
65
|
applyTimestampsToUpdate(now, createdAt, updatedAt, op['updateOne']['update'], {});
|
|
67
66
|
}
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
if (op['updateOne'].timestamps !== false) {
|
|
69
|
+
applyTimestampsToChildren(now, op['updateOne']['update'], model.schema);
|
|
70
|
+
}
|
|
70
71
|
|
|
71
72
|
if (op['updateOne'].setDefaultsOnInsert !== false) {
|
|
72
73
|
setDefaultsOnInsert(op['updateOne']['filter'], model.schema, op['updateOne']['update'], {
|
|
@@ -117,8 +118,9 @@ module.exports = function castBulkWrite(originalModel, op, options) {
|
|
|
117
118
|
const updatedAt = model.schema.$timestamps.updatedAt;
|
|
118
119
|
applyTimestampsToUpdate(now, createdAt, updatedAt, op['updateMany']['update'], {});
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
if (op['updateMany'].timestamps !== false) {
|
|
122
|
+
applyTimestampsToChildren(now, op['updateMany']['update'], model.schema);
|
|
123
|
+
}
|
|
122
124
|
|
|
123
125
|
_addDiscriminatorToObject(schema, op['updateMany']['filter']);
|
|
124
126
|
|
package/lib/model.js
CHANGED
|
@@ -77,7 +77,8 @@ const modelSymbol = require('./helpers/symbols').modelSymbol;
|
|
|
77
77
|
const subclassedSymbol = Symbol('mongoose#Model#subclassed');
|
|
78
78
|
|
|
79
79
|
const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
|
|
80
|
-
bson: true
|
|
80
|
+
bson: true,
|
|
81
|
+
flattenObjectIds: false
|
|
81
82
|
});
|
|
82
83
|
|
|
83
84
|
/**
|
|
@@ -3471,18 +3472,22 @@ Model.bulkWrite = async function bulkWrite(ops, options) {
|
|
|
3471
3472
|
let validOps = [];
|
|
3472
3473
|
let validationErrors = [];
|
|
3473
3474
|
const results = [];
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3475
|
+
if (remaining === 0) {
|
|
3476
|
+
completeUnorderedValidation.call(this);
|
|
3477
|
+
} else {
|
|
3478
|
+
for (let i = 0; i < validations.length; ++i) {
|
|
3479
|
+
validations[i]((err) => {
|
|
3480
|
+
if (err == null) {
|
|
3481
|
+
validOps.push(i);
|
|
3482
|
+
} else {
|
|
3483
|
+
validationErrors.push({ index: i, error: err });
|
|
3484
|
+
results[i] = err;
|
|
3485
|
+
}
|
|
3486
|
+
if (--remaining <= 0) {
|
|
3487
|
+
completeUnorderedValidation.call(this);
|
|
3488
|
+
}
|
|
3489
|
+
});
|
|
3490
|
+
}
|
|
3486
3491
|
}
|
|
3487
3492
|
|
|
3488
3493
|
validationErrors = validationErrors.
|
package/lib/schema.js
CHANGED
|
@@ -413,7 +413,25 @@ Schema.prototype._clone = function _clone(Constructor) {
|
|
|
413
413
|
s.paths = clone(this.paths);
|
|
414
414
|
s.nested = clone(this.nested);
|
|
415
415
|
s.subpaths = clone(this.subpaths);
|
|
416
|
-
|
|
416
|
+
for (const schemaType of Object.values(s.paths)) {
|
|
417
|
+
if (schemaType.$isSingleNested) {
|
|
418
|
+
const path = schemaType.path;
|
|
419
|
+
for (const key of Object.keys(schemaType.schema.paths)) {
|
|
420
|
+
s.singleNestedPaths[path + '.' + key] = schemaType.schema.paths[key];
|
|
421
|
+
}
|
|
422
|
+
for (const key of Object.keys(schemaType.schema.singleNestedPaths)) {
|
|
423
|
+
s.singleNestedPaths[path + '.' + key] =
|
|
424
|
+
schemaType.schema.singleNestedPaths[key];
|
|
425
|
+
}
|
|
426
|
+
for (const key of Object.keys(schemaType.schema.subpaths)) {
|
|
427
|
+
s.singleNestedPaths[path + '.' + key] =
|
|
428
|
+
schemaType.schema.subpaths[key];
|
|
429
|
+
}
|
|
430
|
+
for (const key of Object.keys(schemaType.schema.nested)) {
|
|
431
|
+
s.singleNestedPaths[path + '.' + key] = 'nested';
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
417
435
|
s.childSchemas = gatherChildSchemas(s);
|
|
418
436
|
|
|
419
437
|
s.virtuals = clone(this.virtuals);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "7.4.
|
|
4
|
+
"version": "7.4.2",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"sift": "16.0.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "7.22.
|
|
32
|
-
"@babel/preset-env": "7.22.
|
|
31
|
+
"@babel/core": "7.22.9",
|
|
32
|
+
"@babel/preset-env": "7.22.9",
|
|
33
33
|
"@typescript-eslint/eslint-plugin": "5.61.0",
|
|
34
|
-
"@typescript-eslint/parser": "5.
|
|
34
|
+
"@typescript-eslint/parser": "5.62.0",
|
|
35
35
|
"acquit": "1.3.0",
|
|
36
36
|
"acquit-ignore": "0.2.1",
|
|
37
37
|
"acquit-require": "0.1.1",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"crypto-browserify": "3.12.0",
|
|
47
47
|
"dotenv": "16.3.1",
|
|
48
48
|
"dox": "1.0.0",
|
|
49
|
-
"eslint": "8.
|
|
49
|
+
"eslint": "8.46.0",
|
|
50
50
|
"eslint-plugin-markdown": "^3.0.0",
|
|
51
51
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
52
52
|
"express": "^4.18.1",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"tsd": "0.28.1",
|
|
70
70
|
"typescript": "5.1.6",
|
|
71
71
|
"uuid": "9.0.0",
|
|
72
|
-
"webpack": "5.88.
|
|
72
|
+
"webpack": "5.88.2"
|
|
73
73
|
},
|
|
74
74
|
"directories": {
|
|
75
75
|
"lib": "./lib/mongoose"
|