i;i++)n+=String.fromCharCode(t[i]);return n};r.BUFFER_SIZE=256,r.SUBTYPE_DEFAULT=0,r.SUBTYPE_FUNCTION=1,r.SUBTYPE_BYTE_ARRAY=2,r.SUBTYPE_UUID_OLD=3,r.SUBTYPE_UUID=4,r.SUBTYPE_MD5=5,r.SUBTYPE_USER_DEFINED=128,e.exports=r,e.exports.Binary=r},{buffer:40}],50:[function(t,e,n){(function(e){function i(t,e){return this instanceof i?(this.bigEndian=t,void(this.allowExceptions=e)):new i(t,e)}function o(t,e){this.bigEndian=t||0,this.buffer=[],this.setBuffer(e)}for(var s=String.fromCharCode,a=[],u=0;64>u;u++)a[u]=Math.pow(2,u);i.warn=function(t){if(this.allowExceptions)throw new Error(t);return 1},i.decodeFloat=function(t,e,r){var n=new this.Buffer(this.bigEndian,t);n.checkBuffer(e+r+1);var i=a[r-1]-1,o=n.readBits(e+r,1),s=n.readBits(e,r),u=0,f=2,c=n.buffer.length+(-e>>3)-1;do for(var h=n.buffer[++c],p=e%8||8,l=1<>=1;h&l&&(u+=1/f),f*=2);while(e-=p);return s==(i<<1)+1?u?0/0:o?-1/0:+1/0:(1+-2*o)*(s||u?s?Math.pow(2,s-i)*(1+u):Math.pow(2,-i+1)*u:0)},i.decodeInt=function(t,e,r,n){var i=new this.Buffer(this.bigEndian||n,t),o=i.readBits(0,e),s=a[e];return r&&o>=s/2?o-s:o},i.encodeFloat=function(t,e,n){var i,o,s,u,f,c=a[n-1]-1,h=-c+1,p=c,l=h-e,d=parseFloat(t),y=isNaN(d)||d==-1/0||d==+1/0?d:0,g=0,_=2*c+1+e+3,m=new Array(_),v=(d=0!==y?0:d)<0,b=Math.floor(d=Math.abs(d)),w=d-b;for(u=_;u;m[--u]=0);for(u=c+2;b&&u;m[--u]=b%2,b=Math.floor(b/2));for(u=c+1;w>0&&u;(m[++u]=((w*=2)>=1)-0)&&--w);for(u=-1;++u<_&&!m[u];);if(m[(i=e-1+(u=(g=c+1-u)>=h&&p>=g?u+1:c+1-(g=h-1)))+1]){if(!(o=m[i]))for(f=i+2;!o&&_>f;o=m[f++]);for(f=i+1;o&&--f>=0;(m[f]=!m[f]-0)&&(o=0));}for(u=0>u-2?-1:u-3;++u<_&&!m[u];);for((g=c+1-u)>=h&&p>=g?++u:h>g&&(g!=c+1-_&&l>g&&this.warn("encodeFloat::float underflow"),u=c+1-(g=h-1)),(b||0!==y)&&(this.warn(b?"encodeFloat::float overflow":"encodeFloat::"+y),g=p+1,u=c+2,y==-1/0?v=1:isNaN(y)&&(m[u]=1)),d=Math.abs(g+c),f=n+1,s="";--f;s=d%2+s,d=d>>=1);for(d=0,f=0,u=(s=(v?"1":"0")+s+m.slice(u,u+e).join("")).length,r=[];u;f=(f+1)%8)d+=(1<=i||-(i/2)>t)&&(this.warn("encodeInt::overflow"),t=0),0>t&&(t+=i);for(var o=[];t;o[o.length]=String.fromCharCode(t%256),t=Math.floor(t/256));for(e=-(-e>>3)-o.length;e--;o[o.length]="\x00");return(this.bigEndian||n?o.reverse():o).join("")},i.toSmall=function(t){return this.decodeInt(t,8,!0)},i.fromSmall=function(t){return this.encodeInt(t,8,!0)},i.toByte=function(t){return this.decodeInt(t,8,!1)},i.fromByte=function(t){return this.encodeInt(t,8,!1)},i.toShort=function(t){return this.decodeInt(t,16,!0)},i.fromShort=function(t){return this.encodeInt(t,16,!0)},i.toWord=function(t){return this.decodeInt(t,16,!1)},i.fromWord=function(t){return this.encodeInt(t,16,!1)},i.toInt=function(t){return this.decodeInt(t,32,!0)},i.fromInt=function(t){return this.encodeInt(t,32,!0)},i.toLong=function(t){return this.decodeInt(t,64,!0)},i.fromLong=function(t){return this.encodeInt(t,64,!0)},i.toDWord=function(t){return this.decodeInt(t,32,!1)},i.fromDWord=function(t){return this.encodeInt(t,32,!1)},i.toQWord=function(t){return this.decodeInt(t,64,!0)},i.fromQWord=function(t){return this.encodeInt(t,64,!0)},i.toFloat=function(t){return this.decodeFloat(t,23,8)},i.fromFloat=function(t){return this.encodeFloat(t,23,8)},i.toDouble=function(t){return this.decodeFloat(t,52,11)},i.fromDouble=function(t){return this.encodeFloat(t,52,11)},i.encode_int32=function(t,e){var r,n,i,o,a;return a=0>t?t+4294967296:t,r=Math.floor(a/16777215),a&=16777215,n=Math.floor(a/65535),a&=65535,i=Math.floor(a/255),a&=255,o=Math.floor(a),e?[s(r),s(n),s(i),s(o)]:s(r)+s(n)+s(i)+s(o)},i.encode_int64=function(t){var e,r,n,i,o,a,u,f,c;return c=0>t?t+0x10000000000000000:t,e=Math.floor(c/72057594037927940),c&=72057594037927940,r=Math.floor(c/0xffffffffffff),c&=0xffffffffffff,n=Math.floor(c/0xffffffffff),c&=0xffffffffff,i=Math.floor(c/4294967295),c&=4294967295,o=Math.floor(c/16777215),c&=16777215,a=Math.floor(c/65535),c&=65535,u=Math.floor(c/255),c&=255,f=Math.floor(c),s(e)+s(r)+s(n)+s(i)+s(o)+s(a)+s(u)+s(f)},i.decode_utf8=function(t){for(var e,r=t.length,n="",i=0,o=0,s=0;r>i;)o=t.charCodeAt(i),128>o?(n+=String.fromCharCode(o),i++):o>191&&224>o?(s=t.charCodeAt(i+1),n+=String.fromCharCode((31&o)<<6|63&s),i+=2):(s=t.charCodeAt(i+1),e=t.charCodeAt(i+2),n+=String.fromCharCode((15&o)<<12|(63&s)<<6|63&e),i+=3);return n},i.encode_cstring=function(t){return unescape(encodeURIComponent(t))+i.fromByte(0)},i.encode_utf8=function(t){for(var e,r="",n=0,i=t.length;i>n;n++)e=t.charCodeAt(n),128>e?r+=String.fromCharCode(e):e>127&&2048>e?(r+=String.fromCharCode(e>>6|192),r+=String.fromCharCode(63&e|128)):(r+=String.fromCharCode(e>>12|224),r+=String.fromCharCode(e>>6&63|128),r+=String.fromCharCode(63&e|128));return r},i.hprint=function(t){for(var r,n=0,i=t.length;i>n;n++)t.charCodeAt(n)<32?(r=t.charCodeAt(n)<=15?"0"+t.charCodeAt(n).toString(16):t.charCodeAt(n).toString(16),e.stdout.write(r+" ")):(r=t.charCodeAt(n)<=15?"0"+t.charCodeAt(n).toString(16):t.charCodeAt(n).toString(16),e.stdout.write(r+" "));e.stdout.write("\n\n")},i.ilprint=function(e){for(var r,n=0,i=e.length;i>n;n++)e.charCodeAt(n)<32?(r=e.charCodeAt(n)<=15?"0"+e.charCodeAt(n).toString(10):e.charCodeAt(n).toString(10),t("util").debug(r+" : ")):(r=e.charCodeAt(n)<=15?"0"+e.charCodeAt(n).toString(10):e.charCodeAt(n).toString(10),t("util").debug(r+" : "+e.charAt(n)))},i.hlprint=function(e){for(var r,n=0,i=e.length;i>n;n++)e.charCodeAt(n)<32?(r=e.charCodeAt(n)<=15?"0"+e.charCodeAt(n).toString(16):e.charCodeAt(n).toString(16),t("util").debug(r+" : ")):(r=e.charCodeAt(n)<=15?"0"+e.charCodeAt(n).toString(16):e.charCodeAt(n).toString(16),t("util").debug(r+" : "+e.charAt(n)))},o.prototype.setBuffer=function(t){var e,r,n;if(t){for(r=e=t.length,n=this.buffer=new Array(e);r;n[e-r]=t.charCodeAt(--r));this.bigEndian&&n.reverse()}},o.prototype.hasNeededBits=function(t){return this.buffer.length>=-(-t>>3)},o.prototype.checkBuffer=function(t){if(!this.hasNeededBits(t))throw new Error("checkBuffer::missing bytes")},o.prototype.readBits=function(t,e){function r(t,e){for(;e--;t=1073741824==(1073741824&(t%=2147483648))?2*t:2*(t-1073741824)+2147483647+1);return t}if(0>t||0>=e)return 0;this.checkBuffer(t+e);for(var n,i=t%8,o=this.buffer.length-(t>>3)-1,s=this.buffer.length+(-(t+e)>>3),a=o-s,u=(this.buffer[o]>>i&(1<<(a?8-i:e))-1)+(a&&(n=(t+e)%8)?(this.buffer[s++]&(1<=BSON.JS_INT_MIN&&e<=BSON.JS_INT_MAX&&e>=BSON.BSON_INT32_MIN&&e<=BSON.BSON_INT32_MAX?(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+5:(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+9;case"undefined":return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1;case"boolean":return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+2;case"object":if(null==e||e instanceof MinKey||e instanceof MaxKey||"MinKey"==e._bsontype||"MaxKey"==e._bsontype)return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1;if(e instanceof ObjectID||"ObjectID"==e._bsontype)return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+13;if(e instanceof Date||isDate(e))return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+9;if("undefined"!=typeof Buffer&&Buffer.isBuffer(e))return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+6+e.length;if(e instanceof Long||e instanceof Double||e instanceof Timestamp||"Long"==e._bsontype||"Double"==e._bsontype||"Timestamp"==e._bsontype)return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+9;if(e instanceof Code||"Code"==e._bsontype)return null!=e.scope&&Object.keys(e.scope).length>0?(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1+4+4+(n?Buffer.byteLength(e.code.toString(),"utf8"):numberOfBytes(e.code.toString()))+1+BSON.calculateObjectSize(e.scope,r):(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1+4+(n?Buffer.byteLength(e.code.toString(),"utf8"):numberOfBytes(e.code.toString()))+1;if(e instanceof Binary||"Binary"==e._bsontype)return e.sub_type==Binary.SUBTYPE_BYTE_ARRAY?(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+(e.position+1+4+1+4):(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+(e.position+1+4+1);if(e instanceof Symbol||"Symbol"==e._bsontype)return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+((n?Buffer.byteLength(e.value,"utf8"):numberOfBytes(e.value))+4+1+1);if(e instanceof DBRef||"DBRef"==e._bsontype){var i={$ref:e.namespace,$id:e.oid};return null!=e.db&&(i.$db=e.db),(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1+BSON.calculateObjectSize(i,r)}return e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)?(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1+(n?Buffer.byteLength(e.source,"utf8"):numberOfBytes(e.source))+1+(e.global?1:0)+(e.ignoreCase?1:0)+(e.multiline?1:0)+1:(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+BSON.calculateObjectSize(e,r)+1;case"function":if(e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)||"[object RegExp]"==String.call(e))return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1+(n?Buffer.byteLength(e.source,"utf8"):numberOfBytes(e.source))+1+(e.global?1:0)+(e.ignoreCase?1:0)+(e.multiline?1:0)+1;if(r&&null!=e.scope&&Object.keys(e.scope).length>0)return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1+4+4+(n?Buffer.byteLength(e.toString(),"utf8"):numberOfBytes(e.toString()))+1+BSON.calculateObjectSize(e.scope,r);if(r)return(null!=t?(n?Buffer.byteLength(t,"utf8"):numberOfBytes(t))+1:0)+1+4+(n?Buffer.byteLength(e.toString(),"utf8"):numberOfBytes(e.toString()))+1}return 0}var Long=require("./long").Long,Double=require("./double").Double,Timestamp=require("./timestamp").Timestamp,ObjectID=require("./objectid").ObjectID,Symbol=require("./symbol").Symbol,Code=require("./code").Code,MinKey=require("./min_key").MinKey,MaxKey=require("./max_key").MaxKey,DBRef=require("./db_ref").DBRef,Binary=require("./binary").Binary,BinaryParser=require("./binary_parser").BinaryParser,writeIEEE754=require("./float_parser").writeIEEE754,readIEEE754=require("./float_parser").readIEEE754,isDate=function(t){return"object"==typeof t&&"[object Date]"===Object.prototype.toString.call(t)};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);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_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_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.calculateObjectSize=function(t,e){var r=5;if(Array.isArray(t))for(var n=0;n>8&255,r[n++]=o>>16&255,r[n++]=o>>24&255,serializeObject(t,e,r,n,i)-1};var serializeObject=function(t,e,r,n,i){if(t.toBSON){if("function"!=typeof t.toBSON)throw new Error("toBSON is not a function");if(t=t.toBSON(),null!=t&&"object"!=typeof t)throw new Error("toBSON function did not return an object")}if(Array.isArray(t))for(var o=0;o>=8;while(e);n=n.concat(r.reverse())}return n},numberOfBytes=function(t){for(var e,r,n=0,i=0;i>=8;while(e);n+=r.length}return n},writeToTypedArray=function(t,e,r){for(var n=stringToBytes(e),i=0;i>24&255,n[i+2]=a>>16&255,n[i+1]=a>>8&255,n[i]=255&a,i+=4,supportsBuffer?n.write(e,i,"utf8"):writeToTypedArray(n,e,i),i=i+a-1,n[i++]=0,i;case"number":if(Math.floor(e)===e&&e>=BSON.JS_INT_MIN&&e<=BSON.JS_INT_MAX)if(e>=BSON.BSON_INT32_MIN&&e<=BSON.BSON_INT32_MAX){n[i++]=BSON.BSON_DATA_INT;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0,n[i++]=255&e,n[i++]=e>>8&255,n[i++]=e>>16&255,n[i++]=e>>24&255}else if(e>=BSON.JS_INT_MIN&&e<=BSON.JS_INT_MAX){n[i++]=BSON.BSON_DATA_NUMBER;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0,writeIEEE754(n,e,i,"little",52,8),i+=8}else{n[i++]=BSON.BSON_DATA_LONG;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var u=Long.fromNumber(e),f=u.getLowBits(),c=u.getHighBits();n[i++]=255&f,n[i++]=f>>8&255,n[i++]=f>>16&255,n[i++]=f>>24&255,n[i++]=255&c,n[i++]=c>>8&255,n[i++]=c>>16&255,n[i++]=c>>24&255}else{n[i++]=BSON.BSON_DATA_NUMBER;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0,writeIEEE754(n,e,i,"little",52,8),i+=8}return i;case"undefined":n[i++]=BSON.BSON_DATA_NULL;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);return i=i+s+1,n[i-1]=0,i;case"boolean":n[i++]=BSON.BSON_DATA_BOOLEAN;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);return i=i+s+1,n[i-1]=0,n[i++]=e?1:0,i;case"object":if(null===e||e instanceof MinKey||e instanceof MaxKey||"MinKey"==e._bsontype||"MaxKey"==e._bsontype){n[i++]=null===e?BSON.BSON_DATA_NULL:e instanceof MinKey?BSON.BSON_DATA_MIN_KEY:BSON.BSON_DATA_MAX_KEY;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);return i=i+s+1,n[i-1]=0,i}if(e instanceof ObjectID||"ObjectID"==e._bsontype){n[i++]=BSON.BSON_DATA_OID;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);return i=i+s+1,n[i-1]=0,supportsBuffer?n.write(e.id,i,"binary"):writeToTypedArray(n,e.id,i),i+=12}if(e instanceof Date||isDate(e)){n[i++]=BSON.BSON_DATA_DATE;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var h=Long.fromNumber(e.getTime()),f=h.getLowBits(),c=h.getHighBits();return n[i++]=255&f,n[i++]=f>>8&255,n[i++]=f>>16&255,n[i++]=f>>24&255,n[i++]=255&c,n[i++]=c>>8&255,n[i++]=c>>16&255,n[i++]=c>>24&255,i}if("undefined"!=typeof Buffer&&Buffer.isBuffer(e)){n[i++]=BSON.BSON_DATA_BINARY;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var a=e.length;return n[i++]=255&a,n[i++]=a>>8&255,n[i++]=a>>16&255,n[i++]=a>>24&255,n[i++]=BSON.BSON_BINARY_SUBTYPE_DEFAULT,e.copy(n,i,0,a),i+=a}if(e instanceof Long||e instanceof Timestamp||"Long"==e._bsontype||"Timestamp"==e._bsontype){n[i++]=e instanceof Long||"Long"==e._bsontype?BSON.BSON_DATA_LONG:BSON.BSON_DATA_TIMESTAMP;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var f=e.getLowBits(),c=e.getHighBits();return n[i++]=255&f,n[i++]=f>>8&255,n[i++]=f>>16&255,n[i++]=f>>24&255,n[i++]=255&c,n[i++]=c>>8&255,n[i++]=c>>16&255,n[i++]=c>>24&255,i}if(e instanceof Double||"Double"==e._bsontype){n[i++]=BSON.BSON_DATA_NUMBER;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);return i=i+s+1,n[i-1]=0,writeIEEE754(n,e,i,"little",52,8),i+=8}if(e instanceof Code||"Code"==e._bsontype){if(null!=e.scope&&Object.keys(e.scope).length>0){n[i++]=BSON.BSON_DATA_CODE_W_SCOPE;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var p=BSON.calculateObjectSize(e.scope,o),l=e.code.toString(),d=supportsBuffer?Buffer.byteLength(l)+1:numberOfBytes(l)+1,y=4+d+p+4;n[i++]=255&y,n[i++]=y>>8&255,n[i++]=y>>16&255,n[i++]=y>>24&255,n[i++]=255&d,n[i++]=d>>8&255,n[i++]=d>>16&255,n[i++]=d>>24&255,supportsBuffer?n.write(l,i,"utf8"):writeToTypedArray(n,l,i),i=i+d-1,n[i++]=0;var g=supportsBuffer?new Buffer(p):new Uint8Array(new ArrayBuffer(p));serializeObject(e.scope,r,g,0,o);
-var _=p;return n[i++]=255&_,n[i++]=_>>8&255,n[i++]=_>>16&255,n[i++]=_>>24&255,supportsBuffer?g.copy(n,i,0,p):n.set(g,i),i=i+_-5,n[i++]=0,i}n[i++]=BSON.BSON_DATA_CODE;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var l=e.code.toString(),a=supportsBuffer?Buffer.byteLength(l)+1:numberOfBytes(l)+1;return n[i++]=255&a,n[i++]=a>>8&255,n[i++]=a>>16&255,n[i++]=a>>24&255,supportsBuffer?n.write(l,i,"utf8"):writeToTypedArray(n,l,i),i=i+a-1,n[i++]=0,i}if(e instanceof Binary||"Binary"==e._bsontype){n[i++]=BSON.BSON_DATA_BINARY;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var m=e.value(!0),a=e.position;return n[i++]=255&a,n[i++]=a>>8&255,n[i++]=a>>16&255,n[i++]=a>>24&255,n[i++]=e.sub_type,e.sub_type==Binary.SUBTYPE_BYTE_ARRAY&&(n[i++]=255&a,n[i++]=a>>8&255,n[i++]=a>>16&255,n[i++]=a>>24&255),supportsBuffer?m.copy(n,i,0,e.position):n.set(m,i),i+=e.position}if(e instanceof Symbol||"Symbol"==e._bsontype){n[i++]=BSON.BSON_DATA_SYMBOL;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var a=supportsBuffer?Buffer.byteLength(e.value)+1:numberOfBytes(e.value)+1;return n[i++]=255&a,n[i++]=a>>8&255,n[i++]=a>>16&255,n[i++]=a>>24&255,n.write(e.value,i,"utf8"),i=i+a-1,n[i++]=0,i}if(e instanceof DBRef||"DBRef"==e._bsontype){n[i++]=BSON.BSON_DATA_OBJECT;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var v={$ref:e.namespace,$id:e.oid};null!=e.db&&(v.$db=e.db);var a=BSON.calculateObjectSize(v,o),b=BSON.serializeWithBufferAndIndex(v,r,n,i,o);return n[i++]=255&a,n[i++]=a>>8&255,n[i++]=a>>16&255,n[i++]=a>>24&255,n[b++]=0,b}if(e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)){n[i++]=BSON.BSON_DATA_REGEXP;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);return i=i+s+1,n[i-1]=0,supportsBuffer?n.write(e.source,i,"utf8"):writeToTypedArray(n,e.source,i),i+=supportsBuffer?Buffer.byteLength(e.source):numberOfBytes(e.source),n[i++]=0,e.global&&(n[i++]=115),e.ignoreCase&&(n[i++]=105),e.multiline&&(n[i++]=109),n[i++]=0,i}n[i++]=Array.isArray(e)?BSON.BSON_DATA_ARRAY:BSON.BSON_DATA_OBJECT;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var b=serializeObject(e,r,n,i+4,o),a=b-i;return n[i++]=255&a,n[i++]=a>>8&255,n[i++]=a>>16&255,n[i++]=a>>24&255,b;case"function":if(e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)||"[object RegExp]"==String.call(e)){n[i++]=BSON.BSON_DATA_REGEXP;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);return i=i+s+1,n[i-1]=0,n.write(e.source,i,"utf8"),i+=supportsBuffer?Buffer.byteLength(e.source):numberOfBytes(e.source),n[i++]=0,e.global&&(n[i++]=115),e.ignoreCase&&(n[i++]=105),e.multiline&&(n[i++]=109),n[i++]=0,i}if(o&&null!=e.scope&&Object.keys(e.scope).length>0){n[i++]=BSON.BSON_DATA_CODE_W_SCOPE;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var p=BSON.calculateObjectSize(e.scope,o),l=e.toString(),d=supportsBuffer?Buffer.byteLength(l)+1:numberOfBytes(l)+1,y=4+d+p;n[i++]=255&y,n[i++]=y>>8&255,n[i++]=y>>16&255,n[i++]=y>>24&255,n[i++]=255&d,n[i++]=d>>8&255,n[i++]=d>>16&255,n[i++]=d>>24&255,supportsBuffer?n.write(l,i,"utf8"):writeToTypedArray(n,l,i),i=i+d-1,n[i++]=0;var g=new Buffer(p);serializeObject(e.scope,r,g,0,o);var _=p-4;return n[i++]=255&_,n[i++]=_>>8&255,n[i++]=_>>16&255,n[i++]=_>>24&255,g.copy(n,i,0,p),i=i+_-5,n[i++]=0,i}if(o){n[i++]=BSON.BSON_DATA_CODE;var s=supportsBuffer?n.write(t,i,"utf8"):writeToTypedArray(n,t,i);i=i+s+1,n[i-1]=0;var l=e.toString(),a=supportsBuffer?Buffer.byteLength(l)+1:numberOfBytes(l)+1;return n[i++]=255&a,n[i++]=a>>8&255,n[i++]=a>>16&255,n[i++]=a>>24&255,supportsBuffer?n.write(l,i,"utf8"):writeToTypedArray(n,l,i),i=i+a-1,n[i++]=0,i}}return i};BSON.serialize=function(t,e,r,n){if(null==t||"object"!=typeof t||Array.isArray(t))throw new Error("Only javascript objects supported");var i=null,o=BSON.calculateObjectSize(t,n);return(i="undefined"!=typeof Buffer)?(i=new Buffer(o),r=!0):i="undefined"!=typeof Uint8Array?new Uint8Array(new ArrayBuffer(o)):new Array(o),BSON.serializeWithBufferAndIndex(t,e,i,0,n),i};var functionCache=BSON.functionCache={},table=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],crc32=function(t,e,r){var n=0,i=0,o=0;n=-1^n;for(var s=e,a=r;a>s;s++)o=255&(n^t[s]),i=table[o],n=n>>>8^i;return-1^n};BSON.deserializeStream=function(t,e,r,n,i,o){o=null!=o?o:{};for(var s=e,a=0;r>a;a++){var u=t[s]|t[s+1]<<8|t[s+2]<<16|t[s+3]<<24;o.index=s,n[i+a]=BSON.deserialize(t,o),s+=u}return s};var isolateEvalWithHash=function(functionCache,hash,functionString,object){var value=null;return null==functionCache[hash]&&(eval("value = "+functionString),functionCache[hash]=value),functionCache[hash].bind(object)},isolateEval=function(functionString){var value=null;return eval("value = "+functionString),value},convertUint8ArrayToUtf8String=function(t,e,r){return BinaryParser.decode_utf8(convertArraytoUtf8BinaryString(t,e,r))},convertArraytoUtf8BinaryString=function(t,e,r){for(var n="",i=e;r>i;i++)n+=String.fromCharCode(t[i]);return n};BSON.deserialize=function(t,e,r){e=null==e?{}:e;var n=null==e.evalFunctions?!1:e.evalFunctions,i=null==e.cacheFunctions?!1:e.cacheFunctions,o=null==e.cacheFunctionsCrc32?!1:e.cacheFunctionsCrc32,s=null==e.promoteLongs?!0:e.promoteLongs;if(t.length<5)throw new Error("corrupt bson message < 5 bytes long");var a="number"==typeof e.index?e.index:0,u=function(){for(var e=a;0!==t[e]&&e=t.length)throw new Error("Bad BSON Document: illegal CString");var r=supportsBuffer&&Buffer.isBuffer(t)?t.toString("utf8",a,e):convertUint8ArrayToUtf8String(t,a,e);return a=e+1,r},f=r?[]:{},c=t[a++]|t[a++]<<8|t[a++]<<16|t[a++]<<24;if(5>c||c>t.length)throw new Error("corrupt bson message");for(;;){var h=t[a++];if(0==h)break;var p=u();switch(h){case BSON.BSON_DATA_OID:var l=supportsBuffer&&Buffer.isBuffer(t)?t.toString("binary",a,a+12):convertArraytoUtf8BinaryString(t,a,a+12);f[p]=new ObjectID(l),a+=12;break;case BSON.BSON_DATA_STRING:var d=t[a++]|t[a++]<<8|t[a++]<<16|t[a++]<<24;f[p]=supportsBuffer&&Buffer.isBuffer(t)?t.toString("utf8",a,a+d-1):convertUint8ArrayToUtf8String(t,a,a+d-1),a+=d;break;case BSON.BSON_DATA_INT:f[p]=t[a++]|t[a++]<<8|t[a++]<<16|t[a++]<<24;break;case BSON.BSON_DATA_NUMBER:f[p]=readIEEE754(t,a,"little",52,8),a+=8;break;case BSON.BSON_DATA_DATE:var y=t[a++]|t[a++]<<8|t[a++]<<16|t[a++]<<24,g=t[a++]|t[a++]<<8|t[a++]<<16|t[a++]<<24;f[p]=new Date(new Long(y,g).toNumber());break;case BSON.BSON_DATA_BOOLEAN:f[p]=1==t[a++];break;case BSON.BSON_DATA_UNDEFINED:case BSON.BSON_DATA_NULL:f[p]=null;break;case BSON.BSON_DATA_BINARY:var _=t[a++]|t[a++]<<8|t[a++]<<16|t[a++]<<24,m=t[a++];if(null!=t.slice)m==Binary.SUBTYPE_BYTE_ARRAY&&(_=t[a++]|t[a++]<<8|t[a++]<<16|t[a++]<<24),f[p]=new Binary(t.slice(a,a+_),m);else{var v="undefined"!=typeof Uint8Array?new Uint8Array(new ArrayBuffer(_)):new Array(_);m==Binary.SUBTYPE_BYTE_ARRAY&&(_=t[a++]|t[a++]<<8|t[a++]<<16|t[a++]<<24);for(var b=0;_>b;b++)v[b]=t[a+b];f[p]=new Binary(v,m)}a+=_;break;case BSON.BSON_DATA_ARRAY:e.index=a;var w=t[a]|t[a+1]<<8|t[a+2]<<16|t[a+3]<<24;f[p]=BSON.deserialize(t,e,!0),a+=w;break;case BSON.BSON_DATA_OBJECT:e.index=a;var w=t[a]|t[a+1]<<8|t[a+2]<<16|t[a+3]<<24;f[p]=BSON.deserialize(t,e,!1),a+=w;break;case BSON.BSON_DATA_REGEXP:for(var O=u(),B=u(),A=new Array(B.length),b=0;b>1,h=-7,p=a?0:i-1,l=a?1:-1,d=t[e+p];for(p+=l,o=d&(1<<-h)-1,d>>=-h,h+=u;h>0;o=256*o+t[e+p],p+=l,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[e+p],p+=l,h-=8);if(0===o)o=1-c;else{if(o===f)return s?0/0:1/0*(d?-1:1);s+=Math.pow(2,n),o-=c}return(d?-1:1)*s*Math.pow(2,o-n)},i=function(t,e,r,n,i,o){var s,a,u,f="big"===n,c=8*o-i-1,h=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=f?o-1:0,y=f?-1:1,g=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||1/0===e?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),e+=s+p>=1?l/u:l*Math.pow(2,1-p),e*u>=2&&(s++,u/=2),s+p>=h?(a=0,s=h):s+p>=1?(a=(e*u-1)*Math.pow(2,i),s+=p):(a=e*Math.pow(2,p-1)*Math.pow(2,i),s=0));i>=8;t[r+d]=255&a,d+=y,a/=256,i-=8);for(s=s<0;t[r+d]=255&s,d+=y,s/=256,c-=8);t[r+d-y]|=128*g};r.readIEEE754=n,r.writeIEEE754=i},{}],56:[function(t,e){function r(t,e){return this instanceof r?(this._bsontype="Long",this.low_=0|t,void(this.high_=0|e)):new r(t,e)}r.prototype.toInt=function(){return this.low_},r.prototype.toNumber=function(){return this.high_*r.TWO_PWR_32_DBL_+this.getLowBitsUnsigned()},r.prototype.toJSON=function(){return this.toString()},r.prototype.toString=function(t){var e=t||10;if(2>e||e>36)throw Error("radix out of range: "+e);if(this.isZero())return"0";if(this.isNegative()){if(this.equals(r.MIN_VALUE)){var n=r.fromNumber(e),i=this.div(n),o=i.multiply(n).subtract(this);return i.toString(e)+o.toInt().toString(e)}return"-"+this.negate().toString(e)}for(var s=r.fromNumber(Math.pow(e,6)),o=this,a="";;){var u=o.div(s),f=o.subtract(u.multiply(s)).toInt(),c=f.toString(e);if(o=u,o.isZero())return c+a;for(;c.length<6;)c="0"+c;a=""+c+a}},r.prototype.getHighBits=function(){return this.high_},r.prototype.getLowBits=function(){return this.low_},r.prototype.getLowBitsUnsigned=function(){return this.low_>=0?this.low_:r.TWO_PWR_32_DBL_+this.low_},r.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(r.MIN_VALUE)?64:this.negate().getNumBitsAbs();for(var t=0!=this.high_?this.high_:this.low_,e=31;e>0&&0==(t&1<0},r.prototype.greaterThanOrEqual=function(t){return this.compare(t)>=0},r.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},r.prototype.negate=function(){return this.equals(r.MIN_VALUE)?r.MIN_VALUE:this.not().add(r.ONE)},r.prototype.add=function(t){var e=this.high_>>>16,n=65535&this.high_,i=this.low_>>>16,o=65535&this.low_,s=t.high_>>>16,a=65535&t.high_,u=t.low_>>>16,f=65535&t.low_,c=0,h=0,p=0,l=0;return l+=o+f,p+=l>>>16,l&=65535,p+=i+u,h+=p>>>16,p&=65535,h+=n+a,c+=h>>>16,h&=65535,c+=e+s,c&=65535,r.fromBits(p<<16|l,c<<16|h)},r.prototype.subtract=function(t){return this.add(t.negate())},r.prototype.multiply=function(t){if(this.isZero())return r.ZERO;if(t.isZero())return r.ZERO;if(this.equals(r.MIN_VALUE))return t.isOdd()?r.MIN_VALUE:r.ZERO;if(t.equals(r.MIN_VALUE))return this.isOdd()?r.MIN_VALUE:r.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(r.TWO_PWR_24_)&&t.lessThan(r.TWO_PWR_24_))return r.fromNumber(this.toNumber()*t.toNumber());var e=this.high_>>>16,n=65535&this.high_,i=this.low_>>>16,o=65535&this.low_,s=t.high_>>>16,a=65535&t.high_,u=t.low_>>>16,f=65535&t.low_,c=0,h=0,p=0,l=0;return l+=o*f,p+=l>>>16,l&=65535,p+=i*f,h+=p>>>16,p&=65535,p+=o*u,h+=p>>>16,p&=65535,h+=n*f,c+=h>>>16,h&=65535,h+=i*u,c+=h>>>16,h&=65535,h+=o*a,c+=h>>>16,h&=65535,c+=e*f+n*u+i*a+o*s,c&=65535,r.fromBits(p<<16|l,c<<16|h)},r.prototype.div=function(t){if(t.isZero())throw Error("division by zero");if(this.isZero())return r.ZERO;if(this.equals(r.MIN_VALUE)){if(t.equals(r.ONE)||t.equals(r.NEG_ONE))return r.MIN_VALUE;if(t.equals(r.MIN_VALUE))return r.ONE;var e=this.shiftRight(1),n=e.div(t).shiftLeft(1);if(n.equals(r.ZERO))return t.isNegative()?r.ONE:r.NEG_ONE;var i=this.subtract(t.multiply(n)),o=n.add(i.div(t));return o}if(t.equals(r.MIN_VALUE))return r.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();for(var s=r.ZERO,i=this;i.greaterThanOrEqual(t);){for(var n=Math.max(1,Math.floor(i.toNumber()/t.toNumber())),a=Math.ceil(Math.log(n)/Math.LN2),u=48>=a?1:Math.pow(2,a-48),f=r.fromNumber(n),c=f.multiply(t);c.isNegative()||c.greaterThan(i);)n-=u,f=r.fromNumber(n),c=f.multiply(t);f.isZero()&&(f=r.ONE),s=s.add(f),i=i.subtract(c)}return s},r.prototype.modulo=function(t){return this.subtract(this.div(t).multiply(t))},r.prototype.not=function(){return r.fromBits(~this.low_,~this.high_)},r.prototype.and=function(t){return r.fromBits(this.low_&t.low_,this.high_&t.high_)},r.prototype.or=function(t){return r.fromBits(this.low_|t.low_,this.high_|t.high_)},r.prototype.xor=function(t){return r.fromBits(this.low_^t.low_,this.high_^t.high_)},r.prototype.shiftLeft=function(t){if(t&=63,0==t)return this;var e=this.low_;if(32>t){var n=this.high_;return r.fromBits(e<>>32-t)}return r.fromBits(0,e<t){var n=this.low_;return r.fromBits(n>>>t|e<<32-t,e>>t)}return r.fromBits(e>>t-32,e>=0?0:-1)},r.prototype.shiftRightUnsigned=function(t){if(t&=63,0==t)return this;var e=this.high_;if(32>t){var n=this.low_;return r.fromBits(n>>>t|e<<32-t,e>>>t)}return 32==t?r.fromBits(e,0):r.fromBits(e>>>t-32,0)},r.fromInt=function(t){if(t>=-128&&128>t){var e=r.INT_CACHE_[t];if(e)return e}var n=new r(0|t,0>t?-1:0);return t>=-128&&128>t&&(r.INT_CACHE_[t]=n),n},r.fromNumber=function(t){return isNaN(t)||!isFinite(t)?r.ZERO:t<=-r.TWO_PWR_63_DBL_?r.MIN_VALUE:t+1>=r.TWO_PWR_63_DBL_?r.MAX_VALUE:0>t?r.fromNumber(-t).negate():new r(t%r.TWO_PWR_32_DBL_|0,t/r.TWO_PWR_32_DBL_|0)},r.fromBits=function(t,e){return new r(t,e)},r.fromString=function(t,e){if(0==t.length)throw Error("number format error: empty string");var n=e||10;if(2>n||n>36)throw Error("radix out of range: "+n);if("-"==t.charAt(0))return r.fromString(t.substring(1),n).negate();if(t.indexOf("-")>=0)throw Error('number format error: interior "-" character: '+t);for(var i=r.fromNumber(Math.pow(n,8)),o=r.ZERO,s=0;sa){var f=r.fromNumber(Math.pow(n,a));o=o.multiply(f).add(r.fromNumber(u))}else o=o.multiply(i),o=o.add(r.fromNumber(u))}return o},r.INT_CACHE_={},r.TWO_PWR_16_DBL_=65536,r.TWO_PWR_24_DBL_=1<<24,r.TWO_PWR_32_DBL_=r.TWO_PWR_16_DBL_*r.TWO_PWR_16_DBL_,r.TWO_PWR_31_DBL_=r.TWO_PWR_32_DBL_/2,r.TWO_PWR_48_DBL_=r.TWO_PWR_32_DBL_*r.TWO_PWR_16_DBL_,r.TWO_PWR_64_DBL_=r.TWO_PWR_32_DBL_*r.TWO_PWR_32_DBL_,r.TWO_PWR_63_DBL_=r.TWO_PWR_64_DBL_/2,r.ZERO=r.fromInt(0),r.ONE=r.fromInt(1),r.NEG_ONE=r.fromInt(-1),r.MAX_VALUE=r.fromBits(-1,2147483647),r.MIN_VALUE=r.fromBits(0,-2147483648),r.TWO_PWR_24_=r.fromInt(1<<24),e.exports=r,e.exports.Long=r},{}],57:[function(t,e){function r(){return this instanceof r?void(this._bsontype="MaxKey"):new r}e.exports=r,e.exports.MaxKey=r},{}],58:[function(t,e){function r(){return this instanceof r?void(this._bsontype="MinKey"):new r}e.exports=r,e.exports.MinKey=r},{}],59:[function(t,e){(function(r){for(var n=t("./binary_parser").BinaryParser,i=parseInt(16777215*Math.random(),10),o=new RegExp("^[0-9a-fA-F]{24}$"),s=function t(e){if(!(this instanceof t))return new t(e);if(e instanceof t)return e;this._bsontype="ObjectID";var r=t.isValid(e);if(!r&&null!=e)throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");return r&&"string"==typeof e&&24==e.length?t.createFromHexString(e):(null==e||"number"==typeof e?this.id=this.generate(e):null!=e&&12===e.length&&(this.id=e),void(t.cacheHexString&&(this.__id=this.toHexString())))},a=[],u=0;256>u;u++)a[u]=(15>=u?"0":"")+u.toString(16);s.prototype.toHexString=function(){if(s.cacheHexString&&this.__id)return this.__id;for(var t="",e=0;e24)throw new Error("Id cannot be longer than 12 bytes");for(var r,i,o="",a=0;e>a;a+=2)r=t.substr(a,2),i=parseInt(r,16),o+=n.fromByte(i);return new s(o,t)},s.isValid=function(t){return null==t?!1:null!=t&&"number"!=typeof t&&12!=t.length&&24!=t.length?!1:"string"==typeof t&&24==t.length?o.test(t):!0},Object.defineProperty(s.prototype,"generationTime",{enumerable:!0,get:function(){return Math.floor(n.decodeInt(this.id.substring(0,4),32,!0,!0))},set:function(t){var t=n.encodeInt(t,32,!0,!0);this.id=t+this.id.substr(4),this.toHexString()}}),e.exports=s,e.exports.ObjectID=s,e.exports.ObjectId=s}).call(this,t("FWaASH"))},{"./binary_parser":50,FWaASH:46}],60:[function(t,e){function r(t){return this instanceof r?(this._bsontype="Symbol",void(this.value=t)):new r(t)}r.prototype.valueOf=function(){return this.value},r.prototype.toString=function(){return this.value},r.prototype.inspect=function(){return this.value},r.prototype.toJSON=function(){return this.value},e.exports=r,e.exports.Symbol=r},{}],61:[function(t,e){function r(t,e){return this instanceof r?(this._bsontype="Timestamp",this.low_=0|t,void(this.high_=0|e)):new r(t,e)}r.prototype.toInt=function(){return this.low_},r.prototype.toNumber=function(){return this.high_*r.TWO_PWR_32_DBL_+this.getLowBitsUnsigned()},r.prototype.toJSON=function(){return this.toString()},r.prototype.toString=function(t){var e=t||10;if(2>e||e>36)throw Error("radix out of range: "+e);if(this.isZero())return"0";if(this.isNegative()){if(this.equals(r.MIN_VALUE)){var n=r.fromNumber(e),i=this.div(n),o=i.multiply(n).subtract(this);return i.toString(e)+o.toInt().toString(e)}return"-"+this.negate().toString(e)}for(var s=r.fromNumber(Math.pow(e,6)),o=this,a="";;){var u=o.div(s),f=o.subtract(u.multiply(s)).toInt(),c=f.toString(e);if(o=u,o.isZero())return c+a;for(;c.length<6;)c="0"+c;a=""+c+a}},r.prototype.getHighBits=function(){return this.high_},r.prototype.getLowBits=function(){return this.low_},r.prototype.getLowBitsUnsigned=function(){return this.low_>=0?this.low_:r.TWO_PWR_32_DBL_+this.low_},r.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(r.MIN_VALUE)?64:this.negate().getNumBitsAbs();for(var t=0!=this.high_?this.high_:this.low_,e=31;e>0&&0==(t&1<0},r.prototype.greaterThanOrEqual=function(t){return this.compare(t)>=0},r.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},r.prototype.negate=function(){return this.equals(r.MIN_VALUE)?r.MIN_VALUE:this.not().add(r.ONE)},r.prototype.add=function(t){var e=this.high_>>>16,n=65535&this.high_,i=this.low_>>>16,o=65535&this.low_,s=t.high_>>>16,a=65535&t.high_,u=t.low_>>>16,f=65535&t.low_,c=0,h=0,p=0,l=0;return l+=o+f,p+=l>>>16,l&=65535,p+=i+u,h+=p>>>16,p&=65535,h+=n+a,c+=h>>>16,h&=65535,c+=e+s,c&=65535,r.fromBits(p<<16|l,c<<16|h)},r.prototype.subtract=function(t){return this.add(t.negate())},r.prototype.multiply=function(t){if(this.isZero())return r.ZERO;if(t.isZero())return r.ZERO;if(this.equals(r.MIN_VALUE))return t.isOdd()?r.MIN_VALUE:r.ZERO;if(t.equals(r.MIN_VALUE))return this.isOdd()?r.MIN_VALUE:r.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(r.TWO_PWR_24_)&&t.lessThan(r.TWO_PWR_24_))return r.fromNumber(this.toNumber()*t.toNumber());var e=this.high_>>>16,n=65535&this.high_,i=this.low_>>>16,o=65535&this.low_,s=t.high_>>>16,a=65535&t.high_,u=t.low_>>>16,f=65535&t.low_,c=0,h=0,p=0,l=0;return l+=o*f,p+=l>>>16,l&=65535,p+=i*f,h+=p>>>16,p&=65535,p+=o*u,h+=p>>>16,p&=65535,h+=n*f,c+=h>>>16,h&=65535,h+=i*u,c+=h>>>16,h&=65535,h+=o*a,c+=h>>>16,h&=65535,c+=e*f+n*u+i*a+o*s,c&=65535,r.fromBits(p<<16|l,c<<16|h)},r.prototype.div=function(t){if(t.isZero())throw Error("division by zero");if(this.isZero())return r.ZERO;if(this.equals(r.MIN_VALUE)){if(t.equals(r.ONE)||t.equals(r.NEG_ONE))return r.MIN_VALUE;if(t.equals(r.MIN_VALUE))return r.ONE;var e=this.shiftRight(1),n=e.div(t).shiftLeft(1);if(n.equals(r.ZERO))return t.isNegative()?r.ONE:r.NEG_ONE;var i=this.subtract(t.multiply(n)),o=n.add(i.div(t));return o}if(t.equals(r.MIN_VALUE))return r.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();for(var s=r.ZERO,i=this;i.greaterThanOrEqual(t);){for(var n=Math.max(1,Math.floor(i.toNumber()/t.toNumber())),a=Math.ceil(Math.log(n)/Math.LN2),u=48>=a?1:Math.pow(2,a-48),f=r.fromNumber(n),c=f.multiply(t);c.isNegative()||c.greaterThan(i);)n-=u,f=r.fromNumber(n),c=f.multiply(t);f.isZero()&&(f=r.ONE),s=s.add(f),i=i.subtract(c)}return s},r.prototype.modulo=function(t){return this.subtract(this.div(t).multiply(t))},r.prototype.not=function(){return r.fromBits(~this.low_,~this.high_)},r.prototype.and=function(t){return r.fromBits(this.low_&t.low_,this.high_&t.high_)},r.prototype.or=function(t){return r.fromBits(this.low_|t.low_,this.high_|t.high_)},r.prototype.xor=function(t){return r.fromBits(this.low_^t.low_,this.high_^t.high_)},r.prototype.shiftLeft=function(t){if(t&=63,0==t)return this;var e=this.low_;if(32>t){var n=this.high_;return r.fromBits(e<>>32-t)}return r.fromBits(0,e<t){var n=this.low_;return r.fromBits(n>>>t|e<<32-t,e>>t)}return r.fromBits(e>>t-32,e>=0?0:-1)},r.prototype.shiftRightUnsigned=function(t){if(t&=63,0==t)return this;var e=this.high_;if(32>t){var n=this.low_;return r.fromBits(n>>>t|e<<32-t,e>>>t)}return 32==t?r.fromBits(e,0):r.fromBits(e>>>t-32,0)},r.fromInt=function(t){if(t>=-128&&128>t){var e=r.INT_CACHE_[t];if(e)return e}var n=new r(0|t,0>t?-1:0);return t>=-128&&128>t&&(r.INT_CACHE_[t]=n),n},r.fromNumber=function(t){return isNaN(t)||!isFinite(t)?r.ZERO:t<=-r.TWO_PWR_63_DBL_?r.MIN_VALUE:t+1>=r.TWO_PWR_63_DBL_?r.MAX_VALUE:0>t?r.fromNumber(-t).negate():new r(t%r.TWO_PWR_32_DBL_|0,t/r.TWO_PWR_32_DBL_|0)},r.fromBits=function(t,e){return new r(t,e)},r.fromString=function(t,e){if(0==t.length)throw Error("number format error: empty string");var n=e||10;if(2>n||n>36)throw Error("radix out of range: "+n);if("-"==t.charAt(0))return r.fromString(t.substring(1),n).negate();if(t.indexOf("-")>=0)throw Error('number format error: interior "-" character: '+t);for(var i=r.fromNumber(Math.pow(n,8)),o=r.ZERO,s=0;sa){var f=r.fromNumber(Math.pow(n,a));o=o.multiply(f).add(r.fromNumber(u))}else o=o.multiply(i),o=o.add(r.fromNumber(u))}return o},r.INT_CACHE_={},r.TWO_PWR_16_DBL_=65536,r.TWO_PWR_24_DBL_=1<<24,r.TWO_PWR_32_DBL_=r.TWO_PWR_16_DBL_*r.TWO_PWR_16_DBL_,r.TWO_PWR_31_DBL_=r.TWO_PWR_32_DBL_/2,r.TWO_PWR_48_DBL_=r.TWO_PWR_32_DBL_*r.TWO_PWR_16_DBL_,r.TWO_PWR_64_DBL_=r.TWO_PWR_32_DBL_*r.TWO_PWR_32_DBL_,r.TWO_PWR_63_DBL_=r.TWO_PWR_64_DBL_/2,r.ZERO=r.fromInt(0),r.ONE=r.fromInt(1),r.NEG_ONE=r.fromInt(-1),r.MAX_VALUE=r.fromBits(-1,2147483647),r.MIN_VALUE=r.fromBits(0,-2147483648),r.TWO_PWR_24_=r.fromInt(1<<24),e.exports=r,e.exports.Timestamp=r},{}],62:[function(t,e){function r(t,e){return function r(){return r.hookCalled?void 0:(r.hookCalled=!0,t.apply(e,arguments))}}e.exports={hook:function(t,e,n){if(1!==arguments.length||"object"!=typeof t){var i=this.prototype||this,o=i._pres=i._pres||{},s=i._posts=i._posts||{};return o[t]=o[t]||[],s[t]=s[t]||[],i[t]=function(){var o,s=this,a=arguments[arguments.length-1],u=this._pres[t],f=this._posts[t],c=u.length,h=-1,p=i[t].numAsyncPres,l=function(t){return t?d(t):void(--p||g.apply(s,o))},d=function(t){if("function"==typeof a)return a(t);if(n)return n.call(s,t);throw t},y=function(){if(arguments[0]instanceof Error)return d(arguments[0]);var t,e,n=Array.prototype.slice.call(arguments);
-if(!n.length||null==arguments[0]&&"function"==typeof a||(o=n),++h=o)){var e=i[a];if(e.isAsync)e.fn.call(r,function(t){if(t){if(f)return;return f=!0,n(t)}++a,c.apply(r,arguments)},function(t){if(t){if(f)return;return f=!0,n(t)}return 0===--s?n(null):void 0});else if(e.fn.length>0){var h=[function(t){if(t){if(f)return;return f=!0,n(t)}return++a>=o?u>0?void 0:n(null):void c.apply(r,arguments)}];if(arguments.length>=2)for(var p=1;p=o)return u>0?void 0:t.nextTick(function(){n(null)});c()}}};c()},r.prototype.execPost=function(e,r,n,i){var o=this._posts[e]||[],s=o.length,a=0;if(!s)return t.nextTick(function(){i.apply(null,[null].concat(n))});var u=function(){var t=o[a];if(t.length>n.length)t.apply(r,n.concat(function(t){return t?i(t):++a>=s?i.apply(null,[null].concat(n)):void u()}));else{if(t.apply(r,n),++a>=s)return i.apply(null,[null].concat(n));u()}};u()},r.prototype.wrap=function(t,e,r,n,i){var o=n.length>0?n[n.length-1]:null,s=this;this.execPre(t,r,function(a){if(a){if("function"==typeof o)return o(a)}else{var u="function"==typeof o?n.length-1:n.length;e.apply(r,n.slice(0,u).concat(function(){if(arguments[0])return"function"==typeof o?o(arguments[0]):void 0;i&&"function"==typeof o&&o.apply(r,arguments);var e=Array.prototype.slice.call(arguments,1);s.execPost(t,r,e,function(){return arguments[0]?"function"==typeof o?o(arguments[0]):void 0:"function"!=typeof o||i?void 0:o.apply(r,arguments)})}))}})},r.prototype.createWrapper=function(t,e,r){var n=this;return function(){var i=Array.prototype.slice.call(arguments);n.wrap(t,e,r,i)}},r.prototype.pre=function(t,e,r,n){"boolean"!=typeof arguments[1]&&(n=r,r=e,e=!1),this._pres[t]=this._pres[t]||[];var i=this._pres[t];return e&&(i.numAsync=i.numAsync||0,++i.numAsync),i.push({fn:r,isAsync:e}),this},r.prototype.post=function(t,e){return(this._posts[t]=this._posts[t]||[]).push(e),this},r.prototype.clone=function(){var t=new r;for(var e in this._pres)t._pres[e]=this._pres[e].slice();for(var e in this._posts)t._posts[e]=this._posts[e].slice();return t},e.exports=r}).call(this,t("FWaASH"))},{FWaASH:46}],64:[function(t,e,r){e.exports=r=t("./lib")},{"./lib":65}],65:[function(t,e,r){function n(t){return t}r.get=function(t,e,i,o){"function"==typeof i&&(o=i,i=void 0),o||(o=n);var s="string"==typeof t?t.split("."):t;if(!Array.isArray(s))throw new TypeError("Invalid `path`. Must be either string or array");for(var a,u=e,f=0;fp;++p)if(f=u[p],"$"!=f){if(Array.isArray(h)&&!/^\d+$/.test(f)){var d=u.slice(p);if(!c&&Array.isArray(e))for(var y=0;y0},o.prototype.onReject=function(t){if(!t)return this;if("function"!=typeof t)throw new TypeError("fn should be a function");return this.on(o.FAILURE,t)},o.prototype.onResolve=function(t){if(this.end(),!t)return this;if("function"!=typeof t)throw new TypeError("fn should be a function");return this.on(o.FAILURE,function(e){t.call(this,e)}),this.on(o.SUCCESS,function(){t.apply(this,i(null,arguments))}),this},o.prototype.then=function(t,e){var r=new o;return this.onFulfill("function"==typeof t?s(r,t):r.fulfill.bind(r)),this.onReject("function"==typeof e?s(r,e):r.reject.bind(r)),r},o.prototype.end=function(t){return this.onReject(t),this.ended=!0,this},o.trace=function(t,e){t.then(function(){console.log("%s fulfill %j",e,n(arguments))},function(){console.log("%s reject %j",e,n(arguments))})},o.prototype.chain=function(t){var e=this;return e.onFulfill(t.fulfill.bind(t)),e.onReject(t.reject.bind(t)),t},o.prototype.all=function(t){var e=new o;return this.then(t).then(function(t){var r,n=0,i=[];return t.length||e.resolve(),t.forEach(function(t,o){r||(n++,t.then(function(t){r||(i[o]=t,--n,0==n&&e.fulfill(i))},function(t){r||(r=t,e.reject(t))}))}),e},e.reject.bind(e)),e},o.hook=function(t){var e=new o,r=new o,n=function(){return--i,0==i&&r.fulfill(),r},i=1,s=e;return t.forEach(function(t){s=s.then(function(){var e=new o;return i++,t(e.resolve.bind(e),n),e})}),s=s.then(n),e.resolve(),s},o.fulfilled=function(){var t=new o;return t.fulfill.apply(t,arguments),t},o.rejected=function(t){return(new o).reject(t)},o.deferred=function(){var t=new o;return{promise:t,reject:t.reject.bind(t),resolve:t.fulfill.bind(t),callback:t.resolve.bind(t)}}}).call(this,t("FWaASH"))},{FWaASH:46,events:44,util:48}],67:[function(t,e){!function(t){function r(t){return t==Number(t)?Number(t):(n.exec(t.toLowerCase()),RegExp.$1*i[RegExp.$2])}var n=/(\d*.?\d+)([mshd]+)/,i={};i.ms=1,i.s=1e3,i.m=60*i.s,i.h=60*i.m,i.d=24*i.h,t.top?t.ms=r:e.exports=r}(this)},{}],68:[function(t,e,r){function n(t){return"object"==typeof t&&"[object RegExp]"==i.call(t)}var i=Object.prototype.toString;e.exports=r=function(t){if(!n(t))throw new TypeError("Not a RegExp");var e=[];return t.global&&e.push("g"),t.multiline&&e.push("m"),t.ignoreCase&&e.push("i"),new RegExp(t.source,e.join(""))}},{}],69:[function(t,e,r){e.exports=r=t("./lib/sliced")},{"./lib/sliced":70}],70:[function(t,e){e.exports=function(t,e,r){var n=[],i=t.length;if(0===i)return n;var o=0>e?Math.max(0,e+i):e||0;for(void 0!==r&&(i=0>r?r+i:r);i-->o;)n[i-o]=t[i];return n}},{}]},{},[1]);
\ No newline at end of file
+!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;so;++o)Object.defineProperty(r,i[o],{enumerable:!1,writable:!0,configurable:!0,value:void 0});Object.defineProperty(r,"toObject",{enumerable:!0,configurable:!0,writable:!1,value:function(){return t.get(c)}}),Object.defineProperty(r,"toJSON",{enumerable:!0,configurable:!0,writable:!1,value:function(){return t.get(c)}}),Object.defineProperty(r,"$__isNested",{enumerable:!0,configurable:!0,writable:!1,value:!0}),a(e,r,c,s),this.$__.getters[c]=r}return this.$__.getters[c]},set:function(t){return t instanceof o&&(t=t.toObject()),(this.$__.scope||this).set(c,t)}}):Object.defineProperty(r,t,{enumerable:!0,configurable:!0,get:function(){return this.get.call(this.$__.scope||this,c)},set:function(t){return this.set.call(this.$__.scope||this,c,t)}})}function f(t){for(var e,r,n,i=Object.keys(t),o=i.length;o--;)r=i[o],n=t[r],E.isObject(n)&&(t[r]=f(n)),void 0!==t[r]?e=!0:delete t[r];return e?t:void 0}function l(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,l=f-1,h=e,p=0;f>p;++p)u=c[p],p===l?h[u]=O(t.get(i),n):h=h[u]||(h[u]={})}return e}var h,p,d,_=t("events").EventEmitter,y=t("./error"),g=t("./schema/mixed"),v=t("./schema"),m=t("./error/objectExpected"),b=t("./error/strict"),w=t("./schematype").ValidatorError,E=t("./utils"),O=E.clone,A=E.isMongooseObject,S=t("util").inspect,j=y.ValidationError,N=t("./internal"),x=E.deepEqual,B=t("hooks-fixed"),T=t("./promise_provider");E.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=null,a=this;if(e&&"Object"===E.getFunctionName(e.constructor))if(n=Object.keys(e),i=n.length,1===i&&"_id"===n[0])s=!!e[n[i]];else for(;i--;)if("_id"!==n[i]&&(!e[n[i]]||"object"!=typeof e[n[i]])){s=!e[n[i]];break}for(var u=Object.keys(this.schema.paths),c=u.length,f=0;c>f;++f){var l=u[f];if("_id"===l){if(r)continue;if(t&&"_id"in t)continue}for(var h=this.schema.paths[l],p=l.split("."),d=p.length,_=d-1,y="",g=o,v=0,m=!1;d>v;++v){var b,w=p[v];if(y+=w,s===!0){if(y in e)break}else e&&y in e&&(m=!0);if(v===_)if(e&&null!==s)if(s===!0){if(l in e)continue;b=h.getDefault(a,!0),"undefined"!=typeof b&&(g[w]=b,a.$__.activePaths.default(l))}else m&&(b=h.getDefault(a,!0),"undefined"!=typeof b&&(g[w]=b,a.$__.activePaths.default(l)));else b=h.getDefault(a,!0),"undefined"!=typeof b&&(g[w]=b,a.$__.activePaths.default(l));else g=g[w]||(g[w]={}),y+="."}}return o},o.prototype.init=function(t,e,r){if("function"==typeof e&&(r=e,e=null),this.isNew=!1,null!==t._id&&void 0!==t._id&&e&&e.populated&&e.populated.length)for(var n=String(t._id),i=0;io;++o)e=this.getValue(n[o]),A(e)?r[n[o]]=e.toObject({depopulate:!0}):null===e||void 0===e||!e.valueOf||e.constructor&&"Date"===E.getFunctionName(e.constructor)?r[n[o]]=e:r[n[o]]=e.valueOf()};for(var k in B)"pre"===k||"post"===k?o.prototype["$"+k]=o["$"+k]=B[k]:o.prototype[k]=o[k]=B[k];o.prototype.update=function(){var t=E.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"===E.getFunctionName(r.constructor)&&(n=r,r=void 0);var i,s=n&&n.merge,a=r&&r!==!0,u=r===!0,c=n&&"strict"in n?n.strict:this.$__.strictMode;if(a&&(i=this.$__.adhocPaths||(this.$__.adhocPaths={}),i[t]=v.interpretAsType(t,r,this.schema.options)),"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 l,h,p=Object.keys(t),d=p.length;d--;){h=p[d];var _=f+h;if(l=this.schema.pathType(_),null===t[h]||void 0===t[h]||!E.isObject(t[h])||t[h].constructor&&"Object"!==E.getFunctionName(t[h].constructor)||"virtual"===l||"real"===l||this.$__path(_)instanceof g||this.schema.paths[_]&&this.schema.paths[_].options&&this.schema.paths[_].options.ref)if(c){if(u&&void 0===t[h]&&void 0!==this.get(h))continue;if("real"===l||"virtual"===l)this.schema.paths[_]&&this.schema.paths[_].$isSingleNested&&t[h]instanceof o&&(t[h]=t[h].toObject({virtuals:!1})),this.set(f+h,t[h],u);else if("nested"===l&&t[h]instanceof o)this.set(f+h,t[h].toObject({virtuals:!1}),u);else if("throw"===c)throw"nested"===l?new m(h,t[h]):new b(h)}else void 0!==t[h]&&this.set(f+h,t[h],u);else this.set(t[h],f+h,u)}return this}var w=t;t=e,e=w}var O=this.schema.pathType(t);if("nested"===O&&e)return!E.isObject(e)||e.constructor&&"Object"!==E.getFunctionName(e.constructor)?(this.invalidate(t,new y.CastError("Object",e,t)),this):(s||this.setValue(t,null),this.set(e,t,u),this);var A,S=t.split(".");if("adhocOrUndefined"===O&&c){var j;for(d=0;d0&&e[0]instanceof o&&e[0].constructor.modelName&&A.options.type[0].ref===e[0].constructor.modelName&&(this.ownerDocument?($={model:e[0].constructor},this.ownerDocument().populated(this.$__fullPath(t),e.map(function(t){return t._id}),$)):($={model:e[0].constructor},this.populated(t,e.map(function(t){return t._id}),$)),k=!0),e=A.applySetters(e,this,!1,B),!k&&this.$__.populated&&delete this.$__.populated[t],this.$markValid(t)}catch(r){var I;r instanceof y.CastError||(I=r),this.invalidate(t,new y.CastError(A.instance,e,t,I)),T=!1}return T&&this.$__set(x,t,u,S,A,e,B),this},o.prototype.$__shouldModify=function(t,e,r,n,i,s,a){return this.isNew?!0:void 0!==s||this.isSelected(e)?void 0===s&&e in this.$__.activePaths.states.default?!1:this.populated(e)&&s instanceof o&&x(s._id,a)?!1:x(s,a||this.get(e))?!r&&null!==s&&void 0!==s&&e in this.$__.activePaths.states.default&&x(s,i.getDefault(this,r))?!0:!1:!0:!0},o.prototype.$__set=function(e,r,n,i,o,s,a){d=d||t("./types/embedded");var u=this.$__shouldModify(e,r,n,i,o,s,a),c=this;u&&(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+".")&&c.$__.activePaths.ignore(t)})));for(var f=this._doc,l=0,h=i.length;h>l;l++){var _=l+1,y=_===h;y?f[i[l]]=s:f=f[i[l]]&&"Object"===E.getFunctionName(f[i[l]].constructor)?f[i[l]]:f[i[l]]&&f[i[l]]instanceof d?f[i[l]]:f[i[l]]&&f[i[l]].$isSingleNested?f[i[l]]:f[i[l]]&&Array.isArray(f[i[l]])?f[i[l]]:f[i[l]]={}}},o.prototype.getValue=function(t){return E.getValue(t,this._doc)},o.prototype.setValue=function(t,e){return E.setValue(t,e,this._doc),this},o.prototype.get=function(t,e){var r;e&&(r=v.interpretAsType(t,e,this.schema.options));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=null===o||void 0===o?void 0:o[i[s]];return r&&(o=r.cast(o)),n&&!this.populated(t)&&(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,e){var r=this,n=T.get();return"function"==typeof t&&(e=t,t=null),t&&t.__noPromise?void this.$__validate(e):new n.ES6(function(t,n){r.$__validate(function(r){return e&&e(r),r?void n(r):void t()})})},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 y.CastError&&e.invalidate(r,t.errors[r]);return t}},o=Object.keys(this.$__.activePaths.states.require).filter(function(t){return e.isSelected(t)||e.isModified(t)?!0:!1});o=o.concat(Object.keys(this.$__.activePaths.states.init)),o=o.concat(Object.keys(this.$__.activePaths.states.modify)),o=o.concat(Object.keys(this.$__.activePaths.states.default)),0===o.length&&n.nextTick(function(){var e=r();return e?void t(e):void t()});for(var s={},a=0,u=0;uh;++h)o.push(c+"."+h)}var p=function(){var e=r();return e?void t(e):void t()},d=function(t){s[t]||(s[t]=!0,a++,n.nextTick(function(){var r=e.schema.path(t);if(!r)return--a||p();if(!e.$isValid(t))return void(--a||p());var n=e.getValue(t);r.doValidate(n,function(r){r&&e.invalidate(t,r,void 0,!0),--a||p()},e)}))};o.forEach(d)},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;ie.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,void 0,t.options),this.schema=t},o.prototype.$__getArrayPathsToValidate=function(){return h||(h=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.$isSingleNested&&(t=Object.keys(n._doc).reduce(e.bind(n._doc),t),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))}):n instanceof o&&n.$__isNested&&(n=n.toObject(),n&&(t=Object.keys(n).reduce(e.bind(n),t))),t}h||(h=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=T.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):i.set&&(i.set.pre&&i.set.pre.forEach(function(t){r.$pre.apply(r,t)}),i.set.post&&i.set.post.forEach(function(t){r.$post.apply(r,t)}),delete i.set),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 O(this._id,t);t&&t._skipDepopulateTopLevel&&(t._skipDepopulateTopLevel=!1),(!t||"Object"!==E.getFunctionName(t.constructor)||t&&t._useSchemaOptions)&&(e?(t=this.schema.options.toJSON?O(this.schema.options.toJSON):{},t.json=!0,t._useSchemaOptions=!0):(t=this.schema.options.toObject?O(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=O(this._doc,t)||{};t.getters&&(l(this,o,"paths",t),t.minimize&&(o=f(o)||{})),(t.virtuals||t.getters&&t.virtuals!==!1)&&l(this,o,"virtuals",t),t.versionKey===!1&&this.schema.options.versionKey&&delete o[this.schema.options.versionKey];var s=t.transform;if(s===!0||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,r=t&&"Object"===E.getFunctionName(t.constructor);return e=r?t:this.schema.options.toObject?O(this.schema.options.toObject):{},e.minimize=!1,e.retainKeyOrder=!0,this.toObject(e)},o.prototype.toString=function(){return S(this.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:x(this,t)},o.prototype.populate=function(){if(0===arguments.length)return this;var t,e=this.$__.populate||(this.$__.populate={}),r=E.args(arguments);if("function"==typeof r[r.length-1]&&(t=r.pop()),r.length)for(var n=E.populate.apply(null,r),i=0;in;++n)t(e[n],this.paths[e[n]]);return this},i.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},i.prototype.indexedPaths=function(){return this._indexedpaths?this._indexedpaths:(this._indexedpaths=this.indexes(),this._indexedpaths)},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":t in this.singleNestedPaths?"real":/\.\d+\.|\.\d+$/.test(t)?s(this,t):"adhocOrUndefined"},i.prototype.hasMixedParent=function(t){var e=t.split(/\./g);t="";for(var r=0;r0?t+"."+e[r]:e[r],t in this.paths&&this.paths[t]instanceof u.Mixed)return!0;return!1},i.prototype.setupTimestamp=function(t){if(t){var e=t.createdAt||"createdAt",r=t.updatedAt||"updatedAt",n={};n[r]=Date,this.paths[e]||(n[e]=Date),this.add(n),this.pre("save",function(t){var n=new Date,i=this._id&&this._id.auto;this[e]||(this[e]=i?this._id.getTimestamp():n),(this.isNew||this.isModified())&&(this[r]=this.isNew?this[e]:n),t()});var i=function(){var t=new Date,n={$set:{},$setOnInsert:{}};return n.$set[r]=t,n.$setOnInsert[e]=t,n};this.pre("findOneAndUpdate",function(t){this.findOneAndUpdate({},i()),t()}),this.pre("update",function(t){this.update({},i()),t()})}},i.prototype.queue=function(t,e){return this.callQueue.push([t,e]),this},i.prototype.pre=function(){var t=arguments[0];return _[t]?(this.s.hooks.pre.apply(this.s.hooks,arguments),this):this.queue("pre",arguments)},i.prototype.post=function(t,e){return _[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]=c(e,r);break;case"safe":this.options[t]=e===!1?{w:0}:e;break;case"timestamps":this.setupTimestamp(e),this.options[t]=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,l=0;for(l=0;f>l;++l){for(n=c[l][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[l][1]])}}var e=[],r={},n=function(o,s){if(!r[s]){r[s]=!0,s=s||"";for(var a,c,f,l,p,d,_,y=Object.keys(o.paths),g=0;go;++o)e=n[o],r=t[e],0===e.indexOf("$")&&r&&(t[e]=this.castForQuery(e,r));return v(this.casterConstructor.schema,t)}function l(t){var e=t.$geometry;if(e)return a(t,this),t}var h=t("../schematype"),p=h.CastError,d={Boolean:t("./boolean"),Date:t("./date"),Number:t("./number"),String:t("./string"),ObjectId:t("./objectid"),Buffer:t("./buffer")},_=t("../types").Array,y=t("../types").Embedded,g=t("./mixed"),v=t("../cast"),m=t("../utils"),b=m.isMongooseObject;n.schemaName="Array",n.prototype=Object.create(h.prototype),n.prototype.constructor=n,n.prototype.checkRequired=function(t){return!(!t||!t.length)},n.prototype.applyGetters=function(t,e){return this.caster.options&&this.caster.options.ref?t:h.prototype.applyGetters.call(this,t,e)},n.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 _(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 p(e.type,t,this.path,e)}return t}return e&&r&&e.markModified(this.path),this.cast([t],e,r)},n.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 m.isObject(t)&&t.$elemMatch?t:(o&&(t=o.call(s,t)),b(t)?t.toObject({virtuals:!1}):t)}):o&&(n=o.call(s,n))}return n&&b(n)?n.toObject({virtuals:!1}):n};var w=n.prototype.$conditionalHandlers={};w.$all=c,w.$options=String,w.$elemMatch=f,w.$geoIntersects=l,w.$or=w.$and=function(t){if(!Array.isArray(t))throw new TypeError("conditional $or/$and require array");for(var e=[],r=0;r=r.valueOf()},message:r,type:"min",min:t})}return this},n.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},n.prototype.cast=function(t){if(null===t||void 0===t||""===t)return null;if(t instanceof Date)return t;var e;if("boolean"==typeof t)throw new u("date",t,this.path);if(t instanceof Number||"number"==typeof t||String(t)==Number(t)?e=new Date(Number(t)):t.valueOf&&(e=new Date(t.valueOf())),!isNaN(e.valueOf()))return e;throw new u("date",t,this.path)},n.prototype.$conditionalHandlers=s.options(a.prototype.$conditionalHandlers,{$gt:i,$gte:i,$lt:i,$lte:i}),n.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=n},{"../error":12,"../schematype":39,"../utils":48}],31:[function(t,e,r){function n(t,e,r){function n(){c.apply(this,arguments)}n.prototype=Object.create(c.prototype),n.prototype.$__setSchema(e),n.schema=e;for(var i in e.methods)n.prototype[i]=e.methods[i];for(i in e.statics)n[i]=e.statics[i];n.options=r,o.call(this,t,n,r),this.schema=e;var s=this.path,u=this.defaultValue;this.default(function(){var t=u.call(this);return Array.isArray(t)||(t=[t]),new a(t,s,this)})}function i(t,e,r){if(r&&e){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 o=t("./array"),s=t("../error/cast"),a=t("../types/documentarray"),u=t("../schematype"),c=t("../types/embedded");n.schemaName="DocumentArray",n.prototype=Object.create(o.prototype),n.prototype.constructor=n,n.prototype.doValidate=function(t,e,r,n){u.prototype.doValidate.call(this,t,function(r){function i(t){t&&(o=t),--s||e(o)}if(r)return e(r);var o,s=t&&t.length;if(!s)return e();if(n&&n.updateValidator)return e();for(var a=0,u=s;u>a;++a){var c=t[a];c?c.$__original_validate?c.$__original_validate({__noPromise:!0},i):c.validate({__noPromise:!0},i):--s||e(o)}},r)},n.prototype.doValidateSync=function(t,e){var r=u.prototype.doValidateSync.call(this,t,e);if(r)return r;var n=t&&t.length,i=null;if(n){for(var o=0,s=n;s>o&&!i;++o){var a=t[o];if(a){var c=a.validateSync();c&&(i=c)}}return i}},n.prototype.cast=function(t,e,r,n,o){var u,f,l;if(!Array.isArray(t))return e&&r&&e.markModified(this.path),this.cast([t],e,r,n);if(!(t&&t.isMongooseDocumentArray||o&&o.skipDocumentArrayCast)&&(t=new a(t,this.path,e),n&&n._handlers))for(var h in n._handlers)e.removeListener(h,n._handlers[h]);for(l=t.length;l--;)if(t[l]&&(t[l]instanceof c&&t[l].schema!==this.casterConstructor.schema&&(t[l]=t[l].toObject({virtuals:!1})),!(t[l]instanceof c)&&t[l]))if(r)u||(u=i(this,e.$__.selected,r)),f=new this.casterConstructor(null,t,!0,u,l),t[l]=f.init(t[l]);else{try{f=n.id(t[l]._id)}catch(t){}if(n&&f)f.set(t[l]),t[l]=f;else try{f=new this.casterConstructor(t[l],t,void 0,void 0,l),t[l]=f}catch(e){throw new s("embedded",t[l],t._path,e)}}return t},e.exports=n},{"../error/cast":13,"../schematype":39,"../types/documentarray":43,"../types/embedded":44,"./array":27}],32:[function(t,e,r){function n(t,e,r){var n=function(t,e,r){var n=this;o.apply(this,arguments),this.$parent=r,r&&r.on("save",function(){n.emit("save",n)})};n.prototype=Object.create(o.prototype),n.prototype.$__setSchema(t),n.schema=t,n.$isSingleNested=!0,n.prototype.$basePath=e;for(var s in t.methods)n.prototype[s]=t.methods[s];for(s in t.statics)n[s]=t.statics[s];this.caster=n,this.schema=t,this.$isSingleNested=!0,i.call(this,e,r,"Embedded")}var i=t("../schematype"),o=t("../types/subdocument");e.exports=n,n.prototype=Object.create(i.prototype),n.prototype.$conditionalHandlers.$geoWithin=function(t){return{$geometry:this.castForQuery(t.$geometry)}},n.prototype.cast=function(t,e,r){if(t&&t.$isSingleNested)return t;var n=new this.caster(void 0,e?e.$__.selected:void 0,e);return r?n.init(t):n.set(t,void 0,!0),n},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);return r.call(this,e)}return e=t,new this.caster(e).toObject({virtuals:!1})},n.prototype.doValidate=function(t,e){i.prototype.doValidate.call(this,t,function(r){return r?e(r):t?void t.validate(e,{__noPromise:!0}):e(null)})},n.prototype.doValidateSync=function(t){var e=i.prototype.doValidateSync.call(this,t);if(e)return e;if(t)return t.validateSync()}},{"../schematype":39,"../types/subdocument":47}],33:[function(t,e,r){r.String=t("./string"),r.Number=t("./number"),r.Boolean=t("./boolean"),r.DocumentArray=t("./documentarray"),r.Embedded=t("./embedded"),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":27,"./boolean":28,"./buffer":29,"./date":30,"./documentarray":31,"./embedded":32,"./mixed":34,"./number":35,"./objectid":36,"./string":38}],34:[function(t,e,r){function n(t,e){if(e&&e.default){var r=e.default;Array.isArray(r)&&0===r.length?e.default=Array:!e.shared&&o.isObject(r)&&0===Object.keys(r).length&&(e.default=function(){return{}})}i.call(this,t,e,"Mixed")}var i=t("../schematype"),o=t("../utils");n.schemaName="Mixed",n.prototype=Object.create(i.prototype),n.prototype.constructor=n,n.prototype.cast=function(t){return t},n.prototype.castForQuery=function(t,e){return 2===arguments.length?e:t},e.exports=n},{"../schematype":39,"../utils":48}],35:[function(t,e,r){(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 Array.isArray(t)?t.map(function(t){return e.cast(t)}):[this.cast(t)]}var s,a=t("../schematype"),u=a.CastError,c=t("./operators/bitwise"),f=t("../error").messages,l=t("../utils");n.schemaName="Number",n.prototype=Object.create(a.prototype),n.prototype.constructor=n,n.prototype.checkRequired=function(t,e){return a._isRef(this,t,e,!0)?!!t:"number"==typeof t||t instanceof Number},n.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||f.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},n.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||f.Number.max;r=r.replace(/{MAX}/,t),this.validators.push({validator:this.maxValidator=function(e){return null==e||t>=e},message:r,type:"max",max:t})}return this},n.prototype.cast=function(e,n,i){if(a._isRef(this,e,n,i)){if(null===e||void 0===e)return e;if(s||(s=t("./../document")),e instanceof s)return e.$__.wasPopulated=!0,e;if("number"==typeof e)return e;if(r.isBuffer(e)||!l.isObject(e))throw new u("number",e,this.path);var o=n.$__fullPath(this.path),c=n.ownerDocument?n.ownerDocument():n,f=c.populated(o,!0),h=new f.options.model(e);return h.$__.wasPopulated=!0,h}var p=e&&e._id?e._id:e;if(!isNaN(p)){if(null===p)return p;if(""===p)return null;if(("string"==typeof p||"boolean"==typeof p)&&(p=Number(p)),p instanceof Number)return p;if("number"==typeof p)return p;if(p.toString&&!Array.isArray(p)&&p.toString()==Number(p))return new Number(p)}throw new u("number",e,this.path)},n.prototype.$conditionalHandlers=l.options(a.prototype.$conditionalHandlers,{$bitsAllClear:c,$bitsAnyClear:c,$bitsAllSet:c,$bitsAnySet:c,$gt:i,$gte:i,$lt:i,$lte:i,$mod: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 Number.");return r.call(this,e)}return e=this.cast(t)},e.exports=n}).call(this,t("buffer").Buffer)},{"../error":12,"../schematype":39,"../utils":48,"./../document":5,"./operators/bitwise":37,buffer:71}],36:[function(t,e,r){(function(r){function n(t,e){u.call(this,t,e,"ObjectID")}function i(t){return this.cast(t)}function o(){return new f}function s(t){return this.$__._id=null,t}var a,u=t("../schematype"),c=u.CastError,f=t("../types/objectid"),l=t("../utils");n.schemaName="ObjectId",n.prototype=Object.create(u.prototype),n.prototype.constructor=n,n.prototype.auto=function(t){return t&&(this.default(o),this.set(s)),this},n.prototype.checkRequired=function(t,e){return u._isRef(this,t,e,!0)?!!t:t instanceof f},n.prototype.cast=function(e,n,i){if(u._isRef(this,e,n,i)){if(null===e||void 0===e)return e;if(a||(a=t("./../document")),e instanceof a)return e.$__.wasPopulated=!0,e;if(e instanceof f)return e;if(r.isBuffer(e)||!l.isObject(e))throw new c("ObjectId",e,this.path);var o=n.$__fullPath(this.path),s=n.ownerDocument?n.ownerDocument():n,h=s.populated(o,!0),p=e;return n.$__.populated&&n.$__.populated[o]&&n.$__.populated[o].options&&n.$__.populated[o].options.options&&n.$__.populated[o].options.options.lean||(p=new h.options.model(e),p.$__.wasPopulated=!0),p}if(null===e||void 0===e)return e;if(e instanceof f)return e;if(e._id){if(e._id instanceof f)return e._id;if(e._id.toString instanceof Function)try{return f.createFromHexString(e._id.toString())}catch(t){}}if(e.toString instanceof Function)try{return f.createFromHexString(e.toString())}catch(t){throw new c("ObjectId",e,this.path)}throw new c("ObjectId",e,this.path)},n.prototype.$conditionalHandlers=l.options(u.prototype.$conditionalHandlers,{$gt:i,$gte:i,$lt:i,$lte:i}),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 ObjectId.");return r.call(this,e)}return this.cast(t)},e.exports=n}).call(this,t("buffer").Buffer)},{"../schematype":39,"../types/objectid":46,"../utils":48,"./../document":5,buffer:71}],37:[function(t,e,r){(function(r){function n(t){var e=this;return Array.isArray(t)?t.map(function(t){return i(e.path,t)}):r.isBuffer(t)?t:i(e.path,t)}function i(t,e){var r=Number(e);if(isNaN(r))throw new o("number",e,t);return r}var o=t("../../error/cast");e.exports=n}).call(this,t("buffer").Buffer)},{"../../error/cast":13,buffer:71}],38:[function(t,e,r){(function(r){function n(t,e){this.enumValues=[],this.regExp=null,a.call(this,t,e,"String")}function i(t){return this.castForQuery(t)}function o(t){var e=this;return Array.isArray(t)?t.map(function(t){return e.castForQuery(t)}):[this.castForQuery(t)]}var s,a=t("../schematype"),u=a.CastError,c=t("../error").messages,f=t("../utils");n.schemaName="String",n.prototype=Object.create(a.prototype),n.prototype.constructor=n,n.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]||arguments[0]===!1)return this;var t,e;f.isObject(arguments[0])?(t=arguments[0].values,e=arguments[0].message):(t=arguments,e=c.String.enum);for(var r=0;r=t},message:r,type:"minlength",minlength:t})}return this},n.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||c.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},n.prototype.match=function(t,e){var r=e||c.String.match,n=function(e){if(!t)return!1;var r=null!=e&&""!==e?t.test(e):!0;return r};return this.validators.push({validator:n,message:r,type:"regexp",regexp:t}),this},n.prototype.checkRequired=function(t,e){return a._isRef(this,t,e,!0)?!!t:(t instanceof String||"string"==typeof t)&&t.length},n.prototype.cast=function(e,n,i){if(a._isRef(this,e,n,i)){if(null===e||void 0===e)return e;if(s||(s=t("./../document")),e instanceof s)return e.$__.wasPopulated=!0,e;if("string"==typeof e)return e;if(r.isBuffer(e)||!f.isObject(e))throw new u("string",e,this.path);var o=n.$__fullPath(this.path),c=n.ownerDocument?n.ownerDocument():n,l=c.populated(o,!0),h=new l.options.model(e);return h.$__.wasPopulated=!0,h}if(null===e||void 0===e)return e;if("undefined"!=typeof e){if(e._id&&"string"==typeof e._id)return e._id;if(e.toString&&e.toString!==Object.prototype.toString)return e.toString()}throw new u("string",e,this.path)},n.prototype.$conditionalHandlers=f.options(a.prototype.$conditionalHandlers,{$all:o,$gt:i,$gte:i,$lt:i,$lte:i,$options:i,$regex:i}),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 String.");return r.call(this,e)}return e=t,"[object RegExp]"===Object.prototype.toString.call(e)?e:this.cast(e)},e.exports=n}).call(this,t("buffer").Buffer)},{"../error":12,"../schematype":39,"../utils":48,"./../document":5,buffer:71}],39:[function(t,e,r){(function(n){function i(t,e,r){this.path=t,this.instance=r,this.validators=[],this.setters=[],this.getters=[],this.options=e,this._index=null,this.selected;for(var n in e)if(this[n]&&"function"==typeof this[n]){if("index"===n&&this._index)continue;var i=Array.isArray(e[n])?e[n]:[e[n]];this[n].apply(this,i)}}function o(t){return this.castForQuery(t)}function s(t){var e=this;return Array.isArray(t)?t.map(function(t){return e.castForQuery(t)}):[this.castForQuery(t)]}var a=t("./utils"),u=t("./error"),c=u.messages,f=u.CastError,l=u.ValidatorError;i.prototype.default=function(t){return 1===arguments.length?(this.defaultValue="function"==typeof t?t:this.cast(t),this):(arguments.length>1&&(this.defaultValue=a.args(arguments)),this.defaultValue)},i.prototype.index=function(t){return this._index=t,a.expires(this._index),this},i.prototype.unique=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.unique=t,this},i.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},i.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},i.prototype.set=function(t){if("function"!=typeof t)throw new TypeError("A setter must be a function.");return this.setters.push(t),this},i.prototype.get=function(t){if("function"!=typeof t)throw new TypeError("A getter must be a function.");return this.getters.push(t),this},i.prototype.validate=function(t,e,r){if("function"==typeof t||t&&"RegExp"===a.getFunctionName(t.constructor)){var n;return e instanceof Object&&!r?(n=a.clone(e),n.message||(n.message=n.msg),n.validator=t,n.type=n.type||"user defined"):(e||(e=c.general.default),r||(r="user defined"),n={message:e,type:r,validator:t}),this.validators.push(n),this}var i,o,s;for(i=0,o=arguments.length;o>i;i++){if(s=arguments[i],!s||"Object"!==a.getFunctionName(s.constructor)){var u="Invalid validator. Received ("+typeof s+") "+s+". See http://mongoosejs.com/docs/api.html#schematype_SchemaType-validate";throw new Error(u)}this.validate(s.validator,s)}return this},i.prototype.required=function(t,e){if(t===!1)return this.validators=this.validators.filter(function(t){return t.validator!==this.requiredValidator},this),this.isRequired=!1,this;var r=this;this.isRequired=!0,this.requiredValidator=function(e){return"isSelected"in this&&!this.isSelected(r.path)&&!this.isModified(r.path)?!0:"function"==typeof t&&!t.apply(this)||r.checkRequired(e,this)},"string"==typeof t&&(e=t,t=void 0);var n=e||c.general.required;return this.validators.unshift({validator:this.requiredValidator,message:n,type:"required"}),this},i.prototype.getDefault=function(t,e){var r="function"==typeof this.defaultValue?this.defaultValue.call(t):this.defaultValue;return null!==r&&void 0!==r?this.cast(r,t,e):r},i.prototype.applySetters=function(t,e,r,n,i){for(var o=t,s=this.setters,a=s.length,u=this.caster;a--;)o=s[a].call(e,o,this);if(Array.isArray(o)&&u&&u.setters){for(var c=[],f=0;fr?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(){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(){var t=[].map.call(arguments,this._mapCast,this);t=this._schema.applySetters(t,this._parent);var e=[],r="";return t[0]instanceof o?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 r=this._schema.caster instanceof o?r:this._schema.caster.applySetters(e,this._parent),this[t]=r,this._markModified(t),this},toObject:function(t){return t&&t.depopulate?this.map(function(e){return e instanceof s?e.toObject(t):e}):this.slice()},inspect:function(){return JSON.stringify(this)},indexOf:function(t){t instanceof a&&(t=t.toString());for(var e=0,r=this.length;r>e;++e)if(t==this[e])return e;return-1}},i.mixin.remove=i.mixin.pull,e.exports=r=i}).call(this,t("buffer").Buffer)},{"../document":5,"../utils":48,"./embedded":44,"./objectid":46,buffer:71}],42:[function(t,e,r){(function(r){function n(t,e,i){var s,a=arguments.length;s=0===a||null===arguments[0]||void 0===arguments[0]?0:t;var u,c,f;Array.isArray(e)?(c=e[0],f=e[1]):u=e;var l=new r(s,u,i);return o.decorate(l,n.mixin),l.isMongooseBuffer=!0,Object.defineProperties(l,{validators:{value:[]},_path:{value:c},_parent:{value:f}}),f&&"string"==typeof c&&Object.defineProperty(l,"_schema",{value:f.schema.path(c)}),l._subtype=0,l}var i=t("../drivers").Binary,o=t("../utils");n.mixin={_parent:void 0,_subtype:void 0,_markModified:function(){var t=this._parent;return t&&t.markModified(this._path),this},write:function(){var t=r.prototype.write.apply(this,arguments);return t>0&&this._markModified(),t},copy:function(t){var e=r.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){r.prototype[t]&&(n.mixin[t]=function(){var e=r.prototype[t].apply(this,arguments);return this._markModified(),e})}),n.mixin.toObject=function(t){var e="number"==typeof t?t:this._subtype||0;return new i(this,e)},n.mixin.equals=function(t){if(!r.isBuffer(t))return!1;if(this.length!==t.length)return!1;for(var e=0;ec;c++)if(n=this[c].get("_id"),null!==n&&"undefined"!=typeof n)if(n instanceof u){if(r||(r=String(t)),r==n._id)return this[c]}else if(t instanceof o||n instanceof o){if(e==n)return this[c]}else if(a.deepEqual(t,n))return this[c];return null},toObject:function(t){return this.map(function(e){return e&&e.toObject(t)||null})},inspect:function(){return Array.prototype.slice.call(this)},create:function(t){return new this._schema.casterConstructor(t)},notify:function(t){var e=this;return function(r){for(var n=e.length;n--;)if(e[n]){switch(t){case"save":r=e[n]}e[n].emit(t,r)}}}},e.exports=n}).call(this,t("buffer").Buffer)},{"../document":5,"../schema/objectid":36,"../utils":48,"./array":41,"./objectid":46,buffer:71}],44:[function(t,e,r){function n(t,e,r,n,i){e?(this.__parentArray=e,this.__parent=e._parent):(this.__parentArray=void 0,this.__parent=void 0),this.__index=i,o.call(this,t,n,r);var s=this;this.on("isNew",function(t){s.isNew=t})}function i(t){function e(){r.removeListener("save",e),r.removeListener("remove",e),t.emit("remove",t),r=t=null}var r=t.ownerDocument();r.on("save",e),r.on("remove",e)}var o=t("../document_provider")(),s=t("../promise_provider");n.prototype=Object.create(o.prototype),n.prototype.constructor=n,n.prototype.markModified=function(t){this.$__.activePaths.modify(t),this.__parentArray&&(this.isNew?this.__parentArray._markModified():this.__parentArray._markModified(this,t))},n.prototype.save=function(t){var e=s.get();return new e.ES6(function(e){t&&t(),e()})},n.prototype.remove=function(t){if(!this.__parentArray)return this;var e;if(!this.willRemove){if(e=this._doc._id,!e)throw new Error("For your own good, Mongoose does not know how to remove an EmbeddedDocument that has no _id");this.__parentArray.pull({_id:e}),this.willRemove=!0,i(this)}return t&&t(null),this},n.prototype.update=function(){throw new Error("The #update method is not available on EmbeddedDocuments")},n.prototype.inspect=function(){return this.toObject()},n.prototype.invalidate=function(t,e,r,n){if(!this.__parent){var i="Unable to invalidate a subdocument that has not been added to an array.";throw new Error(i)}var o=this.__index;if("undefined"!=typeof o){var s=this.__parentArray._path,a=[s,o,t].join(".");this.__parent.invalidate(a,e,r)}return n&&(this.$__.validationError=this.ownerDocument().$__.validationError),!0},n.prototype.$markValid=function(t){if(this.__parent){var e=this.__index;if("undefined"!=typeof e){var r=this.__parentArray._path,n=[r,e,t].join(".");this.__parent.$markValid(n)}}},n.prototype.$isValid=function(t){var e=this.__index;return"undefined"!=typeof e?!this.__parent.$__.validationError||!this.__parent.$__.validationError.errors[this.$__fullPath(t)]:!0},n.prototype.ownerDocument=function(){if(this.$__.ownerDocument)return this.$__.ownerDocument;var t=this.__parent;if(!t)return this;for(;t.__parent;)t=t.__parent;return this.$__.ownerDocument=t,this.$__.ownerDocument},n.prototype.$__fullPath=function(t){if(!this.$__.fullPath){var e=this;if(!e.__parent)return t;for(var r=[];e.__parent;)r.unshift(e.__parentArray._path),e=e.__parent;this.$__.fullPath=r.join("."),this.$__.ownerDocument||(this.$__.ownerDocument=e)}return t?this.$__.fullPath+"."+t:this.$__.fullPath},n.prototype.parent=function(){return this.__parent},n.prototype.parentArray=function(){return this.__parentArray},e.exports=n},{"../document_provider":6,"../promise_provider":25}],45:[function(t,e,r){r.Array=t("./array"),r.Buffer=t("./buffer"),r.Document=r.Embedded=t("./embedded"),r.DocumentArray=t("./documentarray"),r.ObjectId=t("./objectid"),r.Subdocument=t("./subdocument")},{"./array":41,"./buffer":42,"./documentarray":43,"./embedded":44,"./objectid":46,"./subdocument":47}],46:[function(t,e,r){var n=t("../drivers").ObjectId;e.exports=n},{"../drivers":11}],47:[function(t,e,r){function n(t,e){this.$isSingleNested=!0,o.call(this,t,e)}function i(t){function e(){r.removeListener("save",e),r.removeListener("remove",e),t.emit("remove",t),r=t=null}var r=t.ownerDocument();r.on("save",e),r.on("remove",e)}var o=t("../document"),s=t("../promise_provider");e.exports=n,n.prototype=Object.create(o.prototype),n.prototype.save=function(t){var e=s.get();return new e.ES6(function(e){t&&t(),e()})},n.prototype.$isValid=function(t){return this.$parent?this.$parent.$isValid([this.$basePath,t].join(".")):void 0},n.prototype.markModified=function(t){o.prototype.markModified.call(this,t),this.$parent&&this.$parent.markModified([this.$basePath,t].join("."))},n.prototype.$markValid=function(t){this.$parent&&this.$parent.$markValid([this.$basePath,t].join("."))},n.prototype.invalidate=function(t,e,r){if(this.$parent)this.$parent.invalidate([this.$basePath,t].join("."),e,r);else if("cast"===e.kind||"CastError"===e.name)throw e},n.prototype.ownerDocument=function(){if(this.$__.ownerDocument)return this.$__.ownerDocument;var t=this.$parent;if(!t)return this;for(;t.$parent;)t=t.$parent;return this.$__.ownerDocument=t,this.$__.ownerDocument},n.prototype.remove=function(t){this.$parent.set(this.$basePath,null),i(this),t&&t(null)}},{"../document":5,"../promise_provider":25}],48:[function(t,e,r){(function(e,n){function i(t){var e;return!~g.indexOf(t.toLowerCase())&&(e=y.filter(function(e){return t.match(e[0])}),e[0])?t.replace(e[0][0],e[0][1]):t}function o(t,e){var r,n,i,o,s,a=e&&e.retainKeyOrder,u=e&&e.minimize,c={};if(a)for(o in t)i=v(t[o],e),u&&"undefined"==typeof i||(r||(r=!0),c[o]=i);else for(n=Object.keys(t),s=n.length;s--;)o=n[s],i=v(t[o],e),u&&"undefined"==typeof i||(r||(r=!0),c[o]=i);return u?r&&c:c}function s(t,e){for(var r=[],n=0,i=t.length;i>n;n++)r.push(v(t[n],e));return r}function a(t,e,r,n,i,o){this.path=t,this.match=r,this.select=e,this.options=n,this.model=i,"object"==typeof o&&(this.populate=o),this._docs={}}var u,c,f,l=t("./types/objectid"),h=t("regexp-clone"),p=t("sliced"),d=t("mpath"),_=t("ms");r.toCollectionName=function(t,e){return e=e||{},"system.profile"===t?t:"system.indexes"===t?t:e.pluralization===!1?t:i(t.toLowerCase())},r.pluralization=[[/(m)an$/gi,"$1en"],[/(pe)rson$/gi,"$1ople"],[/(child)$/gi,"$1ren"],[/^(ox)$/gi,"$1en"],[/(ax|test)is$/gi,"$1es"],[/(octop|vir)us$/gi,"$1i"],[/(alias|status)$/gi,"$1es"],[/(bu)s$/gi,"$1ses"],[/(buffal|tomat|potat)o$/gi,"$1oes"],[/([ti])um$/gi,"$1a"],[/sis$/gi,"ses"],[/(?:([^f])fe|([lr])f)$/gi,"$1$2ves"],[/(hive)$/gi,"$1s"],[/([^aeiouy]|qu)y$/gi,"$1ies"],[/(x|ch|ss|sh)$/gi,"$1es"],[/(matr|vert|ind)ix|ex$/gi,"$1ices"],[/([m|l])ouse$/gi,"$1ice"],[/(kn|w|l)ife$/gi,"$1ives"],[/(quiz)$/gi,"$1zes"],[/s$/gi,"s"],[/([^a-z])$/,"$1"],[/$/gi,"s"]];var y=r.pluralization;r.uncountables=["advice","energy","excretion","digestion","cooperation","health","justice","labour","machinery","equipment","information","pollution","sewage","paper","money","species","series","rain","rice","fish","sheep","moose","deer","news","expertise","status","media"];var g=r.uncountables;r.deepEqual=function t(e,i){if(e===i)return!0;if(e instanceof Date&&i instanceof Date)return e.getTime()===i.getTime();if(e instanceof l&&i instanceof l)return e.toString()===i.toString();if(e instanceof RegExp&&i instanceof RegExp)return e.source===i.source&&e.ignoreCase===i.ignoreCase&&e.multiline===i.multiline&&e.global===i.global;if("object"!=typeof e&&"object"!=typeof i)return e==i;if(null===e||null===i||void 0===e||void 0===i)return!1;if(e.prototype!==i.prototype)return!1;if(e instanceof Number&&i instanceof Number)return e.valueOf()===i.valueOf();if(n.isBuffer(e))return r.buffer.areEqual(e,i);b(e)&&(e=e.toObject()),b(i)&&(i=i.toObject());try{var o,s,a=Object.keys(e),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(o=a[s],!t(e[o],i[o]))return!1;return!0},r.clone=function(t,e){if(void 0===t||null===t)return t;if(Array.isArray(t))return s(t,e);if(b(t))return e&&e.json&&"function"==typeof t.toJSON?t.toJSON(e):t.toObject(e);if(t.constructor)switch(r.getFunctionName(t.constructor)){case"Object":return o(t,e);case"Date":return new t.constructor(+t);case"RegExp":return h(t)}return t instanceof l?new l(t.id):!t.constructor&&r.isObject(t)?o(t,e):t.valueOf?t.valueOf():void 0};var v=r.clone;r.options=function(t,e){var r,n=Object.keys(t),i=n.length;for(e=e||{};i--;)r=n[i],r in e||(e[r]=t[r]);return e},r.random=function(){return Math.random().toString().substr(3)},r.merge=function t(e,n){for(var i,o=Object.keys(n),s=o.length;s--;)i=o[s],"undefined"==typeof e[i]?e[i]=n[i]:r.isObject(n[i])&&t(e[i],n[i])};var m=Object.prototype.toString;r.toObject=function t(e){var n;if(r.isNullOrUndefined(e))return e;if(e instanceof f)return e.toObject();if(Array.isArray(e)){n=[];for(var i=0,o=e.length;o>i;++i)n.push(t(e[i]));return n}if(e.constructor&&"Object"===r.getFunctionName(e.constructor)||!e.constructor&&r.isObject(e)){n={};for(var s in e)n[s]=t(e[s]);return n}return e},r.isObject=function(t){return n.isBuffer(t)?!0:"[object Object]"===m.call(t)},r.args=p,r.tick=function(t){return"function"==typeof t?function(){try{t.apply(this,arguments)}catch(t){e.nextTick(function(){throw t})}}:void 0},r.isMongooseObject=function(e){return f||(f=t("./document")),c||(c=t("./types").Array),u||(u=t("./types").Buffer),e instanceof f||e&&e.isMongooseArray||e&&e.isMongooseBuffer};var b=r.isMongooseObject;r.expires=function(t){if(t&&"Object"===t.constructor.name&&"expires"in t){var e;e="string"!=typeof t.expires?t.expires:Math.round(_(t.expires)/1e3),t.expireAfterSeconds=e,delete t.expires}},a.prototype.constructor=Object,r.PopulateOptions=a,r.populate=function(t,e,n,i,o,s){if(1===arguments.length){if(t instanceof a)return[t];if(Array.isArray(t))return t.map(function(t){return r.populate(t)[0]});r.isObject(t)&&(i=t.match,o=t.options,e=t.select,n=t.model,s=t.populate,t=t.path)}else"string"!=typeof n&&"function"!=typeof n&&(o=i,i=n,n=void 0);if("string"!=typeof t)throw new TypeError("utils.populate: invalid path. Expected string. Got typeof `"+typeof t+"`");"object"==typeof s&&(s=r.populate(s));var u=[],c=t.split(" ");o=r.clone(o,{retainKeyOrder:!0});for(var f=0;fo;++o)if("number"==typeof t[o]||"string"==typeof t[o]){if(e[t[o]])continue;n.push(t[o]),e[t[o]]=!0}else if(t[o]instanceof l){if(r[t[o].toString()])continue;n.push(t[o]),r[t[o].toString()]=!0}else n.push(t[o]);return n},r.buffer={},r.buffer.areEqual=function(t,e){if(!n.isBuffer(t))return!1;if(!n.isBuffer(e))return!1;if(t.length!==e.length)return!1;for(var r=0,i=t.length;i>r;++r)if(t[r]!==e[r])return!1;return!0},r.getFunctionName=function(t){return t.name?t.name:(t.toString().trim().match(/^function\s*([^\s(]+)/)||[])[1]},r.decorate=function(t,e){for(var r in e)t[r]=e[r]},r.mergeClone=function(t,e){for(var n,i=Object.keys(e),o=i.length;o--;)if(n=i[o],"undefined"==typeof t[n])t[n]=r.clone(e[n],{retainKeyOrder:1});else if(r.isObject(e[n])){var s=e[n];b(e[n])&&!e[n].isMongooseBuffer&&(s=s.toObject({virtuals:!1})),r.mergeClone(t[n],s)}else t[n]=r.clone(e[n],{retainKeyOrder:1})},r.each=function(t,e){for(var r=0;r=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},e.exports=n},{}],50:[function(t,e,r){function n(t,e){return p.isUndefined(e)?""+e:!p.isNumber(e)||!isNaN(e)&&isFinite(e)?p.isFunction(e)||p.isRegExp(e)?e.toString():e:e.toString()}function i(t,e){return p.isString(t)?t.length=0;n--)if(i[n]!=o[n])return!1;for(n=i.length-1;n>=0;n--)if(r=i[n],!u(t[r],e[r]))return!1;return!0}function l(t,e){return t&&e?"[object RegExp]"==Object.prototype.toString.call(e)?e.test(t):t instanceof e?!0:e.call({},t)===!0?!0:!1:!1}function h(t,e,r,n){var i;p.isString(r)&&(n=r,r=null);try{e()}catch(t){i=t}if(n=(r&&r.name?" ("+r.name+").":".")+(n?" "+n:"."),t&&!i&&s(i,r,"Missing expected exception"+n),!t&&l(i,r)&&s(i,r,"Got unwanted exception"+n),t&&i&&r&&!l(i,r)||!t&&i)throw i}var p=t("util/"),d=Array.prototype.slice,_=Object.prototype.hasOwnProperty,y=e.exports=a;y.AssertionError=function(t){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=o(this),this.generatedMessage=!0);var e=t.stackStartFunction||s;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var r=new Error;if(r.stack){var n=r.stack,i=e.name,a=n.indexOf("\n"+i);if(a>=0){var u=n.indexOf("\n",a+1);n=n.substring(u+1)}this.stack=n}}},p.inherits(y.AssertionError,Error),y.fail=s,y.ok=a,y.equal=function(t,e,r){t!=e&&s(t,e,r,"==",y.equal)},y.notEqual=function(t,e,r){t==e&&s(t,e,r,"!=",y.notEqual)},y.deepEqual=function(t,e,r){u(t,e)||s(t,e,r,"deepEqual",y.deepEqual)},y.notDeepEqual=function(t,e,r){u(t,e)&&s(t,e,r,"notDeepEqual",y.notDeepEqual)},y.strictEqual=function(t,e,r){t!==e&&s(t,e,r,"===",y.strictEqual)},y.notStrictEqual=function(t,e,r){t===e&&s(t,e,r,"!==",y.notStrictEqual)},y.throws=function(t,e,r){
+h.apply(this,[!0].concat(d.call(arguments)))},y.doesNotThrow=function(t,e){h.apply(this,[!1].concat(d.call(arguments)))},y.ifError=function(t){if(t)throw t};var g=Object.keys||function(t){var e=[];for(var r in t)_.call(t,r)&&e.push(r);return e}},{"util/":98}],51:[function(t,e,r){(function(t,r){!function(){function n(){}function i(t){return t}function o(t){return!!t}function s(t){return!t}function a(t){return function(){if(null===t)throw new Error("Callback was already called.");t.apply(this,arguments),t=null}}function u(t){return function(){null!==t&&(t.apply(this,arguments),t=null)}}function c(t){return L(t)||"number"==typeof t.length&&t.length>=0&&t.length%1===0}function f(t,e){for(var r=-1,n=t.length;++rn?n:null}):(r=U(t),e=r.length,function(){return n++,e>n?r[n]:null})}function g(t,e){return e=null==e?t.length-1:+e,function(){for(var r=Math.max(arguments.length-e,0),n=Array(r),i=0;r>i;i++)n[i]=arguments[i+e];switch(e){case 0:return t.call(this,n);case 1:return t.call(this,arguments[0],n)}}}function v(t){return function(e,r,n){return t(e,n)}}function m(t){return function(e,r,i){i=u(i||n),e=e||[];var o=y(e);if(0>=t)return i(null);var s=!1,c=0,f=!1;!function n(){if(s&&0>=c)return i(null);for(;t>c&&!f;){var u=o();if(null===u)return s=!0,void(0>=c&&i(null));c+=1,r(e[u],u,a(function(t){c-=1,t?(i(t),f=!0):n()}))}}()}}function b(t){return function(e,r,n){return t(R.eachOf,e,r,n)}}function w(t){return function(e,r,n,i){return t(m(r),e,n,i)}}function E(t){return function(e,r,n){return t(R.eachOfSeries,e,r,n)}}function O(t,e,r,i){i=u(i||n),e=e||[];var o=c(e)?[]:{};t(e,function(t,e,n){r(t,function(t,r){o[e]=r,n(t)})},function(t){i(t,o)})}function A(t,e,r,n){var i=[];t(e,function(t,e,n){r(t,function(r){r&&i.push({index:e,value:t}),n()})},function(){n(l(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})}function S(t,e,r,n){A(t,e,function(t,e){r(t,function(t){e(!t)})},n)}function j(t,e,r){return function(n,i,o,s){function a(){s&&s(r(!1,void 0))}function u(t,n,i){return s?void o(t,function(n){s&&e(n)&&(s(r(!0,t)),s=o=!1),i()}):i()}arguments.length>3?t(n,i,u,a):(s=o,o=i,t(n,u,a))}}function N(t,e){return e}function x(t,e,r){r=r||n;var i=c(e)?[]:{};t(e,function(t,e,r){t(g(function(t,n){n.length<=1&&(n=n[0]),i[e]=n,r(t)}))},function(t){r(t,i)})}function B(t,e,r,n){var i=[];t(e,function(t,e,n){r(t,function(t,e){i=i.concat(e||[]),n(t)})},function(t){n(t,i)})}function T(t,e,r){function i(t,e,r,i){if(null!=i&&"function"!=typeof i)throw new Error("task callback must be a function");return t.started=!0,L(e)||(e=[e]),0===e.length&&t.idle()?R.setImmediate(function(){t.drain()}):(f(e,function(e){var o={data:e,callback:i||n};r?t.tasks.unshift(o):t.tasks.push(o),t.tasks.length===t.concurrency&&t.saturated()}),void R.setImmediate(t.process))}function o(t,e){return function(){s-=1;var r=!1,n=arguments;f(e,function(t){f(u,function(e,n){e!==t||r||(u.splice(n,1),r=!0)}),t.callback.apply(t,n)}),t.tasks.length+s===0&&t.drain(),t.process()}}if(null==e)e=1;else if(0===e)throw new Error("Concurrency must not be zero");var s=0,u=[],c={tasks:[],concurrency:e,payload:r,saturated:n,empty:n,drain:n,started:!1,paused:!1,push:function(t,e){i(c,t,!1,e)},kill:function(){c.drain=n,c.tasks=[]},unshift:function(t,e){i(c,t,!0,e)},process:function(){for(;!c.paused&&s=e;e++)R.setImmediate(c.process)}}};return c}function k(t){return g(function(e,r){e.apply(null,r.concat([g(function(e,r){"object"==typeof console&&(e?console.error&&console.error(e):console[t]&&f(r,function(e){console[t](e)}))})]))})}function $(t){return function(e,r,n){t(h(e),r,n)}}function I(t){return g(function(e,r){var n=g(function(r){var n=this,i=r.pop();return t(e,function(t,e,i){t.apply(n,r.concat([i]))},i)});return r.length?n.apply(this,r):n})}function D(t){return g(function(e){var r=e.pop();e.push(function(){var t=arguments;n?R.setImmediate(function(){r.apply(null,t)}):r.apply(null,t)});var n=!0;t.apply(this,e),n=!1})}var P,R={},C="object"==typeof self&&self.self===self&&self||"object"==typeof r&&r.global===r&&r||this;null!=C&&(P=C.async),R.noConflict=function(){return C.async=P,R};var M=Object.prototype.toString,L=Array.isArray||function(t){return"[object Array]"===M.call(t)},F=function(t){var e=typeof t;return"function"===e||"object"===e&&!!t},U=Object.keys||function(t){var e=[];for(var r in t)t.hasOwnProperty(r)&&e.push(r);return e},V="function"==typeof setImmediate&&setImmediate,q=V?function(t){V(t)}:function(t){setTimeout(t,0)};"object"==typeof t&&"function"==typeof t.nextTick?R.nextTick=t.nextTick:R.nextTick=q,R.setImmediate=V?q:R.nextTick,R.forEach=R.each=function(t,e,r){return R.eachOf(t,v(e),r)},R.forEachSeries=R.eachSeries=function(t,e,r){return R.eachOfSeries(t,v(e),r)},R.forEachLimit=R.eachLimit=function(t,e,r,n){return m(e)(t,v(r),n)},R.forEachOf=R.eachOf=function(t,e,r){function i(t){c--,t?r(t):null===o&&0>=c&&r(null)}r=u(r||n),t=t||[];for(var o,s=y(t),c=0;null!=(o=s());)c+=1,e(t[o],o,a(i));0===c&&r(null)},R.forEachOfSeries=R.eachOfSeries=function(t,e,r){function i(){var n=!0;return null===s?r(null):(e(t[s],s,a(function(t){if(t)r(t);else{if(s=o(),null===s)return r(null);n?R.setImmediate(i):i()}})),void(n=!1))}r=u(r||n),t=t||[];var o=y(t),s=o();i()},R.forEachOfLimit=R.eachOfLimit=function(t,e,r,n){m(e)(t,r,n)},R.map=b(O),R.mapSeries=E(O),R.mapLimit=w(O),R.inject=R.foldl=R.reduce=function(t,e,r,n){R.eachOfSeries(t,function(t,n,i){r(e,t,function(t,r){e=r,i(t)})},function(t){n(t,e)})},R.foldr=R.reduceRight=function(t,e,r,n){var o=l(t,i).reverse();R.reduce(o,e,r,n)},R.transform=function(t,e,r,n){3===arguments.length&&(n=r,r=e,e=L(t)?[]:{}),R.eachOf(t,function(t,n,i){r(e,t,n,i)},function(t){n(t,e)})},R.select=R.filter=b(A),R.selectLimit=R.filterLimit=w(A),R.selectSeries=R.filterSeries=E(A),R.reject=b(S),R.rejectLimit=w(S),R.rejectSeries=E(S),R.any=R.some=j(R.eachOf,o,i),R.someLimit=j(R.eachOfLimit,o,i),R.all=R.every=j(R.eachOf,s,s),R.everyLimit=j(R.eachOfLimit,s,s),R.detect=j(R.eachOf,i,N),R.detectSeries=j(R.eachOfSeries,i,N),R.detectLimit=j(R.eachOfLimit,i,N),R.sortBy=function(t,e,r){function n(t,e){var r=t.criteria,n=e.criteria;return n>r?-1:r>n?1:0}R.map(t,function(t,r){e(t,function(e,n){e?r(e):r(null,{value:t,criteria:n})})},function(t,e){return t?r(t):void r(null,l(e.sort(n),function(t){return t.value}))})},R.auto=function(t,e,r){function i(t){v.unshift(t)}function o(t){var e=_(v,t);e>=0&&v.splice(e,1)}function s(){c--,f(v.slice(0),function(t){t()})}"function"==typeof arguments[1]&&(r=e,e=null),r=u(r||n);var a=U(t),c=a.length;if(!c)return r(null);e||(e=c);var l={},h=0,y=!1,v=[];i(function(){c||r(null,l)}),f(a,function(n){function a(){return e>h&&p(m,function(t,e){return t&&l.hasOwnProperty(e)},!0)&&!l.hasOwnProperty(n)}function u(){a()&&(h++,o(u),f[f.length-1](v,l))}if(!y){for(var c,f=L(t[n])?t[n]:[t[n]],v=g(function(t,e){if(h--,e.length<=1&&(e=e[0]),t){var i={};d(l,function(t,e){i[e]=t}),i[n]=e,y=!0,r(t,i)}else l[n]=e,R.setImmediate(s)}),m=f.slice(0,f.length-1),b=m.length;b--;){if(!(c=t[m[b]]))throw new Error("Has nonexistent dependency in "+m.join(", "));if(L(c)&&_(c,n)>=0)throw new Error("Has cyclic dependencies")}a()?(h++,f[f.length-1](v,l)):i(u)}})},R.retry=function(t,e,r){function n(t,e){if("number"==typeof e)t.times=parseInt(e,10)||o;else{if("object"!=typeof e)throw new Error("Unsupported argument type for 'times': "+typeof e);t.times=parseInt(e.times,10)||o,t.interval=parseInt(e.interval,10)||s}}function i(t,e){function r(t,r){return function(n){t(function(t,e){n(!t||r,{err:t,result:e})},e)}}function n(t){return function(e){setTimeout(function(){e(null)},t)}}for(;u.times;){var i=!(u.times-=1);a.push(r(u.task,i)),!i&&u.interval>0&&a.push(n(u.interval))}R.series(a,function(e,r){r=r[r.length-1],(t||u.callback)(r.err,r.result)})}var o=5,s=0,a=[],u={times:o,interval:s},c=arguments.length;if(1>c||c>3)throw new Error("Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)");return 2>=c&&"function"==typeof t&&(r=e,e=t),"function"!=typeof t&&n(u,t),u.callback=r,u.task=e,u.callback?i():i},R.waterfall=function(t,e){function r(t){return g(function(n,i){if(n)e.apply(null,[n].concat(i));else{var o=t.next();o?i.push(r(o)):i.push(e),D(t).apply(null,i)}})}if(e=u(e||n),!L(t)){var i=new Error("First argument to waterfall must be an array of functions");return e(i)}return t.length?void r(R.iterator(t))():e()},R.parallel=function(t,e){x(R.eachOf,t,e)},R.parallelLimit=function(t,e,r){x(m(e),t,r)},R.series=function(t,e){x(R.eachOfSeries,t,e)},R.iterator=function(t){function e(r){function n(){return t.length&&t[r].apply(null,arguments),n.next()}return n.next=function(){return rn;){var o=n+(i-n+1>>>1);r(e,t[o])>=0?n=o:i=o-1}return n}function o(t,e,o,s){if(null!=s&&"function"!=typeof s)throw new Error("task callback must be a function");return t.started=!0,L(e)||(e=[e]),0===e.length?R.setImmediate(function(){t.drain()}):void f(e,function(e){var a={data:e,priority:o,callback:"function"==typeof s?s:n};t.tasks.splice(i(t.tasks,a,r)+1,0,a),t.tasks.length===t.concurrency&&t.saturated(),R.setImmediate(t.process)})}var s=R.queue(t,e);return s.push=function(t,e,r){o(s,t,e,r)},delete s.unshift,s},R.cargo=function(t,e){return T(t,1,e)},R.log=k("log"),R.dir=k("dir"),R.memoize=function(t,e){var r={},n={},o=Object.prototype.hasOwnProperty;e=e||i;var s=g(function(i){var s=i.pop(),a=e.apply(null,i);o.call(r,a)?R.setImmediate(function(){s.apply(null,r[a])}):o.call(n,a)?n[a].push(s):(n[a]=[s],t.apply(null,i.concat([g(function(t){r[a]=t;var e=n[a];delete n[a];for(var i=0,o=e.length;o>i;i++)e[i].apply(null,t)})])))});return s.memo=r,s.unmemoized=t,s},R.unmemoize=function(t){return function(){return(t.unmemoized||t).apply(null,arguments)}},R.times=$(R.map),R.timesSeries=$(R.mapSeries),R.timesLimit=function(t,e,r,n){return R.mapLimit(h(t),e,r,n)},R.seq=function(){var t=arguments;return g(function(e){var r=this,i=e[e.length-1];"function"==typeof i?e.pop():i=n,R.reduce(t,e,function(t,e,n){e.apply(r,t.concat([g(function(t,e){n(t,e)})]))},function(t,e){i.apply(r,[t].concat(e))})})},R.compose=function(){return R.seq.apply(null,Array.prototype.reverse.call(arguments))},R.applyEach=I(R.eachOf),R.applyEachSeries=I(R.eachOfSeries),R.forever=function(t,e){function r(t){return t?i(t):void o(r)}var i=a(e||n),o=D(t);r()},R.ensureAsync=D,R.constant=g(function(t){var e=[null].concat(t);return function(t){return t.apply(this,e)}}),R.wrapSync=R.asyncify=function(t){return g(function(e){var r,n=e.pop();try{r=t.apply(this,e)}catch(t){return n(t)}F(r)&&"function"==typeof r.then?r.then(function(t){n(null,t)}).catch(function(t){n(t.message?t:new Error(t))}):n(null,r)})},"object"==typeof e&&e.exports?e.exports=R:"function"==typeof define&&define.amd?define([],function(){return R}):C.async=R}()}).call(this,t("g5I+bs"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"g5I+bs":94}],52:[function(t,e,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";function e(t){var e=t.charCodeAt(0);return e===s?62:e===a?63:u>e?-1:u+10>e?e-u+26+26:f+26>e?e-f:c+26>e?e-c+26:void 0}function r(t){function r(t){c[l++]=t}var n,i,s,a,u,c;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var f=t.length;u="="===t.charAt(f-2)?2:"="===t.charAt(f-1)?1:0,c=new o(3*t.length/4-u),s=u>0?t.length-4:t.length;var l=0;for(n=0,i=0;s>n;n+=4,i+=3)a=e(t.charAt(n))<<18|e(t.charAt(n+1))<<12|e(t.charAt(n+2))<<6|e(t.charAt(n+3)),r((16711680&a)>>16),r((65280&a)>>8),r(255&a);return 2===u?(a=e(t.charAt(n))<<2|e(t.charAt(n+1))>>4,r(255&a)):1===u&&(a=e(t.charAt(n))<<10|e(t.charAt(n+1))<<4|e(t.charAt(n+2))>>2,r(a>>8&255),r(255&a)),c}function i(t){function e(t){return n.charAt(t)}function r(t){return e(t>>18&63)+e(t>>12&63)+e(t>>6&63)+e(63&t)}var i,o,s,a=t.length%3,u="";for(i=0,s=t.length-a;s>i;i+=3)o=(t[i]<<16)+(t[i+1]<<8)+t[i+2],u+=r(o);switch(a){case 1:o=t[t.length-1],u+=e(o>>2),u+=e(o<<4&63),u+="==";break;case 2:o=(t[t.length-2]<<8)+t[t.length-1],u+=e(o>>10),u+=e(o>>4&63),u+=e(o<<2&63),u+="="}return u}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="+".charCodeAt(0),a="/".charCodeAt(0),u="0".charCodeAt(0),c="a".charCodeAt(0),f="A".charCodeAt(0);t.toByteArray=r,t.fromByteArray=i}("undefined"==typeof r?this.base64js={}:r)},{}],53:[function(t,e,r){(function(r){function n(t,e){if(!(this instanceof n))return new n(t,e);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 i?this.buffer=new i(n.BUFFER_SIZE):"undefined"!=typeof Uint8Array?this.buffer=new Uint8Array(new ArrayBuffer(n.BUFFER_SIZE)):this.buffer=new Array(n.BUFFER_SIZE),this.position=0;else{if("string"==typeof t)if("undefined"!=typeof i)this.buffer=new i(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}}if("undefined"!=typeof r)var i=t("buffer").Buffer;n.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&&0>t||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 i&&i.isBuffer(this.buffer)){var r=new i(n.BUFFER_SIZE+this.buffer.length);this.buffer.copy(r,0,0,this.buffer.length),this.buffer=r,this.buffer[this.position++]=e}else{var r=null;r="[object Uint8Array]"==Object.prototype.toString.call(this.buffer)?new Uint8Array(new ArrayBuffer(n.BUFFER_SIZE+this.buffer.length)):new Array(n.BUFFER_SIZE+this.buffer.length);for(var o=0;othis.position?e+t.length:this.position;else if("undefined"!=typeof i&&"string"==typeof t&&i.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(var n=0;nthis.position?e:this.position}else if("string"==typeof t){for(var n=0;nthis.position?e:this.position}},n.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;e>n;n++)r[n]=this.buffer[t++];return r},n.prototype.value=function(t){if(t=null==t?!1:t,t&&"undefined"!=typeof i&&i.isBuffer(this.buffer)&&this.buffer.length==this.position)return this.buffer;if("undefined"!=typeof i&&i.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;ri;i++)n+=String.fromCharCode(t[i]);return n};n.BUFFER_SIZE=256,n.SUBTYPE_DEFAULT=0,n.SUBTYPE_FUNCTION=1,n.SUBTYPE_BYTE_ARRAY=2,n.SUBTYPE_UUID_OLD=3,n.SUBTYPE_UUID=4,n.SUBTYPE_MD5=5,n.SUBTYPE_USER_DEFINED=128,e.exports=n,e.exports.Binary=n}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{buffer:71}],54:[function(t,e,n){(function(e){function i(t,e){return this instanceof i?(this.bigEndian=t,void(this.allowExceptions=e)):new i(t,e)}function o(t,e){this.bigEndian=t||0,this.buffer=[],this.setBuffer(e)}for(var s=String.fromCharCode,a=[],u=0;64>u;u++)a[u]=Math.pow(2,u);i.warn=function(t){if(this.allowExceptions)throw new Error(t);return 1},i.decodeFloat=function(t,e,r){var n=new this.Buffer(this.bigEndian,t);n.checkBuffer(e+r+1);var i=a[r-1]-1,o=n.readBits(e+r,1),s=n.readBits(e,r),u=0,c=2,f=n.buffer.length+(-e>>3)-1;do for(var l=n.buffer[++f],h=e%8||8,p=1<>=1;l&p&&(u+=1/c),c*=2);while(e-=h);return s==(i<<1)+1?u?NaN:o?-(1/0):+(1/0):(1+-2*o)*(s||u?s?Math.pow(2,s-i)*(1+u):Math.pow(2,-i+1)*u:0)},i.decodeInt=function(t,e,r,n){var i=new this.Buffer(this.bigEndian||n,t),o=i.readBits(0,e),s=a[e];return r&&o>=s/2?o-s:o},i.encodeFloat=function(t,e,n){var i,o,s,u,c,f=a[n-1]-1,l=-f+1,h=f,p=l-e,d=parseFloat(t),_=isNaN(d)||d==-(1/0)||d==+(1/0)?d:0,y=0,g=2*f+1+e+3,v=new Array(g),m=(d=0!==_?0:d)<0,b=Math.floor(d=Math.abs(d)),w=d-b;for(u=g;u;v[--u]=0);for(u=f+2;b&&u;v[--u]=b%2,b=Math.floor(b/2));for(u=f+1;w>0&&u;(v[++u]=((w*=2)>=1)-0)&&--w);for(u=-1;++u=l&&h>=y?u+1:f+1-(y=l-1)))+1]){if(!(o=v[i]))for(c=i+2;!o&&g>c;o=v[c++]);for(c=i+1;o&&--c>=0;(v[c]=!v[c]-0)&&(o=0));}for(u=0>u-2?-1:u-3;++u=l&&h>=y?++u:l>y&&(y!=f+1-g&&p>y&&this.warn("encodeFloat::float underflow"),u=f+1-(y=l-1)),(b||0!==_)&&(this.warn(b?"encodeFloat::float overflow":"encodeFloat::"+_),y=h+1,u=f+2,_==-(1/0)?m=1:isNaN(_)&&(v[u]=1)),d=Math.abs(y+f),c=n+1,s="";--c;s=d%2+s,d=d>>=1);for(d=0,c=0,u=(s=(m?"1":"0")+s+v.slice(u,u+e).join("")).length,r=[];u;c=(c+1)%8)d+=(1<=i||-(i/2)>t)&&(this.warn("encodeInt::overflow"),t=0),0>t&&(t+=i);for(var o=[];t;o[o.length]=String.fromCharCode(t%256),t=Math.floor(t/256));for(e=-(-e>>3)-o.length;e--;o[o.length]="\x00");return(this.bigEndian||n?o.reverse():o).join("")},i.toSmall=function(t){return this.decodeInt(t,8,!0)},i.fromSmall=function(t){return this.encodeInt(t,8,!0)},i.toByte=function(t){return this.decodeInt(t,8,!1)},i.fromByte=function(t){return this.encodeInt(t,8,!1)},i.toShort=function(t){return this.decodeInt(t,16,!0)},i.fromShort=function(t){return this.encodeInt(t,16,!0)},i.toWord=function(t){return this.decodeInt(t,16,!1)},i.fromWord=function(t){return this.encodeInt(t,16,!1)},i.toInt=function(t){return this.decodeInt(t,32,!0)},i.fromInt=function(t){return this.encodeInt(t,32,!0)},i.toLong=function(t){return this.decodeInt(t,64,!0)},i.fromLong=function(t){return this.encodeInt(t,64,!0)},i.toDWord=function(t){return this.decodeInt(t,32,!1)},i.fromDWord=function(t){return this.encodeInt(t,32,!1)},i.toQWord=function(t){return this.decodeInt(t,64,!0)},i.fromQWord=function(t){return this.encodeInt(t,64,!0)},i.toFloat=function(t){return this.decodeFloat(t,23,8)},i.fromFloat=function(t){return this.encodeFloat(t,23,8)},i.toDouble=function(t){return this.decodeFloat(t,52,11)},i.fromDouble=function(t){return this.encodeFloat(t,52,11)},i.encode_int32=function(t,e){var r,n,i,o,a;return a=0>t?t+4294967296:t,r=Math.floor(a/16777215),a&=16777215,n=Math.floor(a/65535),a&=65535,i=Math.floor(a/255),a&=255,o=Math.floor(a),e?[s(r),s(n),s(i),s(o)]:s(r)+s(n)+s(i)+s(o)},i.encode_int64=function(t){var e,r,n,i,o,a,u,c,f;return f=0>t?t+0x10000000000000000:t,e=Math.floor(f/72057594037927940),f&=72057594037927940,r=Math.floor(f/0xffffffffffff),f&=0xffffffffffff,n=Math.floor(f/0xffffffffff),f&=0xffffffffff,i=Math.floor(f/4294967295),f&=4294967295,o=Math.floor(f/16777215),f&=16777215,a=Math.floor(f/65535),f&=65535,u=Math.floor(f/255),f&=255,c=Math.floor(f),s(e)+s(r)+s(n)+s(i)+s(o)+s(a)+s(u)+s(c)},i.decode_utf8=function(t){for(var e,r=t.length,n="",i=0,o=0,s=0;r>i;)o=t.charCodeAt(i),128>o?(n+=String.fromCharCode(o),i++):o>191&&224>o?(s=t.charCodeAt(i+1),n+=String.fromCharCode((31&o)<<6|63&s),i+=2):(s=t.charCodeAt(i+1),e=t.charCodeAt(i+2),n+=String.fromCharCode((15&o)<<12|(63&s)<<6|63&e),i+=3);return n},i.encode_cstring=function(t){return unescape(encodeURIComponent(t))+i.fromByte(0)},i.encode_utf8=function(t){for(var e,r="",n=0,i=t.length;i>n;n++)e=t.charCodeAt(n),128>e?r+=String.fromCharCode(e):e>127&&2048>e?(r+=String.fromCharCode(e>>6|192),r+=String.fromCharCode(63&e|128)):(r+=String.fromCharCode(e>>12|224),r+=String.fromCharCode(e>>6&63|128),r+=String.fromCharCode(63&e|128));return r},i.hprint=function(t){for(var r,n=0,i=t.length;i>n;n++)t.charCodeAt(n)<32?(r=t.charCodeAt(n)<=15?"0"+t.charCodeAt(n).toString(16):t.charCodeAt(n).toString(16),e.stdout.write(r+" ")):(r=t.charCodeAt(n)<=15?"0"+t.charCodeAt(n).toString(16):t.charCodeAt(n).toString(16),e.stdout.write(r+" "));e.stdout.write("\n\n")},i.ilprint=function(e){for(var r,n=0,i=e.length;i>n;n++)e.charCodeAt(n)<32?(r=e.charCodeAt(n)<=15?"0"+e.charCodeAt(n).toString(10):e.charCodeAt(n).toString(10),t("util").debug(r+" : ")):(r=e.charCodeAt(n)<=15?"0"+e.charCodeAt(n).toString(10):e.charCodeAt(n).toString(10),t("util").debug(r+" : "+e.charAt(n)))},i.hlprint=function(e){for(var r,n=0,i=e.length;i>n;n++)e.charCodeAt(n)<32?(r=e.charCodeAt(n)<=15?"0"+e.charCodeAt(n).toString(16):e.charCodeAt(n).toString(16),t("util").debug(r+" : ")):(r=e.charCodeAt(n)<=15?"0"+e.charCodeAt(n).toString(16):e.charCodeAt(n).toString(16),t("util").debug(r+" : "+e.charAt(n)))},o.prototype.setBuffer=function(t){var e,r,n;if(t){for(r=e=t.length,n=this.buffer=new Array(e);r;n[e-r]=t.charCodeAt(--r));this.bigEndian&&n.reverse()}},o.prototype.hasNeededBits=function(t){return this.buffer.length>=-(-t>>3)},o.prototype.checkBuffer=function(t){if(!this.hasNeededBits(t))throw new Error("checkBuffer::missing bytes")},o.prototype.readBits=function(t,e){function r(t,e){for(;e--;t=1073741824==(1073741824&(t%=2147483648))?2*t:2*(t-1073741824)+2147483647+1);return t}if(0>t||0>=e)return 0;this.checkBuffer(t+e);for(var n,i=t%8,o=this.buffer.length-(t>>3)-1,s=this.buffer.length+(-(t+e)>>3),a=o-s,u=(this.buffer[o]>>i&(1<<(a?8-i:e))-1)+(a&&(n=(t+e)%8)?(this.buffer[s++]&(1<a;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},b.BSON_INT32_MAX=2147483647,b.BSON_INT32_MIN=-2147483648,b.BSON_INT64_MAX=Math.pow(2,63)-1,b.BSON_INT64_MIN=-Math.pow(2,63),b.JS_INT_MAX=9007199254740992,b.JS_INT_MIN=-9007199254740992;i.fromNumber(9007199254740992),i.fromNumber(-9007199254740992);b.BSON_DATA_NUMBER=1,b.BSON_DATA_STRING=2,b.BSON_DATA_OBJECT=3,b.BSON_DATA_ARRAY=4,b.BSON_DATA_BINARY=5,b.BSON_DATA_OID=7,b.BSON_DATA_BOOLEAN=8,b.BSON_DATA_DATE=9,b.BSON_DATA_NULL=10,b.BSON_DATA_REGEXP=11,b.BSON_DATA_CODE=13,b.BSON_DATA_SYMBOL=14,b.BSON_DATA_CODE_W_SCOPE=15,b.BSON_DATA_INT=16,b.BSON_DATA_TIMESTAMP=17,b.BSON_DATA_LONG=18,b.BSON_DATA_MIN_KEY=255,b.BSON_DATA_MAX_KEY=127,b.BSON_BINARY_SUBTYPE_DEFAULT=0,b.BSON_BINARY_SUBTYPE_FUNCTION=1,b.BSON_BINARY_SUBTYPE_BYTE_ARRAY=2,b.BSON_BINARY_SUBTYPE_UUID=3,b.BSON_BINARY_SUBTYPE_MD5=4,b.BSON_BINARY_SUBTYPE_USER_DEFINED=128,e.exports=b,e.exports.Code=f,e.exports.Map=n,e.exports.Symbol=c,e.exports.BSON=b,e.exports.DBRef=p,e.exports.Binary=d,e.exports.ObjectID=a,e.exports.Long=i,e.exports.Timestamp=s,e.exports.Double=o,e.exports.MinKey=l,e.exports.MaxKey=h,e.exports.BSONRegExp=u}).call(this,t("buffer").Buffer)},{"./binary":53,"./code":56,"./db_ref":57,"./double":58,"./float_parser":59,"./long":60,"./map":61,"./max_key":62,"./min_key":63,"./objectid":64,"./parser/calculate_size":65,"./parser/deserializer":66,"./parser/serializer":67,"./regexp":68,"./symbol":69,"./timestamp":70,buffer:71}],56:[function(t,e,r){var n=function t(e,r){return this instanceof t?(this._bsontype="Code",this.code=e,void(this.scope=null==r?{}:r)):new t(e,r)};n.prototype.toJSON=function(){return{scope:this.scope,code:this.code}},e.exports=n,e.exports.Code=n},{}],57:[function(t,e,r){function n(t,e,r){return this instanceof n?(this._bsontype="DBRef",this.namespace=t,this.oid=e,void(this.db=r)):new n(t,e,r)}n.prototype.toJSON=function(){return{$ref:this.namespace,$id:this.oid,$db:null==this.db?"":this.db}},e.exports=n,e.exports.DBRef=n},{}],58:[function(t,e,r){function n(t){return this instanceof n?(this._bsontype="Double",void(this.value=t)):new n(t)}n.prototype.valueOf=function(){return this.value},n.prototype.toJSON=function(){return this.value},e.exports=n,e.exports.Double=n},{}],59:[function(t,e,r){var n=function(t,e,r,n,i){var o,s,a="big"===r,u=8*i-n-1,c=(1<>1,l=-7,h=a?0:i-1,p=a?1:-1,d=t[e+h];for(h+=p,o=d&(1<<-l)-1,d>>=-l,l+=u;l>0;o=256*o+t[e+h],h+=p,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=256*s+t[e+h],h+=p,l-=8);if(0===o)o=1-f;else{if(o===c)return s?NaN:(d?-1:1)*(1/0);s+=Math.pow(2,n),o-=f}return(d?-1:1)*s*Math.pow(2,o-n)},i=function(t,e,r,n,i,o){var s,a,u,c="big"===n,f=8*o-i-1,l=(1<>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=c?o-1:0,_=c?-1:1,y=0>e||0===e&&0>1/e?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+h>=1?p/u:p*Math.pow(2,1-h),e*u>=2&&(s++,u/=2),s+h>=l?(a=0,s=l):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+=_,a/=256,i-=8);for(s=s<0;t[r+d]=255&s,d+=_,s/=256,f-=8);t[r+d-_]|=128*y};r.readIEEE754=n,r.writeIEEE754=i},{}],60:[function(t,e,r){function n(t,e){return this instanceof n?(this._bsontype="Long",this.low_=0|t,void(this.high_=0|e)):new n(t,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(2>e||e>36)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)}for(var s=n.fromNumber(Math.pow(e,6)),o=this,a="";;){var u=o.div(s),c=o.subtract(u.multiply(s)).toInt(),f=c.toString(e);if(o=u,o.isZero())return f+a;for(;f.length<6;)f="0"+f;a=""+f+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<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=65535&t.low_,f=0,l=0,h=0,p=0;return p+=o+c,h+=p>>>16,p&=65535,h+=i+u,l+=h>>>16,h&=65535,l+=r+a,f+=l>>>16,l&=65535,f+=e+s,f&=65535,n.fromBits(h<<16|p,f<<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_,f=0,l=0,h=0,p=0;return p+=o*c,h+=p>>>16,p&=65535,h+=i*c,l+=h>>>16,h&=65535,h+=o*u,l+=h>>>16,h&=65535,l+=r*c,f+=l>>>16,l&=65535,l+=i*u,f+=l>>>16,l&=65535,l+=o*a,f+=l>>>16,l&=65535,f+=e*c+r*u+i*a+o*s,f&=65535,n.fromBits(h<<16|p,f<<16|l)},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),r=e.div(t).shiftLeft(1);if(r.equals(n.ZERO))return t.isNegative()?n.ONE:n.NEG_ONE;var i=this.subtract(t.multiply(r)),o=r.add(i.div(t));return o}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();for(var s=n.ZERO,i=this;i.greaterThanOrEqual(t);){for(var r=Math.max(1,Math.floor(i.toNumber()/t.toNumber())),a=Math.ceil(Math.log(r)/Math.LN2),u=48>=a?1:Math.pow(2,a-48),c=n.fromNumber(r),f=c.multiply(t);f.isNegative()||f.greaterThan(i);)r-=u,c=n.fromNumber(r),f=c.multiply(t);c.isZero()&&(c=n.ONE),s=s.add(c),i=i.subtract(f)}return s},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(t&=63,0==t)return this;var e=this.low_;if(32>t){var r=this.high_;return n.fromBits(e<>>32-t)}return n.fromBits(0,e<t){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(t&=63,0==t)return this;var e=this.high_;if(32>t){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(t>=-128&&128>t){var e=n.INT_CACHE_[t];if(e)return e}var r=new n(0|t,0>t?-1:0);return t>=-128&&128>t&&(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:0>t?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(2>r||r>36)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;sa){var c=n.fromNumber(Math.pow(r,a));o=o.multiply(c).add(n.fromNumber(u))}else o=o.multiply(i),o=o.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),e.exports=n,e.exports.Long=n},{}],61:[function(t,e,r){(function(t){"use strict";if("undefined"!=typeof t.Map)e.exports=t.Map,e.exports.Map=t.Map;else{var r=function(t){this._keys=[],this._values={};for(var e=0;eu;u++)a[u]=(15>=u?"0":"")+u.toString(16);s.prototype.toHexString=function(){if(s.cacheHexString&&this.__id)return this.__id;for(var t="",e=0;e24)throw new Error("Id cannot be longer than 12 bytes");for(var r,i,o="",a=0;e>a;a+=2)r=t.substr(a,2),i=parseInt(r,16),o+=n.fromByte(i);return new s(o,t)},s.isValid=function(t){return null==t?!1:"number"==typeof t?!0:"string"==typeof t?12==t.length||24==t.length&&o.test(t):t instanceof s?!0:t.toHexString?12==t.id.length||24==t.id.length&&o.test(t.id):!1},Object.defineProperty(s.prototype,"generationTime",{enumerable:!0,get:function(){return Math.floor(n.decodeInt(this.id.substring(0,4),32,!0,!0))},set:function(t){var t=n.encodeInt(t,32,!0,!0);this.id=t+this.id.substr(4),this.toHexString()}}),e.exports=s,e.exports.ObjectID=s,e.exports.ObjectId=s}).call(this,t("g5I+bs"))},{"./binary_parser":54,"g5I+bs":94}],65:[function(t,e,r){(function(r){"use strict";function n(t,e,n,v,m){switch(e&&e.toBSON&&(e=e.toBSON()),typeof e){case"string":return 1+r.byteLength(t,"utf8")+1+4+r.byteLength(e,"utf8")+1;case"number":return Math.floor(e)===e&&e>=g.JS_INT_MIN&&e<=g.JS_INT_MAX&&e>=g.BSON_INT32_MIN&&e<=g.BSON_INT32_MAX?(null!=t?r.byteLength(t,"utf8")+1:0)+5:(null!=t?r.byteLength(t,"utf8")+1:0)+9;case"undefined":return v||!m?(null!=t?r.byteLength(t,"utf8")+1:0)+1:0;case"boolean":return(null!=t?r.byteLength(t,"utf8")+1:0)+2;case"object":if(null==e||e instanceof l||e instanceof h||"MinKey"==e._bsontype||"MaxKey"==e._bsontype)return(null!=t?r.byteLength(t,"utf8")+1:0)+1;if(e instanceof a||"ObjectID"==e._bsontype)return(null!=t?r.byteLength(t,"utf8")+1:0)+13;if(e instanceof Date||_(e))return(null!=t?r.byteLength(t,"utf8")+1:0)+9;if("undefined"!=typeof r&&r.isBuffer(e))return(null!=t?r.byteLength(t,"utf8")+1:0)+6+e.length;if(e instanceof i||e instanceof o||e instanceof s||"Long"==e._bsontype||"Double"==e._bsontype||"Timestamp"==e._bsontype)return(null!=t?r.byteLength(t,"utf8")+1:0)+9;if(e instanceof f||"Code"==e._bsontype)return null!=e.scope&&Object.keys(e.scope).length>0?(null!=t?r.byteLength(t,"utf8")+1:0)+1+4+4+r.byteLength(e.code.toString(),"utf8")+1+y(e.scope,n,m):(null!=t?r.byteLength(t,"utf8")+1:0)+1+4+r.byteLength(e.code.toString(),"utf8")+1;if(e instanceof d||"Binary"==e._bsontype)return e.sub_type==d.SUBTYPE_BYTE_ARRAY?(null!=t?r.byteLength(t,"utf8")+1:0)+(e.position+1+4+1+4):(null!=t?r.byteLength(t,"utf8")+1:0)+(e.position+1+4+1);if(e instanceof u||"Symbol"==e._bsontype)return(null!=t?r.byteLength(t,"utf8")+1:0)+r.byteLength(e.value,"utf8")+4+1+1;if(e instanceof p||"DBRef"==e._bsontype){var b={$ref:e.namespace,$id:e.oid};return null!=e.db&&(b.$db=e.db),(null!=t?r.byteLength(t,"utf8")+1:0)+1+y(b,n,m)}return e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)?(null!=t?r.byteLength(t,"utf8")+1:0)+1+r.byteLength(e.source,"utf8")+1+(e.global?1:0)+(e.ignoreCase?1:0)+(e.multiline?1:0)+1:e instanceof c||"BSONRegExp"==e._bsontype?(null!=t?r.byteLength(t,"utf8")+1:0)+1+r.byteLength(e.pattern,"utf8")+1+r.byteLength(e.options,"utf8")+1:(null!=t?r.byteLength(t,"utf8")+1:0)+y(e,n,m)+1;case"function":if(e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)||"[object RegExp]"==String.call(e))return(null!=t?r.byteLength(t,"utf8")+1:0)+1+r.byteLength(e.source,"utf8")+1+(e.global?1:0)+(e.ignoreCase?1:0)+(e.multiline?1:0)+1;if(n&&null!=e.scope&&Object.keys(e.scope).length>0)return(null!=t?r.byteLength(t,"utf8")+1:0)+1+4+4+r.byteLength(e.toString(),"utf8")+1+y(e.scope,n,m);if(n)return(null!=t?r.byteLength(t,"utf8")+1:0)+1+4+r.byteLength(e.toString(),"utf8")+1}return 0}var i=(t("../float_parser").writeIEEE754,t("../float_parser").readIEEE754,t("../long").Long),o=t("../double").Double,s=t("../timestamp").Timestamp,a=t("../objectid").ObjectID,u=t("../symbol").Symbol,c=t("../regexp").BSONRegExp,f=t("../code").Code,l=t("../min_key").MinKey,h=t("../max_key").MaxKey,p=t("../db_ref").DBRef,d=t("../binary").Binary,_=function(t){return"object"==typeof t&&"[object Date]"===Object.prototype.toString.call(t)},y=function(t,e,r){var i=5;if(Array.isArray(t))for(var o=0;oi||t.lengthh||h>t.length)throw new Error("corrupt bson message");for(var p=n?[]:{};;){var d=t[e++];if(0==d)break;for(var _=e;0!==t[_]&&_=t.length)throw new Error("Bad BSON Document: illegal CString");var y=t.toString("utf8",e,_);if(e=_+1,d==BSON.BSON_DATA_STRING){var g=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24;if(0>=g||g>t.length-e||0!=t[e+g-1])throw new Error("bad string length in bson");p[y]=t.toString("utf8",e,e+g-1),e+=g}else if(d==BSON.BSON_DATA_OID){var v=t.toString("binary",e,e+12);p[y]=new ObjectID(v),e+=12}else if(d==BSON.BSON_DATA_INT)p[y]=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24;else if(d==BSON.BSON_DATA_NUMBER)p[y]=t.readDoubleLE(e),e+=8;else if(d==BSON.BSON_DATA_DATE){var m=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24,b=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24;p[y]=new Date(new Long(m,b).toNumber())}else if(d==BSON.BSON_DATA_BOOLEAN)p[y]=1==t[e++];else if(d==BSON.BSON_DATA_OBJECT){var w=e,E=t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24;if(0>=E||E>t.length-e)throw new Error("bad embedded document length in bson");c?p[y]=t.slice(e,e+E):p[y]=deserializeObject(t,w,r,!1),e+=E}else if(d==BSON.BSON_DATA_ARRAY){var w=e,E=t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24,O=r;if(u&&u[y]){O={};for(var A in r)O[A]=r[A];O.raw=!0}p[y]=deserializeObject(t,w,O,!0),e+=E}else if(d==BSON.BSON_DATA_UNDEFINED||d==BSON.BSON_DATA_NULL)p[y]=null;else if(d==BSON.BSON_DATA_LONG){var m=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24,b=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24,S=new Long(m,b);a?p[y]=S.lessThanOrEqual(JS_INT_MAX_LONG)&&S.greaterThanOrEqual(JS_INT_MIN_LONG)?S.toNumber():S:p[y]=S}else if(d==BSON.BSON_DATA_BINARY){var j=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24,N=t[e++];if(null!=t.slice)N==Binary.SUBTYPE_BYTE_ARRAY&&(j=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24),l?p[y]=t.slice(e,e+j):p[y]=new Binary(t.slice(e,e+j),N);else{var x="undefined"!=typeof Uint8Array?new Uint8Array(new ArrayBuffer(j)):new Array(j);N==Binary.SUBTYPE_BYTE_ARRAY&&(j=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24);for(var _=0;j>_;_++)x[_]=t[e+_];l?p[y]=x:p[y]=new Binary(x,N)}e+=j}else if(d==BSON.BSON_DATA_REGEXP&&0==f){for(var _=e;0!==t[_]&&_=t.length)throw new Error("Bad BSON Document: illegal CString");var B=t.toString("utf8",e,_);e=_+1;for(var _=e;0!==t[_]&&_=t.length)throw new Error("Bad BSON Document: illegal CString");var T=t.toString("utf8",e,_);e=_+1;for(var k=new Array(T.length),_=0;_=t.length)throw new Error("Bad BSON Document: illegal CString");var B=t.toString("utf8",e,_);e=_+1;for(var _=e;0!==t[_]&&_=t.length)throw new Error("Bad BSON Document: illegal CString");var T=t.toString("utf8",e,_);e=_+1,p[y]=new BSONRegExp(B,T)}else if(d==BSON.BSON_DATA_SYMBOL){var g=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24;if(0>=g||g>t.length-e||0!=t[e+g-1])throw new Error("bad string length in bson");p[y]=new Symbol(t.toString("utf8",e,e+g-1)),e+=g}else if(d==BSON.BSON_DATA_TIMESTAMP){var m=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24,b=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24;p[y]=new Timestamp(m,b)}else if(d==BSON.BSON_DATA_MIN_KEY)p[y]=new MinKey;else if(d==BSON.BSON_DATA_MAX_KEY)p[y]=new MaxKey;else if(d==BSON.BSON_DATA_CODE){var g=t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24;if(0>=g||g>t.length-e||0!=t[e+g-1])throw new Error("bad string length in bson");var $=t.toString("utf8",e,e+g-1);if(i){if(o){var I=s?crc32($):$;p[y]=isolateEvalWithHash(functionCache,I,$,p)}else p[y]=isolateEval($)}else p[y]=new Code($,{});e+=g}else if(d==BSON.BSON_DATA_CODE_W_SCOPE){var g=(t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24,t[e++]|t[e++]<<8|t[e++]<<16|t[e++]<<24);if(0>=g||g>t.length-e||0!=t[e+g-1])throw new Error("bad string length in bson");var $=t.toString("utf8",e,e+g-1);e+=g;var w=e,E=t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24,D=deserializeObject(t,w,r,!1);if(e+=E,i){if(o){var I=s?crc32($):$;p[y]=isolateEvalWithHash(functionCache,I,$,p)}else p[y]=isolateEval($);p[y].scope=D}else p[y]=new Code($,D)}}return null!=p.$id&&(p=new DBRef(p.$ref,p.$id,p.$db)),p},isolateEvalWithHash=function(functionCache,hash,functionString,object){var value=null;return null==functionCache[hash]&&(eval("value = "+functionString),functionCache[hash]=value),functionCache[hash].bind(object)},isolateEval=function(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=7,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_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_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},{"../binary":53,"../code":56,"../db_ref":57,"../double":58,"../float_parser":59,"../long":60,"../max_key":62,"../min_key":63,"../objectid":64,"../regexp":68,"../symbol":69,"../timestamp":70,util:98}],67:[function(t,e,r){(function(r){"use strict";var n=t("../float_parser").writeIEEE754,i=(t("../float_parser").readIEEE754,t("../long").Long),o=t("../map"),s=(t("../double").Double,t("../timestamp").Timestamp,t("../objectid").ObjectID,t("../symbol").Symbol,t("../code").Code,t("../regexp").BSONRegExp,t("../min_key").MinKey),a=(t("../max_key").MaxKey,t("../db_ref").DBRef,t("../binary").Binary),u=/\x00/,c=function(t){return"object"==typeof t&&"[object Date]"===Object.prototype.toString.call(t)},f=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},l=function(t,e,r,n){t[n++]=T.BSON_DATA_STRING;var i=t.write(e,n,"utf8");n=n+i+1,t[n-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},h=function(t,e,r,o){if(Math.floor(r)===r&&r>=T.JS_INT_MIN&&r<=T.JS_INT_MAX)if(r>=T.BSON_INT32_MIN&&r<=T.BSON_INT32_MAX){t[o++]=T.BSON_DATA_INT;var s=t.write(e,o,"utf8");o+=s,t[o++]=0,t[o++]=255&r,t[o++]=r>>8&255,t[o++]=r>>16&255,t[o++]=r>>24&255}else if(r>=T.JS_INT_MIN&&r<=T.JS_INT_MAX){t[o++]=T.BSON_DATA_NUMBER;var s=t.write(e,o,"utf8");o+=s,t[o++]=0,n(t,r,o,"little",52,8),o+=8}else{t[o++]=T.BSON_DATA_LONG;var s=t.write(e,o,"utf8");o+=s,t[o++]=0;var a=i.fromNumber(r),u=a.getLowBits(),c=a.getHighBits();t[o++]=255&u,t[o++]=u>>8&255,t[o++]=u>>16&255,t[o++]=u>>24&255,t[o++]=255&c,t[o++]=c>>8&255,t[o++]=c>>16&255,t[o++]=c>>24&255}else{t[o++]=T.BSON_DATA_NUMBER;var s=t.write(e,o,"utf8");o+=s,t[o++]=0,n(t,r,o,"little",52,8),o+=8}return o},p=function(t,e,r,n){t[n++]=T.BSON_DATA_NULL;var i=t.write(e,n,"utf8");return n+=i,t[n++]=0,n},d=function(t,e,r,n){t[n++]=T.BSON_DATA_BOOLEAN;var i=t.write(e,n,"utf8");return n+=i,t[n++]=0,t[n++]=r?1:0,n},_=function(t,e,r,n){t[n++]=T.BSON_DATA_DATE;var o=t.write(e,n,"utf8");n+=o,t[n++]=0;var s=i.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},y=function(t,e,r,n){t[n++]=T.BSON_DATA_REGEXP;var i=t.write(e,n,"utf8");if(n+=i,t[n++]=0,r.source&&null!=r.source.match(u))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){t[n++]=T.BSON_DATA_REGEXP;var i=t.write(e,n,"utf8");return n+=i,t[n++]=0,n+=t.write(r.pattern,n,"utf8"),t[n++]=0,n+=t.write(r.options,n,"utf8"),t[n++]=0,n},v=function(t,e,r,n){null===r?t[n++]=T.BSON_DATA_NULL:r instanceof s?t[n++]=T.BSON_DATA_MIN_KEY:t[n++]=T.BSON_DATA_MAX_KEY;var i=t.write(e,n,"utf8");return n+=i,t[n++]=0,n},m=function(t,e,r,n){t[n++]=T.BSON_DATA_OID;var i=t.write(e,n,"utf8");return n+=i,t[n++]=0,t.write(r.id,n,"binary"),n+12},b=function(t,e,r,n){t[n++]=T.BSON_DATA_BINARY;var i=t.write(e,n,"utf8");n+=i,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++]=T.BSON_BINARY_SUBTYPE_DEFAULT,r.copy(t,n,0,o),n+=o},w=function(t,e,r,n,i,o,s,a){t[n++]=Array.isArray(r)?T.BSON_DATA_ARRAY:T.BSON_DATA_OBJECT;var u=t.write(e,n,"utf8");n+=u,t[n++]=0;var c=B(t,r,i,n,o+1,s,a);return c},E=function(t,e,r,n){t[n++]="Long"==r._bsontype?T.BSON_DATA_LONG:T.BSON_DATA_TIMESTAMP;var i=t.write(e,n,"utf8");n+=i,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},O=function(t,e,r,i){t[i++]=T.BSON_DATA_NUMBER;var o=t.write(e,i,"utf8");return i+=o,t[i++]=0,n(t,r,i,"little",52,8),i+=8},A=function(t,e,r,n,i,o){t[n++]=T.BSON_DATA_CODE;var s=t.write(e,n,"utf8");n+=s,t[n++]=0;var a=r.toString(),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},S=function(t,e,r,n,i,o,s,a){if(null!=r.scope&&Object.keys(r.scope).length>0){t[n++]=T.BSON_DATA_CODE_W_SCOPE;var u=t.write(e,n,"utf8");n+=u,t[n++]=0;var c=n,f="string"==typeof r.code?r.code:r.code.toString();n+=4;var l=t.write(f,n+4,"utf8")+1;t[n]=255&l,t[n+1]=l>>8&255,t[n+2]=l>>16&255,t[n+3]=l>>24&255,t[n+4+l-1]=0,n=n+l+4;var h=B(t,r.scope,i,n,o+1,s,a);n=h-1;var p=h-c;t[c++]=255&p,t[c++]=p>>8&255,t[c++]=p>>16&255,t[c++]=p>>24&255,t[n++]=0}else{t[n++]=T.BSON_DATA_CODE;var u=t.write(e,n,"utf8");n+=u,t[n++]=0;var f=r.code.toString(),d=t.write(f,n+4,"utf8")+1;t[n]=255&d,t[n+1]=d>>8&255,t[n+2]=d>>16&255,t[n+3]=d>>24&255,n=n+4+d-1,t[n++]=0}return n},j=function(t,e,r,n){t[n++]=T.BSON_DATA_BINARY;var i=t.write(e,n,"utf8");n+=i,t[n++]=0;var o=r.value(!0),s=r.position;return 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==a.SUBTYPE_BYTE_ARRAY&&(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},N=function(t,e,r,n){t[n++]=T.BSON_DATA_SYMBOL;var i=t.write(e,n,"utf8");n+=i,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},x=function(t,e,r,n,i,o){t[n++]=T.BSON_DATA_OBJECT;var s=t.write(e,n,"utf8");n+=s,t[n++]=0;var a,u=n;a=null!=r.db?B(t,{$ref:r.namespace,$id:r.oid,$db:r.db},!1,n,i+1,o):B(t,{$ref:r.namespace,$id:r.oid},!1,n,i+1,o);var c=a-u;return t[u++]=255&c,t[u++]=c>>8&255,t[u++]=c>>16&255,t[u++]=c>>24&255,a},B=function(t,e,n,i,s,a,B){i=i||0;var T=i+4;if(Array.isArray(e))for(var k=0;k>8&255,t[i++]=M>>16&255,t[i++]=M>>24&255,T},T={};T.functionCache={};T.BSON_DATA_NUMBER=1,T.BSON_DATA_STRING=2,T.BSON_DATA_OBJECT=3,T.BSON_DATA_ARRAY=4,T.BSON_DATA_BINARY=5,T.BSON_DATA_OID=7,T.BSON_DATA_BOOLEAN=8,T.BSON_DATA_DATE=9,T.BSON_DATA_NULL=10,T.BSON_DATA_REGEXP=11,T.BSON_DATA_CODE=13,T.BSON_DATA_SYMBOL=14,T.BSON_DATA_CODE_W_SCOPE=15,T.BSON_DATA_INT=16,T.BSON_DATA_TIMESTAMP=17,T.BSON_DATA_LONG=18,T.BSON_DATA_MIN_KEY=255,T.BSON_DATA_MAX_KEY=127,T.BSON_BINARY_SUBTYPE_DEFAULT=0,T.BSON_BINARY_SUBTYPE_FUNCTION=1,T.BSON_BINARY_SUBTYPE_BYTE_ARRAY=2,T.BSON_BINARY_SUBTYPE_UUID=3,T.BSON_BINARY_SUBTYPE_MD5=4,T.BSON_BINARY_SUBTYPE_USER_DEFINED=128,T.BSON_INT32_MAX=2147483647,T.BSON_INT32_MIN=-2147483648,T.BSON_INT64_MAX=Math.pow(2,63)-1,T.BSON_INT64_MIN=-Math.pow(2,63),T.JS_INT_MAX=9007199254740992,T.JS_INT_MIN=-9007199254740992;i.fromNumber(9007199254740992),i.fromNumber(-9007199254740992);e.exports=B}).call(this,t("buffer").Buffer)},{"../binary":53,"../code":56,"../db_ref":57,"../double":58,"../float_parser":59,"../long":60,"../map":61,"../max_key":62,"../min_key":63,"../objectid":64,"../regexp":68,"../symbol":69,"../timestamp":70,buffer:71}],68:[function(t,e,r){function n(t,e){if(!(this instanceof n))return new n;this._bsontype="BSONRegExp",this.pattern=t,this.options=e;for(var r=0;re||e>36)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)}for(var s=n.fromNumber(Math.pow(e,6)),o=this,a="";;){var u=o.div(s),c=o.subtract(u.multiply(s)).toInt(),f=c.toString(e);if(o=u,o.isZero())return f+a;for(;f.length<6;)f="0"+f;a=""+f+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<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=65535&t.low_,f=0,l=0,h=0,p=0;return p+=o+c,h+=p>>>16,p&=65535,h+=i+u,l+=h>>>16,h&=65535,l+=r+a,f+=l>>>16,l&=65535,f+=e+s,f&=65535,n.fromBits(h<<16|p,f<<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_,f=0,l=0,h=0,p=0;return p+=o*c,h+=p>>>16,p&=65535,h+=i*c,l+=h>>>16,h&=65535,h+=o*u,l+=h>>>16,h&=65535,l+=r*c,f+=l>>>16,l&=65535,l+=i*u,f+=l>>>16,l&=65535,l+=o*a,f+=l>>>16,l&=65535,f+=e*c+r*u+i*a+o*s,f&=65535,n.fromBits(h<<16|p,f<<16|l)},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),r=e.div(t).shiftLeft(1);if(r.equals(n.ZERO))return t.isNegative()?n.ONE:n.NEG_ONE;var i=this.subtract(t.multiply(r)),o=r.add(i.div(t));return o}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();for(var s=n.ZERO,i=this;i.greaterThanOrEqual(t);){for(var r=Math.max(1,Math.floor(i.toNumber()/t.toNumber())),a=Math.ceil(Math.log(r)/Math.LN2),u=48>=a?1:Math.pow(2,a-48),c=n.fromNumber(r),f=c.multiply(t);f.isNegative()||f.greaterThan(i);)r-=u,c=n.fromNumber(r),f=c.multiply(t);c.isZero()&&(c=n.ONE),s=s.add(c),i=i.subtract(f)}return s},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(t&=63,0==t)return this;var e=this.low_;if(32>t){var r=this.high_;return n.fromBits(e<>>32-t)}return n.fromBits(0,e<t){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(t&=63,0==t)return this;var e=this.high_;if(32>t){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(t>=-128&&128>t){var e=n.INT_CACHE_[t];if(e)return e}var r=new n(0|t,0>t?-1:0);return t>=-128&&128>t&&(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:0>t?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(2>r||r>36)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;sa){var c=n.fromNumber(Math.pow(r,a));o=o.multiply(c).add(n.fromNumber(u))}else o=o.multiply(i),o=o.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),e.exports=n,e.exports.Timestamp=n},{}],71:[function(t,e,r){function n(t,e,r){if(!(this instanceof n))return new n(t,e,r);var i,o=typeof t;if("number"===o)i=t>0?t>>>0:0;else if("string"===o)"base64"===e&&(t=O(t)),i=n.byteLength(t,e);else{if("object"!==o||null===t)throw new TypeError("must start with number, buffer, array or string");"Buffer"===t.type&&P(t.data)&&(t=t.data),i=+t.length>0?Math.floor(+t.length):0}if(this.length>R)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+R.toString(16)+" bytes");var s;n.TYPED_ARRAY_SUPPORT?s=n._augment(new Uint8Array(i)):(s=this,s.length=i,s._isBuffer=!0);var a;if(n.TYPED_ARRAY_SUPPORT&&"number"==typeof t.byteLength)s._set(t);else if(S(t))if(n.isBuffer(t))for(a=0;i>a;a++)s[a]=t.readUInt8(a);else for(a=0;i>a;a++)s[a]=(t[a]%256+256)%256;else if("string"===o)s.write(t,0,e);else if("number"===o&&!n.TYPED_ARRAY_SUPPORT&&!r)for(a=0;i>a;a++)s[a]=0;return s}function i(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=e.length;if(o%2!==0)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;n>s;s++){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");t[r+s]=a}return s}function o(t,e,r,n){var i=k(N(e),t,r,n);return i}function s(t,e,r,n){var i=k(x(e),t,r,n);return i}function a(t,e,r,n){return s(t,e,r,n)}function u(t,e,r,n){var i=k(T(e),t,r,n);return i}function c(t,e,r,n){var i=k(B(e),t,r,n,2);return i}function f(t,e,r){return 0===e&&r===t.length?I.fromByteArray(t):I.fromByteArray(t.slice(e,r))}function l(t,e,r){var n="",i="";r=Math.min(t.length,r);for(var o=e;r>o;o++)t[o]<=127?(n+=$(i)+String.fromCharCode(t[o]),i=""):i+="%"+t[o].toString(16);return n+$(i)}function h(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;r>i;i++)n+=String.fromCharCode(t[i]);return n}function p(t,e,r){return h(t,e,r)}function d(t,e,r){var n=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>n)&&(r=n);for(var i="",o=e;r>o;o++)i+=j(t[o]);return i}function _(t,e,r){for(var n=t.slice(e,r),i="",o=0;ot)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function g(t,e,r,i,o,s){if(!n.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");if(e>o||s>e)throw new TypeError("value is out of bounds");if(r+i>t.length)throw new TypeError("index out of range")}function v(t,e,r,n){0>e&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);o>i;i++)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function m(t,e,r,n){0>e&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);o>i;i++)t[r+i]=e>>>8*(n?i:3-i)&255}function b(t,e,r,n,i,o){if(e>i||o>e)throw new TypeError("value is out of bounds");if(r+n>t.length)throw new TypeError("index out of range")}function w(t,e,r,n,i){return i||b(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),D.write(t,e,r,n,23,4),r+4}function E(t,e,r,n,i){return i||b(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),D.write(t,e,r,n,52,8),r+8}function O(t){for(t=A(t).replace(M,"");t.length%4!==0;)t+="=";return t}function A(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function S(t){return P(t)||n.isBuffer(t)||t&&"object"==typeof t&&"number"==typeof t.length}function j(t){return 16>t?"0"+t.toString(16):t.toString(16)}function N(t){for(var e=[],r=0;r=n)e.push(n);else{var i=r;n>=55296&&57343>=n&&r++;for(var o=encodeURIComponent(t.slice(i,r+1)).substr(1).split("%"),s=0;s>8,n=e%256,i.push(n),i.push(r);return i}function T(t){return I.toByteArray(t)}function k(t,e,r,n,i){i&&(n-=n%i);for(var o=0;n>o&&!(o+r>=e.length||o>=t.length);o++)e[o+r]=t[o];return o}function $(t){try{return decodeURIComponent(t)}catch(t){return String.fromCharCode(65533)}}var I=t("base64-js"),D=t("ieee754"),P=t("is-array");r.Buffer=n,r.SlowBuffer=n,r.INSPECT_MAX_BYTES=50,n.poolSize=8192;var R=1073741823;n.TYPED_ARRAY_SUPPORT=function(){try{var t=new ArrayBuffer(0),e=new Uint8Array(t);return e.foo=function(){return 42},42===e.foo()&&"function"==typeof e.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(t){return!1}}(),n.isBuffer=function(t){return!(null==t||!t._isBuffer)},n.compare=function(t,e){if(!n.isBuffer(t)||!n.isBuffer(e))throw new TypeError("Arguments must be Buffers");for(var r=t.length,i=e.length,o=0,s=Math.min(r,i);s>o&&t[o]===e[o];o++);return o!==s&&(r=t[o],i=e[o]),i>r?-1:r>i?1:0},n.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},n.concat=function(t,e){if(!P(t))throw new TypeError("Usage: Buffer.concat(list[, length])");if(0===t.length)return new n(0);if(1===t.length)return t[0];var r;if(void 0===e)for(e=0,r=0;r>>1;break;case"utf8":case"utf-8":r=N(t).length;break;case"base64":r=T(t).length;break;default:r=t.length}return r},n.prototype.length=void 0,n.prototype.parent=void 0,n.prototype.toString=function(t,e,r){var n=!1;if(e>>>=0,r=void 0===r||r===1/0?this.length:r>>>0,t||(t="utf8"),0>e&&(e=0),r>this.length&&(r=this.length),e>=r)return"";for(;;)switch(t){case"hex":return d(this,e,r);case"utf8":case"utf-8":return l(this,e,r);case"ascii":return h(this,e,r);case"binary":return p(this,e,r);case"base64":return f(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}},n.prototype.equals=function(t){if(!n.isBuffer(t))throw new TypeError("Argument must be a Buffer");return 0===n.compare(this,t)},n.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},n.prototype.compare=function(t){if(!n.isBuffer(t))throw new TypeError("Argument must be a Buffer");return n.compare(this,t)},n.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},n.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},n.prototype.write=function(t,e,r,n){if(isFinite(e))isFinite(r)||(n=r,r=void 0);else{var f=n;n=e,e=r,r=f}e=Number(e)||0;var l=this.length-e;r?(r=Number(r),r>l&&(r=l)):r=l,n=String(n||"utf8").toLowerCase();var h;switch(n){case"hex":h=i(this,t,e,r);break;case"utf8":case"utf-8":h=o(this,t,e,r);break;case"ascii":h=s(this,t,e,r);break;case"binary":h=a(this,t,e,r);break;case"base64":h=u(this,t,e,r);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":h=c(this,t,e,r);break;default:throw new TypeError("Unknown encoding: "+n)}return h},n.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},n.prototype.slice=function(t,e){var r=this.length;if(t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t),n.TYPED_ARRAY_SUPPORT)return n._augment(this.subarray(t,e));for(var i=e-t,o=new n(i,void 0,!0),s=0;i>s;s++)o[s]=this[s+t];return o},n.prototype.readUInt8=function(t,e){return e||y(t,1,this.length),this[t]},n.prototype.readUInt16LE=function(t,e){return e||y(t,2,this.length),this[t]|this[t+1]<<8},n.prototype.readUInt16BE=function(t,e){return e||y(t,2,this.length),this[t]<<8|this[t+1]},n.prototype.readUInt32LE=function(t,e){return e||y(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},n.prototype.readUInt32BE=function(t,e){return e||y(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},n.prototype.readInt8=function(t,e){return e||y(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},n.prototype.readInt16LE=function(t,e){e||y(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},n.prototype.readInt16BE=function(t,e){e||y(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},n.prototype.readInt32LE=function(t,e){return e||y(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},n.prototype.readInt32BE=function(t,e){return e||y(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},n.prototype.readFloatLE=function(t,e){return e||y(t,4,this.length),D.read(this,t,!0,23,4)},n.prototype.readFloatBE=function(t,e){return e||y(t,4,this.length),D.read(this,t,!1,23,4)},n.prototype.readDoubleLE=function(t,e){return e||y(t,8,this.length),D.read(this,t,!0,52,8)},n.prototype.readDoubleBE=function(t,e){return e||y(t,8,this.length),D.read(this,t,!1,52,8)},n.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,1,255,0),n.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=t,e+1},n.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,2,65535,0),n.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8):v(this,t,e,!0),e+2},n.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,2,65535,0),n.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=t):v(this,t,e,!1),e+2},n.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,4,4294967295,0),n.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t):m(this,t,e,!0),e+4},n.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,4,4294967295,0),n.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t):m(this,t,e,!1),e+4},n.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,1,127,-128),n.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[e]=t,e+1},n.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,2,32767,-32768),n.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8):v(this,t,e,!0),e+2},n.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,2,32767,-32768),n.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=t):v(this,t,e,!1),e+2},n.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,4,2147483647,-2147483648),n.TYPED_ARRAY_SUPPORT?(this[e]=t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):m(this,t,e,!0),e+4},n.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||g(this,t,e,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),n.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t):m(this,t,e,!1),e+4},n.prototype.writeFloatLE=function(t,e,r){return w(this,t,e,!0,r)},n.prototype.writeFloatBE=function(t,e,r){return w(this,t,e,!1,r)},n.prototype.writeDoubleLE=function(t,e,r){return E(this,t,e,!0,r)},n.prototype.writeDoubleBE=function(t,e,r){return E(this,t,e,!1,r)},n.prototype.copy=function(t,e,r,i){var o=this;if(r||(r=0),i||0===i||(i=this.length),e||(e=0),i!==r&&0!==t.length&&0!==o.length){if(r>i)throw new TypeError("sourceEnd < sourceStart");if(0>e||e>=t.length)throw new TypeError("targetStart out of bounds");if(0>r||r>=o.length)throw new TypeError("sourceStart out of bounds");if(0>i||i>o.length)throw new TypeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-es||!n.TYPED_ARRAY_SUPPORT)for(var a=0;s>a;a++)t[a+e]=this[a+r];else t._set(this.subarray(r,r+s),e)}},n.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),e>r)throw new TypeError("end < start");if(r!==e&&0!==this.length){if(0>e||e>=this.length)throw new TypeError("start out of bounds");if(0>r||r>this.length)throw new TypeError("end out of bounds");var n;if("number"==typeof t)for(n=e;r>n;n++)this[n]=t;else{var i=N(t.toString()),o=i.length;for(n=e;r>n;n++)this[n]=i[n%o]}return this}},n.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(n.TYPED_ARRAY_SUPPORT)return new n(this).buffer;for(var t=new Uint8Array(this.length),e=0,r=t.length;r>e;e+=1)t[e]=this[e];return t.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var C=n.prototype;n._augment=function(t){return t.constructor=n,t._isBuffer=!0,t._get=t.get,t._set=t.set,t.get=C.get,t.set=C.set,t.write=C.write,t.toString=C.toString,t.toLocaleString=C.toString,t.toJSON=C.toJSON,t.equals=C.equals,t.compare=C.compare,t.copy=C.copy,t.slice=C.slice,t.readUInt8=C.readUInt8,t.readUInt16LE=C.readUInt16LE,t.readUInt16BE=C.readUInt16BE,t.readUInt32LE=C.readUInt32LE,t.readUInt32BE=C.readUInt32BE,t.readInt8=C.readInt8,t.readInt16LE=C.readInt16LE,t.readInt16BE=C.readInt16BE,t.readInt32LE=C.readInt32LE,t.readInt32BE=C.readInt32BE,t.readFloatLE=C.readFloatLE,t.readFloatBE=C.readFloatBE,t.readDoubleLE=C.readDoubleLE,t.readDoubleBE=C.readDoubleBE,t.writeUInt8=C.writeUInt8,t.writeUInt16LE=C.writeUInt16LE,t.writeUInt16BE=C.writeUInt16BE,t.writeUInt32LE=C.writeUInt32LE,t.writeUInt32BE=C.writeUInt32BE,t.writeInt8=C.writeInt8,t.writeInt16LE=C.writeInt16LE,t.writeInt16BE=C.writeInt16BE,t.writeInt32LE=C.writeInt32LE,t.writeInt32BE=C.writeInt32BE,t.writeFloatLE=C.writeFloatLE,t.writeFloatBE=C.writeFloatBE,t.writeDoubleLE=C.writeDoubleLE,t.writeDoubleBE=C.writeDoubleBE,t.fill=C.fill,t.inspect=C.inspect,t.toArrayBuffer=C.toArrayBuffer,t};var M=/[^+\/0-9A-z]/g},{"base64-js":52,ieee754:76,"is-array":78}],72:[function(t,e,r){function n(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function i(){var t=arguments,e=this.useColors;if(t[0]=(e?"%c":"")+this.namespace+(e?" %c":" ")+t[0]+(e?"%c ":" ")+"+"+r.humanize(this.diff),!e)return t;var n="color: "+this.color;t=[t[0],n,"color: inherit"].concat(Array.prototype.slice.call(t,1));var i=0,o=0;return t[0].replace(/%[a-z%]/g,function(t){"%%"!==t&&(i++,"%c"===t&&(o=i))}),t.splice(o,0,n),t}function o(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(t){try{null==t?r.storage.removeItem("debug"):r.storage.debug=t}catch(t){}}function a(){var t;try{t=r.storage.debug}catch(t){}return t}function u(){try{return window.localStorage}catch(t){}}r=e.exports=t("./debug"),r.log=o,r.formatArgs=i,r.save=s,r.load=a,r.useColors=n,r.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:u(),r.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],r.formatters.j=function(t){return JSON.stringify(t)},r.enable(a())},{"./debug":73}],73:[function(t,e,r){function n(){return r.colors[f++%r.colors.length]}function i(t){function e(){}function i(){var t=i,e=+new Date,o=e-(c||e);t.diff=o,t.prev=c,t.curr=e,c=e,null==t.useColors&&(t.useColors=r.useColors()),null==t.color&&t.useColors&&(t.color=n());var s=Array.prototype.slice.call(arguments);s[0]=r.coerce(s[0]),"string"!=typeof s[0]&&(s=["%o"].concat(s));var a=0;s[0]=s[0].replace(/%([a-z%])/g,function(e,n){if("%%"===e)return e;a++;var i=r.formatters[n];if("function"==typeof i){var o=s[a];e=i.call(t,o),s.splice(a,1),a--}return e}),"function"==typeof r.formatArgs&&(s=r.formatArgs.apply(t,s));var u=i.log||r.log||console.log.bind(console);u.apply(t,s)}e.enabled=!1,i.enabled=!0;var o=r.enabled(t)?i:e;return o.namespace=t,o}function o(t){r.save(t);for(var e=(t||"").split(/[\s,]+/),n=e.length,i=0;n>i;i++)e[i]&&(t=e[i].replace(/\*/g,".*?"),"-"===t[0]?r.skips.push(new RegExp("^"+t.substr(1)+"$")):r.names.push(new RegExp("^"+t+"$")))}function s(){r.enable("")}function a(t){var e,n;for(e=0,n=r.skips.length;n>e;e++)if(r.skips[e].test(t))return!1;for(e=0,n=r.names.length;n>e;e++)if(r.names[e].test(t))return!0;return!1}function u(t){return t instanceof Error?t.stack||t.message:t}r=e.exports=i,r.coerce=u,r.disable=s,r.enable=o,r.enabled=a,r.humanize=t("ms"),r.names=[],r.skips=[],r.formatters={};var c,f=0},{ms:93}],74:[function(t,e,r){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(t){return"function"==typeof t}function o(t){return"number"==typeof t}function s(t){return"object"==typeof t&&null!==t}function a(t){return void 0===t}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(t){if(!o(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},n.prototype.emit=function(t){var e,r,n,o,u,c;if(this._events||(this._events={}),"error"===t&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;throw TypeError('Uncaught, unspecified "error" event.')}if(r=this._events[t],a(r))return!1;if(i(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:for(n=arguments.length,o=new Array(n-1),u=1;n>u;u++)o[u-1]=arguments[u];r.apply(this,o)}else if(s(r)){for(n=arguments.length,o=new Array(n-1),u=1;n>u;u++)o[u-1]=arguments[u];for(c=r.slice(),n=c.length,u=0;n>u;u++)c[u].apply(this,o)}return!0},n.prototype.addListener=function(t,e){var r;if(!i(e))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,i(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){var r;r=a(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&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())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function r(){this.removeListener(t,r),n||(n=!0,e.apply(this,arguments))}if(!i(e))throw TypeError("listener must be a function");var n=!1;return r.listener=e,this.on(t,r),this},n.prototype.removeListener=function(t,e){var r,n,o,a;if(!i(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(r=this._events[t],o=r.length,n=-1,r===e||i(r.listener)&&r.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(s(r)){for(a=o;a-- >0;)if(r[a]===e||r[a].listener&&r[a].listener===e){n=a;break}if(0>n)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},n.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(r=this._events[t],i(r))this.removeListener(t,r);else for(;r.length;)this.removeListener(t,r[r.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){var e;return e=this._events&&this._events[t]?i(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.listenerCount=function(t,e){var r;return r=t._events&&t._events[e]?i(t._events[e])?1:t._events[e].length:0}},{}],75:[function(t,e,r){function n(t,e){return function r(){if(!r.hookCalled){r.hookCalled=!0;var n=t.apply(e,arguments);n&&n.then&&n.then(function(){},function(){})}}}e.exports={hook:function(t,e,r){if(1!==arguments.length||"object"!=typeof t){var i=this.prototype||this,o=i._pres=i._pres||{},s=i._posts=i._posts||{};return o[t]=o[t]||[],s[t]=s[t]||[],i[t]=function(){var o,s=this,a=arguments[arguments.length-1],u=this._pres[t],c=this._posts[t],f=u.length,l=-1,h=i[t].numAsyncPres,p=function(t){return t?d(t):void(--h||y.apply(s,o))},d=function(t){if("function"==typeof a)return a(t);if(r)return r.call(s,t);throw t},_=function(){if(arguments[0]instanceof Error)return d(arguments[0]);var t,e,r=Array.prototype.slice.call(arguments);if(!r.length||null==arguments[0]&&"function"==typeof a||(o=r),++l>1,f=-7,l=r?i-1:0,h=r?-1:1,p=t[e+l];for(l+=h,o=p&(1<<-f)-1,p>>=-f,f+=a;f>0;o=256*o+t[e+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+t[e+l],l+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:(p?-1:1)*(1/0);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,e,r,n,i,o){var s,a,u,c=8*o-i-1,f=(1<>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,_=0>e||0===e&&0>1/e?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+l>=1?h/u:h*Math.pow(2,1-l),e*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(e*u-1)*Math.pow(2,i),s+=l):(a=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;t[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;t[r+p]=255&s,p+=d,s/=256,c-=8);t[r+p-d]|=128*_}},{}],77:[function(t,e,r){"function"==typeof Object.create?e.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}},{}],78:[function(t,e,r){var n=Array.isArray,i=Object.prototype.toString;e.exports=n||function(t){return!!t&&"[object Array]"==i.call(t)}},{}],79:[function(t,e,r){(function(t){"use strict";function r(){this._pres={},this._posts={}}r.prototype.execPre=function(e,r,n){var i=this._pres[e]||[],o=i.length,s=i.numAsync||0,a=0,u=s,c=!1;if(!o)return t.nextTick(function(){n(null)});var f=function(){if(!(a>=o)){var e=i[a];if(e.isAsync)e.fn.call(r,function(t){if(t){if(c)return;return c=!0,n(t)}++a,f.apply(r,arguments)},function(t){if(t){if(c)return;return c=!0,n(t)}return 0===--s?n(null):void 0});else if(e.fn.length>0){var l=[function(t){if(t){if(c)return;return c=!0,n(t)}return++a>=o?u>0?void 0:n(null):void f.apply(r,arguments)}];if(arguments.length>=2)for(var h=1;h=o)return u>0?void 0:t.nextTick(function(){n(null)});f()}}};f()},r.prototype.execPost=function(e,r,n,i){var o=this._posts[e]||[],s=o.length,a=0;if(!s)return t.nextTick(function(){i.apply(null,[null].concat(n))});var u=function(){var t=o[a];if(t.length>n.length)t.apply(r,n.concat(function(t){return t?i(t):++a>=s?i.apply(null,[null].concat(n)):void u()}));else{if(t.apply(r,n),++a>=s)return i.apply(null,[null].concat(n));u()}};u()},r.prototype.wrap=function(t,e,r,n,i){var o=n.length>0?n[n.length-1]:null,s=this;this.execPre(t,r,function(a){if(a){if("function"==typeof o)return o(a)}else{var u="function"==typeof o?n.length-1:n.length;e.apply(r,n.slice(0,u).concat(function(){if(arguments[0])return"function"==typeof o?o(arguments[0]):void 0;i&&"function"==typeof o&&o.apply(r,arguments);var e=Array.prototype.slice.call(arguments,1);s.execPost(t,r,e,function(){return arguments[0]?"function"==typeof o?o(arguments[0]):void 0:"function"!=typeof o||i?void 0:o.apply(r,arguments)})}))}})},r.prototype.createWrapper=function(t,e,r){var n=this;return function(){var i=Array.prototype.slice.call(arguments);n.wrap(t,e,r,i)}},r.prototype.pre=function(t,e,r,n){"boolean"!=typeof arguments[1]&&(n=r,r=e,e=!1),this._pres[t]=this._pres[t]||[];var i=this._pres[t];return e&&(i.numAsync=i.numAsync||0,++i.numAsync),i.push({fn:r,isAsync:e}),this},r.prototype.post=function(t,e){return(this._posts[t]=this._posts[t]||[]).push(e),this},r.prototype.clone=function(){var t=new r;for(var e in this._pres)t._pres[e]=this._pres[e].slice();for(var e in this._posts)t._posts[e]=this._posts[e].slice();return t},e.exports=r}).call(this,t("g5I+bs"))},{"g5I+bs":94}],80:[function(t,e,r){e.exports=r=t("./lib")},{"./lib":81}],81:[function(t,e,r){function n(t){return t}r.get=function(t,e,i,o){var s;"function"==typeof i&&(i.length<2?(o=i,i=void 0):(s=i,i=void 0)),o||(o=n);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=e,f=0;fp;++p)if(f=c[p],"$"!=f){if(Array.isArray(h)&&!/^\d+$/.test(f)){var _=c.slice(p);if(!l&&Array.isArray(e))for(var y=0;y0},o.prototype.fulfill=function(){return this.safeEmit.apply(this,i(o.SUCCESS,arguments))},o.prototype.reject=function(t){if(this.ended&&!this.hasRejectListeners())throw t;return this.safeEmit(o.FAILURE,t)},o.prototype.resolve=function(t,e){return t?this.reject(t):this.fulfill(e)},o.prototype.onFulfill=function(t){if(!t)return this;if("function"!=typeof t)throw new TypeError("fn should be a function");return this.on(o.SUCCESS,t)},o.prototype.onReject=function(t){if(!t)return this;if("function"!=typeof t)throw new TypeError("fn should be a function");return this.on(o.FAILURE,t)},o.prototype.onResolve=function(t){if(!t)return this;if("function"!=typeof t)throw new TypeError("fn should be a function");return this.on(o.FAILURE,function(e){t.call(this,e)}),this.on(o.SUCCESS,function(){t.apply(this,i(null,arguments))}),this},o.prototype.then=function(t,e){var r=new o;return"function"==typeof t?this.onFulfill(s(r,t)):this.onFulfill(r.fulfill.bind(r)),"function"==typeof e?this.onReject(s(r,e)):this.onReject(r.reject.bind(r)),r},o.prototype.end=o.prototype.catch=function(t){return t||this.hasRejectListeners()||(t=function(t){throw t}),this.onReject(t),this.ended=!0,this},o.trace=function(t,e){t.then(function(){console.log("%s fulfill %j",e,n(arguments))},function(){console.log("%s reject %j",e,n(arguments))})},o.prototype.chain=function(t){var e=this;return e.onFulfill(t.fulfill.bind(t)),e.onReject(t.reject.bind(t)),t},o.prototype.all=function(t){var e=new o;return this.then(t).then(function(t){var r,n=0,i=[];return t.length||e.resolve(),t.forEach(function(t,o){r||(n++,t.then(function(t){r||(i[o]=t,--n,0==n&&e.fulfill(i))},function(t){r||(r=t,e.reject(t))}))}),e},e.reject.bind(e)),e},o.hook=function(t){var e=new o,r=new o,n=function(){return--i,0==i&&r.fulfill(),r},i=1,s=e;return t.forEach(function(t){s=s.then(function(){var e=new o;return i++,t(e.resolve.bind(e),n),e})}),s=s.then(n),e.resolve(),s},o.fulfilled=function(){var t=new o;return t.fulfill.apply(t,arguments),t},o.rejected=function(t){return(new o).reject(t)},o.deferred=function(){var t=new o;return{promise:t,reject:t.reject.bind(t),resolve:t.fulfill.bind(t),callback:t.resolve.bind(t)}}}).call(this,t("g5I+bs"))},{events:74,"g5I+bs":94,util:98}],83:[function(t,e,r){"use strict";function n(){}function i(t){return function(){throw new Error("collection."+t+" not implemented")}}for(var o=["find","findOne","update","remove","count","distinct","findAndModify","aggregate","findStream"],s=0,a=o.length;a>s;++s){var u=o[s];n.prototype[u]=i(u)}e.exports=r=n,n.methods=o},{}],84:[function(t,e,r){"use strict";var n=t("../env");if("unknown"==n.type)throw new Error("Unknown environment");e.exports=t(n.isNode?"./node":n.isMongo?"./collection":"./collection")},{"../env":86,"./collection":83,"./node":85}],85:[function(t,e,r){"use strict";function n(t){this.collection=t,this.collectionName=t.collectionName}var i=t("./collection"),o=t("../utils");o.inherits(n,i),n.prototype.find=function(t,e,r){this.collection.find(t,e,function(t,e){return t?r(t):void e.toArray(r)})},n.prototype.findOne=function(t,e,r){this.collection.findOne(t,e,r)},n.prototype.count=function(t,e,r){this.collection.count(t,e,r)},n.prototype.distinct=function(t,e,r,n){this.collection.distinct(t,e,r,n)},n.prototype.update=function(t,e,r,n){this.collection.update(t,e,r,n)},n.prototype.remove=function(t,e,r){this.collection.remove(t,e,r)},n.prototype.findAndModify=function(t,e,r,n){var i=Array.isArray(r.sort)?r.sort:[];this.collection.findAndModify(t,i,e,r,n)},n.prototype.findStream=function(t,e,r){return this.collection.find(t,e).stream(r)},n.prototype.findCursor=function(t,e){return this.collection.find(t,e)},e.exports=r=n},{"../utils":89,"./collection":83}],86:[function(t,e,r){(function(t,n,i){"use strict";r.isNode="undefined"!=typeof t&&"object"==typeof e&&"object"==typeof n&&"function"==typeof i&&t.argv,r.isMongo=!r.isNode&&"function"==typeof printjson&&"function"==typeof ObjectId&&"function"==typeof rs&&"function"==typeof sh,r.isBrowser=!r.isNode&&!r.isMongo&&"undefined"!=typeof window,r.type=r.isNode?"node":r.isMongo?"mongo":r.isBrowser?"browser":"unknown"}).call(this,t("g5I+bs"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},t("buffer").Buffer)},{buffer:71,"g5I+bs":94}],87:[function(t,e,r){"use strict";function n(t,e){if(!(this instanceof n))return new n(t,e);var r=this.constructor.prototype;this.op=r.op||void 0,this.options={},this.setOptions(r.options),this._conditions=r._conditions?c.clone(r._conditions):{},this._fields=r._fields?c.clone(r._fields):void 0,this._update=r._update?c.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))}function i(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 })`");if(r&&r.$meta){var n=t.sort||(t.sort={});return void(n[e]={$meta:r.$meta})}var i=String(r||1).toLowerCase();if(!/^(?:ascending|asc|descending|desc|1|-1)$/.test(i))throw c.isArray(r)&&(r="["+r+"]"),new TypeError("Invalid sort value: {"+e+": "+r+" }");var n=t.sort||(t.sort={}),o=r.toString().replace("asc","1").replace("ascending","1").replace("desc","-1").replace("descending","-1");n[e]=parseInt(o,10)}function o(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 })`");r.toString().replace("asc","1").replace("ascending","1").replace("desc","-1").replace("descending","-1");t.sort.push([e,r])}var s=t("sliced"),a=t("assert"),u=t("util"),c=t("./utils"),f=t("debug")("mquery"),l="$geoWithin";Object.defineProperty(n,"use$geoWithin",{get:function(){return"$geoWithin"==l},set:function(t){l=!0===t?"$geoWithin":"$within"}}),n.prototype.toConstructor=function(){function t(e,r){return this instanceof t?void n.call(this,e,r):new t(e,r)}c.inherits(t,n);var e=t.prototype;return e.options={},e.setOptions(this.options),e.op=this.op,e._conditions=c.clone(this._conditions),e._fields=c.clone(this._fields),e._update=c.clone(this._update),e._path=this._path,e._distinct=this._distinct,e._collection=this._collection,e._traceFunction=this._traceFunction,t},n.prototype.setOptions=function(t){if(!t||!c.isObject(t))return this;for(var e,r=c.keys(t),n=0;nn;++n){var o=t[n];if(o){var s="-"==o[0]?0:1;0===s&&(o=o.substring(1)),e[o]=s}}return this}if(c.isObject(t)&&!Array.isArray(t)){for(var a=c.keys(t),n=0;no;++o)this.slice(n[o],r[n[o]]);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=s(arguments)):(t=arguments[0],e=arguments[1]):3===arguments.length&&(t=arguments[0],e=s(arguments,1));var a=this._fields||(this._fields={});return a[t]={$slice:e},this},n.prototype.sort=function(t){if(!t)return this;var e;this._validate("sort");var r=typeof t;if(Array.isArray(t)){e=t.length;for(var n=0;nn;++n){var s=t[n];if(s){var a="-"==s[0]?-1:1;-1===a&&(s=s.substring(1)),i(this.options,s,a)}}return this}if(c.isObject(t)){for(var u=c.keys(t),n=0;n1&&!n.prototype.read.deprecationWarningIssued&&(console.error("Deprecation warning: 'tags' argument is not supported anymore in Query.read() method. Please use mongodb.ReadPreference object instead."),n.prototype.read.deprecationWarningIssued=!0),this.options.readPreference=c.readPref(t),this},n.prototype.tailable=function(){return this._validate("tailable"),this.options.tailable=arguments.length?!!arguments[0]:!0,this},n.prototype.merge=function(t){if(!t)return this;if(!n.canMerge(t))throw new TypeError("Invalid argument. Expected instanceof mquery or plain object");return t instanceof n?(t._conditions&&c.merge(this._conditions,t._conditions),t._fields&&(this._fields||(this._fields={}),c.merge(this._fields,t._fields)),t.options&&(this.options||(this.options={}),c.merge(this.options,t.options)),t._update&&(this._update||(this._update={}),c.mergeClone(this._update,t._update)),t._distinct&&(this._distinct=t._distinct),this):(c.merge(this._conditions,t),this)},n.prototype.find=function(t,e){if(this.op="find","function"==typeof t?(e=t,t=void 0):n.canMerge(t)&&this.merge(t),!e)return this;var r=this._conditions,i=this._optionsForExec();return i.fields=this._fieldsForExec(),f("find",this._collection.collectionName,r,i),e=this._wrapCallback("find",e,{conditions:r,options:i}),this._collection.find(r,i,c.tick(e)),this},n.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(),f("findCursor",this._collection.collectionName,e,r),this._collection.findCursor(e,r)},n.prototype.findOne=function(t,e){if(this.op="findOne","function"==typeof t?(e=t,t=void 0):n.canMerge(t)&&this.merge(t),!e)return this;var r=this._conditions,i=this._optionsForExec();return i.fields=this._fieldsForExec(),f("findOne",this._collection.collectionName,r,i),e=this._wrapCallback("findOne",e,{conditions:r,options:i}),this._collection.findOne(r,i,c.tick(e)),this},n.prototype.count=function(t,e){if(this.op="count",this._validate(),"function"==typeof t?(e=t,t=void 0):n.canMerge(t)&&this.merge(t),!e)return this;var r=this._conditions,i=this._optionsForExec();return f("count",this._collection.collectionName,r,i),e=this._wrapCallback("count",e,{conditions:r,options:i}),this._collection.count(r,i,c.tick(e)),this},n.prototype.distinct=function(t,e,r){if(this.op="distinct",this._validate(),!r){switch(typeof 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(typeof t){case"function":r=t,t=e=void 0;break;case"string":e=t,t=void 0}}if("string"==typeof e&&(this._distinct=e),n.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 f("distinct",this._collection.collectionName,i,o),r=this._wrapCallback("distinct",r,{conditions:i,options:o}),this._collection.distinct(this._distinct,i,o,c.tick(r)),this},n.prototype.update=function(t,e,r,i){this.op="update";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(typeof 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}}if(n.canMerge(t)&&this.merge(t),e&&this._mergeUpdate(e),c.isObject(r)&&this.setOptions(r),!o&&!i)return this;if(!this._update||!this.options.overwrite&&0===c.keys(this._update).length)return i&&c.soon(i.bind(null,null,0)),this;r=this._optionsForExec(),i||(r.safe=!1);var t=this._conditions;return e=this._updateForExec(),f("update",this._collection.collectionName,t,e,r),i=this._wrapCallback("update",i,{conditions:t,doc:e,options:r}),this._collection.update(t,e,r,c.tick(i)),this},n.prototype.remove=function(t,e){this.op="remove";var r;if("function"==typeof t?(e=t,t=void 0):n.canMerge(t)?this.merge(t):!0===t&&(r=t,t=void 0),!r&&!e)return this;var i=this._optionsForExec();e||(i.safe=!1);var o=this._conditions;return f("remove",this._collection.collectionName,o,i),e=this._wrapCallback("remove",e,{conditions:o,options:i}),this._collection.remove(o,i,c.tick(e)),this},n.prototype.findOneAndUpdate=function(t,e,r,i){switch(this.op="findOneAndUpdate",this._validate(),arguments.length){case 3:"function"==typeof r&&(i=r,r={});break;case 2:"function"==typeof e&&(i=e,e=t,t=void 0),r=void 0;break;case 1:"function"==typeof t?(i=t,t=r=e=void 0):(e=t,t=r=void 0)}return n.canMerge(t)&&this.merge(t),e&&this._mergeUpdate(e),r&&this.setOptions(r),i?this._findAndModify("update",i):this},n.prototype.findOneAndRemove=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),n.canMerge(t)&&this.merge(t),e&&this.setOptions(e),r?this._findAndModify("remove",r):this},n.prototype._findAndModify=function(t,e){a.equal("function",typeof e);var r,n,i=this._optionsForExec();if("remove"==t)i.remove=!0;else if("new"in i||(i.new=!0),"upsert"in i||(i.upsert=!1),n=this._updateForExec(),!n){if(!i.upsert)return this.findOne(e);n={$set:{}}}var r=this._fieldsForExec();r&&(i.fields=r);var o=this._conditions;return f("findAndModify",this._collection.collectionName,o,n,i),e=this._wrapCallback("findAndModify",e,{conditions:o,doc:n,options:i}),this._collection.findAndModify(o,n,i,c.tick(e)),this},n.prototype._wrapCallback=function(t,e,r){var i=this._traceFunction||n.traceFunction;if(i){r.collectionName=this._collection.collectionName;var o=i&&i.call(null,t,r,this),s=(new Date).getTime();return function(t,r){if(o){var n=(new Date).getTime()-s;o.call(null,t,r,n)}e&&e.apply(null,arguments)}}return e},n.prototype.setTraceFunction=function(t){return this._traceFunction=t,this},n.prototype.exec=function(t,e){switch(typeof t){case"function":e=t,t=null;break;case"string":this.op=t}a.ok(this.op,"Missing query type: (find, update, etc)"),("update"==this.op||"remove"==this.op)&&(e||(e=!0));var r=this;return"function"!=typeof e?new n.Promise(function(t,e){r[r.op](function(n,i){n?e(n):t(i),r=t=e=null})}):void this[this.op](e)},n.prototype.thunk=function(){var t=this;return function(e){t.exec(e)}},n.prototype.then=function(t,e){var r=this,i=new n.Promise(function(t,e){r.exec(function(n,i){n?e(n):t(i),r=t=e=null})});return i.then(t,e)},n.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(),f("stream",this._collection.collectionName,e,r,t),this._collection.findStream(e,r,t)},n.prototype.selected=function(){return!!(this._fields&&Object.keys(this._fields).length>0)},n.prototype.selectedInclusively=function(){if(!this._fields)return!1;var t=Object.keys(this._fields);if(0===t.length)return!1;for(var e=0;e0)return"field selection and slice";var e,r=Object.keys(n.distinct);return r.every(function(r){return t.options[r]?(e=r,!1):!0}),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,r=Object.keys(n.findOneAndUpdate);return r.every(function(r){return t.options[r]?(e=r,!1):!0}),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){if(t._fields&&Object.keys(t._fields).length>0)return"field selection and slice";var e,r=Object.keys(n.count);return r.every(function(r){return t.options[r]?(e=r,!1):!0}),e},n.count.slice=n.count.batchSize=n.count.comment=n.count.maxScan=n.count.snapshot=n.count.tailable=!0},{}],89:[function(t,e,r){(function(e,n){"use strict";function i(t){function e(){}if(arguments.length>1)throw new Error("Adding properties is not supported");return e.prototype=t,new e}var o=t("regexp-clone"),s=r.clone=function t(e,n){if(void 0===e||null===e)return e;if(Array.isArray(e))return r.cloneArray(e,n);if(e.constructor){if(/ObjectI[dD]$/.test(e.constructor.name))return"function"==typeof e.clone?e.clone():new e.constructor(e.id);if("ReadPreference"===e._type&&e.isValid&&e.toObject)return"function"==typeof e.clone?e.clone():new e.constructor(e.mode,t(e.tags,n));if("Binary"==e._bsontype&&e.buffer&&e.value)return"function"==typeof e.clone?e.clone():new e.constructor(e.value(!0),e.sub_type);if("Date"===e.constructor.name||"Function"===e.constructor.name)return new e.constructor(+e);if("RegExp"===e.constructor.name)return o(e);if("Buffer"===e.constructor.name)return r.cloneBuffer(e)}return u(e)?r.cloneObject(e,n):e.valueOf?e.valueOf():void 0};r.cloneObject=function(t,e){var r,n,i,o,a,u=e&&e.retainKeyOrder,c=e&&e.minimize,f={};if(u)for(o in t)i=s(t[o],e),c&&"undefined"==typeof i||(r||(r=!0),f[o]=i);else for(n=Object.keys(t),a=n.length;a--;)o=n[a],i=s(t[o],e),c&&"undefined"==typeof i||(r||(r=!0),f[o]=i);return c?r&&f:f},r.cloneArray=function(t,e){for(var r=[],n=0,i=t.length;i>n;n++)r.push(s(t[n],e));return r},r.tick=function(t){return"function"==typeof t?function(){var e=arguments;c(function(){t.apply(this,e)})}:void 0},r.merge=function t(e,n){for(var i,o=Object.keys(n),s=o.length;s--;)i=o[s],"undefined"==typeof e[i]?e[i]=n[i]:r.isObject(n[i])?t(e[i],n[i]):e[i]=n[i]},r.mergeClone=function t(e,n){for(var i,o=Object.keys(n),a=o.length;a--;)i=o[a],"undefined"==typeof e[i]?e[i]=s(n[i],{retainKeyOrder:1}):r.isObject(n[i])?t(e[i],n[i]):e[i]=s(n[i],{retainKeyOrder:1})};r.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};var a=Object.prototype.toString,u=(r.toString=function(t){return a.call(t)},r.isObject=function(t){return"[object Object]"==r.toString(t)});r.isArray=function(t){return Array.isArray(t)||"object"==typeof t&&"[object Array]"==r.toString(t)};r.keys=Object.keys||function(t){var e=[];for(var r in t)t.hasOwnProperty(r)&&e.push(r);return e},r.create="function"==typeof Object.create?Object.create:i,r.inherits=function(t,e){t.prototype=r.create(e.prototype),t.prototype.constructor=t};var c=r.soon="function"==typeof setImmediate?setImmediate:e.nextTick;r.cloneBuffer=function(t){var e=new n(t.length);return t.copy(e,0,0,t.length),e},r.isArgumentsObject=function(t){return"[object Arguments]"===Object.prototype.toString.call(t)}}).call(this,t("g5I+bs"),t("buffer").Buffer)},{buffer:71,"g5I+bs":94,"regexp-clone":95}],90:[function(t,e,r){(function(t,n){!function(t){if("object"==typeof r&&"undefined"!=typeof e)e.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i;"undefined"!=typeof window?i=window:"undefined"!=typeof n?i=n:"undefined"!=typeof self&&(i=self),i.Promise=t()}}(function(){var e,r,i;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 f=r[s]={exports:{}};e[s][0].call(f.exports,function(t){var r=e[s][1][t];return i(r?r:t)},f,f.exports,t,e,r,n)}return r[s].exports}for(var o="function"==typeof _dereq_&&_dereq_,s=0;s0},n.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/m3OTXk\n")}},f.hasDevTools?(u.isStatic&&(u=function(t){setTimeout(t,0)}),n.prototype.invokeLater=function(t,e,r){this._trampolineEnabled?i.call(this,t,e,r):this._schedule(function(){setTimeout(function(){t.call(e,r)},100)})},n.prototype.invoke=function(t,e,r){this._trampolineEnabled?o.call(this,t,e,r):this._schedule(function(){t.call(e,r)})},n.prototype.settlePromises=function(t){this._trampolineEnabled?s.call(this,t):this._schedule(function(){t._settlePromises()})}):(n.prototype.invokeLater=i,n.prototype.invoke=o,n.prototype.settlePromises=s),n.prototype.invokeFirst=function(t,e,r){this._normalQueue.unshift(t,e,r),this._queueTick()},n.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()}},n.prototype._drainQueues=function(){this._drainQueue(this._normalQueue),this._reset(),this._drainQueue(this._lateQueue)},n.prototype._queueTick=function(){this._isTickUsed||(this._isTickUsed=!0,this._schedule(this.drainQueues))},n.prototype._reset=function(){this._isTickUsed=!1},e.exports=new n,e.exports.firstLineError=a},{"./queue.js":28,"./schedule.js":31,"./util.js":38}],3:[function(t,e,r){"use strict";e.exports=function(t,e,r){var n=function(t,e){this._reject(e)},i=function(t,e){e.promiseRejectionQueued=!0,e.bindingPromise._then(n,n,null,this,t)},o=function(t,e){this._isPending()&&this._resolveCallback(e.target)},s=function(t,e){e.promiseRejectionQueued||this._reject(t)};t.prototype.bind=function(n){var a=r(n),u=new t(e);u._propagateFrom(this,1);var c=this._target();if(u._setBoundTo(a),a instanceof t){var f={promiseRejectionQueued:!1,promise:u,target:c,bindingPromise:a};c._then(e,i,u._progress,u,f),a._then(o,s,u._progress,u,f)}else u._resolveCallback(c);return u},t.prototype._setBoundTo=function(t){void 0!==t?(this._bitField=131072|this._bitField,this._boundTo=t):this._bitField=-131073&this._bitField},t.prototype._isBound=function(){return 131072===(131072&this._bitField)},t.bind=function(n,i){var o=r(n),s=new t(e);return s._setBoundTo(o),o instanceof t?o._then(function(){s._resolveCallback(i)},s._reject,s._progress,s,null):s._resolveCallback(i),s}}},{}],4:[function(t,e,r){"use strict";function n(){try{Promise===o&&(Promise=i)}catch(t){}return o}var i;"undefined"!=typeof Promise&&(i=Promise);var o=t("./promise.js")();o.noConflict=n,e.exports=o},{"./promise.js":23}],5:[function(t,e,r){"use strict";var n=Object.create;if(n){var i=n(null),o=n(null);i[" size"]=o[" size"]=0}e.exports=function(e){function r(t,r){var n;if(null!=t&&(n=t[r]),"function"!=typeof n){var i="Object "+a.classString(t)+" has no method '"+a.toString(r)+"'";throw new e.TypeError(i)}return n}function n(t){var e=this.pop(),n=r(t,e);return n.apply(t,this)}function i(t){return t[this]}function o(t){var e=+this;return 0>e&&(e=Math.max(0,e+t.length)),t[e]}var s,a=t("./util.js"),u=a.canEvaluate;a.isIdentifier;e.prototype.call=function(t){for(var e=arguments.length,r=new Array(e-1),i=1;e>i;++i)r[i-1]=arguments[i];return r.push(t),this._then(n,void 0,void 0,r,void 0)},e.prototype.get=function(t){var e,r="number"==typeof t;if(r)e=o;else if(u){var n=s(t);e=null!==n?n:i}else e=i;return this._then(e,void 0,void 0,t,void 0)}}},{"./util.js":38}],6:[function(t,e,r){"use strict";e.exports=function(e){var r=t("./errors.js"),n=t("./async.js"),i=r.CancellationError;e.prototype._cancel=function(t){if(!this.isCancellable())return this;for(var e,r=this;void 0!==(e=r._cancellationParent)&&e.isCancellable();)r=e;this._unsetCancellable(),r._target()._rejectCallback(t,!1,!0)},e.prototype.cancel=function(t){return this.isCancellable()?(void 0===t&&(t=new i),n.invokeLater(this._cancel,this,t),this):this},e.prototype.cancellable=function(){return this._cancellable()?this:(n.enableTrampoline(),this._setCancellable(),this._cancellationParent=void 0,this)},e.prototype.uncancellable=function(){var t=this.then();return t._unsetCancellable(),t},e.prototype.fork=function(t,e,r){var n=this._then(t,e,r,void 0,void 0);return n._setCancellable(),n._cancellationParent=void 0,n}}},{"./async.js":2,"./errors.js":13}],7:[function(e,r,n){"use strict";r.exports=function(){function r(t){this._parent=t;var e=this._length=1+(void 0===t?0:t._length);w(this,r),e>32&&this.uncycle()}function n(t,e){for(var r=0;r=0;--a)if(n[a]===o){s=a;break}for(var a=s;a>=0;--a){var u=n[a];if(e[i]!==u)break;e.pop(),i--}e=n}}function s(t){for(var e=[],r=0;r0&&(e=e.slice(r)),e}function u(t){var e;if("function"==typeof t)e="[function "+(t.name||"anonymous")+"]";else{e=t.toString();var r=/\[object [a-zA-Z0-9$_]+\]/;if(r.test(e))try{var n=JSON.stringify(t);e=n}catch(t){}0===e.length&&(e="(empty array)")}return"(<"+c(e)+">, no stack trace)"}function c(t){var e=41;return t.lengtht)){for(var e=[],r={},n=0,i=this;void 0!==i;++n)e.push(i),i=i._parent;t=this._length=n;for(var n=t-1;n>=0;--n){var o=e[n].stack;void 0===r[o]&&(r[o]=n)}for(var n=0;t>n;++n){var s=e[n].stack,a=r[s];if(void 0!==a&&a!==n){a>0&&(e[a-1]._parent=void 0,e[a-1]._length=1),e[n]._parent=void 0,e[n]._length=1;var u=n>0?e[n-1]:this;t-1>a?(u._parent=e[a+1],u._parent.uncycle(),u._length=u._parent._length+1):(u._parent=void 0,u._length=1);for(var c=u._length+1,f=n-2;f>=0;--f)e[f]._length=c,c++;return}}}},r.prototype.parent=function(){return this._parent},r.prototype.hasParent=function(){return void 0!==this._parent},r.prototype.attachExtraTrace=function(t){if(!t.__stackCleaned__){this.uncycle();for(var e=r.parseStackAndMessage(t),a=e.message,u=[e.stack],c=this;void 0!==c;)u.push(s(c.stack.split("\n"))),c=c._parent;o(u),i(u),p.notEnumerableProp(t,"stack",n(a,u)),p.notEnumerableProp(t,"__stackCleaned__",!0)}},r.parseStackAndMessage=function(t){var e=t.stack,r=t.toString();return e="string"==typeof e&&e.length>0?a(t):[" (No stack trace)"],{message:r,stack:s(e)}},r.formatAndLogError=function(t,e){if("undefined"!=typeof console){var r;if("object"==typeof t||"function"==typeof t){var n=t.stack;r=e+y(n,t)}else r=e+String(t);"function"==typeof l?l(r):("function"==typeof console.log||"object"==typeof console.log)&&console.log(r)}},r.unhandledRejection=function(t){r.formatAndLogError(t,"^--- With additional stack trace: ")},r.isSupported=function(){return"function"==typeof w},r.fireRejectionEvent=function(t,e,n,i){var o=!1;try{"function"==typeof e&&(o=!0,"rejectionHandled"===t?e(i):e(n,i))}catch(t){h.throwLater(t)}var s=!1;try{s=E(t,n,i)}catch(t){s=!0,h.throwLater(t)}var a=!1;if(b)try{a=b(t.toLowerCase(),{reason:n,promise:i})}catch(t){a=!0,h.throwLater(t)}s||o||a||"unhandledRejection"!==t||r.formatAndLogError(n,"Unhandled rejection ")};var v=function(){return!1},m=/[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;r.setBounds=function(t,e){if(r.isSupported()){for(var n,i,o=t.stack.split("\n"),s=e.stack.split("\n"),a=-1,u=-1,c=0;ca||0>u||!n||!i||n!==i||a>=u||(v=function(t){if(d.test(t))return!0;var e=f(t);return e&&e.fileName===n&&a<=e.line&&e.line<=u?!0:!1})}};var b,w=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():u(e)};if("number"==typeof Error.stackTraceLimit&&"function"==typeof Error.captureStackTrace){Error.stackTraceLimit=Error.stackTraceLimit+6,_=t,y=e;var r=Error.captureStackTrace;return v=function(t){return d.test(t)},function(t,e){Error.stackTraceLimit=Error.stackTraceLimit+6,r(t,e),Error.stackTraceLimit=Error.stackTraceLimit-6}}var n=new Error;if("string"==typeof n.stack&&n.stack.split("\n")[0].indexOf("stackDetection@")>=0)return _=/@/,y=e,g=!0,function(t){t.stack=(new Error).stack};var i;try{throw new Error}catch(t){i="stack"in t}return"stack"in n||!i||"number"!=typeof Error.stackTraceLimit?(y=function(t,e){return"string"==typeof t?t:"object"!=typeof e&&"function"!=typeof e||void 0===e.name||void 0===e.message?u(e):e.toString()},null):(_=t,y=e,function(t){Error.stackTraceLimit=Error.stackTraceLimit+6;try{throw new Error}catch(e){t.stack=e.stack}Error.stackTraceLimit=Error.stackTraceLimit-6})}([]),E=function(){if(p.isNode)return function(e,r,n){return"rejectionHandled"===e?t.emit(e,n):t.emit(e,r,n)};var e=!1,r=!0;try{var n=new self.CustomEvent("test");e=n instanceof CustomEvent}catch(t){}if(!e)try{var i=document.createEvent("CustomEvent");i.initCustomEvent("testingtheevent",!1,!0,{}),self.dispatchEvent(i)}catch(t){r=!1}r&&(b=function(t,r){var n;return e?n=new self.CustomEvent(t,{detail:r,bubbles:!1,cancelable:!0}):self.dispatchEvent&&(n=document.createEvent("CustomEvent"),n.initCustomEvent(t,!1,!0,r)),n?!self.dispatchEvent(n):!1});var o={};return o.unhandledRejection="onunhandledRejection".toLowerCase(),o.rejectionHandled="onrejectionHandled".toLowerCase(),function(t,e,r){var n=o[t],i=self[n];return i?("rejectionHandled"===t?i.call(self,r):i.call(self,e,r),!0):!1}}();return"undefined"!=typeof console&&"undefined"!=typeof console.warn&&(l=function(t){console.warn(t)},p.isNode&&t.stderr.isTTY?l=function(e){t.stderr.write("[31m"+e+"[39m\n")}:p.isNode||"string"!=typeof(new Error).stack||(l=function(t){console.warn("%c"+t,"color: red")})),r}},{"./async.js":2,"./util.js":38}],8:[function(t,e,r){"use strict";e.exports=function(e){function r(t,e,r){this._instances=t,this._callback=e,this._promise=r}function n(t,e){var r={},n=s(t).call(r,e);if(n===a)return n;var i=u(r);return i.length?(a.e=new c("Catch filter must inherit from Error or be a simple predicate function\n\n See http://goo.gl/o84o68\n"),a):n}var i=t("./util.js"),o=t("./errors.js"),s=i.tryCatch,a=i.errorObj,u=t("./es5.js").keys,c=o.TypeError;return r.prototype.doFilter=function(t){for(var r=this._callback,i=this._promise,o=i._boundValue(),u=0,c=this._instances.length;c>u;++u){var f=this._instances[u],l=f===Error||null!=f&&f.prototype instanceof Error;if(l&&t instanceof f){var h=s(r).call(o,t);return h===a?(e.e=h.e,e):h}if("function"==typeof f&&!l){var p=n(f,t);if(p===a){t=a.e;break}if(p){var h=s(r).call(o,t);return h===a?(e.e=h.e,e):h}}}return e.e=t,e},r}},{"./errors.js":13,"./es5.js":14,"./util.js":38}],9:[function(t,e,r){"use strict";e.exports=function(t,e,r){function n(){this._trace=new e(o())}function i(){return r()?new n:void 0}function o(){var t=s.length-1;return t>=0?s[t]:void 0}var s=[];return n.prototype._pushContext=function(){r()&&void 0!==this._trace&&s.push(this._trace)},n.prototype._popContext=function(){r()&&void 0!==this._trace&&s.pop()},t.prototype._peekContext=o,t.prototype._pushContext=n.prototype._pushContext,t.prototype._popContext=n.prototype._popContext,i}},{}],10:[function(e,r,n){"use strict";r.exports=function(r,n){var i,o,s=r._getDomain,a=e("./async.js"),u=e("./errors.js").Warning,c=e("./util.js"),f=c.canAttachTrace,l=c.isNode&&(!!t.env.BLUEBIRD_DEBUG||"development"===t.env.NODE_ENV);return c.isNode&&0==t.env.BLUEBIRD_DEBUG&&(l=!1),l&&a.disableTrampolineIfNecessary(),r.prototype._ignoreRejections=function(){this._unsetRejectionIsUnhandled(),this._bitField=16777216|this._bitField},r.prototype._ensurePossibleRejectionHandled=function(){0===(16777216&this._bitField)&&(this._setRejectionIsUnhandled(),a.invokeLater(this._notifyUnhandledRejection,this,void 0))},r.prototype._notifyUnhandledRejectionIsHandled=function(){n.fireRejectionEvent("rejectionHandled",i,void 0,this)},r.prototype._notifyUnhandledRejection=function(){if(this._isRejectionUnhandled()){var t=this._getCarriedStackTrace()||this._settledValue;this._setUnhandledRejectionIsNotified(),n.fireRejectionEvent("unhandledRejection",o,t,this)}},r.prototype._setUnhandledRejectionIsNotified=function(){this._bitField=524288|this._bitField},r.prototype._unsetUnhandledRejectionIsNotified=function(){this._bitField=-524289&this._bitField},r.prototype._isUnhandledRejectionNotified=function(){return(524288&this._bitField)>0},r.prototype._setRejectionIsUnhandled=function(){this._bitField=2097152|this._bitField},r.prototype._unsetRejectionIsUnhandled=function(){this._bitField=-2097153&this._bitField,this._isUnhandledRejectionNotified()&&(this._unsetUnhandledRejectionIsNotified(),this._notifyUnhandledRejectionIsHandled())},r.prototype._isRejectionUnhandled=function(){return(2097152&this._bitField)>0},r.prototype._setCarriedStackTrace=function(t){this._bitField=1048576|this._bitField,this._fulfillmentHandler0=t},r.prototype._isCarryingStackTrace=function(){return(1048576&this._bitField)>0},r.prototype._getCarriedStackTrace=function(){return this._isCarryingStackTrace()?this._fulfillmentHandler0:void 0},r.prototype._captureStackTrace=function(){return l&&(this._trace=new n(this._peekContext())),this},r.prototype._attachExtraTrace=function(t,e){if(l&&f(t)){var r=this._trace;if(void 0!==r&&e&&(r=r._parent),void 0!==r)r.attachExtraTrace(t);else if(!t.__stackCleaned__){var i=n.parseStackAndMessage(t);c.notEnumerableProp(t,"stack",i.message+"\n"+i.stack.join("\n")),c.notEnumerableProp(t,"__stackCleaned__",!0)}}},r.prototype._warn=function(t){var e=new u(t),r=this._peekContext();if(r)r.attachExtraTrace(e);else{var i=n.parseStackAndMessage(e);e.stack=i.message+"\n"+i.stack.join("\n")}n.formatAndLogError(e,"")},r.onPossiblyUnhandledRejection=function(t){var e=s();o="function"==typeof t?null===e?t:e.bind(t):void 0},r.onUnhandledRejectionHandled=function(t){var e=s();i="function"==typeof t?null===e?t:e.bind(t):void 0},r.longStackTraces=function(){if(a.haveItemsQueued()&&l===!1)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/DT1qyG\n");l=n.isSupported(),l&&a.disableTrampolineIfNecessary()},r.hasLongStackTraces=function(){return l&&n.isSupported()},n.isSupported()||(r.longStackTraces=function(){},l=!1),function(){return l}}},{"./async.js":2,"./errors.js":13,"./util.js":38}],11:[function(t,e,r){"use strict";var n=t("./util.js"),i=n.isPrimitive;e.exports=function(t){var e=function(){return this},r=function(){throw this},n=function(){},o=function(){throw void 0},s=function(t,e){return 1===e?function(){throw t}:2===e?function(){return t}:void 0};t.prototype.return=t.prototype.thenReturn=function(r){return void 0===r?this.then(n):i(r)?this._then(s(r,2),void 0,void 0,void 0,void 0):(r instanceof t&&r._ignoreRejections(),this._then(e,void 0,void 0,r,void 0))},t.prototype.throw=t.prototype.thenThrow=function(t){return void 0===t?this.then(o):i(t)?this._then(s(t,1),void 0,void 0,void 0,void 0):this._then(r,void 0,void 0,t,void 0)}}},{"./util.js":38}],12:[function(t,e,r){"use strict";e.exports=function(t,e){var r=t.reduce;t.prototype.each=function(t){return r(this,t,null,e)},t.each=function(t,n){return r(t,n,null,e)}}},{}],13:[function(t,e,r){"use strict";function n(t,e){function r(n){return this instanceof r?(l(this,"message","string"==typeof n?n:e),l(this,"name",t),void(Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):Error.call(this))):new r(n)}return f(r,Error),r}function i(t){return this instanceof i?(l(this,"name","OperationalError"),l(this,"message",t),this.cause=t,this.isOperational=!0,void(t instanceof Error?(l(this,"message",t.message),l(this,"stack",t.stack)):Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor))):new i(t)}var o,s,a=t("./es5.js"),u=a.freeze,c=t("./util.js"),f=c.inherits,l=c.notEnumerableProp,h=n("Warning","warning"),p=n("CancellationError","cancellation error"),d=n("TimeoutError","timeout error"),_=n("AggregateError","aggregate error");try{o=TypeError,s=RangeError}catch(t){o=n("TypeError","type error"),s=n("RangeError","range error")}for(var y="join pop push shift unshift slice filter forEach some every map indexOf lastIndexOf reduce reduceRight sort reverse".split(" "),g=0;g0&&"function"==typeof arguments[e]){t=arguments[e];var n}for(var i=arguments.length,o=new Array(i),s=0;i>s;++s)o[s]=arguments[s];t&&o.pop();var n=new r(o).promise();return void 0!==t?n.spread(t):n}}},{"./util.js":38}],19:[function(t,e,r){"use strict";e.exports=function(e,r,n,i,o){function s(t,e,r,n){this.constructor$(t),this._promise._captureStackTrace();var i=c();this._callback=null===i?e:i.bind(e),this._preservedValues=n===o?new Array(this.length()):null,this._limit=r,this._inFlight=0,this._queue=r>=1?[]:_,f.invoke(a,this,void 0)}function a(){this._init$(void 0,-2)}function u(t,e,r,n){var i="object"==typeof r&&null!==r?r.concurrency:0;return i="number"==typeof i&&isFinite(i)&&i>=1?i:0,new s(t,e,i,n)}var c=e._getDomain,f=t("./async.js"),l=t("./util.js"),h=l.tryCatch,p=l.errorObj,d={},_=[];l.inherits(s,r),s.prototype._init=function(){},s.prototype._promiseFulfilled=function(t,r){var n=this._values,o=this.length(),s=this._preservedValues,a=this._limit;if(n[r]===d){if(n[r]=t,a>=1&&(this._inFlight--,this._drainQueue(),this._isResolved()))return}else{if(a>=1&&this._inFlight>=a)return n[r]=t,void this._queue.push(r);null!==s&&(s[r]=t);var u=this._callback,c=this._promise._boundValue();this._promise._pushContext();var f=h(u).call(c,t,r,o);if(this._promise._popContext(),f===p)return this._reject(f.e);var l=i(f,this._promise);if(l instanceof e){if(l=l._target(),l._isPending())return a>=1&&this._inFlight++,n[r]=d,l._proxyPromiseArray(this,r);if(!l._isFulfilled())return this._reject(l._reason());f=l._value()}n[r]=f}var _=++this._totalResolved;_>=o&&(null!==s?this._filter(n,s):this._resolve(n))},s.prototype._drainQueue=function(){for(var t=this._queue,e=this._limit,r=this._values;t.length>0&&this._inFlighto;++o)t[o]&&(n[i++]=e[o]);n.length=i,this._resolve(n)},s.prototype.preservedValues=function(){return this._preservedValues},e.prototype.map=function(t,e){return"function"!=typeof t?n("fn must be a function\n\n See http://goo.gl/916lJJ\n"):u(this,t,e,null).promise()},e.map=function(t,e,r,i){return"function"!=typeof e?n("fn must be a function\n\n See http://goo.gl/916lJJ\n"):u(t,e,r,i).promise()}}},{"./async.js":2,"./util.js":38}],20:[function(t,e,r){"use strict";e.exports=function(e,r,n,i){var o=t("./util.js"),s=o.tryCatch;e.method=function(t){if("function"!=typeof t)throw new e.TypeError("fn must be a function\n\n See http://goo.gl/916lJJ\n");return function(){var n=new e(r);n._captureStackTrace(),n._pushContext();var i=s(t).apply(this,arguments);return n._popContext(),n._resolveFromSyncValue(i),n}},e.attempt=e.try=function(t,n,a){if("function"!=typeof t)return i("fn must be a function\n\n See http://goo.gl/916lJJ\n");var u=new e(r);u._captureStackTrace(),u._pushContext();var c=o.isArray(n)?s(t).apply(a,n):s(t).call(a,n);return u._popContext(),u._resolveFromSyncValue(c),u},e.prototype._resolveFromSyncValue=function(t){t===o.errorObj?this._rejectCallback(t.e,!1,!0):this._resolveCallback(t,!0)}}},{"./util.js":38}],21:[function(t,e,r){"use strict";e.exports=function(e){function r(t,e){var r=this;if(!o.isArray(t))return n.call(r,t,e);var i=a(e).apply(r._boundValue(),[null].concat(t));i===u&&s.throwLater(i.e)}function n(t,e){var r=this,n=r._boundValue(),i=void 0===t?a(e).call(n,null):a(e).call(n,null,t);i===u&&s.throwLater(i.e)}function i(t,e){var r=this;if(!t){var n=r._target(),i=n._getCarriedStackTrace();i.cause=t,t=i}var o=a(e).call(r._boundValue(),t);o===u&&s.throwLater(o.e)}var o=t("./util.js"),s=t("./async.js"),a=o.tryCatch,u=o.errorObj;e.prototype.asCallback=e.prototype.nodeify=function(t,e){if("function"==typeof t){var o=n;void 0!==e&&Object(e).spread&&(o=r),this._then(o,i,void 0,this,t)}return this}}},{"./async.js":2,"./util.js":38}],22:[function(t,e,r){"use strict";e.exports=function(e,r){var n=t("./util.js"),i=t("./async.js"),o=n.tryCatch,s=n.errorObj;e.prototype.progressed=function(t){return this._then(void 0,void 0,t,void 0,void 0)},e.prototype._progress=function(t){this._isFollowingOrFulfilledOrRejected()||this._target()._progressUnchecked(t)},e.prototype._progressHandlerAt=function(t){return 0===t?this._progressHandler0:this[(t<<2)+t-5+2]},e.prototype._doProgressWith=function(t){var r=t.value,i=t.handler,a=t.promise,u=t.receiver,c=o(i).call(u,r);if(c===s){if(null!=c.e&&"StopProgressPropagation"!==c.e.name){var f=n.canAttachTrace(c.e)?c.e:new Error(n.toString(c.e));a._attachExtraTrace(f),a._progress(c.e)}}else c instanceof e?c._then(a._progress,null,null,a,void 0):a._progress(c)},e.prototype._progressUnchecked=function(t){for(var n=this._length(),o=this._progress,s=0;n>s;s++){var a=this._progressHandlerAt(s),u=this._promiseAt(s);if(u instanceof e)"function"==typeof a?i.invoke(this._doProgressWith,this,{handler:a,promise:u,receiver:this._receiverAt(s),value:t}):i.invoke(o,u,t);else{var c=this._receiverAt(s);"function"==typeof a?a.call(c,t,u):c instanceof r&&!c._isResolved()&&c._promiseProgressed(t,u)}}}}},{"./async.js":2,"./util.js":38}],23:[function(e,r,n){"use strict";r.exports=function(){function r(t){if("function"!=typeof t)throw new h("the promise constructor requires a resolver function\n\n See http://goo.gl/EC22Yn\n");if(this.constructor!==r)throw new h("the promise constructor cannot be invoked directly\n\n See http://goo.gl/KsIlge\n");this._bitField=0,this._fulfillmentHandler0=void 0,this._rejectionHandler0=void 0,this._progressHandler0=void 0,this._promise0=void 0,this._receiver0=void 0,this._settledValue=void 0,t!==p&&this._resolveFromResolver(t)}function n(t){var e=new r(p);e._fulfillmentHandler0=t,e._rejectionHandler0=t,e._progressHandler0=t,e._promise0=t,e._receiver0=t,e._settledValue=t}var i,o=function(){return new h("circular promise resolution chain\n\n See http://goo.gl/LhFpo0\n")},s=function(){return new r.PromiseInspection(this._target())},a=function(t){return r.reject(new h(t))},u=e("./util.js");i=u.isNode?function(){var e=t.domain;return void 0===e&&(e=null),e}:function(){return null},u.notEnumerableProp(r,"_getDomain",i);var c={},f=e("./async.js"),l=e("./errors.js"),h=r.TypeError=l.TypeError;r.RangeError=l.RangeError,r.CancellationError=l.CancellationError,r.TimeoutError=l.TimeoutError,r.OperationalError=l.OperationalError,r.RejectionError=l.OperationalError,r.AggregateError=l.AggregateError;var p=function(){},d={},_={e:null},y=e("./thenables.js")(r,p),g=e("./promise_array.js")(r,p,y,a),v=e("./captured_trace.js")(),m=e("./debuggability.js")(r,v),b=e("./context.js")(r,v,m),w=e("./catch_filter.js")(_),E=e("./promise_resolver.js"),O=E._nodebackForPromise,A=u.errorObj,S=u.tryCatch;return r.prototype.toString=function(){return"[object Promise]"},r.prototype.caught=r.prototype.catch=function(t){var e=arguments.length;if(e>1){var n,i=new Array(e-1),o=0;for(n=0;e-1>n;++n){var s=arguments[n];if("function"!=typeof s)return r.reject(new h("Catch filter must inherit from Error or be a simple predicate function\n\n See http://goo.gl/o84o68\n"));i[o++]=s}i.length=o,t=arguments[n];var a=new w(i,t,this);return this._then(void 0,a.doFilter,void 0,a,void 0)}return this._then(void 0,t,void 0,void 0,void 0)},r.prototype.reflect=function(){return this._then(s,s,void 0,this,void 0)},r.prototype.then=function(t,e,r){if(m()&&arguments.length>0&&"function"!=typeof t&&"function"!=typeof e){var n=".then() only accepts functions but was passed: "+u.classString(t);arguments.length>1&&(n+=", "+u.classString(e)),this._warn(n)}return this._then(t,e,r,void 0,void 0)},r.prototype.done=function(t,e,r){var n=this._then(t,e,r,void 0,void 0);n._setIsFinal()},r.prototype.spread=function(t,e){return this.all()._then(t,e,void 0,d,void 0)},r.prototype.isCancellable=function(){return!this.isResolved()&&this._cancellable()},r.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},r.prototype.all=function(){return new g(this).promise()},r.prototype.error=function(t){return this.caught(u.originatesFromRejection,t)},r.is=function(t){return t instanceof r},r.fromNode=function(t){var e=new r(p),n=S(t)(O(e));return n===A&&e._rejectCallback(n.e,!0,!0),e},r.all=function(t){return new g(t).promise()},r.defer=r.pending=function(){var t=new r(p);return new E(t)},r.cast=function(t){var e=y(t);if(!(e instanceof r)){var n=e;e=new r(p),e._fulfillUnchecked(n)}return e},r.resolve=r.fulfilled=r.cast,r.reject=r.rejected=function(t){var e=new r(p);return e._captureStackTrace(),e._rejectCallback(t,!0),e},r.setScheduler=function(t){if("function"!=typeof t)throw new h("fn must be a function\n\n See http://goo.gl/916lJJ\n");var e=f._schedule;return f._schedule=t,e},r.prototype._then=function(t,e,n,o,s){var a=void 0!==s,u=a?s:new r(p);a||(u._propagateFrom(this,5),u._captureStackTrace());var c=this._target();c!==this&&(void 0===o&&(o=this._boundTo),a||u._setIsMigrated());var l=c._addCallbacks(t,e,n,u,o,i());return c._isResolved()&&!c._isSettlePromisesQueued()&&f.invoke(c._settlePromiseAtPostResolution,c,l),
+u},r.prototype._settlePromiseAtPostResolution=function(t){this._isRejectionUnhandled()&&this._unsetRejectionIsUnhandled(),this._settlePromiseAt(t)},r.prototype._length=function(){return 131071&this._bitField},r.prototype._isFollowingOrFulfilledOrRejected=function(){return(939524096&this._bitField)>0},r.prototype._isFollowing=function(){return 536870912===(536870912&this._bitField)},r.prototype._setLength=function(t){this._bitField=-131072&this._bitField|131071&t},r.prototype._setFulfilled=function(){this._bitField=268435456|this._bitField},r.prototype._setRejected=function(){this._bitField=134217728|this._bitField},r.prototype._setFollowing=function(){this._bitField=536870912|this._bitField},r.prototype._setIsFinal=function(){this._bitField=33554432|this._bitField},r.prototype._isFinal=function(){return(33554432&this._bitField)>0},r.prototype._cancellable=function(){return(67108864&this._bitField)>0},r.prototype._setCancellable=function(){this._bitField=67108864|this._bitField},r.prototype._unsetCancellable=function(){this._bitField=-67108865&this._bitField},r.prototype._setIsMigrated=function(){this._bitField=4194304|this._bitField},r.prototype._unsetIsMigrated=function(){this._bitField=-4194305&this._bitField},r.prototype._isMigrated=function(){return(4194304&this._bitField)>0},r.prototype._receiverAt=function(t){var e=0===t?this._receiver0:this[5*t-5+4];if(e!==c)return void 0===e&&this._isBound()?this._boundValue():e},r.prototype._promiseAt=function(t){return 0===t?this._promise0:this[5*t-5+3]},r.prototype._fulfillmentHandlerAt=function(t){return 0===t?this._fulfillmentHandler0:this[5*t-5+0]},r.prototype._rejectionHandlerAt=function(t){return 0===t?this._rejectionHandler0:this[5*t-5+1]},r.prototype._boundValue=function(){var t=this._boundTo;return void 0!==t&&t instanceof r?t.isFulfilled()?t.value():void 0:t},r.prototype._migrateCallbacks=function(t,e){var n=t._fulfillmentHandlerAt(e),i=t._rejectionHandlerAt(e),o=t._progressHandlerAt(e),s=t._promiseAt(e),a=t._receiverAt(e);s instanceof r&&s._setIsMigrated(),void 0===a&&(a=c),this._addCallbacks(n,i,o,s,a,null)},r.prototype._addCallbacks=function(t,e,r,n,i,o){var s=this._length();if(s>=131066&&(s=0,this._setLength(0)),0===s)this._promise0=n,void 0!==i&&(this._receiver0=i),"function"!=typeof t||this._isCarryingStackTrace()||(this._fulfillmentHandler0=null===o?t:o.bind(t)),"function"==typeof e&&(this._rejectionHandler0=null===o?e:o.bind(e)),"function"==typeof r&&(this._progressHandler0=null===o?r:o.bind(r));else{var a=5*s-5;this[a+3]=n,this[a+4]=i,"function"==typeof t&&(this[a+0]=null===o?t:o.bind(t)),"function"==typeof e&&(this[a+1]=null===o?e:o.bind(e)),"function"==typeof r&&(this[a+2]=null===o?r:o.bind(r))}return this._setLength(s+1),s},r.prototype._setProxyHandlers=function(t,e){var r=this._length();if(r>=131066&&(r=0,this._setLength(0)),0===r)this._promise0=e,this._receiver0=t;else{var n=5*r-5;this[n+3]=e,this[n+4]=t}this._setLength(r+1)},r.prototype._proxyPromiseArray=function(t,e){this._setProxyHandlers(t,e)},r.prototype._resolveCallback=function(t,e){if(!this._isFollowingOrFulfilledOrRejected()){if(t===this)return this._rejectCallback(o(),!1,!0);var n=y(t,this);if(!(n instanceof r))return this._fulfill(t);var i=1|(e?4:0);this._propagateFrom(n,i);var s=n._target();if(s._isPending()){for(var a=this._length(),u=0;a>u;++u)s._migrateCallbacks(this,u);this._setFollowing(),this._setLength(0),this._setFollowee(s)}else s._isFulfilled()?this._fulfillUnchecked(s._value()):this._rejectUnchecked(s._reason(),s._getCarriedStackTrace())}},r.prototype._rejectCallback=function(t,e,r){r||u.markAsOriginatingFromRejection(t);var n=u.ensureErrorObject(t),i=n===t;this._attachExtraTrace(n,e?i:!1),this._reject(t,i?void 0:n)},r.prototype._resolveFromResolver=function(t){var e=this;this._captureStackTrace(),this._pushContext();var r=!0,n=S(t)(function(t){null!==e&&(e._resolveCallback(t),e=null)},function(t){null!==e&&(e._rejectCallback(t,r),e=null)});r=!1,this._popContext(),void 0!==n&&n===A&&null!==e&&(e._rejectCallback(n.e,!0,!0),e=null)},r.prototype._settlePromiseFromHandler=function(t,e,r,n){if(!n._isRejected()){n._pushContext();var i;if(i=e!==d||this._isRejected()?S(t).call(e,r):S(t).apply(this._boundValue(),r),n._popContext(),i===A||i===n||i===_){var s=i===n?o():i.e;n._rejectCallback(s,!1,!0)}else n._resolveCallback(i)}},r.prototype._target=function(){for(var t=this;t._isFollowing();)t=t._followee();return t},r.prototype._followee=function(){return this._rejectionHandler0},r.prototype._setFollowee=function(t){this._rejectionHandler0=t},r.prototype._cleanValues=function(){this._cancellable()&&(this._cancellationParent=void 0)},r.prototype._propagateFrom=function(t,e){(1&e)>0&&t._cancellable()&&(this._setCancellable(),this._cancellationParent=t),(4&e)>0&&t._isBound()&&this._setBoundTo(t._boundTo)},r.prototype._fulfill=function(t){this._isFollowingOrFulfilledOrRejected()||this._fulfillUnchecked(t)},r.prototype._reject=function(t,e){this._isFollowingOrFulfilledOrRejected()||this._rejectUnchecked(t,e)},r.prototype._settlePromiseAt=function(t){var e=this._promiseAt(t),n=e instanceof r;if(n&&e._isMigrated())return e._unsetIsMigrated(),f.invoke(this._settlePromiseAt,this,t);var i=this._isFulfilled()?this._fulfillmentHandlerAt(t):this._rejectionHandlerAt(t),o=this._isCarryingStackTrace()?this._getCarriedStackTrace():void 0,s=this._settledValue,a=this._receiverAt(t);this._clearCallbackDataAtIndex(t),"function"==typeof i?n?this._settlePromiseFromHandler(i,a,s,e):i.call(a,s,e):a instanceof g?a._isResolved()||(this._isFulfilled()?a._promiseFulfilled(s,e):a._promiseRejected(s,e)):n&&(this._isFulfilled()?e._fulfill(s):e._reject(s,o)),t>=4&&4===(31&t)&&f.invokeLater(this._setLength,this,0)},r.prototype._clearCallbackDataAtIndex=function(t){if(0===t)this._isCarryingStackTrace()||(this._fulfillmentHandler0=void 0),this._rejectionHandler0=this._progressHandler0=this._receiver0=this._promise0=void 0;else{var e=5*t-5;this[e+3]=this[e+4]=this[e+0]=this[e+1]=this[e+2]=void 0}},r.prototype._isSettlePromisesQueued=function(){return-1073741824===(-1073741824&this._bitField)},r.prototype._setSettlePromisesQueued=function(){this._bitField=-1073741824|this._bitField},r.prototype._unsetSettlePromisesQueued=function(){this._bitField=1073741823&this._bitField},r.prototype._queueSettlePromises=function(){f.settlePromises(this),this._setSettlePromisesQueued()},r.prototype._fulfillUnchecked=function(t){if(t===this){var e=o();return this._attachExtraTrace(e),this._rejectUnchecked(e,void 0)}this._setFulfilled(),this._settledValue=t,this._cleanValues(),this._length()>0&&this._queueSettlePromises()},r.prototype._rejectUncheckedCheckError=function(t){var e=u.ensureErrorObject(t);this._rejectUnchecked(t,e===t?void 0:e)},r.prototype._rejectUnchecked=function(t,e){if(t===this){var r=o();return this._attachExtraTrace(r),this._rejectUnchecked(r)}return this._setRejected(),this._settledValue=t,this._cleanValues(),this._isFinal()?void f.throwLater(function(t){throw"stack"in t&&f.invokeFirst(v.unhandledRejection,void 0,t),t},void 0===e?t:e):(void 0!==e&&e!==t&&this._setCarriedStackTrace(e),void(this._length()>0?this._queueSettlePromises():this._ensurePossibleRejectionHandled()))},r.prototype._settlePromises=function(){this._unsetSettlePromisesQueued();for(var t=this._length(),e=0;t>e;e++)this._settlePromiseAt(e)},u.notEnumerableProp(r,"_makeSelfResolutionError",o),e("./progress.js")(r,g),e("./method.js")(r,p,y,a),e("./bind.js")(r,p,y),e("./finally.js")(r,_,y),e("./direct_resolve.js")(r),e("./synchronous_inspection.js")(r),e("./join.js")(r,g,y,p),r.Promise=r,e("./map.js")(r,g,a,y,p),e("./cancel.js")(r),e("./using.js")(r,a,y,b),e("./generators.js")(r,a,p,y),e("./nodeify.js")(r),e("./call_get.js")(r),e("./props.js")(r,g,y,a),e("./race.js")(r,p,y,a),e("./reduce.js")(r,g,a,y,p),e("./settle.js")(r,g),e("./some.js")(r,g,a),e("./promisify.js")(r,p),e("./any.js")(r),e("./each.js")(r,p),e("./timers.js")(r,p),e("./filter.js")(r,p),u.toFastProperties(r),u.toFastProperties(r.prototype),n({a:1}),n({b:2}),n({c:3}),n(1),n(function(){}),n(void 0),n(!1),n(new r(p)),v.setBounds(f.firstLineError,u.lastLineError),r}},{"./any.js":1,"./async.js":2,"./bind.js":3,"./call_get.js":5,"./cancel.js":6,"./captured_trace.js":7,"./catch_filter.js":8,"./context.js":9,"./debuggability.js":10,"./direct_resolve.js":11,"./each.js":12,"./errors.js":13,"./filter.js":15,"./finally.js":16,"./generators.js":17,"./join.js":18,"./map.js":19,"./method.js":20,"./nodeify.js":21,"./progress.js":22,"./promise_array.js":24,"./promise_resolver.js":25,"./promisify.js":26,"./props.js":27,"./race.js":29,"./reduce.js":30,"./settle.js":32,"./some.js":33,"./synchronous_inspection.js":34,"./thenables.js":35,"./timers.js":36,"./using.js":37,"./util.js":38}],24:[function(t,e,r){"use strict";e.exports=function(e,r,n,i){function o(t){switch(t){case-2:return[];case-3:return{}}}function s(t){var n,i=this._promise=new e(r);t instanceof e&&(n=t,i._propagateFrom(n,5)),this._values=t,this._length=0,this._totalResolved=0,this._init(void 0,-2)}var a=t("./util.js"),u=a.isArray;return s.prototype.length=function(){return this._length},s.prototype.promise=function(){return this._promise},s.prototype._init=function t(r,s){var a=n(this._values,this._promise);if(a instanceof e){if(a=a._target(),this._values=a,!a._isFulfilled())return a._isPending()?void a._then(t,this._reject,void 0,this,s):void this._reject(a._reason());if(a=a._value(),!u(a)){var c=new e.TypeError("expecting an array, a promise or a thenable\n\n See http://goo.gl/s8MMhc\n");return void this.__hardReject__(c)}}else if(!u(a))return void this._promise._reject(i("expecting an array, a promise or a thenable\n\n See http://goo.gl/s8MMhc\n")._reason());if(0===a.length)return void(-5===s?this._resolveEmptyArray():this._resolve(o(s)));var f=this.getActualLength(a.length);this._length=f,this._values=this.shouldCopyValues()?new Array(f):this._values;for(var l=this._promise,h=0;f>h;++h){var p=this._isResolved(),d=n(a[h],l);d instanceof e?(d=d._target(),p?d._ignoreRejections():d._isPending()?d._proxyPromiseArray(this,h):d._isFulfilled()?this._promiseFulfilled(d._value(),h):this._promiseRejected(d._reason(),h)):p||this._promiseFulfilled(d,h)}},s.prototype._isResolved=function(){return null===this._values},s.prototype._resolve=function(t){this._values=null,this._promise._fulfill(t)},s.prototype.__hardReject__=s.prototype._reject=function(t){this._values=null,this._promise._rejectCallback(t,!1,!0)},s.prototype._promiseProgressed=function(t,e){this._promise._progress({index:e,value:t})},s.prototype._promiseFulfilled=function(t,e){this._values[e]=t;var r=++this._totalResolved;r>=this._length&&this._resolve(this._values)},s.prototype._promiseRejected=function(t,e){this._totalResolved++,this._reject(t)},s.prototype.shouldCopyValues=function(){return!0},s.prototype.getActualLength=function(t){return t},s}},{"./util.js":38}],25:[function(t,e,r){"use strict";function n(t){return t instanceof Error&&p.getPrototypeOf(t)===Error.prototype}function i(t){var e;if(n(t)){e=new l(t),e.name=t.name,e.message=t.message,e.stack=t.stack;for(var r=p.keys(t),i=0;i2){for(var o=arguments.length,s=new Array(o-1),a=1;o>a;++a)s[a-1]=arguments[a];t._fulfill(s)}else t._fulfill(r);t=null}}}var s,a=t("./util.js"),u=a.maybeWrapAsError,c=t("./errors.js"),f=c.TimeoutError,l=c.OperationalError,h=a.haveGetters,p=t("./es5.js"),d=/^(?:name|message|stack|cause)$/;if(s=h?function(t){this.promise=t}:function(t){this.promise=t,this.asCallback=o(t),this.callback=this.asCallback},h){var _={get:function(){return o(this.promise)}};p.defineProperty(s.prototype,"asCallback",_),p.defineProperty(s.prototype,"callback",_)}s._nodebackForPromise=o,s.prototype.toString=function(){return"[object PromiseResolver]"},s.prototype.resolve=s.prototype.fulfill=function(t){if(!(this instanceof s))throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\n\n See http://goo.gl/sdkXL9\n");this.promise._resolveCallback(t)},s.prototype.reject=function(t){if(!(this instanceof s))throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\n\n See http://goo.gl/sdkXL9\n");this.promise._rejectCallback(t)},s.prototype.progress=function(t){if(!(this instanceof s))throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\n\n See http://goo.gl/sdkXL9\n");this.promise._progress(t)},s.prototype.cancel=function(t){this.promise.cancel(t)},s.prototype.timeout=function(){this.reject(new f("timeout"))},s.prototype.isResolved=function(){return this.promise.isResolved()},s.prototype.toJSON=function(){return this.promise.toJSON()},e.exports=s},{"./errors.js":13,"./es5.js":14,"./util.js":38}],26:[function(t,e,r){"use strict";e.exports=function(e,r){function n(t){return!E.test(t)}function i(t){try{return t.__isPromisified__===!0}catch(t){return!1}}function o(t,e,r){var n=p.getDataPropertyOrDefault(t,e+r,b);return n?i(n):!1}function s(t,e,r){for(var n=0;ns;s+=2){var c=o[s],f=o[s+1],l=c+e;if(n===S)t[l]=S(c,h,c,f,e);else{var d=n(f,function(){return S(c,h,c,f,e)});p.notEnumerableProp(d,"__isPromisified__",!0),t[l]=d}}return p.toFastProperties(t),t}function f(t,e){return S(t,e,void 0,t)}var l,h={},p=t("./util.js"),d=t("./promise_resolver.js")._nodebackForPromise,_=p.withAppended,y=p.maybeWrapAsError,g=p.canEvaluate,v=t("./errors").TypeError,m="Async",b={__isPromisified__:!0},w=["arity","length","name","arguments","caller","callee","prototype","__isPromisified__"],E=new RegExp("^(?:"+w.join("|")+")$"),O=function(t){return p.isIdentifier(t)&&"_"!==t.charAt(0)&&"constructor"!==t},A=function(t){return t.replace(/([$])/,"\\$")},S=g?l:u;e.promisify=function(t,e){if("function"!=typeof t)throw new v("fn must be a function\n\n See http://goo.gl/916lJJ\n");if(i(t))return t;var r=f(t,arguments.length<2?h:e);return p.copyDescriptors(t,r,n),r},e.promisifyAll=function(t,e){if("function"!=typeof t&&"object"!=typeof t)throw new v("the target of promisifyAll must be an object or a function\n\n See http://goo.gl/9ITlV0\n");e=Object(e);var r=e.suffix;"string"!=typeof r&&(r=m);var n=e.filter;"function"!=typeof n&&(n=O);var i=e.promisifier;if("function"!=typeof i&&(i=S),!p.isIdentifier(r))throw new RangeError("suffix must be a valid identifier\n\n See http://goo.gl/8FZo5V\n");for(var o=p.inheritedDataKeys(t),s=0;si;++i){var o=e[i];n[i]=t[o],n[i+r]=o}this.constructor$(n)}function s(t){var r,s=n(t);return u(s)?(r=s instanceof e?s._then(e.props,void 0,void 0,void 0,void 0):new o(s).promise(),s instanceof e&&r._propagateFrom(s,4),r):i("cannot await properties of a non-object\n\n See http://goo.gl/OsFKC8\n")}var a=t("./util.js"),u=a.isObject,c=t("./es5.js");a.inherits(o,r),o.prototype._init=function(){this._init$(void 0,-3)},o.prototype._promiseFulfilled=function(t,e){this._values[e]=t;var r=++this._totalResolved;if(r>=this._length){for(var n={},i=this.length(),o=0,s=this.length();s>o;++o)n[this._values[o+i]]=this._values[o];this._resolve(n)}},o.prototype._promiseProgressed=function(t,e){this._promise._progress({key:this._values[e+this.length()],value:t})},o.prototype.shouldCopyValues=function(){return!1},o.prototype.getActualLength=function(t){return t>>1},e.prototype.props=function(){return s(this)},e.props=function(t){return s(t)}}},{"./es5.js":14,"./util.js":38}],28:[function(t,e,r){"use strict";function n(t,e,r,n,i){for(var o=0;i>o;++o)r[o+n]=t[o+e],t[o+e]=void 0}function i(t){this._capacity=t,this._length=0,this._front=0}i.prototype._willBeOverCapacity=function(t){return this._capacityh;++h){var d=t[h];(void 0!==d||h in t)&&e.cast(d)._then(f,l,void 0,c,null)}return c}var s=t("./util.js").isArray,a=function(t){return t.then(function(e){return o(e,t)})};e.race=function(t){return o(t,void 0)},e.prototype.race=function(){return o(this,void 0)}}},{"./util.js":38}],30:[function(t,e,r){"use strict";e.exports=function(e,r,n,i,o){function s(t,r,n,s){this.constructor$(t),this._promise._captureStackTrace(),this._preservedValues=s===o?[]:null,this._zerothIsAccum=void 0===n,this._gotAccum=!1,this._reducingIndex=this._zerothIsAccum?1:0,this._valuesPhase=void 0;var u=i(n,this._promise),l=!1,h=u instanceof e;h&&(u=u._target(),u._isPending()?u._proxyPromiseArray(this,-1):u._isFulfilled()?(n=u._value(),this._gotAccum=!0):(this._reject(u._reason()),l=!0)),h||this._zerothIsAccum||(this._gotAccum=!0);var p=c();this._callback=null===p?r:p.bind(r),this._accum=n,l||f.invoke(a,this,void 0)}function a(){this._init$(void 0,-5)}function u(t,e,r,i){if("function"!=typeof e)return n("fn must be a function\n\n See http://goo.gl/916lJJ\n");var o=new s(t,e,r,i);return o.promise()}var c=e._getDomain,f=t("./async.js"),l=t("./util.js"),h=l.tryCatch,p=l.errorObj;l.inherits(s,r),s.prototype._init=function(){},s.prototype._resolveEmptyArray=function(){(this._gotAccum||this._zerothIsAccum)&&this._resolve(null!==this._preservedValues?[]:this._accum)},s.prototype._promiseFulfilled=function(t,r){var n=this._values;n[r]=t;var o,s=this.length(),a=this._preservedValues,u=null!==a,c=this._gotAccum,f=this._valuesPhase;if(!f)for(f=this._valuesPhase=new Array(s),o=0;s>o;++o)f[o]=0;if(o=f[r],0===r&&this._zerothIsAccum?(this._accum=t,this._gotAccum=c=!0,f[r]=0===o?1:2):-1===r?(this._accum=t,this._gotAccum=c=!0):0===o?f[r]=1:(f[r]=2,this._accum=t),c){for(var l,d=this._callback,_=this._promise._boundValue(),y=this._reducingIndex;s>y;++y)if(o=f[y],2!==o){if(1!==o)return;if(t=n[y],this._promise._pushContext(),u?(a.push(t),l=h(d).call(_,t,y,s)):l=h(d).call(_,this._accum,t,y,s),this._promise._popContext(),l===p)return this._reject(l.e);var g=i(l,this._promise);if(g instanceof e){if(g=g._target(),g._isPending())return f[y]=4,g._proxyPromiseArray(this,y);if(!g._isFulfilled())return this._reject(g._reason());l=g._value()}this._reducingIndex=y+1,this._accum=l}else this._reducingIndex=y+1;this._resolve(u?a:this._accum)}},e.prototype.reduce=function(t,e){return u(this,t,e,null)},e.reduce=function(t,e,r,n){return u(t,e,r,n)}}},{"./async.js":2,"./util.js":38}],31:[function(e,r,i){"use strict";var o,s=e("./util"),a=function(){throw new Error("No async scheduler available\n\n See http://goo.gl/m3OTXk\n")};if(s.isNode&&"undefined"==typeof MutationObserver){var u=n.setImmediate,c=t.nextTick;o=s.isRecentNode?function(t){u.call(n,t)}:function(e){c.call(t,e)}}else"undefined"==typeof MutationObserver||"undefined"!=typeof window&&window.navigator&&window.navigator.standalone?o="undefined"!=typeof setImmediate?function(t){setImmediate(t)}:"undefined"!=typeof setTimeout?function(t){setTimeout(t,0)}:a:(o=function(t){var e=document.createElement("div"),r=new MutationObserver(t);return r.observe(e,{attributes:!0}),function(){e.classList.toggle("foo")}},o.isStatic=!0);r.exports=o},{"./util":38}],32:[function(t,e,r){"use strict";e.exports=function(e,r){function n(t){this.constructor$(t)}var i=e.PromiseInspection,o=t("./util.js");o.inherits(n,r),n.prototype._promiseResolved=function(t,e){this._values[t]=e;var r=++this._totalResolved;r>=this._length&&this._resolve(this._values)},n.prototype._promiseFulfilled=function(t,e){var r=new i;r._bitField=268435456,r._settledValue=t,this._promiseResolved(e,r)},n.prototype._promiseRejected=function(t,e){var r=new i;r._bitField=134217728,r._settledValue=t,this._promiseResolved(e,r)},e.settle=function(t){return new n(t).promise()},e.prototype.settle=function(){return new n(this).promise()}}},{"./util.js":38}],33:[function(t,e,r){"use strict";e.exports=function(e,r,n){function i(t){this.constructor$(t),this._howMany=0,this._unwrap=!1,this._initialized=!1}function o(t,e){if((0|e)!==e||0>e)return n("expecting a positive integer\n\n See http://goo.gl/1wAmHx\n");var r=new i(t),o=r.promise();return r.setHowMany(e),r.init(),o}var s=t("./util.js"),a=t("./errors.js").RangeError,u=t("./errors.js").AggregateError,c=s.isArray;s.inherits(i,r),i.prototype._init=function(){if(this._initialized){if(0===this._howMany)return void this._resolve([]);this._init$(void 0,-5);var t=c(this._values);!this._isResolved()&&t&&this._howMany>this._canPossiblyFulfill()&&this._reject(this._getRangeError(this.length()))}},i.prototype.init=function(){this._initialized=!0,this._init()},i.prototype.setUnwrap=function(){this._unwrap=!0},i.prototype.howMany=function(){return this._howMany},i.prototype.setHowMany=function(t){this._howMany=t},i.prototype._promiseFulfilled=function(t){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))},i.prototype._promiseRejected=function(t){if(this._addRejected(t),this.howMany()>this._canPossiblyFulfill()){for(var e=new u,r=this.length();r0},e.prototype.isRejected=t.prototype._isRejected=function(){return(134217728&this._bitField)>0},e.prototype.isPending=t.prototype._isPending=function(){return 0===(402653184&this._bitField)},e.prototype.isResolved=t.prototype._isResolved=function(){return(402653184&this._bitField)>0},t.prototype.isPending=function(){return this._target()._isPending()},t.prototype.isRejected=function(){return this._target()._isRejected()},t.prototype.isFulfilled=function(){return this._target()._isFulfilled()},t.prototype.isResolved=function(){return this._target()._isResolved()},t.prototype._value=function(){return this._settledValue},t.prototype._reason=function(){return this._unsetRejectionIsUnhandled(),this._settledValue},t.prototype.value=function(){var t=this._target();if(!t.isFulfilled())throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\n\n See http://goo.gl/hc1DLj\n");return t._settledValue},t.prototype.reason=function(){var t=this._target();if(!t.isRejected())throw new TypeError("cannot get rejection reason of a non-rejected promise\n\n See http://goo.gl/hPuiwB\n");return t._unsetRejectionIsUnhandled(),t._settledValue},t.PromiseInspection=e}},{}],35:[function(t,e,r){"use strict";e.exports=function(e,r){function n(t,n){if(c(t)){if(t instanceof e)return t;if(o(t)){var f=new e(r);return t._then(f._fulfillUnchecked,f._rejectUncheckedCheckError,f._progressUnchecked,f,null),f}var l=a.tryCatch(i)(t);if(l===u){n&&n._pushContext();var f=e.reject(l.e);return n&&n._popContext(),f}if("function"==typeof l)return s(t,l,n)}return t}function i(t){return t.then}function o(t){return f.call(t,"_promise0")}function s(t,n,i){function o(t){f&&(f._resolveCallback(t),f=null)}function s(t){f&&(f._rejectCallback(t,h,!0),f=null)}function c(t){f&&"function"==typeof f._progress&&f._progress(t)}var f=new e(r),l=f;i&&i._pushContext(),f._captureStackTrace(),i&&i._popContext();var h=!0,p=a.tryCatch(n).call(t,o,s,c);return h=!1,f&&p===u&&(f._rejectCallback(p.e,!0,!0),f=null),l}var a=t("./util.js"),u=a.errorObj,c=a.isObject,f={}.hasOwnProperty;return n}},{"./util.js":38}],36:[function(t,e,r){"use strict";e.exports=function(e,r){function n(t){var e=this;return e instanceof Number&&(e=+e),clearTimeout(e),t}function i(t){var e=this;throw e instanceof Number&&(e=+e),clearTimeout(e),t}var o=t("./util.js"),s=e.TimeoutError,a=function(t,e){if(t.isPending()){var r;!o.isPrimitive(e)&&e instanceof Error?r=e:("string"!=typeof e&&(e="operation timed out"),r=new s(e)),o.markAsOriginatingFromRejection(r),t._attachExtraTrace(r),t._cancel(r)}},u=function(t){return c(+this).thenReturn(t)},c=e.delay=function(t,n){if(void 0===n){n=t,t=void 0;var i=new e(r);return setTimeout(function(){i._fulfill()},n),i}return n=+n,e.resolve(t)._then(u,null,null,n,void 0)};e.prototype.delay=function(t){return c(this,t)},e.prototype.timeout=function(t,e){t=+t;var r=this.then().cancellable();r._cancellationParent=this;var o=setTimeout(function(){a(r,e)},t);return r._then(n,i,void 0,o,void 0)}}},{"./util.js":38}],37:[function(t,e,r){"use strict";e.exports=function(e,r,n,i){function o(t){for(var r=t.length,n=0;r>n;++n){var i=t[n];if(i.isRejected())return e.reject(i.error());t[n]=i._settledValue}return t}function s(t){setTimeout(function(){throw t},0)}function a(t){var e=n(t);return e!==t&&"function"==typeof t._isDisposable&&"function"==typeof t._getDisposer&&t._isDisposable()&&e._setDisposable(t._getDisposer()),e}function u(t,r){function i(){if(o>=u)return c.resolve();var f=a(t[o++]);if(f instanceof e&&f._isDisposable()){try{f=n(f._getDisposer().tryDispose(r),t.promise)}catch(t){return s(t)}if(f instanceof e)return f._then(i,s,null,null,null)}i()}var o=0,u=t.length,c=e.defer();return i(),c.promise}function c(t){var e=new y;return e._settledValue=t,e._bitField=268435456,u(this,e).thenReturn(t)}function f(t){var e=new y;return e._settledValue=t,e._bitField=134217728,u(this,e).thenThrow(t)}function l(t,e,r){this._data=t,this._promise=e,this._context=r}function h(t,e,r){this.constructor$(t,e,r)}function p(t){return l.isDisposer(t)?(this.resources[this.index]._setDisposable(t),t.promise()):t}var d=t("./errors.js").TypeError,_=t("./util.js").inherits,y=e.PromiseInspection;l.prototype.data=function(){return this._data},l.prototype.promise=function(){return this._promise},l.prototype.resource=function(){return this.promise().isFulfilled()?this.promise().value():null},l.prototype.tryDispose=function(t){var e=this.resource(),r=this._context;void 0!==r&&r._pushContext();var n=null!==e?this.doDispose(e,t):null;return void 0!==r&&r._popContext(),this._promise._unsetDisposable(),this._data=null,n},l.isDisposer=function(t){return null!=t&&"function"==typeof t.resource&&"function"==typeof t.tryDispose},_(h,l),h.prototype.doDispose=function(t,e){var r=this.data();return r.call(t,t,e)},e.using=function(){var t=arguments.length;if(2>t)return r("you must pass at least 2 arguments to Promise.using");var i=arguments[t-1];if("function"!=typeof i)return r("fn must be a function\n\n See http://goo.gl/916lJJ\n");var s,a=!0;2===t&&Array.isArray(arguments[0])?(s=arguments[0],t=s.length,a=!1):(s=arguments,t--);for(var u=new Array(t),h=0;t>h;++h){var d=s[h];if(l.isDisposer(d)){var _=d;d=d.promise(),d._setDisposable(_)}else{var y=n(d);y instanceof e&&(d=y._then(p,null,null,{resources:u,index:h},void 0))}u[h]=d}var g=e.settle(u).then(o).then(function(t){g._pushContext();var e;try{e=a?i.apply(void 0,t):i.call(void 0,t)}finally{g._popContext()}return e})._then(c,f,void 0,u,void 0);return u.promise=g,g},e.prototype._setDisposable=function(t){this._bitField=262144|this._bitField,this._disposer=t},e.prototype._isDisposable=function(){return(262144&this._bitField)>0},e.prototype._getDisposer=function(){return this._disposer},e.prototype._unsetDisposable=function(){this._bitField=-262145&this._bitField,this._disposer=void 0},e.prototype.disposer=function(t){if("function"==typeof t)return new h(t,this,i());throw new d}}},{"./errors.js":13,"./util.js":38}],38:[function(e,r,n){"use strict";function i(){try{var t=N;return N=null,t.apply(this,arguments)}catch(t){return j.e=t,j}}function o(t){return N=t,i}function s(t){return null==t||t===!0||t===!1||"string"==typeof t||"number"==typeof t}function a(t){return!s(t)}function u(t){return s(t)?new Error(g(t)):t}function c(t,e){var r,n=t.length,i=new Array(n+1);for(r=0;n>r;++r)i[r]=t[r];return i[r]=e,i}function f(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 l(t,e,r){if(s(t))return t;var n={value:r,configurable:!0,enumerable:!1,writable:!0};return O.defineProperty(t,e,n),t}function h(t){throw t}function p(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=T.test(t+"")&&O.names(t).length>0;
+if(r||n||i)return!0}return!1}catch(t){return!1}}function d(t){function e(){}e.prototype=t;for(var r=8;r--;)new e;return t}function _(t){return k.test(t)}function y(t,e,r){for(var n=new Array(t),i=0;t>i;++i)n[i]=e+i+r;return n}function g(t){try{return t+""}catch(t){return"[no string representation]"}}function v(t){try{l(t,"isOperational",!0)}catch(t){}}function m(t){return null==t?!1:t instanceof Error.__BluebirdErrorTypes__.OperationalError||t.isOperational===!0}function b(t){return t instanceof Error&&O.propertyIsWritable(t,"stack")}function w(t){return{}.toString.call(t)}function E(t,e,r){for(var n=O.names(t),i=0;i10||e[0]>0}(),I.isNode&&I.toFastProperties(t);try{throw new Error}catch(t){I.lastLineError=t}r.exports=I},{"./es5.js":14}]},{},[4])(4)}),"undefined"!=typeof window&&null!==window?window.P=window.Promise:"undefined"!=typeof self&&null!==self&&(self.P=self.Promise)}).call(this,t("g5I+bs"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"g5I+bs":94}],91:[function(t,e,r){e.exports=r=t("./lib/sliced")},{"./lib/sliced":92}],92:[function(t,e,r){e.exports=function(t,e,r){var n=[],i=t.length;if(0===i)return n;var o=0>e?Math.max(0,e+i):e||0;for(void 0!==r&&(i=0>r?r+i:r);i-- >o;)n[i-o]=t[i];return n}},{}],93:[function(t,e,r){function n(t){if(t=""+t,!(t.length>1e4)){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){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*l;case"days":case"day":case"d":return r*f;case"hours":case"hour":case"hrs":case"hr":case"h":return r*c;case"minutes":case"minute":case"mins":case"min":case"m":return r*u;case"seconds":case"second":case"secs":case"sec":case"s":return r*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r}}}}function i(t){return t>=f?Math.round(t/f)+"d":t>=c?Math.round(t/c)+"h":t>=u?Math.round(t/u)+"m":t>=a?Math.round(t/a)+"s":t+"ms"}function o(t){return s(t,f,"day")||s(t,c,"hour")||s(t,u,"minute")||s(t,a,"second")||t+" ms"}function s(t,e,r){return e>t?void 0:1.5*e>t?Math.floor(t/e)+" "+r:Math.ceil(t/e)+" "+r+"s"}var a=1e3,u=60*a,c=60*u,f=24*c,l=365.25*f;e.exports=function(t,e){return e=e||{},"string"==typeof t?n(t):e.long?o(t):i(t)}},{}],94:[function(t,e,r){function n(){}var i=e.exports={};i.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var r=[];return window.addEventListener("message",function(t){var e=t.source;if((e===window||null===e)&&"process-tick"===t.data&&(t.stopPropagation(),r.length>0)){var n=r.shift();n()}},!0),function(t){r.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),i.title="browser",i.browser=!0,i.env={},i.argv=[],i.on=n,i.addListener=n,i.once=n,i.off=n,i.removeListener=n,i.removeAllListeners=n,i.emit=n,i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")}},{}],95:[function(t,e,r){function n(t){return"object"==typeof t&&"[object RegExp]"==i.call(t)}var i=Object.prototype.toString;e.exports=r=function(t){if(!n(t))throw new TypeError("Not a RegExp");var e=[];return t.global&&e.push("g"),t.multiline&&e.push("m"),t.ignoreCase&&e.push("i"),new RegExp(t.source,e.join(""))}},{}],96:[function(t,e,r){e.exports=t(92)},{}],97:[function(t,e,r){e.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},{}],98:[function(t,e,r){(function(e,n){function i(t,e){var n={seen:[],stylize:s};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),_(e)?n.showHidden=e:e&&r._extend(n,e),w(n.showHidden)&&(n.showHidden=!1),w(n.depth)&&(n.depth=2),w(n.colors)&&(n.colors=!1),w(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),u(n,t,n.depth)}function o(t,e){var r=i.styles[e];return r?"["+i.colors[r][0]+"m"+t+"["+i.colors[r][1]+"m":t}function s(t,e){return t}function a(t){var e={};return t.forEach(function(t,r){e[t]=!0}),e}function u(t,e,n){if(t.customInspect&&e&&j(e.inspect)&&e.inspect!==r.inspect&&(!e.constructor||e.constructor.prototype!==e)){var i=e.inspect(n,t);return m(i)||(i=u(t,i,n)),i}var o=c(t,e);if(o)return o;var s=Object.keys(e),_=a(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(e)),S(e)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(e);if(0===s.length){if(j(e)){var y=e.name?": "+e.name:"";return t.stylize("[Function"+y+"]","special")}if(E(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(A(e))return t.stylize(Date.prototype.toString.call(e),"date");if(S(e))return f(e)}var g="",v=!1,b=["{","}"];if(d(e)&&(v=!0,b=["[","]"]),j(e)){var w=e.name?": "+e.name:"";g=" [Function"+w+"]"}if(E(e)&&(g=" "+RegExp.prototype.toString.call(e)),A(e)&&(g=" "+Date.prototype.toUTCString.call(e)),S(e)&&(g=" "+f(e)),0===s.length&&(!v||0==e.length))return b[0]+g+b[1];if(0>n)return E(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special");t.seen.push(e);var O;return O=v?l(t,e,n,_,s):s.map(function(r){return h(t,e,n,_,r,v)}),t.seen.pop(),p(O,g,b)}function c(t,e){if(w(e))return t.stylize("undefined","undefined");if(m(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}return v(e)?t.stylize(""+e,"number"):_(e)?t.stylize(""+e,"boolean"):y(e)?t.stylize("null","null"):void 0}function f(t){return"["+Error.prototype.toString.call(t)+"]"}function l(t,e,r,n,i){for(var o=[],s=0,a=e.length;a>s;++s)k(e,String(s))?o.push(h(t,e,r,n,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(h(t,e,r,n,i,!0))}),o}function h(t,e,r,n,i,o){var s,a,c;if(c=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]},c.get?a=c.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):c.set&&(a=t.stylize("[Setter]","special")),k(n,i)||(s="["+i+"]"),a||(t.seen.indexOf(c.value)<0?(a=y(r)?u(t,c.value,null):u(t,c.value,r-1),a.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")),w(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function p(t,e,r){var n=0,i=t.reduce(function(t,e){return n++,e.indexOf("\n")>=0&&n++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+r[1]:r[0]+e+" "+t.join(", ")+" "+r[1]}function d(t){return Array.isArray(t)}function _(t){return"boolean"==typeof t}function y(t){return null===t}function g(t){return null==t}function v(t){return"number"==typeof t}function m(t){return"string"==typeof t}function b(t){return"symbol"==typeof t}function w(t){return void 0===t}function E(t){return O(t)&&"[object RegExp]"===x(t)}function O(t){return"object"==typeof t&&null!==t}function A(t){return O(t)&&"[object Date]"===x(t)}function S(t){return O(t)&&("[object Error]"===x(t)||t instanceof Error)}function j(t){return"function"==typeof t}function N(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function x(t){return Object.prototype.toString.call(t)}function B(t){return 10>t?"0"+t.toString(10):t.toString(10)}function T(){var t=new Date,e=[B(t.getHours()),B(t.getMinutes()),B(t.getSeconds())].join(":");return[t.getDate(),P[t.getMonth()],e].join(" ")}function k(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var $=/%[sdj%]/g;r.format=function(t){if(!m(t)){for(var e=[],r=0;r=o)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];o>r;a=n[++r])s+=y(a)||!O(a)?" "+a:" "+i(a);return s},r.deprecate=function(t,i){function o(){if(!s){if(e.throwDeprecation)throw new Error(i);e.traceDeprecation?console.trace(i):console.error(i),s=!0}return t.apply(this,arguments)}if(w(n.process))return function(){return r.deprecate(t,i).apply(this,arguments)};if(e.noDeprecation===!0)return t;var s=!1;return o};var I,D={};r.debuglog=function(t){if(w(I)&&(I=e.env.NODE_DEBUG||""),t=t.toUpperCase(),!D[t])if(new RegExp("\\b"+t+"\\b","i").test(I)){var n=e.pid;D[t]=function(){var e=r.format.apply(r,arguments);console.error("%s %d: %s",t,n,e)}}else D[t]=function(){};return D[t]},r.inspect=i,i.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]},i.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=d,r.isBoolean=_,r.isNull=y,r.isNullOrUndefined=g,r.isNumber=v,r.isString=m,r.isSymbol=b,r.isUndefined=w,r.isRegExp=E,r.isObject=O,r.isDate=A,r.isError=S,r.isFunction=j,r.isPrimitive=N,r.isBuffer=t("./support/isBuffer");var P=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];r.log=function(){console.log("%s - %s",T(),r.format.apply(r,arguments))},r.inherits=t("inherits"),r._extend=function(t,e){if(!e||!O(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t}}).call(this,t("g5I+bs"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":97,"g5I+bs":94,inherits:77}]},{},[2]);
\ No newline at end of file
diff --git a/node_modules/mongoose/lib/aggregate.js b/node_modules/mongoose/lib/aggregate.js
index 4efd40f..306f796 100644
--- a/node_modules/mongoose/lib/aggregate.js
+++ b/node_modules/mongoose/lib/aggregate.js
@@ -80,8 +80,9 @@ Aggregate.prototype.bind = function (model) {
*/
Aggregate.prototype.append = function () {
- var args = utils.args(arguments)
- , arg;
+ var args = (1 === arguments.length && util.isArray(arguments[0]))
+ ? arguments[0]
+ : utils.args(arguments);
if (!args.every(isOperator)) {
throw new Error("Arguments must be aggregate pipeline operators");
@@ -270,7 +271,7 @@ Aggregate.prototype.unwind = function () {
return this.append.apply(this, args.map(function (arg) {
return { $unwind: '$' + arg };
}));
-}
+};
/**
* Appends a new $sort operator to this aggregate pipeline.
diff --git a/node_modules/mongoose/lib/document.js b/node_modules/mongoose/lib/document.js
index bb630c8..d960887 100644
--- a/node_modules/mongoose/lib/document.js
+++ b/node_modules/mongoose/lib/document.js
@@ -456,7 +456,9 @@ Document.prototype.set = function (path, val, type, options) {
&& (!path[key].constructor || 'Object' == path[key].constructor.name)
&& 'virtual' != pathtype
&& !(this.$__path(pathName) instanceof MixedSchema)
- && !(this.schema.paths[pathName] && this.schema.paths[pathName].options.ref)) {
+ && !(this.schema.paths[pathName] &&
+ this.schema.paths[pathName].options &&
+ this.schema.paths[pathName].options.ref)) {
this.set(path[key], prefix + key, constructing);
} else if (strict) {
if ('real' === pathtype || 'virtual' === pathtype) {
@@ -730,7 +732,8 @@ Document.prototype.get = function (path, type) {
*/
Document.prototype.$__path = function (path) {
- var adhocs = this.$__.adhocPaths
+ var base = this.$__
+ , adhocs = (base) ? base.adhocPaths : undefined
, adhocType = adhocs && adhocs[path];
if (adhocType) {
diff --git a/node_modules/mongoose/lib/query.js b/node_modules/mongoose/lib/query.js
index c1a2954..415cd86 100644
--- a/node_modules/mongoose/lib/query.js
+++ b/node_modules/mongoose/lib/query.js
@@ -1757,7 +1757,8 @@ Query.prototype.update = function (conditions, doc, options, callback) {
// validate the update part of the query
var castedDoc;
try {
- castedDoc = this._castUpdate(doc, options && options.overwrite);
+ castedDoc = this._castUpdate(utils.clone(doc, { retainKeyOrder: true }),
+ options && options.overwrite);
} catch (err) {
if (callback) {
callback(err);
@@ -1970,7 +1971,7 @@ Query.prototype._walkUpdatePath = function _walkUpdatePath (obj, op, pref) {
if ('$each' in val) {
obj[key] = {
- $each: this._castUpdateVal(schema, val.$each, op)
+ $each: this._castUpdateVal(schema, val.$each, op)
}
if (val.$slice) {
@@ -2014,6 +2015,11 @@ Query.prototype._walkUpdatePath = function _walkUpdatePath (obj, op, pref) {
delete obj[key];
}
} else {
+ if (op === '$rename') {
+ hasKeys = true;
+ return;
+ }
+
hasKeys = true;
obj[key] = this._castUpdateVal(schema, val, op, key);
}
@@ -2646,7 +2652,17 @@ Query.prototype.tailable = function (val, opts) {
val = true;
}
- if (opts && opts.awaitdata) this.options.awaitdata = true;
+ if (opts && typeof opts === 'object') {
+ for (var key in opts) {
+ if (key === 'awaitdata') {
+ // For backwards compatibility
+ this.options[key] = !!opts[key];
+ } else {
+ this.options[key] = opts[key];
+ }
+ }
+ }
+
return Query.base.tailable.call(this, val);
}
diff --git a/node_modules/mongoose/lib/schema.js b/node_modules/mongoose/lib/schema.js
index 5bb68fc..2999e7b 100644
--- a/node_modules/mongoose/lib/schema.js
+++ b/node_modules/mongoose/lib/schema.js
@@ -301,7 +301,7 @@ Schema.prototype.path = function (path, obj) {
branch[last] = utils.clone(obj);
- this.paths[path] = Schema.interpretAsType(path, obj);
+ this.paths[path] = Schema.interpretAsType(path, obj, this.options);
return this;
};
@@ -313,7 +313,7 @@ Schema.prototype.path = function (path, obj) {
* @api private
*/
-Schema.interpretAsType = function (path, obj) {
+Schema.interpretAsType = function (path, obj, options) {
if (obj.constructor && obj.constructor.name != 'Object')
obj = { type: obj };
@@ -343,7 +343,7 @@ Schema.interpretAsType = function (path, obj) {
} else if (cast && (!cast.type || cast.type.type)
&& 'Object' == cast.constructor.name
&& Object.keys(cast).length) {
- return new Types.DocumentArray(path, new Schema(cast), obj);
+ return new Types.DocumentArray(path, new Schema(cast, options), obj);
}
return new Types.Array(path, cast || Types.Mixed, obj);
@@ -897,4 +897,3 @@ Schema.Types = require('./schema/index');
Types = Schema.Types;
Query = require('./query');
var ObjectId = exports.ObjectId = Types.ObjectId;
-
diff --git a/node_modules/mongoose/lib/schema/buffer.js b/node_modules/mongoose/lib/schema/buffer.js
index 91a59e0..6e18f25 100644
--- a/node_modules/mongoose/lib/schema/buffer.js
+++ b/node_modules/mongoose/lib/schema/buffer.js
@@ -112,6 +112,9 @@ SchemaBuffer.prototype.cast = function (value, doc, init) {
var type = typeof value;
if ('string' == type || 'number' == type || Array.isArray(value)) {
+ if (type === 'number') {
+ value = [value];
+ }
var ret = new MongooseBuffer(value, [this.path, doc]);
return ret;
}
diff --git a/node_modules/mongoose/lib/schema/documentarray.js b/node_modules/mongoose/lib/schema/documentarray.js
index 5f288d1..ef59cb0 100644
--- a/node_modules/mongoose/lib/schema/documentarray.js
+++ b/node_modules/mongoose/lib/schema/documentarray.js
@@ -20,7 +20,6 @@ var Subdocument = require('../types/embedded');
*/
function DocumentArray (key, schema, options) {
-
// compile an embedded document for this schema
function EmbeddedDocument () {
Subdocument.apply(this, arguments);
diff --git a/node_modules/mongoose/lib/schema/string.js b/node_modules/mongoose/lib/schema/string.js
index 0568917..c80e202 100644
--- a/node_modules/mongoose/lib/schema/string.js
+++ b/node_modules/mongoose/lib/schema/string.js
@@ -216,10 +216,14 @@ SchemaString.prototype.match = function match (regExp, message) {
var msg = message || errorMessages.String.match;
- function matchValidator (v){
- return null != v && '' !== v
- ? regExp.test(v)
- : true
+ function matchValidator(v) {
+ if (!regExp) {
+ return false;
+ }
+
+ return null != v && '' !== v ?
+ regExp.test(v) :
+ true;
}
this.validators.push([matchValidator, msg, 'regexp']);
diff --git a/node_modules/mongoose/lib/schematype.js b/node_modules/mongoose/lib/schematype.js
index b3413d3..5addfd1 100644
--- a/node_modules/mongoose/lib/schematype.js
+++ b/node_modules/mongoose/lib/schematype.js
@@ -27,15 +27,17 @@ function SchemaType (path, options, instance) {
this._index = null;
this.selected;
- for (var i in options) if (this[i] && 'function' == typeof this[i]) {
- // { unique: true, index: true }
- if ('index' == i && this._index) continue;
+ for (var i in options) {
+ if (this[i] && 'function' == typeof this[i]) {
+ // { unique: true, index: true }
+ if ('index' == i && this._index) continue;
- var opts = Array.isArray(options[i])
- ? options[i]
- : [options[i]];
+ var opts = Array.isArray(options[i])
+ ? options[i]
+ : [options[i]];
- this[i].apply(this, opts);
+ this[i].apply(this, opts);
+ }
}
};
diff --git a/node_modules/mongoose/lib/types/array.js b/node_modules/mongoose/lib/types/array.js
index 5f6ee6d..1acec5e 100644
--- a/node_modules/mongoose/lib/types/array.js
+++ b/node_modules/mongoose/lib/types/array.js
@@ -28,6 +28,12 @@ function MongooseArray (values, path, doc) {
var arr = [].concat(values);;
arr.__proto__ = MongooseArray.prototype;
+ Object.defineProperty(arr, '_atomics', { enumerable: false, configurable: true, writable: true });
+ Object.defineProperty(arr, 'validators', { enumerable: false, configurable: true, writable: true });
+ Object.defineProperty(arr, '_path', {enumerable: false, configurable: true, writable: true });
+ Object.defineProperty(arr, '_parent', { enumerable: false, configurable: true, writable: true });
+ Object.defineProperty(arr, '_schema', { enumerable: false, configurable: true, writable: true });
+
arr._atomics = {};
arr.validators = [];
arr._path = path;
diff --git a/node_modules/mongoose/lib/utils.js b/node_modules/mongoose/lib/utils.js
index e3f6160..fa809bb 100644
--- a/node_modules/mongoose/lib/utils.js
+++ b/node_modules/mongoose/lib/utils.js
@@ -716,4 +716,3 @@ exports.mergeClone = function(to, from) {
}
}
}
-
diff --git a/node_modules/mongoose/node_modules/hooks/package.json b/node_modules/mongoose/node_modules/hooks/package.json
deleted file mode 100644
index 686c16a..0000000
--- a/node_modules/mongoose/node_modules/hooks/package.json
+++ /dev/null
@@ -1,65 +0,0 @@
-{
- "name": "hooks",
- "description": "Adds pre and post hook functionality to your JavaScript methods.",
- "version": "0.2.1",
- "keywords": [
- "node",
- "hooks",
- "middleware",
- "pre",
- "post"
- ],
- "homepage": "https://github.com/bnoguchi/hooks-js/",
- "repository": {
- "type": "git",
- "url": "git://github.com/bnoguchi/hooks-js.git"
- },
- "author": {
- "name": "Brian Noguchi",
- "email": "brian.noguchi@gmail.com",
- "url": "https://github.com/bnoguchi/"
- },
- "main": "./hooks.js",
- "directories": {
- "lib": "."
- },
- "scripts": {
- "test": "make test"
- },
- "dependencies": {},
- "devDependencies": {
- "expresso": ">=0.7.6",
- "should": ">=0.2.1",
- "underscore": ">=1.1.4"
- },
- "engines": {
- "node": ">=0.4.0"
- },
- "licenses": [
- "MIT"
- ],
- "optionalDependencies": {},
- "_npmUser": {
- "name": "bnoguchi",
- "email": "brian.noguchi@gmail.com"
- },
- "_id": "hooks@0.2.1",
- "_engineSupported": true,
- "_npmVersion": "1.1.16",
- "_nodeVersion": "v0.6.15",
- "_defaultsLoaded": true,
- "dist": {
- "shasum": "0f591b1b344bdcb3df59773f62fbbaf85bf4028b",
- "tarball": "http://registry.npmjs.org/hooks/-/hooks-0.2.1.tgz"
- },
- "readme": "hooks\n============\n\nAdd pre and post middleware hooks to your JavaScript methods.\n\n## Installation\n npm install hooks\n\n## Motivation\nSuppose you have a JavaScript object with a `save` method.\n\nIt would be nice to be able to declare code that runs before `save` and after `save`.\nFor example, you might want to run validation code before every `save`,\nand you might want to dispatch a job to a background job queue after `save`.\n\nOne might have an urge to hard code this all into `save`, but that turns out to\ncouple all these pieces of functionality (validation, save, and job creation) more\ntightly than is necessary. For example, what if someone does not want to do background\njob creation after the logical save? \n\nIt is nicer to tack on functionality using what we call `pre` and `post` hooks. These\nare functions that you define and that you direct to execute before or after particular\nmethods.\n\n## Example\nWe can use `hooks` to add validation and background jobs in the following way:\n\n var hooks = require('hooks')\n , Document = require('./path/to/some/document/constructor');\n\n // Add hooks' methods: `hook`, `pre`, and `post` \n for (var k in hooks) {\n Document[k] = hooks[k];\n }\n\n // Define a new method that is able to invoke pre and post middleware\n Document.hook('save', Document.prototype.save);\n\n // Define a middleware function to be invoked before 'save'\n Document.pre('save', function validate (next) {\n // The `this` context inside of `pre` and `post` functions\n // is the Document instance\n if (this.isValid()) next(); // next() passes control to the next middleware\n // or to the target method itself\n else next(new Error(\"Invalid\")); // next(error) invokes an error callback\n });\n\n // Define a middleware function to be invoked after 'save'\n Document.post('save', function createJob () {\n this.sendToBackgroundQueue();\n });\n\nIf you already have defined `Document.prototype` methods for which you want pres and posts,\nthen you do not need to explicitly invoke `Document.hook(...)`. Invoking `Document.pre(methodName, fn)`\nor `Document.post(methodName, fn)` will automatically and lazily change `Document.prototype[methodName]`\nso that it plays well with `hooks`. An equivalent way to implement the previous example is:\n\n```javascript\nvar hooks = require('hooks')\n , Document = require('./path/to/some/document/constructor');\n\n// Add hooks' methods: `hook`, `pre`, and `post` \nfor (var k in hooks) {\n Document[k] = hooks[k];\n}\n\nDocument.prototype.save = function () {\n // ...\n};\n\n// Define a middleware function to be invoked before 'save'\nDocument.pre('save', function validate (next) {\n // The `this` context inside of `pre` and `post` functions\n // is the Document instance\n if (this.isValid()) next(); // next() passes control to the next middleware\n // or to the target method itself\n else next(new Error(\"Invalid\")); // next(error) invokes an error callback\n});\n\n// Define a middleware function to be invoked after 'save'\nDocument.post('save', function createJob () {\n this.sendToBackgroundQueue();\n});\n```\n\n## Pres and Posts as Middleware\nWe structure pres and posts as middleware to give you maximum flexibility:\n\n1. You can define **multiple** pres (or posts) for a single method.\n2. These pres (or posts) are then executed as a chain of methods.\n3. Any functions in this middleware chain can choose to halt the chain's execution by `next`ing an Error from that middleware function. If this occurs, then none of the other middleware in the chain will execute, and the main method (e.g., `save`) will not execute. This is nice, for example, when we don't want a document to save if it is invalid.\n\n## Defining multiple pres (or posts)\n`pre` is chainable, so you can define multiple pres via:\n Document.pre('save', function (next, halt) {\n console.log(\"hello\");\n }).pre('save', function (next, halt) {\n console.log(\"world\");\n });\n\nAs soon as one pre finishes executing, the next one will be invoked, and so on.\n\n## Error Handling\nYou can define a default error handler by passing a 2nd function as the 3rd argument to `hook`:\n Document.hook('set', function (path, val) {\n this[path] = val;\n }, function (err) {\n // Handler the error here\n console.error(err);\n });\n\nThen, we can pass errors to this handler from a pre or post middleware function:\n Document.pre('set', function (next, path, val) {\n next(new Error());\n });\n\nIf you do not set up a default handler, then `hooks` makes the default handler that just throws the `Error`.\n\nThe default error handler can be over-rided on a per method invocation basis.\n\nIf the main method that you are surrounding with pre and post middleware expects its last argument to be a function\nwith callback signature `function (error, ...)`, then that callback becomes the error handler, over-riding the default\nerror handler you may have set up.\n \n```javascript\nDocument.hook('save', function (callback) {\n // Save logic goes here\n ...\n});\n\nvar doc = new Document();\ndoc.save( function (err, saved) {\n // We can pass err via `next` in any of our pre or post middleware functions\n if (err) console.error(err);\n \n // Rest of callback logic follows ...\n});\n```\n\n## Mutating Arguments via Middleware\n`pre` and `post` middleware can also accept the intended arguments for the method\nthey augment. This is useful if you want to mutate the arguments before passing\nthem along to the next middleware and eventually pass a mutated arguments list to\nthe main method itself.\n\nAs a simple example, let's define a method `set` that just sets a key, value pair.\nIf we want to namespace the key, we can do so by adding a `pre` middleware hook\nthat runs before `set`, alters the arguments by namespacing the `key` argument, and passes them onto `set`:\n\n Document.hook('set', function (key, val) {\n this[key] = val;\n });\n Document.pre('set', function (next, key, val) {\n next('namespace-' + key, val);\n });\n var doc = new Document();\n doc.set('hello', 'world');\n console.log(doc.hello); // undefined\n console.log(doc['namespace-hello']); // 'world'\n\nAs you can see above, we pass arguments via `next`.\n\nIf you are not mutating the arguments, then you can pass zero arguments\nto `next`, and the next middleware function will still have access\nto the arguments.\n\n Document.hook('set', function (key, val) {\n this[key] = val;\n });\n Document.pre('set', function (next, key, val) {\n // I have access to key and val here\n next(); // We don't need to pass anything to next\n });\n Document.pre('set', function (next, key, val) {\n // And I still have access to the original key and val here\n next();\n });\n\nFinally, you can add arguments that downstream middleware can also see:\n\n // Note that in the definition of `set`, there is no 3rd argument, options\n Document.hook('set', function (key, val) {\n // But...\n var options = arguments[2]; // ...I have access to an options argument\n // because of pre function pre2 (defined below)\n console.log(options); // '{debug: true}'\n this[key] = val;\n });\n Document.pre('set', function pre1 (next, key, val) {\n // I only have access to key and val arguments\n console.log(arguments.length); // 3\n next(key, val, {debug: true});\n });\n Document.pre('set', function pre2 (next, key, val, options) {\n console.log(arguments.length); // 4\n console.log(options); // '{ debug: true}'\n next();\n });\n Document.pre('set', function pre3 (next, key, val, options) {\n // I still have access to key, val, AND the options argument introduced via the preceding middleware\n console.log(arguments.length); // 4\n console.log(options); // '{ debug: true}'\n next();\n });\n \n var doc = new Document()\n doc.set('hey', 'there');\n\n## Parallel `pre` middleware\n\nAll middleware up to this point has been \"serial\" middleware -- i.e., middleware whose logic\nis executed as a serial chain.\n\nSome scenarios call for parallel middleware -- i.e., middleware that can wait for several\nasynchronous services at once to respond.\n\nFor instance, you may only want to save a Document only after you have checked\nthat the Document is valid according to two different remote services.\n\nWe accomplish asynchronous middleware by adding a second kind of flow control callback\n(the only flow control callback so far has been `next`), called `done`.\n\n- `next` passes control to the next middleware in the chain\n- `done` keeps track of how many parallel middleware have invoked `done` and passes\n control to the target method when ALL parallel middleware have invoked `done`. If\n you pass an `Error` to `done`, then the error is handled, and the main method that is\n wrapped by pres and posts will not get invoked.\n\nWe declare pre middleware that is parallel by passing a 3rd boolean argument to our `pre`\ndefinition method.\n\nWe illustrate via the parallel validation example mentioned above:\n\n Document.hook('save', function targetFn (callback) {\n // Save logic goes here\n // ...\n // This only gets run once the two `done`s are both invoked via preOne and preTwo.\n });\n\n // true marks this as parallel middleware\n Document.pre('save', true, function preOne (next, doneOne, callback) {\n remoteServiceOne.validate(this.serialize(), function (err, isValid) {\n // The code in here will probably be run after the `next` below this block\n // and could possibly be run after the console.log(\"Hola\") in `preTwo\n if (err) return doneOne(err);\n if (isValid) doneOne();\n });\n next(); // Pass control to the next middleware\n });\n \n // We will suppose that we need 2 different remote services to validate our document\n Document.pre('save', true, function preTwo (next, doneTwo, callback) {\n remoteServiceTwo.validate(this.serialize(), function (err, isValid) {\n if (err) return doneTwo(err);\n if (isValid) doneTwo();\n });\n next();\n });\n \n // While preOne and preTwo are parallel, preThree is a serial pre middleware\n Document.pre('save', function preThree (next, callback) {\n next();\n });\n \n var doc = new Document();\n doc.save( function (err, doc) {\n // Do stuff with the saved doc here...\n });\n\nIn the above example, flow control may happen in the following way:\n\n(1) doc.save -> (2) preOne --(next)--> (3) preTwo --(next)--> (4) preThree --(next)--> (wait for dones to invoke) -> (5) doneTwo -> (6) doneOne -> (7) targetFn\n\nSo what's happening is that:\n\n1. You call `doc.save(...)`\n2. First, your preOne middleware gets executed. It makes a remote call to the validation service and `next()`s to the preTwo middleware.\n3. Now, your preTwo middleware gets executed. It makes a remote call to another validation service and `next()`s to the preThree middleware.\n4. Your preThree middleware gets executed. It immediately `next()`s. But nothing else gets executing until both `doneOne` and `doneTwo` are invoked inside the callbacks handling the response from the two valiation services.\n5. We will suppose that validation remoteServiceTwo returns a response to us first. In this case, we call `doneTwo` inside the callback to remoteServiceTwo.\n6. Some fractions of a second later, remoteServiceOne returns a response to us. In this case, we call `doneOne` inside the callback to remoteServiceOne.\n7. `hooks` implementation keeps track of how many parallel middleware has been defined per target function. It detects that both asynchronous pre middlewares (`preOne` and `preTwo`) have finally called their `done` functions (`doneOne` and `doneTwo`), so the implementation finally invokes our `targetFn` (i.e., our core `save` business logic).\n\n## Removing Pres\n\nYou can remove a particular pre associated with a hook:\n\n Document.pre('set', someFn);\n Document.removePre('set', someFn);\n\nAnd you can also remove all pres associated with a hook:\n Document.removePre('set'); // Removes all declared `pre`s on the hook 'set'\n\n## Tests\nTo run the tests:\n make test\n\n### Contributors\n- [Brian Noguchi](https://github.com/bnoguchi)\n\n### License\nMIT License\n\n---\n### Author\nBrian Noguchi\n",
- "maintainers": [
- {
- "name": "bnoguchi",
- "email": "brian.noguchi@gmail.com"
- }
- ],
- "_shasum": "0f591b1b344bdcb3df59773f62fbbaf85bf4028b",
- "_resolved": "https://registry.npmjs.org/hooks/-/hooks-0.2.1.tgz",
- "_from": "hooks@0.2.1"
-}
diff --git a/node_modules/mongoose/node_modules/mongodb/node_modules/bson/node_modules/nan/nan_implementation_pre_12_inl.h b/node_modules/mongoose/node_modules/mongodb/node_modules/bson/node_modules/nan/nan_implementation_pre_12_inl.h
deleted file mode 100644
index 85dd275..0000000
--- a/node_modules/mongoose/node_modules/mongodb/node_modules/bson/node_modules/nan/nan_implementation_pre_12_inl.h
+++ /dev/null
@@ -1,268 +0,0 @@
-/*********************************************************************
- * NAN - Native Abstractions for Node.js
- *
- * Copyright (c) 2015 NAN contributors
- *
- * MIT License
- ********************************************************************/
-
-#ifndef NAN_IMPLEMENTATION_PRE_12_INL_H_
-#define NAN_IMPLEMENTATION_PRE_12_INL_H_
-
-#include
-
-#if defined(_MSC_VER)
-# pragma warning( disable : 4530 )
-# include
-# include
-# pragma warning( default : 4530 )
-#else
-# include
-# include
-#endif
-
-//==============================================================================
-// node v0.10 implementation
-//==============================================================================
-
-namespace NanIntern {
-
-//=== Array ====================================================================
-
-Factory::return_t
-Factory::New() {
- return v8::Array::New();
-}
-
-Factory::return_t
-Factory::New(int length) {
- return v8::Array::New(length);
-}
-
-//=== Boolean ==================================================================
-
-Factory::return_t
-Factory::New(bool value) {
- return v8::Boolean::New(value)->ToBoolean();
-}
-
-//=== Boolean Object ===========================================================
-
-Factory::return_t
-Factory::New(bool value) {
- return v8::BooleanObject::New(value).As();
-}
-
-//=== Context ==================================================================
-
-Factory::return_t
-Factory::New( v8::ExtensionConfiguration* extensions
- , v8::Handle tmpl
- , v8::Handle obj) {
- v8::Persistent ctx = v8::Context::New(extensions, tmpl, obj);
- v8::Local lctx = v8::Local::New(ctx);
- ctx.Dispose();
- return lctx;
-}
-
-//=== Date =====================================================================
-
-Factory::return_t
-Factory::New(double value) {
- return v8::Date::New(value).As();
-}
-
-//=== External =================================================================
-
-Factory::return_t
-Factory::New(void * value) {
- return v8::External::New(value);
-}
-
-//=== Function =================================================================
-
-Factory::return_t
-Factory::New( NanFunctionCallback callback
- , v8::Handle data) {
- return Factory::New( callback
- , data
- , v8::Handle()
- )->GetFunction();
-}
-
-
-//=== FunctionTemplate =========================================================
-
-Factory::return_t
-Factory::New( NanFunctionCallback callback
- , v8::Handle data
- , v8::Handle signature) {
- // Note(agnat): Emulate length argument here. Unfortunately, I couldn't find
- // a way. Have at it though...
- return v8::FunctionTemplate::New( callback
- , data
- , signature);
-}
-
-//=== Number ===================================================================
-
-Factory::return_t
-Factory::New(double value) {
- return v8::Number::New(value);
-}
-
-//=== Number Object ============================================================
-
-Factory::return_t
-Factory::New(double value) {
- return v8::NumberObject::New(value).As();
-}
-
-//=== Integer, Int32 and Uint32 ================================================
-
-template
-typename IntegerFactory::return_t
-IntegerFactory::New(int32_t value) {
- return To(T::New(value));
-}
-
-template
-typename IntegerFactory::return_t
-IntegerFactory::New(uint32_t value) {
- return To(T::NewFromUnsigned(value));
-}
-
-Factory::return_t
-Factory::New(int32_t value) {
- return To(v8::Uint32::NewFromUnsigned(value));
-}
-
-Factory::return_t
-Factory::New(uint32_t value) {
- return To(v8::Uint32::NewFromUnsigned(value));
-}
-
-
-//=== Object ===================================================================
-
-Factory::return_t
-Factory::New() {
- return v8::Object::New();
-}
-
-//=== Object Template ==========================================================
-
-Factory::return_t
-Factory::New() {
- return v8::ObjectTemplate::New();
-}
-
-//=== RegExp ===================================================================
-
-Factory::return_t
-Factory::New(
- v8::Handle pattern
- , v8::RegExp::Flags flags) {
- return v8::RegExp::New(pattern, flags);
-}
-
-//=== Script ===================================================================
-
-Factory::return_t
-Factory::New( v8::Local source) {
- return v8::Script::New(source);
-}
-Factory::return_t
-Factory::New( v8::Local source
- , v8::ScriptOrigin const& origin) {
- return v8::Script::New(source, const_cast(&origin));
-}
-
-//=== Signature ================================================================
-
-Factory::return_t
-Factory::New( Factory::FTH receiver
- , int argc
- , Factory::FTH argv[]) {
- return v8::Signature::New(receiver, argc, argv);
-}
-
-//=== String ===================================================================
-
-Factory::return_t
-Factory::New() {
- return v8::String::Empty();
-}
-
-Factory::return_t
-Factory::New(const char * value, int length) {
- return v8::String::New(value, length);
-}
-
-Factory::return_t
-Factory::New(std::string const& value) {
- assert(value.size() <= INT_MAX && "string too long");
- return v8::String::New( value.data(), static_cast(value.size()));
-}
-
-inline
-void
-widenString(std::vector *ws, const uint8_t *s, int l = -1) {
- size_t len = static_cast(l);
- if (l < 0) {
- len = strlen(reinterpret_cast(s));
- }
- assert(len <= INT_MAX && "string too long");
- ws->resize(len);
- std::copy(s, s + len, ws->begin());
-}
-
-Factory::return_t
-Factory::New(const uint16_t * value, int length) {
- return v8::String::New(value, length);
-}
-
-Factory::return_t
-Factory::New(const uint8_t * value, int length) {
- std::vector wideString;
- widenString(&wideString, value, length);
- if (wideString.size() == 0) {
- return v8::String::Empty();
- } else {
- return v8::String::New(&wideString.front()
- , static_cast(wideString.size()));
- }
-}
-
-Factory::return_t
-Factory::New(v8::String::ExternalStringResource * value) {
- return v8::String::NewExternal(value);
-}
-
-Factory::return_t
-Factory::New(v8::String::ExternalAsciiStringResource * value) {
- return v8::String::NewExternal(value);
-}
-
-//=== String Object ============================================================
-
-Factory::return_t
-Factory::New(v8::Handle value) {
- return v8::StringObject::New(value).As();
-}
-
-} // end of namespace NanIntern
-
-//=== Presistents and Handles ==================================================
-
-template
-inline v8::Local NanNew(v8::Handle h) {
- return v8::Local