mongoose 6.2.10 → 6.2.11
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/CHANGELOG.md +11 -0
- package/dist/browser.umd.js +20 -9
- package/lib/aggregate.js +21 -30
- package/lib/document.js +3 -10
- package/lib/helpers/indexes/applySchemaCollation.js +13 -0
- package/lib/helpers/indexes/isTextIndex.js +16 -0
- package/lib/helpers/query/castUpdate.js +3 -1
- package/lib/helpers/update/applyTimestampsToChildren.js +2 -2
- package/lib/helpers/update/applyTimestampsToUpdate.js +0 -1
- package/lib/model.js +4 -11
- package/lib/query.js +38 -23
- package/lib/schema/SubdocumentPath.js +2 -1
- package/lib/schema/objectid.js +0 -3
- package/lib/schema/string.js +24 -2
- package/lib/schema.js +2 -1
- package/lib/schematype.js +0 -1
- package/lib/types/array/methods/index.js +1 -1
- package/lib/types/subdocument.js +29 -0
- package/package.json +3 -1
- package/types/aggregate.d.ts +223 -0
- package/types/index.d.ts +8 -149
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
6.2.11 / 2022-04-13
|
|
2
|
+
===================
|
|
3
|
+
* fix(document): handle validation with triply nested document arrays #11564
|
|
4
|
+
* fix(query): skip applying string schema setters on $regex #11426
|
|
5
|
+
* fix: skip findOneAndReplace() validation if runValidators = false #11559
|
|
6
|
+
* fix(model): correctly handle schema-level collations in syncIndexes() #7621
|
|
7
|
+
* fix(types): correct populate query return type with lean #11560 [mohammad0-0ahmad](https://github.com/mohammad0-0ahmad)
|
|
8
|
+
* fix(types): allow using { type: Mixed } as schema type definition for any path #10900
|
|
9
|
+
* docs: fix example on Schema.prototype.post() #11648 [EmilienLeroy](https://github.com/EmilienLeroy)
|
|
10
|
+
* docs: fix typo in methods/index.js #11651 [eltociear](https://github.com/eltociear)
|
|
11
|
+
|
|
1
12
|
6.2.10 / 2022-04-04
|
|
2
13
|
===================
|
|
3
14
|
* fix(types): improve lastErrorObject typing for rawResults #11602 [simllll](https://github.com/simllll)
|
package/dist/browser.umd.js
CHANGED
|
@@ -290,7 +290,7 @@ _.prototype.clone=function(){var t=Object.assign({},this.options),e=new this.con
|
|
|
290
290
|
t.exports=e=_,e.CastError=v,e.ValidatorError=g}).call(this,r(3).Buffer)},function(t,e,r){(function(t){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=Object.getOwnPropertyDescriptors||function(t){for(var e=Object.keys(t),r={},n=0;n<e.length;n++)r[e[n]]=Object.getOwnPropertyDescriptor(t,e[n]);return r},o=/%[sdj%]/g;e.format=function(t){if(!v(t)){for(var e=[],r=0;r<arguments.length;r++)e.push(u(arguments[r]));return e.join(" ")}r=1;for(var n=arguments,i=n.length,s=String(t).replace(o,(function(t){if("%%"===t)return"%";if(r>=i)return t;switch(t){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(t){return"[Circular]"}default:return t}})),a=n[r];r<i;a=n[++r])m(a)||!_(a)?s+=" "+a:s+=" "+u(a);return s},e.deprecate=function(r,n){if(void 0!==t&&!0===t.noDeprecation)return r;if(void 0===t)return function(){return e.deprecate(r,n).apply(this,arguments)};var i=!1;return function(){if(!i){if(t.throwDeprecation)throw new Error(n);t.traceDeprecation?console.trace(n):console.error(n),i=!0}return r.apply(this,arguments)}};var s,a={};function u(t,r){var n={seen:[],stylize:f};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),y(r)?n.showHidden=r:r&&e._extend(n,r),g(n.showHidden)&&(n.showHidden=!1),g(n.depth)&&(n.depth=2),g(n.colors)&&(n.colors=!1),g(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=h),c(n,t,n.depth)}function h(t,e){var r=u.styles[e];return r?"["+u.colors[r][0]+"m"+t+"["+u.colors[r][1]+"m":t}function f(t,e){return t}function c(t,r,n){if(t.customInspect&&r&&O(r.inspect)&&r.inspect!==e.inspect&&(!r.constructor||r.constructor.prototype!==r)){var i=r.inspect(n,t);return v(i)||(i=c(t,i,n)),i}var o=function(t,e){if(g(e))return t.stylize("undefined","undefined");if(v(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}if(b(e))return t.stylize(""+e,"number");if(y(e))return t.stylize(""+e,"boolean");if(m(e))return t.stylize("null","null")}(t,r);if(o)return o;var s=Object.keys(r),a=function(t){var e={};return t.forEach((function(t,r){e[t]=!0})),e}(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(r)),S(r)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return l(r);if(0===s.length){if(O(r)){var u=r.name?": "+r.name:"";return t.stylize("[Function"+u+"]","special")}if(w(r))return t.stylize(RegExp.prototype.toString.call(r),"regexp");if(M(r))return t.stylize(Date.prototype.toString.call(r),"date");if(S(r))return l(r)}var h,f="",_=!1,A=["{","}"];(p(r)&&(_=!0,A=["[","]"]),O(r))&&(f=" [Function"+(r.name?": "+r.name:"")+"]");return w(r)&&(f=" "+RegExp.prototype.toString.call(r)),M(r)&&(f=" "+Date.prototype.toUTCString.call(r)),S(r)&&(f=" "+l(r)),0!==s.length||_&&0!=r.length?n<0?w(r)?t.stylize(RegExp.prototype.toString.call(r),"regexp"):t.stylize("[Object]","special"):(t.seen.push(r),h=_?function(t,e,r,n,i){for(var o=[],s=0,a=e.length;s<a;++s)j(e,String(s))?o.push(d(t,e,r,n,String(s),!0)):o.push("");return i.forEach((function(i){i.match(/^\d+$/)||o.push(d(t,e,r,n,i,!0))})),o}(t,r,n,a,s):s.map((function(e){return d(t,r,n,a,e,_)})),t.seen.pop(),function(t,e,r){if(t.reduce((function(t,e){return e.indexOf("\n")>=0&&0,t+e.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60)return r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+r[1];return r[0]+e+" "+t.join(", ")+" "+r[1]}(h,f,A)):A[0]+f+A[1]}function l(t){return"["+Error.prototype.toString.call(t)+"]"}function d(t,e,r,n,i,o){var s,a,u;if((u=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?a=u.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):u.set&&(a=t.stylize("[Setter]","special")),j(n,i)||(s="["+i+"]"),a||(t.seen.indexOf(u.value)<0?(a=m(r)?c(t,u.value,null):c(t,u.value,r-1)).indexOf("\n")>-1&&(a=o?a.split("\n").map((function(t){return" "+t})).join("\n").substr(2):"\n"+a.split("\n").map((function(t){return" "+t})).join("\n")):a=t.stylize("[Circular]","special")),g(s)){if(o&&i.match(/^\d+$/))return a;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function p(t){return Array.isArray(t)}function y(t){return"boolean"==typeof t}function m(t){return null===t}function b(t){return"number"==typeof t}function v(t){return"string"==typeof t}function g(t){return void 0===t}function w(t){return _(t)&&"[object RegExp]"===A(t)}function _(t){return"object"===n(t)&&null!==t}function M(t){return _(t)&&"[object Date]"===A(t)}function S(t){return _(t)&&("[object Error]"===A(t)||t instanceof Error)}function O(t){return"function"==typeof t}function A(t){return Object.prototype.toString.call(t)}function E(t){return t<10?"0"+t.toString(10):t.toString(10)}e.debuglog=function(r){if(g(s)&&(s=t.env.NODE_DEBUG||""),r=r.toUpperCase(),!a[r])if(new RegExp("\\b"+r+"\\b","i").test(s)){var n=t.pid;a[r]=function(){var t=e.format.apply(e,arguments);console.error("%s %d: %s",r,n,t)}}else a[r]=function(){};return a[r]},e.inspect=u,u.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},u.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=p,e.isBoolean=y,e.isNull=m,e.isNullOrUndefined=function(t){return null==t},e.isNumber=b,e.isString=v,e.isSymbol=function(t){return"symbol"===n(t)},e.isUndefined=g,e.isRegExp=w,e.isObject=_,e.isDate=M,e.isError=S,e.isFunction=O,e.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"===n(t)||void 0===t},e.isBuffer=r(282);var x=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function k(){var t=new Date,e=[E(t.getHours()),E(t.getMinutes()),E(t.getSeconds())].join(":");return[t.getDate(),x[t.getMonth()],e].join(" ")}function j(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.log=function(){console.log("%s - %s",k(),e.format.apply(e,arguments))},e.inherits=r(283),e._extend=function(t,e){if(!e||!_(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t};var $="undefined"!=typeof Symbol?Symbol("util.promisify.custom"):void 0;function P(t,e){if(!t){var r=new Error("Promise was rejected with a falsy value");r.reason=t,t=r}return e(t)}e.promisify=function(t){if("function"!=typeof t)throw new TypeError('The "original" argument must be of type Function');if($&&t[$]){var e;if("function"!=typeof(e=t[$]))throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(e,$,{value:e,enumerable:!1,writable:!1,configurable:!0}),e}function e(){for(var e,r,n=new Promise((function(t,n){e=t,r=n})),i=[],o=0;o<arguments.length;o++)i.push(arguments[o]);i.push((function(t,n){t?r(t):e(n)}));try{t.apply(this,i)}catch(t){r(t)}return n}return Object.setPrototypeOf(e,Object.getPrototypeOf(t)),$&&Object.defineProperty(e,$,{value:e,enumerable:!1,writable:!1,configurable:!0}),Object.defineProperties(e,i(t))},e.promisify.custom=$,e.callbackify=function(e){if("function"!=typeof e)throw new TypeError('The "original" argument must be of type Function');function r(){for(var r=[],n=0;n<arguments.length;n++)r.push(arguments[n]);var i=r.pop();if("function"!=typeof i)throw new TypeError("The last argument must be of type Function");var o=this,s=function(){return i.apply(o,arguments)};e.apply(this,r).then((function(e){t.nextTick(s,null,e)}),(function(e){t.nextTick(P,e,s)}))}return Object.setPrototypeOf(r,Object.getPrototypeOf(e)),Object.defineProperties(r,i(e)),r}}).call(this,r(5))},function(t,e){function r(t,e){if(!t)throw new Error(e||"Assertion failed")}t.exports=r,r.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)}},function(t,e,r){"use strict";var n=e,i=r(21),o=r(10),s=r(129);n.assert=o,n.toArray=s.toArray,n.zero2=s.zero2,n.toHex=s.toHex,n.encode=s.encode,n.getNAF=function(t,e,r){var n=new Array(Math.max(t.bitLength(),r)+1);n.fill(0);for(var i=1<<e+1,o=t.clone(),s=0;s<n.length;s++){var a,u=o.andln(i-1);o.isOdd()?(a=u>(i>>1)-1?(i>>1)-u:u,o.isubn(a)):a=0,n[s]=a,o.iushrn(1)}return n},n.getJSF=function(t,e){var r=[[],[]];t=t.clone(),e=e.clone();for(var n,i=0,o=0;t.cmpn(-i)>0||e.cmpn(-o)>0;){var s,a,u=t.andln(3)+i&3,h=e.andln(3)+o&3;3===u&&(u=-1),3===h&&(h=-1),s=0==(1&u)?0:3!==(n=t.andln(7)+i&7)&&5!==n||2!==h?u:-u,r[0].push(s),a=0==(1&h)?0:3!==(n=e.andln(7)+o&7)&&5!==n||2!==u?h:-h,r[1].push(a),2*i===s+1&&(i=1-i),2*o===a+1&&(o=1-o),t.iushrn(1),e.iushrn(1)}return r},n.cachedProperty=function(t,e,r){var n="_"+e;t.prototype[e]=function(){return void 0!==this[n]?this[n]:this[n]=r.call(this)}},n.parseBytes=function(t){return"string"==typeof t?n.toArray(t,"hex"):t},n.intFromLE=function(t){return new i(t,"hex","le")}},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,o="object"===("undefined"==typeof Reflect?"undefined":n(Reflect))?Reflect:null,s=o&&"function"==typeof o.apply?o.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};i=o&&"function"==typeof o.ownKeys?o.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var a=Number.isNaN||function(t){return t!=t};function u(){u.init.call(this)}t.exports=u,t.exports.once=function(t,e){return new Promise((function(r,n){function i(r){t.removeListener(e,o),n(r)}function o(){"function"==typeof t.removeListener&&t.removeListener("error",i),r([].slice.call(arguments))}v(t,e,o,{once:!0}),"error"!==e&&function(t,e,r){"function"==typeof t.on&&v(t,"error",e,r)}(t,i,{once:!0})}))},u.EventEmitter=u,u.prototype._events=void 0,u.prototype._eventsCount=0,u.prototype._maxListeners=void 0;var h=10;function f(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+n(t))}function c(t){return void 0===t._maxListeners?u.defaultMaxListeners:t._maxListeners}function l(t,e,r,n){var i,o,s,a;if(f(r),void 0===(o=t._events)?(o=t._events=Object.create(null),t._eventsCount=0):(void 0!==o.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),o=t._events),s=o[e]),void 0===s)s=o[e]=r,++t._eventsCount;else if("function"==typeof s?s=o[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(i=c(t))>0&&s.length>i&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=s.length,a=u,console&&console.warn&&console.warn(a)}return t}function d(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=d.bind(n);return i.listener=r,n.wrapFn=i,i}function y(t,e,r){var n=t._events;if(void 0===n)return[];var i=n[e];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}(i):b(i,i.length)}function m(t){var e=this._events;if(void 0!==e){var r=e[t];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function b(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function v(t,e,r,i){if("function"==typeof t.on)i.once?t.once(e,r):t.on(e,r);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+n(t));t.addEventListener(e,(function n(o){i.once&&t.removeEventListener(e,n),r(o)}))}}Object.defineProperty(u,"defaultMaxListeners",{enumerable:!0,get:function(){return h},set:function(t){if("number"!=typeof t||t<0||a(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");h=t}}),u.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},u.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||a(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},u.prototype.getMaxListeners=function(){return c(this)},u.prototype.emit=function(t){for(var e=[],r=1;r<arguments.length;r++)e.push(arguments[r]);var n="error"===t,i=this._events;if(void 0!==i)n=n&&void 0===i.error;else if(!n)return!1;if(n){var o;if(e.length>0&&(o=e[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var u=i[t];if(void 0===u)return!1;if("function"==typeof u)s(u,this,e);else{var h=u.length,f=b(u,h);for(r=0;r<h;++r)s(f[r],this,e)}return!0},u.prototype.addListener=function(t,e){return l(this,t,e,!1)},u.prototype.on=u.prototype.addListener,u.prototype.prependListener=function(t,e){return l(this,t,e,!0)},u.prototype.once=function(t,e){return f(e),this.on(t,p(this,t,e)),this},u.prototype.prependOnceListener=function(t,e){return f(e),this.prependListener(t,p(this,t,e)),this},u.prototype.removeListener=function(t,e){var r,n,i,o,s;if(f(e),void 0===(n=this._events))return this;if(void 0===(r=n[t]))return this;if(r===e||r.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete n[t],n.removeListener&&this.emit("removeListener",t,r.listener||e));else if("function"!=typeof r){for(i=-1,o=r.length-1;o>=0;o--)if(r[o]===e||r[o].listener===e){s=r[o].listener,i=o;break}if(i<0)return this;0===i?r.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(r,i),1===r.length&&(n[t]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",t,s||e)}return this},u.prototype.off=u.prototype.removeListener,u.prototype.removeAllListeners=function(t){var e,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[t]),this;if(0===arguments.length){var i,o=Object.keys(r);for(n=0;n<o.length;++n)"removeListener"!==(i=o[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=r[t]))this.removeListener(t,e);else if(void 0!==e)for(n=e.length-1;n>=0;n--)this.removeListener(t,e[n]);return this},u.prototype.listeners=function(t){return y(this,t,!0)},u.prototype.rawListeners=function(t){return y(this,t,!1)},u.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):m.call(t,e)},u.prototype.listenerCount=m,u.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]}},function(t,e,r){"use strict";
|
|
291
291
|
/*!
|
|
292
292
|
* Module dependencies.
|
|
293
|
-
*/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}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 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 n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}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,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t){return(s="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 a,u,h,f=r(12).EventEmitter,c=r(274),l=r(7),d=r(45),p=r(154),y=r(306),m=r(307),b=r(85),v=r(44),g=r(151),w=r(152),_=r(86),M=r(345),S=r(53),O=r(167),A=r(92).compile,E=r(92).defineKey,x=r(346).flatten,k=r(347),j=r(14),$=r(349),P=r(350),R=r(91),B=r(42),T=r(93),I=r(351),N=r(9).inspect,D=r(34).internalToObjectOptions,C=r(352),L=r(81),q=r(353),U=r(4),F=r(355),z=U.clone,V=U.deepEqual,K=U.isMongooseObject,H=r(1).arrayAtomicsBackupSymbol,Z=r(1).arrayAtomicsSymbol,W=r(1).documentArrayParent,J=r(1).documentIsModified,Y=r(1).documentModifiedPaths,Q=r(1).documentSchemaSymbol,G=r(1).getSymbol,X=r(1).populateModelSymbol,tt=r(1).scopeSymbol,et=r(55).schemaMixedSymbol,rt=r(356),nt=U.specialProperties;function it(t,e,r,n){if("object"===s(r)&&null!=r&&(r=(n=r).skipId),n=Object.assign({},n),null==this.$__schema){var o=U.isObject(e)&&!e.instanceOfSchema?new b(e):e;this.$__setSchema(o),e=r,r=n,n=arguments[4]||{}}if(this.$__=new c,this.$isNew=!("isNew"in n)||n.isNew,
|
|
293
|
+
*/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}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 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 n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}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,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t){return(s="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 a,u,h,f=r(12).EventEmitter,c=r(274),l=r(7),d=r(45),p=r(154),y=r(306),m=r(307),b=r(85),v=r(44),g=r(151),w=r(152),_=r(86),M=r(345),S=r(53),O=r(167),A=r(92).compile,E=r(92).defineKey,x=r(346).flatten,k=r(347),j=r(14),$=r(349),P=r(350),R=r(91),B=r(42),T=r(93),I=r(351),N=r(9).inspect,D=r(34).internalToObjectOptions,C=r(352),L=r(81),q=r(353),U=r(4),F=r(355),z=U.clone,V=U.deepEqual,K=U.isMongooseObject,H=r(1).arrayAtomicsBackupSymbol,Z=r(1).arrayAtomicsSymbol,W=r(1).documentArrayParent,J=r(1).documentIsModified,Y=r(1).documentModifiedPaths,Q=r(1).documentSchemaSymbol,G=r(1).getSymbol,X=r(1).populateModelSymbol,tt=r(1).scopeSymbol,et=r(55).schemaMixedSymbol,rt=r(356),nt=U.specialProperties;function it(t,e,r,n){if("object"===s(r)&&null!=r&&(r=(n=r).skipId),n=Object.assign({},n),null==this.$__schema){var o=U.isObject(e)&&!e.instanceOfSchema?new b(e):e;this.$__setSchema(o),e=r,r=n,n=arguments[4]||{}}if(this.$__=new c,this.$isNew=!("isNew"in n)||n.isNew,null!=n.priorDoc&&(this.$__.priorDoc=n.priorDoc),r&&(this.$__.skipId=r),null!=t&&"object"!==s(t))throw new y(t,"obj","Document");var a=!0;void 0!==n.defaults&&(this.$__.defaults=n.defaults,a=n.defaults);var u=this.$__schema;"boolean"==typeof e||"throw"===e?(this.$__.strictMode=e,e=void 0):(this.$__.strictMode=u.options.strict,null!=e&&(this.$__.selected=e));var h,f=u.requiredPaths(!0),l=i(f);try{for(l.s();!(h=l.n()).done;){var d=h.value;this.$__.activePaths.require(d)}}catch(t){l.e(t)}finally{l.f()}var p=null;U.isPOJO(e)&&(p=I(e),this.$__.fields=e,this.$__.exclude=p);var m=!1===p&&e?M(e):null;if(null==this._doc&&(this.$__buildDoc(t,e,r,p,m,!1),a&&st(this,e,p,m,!0,null)),t&&(this.$__original_set?this.$__original_set(t,void 0,!0,n):this.$set(t,void 0,!0,n),t instanceof it&&(this.$isNew=t.$isNew)),n.willInit&&a?n.skipDefaults&&(this.$__.skipDefaults=n.skipDefaults):a&&st(this,e,p,m,!1,n.skipDefaults),!this.$__.strictMode&&t){var v=this,g=Object.keys(this._doc);g.forEach((function(t){t in u.tree||t in u.methods||t in u.virtuals||t.startsWith("$")||E({prop:t,subprops:null,prototype:v})}))}lt(this)}for(var ot in Object.defineProperty(it.prototype,"isNew",{get:function(){return this.$isNew},set:function(t){this.$isNew=t}}),Object.defineProperty(it.prototype,"errors",{get:function(){return this.$errors},set:function(t){this.$errors=t}}),
|
|
294
294
|
/*!
|
|
295
295
|
* Document exposes the NodeJS event emitter API, so you can use
|
|
296
296
|
* `on`, `once`, etc.
|
|
@@ -310,7 +310,7 @@ function ht(t){var e={};!
|
|
|
310
310
|
/*!
|
|
311
311
|
* ignore
|
|
312
312
|
*/
|
|
313
|
-
function(t){var e=Object.keys(t.$__.activePaths.states.require),r=0,n=e.length;for(r=0;r<n;++r){var i=e[r],o=t.$__schema.path(i);if(null!=o&&"function"==typeof o.originalRequiredValue){t.$__.cachedRequired=t.$__.cachedRequired||{};try{t.$__.cachedRequired[i]=o.originalRequiredValue.call(t,t)}catch(e){t.invalidate(i,e)}}}}(t);var r=new Set(Object.keys(t.$__.activePaths.states.require).filter((function(e){return!(!t.$__isSelected(e)&&!t.$isModified(e))&&(null==t.$__.cachedRequired||!(e in t.$__.cachedRequired)||t.$__.cachedRequired[e])})));function n(t){r.add(t)}Object.keys(t.$__.activePaths.states.init).forEach(n),Object.keys(t.$__.activePaths.states.modify).forEach(n),Object.keys(t.$__.activePaths.states.default).forEach(n);var o,s=t.$getAllSubdocs(),a=t.modifiedPaths(),u=i(s);try{for(u.s();!(o=u.n()).done;){var h=o.value;if(h.$basePath){
|
|
313
|
+
function(t){var e=Object.keys(t.$__.activePaths.states.require),r=0,n=e.length;for(r=0;r<n;++r){var i=e[r],o=t.$__schema.path(i);if(null!=o&&"function"==typeof o.originalRequiredValue){t.$__.cachedRequired=t.$__.cachedRequired||{};try{t.$__.cachedRequired[i]=o.originalRequiredValue.call(t,t)}catch(e){t.invalidate(i,e)}}}}(t);var r=new Set(Object.keys(t.$__.activePaths.states.require).filter((function(e){return!(!t.$__isSelected(e)&&!t.$isModified(e))&&(null==t.$__.cachedRequired||!(e in t.$__.cachedRequired)||t.$__.cachedRequired[e])})));function n(t){r.add(t)}Object.keys(t.$__.activePaths.states.init).forEach(n),Object.keys(t.$__.activePaths.states.modify).forEach(n),Object.keys(t.$__.activePaths.states.default).forEach(n);var o,s=t.$getAllSubdocs(),a=t.modifiedPaths(),u=i(s);try{for(u.s();!(o=u.n()).done;){var h=o.value;if(h.$basePath){var f,c=h.$__fullPathWithIndexes(),l=i(r);try{for(l.s();!(f=l.n()).done;){var d=f.value;(null===d||d.startsWith(c+"."))&&r.delete(d)}}catch(t){l.e(t)}finally{l.f()}!t.$isModified(c,a)||t.isDirectModified(c)||t.$isDefault(c)||(r.add(c),e[c]=!0)}}}catch(t){u.e(t)}finally{u.f()}var p,y=i(r);try{for(y.s();!(p=y.n()).done;){var m=p.value,b=t.$__schema.path(m);b&&((b.caster||0!==b.validators.length)&&(!b.$isMongooseArray||b.$isMongooseDocumentArray||b.$embeddedSchemaType.$isMongooseArray||0!==b.validators.length||0!==b.$embeddedSchemaType.validators.length)||r.delete(m))}}catch(t){y.e(t)}finally{y.f()}var v,g=i(r);try{for(g.s();!(v=g.n()).done;){var w=v.value,_=t.$__schema.path(w);if(_&&_.$isMongooseArray&&(Array.isArray(_)||!_.$isMongooseDocumentArray||_&&_.schemaOptions&&_.schemaOptions.required))if(!_||!_.$isMongooseArray||_.$isMongooseDocumentArray||_.$embeddedSchemaType.$isMongooseArray||0!==_.$embeddedSchemaType.validators.length)M(t.$__getValue(w),r,w)}}catch(t){g.e(t)}finally{g.f()}function M(t,e,r){if(null!=t)for(var n=t.length,i=0;i<n;++i)Array.isArray(t[i])?M(t[i],e,r+"."+i):e.add(r+"."+i)}var S,O={skipArrays:!0},A=i(r);try{for(A.s();!(S=A.n()).done;){var E=S.value;if(t.$__schema.nested[E]){var k=t.$__getValue(E);K(k)&&(k=k.toObject({transform:!1}));var j=x(k,E,O,t.$__schema);Object.keys(j).forEach(n)}}}catch(t){A.e(t)}finally{A.f()}var $,P=i(r);try{for(P.s();!($=P.n()).done;){var R=$.value;if(t.$__schema.singleNestedPaths.hasOwnProperty(R))r.delete(R);else{var B=t.$__schema.path(R);if(B&&B.$isSchemaMap){var T=t.$__getValue(R);if(null!=T){var I,N=i(T.keys());try{for(N.s();!(I=N.n()).done;){var D=I.value;r.add(R+"."+D)}}catch(t){N.e(t)}finally{N.f()}}}}}}catch(t){P.e(t)}finally{P.f()}return[r=Array.from(r),e]}
|
|
314
314
|
/*!
|
|
315
315
|
* ignore
|
|
316
316
|
*/
|
|
@@ -354,7 +354,7 @@ it.prototype.toBSON=function(){return this.toObject(D)},it.prototype.init=functi
|
|
|
354
354
|
* @param {Object} doc object we are initializing
|
|
355
355
|
* @api private
|
|
356
356
|
*/
|
|
357
|
-
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,d=e.$__schema;for(;c<f;)p(c++);function p(f){if(u=h[f],a=o+u,s=d.path(a),!d.$isRootDiscriminator||e.$__isSelected(a))if(!s&&U.isPOJO(r[u]))n[u]||(n[u]={},l||u in d.tree||u in d.methods||u in d.virtuals||(e[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=null==r[u].$__?null:r[u].$__.wasPopulated;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),C(this,e.populated),this.$emit("init",this),this.constructor.emit("init",this)
|
|
357
|
+
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,d=e.$__schema;for(;c<f;)p(c++);function p(f){if(u=h[f],a=o+u,s=d.path(a),!d.$isRootDiscriminator||e.$__isSelected(a))if(!s&&U.isPOJO(r[u]))n[u]||(n[u]={},l||u in d.tree||u in d.methods||u in d.virtuals||(e[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=null==r[u].$__?null:r[u].$__.wasPopulated;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),C(this,e.populated),this.$emit("init",this),this.constructor.emit("init",this);var f=!1===this.$__.exclude&&this.$__.fields?M(this.$__.fields):null;return st(this,this.$__.fields,this.$__.exclude,f,!1,this.$__.skipDefaults),this},it.prototype.update=function(){var t=Array.prototype.slice.call(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},it.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},it.prototype.replaceOne=function(){var t=Array.prototype.slice.call(arguments);return t.unshift({_id:this._id}),this.constructor.replaceOne.apply(this.constructor,t)},it.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}},it.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},it.prototype.$set=function(t,e,r,o){var a=this;U.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 it&&(t=t.$__isNested?t.toObject():t._doc),null==t){var S=[e,t];t=S[0],e=S[1]}c=e?e+".":"";var A=(u=P(this.$__schema,t)).length,E=o._skipMinimizeTopLevel||!1;if(0===A&&E)return delete o._skipMinimizeTopLevel,e&&this.$set(e,{}),this;for(var x=0;x<A;++x){var k=c+(f=u[x]);h=this.$__schema.pathType(k);var j=t[f];if(!0!==r||c||null==j||"nested"!==h||null==this._doc[f]?o=Object.assign({},o,{_skipMinimizeTopLevel:!1}):(delete this._doc[f],o=Object.assign({},o,{_skipMinimizeTopLevel:!0})),U.isNonBuiltinObject(j)&&"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(k))continue;if("adhocOrUndefined"===h&&(h=$(this,k,{typeOnly:!0})),"real"===h||"virtual"===h){var B=t[f];this.$set(c+f,B,b,o)}else if("nested"===h&&t[f]instanceof it)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 T=0,I=Object.keys(this.$__schema.tree);T<I.length;T++){var N=I[T];if(this._doc.hasOwnProperty(N)){var C=this._doc[N];delete this._doc[N],this._doc[N]=C}}return this}var q=this.$__schema.pathType(t);"adhocOrUndefined"===q&&(q=$(this,t,{typeOnly:!0})),e=R(e);var F,z=null!=a.$__.priorDoc?a.$__.priorDoc.$__getValue(t):b?void 0:a.$__getValue(t);if("nested"===q&&e){if("object"===s(e)&&null!=e){if(null!=e.$__&&(e=e.toObject(D)),null==e)return this.invalidate(t,new l.CastError("Object",e,t)),this;var V=null!=this.$__.savedState&&this.$__.savedState.hasOwnProperty(t);if(null!=this.$__.savedState&&!this.$isNew&&!this.$__.savedState.hasOwnProperty(t)){var K=this.$__getValue(t);this.$__.savedState[t]=K;for(var H=0,Z=Object.keys(K||{});H<Z.length;H++){var W=Z[H];this.$__.savedState[t+"."+W]=K[W]}}if(y)return this.$set(e,t,b);this.$__setValue(t,null),O(this,t);var J=P(this.$__schema,e,t);this.$__setValue(t,{});var Y,Q=i(J);try{for(Q.s();!(Y=Q.n()).done;){var G=Y.value;this.$set(t+"."+G,e[G],b,o)}}catch(t){Q.e(t)}finally{Q.f()}return null!=z&&U.deepEqual(V?this.$__.savedState[t]:z,e)?this.unmarkModified(t):this.markModified(t),this}return this.invalidate(t,new l.CastError("Object",e,t)),this}var tt=-1===t.indexOf(".")?[t]:t.split(".");if("string"==typeof this.$__schema.aliases[tt[0]]&&(tt[0]=this.$__schema.aliases[tt[0]]),"adhocOrUndefined"===q&&_){var et;for(w=0;w<tt.length;++w){var rt=tt.slice(0,w+1).join(".");if(w+1<tt.length&&"virtual"===this.$__schema.pathType(rt))return L.set(t,e,this),this;if(null!=(F=this.$__schema.path(rt))&&F instanceof d){et=!0;break}}if(null==F&&(F=$(this,t)),!et&&!F){if("throw"===_)throw new v(t);return this}}else{if("virtual"===q)return(F=this.$__schema.virtualpath(t)).applySetters(e,this),this;F=this.$__path(t)}var nt,ot=this._doc,st="";for(w=0;w<tt.length-1;++w)ot=ot[tt[w]],st+=(0!==st.length?".":"")+tt[w],ot||(this.$set(st,{}),this.$__isSelected(st)||this.unmarkModified(st),ot=this.$__getValue(st));if(tt.length<=1)nt=t;else{var ut=tt.length;for(w=0;w<ut;++w){var ht=tt.slice(0,w+1).join(".");if(null===this.$get(ht,null,{getters:!1})){nt=ht;break}}nt||(nt=t)}if(!F)return this.$__set(nt,t,o,b,tt,F,e,z),this;if((F.$isSingleNested||F.$isMongooseArray)&&
|
|
358
358
|
/*!
|
|
359
359
|
* ignore
|
|
360
360
|
*/
|
|
@@ -772,7 +772,11 @@ h.prototype.invalidate=function(t,e,r){n.prototype.invalidate.call(this,t,e,r);v
|
|
|
772
772
|
/*!
|
|
773
773
|
* ignore
|
|
774
774
|
*/
|
|
775
|
-
h.prototype.$ignore=function(t){n.prototype.$ignore.call(this,t);var e=this.$parent(),r=this.$__pathRelativeToParent(t);null!=e&&null!=r&&e.$ignore(r)},h.prototype.ownerDocument=function(){if(this.$__.ownerDocument)return this.$__.ownerDocument;for(var t=this,e=[],r=new Set([t]);"function"==typeof t.$__pathRelativeToParent;){e.unshift(t.$__pathRelativeToParent(void 0,!0));var n=t.$parent();if(null==n)break;if(t=n,r.has(t))throw new Error("Infinite subdocument loop: subdoc with _id "+t._id+" is a parent of itself");r.add(t)}return this.$__.fullPath=e.join("."),this.$__.ownerDocument=t,this.$__.ownerDocument},
|
|
775
|
+
h.prototype.$ignore=function(t){n.prototype.$ignore.call(this,t);var e=this.$parent(),r=this.$__pathRelativeToParent(t);null!=e&&null!=r&&e.$ignore(r)},h.prototype.ownerDocument=function(){if(this.$__.ownerDocument)return this.$__.ownerDocument;for(var t=this,e=[],r=new Set([t]);"function"==typeof t.$__pathRelativeToParent;){e.unshift(t.$__pathRelativeToParent(void 0,!0));var n=t.$parent();if(null==n)break;if(t=n,r.has(t))throw new Error("Infinite subdocument loop: subdoc with _id "+t._id+" is a parent of itself");r.add(t)}return this.$__.fullPath=e.join("."),this.$__.ownerDocument=t,this.$__.ownerDocument},
|
|
776
|
+
/*!
|
|
777
|
+
* ignore
|
|
778
|
+
*/
|
|
779
|
+
h.prototype.$__fullPathWithIndexes=function(){for(var t=this,e=[],r=new Set([t]);"function"==typeof t.$__pathRelativeToParent;){e.unshift(t.$__pathRelativeToParent(void 0,!1));var n=t.$parent();if(null==n)break;if(t=n,r.has(t))throw new Error("Infinite subdocument loop: subdoc with _id "+t._id+" is a parent of itself");r.add(t)}return e.join(".")},h.prototype.parent=function(){return this.$__parent},h.prototype.$parent=h.prototype.parent,
|
|
776
780
|
/*!
|
|
777
781
|
* no-op for hooks
|
|
778
782
|
*/
|
|
@@ -1279,7 +1283,7 @@ function n(){return null!=this._id?String(this._id):null}t.exports=function(t){r
|
|
|
1279
1283
|
/*!
|
|
1280
1284
|
* ignore
|
|
1281
1285
|
*/
|
|
1282
|
-
function a(t,e,r){if(null!=e){if(Object.keys(e).some((function(t){return
|
|
1286
|
+
function a(t,e,r){if(null!=e){if(Object.keys(e).some((function(t){return"$"===t[0]}))){if(e.$push&&y(e.$push),e.$addToSet&&y(e.$addToSet),null!=e.$set)for(var i=0,o=Object.keys(e.$set);i<o.length;i++){var a=o[i];u(r,a,e.$set,t)}if(null!=e.$setOnInsert)for(var h=0,f=Object.keys(e.$setOnInsert);h<f.length;h++){var c=f[h];u(r,c,e.$setOnInsert,t)}}var l,d=n(Object.keys(e).filter((function(t){return"$"!==t[0]})));try{for(d.s();!(l=d.n()).done;){var p=l.value;u(r,p,e,t)}}catch(t){d.e(t)}finally{d.f()}}function y(e){for(var n=0,i=Object.keys(e);n<i.length;n++){var o=i[n],a=r.path(o.replace(/\.\$\./i,".").replace(/.\$$/,""));e[o]&&a&&a.$isMongooseDocumentArray&&a.schema.options.timestamps&&function(){var r=a.schema.options.timestamps,n=s(r,"createdAt"),i=s(r,"updatedAt");e[o].$each?e[o].$each.forEach((function(e){null!=i&&(e[i]=t),null!=n&&(e[n]=t)})):(null!=i&&(e[o][i]=t),null!=n&&(e[o][n]=t))}()}}}function u(t,e,r,i){var u=o(e),h=t.path(u);if(h){for(var f=[],c=u.split("."),l=c.length-1;l>0;--l){var d=t.path(c.slice(0,l).join("."));null!=d&&(d.$isMongooseDocumentArray||d.$isSingleNested)&&f.push({parentPath:e.split(".").slice(0,l).join("."),parentSchemaType:d})}if(Array.isArray(r[e])&&h.$isMongooseDocumentArray)!function(t,e,r){var n=e.schema.options.timestamps;if(n)for(var i=t.length,o=s(n,"createdAt"),u=s(n,"updatedAt"),h=0;h<i;++h)null!=u&&(t[h][u]=r),null!=o&&(t[h][o]=r),a(r,t[h],e.schema)}(r[e],h,i);else if(r[e]&&h.$isSingleNested)!function(t,e,r){var n=e.schema.options.timestamps;if(n){var i=s(n,"createdAt"),o=s(n,"updatedAt");null!=o&&(t[o]=r),null!=i&&(t[i]=r),a(r,t,e.schema)}}(r[e],h,i);else if(f.length>0){var p,y=n(f);try{for(y.s();!(p=y.n()).done;){var m=p.value,b=m.parentPath,v=m.parentSchemaType,g=v.schema.options.timestamps,w=s(g,"updatedAt");if(g&&null!=w)if(v.$isSingleNested)r[b+"."+w]=i;else if(v.$isMongooseDocumentArray){var _=e.substring(b.length+1);if(/^\d+$/.test(_)){r[b+"."+_][w]=i;continue}var M=_.indexOf(".");r[b+"."+(_=-1!==M?_.substring(0,M):_)+"."+w]=i}}}catch(t){y.e(t)}finally{y.f()}}else if(null!=h.schema&&h.schema!=t&&r[e]){var S=h.schema.options.timestamps,O=s(S,"createdAt"),A=s(S,"updatedAt");if(!S)return;null!=A&&(r[e][A]=i),null!=O&&(r[e][O]=i)}}}t.exports=a},function(t,e,r){"use strict";t.exports=function(t){return t.replace(/\.\$(\[[^\]]*\])?(?=\.)/g,".0").replace(/\.\$(\[[^\]]*\])?$/g,".0")}},function(t,e,r){"use strict";
|
|
1283
1287
|
/*!
|
|
1284
1288
|
* ignore
|
|
1285
1289
|
*/var n=r(14);t.exports=
|
|
@@ -1306,7 +1310,14 @@ function i(t,e){var r={useErrorHandlers:!0,numCallbackParams:1,nullResultByDefau
|
|
|
1306
1310
|
/*!
|
|
1307
1311
|
* ignore
|
|
1308
1312
|
*/
|
|
1309
|
-
function l(t){return this.castForQuery(t)}
|
|
1313
|
+
function l(t){return this.castForQuery(t)}
|
|
1314
|
+
/*!
|
|
1315
|
+
* ignore
|
|
1316
|
+
*/
|
|
1317
|
+
/*!
|
|
1318
|
+
* ignore
|
|
1319
|
+
*/
|
|
1320
|
+
function d(t){return null==t?this._castNullish(t):this.cast(t,this)}c.schemaName="String",c.defaultOptions={},
|
|
1310
1321
|
/*!
|
|
1311
1322
|
* Inherits from SchemaType.
|
|
1312
1323
|
*/
|
|
@@ -1322,7 +1333,7 @@ c._defaultCaster=function(t){if(null!=t&&"string"!=typeof t)throw new Error;retu
|
|
|
1322
1333
|
/*!
|
|
1323
1334
|
* ignore
|
|
1324
1335
|
*/
|
|
1325
|
-
c._checkRequired=function(t){return(t instanceof String||"string"==typeof t)&&t.length},c.checkRequired=o.checkRequired,c.prototype.enum=function(){if(this.enumValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.enumValidator}),this),this.enumValidator=!1),void 0===arguments[0]||!1===arguments[0])return this;var t,e;h.isObject(arguments[0])?Array.isArray(arguments[0].values)?(t=arguments[0].values,e=arguments[0].message):(t=h.object.vals(arguments[0]),e=s.messages.String.enum):(t=arguments,e=s.messages.String.enum);var r,i=n(t);try{for(i.s();!(r=i.n()).done;){var o=r.value;void 0!==o&&this.enumValues.push(this.cast(o))}}catch(t){i.e(t)}finally{i.f()}var a=this.enumValues;return this.enumValidator=function(t){return void 0===t||~a.indexOf(t)},this.validators.push({validator:this.enumValidator,message:e,type:"enum",enumValues:a}),this},c.prototype.lowercase=function(t){var e=this;return arguments.length>0&&!t?this:this.set((function(t){return"string"!=typeof t&&(t=e.cast(t)),t?t.toLowerCase():t}))},c.prototype.uppercase=function(t){var e=this;return arguments.length>0&&!t?this:this.set((function(t){return"string"!=typeof t&&(t=e.cast(t)),t?t.toUpperCase():t}))},c.prototype.trim=function(t){var e=this;return arguments.length>0&&!t?this:this.set((function(t){return"string"!=typeof t&&(t=e.cast(t)),t?t.trim():t}))},c.prototype.minlength=function(t,e){if(this.minlengthValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.minlengthValidator}),this)),null!=t){var r=e||s.messages.String.minlength;r=r.replace(/{MINLENGTH}/,t),this.validators.push({validator:this.minlengthValidator=function(e){return null===e||e.length>=t},message:r,type:"minlength",minlength:t})}return this},c.prototype.minLength=c.prototype.minlength,c.prototype.maxlength=function(t,e){if(this.maxlengthValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.maxlengthValidator}),this)),null!=t){var r=e||s.messages.String.maxlength;r=r.replace(/{MAXLENGTH}/,t),this.validators.push({validator:this.maxlengthValidator=function(e){return null===e||e.length<=t},message:r,type:"maxlength",maxlength:t})}return this},c.prototype.maxLength=c.prototype.maxlength,c.prototype.match=function(t,e){var r=e||s.messages.String.match;return this.validators.push({validator:function(e){return!!t&&(t.lastIndex=0,null==e||""===e||t.test(e))},message:r,type:"regexp",regexp:t}),this},c.prototype.checkRequired=function(t,e){return o._isRef(this,t,e,!0)?!!t:("function"==typeof this.constructor.checkRequired?this.constructor.checkRequired():c.checkRequired())(t)},c.prototype.cast=function(t,e,r){if(o._isRef(this,t,e,r))return"string"==typeof t?t:this._castRef(t,e,r);var n;n="function"==typeof this._castFunction?this._castFunction:"function"==typeof this.constructor.cast?this.constructor.cast():c.cast();try{return n(t)}catch(e){throw new f("string",t,this.path,null,this)}};var
|
|
1336
|
+
c._checkRequired=function(t){return(t instanceof String||"string"==typeof t)&&t.length},c.checkRequired=o.checkRequired,c.prototype.enum=function(){if(this.enumValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.enumValidator}),this),this.enumValidator=!1),void 0===arguments[0]||!1===arguments[0])return this;var t,e;h.isObject(arguments[0])?Array.isArray(arguments[0].values)?(t=arguments[0].values,e=arguments[0].message):(t=h.object.vals(arguments[0]),e=s.messages.String.enum):(t=arguments,e=s.messages.String.enum);var r,i=n(t);try{for(i.s();!(r=i.n()).done;){var o=r.value;void 0!==o&&this.enumValues.push(this.cast(o))}}catch(t){i.e(t)}finally{i.f()}var a=this.enumValues;return this.enumValidator=function(t){return void 0===t||~a.indexOf(t)},this.validators.push({validator:this.enumValidator,message:e,type:"enum",enumValues:a}),this},c.prototype.lowercase=function(t){var e=this;return arguments.length>0&&!t?this:this.set((function(t){return"string"!=typeof t&&(t=e.cast(t)),t?t.toLowerCase():t}))},c.prototype.uppercase=function(t){var e=this;return arguments.length>0&&!t?this:this.set((function(t){return"string"!=typeof t&&(t=e.cast(t)),t?t.toUpperCase():t}))},c.prototype.trim=function(t){var e=this;return arguments.length>0&&!t?this:this.set((function(t){return"string"!=typeof t&&(t=e.cast(t)),t?t.trim():t}))},c.prototype.minlength=function(t,e){if(this.minlengthValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.minlengthValidator}),this)),null!=t){var r=e||s.messages.String.minlength;r=r.replace(/{MINLENGTH}/,t),this.validators.push({validator:this.minlengthValidator=function(e){return null===e||e.length>=t},message:r,type:"minlength",minlength:t})}return this},c.prototype.minLength=c.prototype.minlength,c.prototype.maxlength=function(t,e){if(this.maxlengthValidator&&(this.validators=this.validators.filter((function(t){return t.validator!==this.maxlengthValidator}),this)),null!=t){var r=e||s.messages.String.maxlength;r=r.replace(/{MAXLENGTH}/,t),this.validators.push({validator:this.maxlengthValidator=function(e){return null===e||e.length<=t},message:r,type:"maxlength",maxlength:t})}return this},c.prototype.maxLength=c.prototype.maxlength,c.prototype.match=function(t,e){var r=e||s.messages.String.match;return this.validators.push({validator:function(e){return!!t&&(t.lastIndex=0,null==e||""===e||t.test(e))},message:r,type:"regexp",regexp:t}),this},c.prototype.checkRequired=function(t,e){return o._isRef(this,t,e,!0)?!!t:("function"==typeof this.constructor.checkRequired?this.constructor.checkRequired():c.checkRequired())(t)},c.prototype.cast=function(t,e,r){if(o._isRef(this,t,e,r))return"string"==typeof t?t:this._castRef(t,e,r);var n;n="function"==typeof this._castFunction?this._castFunction:"function"==typeof this.constructor.cast?this.constructor.cast():c.cast();try{return n(t)}catch(e){throw new f("string",t,this.path,null,this)}};var p=h.options(o.prototype.$conditionalHandlers,{$all:function(t){var e=this;return Array.isArray(t)?t.map((function(t){return e.castForQuery(t)})):[this.castForQuery(t)]},$gt:l,$gte:l,$lt:l,$lte:l,$options:d,$regex:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)?t:d.call(this,t)},$not:l});Object.defineProperty(c.prototype,"$conditionalHandlers",{configurable:!1,enumerable:!1,writable:!1,value:Object.freeze(p)}),c.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t+" with String.");return r.call(this,e)}return e=t,"[object RegExp]"===Object.prototype.toString.call(e)?e:this._castForQuery(e)},
|
|
1326
1337
|
/*!
|
|
1327
1338
|
* Module exports.
|
|
1328
1339
|
*/
|
|
@@ -1459,7 +1470,7 @@ function g(t,e){i||(i=r(90));var n=function(t,e,r){var n=this;this.$__parent=r,i
|
|
|
1459
1470
|
/*!
|
|
1460
1471
|
* ignore
|
|
1461
1472
|
*/
|
|
1462
|
-
v.prototype.$conditionalHandlers.$near=v.prototype.$conditionalHandlers.$nearSphere=d.cast$near,v.prototype.$conditionalHandlers.$within=v.prototype.$conditionalHandlers.$geoWithin=d.cast$within,v.prototype.$conditionalHandlers.$geoIntersects=d.cast$geoIntersects,v.prototype.$conditionalHandlers.$minDistance=c,v.prototype.$conditionalHandlers.$maxDistance=c,v.prototype.$conditionalHandlers.$exists=f,v.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=p(this.caster,t),h=e&&e.$__&&e.$__.selected||{},f=this.path,c=Object.keys(h).reduce((function(t,e){return e.startsWith(f+".")&&(t[e.substring(f.length+1)]=h[e]),t}),
|
|
1473
|
+
v.prototype.$conditionalHandlers.$near=v.prototype.$conditionalHandlers.$nearSphere=d.cast$near,v.prototype.$conditionalHandlers.$within=v.prototype.$conditionalHandlers.$geoWithin=d.cast$within,v.prototype.$conditionalHandlers.$geoIntersects=d.cast$geoIntersects,v.prototype.$conditionalHandlers.$minDistance=c,v.prototype.$conditionalHandlers.$maxDistance=c,v.prototype.$conditionalHandlers.$exists=f,v.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=p(this.caster,t),h=e&&e.$__&&e.$__.selected||{},f=this.path,c=Object.keys(h).reduce((function(t,e){return e.startsWith(f+".")&&((t=t||{})[e.substring(f.length+1)]=h[e]),t}),null);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)},v.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=p(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},v.prototype.doValidate=function(t,e,r,n){var i=p(this.caster,t);if(!t||t instanceof i||(t=new i(t,null,null!=r&&null!=r.$__?r:null)),n&&n.skipSchemaValidators)return t?t.validate(e):e(null);h.prototype.doValidate.call(this,t,(function(r){return r?e(r):t?void t.validate(e):e(null)}),r,n)},v.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()},v.prototype.discriminator=function(t,e,r){r=r||{};var n=b.isPOJO(r)?r.value:r,i="boolean"!=typeof r.clone||r.clone;return e.instanceOfSchema&&i&&(e=e.clone()),e=l(this.caster,t,e,n),this.caster.discriminators[t]=g(e,this.caster),this.caster.discriminators[t]},v.defaultOptions={},v.set=h.set,
|
|
1463
1474
|
/*!
|
|
1464
1475
|
* ignore
|
|
1465
1476
|
*/
|
|
@@ -1531,7 +1542,7 @@ function l(t){return this.cast(t)}
|
|
|
1531
1542
|
/*!
|
|
1532
1543
|
* ignore
|
|
1533
1544
|
*/
|
|
1534
|
-
function d(){return new u}function p(t){if(n||(n=r(13)),this instanceof n)
|
|
1545
|
+
function d(){return new u}function p(t){if((n||(n=r(13)),this instanceof n)&&void 0===t)return new u;return t}
|
|
1535
1546
|
/*!
|
|
1536
1547
|
* Module exports.
|
|
1537
1548
|
*/c.schemaName="ObjectId",c.defaultOptions={},
|
package/lib/aggregate.js
CHANGED
|
@@ -63,19 +63,21 @@ function Aggregate(pipeline, model) {
|
|
|
63
63
|
* Contains options passed down to the [aggregate command](https://docs.mongodb.com/manual/reference/command/aggregate/).
|
|
64
64
|
* Supported options are:
|
|
65
65
|
*
|
|
66
|
-
* - `readPreference`
|
|
67
|
-
* - [`cursor`](./api.html#aggregate_Aggregate-cursor)
|
|
68
|
-
* - [`explain`](./api.html#aggregate_Aggregate-explain)
|
|
69
66
|
* - [`allowDiskUse`](./api.html#aggregate_Aggregate-allowDiskUse)
|
|
70
|
-
* - `maxTimeMS`
|
|
71
67
|
* - `bypassDocumentValidation`
|
|
72
|
-
* - `raw`
|
|
73
|
-
* - `promoteLongs`
|
|
74
|
-
* - `promoteValues`
|
|
75
|
-
* - `promoteBuffers`
|
|
76
68
|
* - [`collation`](./api.html#aggregate_Aggregate-collation)
|
|
77
69
|
* - `comment`
|
|
70
|
+
* - [`cursor`](./api.html#aggregate_Aggregate-cursor)
|
|
71
|
+
* - [`explain`](./api.html#aggregate_Aggregate-explain)
|
|
72
|
+
* - `fieldsAsRaw`
|
|
73
|
+
* - hint
|
|
74
|
+
* - let
|
|
75
|
+
* - `maxTimeMS`
|
|
76
|
+
* - `raw`
|
|
77
|
+
* - `readConcern`
|
|
78
|
+
* - `readPreference`
|
|
78
79
|
* - [`session`](./api.html#aggregate_Aggregate-session)
|
|
80
|
+
* - `writeConcern`
|
|
79
81
|
*
|
|
80
82
|
* @property options
|
|
81
83
|
* @memberOf Aggregate
|
|
@@ -374,7 +376,7 @@ Aggregate.prototype.unwind = function() {
|
|
|
374
376
|
res.push({ $unwind: arg });
|
|
375
377
|
} else if (typeof arg === 'string') {
|
|
376
378
|
res.push({
|
|
377
|
-
$unwind: (arg
|
|
379
|
+
$unwind: (arg[0] === '$') ? arg : '$' + arg
|
|
378
380
|
});
|
|
379
381
|
} else {
|
|
380
382
|
throw new Error('Invalid arg "' + arg + '" to unwind(), ' +
|
|
@@ -399,7 +401,7 @@ Aggregate.prototype.unwind = function() {
|
|
|
399
401
|
* aggregate.replaceRoot({ x: { $concat: ['$this', '$that'] } });
|
|
400
402
|
*
|
|
401
403
|
* @see $replaceRoot https://docs.mongodb.org/manual/reference/operator/aggregation/replaceRoot
|
|
402
|
-
* @param {String|Object} the field or document which will become the new root document
|
|
404
|
+
* @param {String|Object} newRoot the field or document which will become the new root document
|
|
403
405
|
* @return {Aggregate}
|
|
404
406
|
* @api public
|
|
405
407
|
*/
|
|
@@ -428,13 +430,13 @@ Aggregate.prototype.replaceRoot = function(newRoot) {
|
|
|
428
430
|
* aggregate.count("userCount");
|
|
429
431
|
*
|
|
430
432
|
* @see $count https://docs.mongodb.org/manual/reference/operator/aggregation/count
|
|
431
|
-
* @param {String}
|
|
433
|
+
* @param {String} fieldName The name of the output field which has the count as its value. It must be a non-empty string, must not start with $ and must not contain the . character.
|
|
432
434
|
* @return {Aggregate}
|
|
433
435
|
* @api public
|
|
434
436
|
*/
|
|
435
437
|
|
|
436
|
-
Aggregate.prototype.count = function(
|
|
437
|
-
return this.append({ $count:
|
|
438
|
+
Aggregate.prototype.count = function(fieldName) {
|
|
439
|
+
return this.append({ $count: fieldName });
|
|
438
440
|
};
|
|
439
441
|
|
|
440
442
|
/**
|
|
@@ -460,7 +462,7 @@ Aggregate.prototype.sortByCount = function(arg) {
|
|
|
460
462
|
return this.append({ $sortByCount: arg });
|
|
461
463
|
} else if (typeof arg === 'string') {
|
|
462
464
|
return this.append({
|
|
463
|
-
$sortByCount: (arg
|
|
465
|
+
$sortByCount: (arg[0] === '$') ? arg : '$' + arg
|
|
464
466
|
});
|
|
465
467
|
} else {
|
|
466
468
|
throw new TypeError('Invalid arg "' + arg + '" to sortByCount(), ' +
|
|
@@ -621,9 +623,6 @@ Aggregate.prototype.unionWith = function(options) {
|
|
|
621
623
|
*/
|
|
622
624
|
|
|
623
625
|
Aggregate.prototype.read = function(pref, tags) {
|
|
624
|
-
if (!this.options) {
|
|
625
|
-
this.options = {};
|
|
626
|
-
}
|
|
627
626
|
read.call(this, pref, tags);
|
|
628
627
|
return this;
|
|
629
628
|
};
|
|
@@ -642,9 +641,6 @@ Aggregate.prototype.read = function(pref, tags) {
|
|
|
642
641
|
*/
|
|
643
642
|
|
|
644
643
|
Aggregate.prototype.readConcern = function(level) {
|
|
645
|
-
if (!this.options) {
|
|
646
|
-
this.options = {};
|
|
647
|
-
}
|
|
648
644
|
readConcern.call(this, level);
|
|
649
645
|
return this;
|
|
650
646
|
};
|
|
@@ -676,11 +672,13 @@ Aggregate.prototype.readConcern = function(level) {
|
|
|
676
672
|
* @api public
|
|
677
673
|
*/
|
|
678
674
|
|
|
675
|
+
const validRedactStringValues = new Set(['$$DESCEND', '$$PRUNE', '$$KEEP']);
|
|
676
|
+
|
|
679
677
|
Aggregate.prototype.redact = function(expression, thenExpr, elseExpr) {
|
|
680
678
|
if (arguments.length === 3) {
|
|
681
|
-
if ((typeof thenExpr === 'string' && !
|
|
682
|
-
(typeof elseExpr === 'string' && !
|
|
683
|
-
throw new Error('If thenExpr or elseExpr is string, it must
|
|
679
|
+
if ((typeof thenExpr === 'string' && !validRedactStringValues.has(thenExpr)) ||
|
|
680
|
+
(typeof elseExpr === 'string' && !validRedactStringValues.has(elseExpr))) {
|
|
681
|
+
throw new Error('If thenExpr or elseExpr is string, it must be either $$DESCEND, $$PRUNE or $$KEEP');
|
|
684
682
|
}
|
|
685
683
|
|
|
686
684
|
expression = {
|
|
@@ -773,7 +771,6 @@ Aggregate.prototype.explain = function(verbosity, callback) {
|
|
|
773
771
|
* await Model.aggregate([{ $match: { foo: 'bar' } }]).allowDiskUse(true);
|
|
774
772
|
*
|
|
775
773
|
* @param {Boolean} value Should tell server it can use hard drive to store data during aggregation.
|
|
776
|
-
* @param {Array} [tags] optional tags for this query
|
|
777
774
|
* @see mongodb https://docs.mongodb.org/manual/reference/command/aggregate/
|
|
778
775
|
*/
|
|
779
776
|
|
|
@@ -865,9 +862,6 @@ Aggregate.prototype.option = function(value) {
|
|
|
865
862
|
*/
|
|
866
863
|
|
|
867
864
|
Aggregate.prototype.cursor = function(options) {
|
|
868
|
-
if (!this.options) {
|
|
869
|
-
this.options = {};
|
|
870
|
-
}
|
|
871
865
|
this.options.cursor = options || {};
|
|
872
866
|
return new AggregationCursor(this); // return this;
|
|
873
867
|
};
|
|
@@ -886,9 +880,6 @@ Aggregate.prototype.cursor = function(options) {
|
|
|
886
880
|
*/
|
|
887
881
|
|
|
888
882
|
Aggregate.prototype.collation = function(collation) {
|
|
889
|
-
if (!this.options) {
|
|
890
|
-
this.options = {};
|
|
891
|
-
}
|
|
892
883
|
this.options.collation = collation;
|
|
893
884
|
return this;
|
|
894
885
|
};
|
package/lib/document.js
CHANGED
|
@@ -94,7 +94,7 @@ function Document(obj, fields, skipId, options) {
|
|
|
94
94
|
this.$__ = new InternalCache();
|
|
95
95
|
this.$isNew = 'isNew' in options ? options.isNew : true;
|
|
96
96
|
|
|
97
|
-
if (
|
|
97
|
+
if (options.priorDoc != null) {
|
|
98
98
|
this.$__.priorDoc = options.priorDoc;
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -119,7 +119,7 @@ function Document(obj, fields, skipId, options) {
|
|
|
119
119
|
fields = undefined;
|
|
120
120
|
} else {
|
|
121
121
|
this.$__.strictMode = schema.options.strict;
|
|
122
|
-
if (fields
|
|
122
|
+
if (fields != null) {
|
|
123
123
|
this.$__.selected = fields;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -177,8 +177,6 @@ function Document(obj, fields, skipId, options) {
|
|
|
177
177
|
$__applyDefaults(this, fields, exclude, hasIncludedChildren, false, options.skipDefaults);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
this.$__._id = this._id;
|
|
181
|
-
|
|
182
180
|
if (!this.$__.strictMode && obj) {
|
|
183
181
|
const _this = this;
|
|
184
182
|
const keys = Object.keys(this._doc);
|
|
@@ -743,8 +741,6 @@ Document.prototype.$__init = function(doc, opts) {
|
|
|
743
741
|
this.$emit('init', this);
|
|
744
742
|
this.constructor.emit('init', this);
|
|
745
743
|
|
|
746
|
-
this.$__._id = this._id;
|
|
747
|
-
|
|
748
744
|
const hasIncludedChildren = this.$__.exclude === false && this.$__.fields ?
|
|
749
745
|
$__hasIncludedChildren(this.$__.fields) :
|
|
750
746
|
null;
|
|
@@ -2485,10 +2481,7 @@ function _getPathsToValidate(doc) {
|
|
|
2485
2481
|
if (subdoc.$basePath) {
|
|
2486
2482
|
// Remove child paths for now, because we'll be validating the whole
|
|
2487
2483
|
// subdoc
|
|
2488
|
-
|
|
2489
|
-
subdoc.ownerDocument();
|
|
2490
|
-
}
|
|
2491
|
-
const fullPathToSubdoc = subdoc.$__.fullPath;
|
|
2484
|
+
const fullPathToSubdoc = subdoc.$__fullPathWithIndexes();
|
|
2492
2485
|
|
|
2493
2486
|
for (const p of paths) {
|
|
2494
2487
|
if (p === null || p.startsWith(fullPathToSubdoc + '.')) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isTextIndex = require('./isTextIndex');
|
|
4
|
+
|
|
5
|
+
module.exports = function applySchemaCollation(indexKeys, indexOptions, schemaOptions) {
|
|
6
|
+
if (isTextIndex(indexKeys)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (schemaOptions.hasOwnProperty('collation') && !indexOptions.hasOwnProperty('collation')) {
|
|
11
|
+
indexOptions.collation = schemaOptions.collation;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the given index options have a `text` option.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
module.exports = function isTextIndex(indexKeys) {
|
|
8
|
+
let isTextIndex = false;
|
|
9
|
+
for (const key of Object.keys(indexKeys)) {
|
|
10
|
+
if (indexKeys[key] === 'text') {
|
|
11
|
+
isTextIndex = true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return isTextIndex;
|
|
16
|
+
};
|
|
@@ -47,7 +47,7 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
|
|
|
47
47
|
} else if (!options.overwriteDiscriminatorKey) {
|
|
48
48
|
delete obj[schema.options.discriminatorKey];
|
|
49
49
|
}
|
|
50
|
-
if (options.upsert) {
|
|
50
|
+
if (options.upsert && !options.overwrite) {
|
|
51
51
|
moveImmutableProperties(schema, obj, context);
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -217,6 +217,7 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
if (op !== '$setOnInsert' &&
|
|
220
|
+
!options.overwrite &&
|
|
220
221
|
handleImmutable(schematype, strict, obj, key, prefix + key, context)) {
|
|
221
222
|
continue;
|
|
222
223
|
}
|
|
@@ -311,6 +312,7 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
|
|
|
311
312
|
|
|
312
313
|
// You can use `$setOnInsert` with immutable keys
|
|
313
314
|
if (op !== '$setOnInsert' &&
|
|
315
|
+
!options.overwrite &&
|
|
314
316
|
handleImmutable(schematype, strict, obj, key, prefix + key, context)) {
|
|
315
317
|
continue;
|
|
316
318
|
}
|
|
@@ -15,7 +15,7 @@ function applyTimestampsToChildren(now, update, schema) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const keys = Object.keys(update);
|
|
18
|
-
const hasDollarKey = keys.some(key => key
|
|
18
|
+
const hasDollarKey = keys.some(key => key[0] === '$');
|
|
19
19
|
|
|
20
20
|
if (hasDollarKey) {
|
|
21
21
|
if (update.$push) {
|
|
@@ -38,7 +38,7 @@ function applyTimestampsToChildren(now, update, schema) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const updateKeys = Object.keys(update).filter(key =>
|
|
41
|
+
const updateKeys = Object.keys(update).filter(key => key[0] !== '$');
|
|
42
42
|
for (const key of updateKeys) {
|
|
43
43
|
applyTimestampsToUpdateKey(schema, key, update, now);
|
|
44
44
|
}
|
package/lib/model.js
CHANGED
|
@@ -26,6 +26,7 @@ const applyQueryMiddleware = require('./helpers/query/applyQueryMiddleware');
|
|
|
26
26
|
const applyHooks = require('./helpers/model/applyHooks');
|
|
27
27
|
const applyMethods = require('./helpers/model/applyMethods');
|
|
28
28
|
const applyProjection = require('./helpers/projection/applyProjection');
|
|
29
|
+
const applySchemaCollation = require('./helpers/indexes/applySchemaCollation');
|
|
29
30
|
const applyStaticHooks = require('./helpers/model/applyStaticHooks');
|
|
30
31
|
const applyStatics = require('./helpers/model/applyStatics');
|
|
31
32
|
const applyWriteConcern = require('./helpers/schema/applyWriteConcern');
|
|
@@ -1562,6 +1563,7 @@ Model.cleanIndexes = function cleanIndexes(callback) {
|
|
|
1562
1563
|
|
|
1563
1564
|
for (const [schemaIndexKeysObject, schemaIndexOptions] of schemaIndexes) {
|
|
1564
1565
|
const options = decorateDiscriminatorIndexOptions(this.schema, utils.clone(schemaIndexOptions));
|
|
1566
|
+
applySchemaCollation(schemaIndexKeysObject, options, this.schema.options);
|
|
1565
1567
|
|
|
1566
1568
|
if (isIndexEqual(schemaIndexKeysObject, options, dbIndex)) {
|
|
1567
1569
|
found = true;
|
|
@@ -1780,26 +1782,17 @@ function _ensureIndexes(model, options, callback) {
|
|
|
1780
1782
|
|
|
1781
1783
|
const indexFields = utils.clone(index[0]);
|
|
1782
1784
|
const indexOptions = utils.clone(index[1]);
|
|
1783
|
-
|
|
1784
|
-
for (const key of Object.keys(indexFields)) {
|
|
1785
|
-
if (indexFields[key] === 'text') {
|
|
1786
|
-
isTextIndex = true;
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1785
|
+
|
|
1789
1786
|
delete indexOptions._autoIndex;
|
|
1790
1787
|
decorateDiscriminatorIndexOptions(model.schema, indexOptions);
|
|
1791
1788
|
applyWriteConcern(model.schema, indexOptions);
|
|
1789
|
+
applySchemaCollation(indexFields, indexOptions, model.schema.options);
|
|
1792
1790
|
|
|
1793
1791
|
indexSingleStart(indexFields, options);
|
|
1794
1792
|
|
|
1795
1793
|
if ('background' in options) {
|
|
1796
1794
|
indexOptions.background = options.background;
|
|
1797
1795
|
}
|
|
1798
|
-
if (model.schema.options.hasOwnProperty('collation') &&
|
|
1799
|
-
!indexOptions.hasOwnProperty('collation') &&
|
|
1800
|
-
!isTextIndex) {
|
|
1801
|
-
indexOptions.collation = model.schema.options.collation;
|
|
1802
|
-
}
|
|
1803
1796
|
|
|
1804
1797
|
model.collection.createIndex(indexFields, indexOptions, utils.tick(function(err, name) {
|
|
1805
1798
|
indexSingleDone(err, indexFields, indexOptions, name);
|
package/lib/query.js
CHANGED
|
@@ -11,6 +11,7 @@ const MongooseError = require('./error/mongooseError');
|
|
|
11
11
|
const ObjectParameterError = require('./error/objectParameter');
|
|
12
12
|
const QueryCursor = require('./cursor/QueryCursor');
|
|
13
13
|
const ReadPreference = require('./driver').get().ReadPreference;
|
|
14
|
+
const ValidationError = require('./error/validation');
|
|
14
15
|
const applyGlobalMaxTimeMS = require('./helpers/query/applyGlobalMaxTimeMS');
|
|
15
16
|
const applyWriteConcern = require('./helpers/schema/applyWriteConcern');
|
|
16
17
|
const cast = require('./cast');
|
|
@@ -3713,7 +3714,6 @@ Query.prototype.findOneAndReplace = function(filter, replacement, options, callb
|
|
|
3713
3714
|
*/
|
|
3714
3715
|
Query.prototype._findOneAndReplace = wrapThunk(function(callback) {
|
|
3715
3716
|
this._castConditions();
|
|
3716
|
-
|
|
3717
3717
|
if (this.error() != null) {
|
|
3718
3718
|
callback(this.error());
|
|
3719
3719
|
return null;
|
|
@@ -3724,9 +3724,6 @@ Query.prototype._findOneAndReplace = wrapThunk(function(callback) {
|
|
|
3724
3724
|
convertNewToReturnDocument(options);
|
|
3725
3725
|
let fields = null;
|
|
3726
3726
|
|
|
3727
|
-
let castedDoc = new this.model(this._update, null, true);
|
|
3728
|
-
this._update = castedDoc;
|
|
3729
|
-
|
|
3730
3727
|
this._applyPaths();
|
|
3731
3728
|
if (this._fields != null) {
|
|
3732
3729
|
options.projection = this._castFields(utils.clone(this._fields));
|
|
@@ -3737,7 +3734,34 @@ Query.prototype._findOneAndReplace = wrapThunk(function(callback) {
|
|
|
3737
3734
|
}
|
|
3738
3735
|
}
|
|
3739
3736
|
|
|
3740
|
-
|
|
3737
|
+
const runValidators = _getOption(this, 'runValidators', false);
|
|
3738
|
+
if (runValidators === false) {
|
|
3739
|
+
try {
|
|
3740
|
+
this._update = this._castUpdate(this._update, true);
|
|
3741
|
+
} catch (err) {
|
|
3742
|
+
const validationError = new ValidationError();
|
|
3743
|
+
validationError.errors[err.path] = err;
|
|
3744
|
+
callback(validationError);
|
|
3745
|
+
return null;
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3748
|
+
this._collection.collection.findOneAndReplace(filter, this._update || {}, options, _wrapThunkCallback(this, (err, res) => {
|
|
3749
|
+
if (err) {
|
|
3750
|
+
return callback(err);
|
|
3751
|
+
}
|
|
3752
|
+
|
|
3753
|
+
const doc = res.value;
|
|
3754
|
+
|
|
3755
|
+
return this._completeOne(doc, res, callback);
|
|
3756
|
+
}));
|
|
3757
|
+
|
|
3758
|
+
return;
|
|
3759
|
+
}
|
|
3760
|
+
|
|
3761
|
+
|
|
3762
|
+
let castedDoc = new this.model(this._update, null, true);
|
|
3763
|
+
this._update = castedDoc;
|
|
3764
|
+
castedDoc.validate(err => {
|
|
3741
3765
|
if (err != null) {
|
|
3742
3766
|
return callback(err);
|
|
3743
3767
|
}
|
|
@@ -3860,7 +3884,11 @@ Query.prototype._findAndModify = function(type, callback) {
|
|
|
3860
3884
|
}
|
|
3861
3885
|
|
|
3862
3886
|
if (!isOverwriting) {
|
|
3863
|
-
|
|
3887
|
+
try {
|
|
3888
|
+
this._update = this._castUpdate(this._update, opts.overwrite);
|
|
3889
|
+
} catch (err) {
|
|
3890
|
+
return callback(err);
|
|
3891
|
+
}
|
|
3864
3892
|
const _opts = Object.assign({}, opts, {
|
|
3865
3893
|
setDefaultsOnInsert: this._mongooseOptions.setDefaultsOnInsert
|
|
3866
3894
|
});
|
|
@@ -4055,10 +4083,10 @@ function _updateThunk(op, callback) {
|
|
|
4055
4083
|
}
|
|
4056
4084
|
this._update = new this.model(this._update, null, true);
|
|
4057
4085
|
} else {
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
callback(
|
|
4086
|
+
try {
|
|
4087
|
+
this._update = this._castUpdate(this._update, options.overwrite);
|
|
4088
|
+
} catch (err) {
|
|
4089
|
+
callback(err);
|
|
4062
4090
|
return null;
|
|
4063
4091
|
}
|
|
4064
4092
|
|
|
@@ -4897,19 +4925,6 @@ function castQuery(query) {
|
|
|
4897
4925
|
}
|
|
4898
4926
|
}
|
|
4899
4927
|
|
|
4900
|
-
/*!
|
|
4901
|
-
* castDoc
|
|
4902
|
-
* @api private
|
|
4903
|
-
*/
|
|
4904
|
-
|
|
4905
|
-
function castDoc(query, overwrite) {
|
|
4906
|
-
try {
|
|
4907
|
-
return query._castUpdate(query._update, overwrite);
|
|
4908
|
-
} catch (err) {
|
|
4909
|
-
return err;
|
|
4910
|
-
}
|
|
4911
|
-
}
|
|
4912
|
-
|
|
4913
4928
|
/**
|
|
4914
4929
|
* Specifies paths which should be populated with other documents.
|
|
4915
4930
|
*
|
|
@@ -167,10 +167,11 @@ SubdocumentPath.prototype.cast = function(val, doc, init, priorVal, options) {
|
|
|
167
167
|
const path = this.path;
|
|
168
168
|
const selected = Object.keys(parentSelected).reduce((obj, key) => {
|
|
169
169
|
if (key.startsWith(path + '.')) {
|
|
170
|
+
obj = obj || {};
|
|
170
171
|
obj[key.substring(path.length + 1)] = parentSelected[key];
|
|
171
172
|
}
|
|
172
173
|
return obj;
|
|
173
|
-
},
|
|
174
|
+
}, null);
|
|
174
175
|
options = Object.assign({}, options, { priorDoc: priorVal });
|
|
175
176
|
if (init) {
|
|
176
177
|
subdoc = new Constructor(void 0, selected, doc);
|
package/lib/schema/objectid.js
CHANGED
package/lib/schema/string.js
CHANGED
|
@@ -612,6 +612,10 @@ function handleSingle(val) {
|
|
|
612
612
|
return this.castForQuery(val);
|
|
613
613
|
}
|
|
614
614
|
|
|
615
|
+
/*!
|
|
616
|
+
* ignore
|
|
617
|
+
*/
|
|
618
|
+
|
|
615
619
|
function handleArray(val) {
|
|
616
620
|
const _this = this;
|
|
617
621
|
if (!Array.isArray(val)) {
|
|
@@ -622,14 +626,32 @@ function handleArray(val) {
|
|
|
622
626
|
});
|
|
623
627
|
}
|
|
624
628
|
|
|
629
|
+
/*!
|
|
630
|
+
* ignore
|
|
631
|
+
*/
|
|
632
|
+
|
|
633
|
+
function handleSingleNoSetters(val) {
|
|
634
|
+
if (val == null) {
|
|
635
|
+
return this._castNullish(val);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
return this.cast(val, this);
|
|
639
|
+
}
|
|
640
|
+
|
|
625
641
|
const $conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {
|
|
626
642
|
$all: handleArray,
|
|
627
643
|
$gt: handleSingle,
|
|
628
644
|
$gte: handleSingle,
|
|
629
645
|
$lt: handleSingle,
|
|
630
646
|
$lte: handleSingle,
|
|
631
|
-
$options:
|
|
632
|
-
$regex:
|
|
647
|
+
$options: handleSingleNoSetters,
|
|
648
|
+
$regex: function handle$regex(val) {
|
|
649
|
+
if (Object.prototype.toString.call(val) === '[object RegExp]') {
|
|
650
|
+
return val;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return handleSingleNoSetters.call(this, val);
|
|
654
|
+
},
|
|
633
655
|
$not: handleSingle
|
|
634
656
|
});
|
|
635
657
|
|
package/lib/schema.js
CHANGED
|
@@ -1010,6 +1010,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1010
1010
|
if (options.hasOwnProperty('strict')) {
|
|
1011
1011
|
childSchemaOptions.strict = options.strict;
|
|
1012
1012
|
}
|
|
1013
|
+
|
|
1013
1014
|
if (this._userProvidedOptions.hasOwnProperty('_id')) {
|
|
1014
1015
|
childSchemaOptions._id = this._userProvidedOptions._id;
|
|
1015
1016
|
} else if (Schema.Types.DocumentArray.defaultOptions._id != null) {
|
|
@@ -1466,7 +1467,7 @@ Schema.prototype.pre = function(name) {
|
|
|
1466
1467
|
* });
|
|
1467
1468
|
*
|
|
1468
1469
|
* schema.post(/Many$/, function(res) {
|
|
1469
|
-
* console.log('this fired after you ran `updateMany()` or `deleteMany()`);
|
|
1470
|
+
* console.log('this fired after you ran `updateMany()` or `deleteMany()`');
|
|
1470
1471
|
* });
|
|
1471
1472
|
*
|
|
1472
1473
|
* const Model = mongoose.model('Model', schema);
|
package/lib/schematype.js
CHANGED
|
@@ -1128,7 +1128,6 @@ SchemaType.prototype.getDefault = function(scope, init) {
|
|
|
1128
1128
|
ret = this.defaultValue;
|
|
1129
1129
|
}
|
|
1130
1130
|
|
|
1131
|
-
|
|
1132
1131
|
if (ret !== null && ret !== undefined) {
|
|
1133
1132
|
if (typeof ret === 'object' && (!this.options || !this.options.shared)) {
|
|
1134
1133
|
ret = utils.clone(ret);
|
|
@@ -149,7 +149,7 @@ const methods = {
|
|
|
149
149
|
*
|
|
150
150
|
* #### NOTE:
|
|
151
151
|
*
|
|
152
|
-
* _Calling this
|
|
152
|
+
* _Calling this multiple times on an array before saving sends the same command as calling it once._
|
|
153
153
|
* _This update is implemented using the MongoDB [$pop](https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop) method which enforces this restriction._
|
|
154
154
|
*
|
|
155
155
|
* doc.array = [1,2,3];
|
package/lib/types/subdocument.js
CHANGED
|
@@ -269,6 +269,35 @@ Subdocument.prototype.ownerDocument = function() {
|
|
|
269
269
|
return this.$__.ownerDocument;
|
|
270
270
|
};
|
|
271
271
|
|
|
272
|
+
/*!
|
|
273
|
+
* ignore
|
|
274
|
+
*/
|
|
275
|
+
|
|
276
|
+
Subdocument.prototype.$__fullPathWithIndexes = function() {
|
|
277
|
+
let parent = this; // eslint-disable-line consistent-this
|
|
278
|
+
const paths = [];
|
|
279
|
+
const seenDocs = new Set([parent]);
|
|
280
|
+
|
|
281
|
+
while (true) {
|
|
282
|
+
if (typeof parent.$__pathRelativeToParent !== 'function') {
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
paths.unshift(parent.$__pathRelativeToParent(void 0, false));
|
|
286
|
+
const _parent = parent.$parent();
|
|
287
|
+
if (_parent == null) {
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
parent = _parent;
|
|
291
|
+
if (seenDocs.has(parent)) {
|
|
292
|
+
throw new Error('Infinite subdocument loop: subdoc with _id ' + parent._id + ' is a parent of itself');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
seenDocs.add(parent);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return paths.join('.');
|
|
299
|
+
};
|
|
300
|
+
|
|
272
301
|
/**
|
|
273
302
|
* Returns this sub-documents parent document.
|
|
274
303
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.2.
|
|
4
|
+
"version": "6.2.11",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -64,6 +64,8 @@
|
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"lint": "eslint .",
|
|
67
|
+
"lint-js": "eslint . --ext .js",
|
|
68
|
+
"lint-ts": "eslint . --ext .ts",
|
|
67
69
|
"build-browser": "node build-browser.js",
|
|
68
70
|
"prepublishOnly": "npm run build-browser",
|
|
69
71
|
"release": "git pull && git push origin master --tags && npm publish",
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import mongodb = require('mongodb');
|
|
2
|
+
|
|
3
|
+
declare module 'mongoose' {
|
|
4
|
+
|
|
5
|
+
interface AggregateOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If true, the MongoDB server will use the hard drive to store data during this aggregation.
|
|
8
|
+
*/
|
|
9
|
+
allowDiskUse?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Applicable only if you specify the $out or $merge aggregation stages.
|
|
12
|
+
*
|
|
13
|
+
* Enables db.collection.aggregate() to bypass document validation during the operation. This lets you insert documents that do not meet the validation requirements.
|
|
14
|
+
*/
|
|
15
|
+
bypassDocumentValidation?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The BSON-serializer will check if keys are valid
|
|
18
|
+
*/
|
|
19
|
+
collation?: mongodb.CollationOptions;
|
|
20
|
+
/**
|
|
21
|
+
* Users can specify an arbitrary string to help trace the operation through the database profiler, currentOp, and logs.
|
|
22
|
+
*/
|
|
23
|
+
comment?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Specifies the initial batch size for the cursor. The value of the cursor field is a document with the field batchSize.
|
|
26
|
+
*/
|
|
27
|
+
cursor?: { batchSize?: number; };
|
|
28
|
+
/**
|
|
29
|
+
* Specifies to return the information on the processing of the pipeline. See Return Information on Aggregation Pipeline Operation for an example.
|
|
30
|
+
*
|
|
31
|
+
* Not available in multi-document transactions.
|
|
32
|
+
*/
|
|
33
|
+
explain?: mongodb.ExplainVerbosityLike;
|
|
34
|
+
/**
|
|
35
|
+
* The index to use for the aggregation. The index is on the initial collection/view against which the aggregation is run.
|
|
36
|
+
*/
|
|
37
|
+
hint?: string | AnyObject;
|
|
38
|
+
/**
|
|
39
|
+
* Specifies a document with a list of variables. This allows you to improve command readability by separating the variables from the query text.
|
|
40
|
+
*/
|
|
41
|
+
let?: AnyObject;
|
|
42
|
+
/**
|
|
43
|
+
* Specifies a time limit in milliseconds for processing operations on a cursor. If you do not specify a value for maxTimeMS, operations will not time out. A value of 0 explicitly specifies the default unbounded behavior.
|
|
44
|
+
*
|
|
45
|
+
* @see https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/
|
|
46
|
+
*/
|
|
47
|
+
maxTimeMS?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Return BSON filled buffers from operations.
|
|
50
|
+
*/
|
|
51
|
+
raw?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Specifies the read concern.
|
|
54
|
+
*/
|
|
55
|
+
readConcern?: mongodb.ReadConcernLike;
|
|
56
|
+
/**
|
|
57
|
+
* The preferred read preference.
|
|
58
|
+
*/
|
|
59
|
+
readPreference?: mongodb.ReadPreferenceLike;
|
|
60
|
+
/** The ClientSession for this aggregation */
|
|
61
|
+
session?: mongodb.ClientSession;
|
|
62
|
+
/**
|
|
63
|
+
* Specifies the write concern.
|
|
64
|
+
*/
|
|
65
|
+
writeConcern?: mongodb.WriteConcern;
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class Aggregate<R> {
|
|
70
|
+
/**
|
|
71
|
+
* Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js
|
|
72
|
+
* You do not need to call this function explicitly, the JavaScript runtime
|
|
73
|
+
* will call it for you.
|
|
74
|
+
*/
|
|
75
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Unpacked<R>>;
|
|
76
|
+
|
|
77
|
+
options: AggregateOptions;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Sets an option on this aggregation. This function will be deprecated in a
|
|
81
|
+
* future release.
|
|
82
|
+
*
|
|
83
|
+
* @deprecated
|
|
84
|
+
*/
|
|
85
|
+
addCursorFlag(flag: CursorFlag, value: boolean): this;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Appends a new $addFields operator to this aggregate pipeline.
|
|
89
|
+
* Requires MongoDB v3.4+ to work
|
|
90
|
+
*/
|
|
91
|
+
addFields(arg: PipelineStage.AddFields['$addFields']): this;
|
|
92
|
+
|
|
93
|
+
/** Sets the allowDiskUse option for the aggregation query (ignored for < 2.6.0) */
|
|
94
|
+
allowDiskUse(value: boolean): this;
|
|
95
|
+
|
|
96
|
+
/** Appends new operators to this aggregate pipeline */
|
|
97
|
+
append(...args: PipelineStage[]): this;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Executes the query returning a `Promise` which will be
|
|
101
|
+
* resolved with either the doc(s) or rejected with the error.
|
|
102
|
+
* Like [`.then()`](#query_Query-then), but only takes a rejection handler.
|
|
103
|
+
*/
|
|
104
|
+
catch: Promise<R>['catch'];
|
|
105
|
+
|
|
106
|
+
/** Set the collation. */
|
|
107
|
+
collation(options: mongodb.CollationOptions): this;
|
|
108
|
+
|
|
109
|
+
/** Appends a new $count operator to this aggregate pipeline. */
|
|
110
|
+
count(fieldName: PipelineStage.Count['$count']): this;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Sets the cursor option for the aggregation query (ignored for < 2.6.0).
|
|
114
|
+
*/
|
|
115
|
+
cursor<DocType = any>(options?: Record<string, unknown>): Cursor<DocType>;
|
|
116
|
+
|
|
117
|
+
/** Executes the aggregate pipeline on the currently bound Model. */
|
|
118
|
+
exec(callback: Callback<R>): void;
|
|
119
|
+
exec(): Promise<R>;
|
|
120
|
+
|
|
121
|
+
/** Execute the aggregation with explain */
|
|
122
|
+
explain(verbosity: mongodb.ExplainVerbosityLike, callback: Callback<AnyObject>): void;
|
|
123
|
+
explain(verbosity: mongodb.ExplainVerbosityLike): Promise<AnyObject>;
|
|
124
|
+
explain(callback: Callback<AnyObject>): void;
|
|
125
|
+
explain(): Promise<AnyObject>;
|
|
126
|
+
|
|
127
|
+
/** Combines multiple aggregation pipelines. */
|
|
128
|
+
facet(options: PipelineStage.Facet['$facet']): this;
|
|
129
|
+
|
|
130
|
+
/** Appends new custom $graphLookup operator(s) to this aggregate pipeline, performing a recursive search on a collection. */
|
|
131
|
+
graphLookup(options: PipelineStage.GraphLookup['$graphLookup']): this;
|
|
132
|
+
|
|
133
|
+
/** Appends new custom $group operator to this aggregate pipeline. */
|
|
134
|
+
group(arg: PipelineStage.Group['$group']): this;
|
|
135
|
+
|
|
136
|
+
/** Sets the hint option for the aggregation query (ignored for < 3.6.0) */
|
|
137
|
+
hint(value: Record<string, unknown> | string): this;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Appends a new $limit operator to this aggregate pipeline.
|
|
141
|
+
* @param num maximum number of records to pass to the next stage
|
|
142
|
+
*/
|
|
143
|
+
limit(num: PipelineStage.Limit['$limit']): this;
|
|
144
|
+
|
|
145
|
+
/** Appends new custom $lookup operator to this aggregate pipeline. */
|
|
146
|
+
lookup(options: PipelineStage.Lookup['$lookup']): this;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Appends a new custom $match operator to this aggregate pipeline.
|
|
150
|
+
* @param arg $match operator contents
|
|
151
|
+
*/
|
|
152
|
+
match(arg: PipelineStage.Match['$match']): this;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Binds this aggregate to a model.
|
|
156
|
+
* @param model the model to which the aggregate is to be bound
|
|
157
|
+
*/
|
|
158
|
+
model(model: Model<any>): this;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Append a new $near operator to this aggregation pipeline
|
|
162
|
+
* @param arg $near operator contents
|
|
163
|
+
*/
|
|
164
|
+
near(arg: { near?: number[]; distanceField: string; maxDistance?: number; query?: Record<string, any>; includeLocs?: string; num?: number; uniqueDocs?: boolean }): this;
|
|
165
|
+
|
|
166
|
+
/** Returns the current pipeline */
|
|
167
|
+
pipeline(): PipelineStage[];
|
|
168
|
+
|
|
169
|
+
/** Appends a new $project operator to this aggregate pipeline. */
|
|
170
|
+
project(arg: PipelineStage.Project['$project']): this;
|
|
171
|
+
|
|
172
|
+
/** Sets the readPreference option for the aggregation query. */
|
|
173
|
+
read(pref: mongodb.ReadPreferenceLike): this;
|
|
174
|
+
|
|
175
|
+
/** Sets the readConcern level for the aggregation query. */
|
|
176
|
+
readConcern(level: string): this;
|
|
177
|
+
|
|
178
|
+
/** Appends a new $redact operator to this aggregate pipeline. */
|
|
179
|
+
redact(expression: PipelineStage.Redact['$redact'], thenExpr: '$$DESCEND' | '$$PRUNE' | '$$KEEP' | AnyObject, elseExpr: '$$DESCEND' | '$$PRUNE' | '$$KEEP' | AnyObject): this;
|
|
180
|
+
|
|
181
|
+
/** Appends a new $replaceRoot operator to this aggregate pipeline. */
|
|
182
|
+
replaceRoot(newRoot: PipelineStage.ReplaceRoot['$replaceRoot']['newRoot'] | string): this;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Helper for [Atlas Text Search](https://docs.atlas.mongodb.com/reference/atlas-search/tutorial/)'s
|
|
186
|
+
* `$search` stage.
|
|
187
|
+
*/
|
|
188
|
+
search(options: PipelineStage.Search['$search']): this;
|
|
189
|
+
|
|
190
|
+
/** Lets you set arbitrary options, for middlewares or plugins. */
|
|
191
|
+
option(value: AggregateOptions): this;
|
|
192
|
+
|
|
193
|
+
/** Appends new custom $sample operator to this aggregate pipeline. */
|
|
194
|
+
sample(arg: PipelineStage.Sample['$sample']['size']): this;
|
|
195
|
+
|
|
196
|
+
/** Sets the session for this aggregation. Useful for [transactions](/docs/transactions.html). */
|
|
197
|
+
session(session: mongodb.ClientSession | null): this;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Appends a new $skip operator to this aggregate pipeline.
|
|
201
|
+
* @param num number of records to skip before next stage
|
|
202
|
+
*/
|
|
203
|
+
skip(num: PipelineStage.Skip['$skip']): this;
|
|
204
|
+
|
|
205
|
+
/** Appends a new $sort operator to this aggregate pipeline. */
|
|
206
|
+
sort(arg: string | Record<string, SortValues> | PipelineStage.Sort['$sort']): this;
|
|
207
|
+
|
|
208
|
+
/** Provides promise for aggregate. */
|
|
209
|
+
then: Promise<R>['then'];
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Appends a new $sortByCount operator to this aggregate pipeline. Accepts either a string field name
|
|
213
|
+
* or a pipeline object.
|
|
214
|
+
*/
|
|
215
|
+
sortByCount(arg: string | PipelineStage.SortByCount['$sortByCount']): this;
|
|
216
|
+
|
|
217
|
+
/** Appends new $unionWith operator to this aggregate pipeline. */
|
|
218
|
+
unionWith(options: PipelineStage.UnionWith['$unionWith']): this;
|
|
219
|
+
|
|
220
|
+
/** Appends new custom $unwind operator(s) to this aggregate pipeline. */
|
|
221
|
+
unwind(...args: PipelineStage.Unwind['$unwind'][]): this;
|
|
222
|
+
}
|
|
223
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference path="./aggregate.d.ts" />
|
|
1
2
|
/// <reference path="./connection.d.ts" />
|
|
2
3
|
/// <reference path="./cursor.d.ts" />
|
|
3
4
|
/// <reference path="./document.d.ts" />
|
|
@@ -926,7 +927,8 @@ declare module 'mongoose' {
|
|
|
926
927
|
Function[] |
|
|
927
928
|
SchemaDefinition<T> |
|
|
928
929
|
SchemaDefinition<Unpacked<T>>[] |
|
|
929
|
-
typeof
|
|
930
|
+
typeof Schema.Types.Mixed |
|
|
931
|
+
MixedSchemaTypeOptions;
|
|
930
932
|
|
|
931
933
|
type SchemaDefinition<T = undefined> = T extends undefined
|
|
932
934
|
? { [path: string]: SchemaDefinitionProperty; }
|
|
@@ -941,6 +943,10 @@ declare module 'mongoose' {
|
|
|
941
943
|
|
|
942
944
|
type ExtractMongooseArray<T> = T extends Types.Array<any> ? AnyArray<Unpacked<T>> : T;
|
|
943
945
|
|
|
946
|
+
class MixedSchemaTypeOptions extends SchemaTypeOptions<Schema.Types.Mixed> {
|
|
947
|
+
type: typeof Schema.Types.Mixed;
|
|
948
|
+
}
|
|
949
|
+
|
|
944
950
|
export class SchemaTypeOptions<T> {
|
|
945
951
|
type?:
|
|
946
952
|
T extends string ? StringSchemaDefinition :
|
|
@@ -978,7 +984,7 @@ declare module 'mongoose' {
|
|
|
978
984
|
* The default value for this path. If a function, Mongoose executes the function
|
|
979
985
|
* and uses the return value as the default.
|
|
980
986
|
*/
|
|
981
|
-
default?: ExtractMongooseArray<T> | ((this: any, doc: any) => Partial<ExtractMongooseArray<T>>);
|
|
987
|
+
default?: T extends Schema.Types.Mixed ? ({} | ((this: any, doc: any) => any)) : (ExtractMongooseArray<T> | ((this: any, doc: any) => Partial<ExtractMongooseArray<T>>));
|
|
982
988
|
|
|
983
989
|
/**
|
|
984
990
|
* The model that `populate()` should use if populating this path.
|
|
@@ -2122,153 +2128,6 @@ declare module 'mongoose' {
|
|
|
2122
2128
|
T extends Document ? RawDocType :
|
|
2123
2129
|
T;
|
|
2124
2130
|
|
|
2125
|
-
class Aggregate<R> {
|
|
2126
|
-
/**
|
|
2127
|
-
* Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js
|
|
2128
|
-
* You do not need to call this function explicitly, the JavaScript runtime
|
|
2129
|
-
* will call it for you.
|
|
2130
|
-
*/
|
|
2131
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<Unpacked<R>>;
|
|
2132
|
-
|
|
2133
|
-
/**
|
|
2134
|
-
* Sets an option on this aggregation. This function will be deprecated in a
|
|
2135
|
-
* future release. */
|
|
2136
|
-
addCursorFlag(flag: string, value: boolean): this;
|
|
2137
|
-
|
|
2138
|
-
/**
|
|
2139
|
-
* Appends a new $addFields operator to this aggregate pipeline.
|
|
2140
|
-
* Requires MongoDB v3.4+ to work
|
|
2141
|
-
*/
|
|
2142
|
-
addFields(arg: PipelineStage.AddFields['$addFields']): this;
|
|
2143
|
-
|
|
2144
|
-
/** Sets the allowDiskUse option for the aggregation query (ignored for < 2.6.0) */
|
|
2145
|
-
allowDiskUse(value: boolean): this;
|
|
2146
|
-
|
|
2147
|
-
/** Appends new operators to this aggregate pipeline */
|
|
2148
|
-
append(...args: any[]): this;
|
|
2149
|
-
|
|
2150
|
-
/**
|
|
2151
|
-
* Executes the query returning a `Promise` which will be
|
|
2152
|
-
* resolved with either the doc(s) or rejected with the error.
|
|
2153
|
-
* Like [`.then()`](#query_Query-then), but only takes a rejection handler.
|
|
2154
|
-
*/
|
|
2155
|
-
catch: Promise<R>['catch'];
|
|
2156
|
-
|
|
2157
|
-
/** Adds a collation. */
|
|
2158
|
-
collation(options: mongodb.CollationOptions): this;
|
|
2159
|
-
|
|
2160
|
-
/** Appends a new $count operator to this aggregate pipeline. */
|
|
2161
|
-
count(countName: PipelineStage.Count['$count']): this;
|
|
2162
|
-
|
|
2163
|
-
/**
|
|
2164
|
-
* Sets the cursor option for the aggregation query (ignored for < 2.6.0).
|
|
2165
|
-
*/
|
|
2166
|
-
cursor<DocType = any>(options?: Record<string, unknown>): Cursor<DocType>;
|
|
2167
|
-
|
|
2168
|
-
/** Executes the aggregate pipeline on the currently bound Model. */
|
|
2169
|
-
exec(callback?: Callback<R>): Promise<R>;
|
|
2170
|
-
|
|
2171
|
-
/** Execute the aggregation with explain */
|
|
2172
|
-
explain(callback?: Callback): Promise<any>;
|
|
2173
|
-
explain(verbosity?: string, callback?: Callback): Promise<any>;
|
|
2174
|
-
|
|
2175
|
-
/** Combines multiple aggregation pipelines. */
|
|
2176
|
-
facet(options: PipelineStage.Facet['$facet']): this;
|
|
2177
|
-
|
|
2178
|
-
/** Appends new custom $graphLookup operator(s) to this aggregate pipeline, performing a recursive search on a collection. */
|
|
2179
|
-
graphLookup(options: PipelineStage.GraphLookup['$graphLookup']): this;
|
|
2180
|
-
|
|
2181
|
-
/** Appends new custom $group operator to this aggregate pipeline. */
|
|
2182
|
-
group(arg: PipelineStage.Group['$group']): this;
|
|
2183
|
-
|
|
2184
|
-
/** Sets the hint option for the aggregation query (ignored for < 3.6.0) */
|
|
2185
|
-
hint(value: Record<string, unknown> | string): this;
|
|
2186
|
-
|
|
2187
|
-
/**
|
|
2188
|
-
* Appends a new $limit operator to this aggregate pipeline.
|
|
2189
|
-
* @param num maximum number of records to pass to the next stage
|
|
2190
|
-
*/
|
|
2191
|
-
limit(num: PipelineStage.Limit['$limit']): this;
|
|
2192
|
-
|
|
2193
|
-
/** Appends new custom $lookup operator to this aggregate pipeline. */
|
|
2194
|
-
lookup(options: PipelineStage.Lookup['$lookup']): this;
|
|
2195
|
-
|
|
2196
|
-
/**
|
|
2197
|
-
* Appends a new custom $match operator to this aggregate pipeline.
|
|
2198
|
-
* @param arg $match operator contents
|
|
2199
|
-
*/
|
|
2200
|
-
match(arg: PipelineStage.Match['$match']): this;
|
|
2201
|
-
|
|
2202
|
-
/**
|
|
2203
|
-
* Binds this aggregate to a model.
|
|
2204
|
-
* @param model the model to which the aggregate is to be bound
|
|
2205
|
-
*/
|
|
2206
|
-
model(model: any): this;
|
|
2207
|
-
|
|
2208
|
-
/**
|
|
2209
|
-
* Append a new $near operator to this aggregation pipeline
|
|
2210
|
-
* @param arg $near operator contents
|
|
2211
|
-
*/
|
|
2212
|
-
near(arg: { near?: number[]; distanceField: string; maxDistance?: number; query?: Record<string, any>; includeLocs?: string; num?: number; uniqueDocs?: boolean }): this;
|
|
2213
|
-
|
|
2214
|
-
/** Returns the current pipeline */
|
|
2215
|
-
pipeline(): any[];
|
|
2216
|
-
|
|
2217
|
-
/** Appends a new $project operator to this aggregate pipeline. */
|
|
2218
|
-
project(arg: PipelineStage.Project['$project']): this;
|
|
2219
|
-
|
|
2220
|
-
/** Sets the readPreference option for the aggregation query. */
|
|
2221
|
-
read(pref: string | mongodb.ReadPreferenceMode, tags?: any[]): this;
|
|
2222
|
-
|
|
2223
|
-
/** Sets the readConcern level for the aggregation query. */
|
|
2224
|
-
readConcern(level: string): this;
|
|
2225
|
-
|
|
2226
|
-
/** Appends a new $redact operator to this aggregate pipeline. */
|
|
2227
|
-
redact(expression: any, thenExpr: string | any, elseExpr: string | any): this;
|
|
2228
|
-
|
|
2229
|
-
/** Appends a new $replaceRoot operator to this aggregate pipeline. */
|
|
2230
|
-
replaceRoot(newRoot: PipelineStage.ReplaceRoot['$replaceRoot']['newRoot'] | string): this;
|
|
2231
|
-
|
|
2232
|
-
/**
|
|
2233
|
-
* Helper for [Atlas Text Search](https://docs.atlas.mongodb.com/reference/atlas-search/tutorial/)'s
|
|
2234
|
-
* `$search` stage.
|
|
2235
|
-
*/
|
|
2236
|
-
search(options: PipelineStage.Search['$search']): this;
|
|
2237
|
-
|
|
2238
|
-
/** Lets you set arbitrary options, for middleware or plugins. */
|
|
2239
|
-
option(value: Record<string, unknown>): this;
|
|
2240
|
-
|
|
2241
|
-
/** Appends new custom $sample operator to this aggregate pipeline. */
|
|
2242
|
-
sample(size: number): this;
|
|
2243
|
-
|
|
2244
|
-
/** Sets the session for this aggregation. Useful for [transactions](/docs/transactions.html). */
|
|
2245
|
-
session(session: mongodb.ClientSession | null): this;
|
|
2246
|
-
|
|
2247
|
-
/**
|
|
2248
|
-
* Appends a new $skip operator to this aggregate pipeline.
|
|
2249
|
-
* @param num number of records to skip before next stage
|
|
2250
|
-
*/
|
|
2251
|
-
skip(num: number): this;
|
|
2252
|
-
|
|
2253
|
-
/** Appends a new $sort operator to this aggregate pipeline. */
|
|
2254
|
-
sort(arg: string | Record<string, SortValues> | PipelineStage.Sort['$sort']): this;
|
|
2255
|
-
|
|
2256
|
-
/** Provides promise for aggregate. */
|
|
2257
|
-
then: Promise<R>['then'];
|
|
2258
|
-
|
|
2259
|
-
/**
|
|
2260
|
-
* Appends a new $sortByCount operator to this aggregate pipeline. Accepts either a string field name
|
|
2261
|
-
* or a pipeline object.
|
|
2262
|
-
*/
|
|
2263
|
-
sortByCount(arg: string | any): this;
|
|
2264
|
-
|
|
2265
|
-
/** Appends new $unionWith operator to this aggregate pipeline. */
|
|
2266
|
-
unionWith(options: any): this;
|
|
2267
|
-
|
|
2268
|
-
/** Appends new custom $unwind operator(s) to this aggregate pipeline. */
|
|
2269
|
-
unwind(...args: PipelineStage.Unwind['$unwind'][]): this;
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2272
2131
|
class SchemaType {
|
|
2273
2132
|
/** SchemaType constructor */
|
|
2274
2133
|
constructor(path: string, options?: AnyObject, instance?: string);
|