Passed
Push — master ( 850f91...109844 )
by Alberto
04:39 queued 02:29
created

lib/Document.js   A

Complexity

Total Complexity 8
Complexity/F 2

Size

Lines of Code 26
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 21
mnd 4
bc 4
fnc 4
dl 0
loc 26
bpm 1
cpm 2
noi 3
c 0
b 0
f 0
rs 10
1
"use strict";
2
var __assign = (this && this.__assign) || function () {
3
    __assign = Object.assign || function(t) {
4
        for (var s, i = 1, n = arguments.length; i < n; i++) {
5
            s = arguments[i];
6
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
7
                t[p] = s[p];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8
        }
9
        return t;
10
    };
11
    return __assign.apply(this, arguments);
12
};
13
Object.defineProperty(exports, "__esModule", { value: true });
14
var CompoundDocument_1 = require("./CompoundDocument");
15
var RelationshipsCache_1 = require("./RelationshipsCache");
16
var fromCompoundDocument = function (w) {
17
    var _a = w(), data = _a[0], relationships = _a[1];
18
    var cache = RelationshipsCache_1.RelationshipsCache.fromRelationships(relationships);
19
    var included = Object.values(RelationshipsCache_1.RelationshipsCache.lens.global.get(cache));
20
    return __assign({ data: data }, (included.length > 0 ? { included: included } : null));
21
};
22
var fromJson = function (u) { return fromCompoundDocument(CompoundDocument_1.CompoundDocument.fromJson(u, true)); };
23
exports.Document = {
24
    fromCompoundDocument: fromCompoundDocument,
25
    fromJson: fromJson
26
};
27