UNPKG

iridium

Version:

A custom lightweight ORM for MongoDB designed for power-users

475 lines (473 loc) 16.8 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for dist\lib\Cursor.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 high"> <h1>Code coverage report for <span class="entity">dist\lib\Cursor.js</span></h1> <h2> Statements: <span class="metric">92.42% <small>(61 / 66)</small></span> &nbsp;&nbsp;&nbsp;&nbsp; Branches: <span class="metric">58.33% <small>(7 / 12)</small></span> &nbsp;&nbsp;&nbsp;&nbsp; Functions: <span class="metric">100% <small>(29 / 29)</small></span> &nbsp;&nbsp;&nbsp;&nbsp; Lines: <span class="metric">91.94% <small>(57 / 62)</small></span> &nbsp;&nbsp;&nbsp;&nbsp; Ignored: <span class="metric"><span class="ignore-none">none</span></span> &nbsp;&nbsp;&nbsp;&nbsp; </h2> <div class="path"><a href="../../index.html">All files</a> &#187; <a href="index.html">dist/lib/</a> &#187; Cursor.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 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144</td><td class="line-coverage"><span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">44</span> <span class="cline-any cline-yes">44</span> <span class="cline-any cline-yes">44</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-yes">20</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-yes">5</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">9</span> <span class="cline-any cline-yes">9</span> <span class="cline-any cline-yes">9</span> <span class="cline-any cline-yes">9</span> <span class="cline-any cline-yes">9</span> <span class="cline-any cline-yes">37</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">9</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-yes">9</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">15</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">7</span> <span class="cline-any cline-yes">7</span> <span class="cline-any cline-yes">7</span> <span class="cline-any cline-yes">7</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-yes">7</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">7</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">6</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">3</span> <span class="cline-any cline-yes">3</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">3</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">3</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-yes">2</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var Bluebird = require('bluebird'); var Cursor = (function () { /** * Creates a new Iridium cursor which wraps a MongoDB cursor object * @param {Model} model The Iridium model that this cursor belongs to * @param {Object} conditions The conditions that resulte in this cursor being created * @param {MongoDB.Cursor} cursor The MongoDB native cursor object to be wrapped * @constructor */ function Cursor(model, conditions, cursor) { this.model = model; this.conditions = conditions; this.cursor = cursor; } /** * Counts the number of documents which are matched by this cursor * @param {function(Error, Number)} callback A callback which is triggered when the result is available * @return {Promise&lt;number&gt;} A promise which will resolve with the number of documents matched by this cursor */ Cursor.prototype.count = function (callback) { var _this = this; return new Bluebird(function (resolve, reject) { _this.cursor.count(true, function (err, count) { <span class="missing-if-branch" title="if path not taken" >I</span>if (err) <span class="cstat-no" title="statement not covered" > return reject(err);</span> return resolve(count); }); }).nodeify(callback); }; /** * Runs the specified handler over each instance in the query results * @param {function(Instance)} handler The handler which is triggered for each element in the query * @param {function(Error)} callback A callback which is triggered when all operations have been dispatched * @return {Promise} A promise which is resolved when all operations have been dispatched */ Cursor.prototype.forEach = function (handler, callback) { var _this = this; var helpers = this.model.helpers; return new Bluebird(function (resolve, reject) { _this.cursor.forEach(function (item) { _this.model.handlers.documentReceived(_this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); }).then(handler); }, function (err) { <span class="missing-if-branch" title="if path not taken" >I</span>if (err) <span class="cstat-no" title="statement not covered" > return reject(err);</span> return resolve(null); }); }).nodeify(callback); }; /** * Runs the specified transform over each instance in the query results and returns the resulting transformed objects * @param {function(Instance): TResult} transform A handler which is used to transform the result objects * @param {function(Error, TResult[])} callback A callback which is triggered when the transformations are completed * @return {Promise&lt;TResult[]&gt;} A promise which is fulfilled with the results of the transformations */ Cursor.prototype.map = function (transform, callback) { var _this = this; var helpers = this.model.helpers; return new Bluebird(function (resolve, reject) { var promises = []; _this.cursor.forEach(function (item) { promises.push(_this.model.handlers.documentReceived(_this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); }) .then(transform)); }, function (err) { <span class="missing-if-branch" title="if path not taken" >I</span>if (err) <span class="cstat-no" title="statement not covered" > return reject(err);</span> return resolve(Bluebird.all(promises)); }); }).nodeify(callback); }; /** * Retrieves all matching instances and returns them in an array * @param {function(Error, TInstance[])} callback A callback which is triggered with the resulting instances * @return {Promise&lt;TInstance[]&gt;} A promise which resolves with the instances returned by the query */ Cursor.prototype.toArray = function (callback) { var _this = this; var helpers = this.model.helpers; return new Bluebird(function (resolve, reject) { _this.cursor.toArray(function (err, results) { <span class="missing-if-branch" title="if path not taken" >I</span>if (err) <span class="cstat-no" title="statement not covered" > return reject(err);</span> return resolve(results); }); }).map(function (document) { return _this.model.handlers.documentReceived(_this.conditions, document, function () { return helpers.wrapDocument.apply(helpers, arguments); }); }).nodeify(callback); }; /** * Retrieves the next item in the results list * @param {function(Error, TInstance)} callback A callback which is triggered when the next item becomes available * @return {Promise&lt;TInstance&gt;} A promise which is resolved with the next item */ Cursor.prototype.next = function (callback) { var _this = this; return new Bluebird(function (resolve, reject) { _this.cursor.next(function (err, result) { <span class="missing-if-branch" title="if path not taken" >I</span>if (err) <span class="cstat-no" title="statement not covered" > return reject(err);</span> return resolve(result); }); }).then(function (document) { if (!document) return Bluebird.resolve(null); return _this.model.handlers.documentReceived(_this.conditions, document, function (document, isNew, isPartial) { return _this.model.helpers.wrapDocument(document, isNew, isPartial); }); }).nodeify(callback); }; /** * Returns a new cursor which behaves the same as this one did before any results were retrieved * @return {Cursor} The new cursor which starts at the beginning of the results */ Cursor.prototype.rewind = function () { this.cursor.rewind(); return this; }; /** * Returns a new cursor which sorts its results by the given index expression * @param {model.IndexSpecification} sortExpression The index expression dictating the sort order and direction to use * @return {Cursor} The new cursor which sorts its results by the sortExpression */ Cursor.prototype.sort = function (sortExpression) { return new Cursor(this.model, this.conditions, this.cursor.sort(sortExpression)); }; /** * Returns a new cursor which limits the number of returned results * @param {Number} limit The maximum number of results to return * @return {Cursor} The new cursor which will return a maximum number of results */ Cursor.prototype.limit = function (limit) { return new Cursor(this.model, this.conditions, this.cursor.limit(limit)); }; /** * Returns a new cursor which skips a number of results before it begins * returning any. * @param {Number} skip The number of results to skip before the cursor beings returning * @return {Cursor} The new cursor which skips a number of results */ Cursor.prototype.skip = function (skip) { return new Cursor(this.model, this.conditions, this.cursor.skip(skip)); }; return Cursor; })(); exports.default = Cursor; &nbsp; //# sourceMappingURL=../lib/Cursor.js.map</pre></td></tr> </table></pre> </div> <div class="footer"> <div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Thu Jun 18 2015 15:09:28 GMT+0200 (South Africa Standard Time)</div> </div> <script src="../../prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="../../sorter.js"></script> </body> </html>