mongoose 6.1.3 → 6.1.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 +6 -6
- package/index.d.ts +5 -3
- package/lib/connection.js +2 -2
- package/lib/document.js +2 -8
- package/lib/helpers/common.js +1 -1
- package/lib/helpers/populate/modelNamesFromRefPath.js +4 -2
- package/lib/helpers/timestamps/setupTimestamps.js +1 -1
- package/lib/index.js +9 -0
- package/lib/model.js +7 -0
- package/lib/schema/SubdocumentPath.js +4 -3
- package/package.json +2 -2
package/dist/browser.umd.js
CHANGED
|
@@ -376,7 +376,7 @@ nt.prototype.$__init=function(t,e){if(this.$isNew=!1,e=e||{},null!=t._id&&e.popu
|
|
|
376
376
|
* @param {Object} doc object we are initializing
|
|
377
377
|
* @api private
|
|
378
378
|
*/
|
|
379
|
-
return function t(e,r,n,i,o){o=o||"";var s,a,u,h=Object.keys(r),f=h.length,c=0,l=e.$__.strictMode;for(;c<f;)d(c++);function d(f){if(u=h[f],a=o+u,s=e.$__schema.path(a),!e.$__schema.$isRootDiscriminator||e.$__isSelected(a))if(!s&&q.isPOJO(r[u]))n[u]||(n[u]={}),t(e,r[u],n[u],i,a+".");else if(s){if(n.hasOwnProperty(u)&&void 0!==r[u]&&delete n[u],null===r[u])n[u]=s._castNullish(null);else if(void 0!==r[u]){var c=(r[u].$__||{}).wasPopulated||null;if(s&&!c)try{n[u]=s.cast(r[u],e,!0)}catch(t){e.invalidate(t.path,new w({path:t.path,message:t.message,type:"cast",value:t.value,reason:t}))}else n[u]=r[u]}e.$isModified(a)||e.$__.activePaths.init(a)}else n[u]=r[u],l||o||(e[u]=r[u])}}(this,t,this._doc,e),D(this,e.populated),this.$emit("init",this),this.constructor.emit("init",this),this.$__._id=this._id,this},nt.prototype.update=function(){var t=q.args(arguments);t.unshift({_id:this._id});var e=this.constructor.update.apply(this.constructor,t);return null!=this.$session()&&("session"in e.options||(e.options.session=this.$session())),e},nt.prototype.updateOne=function(t,e,r){var n=this,i=this.constructor.updateOne({_id:this._id},t,e);return i.pre((function(t){n.constructor._middleware.execPre("updateOne",n,[n],t)})),i.post((function(t){n.constructor._middleware.execPost("updateOne",n,[n],{},t)})),null!=this.$session()&&("session"in i.options||(i.options.session=this.$session())),null!=r?i.exec(r):i},nt.prototype.replaceOne=function(){var t=q.args(arguments);return t.unshift({_id:this._id}),this.constructor.replaceOne.apply(this.constructor,t)},nt.prototype.$session=function(t){if(0===arguments.length)return null!=this.$__.session&&this.$__.session.hasEnded?(this.$__.session=null,null):this.$__.session;if(null!=t&&t.hasEnded)throw new l("Cannot set a document's session to a session that has ended. Make sure you haven't called `endSession()` on the session you are passing to `$session()`.");if(null!=t||null!=this.$__.session){if(this.$__.session=t,!this.$isSubdocument){var e,r=this.$getAllSubdocs(),n=i(r);try{for(n.s();!(e=n.n()).done;){var o=e.value;o.$session(t)}}catch(t){n.e(t)}finally{n.f()}}return t}},nt.prototype.overwrite=function(t){for(var e=0,r=Array.from(new Set(Object.keys(this._doc).concat(Object.keys(t))));e<r.length;e++){var n=r[e];"_id"!==n&&(this.$__schema.options.versionKey&&n===this.$__schema.options.versionKey||this.$__schema.options.discriminatorKey&&n===this.$__schema.options.discriminatorKey||this.$set(n,t[n]))}return this},nt.prototype.$set=function(t,e,r,o){var a=this;q.isPOJO(r)&&(o=r,r=void 0);var u,h,f,c,y=(o=o||{}).merge,m=r&&!0!==r,b=!0===r,g=this.$__schema.options.typeKey,w=0,_="strict"in o?o.strict:this.$__.strictMode;if(m&&((this.$__.adhocPaths||(this.$__.adhocPaths={}))[t]=this.$__schema.interpretAsType(t,r,this.$__schema.options)),null==t){var M=[e,t];t=M[0],e=M[1]}else if("string"!=typeof t){if(t instanceof nt&&(t=t.$__isNested?t.toObject():t._doc),null==t){var O=[e,t];t=O[0],e=O[1]}c=e?e+".":"";var A=(u=$(this.$__schema,t)).length,E=k(o,"_skipMinimizeTopLevel",!1);if(0===A&&E)return delete o._skipMinimizeTopLevel,e&&this.$set(e,{}),this;for(var x=0;x<A;++x){var R=c+(f=u[x]);h=this.$__schema.pathType(R);var B=t[f];if(!0!==r||c||null==t[f]||"nested"!==h||null==this._doc[f]?o=Object.assign({},o,{_skipMinimizeTopLevel:!1}):(delete this._doc[f],o=Object.assign({},o,{_skipMinimizeTopLevel:!0})),q.isNonBuiltinObject(B)&&"nested"===h)at(t[f],c+f,this),this.$set(c+f,t[f],b,Object.assign({},o,{_skipMarkModified:!0}));else if(_){if(b&&void 0===t[f]&&void 0!==this.$get(R))continue;if("adhocOrUndefined"===h&&(h=j(this,R,{typeOnly:!0})),"real"===h||"virtual"===h){var T=t[f];this.$
|
|
379
|
+
return function t(e,r,n,i,o){o=o||"";var s,a,u,h=Object.keys(r),f=h.length,c=0,l=e.$__.strictMode;for(;c<f;)d(c++);function d(f){if(u=h[f],a=o+u,s=e.$__schema.path(a),!e.$__schema.$isRootDiscriminator||e.$__isSelected(a))if(!s&&q.isPOJO(r[u]))n[u]||(n[u]={}),t(e,r[u],n[u],i,a+".");else if(s){if(n.hasOwnProperty(u)&&void 0!==r[u]&&delete n[u],null===r[u])n[u]=s._castNullish(null);else if(void 0!==r[u]){var c=(r[u].$__||{}).wasPopulated||null;if(s&&!c)try{n[u]=s.cast(r[u],e,!0)}catch(t){e.invalidate(t.path,new w({path:t.path,message:t.message,type:"cast",value:t.value,reason:t}))}else n[u]=r[u]}e.$isModified(a)||e.$__.activePaths.init(a)}else n[u]=r[u],l||o||(e[u]=r[u])}}(this,t,this._doc,e),D(this,e.populated),this.$emit("init",this),this.constructor.emit("init",this),this.$__._id=this._id,this},nt.prototype.update=function(){var t=q.args(arguments);t.unshift({_id:this._id});var e=this.constructor.update.apply(this.constructor,t);return null!=this.$session()&&("session"in e.options||(e.options.session=this.$session())),e},nt.prototype.updateOne=function(t,e,r){var n=this,i=this.constructor.updateOne({_id:this._id},t,e);return i.pre((function(t){n.constructor._middleware.execPre("updateOne",n,[n],t)})),i.post((function(t){n.constructor._middleware.execPost("updateOne",n,[n],{},t)})),null!=this.$session()&&("session"in i.options||(i.options.session=this.$session())),null!=r?i.exec(r):i},nt.prototype.replaceOne=function(){var t=q.args(arguments);return t.unshift({_id:this._id}),this.constructor.replaceOne.apply(this.constructor,t)},nt.prototype.$session=function(t){if(0===arguments.length)return null!=this.$__.session&&this.$__.session.hasEnded?(this.$__.session=null,null):this.$__.session;if(null!=t&&t.hasEnded)throw new l("Cannot set a document's session to a session that has ended. Make sure you haven't called `endSession()` on the session you are passing to `$session()`.");if(null!=t||null!=this.$__.session){if(this.$__.session=t,!this.$isSubdocument){var e,r=this.$getAllSubdocs(),n=i(r);try{for(n.s();!(e=n.n()).done;){var o=e.value;o.$session(t)}}catch(t){n.e(t)}finally{n.f()}}return t}},nt.prototype.overwrite=function(t){for(var e=0,r=Array.from(new Set(Object.keys(this._doc).concat(Object.keys(t))));e<r.length;e++){var n=r[e];"_id"!==n&&(this.$__schema.options.versionKey&&n===this.$__schema.options.versionKey||this.$__schema.options.discriminatorKey&&n===this.$__schema.options.discriminatorKey||this.$set(n,t[n]))}return this},nt.prototype.$set=function(t,e,r,o){var a=this;q.isPOJO(r)&&(o=r,r=void 0);var u,h,f,c,y=(o=o||{}).merge,m=r&&!0!==r,b=!0===r,g=this.$__schema.options.typeKey,w=0,_="strict"in o?o.strict:this.$__.strictMode;if(m&&((this.$__.adhocPaths||(this.$__.adhocPaths={}))[t]=this.$__schema.interpretAsType(t,r,this.$__schema.options)),null==t){var M=[e,t];t=M[0],e=M[1]}else if("string"!=typeof t){if(t instanceof nt&&(t=t.$__isNested?t.toObject():t._doc),null==t){var O=[e,t];t=O[0],e=O[1]}c=e?e+".":"";var A=(u=$(this.$__schema,t)).length,E=k(o,"_skipMinimizeTopLevel",!1);if(0===A&&E)return delete o._skipMinimizeTopLevel,e&&this.$set(e,{}),this;for(var x=0;x<A;++x){var R=c+(f=u[x]);h=this.$__schema.pathType(R);var B=t[f];if(!0!==r||c||null==t[f]||"nested"!==h||null==this._doc[f]?o=Object.assign({},o,{_skipMinimizeTopLevel:!1}):(delete this._doc[f],o=Object.assign({},o,{_skipMinimizeTopLevel:!0})),q.isNonBuiltinObject(B)&&"nested"===h)at(t[f],c+f,this),this.$set(c+f,t[f],b,Object.assign({},o,{_skipMarkModified:!0}));else if(_){if(b&&void 0===t[f]&&void 0!==this.$get(R))continue;if("adhocOrUndefined"===h&&(h=j(this,R,{typeOnly:!0})),"real"===h||"virtual"===h){var T=t[f];this.$set(c+f,T,b,o)}else if("nested"===h&&t[f]instanceof nt)this.$set(c+f,t[f].toObject({transform:!1}),b,o);else if("throw"===_)throw"nested"===h?new p(f,t[f]):new v(f)}else void 0!==t[f]&&this.$set(c+f,t[f],b,o)}for(var I=0,D=Object.keys(this.$__schema.tree);I<D.length;I++){var L=D[I];if(this._doc.hasOwnProperty(L)){var U=this._doc[L];delete this._doc[L],this._doc[L]=U}}return this}var F=this.$__schema.pathType(t);"adhocOrUndefined"===F&&(F=j(this,t,{typeOnly:!0})),e=P(e);var z,V=null!=a.$__.priorDoc?a.$__.priorDoc.$__getValue(t):b?void 0:a.$__getValue(t);if("nested"===F&&e){if("object"===s(e)&&null!=e){if(null!=e.$__&&(e=e.toObject(N)),null==e)return this.invalidate(t,new l.CastError("Object",e,t)),this;var K=null!=this.$__.savedState&&this.$__.savedState.hasOwnProperty(t);if(null!=this.$__.savedState&&!this.$isNew&&!this.$__.savedState.hasOwnProperty(t)){var H=this.$__getValue(t);this.$__.savedState[t]=H;for(var W=0,Z=Object.keys(H||{});W<Z.length;W++){var J=Z[W];this.$__.savedState[t+"."+J]=H[J]}}if(y)return this.$set(e,t,b);this.$__setValue(t,null),S(this,t);var Y=$(this.$__schema,e,t);this.$__setValue(t,{});var G,X=i(Y);try{for(X.s();!(G=X.n()).done;){var tt=G.value;this.$set(t+"."+tt,e[tt],b,o)}}catch(t){X.e(t)}finally{X.f()}return null!=V&&q.deepEqual(K?this.$__.savedState[t]:V,e)?this.unmarkModified(t):this.markModified(t),S(this,t,{skipDocArrays:!0}),this}return this.invalidate(t,new l.CastError("Object",e,t)),this}var et=-1===t.indexOf(".")?[t]:t.split(".");if("string"==typeof this.$__schema.aliases[et[0]]&&(et[0]=this.$__schema.aliases[et[0]]),"adhocOrUndefined"===F&&_){var rt;for(w=0;w<et.length;++w){var it=et.slice(0,w+1).join(".");if(w+1<et.length&&"virtual"===this.$__schema.pathType(it))return C.set(t,e,this),this;if(null!=(z=this.$__schema.path(it))&&z instanceof d){rt=!0;break}}if(null==z&&(z=j(this,t)),!rt&&!z){if("throw"===_)throw new v(t);return this}}else{if("virtual"===F)return(z=this.$__schema.virtualpath(t)).applySetters(e,this),this;z=this.$__path(t)}var ot,st=this._doc,ut="";for(w=0;w<et.length-1;++w)st=st[et[w]],ut+=(ut.length>0?".":"")+et[w],st||(this.$set(ut,{}),this.$__isSelected(ut)||this.unmarkModified(ut),st=this.$__getValue(ut));if(et.length<=1)ot=t;else{for(w=0;w<et.length;++w){var ht=et.slice(0,w+1).join(".");if(null===this.$get(ht,null,{getters:!1})){ot=ht;break}}ot||(ot=t)}if(!z)return this.$__set(ot,t,o,b,et,z,e,V),this;if((z.$isSingleNested||z.$isMongooseArray)&&
|
|
380
380
|
/*!
|
|
381
381
|
* ignore
|
|
382
382
|
*/
|
|
@@ -387,7 +387,7 @@ function(t,e){if(!t.$__.validationError)return;for(var r=Object.keys(t.$__.valid
|
|
|
387
387
|
/*!
|
|
388
388
|
* ignore
|
|
389
389
|
*/
|
|
390
|
-
function(t,e){if(!Array.isArray(t))return!1;if(0===t.length)return!1;var r,n=i(t);try{for(n.s();!(r=n.n()).done;){var o=r.value;if(!(o instanceof nt))return!1;if(null==o.constructor.modelName)return!1;if(o.constructor.modelName!=e&&o.constructor.baseModelName!=e)return!1}}catch(t){n.e(t)}finally{n.f()}return!0}(e,z.options[g][0].ref)){pt=n({},Q,e[0].constructor),this.$populated(t,e.map((function(t){return t._id})),pt);var bt,vt=i(e);try{for(vt.s();!(bt=vt.n()).done;){bt.value.$__.wasPopulated=!0}}catch(t){vt.e(t)}finally{vt.f()}mt=!0}if(null
|
|
390
|
+
function(t,e){if(!Array.isArray(t))return!1;if(0===t.length)return!1;var r,n=i(t);try{for(n.s();!(r=n.n()).done;){var o=r.value;if(!(o instanceof nt))return!1;if(null==o.constructor.modelName)return!1;if(o.constructor.modelName!=e&&o.constructor.baseModelName!=e)return!1}}catch(t){n.e(t)}finally{n.f()}return!0}(e,z.options[g][0].ref)){pt=n({},Q,e[0].constructor),this.$populated(t,e.map((function(t){return t._id})),pt);var bt,vt=i(e);try{for(vt.s();!(bt=vt.n()).done;){bt.value.$__.wasPopulated=!0}}catch(t){vt.e(t)}finally{vt.f()}mt=!0}if(null!=this.$__schema.singleNestedPaths[t]||yt&&z.$isSingleNested&&e.$__||(e=z.applySetters(e,this,!1,V)),z.$isMongooseDocumentArray&&Array.isArray(e)&&e.length>0&&null!=e[0]&&null!=e[0].$__&&null!=e[0].$__.populated){for(var gt=Object.keys(e[0].$__.populated),wt=function(){var r=Mt[_t];a.$populated(t+"."+r,e.map((function(t){return t.$populated(r)})),e[0].$__.populated[r].options)},_t=0,Mt=gt;_t<Mt.length;_t++)wt();mt=!0}if(!mt&&this.$__.populated){if(Array.isArray(e)&&this.$__.populated[t])for(var St=0;St<e.length;++St)e[St]instanceof nt&&e.set(St,e[St]._id,!0);delete this.$__.populated[t]}z.$isSingleNested&&null!=e&&function(t,e,r){var n=e.schema;if(null==n)return;for(var i=0,o=Object.keys(n.paths);i<o.length;i++){var s=o[i],a=n.paths[s];if(null!=a.$immutableSetter){var u=null==r?void 0:r.$__getValue(s);a.$immutableSetter.call(t,u)}}}(e,z,V),this.$markValid(t)}catch(r){r instanceof l.StrictModeError&&r.isImmutableError?this.invalidate(t,r):r instanceof l.CastError?(this.invalidate(r.path,r),r.$originalErrorPath&&this.invalidate(t,new l.CastError(z.instance,e,t,r.$originalErrorPath))):this.invalidate(t,new l.CastError(z.instance,e,t,r)),dt=!1}if(dt){var Ot=this.$isSubdocument?this.ownerDocument():this,At=Ot.$__.savedState,Et=this.$isSubdocument?this.$__.fullPath+"."+t:t;if(null!=At){var xt=Et.indexOf("."),kt=-1===xt?Et:Et.slice(0,xt);At.hasOwnProperty(kt)||(At[kt]=q.clone(Ot.$__getValue(kt)))}this.$__set(ot,t,o,b,et,z,e,V),null!=At&&At.hasOwnProperty(Et)&&q.deepEqual(e,At[Et])&&this.unmarkModified(t)}return z.$isSingleNested&&(this.isDirectModified(t)||null==e)&&S(this,t),this},nt.prototype.set=nt.prototype.$set,nt.prototype.$__shouldModify=function(t,e,r,n,i,o,s,a){return!r._skipMarkModified&&(!!this.$isNew||null==this.$__schema.singleNestedPaths[e]&&(void 0===s&&!this.$__isSelected(e)||(void 0!==s||!(e in this.$__.activePaths.states.default))&&(!(this.$populated(e)&&s instanceof nt&&z(s._id,a))&&(!z(s,a||q.getValue(e,this))||!(n||null==s||!(e in this.$__.activePaths.states.default)||!z(s,o.getDefault(this,n)))))))},nt.prototype.$__set=function(t,e,n,i,o,s,a,f){h=h||r(47);var c=this.$__shouldModify(t,e,n,i,o,s,a,f),l=this;c?(this.markModified(t),u||(u=r(175)),a&&a.isMongooseArray&&(a._registerAtomic("$set",a),a.isMongooseDocumentArray&&a.forEach((function(t){t&&t.__parentArray&&(t.__parentArray=a)})),this.$__.activePaths.forEach((function(t){t.startsWith(e+".")&&l.$__.activePaths.ignore(t)})))):Array.isArray(a)&&a.isMongooseArray&&Array.isArray(f)&&f.isMongooseArray&&(a[H]=f[H],a[K]=f[K]);for(var d=this._doc,p=0,y=o.length,m="";p<y;p++){var b=p+1===y;if(m+=m?"."+o[p]:o[p],rt.has(o[p]))return;b?d instanceof Map?d.set(o[p],a):d[o[p]]=a:(q.isPOJO(d[o[p]])||d[o[p]]&&d[o[p]]instanceof h||d[o[p]]&&d[o[p]].$isSingleNested||d[o[p]]&&Array.isArray(d[o[p]])||(d[o[p]]=d[o[p]]||{}),d=d[o[p]])}},nt.prototype.$__getValue=function(t){return q.getValue(t,this._doc)},nt.prototype.$__setValue=function(t,e){return q.setValue(t,e,this._doc),this},nt.prototype.get=function(t,e,r){var n;r=r||{},e&&(n=this.$__schema.interpretAsType(t,e,this.$__schema.options));var i=this.$__path(t);if(null==i&&(i=this.$__schema.virtualpath(t)),i instanceof d){var o=this.$__schema.virtualpath(t);null!=o&&(i=o)}var s=-1===t.indexOf(".")?[t]:t.split("."),a=this._doc;if(i instanceof _)return i.applyGetters(void 0,this);"string"==typeof this.$__schema.aliases[s[0]]&&(s[0]=this.$__schema.aliases[s[0]]);for(var u=0,h=s.length;u<h;u++)a&&a._doc&&(a=a._doc),a=null==a?void 0:a instanceof Map?a.get(s[u],{getters:!1}):u===h-1?q.getValue(s[u],a):a[s[u]];if(n&&(a=n.cast(a)),null!=i&&!1!==r.getters)a=i.applyGetters(a,this);else if(this.$__schema.nested[t]&&r.virtuals)return dt(this,q.clone(a)||{},{path:t});return a},
|
|
391
391
|
/*!
|
|
392
392
|
* ignore
|
|
393
393
|
*/
|
|
@@ -1240,7 +1240,7 @@ t.exports=h},function(t,e,r){"use strict";var n=r(56);
|
|
|
1240
1240
|
/*!
|
|
1241
1241
|
* exports
|
|
1242
1242
|
*/
|
|
1243
|
-
t.exports=h},function(t,e,r){"use strict";(function(e){function r(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0,o=function(){};return{s:o,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(){this._pres=new Map,this._posts=new Map}function s(t,e,r,n,i,o,s){if(o.useErrorHandlers){var a={error:e};return t.execPost(r,n,i,a,(function(t){return"function"==typeof s&&s(t)}))}return"function"==typeof s?s(e):void 0}function a(t,e,r){return t.has(e)?t.get(e):r}function u(t,e,r,n){var i;try{i=t.apply(e,r)}catch(t){return n(t)}h(i)&&i.then((function(){return n()}),(function(t){return n(t)}))}function h(t){return null!=t&&"function"==typeof t.then}function f(t){var r=!1,n=this;return function(){var i=arguments;if(!r)return r=!0,e.nextTick((function(){return t.apply(n,i)}))}}o.prototype.execPre=function(t,r,n,i){3===arguments.length&&(i=n,n=[]);var o=a(this._pres,t,[]),s=o.length,c=o.numAsync||0,l=0,d=c,p=!1,y=n;if(!s)return e.nextTick((function(){i(null)}));var m=function t(){if(!(l>=s)){var n=o[l];if(n.isAsync){var a=[f(b),f((function(t){if(t){if(p)return;return p=!0,i(t)}if(0==--d&&l>=s)return i(null)}))];u(n.fn,r,a,a[0])}else if(n.fn.length>0){a=[f(b)];for(var c=arguments.length>=2?arguments:[null].concat(y),m=1;m<c.length;++m)a.push(c[m]);u(n.fn,r,a,a[0])}else{var v=null;try{v=n.fn.call(r)}catch(t){if(null!=t)return i(t)}if(h(v))v.then((function(){return b()}),(function(t){return b(t)}));else{if(++l>=s)return d>0?void 0:e.nextTick((function(){i(null)}));t()}}}};function b(t){if(t){if(p)return;return p=!0,i(t)}if(++l>=s)return d>0?void 0:i(null);m.apply(r,arguments)}m.apply(null,[null].concat(n))},o.prototype.execPreSync=function(t,e,r){for(var n=a(this._pres,t,[]),i=n.length,o=0;o<i;++o)n[o].fn.apply(e,r||[])},o.prototype.execPost=function(t,r,n,i,o){arguments.length<5&&(o=i,i=null);var s=a(this._posts,t,[]),c=s.length,l=0,d=null;if(i&&i.error&&(d=i.error),!c)return e.nextTick((function(){o.apply(null,[d].concat(n))}));var p=function t(){for(var e=s[l].fn,i=0,a=n.length,p=[],y=0;y<a;++y)i+=n[y]&&n[y]._kareemIgnore?0:1,n[y]&&n[y]._kareemIgnore||p.push(n[y]);if(d)if(e.length===i+2){var m=f((function(e){if(e&&(d=e),++l>=c)return o.call(null,d);t()}));u(e,r,[d].concat(p).concat([m]),m)}else{if(++l>=c)return o.call(null,d);t()}else{var b=f((function(e){return e?(d=e,t()):++l>=c?o.apply(null,[null].concat(n)):void t()}));if(e.length===i+2)return++l>=c?o.apply(null,[null].concat(n)):t();if(e.length===i+1)u(e,r,p.concat([b]),b);else{var v,g;try{g=e.apply(r,p)}catch(t){v=t,d=t}if(h(g))return g.then((function(){return b()}),(function(t){return b(t)}));if(++l>=c)return o.apply(null,[v].concat(n));t()}}};p()},o.prototype.execPostSync=function(t,e,r){for(var n=a(this._posts,t,[]),i=n.length,o=0;o<i;++o)n[o].fn.apply(e,r||[])},o.prototype.createWrapperSync=function(t,e){var r=this;return function(){r.execPreSync(t,this,arguments);var n=e.apply(this,arguments);return r.execPostSync(t,this,[n]),n}},o.prototype.wrap=function(t,e,r,n,i){var o=n.length>0?n[n.length-1]:null,a=("function"==typeof o&&n.slice(0,n.length-1),this),u=(i=i||{}).checkForPromise;this.execPre(t,r,n,(function(h){if(h){for(var f=i.numCallbackParams||0,c=i.contextParameter?[r]:[],l=c.length;l<f;++l)c.push(null);return s(a,h,t,r,c,i,o)}var d="function"==typeof o?n.length-1:n.length,
|
|
1243
|
+
t.exports=h},function(t,e,r){"use strict";(function(e){function r(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0,o=function(){};return{s:o,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(){this._pres=new Map,this._posts=new Map}function s(t,e,r,n,i,o,s){if(o.useErrorHandlers){var a={error:e};return t.execPost(r,n,i,a,(function(t){return"function"==typeof s&&s(t)}))}return"function"==typeof s?s(e):void 0}function a(t,e,r){return t.has(e)?t.get(e):r}function u(t,e,r,n){var i;try{i=t.apply(e,r)}catch(t){return n(t)}h(i)&&i.then((function(){return n()}),(function(t){return n(t)}))}function h(t){return null!=t&&"function"==typeof t.then}function f(t){var r=!1,n=this;return function(){var i=arguments;if(!r)return r=!0,e.nextTick((function(){return t.apply(n,i)}))}}o.prototype.execPre=function(t,r,n,i){3===arguments.length&&(i=n,n=[]);var o=a(this._pres,t,[]),s=o.length,c=o.numAsync||0,l=0,d=c,p=!1,y=n;if(!s)return e.nextTick((function(){i(null)}));var m=function t(){if(!(l>=s)){var n=o[l];if(n.isAsync){var a=[f(b),f((function(t){if(t){if(p)return;return p=!0,i(t)}if(0==--d&&l>=s)return i(null)}))];u(n.fn,r,a,a[0])}else if(n.fn.length>0){a=[f(b)];for(var c=arguments.length>=2?arguments:[null].concat(y),m=1;m<c.length;++m)a.push(c[m]);u(n.fn,r,a,a[0])}else{var v=null;try{v=n.fn.call(r)}catch(t){if(null!=t)return i(t)}if(h(v))v.then((function(){return b()}),(function(t){return b(t)}));else{if(++l>=s)return d>0?void 0:e.nextTick((function(){i(null)}));t()}}}};function b(t){if(t){if(p)return;return p=!0,i(t)}if(++l>=s)return d>0?void 0:i(null);m.apply(r,arguments)}m.apply(null,[null].concat(n))},o.prototype.execPreSync=function(t,e,r){for(var n=a(this._pres,t,[]),i=n.length,o=0;o<i;++o)n[o].fn.apply(e,r||[])},o.prototype.execPost=function(t,r,n,i,o){arguments.length<5&&(o=i,i=null);var s=a(this._posts,t,[]),c=s.length,l=0,d=null;if(i&&i.error&&(d=i.error),!c)return e.nextTick((function(){o.apply(null,[d].concat(n))}));var p=function t(){for(var e=s[l].fn,i=0,a=n.length,p=[],y=0;y<a;++y)i+=n[y]&&n[y]._kareemIgnore?0:1,n[y]&&n[y]._kareemIgnore||p.push(n[y]);if(d)if(e.length===i+2){var m=f((function(e){if(e&&(d=e),++l>=c)return o.call(null,d);t()}));u(e,r,[d].concat(p).concat([m]),m)}else{if(++l>=c)return o.call(null,d);t()}else{var b=f((function(e){return e?(d=e,t()):++l>=c?o.apply(null,[null].concat(n)):void t()}));if(e.length===i+2)return++l>=c?o.apply(null,[null].concat(n)):t();if(e.length===i+1)u(e,r,p.concat([b]),b);else{var v,g;try{g=e.apply(r,p)}catch(t){v=t,d=t}if(h(g))return g.then((function(){return b()}),(function(t){return b(t)}));if(++l>=c)return o.apply(null,[v].concat(n));t()}}};p()},o.prototype.execPostSync=function(t,e,r){for(var n=a(this._posts,t,[]),i=n.length,o=0;o<i;++o)n[o].fn.apply(e,r||[])},o.prototype.createWrapperSync=function(t,e){var r=this;return function(){r.execPreSync(t,this,arguments);var n=e.apply(this,arguments);return r.execPostSync(t,this,[n]),n}},o.prototype.wrap=function(t,e,r,n,i){var o=n.length>0?n[n.length-1]:null,a=("function"==typeof o&&n.slice(0,n.length-1),this),u=(i=i||{}).checkForPromise;this.execPre(t,r,n,(function(h){if(h){for(var f=i.numCallbackParams||0,c=i.contextParameter?[r]:[],l=c.length;l<f;++l)c.push(null);return s(a,h,t,r,c,i,o)}var d,p="function"==typeof o?n.length-1:n.length,y=e.length;try{d=e.apply(r,n.slice(0,p).concat(m))}catch(t){return m(t)}if(u){if(null!=d&&"function"==typeof d.then)return d.then((function(t){return m(null,t)}),(function(t){return m(t)}));if(y<p+1)return m(null,d)}function m(){var e=Array.prototype.slice.call(arguments,1);if(i.nullResultByDefault&&0===e.length&&e.push(null),arguments[0])return s(a,arguments[0],t,r,e,i,o);a.execPost(t,r,e,(function(){return arguments[0]?"function"==typeof o?o(arguments[0]):void 0:"function"==typeof o?o.apply(r,arguments):void 0}))}}))},o.prototype.filter=function(t){for(var e=this,r=this.clone(),n=Array.from(r._pres.keys()),i=function(){var n=s[o],i=e._pres.get(n).map((function(t){return Object.assign({},t,{name:n})})).filter(t);if(0===i.length)return r._pres.delete(n),"continue";i.numAsync=i.filter((function(t){return t.isAsync})).length,r._pres.set(n,i)},o=0,s=n;o<s.length;o++)i();for(var a=Array.from(r._posts.keys()),u=function(){var n=f[h],i=e._posts.get(n).map((function(t){return Object.assign({},t,{name:n})})).filter(t);if(0===i.length)return r._posts.delete(n),"continue";r._posts.set(n,i)},h=0,f=a;h<f.length;h++)u();return r},o.prototype.hasHooks=function(t){return this._pres.has(t)||this._posts.has(t)},o.prototype.createWrapper=function(t,r,n,i){var o=this;return this.hasHooks(t)?function(){var e=n||this,s=Array.prototype.slice.call(arguments);o.wrap(t,r,e,s,i)}:function(){var t=arguments,n=this;e.nextTick((function(){return r.apply(n,t)}))}},o.prototype.pre=function(t,e,r,n,o){var s={};"object"===i(e)&&null!=e?e=(s=e).isAsync:"boolean"!=typeof arguments[1]&&(n=r,r=e,e=!1);var u=a(this._pres,t,[]);if(this._pres.set(t,u),e&&(u.numAsync=u.numAsync||0,++u.numAsync),"function"!=typeof r)throw new Error('pre() requires a function, got "'+i(r)+'"');return o?u.unshift(Object.assign({},s,{fn:r,isAsync:e})):u.push(Object.assign({},s,{fn:r,isAsync:e})),this},o.prototype.post=function(t,e,r,n){var o=a(this._posts,t,[]);if("function"==typeof e&&(n=!!r,r=e,e={}),"function"!=typeof r)throw new Error('post() requires a function, got "'+i(r)+'"');return n?o.unshift(Object.assign({},e,{fn:r})):o.push(Object.assign({},e,{fn:r})),this._posts.set(t,o),this},o.prototype.clone=function(){var t,e=new o,n=r(this._pres.keys());try{for(n.s();!(t=n.n()).done;){var i=t.value,s=this._pres.get(i).slice();s.numAsync=this._pres.get(i).numAsync,e._pres.set(i,s)}}catch(t){n.e(t)}finally{n.f()}var a,u=r(this._posts.keys());try{for(u.s();!(a=u.n()).done;){var h=a.value;e._posts.set(h,this._posts.get(h).slice())}}catch(t){u.e(t)}finally{u.f()}return e},o.prototype.merge=function(t,e){var n,i=(e=1===arguments.length||e)?this.clone():this,o=r(t._pres.keys());try{var s=function(){var e=n.value,r=a(i._pres,e,[]),o=t._pres.get(e).filter((function(t){return-1===r.map((function(t){return t.fn})).indexOf(t.fn)})),s=r.concat(o);s.numAsync=r.numAsync||0,s.numAsync+=o.filter((function(t){return t.isAsync})).length,i._pres.set(e,s)};for(o.s();!(n=o.n()).done;)s()}catch(t){o.e(t)}finally{o.f()}var u,h=r(t._posts.keys());try{var f=function(){var e=u.value,r=a(i._posts,e,[]),n=t._posts.get(e).filter((function(t){return-1===r.indexOf(t)}));i._posts.set(e,r.concat(n))};for(h.s();!(u=h.n()).done;)f()}catch(t){h.e(t)}finally{h.f()}return i},t.exports=o}).call(this,r(5))},function(t,e,r){"use strict";function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function i(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}var o=r(16),s=i((function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Object.assign(this,e),null!=e&&null!=e.options&&(this.options=Object.assign({},e.options))}));Object.defineProperty(s.prototype,"ref",o),Object.defineProperty(s.prototype,"refPath",o),Object.defineProperty(s.prototype,"localField",o),Object.defineProperty(s.prototype,"foreignField",o),Object.defineProperty(s.prototype,"justOne",o),Object.defineProperty(s.prototype,"count",o),Object.defineProperty(s.prototype,"match",o),Object.defineProperty(s.prototype,"options",o),Object.defineProperty(s.prototype,"skip",o),Object.defineProperty(s.prototype,"limit",o),Object.defineProperty(s.prototype,"perDocumentLimit",o),t.exports=s},function(t,e,r){"use strict";var n=r(6),i=r(35);
|
|
1244
1244
|
/*!
|
|
1245
1245
|
* Gather all indexes defined in the schema, including single nested,
|
|
1246
1246
|
* document arrays, and embedded discriminators.
|
|
@@ -1259,7 +1259,7 @@ function(t,r){for(var n=t._indexes,i=n.length,o=0;o<i;++o){for(var s=n[o][0],a=n
|
|
|
1259
1259
|
/*!
|
|
1260
1260
|
* Returns this documents _id cast to a string.
|
|
1261
1261
|
*/
|
|
1262
|
-
function n(){return null!=this._id?String(this._id):null}t.exports=function(t){return!t.paths.id&&t.paths._id&&t.options.id?(t.virtual("id").get(n),t):t}},function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var i=r(323),o=r(325),s=r(6),a=r(166),u=r(57);t.exports=function(t,e){var r=t.childSchemas.find((function(t){return!!t.schema.options.timestamps}));if(e||r){var h,f=a(e,"createdAt"),c=a(e,"updatedAt"),l=null!=e&&e.hasOwnProperty("currentTime")?e.currentTime:null,d={};if(t.$timestamps={createdAt:f,updatedAt:c},c&&!t.paths[c]&&(d[c]=Date),f&&!t.paths[f])d[f]=(n(h={},t.options.typeKey||"type",Date),n(h,"immutable",!0),h);t.add(d),t.pre("save",(function(t){var e=s(this,"$__.saveOptions.timestamps");if(!1===e)return t();var r=null!=e&&!1===e.updatedAt,n=null!=e&&!1===e.createdAt,i=null!=l?l():this.ownerDocument().constructor.base.now(),o=this._id&&this._id.auto;if(!n&&f&&!this.$__getValue(f)&&this.$__isSelected(f)&&this.$set(f,o?this._id.getTimestamp():i),!r&&c&&(this.isNew||this.$isModified())){var a=i;this.isNew&&(null!=f?a=this.$__getValue(f):o&&(a=this._id.getTimestamp())),this.$set(c,a)}t()})),t.methods.initializeTimestamps=function(){var t=null!=l?l():this.constructor.base.now();return f&&!this.get(f)&&this.$set(f,t),c&&!this.get(c)&&this.$set(c,t),this},y[u.builtInMiddleware]=!0;var p={query:!0,model:!1};t.pre("findOneAndReplace",p,y),t.pre("findOneAndUpdate",p,y),t.pre("replaceOne",p,y),t.pre("update",p,y),t.pre("updateOne",p,y),t.pre("updateMany",p,y)}function y(t){var e=null!=l?l():this.model.base.now();"findOneAndReplace"===this.op&&null==this.getUpdate()&&this.setUpdate({}),o(e,f,c,this.getUpdate(),this.options,this.schema),i(e,this.getUpdate(),this.model.schema),t()}}},function(t,e,r){"use strict";function n(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var o=r(324),s=r(166);
|
|
1262
|
+
function n(){return null!=this._id?String(this._id):null}t.exports=function(t){return!t.paths.id&&t.paths._id&&t.options.id?(t.virtual("id").get(n),t):t}},function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var i=r(323),o=r(325),s=r(6),a=r(166),u=r(57);t.exports=function(t,e){var r=t.childSchemas.find((function(t){return!!t.schema.options.timestamps}));if(e||r){var h,f=a(e,"createdAt"),c=a(e,"updatedAt"),l=null!=e&&e.hasOwnProperty("currentTime")?e.currentTime:null,d={};if(t.$timestamps={createdAt:f,updatedAt:c},c&&!t.paths[c]&&(d[c]=Date),f&&!t.paths[f])d[f]=(n(h={},t.options.typeKey||"type",Date),n(h,"immutable",!0),h);t.add(d),t.pre("save",(function(t){var e=s(this,"$__.saveOptions.timestamps");if(!1===e)return t();var r=null!=e&&!1===e.updatedAt,n=null!=e&&!1===e.createdAt,i=null!=l?l():this.ownerDocument().constructor.base.now(),o=this._id&&this._id.auto;if(!n&&this.isNew&&f&&!this.$__getValue(f)&&this.$__isSelected(f)&&this.$set(f,o?this._id.getTimestamp():i),!r&&c&&(this.isNew||this.$isModified())){var a=i;this.isNew&&(null!=f?a=this.$__getValue(f):o&&(a=this._id.getTimestamp())),this.$set(c,a)}t()})),t.methods.initializeTimestamps=function(){var t=null!=l?l():this.constructor.base.now();return f&&!this.get(f)&&this.$set(f,t),c&&!this.get(c)&&this.$set(c,t),this},y[u.builtInMiddleware]=!0;var p={query:!0,model:!1};t.pre("findOneAndReplace",p,y),t.pre("findOneAndUpdate",p,y),t.pre("replaceOne",p,y),t.pre("update",p,y),t.pre("updateOne",p,y),t.pre("updateMany",p,y)}function y(t){var e=null!=l?l():this.model.base.now();"findOneAndReplace"===this.op&&null==this.getUpdate()&&this.setUpdate({}),o(e,f,c,this.getUpdate(),this.options,this.schema),i(e,this.getUpdate(),this.model.schema),t()}}},function(t,e,r){"use strict";function n(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var o=r(324),s=r(166);
|
|
1263
1263
|
/*!
|
|
1264
1264
|
* ignore
|
|
1265
1265
|
*/
|
|
@@ -1453,7 +1453,7 @@ function w(t,e){i||(i=r(94));var n=function(t,e,r){var n=this;this.$__parent=r,i
|
|
|
1453
1453
|
/*!
|
|
1454
1454
|
* ignore
|
|
1455
1455
|
*/
|
|
1456
|
-
g.prototype.$conditionalHandlers.$near=g.prototype.$conditionalHandlers.$nearSphere=d.cast$near,g.prototype.$conditionalHandlers.$within=g.prototype.$conditionalHandlers.$geoWithin=d.cast$within,g.prototype.$conditionalHandlers.$geoIntersects=d.cast$geoIntersects,g.prototype.$conditionalHandlers.$minDistance=c,g.prototype.$conditionalHandlers.$maxDistance=c,g.prototype.$conditionalHandlers.$exists=f,g.prototype.cast=function(t,e,r,i,o){if(t&&t.$isSingleNested&&t.parent===e)return t;if(null!=t&&("object"!==n(t)||Array.isArray(t)))throw new a(this.path,t);var s,u=y(this.caster,t),h=p(e,"$__.selected",{}),f=this.path,c=Object.keys(h).reduce((function(t,e){return e.startsWith(f+".")&&(t[e.substr(f.length+1)]=h[e]),t}),{});return o=Object.assign({},o,{priorDoc:i}),r?((s=new u(void 0,c,e)).$init(t),s):0===Object.keys(t).length?new u({},c,e,void 0,o):new u(t,c,e,void 0,o)},g.prototype.castForQuery=function(t,e,r){var n;if(2===arguments.length){if(!(n=this.$conditionalHandlers[t]))throw new Error("Can't use "+t);return n.call(this,e)}if(null==(e=t))return e;this.options.runSetters&&(e=this._applySetters(e));var i=y(this.caster,e),s=null!=r&&null!=r.strict?r.strict:void 0;try{e=new i(e,s)}catch(t){if(!(t instanceof o))throw new o("Embedded",e,this.path,t,this);throw t}return e},g.prototype.doValidate=function(t,e,r,n){var i=y(this.caster,t);if(
|
|
1456
|
+
g.prototype.$conditionalHandlers.$near=g.prototype.$conditionalHandlers.$nearSphere=d.cast$near,g.prototype.$conditionalHandlers.$within=g.prototype.$conditionalHandlers.$geoWithin=d.cast$within,g.prototype.$conditionalHandlers.$geoIntersects=d.cast$geoIntersects,g.prototype.$conditionalHandlers.$minDistance=c,g.prototype.$conditionalHandlers.$maxDistance=c,g.prototype.$conditionalHandlers.$exists=f,g.prototype.cast=function(t,e,r,i,o){if(t&&t.$isSingleNested&&t.parent===e)return t;if(null!=t&&("object"!==n(t)||Array.isArray(t)))throw new a(this.path,t);var s,u=y(this.caster,t),h=p(e,"$__.selected",{}),f=this.path,c=Object.keys(h).reduce((function(t,e){return e.startsWith(f+".")&&(t[e.substr(f.length+1)]=h[e]),t}),{});return o=Object.assign({},o,{priorDoc:i}),r?((s=new u(void 0,c,e)).$init(t),s):0===Object.keys(t).length?new u({},c,e,void 0,o):new u(t,c,e,void 0,o)},g.prototype.castForQuery=function(t,e,r){var n;if(2===arguments.length){if(!(n=this.$conditionalHandlers[t]))throw new Error("Can't use "+t);return n.call(this,e)}if(null==(e=t))return e;this.options.runSetters&&(e=this._applySetters(e));var i=y(this.caster,e),s=null!=r&&null!=r.strict?r.strict:void 0;try{e=new i(e,s)}catch(t){if(!(t instanceof o))throw new o("Embedded",e,this.path,t,this);throw t}return e},g.prototype.doValidate=function(t,e,r,n){var i=y(this.caster,t);if(!t||t instanceof i||(t=new i(t,null,r)),n&&n.skipSchemaValidators)return t.validate(e);h.prototype.doValidate.call(this,t,(function(r){return r?e(r):t?void t.validate(e):e(null)}),r,n)},g.prototype.doValidateSync=function(t,e,r){if(!r||!r.skipSchemaValidators){var n=h.prototype.doValidateSync.call(this,t,e);if(n)return n}if(t)return t.validateSync()},g.prototype.discriminator=function(t,e,r){r=r||{};var n=v.isPOJO(r)?r.value:r,i=p(r,"clone",!0);return e.instanceOfSchema&&i&&(e=e.clone()),e=l(this.caster,t,e,n),this.caster.discriminators[t]=w(e,this.caster),this.caster.discriminators[t]},g.defaultOptions={},g.set=h.set,
|
|
1457
1457
|
/*!
|
|
1458
1458
|
* ignore
|
|
1459
1459
|
*/
|
|
@@ -1591,7 +1591,7 @@ function u(e){return e&&"object"===n(e)&&!(e instanceof Date)&&!(e instanceof s)
|
|
|
1591
1591
|
/*!
|
|
1592
1592
|
* ignore
|
|
1593
1593
|
*/
|
|
1594
|
-
function e(r,n,i,o){var s;s=r&&a(r)&&!t.isBuffer(r)?Object.keys(r.toObject({transform:!1,virtuals:!1})):Object.keys(r||{});var h=s.length,f={};n=n?n+".":"";for(var c=0;c<h;++c){var l=s[c],d=r[l];f[n+l]=d;var p=o&&o.path&&o.path(n+l),y=o&&o.nested&&o.nested[n+l];if(!p||"Mixed"!==p.instance){if(u(d)){if(i&&i.skipArrays&&Array.isArray(d))continue;var m=e(d,n+l,i,o);for(var b in m)f[b]=m[b];Array.isArray(d)&&(f[n+l]=d)}if(y)for(var v=Object.keys(o.paths),g=0,w=v;g<w.length;g++){var _=w[g];_.startsWith(n+l+".")&&!f.hasOwnProperty(_)&&(f[_]=void 0)}}}return f}
|
|
1594
|
+
function e(r,n,i,o){var s;s=r&&a(r)&&!t.isBuffer(r)?Object.keys(r.toObject({transform:!1,virtuals:!1})||{}):Object.keys(r||{});var h=s.length,f={};n=n?n+".":"";for(var c=0;c<h;++c){var l=s[c],d=r[l];f[n+l]=d;var p=o&&o.path&&o.path(n+l),y=o&&o.nested&&o.nested[n+l];if(!p||"Mixed"!==p.instance){if(u(d)){if(i&&i.skipArrays&&Array.isArray(d))continue;var m=e(d,n+l,i,o);for(var b in m)f[b]=m[b];Array.isArray(d)&&(f[n+l]=d)}if(y)for(var v=Object.keys(o.paths),g=0,w=v;g<w.length;g++){var _=w[g];_.startsWith(n+l+".")&&!f.hasOwnProperty(_)&&(f[_]=void 0)}}}return f}
|
|
1595
1595
|
/*!
|
|
1596
1596
|
* ignore
|
|
1597
1597
|
*/,e.modifiedPaths=function e(r,n,i){var o=Object.keys(r||{}),s=o.length;i=i||{},n=n?n+".":"";for(var h=0;h<s;++h){var f=o[h],c=r[f],l=n+f;if(i[l]=!0,-1!==l.indexOf("."))for(var d=l.split("."),p=d[0],y=1;y<d.length;++y)i[p]=!0,p+="."+d[y];a(c)&&!t.isBuffer(c)&&(c=c.toObject({transform:!1,virtuals:!1})),u(c)&&e(c,n+f,i)}return i}}).call(this,r(3).Buffer)},function(t,e,r){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(20),o=r(356),s=r(9);t.exports=function t(e){if(null!=e&&"object"===n(e)&&!Array.isArray(e)&&!e.$__)for(var r=0,a=Object.keys(e);r<a.length;r++){var u=a[r],h=e[u];if(-1===u.indexOf("."))t(e[u]);else try{delete e[u],o(e,u,h)}catch(t){if(!(t instanceof TypeError))throw t;throw new i('Conflicting dotted paths when setting document path, key: "'.concat(u,'", value: ').concat(s.inspect(h)))}}}},function(t,e,r){"use strict";function n(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}t.exports=function(t,e,r){var i,o=-1===e.indexOf(".")?[e]:e.split("."),s=t,a=n(o.slice(0,-1));try{for(a.s();!(i=a.n()).done;){var u=i.value;null==s[u]&&(s[u]={}),s=s[u]}}catch(t){a.e(t)}finally{a.f()}s[o[o.length-1]]=r}},function(t,e,r){"use strict";var n=r(6),i=r(171);
|
package/index.d.ts
CHANGED
|
@@ -2116,6 +2116,8 @@ declare module 'mongoose' {
|
|
|
2116
2116
|
|
|
2117
2117
|
type QueryWithHelpers<ResultType, DocType, THelpers = {}, RawDocType = DocType> = Query<ResultType, DocType, THelpers, RawDocType> & THelpers;
|
|
2118
2118
|
|
|
2119
|
+
type UnpackedIntersection<T, U> = T extends (infer V)[] ? (V & U)[] : T & U;
|
|
2120
|
+
|
|
2119
2121
|
class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
|
|
2120
2122
|
_mongooseOptions: MongooseQueryOptions;
|
|
2121
2123
|
|
|
@@ -2398,8 +2400,8 @@ declare module 'mongoose' {
|
|
|
2398
2400
|
polygon(path: string, ...coordinatePairs: number[][]): this;
|
|
2399
2401
|
|
|
2400
2402
|
/** Specifies paths which should be populated with other documents. */
|
|
2401
|
-
populate<Paths = {}>(path: string | any, select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<ResultType
|
|
2402
|
-
populate<Paths = {}>(options: PopulateOptions | Array<PopulateOptions>): QueryWithHelpers<ResultType
|
|
2403
|
+
populate<Paths = {}>(path: string | any, select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>;
|
|
2404
|
+
populate<Paths = {}>(options: PopulateOptions | Array<PopulateOptions>): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>;
|
|
2403
2405
|
|
|
2404
2406
|
/** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
|
|
2405
2407
|
projection(fields?: any | null): any;
|
|
@@ -3099,7 +3101,7 @@ declare module 'mongoose' {
|
|
|
3099
3101
|
into: string | { db: string; coll: string }
|
|
3100
3102
|
on?: string | string[]
|
|
3101
3103
|
let?: Record<string, any>
|
|
3102
|
-
whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' |
|
|
3104
|
+
whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' | Extract<PipelineStage, PipelineStage.AddFields | PipelineStage.Set | PipelineStage.Project | PipelineStage.Unset | PipelineStage.ReplaceRoot | PipelineStage.ReplaceWith>[]
|
|
3103
3105
|
whenNotMatched?: 'insert' | 'discard' | 'fail'
|
|
3104
3106
|
}
|
|
3105
3107
|
}
|
package/lib/connection.js
CHANGED
|
@@ -43,10 +43,10 @@ const noPasswordAuthMechanisms = [
|
|
|
43
43
|
* @inherits NodeJS EventEmitter http://nodejs.org/api/events.html#events_class_events_eventemitter
|
|
44
44
|
* @event `connecting`: Emitted when `connection.openUri()` is executed on this connection.
|
|
45
45
|
* @event `connected`: Emitted when this connection successfully connects to the db. May be emitted _multiple_ times in `reconnected` scenarios.
|
|
46
|
-
* @event `open`: Emitted after we `connected` and `onOpen` is executed on all of this
|
|
46
|
+
* @event `open`: Emitted after we `connected` and `onOpen` is executed on all of this connection's models.
|
|
47
47
|
* @event `disconnecting`: Emitted when `connection.close()` was executed.
|
|
48
48
|
* @event `disconnected`: Emitted after getting disconnected from the db.
|
|
49
|
-
* @event `close`: Emitted after we `disconnected` and `onClose` executed on all of this
|
|
49
|
+
* @event `close`: Emitted after we `disconnected` and `onClose` executed on all of this connection's models.
|
|
50
50
|
* @event `reconnected`: Emitted after we `connected` and subsequently `disconnected`, followed by successfully another successful connection.
|
|
51
51
|
* @event `error`: Emitted when an error occurs on this connection.
|
|
52
52
|
* @event `fullsetup`: Emitted after the driver has connected to primary and all secondaries if specified in the connection string.
|
package/lib/document.js
CHANGED
|
@@ -1145,13 +1145,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1145
1145
|
}
|
|
1146
1146
|
|
|
1147
1147
|
if (pathtype === 'real' || pathtype === 'virtual') {
|
|
1148
|
-
|
|
1149
|
-
let p = path[key];
|
|
1150
|
-
if (this.$__schema.paths[pathName] &&
|
|
1151
|
-
this.$__schema.paths[pathName].$isSingleNested &&
|
|
1152
|
-
path[key] instanceof Document) {
|
|
1153
|
-
p = p.toObject({ virtuals: false, transform: false });
|
|
1154
|
-
}
|
|
1148
|
+
const p = path[key];
|
|
1155
1149
|
this.$set(prefix + key, p, constructing, options);
|
|
1156
1150
|
} else if (pathtype === 'nested' && path[key] instanceof Document) {
|
|
1157
1151
|
this.$set(prefix + key,
|
|
@@ -1412,7 +1406,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
1412
1406
|
didPopulate = true;
|
|
1413
1407
|
}
|
|
1414
1408
|
|
|
1415
|
-
if (this.$__schema.singleNestedPaths[path] == null) {
|
|
1409
|
+
if (this.$__schema.singleNestedPaths[path] == null && (!refMatches || !schema.$isSingleNested || !val.$__)) {
|
|
1416
1410
|
// If this path is underneath a single nested schema, we'll call the setter
|
|
1417
1411
|
// later in `$__set()` because we don't take `_doc` when we iterate through
|
|
1418
1412
|
// a single nested doc. That's to make sure we get the correct context.
|
package/lib/helpers/common.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.modifiedPaths = modifiedPaths;
|
|
|
19
19
|
function flatten(update, path, options, schema) {
|
|
20
20
|
let keys;
|
|
21
21
|
if (update && isMongooseObject(update) && !Buffer.isBuffer(update)) {
|
|
22
|
-
keys = Object.keys(update.toObject({ transform: false, virtuals: false }));
|
|
22
|
+
keys = Object.keys(update.toObject({ transform: false, virtuals: false }) || {});
|
|
23
23
|
} else {
|
|
24
24
|
keys = Object.keys(update || {});
|
|
25
25
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const MongooseError = require('../../error/mongooseError');
|
|
4
4
|
const isPathExcluded = require('../projection/isPathExcluded');
|
|
5
|
+
const lookupLocalFields = require('./lookupLocalFields');
|
|
6
|
+
const mpath = require('mpath');
|
|
5
7
|
const util = require('util');
|
|
6
8
|
const utils = require('../../utils');
|
|
7
9
|
|
|
@@ -44,13 +46,13 @@ module.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, mod
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
const refValue =
|
|
49
|
+
const refValue = mpath.get(_refPath, doc, lookupLocalFields);
|
|
48
50
|
let modelNames = Array.isArray(refValue) ? refValue : [refValue];
|
|
49
51
|
modelNames = utils.array.flatten(modelNames);
|
|
50
52
|
return modelNames;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
const refValue =
|
|
55
|
+
const refValue = mpath.get(refPath, doc, lookupLocalFields);
|
|
54
56
|
|
|
55
57
|
let modelNames;
|
|
56
58
|
if (modelSchema != null && modelSchema.virtuals.hasOwnProperty(refPath)) {
|
|
@@ -49,7 +49,7 @@ module.exports = function setupTimestamps(schema, timestamps) {
|
|
|
49
49
|
this.ownerDocument().constructor.base.now();
|
|
50
50
|
const auto_id = this._id && this._id.auto;
|
|
51
51
|
|
|
52
|
-
if (!skipCreatedAt && createdAt && !this.$__getValue(createdAt) && this.$__isSelected(createdAt)) {
|
|
52
|
+
if (!skipCreatedAt && this.isNew && createdAt && !this.$__getValue(createdAt) && this.$__isSelected(createdAt)) {
|
|
53
53
|
this.$set(createdAt, auto_id ? this._id.getTimestamp() : defaultTimestamp);
|
|
54
54
|
}
|
|
55
55
|
|
package/lib/index.js
CHANGED
|
@@ -121,6 +121,15 @@ Mongoose.prototype.cast = cast;
|
|
|
121
121
|
*/
|
|
122
122
|
Mongoose.prototype.STATES = STATES;
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Expose connection states for user-land
|
|
126
|
+
*
|
|
127
|
+
* @memberOf Mongoose
|
|
128
|
+
* @property ConnectionStates
|
|
129
|
+
* @api public
|
|
130
|
+
*/
|
|
131
|
+
Mongoose.prototype.ConnectionStates = STATES;
|
|
132
|
+
|
|
124
133
|
/**
|
|
125
134
|
* Object with `get()` and `set()` containing the underlying driver this Mongoose instance
|
|
126
135
|
* uses to communicate with the database. A driver is a Mongoose-specific interface that defines functions
|
package/lib/model.js
CHANGED
|
@@ -2623,6 +2623,10 @@ function _decorateUpdateWithVersionKey(update, options, versionKey) {
|
|
|
2623
2623
|
*
|
|
2624
2624
|
* ####Note:
|
|
2625
2625
|
*
|
|
2626
|
+
* If id is undefined and update is specified, an error will be thrown.
|
|
2627
|
+
*
|
|
2628
|
+
* ####Note:
|
|
2629
|
+
*
|
|
2626
2630
|
* All top level update keys which are not `atomic` operation names are treated as set operations:
|
|
2627
2631
|
*
|
|
2628
2632
|
* ####Example:
|
|
@@ -2677,6 +2681,9 @@ Model.findByIdAndUpdate = function(id, update, options, callback) {
|
|
|
2677
2681
|
throw new TypeError(msg);
|
|
2678
2682
|
}
|
|
2679
2683
|
return this.findOneAndUpdate({ _id: id }, undefined);
|
|
2684
|
+
} else if (arguments.length > 1 && id === undefined) {
|
|
2685
|
+
const msg = 'Model.findByIdAndUpdate(): id cannot be undefined if update is specified.';
|
|
2686
|
+
throw new TypeError(msg);
|
|
2680
2687
|
}
|
|
2681
2688
|
|
|
2682
2689
|
// if a model is passed in instead of an id
|
|
@@ -239,10 +239,11 @@ SubdocumentPath.prototype.castForQuery = function($conditional, val, options) {
|
|
|
239
239
|
SubdocumentPath.prototype.doValidate = function(value, fn, scope, options) {
|
|
240
240
|
const Constructor = getConstructor(this.caster, value);
|
|
241
241
|
|
|
242
|
+
if (value && !(value instanceof Constructor)) {
|
|
243
|
+
value = new Constructor(value, null, scope);
|
|
244
|
+
}
|
|
245
|
+
|
|
242
246
|
if (options && options.skipSchemaValidators) {
|
|
243
|
-
if (!(value instanceof Constructor)) {
|
|
244
|
-
value = new Constructor(value, null, scope);
|
|
245
|
-
}
|
|
246
247
|
return value.validate(fn);
|
|
247
248
|
}
|
|
248
249
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.1.
|
|
4
|
+
"version": "6.1.4",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"bson": "^4.2.2",
|
|
23
|
-
"kareem": "2.3.
|
|
23
|
+
"kareem": "2.3.3",
|
|
24
24
|
"mongodb": "4.2.2",
|
|
25
25
|
"mpath": "0.8.4",
|
|
26
26
|
"mquery": "4.0.0",
|