/*
 btree.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
 Released under the Apache License, Version 2.0
 see: http://github.com/dcodeIO/btree.js for details
*/
!function(D){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=D();else if("function"==typeof define&&define.amd)define([],D);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self);f.ForerunnerDB=D()}}(function(){return function f(m,h,d){function b(a,l){if(!h[a]){if(!m[a]){var e="function"==typeof require&&require;if(!l&&e)return e(a,!0);if(k)return k(a,!0);e=Error("Cannot find module '"+a+"'");throw e.code="MODULE_NOT_FOUND",
e;}e=h[a]={exports:{}};m[a][0].call(e.exports,function(g){var n=m[a][1][g];return b(n?n:g)},e,e.exports,f,m,h,d)}return h[a].exports}for(var k="function"==typeof require&&require,a=0;a<d.length;a++)b(d[a]);return b}({1:[function(f,m,h){h=f("../lib/Core");f("../lib/CollectionGroup");f("../lib/View");f("../lib/Highchart");f("../lib/Persist");f("../lib/Document");f("../lib/Overview");f("../lib/Grid");m.exports=h},{"../lib/CollectionGroup":4,"../lib/Core":5,"../lib/Document":7,"../lib/Grid":8,"../lib/Highchart":9,
"../lib/Overview":23,"../lib/Persist":25,"../lib/View":28}],2:[function(f,m,h){h=f("./Shared");f("./Path");f=function(d){var b;this._primaryKey="_id";this._keyArr=[];this._data=[];this._objLookup={};this._count=0;for(b in d)d.hasOwnProperty(b)&&this._keyArr.push({key:b,dir:d[b]})};h.addModule("ActiveBucket",f);h.synthesize(f.prototype,"primaryKey");h.mixin(f.prototype,"Mixin.Sorting");f.prototype.qs=function(d,b,k,a){if(!b.length)return 0;for(var c=-1,l,e,g=0,n=b.length-1;n>=g;){l=Math.floor((g+n)/
2);if(c===l)break;c=b[l];void 0!==c&&(e=a(this,d,k,c),0<e&&(g=l+1),0>e&&(n=l-1));c=l}return 0<e?l+1:l};f.prototype._sortFunc=function(d,b,k,a){k=k.split(".:.");a=a.split(".:.");var c=d._keyArr,l=c.length,e,g,n;for(e=0;e<l;e++)if(g=c[e],n=typeof b[g.key],"number"===n&&(k[e]=Number(k[e]),a[e]=Number(a[e])),k[e]!==a[e]){if(1===g.dir)return d.sortAsc(k[e],a[e]);if(-1===g.dir)return d.sortDesc(k[e],a[e])}};f.prototype.insert=function(d){var b,k;b=this.documentKey(d);k=this._data.indexOf(b);-1===k&&(k=
this.qs(d,this._data,b,this._sortFunc));this._data.splice(k,0,b);this._objLookup[d[this._primaryKey]]=b;this._count++;return k};f.prototype.remove=function(d){var b;if(b=this._objLookup[d[this._primaryKey]])if(b=this._data.indexOf(b),-1<b)return this._data.splice(b,1),delete this._objLookup[d[this._primaryKey]],this._count--,!0;return!1};f.prototype.index=function(d){var b,k;b=this.documentKey(d);k=this._data.indexOf(b);-1===k&&(k=this.qs(d,this._data,b,this._sortFunc));return k};f.prototype.documentKey=
function(d){var b="",k=this._keyArr,a=k.length,c,l;for(c=0;c<a;c++)l=k[c],b&&(b+=".:."),b+=d[l.key];return b+=".:."+d[this._primaryKey]};f.prototype.count=function(){return this._count};h.finishModule("ActiveBucket");m.exports=f},{"./Path":24,"./Shared":27}],3:[function(f,m,h){var d,b,k,a,c,l;h=f("./Shared");var e=function(g){this.init.apply(this,arguments)};e.prototype.init=function(g){this._primaryKey="_id";this._primaryIndex=new b("primary");this._primaryCrc=new b("primaryCrc");this._crcLookup=
new b("crcLookup");this._name=g;this._data=[];this._groups=[];this._metrics=new d;this._deferQueue={insert:[],update:[],remove:[],upsert:[]};this._deferThreshold={insert:100,update:100,remove:100,upsert:100};this._deferTime={insert:1,update:1,remove:1,upsert:1};this._subsetOf(this)};h.addModule("Collection",e);h.mixin(e.prototype,"Mixin.Common");h.mixin(e.prototype,"Mixin.Events");h.mixin(e.prototype,"Mixin.ChainReactor");h.mixin(e.prototype,"Mixin.CRUD");h.mixin(e.prototype,"Mixin.Constants");h.mixin(e.prototype,
"Mixin.Triggers");h.mixin(e.prototype,"Mixin.Sorting");d=f("./Metrics");b=f("./KeyValueStore");k=f("./Path");a=f("./IndexHashMap");c=f("./IndexBinaryTree");l=f("./Crc");f=h.modules.Core;e.prototype.crc=l;h.synthesize(e.prototype,"state");h.synthesize(e.prototype,"name");e.prototype.data=function(){return this._data};e.prototype.drop=function(){if("dropped"!==this._state){if(this._db&&this._db._collection&&this._name){this.debug()&&console.log("Dropping collection "+this._name);this._state="dropped";
this.emit("drop",this);delete this._db._collection[this._name];if(this._groups&&this._groups.length){var g=[],n;for(n=0;n<this._groups.length;n++)g.push(this._groups[n]);for(n=0;n<g.length;n++)this._groups[n].removeCollection(this)}delete this._primaryKey;delete this._primaryIndex;delete this._primaryCrc;delete this._crcLookup;delete this._name;delete this._data;delete this._groups;delete this._metrics;return!0}}else return!0;return!1};e.prototype.primaryKey=function(g){return void 0!==g?(this._primaryKey!==
g&&(this._primaryKey=g,this._primaryIndex.primaryKey(g),this.rebuildPrimaryKeyIndex()),this):this._primaryKey};e.prototype._onInsert=function(g,n){this.emit("insert",g,n)};e.prototype._onUpdate=function(g){this.emit("update",g)};e.prototype._onRemove=function(g){this.emit("remove",g)};h.synthesize(e.prototype,"db");e.prototype.setData=function(g,n,a){if(g){var c=this._metrics.create("setData");c.start();n=this.options(n);this.preSetData(g,n,a);n.$decouple&&(g=this.decouple(g));g instanceof Array||
(g=[g]);c.time("transformIn");g=this.transformIn(g);c.time("transformIn");var e=[].concat(this._data);this._dataReplace(g);c.time("Rebuild Primary Key Index");this.rebuildPrimaryKeyIndex(n);c.time("Rebuild Primary Key Index");c.time("Rebuild All Other Indexes");this._rebuildIndexes();c.time("Rebuild All Other Indexes");c.time("Resolve chains");this.chainSend("setData",g,{oldData:e});c.time("Resolve chains");c.stop();this.emit("setData",this._data,e)}a&&a(!1);return this};e.prototype.rebuildPrimaryKeyIndex=
function(g){var n=g&&void 0!==g.$ensureKeys?g.$ensureKeys:!0;g=g&&void 0!==g.$violationCheck?g.$violationCheck:!0;var a,c,e,b=this._primaryIndex,k=this._primaryCrc,d=this._crcLookup,l=this._primaryKey,f;b.truncate();k.truncate();d.truncate();a=this._data;for(c=a.length;c--;){e=a[c];n&&this.ensurePrimaryKey(e);if(g){if(!b.uniqueSet(e[l],e))throw'ForerunnerDB.Collection "'+this.name()+'": Call to setData on collection failed because your data violates the primary key unique constraint. One or more documents are using the same primary key: '+
e[this._primaryKey];}else b.set(e[l],e);f=JSON.stringify(e);k.set(e[l],f);d.set(f,e)}};e.prototype.ensurePrimaryKey=function(g){void 0===g[this._primaryKey]&&(g[this._primaryKey]=this.objectId())};e.prototype.truncate=function(){this.emit("truncate",this._data);this._data.length=0;this._primaryIndex=new b("primary");this._primaryCrc=new b("primaryCrc");this._crcLookup=new b("crcLookup");this.deferEmit("change",{type:"truncate"});return this};e.prototype.upsert=function(g,n){if(g){var a=this._deferQueue.upsert,
c=this._deferThreshold.upsert,e={},b;if(g instanceof Array){if(g.length>c)return this._deferQueue.upsert=a.concat(g),this.processQueue("upsert",n),{};e=[];for(a=0;a<g.length;a++)e.push(this.upsert(g[a]));n&&n();return e}g[this._primaryKey]?(b={},b[this._primaryKey]=g[this._primaryKey],this._primaryIndex.lookup(b)[0]?e.op="update":e.op="insert"):e.op="insert";switch(e.op){case "insert":e.result=this.insert(g);break;case "update":e.result=this.update(b,g)}return e}n&&n();return{}};e.prototype.update=
function(g,n,a){n=this.decouple(n);n=this.transformIn(n);this.debug()&&console.log('Updating some collection data for collection "'+this.name()+'"');var c=this,e=this._metrics.create("update"),b,k,d=function(b){var k=c.decouple(b),d,l;if(c.willTrigger(c.TYPE_UPDATE,c.PHASE_BEFORE)||c.willTrigger(c.TYPE_UPDATE,c.PHASE_AFTER)){d={type:"update",query:c.decouple(g),update:c.decouple(n),options:c.decouple(a),op:e};if(!1===c.processTrigger(d,c.TYPE_UPDATE,c.PHASE_BEFORE,k)||c.willTrigger(c.TYPE_UPDATE,
c.PHASE_BEFORE)&&(l=c.updateObject(k,d.update,d.query,d.options,""))&&!1===c.processTrigger(d,c.TYPE_UPDATE,c.PHASE_AFTER,b,k))return!1;l=c.updateObject(b,d.update,d.query,d.options,"")}else l=c.updateObject(b,n,g,a,"");return l};e.start();e.time("Retrieve documents to update");b=this.find(g,{$decouple:!1});e.time("Retrieve documents to update");b.length&&(e.time("Update documents"),k=b.filter(d),e.time("Update documents"),k.length&&(e.time("Resolve chains"),this.chainSend("update",{query:g,update:n,
dataSet:b},a),e.time("Resolve chains"),this._onUpdate(k),this.deferEmit("change",{type:"update",data:k})));e.stop();return k||[]};e.prototype._replaceObj=function(g,n){var a;this._removeFromIndexes(g);for(a in g)g.hasOwnProperty(a)&&delete g[a];for(a in n)n.hasOwnProperty(a)&&(g[a]=n[a]);if(!this._insertIntoIndexes(g))throw'ForerunnerDB.Collection "'+this.name()+'": Primary key violation in update! Key violated: '+g[this._primaryKey];return!0};e.prototype.updateById=function(g,n){var a={};a[this._primaryKey]=
g;return this.update(a,n)};e.prototype.updateObject=function(g,n,a,c,e,b){n=this.decouple(n);e=e||"";"."===e.substr(0,1)&&(e=e.substr(1,e.length-1));this.decouple(g);var d=!1,l=!1,f,h,q,p;for(p in n)if(n.hasOwnProperty(p)){f=!1;if("$"===p.substr(0,1))switch(p){case "$key":case "$index":f=!0;break;default:f=!0,l=this.updateObject(g,n[p],a,c,e,p),d=d||l}if(this._isPositionalKey(p)&&(f=!0,p=p.substr(0,p.length-2),l=new k(e+"."+p),g[p]&&g[p]instanceof Array&&g[p].length)){h=[];for(q=0;q<g[p].length;q++)this._match(g[p][q],
l.value(a)[0])&&h.push(q);for(q=0;q<h.length;q++)l=this.updateObject(g[p][h[q]],n[p+".$"],a,c,e+"."+p,b),d=d||l}if(!f)if(b||"object"!==typeof n[p])switch(b){case "$inc":this._updateIncrement(g,p,n[p]);d=!0;break;case "$push":void 0===g[p]&&this._updateProperty(g,p,[]);if(g[p]instanceof Array){if(void 0!==n[p].$position&&n[p].$each instanceof Array)for(l=n[p].$position,f=n[p].$each.length,q=0;q<f;q++)this._updateSplicePush(g[p],l+q,n[p].$each[q]);else if(n[p].$each instanceof Array)for(f=n[p].$each.length,
q=0;q<f;q++)this._updatePush(g[p],n[p].$each[q]);else this._updatePush(g[p],n[p]);d=!0}else throw'ForerunnerDB.Collection "'+this.name()+'": Cannot push to a key that is not an array! ('+p+")";break;case "$pull":if(g[p]instanceof Array){h=[];for(q=0;q<g[p].length;q++)this._match(g[p][q],n[p])&&h.push(q);for(f=h.length;f--;)this._updatePull(g[p],h[f]),d=!0}break;case "$pullAll":if(g[p]instanceof Array)if(n[p]instanceof Array){if(h=g[p],f=h.length,0<f)for(;f--;){for(l=0;l<n[p].length;l++)h[f]===n[p][l]&&
(this._updatePull(g[p],f),f--,d=!0);if(0>f)break}}else throw'ForerunnerDB.Collection "'+this.name()+'": Cannot pullAll without being given an array of values to pull! ('+p+")";break;case "$addToSet":void 0===g[p]&&this._updateProperty(g,p,[]);if(g[p]instanceof Array){q=g[p];var m;h=q.length;var A;f=!0;m=c&&c.$addToSet;var y;n[p].$key?(l=!1,y=new k(n[p].$key),A=y.value(n[p])[0],delete n[p].$key):m&&m.key?(l=!1,y=new k(m.key),A=y.value(n[p])[0]):(A=JSON.stringify(n[p]),l=!0);for(m=0;m<h;m++)if(l){if(JSON.stringify(q[m])===
A){f=!1;break}}else if(A===y.value(q[m])[0]){f=!1;break}f&&(this._updatePush(g[p],n[p]),d=!0)}else throw'ForerunnerDB.Collection "'+this.name()+'": Cannot addToSet on a key that is not an array! (undefined)';break;case "$splicePush":void 0===g[p]&&this._updateProperty(g,p,[]);if(g[p]instanceof Array)if(l=n.$index,void 0!==l)delete n.$index,l>g[p].length&&(l=g[p].length),this._updateSplicePush(g[p],l,n[p]),d=!0;else throw'ForerunnerDB.Collection "'+this.name()+'": Cannot splicePush without a $index integer value!';
else throw'ForerunnerDB.Collection "'+this.name()+'": Cannot splicePush with a key that is not an array! ('+p+")";break;case "$move":if(g[p]instanceof Array)for(q=0;q<g[p].length;q++){if(this._match(g[p][q],n[p])){d=n.$index;if(void 0!==d)delete n.$index,this._updateSpliceMove(g[p],q,d),d=!0;else throw'ForerunnerDB.Collection "'+this.name()+'": Cannot move without a $index integer value!';break}}else throw'ForerunnerDB.Collection "'+this.name()+'": Cannot move on a key that is not an array! ('+p+
")";break;case "$mul":this._updateMultiply(g,p,n[p]);d=!0;break;case "$rename":this._updateRename(g,p,n[p]);d=!0;break;case "$unset":this._updateUnset(g,p);d=!0;break;case "$pop":if(g[p]instanceof Array)this._updatePop(g[p],n[p])&&(d=!0);else throw'ForerunnerDB.Collection "'+this.name()+'": Cannot pop from a key that is not an array! ('+p+")";break;default:g[p]!==n[p]&&(this._updateProperty(g,p,n[p]),d=!0)}else if(null!==g[p]&&"object"===typeof g[p])if(q=g[p]instanceof Array,h=n[p]instanceof Array,
q||h)if(!h&&q)for(q=0;q<g[p].length;q++)l=this.updateObject(g[p][q],n[p],a,c,e+"."+p,b),d=d||l;else g[p]!==n[p]&&(this._updateProperty(g,p,n[p]),d=!0);else l=this.updateObject(g[p],n[p],a,c,e+"."+p,b),d=d||l;else g[p]!==n[p]&&(this._updateProperty(g,p,n[p]),d=!0)}return d};e.prototype._isPositionalKey=function(g){return".$"===g.substr(g.length-2,2)};e.prototype._updateProperty=function(g,a,c){g[a]=c;this.debug()&&console.log('ForerunnerDB.Collection: Setting non-data-bound document property "'+a+
'" for collection "'+this.name()+'"')};e.prototype._updateIncrement=function(g,a,c){g[a]+=c};e.prototype._updateSpliceMove=function(g,a,c){g.splice(c,0,g.splice(a,1)[0]);this.debug()&&console.log('ForerunnerDB.Collection: Moving non-data-bound document array index from "'+a+'" to "'+c+'" for collection "'+this.name()+'"')};e.prototype._updateSplicePush=function(g,a,c){g.length>a?g.splice(a,0,c):g.push(c)};e.prototype._updatePush=function(g,a){g.push(a)};e.prototype._updatePull=function(g,a){g.splice(a,
1)};e.prototype._updateMultiply=function(g,a,c){g[a]*=c};e.prototype._updateRename=function(g,a,c){g[c]=g[a];delete g[a]};e.prototype._updateUnset=function(g,a){delete g[a]};e.prototype._updatePop=function(g,a){var c=!1;0<g.length&&(1===a?(g.pop(),c=!0):-1===a&&(g.shift(),c=!0));return c};e.prototype.remove=function(g,a,c){var e,b;if(g instanceof Array){e=[];for(c=0;c<g.length;c++)e.push(this.remove(g[c],{noEmit:!0}));(!a||a&&!a.noEmit)&&this._onRemove(e);return e}c=this.find(g,{$decouple:!1});if(c.length){for(var k=
0;k<c.length;k++)b=c[k],this._removeFromIndexes(b),e=this._data.indexOf(b),this._dataRemoveAtIndex(e),this.processTrigger(this.TYPE_REMOVE,this.PHASE_AFTER,b,{});this.chainSend("remove",{query:g,dataSet:c},a);(!a||a&&!a.noEmit)&&this._onRemove(c);this.deferEmit("change",{type:"remove",data:c})}return c};e.prototype.removeById=function(g){var a={};a[this._primaryKey]=g;return this.remove(a)};e.prototype.deferEmit=function(){var g=this,a;this._noEmitDefer||this._db&&(!this._db||this._db._noEmitDefer)?
this.emit.apply(this,arguments):(a=arguments,this._changeTimeout&&clearTimeout(this._changeTimeout),this._changeTimeout=setTimeout(function(){g.debug()&&console.log("ForerunnerDB.Collection: Emitting "+a[0]);g.emit.apply(g,a)},100))};e.prototype.processQueue=function(g,a){var c=this._deferQueue[g],e=this._deferThreshold[g],b=this._deferTime[g];if(c.length){var k=this;c.length&&(c=c.length>e?c.splice(0,e):c.splice(0,c.length),this[g](c));setTimeout(function(){k.processQueue(g,a)},b)}else a&&a()};e.prototype.insert=
function(g,a,c){"function"===typeof a?(c=a,a=this._data.length):void 0===a&&(a=this._data.length);g=this.transformIn(g);return this._insertHandle(g,a,c)};e.prototype._insertHandle=function(g,a,c){var e=this._deferQueue.insert,b=this._deferThreshold.insert,k=[],d=[];if(g instanceof Array){if(g.length>b){this._deferQueue.insert=e.concat(g);this.processQueue("insert",c);return}for(b=0;b<g.length;b++)e=this._insert(g[b],a+b),!0===e?k.push(g[b]):d.push({doc:g[b],reason:e})}else e=this._insert(g,a),!0===
e?k.push(g):d.push({doc:g,reason:e});this.chainSend("insert",g,{index:a});this._onInsert(k,d);c&&c();this.deferEmit("change",{type:"insert",data:k});return{inserted:k,failed:d}};e.prototype._insert=function(g,a){if(g){var c;this.ensurePrimaryKey(g);if(c=this.insertIndexViolation(g))return"Index violation in index: "+c;this._insertIntoIndexes(g);a>this._data.length&&(a=this._data.length);this._dataInsertAtIndex(a,g);this.processTrigger(this.TYPE_INSERT,this.PHASE_AFTER,{},g);return!0}return"No document passed to insert"};
e.prototype._dataInsertAtIndex=function(g,a){this._data.splice(g,0,a)};e.prototype._dataRemoveAtIndex=function(g){this._data.splice(g,1)};e.prototype._dataReplace=function(g){for(;this._data.length;)this._data.pop();this._data=this._data.concat(g)};e.prototype._insertIntoIndexes=function(g){var a=this._indexByName,c,e,b=JSON.stringify(g);e=this._primaryIndex.uniqueSet(g[this._primaryKey],g);this._primaryCrc.uniqueSet(g[this._primaryKey],b);this._crcLookup.uniqueSet(b,g);for(c in a)a.hasOwnProperty(c)&&
a[c].insert(g);return e};e.prototype._removeFromIndexes=function(g){var a=this._indexByName,c,e=JSON.stringify(g);this._primaryIndex.unSet(g[this._primaryKey]);this._primaryCrc.unSet(g[this._primaryKey]);this._crcLookup.unSet(e);for(c in a)a.hasOwnProperty(c)&&a[c].remove(g)};e.prototype._rebuildIndexes=function(){var g=this._indexByName,a;for(a in g)g.hasOwnProperty(a)&&g[a].rebuild()};e.prototype.indexOfDocById=function(g){return this._data.indexOf(this._primaryIndex.get(g[this._primaryKey]))};
e.prototype.subset=function(g,a){var c=this.find(g,a);return(new e)._subsetOf(this).primaryKey(this._primaryKey).setData(c)};e.prototype.subsetOf=function(){return this.__subsetOf};e.prototype._subsetOf=function(g){this.__subsetOf=g;return this};e.prototype.distinct=function(g,a,c){a=this.find(a,c);g=new k(g);c={};var e=[],b,d;for(d=0;d<a.length;d++)(b=g.value(a[d])[0])&&!c[b]&&(c[b]=!0,e.push(b));return e};e.prototype.findById=function(g,a){var c={};c[this._primaryKey]=g;return this.find(c,a)[0]};
e.prototype.peek=function(g,a){var c=this._data,b=c.length,k,d,l=new e;if("string"===typeof g){for(k=0;k<b;k++)d=JSON.stringify(c[k]),-1<d.indexOf(g)&&l.insert(c[k]);return l.find({},a)}return this.find(g,a)};e.prototype.explain=function(g,a){return this.find(g,a).__fdbOp._data};e.prototype.options=function(g){g=g||{};g.$decouple=void 0!==g.$decouple?g.$decouple:!0;g.$explain=void 0!==g.$explain?g.$explain:!1;return g};e.prototype.find=function(g,a){g=g||{};a=this.options(a);var c=this._metrics.create("find"),
e=this,b,d=!0,l,f,h,m,q,p,z,A,y,C=[];f=function(a){return e._match(a,g,"and")};c.start();if(g){c.time("analyseQuery");b=this._analyseQuery(g,a,c);c.time("analyseQuery");c.data("analysis",b);if(b.hasJoin&&b.queriesJoin){c.time("joinReferences");for(h=0;h<b.joinsOn.length;h++)q=b.joinsOn[h],m=new k(b.joinQueries[q]),m=m.value(g)[0],this._db.collection(b.joinsOn[h]).subset(m);c.time("joinReferences")}b.indexMatch.length&&(!a||a&&!a.$skipIndex)?(c.data("index.potential",b.indexMatch),c.data("index.used",
b.indexMatch[0].index),c.time("indexLookup"),l=b.indexMatch[0].lookup,c.time("indexLookup"),b.indexMatch[0].keyData.totalKeyCount===b.indexMatch[0].keyData.score&&(d=!1)):c.flag("usedIndex",!1);d&&(l&&l.length?(b=l.length,c.time("tableScan: "+b),l=l.filter(f)):(b=this._data.length,c.time("tableScan: "+b),l=this._data.filter(f)),a.$orderBy&&(c.time("sort"),l=this.sort(a.$orderBy,l),c.time("sort")),c.time("tableScan: "+b));a.limit&&l&&l.length>a.limit&&(l.length=a.limit,c.data("limit",a.limit));a.$decouple&&
(c.time("decouple"),l=this.decouple(l),c.time("decouple"),c.data("flag.decouple",!0));if(a.join){for(f=0;f<a.join.length;f++)for(q in a.join[f])if(a.join[f].hasOwnProperty(q))for(A=q,b=this._db.collection(q),d=a.join[f][q],y=0;y<l.length;y++){z={};m=h=!1;for(p in d)if(d.hasOwnProperty(p))if("$"===p.substr(0,1))switch(p){case "$as":A=d[p];break;case "$multi":h=d[p];break;case "$require":m=d[p];break;default:p.substr(0,3)}else z[p]=(new k(d[p])).value(l[y])[0];z=b.find(z);!m||m&&z[0]?l[y][A]=!1===h?
z[0]:z:C.push(l[y])}c.data("flag.join",!0)}if(C.length){c.time("removalQueue");for(p=0;p<C.length;p++)q=l.indexOf(C[p]),-1<q&&l.splice(q,1);c.time("removalQueue")}if(a.transform){c.time("transform");for(p=0;p<l.length;p++)l.splice(p,1,a.transform(l[p]));c.time("transform");c.data("flag.transform",!0)}this._transformEnabled&&this._transformOut&&(c.time("transformOut"),l=this.transformOut(l),c.time("transformOut"));c.data("results",l.length);c.stop()}else c.stop(),l=[];l.__fdbOp=c;return l};e.prototype.indexOf=
function(a){if(a=this.find(a,{$decouple:!1})[0])return this._data.indexOf(a)};e.prototype.transform=function(a){return void 0!==a?("object"===typeof a?(void 0!==a.enabled&&(this._transformEnabled=a.enabled),void 0!==a.dataIn&&(this._transformIn=a.dataIn),void 0!==a.dataOut&&(this._transformOut=a.dataOut)):this._transformEnabled=!1===a?!1:!0,this):{enabled:this._transformEnabled,dataIn:this._transformIn,dataOut:this._transformOut}};e.prototype.transformIn=function(a){if(this._transformEnabled&&this._transformIn){if(a instanceof
Array){var c=[],e;for(e=0;e<a.length;e++)c[e]=this._transformIn(a[e]);return c}return this._transformIn(a)}return a};e.prototype.transformOut=function(a){if(this._transformEnabled&&this._transformOut){if(a instanceof Array){var c=[],e;for(e=0;e<a.length;e++)c[e]=this._transformOut(a[e]);return c}return this._transformOut(a)}return a};e.prototype.sort=function(a,c){c=c||[];var e=[],b,k;for(b in a)a.hasOwnProperty(b)&&(k={},k[b]=a[b],k.___fdbKey=b,e.push(k));return 2>e.length?this._sort(a,c):this._bucketSort(e,
c)};e.prototype._bucketSort=function(a,c){var e=a.shift(),b,k,d=[];if(0<a.length){c=this._sort(e,c);b=this.bucket(e.___fdbKey,c);for(k in b)b.hasOwnProperty(k)&&(e=[].concat(a),d=d.concat(this._bucketSort(e,b[k])));return d}return this._sort(e,c)};e.prototype._sort=function(a,c){var e=this,b,d=new k;b=d.parse(a,!0)[0];d.path(b.path);if(1===b.value)b=function(a,g){var c=d.value(a)[0],b=d.value(g)[0];return e.sortAsc(c,b)};else if(-1===b.value)b=function(a,g){var c=d.value(a)[0],b=d.value(g)[0];return e.sortDesc(c,
b)};else throw'ForerunnerDB.Collection "'+this.name()+'": $orderBy clause has invalid direction: '+b.value+", accepted values are 1 or -1 for ascending or descending!";return c.sort(b)};e.prototype.bucket=function(a,c){var e,b={};for(e=0;e<c.length;e++)b[c[e][a]]=b[c[e][a]]||[],b[c[e][a]].push(c[e]);return b};e.prototype._analyseQuery=function(a,c,e){var b={queriesOn:[this._name],indexMatch:[],hasJoin:!1,queriesJoin:!1,joinQueries:{},query:a,options:c},d,l=[],f=[],h,m,v,q,p,z;e.time("checkIndexes");
if(p=(new k).countKeys(a)){void 0!==a[this._primaryKey]&&(e.time("checkIndexMatch: Primary Key"),b.indexMatch.push({lookup:this._primaryIndex.lookup(a,c),keyData:{matchedKeys:[this._primaryKey],totalKeyCount:p,score:1},index:this._primaryIndex}),e.time("checkIndexMatch: Primary Key"));for(z in this._indexById)if(this._indexById.hasOwnProperty(z)&&(m=this._indexById[z],v=m.name(),e.time("checkIndexMatch: "+v),h=m.match(a,c),0<h.score&&(q=m.lookup(a,c),b.indexMatch.push({lookup:q,keyData:h,index:m})),
e.time("checkIndexMatch: "+v),h.score===p))break;e.time("checkIndexes");1<b.indexMatch.length&&(e.time("findOptimalIndex"),b.indexMatch.sort(function(a,c){if(a.keyData.score>c.keyData.score)return-1;if(a.keyData.score<c.keyData.score)return 1;if(a.keyData.score===c.keyData.score)return a.lookup.length-c.lookup.length}),e.time("findOptimalIndex"))}if(c.join){b.hasJoin=!0;for(e=0;e<c.join.length;e++)for(d in c.join[e])c.join[e].hasOwnProperty(d)&&(l.push(d),"$as"in c.join[e][d]?f.push(c.join[e][d].$as):
f.push(d));for(d=0;d<f.length;d++)if(c=this._queryReferencesCollection(a,f[d],""))b.joinQueries[l[d]]=c,b.queriesJoin=!0;b.joinsOn=l;b.queriesOn=b.queriesOn.concat(l)}return b};e.prototype._queryReferencesCollection=function(a,c,e){for(var b in a)if(a.hasOwnProperty(b)){if(b===c)return e&&(e+="."),e+b;if("object"===typeof a[b])return e&&(e+="."),e+=b,this._queryReferencesCollection(a[b],c,e)}return!1};e.prototype._match=function(a,c,e){var b,d;b=typeof a;d=typeof c;var k=!0,l;if(!("string"!==b&&"number"!==
b||"string"!==d&&"number"!==d))a!==c&&(k=!1);else for(l in c)if(c.hasOwnProperty(l)){b=!1;if("$"===l.substr(0,1)&&(d=this._matchOp(l,a,c[l]),-1<d)){if(d){if("or"===e)return!0}else k=d;b=!0}if(!b&&c[l]instanceof RegExp)if(b=!0,"object"===typeof a&&void 0!==a[l]&&c[l].test(a[l])){if("or"===e)return!0}else k=!1;if(!b)if("object"===typeof c[l])if(void 0!==a[l]){if(a[l]instanceof Array&&!(c[l]instanceof Array))for(b=!1,d=0;d<a[l].length&&!(b=this._match(a[l][d],c[l],void 0));d++);else if(!(a[l]instanceof
Array)&&c[l]instanceof Array)for(b=!1,d=0;d<c[l].length&&!(b=this._match(a[l],c[l][d],void 0));d++);else b="object"===typeof a?this._match(a[l],c[l],void 0):this._match(void 0,c[l],void 0);if(b){if("or"===e)return!0}else k=!1}else if(c[l]&&void 0!==c[l].$exists)if(b=this._match(void 0,c[l],void 0)){if("or"===e)return!0}else k=!1;else k=!1;else if(a&&a[l]===c[l]){if("or"===e)return!0}else if(a&&a[l]&&a[l]instanceof Array&&c[l]&&"object"!==typeof c[l]){b=!1;for(d=0;d<a[l].length&&!(b=this._match(a[l][d],
c[l],void 0));d++);if(b){if("or"===e)return!0}else k=!1}else k=!1;if("and"===e&&!k)return!1}return k};e.prototype._matchOp=function(a,c,e){switch(a){case "$gt":return c>e;case "$gte":return c>=e;case "$lt":return c<e;case "$lte":return c<=e;case "$exists":return void 0===c!==e;case "$ne":return c!=e;case "$or":for(a=0;a<e.length;a++)if(this._match(c,e[a],"and"))return!0;return!1;case "$and":for(a=0;a<e.length;a++)if(!this._match(c,e[a],"and"))return!1;return!0;case "$in":if(e instanceof Array){a=
e.length;var b;for(b=0;b<a;b++)if(e[b]===c)return!0;return!1}throw'ForerunnerDB.Collection "'+this.name()+'": Cannot use an $in operator on a non-array key: '+a;case "$nin":if(e instanceof Array){a=e.length;for(b=0;b<a;b++)if(e[b]===c)return!1;return!0}throw'ForerunnerDB.Collection "'+this.name()+'": Cannot use a $nin operator on a non-array key: '+a;}return-1};e.prototype.count=function(a,c){return a?this.find(a,c).length:this._data.length};e.prototype.findSub=function(a,c,e,b){var d=new k(c);a=
this.find(a);var l=a.length,f,h,m=this._db.collection("__FDB_temp_"+this.objectId()),v={parents:l,subDocTotal:0,subDocs:[],pathFound:!1,err:""};for(f=0;f<l;f++)if(h=d.value(a[f])[0]){m.setData(h);h=m.find(e,b);if(b.returnFirst&&h.length)return h[0];v.subDocs.push(h);v.subDocTotal+=h.length;v.pathFound=!0}m.drop();if(b.noStats)return v.subDocs;v.pathFound||(v.err="No objects found in the parent documents with a matching path of: "+c);return v};e.prototype.insertIndexViolation=function(a){var c,e=this._indexByName,
b,d;if(this._primaryIndex.get(a[this._primaryKey]))c=this._primaryIndex;else for(b in e)if(e.hasOwnProperty(b)&&(d=e[b],d.unique()&&d.violation(a))){c=d;break}return c?c.name():!1};e.prototype.ensureIndex=function(g,e){this._indexByName=this._indexByName||{};this._indexById=this._indexById||{};var b,d={start:(new Date).getTime()};if(e)switch(e.type){case "hashed":b=new a(g,e,this);break;case "btree":b=new c(g,e,this);break;default:b=new a(g,e,this)}else b=new a(g,e,this);if(this._indexByName[b.name()])return{err:"Index with that name already exists"};
if(this._indexById[b.id()])return{err:"Index with those keys already exists"};b.rebuild();this._indexByName[b.name()]=b;this._indexById[b.id()]=b;d.end=(new Date).getTime();d.total=d.end-d.start;this._lastOp={type:"ensureIndex",stats:{time:d}};return{index:b,id:b.id(),name:b.name(),state:b.state()}};e.prototype.index=function(a){if(this._indexByName)return this._indexByName[a]};e.prototype.lastOp=function(){return this._metrics.list()};e.prototype.diff=function(a){var c={insert:[],update:[],remove:[]},
e=this.primaryKey(),b,d,l,k;if(e===a.primaryKey()){for(b=a._data;b&&!(b instanceof Array);)a=b,b=a._data;k=b.length;for(d=0;d<k;d++)l=b[d],this._primaryIndex.get(l[e])?this._primaryCrc.get(l[e])!==a._primaryCrc.get(l[e])&&c.update.push(l):c.insert.push(l);b=this._data;k=b.length;for(d=0;d<k;d++)l=b[d],a._primaryIndex.get(l[e])||c.remove.push(l)}else throw'ForerunnerDB.Collection "'+this.name()+'": Collection diffing requires that both collections have the same primary key!';return c};f.prototype.collection=
function(a,c){if(a)return this._collection[a]||this.debug()&&console.log("Creating collection "+a),this._collection[a]=this._collection[a]||(new e(a)).db(this),void 0!==c&&this._collection[a].primaryKey(c),this._collection[a];throw'ForerunnerDB.Core "'+this.name()+'": Cannot get collection with undefined name!';};f.prototype.collectionExists=function(a){return Boolean(this._collection[a])};f.prototype.collections=function(a){var c=[],e;a&&(a instanceof RegExp||(a=RegExp(a)));for(e in this._collection)this._collection.hasOwnProperty(e)&&
(a?a.exec(e)&&c.push({name:e,count:this._collection[e].count()}):c.push({name:e,count:this._collection[e].count()}));return c};h.finishModule("Collection");m.exports=e},{"./Crc":6,"./IndexBinaryTree":10,"./IndexHashMap":11,"./KeyValueStore":12,"./Metrics":13,"./Path":24,"./Shared":27}],4:[function(f,m,h){var d,b;h=f("./Shared");var k=function(){this.init.apply(this,arguments)};k.prototype.init=function(a){this._name=a;this._data=new b("__FDB__cg_data_"+this._name);this._collections=[];this._view=
[]};h.addModule("CollectionGroup",k);h.mixin(k.prototype,"Mixin.Common");h.mixin(k.prototype,"Mixin.ChainReactor");h.mixin(k.prototype,"Mixin.Constants");h.mixin(k.prototype,"Mixin.Triggers");b=f("./Collection");f=h.modules.Core;d=h.modules.Core.prototype.init;k.prototype.on=function(){this._data.on.apply(this._data,arguments)};k.prototype.off=function(){this._data.off.apply(this._data,arguments)};k.prototype.emit=function(){this._data.emit.apply(this._data,arguments)};k.prototype.primaryKey=function(a){return void 0!==
a?(this._primaryKey=a,this):this._primaryKey};h.synthesize(k.prototype,"state");h.synthesize(k.prototype,"db");k.prototype.addCollection=function(a){if(a&&-1===this._collections.indexOf(a)){if(this._collections.length){if(this._primaryKey!==a.primaryKey())throw'ForerunnerDB.CollectionGroup "'+this.name()+'": All collections in a collection group must have the same primary key!';}else this.primaryKey(a.primaryKey());this._collections.push(a);a._groups.push(this);a.chain(this);this._data.insert(a.find())}return this};
k.prototype.removeCollection=function(a){if(a){var c=this._collections.indexOf(a);-1!==c&&(a.unChain(this),this._collections.splice(c,1),c=a._groups.indexOf(this),-1!==c&&a._groups.splice(c,1));0===this._collections.length&&delete this._primaryKey}return this};k.prototype._chainHandler=function(a){switch(a.type){case "setData":a.data=this.decouple(a.data);this._data.remove(a.options.oldData);this._data.insert(a.data);break;case "insert":a.data=this.decouple(a.data);this._data.insert(a.data);break;
case "update":this._data.update(a.data.query,a.data.update,a.options);break;case "remove":this._data.remove(a.data.query,a.options)}};k.prototype.insert=function(){this._collectionsRun("insert",arguments)};k.prototype.update=function(){this._collectionsRun("update",arguments)};k.prototype.updateById=function(){this._collectionsRun("updateById",arguments)};k.prototype.remove=function(){this._collectionsRun("remove",arguments)};k.prototype._collectionsRun=function(a,c){for(var b=0;b<this._collections.length;b++)this._collections[b][a].apply(this._collections[b],
c)};k.prototype.find=function(a,c){return this._data.find(a,c)};k.prototype.removeById=function(a){for(var c=0;c<this._collections.length;c++)this._collections[c].removeById(a)};k.prototype.subset=function(a,c){var d=this.find(a,c);return(new b)._subsetOf(this).primaryKey(this._primaryKey).setData(d)};k.prototype.drop=function(){if("dropped"!==this._state){var a,c;this._debug&&console.log("Dropping collection group "+this._name);this._state="dropped";if(this._collections&&this._collections.length)for(c=
[].concat(this._collections),a=0;a<c.length;a++)this.removeCollection(c[a]);if(this._view&&this._view.length)for(c=[].concat(this._view),a=0;a<c.length;a++)this._removeView(c[a]);this.emit("drop",this)}return!0};f.prototype.init=function(){this._collectionGroup={};d.apply(this,arguments)};f.prototype.collectionGroup=function(a){return a?(this._collectionGroup[a]=this._collectionGroup[a]||(new k(a)).db(this),this._collectionGroup[a]):this._collectionGroup};f.prototype.collectionGroups=function(){var a=
[],c;for(c in this._collectionGroup)this._collectionGroup.hasOwnProperty(c)&&a.push({name:c});return a};m.exports=k},{"./Collection":3,"./Shared":27}],5:[function(f,m,h){var d,b,k;d=f("./Shared");k=f("./Overload");h=function(a){this.init.apply(this,arguments)};h.prototype.init=function(a){this._name=a;this._collection={};this._debug={}};h.prototype.moduleLoaded=k({string:function(a){if(void 0!==a){a=a.replace(/ /g,"");a=a.split(",");var c;for(c=0;c<a.length;c++)if(!d.modules[a[c]])return!1;return!0}return!1},
"string, function":function(a,c){if(void 0!==a){a=a.replace(/ /g,"");var b=a.split(","),e;for(e=0;e<b.length;e++)if(!d.modules[b[e]])return!1;c()}},"string, function, function":function(a,c,b){if(void 0!==a){a=a.replace(/ /g,"");a=a.split(",");var e;for(e=0;e<a.length;e++)if(!d.modules[a[e]])return b(),!1;c()}}});h.prototype.version=function(a,c){return void 0!==a?0===d.version.indexOf(a)?(c&&c(),!0):!1:d.version};h.moduleLoaded=h.prototype.moduleLoaded;h.version=h.prototype.version;h.shared=d;h.prototype.shared=
d;d.addModule("Core",h);d.mixin(h.prototype,"Mixin.Common");d.mixin(h.prototype,"Mixin.ChainReactor");d.mixin(h.prototype,"Mixin.Constants");b=f("./Collection.js");f("./Metrics.js");f=f("./Crc.js");h.prototype._isServer=!1;d.synthesize(h.prototype,"state");d.synthesize(h.prototype,"name");h.prototype.isClient=function(){return!this._isServer};h.prototype.isServer=function(){return this._isServer};h.prototype.crc=f;h.prototype.isClient=function(){return!this._isServer};h.prototype.isServer=function(){return this._isServer};
h.prototype.arrayToCollection=function(a){return(new b).setData(a)};h.prototype.on=function(a,c){this._listeners=this._listeners||{};this._listeners[a]=this._listeners[a]||[];this._listeners[a].push(c);return this};h.prototype.off=function(a,c){if(a in this._listeners){var b=this._listeners[a],e=b.indexOf(c);-1<e&&b.splice(e,1)}return this};h.prototype.emit=function(a,c){this._listeners=this._listeners||{};if(a in this._listeners){var b=this._listeners[a],e=b.length,g;for(g=0;g<e;g++)b[g].apply(this,
Array.prototype.slice.call(arguments,1))}return this};h.prototype.peek=function(a){var c,b,e=[],g=typeof a;for(c in this._collection)this._collection.hasOwnProperty(c)&&(b=this._collection[c],e="string"===g?e.concat(b.peek(a)):e.concat(b.find(a)));return e};h.prototype.peekCat=function(a){var c,b,e={},g,d=typeof a;for(c in this._collection)this._collection.hasOwnProperty(c)&&(b=this._collection[c],(g="string"===d?b.peek(a):b.find(a))&&g.length&&(e[b.name()]=g));return e};h.prototype.drop=function(a){if("dropped"!==
this._state){var c=this.collections(),b=c.length,e,g=0;this._state="dropped";for(e=0;e<b;e++)this.collection(c[e].name).drop(function(){g++;g===b&&a&&a()}),delete this._collection[c[e].name];this.emit("drop",this)}return!0};m.exports=h},{"./Collection.js":3,"./Crc.js":6,"./Metrics.js":13,"./Overload":22,"./Shared":27}],6:[function(f,m,h){var d=function(){var b=[],d,a,c;for(a=0;256>a;a++){d=a;for(c=0;8>c;c++)d=d&1?3988292384^d>>>1:d>>>1;b[a]=d}return b}();m.exports=function(b){var k=-1,a;for(a=0;a<
b.length;a++)k=k>>>8^d[(k^b.charCodeAt(a))&255];return(k^-1)>>>0}},{}],7:[function(f,m,h){var d,b;h=f("./Shared");var k=function(){this.init.apply(this,arguments)};k.prototype.init=function(a){this._name=a;this._data={}};h.addModule("Document",k);h.mixin(k.prototype,"Mixin.Common");h.mixin(k.prototype,"Mixin.Events");h.mixin(k.prototype,"Mixin.ChainReactor");h.mixin(k.prototype,"Mixin.Constants");h.mixin(k.prototype,"Mixin.Triggers");f=f("./Collection");d=h.modules.Core;b=h.modules.Core.prototype.init;
h.synthesize(k.prototype,"state");h.synthesize(k.prototype,"db");h.synthesize(k.prototype,"name");k.prototype.setData=function(a){var c,b;if(a)if(a=this.decouple(a),this._linked){b={};for(c in this._data)"jQuery"!==c.substr(0,6)&&this._data.hasOwnProperty(c)&&void 0===a[c]&&(b[c]=1);a.$unset=b;this.updateObject(this._data,a,{})}else this._data=a;return this};k.prototype.update=function(a,c,b){this.updateObject(this._data,c,a,b)};k.prototype.updateObject=f.prototype.updateObject;k.prototype._isPositionalKey=
function(a){return".$"===a.substr(a.length-2,2)};k.prototype._updateProperty=function(a,c,b){this._linked?(jQuery.observable(a).setProperty(c,b),this.debug()&&console.log('ForerunnerDB.Document: Setting data-bound document property "'+c+'" for collection "'+this.name()+'"')):(a[c]=b,this.debug()&&console.log('ForerunnerDB.Document: Setting non-data-bound document property "'+c+'" for collection "'+this.name()+'"'))};k.prototype._updateIncrement=function(a,c,b){this._linked?jQuery.observable(a).setProperty(c,
a[c]+b):a[c]+=b};k.prototype._updateSpliceMove=function(a,c,b){this._linked?(jQuery.observable(a).move(c,b),this.debug()&&console.log('ForerunnerDB.Document: Moving data-bound document array index from "'+c+'" to "'+b+'" for collection "'+this.name()+'"')):(a.splice(b,0,a.splice(c,1)[0]),this.debug()&&console.log('ForerunnerDB.Document: Moving non-data-bound document array index from "'+c+'" to "'+b+'" for collection "'+this.name()+'"'))};k.prototype._updateSplicePush=function(a,c,b){a.length>c?this._linked?
jQuery.observable(a).insert(c,b):a.splice(c,0,b):this._linked?jQuery.observable(a).insert(b):a.push(b)};k.prototype._updatePush=function(a,c){this._linked?jQuery.observable(a).insert(c):a.push(c)};k.prototype._updatePull=function(a,c){this._linked?jQuery.observable(a).remove(c):a.splice(c,1)};k.prototype._updateMultiply=function(a,c,b){this._linked?jQuery.observable(a).setProperty(c,a[c]*b):a[c]*=b};k.prototype._updateRename=function(a,c,b){var e=a[c];this._linked?(jQuery.observable(a).setProperty(b,
e),jQuery.observable(a).removeProperty(c)):(a[b]=e,delete a[c])};k.prototype._updateUnset=function(a,c){this._linked?jQuery.observable(a).removeProperty(c):delete a[c]};k.prototype._updatePop=function(a,c){var b,e=!1;0<a.length&&(this._linked?(1===c?b=a.length-1:-1===c&&(b=0),-1<b&&(jQuery.observable(arr).remove(b),e=!0)):1===c?(a.pop(),e=!0):-1===c&&(a.shift(),e=!0));return e};k.prototype.drop=function(){if("dropped"!==this._state){if(this._db&&this._name&&this._db&&this._db._document&&this._db._document[this._name])return this._state=
"dropped",delete this._db._document[this._name],delete this._data,this.emit("drop",this),!0}else return!0;return!1};d.prototype.init=function(){b.apply(this,arguments)};d.prototype.document=function(a){return a?(this._document=this._document||{},this._document[a]=this._document[a]||(new k(a)).db(this),this._document[a]):this._document};d.prototype.documents=function(){var a=[],c;for(c in this._document)this._document.hasOwnProperty(c)&&a.push({name:c});return a};h.finishModule("Document");m.exports=
k},{"./Collection":3,"./Shared":27}],8:[function(f,m,h){var d,b,k,a;h=f("./Shared");var c=function(a,c){this.init.apply(this,arguments)};c.prototype.init=function(a,c,b){var d=this;this._selector=a;this._template=c;this._options=b;this._debug={};this._collectionDroppedWrap=function(){d._collectionDropped.apply(d,arguments)}};h.addModule("Grid",c);h.mixin(c.prototype,"Mixin.Common");h.mixin(c.prototype,"Mixin.ChainReactor");h.mixin(c.prototype,"Mixin.Constants");h.mixin(c.prototype,"Mixin.Triggers");
h.mixin(c.prototype,"Mixin.Events");d=f("./Collection");b=f("./CollectionGroup");k=f("./View");f("./ReactorIO");f=h.modules.Core;a=f.prototype.init;h.synthesize(c.prototype,"state");h.synthesize(c.prototype,"name");c.prototype.insert=function(){this._from.insert.apply(this._from,arguments)};c.prototype.update=function(){this._from.update.apply(this._from,arguments)};c.prototype.updateById=function(){this._from.updateById.apply(this._from,arguments)};c.prototype.remove=function(){this._from.remove.apply(this._from,
arguments)};c.prototype.from=function(a){void 0!==a&&(this._from&&(this._from.off("drop",this._collectionDroppedWrap),this._from._removeGrid(this)),"string"===typeof a&&(a=this._db.collection(a)),this._from=a,this.refresh());return this};c.prototype.db=function(a){return void 0!==a?(this._db=a,this):this._db};c.prototype._collectionDropped=function(a){a&&delete this._from};c.prototype.drop=function(){if("dropped"!==this._state){if(this._from)return this._from.unlink(this._selector,this.template()),
this._from.off("drop",this._collectionDroppedWrap),this._from._removeGrid(this),(this.debug()||this._db&&this._db.debug())&&console.log("ForerunnerDB.Grid: Dropping grid "+this._selector),this._state="dropped",this._db&&this._selector&&delete this._db._grid[this._selector],this.emit("drop",this),delete this._selector,delete this._template,delete this._from,delete this._db,!0}else return!0;return!1};c.prototype.template=function(a){return void 0!==a?(this._template=a,this):this._template};c.prototype._sortGridClick=
function(a){a=($(a.currentTarget).attr("data-grid-sort")||"").split(",");var c={},b;for(b=0;b<a.length;b++)c[a]=1;this._from.orderBy(c)};c.prototype.refresh=function(){if(this._from)if(this._from.link){var a=this,c=$(this._selector),b=function(){a._sortGridClick.apply(a,arguments)};c.html("");this._from.orderBy&&c.off("click","[data-grid-sort]",b);this._from.link(this._selector,this.template(),{wrap:"gridRow"});if(this._from.orderBy)c.on("click","[data-grid-sort]",b)}else throw"Grid requires the AutoBind module in order to operate!";
return this};d.prototype.grid=k.prototype.grid=function(a,b,g){if(this._db&&this._db._grid){if(this._db._grid[a])throw'ForerunnerDB.Collection/View "'+this.name()+'": Cannot create a grid using this collection/view because a grid with this name already exists: '+name;a=(new c(a,b,g)).db(this._db).from(this);this._grid=this._grid||[];this._grid.push(a);return a}};d.prototype._addGrid=b.prototype._addGrid=k.prototype._addGrid=function(a){void 0!==a&&(this._grid=this._grid||[],this._grid.push(a));return this};
d.prototype._removeGrid=b.prototype._removeGrid=k.prototype._removeGrid=function(a){void 0!==a&&this._grid&&(a=this._grid.indexOf(a),-1<a&&this._grid.splice(a,1));return this};f.prototype.init=function(){this._grid={};a.apply(this,arguments)};f.prototype.grid=function(a,b,g){this._grid[a]||(this.debug()||this._db&&this._db.debug())&&console.log("Core.Grid: Creating grid "+a);this._grid[a]=this._grid[a]||(new c(a,b,g)).db(this);return this._grid[a]};f.prototype.gridExists=function(a){return Boolean(this._grid[a])};
f.prototype.grids=function(){var a=[],c;for(c in this._grid)this._grid.hasOwnProperty(c)&&a.push({name:c,count:this._grid[c].count()});return a};h.finishModule("Grid");m.exports=c},{"./Collection":3,"./CollectionGroup":4,"./ReactorIO":26,"./Shared":27,"./View":28}],9:[function(f,m,h){var d,b;h=f("./Shared");b=f("./Overload");var k=function(a,c){this.init.apply(this,arguments)};k.prototype.init=function(a,c){this._options=c;this._selector=$(this._options.selector);if(!this._selector[0])throw'ForerunnerDB.Highchart "'+
a.name()+'": Chart target element does not exist via selector: '+this._options.selector;this._listeners={};this._collection=a;this._options.series=[];c.chartOptions=c.chartOptions||{};c.chartOptions.credits=!1;var b,e;switch(this._options.type){case "pie":this._selector.highcharts(this._options.chartOptions);this._chart=this._selector.highcharts();b=this._collection.find();e={allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,format:"<b>{point.name}</b>: {y} ({point.percentage:.0f}%)",style:{color:Highcharts.theme&&
Highcharts.theme.contrastTextColor||"black"}}};b=this.pieDataFromCollectionData(b,this._options.keyField,this._options.valField);$.extend(e,this._options.seriesOptions);$.extend(e,{name:this._options.seriesName,data:b});this._chart.addSeries(e,!0,!0);break;case "line":case "area":case "column":case "bar":b=this.seriesDataFromCollectionData(this._options.seriesField,this._options.keyField,this._options.valField,this._options.orderBy);this._options.chartOptions.xAxis=b.xAxis;this._options.chartOptions.series=
b.series;this._selector.highcharts(this._options.chartOptions);this._chart=this._selector.highcharts();break;default:throw'ForerunnerDB.Highchart "'+a.name()+'": Chart type specified is not currently supported by ForerunnerDB: '+this._options.type;}this._hookEvents()};h.addModule("Highchart",k);f=h.modules.Collection;d=f.prototype.init;h.mixin(k.prototype,"Mixin.Events");h.synthesize(k.prototype,"state");k.prototype.pieDataFromCollectionData=function(a,c,b){var e=[],g;for(g=0;g<a.length;g++)e.push([a[g][c],
a[g][b]]);return e};k.prototype.seriesDataFromCollectionData=function(a,c,b,e){var g=this._collection.distinct(a),d=[],k={categories:[]},f,h,m,u,w;for(u=0;u<g.length;u++){f=g[u];h={};h[a]=f;m=[];h=this._collection.find(h,{orderBy:e});for(w=0;w<h.length;w++)k.categories.push(h[w][c]),m.push(h[w][b]);d.push({name:f,data:m})}return{xAxis:k,series:d}};k.prototype._hookEvents=function(){var a=this;a._collection.on("change",function(){a._changeListener.apply(a,arguments)});a._collection.on("drop",function(){a.drop.apply(a,
arguments)})};k.prototype._changeListener=function(){if("undefined"!==typeof this._collection&&this._chart){var a=this._collection.find();switch(this._options.type){case "pie":this._chart.series[0].setData(this.pieDataFromCollectionData(a,this._options.keyField,this._options.valField),!0,!0);break;case "bar":case "line":case "area":case "column":var c=this.seriesDataFromCollectionData(this._options.seriesField,this._options.keyField,this._options.valField,this._options.orderBy);this._chart.xAxis[0].setCategories(c.xAxis.categories);
for(a=0;a<c.series.length;a++)this._chart.series[a]?this._chart.series[a].setData(c.series[a].data,!0,!0):this._chart.addSeries(c.series[a],!0,!0)}}};k.prototype.drop=function(){"dropped"!==this._state&&(this._state="dropped",this._chart&&this._chart.destroy(),this._collection&&(this._collection.off("change",this._changeListener),this._collection.off("drop",this.drop),this._collection._highcharts&&delete this._collection._highcharts[this._options.selector]),delete this._chart,delete this._options,
delete this._collection,this.emit("drop",this));return!0};f.prototype.init=function(){this._highcharts={};d.apply(this,arguments)};f.prototype.pieChart=new b({object:function(a){a.type="pie";a.chartOptions=a.chartOptions||{};a.chartOptions.chart=a.chartOptions.chart||{};a.chartOptions.chart.type="pie";this._highcharts[a.selector]||(this._highcharts[a.selector]=new k(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,c,b,e,g){g=g||{};g.selector=a;g.keyField=c;
g.valField=b;g.seriesName=e;this.pieChart(g)}});f.prototype.lineChart=new b({object:function(a){a.type="line";a.chartOptions=a.chartOptions||{};a.chartOptions.chart=a.chartOptions.chart||{};a.chartOptions.chart.type="line";this._highcharts[a.selector]||(this._highcharts[a.selector]=new k(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,c,b,e,g){g=g||{};g.seriesField=c;g.selector=a;g.keyField=b;g.valField=e;this.lineChart(g)}});f.prototype.areaChart=new b({object:function(a){a.type=
"area";a.chartOptions=a.chartOptions||{};a.chartOptions.chart=a.chartOptions.chart||{};a.chartOptions.chart.type="area";this._highcharts[a.selector]||(this._highcharts[a.selector]=new k(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,c,b,e,g){g=g||{};g.seriesField=c;g.selector=a;g.keyField=b;g.valField=e;this.areaChart(g)}});f.prototype.columnChart=new b({object:function(a){a.type="column";a.chartOptions=a.chartOptions||{};a.chartOptions.chart=a.chartOptions.chart||
{};a.chartOptions.chart.type="column";this._highcharts[a.selector]||(this._highcharts[a.selector]=new k(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,c,b,e,g){g=g||{};g.seriesField=c;g.selector=a;g.keyField=b;g.valField=e;this.columnChart(g)}});f.prototype.barChart=new b({object:function(a){a.type="bar";a.chartOptions=a.chartOptions||{};a.chartOptions.chart=a.chartOptions.chart||{};a.chartOptions.chart.type="bar";this._highcharts[a.selector]||(this._highcharts[a.selector]=
new k(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,c,b,e,g){g=g||{};g.seriesField=c;g.selector=a;g.keyField=b;g.valField=e;this.barChart(g)}});f.prototype.stackedBarChart=new b({object:function(a){a.type="bar";a.chartOptions=a.chartOptions||{};a.chartOptions.chart=a.chartOptions.chart||{};a.chartOptions.chart.type="bar";a.plotOptions=a.plotOptions||{};a.plotOptions.series=a.plotOptions.series||{};a.plotOptions.series.stacking=a.plotOptions.series.stacking||
"normal";this._highcharts[a.selector]||(this._highcharts[a.selector]=new k(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,c,b,e,g){g=g||{};g.seriesField=c;g.selector=a;g.keyField=b;g.valField=e;this.stackedBarChart(g)}});f.prototype.dropChart=function(a){this._highcharts&&this._highcharts[a]&&this._highcharts[a].drop()};h.finishModule("Highchart");m.exports=k},{"./Overload":22,"./Shared":27}],10:[function(f,m,h){h=f("./Shared");var d=f("./Path"),b=f("./vendor/btree");
f=function(){this.init.apply(this,arguments)};f.prototype.init=function(d,a,c){this._btree=new (b.create(2,this.sortAsc));this._size=0;this._id=this._itemKeyHash(d,d);this.unique(a&&a.unique?a.unique:!1);void 0!==d&&this.keys(d);void 0!==c&&this.collection(c);this.name(a&&a.name?a.name:this._id)};h.addModule("IndexBinaryTree",f);h.mixin(f.prototype,"Mixin.ChainReactor");h.mixin(f.prototype,"Mixin.Sorting");f.prototype.id=function(){return this._id};f.prototype.state=function(){return this._state};
f.prototype.size=function(){return this._size};h.synthesize(f.prototype,"data");h.synthesize(f.prototype,"name");h.synthesize(f.prototype,"collection");h.synthesize(f.prototype,"type");h.synthesize(f.prototype,"unique");f.prototype.keys=function(b){return void 0!==b?(this._keys=b,this._keyCount=(new d).parse(this._keys).length,this):this._keys};f.prototype.rebuild=function(){if(this._collection){var d=this._collection.subset({},{$decouple:!1,$orderBy:this._keys}).find(),a,c=d.length;this._btree=new (b.create(2,
this.sortAsc));this._unique&&(this._uniqueLookup={});for(a=0;a<c;a++)this.insert(d[a])}this._state={name:this._name,keys:this._keys,indexSize:this._size,built:new Date,updated:new Date,ok:!0}};f.prototype.insert=function(b,a){var c=this._unique,d=this._itemKeyHash(b,this._keys);c&&(c=this._itemHash(b,this._keys),this._uniqueLookup[c]=b);c=this._btree.get(d);void 0===c&&(c=[],this._btree.put(d,c));c.push(b);this._size++};f.prototype.remove=function(b,a){var c=this._unique,d=this._itemKeyHash(b,this._keys),
e;c&&(c=this._itemHash(b,this._keys),delete this._uniqueLookup[c]);c=this._btree.get(d);void 0!==c&&(e=c.indexOf(b),-1<e&&(1===c.length?this._btree.del(d):c.splice(e,1),this._size--))};f.prototype.violation=function(b){b=this._itemHash(b,this._keys);return Boolean(this._uniqueLookup[b])};f.prototype.hashViolation=function(b){return Boolean(this._uniqueLookup[b])};f.prototype.lookup=function(b){return this._data[this._itemHash(b,this._keys)]||[]};f.prototype.match=function(b,a){var c=new d,f=c.parseArr(this._keys),
c=c.parseArr(b),e=[],g=0,n;for(n=0;n<f.length;n++)if(c[n]===f[n])g++,e.push(c[n]);else return{matchedKeys:[],totalKeyCount:c.length,score:0};return{matchedKeys:e,totalKeyCount:c.length,score:g}};f.prototype._itemHash=function(b,a){var c=new d,f,e="",g;f=c.parse(a);for(g=0;g<f.length;g++)e&&(e+="_"),e+=c.value(b,f[g].path).join(":");return e};f.prototype._itemKeyHash=function(b,a){var c=new d,f,e="",g;f=c.parse(a);for(g=0;g<f.length;g++)e&&(e+="_"),e+=c.keyValue(b,f[g].path);return e};f.prototype._itemHashArr=
function(b,a){var c=new d,f,e=[],g,n,r,h;f=c.parse(a);for(r=0;r<f.length;r++)for(g=c.value(b,f[r].path),n=0;n<g.length;n++)if(0===r)e.push(g[n]);else for(h=0;h<e.length;h++)e[h]=e[h]+"_"+g[n];return e};h.finishModule("IndexBinaryTree");m.exports=f},{"./Path":24,"./Shared":27,"./vendor/btree":29}],11:[function(f,m,h){h=f("./Shared");var d=f("./Path");f=function(){this.init.apply(this,arguments)};f.prototype.init=function(b,d,a){this._crossRef={};this._size=0;this._id=this._itemKeyHash(b,b);this.data({});
this.unique(d&&d.unique?d.unique:!1);void 0!==b&&this.keys(b);void 0!==a&&this.collection(a);this.name(d&&d.name?d.name:this._id)};h.addModule("IndexHashMap",f);h.mixin(f.prototype,"Mixin.ChainReactor");f.prototype.id=function(){return this._id};f.prototype.state=function(){return this._state};f.prototype.size=function(){return this._size};h.synthesize(f.prototype,"data");h.synthesize(f.prototype,"name");h.synthesize(f.prototype,"collection");h.synthesize(f.prototype,"type");h.synthesize(f.prototype,
"unique");f.prototype.keys=function(b){return void 0!==b?(this._keys=b,this._keyCount=(new d).parse(this._keys).length,this):this._keys};f.prototype.rebuild=function(){if(this._collection){var b=this._collection.subset({},{$decouple:!1,$orderBy:this._keys}).find(),d,a=b.length;this._data={};this._unique&&(this._uniqueLookup={});for(d=0;d<a;d++)this.insert(b[d])}this._state={name:this._name,keys:this._keys,indexSize:this._size,built:new Date,updated:new Date,ok:!0}};f.prototype.insert=function(b,d){var a,
c;this._unique&&(a=this._itemHash(b,this._keys),this._uniqueLookup[a]=b);a=this._itemHashArr(b,this._keys);for(c=0;c<a.length;c++)this.pushToPathValue(a[c],b)};f.prototype.remove=function(b,d){var a,c;this._unique&&(a=this._itemHash(b,this._keys),delete this._uniqueLookup[a]);a=this._itemHashArr(b,this._keys);for(c=0;c<a.length;c++)this.pullFromPathValue(a[c],b)};f.prototype.violation=function(b){b=this._itemHash(b,this._keys);return Boolean(this._uniqueLookup[b])};f.prototype.hashViolation=function(b){return Boolean(this._uniqueLookup[b])};
f.prototype.pushToPathValue=function(b,d){var a=this._data[b]=this._data[b]||[];-1===a.indexOf(d)&&(a.push(d),this._size++,this.pushToCrossRef(d,a))};f.prototype.pullFromPathValue=function(b,d){var a=this._data[b],c;c=a.indexOf(d);-1<c&&(a.splice(c,1),this._size--,this.pullFromCrossRef(d,a));a.length||delete this._data[b]};f.prototype.pull=function(b){var d=b[this._collection.primaryKey()],a=this._crossRef[d],c,f=a.length,e;for(c=0;c<f;c++)e=a[c],this._pullFromArray(e,b);this._size--;delete this._crossRef[d]};
f.prototype._pullFromArray=function(b,d){for(var a=b.length;a--;)b[a]===d&&b.splice(a,1)};f.prototype.pushToCrossRef=function(b,d){var a=b[this._collection.primaryKey()];this._crossRef[a]=this._crossRef[a]||[];a=this._crossRef[a];-1===a.indexOf(d)&&a.push(d)};f.prototype.pullFromCrossRef=function(b,d){var a=b[this._collection.primaryKey()];delete this._crossRef[a]};f.prototype.lookup=function(b){return this._data[this._itemHash(b,this._keys)]||[]};f.prototype.match=function(b,k){var a=new d,c=a.parseArr(this._keys),
a=a.parseArr(b),f=[],e=0,g;for(g=0;g<c.length;g++)if(a[g]===c[g])e++,f.push(a[g]);else return{matchedKeys:[],totalKeyCount:a.length,score:0};return{matchedKeys:f,totalKeyCount:a.length,score:e}};f.prototype._itemHash=function(b,k){var a=new d,c,f="",e;c=a.parse(k);for(e=0;e<c.length;e++)f&&(f+="_"),f+=a.value(b,c[e].path).join(":");return f};f.prototype._itemKeyHash=function(b,k){var a=new d,c,f="",e;c=a.parse(k);for(e=0;e<c.length;e++)f&&(f+="_"),f+=a.keyValue(b,c[e].path);return f};f.prototype._itemHashArr=
function(b,k){var a=new d,c,f=[],e,g,n,r;c=a.parse(k);for(n=0;n<c.length;n++)for(e=a.value(b,c[n].path),g=0;g<e.length;g++)if(0===n)f.push(e[g]);else for(r=0;r<f.length;r++)f[r]=f[r]+"_"+e[g];return f};h.finishModule("IndexHashMap");m.exports=f},{"./Path":24,"./Shared":27}],12:[function(f,m,h){f=f("./Shared");h=function(d){this.init.apply(this,arguments)};h.prototype.init=function(d){this._name=d;this._data={};this._primaryKey="_id"};f.addModule("KeyValueStore",h);f.mixin(h.prototype,"Mixin.ChainReactor");
f.synthesize(h.prototype,"name");h.prototype.primaryKey=function(d){return void 0!==d?(this._primaryKey=d,this):this._primaryKey};h.prototype.truncate=function(){this._data={};return this};h.prototype.set=function(d,b){this._data[d]=b?b:!0;return this};h.prototype.get=function(d){return this._data[d]};h.prototype.lookup=function(d){d=d[this._primaryKey];var b,k,a,c;if(d instanceof Array){k=d.length;c=[];for(b=0;b<k;b++)(a=this._data[d[b]])&&c.push(a);return c}if(d instanceof RegExp){c=[];for(b in this._data)this._data.hasOwnProperty(b)&&
d.test(b)&&c.push(this._data[b]);return c}if("object"===typeof d){if(d.$ne){c=[];for(b in this._data)this._data.hasOwnProperty(b)&&b!==d.$ne&&c.push(this._data[b]);return c}if(d.$in&&d.$in instanceof Array){c=[];for(b in this._data)this._data.hasOwnProperty(b)&&-1<d.$in.indexOf(b)&&c.push(this._data[b]);return c}if(d.$nin&&d.$nin instanceof Array){c=[];for(b in this._data)this._data.hasOwnProperty(b)&&-1===d.$nin.indexOf(b)&&c.push(this._data[b]);return c}if(d.$or&&d.$or instanceof Array){c=[];for(b=
0;b<d.$or.length;b++)c=c.concat(this.lookup(d.$or[b]));return c}}else return a=this._data[d],void 0!==a?[a]:[]};h.prototype.unSet=function(d){delete this._data[d];return this};h.prototype.uniqueSet=function(d,b){return void 0===this._data[d]?(this._data[d]=b,!0):!1};f.finishModule("KeyValueStore");m.exports=h},{"./Shared":27}],13:[function(f,m,h){h=f("./Shared");var d=f("./Operation");f=function(){this.init.apply(this,arguments)};f.prototype.init=function(){this._data=[]};h.addModule("Metrics",f);
h.mixin(f.prototype,"Mixin.ChainReactor");f.prototype.create=function(b){b=new d(b);this._enabled&&this._data.push(b);return b};f.prototype.start=function(){this._enabled=!0;return this};f.prototype.stop=function(){this._enabled=!1;return this};f.prototype.clear=function(){this._data=[];return this};f.prototype.list=function(){return this._data};h.finishModule("Metrics");m.exports=f},{"./Operation":21,"./Shared":27}],14:[function(f,m,h){m.exports={preSetData:function(){},postSetData:function(){}}},
{}],15:[function(f,m,h){m.exports={chain:function(d){this._chain=this._chain||[];-1===this._chain.indexOf(d)&&this._chain.push(d)},unChain:function(d){this._chain&&(d=this._chain.indexOf(d),-1<d&&this._chain.splice(d,1))},chainSend:function(d,b,k){if(this._chain){var a=this._chain,c=a.length,f;for(f=0;f<c;f++)a[f].chainReceive(this,d,b,k)}},chainReceive:function(d,b,k,a){d={sender:d,type:b,data:k,options:a};(!this._chainHandler||this._chainHandler&&!this._chainHandler(d))&&this.chainSend(d.type,d.data,
d.options)}}},{}],16:[function(f,m,h){var d=0;f={decouple:function(b,d){if(void 0!==b){if(d){var a,c=JSON.stringify(b),f=[];for(a=0;a<d;a++)f.push(JSON.parse(c));return f}return JSON.parse(JSON.stringify(b))}},objectId:function(b){var k=Math.pow(10,17);if(b){var a=0,c=b.length,f;for(f=0;f<c;f++)a+=b.charCodeAt(f)*k;b=a.toString(16)}else d++,b=(d+(Math.random()*k+Math.random()*k+Math.random()*k+Math.random()*k)).toString(16);return b},debug:f("./Overload")([function(){return this._debug&&this._debug.all},
function(b){return void 0!==b?"boolean"===typeof b?(this._debug=this._debug||{},this._debug.all=b,this.chainSend("debug",this._debug),this):this._debug&&this._debug[b]||this._db&&this._db._debug&&this._db._debug[b]||this._debug&&this._debug.all:this._debug&&this._debug.all},function(b,d){return void 0!==b?void 0!==d?(this._debug=this._debug||{},this._debug[b]=d,this.chainSend("debug",this._debug),this):this._debug&&this._debug[d]||this._db&&this._db._debug&&this._db._debug[b]:this._debug&&this._debug.all}])};
m.exports=f},{"./Overload":22}],17:[function(f,m,h){m.exports={TYPE_INSERT:0,TYPE_UPDATE:1,TYPE_REMOVE:2,PHASE_BEFORE:0,PHASE_AFTER:1}},{}],18:[function(f,m,h){f={on:new Overload({"string, function":function(d,b){this._listeners=this._listeners||{};this._listeners[d]=this._listeners[d]||{};this._listeners[d]["*"]=this._listeners[d]["*"]||[];this._listeners[d]["*"].push(b);return this},"string, *, function":function(d,b,k){this._listeners=this._listeners||{};this._listeners[d]=this._listeners[d]||
{};this._listeners[d][b]=this._listeners[d][b]||[];this._listeners[d][b].push(k);return this}}),off:new Overload({string:function(d){this._listeners&&this._listeners[d]&&d in this._listeners&&delete this._listeners[d];return this},"string, function":function(d,b){var k,a;"string"===typeof b?this._listeners&&this._listeners[d]&&this._listeners[d][b]&&delete this._listeners[d][b]:d in this._listeners&&(k=this._listeners[d]["*"],a=k.indexOf(b),-1<a&&k.splice(a,1));return this},"string, *, function":function(d,
b,k){this._listeners&&d in this._listeners&&b in this.listeners[d]&&(d=this._listeners[d][b],k=d.indexOf(k),-1<k&&d.splice(k,1))},"string, *":function(d,b){this._listeners&&d in this._listeners&&b in this._listeners[d]&&delete this._listeners[d][b]}}),emit:function(d,b){this._listeners=this._listeners||{};if(d in this._listeners){if(this._listeners[d]["*"]){var k=this._listeners[d]["*"],a=k.length,c;for(c=0;c<a;c++)k[c].apply(this,Array.prototype.slice.call(arguments,1))}if(b instanceof Array&&b[0]&&
b[0][this._primaryKey]){var k=this._listeners[d],f,e,a=b.length;for(c=0;c<a;c++)if(k[b[c][this._primaryKey]])for(f=k[b[c][this._primaryKey]].length,e=0;e<f;e++)k[b[c][this._primaryKey]][e].apply(this,Array.prototype.slice.call(arguments,1))}}return this}};m.exports=f},{}],19:[function(f,m,h){m.exports={sortAsc:function(d,b){return"string"===typeof d&&"string"===typeof b?d.localeCompare(b):d>b?1:d<b?-1:0},sortDesc:function(d,b){return"string"===typeof d&&"string"===typeof b?b.localeCompare(d):d>b?
-1:d<b?1:0}}},{}],20:[function(f,m,h){m.exports={addTrigger:function(d,b,k,a){return-1===this._triggerIndex(d,b,k)?(this._trigger=this._trigger||{},this._trigger[b]=this._trigger[b]||{},this._trigger[b][k]=this._trigger[b][k]||[],this._trigger[b][k].push({id:d,method:a}),!0):!1},removeTrigger:function(d,b,k){d=this._triggerIndex(d,b,k);-1<d&&this._trigger[b][k].splice(d,1);return!1},willTrigger:function(d,b){return this._trigger&&this._trigger[d]&&this._trigger[d][b]&&this._trigger[d][b].length},
processTrigger:function(d,b,k,a,c){var f,e,g,n;if(this._trigger&&this._trigger[b]&&this._trigger[b][k]){f=this._trigger[b][k];g=f.length;for(e=0;e<g;e++){n=f[e];if(this.debug()){var r,h;switch(b){case this.TYPE_INSERT:r="insert";break;case this.TYPE_UPDATE:r="update";break;case this.TYPE_REMOVE:r="remove";break;default:r=""}switch(k){case this.PHASE_BEFORE:h="before";break;case this.PHASE_AFTER:h="after";break;default:h=""}console.log('Triggers: Processing trigger "'+id+'" for '+r+' in phase "'+h+
'"')}n=n.method.call(this,d,a,c);if(!1===n)return!1;if(void 0!==n&&!0!==n&&!1!==n)throw"ForerunnerDB.Mixin.Triggers: Trigger error: "+n;}return!0}},_triggerIndex:function(d,b,f){var a;if(this._trigger&&this._trigger[b]&&this._trigger[b][f])for(b=this._trigger[b][f],f=b.length,a=0;a<f;a++)if(b[a].id===d)return a;return-1}}},{}],21:[function(f,m,h){h=f("./Shared");var d=f("./Path");f=function(b){this.pathSolver=new d;this.counter=0;this.init.apply(this,arguments)};f.prototype.init=function(b){this._data=
{operation:b,index:{potential:[],used:!1},steps:[],time:{startMs:0,stopMs:0,totalMs:0,process:{}},flag:{},log:[]}};h.addModule("Operation",f);h.mixin(f.prototype,"Mixin.ChainReactor");f.prototype.start=function(){this._data.time.startMs=(new Date).getTime()};f.prototype.log=function(b){if(b){var d=0<this._log.length?this._data.log[this._data.log.length-1].time:0;b={event:b,time:(new Date).getTime(),delta:0};this._data.log.push(b);d&&(b.delta=b.time-d);return this}return this._data.log};f.prototype.time=
function(b){if(void 0!==b){var d=this._data.time.process,d=d[b]=d[b]||{};d.startMs?(d.stopMs=(new Date).getTime(),d.totalMs=d.stopMs-d.startMs,d.stepObj.totalMs=d.totalMs,delete d.stepObj):(d.startMs=(new Date).getTime(),d.stepObj={name:b},this._data.steps.push(d.stepObj));return this}return this._data.time};f.prototype.flag=function(b,d){if(void 0!==b&&void 0!==d)this._data.flag[b]=d;else return void 0!==b?this._data.flag[b]:this._data.flag};f.prototype.data=function(b,d,a){return void 0!==d?(this.pathSolver.set(this._data,
b,d),this):this.pathSolver.get(this._data,b)};f.prototype.pushData=function(b,d,a){this.pathSolver.push(this._data,b,d)};f.prototype.stop=function(){this._data.time.stopMs=(new Date).getTime();this._data.time.totalMs=this._data.time.stopMs-this._data.time.startMs};h.finishModule("Operation");m.exports=f},{"./Path":24,"./Shared":27}],22:[function(f,m,h){Overload=function(d){if(d){var b,f,a,c,h;if(!(d instanceof Array)){a={};for(b in d)if(d.hasOwnProperty(b))if(c=b.replace(/ /g,""),-1===c.indexOf("*"))a[c]=
d[b];else for(h=generateSignaturePermutations(c),c=0;c<h.length;c++)a[h[c]]||(a[h[c]]=d[b]);d=a}return function(){if(d instanceof Array)for(f=d.length,b=0;b<f;b++){if(d[b].length===arguments.length)return d[b].apply(this,arguments)}else{var a=[],c;for(b=0;b<arguments.length;b++)c=typeof arguments[b],"object"===c&&arguments[b]instanceof Array&&(c="array"),a.push(c);c=a.join(",");if(d[c])return d[c].apply(this,arguments);for(b=a.length;0<=b;b--)if(c=a.slice(0,b).join(","),d[c+",..."])return d[c+",..."].apply(this,
arguments)}throw'ForerunnerDB.Overload "'+this.name()+'": Overloaded method does not have a matching signature for the passed arguments: '+JSON.stringify(a);}}return function(){}};generateSignaturePermutations=function(d){var b=[],f,a=["string","object","number","function","undefined"],c;if(-1<d.indexOf("*"))for(c=0;c<a.length;c++)f=d.replace("*",a[c]),b=b.concat(generateSignaturePermutations(f));else b.push(d);return b};m.exports=Overload},{}],23:[function(f,m,h){var d,b,k;h=f("./Shared");var a=
function(){this.init.apply(this,arguments)};a.prototype.init=function(a){var d=this;this._name=a;this._data=new k("__FDB__dc_data_"+this._name);this._collData=new b;this._collections=[];this._collectionDroppedWrap=function(){d._collectionDropped.apply(d,arguments)}};h.addModule("Overview",a);h.mixin(a.prototype,"Mixin.Common");h.mixin(a.prototype,"Mixin.ChainReactor");h.mixin(a.prototype,"Mixin.Constants");h.mixin(a.prototype,"Mixin.Triggers");h.mixin(a.prototype,"Mixin.Events");b=f("./Collection");
k=f("./Document");f=h.modules.Core;d=h.modules.Core.prototype.init;h.synthesize(a.prototype,"state");h.synthesize(a.prototype,"db");h.synthesize(a.prototype,"name");h.synthesize(a.prototype,"query",function(a){var b=this.$super(a);void 0!==a&&this._refresh();return b});h.synthesize(a.prototype,"queryOptions",function(a){var b=this.$super(a);void 0!==a&&this._refresh();return b});h.synthesize(a.prototype,"reduce",function(a){var b=this.$super(a);void 0!==a&&this._refresh();return b});a.prototype.from=
function(a){return void 0!==a?("string"===typeof a&&(a=this._db.collection(a)),this._addCollection(a),this):this._collections};a.prototype.find=function(){return this._collData.find.apply(this._collData,arguments)};a.prototype.count=function(){return this._collData.count.apply(this._collData,arguments)};a.prototype._addCollection=function(a){-1===this._collections.indexOf(a)&&(this._collections.push(a),a.chain(this),a.on("drop",this._collectionDroppedWrap),this._refresh());return this};a.prototype._removeCollection=
function(a){-1<this._collections.indexOf(a)&&(this._collections.splice(a,1),a.unChain(this),a.off("drop",this._collectionDroppedWrap),this._refresh());return this};a.prototype._collectionDropped=function(a){a&&this._removeCollection(a)};a.prototype._refresh=function(){if("dropped"!==this._state){if(this._collections&&this._collections[0]){this._collData.primaryKey(this._collections[0].primaryKey());var a=[],b;for(b=0;b<this._collections.length;b++)a=a.concat(this._collections[b].find(this._query,
this._queryOptions));this._collData.setData(a)}this._reduce&&(a=this._reduce(),this._data.setData(a))}};a.prototype._chainHandler=function(a){switch(a.type){case "setData":case "insert":case "update":case "remove":this._refresh()}};a.prototype.data=function(){return this._data};a.prototype.drop=function(){if("dropped"!==this._state){this._state="dropped";delete this._data;for(delete this._collData;this._collections.length;)this._removeCollection(this._collections[0]);delete this._collections;this._db&&
this._name&&delete this._db._overview[this._name];delete this._name;this.emit("drop",this)}return!0};f.prototype.init=function(){this._overview={};d.apply(this,arguments)};f.prototype.overview=function(b){return b?(this._overview[b]=this._overview[b]||(new a(b)).db(this),this._overview[b]):this._overview};h.finishModule("Overview");m.exports=a},{"./Collection":3,"./Document":7,"./Shared":27}],24:[function(f,m,h){f=f("./Shared");h=function(d){this.init.apply(this,arguments)};h.prototype.init=function(d){d&&
this.path(d)};f.addModule("Path",h);f.mixin(h.prototype,"Mixin.ChainReactor");h.prototype.path=function(d){return void 0!==d?(this._path=this.clean(d),this._pathParts=this._path.split("."),this):this._path};h.prototype.hasObjectPaths=function(d,b){var f=!0,a;for(a in d)if(d.hasOwnProperty(a)&&(void 0===b[a]||"object"===typeof d[a]&&(f=this.hasObjectPaths(d[a],b[a]),!f)))return!1;return f};h.prototype.countKeys=function(d){var b=0,f;for(f in d)d.hasOwnProperty(f)&&void 0!==d[f]&&("object"!==typeof d[f]?
b++:b+=this.countKeys(d[f]));return b};h.prototype.countObjectPaths=function(d,b){var f,a={},c=0,h=0,e;for(e in b)b.hasOwnProperty(e)&&("object"===typeof b[e]?(f=this.countObjectPaths(d[e],b[e]),a[e]=f.matchedKeys,h+=f.totalKeyCount,c+=f.matchedKeyCount):(h++,d&&d[e]&&"object"!==typeof d[e]?(a[e]=!0,c++):a[e]=!1));return{matchedKeys:a,matchedKeyCount:c,totalKeyCount:h}};h.prototype.parse=function(d,b){var f=[],a="",c,h,e;for(h in d)if(d.hasOwnProperty(h))if(a=h,"object"===typeof d[h])if(b)for(c=this.parse(d[h],
b),e=0;e<c.length;e++)f.push({path:a+"."+c[e].path,value:c[e].value});else for(c=this.parse(d[h]),e=0;e<c.length;e++)f.push({path:a+"."+c[e].path});else b?f.push({path:a,value:d[h]}):f.push({path:a});return f};h.prototype.parseArr=function(d,b){b=b||{};return this._parseArr(d,"",[],b)};h.prototype._parseArr=function(d,b,f,a){var c,h="";b=b||"";f=f||[];for(c in d)d.hasOwnProperty(c)&&(!a.ignore||a.ignore&&!a.ignore.test(c))&&(h=b?b+"."+c:c,"object"===typeof d[c]?this._parseArr(d[c],h,f,a):f.push(h));
return f};h.prototype.value=function(d,b){if(void 0!==d&&"object"===typeof d){var f,a,c,h,e=[],g;void 0!==b&&(b=this.clean(b),f=b.split("."));f=f||this._pathParts;a=f.length;c=d;for(g=0;g<a;g++){c=c[f[g]];if(h instanceof Array){for(a=0;a<h.length;a++)e=e.concat(this.value(h,a+"."+f[g]));return e}if(!c||"object"!==typeof c)break;h=c}return[c]}return[]};h.prototype.set=function(d,b,f){if(void 0!==d&&void 0!==b){var a;b=this.clean(b);b=b.split(".");a=b.shift();b.length?(d[a]=d[a]||{},this.set(d[a],b.join("."),
f)):d[a]=f}return d};h.prototype.get=function(d,b){return this.value(d,b)[0]};h.prototype.push=function(d,b,f){if(void 0!==d&&void 0!==b){var a;b=this.clean(b);b=b.split(".");a=b.shift();if(b.length)d[a]=d[a]||{},this.set(d[a],b.join("."),f);else if(d[a]=d[a]||[],d[a]instanceof Array)d[a].push(f);else throw"ForerunnerDB.Path: Cannot push to a path whose endpoint is not an array!";}return d};h.prototype.keyValue=function(d,b){var f,a,c,h,e;void 0!==b&&(b=this.clean(b),f=b.split("."));f=f||this._pathParts;
a=f.length;c=d;for(e=0;e<a;e++)if(c=c[f[e]],!c||"object"!==typeof c){h=f[e]+":"+c;break}return h};h.prototype.clean=function(d){"."===d.substr(0,1)&&(d=d.substr(1,d.length-1));return d};f.finishModule("Path");m.exports=h},{"./Shared":27}],25:[function(f,m,h){h=f("./Shared");var d=f("localforage"),b,k,a,c,l;l=function(){this.init.apply(this,arguments)};l.prototype.init=function(a){a.isClient()&&void 0!==Storage&&(this.mode("localforage"),d.config({driver:[d.INDEXEDDB,d.WEBSQL,d.LOCALSTORAGE],name:"ForerunnerDB",
storeName:"FDB"}))};h.addModule("Persist",l);h.mixin(l.prototype,"Mixin.ChainReactor");b=h.modules.Core;k=f("./Collection");a=k.prototype.drop;f("./CollectionGroup");c=b.prototype.init;f=h.overload;l.prototype.mode=function(a){return void 0!==a?(this._mode=a,this):this._mode};l.prototype.driver=function(a){if(void 0!==a){switch(a.toUpperCase()){case "LOCALSTORAGE":d.setDriver(d.LOCALSTORAGE);break;case "WEBSQL":d.setDriver(d.WEBSQL);break;case "INDEXEDDB":d.setDriver(d.INDEXEDDB);break;default:throw"ForerunnerDB.Persist: The persistence driver you have specified is not found. Please use either IndexedDB, WebSQL or LocalStorage!";
}return this}return d.driver()};l.prototype.save=function(a,b,c){var f;f=function(a,b){a="object"===typeof a?"json::fdb::"+JSON.stringify(a):"raw::fdb::"+a;b&&b(!1,a)};switch(this.mode()){case "localforage":f(b,function(b,g){d.setItem(a,g).then(function(a){c(!1,a)},function(a){c(a)})});break;default:c&&c("No data handler.")}};l.prototype.load=function(a,b){var c,f,k;k=function(a,b){if(a){c=a.split("::fdb::");switch(c[0]){case "json":f=JSON.parse(c[1]);break;case "raw":f=c[1]}b&&b(!1,f)}else b(!1,
a)};switch(this.mode()){case "localforage":d.getItem(a).then(function(a){k(a,b)},function(a){b(a)});break;default:b&&b("No data handler or unrecognised data type.")}};l.prototype.drop=function(a,b){switch(this.mode()){case "localforage":d.removeItem(a).then(function(){b(!1)},function(a){b(a)});break;default:b&&b("No data handler or unrecognised data type.")}};k.prototype.drop=new f({"":function(){"dropped"!==this._state&&this.drop(!0)},"function":function(a){"dropped"!==this._state&&this.drop(!0,
a)},"boolean":function(b){if("dropped"!==this._state){if(b)if(this._name)if(this._db)this._db.persist.drop(this._name);else throw"ForerunnerDB.Persist: Cannot drop a collection's persistent storage when the collection is not attached to a database!";else throw"ForerunnerDB.Persist: Cannot drop a collection's persistent storage when no name assigned to collection!";a.apply(this,arguments)}},"boolean, function":function(b,c){"dropped"!==this._state&&(b&&(this._name?this._db?this._db.persist.drop(this._name,
c):c&&c("Cannot drop a collection's persistent storage when the collection is not attached to a database!"):c&&c("Cannot drop a collection's persistent storage when no name assigned to collection!")),a.apply(this,arguments))}});k.prototype.save=function(a){this._name?this._db?this._db.persist.save(this._name,this._data,a):a&&a("Cannot save a collection that is not attached to a database!"):a&&a("Cannot save a collection with no assigned name!")};k.prototype.load=function(a){var b=this;this._name?
this._db?this._db.persist.load(this._name,function(c,d){c?a&&a(c):(d&&b.setData(d),a&&a(!1))}):a&&a("Cannot load a collection that is not attached to a database!"):a&&a("Cannot load a collection with no assigned name!")};b.prototype.init=function(){this.persist=new l(this);c.apply(this,arguments)};b.prototype.load=function(a){var b=this._collection,c=b.keys().length,d;for(d in b)b.hasOwnProperty(d)&&b[d].load(function(b){b?a(b):(c--,0===c&&a(!1))})};b.prototype.save=function(a){var b=this._collection,
c=b.keys().length,d;for(d in b)b.hasOwnProperty(d)&&b[d].save(function(b){b?a(b):(c--,0===c&&a(!1))})};h.finishModule("Persist");m.exports=l},{"./Collection":3,"./CollectionGroup":4,"./Shared":27,localforage:36}],26:[function(f,m,h){f=f("./Shared");h=function(d,b,f){if(d&&b&&f){this._reactorIn=d;this._reactorOut=b;this._chainHandler=f;if(!d.chain||!b.chainReceive)throw"ForerunnerDB.ReactorIO: ReactorIO requires passed in and out objects to implement the ChainReactor mixin!";d.chain(this);this.chain(b)}else throw"ForerunnerDB.ReactorIO: ReactorIO requires an in, out and process argument to instantiate!";
};f.addModule("ReactorIO",h);h.prototype.drop=function(){"dropped"!==this._state&&(this._state="dropped",this._reactorIn&&this._reactorIn.unChain(this),this._reactorOut&&this.unChain(this._reactorOut),delete this._reactorIn,delete this._reactorOut,delete this._chainHandler,this.emit("drop",this));return!0};f.synthesize(h.prototype,"state");f.mixin(h.prototype,"Mixin.ChainReactor");f.mixin(h.prototype,"Mixin.Events");f.finishModule("ReactorIO");m.exports=h},{"./Shared":27}],27:[function(f,m,h){f={version:"1.3.4",
modules:{},_synth:{},addModule:function(d,b){this.modules[d]=b;this.emit("moduleLoad",[d,b])},finishModule:function(d){if(this.modules[d])this.modules[d]._fdbFinished=!0,this.emit("moduleFinished",[d,this.modules[d]]);else throw"ForerunnerDB.Shared: finishModule called on a module that has not been registered with addModule(): "+d;},moduleFinished:function(d,b){if(this.modules[d]&&this.modules[d]._fdbFinished)b(d,this.modules[d]);else this.on("moduleFinished",b)},moduleExists:function(d){return Boolean(this.modules[d])},
mixin:function(d,b){var f=this.mixins[b];if(f)for(var a in f)f.hasOwnProperty(a)&&(d[a]=f[a]);else throw"ForerunnerDB.Shared: Cannot find mixin named: "+b;},synthesize:function(d,b,f){this._synth[b]=this._synth[b]||function(a){return void 0!==a?(this["_"+b]=a,this):this["_"+b]};if(f){var a=this;d[b]=function(){var c=this.$super,d;this.$super=a._synth[b];d=f.apply(this,arguments);this.$super=c;return d}}else d[b]=this._synth[b]},overload:f("./Overload"),mixins:{"Mixin.Common":f("./Mixin.Common"),"Mixin.Events":f("./Mixin.Events"),
"Mixin.ChainReactor":f("./Mixin.ChainReactor"),"Mixin.CRUD":f("./Mixin.CRUD"),"Mixin.Constants":f("./Mixin.Constants"),"Mixin.Triggers":f("./Mixin.Triggers"),"Mixin.Sorting":f("./Mixin.Sorting")}};f.mixin(f,"Mixin.Events");m.exports=f},{"./Mixin.CRUD":14,"./Mixin.ChainReactor":15,"./Mixin.Common":16,"./Mixin.Constants":17,"./Mixin.Events":18,"./Mixin.Sorting":19,"./Mixin.Triggers":20,"./Overload":22}],28:[function(f,m,h){var d,b,k,a,c,l;h=f("./Shared");var e=function(a,b,c){this.init.apply(this,arguments)};
e.prototype.init=function(a,b,c){var e=this;this._name=a;this._groups=[];this._listeners={};this._querySettings={};this._debug={};this.query(b,!1);this.queryOptions(c,!1);this._collectionDroppedWrap=function(){e._collectionDropped.apply(e,arguments)};this._privateData=new d("__FDB__view_privateData_"+this._name)};h.addModule("View",e);h.mixin(e.prototype,"Mixin.Common");h.mixin(e.prototype,"Mixin.ChainReactor");h.mixin(e.prototype,"Mixin.Constants");h.mixin(e.prototype,"Mixin.Triggers");d=f("./Collection");
b=f("./CollectionGroup");l=f("./ActiveBucket");c=f("./ReactorIO");k=d.prototype.init;f=h.modules.Core;a=f.prototype.init;h.synthesize(e.prototype,"state");h.synthesize(e.prototype,"name");e.prototype.insert=function(){this._from.insert.apply(this._from,arguments)};e.prototype.update=function(){this._from.update.apply(this._from,arguments)};e.prototype.updateById=function(){this._from.updateById.apply(this._from,arguments)};e.prototype.remove=function(){this._from.remove.apply(this._from,arguments)};
e.prototype.find=function(a,b){return this.publicData().find(a,b)};e.prototype.data=function(){return this._privateData};e.prototype.from=function(a){var b=this;if(void 0!==a){this._from&&(this._from.off("drop",this._collectionDroppedWrap),this._from._removeView(this));"string"===typeof a&&(a=this._db.collection(a));this._from=a;this._io=new c(a,this,function(a){var c,d,e;if(b._querySettings.query){if("insert"===a.type){c=a.data;if(c instanceof Array)for(d=[],a=0;a<c.length;a++)b._privateData._match(c[a],
b._querySettings.query,"and")&&(d.push(c[a]),e=!0);else b._privateData._match(c,b._querySettings.query,"and")&&(d=c,e=!0);e&&this.chainSend("insert",d);return!0}if("update"===a.type&&(d=b._privateData.diff(b._from.subset(b._querySettings.query,b._querySettings.options)),d.insert.length||d.remove.length)){d.insert.length&&this.chainSend("insert",d.insert);if(d.update.length)for(e=b._privateData.primaryKey(),a=0;a<d.update.length;a++)c={},c[e]=d.update[a][e],this.chainSend("update",{query:c,update:d.update[a]});
if(d.remove.length){e=b._privateData.primaryKey();c=[];var g={query:{$or:c}};for(a=0;a<d.remove.length;a++)c.push({_id:d.remove[a][e]});this.chainSend("remove",g)}return!0}}return!1});var d=a.find(this._querySettings.query,this._querySettings.options);this._transformPrimaryKey(a.primaryKey());this._transformSetData(d);this._privateData.primaryKey(a.primaryKey());this._privateData.setData(d);this._querySettings.options&&this._querySettings.options.$orderBy?this.rebuildActiveBucket(this._querySettings.options.$orderBy):
this.rebuildActiveBucket()}return this};e.prototype._collectionDropped=function(a){a&&delete this._from};e.prototype.ensureIndex=function(){return this._privateData.ensureIndex.apply(this._privateData,arguments)};e.prototype._chainHandler=function(a){var b,c,d,e;switch(a.type){case "setData":this.debug()&&console.log('ForerunnerDB.View: Setting data on view "'+this.name()+'" in underlying (internal) view collection "'+this._privateData.name()+'"');a=this._from.find(this._querySettings.query,this._querySettings.options);
this._transformSetData(a);this._privateData.setData(a);break;case "insert":this.debug()&&console.log('ForerunnerDB.View: Inserting some data on view "'+this.name()+'" in underlying (internal) view collection "'+this._privateData.name()+'"');a.data=this.decouple(a.data);a.data instanceof Array||(a.data=[a.data]);if(this._querySettings.options&&this._querySettings.options.$orderBy)for(b=a.data,c=b.length,d=0;d<c;d++)e=this._activeBucket.insert(b[d]),this._transformInsert(a.data,e),this._privateData._insertHandle(a.data,
e);else e=this._privateData._data.length,this._transformInsert(a.data,e),this._privateData._insertHandle(a.data,e);break;case "update":this.debug()&&console.log('ForerunnerDB.View: Updating some data on view "'+this.name()+'" in underlying (internal) view collection "'+this._privateData.name()+'"');this._privateData.primaryKey();a=this._privateData.update(a.data.query,a.data.update,a.data.options);if(this._querySettings.options&&this._querySettings.options.$orderBy)for(c=a.length,d=0;d<c;d++)e=a[d],
this._activeBucket.remove(e),b=this._privateData._data.indexOf(e),e=this._activeBucket.insert(e),b!==e&&this._privateData._updateSpliceMove(this._privateData._data,b,e);if(this._transformEnabled&&this._transformIn)for(c=this._publicData.primaryKey(),b=0;b<a.length;b++)d={},e=a[b],d[c]=e[c],this._transformUpdate(d,e);break;case "remove":this.debug()&&console.log('ForerunnerDB.View: Removing some data on view "'+this.name()+'" in underlying (internal) view collection "'+this._privateData.name()+'"'),
this._transformRemove(a.data.query,a.options),this._privateData.remove(a.data.query,a.options)}};e.prototype.on=function(){this._privateData.on.apply(this._privateData,arguments)};e.prototype.off=function(){this._privateData.off.apply(this._privateData,arguments)};e.prototype.emit=function(){this._privateData.emit.apply(this._privateData,arguments)};e.prototype.drop=function(){if("dropped"!==this._state){if(this._from)return this._from.off("drop",this._collectionDroppedWrap),this._from._removeView(this),
(this.debug()||this._db&&this._db.debug())&&console.log("ForerunnerDB.View: Dropping view "+this._name),this._state="dropped",this._io&&this._io.drop(),this._privateData&&this._privateData.drop(),this._db&&this._name&&delete this._db._view[this._name],this.emit("drop",this),delete this._chain,delete this._from,delete this._privateData,delete this._io,delete this._groups,delete this._listeners,delete this._querySettings,delete this._db,!0}else return!0;return!1};e.prototype.db=function(a){return void 0!==
a?(this._db=a,this.privateData().db(a),this.publicData().db(a),this):this._db};e.prototype.primaryKey=function(){return this._privateData.primaryKey()};e.prototype.queryData=function(a,b,c){void 0!==a&&(this._querySettings.query=a);void 0!==b&&(this._querySettings.options=b);return void 0!==a||void 0!==b?(void 0!==c&&!0!==c||this.refresh(),this):this._querySettings};e.prototype.queryAdd=function(a,b,c){var d=this._querySettings.query,e;if(void 0!==a)for(e in a)a.hasOwnProperty(e)&&(void 0===d[e]||
void 0!==d[e]&&b)&&(d[e]=a[e]);void 0!==c&&!0!==c||this.refresh()};e.prototype.queryRemove=function(a,b){var c=this._querySettings.query,d;if(void 0!==a)for(d in a)a.hasOwnProperty(d)&&delete c[d];void 0!==b&&!0!==b||this.refresh()};e.prototype.query=function(a,b){return void 0!==a?(this._querySettings.query=a,void 0!==b&&!0!==b||this.refresh(),this):this._querySettings.query};e.prototype.orderBy=function(a){if(void 0!==a){var b=this.queryOptions()||{};b.$orderBy=a;this.queryOptions(b);return this}return(this.queryOptions()||
{}).$orderBy};e.prototype.queryOptions=function(a,b){return void 0!==a?(this._querySettings.options=a,void 0===a.$decouple&&(a.$decouple=!0),void 0===b||!0===b?this.refresh():this.rebuildActiveBucket(a.$orderBy),this):this._querySettings.options};e.prototype.rebuildActiveBucket=function(a){if(a){var b=this._privateData._data,c=b.length;this._activeBucket=new l(a);this._activeBucket.primaryKey(this._privateData.primaryKey());for(a=0;a<c;a++)this._activeBucket.insert(b[a])}else delete this._activeBucket};
e.prototype.refresh=function(){if(this._from){var a=this.publicData();this._privateData.remove();a.remove();this._privateData.insert(this._from.find(this._querySettings.query,this._querySettings.options))}this._querySettings.options&&this._querySettings.options.$orderBy?this.rebuildActiveBucket(this._querySettings.options.$orderBy):this.rebuildActiveBucket();return this};e.prototype.count=function(){return this._privateData&&this._privateData._data?this._privateData._data.length:0};e.prototype.transform=
function(a){return void 0!==a?("object"===typeof a?(void 0!==a.enabled&&(this._transformEnabled=a.enabled),void 0!==a.dataIn&&(this._transformIn=a.dataIn),void 0!==a.dataOut&&(this._transformOut=a.dataOut)):this._transformEnabled=!1===a?!1:!0,this._transformPrimaryKey(this.privateData().primaryKey()),this._transformSetData(this.privateData().find()),this):{enabled:this._transformEnabled,dataIn:this._transformIn,dataOut:this._transformOut}};e.prototype.privateData=function(){return this._privateData};
e.prototype.publicData=function(){return this._transformEnabled?this._publicData:this._privateData};e.prototype._transformSetData=function(a){this._transformEnabled&&(this._publicData=new d("__FDB__view_publicData_"+this._name),this._publicData.db(this._privateData._db),this._publicData.transform({enabled:!0,dataIn:this._transformIn,dataOut:this._transformOut}),this._publicData.setData(a))};e.prototype._transformInsert=function(a,b){this._transformEnabled&&this._publicData&&this._publicData.insert(a,
b)};e.prototype._transformUpdate=function(a,b,c){this._transformEnabled&&this._publicData&&this._publicData.update(a,b,c)};e.prototype._transformRemove=function(a,b){this._transformEnabled&&this._publicData&&this._publicData.remove(a,b)};e.prototype._transformPrimaryKey=function(a){this._transformEnabled&&this._publicData&&this._publicData.primaryKey(a)};d.prototype.init=function(){this._view=[];k.apply(this,arguments)};d.prototype.view=function(a,b,c){if(this._db&&this._db._view){if(this._db._view[a])throw'ForerunnerDB.Collection "'+
this.name()+'": Cannot create a view using this collection because a view with this name already exists: '+a;a=(new e(a,b,c)).db(this._db).from(this);this._view=this._view||[];this._view.push(a);return a}};d.prototype._addView=b.prototype._addView=function(a){void 0!==a&&this._view.push(a);return this};d.prototype._removeView=b.prototype._removeView=function(a){void 0!==a&&(a=this._view.indexOf(a),-1<a&&this._view.splice(a,1));return this};f.prototype.init=function(){this._view={};a.apply(this,arguments)};
f.prototype.view=function(a){this._view[a]||(this.debug()||this._db&&this._db.debug())&&console.log("Core.View: Creating view "+a);this._view[a]=this._view[a]||(new e(a)).db(this);return this._view[a]};f.prototype.viewExists=function(a){return Boolean(this._view[a])};f.prototype.views=function(){var a=[],b;for(b in this._view)this._view.hasOwnProperty(b)&&a.push({name:b,count:this._view[b].count()});return a};h.finishModule("View");m.exports=e},{"./ActiveBucket":2,"./Collection":3,"./CollectionGroup":4,
"./ReactorIO":26,"./Shared":27}],29:[function(f,m,h){f=function(){function d(b){for(var a=[],c=0;c<arguments.length;c++)a=a.concat(arguments[c]);return a}var b={strcmp:function(b,a){for(var c,d,e=0;e<b.length;e++){if(e>=a.length)return 1;if((c=b.charCodeAt(e))<(d=a.charCodeAt(e)))return-1;if(c>d)return 1}return b.length==a.length?0:-1},numcmp:function(b,a){return b<a?-1:b>a?1:0},create:function(f,a){function c(){this.root=new e(this)}f="undefined"==typeof f?52:"number"==typeof f?Math.floor(f):parseInt(f,
10);1>f&&(f=1);var h=1<f?Math.floor(f/2):1;"function"!=typeof a&&(a=b.numcmp);var e=function(a,b,c){this.parent=a;this.leaves=b||[];this.leaves.forEach(function(a){a.parent=this},this);this.nodes=c||[null];this.nodes.forEach(function(a){null!==a&&(a.parent=this)},this)};e.prototype.search=function(b){if(0<this.leaves.length){var c=this.leaves[0];if(0==a(c.key,b))return{leaf:c,index:0};if(0>a(b,c.key))return null!==this.nodes[0]?this.nodes[0].search(b):{node:this,index:0};for(c=1;c<this.leaves.length;c++){var d=
this.leaves[c];if(0==a(d.key,b))return{leaf:d,index:c};if(0>a(b,d.key))break}return null!==this.nodes[c]?this.nodes[c].search(b):{node:this,index:c}}return{node:this,index:0}};e.prototype.get=function(a){a=this.search(a);if(a.leaf)return a.leaf.value};e.prototype.put=function(a,b,c){var d=this.search(a);if(d.leaf){if("undefined"!==typeof c&&!c)return!1;d.leaf.value=b;return!0}c=d.node;d=d.index;c.leaves.splice(d,0,new g(c,a,b));c.nodes.splice(d+1,0,null);c.leaves.length>f&&c.split();return!0};e.prototype.del=
function(a){var b=this.search(a);if(!b.leaf)return!1;a=b.leaf.parent;var b=b.index,c=a.nodes[b];if(null===c)a.leaves.splice(b,1),a.nodes.splice(b,1),a.balance();else{var d=c.leaves[c.leaves.length-1];c.del(d.key);d.parent=a;a.leaves.splice(b,1,d)}return!0};e.prototype.balance=function(){if(this.parent instanceof c)0==this.leaves.length&&null!==this.nodes[0]&&(this.parent.root=this.nodes[0],this.parent.root.parent=this.parent);else if(!(this.leaves.length>=h)){var a=this.parent.nodes.indexOf(this),
b=0<a?this.parent.nodes[a-1]:null,f=this.parent.nodes.length>a+1?this.parent.nodes[a+1]:null,g;if(null!==f&&f.leaves.length>h)g=this.parent.leaves[a],g.parent=this,this.leaves.push(g),g=f.leaves.shift(),g.parent=this.parent,this.parent.leaves[a]=g,a=f.nodes.shift(),null!==a&&(a.parent=this),this.nodes.push(a);else if(null!==b&&b.leaves.length>h)g=this.parent.leaves[a-1],g.parent=this,this.leaves.unshift(g),g=b.leaves.pop(),g.parent=this.parent,this.parent.leaves[a-1]=g,a=b.nodes.pop(),null!==a&&(a.parent=
this),this.nodes.unshift(a);else{if(null!==f)g=this.parent.leaves[a],b=new e(this.parent,d(this.leaves,[g],f.leaves),d(this.nodes,f.nodes)),this.parent.leaves.splice(a,1),this.parent.nodes.splice(a,2,b);else if(null!==b)g=this.parent.leaves[a-1],b=new e(this.parent,d(b.leaves,[g],this.leaves),d(b.nodes,this.nodes)),this.parent.leaves.splice(a-1,1),this.parent.nodes.splice(a-1,2,b);else throw Error("Internal error: "+this.toString(!0)+" has neither a left nor a right sibling");this.parent.balance()}}};
e.prototype.unsplit=function(b,c){b.parent=this;c.parent=this;if(0>a(b.key,this.leaves[0].key))this.leaves.unshift(b),this.nodes.splice(1,0,c);else{for(var d=1;d<this.leaves.length;d++)if(0>a(b.key,this.leaves[d].key)){this.leaves.splice(d,0,b);this.nodes.splice(d+1,0,c);break}d==this.leaves.length&&(this.leaves.push(b),this.nodes.push(c))}this.leaves.length>f&&this.split()};e.prototype.split=function(){var a=Math.floor(this.leaves.length/2);if(this.parent instanceof c)this.nodes=[new e(this,this.leaves.slice(0,
a),this.nodes.slice(0,a+1)),new e(this,this.leaves.slice(a+1),this.nodes.slice(a+1))],this.leaves=[this.leaves[a]];else{var b=this.leaves[a],d=new e(this.parent,this.leaves.slice(a+1),this.nodes.slice(a+1));this.leaves=this.leaves.slice(0,a);this.nodes=this.nodes.slice(0,a+1);this.parent.unsplit(b,d)}};e.prototype.toString=function(a){for(var b=[],d=0;d<this.leaves.length;d++)b.push(this.leaves[d].key);b="["+b.toString()+"]"+(this.parent instanceof c?":*":":"+this.parent);if(a)for(d=0;d<this.nodes.length;d++)b+=
" -> "+this.nodes[d];return b};e.prototype.print=function(a){for(var b="",d=0;d<a;d++)b+=" ";for(d=this.leaves.length-1;0<=d;d--)null!==this.nodes[d+1]&&this.nodes[d+1].print(a+2),console.log(b+this.leaves[d].key+(this.parent instanceof c?"*":""));null!==this.nodes[0]&&this.nodes[0].print(a+2)};var g=function(a,b,c){this.parent=a;this.key=b;this.value=c};g.prototype.toString=function(){return""+this.key};c.prototype.put=function(a,b,c){if("undefined"===typeof a||null===a)throw Error("Illegal key: "+
a);if("undefined"===typeof b)throw Error("Illegal value: "+b);return this.root.put(a,b,c)};c.prototype.get=function(a){if("undefined"===typeof a||null===a)throw Error("Illegal key: "+a);return this.root.get(a)};c.prototype.del=function(a){if("undefined"===typeof a||null===a)throw Error("Illegal key: "+a);return this.root.del(a)};c.prototype.walkAsc=function(b,d,e){if(0!=this.root.leaves.length){"function"==typeof b?(e=b,b=d=null):"function"==typeof d&&(e=d,d=null);b="undefined"!=typeof b?b:null;d=
"undefined"!=typeof d?d:null;var f;if(null===b){for(b=this.root;null!==b.nodes[0];)b=b.nodes[0];f=0}else if(f=this.root.search(b),f.leaf)b=f.leaf.parent,f=b.leaves.indexOf(f.leaf);else if(b=f.node,f=f.index,f>=b.leaves.length){if(b.parent instanceof c)return;f=b.parent.nodes.indexOf(b);if(f>=b.parent.leaves.length)return;b=b.parent}for(;!(null!==d&&0<a(b.leaves[f].key,d)||e(b.leaves[f].key,b.leaves[f].value));)if(null!==b.nodes[f+1])for(b=b.nodes[f+1],f=0;null!==b.nodes[0];)b=b.nodes[0];else if(b.leaves.length>
f+1)f++;else{do{if(b.parent instanceof c)return;f=b.parent.nodes.indexOf(b);b=b.parent}while(f>=b.leaves.length)}}};c.prototype.walk=c.prototype.walkAsc;c.prototype.walkDesc=function(b,d,e){"function"==typeof b?(e=b,b=d=null):"function"==typeof d&&(e=d,d=null);b="undefined"!=typeof b?b:null;d="undefined"!=typeof d?d:null;var f;if(null===d){for(d=this.root;null!==d.nodes[d.nodes.length-1];)d=d.nodes[d.nodes.length-1];f=d.leaves.length-1}else if(f=this.root.search(d),f.leaf)d=f.leaf.parent,f=d.leaves.indexOf(f.leaf);
else for(d=f.node,f=f.index-1;0>f;){if(d.parent instanceof c)return;f=d.parent.nodes.indexOf(d)-1;if(0>f)return;d=d.parent}for(;!(null!==b&&0>a(d.leaves[f].key,b)||e(d.leaves[f].key,d.leaves[f].value));)if(null!==d.nodes[f]){for(d=d.nodes[f];null!==d.nodes[d.nodes.length-1];)d=d.nodes[d.nodes.length-1];f=d.leaves.length-1}else if(0<f)f--;else{do{if(d.parent instanceof c)return;f=d.parent.nodes.indexOf(d)-1;d=d.parent}while(0>f)}};c.prototype.count=function(a,b){var c=0;this.walk("undefined"!=typeof a?
a:null,"undefined"!=typeof b?b:null,function(a,b){c++});return c};c.prototype.print=function(){this.root.print(0)};c.prototype.toString=function(){return"Tree("+f+") "+this.root.toString()};return c}};return b}();m.exports=f},{}],30:[function(f,m,h){function d(c){function f(b){null===m?x.push(b):a(function(){var a=m?b.onFulfilled:b.onRejected;if(null===a)(m?b.resolve:b.reject)(s);else{var c;try{c=a(s)}catch(d){b.reject(d);return}b.resolve(c)}})}function e(a){try{if(a===t)throw new TypeError("A promise cannot be resolved with itself.");
if(a&&("object"===typeof a||"function"===typeof a)){var b=a.then;if("function"===typeof b){k(b.bind(a),e,g);return}}m=!0;s=a;h()}catch(c){g(c)}}function g(a){m=!1;s=a;h()}function h(){for(var a=0,b=x.length;a<b;a++)f(x[a]);x=null}if("object"!==typeof this)throw new TypeError("Promises must be constructed via new");if("function"!==typeof c)throw new TypeError("not a function");var m=null,s=null,x=[],t=this;this.then=function(a,c){return new d(function(d,e){f(new b(a,c,d,e))})};k(c,e,g)}function b(a,
b,d,f){this.onFulfilled="function"===typeof a?a:null;this.onRejected="function"===typeof b?b:null;this.resolve=d;this.reject=f}function k(a,b,d){var f=!1;try{a(function(a){f||(f=!0,b(a))},function(a){f||(f=!0,d(a))})}catch(h){f||(f=!0,d(h))}}var a=f("asap");m.exports=d},{asap:32}],31:[function(f,m,h){function d(a){this.then=function(c){return"function"!==typeof c?this:new b(function(b,d){k(function(){try{b(c(a))}catch(e){d(e)}})})}}var b=f("./core.js"),k=f("asap");m.exports=b;d.prototype=Object.create(b.prototype);
var a=new d(!0),c=new d(!1),l=new d(null),e=new d(void 0),g=new d(0),n=new d("");b.resolve=function(f){if(f instanceof b)return f;if(null===f)return l;if(void 0===f)return e;if(!0===f)return a;if(!1===f)return c;if(0===f)return g;if(""===f)return n;if("object"===typeof f||"function"===typeof f)try{var h=f.then;if("function"===typeof h)return new b(h.bind(f))}catch(k){return new b(function(a,b){b(k)})}return new d(f)};b.from=b.cast=function(a){var c=Error("Promise.from and Promise.cast are deprecated, use Promise.resolve instead");
c.name="Warning";console.warn(c.stack);return b.resolve(a)};b.denodeify=function(a,c){c=c||Infinity;return function(){var d=this,e=Array.prototype.slice.call(arguments);return new b(function(b,f){for(;e.length&&e.length>c;)e.pop();e.push(function(a,c){a?f(a):b(c)});a.apply(d,e)})}};b.nodeify=function(a){return function(){var c=Array.prototype.slice.call(arguments),d="function"===typeof c[c.length-1]?c.pop():null;try{return a.apply(this,arguments).nodeify(d)}catch(e){if(null===d||"undefined"==typeof d)return new b(function(a,
b){b(e)});k(function(){d(e)})}}};b.all=function(){var a=1===arguments.length&&Array.isArray(arguments[0]),c=Array.prototype.slice.call(a?arguments[0]:arguments);a||(a=Error("Promise.all should be called with a single array, calling it with multiple arguments is deprecated"),a.name="Warning",console.warn(a.stack));return new b(function(a,b){function d(f,g){try{if(g&&("object"===typeof g||"function"===typeof g)){var h=g.then;if("function"===typeof h){h.call(g,function(a){d(f,a)},b);return}}c[f]=g;0===
--e&&a(c)}catch(k){b(k)}}if(0===c.length)return a([]);for(var e=c.length,f=0;f<c.length;f++)d(f,c[f])})};b.reject=function(a){return new b(function(b,c){c(a)})};b.race=function(a){return new b(function(c,d){a.forEach(function(a){b.resolve(a).then(c,d)})})};b.prototype.done=function(a,b){(arguments.length?this.then.apply(this,arguments):this).then(null,function(a){k(function(){throw a;})})};b.prototype.nodeify=function(a){if("function"!=typeof a)return this;this.then(function(b){k(function(){a(null,
b)})},function(b){k(function(){a(b)})})};b.prototype["catch"]=function(a){return this.then(null,a)}},{"./core.js":30,asap:32}],32:[function(f,m,h){(function(d){function b(){for(;f.next;){f=f.next;var a=f.task;f.task=void 0;var d=f.domain;d&&(f.domain=void 0,d.enter());try{a()}catch(g){if(e)throw d&&d.exit(),setTimeout(b,0),d&&d.enter(),g;setTimeout(function(){throw g;},0)}d&&d.exit()}c=!1}var f={task:void 0,next:null},a=f,c=!1,h=void 0,e=!1;if("undefined"!==typeof d&&d.nextTick)e=!0,h=function(){d.nextTick(b)};
else if("function"===typeof setImmediate)h="undefined"!==typeof window?setImmediate.bind(window,b):function(){setImmediate(b)};else if("undefined"!==typeof MessageChannel){var g=new MessageChannel;g.port1.onmessage=b;h=function(){g.port2.postMessage(0)}}else h=function(){setTimeout(b,0)};m.exports=function(b){a=a.next={task:b,domain:e&&d.domain,next:null};c||(c=!0,h())}}).call(this,f("_process"))},{_process:38}],33:[function(f,m,h){(function(){function d(a){var b=this,c={db:null};if(a)for(var d in a)c[d]=
a[d];return new t(function(a,d){var e=u.open(c.name,c.version);e.onerror=function(){d(e.error)};e.onupgradeneeded=function(){e.result.createObjectStore(c.storeName)};e.onsuccess=function(){c.db=e.result;b._dbInfo=c;a()}})}function b(a,b){var c=this;"string"!==typeof a&&(window.console.warn(a+" used as a key, but it is not a string."),a=String(a));var d=new t(function(b,d){c.ready().then(function(){var e=c._dbInfo,f=e.db.transaction(e.storeName,"readonly").objectStore(e.storeName).get(a);f.onsuccess=
function(){var a=f.result;void 0===a&&(a=null);b(a)};f.onerror=function(){d(f.error)}})["catch"](d)});s(d,b);return d}function h(a,b){var c=this,d=new t(function(b,d){c.ready().then(function(){var e=c._dbInfo,f=e.db.transaction(e.storeName,"readonly").objectStore(e.storeName).openCursor(),g=1;f.onsuccess=function(){var c=f.result;if(c){var d=a(c.value,c.key,g++);void 0!==d?b(d):c["continue"]()}else b()};f.onerror=function(){d(f.error)}})["catch"](d)});s(d,b);return d}function a(a,b,c){var d=this;
"string"!==typeof a&&(window.console.warn(a+" used as a key, but it is not a string."),a=String(a));var e=new t(function(c,e){d.ready().then(function(){var f=d._dbInfo,g=f.db.transaction(f.storeName,"readwrite"),f=g.objectStore(f.storeName);null===b&&(b=void 0);var h=f.put(b,a);g.oncomplete=function(){void 0===b&&(b=null);c(b)};g.onabort=g.onerror=function(){e(h.error)}})["catch"](e)});s(e,c);return e}function c(a,b){var c=this;"string"!==typeof a&&(window.console.warn(a+" used as a key, but it is not a string."),
a=String(a));var d=new t(function(b,d){c.ready().then(function(){var e=c._dbInfo,f=e.db.transaction(e.storeName,"readwrite"),g=f.objectStore(e.storeName)["delete"](a);f.oncomplete=function(){b()};f.onerror=function(){d(g.error)};f.onabort=function(a){a=a.target.error;"QuotaExceededError"===a&&d(a)}})["catch"](d)});s(d,b);return d}function l(a){var b=this,c=new t(function(a,c){b.ready().then(function(){var d=b._dbInfo,e=d.db.transaction(d.storeName,"readwrite"),f=e.objectStore(d.storeName).clear();
e.oncomplete=function(){a()};e.onabort=e.onerror=function(){c(f.error)}})["catch"](c)});s(c,a);return c}function e(a){var b=this,c=new t(function(a,c){b.ready().then(function(){var d=b._dbInfo,e=d.db.transaction(d.storeName,"readonly").objectStore(d.storeName).count();e.onsuccess=function(){a(e.result)};e.onerror=function(){c(e.error)}})["catch"](c)});r(c,a);return c}function g(a,b){var c=this,d=new t(function(b,d){0>a?b(null):c.ready().then(function(){var e=c._dbInfo,f=!1,g=e.db.transaction(e.storeName,
"readonly").objectStore(e.storeName).openCursor();g.onsuccess=function(){var c=g.result;c?0===a?b(c.key):f?b(c.key):(f=!0,c.advance(a)):b(null)};g.onerror=function(){d(g.error)}})["catch"](d)});r(d,b);return d}function n(a){var b=this,c=new t(function(a,c){b.ready().then(function(){var d=b._dbInfo,e=d.db.transaction(d.storeName,"readonly").objectStore(d.storeName).openCursor(),f=[];e.onsuccess=function(){var b=e.result;b?(f.push(b.key),b["continue"]()):a(f)};e.onerror=function(){c(e.error)}})["catch"](c)});
r(c,a);return c}function r(a,b){b&&a.then(function(a){b(null,a)},function(a){b(a)})}function s(a,b){b&&a.then(function(a){x(b,a)},function(a){b(a)})}function x(a,b){if(a)return setTimeout(function(){return a(null,b)},0)}var t="undefined"!==typeof m&&m.exports?f("promise"):this.Promise,u=u||this.indexedDB||this.webkitIndexedDB||this.mozIndexedDB||this.OIndexedDB||this.msIndexedDB;if(u){var w={_driver:"asyncStorage",_initStorage:d,iterate:h,getItem:b,setItem:a,removeItem:c,clear:l,length:e,key:g,keys:n};
"undefined"!==typeof m&&m.exports?m.exports=w:this.asyncStorage=w}}).call(window)},{promise:31}],34:[function(f,m,h){(function(){function d(a,b){b&&a.then(function(a){b(null,a)},function(a){b(a)})}var b="undefined"!==typeof m&&m.exports?f("promise"):this.Promise,h=this,a=null,c=null;try{if(!(this.localStorage&&"setItem"in this.localStorage))return;c=this.localStorage}catch(l){return}var e=3;"undefined"!==typeof m&&m.exports&&(e=2);var g={_driver:"localStorageWrapper",_initStorage:function(c){var d=
{};if(c)for(var g in c)d[g]=c[g];d.keyPrefix=d.name+"/";this._dbInfo=d;return(new b(function(a){1===e?f(["localforageSerializer"],a):2===e?a(f("./../utils/serializer")):a(h.localforageSerializer)})).then(function(c){a=c;return b.resolve()})},iterate:function(b,e){var f=this,g=f.ready().then(function(){for(var d=f._dbInfo.keyPrefix.length,e=c.length,g=0;g<e;g++){var h=c.key(g),k=c.getItem(h);k&&(k=a.deserialize(k));k=b(k,h.substring(d),g+1);if(void 0!==k)return k}});d(g,e);return g},getItem:function(b,
e){var f=this;"string"!==typeof b&&(window.console.warn(b+" used as a key, but it is not a string."),b=String(b));var g=f.ready().then(function(){var d=c.getItem(f._dbInfo.keyPrefix+b);d&&(d=a.deserialize(d));return d});d(g,e);return g},setItem:function(e,f,g){var h=this;"string"!==typeof e&&(window.console.warn(e+" used as a key, but it is not a string."),e=String(e));var k=h.ready().then(function(){void 0===f&&(f=null);var d=f;return new b(function(b,g){a.serialize(f,function(a,f){if(f)g(f);else try{c.setItem(h._dbInfo.keyPrefix+
e,a),b(d)}catch(k){"QuotaExceededError"!==k.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==k.name||g(k),g(k)}})})});d(k,g);return k},removeItem:function(a,b){var e=this;"string"!==typeof a&&(window.console.warn(a+" used as a key, but it is not a string."),a=String(a));var f=e.ready().then(function(){c.removeItem(e._dbInfo.keyPrefix+a)});d(f,b);return f},clear:function(a){var b=this,e=b.ready().then(function(){for(var a=b._dbInfo.keyPrefix,d=c.length-1;0<=d;d--){var e=c.key(d);0===e.indexOf(a)&&c.removeItem(e)}});
d(e,a);return e},length:function(a){var b=this.keys().then(function(a){return a.length});d(b,a);return b},key:function(a,b){var e=this,f=e.ready().then(function(){var b=e._dbInfo,d;try{d=c.key(a)}catch(f){d=null}d&&(d=d.substring(b.keyPrefix.length));return d});d(f,b);return f},keys:function(a){var b=this,e=b.ready().then(function(){for(var a=b._dbInfo,d=c.length,e=[],f=0;f<d;f++)0===c.key(f).indexOf(a.keyPrefix)&&e.push(c.key(f).substring(a.keyPrefix.length));return e});d(e,a);return e}};2===e?m.exports=
g:1===e?(void 0)("localStorageWrapper",function(){return g}):this.localStorageWrapper=g}).call(window)},{"./../utils/serializer":37,promise:31}],35:[function(f,m,h){(function(){function d(a){var b=this,c={db:null};if(a)for(var d in a)c[d]="string"!==typeof a[d]?a[d].toString():a[d];d=new s(function(a){B===w.DEFINE?f(["localforageSerializer"],a):B===w.EXPORT?a(f("./../utils/serializer")):a(x.localforageSerializer)});var e=new s(function(d,e){try{c.db=u(c.name,String(c.version),c.description,c.size)}catch(f){return b.setDriver(b.LOCALSTORAGE).then(function(){return b._initStorage(a)}).then(d)["catch"](e)}c.db.transaction(function(a){a.executeSql("CREATE TABLE IF NOT EXISTS "+
c.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],function(){b._dbInfo=c;d()},function(a,b){e(b)})})});return d.then(function(a){t=a;return e})}function b(a,b){var c=this;"string"!==typeof a&&(window.console.warn(a+" used as a key, but it is not a string."),a=String(a));var d=new s(function(b,d){c.ready().then(function(){var e=c._dbInfo;e.db.transaction(function(c){c.executeSql("SELECT * FROM "+e.storeName+" WHERE key = ? LIMIT 1",[a],function(a,c){var d=c.rows.length?c.rows.item(0).value:
null;d&&(d=t.deserialize(d));b(d)},function(a,b){d(b)})})})["catch"](d)});r(d,b);return d}function h(a,b){var c=this,d=new s(function(b,d){c.ready().then(function(){var e=c._dbInfo;e.db.transaction(function(c){c.executeSql("SELECT * FROM "+e.storeName,[],function(c,d){for(var e=d.rows,f=e.length,g=0;g<f;g++){var h=e.item(g),k=h.value;k&&(k=t.deserialize(k));k=a(k,h.key,g+1);if(void 0!==k){b(k);return}}b()},function(a,b){d(b)})})})["catch"](d)});r(d,b);return d}function a(a,b,c){var d=this;"string"!==
typeof a&&(window.console.warn(a+" used as a key, but it is not a string."),a=String(a));var e=new s(function(c,e){d.ready().then(function(){void 0===b&&(b=null);var f=b;t.serialize(b,function(b,g){if(g)e(g);else{var h=d._dbInfo;h.db.transaction(function(d){d.executeSql("INSERT OR REPLACE INTO "+h.storeName+" (key, value) VALUES (?, ?)",[a,b],function(){c(f)},function(a,b){e(b)})},function(a){a.code===a.QUOTA_ERR&&e(a)})}})})["catch"](e)});r(e,c);return e}function c(a,b){var c=this;"string"!==typeof a&&
(window.console.warn(a+" used as a key, but it is not a string."),a=String(a));var d=new s(function(b,d){c.ready().then(function(){var e=c._dbInfo;e.db.transaction(function(c){c.executeSql("DELETE FROM "+e.storeName+" WHERE key = ?",[a],function(){b()},function(a,b){d(b)})})})["catch"](d)});r(d,b);return d}function l(a){var b=this,c=new s(function(a,c){b.ready().then(function(){var d=b._dbInfo;d.db.transaction(function(b){b.executeSql("DELETE FROM "+d.storeName,[],function(){a()},function(a,b){c(b)})})})["catch"](c)});
r(c,a);return c}function e(a){var b=this,c=new s(function(a,c){b.ready().then(function(){var d=b._dbInfo;d.db.transaction(function(b){b.executeSql("SELECT COUNT(key) as c FROM "+d.storeName,[],function(b,c){var d=c.rows.item(0).c;a(d)},function(a,b){c(b)})})})["catch"](c)});r(c,a);return c}function g(a,b){var c=this,d=new s(function(b,d){c.ready().then(function(){var e=c._dbInfo;e.db.transaction(function(c){c.executeSql("SELECT key FROM "+e.storeName+" WHERE id = ? LIMIT 1",[a+1],function(a,c){var d=
c.rows.length?c.rows.item(0).key:null;b(d)},function(a,b){d(b)})})})["catch"](d)});r(d,b);return d}function n(a){var b=this,c=new s(function(a,c){b.ready().then(function(){var d=b._dbInfo;d.db.transaction(function(b){b.executeSql("SELECT key FROM "+d.storeName,[],function(b,c){for(var d=[],e=0;e<c.rows.length;e++)d.push(c.rows.item(e).key);a(d)},function(a,b){c(b)})})})["catch"](c)});r(c,a);return c}function r(a,b){b&&a.then(function(a){b(null,a)},function(a){b(a)})}var s="undefined"!==typeof m&&
m.exports?f("promise"):this.Promise,x=this,t=null,u=this.openDatabase;if(u){var w={DEFINE:1,EXPORT:2,WINDOW:3},B=w.WINDOW;"undefined"!==typeof m&&m.exports&&(B=w.EXPORT);var v={_driver:"webSQLStorage",_initStorage:d,iterate:h,getItem:b,setItem:a,removeItem:c,clear:l,length:e,key:g,keys:n};B===w.DEFINE?(void 0)("webSQLStorage",function(){return v}):B===w.EXPORT?m.exports=v:this.webSQLStorage=v}}).call(window)},{"./../utils/serializer":37,promise:31}],36:[function(f,m,h){(function(){function d(a,b){a[b]=
function(){var c=arguments;return a.ready().then(function(){return a[b].apply(a,c)})}}function b(){for(var a=1;a<arguments.length;a++){var b=arguments[a];if(b)for(var c in b)b.hasOwnProperty(c)&&(x(b[c])?arguments[0][c]=b[c].slice():arguments[0][c]=b[c])}return arguments[0]}function h(a){for(var b in e)if(e.hasOwnProperty(b)&&e[b]===a)return!0;return!1}function a(a){this._config=b({},n,a);this._driverSet=null;this._ready=!1;this._dbInfo=null;for(a=0;a<g.length;a++)d(this,g[a]);this.setDriver(this._config.driver)}
var c="undefined"!==typeof m&&m.exports?f("promise"):this.Promise,l={},e={INDEXEDDB:"asyncStorage",LOCALSTORAGE:"localStorageWrapper",WEBSQL:"webSQLStorage"},g="clear getItem iterate key keys length removeItem setItem".split(" "),n={description:"",driver:[e.INDEXEDDB,e.WEBSQL,e.LOCALSTORAGE].slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1},r=3;"undefined"!==typeof m&&m.exports&&(r=2);var s=function(a){var b=b||a.indexedDB||a.webkitIndexedDB||a.mozIndexedDB||a.OIndexedDB||
a.msIndexedDB,c={};c[e.WEBSQL]=!!a.openDatabase;c[e.INDEXEDDB]=!!function(){if("undefined"!==typeof a.openDatabase&&a.navigator&&a.navigator.userAgent&&/Safari/.test(a.navigator.userAgent)&&!/Chrome/.test(a.navigator.userAgent))return!1;try{return b&&"function"===typeof b.open&&"undefined"!==typeof a.IDBKeyRange}catch(c){return!1}}();var d=e.LOCALSTORAGE,f;try{f=a.localStorage&&"setItem"in a.localStorage&&a.localStorage.setItem}catch(g){f=!1}c[d]=!!f;return c}(this),x=Array.isArray||function(a){return"[object Array]"===
Object.prototype.toString.call(a)},t=this;a.prototype.INDEXEDDB=e.INDEXEDDB;a.prototype.LOCALSTORAGE=e.LOCALSTORAGE;a.prototype.WEBSQL=e.WEBSQL;a.prototype.config=function(a){if("object"===typeof a){if(this._ready)return Error("Can't call config() after localforage has been used.");for(var b in a)"storeName"===b&&(a[b]=a[b].replace(/\W/g,"_")),this._config[b]=a[b];"driver"in a&&a.driver&&this.setDriver(this._config.driver);return!0}return"string"===typeof a?this._config[a]:this._config};a.prototype.defineDriver=
function(a,b,d){var e=new c(function(b,d){try{var e=a._driver,f=Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver"),n=Error("Custom driver name already in use: "+a._driver);if(a._driver)if(h(a._driver))d(n);else{for(var m=g.concat("_initStorage"),n=0;n<m.length;n++){var q=m[n];if(!q||!a[q]||"function"!==typeof a[q]){d(f);return}}var r=c.resolve(!0);"_support"in a&&(r=a._support&&"function"===typeof a._support?a._support():c.resolve(!!a._support));r.then(function(c){s[e]=
c;l[e]=a;b()},d)}else d(f)}catch(v){d(v)}});e.then(b,d);return e};a.prototype.driver=function(){return this._driver||null};a.prototype.ready=function(a){var b=this,d=new c(function(a,c){b._driverSet.then(function(){null===b._ready&&(b._ready=b._initStorage(b._config));b._ready.then(a,c)})["catch"](c)});d.then(a,a);return d};a.prototype.setDriver=function(a,b,d){function e(){g._config.driver=g.driver()}var g=this;"string"===typeof a&&(a=[a]);this._driverSet=new c(function(b,d){var e=g._getFirstSupportedDriver(a),
n=Error("No available storage method found.");if(e){g._dbInfo=null;g._ready=null;if(h(e)){if(1===r){f([e],function(a){g._extend(a);b()});return}if(2===r){var m;switch(e){case g.INDEXEDDB:m=f("./drivers/indexeddb");break;case g.LOCALSTORAGE:m=f("./drivers/localstorage");break;case g.WEBSQL:m=f("./drivers/websql")}g._extend(m)}else g._extend(t[e])}else if(l[e])g._extend(l[e]);else{g._driverSet=c.reject(n);d(n);return}b()}else g._driverSet=c.reject(n),d(n)});this._driverSet.then(e,e);this._driverSet.then(b,
d);return this._driverSet};a.prototype.supports=function(a){return!!s[a]};a.prototype._extend=function(a){b(this,a)};a.prototype._getFirstSupportedDriver=function(a){if(a&&x(a))for(var b=0;b<a.length;b++){var c=a[b];if(this.supports(c))return c}return null};a.prototype.createInstance=function(b){return new a(b)};var u=new a;1===r?(void 0)("localforage",function(){return u}):2===r?m.exports=u:this.localforage=u}).call(window)},{"./drivers/indexeddb":33,"./drivers/localstorage":34,"./drivers/websql":35,
promise:31}],37:[function(f,m,h){(function(){function d(a){var b=0.75*a.length,d=a.length,g=0,h,m,s,x;"="===a[a.length-1]&&(b--,"="===a[a.length-2]&&b--);for(var t=new ArrayBuffer(b),u=new Uint8Array(t),b=0;b<d;b+=4)h=f.indexOf(a[b]),m=f.indexOf(a[b+1]),s=f.indexOf(a[b+2]),x=f.indexOf(a[b+3]),u[g++]=h<<2|m>>4,u[g++]=(m&15)<<4|s>>2,u[g++]=(s&3)<<6|x&63;return t}function b(a){a=new Uint8Array(a);var b="",d;for(d=0;d<a.length;d+=3)b+=f[a[d]>>2],b+=f[(a[d]&3)<<4|a[d+1]>>4],b+=f[(a[d+1]&15)<<2|a[d+2]>>
6],b+=f[a[d+2]&63];2===a.length%3?b=b.substring(0,b.length-1)+"=":1===a.length%3&&(b=b.substring(0,b.length-2)+"==");return b}var f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a={serialize:function(a,d){var e="";a&&(e=a.toString());if(a&&("[object ArrayBuffer]"===a.toString()||a.buffer&&"[object ArrayBuffer]"===a.buffer.toString())){var f,h="__lfsc__:";a instanceof ArrayBuffer?(f=a,h+="arbf"):(f=a.buffer,"[object Int8Array]"===e?h+="si08":"[object Uint8Array]"===e?h+="ui08":
"[object Uint8ClampedArray]"===e?h+="uic8":"[object Int16Array]"===e?h+="si16":"[object Uint16Array]"===e?h+="ur16":"[object Int32Array]"===e?h+="si32":"[object Uint32Array]"===e?h+="ui32":"[object Float32Array]"===e?h+="fl32":"[object Float64Array]"===e?h+="fl64":d(Error("Failed to get type for BinaryArray")));d(h+b(f))}else if("[object Blob]"===e)e=new FileReader,e.onload=function(){var a=b(this.result);d("__lfsc__:blob"+a)},e.readAsArrayBuffer(a);else try{d(JSON.stringify(a))}catch(k){window.console.error("Couldn't convert value into a JSON string: ",
a),d(null,k)}},deserialize:function(a){if("__lfsc__:"!==a.substring(0,9))return JSON.parse(a);var b=a.substring(13);a=a.substring(9,13);b=d(b);switch(a){case "arbf":return b;case "blob":return new Blob([b]);case "si08":return new Int8Array(b);case "ui08":return new Uint8Array(b);case "uic8":return new Uint8ClampedArray(b);case "si16":return new Int16Array(b);case "ur16":return new Uint16Array(b);case "si32":return new Int32Array(b);case "ui32":return new Uint32Array(b);case "fl32":return new Float32Array(b);
case "fl64":return new Float64Array(b);default:throw Error("Unkown type: "+a);}},stringToBuffer:d,bufferToString:b};"undefined"!==typeof m&&m.exports?m.exports=a:this.localforageSerializer=a}).call(window)},{}],38:[function(f,m,h){function d(){}f=m.exports={};f.nextTick=function(){if("undefined"!==typeof window&&window.setImmediate)return function(b){return window.setImmediate(b)};if("undefined"!==typeof window&&window.postMessage&&window.addEventListener){var b=[];window.addEventListener("message",
function(d){var a=d.source;a!==window&&null!==a||"process-tick"!==d.data||(d.stopPropagation(),0<b.length&&b.shift()())},!0);return function(d){b.push(d);window.postMessage("process-tick","*")}}return function(b){setTimeout(b,0)}}();f.title="browser";f.browser=!0;f.env={};f.argv=[];f.on=d;f.addListener=d;f.once=d;f.off=d;f.removeListener=d;f.removeAllListeners=d;f.emit=d;f.binding=function(b){throw Error("process.binding is not supported");};f.cwd=function(){return"/"};f.chdir=function(b){throw Error("process.chdir is not supported");
}},{}]},{},[1])(1)});
