forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1 lines (1 loc) · 362 KB
/
index.js
1
!function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define("mingoose",[],e):"object"===typeof exports?exports.mingoose=e():t.mingoose=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=76)}([function(t,e,r){"use strict";(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,o,s,a=r(33),u=r(10),c=r(52),l=r(57),f=r(8),h=r(54),p=r(34),d=r(105),y=r(59).Buffer;function _(t,e){return f(t,"_bsontype",void 0)===e}e.toCollectionName=function(t,e){return"system.profile"===t?t:"system.indexes"===t?t:"function"===typeof e?e(t):t},e.deepEqual=function t(r,i){if(r===i)return!0;if(r instanceof Date&&i instanceof Date)return r.getTime()===i.getTime();if(_(r,"ObjectID")&&_(i,"ObjectID")||_(r,"Decimal128")&&_(i,"Decimal128"))return r.toString()===i.toString();if(r instanceof RegExp&&i instanceof RegExp)return r.source===i.source&&r.ignoreCase===i.ignoreCase&&r.multiline===i.multiline&&r.global===i.global;if("object"!==n(r)&&"object"!==n(i))return r==i;if(null===r||null===i||void 0===r||void 0===i)return!1;if(r.prototype!==i.prototype)return!1;if(r instanceof Number&&i instanceof Number)return r.valueOf()===i.valueOf();if(y.isBuffer(r))return e.buffer.areEqual(r,i);b(r)&&(r=r.toObject()),b(i)&&(i=i.toObject());try{var o,s,a=Object.keys(r),u=Object.keys(i)}catch(t){return!1}if(a.length!==u.length)return!1;for(a.sort(),u.sort(),s=a.length-1;s>=0;s--)if(a[s]!==u[s])return!1;for(s=a.length-1;s>=0;s--)if(!t(r[o=a[s]],i[o]))return!1;return!0},e.last=function(t){if(t.length>0)return t[t.length-1]},e.clone=function(t,r){if(void 0===t||null===t)return t;if(Array.isArray(t))return g(t,r);if(b(t))return r&&r.json&&"function"===typeof t.toJSON?t.toJSON(r):t.toObject(r);if(t.constructor)switch(e.getFunctionName(t.constructor)){case"Object":return v(t,r);case"Date":return new t.constructor(+t);case"RegExp":return l(t)}return t instanceof u?new u(t.id):_(t,"Decimal128")?r&&r.flattenDecimals?t.toJSON():a.fromString(t.toString()):!t.constructor&&e.isObject(t)?v(t,r):t.valueOf?t.valueOf():void 0};var m=e.clone;function v(t,e){var r,n,i,o=e&&e.minimize,s={};for(i in t)n=m(t[i],e),o&&"undefined"===typeof n||(r||(r=!0),s[i]=n);return o?r&&s:s}function g(t,e){for(var r=[],n=0,i=t.length;n<i;n++)r.push(m(t[n],e));return r}e.promiseOrCallback=function(e,r){if("function"===typeof e)try{return r(e)}catch(e){return t.nextTick(function(){throw e})}return new(c.get())(function(t,e){r(function(r,n){return null!=r?e(r):arguments.length>2?t(Array.prototype.slice.call(arguments,1)):void t(n)})})},e.options=function(t,e){var r,n=Object.keys(t),i=n.length;for(e=e||{};i--;)(r=n[i])in e||(e[r]=t[r]);return e},e.random=function(){return Math.random().toString().substr(3)},e.merge=function t(r,n,i,o){i=i||{};var s,a=Object.keys(n),u=0,c=a.length;o=o||"";for(var l=i.omitNested||{};u<c;)s=a[u++],i.omit&&i.omit[s]||l[o]||(null==r[s]?r[s]=n[s]:e.isObject(n[s])?(e.isObject(r[s])||(r[s]={}),t(r[s],n[s],i,o?o+"."+s:s)):i.overwrite&&(r[s]=n[s]))},e.toObject=function t(n){var i;if(s||(s=r(4)),null==n)return n;if(n instanceof s)return n.toObject();if(Array.isArray(n)){i=[];for(var o=0,a=n.length;o<a;++o)i.push(t(n[o]));return i}if(n.constructor&&"Object"===e.getFunctionName(n.constructor)||!n.constructor&&e.isObject(n)){for(var u in i={},n)i[u]=t(n[u]);return i}return n},e.isObject=function(t){return!!y.isBuffer(t)||"[object Object]"===Object.prototype.toString.call(t)},e.isPOJO=function(t){return"Object"===f(t,"constructor.name")},e.args=h,e.tick=function(e){if("function"===typeof e)return function(){try{e.apply(this,arguments)}catch(e){t.nextTick(function(){throw e})}}},e.isMongooseObject=function(t){return s||(s=r(4)),o||(o=r(16).Array),i||(i=r(16).Buffer),null!=t&&(null!=t.$__||t.isMongooseArray||t.isMongooseBuffer||t.$isMongooseMap)};var b=e.isMongooseObject;function w(t,e,r,i,o,s){this.path=t,this.match=r,this.select=e,this.options=i,this.model=o,"object"===n(s)&&(this.populate=s),this._docs={}}e.expires=function(t){var e;t&&"Object"===t.constructor.name&&("expires"in t&&(e="string"!==typeof t.expires?t.expires:Math.round(d(t.expires)/1e3),t.expireAfterSeconds=e,delete t.expires))},w.prototype.constructor=Object,e.PopulateOptions=w,e.populate=function(t,r,i,o,s,a){if(1===arguments.length){if(t instanceof w)return[t];if(Array.isArray(t))return function(t){var e=[];return t.forEach(function(t){/[\s]/.test(t.path)?t.path.split(" ").forEach(function(r){var n=Object.assign({},t);n.path=r,e.push(n)}):e.push(t)}),e}(t).map(function(t){return!t.populate||t.match||t.options?e.populate(t)[0]:e.populate(t.path,t.select,t.model,t.match,t.options,t.populate)[0]});e.isObject(t)&&(o=t.match,s=t.options,r=t.select,i=t.model,a=t.populate,t=t.path)}else"object"===n(i)&&(s=o,o=i,i=void 0);if("string"!==typeof t)throw new TypeError("utils.populate: invalid path. Expected string. Got typeof `"+n(t)+"`");if(Array.isArray(a)){var u=[];a.forEach(function(t){if(/[\s]/.test(t.path)){var r=Object.assign({},t);r.path.split(" ").forEach(function(t){r.path=t,u.push(e.populate(r)[0])})}else u.push(e.populate(t)[0])}),a=e.populate(u)}else"object"===n(a)&&(a=e.populate(a));var c=[],l=t.split(" ");s=e.clone(s);for(var f=0;f<l.length;++f)c.push(new w(l[f],r,o,s,i,a));return c},e.getValue=function(t,e,r){return p.get(t,e,"_doc",r)},e.setValue=function(t,e,r,n,i){p.set(t,e,r,"_doc",n,i)},e.object={},e.object.vals=function(t){for(var e=Object.keys(t),r=e.length,n=[];r--;)n.push(t[e[r]]);return n},e.object.shallowCopy=e.options;var O=Object.prototype.hasOwnProperty;e.object.hasOwnProperty=function(t,e){return O.call(t,e)},e.isNullOrUndefined=function(t){return null===t||void 0===t},e.array={},e.array.flatten=function t(e,r,n){return n||(n=[]),e.forEach(function(e){Array.isArray(e)?t(e,r,n):r&&!r(e)||n.push(e)}),n},e.array.unique=function(t){for(var e={},r={},n=[],i=t.length,o=0;o<i;++o)if("number"===typeof t[o]||"string"===typeof t[o]||null==t[o]){if(e[t[o]])continue;n.push(t[o]),e[t[o]]=!0}else if(t[o]instanceof u){if(r[t[o].toString()])continue;n.push(t[o]),r[t[o].toString()]=!0}else n.push(t[o]);return n},e.buffer={},e.buffer.areEqual=function(t,e){if(!y.isBuffer(t))return!1;if(!y.isBuffer(e))return!1;if(t.length!==e.length)return!1;for(var r=0,n=t.length;r<n;++r)if(t[r]!==e[r])return!1;return!0},e.getFunctionName=function(t){return t.name?t.name:(t.toString().trim().match(/^function\s*([^\s(]+)/)||[])[1]},e.decorate=function(t,e){for(var r in e)t[r]=e[r]},e.mergeClone=function(t,r){b(r)&&(r=r.toObject({transform:!1,virtuals:!1,depopulate:!0,getters:!1,flattenDecimals:!1}));for(var n,i=Object.keys(r),o=i.length,s=0;s<o;)if("undefined"===typeof t[n=i[s++]])t[n]=e.clone(r[n],{transform:!1,virtuals:!1,depopulate:!0,getters:!1,flattenDecimals:!1});else{var a=r[n];if(null==a||!a.valueOf||a instanceof Date||(a=a.valueOf()),e.isObject(a)){var u=a;b(a)&&!a.isMongooseBuffer&&(u=u.toObject({transform:!1,virtuals:!1,depopulate:!0,getters:!1,flattenDecimals:!1})),a.isMongooseBuffer&&(u=y.from(u)),e.mergeClone(t[n],u)}else t[n]=e.clone(a,{flattenDecimals:!1})}},e.each=function(t,e){for(var r=0;r<t.length;++r)e(t[r])},e.noop=function(){}}).call(this,r(7))},function(t,e,r){"use strict";(function(t){var n=r(78),i=r(79),o=r(80);function s(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,e){if(s()<e)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=u.prototype:(null===t&&(t=new u(e)),t.length=e),t}function u(t,e,r){if(!u.TYPED_ARRAY_SUPPORT&&!(this instanceof u))return new u(t,e,r);if("number"===typeof t){if("string"===typeof e)throw new Error("If encoding is specified then the first argument must be a string");return f(this,t)}return c(this,t,e,r)}function c(t,e,r,n){if("number"===typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!==typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);u.TYPED_ARRAY_SUPPORT?(t=e).__proto__=u.prototype:t=h(t,e);return t}(t,e,r,n):"string"===typeof e?function(t,e,r){"string"===typeof r&&""!==r||(r="utf8");if(!u.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|d(e,r),i=(t=a(t,n)).write(e,r);i!==n&&(t=t.slice(0,i));return t}(t,e,r):function(t,e){if(u.isBuffer(e)){var r=0|p(e.length);return 0===(t=a(t,r)).length?t:(e.copy(t,0,0,r),t)}if(e){if("undefined"!==typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!==typeof e.length||(n=e.length)!==n?a(t,0):h(t,e);if("Buffer"===e.type&&o(e.data))return h(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function l(t){if("number"!==typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function f(t,e){if(l(e),t=a(t,e<0?0:0|p(e)),!u.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function h(t,e){var r=e.length<0?0:0|p(e.length);t=a(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function p(t){if(t>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function d(t,e){if(u.isBuffer(t))return t.length;if("undefined"!==typeof ArrayBuffer&&"function"===typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!==typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return L(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return U(t).length;default:if(n)return L(t).length;e=(""+e).toLowerCase(),n=!0}}function y(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function _(t,e,r,n,i){if(0===t.length)return-1;if("string"===typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"===typeof e&&(e=u.from(e,n)),u.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"===typeof e)return e&=255,u.TYPED_ARRAY_SUPPORT&&"function"===typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){var o,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var l=-1;for(o=r;o<a;o++)if(c(t,o)===c(e,-1===l?0:o-l)){if(-1===l&&(l=o),o-l+1===u)return l*s}else-1!==l&&(o-=o-l),l=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var f=!0,h=0;h<u;h++)if(c(t,o+h)!==c(e,h)){f=!1;break}if(f)return o}return-1}function v(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=e.length;if(o%2!==0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[r+s]=a}return s}function g(t,e,r,n){return V(L(e,t.length-r),t,r,n)}function b(t,e,r,n){return V(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function w(t,e,r,n){return b(t,e,r,n)}function O(t,e,r,n){return V(U(e),t,r,n)}function S(t,e,r,n){return V(function(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function E(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function A(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o,s,a,u,c=t[i],l=null,f=c>239?4:c>223?3:c>191?2:1;if(i+f<=r)switch(f){case 1:c<128&&(l=c);break;case 2:128===(192&(o=t[i+1]))&&(u=(31&c)<<6|63&o)>127&&(l=u);break;case 3:o=t[i+1],s=t[i+2],128===(192&o)&&128===(192&s)&&(u=(15&c)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128===(192&o)&&128===(192&s)&&128===(192&a)&&(u=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,f=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),i+=f}return function(t){var e=t.length;if(e<=$)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=$));return r}(n)}e.Buffer=u,e.SlowBuffer=function(t){+t!=t&&(t=0);return u.alloc(+t)},e.INSPECT_MAX_BYTES=50,u.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"===typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=s(),u.poolSize=8192,u._augment=function(t){return t.__proto__=u.prototype,t},u.from=function(t,e,r){return c(null,t,e,r)},u.TYPED_ARRAY_SUPPORT&&(u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,"undefined"!==typeof Symbol&&Symbol.species&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0})),u.alloc=function(t,e,r){return function(t,e,r,n){return l(e),e<=0?a(t,e):void 0!==r?"string"===typeof n?a(t,e).fill(r,n):a(t,e).fill(r):a(t,e)}(null,t,e,r)},u.allocUnsafe=function(t){return f(null,t)},u.allocUnsafeSlow=function(t){return f(null,t)},u.isBuffer=function(t){return!(null==t||!t._isBuffer)},u.compare=function(t,e){if(!u.isBuffer(t)||!u.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},u.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(t,e){if(!o(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=u.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var s=t[r];if(!u.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,i),i+=s.length}return n},u.byteLength=d,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)y(this,e,e+1);return this},u.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)y(this,e,e+3),y(this,e+1,e+2);return this},u.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},u.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?A(this,0,t):function(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return x(this,e,r);case"utf8":case"utf-8":return A(this,e,r);case"ascii":return N(this,e,r);case"latin1":case"binary":return j(this,e,r);case"base64":return E(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},u.prototype.compare=function(t,e,r,n,i){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(e>>>=0,r>>>=0,n>>>=0,i>>>=0,this===t)return 0;for(var o=i-n,s=r-e,a=Math.min(o,s),c=this.slice(n,i),l=t.slice(e,r),f=0;f<a;++f)if(c[f]!==l[f]){o=c[f],s=l[f];break}return o<s?-1:s<o?1:0},u.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},u.prototype.indexOf=function(t,e,r){return _(this,t,e,r,!0)},u.prototype.lastIndexOf=function(t,e,r){return _(this,t,e,r,!1)},u.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"===typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return v(this,t,e,r);case"utf8":case"utf-8":return g(this,t,e,r);case"ascii":return b(this,t,e,r);case"latin1":case"binary":return w(this,t,e,r);case"base64":return O(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var $=4096;function N(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function j(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function x(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=I(t[o]);return i}function T(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function B(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function k(t,e,r,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function C(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i<o;++i)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function D(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i<o;++i)t[r+i]=e>>>8*(n?i:3-i)&255}function P(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function M(t,e,r,n,o){return o||P(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function R(t,e,r,n,o){return o||P(t,0,r,8),i.write(t,e,r,n,52,8),r+8}u.prototype.slice=function(t,e){var r,n=this.length;if(t=~~t,e=void 0===e?n:~~e,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),e<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),u.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=u.prototype;else{var i=e-t;r=new u(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+t]}return r},u.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||B(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},u.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||B(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},u.prototype.readUInt8=function(t,e){return e||B(t,1,this.length),this[t]},u.prototype.readUInt16LE=function(t,e){return e||B(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUInt16BE=function(t,e){return e||B(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUInt32LE=function(t,e){return e||B(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUInt32BE=function(t,e){return e||B(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||B(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},u.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||B(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},u.prototype.readInt8=function(t,e){return e||B(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){e||B(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(t,e){e||B(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(t,e){return e||B(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return e||B(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readFloatLE=function(t,e){return e||B(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return e||B(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return e||B(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return e||B(t,8,this.length),i.read(this,t,!1,52,8)},u.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||k(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},u.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||k(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},u.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,1,255,0),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},u.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):C(this,t,e,!0),e+2},u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):C(this,t,e,!1),e+2},u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):D(this,t,e,!0),e+4},u.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):D(this,t,e,!1),e+4},u.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);k(this,t,e,r,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o<r&&(s*=256);)t<0&&0===a&&0!==this[e+o-1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},u.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);k(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},u.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,1,127,-128),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):C(this,t,e,!0),e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):C(this,t,e,!1),e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):D(this,t,e,!0),e+4},u.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||k(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):D(this,t,e,!1),e+4},u.prototype.writeFloatLE=function(t,e,r){return M(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return M(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return R(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return R(this,t,e,!1,r)},u.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,o=n-r;if(this===t&&r<e&&e<n)for(i=o-1;i>=0;--i)t[i+e]=this[i+r];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+e]=this[i+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+o),e);return o},u.prototype.fill=function(t,e,r,n){if("string"===typeof t){if("string"===typeof e?(n=e,e=0,r=this.length):"string"===typeof r&&(n=r,r=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!==typeof n)throw new TypeError("encoding must be a string");if("string"===typeof n&&!u.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"===typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"===typeof t)for(o=e;o<r;++o)this[o]=t;else{var s=u.isBuffer(t)?t:L(new u(t,n).toString()),a=s.length;for(o=0;o<r-e;++o)this[o+e]=s[o%a]}return this};var F=/[^+\/0-9A-Za-z-_]/g;function I(t){return t<16?"0"+t.toString(16):t.toString(16)}function L(t,e){var r;e=e||1/0;for(var n=t.length,i=null,o=[],s=0;s<n;++s){if((r=t.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function U(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(F,"")).length<2)return"";for(;t.length%4!==0;)t+="=";return t}(t))}function V(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}}).call(this,r(6))},function(t,e,r){"use strict";var n=r(38);t.exports=n,n.messages=r(106),n.Messages=n.messages,n.DocumentNotFoundError=r(107),n.CastError=r(9),n.ValidationError=r(108),n.ValidatorError=r(109),n.VersionError=r(110),n.ParallelSaveError=r(111),n.OverwriteModelError=r(112),n.MissingSchemaError=r(113),n.DivergentArrayError=r(114)},function(t,e,r){"use strict";(function(t,n){function i(t){return(i="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var 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])_(a)||!w(a)?s+=" "+a:s+=" "+u(a);return s},e.deprecate=function(r,i){if(g(t.process))return function(){return e.deprecate(r,i).apply(this,arguments)};if(!0===n.noDeprecation)return r;var o=!1;return function(){if(!o){if(n.throwDeprecation)throw new Error(i);n.traceDeprecation?console.trace(i):console.error(i),o=!0}return r.apply(this,arguments)}};var s,a={};function u(t,r){var n={seen:[],stylize:l};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=c),f(n,t,n.depth)}function c(t,e){var r=u.styles[e];return r?"\x1b["+u.colors[r][0]+"m"+t+"\x1b["+u.colors[r][1]+"m":t}function l(t,e){return t}function f(t,r,n){if(t.customInspect&&r&&E(r.inspect)&&r.inspect!==e.inspect&&(!r.constructor||r.constructor.prototype!==r)){var i=r.inspect(n,t);return v(i)||(i=f(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(m(e))return t.stylize(""+e,"number");if(y(e))return t.stylize(""+e,"boolean");if(_(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 h(r);if(0===s.length){if(E(r)){var u=r.name?": "+r.name:"";return t.stylize("[Function"+u+"]","special")}if(b(r))return t.stylize(RegExp.prototype.toString.call(r),"regexp");if(O(r))return t.stylize(Date.prototype.toString.call(r),"date");if(S(r))return h(r)}var c,l="",w=!1,A=["{","}"];(d(r)&&(w=!0,A=["[","]"]),E(r))&&(l=" [Function"+(r.name?": "+r.name:"")+"]");return b(r)&&(l=" "+RegExp.prototype.toString.call(r)),O(r)&&(l=" "+Date.prototype.toUTCString.call(r)),S(r)&&(l=" "+h(r)),0!==s.length||w&&0!=r.length?n<0?b(r)?t.stylize(RegExp.prototype.toString.call(r),"regexp"):t.stylize("[Object]","special"):(t.seen.push(r),c=w?function(t,e,r,n,i){for(var o=[],s=0,a=e.length;s<a;++s)j(e,String(s))?o.push(p(t,e,r,n,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(p(t,e,r,n,i,!0))}),o}(t,r,n,a,s):s.map(function(e){return p(t,r,n,a,e,w)}),t.seen.pop(),function(t,e,r){if(t.reduce(function(t,e){return 0,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]}(c,l,A)):A[0]+l+A[1]}function h(t){return"["+Error.prototype.toString.call(t)+"]"}function p(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=_(r)?f(t,u.value,null):f(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 d(t){return Array.isArray(t)}function y(t){return"boolean"===typeof t}function _(t){return null===t}function m(t){return"number"===typeof t}function v(t){return"string"===typeof t}function g(t){return void 0===t}function b(t){return w(t)&&"[object RegExp]"===A(t)}function w(t){return"object"===i(t)&&null!==t}function O(t){return w(t)&&"[object Date]"===A(t)}function S(t){return w(t)&&("[object Error]"===A(t)||t instanceof Error)}function E(t){return"function"===typeof t}function A(t){return Object.prototype.toString.call(t)}function $(t){return t<10?"0"+t.toString(10):t.toString(10)}e.debuglog=function(t){if(g(s)&&(s=n.env.NODE_DEBUG||""),t=t.toUpperCase(),!a[t])if(new RegExp("\\b"+t+"\\b","i").test(s)){var r=n.pid;a[t]=function(){var n=e.format.apply(e,arguments);console.error("%s %d: %s",t,r,n)}}else a[t]=function(){};return a[t]},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=d,e.isBoolean=y,e.isNull=_,e.isNullOrUndefined=function(t){return null==t},e.isNumber=m,e.isString=v,e.isSymbol=function(t){return"symbol"===i(t)},e.isUndefined=g,e.isRegExp=b,e.isObject=w,e.isDate=O,e.isError=S,e.isFunction=E,e.isPrimitive=function(t){return null===t||"boolean"===typeof t||"number"===typeof t||"string"===typeof t||"symbol"===i(t)||"undefined"===typeof t},e.isBuffer=r(83);var N=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function j(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.log=function(){var t,r;console.log("%s - %s",(t=new Date,r=[$(t.getHours()),$(t.getMinutes()),$(t.getSeconds())].join(":"),[t.getDate(),N[t.getMonth()],r].join(" ")),e.format.apply(e,arguments))},e.inherits=r(84),e._extend=function(t,e){if(!e||!w(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t}}).call(this,r(6),r(7))},function(t,e,r){"use strict";(function(e,n){function i(t){return(i="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o,s,a,u=r(11).EventEmitter,c=r(92),l=r(2),f=r(42),h=r(43),p=r(75),d=r(124),y=r(72),_=r(5).ValidatorError,m=r(44),v=r(60),g=r(47).compile,b=r(47).defineKey,w=r(125).flatten,O=r(8),S=r(126),E=r(127),A=r(41),$=r(128),N=r(3).inspect,j=r(12).internalToObjectOptions,x=r(34),T=r(0),B=l.ValidationError,k=T.clone,C=T.deepEqual,D=T.isMongooseObject;function P(t,e,r,n){if("object"===i(r)&&null!=r&&(r=(n=r).skipId),n=n||{},this.$__=new c,this.$__.emitter=new u,this.isNew=!("isNew"in n)||n.isNew,this.errors=void 0,this.$__.$options=n||{},null!=t&&"object"!==i(t))throw new d(t,"obj","Document");var o=this.schema;"boolean"===typeof e?(this.$__.strictMode=e,e=void 0):(this.$__.strictMode=o.options&&o.options.strict,this.$__.selected=e);for(var s=o.requiredPaths(!0),a=0;a<s.length;++a)this.$__.activePaths.require(s[a]);this.$__.emitter.setMaxListeners(0);var l=null;e&&"Object"===T.getFunctionName(e.constructor)&&(l=$(e));var f=!1===l&&e?function(t){for(var e={},r=Object.keys(t),n=0;n<r.length;++n)for(var i=r[n].split("."),o=[],s=0;s<i.length;++s)o.push(i[s]),e[o.join(".")]=1;return e}(e):{};if(this.$__buildDoc(t,e,r,l,f,!1),M(this,e,r,l,f,!0),t&&(t instanceof P&&(this.isNew=t.isNew),this.$__original_set?this.$__original_set(t,void 0,!0):this.$set(t,void 0,!0)),M(this,e,r,l,f,!1,n.skipDefaults),this.$__._id=this._id,!o.options.strict&&t){var h=this;Object.keys(this._doc).forEach(function(t){t in o.tree||b(t,null,h)})}!function(t){var e,r=t.schema&&t.schema.callQueue;if(!r.length)return;for(var n=0;n<r.length;++n)"pre"!==(e=r[n])[0]&&"post"!==e[0]&&"on"!==e[0]&&t[e[0]].apply(t,e[1])}(this)}function M(t,e,r,n,i,o,s){for(var a=Object.keys(t.schema.paths),u=a.length,c=0;c<u;++c){var l=void 0,f="",h=a[c];if("_id"!==h||!r)for(var p=t.schema.paths[h],d=h.split("."),y=d.length,_=!1,m=t._doc,v=0;v<y&&null!=m;++v){var g=d[v];if(f+=(f.length?".":"")+g,!0===n){if(f in e)break}else if(!1===n&&e&&!_)if(f in e)_=!0;else if(!i[f])break;if(v===y-1){if(void 0!==m[g])break;if("function"===typeof p.defaultValue){if(!p.defaultValue.$runBeforeSetters&&o)break;if(p.defaultValue.$runBeforeSetters&&!o)break}else if(!o)continue;if(s&&s[f])break;if(e&&null!==n)if(!0===n){if(h in e)continue;"undefined"!==typeof(l=p.getDefault(t,!1))&&(m[g]=l,t.$__.activePaths.default(h))}else _&&"undefined"!==typeof(l=p.getDefault(t,!1))&&(m[g]=l,t.$__.activePaths.default(h));else"undefined"!==typeof(l=p.getDefault(t,!1))&&(m[g]=l,t.$__.activePaths.default(h))}else m=m[g]}}}function R(t){var e,r,n={};!function(t){Object.keys(t.$__.activePaths.states.require).forEach(function(e){var r=t.schema.path(e);"function"===typeof r.originalRequiredValue&&(r.$cachedRequired=r.originalRequiredValue.call(t))})}(t);var i=Object.keys(t.$__.activePaths.states.require).filter(function(e){if(!t.isSelected(e)&&!t.isModified(e))return!1;var r=t.schema.path(e);return!("$cachedRequired"in r)||r.$cachedRequired});if(i=(i=(i=i.concat(Object.keys(t.$__.activePaths.states.init))).concat(Object.keys(t.$__.activePaths.states.modify))).concat(Object.keys(t.$__.activePaths.states.default)),!t.ownerDocument){var o,s=t.$__getAllSubdocs();r=s.length;var a=t.modifiedPaths();for(e=0;e<r;++e)o=s[e],t.isModified(o.$basePath,a)&&!t.isDirectModified(o.$basePath)&&((i=i.filter(function(t){return null!=t&&0!==t.indexOf(o.$basePath+".")})).push(o.$basePath),n[o.$basePath]=!0)}for(r=i.length,e=0;e<r;++e){var u=i[e],c=t.schema.path(u);if(c&&c.$isMongooseArray&&(!c.$isMongooseDocumentArray||O(c,"schemaOptions.required"))){var l=t.getValue(u);if(l)for(var f=l.length,h=0;h<f;++h)i.push(u+"."+h)}}var p={skipArrays:!0};for(r=i.length,e=0;e<r;++e){var d=i[e];if(t.schema.nested[d]){var y=t.getValue(d);D(y)&&(y=y.toObject({transform:!1}));var _=w(y,"",p),m=Object.keys(_).map(function(t){return d+"."+t});i=i.concat(m)}}for(r=i.length,e=0;e<r;++e){var v=i[e],g=t.schema.path(v);if(g&&g.$isSchemaMap){var b=t.getValue(v);if(null!=b){var S=!0,E=!1,A=void 0;try{for(var $,N=b.keys()[Symbol.iterator]();!(S=($=N.next()).done);S=!0){var j=$.value;i.push(v+"."+j)}}catch(t){E=!0,A=t}finally{try{S||null==N.return||N.return()}finally{if(E)throw A}}}}}return[i,n]}function F(t,e,r,n){var i,o,s,a=t.schema,u=Object.keys(a[r]),c=u.length,l=c,f=t._doc;if(!f)return e;if("virtuals"===r){for(n=n||{},c=0;c<l;++c){if(o=i=u[c],null!=n.path){if(!i.startsWith(n.path+"."))continue;o=i.substr(n.path.length+1)}if(d=o.split("."),void 0!==(s=k(t.get(i),n))){y=d.length,f=e;for(var h=0;h<y-1;++h)f[d[h]]=f[d[h]]||{},f=f[d[h]];f[d[y-1]]=s}}return e}for(;c--;){var p,d=(i=u[c]).split("."),y=d.length,_=y-1,m=e;f=t._doc;for(var v=0;v<y;++v){if(s=f[p=d[v]],v===_)m[p]=k(t.get(i),n);else{if(null==s){p in f&&(m[p]=s);break}m=m[p]||(m[p]={})}f=s}}return e}T.each(["on","once","emit","listeners","removeListener","setMaxListeners","removeAllListeners","addListener"],function(t){P.prototype[t]=function(){return this.$__.emitter[t].apply(this.$__.emitter,arguments)}}),P.prototype.constructor=P,P.prototype.schema,P.prototype.isNew,P.prototype.id,P.prototype.errors,P.prototype.$__buildDoc=function(t,e,r,n,i){for(var o={},s=Object.keys(this.schema.paths).filter(function(t){return!t.includes("$*")}),a=s.length,u=0;u<a;++u){var c=s[u];if("_id"===c){if(r)continue;if(t&&"_id"in t)continue}for(var l=c.split("."),f=l.length,h=f-1,p="",d=o,y=!1,_=0;_<f;++_){var m=l[_];if(p+=(p.length?".":"")+m,!0===n){if(p in e)break}else if(!1===n&&e&&!y)if(p in e)y=!0;else if(!i[p])break;_<h&&(d=d[m]||(d[m]={}))}}this._doc=o},P.prototype.toBSON=function(){return this.toObject(j)},P.prototype.init=function(t,e,r){return"function"===typeof e&&(r=e,e=null),this.$__init(t,e),r&&r(null,this),this},P.prototype.$__init=function(t,e){if(this.isNew=!1,this.$init=!0,null!==t._id&&void 0!==t._id&&e&&e.populated&&e.populated.length)for(var r=String(t._id),n=0;n<e.populated.length;++n){var i=e.populated[n];i.isVirtual?this.populated(i.path,T.getValue(i.path,t),i):this.populated(i.path,i._docs[r],i)}return function t(e,r,n,i){i=i||"";var o=Object.keys(r);var s=o.length;var a;var u;var c;var l=0;for(;l<s;)f(l++);function f(s){if(c=o[s],u=i+c,a=e.schema.path(u),!e.schema.$isRootDiscriminator||e.isSelected(u))if(a||!T.isObject(r[c])||r[c].constructor&&"Object"!==T.getFunctionName(r[c].constructor))if(a){if(null===r[c])n[c]=null;else if(void 0!==r[c]){var l=r[c].$__||{},f=l.wasPopulated||null;if(a&&!f)try{n[c]=a.cast(r[c],e,!0)}catch(t){e.invalidate(t.path,new _({path:t.path,message:t.message,type:"cast",value:t.value}))}else n[c]=r[c]}e.isModified(u)||e.$__.activePaths.init(u)}else n[c]=r[c];else n[c]||(n[c]={}),t(e,r[c],n[c],u+".")}}(this,t,this._doc),this.emit("init",this),this.constructor.emit("init",this),this.$__._id=this._id,this},P.prototype.update=function(){var t=T.args(arguments);return t.unshift({_id:this._id}),this.constructor.update.apply(this.constructor,t)},P.prototype.$session=function(t){return 0===arguments.length?this.$__.session:(this.$__.session=t,t)},P.prototype.$set=function(t,e,r,n){r&&"Object"===T.getFunctionName(r.constructor)&&(n=r,r=void 0);var i=(n=n||{}).merge,o=r&&!0!==r,s=!0===r,a="strict"in n?n.strict:this.$__.strictMode;if(o&&((this.$__.adhocPaths||(this.$__.adhocPaths={}))[t]=h.interpretAsType(t,r,this.schema.options)),"string"!==typeof t){if(null!==t&&void 0!==t){var u=e?e+".":"";t instanceof P&&(t=t.$__isNested?t.toObject():t._doc);var c,d,_=Object.keys(t),m=_.length,g=0;if(0===m&&!this.schema.options.minimize)return e&&this.$set(e,{}),this;for(;g<m;)w.call(this,g++);return this}var b=t;t=e,e=b}function w(e){d=_[e];var r=u+d;if(c=this.schema.pathType(r),null===t[d]||void 0===t[d]||!T.isObject(t[d])||t[d].constructor&&"Object"!==T.getFunctionName(t[d].constructor)||"virtual"===c||"real"===c||this.$__path(r)instanceof f||this.schema.paths[r]&&this.schema.paths[r].options&&this.schema.paths[r].options.ref)if(a){if(s&&void 0===t[d]&&void 0!==this.get(d))return;if("adhocOrUndefined"===c&&(c=S(this,r,{typeOnly:!0})),"real"===c||"virtual"===c){var n=t[d];this.schema.paths[r]&&this.schema.paths[r].$isSingleNested&&t[d]instanceof P&&(n=n.toObject({virtuals:!1,transform:!1})),this.$set(u+d,n,s)}else if("nested"===c&&t[d]instanceof P)this.$set(u+d,t[d].toObject({transform:!1}),s);else if("throw"===a)throw"nested"===c?new p(d,t[d]):new y(d)}else void 0!==t[d]&&this.$set(u+d,t[d],s);else this.$set(t[d],u+d,s)}var O,E=this.schema.pathType(t);if("nested"===E&&e){if(T.isObject(e)&&(!e.constructor||"Object"===T.getFunctionName(e.constructor))){if(i)return this.$set(e,t,s);this.setValue(t,null),v(this,t);var A=Object.keys(e);this.setValue(t,{});for(var $=0;$<A.length;$++){var N=A[$];this.$set(t+"."+N,e[N],s)}return this.markModified(t),v(this,t,{skipDocArrays:!0}),this}return this.invalidate(t,new l.CastError("Object",e,t)),this}var j=t.split(".");if("adhocOrUndefined"===E&&a){var B;for(g=0;g<j.length;++g){var k=j.slice(0,g+1).join(".");if(g+1<j.length&&"virtual"===this.schema.pathType(k))return x.set(t,e,this),this;if(null!=(O=this.schema.path(k))&&O instanceof f){B=!0;break}}if(null==O&&(O=S(this,t)),!B&&!O){if("throw"===a)throw new y(t);return this}}else{if("virtual"===E)return(O=this.schema.virtualpath(t)).applySetters(e,this),this;O=this.$__path(t)}var C,D=this._doc,M="";for(g=0;g<j.length-1;++g)D=D[j[g]],M+=(M.length>0?".":"")+j[g],D||(this.$set(M,{}),this.isSelected(M)||this.unmarkModified(M),D=this.getValue(M));if(j.length<=1)C=t;else{for(g=0;g<j.length;++g)if(k=j.slice(0,g+1).join("."),this.isDirectModified(k)||null===this.get(k)){C=k;break}C||(C=t)}var R=s?void 0:this.getValue(t);if(!O)return this.$__set(C,t,s,j,O,e,R),this;var F=!0;try{var I,L=!1;O.options&&O.options.ref&&e instanceof P&&(O.options.ref===e.constructor.modelName||O.options.ref===e.constructor.baseModelName)&&(this.ownerDocument?this.ownerDocument().populated(this.$__fullPath(t),e._id,{model:e.constructor}):this.populated(t,e._id,{model:e.constructor}),L=!0),O.options&&Array.isArray(O.options[this.schema.options.typeKey])&&O.options[this.schema.options.typeKey].length&&O.options[this.schema.options.typeKey][0].ref&&Array.isArray(e)&&e.length>0&&e[0]instanceof P&&e[0].constructor.modelName&&(O.options[this.schema.options.typeKey][0].ref===e[0].constructor.baseModelName||O.options[this.schema.options.typeKey][0].ref===e[0].constructor.modelName)&&(this.ownerDocument?(I={model:e[0].constructor},this.ownerDocument().populated(this.$__fullPath(t),e.map(function(t){return t._id}),I)):(I={model:e[0].constructor},this.populated(t,e.map(function(t){return t._id}),I)),L=!0);var U=s&&this.$__.$options.priorDoc?this.$__.$options.priorDoc:this;e=O.applySetters(e,U,!1,R),!L&&this.$__.populated&&delete this.$__.populated[t],this.$markValid(t)}catch(r){this.invalidate(t,new l.CastError(O.instance,e,t,r)),F=!1}return F&&this.$__set(C,t,s,j,O,e,R),O.$isSingleNested&&(this.isDirectModified(t)||null==e)&&v(this,t),this},P.prototype.set=P.prototype.$set,P.prototype.$__shouldModify=function(t,e,r,n,i,o,s){return!!this.isNew||(void 0===o&&!this.isSelected(e)||!(void 0===o&&e in this.$__.activePaths.states.default)&&(!(this.populated(e)&&o instanceof P&&C(o._id,s))&&(!C(o,s||this.get(e))||!!(!r&&null!==o&&void 0!==o&&e in this.$__.activePaths.states.default&&C(o,i.getDefault(this,r))))))},P.prototype.$__set=function(t,e,n,i,o,u,c){a=a||r(17);var l=this;this.$__shouldModify(t,e,n,i,o,u,c)&&(this.markModified(t),s||(s=r(35)),u&&u.isMongooseArray&&(u._registerAtomic("$set",u),u.isMongooseDocumentArray&&u.forEach(function(t){t&&t.__parentArray&&(t.__parentArray=u)}),this.$__.activePaths.forEach(function(t){0===t.indexOf(e+".")&&l.$__.activePaths.ignore(t)})));for(var f=this._doc,h=0,p=i.length,d="";h<p;h++){var y=h+1===p;d+=d?"."+i[h]:i[h],y?f instanceof Map?f.set(i[h],u):f[i[h]]=u:f[i[h]]&&"Object"===T.getFunctionName(f[i[h]].constructor)?f=f[i[h]]:f[i[h]]&&f[i[h]]instanceof a?f=f[i[h]]:f[i[h]]&&f[i[h]].$isSingleNested?f=f[i[h]]:f[i[h]]&&Array.isArray(f[i[h]])?f=f[i[h]]:(f[i[h]]=f[i[h]]||{},f=f[i[h]])}},P.prototype.getValue=function(t){return T.getValue(t,this._doc)},P.prototype.setValue=function(t,e){return T.setValue(t,e,this._doc),this},P.prototype.get=function(t,e,r){var n;r=r||{},e&&(n=h.interpretAsType(t,e,this.schema.options));var i=this.$__path(t)||this.schema.virtualpath(t),o=t.split("."),s=this._doc;if(i instanceof m){if(0===i.getters.length)return;return i.applyGetters(null,this)}for(var a=0,u=o.length;a<u;a++)s=null==s?void 0:s instanceof Map?s.get(o[a]):a===u-1?T.getValue(o[a],s):s[o[a]];if(n&&(s=n.cast(s)),i)s=i.applyGetters(s,this);else if(this.schema.nested[t]&&r.virtuals)return F(this,T.clone(s),"virtuals",{path:t});return s},P.prototype.$__path=function(t){var e=this.$__.adhocPaths,r=e&&e[t];return r||this.schema.path(t)},P.prototype.markModified=function(t,e){this.$__.activePaths.modify(t),null==e||this.ownerDocument||(this.$__.pathsToScopes[t]=e)},P.prototype.unmarkModified=function(t){this.$__.activePaths.init(t),delete this.$__.pathsToScopes[t]},P.prototype.$ignore=function(t){this.$__.activePaths.ignore(t)},P.prototype.modifiedPaths=function(t){t=t||{};var e=this;return Object.keys(this.$__.activePaths.states.modify).reduce(function(r,n){var o=n.split(".");if(r=r.concat(o.reduce(function(t,e,r){return t.concat(o.slice(0,r).concat(e).join("."))},[]).filter(function(t){return-1===r.indexOf(t)})),!t.includeChildren)return r;var s=e.get(n);if(null!=s&&"object"===i(s))if(s._doc&&(s=s._doc),Array.isArray(s)){for(var a=s.length,u=0;u<a;++u)if(-1===r.indexOf(n+"."+u)&&(r.push(n+"."+u),null!=s[u]&&s[u].$__)){var c=s[u].modifiedPaths(),l=!0,f=!1,h=void 0;try{for(var p,d=c[Symbol.iterator]();!(l=(p=d.next()).done);l=!0){var y=p.value;r.push(n+"."+u+"."+y)}}catch(t){f=!0,h=t}finally{try{l||null==d.return||d.return()}finally{if(f)throw h}}}}else Object.keys(s).filter(function(t){return-1===r.indexOf(n+"."+t)}).forEach(function(t){r.push(n+"."+t)});return r},[])},P.prototype.isModified=function(t,e){if(t){Array.isArray(t)||(t=t.split(" "));var r=e||this.modifiedPaths(),n=Object.keys(this.$__.activePaths.states.modify);return t.some(function(t){return!!~r.indexOf(t)})||t.some(function(t){return n.some(function(e){return e===t||0===t.indexOf(e+".")})})}return this.$__.activePaths.some("modify")},P.prototype.$isDefault=function(t){return t in this.$__.activePaths.states.default},P.prototype.$isDeleted=function(t){return 0===arguments.length?!!this.$__.isDeleted:(this.$__.isDeleted=!!t,this)},P.prototype.isDirectModified=function(t){return t in this.$__.activePaths.states.modify},P.prototype.isInit=function(t){return t in this.$__.activePaths.states.init},P.prototype.isSelected=function(t){if(this.$__.selected){if("_id"===t)return 0!==this.$__.selected._id;var e,r=Object.keys(this.$__.selected),n=r.length,i=null;if(1===n&&"_id"===r[0])return 0===this.$__.selected._id;for(;n--;)if("_id"!==(e=r[n])&&A(this.$__.selected[e])){i=!!this.$__.selected[e];break}if(null===i)return!0;if(t in this.$__.selected)return i;n=r.length;for(var o=t+".";n--;)if("_id"!==(e=r[n])){if(0===e.indexOf(o))return i||e!==o;if(0===o.indexOf(e+"."))return i}return!i}return!0},P.prototype.isDirectSelected=function(t){if(this.$__.selected){if("_id"===t)return 0!==this.$__.selected._id;var e,r=Object.keys(this.$__.selected),n=r.length,i=null;if(1===n&&"_id"===r[0])return 0===this.$__.selected._id;for(;n--;)if("_id"!==(e=r[n])&&A(this.$__.selected[e])){i=!!this.$__.selected[e];break}return null===i||(t in this.$__.selected?i:!i)}return!0},P.prototype.validate=function(t,e){var r=this;return"function"===typeof t&&(e=t,t=null),T.promiseOrCallback(e,function(t){return r.$__validate(function(e){t(e)})})},P.prototype.$__validate=function(t){var r=this,n=function(){var t=r.$__.validationError;if(r.$__.validationError=void 0,r.emit("validate",r),r.constructor.emit("validate",r),t){for(var e in t.errors)!r.__parent&&t.errors[e]instanceof l.CastError&&r.invalidate(e,t.errors[e]);return t}},i=R(this),o=i[0],s=i[1];if(0===o.length)return e.nextTick(function(){var e=n();if(e)return r.schema.s.hooks.execPost("validate:error",r,[r],{error:e},function(e){t(e)});t(null,r)});for(var a={},u=0,c=function(){var e=n();if(e)return r.schema.s.hooks.execPost("validate:error",r,[r],{error:e},function(e){t(e)});t(null,r)},f=function(t){null==t||a[t]||(a[t]=!0,u++,e.nextTick(function(){var e=r.schema.path(t);if(!e)return--u||c();if(r.$isValid(t)){var n=r.getValue(t),i=t in r.$__.pathsToScopes?r.$__.pathsToScopes[t]:r;e.doValidate(n,function(e){e&&r.invalidate(t,e,void 0,!0),--u||c()},i,{skipSchemaValidators:s[t]})}else--u||c()}))},h=o.length,p=0;p<h;++p)f(o[p])},P.prototype.validateSync=function(t){var e=this;"string"===typeof t&&(t=t.split(" "));var r=R(this),n=r[0],i=r[1];if(t&&t.length){for(var o=[],s=0;s<n.length;++s)-1!==t.indexOf(n[s])&&o.push(n[s]);n=o}var a={};n.forEach(function(t){if(!a[t]){a[t]=!0;var r=e.schema.path(t);if(r&&e.$isValid(t)){var n=e.getValue(t),o=r.doValidateSync(n,e,{skipSchemaValidators:i[t]});o&&e.invalidate(t,o,void 0,!0)}}});var u=e.$__.validationError;if(e.$__.validationError=void 0,e.emit("validate",e),e.constructor.emit("validate",e),u)for(var c in u.errors)u.errors[c]instanceof l.CastError&&e.invalidate(c,u.errors[c]);return u},P.prototype.invalidate=function(t,e,r,n){if(this.$__.validationError||(this.$__.validationError=new B(this)),!this.$__.validationError.errors[t])return e&&"string"!==typeof e||(e=new _({path:t,message:e,type:n||"user defined",value:r})),this.$__.validationError===e?this.$__.validationError:(this.$__.validationError.addError(t,e),this.$__.validationError)},P.prototype.$markValid=function(t){this.$__.validationError&&this.$__.validationError.errors[t]&&(delete this.$__.validationError.errors[t],0===Object.keys(this.$__.validationError.errors).length&&(this.$__.validationError=null))},P.prototype.$isValid=function(t){return!this.$__.validationError||!this.$__.validationError.errors[t]},P.prototype.$__reset=function(){var t=this;return o||(o=r(13)),this.$__.activePaths.map("init","modify",function(e){return t.getValue(e)}).filter(function(t){return t&&t instanceof Array&&t.isMongooseDocumentArray&&t.length}).forEach(function(t){for(var e=t.length;e--;){var r=t[e];r&&r.$__reset()}}),this.$__.activePaths.map("init","modify",function(e){return t.getValue(e)}).filter(function(t){return t&&t.$isSingleNested}).forEach(function(t){t.$__reset()}),this.$__dirty().forEach(function(t){var e=t.value;e&&e._atomics&&(e._atomics={})}),this.$__.activePaths.clear("modify"),this.$__.activePaths.clear("default"),this.$__.validationError=void 0,this.errors=void 0,t=this,this.schema.requiredPaths().forEach(function(e){t.$__.activePaths.require(e)}),this},P.prototype.$__dirty=function(){var t=this,e=this.$__.activePaths.map("modify",function(e){return{path:e,value:t.getValue(e),schema:t.$__path(e)}});(e=e.concat(this.$__.activePaths.map("default",function(e){if("_id"!==e&&null!=t.getValue(e))return{path:e,value:t.getValue(e),schema:t.$__path(e)}}))).sort(function(t,e){return t.path<e.path?-1:t.path>e.path?1:0});var r,n,i=[];return e.forEach(function(t){t&&(0!==t.path.indexOf(r)?(r=t.path+".",i.push(t),n=t):n.value&&n.value._atomics&&n.value.hasAtomics()&&(n.value._atomics={},n.value._atomics.$set=n.value))}),n=r=null,i},P.prototype.$__setSchema=function(t){t.plugin(E,{deduplicate:!0}),g(t.tree,this,void 0,t.options);for(var e=Object.keys(t.virtuals),r=0;r<e.length;r++){var n=e[r];t.virtuals[n]._applyDefaultGetters()}this.schema=t},P.prototype.$__getArrayPathsToValidate=function(){return o||(o=r(13)),this.$__.activePaths.map("init","modify",function(t){return this.getValue(t)}.bind(this)).filter(function(t){return t&&t instanceof Array&&t.isMongooseDocumentArray&&t.length}).reduce(function(t,e){return t.concat(e)},[]).filter(function(t){return t})},P.prototype.$__getAllSubdocs=function(){o||(o=r(13)),a=a||r(17);var t=this;return Object.keys(this._doc).reduce(function(e,r){return function t(e,r,n){var i=e[n];return i instanceof a&&r.push(i),i&&i.$isSingleNested&&(r=Object.keys(i._doc).reduce(function(e,r){return t(i._doc,e,r)},r)).push(i),i&&i.isMongooseDocumentArray?i.forEach(function(e){e&&e._doc&&(e instanceof a&&r.push(e),r=Object.keys(e._doc).reduce(function(r,n){return t(e._doc,r,n)},r))}):i instanceof P&&i.$__isNested&&i&&(r=Object.keys(i).reduce(function(e,r){return t(i,e,r)},r)),r}(t,e,r)},[])},P.prototype.$__handleReject=function(t){this.listeners("error").length?this.emit("error",t):this.constructor.listeners&&this.constructor.listeners("error").length?this.constructor.emit("error",t):this.listeners&&this.listeners("error").length&&this.emit("error",t)},P.prototype.$toObject=function(t,e){var r,i={transform:!0,flattenDecimals:!0},o=O(this,"schema.options",{});e&&o.toJSON?i=T.options(i,k(o.toJSON)):o.toObject&&(i=T.options(i,k(o.toObject))),r=null!=(t=t&&"Object"===T.getFunctionName(t.constructor)?k(t):{}).minimize?t.minimize:null!=i.minimize?i.minimize:o.minimize;var s=Object.assign(T.clone(t),{_isNested:!0,json:e,minimize:r});if((t.depopulate||O(t,"_parentOptions.depopulate",!1))&&t._isNested&&this.$__.wasPopulated)return k(this._id,s);(t=T.options(i,t))._isNested=!0,t.json=e,t.minimize=r,s._parentOptions=t;var a=t.transform,u=k(this._doc,s)||{};t.getters&&(F(this,u,"paths",s),t.minimize&&(u=function t(e){var r,i,o,s=Object.keys(e),a=s.length;for(;a--;)i=s[a],o=e[i],T.isObject(o)&&!n.isBuffer(o)&&(e[i]=t(o)),void 0!==e[i]?r=!0:delete e[i];return r?e:void 0}(u)||{})),(t.virtuals||t.getters&&!1!==t.virtuals)&&F(this,u,"virtuals",s),!1===t.versionKey&&this.schema.options.versionKey&&delete u[this.schema.options.versionKey];var c=t.transform;if(!0===c||o.toObject&&c){var l=t.json?o.toJSON:o.toObject;l&&(c="function"===typeof t.transform?t.transform:l.transform)}else t.transform=a;if("function"===typeof c){var f=c(this,u,t);"undefined"!==typeof f&&(u=f)}return u},P.prototype.toObject=function(t){return this.$toObject(t)},P.prototype.toJSON=function(t){return this.$toObject(t,!0)},P.prototype.inspect=function(t){var e;return t&&"Object"===T.getFunctionName(t.constructor)&&((e=t).minimize=!1),this.toObject(e)},N.custom&&(P.prototype[N.custom]=P.prototype.inspect),P.prototype.toString=function(){return N(this.inspect())},P.prototype.equals=function(t){if(!t)return!1;var e=this.get("_id"),r=t.get?t.get("_id"):t;return e||r?e&&e.equals?e.equals(r):e===r:C(this,t)},P.prototype.populate=function(){if(0===arguments.length)return this;var t,e=this.$__.populate||(this.$__.populate={}),r=T.args(arguments);if("function"===typeof r[r.length-1]&&(t=r.pop()),r.length)for(var n=T.populate.apply(null,r),i=0;i<n.length;++i)e[n[i].path]=n[i];if(t){var o=T.object.vals(e);this.$__.populate=void 0;var s=this.constructor;if(this.$__isNested){s=this.$__.scope.constructor;var a=this.$__.nestedPath;o.forEach(function(t){t.path=a+"."+t.path})}if(null!=this.$session()){var u=this.$session();o.forEach(function(t){null!=t.options?"session"in t.options||(t.options.session=u):t.options={session:u}})}s.populate(this,o,t)}return this},P.prototype.execPopulate=function(){var t=this;return T.promiseOrCallback(null,function(e){t.populate(e)})},P.prototype.populated=function(t,e,r){if(null===e||void 0===e){if(!this.$__.populated)return;var n=this.$__.populated[t];return n?n.value:void 0}if(!0===e){if(!this.$__.populated)return;return this.$__.populated[t]}return this.$__.populated||(this.$__.populated={}),this.$__.populated[t]={value:e,options:r},e},P.prototype.depopulate=function(t){var e,r;if("string"===typeof t&&(t=t.split(" ")),0===arguments.length){var n=Object.keys(this.$__.populated);for(e=0;e<n.length;e++)(r=this.populated(n[e]))&&(delete this.$__.populated[n[e]],this.$set(n[e],r));return this}for(e=0;e<t.length;e++)(r=this.populated(t[e]))&&(delete this.$__.populated[t[e]],this.$set(t[e],r));return this},P.prototype.$__fullPath=function(t){return t||""},P.ValidationError=B,t.exports=P}).call(this,r(7),r(1).Buffer)},function(t,e,r){"use strict";(function(n){function i(t){return(i="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=r(2),s=r(39),a=r(62),u=r(36),c=r(0),l=o.CastError,f=o.ValidatorError;function h(t,e,r){for(var n in this.path=t,this.instance=r,this.validators=[],this.setters=[],this.getters=[],this.options=e,this._index=null,this.selected,e)if(this[n]&&"function"===typeof this[n]){if("index"===n&&this._index)continue;var i=e[n];if("default"===n){this.default(i);continue}var o=Array.isArray(i)?i:[i];this[n].apply(this,o)}Object.defineProperty(this,"$$context",{enumerable:!1,configurable:!1,writable:!0,value:null})}function p(t){return this.castForQuery(t)}function d(t){var e=this;return Array.isArray(t)?t.map(function(t){return e.castForQuery(t)}):[this.castForQuery(t)]}h.prototype.default=function(t){return 1===arguments.length?void 0===t?void(this.defaultValue=void 0):(this.defaultValue=t,this.defaultValue):(arguments.length>1&&(this.defaultValue=c.args(arguments)),this.defaultValue)},h.prototype.index=function(t){return this._index=t,c.expires(this._index),this},h.prototype.unique=function(t){if(!1===this._index){if(!t)return;throw new Error('Path "'+this.path+'" may not have `index` set to false and `unique` set to true')}return null==this._index||!0===this._index?this._index={}:"string"===typeof this._index&&(this._index={type:this._index}),this._index.unique=t,this},h.prototype.text=function(t){return null===this._index||void 0===this._index||"boolean"===typeof this._index?this._index={}:"string"===typeof this._index&&(this._index={type:this._index}),this._index.text=t,this},h.prototype.sparse=function(t){return null===this._index||void 0===this._index||"boolean"===typeof this._index?this._index={}:"string"===typeof this._index&&(this._index={type:this._index}),this._index.sparse=t,this},h.prototype.set=function(t){if("function"!==typeof t)throw new TypeError("A setter must be a function.");return this.setters.push(t),this},h.prototype.get=function(t){if("function"!==typeof t)throw new TypeError("A getter must be a function.");return this.getters.push(t),this},h.prototype.validate=function(t,e,r){var n,s,a,u;if("function"===typeof t||t&&"RegExp"===c.getFunctionName(t.constructor))return e instanceof Object&&!r?((n=c.clone(e)).message||(n.message=n.msg),n.validator=t,n.type=n.type||"user defined"):(e||(e=o.messages.general.default),r||(r="user defined"),n={message:e,type:r,validator:t}),this.validators.push(n),this;for(s=0,a=arguments.length;s<a;s++){if(!(u=arguments[s])||"Object"!==c.getFunctionName(u.constructor)){var l="Invalid validator. Received ("+i(u)+") "+u+". See http://mongoosejs.com/docs/api.html#schematype_SchemaType-validate";throw new Error(l)}this.validate(u.validator,u)}return this},h.prototype.required=function(t,e){var r={};if("object"===i(t)&&(e=(r=t).message||e,t=t.isRequired),!1===t)return this.validators=this.validators.filter(function(t){return t.validator!==this.requiredValidator},this),this.isRequired=!1,this;var n=this;this.isRequired=!0,this.requiredValidator=function(e){if(null!=this&&this.$__&&!this.isSelected(n.path)&&!this.isModified(n.path))return!0;if("$cachedRequired"in n){var r=!n.$cachedRequired||n.checkRequired(e,this);return delete n.$cachedRequired,r}return"function"===typeof t&&!t.apply(this)||n.checkRequired(e,this)},this.originalRequiredValue=t,"string"===typeof t&&(e=t,t=void 0);var s=e||o.messages.general.required;return this.validators.unshift(Object.assign({},r,{validator:this.requiredValidator,message:s,type:"required"})),this},h.prototype.getDefault=function(t,e){var r="function"===typeof this.defaultValue?this.defaultValue.call(t):this.defaultValue;if(null!==r&&void 0!==r){"object"!==i(r)||this.options&&this.options.shared||(r=c.clone(r));var n=this.cast(r,t,e);return n&&n.$isSingleNested&&(n.$parent=t),n}return r},h.prototype._applySetters=function(t,e,r,n){for(var i=t,o=this.setters,s=o.length,a=this.caster;s--;)i=o[s].call(e,i,this);if(Array.isArray(i)&&a&&a.setters){for(var u=[],c=0;c<i.length;c++)u.push(a.applySetters(i[c],e,r,n));i=u}return i},h.prototype.applySetters=function(t,e,r,n,i){var o=this._applySetters(t,e,r,n,i);return null==o?o:o=this.cast(o,e,r,n,i)},h.prototype.applyGetters=function(t,e){var r=t,n=this.getters,i=n.length;if(0===i)return r;for(var o=0;o<i;++o)r=n[o].call(e,r,this);return r},h.prototype.select=function(t){return this.selected=!!t,this},h.prototype.doValidate=function(t,e,r){var n=!1,i=this.path,o=this.validators.length;if(!o)return e(null);var s=function(t,r){if(!n)if(void 0===t||t)--o<=0&&u(function(){e(null)});else{var i=r.ErrorConstructor||f;(n=new i(r)).$isValidatorError=!0,u(function(){e(n)})}},a=this;this.validators.forEach(function(e){if(!n){var o,u=e.validator,l=c.clone(e);if(l.path=i,l.value=t,u instanceof RegExp)s(u.test(t),l);else if("function"===typeof u){if(void 0===t&&u!==a.requiredValidator)return void s(!0,l);if(l.isAsync)!function(t,e,r,n,i){var o=!1,s=t.call(e,r,function(t,e){o||(o=!0,"boolean"!==typeof s&&(e&&(n.message=e),i(t,n)))});"boolean"===typeof s?(o=!0,i(s,n)):s&&"function"===typeof s.then&&s.then(function(t){o||(o=!0,i(t,n))},function(t){o||(o=!0,n.reason=t,i(!1,n))})}(u,r,t,l,s);else{try{o=u.call(r,t,l)}catch(t){o=!1,l.reason=t,t.message&&(l.message=t.message)}null!=o&&"function"===typeof o.then?o.then(function(t){s(t,l)},function(t){l.reason=t,s(o=!1,l)}):s(o,l)}}}})},h.prototype.doValidateSync=function(t,e){var r=null,n=this.path;if(!this.validators.length)return null;var i=function(t,e){if(!r&&void 0!==t&&!t){var n=e.ErrorConstructor||f;(r=new n(e)).$isValidatorError=!0}},o=this.validators;if(void 0===t){if(!(this.validators.length>0&&"required"===this.validators[0].type))return null;o=[this.validators[0]]}return o.forEach(function(o){if(!r){var s,a=o.validator,u=c.clone(o);if(u.path=n,u.value=t,a instanceof RegExp)i(a.test(t),u);else if("function"===typeof a&&2!==a.length&&!u.isAsync){try{s=a.call(e,t)}catch(t){s=!1,u.reason=t}i(s,u)}}}),r},h._isRef=function(t,e,r,i){var o=i&&t.options&&t.options.ref;if(!o&&r&&r.$__fullPath){var s=r.$__fullPath(t.path);o=(r.ownerDocument?r.ownerDocument():r).populated(s)}if(o){if(null==e)return!0;if(!n.isBuffer(e)&&"Binary"!==e._bsontype&&c.isObject(e))return!0}return!1},h.prototype.$conditionalHandlers={$all:d,$eq:p,$in:function(t){var e=this;return Array.isArray(t)?t.map(function(t){return Array.isArray(t)&&0===t.length?t:e.castForQuery(t)}):[this.castForQuery(t)]},$ne:p,$nin:d,$exists:s,$type:a},h.prototype.castForQueryWrapper=function(t){return this.$$context=t.context,"$conditional"in t?this.castForQuery(t.$conditional,t.val):t.$skipQueryCastForUpdate?this._castForQuery(t.val):this.castForQuery(t.val)},h.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t);return r.call(this,e)}return e=t,this._castForQuery(e)},h.prototype._castForQuery=function(t){return this.applySetters(t,this.$$context)},h.prototype.checkRequired=function(t){return null!=t},t.exports=e=h,e.CastError=l,e.ValidatorError=f}).call(this,r(1).Buffer)},function(t,e,r){"use strict";function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i;i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(t){"object"===("undefined"===typeof window?"undefined":n(window))&&(i=window)}t.exports=i},function(t,e,r){"use strict";var n,i,o=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(t){if(n===setTimeout)return setTimeout(t,0);if((n===s||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"===typeof setTimeout?setTimeout:s}catch(t){n=s}try{i="function"===typeof clearTimeout?clearTimeout:a}catch(t){i=a}}();var c,l=[],f=!1,h=-1;function p(){f&&c&&(f=!1,c.length?l=c.concat(l):h=-1,l.length&&d())}function d(){if(!f){var t=u(p);f=!0;for(var e=l.length;e;){for(c=l,l=[];++h<e;)c&&c[h].run();h=-1,e=l.length}c=null,f=!1,function(t){if(i===clearTimeout)return clearTimeout(t);if((i===a||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(t);try{i(t)}catch(e){try{return i.call(null,t)}catch(e){return i.call(this,t)}}}(t)}}function y(t,e){this.fun=t,this.array=e}function _(){}o.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];l.push(new y(t,e)),1!==l.length||f||u(d)},y.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=_,o.addListener=_,o.once=_,o.off=_,o.removeListener=_,o.removeAllListeners=_,o.emit=_,o.prependListener=_,o.prependOnceListener=_,o.listeners=function(t){return[]},o.binding=function(t){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(t){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(t,e,r){"use strict";(function(e){function r(t){return(r="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var n="Expected a function",i="__lodash_hash_undefined__",o=1/0,s="[object Function]",a="[object GeneratorFunction]",u="[object Symbol]",c=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,l=/^\w*$/,f=/^\./,h=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,p=/\\(\\)?/g,d=/^\[object .+?Constructor\]$/,y="object"==("undefined"===typeof e?"undefined":r(e))&&e&&e.Object===Object&&e,_="object"==("undefined"===typeof self?"undefined":r(self))&&self&&self.Object===Object&&self,m=y||_||Function("return this")();var v,g=Array.prototype,b=Function.prototype,w=Object.prototype,O=m["__core-js_shared__"],S=(v=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+v:"",E=b.toString,A=w.hasOwnProperty,$=w.toString,N=RegExp("^"+E.call(A).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),j=m.Symbol,x=g.splice,T=U(m,"Map"),B=U(Object,"create"),k=j?j.prototype:void 0,C=k?k.toString:void 0;function D(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function P(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function M(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function R(t,e){for(var r,n,i=t.length;i--;)if((r=t[i][0])===(n=e)||r!==r&&n!==n)return i;return-1}function F(t,e){for(var n,i=0,o=(e=function(t,e){if(H(t))return!1;var n=r(t);if("number"==n||"symbol"==n||"boolean"==n||null==t||z(t))return!0;return l.test(t)||!c.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:H(n=e)?n:V(n)).length;null!=t&&i<o;)t=t[q(e[i++])];return i&&i==o?t:void 0}function I(t){return!(!Y(t)||S&&S in t)&&(function(t){var e=Y(t)?$.call(t):"";return e==s||e==a}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?N:d).test(function(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function L(t,e){var n,i,o=t.__data__;return("string"==(i=r(n=e))||"number"==i||"symbol"==i||"boolean"==i?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function U(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return I(r)?r:void 0}D.prototype.clear=function(){this.__data__=B?B(null):{}},D.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},D.prototype.get=function(t){var e=this.__data__;if(B){var r=e[t];return r===i?void 0:r}return A.call(e,t)?e[t]:void 0},D.prototype.has=function(t){var e=this.__data__;return B?void 0!==e[t]:A.call(e,t)},D.prototype.set=function(t,e){return this.__data__[t]=B&&void 0===e?i:e,this},P.prototype.clear=function(){this.__data__=[]},P.prototype.delete=function(t){var e=this.__data__,r=R(e,t);return!(r<0)&&(r==e.length-1?e.pop():x.call(e,r,1),!0)},P.prototype.get=function(t){var e=this.__data__,r=R(e,t);return r<0?void 0:e[r][1]},P.prototype.has=function(t){return R(this.__data__,t)>-1},P.prototype.set=function(t,e){var r=this.__data__,n=R(r,t);return n<0?r.push([t,e]):r[n][1]=e,this},M.prototype.clear=function(){this.__data__={hash:new D,map:new(T||P),string:new D}},M.prototype.delete=function(t){return L(this,t).delete(t)},M.prototype.get=function(t){return L(this,t).get(t)},M.prototype.has=function(t){return L(this,t).has(t)},M.prototype.set=function(t,e){return L(this,t).set(t,e),this};var V=W(function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(z(t))return C?C.call(t):"";var e=t+"";return"0"==e&&1/t==-o?"-0":e}(e);var r=[];return f.test(t)&&r.push(""),t.replace(h,function(t,e,n,i){r.push(n?i.replace(p,"$1"):e||t)}),r});function q(t){if("string"==typeof t||z(t))return t;var e=t+"";return"0"==e&&1/t==-o?"-0":e}function W(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError(n);var r=function r(){var n=arguments,i=e?e.apply(this,n):n[0],o=r.cache;if(o.has(i))return o.get(i);var s=t.apply(this,n);return r.cache=o.set(i,s),s};return r.cache=new(W.Cache||M),r}W.Cache=M;var H=Array.isArray;function Y(t){var e=r(t);return!!t&&("object"==e||"function"==e)}function z(t){return"symbol"==r(t)||function(t){return!!t&&"object"==r(t)}(t)&&$.call(t)==u}t.exports=function(t,e,r){var n=null==t?void 0:F(t,e);return void 0===n?r:n}}).call(this,r(6))},function(t,e,r){"use strict";var n=r(38),i=r(3);function o(t,e,r,o){var s=i.inspect(e);'"'!==(s=s.replace(/^'/,'"').replace(/'$/,'"')).charAt(0)&&(s='"'+s+'"'),n.call(this,"Cast to "+t+" failed for value "+s+' at path "'+r+'"'),this.name="CastError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack,this.stringValue=s,this.kind=t,this.value=e,this.path=r,this.reason=o}o.prototype=Object.create(n.prototype),o.prototype.constructor=n,o.prototype.setModel=function(t){this.model=t,this.message="Cast to "+this.kind+" failed for value "+this.stringValue+' at path "'+this.path+'" for model "'+t.modelName+'"'},t.exports=o},function(t,e,r){"use strict";var n=r(14).get().ObjectId;Object.defineProperty(n.prototype,"_id",{enumerable:!1,configurable:!0,get:function(){return this}}),t.exports=n},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)}function i(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(t){return"function"===typeof t}function s(t){return"object"===n(t)&&null!==t}function a(t){return void 0===t}t.exports=i,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._maxListeners=void 0,i.defaultMaxListeners=10,i.prototype.setMaxListeners=function(t){if("number"!==typeof t||t<0||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},i.prototype.emit=function(t){var e,r,n,i,u,c;if(this._events||(this._events={}),"error"===t&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if((e=arguments[1])instanceof Error)throw e;var l=new Error('Uncaught, unspecified "error" event. ('+e+")");throw l.context=e,l}if(a(r=this._events[t]))return!1;if(o(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:i=Array.prototype.slice.call(arguments,1),r.apply(this,i)}else if(s(r))for(i=Array.prototype.slice.call(arguments,1),n=(c=r.slice()).length,u=0;u<n;u++)c[u].apply(this,i);return!0},i.prototype.addListener=function(t,e){var r;if(!o(e))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,o(e.listener)?e.listener:e),this._events[t]?s(this._events[t])?this._events[t].push(e):this._events[t]=[this._events[t],e]:this._events[t]=e,s(this._events[t])&&!this._events[t].warned&&(r=a(this._maxListeners)?i.defaultMaxListeners:this._maxListeners)&&r>0&&this._events[t].length>r&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"===typeof console.trace&&console.trace()),this},i.prototype.on=i.prototype.addListener,i.prototype.once=function(t,e){if(!o(e))throw TypeError("listener must be a function");var r=!1;function n(){this.removeListener(t,n),r||(r=!0,e.apply(this,arguments))}return n.listener=e,this.on(t,n),this},i.prototype.removeListener=function(t,e){var r,n,i,a;if(!o(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(i=(r=this._events[t]).length,n=-1,r===e||o(r.listener)&&r.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(s(r)){for(a=i;a-- >0;)if(r[a]===e||r[a].listener&&r[a].listener===e){n=a;break}if(n<0)return this;1===r.length?(r.length=0,delete this._events[t]):r.splice(n,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},i.prototype.removeAllListeners=function(t){var e,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(o(r=this._events[t]))this.removeListener(t,r);else if(r)for(;r.length;)this.removeListener(t,r[r.length-1]);return delete this._events[t],this},i.prototype.listeners=function(t){return this._events&&this._events[t]?o(this._events[t])?[this._events[t]]:this._events[t].slice():[]},i.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(o(e))return 1;if(e)return e.length}return 0},i.listenerCount=function(t,e){return t.listenerCount(e)}},function(t,e,r){"use strict";e.internalToObjectOptions={transform:!1,virtuals:!1,getters:!1,_skipDepopulateTopLevel:!0,depopulate:!0,flattenDecimals:!1}},function(t,e,r){"use strict";(function(e){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)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function o(t,e){return!e||"object"!==n(e)&&"function"!==typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function s(t){var e="function"===typeof Map?new Map:void 0;return(s=function(t){if(null===t)return null;if("function"!==typeof t)throw new TypeError("Super expression must either be null or a function");if("undefined"!==typeof e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return a(t,arguments,c(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,t)})(t)}function a(t,e,r){return(a=function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&u(i,r.prototype),i}).apply(null,arguments)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var l=r(35),f=r(10),h=r(37),p=r(8),d=r(12).internalToObjectOptions,y=r(0),_=r(4),m=r(21).getDiscriminatorByValue,v=r(3),g=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),o(this,c(e).apply(this,arguments))}var r,n,a;return function(t,e){if("function"!==typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}(e,s(Array)),r=e,(n=[{key:"remove",value:function(){}},{key:"isMongooseArray",get:function(){return!0}}])&&i(r.prototype,n),a&&i(r,a),e}();function b(t,e,r){var n=new g;Array.isArray(t)&&t.forEach(function(t){return n.push(t)}),n._path=e;for(var i={isMongooseDocumentArray:!0,validators:[],_atomics:{},_schema:void 0,_handlers:void 0},o=Object.keys(l.mixin),s=o.length,a=0;a<s;++a)n[o[a]]=l.mixin[o[a]];var u=Object.keys(b.mixin);s=u.length;for(var c=0;c<s;++c)n[u[c]]=b.mixin[u[c]];v.inspect.custom&&(i[v.inspect.custom]=n.inspect);var f=Object.keys(i);s=f.length;for(var h=0;h<s;++h)n[f[h]]=i[f[h]];if(r&&r instanceof _){for(n._parent=r,n._schema=r.schema.path(e);p(n,"_schema.$isMongooseArray")&&!p(n,"_schema.$isMongooseDocumentArray");)n._schema=n._schema.casterConstructor;n._schema&&!n._schema.$isMongooseDocumentArray&&(n._schema=n._schema.casterConstructor),n._handlers={isNew:n.notify("isNew"),save:n.notify("save")},r.on("save",n._handlers.save),r.on("isNew",n._handlers.isNew)}return n}b.mixin={toBSON:function(){return this.toObject(d)},_cast:function(t,r){var n=this._schema.casterConstructor;if((n.$isMongooseDocumentArray?t&&t.isMongooseDocumentArray:t instanceof n)||t&&t.constructor&&t.constructor.baseCasterConstructor===n)return t.__parent&&t.__parentArray||(t.__parent=this._parent,t.__parentArray=this),t.__index=r,t;if(void 0===t||null===t)return null;if((e.isBuffer(t)||t instanceof f||!y.isObject(t))&&(t={_id:t}),t&&n.discriminators&&n.schema&&n.schema.options&&n.schema.options.discriminatorKey)if("string"===typeof t[n.schema.options.discriminatorKey]&&n.discriminators[t[n.schema.options.discriminatorKey]])n=n.discriminators[t[n.schema.options.discriminatorKey]];else{var i=m(n,t[n.schema.options.discriminatorKey]);i&&(n=i)}return n.$isMongooseDocumentArray?n.cast(t,this,void 0,void 0,r):new n(t,this,void 0,void 0,r)},id:function(t){var e,r,n;try{var i=h.prototype.cast.call({},t);i&&(e=String(i))}catch(t){e=null}for(var o=0,s=this.length;o<s;o++)if(this[o]&&null!==(n=this[o].get("_id"))&&"undefined"!==typeof n)if(n instanceof _){if(r||(r=String(t)),r==n._id)return this[o]}else if(t instanceof f||n instanceof f){if(e==n)return this[o]}else if(y.deepEqual(t,n))return this[o];return null},toObject:function(t){return this.map(function(e){try{return e.toObject(t)}catch(t){return e||null}})},inspect:function(){return this.toObject()},create:function(t){var e=this._schema.casterConstructor;if(t&&e.discriminators&&e.schema&&e.schema.options&&e.schema.options.discriminatorKey)if("string"===typeof t[e.schema.options.discriminatorKey]&&e.discriminators[t[e.schema.options.discriminatorKey]])e=e.discriminators[t[e.schema.options.discriminatorKey]];else{var r=m(e,t[e.schema.options.discriminatorKey]);r&&(e=r)}return new e(t)},notify:function(t){var e=this;return function r(n,i){for(var o=(i=i||e).length;o--;)if(null!=i[o]){switch(t){case"save":n=e[o]}i[o].isMongooseArray?r(n,i[o]):i[o]&&i[o].emit(t,n)}}}},t.exports=b}).call(this,r(1).Buffer)},function(t,e,r){"use strict";var n=null;t.exports.get=function(){return n},t.exports.set=function(t){n=t}},function(t,e,r){"use strict";function n(t,e){if(!(this instanceof n))return new n(t,e);this._bsontype="Long",this.low_=0|t,this.high_=0|e}n.prototype.toInt=function(){return this.low_},n.prototype.toNumber=function(){return this.high_*n.TWO_PWR_32_DBL_+this.getLowBitsUnsigned()},n.prototype.toJSON=function(){return this.toString()},n.prototype.toString=function(t){var e=t||10;if(e<2||36<e)throw Error("radix out of range: "+e);if(this.isZero())return"0";if(this.isNegative()){if(this.equals(n.MIN_VALUE)){var r=n.fromNumber(e),i=this.div(r),o=i.multiply(r).subtract(this);return i.toString(e)+o.toInt().toString(e)}return"-"+this.negate().toString(e)}var s=n.fromNumber(Math.pow(e,6));o=this;for(var a="";!o.isZero();){var u=o.div(s),c=o.subtract(u.multiply(s)).toInt().toString(e);if((o=u).isZero())return c+a;for(;c.length<6;)c="0"+c;a=""+c+a}},n.prototype.getHighBits=function(){return this.high_},n.prototype.getLowBits=function(){return this.low_},n.prototype.getLowBitsUnsigned=function(){return this.low_>=0?this.low_:n.TWO_PWR_32_DBL_+this.low_},n.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(n.MIN_VALUE)?64:this.negate().getNumBitsAbs();for(var t=0!==this.high_?this.high_:this.low_,e=31;e>0&&0===(t&1<<e);e--);return 0!==this.high_?e+33:e+1},n.prototype.isZero=function(){return 0===this.high_&&0===this.low_},n.prototype.isNegative=function(){return this.high_<0},n.prototype.isOdd=function(){return 1===(1&this.low_)},n.prototype.equals=function(t){return this.high_===t.high_&&this.low_===t.low_},n.prototype.notEquals=function(t){return this.high_!==t.high_||this.low_!==t.low_},n.prototype.lessThan=function(t){return this.compare(t)<0},n.prototype.lessThanOrEqual=function(t){return this.compare(t)<=0},n.prototype.greaterThan=function(t){return this.compare(t)>0},n.prototype.greaterThanOrEqual=function(t){return this.compare(t)>=0},n.prototype.compare=function(t){if(this.equals(t))return 0;var e=this.isNegative(),r=t.isNegative();return e&&!r?-1:!e&&r?1:this.subtract(t).isNegative()?-1:1},n.prototype.negate=function(){return this.equals(n.MIN_VALUE)?n.MIN_VALUE:this.not().add(n.ONE)},n.prototype.add=function(t){var e=this.high_>>>16,r=65535&this.high_,i=this.low_>>>16,o=65535&this.low_,s=t.high_>>>16,a=65535&t.high_,u=t.low_>>>16,c=0,l=0,f=0,h=0;return f+=(h+=o+(65535&t.low_))>>>16,h&=65535,l+=(f+=i+u)>>>16,f&=65535,c+=(l+=r+a)>>>16,l&=65535,c+=e+s,c&=65535,n.fromBits(f<<16|h,c<<16|l)},n.prototype.subtract=function(t){return this.add(t.negate())},n.prototype.multiply=function(t){if(this.isZero())return n.ZERO;if(t.isZero())return n.ZERO;if(this.equals(n.MIN_VALUE))return t.isOdd()?n.MIN_VALUE:n.ZERO;if(t.equals(n.MIN_VALUE))return this.isOdd()?n.MIN_VALUE:n.ZERO;if(this.isNegative())return t.isNegative()?this.negate().multiply(t.negate()):this.negate().multiply(t).negate();if(t.isNegative())return this.multiply(t.negate()).negate();if(this.lessThan(n.TWO_PWR_24_)&&t.lessThan(n.TWO_PWR_24_))return n.fromNumber(this.toNumber()*t.toNumber());var e=this.high_>>>16,r=65535&this.high_,i=this.low_>>>16,o=65535&this.low_,s=t.high_>>>16,a=65535&t.high_,u=t.low_>>>16,c=65535&t.low_,l=0,f=0,h=0,p=0;return h+=(p+=o*c)>>>16,p&=65535,f+=(h+=i*c)>>>16,h&=65535,f+=(h+=o*u)>>>16,h&=65535,l+=(f+=r*c)>>>16,f&=65535,l+=(f+=i*u)>>>16,f&=65535,l+=(f+=o*a)>>>16,f&=65535,l+=e*c+r*u+i*a+o*s,l&=65535,n.fromBits(h<<16|p,l<<16|f)},n.prototype.div=function(t){if(t.isZero())throw Error("division by zero");if(this.isZero())return n.ZERO;if(this.equals(n.MIN_VALUE)){if(t.equals(n.ONE)||t.equals(n.NEG_ONE))return n.MIN_VALUE;if(t.equals(n.MIN_VALUE))return n.ONE;var e=this.shiftRight(1).div(t).shiftLeft(1);if(e.equals(n.ZERO))return t.isNegative()?n.ONE:n.NEG_ONE;var r=this.subtract(t.multiply(e));return e.add(r.div(t))}if(t.equals(n.MIN_VALUE))return n.ZERO;if(this.isNegative())return t.isNegative()?this.negate().div(t.negate()):this.negate().div(t).negate();if(t.isNegative())return this.div(t.negate()).negate();var i=n.ZERO;for(r=this;r.greaterThanOrEqual(t);){e=Math.max(1,Math.floor(r.toNumber()/t.toNumber()));for(var o=Math.ceil(Math.log(e)/Math.LN2),s=o<=48?1:Math.pow(2,o-48),a=n.fromNumber(e),u=a.multiply(t);u.isNegative()||u.greaterThan(r);)e-=s,u=(a=n.fromNumber(e)).multiply(t);a.isZero()&&(a=n.ONE),i=i.add(a),r=r.subtract(u)}return i},n.prototype.modulo=function(t){return this.subtract(this.div(t).multiply(t))},n.prototype.not=function(){return n.fromBits(~this.low_,~this.high_)},n.prototype.and=function(t){return n.fromBits(this.low_&t.low_,this.high_&t.high_)},n.prototype.or=function(t){return n.fromBits(this.low_|t.low_,this.high_|t.high_)},n.prototype.xor=function(t){return n.fromBits(this.low_^t.low_,this.high_^t.high_)},n.prototype.shiftLeft=function(t){if(0===(t&=63))return this;var e=this.low_;if(t<32){var r=this.high_;return n.fromBits(e<<t,r<<t|e>>>32-t)}return n.fromBits(0,e<<t-32)},n.prototype.shiftRight=function(t){if(0===(t&=63))return this;var e=this.high_;if(t<32){var r=this.low_;return n.fromBits(r>>>t|e<<32-t,e>>t)}return n.fromBits(e>>t-32,e>=0?0:-1)},n.prototype.shiftRightUnsigned=function(t){if(0===(t&=63))return this;var e=this.high_;if(t<32){var r=this.low_;return n.fromBits(r>>>t|e<<32-t,e>>>t)}return 32===t?n.fromBits(e,0):n.fromBits(e>>>t-32,0)},n.fromInt=function(t){if(-128<=t&&t<128){var e=n.INT_CACHE_[t];if(e)return e}var r=new n(0|t,t<0?-1:0);return-128<=t&&t<128&&(n.INT_CACHE_[t]=r),r},n.fromNumber=function(t){return isNaN(t)||!isFinite(t)?n.ZERO:t<=-n.TWO_PWR_63_DBL_?n.MIN_VALUE:t+1>=n.TWO_PWR_63_DBL_?n.MAX_VALUE:t<0?n.fromNumber(-t).negate():new n(t%n.TWO_PWR_32_DBL_|0,t/n.TWO_PWR_32_DBL_|0)},n.fromBits=function(t,e){return new n(t,e)},n.fromString=function(t,e){if(0===t.length)throw Error("number format error: empty string");var r=e||10;if(r<2||36<r)throw Error("radix out of range: "+r);if("-"===t.charAt(0))return n.fromString(t.substring(1),r).negate();if(t.indexOf("-")>=0)throw Error('number format error: interior "-" character: '+t);for(var i=n.fromNumber(Math.pow(r,8)),o=n.ZERO,s=0;s<t.length;s+=8){var a=Math.min(8,t.length-s),u=parseInt(t.substring(s,s+a),r);if(a<8){var c=n.fromNumber(Math.pow(r,a));o=o.multiply(c).add(n.fromNumber(u))}else o=(o=o.multiply(i)).add(n.fromNumber(u))}return o},n.INT_CACHE_={},n.TWO_PWR_16_DBL_=65536,n.TWO_PWR_24_DBL_=1<<24,n.TWO_PWR_32_DBL_=n.TWO_PWR_16_DBL_*n.TWO_PWR_16_DBL_,n.TWO_PWR_31_DBL_=n.TWO_PWR_32_DBL_/2,n.TWO_PWR_48_DBL_=n.TWO_PWR_32_DBL_*n.TWO_PWR_16_DBL_,n.TWO_PWR_64_DBL_=n.TWO_PWR_32_DBL_*n.TWO_PWR_32_DBL_,n.TWO_PWR_63_DBL_=n.TWO_PWR_64_DBL_/2,n.ZERO=n.fromInt(0),n.ONE=n.fromInt(1),n.NEG_ONE=n.fromInt(-1),n.MAX_VALUE=n.fromBits(-1,2147483647),n.MIN_VALUE=n.fromBits(0,-2147483648),n.TWO_PWR_24_=n.fromInt(1<<24),t.exports=n,t.exports.Long=n},function(t,e,r){"use strict";e.Array=r(35),e.Buffer=r(61),e.Document=e.Embedded=r(17),e.DocumentArray=r(13),e.Decimal128=r(33),e.ObjectId=r(10),e.Map=r(63),e.Subdocument=r(64)},function(t,e,r){"use strict";var n=r(51)(),i=r(11).EventEmitter,o=r(36),s=r(12).internalToObjectOptions,a=r(0),u=r(3);function c(t,e,r,i,o){e?(this.__parentArray=e,this.__parent=e._parent):(this.__parentArray=void 0,this.__parent=void 0),this.__index=o,n.call(this,t,i,r);var s=this;this.on("isNew",function(t){s.isNew=t}),s.on("save",function(){s.constructor.emit("save",s)})}for(var l in c.prototype=Object.create(n.prototype),c.prototype.constructor=c,i.prototype)c[l]=i.prototype[l];c.prototype.toBSON=function(){return this.toObject(s)},c.prototype.markModified=function(t){this.$__.activePaths.modify(t),this.__parentArray&&(this.isNew?this.__parentArray._markModified():this.__parentArray._markModified(this,t))},c.prototype.populate=function(){throw new Error('Mongoose does not support calling populate() on nested docs. Instead of `doc.arr[0].populate("path")`, use `doc.populate("arr.0.path")`')},c.prototype.save=function(t,e){var r=this;return"function"===typeof t&&(e=t,t={}),(t=t||{}).suppressWarning||console.warn("mongoose: calling `save()` on a subdoc does **not** save the document to MongoDB, it only runs save middleware. Use `subdoc.save({ suppressWarning: true })` to hide this warning if you're sure this behavior is right for your app."),a.promiseOrCallback(e,function(t){r.$__save(t)})},c.prototype.$__save=function(t){var e=this;return o(function(){return t(null,e)})},c.prototype.$__remove=function(t){return t(null,this)},c.prototype.remove=function(t,e){if("function"!==typeof t||e||(e=t,t=void 0),!this.__parentArray||t&&t.noop)return e&&e(null),this;var r;if(!this.willRemove){if(!(r=this._doc._id))throw new Error("For your own good, Mongoose does not know how to remove an EmbeddedDocument that has no _id");this.__parentArray.pull({_id:r}),this.willRemove=!0,function(t){var e=t.ownerDocument();function r(){e.removeListener("save",r),e.removeListener("remove",r),t.emit("remove",t),t.constructor.emit("remove",t),e=t=null}e.on("save",r),e.on("remove",r)}(this)}return e&&e(null),this},c.prototype.update=function(){throw new Error("The #update method is not available on EmbeddedDocuments")},c.prototype.inspect=function(){return this.toObject({transform:!1,virtuals:!1,flattenDecimals:!1})},u.inspect.custom&&(c.prototype[u.inspect.custom]=c.prototype.inspect),c.prototype.invalidate=function(t,e,r,i){if(!this.__parent){if(n.prototype.invalidate.call(this,t,e,r),e.$isValidatorError)return!0;throw e}var o=this.__index;if("undefined"!==typeof o){var s=[this.__parentArray._path,o,t].join(".");this.__parent.invalidate(s,e,r)}return i&&(this.$__.validationError=this.ownerDocument().$__.validationError),!0},c.prototype.$markValid=function(t){if(this.__parent){var e=this.__index;if("undefined"!==typeof e){var r=[this.__parentArray._path,e,t].join(".");this.__parent.$markValid(r)}}},c.prototype.$ignore=function(t){if(n.prototype.$ignore.call(this,t),this.__parent){var e=this.__index;if("undefined"!==typeof e){var r=[this.__parentArray._path,e,t].join(".");this.__parent.$ignore(r)}}},c.prototype.$isValid=function(t){return"undefined"===typeof this.__index||!this.__parent||(!this.__parent.$__.validationError||!this.__parent.$__.validationError.errors[this.$__fullPath(t)])},c.prototype.ownerDocument=function(){if(this.$__.ownerDocument)return this.$__.ownerDocument;var t=this.__parent;if(!t)return this;for(;t.__parent||t.$parent;)t=t.__parent||t.$parent;return this.$__.ownerDocument=t,this.$__.ownerDocument},c.prototype.$__fullPath=function(t){if(!this.$__.fullPath){var e=this;if(!e.__parent)return t;for(var r=[];e.__parent||e.$parent;)e.__parent?r.unshift(e.__parentArray._path):r.unshift(e.$basePath),e=e.__parent||e.$parent;this.$__.fullPath=r.join("."),this.$__.ownerDocument||(this.$__.ownerDocument=e)}return t?this.$__.fullPath+"."+t:this.$__.fullPath},c.prototype.parent=function(){return this.__parent},c.prototype.parentArray=function(){return this.__parentArray},t.exports=c},function(t,e,r){"use strict";function n(){if(!(this instanceof n))return new n;this._bsontype="MinKey"}t.exports=n,t.exports.MinKey=n},function(t,e,r){"use strict";(function(e){if("undefined"!==typeof e)var n=r(1).Buffer;function i(t,e){if(!(this instanceof i))return new i(t,e);if(null!=t&&"string"!==typeof t&&!n.isBuffer(t)&&!(t instanceof Uint8Array)&&!Array.isArray(t))throw new Error("only String, Buffer, Uint8Array or Array accepted");if(this._bsontype="Binary",t instanceof Number?(this.sub_type=t,this.position=0):(this.sub_type=null==e?o:e,this.position=0),null==t||t instanceof Number)"undefined"!==typeof n?this.buffer=new n(i.BUFFER_SIZE):"undefined"!==typeof Uint8Array?this.buffer=new Uint8Array(new ArrayBuffer(i.BUFFER_SIZE)):this.buffer=new Array(i.BUFFER_SIZE),this.position=0;else{if("string"===typeof t)if("undefined"!==typeof n)this.buffer=new n(t);else{if("undefined"===typeof Uint8Array&&"[object Array]"!==Object.prototype.toString.call(t))throw new Error("only String, Buffer, Uint8Array or Array accepted");this.buffer=s(t)}else this.buffer=t;this.position=t.length}}i.prototype.put=function(t){if(null!=t.length&&"number"!==typeof t&&1!==t.length)throw new Error("only accepts single character String, Uint8Array or Array");if("number"!==typeof t&&t<0||t>255)throw new Error("only accepts number in a valid unsigned byte range 0-255");var e=null;if(e="string"===typeof t?t.charCodeAt(0):null!=t.length?t[0]:t,this.buffer.length>this.position)this.buffer[this.position++]=e;else if("undefined"!==typeof n&&n.isBuffer(this.buffer)){var r=new n(i.BUFFER_SIZE+this.buffer.length);this.buffer.copy(r,0,0,this.buffer.length),this.buffer=r,this.buffer[this.position++]=e}else{r=null,r="[object Uint8Array]"===Object.prototype.toString.call(this.buffer)?new Uint8Array(new ArrayBuffer(i.BUFFER_SIZE+this.buffer.length)):new Array(i.BUFFER_SIZE+this.buffer.length);for(var o=0;o<this.buffer.length;o++)r[o]=this.buffer[o];this.buffer=r,this.buffer[this.position++]=e}},i.prototype.write=function(t,e){if(e="number"===typeof e?e:this.position,this.buffer.length<e+t.length){var r=null;if("undefined"!==typeof n&&n.isBuffer(this.buffer))r=new n(this.buffer.length+t.length),this.buffer.copy(r,0,0,this.buffer.length);else if("[object Uint8Array]"===Object.prototype.toString.call(this.buffer)){r=new Uint8Array(new ArrayBuffer(this.buffer.length+t.length));for(var i=0;i<this.position;i++)r[i]=this.buffer[i]}this.buffer=r}if("undefined"!==typeof n&&n.isBuffer(t)&&n.isBuffer(this.buffer))t.copy(this.buffer,e,0,t.length),this.position=e+t.length>this.position?e+t.length:this.position;else if("undefined"!==typeof n&&"string"===typeof t&&n.isBuffer(this.buffer))this.buffer.write(t,e,"binary"),this.position=e+t.length>this.position?e+t.length:this.position;else if("[object Uint8Array]"===Object.prototype.toString.call(t)||"[object Array]"===Object.prototype.toString.call(t)&&"string"!==typeof t){for(i=0;i<t.length;i++)this.buffer[e++]=t[i];this.position=e>this.position?e:this.position}else if("string"===typeof t){for(i=0;i<t.length;i++)this.buffer[e++]=t.charCodeAt(i);this.position=e>this.position?e:this.position}},i.prototype.read=function(t,e){if(e=e&&e>0?e:this.position,this.buffer.slice)return this.buffer.slice(t,t+e);for(var r="undefined"!==typeof Uint8Array?new Uint8Array(new ArrayBuffer(e)):new Array(e),n=0;n<e;n++)r[n]=this.buffer[t++];return r},i.prototype.value=function(t){if((t=null!=t&&t)&&"undefined"!==typeof n&&n.isBuffer(this.buffer)&&this.buffer.length===this.position)return this.buffer;if("undefined"!==typeof n&&n.isBuffer(this.buffer))return t?this.buffer.slice(0,this.position):this.buffer.toString("binary",0,this.position);if(t){if(null!=this.buffer.slice)return this.buffer.slice(0,this.position);for(var e="[object Uint8Array]"===Object.prototype.toString.call(this.buffer)?new Uint8Array(new ArrayBuffer(this.position)):new Array(this.position),r=0;r<this.position;r++)e[r]=this.buffer[r];return e}return a(this.buffer,0,this.position)},i.prototype.length=function(){return this.position},i.prototype.toJSON=function(){return null!=this.buffer?this.buffer.toString("base64"):""},i.prototype.toString=function(t){return null!=this.buffer?this.buffer.slice(0,this.position).toString(t):""};var o=0,s=function(t){for(var e="undefined"!==typeof Uint8Array?new Uint8Array(new ArrayBuffer(t.length)):new Array(t.length),r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e},a=function(t,e,r){for(var n="",i=e;i<r;i++)n+=String.fromCharCode(t[i]);return n};i.BUFFER_SIZE=256,i.SUBTYPE_DEFAULT=0,i.SUBTYPE_FUNCTION=1,i.SUBTYPE_BYTE_ARRAY=2,i.SUBTYPE_UUID_OLD=3,i.SUBTYPE_UUID=4,i.SUBTYPE_MD5=5,i.SUBTYPE_USER_DEFINED=128,t.exports=i,t.exports.Binary=i}).call(this,r(6))},function(t,e,r){"use strict";var n=["find","findOne","update","updateMany","updateOne","replaceOne","remove","count","distinct","findAndModify","aggregate","findStream","deleteOne","deleteMany"];function i(){}for(var o=0,s=n.length;o<s;++o){var a=n[o];i.prototype[a]=u(a)}function u(t){return function(){throw new Error("collection."+t+" not implemented")}}t.exports=i,i.methods=n},function(t,e,r){"use strict";function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(8),o=r(41),s=r(0);function a(t,e){var r=null;if(!t.discriminators)return r;for(var n in t.discriminators){var i=t.discriminators[n];if(i.schema&&i.schema.discriminatorMapping&&i.schema.discriminatorMapping.value==e){r=i;break}}return r}function u(t){return function(e){e.options||(e.options={}),e.options.lean=t}}e.preparePopulationOptions=function(t,e){var r=s.object.vals(t.options.populate);return null!=e.lean&&r.filter(function(t){return null==i(t,"options.lean")}).forEach(u(e.lean)),r},e.preparePopulationOptionsMQ=function(t,e){var r=s.object.vals(t._mongooseOptions.populate);null!=e.lean&&r.filter(function(t){return null==i(t,"options.lean")}).forEach(u(e.lean));var n=i(t,"options.session",null);return null!=n&&r.forEach(function(t){null!=t.options?"session"in t.options||(t.options.session=n):t.options={session:n}}),r},e.getDiscriminatorByValue=a,e.createModel=function(t,r,i,o){t.hooks.execPreSync("createModel",r);var u=t.schema?t.schema.discriminatorMapping:null,c=u&&u.isRoot?u.key:null,l=r[c];if(c&&l&&t.discriminators){var f=t.discriminators[l]||a(t,l);if(f){var h=s.clone(o);return e.applyPaths(h,f.schema),new f(void 0,h,!0)}}return new t(void 0,i,{skipId:!0,isNew:!1,skipDefaults:function t(e,r,i){var o=Object.keys(e);for(var a=0;a<o.length;a++){var u=o[a],c=i?i+"."+u:u;r[c]=!0,null==e[u]||"object"!==n(e[u])||Array.isArray(e)||e instanceof Map||e[u]._bsontype||s.isMongooseObject(e[u])||t(e[u],r,c)}return r}(r,{},"")})},e.applyPaths=function(t,e){var r,s,a,u;if(t)for(a=(s=Object.keys(t)).length;a--;)if("+"!==s[a][0]&&(u=t[s[a]],o(u))){r=0===u;break}var c,l=[],f=[],h=[];switch(function e(o,a){a||(a=""),-1===h.indexOf(o)&&(h.push(o),o.eachPath(function(o,u){a&&(o=a+"."+o),function(e,o){var a="+"+e,u=t&&a in t;if(u&&delete t[a],"boolean"===typeof o.selected){if(u)return delete t[a],void(!1===r&&s.length>1&&!~s.indexOf(e)&&(t[e]=1));var c=e.split("."),h=c[0];if(!~f.indexOf(h)){if(!r&&i(o,"options.$skipDiscriminatorCheck",!1))for(var p="",d=0;d<c.length;++d){p+=(0===p.length?"":".")+c[d];var y=i(t,p,!1);if(y&&"object"!==n(y))return}(o.selected?l:f).push(e)}}}(o,u),u.schema&&e(u.schema,o)}),h.pop())}(e),r){case!0:for(c=0;c<f.length;++c)t[f[c]]=0;break;case!1:for(e&&e.paths._id&&e.paths._id.options&&!1===e.paths._id.options.select&&(t._id=0),c=0;c<l.length;++c)t[l[c]]=1;break;case void 0:for(c=0;c<f.length;++c)t[f[c]]=0}},e.handleWriteOpResult=function(t){return function(e,r){return e?t(e):t(null,r.result)}}},function(t,e,r){"use strict";var n={Number:r(45)};function i(t){return n.Number.prototype.cast.call(this,t)}e.castToNumber=i,e.castArraysOfNumbers=function t(e,r){e.forEach(function(n,o){Array.isArray(n)?t(n,r):e[o]=i.call(r,n)})}},function(t,e,r){"use strict";(function(e){var n=r(48),i=r(15),o=r(24),s=r(25),a=r(26),u=r(27),c=r(28),l=r(49),f=r(29),h=r(30),p=r(18),d=r(31),y=r(32),_=r(19),m=r(85),v=r(86),g=r(88),b=new e(17825792),w=function(){};w.prototype.serialize=function(t,r){var n="boolean"===typeof(r=r||{}).checkKeys&&r.checkKeys,i="boolean"===typeof r.serializeFunctions&&r.serializeFunctions,o="boolean"!==typeof r.ignoreUndefined||r.ignoreUndefined,s="number"===typeof r.minInternalBufferSize?r.minInternalBufferSize:17825792;b.length<s&&(b=new e(s));var a=v(b,t,n,0,0,i,o,[]),u=new e(a);return b.copy(u,0,0,u.length),u},w.prototype.serializeWithBufferAndIndex=function(t,e,r){var n="boolean"===typeof(r=r||{}).checkKeys&&r.checkKeys,i="boolean"===typeof r.serializeFunctions&&r.serializeFunctions,o="boolean"!==typeof r.ignoreUndefined||r.ignoreUndefined,s="number"===typeof r.index?r.index:0;return v(e,t,n,s||0,0,i,o)-1},w.prototype.deserialize=function(t,e){return m(t,e)},w.prototype.calculateObjectSize=function(t,e){var r="boolean"===typeof(e=e||{}).serializeFunctions&&e.serializeFunctions,n="boolean"!==typeof e.ignoreUndefined||e.ignoreUndefined;return g(t,r,n)},w.prototype.deserializeStream=function(t,e,r,n,i,o){o=null!=o?o:{};for(var s=e,a=0;a<r;a++){var u=t[s]|t[s+1]<<8|t[s+2]<<16|t[s+3]<<24;o.index=s,n[i+a]=this.deserialize(t,o),s+=u}return s},w.BSON_INT32_MAX=2147483647,w.BSON_INT32_MIN=-2147483648,w.BSON_INT64_MAX=Math.pow(2,63)-1,w.BSON_INT64_MIN=-Math.pow(2,63),w.JS_INT_MAX=9007199254740992,w.JS_INT_MIN=-9007199254740992,w.BSON_DATA_NUMBER=1,w.BSON_DATA_STRING=2,w.BSON_DATA_OBJECT=3,w.BSON_DATA_ARRAY=4,w.BSON_DATA_BINARY=5,w.BSON_DATA_OID=7,w.BSON_DATA_BOOLEAN=8,w.BSON_DATA_DATE=9,w.BSON_DATA_NULL=10,w.BSON_DATA_REGEXP=11,w.BSON_DATA_CODE=13,w.BSON_DATA_SYMBOL=14,w.BSON_DATA_CODE_W_SCOPE=15,w.BSON_DATA_INT=16,w.BSON_DATA_TIMESTAMP=17,w.BSON_DATA_LONG=18,w.BSON_DATA_MIN_KEY=255,w.BSON_DATA_MAX_KEY=127,w.BSON_BINARY_SUBTYPE_DEFAULT=0,w.BSON_BINARY_SUBTYPE_FUNCTION=1,w.BSON_BINARY_SUBTYPE_BYTE_ARRAY=2,w.BSON_BINARY_SUBTYPE_UUID=3,w.BSON_BINARY_SUBTYPE_MD5=4,w.BSON_BINARY_SUBTYPE_USER_DEFINED=128,t.exports=w,t.exports.Code=f,t.exports.Map=n,t.exports.Symbol=c,t.exports.BSON=w,t.exports.DBRef=y,t.exports.Binary=_,t.exports.ObjectID=a,t.exports.Long=i,t.exports.Timestamp=s,t.exports.Double=o,t.exports.Int32=l,t.exports.MinKey=p,t.exports.MaxKey=d,t.exports.BSONRegExp=u,t.exports.Decimal128=h}).call(this,r(1).Buffer)},function(t,e,r){"use strict";function n(t){if(!(this instanceof n))return new n(t);this._bsontype="Double",this.value=t}n.prototype.valueOf=function(){return this.value},n.prototype.toJSON=function(){return this.value},t.exports=n,t.exports.Double=n},function(t,e,r){"use strict";function n(t,e){if(!(this instanceof n))return new n(t,e);this._bsontype="Timestamp",this.low_=0|t,this.high_=0|e}n.prototype.toInt=function(){return this.low_},n.prototype.toNumber=function(){return this.high_*n.TWO_PWR_32_DBL_+this.getLowBitsUnsigned()},n.prototype.toJSON=function(){return this.toString()},n.prototype.toString=function(t){var e=t||10;if(e<2||36<e)throw Error("radix out of range: "+e);if(this.isZero())return"0";if(this.isNegative()){if(this.equals(n.MIN_VALUE)){var r=n.fromNumber(e),i=this.div(r),o=i.multiply(r).subtract(this);return i.toString(e)+o.toInt().toString(e)}return"-"+this.negate().toString(e)}var s=n.fromNumber(Math.pow(e,6));o=this;for(var a="";!o.isZero();){var u=o.div(s),c=o.subtract(u.multiply(s)).toInt().toString(e);if((o=u).isZero())return c+a;for(;c.length<6;)c="0"+c;a=""+c+a}},n.prototype.getHighBits=function(){return this.high_},n.prototype.getLowBits=function(){return this.low_},n.prototype.getLowBitsUnsigned=function(){return this.low_>=0?this.low_:n.TWO_PWR_32_DBL_+this.low_},n.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(n.MIN_VALUE)?64:this.negate().getNumBitsAbs();for(var t=0!==this.high_?this.high_:this.low_,e=31;e>0&&0===(t&1<<e);e--);return 0!==this.high_?e+33:e+1},n.prototype.isZero=function(){return 0===this.high_&&0===this.low_},n.prototype.isNegative=function(){return this.high_<0},n.prototype.isOdd=function(){return 1===(1&this.low_)},n.prototype.equals=function(t){return this.high_===t.high_&&this.low_===t.low_},n.prototype.notEquals=function(t){return this.high_!==t.high_||this.low_!==t.low_},n.prototype.lessThan=function(t){return this.compare(t)<0},n.prototype.lessThanOrEqual=function(t){return this.compare(t)<=0},n.prototype.greaterThan=function(t){return this.compare(t)>0},n.prototype.greaterThanOrEqual=function(t){return this.compare(t)>=0},n.prototype.compare=function(t){if(this.equals(t))return 0;var e=this.isNegative(),r=t.isNegative();return e&&!r?-1:!e&&r?1:this.subtract(t).isNegative()?-1:1},n.prototype.negate=function(){return this.equals(n.MIN_VALUE)?n.MIN_VALUE:this.not().add(n.ONE)},n.prototype.add=function(t){var e=this.high_>>>16,r=65535&this.high_,i=this.low_>>>16,o=65535&this.low_,s=t.high_>>>16,a=65535&t.high_,u=t.low_>>>16,c=0,l=0,f=0,h=0;return f+=(h+=o+(65535&t.low_))>>>16,h&=65535,l+=(f+=i+u)>>>16,f&=65535,c+=(l+=r+a)>>>16,l&=65535,c+=e+s,c&=65535,n.fromBits(f<<16|h,c<<16|l)},n.prototype.subtract=function(t){return this.add(t.negate())},n.prototype.multiply=function(t){if(this.isZero())return n.ZERO;if(t.isZero())return n.ZERO;if(this.equals(n.MIN_VALUE))return t.isOdd()?n.MIN_VALUE:n.ZERO;if(t.equals(n.MIN_VALUE))return this.isOdd()?n.MIN_VALUE:n.ZERO;if(this.isNegative())return t.isNegative()?this.negate().multiply(t.negate()):this.negate().multiply(t).negate();if(t.isNegative())return this.multiply(t.negate()).negate();if(this.lessThan(n.TWO_PWR_24_)&&t.lessThan(n.TWO_PWR_24_))return n.fromNumber(this.toNumber()*t.toNumber());var e=this.high_>>>16,r=65535&this.high_,i=this.low_>>>16,o=65535&this.low_,s=t.high_>>>16,a=65535&t.high_,u=t.low_>>>16,c=65535&t.low_,l=0,f=0,h=0,p=0;return h+=(p+=o*c)>>>16,p&=65535,f+=(h+=i*c)>>>16,h&=65535,f+=(h+=o*u)>>>16,h&=65535,l+=(f+=r*c)>>>16,f&=65535,l+=(f+=i*u)>>>16,f&=65535,l+=(f+=o*a)>>>16,f&=65535,l+=e*c+r*u+i*a+o*s,l&=65535,n.fromBits(h<<16|p,l<<16|f)},n.prototype.div=function(t){if(t.isZero())throw Error("division by zero");if(this.isZero())return n.ZERO;if(this.equals(n.MIN_VALUE)){if(t.equals(n.ONE)||t.equals(n.NEG_ONE))return n.MIN_VALUE;if(t.equals(n.MIN_VALUE))return n.ONE;var e=this.shiftRight(1).div(t).shiftLeft(1);if(e.equals(n.ZERO))return t.isNegative()?n.ONE:n.NEG_ONE;var r=this.subtract(t.multiply(e));return e.add(r.div(t))}if(t.equals(n.MIN_VALUE))return n.ZERO;if(this.isNegative())return t.isNegative()?this.negate().div(t.negate()):this.negate().div(t).negate();if(t.isNegative())return this.div(t.negate()).negate();var i=n.ZERO;for(r=this;r.greaterThanOrEqual(t);){e=Math.max(1,Math.floor(r.toNumber()/t.toNumber()));for(var o=Math.ceil(Math.log(e)/Math.LN2),s=o<=48?1:Math.pow(2,o-48),a=n.fromNumber(e),u=a.multiply(t);u.isNegative()||u.greaterThan(r);)e-=s,u=(a=n.fromNumber(e)).multiply(t);a.isZero()&&(a=n.ONE),i=i.add(a),r=r.subtract(u)}return i},n.prototype.modulo=function(t){return this.subtract(this.div(t).multiply(t))},n.prototype.not=function(){return n.fromBits(~this.low_,~this.high_)},n.prototype.and=function(t){return n.fromBits(this.low_&t.low_,this.high_&t.high_)},n.prototype.or=function(t){return n.fromBits(this.low_|t.low_,this.high_|t.high_)},n.prototype.xor=function(t){return n.fromBits(this.low_^t.low_,this.high_^t.high_)},n.prototype.shiftLeft=function(t){if(0===(t&=63))return this;var e=this.low_;if(t<32){var r=this.high_;return n.fromBits(e<<t,r<<t|e>>>32-t)}return n.fromBits(0,e<<t-32)},n.prototype.shiftRight=function(t){if(0===(t&=63))return this;var e=this.high_;if(t<32){var r=this.low_;return n.fromBits(r>>>t|e<<32-t,e>>t)}return n.fromBits(e>>t-32,e>=0?0:-1)},n.prototype.shiftRightUnsigned=function(t){if(0===(t&=63))return this;var e=this.high_;if(t<32){var r=this.low_;return n.fromBits(r>>>t|e<<32-t,e>>>t)}return 32===t?n.fromBits(e,0):n.fromBits(e>>>t-32,0)},n.fromInt=function(t){if(-128<=t&&t<128){var e=n.INT_CACHE_[t];if(e)return e}var r=new n(0|t,t<0?-1:0);return-128<=t&&t<128&&(n.INT_CACHE_[t]=r),r},n.fromNumber=function(t){return isNaN(t)||!isFinite(t)?n.ZERO:t<=-n.TWO_PWR_63_DBL_?n.MIN_VALUE:t+1>=n.TWO_PWR_63_DBL_?n.MAX_VALUE:t<0?n.fromNumber(-t).negate():new n(t%n.TWO_PWR_32_DBL_|0,t/n.TWO_PWR_32_DBL_|0)},n.fromBits=function(t,e){return new n(t,e)},n.fromString=function(t,e){if(0===t.length)throw Error("number format error: empty string");var r=e||10;if(r<2||36<r)throw Error("radix out of range: "+r);if("-"===t.charAt(0))return n.fromString(t.substring(1),r).negate();if(t.indexOf("-")>=0)throw Error('number format error: interior "-" character: '+t);for(var i=n.fromNumber(Math.pow(r,8)),o=n.ZERO,s=0;s<t.length;s+=8){var a=Math.min(8,t.length-s),u=parseInt(t.substring(s,s+a),r);if(a<8){var c=n.fromNumber(Math.pow(r,a));o=o.multiply(c).add(n.fromNumber(u))}else o=(o=o.multiply(i)).add(n.fromNumber(u))}return o},n.INT_CACHE_={},n.TWO_PWR_16_DBL_=65536,n.TWO_PWR_24_DBL_=1<<24,n.TWO_PWR_32_DBL_=n.TWO_PWR_16_DBL_*n.TWO_PWR_16_DBL_,n.TWO_PWR_31_DBL_=n.TWO_PWR_32_DBL_/2,n.TWO_PWR_48_DBL_=n.TWO_PWR_32_DBL_*n.TWO_PWR_16_DBL_,n.TWO_PWR_64_DBL_=n.TWO_PWR_32_DBL_*n.TWO_PWR_32_DBL_,n.TWO_PWR_63_DBL_=n.TWO_PWR_64_DBL_/2,n.ZERO=n.fromInt(0),n.ONE=n.fromInt(1),n.NEG_ONE=n.fromInt(-1),n.MAX_VALUE=n.fromBits(-1,2147483647),n.MIN_VALUE=n.fromBits(0,-2147483648),n.TWO_PWR_24_=n.fromInt(1<<24),t.exports=n,t.exports.Timestamp=n},function(t,e,r){"use strict";(function(e,n){var i="inspect",o=parseInt(16777215*Math.random(),10),s=new RegExp("^[0-9a-fA-F]{24}$");try{if(e&&e.from){var a=!0;i=r(3).inspect.custom||"inspect"}}catch(t){a=!1}for(var u=function t(r){if(r instanceof t)return r;if(!(this instanceof t))return new t(r);if(this._bsontype="ObjectID",null==r||"number"===typeof r)return this.id=this.generate(r),void(t.cacheHexString&&(this.__id=this.toString("hex")));var n=t.isValid(r);if(!n&&null!=r)throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");if(n&&"string"===typeof r&&24===r.length&&a)return new t(new e(r,"hex"));if(n&&"string"===typeof r&&24===r.length)return t.createFromHexString(r);if(null==r||12!==r.length){if(null!=r&&r.toHexString)return r;throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters")}this.id=r,t.cacheHexString&&(this.__id=this.toString("hex"))},c=[],l=0;l<256;l++)c[l]=(l<=15?"0":"")+l.toString(16);u.prototype.toHexString=function(){if(u.cacheHexString&&this.__id)return this.__id;var t="";if(!this.id||!this.id.length)throw new Error("invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is ["+JSON.stringify(this.id)+"]");if(this.id instanceof h)return t=p(this.id),u.cacheHexString&&(this.__id=t),t;for(var e=0;e<this.id.length;e++)t+=c[this.id.charCodeAt(e)];return u.cacheHexString&&(this.__id=t),t},u.prototype.get_inc=function(){return u.index=(u.index+1)%16777215},u.prototype.getInc=function(){return this.get_inc()},u.prototype.generate=function(t){"number"!==typeof t&&(t=~~(Date.now()/1e3));var r=("undefined"===typeof n||1===n.pid?Math.floor(1e5*Math.random()):n.pid)%65535,i=this.get_inc(),s=new e(12);return s[3]=255&t,s[2]=t>>8&255,s[1]=t>>16&255,s[0]=t>>24&255,s[6]=255&o,s[5]=o>>8&255,s[4]=o>>16&255,s[8]=255&r,s[7]=r>>8&255,s[11]=255&i,s[10]=i>>8&255,s[9]=i>>16&255,s},u.prototype.toString=function(t){return this.id&&this.id.copy?this.id.toString("string"===typeof t?t:"hex"):this.toHexString()},u.prototype[i]=u.prototype.toString,u.prototype.toJSON=function(){return this.toHexString()},u.prototype.equals=function(t){return t instanceof u?this.toString()===t.toString():"string"===typeof t&&u.isValid(t)&&12===t.length&&this.id instanceof h?t===this.id.toString("binary"):"string"===typeof t&&u.isValid(t)&&24===t.length?t.toLowerCase()===this.toHexString():"string"===typeof t&&u.isValid(t)&&12===t.length?t===this.id:!(null==t||!(t instanceof u||t.toHexString))&&t.toHexString()===this.toHexString()},u.prototype.getTimestamp=function(){var t=new Date,e=this.id[3]|this.id[2]<<8|this.id[1]<<16|this.id[0]<<24;return t.setTime(1e3*Math.floor(e)),t},u.index=~~(16777215*Math.random()),u.createPk=function(){return new u},u.createFromTime=function(t){var r=new e([0,0,0,0,0,0,0,0,0,0,0,0]);return r[3]=255&t,r[2]=t>>8&255,r[1]=t>>16&255,r[0]=t>>24&255,new u(r)};var f=[];for(l=0;l<10;)f[48+l]=l++;for(;l<16;)f[55+l]=f[87+l]=l++;var h=e,p=function(t){return t.toString("hex")};u.createFromHexString=function(t){if("undefined"===typeof t||null!=t&&24!==t.length)throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");if(a)return new u(new e(t,"hex"));for(var r=new h(12),n=0,i=0;i<24;)r[n++]=f[t.charCodeAt(i++)]<<4|f[t.charCodeAt(i++)];return new u(r)},u.isValid=function(t){return null!=t&&("number"===typeof t||("string"===typeof t?12===t.length||24===t.length&&s.test(t):t instanceof u||(t instanceof h||!!t.toHexString&&(12===t.id.length||24===t.id.length&&s.test(t.id)))))},Object.defineProperty(u.prototype,"generationTime",{enumerable:!0,get:function(){return this.id[3]|this.id[2]<<8|this.id[1]<<16|this.id[0]<<24},set:function(t){this.id[3]=255&t,this.id[2]=t>>8&255,this.id[1]=t>>16&255,this.id[0]=t>>24&255}}),t.exports=u,t.exports.ObjectID=u,t.exports.ObjectId=u}).call(this,r(1).Buffer,r(7))},function(t,e,r){"use strict";function n(t,e){if(!(this instanceof n))return new n;this._bsontype="BSONRegExp",this.pattern=t||"",this.options=e||"";for(var r=0;r<this.options.length;r++)if("i"!==this.options[r]&&"m"!==this.options[r]&&"x"!==this.options[r]&&"l"!==this.options[r]&&"s"!==this.options[r]&&"u"!==this.options[r])throw new Error("the regular expression options ["+this.options[r]+"] is not supported")}t.exports=n,t.exports.BSONRegExp=n},function(t,e,r){"use strict";(function(e){var n=e&&r(3).inspect.custom||"inspect";function i(t){if(!(this instanceof i))return new i(t);this._bsontype="Symbol",this.value=t}i.prototype.valueOf=function(){return this.value},i.prototype.toString=function(){return this.value},i.prototype[n]=function(){return this.value},i.prototype.toJSON=function(){return this.value},t.exports=i,t.exports.Symbol=i}).call(this,r(1).Buffer)},function(t,e,r){"use strict";var n=function t(e,r){if(!(this instanceof t))return new t(e,r);this._bsontype="Code",this.code=e,this.scope=r};n.prototype.toJSON=function(){return{scope:this.scope,code:this.code}},t.exports=n,t.exports.Code=n},function(t,e,r){"use strict";(function(e){var n=r(15),i=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,o=/^(\+|-)?(Infinity|inf)$/i,s=/^(\+|-)?NaN$/i,a=6176,u=[124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),c=[248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),l=[120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),f=/^([-+])?(\d+)?$/,h=function(t){return!isNaN(parseInt(t,10))},p=function(t){var e=n.fromNumber(1e9),r=n.fromNumber(0),i=0;if(!t.parts[0]&&!t.parts[1]&&!t.parts[2]&&!t.parts[3])return{quotient:t,rem:r};for(i=0;i<=3;i++)r=(r=r.shiftLeft(32)).add(new n(t.parts[i],0)),t.parts[i]=r.div(e).low_,r=r.modulo(e);return{quotient:t,rem:r}},d=function(t){this._bsontype="Decimal128",this.bytes=t};d.fromString=function(t){var r,p=!1,y=!1,_=!1,m=0,v=0,g=0,b=0,w=0,O=[0],S=0,E=0,A=0,$=0,N=0,j=0,x=[0,0],T=[0,0],B=0;if((t=t.trim()).length>=7e3)throw new Error(t+" not a valid Decimal128 string");var k=t.match(i),C=t.match(o),D=t.match(s);if(!k&&!C&&!D||0===t.length)throw new Error(t+" not a valid Decimal128 string");if(k&&k[4]&&void 0===k[2])throw new Error(t+" not a valid Decimal128 string");if("+"!==t[B]&&"-"!==t[B]||(p="-"===t[B++]),!h(t[B])&&"."!==t[B]){if("i"===t[B]||"I"===t[B])return new d(new e(p?c:l));if("N"===t[B])return new d(new e(u))}for(;h(t[B])||"."===t[B];)if("."!==t[B])S<34&&("0"!==t[B]||_)&&(_||(w=v),_=!0,O[E++]=parseInt(t[B],10),S+=1),_&&(g+=1),y&&(b+=1),v+=1,B+=1;else{if(y)return new d(new e(u));y=!0,B+=1}if(y&&!v)throw new Error(t+" not a valid Decimal128 string");if("e"===t[B]||"E"===t[B]){var P=t.substr(++B).match(f);if(!P||!P[2])return new d(new e(u));N=parseInt(P[0],10),B+=P[0].length}if(t[B])return new d(new e(u));if(A=0,S){if($=S-1,m=g,0!==N&&1!==m)for(;"0"===t[w+m-1];)m-=1}else A=0,$=0,O[0]=0,g=1,S=1,m=0;for(N<=b&&b-N>16384?N=-6176:N-=b;N>6111;){if(($+=1)-A>34){var M=O.join("");if(M.match(/^0+$/)){N=6111;break}return new d(new e(p?c:l))}N-=1}for(;N<-6176||S<g;){if(0===$){N=-6176,m=0;break}if(S<g?g-=1:$-=1,!(N<6111)){if((M=O.join("")).match(/^0+$/)){N=6111;break}return new d(new e(p?c:l))}N+=1}if($-A+1<m&&"0"!==t[m]){var R=v;y&&-6176===N&&(w+=1,R+=1);var F=parseInt(t[w+$+1],10),I=0;if(F>=5&&(I=1,5===F))for(I=O[$]%2===1,j=w+$+2;j<R;j++)if(parseInt(t[j],10)){I=1;break}if(I)for(var L=$;L>=0&&++O[L]>9;L--)if(O[L]=0,0===L){if(!(N<6111))return new d(new e(p?c:l));N+=1,O[L]=1}}if(x=n.fromNumber(0),T=n.fromNumber(0),0===m)x=n.fromNumber(0),T=n.fromNumber(0);else if($-A<17)for(L=A,T=n.fromNumber(O[L++]),x=new n(0,0);L<=$;L++)T=(T=T.multiply(n.fromNumber(10))).add(n.fromNumber(O[L]));else{for(L=A,x=n.fromNumber(O[L++]);L<=$-17;L++)x=(x=x.multiply(n.fromNumber(10))).add(n.fromNumber(O[L]));for(T=n.fromNumber(O[L++]);L<=$;L++)T=(T=T.multiply(n.fromNumber(10))).add(n.fromNumber(O[L]))}var U,V,q,W,H=function(t,e){if(!t&&!e)return{high:n.fromNumber(0),low:n.fromNumber(0)};var r=t.shiftRightUnsigned(32),i=new n(t.getLowBits(),0),o=e.shiftRightUnsigned(32),s=new n(e.getLowBits(),0),a=r.multiply(o),u=r.multiply(s),c=i.multiply(o),l=i.multiply(s);return a=a.add(u.shiftRightUnsigned(32)),u=new n(u.getLowBits(),0).add(c).add(l.shiftRightUnsigned(32)),{high:a=a.add(u.shiftRightUnsigned(32)),low:l=u.shiftLeft(32).add(new n(l.getLowBits(),0))}}(x,n.fromString("100000000000000000"));H.low=H.low.add(T),U=H.low,V=T,q=U.high_>>>0,W=V.high_>>>0,(q<W||q===W&&U.low_>>>0<V.low_>>>0)&&(H.high=H.high.add(n.fromNumber(1))),r=N+a;var Y={low:n.fromNumber(0),high:n.fromNumber(0)};H.high.shiftRightUnsigned(49).and(n.fromNumber(1)).equals(n.fromNumber)?(Y.high=Y.high.or(n.fromNumber(3).shiftLeft(61)),Y.high=Y.high.or(n.fromNumber(r).and(n.fromNumber(16383).shiftLeft(47))),Y.high=Y.high.or(H.high.and(n.fromNumber(0x7fffffffffff)))):(Y.high=Y.high.or(n.fromNumber(16383&r).shiftLeft(49)),Y.high=Y.high.or(H.high.and(n.fromNumber(562949953421311)))),Y.low=H.low,p&&(Y.high=Y.high.or(n.fromString("9223372036854775808")));var z=new e(16);return B=0,z[B++]=255&Y.low.low_,z[B++]=Y.low.low_>>8&255,z[B++]=Y.low.low_>>16&255,z[B++]=Y.low.low_>>24&255,z[B++]=255&Y.low.high_,z[B++]=Y.low.high_>>8&255,z[B++]=Y.low.high_>>16&255,z[B++]=Y.low.high_>>24&255,z[B++]=255&Y.high.low_,z[B++]=Y.high.low_>>8&255,z[B++]=Y.high.low_>>16&255,z[B++]=Y.high.low_>>24&255,z[B++]=255&Y.high.high_,z[B++]=Y.high.high_>>8&255,z[B++]=Y.high.high_>>16&255,z[B++]=Y.high.high_>>24&255,new d(z)};a=6176,d.prototype.toString=function(){for(var t,e,r,i,o,s,u=0,c=new Array(36),l=0;l<c.length;l++)c[l]=0;var f,h,d,y,_,m=0,v=!1,g={parts:new Array(4)},b=[];m=0;var w=this.bytes;if(i=w[m++]|w[m++]<<8|w[m++]<<16|w[m++]<<24,r=w[m++]|w[m++]<<8|w[m++]<<16|w[m++]<<24,e=w[m++]|w[m++]<<8|w[m++]<<16|w[m++]<<24,t=w[m++]|w[m++]<<8|w[m++]<<16|w[m++]<<24,m=0,{low:new n(i,r),high:new n(e,t)}.high.lessThan(n.ZERO)&&b.push("-"),(o=t>>26&31)>>3===3){if(30===o)return b.join("")+"Infinity";if(31===o)return"NaN";s=t>>15&16383,d=8+(t>>14&1)}else d=t>>14&7,s=t>>17&16383;if(f=s-a,g.parts[0]=(16383&t)+((15&d)<<14),g.parts[1]=e,g.parts[2]=r,g.parts[3]=i,0===g.parts[0]&&0===g.parts[1]&&0===g.parts[2]&&0===g.parts[3])v=!0;else for(_=3;_>=0;_--){var O=0,S=p(g);if(g=S.quotient,O=S.rem.low_)for(y=8;y>=0;y--)c[9*_+y]=O%10,O=Math.floor(O/10)}if(v)u=1,c[m]=0;else for(u=36,l=0;!c[m];)l++,u-=1,m+=1;if((h=u-1+f)>=34||h<=-7||f>0){for(b.push(c[m++]),(u-=1)&&b.push("."),l=0;l<u;l++)b.push(c[m++]);b.push("E"),h>0?b.push("+"+h):b.push(h)}else if(f>=0)for(l=0;l<u;l++)b.push(c[m++]);else{var E=u+f;if(E>0)for(l=0;l<E;l++)b.push(c[m++]);else b.push("0");for(b.push(".");E++<0;)b.push("0");for(l=0;l<u-Math.max(E-1,0);l++)b.push(c[m++])}return b.join("")},d.prototype.toJSON=function(){return{$numberDecimal:this.toString()}},t.exports=d,t.exports.Decimal128=d}).call(this,r(1).Buffer)},function(t,e,r){"use strict";function n(){if(!(this instanceof n))return new n;this._bsontype="MaxKey"}t.exports=n,t.exports.MaxKey=n},function(t,e,r){"use strict";function n(t,e,r){if(!(this instanceof n))return new n(t,e,r);this._bsontype="DBRef",this.namespace=t,this.oid=e,this.db=r}n.prototype.toJSON=function(){return{$ref:this.namespace,$id:this.oid,$db:null==this.db?"":this.db}},t.exports=n,t.exports.DBRef=n},function(t,e,r){"use strict";t.exports=r(14).get().Decimal128},function(t,e,r){"use strict";t.exports=r(104)},function(t,e,r){"use strict";(function(e){var n=r(17),i=r(4),o=r(10),s=r(60),a=r(8),u=r(12).internalToObjectOptions,c=r(0),l=r(3),f=c.isMongooseObject;function h(t,e,r){for(var n=[].concat(t),o=Object.keys(h.mixin),s=o.length,a=0;a<s;++a)n[o[a]]=h.mixin[o[a]];return n._path=e,n.isMongooseArray=!0,n.validators=[],n._atomics={},n._schema=void 0,l.inspect.custom&&(n[l.inspect.custom]=n.inspect),r&&r instanceof i&&(n._parent=r,n._schema=r.schema.path(e)),n}function p(t,e){var r=a(t,"_schema.caster.options.ref",null);0===t.length&&e.length>0&&function(t,e){if(!e)return!1;for(var r=0;r<t.length;++r){var n=t[r];if(null==n)return!1;var o=n.constructor;if(!(n instanceof i)||o.modelName!==e&&o.baseModelName!==e)return!1}return!0}(e,r)&&t._parent.populated(t._path,[],{model:e[0].constructor})}h.mixin={toBSON:function(){return this.toObject(u)},_atomics:void 0,_parent:void 0,_cast:function(t){var r,n=!1;return this._parent&&(n=this._parent.populated(this._path,!0)),n&&null!==t&&void 0!==t?(r=n.options.model||n.options.Model,(e.isBuffer(t)||t instanceof o||!c.isObject(t))&&(t={_id:t}),t.schema&&t.schema.discriminatorMapping&&void 0!==t.schema.discriminatorMapping.key||(t=new r(t)),this._schema.caster.applySetters(t,this._parent,!0)):this._schema.caster.applySetters(t,this._parent,!1)},_markModified:function(t,e){var r,n=this._parent;return n&&(r=this._path,arguments.length&&(r=null!=e?r+"."+this.indexOf(t)+"."+e:r+"."+t),n.markModified(r,arguments.length>0?t:n)),this},_registerAtomic:function(t,e){if("$set"===t)return this._atomics={$set:e},this;var r,i=this._atomics;if("$pop"===t&&!("$pop"in i)){var o=this;this._parent.once("save",function(){o._popped=o._shifted=null})}if(this._atomics.$set||Object.keys(i).length&&!(t in i))return this._atomics={$set:this},this;if("$pullAll"===t||"$addToSet"===t)i[t]||(i[t]=[]),i[t]=i[t].concat(e);else if("$pullDocs"===t){var s=i.$pull||(i.$pull={});e[0]instanceof n?(r=s.$or||(s.$or=[]),Array.prototype.push.apply(r,e.map(function(t){return t.toObject({transform:!1,virtuals:!1})}))):(r=s._id||(s._id={$in:[]})).$in=r.$in.concat(e)}else"$push"===t?(i.$push=i.$push||{$each:[]},i.$push.$each=i.$push.$each.concat(e)):i[t]=e;return this},$__getAtomics:function(){var t=[],e=Object.keys(this._atomics),r=e.length,n=Object.assign({},u,{_isNested:!0});if(0===r)return t[0]=["$set",this.toObject(n)],t;for(;r--;){var i=e[r],o=this._atomics[i];f(o)?o=o.toObject(n):Array.isArray(o)?o=this.toObject.call(o,n):null!=o&&Array.isArray(o.$each)?o.$each=this.toObject.call(o.$each,n):o.valueOf&&(o=o.valueOf()),"$addToSet"===i&&(o={$each:o}),t.push([i,o])}return t},hasAtomics:function(){return this._atomics&&"Object"===this._atomics.constructor.name?Object.keys(this._atomics).length:0},_mapCast:function(t,e){return this._cast(t,this.length+e)},push:function(){p(this,arguments);var t=[].map.call(arguments,this._mapCast,this);t=this._schema.applySetters(t,this._parent,void 0,void 0,{skipDocumentArrayCast:!0});var e=[].push.apply(this,t);return this._registerAtomic("$push",t),this._markModified(),e},nonAtomicPush:function(){var t=[].map.call(arguments,this._mapCast,this),e=[].push.apply(this,t);return this._registerAtomic("$set",this),this._markModified(),e},$pop:function(){if(this._registerAtomic("$pop",1),this._markModified(),!this._popped)return this._popped=!0,[].pop.call(this)},pop:function(){var t=[].pop.call(this);return this._registerAtomic("$set",this),this._markModified(),t},$shift:function(){if(this._registerAtomic("$pop",-1),this._markModified(),!this._shifted)return this._shifted=!0,[].shift.call(this)},shift:function(){var t=[].shift.call(this);return this._registerAtomic("$set",this),this._markModified(),t},pull:function(){for(var t,e=[].map.call(arguments,this._cast,this),r=this._parent.get(this._path),o=r.length;o--;){if((t=r[o])instanceof i)e.some(function(e){return t.equals(e)})&&[].splice.call(r,o,1);else~r.indexOf.call(e,t)&&[].splice.call(r,o,1)}return e[0]instanceof n?this._registerAtomic("$pullDocs",e.map(function(t){return t._id||t})):this._registerAtomic("$pullAll",e),this._markModified(),s(this._parent,this._path)>0&&this._registerAtomic("$set",this),this},splice:function(){var t,e,r;if(p(this,Array.prototype.slice.call(arguments,2)),arguments.length){for(e=[],r=0;r<arguments.length;++r)e[r]=r<2?arguments[r]:this._cast(arguments[r],arguments[0]+(r-2));t=[].splice.apply(this,e),this._registerAtomic("$set",this),this._markModified()}return t},unshift:function(){p(this,arguments);var t=[].map.call(arguments,this._cast,this);return t=this._schema.applySetters(t,this._parent),[].unshift.apply(this,t),this._registerAtomic("$set",this),this._markModified(),this.length},sort:function(){var t=[].sort.apply(this,arguments);return this._registerAtomic("$set",this),this._markModified(),t},addToSet:function(){p(this,arguments);var t=[].map.call(arguments,this._mapCast,this),e=[],r="";return(t=this._schema.applySetters(t,this._parent))[0]instanceof n?r="doc":t[0]instanceof Date&&(r="date"),t.forEach(function(t){var n;switch(r){case"doc":n=this.some(function(e){return e.equals(t)});break;case"date":var i=+t;n=this.some(function(t){return+t===i});break;default:n=~this.indexOf(t)}n||([].push.call(this,t),this._registerAtomic("$addToSet",t),this._markModified(),[].push.call(e,t))},this),e},set:function(t,e){var r=this._cast(e,t);return this[t]=r,this._markModified(t),this},toObject:function(t){return t&&t.depopulate?((t=c.clone(t))._isNested=!0,this.map(function(e){return e instanceof i?e.toObject(t):e})):this.slice()},inspect:function(){return JSON.stringify(this)},indexOf:function(t){t instanceof o&&(t=t.toString());for(var e=0,r=this.length;e<r;++e)if(t==this[e])return e;return-1}},h.mixin.remove=h.mixin.pull,t.exports=h}).call(this,r(1).Buffer)},function(t,e,r){"use strict";(function(e){t.exports=function(t){return e.nextTick(t)}}).call(this,r(7))},function(t,e,r){"use strict";(function(e){var n,i=r(5),o=i.CastError,s=r(10),a=r(0);function u(t,e){var r="string"===typeof t&&24===t.length&&/^[a-f0-9]+$/i.test(t),n=e&&e.suppressWarning;!r&&"undefined"!==typeof t||n||(console.warn("mongoose: To create a new ObjectId please try `Mongoose.Types.ObjectId` instead of using `Mongoose.Schema.ObjectId`. Set the `suppressWarning` option if you're trying to create a hex char path in your schema."),console.trace()),i.call(this,t,e,"ObjectID")}function c(t){return this.cast(t)}function l(){return new s}function f(t){if(n||(n=r(4)),this instanceof n){if(void 0===t){var e=new s;return this.$__._id=e,e}this.$__._id=t}return t}u.schemaName="ObjectId",u.prototype=Object.create(i.prototype),u.prototype.constructor=u,u.prototype.auto=function(t){return t&&(this.default(l),this.set(f)),this},u.prototype.checkRequired=function(t,e){return i._isRef(this,t,e,!0)?!!t:t instanceof s},u.prototype.cast=function(t,u,c){if(i._isRef(this,t,u,c)){if(null===t||void 0===t)return t;if(n||(n=r(4)),t instanceof n)return t.$__.wasPopulated=!0,t;if(t instanceof s)return t;if("objectid"===(t.constructor.name||"").toLowerCase())return new s(t.toHexString());if(e.isBuffer(t)||!a.isObject(t))throw new o("ObjectId",t,this.path);var l=u.$__fullPath(this.path),f=(u.ownerDocument?u.ownerDocument():u).populated(l,!0),h=t;return u.$__.populated&&u.$__.populated[l]&&u.$__.populated[l].options&&u.$__.populated[l].options.options&&u.$__.populated[l].options.options.lean||((h=new f.options.model(t)).$__.wasPopulated=!0),h}if(null===t||void 0===t)return t;if(t instanceof s)return t;if(t._id){if(t._id instanceof s)return t._id;if(t._id.toString instanceof Function)return new s(t._id.toString())}if(t.toString instanceof Function)try{return new s(t.toString())}catch(e){throw new o("ObjectId",t,this.path)}throw new o("ObjectId",t,this.path)},u.prototype.$conditionalHandlers=a.options(i.prototype.$conditionalHandlers,{$gt:c,$gte:c,$lt:c,$lte:c}),l.$runBeforeSetters=!0,t.exports=u}).call(this,r(1).Buffer)},function(t,e,r){"use strict";function n(t){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack,this.message=t,this.name="MongooseError"}n.prototype=Object.create(Error.prototype),n.prototype.constructor=Error,t.exports=n},function(t,e,r){"use strict";var n=r(40);t.exports=function(t){var e=null!=this?this.path:null;return n(t,e)}},function(t,e,r){"use strict";var n=r(9);t.exports=function(e,r){if(null==e)return e;if(t.exports.convertToTrue.has(e))return!0;if(t.exports.convertToFalse.has(e))return!1;throw new n("boolean",e,r)},t.exports.convertToTrue=new Set([!0,"true",1,"1","yes"]),t.exports.convertToFalse=new Set([!1,"false",0,"0","no"])},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)}t.exports=function(t){return null==t||("object"!==n(t)||!("$meta"in t)&&!("$slice"in t))}},function(t,e,r){"use strict";var n=r(5),i=r(0);function o(t,e){if(e&&e.default){var r=e.default;Array.isArray(r)&&0===r.length?e.default=Array:!e.shared&&i.isObject(r)&&0===Object.keys(r).length&&(e.default=function(){return{}})}n.call(this,t,e,"Mixed")}o.schemaName="Mixed",o.prototype=Object.create(n.prototype),o.prototype.constructor=o,o.prototype.cast=function(t){return t},o.prototype.castForQuery=function(t,e){return 2===arguments.length?e:t},t.exports=o},function(t,e,r){"use strict";(function(n){function i(t){return(i="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o,s=r(11).EventEmitter,a=r(115),u=r(5),c=r(44),l=r(8),f=r(116),h=r(34),p=r(14).get().ReadPreference,d=r(0);function y(t,e){if(!(this instanceof y))return new y(t,e);this.obj=t,this.paths={},this.aliases={},this.subpaths={},this.virtuals={},this.singleNestedPaths={},this.nested={},this.inherits={},this.callQueue=[],this._indexes=[],this.methods={},this.methodOptions={},this.statics={},this.tree={},this.query={},this.childSchemas=[],this.plugins=[],this.s={hooks:new a},this.options=this.defaultOptions(e),t&&this.add(t);var r=t&&t._id&&d.isObject(t._id);if(!this.paths._id&&!this.options.noId&&this.options._id&&!r){var n={_id:{auto:!0}};n._id[this.options.typeKey]=y.ObjectId,this.add(n)}this.options.timestamps&&this.setupTimestamp(this.options.timestamps)}y.prototype=Object.create(s.prototype),y.prototype.constructor=y,y.prototype.instanceOfSchema=!0,Object.defineProperty(y.prototype,"childSchemas",{configurable:!1,enumerable:!0,writable:!0}),y.prototype.obj,y.prototype.paths,y.prototype.tree,y.prototype.clone=function(){var t=this,e=new y({},this._userProvidedOptions);return e.obj=this.obj,e.options=d.clone(this.options),e.callQueue=this.callQueue.map(function(t){return t}),e.methods=d.clone(this.methods),e.methodOptions=d.clone(this.methodOptions),e.statics=d.clone(this.statics),e.query=d.clone(this.query),e.plugins=Array.prototype.slice.call(this.plugins),e._indexes=d.clone(this._indexes),e.s.hooks=this.s.hooks.clone(),e._originalSchema=null==this._originalSchema?this._originalSchema:this._originalSchema.clone(),e.tree=d.clone(this.tree),e.paths=d.clone(this.paths),e.nested=d.clone(this.nested),e.subpaths=d.clone(this.subpaths),e.childSchemas=this.childSchemas.slice(),e.singleNestedPaths=d.clone(this.singleNestedPaths),e.virtuals=d.clone(this.virtuals),e.$globalPluginsApplied=this.$globalPluginsApplied,e.$isRootDiscriminator=this.$isRootDiscriminator,null!=this.discriminatorMapping&&(e.discriminatorMapping=Object.assign({},this.discriminatorMapping)),null!=e.discriminators&&(e.discriminators=Object.assign({},this.discriminators)),e.aliases=Object.assign({},this.aliases),e.on("init",function(e){return t.emit("init",e)}),e},y.prototype.defaultOptions=function(t){return t&&!1===t.safe&&(t.safe={w:0}),t&&t.safe&&0===t.safe.w&&(t.versionKey=!1),this._userProvidedOptions=null==t?{}:d.clone(t),(t=d.options({strict:!0,bufferCommands:!0,capped:!1,versionKey:"__v",discriminatorKey:"__t",minimize:!0,autoIndex:null,shardKey:null,read:null,validateBeforeSave:!0,noId:!1,_id:!0,noVirtualId:!1,id:!0,typeKey:"type"},d.clone(t))).read&&(t.read=p(t.read)),t},y.prototype.add=function(t,e){e=e||"";for(var r=Object.keys(t),n=0;n<r.length;++n){var i=r[n];if(null==t[i])throw new TypeError("Invalid value for schema path `"+e+i+"`");if(Array.isArray(t[i])&&1===t[i].length&&null==t[i][0])throw new TypeError("Invalid value for schema Array path `"+e+i+"`");!d.isObject(t[i])||t[i].constructor&&"Object"!==d.getFunctionName(t[i].constructor)||t[i][this.options.typeKey]&&("type"!==this.options.typeKey||!t[i].type.type)?(e&&(this.nested[e.substr(0,e.length-1)]=!0),this.path(e+i,t[i])):Object.keys(t[i]).length?(this.nested[e+i]=!0,this.add(t[i],e+i+".")):(e&&(this.nested[e.substr(0,e.length-1)]=!0),this.path(e+i,t[i]))}!function(t,e){e=e||Object.keys(t.paths);var r=!0,n=!1,i=void 0;try{for(var o,s=e[Symbol.iterator]();!(r=(o=s.next()).done);r=!0){var a=o.value,u=l(t.paths[a],"options");if(null!=u){var c=t.paths[a].path,f=u.alias;if(f){if("string"!==typeof f)throw new Error("Invalid value for alias option on "+c+", got "+f);t.aliases[f]=c,t.virtual(f).get(function(t){return function(){return"function"===typeof this.get?this.get(t):this[t]}}(c)).set(function(t){return function(e){return this.set(t,e)}}(c))}}}}catch(t){n=!0,i=t}finally{try{r||null==s.return||s.return()}finally{if(n)throw i}}}(this,Object.keys(t).map(function(t){return e?e+t:t}))},y.reserved=Object.create(null),y.prototype.reserved=y.reserved;var _=y.reserved;_.prototype=_.emit=_.on=_.once=_.listeners=_.removeListener=_.collection=_.db=_.errors=_.init=_.isModified=_.isNew=_.get=_.modelName=_.save=_.schema=_.toObject=_.validate=_.remove=_._pres=_._posts=1;var m={};function v(t,e){return"boolean"===typeof t?e:"boolean"===typeof t[e]?t[e]?e:null:e in t?t[e]:e}function g(t,e){var r=e.split(/\.(\d+)\.|\.(\d+)$/).filter(Boolean);if(r.length<2)return t.paths[r[0]];var n=t.path(r[0]),i=!1;if(!n)return n;for(var s,a=r.length-1,c=1;c<r.length;++c){if(i=!1,s=r[c],c===a&&n&&!/\D/.test(s)){if(n.$isMongooseDocumentArray){var f=n;(n=new u(s,{required:l(n,"schemaOptions.required",!1)})).cast=function(t,e,r){return f.cast(t,e,r)[0]},n.$isMongooseDocumentArrayElement=!0,n.caster=f.caster,n.schema=f.schema}else n=n instanceof o.Array?n.caster:void 0;break}if(/\D/.test(s)){if(!n||!n.schema){n=void 0;break}i="nested"===n.schema.pathType(s),n=n.schema.path(s)}}return t.subpaths[e]=n,n?"real":i?"nested":"adhocOrUndefined"}m.increment="`increment` should not be used as a schema path name unless you have disabled versioning.",y.prototype.path=function(t,e){if(void 0===e){if(this.paths[t])return this.paths[t];if(this.subpaths[t])return this.subpaths[t];if(this.singleNestedPaths[t])return this.singleNestedPaths[t];for(var r=Object.keys(this.paths),n=0;n<r.length;n++){var o=r[n];if(o.includes(".$*"))if(new RegExp("^"+o.replace(/\.\$\*/g,".[^.]+")+"$").test(t))return this.paths[o]}return/\.\d+\.?.*$/.test(t)?function(t,e){return g(t,e),t.subpaths[e]}(this,t):void 0}if(_[t])throw new Error("`"+t+"` may not be used as a schema pathname");m[t]&&console.log("WARN: "+m[t]);var s=t.split(/\./),a=s.pop(),u=this.tree;s.forEach(function(e,r){if(u[e]||(u[e]={}),"object"!==i(u[e])){var n="Cannot set nested path `"+t+"`. Parent path `"+s.slice(0,r).concat([e]).join(".")+"` already set to type "+u[e].name+".";throw new Error(n)}u=u[e]}),u[a]=d.clone(e),this.paths[t]=y.interpretAsType(t,e,this.options);var c=this.paths[t];if(c.$isSchemaMap){var l=t+".$*";this.paths[t+".$*"]=y.interpretAsType(l,e.of||{type:{}},this.options),c.$__schemaType=this.paths[t+".$*"]}if(c.$isSingleNested){for(var f in c.schema.paths)this.singleNestedPaths[t+"."+f]=c.schema.paths[f];for(var h in c.schema.singleNestedPaths)this.singleNestedPaths[t+"."+h]=c.schema.singleNestedPaths[h];this.childSchemas.push({schema:c.schema,model:c.caster})}else c.$isMongooseDocumentArray&&this.childSchemas.push({schema:c.schema,model:c.casterConstructor});return this},y.interpretAsType=function(t,e,r){if(e instanceof u)return e;if(e.constructor&&"Object"!==d.getFunctionName(e.constructor)){var i=e;(e={})[r.typeKey]=i}var s,a=!e[r.typeKey]||"type"===r.typeKey&&e.type.type?{}:e[r.typeKey];if("Object"===d.getFunctionName(a.constructor)||"mixed"===a)return new o.Mixed(t,e);if(Array.isArray(a)||Array===a||"array"===a){var c=Array===a||"array"===a?e.cast:a[0];if(c&&c.instanceOfSchema)return new o.DocumentArray(t,c,e);if(c&&c[r.typeKey]&&c[r.typeKey].instanceOfSchema)return new o.DocumentArray(t,c[r.typeKey],e,c);if(Array.isArray(c))return new o.Array(t,y.interpretAsType(t,c,r),e);if("string"===typeof c)c=o[c.charAt(0).toUpperCase()+c.substring(1)];else if(c&&(!c[r.typeKey]||"type"===r.typeKey&&c.type.type)&&"Object"===d.getFunctionName(c.constructor)){if(Object.keys(c).length){var l={minimize:r.minimize};r.typeKey&&(l.typeKey=r.typeKey),r.hasOwnProperty("strict")&&(l.strict=r.strict);var f=new y(c,l);return f.$implicitlyCreated=!0,new o.DocumentArray(t,f,e)}return new o.Array(t,o.Mixed,e)}if(c&&!((s="string"===typeof(a=!c[r.typeKey]||"type"===r.typeKey&&c.type.type?c:c[r.typeKey])?a:a.schemaName||d.getFunctionName(a))in o))throw new TypeError("Undefined type `"+s+"` at array `"+t+"`");return new o.Array(t,c||o.Mixed,e,r)}if(a&&a.instanceOfSchema)return new o.Embedded(a,t,e);if((s=n.isBuffer(a)?"Buffer":"string"===typeof a?a:a.schemaName||d.getFunctionName(a))&&(s=s.charAt(0).toUpperCase()+s.substring(1)),void 0==o[s])throw new TypeError("Undefined type `"+s+"` at `"+t+"`\n Did you try nesting Schemas? You can only nest using refs or arrays.");return new o[s](t,e)},y.prototype.eachPath=function(t){for(var e=Object.keys(this.paths),r=e.length,n=0;n<r;++n)t(e[n],this.paths[e[n]]);return this},y.prototype.requiredPaths=function(t){if(this._requiredpaths&&!t)return this._requiredpaths;for(var e=Object.keys(this.paths),r=e.length,n=[];r--;){var i=e[r];this.paths[i].isRequired&&n.push(i)}return this._requiredpaths=n,this._requiredpaths},y.prototype.indexedPaths=function(){return this._indexedpaths?this._indexedpaths:(this._indexedpaths=this.indexes(),this._indexedpaths)},y.prototype.pathType=function(t){if(t in this.paths)return"real";if(t in this.virtuals)return"virtual";if(t in this.nested)return"nested";if(t in this.subpaths)return"real";if(t in this.singleNestedPaths)return"real";for(var e=Object.keys(this.paths),r=0;r<e.length;r++){var n=e[r];if(n.includes(".$*"))if(new RegExp("^"+n.replace(/\.\$\*/g,".[^.]+")+"$").test(t))return this.paths[n]}return/\.\d+\.|\.\d+$/.test(t)?g(this,t):"adhocOrUndefined"},y.prototype.hasMixedParent=function(t){var e=t.split(/\./g);t="";for(var r=0;r<e.length;++r)if((t=r>0?t+"."+e[r]:e[r])in this.paths&&this.paths[t]instanceof o.Mixed)return!0;return!1},y.prototype.setupTimestamp=function(t){if(t){var e=v(t,"createdAt"),r=v(t,"updatedAt"),n={};r&&!this.paths[r]&&(n[r]=Date),e&&!this.paths[e]&&(n[e]=Date),this.add(n),this.pre("save",function(t){var n=new Date,i=this._id&&this._id.auto;if(e&&!this.get(e)&&this.isSelected(e)&&this.set(e,i?this._id.getTimestamp():n),r&&(this.isNew||this.isModified())){var o=n;this.isNew&&(null!=e?o=this.get(e):i&&(o=this._id.getTimestamp())),this.set(r,o)}t()});var i=function(t,n){var i=new Date,o={},s=o;return n?(t&&t.$set&&(t=t.$set,o.$set={},s=o.$set),r&&!t[r]&&(s[r]=i),e&&!t[e]&&(s[e]=i),o):(o={$set:{}},t=t||{},!r||t.$currentDate&&t.$currentDate[r]||(o.$set[r]=i),e&&(t[e]&&delete t[e],t.$set&&t.$set[e]&&delete t.$set[e],o.$setOnInsert={},o.$setOnInsert[e]=i),o)};this.methods.initializeTimestamps=function(){return e&&!this.get(e)&&this.set(e,new Date),r&&!this.get(r)&&this.set(r,new Date),this},this.pre("findOneAndUpdate",o),this.pre("update",o),this.pre("updateOne",o),this.pre("updateMany",o)}function o(t){var e=this.options.overwrite;this.update({},i(this.getUpdate(),e),{overwrite:e}),function(t){var e,r,n,i,o,s,a=new Date,u=t.getUpdate(),c=Object.keys(u),l=t.model.schema;if(c.length&&"$"===c[0].charAt(0)){if(u.$push)for(e in u.$push){var f=l.path(e);u.$push[e]&&f&&f.$isMongooseDocumentArray&&f.schema.options.timestamps&&(o=f.schema.options.timestamps,n=v(o,"createdAt"),i=v(o,"updatedAt"),u.$push[e].$each?u.$push[e].$each.forEach(function(t){null!=i&&(t[i]=a),null!=n&&(t[n]=a)}):(null!=i&&(u.$push[e][i]=a),null!=n&&(u.$push[e][n]=a)))}if(u.$set)for(e in u.$set)if(s=l.path(e))if(Array.isArray(u.$set[e])&&s.$isMongooseDocumentArray){if(r=u.$set[e].length,o=l.path(e).schema.options.timestamps){n=v(o,"createdAt"),i=v(o,"updatedAt");for(var h=0;h<r;++h)null!=i&&(u.$set[e][h][i]=a),null!=n&&(u.$set[e][h][n]=a)}}else u.$set[e]&&s.$isSingleNested&&(o=l.path(e).schema.options.timestamps)&&(n=v(o,"createdAt"),null!=(i=v(o,"updatedAt"))&&(u.$set[e][i]=a),null!=n&&(u.$set[e][n]=a))}}(this),t()}},y.prototype.queue=function(t,e){return this.callQueue.push([t,e]),this},y.prototype.pre=function(){return this.s.hooks.pre.apply(this.s.hooks,arguments),this},y.prototype.post=function(){return this.s.hooks.post.apply(this.s.hooks,arguments),this},y.prototype.plugin=function(t,e){if("function"!==typeof t)throw new Error('First param to `schema.plugin()` must be a function, got "'+i(t)+'"');if(e&&e.deduplicate)for(var r=0;r<this.plugins.length;++r)if(this.plugins[r].fn===t)return this;return this.plugins.push({fn:t,opts:e}),t(this,e),this},y.prototype.method=function(t,e,r){if("string"!==typeof t)for(var n in t)this.methods[n]=t[n],this.methodOptions[n]=d.clone(r);else this.methods[t]=e,this.methodOptions[t]=d.clone(r);return this},y.prototype.static=function(t,e){if("string"!==typeof t)for(var r in t)this.statics[r]=t[r];else this.statics[t]=e;return this},y.prototype.index=function(t,e){return t||(t={}),e||(e={}),e.expires&&d.expires(e),this._indexes.push([t,e]),this},y.prototype.set=function(t,e,r){if(1===arguments.length)return this.options[t];switch(t){case"read":this.options[t]=p(e,r),this._userProvidedOptions[t]=this.options[t];break;case"safe":this.options[t]=!1===e?{w:0}:e,this._userProvidedOptions[t]=this.options[t];break;case"timestamps":this.setupTimestamp(e),this.options[t]=e,this._userProvidedOptions[t]=this.options[t];break;default:this.options[t]=e,this._userProvidedOptions[t]=this.options[t]}return this},y.prototype.get=function(t){return this.options[t]};var b="2d 2dsphere hashed text".split(" ");function w(t){return 0===t.indexOf("$[")&&t.lastIndexOf("]")===t.length-1}Object.defineProperty(y,"indexTypes",{get:function(){return b},set:function(){throw new Error("Cannot overwrite Schema.indexTypes")}}),y.prototype.indexes=function(){return f(this)},y.prototype.virtual=function(t,e){if(e&&e.ref){if(!e.localField)throw new Error("Reference virtuals require `localField` option");if(!e.foreignField)throw new Error("Reference virtuals require `foreignField` option");this.pre("init",function(r){if(h.has(t,r)){var n=h.get(t,r);this.$$populatedVirtuals||(this.$$populatedVirtuals={}),e.justOne?this.$$populatedVirtuals[t]=Array.isArray(n)?n[0]:n:this.$$populatedVirtuals[t]=Array.isArray(n)?n:null==n?[]:[n],h.unset(t,r)}});var r=this.virtual(t);return r.options=e,r.get(function(){return this.$$populatedVirtuals||(this.$$populatedVirtuals={}),t in this.$$populatedVirtuals?this.$$populatedVirtuals[t]:null}).set(function(r){this.$$populatedVirtuals||(this.$$populatedVirtuals={}),e.justOne?(this.$$populatedVirtuals[t]=Array.isArray(r)?r[0]:r,"object"!==i(this.$$populatedVirtuals[t])&&(this.$$populatedVirtuals[t]=null)):(this.$$populatedVirtuals[t]=Array.isArray(r)?r:null==r?[]:[r],this.$$populatedVirtuals[t]=this.$$populatedVirtuals[t].filter(function(t){return t&&"object"===i(t)}))})}var n=this.virtuals,o=t.split(".");if("real"===this.pathType(t))throw new Error('Virtual path "'+t+'" conflicts with a real path in the schema');return n[t]=o.reduce(function(r,n,i){return r[n]||(r[n]=i===o.length-1?new c(e,t):{}),r[n]},this.tree),n[t]},y.prototype.virtualpath=function(t){return this.virtuals[t]},y.prototype.remove=function(t){"string"===typeof t&&(t=[t]),Array.isArray(t)&&t.forEach(function(t){if(this.path(t)){delete this.paths[t];for(var e=t.split("."),r=e.pop(),n=this.tree,i=0;i<e.length;++i)n=n[e[i]];delete n[r]}},this)},y.prototype.loadClass=function(t,e){return t===Object.prototype||t===Function.prototype||t.prototype.hasOwnProperty("$isMongooseModelPrototype")?this:(this.loadClass(Object.getPrototypeOf(t)),e||Object.getOwnPropertyNames(t).forEach(function(e){if(!e.match(/^(length|name|prototype)$/)){var r=Object.getOwnPropertyDescriptor(t,e);"function"===typeof r.value&&this.static(e,r.value)}},this),Object.getOwnPropertyNames(t.prototype).forEach(function(r){if(!r.match(/^(constructor)$/)){var n=Object.getOwnPropertyDescriptor(t.prototype,r);e||"function"===typeof n.value&&this.method(r,n.value),"function"===typeof n.get&&this.virtual(r).get(n.get),"function"===typeof n.set&&this.virtual(r).set(n.set)}},this),this)},y.prototype._getSchema=function(t){var e=this.path(t),r=[];if(e)return e.$fullPath=t,e;for(var n=t.split("."),i=0;i<n.length;++i)("$"===n[i]||w(n[i]))&&(n[i]="0");return function t(e,n){for(var i,s,a=e.length+1;a--;)if(s=e.slice(0,a).join("."),i=n.path(s)){if(r.push(s),i.caster){if(i.caster instanceof o.Mixed)return i.caster.$fullPath=r.join("."),i.caster;var u;if(a!==e.length&&i.schema)return"$"===e[a]||w(e[a])?a+1===e.length?i:((u=t(e.slice(a+1),i.schema))&&(u.$isUnderneathDocArray=u.$isUnderneathDocArray||!i.schema.$isSingleNested),u):((u=t(e.slice(a),i.schema))&&(u.$isUnderneathDocArray=u.$isUnderneathDocArray||!i.schema.$isSingleNested),u)}return i.$fullPath=r.join("."),i}}(n,this)},y.prototype._getPathType=function(t){if(this.path(t))return"real";return function t(e,r){for(var n,i,s=e.length+1;s--;){if(i=e.slice(0,s).join("."),n=r.path(i))return n.caster?n.caster instanceof o.Mixed?{schema:n,pathType:"mixed"}:s!==e.length&&n.schema?"$"===e[s]||w(e[s])?s===e.length-1?{schema:n,pathType:"nested"}:t(e.slice(s+1),n.schema):t(e.slice(s),n.schema):{schema:n,pathType:n.$isSingleNested?"nested":"array"}:{schema:n,pathType:"real"};if(s===e.length&&r.nested[i])return{schema:r,pathType:"nested"}}return{schema:n||r,pathType:"undefined"}}(t.split("."),this)},t.exports=e=y,y.Types=o=r(65),e.ObjectId=o.ObjectId}).call(this,r(1).Buffer)},function(t,e,r){"use strict";function n(t,e){this.path=e,this.getters=[],this.setters=[],this.options=t||{}}n.prototype._applyDefaultGetters=function(){if(!(this.getters.length>0||this.setters.length>0)){var t="$"+this.path;this.getters.push(function(){return this[t]}),this.setters.push(function(e){this[t]=e})}},n.prototype.get=function(t){return this.getters.push(t),this},n.prototype.set=function(t){return this.setters.push(t),this},n.prototype.applyGetters=function(t,e){for(var r=t,n=this.getters.length-1;n>=0;n--)r=this.getters[n].call(e,r,this);return r},n.prototype.applySetters=function(t,e){for(var r=t,n=this.setters.length-1;n>=0;n--)r=this.setters[n].call(e,r,this);return r},t.exports=n},function(t,e,r){"use strict";(function(e){var n,i=r(2),o=r(5),s=r(117),a=r(68),u=r(0),c=o.CastError;function l(t,e){o.call(this,t,e,"Number")}function f(t){return this.cast(t)}l.schemaName="Number",l.prototype=Object.create(o.prototype),l.prototype.constructor=l,l.prototype.checkRequired=function(t,e){return o._isRef(this,t,e,!0)?!!t:"number"===typeof t||t instanceof Number},l.prototype.min=function(t,e){if(this.minValidator&&(this.validators=this.validators.filter(function(t){return t.validator!==this.minValidator},this)),null!==t&&void 0!==t){var r=e||i.messages.Number.min;r=r.replace(/{MIN}/,t),this.validators.push({validator:this.minValidator=function(e){return null==e||e>=t},message:r,type:"min",min:t})}return this},l.prototype.max=function(t,e){if(this.maxValidator&&(this.validators=this.validators.filter(function(t){return t.validator!==this.maxValidator},this)),null!==t&&void 0!==t){var r=e||i.messages.Number.max;r=r.replace(/{MAX}/,t),this.validators.push({validator:this.maxValidator=function(e){return null==e||e<=t},message:r,type:"max",max:t})}return this},l.prototype.cast=function(t,i,a){if(o._isRef(this,t,i,a)){if(null===t||void 0===t)return t;if(n||(n=r(4)),t instanceof n)return t.$__.wasPopulated=!0,t;if("number"===typeof t)return t;if(e.isBuffer(t)||!u.isObject(t))throw new c("number",t,this.path);var l=i.$__fullPath(this.path),f=new((i.ownerDocument?i.ownerDocument():i).populated(l,!0).options.model)(t);return f.$__.wasPopulated=!0,f}var h=t&&"undefined"!==typeof t._id?t._id:t;return s(h,this.path)},l.prototype.$conditionalHandlers=u.options(o.prototype.$conditionalHandlers,{$bitsAllClear:a,$bitsAnyClear:a,$bitsAllSet:a,$bitsAnySet:a,$gt:f,$gte:f,$lt:f,$lte:f,$mod:function(t){var e=this;return Array.isArray(t)?t.map(function(t){return e.cast(t)}):[this.cast(t)]}}),l.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t+" with Number.");return r.call(this,e)}return e=this._castForQuery(t)},t.exports=l}).call(this,r(1).Buffer)},function(t,e,r){"use strict";var n,i,o=r(39),s=r(62),a=r(38),u=r(5),c=u.CastError,l={Array:g,Boolean:r(69),Date:r(70),Number:r(45),String:r(66),ObjectId:r(37),Buffer:r(71)},f=r(42),h=r(119),p=r(8),d=r(3),y=r(0),_=r(22).castToNumber,m=r(73),v=r(21).getDiscriminatorByValue;function g(t,e,n,o){i||(i=r(16).Embedded);var s,a,c="type";if(o&&o.typeKey&&(c=o.typeKey),e){var h={};"Object"===y.getFunctionName(e.constructor)&&(e[c]?(delete(h=y.clone(e))[c],e=e[c]):e=f);var p="string"===typeof e?e:y.getFunctionName(e),d=p in l?l[p]:e;this.casterConstructor=d,"function"!==typeof d||d.$isArraySubdocument?this.caster=d:this.caster=new d(null,h),this.caster instanceof i||(this.caster.path=t)}if(this.$isMongooseArray=!0,u.call(this,t,n,"Array"),null!=this.defaultValue&&(s=this.defaultValue,a="function"===typeof s),!("defaultValue"in this)||void 0!==this.defaultValue){var _=function(){var t=[];return a?t=s():null!=s&&(t=t.concat(s)),t};_.$runBeforeSetters=!0,this.default(_)}}g.schemaName="Array",g.prototype=Object.create(u.prototype),g.prototype.constructor=g,g.prototype.enum=function(){var t=p(this,"caster.instance");if("String"!==t)throw new Error("`enum` can only be set on an array of strings, not "+t);return this.caster.enum.apply(this.caster,arguments),this},g.prototype.applyGetters=function(t,e){return this.caster.options&&this.caster.options.ref?t:u.prototype.applyGetters.call(this,t,e)},g.prototype.cast=function(t,e,i){if(n||(n=r(16).Array),Array.isArray(t)){if(!t.length&&e)for(var o=e.schema.indexedPaths(),s=0,a=o.length;s<a;++s){var u=o[s][0][this.path];if("2dsphere"===u||"2d"===u)return}if(t&&t.isMongooseArray?t&&t.isMongooseArray&&(t=new n(t,this.path,e)):t=new n(t,this.path,e),this.caster)try{for(s=0,a=t.length;s<a;s++)t[s]=this.caster.cast(t[s],e,i)}catch(e){throw new c("["+e.kind+"]",d.inspect(t),this.path,e)}return t}return e&&i&&e.markModified(this.path),this.cast([t],e,i)},g.prototype.discriminator=function(t,e){for(var r=this;r.$isMongooseArray&&!r.$isMongooseDocumentArray;)if(null==(r=r.casterConstructor)||"function"===typeof r)throw new a("You can only add an embedded discriminator on a document array, "+this.path+" is a plain array");return r.discriminator(t,e)},g.prototype.castForQuery=function(t,e){var r,n,i=this;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t+" with Array.");n=r.call(this,e)}else{n=t;var o=this.casterConstructor;if(n&&o.discriminators&&o.schema&&o.schema.options&&o.schema.options.discriminatorKey)if("string"===typeof n[o.schema.options.discriminatorKey]&&o.discriminators[n[o.schema.options.discriminatorKey]])o=o.discriminators[n[o.schema.options.discriminatorKey]];else{var s=v(o,n[o.schema.options.discriminatorKey]);s&&(o=s)}var a=this.casterConstructor.prototype,u=a&&(a.castForQuery||a.cast);!u&&o.castForQuery&&(u=o.castForQuery);var c=this.caster;Array.isArray(n)?(this.setters.reverse().forEach(function(t){n=t.call(i,n,i)}),n=n.map(function(t){return y.isObject(t)&&t.$elemMatch?t:u?t=u.call(c,t):null!=t?t=new o(t):t})):u?n=u.call(c,n):null!=n&&(n=new o(n))}return n};var b=g.prototype.$conditionalHandlers={};b.$all=function(t){return Array.isArray(t)||(t=[t]),t=t.map(function(t){if(y.isObject(t)){var e={};return e[this.path]=t,h(this.casterConstructor.schema,e)[this.path]}return t},this),this.castForQuery(t)},b.$options=String,b.$elemMatch=function(t){for(var e,r,n=Object.keys(t),i=n.length,o=0;o<i;++o)r=t[e=n[o]],0===e.indexOf("$")&&r&&(t[e]=this.castForQuery(e,r));return h(this.casterConstructor.schema,t)},b.$geoIntersects=m.cast$geoIntersects,b.$or=b.$and=function(t){if(!Array.isArray(t))throw new TypeError("conditional $or/$and require array");for(var e=[],r=0;r<t.length;++r)e.push(h(this.casterConstructor.schema,t[r]));return e},b.$near=b.$nearSphere=m.cast$near,b.$within=b.$geoWithin=m.cast$within,b.$size=b.$minDistance=b.$maxDistance=_,b.$exists=o,b.$type=s,b.$eq=b.$gt=b.$gte=b.$lt=b.$lte=b.$ne=b.$nin=b.$regex=g.prototype.castForQuery,b.$in=u.prototype.$conditionalHandlers.$in,t.exports=g},function(t,e,r){"use strict";var n,i=r(8),o=r(0);function s(t,e,i,s){n=n||r(4);for(var u,c,l=Object.keys(t),f=l.length,h=0;h<f;++h){u=t[c=l[h]],a(c,"Object"===o.getFunctionName(u.constructor)&&Object.keys(u).length&&(!u[s.typeKey]||"type"===s.typeKey&&u.type.type)?u:null,e,i,l,s)}}function a(t,e,a,u,c,l){n=n||r(4);var f=(u?u+".":"")+t;u=u||"",e?Object.defineProperty(a,t,{enumerable:!0,configurable:!0,get:function(){var t,r,c=this;if(this.$__.getters||(this.$__.getters={}),!this.$__.getters[f]){var h=Object.create(n.prototype,(t=this,r={},Object.getOwnPropertyNames(t).forEach(function(e){r[e]=Object.getOwnPropertyDescriptor(t,e),r[e].get?delete r[e]:r[e].enumerable=-1===["isNew","$__","errors","_doc"].indexOf(e)}),r));u||(h.$__.scope=this),h.$__.nestedPath=f,Object.defineProperty(h,"schema",{enumerable:!1,configurable:!0,writable:!1,value:a.schema}),Object.defineProperty(h,"toObject",{enumerable:!1,configurable:!0,writable:!1,value:function(){return o.clone(c.get(f,null,{virtuals:i(this,"schema.options.toObject.virtuals",null)}))}}),Object.defineProperty(h,"toJSON",{enumerable:!1,configurable:!0,writable:!1,value:function(){return c.get(f,null,{virtuals:i(c,"schema.options.toJSON.virtuals",null)})}}),Object.defineProperty(h,"$__isNested",{enumerable:!1,configurable:!0,writable:!1,value:!0}),s(e,h,f,l),this.$__.getters[f]=h}return this.$__.getters[f]},set:function(t){return t instanceof n&&(t=t.toObject({transform:!1})),(this.$__.scope||this).$set(f,t)}}):Object.defineProperty(a,t,{enumerable:!0,configurable:!0,get:function(){return this.get.call(this.$__.scope||this,f)},set:function(t){return this.$set.call(this.$__.scope||this,f,t)}})}e.compile=s,e.defineKey=a},function(t,e,r){"use strict";(function(e){if("undefined"!==typeof e.Map)t.exports=e.Map,t.exports.Map=e.Map;else{var r=function(t){this._keys=[],this._values={};for(var e=0;e<t.length;e++)if(null!=t[e]){var r=t[e],n=r[0],i=r[1];this._keys.push(n),this._values[n]={v:i,i:this._keys.length-1}}};r.prototype.clear=function(){this._keys=[],this._values={}},r.prototype.delete=function(t){var e=this._values[t];return null!=e&&(delete this._values[t],this._keys.splice(e.i,1),!0)},r.prototype.entries=function(){var t=this,e=0;return{next:function(){var r=t._keys[e++];return{value:void 0!==r?[r,t._values[r].v]:void 0,done:void 0===r}}}},r.prototype.forEach=function(t,e){e=e||this;for(var r=0;r<this._keys.length;r++){var n=this._keys[r];t.call(e,this._values[n].v,n,e)}},r.prototype.get=function(t){return this._values[t]?this._values[t].v:void 0},r.prototype.has=function(t){return null!=this._values[t]},r.prototype.keys=function(){var t=this,e=0;return{next:function(){var r=t._keys[e++];return{value:void 0!==r?r:void 0,done:void 0===r}}}},r.prototype.set=function(t,e){return this._values[t]?(this._values[t].v=e,this):(this._keys.push(t),this._values[t]={v:e,i:this._keys.length-1},this)},r.prototype.values=function(){var t=this,e=0;return{next:function(){var r=t._keys[e++];return{value:void 0!==r?t._values[r].v:void 0,done:void 0===r}}}},Object.defineProperty(r.prototype,"size",{enumerable:!0,get:function(){return this._keys.length}}),t.exports=r,t.exports.Map=r}}).call(this,r(6))},function(t,e,r){"use strict";var n=function t(e){if(!(this instanceof t))return new t(e);this._bsontype="Int32",this.value=e};n.prototype.valueOf=function(){return this.value},n.prototype.toJSON=function(){return this.value},t.exports=n,t.exports.Int32=n},function(t,e,r){"use strict";t.exports={normalizedFunctionString:function(t){return t.toString().replace(/function *\(/,"function (")}}},function(t,e,r){"use strict";var n=r(4),i=r(129),o=!1;t.exports=function(){return o?i:n},t.exports.setBrowser=function(t){o=t}},function(t,e,r){"use strict";(function(e){var n=r(53),i=r(94),o={_promise:null,get:function(){return o._promise},set:function(t){n.ok("function"===typeof t,"mongoose.Promise must be a function, got ".concat(t)),o._promise=t,i.Promise=t}};o.set(e.Promise),t.exports=o}).call(this,r(6))},function(t,e,r){"use strict";(function(e){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)}function i(t,e){if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0}function o(t){return e.Buffer&&"function"===typeof e.Buffer.isBuffer?e.Buffer.isBuffer(t):!(null==t||!t._isBuffer)}var s=r(3),a=Object.prototype.hasOwnProperty,u=Array.prototype.slice,c="foo"===function(){}.name;function l(t){return Object.prototype.toString.call(t)}function f(t){return!o(t)&&("function"===typeof e.ArrayBuffer&&("function"===typeof ArrayBuffer.isView?ArrayBuffer.isView(t):!!t&&(t instanceof DataView||!!(t.buffer&&t.buffer instanceof ArrayBuffer))))}var h=t.exports=v,p=/\s*function\s+([^\(\s]*)\s*/;function d(t){if(s.isFunction(t)){if(c)return t.name;var e=t.toString().match(p);return e&&e[1]}}function y(t,e){return"string"===typeof t?t.length<e?t:t.slice(0,e):t}function _(t){if(c||!s.isFunction(t))return s.inspect(t);var e=d(t);return"[Function"+(e?": "+e:"")+"]"}function m(t,e,r,n,i){throw new h.AssertionError({message:r,actual:t,expected:e,operator:n,stackStartFunction:i})}function v(t,e){t||m(t,!0,e,"==",h.ok)}function g(t,e,r,a){if(t===e)return!0;if(o(t)&&o(e))return 0===i(t,e);if(s.isDate(t)&&s.isDate(e))return t.getTime()===e.getTime();if(s.isRegExp(t)&&s.isRegExp(e))return t.source===e.source&&t.global===e.global&&t.multiline===e.multiline&&t.lastIndex===e.lastIndex&&t.ignoreCase===e.ignoreCase;if(null!==t&&"object"===n(t)||null!==e&&"object"===n(e)){if(f(t)&&f(e)&&l(t)===l(e)&&!(t instanceof Float32Array||t instanceof Float64Array))return 0===i(new Uint8Array(t.buffer),new Uint8Array(e.buffer));if(o(t)!==o(e))return!1;var c=(a=a||{actual:[],expected:[]}).actual.indexOf(t);return-1!==c&&c===a.expected.indexOf(e)||(a.actual.push(t),a.expected.push(e),function(t,e,r,n){if(null===t||void 0===t||null===e||void 0===e)return!1;if(s.isPrimitive(t)||s.isPrimitive(e))return t===e;if(r&&Object.getPrototypeOf(t)!==Object.getPrototypeOf(e))return!1;var i=b(t),o=b(e);if(i&&!o||!i&&o)return!1;if(i)return t=u.call(t),e=u.call(e),g(t,e,r);var a,c,l=S(t),f=S(e);if(l.length!==f.length)return!1;for(l.sort(),f.sort(),c=l.length-1;c>=0;c--)if(l[c]!==f[c])return!1;for(c=l.length-1;c>=0;c--)if(a=l[c],!g(t[a],e[a],r,n))return!1;return!0}(t,e,r,a))}return r?t===e:t==e}function b(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function w(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(t){}return!Error.isPrototypeOf(e)&&!0===e.call({},t)}function O(t,e,r,n){var i;if("function"!==typeof e)throw new TypeError('"block" argument must be a function');"string"===typeof r&&(n=r,r=null),i=function(t){var e;try{t()}catch(t){e=t}return e}(e),n=(r&&r.name?" ("+r.name+").":".")+(n?" "+n:"."),t&&!i&&m(i,r,"Missing expected exception"+n);var o="string"===typeof n,a=!t&&s.isError(i),u=!t&&i&&!r;if((a&&o&&w(i,r)||u)&&m(i,r,"Got unwanted exception"+n),t&&i&&r&&!w(i,r)||!t&&i)throw i}h.AssertionError=function(t){var e;this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=y(_((e=this).actual),128)+" "+e.operator+" "+y(_(e.expected),128),this.generatedMessage=!0);var r=t.stackStartFunction||m;if(Error.captureStackTrace)Error.captureStackTrace(this,r);else{var n=new Error;if(n.stack){var i=n.stack,o=d(r),s=i.indexOf("\n"+o);if(s>=0){var a=i.indexOf("\n",s+1);i=i.substring(a+1)}this.stack=i}}},s.inherits(h.AssertionError,Error),h.fail=m,h.ok=v,h.equal=function(t,e,r){t!=e&&m(t,e,r,"==",h.equal)},h.notEqual=function(t,e,r){t==e&&m(t,e,r,"!=",h.notEqual)},h.deepEqual=function(t,e,r){g(t,e,!1)||m(t,e,r,"deepEqual",h.deepEqual)},h.deepStrictEqual=function(t,e,r){g(t,e,!0)||m(t,e,r,"deepStrictEqual",h.deepStrictEqual)},h.notDeepEqual=function(t,e,r){g(t,e,!1)&&m(t,e,r,"notDeepEqual",h.notDeepEqual)},h.notDeepStrictEqual=function t(e,r,n){g(e,r,!0)&&m(e,r,n,"notDeepStrictEqual",t)},h.strictEqual=function(t,e,r){t!==e&&m(t,e,r,"===",h.strictEqual)},h.notStrictEqual=function(t,e,r){t===e&&m(t,e,r,"!==",h.notStrictEqual)},h.throws=function(t,e,r){O(!0,t,e,r)},h.doesNotThrow=function(t,e,r){O(!1,t,e,r)},h.ifError=function(t){if(t)throw t};var S=Object.keys||function(t){var e=[];for(var r in t)a.call(t,r)&&e.push(r);return e}}).call(this,r(6))},function(t,e,r){"use strict";t.exports=function(t,e,r){var n=[],i=t.length;if(0===i)return n;var o=e<0?Math.max(0,e+i):e||0;for(void 0!==r&&(i=r<0?r+i:r);i-- >o;)n[i-o]=t[i];return n}},function(t,e,r){"use strict";(function(t,n,i){function o(t){return(o="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var s=r(57),a=e.clone=function t(r,n){if(void 0===r||null===r)return r;if(Array.isArray(r))return e.cloneArray(r,n);if(r.constructor){if(/ObjectI[dD]$/.test(r.constructor.name))return"function"==typeof r.clone?r.clone():new r.constructor(r.id);if("ReadPreference"===r._type&&r.isValid&&r.toObject)return"function"==typeof r.clone?r.clone():new r.constructor(r.mode,t(r.tags,n));if("Binary"==r._bsontype&&r.buffer&&r.value)return"function"==typeof r.clone?r.clone():new r.constructor(r.value(!0),r.sub_type);if("Date"===r.constructor.name||"Function"===r.constructor.name)return new r.constructor(+r);if("RegExp"===r.constructor.name)return s(r);if("Buffer"===r.constructor.name)return e.cloneBuffer(r)}return c(r)?e.cloneObject(r,n):r.valueOf?r.valueOf():void 0};e.cloneObject=function(t,e){var r,n,i,o=e&&e.minimize,s={};for(i in t)n=a(t[i],e),o&&"undefined"===typeof n||(r||(r=!0),s[i]=n);return o?r&&s:s},e.cloneArray=function(t,e){for(var r=[],n=0,i=t.length;n<i;n++)r.push(a(t[n],e));return r},e.tick=function(t){if("function"===typeof t)return function(){var e=arguments;l(function(){t.apply(this,e)})}},e.merge=function t(r,n){for(var i,o=Object.keys(n),s=o.length;s--;)"undefined"===typeof r[i=o[s]]?r[i]=n[i]:e.isObject(n[i])?t(r[i],n[i]):r[i]=n[i]},e.mergeClone=function t(r,n){for(var i,o=Object.keys(n),s=o.length;s--;)"undefined"===typeof r[i=o[s]]?r[i]=a(n[i]):e.isObject(n[i])?t(r[i],n[i]):r[i]=a(n[i])},e.readPref=function(t){switch(t){case"p":t="primary";break;case"pp":t="primaryPreferred";break;case"s":t="secondary";break;case"sp":t="secondaryPreferred";break;case"n":t="nearest"}return t},e.readConcern=function(t){if("string"===typeof t){switch(t){case"l":t="local";break;case"a":t="available";break;case"m":t="majority";break;case"lz":t="linearizable";break;case"s":t="snapshot"}t={level:t}}return t};var u=Object.prototype.toString;e.toString=function(t){return u.call(t)};var c=e.isObject=function(t){return"[object Object]"==e.toString(t)};e.isArray=function(t){return Array.isArray(t)||"object"==o(t)&&"[object Array]"==e.toString(t)},e.keys=Object.keys||function(t){var e=[];for(var r in t)t.hasOwnProperty(r)&&e.push(r);return e},e.create="function"==typeof Object.create?Object.create:function(t){if(arguments.length>1)throw new Error("Adding properties is not supported");function e(){}return e.prototype=t,new e},e.inherits=function(t,r){t.prototype=e.create(r.prototype),t.prototype.constructor=t};var l=e.soon="function"==typeof t?t:n.nextTick;e.cloneBuffer=function(t){var e=i.alloc(t.length);return t.copy(e,0,0,t.length),e},e.isArgumentsObject=function(t){return"[object Arguments]"===Object.prototype.toString.call(t)}}).call(this,r(56).setImmediate,r(7),r(1).Buffer)},function(t,e,r){"use strict";(function(t){var n="undefined"!==typeof t&&t||"undefined"!==typeof self&&self||window,i=Function.prototype.apply;function o(t,e){this._id=t,this._clearFn=e}e.setTimeout=function(){return new o(i.call(setTimeout,n,arguments),clearTimeout)},e.setInterval=function(){return new o(i.call(setInterval,n,arguments),clearInterval)},e.clearTimeout=e.clearInterval=function(t){t&&t.close()},o.prototype.unref=o.prototype.ref=function(){},o.prototype.close=function(){this._clearFn.call(n,this._id)},e.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},e.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},e._unrefActive=e.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;e>=0&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},r(95),e.setImmediate="undefined"!==typeof self&&self.setImmediate||"undefined"!==typeof t&&t.setImmediate||void 0,e.clearImmediate="undefined"!==typeof self&&self.clearImmediate||"undefined"!==typeof t&&t.clearImmediate||void 0}).call(this,r(6))},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=Object.prototype.toString;t.exports=function(t){if("object"!=n(e=t)||"[object RegExp]"!=i.call(e))throw new TypeError("Not a RegExp");var e,r=[];return t.global&&r.push("g"),t.multiline&&r.push("m"),t.ignoreCase&&r.push("i"),new RegExp(t.source,r.join(""))}},function(t,e,r){"use strict";(function(t,r,n,i){function o(t){return(o="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}e.isNode="undefined"!=typeof t&&"object"==o(r)&&"object"==("undefined"===typeof n?"undefined":o(n))&&"function"==typeof i&&t.argv,e.isMongo=!e.isNode&&"function"==typeof printjson&&"function"==typeof ObjectId&&"function"==typeof rs&&"function"==typeof sh,e.isBrowser=!e.isNode&&!e.isMongo&&"undefined"!=typeof window,e.type=e.isNode?"node":e.isMongo?"mongo":e.isBrowser?"browser":"unknown"}).call(this,r(7),r(100)(t),r(6),r(1).Buffer)},function(t,e,r){"use strict";var n=r(1),i=n.Buffer;function o(t,e){for(var r in t)e[r]=t[r]}function s(t,e,r){return i(t,e,r)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?t.exports=n:(o(n,e),e.Buffer=s),o(i,s),s.from=function(t,e,r){if("number"===typeof t)throw new TypeError("Argument must not be a number");return i(t,e,r)},s.alloc=function(t,e,r){if("number"!==typeof t)throw new TypeError("Argument must be a number");var n=i(t);return void 0!==e?"string"===typeof r?n.fill(e,r):n.fill(e):n.fill(0),n},s.allocUnsafe=function(t){if("number"!==typeof t)throw new TypeError("Argument must be a number");return i(t)},s.allocUnsafeSlow=function(t){if("number"!==typeof t)throw new TypeError("Argument must be a number");return n.SlowBuffer(t)}},function(t,e,r){"use strict";t.exports=function(t,e,r){for(var n=(r=r||{}).skipDocArrays,i=0,o=Object.keys(t.$__.activePaths.states.modify),s=0;s<o.length;s++){var a=o[s];if(n){var u=t.schema.path(a);if(u&&u.$isMongooseDocumentArray)continue}0===a.indexOf(e+".")&&(delete t.$__.activePaths.states.modify[a],++i)}return i}},function(t,e,r){"use strict";var n=r(14).get().Binary,i=r(0),o=r(59).Buffer;function s(t,e,r){var n,a,u,c,l;return n=0===arguments.length||null===arguments[0]||void 0===arguments[0]?0:t,Array.isArray(e)?(u=e[0],c=e[1]):a=e,l="number"===typeof n||n instanceof Number?o.alloc(n):o.from(n,a,r),i.decorate(l,s.mixin),l.isMongooseBuffer=!0,Object.defineProperties(l,{validators:{value:[],enumerable:!1},_path:{value:u,enumerable:!1},_parent:{value:c,enumerable:!1}}),c&&"string"===typeof u&&Object.defineProperty(l,"_schema",{value:c.schema.path(u)}),l._subtype=0,l}s.mixin={_parent:void 0,_subtype:void 0,_markModified:function(){var t=this._parent;return t&&t.markModified(this._path),this},write:function(){var t=o.prototype.write.apply(this,arguments);return t>0&&this._markModified(),t},copy:function(t){var e=o.prototype.copy.apply(this,arguments);return t&&t.isMongooseBuffer&&t._markModified(),e}},"writeUInt8 writeUInt16 writeUInt32 writeInt8 writeInt16 writeInt32 writeFloat writeDouble fill utf8Write binaryWrite asciiWrite set writeUInt16LE writeUInt16BE writeUInt32LE writeUInt32BE writeInt16LE writeInt16BE writeInt32LE writeInt32BE writeFloatLE writeFloatBE writeDoubleLE writeDoubleBE".split(" ").forEach(function(t){o.prototype[t]&&(s.mixin[t]=function(){var e=o.prototype[t].apply(this,arguments);return this._markModified(),e})}),s.mixin.toObject=function(t){var e="number"===typeof t?t:this._subtype||0;return new n(this,e)},s.mixin.toBSON=function(){return new n(this,this._subtype||0)},s.mixin.equals=function(t){if(!o.isBuffer(t))return!1;if(this.length!==t.length)return!1;for(var e=0;e<this.length;++e)if(this[e]!==t[e])return!1;return!0},s.mixin.subtype=function(t){if("number"!==typeof t)throw new TypeError("Invalid subtype. Expected a number");this._subtype!==t&&this._markModified(),this._subtype=t},s.Binary=n,t.exports=s},function(t,e,r){"use strict";t.exports=function(t){if("number"!==typeof t&&"string"!==typeof t)throw new Error("$type parameter must be number or string");return t}},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)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function o(t,e){return!e||"object"!==n(e)&&"function"!==typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function s(t,e,r){return(s="undefined"!==typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=l(t)););return t}(t,e);if(n){var i=Object.getOwnPropertyDescriptor(n,e);return i.get?i.get.call(r):i.value}})(t,e,r||t)}function a(t){var e="function"===typeof Map?new Map:void 0;return(a=function(t){if(null===t)return null;if("function"!==typeof t)throw new TypeError("Super expression must either be null or a function");if("undefined"!==typeof e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return u(t,arguments,l(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,t)})(t)}function u(t,e,r){return(u=function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&c(i,r.prototype),i}).apply(null,arguments)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var f=r(3),h=function(t){function e(t,r,n,i){var s;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),null!=t&&"Object"===t.constructor.name&&(t=Object.keys(t).reduce(function(e,r){return e.concat([[r,t[r]]])},[])),(s=o(this,l(e).call(this,t))).$__parent=n,s.$__path=r,s.$__schemaType=i,s.$__runDeferred(),s}var r,n,u;return function(t,e){if("function"!==typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}(e,a(Map)),r=e,(n=[{key:"$init",value:function(t,r){if(t.startsWith("$"))throw new Error('Mongoose maps do not support keys that start with `$`, got "'+t+'"');if(-1!==t.indexOf("."))throw new Error('Mongoose maps do not support keys that contain `.`, got "'+t+'"');s(l(e.prototype),"set",this).call(this,t,r),null!=r&&r.$isSingleNested&&(r.$basePath=this.$__path+"."+t)}},{key:"set",value:function(t,r){if(t.startsWith("$"))throw new Error('Mongoose maps do not support keys that start with `$`, got "'+t+'"');if(-1!==t.indexOf("."))throw new Error('Mongoose maps do not support keys that contain `.`, got "'+t+'"');if(null==this.$__schemaType)return this.$__deferred=this.$__deferred||[],void this.$__deferred.push({key:t,value:r});var n=this.$__path+"."+t,i=null!=this.$__parent&&this.$__parent.$__?this.$__parent.populated(n)||this.$__parent.populated(this.$__path):null;if(null!=i)null==r.$__&&(r=new i.options.model(r)),r.$__.wasPopulated=!0;else try{r=this.$__schemaType.applySetters(r,this.$__parent,!1,this.get(t))}catch(t){return void this.$__parent.invalidate(n,t)}s(l(e.prototype),"set",this).call(this,t,r),null!=r&&r.$isSingleNested&&(r.$basePath=this.$__path+"."+t),null!=this.$__parent&&this.$__parent.$__&&this.$__parent.markModified(this.$__path+"."+t)}},{key:"toBSON",value:function(){return new Map(this)}},{key:"toObject",value:function(){return new Map(this)}},{key:"toJSON",value:function(){var t={},e=this.keys(),r=!0,n=!1,i=void 0;try{for(var o,s=e[Symbol.iterator]();!(r=(o=s.next()).done);r=!0){var a=o.value;t[a]=this.get(a)}}catch(t){n=!0,i=t}finally{try{r||null==s.return||s.return()}finally{if(n)throw i}}return t}},{key:"inspect",value:function(){return new Map(this)}},{key:"$__runDeferred",value:function(){if(this.$__deferred){for(var t=0;t<this.$__deferred.length;++t)this.set(this.$__deferred[t].key,this.$__deferred[t].value);this.$__deferred=null}}}])&&i(r.prototype,n),u&&i(r,u),e}();f.inspect.custom&&Object.defineProperty(h.prototype,f.inspect.custom,{enumerable:!1,writable:!1,configurable:!1,value:h.prototype.inspect}),Object.defineProperty(h.prototype,"$__parent",{enumerable:!1,writable:!0,configurable:!1}),Object.defineProperty(h.prototype,"$__path",{enumerable:!1,writable:!0,configurable:!1}),Object.defineProperty(h.prototype,"$__schemaType",{enumerable:!1,writable:!0,configurable:!1}),Object.defineProperty(h.prototype,"$isMongooseMap",{enumerable:!1,writable:!1,configurable:!1,value:!0}),Object.defineProperty(h.prototype,"$__deferredCalls",{enumerable:!1,writable:!1,configurable:!1,value:!0}),t.exports=h},function(t,e,r){"use strict";var n=r(4),i=r(36),o=r(12).internalToObjectOptions,s=r(0);function a(t,e,r,i,o){this.$isSingleNested=!0,n.call(this,t,e,i,o)}t.exports=a,a.prototype=Object.create(n.prototype),a.prototype.toBSON=function(){return this.toObject(o)},a.prototype.save=function(t,e){var r=this;return"function"===typeof t&&(e=t,t={}),(t=t||{}).suppressWarning||console.warn("mongoose: calling `save()` on a subdoc does **not** save the document to MongoDB, it only runs save middleware. Use `subdoc.save({ suppressWarning: true })` to hide this warning if you're sure this behavior is right for your app."),s.promiseOrCallback(e,function(t){r.$__save(t)})},a.prototype.$__save=function(t){var e=this;return i(function(){return t(null,e)})},a.prototype.$isValid=function(t){return this.$parent&&this.$basePath?this.$parent.$isValid([this.$basePath,t].join(".")):n.prototype.$isValid.call(this,t)},a.prototype.markModified=function(t){if(n.prototype.markModified.call(this,t),this.$parent&&this.$basePath){if(this.$parent.isDirectModified(this.$basePath))return;this.$parent.markModified([this.$basePath,t].join("."),this)}},a.prototype.$markValid=function(t){n.prototype.$markValid.call(this,t),this.$parent&&this.$basePath&&this.$parent.$markValid([this.$basePath,t].join("."))},a.prototype.invalidate=function(t,e,r){if(e!==this.ownerDocument().$__.validationError&&n.prototype.invalidate.call(this,t,e,r),this.$parent&&this.$basePath)this.$parent.invalidate([this.$basePath,t].join("."),e,r);else if("cast"===e.kind||"CastError"===e.name)throw e},a.prototype.$ignore=function(t){n.prototype.$ignore.call(this,t),this.$parent&&this.$basePath&&this.$parent.$ignore([this.$basePath,t].join("."))},a.prototype.ownerDocument=function(){if(this.$__.ownerDocument)return this.$__.ownerDocument;var t=this.$parent;if(!t)return this;for(;t.$parent||t.__parent;)t=t.$parent||t.__parent;return this.$__.ownerDocument=t,this.$__.ownerDocument},a.prototype.parent=function(){return this.$parent},a.prototype.$__remove=function(t){return t(null,this)},a.prototype.remove=function(t,e){"function"===typeof t&&(e=t,t=null),function(t){var e=t.ownerDocument();function r(){e.removeListener("save",r),e.removeListener("remove",r),t.emit("remove",t),t.constructor.emit("remove",t),e=t=null}e.on("save",r),e.on("remove",r)}(this),t&&t.noop||this.$parent.set(this.$basePath,null),"function"===typeof e&&e(null)},a.prototype.populate=function(){throw new Error('Mongoose does not support calling populate() on nested docs. Instead of `doc.nested.populate("path")`, use `doc.populate("nested.path")`')}},function(t,e,r){"use strict";e.String=r(66),e.Number=r(45),e.Boolean=r(69),e.DocumentArray=r(118),e.Embedded=r(121),e.Array=r(46),e.Buffer=r(71),e.Date=r(70),e.ObjectId=r(37),e.Mixed=r(42),e.Decimal128=e.Decimal=r(122),e.Map=r(123),e.Oid=e.ObjectId,e.Object=e.Mixed,e.Bool=e.Boolean},function(t,e,r){"use strict";(function(e){var n,i=r(5),o=i.CastError,s=r(2),a=r(67),u=r(0);function c(t,e){this.enumValues=[],this.regExp=null,i.call(this,t,e,"String")}function l(t){return this.castForQuery(t)}c.schemaName="String",c.prototype=Object.create(i.prototype),c.prototype.constructor=c,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;u.isObject(arguments[0])?(t=arguments[0].values,e=arguments[0].message):(t=arguments,e=s.messages.String.enum);for(var r=0;r<t.length;r++)void 0!==t[r]&&this.enumValues.push(this.cast(t[r]));var n=this.enumValues;return this.enumValidator=function(t){return void 0===t||~n.indexOf(t)},this.validators.push({validator:this.enumValidator,message:e,type:"enum",enumValues:n}),this},c.prototype.lowercase=function(t){return arguments.length>0&&!t?this:this.set(function(t,e){return"string"!==typeof t&&(t=e.cast(t)),t?t.toLowerCase():t})},c.prototype.uppercase=function(t){return arguments.length>0&&!t?this:this.set(function(t,e){return"string"!==typeof t&&(t=e.cast(t)),t?t.toUpperCase():t})},c.prototype.trim=function(t){return arguments.length>0&&!t?this:this.set(function(t,e){return"string"!==typeof t&&(t=e.cast(t)),t?t.trim():t})},c.prototype.minlength=function(t,e){if(this.minlengthValidator&&(this.validators=this.validators.filter(function(t){return t.validator!==this.minlengthValidator},this)),null!==t&&void 0!==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.maxlength=function(t,e){if(this.maxlengthValidator&&(this.validators=this.validators.filter(function(t){return t.validator!==this.maxlengthValidator},this)),null!==t&&void 0!==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.match=function(t,e){var r=e||s.messages.String.match;return this.validators.push({validator:function(e){return!!t&&(null==e||""===e||t.test(e))},message:r,type:"regexp",regexp:t}),this},c.prototype.checkRequired=function(t,e){return i._isRef(this,t,e,!0)?!!t:(t instanceof String||"string"===typeof t)&&t.length},c.prototype.cast=function(t,s,c){if(i._isRef(this,t,s,c)){if(null===t||void 0===t)return t;if(n||(n=r(4)),t instanceof n)return t.$__.wasPopulated=!0,t;if("string"===typeof t)return t;if(e.isBuffer(t)||!u.isObject(t))throw new o("string",t,this.path);var l=s.$__fullPath(this.path),f=new((s.ownerDocument?s.ownerDocument():s).populated(l,!0).options.model)(t);return f.$__.wasPopulated=!0,f}return a(t,this.path)},c.prototype.$conditionalHandlers=u.options(i.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:l,$regex:l,$not:l}),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)},t.exports=c}).call(this,r(1).Buffer)},function(t,e,r){"use strict";var n=r(9);t.exports=function(t,e){if(null==t)return t;if(t._id&&"string"===typeof t._id)return t._id;if(t.toString&&t.toString!==Object.prototype.toString)return t.toString();throw new n("string",t,e)}},function(t,e,r){"use strict";(function(e){var n=r(9);function i(t,e){var r=Number(e);if(isNaN(r))throw new n("number",e,t);return r}t.exports=function(t){var r=this;return Array.isArray(t)?t.map(function(t){return i(r.path,t)}):e.isBuffer(t)?t:i(r.path,t)}}).call(this,r(1).Buffer)},function(t,e,r){"use strict";var n=r(5),i=r(40),o=r(0);function s(t,e){n.call(this,t,e,"Boolean")}s.schemaName="Boolean",s.prototype=Object.create(n.prototype),s.prototype.constructor=s,s.prototype.checkRequired=function(t){return!0===t||!1===t},Object.defineProperty(s,"convertToTrue",{get:function(){return i.convertToTrue},set:function(t){i.convertToTrue=t}}),Object.defineProperty(s,"convertToFalse",{get:function(){return i.convertToFalse},set:function(t){i.convertToFalse=t}}),s.prototype.cast=function(t){return i(t,this.path)},s.$conditionalHandlers=o.options(n.prototype.$conditionalHandlers,{}),s.prototype.castForQuery=function(t,e){var r;return 2===arguments.length?(r=s.$conditionalHandlers[t])?r.call(this,e):this._castForQuery(e):this._castForQuery(t)},t.exports=s},function(t,e,r){"use strict";var n=r(2),i=r(0),o=r(5),s=o.CastError;function a(t,e){o.call(this,t,e,"Date")}function u(t){return this.cast(t)}a.schemaName="Date",a.prototype=Object.create(o.prototype),a.prototype.constructor=a,a.prototype.expires=function(t){return this._index&&"Object"===this._index.constructor.name||(this._index={}),this._index.expires=t,i.expires(this._index),this},a.prototype.checkRequired=function(t){return t instanceof Date},a.prototype.min=function(t,e){if(this.minValidator&&(this.validators=this.validators.filter(function(t){return t.validator!==this.minValidator},this)),t){var r=e||n.messages.Date.min;r=r.replace(/{MIN}/,t===Date.now?"Date.now()":this.cast(t).toString());var i=this;this.validators.push({validator:this.minValidator=function(e){var r=t===Date.now?t():i.cast(t);return null===e||e.valueOf()>=r.valueOf()},message:r,type:"min",min:t})}return this},a.prototype.max=function(t,e){if(this.maxValidator&&(this.validators=this.validators.filter(function(t){return t.validator!==this.maxValidator},this)),t){var r=e||n.messages.Date.max;r=r.replace(/{MAX}/,t===Date.now?"Date.now()":this.cast(t).toString());var i=this;this.validators.push({validator:this.maxValidator=function(e){var r=t===Date.now?t():i.cast(t);return null===e||e.valueOf()<=r.valueOf()},message:r,type:"max",max:t})}return this},a.prototype.cast=function(t){if(null===t||void 0===t||""===t)return null;if(t instanceof Date){if(isNaN(t.valueOf()))throw new s("date",t,this.path);return t}var e;if("boolean"===typeof t)throw new s("date",t,this.path);if(e=t instanceof Number||"number"===typeof t?new Date(t):"string"===typeof t&&!isNaN(Number(t))&&(Number(t)>=275761||Number(t)<-271820)?new Date(Number(t)):"function"===typeof t.valueOf?new Date(t.valueOf()):new Date(t),!isNaN(e.valueOf()))return e;throw new s("date",t,this.path)},a.prototype.$conditionalHandlers=i.options(o.prototype.$conditionalHandlers,{$gt:u,$gte:u,$lt:u,$lte:u}),a.prototype.castForQuery=function(t,e){var r;if(2!==arguments.length)return this._castForQuery(t);if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t+" with Date.");return r.call(this,e)},t.exports=a},function(t,e,r){"use strict";(function(e){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=r(68),s=r(0),a=r(61),u=r(5),c=a.Binary,l=u.CastError;function f(t,e){u.call(this,t,e,"Buffer")}function h(t){return this.castForQuery(t)}f.schemaName="Buffer",f.prototype=Object.create(u.prototype),f.prototype.constructor=f,f.prototype.checkRequired=function(t,e){return u._isRef(this,t,e,!0)?!!t:!(!t||!t.length)},f.prototype.cast=function(t,o,f){var h;if(u._isRef(this,t,o,f)){if(null===t||void 0===t)return t;if(i||(i=r(4)),t instanceof i)return t.$__.wasPopulated=!0,t;if(e.isBuffer(t))return t;if(!s.isObject(t))throw new l("buffer",t,this.path);var p=o.$__fullPath(this.path);return(h=new((o.ownerDocument?o.ownerDocument():o).populated(p,!0).options.model)(t)).$__.wasPopulated=!0,h}if(t&&t._id&&(t=t._id),t&&t.isMongooseBuffer)return t;if(e.isBuffer(t))return t&&t.isMongooseBuffer||(t=new a(t,[this.path,o]),null!=this.options.subtype&&(t._subtype=this.options.subtype)),t;if(t instanceof c){if(h=new a(t.value(!0),[this.path,o]),"number"!==typeof t.sub_type)throw new l("buffer",t,this.path);return h._subtype=t.sub_type,h}if(null===t)return t;var d=n(t);if("string"===d||"number"===d||Array.isArray(t))return"number"===d&&(t=[t]),h=new a(t,[this.path,o]),null!=this.options.subtype&&(h._subtype=this.options.subtype),h;throw new l("buffer",t,this.path)},f.prototype.subtype=function(t){return this.options.subtype=t,this},f.prototype.$conditionalHandlers=s.options(u.prototype.$conditionalHandlers,{$bitsAllClear:o,$bitsAnyClear:o,$bitsAllSet:o,$bitsAnySet:o,$gt:h,$gte:h,$lt:h,$lte:h}),f.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t+" with Buffer.");return r.call(this,e)}e=t;var n=this._castForQuery(e);return n?n.toObject({transform:!1,virtuals:!1}):n},t.exports=f}).call(this,r(1).Buffer)},function(t,e,r){"use strict";var n=r(2);function i(t,e){e=e||"Field `"+t+"` is not in schema and strict mode is set to throw.",n.call(this,e),this.name="StrictModeError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack,this.path=t}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,t.exports=i},function(t,e,r){"use strict";var n=r(22).castArraysOfNumbers,i=r(22).castToNumber;function o(t,e){switch(t.$geometry.type){case"Polygon":case"LineString":case"Point":n(t.$geometry.coordinates,e)}return s(this,t),t}function s(t,e){e.$maxDistance&&(e.$maxDistance=i.call(t,e.$maxDistance)),e.$minDistance&&(e.$minDistance=i.call(t,e.$minDistance))}e.cast$geoIntersects=function(t){if(!t.$geometry)return;return o(t,this),t},e.cast$near=function(t){var e=r(46);if(Array.isArray(t))return n(t,this),t;if(s(this,t),t&&t.$geometry)return o(t,this);return e.prototype.castForQuery.call(this,t)},e.cast$within=function(t){if(s(this,t),t.$box||t.$polygon){var e=t.$box?"$box":"$polygon";t[e].forEach(function(t){if(!Array.isArray(t)){var e="Invalid $within $box argument. Expected an array, received "+t;throw new TypeError(e)}t.forEach(function(e,r){t[r]=i.call(this,e)})})}else t.$center||t.$centerSphere?(e=t.$center?"$center":"$centerSphere",t[e].forEach(function(r,n){Array.isArray(r)?r.forEach(function(t,e){r[e]=i.call(this,t)}):t[e][n]=i.call(this,r)})):t.$geometry&&o(t,this);return t}},function(t,e,r){"use strict";var n=r(47).defineKey,i=r(0),o={toJSON:!0,toObject:!0,_id:!0,id:!0};t.exports=function(t,e,r,s){if(!r||!r.instanceOfSchema)throw new Error("You must pass a valid discriminator Schema");if(t.base&&t.base.options.applyPluginsToDiscriminators&&t.base._applyPlugins(r),t.schema.discriminatorMapping&&!t.schema.discriminatorMapping.isRoot)throw new Error('Discriminator "'+e+'" can only be a discriminator of the root model');var a=t.schema.options.discriminatorKey,u={};if(u[a]={default:void 0,select:!0,$skipDiscriminatorCheck:!0},u[a][t.schema.options.typeKey]=String,t.schema.add(u),n(a,null,t.prototype,null,[a],t.schema.options),r.path(a)&&!0!==r.path(a).options.$skipDiscriminatorCheck)throw new Error('Discriminator "'+e+'" cannot have field with name "'+a+'"');var c=e;if("string"==typeof s&&s.length&&(c=s),function(e,r){if(e._originalSchema=e.clone(),r.paths._id&&r.paths._id.options&&!r.paths._id.options.auto){var n=e;i.merge(e,n),delete e.paths._id,delete e.tree._id}var s=Object.keys(r.paths),u=[];for(_=0;_<s.length;++_)e.nested[s[_]]&&u.push(s[_]);for(i.merge(e,r,{omit:{discriminators:!0},omitNested:u.reduce(function(t,e){return t["tree."+e]=!0,t},{})}),_=0;_<u.length;++_)delete e.paths[u[_]];var l={};l[a]={default:c,select:!0,set:function(t){if(t===c)return c;throw new Error("Can't set discriminator key \""+a+'"')},$skipDiscriminatorCheck:!0},l[a][e.options.typeKey]=String,e.add(l),e.discriminatorMapping={key:a,value:c,isRoot:!1},r.options.collection&&(e.options.collection=r.options.collection);var f=e.options.toJSON,h=e.options.toObject,p=e.options._id,d=e.options.id,y=Object.keys(e.options);e.options.discriminatorKey=r.options.discriminatorKey;for(var _=0;_<y.length;++_){var m=y[_];if(!o[m]&&!i.deepEqual(e.options[m],r.options[m]))throw new Error("Can't customize discriminator option "+m+" (can only modify "+Object.keys(o).join(", ")+")")}e.options=i.clone(r.options),f&&(e.options.toJSON=f),h&&(e.options.toObject=h),"undefined"!==typeof p&&(e.options._id=p),e.options.id=d,e.s.hooks=t.schema.s.hooks.merge(e.s.hooks),e.plugins=Array.prototype.slice(r.plugins),e.callQueue=r.callQueue.concat(e.callQueue),delete e._requiredpaths}(r,t.schema),t.discriminators||(t.discriminators={}),t.schema.discriminatorMapping||(t.schema.discriminatorMapping={key:a,value:null,isRoot:!0}),t.schema.discriminators||(t.schema.discriminators={}),t.schema.discriminators[e]=r,t.discriminators[e])throw new Error('Discriminator with name "'+e+'" already exists');return r}},function(t,e,r){"use strict";var n=r(2);function i(t,e){n.call(this,"Tried to set nested object field `"+t+"` to primitive value `"+e+"` and strict mode is set to throw."),this.name="ObjectExpectedError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack,this.path=t}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,t.exports=i},function(t,e,r){"use strict";t.exports=r(77)},function(t,e,r){"use strict";(function(n){r(14).set(r(81));var i=r(51),o=r(52);i.setBrowser(!0),Object.defineProperty(e,"Promise",{get:function(){return o.get()},set:function(t){o.set(t)}}),e.PromiseProvider=o,e.Error=r(2),e.Schema=r(43),e.Types=r(16),e.VirtualType=r(44),e.SchemaType=r(5),e.utils=r(0),e.Document=i(),"undefined"!==typeof window&&(window.mongoose=t.exports,window.Buffer=n)}).call(this,r(1).Buffer)},function(t,e,r){"use strict";e.byteLength=function(t){var e=c(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){for(var e,r=c(t),n=r[0],s=r[1],a=new o(function(t,e,r){return 3*(e+r)/4-r}(0,n,s)),u=0,l=s>0?n-4:n,f=0;f<l;f+=4)e=i[t.charCodeAt(f)]<<18|i[t.charCodeAt(f+1)]<<12|i[t.charCodeAt(f+2)]<<6|i[t.charCodeAt(f+3)],a[u++]=e>>16&255,a[u++]=e>>8&255,a[u++]=255&e;2===s&&(e=i[t.charCodeAt(f)]<<2|i[t.charCodeAt(f+1)]>>4,a[u++]=255&e);1===s&&(e=i[t.charCodeAt(f)]<<10|i[t.charCodeAt(f+1)]<<4|i[t.charCodeAt(f+2)]>>2,a[u++]=e>>8&255,a[u++]=255&e);return a},e.fromByteArray=function(t){for(var e,r=t.length,i=r%3,o=[],s=0,a=r-i;s<a;s+=16383)o.push(l(t,s,s+16383>a?a:s+16383));1===i?(e=t[r-1],o.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],o.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!==typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],i[s.charCodeAt(a)]=a;function c(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function l(t,e,r){for(var i,o,s=[],a=e;a<r;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(t,e,r){"use strict";e.read=function(t,e,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,c=u>>1,l=-7,f=r?i-1:0,h=r?-1:1,p=t[e+f];for(f+=h,o=p&(1<<-l)-1,p>>=-l,l+=a;l>0;o=256*o+t[e+f],f+=h,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=256*s+t[e+f],f+=h,l-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},e.write=function(t,e,r,n,i,o){var s,a,u,c=8*o-i-1,l=(1<<c)-1,f=l>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+f>=1?h/u:h*Math.pow(2,1-f))*u>=2&&(s++,u/=2),s+f>=l?(a=0,s=l):s+f>=1?(a=(e*u-1)*Math.pow(2,i),s+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;t[r+p]=255&s,p+=d,s/=256,c-=8);t[r+p-d]|=128*y}},function(t,e,r){"use strict";var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,r){"use strict";e.Binary=r(82),e.Collection=function(){throw new Error("Cannot create a collection from browser library")},e.Decimal128=r(89),e.ObjectId=r(90),e.ReadPreference=r(91)},function(t,e,r){"use strict";var n=r(23).Binary;t.exports=n},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)}t.exports=function(t){return t&&"object"===n(t)&&"function"===typeof t.copy&&"function"===typeof t.fill&&"function"===typeof t.readUInt8}},function(t,e,r){"use strict";"function"===typeof Object.create?t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}},function(module,exports,__webpack_require__){"use strict";(function(Buffer){var Long=__webpack_require__(15).Long,Double=__webpack_require__(24).Double,Timestamp=__webpack_require__(25).Timestamp,ObjectID=__webpack_require__(26).ObjectID,_Symbol=__webpack_require__(28).Symbol,Code=__webpack_require__(29).Code,MinKey=__webpack_require__(18).MinKey,MaxKey=__webpack_require__(31).MaxKey,Decimal128=__webpack_require__(30),Int32=__webpack_require__(49),DBRef=__webpack_require__(32).DBRef,BSONRegExp=__webpack_require__(27).BSONRegExp,Binary=__webpack_require__(19).Binary,deserialize=function(t,e,r){var n=(e=null==e?{}:e)&&e.index?e.index:0,i=t[n]|t[n+1]<<8|t[n+2]<<16|t[n+3]<<24;if(i<5||t.length<i||i+n>t.length)throw new Error("corrupt bson message");if(0!==t[n+i-1])throw new Error("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return deserializeObject(t,n,e,r)},deserializeObject=function t(e,r,n,i){var o=null!=n.evalFunctions&&n.evalFunctions,s=null!=n.cacheFunctions&&n.cacheFunctions,a=null!=n.cacheFunctionsCrc32&&n.cacheFunctionsCrc32;if(!a)var u=null;var c=null==n.fieldsAsRaw?null:n.fieldsAsRaw,l=null!=n.raw&&n.raw,f="boolean"===typeof n.bsonRegExp&&n.bsonRegExp,h=null!=n.promoteBuffers&&n.promoteBuffers,p=null==n.promoteLongs||n.promoteLongs,d=null==n.promoteValues||n.promoteValues,y=r;if(e.length<5)throw new Error("corrupt bson message < 5 bytes long");var _=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24;if(_<5||_>e.length)throw new Error("corrupt bson message");for(var m=i?[]:{},v=0;;){var g=e[r++];if(0===g)break;for(var b=r;0!==e[b]&&b<e.length;)b++;if(b>=e.length)throw new Error("Bad BSON Document: illegal CString");var w=i?v++:e.toString("utf8",r,b);if(r=b+1,g===BSON.BSON_DATA_STRING){var O=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24;if(O<=0||O>e.length-r||0!==e[r+O-1])throw new Error("bad string length in bson");m[w]=e.toString("utf8",r,r+O-1),r+=O}else if(g===BSON.BSON_DATA_OID){var S=new Buffer(12);e.copy(S,0,r,r+12),m[w]=new ObjectID(S),r+=12}else if(g===BSON.BSON_DATA_INT&&!1===d)m[w]=new Int32(e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24);else if(g===BSON.BSON_DATA_INT)m[w]=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24;else if(g===BSON.BSON_DATA_NUMBER&&!1===d)m[w]=new Double(e.readDoubleLE(r)),r+=8;else if(g===BSON.BSON_DATA_NUMBER)m[w]=e.readDoubleLE(r),r+=8;else if(g===BSON.BSON_DATA_DATE){var E=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24,A=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24;m[w]=new Date(new Long(E,A).toNumber())}else if(g===BSON.BSON_DATA_BOOLEAN){if(0!==e[r]&&1!==e[r])throw new Error("illegal boolean type value");m[w]=1===e[r++]}else if(g===BSON.BSON_DATA_OBJECT){var $=r,N=e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24;if(N<=0||N>e.length-r)throw new Error("bad embedded document length in bson");m[w]=l?e.slice(r,r+N):t(e,$,n,!1),r+=N}else if(g===BSON.BSON_DATA_ARRAY){$=r;var j=n,x=r+(N=e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24);if(c&&c[w]){for(var T in j={},n)j[T]=n[T];j.raw=!0}if(m[w]=t(e,$,j,!0),0!==e[(r+=N)-1])throw new Error("invalid array terminator byte");if(r!==x)throw new Error("corrupted array bson")}else if(g===BSON.BSON_DATA_UNDEFINED)m[w]=void 0;else if(g===BSON.BSON_DATA_NULL)m[w]=null;else if(g===BSON.BSON_DATA_LONG){E=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24,A=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24;var B=new Long(E,A);m[w]=p&&!0===d&&B.lessThanOrEqual(JS_INT_MAX_LONG)&&B.greaterThanOrEqual(JS_INT_MIN_LONG)?B.toNumber():B}else if(g===BSON.BSON_DATA_DECIMAL128){var k=new Buffer(16);e.copy(k,0,r,r+16),r+=16;var C=new Decimal128(k);m[w]=C.toObject?C.toObject():C}else if(g===BSON.BSON_DATA_BINARY){var D=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24,P=D,M=e[r++];if(D<0)throw new Error("Negative binary type element size found");if(D>e.length)throw new Error("Binary type size larger than document size");if(null!=e.slice){if(M===Binary.SUBTYPE_BYTE_ARRAY){if((D=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24)<0)throw new Error("Negative binary type element size found for subtype 0x02");if(D>P-4)throw new Error("Binary type with subtype 0x02 contains to long binary size");if(D<P-4)throw new Error("Binary type with subtype 0x02 contains to short binary size")}m[w]=h&&d?e.slice(r,r+D):new Binary(e.slice(r,r+D),M)}else{var R="undefined"!==typeof Uint8Array?new Uint8Array(new ArrayBuffer(D)):new Array(D);if(M===Binary.SUBTYPE_BYTE_ARRAY){if((D=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24)<0)throw new Error("Negative binary type element size found for subtype 0x02");if(D>P-4)throw new Error("Binary type with subtype 0x02 contains to long binary size");if(D<P-4)throw new Error("Binary type with subtype 0x02 contains to short binary size")}for(b=0;b<D;b++)R[b]=e[r+b];m[w]=h&&d?R:new Binary(R,M)}r+=D}else if(g===BSON.BSON_DATA_REGEXP&&!1===f){for(b=r;0!==e[b]&&b<e.length;)b++;if(b>=e.length)throw new Error("Bad BSON Document: illegal CString");var F=e.toString("utf8",r,b);for(b=r=b+1;0!==e[b]&&b<e.length;)b++;if(b>=e.length)throw new Error("Bad BSON Document: illegal CString");var I=e.toString("utf8",r,b);r=b+1;var L=new Array(I.length);for(b=0;b<I.length;b++)switch(I[b]){case"m":L[b]="m";break;case"s":L[b]="g";break;case"i":L[b]="i"}m[w]=new RegExp(F,L.join(""))}else if(g===BSON.BSON_DATA_REGEXP&&!0===f){for(b=r;0!==e[b]&&b<e.length;)b++;if(b>=e.length)throw new Error("Bad BSON Document: illegal CString");for(F=e.toString("utf8",r,b),b=r=b+1;0!==e[b]&&b<e.length;)b++;if(b>=e.length)throw new Error("Bad BSON Document: illegal CString");I=e.toString("utf8",r,b),r=b+1,m[w]=new BSONRegExp(F,I)}else if(g===BSON.BSON_DATA_SYMBOL){if((O=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24)<=0||O>e.length-r||0!==e[r+O-1])throw new Error("bad string length in bson");m[w]=new _Symbol(e.toString("utf8",r,r+O-1)),r+=O}else if(g===BSON.BSON_DATA_TIMESTAMP)E=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24,A=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24,m[w]=new Timestamp(E,A);else if(g===BSON.BSON_DATA_MIN_KEY)m[w]=new MinKey;else if(g===BSON.BSON_DATA_MAX_KEY)m[w]=new MaxKey;else if(g===BSON.BSON_DATA_CODE){if((O=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24)<=0||O>e.length-r||0!==e[r+O-1])throw new Error("bad string length in bson");var U=e.toString("utf8",r,r+O-1);if(o)if(s){var V=a?u(U):U;m[w]=isolateEvalWithHash(functionCache,V,U,m)}else m[w]=isolateEval(U);else m[w]=new Code(U);r+=O}else if(g===BSON.BSON_DATA_CODE_W_SCOPE){var q=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24;if(q<13)throw new Error("code_w_scope total size shorter minimum expected length");if((O=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24)<=0||O>e.length-r||0!==e[r+O-1])throw new Error("bad string length in bson");U=e.toString("utf8",r,r+O-1),$=r+=O,N=e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24;var W=t(e,$,n,!1);if(r+=N,q<8+N+O)throw new Error("code_w_scope total size is to short, truncating scope");if(q>8+N+O)throw new Error("code_w_scope total size is to long, clips outer document");o?(s?(V=a?u(U):U,m[w]=isolateEvalWithHash(functionCache,V,U,m)):m[w]=isolateEval(U),m[w].scope=W):m[w]=new Code(U,W)}else{if(g!==BSON.BSON_DATA_DBPOINTER)throw new Error("Detected unknown BSON type "+g.toString(16)+' for fieldname "'+w+'", are you using the latest BSON parser');if((O=e[r++]|e[r++]<<8|e[r++]<<16|e[r++]<<24)<=0||O>e.length-r||0!==e[r+O-1])throw new Error("bad string length in bson");var H=e.toString("utf8",r,r+O-1);r+=O;var Y=new Buffer(12);e.copy(Y,0,r,r+12),S=new ObjectID(Y),r+=12;var z=H.split("."),K=z.shift(),Q=z.join(".");m[w]=new DBRef(Q,S,K)}}if(_!==r-y){if(i)throw new Error("corrupt array bson");throw new Error("corrupt object bson")}return null!=m.$id&&(m=new DBRef(m.$ref,m.$id,m.$db)),m},isolateEvalWithHash=function isolateEvalWithHash(functionCache,hash,functionString,object){var value=null;return null==functionCache[hash]&&(eval("value = "+functionString),functionCache[hash]=value),functionCache[hash].bind(object)},isolateEval=function isolateEval(functionString){var value=null;return eval("value = "+functionString),value},BSON={},functionCache=BSON.functionCache={};BSON.BSON_DATA_NUMBER=1,BSON.BSON_DATA_STRING=2,BSON.BSON_DATA_OBJECT=3,BSON.BSON_DATA_ARRAY=4,BSON.BSON_DATA_BINARY=5,BSON.BSON_DATA_UNDEFINED=6,BSON.BSON_DATA_OID=7,BSON.BSON_DATA_BOOLEAN=8,BSON.BSON_DATA_DATE=9,BSON.BSON_DATA_NULL=10,BSON.BSON_DATA_REGEXP=11,BSON.BSON_DATA_DBPOINTER=12,BSON.BSON_DATA_CODE=13,BSON.BSON_DATA_SYMBOL=14,BSON.BSON_DATA_CODE_W_SCOPE=15,BSON.BSON_DATA_INT=16,BSON.BSON_DATA_TIMESTAMP=17,BSON.BSON_DATA_LONG=18,BSON.BSON_DATA_DECIMAL128=19,BSON.BSON_DATA_MIN_KEY=255,BSON.BSON_DATA_MAX_KEY=127,BSON.BSON_BINARY_SUBTYPE_DEFAULT=0,BSON.BSON_BINARY_SUBTYPE_FUNCTION=1,BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY=2,BSON.BSON_BINARY_SUBTYPE_UUID=3,BSON.BSON_BINARY_SUBTYPE_MD5=4,BSON.BSON_BINARY_SUBTYPE_USER_DEFINED=128,BSON.BSON_INT32_MAX=2147483647,BSON.BSON_INT32_MIN=-2147483648,BSON.BSON_INT64_MAX=Math.pow(2,63)-1,BSON.BSON_INT64_MIN=-Math.pow(2,63),BSON.JS_INT_MAX=9007199254740992,BSON.JS_INT_MIN=-9007199254740992;var JS_INT_MAX_LONG=Long.fromNumber(9007199254740992),JS_INT_MIN_LONG=Long.fromNumber(-9007199254740992);module.exports=deserialize}).call(this,__webpack_require__(1).Buffer)},function(t,e,r){"use strict";(function(e){function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(87).writeIEEE754,o=r(15).Long,s=r(18).MinKey,a=r(48),u=r(19).Binary,c=r(50).normalizedFunctionString,l=/\x00/,f=function(t){return"object"===n(t)&&"[object Date]"===Object.prototype.toString.call(t)},h=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},p=function(t,e,r,n,i){t[n++]=D.BSON_DATA_STRING,t[(n=n+(i?t.write(e,n,"ascii"):t.write(e,n,"utf8"))+1)-1]=0;var o=t.write(r,n+4,"utf8");return t[n+3]=o+1>>24&255,t[n+2]=o+1>>16&255,t[n+1]=o+1>>8&255,t[n]=o+1&255,n=n+4+o,t[n++]=0,n},d=function(t,e,r,n,s){if(Math.floor(r)===r&&r>=D.JS_INT_MIN&&r<=D.JS_INT_MAX)if(r>=D.BSON_INT32_MIN&&r<=D.BSON_INT32_MAX){t[n++]=D.BSON_DATA_INT;var a=s?t.write(e,n,"ascii"):t.write(e,n,"utf8");n+=a,t[n++]=0,t[n++]=255&r,t[n++]=r>>8&255,t[n++]=r>>16&255,t[n++]=r>>24&255}else if(r>=D.JS_INT_MIN&&r<=D.JS_INT_MAX)t[n++]=D.BSON_DATA_NUMBER,n+=a=s?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,i(t,r,n,"little",52,8),n+=8;else{t[n++]=D.BSON_DATA_LONG,n+=a=s?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var u=o.fromNumber(r),c=u.getLowBits(),l=u.getHighBits();t[n++]=255&c,t[n++]=c>>8&255,t[n++]=c>>16&255,t[n++]=c>>24&255,t[n++]=255&l,t[n++]=l>>8&255,t[n++]=l>>16&255,t[n++]=l>>24&255}else t[n++]=D.BSON_DATA_NUMBER,n+=a=s?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,i(t,r,n,"little",52,8),n+=8;return n},y=function(t,e,r,n,i){return t[n++]=D.BSON_DATA_NULL,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,n},_=function(t,e,r,n,i){return t[n++]=D.BSON_DATA_BOOLEAN,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,t[n++]=r?1:0,n},m=function(t,e,r,n,i){t[n++]=D.BSON_DATA_DATE,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var s=o.fromNumber(r.getTime()),a=s.getLowBits(),u=s.getHighBits();return t[n++]=255&a,t[n++]=a>>8&255,t[n++]=a>>16&255,t[n++]=a>>24&255,t[n++]=255&u,t[n++]=u>>8&255,t[n++]=u>>16&255,t[n++]=u>>24&255,n},v=function(t,e,r,n,i){if(t[n++]=D.BSON_DATA_REGEXP,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,r.source&&null!=r.source.match(l))throw Error("value "+r.source+" must not contain null bytes");return n+=t.write(r.source,n,"utf8"),t[n++]=0,r.global&&(t[n++]=115),r.ignoreCase&&(t[n++]=105),r.multiline&&(t[n++]=109),t[n++]=0,n},g=function(t,e,r,n,i){if(t[n++]=D.BSON_DATA_REGEXP,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,null!=r.pattern.match(l))throw Error("pattern "+r.pattern+" must not contain null bytes");return n+=t.write(r.pattern,n,"utf8"),t[n++]=0,n+=t.write(r.options.split("").sort().join(""),n,"utf8"),t[n++]=0,n},b=function(t,e,r,n,i){return t[n++]=null===r?D.BSON_DATA_NULL:r instanceof s?D.BSON_DATA_MIN_KEY:D.BSON_DATA_MAX_KEY,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,n},w=function(t,e,r,n,i){if(t[n++]=D.BSON_DATA_OID,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,"string"===typeof r.id)t.write(r.id,n,"binary");else{if(!r.id||!r.id.copy)throw new Error("object ["+JSON.stringify(r)+"] is not a valid ObjectId");r.id.copy(t,n,0,12)}return n+12},O=function(t,e,r,n,i){t[n++]=D.BSON_DATA_BINARY,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var o=r.length;return t[n++]=255&o,t[n++]=o>>8&255,t[n++]=o>>16&255,t[n++]=o>>24&255,t[n++]=D.BSON_BINARY_SUBTYPE_DEFAULT,r.copy(t,n,0,o),n+=o},S=function(t,e,r,n,i,o,s,a,u,c){for(var l=0;l<c.length;l++)if(c[l]===r)throw new Error("cyclic dependency detected");c.push(r),t[n++]=Array.isArray(r)?D.BSON_DATA_ARRAY:D.BSON_DATA_OBJECT,n+=u?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var f=C(t,r,i,n,o+1,s,a,c);return c.pop(),f},E=function(t,e,r,n,i){return t[n++]=D.BSON_DATA_DECIMAL128,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,r.bytes.copy(t,n,0,16),n+16},A=function(t,e,r,n,i){t[n++]="Long"===r._bsontype?D.BSON_DATA_LONG:D.BSON_DATA_TIMESTAMP,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var o=r.getLowBits(),s=r.getHighBits();return t[n++]=255&o,t[n++]=o>>8&255,t[n++]=o>>16&255,t[n++]=o>>24&255,t[n++]=255&s,t[n++]=s>>8&255,t[n++]=s>>16&255,t[n++]=s>>24&255,n},$=function(t,e,r,n,i){return t[n++]=D.BSON_DATA_INT,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,t[n++]=255&r,t[n++]=r>>8&255,t[n++]=r>>16&255,t[n++]=r>>24&255,n},N=function(t,e,r,n,o){return t[n++]=D.BSON_DATA_NUMBER,n+=o?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0,i(t,r,n,"little",52,8),n+=8},j=function(t,e,r,n,i,o,s){t[n++]=D.BSON_DATA_CODE,n+=s?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var a=c(r),u=t.write(a,n+4,"utf8")+1;return t[n]=255&u,t[n+1]=u>>8&255,t[n+2]=u>>16&255,t[n+3]=u>>24&255,n=n+4+u-1,t[n++]=0,n},x=function(t,e,r,i,o,s,a,u,c){if(r.scope&&"object"===n(r.scope)){t[i++]=D.BSON_DATA_CODE_W_SCOPE;var l=c?t.write(e,i,"ascii"):t.write(e,i,"utf8");i+=l,t[i++]=0;var f=i,h="string"===typeof r.code?r.code:r.code.toString();i+=4;var p=t.write(h,i+4,"utf8")+1;t[i]=255&p,t[i+1]=p>>8&255,t[i+2]=p>>16&255,t[i+3]=p>>24&255,t[i+4+p-1]=0,i=i+p+4;var d=C(t,r.scope,o,i,s+1,a,u);i=d-1;var y=d-f;t[f++]=255&y,t[f++]=y>>8&255,t[f++]=y>>16&255,t[f++]=y>>24&255,t[i++]=0}else{t[i++]=D.BSON_DATA_CODE,i+=l=c?t.write(e,i,"ascii"):t.write(e,i,"utf8"),t[i++]=0,h=r.code.toString();var _=t.write(h,i+4,"utf8")+1;t[i]=255&_,t[i+1]=_>>8&255,t[i+2]=_>>16&255,t[i+3]=_>>24&255,i=i+4+_-1,t[i++]=0}return i},T=function(t,e,r,n,i){t[n++]=D.BSON_DATA_BINARY,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var o=r.value(!0),s=r.position;return r.sub_type===u.SUBTYPE_BYTE_ARRAY&&(s+=4),t[n++]=255&s,t[n++]=s>>8&255,t[n++]=s>>16&255,t[n++]=s>>24&255,t[n++]=r.sub_type,r.sub_type===u.SUBTYPE_BYTE_ARRAY&&(s-=4,t[n++]=255&s,t[n++]=s>>8&255,t[n++]=s>>16&255,t[n++]=s>>24&255),o.copy(t,n,0,r.position),n+=r.position},B=function(t,e,r,n,i){t[n++]=D.BSON_DATA_SYMBOL,n+=i?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var o=t.write(r.value,n+4,"utf8")+1;return t[n]=255&o,t[n+1]=o>>8&255,t[n+2]=o>>16&255,t[n+3]=o>>24&255,n=n+4+o-1,t[n++]=0,n},k=function(t,e,r,n,i,o,s){t[n++]=D.BSON_DATA_OBJECT,n+=s?t.write(e,n,"ascii"):t.write(e,n,"utf8"),t[n++]=0;var a,u=n,c=(a=null!=r.db?C(t,{$ref:r.namespace,$id:r.oid,$db:r.db},!1,n,i+1,o):C(t,{$ref:r.namespace,$id:r.oid},!1,n,i+1,o))-u;return t[u++]=255&c,t[u++]=c>>8&255,t[u++]=c>>16&255,t[u++]=c>>24&255,a},C=function(t,r,i,o,s,u,c,C){o=o||0,(C=C||[]).push(r);var D=o+4;if(Array.isArray(r))for(var P=0;P<r.length;P++){var M=""+P,R=r[P];if(R&&R.toBSON){if("function"!==typeof R.toBSON)throw new Error("toBSON is not a function");R=R.toBSON()}var F=n(R);"string"===F?D=p(t,M,R,D,!0):"number"===F?D=d(t,M,R,D,!0):"boolean"===F?D=_(t,M,R,D,!0):R instanceof Date||f(R)?D=m(t,M,R,D,!0):void 0===R?D=y(t,M,0,D,!0):null===R?D=y(t,M,0,D,!0):"ObjectID"===R._bsontype?D=w(t,M,R,D,!0):e.isBuffer(R)?D=O(t,M,R,D,!0):R instanceof RegExp||h(R)?D=v(t,M,R,D,!0):"object"===F&&null==R._bsontype?D=S(t,M,R,D,i,s,u,c,!0,C):"object"===F&&"Decimal128"===R._bsontype?D=E(t,M,R,D,!0):"Long"===R._bsontype||"Timestamp"===R._bsontype?D=A(t,M,R,D,!0):"Double"===R._bsontype?D=N(t,M,R,D,!0):"function"===typeof R&&u?D=j(t,M,R,D,0,0,u):"Code"===R._bsontype?D=x(t,M,R,D,i,s,u,c,!0):"Binary"===R._bsontype?D=T(t,M,R,D,!0):"Symbol"===R._bsontype?D=B(t,M,R,D,!0):"DBRef"===R._bsontype?D=k(t,M,R,D,s,u,!0):"BSONRegExp"===R._bsontype?D=g(t,M,R,D,!0):"Int32"===R._bsontype?D=$(t,M,R,D,!0):"MinKey"!==R._bsontype&&"MaxKey"!==R._bsontype||(D=b(t,M,R,D,!0))}else if(r instanceof a)for(var I=r.entries(),L=!1;!L;){var U=I.next();if(!(L=U.done)){if(M=U.value[0],F=n(R=U.value[1]),"$db"!==M&&"$ref"!==M&&"$id"!==M){if(null!=M.match(l))throw Error("key "+M+" must not contain null bytes");if(i){if("$"===M[0])throw Error("key "+M+" must not start with '$'");if(~M.indexOf("."))throw Error("key "+M+" must not contain '.'")}}"string"===F?D=p(t,M,R,D):"number"===F?D=d(t,M,R,D):"boolean"===F?D=_(t,M,R,D):R instanceof Date||f(R)?D=m(t,M,R,D):null===R||void 0===R&&!1===c?D=y(t,M,0,D):"ObjectID"===R._bsontype?D=w(t,M,R,D):e.isBuffer(R)?D=O(t,M,R,D):R instanceof RegExp||h(R)?D=v(t,M,R,D):"object"===F&&null==R._bsontype?D=S(t,M,R,D,i,s,u,c,!1,C):"object"===F&&"Decimal128"===R._bsontype?D=E(t,M,R,D):"Long"===R._bsontype||"Timestamp"===R._bsontype?D=A(t,M,R,D):"Double"===R._bsontype?D=N(t,M,R,D):"Code"===R._bsontype?D=x(t,M,R,D,i,s,u,c):"function"===typeof R&&u?D=j(t,M,R,D,0,0,u):"Binary"===R._bsontype?D=T(t,M,R,D):"Symbol"===R._bsontype?D=B(t,M,R,D):"DBRef"===R._bsontype?D=k(t,M,R,D,s,u):"BSONRegExp"===R._bsontype?D=g(t,M,R,D):"Int32"===R._bsontype?D=$(t,M,R,D):"MinKey"!==R._bsontype&&"MaxKey"!==R._bsontype||(D=b(t,M,R,D))}}else{if(r.toBSON){if("function"!==typeof r.toBSON)throw new Error("toBSON is not a function");if(null!=(r=r.toBSON())&&"object"!==n(r))throw new Error("toBSON function did not return an object")}for(M in r){if((R=r[M])&&R.toBSON){if("function"!==typeof R.toBSON)throw new Error("toBSON is not a function");R=R.toBSON()}if(F=n(R),"$db"!==M&&"$ref"!==M&&"$id"!==M){if(null!=M.match(l))throw Error("key "+M+" must not contain null bytes");if(i){if("$"===M[0])throw Error("key "+M+" must not start with '$'");if(~M.indexOf("."))throw Error("key "+M+" must not contain '.'")}}"string"===F?D=p(t,M,R,D):"number"===F?D=d(t,M,R,D):"boolean"===F?D=_(t,M,R,D):R instanceof Date||f(R)?D=m(t,M,R,D):void 0===R?!1===c&&(D=y(t,M,0,D)):null===R?D=y(t,M,0,D):"ObjectID"===R._bsontype?D=w(t,M,R,D):e.isBuffer(R)?D=O(t,M,R,D):R instanceof RegExp||h(R)?D=v(t,M,R,D):"object"===F&&null==R._bsontype?D=S(t,M,R,D,i,s,u,c,!1,C):"object"===F&&"Decimal128"===R._bsontype?D=E(t,M,R,D):"Long"===R._bsontype||"Timestamp"===R._bsontype?D=A(t,M,R,D):"Double"===R._bsontype?D=N(t,M,R,D):"Code"===R._bsontype?D=x(t,M,R,D,i,s,u,c):"function"===typeof R&&u?D=j(t,M,R,D,0,0,u):"Binary"===R._bsontype?D=T(t,M,R,D):"Symbol"===R._bsontype?D=B(t,M,R,D):"DBRef"===R._bsontype?D=k(t,M,R,D,s,u):"BSONRegExp"===R._bsontype?D=g(t,M,R,D):"Int32"===R._bsontype?D=$(t,M,R,D):"MinKey"!==R._bsontype&&"MaxKey"!==R._bsontype||(D=b(t,M,R,D))}}C.pop(),t[D++]=0;var V=D-o;return t[o++]=255&V,t[o++]=V>>8&255,t[o++]=V>>16&255,t[o++]=V>>24&255,D},D={BSON_DATA_NUMBER:1,BSON_DATA_STRING:2,BSON_DATA_OBJECT:3,BSON_DATA_ARRAY:4,BSON_DATA_BINARY:5,BSON_DATA_UNDEFINED:6,BSON_DATA_OID:7,BSON_DATA_BOOLEAN:8,BSON_DATA_DATE:9,BSON_DATA_NULL:10,BSON_DATA_REGEXP:11,BSON_DATA_CODE:13,BSON_DATA_SYMBOL:14,BSON_DATA_CODE_W_SCOPE:15,BSON_DATA_INT:16,BSON_DATA_TIMESTAMP:17,BSON_DATA_LONG:18,BSON_DATA_DECIMAL128:19,BSON_DATA_MIN_KEY:255,BSON_DATA_MAX_KEY:127,BSON_BINARY_SUBTYPE_DEFAULT:0,BSON_BINARY_SUBTYPE_FUNCTION:1,BSON_BINARY_SUBTYPE_BYTE_ARRAY:2,BSON_BINARY_SUBTYPE_UUID:3,BSON_BINARY_SUBTYPE_MD5:4,BSON_BINARY_SUBTYPE_USER_DEFINED:128,BSON_INT32_MAX:2147483647,BSON_INT32_MIN:-2147483648};D.BSON_INT64_MAX=Math.pow(2,63)-1,D.BSON_INT64_MIN=-Math.pow(2,63),D.JS_INT_MAX=9007199254740992,D.JS_INT_MIN=-9007199254740992,t.exports=C}).call(this,r(1).Buffer)},function(t,e,r){"use strict";e.readIEEE754=function(t,e,r,n,i){var o,s,a="big"===r,u=8*i-n-1,c=(1<<u)-1,l=c>>1,f=-7,h=a?0:i-1,p=a?1:-1,d=t[e+h];for(h+=p,o=d&(1<<-f)-1,d>>=-f,f+=u;f>0;o=256*o+t[e+h],h+=p,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+t[e+h],h+=p,f-=8);if(0===o)o=1-l;else{if(o===c)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),o-=l}return(d?-1:1)*s*Math.pow(2,o-n)},e.writeIEEE754=function(t,e,r,n,i,o){var s,a,u,c="big"===n,l=8*o-i-1,f=(1<<l)-1,h=f>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=c?o-1:0,y=c?-1:1,_=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+h>=1?p/u:p*Math.pow(2,1-h))*u>=2&&(s++,u/=2),s+h>=f?(a=0,s=f):s+h>=1?(a=(e*u-1)*Math.pow(2,i),s+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;t[r+d]=255&a,d+=y,a/=256,i-=8);for(s=s<<i|a,l+=i;l>0;t[r+d]=255&s,d+=y,s/=256,l-=8);t[r+d-y]|=128*_}},function(t,e,r){"use strict";(function(e){function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(15).Long,o=r(24).Double,s=r(25).Timestamp,a=r(26).ObjectID,u=r(28).Symbol,c=r(27).BSONRegExp,l=r(29).Code,f=r(30),h=r(18).MinKey,p=r(31).MaxKey,d=r(32).DBRef,y=r(19).Binary,_=r(50).normalizedFunctionString,m=function(t){return"object"===n(t)&&"[object Date]"===Object.prototype.toString.call(t)},v=function(t,e,r){var n=5;if(Array.isArray(t))for(var i=0;i<t.length;i++)n+=g(i.toString(),t[i],e,!0,r);else for(var o in t.toBSON&&(t=t.toBSON()),t)n+=g(o,t[o],e,!1,r);return n};function g(t,r,g,w,O){switch(r&&r.toBSON&&(r=r.toBSON()),n(r)){case"string":return 1+e.byteLength(t,"utf8")+1+4+e.byteLength(r,"utf8")+1;case"number":return Math.floor(r)===r&&r>=b.JS_INT_MIN&&r<=b.JS_INT_MAX&&r>=b.BSON_INT32_MIN&&r<=b.BSON_INT32_MAX?(null!=t?e.byteLength(t,"utf8")+1:0)+5:(null!=t?e.byteLength(t,"utf8")+1:0)+9;case"undefined":return w||!O?(null!=t?e.byteLength(t,"utf8")+1:0)+1:0;case"boolean":return(null!=t?e.byteLength(t,"utf8")+1:0)+2;case"object":if(null==r||r instanceof h||r instanceof p||"MinKey"===r._bsontype||"MaxKey"===r._bsontype)return(null!=t?e.byteLength(t,"utf8")+1:0)+1;if(r instanceof a||"ObjectID"===r._bsontype)return(null!=t?e.byteLength(t,"utf8")+1:0)+13;if(r instanceof Date||m(r))return(null!=t?e.byteLength(t,"utf8")+1:0)+9;if("undefined"!==typeof e&&e.isBuffer(r))return(null!=t?e.byteLength(t,"utf8")+1:0)+6+r.length;if(r instanceof i||r instanceof o||r instanceof s||"Long"===r._bsontype||"Double"===r._bsontype||"Timestamp"===r._bsontype)return(null!=t?e.byteLength(t,"utf8")+1:0)+9;if(r instanceof f||"Decimal128"===r._bsontype)return(null!=t?e.byteLength(t,"utf8")+1:0)+17;if(r instanceof l||"Code"===r._bsontype)return null!=r.scope&&Object.keys(r.scope).length>0?(null!=t?e.byteLength(t,"utf8")+1:0)+1+4+4+e.byteLength(r.code.toString(),"utf8")+1+v(r.scope,g,O):(null!=t?e.byteLength(t,"utf8")+1:0)+1+4+e.byteLength(r.code.toString(),"utf8")+1;if(r instanceof y||"Binary"===r._bsontype)return r.sub_type===y.SUBTYPE_BYTE_ARRAY?(null!=t?e.byteLength(t,"utf8")+1:0)+(r.position+1+4+1+4):(null!=t?e.byteLength(t,"utf8")+1:0)+(r.position+1+4+1);if(r instanceof u||"Symbol"===r._bsontype)return(null!=t?e.byteLength(t,"utf8")+1:0)+e.byteLength(r.value,"utf8")+4+1+1;if(r instanceof d||"DBRef"===r._bsontype){var S={$ref:r.namespace,$id:r.oid};return null!=r.db&&(S.$db=r.db),(null!=t?e.byteLength(t,"utf8")+1:0)+1+v(S,g,O)}return r instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(r)?(null!=t?e.byteLength(t,"utf8")+1:0)+1+e.byteLength(r.source,"utf8")+1+(r.global?1:0)+(r.ignoreCase?1:0)+(r.multiline?1:0)+1:r instanceof c||"BSONRegExp"===r._bsontype?(null!=t?e.byteLength(t,"utf8")+1:0)+1+e.byteLength(r.pattern,"utf8")+1+e.byteLength(r.options,"utf8")+1:(null!=t?e.byteLength(t,"utf8")+1:0)+v(r,g,O)+1;case"function":if(r instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(r)||"[object RegExp]"===String.call(r))return(null!=t?e.byteLength(t,"utf8")+1:0)+1+e.byteLength(r.source,"utf8")+1+(r.global?1:0)+(r.ignoreCase?1:0)+(r.multiline?1:0)+1;if(g&&null!=r.scope&&Object.keys(r.scope).length>0)return(null!=t?e.byteLength(t,"utf8")+1:0)+1+4+4+e.byteLength(_(r),"utf8")+1+v(r.scope,g,O);if(g)return(null!=t?e.byteLength(t,"utf8")+1:0)+1+4+e.byteLength(_(r),"utf8")+1}return 0}var b={BSON_INT32_MAX:2147483647,BSON_INT32_MIN:-2147483648,JS_INT_MAX:9007199254740992,JS_INT_MIN:-9007199254740992};t.exports=v}).call(this,r(1).Buffer)},function(t,e,r){"use strict";t.exports=r(23).Decimal128},function(t,e,r){"use strict";var n=r(23).ObjectID;Object.defineProperty(n.prototype,"_id",{enumerable:!1,configurable:!0,get:function(){return this}}),t.exports=n},function(t,e,r){"use strict";t.exports=function(){}},function(t,e,r){"use strict";var n=r(93).ctor("require","modify","init","default","ignore");t.exports=function(){this.strictMode=void 0,this.selected=void 0,this.shardval=void 0,this.saveError=void 0,this.validationError=void 0,this.adhocPaths=void 0,this.removing=void 0,this.inserting=void 0,this.saving=void 0,this.version=void 0,this.getters={},this._id=void 0,this.populate=void 0,this.populated=void 0,this.wasPopulated=!1,this.scope=void 0,this.activePaths=new n,this.pathsToScopes={},this.session=null,this.ownerDocument=void 0,this.fullPath=void 0}},function(t,e,r){"use strict";var n=r(0),i=t.exports=function(){};i.ctor=function(){var t=n.args(arguments),e=function(){i.apply(this,arguments),this.paths={},this.states={},this.stateNames=t;for(var e,r=t.length;r--;)e=t[r],this.states[e]={}};return e.prototype=new i,t.forEach(function(t){e.prototype[t]=function(e){this._changeState(e,t)}}),e},i.prototype._changeState=function(t,e){var r=this.states[this.paths[t]];r&&delete r[t],this.paths[t]=e,this.states[e][t]=!0},i.prototype.clear=function(t){for(var e,r=Object.keys(this.states[t]),n=r.length;n--;)e=r[n],delete this.states[t][e],delete this.paths[e]},i.prototype.some=function(){var t=this,e=arguments.length?arguments:this.stateNames;return Array.prototype.some.call(e,function(e){return Object.keys(t.states[e]).length})},i.prototype._iter=function(t){return function(){var e=arguments.length,r=n.args(arguments,0,e-1),i=arguments[e-1];r.length||(r=this.stateNames);var o=this;return r.reduce(function(t,e){return t.concat(Object.keys(o.states[e]))},[])[t](function(t,e,r){return i(t,e,r)})}},i.prototype.forEach=function(){return this.forEach=this._iter("forEach"),this.forEach.apply(this,arguments)},i.prototype.map=function(){return this.map=this._iter("map"),this.map.apply(this,arguments)}},function(t,e,r){"use strict";function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(54),o=r(53),s=r(3),a=r(55),u=r(96)("mquery");function c(t,e){if(!(this instanceof c))return new c(t,e);var r=this.constructor.prototype;this.op=r.op||void 0,this.options={},this.setOptions(r.options),this._conditions=r._conditions?a.clone(r._conditions):{},this._fields=r._fields?a.clone(r._fields):void 0,this._update=r._update?a.clone(r._update):void 0,this._path=r._path||void 0,this._distinct=r._distinct||void 0,this._collection=r._collection||void 0,this._traceFunction=r._traceFunction||void 0,e&&this.setOptions(e),t&&(t.find&&t.remove&&t.update?this.collection(t):this.find(t))}var l="$geoWithin";Object.defineProperty(c,"use$geoWithin",{get:function(){return"$geoWithin"==l},set:function(t){l=!0===t?"$geoWithin":"$within"}}),c.prototype.toConstructor=function(){function t(e,r){if(!(this instanceof t))return new t(e,r);c.call(this,e,r)}a.inherits(t,c);var e=t.prototype;return e.options={},e.setOptions(this.options),e.op=this.op,e._conditions=a.clone(this._conditions),e._fields=a.clone(this._fields),e._update=a.clone(this._update),e._path=this._path,e._distinct=this._distinct,e._collection=this._collection,e._traceFunction=this._traceFunction,t},c.prototype.setOptions=function(t){if(!t||!a.isObject(t))return this;for(var e,r=a.keys(t),n=0;n<r.length;++n)if("function"==typeof this[e=r[n]]){var i=a.isArray(t[e])?t[e]:[t[e]];this[e].apply(this,i)}else this.options[e]=t[e];return this},c.prototype.collection=function(t){return this._collection=new c.Collection(t),this},c.prototype.collation=function(t){return this.options.collation=t,this},c.prototype.$where=function(t){return this._conditions.$where=t,this},c.prototype.where=function(){if(!arguments.length)return this;this.op||(this.op="find");var t=n(arguments[0]);if("string"==t)return this._path=arguments[0],2===arguments.length&&(this._conditions[this._path]=arguments[1]),this;if("object"==t&&!Array.isArray(arguments[0]))return this.merge(arguments[0]);throw new TypeError("path must be a string or object")},c.prototype.equals=function(t){this._ensurePath("equals");var e=this._path;return this._conditions[e]=t,this},c.prototype.eq=function(t){this._ensurePath("eq");var e=this._path;return this._conditions[e]=t,this},c.prototype.or=function(t){var e=this._conditions.$or||(this._conditions.$or=[]);return a.isArray(t)||(t=[t]),e.push.apply(e,t),this},c.prototype.nor=function(t){var e=this._conditions.$nor||(this._conditions.$nor=[]);return a.isArray(t)||(t=[t]),e.push.apply(e,t),this},c.prototype.and=function(t){var e=this._conditions.$and||(this._conditions.$and=[]);return Array.isArray(t)||(t=[t]),e.push.apply(e,t),this},"gt gte lt lte ne in nin all regex size maxDistance minDistance".split(" ").forEach(function(t){c.prototype[t]=function(){var e,r;return 1===arguments.length?(this._ensurePath(t),r=arguments[0],e=this._path):(r=arguments[1],e=arguments[0]),(null===this._conditions[e]||"object"===n(this._conditions[e])?this._conditions[e]:this._conditions[e]={})["$"+t]=r,this}}),c.prototype.mod=function(){var t,e;return 1===arguments.length?(this._ensurePath("mod"),t=arguments[0],e=this._path):2!==arguments.length||a.isArray(arguments[1])?3===arguments.length?(t=i(arguments,1),e=arguments[0]):(t=arguments[1],e=arguments[0]):(this._ensurePath("mod"),t=i(arguments),e=this._path),(this._conditions[e]||(this._conditions[e]={})).$mod=t,this},c.prototype.exists=function(){var t,e;return 0===arguments.length?(this._ensurePath("exists"),t=this._path,e=!0):1===arguments.length?"boolean"===typeof arguments[0]?(this._ensurePath("exists"),t=this._path,e=arguments[0]):(t=arguments[0],e=!0):2===arguments.length&&(t=arguments[0],e=arguments[1]),(this._conditions[t]||(this._conditions[t]={})).$exists=e,this},c.prototype.elemMatch=function(){if(null==arguments[0])throw new TypeError("Invalid argument");var t,e,r;if("function"===typeof arguments[0])this._ensurePath("elemMatch"),e=this._path,t=arguments[0];else if(a.isObject(arguments[0]))this._ensurePath("elemMatch"),e=this._path,r=arguments[0];else if("function"===typeof arguments[1])e=arguments[0],t=arguments[1];else{if(!arguments[1]||!a.isObject(arguments[1]))throw new TypeError("Invalid argument");e=arguments[0],r=arguments[1]}return t&&(t(r=new c),r=r._conditions),(this._conditions[e]||(this._conditions[e]={})).$elemMatch=r,this},c.prototype.within=function(){if(this._ensurePath("within"),this._geoComparison=l,0===arguments.length)return this;if(2===arguments.length)return this.box.apply(this,arguments);if(2<arguments.length)return this.polygon.apply(this,arguments);var t=arguments[0];if(!t)throw new TypeError("Invalid argument");if(t.center)return this.circle(t);if(t.box)return this.box.apply(this,t.box);if(t.polygon)return this.polygon.apply(this,t.polygon);if(t.type&&t.coordinates)return this.geometry(t);throw new TypeError("Invalid argument")},c.prototype.box=function(){var t,e;if(3===arguments.length)t=arguments[0],e=[arguments[1],arguments[2]];else{if(2!==arguments.length)throw new TypeError("Invalid argument");this._ensurePath("box"),t=this._path,e=[arguments[0],arguments[1]]}return(this._conditions[t]||(this._conditions[t]={}))[this._geoComparison||l]={$box:e},this},c.prototype.polygon=function(){var t,e;return"string"==typeof arguments[0]?(e=arguments[0],t=i(arguments,1)):(this._ensurePath("polygon"),e=this._path,t=i(arguments)),(this._conditions[e]||(this._conditions[e]={}))[this._geoComparison||l]={$polygon:t},this},c.prototype.circle=function(){var t,e;if(1===arguments.length)this._ensurePath("circle"),t=this._path,e=arguments[0];else{if(2!==arguments.length)throw new TypeError("Invalid argument");t=arguments[0],e=arguments[1]}if(!("radius"in e&&e.center))throw new Error("center and radius are required");var r=this._conditions[t]||(this._conditions[t]={}),n=e.spherical?"$centerSphere":"$center",i=this._geoComparison||l;return r[i]={},r[i][n]=[e.center,e.radius],"unique"in e&&(r[i].$uniqueDocs=!!e.unique),this},c.prototype.near=function(){var t,e;if(this._geoComparison="$near",0===arguments.length)return this;if(1===arguments.length)this._ensurePath("near"),t=this._path,e=arguments[0];else{if(2!==arguments.length)throw new TypeError("Invalid argument");t=arguments[0],e=arguments[1]}if(!e.center)throw new Error("center is required");var r=this._conditions[t]||(this._conditions[t]={}),n=e.spherical?"$nearSphere":"$near";if(Array.isArray(e.center)){r[n]=e.center;var i="maxDistance"in e?e.maxDistance:null;null!=i&&(r.$maxDistance=i),null!=e.minDistance&&(r.$minDistance=e.minDistance)}else{if("Point"!=e.center.type||!Array.isArray(e.center.coordinates))throw new Error(s.format("Invalid GeoJSON specified for %s",n));r[n]={$geometry:e.center},"maxDistance"in e&&(r[n].$maxDistance=e.maxDistance),"minDistance"in e&&(r[n].$minDistance=e.minDistance)}return this},c.prototype.intersects=function(){if(this._ensurePath("intersects"),this._geoComparison="$geoIntersects",0===arguments.length)return this;var t=arguments[0];if(null!=t&&t.type&&t.coordinates)return this.geometry(t);throw new TypeError("Invalid argument")},c.prototype.geometry=function(){if("$within"!=this._geoComparison&&"$geoWithin"!=this._geoComparison&&"$near"!=this._geoComparison&&"$geoIntersects"!=this._geoComparison)throw new Error("geometry() must come after `within()`, `intersects()`, or `near()");var t,e;if(1!==arguments.length)throw new TypeError("Invalid argument");if(this._ensurePath("geometry"),e=this._path,!(t=arguments[0]).type||!Array.isArray(t.coordinates))throw new TypeError("Invalid argument");return(this._conditions[e]||(this._conditions[e]={}))[this._geoComparison]={$geometry:t},this},c.prototype.select=function(){var t=arguments[0];if(!t)return this;if(1!==arguments.length)throw new Error("Invalid select: select only takes 1 argument");this._validate("select");var e,r,i=this._fields||(this._fields={}),o=n(t);if(("string"==o||a.isArgumentsObject(t))&&"number"==typeof t.length||Array.isArray(t)){for("string"==o&&(t=t.split(/\s+/)),e=0,r=t.length;e<r;++e){var s=t[e];if(s){var u="-"==s[0]?0:1;0===u&&(s=s.substring(1)),i[s]=u}}return this}if(a.isObject(t)){var c=a.keys(t);for(e=0;e<c.length;++e)i[c[e]]=t[c[e]];return this}throw new TypeError("Invalid select() argument. Must be string or object.")},c.prototype.slice=function(){if(0===arguments.length)return this;var t,e;if(this._validate("slice"),1===arguments.length){var r=arguments[0];if("object"===n(r)&&!Array.isArray(r)){for(var o=Object.keys(r),s=o.length,a=0;a<s;++a)this.slice(o[a],r[o[a]]);return this}this._ensurePath("slice"),t=this._path,e=arguments[0]}else 2===arguments.length?"number"===typeof arguments[0]?(this._ensurePath("slice"),t=this._path,e=i(arguments)):(t=arguments[0],e=arguments[1]):3===arguments.length&&(t=arguments[0],e=i(arguments,1));return(this._fields||(this._fields={}))[t]={$slice:e},this},c.prototype.sort=function(t){if(!t)return this;var e,r,i;this._validate("sort");var o=n(t);if(Array.isArray(t)){for(r=t.length,e=0;e<t.length;++e){if(!Array.isArray(t[e]))throw new Error("Invalid sort() argument, must be array of arrays");p(this.options,t[e][0],t[e][1])}return this}if(1===arguments.length&&"string"==o){for(r=(t=t.split(/\s+/)).length,e=0;e<r;++e)if(i=t[e]){var s="-"==i[0]?-1:1;-1===s&&(i=i.substring(1)),h(this.options,i,s)}return this}if(a.isObject(t)){var u=a.keys(t);for(e=0;e<u.length;++e)i=u[e],h(this.options,i,t[i]);return this}if("undefined"!==typeof Map&&t instanceof Map)return function(t,e){if(t.sort=t.sort||new Map,!(t.sort instanceof Map))throw new TypeError("Can't mix sort syntaxes. Use either array or object or map consistently");e.forEach(function(e,r){var n=String(e||1).toLowerCase();if(!(n=f[n]))throw new TypeError("Invalid sort value: < "+r+": "+e+" >");t.sort.set(r,n)})}(this.options,t),this;throw new TypeError("Invalid sort() argument. Must be a string, object, or array.")};var f={1:1,"-1":-1,asc:1,ascending:1,desc:-1,descending:-1};function h(t,e,r){if(Array.isArray(t.sort))throw new TypeError("Can't mix sort syntaxes. Use either array or object:\n- `.sort([['field', 1], ['test', -1]])`\n- `.sort({ field: 1, test: -1 })`");var n;if(r&&r.$meta)(n=t.sort||(t.sort={}))[e]={$meta:r.$meta};else{n=t.sort||(t.sort={});var i=String(r||1).toLowerCase();if(!(i=f[i]))throw new TypeError("Invalid sort value: { "+e+": "+r+" }");n[e]=i}}function p(t,e,r){if(t.sort=t.sort||[],!Array.isArray(t.sort))throw new TypeError("Can't mix sort syntaxes. Use either array or object:\n- `.sort([['field', 1], ['test', -1]])`\n- `.sort({ field: 1, test: -1 })`");var n=String(r||1).toLowerCase();if(!(n=f[n]))throw new TypeError("Invalid sort value: [ "+e+", "+r+" ]");t.sort.push([e,n])}function d(t,e,r,n,i,o,s){return t.op=e,c.canMerge(r)&&t.merge(r),n&&t._mergeUpdate(n),a.isObject(i)&&t.setOptions(i),o||s?!t._update||!t.options.overwrite&&0===a.keys(t._update).length?(s&&a.soon(s.bind(null,null,0)),t):(i=t._optionsForExec(),s||(i.safe=!1),r=t._conditions,n=t._updateForExec(),u("update",t._collection.collectionName,r,n,i),s=t._wrapCallback(e,s,{conditions:r,doc:n,options:i}),t._collection[e](r,n,i,a.tick(s)),t):t}["limit","skip","maxScan","batchSize","comment"].forEach(function(t){c.prototype[t]=function(e){return this._validate(t),this.options[t]=e,this}}),c.prototype.maxTime=c.prototype.maxTimeMS=function(t){return this._validate("maxTime"),this.options.maxTimeMS=t,this},c.prototype.snapshot=function(){return this._validate("snapshot"),this.options.snapshot=!arguments.length||!!arguments[0],this},c.prototype.hint=function(){if(0===arguments.length)return this;this._validate("hint");var t=arguments[0];if(a.isObject(t)){var e=this.options.hint||(this.options.hint={});for(var r in t)e[r]=t[r];return this}if("string"===typeof t)return this.options.hint=t,this;throw new TypeError("Invalid hint. "+t)},c.prototype.j=function(t){return this.options.j=t,this},c.prototype.slaveOk=function(t){return this.options.slaveOk=!arguments.length||!!t,this},c.prototype.read=c.prototype.setReadPreference=function(t){return arguments.length>1&&!c.prototype.read.deprecationWarningIssued&&(console.error("Deprecation warning: 'tags' argument is not supported anymore in Query.read() method. Please use mongodb.ReadPreference object instead."),c.prototype.read.deprecationWarningIssued=!0),this.options.readPreference=a.readPref(t),this},c.prototype.readConcern=c.prototype.r=function(t){return this.options.readConcern=a.readConcern(t),this},c.prototype.tailable=function(){return this._validate("tailable"),this.options.tailable=!arguments.length||!!arguments[0],this},c.prototype.writeConcern=c.prototype.w=function(t){return"object"===n(t)?("undefined"!==typeof t.j&&(this.options.j=t.j),"undefined"!==typeof t.w&&(this.options.w=t.w),"undefined"!==typeof t.wtimeout&&(this.options.wtimeout=t.wtimeout)):this.options.w="m"===t?"majority":t,this},c.prototype.wtimeout=c.prototype.wTimeout=function(t){return this.options.wtimeout=t,this},c.prototype.merge=function(t){if(!t)return this;if(!c.canMerge(t))throw new TypeError("Invalid argument. Expected instanceof mquery or plain object");return t instanceof c?(t._conditions&&a.merge(this._conditions,t._conditions),t._fields&&(this._fields||(this._fields={}),a.merge(this._fields,t._fields)),t.options&&(this.options||(this.options={}),a.merge(this.options,t.options)),t._update&&(this._update||(this._update={}),a.mergeClone(this._update,t._update)),t._distinct&&(this._distinct=t._distinct),this):(a.merge(this._conditions,t),this)},c.prototype.find=function(t,e){if(this.op="find","function"===typeof t?(e=t,t=void 0):c.canMerge(t)&&this.merge(t),!e)return this;var r=this._conditions,n=this._optionsForExec();return n.fields=this._fieldsForExec(),u("find",this._collection.collectionName,r,n),e=this._wrapCallback("find",e,{conditions:r,options:n}),this._collection.find(r,n,a.tick(e)),this},c.prototype.cursor=function(t){if(this.op){if("find"!==this.op)throw new TypeError(".cursor only support .find method")}else this.find(t);var e=this._conditions,r=this._optionsForExec();return r.fields=this._fieldsForExec(),u("findCursor",this._collection.collectionName,e,r),this._collection.findCursor(e,r)},c.prototype.findOne=function(t,e){if(this.op="findOne","function"===typeof t?(e=t,t=void 0):c.canMerge(t)&&this.merge(t),!e)return this;var r=this._conditions,n=this._optionsForExec();return n.fields=this._fieldsForExec(),u("findOne",this._collection.collectionName,r,n),e=this._wrapCallback("findOne",e,{conditions:r,options:n}),this._collection.findOne(r,n,a.tick(e)),this},c.prototype.count=function(t,e){if(this.op="count",this._validate(),"function"===typeof t?(e=t,t=void 0):c.canMerge(t)&&this.merge(t),!e)return this;var r=this._conditions,n=this._optionsForExec();return u("count",this._collection.collectionName,r,n),e=this._wrapCallback("count",e,{conditions:r,options:n}),this._collection.count(r,n,a.tick(e)),this},c.prototype.distinct=function(t,e,r){if(this.op="distinct",this._validate(),!r){switch(n(e)){case"function":r=e,"string"==typeof t&&(e=t,t=void 0);break;case"undefined":case"string":break;default:throw new TypeError("Invalid `field` argument. Must be string or function")}switch(n(t)){case"function":r=t,t=e=void 0;break;case"string":e=t,t=void 0}}if("string"==typeof e&&(this._distinct=e),c.canMerge(t)&&this.merge(t),!r)return this;if(!this._distinct)throw new Error("No value for `distinct` has been declared");var i=this._conditions,o=this._optionsForExec();return u("distinct",this._collection.collectionName,i,o),r=this._wrapCallback("distinct",r,{conditions:i,options:o}),this._collection.distinct(this._distinct,i,o,a.tick(r)),this},c.prototype.update=function(t,e,r,i){var o;switch(arguments.length){case 3:"function"==typeof r&&(i=r,r=void 0);break;case 2:"function"==typeof e&&(i=e,e=t,t=void 0);break;case 1:switch(n(t)){case"function":i=t,t=r=e=void 0;break;case"boolean":o=t,t=void 0;break;default:e=t,t=r=void 0}}return d(this,"update",t,e,r,o,i)},c.prototype.updateMany=function(t,e,r,i){var o;switch(arguments.length){case 3:"function"==typeof r&&(i=r,r=void 0);break;case 2:"function"==typeof e&&(i=e,e=t,t=void 0);break;case 1:switch(n(t)){case"function":i=t,t=r=e=void 0;break;case"boolean":o=t,t=void 0;break;default:e=t,t=r=void 0}}return d(this,"updateMany",t,e,r,o,i)},c.prototype.updateOne=function(t,e,r,i){var o;switch(arguments.length){case 3:"function"==typeof r&&(i=r,r=void 0);break;case 2:"function"==typeof e&&(i=e,e=t,t=void 0);break;case 1:switch(n(t)){case"function":i=t,t=r=e=void 0;break;case"boolean":o=t,t=void 0;break;default:e=t,t=r=void 0}}return d(this,"updateOne",t,e,r,o,i)},c.prototype.replaceOne=function(t,e,r,i){var o;switch(arguments.length){case 3:"function"==typeof r&&(i=r,r=void 0);break;case 2:"function"==typeof e&&(i=e,e=t,t=void 0);break;case 1:switch(n(t)){case"function":i=t,t=r=e=void 0;break;case"boolean":o=t,t=void 0;break;default:e=t,t=r=void 0}}return this.setOptions({overwrite:!0}),d(this,"replaceOne",t,e,r,o,i)},c.prototype.remove=function(t,e){var r;if(this.op="remove","function"===typeof t?(e=t,t=void 0):c.canMerge(t)?this.merge(t):!0===t&&(r=t,t=void 0),!r&&!e)return this;var n=this._optionsForExec();e||(n.safe=!1);var i=this._conditions;return u("remove",this._collection.collectionName,i,n),e=this._wrapCallback("remove",e,{conditions:i,options:n}),this._collection.remove(i,n,a.tick(e)),this},c.prototype.deleteOne=function(t,e){var r;if(this.op="deleteOne","function"===typeof t?(e=t,t=void 0):c.canMerge(t)?this.merge(t):!0===t&&(r=t,t=void 0),!r&&!e)return this;var n=this._optionsForExec();e||(n.safe=!1),delete n.justOne;var i=this._conditions;return u("deleteOne",this._collection.collectionName,i,n),e=this._wrapCallback("deleteOne",e,{conditions:i,options:n}),this._collection.deleteOne(i,n,a.tick(e)),this},c.prototype.deleteMany=function(t,e){var r;if(this.op="deleteMany","function"===typeof t?(e=t,t=void 0):c.canMerge(t)?this.merge(t):!0===t&&(r=t,t=void 0),!r&&!e)return this;var n=this._optionsForExec();e||(n.safe=!1),delete n.justOne;var i=this._conditions;return u("deleteOne",this._collection.collectionName,i,n),e=this._wrapCallback("deleteOne",e,{conditions:i,options:n}),this._collection.deleteMany(i,n,a.tick(e)),this},c.prototype.findOneAndUpdate=function(t,e,r,n){switch(this.op="findOneAndUpdate",this._validate(),arguments.length){case 3:"function"==typeof r&&(n=r,r={});break;case 2:"function"==typeof e&&(n=e,e=t,t=void 0),r=void 0;break;case 1:"function"==typeof t?(n=t,t=r=e=void 0):(e=t,t=r=void 0)}return c.canMerge(t)&&this.merge(t),e&&this._mergeUpdate(e),r&&this.setOptions(r),n?this._findAndModify("update",n):this},c.prototype.findOneAndRemove=c.prototype.findOneAndDelete=function(t,e,r){return this.op="findOneAndRemove",this._validate(),"function"==typeof e?(r=e,e=void 0):"function"==typeof t&&(r=t,t=void 0),c.canMerge(t)&&this.merge(t),e&&this.setOptions(e),r?this._findAndModify("remove",r):this},c.prototype._findAndModify=function(t,e){o.equal("function",n(e));var r,i,s=this._optionsForExec();if("remove"==t)s.remove=!0;else if("new"in s||(s.new=!0),"upsert"in s||(s.upsert=!1),!(i=this._updateForExec())){if(!s.upsert)return this.findOne(e);i={$set:{}}}(r=this._fieldsForExec())&&(s.fields=r);var c=this._conditions;return u("findAndModify",this._collection.collectionName,c,i,s),e=this._wrapCallback("findAndModify",e,{conditions:c,doc:i,options:s}),this._collection.findAndModify(c,i,s,a.tick(e)),this},c.prototype._wrapCallback=function(t,e,r){var n=this._traceFunction||c.traceFunction;if(n){r.collectionName=this._collection.collectionName;var i=n&&n.call(null,t,r,this),o=(new Date).getTime();return function(t,r){if(i){var n=(new Date).getTime()-o;i.call(null,t,r,n)}e&&e.apply(null,arguments)}}return e},c.prototype.setTraceFunction=function(t){return this._traceFunction=t,this},c.prototype.exec=function(t,e){switch(n(t)){case"function":e=t,t=null;break;case"string":this.op=t}o.ok(this.op,"Missing query type: (find, update, etc)"),"update"!=this.op&&"remove"!=this.op||e||(e=!0);var r=this;if("function"!=typeof e)return new c.Promise(function(t,e){r[r.op](function(r,n){r?e(r):t(n),t=e=null})});this[this.op](e)},c.prototype.thunk=function(){var t=this;return function(e){t.exec(e)}},c.prototype.then=function(t,e){var r=this;return new c.Promise(function(t,e){r.exec(function(r,n){r?e(r):t(n),t=e=null})}).then(t,e)},c.prototype.stream=function(t){if("find"!=this.op)throw new Error("stream() is only available for find");var e=this._conditions,r=this._optionsForExec();return r.fields=this._fieldsForExec(),u("stream",this._collection.collectionName,e,r,t),this._collection.findStream(e,r,t)},c.prototype.selected=function(){return!!(this._fields&&Object.keys(this._fields).length>0)},c.prototype.selectedInclusively=function(){if(!this._fields)return!1;var t=Object.keys(this._fields);if(0===t.length)return!1;for(var e=0;e<t.length;++e){var r=t[e];if(0===this._fields[r])return!1;if(this._fields[r]&&"object"===n(this._fields[r])&&this._fields[r].$meta)return!1}return!0},c.prototype.selectedExclusively=function(){if(!this._fields)return!1;var t=Object.keys(this._fields);if(0===t.length)return!1;for(var e=0;e<t.length;++e){var r=t[e];if(0===this._fields[r])return!0}return!1},c.prototype._mergeUpdate=function(t){this._update||(this._update={}),t instanceof c?t._update&&a.mergeClone(this._update,t._update):a.mergeClone(this._update,t)},c.prototype._optionsForExec=function(){return a.clone(this.options)},c.prototype._fieldsForExec=function(){return a.clone(this._fields)},c.prototype._updateForExec=function(){for(var t=a.clone(this._update),e=a.keys(t),r=e.length,n={};r--;){var i=e[r];this.options.overwrite?n[i]=t[i]:"$"!==i[0]?(n.$set||(t.$set?n.$set=t.$set:n.$set={}),n.$set[i]=t[i],e.splice(r,1),~e.indexOf("$set")||e.push("$set")):"$set"===i&&n.$set||(n[i]=t[i])}return this._compiledUpdate=n,n},c.prototype._ensurePath=function(t){if(!this._path)throw new Error(t+"() must be used after where() when called with these arguments")},c.permissions=r(99),c._isPermitted=function(t,e){var r=c.permissions[e];return!r||!0!==r[t]},c.prototype._validate=function(t){var e,r;if(void 0===t){if("function"!=typeof(r=c.permissions[this.op]))return!0;e=r(this)}else c._isPermitted(t,this.op)||(e=t);if(e)throw new Error(e+" cannot be used with "+this.op)},c.canMerge=function(t){return t instanceof c||a.isObject(t)},c.setGlobalTraceFunction=function(t){c.traceFunction=t},c.utils=a,c.env=r(58),c.Collection=r(101),c.BaseCollection=r(20),c.Promise=r(103),t.exports=c},function(t,e,r){"use strict";(function(t,e){!function(t,r){if(!t.setImmediate){var n,i,o,s,a,u=1,c={},l=!1,f=t.document,h=Object.getPrototypeOf&&Object.getPrototypeOf(t);h=h&&h.setTimeout?h:t,"[object process]"==={}.toString.call(t.process)?n=function(t){e.nextTick(function(){d(t)})}:!function(){if(t.postMessage&&!t.importScripts){var e=!0,r=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=r,e}}()?t.MessageChannel?((o=new MessageChannel).port1.onmessage=function(t){d(t.data)},n=function(t){o.port2.postMessage(t)}):f&&"onreadystatechange"in f.createElement("script")?(i=f.documentElement,n=function(t){var e=f.createElement("script");e.onreadystatechange=function(){d(t),e.onreadystatechange=null,i.removeChild(e),e=null},i.appendChild(e)}):n=function(t){setTimeout(d,0,t)}:(s="setImmediate$"+Math.random()+"$",a=function(e){e.source===t&&"string"===typeof e.data&&0===e.data.indexOf(s)&&d(+e.data.slice(s.length))},t.addEventListener?t.addEventListener("message",a,!1):t.attachEvent("onmessage",a),n=function(e){t.postMessage(s+e,"*")}),h.setImmediate=function(t){"function"!==typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),r=0;r<e.length;r++)e[r]=arguments[r+1];var i={callback:t,args:e};return c[u]=i,n(u),u++},h.clearImmediate=p}function p(t){delete c[t]}function d(t){if(l)setTimeout(d,0,t);else{var e=c[t];if(e){l=!0;try{!function(t){var e=t.callback,n=t.args;switch(n.length){case 0:e();break;case 1:e(n[0]);break;case 2:e(n[0],n[1]);break;case 3:e(n[0],n[1],n[2]);break;default:e.apply(r,n)}}(e)}finally{p(t),l=!1}}}}}("undefined"===typeof self?"undefined"===typeof t?void 0:t:self)}).call(this,r(6),r(7))},function(t,e,r){"use strict";(function(n){function i(t){return(i="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(){var t;try{t=e.storage.debug}catch(t){}return!t&&"undefined"!==typeof n&&"env"in n&&(t=n.env.DEBUG),t}(e=t.exports=r(97)).log=function(){return"object"===("undefined"===typeof console?"undefined":i(console))&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},e.formatArgs=function(t){var r=this.useColors;if(t[0]=(r?"%c":"")+this.namespace+(r?" %c":" ")+t[0]+(r?"%c ":" ")+"+"+e.humanize(this.diff),!r)return;var n="color: "+this.color;t.splice(1,0,n,"color: inherit");var i=0,o=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&"%c"===t&&(o=++i)}),t.splice(o,0,n)},e.save=function(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(t){}},e.load=o,e.useColors=function(){if("undefined"!==typeof window&&window.process&&"renderer"===window.process.type)return!0;if("undefined"!==typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!==typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!==typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!==typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!==typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},e.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},e.enable(o())}).call(this,r(7))},function(t,e,r){"use strict";function n(t){var r;function n(){if(n.enabled){var t=n,i=+new Date,o=i-(r||i);t.diff=o,t.prev=r,t.curr=i,r=i;for(var s=new Array(arguments.length),a=0;a<s.length;a++)s[a]=arguments[a];s[0]=e.coerce(s[0]),"string"!==typeof s[0]&&s.unshift("%O");var u=0;s[0]=s[0].replace(/%([a-zA-Z%])/g,function(r,n){if("%%"===r)return r;u++;var i=e.formatters[n];if("function"===typeof i){var o=s[u];r=i.call(t,o),s.splice(u,1),u--}return r}),e.formatArgs.call(t,s),(n.log||e.log||console.log.bind(console)).apply(t,s)}}return n.namespace=t,n.enabled=e.enabled(t),n.useColors=e.useColors(),n.color=function(t){var r,n=0;for(r in t)n=(n<<5)-n+t.charCodeAt(r),n|=0;return e.colors[Math.abs(n)%e.colors.length]}(t),n.destroy=i,"function"===typeof e.init&&e.init(n),e.instances.push(n),n}function i(){var t=e.instances.indexOf(this);return-1!==t&&(e.instances.splice(t,1),!0)}(e=t.exports=n.debug=n.default=n).coerce=function(t){return t instanceof Error?t.stack||t.message:t},e.disable=function(){e.enable("")},e.enable=function(t){var r;e.save(t),e.names=[],e.skips=[];var n=("string"===typeof t?t:"").split(/[\s,]+/),i=n.length;for(r=0;r<i;r++)n[r]&&("-"===(t=n[r].replace(/\*/g,".*?"))[0]?e.skips.push(new RegExp("^"+t.substr(1)+"$")):e.names.push(new RegExp("^"+t+"$")));for(r=0;r<e.instances.length;r++){var o=e.instances[r];o.enabled=e.enabled(o.namespace)}},e.enabled=function(t){if("*"===t[t.length-1])return!0;var r,n;for(r=0,n=e.skips.length;r<n;r++)if(e.skips[r].test(t))return!1;for(r=0,n=e.names.length;r<n;r++)if(e.names[r].test(t))return!0;return!1},e.humanize=r(98),e.instances=[],e.names=[],e.skips=[],e.formatters={}},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=1e3,o=60*i,s=60*o,a=24*s,u=365.25*a;function c(t,e,r){if(!(t<e))return t<1.5*e?Math.floor(t/e)+" "+r:Math.ceil(t/e)+" "+r+"s"}t.exports=function(t,e){e=e||{};var r,l=n(t);if("string"===l&&t.length>0)return function(t){if((t=String(t)).length>100)return;var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(!e)return;var r=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return r*u;case"days":case"day":case"d":return r*a;case"hours":case"hour":case"hrs":case"hr":case"h":return r*s;case"minutes":case"minute":case"mins":case"min":case"m":return r*o;case"seconds":case"second":case"secs":case"sec":case"s":return r*i;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}(t);if("number"===l&&!1===isNaN(t))return e.long?c(r=t,a,"day")||c(r,s,"hour")||c(r,o,"minute")||c(r,i,"second")||r+" ms":function(t){if(t>=a)return Math.round(t/a)+"d";if(t>=s)return Math.round(t/s)+"h";if(t>=o)return Math.round(t/o)+"m";if(t>=i)return Math.round(t/i)+"s";return t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,r){"use strict";var n=e;n.distinct=function(t){return t._fields&&Object.keys(t._fields).length>0?"field selection and slice":(Object.keys(n.distinct).every(function(r){return!t.options[r]||(e=r,!1)}),e);var e},n.distinct.select=n.distinct.slice=n.distinct.sort=n.distinct.limit=n.distinct.skip=n.distinct.batchSize=n.distinct.comment=n.distinct.maxScan=n.distinct.snapshot=n.distinct.hint=n.distinct.tailable=!0,n.findOneAndUpdate=n.findOneAndRemove=function(t){var e;return Object.keys(n.findOneAndUpdate).every(function(r){return!t.options[r]||(e=r,!1)}),e},n.findOneAndUpdate.limit=n.findOneAndUpdate.skip=n.findOneAndUpdate.batchSize=n.findOneAndUpdate.maxScan=n.findOneAndUpdate.snapshot=n.findOneAndUpdate.hint=n.findOneAndUpdate.tailable=n.findOneAndUpdate.comment=!0,n.count=function(t){return t._fields&&Object.keys(t._fields).length>0?"field selection and slice":(Object.keys(n.count).every(function(r){return!t.options[r]||(e=r,!1)}),e);var e},n.count.slice=n.count.batchSize=n.count.comment=n.count.maxScan=n.count.snapshot=n.count.tailable=!0},function(t,e,r){"use strict";t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,r){"use strict";var n=r(58);if("unknown"==n.type)throw new Error("Unknown environment");t.exports=n.isNode?r(102):(n.isMongo,r(20))},function(t,e,r){"use strict";var n=r(20);function i(t){this.collection=t,this.collectionName=t.collectionName}r(55).inherits(i,n),i.prototype.find=function(t,e,r){this.collection.find(t,e,function(t,e){if(t)return r(t);try{e.toArray(r)}catch(t){r(t)}})},i.prototype.findOne=function(t,e,r){this.collection.findOne(t,e,r)},i.prototype.count=function(t,e,r){this.collection.count(t,e,r)},i.prototype.distinct=function(t,e,r,n){this.collection.distinct(t,e,r,n)},i.prototype.update=function(t,e,r,n){this.collection.update(t,e,r,n)},i.prototype.updateMany=function(t,e,r,n){this.collection.updateMany(t,e,r,n)},i.prototype.updateOne=function(t,e,r,n){this.collection.updateOne(t,e,r,n)},i.prototype.replaceOne=function(t,e,r,n){this.collection.replaceOne(t,e,r,n)},i.prototype.deleteOne=function(t,e,r){this.collection.deleteOne(t,e,r)},i.prototype.deleteMany=function(t,e,r){this.collection.deleteMany(t,e,r)},i.prototype.remove=function(t,e,r){this.collection.remove(t,e,r)},i.prototype.findAndModify=function(t,e,r,n){var i=Array.isArray(r.sort)?r.sort:[];this.collection.findAndModify(t,i,e,r,n)},i.prototype.findStream=function(t,e,r){return this.collection.find(t,e).stream(r)},i.prototype.findCursor=function(t,e){return this.collection.find(t,e)},t.exports=i},function(t,e,r){"use strict";(function(r,n,i){var o,s,a,u;function c(t){return(c="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)}u=function(){var t,e,o;return function t(e,r,n){function i(s,a){if(!r[s]){if(!e[s]){var u="function"==typeof _dereq_&&_dereq_;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[s]={exports:{}};e[s][0].call(l.exports,function(t){var r=e[s][1][t];return i(r||t)},l,l.exports,t,e,r,n)}return r[s].exports}for(var o="function"==typeof _dereq_&&_dereq_,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(t,e,r){e.exports=function(t){var e=t._SomePromiseArray;function r(t){var r=new e(t),n=r.promise();return r.setHowMany(1),r.setUnwrap(),r.init(),n}t.any=function(t){return r(t)},t.prototype.any=function(){return r(this)}}},{}],2:[function(t,e,n){var i;try{throw new Error}catch(t){i=t}var o=t("./schedule"),s=t("./queue"),a=t("./util");function u(){this._customScheduler=!1,this._isTickUsed=!1,this._lateQueue=new s(16),this._normalQueue=new s(16),this._haveDrainedQueues=!1,this._trampolineEnabled=!0;var t=this;this.drainQueues=function(){t._drainQueues()},this._schedule=o}function c(t,e,r){this._lateQueue.push(t,e,r),this._queueTick()}function l(t,e,r){this._normalQueue.push(t,e,r),this._queueTick()}function f(t){this._normalQueue._pushOne(t),this._queueTick()}u.prototype.setScheduler=function(t){var e=this._schedule;return this._schedule=t,this._customScheduler=!0,e},u.prototype.hasCustomScheduler=function(){return this._customScheduler},u.prototype.enableTrampoline=function(){this._trampolineEnabled=!0},u.prototype.disableTrampolineIfNecessary=function(){a.hasDevTools&&(this._trampolineEnabled=!1)},u.prototype.haveItemsQueued=function(){return this._isTickUsed||this._haveDrainedQueues},u.prototype.fatalError=function(t,e){e?(r.stderr.write("Fatal "+(t instanceof Error?t.stack:t)+"\n"),r.exit(2)):this.throwLater(t)},u.prototype.throwLater=function(t,e){if(1===arguments.length&&(e=t,t=function(){throw e}),"undefined"!==typeof setTimeout)setTimeout(function(){t(e)},0);else try{this._schedule(function(){t(e)})}catch(t){throw new Error("No async scheduler available\n\n See http://goo.gl/MqrFmX\n")}},a.hasDevTools?(u.prototype.invokeLater=function(t,e,r){this._trampolineEnabled?c.call(this,t,e,r):this._schedule(function(){setTimeout(function(){t.call(e,r)},100)})},u.prototype.invoke=function(t,e,r){this._trampolineEnabled?l.call(this,t,e,r):this._schedule(function(){t.call(e,r)})},u.prototype.settlePromises=function(t){this._trampolineEnabled?f.call(this,t):this._schedule(function(){t._settlePromises()})}):(u.prototype.invokeLater=c,u.prototype.invoke=l,u.prototype.settlePromises=f),u.prototype._drainQueue=function(t){for(;t.length()>0;){var e=t.shift();if("function"===typeof e){var r=t.shift(),n=t.shift();e.call(r,n)}else e._settlePromises()}},u.prototype._drainQueues=function(){this._drainQueue(this._normalQueue),this._reset(),this._haveDrainedQueues=!0,this._drainQueue(this._lateQueue)},u.prototype._queueTick=function(){this._isTickUsed||(this._isTickUsed=!0,this._schedule(this.drainQueues))},u.prototype._reset=function(){this._isTickUsed=!1},e.exports=u,e.exports.firstLineError=i},{"./queue":26,"./schedule":29,"./util":36}],3:[function(t,e,r){e.exports=function(t,e,r,n){var i=!1,o=function(t,e){this._reject(e)},s=function(t,e){e.promiseRejectionQueued=!0,e.bindingPromise._then(o,o,null,this,t)},a=function(t,e){0===(50397184&this._bitField)&&this._resolveCallback(e.target)},u=function(t,e){e.promiseRejectionQueued||this._reject(t)};t.prototype.bind=function(o){i||(i=!0,t.prototype._propagateFrom=n.propagateFromFunction(),t.prototype._boundValue=n.boundValueFunction());var c=r(o),l=new t(e);l._propagateFrom(this,1);var f=this._target();if(l._setBoundTo(c),c instanceof t){var h={promiseRejectionQueued:!1,promise:l,target:f,bindingPromise:c};f._then(e,s,void 0,l,h),c._then(a,u,void 0,l,h),l._setOnCancel(c)}else l._resolveCallback(f);return l},t.prototype._setBoundTo=function(t){void 0!==t?(this._bitField=2097152|this._bitField,this._boundTo=t):this._bitField=-2097153&this._bitField},t.prototype._isBound=function(){return 2097152===(2097152&this._bitField)},t.bind=function(e,r){return t.resolve(r).bind(e)}}},{}],4:[function(t,e,r){var n;"undefined"!==typeof Promise&&(n=Promise);var i=t("./promise")();i.noConflict=function(){try{Promise===i&&(Promise=n)}catch(t){}return i},e.exports=i},{"./promise":22}],5:[function(t,e,r){var n=Object.create;if(n){var i=n(null),o=n(null);i[" size"]=o[" size"]=0}e.exports=function(e){var r=t("./util"),n=r.canEvaluate;r.isIdentifier;function i(t){return function(t,n){var i;if(null!=t&&(i=t[n]),"function"!==typeof i){var o="Object "+r.classString(t)+" has no method '"+r.toString(n)+"'";throw new e.TypeError(o)}return i}(t,this.pop()).apply(t,this)}function o(t){return t[this]}function s(t){var e=+this;return e<0&&(e=Math.max(0,e+t.length)),t[e]}e.prototype.call=function(t){var e=[].slice.call(arguments,1);return e.push(t),this._then(i,void 0,void 0,e,void 0)},e.prototype.get=function(t){var e;if("number"===typeof t)e=s;else if(n){var r=(void 0)(t);e=null!==r?r:o}else e=o;return this._then(e,void 0,void 0,t,void 0)}}},{"./util":36}],6:[function(t,e,r){e.exports=function(e,r,n,i){var o=t("./util"),s=o.tryCatch,a=o.errorObj,u=e._async;e.prototype.break=e.prototype.cancel=function(){if(!i.cancellation())return this._warn("cancellation is disabled");for(var t=this,e=t;t._isCancellable();){if(!t._cancelBy(e)){e._isFollowing()?e._followee().cancel():e._cancelBranched();break}var r=t._cancellationParent;if(null==r||!r._isCancellable()){t._isFollowing()?t._followee().cancel():t._cancelBranched();break}t._isFollowing()&&t._followee().cancel(),t._setWillBeCancelled(),e=t,t=r}},e.prototype._branchHasCancelled=function(){this._branchesRemainingToCancel--},e.prototype._enoughBranchesHaveCancelled=function(){return void 0===this._branchesRemainingToCancel||this._branchesRemainingToCancel<=0},e.prototype._cancelBy=function(t){return t===this?(this._branchesRemainingToCancel=0,this._invokeOnCancel(),!0):(this._branchHasCancelled(),!!this._enoughBranchesHaveCancelled()&&(this._invokeOnCancel(),!0))},e.prototype._cancelBranched=function(){this._enoughBranchesHaveCancelled()&&this._cancel()},e.prototype._cancel=function(){this._isCancellable()&&(this._setCancelled(),u.invoke(this._cancelPromises,this,void 0))},e.prototype._cancelPromises=function(){this._length()>0&&this._settlePromises()},e.prototype._unsetOnCancel=function(){this._onCancelField=void 0},e.prototype._isCancellable=function(){return this.isPending()&&!this._isCancelled()},e.prototype.isCancellable=function(){return this.isPending()&&!this.isCancelled()},e.prototype._doInvokeOnCancel=function(t,e){if(o.isArray(t))for(var r=0;r<t.length;++r)this._doInvokeOnCancel(t[r],e);else if(void 0!==t)if("function"===typeof t){if(!e){var n=s(t).call(this._boundValue());n===a&&(this._attachExtraTrace(n.e),u.throwLater(n.e))}}else t._resultCancelled(this)},e.prototype._invokeOnCancel=function(){var t=this._onCancel();this._unsetOnCancel(),u.invoke(this._doInvokeOnCancel,this,t)},e.prototype._invokeInternalOnCancel=function(){this._isCancellable()&&(this._doInvokeOnCancel(this._onCancel(),!0),this._unsetOnCancel())},e.prototype._resultCancelled=function(){this.cancel()}}},{"./util":36}],7:[function(t,e,r){e.exports=function(e){var r=t("./util"),n=t("./es5").keys,i=r.tryCatch,o=r.errorObj;return function(t,s,a){return function(u){var c=a._boundValue();t:for(var l=0;l<t.length;++l){var f=t[l];if(f===Error||null!=f&&f.prototype instanceof Error){if(u instanceof f)return i(s).call(c,u)}else if("function"===typeof f){var h=i(f).call(c,u);if(h===o)return h;if(h)return i(s).call(c,u)}else if(r.isObject(u)){for(var p=n(f),d=0;d<p.length;++d){var y=p[d];if(f[y]!=u[y])continue t}return i(s).call(c,u)}}return e}}}},{"./es5":13,"./util":36}],8:[function(t,e,r){e.exports=function(t){var e=!1,r=[];function n(){this._trace=new n.CapturedTrace(i())}function i(){var t=r.length-1;if(t>=0)return r[t]}return t.prototype._promiseCreated=function(){},t.prototype._pushContext=function(){},t.prototype._popContext=function(){return null},t._peekContext=t.prototype._peekContext=function(){},n.prototype._pushContext=function(){void 0!==this._trace&&(this._trace._promiseCreated=null,r.push(this._trace))},n.prototype._popContext=function(){if(void 0!==this._trace){var t=r.pop(),e=t._promiseCreated;return t._promiseCreated=null,e}return null},n.CapturedTrace=null,n.create=function(){if(e)return new n},n.deactivateLongStackTraces=function(){},n.activateLongStackTraces=function(){var r=t.prototype._pushContext,o=t.prototype._popContext,s=t._peekContext,a=t.prototype._peekContext,u=t.prototype._promiseCreated;n.deactivateLongStackTraces=function(){t.prototype._pushContext=r,t.prototype._popContext=o,t._peekContext=s,t.prototype._peekContext=a,t.prototype._promiseCreated=u,e=!1},e=!0,t.prototype._pushContext=n.prototype._pushContext,t.prototype._popContext=n.prototype._popContext,t._peekContext=t.prototype._peekContext=i,t.prototype._promiseCreated=function(){var t=this._peekContext();t&&null==t._promiseCreated&&(t._promiseCreated=this)}},n}},{}],9:[function(t,e,n){e.exports=function(e,n){var i,o,s,a=e._getDomain,u=e._async,l=t("./errors").Warning,f=t("./util"),h=f.canAttachTrace,p=/[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/,d=/\((?:timers\.js):\d+:\d+\)/,y=/[\/<\(](.+?):(\d+):(\d+)\)?\s*$/,_=null,m=null,v=!1,g=!(0==f.env("BLUEBIRD_DEBUG")),b=!(0==f.env("BLUEBIRD_WARNINGS")||!g&&!f.env("BLUEBIRD_WARNINGS")),w=!(0==f.env("BLUEBIRD_LONG_STACK_TRACES")||!g&&!f.env("BLUEBIRD_LONG_STACK_TRACES")),O=0!=f.env("BLUEBIRD_W_FORGOTTEN_RETURN")&&(b||!!f.env("BLUEBIRD_W_FORGOTTEN_RETURN"));e.prototype.suppressUnhandledRejections=function(){var t=this._target();t._bitField=-1048577&t._bitField|524288},e.prototype._ensurePossibleRejectionHandled=function(){if(0===(524288&this._bitField)){this._setRejectionIsUnhandled();var t=this;setTimeout(function(){t._notifyUnhandledRejection()},1)}},e.prototype._notifyUnhandledRejectionIsHandled=function(){W("rejectionHandled",i,void 0,this)},e.prototype._setReturnedNonUndefined=function(){this._bitField=268435456|this._bitField},e.prototype._returnedNonUndefined=function(){return 0!==(268435456&this._bitField)},e.prototype._notifyUnhandledRejection=function(){if(this._isRejectionUnhandled()){var t=this._settledValue();this._setUnhandledRejectionIsNotified(),W("unhandledRejection",o,t,this)}},e.prototype._setUnhandledRejectionIsNotified=function(){this._bitField=262144|this._bitField},e.prototype._unsetUnhandledRejectionIsNotified=function(){this._bitField=-262145&this._bitField},e.prototype._isUnhandledRejectionNotified=function(){return(262144&this._bitField)>0},e.prototype._setRejectionIsUnhandled=function(){this._bitField=1048576|this._bitField},e.prototype._unsetRejectionIsUnhandled=function(){this._bitField=-1048577&this._bitField,this._isUnhandledRejectionNotified()&&(this._unsetUnhandledRejectionIsNotified(),this._notifyUnhandledRejectionIsHandled())},e.prototype._isRejectionUnhandled=function(){return(1048576&this._bitField)>0},e.prototype._warn=function(t,e,r){return L(t,e,r||this)},e.onPossiblyUnhandledRejection=function(t){var e=a();o="function"===typeof t?null===e?t:f.domainBind(e,t):void 0},e.onUnhandledRejectionHandled=function(t){var e=a();i="function"===typeof t?null===e?t:f.domainBind(e,t):void 0};var S=function(){};e.longStackTraces=function(){if(u.haveItemsQueued()&&!X.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");if(!X.longStackTraces&&Y()){var t=e.prototype._captureStackTrace,r=e.prototype._attachExtraTrace;X.longStackTraces=!0,S=function(){if(u.haveItemsQueued()&&!X.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");e.prototype._captureStackTrace=t,e.prototype._attachExtraTrace=r,n.deactivateLongStackTraces(),u.enableTrampoline(),X.longStackTraces=!1},e.prototype._captureStackTrace=F,e.prototype._attachExtraTrace=I,n.activateLongStackTraces(),u.disableTrampolineIfNecessary()}},e.hasLongStackTraces=function(){return X.longStackTraces&&Y()};var E=function(){try{if("function"===typeof CustomEvent){var t=new CustomEvent("CustomEvent");return f.global.dispatchEvent(t),function(t,e){var r=new CustomEvent(t.toLowerCase(),{detail:e,cancelable:!0});return!f.global.dispatchEvent(r)}}if("function"===typeof Event){t=new Event("CustomEvent");return f.global.dispatchEvent(t),function(t,e){var r=new Event(t.toLowerCase(),{cancelable:!0});return r.detail=e,!f.global.dispatchEvent(r)}}return(t=document.createEvent("CustomEvent")).initCustomEvent("testingtheevent",!1,!0,{}),f.global.dispatchEvent(t),function(t,e){var r=document.createEvent("CustomEvent");return r.initCustomEvent(t.toLowerCase(),!1,!0,e),!f.global.dispatchEvent(r)}}catch(t){}return function(){return!1}}(),A=f.isNode?function(){return r.emit.apply(r,arguments)}:f.global?function(t){var e="on"+t.toLowerCase(),r=f.global[e];return!!r&&(r.apply(f.global,[].slice.call(arguments,1)),!0)}:function(){return!1};function $(t,e){return{promise:e}}var N={promiseCreated:$,promiseFulfilled:$,promiseRejected:$,promiseResolved:$,promiseCancelled:$,promiseChained:function(t,e,r){return{promise:e,child:r}},warning:function(t,e){return{warning:e}},unhandledRejection:function(t,e,r){return{reason:e,promise:r}},rejectionHandled:$},j=function(t){var e=!1;try{e=A.apply(null,arguments)}catch(t){u.throwLater(t),e=!0}var r=!1;try{r=E(t,N[t].apply(null,arguments))}catch(t){u.throwLater(t),r=!0}return r||e};function x(){return!1}function T(t,e,r){var n=this;try{t(e,r,function(t){if("function"!==typeof t)throw new TypeError("onCancel must be a function, got: "+f.toString(t));n._attachCancellationCallback(t)})}catch(t){return t}}function B(t){if(!this._isCancellable())return this;var e=this._onCancel();void 0!==e?f.isArray(e)?e.push(t):this._setOnCancel([e,t]):this._setOnCancel(t)}function k(){return this._onCancelField}function C(t){this._onCancelField=t}function D(){this._cancellationParent=void 0,this._onCancelField=void 0}function P(t,e){if(0!==(1&e)){this._cancellationParent=t;var r=t._branchesRemainingToCancel;void 0===r&&(r=0),t._branchesRemainingToCancel=r+1}0!==(2&e)&&t._isBound()&&this._setBoundTo(t._boundTo)}e.config=function(t){if("longStackTraces"in(t=Object(t))&&(t.longStackTraces?e.longStackTraces():!t.longStackTraces&&e.hasLongStackTraces()&&S()),"warnings"in t){var r=t.warnings;X.warnings=!!r,O=X.warnings,f.isObject(r)&&"wForgottenReturn"in r&&(O=!!r.wForgottenReturn)}if("cancellation"in t&&t.cancellation&&!X.cancellation){if(u.haveItemsQueued())throw new Error("cannot enable cancellation after promises are in use");e.prototype._clearCancellationData=D,e.prototype._propagateFrom=P,e.prototype._onCancel=k,e.prototype._setOnCancel=C,e.prototype._attachCancellationCallback=B,e.prototype._execute=T,M=P,X.cancellation=!0}return"monitoring"in t&&(t.monitoring&&!X.monitoring?(X.monitoring=!0,e.prototype._fireEvent=j):!t.monitoring&&X.monitoring&&(X.monitoring=!1,e.prototype._fireEvent=x)),e},e.prototype._fireEvent=x,e.prototype._execute=function(t,e,r){try{t(e,r)}catch(t){return t}},e.prototype._onCancel=function(){},e.prototype._setOnCancel=function(t){},e.prototype._attachCancellationCallback=function(t){},e.prototype._captureStackTrace=function(){},e.prototype._attachExtraTrace=function(){},e.prototype._clearCancellationData=function(){},e.prototype._propagateFrom=function(t,e){};var M=function(t,e){0!==(2&e)&&t._isBound()&&this._setBoundTo(t._boundTo)};function R(){var t=this._boundTo;return void 0!==t&&t instanceof e?t.isFulfilled()?t.value():void 0:t}function F(){this._trace=new J(this._peekContext())}function I(t,e){if(h(t)){var r=this._trace;if(void 0!==r&&e&&(r=r._parent),void 0!==r)r.attachExtraTrace(t);else if(!t.__stackCleaned__){var n=V(t);f.notEnumerableProp(t,"stack",n.message+"\n"+n.stack.join("\n")),f.notEnumerableProp(t,"__stackCleaned__",!0)}}}function L(t,r,n){if(X.warnings){var i,o=new l(t);if(r)n._attachExtraTrace(o);else if(X.longStackTraces&&(i=e._peekContext()))i.attachExtraTrace(o);else{var s=V(o);o.stack=s.message+"\n"+s.stack.join("\n")}j("warning",o)||q(o,"",!0)}}function U(t){for(var e=[],r=0;r<t.length;++r){var n=t[r],i=" (No stack trace)"===n||_.test(n),o=i&&z(n);i&&!o&&(v&&" "!==n.charAt(0)&&(n=" "+n),e.push(n))}return e}function V(t){var e=t.stack,r=t.toString();return e="string"===typeof e&&e.length>0?function(t){for(var e=t.stack.replace(/\s+$/g,"").split("\n"),r=0;r<e.length;++r){var n=e[r];if(" (No stack trace)"===n||_.test(n))break}return r>0&&"SyntaxError"!=t.name&&(e=e.slice(r)),e}(t):[" (No stack trace)"],{message:r,stack:"SyntaxError"==t.name?e:U(e)}}function q(t,e,r){if("undefined"!==typeof console){var n;if(f.isObject(t)){var i=t.stack;n=e+m(i,t)}else n=e+String(t);"function"===typeof s?s(n,r):"function"!==typeof console.log&&"object"!==c(console.log)||console.log(n)}}function W(t,e,r,n){var i=!1;try{"function"===typeof e&&(i=!0,"rejectionHandled"===t?e(n):e(r,n))}catch(t){u.throwLater(t)}"unhandledRejection"===t?j(t,r,n)||i||q(r,"Unhandled rejection "):j(t,n)}function H(t){var e;if("function"===typeof t)e="[function "+(t.name||"anonymous")+"]";else{e=t&&"function"===typeof t.toString?t.toString():f.toString(t);if(/\[object [a-zA-Z0-9$_]+\]/.test(e))try{e=JSON.stringify(t)}catch(t){}0===e.length&&(e="(empty array)")}return"(<"+function(t){if(t.length<41)return t;return t.substr(0,38)+"..."}(e)+">, no stack trace)"}function Y(){return"function"===typeof G}var z=function(){return!1},K=/[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;function Q(t){var e=t.match(K);if(e)return{fileName:e[1],line:parseInt(e[2],10)}}function J(t){this._parent=t,this._promisesCreated=0;var e=this._length=1+(void 0===t?0:t._length);G(this,J),e>32&&this.uncycle()}f.inherits(J,Error),n.CapturedTrace=J,J.prototype.uncycle=function(){var t=this._length;if(!(t<2)){for(var e=[],r={},n=0,i=this;void 0!==i;++n)e.push(i),i=i._parent;for(n=(t=this._length=n)-1;n>=0;--n){var o=e[n].stack;void 0===r[o]&&(r[o]=n)}for(n=0;n<t;++n){var s=r[e[n].stack];if(void 0!==s&&s!==n){s>0&&(e[s-1]._parent=void 0,e[s-1]._length=1),e[n]._parent=void 0,e[n]._length=1;var a=n>0?e[n-1]:this;s<t-1?(a._parent=e[s+1],a._parent.uncycle(),a._length=a._parent._length+1):(a._parent=void 0,a._length=1);for(var u=a._length+1,c=n-2;c>=0;--c)e[c]._length=u,u++;return}}}},J.prototype.attachExtraTrace=function(t){if(!t.__stackCleaned__){this.uncycle();for(var e=V(t),r=e.message,n=[e.stack],i=this;void 0!==i;)n.push(U(i.stack.split("\n"))),i=i._parent;!function(t){for(var e=t[0],r=1;r<t.length;++r){for(var n=t[r],i=e.length-1,o=e[i],s=-1,a=n.length-1;a>=0;--a)if(n[a]===o){s=a;break}for(a=s;a>=0;--a){var u=n[a];if(e[i]!==u)break;e.pop(),i--}e=n}}(n),function(t){for(var e=0;e<t.length;++e)(0===t[e].length||e+1<t.length&&t[e][0]===t[e+1][0])&&(t.splice(e,1),e--)}(n),f.notEnumerableProp(t,"stack",function(t,e){for(var r=0;r<e.length-1;++r)e[r].push("From previous event:"),e[r]=e[r].join("\n");return r<e.length&&(e[r]=e[r].join("\n")),t+"\n"+e.join("\n")}(r,n)),f.notEnumerableProp(t,"__stackCleaned__",!0)}};var G=function(){var t=/^\s*at\s*/,e=function(t,e){return"string"===typeof t?t:void 0!==e.name&&void 0!==e.message?e.toString():H(e)};if("number"===typeof Error.stackTraceLimit&&"function"===typeof Error.captureStackTrace){Error.stackTraceLimit+=6,_=t,m=e;var r=Error.captureStackTrace;return z=function(t){return p.test(t)},function(t,e){Error.stackTraceLimit+=6,r(t,e),Error.stackTraceLimit-=6}}var n,i=new Error;if("string"===typeof i.stack&&i.stack.split("\n")[0].indexOf("stackDetection@")>=0)return _=/@/,m=e,v=!0,function(t){t.stack=(new Error).stack};try{throw new Error}catch(t){n="stack"in t}return"stack"in i||!n||"number"!==typeof Error.stackTraceLimit?(m=function(t,e){return"string"===typeof t?t:"object"!==c(e)&&"function"!==typeof e||void 0===e.name||void 0===e.message?H(e):e.toString()},null):(_=t,m=e,function(t){Error.stackTraceLimit+=6;try{throw new Error}catch(e){t.stack=e.stack}Error.stackTraceLimit-=6})}();"undefined"!==typeof console&&"undefined"!==typeof console.warn&&(s=function(t){console.warn(t)},f.isNode&&r.stderr.isTTY?s=function(t,e){var r=e?"\x1b[33m":"\x1b[31m";console.warn(r+t+"\x1b[0m\n")}:f.isNode||"string"!==typeof(new Error).stack||(s=function(t,e){console.warn("%c"+t,e?"color: darkorange":"color: red")}));var X={warnings:b,longStackTraces:!1,cancellation:!1,monitoring:!1};return w&&e.longStackTraces(),{longStackTraces:function(){return X.longStackTraces},warnings:function(){return X.warnings},cancellation:function(){return X.cancellation},monitoring:function(){return X.monitoring},propagateFromFunction:function(){return M},boundValueFunction:function(){return R},checkForgottenReturns:function(t,e,r,n,i){if(void 0===t&&null!==e&&O){if(void 0!==i&&i._returnedNonUndefined())return;if(0===(65535&n._bitField))return;r&&(r+=" ");var o="",s="";if(e._trace){for(var a=e._trace.stack.split("\n"),u=U(a),c=u.length-1;c>=0;--c){var l=u[c];if(!d.test(l)){var f=l.match(y);f&&(o="at "+f[1]+":"+f[2]+":"+f[3]+" ");break}}if(u.length>0){var h=u[0];for(c=0;c<a.length;++c)if(a[c]===h){c>0&&(s="\n"+a[c-1]);break}}}var p="a promise was created in a "+r+"handler "+o+"but was not returned from it, see http://goo.gl/rRqMUw"+s;n._warn(p,!0,e)}},setBounds:function(t,e){if(Y()){for(var r,n,i=t.stack.split("\n"),o=e.stack.split("\n"),s=-1,a=-1,u=0;u<i.length;++u)if(c=Q(i[u])){r=c.fileName,s=c.line;break}for(u=0;u<o.length;++u){var c;if(c=Q(o[u])){n=c.fileName,a=c.line;break}}s<0||a<0||!r||!n||r!==n||s>=a||(z=function(t){if(p.test(t))return!0;var e=Q(t);return!!(e&&e.fileName===r&&s<=e.line&&e.line<=a)})}},warn:L,deprecated:function(t,e){var r=t+" is deprecated and will be removed in a future version.";return e&&(r+=" Use "+e+" instead."),L(r)},CapturedTrace:J,fireDomEvent:E,fireGlobalEvent:A}}},{"./errors":12,"./util":36}],10:[function(t,e,r){e.exports=function(t){function e(){return this.value}function r(){throw this.reason}t.prototype.return=t.prototype.thenReturn=function(r){return r instanceof t&&r.suppressUnhandledRejections(),this._then(e,void 0,void 0,{value:r},void 0)},t.prototype.throw=t.prototype.thenThrow=function(t){return this._then(r,void 0,void 0,{reason:t},void 0)},t.prototype.catchThrow=function(t){if(arguments.length<=1)return this._then(void 0,r,void 0,{reason:t},void 0);var e=arguments[1];return this.caught(t,function(){throw e})},t.prototype.catchReturn=function(r){if(arguments.length<=1)return r instanceof t&&r.suppressUnhandledRejections(),this._then(void 0,e,void 0,{value:r},void 0);var n=arguments[1];n instanceof t&&n.suppressUnhandledRejections();return this.caught(r,function(){return n})}}},{}],11:[function(t,e,r){e.exports=function(t,e){var r=t.reduce,n=t.all;function i(){return n(this)}t.prototype.each=function(t){return r(this,t,e,0)._then(i,void 0,void 0,this,void 0)},t.prototype.mapSeries=function(t){return r(this,t,e,e)},t.each=function(t,n){return r(t,n,e,0)._then(i,void 0,void 0,t,void 0)},t.mapSeries=function(t,n){return r(t,n,e,e)}}},{}],12:[function(t,e,r){var n,i,o=t("./es5"),s=o.freeze,a=t("./util"),u=a.inherits,c=a.notEnumerableProp;function l(t,e){function r(n){if(!(this instanceof r))return new r(n);c(this,"message","string"===typeof n?n:e),c(this,"name",t),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):Error.call(this)}return u(r,Error),r}var f=l("Warning","warning"),h=l("CancellationError","cancellation error"),p=l("TimeoutError","timeout error"),d=l("AggregateError","aggregate error");try{n=TypeError,i=RangeError}catch(t){n=l("TypeError","type error"),i=l("RangeError","range error")}for(var y="join pop push shift unshift slice filter forEach some every map indexOf lastIndexOf reduce reduceRight sort reverse".split(" "),_=0;_<y.length;++_)"function"===typeof Array.prototype[y[_]]&&(d.prototype[y[_]]=Array.prototype[y[_]]);o.defineProperty(d.prototype,"length",{value:0,configurable:!1,writable:!0,enumerable:!0}),d.prototype.isOperational=!0;var m=0;function v(t){if(!(this instanceof v))return new v(t);c(this,"name","OperationalError"),c(this,"message",t),this.cause=t,this.isOperational=!0,t instanceof Error?(c(this,"message",t.message),c(this,"stack",t.stack)):Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}d.prototype.toString=function(){var t=Array(4*m+1).join(" "),e="\n"+t+"AggregateError of:\n";m++,t=Array(4*m+1).join(" ");for(var r=0;r<this.length;++r){for(var n=this[r]===this?"[Circular AggregateError]":this[r]+"",i=n.split("\n"),o=0;o<i.length;++o)i[o]=t+i[o];e+=(n=i.join("\n"))+"\n"}return m--,e},u(v,Error);var g=Error.__BluebirdErrorTypes__;g||(g=s({CancellationError:h,TimeoutError:p,OperationalError:v,RejectionError:v,AggregateError:d}),o.defineProperty(Error,"__BluebirdErrorTypes__",{value:g,writable:!1,enumerable:!1,configurable:!1})),e.exports={Error:Error,TypeError:n,RangeError:i,CancellationError:g.CancellationError,OperationalError:g.OperationalError,TimeoutError:g.TimeoutError,AggregateError:g.AggregateError,Warning:f}},{"./es5":13,"./util":36}],13:[function(t,e,r){var n=function(){return void 0===this}();if(n)e.exports={freeze:Object.freeze,defineProperty:Object.defineProperty,getDescriptor:Object.getOwnPropertyDescriptor,keys:Object.keys,names:Object.getOwnPropertyNames,getPrototypeOf:Object.getPrototypeOf,isArray:Array.isArray,isES5:n,propertyIsWritable:function(t,e){var r=Object.getOwnPropertyDescriptor(t,e);return!(r&&!r.writable&&!r.set)}};else{var i={}.hasOwnProperty,o={}.toString,s={}.constructor.prototype,a=function(t){var e=[];for(var r in t)i.call(t,r)&&e.push(r);return e};e.exports={isArray:function(t){try{return"[object Array]"===o.call(t)}catch(t){return!1}},keys:a,names:a,defineProperty:function(t,e,r){return t[e]=r.value,t},getDescriptor:function(t,e){return{value:t[e]}},freeze:function(t){return t},getPrototypeOf:function(t){try{return Object(t).constructor.prototype}catch(t){return s}},isES5:n,propertyIsWritable:function(){return!0}}}},{}],14:[function(t,e,r){e.exports=function(t,e){var r=t.map;t.prototype.filter=function(t,n){return r(this,t,n,e)},t.filter=function(t,n,i){return r(t,n,i,e)}}},{}],15:[function(t,e,r){e.exports=function(e,r,n){var i=t("./util"),o=e.CancellationError,s=i.errorObj,a=t("./catch_filter")(n);function u(t,e,r){this.promise=t,this.type=e,this.handler=r,this.called=!1,this.cancelPromise=null}function c(t){this.finallyHandler=t}function l(t,e){return null!=t.cancelPromise&&(arguments.length>1?t.cancelPromise._reject(e):t.cancelPromise._cancel(),t.cancelPromise=null,!0)}function f(){return p.call(this,this.promise._target()._settledValue())}function h(t){if(!l(this,t))return s.e=t,s}function p(t){var i=this.promise,a=this.handler;if(!this.called){this.called=!0;var u=this.isFinallyHandler()?a.call(i._boundValue()):a.call(i._boundValue(),t);if(u===n)return u;if(void 0!==u){i._setReturnedNonUndefined();var p=r(u,i);if(p instanceof e){if(null!=this.cancelPromise){if(p._isCancelled()){var d=new o("late cancellation observer");return i._attachExtraTrace(d),s.e=d,s}p.isPending()&&p._attachCancellationCallback(new c(this))}return p._then(f,h,void 0,this,void 0)}}}return i.isRejected()?(l(this),s.e=t,s):(l(this),t)}return u.prototype.isFinallyHandler=function(){return 0===this.type},c.prototype._resultCancelled=function(){l(this.finallyHandler)},e.prototype._passThrough=function(t,e,r,n){return"function"!==typeof t?this.then():this._then(r,n,void 0,new u(this,e,t),void 0)},e.prototype.lastly=e.prototype.finally=function(t){return this._passThrough(t,0,p,p)},e.prototype.tap=function(t){return this._passThrough(t,1,p)},e.prototype.tapCatch=function(t){var r=arguments.length;if(1===r)return this._passThrough(t,1,void 0,p);var n,o=new Array(r-1),s=0;for(n=0;n<r-1;++n){var u=arguments[n];if(!i.isObject(u))return e.reject(new TypeError("tapCatch statement predicate: expecting an object but got "+i.classString(u)));o[s++]=u}o.length=s;var c=arguments[n];return this._passThrough(a(o,c,this),1,void 0,p)},u}},{"./catch_filter":7,"./util":36}],16:[function(t,e,r){e.exports=function(e,r,n,i,o,s){var a=t("./errors").TypeError,u=t("./util"),c=u.errorObj,l=u.tryCatch,f=[];function h(t,r,i,o){if(s.cancellation()){var a=new e(n),u=this._finallyPromise=new e(n);this._promise=a.lastly(function(){return u}),a._captureStackTrace(),a._setOnCancel(this)}else{(this._promise=new e(n))._captureStackTrace()}this._stack=o,this._generatorFunction=t,this._receiver=r,this._generator=void 0,this._yieldHandlers="function"===typeof i?[i].concat(f):f,this._yieldedPromise=null,this._cancellationPhase=!1}u.inherits(h,o),h.prototype._isResolved=function(){return null===this._promise},h.prototype._cleanup=function(){this._promise=this._generator=null,s.cancellation()&&null!==this._finallyPromise&&(this._finallyPromise._fulfill(),this._finallyPromise=null)},h.prototype._promiseCancelled=function(){if(!this._isResolved()){var t;if("undefined"!==typeof this._generator.return)this._promise._pushContext(),t=l(this._generator.return).call(this._generator,void 0),this._promise._popContext();else{var r=new e.CancellationError("generator .return() sentinel");e.coroutine.returnSentinel=r,this._promise._attachExtraTrace(r),this._promise._pushContext(),t=l(this._generator.throw).call(this._generator,r),this._promise._popContext()}this._cancellationPhase=!0,this._yieldedPromise=null,this._continue(t)}},h.prototype._promiseFulfilled=function(t){this._yieldedPromise=null,this._promise._pushContext();var e=l(this._generator.next).call(this._generator,t);this._promise._popContext(),this._continue(e)},h.prototype._promiseRejected=function(t){this._yieldedPromise=null,this._promise._attachExtraTrace(t),this._promise._pushContext();var e=l(this._generator.throw).call(this._generator,t);this._promise._popContext(),this._continue(e)},h.prototype._resultCancelled=function(){if(this._yieldedPromise instanceof e){var t=this._yieldedPromise;this._yieldedPromise=null,t.cancel()}},h.prototype.promise=function(){return this._promise},h.prototype._run=function(){this._generator=this._generatorFunction.call(this._receiver),this._receiver=this._generatorFunction=void 0,this._promiseFulfilled(void 0)},h.prototype._continue=function(t){var r=this._promise;if(t===c)return this._cleanup(),this._cancellationPhase?r.cancel():r._rejectCallback(t.e,!1);var n=t.value;if(!0===t.done)return this._cleanup(),this._cancellationPhase?r.cancel():r._resolveCallback(n);var o=i(n,this._promise);if(o instanceof e||null!==(o=function(t,r,n){for(var o=0;o<r.length;++o){n._pushContext();var s=l(r[o])(t);if(n._popContext(),s===c){n._pushContext();var a=e.reject(c.e);return n._popContext(),a}var u=i(s,n);if(u instanceof e)return u}return null}(o,this._yieldHandlers,this._promise))){var s=(o=o._target())._bitField;0===(50397184&s)?(this._yieldedPromise=o,o._proxy(this,null)):0!==(33554432&s)?e._async.invoke(this._promiseFulfilled,this,o._value()):0!==(16777216&s)?e._async.invoke(this._promiseRejected,this,o._reason()):this._promiseCancelled()}else this._promiseRejected(new a("A value %s was yielded that could not be treated as a promise\n\n See http://goo.gl/MqrFmX\n\n".replace("%s",String(n))+"From coroutine:\n"+this._stack.split("\n").slice(1,-7).join("\n")))},e.coroutine=function(t,e){if("function"!==typeof t)throw new a("generatorFunction must be a function\n\n See http://goo.gl/MqrFmX\n");var r=Object(e).yieldHandler,n=h,i=(new Error).stack;return function(){var e=t.apply(this,arguments),o=new n(void 0,void 0,r,i),s=o.promise();return o._generator=e,o._promiseFulfilled(void 0),s}},e.coroutine.addYieldHandler=function(t){if("function"!==typeof t)throw new a("expecting a function but got "+u.classString(t));f.push(t)},e.spawn=function(t){if(s.deprecated("Promise.spawn()","Promise.coroutine()"),"function"!==typeof t)return r("generatorFunction must be a function\n\n See http://goo.gl/MqrFmX\n");var n=new h(t,this),i=n.promise();return n._run(e.spawn),i}}},{"./errors":12,"./util":36}],17:[function(t,e,r){e.exports=function(e,r,n,i,o,s){var a=t("./util");a.canEvaluate,a.tryCatch,a.errorObj;e.join=function(){var t,e=arguments.length-1;e>0&&"function"===typeof arguments[e]&&(t=arguments[e]);var n=[].slice.call(arguments);t&&n.pop();var i=new r(n).promise();return void 0!==t?i.spread(t):i}}},{"./util":36}],18:[function(t,e,r){e.exports=function(e,r,n,i,o,s){var a=e._getDomain,u=t("./util"),l=u.tryCatch,f=u.errorObj,h=e._async;function p(t,e,r,n){this.constructor$(t),this._promise._captureStackTrace();var i=a();this._callback=null===i?e:u.domainBind(i,e),this._preservedValues=n===o?new Array(this.length()):null,this._limit=r,this._inFlight=0,this._queue=[],h.invoke(this._asyncInit,this,void 0)}function d(t,r,i,o){if("function"!==typeof r)return n("expecting a function but got "+u.classString(r));var s=0;if(void 0!==i){if("object"!==c(i)||null===i)return e.reject(new TypeError("options argument must be an object but it is "+u.classString(i)));if("number"!==typeof i.concurrency)return e.reject(new TypeError("'concurrency' must be a number but it is "+u.classString(i.concurrency)));s=i.concurrency}return new p(t,r,s="number"===typeof s&&isFinite(s)&&s>=1?s:0,o).promise()}u.inherits(p,r),p.prototype._asyncInit=function(){this._init$(void 0,-2)},p.prototype._init=function(){},p.prototype._promiseFulfilled=function(t,r){var n=this._values,o=this.length(),a=this._preservedValues,u=this._limit;if(r<0){if(n[r=-1*r-1]=t,u>=1&&(this._inFlight--,this._drainQueue(),this._isResolved()))return!0}else{if(u>=1&&this._inFlight>=u)return n[r]=t,this._queue.push(r),!1;null!==a&&(a[r]=t);var c=this._promise,h=this._callback,p=c._boundValue();c._pushContext();var d=l(h).call(p,t,r,o),y=c._popContext();if(s.checkForgottenReturns(d,y,null!==a?"Promise.filter":"Promise.map",c),d===f)return this._reject(d.e),!0;var _=i(d,this._promise);if(_ instanceof e){var m=(_=_._target())._bitField;if(0===(50397184&m))return u>=1&&this._inFlight++,n[r]=_,_._proxy(this,-1*(r+1)),!1;if(0===(33554432&m))return 0!==(16777216&m)?(this._reject(_._reason()),!0):(this._cancel(),!0);d=_._value()}n[r]=d}return++this._totalResolved>=o&&(null!==a?this._filter(n,a):this._resolve(n),!0)},p.prototype._drainQueue=function(){for(var t=this._queue,e=this._limit,r=this._values;t.length>0&&this._inFlight<e;){if(this._isResolved())return;var n=t.pop();this._promiseFulfilled(r[n],n)}},p.prototype._filter=function(t,e){for(var r=e.length,n=new Array(r),i=0,o=0;o<r;++o)t[o]&&(n[i++]=e[o]);n.length=i,this._resolve(n)},p.prototype.preservedValues=function(){return this._preservedValues},e.prototype.map=function(t,e){return d(this,t,e,null)},e.map=function(t,e,r,n){return d(t,e,r,n)}}},{"./util":36}],19:[function(t,e,r){e.exports=function(e,r,n,i,o){var s=t("./util"),a=s.tryCatch;e.method=function(t){if("function"!==typeof t)throw new e.TypeError("expecting a function but got "+s.classString(t));return function(){var n=new e(r);n._captureStackTrace(),n._pushContext();var i=a(t).apply(this,arguments),s=n._popContext();return o.checkForgottenReturns(i,s,"Promise.method",n),n._resolveFromSyncValue(i),n}},e.attempt=e.try=function(t){if("function"!==typeof t)return i("expecting a function but got "+s.classString(t));var n,u=new e(r);if(u._captureStackTrace(),u._pushContext(),arguments.length>1){o.deprecated("calling Promise.try with more than 1 argument");var c=arguments[1],l=arguments[2];n=s.isArray(c)?a(t).apply(l,c):a(t).call(l,c)}else n=a(t)();var f=u._popContext();return o.checkForgottenReturns(n,f,"Promise.try",u),u._resolveFromSyncValue(n),u},e.prototype._resolveFromSyncValue=function(t){t===s.errorObj?this._rejectCallback(t.e,!1):this._resolveCallback(t,!0)}}},{"./util":36}],20:[function(t,e,r){var n=t("./util"),i=n.maybeWrapAsError,o=t("./errors").OperationalError,s=t("./es5");var a=/^(?:name|message|stack|cause)$/;function u(t){var e;if(function(t){return t instanceof Error&&s.getPrototypeOf(t)===Error.prototype}(t)){(e=new o(t)).name=t.name,e.message=t.message,e.stack=t.stack;for(var r=s.keys(t),i=0;i<r.length;++i){var u=r[i];a.test(u)||(e[u]=t[u])}return e}return n.markAsOriginatingFromRejection(t),t}e.exports=function(t,e){return function(r,n){if(null!==t){if(r){var o=u(i(r));t._attachExtraTrace(o),t._reject(o)}else if(e){var s=[].slice.call(arguments,1);t._fulfill(s)}else t._fulfill(n);t=null}}}},{"./errors":12,"./es5":13,"./util":36}],21:[function(t,e,r){e.exports=function(e){var r=t("./util"),n=e._async,i=r.tryCatch,o=r.errorObj;function s(t,e){if(!r.isArray(t))return a.call(this,t,e);var s=i(e).apply(this._boundValue(),[null].concat(t));s===o&&n.throwLater(s.e)}function a(t,e){var r=this._boundValue(),s=void 0===t?i(e).call(r,null):i(e).call(r,null,t);s===o&&n.throwLater(s.e)}function u(t,e){if(!t){var r=new Error(t+"");r.cause=t,t=r}var s=i(e).call(this._boundValue(),t);s===o&&n.throwLater(s.e)}e.prototype.asCallback=e.prototype.nodeify=function(t,e){if("function"==typeof t){var r=a;void 0!==e&&Object(e).spread&&(r=s),this._then(r,u,void 0,this,t)}return this}}},{"./util":36}],22:[function(t,e,n){e.exports=function(){var n=function(){return new d("circular promise resolution chain\n\n See http://goo.gl/MqrFmX\n")},i=function(){return new x.PromiseInspection(this._target())},o=function(t){return x.reject(new d(t))};function s(){}var a,u={},c=t("./util");a=c.isNode?function(){var t=r.domain;return void 0===t&&(t=null),t}:function(){return null},c.notEnumerableProp(x,"_getDomain",a);var l=t("./es5"),f=t("./async"),h=new f;l.defineProperty(x,"_async",{value:h});var p=t("./errors"),d=x.TypeError=p.TypeError;x.RangeError=p.RangeError;var y=x.CancellationError=p.CancellationError;x.TimeoutError=p.TimeoutError,x.OperationalError=p.OperationalError,x.RejectionError=p.OperationalError,x.AggregateError=p.AggregateError;var _=function(){},m={},v={},g=t("./thenables")(x,_),b=t("./promise_array")(x,_,g,o,s),w=t("./context")(x),O=w.create,S=t("./debuggability")(x,w),E=(S.CapturedTrace,t("./finally")(x,g,v)),A=t("./catch_filter")(v),$=t("./nodeback"),N=c.errorObj,j=c.tryCatch;function x(t){t!==_&&function(t,e){if(null==t||t.constructor!==x)throw new d("the promise constructor cannot be invoked directly\n\n See http://goo.gl/MqrFmX\n");if("function"!==typeof e)throw new d("expecting a function but got "+c.classString(e))}(this,t),this._bitField=0,this._fulfillmentHandler0=void 0,this._rejectionHandler0=void 0,this._promise0=void 0,this._receiver0=void 0,this._resolveFromExecutor(t),this._promiseCreated(),this._fireEvent("promiseCreated",this)}function T(t){this.promise._resolveCallback(t)}function B(t){this.promise._rejectCallback(t,!1)}function k(t){var e=new x(_);e._fulfillmentHandler0=t,e._rejectionHandler0=t,e._promise0=t,e._receiver0=t}return x.prototype.toString=function(){return"[object Promise]"},x.prototype.caught=x.prototype.catch=function(t){var e=arguments.length;if(e>1){var r,n=new Array(e-1),i=0;for(r=0;r<e-1;++r){var s=arguments[r];if(!c.isObject(s))return o("Catch statement predicate: expecting an object but got "+c.classString(s));n[i++]=s}return n.length=i,t=arguments[r],this.then(void 0,A(n,t,this))}return this.then(void 0,t)},x.prototype.reflect=function(){return this._then(i,i,void 0,this,void 0)},x.prototype.then=function(t,e){if(S.warnings()&&arguments.length>0&&"function"!==typeof t&&"function"!==typeof e){var r=".then() only accepts functions but was passed: "+c.classString(t);arguments.length>1&&(r+=", "+c.classString(e)),this._warn(r)}return this._then(t,e,void 0,void 0,void 0)},x.prototype.done=function(t,e){this._then(t,e,void 0,void 0,void 0)._setIsFinal()},x.prototype.spread=function(t){return"function"!==typeof t?o("expecting a function but got "+c.classString(t)):this.all()._then(t,void 0,void 0,m,void 0)},x.prototype.toJSON=function(){var t={isFulfilled:!1,isRejected:!1,fulfillmentValue:void 0,rejectionReason:void 0};return this.isFulfilled()?(t.fulfillmentValue=this.value(),t.isFulfilled=!0):this.isRejected()&&(t.rejectionReason=this.reason(),t.isRejected=!0),t},x.prototype.all=function(){return arguments.length>0&&this._warn(".all() was passed arguments but it does not take any"),new b(this).promise()},x.prototype.error=function(t){return this.caught(c.originatesFromRejection,t)},x.getNewLibraryCopy=e.exports,x.is=function(t){return t instanceof x},x.fromNode=x.fromCallback=function(t){var e=new x(_);e._captureStackTrace();var r=arguments.length>1&&!!Object(arguments[1]).multiArgs,n=j(t)($(e,r));return n===N&&e._rejectCallback(n.e,!0),e._isFateSealed()||e._setAsyncGuaranteed(),e},x.all=function(t){return new b(t).promise()},x.cast=function(t){var e=g(t);return e instanceof x||((e=new x(_))._captureStackTrace(),e._setFulfilled(),e._rejectionHandler0=t),e},x.resolve=x.fulfilled=x.cast,x.reject=x.rejected=function(t){var e=new x(_);return e._captureStackTrace(),e._rejectCallback(t,!0),e},x.setScheduler=function(t){if("function"!==typeof t)throw new d("expecting a function but got "+c.classString(t));return h.setScheduler(t)},x.prototype._then=function(t,e,r,n,i){var o=void 0!==i,s=o?i:new x(_),u=this._target(),l=u._bitField;o||(s._propagateFrom(this,3),s._captureStackTrace(),void 0===n&&0!==(2097152&this._bitField)&&(n=0!==(50397184&l)?this._boundValue():u===this?void 0:this._boundTo),this._fireEvent("promiseChained",this,s));var f=a();if(0!==(50397184&l)){var p,d,m=u._settlePromiseCtx;0!==(33554432&l)?(d=u._rejectionHandler0,p=t):0!==(16777216&l)?(d=u._fulfillmentHandler0,p=e,u._unsetRejectionIsUnhandled()):(m=u._settlePromiseLateCancellationObserver,d=new y("late cancellation observer"),u._attachExtraTrace(d),p=e),h.invoke(m,u,{handler:null===f?p:"function"===typeof p&&c.domainBind(f,p),promise:s,receiver:n,value:d})}else u._addCallbacks(t,e,s,n,f);return s},x.prototype._length=function(){return 65535&this._bitField},x.prototype._isFateSealed=function(){return 0!==(117506048&this._bitField)},x.prototype._isFollowing=function(){return 67108864===(67108864&this._bitField)},x.prototype._setLength=function(t){this._bitField=-65536&this._bitField|65535&t},x.prototype._setFulfilled=function(){this._bitField=33554432|this._bitField,this._fireEvent("promiseFulfilled",this)},x.prototype._setRejected=function(){this._bitField=16777216|this._bitField,this._fireEvent("promiseRejected",this)},x.prototype._setFollowing=function(){this._bitField=67108864|this._bitField,this._fireEvent("promiseResolved",this)},x.prototype._setIsFinal=function(){this._bitField=4194304|this._bitField},x.prototype._isFinal=function(){return(4194304&this._bitField)>0},x.prototype._unsetCancelled=function(){this._bitField=-65537&this._bitField},x.prototype._setCancelled=function(){this._bitField=65536|this._bitField,this._fireEvent("promiseCancelled",this)},x.prototype._setWillBeCancelled=function(){this._bitField=8388608|this._bitField},x.prototype._setAsyncGuaranteed=function(){h.hasCustomScheduler()||(this._bitField=134217728|this._bitField)},x.prototype._receiverAt=function(t){var e=0===t?this._receiver0:this[4*t-4+3];if(e!==u)return void 0===e&&this._isBound()?this._boundValue():e},x.prototype._promiseAt=function(t){return this[4*t-4+2]},x.prototype._fulfillmentHandlerAt=function(t){return this[4*t-4+0]},x.prototype._rejectionHandlerAt=function(t){return this[4*t-4+1]},x.prototype._boundValue=function(){},x.prototype._migrateCallback0=function(t){t._bitField;var e=t._fulfillmentHandler0,r=t._rejectionHandler0,n=t._promise0,i=t._receiverAt(0);void 0===i&&(i=u),this._addCallbacks(e,r,n,i,null)},x.prototype._migrateCallbackAt=function(t,e){var r=t._fulfillmentHandlerAt(e),n=t._rejectionHandlerAt(e),i=t._promiseAt(e),o=t._receiverAt(e);void 0===o&&(o=u),this._addCallbacks(r,n,i,o,null)},x.prototype._addCallbacks=function(t,e,r,n,i){var o=this._length();if(o>=65531&&(o=0,this._setLength(0)),0===o)this._promise0=r,this._receiver0=n,"function"===typeof t&&(this._fulfillmentHandler0=null===i?t:c.domainBind(i,t)),"function"===typeof e&&(this._rejectionHandler0=null===i?e:c.domainBind(i,e));else{var s=4*o-4;this[s+2]=r,this[s+3]=n,"function"===typeof t&&(this[s+0]=null===i?t:c.domainBind(i,t)),"function"===typeof e&&(this[s+1]=null===i?e:c.domainBind(i,e))}return this._setLength(o+1),o},x.prototype._proxy=function(t,e){this._addCallbacks(void 0,void 0,e,t,null)},x.prototype._resolveCallback=function(t,e){if(0===(117506048&this._bitField)){if(t===this)return this._rejectCallback(n(),!1);var r=g(t,this);if(!(r instanceof x))return this._fulfill(t);e&&this._propagateFrom(r,2);var i=r._target();if(i!==this){var o=i._bitField;if(0===(50397184&o)){var s=this._length();s>0&&i._migrateCallback0(this);for(var a=1;a<s;++a)i._migrateCallbackAt(this,a);this._setFollowing(),this._setLength(0),this._setFollowee(i)}else if(0!==(33554432&o))this._fulfill(i._value());else if(0!==(16777216&o))this._reject(i._reason());else{var u=new y("late cancellation observer");i._attachExtraTrace(u),this._reject(u)}}else this._reject(n())}},x.prototype._rejectCallback=function(t,e,r){var n=c.ensureErrorObject(t),i=n===t;if(!i&&!r&&S.warnings()){var o="a promise was rejected with a non-error: "+c.classString(t);this._warn(o,!0)}this._attachExtraTrace(n,!!e&&i),this._reject(t)},x.prototype._resolveFromExecutor=function(t){if(t!==_){var e=this;this._captureStackTrace(),this._pushContext();var r=!0,n=this._execute(t,function(t){e._resolveCallback(t)},function(t){e._rejectCallback(t,r)});r=!1,this._popContext(),void 0!==n&&e._rejectCallback(n,!0)}},x.prototype._settlePromiseFromHandler=function(t,e,r,n){var i=n._bitField;if(0===(65536&i)){var o;n._pushContext(),e===m?r&&"number"===typeof r.length?o=j(t).apply(this._boundValue(),r):(o=N).e=new d("cannot .spread() a non-array: "+c.classString(r)):o=j(t).call(e,r);var s=n._popContext();0===(65536&(i=n._bitField))&&(o===v?n._reject(r):o===N?n._rejectCallback(o.e,!1):(S.checkForgottenReturns(o,s,"",n,this),n._resolveCallback(o)))}},x.prototype._target=function(){for(var t=this;t._isFollowing();)t=t._followee();return t},x.prototype._followee=function(){return this._rejectionHandler0},x.prototype._setFollowee=function(t){this._rejectionHandler0=t},x.prototype._settlePromise=function(t,e,r,n){var o=t instanceof x,a=this._bitField,u=0!==(134217728&a);0!==(65536&a)?(o&&t._invokeInternalOnCancel(),r instanceof E&&r.isFinallyHandler()?(r.cancelPromise=t,j(e).call(r,n)===N&&t._reject(N.e)):e===i?t._fulfill(i.call(r)):r instanceof s?r._promiseCancelled(t):o||t instanceof b?t._cancel():r.cancel()):"function"===typeof e?o?(u&&t._setAsyncGuaranteed(),this._settlePromiseFromHandler(e,r,n,t)):e.call(r,n,t):r instanceof s?r._isResolved()||(0!==(33554432&a)?r._promiseFulfilled(n,t):r._promiseRejected(n,t)):o&&(u&&t._setAsyncGuaranteed(),0!==(33554432&a)?t._fulfill(n):t._reject(n))},x.prototype._settlePromiseLateCancellationObserver=function(t){var e=t.handler,r=t.promise,n=t.receiver,i=t.value;"function"===typeof e?r instanceof x?this._settlePromiseFromHandler(e,n,i,r):e.call(n,i,r):r instanceof x&&r._reject(i)},x.prototype._settlePromiseCtx=function(t){this._settlePromise(t.promise,t.handler,t.receiver,t.value)},x.prototype._settlePromise0=function(t,e,r){var n=this._promise0,i=this._receiverAt(0);this._promise0=void 0,this._receiver0=void 0,this._settlePromise(n,t,i,e)},x.prototype._clearCallbackDataAtIndex=function(t){var e=4*t-4;this[e+2]=this[e+3]=this[e+0]=this[e+1]=void 0},x.prototype._fulfill=function(t){var e=this._bitField;if(!((117506048&e)>>>16)){if(t===this){var r=n();return this._attachExtraTrace(r),this._reject(r)}this._setFulfilled(),this._rejectionHandler0=t,(65535&e)>0&&(0!==(134217728&e)?this._settlePromises():h.settlePromises(this))}},x.prototype._reject=function(t){var e=this._bitField;if(!((117506048&e)>>>16)){if(this._setRejected(),this._fulfillmentHandler0=t,this._isFinal())return h.fatalError(t,c.isNode);(65535&e)>0?h.settlePromises(this):this._ensurePossibleRejectionHandled()}},x.prototype._fulfillPromises=function(t,e){for(var r=1;r<t;r++){var n=this._fulfillmentHandlerAt(r),i=this._promiseAt(r),o=this._receiverAt(r);this._clearCallbackDataAtIndex(r),this._settlePromise(i,n,o,e)}},x.prototype._rejectPromises=function(t,e){for(var r=1;r<t;r++){var n=this._rejectionHandlerAt(r),i=this._promiseAt(r),o=this._receiverAt(r);this._clearCallbackDataAtIndex(r),this._settlePromise(i,n,o,e)}},x.prototype._settlePromises=function(){var t=this._bitField,e=65535&t;if(e>0){if(0!==(16842752&t)){var r=this._fulfillmentHandler0;this._settlePromise0(this._rejectionHandler0,r,t),this._rejectPromises(e,r)}else{var n=this._rejectionHandler0;this._settlePromise0(this._fulfillmentHandler0,n,t),this._fulfillPromises(e,n)}this._setLength(0)}this._clearCancellationData()},x.prototype._settledValue=function(){var t=this._bitField;return 0!==(33554432&t)?this._rejectionHandler0:0!==(16777216&t)?this._fulfillmentHandler0:void 0},x.defer=x.pending=function(){return S.deprecated("Promise.defer","new Promise"),{promise:new x(_),resolve:T,reject:B}},c.notEnumerableProp(x,"_makeSelfResolutionError",n),t("./method")(x,_,g,o,S),t("./bind")(x,_,g,S),t("./cancel")(x,b,o,S),t("./direct_resolve")(x),t("./synchronous_inspection")(x),t("./join")(x,b,g,_,h,a),x.Promise=x,x.version="3.5.1",t("./map.js")(x,b,o,g,_,S),t("./call_get.js")(x),t("./using.js")(x,o,g,O,_,S),t("./timers.js")(x,_,S),t("./generators.js")(x,o,_,g,s,S),t("./nodeify.js")(x),t("./promisify.js")(x,_),t("./props.js")(x,b,g,o),t("./race.js")(x,_,g,o),t("./reduce.js")(x,b,o,g,_,S),t("./settle.js")(x,b,S),t("./some.js")(x,b,o),t("./filter.js")(x,_),t("./each.js")(x,_),t("./any.js")(x),c.toFastProperties(x),c.toFastProperties(x.prototype),k({a:1}),k({b:2}),k({c:3}),k(1),k(function(){}),k(void 0),k(!1),k(new x(_)),S.setBounds(f.firstLineError,c.lastLineError),x}},{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(t,e,r){e.exports=function(e,r,n,i,o){var s=t("./util");s.isArray;function a(t){var n=this._promise=new e(r);t instanceof e&&n._propagateFrom(t,3),n._setOnCancel(this),this._values=t,this._length=0,this._totalResolved=0,this._init(void 0,-2)}return s.inherits(a,o),a.prototype.length=function(){return this._length},a.prototype.promise=function(){return this._promise},a.prototype._init=function t(r,o){var a=n(this._values,this._promise);if(a instanceof e){var u=(a=a._target())._bitField;if(this._values=a,0===(50397184&u))return this._promise._setAsyncGuaranteed(),a._then(t,this._reject,void 0,this,o);if(0===(33554432&u))return 0!==(16777216&u)?this._reject(a._reason()):this._cancel();a=a._value()}if(null!==(a=s.asArray(a)))0!==a.length?this._iterate(a):-5===o?this._resolveEmptyArray():this._resolve(function(t){switch(t){case-2:return[];case-3:return{};case-6:return new Map}}(o));else{var c=i("expecting an array or an iterable object but got "+s.classString(a)).reason();this._promise._rejectCallback(c,!1)}},a.prototype._iterate=function(t){var r=this.getActualLength(t.length);this._length=r,this._values=this.shouldCopyValues()?new Array(r):this._values;for(var i=this._promise,o=!1,s=null,a=0;a<r;++a){var u=n(t[a],i);s=u instanceof e?(u=u._target())._bitField:null,o?null!==s&&u.suppressUnhandledRejections():null!==s?0===(50397184&s)?(u._proxy(this,a),this._values[a]=u):o=0!==(33554432&s)?this._promiseFulfilled(u._value(),a):0!==(16777216&s)?this._promiseRejected(u._reason(),a):this._promiseCancelled(a):o=this._promiseFulfilled(u,a)}o||i._setAsyncGuaranteed()},a.prototype._isResolved=function(){return null===this._values},a.prototype._resolve=function(t){this._values=null,this._promise._fulfill(t)},a.prototype._cancel=function(){!this._isResolved()&&this._promise._isCancellable()&&(this._values=null,this._promise._cancel())},a.prototype._reject=function(t){this._values=null,this._promise._rejectCallback(t,!1)},a.prototype._promiseFulfilled=function(t,e){return this._values[e]=t,++this._totalResolved>=this._length&&(this._resolve(this._values),!0)},a.prototype._promiseCancelled=function(){return this._cancel(),!0},a.prototype._promiseRejected=function(t){return this._totalResolved++,this._reject(t),!0},a.prototype._resultCancelled=function(){if(!this._isResolved()){var t=this._values;if(this._cancel(),t instanceof e)t.cancel();else for(var r=0;r<t.length;++r)t[r]instanceof e&&t[r].cancel()}},a.prototype.shouldCopyValues=function(){return!0},a.prototype.getActualLength=function(t){return t},a}},{"./util":36}],24:[function(t,e,r){e.exports=function(e,r){var n={},i=t("./util"),o=t("./nodeback"),s=i.withAppended,a=i.maybeWrapAsError,u=i.canEvaluate,l=t("./errors").TypeError,f={__isPromisified__:!0},h=new RegExp("^(?:"+["arity","length","name","arguments","caller","callee","prototype","__isPromisified__"].join("|")+")$"),p=function(t){return i.isIdentifier(t)&&"_"!==t.charAt(0)&&"constructor"!==t};function d(t){return!h.test(t)}function y(t){try{return!0===t.__isPromisified__}catch(t){return!1}}function _(t,e,r){var n=i.getDataPropertyOrDefault(t,e+r,f);return!!n&&y(n)}function m(t,e,r,n){for(var o=i.inheritedDataKeys(t),s=[],a=0;a<o.length;++a){var u=o[a],c=t[u],f=n===p||p(u,c,t);"function"!==typeof c||y(c)||_(t,u,e)||!n(u,c,t,f)||s.push(u,c)}return function(t,e,r){for(var n=0;n<t.length;n+=2){var i=t[n];if(r.test(i))for(var o=i.replace(r,""),s=0;s<t.length;s+=2)if(t[s]===o)throw new l("Cannot promisify an API that has normal methods with '%s'-suffix\n\n See http://goo.gl/MqrFmX\n".replace("%s",e))}}(s,e,r),s}var v=function(t){return t.replace(/([$])/,"\\$")};var g=u?void 0:function(t,u,c,l,f,h){var p=function(){return this}(),d=t;function y(){var i=u;u===n&&(i=this);var c=new e(r);c._captureStackTrace();var l="string"===typeof d&&this!==p?this[d]:t,f=o(c,h);try{l.apply(i,s(arguments,f))}catch(t){c._rejectCallback(a(t),!0,!0)}return c._isFateSealed()||c._setAsyncGuaranteed(),c}return"string"===typeof d&&(t=l),i.notEnumerableProp(y,"__isPromisified__",!0),y};function b(t,e,r,o,s){for(var a=new RegExp(v(e)+"$"),u=m(t,e,a,r),c=0,l=u.length;c<l;c+=2){var f=u[c],h=u[c+1],p=f+e;if(o===g)t[p]=g(f,n,f,h,e,s);else{var d=o(h,function(){return g(f,n,f,h,e,s)});i.notEnumerableProp(d,"__isPromisified__",!0),t[p]=d}}return i.toFastProperties(t),t}e.promisify=function(t,e){if("function"!==typeof t)throw new l("expecting a function but got "+i.classString(t));if(y(t))return t;var r=function(t,e,r){return g(t,e,void 0,t,null,r)}(t,void 0===(e=Object(e)).context?n:e.context,!!e.multiArgs);return i.copyDescriptors(t,r,d),r},e.promisifyAll=function(t,e){if("function"!==typeof t&&"object"!==c(t))throw new l("the target of promisifyAll must be an object or a function\n\n See http://goo.gl/MqrFmX\n");var r=!!(e=Object(e)).multiArgs,n=e.suffix;"string"!==typeof n&&(n="Async");var o=e.filter;"function"!==typeof o&&(o=p);var s=e.promisifier;if("function"!==typeof s&&(s=g),!i.isIdentifier(n))throw new RangeError("suffix must be a valid identifier\n\n See http://goo.gl/MqrFmX\n");for(var a=i.inheritedDataKeys(t),u=0;u<a.length;++u){var f=t[a[u]];"constructor"!==a[u]&&i.isClass(f)&&(b(f.prototype,n,o,s,r),b(f,n,o,s,r))}return b(t,n,o,s,r)}}},{"./errors":12,"./nodeback":20,"./util":36}],25:[function(t,e,r){e.exports=function(e,r,n,i){var o,s=t("./util"),a=s.isObject,u=t("./es5");"function"===typeof Map&&(o=Map);var c=function(){var t=0,e=0;function r(r,n){this[t]=r,this[t+e]=n,t++}return function(n){e=n.size,t=0;var i=new Array(2*n.size);return n.forEach(r,i),i}}();function l(t){var e,r=!1;if(void 0!==o&&t instanceof o)e=c(t),r=!0;else{var n=u.keys(t),i=n.length;e=new Array(2*i);for(var s=0;s<i;++s){var a=n[s];e[s]=t[a],e[s+i]=a}}this.constructor$(e),this._isMap=r,this._init$(void 0,r?-6:-3)}function f(t){var r,o=n(t);return a(o)?(r=o instanceof e?o._then(e.props,void 0,void 0,void 0,void 0):new l(o).promise(),o instanceof e&&r._propagateFrom(o,2),r):i("cannot await properties of a non-object\n\n See http://goo.gl/MqrFmX\n")}s.inherits(l,r),l.prototype._init=function(){},l.prototype._promiseFulfilled=function(t,e){if(this._values[e]=t,++this._totalResolved>=this._length){var r;if(this._isMap)r=function(t){for(var e=new o,r=t.length/2|0,n=0;n<r;++n){var i=t[r+n],s=t[n];e.set(i,s)}return e}(this._values);else{r={};for(var n=this.length(),i=0,s=this.length();i<s;++i)r[this._values[i+n]]=this._values[i]}return this._resolve(r),!0}return!1},l.prototype.shouldCopyValues=function(){return!1},l.prototype.getActualLength=function(t){return t>>1},e.prototype.props=function(){return f(this)},e.props=function(t){return f(t)}}},{"./es5":13,"./util":36}],26:[function(t,e,r){function n(t){this._capacity=t,this._length=0,this._front=0}n.prototype._willBeOverCapacity=function(t){return this._capacity<t},n.prototype._pushOne=function(t){var e=this.length();this._checkCapacity(e+1),this[this._front+e&this._capacity-1]=t,this._length=e+1},n.prototype.push=function(t,e,r){var n=this.length()+3;if(this._willBeOverCapacity(n))return this._pushOne(t),this._pushOne(e),void this._pushOne(r);var i=this._front+n-3;this._checkCapacity(n);var o=this._capacity-1;this[i+0&o]=t,this[i+1&o]=e,this[i+2&o]=r,this._length=n},n.prototype.shift=function(){var t=this._front,e=this[t];return this[t]=void 0,this._front=t+1&this._capacity-1,this._length--,e},n.prototype.length=function(){return this._length},n.prototype._checkCapacity=function(t){this._capacity<t&&this._resizeTo(this._capacity<<1)},n.prototype._resizeTo=function(t){var e=this._capacity;this._capacity=t,function(t,e,r,n,i){for(var o=0;o<i;++o)r[o+n]=t[o+e],t[o+e]=void 0}(this,0,this,e,this._front+this._length&e-1)},e.exports=n},{}],27:[function(t,e,r){e.exports=function(e,r,n,i){var o=t("./util"),s=function(t){return t.then(function(e){return a(e,t)})};function a(t,a){var u=n(t);if(u instanceof e)return s(u);if(null===(t=o.asArray(t)))return i("expecting an array or an iterable object but got "+o.classString(t));var c=new e(r);void 0!==a&&c._propagateFrom(a,3);for(var l=c._fulfill,f=c._reject,h=0,p=t.length;h<p;++h){var d=t[h];(void 0!==d||h in t)&&e.cast(d)._then(l,f,void 0,c,null)}return c}e.race=function(t){return a(t,void 0)},e.prototype.race=function(){return a(this,void 0)}}},{"./util":36}],28:[function(t,e,r){e.exports=function(e,r,n,i,o,s){var a=e._getDomain,u=t("./util"),c=u.tryCatch;function l(t,r,n,i){this.constructor$(t);var s=a();this._fn=null===s?r:u.domainBind(s,r),void 0!==n&&(n=e.resolve(n))._attachCancellationCallback(this),this._initialValue=n,this._currentCancellable=null,this._eachValues=i===o?Array(this._length):0===i?null:void 0,this._promise._captureStackTrace(),this._init$(void 0,-5)}function f(t,e){this.isFulfilled()?e._resolve(t):e._reject(t)}function h(t,e,r,i){return"function"!==typeof e?n("expecting a function but got "+u.classString(e)):new l(t,e,r,i).promise()}function p(t){this.accum=t,this.array._gotAccum(t);var r=i(this.value,this.array._promise);return r instanceof e?(this.array._currentCancellable=r,r._then(d,void 0,void 0,this,void 0)):d.call(this,r)}function d(t){var r,n=this.array,i=n._promise,o=c(n._fn);i._pushContext(),(r=void 0!==n._eachValues?o.call(i._boundValue(),t,this.index,this.length):o.call(i._boundValue(),this.accum,t,this.index,this.length))instanceof e&&(n._currentCancellable=r);var a=i._popContext();return s.checkForgottenReturns(r,a,void 0!==n._eachValues?"Promise.each":"Promise.reduce",i),r}u.inherits(l,r),l.prototype._gotAccum=function(t){void 0!==this._eachValues&&null!==this._eachValues&&t!==o&&this._eachValues.push(t)},l.prototype._eachComplete=function(t){return null!==this._eachValues&&this._eachValues.push(t),this._eachValues},l.prototype._init=function(){},l.prototype._resolveEmptyArray=function(){this._resolve(void 0!==this._eachValues?this._eachValues:this._initialValue)},l.prototype.shouldCopyValues=function(){return!1},l.prototype._resolve=function(t){this._promise._resolveCallback(t),this._values=null},l.prototype._resultCancelled=function(t){if(t===this._initialValue)return this._cancel();this._isResolved()||(this._resultCancelled$(),this._currentCancellable instanceof e&&this._currentCancellable.cancel(),this._initialValue instanceof e&&this._initialValue.cancel())},l.prototype._iterate=function(t){var r,n;this._values=t;var i=t.length;if(void 0!==this._initialValue?(r=this._initialValue,n=0):(r=e.resolve(t[0]),n=1),this._currentCancellable=r,!r.isRejected())for(;n<i;++n){var o={accum:null,value:t[n],index:n,length:i,array:this};r=r._then(p,void 0,void 0,o,void 0)}void 0!==this._eachValues&&(r=r._then(this._eachComplete,void 0,void 0,this,void 0)),r._then(f,f,void 0,r,this)},e.prototype.reduce=function(t,e){return h(this,t,e,null)},e.reduce=function(t,e,r,n){return h(t,e,r,n)}}},{"./util":36}],29:[function(t,e,o){var s,a=t("./util"),u=a.getNativePromise();if(a.isNode&&"undefined"===typeof MutationObserver){var c=n.setImmediate,l=r.nextTick;s=a.isRecentNode?function(t){c.call(n,t)}:function(t){l.call(r,t)}}else if("function"===typeof u&&"function"===typeof u.resolve){var f=u.resolve();s=function(t){f.then(t)}}else s="undefined"===typeof MutationObserver||"undefined"!==typeof window&&window.navigator&&(window.navigator.standalone||window.cordova)?"undefined"!==typeof i?function(t){i(t)}:"undefined"!==typeof setTimeout?function(t){setTimeout(t,0)}:function(){throw new Error("No async scheduler available\n\n See http://goo.gl/MqrFmX\n")}:function(){var t=document.createElement("div"),e={attributes:!0},r=!1,n=document.createElement("div");new MutationObserver(function(){t.classList.toggle("foo"),r=!1}).observe(n,e);return function(i){var o=new MutationObserver(function(){o.disconnect(),i()});o.observe(t,e),r||(r=!0,n.classList.toggle("foo"))}}();e.exports=s},{"./util":36}],30:[function(t,e,r){e.exports=function(e,r,n){var i=e.PromiseInspection;function o(t){this.constructor$(t)}t("./util").inherits(o,r),o.prototype._promiseResolved=function(t,e){return this._values[t]=e,++this._totalResolved>=this._length&&(this._resolve(this._values),!0)},o.prototype._promiseFulfilled=function(t,e){var r=new i;return r._bitField=33554432,r._settledValueField=t,this._promiseResolved(e,r)},o.prototype._promiseRejected=function(t,e){var r=new i;return r._bitField=16777216,r._settledValueField=t,this._promiseResolved(e,r)},e.settle=function(t){return n.deprecated(".settle()",".reflect()"),new o(t).promise()},e.prototype.settle=function(){return e.settle(this)}}},{"./util":36}],31:[function(t,e,r){e.exports=function(e,r,n){var i=t("./util"),o=t("./errors").RangeError,s=t("./errors").AggregateError,a=i.isArray,u={};function c(t){this.constructor$(t),this._howMany=0,this._unwrap=!1,this._initialized=!1}function l(t,e){if((0|e)!==e||e<0)return n("expecting a positive integer\n\n See http://goo.gl/MqrFmX\n");var r=new c(t),i=r.promise();return r.setHowMany(e),r.init(),i}i.inherits(c,r),c.prototype._init=function(){if(this._initialized)if(0!==this._howMany){this._init$(void 0,-5);var t=a(this._values);!this._isResolved()&&t&&this._howMany>this._canPossiblyFulfill()&&this._reject(this._getRangeError(this.length()))}else this._resolve([])},c.prototype.init=function(){this._initialized=!0,this._init()},c.prototype.setUnwrap=function(){this._unwrap=!0},c.prototype.howMany=function(){return this._howMany},c.prototype.setHowMany=function(t){this._howMany=t},c.prototype._promiseFulfilled=function(t){return this._addFulfilled(t),this._fulfilled()===this.howMany()&&(this._values.length=this.howMany(),1===this.howMany()&&this._unwrap?this._resolve(this._values[0]):this._resolve(this._values),!0)},c.prototype._promiseRejected=function(t){return this._addRejected(t),this._checkOutcome()},c.prototype._promiseCancelled=function(){return this._values instanceof e||null==this._values?this._cancel():(this._addRejected(u),this._checkOutcome())},c.prototype._checkOutcome=function(){if(this.howMany()>this._canPossiblyFulfill()){for(var t=new s,e=this.length();e<this._values.length;++e)this._values[e]!==u&&t.push(this._values[e]);return t.length>0?this._reject(t):this._cancel(),!0}return!1},c.prototype._fulfilled=function(){return this._totalResolved},c.prototype._rejected=function(){return this._values.length-this.length()},c.prototype._addRejected=function(t){this._values.push(t)},c.prototype._addFulfilled=function(t){this._values[this._totalResolved++]=t},c.prototype._canPossiblyFulfill=function(){return this.length()-this._rejected()},c.prototype._getRangeError=function(t){var e="Input array must contain at least "+this._howMany+" items but contains only "+t+" items";return new o(e)},c.prototype._resolveEmptyArray=function(){this._reject(this._getRangeError(0))},e.some=function(t,e){return l(t,e)},e.prototype.some=function(t){return l(this,t)},e._SomePromiseArray=c}},{"./errors":12,"./util":36}],32:[function(t,e,r){e.exports=function(t){function e(t){void 0!==t?(t=t._target(),this._bitField=t._bitField,this._settledValueField=t._isFateSealed()?t._settledValue():void 0):(this._bitField=0,this._settledValueField=void 0)}e.prototype._settledValue=function(){return this._settledValueField};var r=e.prototype.value=function(){if(!this.isFulfilled())throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},n=e.prototype.error=e.prototype.reason=function(){if(!this.isRejected())throw new TypeError("cannot get rejection reason of a non-rejected promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},i=e.prototype.isFulfilled=function(){return 0!==(33554432&this._bitField)},o=e.prototype.isRejected=function(){return 0!==(16777216&this._bitField)},s=e.prototype.isPending=function(){return 0===(50397184&this._bitField)},a=e.prototype.isResolved=function(){return 0!==(50331648&this._bitField)};e.prototype.isCancelled=function(){return 0!==(8454144&this._bitField)},t.prototype.__isCancelled=function(){return 65536===(65536&this._bitField)},t.prototype._isCancelled=function(){return this._target().__isCancelled()},t.prototype.isCancelled=function(){return 0!==(8454144&this._target()._bitField)},t.prototype.isPending=function(){return s.call(this._target())},t.prototype.isRejected=function(){return o.call(this._target())},t.prototype.isFulfilled=function(){return i.call(this._target())},t.prototype.isResolved=function(){return a.call(this._target())},t.prototype.value=function(){return r.call(this._target())},t.prototype.reason=function(){var t=this._target();return t._unsetRejectionIsUnhandled(),n.call(t)},t.prototype._value=function(){return this._settledValue()},t.prototype._reason=function(){return this._unsetRejectionIsUnhandled(),this._settledValue()},t.PromiseInspection=e}},{}],33:[function(t,e,r){e.exports=function(e,r){var n=t("./util"),i=n.errorObj,o=n.isObject;var s={}.hasOwnProperty;return function(t,a){if(o(t)){if(t instanceof e)return t;var u=function(t){try{return function(t){return t.then}(t)}catch(t){return i.e=t,i}}(t);if(u===i){a&&a._pushContext();var c=e.reject(u.e);return a&&a._popContext(),c}if("function"===typeof u)return function(t){try{return s.call(t,"_promise0")}catch(t){return!1}}(t)?(c=new e(r),t._then(c._fulfill,c._reject,void 0,c,null),c):function(t,o,s){var a=new e(r),u=a;s&&s._pushContext(),a._captureStackTrace(),s&&s._popContext();var c=!0,l=n.tryCatch(o).call(t,function(t){a&&(a._resolveCallback(t),a=null)},function(t){a&&(a._rejectCallback(t,c,!0),a=null)});return c=!1,a&&l===i&&(a._rejectCallback(l.e,!0,!0),a=null),u}(t,u,a)}return t}}},{"./util":36}],34:[function(t,e,r){e.exports=function(e,r,n){var i=t("./util"),o=e.TimeoutError;function s(t){this.handle=t}s.prototype._resultCancelled=function(){clearTimeout(this.handle)};var a=function(t){return u(+this).thenReturn(t)},u=e.delay=function(t,i){var o,u;return void 0!==i?(o=e.resolve(i)._then(a,null,null,t,void 0),n.cancellation()&&i instanceof e&&o._setOnCancel(i)):(o=new e(r),u=setTimeout(function(){o._fulfill()},+t),n.cancellation()&&o._setOnCancel(new s(u)),o._captureStackTrace()),o._setAsyncGuaranteed(),o};e.prototype.delay=function(t){return u(t,this)};function c(t){return clearTimeout(this.handle),t}function l(t){throw clearTimeout(this.handle),t}e.prototype.timeout=function(t,e){var r,a;t=+t;var u=new s(setTimeout(function(){r.isPending()&&function(t,e,r){var n;n="string"!==typeof e?e instanceof Error?e:new o("operation timed out"):new o(e),i.markAsOriginatingFromRejection(n),t._attachExtraTrace(n),t._reject(n),null!=r&&r.cancel()}(r,e,a)},t));return n.cancellation()?(a=this.then(),(r=a._then(c,l,void 0,u,void 0))._setOnCancel(u)):r=this._then(c,l,void 0,u,void 0),r}}},{"./util":36}],35:[function(t,e,r){e.exports=function(e,r,n,i,o,s){var a=t("./util"),u=t("./errors").TypeError,c=t("./util").inherits,l=a.errorObj,f=a.tryCatch,h={};function p(t){setTimeout(function(){throw t},0)}function d(t,r){var i=0,s=t.length,a=new e(o);return function o(){if(i>=s)return a._fulfill();var u=function(t){var e=n(t);return e!==t&&"function"===typeof t._isDisposable&&"function"===typeof t._getDisposer&&t._isDisposable()&&e._setDisposable(t._getDisposer()),e}(t[i++]);if(u instanceof e&&u._isDisposable()){try{u=n(u._getDisposer().tryDispose(r),t.promise)}catch(t){return p(t)}if(u instanceof e)return u._then(o,p,null,null,null)}o()}(),a}function y(t,e,r){this._data=t,this._promise=e,this._context=r}function _(t,e,r){this.constructor$(t,e,r)}function m(t){return y.isDisposer(t)?(this.resources[this.index]._setDisposable(t),t.promise()):t}function v(t){this.length=t,this.promise=null,this[t-1]=null}y.prototype.data=function(){return this._data},y.prototype.promise=function(){return this._promise},y.prototype.resource=function(){return this.promise().isFulfilled()?this.promise().value():h},y.prototype.tryDispose=function(t){var e=this.resource(),r=this._context;void 0!==r&&r._pushContext();var n=e!==h?this.doDispose(e,t):null;return void 0!==r&&r._popContext(),this._promise._unsetDisposable(),this._data=null,n},y.isDisposer=function(t){return null!=t&&"function"===typeof t.resource&&"function"===typeof t.tryDispose},c(_,y),_.prototype.doDispose=function(t,e){return this.data().call(t,t,e)},v.prototype._resultCancelled=function(){for(var t=this.length,r=0;r<t;++r){var n=this[r];n instanceof e&&n.cancel()}},e.using=function(){var t=arguments.length;if(t<2)return r("you must pass at least 2 arguments to Promise.using");var i,o=arguments[t-1];if("function"!==typeof o)return r("expecting a function but got "+a.classString(o));var u=!0;2===t&&Array.isArray(arguments[0])?(t=(i=arguments[0]).length,u=!1):(i=arguments,t--);for(var c=new v(t),h=0;h<t;++h){var p=i[h];if(y.isDisposer(p)){var _=p;(p=p.promise())._setDisposable(_)}else{var g=n(p);g instanceof e&&(p=g._then(m,null,null,{resources:c,index:h},void 0))}c[h]=p}var b=new Array(c.length);for(h=0;h<b.length;++h)b[h]=e.resolve(c[h]).reflect();var w=e.all(b).then(function(t){for(var e=0;e<t.length;++e){var r=t[e];if(r.isRejected())return l.e=r.error(),l;if(!r.isFulfilled())return void w.cancel();t[e]=r.value()}O._pushContext(),o=f(o);var n=u?o.apply(void 0,t):o(t),i=O._popContext();return s.checkForgottenReturns(n,i,"Promise.using",O),n}),O=w.lastly(function(){var t=new e.PromiseInspection(w);return d(c,t)});return c.promise=O,O._setOnCancel(c),O},e.prototype._setDisposable=function(t){this._bitField=131072|this._bitField,this._disposer=t},e.prototype._isDisposable=function(){return(131072&this._bitField)>0},e.prototype._getDisposer=function(){return this._disposer},e.prototype._unsetDisposable=function(){this._bitField=-131073&this._bitField,this._disposer=void 0},e.prototype.disposer=function(t){if("function"===typeof t)return new _(t,this,i());throw new u}}},{"./errors":12,"./util":36}],36:[function(t,e,i){var o=t("./es5"),s="undefined"==typeof navigator,a={e:{}},u,l="undefined"!==typeof self?self:"undefined"!==typeof window?window:"undefined"!==typeof n?n:void 0!==this?this:null;function f(){try{var t=u;return u=null,t.apply(this,arguments)}catch(t){return a.e=t,a}}function h(t){return u=t,f}var p=function(t,e){var r={}.hasOwnProperty;function n(){for(var n in this.constructor=t,this.constructor$=e,e.prototype)r.call(e.prototype,n)&&"$"!==n.charAt(n.length-1)&&(this[n+"$"]=e.prototype[n])}return n.prototype=e.prototype,t.prototype=new n,t.prototype};function d(t){return null==t||!0===t||!1===t||"string"===typeof t||"number"===typeof t}function y(t){return"function"===typeof t||"object"===c(t)&&null!==t}function _(t){return d(t)?new Error(j(t)):t}function m(t,e){var r,n=t.length,i=new Array(n+1);for(r=0;r<n;++r)i[r]=t[r];return i[r]=e,i}function v(t,e,r){if(!o.isES5)return{}.hasOwnProperty.call(t,e)?t[e]:void 0;var n=Object.getOwnPropertyDescriptor(t,e);return null!=n?null==n.get&&null==n.set?n.value:r:void 0}function g(t,e,r){if(d(t))return t;var n={value:r,configurable:!0,enumerable:!1,writable:!0};return o.defineProperty(t,e,n),t}function b(t){throw t}var w=function(){var t=[Array.prototype,Object.prototype,Function.prototype],e=function(e){for(var r=0;r<t.length;++r)if(t[r]===e)return!0;return!1};if(o.isES5){var r=Object.getOwnPropertyNames;return function(t){for(var n=[],i=Object.create(null);null!=t&&!e(t);){var s;try{s=r(t)}catch(t){return n}for(var a=0;a<s.length;++a){var u=s[a];if(!i[u]){i[u]=!0;var c=Object.getOwnPropertyDescriptor(t,u);null!=c&&null==c.get&&null==c.set&&n.push(u)}}t=o.getPrototypeOf(t)}return n}}var n={}.hasOwnProperty;return function(r){if(e(r))return[];var i=[];t:for(var o in r)if(n.call(r,o))i.push(o);else{for(var s=0;s<t.length;++s)if(n.call(t[s],o))continue t;i.push(o)}return i}}(),O=/this\s*\.\s*\S+\s*=/;function S(t){try{if("function"===typeof t){var e=o.names(t.prototype),r=o.isES5&&e.length>1,n=e.length>0&&!(1===e.length&&"constructor"===e[0]),i=O.test(t+"")&&o.names(t).length>0;if(r||n||i)return!0}return!1}catch(t){return!1}}function E(t){function e(){}e.prototype=t;for(var r=8;r--;)new e;return t}var A=/^[a-z$_][a-z$_0-9]*$/i;function $(t){return A.test(t)}function N(t,e,r){for(var n=new Array(t),i=0;i<t;++i)n[i]=e+i+r;return n}function j(t){try{return t+""}catch(t){return"[no string representation]"}}function x(t){return t instanceof Error||null!==t&&"object"===c(t)&&"string"===typeof t.message&&"string"===typeof t.name}function T(t){try{g(t,"isOperational",!0)}catch(t){}}function B(t){return null!=t&&(t instanceof Error.__BluebirdErrorTypes__.OperationalError||!0===t.isOperational)}function k(t){return x(t)&&o.propertyIsWritable(t,"stack")}var C="stack"in new Error?function(t){return k(t)?t:new Error(j(t))}:function(t){if(k(t))return t;try{throw new Error(j(t))}catch(t){return t}};function D(t){return{}.toString.call(t)}function P(t,e,r){for(var n=o.names(t),i=0;i<n.length;++i){var s=n[i];if(r(s))try{o.defineProperty(e,s,o.getDescriptor(t,s))}catch(t){}}}var M=function(t){return o.isArray(t)?t:null};if("undefined"!==typeof Symbol&&Symbol.iterator){var R="function"===typeof Array.from?function(t){return Array.from(t)}:function(t){for(var e,r=[],n=t[Symbol.iterator]();!(e=n.next()).done;)r.push(e.value);return r};M=function(t){return o.isArray(t)?t:null!=t&&"function"===typeof t[Symbol.iterator]?R(t):null}}var F="undefined"!==typeof r&&"[object process]"===D(r).toLowerCase(),I="undefined"!==typeof r&&"undefined"!==typeof r.env;function L(t){return I?r.env[t]:void 0}function U(){if("function"===typeof Promise)try{var t=new Promise(function(){});if("[object Promise]"==={}.toString.call(t))return Promise}catch(t){}}function V(t,e){return t.bind(e)}var q={isClass:S,isIdentifier:$,inheritedDataKeys:w,getDataPropertyOrDefault:v,thrower:b,isArray:o.isArray,asArray:M,notEnumerableProp:g,isPrimitive:d,isObject:y,isError:x,canEvaluate:s,errorObj:a,tryCatch:h,inherits:p,withAppended:m,maybeWrapAsError:_,toFastProperties:E,filledRange:N,toString:j,canAttachTrace:k,ensureErrorObject:C,originatesFromRejection:B,markAsOriginatingFromRejection:T,classString:D,copyDescriptors:P,hasDevTools:"undefined"!==typeof chrome&&chrome&&"function"===typeof chrome.loadTimes,isNode:F,hasEnvVariables:I,env:L,global:l,getNativePromise:U,domainBind:V},W;q.isRecentNode=q.isNode&&(W=r.versions.node.split(".").map(Number),0===W[0]&&W[1]>10||W[0]>0),q.isNode&&q.toFastProperties(r);try{throw new Error}catch(t){q.lastLineError=t}e.exports=q},{"./es5":13}]},{},[4])(4)},"object"==c(e)&&"undefined"!=typeof t?t.exports=u():(s=[],void 0===(a="function"===typeof(o=u)?o.apply(e,s):o)||(t.exports=a)),"undefined"!==typeof window&&null!==window?window.P=window.Promise:"undefined"!==typeof self&&null!==self&&(self.P=self.Promise)}).call(this,r(7),r(6),r(56).setImmediate)},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)}function i(t){return t}e.get=function(t,r,n,o){var s;"function"==typeof n&&(n.length<2?(o=n,n=void 0):(s=n,n=void 0)),o||(o=i);var a="string"==typeof t?t.split("."):t;if(!Array.isArray(a))throw new TypeError("Invalid `path`. Must be either string or array");for(var u,c=r,l=0;l<a.length;++l){if(u=a[l],Array.isArray(c)&&!/^\d+$/.test(u)){var f=a.slice(l);return c.map(function(t){return t?e.get(f,t,n||s,o):o(void 0)})}if(s)c=s(c,u);else{var h=n&&c[n]?c[n]:c;c=h instanceof Map?h.get(u):h[u]}if(!c)return o(c)}return o(c)},e.has=function(t,e){var r="string"===typeof t?t.split("."):t;if(!Array.isArray(r))throw new TypeError("Invalid `path`. Must be either string or array");for(var i=r.length,o=e,s=0;s<i;++s){if(null==o||"object"!==n(o)||!(r[s]in o))return!1;o=o[r[s]]}return!0},e.unset=function(t,e){var r="string"===typeof t?t.split("."):t;if(!Array.isArray(r))throw new TypeError("Invalid `path`. Must be either string or array");for(var i=r.length,o=e,s=0;s<i;++s){if(null==o||"object"!==n(o)||!(r[s]in o))return!1;if(s===i-1)return delete o[r[s]],!0;o=o instanceof Map?o.get(r[s]):o[r[s]]}return!0},e.set=function(t,r,n,o,s,a){var u;"function"==typeof o&&(o.length<2?(s=o,o=void 0):(u=o,o=void 0)),s||(s=i);var c="string"==typeof t?t.split("."):t;if(!Array.isArray(c))throw new TypeError("Invalid `path`. Must be either string or array");if(null!=n){for(var l,f=a||/\$/.test(t)&&!1!==a,h=n,p=0,d=c.length-1;p<d;++p)if("$"!=(l=c[p])){if(Array.isArray(h)&&!/^\d+$/.test(l)){var y=c.slice(p);if(!f&&Array.isArray(r))for(var _=0;_<h.length&&_<r.length;++_)e.set(y,r[_],h[_],o||u,s,f);else for(_=0;_<h.length;++_)e.set(y,r,h[_],o||u,s,f);return}if(u)h=u(h,l);else{var m=o&&h[o]?h[o]:h;h=m instanceof Map?m.get(l):m[l]}if(!h)return}else if(p==d-1)break;if(l=c[d],o&&h[o]&&(h=h[o]),Array.isArray(h)&&!/^\d+$/.test(l))if(!f&&Array.isArray(r)){var v;for(_=0;_<h.length&&_<r.length;++_)(v=h[_])&&(u?u(v,l,s(r[_])):(v[o]&&(v=v[o]),v[l]=s(r[_])))}else for(_=0;_<h.length;++_)(v=h[_])&&(u?u(v,l,s(r)):(v[o]&&(v=v[o]),v[l]=s(r)));else u?u(h,l,s(r)):h instanceof Map?h.set(l,s(r)):h[l]=s(r)}}},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=1e3,o=60*i,s=60*o,a=24*s,u=365.25*a;function c(t,e,r){if(!(t<e))return t<1.5*e?Math.floor(t/e)+" "+r:Math.ceil(t/e)+" "+r+"s"}t.exports=function(t,e){e=e||{};var r,l=n(t);if("string"===l&&t.length>0)return function(t){if((t=String(t)).length>100)return;var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(!e)return;var r=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return r*u;case"days":case"day":case"d":return r*a;case"hours":case"hour":case"hrs":case"hr":case"h":return r*s;case"minutes":case"minute":case"mins":case"min":case"m":return r*o;case"seconds":case"second":case"secs":case"sec":case"s":return r*i;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}(t);if("number"===l&&!1===isNaN(t))return e.long?c(r=t,a,"day")||c(r,s,"hour")||c(r,o,"minute")||c(r,i,"second")||r+" ms":function(t){if(t>=a)return Math.round(t/a)+"d";if(t>=s)return Math.round(t/s)+"h";if(t>=o)return Math.round(t/o)+"m";if(t>=i)return Math.round(t/i)+"s";return t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,r){"use strict";var n=t.exports={};n.DocumentNotFoundError=null,n.general={},n.general.default="Validator failed for path `{PATH}` with value `{VALUE}`",n.general.required="Path `{PATH}` is required.",n.Number={},n.Number.min="Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).",n.Number.max="Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).",n.Date={},n.Date.min="Path `{PATH}` ({VALUE}) is before minimum allowed value ({MIN}).",n.Date.max="Path `{PATH}` ({VALUE}) is after maximum allowed value ({MAX}).",n.String={},n.String.enum="`{VALUE}` is not a valid enum value for path `{PATH}`.",n.String.match="Path `{PATH}` is invalid ({VALUE}).",n.String.minlength="Path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).",n.String.maxlength="Path `{PATH}` (`{VALUE}`) is longer than the maximum allowed length ({MAXLENGTH})."},function(t,e,r){"use strict";var n=r(2),i=r(3);function o(t){var e,r=n.messages;e=null!=r.DocumentNotFoundError?"function"===typeof r.DocumentNotFoundError?r.DocumentNotFoundError(t):r.DocumentNotFoundError:'No document found for query "'+i.inspect(t)+'"',n.call(this,e),this.name="DocumentNotFoundError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack,this.query=t}o.prototype=Object.create(n.prototype),o.prototype.constructor=n,t.exports=o},function(t,e,r){"use strict";var n=r(2),i=r(3);function o(t){this.errors={},this._message="",t&&"model"===t.constructor.name?(this._message=t.constructor.modelName+" validation failed",n.call(this,this._message)):(this._message="Validation failed",n.call(this,this._message)),this.name="ValidationError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack,t&&(t.errors=this.errors)}function s(t){for(var e,r=Object.keys(t.errors||{}),n=r.length,i=[],o=0;o<n;++o)e=r[o],t!==t.errors[e]&&i.push(e+": "+t.errors[e].message);return i.join(", ")}o.prototype=Object.create(n.prototype),o.prototype.constructor=n,o.prototype.toString=function(){return this.name+": "+s(this)},o.prototype.inspect=function(){return Object.assign(new Error(this.message),this)},i.inspect.custom&&(o.prototype[i.inspect.custom]=o.prototype.inspect),o.prototype.toJSON=function(){return Object.assign({},this,{message:this.message})},o.prototype.addError=function(t,e){this.errors[t]=e,this.message=this._message+": "+s(this)},t.exports=o},function(t,e,r){"use strict";var n=r(2);function i(t){var e=t.message;e||(e=n.messages.general.default);var r=this.formatMessage(e,t);n.call(this,r),t=Object.assign({},t,{message:r}),this.name="ValidatorError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack,this.properties=t,this.kind=t.type,this.path=t.path,this.value=t.value,this.reason=t.reason}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,Object.defineProperty(i.prototype,"properties",{enumerable:!1,writable:!0,value:null}),i.prototype.formatMessage=function(t,e){if("function"===typeof t)return t(e);for(var r=Object.keys(e),n=0;n<r.length;++n){var i=r[n];"message"!==i&&(t=t.replace("{"+i.toUpperCase()+"}",e[i]))}return t},i.prototype.toString=function(){return this.message},t.exports=i},function(t,e,r){"use strict";var n=r(2);function i(t,e,r){n.call(this,'No matching document found for id "'+t._id+'" version '+e),this.name="VersionError",this.version=e,this.modifiedPaths=r}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,t.exports=i},function(t,e,r){"use strict";var n=r(2);function i(t){n.call(this,"Can't save() the same doc multiple times in parallel. Document: "+t.id),this.name="ParallelSaveError"}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,t.exports=i},function(t,e,r){"use strict";var n=r(2);function i(t){n.call(this,"Cannot overwrite `"+t+"` model once compiled."),this.name="OverwriteModelError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,t.exports=i},function(t,e,r){"use strict";var n=r(2);function i(t){var e="Schema hasn't been registered for model \""+t+'".\nUse mongoose.model(name, schema)';n.call(this,e),this.name="MissingSchemaError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,t.exports=i},function(t,e,r){"use strict";var n=r(2);function i(t){var e="For your own good, using `document.save()` to update an array which was selected using an $elemMatch projection OR populated using skip, limit, query conditions, or exclusion of the _id field when the operation results in a $pop or $set of the entire array is not supported. The following path(s) would have been modified unsafely:\n "+t.join("\n ")+"\nUse Model.update() to update these arrays instead.";n.call(this,e),this.name="DivergentArrayError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,t.exports=i},function(t,e,r){"use strict";(function(e){function r(){this._pres=new Map,this._posts=new Map}function n(t,e,r,n,i,o,s){if(o.useErrorHandlers){var a={error:e};return t.execPost(r,n,i,a,function(t){return"function"===typeof s&&s(t)})}return"function"===typeof s?s(e):void 0}function i(t,e,r){return t.has(e)?t.get(e):r}function o(t,e,r,n){var i;try{i=t.apply(e,r)}catch(t){return n(t)}s(i)&&i.then(function(){return n()},function(t){return n(t)})}function s(t){return null!=t&&"function"===typeof t.then}function a(t){var r=!1,n=this;return function(){var i=arguments;if(!r)return r=!0,e.nextTick(function(){return t.apply(n,i)})}}r.prototype.execPre=function(t,r,n,u){3===arguments.length&&(u=n,n=[]);var c=i(this._pres,t,[]),l=c.length,f=0,h=c.numAsync||0,p=!1,d=n;if(!l)return e.nextTick(function(){u(null)});var y=function t(){if(!(f>=l)){var n=c[f];if(n.isAsync){var i=[a(_),a(function(t){if(t){if(p)return;return p=!0,u(t)}if(0===--h&&f>=l)return u(null)})];o(n.fn,r,i,i[0])}else if(n.fn.length>0){i=[a(_)];for(var y=arguments.length>=2?arguments:[null].concat(d),m=1;m<y.length;++m)i.push(y[m]);o(n.fn,r,i,i[0])}else{var v=null,g=null;try{g=n.fn.call(r)}catch(t){v=t}if(s(g))g.then(function(){return _()},function(t){return _(t)});else{if(++f>=l)return h>0?void 0:e.nextTick(function(){u(v)});t(v)}}}};function _(t){if(t){if(p)return;return p=!0,u(t)}if(++f>=l)return h>0?void 0:u(null);y.apply(r,arguments)}y.apply(null,[null].concat(n))},r.prototype.execPreSync=function(t,e,r){for(var n=i(this._pres,t,[]),o=n.length,s=0;s<o;++s)n[s].fn.apply(e,r||[])},r.prototype.execPost=function(t,r,n,u,c){arguments.length<5&&(c=u,u=null);var l=i(this._posts,t,[]),f=l.length,h=0,p=null;if(u&&u.error&&(p=u.error),!f)return e.nextTick(function(){c.apply(null,[p].concat(n))});!function t(){for(var e=l[h],i=0,u=n.length,d=[],y=0;y<u;++y)i+=n[y]&&n[y]._kareemIgnore?0:1,n[y]&&n[y]._kareemIgnore||d.push(n[y]);if(p)if(e.length===i+2){var _=a(function(e){if(e&&(p=e),++h>=f)return c.call(null,p);t()});o(e,r,[p].concat(d).concat([_]),_)}else{if(++h>=f)return c.call(null,p);t()}else{var m=a(function(e){return e?(p=e,t()):++h>=f?c.apply(null,[null].concat(n)):void t()});if(e.length===i+2)return++h>=f?c.apply(null,[null].concat(n)):t();if(e.length===i+1)o(e,r,d.concat([m]),m);else{var v,g;try{g=e.apply(r,d)}catch(t){v=t,p=t}if(s(g))return g.then(function(){return m()},function(t){return m(t)});if(++h>=f)return c.apply(null,[v].concat(n));t()}}}()},r.prototype.execPostSync=function(t,e,r){for(var n=i(this._posts,t,[]),o=n.length,s=0;s<o;++s)n[s].apply(e,r||[])},r.prototype.createWrapperSync=function(t,e){var r=this;return function(){r.execPreSync(t,this,arguments);var n=e.apply(this,arguments);return r.execPostSync(t,this,[n]),n}},r.prototype.wrap=function(t,e,r,i,o){var s=i.length>0?i[i.length-1]:null,a=("function"===typeof s&&i.slice(0,i.length-1),this),u=(o=o||{}).checkForPromise;this.execPre(t,r,i,function(c){if(c){for(var l=o.numCallbackParams||0,f=o.contextParameter?[r]:[],h=f.length;h<l;++h)f.push(null);return n(a,c,t,r,f,o,s)}var p="function"===typeof s?i.length-1:i.length,d=e.length,y=e.apply(r,i.slice(0,p).concat(_));if(u){if(null!=y&&"function"===typeof y.then)return y.then(function(t){return _(null,t)},function(t){return _(t)});if(d<p+1)return _(null,y)}function _(){var e=Array.prototype.slice.call(arguments,1);if(o.nullResultByDefault&&0===e.length&&e.push(null),arguments[0])return n(a,arguments[0],t,r,e,o,s);a.execPost(t,r,e,function(){return arguments[0]?"function"===typeof s?s(arguments[0]):void 0:"function"===typeof s?s.apply(r,arguments):void 0})}})},r.prototype.hasHooks=function(t){return this._pres.has(t)||this._posts.has(t)},r.prototype.createWrapper=function(t,r,n,i){var o=this;return this.hasHooks(t)?function(){var e=n||this,s=Array.prototype.slice.call(arguments);o.wrap(t,r,e,s,i)}:function(){var t=this,n=arguments;e.nextTick(function(){return r.apply(t,n)})}},r.prototype.pre=function(t,e,r,n,o){"boolean"!==typeof arguments[1]&&(r,r=e,e=!1);var s=i(this._pres,t,[]);return this._pres.set(t,s),e&&(s.numAsync=s.numAsync||0,++s.numAsync),o?s.unshift({fn:r,isAsync:e}):s.push({fn:r,isAsync:e}),this},r.prototype.post=function(t,e,r){var n=i(this._posts,t,[]);return r?n.unshift(e):n.push(e),this._posts.set(t,n),this},r.prototype.clone=function(){var t=new r,e=!0,n=!1,i=void 0;try{for(var o,s=this._pres.keys()[Symbol.iterator]();!(e=(o=s.next()).done);e=!0){var a=o.value,u=this._pres.get(a).slice();u.numAsync=this._pres.get(a).numAsync,t._pres.set(a,u)}}catch(t){n=!0,i=t}finally{try{e||null==s.return||s.return()}finally{if(n)throw i}}var c=!0,l=!1,f=void 0;try{for(var h,p=this._posts.keys()[Symbol.iterator]();!(c=(h=p.next()).done);c=!0){var d=h.value;t._posts.set(d,this._posts.get(d).slice())}}catch(t){l=!0,f=t}finally{try{c||null==p.return||p.return()}finally{if(l)throw f}}return t},r.prototype.merge=function(t){var e=this.clone(),r=!0,n=!1,o=void 0;try{for(var s,a=function(){var r=s.value,n=i(e._pres,r,[]),o=t._pres.get(r).filter(function(t){return-1===n.map(function(t){return t.fn}).indexOf(t.fn)}),a=n.concat(o);a.numAsync=n.numAsync||0,a.numAsync+=o.filter(function(t){return t.isAsync}).length,e._pres.set(r,a)},u=t._pres.keys()[Symbol.iterator]();!(r=(s=u.next()).done);r=!0)a()}catch(t){n=!0,o=t}finally{try{r||null==u.return||u.return()}finally{if(n)throw o}}var c=!0,l=!1,f=void 0;try{for(var h,p=function(){var r=h.value,n=i(e._posts,r,[]),o=t._posts.get(r).filter(function(t){return-1===n.indexOf(t)});e._posts.set(r,n.concat(o))},d=t._posts.keys()[Symbol.iterator]();!(c=(h=d.next()).done);c=!0)p()}catch(t){l=!0,f=t}finally{try{c||null==d.return||d.return()}finally{if(l)throw f}}return e},t.exports=r}).call(this,r(7))},function(t,e,r){"use strict";var n=r(8),i=r(0);t.exports=function(t){var e=[],r=new WeakMap,o=t.constructor.indexTypes;return function t(s,a){if(!r.has(s)){r.set(s,!0),a=a||"";for(var u=Object.keys(s.paths),c=u.length,l=0;l<c;++l){var f=u[l],h=s.paths[f];if(h.$isMongooseDocumentArray||h.$isSingleNested){if(!0!==n(h,"options.excludeIndexes")&&!0!==n(h,"schemaOptions.excludeIndexes")&&t(h.schema,a+f+"."),null!=h.schema.discriminators)for(var p=h.schema.discriminators,d=Object.keys(p),y=0;y<d.length;y++)t(p[d[y]]._originalSchema,a+f+".");if(h.$isMongooseDocumentArray)continue}var _=h._index||h.caster&&h.caster._index;if(!1!==_&&null!==_&&void 0!==_){var m={},v=i.isObject(_),g=v?_:{},b="string"===typeof _?_:!!v&&_.type;b&&-1!==o.indexOf(b)?m[a+f]=b:g.text?(m[a+f]="text",delete g.text):m[a+f]=1,delete g.type,"background"in g||(g.background=!0),e.push([m,g])}}r.delete(s),a?function(t,r){for(var n=t._indexes,i=n.length,o=0;o<i;++o){for(var s=n[o][0],a=Object.keys(s),u=a.length,c={},l=0;l<u;++l){var f=a[l];c[r+f]=s[f]}e.push([c,n[o][1]])}}(s,a):(s._indexes.forEach(function(t){"background"in t[1]||(t[1].background=!0)}),e=e.concat(s._indexes))}}(t),e}},function(t,e,r){"use strict";var n=r(9);t.exports=function(t,e){if(isNaN(t))throw new n("number",t,e);if(null==t)return t;if(""===t)return null;if("string"!==typeof t&&"boolean"!==typeof t||(t=Number(t)),isNaN(t))throw new n("number",t,e);if(t instanceof Number)return t;if("number"===typeof t)return t;if(!Array.isArray(t)&&"function"===typeof t.valueOf)return Number(t.valueOf());if(t.toString&&!Array.isArray(t)&&t.toString()==Number(t))return new Number(t);throw new n("number",t,e)}},function(t,e,r){"use strict";var n,i,o=r(46),s=r(9),a=r(11).EventEmitter,u=r(5),c=r(74),l=r(3),f=r(0),h=r(21).getDiscriminatorByValue;function p(t,e,r,n){var i=d(e,r);i.prototype.$basePath=t,o.call(this,t,i,r),this.schema=e,this.schemaOptions=n||{},this.$isMongooseDocumentArray=!0;var s=this.defaultValue;"defaultValue"in this&&void 0===s||this.default(function(){var t=s.call(this);return Array.isArray(t)||(t=[t]),t})}function d(t,e){function n(){i.apply(this,arguments)}for(var o in i||(i=r(17)),n.prototype=Object.create(i.prototype),n.prototype.$__setSchema(t),n.schema=t,n.prototype.constructor=n,n.$isArraySubdocument=!0,t.methods)n.prototype[o]=t.methods[o];for(o in t.statics)n[o]=t.statics[o];for(o in a.prototype)n[o]=a.prototype[o];return n.options=e,n}function y(t){if(null!=t&&null!=t._parent)for(var e in t._handlers)t._parent.removeListener(e,t._handlers[e])}function _(t,e,r){if(r&&e){for(var n,i,o,s=t.path+".",a=Object.keys(e),u=a.length,c={};u--;)if(0===(i=a[u]).indexOf(s)){if("$"===(o=i.substring(s.length)))continue;0===o.indexOf("$.")&&(o=o.substr(2)),n||(n=!0),c[o]=e[i]}return n&&c||void 0}}p.schemaName="DocumentArray",p.prototype=Object.create(o.prototype),p.prototype.constructor=p,p.prototype.discriminator=function(t,e){"function"===typeof t&&(t=f.getFunctionName(t));var r=d(e=c(this.casterConstructor,t,e));r.baseCasterConstructor=this.casterConstructor;try{Object.defineProperty(r,"name",{value:t})}catch(t){}return this.casterConstructor.discriminators[t]=r,this.casterConstructor.discriminators[t]},p.prototype.doValidate=function(t,e,o,s){n||(n=r(13));var a=this;u.prototype.doValidate.call(this,t,function(r){if(r)return e(r);var u,c=t&&t.length;if(!c)return e();if(s&&s.updateValidator)return e();function l(t){t&&(u=t),--c||e(u)}t.isMongooseDocumentArray||(t=new n(t,a.path,o));for(var f=0,h=c;f<h;++f){var p=t[f];null!=p?(p instanceof i||(p=t[f]=new a.casterConstructor(p,t,void 0,void 0,f)),p.$__validate(l)):--c||e(u)}},o)},p.prototype.doValidateSync=function(t,e){var r=u.prototype.doValidateSync.call(this,t,e);if(r)return r;var n=t&&t.length,o=null;if(n){for(var s=0,a=n;s<a&&!o;++s){var c=t[s];if(c){c instanceof i||(c=t[s]=new this.casterConstructor(c,t,void 0,void 0,s));var l=c.validateSync();l&&(o=l)}}return o}},p.prototype.cast=function(t,e,o,a,u){var c,p,d;n||(n=r(13));var m={transform:!1,virtuals:!1};if(!Array.isArray(t))return e&&o&&e.markModified(this.path),this.cast([t],e,o,a);for(t&&t.isMongooseDocumentArray||u&&u.skipDocumentArrayCast?t&&t.isMongooseDocumentArray&&(t=new n(t,this.path,e)):(t=new n(t,this.path,e),y(a)),d=t.length;d--;)if(t[d]){var v=this.casterConstructor;if(v.discriminators&&v.schema&&v.schema.options&&"string"===typeof t[d][v.schema.options.discriminatorKey])if(v.discriminators[t[d][v.schema.options.discriminatorKey]])v=v.discriminators[t[d][v.schema.options.discriminatorKey]];else{var g=h(v,t[d][v.schema.options.discriminatorKey]);g&&(v=g)}if(t[d].$__&&t[d].schema!==v.schema&&(t[d]=t[d].toObject({transform:!1,virtuals:!1})),!(t[d]instanceof i)&&t[d])if(o)e?c||(c=_(this,e.$__.selected,o)):c=!0,p=new v(null,t,!0,c,d),t[d]=p.init(t[d]);else if(a&&(p=a.id(t[d]._id))&&(p=a.id(t[d]._id)),a&&p&&f.deepEqual(p.toObject(m),t[d]))p.set(t[d]),t[d]=p;else try{p=new v(t[d],t,void 0,void 0,d),t[d]=p}catch(e){y(t);var b=l.inspect(t[d]);throw new s("embedded",b,t._path,e)}}return t},t.exports=p},function(t,e,r){"use strict";function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(72),o=r(65),s=r(120),a=r(8),u=r(3),c=r(0),l=["Polygon","MultiPolygon"];function f(t,e,r){if(Array.isArray(t))t.forEach(function(n,i){if(Array.isArray(n)||c.isObject(n))return f(n,e,r);t[i]=e.castForQueryWrapper({val:n,context:r})});else for(var n=Object.keys(t),i=n.length;i--;){var o=n[i],s=t[o];Array.isArray(s)||c.isObject(s)?(f(s,e,r),t[o]=s):t[o]=e.castForQuery({val:s,context:r})}}t.exports=function t(e,r,h,p){if(Array.isArray(r))throw new Error("Query filter must be an object, got an array ",u.inspect(r));var d,y,_,m,v,g,b=Object.keys(r),w=b.length;for(h=h||{};w--;)if(g=r[m=b[w]],"$or"===m||"$nor"===m||"$and"===m)for(var O=g.length;O--;)g[O]=t(e,g[O],h,p);else{if("$where"===m){if("string"!==(v=n(g))&&"function"!==v)throw new Error("Must have a string or function for $where");"function"===v&&(r[m]=g.toString());continue}if("$elemMatch"===m)g=t(e,g,h,p);else if("$text"===m)g=s(g,m);else{if(!e)continue;if(!(y=e.path(m)))for(var S=m.split("."),E=S.length;E--;){var A=S.slice(0,E).join("."),$=S.slice(E).join("."),N=e.path(A),j=a(N,"schema.options.discriminatorKey");if(null!=N&&null!=a(N,"schema.discriminators")&&null!=j&&$!==j){var x=a(r,A+"."+j);x&&(y=N.schema.discriminators[x].path($))}}if(y){if(null==g)continue;if("Object"===g.constructor.name)if(Object.keys(g).some(function(t){return"$"===t.charAt(0)&&"$id"!==t&&"$ref"!==t})){var T,B=Object.keys(g);for(O=B.length;O--;)if(_=g[T=B[O]],"$not"===T){if(_&&y&&!y.caster){if((d=Object.keys(_)).length&&"$"===d[0].charAt(0))for(var k in _)_[k]=y.castForQueryWrapper({$conditional:k,val:_[k],context:p});else g[T]=y.castForQueryWrapper({$conditional:T,val:_,context:p});continue}t(y.caster?y.caster.schema:e,_,h,p)}else g[T]=y.castForQueryWrapper({$conditional:T,val:_,context:p})}else r[m]=y.castForQueryWrapper({val:g,context:p});else if("Array"===g.constructor.name&&-1===["Buffer","Array"].indexOf(y.instance)){for(var C=[],D=0;D<g.length;D++)C.push(y.castForQueryWrapper({val:g[D],context:p}));r[m]={$in:C}}else r[m]=y.castForQueryWrapper({val:g,context:p})}else{for(var P,M,R,F=m.split("."),I=F.length;I--&&(P=F.slice(0,I).join("."),!(y=e.path(P))););if(y){y.caster&&y.caster.schema?((R={})[M=F.slice(I).join(".")]=g,r[m]=t(y.caster.schema,R,h,p)[M]):r[m]=g;continue}if(c.isObject(g)){var L="";if(g.$near?L="$near":g.$nearSphere?L="$nearSphere":g.$within?L="$within":g.$geoIntersects?L="$geoIntersects":g.$geoWithin&&(L="$geoWithin"),L){var U=new o.Number("__QueryCasting__"),V=g[L];if(null!=g.$maxDistance&&(g.$maxDistance=U.castForQueryWrapper({val:g.$maxDistance,context:p})),null!=g.$minDistance&&(g.$minDistance=U.castForQueryWrapper({val:g.$minDistance,context:p})),"$within"===L){var q=V.$center||V.$centerSphere||V.$box||V.$polygon;if(!q)throw new Error("Bad $within parameter: "+JSON.stringify(g));V=q}else if("$near"===L&&"string"===typeof V.type&&Array.isArray(V.coordinates))V=V.coordinates;else if(("$near"===L||"$nearSphere"===L||"$geoIntersects"===L)&&V.$geometry&&"string"===typeof V.$geometry.type&&Array.isArray(V.$geometry.coordinates))null!=V.$maxDistance&&(V.$maxDistance=U.castForQueryWrapper({val:V.$maxDistance,context:p})),null!=V.$minDistance&&(V.$minDistance=U.castForQueryWrapper({val:V.$minDistance,context:p})),c.isMongooseObject(V.$geometry)&&(V.$geometry=V.$geometry.toObject({transform:!1,virtuals:!1})),V=V.$geometry.coordinates;else if("$geoWithin"===L)if(V.$geometry){c.isMongooseObject(V.$geometry)&&(V.$geometry=V.$geometry.toObject({virtuals:!1}));var W=V.$geometry.type;if(-1===l.indexOf(W))throw new Error('Invalid geoJSON type for $geoWithin "'+W+'", must be "Polygon" or "MultiPolygon"');V=V.$geometry.coordinates}else V=V.$box||V.$polygon||V.$center||V.$centerSphere,c.isMongooseObject(V)&&(V=V.toObject({virtuals:!1}));f(V,U,p);continue}}if(h.upsert&&h.strict&&!e.nested[m]){if("throw"===h.strict)throw new i(m);throw new i(m,'Path "'+m+'" is not in schema, strict mode is `true`, and upsert is `true`.')}if("throw"===h.strictQuery)throw new i(m,'Path "'+m+'" is not in schema and strictQuery is true.');h.strictQuery&&delete r[m]}}}return r}},function(t,e,r){"use strict";function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(9),o=r(40),s=r(67);t.exports=function(t,e){if(null==t||"object"!==n(t))throw new i("$text",t,e);return null!=t.$search&&(t.$search=s(t.$search,e+".$search")),null!=t.$language&&(t.$language=s(t.$language,e+".$language")),null!=t.$caseSensitive&&(t.$caseSensitive=o(t.$caseSensitive,e+".$castSensitive")),null!=t.$diacriticSensitive&&(t.$diacriticSensitive=o(t.$diacriticSensitive,e+".$diacriticSensitive")),t}},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=r(9),s=r(11).EventEmitter,a=r(75),u=r(5),c=r(39),l=r(22).castToNumber,f=r(74),h=r(73),p=r(21).getDiscriminatorByValue,d=r(12).internalToObjectOptions;function y(t,e,r){this.caster=_(t),this.caster.prototype.$basePath=e,this.schema=t,this.$isSingleNested=!0,u.call(this,e,r,"Embedded")}function _(t){i||(i=r(64));var e=function(t,e,r){var n=this;this.$parent=r,i.apply(this,arguments),r&&(r.on("save",function(){n.emit("save",n),n.constructor.emit("save",n)}),r.on("isNew",function(t){n.isNew=t,n.emit("isNew",t),n.constructor.emit("isNew",t)}))};for(var n in(e.prototype=Object.create(i.prototype)).$__setSchema(t),e.prototype.constructor=e,e.schema=t,e.$isSingleNested=!0,e.prototype.toBSON=function(){return this.toObject(d)},t.methods)e.prototype[n]=t.methods[n];for(n in t.statics)e[n]=t.statics[n];for(n in s.prototype)e[n]=s.prototype[n];return e}t.exports=y,y.prototype=Object.create(u.prototype),y.prototype.$conditionalHandlers.$geoWithin=function(t){return{$geometry:this.castForQuery(t.$geometry)}},y.prototype.$conditionalHandlers.$near=y.prototype.$conditionalHandlers.$nearSphere=h.cast$near,y.prototype.$conditionalHandlers.$within=y.prototype.$conditionalHandlers.$geoWithin=h.cast$within,y.prototype.$conditionalHandlers.$geoIntersects=h.cast$geoIntersects,y.prototype.$conditionalHandlers.$minDistance=l,y.prototype.$conditionalHandlers.$maxDistance=l,y.prototype.$conditionalHandlers.$exists=c,y.prototype.cast=function(t,e,r,i){if(t&&t.$isSingleNested)return t;if(null!=t&&("object"!==n(t)||Array.isArray(t)))throw new a(this.path,t);var o,s=this.caster,u=s.schema.options.discriminatorKey;if(null!=t&&s.discriminators&&"string"===typeof t[u])if(s.discriminators[t[u]])s=s.discriminators[t[u]];else{var c=p(s,t[u]);c&&(s=c)}return r?((o=new s(void 0,e?e.$__.selected:void 0,e)).init(t),o):0===Object.keys(t).length?new s({},e?e.$__.selected:void 0,e):new s(t,e?e.$__.selected:void 0,e,void 0,{priorDoc:i})},y.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(!(r=this.$conditionalHandlers[t]))throw new Error("Can't use "+t);return r.call(this,e)}if(null==(e=t))return e;this.options.runSetters&&(e=this._applySetters(e));var n=this.caster,i=n.schema.options.discriminatorKey;if(null!=e&&n.discriminators&&"string"===typeof e[i])if(n.discriminators[e[i]])n=n.discriminators[e[i]];else{var s=p(n,e[i]);s&&(n=s)}try{e=new n(e)}catch(t){if(!(t instanceof o))throw new o("Embedded",e,this.path,t);throw t}return e},y.prototype.doValidate=function(t,e,r,n){var i=this.caster,o=i.schema.options.discriminatorKey;if(null!=t&&i.discriminators&&"string"===typeof t[o])if(i.discriminators[t[o]])i=i.discriminators[t[o]];else{var s=p(i,t[o]);s&&(i=s)}if(n&&n.skipSchemaValidators)return t instanceof i||(t=new i(t,null,r)),t.validate(e);u.prototype.doValidate.call(this,t,function(r){return r?e(r):t?void t.validate(e):e(null)},r)},y.prototype.doValidateSync=function(t,e,r){if(!r||!r.skipSchemaValidators){var n=u.prototype.doValidateSync.call(this,t,e);if(n)return n}if(t)return t.validateSync()},y.prototype.discriminator=function(t,e){return f(this.caster,t,e),this.caster.discriminators[t]=_(e),this.caster.discriminators[t]}},function(t,e,r){"use strict";(function(e){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=r(5),s=o.CastError,a=r(33),u=r(0);function c(t,e){o.call(this,t,e,"Decimal128")}function l(t){return this.cast(t)}c.schemaName="Decimal128",c.prototype=Object.create(o.prototype),c.prototype.constructor=c,c.prototype.checkRequired=function(t,e){return o._isRef(this,t,e,!0)?!!t:t instanceof a},c.prototype.cast=function(t,c,l){if(o._isRef(this,t,c,l)){if(null===t||void 0===t)return t;if(i||(i=r(4)),t instanceof i)return t.$__.wasPopulated=!0,t;if(t instanceof a)return t;if(e.isBuffer(t)||!u.isObject(t))throw new s("Decimal128",t,this.path);var f=c.$__fullPath(this.path),h=(c.ownerDocument?c.ownerDocument():c).populated(f,!0),p=t;return c.$__.populated&&c.$__.populated[f]&&c.$__.populated[f].options&&c.$__.populated[f].options.options&&c.$__.populated[f].options.options.lean||((p=new h.options.model(t)).$__.wasPopulated=!0),p}if(null==t)return t;if("object"===n(t)&&"string"===typeof t.$numberDecimal)return a.fromString(t.$numberDecimal);if(t instanceof a)return t;if("string"===typeof t)return a.fromString(t);if(e.isBuffer(t))return new a(t);if("number"===typeof t)return a.fromString(String(t));if("function"===typeof t.valueOf&&"string"===typeof t.valueOf())return a.fromString(t.valueOf());throw new s("Decimal128",t,this.path)},c.prototype.$conditionalHandlers=u.options(o.prototype.$conditionalHandlers,{$gt:l,$gte:l,$lt:l,$lte:l}),t.exports=c}).call(this,r(1).Buffer)},function(t,e,r){"use strict";function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function o(t,e){return!e||"object"!==n(e)&&"function"!==typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var u=r(63),c=r(5),l=function(t){function e(t,r){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=o(this,s(e).call(this,t,r,"Map"))).$isSchemaMap=!0,n}var r,n,l;return function(t,e){if("function"!==typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&a(t,e)}(e,c),r=e,(n=[{key:"cast",value:function(t,e){return t instanceof u?t:new u(t,this.path,e,this.$__schemaType)}}])&&i(r.prototype,n),l&&i(r,l),e}();t.exports=l},function(t,e,r){"use strict";var n=r(2);function i(t,e,r){n.call(this,'Parameter "'+e+'" to '+r+"() must be an object, got "+t.toString()),this.name="ObjectParameterError",Error.captureStackTrace?Error.captureStackTrace(this):this.stack=(new Error).stack}i.prototype=Object.create(n.prototype),i.prototype.constructor=n,t.exports=i},function(t,e,r){"use strict";(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=r(10),o=r(0);function s(e){return e&&"object"===n(e)&&!(e instanceof Date)&&!(e instanceof i)&&(!Array.isArray(e)||e.length>0)&&!(e instanceof t)}e.flatten=function e(r,n,i){var a;a=r&&o.isMongooseObject(r)&&!t.isBuffer(r)?Object.keys(r.toObject({transform:!1,virtuals:!1})):Object.keys(r||{});var u=a.length;var c={};n=n?n+".":"";for(var l=0;l<u;++l){var f=a[l],h=r[f];if(c[n+f]=h,s(h)){if(i&&i.skipArrays&&Array.isArray(h))continue;var p=e(h,n+f,i);for(var d in p)c[d]=p[d];Array.isArray(h)&&(c[n+f]=h)}}return c},e.modifiedPaths=function e(r,n,i){var a=Object.keys(r||{});var u=a.length;i=i||{};n=n?n+".":"";for(var c=0;c<u;++c){var l=a[c],f=r[l];i[n+l]=!0,o.isMongooseObject(f)&&!t.isBuffer(f)&&(f=f.toObject({transform:!1,virtuals:!1})),s(f)&&e(f,n+l,i)}return i}}).call(this,r(1).Buffer)},function(t,e,r){"use strict";var n=r(8);t.exports=function(t,e,r){for(var i=(r=r||{}).typeOnly,o=e.split("."),s=null,a="adhocOrUndefined",u=0;u<o.length;++u){var c=o.slice(0,u+1).join(".");if(null!=(s=t.schema.path(c))&&(a=t.schema.pathType(c),(s.$isSingleNested||s.$isMongooseDocumentArrayElement)&&null!=s.schema.discriminators)){var l=s.schema.discriminators,f=t.get(c+"."+n(s,"schema.options.discriminatorKey"));if(null==f||null==l[f])continue;var h=o.slice(u+1).join(".");if(null!=(s=l[f].path(h))){a=l[f].pathType(h);break}}}return i?a:s}},function(t,e,r){"use strict";function n(){return null!=this._id?String(this._id):null}t.exports=function(t){!t.paths.id&&!t.options.noVirtualId&&t.options.id&&t.virtual("id").get(n)}},function(t,e,r){"use strict";var n=r(41);t.exports=function(t){var e=Object.keys(t),r=e.length,i=null;if(1===r&&"_id"===e[0])i=!!t[e[r]];else for(;r--;)if("_id"!==e[r]&&n(t[e[r]])){i=!t[e[r]];break}return i}},function(t,e,r){"use strict";var n=r(4),i=r(11).EventEmitter,o=r(2),s=r(43),a=r(10),u=o.ValidationError,c=r(130),l=r(0);function f(t,e,r,i,u){if(!(this instanceof f))return new f(t,e,r,i,u);if(l.isObject(e)&&!e.instanceOfSchema&&(e=new s(e)),e=this.schema||e,!this.schema&&e.options._id&&void 0===(t=t||{})._id&&(t._id=new a),!e)throw new o.MissingSchemaError;for(var h in this.$__setSchema(e),n.call(this,t,r,i,u),c(this,e,{decorateDoc:!0}),e.methods)this[h]=e.methods[h];for(var p in e.statics)this[p]=e.statics[p]}f.prototype=Object.create(n.prototype),f.prototype.constructor=f,f.$emitter=new i,l.each(["on","once","emit","listeners","removeListener","setMaxListeners","removeAllListeners","addListener"],function(t){f[t]=function(){return f.$emitter[t].apply(f.$emitter,arguments)}}),f.ValidationError=u,t.exports=f},function(t,e,r){"use strict";var n=r(0);t.exports=function t(e,r,i){i=i||{};var o={useErrorHandlers:!0,numCallbackParams:1,nullResultByDefault:!0,contextParameter:!0};var s=i.decorateDoc?e:e.prototype;e.$appliedHooks=!0;for(var a=0;a<r.childSchemas.length;++a){var u=r.childSchemas[a].model;if(!u.$appliedHooks&&(t(u,r.childSchemas[a].schema,i),null!=u.discriminators))for(var c=Object.keys(u.discriminators),l=0;l<c.length;++l)t(u.discriminators[c[l]],u.discriminators[c[l]].schema,i)}s.$__save=r.s.hooks.createWrapper("save",s.$__save,null,o);s.$__validate=r.s.hooks.createWrapper("validate",s.$__validate,null,o);s.$__remove=r.s.hooks.createWrapper("remove",s.$__remove,null,o);s.$__init=r.s.hooks.createWrapperSync("init",s.$__init,null,o);var f=Object.keys(r.methods);var h=Object.assign({},o,{checkForPromise:!0});var p=function(){var t=f[d];if(!r.s.hooks.hasHooks(t))return"continue";var e=s[t];s[t]=function(){var e=this,r=Array.prototype.slice.call(arguments),i=n.last(r),o=null==i?r:r.slice(0,r.length-1);return n.promiseOrCallback(i,function(r){e["$__".concat(t)].apply(e,o.concat([r]))})},s["$__".concat(t)]=r.s.hooks.createWrapper(t,e,null,h)};for(var d=0;d<f.length;d++)p()}}])});