UNPKG

@atlascity/vuex-orm-plugin-lokijs

Version:
1 lines 101 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["vuex-orm-plugin-loki"]=e():t["vuex-orm-plugin-loki"]=e()}(window,function(){return function(t){var e={};function i(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(r,n,function(e){return t[e]}.bind(null,n));return r},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=12)}([function(t,e,i){var r;t.exports=(r=r||function(t,e){var i=Object.create||function(){function t(){}return function(e){var i;return t.prototype=e,i=new t,t.prototype=null,i}}(),r={},n=r.lib={},o=n.Base={extend:function(t){var e=i(this);return t&&e.mixIn(t),e.hasOwnProperty("init")&&this.init!==e.init||(e.init=function(){e.$super.init.apply(this,arguments)}),e.init.prototype=e,e.$super=this,e},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}},s=n.WordArray=o.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=null!=e?e:4*t.length},toString:function(t){return(t||l).stringify(this)},concat:function(t){var e=this.words,i=t.words,r=this.sigBytes,n=t.sigBytes;if(this.clamp(),r%4)for(var o=0;o<n;o++){var s=i[o>>>2]>>>24-o%4*8&255;e[r+o>>>2]|=s<<24-(r+o)%4*8}else for(var o=0;o<n;o+=4)e[r+o>>>2]=i[o>>>2];return this.sigBytes+=n,this},clamp:function(){var e=this.words,i=this.sigBytes;e[i>>>2]&=4294967295<<32-i%4*8,e.length=t.ceil(i/4)},clone:function(){var t=o.clone.call(this);return t.words=this.words.slice(0),t},random:function(e){for(var i,r=[],n=function(e){var e=e,i=987654321,r=4294967295;return function(){var n=((i=36969*(65535&i)+(i>>16)&r)<<16)+(e=18e3*(65535&e)+(e>>16)&r)&r;return n/=4294967296,(n+=.5)*(t.random()>.5?1:-1)}},o=0;o<e;o+=4){var a=n(4294967296*(i||t.random()));i=987654071*a(),r.push(4294967296*a()|0)}return new s.init(r,e)}}),a=r.enc={},l=a.Hex={stringify:function(t){for(var e=t.words,i=t.sigBytes,r=[],n=0;n<i;n++){var o=e[n>>>2]>>>24-n%4*8&255;r.push((o>>>4).toString(16)),r.push((15&o).toString(16))}return r.join("")},parse:function(t){for(var e=t.length,i=[],r=0;r<e;r+=2)i[r>>>3]|=parseInt(t.substr(r,2),16)<<24-r%8*4;return new s.init(i,e/2)}},c=a.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,r=[],n=0;n<i;n++){var o=e[n>>>2]>>>24-n%4*8&255;r.push(String.fromCharCode(o))}return r.join("")},parse:function(t){for(var e=t.length,i=[],r=0;r<e;r++)i[r>>>2]|=(255&t.charCodeAt(r))<<24-r%4*8;return new s.init(i,e)}},h=a.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},u=n.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=h.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(e){var i=this._data,r=i.words,n=i.sigBytes,o=this.blockSize,a=4*o,l=n/a,c=(l=e?t.ceil(l):t.max((0|l)-this._minBufferSize,0))*o,h=t.min(4*c,n);if(c){for(var u=0;u<c;u+=o)this._doProcessBlock(r,u);var d=r.splice(0,c);i.sigBytes-=h}return new s.init(d,h)},clone:function(){var t=o.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0}),d=(n.Hasher=u.extend({cfg:o.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){u.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){t&&this._append(t);var e=this._doFinalize();return e},blockSize:16,_createHelper:function(t){return function(e,i){return new t.init(i).finalize(e)}},_createHmacHelper:function(t){return function(e,i){return new d.HMAC.init(t,i).finalize(e)}}}),r.algo={});return r}(Math),r)},function(t,e,i){var r;t.exports=(r=i(0),i(7),i(8),i(2),i(11),function(){var t=r,e=t.lib.BlockCipher,i=t.algo,n=[],o=[],s=[],a=[],l=[],c=[],h=[],u=[],d=[],p=[];!function(){for(var t=[],e=0;e<256;e++)t[e]=e<128?e<<1:e<<1^283;var i=0,r=0;for(e=0;e<256;e++){var f=r^r<<1^r<<2^r<<3^r<<4;f=f>>>8^255&f^99,n[i]=f,o[f]=i;var y=t[i],v=t[y],g=t[v],m=257*t[f]^16843008*f;s[i]=m<<24|m>>>8,a[i]=m<<16|m>>>16,l[i]=m<<8|m>>>24,c[i]=m,m=16843009*g^65537*v^257*y^16843008*i,h[f]=m<<24|m>>>8,u[f]=m<<16|m>>>16,d[f]=m<<8|m>>>24,p[f]=m,i?(i=y^t[t[t[g^y]]],r^=t[t[r]]):i=r=1}}();var f=[0,1,2,4,8,16,32,64,128,27,54],y=i.AES=e.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var t=this._keyPriorReset=this._key,e=t.words,i=t.sigBytes/4,r=4*((this._nRounds=i+6)+1),o=this._keySchedule=[],s=0;s<r;s++)if(s<i)o[s]=e[s];else{var a=o[s-1];s%i?i>6&&s%i==4&&(a=n[a>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=f[s/i|0]<<24),o[s]=o[s-i]^a}for(var l=this._invKeySchedule=[],c=0;c<r;c++)s=r-c,a=c%4?o[s]:o[s-4],l[c]=c<4||s<=4?a:h[n[a>>>24]]^u[n[a>>>16&255]]^d[n[a>>>8&255]]^p[n[255&a]]}},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,l,c,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,h,u,d,p,o),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,r,n,o,s,a){for(var l=this._nRounds,c=t[e]^i[0],h=t[e+1]^i[1],u=t[e+2]^i[2],d=t[e+3]^i[3],p=4,f=1;f<l;f++){var y=r[c>>>24]^n[h>>>16&255]^o[u>>>8&255]^s[255&d]^i[p++],v=r[h>>>24]^n[u>>>16&255]^o[d>>>8&255]^s[255&c]^i[p++],g=r[u>>>24]^n[d>>>16&255]^o[c>>>8&255]^s[255&h]^i[p++],m=r[d>>>24]^n[c>>>16&255]^o[h>>>8&255]^s[255&u]^i[p++];c=y,h=v,u=g,d=m}y=(a[c>>>24]<<24|a[h>>>16&255]<<16|a[u>>>8&255]<<8|a[255&d])^i[p++],v=(a[h>>>24]<<24|a[u>>>16&255]<<16|a[d>>>8&255]<<8|a[255&c])^i[p++],g=(a[u>>>24]<<24|a[d>>>16&255]<<16|a[c>>>8&255]<<8|a[255&h])^i[p++],m=(a[d>>>24]<<24|a[c>>>16&255]<<16|a[h>>>8&255]<<8|a[255&u])^i[p++],t[e]=y,t[e+1]=v,t[e+2]=g,t[e+3]=m},keySize:8});t.AES=e._createHelper(y)}(),r.AES)},function(t,e,i){var r,n,o,s,a,l,c,h;t.exports=(r=i(0),i(9),i(10),o=(n=r).lib,s=o.Base,a=o.WordArray,l=n.algo,c=l.MD5,h=l.EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:c,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var i=this.cfg,r=i.hasher.create(),n=a.create(),o=n.words,s=i.keySize,l=i.iterations;o.length<s;){c&&r.update(c);var c=r.update(t).finalize(e);r.reset();for(var h=1;h<l;h++)c=r.finalize(c),r.reset();n.concat(c)}return n.sigBytes=4*s,n}}),n.EvpKDF=function(t,e,i){return h.create(i).compute(t,e)},r.EvpKDF)},function(t,e,i){(function(r,n){var o,s,a;s=[],void 0===(a="function"==typeof(o=function(){return function(){"use strict";var t=Object.prototype.hasOwnProperty,e={copyProperties:function(t,e){var i;for(i in t)e[i]=t[i]},resolveTransformObject:function(t,i,r){var n,o;if("number"!=typeof r&&(r=0),++r>=10)return t;for(n in t)"string"==typeof t[n]&&0===t[n].indexOf("[%lktxp]")?(o=t[n].substring(8),i.hasOwnProperty(o)&&(t[n]=i[o])):"object"==typeof t[n]&&(t[n]=e.resolveTransformObject(t[n],i,r));return t},resolveTransformParams:function(t,i){var r,n,o=[];if(void 0===i)return t;for(r=0;r<t.length;r++)n=y(t[r],"shallow-recurse-objects"),o.push(e.resolveTransformObject(n,i));return o}},o={aeq:s,lt:a,gt:l};function s(t,e){var i,r,n,o;if(t===e)return!0;if(!t||!e||!0===t||!0===e||t!=t||e!=e){switch(t){case void 0:case null:n=1;break;case!1:n=3;break;case!0:n=4;break;case"":n=5;break;default:n=t==t?9:0}switch(e){case void 0:case null:o=1;break;case!1:o=3;break;case!0:o=4;break;case"":o=5;break;default:o=e==e?9:0}if(9!==n||9!==o)return n===o}return i=Number(t),r=Number(e),i==i||r==r?i===r:(i=t.toString(),r=e.toString(),i==r)}function a(t,e,i){var r,n,o,s;if(!t||!e||!0===t||!0===e||t!=t||e!=e){switch(t){case void 0:case null:o=1;break;case!1:o=3;break;case!0:o=4;break;case"":o=5;break;default:o=t==t?9:0}switch(e){case void 0:case null:s=1;break;case!1:s=3;break;case!0:s=4;break;case"":s=5;break;default:s=e==e?9:0}if(9!==o||9!==s)return o===s?i:o<s}return r=Number(t),n=Number(e),r==r&&n==n?r<n||!(r>n)&&i:r==r&&n!=n||(n!=n||r==r)&&(t<e||!(t>e)&&(t==e?i:(r=t.toString(),n=e.toString(),r<n||r==n&&i)))}function l(t,e,i){var r,n,o,s;if(!t||!e||!0===t||!0===e||t!=t||e!=e){switch(t){case void 0:case null:o=1;break;case!1:o=3;break;case!0:o=4;break;case"":o=5;break;default:o=t==t?9:0}switch(e){case void 0:case null:s=1;break;case!1:s=3;break;case!0:s=4;break;case"":s=5;break;default:s=e==e?9:0}if(9!==o||9!==s)return o===s?i:o>s}return r=Number(t),n=Number(e),r==r&&n==n?r>n||!(r<n)&&i:(r!=r||n==n)&&(n==n&&r!=r||t>e||!(t<e)&&(t==e?i:(r=t.toString(),n=e.toString(),r>n||r==n&&i)))}function c(t,e,i){return o.aeq(t,e)?0:o.lt(t,e,!1)?i?1:-1:o.gt(t,e,!1)?i?-1:1:0}function h(e,i,r,n,o){var s=o||0,a=i[s];if(null==e||!t.call(e,a))return!1;var l=!1,c=e[a];if(s+1>=i.length)l=r(c,n);else if(Array.isArray(c))for(var u=0,d=c.length;u<d&&!0!==(l=h(c[u],i,r,n,s+1));u+=1);else l=h(c,i,r,n,s+1);return l}function u(e){return"string"==typeof e||Array.isArray(e)?function(t){return-1!==e.indexOf(t)}:"object"==typeof e&&null!==e?function(i){return t.call(e,i)}:null}function d(e,i){for(var r in i)if(t.call(i,r))return p[r](e,i[r]);return!1}var p={$eq:function(t,e){return t===e},$aeq:function(t,e){return t==e},$ne:function(t,e){return e!=e?t==t:t!==e},$dteq:function(t,e){return o.aeq(t,e)},$gt:function(t,e){return o.gt(t,e,!1)},$gte:function(t,e){return o.gt(t,e,!0)},$lt:function(t,e){return o.lt(t,e,!1)},$lte:function(t,e){return o.lt(t,e,!0)},$jgt:function(t,e){return t>e},$jgte:function(t,e){return t>=e},$jlt:function(t,e){return t<e},$jlte:function(t,e){return t<=e},$between:function(t,e){return null!=t&&o.gt(t,e[0],!0)&&o.lt(t,e[1],!0)},$jbetween:function(t,e){return null!=t&&t>=e[0]&&t<=e[1]},$in:function(t,e){return-1!==e.indexOf(t)},$nin:function(t,e){return-1===e.indexOf(t)},$keyin:function(t,e){return t in e},$nkeyin:function(t,e){return!(t in e)},$definedin:function(t,e){return void 0!==e[t]},$undefinedin:function(t,e){return void 0===e[t]},$regex:function(t,e){return e.test(t)},$containsString:function(t,e){return"string"==typeof t&&-1!==t.indexOf(e)},$containsNone:function(t,e){return!p.$containsAny(t,e)},$containsAny:function(t,e){var i=u(t);return null!==i&&(Array.isArray(e)?e.some(i):i(e))},$contains:function(t,e){var i=u(t);return null!==i&&(Array.isArray(e)?e.every(i):i(e))},$type:function(t,e){var i=typeof t;return"object"===i&&(Array.isArray(t)?i="array":t instanceof Date&&(i="date")),"object"!=typeof e?i===e:d(i,e)},$finite:function(t,e){return e===isFinite(t)},$size:function(t,e){return!!Array.isArray(t)&&("object"!=typeof e?t.length===e:d(t.length,e))},$len:function(t,e){return"string"==typeof t&&("object"!=typeof e?t.length===e:d(t.length,e))},$where:function(t,e){return!0===e(t)},$not:function(t,e){return!d(t,e)},$and:function(t,e){for(var i=0,r=e.length;i<r;i+=1)if(!d(t,e[i]))return!1;return!0},$or:function(t,e){for(var i=0,r=e.length;i<r;i+=1)if(d(t,e[i]))return!0;return!1}},f={$eq:p.$eq,$aeq:!0,$dteq:!0,$gt:!0,$gte:!0,$lt:!0,$lte:!0,$in:!0,$between:!0};function y(t,e){if(null==t)return null;var i,r=e||"parse-stringify";switch(r){case"parse-stringify":i=JSON.parse(JSON.stringify(t));break;case"jquery-extend-deep":i=jQuery.extend(!0,{},t);break;case"shallow":i=Object.create(t.constructor.prototype),Object.keys(t).map(function(e){i[e]=t[e]});break;case"shallow-assign":i=Object.create(t.constructor.prototype),Object.assign(i,t);break;case"shallow-recurse-objects":i=y(t,"shallow");var n=Object.keys(t);n.forEach(function(e){"object"==typeof t[e]&&"Object"===t[e].constructor.name&&(i[e]=y(t[e],"shallow-recurse-objects"))})}return i}function v(){try{return window&&void 0!==window.localStorage&&null!==window.localStorage}catch(t){return!1}}function g(){}function m(t,e){this.filename=t||"loki.db",this.collections=[],this.databaseVersion=1.5,this.engineVersion=1.5,this.autosave=!1,this.autosaveInterval=5e3,this.autosaveHandle=null,this.throttledSaves=!0,this.options={},this.persistenceMethod=null,this.persistenceAdapter=null,this.throttledSavePending=!1,this.throttledCallbacks=[],this.verbose=!(!e||!e.hasOwnProperty("verbose"))&&e.verbose,this.events={init:[],loaded:[],flushChanges:[],close:[],changes:[],warning:[]},e&&e.hasOwnProperty("env")?this.ENV=e.env:this.ENV=void 0!==r&&(r.android||r.NSObject)?"NATIVESCRIPT":"undefined"==typeof window?"NODEJS":void 0!==r&&r.window&&n?"NODEJS":"undefined"!=typeof document?-1===document.URL.indexOf("http://")&&-1===document.URL.indexOf("https://")?"CORDOVA":"BROWSER":"CORDOVA","undefined"===this.ENV&&(this.ENV="NODEJS"),this.configureOptions(e,!0),this.on("init",this.clearChanges)}function b(t){this.hashStore={},this.options=t||{},this.options.hasOwnProperty("asyncResponses")||(this.options.asyncResponses=!1),this.options.hasOwnProperty("asyncTimeout")||(this.options.asyncTimeout=50)}function w(t,e){if(this.mode="reference",this.adapter=null,this.options=e||{},this.dbref=null,this.dbname="",this.pageIterator={},!t)throw new Error("LokiPartitioningAdapter requires a (non-reference mode) adapter on construction");if("reference"===t.mode)throw new Error("LokiPartitioningAdapter cannot be instantiated with a reference mode adapter");this.adapter=t,this.options.hasOwnProperty("paging")||(this.options.paging=!1),this.options.hasOwnProperty("pageSize")||(this.options.pageSize=26214400),this.options.hasOwnProperty("delimiter")||(this.options.delimiter="$<\n")}function x(){try{this.fs=i(!function(){var t=new Error("Cannot find module 'fs'");throw t.code="MODULE_NOT_FOUND",t}())}catch(t){this.fs=null}}function I(){}function k(t,e){return e=e||{},this.collection=t,this.filteredrows=[],this.filterInitialized=!1,this}function O(t,e,i){this.collection=t,this.name=e,this.rebuildPending=!1,this.options=i||{},this.options.hasOwnProperty("persistent")||(this.options.persistent=!1),this.options.hasOwnProperty("sortPriority")||(this.options.sortPriority="passive"),this.options.hasOwnProperty("minRebuildInterval")||(this.options.minRebuildInterval=1),this.resultset=new k(t),this.resultdata=[],this.resultsdirty=!1,this.cachedresultset=null,this.filterPipeline=[],this.sortFunction=null,this.sortCriteria=null,this.sortCriteriaSimple=null,this.sortDirty=!1,this.events={rebuild:[]}}function S(e,i){this.name=e,this.data=[],this.idIndex=[],this.binaryIndices={},this.constraints={unique:{},exact:{}},this.uniqueNames=[],this.transforms={},this.objType=e,this.dirty=!0,this.cachedIndex=null,this.cachedBinaryIndex=null,this.cachedData=null;var r=this;(i=i||{}).hasOwnProperty("unique")&&(Array.isArray(i.unique)||(i.unique=[i.unique]),i.unique.forEach(function(t){r.uniqueNames.push(t),r.constraints.unique[t]=new B(t)})),i.hasOwnProperty("exact")&&i.exact.forEach(function(t){r.constraints.exact[t]=new j(t)}),this.adaptiveBinaryIndices=!i.hasOwnProperty("adaptiveBinaryIndices")||i.adaptiveBinaryIndices,this.transactional=!!i.hasOwnProperty("transactional")&&i.transactional,this.cloneObjects=!!i.hasOwnProperty("clone")&&i.clone,this.cloneMethod=i.hasOwnProperty("cloneMethod")?i.cloneMethod:"parse-stringify",this.asyncListeners=!!i.hasOwnProperty("asyncListeners")&&i.asyncListeners,this.disableMeta=!!i.hasOwnProperty("disableMeta")&&i.disableMeta,this.disableChangesApi=!i.hasOwnProperty("disableChangesApi")||i.disableChangesApi,this.disableDeltaChangesApi=!i.hasOwnProperty("disableDeltaChangesApi")||i.disableDeltaChangesApi,this.disableChangesApi&&(this.disableDeltaChangesApi=!0),this.autoupdate=!!i.hasOwnProperty("autoupdate")&&i.autoupdate,this.serializableIndices=!i.hasOwnProperty("serializableIndices")||i.serializableIndices,this.ttl={age:null,ttlInterval:null,daemon:null},this.setTTL(i.ttl||-1,i.ttlInterval),this.maxId=0,this.DynamicViews=[],this.events={insert:[],update:[],"pre-insert":[],"pre-update":[],close:[],flushbuffer:[],error:[],delete:[],warning:[]},this.changes=[],this.ensureId();var n=[];if(i&&i.indices)if("[object Array]"===Object.prototype.toString.call(i.indices))n=i.indices;else{if("string"!=typeof i.indices)throw new TypeError("Indices needs to be a string or an array of strings");n=[i.indices]}for(var o=0;o<n.length;o++)this.ensureIndex(n[o]);function s(t,e){var i=null!==e&&"object"==typeof e?Object.keys(e):null;if(i&&i.length&&["string","boolean","number"].indexOf(typeof e)<0){for(var n={},o=0;o<i.length;o++){var a=i[o];if(e.hasOwnProperty(a))if(!t.hasOwnProperty(a)||r.uniqueNames.indexOf(a)>=0||"$loki"==a||"meta"==a)n[a]=e[a];else{var l=s(t[a],e[a]);void 0!==l&&l!={}&&(n[a]=l)}}return 0===Object.keys(n).length?void 0:n}return t===e?void 0:e}function a(){r.changes=[]}this.observerCallback=function(e){var i="function"==typeof Set?new Set:[];i.add||(i.add=function(t){return-1===this.indexOf(t)&&this.push(t),this}),e.forEach(function(t){i.add(t.object)}),i.forEach(function(e){if(!t.call(e,"$loki"))return r.removeAutoUpdateObserver(e);try{r.update(e)}catch(t){}})},this.getChangeDelta=function(t,e){return e?s(e,t):JSON.parse(JSON.stringify(t))},this.getObjectDelta=s,this.getChanges=function(){return r.changes},this.flushChanges=a,this.setChangesApi=function(t){r.disableChangesApi=!t,t||(r.disableDeltaChangesApi=!1)},this.on("delete",function(t){r.disableChangesApi||r.createChange(r.name,"R",t)}),this.on("warning",function(t){r.console.warn(t)}),a()}function D(t){return-1!==t.indexOf(".")}function C(t){return parseFloat(t,10)}function A(t,e){return t+e}function P(t,e){return t-e}function E(t){return t.reduce(A,0)/t.length}function _(t,e,i){if(!1===i)return t[e];for(var r=e.split("."),n=t;r.length>0;)n=n[r.shift()];return n}function M(t,e,i){for(var r,n,o=0,s=t.length;o<s;){if(n=o+s>>1,0===(r=i.apply(null,[e,t[n]])))return{found:!0,index:n};r<0?s=n:o=n+1}return{found:!1,index:s}}function $(t){return function(e,i){return M(e,i,t)}}function z(){}function B(t){this.field=t,this.keyMap={},this.lokiMap={}}function j(t){this.index={},this.field=t}return g.prototype.events={},g.prototype.asyncListeners=!1,g.prototype.on=function(t,e){var i,r=this;return Array.isArray(t)?(t.forEach(function(t){r.on(t,e)}),e):((i=this.events[t])||(i=this.events[t]=[]),i.push(e),e)},g.prototype.emit=function(t){var e=this,i=Array.prototype.slice.call(arguments,1);if(!t||!this.events[t])throw new Error("No event "+t+" defined");this.events[t].forEach(function(t){e.asyncListeners?setTimeout(function(){t.apply(e,i)},1):t.apply(e,i)})},g.prototype.addListener=g.prototype.on,g.prototype.removeListener=function(t,e){var i=this;if(Array.isArray(t))t.forEach(function(t){i.removeListener(t,e)});else if(this.events[t]){var r=this.events[t];r.splice(r.indexOf(e),1)}},m.prototype=new g,m.prototype.constructor=m,m.prototype.getIndexedAdapter=function(){return i(6)},m.prototype.configureOptions=function(t,e){var i={fs:x,localStorage:I,memory:b};if(this.options={},this.persistenceMethod=null,this.persistenceAdapter=null,void 0!==t){if(this.options=t,this.options.hasOwnProperty("persistenceMethod")&&"function"==typeof i[t.persistenceMethod]&&(this.persistenceMethod=t.persistenceMethod,this.persistenceAdapter=new i[t.persistenceMethod]),this.options.hasOwnProperty("adapter")&&(this.persistenceMethod="adapter",this.persistenceAdapter=t.adapter,this.options.adapter=null),t.autoload&&e){var r=this;setTimeout(function(){r.loadDatabase(t,t.autoloadCallback)},1)}this.options.hasOwnProperty("autosaveInterval")&&(this.autosaveDisable(),this.autosaveInterval=parseInt(this.options.autosaveInterval,10)),this.options.hasOwnProperty("autosave")&&this.options.autosave&&(this.autosaveDisable(),this.autosave=!0,this.options.hasOwnProperty("autosaveCallback")?this.autosaveEnable(t,t.autosaveCallback):this.autosaveEnable()),this.options.hasOwnProperty("throttledSaves")&&(this.throttledSaves=this.options.throttledSaves)}this.options.hasOwnProperty("serializationMethod")||(this.options.serializationMethod="normal"),this.options.hasOwnProperty("destructureDelimiter")||(this.options.destructureDelimiter="$<\n"),null===this.persistenceAdapter&&(this.persistenceMethod={NODEJS:"fs",BROWSER:"localStorage",CORDOVA:"localStorage",MEMORY:"memory"}[this.ENV],this.persistenceMethod&&(this.persistenceAdapter=new i[this.persistenceMethod]))},m.prototype.copy=function(t){var e,i,r=new m(this.filename,{env:"NA"});if(t=t||{},r.loadJSONObject(this,{retainDirtyFlags:!0}),t.hasOwnProperty("removeNonSerializable")&&!0===t.removeNonSerializable)for(r.autosaveHandle=null,r.persistenceAdapter=null,e=r.collections.length,i=0;i<e;i++)r.collections[i].constraints=null,r.collections[i].ttl=null;return r},m.prototype.addCollection=function(t,e){var i,r=this.collections.length;if(e&&!0===e.disableMeta){if(!1===e.disableChangesApi)throw new Error("disableMeta option cannot be passed as true when disableChangesApi is passed as false");if(!1===e.disableDeltaChangesApi)throw new Error("disableMeta option cannot be passed as true when disableDeltaChangesApi is passed as false");if("number"==typeof e.ttl&&e.ttl>0)throw new Error("disableMeta option cannot be passed as true when ttl is enabled")}for(i=0;i<r;i+=1)if(this.collections[i].name===t)return this.collections[i];var n=new S(t,e);return this.collections.push(n),this.verbose&&(n.console=console),n},m.prototype.loadCollection=function(t){if(!t.name)throw new Error("Collection must have a name property to be loaded");this.collections.push(t)},m.prototype.getCollection=function(t){var e,i=this.collections.length;for(e=0;e<i;e+=1)if(this.collections[e].name===t)return this.collections[e];return this.emit("warning","collection "+t+" not found"),null},m.prototype.renameCollection=function(t,e){var i=this.getCollection(t);return i&&(i.name=e),i},m.prototype.listCollections=function(){for(var t=this.collections.length,e=[];t--;)e.push({name:this.collections[t].name,type:this.collections[t].objType,count:this.collections[t].data.length});return e},m.prototype.removeCollection=function(t){var e,i=this.collections.length;for(e=0;e<i;e+=1)if(this.collections[e].name===t){var r=new S(t,{}),n=this.collections[e];for(var o in n)n.hasOwnProperty(o)&&r.hasOwnProperty(o)&&(n[o]=r[o]);return void this.collections.splice(e,1)}},m.prototype.getName=function(){return this.name},m.prototype.serializeReplacer=function(t,e){switch(t){case"autosaveHandle":case"persistenceAdapter":case"constraints":case"ttl":return null;case"throttledSavePending":case"throttledCallbacks":return;default:return e}},m.prototype.serialize=function(t){switch((t=t||{}).hasOwnProperty("serializationMethod")||(t.serializationMethod=this.options.serializationMethod),t.serializationMethod){case"normal":return JSON.stringify(this,this.serializeReplacer);case"pretty":return JSON.stringify(this,this.serializeReplacer,2);case"destructured":return this.serializeDestructured();default:return JSON.stringify(this,this.serializeReplacer)}},m.prototype.toJson=m.prototype.serialize,m.prototype.serializeDestructured=function(t){var e,i,r,n,o,s=[];if((t=t||{}).hasOwnProperty("partitioned")||(t.partitioned=!1),t.hasOwnProperty("delimited")||(t.delimited=!0),t.hasOwnProperty("delimiter")||(t.delimiter=this.options.destructureDelimiter),!0===t.partitioned&&t.hasOwnProperty("partition")&&t.partition>=0)return this.serializeCollection({delimited:t.delimited,delimiter:t.delimiter,collectionIndex:t.partition});for((o=new m(this.filename)).loadJSONObject(this),e=0;e<o.collections.length;e++)o.collections[e].data=[];if(!0===t.partitioned&&-1===t.partition)return o.serialize({serializationMethod:"normal"});for(s.push(o.serialize({serializationMethod:"normal"})),o=null,e=0;e<this.collections.length;e++)if(r=this.serializeCollection({delimited:t.delimited,delimiter:t.delimiter,collectionIndex:e}),!1===t.partitioned&&!1===t.delimited){if(!Array.isArray(r))throw new Error("a nondelimited, non partitioned collection serialization did not return an expected array");for(n=r.length,i=0;i<n;i++)s.push(r[i]),r[i]=null;s.push("")}else s.push(r);return t.partitioned?(t.delimited,s):t.delimited?(s.push(""),s.join(t.delimiter)):(s.push(""),s)},m.prototype.serializeCollection=function(t){var e,i,r=[];if((t=t||{}).hasOwnProperty("delimited")||(t.delimited=!0),!t.hasOwnProperty("collectionIndex"))throw new Error("serializeCollection called without 'collectionIndex' option");for(e=this.collections[t.collectionIndex].data.length,r=[],i=0;i<e;i++)r.push(JSON.stringify(this.collections[t.collectionIndex].data[i]));return t.delimited?(r.push(""),r.join(t.delimiter)):r},m.prototype.deserializeDestructured=function(t,e){var i,r,n,o=[],s=0,a=1,l=!1;if((e=e||{}).hasOwnProperty("partitioned")||(e.partitioned=!1),e.hasOwnProperty("delimited")||(e.delimited=!0),e.hasOwnProperty("delimiter")||(e.delimiter=this.options.destructureDelimiter),e.partitioned){if(e.hasOwnProperty("partition"))return-1===e.partition?i=JSON.parse(t[0]):this.deserializeCollection(t[e.partition+1],e);for(i=JSON.parse(t[0]),r=i.collections.length,s=0;s<r;s++)i.collections[s].data=this.deserializeCollection(t[s+1],e);return i}if(e.delimited){if(o=t.split(e.delimiter),t=null,0===o.length)return null}else o=t;for(i=JSON.parse(o[0]),r=i.collections.length,o[0]=null;!l;)o[a],""===o[a]?++s>r&&(l=!0):(n=JSON.parse(o[a]),i.collections[s].data.push(n)),o[a++]=null;return i},m.prototype.deserializeCollection=function(t,e){var i,r,n=[];for((e=e||{}).hasOwnProperty("partitioned")||(e.partitioned=!1),e.hasOwnProperty("delimited")||(e.delimited=!0),e.hasOwnProperty("delimiter")||(e.delimiter=this.options.destructureDelimiter),e.delimited?(n=t.split(e.delimiter)).pop():n=t,r=n.length,i=0;i<r;i++)n[i]=JSON.parse(n[i]);return n},m.prototype.loadJSON=function(t,e){var i;if(0===t.length)i={};else switch(this.options.serializationMethod){case"normal":case"pretty":i=JSON.parse(t);break;case"destructured":i=this.deserializeDestructured(t);break;default:i=JSON.parse(t)}this.loadJSONObject(i,e)},m.prototype.loadJSONObject=function(t,i){var r,n,o,s,a,l,c=0,h=t.collections?t.collections.length:0;function u(t){var r,n=i[t.name];return n.proto?(r=n.inflate||e.copyProperties,function(t){var e=new n.proto;return r(t,e),e}):n.inflate}for(this.name=t.name,t.hasOwnProperty("throttledSaves")&&i&&!i.hasOwnProperty("throttledSaves")&&(this.throttledSaves=t.throttledSaves),this.collections=[];c<h;c+=1){if(r=t.collections[c],(n=this.addCollection(r.name,{disableChangesApi:r.disableChangesApi,disableDeltaChangesApi:r.disableDeltaChangesApi,disableMeta:r.disableMeta})).adaptiveBinaryIndices=!!r.hasOwnProperty("adaptiveBinaryIndices")&&!0===r.adaptiveBinaryIndices,n.transactional=r.transactional,n.asyncListeners=r.asyncListeners,n.cloneObjects=r.cloneObjects,n.cloneMethod=r.cloneMethod||"parse-stringify",n.autoupdate=r.autoupdate,n.changes=r.changes,i&&!0===i.retainDirtyFlags?n.dirty=r.dirty:n.dirty=!1,o=r.data.length,s=0,i&&i.hasOwnProperty(r.name))for(a=u(r);s<o;s++)l=a(r.data[s]),n.data[s]=l,n.addAutoUpdateObserver(l);else for(;s<o;s++)n.data[s]=r.data[s],n.addAutoUpdateObserver(n.data[s]);if(n.maxId=void 0===r.maxId?0:r.maxId,n.idIndex=r.idIndex,void 0!==r.binaryIndices&&(n.binaryIndices=r.binaryIndices),void 0!==r.transforms&&(n.transforms=r.transforms),n.ensureId(),n.uniqueNames=[],r.hasOwnProperty("uniqueNames"))for(n.uniqueNames=r.uniqueNames,s=0;s<n.uniqueNames.length;s++)n.ensureUniqueIndex(n.uniqueNames[s]);if(void 0!==r.DynamicViews){for(var d=0;d<r.DynamicViews.length;d++){var p=r.DynamicViews[d],f=n.addDynamicView(p.name,p.options);f.resultdata=p.resultdata,f.resultsdirty=p.resultsdirty,f.filterPipeline=p.filterPipeline,f.sortCriteria=p.sortCriteria,f.sortFunction=null,f.sortDirty=p.sortDirty,f.resultset.filteredrows=p.resultset.filteredrows,f.resultset.filterInitialized=p.resultset.filterInitialized,f.rematerialize({removeWhereFilters:!0})}t.databaseVersion<1.5&&(n.ensureAllIndexes(!0),n.dirty=!0)}}},m.prototype.close=function(t){this.autosave&&(this.autosaveDisable(),this.autosaveDirty()&&(this.saveDatabase(t),t=void 0)),t&&this.on("close",t),this.emit("close")},m.prototype.generateChangesNotification=function(t){function e(t){return t.name}var i=[],r=t||this.collections.map(e);return this.collections.forEach(function(t){-1!==r.indexOf(e(t))&&(i=i.concat(t.getChanges()))}),i},m.prototype.serializeChanges=function(t){return JSON.stringify(this.generateChangesNotification(t))},m.prototype.clearChanges=function(){this.collections.forEach(function(t){t.flushChanges&&t.flushChanges()})},b.prototype.loadDatabase=function(t,e){var i=this;this.options.asyncResponses?setTimeout(function(){i.hashStore.hasOwnProperty(t)?e(i.hashStore[t].value):e(null)},this.options.asyncTimeout):this.hashStore.hasOwnProperty(t)?e(this.hashStore[t].value):e(null)},b.prototype.saveDatabase=function(t,e,i){var r,n=this;this.options.asyncResponses?setTimeout(function(){r=n.hashStore.hasOwnProperty(t)?n.hashStore[t].savecount:0,n.hashStore[t]={savecount:r+1,lastsave:new Date,value:e},i()},this.options.asyncTimeout):(r=this.hashStore.hasOwnProperty(t)?this.hashStore[t].savecount:0,this.hashStore[t]={savecount:r+1,lastsave:new Date,value:e},i())},b.prototype.deleteDatabase=function(t,e){this.hashStore.hasOwnProperty(t)&&delete this.hashStore[t],"function"==typeof e&&e()},w.prototype.loadDatabase=function(t,e){var i=this;this.dbname=t,this.dbref=new m(t),this.adapter.loadDatabase(t,function(t){if(t){"string"!=typeof t&&e(new Error("LokiPartitioningAdapter received an unexpected response from inner adapter loadDatabase()"));var r=JSON.parse(t);i.dbref.loadJSONObject(r),r=null,i.dbref.collections.length,0!==i.dbref.collections.length?(i.pageIterator={collection:0,pageIndex:0},i.loadNextPartition(0,function(){e(i.dbref)})):e(i.dbref)}else e(t)})},w.prototype.loadNextPartition=function(t,e){var i=this.dbname+"."+t,r=this;if(!0===this.options.paging)return this.pageIterator.pageIndex=0,void this.loadNextPage(e);this.adapter.loadDatabase(i,function(i){var n=r.dbref.deserializeCollection(i,{delimited:!0,collectionIndex:t});r.dbref.collections[t].data=n,++t<r.dbref.collections.length?r.loadNextPartition(t,e):e()})},w.prototype.loadNextPage=function(t){var e=this.dbname+"."+this.pageIterator.collection+"."+this.pageIterator.pageIndex,i=this;this.adapter.loadDatabase(e,function(e){var r=e.split(i.options.delimiter);e="";var n,o=r.length,s=""===r[o-1];for(s&&(r.pop(),o=r.length,""===r[o-1]&&1===o&&(r.pop(),o=r.length)),n=0;n<o;n++)i.dbref.collections[i.pageIterator.collection].data.push(JSON.parse(r[n])),r[n]=null;r=[],s?++i.pageIterator.collection<i.dbref.collections.length?i.loadNextPartition(i.pageIterator.collection,t):t():(i.pageIterator.pageIndex++,i.loadNextPage(t))})},w.prototype.exportDatabase=function(t,e,i){var r,n=e.collections.length;for(this.dbref=e,this.dbname=t,this.dirtyPartitions=[-1],r=0;r<n;r++)e.collections[r].dirty&&this.dirtyPartitions.push(r);this.saveNextPartition(function(t){i(t)})},w.prototype.saveNextPartition=function(t){var e=this,i=this.dirtyPartitions.shift(),r=this.dbname+(-1===i?"":"."+i);if(this.options.paging&&-1!==i)return this.pageIterator={collection:i,docIndex:0,pageIndex:0},void this.saveNextPage(function(i){0===e.dirtyPartitions.length?t(i):e.saveNextPartition(t)});var n=this.dbref.serializeDestructured({partitioned:!0,delimited:!0,partition:i});this.adapter.saveDatabase(r,n,function(i){i?t(i):0===e.dirtyPartitions.length?t(null):e.saveNextPartition(t)})},w.prototype.saveNextPage=function(t){var e=this,i=this.dbref.collections[this.pageIterator.collection],r=this.dbname+"."+this.pageIterator.collection+"."+this.pageIterator.pageIndex,n=0,o=i.data.length,s=this.options.delimiter.length,a="",l="",c=!1,h=!1,u=function(i){l="",i&&t(i),c?t(null):(e.pageIterator.pageIndex++,e.saveNextPage(t))};for(0===i.data.length&&(c=!0);;)if(c||(a=JSON.stringify(i.data[this.pageIterator.docIndex]),l+=a,n+=a.length,++this.pageIterator.docIndex>=o&&(c=!0)),n>=this.options.pageSize&&(h=!0),h&&!c||(l+=this.options.delimiter,n+=s),c||h)return void this.adapter.saveDatabase(r,l,u)},x.prototype.loadDatabase=function(t,e){var i=this;this.fs.stat(t,function(r,n){!r&&n.isFile()?i.fs.readFile(t,{encoding:"utf8"},function(t,i){e(t?new Error(t):i)}):e(null)})},x.prototype.saveDatabase=function(t,e,i){var r=this,n=t+"~";this.fs.writeFile(n,e,function(e){e?i(new Error(e)):r.fs.rename(n,t,i)})},x.prototype.deleteDatabase=function(t,e){this.fs.unlink(t,function(t){t?e(new Error(t)):e()})},I.prototype.loadDatabase=function(t,e){v()?e(localStorage.getItem(t)):e(new Error("localStorage is not available"))},I.prototype.saveDatabase=function(t,e,i){v()?(localStorage.setItem(t,e),i(null)):i(new Error("localStorage is not available"))},I.prototype.deleteDatabase=function(t,e){v()?(localStorage.removeItem(t),e(null)):e(new Error("localStorage is not available"))},m.prototype.throttledSaveDrain=function(t,e){var i=this,r=(new Date).getTime();if(this.throttledSaves||t(!0),(e=e||{}).hasOwnProperty("recursiveWait")||(e.recursiveWait=!0),e.hasOwnProperty("recursiveWaitLimit")||(e.recursiveWaitLimit=!1),e.hasOwnProperty("recursiveWaitLimitDuration")||(e.recursiveWaitLimitDuration=2e3),e.hasOwnProperty("started")||(e.started=(new Date).getTime()),this.throttledSaves&&this.throttledSavePending){if(!e.recursiveWait)return void this.throttledCallbacks.push(t);this.throttledCallbacks.push(function(){return i.throttledSavePending?e.recursiveWaitLimit&&r-e.started>e.recursiveWaitLimitDuration?void t(!1):void i.throttledSaveDrain(t,e):void t(!0)})}else t(!0)},m.prototype.loadDatabaseInternal=function(t,e){var i=e||function(t,e){if(t)throw t},r=this;null!==this.persistenceAdapter?this.persistenceAdapter.loadDatabase(this.filename,function(e){if("string"==typeof e){var n=!1;try{r.loadJSON(e,t||{}),n=!0}catch(t){i(t)}n&&(i(null),r.emit("loaded","database "+r.filename+" loaded"))}else{if(!e)return i(null),void r.emit("loaded","empty database "+r.filename+" loaded");if(e instanceof Error)return void i(e);if("object"==typeof e)return r.loadJSONObject(e,t||{}),i(null),void r.emit("loaded","database "+r.filename+" loaded");i("unexpected adapter response : "+e)}}):i(new Error("persistenceAdapter not configured"))},m.prototype.loadDatabase=function(t,e){var i=this;this.throttledSaves?this.throttledSaveDrain(function(r){if(r)return i.throttledSavePending=!0,void i.loadDatabaseInternal(t,function(t){0===i.throttledCallbacks.length?i.throttledSavePending=!1:i.saveDatabase(),"function"==typeof e&&e(t)});"function"==typeof e&&e(new Error("Unable to pause save throttling long enough to read database"))},t):this.loadDatabaseInternal(t,e)},m.prototype.saveDatabaseInternal=function(t){var e=t||function(t){if(t)throw t},i=this;null!==this.persistenceAdapter?"reference"===this.persistenceAdapter.mode&&"function"==typeof this.persistenceAdapter.exportDatabase?this.persistenceAdapter.exportDatabase(this.filename,this.copy({removeNonSerializable:!0}),function(t){i.autosaveClearFlags(),e(t)}):(i.autosaveClearFlags(),this.persistenceAdapter.saveDatabase(this.filename,i.serialize(),function(t){e(t)})):e(new Error("persistenceAdapter not configured"))},m.prototype.saveDatabase=function(t){if(this.throttledSaves)if(this.throttledSavePending)this.throttledCallbacks.push(t);else{var e=this.throttledCallbacks;this.throttledCallbacks=[],e.unshift(t),this.throttledSavePending=!0;var i=this;this.saveDatabaseInternal(function(t){i.throttledSavePending=!1,e.forEach(function(e){"function"==typeof e&&setTimeout(function(){e(t)},1)}),i.throttledCallbacks.length>0&&i.saveDatabase()})}else this.saveDatabaseInternal(t)},m.prototype.save=m.prototype.saveDatabase,m.prototype.deleteDatabase=function(t,e){var i=e||function(t,e){if(t)throw t};"function"!=typeof t||e||(i=t),null!==this.persistenceAdapter?this.persistenceAdapter.deleteDatabase(this.filename,function(t){i(t)}):i(new Error("persistenceAdapter not configured"))},m.prototype.autosaveDirty=function(){for(var t=0;t<this.collections.length;t++)if(this.collections[t].dirty)return!0;return!1},m.prototype.autosaveClearFlags=function(){for(var t=0;t<this.collections.length;t++)this.collections[t].dirty=!1},m.prototype.autosaveEnable=function(t,e){this.autosave=!0;var i=5e3,r=this;void 0!==this.autosaveInterval&&null!==this.autosaveInterval&&(i=this.autosaveInterval),this.autosaveHandle=setInterval(function(){r.autosaveDirty()&&r.saveDatabase(e)},i)},m.prototype.autosaveDisable=function(){void 0!==this.autosaveHandle&&null!==this.autosaveHandle&&(clearInterval(this.autosaveHandle),this.autosaveHandle=null)},k.prototype.reset=function(){return this.filteredrows.length>0&&(this.filteredrows=[]),this.filterInitialized=!1,this},k.prototype.toJSON=function(){var t=this.copy();return t.collection=null,t},k.prototype.limit=function(t){this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex());var e=new k(this.collection);return e.filteredrows=this.filteredrows.slice(0,t),e.filterInitialized=!0,e},k.prototype.offset=function(t){this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex());var e=new k(this.collection);return e.filteredrows=this.filteredrows.slice(t),e.filterInitialized=!0,e},k.prototype.copy=function(){var t=new k(this.collection);return this.filteredrows.length>0&&(t.filteredrows=this.filteredrows.slice()),t.filterInitialized=this.filterInitialized,t},k.prototype.branch=k.prototype.copy,k.prototype.transform=function(t,i){var r,n,o=this;if("string"==typeof t&&this.collection.transforms.hasOwnProperty(t)&&(t=this.collection.transforms[t]),"object"!=typeof t||!Array.isArray(t))throw new Error("Invalid transform");for(void 0!==i&&(t=e.resolveTransformParams(t,i)),r=0;r<t.length;r++)switch((n=t[r]).type){case"find":o.find(n.value);break;case"where":o.where(n.value);break;case"simplesort":o.simplesort(n.property,n.desc||n.options);break;case"compoundsort":o.compoundsort(n.value);break;case"sort":o.sort(n.value);break;case"limit":o=o.limit(n.value);break;case"offset":o=o.offset(n.value);break;case"map":o=o.map(n.value,n.dataOptions);break;case"eqJoin":o=o.eqJoin(n.joinData,n.leftJoinKey,n.rightJoinKey,n.mapFun,n.dataOptions);break;case"mapReduce":o=o.mapReduce(n.mapFunction,n.reduceFunction);break;case"update":o.update(n.value);break;case"remove":o.remove()}return o},k.prototype.sort=function(t){this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex());var e,i,r=(e=t,i=this.collection.data,function(t,r){return e(i[t],i[r])});return this.filteredrows.sort(r),this},k.prototype.simplesort=function(t,e){var i,r=10,n=this.collection.data.length,o=this.filteredrows.length,s=this.collection.binaryIndices.hasOwnProperty(t);if(void 0!==e&&!1!==e||(e={desc:!1}),!0===e&&(e={desc:!0}),0===o){if(this.filterInitialized)return this;if(this.collection.binaryIndices.hasOwnProperty(t))return this.collection.ensureIndex(t),this.filteredrows=this.collection.binaryIndices[t].values.slice(0),e.desc&&this.filteredrows.reverse(),this;this.filteredrows=this.collection.prepareFullDocIndex()}else if(!e.disableIndexIntersect&&s&&(i=n/o,e.useJavascriptSorting&&(r=6),i<=r||e.forceIndexIntersect)){var a,l=this.filteredrows,h={};for(a=0;a<o;a++)h[l[a]]=!0;var u=this.collection.binaryIndices[t].values;return this.filteredrows=u.filter(function(t){return h[t]}),e.desc&&this.filteredrows.reverse(),this}if(e.useJavascriptSorting)return this.sort(function(e,i){return e[t]===i[t]?0:e[t]>i[t]?1:e[t]<i[t]?-1:void 0});var d,p,f,y,v,g,m=(d=t,p=e.desc,f=this.collection.data,function(t,e){return~d.indexOf(".")?(g=d.split("."),y=g.reduce(function(t,e){return t&&t[e]||void 0},f[t]),v=g.reduce(function(t,e){return t&&t[e]||void 0},f[e])):(y=f[t][d],v=f[e][d]),c(y,v,p)});return this.filteredrows.sort(m),this},k.prototype.compoundsort=function(t){if(0===t.length)throw new Error("Invalid call to compoundsort, need at least one property");var e;if(1===t.length)return e=t[0],Array.isArray(e)?this.simplesort(e[0],e[1]):this.simplesort(e,!1);for(var i=0,r=t.length;i<r;i+=1)e=t[i],Array.isArray(e)||(t[i]=[e,!1]);this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex());var n,o,s=(n=t,o=this.collection.data,function(t,e){return function(t,e,i){for(var r,n,o,s,a,l=0,h=0,u=t.length;h<u;h++)if(r=t[h],~(n=r[0]).indexOf(".")?(a=n.split("."),o=a.reduce(function(t,e){return t&&t[e]||void 0},e),s=a.reduce(function(t,e){return t&&t[e]||void 0},i)):(o=e[n],s=i[n]),0!==(l=c(o,s,r[1])))return l;return 0}(n,o[t],o[e])});return this.filteredrows.sort(s),this},k.prototype.findOr=function(t){for(var e=null,i=0,r=0,n=[],o=[],s=0,a=this.count(),l=0,c=t.length;l<c;l++){if(e=this.branch().find(t[l]).filteredrows,(r=e.length)===a)return this;for(i=0;i<r;i++)s=e[i],void 0===o[s]&&(o[s]=!0,n.push(s))}return this.filteredrows=n,this.filterInitialized=!0,this},k.prototype.$or=k.prototype.findOr,k.prototype.findAnd=function(t){for(var e=0,i=t.length;e<i;e++){if(0===this.count())return this;this.find(t[e])}return this},k.prototype.$and=k.prototype.findAnd,k.prototype.find=function(e,i){if(0===this.collection.data.length)return this.filteredrows=[],this.filterInitialized=!0,this;var r,n,o,s,a,l,c,u=e||"getAll",d=!1,y=[],v=[],g=null;if(i=i||!1,"object"==typeof u){for(r in u)(s={})[r]=u[r],v.push(s),t.call(u,r)&&(n=r,o=u[r]);if(v.length>1)return this.find({$and:v},i)}if(!n||"getAll"===u)return i&&(this.filteredrows=this.collection.data.length>0?[0]:[],this.filterInitialized=!0),this;if("$and"===n||"$or"===n)return this[n](o),i&&this.filteredrows.length>1&&(this.filteredrows=this.filteredrows.slice(0,1)),this;if(null===o||"object"!=typeof o||o instanceof Date)a="$eq",l=o;else{if("object"!=typeof o)throw new Error("Do not know what you want to do.");for(c in o)if(t.call(o,c)){a=c,l=o[c];break}}"$regex"===a&&(Array.isArray(l)?l=new RegExp(l[0],l[1]):l instanceof RegExp||(l=new RegExp(l)));var m=-1!==n.indexOf("."),b=!m&&!this.filterInitialized;b&&this.collection.binaryIndices[n]&&f[a]&&(!0!==this.collection.adaptiveBinaryIndices&&this.collection.ensureIndex(n),d=!0,g=this.collection.binaryIndices[n]);var w,x=p[a],I=this.collection.data,k=0,O=0,S=0;if(this.filterInitialized)if(w=this.filteredrows,O=w.length,m)for(n=n.split("."),k=0;k<O;k++)S=w[k],h(I[S],n,x,l)&&y.push(S);else for(k=0;k<O;k++)S=w[k],x(I[S][n],l)&&y.push(S);else if(d){var D=this.collection.calculateRange(a,n,l);if("$in"!==a){for(k=D[0];k<=D[1];k++)if(!0!==f[a]){if(f[a](I[g.values[k]][n],l)&&(y.push(g.values[k]),i))return this.filteredrows=y,this.filterInitialized=!0,this}else if(y.push(g.values[k]),i)return this.filteredrows=y,this.filterInitialized=!0,this}else for(k=0,O=D.length;k<O;k++)if(y.push(g.values[D[k]]),i)return this.filteredrows=y,this.filterInitialized=!0,this}else if(O=I.length,m){for(n=n.split("."),k=0;k<O;k++)if(h(I[k],n,x,l)&&(y.push(k),i))return this.filteredrows=y,this.filterInitialized=!0,this}else for(k=0;k<O;k++)if(x(I[k][n],l)&&(y.push(k),i))return this.filteredrows=y,this.filterInitialized=!0,this;return this.filteredrows=y,this.filterInitialized=!0,this},k.prototype.where=function(t){var e,i=[];if("function"!=typeof t)throw new TypeError("Argument is not a stored view or a function");e=t;try{if(this.filterInitialized){for(var r=this.filteredrows.length;r--;)!0===e(this.collection.data[this.filteredrows[r]])&&i.push(this.filteredrows[r]);return this.filteredrows=i,this}for(var n=this.collection.data.length;n--;)!0===e(this.collection.data[n])&&i.push(n);return this.filteredrows=i,this.filterInitialized=!0,this}catch(t){throw t}},k.prototype.count=function(){return this.filterInitialized?this.filteredrows.length:this.collection.count()},k.prototype.data=function(t){var e,i,r,n,o=[],s=this.collection.data;if((t=t||{}).removeMeta&&!t.forceClones&&(t.forceClones=!0,t.forceCloneMethod=t.forceCloneMethod||"shallow"),this.collection.disableDeltaChangesApi||(t.forceClones=!0,t.forceCloneMethod="parse-stringify"),!this.filterInitialized){if(0===this.filteredrows.length){if(this.collection.cloneObjects||t.forceClones){for(i=s.length,n=t.forceCloneMethod||this.collection.cloneMethod,r=0;r<i;r++)e=y(s[r],n),t.removeMeta&&(delete e.$loki,delete e.meta),o.push(e);return o}return s.slice()}this.filterInitialized=!0}var a=this.filteredrows;if(i=a.length,this.collection.cloneObjects||t.forceClones)for(n=t.forceCloneMethod||this.collection.cloneMethod,r=0;r<i;r++)e=y(s[a[r]],n),t.removeMeta&&(delete e.$loki,delete e.meta),o.push(e);else for(r=0;r<i;r++)o.push(s[a[r]]);return o},k.prototype.update=function(t){if("function"!=typeof t)throw new TypeError("Argument is not a function");this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex());for(var e,i=this.filteredrows.length,r=this.collection.data,n=0;n<i;n++)this.collection.cloneObjects||!this.collection.disableDeltaChangesApi?(e=y(r[this.filteredrows[n]],this.collection.cloneMethod),t(e),this.collection.update(e)):(t(r[this.filteredrows[n]]),this.collection.update(r[this.filteredrows[n]]));return this},k.prototype.remove=function(){return this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex()),this.collection.removeBatchByPositions(this.filteredrows),this.filteredrows=[],this},k.prototype.mapReduce=function(t,e){try{return e(this.data().map(t))}catch(t){throw t}},k.prototype.eqJoin=function(t,e,i,r,n){var o,s,a,l=[],c=[],h=[],u="function"==typeof e,d="function"==typeof i,p={};if(l=this.data(n),o=l.length,t instanceof S)c=t.chain().data(n);else if(t instanceof k)c=t.data(n);else{if(!Array.isArray(t))throw new TypeError("joinData needs to be an array or result set");c=t}s=c.length;for(var f=0;f<s;f++)a=d?i(c[f]):c[f][i],p[a]=c[f];r||(r=function(t,e){return{left:t,right:e}});for(var y=0;y<o;y++)a=u?e(l[y]):l[y][e],h.push(r(l[y],p[a]||{}));return this.collection=new S("joinData"),this.collection.insert(h),this.filteredrows=[],this.filterInitialized=!1,this},k.prototype.map=function(t,e){var i=this.data(e).map(t);return this.collection=new S("mappedData"),this.collection.insert(i),this.filteredrows=[],this.filterInitialized=!1,this},O.prototype=new g,O.prototype.rematerialize=function(t){var e,i,r;if(t=t||{},this.resultdata=[],this.resultsdirty=!0,this.resultset=new k(this.collection),(this.sortFunction||this.sortCriteria||this.sortCriteriaSimple)&&(this.sortDirty=!0),t.hasOwnProperty("removeWhereFilters"))for(e=this.filterPipeline.length,i=e;i--;)"where"===this.filterPipeline[i].type&&(i!==this.filterPipeline.length-1&&(this.filterPipeline[i]=this.filterPipeline[this.filterPipeline.length-1]),this.filterPipeline.length--);var n=this.filterPipeline;for(this.filterPipeline=[],e=n.length,r=0;r<e;r++)this.applyFind(n[r].val);return this.data(),this.emit("rebuild",this),this},O.prototype.branchResultset=function(t,e){var i=this.resultset.branch();return void 0===t?i:i.transform(t,e)},O.prototype.toJSON=function(){var t=new O(this.collection,this.name,this.options);return t.resultset=this.resultset,t.resultdata=[],t.resultsdirty=!0,t.filterPipeline=this.filterPipeline,t.sortFunction=this.sortFunction,t.sortCriteria=this.sortCriteria,t.sortCriteriaSimple=this.sortCriteriaSimple||null,t.sortDirty=this.sortDirty,t.collection=null,t},O.prototype.removeFilters=function(t){t=t||{},this.rebuildPending=!1,this.resultset.reset(),this.resultdata=[],this.resultsdirty=!0,this.cachedresultset=null,this.filterPipeline=[],this.sortFunction=null,this.sortCriteria=null,this.sortCriteriaSimple=null,this.sortDirty=!1,!0===t.queueSortPhase&&this.queueSortPhase()},O.prototype.applySort=function(t){return this.sortFunction=t,this.sortCriteria=null,this.sortCriteriaSimple=null,this.queueSortPhase(),this},O.prototype.applySimpleSort=function(t,e){return this.sortCriteriaSimple={propname:t,options:e||!1},this.sortCriteria=null,this.sortFunction=null,this.queueSortPhase(),this},O.prototype.applySortCriteria=function(t){return this.sortCriteria=t,this.sortCriteriaSimple=null,this.sortFunction=null,this.queueSortPhase(),this},O.prototype.startTransaction=function(){return this.cachedresultset=this.resultset.copy(),this},O.prototype.commit=function(){return this.cachedresultset=null,this},O.prototype.rollback=function(){return this.resultset=this.cachedresultset,this.options.persistent&&(this.resultdata=this.resultset.data(),this.emit("rebuild",this)),this},O.prototype._indexOfFilterWithId=function(t){if("string"==typeof t||"number"==typeof t)for(var e=0,i=this.filterPipeline.length;e<i;e+=1)if(t===this.filterPipeline[e].uid)return e;return-1},O.prototype._addFilter=function(t){this.filterPipeline.push(t),this.resultset[t.type](t.val)},O.prototype.reapplyFilters=function(){this.resultset.reset(),this.cachedresultset=null,this.options.persistent&&(this.resultdata=[],this.resultsdirty=!0);var t=this.filterPipeline;this.filterPipeline=[];for(var e=0,i=t.length;e<i;e+=1)this._addFilter(t[e]);return this.sortFunction||this.sortCriteria||this.sortCriteriaSimple?this.queueSortPhase():this.queueRebuildEvent(),this},O.prototype.applyFilter=function(t){var e=this._indexOfFilterWithId(t.uid);return e>=0?(this.filterPipeline[e]=t,this.reapplyFilters()):(this.cachedresultset=null,this.options.persistent&&(this.resultdata=[],this.resultsdirty=!0),this._addFilter(t),this.sortFun