iridium
Version:
A custom lightweight ORM for MongoDB designed for power-users
238 lines (236 loc) • 8.11 kB
HTML
<html lang="en">
<head>
<title>Code coverage report for dist\lib\ModelHelpers.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\ModelHelpers.js</span></h1>
<h2>
Statements: <span class="metric">100% <small>(28 / 28)</small></span>
Branches: <span class="metric">100% <small>(2 / 2)</small></span>
Functions: <span class="metric">100% <small>(8 / 8)</small></span>
Lines: <span class="metric">100% <small>(27 / 27)</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">dist/lib/</a> » ModelHelpers.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</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-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">31</span>
<span class="cline-any cline-yes">31</span>
<span class="cline-any cline-yes">31</span>
<span class="cline-any cline-yes">31</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">249</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">397</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">580</span>
<span class="cline-any cline-yes">603</span>
<span class="cline-any cline-yes">27</span>
<span class="cline-any cline-yes">580</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">580</span>
<span class="cline-any cline-yes">580</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">18</span>
<span class="cline-any cline-yes">18</span>
<span class="cline-any cline-yes">18</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">var skmatc = require('skmatc');
var Omnom_1 = require('./utils/Omnom');
var _ = require('lodash');
var ModelHelpers = (function () {
function ModelHelpers(model) {
var _this = this;
this.model = model;
this._validator = new skmatc(model.schema);
model.validators.forEach(function (validator) { return _this._validator.register(validator); });
}
/**
* Validates a document to ensure that it matches the model's ISchema requirements
* @param {any} document The document to validate against the ISchema
* @returns {SkmatcCore.IResult} The result of the validation
*/
ModelHelpers.prototype.validate = function (document) {
return this._validator.validate(document);
};
/**
* Wraps the given document in an instance wrapper for use throughout the application
* @param {any} document The document to be wrapped as an instance
* @param {Boolean} isNew Whether the instance originated from the database or was created by the application
* @param {Boolean} isPartial Whether the document supplied contains all information present in the database
* @returns {any} An instance which wraps this document
*/
ModelHelpers.prototype.wrapDocument = function (document, isNew, isPartial) {
return new this.model.Instance(document, isNew, isPartial);
};
/**
* Converts the given document to its database form into a form
* using the transforms defined on the model.
* @param {any} document The document to be converted
* @returns {any} A new document cloned from the original and transformed
*/
ModelHelpers.prototype.transformToDB = function (document) {
for (var property in this.model.transforms)
if (document.hasOwnProperty(property))
document[property] = this.model.transforms[property].toDB(document[property]);
return document;
};
/**
* Converts the given document to its database form into a form
* using the transforms defined on the model.
* @param {any} document The document to be converted
* @returns {any} A new document cloned from the original and transformed
*/
ModelHelpers.prototype.convertToDB = function (document) {
var doc = _.cloneDeep(document);
return this.transformToDB(doc);
};
/**
* Performs a diff operation between two documents and creates a MongoDB changes object to represent the differences
* @param {any} original The original document prior to changes being made
* @param {any} modified The document after changes were made
*/
ModelHelpers.prototype.diff = function (original, modified) {
var omnom = new Omnom_1.default();
omnom.diff(original, modified);
return omnom.changes;
};
return ModelHelpers;
})();
exports.default = ModelHelpers;
//# sourceMappingURL=../lib/ModelHelpers.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>