mongoose 4.10.7 → 4.10.8
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/History.md +10 -0
- package/lib/document.js +12 -4
- package/lib/error/validation.js +9 -7
- package/lib/internal.js +1 -0
- package/lib/model.js +14 -5
- package/lib/query.js +4 -1
- package/lib/schema/decimal128.js +5 -1
- package/lib/schema/objectid.js +7 -2
- package/lib/services/query/castUpdate.js +0 -1
- package/lib/services/updateValidators.js +1 -1
- package/lib/types/array.js +1 -1
- package/lib/types/embedded.js +6 -1
- package/lib/utils.js +8 -2
- package/package.json +1 -1
package/History.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
4.10.8 / 2017-06-21
|
|
2
|
+
===================
|
|
3
|
+
* docs: fix small formatting typo on schematypes #5374 [gianpaj](https://github.com/gianpaj)
|
|
4
|
+
* fix(model): allow null as an _id #5370
|
|
5
|
+
* fix(populate): don't throw async uncaught exception if model not found in populate #5364
|
|
6
|
+
* fix: correctly cast decimals in update #5361
|
|
7
|
+
* fix(error): don't use custom getter for ValidationError message #5359
|
|
8
|
+
* fix(query): handle runSettersOnQuery in built-in _id setter #5351
|
|
9
|
+
* fix(document): ensure consistent context for nested doc custom validators #5347
|
|
10
|
+
|
|
1
11
|
4.10.7 / 2017-06-18
|
|
2
12
|
===================
|
|
3
13
|
* docs(validation): show overriding custom validator error with 2nd cb arg #5358
|
package/lib/document.js
CHANGED
|
@@ -845,7 +845,7 @@ Document.prototype.$__set = function(pathToMark, path, constructing, parts, sche
|
|
|
845
845
|
var _this = this;
|
|
846
846
|
|
|
847
847
|
if (shouldModify) {
|
|
848
|
-
this.markModified(pathToMark
|
|
848
|
+
this.markModified(pathToMark);
|
|
849
849
|
|
|
850
850
|
// handle directly setting arrays (gh-1126)
|
|
851
851
|
MongooseArray || (MongooseArray = require('./types/array'));
|
|
@@ -996,11 +996,15 @@ Document.prototype.$__path = function(path) {
|
|
|
996
996
|
* doc.save() // changes to mixed.type are now persisted
|
|
997
997
|
*
|
|
998
998
|
* @param {String} path the path to mark modified
|
|
999
|
+
* @param {Document} [scope] the scope to run validators with
|
|
999
1000
|
* @api public
|
|
1000
1001
|
*/
|
|
1001
1002
|
|
|
1002
|
-
Document.prototype.markModified = function(path) {
|
|
1003
|
+
Document.prototype.markModified = function(path, scope) {
|
|
1003
1004
|
this.$__.activePaths.modify(path);
|
|
1005
|
+
if (scope != null && !this.ownerDocument) {
|
|
1006
|
+
this.$__.pathsToScopes[path] = scope;
|
|
1007
|
+
}
|
|
1004
1008
|
};
|
|
1005
1009
|
|
|
1006
1010
|
/**
|
|
@@ -1018,6 +1022,7 @@ Document.prototype.markModified = function(path) {
|
|
|
1018
1022
|
|
|
1019
1023
|
Document.prototype.unmarkModified = function(path) {
|
|
1020
1024
|
this.$__.activePaths.init(path);
|
|
1025
|
+
delete this.$__.pathsToScopes[path];
|
|
1021
1026
|
};
|
|
1022
1027
|
|
|
1023
1028
|
/**
|
|
@@ -1459,12 +1464,15 @@ Document.prototype.$__validate = function(callback) {
|
|
|
1459
1464
|
}
|
|
1460
1465
|
|
|
1461
1466
|
var val = _this.getValue(path);
|
|
1467
|
+
var scope = path in _this.$__.pathsToScopes ?
|
|
1468
|
+
_this.$__.pathsToScopes[path] :
|
|
1469
|
+
_this;
|
|
1462
1470
|
p.doValidate(val, function(err) {
|
|
1463
1471
|
if (err) {
|
|
1464
1472
|
_this.invalidate(path, err, undefined, true);
|
|
1465
1473
|
}
|
|
1466
1474
|
--total || complete();
|
|
1467
|
-
},
|
|
1475
|
+
}, scope);
|
|
1468
1476
|
});
|
|
1469
1477
|
};
|
|
1470
1478
|
|
|
@@ -1609,7 +1617,7 @@ Document.prototype.invalidate = function(path, err, val, kind) {
|
|
|
1609
1617
|
return this.$__.validationError;
|
|
1610
1618
|
}
|
|
1611
1619
|
|
|
1612
|
-
this.$__.validationError.
|
|
1620
|
+
this.$__.validationError.addError(path, err);
|
|
1613
1621
|
return this.$__.validationError;
|
|
1614
1622
|
};
|
|
1615
1623
|
|
package/lib/error/validation.js
CHANGED
|
@@ -41,13 +41,6 @@ function ValidationError(instance) {
|
|
|
41
41
|
ValidationError.prototype = Object.create(MongooseError.prototype);
|
|
42
42
|
ValidationError.prototype.constructor = MongooseError;
|
|
43
43
|
|
|
44
|
-
Object.defineProperty(ValidationError.prototype, 'message', {
|
|
45
|
-
get: function() {
|
|
46
|
-
return this._message + ': ' + _generateMessage(this);
|
|
47
|
-
},
|
|
48
|
-
enumerable: true
|
|
49
|
-
});
|
|
50
|
-
|
|
51
44
|
/**
|
|
52
45
|
* Console.log helper
|
|
53
46
|
*/
|
|
@@ -72,6 +65,15 @@ ValidationError.prototype.toJSON = function() {
|
|
|
72
65
|
return utils.assign({}, this, { message: this.message });
|
|
73
66
|
};
|
|
74
67
|
|
|
68
|
+
/*!
|
|
69
|
+
* add message
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
ValidationError.prototype.addError = function(path, error) {
|
|
73
|
+
this.errors[path] = error;
|
|
74
|
+
this.message = this._message + ': ' + _generateMessage(this);
|
|
75
|
+
};
|
|
76
|
+
|
|
75
77
|
/*!
|
|
76
78
|
* ignore
|
|
77
79
|
*/
|
package/lib/internal.js
CHANGED
package/lib/model.js
CHANGED
|
@@ -128,7 +128,7 @@ Model.prototype.$__handleSave = function(options, callback) {
|
|
|
128
128
|
|
|
129
129
|
var obj = this.toObject(toObjectOptions);
|
|
130
130
|
|
|
131
|
-
if ((obj || {})._id
|
|
131
|
+
if ((obj || {})._id === void 0) {
|
|
132
132
|
// documents must have an _id else mongoose won't know
|
|
133
133
|
// what to update later if more changes are made. the user
|
|
134
134
|
// wouldn't know what _id was generated by mongodb either
|
|
@@ -3338,7 +3338,12 @@ function getModelsMapForPopulate(model, docs, options) {
|
|
|
3338
3338
|
modelForFindSchema = utils.getValue(discriminatorKey, doc);
|
|
3339
3339
|
|
|
3340
3340
|
if (modelForFindSchema) {
|
|
3341
|
-
|
|
3341
|
+
try {
|
|
3342
|
+
modelForCurrentDoc = model.db.model(modelForFindSchema);
|
|
3343
|
+
} catch (error) {
|
|
3344
|
+
return error;
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3342
3347
|
schemaForCurrentDoc = modelForCurrentDoc._getSchema(options.path);
|
|
3343
3348
|
|
|
3344
3349
|
if (schemaForCurrentDoc && schemaForCurrentDoc.caster) {
|
|
@@ -3403,9 +3408,13 @@ function getModelsMapForPopulate(model, docs, options) {
|
|
|
3403
3408
|
modelName = modelNames[k];
|
|
3404
3409
|
var _doc = Array.isArray(doc) && isRefPathArray ? doc[k] : doc;
|
|
3405
3410
|
var _ret = Array.isArray(ret) && isRefPathArray ? ret[k] : ret;
|
|
3406
|
-
|
|
3407
|
-
originalModel
|
|
3408
|
-
|
|
3411
|
+
try {
|
|
3412
|
+
Model = originalModel && originalModel.modelName ?
|
|
3413
|
+
originalModel :
|
|
3414
|
+
model.db.model(modelName);
|
|
3415
|
+
} catch (error) {
|
|
3416
|
+
return error;
|
|
3417
|
+
}
|
|
3409
3418
|
|
|
3410
3419
|
if (!available[modelName]) {
|
|
3411
3420
|
currentOptions = {
|
package/lib/query.js
CHANGED
|
@@ -186,7 +186,10 @@ Query.prototype.toConstructor = function toConstructor() {
|
|
|
186
186
|
p.op = this.op;
|
|
187
187
|
p._conditions = utils.clone(this._conditions, { retainKeyOrder: true });
|
|
188
188
|
p._fields = utils.clone(this._fields);
|
|
189
|
-
p._update = utils.clone(this._update
|
|
189
|
+
p._update = utils.clone(this._update, {
|
|
190
|
+
flattenDecimals: false,
|
|
191
|
+
retainKeyOrder: true
|
|
192
|
+
});
|
|
190
193
|
p._path = this._path;
|
|
191
194
|
p._distinct = this._distinct;
|
|
192
195
|
p._collection = this._collection;
|
package/lib/schema/decimal128.js
CHANGED
|
@@ -104,10 +104,14 @@ Decimal128.prototype.cast = function(value, doc, init) {
|
|
|
104
104
|
return ret;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
if (value
|
|
107
|
+
if (value == null) {
|
|
108
108
|
return value;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
if (typeof value === 'object' && typeof value.$numberDecimal === 'string') {
|
|
112
|
+
return Decimal128Type.fromString(value.$numberDecimal);
|
|
113
|
+
}
|
|
114
|
+
|
|
111
115
|
if (value instanceof Decimal128Type) {
|
|
112
116
|
return value;
|
|
113
117
|
}
|
package/lib/schema/objectid.js
CHANGED
|
@@ -198,10 +198,15 @@ function defaultId() {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
function resetId(v) {
|
|
201
|
-
|
|
201
|
+
Document || (Document = require('./../document'));
|
|
202
|
+
|
|
203
|
+
if (v === void 0) {
|
|
202
204
|
return new oid();
|
|
203
205
|
}
|
|
204
|
-
|
|
206
|
+
|
|
207
|
+
if (this instanceof Document) {
|
|
208
|
+
delete this.$__._id;
|
|
209
|
+
}
|
|
205
210
|
return v;
|
|
206
211
|
}
|
|
207
212
|
|
|
@@ -146,7 +146,7 @@ module.exports = function(query, schema, castedDoc, options) {
|
|
|
146
146
|
if (validationErrors.length) {
|
|
147
147
|
var err = new ValidationError(null);
|
|
148
148
|
for (var i = 0; i < validationErrors.length; ++i) {
|
|
149
|
-
err.
|
|
149
|
+
err.addError(validationErrors[i].path, validationErrors[i]);
|
|
150
150
|
}
|
|
151
151
|
return callback(err);
|
|
152
152
|
}
|
package/lib/types/array.js
CHANGED
package/lib/types/embedded.js
CHANGED
|
@@ -196,7 +196,12 @@ EmbeddedDocument.prototype.update = function() {
|
|
|
196
196
|
*/
|
|
197
197
|
|
|
198
198
|
EmbeddedDocument.prototype.inspect = function() {
|
|
199
|
-
return this.toObject({
|
|
199
|
+
return this.toObject({
|
|
200
|
+
transform: false,
|
|
201
|
+
retainKeyOrder: true,
|
|
202
|
+
virtuals: false,
|
|
203
|
+
flattenDecimals: false
|
|
204
|
+
});
|
|
200
205
|
};
|
|
201
206
|
|
|
202
207
|
/**
|
package/lib/utils.js
CHANGED
|
@@ -861,7 +861,10 @@ exports.mergeClone = function(to, fromObj) {
|
|
|
861
861
|
if (typeof to[key] === 'undefined') {
|
|
862
862
|
// make sure to retain key order here because of a bug handling the $each
|
|
863
863
|
// operator in mongodb 2.4.4
|
|
864
|
-
to[key] = exports.clone(fromObj[key], {
|
|
864
|
+
to[key] = exports.clone(fromObj[key], {
|
|
865
|
+
retainKeyOrder: 1,
|
|
866
|
+
flattenDecimals: false
|
|
867
|
+
});
|
|
865
868
|
} else {
|
|
866
869
|
if (exports.isObject(fromObj[key])) {
|
|
867
870
|
var obj = fromObj[key];
|
|
@@ -875,7 +878,10 @@ exports.mergeClone = function(to, fromObj) {
|
|
|
875
878
|
} else {
|
|
876
879
|
// make sure to retain key order here because of a bug handling the
|
|
877
880
|
// $each operator in mongodb 2.4.4
|
|
878
|
-
to[key] = exports.clone(fromObj[key], {
|
|
881
|
+
to[key] = exports.clone(fromObj[key], {
|
|
882
|
+
retainKeyOrder: 1,
|
|
883
|
+
flattenDecimals: false
|
|
884
|
+
});
|
|
879
885
|
}
|
|
880
886
|
}
|
|
881
887
|
}
|