!function(C){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=C();else if("function"==typeof define&&define.amd)define([],C);else{var d;"undefined"!=typeof window?d=window:"undefined"!=typeof global?d=global:"undefined"!=typeof self&&(d=self);d.ForerunnerDB=C()}}(function(){return function d(l,h,c){function b(a,e){if(!h[a]){if(!l[a]){var f="function"==typeof require&&require;if(!e&&f)return f(a,!0);if(g)return g(a,!0);f=Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",
f;}f=h[a]={exports:{}};l[a][0].call(f.exports,function(f){var e=l[a][1][f];return b(e?e:f)},f,f.exports,d,l,h,c)}return h[a].exports}for(var g="function"==typeof require&&require,a=0;a<c.length;a++)b(c[a]);return b}({1:[function(d,l,h){h=d("../lib/Core");d("../lib/CollectionGroup");d("../lib/View");d("../lib/Highchart");d("../lib/Persist");d("../lib/Document");d("../lib/Overview");l.exports=h},{"../lib/CollectionGroup":4,"../lib/Core":5,"../lib/Document":7,"../lib/Highchart":8,"../lib/Overview":18,
"../lib/Persist":20,"../lib/View":23}],2:[function(d,l,h){h=d("./Shared");d("./Path");d=function(c){var b;this._primaryKey="_id";this._keyArr=[];this._data=[];this._objLookup={};this._count=0;for(b in c)c.hasOwnProperty(b)&&this._keyArr.push({key:b,dir:c[b]})};h.addModule("ActiveBucket",d);h.synthesize(d.prototype,"primaryKey");d.prototype.qs=function(c,b,g,a){if(!b.length)return 0;for(var k=-1,e,f,t=0,w=b.length-1;w>=t;){e=Math.floor((t+w)/2);if(k===e)break;k=b[e];void 0!==k&&(f=a(this,c,g,k),0<
f&&(t=e+1),0>f&&(w=e-1));k=e}return 0<f?e+1:e};d.prototype._sortFunc=function(c,b,g,a){g=g.split(".:.");a=a.split(".:.");var k=c._keyArr,e=k.length,f,t,w;for(f=0;f<e;f++)if(t=k[f],w=typeof b[t.key],"number"===w&&(g[f]=Number(g[f]),a[f]=Number(a[f])),g[f]!==a[f]){if(1===t.dir)return c.sortAsc(g[f],a[f]);if(-1===t.dir)return c.sortDesc(g[f],a[f])}};d.prototype.insert=function(c){var b,g;b=this.documentKey(c);g=this._data.indexOf(b);-1===g&&(g=this.qs(c,this._data,b,this._sortFunc));this._data.splice(g,
0,b);this._objLookup[c[this._primaryKey]]=b;this._count++;return g};d.prototype.remove=function(c){var b;if(b=this._objLookup[c[this._primaryKey]])if(b=this._data.indexOf(b),-1<b)return this._data.splice(b,1),delete this._objLookup[c[this._primaryKey]],this._count--,!0;return!1};d.prototype.index=function(c){var b,g;b=this.documentKey(c);g=this._data.indexOf(b);-1===g&&(g=this.qs(c,this._data,b,this._sortFunc));return g};d.prototype.documentKey=function(c){var b="",g=this._keyArr,a=g.length,k,e;for(k=
0;k<a;k++)e=g[k],b&&(b+=".:."),b+=c[e.key];return b+=".:."+c[this._primaryKey]};d.prototype.count=function(){return this._count};d.prototype.sortAsc=function(c,b){return"string"===typeof c&&"string"===typeof b?c.localeCompare(b):c>b?1:c<b?-1:0};d.prototype.sortDesc=function(c,b){return"string"===typeof c&&"string"===typeof b?b.localeCompare(c):c>b?-1:c<b?1:0};h.finishModule("ActiveBucket");l.exports=d},{"./Path":19,"./Shared":22}],3:[function(d,l,h){var c,b,g,a,k;h=d("./Shared");var e=function(f){this.init.apply(this,
arguments)};e.prototype.init=function(f){this._primaryKey="_id";this._primaryIndex=new b("primary");this._primaryCrc=new b("primaryCrc");this._crcLookup=new b("crcLookup");this._name=f;this._data=[];this._groups=[];this._metrics=new c;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");c=d("./Metrics");b=d("./KeyValueStore");g=d("./Path");a=d("./Index");k=d("./Crc");d=h.modules.Core;e.prototype.crc=k;h.synthesize(e.prototype,"name");e.prototype.data=function(){return this._data};e.prototype.drop=function(){if(this._db&&this._db._collection&&this._name){this.debug()&&console.log("Dropping collection "+this._name);this.emit("drop");delete this._db._collection[this._name];
var f=[],a;for(a=0;a<this._groups.length;a++)f.push(this._groups[a]);for(a=0;a<f.length;a++)this._groups[a].removeCollection(this);return!0}return!1};e.prototype.primaryKey=function(f){return void 0!==f?(this._primaryKey!==f&&(this._primaryKey=f,this._primaryIndex.primaryKey(f),this.rebuildPrimaryKeyIndex()),this):this._primaryKey};e.prototype._onInsert=function(f,a){this.emit("insert",f,a)};e.prototype._onUpdate=function(f){this.emit("update",f)};e.prototype._onRemove=function(f){this.emit("remove",
f)};h.synthesize(e.prototype,"db");e.prototype.setData=function(f,a,b){if(f){var e=this._metrics.create("setData");e.start();a=this.options(a);this.preSetData(f,a,b);a.$decouple&&(f=this.decouple(f));f instanceof Array||(f=[f]);e.time("transformIn");f=this.transformIn(f);e.time("transformIn");var c=[].concat(this._data);this._dataReplace(f);e.time("Rebuild Primary Key Index");this.rebuildPrimaryKeyIndex(a);e.time("Rebuild Primary Key Index");e.time("Resolve chains");this.chainSend("setData",f,{oldData:c});
e.time("Resolve chains");e.stop();this.emit("setData",this._data,c)}b&&b(!1);return this};e.prototype.rebuildPrimaryKeyIndex=function(f){var a=f&&void 0!==f.$ensureKeys?f.$ensureKeys:!0;f=f&&void 0!==f.$violationCheck?f.$violationCheck:!0;var b,e,c,k=this._primaryIndex,g=this._primaryCrc,d=this._crcLookup,n=this._primaryKey,h;k.truncate();g.truncate();d.truncate();b=this._data;for(e=b.length;e--;){c=b[e];a&&this.ensurePrimaryKey(c);if(f){if(!k.uniqueSet(c[n],c))throw"Call to setData failed because your data violates the primary key unique constraint. One or more documents are using the same primary key: "+
c[this._primaryKey];}else k.set(c[n],c);h=JSON.stringify(c);g.set(c[n],h);d.set(h,c)}};e.prototype.ensurePrimaryKey=function(f){void 0===f[this._primaryKey]&&(f[this._primaryKey]=this.objectId())};e.prototype.truncate=function(){this.emit("truncate",this._data);this._data.length=0;this.deferEmit("change",{type:"truncate"});return this};e.prototype.upsert=function(f,a){if(f){var b=this._deferQueue.upsert,e=this._deferThreshold.upsert,c={},k;if(f instanceof Array){if(f.length>e)return this._deferQueue.upsert=
b.concat(f),this.processQueue("upsert",a),{};c=[];for(b=0;b<f.length;b++)c.push(this.upsert(f[b]));a&&a();return c}f[this._primaryKey]?(k={},k[this._primaryKey]=f[this._primaryKey],this._primaryIndex.lookup(k)[0]?c.op="update":c.op="insert"):c.op="insert";switch(c.op){case "insert":c.result=this.insert(f);break;case "update":c.result=this.update(k,f)}return c}a&&a();return{}};e.prototype.update=function(f,a,b){a=this.decouple(a);a=this.transformIn(a);this.debug()&&console.log('Updating some collection data for collection "'+
this.name()+'"');var c=this,e=this._metrics.create("update"),k=this._primaryKey,g,d,n=function(e){if(a&&void 0!==a[k]&&a[k]!=e[k]){c._removeIndex(e);var g=c.updateObject(e,a,f,b,"");if(c._insertIndex(e))return g;throw"Primary key violation in update! Key violated: "+e[k];}return c.updateObject(e,a,f,b,"")};e.start();e.time("Retrieve documents to update");g=this.find(f,{$decouple:!1});e.time("Retrieve documents to update");g.length&&(e.time("Update documents"),d=g.filter(n),e.time("Update documents"),
d.length&&(e.time("Resolve chains"),this.chainSend("update",{query:f,update:a,dataSet:g},b),e.time("Resolve chains"),this._onUpdate(d),this.deferEmit("change",{type:"update",data:d})));e.stop();return d||[]};e.prototype.updateById=function(f,a){var b={};b[this._primaryKey]=f;return this.update(b,a)};e.prototype.updateObject=function(f,a,b,e,c,k){a=this.decouple(a);c=c||"";"."===c.substr(0,1)&&(c=c.substr(1,c.length-1));var d=!1,h=!1,n,q,p,m;for(m in a)if(a.hasOwnProperty(m)){n=!1;if("$"===m.substr(0,
1))switch(m){case "$index":n=!0;break;default:n=!0,h=this.updateObject(f,a[m],b,e,c,m),d=d||h}if(this._isPositionalKey(m)&&(n=!0,m=m.substr(0,m.length-2),h=new g(c+"."+m),f[m]&&f[m]instanceof Array&&f[m].length)){q=[];for(p=0;p<f[m].length;p++)this._match(f[m][p],h.value(b)[0])&&q.push(p);for(p=0;p<q.length;p++)h=this.updateObject(f[m][q[p]],a[m+".$"],b,e,c+"."+m,k),d=d||h}if(!n)if(k||"object"!==typeof a[m])switch(k){case "$inc":this._updateIncrement(f,m,a[m]);d=!0;break;case "$push":void 0===f[m]&&
(f[m]=[]);if(f[m]instanceof Array){if(void 0!==a[m].$position&&a[m].$each instanceof Array)for(h=a[m].$position,n=a[m].$each.length,p=0;p<n;p++)this._updateSplicePush(f[m],h+p,a[m].$each[p]);else if(a[m].$each instanceof Array)for(n=a[m].$each.length,p=0;p<n;p++)this._updatePush(f[m],a[m].$each[p]);else this._updatePush(f[m],a[m]);d=!0}else throw"Cannot push to a key that is not an array! ("+m+")";break;case "$pull":if(f[m]instanceof Array){q=[];for(p=0;p<f[m].length;p++)this._match(f[m][p],a[m])&&
q.push(p);for(n=q.length;n--;)this._updatePull(f[m],q[n]),d=!0}break;case "$pullAll":if(f[m]instanceof Array)if(a[m]instanceof Array){if(q=f[m],n=q.length,0<n)for(;n--;){for(h=0;h<a[m].length;h++)q[n]===a[m][h]&&(this._updatePull(f[m],n),n--,d=!0);if(0>n)break}}else throw"Cannot pullAll without being given an array of values to pull! ("+m+")";break;case "$addToSet":void 0===f[m]&&(f[m]=[]);if(f[m]instanceof Array){p=f[m];var l;q=p.length;var z;n=!0;l=e&&e.$addToSet;var x;l&&l.key?(h=!1,x=new g(l.key),
z=x.value(a[m])[0]):(z=JSON.stringify(a[m]),h=!0);for(l=0;l<q;l++)if(h){if(JSON.stringify(p[l])===z){n=!1;break}}else if(z===x.value(p[l])[0]){n=!1;break}n&&(this._updatePush(f[m],a[m]),d=!0)}else throw"Cannot addToSet on a key that is not an array! (undefined)!";break;case "$splicePush":void 0===f[m]&&(f[m]=[]);if(f[m]instanceof Array)if(h=a.$index,void 0!==h)delete a.$index,h>f[m].length&&(h=f[m].length),this._updateSplicePush(f[m],h,a[m]),d=!0;else throw"Cannot splicePush without a $index integer value!";
else throw"Cannot splicePush with a key that is not an array! ("+m+")";break;case "$move":if(f[m]instanceof Array)for(p=0;p<f[m].length;p++){if(this._match(f[m][p],a[m])){d=a.$index;if(void 0!==d)delete a.$index,this._updateSpliceMove(f[m],p,d),d=!0;else throw"Cannot move without a $index integer value!";break}}else throw"Cannot move on a key that is not an array! ("+m+")";break;case "$mul":this._updateMultiply(f,m,a[m]);d=!0;break;case "$rename":this._updateRename(f,m,a[m]);d=!0;break;case "$unset":this._updateUnset(f,
m);d=!0;break;case "$pop":if(f[m]instanceof Array)this._updatePop(f[m],a[m])&&(d=!0);else throw"Cannot pop from a key that is not an array! ("+m+")";break;default:f[m]!==a[m]&&(this._updateProperty(f,m,a[m]),d=!0)}else if(null!==f[m]&&"object"===typeof f[m])if(p=f[m]instanceof Array,q=a[m]instanceof Array,p||q)if(!q&&p)for(p=0;p<f[m].length;p++)h=this.updateObject(f[m][p],a[m],b,e,c+"."+m,k),d=d||h;else f[m]!==a[m]&&(this._updateProperty(f,m,a[m]),d=!0);else h=this.updateObject(f[m],a[m],b,e,c+"."+
m,k),d=d||h;else f[m]!==a[m]&&(this._updateProperty(f,m,a[m]),d=!0)}return d};e.prototype._isPositionalKey=function(f){return".$"===f.substr(f.length-2,2)};e.prototype._updateProperty=function(f,a,b){f[a]=b;this.debug()&&console.log('ForerunnerDB.Collection: Setting non-data-bound document property "'+a+'" for collection "'+this.name()+'"')};e.prototype._updateIncrement=function(f,a,b){f[a]+=b};e.prototype._updateSpliceMove=function(f,a,b){f.splice(b,0,f.splice(a,1)[0]);this.debug()&&console.log('ForerunnerDB.Collection: Moving non-data-bound document array index from "'+
a+'" to "'+b+'" for collection "'+this.name()+'"')};e.prototype._updateSplicePush=function(f,a,b){f.length>a?f.splice(a,0,b):f.push(b)};e.prototype._updatePush=function(f,a){f.push(a)};e.prototype._updatePull=function(f,a){f.splice(a,1)};e.prototype._updateMultiply=function(f,a,b){f[a]*=b};e.prototype._updateRename=function(f,a,b){f[b]=f[a];delete f[a]};e.prototype._updateUnset=function(f,a){delete f[a]};e.prototype._updatePop=function(f,a){var b=!1;0<f.length&&(1===a?(f.pop(),b=!0):-1===a&&(f.shift(),
b=!0));return b};e.prototype.remove=function(f,a,b){var e,c;if(f instanceof Array){c=[];for(b=0;b<f.length;b++)c.push(this.remove(f[b],{noEmit:!0}));(!a||a&&!a.noEmit)&&this._onRemove(c);return c}b=this.find(f,{$decouple:!1});if(b.length){for(c=0;c<b.length;c++)e=b[c],this._removeIndex(e),e=this._data.indexOf(e),this._dataRemoveIndex(e);this.chainSend("remove",{query:f,dataSet:b},a);(!a||a&&!a.noEmit)&&this._onRemove(b);this.deferEmit("change",{type:"remove",data:b})}return b};e.prototype.removeById=
function(f){var a={};a[this._primaryKey]=f;return this.remove(a)};e.prototype.deferEmit=function(){var f=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(){f.debug()&&console.log("ForerunnerDB.Collection: Emitting "+a[0]);f.emit.apply(f,a)},100))};e.prototype.processQueue=function(f,a){var b=this._deferQueue[f],e=this._deferThreshold[f],
c=this._deferTime[f];if(b.length){var k=this;b.length&&(b=b.length>e?b.splice(0,e):b.splice(0,b.length),this[f](b));setTimeout(function(){k.processQueue(f,a)},c)}else a&&a()};e.prototype.insert=function(f,a,b){"function"===typeof a?(b=a,a=this._data.length):void 0===a&&(a=this._data.length);f=this.transformIn(f);return this._insertHandle(f,a,b)};e.prototype._insertHandle=function(f,a,b){var e=this._deferQueue.insert,c=this._deferThreshold.insert,k=[],g=[];if(f instanceof Array){if(f.length>c){this._deferQueue.insert=
e.concat(f);this.processQueue("insert",b);return}for(c=0;c<f.length;c++)e=this._insert(f[c],a+c),!0===e?k.push(f[c]):g.push({doc:f[c],reason:e})}else e=this._insert(f,a),!0===e?k.push(f):g.push({doc:f,reason:e});this.chainSend("insert",f,{index:a});this._onInsert(k,g);b&&b();this.deferEmit("change",{type:"insert",data:k});return{inserted:k,failed:g}};e.prototype._insert=function(f,a){if(f){var b;this.ensurePrimaryKey(f);if(b=this.insertIndexViolation(f))return"Index violation in index: "+b;this._insertIndex(f);
a>this._data.length&&(a=this._data.length);this._dataInsertIndex(a,f);return!0}return"No document passed to insert"};e.prototype._dataInsertIndex=function(f,a){this._data.splice(f,0,a)};e.prototype._dataRemoveIndex=function(f){this._data.splice(f,1)};e.prototype._dataReplace=function(f){for(;this._data.length;)this._data.pop();this._data=this._data.concat(f)};e.prototype._insertIndex=function(f){var a=this._indexByName,b,e,c=JSON.stringify(f);e=this._primaryIndex.uniqueSet(f[this._primaryKey],f);
this._primaryCrc.uniqueSet(f[this._primaryKey],c);this._crcLookup.uniqueSet(c,f);for(b in a)a.hasOwnProperty(b)&&a[b].insert(f);return e};e.prototype._removeIndex=function(f){var a=this._indexByName,b,e=JSON.stringify(f);this._primaryIndex.unSet(f[this._primaryKey]);this._primaryCrc.unSet(f[this._primaryKey]);this._crcLookup.unSet(e);for(b in a)a.hasOwnProperty(b)&&a[b].remove(f)};e.prototype.subset=function(f,a){var b=this.find(f,a);return(new e)._subsetOf(this).primaryKey(this._primaryKey).setData(b)};
e.prototype.subsetOf=function(){return this.__subsetOf};e.prototype._subsetOf=function(f){this.__subsetOf=f;return this};e.prototype.distinct=function(f,a,b){a=this.find(a,b);f=new g(f);b={};var e=[],c,k;for(k=0;k<a.length;k++)(c=f.value(a[k])[0])&&!b[c]&&(b[c]=!0,e.push(c));return e};e.prototype.findById=function(f,a){var b={};b[this._primaryKey]=f;return this.find(b,a)[0]};e.prototype.peek=function(f,a){var b=this._data,c=b.length,k,g,d=new e;if("string"===typeof f){for(k=0;k<c;k++)g=JSON.stringify(b[k]),
-1<g.indexOf(f)&&d.insert(b[k]);return d.find({},a)}return this.find(f,a)};e.prototype.explain=function(f,a){return this.find(f,a).__fdbOp._data};e.prototype.options=function(f){f=f||{};f.$decouple=void 0!==f.$decouple?f.$decouple:!0;f.$explain=void 0!==f.$explain?f.$explain:!1;return f};e.prototype.find=function(f,a){f=f||{};a=this.options(a);var b=this._metrics.create("find"),e=this,c,k=!0,d,h,n,q,p,m,l,z,x,A=[];h=function(a){return e._match(a,f,"and")};b.start();if(f){b.time("analyseQuery");c=
this._analyseQuery(f,a,b);b.time("analyseQuery");b.data("analysis",c);if(c.hasJoin&&c.queriesJoin){b.time("joinReferences");for(n=0;n<c.joinsOn.length;n++)p=c.joinsOn[n],q=new g(c.joinQueries[p]),q=q.value(f)[0],this._db.collection(c.joinsOn[n]).subset(q);b.time("joinReferences")}c.indexMatch.length&&(!a||a&&!a.$skipIndex)?(b.data("index.potential",c.indexMatch),b.data("index.used",c.indexMatch[0].index),b.time("indexLookup"),d=c.indexMatch[0].lookup,b.time("indexLookup"),c.indexMatch[0].keyData.totalKeyCount===
c.indexMatch[0].keyData.matchedKeyCount&&(k=!1)):b.flag("usedIndex",!1);k&&(d&&d.length?(c=d.length,b.time("tableScan: "+c),d=d.filter(h)):(c=this._data.length,b.time("tableScan: "+c),d=this._data.filter(h)),a.$orderBy&&(b.time("sort"),d=this.sort(a.$orderBy,d),b.time("sort")),b.time("tableScan: "+c));a.limit&&d&&d.length>a.limit&&(d.length=a.limit,b.data("limit",a.limit));a.$decouple&&(b.time("decouple"),d=this.decouple(d),b.time("decouple"),b.data("flag.decouple",!0));if(a.join){for(h=0;h<a.join.length;h++)for(p in a.join[h])if(a.join[h].hasOwnProperty(p))for(z=
p,c=this._db.collection(p),k=a.join[h][p],x=0;x<d.length;x++){l={};q=n=!1;for(m in k)if(k.hasOwnProperty(m))if("$"===m.substr(0,1))switch(m){case "$as":z=k[m];break;case "$multi":n=k[m];break;case "$require":q=k[m];break;default:m.substr(0,3)}else l[m]=(new g(k[m])).value(d[x])[0];l=c.find(l);!q||q&&l[0]?d[x][z]=!1===n?l[0]:l:A.push(d[x])}b.data("flag.join",!0)}if(A.length){b.time("removalQueue");for(m=0;m<A.length;m++)p=d.indexOf(A[m]),-1<p&&d.splice(p,1);b.time("removalQueue")}if(a.transform){b.time("transform");
for(m=0;m<d.length;m++)d.splice(m,1,a.transform(d[m]));b.time("transform");b.data("flag.transform",!0)}this._transformEnabled&&this._transformOut&&(b.time("transformOut"),d=this.transformOut(d),b.time("transformOut"));b.data("results",d.length);b.stop()}else b.stop(),d=[];d.__fdbOp=b;return d};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 b=[],c;for(c=0;c<a.length;c++)b[c]=this._transformIn(a[c]);return b}return this._transformIn(a)}return a};e.prototype.transformOut=function(a){if(this._transformEnabled&&
this._transformOut){if(a instanceof Array){var b=[],c;for(c=0;c<a.length;c++)b[c]=this._transformOut(a[c]);return b}return this._transformOut(a)}return a};e.prototype.sort=function(a,b){b=b||[];var c=[],e,k;for(e in a)a.hasOwnProperty(e)&&(k={},k[e]=a[e],k.___fdbKey=e,c.push(k));return 2>c.length?this._sort(a,b):this._bucketSort(c,b)};e.prototype._bucketSort=function(a,b){var c=a.shift(),e,k,g=[];if(0<a.length){b=this._sort(c,b);e=this.bucket(c.___fdbKey,b);for(k in e)e.hasOwnProperty(k)&&(c=[].concat(a),
g=g.concat(this._bucketSort(c,e[k])));return g}return this._sort(c,b)};e.prototype._sort=function(a,b){var c,e=new g;c=e.parse(a,!0)[0];e.path(c.path);if(1===c.value)c=function(a,f){var b=e.value(a)[0],c=e.value(f)[0];return"string"===typeof b&&"string"===typeof c?b.localeCompare(c):b>c?1:b<c?-1:0};else if(-1===c.value)c=function(a,f){var b=e.value(a)[0],c=e.value(f)[0];return"string"===typeof b&&"string"===typeof c?c.localeCompare(b):b>c?-1:b<c?1:0};else throw this._name+": $orderBy clause has invalid direction: "+
c.value+", accepted values are 1 or -1 for ascending or descending!";return b.sort(c)};e.prototype.bucket=function(a,b){var c,e={};for(c=0;c<b.length;c++)e[b[c][a]]=e[b[c][a]]||[],e[b[c][a]].push(b[c]);return e};e.prototype._analyseQuery=function(a,b,c){var e={queriesOn:[this._name],indexMatch:[],hasJoin:!1,queriesJoin:!1,joinQueries:{},query:a,options:b},k,d=[],h=[],l,n,q,p,m;c.time("checkIndexes");void 0!==a[this._primaryKey]&&(c.time("checkIndexMatch: Primary Key"),l=new g,e.indexMatch.push({lookup:this._primaryIndex.lookup(a,
b),keyData:{matchedKeys:[this._primaryKey],matchedKeyCount:1,totalKeyCount:l.countKeys(a)},index:this._primaryIndex}),c.time("checkIndexMatch: Primary Key"));for(m in this._indexById)if(this._indexById.hasOwnProperty(m)&&(n=this._indexById[m],q=n.name(),c.time("checkIndexMatch: "+q),l=n.match(a,b),p=n.lookup(a,b),0<l.matchedKeyCount&&e.indexMatch.push({lookup:p,keyData:l,index:n}),c.time("checkIndexMatch: "+q),l.totalKeyCount===l.matchedKeyCount))break;c.time("checkIndexes");1<e.indexMatch.length&&
(c.time("findOptimalIndex"),e.indexMatch.sort(function(a,f){return a.keyData.totalKeyCount===a.keyData.matchedKeyCount?-1:f.keyData.totalKeyCount===f.keyData.matchedKeyCount?1:a.keyData.matchedKeyCount===f.keyData.matchedKeyCount?a.lookup.length-f.lookup.length:f.keyData.matchedKeyCount-a.keyData.matchedKeyCount}),c.time("findOptimalIndex"));if(b.join){e.hasJoin=!0;for(c=0;c<b.join.length;c++)for(k in b.join[c])b.join[c].hasOwnProperty(k)&&(d.push(k),"$as"in b.join[c][k]?h.push(b.join[c][k].$as):
h.push(k));for(k=0;k<h.length;k++)if(b=this._queryReferencesCollection(a,h[k],""))e.joinQueries[d[k]]=b,e.queriesJoin=!0;e.joinsOn=d;e.queriesOn=e.queriesOn.concat(d)}return e};e.prototype._queryReferencesCollection=function(a,b,c){for(var e in a)if(a.hasOwnProperty(e)){if(e===b)return c&&(c+="."),c+e;if("object"===typeof a[e])return c&&(c+="."),c+=e,this._queryReferencesCollection(a[e],b,c)}return!1};e.prototype._match=function(a,b,c){var e,k;e=typeof a;k=typeof b;var g=!0,d;if(!("string"!==e&&"number"!==
e||"string"!==k&&"number"!==k))a!==b&&(g=!1);else for(d in b)if(b.hasOwnProperty(d)){e=!1;if("$"===d.substr(0,1))switch(d){case "$gt":if(a>b[d]){if("or"===c)return!0}else g=!1;e=!0;break;case "$gte":if(a>=b[d]){if("or"===c)return!0}else g=!1;e=!0;break;case "$lt":if(a<b[d]){if("or"===c)return!0}else g=!1;e=!0;break;case "$lte":if(a<=b[d]){if("or"===c)return!0}else g=!1;e=!0;break;case "$exists":if(void 0===a!==b[d]){if("or"===c)return!0}else g=!1;e=!0;break;case "$or":e=!0;for(k=0;k<b[d].length;k++){if(this._match(a,
b[d][k],"and"))return!0;g=!1}break;case "$and":e=!0;for(k=0;k<b[d].length;k++)if(!this._match(a,b[d][k],"and"))return!1;break;case "$in":if(b[d]instanceof Array){e=b[d];k=e.length;var h,n=!1;for(h=0;h<k;h++)if(e[h]===a){n=!0;break}if(n){if("or"===c)return!0}else g=!1}else throw"Cannot use a $nin operator on a non-array key: "+d;e=!0;break;case "$nin":if(b[d]instanceof Array){e=b[d];k=e.length;n=!0;for(h=0;h<k;h++)if(e[h]===a){n=!1;break}if(n){if("or"===c)return!0}else g=!1}else throw"Cannot use a $nin operator on a non-array key: "+
d;e=!0;break;case "$ne":if(a!=b[d]){if("or"===c)return!0}else g=!1;e=!0}if(!e&&b[d]instanceof RegExp)if(e=!0,"object"===typeof a&&void 0!==a[d]&&b[d].test(a[d])){if("or"===c)return!0}else g=!1;if(!e)if("object"===typeof b[d])if(void 0!==a[d]){if(a[d]instanceof Array&&!(b[d]instanceof Array))for(e=!1,k=0;k<a[d].length&&!(e=this._match(a[d][k],b[d],void 0));k++);else if(!(a[d]instanceof Array)&&b[d]instanceof Array)for(e=!1,k=0;k<b[d].length&&!(e=this._match(a[d],b[d][k],void 0));k++);else e="object"===
typeof a?this._match(a[d],b[d],void 0):this._match(void 0,b[d],void 0);if(e){if("or"===c)return!0}else g=!1}else if(b[d]&&void 0!==b[d].$exists)if(e=this._match(void 0,b[d],void 0)){if("or"===c)return!0}else g=!1;else g=!1;else if(a&&a[d]===b[d]){if("or"===c)return!0}else if(a&&a[d]&&a[d]instanceof Array&&b[d]&&"object"!==typeof b[d]){e=!1;for(k=0;k<a[d].length&&!(e=this._match(a[d][k],b[d],void 0));k++);if(e){if("or"===c)return!0}else g=!1}else g=!1;if("and"===c&&!g)return!1}return g};e.prototype.count=
function(a,b){return a?this.find(a,b).length:this._data.length};e.prototype.findSub=function(a,b,c,e){var k=new g(b);a=this.find(a);var d=a.length,h,l,n=this._db.collection("__FDB_temp_"+this.objectId()),q={parents:d,subDocTotal:0,subDocs:[],pathFound:!1,err:""};for(h=0;h<d;h++)if(l=k.value(a[h])[0]){n.setData(l);l=n.find(c,e);if(e.returnFirst&&l.length)return l[0];q.subDocs.push(l);q.subDocTotal+=l.length;q.pathFound=!0}n.drop();if(e.noStats)return q.subDocs;q.pathFound||(q.err="No objects found in the parent documents with a matching path of: "+
b);return q};e.prototype.insertIndexViolation=function(a){var b,c=this._indexByName,e,k;if(this._primaryIndex.get(a[this._primaryKey]))b=this._primaryIndex;else for(e in c)if(c.hasOwnProperty(e)&&(k=c[e],k.unique()&&k.violation(a))){b=k;break}return b?b.name():!1};e.prototype.ensureIndex=function(b,c){this._indexByName=this._indexByName||{};this._indexById=this._indexById||{};var e=new a(b,c,this),k={start:(new Date).getTime()};if(this._indexByName[e.name()])return{err:"Index with that name already exists"};
if(this._indexById[e.id()])return{err:"Index with those keys already exists"};e.rebuild();this._indexByName[e.name()]=e;this._indexById[e.id()]=e;k.end=(new Date).getTime();k.total=k.end-k.start;this._lastOp={type:"ensureIndex",stats:{time:k}};return{index:e,id:e.id(),name:e.name(),state:e.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 b={insert:[],update:[],remove:[]},
c=this.primaryKey(),e,k,g,d;if(c===a.primaryKey()){for(e=a._data;e&&!(e instanceof Array);)a=e,e=a._data;d=e.length;for(k=0;k<d;k++)g=e[k],this._primaryIndex.get(g[c])?this._primaryCrc.get(g[c])!==a._primaryCrc.get(g[c])&&b.update.push(g):b.insert.push(g);e=this._data;d=e.length;for(k=0;k<d;k++)g=e[k],a._primaryIndex.get(g[c])||b.remove.push(g)}else throw"Collection diffing requires that both collections have the same primary key!";return b};d.prototype.collection=function(a,b){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!==b&&this._collection[a].primaryKey(b),this._collection[a];throw"Cannot get collection with undefined name!";};d.prototype.collectionExists=function(a){return Boolean(this._collection[a])};d.prototype.collections=function(a){var b=[],c;a&&(a instanceof RegExp||(a=RegExp(a)));for(c in this._collection)this._collection.hasOwnProperty(c)&&(a?a.exec(c)&&b.push({name:c,count:this._collection[c].count()}):
b.push({name:c,count:this._collection[c].count()}));return b};h.finishModule("Collection");l.exports=e},{"./Crc":6,"./Index":9,"./KeyValueStore":10,"./Metrics":11,"./Path":19,"./Shared":22}],4:[function(d,l,h){var c,b;h=d("./Shared");var g=function(){this.init.apply(this,arguments)};g.prototype.init=function(a){this._name=a;this._data=new b("__FDB__cg_data_"+this._name);this._collections=[];this._views=[]};h.addModule("CollectionGroup",g);h.mixin(g.prototype,"Mixin.Common");h.mixin(g.prototype,"Mixin.ChainReactor");
b=d("./Collection");d=h.modules.Core;c=h.modules.Core.prototype.init;g.prototype.on=function(){this._data.on.apply(this._data,arguments)};g.prototype.off=function(){this._data.off.apply(this._data,arguments)};g.prototype.emit=function(){this._data.emit.apply(this._data,arguments)};g.prototype.primaryKey=function(a){return void 0!==a?(this._primaryKey=a,this):this._primaryKey};h.synthesize(g.prototype,"db");g.prototype.addCollection=function(a){if(a&&-1===this._collections.indexOf(a)){if(this._collections.length){if(this._primaryKey!==
a.primaryKey())throw"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};g.prototype.removeCollection=function(a){if(a){var b=this._collections.indexOf(a);-1!==b&&(a.unChain(this),this._collections.splice(b,1),b=a._groups.indexOf(this),-1!==b&&a._groups.splice(b,1));0===this._collections.length&&delete this._primaryKey}return this};g.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)}};g.prototype.insert=function(){this._collectionsRun("insert",arguments)};g.prototype.update=function(){this._collectionsRun("update",arguments)};g.prototype.updateById=
function(){this._collectionsRun("updateById",arguments)};g.prototype.remove=function(){this._collectionsRun("remove",arguments)};g.prototype._collectionsRun=function(a,b){for(var c=0;c<this._collections.length;c++)this._collections[c][a].apply(this._collections[c],b)};g.prototype.find=function(a,b){return this._data.find(a,b)};g.prototype.removeById=function(a){for(var b=0;b<this._collections.length;b++)this._collections[b].removeById(a)};g.prototype.subset=function(a,c){var e=this.find(a,c);return(new b)._subsetOf(this).primaryKey(this._primaryKey).setData(e)};
g.prototype.drop=function(){var a,b=[].concat(this._collections),c=[].concat(this._views);this._debug&&console.log("Dropping collection group "+this._name);for(a=0;a<b.length;a++)this.removeCollection(b[a]);for(a=0;a<c.length;a++)this._removeView(c[a]);this.emit("drop");return!0};d.prototype.init=function(){this._collectionGroup={};c.apply(this,arguments)};d.prototype.collectionGroup=function(a){return a?(this._collectionGroup[a]=this._collectionGroup[a]||(new g(a)).db(this),this._collectionGroup[a]):
this._collectionGroup};l.exports=g},{"./Collection":3,"./Shared":22}],5:[function(d,l,h){var c,b,g;c=d("./Shared");g=d("./Overload");h=function(){this.init.apply(this,arguments)};h.prototype.init=function(){this._collection={};this._debug={};this._version="1.2.13"};h.prototype.moduleLoaded=g({string:function(a){if(void 0!==a){a=a.replace(/ /g,"");a=a.split(",");var b;for(b=0;b<a.length;b++)if(!c.modules[a[b]])return!1;return!0}return!1},"string, function":function(a,b){if(void 0!==a){a=a.replace(/ /g,
"");var e=a.split(","),f;for(f=0;f<e.length;f++)if(!c.modules[e[f]])return!1;b()}},"string, function, function":function(a,b,e){if(void 0!==a){a=a.replace(/ /g,"");a=a.split(",");var f;for(f=0;f<a.length;f++)if(!c.modules[a[f]])return e(),!1;b()}}});h.moduleLoaded=h.prototype.moduleLoaded;h.shared=c;h.prototype.shared=c;c.addModule("Core",h);c.mixin(h.prototype,"Mixin.Common");c.mixin(h.prototype,"Mixin.ChainReactor");b=d("./Collection.js");d("./Metrics.js");d=d("./Crc.js");h.prototype._isServer=
!1;h.prototype.isClient=function(){return!this._isServer};h.prototype.isServer=function(){return this._isServer};h.prototype.crc=d;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,b){this._listeners=this._listeners||{};this._listeners[a]=this._listeners[a]||[];this._listeners[a].push(b);return this};h.prototype.off=function(a,b){if(a in this._listeners){var c=
this._listeners[a],f=c.indexOf(b);-1<f&&c.splice(f,1)}return this};h.prototype.emit=function(a,b){this._listeners=this._listeners||{};if(a in this._listeners){var c=this._listeners[a],f=c.length,g;for(g=0;g<f;g++)c[g].apply(this,Array.prototype.slice.call(arguments,1))}return this};h.prototype.peek=function(a){var b,c,f=[],g=typeof a;for(b in this._collection)this._collection.hasOwnProperty(b)&&(c=this._collection[b],f="string"===g?f.concat(c.peek(a)):f.concat(c.find(a)));return f};h.prototype.peekCat=
function(a){var b,c,f={},g,d=typeof a;for(b in this._collection)this._collection.hasOwnProperty(b)&&(c=this._collection[b],(g="string"===d?c.peek(a):c.find(a))&&g.length&&(f[c.name()]=g));return f};l.exports=h},{"./Collection.js":3,"./Crc.js":6,"./Metrics.js":11,"./Overload":17,"./Shared":22}],6:[function(d,l,h){var c=function(){var b=[],c,a,k;for(a=0;256>a;a++){c=a;for(k=0;8>k;k++)c=c&1?3988292384^c>>>1:c>>>1;b[a]=c}return b}();l.exports=function(b){var g=-1,a;for(a=0;a<b.length;a++)g=g>>>8^c[(g^
b.charCodeAt(a))&255];return(g^-1)>>>0}},{}],7:[function(d,l,h){var c,b;h=d("./Shared");var g=function(){this.init.apply(this,arguments)};g.prototype.init=function(a){this._name=a;this._data={}};h.addModule("Document",g);h.mixin(g.prototype,"Mixin.Common");h.mixin(g.prototype,"Mixin.Events");h.mixin(g.prototype,"Mixin.ChainReactor");d=d("./Collection");c=h.modules.Core;b=h.modules.Core.prototype.init;h.synthesize(g.prototype,"db");h.synthesize(g.prototype,"name");g.prototype.setData=function(a){var b,
c;if(a)if(a=this.decouple(a),this._linked){c={};for(b in this._data)"jQuery"!==b.substr(0,6)&&this._data.hasOwnProperty(b)&&void 0===a[b]&&(c[b]=1);a.$unset=c;this.updateObject(this._data,a,{})}else this._data=a;return this};g.prototype.update=function(a,b,c){this.updateObject(this._data,b,a,c)};g.prototype.updateObject=d.prototype.updateObject;g.prototype._isPositionalKey=function(a){return".$"===a.substr(a.length-2,2)};g.prototype._updateProperty=function(a,b,c){this._linked?(jQuery.observable(a).setProperty(b,
c),this.debug()&&console.log('ForerunnerDB.Document: Setting data-bound document property "'+b+'" for collection "'+this.name()+'"')):(a[b]=c,this.debug()&&console.log('ForerunnerDB.Document: Setting non-data-bound document property "'+b+'" for collection "'+this.name()+'"'))};g.prototype._updateIncrement=function(a,b,c){this._linked?jQuery.observable(a).setProperty(b,a[b]+c):a[b]+=c};g.prototype._updateSpliceMove=function(a,b,c){this._linked?(jQuery.observable(a).move(b,c),this.debug()&&console.log('ForerunnerDB.Document: Moving data-bound document array index from "'+
b+'" to "'+c+'" for collection "'+this.name()+'"')):(a.splice(c,0,a.splice(b,1)[0]),this.debug()&&console.log('ForerunnerDB.Document: Moving non-data-bound document array index from "'+b+'" to "'+c+'" for collection "'+this.name()+'"'))};g.prototype._updateSplicePush=function(a,b,c){a.length>b?this._linked?jQuery.observable(a).insert(b,c):a.splice(b,0,c):this._linked?jQuery.observable(a).insert(c):a.push(c)};g.prototype._updatePush=function(a,b){this._linked?jQuery.observable(a).insert(b):a.push(b)};
g.prototype._updatePull=function(a,b){this._linked?jQuery.observable(a).remove(b):a.splice(b,1)};g.prototype._updateMultiply=function(a,b,c){this._linked?jQuery.observable(a).setProperty(b,a[b]*c):a[b]*=c};g.prototype._updateRename=function(a,b,c){var f=a[b];this._linked?(jQuery.observable(a).setProperty(c,f),jQuery.observable(a).removeProperty(b)):(a[c]=f,delete a[b])};g.prototype._updateUnset=function(a,b){this._linked?jQuery.observable(a).removeProperty(b):delete a[b]};g.prototype._updatePop=function(a,
b){var c,f=!1;0<a.length&&(this._linked?(1===b?c=a.length-1:-1===b&&(c=0),-1<c&&(jQuery.observable(arr).remove(c),f=!0)):1===b?(a.pop(),f=!0):-1===b&&(a.shift(),f=!0));return f};g.prototype.drop=function(){this._db&&this._name&&this._db&&this._db._document&&this._db._document[this._name]&&(delete this._db._document[this._name],this._data={})};c.prototype.init=function(){b.apply(this,arguments)};c.prototype.document=function(a){return a?(this._document=this._document||{},this._document[a]=this._document[a]||
(new g(a)).db(this),this._document[a]):this._document};h.finishModule("Document");l.exports=g},{"./Collection":3,"./Shared":22}],8:[function(d,l,h){var c,b;h=d("./Shared");b=d("./Overload");var g=function(a,b){this.init.apply(this,arguments)};g.prototype.init=function(a,b){this._options=b;this._selector=$(this._options.selector);if(!this._selector[0])throw"Chart target element does not exist via selector: "+this._options.selector;this._listeners={};this._collection=a;this._options.series=[];b.chartOptions=
b.chartOptions||{};b.chartOptions.credits=!1;var c,f;switch(this._options.type){case "pie":this._selector.highcharts(this._options.chartOptions);this._chart=this._selector.highcharts();c=this._collection.find();f={allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,format:"<b>{point.name}</b>: {y} ({point.percentage:.0f}%)",style:{color:Highcharts.theme&&Highcharts.theme.contrastTextColor||"black"}}};c=this.pieDataFromCollectionData(c,this._options.keyField,this._options.valField);$.extend(f,
this._options.seriesOptions);$.extend(f,{name:this._options.seriesName,data:c});this._chart.addSeries(f,!0,!0);break;case "line":case "area":case "column":case "bar":c=this.seriesDataFromCollectionData(this._options.seriesField,this._options.keyField,this._options.valField,this._options.orderBy);this._options.chartOptions.xAxis=c.xAxis;this._options.chartOptions.series=c.series;this._selector.highcharts(this._options.chartOptions);this._chart=this._selector.highcharts();break;default:throw"Chart type specified is not currently supported by ForerunnerDB: "+
this._options.type;}this._hookEvents()};h.addModule("Highchart",g);d=h.modules.Collection;c=d.prototype.init;g.prototype.pieDataFromCollectionData=function(a,b,c){var f=[],g;for(g=0;g<a.length;g++)f.push([a[g][b],a[g][c]]);return f};g.prototype.seriesDataFromCollectionData=function(a,b,c,f){var g=this._collection.distinct(a),d=[],h={categories:[]},l,r,u,v,n;for(v=0;v<g.length;v++){l=g[v];r={};r[a]=l;u=[];r=this._collection.find(r,{orderBy:f});for(n=0;n<r.length;n++)h.categories.push(r[n][b]),u.push(r[n][c]);
d.push({name:l,data:u})}return{xAxis:h,series:d}};g.prototype._hookEvents=function(){var a=this;a._collection.on("change",function(){a._changeListener.apply(a,arguments)});a._collection.on("drop",function(){a._dropListener.apply(a,arguments)})};g.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 b=this.seriesDataFromCollectionData(this._options.seriesField,this._options.keyField,this._options.valField,this._options.orderBy);this._chart.xAxis[0].setCategories(b.xAxis.categories);for(a=0;a<b.series.length;a++)this._chart.series[a]?this._chart.series[a].setData(b.series[a].data,!0,!0):this._chart.addSeries(b.series[a],!0,!0)}}};g.prototype._dropListener=function(){this._collection.off("change",this._changeListener);this._collection.off("drop",
this._dropListener)};g.prototype.drop=function(){this._chart.destroy();this._collection.off("change",this._changeListener);this._collection.off("drop",this._dropListener);delete this._collection._highcharts[this._options.selector];delete this._chart;delete this._options;delete this._collection;return this};d.prototype.init=function(){this._highcharts={};c.apply(this,arguments)};d.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 g(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,b,c,f,g){g=g||{};g.selector=a;g.keyField=b;g.valField=c;g.seriesName=f;this.pieChart(g)}});d.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 g(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,b,c,f,g){g=g||{};g.seriesField=b;g.selector=a;g.keyField=c;g.valField=f;this.lineChart(g)}});d.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 g(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,
b,c,f,g){g=g||{};g.seriesField=b;g.selector=a;g.keyField=c;g.valField=f;this.areaChart(g)}});d.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 g(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,b,c,f,g){g=g||{};g.seriesField=b;g.selector=a;g.keyField=c;g.valField=f;
this.columnChart(g)}});d.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 g(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,b,c,f,g){g=g||{};g.seriesField=b;g.selector=a;g.keyField=c;g.valField=f;this.barChart(g)}});d.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 g(this,a));return this._highcharts[a.selector]},"*, string, string, string, ...":function(a,b,c,f,g){g=g||{};g.seriesField=b;g.selector=a;g.keyField=c;g.valField=f;this.stackedBarChart(g)}});
d.prototype.dropChart=function(a){this._highcharts[a]&&this._highcharts[a].drop()};h.finishModule("Highchart");l.exports=g},{"./Overload":17,"./Shared":22}],9:[function(d,l,h){h=d("./Shared");var c=d("./Path");d=function(){this.init.apply(this,arguments)};d.prototype.init=function(b,c,a){this._crossRef={};this._size=0;this._id=this._itemKeyHash(b,b);this.data({});this.unique(c&&c.unique?c.unique:!1);void 0!==b&&this.keys(b);void 0!==a&&this.collection(a);this.name(c&&c.name?c.name:this._id)};h.addModule("Index",
d);h.mixin(d.prototype,"Mixin.ChainReactor");d.prototype.id=function(){return this._id};d.prototype.state=function(){return this._state};d.prototype.size=function(){return this._size};d.prototype.data=function(b){return void 0!==b?(this._data=b,this):this._data};h.synthesize(d.prototype,"name");d.prototype.collection=function(b){return void 0!==b?(this._collection=b,this):this._collection};d.prototype.keys=function(b){return void 0!==b?(this._keys=b,this._keyCount=(new c).parse(this._keys).length,
this):this._keys};d.prototype.type=function(b){return void 0!==b?(this._type=b,this):this._type};d.prototype.unique=function(b){return void 0!==b?(this._unique=b,this):this._unique};d.prototype.rebuild=function(){if(this._collection){var b=this._collection.subset({},{$decouple:!1,$orderBy:this._keys}).find(),c,a=b.length;this._data={};this._unique&&(this._uniqueLookup={});for(c=0;c<a;c++)this.insert(b[c])}this._state={name:this._name,keys:this._keys,indexSize:this._size,built:new Date,updated:new Date,
ok:!0}};d.prototype.insert=function(b,c){var a,d;this._unique&&(a=this._itemHash(b,this._keys),this._uniqueLookup[a]=b);a=this._itemHashArr(b,this._keys);for(d=0;d<a.length;d++)this.pushToPathValue(a[d],b)};d.prototype.remove=function(b,c){var a,d;this._unique&&(a=this._itemHash(b,this._keys),delete this._uniqueLookup[a]);a=this._itemHashArr(b,this._keys);for(d=0;d<a.length;d++)this.pullFromPathValue(a[d],b)};d.prototype.violation=function(b){b=this._itemHash(b,this._keys);return Boolean(this._uniqueLookup[b])};
d.prototype.hashViolation=function(b){return Boolean(this._uniqueLookup[b])};d.prototype.pushToPathValue=function(b,c){var a=this._data[b]=this._data[b]||[];-1===a.indexOf(c)&&(a.push(c),this._size++,this.pushToCrossRef(c,a))};d.prototype.pullFromPathValue=function(b,c){var a=this._data[b],d;d=a.indexOf(c);-1<d&&(a.splice(d,1),this._size--,this.pullFromCrossRef(c,a));a.length||delete this._data[b]};d.prototype.pull=function(b){var c=b[this._collection.primaryKey()],a=this._crossRef[c],d,e=a.length,
f;for(d=0;d<e;d++)f=a[d],this._pullFromArray(f,b);this._size--;delete this._crossRef[c]};d.prototype._pullFromArray=function(b,c){for(var a=b.length;a--;)b[a]===c&&b.splice(a,1)};d.prototype.pushToCrossRef=function(b,c){var a=b[this._collection.primaryKey()];this._crossRef[a]=this._crossRef[a]||[];a=this._crossRef[a];-1===a.indexOf(c)&&a.push(c)};d.prototype.pullFromCrossRef=function(b,c){var a=b[this._collection.primaryKey()];delete this._crossRef[a]};d.prototype.lookup=function(b){return this._data[this._itemHash(b,
this._keys)]||[]};d.prototype.match=function(b,g){return(new c).countObjectPaths(this._keys,b)};d.prototype._itemHash=function(b,g){var a=new c,d,e="",f;d=a.parse(g);for(f=0;f<d.length;f++)e&&(e+="_"),e+=a.value(b,d[f].path).join(":");return e};d.prototype._itemKeyHash=function(b,g){var a=new c,d,e="",f;d=a.parse(g);for(f=0;f<d.length;f++)e&&(e+="_"),e+=a.keyValue(b,d[f].path);return e};d.prototype._itemHashArr=function(b,g){var a=new c,d,e=[],f,h,l,s;d=a.parse(g);for(l=0;l<d.length;l++)for(f=a.value(b,
d[l].path),h=0;h<f.length;h++)if(0===l)e.push(f[h]);else for(s=0;s<e.length;s++)e[s]=e[s]+"_"+f[h];return e};h.finishModule("Index");l.exports=d},{"./Path":19,"./Shared":22}],10:[function(d,l,h){d=d("./Shared");h=function(c){this.init.apply(this,arguments)};h.prototype.init=function(c){this._name=c;this._data={};this._primaryKey="_id"};d.addModule("KeyValueStore",h);d.mixin(h.prototype,"Mixin.ChainReactor");d.synthesize(h.prototype,"name");h.prototype.primaryKey=function(c){return void 0!==c?(this._primaryKey=
c,this):this._primaryKey};h.prototype.truncate=function(){this._data={};return this};h.prototype.set=function(c,b){this._data[c]=b?b:!0;return this};h.prototype.get=function(c){return this._data[c]};h.prototype.lookup=function(c){c=c[this._primaryKey];var b,g,a,d;if(c instanceof Array){g=c.length;d=[];for(b=0;b<g;b++)(a=this._data[c[b]])&&d.push(a);return d}if(c instanceof RegExp){d=[];for(b in this._data)this._data.hasOwnProperty(b)&&c.test(b)&&d.push(this._data[b]);return d}if("object"===typeof c){if(c.$ne){d=
[];for(b in this._data)this._data.hasOwnProperty(b)&&b!==c.$ne&&d.push(this._data[b]);return d}if(c.$in&&c.$in instanceof Array){d=[];for(b in this._data)this._data.hasOwnProperty(b)&&-1<c.$in.indexOf(b)&&d.push(this._data[b]);return d}if(c.$nin&&c.$nin instanceof Array){d=[];for(b in this._data)this._data.hasOwnProperty(b)&&-1===c.$nin.indexOf(b)&&d.push(this._data[b]);return d}if(c.$or&&c.$or instanceof Array){d=[];for(b=0;b<c.$or.length;b++)d=d.concat(this.lookup(c.$or[b]));return d}}else return a=
this._data[c],void 0!==a?[a]:[]};h.prototype.unSet=function(c){delete this._data[c];return this};h.prototype.uniqueSet=function(c,b){return void 0===this._data[c]?(this._data[c]=b,!0):!1};d.finishModule("KeyValueStore");l.exports=h},{"./Shared":22}],11:[function(d,l,h){h=d("./Shared");var c=d("./Operation");d=function(){this.init.apply(this,arguments)};d.prototype.init=function(){this._data=[]};h.addModule("Metrics",d);h.mixin(d.prototype,"Mixin.ChainReactor");d.prototype.create=function(b){b=new c(b);
this._enabled&&this._data.push(b);return b};d.prototype.start=function(){this._enabled=!0;return this};d.prototype.stop=function(){this._enabled=!1;return this};d.prototype.clear=function(){this._data=[];return this};d.prototype.list=function(){return this._data};h.finishModule("Metrics");l.exports=d},{"./Operation":16,"./Shared":22}],12:[function(d,l,h){l.exports={preSetData:function(){},postSetData:function(){}}},{}],13:[function(d,l,h){l.exports={chain:function(c){this._chain=this._chain||[];-1===
this._chain.indexOf(c)&&this._chain.push(c)},unChain:function(c){this._chain&&(c=this._chain.indexOf(c),-1<c&&this._chain.splice(c,1))},chainSend:function(c,b,d){if(this._chain){var a=this._chain,k=a.length,e;for(e=0;e<k;e++)a[e].chainReceive(this,c,b,d)}},chainReceive:function(c,b,d,a){c={sender:c,type:b,data:d,options:a};(!this._chainHandler||this._chainHandler&&!this._chainHandler(c))&&this.chainSend(c.type,c.data,c.options)}}},{}],14:[function(d,l,h){var c=0;d={decouple:function(b){if(void 0!==
b)return JSON.parse(JSON.stringify(b))},objectId:function(b){var d=Math.pow(10,17);if(b){var a=0,k=b.length,e;for(e=0;e<k;e++)a+=b.charCodeAt(e)*d;b=a.toString(16)}else c++,b=(c+(Math.random()*d+Math.random()*d+Math.random()*d+Math.random()*d)).toString(16);return b},debug:d("./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,c){return void 0!==b?void 0!==c?(this._debug=this._debug||{},this._debug[b]=c,this.chainSend("debug",this._debug),this):this._debug&&this._debug[c]||this._db&&this._db._debug&&this._db._debug[b]:this._debug&&this._debug.all}])};l.exports=d},{"./Overload":17}],15:[function(d,l,h){d={on:new Overload({"string, function":function(c,b){this._listeners=this._listeners||{};this._listeners[c]=
this._listeners[c]||{};this._listeners[c]["*"]=this._listeners[c]["*"]||[];this._listeners[c]["*"].push(b);return this},"string, *, function":function(c,b,d){this._listeners=this._listeners||{};this._listeners[c]=this._listeners[c]||{};this._listeners[c][b]=this._listeners[c][b]||[];this._listeners[c][b].push(d);return this}}),off:new Overload({string:function(c){this._listeners&&this._listeners[c]&&c in this._listeners&&delete this._listeners[c];return this},"string, function":function(c,b){var d,
a;"string"===typeof b?this._listeners&&this._listeners[c]&&this._listeners[c][b]&&delete this._listeners[c][b]:c in this._listeners&&(d=this._listeners[c]["*"],a=d.indexOf(b),-1<a&&d.splice(a,1));return this},"string, *, function":function(c,b,d){this._listeners&&c in this._listeners&&b in this.listeners[c]&&(c=this._listeners[c][b],d=c.indexOf(d),-1<d&&c.splice(d,1))},"string, *":function(c,b){this._listeners&&c in this._listeners&&b in this._listeners[c]&&delete this._listeners[c][b]}}),emit:function(c,
b){this._listeners=this._listeners||{};if(c in this._listeners){if(this._listeners[c]["*"]){var d=this._listeners[c]["*"],a=d.length,k;for(k=0;k<a;k++)d[k].apply(this,Array.prototype.slice.call(arguments,1))}if(b instanceof Array&&b[0]&&b[0][this._primaryKey]){var d=this._listeners[c],e,f,a=b.length;for(k=0;k<a;k++)if(d[b[k][this._primaryKey]])for(e=d[b[k][this._primaryKey]].length,f=0;f<e;f++)d[b[k][this._primaryKey]][f].apply(this,Array.prototype.slice.call(arguments,1))}}return this}};l.exports=
d},{}],16:[function(d,l,h){h=d("./Shared");var c=d("./Path");d=function(b){this.pathSolver=new c;this.counter=0;this.init.apply(this,arguments)};d.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",d);h.mixin(d.prototype,"Mixin.ChainReactor");d.prototype.start=function(){this._data.time.startMs=(new Date).getTime()};d.prototype.log=function(b){if(b){var c=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);c&&(b.delta=b.time-c);return this}return this._data.log};d.prototype.time=function(b){if(void 0!==b){var c=this._data.time.process,c=c[b]=c[b]||{};c.startMs?(c.stopMs=(new Date).getTime(),c.totalMs=c.stopMs-c.startMs,c.stepObj.totalMs=c.totalMs,delete c.stepObj):(c.startMs=(new Date).getTime(),c.stepObj={name:b},this._data.steps.push(c.stepObj));return this}return this._data.time};d.prototype.flag=
function(b,c){if(void 0!==b&&void 0!==c)this._data.flag[b]=c;else return void 0!==b?this._data.flag[b]:this._data.flag};d.prototype.data=function(b,c,a){return void 0!==c?(this.pathSolver.set(this._data,b,c),this):this.pathSolver.get(this._data,b)};d.prototype.pushData=function(b,c,a){this.pathSolver.push(this._data,b,c)};d.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");l.exports=
d},{"./Path":19,"./Shared":22}],17:[function(d,l,h){Overload=function(c){if(c){var b,d,a,k,e;if(!(c instanceof Array)){a={};for(b in c)if(c.hasOwnProperty(b))if(k=b.replace(/ /g,""),-1===k.indexOf("*"))a[k]=c[b];else for(e=generateSignaturePermutations(k),k=0;k<e.length;k++)a[e[k]]||(a[e[k]]=c[b]);c=a}return function(){if(c instanceof Array)for(d=c.length,b=0;b<d;b++){if(c[b].length===arguments.length)return c[b].apply(this,arguments)}else{var a=[],e;for(b=0;b<arguments.length;b++)e=typeof arguments[b],
"object"===e&&arguments[b]instanceof Array&&(e="array"),a.push(e);e=a.join(",");if(c[e])return c[e].apply(this,arguments);for(b=a.length;0<=b;b--)if(e=a.slice(0,b).join(","),c[e+",..."])return c[e+",..."].apply(this,arguments)}throw"Overloaded method does not have a matching signature for the passed arguments: "+JSON.stringify(a);}}return function(){}};generateSignaturePermutations=function(c){var b=[],d,a=["string","object","number","function","undefined"],k;if(-1<c.indexOf("*"))for(k=0;k<a.length;k++)d=
c.replace("*",a[k]),b=b.concat(generateSignaturePermutations(d));else b.push(c);return b};l.exports=Overload},{}],18:[function(d,l,h){var c,b,g;h=d("./Shared");var a=function(){this.init.apply(this,arguments)};a.prototype.init=function(a){this._name=a;this._data=new g("__FDB__dc_data_"+this._name);this._collData=new b;this._collections=[]};h.addModule("Overview",a);h.mixin(a.prototype,"Mixin.Common");h.mixin(a.prototype,"Mixin.ChainReactor");b=d("./Collection");g=d("./Document");d=h.modules.Core;
c=h.modules.Core.prototype.init;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){void 0!==a&&("string"===typeof a&&(a=this._db.collection(a)),
this._addCollection(a));return this};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),this._refresh());return this};a.prototype._removeCollection=function(a){-1<this._collections.indexOf(a)&&(this._collections.splice(a,1),a.unChain(this),this._refresh());return this};
a.prototype._refresh=function(){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};
d.prototype.init=function(){this._overview={};c.apply(this,arguments)};d.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");l.exports=a},{"./Collection":3,"./Document":7,"./Shared":22}],19:[function(d,l,h){d=d("./Shared");h=function(c){this.init.apply(this,arguments)};h.prototype.init=function(c){c&&this.path(c)};d.addModule("Path",h);d.mixin(h.prototype,"Mixin.ChainReactor");h.prototype.path=
function(c){return void 0!==c?(this._path=this.clean(c),this._pathParts=this._path.split("."),this):this._path};h.prototype.hasObjectPaths=function(c,b){var d=!0,a;for(a in c)if(c.hasOwnProperty(a)&&(void 0===b[a]||"object"===typeof c[a]&&(d=this.hasObjectPaths(c[a],b[a]),!d)))return!1;return d};h.prototype.countKeys=function(c){var b=0,d;for(d in c)c.hasOwnProperty(d)&&void 0!==c[d]&&("object"!==typeof c[d]?b++:b+=this.countKeys(c[d]));return b};h.prototype.countObjectPaths=function(c,b){var d,a=
{},k=0,e=0,f;for(f in b)b.hasOwnProperty(f)&&("object"===typeof b[f]?(d=this.countObjectPaths(c[f],b[f]),a[f]=d.matchedKeys,e+=d.totalKeyCount,k+=d.matchedKeyCount):(e++,c&&c[f]&&"object"!==typeof c[f]?(a[f]=!0,k++):a[f]=!1));return{matchedKeys:a,matchedKeyCount:k,totalKeyCount:e}};h.prototype.parse=function(c,b){var d=[],a="",k,e,f;for(e in c)if(c.hasOwnProperty(e))if(a=e,"object"===typeof c[e])if(b)for(k=this.parse(c[e],b),f=0;f<k.length;f++)d.push({path:a+"."+k[f].path,value:k[f].value});else for(k=
this.parse(c[e]),f=0;f<k.length;f++)d.push({path:a+"."+k[f].path});else b?d.push({path:a,value:c[e]}):d.push({path:a});return d};h.prototype.parseArr=function(c,b){b=b||{};return this._parseArr(c,"",[],b)};h.prototype._parseArr=function(c,b,d,a){var k,e="";b=b||"";d=d||[];for(k in c)c.hasOwnProperty(k)&&(!a.ignore||a.ignore&&!a.ignore.test(k))&&(e=b?b+"."+k:k,"object"===typeof c[k]?this._parseArr(c[k],e,d,a):d.push(e));return d};h.prototype.value=function(c,b){if(void 0!==c&&"object"===typeof c){var d,
a,k,e,f=[],h;void 0!==b&&(b=this.clean(b),d=b.split("."));d=d||this._pathParts;a=d.length;k=c;for(h=0;h<a;h++){k=k[d[h]];if(e instanceof Array){for(a=0;a<e.length;a++)f=f.concat(this.value(e,a+"."+d[h]));return f}if(!k||"object"!==typeof k)break;e=k}return[k]}return[]};h.prototype.set=function(c,b,d){if(void 0!==c&&void 0!==b){var a;b=this.clean(b);b=b.split(".");a=b.shift();b.length?(c[a]=c[a]||{},this.set(c[a],b.join("."),d)):c[a]=d}return c};h.prototype.get=function(c,b){return this.value(c,b)[0]};
h.prototype.push=function(c,b,d){if(void 0!==c&&void 0!==b){var a;b=this.clean(b);b=b.split(".");a=b.shift();if(b.length)c[a]=c[a]||{},this.set(c[a],b.join("."),d);else if(c[a]=c[a]||[],c[a]instanceof Array)c[a].push(d);else throw"Cannot push to a path whose endpoint is not an array!";}return c};h.prototype.keyValue=function(c,b){var d,a,k,e,f;void 0!==b&&(b=this.clean(b),d=b.split("."));d=d||this._pathParts;a=d.length;k=c;for(f=0;f<a;f++)if(k=k[d[f]],!k||"object"!==typeof k){e=d[f]+":"+k;break}return e};
h.prototype.clean=function(c){"."===c.substr(0,1)&&(c=c.substr(1,c.length-1));return c};d.finishModule("Path");l.exports=h},{"./Shared":22}],20:[function(d,l,h){h=d("./Shared");var c=d("localforage"),b,g,a,k,e;e=function(){this.init.apply(this,arguments)};e.prototype.init=function(a){a.isClient()&&void 0!==Storage&&(this.mode("localforage"),c.config({driver:[c.INDEXEDDB,c.WEBSQL,c.LOCALSTORAGE],name:"ForerunnerDB",storeName:"FDB"}))};h.addModule("Persist",e);h.mixin(e.prototype,"Mixin.ChainReactor");
b=h.modules.Core;g=d("./Collection");a=g.prototype.drop;d("./CollectionGroup");k=b.prototype.init;e.prototype.mode=function(a){return void 0!==a?(this._mode=a,this):this._mode};e.prototype.driver=function(a){if(void 0!==a){switch(a.toUpperCase()){case "LOCALSTORAGE":c.setDriver(c.LOCALSTORAGE);break;case "WEBSQL":c.setDriver(c.WEBSQL);break;case "INDEXEDDB":c.setDriver(c.INDEXEDDB);break;default:throw"The persistence driver you have specified is not found. Please use either IndexedDB, WebSQL or LocalStorage!";
}return this}return c.driver()};e.prototype.save=function(a,b,d){var e;e=function(a,b){a="object"===typeof a?"json::fdb::"+JSON.stringify(a):"raw::fdb::"+a;b&&b(!1,a)};switch(this.mode()){case "localforage":e(b,function(b,e){c.setItem(a,e).then(function(a){d(!1,a)},function(a){d(a)})});break;default:d&&d("No data handler.")}};e.prototype.load=function(a,b){var d,e,g;g=function(a,b){if(a){d=a.split("::fdb::");switch(d[0]){case "json":e=JSON.parse(d[1]);break;case "raw":e=d[1]}b&&b(!1,e)}else b(!1,
a)};switch(this.mode()){case "localforage":c.getItem(a).then(function(a){g(a,b)},function(a){b(a)});break;default:b&&b("No data handler or unrecognised data type.")}};e.prototype.drop=function(a,b){switch(this.mode()){case "localforage":c.removeItem(a).then(function(){b(!1)},function(a){b(a)});break;default:b&&b("No data handler or unrecognised data type.")}};g.prototype.drop=function(b){b&&(this._name?this._db?this._db.persist.drop(this._name):callback&&callback("Cannot drop a collection's persistent storage when the collection is not attached to a database!"):
callback&&callback("Cannot drop a collection's persistent storage when no name assigned to collection!"));a.apply(this,arguments)};g.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!")};g.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 e(this);k.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");l.exports=e},{"./Collection":3,"./CollectionGroup":4,"./Shared":22,localforage:30}],21:[function(d,l,h){d=d("./Shared");h=function(c,b,d){if(c&&b&&d){this._reactorIn=c;this._reactorOut=b;this._chainHandler=d;if(!c.chain||!b.chainReceive)throw"ReactorIO requires passed in and out objects to implement the ChainReactor mixin!";c.chain(this);this.chain(b)}else throw"ReactorIO requires an in, out and process argument to instantiate!";};d.addModule("ReactorIO",h);h.prototype.drop=
function(){this._reactorIn.unChain(this);this.unChain(this._reactorOut);delete this._reactorIn;delete this._reactorOut;delete this._chainHandler};d.mixin(h.prototype,"Mixin.ChainReactor");d.finishModule("ReactorIO");l.exports=h},{"./Shared":22}],22:[function(d,l,h){d={modules:{},_synth:{},addModule:function(c,b){this.modules[c]=b;this.emit("moduleLoad",[c,b])},finishModule:function(c){if(this.modules[c])this.modules[c]._fdbFinished=!0,this.emit("moduleFinished",[c,this.modules[c]]);else throw"finishModule called on a module that has not been registered with addModule(): "+
c;},moduleFinished:function(c,b){if(this.modules[c]&&this.modules[c]._fdbFinished)b(c,this.modules[c]);else this.on("moduleFinished",b)},moduleExists:function(c){return Boolean(this.modules[c])},mixin:function(c,b){var d=this.mixins[b];if(d)for(var a in d)d.hasOwnProperty(a)&&(c[a]=d[a]);else throw"Cannot find mixin named: "+b;},synthesize:function(c,b,d){this._synth[b]=this._synth[b]||function(a){return void 0!==a?(this["_"+b]=a,this):this["_"+b]};if(d){var a=this;c[b]=function(){var c=this.$super,
e;this.$super=a._synth[b];e=d.apply(this,arguments);this.$super=c;return e}}else c[b]=this._synth[b]},overload:d("./Overload"),mixins:{"Mixin.Common":d("./Mixin.Common"),"Mixin.Events":d("./Mixin.Events"),"Mixin.ChainReactor":d("./Mixin.ChainReactor"),"Mixin.CRUD":d("./Mixin.CRUD")}};d.mixin(d,"Mixin.Events");l.exports=d},{"./Mixin.CRUD":12,"./Mixin.ChainReactor":13,"./Mixin.Common":14,"./Mixin.Events":15,"./Overload":17}],23:[function(d,l,h){var c,b,g,a,k;h=d("./Shared");var e=function(a,b,c){this.init.apply(this,
arguments)};e.prototype.init=function(a,b,d){this._name=a;this._groups=[];this._listeners={};this._querySettings={};this._debug={};this.query(b,!1);this.queryOptions(d,!1);this._privateData=new c("__FDB__view_privateData_"+this._name)};h.addModule("View",e);h.mixin(e.prototype,"Mixin.Common");h.mixin(e.prototype,"Mixin.ChainReactor");c=d("./Collection");CollectionGroup=d("./CollectionGroup");k=d("./ActiveBucket");a=d("./ReactorIO");b=c.prototype.init;d=h.modules.Core;g=d.prototype.init;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(b){var c=this;if(void 0!==b){"string"===
typeof b&&(b=this._db.collection(b));this._from=b;this._io=new a(b,this,function(a){var b,d,f;if(c._querySettings.query){if("insert"===a.type){b=a.data;if(b instanceof Array)for(d=[],a=0;a<b.length;a++)c._privateData._match(b[a],c._querySettings.query,"and")&&(d.push(b[a]),f=!0);else c._privateData._match(b,c._querySettings.query,"and")&&(d=b,f=!0);f&&this.chainSend("insert",d);return!0}if("update"===a.type&&(d=c._privateData.diff(c._from.subset(c._querySettings.query,c._querySettings.options)),d.insert.length||
d.remove.length)){d.insert.length&&this.chainSend("insert",d.insert);if(d.update.length)for(f=c._privateData.primaryKey(),a=0;a<d.update.length;a++)b={},b[f]=d.update[a][f],this.chainSend("update",{query:b,update:d.update[a]});if(d.remove.length){f=c._privateData.primaryKey();b=[];var e={query:{$or:b}};for(a=0;a<d.remove.length;a++)b.push({_id:d.remove[a][f]});this.chainSend("remove",e)}return!0}}return!1});var d=b.find(this._querySettings.query,this._querySettings.options);this._transformPrimaryKey(b.primaryKey());
this._transformSetData(d);this._privateData.primaryKey(b.primaryKey());this._privateData.setData(d);this._querySettings.options&&this._querySettings.options.$orderBy?this.rebuildActiveBucket(this._querySettings.options.$orderBy):this.rebuildActiveBucket()}return this};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(){return this._from?((this.debug()||this._db&&this._db.debug())&&console.log("ForerunnerDB.View: Dropping view "+this._name),this._io.drop(),this._privateData.drop(),!0):!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.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 k(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 c("__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)};c.prototype.init=function(){this._views=[];b.apply(this,arguments)};c.prototype.view=function(a,b,c){if(this._db&&
this._db._views){if(this._db._views[a])throw"Cannot create a view using this collection because one with this name already exists: "+a;a=(new e(a,b,c)).db(this._db).from(this);this._views=this._views||[];this._views.push(a);return a}};c.prototype._addView=CollectionGroup.prototype._addView=function(a){void 0!==a&&this._views.push(a);return this};c.prototype._removeView=CollectionGroup.prototype._removeView=function(a){void 0!==a&&(a=this._views.indexOf(a),-1<a&&this._views.splice(a,1));return this};
d.prototype.init=function(){this._views={};g.apply(this,arguments)};d.prototype.view=function(a){this._views[a]||(this.debug()||this._db&&this._db.debug())&&console.log("Core.View: Creating view "+a);this._views[a]=this._views[a]||(new e(a)).db(this);return this._views[a]};d.prototype.viewExists=function(a){return Boolean(this._views[a])};d.prototype.views=function(){var a=[],b;for(b in this._views)this._views.hasOwnProperty(b)&&a.push({name:b,count:this._views[b].count()});return a};h.finishModule("View");
l.exports=e},{"./ActiveBucket":2,"./Collection":3,"./CollectionGroup":4,"./ReactorIO":21,"./Shared":22}],24:[function(d,l,h){function c(d){function e(b){null===s?r.push(b):a(function(){var a=s?b.onFulfilled:b.onRejected;if(null===a)(s?b.resolve:b.reject)(y);else{var c;try{c=a(y)}catch(d){b.reject(d);return}b.resolve(c)}})}function f(a){try{if(a===u)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){g(b.bind(a),
f,h);return}}s=!0;y=a;l()}catch(c){h(c)}}function h(a){s=!1;y=a;l()}function l(){for(var a=0,b=r.length;a<b;a++)e(r[a]);r=null}if("object"!==typeof this)throw new TypeError("Promises must be constructed via new");if("function"!==typeof d)throw new TypeError("not a function");var s=null,y=null,r=[],u=this;this.then=function(a,d){return new c(function(c,f){e(new b(a,d,c,f))})};g(d,f,h)}function b(a,b,c,d){this.onFulfilled="function"===typeof a?a:null;this.onRejected="function"===typeof b?b:null;this.resolve=
c;this.reject=d}function g(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(g){d||(d=!0,c(g))}}var a=d("asap");l.exports=c},{asap:26}],25:[function(d,l,h){function c(a){this.then=function(c){return"function"!==typeof c?this:new b(function(b,d){g(function(){try{b(c(a))}catch(e){d(e)}})})}}var b=d("./core.js"),g=d("asap");l.exports=b;c.prototype=Object.create(b.prototype);var a=new c(!0),k=new c(!1),e=new c(null),f=new c(void 0),t=new c(0),w=new c("");b.resolve=function(d){if(d instanceof
b)return d;if(null===d)return e;if(void 0===d)return f;if(!0===d)return a;if(!1===d)return k;if(0===d)return t;if(""===d)return w;if("object"===typeof d||"function"===typeof d)try{var g=d.then;if("function"===typeof g)return new b(g.bind(d))}catch(h){return new b(function(a,b){b(h)})}return new c(d)};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)});g(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){g(function(){throw a;})})};b.prototype.nodeify=function(a){if("function"!=typeof a)return this;this.then(function(b){g(function(){a(null,b)})},function(b){g(function(){a(b)})})};b.prototype["catch"]=
function(a){return this.then(null,a)}},{"./core.js":24,asap:26}],26:[function(d,l,h){(function(c){function b(){for(;d.next;){d=d.next;var a=d.task;d.task=void 0;var c=d.domain;c&&(d.domain=void 0,c.enter());try{a()}catch(e){if(f)throw c&&c.exit(),setTimeout(b,0),c&&c.enter(),e;setTimeout(function(){throw e;},0)}c&&c.exit()}h=!1}var d={task:void 0,next:null},a=d,h=!1,e=void 0,f=!1;if("undefined"!==typeof c&&c.nextTick)f=!0,e=function(){c.nextTick(b)};else if("function"===typeof setImmediate)e="undefined"!==
typeof window?setImmediate.bind(window,b):function(){setImmediate(b)};else if("undefined"!==typeof MessageChannel){var t=new MessageChannel;t.port1.onmessage=b;e=function(){t.port2.postMessage(0)}}else e=function(){setTimeout(b,0)};l.exports=function(b){a=a.next={task:b,domain:f&&c.domain,next:null};h||(h=!0,e())}}).call(this,d("_process"))},{_process:31}],27:[function(d,l,h){(function(){function c(a){var b=this,c={db:null};if(a)for(var d in a)c[d]=a[d];return new r(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 r(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 g(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 r(function(c,e){d.ready().then(function(){var f=d._dbInfo,f=f.db.transaction(f.storeName,"readwrite").objectStore(f.storeName);null===b&&(b=void 0);var g=f.put(b,a);g.onsuccess=function(){void 0===b&&(b=null);c(b)};g.onerror=function(){e(g.error)}})["catch"](e)});s(e,c);return e}function a(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 r(function(b,d){c.ready().then(function(){var e=c._dbInfo,f=e.db.transaction(e.storeName,"readwrite").objectStore(e.storeName)["delete"](a);f.onsuccess=function(){b()};f.onerror=function(){d(f.error)};f.onabort=function(a){a=a.target.error;"QuotaExceededError"===a&&d(a)}})["catch"](d)});s(d,b);return d}function h(a){var b=this,c=new r(function(a,c){b.ready().then(function(){var d=b._dbInfo,
e=d.db.transaction(d.storeName,"readwrite").objectStore(d.storeName).clear();e.onsuccess=function(){a()};e.onerror=function(){c(e.error)}})["catch"](c)});s(c,a);return c}function e(a){var b=this,c=new r(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)});w(c,a);return c}function f(a,b){var c=this,d=new r(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)});w(d,b);return d}function t(a){var b=this,c=new r(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)});w(c,a);return c}function w(a,b){b&&a.then(function(a){b(null,a)},function(a){b(a)})}function s(a,b){b&&a.then(function(a){y(b,a)},function(a){b(a)})}function y(a,b){if(a)return setTimeout(function(){return a(null,b)},0)}var r="undefined"!==typeof l&&l.exports?d("promise"):this.Promise,u=u||this.indexedDB||this.webkitIndexedDB||this.mozIndexedDB||this.OIndexedDB||this.msIndexedDB;if(u){var v={_driver:"asyncStorage",_initStorage:c,getItem:b,setItem:g,
removeItem:a,clear:h,length:e,key:f,keys:t};"undefined"!==typeof l&&l.exports?l.exports=v:this.asyncStorage=v}}).call(window)},{promise:25}],28:[function(d,l,h){(function(){function c(a){if(a.substring(0,w)!==t)return JSON.parse(a);var b=a.substring(x);a=a.substring(w,x);for(var c=new ArrayBuffer(2*b.length),d=new Uint16Array(c),e=b.length-1;0<=e;e--)d[e]=b.charCodeAt(e);switch(a){case s:return c;case y:return new Blob([c]);case r:return new Int8Array(c);case u:return new Uint8Array(c);case v:return new Uint8ClampedArray(c);
case n:return new Int16Array(c);case p:return new Uint16Array(c);case q:return new Int32Array(c);case m:return new Uint32Array(c);case B:return new Float32Array(c);case z:return new Float64Array(c);default:throw Error("Unkown type: "+a);}}function b(a){var b="";a=new Uint16Array(a);try{b=String.fromCharCode.apply(null,a)}catch(c){for(var d=0;d<a.length;d++)b+=String.fromCharCode(a[d])}return b}function g(a,c){var d="";a&&(d=a.toString());if(a&&("[object ArrayBuffer]"===a.toString()||a.buffer&&"[object ArrayBuffer]"===
a.buffer.toString())){var e,f=t;a instanceof ArrayBuffer?(e=a,f+=s):(e=a.buffer,"[object Int8Array]"===d?f+=r:"[object Uint8Array]"===d?f+=u:"[object Uint8ClampedArray]"===d?f+=v:"[object Int16Array]"===d?f+=n:"[object Uint16Array]"===d?f+=p:"[object Int32Array]"===d?f+=q:"[object Uint32Array]"===d?f+=m:"[object Float32Array]"===d?f+=B:"[object Float64Array]"===d?f+=z:c(Error("Failed to get type for BinaryArray")));c(f+b(e))}else if("[object Blob]"===d)d=new FileReader,d.onload=function(){var a=b(this.result);
c(t+y+a)},d.readAsArrayBuffer(a);else try{c(JSON.stringify(a))}catch(g){window.console.error("Couldn't convert value into a JSON string: ",a),c(g)}}function a(a,b){b&&a.then(function(a){b(null,a)},function(a){b(a)})}var h="undefined"!==typeof l&&l.exports?d("promise"):this.Promise,e=null;try{if(!(this.localStorage&&"setItem"in this.localStorage))return;e=this.localStorage}catch(f){return}var t="__lfsc__:",w=t.length,s="arbf",y="blob",r="si08",u="ui08",v="uic8",n="si16",q="si32",p="ur16",m="ui32",
B="fl32",z="fl64",x=w+s.length,A={_driver:"localStorageWrapper",_initStorage:function(a){var b={};if(a)for(var c in a)b[c]=a[c];b.keyPrefix=b.name+"/";this._dbInfo=b;return h.resolve()},getItem:function(b,d){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=new h(function(a,d){f.ready().then(function(){try{var g=e.getItem(f._dbInfo.keyPrefix+b);g&&(g=c(g));a(g)}catch(h){d(h)}})["catch"](d)});a(g,d);return g},setItem:function(b,c,d){var f=
this;"string"!==typeof b&&(window.console.warn(b+" used as a key, but it is not a string."),b=String(b));var m=new h(function(a,d){f.ready().then(function(){void 0===c&&(c=null);var h=c;g(c,function(c,g){if(g)d(g);else{try{e.setItem(f._dbInfo.keyPrefix+b,c)}catch(k){"QuotaExceededError"!==k.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==k.name||d(k)}a(h)}})})["catch"](d)});a(m,d);return m},removeItem:function(b,c){var d=this;"string"!==typeof b&&(window.console.warn(b+" used as a key, but it is not a string."),
b=String(b));var f=new h(function(a,c){d.ready().then(function(){e.removeItem(d._dbInfo.keyPrefix+b);a()})["catch"](c)});a(f,c);return f},clear:function(b){var c=this,d=new h(function(a,b){c.ready().then(function(){for(var b=c._dbInfo.keyPrefix,d=e.length-1;0<=d;d--){var f=e.key(d);0===f.indexOf(b)&&e.removeItem(f)}a()})["catch"](b)});a(d,b);return d},length:function(b){var c=this,d=new h(function(a,b){c.keys().then(function(b){a(b.length)})["catch"](b)});a(d,b);return d},key:function(b,c){var d=
this,f=new h(function(a,c){d.ready().then(function(){var c=d._dbInfo,f;try{f=e.key(b)}catch(g){f=null}f&&(f=f.substring(c.keyPrefix.length));a(f)})["catch"](c)});a(f,c);return f},keys:function(b){var c=this,d=new h(function(a,b){c.ready().then(function(){for(var b=c._dbInfo,d=e.length,f=[],g=0;g<d;g++)0===e.key(g).indexOf(b.keyPrefix)&&f.push(e.key(g).substring(b.keyPrefix.length));a(f)})["catch"](b)});a(d,b);return d}};"undefined"!==typeof l&&l.exports?l.exports=A:this.localStorageWrapper=A}).call(window)},
{promise:25}],29:[function(d,l,h){(function(){function c(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];return new v(function(d,e){try{c.db=n(c.name,String(c.version),c.description,c.size)}catch(f){return b.setDriver("localStorageWrapper").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)})})})}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 v(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=s(d));b(d)},function(a,b){d(b)})})})["catch"](d)});r(d,b);return d}function g(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 v(function(c,e){d.ready().then(function(){void 0===b&&(b=null);var f=b;y(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 a(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 v(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 h(a){var b=this,c=new v(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 v(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 f(a,b){var c=this,d=new v(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 t(a){var b=this,c=new v(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 w(a){a=new Uint8Array(a);var b,c="";for(b=0;b<a.length;b+=3)c+=u[a[b]>>2],c+=u[(a[b]&3)<<
4|a[b+1]>>4],c+=u[(a[b+1]&15)<<2|a[b+2]>>6],c+=u[a[b+2]&63];2===a.length%3?c=c.substring(0,c.length-1)+"=":1===a.length%3&&(c=c.substring(0,c.length-2)+"==");return c}function s(a){if(a.substring(0,p)!==q)return JSON.parse(a);var b=a.substring(I);a=a.substring(p,I);var c=0.75*b.length,d=b.length,e=0,f,g,h,k;"="===b[b.length-1]&&(c--,"="===b[b.length-2]&&c--);for(var n=new ArrayBuffer(c),l=new Uint8Array(n),c=0;c<d;c+=4)f=u.indexOf(b[c]),g=u.indexOf(b[c+1]),h=u.indexOf(b[c+2]),k=u.indexOf(b[c+3]),
l[e++]=f<<2|g>>4,l[e++]=(g&15)<<4|h>>2,l[e++]=(h&3)<<6|k&63;switch(a){case m:return n;case B:return new Blob([n]);case z:return new Int8Array(n);case x:return new Uint8Array(n);case A:return new Uint8ClampedArray(n);case D:return new Int16Array(n);case F:return new Uint16Array(n);case E:return new Int32Array(n);case G:return new Uint32Array(n);case H:return new Float32Array(n);case J:return new Float64Array(n);default:throw Error("Unkown type: "+a);}}function y(a,b){var c="";a&&(c=a.toString());if(a&&
("[object ArrayBuffer]"===a.toString()||a.buffer&&"[object ArrayBuffer]"===a.buffer.toString())){var d,e=q;a instanceof ArrayBuffer?(d=a,e+=m):(d=a.buffer,"[object Int8Array]"===c?e+=z:"[object Uint8Array]"===c?e+=x:"[object Uint8ClampedArray]"===c?e+=A:"[object Int16Array]"===c?e+=D:"[object Uint16Array]"===c?e+=F:"[object Int32Array]"===c?e+=E:"[object Uint32Array]"===c?e+=G:"[object Float32Array]"===c?e+=H:"[object Float64Array]"===c?e+=J:b(Error("Failed to get type for BinaryArray")));b(e+w(d))}else if("[object Blob]"===
c)c=new FileReader,c.onload=function(){var a=w(this.result);b(q+B+a)},c.readAsArrayBuffer(a);else try{b(JSON.stringify(a))}catch(f){window.console.error("Couldn't convert value into a JSON string: ",a),b(null,f)}}function r(a,b){b&&a.then(function(a){b(null,a)},function(a){b(a)})}var u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",v="undefined"!==typeof l&&l.exports?d("promise"):this.Promise,n=this.openDatabase,q="__lfsc__:",p=q.length,m="arbf",B="blob",z="si08",x="ui08",A="uic8",
D="si16",E="si32",F="ur16",G="ui32",H="fl32",J="fl64",I=p+m.length;if(n){var K={_driver:"webSQLStorage",_initStorage:c,getItem:b,setItem:g,removeItem:a,clear:h,length:e,key:f,keys:t};"undefined"!==typeof l&&l.exports?l.exports=K:this.webSQLStorage=K}}).call(window)},{promise:25}],30:[function(d,l,h){(function(){function c(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)&&
(r(b[c])?arguments[0][c]=b[c].slice():arguments[0][c]=b[c])}return arguments[0]}function g(a){for(var b in f)if(f.hasOwnProperty(b)&&f[b]===a)return!0;return!1}function a(a){this._config=b({},w,a);this._driverSet=null;this._ready=!1;this._dbInfo=null;for(a=0;a<t.length;a++)c(this,t[a]);this.setDriver(this._config.driver)}var h="undefined"!==typeof l&&l.exports?d("promise"):this.Promise,e={},f={INDEXEDDB:"asyncStorage",LOCALSTORAGE:"localStorageWrapper",WEBSQL:"webSQLStorage"},t="clear getItem key keys length removeItem setItem".split(" "),
w={description:"",driver:[f.INDEXEDDB,f.WEBSQL,f.LOCALSTORAGE].slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1},s=3;"undefined"!==typeof l&&l.exports&&(s=2);var y=function(a){var b=b||a.indexedDB||a.webkitIndexedDB||a.mozIndexedDB||a.OIndexedDB||a.msIndexedDB,c={};c[f.WEBSQL]=!!a.openDatabase;c[f.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=f.LOCALSTORAGE,e;try{e=a.localStorage&&"setItem"in a.localStorage&&a.localStorage.setItem}catch(g){e=!1}c[d]=!!e;return c}(this),r=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},u=this;a.prototype.INDEXEDDB=f.INDEXEDDB;a.prototype.LOCALSTORAGE=f.LOCALSTORAGE;a.prototype.WEBSQL=f.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,c){var d=new h(function(b,c){try{var d=a._driver,f=Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver"),m=Error("Custom driver name already in use: "+a._driver);if(a._driver)if(g(a._driver))c(m);else{for(var l=t.concat("_initStorage"),
m=0;m<l.length;m++){var p=l[m];if(!p||!a[p]||"function"!==typeof a[p]){c(f);return}}var q=h.resolve(!0);"_support"in a&&(q=a._support&&"function"===typeof a._support?a._support():h.resolve(!!a._support));q.then(function(c){y[d]=c;e[d]=a;b()},c)}else c(f)}catch(r){c(r)}});d.then(b,c);return d};a.prototype.driver=function(){return this._driver||null};a.prototype.ready=function(a){var b=this,c=new h(function(a,c){b._driverSet.then(function(){null===b._ready&&(b._ready=b._initStorage(b._config));b._ready.then(a,
c)})["catch"](c)});c.then(a,a);return c};a.prototype.setDriver=function(a,b,c){function f(){l._config.driver=l.driver()}var l=this;"string"===typeof a&&(a=[a]);this._driverSet=new h(function(b,c){var f=l._getFirstSupportedDriver(a),m=Error("No available storage method found.");if(f){l._dbInfo=null;l._ready=null;if(g(f)){if(1===s){d([f],function(a){l._extend(a);b()});return}if(2===s){var p;switch(f){case l.INDEXEDDB:p=d("./drivers/indexeddb");break;case l.LOCALSTORAGE:p=d("./drivers/localstorage");
break;case l.WEBSQL:p=d("./drivers/websql")}l._extend(p)}else l._extend(u[f])}else if(e[f])l._extend(e[f]);else{l._driverSet=h.reject(m);c(m);return}b()}else l._driverSet=h.reject(m),c(m)});this._driverSet.then(f,f);this._driverSet.then(b,c);return this._driverSet};a.prototype.supports=function(a){return!!y[a]};a.prototype._extend=function(a){b(this,a)};a.prototype._getFirstSupportedDriver=function(a){if(a&&r(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 v=new a;1===s?(void 0)("localforage",function(){return v}):2===s?l.exports=v:this.localforage=v}).call(window)},{"./drivers/indexeddb":27,"./drivers/localstorage":28,"./drivers/websql":29,promise:25}],31:[function(d,l,h){function c(){}d=l.exports={};d.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(c){var a=c.source;a!==window&&null!==a||"process-tick"!==c.data||(c.stopPropagation(),0<b.length&&b.shift()())},!0);return function(c){b.push(c);window.postMessage("process-tick","*")}}return function(b){setTimeout(b,0)}}();d.title="browser";d.browser=!0;d.env={};d.argv=[];d.on=c;d.addListener=c;d.once=c;d.off=c;d.removeListener=c;d.removeAllListeners=c;d.emit=c;d.binding=function(b){throw Error("process.binding is not supported");};d.cwd=function(){return"/"};d.chdir=function(b){throw Error("process.chdir is not supported");
}},{}]},{},[1])(1)});
