mongoose 6.0.4 → 6.0.5
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 +5 -5
- package/index.d.ts +20 -11
- package/lib/cast.js +5 -0
- package/lib/document.js +2 -2
- package/lib/helpers/populate/assignVals.js +3 -0
- package/lib/helpers/populate/lookupLocalFields.js +3 -0
- package/lib/helpers/setDefaultsOnInsert.js +3 -0
- package/lib/model.js +6 -0
- package/lib/schema/number.js +11 -4
- package/lib/types/array/index.js +1 -1
- package/lib/types/map.js +1 -1
- package/package.json +22 -20
package/dist/browser.umd.js
CHANGED
|
@@ -405,7 +405,7 @@ function t(e){var r,i,n,o=Object.keys(e),s=o.length;for(;s--;)i=o[s],n=e[i],q.is
|
|
|
405
405
|
/*!
|
|
406
406
|
* Avoid Node deprecation warning DEP0079
|
|
407
407
|
*/
|
|
408
|
-
rt.prototype[I.custom]=rt.prototype.inspect),rt.prototype.toString=function(){var t=this.inspect();return"string"==typeof t?t:I(t)},rt.prototype.equals=function(t){if(!t)return!1;var e=this.$__getValue("_id"),r=null!=t.$__?t.$__getValue("_id"):t;return e||r?e&&e.equals?e.equals(r):e===r:z(this,t)},rt.prototype.populate=function(){var t,e={},r=q.args(arguments);if(r.length>0){"function"==typeof r[r.length-1]&&(t=r.pop());var i,o=q.populate.apply(null,r),s=n(o);try{for(s.s();!(i=s.n()).done;){var a=i.value;e[a.path]=a}}catch(t){s.e(t)}finally{s.f()}}var u=q.object.vals(e),h=this.constructor;if(this.$__isNested){h=this.$__[X].constructor;var f=this.$__.nestedPath;u.forEach((function(t){t.path=f+"."+t.path}))}if(null!=this.$session()){var c=this.$session();u.forEach((function(t){null!=t.options?"session"in t.options||(t.options.session=c):t.options={session:c}}))}return u.forEach((function(t){t._localModel=h})),h.populate(this,u,t)},rt.prototype.$getPopulatedDocs=function(){var t=[];null!=this.$__.populated&&(t=t.concat(Object.keys(this.$__.populated)));var e,r=[],i=n(t);try{for(i.s();!(e=i.n()).done;){var o=e.value,s=this.$get(o);Array.isArray(s)?r=r.concat(s):s instanceof rt&&r.push(s)}}catch(t){i.e(t)}finally{i.f()}return r},rt.prototype.populated=function(t,e,r){if(null==e||!0===e){if(!this.$__.populated)return;var i=t.endsWith(".$*")?t.replace(/\.\$\*$/,""):t,n=this.$__.populated[i];return n?!0===e?n:n.value:void 0}this.$__.populated||(this.$__.populated={}),this.$__.populated[t]={value:e,options:r};for(var o=t.split("."),s=0;s<o.length-1;++s){var a=o.slice(0,s+1).join("."),u=this.$get(a);if(null!=u&&null!=u.$__&&this.$populated(a)){var h=o.slice(s+1).join(".");u.$populated(h,e,r);break}}return e},rt.prototype.$populated=rt.prototype.populated,rt.prototype.depopulate=function(t){var e;"string"==typeof t&&(t=t.split(" "));var r=this.$$populatedVirtuals?Object.keys(this.$$populatedVirtuals):[],i=k(this,"$__.populated",{});if(0===arguments.length){var o,s=n(r);try{for(s.s();!(o=s.n()).done;){var a=o.value;delete this.$$populatedVirtuals[a],delete this._doc[a],delete i[a]}}catch(t){s.e(t)}finally{s.f()}for(var u=Object.keys(i),h=0,f=u;h<f.length;h++){var c=f[h];(e=this.$populated(c))&&(delete i[c],
|
|
408
|
+
rt.prototype[I.custom]=rt.prototype.inspect),rt.prototype.toString=function(){var t=this.inspect();return"string"==typeof t?t:I(t)},rt.prototype.equals=function(t){if(!t)return!1;var e=this.$__getValue("_id"),r=null!=t.$__?t.$__getValue("_id"):t;return e||r?e&&e.equals?e.equals(r):e===r:z(this,t)},rt.prototype.populate=function(){var t,e={},r=q.args(arguments);if(r.length>0){"function"==typeof r[r.length-1]&&(t=r.pop());var i,o=q.populate.apply(null,r),s=n(o);try{for(s.s();!(i=s.n()).done;){var a=i.value;e[a.path]=a}}catch(t){s.e(t)}finally{s.f()}}var u=q.object.vals(e),h=this.constructor;if(this.$__isNested){h=this.$__[X].constructor;var f=this.$__.nestedPath;u.forEach((function(t){t.path=f+"."+t.path}))}if(null!=this.$session()){var c=this.$session();u.forEach((function(t){null!=t.options?"session"in t.options||(t.options.session=c):t.options={session:c}}))}return u.forEach((function(t){t._localModel=h})),h.populate(this,u,t)},rt.prototype.$getPopulatedDocs=function(){var t=[];null!=this.$__.populated&&(t=t.concat(Object.keys(this.$__.populated)));var e,r=[],i=n(t);try{for(i.s();!(e=i.n()).done;){var o=e.value,s=this.$get(o);Array.isArray(s)?r=r.concat(s):s instanceof rt&&r.push(s)}}catch(t){i.e(t)}finally{i.f()}return r},rt.prototype.populated=function(t,e,r){if(null==e||!0===e){if(!this.$__.populated)return;var i=t.endsWith(".$*")?t.replace(/\.\$\*$/,""):t,n=this.$__.populated[i];return n?!0===e?n:n.value:void 0}this.$__.populated||(this.$__.populated={}),this.$__.populated[t]={value:e,options:r};for(var o=t.split("."),s=0;s<o.length-1;++s){var a=o.slice(0,s+1).join("."),u=this.$get(a);if(null!=u&&null!=u.$__&&this.$populated(a)){var h=o.slice(s+1).join(".");u.$populated(h,e,r);break}}return e},rt.prototype.$populated=rt.prototype.populated,rt.prototype.depopulate=function(t){var e;"string"==typeof t&&(t=t.split(" "));var r=this.$$populatedVirtuals?Object.keys(this.$$populatedVirtuals):[],i=k(this,"$__.populated",{});if(0===arguments.length){var o,s=n(r);try{for(s.s();!(o=s.n()).done;){var a=o.value;delete this.$$populatedVirtuals[a],delete this._doc[a],delete i[a]}}catch(t){s.e(t)}finally{s.f()}for(var u=Object.keys(i),h=0,f=u;h<f.length;h++){var c=f[h];(e=this.$populated(c))&&(delete i[c],q.setValue(c,e,this._doc))}return this}var l,d=n(t);try{for(d.s();!(l=d.n()).done;){var p=l.value;e=this.$populated(p),delete i[p],-1!==r.indexOf(p)?(delete this.$$populatedVirtuals[p],delete this._doc[p]):e&&q.setValue(p,e,this._doc)}}catch(t){d.e(t)}finally{d.f()}return this},rt.prototype.$__fullPath=function(t){return t||""},rt.prototype.getChanges=function(){var t=this.$__delta();return t?t[1]:{}},
|
|
409
409
|
/*!
|
|
410
410
|
* Module exports.
|
|
411
411
|
*/
|
|
@@ -919,7 +919,7 @@ f.prototype=Object.create(o.prototype),f.prototype.constructor=f,f.prototype.Opt
|
|
|
919
919
|
/*!
|
|
920
920
|
* ignore
|
|
921
921
|
*/
|
|
922
|
-
f._checkRequired=function(t){return"number"==typeof t||t instanceof Number},f.checkRequired=o.checkRequired,f.prototype.checkRequired=function(t,e){return o._isRef(this,t,e,!0)?!!t:("function"==typeof this.constructor.checkRequired?this.constructor.checkRequired():f.checkRequired())(t)},f.prototype.min=function(t,e){if(this.minValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.minValidator}),this)),null!=t){var r=e||i.messages.Number.min;r=r.replace(/{MIN}/,t),this.validators.push({validator:this.minValidator=function(e){return null==e||e>=t},message:r,type:"min",min:t})}return this},f.prototype.max=function(t,e){if(this.maxValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.maxValidator}),this)),null!=t){var r=e||i.messages.Number.max;r=r.replace(/{MAX}/,t),this.validators.push({validator:this.maxValidator=function(e){return null==e||e<=t},message:r,type:"max",max:t})}return this},f.prototype.enum=function(t,e){
|
|
922
|
+
f._checkRequired=function(t){return"number"==typeof t||t instanceof Number},f.checkRequired=o.checkRequired,f.prototype.checkRequired=function(t,e){return o._isRef(this,t,e,!0)?!!t:("function"==typeof this.constructor.checkRequired?this.constructor.checkRequired():f.checkRequired())(t)},f.prototype.min=function(t,e){if(this.minValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.minValidator}),this)),null!=t){var r=e||i.messages.Number.min;r=r.replace(/{MIN}/,t),this.validators.push({validator:this.minValidator=function(e){return null==e||e>=t},message:r,type:"min",min:t})}return this},f.prototype.max=function(t,e){if(this.maxValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.maxValidator}),this)),null!=t){var r=e||i.messages.Number.max;r=r.replace(/{MAX}/,t),this.validators.push({validator:this.maxValidator=function(e){return null==e||e<=t},message:r,type:"max",max:t})}return this},f.prototype.enum=function(t,e){if(this.enumValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.enumValidator}),this)),!Array.isArray(t)){var r=u.isPOJO(t)&&null!=t.values;r?(e=t.message,t=t.values):"number"==typeof t&&(t=Array.prototype.slice.call(arguments),e=null),u.isPOJO(t)&&(t=Object.values(t)),e=e||i.messages.Number.enum}return e=null==e?i.messages.Number.enum:e,this.enumValidator=function(e){return null==e||-1!==t.indexOf(e)},this.validators.push({validator:this.enumValidator,message:e,type:"enum",enumValues:t}),this},f.prototype.cast=function(t,e,r){if(o._isRef(this,t,e,r))return"number"==typeof t?t:this._castRef(t,e,r);var i,n=t&&void 0!==t._id?t._id:t;i="function"==typeof this._castFunction?this._castFunction:"function"==typeof this.constructor.cast?this.constructor.cast():f.cast();try{return i(n)}catch(t){throw new h("Number",n,this.path,t,this)}},f.prototype.$conditionalHandlers=u.options(o.prototype.$conditionalHandlers,{$bitsAllClear:a,$bitsAnyClear:a,$bitsAllSet:a,$bitsAnySet:a,$gt:c,$gte:c,$lt:c,$lte:c,$mod:function(t){var e=this;return Array.isArray(t)?t.map((function(t){return e.cast(t)})):[this.cast(t)]}}),f.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new h("number",e,this.path,null,this);return r.call(this,e)}return e=this._castForQuery(t)},
|
|
923
923
|
/*!
|
|
924
924
|
* Module exports.
|
|
925
925
|
*/
|
|
@@ -948,7 +948,7 @@ e.cast$geoIntersects=function(t){if(!t.$geometry)return;return o(t,this),t},e.ca
|
|
|
948
948
|
/*!
|
|
949
949
|
* Module exports.
|
|
950
950
|
*/
|
|
951
|
-
t.exports=function(t,e,r,c){var l,d=t,p=(i(l={},s,{}),i(l,a,void 0),i(l,h,e),i(l,f,
|
|
951
|
+
t.exports=function(t,e,r,c){var l,d=t,p=(i(l={},s,{}),i(l,a,void 0),i(l,h,e),i(l,f,c),i(l,u,void 0),i(l,"isMongooseArray",!0),i(l,"isMongooseArrayProxy",!0),i(l,"__array",d),l);null!=t[s]&&(p[s]=t[s]),null!=r&&r instanceof n&&(p[u]=r,p[f]=c||r.schema.path(e));var m=new Proxy(d,{get:function(t,e){return p.hasOwnProperty(e)?p[e]:o.hasOwnProperty(e)?o[e]:d[e]},set:function(t,e,r){if("string"==typeof e&&/^\d+$/.test(e)){var i=o._cast.call(m,r,e);d[e]=i,o._markModified.call(m,e)}else p.hasOwnProperty(e)?p[e]=r:d[e]=r;return!0}});return m}},function(t,e,r){"use strict";
|
|
952
952
|
/*!
|
|
953
953
|
* ignore
|
|
954
954
|
*/t.exports=function(t,e,r){var i=(r=r||{}).skipDocArrays,n=0;if(!t)return n;for(var o=0,s=Object.keys(t.$__.activePaths.states.modify);o<s.length;o++){var a=s[o];if(i){var u=t.$__schema.path(a);if(u&&u.$isMongooseDocumentArray)continue}a.startsWith(e+".")&&(delete t.$__.activePaths.states.modify[a],++n)}return n}},function(t,e,r){"use strict";(function(e){
|
|
@@ -967,7 +967,7 @@ o.mixin={_subtype:void 0,_markModified:function(){var t=this[a];return t&&t.mark
|
|
|
967
967
|
/*!
|
|
968
968
|
* Module exports.
|
|
969
969
|
*/
|
|
970
|
-
o.Binary=i,t.exports=o}).call(this,r(3).Buffer)},function(t,e,r){"use strict";var i=r(24).get().ObjectId,n=r(33);t.exports=function(t){if(null==t)return t;if(t instanceof i)return t;if(t._id){if(t._id instanceof i)return t._id;if(t._id.toString instanceof Function)return new i(t._id.toString())}if(t.toString instanceof Function)return new i(t.toString());n.ok(!1)}},function(t,e,r){"use strict";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 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 o(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 o(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0,n=function(){};return{s:n,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:n}}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 o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}function s(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function a(t,e,r){return(a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=d(t)););return t}(t,e);if(i){var n=Object.getOwnPropertyDescriptor(i,e);return n.get?n.get.call(r):n.value}})(t,e,r||t)}function u(t,e){if(e&&("object"===i(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function h(t){var e="function"==typeof Map?new Map:void 0;return(h=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return f(t,arguments,d(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),l(i,t)})(t)}function f(t,e,r){return(f=c()?Reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var n=new(Function.bind.apply(t,i));return r&&l(n,r.prototype),n}).apply(null,arguments)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function l(t,e){return(l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function d(t){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=r(44),m=r(18),y=r(42),v=r(4).deepEqual,b=r(5),g=r(34),w=r(171),_=r(10),M=r(82),S=r(1).populateModelSymbol,O=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&l(t,e)}(_,t);var e,r,i,o,h,f=(e=_,r=c(),function(){var t,i=d(e);if(r){var n=d(this).constructor;t=Reflect.construct(i,arguments,n)}else t=i.apply(this,arguments);return u(this,t)});function _(t,e,r,i){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,_),"Object"===g(t)&&(t=Object.keys(t).reduce((function(e,r){return e.concat([[r,t[r]]])}),[])),(n=f.call(this,t)).$__parent=null!=r&&null!=r.$__?r:null,n.$__path=e,n.$__schemaType=null==i?new p(e):i,n.$__runDeferred(),n}return i=_,(o=[{key:"$init",value:function(t,e){A(t),a(d(_.prototype),"set",this).call(this,t,e),null!=e&&e.$isSingleNested&&(e.$basePath=this.$__path+"."+t)}},{key:"$__set",value:function(t,e){a(d(_.prototype),"set",this).call(this,t,e)}},{key:"get",value:function(t,e){return t instanceof m&&(t=t.toString()),!1===(e=e||{}).getters?a(d(_.prototype),"get",this).call(this,t):this.$__schemaType.applyGetters(a(d(_.prototype),"get",this).call(this,t),this.$__parent)}},{key:"set",value:function(t,e){if(t instanceof m&&(t=t.toString()),A(t),e=w(e),null==this.$__schemaType)return this.$__deferred=this.$__deferred||[],void this.$__deferred.push({key:t,value:e});var r=this.$__path+"."+t,i=null!=this.$__parent&&this.$__parent.$__?this.$__parent.$populated(r)||this.$__parent.$populated(this.$__path):null,n=this.get(t);if(null!=i)null==e.$__&&(e=new i.options[S](e)),e.$__.wasPopulated=!0;else try{e=this.$__schemaType.applySetters(e,this.$__parent,!1,this.get(t),{path:r})}catch(t){if(null!=this.$__parent&&null!=this.$__parent.$__)return void this.$__parent.invalidate(r,t);throw t}a(d(_.prototype),"set",this).call(this,t,e),null!=e&&e.$isSingleNested&&(e.$basePath=this.$__path+"."+t);var o=this.$__parent;null==o||null==o.$__||v(e,n)||o.markModified(this.$__path+"."+t)}},{key:"clear",value:function(){a(d(_.prototype),"clear",this).call(this);var t=this.$__parent;null!=t&&t.markModified(this.$__path)}},{key:"delete",value:function(t){t instanceof m&&(t=t.toString()),this.set(t,void 0),a(d(_.prototype),"delete",this).call(this,t)}},{key:"toBSON",value:function(){return new Map(this)}},{key:"toObject",value:function(t){if(b(t,"flattenMaps")){var e,r={},i=n(this.keys());try{for(i.s();!(e=i.n()).done;){var o=e.value;r[o]=y(this.get(o))}}catch(t){i.e(t)}finally{i.f()}return r}return new Map(this)}},{key:"$toObject",value:function(){return this.constructor.prototype.toObject.apply(this,arguments)}},{key:"toJSON",value:function(){var t,e={},r=n(this.keys());try{for(r.s();!(t=r.n()).done;){var i=t.value;e[i]=this.get(i)}}catch(t){r.e(t)}finally{r.f()}return e}},{key:"inspect",value:function(){return new Map(this)}},{key:"$__runDeferred",value:function(){if(this.$__deferred){var t,e=n(this.$__deferred);try{for(e.s();!(t=e.n()).done;){var r=t.value;this.set(r.key,r.value)}}catch(t){e.e(t)}finally{e.f()}this.$__deferred=null}}}])&&s(i.prototype,o),h&&s(i,h),_}(h(Map));
|
|
970
|
+
o.Binary=i,t.exports=o}).call(this,r(3).Buffer)},function(t,e,r){"use strict";var i=r(24).get().ObjectId,n=r(33);t.exports=function(t){if(null==t)return t;if(t instanceof i)return t;if(t._id){if(t._id instanceof i)return t._id;if(t._id.toString instanceof Function)return new i(t._id.toString())}if(t.toString instanceof Function)return new i(t.toString());n.ok(!1)}},function(t,e,r){"use strict";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 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 o(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 o(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0,n=function(){};return{s:n,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:n}}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 o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}function s(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function a(t,e,r){return(a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=d(t)););return t}(t,e);if(i){var n=Object.getOwnPropertyDescriptor(i,e);return n.get?n.get.call(r):n.value}})(t,e,r||t)}function u(t,e){if(e&&("object"===i(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function h(t){var e="function"==typeof Map?new Map:void 0;return(h=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return f(t,arguments,d(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),l(i,t)})(t)}function f(t,e,r){return(f=c()?Reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var n=new(Function.bind.apply(t,i));return r&&l(n,r.prototype),n}).apply(null,arguments)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function l(t,e){return(l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function d(t){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=r(44),m=r(18),y=r(42),v=r(4).deepEqual,b=r(5),g=r(34),w=r(171),_=r(10),M=r(82),S=r(1).populateModelSymbol,O=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&l(t,e)}(_,t);var e,r,i,o,h,f=(e=_,r=c(),function(){var t,i=d(e);if(r){var n=d(this).constructor;t=Reflect.construct(i,arguments,n)}else t=i.apply(this,arguments);return u(this,t)});function _(t,e,r,i){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,_),"Object"===g(t)&&(t=Object.keys(t).reduce((function(e,r){return e.concat([[r,t[r]]])}),[])),(n=f.call(this,t)).$__parent=null!=r&&null!=r.$__?r:null,n.$__path=e,n.$__schemaType=null==i?new p(e):i,n.$__runDeferred(),n}return i=_,(o=[{key:"$init",value:function(t,e){A(t),a(d(_.prototype),"set",this).call(this,t,e),null!=e&&e.$isSingleNested&&(e.$basePath=this.$__path+"."+t)}},{key:"$__set",value:function(t,e){a(d(_.prototype),"set",this).call(this,t,e)}},{key:"get",value:function(t,e){return t instanceof m&&(t=t.toString()),!1===(e=e||{}).getters?a(d(_.prototype),"get",this).call(this,t):this.$__schemaType.applyGetters(a(d(_.prototype),"get",this).call(this,t),this.$__parent)}},{key:"set",value:function(t,e){if(t instanceof m&&(t=t.toString()),A(t),e=w(e),null==this.$__schemaType)return this.$__deferred=this.$__deferred||[],void this.$__deferred.push({key:t,value:e});var r=this.$__path+"."+t,i=null!=this.$__parent&&this.$__parent.$__?this.$__parent.$populated(r)||this.$__parent.$populated(this.$__path):null,n=this.get(t);if(null!=i)null==e.$__&&(e=new i.options[S](e)),e.$__.wasPopulated=!0;else try{e=this.$__schemaType.applySetters(e,this.$__parent,!1,this.get(t),{path:r})}catch(t){if(null!=this.$__parent&&null!=this.$__parent.$__)return void this.$__parent.invalidate(r,t);throw t}a(d(_.prototype),"set",this).call(this,t,e),null!=e&&e.$isSingleNested&&(e.$basePath=this.$__path+"."+t);var o=this.$__parent;null==o||null==o.$__||v(e,n)||o.markModified(this.$__path+"."+t)}},{key:"clear",value:function(){a(d(_.prototype),"clear",this).call(this);var t=this.$__parent;null!=t&&t.markModified(this.$__path)}},{key:"delete",value:function(t){t instanceof m&&(t=t.toString()),this.set(t,void 0),a(d(_.prototype),"delete",this).call(this,t)}},{key:"toBSON",value:function(){return new Map(this)}},{key:"toObject",value:function(t){if(b(t,"flattenMaps")){var e,r={},i=n(this.keys());try{for(i.s();!(e=i.n()).done;){var o=e.value;r[o]=y(this.get(o),t)}}catch(t){i.e(t)}finally{i.f()}return r}return new Map(this)}},{key:"$toObject",value:function(){return this.constructor.prototype.toObject.apply(this,arguments)}},{key:"toJSON",value:function(){var t,e={},r=n(this.keys());try{for(r.s();!(t=r.n()).done;){var i=t.value;e[i]=this.get(i)}}catch(t){r.e(t)}finally{r.f()}return e}},{key:"inspect",value:function(){return new Map(this)}},{key:"$__runDeferred",value:function(){if(this.$__deferred){var t,e=n(this.$__deferred);try{for(e.s();!(t=e.n()).done;){var r=t.value;this.set(r.key,r.value)}}catch(t){e.e(t)}finally{e.f()}this.$__deferred=null}}}])&&s(i.prototype,o),h&&s(i,h),_}(h(Map));
|
|
971
971
|
/*!
|
|
972
972
|
* Since maps are stored as objects under the hood, keys must be strings
|
|
973
973
|
* and can't contain any invalid characters
|
|
@@ -1366,7 +1366,7 @@ t.exports=g},function(t,e,r){"use strict";function i(t){return(i="function"==typ
|
|
|
1366
1366
|
t.exports=h},function(t,e,r){"use strict";t.exports=function t(e){if(!Array.isArray(e))return{min:0,max:0,containsNonArrayItem:!0};if(0===e.length)return{min:1,max:1,containsNonArrayItem:!1};if(1===e.length&&!Array.isArray(e[0]))return{min:1,max:1,containsNonArrayItem:!1};for(var r=t(e[0]),i=1;i<e.length;++i){var n=t(e[i]);n.min<r.min&&(r.min=n.min),n.max>r.max&&(r.max=n.max),r.containsNonArrayItem=r.containsNonArrayItem||n.containsNonArrayItem}return r.min=r.min+1,r.max=r.max+1,r}},function(t,e,r){"use strict";
|
|
1367
1367
|
/*!
|
|
1368
1368
|
* Module dependencies.
|
|
1369
|
-
*/function i(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,i=new Array(e);r<e;r++)i[r]=t[r];return i}function o(t){return(o="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 s=r(20),a=r(54),u=r(87),h=r(318),f=r(5),c=r(34),l=r(319),d=r(164),p=r(10),m=r(32),y=r(51),v=["Polygon","MultiPolygon"];function b(t,e,r){if(Array.isArray(t))t.forEach((function(i,n){if(Array.isArray(i)||m(i))return b(i,e,r);t[n]=e.castForQueryWrapper({val:i,context:r})}));else for(var i=Object.keys(t),n=i.length;n--;){var o=i[n],s=t[o];Array.isArray(s)||m(s)?(b(s,e,r),t[o]=s):t[o]=e.castForQuery({val:s,context:r})}}t.exports=function t(e,r,n,g){if(Array.isArray(r))throw new Error("Query filter must be an object, got an array ",p.inspect(r));if(null==r)return r;r.hasOwnProperty("_bsontype")&&"ObjectID"!==r._bsontype&&delete r._bsontype,null!=e&&null!=e.discriminators&&null!=r[e.options.discriminatorKey]&&(e=l(e,r[e.options.discriminatorKey])||e);var w,_,M,S,O,A,E=Object.keys(r),x=E.length;for(n=n||{};x--;)if(A=r[S=E[x]],"$or"===S||"$nor"===S||"$and"===S){if(!Array.isArray(A))throw new s("Array",A,S);for(var k=0;k<A.length;++k){if(null==A[k]||"object"!==o(A[k]))throw new s("Object",A[k],S+"."+k);A[k]=t(e,A[k],n,g)}}else{if("$where"===S){if("string"!==(O=o(A))&&"function"!==O)throw new Error("Must have a string or function for $where");"function"===O&&(r[S]=A.toString());continue}if("$elemMatch"===S)A=t(e,A,n,g);else if("$text"===S)A=h(A,S);else{if(!e)continue;if(!(_=e.path(S)))for(var j=S.split("."),$=j.length;$--;){var P=j.slice(0,$).join("."),R=j.slice($).join("."),B=e.path(P),T=f(B,"schema.options.discriminatorKey");if(null!=B&&null!=f(B,"schema.discriminators")&&null!=T&&R!==T){var I=f(r,P+"."+T);null!=I&&(_=B.schema.discriminators[I].path(R))}}if(_){if(null==A)continue;if("Object"===c(A))if(Object.keys(A).some(d))for(var N=Object.keys(A),D=void 0,C=N.length;C--;)if(M=A[D=N[C]],"$not"===D){if(M&&_&&!_.caster){if((w=Object.keys(M)).length&&d(w[0]))for(var L in M)M[L]=_.castForQueryWrapper({$conditional:L,val:M[L],context:g});else A[D]=_.castForQueryWrapper({$conditional:D,val:M,context:g});continue}t(_.caster?_.caster.schema:e,M,n,g)}else A[D]=_.castForQueryWrapper({$conditional:D,val:M,context:g});else r[S]=_.castForQueryWrapper({val:A,context:g});else if(Array.isArray(A)&&-1===["Buffer","Array"].indexOf(_.instance)){var q,U=[],F=i(A);try{for(F.s();!(q=F.n()).done;){var z=q.value;U.push(_.castForQueryWrapper({val:z,context:g}))}}catch(t){F.e(t)}finally{F.f()}r[S]={$in:U}}else r[S]=_.castForQueryWrapper({val:A,context:g})}else{for(var V=S.split("."),K=V.length,H=void 0,Z=void 0,W=void 0;K--&&(H=V.slice(0,K).join("."),!(_=e.path(H))););if(_){_.caster&&_.caster.schema?((W={})[Z=V.slice(K).join(".")]=A,r[S]=t(_.caster.schema,W,n,g)[Z]):r[S]=A;continue}if(m(A)){var J="";if(A.$near?J="$near":A.$nearSphere?J="$nearSphere":A.$within?J="$within":A.$geoIntersects?J="$geoIntersects":A.$geoWithin&&(J="$geoWithin"),J){var Y=new u.Number("__QueryCasting__"),G=A[J];if(null!=A.$maxDistance&&(A.$maxDistance=Y.castForQueryWrapper({val:A.$maxDistance,context:g})),null!=A.$minDistance&&(A.$minDistance=Y.castForQueryWrapper({val:A.$minDistance,context:g})),"$within"===J){var Q=G.$center||G.$centerSphere||G.$box||G.$polygon;if(!Q)throw new Error("Bad $within parameter: "+JSON.stringify(A));G=Q}else if("$near"===J&&"string"==typeof G.type&&Array.isArray(G.coordinates))G=G.coordinates;else if(("$near"===J||"$nearSphere"===J||"$geoIntersects"===J)&&G.$geometry&&"string"==typeof G.$geometry.type&&Array.isArray(G.$geometry.coordinates))null!=G.$maxDistance&&(G.$maxDistance=Y.castForQueryWrapper({val:G.$maxDistance,context:g})),null!=G.$minDistance&&(G.$minDistance=Y.castForQueryWrapper({val:G.$minDistance,context:g})),y(G.$geometry)&&(G.$geometry=G.$geometry.toObject({transform:!1,virtuals:!1})),G=G.$geometry.coordinates;else if("$geoWithin"===J)if(G.$geometry){y(G.$geometry)&&(G.$geometry=G.$geometry.toObject({virtuals:!1}));var X=G.$geometry.type;if(-1===v.indexOf(X))throw new Error('Invalid geoJSON type for $geoWithin "'+X+'", must be "Polygon" or "MultiPolygon"');G=G.$geometry.coordinates}else G=G.$box||G.$polygon||G.$center||G.$centerSphere,y(G)&&(G=G.toObject({virtuals:!1}));b(G,Y,g);continue}}if(e.nested[S])continue;if(n.upsert&&n.strict){if("throw"===n.strict)throw new a(S);throw new a(S,'Path "'+S+'" is not in schema, strict mode is `true`, and upsert is `true`.')}if(n.strict){if("throw"===n.strict)throw new a(S,'Path "'+S+"\" is not in schema and strict is 'throw'.");delete r[S]}}}}return r}},function(t,e,r){"use strict";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)}var n=r(20),o=r(84),s=r(160);
|
|
1369
|
+
*/function i(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,i=new Array(e);r<e;r++)i[r]=t[r];return i}function o(t){return(o="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 s=r(20),a=r(54),u=r(87),h=r(318),f=r(5),c=r(34),l=r(319),d=r(164),p=r(10),m=r(32),y=r(51),v=["Polygon","MultiPolygon"];function b(t,e,r){if(Array.isArray(t))t.forEach((function(i,n){if(Array.isArray(i)||m(i))return b(i,e,r);t[n]=e.castForQueryWrapper({val:i,context:r})}));else for(var i=Object.keys(t),n=i.length;n--;){var o=i[n],s=t[o];Array.isArray(s)||m(s)?(b(s,e,r),t[o]=s):t[o]=e.castForQuery({val:s,context:r})}}t.exports=function t(e,r,n,g){if(Array.isArray(r))throw new Error("Query filter must be an object, got an array ",p.inspect(r));if(null==r)return r;r.hasOwnProperty("_bsontype")&&"ObjectID"!==r._bsontype&&delete r._bsontype,null!=e&&null!=e.discriminators&&null!=r[e.options.discriminatorKey]&&(e=l(e,r[e.options.discriminatorKey])||e);var w,_,M,S,O,A,E=Object.keys(r),x=E.length;for(n=n||{};x--;)if(A=r[S=E[x]],"$or"===S||"$nor"===S||"$and"===S){if(!Array.isArray(A))throw new s("Array",A,S);for(var k=0;k<A.length;++k){if(null==A[k]||"object"!==o(A[k]))throw new s("Object",A[k],S+"."+k);A[k]=t(e,A[k],n,g)}}else{if("$where"===S){if("string"!==(O=o(A))&&"function"!==O)throw new Error("Must have a string or function for $where");"function"===O&&(r[S]=A.toString());continue}if("$expr"===S){if("object"!==o(A)||null==A)throw new Error("`$expr` must be an object");continue}if("$elemMatch"===S)A=t(e,A,n,g);else if("$text"===S)A=h(A,S);else{if(!e)continue;if(!(_=e.path(S)))for(var j=S.split("."),$=j.length;$--;){var P=j.slice(0,$).join("."),R=j.slice($).join("."),B=e.path(P),T=f(B,"schema.options.discriminatorKey");if(null!=B&&null!=f(B,"schema.discriminators")&&null!=T&&R!==T){var I=f(r,P+"."+T);null!=I&&(_=B.schema.discriminators[I].path(R))}}if(_){if(null==A)continue;if("Object"===c(A))if(Object.keys(A).some(d))for(var N=Object.keys(A),D=void 0,C=N.length;C--;)if(M=A[D=N[C]],"$not"===D){if(M&&_&&!_.caster){if((w=Object.keys(M)).length&&d(w[0]))for(var L in M)M[L]=_.castForQueryWrapper({$conditional:L,val:M[L],context:g});else A[D]=_.castForQueryWrapper({$conditional:D,val:M,context:g});continue}t(_.caster?_.caster.schema:e,M,n,g)}else A[D]=_.castForQueryWrapper({$conditional:D,val:M,context:g});else r[S]=_.castForQueryWrapper({val:A,context:g});else if(Array.isArray(A)&&-1===["Buffer","Array"].indexOf(_.instance)){var q,U=[],F=i(A);try{for(F.s();!(q=F.n()).done;){var z=q.value;U.push(_.castForQueryWrapper({val:z,context:g}))}}catch(t){F.e(t)}finally{F.f()}r[S]={$in:U}}else r[S]=_.castForQueryWrapper({val:A,context:g})}else{for(var V=S.split("."),K=V.length,H=void 0,Z=void 0,W=void 0;K--&&(H=V.slice(0,K).join("."),!(_=e.path(H))););if(_){_.caster&&_.caster.schema?((W={})[Z=V.slice(K).join(".")]=A,r[S]=t(_.caster.schema,W,n,g)[Z]):r[S]=A;continue}if(m(A)){var J="";if(A.$near?J="$near":A.$nearSphere?J="$nearSphere":A.$within?J="$within":A.$geoIntersects?J="$geoIntersects":A.$geoWithin&&(J="$geoWithin"),J){var Y=new u.Number("__QueryCasting__"),G=A[J];if(null!=A.$maxDistance&&(A.$maxDistance=Y.castForQueryWrapper({val:A.$maxDistance,context:g})),null!=A.$minDistance&&(A.$minDistance=Y.castForQueryWrapper({val:A.$minDistance,context:g})),"$within"===J){var Q=G.$center||G.$centerSphere||G.$box||G.$polygon;if(!Q)throw new Error("Bad $within parameter: "+JSON.stringify(A));G=Q}else if("$near"===J&&"string"==typeof G.type&&Array.isArray(G.coordinates))G=G.coordinates;else if(("$near"===J||"$nearSphere"===J||"$geoIntersects"===J)&&G.$geometry&&"string"==typeof G.$geometry.type&&Array.isArray(G.$geometry.coordinates))null!=G.$maxDistance&&(G.$maxDistance=Y.castForQueryWrapper({val:G.$maxDistance,context:g})),null!=G.$minDistance&&(G.$minDistance=Y.castForQueryWrapper({val:G.$minDistance,context:g})),y(G.$geometry)&&(G.$geometry=G.$geometry.toObject({transform:!1,virtuals:!1})),G=G.$geometry.coordinates;else if("$geoWithin"===J)if(G.$geometry){y(G.$geometry)&&(G.$geometry=G.$geometry.toObject({virtuals:!1}));var X=G.$geometry.type;if(-1===v.indexOf(X))throw new Error('Invalid geoJSON type for $geoWithin "'+X+'", must be "Polygon" or "MultiPolygon"');G=G.$geometry.coordinates}else G=G.$box||G.$polygon||G.$center||G.$centerSphere,y(G)&&(G=G.toObject({virtuals:!1}));b(G,Y,g);continue}}if(e.nested[S])continue;if(n.upsert&&n.strict){if("throw"===n.strict)throw new a(S);throw new a(S,'Path "'+S+'" is not in schema, strict mode is `true`, and upsert is `true`.')}if(n.strict){if("throw"===n.strict)throw new a(S,'Path "'+S+"\" is not in schema and strict is 'throw'.");delete r[S]}}}}return r}},function(t,e,r){"use strict";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)}var n=r(20),o=r(84),s=r(160);
|
|
1370
1370
|
/*!
|
|
1371
1371
|
* Casts val to an object suitable for `$text`. Throws an error if the object
|
|
1372
1372
|
* can't be casted.
|
package/index.d.ts
CHANGED
|
@@ -642,15 +642,11 @@ declare module 'mongoose' {
|
|
|
642
642
|
*/
|
|
643
643
|
$parent(): Document | undefined;
|
|
644
644
|
|
|
645
|
-
/**
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
populate(path: string | string[]): Promise<this>;
|
|
649
|
-
populate(path: string | string[], callback: Callback<this>): void;
|
|
645
|
+
/** Populates document references. */
|
|
646
|
+
populate(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<this>;
|
|
647
|
+
populate(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this>): void;
|
|
650
648
|
populate(path: string, names: string): Promise<this>;
|
|
651
649
|
populate(path: string, names: string, callback: Callback<this>): void;
|
|
652
|
-
populate(opts: PopulateOptions | Array<PopulateOptions>): Promise<this>;
|
|
653
|
-
populate(opts: PopulateOptions | Array<PopulateOptions>, callback: Callback<this>): void;
|
|
654
650
|
|
|
655
651
|
/** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */
|
|
656
652
|
populated(path: string): any;
|
|
@@ -718,7 +714,9 @@ declare module 'mongoose' {
|
|
|
718
714
|
|
|
719
715
|
type AnyKeys<T> = { [P in keyof T]?: T[P] | any };
|
|
720
716
|
interface AnyObject { [k: string]: any }
|
|
721
|
-
|
|
717
|
+
|
|
718
|
+
type Require_id<T> = T extends { _id?: any } ? (T & { _id: T['_id'] }) : (T & { _id: Types.ObjectId });
|
|
719
|
+
type EnforceDocument<T, TMethods> = T extends Document ? Require_id<T> : (Document<any, any, T> & Require_id<T> & TMethods);
|
|
722
720
|
|
|
723
721
|
interface IndexesDiff {
|
|
724
722
|
/** Indexes that would be created in mongodb. */
|
|
@@ -2460,11 +2458,11 @@ declare module 'mongoose' {
|
|
|
2460
2458
|
$eq?: T;
|
|
2461
2459
|
$gt?: T;
|
|
2462
2460
|
$gte?: T;
|
|
2463
|
-
$in?: T[];
|
|
2461
|
+
$in?: T extends AnyArray<any> ? Unpacked<T>[] : T[];
|
|
2464
2462
|
$lt?: T;
|
|
2465
2463
|
$lte?: T;
|
|
2466
2464
|
$ne?: T;
|
|
2467
|
-
$nin?: T[];
|
|
2465
|
+
$nin?: T extends AnyArray<any> ? Unpacked<T>[] : T[];
|
|
2468
2466
|
// Logical
|
|
2469
2467
|
$not?: T extends string ? QuerySelector<T> | RegExp : QuerySelector<T>;
|
|
2470
2468
|
// Element
|
|
@@ -2604,7 +2602,18 @@ declare module 'mongoose' {
|
|
|
2604
2602
|
{ $replaceRoot: any } |
|
|
2605
2603
|
{ $replaceWith: any };
|
|
2606
2604
|
|
|
2607
|
-
|
|
2605
|
+
type __UpdateDefProperty<T> =
|
|
2606
|
+
0 extends (1 & T) ? T : // any
|
|
2607
|
+
T extends unknown[] ? LeanArray<T> : // Array
|
|
2608
|
+
T extends Document ? LeanDocument<T> : // Subdocument
|
|
2609
|
+
[Extract<T, mongodb.ObjectId>] extends [never] ? T :
|
|
2610
|
+
T | string;
|
|
2611
|
+
type __UpdateQueryDef<T> = {
|
|
2612
|
+
[K in keyof T]: __UpdateDefProperty<T[K]>;
|
|
2613
|
+
};
|
|
2614
|
+
type _UpdateQueryDef<T> = __UpdateQueryDef<T>;
|
|
2615
|
+
|
|
2616
|
+
export type UpdateQuery<T> = (_UpdateQuery<_UpdateQueryDef<T>> & MatchKeysAndValues<_UpdateQueryDef<LeanDocument<T>>>);
|
|
2608
2617
|
|
|
2609
2618
|
type _AllowStringsForIds<T> = {
|
|
2610
2619
|
[K in keyof T]: [Extract<T[K], mongodb.ObjectId>] extends [never]
|
package/lib/cast.js
CHANGED
|
@@ -85,6 +85,11 @@ module.exports = function cast(schema, obj, options, context) {
|
|
|
85
85
|
obj[path] = val.toString();
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
continue;
|
|
89
|
+
} else if (path === '$expr') {
|
|
90
|
+
if (typeof val !== 'object' || val == null) {
|
|
91
|
+
throw new Error('`$expr` must be an object');
|
|
92
|
+
}
|
|
88
93
|
continue;
|
|
89
94
|
} else if (path === '$elemMatch') {
|
|
90
95
|
val = cast(schema, val, options, context);
|
package/lib/document.js
CHANGED
|
@@ -4210,7 +4210,7 @@ Document.prototype.depopulate = function(path) {
|
|
|
4210
4210
|
continue;
|
|
4211
4211
|
}
|
|
4212
4212
|
delete populated[key];
|
|
4213
|
-
|
|
4213
|
+
utils.setValue(key, populatedIds, this._doc);
|
|
4214
4214
|
}
|
|
4215
4215
|
return this;
|
|
4216
4216
|
}
|
|
@@ -4223,7 +4223,7 @@ Document.prototype.depopulate = function(path) {
|
|
|
4223
4223
|
delete this.$$populatedVirtuals[singlePath];
|
|
4224
4224
|
delete this._doc[singlePath];
|
|
4225
4225
|
} else if (populatedIds) {
|
|
4226
|
-
|
|
4226
|
+
utils.setValue(singlePath, populatedIds, this._doc);
|
|
4227
4227
|
}
|
|
4228
4228
|
}
|
|
4229
4229
|
return this;
|
|
@@ -77,6 +77,9 @@ module.exports = function(filter, schema, castedDoc, options) {
|
|
|
77
77
|
// Skip single nested paths if underneath a map
|
|
78
78
|
const isUnderneathMap = schemaType.path.endsWith('.$*') ||
|
|
79
79
|
schemaType.path.indexOf('.$*.') !== -1;
|
|
80
|
+
if (schemaType.path === '_id' && schemaType.options.auto) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
80
83
|
if (schemaType.$isSingleNested && !isUnderneathMap) {
|
|
81
84
|
// Only handle nested schemas 1-level deep to avoid infinite
|
|
82
85
|
// recursion re: https://github.com/mongodb-js/mongoose-autopopulate/issues/11
|
package/lib/model.js
CHANGED
|
@@ -1942,6 +1942,8 @@ Model.translateAliases = function translateAliases(fields) {
|
|
|
1942
1942
|
* To remove just the first document that matches `conditions`, set the `single`
|
|
1943
1943
|
* option to true.
|
|
1944
1944
|
*
|
|
1945
|
+
* This method is deprecated. See [Deprecation Warnings](../deprecations.html#remove) for details.
|
|
1946
|
+
*
|
|
1945
1947
|
* ####Example:
|
|
1946
1948
|
*
|
|
1947
1949
|
* const res = await Character.remove({ name: 'Eddard Stark' });
|
|
@@ -1953,6 +1955,7 @@ Model.translateAliases = function translateAliases(fields) {
|
|
|
1953
1955
|
* are involved. Because no Mongoose documents are involved, Mongoose does
|
|
1954
1956
|
* not execute [document middleware](/docs/middleware.html#types-of-middleware).
|
|
1955
1957
|
*
|
|
1958
|
+
* @deprecated
|
|
1956
1959
|
* @param {Object} conditions
|
|
1957
1960
|
* @param {Object} [options]
|
|
1958
1961
|
* @param {Session} [options.session=null] the [session](https://docs.mongodb.com/manual/reference/server-sessions/) associated with this operation.
|
|
@@ -3752,6 +3755,8 @@ Model.hydrate = function(obj, projection) {
|
|
|
3752
3755
|
*
|
|
3753
3756
|
* - `update()`
|
|
3754
3757
|
*
|
|
3758
|
+
* This method is deprecated. See [Deprecation Warnings](../deprecations.html#update) for details.
|
|
3759
|
+
*
|
|
3755
3760
|
* ####Examples:
|
|
3756
3761
|
*
|
|
3757
3762
|
* MyModel.update({ age: { $gt: 18 } }, { oldEnough: true }, fn);
|
|
@@ -3799,6 +3804,7 @@ Model.hydrate = function(obj, projection) {
|
|
|
3799
3804
|
*
|
|
3800
3805
|
* Be careful to not use an existing model instance for the update clause (this won't work and can cause weird behavior like infinite loops). Also, ensure that the update clause does not have an _id property, which causes Mongo to return a "Mod on _id not allowed" error.
|
|
3801
3806
|
*
|
|
3807
|
+
* @deprecated
|
|
3802
3808
|
* @see strict http://mongoosejs.com/docs/guide.html#strict
|
|
3803
3809
|
* @see response http://docs.mongodb.org/v2.6/reference/command/update/#output
|
|
3804
3810
|
* @param {Object} filter
|
package/lib/schema/number.js
CHANGED
|
@@ -315,12 +315,19 @@ SchemaNumber.prototype.enum = function(values, message) {
|
|
|
315
315
|
|
|
316
316
|
|
|
317
317
|
if (!Array.isArray(values)) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
318
|
+
const isObjectSyntax = utils.isPOJO(values) && values.values != null;
|
|
319
|
+
if (isObjectSyntax) {
|
|
320
|
+
message = values.message;
|
|
321
|
+
values = values.values;
|
|
322
|
+
} else if (typeof values === 'number') {
|
|
321
323
|
values = Array.prototype.slice.call(arguments);
|
|
324
|
+
message = null;
|
|
322
325
|
}
|
|
323
|
-
|
|
326
|
+
|
|
327
|
+
if (utils.isPOJO(values)) {
|
|
328
|
+
values = Object.values(values);
|
|
329
|
+
}
|
|
330
|
+
message = message || MongooseError.messages.Number.enum;
|
|
324
331
|
}
|
|
325
332
|
|
|
326
333
|
message = message == null ? MongooseError.messages.Number.enum : message;
|
package/lib/types/array/index.js
CHANGED
|
@@ -35,7 +35,7 @@ function MongooseArray(values, path, doc, schematype) {
|
|
|
35
35
|
[arrayAtomicsSymbol]: {},
|
|
36
36
|
[arrayAtomicsBackupSymbol]: void 0,
|
|
37
37
|
[arrayPathSymbol]: path,
|
|
38
|
-
[arraySchemaSymbol]:
|
|
38
|
+
[arraySchemaSymbol]: schematype,
|
|
39
39
|
[arrayParentSymbol]: void 0,
|
|
40
40
|
isMongooseArray: true,
|
|
41
41
|
isMongooseArrayProxy: true,
|
package/lib/types/map.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.5",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"build-browser": "node build-browser.js",
|
|
74
74
|
"prepublishOnly": "npm run build-browser",
|
|
75
75
|
"release": "git pull && git push origin master --tags && npm publish",
|
|
76
|
-
"release-legacy": "git pull origin
|
|
76
|
+
"release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy",
|
|
77
77
|
"test": "mocha --exit ./test/*.test.js ./test/typescript/main.test.js",
|
|
78
78
|
"tdd": "mocha ./test/*.test.js ./test/typescript/main.test.js --inspect --watch --recursive --watch-files ./**/*.js",
|
|
79
79
|
"test-cov": "nyc --reporter=html --reporter=text npm test"
|
|
@@ -104,24 +104,26 @@
|
|
|
104
104
|
"extends": [
|
|
105
105
|
"eslint:recommended"
|
|
106
106
|
],
|
|
107
|
-
"overrides": [
|
|
108
|
-
|
|
109
|
-
"
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
"
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
107
|
+
"overrides": [
|
|
108
|
+
{
|
|
109
|
+
"files": [
|
|
110
|
+
"**/*.{ts,tsx}"
|
|
111
|
+
],
|
|
112
|
+
"extends": [
|
|
113
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
114
|
+
"plugin:@typescript-eslint/recommended"
|
|
115
|
+
],
|
|
116
|
+
"plugins": [
|
|
117
|
+
"@typescript-eslint"
|
|
118
|
+
],
|
|
119
|
+
"rules": {
|
|
120
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
121
|
+
"@typescript-eslint/ban-types": "off",
|
|
122
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
123
|
+
"@typescript-eslint/explicit-module-boundary-types": "off"
|
|
124
|
+
}
|
|
123
125
|
}
|
|
124
|
-
|
|
126
|
+
],
|
|
125
127
|
"plugins": [
|
|
126
128
|
"mocha-no-only"
|
|
127
129
|
],
|
|
@@ -245,4 +247,4 @@
|
|
|
245
247
|
"type": "opencollective",
|
|
246
248
|
"url": "https://opencollective.com/mongoose"
|
|
247
249
|
}
|
|
248
|
-
}
|
|
250
|
+
}
|