UNPKG

passport-negotiate

Version:

Negotiate (kerberos) authentication strategy for Passport.

2 lines 286 kB
!function t(e,r,n){function i(s,a){if(!r[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var c=r[s]={exports:{}};e[s][0].call(c.exports,function(t){var r=e[s][1][t];return i(r?r:t)},c,c.exports,t,e,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(t,e){function r(){throw"Can't use ES6 promise with mpromise style constructor"}r.use=function(t){r.ES6=t},e.exports=r},{}],2:[function(t,e,r){(function(n){r.Error=t("./error"),r.Schema=t("./schema"),r.Types=t("./types"),r.VirtualType=t("./virtualtype"),r.SchemaType=t("./schematype.js"),r.utils=t("./utils.js"),r.Document=t("./document_provider.js")(),"undefined"!=typeof window&&(window.mongoose=e.exports,window.Buffer=n)}).call(this,t("buffer").Buffer)},{"./document_provider.js":6,"./error":12,"./schema":24,"./schematype.js":35,"./types":41,"./utils.js":43,"./virtualtype":44,buffer:47}],3:[function(t,e,r){function n(t,e,r,i,f){if(!(this instanceof n))return new n(t,e,r,i,f);if(!c.isObject(e)||e instanceof a||(e=new a(e)),e=this.schema||e,!this.schema&&e.options._id&&(t=t||{},void 0===t._id&&(t._id=new u)),!e)throw new s.MissingSchemaError;this.$__setSchema(e),this.$__=new h,this.$__.emitter=new o,this.isNew=!0,this.errors=void 0,"boolean"==typeof r?(this.$__.strictMode=r,r=void 0):(this.$__.strictMode=this.schema.options&&this.schema.options.strict,this.$__.selected=r);for(var l=this.schema.requiredPaths(),p=0;p<l.length;++p)this.$__.activePaths.require(l[p]);this.$__.emitter.setMaxListeners(0),this._doc=this.$__buildDoc(t,r,i),!f&&t&&this.init(t),this.$__registerHooksFromSchema();for(var d in e.methods)this[d]=e.methods[d];for(var y in e.statics)this[y]=e.statics[y]}var i=t("./document"),o=t("events").EventEmitter,s=t("./error"),a=t("./schema"),u=t("./types/objectid"),c=t("./utils"),f=s.ValidationError,h=t("./internal");n.prototype=Object.create(i.prototype),n.prototype.constructor=n,n.ValidationError=f,e.exports=r=n},{"./document":5,"./error":12,"./internal":21,"./schema":24,"./types/objectid":42,"./utils":43,events:51}],4:[function(t,e){var r=t("./utils"),n=t("./schema/index"),i=e.exports=function(t,e){for(var o,s,a,u,c,f,h=Object.keys(e),l=h.length;l--;)if(u=h[l],f=e[u],"$or"===u||"$nor"===u||"$and"===u)for(var p=f.length;p--;)f[p]=i(t,f[p]);else{if("$where"===u){if(c=typeof f,"string"!==c&&"function"!==c)throw new Error("Must have a string or function for $where");"function"===c&&(e[u]=f.toString());continue}if(!t)continue;if(s=t.path(u)){if(null===f||void 0===f)continue;if("Object"===f.constructor.name)if(o=Object.keys(f).some(function(t){return"$"===t.charAt(0)&&"$id"!==t&&"$ref"!==t})){var d,y=Object.keys(f);for(p=y.length;p--;)if(d=y[p],a=f[d],"$exists"!==d){if("$type"!==d)"$not"===d?i(t,a):f[d]=s.castForQuery(d,a);else if("number"!=typeof a)throw new Error("$type parameter must be Number")}else if("boolean"!=typeof a)throw new Error("$exists parameter must be Boolean")}else e[u]=s.castForQuery(f);else e[u]=s.castForQuery(f)}else{for(var _,g,v,m=u.split("."),b=m.length;b--&&(_=m.slice(0,b).join("."),!(s=t.path(_))););if(s){s.caster&&s.caster.schema?(v={},g=m.slice(b).join("."),v[g]=f,e[u]=i(s.caster.schema,v)[g]):e[u]=f;continue}if(r.isObject(f)){var w=f.$near?"$near":f.$nearSphere?"$nearSphere":f.$within?"$within":f.$geoIntersects?"$geoIntersects":"";if(!w)continue;var E=new n.Number("__QueryCasting__"),O=f[w];if(f.$maxDistance&&(f.$maxDistance=E.castForQuery(f.$maxDistance)),"$within"==w){var A=O.$center||O.$centerSphere||O.$box||O.$polygon;if(!A)throw new Error("Bad $within paramater: "+JSON.stringify(f));O=A}else"$near"==w&&"string"==typeof O.type&&Array.isArray(O.coordinates)?O=O.coordinates:("$near"==w||"$nearSphere"==w||"$geoIntersects"==w)&&O.$geometry&&"string"==typeof O.$geometry.type&&Array.isArray(O.$geometry.coordinates)&&(O=O.$geometry.coordinates);!function t(e){if(Array.isArray(e))e.forEach(function(n,i){return Array.isArray(n)||r.isObject(n)?t(n):void(e[i]=E.castForQuery(n))});else for(var n=Object.keys(e),i=n.length;i--;){var o=n[i],s=e[o];Array.isArray(s)||r.isObject(s)?(t(s),e[o]=s):e[o]=E.castForQuery(s)}}(O)}}}return e}},{"./schema/index":30,"./utils":43}],5:[function(t,e,r){(function(n,i){function o(t,e,r){this.$__=new j,this.$__.emitter=new y,this.isNew=!0,this.errors=void 0;var n=this.schema;"boolean"==typeof e?(this.$__.strictMode=e,e=void 0):(this.$__.strictMode=n.options&&n.options.strict,this.$__.selected=e);for(var i=n.requiredPaths(),o=0;o<i.length;++o)this.$__.activePaths.require(i[o]);if(this.$__.emitter.setMaxListeners(0),this._doc=this.$__buildDoc(t,e,r),t&&this.set(t,void 0,!0),!n.options.strict&&t){var s=this,a=Object.keys(this._doc);a.forEach(function(t){t in n.tree||c(t,null,s)})}this.$__registerHooksFromSchema()}function s(t,e,r,n){n=n||"";for(var i,o,a,u=Object.keys(e),c=u.length;c--;)if(a=u[c],o=n+a,i=t.schema.path(o),i||!b.isObject(e[a])||e[a].constructor&&"Object"!=b.getFunctionName(e[a].constructor)){if(null===e[a])r[a]=null;else if(void 0!==e[a])if(i)try{r[a]=i.cast(e[a],t,!0)}catch(e){t.invalidate(e.path,new m({path:e.path,message:e.message,type:"cast",value:e.value}))}else r[a]=e[a];t.isModified(o)||t.$__.activePaths.init(o)}else r[a]||(r[a]={}),s(t,e[a],r[a],o+".")}function a(t,e,r){for(var n,i,o=Object.keys(t),s=o.length;s--;)i=o[s],n=t[i],c(i,"Object"!==b.getFunctionName(n.constructor)||!Object.keys(n).length||n.type&&!n.type.type?null:n,e,r,o)}function u(t){var e={};return Object.getOwnPropertyNames(t).forEach(function(r){e[r]=Object.getOwnPropertyDescriptor(t,r),e[r].enumerable=!0}),e}function c(t,e,r,n,i){var s=(n?n+".":"")+t;n=n||"",e?Object.defineProperty(r,t,{enumerable:!0,configurable:!0,get:function(){if(this.$__.getters||(this.$__.getters={}),!this.$__.getters[s]){var t=Object.create(Object.getPrototypeOf(this),u(this));n||(t.$__.scope=this);for(var r=0,o=i.length;o>r;++r)Object.defineProperty(t,i[r],{enumerable:!1,writable:!0,configurable:!0,value:void 0});t.toObject=function(){return this.get(s)},t.toJSON=t.toObject,t.$__isNested=!0,a(e,t,s),this.$__.getters[s]=t}return this.$__.getters[s]},set:function(t){return t instanceof o&&(t=t.toObject()),(this.$__.scope||this).set(s,t)}}):Object.defineProperty(r,t,{enumerable:!0,configurable:!0,get:function(){return this.get.call(this.$__.scope||this,s)},set:function(t){return this.set.call(this.$__.scope||this,s,t)}})}function f(t){for(var e,r,n,i=Object.keys(t),o=i.length;o--;)r=i[o],n=t[r],b.isObject(n)&&(t[r]=f(n)),void 0!==t[r]?e=!0:delete t[r];return e?t:void 0}function h(t,e,r,n){for(var i,o=t.schema,s=Object.keys(o[r]),a=s.length;a--;){i=s[a];for(var u,c=i.split("."),f=c.length,h=f-1,l=e,p=0;f>p;++p)u=c[p],p===h?l[u]=w(t.get(i),n):l=l[u]||(l[u]={})}return e}var l,p,d,y=t("events").EventEmitter,_=t("./error"),g=t("./schema/mixed"),v=t("./schema"),m=t("./schematype").ValidatorError,b=t("./utils"),w=b.clone,E=b.isMongooseObject,O=t("util").inspect,A=_.ValidationError,j=t("./internal"),S=b.deepEqual,B=t("hooks-fixed"),x=t("./promise_provider");b.each(["on","once","emit","listeners","removeListener","setMaxListeners","removeAllListeners","addListener"],function(t){o.prototype[t]=function(){return this.$__.emitter[t].apply(this.$__.emitter,arguments)}}),o.prototype.constructor=o,o.prototype.schema,o.prototype.isNew,o.prototype.id,o.prototype.errors,o.prototype.$__buildDoc=function(t,e,r){var n,i,o,s={},a=this;if(e&&"Object"===b.getFunctionName(e.constructor))for(i=Object.keys(e),o=i.length;o--;)if("_id"!==i[o]){n=0===e[i[o]];break}for(var u=Object.keys(this.schema.paths),c=u.length,f=0;c>f;++f){var h=u[f];if("_id"==h){if(r)continue;if(t&&"_id"in t)continue}for(var l=this.schema.paths[h],p=h.split("."),d=p.length,y=d-1,_="",g=s,v=0,m=!1;d>v;++v){var w,E=p[v];if(_+=E,n){if(_ in e)break}else e&&_ in e&&(m=!0);if(v===y)if(e)if(n){if(h in e)continue;w=l.getDefault(a,!0),"undefined"!=typeof w&&(g[E]=w,a.$__.activePaths.default(h))}else m&&(w=l.getDefault(a,!0),"undefined"!=typeof w&&(g[E]=w,a.$__.activePaths.default(h)));else w=l.getDefault(a,!0),"undefined"!=typeof w&&(g[E]=w,a.$__.activePaths.default(h));else g=g[E]||(g[E]={}),_+="."}}return s},o.prototype.init=function(t,e,r){if("function"==typeof e&&(r=e,e=null),this.isNew=!1,null!=t._id&&e&&e.populated&&e.populated.length)for(var n=String(t._id),i=0;i<e.populated.length;++i){var o=e.populated[i];this.populated(o.path,o._docs[n],o)}return s(this,t,this._doc),this.$__storeShard(),this.emit("init",this),r&&r(null),this},o.prototype.$__storeShard=function(){var t=this.schema.options.shardKey||this.schema.options.shardkey;if(t&&"Object"==b.getFunctionName(t.constructor))for(var e,r=this.$__.shardval={},n=Object.keys(t),i=n.length,o=0;i>o;++o)e=this.getValue(n[o]),r[n[o]]=E(e)?e.toObject({depopulate:!0}):null==e||!e.valueOf||e.constructor&&"Date"===b.getFunctionName(e.constructor)?e:e.valueOf()};for(var N in B)o.prototype[N]=o[N]=B[N];o.prototype.update=function(){var t=b.args(arguments);return t.unshift({_id:this._id}),this.constructor.update.apply(this.constructor,t)},o.prototype.set=function(t,e,r,n){r&&"Object"==b.getFunctionName(r.constructor)&&(n=r,r=void 0);var i,s=n&&n.merge,a=r&&!0!==r,u=!0===r,c=n&&"strict"in n?n.strict:this.$__.strictMode;if(a&&(i=this.$__.adhocPaths||(this.$__.adhocPaths={}),i[t]=v.interpretAsType(t,r)),"string"!=typeof t){if(null!==t&&void 0!==t){var f=e?e+".":"";t instanceof o&&(t=t.$__isNested?t.toObject():t._doc);for(var h,l,p=Object.keys(t),d=p.length;d--;){l=p[d];var y=f+l;if(h=this.schema.pathType(y),null==t[l]||!b.isObject(t[l])||t[l].constructor&&"Object"!=b.getFunctionName(t[l].constructor)||"virtual"===h||"real"===h||this.$__path(y)instanceof g||this.schema.paths[y]&&this.schema.paths[y].options.ref)if(c){if("real"===h||"virtual"===h)this.set(f+l,t[l],u);else if("throw"==c)throw new Error("Field `"+l+"` is not in schema.")}else void 0!==t[l]&&this.set(f+l,t[l],u);else this.set(t[l],f+l,u)}return this}var m=t;t=e,e=m}var w=this.schema.pathType(t);if("nested"==w&&e)return!b.isObject(e)||e.constructor&&"Object"!=b.getFunctionName(e.constructor)?(this.invalidate(t,new _.CastError("Object",e,t)),this):(s||this.setValue(t,null),this.set(e,t,u),this);var E,O=t.split(".");if("adhocOrUndefined"==w&&c){var A;for(d=0;d<O.length;++d){var j=O.slice(0,d+1).join(".");if(E=this.schema.path(j),E instanceof g){A=!0;break}}if(!A){if("throw"==c)throw new Error("Field `"+t+"` is not in schema.");return this}}else{if("virtual"==w)return E=this.schema.virtualpath(t),E.applySetters(e,this),this;E=this.$__path(t)}var S;if(O.length<=1)S=t;else{for(d=0;d<O.length;++d)if(j=O.slice(0,d+1).join("."),this.isDirectModified(j)||null===this.get(j)){S=j;break}S||(S=t)}var B=u?void 0:this.getValue(t);if(!E)return this.$__set(S,t,u,O,E,e,B),this;var x=!0;try{E.options&&E.options.ref&&e instanceof o&&E.options.ref===e.constructor.modelName&&this.populated(t,e._id),e=E.applySetters(e,this,!1,B),this.$markValid(t)}catch(r){this.invalidate(t,new _.CastError(E.instance,e,t)),x=!1}return x&&this.$__set(S,t,u,O,E,e,B),this},o.prototype.$__shouldModify=function(t,e,r,n,i,o,s){return this.isNew?!0:void 0!==o||this.isSelected(e)?void 0===o&&e in this.$__.activePaths.states.default?!1:S(o,s||this.get(e))?!r&&null!=o&&e in this.$__.activePaths.states.default&&S(o,i.getDefault(this,r))?!0:!1:!0:!0},o.prototype.$__set=function(e,r,n,i,o,s){d=d||t("./types/embedded");var a=this.$__shouldModify.apply(this,arguments),u=this;a&&(this.markModified(e,s),p||(p=t("./types/array")),s&&s.isMongooseArray&&(s._registerAtomic("$set",s),this.$__.activePaths.forEach(function(t){0===t.indexOf(r+".")&&u.$__.activePaths.ignore(t)})));for(var c=this._doc,f=0,h=i.length;h>f;f++){var l=f+1,y=l===h;y?c[i[f]]=s:c=c[i[f]]&&"Object"===b.getFunctionName(c[i[f]].constructor)?c[i[f]]:c[i[f]]&&c[i[f]]instanceof d?c[i[f]]:c[i[f]]&&Array.isArray(c[i[f]])?c[i[f]]:c[i[f]]={}}},o.prototype.getValue=function(t){return b.getValue(t,this._doc)},o.prototype.setValue=function(t,e){return b.setValue(t,e,this._doc),this},o.prototype.get=function(t,e){var r;e&&(r=v.interpretAsType(t,e));for(var n=this.$__path(t)||this.schema.virtualpath(t),i=t.split("."),o=this._doc,s=0,a=i.length;a>s;s++)o=void 0===o||null===o?void 0:o[i[s]];return r&&(o=r.cast(o)),n&&(o=n.applyGetters(o,this)),o},o.prototype.$__path=function(t){var e=this.$__.adhocPaths,r=e&&e[t];return r?r:this.schema.path(t)},o.prototype.markModified=function(t){this.$__.activePaths.modify(t)},o.prototype.modifiedPaths=function(){var t=Object.keys(this.$__.activePaths.states.modify);return t.reduce(function(t,e){var r=e.split(".");return t.concat(r.reduce(function(t,e,n){return t.concat(r.slice(0,n).concat(e).join("."))},[]))},[])},o.prototype.isModified=function(t){return t?!!~this.modifiedPaths().indexOf(t):this.$__.activePaths.some("modify")},o.prototype.$isDefault=function(t){return t in this.$__.activePaths.states.default},o.prototype.isDirectModified=function(t){return t in this.$__.activePaths.states.modify},o.prototype.isInit=function(t){return t in this.$__.activePaths.states.init},o.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=!1;if(1===n&&"_id"===r[0])return 0===this.$__.selected._id;for(;n--;)if(e=r[n],"_id"!=e){i=!!this.$__.selected[e];break}if(t in this.$__.selected)return i;n=r.length;for(var o=t+".";n--;)if(e=r[n],"_id"!=e){if(0===e.indexOf(o))return i;if(0===o.indexOf(e+"."))return i}return!i}return!0},o.prototype.validate=function(t){var e=this,r=function(){var t=e.$__.validationError;if(e.$__.validationError=void 0,e.emit("validate",e),t){for(var r in t.errors)!e.__parent&&t.errors[r]instanceof _.CastError&&e.invalidate(r,t.errors[r]);return t}},o=x.get(),s=Object.keys(this.$__.activePaths.states.require).filter(function(t){return e.isSelected(t)||e.isModified(t)?!0:!1});if(s=s.concat(Object.keys(this.$__.activePaths.states.init)),s=s.concat(Object.keys(this.$__.activePaths.states.modify)),s=s.concat(Object.keys(this.$__.activePaths.states.default)),0===s.length)return new o.ES6(function(e,i){n.nextTick(function(){var n=r();return n?(t&&t(n),void i(n)):(t&&t(),void e())})});for(var a={},u=0,c=0;c<s.length;++c){var f=s[c],h=e.getValue(f);if(h instanceof Array&&!i.isBuffer(h)&&!h.isMongooseDocumentArray)for(var l=h.length,p=0;l>p;++p)s.push(f+"."+p)}return new o.ES6(function(i,o){var c=function(){var e=r();return e?(t&&t(e),void o(e)):(t&&t(),void i())},f=function(t){a[t]||(a[t]=!0,u++,n.nextTick(function(){var r=e.schema.path(t);if(!r)return--u||c();if(!e.$isValid(t))return void(--u||c());var n=e.getValue(t);r.doValidate(n,function(r){r&&e.invalidate(t,r,void 0,!0),--u||c()},e)}))};s.forEach(f)})},o.prototype.validateSync=function(t){var e=this;"string"==typeof t&&(t=t.split(" "));var r=Object.keys(this.$__.activePaths.states.require).filter(function(t){return e.isSelected(t)||e.isModified(t)?!0:!1});if(r=r.concat(Object.keys(this.$__.activePaths.states.init)),r=r.concat(Object.keys(this.$__.activePaths.states.modify)),r=r.concat(Object.keys(this.$__.activePaths.states.default)),t&&t.length){for(var n=[],i=0;i<r.length;++i)-1!==t.indexOf(r[i])&&n.push(r[i]);r=n}var o={};r.forEach(function(t){if(!o[t]){o[t]=!0;var r=e.schema.path(t);if(r&&e.$isValid(t)){var n=e.getValue(t),i=r.doValidateSync(n,e);i&&e.invalidate(t,i,void 0,!0)}}});var s=e.$__.validationError;if(e.$__.validationError=void 0,e.emit("validate",e),s)for(var a in s.errors)s.errors[a]instanceof _.CastError&&e.invalidate(a,s.errors[a]);return s},o.prototype.invalidate=function(t,e,r){this.$__.validationError||(this.$__.validationError=new A(this)),this.$__.validationError.errors[t]||(e&&"string"!=typeof e||(e=new m({path:t,message:e,type:"user defined",value:r})),this.$__.validationError!=e&&(this.$__.validationError.errors[t]=e))},o.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))},o.prototype.$isValid=function(t){return!this.$__.validationError||!this.$__.validationError.errors[t]},o.prototype.$__reset=function(){var e=this;return l||(l=t("./types/documentarray")),this.$__.activePaths.map("init","modify",function(t){return e.getValue(t)}).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.$__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,e=this,this.schema.requiredPaths().forEach(function(t){e.$__.activePaths.require(t)}),this},o.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){return"_id"!==e&&t.getValue(e)?{path:e,value:t.getValue(e),schema:t.$__path(e)}:void 0})),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},o.prototype.$__setSchema=function(t){a(t.tree,this),this.schema=t},o.prototype.$__getArrayPathsToValidate=function(){return l||(l=t("./types/documentarray")),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})},o.prototype.$__getAllSubdocs=function(){function e(t,r){var n=this[r];return n instanceof d&&t.push(n),n&&n.isMongooseDocumentArray&&n.forEach(function(r){r&&r._doc&&(r instanceof d&&t.push(r),t=Object.keys(r._doc).reduce(e.bind(r._doc),t))}),t}l||(l=t("./types/documentarray")),d=d||t("./types/embedded");var r=Object.keys(this._doc).reduce(e.bind(this),[]);return r},o.prototype.$__registerHooksFromSchema=function(){d=d||t("./types/embedded");var e=x.get(),r=this,n=r.schema&&r.schema.callQueue;if(!n.length)return r;var i=n.reduce(function(t,e){if("pre"!==e[0]&&"post"!==e[0]&&"on"!==e[0])return r[e[0]].apply(r,e[1]),t;var n=[].slice.call(e[1]),i="on"===e[0]?"post":n[0];return i in t||(t[i]={post:[],pre:[]}),"post"===e[0]?t[i].post.push(n):"on"===e[0]?t[i].push(n):t[i].pre.push(n),t},{post:[]});return i.post.forEach(function(t){r.on.apply(r,t)}),delete i.post,i.init&&r instanceof d&&(i.init.pre&&i.init.pre.forEach(function(t){r.pre.apply(r,t)}),i.init.post&&i.init.post.forEach(function(t){r.post.apply(r,t)}),delete i.init),Object.keys(i).forEach(function(t){var n="$__original_"+t;r[t]&&(r[n]=r[t],r[t]=function(){var t,i=[].slice.call(arguments),o=i.pop();return new e.ES6(function(e,s){o&&"function"!=typeof o?i.push(o):t=o,i.push(function(n,i){return n?(r.$__handleReject(n),t&&t(n),void s(n)):(t&&t.apply(null,[null].concat(Array.prototype.slice.call(arguments,1))),void e(i))}),r[n].apply(r,i)})},i[t].pre.forEach(function(t){t[0]=n,r.pre.apply(r,t)}),i[t].post.forEach(function(t){t[0]=n,r.post.apply(r,t)}))}),r},o.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)},o.prototype.$toObject=function(t,e){var r={transform:!0,json:e};if(t&&t.depopulate&&!t._skipDepopulateTopLevel&&this.$__.wasPopulated)return w(this._id,t);t&&t._skipDepopulateTopLevel&&(t._skipDepopulateTopLevel=!1),(!t||"Object"!=b.getFunctionName(t.constructor)||t&&t._useSchemaOptions)&&(e?(t=this.schema.options.toJSON?w(this.schema.options.toJSON):{},t.json=!0,t._useSchemaOptions=!0):(t=this.schema.options.toObject?w(this.schema.options.toObject):{},t.json=!1,t._useSchemaOptions=!0));for(var n in r)void 0===t[n]&&(t[n]=r[n]);"minimize"in t||(t.minimize=this.schema.options.minimize);var i=t.transform,o=w(this._doc,t)||{};(t.virtuals||t.getters&&!1!==t.virtuals)&&h(this,o,"virtuals",t),t.getters&&(h(this,o,"paths",t),t.minimize&&(o=f(o)||{})),t.versionKey===!1&&this.schema.options.versionKey&&delete o[this.schema.options.versionKey];var s=t.transform;if(!0===s||this.schema.options.toObject&&s){var a=t.json?this.schema.options.toJSON:this.schema.options.toObject;a&&(s="function"==typeof t.transform?t.transform:a.transform)}else t.transform=i;if("function"==typeof s){var u=s(this,o,t);"undefined"!=typeof u&&(o=u)}return o},o.prototype.toObject=function(t){return this.$toObject(t)},o.prototype.toJSON=function(t){return this.$toObject(t,!0)},o.prototype.inspect=function(t){var e=t&&"Object"==b.getFunctionName(t.constructor)?t:{};return e.minimize=!1,O(this.toObject(e))},o.prototype.toString=o.prototype.inspect,o.prototype.equals=function(t){var e=this.get("_id"),r=t.get?t.get("_id"):t;return e||r?e&&e.equals?e.equals(r):e===r:S(this,t)},o.prototype.populate=function(){if(0===arguments.length)return this;var t,e=this.$__.populate||(this.$__.populate={}),r=b.args(arguments);if("function"==typeof r[r.length-1]&&(t=r.pop()),r.length)for(var n=b.populate.apply(null,r),i=0;i<n.length;++i)e[n[i].path]=n[i];if(t){var o=b.object.vals(e);this.$__.populate=void 0,this.constructor.populate(this,o,t)}return this},o.prototype.execPopulate=function(){var t=x.get(),e=this;return new t.ES6(function(t,r){e.populate(function(n){return n?r(n):void t(e)})})},o.prototype.populated=function(t,e,r){if(null==e){if(!this.$__.populated)return void 0;var n=this.$__.populated[t];return n?n.value:void 0}return!0===e?this.$__.populated?this.$__.populated[t]:void 0:(this.$__.populated||(this.$__.populated={}),this.$__.populated[t]={value:e,options:r},e)},o.prototype.$__fullPath=function(t){return t||""},o.ValidationError=A,e.exports=r=o}).call(this,t("FWaASH"),t("buffer").Buffer)},{"./error":12,"./internal":21,"./promise_provider":23,"./schema":24,"./schema/mixed":31,"./schematype":35,"./types/array":37,"./types/documentarray":39,"./types/embedded":40,"./utils":43,FWaASH:53,buffer:47,events:51,"hooks-fixed":69,util:55}],6:[function(t,e){"use strict";var r=t("./document.js"),n=t("./browserDocument.js");e.exports=function(){return"undefined"!=typeof window&&"undefined"!=typeof document&&document===window.document?n:r}},{"./browserDocument.js":3,"./document.js":5}],7:[function(t,e){e.exports=function(){}},{}],8:[function(t,e,r){var n=t("bson").Binary;e.exports=r=n},{bson:58}],9:[function(t,e,r){r.Binary=t("./binary"),r.ObjectId=t("./objectid"),r.ReadPreference=t("./ReadPreference")},{"./ReadPreference":7,"./binary":8,"./objectid":10}],10:[function(t,e,r){var n=t("bson").ObjectID;e.exports=r=n},{bson:58}],11:[function(t,e){(function(r){var n;n=t("undefined"==typeof window?"./"+(r.MONGOOSE_DRIVER_PATH||"node-mongodb-native"):"./browser"),e.exports=n}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./browser":9}],12:[function(t,e,r){function n(t){Error.call(this),this.stack=(new Error).stack,this.message=t,this.name="MongooseError"}n.prototype=Object.create(Error.prototype),n.prototype.constructor=Error,e.exports=r=n,n.messages=t("./error/messages"),n.Messages=n.messages,n.CastError=t("./error/cast"),n.ValidationError=t("./error/validation"),n.ValidatorError=t("./error/validator"),n.VersionError=t("./error/version"),n.OverwriteModelError=t("./error/overwriteModel"),n.MissingSchemaError=t("./error/missingSchema"),n.DivergentArrayError=t("./error/divergentArray")},{"./error/cast":13,"./error/divergentArray":14,"./error/messages":15,"./error/missingSchema":16,"./error/overwriteModel":17,"./error/validation":18,"./error/validator":19,"./error/version":20}],13:[function(t,e){function r(t,e,r){n.call(this,"Cast to "+t+' failed for value "'+e+'" at path "'+r+'"'),this.stack=(new Error).stack,this.name="CastError",this.kind=t,this.value=e,this.path=r}var n=t("../error.js");r.prototype=Object.create(n.prototype),r.prototype.constructor=n,e.exports=r},{"../error.js":12}],14:[function(t,e){function r(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),Error.captureStackTrace&&Error.captureStackTrace(this,arguments.callee),this.name="DivergentArrayError"}var n=t("../error.js");r.prototype=Object.create(n.prototype),r.prototype.constructor=n,e.exports=r},{"../error.js":12}],15:[function(t,e,r){var n=e.exports=r={};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})."},{}],16:[function(t,e){function r(t){var e="Schema hasn't been registered for model \""+t+'".\nUse mongoose.model(name, schema)';n.call(this,e),Error.captureStackTrace&&Error.captureStackTrace(this,arguments.callee),this.name="MissingSchemaError"}var n=t("../error.js");r.prototype=Object.create(n.prototype),r.prototype.constructor=n,e.exports=r},{"../error.js":12}],17:[function(t,e){function r(t){n.call(this,"Cannot overwrite `"+t+"` model once compiled."),Error.captureStackTrace&&Error.captureStackTrace(this,arguments.callee),this.name="OverwriteModelError"}var n=t("../error.js");r.prototype=Object.create(n.prototype),r.prototype.constructor=n,e.exports=r},{"../error.js":12}],18:[function(t,e,r){function n(t){t&&"model"===t.constructor.name?i.call(this,t.constructor.modelName+" validation failed"):i.call(this,"Validation failed"),this.stack=(new Error).stack,this.name="ValidationError",this.errors={},t&&(t.errors=this.errors)}var i=t("../error.js");n.prototype=Object.create(i.prototype),n.prototype.constructor=i,n.prototype.toString=function(){var t=this.name+": ",e=[];return Object.keys(this.errors).forEach(function(t){this!=this.errors[t]&&e.push(String(this.errors[t]))},this),t+e.join(", ")},e.exports=r=n},{"../error.js":12}],19:[function(t,e){function r(t){var e=t.message;e||(e=i.general.default),this.properties=t;var r=this.formatMessage(e,t);n.call(this,r),this.stack=(new Error).stack,this.name="ValidatorError",this.kind=t.type,this.path=t.path,this.value=t.value}var n=t("../error.js"),i=n.messages;r.prototype=Object.create(n.prototype),r.prototype.constructor=n,r.prototype.formatMessage=function(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},r.prototype.toString=function(){return this.message},e.exports=r},{"../error.js":12}],20:[function(t,e){function r(){n.call(this,"No matching document found."),Error.captureStackTrace&&Error.captureStackTrace(this,arguments.callee),this.name="VersionError"}var n=t("../error.js");r.prototype=Object.create(n.prototype),r.prototype.constructor=n,e.exports=r},{"../error.js":12}],21:[function(t,e,r){function n(){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.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 o,this.ownerDocument=void 0,this.fullPath=void 0}var i=t("./statemachine"),o=i.ctor("require","modify","init","default","ignore");e.exports=r=n},{"./statemachine":36}],22:[function(t,e){function r(t){n.call(this,t)}var n=t("mpromise"),i=t("util");r.ES6=function(t){var e=new r;try{t(function(){e.complete.apply(e,arguments)},function(t){e.error(t)})}catch(t){e.error(t)}return e},r.prototype=Object.create(n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),r.SUCCESS="complete",r.FAILURE="err",r.prototype.error=function(t){return t instanceof Error||(t instanceof Object&&(t=i.inspect(t)),t=new Error(t)),this.reject(t)},r.prototype.resolve=function(t){return t?this.error(t):this.fulfill.apply(this,Array.prototype.slice.call(arguments,1))},r.prototype.addBack=r.prototype.onResolve,r.prototype.complete=n.prototype.fulfill,r.prototype.addCallback=r.prototype.onFulfill,r.prototype.addErrback=r.prototype.onReject,e.exports=r},{mpromise:73,util:55}],23:[function(t,e){var r=t("./promise"),n={_promise:r};n.get=function(){return n._promise},n.set=function(e){return e===r?n.reset():(n._promise=t("./ES6Promise"),n._promise.use(e),void(t("mquery").Promise=n._promise.ES6))},n.reset=function(){n._promise=r},e.exports=n},{"./ES6Promise":1,"./promise":22,mquery:78}],24:[function(t,e,r){(function(n){function i(t,e){if(!(this instanceof i))return new i(t,e);this.paths={},this.subpaths={},this.virtuals={},this.nested={},this.inherits={},this.callQueue=[],this._indexes=[],this.methods={},this.statics={},this.tree={},this._requiredpaths=void 0,this.discriminatorMapping=void 0,this._indexedpaths=void 0,this.s={hooks:new l,queryHooks:y},this.options=this.defaultOptions(e),t&&this.add(t);var r=t&&t._id&&h.isObject(t._id),n=!this.paths._id&&!this.options.noId&&this.options._id&&!r;n&&this.add({_id:{type:i.ObjectId,auto:!0}});var s=!this.paths.id&&!this.options.noVirtualId&&this.options.id;s&&this.virtual("id").get(o);for(var a=0;a<this._defaultMiddleware.length;++a){var u=this._defaultMiddleware[a];this[u.kind](u.hook,!!u.isAsync,u.fn)}var c=this.options.timestamps;if(c){var f=c.createdAt||"createdAt",p=c.updatedAt||"updatedAt",d={};d[p]=Date,this.paths[f]||(d[f]=Date),this.add(d),this.pre("save",function(t){var e=new Date;this[f]||(this[f]=n?this._id.getTimestamp():e),this[p]=this.isNew?this[f]:e,t()})}}function o(){return this.$__._id?this.$__._id:this.$__._id=null==this._id?null:String(this._id)}function s(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]);if(!n)return n;for(var i,o=r.length-1,s=1;s<r.length;++s){if(i=r[s],s===o&&n&&!n.schema&&!/\D/.test(i)){n=n instanceof a.Array?n.caster:void 0;break}if(/\D/.test(i)){if(!n||!n.schema){n=void 0;break}n=n.schema.path(i)}}return t.subpaths[e]=n}var a,u=t("./drivers").ReadPreference,c=t("events").EventEmitter,f=t("./virtualtype"),h=t("./utils"),l=t("kareem"),p=t("async"),d=t("./promise_provider"),y={count:!0,find:!0,findOne:!0,findOneAndUpdate:!0,findOneAndRemove:!0,update:!0};i.prototype=Object.create(c.prototype),i.prototype.constructor=i,Object.defineProperty(i.prototype,"_defaultMiddleware",{configurable:!1,enumerable:!1,writable:!1,value:[{kind:"pre",hook:"save",fn:function(t){return this.ownerDocument?t():void(this.schema.options.validateBeforeSave?this.validate().then(t,t):t())}},{kind:"pre",hook:"save",isAsync:!0,fn:function(t,e){var r=d.get(),n=this.$__getAllSubdocs();return n=n.filter(function(t){return!t.$__preSavingFromParent}),n.length?void new r.ES6(function(t,e){p.each(n,function(t,e){t.$__preSavingFromParent=!0,t.save(function(r){delete t.$__preSavingFromParent,e(r)})},function(r){return r?void e(r):void t() })}).then(function(){t(),e()},e):(e(),void t())}}]}),i.prototype.paths,i.prototype.tree,i.prototype.defaultOptions=function(t){return t&&!1===t.safe&&(t.safe={w:0}),t&&t.safe&&0===t.safe.w&&(t.versionKey=!1),t=h.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},t),t.read&&(t.read=u(t.read)),t},i.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+"`");!h.isObject(t[i])||t[i].constructor&&"Object"!=h.getFunctionName(t[i].constructor)||t[i].type&&!t[i].type.type?this.path(e+i,t[i]):Object.keys(t[i]).length?(this.nested[e+i]=!0,this.add(t[i],e+i+".")):this.path(e+i,t[i])}},i.reserved=Object.create(null);var _=i.reserved;_.emit=_.on=_.once=_.collection=_.db=_.errors=_.init=_.isModified=_.isNew=_.get=_.modelName=_.save=_.schema=_.set=_.toObject=_.validate=_._pres=_._posts=1;var g={};g.increment="`increment` should not be used as a schema path name unless you have disabled versioning.",i.prototype.path=function(t,e){if(void 0==e)return this.paths[t]?this.paths[t]:this.subpaths[t]?this.subpaths[t]:/\.\d+\.?.*$/.test(t)?s(this,t):void 0;if(_[t])throw new Error("`"+t+"` may not be used as a schema pathname");g[t]&&console.log("WARN: "+g[t]);var r=t.split(/\./),n=r.pop(),o=this.tree;return r.forEach(function(e,n){if(o[e]||(o[e]={}),"object"!=typeof o[e]){var i="Cannot set nested path `"+t+"`. Parent path `"+r.slice(0,n).concat([e]).join(".")+"` already set to type "+o[e].name+".";throw new Error(i)}o=o[e]}),o[n]=h.clone(e),this.paths[t]=i.interpretAsType(t,e),this},i.interpretAsType=function(t,e){if(e.constructor){var r=h.getFunctionName(e.constructor);"Object"!=r&&(e={type:e})}var o=e.type&&!e.type.type?e.type:{};if("Object"==h.getFunctionName(o.constructor)||"mixed"==o)return new a.Mixed(t,e);if(Array.isArray(o)||Array==o||"array"==o){var s=Array==o||"array"==o?e.cast:o[0];if(s instanceof i)return new a.DocumentArray(t,s,e);if("string"==typeof s)s=a[s.charAt(0).toUpperCase()+s.substring(1)];else if(s&&(!s.type||s.type.type)&&"Object"==h.getFunctionName(s.constructor)&&Object.keys(s).length)return new a.DocumentArray(t,new i(s),e);return new a.Array(t,s||a.Mixed,e)}var u;if(u=n.isBuffer(o)?"Buffer":"string"==typeof o?o:o.schemaName||h.getFunctionName(o),u&&(u=u.charAt(0).toUpperCase()+u.substring(1)),void 0==a[u])throw new TypeError("Undefined type `"+u+"` at `"+t+"`\n Did you try nesting Schemas? You can only nest using refs or arrays.");return new a[u](t,e)},i.prototype.eachPath=function(t){for(var e=Object.keys(this.paths),r=e.length,n=0;r>n;++n)t(e[n],this.paths[e[n]]);return this},i.prototype.requiredPaths=function(){if(this._requiredpaths)return this._requiredpaths;for(var t=Object.keys(this.paths),e=t.length,r=[];e--;){var n=t[e];this.paths[n].isRequired&&r.push(n)}return this._requiredpaths=r},i.prototype.indexedPaths=function(){return this._indexedpaths?this._indexedpaths:this._indexedpaths=this.indexes()},i.prototype.pathType=function(t){return t in this.paths?"real":t in this.virtuals?"virtual":t in this.nested?"nested":t in this.subpaths?"real":/\.\d+\.|\.\d+$/.test(t)&&s(this,t)?"real":"adhocOrUndefined"},i.prototype.queue=function(t,e){return this.callQueue.push([t,e]),this},i.prototype.pre=function(){var t=arguments[0];return y[t]?(this.s.hooks.pre.apply(this.s.hooks,arguments),this):this.queue("pre",arguments)},i.prototype.post=function(t,e){return y[t]?(this.s.hooks.post.apply(this.s.hooks,arguments),this):e.length<2?this.queue("on",[arguments[0],function(t){return e.call(t,t)}]):this.queue("post",[arguments[0],function(t){var r=this,n=Array.prototype.slice.call(arguments,1);e.call(this,this,function(e){return t.apply(r,[e].concat(n))})}])},i.prototype.plugin=function(t,e){return t(this,e),this},i.prototype.method=function(t,e){if("string"!=typeof t)for(var r in t)this.methods[r]=t[r];else this.methods[t]=e;return this},i.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},i.prototype.index=function(t,e){return e||(e={}),e.expires&&h.expires(e),this._indexes.push([t,e]),this},i.prototype.set=function(t,e,r){if(1===arguments.length)return this.options[t];switch(t){case"read":this.options[t]=u(e,r);break;case"safe":this.options[t]=!1===e?{w:0}:e;break;default:this.options[t]=e}return this},i.prototype.get=function(t){return this.options[t]};var v="2d 2dsphere hashed text".split(" ");Object.defineProperty(i,"indexTypes",{get:function(){return v},set:function(){throw new Error("Cannot overwrite Schema.indexTypes")}}),i.prototype.indexes=function(){"use strict";function t(t,r){var n,i,o,s,a,u,c=t._indexes,f=c.length,h=0;for(h=0;f>h;++h){for(n=c[h][0],s=Object.keys(n),o=s.length,i={},u=0;o>u;++u)a=s[u],i[r+a]=n[a];e.push([i,c[h][1]])}}var e=[],r={},n=function(o,s){if(!r[s]){r[s]=!0,s=s||"";for(var u,c,f,l,p,d,y,_=Object.keys(o.paths),g=0;g<_.length;++g)u=_[g],c=o.paths[u],c instanceof a.DocumentArray?n(c.schema,u+"."):(f=c._index,!1!==f&&null!=f&&(l={},p=h.isObject(f),d=p?f:{},y="string"==typeof f?f:p?f.type:!1,l[s+u]=y&&~i.indexTypes.indexOf(y)?y:1,delete d.type,"background"in d||(d.background=!0),e.push([l,d])));s?t(o,s):(o._indexes.forEach(function(t){"background"in t[1]||(t[1].background=!0)}),e=e.concat(o._indexes))}};return n(this),e},i.prototype.virtual=function(t,e){var r=this.virtuals,n=t.split(".");return r[t]=n.reduce(function(r,i,o){return r[i]||(r[i]=o===n.length-1?new f(e,t):{}),r[i]},this.tree)},i.prototype.virtualpath=function(t){return this.virtuals[t]},i.prototype.remove=function(t){"string"==typeof t&&(t=[t]),Array.isArray(t)&&t.forEach(function(t){this.path(t)&&delete this.paths[t]},this)},e.exports=r=i,i.Types=a=t("./schema/index"),r.ObjectId=a.ObjectId}).call(this,t("buffer").Buffer)},{"./drivers":11,"./promise_provider":23,"./schema/index":30,"./utils":43,"./virtualtype":44,async:45,buffer:47,events:51,kareem:70}],25:[function(t,e){function r(t,e,r){if(e){var n={};"Object"===v.getFunctionName(e.constructor)&&(e.type?(n=v.clone(e),delete n.type,e=e.type):e=_);var i="string"==typeof e?e:v.getFunctionName(e),o=i in p?p[i]:e;this.casterConstructor=o,this.caster=new o(null,n),this.caster instanceof y||(this.caster.path=t)}h.call(this,t,r,"Array");var s,a,u=this;this.defaultValue&&(s=this.defaultValue,a="function"==typeof s),this.default(function(){var t=a?s():s||[];return new d(t,u.path,this)})}function n(t){return p.Number.prototype.cast.call(this,t)}function i(t,e){e||(e=this),t.forEach(function(r,o){Array.isArray(r)?i(r,e):t[o]=n.call(e,r)})}function o(t){return Array.isArray(t)?(i(t,this),t):t&&t.$geometry?s(t,this):r.prototype.castForQuery.call(this,t)}function s(t,e){switch(t.$geometry.type){case"Polygon":case"LineString":case"Point":i(t.$geometry.coordinates,e)}return t.$maxDistance&&(t.$maxDistance=n.call(e,t.$maxDistance)),t}function a(t){var e=this;if(t.$maxDistance&&(t.$maxDistance=n.call(e,t.$maxDistance)),t.$box||t.$polygon){var r=t.$box?"$box":"$polygon";t[r].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]=n.call(this,e)})})}else t.$center||t.$centerSphere?(r=t.$center?"$center":"$centerSphere",t[r].forEach(function(e,i){Array.isArray(e)?e.forEach(function(t,r){e[r]=n.call(this,t)}):t[r][i]=n.call(this,e)})):t.$geometry&&s(t,this);return t}function u(t){return Array.isArray(t)||(t=[t]),t=t.map(function(t){if(v.isObject(t)){var e={};return e[this.path]=t,g(this.casterConstructor.schema,e)[this.path]}return t},this)}function c(t){for(var e,r,n=!1,i=Object.keys(t),o=i.length,s=0;o>s;++s)e=i[s],r=t[e],0===e.indexOf("$")&&r&&(t[e]=this.castForQuery(e,r),n=!0);return n?t:g(this.casterConstructor.schema,t)}function f(t){var e=t.$geometry;if(e)return s(t,this),t}var h=t("../schematype"),l=h.CastError,p={Boolean:t("./boolean"),Date:t("./date"),Number:t("./number"),String:t("./string"),ObjectId:t("./objectid"),Buffer:t("./buffer")},d=t("../types").Array,y=t("../types").Embedded,_=t("./mixed"),g=t("../cast"),v=t("../utils"),m=v.isMongooseObject;r.schemaName="Array",r.prototype=Object.create(h.prototype),r.prototype.constructor=r,r.prototype.checkRequired=function(t){return!(!t||!t.length)},r.prototype.applyGetters=function(t,e){return this.caster.options&&this.caster.options.ref?t:h.prototype.applyGetters.call(this,t,e)},r.prototype.cast=function(t,e,r){if(Array.isArray(t)){if(!t.length&&e)for(var n=e.schema.indexedPaths(),i=0,o=n.length;o>i;++i){var s=n[i][0][this.path];if("2dsphere"===s||"2d"===s)return}if(t&&t.isMongooseArray||(t=new d(t,this.path,e)),this.caster)try{for(i=0,o=t.length;o>i;i++)t[i]=this.caster.cast(t[i],e,r)}catch(e){throw new l(e.type,t,this.path)}return t}return e&&r&&e.markModified(this.path),this.cast([t],e,r)},r.prototype.castForQuery=function(t,e){var r,n;if(2===arguments.length){if(r=this.$conditionalHandlers[t],!r)throw new Error("Can't use "+t+" with Array.");n=r.call(this,e)}else{n=t;var i=this.casterConstructor.prototype,o=i.castForQuery||i.cast,s=this.caster;Array.isArray(n)?n=n.map(function(t){return o&&(t=o.call(s,t)),m(t)?t.toObject({virtuals:!1}):t}):o&&(n=o.call(s,n))}return n&&m(n)?n.toObject({virtuals:!1}):n};var b=r.prototype.$conditionalHandlers={};b.$all=u,b.$options=String,b.$elemMatch=c,b.$geoIntersects=f,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(g(this.casterConstructor.schema,t[r]));return e},b.$near=b.$nearSphere=o,b.$within=b.$geoWithin=a,b.$size=b.$maxDistance=n,b.$eq=b.$gt=b.$gte=b.$in=b.$lt=b.$lte=b.$ne=b.$nin=b.$regex=r.prototype.castForQuery,e.exports=r},{"../cast":4,"../schematype":35,"../types":41,"../utils":43,"./boolean":26,"./buffer":27,"./date":28,"./mixed":31,"./number":32,"./objectid":33,"./string":34}],26:[function(t,e){function r(t,e){o.call(this,t,e,"Boolean")}function n(t){var e=this;return t.map(function(t){return e.cast(t)})}var i=t("../utils"),o=t("../schematype");r.schemaName="Boolean",r.prototype=Object.create(o.prototype),r.prototype.constructor=r,r.prototype.checkRequired=function(t){return t===!0||t===!1},r.prototype.cast=function(t){return null===t?t:"0"===t?!1:"true"===t?!0:"false"===t?!1:!!t},r.$conditionalHandlers=i.options(o.prototype.$conditionalHandlers,{$in:n}),r.prototype.castForQuery=function(t,e){var n;return 2===arguments.length?(n=r.$conditionalHandlers[t],n?n.call(this,e):this.cast(e)):this.cast(t)},e.exports=r},{"../schematype":35,"../utils":43}],27:[function(t,e){(function(r){function n(t,e){c.call(this,t,e,"Buffer")}function i(t){return this.castForQuery(t)}function o(t){var e=this;return t.map(function(t){return e.castForQuery(t)})}var s,a=t("../utils"),u=t("../types").Buffer,c=t("../schematype"),f=u.Binary,h=c.CastError;n.schemaName="Buffer",n.prototype=Object.create(c.prototype),n.prototype.constructor=n,n.prototype.checkRequired=function(t,e){return c._isRef(this,t,e,!0)?null!=t:!(!t||!t.length)},n.prototype.cast=function(e,n,i){var o;if(c._isRef(this,e,n,i)){if(null==e)return e;if(s||(s=t("./../document")),e instanceof s)return e.$__.wasPopulated=!0,e;if(r.isBuffer(e))return e;if(!a.isObject(e))throw new h("buffer",e,this.path);var l=n.$__fullPath(this.path),p=n.ownerDocument?n.ownerDocument():n,d=p.populated(l,!0);return o=new d.options.model(e),o.$__.wasPopulated=!0,o}if(e&&e._id&&(e=e._id),e&&e.isMongooseBuffer)return e;if(r.isBuffer(e))return e&&e.isMongooseBuffer||(e=new u(e,[this.path,n])),e;if(e instanceof f){if(o=new u(e.value(!0),[this.path,n]),"number"!=typeof e.sub_type)throw new h("buffer",e,this.path);return o._subtype=e.sub_type,o}if(null===e)return e;var y=typeof e;if("string"==y||"number"==y||Array.isArray(e))return o=new u(e,[this.path,n]);throw new h("buffer",e,this.path)},n.prototype.$conditionalHandlers=a.options(c.prototype.$conditionalHandlers,{$gt:i,$gte:i,$in:o,$lt:i,$lte:i,$ne:i,$nin:o}),n.prototype.castForQuery=function(t,e){var r;if(2===arguments.length){if(r=this.$conditionalHandlers[t],!r)throw new Error("Can't use "+t+" with Buffer.");return r.call(this,e)}return e=t,this.cast(e).toObject()},e.exports=n}).call(this,t("buffer").Buffer)},{"../schematype":35,"../types":41,"../utils":43,"./../document":5,buffer:47}],28:[function(t,e){function r(t,e){a.call(this,t,e,"Date")}function n(t){return this.cast(t)}function i(t){var e=this;return t.map(function(t){return e.cast(t)})}var o=t("../error").messages,s=t("../utils"),a=t("../schematype"),u=a.CastError;r.schemaName="Date",r.prototype=Object.create(a.prototype),r.prototype.constructor=r,r.prototype.expires=function(t){return this._index&&"Object"===this._index.constructor.name||(this._index={}),this._index.expires=t,s.expires(this._index),this},r.prototype.checkRequired=function(t){return t instanceof Date},r.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||o.Date.min;r=r.replace(/{MIN}/,t===Date.now?"Date.now()":this.cast(t).toString());var n=this;this.validators.push({validator:this.minValidator=function(e){var r=t===Date.now?t():n.cast(t);return null===e||e.valueOf()>=r.valueOf()},message:r,type:"min",min:t})}return this},r.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||o.Date.max;r=r.replace(/{MAX}/,t===Date.now?"Date.now()":this.cast(t).toString());var n=this;this.validators.push({validator:this.maxValidator=function(e){var r=t===Date.now?t():n.cast(t);return null===e||e.valueOf()<=r.valueOf()},message:r,type:"max",max:t})}return this},r.prototype.cast=function(t){if(null==t||""===t)return t;if(t instanceof Date)return t;var e;if("undefined"!=typeof t&&(t instanceof Number||"number"==typeof t||String(t)==Number(t)?e=new Date(Number(t)):t.toString&&(e=new Date(t.toString())),"Invalid Date"!=e.toString()))return e;throw new u("date",t,this.path)},r.prototype.$conditionalHandlers=s.options(a.prototype.$conditionalHandlers,{$all:i,$gt:n,$gte:n,$in:i,$lt:n,$lte:n,$ne:n,$nin:i}),r.prototype.castForQuery=function(t,e){var r;if(2!==arguments.length)return this.cast(t);if(r=this.$conditionalHandlers[t],!r)throw new Error("Can't use "+t+" with Date.");return r.call(this,e)},e.exports=r},{"../error":12,"../schematype":35,"../utils":43}],29:[function(t,e){function r(t,e,r){function n(){a.apply(this,arguments)}n.prototype=Object.create(a.prototype),n.prototype.$__setSchema(e),n.schema=e;for(var s in e.methods)n.prototype[s]=e.methods[s];for(s in e.statics)n[s]=e.statics[s];n.options=r,this.schema=e,i.call(this,t,n,r),this.schema=e;var u=this.path,c=this.defaultValue;this.default(function(){var t=c.call(this);return Array.isArray(t)||(t=[t]),new o(t,u,this)})}function n(t,e,r){if(!r||!e)return void 0;for(var n,i,o=t.path+".",s=Object.keys(e),a=s.length,u={};a--;)i=s[a],0===i.indexOf(o)&&(n||(n=!0),u[i.substring(o.length)]=e[i]);return n&&u||void 0}var i=t("./array"),o=t("../types/documentarray"),s=t("../schematype"),a=t("../types/embedded");r.schemaName="DocumentArray",r.prototype=Object.create(i.prototype),r.prototype.constructor=r,r.prototype.doValidate=function(t,e,r){s.prototype.doValidate.call(this,t,function(r){if(r)return e(r);var n,i=t&&t.length;if(!i)return e();for(var o=0,s=i;s>o;++o){var a=t[o];a?a.validate(function(t){t&&(n=t),--i||e(n)}):--i||e(n)}},r)},r.prototype.doValidateSync=function(t,e){var r=s.prototype.doValidateSync.call(this,t,e);if(r)return r;var n=t&&t.length,i=null;if(n){for(var o=0,a=n;a>o&&!i;++o){var u=t[o];if(u){var c=u.validateSync();c&&(i=c)}}return i}},r.prototype.cast=function(t,e,r,i){var s,u,c;if(!Array.isArray(t))return e&&r&&e.markModified(this.path),this.cast([t],e,r,i);if((!t||!t.isMongooseDocumentArray)&&(t=new o(t,this.path,e),i&&i._handlers))for(var f in i._handlers)e.removeListener(f,i._handlers[f]);for(c=t.length;c--;)if(!(t[c]instanceof a)&&t[c])if(r)s||(s=n(this,e.$__.selected,r)),u=new this.casterConstructor(null,t,!0,s,c),t[c]=u.init(t[c]);else{try{u=i.id(t[c]._id)}catch(t){}i&&u?(u.set(t[c]),t[c]=u):(u=new this.casterConstructor(t[c],t,void 0,void 0,c),t[c]=u)}return t},e.exports=r},{"../schematype":35,"../types/documentarray":39,"../types/embedded":40,"./array":25}],30:[function(t,e,r){r.String=t("./string"),r.Number=t("./number"),r.Boolean=t("./boolean"),r.DocumentArray=t("./documentarray"),r.Array=t("./array"),r.Buffer=t("./buffer"),r.Date=t("./date"),r.ObjectId=t("./objectid"),r.Mixed=t("./mixed"),r.Oid=r.ObjectId,r.Object=r.Mixed,r.Bool=r.Boolean},{"./array":25,"./boolean":26,"./buffer":27,"./date":28,"./documentarray":29,"./mixed":31,"./number":32,"./objectid":33,"./string":34}],31:[function(t,e){function r(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")}var n=t("../schematype"),i=t("../utils");r.schemaName="Mixed",r.prototype=Object.create(n.prototype),r.prototype.constructor=r,r.prototype.checkRequired=function(t){return void 0!==t&&null!==t},r.prototype.cast=function(t){return t},r.prototype.castForQuery=function(t,e){return 2===arguments.length?e:t},e.exports=r},{"../schematype":35,"../utils":43}],32:[function(t,e){(function(r){function n(t,e){a.call(this,t,e,"Number")}function i(t){return this.cast(t)}function o(t){var e=this;return t.map(function(t){return e.cast(t)})}var s,a=t("../schematype"),u=a.CastError,c=t("../error").messages,f=t("../utils");n.schemaName="Number",n.prototype=Object.create(a.prototype),n.prototype.constructor=n,n.prototype.checkRequi