|
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)) |
|
|
|
|
|
|
7
|
|
|
t[p] = s[p]; |
|
|
|
|
|
|
8
|
|
|
} |
|
9
|
|
|
return t; |
|
10
|
|
|
}; |
|
11
|
|
|
return __assign.apply(this, arguments); |
|
12
|
|
|
}; |
|
13
|
|
View Code Duplication |
var __rest = (this && this.__rest) || function (s, e) { |
|
|
|
|
|
|
14
|
|
|
var t = {}; |
|
15
|
|
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) |
|
|
|
|
|
|
16
|
|
|
t[p] = s[p]; |
|
|
|
|
|
|
17
|
|
|
if (s != null && typeof Object.getOwnPropertySymbols === "function") |
|
|
|
|
|
|
18
|
|
|
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { |
|
|
|
|
|
|
19
|
|
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) |
|
20
|
|
|
t[p[i]] = s[p[i]]; |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
return t; |
|
23
|
|
|
}; |
|
24
|
|
|
var __importStar = (this && this.__importStar) || function (mod) { |
|
25
|
|
|
if (mod && mod.__esModule) return mod; |
|
|
|
|
|
|
26
|
|
|
var result = {}; |
|
27
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
|
|
|
|
|
|
28
|
|
|
result["default"] = mod; |
|
29
|
|
|
return result; |
|
30
|
|
|
}; |
|
31
|
|
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
32
|
|
|
var t = __importStar(require("io-ts")); |
|
33
|
|
|
var ArrayC_1 = require("./io/ArrayC"); |
|
34
|
|
|
var EntityC_1 = require("./io/EntityC"); |
|
35
|
|
|
var Resource_1 = require("./Resource"); |
|
36
|
|
|
var fromRecord = function (_a, relationships) { |
|
37
|
|
|
var _type = _a._type, _id = _a._id, attributes = __rest(_a, ["_type", "_id"]); |
|
38
|
|
|
return (__assign(__assign(__assign({}, (EntityC_1.EntityC.is({ _type: _type, _id: _id }) |
|
39
|
|
|
? { |
|
40
|
|
|
type: '' + _type, |
|
41
|
|
|
id: '' + _id |
|
42
|
|
|
} |
|
43
|
|
|
: null)), (Object.keys(attributes).length > 0 |
|
44
|
|
|
? { attributes: attributes } |
|
45
|
|
|
: null)), (Object.keys(relationships).length > 0 |
|
46
|
|
|
? { |
|
47
|
|
|
relationships: Object.keys(relationships) |
|
48
|
|
|
.reduce(function (carry, key) { |
|
49
|
|
|
var _a; |
|
50
|
|
|
var resource = relationships[key]; |
|
51
|
|
|
return __assign(__assign({}, carry), (_a = {}, _a[key] = { |
|
|
|
|
|
|
52
|
|
|
data: ArrayC_1.ArrayC().is(resource) |
|
53
|
|
|
? resource.map(Resource_1.Resource.lens.identifier.get) |
|
54
|
|
|
: Resource_1.Resource.lens.identifier.get(resource) |
|
55
|
|
|
}, _a)); |
|
56
|
|
|
}, {}) |
|
57
|
|
|
} |
|
58
|
|
|
: null))); |
|
59
|
|
|
}; |
|
60
|
|
|
var fromJson = function (u, relationships) { |
|
61
|
|
|
return t.UnknownRecord.is(u) |
|
62
|
|
|
? fromRecord(u, relationships) |
|
63
|
|
|
: u; |
|
64
|
|
|
}; |
|
65
|
|
|
exports.JsonApiData = { |
|
66
|
|
|
fromJson: fromJson |
|
67
|
|
|
}; |
|
68
|
|
|
|
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 you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.