mongoose 8.23.0 → 8.23.1
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/helpers/setDefaultsOnInsert.js +15 -1
- package/lib/model.js +1 -1
- package/lib/schema/string.js +19 -2
- package/lib/schemaType.js +0 -6
- package/package.json +1 -1
|
@@ -25,7 +25,7 @@ module.exports = function(filter, schema, castedDoc, options) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const keys = Object.keys(castedDoc || {});
|
|
28
|
-
const updatedKeys =
|
|
28
|
+
const updatedKeys = Object.create(null);
|
|
29
29
|
const updatedValues = {};
|
|
30
30
|
const numKeys = keys.length;
|
|
31
31
|
|
|
@@ -58,6 +58,20 @@ module.exports = function(filter, schema, castedDoc, options) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
updatedKeys[path] = true;
|
|
61
|
+
if (path.indexOf('.') === -1) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
// Also mark all parent prefixes so child-path lookups are O(1).
|
|
65
|
+
// e.g. 'extraProps.location' also marks 'extraProps'
|
|
66
|
+
const pieces = schema.paths[path] ?
|
|
67
|
+
// If the SchemaType already split for us, use that to avoid the extra overhead
|
|
68
|
+
schema.paths[path].splitPath() :
|
|
69
|
+
path.split('.');
|
|
70
|
+
let cur = pieces[0];
|
|
71
|
+
for (let j = 1; j < pieces.length; ++j) {
|
|
72
|
+
updatedKeys[cur] = true;
|
|
73
|
+
cur += '.' + pieces[j];
|
|
74
|
+
}
|
|
61
75
|
}
|
|
62
76
|
|
|
63
77
|
if (options && options.overwrite && !hasDollarUpdate) {
|
package/lib/model.js
CHANGED
|
@@ -3490,7 +3490,7 @@ Model.bulkWrite = async function bulkWrite(ops, options) {
|
|
|
3490
3490
|
sort((v1, v2) => v1.index - v2.index).
|
|
3491
3491
|
map(v => v.error);
|
|
3492
3492
|
|
|
3493
|
-
const validOps = validOpIndexes.sort().map(index => ops[index]);
|
|
3493
|
+
const validOps = validOpIndexes.sort((a, b) => a - b).map(index => ops[index]);
|
|
3494
3494
|
|
|
3495
3495
|
if (validOps.length === 0) {
|
|
3496
3496
|
if (options.throwOnValidationError && validationErrors.length) {
|
package/lib/schema/string.js
CHANGED
|
@@ -474,12 +474,14 @@ SchemaString.prototype.maxlength = function(value, message) {
|
|
|
474
474
|
|
|
475
475
|
if (value !== null && value !== undefined) {
|
|
476
476
|
let msg = message || MongooseError.messages.String.maxlength;
|
|
477
|
-
|
|
477
|
+
if (typeof msg !== 'function') {
|
|
478
|
+
msg = msg.replace(/{MAXLENGTH}/, value);
|
|
479
|
+
}
|
|
478
480
|
this.validators.push({
|
|
479
481
|
validator: this.maxlengthValidator = function(v) {
|
|
480
482
|
return v === null || v.length <= value;
|
|
481
483
|
},
|
|
482
|
-
message: msg,
|
|
484
|
+
message: formatMaxLengthValidatorMessage(msg),
|
|
483
485
|
type: 'maxlength',
|
|
484
486
|
maxlength: value
|
|
485
487
|
});
|
|
@@ -731,3 +733,18 @@ SchemaString.prototype.autoEncryptionType = function autoEncryptionType() {
|
|
|
731
733
|
*/
|
|
732
734
|
|
|
733
735
|
module.exports = SchemaString;
|
|
736
|
+
|
|
737
|
+
function formatMaxLengthValidatorMessage(msg) {
|
|
738
|
+
return function(props, doc) {
|
|
739
|
+
if (typeof msg === 'function') {
|
|
740
|
+
return MongooseError.ValidatorError.prototype.formatMessage(msg, props, doc);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
if (typeof msg === 'string' && typeof props.value === 'string' && props.value.length > 30) {
|
|
744
|
+
props = Object.assign({}, props, {
|
|
745
|
+
value: props.value.slice(0, 30) + '...'
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
return MongooseError.ValidatorError.prototype.formatMessage(msg, props, doc);
|
|
749
|
+
};
|
|
750
|
+
}
|
package/lib/schemaType.js
CHANGED
|
@@ -1381,9 +1381,6 @@ SchemaType.prototype.doValidate = function(value, fn, scope, options) {
|
|
|
1381
1381
|
validatorProperties.value = value;
|
|
1382
1382
|
if (typeof value === 'string') {
|
|
1383
1383
|
validatorProperties.length = value.length;
|
|
1384
|
-
if (validatorProperties.value.length > 30) {
|
|
1385
|
-
validatorProperties.value = validatorProperties.value.slice(0, 30) + '...';
|
|
1386
|
-
}
|
|
1387
1384
|
}
|
|
1388
1385
|
|
|
1389
1386
|
if (validator instanceof RegExp) {
|
|
@@ -1508,9 +1505,6 @@ SchemaType.prototype.doValidateSync = function(value, scope, options) {
|
|
|
1508
1505
|
validatorProperties.value = value;
|
|
1509
1506
|
if (typeof value === 'string') {
|
|
1510
1507
|
validatorProperties.length = value.length;
|
|
1511
|
-
if (validatorProperties.value.length > 30) {
|
|
1512
|
-
validatorProperties.value = validatorProperties.value.slice(0, 30) + '...';
|
|
1513
|
-
}
|
|
1514
1508
|
}
|
|
1515
1509
|
let ok = false;
|
|
1516
1510
|
|