forerunnerdb
Version:
A NoSQL document store database for browsers and Node.js.
47 lines • 564 kB
HTML
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for lib/fdb-all.min.js</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../prettify.css">
<link rel="stylesheet" href="../base.css">
<style type='text/css'>
div.coverage-summary .sorter {
background-image: url(../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class="header medium">
<h1>Code coverage report for <span class="entity">lib/fdb-all.min.js</span></h1>
<h2>
Statements: <span class="metric">52.32% <small>(2770 / 5294)</small></span>
Branches: <span class="metric">43.03% <small>(2444 / 5680)</small></span>
Functions: <span class="metric">52.8% <small>(895 / 1695)</small></span>
Lines: <span class="metric">100% <small>(10 / 10)</small></span>
Ignored: <span class="metric"><span class="ignore-none">none</span></span>
</h2>
<div class="path"><a href="../index.html">All files</a> » <a href="index.html">lib/</a> » fdb-all.min.js</div>
</div>
<div class="body">
<pre><table class="coverage">
<tr><td class="line-count">1
2
3
4
5
6
7
8
9
10</td><td class="line-coverage"><span class="cline-any cline-yes">105259</span>
<span class="cline-any cline-yes">153290</span>
<span class="cline-any cline-yes">383415</span>
<span class="cline-any cline-yes">569934</span>
<span class="cline-any cline-yes">412063</span>
<span class="cline-any cline-yes">364</span>
<span class="cline-any cline-yes">1118</span>
<span class="cline-any cline-yes">40776</span>
<span class="cline-any cline-yes">70520</span>
<span class="cline-any cline-yes">2933</span></td><td class="text"><pre class="prettyprint lang-js">!function a(b,c,d){function e(g,h){if(!c[g]){<span class="missing-if-branch" title="if path not taken" >I</span>if(!b[g]){<span class="cstat-no" title="statement not covered" >var i="function"==typeof require&&require;<span class="cstat-no" title="statement not covered" >i</span>f(!h&&i)<span class="cstat-no" title="statement not covered" >return i(g,!0);<span class="cstat-no" title="statement not covered" >i</span></span>f(f)<span class="cstat-no" title="statement not covered" >return f(g,!0);<span class="cstat-no" title="statement not covered" >v</span></span>ar j=new Error("Cannot find module '"+g+"'");<span class="cstat-no" title="statement not covered" >t</span>hrow j.code="MODULE_NOT_FOUND",j}</span>var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:<span class="branch-1 cbranch-no" title="branch not covered" >a)</span>},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){var d=a("./core");a("../lib/CollectionGroup"),a("../lib/View"),a("../lib/Highchart"),a("../lib/Persist"),a("../lib/Document"),a("../lib/Overview"),a("../lib/Grid"),a("../lib/NodeApiClient"),a("../lib/BinaryLog");"undefined"!=typeof window&&(window.ForerunnerDB=d),b.exports=d},{"../lib/BinaryLog":4,"../lib/CollectionGroup":8,"../lib/Document":11,"../lib/Grid":13,"../lib/Highchart":14,"../lib/NodeApiClient":30,"../lib/Overview":33,"../lib/Persist":35,"../lib/View":42,"./core":2}],2:[function(a,b,c){var d=a("../lib/Core");a("../lib/Shim.IE8");"undefined"!=typeof window&&(window.ForerunnerDB=d),b.exports=d},{"../lib/Core":9,"../lib/Shim.IE8":41}],3:[function(a,b,c){"use strict";var d,e=a("./Shared"),f=a("./Path"),g=function(a){this._primaryKey="_id",this._keyArr=[],this._data=[],this._objLookup={},this._count=0,this._keyArr=d.parse(a,!0)};e.addModule("ActiveBucket",g),e.mixin(g.prototype,"Mixin.Sorting"),d=new f,e.synthesize(g.prototype,"primaryKey"),g.prototype.qs=function(a,b,c,d){if(!b.length)return 0;for(var e,f,g,h=-1,i=0,j=b.length-1;j>=i&&(e=Math.floor((i+j)/2),h!==e);)f=b[e],void 0!==f&&(g=d(this,a,c,f),g>0&&(i=e+1),0>g&&(j=e-1)),h=e;return g>0?e+1:e},g.prototype._sortFunc=function(a,b,c,e){var f,g,h,i=c.split(".:."),j=e.split(".:."),k=a._keyArr,l=k.length;for(f=0;l>f;f++)if(g=k[f],h=typeof d.get(b,g.path),"number"===h&&(i[f]=Number(i[f]),j[f]=Number(j[f])),i[f]!==j[f]){if(1===g.value)return a.sortAsc(i[f],j[f]);<span class="missing-if-branch" title="else path not taken" >E</span>if(-1===g.value)return a.sortDesc(i[f],j[f])}},g.prototype.insert=function(a){var b,c;return b=this.documentKey(a),c=this._data.indexOf(b),-1===c?(c=this.qs(a,this._data,b,this._sortFunc),this._data.splice(c,0,b)):this._data.splice(c,0,b),this._objLookup[a[this._primaryKey]]=b,this._count++,c},g.prototype.remove=function(a){var b,c;return b=this._objLookup[a[this._primaryKey]],b?(c=this._data.indexOf(b),c>-1?(this._data.splice(c,1),delete this._objLookup[a[this._primaryKey]],this._count--,!0):<span class="branch-1 cbranch-no" title="branch not covered" >!1)</span>:!1},g.prototype.index=function(a){var b,c;return b=this.documentKey(a),c=this._data.indexOf(b),-1===c&&(<span class="branch-1 cbranch-no" title="branch not covered" >c=this.qs(a,this._data,b,this._sortFunc))</span>,c},g.prototype.documentKey=function(a){var b,c,e="",f=this._keyArr,g=f.length;for(b=0;g>b;b++)c=f[b],e&&(e+=".:."),e+=d.get(a,c.path);return e+=".:."+a[this._primaryKey]},g.prototype.count=function(){return this._count},e.finishModule("ActiveBucket"),b.exports=g},{"./Path":34,"./Shared":40}],4:[function(a,b,c){"use strict";var d,e,f,g,h,i,j;d=a("./Shared"),j=function(){this.init.apply(this,arguments)},j.prototype.init=function(a){var b=this;b._logCounter=0,b._parent=a,b.size(1e3)},d.addModule("BinaryLog",j),d.mixin(j.prototype,"Mixin.Common"),d.mixin(j.prototype,"Mixin.ChainReactor"),d.mixin(j.prototype,"Mixin.Events"),f=d.modules.Collection,h=d.modules.Db,e=d.modules.ReactorIO,g=f.prototype.init,i=h.prototype.init,d.synthesize(j.prototype,"name"),d.synthesize(j.prototype,"size"),j.prototype.attachIO=<span class="fstat-no" title="function not covered" >function(){<span class="cstat-no" title="statement not covered" ></span>var a=this;<span class="cstat-no" title="statement not covered" >a</span>._io||(a._log=new f(a._parent.name()+"-BinaryLog",{capped:!0,size:a.size()}),a._log.objectId=<span class="fstat-no" title="function not covered" >function(b){<span class="cstat-no" title="statement not covered" ></span>return b||(b=++a._logCounter),b}</span>,a._io=new e(a._parent,a,<span class="fstat-no" title="function not covered" >function(b){<span class="cstat-no" title="statement not covered" ></span>return a._log.insert({type:b.type,data:b.data}),!1}</span>))}</span>,j.prototype.detachIO=<span class="fstat-no" title="function not covered" >function(){<span class="cstat-no" title="statement not covered" ></span>var a=this;<span class="cstat-no" title="statement not covered" >a</span>._io&&(a._log.drop(),a._io.drop(),delete a._log,delete a._io)}</span>,f.prototype.init=function(){g.apply(this,arguments),this._binaryLog=new j(this)},d.finishModule("BinaryLog"),b.exports=j},{"./Shared":40}],5:[function(a,b,c){"use strict";var d=a("./Shared"),e=a("./Path"),f=new e,g=function(a,b,c){this.init.apply(this,arguments)};g.prototype.init=function(a,b,c,d,e){this._store=[],this._keys=[],void 0!==c&&<span class="branch-1 cbranch-no" title="branch not covered" >this.primaryKey(c),</span>void 0!==b&&this.index(b),void 0!==d&&this.compareFunc(d),void 0!==e&&this.hashFunc(e),void 0!==a&&this.data(a)},d.addModule("BinaryTree",g),d.mixin(g.prototype,"Mixin.ChainReactor"),d.mixin(g.prototype,"Mixin.Sorting"),d.mixin(g.prototype,"Mixin.Common"),d.synthesize(g.prototype,"compareFunc"),d.synthesize(g.prototype,"hashFunc"),d.synthesize(g.prototype,"indexDir"),d.synthesize(g.prototype,"primaryKey"),d.synthesize(g.prototype,"keys"),d.synthesize(g.prototype,"index",function(a){return void 0!==a&&(this.debug()&&<span class="branch-1 cbranch-no" title="branch not covered" >console.log("Setting index",a,f.parse(a,!0)),</span>this.keys(f.parse(a,!0))),this.$super.call(this,a)}),g.prototype.clear=function(){delete this._data,delete this._left,delete this._right,this._store=[]},g.prototype.data=function(a){return void 0!==a?(this._data=a,this._hashFunc&&(this._hash=this._hashFunc(a)),this):<span class="branch-1 cbranch-no" title="branch not covered" >this._data}</span>,g.prototype.push=<span class="fstat-no" title="function not covered" >function(a){<span class="cstat-no" title="statement not covered" ></span>return void 0!==a?(this._store.push(a),this):!1}</span>,g.prototype.pull=<span class="fstat-no" title="function not covered" >function(a){<span class="cstat-no" title="statement not covered" ></span>if(void 0!==a){<span class="cstat-no" title="statement not covered" >var b=this._store.indexOf(a);<span class="cstat-no" title="statement not covered" >i</span>f(b>-1)<span class="cstat-no" title="statement not covered" >return this._store.splice(b,1),this}<span class="cstat-no" title="statement not covered" ></span></span>r</span>eturn!1}</span>,g.prototype._compareFunc=function(a,b){var c,d,e=0;for(c=0;c<this._keys.length;c++)if(d=this._keys[c],1===d.value?e=this.sortAsc(f.get(a,d.path),f.get(b,d.path)):-1===d.value&&(e=this.sortDesc(f.get(a,d.path),f.get(b,d.path))),this.debug()&&console.log("Compared %s with %s order %d in path %s and result was %d",f.get(a,d.path),f.get(b,d.path),d.value,d.path,e),0!==e)return this.debug()&&console.log("Retuning result %d",e),e;return this.debug()&&console.log("Retuning result %d",e),e},g.prototype._hashFunc=function(a){return a[this._keys[0].path]},g.prototype.removeChildNode=<span class="fstat-no" title="function not covered" >function(a){<span class="cstat-no" title="statement not covered" ></span>this._left===a?delete this._left:this._right===a&&delete this._right}</span>,g.prototype.nodeBranch=<span class="fstat-no" title="function not covered" >function(a){<span class="cstat-no" title="statement not covered" ></span>return this._left===a?"left":this._right===a?"right":void 0}</span>,g.prototype.insert=function(a){var b,c,d,e;if(a instanceof Array){for(c=[],d=[],e=0;e<a.length;e++)this.insert(a[e])?c.push(a[e]):<span class="branch-1 cbranch-no" title="branch not covered" >d.push(a[e]);</span>return{inserted:c,failed:d}}return this.debug()&&console.log("Inserting",a),this._data?(b=this._compareFunc(this._data,a),0===b?(this.debug()&&<span class="branch-1 cbranch-no" title="branch not covered" >console.log("Data is equal (currrent, new)",this._data,a),</span>this._left?this._left.insert(a):(this._left=new g(a,this._index,this._binaryTree,this._compareFunc,this._hashFunc),this._left._parent=this),!0):-1===b?(this.debug()&&console.log("Data is greater (currrent, new)",this._data,a),this._right?this._right.insert(a):(this._right=new g(a,this._index,this._binaryTree,this._compareFunc,this._hashFunc),this._right._parent=this),!0):1===b?(this.debug()&&<span class="branch-1 cbranch-no" title="branch not covered" >console.log("Data is less (currrent, new)",this._data,a),</span>this._left?this._left.insert(a):(this._left=new g(a,this._index,this._binaryTree,this._compareFunc,this._hashFunc),this._left._parent=this),!0):<span class="branch-1 cbranch-no" title="branch not covered" >!1)</span>:(this.debug()&&console.log("Node has no data, setting data",a),this.data(a),!0)},g.prototype.remove=function(a){var b,c,d,e=this.primaryKey();<span class="missing-if-branch" title="if path not taken" >I</span>if(a instanceof Array){<span class="cstat-no" title="statement not covered" >for(c=[],d=0;d<a.length;d++)<span class="cstat-no" title="statement not covered" >this.remove(a[d])&&c.push(a[d]);<span class="cstat-no" title="statement not covered" >r</span></span>eturn c}</span>return this.debug()&&<span class="branch-1 cbranch-no" title="branch not covered" >console.log("Removing",a),</span>this._data[e]===a[e]?this._remove(this):(<span class="branch-1 cbranch-no" title="branch not covered" >b=this._compareFunc(this._data,a),-1===b&&this._right?this._right.remove(a):1===b&&this._left?this._left.remove(a):!1)</span>},g.prototype._remove=function(a){var b,c;return this._left?(b=this._left,c=this._right,this._left=b._left,this._right=b._right,this._data=b._data,this._store=b._store,c&&(b.rightMost()._right=c)):<span class="branch-1 cbranch-no" title="branch not covered" >this._right?(c=this._right,this._left=c._left,this._right=c._right,this._data=c._data,this._store=c._store):this.clear(),</span>!0},g.prototype.leftMost=<span class="fstat-no" title="function not covered" >function(){<span class="cstat-no" title="statement not covered" ></span>return this._left?this._left.leftMost():this}</span>,g.prototype.rightMost=function(){return this._right?this._right.rightMost():this},g.prototype.lookup=function(a,b,c){var d=this._compareFunc(this._data,a);return c=c||[],0===d&&(this._left&&this._left.lookup(a,b,c),c.push(this._data),this._right&&this._right.lookup(a,b,c)),-1===d&&this._right&&this._right.lookup(a,b,c),1===d&&this._left&&this._left.lookup(a,b,c),c},g.prototype.inOrder=function(a,b){switch(b=b||[],this._left&&this._left.inOrder(a,b),a){<span class="branch-0 cbranch-no" title="branch not covered" >case"hash":<span class="cstat-no" title="statement not covered" >b.push(this._hash);<span class="cstat-no" title="statement not covered" >b</span>reak;c</span></span>ase"data":b.push(this._data);break;<span class="branch-2 cbranch-no" title="branch not covered" >default:<span class="cstat-no" title="statement not covered" >b.push({key:this._data,arr:this._store})}</span></span>return this._right&&this._right.inOrder(a,b),b},g.prototype.startsWith=function(a,b,c,d){var e,g,h=f.get(this._data,a),i=h.substr(0,b.length);return c=c||new RegExp("^"+b),d=d||[],void 0===d._visited&&(d._visited=0),d._visited++,g=this.sortAsc(h,b),e=i===b,0===g&&(<span class="branch-1 cbranch-no" title="branch not covered" >this._left&&this._left.startsWith(a,b,c,d),e&&d.push(this._data),this._right&&this._right.startsWith(a,b,c,d))</span>,-1===g&&(e&&<span class="branch-1 cbranch-no" title="branch not covered" >d.push(this._data),</span>this._right&&this._right.startsWith(a,b,c,d)),1===g&&(this._left&&this._left.startsWith(a,b,c,d),e&&d.push(this._data)),d},g.prototype.findRange=function(a,b,c,d,f,g){f=f||[],g=g||new e(b),this._left&&this._left.findRange(a,b,c,d,f,g);var h=g.value(this._data),i=this.sortAsc(h,c),j=this.sortAsc(h,d);if(!(0!==i&&1!==i||0!==j&&-1!==j))switch(a){<span class="branch-0 cbranch-no" title="branch not covered" >case"hash":<span class="cstat-no" title="statement not covered" >f.push(this._hash);<span class="cstat-no" title="statement not covered" >b</span>reak;c</span></span>ase"data":f.push(this._data);break;<span class="branch-2 cbranch-no" title="branch not covered" >default:<span class="cstat-no" title="statement not covered" >f.push({key:this._data,arr:this._store})}</span></span>return this._right&&this._right.findRange(a,b,c,d,f,g),f},g.prototype.match=function(a,b,c){var d,e,g,h=[],i=0;for(d=f.parseArr(this._index,{verbose:!0}),e=f.parseArr(a,c&&c.pathOptions?c.pathOptions:{ignore:/\$/,verbose:!0}),g=0;g<d.length;g++)e[g]===d[g]&&(i++,h.push(e[g]));return{matchedKeys:h,totalKeyCount:e.length,score:i}},d.finishModule("BinaryTree"),b.exports=g},{"./Path":34,"./Shared":40}],6:[function(a,b,c){"use strict";var d,e;d=function(){var a,b,c,d=[];for(b=0;256>b;b++){for(a=b,c=0;8>c;c++)a=1&a?3988292384^a>>>1:a>>>1;d[b]=a}return d}(),e=<span class="fstat-no" title="function not covered" >function(a){<span class="cstat-no" title="statement not covered" ></span>var b,c=-1;<span class="cstat-no" title="statement not covered" >f</span>or(b=0;b<a.length;b++)<span class="cstat-no" title="statement not covered" >c=c>>>8^d[255&(c^a.charCodeAt(b))];<span class="cstat-no" title="statement not covered" >r</span></span>eturn(-1^c)>>>0}</span>,b.exports=e},{}],7:[function(a,b,c){"use strict";var d,e,f,g,h,i,j,k,l,m,n;d=a("./Shared");var o=function(a,b){this.init.apply(this,arguments)};o.prototype.init=function(a,b){this.sharedPathSolver=n,this._primaryKey="_id",this._primaryIndex=new g("primary"),this._primaryCrc=new g("primaryCrc"),this._crcLookup=new g("crcLookup"),this._name=a,this._data=[],this._metrics=new f,this._options=b||{changeTimestamp:!1},this._options.db&&<span class="branch-1 cbranch-no" title="branch not covered" >this.db(this._options.db),</span>this._metaData={},this._deferQueue={insert:[],update:[],remove:[],upsert:[],async:[]},this._deferThreshold={insert:100,update:100,remove:100,upsert:100},this._deferTime={insert:1,update:1,remove:1,upsert:1},this._deferredCalls=!0,this.subsetOf(this)},d.addModule("Collection",o),d.mixin(o.prototype,"Mixin.Common"),d.mixin(o.prototype,"Mixin.Events"),d.mixin(o.prototype,"Mixin.ChainReactor"),d.mixin(o.prototype,"Mixin.CRUD"),d.mixin(o.prototype,"Mixin.Constants"),d.mixin(o.prototype,"Mixin.Triggers"),d.mixin(o.prototype,"Mixin.Sorting"),d.mixin(o.prototype,"Mixin.Matching"),d.mixin(o.prototype,"Mixin.Updating"),d.mixin(o.prototype,"Mixin.Tags"),f=a("./Metrics"),g=a("./KeyValueStore"),h=a("./Path"),i=a("./IndexHashMap"),j=a("./IndexBinaryTree"),k=a("./Index2d"),e=d.modules.Db,l=a("./Overload"),m=a("./ReactorIO"),n=new h,d.synthesize(o.prototype,"deferredCalls"),d.synthesize(o.prototype,"state"),d.synthesize(o.prototype,"name"),d.synthesize(o.prototype,"metaData"),d.synthesize(o.prototype,"capped"),d.synthesize(o.prototype,"cappedSize"),o.prototype._asyncPending=function(a){this._deferQueue.async.push(a)},o.prototype._asyncComplete=function(a){for(var b=this._deferQueue.async.indexOf(a);b>-1;)this._deferQueue.async.splice(b,1),b=this._deferQueue.async.indexOf(a);0===this._deferQueue.async.length&&this.deferEmit("ready")},o.prototype.data=function(){return this._data},o.prototype.drop=function(a){var b;<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >return a&&a.call(this,!1,!0),!0;<span class="missing-if-branch" title="else path not taken" >E</span>i</span>f(this._db&&this._db._collection&&this._name){if(this.debug()&&console.log(this.logIdentifier()+" Dropping"),this._state="dropped",this.emit("drop",this),delete this._db._collection[this._name],this._collate)for(b in this._collate)this._collate.hasOwnProperty(b)&&this.collateRemove(b);return delete this._primaryKey,delete this._primaryIndex,delete this._primaryCrc,delete this._crcLookup,delete this._data,delete this._metrics,delete this._listeners,a&&<span class="branch-1 cbranch-no" title="branch not covered" >a.call(this,!1,!0),</span>!0}<span class="cstat-no" title="statement not covered" >return a&&a.call(this,!1,!0),!1}</span>,o.prototype.primaryKey=function(a){if(void 0!==a){if(this._primaryKey!==a){var b=this._primaryKey;this._primaryKey=a,this._primaryIndex.primaryKey(a),this.rebuildPrimaryKeyIndex(),this.chainSend("primaryKey",{keyName:a,oldData:b})}return this}return this._primaryKey},o.prototype._onInsert=function(a,b){this.emit("insert",a,b)},o.prototype._onUpdate=function(a){this.emit("update",a)},o.prototype._onRemove=function(a){this.emit("remove",a)},o.prototype._onChange=function(){this._options.changeTimestamp&&(this._metaData.lastChange=this.serialiser.convert(new Date))},d.synthesize(o.prototype,"db",function(a){return a&&"_id"===this.primaryKey()&&(this.primaryKey(a.primaryKey()),this.debug(a.debug())),this.$super.apply(this,arguments)}),d.synthesize(o.prototype,"mongoEmulation"),o.prototype.setData=new l("Collection.prototype.setData",{"*":function(a){return this.$main.call(this,a,{})},"*, object":function(a,b){return this.$main.call(this,a,b)},"*, function":<span class="fstat-no" title="function not covered" >function(a,b){<span class="cstat-no" title="statement not covered" ></span>return this.$main.call(this,a,{},b)}</span>,"*, *, function":<span class="fstat-no" title="function not covered" >function(a,b,c){<span class="cstat-no" title="statement not covered" ></span>return this.$main.call(this,a,b,c)}</span>,"*, *, *":function(a,b,c){return this.$main.call(this,a,b,c)},$main:function(a,b,c){<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot operate in a dropped state!";<span class="missing-if-branch" title="else path not taken" >E</span>i</span>f(a){var d=this.deferredCalls(),e=[].concat(this._data);this.deferredCalls(!1),b=this.options(b),b.$decouple&&(a=this.decouple(a)),a instanceof Array||(a=[a]),this.remove({}),this.insert(a),this.deferredCalls(d),this._onChange(),this.emit("setData",this._data,e)}return c&&<span class="branch-1 cbranch-no" title="branch not covered" >c.call(this),</span>this}}),o.prototype.rebuildPrimaryKeyIndex=function(a){a=a||{$ensureKeys:void 0,$violationCheck:void 0};var b,c,d,e,f=a&&void 0!==a.$ensureKeys?<span class="branch-0 cbranch-no" title="branch not covered" >a.$ensureKeys:</span>!0,g=a&&void 0!==a.$violationCheck?<span class="branch-0 cbranch-no" title="branch not covered" >a.$violationCheck:</span>!0,h=this._primaryIndex,i=this._primaryCrc,j=this._crcLookup,k=this._primaryKey;for(h.truncate(),i.truncate(),j.truncate(),b=this._data,c=b.length;c--;){<span class="missing-if-branch" title="else path not taken" >E</span>if(d=b[c],f&&this.ensurePrimaryKey(d),g){<span class="missing-if-branch" title="if path not taken" >I</span>if(!h.uniqueSet(d[k],d))<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Call to setData on collection failed because your data violates the primary key unique constraint. One or more documents are using the same primary key: "+d[this._primaryKey]}</span>else <span class="cstat-no" title="statement not covered" >h.set(d[k],d);e</span>=this.hash(d),i.set(d[k],e),j.set(e,d)}},o.prototype.ensurePrimaryKey=function(a){void 0===a[this._primaryKey]&&(a[this._primaryKey]=this.objectId())},o.prototype.truncate=function(){<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot operate in a dropped state!";r</span>eturn this.emit("truncate",this._data),this._data.length=0,this._primaryIndex=new g("primary"),this._primaryCrc=new g("primaryCrc"),this._crcLookup=new g("crcLookup"),this._onChange(),this.emit("immediateChange",{type:"truncate"}),this.deferEmit("change",{type:"truncate"}),this},o.prototype.upsert=function(a,b){<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot operate in a dropped state!";<span class="missing-if-branch" title="else path not taken" >E</span>i</span>f(a){var c,d,e=this._deferQueue.upsert,f=this._deferThreshold.upsert,g={};if(a instanceof Array){<span class="missing-if-branch" title="if path not taken" >I</span>if(this._deferredCalls&&a.length>f)<span class="cstat-no" title="statement not covered" >return this._deferQueue.upsert=e.concat(a),this._asyncPending("upsert"),this.processQueue("upsert",b),{};f</span>or(g=[],d=0;d<a.length;d++)g.push(this.upsert(a[d]));return b&&<span class="branch-1 cbranch-no" title="branch not covered" >b.call(this),</span>g}switch(a[this._primaryKey]?(c={},c[this._primaryKey]=a[this._primaryKey],this._primaryIndex.lookup(c)[0]?g.op="update":g.op="insert"):g.op="insert",g.op){case"insert":g.result=this.insert(a,b);break;case"update":g.result=this.update(c,a,{},b)}return g}<span class="cstat-no" title="statement not covered" >return b&&b.call(this),{}}</span>,o.prototype.filter=function(a,b,c){return this.find(a,c).filter(b)},o.prototype.filterUpdate=function(a,b,c){var d,e,f,g,h=this.find(a,c),i=[],j=this.primaryKey();for(g=0;g<h.length;g++)d=h[g],f=b(d),f&&(e={},e[j]=d[j],i.push(this.update(e,f)));return i},o.prototype.update=function(a,b,c,d){<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot operate in a dropped state!";r</span>eturn this.mongoEmulation()?(this.convertToFdb(a),this.convertToFdb(b)):b=this.decouple(b),b=this.transformIn(b),this._handleUpdate(a,b,c,d)},o.prototype._handleUpdate=function(a,b,c,d){var e,f,g=this,h=this._metrics.create("update"),i=function(d){var e,f,i,j=g.decouple(d);return g.willTrigger(g.TYPE_UPDATE,g.PHASE_BEFORE)||g.willTrigger(g.TYPE_UPDATE,g.PHASE_AFTER)?(e=g.decouple(d),f={type:"update",query:g.decouple(a),update:g.decouple(b),options:g.decouple(c),op:h},i=g.updateObject(e,f.update,f.query,f.options,""),g.processTrigger(f,g.TYPE_UPDATE,g.PHASE_BEFORE,d,e)!==!1?(i=g.updateObject(d,e,f.query,f.options,""),g.processTrigger(f,g.TYPE_UPDATE,g.PHASE_AFTER,j,e)):i=!1):i=g.updateObject(d,b,a,c,""),g._updateIndexes(j,d),i};return h.start(),h.time("Retrieve documents to update"),e=this.find(a,{$decouple:!1}),h.time("Retrieve documents to update"),e.length&&(h.time("Update documents"),f=e.filter(i),h.time("Update documents"),f.length&&(this.debug()&&console.log(this.logIdentifier()+" Updated some data"),h.time("Resolve chains"),this.chainWillSend()&&this.chainSend("update",{query:a,update:b,dataSet:this.decouple(f)},c),h.time("Resolve chains"),this._onUpdate(f),this._onChange(),d&&<span class="branch-1 cbranch-no" title="branch not covered" >d.call(this),</span>this.emit("immediateChange",{type:"update",data:f}),this.deferEmit("change",{type:"update",data:f}))),h.stop(),f||<span class="branch-1 cbranch-no" title="branch not covered" >[]}</span>,o.prototype._replaceObj=<span class="fstat-no" title="function not covered" >function(a,b){<span class="cstat-no" title="statement not covered" ></span>var c;<span class="cstat-no" title="statement not covered" >t</span>his._removeFromIndexes(a);<span class="cstat-no" title="statement not covered" >f</span>or(c in a)<span class="cstat-no" title="statement not covered" >a.hasOwnProperty(c)&&delete a[c];<span class="cstat-no" title="statement not covered" >f</span></span>or(c in b)<span class="cstat-no" title="statement not covered" >b.hasOwnProperty(c)&&(a[c]=b[c]);<span class="cstat-no" title="statement not covered" >i</span></span>f(!this._insertIntoIndexes(a))<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Primary key violation in update! Key violated: "+a[this._primaryKey];<span class="cstat-no" title="statement not covered" >r</span></span>eturn this}</span>,o.prototype.updateById=function(a,b){var c={};return c[this._primaryKey]=a,this.update(c,b)[0]},o.prototype.updateObject=function(a,b,c,d,e,f){b=this.decouple(b),e=e||"","."===e.substr(0,1)&&(e=e.substr(1,e.length-1));var g,i,j,k,l,m,n,o,p,q,r,s,t=!1,u=!1;for(s in b)<span class="missing-if-branch" title="else path not taken" >E</span>if(b.hasOwnProperty(s)){if(g=!1,"$"===s.substr(0,1))switch(s){<span class="branch-0 cbranch-no" title="branch not covered" >case"$key":<span class="branch-1 cbranch-no" title="branch not covered" >c</span>ase"$index":c</span>ase"$data":case"$min":case"$max":g=!0;break;case"$each":for(g=!0,k=b.$each.length,j=0;k>j;j++)u=this.updateObject(a,b.$each[j],c,d,e),u&&(t=!0);t=t||<span class="branch-1 cbranch-no" title="branch not covered" >u;</span>break;case"$replace":g=!0,n=b.$replace,o=this.primaryKey();for(m in a)a.hasOwnProperty(m)&&m!==o&&void 0===n[m]&&(this._updateUnset(a,m),t=!0);for(m in n)n.hasOwnProperty(m)&&m!==o&&(this._updateOverwrite(a,m,n[m]),t=!0);break;default:g=!0,u=this.updateObject(a,b[s],c,d,e,s),t=t||u}if(this._isPositionalKey(s)&&(g=!0,s=s.substr(0,s.length-2),p=new h(e+"."+s),a[s]&&a[s]instanceof Array&&a[s].length)){for(i=[],j=0;j<a[s].length;j++)this._match(a[s][j],p.value(c)[0],d,"",{})&&i.push(j);for(j=0;j<i.length;j++)u=this.updateObject(a[s][i[j]],b[s+".$"],c,d,e+"."+s,f),t=t||u}if(!g)if(f||"object"!=typeof b[s])switch(f){case"$inc":var v=!0;b[s]>0?b.$max&&<span class="branch-1 cbranch-no" title="branch not covered" >a[s]>=b.$max&</span>&(<span class="branch-2 cbranch-no" title="branch not covered" >v=!1)</span>:b[s]<0&&b.$min&&<span class="branch-2 cbranch-no" title="branch not covered" >a[s]<=b.$min&</span>&(<span class="branch-3 cbranch-no" title="branch not covered" >v=!1)</span>,v&&(this._updateIncrement(a,s,b[s]),t=!0);break;case"$cast":switch(b[s]){case"array":a[s]instanceof Array||(this._updateProperty(a,s,b.$data||[]),t=!0);break;<span class="branch-1 cbranch-no" title="branch not covered" >case"object":<span class="cstat-no" title="statement not covered" >(!(a[s]instanceof Object)||a[s]instanceof Array)&&(this._updateProperty(a,s,b.$data||{}),t=!0);<span class="cstat-no" title="statement not covered" >b</span>reak;<span class="branch-2 cbranch-no" title="branch not covered" >c</span></span>ase"number":<span class="cstat-no" title="statement not covered" >"number"!=typeof a[s]&&(this._updateProperty(a,s,Number(a[s])),t=!0);<span class="cstat-no" title="statement not covered" >b</span>reak;<span class="branch-3 cbranch-no" title="branch not covered" >c</span></span>ase"string":<span class="cstat-no" title="statement not covered" >"string"!=typeof a[s]&&(this._updateProperty(a,s,String(a[s])),t=!0);<span class="cstat-no" title="statement not covered" >b</span>reak;<span class="branch-4 cbranch-no" title="branch not covered" >d</span></span>efault:<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot update cast to unknown type: "+b[s]}</span></span>break;case"$push":<span class="missing-if-branch" title="if path not taken" >I</span>if(void 0===a[s]&&this._updateProperty(a,s,[]),!(a[s]instanceof Array))<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot push to a key that is not an array! ("+s+")";i</span>f(void 0!==b[s].$position&&b[s].$each instanceof Array)for(l=b[s].$position,k=b[s].$each.length,j=0;k>j;j++)this._updateSplicePush(a[s],l+j,b[s].$each[j]);else if(b[s].$each instanceof Array)for(k=b[s].$each.length,j=0;k>j;j++)this._updatePush(a[s],b[s].$each[j]);else this._updatePush(a[s],b[s]);t=!0;break;case"$pull":<span class="missing-if-branch" title="else path not taken" >E</span>if(a[s]instanceof Array){for(i=[],j=0;j<a[s].length;j++)this._match(a[s][j],b[s],d,"",{})&&i.push(j);for(k=i.length;k--;)this._updatePull(a[s],i[k]),t=!0}break;case"$pullAll":<span class="missing-if-branch" title="else path not taken" >E</span>if(a[s]instanceof Array){<span class="missing-if-branch" title="if path not taken" >I</span>if(!(b[s]instanceof Array))<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot pullAll without being given an array of values to pull! ("+s+")";<span class="missing-if-branch" title="else path not taken" >E</span>i</span>f(i=a[s],k=i.length,k>0)for(;k--;){for(l=0;l<b[s].length;l++)i[k]===b[s][l]&&(this._updatePull(a[s],k),k--,t=!0);if(0>k)break}}break;case"$addToSet":<span class="missing-if-branch" title="if path not taken" >I</span>if(void 0===a[s]&&<span class="branch-1 cbranch-no" title="branch not covered" >this._updateProperty(a,s,[]),</span>!(a[s]instanceof Array))<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot addToSet on a key that is not an array! ("+s+")";v</span>ar w,x,y,z,A=a[s],B=A.length,C=!0,D=d&&d.$addToSet;for(b[s].$key?(y=!1,z=new h(b[s].$key),x=z.value(b[s])[0],delete b[s].$key):D&&D.key?(y=!1,z=new h(D.key),x=z.value(b[s])[0]):(x=this.jStringify(b[s]),y=!0),w=0;B>w;w++)if(y){<span class="missing-if-branch" title="else path not taken" >E</span>if(this.jStringify(A[w])===x){C=!1;break}}else if(x===z.value(A[w])[0]){C=!1;break}C&&(this._updatePush(a[s],b[s]),t=!0);break;case"$splicePush":<span class="missing-if-branch" title="if path not taken" >I</span>if(void 0===a[s]&&<span class="branch-1 cbranch-no" title="branch not covered" >this._updateProperty(a,s,[]),</span>!(a[s]instanceof Array))<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot splicePush with a key that is not an array! ("+s+")";<span class="missing-if-branch" title="if path not taken" >I</span>i</span>f(l=b.$index,void 0===l)<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot splicePush without a $index integer value!";d</span>elete b.$index,l>a[s].length&&(<span class="branch-1 cbranch-no" title="branch not covered" >l=a[s].length)</span>,this._updateSplicePush(a[s],l,b[s]),t=!0;break;case"$move":<span class="missing-if-branch" title="if path not taken" >I</span>if(!(a[s]instanceof Array))<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot move on a key that is not an array! ("+s+")";f</span>or(j=0;j<a[s].length;j++)<span class="missing-if-branch" title="else path not taken" >E</span>if(this._match(a[s][j],b[s],d,"",{})){var E=b.$index;<span class="missing-if-branch" title="if path not taken" >I</span>if(void 0===E)<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot move without a $index integer value!";d</span>elete b.$index,this._updateSpliceMove(a[s],j,E),t=!0;break}break;case"$mul":this._updateMultiply(a,s,b[s]),t=!0;break;case"$rename":this._updateRename(a,s,b[s]),t=!0;break;case"$overwrite":this._updateOverwrite(a,s,b[s]),t=!0;break;case"$unset":this._updateUnset(a,s),t=!0;break;<span class="branch-12 cbranch-no" title="branch not covered" >case"$clear":<span class="cstat-no" title="statement not covered" >this._updateClear(a,s),t=!0;<span class="cstat-no" title="statement not covered" >b</span>reak;<span class="branch-13 cbranch-no" title="branch not covered" >c</span></span>ase"$pop":<span class="cstat-no" title="statement not covered" >if(!(a[s]instanceof Array))<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot pop from a key that is not an array! ("+s+")";<span class="cstat-no" title="statement not covered" >t</span></span>his._updatePop(a[s],b[s])&&(t=!0);<span class="cstat-no" title="statement not covered" >b</span>reak;c</span></span>ase"$toggle":this._updateProperty(a,s,!a[s]),t=!0;break;default:a[s]!==b[s]&&(this._updateProperty(a,s,b[s]),t=!0)}else <span class="missing-if-branch" title="else path not taken" >E</span>if(null!==a[s]&&"object"==typeof a[s])if(q=a[s]instanceof Array,r=b[s]instanceof Array,q||r)if(!r&&q)for(j=0;j<a[s].length;j++)u=this.updateObject(a[s][j],b[s],c,d,e+"."+s,f),t=t||u;else a[s]!==b[s]&&(this._updateProperty(a,s,b[s]),t=!0);else u=this.updateObject(a[s],b[s],c,d,e+"."+s,f),t=t||u;else <span class="cstat-no" title="statement not covered" >a[s]!==b[s]&&(this._updateProperty(a,s,b[s]),t=!0)}</span>return t},o.prototype._isPositionalKey=function(a){return".$"===a.substr(a.length-2,2)},o.prototype.remove=function(a,b,c){<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot operate in a dropped state!";v</span>ar d,e,f,g,h,i,j,k,l=this;<span class="missing-if-branch" title="if path not taken" >I</span>if("function"==typeof b&&(<span class="branch-1 cbranch-no" title="branch not covered" >c=b,b={})</span>,this.mongoEmulation()&&<span class="branch-1 cbranch-no" title="branch not covered" >this.convertToFdb(a),</span>a instanceof Array){<span class="cstat-no" title="statement not covered" >for(g=[],f=0;f<a.length;f++)<span class="cstat-no" title="statement not covered" >g.push(this.remove(a[f],{noEmit:!0}));<span class="cstat-no" title="statement not covered" >r</span></span>eturn(!b||b&&!b.noEmit)&&this._onRemove(g),c&&c.call(this,!1,g),g}</span>if(g=[],d=this.find(a,{$decouple:!1}),d.length){h=function(a){l._removeFromIndexes(a),e=l._data.indexOf(a),l._dataRemoveAtIndex(e),g.push(a)};for(var m=0;m<d.length;m++)j=d[m],l.willTrigger(l.TYPE_REMOVE,l.PHASE_BEFORE)||l.willTrigger(l.TYPE_REMOVE,l.PHASE_AFTER)?(i={type:"remove"},k=l.decouple(j),l.processTrigger(i,l.TYPE_REMOVE,l.PHASE_BEFORE,k,k)!==!1&&(h(j),l.processTrigger(i,l.TYPE_REMOVE,l.PHASE_AFTER,k,k))):h(j);g.length&&(l.chainSend("remove",{query:a,dataSet:g},b),(!b||<span class="branch-1 cbranch-no" title="branch not covered" >b&</span>&<span class="branch-2 cbranch-no" title="branch not covered" >!b.noEmit)</span>&&this._onRemove(g),this._onChange(),this.emit("immediateChange",{type:"remove",data:g}),this.deferEmit("change",{type:"remove",data:g}))}return c&&<span class="branch-1 cbranch-no" title="branch not covered" >c.call(this,!1,g),</span>g},o.prototype.removeById=function(a){var b={};return b[this._primaryKey]=a,this.remove(b)[0]},o.prototype.processQueue=function(a,b,c){var d,e,f=this,g=this._deferQueue[a],h=this._deferThreshold[a],i=this._deferTime[a];if(c=c||{deferred:!0},g.length){switch(d=g.length>h?g.splice(0,h):g.splice(0,g.length),e=f[a](d),a){case"insert":c.inserted=c.inserted||[],c.failed=c.failed||[],c.inserted=c.inserted.concat(e.inserted),c.failed=c.failed.concat(e.failed)}setTimeout(function(){f.processQueue.call(f,a,b,c)},i)}else b&&b.call(this,c),this._asyncComplete(a);this.isProcessingQueue()||this.deferEmit("queuesComplete")},o.prototype.isProcessingQueue=function(){var a;for(a in this._deferQueue)if(this._deferQueue.hasOwnProperty(a)&&this._deferQueue[a].length)return!0;return!1},o.prototype.insert=function(a,b,c){<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot operate in a dropped state!";r</span>eturn"function"==typeof b?(c=b,b=this._data.length):void 0===b&&(b=this._data.length),a=this.transformIn(a),this._insertHandle(a,b,c)},o.prototype._insertHandle=function(a,b,c){var d,e,f,g=this._deferQueue.insert,h=this._deferThreshold.insert,i=[],j=[];if(a instanceof Array){if(this._deferredCalls&&a.length>h)return this._deferQueue.insert=g.concat(a),this._asyncPending("insert"),void this.processQueue("insert",c);for(f=0;f<a.length;f++)d=this._insert(a[f],b+f),d===!0?i.push(a[f]):j.push({doc:a[f],reason:d})}else d=this._insert(a,b),d===!0?i.push(a):j.push({doc:a,reason:d});return e={deferred:!1,inserted:i,failed:j},this._onInsert(i,j),c&&<span class="branch-1 cbranch-no" title="branch not covered" >c.call(this,e),</span>this._onChange(),this.emit("immediateChange",{type:"insert",data:i}),this.deferEmit("change",{type:"insert",data:i}),e},o.prototype._insert=function(a,b){<span class="missing-if-branch" title="else path not taken" >E</span>if(a){var c,d,e,f,g=this,h=this.capped(),i=this.cappedSize();if(this.ensurePrimaryKey(a),c=this.insertIndexViolation(a),e=function(a){g._insertIntoIndexes(a),b>g._data.length&&(b=g._data.length),g._dataInsertAtIndex(b,a),h&&g._data.length>i&&g.removeById(g._data[0][g._primaryKey]),g.chainWillSend()&&g.chainSend("insert",{dataSet:g.decouple([a])},{index:b})},c)return"Index violation in index: "+c;if(g.willTrigger(g.TYPE_INSERT,g.PHASE_BEFORE)||g.willTrigger(g.TYPE_INSERT,g.PHASE_AFTER)){if(d={type:"insert"},g.processTrigger(d,g.TYPE_INSERT,g.PHASE_BEFORE,{},a)===!1)return"Trigger cancelled operation";e(a),g.willTrigger(g.TYPE_INSERT,g.PHASE_AFTER)&&(f=g.decouple(a),g.processTrigger(d,g.TYPE_INSERT,g.PHASE_AFTER,{},f))}else e(a);return!0}<span class="cstat-no" title="statement not covered" >return"No document passed to insert"}</span>,o.prototype._dataInsertAtIndex=function(a,b){this._data.splice(a,0,b)},o.prototype._dataRemoveAtIndex=function(a){this._data.splice(a,1)},o.prototype._dataReplace=<span class="fstat-no" title="function not covered" >function(a){<span class="cstat-no" title="statement not covered" ></span>for(;this._data.length;)<span class="cstat-no" title="statement not covered" >this._data.pop();<span class="cstat-no" title="statement not covered" >t</span></span>his._data=this._data.concat(a)}</span>,o.prototype._insertIntoIndexes=function(a){var b,c,d=this._indexByName,e=this.hash(a),f=this._primaryKey;c=this._primaryIndex.uniqueSet(a[f],a),this._primaryCrc.uniqueSet(a[f],e),this._crcLookup.uniqueSet(e,a);for(b in d)d.hasOwnProperty(b)&&d[b].insert(a);return c},o.prototype._removeFromIndexes=function(a){var b,c=this._indexByName,d=this.hash(a),e=this._primaryKey;this._primaryIndex.unSet(a[e]),this._primaryCrc.unSet(a[e]),this._crcLookup.unSet(d);for(b in c)c.hasOwnProperty(b)&&c[b].remove(a)},o.prototype._updateIndexes=function(a,b){this._removeFromIndexes(a),this._insertIntoIndexes(b)},o.prototype._rebuildIndexes=<span class="fstat-no" title="function not covered" >function(){<span class="cstat-no" title="statement not covered" ></span>var a,b=this._indexByName;<span class="cstat-no" title="statement not covered" >f</span>or(a in b)<span class="cstat-no" title="statement not covered" >b.hasOwnProperty(a)&&b[a].rebuild()}</span></span>,o.prototype.subset=function(a,b){var c,d=this.find(a,b);return c=new o,c.db(this._db),c.subsetOf(this).primaryKey(this._primaryKey).setData(d),c},d.synthesize(o.prototype,"subsetOf"),o.prototype.isSubsetOf=function(a){return this._subsetOf===a},o.prototype.distinct=function(a,b,c){<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot operate in a dropped state!";v</span>ar d,e,f=this.find(b,c),g=new h(a),i={},j=[];for(e=0;e<f.length;e++)d=g.value(f[e])[0],d&&!i[d]&&(i[d]=!0,j.push(d));return j},o.prototype.findById=function(a,b){var c={};return c[this._primaryKey]=a,this.find(c,b)[0]},o.prototype.peek=function(a,b){var c,d,e=this._data,f=e.length,g=new o,h=typeof a;<span class="missing-if-branch" title="else path not taken" >E</span>if("string"===h){for(c=0;f>c;c++)d=this.jStringify(e[c]),d.indexOf(a)>-1&&g.insert(e[c]);return g.find({},b)}<span class="cstat-no" title="statement not covered" >return this.find(a,b)}</span>,o.prototype.explain=function(a,b){var c=this.find(a,b);return c.__fdbOp._data},o.prototype.options=function(a){return a=a||{},a.$decouple=void 0!==a.$decouple?a.$decouple:!0,a.$explain=void 0!==a.$explain?a.$explain:!1,a},o.prototype.find=function(a,b,c){return this.mongoEmulation()&&this.convertToFdb(a),c?(<span class="branch-0 cbranch-no" title="branch not covered" >c.call(this,"Callbacks for the find() operation are not yet implemented!",[]),[])</span>:this._find.call(this,a,b,c)},o.prototype._find=function(a,b){<span class="missing-if-branch" title="if path not taken" >I</span>if(this.isDropped())<span class="cstat-no" title="statement not covered" >throw this.logIdentifier()+" Cannot operate in a dropped state!";a</span>=a||{};var c,d,e,f,g,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x=this._metrics.create("find"),y=this.primaryKey(),z=this,A=!0,B={},C=[],D=[],E=[],F={},G={};<span class="missing-if-branch" title="else path not taken" >E</span>if(b instanceof Array||(b=this.options(b)),w=function(c){return z._match(c,a,b,"and",F)},x.start(),a){if(a instanceof Array){for(v=this,n=0;n<a.length;n++)v=v.subset(a[n],b&&b[n]?<span class="branch-0 cbranch-no" title="branch not covered" >b[n]:</span>{});return v.find()}if(a.$findSub){<span class="missing-if-branch" title="if path not taken" >I</span>if(!a.$findSub.$path)<span class="cstat-no" title="statement not covered" >throw"$findSub missing $path property!";r</span>eturn this.findSub(a.$findSub.$query,a.$findSub.$path,a.$findSub.$subQuery,a.$findSub.$subOptions)}<span class="missing-if-branch" title="if path not taken" >I</span>if(a.$findSubOne){<span class="cstat-no" title="statement not covered" >if(!a.$findSubOne.$path)<span class="cstat-no" title="statement not covered" >throw"$findSubOne missing $path property!";<span class="cstat-no" title="statement not covered" >r</span></span>eturn this.findSubOne(a.$findSubOne.$query,a.$findSubOne.$path,a.$findSubOne.$subQuery,a.$findSubOne.$subOptions)}</span>if(x.time("analyseQuery"),c=this._analyseQuery(z.decouple(a),b,x),x.time("analyseQuery"),x.data("analysis",c),c.hasJoin&&c.queriesJoin){for(x.time("joinReferences"),f=0;f<c.joinsOn.length;f++)m=c.joinsOn[f],j=m.key,k=m.type,l=m.id,i=new h(c.joinQueries[j]),g=i.value(a)[0],B[l]=this._db[k](j).subset(g),delete a[c.joinQueries[j]];x.time("joinReferences")}if(c.indexMatch.length&&(!b||b&&!b.$skipIndex)?(x.data("index.potential",c.indexMatch),x.data("index.used",c.indexMatch[0].index),x.time("indexLookup"),e=c.indexMatch[0].lookup||<span class="branch-1 cbranch-no" title="branch not covered" >[],</span>x.time("indexLookup"),c.indexMatch[0].keyData.totalKeyCount===c.indexMatch[0].keyData.score&&(A=!1)):x.flag("usedIndex",!1),A&&(e&&e.length?(d=e.length,x.time("tableScan: "+d),e=e.filter(w)):(d=this._data.length,x.time("tableScan: "+d),e=this._data.filter(w)),x.time("tableScan: "+d)),b.$orderBy&&(x.time("sort"),e=this.sort(b.$orderBy,e),x.time("sort")),void 0!==b.$page&&void 0!==b.$limit&&(G.page=b.$page,G.pages=Math.ceil(e.length/b.$limit),G.records=e.length,b.$page&&b.$limit>0&&(x.data("cursor",G),e.splice(0,b.$page*b.$limit))),b.$skip&&(G.skip=b.$skip,e.splice(0,b.$skip),x.data("skip",b.$skip)),b.$limit&&e&&e.length>b.$limit&&(G.limit=b.$limit,e.length=b.$limit,x.data("limit",b.$limit)),b.$decouple&&(x.time("decouple"),e=this.decouple(e),x.time("decouple"),x.data("flag.decouple",!0)),b.$join&&(C=C.concat(this.applyJoin(e,b.$join,B)),x.data("flag.join",!0)),C.length&&(x.time("removalQueue"),this.spliceArrayByIndexList(e,C),x.time("removalQueue")),b.$transform){for(x.time("transform"),n=0;n<e.length;n++)e.splice(n,1,b.$transform(e[n]));x.time("transform"),x.data("flag.transform",!0)}this._transformEnabled&&this._transformOut&&(x.time("transformOut"),e=this.transformOut(e),x.time("transformOut")),x.data("results",e.length)}else <span class="cstat-no" title="statement not covered" >e=[];i</span>f(!b.$aggregate){x.time("scanFields");for(n in b)b.hasOwnProperty(n)&&0!==n.indexOf("$")&&(1===b[n]?D.push(n):0===b[n]&&E.push(n));if(x.time("scanFields"),D.length||E.length){for(x.data("flag.limitFields",!0),x.data("limitFields.on",D),x.data("limitFields.off",E),x.time("limitFields"),n=0;n<e.length;n++){t=e[n];for(o in t)t.hasOwnProperty(o)&&(D.length&&o!==y&&-1===D.indexOf(o)&&delete t[o],E.length&&E.indexOf(o)>-1&&delete t[o])}x.time("limitFields")}if(b.$elemMatch){x.data("flag.elemMatch",!0),x.time("projection-elemMatch");for(n in b.$elemMatch)<span class="missing-if-branch" title="else path not taken" >E</span>if(b.$elemMatch.hasOwnProperty(n))for(q=new h(n),o=0;o<e.length;o++)<span class="missing-if-branch" title="else path not taken" >E</span>if(r=q.value(e[o])[0],r&&r.length)for(p=0;p<r.length;p++)if(z._match(r[p],b.$elemMatch[n],b,"",{})){q.set(e[o],n,[r[p]]);break}x.time("projection-elemMatch")}if(b.$elemsMatch){x.data("flag.elemsMatch",!0),x.time("projection-elemsMatch");for(n in b.$elemsMatch)<span class="missing-if-branch" title="else path not taken" >E</span>if(b.$elemsMatch.hasOwnProperty(n))for(q=new h(n),o=0;o<e.length;o++)<span class="missing-if-branch" title="else path not taken" >E</span>if(r=q.value(e[o])[0],r&&r.length){for(s=[],p=0;p<r.length;p++)z._match(r[p],b.$elemsMatch[n],b,"",{})&&s.push(r[p]);
q.set(e[o],n,s)}x.time("projection-elemsMatch")}}return b.$aggregate&&(x.data("flag.aggregate",!0),x.time("aggregate"),u=new h(b.$aggregate),e=u.value(e),x.time("aggregate")),x.stop(),e.__fdbOp=x,e.$cursor=G,e},o.prototype.findOne=function(){return this.find.apply(this,arguments)[0]},o.prototype.indexOf=function(a,b){var c,d=this.find(a,{$decouple:!1})[0];return d?!b||<span class="branch-1 cbranch-no" title="branch not covered" >b&</span>&<span class="branch-2 cbranch-no" title="branch not covered" >!b.$orderBy?</span>this._data.indexOf(d):(<span class="branch-1 cbranch-no" title="branch not covered" >b.$decouple=!1,c=this.find(a,b),c.indexOf(d))</span>:<span class="branch-1 cbranch-no" title="branch not covered" >-1}</span>,o.prototype.indexOfDocById=function(a,b){var c,d;return c="object"!=typeof a?this._primaryIndex.get(a):this._primaryIndex.get(a[this._primaryKey]),c?!b||<span class="branch-1 cbranch-no" title="branch not covered" >b&</span>&<span class="branch-2 cbranch-no" title="branch not covered" >!b.$orderBy?</span>this._data.indexOf(c):(<span class="branch-1 cbranch-no" title="branch not c