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

lib/RelationshipsCache.js   A

Complexity

Total Complexity 27
Complexity/F 1.42

Size

Lines of Code 66
Function Count 19

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 27
eloc 53
mnd 8
bc 8
fnc 19
dl 0
loc 66
bpm 0.421
cpm 1.421
noi 8
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
var __spreadArrays = (this && this.__spreadArrays) || function () {
14
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
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...
15
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 14. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
16
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
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...
17
            r[k] = a[j];
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...
18
    return r;
19
};
20
Object.defineProperty(exports, "__esModule", { value: true });
21
var monocle_ts_1 = require("monocle-ts");
22
var ArrayC_1 = require("./io/ArrayC");
23
var RelationshipsCacheC_1 = require("./io/RelationshipsCacheC");
24
var RelationshipsRecord_1 = require("./RelationshipsRecord");
25
var ResourceIdentifier_1 = require("./ResourceIdentifier");
26
var fromRelationships = function (x) {
27
    return RelationshipsCacheC_1.RelationshipsCacheC.is(x)
28
        ? x
29
        : [0, {}, x];
30
};
31
var lenses = {
32
    counter: new monocle_ts_1.Lens(function (s) { return s[0]; }, function (a) { return function (s) { return ([a, s[1], s[2]]); }; }),
33
    global: new monocle_ts_1.Lens(function (s) { return s[1]; }, function (a) { return function (s) { return ([s[0], a, s[2]]); }; }),
34
    local: new monocle_ts_1.Lens(function (s) { return s[2]; }, function (a) { return function (s) { return ([s[0], s[1], a]); }; })
35
};
36
var monoid = {
37
    empty: [0, {}, {}],
38
    concat: function (x, y) {
39
        var _a = [x, y].map(fromRelationships), xs = _a[0], ys = _a[1];
40
        var locals = Object.values(lenses.local.get(ys))
41
            .reduce(function (array, item) { return (__spreadArrays(array, (ArrayC_1.ArrayC().is(item) ? item : [item]))); }, []);
42
        return [
43
            lenses.counter.get(xs) + (lenses.counter.get(ys) || locals.length),
44
            __assign(__assign(__assign({}, lenses.global.get(xs)), lenses.global.get(ys)), locals.reduce(function (record, identifier) {
45
                var _a;
46
                return (__assign(__assign({}, record), (_a = {}, _a[ResourceIdentifier_1.ResourceIdentifier.iso.string.get(identifier)] = identifier, _a)));
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
47
            }, {})),
48
            __assign(__assign({}, lenses.local.get(xs)), lenses.local.get(ys))
49
        ];
50
    }
51
};
52
exports.RelationshipsCache = {
53
    fromRelationships: fromRelationships,
54
    emptyLocal: function (cache) {
55
        return lenses.local.set({})(fromRelationships(cache));
56
    },
57
    nestLocal: function (cache, key) {
58
        return (function (cache) {
59
            return lenses.local.set(RelationshipsRecord_1.RelationshipsRecord.nest(lenses.local.get(cache), key))(cache);
60
        })(fromRelationships(cache));
61
    },
62
    lens: lenses,
63
    monoid: {
64
        self: monoid
65
    }
66
};
67