| Total Complexity | 11 |
| Complexity/F | 1.38 |
| Lines of Code | 56 |
| Function Count | 8 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | const check = require('check-types'); |
||
| 2 | |||
| 3 | /** |
||
| 4 | * A node object represents a node in a graph. |
||
| 5 | */ |
||
| 6 | class JGFNode { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Constructor |
||
| 10 | * @param {string} id Primary key for the node, that is unique for the object type. |
||
| 11 | * @param {string} label A text display for the node. |
||
| 12 | * @param {object,null} metadata Metadata about the node. |
||
| 13 | */ |
||
| 14 | constructor(id, label, metadata = null) { |
||
| 15 | this._id = id; |
||
| 16 | this._label = label; |
||
| 17 | this.metadata = metadata; |
||
| 18 | } |
||
| 19 | |||
| 20 | static _guardAgainstInvalidMetaData(metadata) { |
||
| 21 | if (!check.nonEmptyObject(metadata)) { |
||
| 22 | throw Error('Metadata on an node has to be an object.'); |
||
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | set id(id) { |
||
| 27 | this._id = id; |
||
| 28 | } |
||
| 29 | |||
| 30 | get id() { |
||
| 31 | return this._id; |
||
| 32 | } |
||
| 33 | |||
| 34 | set label(label) { |
||
| 35 | this._label = label; |
||
| 36 | } |
||
| 37 | |||
| 38 | get label() { |
||
| 39 | return this._label; |
||
| 40 | } |
||
| 41 | |||
| 42 | set metadata(metadata) { |
||
| 43 | if (check.assigned(metadata)) { |
||
| 44 | JGFNode._guardAgainstInvalidMetaData(metadata); |
||
| 45 | } |
||
| 46 | this._metadata = metadata; |
||
| 47 | } |
||
| 48 | |||
| 49 | get metadata() { |
||
| 50 | return this._metadata; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | module.exports = { |
||
| 55 | JGFNode, |
||
| 56 | }; |