mongoose 5.9.27 → 5.9.28
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 +9 -0
- package/dist/browser.umd.js +7 -4
- package/lib/connection.js +1 -0
- package/lib/error/validator.js +8 -0
- package/lib/helpers/document/compile.js +11 -2
- package/lib/schema/documentarray.js +5 -0
- package/lib/schema/string.js +4 -0
- package/package.json +1 -1
package/History.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
5.9.28 / 2020-08-07
|
|
2
|
+
===================
|
|
3
|
+
* fix(connection): consistently stop buffering when "reconnected" is emitted #9295
|
|
4
|
+
* fix(error): ensure `name` and `message` show up on individual ValidatorErrors when calling JSON.stringify() on a ValidationError #9296
|
|
5
|
+
* fix(document): keeps manually populated paths when setting a nested path to itself #9293
|
|
6
|
+
* fix(document): allow saving after setting document array to itself #9266
|
|
7
|
+
* fix(schema): handle `match` schema validator with `/g` flag #9287
|
|
8
|
+
* docs(guide): refactor transactions examples to async/await #9204
|
|
9
|
+
|
|
1
10
|
5.9.27 / 2020-07-31
|
|
2
11
|
===================
|
|
3
12
|
* fix: upgrade mongodb driver -> 3.5.10 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
|
package/dist/browser.umd.js
CHANGED
|
@@ -718,7 +718,7 @@ t.exports=A},function(t,e,r){"use strict";
|
|
|
718
718
|
function c(t,e,o,i){n=n||r(6);for(var a,u,c=Object.keys(t),f=c.length,p=0;p<f;++p){a=t[u=c[p]],l(u,s.isPOJO(a)&&Object.keys(a).length&&(!a[i.typeKey]||"type"===i.typeKey&&a.type.type)?a:null,e,o,c,i)}}
|
|
719
719
|
/*!
|
|
720
720
|
* Defines the accessor named prop on the incoming prototype.
|
|
721
|
-
*/function l(t,e,l,f,p,h){n=n||r(6);var y=(f?f+".":"")+t;f=f||"",e?Object.defineProperty(l,t,{enumerable:!0,configurable:!0,get:function(){var t,r,a=this;if(this.$__.getters||(this.$__.getters={}),!this.$__.getters[y]){var p=Object.create(n.prototype,(t=this,r={},Object.getOwnPropertyNames(t).forEach((function(e){r[e]=Object.getOwnPropertyDescriptor(t,e),r[e].get?delete r[e]:r[e].enumerable=-1===["isNew","$__","errors","_doc","$locals","$op","__parentArray","__index","$isDocumentArrayElement"].indexOf(e)})),r));f||(p.$__[u]=this),p.$__.nestedPath=y,Object.defineProperty(p,"schema",{enumerable:!1,configurable:!0,writable:!1,value:l.schema}),Object.defineProperty(p,o,{enumerable:!1,configurable:!0,writable:!1,value:l.schema}),Object.defineProperty(p,"toObject",{enumerable:!1,configurable:!0,writable:!1,value:function(){return s.clone(a.get(y,null,{virtuals:i(this,"schema.options.toObject.virtuals",null)}))}}),Object.defineProperty(p,"toJSON",{enumerable:!1,configurable:!0,writable:!1,value:function(){return a.get(y,null,{virtuals:i(a,"schema.options.toJSON.virtuals",null)})}}),Object.defineProperty(p,"$__isNested",{enumerable:!1,configurable:!0,writable:!1,value:!0});var d=Object.freeze({minimize:!0,virtuals:!1,getters:!1,transform:!1});Object.defineProperty(p,"$isEmpty",{enumerable:!1,configurable:!0,writable:!1,value:function(){return 0===Object.keys(this.get(y,null,d)||{}).length}}),c(e,p,y,h),this.$__.getters[y]=p}return this.$__.getters[y]},set:function(t){t
|
|
721
|
+
*/function l(t,e,l,f,p,h){n=n||r(6);var y=(f?f+".":"")+t;f=f||"",e?Object.defineProperty(l,t,{enumerable:!0,configurable:!0,get:function(){var t,r,a=this;if(this.$__.getters||(this.$__.getters={}),!this.$__.getters[y]){var p=Object.create(n.prototype,(t=this,r={},Object.getOwnPropertyNames(t).forEach((function(e){r[e]=Object.getOwnPropertyDescriptor(t,e),r[e].get?delete r[e]:r[e].enumerable=-1===["isNew","$__","errors","_doc","$locals","$op","__parentArray","__index","$isDocumentArrayElement"].indexOf(e)})),r));f||(p.$__[u]=this),p.$__.nestedPath=y,Object.defineProperty(p,"schema",{enumerable:!1,configurable:!0,writable:!1,value:l.schema}),Object.defineProperty(p,o,{enumerable:!1,configurable:!0,writable:!1,value:l.schema}),Object.defineProperty(p,"toObject",{enumerable:!1,configurable:!0,writable:!1,value:function(){return s.clone(a.get(y,null,{virtuals:i(this,"schema.options.toObject.virtuals",null)}))}}),Object.defineProperty(p,"toJSON",{enumerable:!1,configurable:!0,writable:!1,value:function(){return a.get(y,null,{virtuals:i(a,"schema.options.toJSON.virtuals",null)})}}),Object.defineProperty(p,"$__isNested",{enumerable:!1,configurable:!0,writable:!1,value:!0});var d=Object.freeze({minimize:!0,virtuals:!1,getters:!1,transform:!1});Object.defineProperty(p,"$isEmpty",{enumerable:!1,configurable:!0,writable:!1,value:function(){return 0===Object.keys(this.get(y,null,d)||{}).length}}),Object.defineProperty(p,"$__parent",{enumerable:!1,configurable:!0,writable:!1,value:this}),c(e,p,y,h),this.$__.getters[y]=p}return this.$__.getters[y]},set:function(t){null!=t&&t.$__isNested&&(t=t.$__parent.get(t.$__.nestedPath)),(this.$__[u]||this).$set(y,t)}}):Object.defineProperty(l,t,{enumerable:!0,configurable:!0,get:function(){return this[a].call(this.$__[u]||this,y)},set:function(t){this.$set.call(this.$__[u]||this,y,t)}})}
|
|
722
722
|
/*!
|
|
723
723
|
* exports
|
|
724
724
|
*/
|
|
@@ -757,7 +757,10 @@ e.cloneObject=function(t,e){var r,n,o,i=e&&e.minimize,s={};for(o in t)n=a(t[o],e
|
|
|
757
757
|
/*!
|
|
758
758
|
* toString helper
|
|
759
759
|
* TODO remove? This defaults to `${this.name}: ${this.message}`
|
|
760
|
-
*/return e=u,(r=[{key:"toString",value:function(){return this.message}
|
|
760
|
+
*/return e=u,(r=[{key:"toString",value:function(){return this.message}
|
|
761
|
+
/*!
|
|
762
|
+
* Ensure `name` and `message` show up in toJSON output re: gh-9296
|
|
763
|
+
*/},{key:"toJSON",value:function(){return Object.assign({name:this.name,message:this.message},this)}}])&&o(e.prototype,r),n&&o(e,n),u}(c);
|
|
761
764
|
/*!
|
|
762
765
|
* Formats error messages
|
|
763
766
|
*/
|
|
@@ -1246,7 +1249,7 @@ h._cast=c,h.cast=function(t){return 0===arguments.length||(!1===t&&(t=function(t
|
|
|
1246
1249
|
/*!
|
|
1247
1250
|
* ignore
|
|
1248
1251
|
*/
|
|
1249
|
-
h._checkRequired=function(t){return(t instanceof String||"string"==typeof t)&&t.length},h.checkRequired=s.checkRequired,h.prototype.enum=function(){if(this.enumValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.enumValidator}),this),this.enumValidator=!1),void 0===arguments[0]||!1===arguments[0])return this;var t,e;l.isObject(arguments[0])?(t=arguments[0].values,e=arguments[0].message):(t=arguments,e=a.messages.String.enum);var r,o=n(t);try{for(o.s();!(r=o.n()).done;){var i=r.value;void 0!==i&&this.enumValues.push(this.cast(i))}}catch(t){o.e(t)}finally{o.f()}var s=this.enumValues;return this.enumValidator=function(t){return void 0===t||~s.indexOf(t)},this.validators.push({validator:this.enumValidator,message:e,type:"enum",enumValues:s}),this},h.prototype.lowercase=function(t){return arguments.length>0&&!t?this:this.set((function(t,e){return"string"!=typeof t&&(t=e.cast(t)),t?t.toLowerCase():t}))},h.prototype.uppercase=function(t){return arguments.length>0&&!t?this:this.set((function(t,e){return"string"!=typeof t&&(t=e.cast(t)),t?t.toUpperCase():t}))},h.prototype.trim=function(t){return arguments.length>0&&!t?this:this.set((function(t,e){return"string"!=typeof t&&(t=e.cast(t)),t?t.trim():t}))},h.prototype.minlength=function(t,e){if(this.minlengthValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.minlengthValidator}),this)),null!=t){var r=e||a.messages.String.minlength;r=r.replace(/{MINLENGTH}/,t),this.validators.push({validator:this.minlengthValidator=function(e){return null===e||e.length>=t},message:r,type:"minlength",minlength:t})}return this},h.prototype.maxlength=function(t,e){if(this.maxlengthValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.maxlengthValidator}),this)),null!=t){var r=e||a.messages.String.maxlength;r=r.replace(/{MAXLENGTH}/,t),this.validators.push({validator:this.maxlengthValidator=function(e){return null===e||e.length<=t},message:r,type:"maxlength",maxlength:t})}return this},h.prototype.match=function(t,e){var r=e||a.messages.String.match;return this.validators.push({validator:function(e){return!!t&&(null==e||""===e||t.test(e))},message:r,type:"regexp",regexp:t}),this},h.prototype.checkRequired=function(t,e){return s._isRef(this,t,e,!0)?!!t:("function"==typeof this.constructor.checkRequired?this.constructor.checkRequired():h.checkRequired())(t)},h.prototype.cast=function(t,n,o){if(s._isRef(this,t,n,o)){if(null==t)return t;if(i||(i=r(6)),t instanceof i)return t.$__.wasPopulated=!0,t;if("string"==typeof t)return t;if(e.isBuffer(t)||!l.isObject(t))throw new p("string",t,this.path,null,this);var a=n.$__fullPath(this.path),u=new((n.ownerDocument?n.ownerDocument():n).populated(a,!0).options[f])(t);return u.$__.wasPopulated=!0,u}var c="function"==typeof this.constructor.cast?this.constructor.cast():h.cast();try{return c(t)}catch(e){throw new p("string",t,this.path,null,this)}};var d=l.options(s.prototype.$conditionalHandlers,{$all:function(t){var e=this;return Array.isArray(t)?t.map((function(t){return e.castForQuery(t)})):[this.castForQuery(t)]},$gt:y,$gte:y,$lt:y,$lte:y,$options:String,$regex:y,$not:y});Object.defineProperty(h.prototype,"$conditionalHandlers",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(d)}),h.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t+" with String.");return r.call(this,e)}return e=t,"[object RegExp]"===Object.prototype.toString.call(e)?e:this._castForQuery(e)},
|
|
1252
|
+
h._checkRequired=function(t){return(t instanceof String||"string"==typeof t)&&t.length},h.checkRequired=s.checkRequired,h.prototype.enum=function(){if(this.enumValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.enumValidator}),this),this.enumValidator=!1),void 0===arguments[0]||!1===arguments[0])return this;var t,e;l.isObject(arguments[0])?(t=arguments[0].values,e=arguments[0].message):(t=arguments,e=a.messages.String.enum);var r,o=n(t);try{for(o.s();!(r=o.n()).done;){var i=r.value;void 0!==i&&this.enumValues.push(this.cast(i))}}catch(t){o.e(t)}finally{o.f()}var s=this.enumValues;return this.enumValidator=function(t){return void 0===t||~s.indexOf(t)},this.validators.push({validator:this.enumValidator,message:e,type:"enum",enumValues:s}),this},h.prototype.lowercase=function(t){return arguments.length>0&&!t?this:this.set((function(t,e){return"string"!=typeof t&&(t=e.cast(t)),t?t.toLowerCase():t}))},h.prototype.uppercase=function(t){return arguments.length>0&&!t?this:this.set((function(t,e){return"string"!=typeof t&&(t=e.cast(t)),t?t.toUpperCase():t}))},h.prototype.trim=function(t){return arguments.length>0&&!t?this:this.set((function(t,e){return"string"!=typeof t&&(t=e.cast(t)),t?t.trim():t}))},h.prototype.minlength=function(t,e){if(this.minlengthValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.minlengthValidator}),this)),null!=t){var r=e||a.messages.String.minlength;r=r.replace(/{MINLENGTH}/,t),this.validators.push({validator:this.minlengthValidator=function(e){return null===e||e.length>=t},message:r,type:"minlength",minlength:t})}return this},h.prototype.maxlength=function(t,e){if(this.maxlengthValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.maxlengthValidator}),this)),null!=t){var r=e||a.messages.String.maxlength;r=r.replace(/{MAXLENGTH}/,t),this.validators.push({validator:this.maxlengthValidator=function(e){return null===e||e.length<=t},message:r,type:"maxlength",maxlength:t})}return this},h.prototype.match=function(t,e){var r=e||a.messages.String.match;return this.validators.push({validator:function(e){return!!t&&(t.lastIndex=0,null==e||""===e||t.test(e))},message:r,type:"regexp",regexp:t}),this},h.prototype.checkRequired=function(t,e){return s._isRef(this,t,e,!0)?!!t:("function"==typeof this.constructor.checkRequired?this.constructor.checkRequired():h.checkRequired())(t)},h.prototype.cast=function(t,n,o){if(s._isRef(this,t,n,o)){if(null==t)return t;if(i||(i=r(6)),t instanceof i)return t.$__.wasPopulated=!0,t;if("string"==typeof t)return t;if(e.isBuffer(t)||!l.isObject(t))throw new p("string",t,this.path,null,this);var a=n.$__fullPath(this.path),u=new((n.ownerDocument?n.ownerDocument():n).populated(a,!0).options[f])(t);return u.$__.wasPopulated=!0,u}var c="function"==typeof this.constructor.cast?this.constructor.cast():h.cast();try{return c(t)}catch(e){throw new p("string",t,this.path,null,this)}};var d=l.options(s.prototype.$conditionalHandlers,{$all:function(t){var e=this;return Array.isArray(t)?t.map((function(t){return e.castForQuery(t)})):[this.castForQuery(t)]},$gt:y,$gte:y,$lt:y,$lte:y,$options:String,$regex:y,$not:y});Object.defineProperty(h.prototype,"$conditionalHandlers",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(d)}),h.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t+" with String.");return r.call(this,e)}return e=t,"[object RegExp]"===Object.prototype.toString.call(e)?e:this._castForQuery(e)},
|
|
1250
1253
|
/*!
|
|
1251
1254
|
* Module exports.
|
|
1252
1255
|
*/
|
|
@@ -1314,7 +1317,7 @@ g.prototype=Object.create(i.prototype),g.prototype.constructor=g,g.prototype.Opt
|
|
|
1314
1317
|
/*!
|
|
1315
1318
|
* ignore
|
|
1316
1319
|
*/
|
|
1317
|
-
g.prototype.getDefault=function(t){var e="function"==typeof this.defaultValue?this.defaultValue.call(t):this.defaultValue;if(null==e)return e;n||(n=r(17)),Array.isArray(e)||(e=[e]),e=new n(e,this.path,t);for(var o=0;o<e.length;++o){var i=new(m(this.casterConstructor,e[o]))({},e,void 0,void 0,o);i.init(e[o]),i.isNew=!0,Object.assign(i.$__.activePaths.default,i.$__.activePaths.init),i.$__.activePaths.init={},e[o]=i}return e},g.prototype.cast=function(t,e,i,a,u){
|
|
1320
|
+
g.prototype.getDefault=function(t){var e="function"==typeof this.defaultValue?this.defaultValue.call(t):this.defaultValue;if(null==e)return e;n||(n=r(17)),Array.isArray(e)||(e=[e]),e=new n(e,this.path,t);for(var o=0;o<e.length;++o){var i=new(m(this.casterConstructor,e[o]))({},e,void 0,void 0,o);i.init(e[o]),i.isNew=!0,Object.assign(i.$__.activePaths.default,i.$__.activePaths.init),i.$__.activePaths.init={},e[o]=i}return e},g.prototype.cast=function(t,e,i,a,u){if(n||(n=r(17)),null!=t&&null!=t[_]&&t===a)return t;var c,l,f={transform:!1,virtuals:!1};if(u=u||{},!Array.isArray(t)){if(!i&&!g.options.castNonArrays)throw new s("DocumentArray",y.inspect(t),this.path,null,this);return e&&i&&e.markModified(this.path),this.cast([t],e,i,a,u)}t&&t.isMongooseDocumentArray||u.skipDocumentArrayCast?t&&t.isMongooseDocumentArray&&(t=new n(t,this.path,e)):t=new n(t,this.path,e),null!=u.arrayPath&&(t[_]=u.arrayPath);for(var p=t.length,h=0;h<p;++h)if(t[h]){var b=m(this.casterConstructor,t[h]);if(!t[h].$__||t[h]instanceof b&&t[h][v]===e||(t[h]=t[h].toObject({transform:!1,virtuals:t[h].schema===b.schema})),t[h]instanceof o)null==t[h].__index&&t[h].$setIndex(h);else if(null!=t[h])if(i)e?c||(c=w(this,e.$__.selected,i)):c=!0,l=new b(null,t,!0,c,h),t[h]=l.init(t[h]);else if(a&&"function"==typeof a.id&&(l=a.id(t[h]._id)),a&&l&&d.deepEqual(l.toObject(f),t[h]))l.set(t[h]),t[h]=l;else try{l=new b(t[h],t,void 0,void 0,h),t[h]=l}catch(e){var O=y.inspect(t[h]);throw new s("embedded",O,t[_],e,this)}}return t},
|
|
1318
1321
|
/*!
|
|
1319
1322
|
* ignore
|
|
1320
1323
|
*/
|
package/lib/connection.js
CHANGED
package/lib/error/validator.js
CHANGED
|
@@ -38,6 +38,14 @@ class ValidatorError extends MongooseError {
|
|
|
38
38
|
toString() {
|
|
39
39
|
return this.message;
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/*!
|
|
43
|
+
* Ensure `name` and `message` show up in toJSON output re: gh-9296
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
toJSON() {
|
|
47
|
+
return Object.assign({ name: this.name, message: this.message }, this);
|
|
48
|
+
}
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
|
|
@@ -124,6 +124,13 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) {
|
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
+
Object.defineProperty(nested, '$__parent', {
|
|
128
|
+
enumerable: false,
|
|
129
|
+
configurable: true,
|
|
130
|
+
writable: false,
|
|
131
|
+
value: this
|
|
132
|
+
});
|
|
133
|
+
|
|
127
134
|
compile(subprops, nested, path, options);
|
|
128
135
|
this.$__.getters[path] = nested;
|
|
129
136
|
}
|
|
@@ -131,8 +138,10 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) {
|
|
|
131
138
|
return this.$__.getters[path];
|
|
132
139
|
},
|
|
133
140
|
set: function(v) {
|
|
134
|
-
if (v
|
|
135
|
-
|
|
141
|
+
if (v != null && v.$__isNested) {
|
|
142
|
+
// Convert top-level to POJO, but leave subdocs hydrated so `$set`
|
|
143
|
+
// can handle them. See gh-9293.
|
|
144
|
+
v = v.$__parent.get(v.$__.nestedPath);
|
|
136
145
|
}
|
|
137
146
|
const doc = this.$__[scopeSymbol] || this;
|
|
138
147
|
doc.$set(path, v);
|
|
@@ -361,6 +361,11 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
361
361
|
// lazy load
|
|
362
362
|
MongooseDocumentArray || (MongooseDocumentArray = require('../types/documentarray'));
|
|
363
363
|
|
|
364
|
+
// Skip casting if `value` is the same as the previous value, no need to cast. See gh-9266
|
|
365
|
+
if (value != null && value[arrayPathSymbol] != null && value === prev) {
|
|
366
|
+
return value;
|
|
367
|
+
}
|
|
368
|
+
|
|
364
369
|
let selected;
|
|
365
370
|
let subdoc;
|
|
366
371
|
const _opts = { transform: false, virtuals: false };
|
package/lib/schema/string.js
CHANGED
|
@@ -516,6 +516,10 @@ SchemaString.prototype.match = function match(regExp, message) {
|
|
|
516
516
|
return false;
|
|
517
517
|
}
|
|
518
518
|
|
|
519
|
+
// In case RegExp happens to have `/g` flag set, we need to reset the
|
|
520
|
+
// `lastIndex`, otherwise `match` will intermittently fail.
|
|
521
|
+
regExp.lastIndex = 0;
|
|
522
|
+
|
|
519
523
|
const ret = ((v != null && v !== '')
|
|
520
524
|
? regExp.test(v)
|
|
521
525
|
: true);
|