Total Complexity | 5 |
Complexity/F | 1.67 |
Lines of Code | 35 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | const check = require('check-types'); |
||
2 | const { Guard } = require('./guard'); |
||
3 | |||
4 | /** |
||
5 | * A node object represents a node in a graph. |
||
6 | */ |
||
7 | class JGFNode { |
||
8 | |||
9 | /** |
||
10 | * Constructor |
||
11 | * @param {string} id Primary key for the node, that is unique for the object type. |
||
12 | * @param {string} label A text display for the node. |
||
13 | * @param {object,null} metadata Metadata about the node. |
||
14 | */ |
||
15 | constructor(id, label, metadata = null) { |
||
16 | this.id = id; |
||
17 | this.label = label; |
||
18 | this.metadata = metadata; |
||
19 | } |
||
20 | |||
21 | set metadata(metadata) { |
||
22 | if (check.assigned(metadata)) { |
||
23 | Guard.assertValidMetadata(metadata); |
||
24 | } |
||
25 | this._metadata = metadata; |
||
26 | } |
||
27 | |||
28 | get metadata() { |
||
29 | return this._metadata; |
||
30 | } |
||
31 | } |
||
32 | |||
33 | module.exports = { |
||
34 | JGFNode, |
||
35 | }; |