-
Notifications
You must be signed in to change notification settings - Fork 3
/
minimongo.min.js
3 lines (3 loc) · 72 KB
/
minimongo.min.js
1
2
3
!function(a,b){function c(a){return a?Meteor._debug("Exception in callback of async function",a.stack?a.stack:a):void 0}function d(){if(b.setImmediate){var a=function(a){b.setImmediate(a)};return a.implementation="setImmediate",a}return null}function e(){function a(a,b){return"string"==typeof a&&a.substring(0,b.length)===b}function c(c){if(c.source===b&&a(c.data,h)){var d=c.data.substring(h.length);try{g[d]&&g[d]()}finally{delete g[d]}}}if(!b.postMessage||b.importScripts)return null;var d=!0,e=b.onmessage;if(b.onmessage=function(){d=!1},b.postMessage("","*"),b.onmessage=e,!d)return null;var f=0,g={},h="Meteor._setImmediate."+Math.random()+".";b.addEventListener?b.addEventListener("message",c,!1):b.attachEvent("onmessage",c);var i=function(a){++f,g[f]=a,b.postMessage(h+f,"*")};return i.implementation="postMessage",i}function f(){var a=function(a){b.setTimeout(a,0)};return a.implementation="setTimeout",a}b.Minimongo=a;var g={};if(Meteor={isClient:!0,isServer:!1,isCordova:!1},"object"==typeof g&&g.PUBLIC_SETTINGS&&(Meteor.settings={"public":g.PUBLIC_SETTINGS}),Meteor.isServer)var h=Npm.require("fibers/future");"object"==typeof g&&g.meteorRelease&&(Meteor.release=g.meteorRelease),_.extend(Meteor,{_get:function(a){for(var b=1;b<arguments.length;b++){if(!(arguments[b]in a))return void 0;a=a[arguments[b]]}return a},_ensure:function(a){for(var b=1;b<arguments.length;b++){var c=arguments[b];c in a||(a[c]={}),a=a[c]}return a},_delete:function(a){for(var b=[a],c=!0,d=1;d<arguments.length-1;d++){var e=arguments[d];if(!(e in a)){c=!1;break}if(a=a[e],"object"!=typeof a)break;b.push(a)}for(var d=b.length-1;d>=0;d--){var e=arguments[d+1];if(c)c=!1;else for(var f in b[d][e])return;delete b[d][e]}},wrapAsync:function(a,b){return function(){for(var d,e=b||this,f=_.toArray(arguments),g=f.length-1;g>=0;--g){var i=f[g],j=typeof i;if("undefined"!==j){"function"===j&&(d=i);break}}if(!d){if(Meteor.isClient)d=c;else{var k=new h;d=k.resolver()}++g}f[g]=Meteor.bindEnvironment(d);var l=a.apply(e,f);return k?k.wait():l}},_inherits:function(a,b){for(var c in b)_.has(b,c)&&(a[c]=b[c]);var d=function(){this.constructor=a};return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a}});var i=!1;Meteor._wrapAsync=function(a,b){return i||(Meteor._debug("Meteor._wrapAsync has been renamed to Meteor.wrapAsync"),i=!0),Meteor.wrapAsync.apply(Meteor,arguments)};var b=this;Meteor._setImmediate=d()||e()||f();var j=function(a){if(Package.ddp){var b=Package.ddp.DDP._CurrentInvocation;if(b.get()&&b.get().isSimulation)throw new Error("Can't set timers inside simulations");return function(){b.withValue(null,a)}}return a},k=function(a,b){return Meteor.bindEnvironment(j(b),a)};_.extend(Meteor,{setTimeout:function(a,b){return setTimeout(k("setTimeout callback",a),b)},setInterval:function(a,b){return setInterval(k("setInterval callback",a),b)},clearInterval:function(a){return clearInterval(a)},clearTimeout:function(a){return clearTimeout(a)},defer:function(a){Meteor._setImmediate(k("defer callback",a))}}),Meteor.makeErrorType=function(a,b){var c=function(){var d=this;if(Error.captureStackTrace)Error.captureStackTrace(d,c);else{var e=new Error;e.__proto__=c.prototype,e instanceof c&&(d=e)}return b.apply(d,arguments),d.errorType=a,d};return Meteor._inherits(c,Error),c},Meteor.Error=Meteor.makeErrorType("Meteor.Error",function(a,b,c){var d=this;d.error=a,d.reason=b,d.details=c,d.reason?d.message=d.reason+" ["+d.error+"]":d.message="["+d.error+"]"}),Meteor.Error.prototype.clone=function(){var a=this;return new Meteor.Error(a.error,a.reason,a.details)},Meteor._noYieldsAllowed=function(a){return a()},Meteor._SynchronousQueue=function(){var a=this;a._tasks=[],a._running=!1,a._runTimeout=null},_.extend(Meteor._SynchronousQueue.prototype,{runTask:function(a){var b=this;if(!b.safeToRunTask())throw new Error("Could not synchronously run a task from a running task");b._tasks.push(a);var c=b._tasks;b._tasks=[],b._running=!0,b._runTimeout&&(clearTimeout(b._runTimeout),b._runTimeout=null);try{for(;!_.isEmpty(c);){var d=c.shift();try{d()}catch(e){if(_.isEmpty(c))throw e;Meteor._debug("Exception in queued task: "+e.stack)}}}finally{b._running=!1}},queueTask:function(a){var b=this;b._tasks.push(a),b._runTimeout||(b._runTimeout=setTimeout(_.bind(b.flush,b),0))},flush:function(){var a=this;a.runTask(function(){})},drain:function(){var a=this;if(a.safeToRunTask())for(;!_.isEmpty(a._tasks);)a.flush()},safeToRunTask:function(){var a=this;return!a._running}});var l=0;Meteor._debug=function(){if(l)return void l--;if("undefined"!=typeof console&&"undefined"!=typeof console.log)if(0==arguments.length)console.log("");else if("function"==typeof console.log.apply){for(var a=!0,b=0;b<arguments.length;b++)"string"!=typeof arguments[b]&&(a=!1);a?console.log.apply(console,[Array.prototype.join.call(arguments," ")]):console.log.apply(console,arguments)}else if("function"==typeof Function.prototype.bind){var c=Function.prototype.bind.call(console.log,console);c.apply(console,arguments)}else Function.prototype.call.call(console.log,console,Array.prototype.slice.call(arguments))},Meteor._suppress_log=function(a){l+=a},Meteor._supressed_log_expected=function(){return 0!==l};for(var m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n={},o=0;o<m.length;o++)n[m.charAt(o)]=o;Base64={},Base64.encode=function(a){if("string"==typeof a){var b=a;a=Base64.newBinary(b.length);for(var c=0;c<b.length;c++){var d=b.charCodeAt(c);if(d>255)throw new Error("Not ascii. Base64.encode can only take ascii strings.");a[c]=d}}for(var e=[],f=null,g=null,h=null,i=null,c=0;c<a.length;c++)switch(c%3){case 0:f=a[c]>>2&63,g=(3&a[c])<<4;break;case 1:g|=a[c]>>4&15,h=(15&a[c])<<2;break;case 2:h|=a[c]>>6&3,i=63&a[c],e.push(p(f)),e.push(p(g)),e.push(p(h)),e.push(p(i)),f=null,g=null,h=null,i=null}return null!=f&&(e.push(p(f)),e.push(p(g)),null==h?e.push("="):e.push(p(h)),null==i&&e.push("=")),e.join("")};var p=function(a){return m.charAt(a)},q=function(a){return"="===a?-1:n[a]};Base64.newBinary=function(a){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer){for(var b=[],c=0;a>c;c++)b.push(0);return b.$Uint8ArrayPolyfill=!0,b}return new Uint8Array(new ArrayBuffer(a))},Base64.decode=function(a){var b=Math.floor(3*a.length/4);"="==a.charAt(a.length-1)&&(b--,"="==a.charAt(a.length-2)&&b--);for(var c=Base64.newBinary(b),d=null,e=null,f=null,g=0,h=0;h<a.length;h++){var i=a.charAt(h),j=q(i);switch(h%4){case 0:if(0>j)throw new Error("invalid base64 string");d=j<<2;break;case 1:if(0>j)throw new Error("invalid base64 string");d|=j>>4,c[g++]=d,e=(15&j)<<4;break;case 2:j>=0&&(e|=j>>2,c[g++]=e,f=(3&j)<<6);break;case 3:j>=0&&(c[g++]=f|j)}}return c},EJSON={},EJSONTest={};var r={};EJSON.addType=function(a,b){if(_.has(r,a))throw new Error("Type "+a+" already present");r[a]=b};var s=function(a){return _.isNaN(a)||a===1/0||a===-(1/0)},t=[{matchJSONValue:function(a){return _.has(a,"$date")&&1===_.size(a)},matchObject:function(a){return a instanceof Date},toJSONValue:function(a){return{$date:a.getTime()}},fromJSONValue:function(a){return new Date(a.$date)}},{matchJSONValue:function(a){return _.has(a,"$InfNaN")&&1===_.size(a)},matchObject:s,toJSONValue:function(a){var b;return b=_.isNaN(a)?0:a===1/0?1:-1,{$InfNaN:b}},fromJSONValue:function(a){return a.$InfNaN/0}},{matchJSONValue:function(a){return _.has(a,"$binary")&&1===_.size(a)},matchObject:function(a){return"undefined"!=typeof Uint8Array&&a instanceof Uint8Array||a&&_.has(a,"$Uint8ArrayPolyfill")},toJSONValue:function(a){return{$binary:Base64.encode(a)}},fromJSONValue:function(a){return Base64.decode(a.$binary)}},{matchJSONValue:function(a){return _.has(a,"$escape")&&1===_.size(a)},matchObject:function(a){return _.isEmpty(a)||_.size(a)>2?!1:_.any(t,function(b){return b.matchJSONValue(a)})},toJSONValue:function(a){var b={};return _.each(a,function(a,c){b[c]=EJSON.toJSONValue(a)}),{$escape:b}},fromJSONValue:function(a){var b={};return _.each(a.$escape,function(a,c){b[c]=EJSON.fromJSONValue(a)}),b}},{matchJSONValue:function(a){return _.has(a,"$type")&&_.has(a,"$value")&&2===_.size(a)},matchObject:function(a){return EJSON._isCustomType(a)},toJSONValue:function(a){var b=Meteor._noYieldsAllowed(function(){return a.toJSONValue()});return{$type:a.typeName(),$value:b}},fromJSONValue:function(a){var b=a.$type;if(!_.has(r,b))throw new Error("Custom EJSON type "+b+" is not defined");var c=r[b];return Meteor._noYieldsAllowed(function(){return c(a.$value)})}}];EJSON._isCustomType=function(a){return a&&"function"==typeof a.toJSONValue&&"function"==typeof a.typeName&&_.has(r,a.typeName())};var u=EJSON._adjustTypesToJSONValue=function(a){if(null===a)return null;var b=v(a);return void 0!==b?b:"object"!=typeof a?a:(_.each(a,function(b,c){if("object"==typeof b||void 0===b||s(b)){var d=v(b);return d?void(a[c]=d):void u(b)}}),a)},v=function(a){for(var b=0;b<t.length;b++){var c=t[b];if(c.matchObject(a))return c.toJSONValue(a)}return void 0};EJSON.toJSONValue=function(a){var b=v(a);return void 0!==b?b:("object"==typeof a&&(a=EJSON.clone(a),u(a)),a)};var w=EJSON._adjustTypesFromJSONValue=function(a){if(null===a)return null;var b=x(a);return b!==a?b:"object"!=typeof a?a:(_.each(a,function(b,c){if("object"==typeof b){var d=x(b);if(b!==d)return void(a[c]=d);w(b)}}),a)},x=function(a){if("object"==typeof a&&null!==a&&_.size(a)<=2&&_.all(a,function(a,b){return"string"==typeof b&&"$"===b.substr(0,1)}))for(var b=0;b<t.length;b++){var c=t[b];if(c.matchJSONValue(a))return c.fromJSONValue(a)}return a};EJSON.fromJSONValue=function(a){var b=x(a);return b===a&&"object"==typeof a?(a=EJSON.clone(a),w(a),a):b},EJSON.stringify=function(a,b){var c=EJSON.toJSONValue(a);return b&&(b.canonical||b.indent)?EJSON._canonicalStringify(c,b):JSON.stringify(c)},EJSON.parse=function(a){if("string"!=typeof a)throw new Error("EJSON.parse argument should be a string");return EJSON.fromJSONValue(JSON.parse(a))},EJSON.isBinary=function(a){return!!("undefined"!=typeof Uint8Array&&a instanceof Uint8Array||a&&a.$Uint8ArrayPolyfill)},EJSON.equals=function(a,b,c){var d,e=!(!c||!c.keyOrderSensitive);if(a===b)return!0;if(_.isNaN(a)&&_.isNaN(b))return!0;if(!a||!b)return!1;if("object"!=typeof a||"object"!=typeof b)return!1;if(a instanceof Date&&b instanceof Date)return a.valueOf()===b.valueOf();if(EJSON.isBinary(a)&&EJSON.isBinary(b)){if(a.length!==b.length)return!1;for(d=0;d<a.length;d++)if(a[d]!==b[d])return!1;return!0}if("function"==typeof a.equals)return a.equals(b,c);if("function"==typeof b.equals)return b.equals(a,c);if(a instanceof Array){if(!(b instanceof Array))return!1;if(a.length!==b.length)return!1;for(d=0;d<a.length;d++)if(!EJSON.equals(a[d],b[d],c))return!1;return!0}switch(EJSON._isCustomType(a)+EJSON._isCustomType(b)){case 1:return!1;case 2:return EJSON.equals(EJSON.toJSONValue(a),EJSON.toJSONValue(b))}var f;if(e){var g=[];return _.each(b,function(a,b){g.push(b)}),d=0,f=_.all(a,function(a,e){return d>=g.length?!1:e!==g[d]?!1:EJSON.equals(a,b[g[d]],c)?(d++,!0):!1}),f&&d===g.length}return d=0,f=_.all(a,function(a,e){return _.has(b,e)&&EJSON.equals(a,b[e],c)?(d++,!0):!1}),f&&_.size(b)===d},EJSON.clone=function(a){var b;if("object"!=typeof a)return a;if(null===a)return null;if(a instanceof Date)return new Date(a.getTime());if(a instanceof RegExp)return a;if(EJSON.isBinary(a)){b=EJSON.newBinary(a.length);for(var c=0;c<a.length;c++)b[c]=a[c];return b}if(_.isArray(a)||_.isArguments(a)){for(b=[],c=0;c<a.length;c++)b[c]=EJSON.clone(a[c]);return b}return"function"==typeof a.clone?a.clone():EJSON._isCustomType(a)?EJSON.fromJSONValue(EJSON.clone(EJSON.toJSONValue(a)),!0):(b={},_.each(a,function(a,c){b[c]=EJSON.clone(a)}),b)},EJSON.newBinary=Base64.newBinary,IdMap=function(a,b){var c=this;c._map={},c._idStringify=a||JSON.stringify,c._idParse=b||JSON.parse},_.extend(IdMap.prototype,{get:function(a){var b=this,c=b._idStringify(a);return b._map[c]},set:function(a,b){var c=this,d=c._idStringify(a);c._map[d]=b},remove:function(a){var b=this,c=b._idStringify(a);delete b._map[c]},has:function(a){var b=this,c=b._idStringify(a);return _.has(b._map,c)},empty:function(){var a=this;return _.isEmpty(a._map)},clear:function(){var a=this;a._map={}},forEach:function(a){for(var b=this,c=_.keys(b._map),d=0;d<c.length;d++){var e=a.call(null,b._map[c[d]],b._idParse(c[d]));if(e===!1)return}},size:function(){var a=this;return _.size(a._map)},setDefault:function(a,b){var c=this,d=c._idStringify(a);return _.has(c._map,d)?c._map[d]:(c._map[d]=b,b)},clone:function(){var a=this,b=new IdMap(a._idStringify,a._idParse);return a.forEach(function(a,c){b.set(c,EJSON.clone(a))}),b}});var y=function(a,b,c,d){return{key:a,value:b,next:c,prev:d}};OrderedDict=function(){var a=this;a._dict={},a._first=null,a._last=null,a._size=0;var b=_.toArray(arguments);a._stringify=function(a){return a},"function"==typeof b[0]&&(a._stringify=b.shift()),_.each(b,function(b){a.putBefore(b[0],b[1],null)})},_.extend(OrderedDict.prototype,{_k:function(a){return" "+this._stringify(a)},empty:function(){var a=this;return!a._first},size:function(){var a=this;return a._size},_linkEltIn:function(a){var b=this;a.next?(a.prev=a.next.prev,a.next.prev=a,a.prev&&(a.prev.next=a)):(a.prev=b._last,b._last&&(b._last.next=a),b._last=a),(null===b._first||b._first===a.next)&&(b._first=a)},_linkEltOut:function(a){var b=this;a.next&&(a.next.prev=a.prev),a.prev&&(a.prev.next=a.next),a===b._last&&(b._last=a.prev),a===b._first&&(b._first=a.next)},putBefore:function(a,b,c){var d=this;if(d._dict[d._k(a)])throw new Error("Item "+a+" already present in OrderedDict");var e=c?y(a,b,d._dict[d._k(c)]):y(a,b,null);if(void 0===e.next)throw new Error("could not find item to put this one before");d._linkEltIn(e),d._dict[d._k(a)]=e,d._size++},append:function(a,b){var c=this;c.putBefore(a,b,null)},remove:function(a){var b=this,c=b._dict[b._k(a)];if(void 0===c)throw new Error("Item "+a+" not present in OrderedDict");return b._linkEltOut(c),b._size--,delete b._dict[b._k(a)],c.value},get:function(a){var b=this;return b.has(a)?b._dict[b._k(a)].value:void 0},has:function(a){var b=this;return _.has(b._dict,b._k(a))},forEach:function(a){for(var b=this,c=0,d=b._first;null!==d;){var e=a(d.value,d.key,c);if(e===OrderedDict.BREAK)return;d=d.next,c++}},first:function(){var a=this;return a.empty()?void 0:a._first.key},firstValue:function(){var a=this;return a.empty()?void 0:a._first.value},last:function(){var a=this;return a.empty()?void 0:a._last.key},lastValue:function(){var a=this;return a.empty()?void 0:a._last.value},prev:function(a){var b=this;if(b.has(a)){var c=b._dict[b._k(a)];if(c.prev)return c.prev.key}return null},next:function(a){var b=this;if(b.has(a)){var c=b._dict[b._k(a)];if(c.next)return c.next.key}return null},moveBefore:function(a,b){var c=this,d=c._dict[c._k(a)],e=b?c._dict[c._k(b)]:null;if(void 0===d)throw new Error("Item to move is not present");if(void 0===e)throw new Error("Could not find element to move this one before");e!==d.next&&(c._linkEltOut(d),d.next=e,c._linkEltIn(d))},indexOf:function(a){var b=this,c=null;return b.forEach(function(d,e,f){return b._k(e)===b._k(a)?(c=f,OrderedDict.BREAK):void 0}),c},_checkRep:function(){var a=this;_.each(a._dict,function(a,b){if(b.next===b)throw new Error("Next is a loop");if(b.prev===b)throw new Error("Prev is a loop")})}}),OrderedDict.BREAK={"break":!0},Tracker={},Tracker.active=!1,Tracker.currentComputation=null,Tracker._computations={};var z=function(a){Tracker.currentComputation=a,Tracker.active=!!a},A=function(){return"undefined"!=typeof Meteor?Meteor._debug:"undefined"!=typeof console&&console.error?function(){console.error.apply(console,arguments)}:function(){}},B=function(a){"undefined"!=typeof Meteor&&Meteor._supressed_log_expected()&&Meteor._suppress_log(a-1)},C=function(a,b){if(J)throw b;var c=["Exception from Tracker "+a+" function:"];if(b.stack&&b.message&&b.name){var d=b.stack.indexOf(b.message);if(0>d||d>b.name.length+2){var e=b.name+": "+b.message;c.push(e)}}c.push(b.stack),B(c.length);for(var f=0;f<c.length;f++)A()(c[f])},D=function(a){return"undefined"==typeof Meteor||Meteor.isClient?a:function(){var b=arguments;Meteor._noYieldsAllowed(function(){a.apply(null,b)})}},E=1,F=[],G=!1,H=!1,I=!1,J=!1,K=[],L=function(){G||("undefined"!=typeof Meteor?Meteor._setImmediate(Tracker._runFlush):setTimeout(Tracker._runFlush,0),G=!0)},M=!1;if(Tracker.Computation=function(a,b,c){if(!M)throw new Error("Tracker.Computation constructor is private; use Tracker.autorun");M=!1;var d=this;d.stopped=!1,d.invalidated=!1,d.firstRun=!0,d._id=E++,d._onInvalidateCallbacks=[],d._parent=b,d._func=a,d._onError=c,d._recomputing=!1,Tracker._computations[d._id]=d;var e=!0;try{d._compute(),e=!1}finally{d.firstRun=!1,e&&d.stop()}},Tracker.Computation.prototype.onInvalidate=function(a){var b=this;if("function"!=typeof a)throw new Error("onInvalidate requires a function");b.invalidated?Tracker.nonreactive(function(){D(a)(b)}):b._onInvalidateCallbacks.push(a)},Tracker.Computation.prototype.invalidate=function(){var a=this;if(!a.invalidated){a._recomputing||a.stopped||(L(),F.push(this)),a.invalidated=!0;for(var b,c=0;b=a._onInvalidateCallbacks[c];c++)Tracker.nonreactive(function(){D(b)(a)});a._onInvalidateCallbacks=[]}},Tracker.Computation.prototype.stop=function(){this.stopped||(this.stopped=!0,this.invalidate(),delete Tracker._computations[this._id])},Tracker.Computation.prototype._compute=function(){var a=this;a.invalidated=!1;var b=Tracker.currentComputation;z(a);var c=I;I=!0;try{D(a._func)(a)}finally{z(b),I=c}},Tracker.Computation.prototype._needsRecompute=function(){var a=this;return a.invalidated&&!a.stopped},Tracker.Computation.prototype._recompute=function(){var a=this;a._recomputing=!0;try{if(a._needsRecompute())try{a._compute()}catch(b){a._onError?a._onError(b):C("recompute",b)}}finally{a._recomputing=!1}},Tracker.Dependency=function(){this._dependentsById={}},Tracker.Dependency.prototype.depend=function(a){if(!a){if(!Tracker.active)return!1;a=Tracker.currentComputation}var b=this,c=a._id;return c in b._dependentsById?!1:(b._dependentsById[c]=a,a.onInvalidate(function(){delete b._dependentsById[c]}),!0)},Tracker.Dependency.prototype.changed=function(){var a=this;for(var b in a._dependentsById)a._dependentsById[b].invalidate()},Tracker.Dependency.prototype.hasDependents=function(){var a=this;for(var b in a._dependentsById)return!0;return!1},Tracker.flush=function(a){Tracker._runFlush({finishSynchronously:!0,throwFirstError:a&&a._throwFirstError})},Tracker._runFlush=function(a){if(H)throw new Error("Can't call Tracker.flush while flushing");if(I)throw new Error("Can't flush inside Tracker.autorun");a=a||{},H=!0,G=!0,J=!!a.throwFirstError;var b=0,c=!1;try{for(;F.length||K.length;){for(;F.length;){var d=F.shift();if(d._recompute(),d._needsRecompute()&&F.unshift(d),!a.finishSynchronously&&++b>1e3)return void(c=!0)}if(K.length){var e=K.shift();try{e()}catch(f){C("afterFlush",f)}}}c=!0}finally{if(c||(H=!1,Tracker._runFlush({finishSynchronously:a.finishSynchronously,throwFirstError:!1})),G=!1,H=!1,F.length||K.length){if(a.finishSynchronously)throw new Error("still have more to do?");setTimeout(L,10)}}},Tracker.autorun=function(a,b){if("function"!=typeof a)throw new Error("Tracker.autorun requires a function argument");b=b||{},M=!0;var c=new Tracker.Computation(a,Tracker.currentComputation,b.onError);return Tracker.active&&Tracker.onInvalidate(function(){c.stop()}),c},Tracker.nonreactive=function(a){var b=Tracker.currentComputation;z(null);try{return a()}finally{z(b)}},Tracker.onInvalidate=function(a){if(!Tracker.active)throw new Error("Tracker.onInvalidate requires a currentComputation");Tracker.currentComputation.onInvalidate(a)},Tracker.afterFlush=function(a){K.push(a),L()},Meteor.flush=Tracker.flush,Meteor.autorun=Tracker.autorun,Meteor.autosubscribe=Tracker.autorun,Tracker.depend=function(a){return a.depend()},Deps=Tracker,Meteor.isServer)var N=Npm.require("crypto");var O=function(){function a(){var a=4022871197,b=function(b){b=b.toString();for(var c=0;c<b.length;c++){a+=b.charCodeAt(c);var d=.02519603282416938*a;a=d>>>0,d-=a,d*=a,a=d>>>0,d-=a,a+=4294967296*d}return 2.3283064365386963e-10*(a>>>0)};return b.version="Mash 0.9",b}return function(b){var c=0,d=0,e=0,f=1;0==b.length&&(b=[+new Date]);var g=a();c=g(" "),d=g(" "),e=g(" ");for(var h=0;h<b.length;h++)c-=g(b[h]),0>c&&(c+=1),d-=g(b[h]),0>d&&(d+=1),e-=g(b[h]),0>e&&(e+=1);g=null;var i=function(){var a=2091639*c+2.3283064365386963e-10*f;return c=d,d=e,e=a-(f=0|a)};return i.uint32=function(){return 4294967296*i()},i.fract53=function(){return i()+1.1102230246251565e-16*(2097152*i()|0)},i.version="Alea 0.9",i.args=b,i}(Array.prototype.slice.call(arguments))},P="23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz",Q="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_",R=function(a){var b=this;void 0!==a&&(b.alea=O.apply(null,a))};R.prototype.fraction=function(){var a=this;if(a.alea)return a.alea();if(N){var b=parseInt(a.hexString(8),16);return 2.3283064365386963e-10*b}if("undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues){var c=new Uint32Array(1);return window.crypto.getRandomValues(c),2.3283064365386963e-10*c[0]}throw new Error("No random generator available")},R.prototype.hexString=function(a){var b=this;if(N&&!b.alea){var c,d=Math.ceil(a/2);try{c=N.randomBytes(d)}catch(e){c=N.pseudoRandomBytes(d)}var f=c.toString("hex");return f.substring(0,a)}for(var g=[],h=0;a>h;++h)g.push(b.choice("0123456789abcdef"));return g.join("")},R.prototype._randomString=function(a,b){for(var c=this,d=[],e=0;a>e;e++)d[e]=c.choice(b);return d.join("")},R.prototype.id=function(a){var b=this;return void 0===a&&(a=17),b._randomString(a,P)},R.prototype.secret=function(a){var b=this;return void 0===a&&(a=43),b._randomString(a,Q)},R.prototype.choice=function(a){var b=Math.floor(this.fraction()*a.length);return"string"==typeof a?a.substr(b,1):a[b]};var S="undefined"!=typeof window&&window.innerHeight||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientHeight||"undefined"!=typeof document&&document.body&&document.body.clientHeight||1,T="undefined"!=typeof window&&window.innerWidth||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientWidth||"undefined"!=typeof document&&document.body&&document.body.clientWidth||1,U="undefined"!=typeof navigator&&navigator.userAgent||"";N||"undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues?Random=new R:Random=new R([new Date,S,T,U,Math.random()]),Random.createWithSeeds=function(){if(0===arguments.length)throw new Error("No seeds were provided");return new R(arguments)},module={exports:{}},function(){function a(a){for(var b=[],c=[],d=0;d<a[0].length;d++)b.push(a[0][d][1]),c.push(a[0][d][0]);return b=b.sort(function(a,b){return a-b}),c=c.sort(function(a,b){return a-b}),[[b[0],c[0]],[b[b.length-1],c[c.length-1]]]}function b(a,b,c){for(var d=[[0,0]],e=0;e<c.length;e++){for(var f=0;f<c[e].length;f++)d.push(c[e][f]);d.push([0,0])}for(var g=!1,e=0,f=d.length-1;e<d.length;f=e++)d[e][0]>b!=d[f][0]>b&&a<(d[f][1]-d[e][1])*(b-d[e][0])/(d[f][0]-d[e][0])+d[e][1]&&(g=!g);return g}var c={};"undefined"!=typeof module&&module.exports&&(module.exports=c),c.lineStringsIntersect=function(a,b){for(var c=[],d=0;d<=a.coordinates.length-2;++d)for(var e=0;e<=b.coordinates.length-2;++e){var f={x:a.coordinates[d][1],y:a.coordinates[d][0]},g={x:a.coordinates[d+1][1],y:a.coordinates[d+1][0]},h={x:b.coordinates[e][1],y:b.coordinates[e][0]},i={x:b.coordinates[e+1][1],y:b.coordinates[e+1][0]},j=(i.x-h.x)*(f.y-h.y)-(i.y-h.y)*(f.x-h.x),k=(g.x-f.x)*(f.y-h.y)-(g.y-f.y)*(f.x-h.x),l=(i.y-h.y)*(g.x-f.x)-(i.x-h.x)*(g.y-f.y);if(0!=l){var m=j/l,n=k/l;m>=0&&1>=m&&n>=0&&1>=n&&c.push({type:"Point",coordinates:[f.x+m*(g.x-f.x),f.y+m*(g.y-f.y)]})}}return 0==c.length&&(c=!1),c},c.pointInBoundingBox=function(a,b){return!(a.coordinates[1]<b[0][0]||a.coordinates[1]>b[1][0]||a.coordinates[0]<b[0][1]||a.coordinates[0]>b[1][1])},c.pointInPolygon=function(d,e){for(var f="Polygon"==e.type?[e.coordinates]:e.coordinates,g=!1,h=0;h<f.length;h++)c.pointInBoundingBox(d,a(f[h]))&&(g=!0);if(!g)return!1;for(var i=!1,h=0;h<f.length;h++)b(d.coordinates[1],d.coordinates[0],f[h])&&(i=!0);return i},c.numberToRadius=function(a){return a*Math.PI/180},c.numberToDegree=function(a){return 180*a/Math.PI},c.drawCircle=function(a,b,d){for(var e=[b.coordinates[1],b.coordinates[0]],f=a/1e3/6371,g=[c.numberToRadius(e[0]),c.numberToRadius(e[1])],d=d||15,h=[[e[0],e[1]]],i=0;d>i;i++){var j=2*Math.PI*i/d,k=Math.asin(Math.sin(g[0])*Math.cos(f)+Math.cos(g[0])*Math.sin(f)*Math.cos(j)),l=g[1]+Math.atan2(Math.sin(j)*Math.sin(f)*Math.cos(g[0]),Math.cos(f)-Math.sin(g[0])*Math.sin(k));h[i]=[],h[i][1]=c.numberToDegree(k),h[i][0]=c.numberToDegree(l)}return{type:"Polygon",coordinates:[h]}},c.rectangleCentroid=function(a){var b=a.coordinates[0],c=b[0][0],d=b[0][1],e=b[2][0],f=b[2][1],g=e-c,h=f-d;return{type:"Point",coordinates:[c+g/2,d+h/2]}},c.pointDistance=function(a,b){var d=a.coordinates[0],e=a.coordinates[1],f=b.coordinates[0],g=b.coordinates[1],h=c.numberToRadius(g-e),i=c.numberToRadius(f-d),j=Math.pow(Math.sin(h/2),2)+Math.cos(c.numberToRadius(e))*Math.cos(c.numberToRadius(g))*Math.pow(Math.sin(i/2),2),k=2*Math.atan2(Math.sqrt(j),Math.sqrt(1-j));return 6371*k*1e3},c.geometryWithinRadius=function(a,b,d){if("Point"==a.type)return c.pointDistance(a,b)<=d;if("LineString"==a.type||"Polygon"==a.type){var e,f={};e="Polygon"==a.type?a.coordinates[0]:a.coordinates;for(var g in e)if(f.coordinates=e[g],c.pointDistance(f,b)>d)return!1}return!0},c.area=function(a){for(var b,c,d=0,e=a.coordinates[0],f=e.length-1,g=0;g<e.length;f=g++){var b={x:e[g][1],y:e[g][0]},c={x:e[f][1],y:e[f][0]};d+=b.x*c.y,d-=b.y*c.x}return d/=2},c.centroid=function(a){for(var b,d,e,f=0,g=0,h=a.coordinates[0],i=h.length-1,j=0;j<h.length;i=j++){var d={x:h[j][1],y:h[j][0]},e={x:h[i][1],y:h[i][0]};b=d.x*e.y-e.x*d.y,f+=(d.x+e.x)*b,g+=(d.y+e.y)*b}return b=6*c.area(a),{type:"Point",coordinates:[g/b,f/b]}},c.simplify=function(a,b){b=b||20,a=a.map(function(a){return{lng:a.coordinates[0],lat:a.coordinates[1]}});var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v=Math.PI/180*.5,w=new Array,x=new Array,y=new Array;if(a.length<3)return a;for(c=a.length,l=360*b/(2*Math.PI*6378137),l*=l,e=0,x[0]=0,y[0]=c-1,d=1;d>0;)if(f=x[d-1],g=y[d-1],d--,g-f>1){for(m=a[g].lng()-a[f].lng(),n=a[g].lat()-a[f].lat(),Math.abs(m)>180&&(m=360-Math.abs(m)),m*=Math.cos(v*(a[g].lat()+a[f].lat())),o=m*m+n*n,h=f+1,i=f,k=-1;g>h;h++)p=a[h].lng()-a[f].lng(),q=a[h].lat()-a[f].lat(),Math.abs(p)>180&&(p=360-Math.abs(p)),p*=Math.cos(v*(a[h].lat()+a[f].lat())),r=p*p+q*q,s=a[h].lng()-a[g].lng(),t=a[h].lat()-a[g].lat(),Math.abs(s)>180&&(s=360-Math.abs(s)),s*=Math.cos(v*(a[h].lat()+a[g].lat())),u=s*s+t*t,j=r>=o+u?u:u>=o+r?r:(p*n-q*m)*(p*n-q*m)/o,j>k&&(i=h,k=j);l>k?(w[e]=f,e++):(d++,x[d-1]=i,y[d-1]=g,d++,x[d-1]=f,y[d-1]=i)}else w[e]=f,e++;w[e]=c-1,e++;for(var z=new Array,h=0;e>h;h++)z.push(a[w[h]]);return z.map(function(a){return{type:"Point",coordinates:[a.lng,a.lat]}})},c.destinationPoint=function(a,b,d){d/=6371,b=c.numberToRadius(b);var e=c.numberToRadius(a.coordinates[0]),f=c.numberToRadius(a.coordinates[1]),g=Math.asin(Math.sin(e)*Math.cos(d)+Math.cos(e)*Math.sin(d)*Math.cos(b)),h=f+Math.atan2(Math.sin(b)*Math.sin(d)*Math.cos(e),Math.cos(d)-Math.sin(e)*Math.sin(g));return h=(h+3*Math.PI)%(2*Math.PI)-Math.PI,{type:"Point",coordinates:[c.numberToDegree(g),c.numberToDegree(h)]}}}(),GeoJSON=module.exports,LocalCollection=function(a){var b=this;b.name=a,b._docs=new LocalCollection._IdMap,b._observeQueue=new Meteor._SynchronousQueue,b.next_qid=1,b.queries={},b._savedOriginals=null,b.paused=!1},Minimongo={},MinimongoTest={},LocalCollection._applyChanges=function(a,b){_.each(b,function(b,c){void 0===b?delete a[c]:a[c]=b})},MinimongoError=function(a){var b=new Error(a);return b.name="MinimongoError",b},LocalCollection.prototype.find=function(a,b){return 0===arguments.length&&(a={}),new LocalCollection.Cursor(this,a,b)},LocalCollection.Cursor=function(a,b,c){var d=this;c||(c={}),d.collection=a,d.sorter=null,LocalCollection._selectorIsId(b)?(d._selectorId=b,d.matcher=new Minimongo.Matcher(b)):(d._selectorId=void 0,d.matcher=new Minimongo.Matcher(b),(d.matcher.hasGeoQuery()||c.sort)&&(d.sorter=new Minimongo.Sorter(c.sort||[],{matcher:d.matcher}))),d.skip=c.skip,d.limit=c.limit,d.fields=c.fields,d._projectionFn=LocalCollection._compileProjection(d.fields||{}),d._transform=LocalCollection.wrapTransform(c.transform),"undefined"!=typeof Tracker&&(d.reactive=void 0===c.reactive?!0:c.reactive)},LocalCollection.Cursor.prototype.rewind=function(){},LocalCollection.prototype.findOne=function(a,b){return 0===arguments.length&&(a={}),b=b||{},b.limit=1,this.find(a,b).fetch()[0]},LocalCollection.Cursor.prototype.forEach=function(a,b){var c=this,d=c._getRawObjects({ordered:!0});c.reactive&&c._depend({addedBefore:!0,removed:!0,changed:!0,movedBefore:!0}),_.each(d,function(d,e){d=c._projectionFn(d),c._transform&&(d=c._transform(d)),a.call(b,d,e,c)})},LocalCollection.Cursor.prototype.getTransform=function(){return this._transform},LocalCollection.Cursor.prototype.map=function(a,b){var c=this,d=[];return c.forEach(function(e,f){d.push(a.call(b,e,f,c))}),d},LocalCollection.Cursor.prototype.fetch=function(){var a=this,b=[];return a.forEach(function(a){b.push(a)}),b},LocalCollection.Cursor.prototype.count=function(){var a=this;return a.reactive&&a._depend({added:!0,removed:!0},!0),a._getRawObjects({ordered:!0}).length},LocalCollection.Cursor.prototype._publishCursor=function(a){var b=this;if(!b.collection.name)throw new Error("Can't publish a cursor from a collection without a name.");var c=b.collection.name;return Mongo.Collection._publishCursor(b,a,c)},LocalCollection.Cursor.prototype._getCollectionName=function(){var a=this;return a.collection.name},LocalCollection._observeChangesCallbacksAreOrdered=function(a){if(a.added&&a.addedBefore)throw new Error("Please specify only one of added() and addedBefore()");return!(!a.addedBefore&&!a.movedBefore)},LocalCollection._observeCallbacksAreOrdered=function(a){if(a.addedAt&&a.added)throw new Error("Please specify only one of added() and addedAt()");if(a.changedAt&&a.changed)throw new Error("Please specify only one of changed() and changedAt()");if(a.removed&&a.removedAt)throw new Error("Please specify only one of removed() and removedAt()");return!!(a.addedAt||a.movedTo||a.changedAt||a.removedAt)},LocalCollection.ObserveHandle=function(){},_.extend(LocalCollection.Cursor.prototype,{observe:function(a){var b=this;return LocalCollection._observeFromObserveChanges(b,a)},observeChanges:function(a){var b=this,c=LocalCollection._observeChangesCallbacksAreOrdered(a);if(!a._allow_unordered&&!c&&(b.skip||b.limit))throw new Error("must use ordered observe (ie, 'addedBefore' instead of 'added') with skip or limit");if(b.fields&&(0===b.fields._id||b.fields._id===!1))throw Error("You may not observe a cursor with {fields: {_id: 0}}");var d,e={matcher:b.matcher,sorter:c&&b.sorter,distances:b.matcher.hasGeoQuery()&&c&&new LocalCollection._IdMap,resultsSnapshot:null,ordered:c,cursor:b,projectionFn:b._projectionFn};b.reactive&&(d=b.collection.next_qid++,b.collection.queries[d]=e),e.results=b._getRawObjects({ordered:c,distances:e.distances}),b.collection.paused&&(e.resultsSnapshot=c?[]:new LocalCollection._IdMap);var f=function(a){return a?function(){var c=this,d=arguments;b.collection.paused||b.collection._observeQueue.queueTask(function(){a.apply(c,d)})}:function(){}};if(e.added=f(a.added),e.changed=f(a.changed),e.removed=f(a.removed),c&&(e.addedBefore=f(a.addedBefore),e.movedBefore=f(a.movedBefore)),!a._suppress_initial&&!b.collection.paused){var g=c?_.bind(_.each,null,e.results):_.bind(e.results.forEach,e.results);g(function(a){var d=EJSON.clone(a);delete d._id,c&&e.addedBefore(a._id,b._projectionFn(d),null),e.added(a._id,b._projectionFn(d))})}var h=new LocalCollection.ObserveHandle;return _.extend(h,{collection:b.collection,stop:function(){b.reactive&&delete b.collection.queries[d];
}}),b.reactive&&Tracker.active&&Tracker.onInvalidate(function(){h.stop()}),b.collection._observeQueue.drain(),h}}),LocalCollection.Cursor.prototype._getRawObjects=function(a){var b=this;a=a||{};var c=a.ordered?[]:new LocalCollection._IdMap;if(void 0!==b._selectorId){if(b.skip)return c;var d=b.collection._docs.get(b._selectorId);return d&&(a.ordered?c.push(d):c.set(b._selectorId,d)),c}var e;if(b.matcher.hasGeoQuery()&&a.ordered&&(a.distances?(e=a.distances,e.clear()):e=new LocalCollection._IdMap),b.collection._docs.forEach(function(d,f){var g=b.matcher.documentMatches(d);return g.result&&(a.ordered?(c.push(d),e&&void 0!==g.distance&&e.set(f,g.distance)):c.set(f,d)),!b.limit||b.skip||b.sorter||c.length!==b.limit?!0:!1}),!a.ordered)return c;if(b.sorter){var f=b.sorter.getComparator({distances:e});c.sort(f)}var g=b.skip||0,h=b.limit?b.limit+g:c.length;return c.slice(g,h)},LocalCollection.Cursor.prototype._depend=function(a,b){var c=this;if(Tracker.active){var d=new Tracker.Dependency;d.depend();var e=_.bind(d.changed,d),f={_suppress_initial:!0,_allow_unordered:b};_.each(["added","changed","removed","addedBefore","movedBefore"],function(b){a[b]&&(f[b]=e)}),c.observeChanges(f)}},LocalCollection.prototype.insert=function(a,b){var c=this;a=EJSON.clone(a),_.has(a,"_id")||(a._id=LocalCollection._useOID?new LocalCollection._ObjectID:Random.id());var d=a._id;if(c._docs.has(d))throw MinimongoError("Duplicate _id '"+d+"'");c._saveOriginal(d,void 0),c._docs.set(d,a);var e=[];for(var f in c.queries){var g=c.queries[f],h=g.matcher.documentMatches(a);h.result&&(g.distances&&void 0!==h.distance&&g.distances.set(d,h.distance),g.cursor.skip||g.cursor.limit?e.push(f):LocalCollection._insertInResults(g,a))}return _.each(e,function(a){c.queries[a]&&c._recomputeResults(c.queries[a])}),c._observeQueue.drain(),b&&Meteor.defer(function(){b(null,d)}),d},LocalCollection.prototype._eachPossiblyMatchingDoc=function(a,b){var c=this,d=LocalCollection._idsMatchedBySelector(a);if(d)for(var e=0;e<d.length;++e){var f=d[e],g=c._docs.get(f);if(g){var h=b(g,f);if(h===!1)break}}else c._docs.forEach(b)},LocalCollection.prototype.remove=function(a,b){var c=this;if(c.paused&&!c._savedOriginals&&EJSON.equals(a,{})){var d=c._docs.size();return c._docs.clear(),_.each(c.queries,function(a){a.ordered?a.results=[]:a.results.clear()}),b&&Meteor.defer(function(){b(null,d)}),d}var e=new Minimongo.Matcher(a),f=[];c._eachPossiblyMatchingDoc(a,function(a,b){e.documentMatches(a).result&&f.push(b)});for(var g=[],h=[],i=0;i<f.length;i++){var j=f[i],k=c._docs.get(j);_.each(c.queries,function(a,b){a.matcher.documentMatches(k).result&&(a.cursor.skip||a.cursor.limit?g.push(b):h.push({qid:b,doc:k}))}),c._saveOriginal(j,k),c._docs.remove(j)}return _.each(h,function(a){var b=c.queries[a.qid];b&&(b.distances&&b.distances.remove(a.doc._id),LocalCollection._removeFromResults(b,a.doc))}),_.each(g,function(a){var b=c.queries[a];b&&c._recomputeResults(b)}),c._observeQueue.drain(),d=f.length,b&&Meteor.defer(function(){b(null,d)}),d},LocalCollection.prototype.update=function(a,b,c,d){var e=this;!d&&c instanceof Function&&(d=c,c=null),c||(c={});var f=new Minimongo.Matcher(a),g={};_.each(e.queries,function(a,b){!a.cursor.skip&&!a.cursor.limit||e.paused||(g[b]=EJSON.clone(a.results))});var h={},i=0;e._eachPossiblyMatchingDoc(a,function(a,d){var g=f.documentMatches(a);return g.result&&(e._saveOriginal(d,a),e._modifyAndNotify(a,b,h,g.arrayIndices),++i,!c.multi)?!1:!0}),_.each(h,function(a,b){var c=e.queries[b];c&&e._recomputeResults(c,g[b])}),e._observeQueue.drain();var j;if(0===i&&c.upsert){var k=LocalCollection._removeDollarOperators(a);LocalCollection._modify(k,b,{isInsert:!0}),!k._id&&c.insertedId&&(k._id=c.insertedId),j=e.insert(k),i=1}var l;return c._returnObject?(l={numberAffected:i},void 0!==j&&(l.insertedId=j)):l=i,d&&Meteor.defer(function(){d(null,l)}),l},LocalCollection.prototype.upsert=function(a,b,c,d){var e=this;return d||"function"!=typeof c||(d=c,c={}),e.update(a,b,_.extend({},c,{upsert:!0,_returnObject:!0}),d)},LocalCollection.prototype._modifyAndNotify=function(a,b,c,d){var e=this,f={};for(var g in e.queries){var h=e.queries[g];h.ordered?f[g]=h.matcher.documentMatches(a).result:f[g]=h.results.has(a._id)}var i=EJSON.clone(a);LocalCollection._modify(a,b,{arrayIndices:d});for(g in e.queries){h=e.queries[g];var j=f[g],k=h.matcher.documentMatches(a),l=k.result;l&&h.distances&&void 0!==k.distance&&h.distances.set(a._id,k.distance),h.cursor.skip||h.cursor.limit?(j||l)&&(c[g]=!0):j&&!l?LocalCollection._removeFromResults(h,a):!j&&l?LocalCollection._insertInResults(h,a):j&&l&&LocalCollection._updateInResults(h,a,i)}},LocalCollection._insertInResults=function(a,b){var c=EJSON.clone(b);if(delete c._id,a.ordered){if(a.sorter){var d=LocalCollection._insertInSortedList(a.sorter.getComparator({distances:a.distances}),a.results,b),e=a.results[d+1];e=e?e._id:null,a.addedBefore(b._id,a.projectionFn(c),e)}else a.addedBefore(b._id,a.projectionFn(c),null),a.results.push(b);a.added(b._id,a.projectionFn(c))}else a.added(b._id,a.projectionFn(c)),a.results.set(b._id,b)},LocalCollection._removeFromResults=function(a,b){if(a.ordered){var c=LocalCollection._findInOrderedResults(a,b);a.removed(b._id),a.results.splice(c,1)}else{var d=b._id;a.removed(b._id),a.results.remove(d)}},LocalCollection._updateInResults=function(a,b,c){if(!EJSON.equals(b._id,c._id))throw new Error("Can't change a doc's _id while updating");var d=a.projectionFn,e=LocalCollection._makeChangedFields(d(b),d(c));if(!a.ordered)return void(_.isEmpty(e)||(a.changed(b._id,e),a.results.set(b._id,b)));var f=LocalCollection._findInOrderedResults(a,b);if(_.isEmpty(e)||a.changed(b._id,e),a.sorter){a.results.splice(f,1);var g=LocalCollection._insertInSortedList(a.sorter.getComparator({distances:a.distances}),a.results,b);if(f!==g){var h=a.results[g+1];h=h?h._id:null,a.movedBefore&&a.movedBefore(b._id,h)}}},LocalCollection.prototype._recomputeResults=function(a,b){var c=this;c.paused||b||(b=a.results),a.distances&&a.distances.clear(),a.results=a.cursor._getRawObjects({ordered:a.ordered,distances:a.distances}),c.paused||LocalCollection._diffQueryChanges(a.ordered,b,a.results,a,{projectionFn:a.projectionFn})},LocalCollection._findInOrderedResults=function(a,b){if(!a.ordered)throw new Error("Can't call _findInOrderedResults on unordered query");for(var c=0;c<a.results.length;c++)if(a.results[c]===b)return c;throw Error("object missing from query")},LocalCollection._binarySearch=function(a,b,c){for(var d=0,e=b.length;e>0;){var f=Math.floor(e/2);a(c,b[d+f])>=0?(d+=f+1,e-=f+1):e=f}return d},LocalCollection._insertInSortedList=function(a,b,c){if(0===b.length)return b.push(c),0;var d=LocalCollection._binarySearch(a,b,c);return b.splice(d,0,c),d},LocalCollection.prototype.saveOriginals=function(){var a=this;if(a._savedOriginals)throw new Error("Called saveOriginals twice without retrieveOriginals");a._savedOriginals=new LocalCollection._IdMap},LocalCollection.prototype.retrieveOriginals=function(){var a=this;if(!a._savedOriginals)throw new Error("Called retrieveOriginals without saveOriginals");var b=a._savedOriginals;return a._savedOriginals=null,b},LocalCollection.prototype._saveOriginal=function(a,b){var c=this;c._savedOriginals&&(c._savedOriginals.has(a)||c._savedOriginals.set(a,EJSON.clone(b)))},LocalCollection.prototype.pauseObservers=function(){if(!this.paused){this.paused=!0;for(var a in this.queries){var b=this.queries[a];b.resultsSnapshot=EJSON.clone(b.results)}}},LocalCollection.prototype.resumeObservers=function(){var a=this;if(this.paused){this.paused=!1;for(var b in this.queries){var c=a.queries[b];LocalCollection._diffQueryChanges(c.ordered,c.resultsSnapshot,c.results,c,{projectionFn:c.projectionFn}),c.resultsSnapshot=null}a._observeQueue.drain()}},LocalCollection._idStringify=function(a){if(a instanceof LocalCollection._ObjectID)return a.valueOf();if("string"==typeof a)return""===a?a:"-"===a.substr(0,1)||"~"===a.substr(0,1)||LocalCollection._looksLikeObjectID(a)||"{"===a.substr(0,1)?"-"+a:a;if(void 0===a)return"-";if("object"==typeof a&&null!==a)throw new Error("Meteor does not currently support objects other than ObjectID as ids");return"~"+JSON.stringify(a)},LocalCollection._idParse=function(a){return""===a?a:"-"===a?void 0:"-"===a.substr(0,1)?a.substr(1):"~"===a.substr(0,1)?JSON.parse(a.substr(1)):LocalCollection._looksLikeObjectID(a)?new LocalCollection._ObjectID(a):a},LocalCollection._makeChangedFields=function(a,b){var c={};return LocalCollection._diffObjects(b,a,{leftOnly:function(a,b){c[a]=void 0},rightOnly:function(a,b){c[a]=b},both:function(a,b,d){EJSON.equals(b,d)||(c[a]=d)}}),c},LocalCollection.wrapTransform=function(a){if(!a)return null;if(a.__wrappedTransform__)return a;var b=function(b){if(!_.has(b,"_id"))throw new Error("can only transform documents with _id");var c=b._id,d=Tracker.nonreactive(function(){return a(b)});if(!isPlainObject(d))throw new Error("transform must return object");if(_.has(d,"_id")){if(!EJSON.equals(d._id,c))throw new Error("transformed document can't have different _id")}else d._id=c;return d};return b.__wrappedTransform__=!0,b},isArray=function(a){return _.isArray(a)&&!EJSON.isBinary(a)},isPlainObject=LocalCollection._isPlainObject=function(a){return a&&3===LocalCollection._f._type(a)},isIndexable=function(a){return isArray(a)||isPlainObject(a)},isOperatorObject=function(a,b){if(!isPlainObject(a))return!1;var c=void 0;return _.each(a,function(d,e){var f="$"===e.substr(0,1);if(void 0===c)c=f;else if(c!==f){if(!b)throw new Error("Inconsistent operator: "+JSON.stringify(a));c=!1}}),!!c},isNumericKey=function(a){return/^[0-9]+$/.test(a)},Minimongo.Matcher=function(a){var b=this;b._paths={},b._hasGeoQuery=!1,b._hasWhere=!1,b._isSimple=!0,b._matchingDocument=void 0,b._selector=null,b._docMatcher=b._compileSelector(a)},_.extend(Minimongo.Matcher.prototype,{documentMatches:function(a){if(!a||"object"!=typeof a)throw Error("documentMatches needs a document");return this._docMatcher(a)},hasGeoQuery:function(){return this._hasGeoQuery},hasWhere:function(){return this._hasWhere},isSimple:function(){return this._isSimple},_compileSelector:function(a){var b=this;if(a instanceof Function)return b._isSimple=!1,b._selector=a,b._recordPathUsed(""),function(b){return{result:!!a.call(b)}};if(LocalCollection._selectorIsId(a))return b._selector={_id:a},b._recordPathUsed("_id"),function(b){return{result:EJSON.equals(b._id,a)}};if(!a||"_id"in a&&!a._id)return b._isSimple=!1,fa;if("boolean"==typeof a||isArray(a)||EJSON.isBinary(a))throw new Error("Invalid selector: "+a);return b._selector=EJSON.clone(a),V(a,b,{isRoot:!0})},_recordPathUsed:function(a){this._paths[a]=!0},_getPaths:function(){return _.keys(this._paths)}});var V=function(a,b,c){c=c||{};var d=[];return _.each(a,function(a,e){if("$"===e.substr(0,1)){if(!_.has($,e))throw new Error("Unrecognized logical operator: "+e);b._isSimple=!1,d.push($[e](a,b,c.inElemMatch))}else{c.inElemMatch||b._recordPathUsed(e);var f=makeLookupFunction(e),g=W(a,b,c.isRoot);d.push(function(a){var b=f(a);return g(b)})}}),ia(d)},W=function(a,b,c){return a instanceof RegExp?(b._isSimple=!1,X(regexpElementMatcher(a))):isOperatorObject(a)?Y(a,b,c):X(equalityElementMatcher(a))},X=function(a,b){return b=b||{},function(c){var d=c;b.dontExpandLeafArrays||(d=expandArraysInBranches(c,b.dontIncludeLeafArrays));var e={};return e.result=_.any(d,function(b){var c=a(b.value);return"number"==typeof c&&(b.arrayIndices||(b.arrayIndices=[c]),c=!0),c&&b.arrayIndices&&(e.arrayIndices=b.arrayIndices),c}),e}};regexpElementMatcher=function(a){return function(b){return b instanceof RegExp?_.isEqual(b,a):"string"!=typeof b?!1:(a.lastIndex=0,a.test(b))}},equalityElementMatcher=function(a){if(isOperatorObject(a))throw Error("Can't create equalityValueSelector for operator object");return null==a?function(a){return null==a}:function(b){return LocalCollection._f._equal(a,b)}};var Y=function(a,b,c){var d=[];return _.each(a,function(e,f){var g=_.contains(["$lt","$lte","$gt","$gte"],f)&&_.isNumber(e),h="$ne"===f&&!_.isObject(e),i=_.contains(["$in","$nin"],f)&&_.isArray(e)&&!_.any(e,_.isObject);if("$eq"===f||g||i||h||(b._isSimple=!1),_.has(ba,f))d.push(ba[f](e,a,b,c));else{if(!_.has(ELEMENT_OPERATORS,f))throw new Error("Unrecognized operator: "+f);var j=ELEMENT_OPERATORS[f];d.push(X(j.compileElementSelector(e,a,b),j))}}),ja(d)},Z=function(a,b,c){if(!isArray(a)||_.isEmpty(a))throw Error("$and/$or/$nor must be nonempty array");return _.map(a,function(a){if(!isPlainObject(a))throw Error("$or/$and/$nor entries need to be full objects");return V(a,b,{inElemMatch:c})})},$={$and:function(a,b,c){var d=Z(a,b,c);return ia(d)},$or:function(a,b,c){var d=Z(a,b,c);return 1===d.length?d[0]:function(a){var b=_.any(d,function(b){return b(a).result});return{result:b}}},$nor:function(a,b,c){var d=Z(a,b,c);return function(a){var b=_.all(d,function(b){return!b(a).result});return{result:b}}},$where:function(a,b){return b._recordPathUsed(""),b._hasWhere=!0,a instanceof Function||(a=Function("obj","return "+a)),function(b){return{result:a.call(b,b)}}},$comment:function(){return function(){return{result:!0}}}},aa=function(a){return function(b){var c=a(b);return{result:!c.result}}},ba={$not:function(a,b,c){return aa(W(a,c))},$ne:function(a){return aa(X(equalityElementMatcher(a)))},$nin:function(a){return aa(X(ELEMENT_OPERATORS.$in.compileElementSelector(a)))},$exists:function(a){var b=X(function(a){return void 0!==a});return a?b:aa(b)},$options:function(a,b){if(!_.has(b,"$regex"))throw Error("$options needs a $regex");return ga},$maxDistance:function(a,b){if(!b.$near)throw Error("$maxDistance needs a $near");return ga},$all:function(a,b,c){if(!isArray(a))throw Error("$all requires array");if(_.isEmpty(a))return fa;var d=[];return _.each(a,function(a){if(isOperatorObject(a))throw Error("no $ expressions in $all");d.push(W(a,c))}),ja(d)},$near:function(a,b,c,d){if(!d)throw Error("$near can't be inside another $ operator");c._hasGeoQuery=!0;var e,f,g;if(isPlainObject(a)&&_.has(a,"$geometry"))e=a.$maxDistance,f=a.$geometry,g=function(a){return a&&a.type?"Point"===a.type?GeoJSON.pointDistance(f,a):GeoJSON.geometryWithinRadius(a,f,e)?0:e+1:null};else{if(e=b.$maxDistance,!isArray(a)&&!isPlainObject(a))throw Error("$near argument must be coordinate pair or GeoJSON");f=da(a),g=function(a){return isArray(a)||isPlainObject(a)?ca(f,a):null}}return function(a){a=expandArraysInBranches(a);var b={result:!1};return _.each(a,function(a){var c=g(a.value);null===c||c>e||void 0!==b.distance&&b.distance<=c||(b.result=!0,b.distance=c,a.arrayIndices?b.arrayIndices=a.arrayIndices:delete b.arrayIndices)}),b}}},ca=function(a,b){a=da(a),b=da(b);var c=a[0]-b[0],d=a[1]-b[1];return _.isNaN(c)||_.isNaN(d)?null:Math.sqrt(c*c+d*d)},da=function(a){return _.map(a,_.identity)},ea=function(a){return{compileElementSelector:function(b){if(isArray(b))return function(){return!1};void 0===b&&(b=null);var c=LocalCollection._f._type(b);return function(d){return void 0===d&&(d=null),LocalCollection._f._type(d)!==c?!1:a(LocalCollection._f._cmp(d,b))}}}};ELEMENT_OPERATORS={$lt:ea(function(a){return 0>a}),$gt:ea(function(a){return a>0}),$lte:ea(function(a){return 0>=a}),$gte:ea(function(a){return a>=0}),$mod:{compileElementSelector:function(a){if(!isArray(a)||2!==a.length||"number"!=typeof a[0]||"number"!=typeof a[1])throw Error("argument to $mod must be an array of two numbers");var b=a[0],c=a[1];return function(a){return"number"==typeof a&&a%b===c}}},$in:{compileElementSelector:function(a){if(!isArray(a))throw Error("$in needs an array");var b=[];return _.each(a,function(a){if(a instanceof RegExp)b.push(regexpElementMatcher(a));else{if(isOperatorObject(a))throw Error("cannot nest $ under $in");b.push(equalityElementMatcher(a))}}),function(a){return void 0===a&&(a=null),_.any(b,function(b){return b(a)})}}},$size:{dontExpandLeafArrays:!0,compileElementSelector:function(a){if("string"==typeof a)a=0;else if("number"!=typeof a)throw Error("$size needs a number");return function(b){return isArray(b)&&b.length===a}}},$type:{dontIncludeLeafArrays:!0,compileElementSelector:function(a){if("number"!=typeof a)throw Error("$type needs a number");return function(b){return void 0!==b&&LocalCollection._f._type(b)===a}}},$regex:{compileElementSelector:function(a,b){if(!("string"==typeof a||a instanceof RegExp))throw Error("$regex has to be a string or RegExp");var c;if(void 0!==b.$options){if(/[^gim]/.test(b.$options))throw new Error("Only the i, m, and g regexp options are supported");var d=a instanceof RegExp?a.source:a;c=new RegExp(d,b.$options)}else c=a instanceof RegExp?a:new RegExp(a);return regexpElementMatcher(c)}},$elemMatch:{dontExpandLeafArrays:!0,compileElementSelector:function(a,b,c){if(!isPlainObject(a))throw Error("$elemMatch need an object");var d,e;return isOperatorObject(a,!0)?(d=W(a,c),e=!1):(d=V(a,c,{inElemMatch:!0}),e=!0),function(a){if(!isArray(a))return!1;for(var b=0;b<a.length;++b){var c,f=a[b];if(e){if(!isPlainObject(f)&&!isArray(f))return!1;c=f}else c=[{value:f,dontIterate:!0}];if(d(c).result)return b}return!1}}}},makeLookupFunction=function(a,b){b=b||{};var c,d=a.split("."),e=d.length?d[0]:"",f=isNumericKey(e),g=d.length>=2&&isNumericKey(d[1]);d.length>1&&(c=makeLookupFunction(d.slice(1).join(".")));var h=function(a){return a.dontIterate||delete a.dontIterate,a.arrayIndices&&!a.arrayIndices.length&&delete a.arrayIndices,a};return function(a,d){if(d||(d=[]),isArray(a)){if(!(f&&e<a.length))return[];d=d.concat(+e,"x")}var i=a[e];if(!c)return[h({value:i,dontIterate:isArray(a)&&isArray(i),arrayIndices:d})];if(!isIndexable(i))return isArray(a)?[]:[h({value:void 0,arrayIndices:d})];var j=[],k=function(a){Array.prototype.push.apply(j,a)};return k(c(i,d)),!isArray(i)||g&&b.forSort||_.each(i,function(a,b){isPlainObject(a)&&k(c(a,d.concat(b)))}),j}},MinimongoTest.makeLookupFunction=makeLookupFunction,expandArraysInBranches=function(a,b){var c=[];return _.each(a,function(a){var d=isArray(a.value);b&&d&&!a.dontIterate||c.push({value:a.value,arrayIndices:a.arrayIndices}),d&&!a.dontIterate&&_.each(a.value,function(b,d){c.push({value:b,arrayIndices:(a.arrayIndices||[]).concat(d)})})}),c};var fa=function(a){return{result:!1}},ga=function(a){return{result:!0}},ha=function(a){return 0===a.length?ga:1===a.length?a[0]:function(b){var c={};return c.result=_.all(a,function(a){var d=a(b);return d.result&&void 0!==d.distance&&void 0===c.distance&&(c.distance=d.distance),d.result&&d.arrayIndices&&(c.arrayIndices=d.arrayIndices),d.result}),c.result||(delete c.distance,delete c.arrayIndices),c}},ia=ha,ja=ha;LocalCollection._f={_type:function(a){return"number"==typeof a?1:"string"==typeof a?2:"boolean"==typeof a?8:isArray(a)?4:null===a?10:a instanceof RegExp?11:"function"==typeof a?13:a instanceof Date?9:EJSON.isBinary(a)?5:a instanceof LocalCollection._ObjectID?7:3},_equal:function(a,b){return EJSON.equals(a,b,{keyOrderSensitive:!0})},_typeorder:function(a){return[-1,1,2,3,4,5,-1,6,7,8,0,9,-1,100,2,100,1,8,1][a]},_cmp:function(a,b){if(void 0===a)return void 0===b?0:-1;if(void 0===b)return 1;var c=LocalCollection._f._type(a),d=LocalCollection._f._type(b),e=LocalCollection._f._typeorder(c),f=LocalCollection._f._typeorder(d);if(e!==f)return f>e?-1:1;if(c!==d)throw Error("Missing type coercion logic in _cmp");if(7===c&&(c=d=2,a=a.toHexString(),b=b.toHexString()),9===c&&(c=d=1,a=a.getTime(),b=b.getTime()),1===c)return a-b;if(2===d)return b>a?-1:a===b?0:1;if(3===c){var g=function(a){var b=[];for(var c in a)b.push(c),b.push(a[c]);return b};return LocalCollection._f._cmp(g(a),g(b))}if(4===c)for(var h=0;;h++){if(h===a.length)return h===b.length?0:-1;if(h===b.length)return 1;var i=LocalCollection._f._cmp(a[h],b[h]);if(0!==i)return i}if(5===c){if(a.length!==b.length)return a.length-b.length;for(h=0;h<a.length;h++){if(a[h]<b[h])return-1;if(a[h]>b[h])return 1}return 0}if(8===c)return a?b?0:1:b?-1:0;if(10===c)return 0;if(11===c)throw Error("Sorting not supported on regular expression");if(13===c)throw Error("Sorting not supported on Javascript code");throw Error("Unknown type to sort")}},LocalCollection._removeDollarOperators=function(a){var b={};for(var c in a)"$"!==c.substr(0,1)&&(b[c]=a[c]);return b},Minimongo.Sorter=function(a,b){var c=this;b=b||{},c._sortSpecParts=[];var d=function(a,b){if(!a)throw Error("sort keys must be non-empty");if("$"===a.charAt(0))throw Error("unsupported sort key: "+a);c._sortSpecParts.push({path:a,lookup:makeLookupFunction(a,{forSort:!0}),ascending:b})};if(a instanceof Array)for(var e=0;e<a.length;e++)"string"==typeof a[e]?d(a[e],!0):d(a[e][0],"desc"!==a[e][1]);else{if("object"!=typeof a)throw Error("Bad sort specification: "+JSON.stringify(a));_.each(a,function(a,b){d(b,a>=0)})}if(c.affectedByModifier){var f={};_.each(c._sortSpecParts,function(a){f[a.path]=1}),c._selectorForAffectedByModifier=new Minimongo.Matcher(f)}c._keyComparator=ka(_.map(c._sortSpecParts,function(a,b){return c._keyFieldComparator(b)})),c._keyFilter=null,b.matcher&&c._useWithMatcher(b.matcher)},_.extend(Minimongo.Sorter.prototype,{getComparator:function(a){var b=this;if(!a||!a.distances)return b._getBaseComparator();var c=a.distances;return ka([b._getBaseComparator(),function(a,b){if(!c.has(a._id))throw Error("Missing distance for "+a._id);if(!c.has(b._id))throw Error("Missing distance for "+b._id);return c.get(a._id)-c.get(b._id)}])},_getPaths:function(){var a=this;return _.pluck(a._sortSpecParts,"path")},_getMinKeyFromDoc:function(a){var b=this,c=null;if(b._generateKeysFromDoc(a,function(a){return b._keyCompatibleWithSelector(a)?null===c?void(c=a):void(b._compareKeys(a,c)<0&&(c=a)):void 0}),null===c)throw Error("sort selector found no keys in doc?");return c},_keyCompatibleWithSelector:function(a){var b=this;return!b._keyFilter||b._keyFilter(a)},_generateKeysFromDoc:function(a,b){var c=this;if(0===c._sortSpecParts.length)throw new Error("can't generate keys without a spec");var d=[],e=function(a){return a.join(",")+","},f=null;if(_.each(c._sortSpecParts,function(b,c){var g=expandArraysInBranches(b.lookup(a),!0);g.length||(g=[{value:null}]);var h=!1;if(d[c]={},_.each(g,function(a){if(!a.arrayIndices){if(g.length>1)throw Error("multiple branches but no array used?");return void(d[c][""]=a.value)}h=!0;var b=e(a.arrayIndices);if(_.has(d[c],b))throw Error("duplicate path: "+b);if(d[c][b]=a.value,f&&!_.has(f,b))throw Error("cannot index parallel arrays")}),f){if(!_.has(d[c],"")&&_.size(f)!==_.size(d[c]))throw Error("cannot index parallel arrays!")}else h&&(f={},_.each(d[c],function(a,b){f[b]=!0}))}),!f){var g=_.map(d,function(a){if(!_.has(a,""))throw Error("no value in sole key case?");return a[""]});return void b(g)}_.each(f,function(a,c){var e=_.map(d,function(a){if(_.has(a,""))return a[""];if(!_.has(a,c))throw Error("missing path?");return a[c]});b(e)})},_compareKeys:function(a,b){var c=this;if(a.length!==c._sortSpecParts.length||b.length!==c._sortSpecParts.length)throw Error("Key has wrong length");return c._keyComparator(a,b)},_keyFieldComparator:function(a){var b=this,c=!b._sortSpecParts[a].ascending;return function(b,d){var e=LocalCollection._f._cmp(b[a],d[a]);return c&&(e=-e),e}},_getBaseComparator:function(){var a=this;return a._sortSpecParts.length?function(b,c){var d=a._getMinKeyFromDoc(b),e=a._getMinKeyFromDoc(c);return a._compareKeys(d,e)}:function(a,b){return 0}},_useWithMatcher:function(a){var b=this;if(b._keyFilter)throw Error("called _useWithMatcher twice?");if(!_.isEmpty(b._sortSpecParts)){var c=a._selector;if(!(c instanceof Function)){var d={};_.each(b._sortSpecParts,function(a,b){d[a.path]=[]}),_.each(c,function(a,b){var c=d[b];if(c){if(a instanceof RegExp){if(a.ignoreCase||a.multiline)return;return void c.push(regexpElementMatcher(a))}return isOperatorObject(a)?void _.each(a,function(b,d){_.contains(["$lt","$lte","$gt","$gte"],d)&&c.push(ELEMENT_OPERATORS[d].compileElementSelector(b)),"$regex"!==d||a.$options||c.push(ELEMENT_OPERATORS.$regex.compileElementSelector(b,a))}):void c.push(equalityElementMatcher(a))}}),_.isEmpty(d[b._sortSpecParts[0].path])||(b._keyFilter=function(a){return _.all(b._sortSpecParts,function(b,c){return _.all(d[b.path],function(b){return b(a[c])})})})}}}});var ka=function(a){return function(b,c){for(var d=0;d<a.length;++d){var e=a[d](b,c);if(0!==e)return e}return 0}};LocalCollection._compileProjection=function(a){LocalCollection._checkSupportedProjection(a);var b=_.isUndefined(a._id)?!0:a._id,c=projectionDetails(a),d=function(a,b){if(_.isArray(a))return _.map(a,function(a){return d(a,b)});var e=c.including?{}:EJSON.clone(a);return _.each(b,function(b,f){_.has(a,f)&&(_.isObject(b)?_.isObject(a[f])&&(e[f]=d(a[f],b)):c.including?e[f]=EJSON.clone(a[f]):delete e[f])}),e};return function(a){var e=d(a,c.tree);return b&&_.has(a,"_id")&&(e._id=a._id),!b&&_.has(e,"_id")&&delete e._id,e}},projectionDetails=function(a){var b=_.keys(a).sort();b.length>0&&(1!==b.length||"_id"!==b[0])&&(b=_.reject(b,function(a){return"_id"===a}));var c=null;_.each(b,function(b){var d=!!a[b];if(null===c&&(c=d),c!==d)throw MinimongoError("You cannot currently mix including and excluding fields.")});var d=pathsToTree(b,function(a){return c},function(a,b,c){var d=c,e=b;throw MinimongoError("both "+d+" and "+e+" found in fields option, using both of them may trigger unexpected behavior. Did you mean to use only one of them?")});return{tree:d,including:c}},pathsToTree=function(a,b,c,d){return d=d||{},_.each(a,function(a){var e=d,f=a.split("."),g=_.all(f.slice(0,-1),function(b,d){if(_.has(e,b)){if(!_.isObject(e[b])&&(e[b]=c(e[b],f.slice(0,d+1).join("."),a),!_.isObject(e[b])))return!1}else e[b]={};return e=e[b],!0});if(g){var h=_.last(f);_.has(e,h)?e[h]=c(e[h],a,a):e[h]=b(a)}}),d},LocalCollection._checkSupportedProjection=function(a){if(!_.isObject(a)||_.isArray(a))throw MinimongoError("fields option must be an object");_.each(a,function(a,b){if(_.contains(b.split("."),"$"))throw MinimongoError("Minimongo doesn't support $ operator in projections yet.");if(-1===_.indexOf([1,0,!0,!1],a))throw MinimongoError("Projection values should be one of 1, 0, true, or false")})},LocalCollection._modify=function(a,b,c){if(c=c||{},!isPlainObject(b))throw MinimongoError("Modifier must be an object");var d,e=isOperatorObject(b);if(e)d=EJSON.clone(a),_.each(b,function(a,b){var e=na[b];if(c.isInsert&&"$setOnInsert"===b&&(e=na.$set),!e)throw MinimongoError("Invalid modifier specified "+b);_.each(a,function(a,f){if(""===f)throw MinimongoError("An empty update path is not valid.");if("_id"===f)throw MinimongoError("Mod on _id not allowed");var g=f.split(".");if(!_.all(g,_.identity))throw MinimongoError("The update path '"+f+"' contains an empty field name, which is not allowed.");var h=(_.has(ma,b),la(d,g,{noCreate:ma[b],forbidArray:"$rename"===b,arrayIndices:c.arrayIndices})),i=g.pop();e(h,i,a,f,d)})});else{if(b._id&&!EJSON.equals(a._id,b._id))throw MinimongoError("Cannot change the _id of a document");for(var f in b)if(/\./.test(f))throw MinimongoError("When replacing document, field name may not contain '.'");d=b}_.each(_.keys(a),function(b){"_id"!==b&&delete a[b]}),_.each(d,function(b,c){a[c]=b})};var la=function(a,b,c){c=c||{};for(var d=!1,e=0;e<b.length;e++){var f=e===b.length-1,g=b[e],h=isIndexable(a);if(!h){if(c.noCreate)return void 0;var i=MinimongoError("cannot use the part '"+g+"' to traverse "+a);throw i.setPropertyError=!0,i}if(a instanceof Array){if(c.forbidArray)return null;if("$"===g){if(d)throw MinimongoError("Too many positional (i.e. '$') elements");if(!c.arrayIndices||!c.arrayIndices.length)throw MinimongoError("The positional operator did not find the match needed from the query");g=c.arrayIndices[0],d=!0}else{if(!isNumericKey(g)){if(c.noCreate)return void 0;throw MinimongoError("can't append to array using string field name ["+g+"]")}g=parseInt(g)}if(f&&(b[e]=g),c.noCreate&&g>=a.length)return void 0;for(;a.length<g;)a.push(null);if(!f)if(a.length===g)a.push({});else if("object"!=typeof a[g])throw MinimongoError("can't modify field '"+b[e+1]+"' of list value "+JSON.stringify(a[g]))}else{if(g.length&&"$"===g.substr(0,1))throw MinimongoError("can't set field named "+g);if(!(g in a)){if(c.noCreate)return void 0;f||(a[g]={})}}if(f)return a;a=a[g]}},ma={$unset:!0,$pop:!0,$rename:!0,$pull:!0,$pullAll:!0},na={$inc:function(a,b,c){if("number"!=typeof c)throw MinimongoError("Modifier $inc allowed for numbers only");if(b in a){if("number"!=typeof a[b])throw MinimongoError("Cannot apply $inc modifier to non-number");a[b]+=c}else a[b]=c},$set:function(a,b,c){if(!_.isObject(a)){var d=MinimongoError("Cannot set property on non-object field");throw d.setPropertyError=!0,d}if(null===a){var d=MinimongoError("Cannot set property on null");throw d.setPropertyError=!0,d}a[b]=EJSON.clone(c)},$setOnInsert:function(a,b,c){},$unset:function(a,b,c){void 0!==a&&(a instanceof Array?b in a&&(a[b]=null):delete a[b])},$push:function(a,b,c){if(void 0===a[b]&&(a[b]=[]),!(a[b]instanceof Array))throw MinimongoError("Cannot apply $push modifier to non-array");if(!c||!c.$each)return void a[b].push(EJSON.clone(c));var d=c.$each;if(!(d instanceof Array))throw MinimongoError("$each must be an array");var e=void 0;if("$slice"in c){if("number"!=typeof c.$slice)throw MinimongoError("$slice must be a numeric value");if(c.$slice>0)throw MinimongoError("$slice in $push must be zero or negative");e=c.$slice}var f=void 0;if(c.$sort){if(void 0===e)throw MinimongoError("$sort requires $slice to be present");f=new Minimongo.Sorter(c.$sort).getComparator();for(var g=0;g<d.length;g++)if(3!==LocalCollection._f._type(d[g]))throw MinimongoError("$push like modifiers using $sort require all elements to be objects")}for(var h=0;h<d.length;h++)a[b].push(EJSON.clone(d[h]));f&&a[b].sort(f),void 0!==e&&(0===e?a[b]=[]:a[b]=a[b].slice(e))},$pushAll:function(a,b,c){if(!("object"==typeof c&&c instanceof Array))throw MinimongoError("Modifier $pushAll/pullAll allowed for arrays only");var d=a[b];if(void 0===d)a[b]=c;else{if(!(d instanceof Array))throw MinimongoError("Cannot apply $pushAll modifier to non-array");for(var e=0;e<c.length;e++)d.push(c[e])}},$addToSet:function(a,b,c){var d=!1;if("object"==typeof c)for(var e in c){"$each"===e&&(d=!0);break}var f=d?c.$each:[c],g=a[b];if(void 0===g)a[b]=f;else{if(!(g instanceof Array))throw MinimongoError("Cannot apply $addToSet modifier to non-array");_.each(f,function(a){for(var b=0;b<g.length;b++)if(LocalCollection._f._equal(a,g[b]))return;g.push(EJSON.clone(a))})}},$pop:function(a,b,c){if(void 0!==a){var d=a[b];if(void 0!==d){if(!(d instanceof Array))throw MinimongoError("Cannot apply $pop modifier to non-array");"number"==typeof c&&0>c?d.splice(0,1):d.pop()}}},$pull:function(a,b,c){if(void 0!==a){var d=a[b];if(void 0!==d){if(!(d instanceof Array))throw MinimongoError("Cannot apply $pull/pullAll modifier to non-array");var e=[];if("object"!=typeof c||c instanceof Array)for(var f=0;f<d.length;f++)LocalCollection._f._equal(d[f],c)||e.push(d[f]);else for(var g=new Minimongo.Matcher(c),f=0;f<d.length;f++)g.documentMatches(d[f]).result||e.push(d[f]);a[b]=e}}},$pullAll:function(a,b,c){if(!("object"==typeof c&&c instanceof Array))throw MinimongoError("Modifier $pushAll/pullAll allowed for arrays only");if(void 0!==a){var d=a[b];if(void 0!==d){if(!(d instanceof Array))throw MinimongoError("Cannot apply $pull/pullAll modifier to non-array");for(var e=[],f=0;f<d.length;f++){for(var g=!1,h=0;h<c.length;h++)if(LocalCollection._f._equal(d[f],c[h])){g=!0;break}g||e.push(d[f])}a[b]=e}}},$rename:function(a,b,c,d,e){if(d===c)throw MinimongoError("$rename source must differ from target");if(null===a)throw MinimongoError("$rename source field invalid");if("string"!=typeof c)throw MinimongoError("$rename target must be a string");if(void 0!==a){var f=a[b];delete a[b];var g=c.split("."),h=la(e,g,{forbidArray:!0});if(null===h)throw MinimongoError("$rename target field invalid");var i=g.pop();h[i]=f}},$bit:function(a,b,c){throw MinimongoError("$bit is not supported")}};LocalCollection._diffQueryChanges=function(a,b,c,d,e){a?LocalCollection._diffQueryOrderedChanges(b,c,d,e):LocalCollection._diffQueryUnorderedChanges(b,c,d,e);
},LocalCollection._diffQueryUnorderedChanges=function(a,b,c,d){d=d||{};var e=d.projectionFn||EJSON.clone;if(c.movedBefore)throw new Error("_diffQueryUnordered called with a movedBefore observer!");b.forEach(function(b,d){var f=a.get(d);if(f){if(c.changed&&!EJSON.equals(f,b)){var g=e(b),h=e(f),i=LocalCollection._makeChangedFields(g,h);_.isEmpty(i)||c.changed(d,i)}}else if(c.added){var j=e(b);delete j._id,c.added(b._id,j)}}),c.removed&&a.forEach(function(a,d){b.has(d)||c.removed(d)})},LocalCollection._diffQueryOrderedChanges=function(a,b,c,d){d=d||{};var e=d.projectionFn||EJSON.clone,f={};_.each(b,function(a){f[a._id]&&Meteor._debug("Duplicate _id in new_results"),f[a._id]=!0});var g={};_.each(a,function(a,b){a._id in g&&Meteor._debug("Duplicate _id in old_results"),g[a._id]=b});for(var h=[],i=0,j=b.length,k=new Array(j),l=new Array(j),m=function(a){return g[b[a]._id]},n=0;j>n;n++)if(void 0!==g[b[n]._id]){for(var o=i;o>0&&!(m(k[o-1])<m(n));)o--;l[n]=0===o?-1:k[o-1],k[o]=n,o+1>i&&(i=o+1)}for(var p=0===i?-1:k[i-1];p>=0;)h.push(p),p=l[p];h.reverse(),h.push(b.length),_.each(a,function(a){f[a._id]||c.removed&&c.removed(a._id)});var q=0;_.each(h,function(d){for(var f,h,i,j,k,l=b[d]?b[d]._id:null,m=q;d>m;m++)h=b[m],_.has(g,h._id)?(f=a[g[h._id]],j=e(h),k=e(f),i=LocalCollection._makeChangedFields(j,k),_.isEmpty(i)||c.changed&&c.changed(h._id,i),c.movedBefore&&c.movedBefore(h._id,l)):(i=e(h),delete i._id,c.addedBefore&&c.addedBefore(h._id,i,l),c.added&&c.added(h._id,i));l&&(h=b[d],f=a[g[h._id]],j=e(h),k=e(f),i=LocalCollection._makeChangedFields(j,k),_.isEmpty(i)||c.changed&&c.changed(h._id,i)),q=d+1})},LocalCollection._diffObjects=function(a,b,c){_.each(a,function(a,d){_.has(b,d)?c.both&&c.both(d,a,b[d]):c.leftOnly&&c.leftOnly(d,a)}),c.rightOnly&&_.each(b,function(b,d){_.has(a,d)||c.rightOnly(d,b)})},LocalCollection._IdMap=function(){var a=this;IdMap.call(a,LocalCollection._idStringify,LocalCollection._idParse)},Meteor._inherits(LocalCollection._IdMap,IdMap),LocalCollection._CachingChangeObserver=function(a){var b=this;a=a||{};var c=a.callbacks&&LocalCollection._observeChangesCallbacksAreOrdered(a.callbacks);if(_.has(a,"ordered")){if(b.ordered=a.ordered,a.callbacks&&a.ordered!==c)throw Error("ordered option doesn't match callbacks")}else{if(!a.callbacks)throw Error("must provide ordered or callbacks");b.ordered=c}var d=a.callbacks||{};b.ordered?(b.docs=new OrderedDict(LocalCollection._idStringify),b.applyChange={addedBefore:function(a,c,e){var f=EJSON.clone(c);f._id=a,d.addedBefore&&d.addedBefore.call(b,a,c,e),d.added&&d.added.call(b,a,c),b.docs.putBefore(a,f,e||null)},movedBefore:function(a,c){b.docs.get(a);d.movedBefore&&d.movedBefore.call(b,a,c),b.docs.moveBefore(a,c||null)}}):(b.docs=new LocalCollection._IdMap,b.applyChange={added:function(a,c){var e=EJSON.clone(c);d.added&&d.added.call(b,a,c),e._id=a,b.docs.set(a,e)}}),b.applyChange.changed=function(a,c){var e=b.docs.get(a);if(!e)throw new Error("Unknown id for changed: "+a);d.changed&&d.changed.call(b,a,EJSON.clone(c)),LocalCollection._applyChanges(e,c)},b.applyChange.removed=function(a){d.removed&&d.removed.call(b,a),b.docs.remove(a)}},LocalCollection._observeFromObserveChanges=function(a,b){var c,d=a.getTransform()||function(a){return a},e=!!b._suppress_initial;if(LocalCollection._observeCallbacksAreOrdered(b)){var f=!b._no_indices;c={addedBefore:function(a,c,g){var h=this;if(!e&&(b.addedAt||b.added)){var i=d(_.extend(c,{_id:a}));if(b.addedAt){var j=f?g?h.docs.indexOf(g):h.docs.size():-1;b.addedAt(i,j,g)}else b.added(i)}},changed:function(a,c){var e=this;if(b.changedAt||b.changed){var g=EJSON.clone(e.docs.get(a));if(!g)throw new Error("Unknown id for changed: "+a);var h=d(EJSON.clone(g));if(LocalCollection._applyChanges(g,c),g=d(g),b.changedAt){var i=f?e.docs.indexOf(a):-1;b.changedAt(g,h,i)}else b.changed(g,h)}},movedBefore:function(a,c){var e=this;if(b.movedTo){var g=f?e.docs.indexOf(a):-1,h=f?c?e.docs.indexOf(c):e.docs.size():-1;h>g&&--h,b.movedTo(d(EJSON.clone(e.docs.get(a))),g,h,c||null)}},removed:function(a){var c=this;if(b.removedAt||b.removed){var e=d(c.docs.get(a));if(b.removedAt){var g=f?c.docs.indexOf(a):-1;b.removedAt(e,g)}else b.removed(e)}}}}else c={added:function(a,c){if(!e&&b.added){var f=_.extend(c,{_id:a});b.added(d(f))}},changed:function(a,c){var e=this;if(b.changed){var f=e.docs.get(a),g=EJSON.clone(f);LocalCollection._applyChanges(g,c),b.changed(d(g),d(EJSON.clone(f)))}},removed:function(a){var c=this;b.removed&&b.removed(d(c.docs.get(a)))}};var g=new LocalCollection._CachingChangeObserver({callbacks:c}),h=a.observeChanges(g.applyChange);return e=!1,h},LocalCollection._looksLikeObjectID=function(a){return 24===a.length&&a.match(/^[0-9a-f]*$/)},LocalCollection._ObjectID=function(a){var b=this;if(a){if(a=a.toLowerCase(),!LocalCollection._looksLikeObjectID(a))throw new Error("Invalid hexadecimal string for creating an ObjectID");b._str=a}else b._str=Random.hexString(24)},LocalCollection._ObjectID.prototype.toString=function(){var a=this;return'ObjectID("'+a._str+'")'},LocalCollection._ObjectID.prototype.equals=function(a){var b=this;return a instanceof LocalCollection._ObjectID&&b.valueOf()===a.valueOf()},LocalCollection._ObjectID.prototype.clone=function(){var a=this;return new LocalCollection._ObjectID(a._str)},LocalCollection._ObjectID.prototype.typeName=function(){return"oid"},LocalCollection._ObjectID.prototype.getTimestamp=function(){var a=this;return parseInt(a._str.substr(0,8),16)},LocalCollection._ObjectID.prototype.valueOf=LocalCollection._ObjectID.prototype.toJSONValue=LocalCollection._ObjectID.prototype.toHexString=function(){return this._str},LocalCollection._selectorIsId=function(a){return"string"==typeof a||"number"==typeof a||a instanceof LocalCollection._ObjectID},LocalCollection._selectorIsIdPerhapsAsObject=function(a){return LocalCollection._selectorIsId(a)||a&&"object"==typeof a&&a._id&&LocalCollection._selectorIsId(a._id)&&1===_.size(a)},LocalCollection._idsMatchedBySelector=function(a){if(LocalCollection._selectorIsId(a))return[a];if(!a)return null;if(_.has(a,"_id"))return LocalCollection._selectorIsId(a._id)?[a._id]:a._id&&a._id.$in&&_.isArray(a._id.$in)&&!_.isEmpty(a._id.$in)&&_.all(a._id.$in,LocalCollection._selectorIsId)?a._id.$in:null;if(a.$and&&_.isArray(a.$and))for(var b=0;b<a.$and.length;++b){var c=LocalCollection._idsMatchedBySelector(a.$and[b]);if(c)return c}return null},EJSON.addType("oid",function(a){return new LocalCollection._ObjectID(a)});var oa=0,pa=[];Meteor.EnvironmentVariable=function(){this.slot=oa++},_.extend(Meteor.EnvironmentVariable.prototype,{get:function(){return pa[this.slot]},getOrNullIfOutsideFiber:function(){return this.get()},withValue:function(a,b){var c=pa[this.slot];try{pa[this.slot]=a;var d=b()}finally{pa[this.slot]=c}return d}}),Meteor.bindEnvironment=function(a,b,c){var d=_.clone(pa);if(!b||"string"==typeof b){var e=b||"callback of async function";b=function(a){Meteor._debug("Exception in "+e+":",a&&a.stack||a)}}return function(){var e=pa;try{pa=d;var f=a.apply(c,_.toArray(arguments))}catch(g){b(g)}finally{pa=e}return f}},Meteor._nodeCodeMustBeInFiber=function(){},ReactiveVar=function(a,b){return this instanceof ReactiveVar?(this.curValue=a,this.equalsFunc=b,void(this.dep=new Tracker.Dependency)):new ReactiveVar(a,b)},ReactiveVar._isEqual=function(a,b){var c=a,d=b;return c!==d?!1:!c||"number"==typeof c||"boolean"==typeof c||"string"==typeof c},ReactiveVar.prototype.get=function(){return Tracker.active&&this.dep.depend(),this.curValue},ReactiveVar.prototype.set=function(a){var b=this.curValue;(this.equalsFunc||ReactiveVar._isEqual)(b,a)||(this.curValue=a,this.dep.changed())},ReactiveVar.prototype.toString=function(){return"ReactiveVar{"+this.get()+"}"},ReactiveVar.prototype._numListeners=function(){var a=0;for(var b in this.dep._dependentsById)a++;return a};var qa=function(a){return void 0===a?"undefined":EJSON.stringify(a)},ra=function(a){return void 0===a||"undefined"===a?void 0:EJSON.parse(a)};ReactiveDict=function(a){if(a)if("string"==typeof a)ReactiveDict._registerDictForMigrate(a,this),this.keys=ReactiveDict._loadMigratedDict(a)||{};else{if("object"!=typeof a)throw new Error("Invalid ReactiveDict argument: "+a);this.keys=a}else this.keys={};this.keyDeps={},this.keyValueDeps={}},_.extend(ReactiveDict.prototype,{set:function(a,b){var c=this;if("object"==typeof a&&void 0===b)return void c._setObject(a);var d=a;b=qa(b);var e="undefined";if(_.has(c.keys,d)&&(e=c.keys[d]),b!==e){c.keys[d]=b;var f=function(a){a&&a.changed()};f(c.keyDeps[d]),c.keyValueDeps[d]&&(f(c.keyValueDeps[d][e]),f(c.keyValueDeps[d][b]))}},setDefault:function(a,b){var c=this;void 0===c.keys[a]&&c.set(a,b)},get:function(a){var b=this;return b._ensureKey(a),b.keyDeps[a].depend(),ra(b.keys[a])},equals:function(a,b){var c=this,d=null;if("undefined"!=typeof Mongo&&(d=Mongo.ObjectID),!("string"==typeof b||"number"==typeof b||"boolean"==typeof b||"undefined"==typeof b||b instanceof Date||d&&b instanceof d||null===b))throw new Error("ReactiveDict.equals: value must be scalar");var e=qa(b);if(Tracker.active){c._ensureKey(a),_.has(c.keyValueDeps[a],e)||(c.keyValueDeps[a][e]=new Tracker.Dependency);var f=c.keyValueDeps[a][e].depend();f&&Tracker.onInvalidate(function(){c.keyValueDeps[a][e].hasDependents()||delete c.keyValueDeps[a][e]})}var g=void 0;return _.has(c.keys,a)&&(g=ra(c.keys[a])),EJSON.equals(g,b)},_setObject:function(a){var b=this;_.each(a,function(a,c){b.set(c,a)})},_ensureKey:function(a){var b=this;a in b.keyDeps||(b.keyDeps[a]=new Tracker.Dependency,b.keyValueDeps[a]={})},_getMigrationData:function(){return this.keys}})}({},function(){return this}());