raain-model 2.6.8 → 2.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/.cursorignore +10 -0
  2. package/.github/workflows/ci.yml +29 -0
  3. package/CHANGELOG.md +166 -0
  4. package/LICENSE +21 -0
  5. package/README.md +5 -3
  6. package/RELEASE_PROCESS.md +111 -0
  7. package/package.json +1 -1
  8. package/specs/REQUIREMENTS.md +42 -0
  9. package/specs/TECHNICAL.md +57 -0
  10. package/specs/cartesian/Cartesian.spec.ts +82 -0
  11. package/specs/cartesian/CartesianTools.spec.ts +121 -0
  12. package/specs/gauge/Gauge.spec.ts +39 -0
  13. package/specs/organization/Organization.spec.ts +38 -0
  14. package/specs/polar/Polar.spec.ts +267 -0
  15. package/specs/quality/Position.spec.ts +18 -0
  16. package/specs/quality/QualityPointEdgeCases.spec.ts +215 -0
  17. package/specs/quality/QualityTools.spec.ts +67 -0
  18. package/specs/quality/SpeedMatrix.spec.ts +214 -0
  19. package/specs/radar/Radar.spec.ts +129 -0
  20. package/specs/rain/Rain.spec.ts +334 -0
  21. package/specs/tsconfig.json +12 -0
  22. package/{cartesian/CartesianMeasureValue.js → src/cartesian/CartesianMeasureValue.ts} +73 -41
  23. package/{cartesian/CartesianTools.js → src/cartesian/CartesianTools.ts} +130 -69
  24. package/src/cartesian/CartesianValue.ts +26 -0
  25. package/src/cartesian/EarthMap.ts +5 -0
  26. package/src/cartesian/ICartesianMeasureValue.ts +22 -0
  27. package/src/cartesian/LatLng.ts +43 -0
  28. package/src/cartesian/RadarCartesianMeasureValue.ts +32 -0
  29. package/src/cartesian/RainCartesianMeasureValue.ts +32 -0
  30. package/src/gauge/GaugeMeasure.ts +42 -0
  31. package/{gauge/GaugeNode.js → src/gauge/GaugeNode.ts} +48 -20
  32. package/src/gauge/GaugeNodeMap.ts +55 -0
  33. package/src/organization/EventNode.ts +43 -0
  34. package/{organization/Link.js → src/organization/Link.ts} +15 -15
  35. package/src/organization/Measure.ts +61 -0
  36. package/{organization/PeopleNode.js → src/organization/PeopleNode.ts} +20 -10
  37. package/{organization/RaainNode.js → src/organization/RaainNode.ts} +91 -58
  38. package/{organization/TeamNode.js → src/organization/TeamNode.ts} +36 -13
  39. package/{polar/AbstractPolarMeasureValue.js → src/polar/AbstractPolarMeasureValue.ts} +58 -32
  40. package/src/polar/IPolarMeasureValue.ts +21 -0
  41. package/{polar/MeasureValuePolarContainer.js → src/polar/MeasureValuePolarContainer.ts} +29 -13
  42. package/src/polar/PolarFilter.ts +46 -0
  43. package/{polar/PolarMeasureValue.js → src/polar/PolarMeasureValue.ts} +125 -62
  44. package/{polar/PolarMeasureValueMap.js → src/polar/PolarMeasureValueMap.ts} +165 -88
  45. package/src/polar/PolarValue.ts +16 -0
  46. package/{polar/RadarPolarMeasureValue.js → src/polar/RadarPolarMeasureValue.ts} +34 -21
  47. package/src/polar/RainPolarMeasureValue.ts +57 -0
  48. package/{quality/QualityPoint.js → src/quality/QualityPoint.ts} +62 -34
  49. package/{quality/SpeedMatrix.js → src/quality/SpeedMatrix.ts} +117 -76
  50. package/{quality/SpeedMatrixContainer.js → src/quality/SpeedMatrixContainer.ts} +210 -103
  51. package/src/quality/history/CartesianGaugeHistory.ts +23 -0
  52. package/src/quality/history/CartesianRainHistory.ts +15 -0
  53. package/src/quality/history/PositionHistory.ts +31 -0
  54. package/{quality/index.d.ts → src/quality/index.ts} +3 -0
  55. package/src/quality/position/Position.ts +59 -0
  56. package/src/quality/position/PositionValue.ts +15 -0
  57. package/{quality/tools/QualityTools.js → src/quality/tools/QualityTools.ts} +18 -17
  58. package/src/radar/RadarMeasure.ts +41 -0
  59. package/{radar/RadarNode.js → src/radar/RadarNode.ts} +41 -19
  60. package/src/radar/RadarNodeMap.ts +61 -0
  61. package/src/rain/MergeStrategy.ts +15 -0
  62. package/src/rain/RainComputation.ts +96 -0
  63. package/{rain/RainComputationAbstract.js → src/rain/RainComputationAbstract.ts} +135 -69
  64. package/{rain/RainComputationMap.js → src/rain/RainComputationMap.ts} +55 -22
  65. package/{rain/RainComputationQuality.js → src/rain/RainComputationQuality.ts} +82 -44
  66. package/src/rain/RainMeasure.ts +25 -0
  67. package/{rain/RainNode.js → src/rain/RainNode.ts} +117 -72
  68. package/tsconfig.json +17 -0
  69. package/tslint.json +79 -0
  70. package/typedoc.json +31 -0
  71. package/cartesian/CartesianMeasureValue.d.ts +0 -40
  72. package/cartesian/CartesianMeasureValue.js.map +0 -1
  73. package/cartesian/CartesianTools.d.ts +0 -32
  74. package/cartesian/CartesianTools.js.map +0 -1
  75. package/cartesian/CartesianValue.d.ts +0 -14
  76. package/cartesian/CartesianValue.js +0 -17
  77. package/cartesian/CartesianValue.js.map +0 -1
  78. package/cartesian/EarthMap.d.ts +0 -5
  79. package/cartesian/EarthMap.js +0 -3
  80. package/cartesian/EarthMap.js.map +0 -1
  81. package/cartesian/ICartesianMeasureValue.d.ts +0 -23
  82. package/cartesian/ICartesianMeasureValue.js +0 -3
  83. package/cartesian/ICartesianMeasureValue.js.map +0 -1
  84. package/cartesian/LatLng.d.ts +0 -16
  85. package/cartesian/LatLng.js +0 -34
  86. package/cartesian/LatLng.js.map +0 -1
  87. package/cartesian/RadarCartesianMeasureValue.d.ts +0 -17
  88. package/cartesian/RadarCartesianMeasureValue.js +0 -22
  89. package/cartesian/RadarCartesianMeasureValue.js.map +0 -1
  90. package/cartesian/RainCartesianMeasureValue.d.ts +0 -17
  91. package/cartesian/RainCartesianMeasureValue.js +0 -23
  92. package/cartesian/RainCartesianMeasureValue.js.map +0 -1
  93. package/cartesian/index.js +0 -25
  94. package/cartesian/index.js.map +0 -1
  95. package/gauge/GaugeMeasure.d.ts +0 -20
  96. package/gauge/GaugeMeasure.js +0 -30
  97. package/gauge/GaugeMeasure.js.map +0 -1
  98. package/gauge/GaugeNode.d.ts +0 -85
  99. package/gauge/GaugeNode.js.map +0 -1
  100. package/gauge/GaugeNodeMap.d.ts +0 -24
  101. package/gauge/GaugeNodeMap.js +0 -40
  102. package/gauge/GaugeNodeMap.js.map +0 -1
  103. package/gauge/index.js +0 -20
  104. package/gauge/index.js.map +0 -1
  105. package/index.js +0 -24
  106. package/index.js.map +0 -1
  107. package/organization/EventNode.d.ts +0 -22
  108. package/organization/EventNode.js +0 -30
  109. package/organization/EventNode.js.map +0 -1
  110. package/organization/IVersion.js +0 -3
  111. package/organization/IVersion.js.map +0 -1
  112. package/organization/Link.d.ts +0 -16
  113. package/organization/Link.js.map +0 -1
  114. package/organization/Measure.d.ts +0 -22
  115. package/organization/Measure.js +0 -45
  116. package/organization/Measure.js.map +0 -1
  117. package/organization/PeopleNode.d.ts +0 -18
  118. package/organization/PeopleNode.js.map +0 -1
  119. package/organization/RaainNode.d.ts +0 -96
  120. package/organization/RaainNode.js.map +0 -1
  121. package/organization/TeamNode.d.ts +0 -63
  122. package/organization/TeamNode.js.map +0 -1
  123. package/organization/index.js +0 -24
  124. package/organization/index.js.map +0 -1
  125. package/polar/AbstractPolarMeasureValue.d.ts +0 -29
  126. package/polar/AbstractPolarMeasureValue.js.map +0 -1
  127. package/polar/IPolarMeasureValue.d.ts +0 -19
  128. package/polar/IPolarMeasureValue.js +0 -3
  129. package/polar/IPolarMeasureValue.js.map +0 -1
  130. package/polar/MeasureValuePolarContainer.d.ts +0 -19
  131. package/polar/MeasureValuePolarContainer.js.map +0 -1
  132. package/polar/PolarFilter.d.ts +0 -16
  133. package/polar/PolarFilter.js +0 -45
  134. package/polar/PolarFilter.js.map +0 -1
  135. package/polar/PolarMeasureValue.d.ts +0 -51
  136. package/polar/PolarMeasureValue.js.map +0 -1
  137. package/polar/PolarMeasureValueMap.d.ts +0 -45
  138. package/polar/PolarMeasureValueMap.js.map +0 -1
  139. package/polar/PolarValue.d.ts +0 -10
  140. package/polar/PolarValue.js +0 -12
  141. package/polar/PolarValue.js.map +0 -1
  142. package/polar/RadarPolarMeasureValue.d.ts +0 -27
  143. package/polar/RadarPolarMeasureValue.js.map +0 -1
  144. package/polar/RainPolarMeasureValue.d.ts +0 -20
  145. package/polar/RainPolarMeasureValue.js +0 -42
  146. package/polar/RainPolarMeasureValue.js.map +0 -1
  147. package/polar/index.js +0 -25
  148. package/polar/index.js.map +0 -1
  149. package/quality/QualityPoint.d.ts +0 -37
  150. package/quality/QualityPoint.js.map +0 -1
  151. package/quality/SpeedMatrix.d.ts +0 -83
  152. package/quality/SpeedMatrix.js.map +0 -1
  153. package/quality/SpeedMatrixContainer.d.ts +0 -102
  154. package/quality/SpeedMatrixContainer.js.map +0 -1
  155. package/quality/history/CartesianGaugeHistory.d.ts +0 -15
  156. package/quality/history/CartesianGaugeHistory.js +0 -14
  157. package/quality/history/CartesianGaugeHistory.js.map +0 -1
  158. package/quality/history/CartesianRainHistory.d.ts +0 -9
  159. package/quality/history/CartesianRainHistory.js +0 -11
  160. package/quality/history/CartesianRainHistory.js.map +0 -1
  161. package/quality/history/PositionHistory.d.ts +0 -20
  162. package/quality/history/PositionHistory.js +0 -17
  163. package/quality/history/PositionHistory.js.map +0 -1
  164. package/quality/index.js +0 -26
  165. package/quality/index.js.map +0 -1
  166. package/quality/position/Position.d.ts +0 -22
  167. package/quality/position/Position.js +0 -50
  168. package/quality/position/Position.js.map +0 -1
  169. package/quality/position/PositionValue.d.ts +0 -9
  170. package/quality/position/PositionValue.js +0 -12
  171. package/quality/position/PositionValue.js.map +0 -1
  172. package/quality/tools/QualityTools.d.ts +0 -9
  173. package/quality/tools/QualityTools.js.map +0 -1
  174. package/radar/RadarMeasure.d.ts +0 -19
  175. package/radar/RadarMeasure.js +0 -30
  176. package/radar/RadarMeasure.js.map +0 -1
  177. package/radar/RadarNode.d.ts +0 -30
  178. package/radar/RadarNode.js.map +0 -1
  179. package/radar/RadarNodeMap.d.ts +0 -26
  180. package/radar/RadarNodeMap.js +0 -44
  181. package/radar/RadarNodeMap.js.map +0 -1
  182. package/radar/index.js +0 -20
  183. package/radar/index.js.map +0 -1
  184. package/rain/MergeStrategy.d.ts +0 -13
  185. package/rain/MergeStrategy.js +0 -11
  186. package/rain/MergeStrategy.js.map +0 -1
  187. package/rain/RainComputation.d.ts +0 -42
  188. package/rain/RainComputation.js +0 -65
  189. package/rain/RainComputation.js.map +0 -1
  190. package/rain/RainComputationAbstract.d.ts +0 -73
  191. package/rain/RainComputationAbstract.js.map +0 -1
  192. package/rain/RainComputationMap.d.ts +0 -97
  193. package/rain/RainComputationMap.js.map +0 -1
  194. package/rain/RainComputationQuality.d.ts +0 -40
  195. package/rain/RainComputationQuality.js.map +0 -1
  196. package/rain/RainMeasure.d.ts +0 -17
  197. package/rain/RainMeasure.js +0 -18
  198. package/rain/RainMeasure.js.map +0 -1
  199. package/rain/RainNode.d.ts +0 -46
  200. package/rain/RainNode.js.map +0 -1
  201. package/rain/index.js +0 -23
  202. package/rain/index.js.map +0 -1
  203. /package/{cartesian/index.d.ts → src/cartesian/index.ts} +0 -0
  204. /package/{gauge/index.d.ts → src/gauge/index.ts} +0 -0
  205. /package/{index.d.ts → src/index.ts} +0 -0
  206. /package/{organization/IVersion.d.ts → src/organization/IVersion.ts} +0 -0
  207. /package/{organization/index.d.ts → src/organization/index.ts} +0 -0
  208. /package/{polar/index.d.ts → src/polar/index.ts} +0 -0
  209. /package/{radar/index.d.ts → src/radar/index.ts} +0 -0
  210. /package/{rain/index.d.ts → src/rain/index.ts} +0 -0
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GaugeNode = void 0;
4
- const organization_1 = require("../organization");
1
+ import {Link, RaainNode, TeamNode} from '../organization';
2
+
5
3
  /**
6
4
  * Represents a rain gauge station in the RAAIN system.
7
5
  * This class manages gauge data collection and configuration.
@@ -21,7 +19,29 @@ const organization_1 = require("../organization");
21
19
  * });
22
20
  * ```
23
21
  */
24
- class GaugeNode extends organization_1.RaainNode {
22
+ export class GaugeNode extends RaainNode {
23
+
24
+ /** Type identifier for gauge nodes */
25
+ public static TYPE = 'gauge';
26
+
27
+ /** Name of the gauge station */
28
+ public name: string;
29
+
30
+ /** Description of the gauge station */
31
+ public description: string;
32
+
33
+ /** Latitude of the gauge station */
34
+ public latitude: number;
35
+
36
+ /** Longitude of the gauge station */
37
+ public longitude: number;
38
+
39
+ /** Associated team */
40
+ public team: TeamNode;
41
+
42
+ /** Internal configuration storage */
43
+ private configurationAsJSON: string;
44
+
25
45
  /**
26
46
  * Creates a new GaugeNode instance.
27
47
  *
@@ -36,7 +56,17 @@ class GaugeNode extends organization_1.RaainNode {
36
56
  * @param json.version - Optional version string
37
57
  * @param json.configurationAsJSON - Optional configuration object
38
58
  */
39
- constructor(json) {
59
+ constructor(json: {
60
+ id: string,
61
+ latitude: number,
62
+ longitude: number,
63
+ name: string,
64
+ team: TeamNode,
65
+ description?: string,
66
+ links?: Link[] | RaainNode[],
67
+ version?: string,
68
+ configurationAsJSON?: any,
69
+ }) {
40
70
  super(json);
41
71
  this.latitude = json.latitude;
42
72
  this.longitude = json.longitude;
@@ -45,61 +75,59 @@ class GaugeNode extends organization_1.RaainNode {
45
75
  this.team = json.team;
46
76
  this.setConfiguration(json.configurationAsJSON);
47
77
  }
78
+
48
79
  /**
49
80
  * Sets the configuration for the gauge node.
50
81
  *
51
82
  * @param configuration - Configuration object or JSON string
52
83
  */
53
- setConfiguration(configuration) {
84
+ public setConfiguration(configuration: string | any) {
54
85
  let conf = configuration;
55
86
  try {
56
87
  conf = JSON.parse(configuration);
88
+ } catch (ignored) {
57
89
  }
58
- catch (ignored) {
59
- }
90
+
60
91
  if (conf) {
61
92
  this.configurationAsJSON = JSON.stringify(conf);
62
93
  }
63
94
  }
95
+
64
96
  /**
65
97
  * Gets the configuration of the gauge node.
66
98
  *
67
99
  * @returns The configuration object or null if not set
68
100
  */
69
- getConfiguration() {
101
+ public getConfiguration(): any {
70
102
  try {
71
103
  return JSON.parse(this.configurationAsJSON);
72
- }
73
- catch (e) {
104
+ } catch (e) {
74
105
  }
75
106
  return null;
76
107
  }
108
+
77
109
  /**
78
110
  * Converts the gauge node to a JSON object.
79
111
  *
80
112
  * @returns A JSON object containing the gauge node's data
81
113
  */
82
- toJSON() {
83
- var _a;
114
+ public toJSON(): any {
84
115
  const json = super.toJSON();
85
116
  json['name'] = this.name;
86
117
  json['description'] = this.description;
87
118
  json['latitude'] = this.latitude;
88
119
  json['longitude'] = this.longitude;
89
- json['team'] = ((_a = this.team) === null || _a === void 0 ? void 0 : _a.id) || this.team;
120
+ json['team'] = this.team?.id || this.team;
90
121
  json['configurationAsJSON'] = this.configurationAsJSON;
91
122
  return json;
92
123
  }
124
+
93
125
  /**
94
126
  * Returns the link type for gauge nodes.
95
127
  *
96
128
  * @returns The string 'gauge'
97
129
  */
98
- getLinkType() {
130
+ protected getLinkType(): string {
99
131
  return GaugeNode.TYPE;
100
132
  }
101
133
  }
102
- exports.GaugeNode = GaugeNode;
103
- /** Type identifier for gauge nodes */
104
- GaugeNode.TYPE = 'gauge';
105
- //# sourceMappingURL=GaugeNode.js.map
@@ -0,0 +1,55 @@
1
+ import {Link, RaainNode, TeamNode} from '../organization';
2
+ import {GaugeNode} from './GaugeNode';
3
+ import {GaugeMeasure} from './GaugeMeasure';
4
+
5
+ /**
6
+ * api/gauges/:id?format=map&begin=...
7
+ */
8
+ export class GaugeNodeMap extends GaugeNode {
9
+
10
+ private map: string; // GaugeMeasure[]; stringified
11
+
12
+ constructor(json: {
13
+ id: string,
14
+ latitude: number,
15
+ longitude: number,
16
+ name: string,
17
+ description: string,
18
+ team: TeamNode,
19
+ configurationAsJSON?: any,
20
+ map?: string,
21
+ links?: Link[] | RaainNode[],
22
+ version?: string,
23
+ }) {
24
+ super(json);
25
+ this.setMapData(json.map);
26
+ }
27
+
28
+ public toJSON(): any {
29
+ const json = super.toJSON();
30
+ json.map = this.map;
31
+ return json;
32
+ }
33
+
34
+ public setMapData(mapData: GaugeMeasure[] | string) {
35
+ if (!mapData) {
36
+ return;
37
+ }
38
+
39
+ let map = mapData;
40
+ try {
41
+ if (typeof (mapData) !== 'string') {
42
+ map = JSON.stringify(mapData);
43
+ }
44
+ } catch (e) {
45
+ }
46
+ this.map = map.toString();
47
+ }
48
+
49
+ public getMapData(): GaugeMeasure[] {
50
+ if (!this.map) {
51
+ return [];
52
+ }
53
+ return JSON.parse(this.map);
54
+ }
55
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * api/notifications/:id
3
+ */
4
+ export class EventNode {
5
+ public id: string;
6
+ public title: string;
7
+ public status: number;
8
+ public red: boolean;
9
+ public description: string;
10
+ public created: Date;
11
+ public modified: Date;
12
+
13
+ constructor(json: {
14
+ id: string,
15
+ title: string,
16
+ status: number,
17
+ red: boolean,
18
+ description: string,
19
+ created: Date,
20
+ modified: Date
21
+ }
22
+ ) {
23
+ this.id = json.id;
24
+ this.title = json.title;
25
+ this.status = json.status;
26
+ this.red = json.red;
27
+ this.description = json.description;
28
+ this.created = json.created;
29
+ this.modified = json.modified;
30
+ }
31
+
32
+ public toJSON(): any {
33
+ return {
34
+ id: this.id,
35
+ title: this.title,
36
+ status: this.status,
37
+ red: this.red,
38
+ description: this.description,
39
+ created: this.created,
40
+ modified: this.modified,
41
+ } as any;
42
+ }
43
+ }
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Link = void 0;
4
1
  /**
5
2
  * Hateoas Links :
6
3
  * [ {
@@ -8,31 +5,34 @@ exports.Link = void 0;
8
5
  * href: string // like "https://../rains/2"
9
6
  * },...]
10
7
  */
11
- class Link {
12
- constructor(rel, href) {
13
- this.rel = rel;
14
- this.href = href;
8
+ export class Link {
9
+ constructor(
10
+ public rel: string,
11
+ public href: string
12
+ ) {
15
13
  }
16
- static isCloneable(object) {
17
- return (object === null || object === void 0 ? void 0 : object.rel) && (object === null || object === void 0 ? void 0 : object.href);
14
+
15
+ public static isCloneable(object: any): boolean {
16
+ return object?.rel && object?.href;
18
17
  }
19
- static clone(object) {
20
- if (!(object === null || object === void 0 ? void 0 : object.rel) || !(object === null || object === void 0 ? void 0 : object.href)) {
18
+
19
+ public static clone(object: any): Link | null {
20
+ if (!object?.rel || !object?.href) {
21
21
  return null;
22
22
  }
23
23
  return new Link(object.rel, object.href);
24
24
  }
25
- getId() {
25
+
26
+ public getId(): string {
26
27
  const urls = this.href.split('/');
27
28
  // can be enforced : verify rel in -2 urls ?...
28
29
  return urls[urls.length - 1];
29
30
  }
30
- getLinkType() {
31
+
32
+ public getLinkType(): string {
31
33
  // const urls = this.href.split('/');
32
34
  // can be enforced : verify rel in -2 urls ?...
33
35
  // return urls[1].substring(0, urls[1].length - 1);
34
36
  return this.rel;
35
37
  }
36
38
  }
37
- exports.Link = Link;
38
- //# sourceMappingURL=Link.js.map
@@ -0,0 +1,61 @@
1
+ import {IPolarMeasureValue} from '../polar';
2
+ import {RaainNode} from './RaainNode';
3
+ import {ICartesianMeasureValue} from '../cartesian';
4
+
5
+ export class Measure extends RaainNode {
6
+ public date: Date;
7
+ // -> why array ? because you have different angle/axis from the Radar
8
+ public values: IPolarMeasureValue[] | ICartesianMeasureValue[] | number[];
9
+ public validity: number;
10
+
11
+ // internal
12
+ private configurationAsJSON: string;
13
+
14
+ constructor(json: {
15
+ id: string,
16
+ values: IPolarMeasureValue[] | ICartesianMeasureValue[] | number[],
17
+ date?: Date,
18
+ validity?: number,
19
+ configurationAsJSON?: string,
20
+ version?: string,
21
+ }
22
+ ) {
23
+ super(json);
24
+ this.values = json.values ? json.values : [];
25
+ this.date = json.date ? new Date(json.date) : undefined;
26
+ this.validity = json.validity >= 0 ? json.validity : -1;
27
+ this.setConfiguration(json.configurationAsJSON);
28
+ }
29
+
30
+ public setConfiguration(configuration: string | any) {
31
+ let conf = configuration;
32
+ try {
33
+ conf = JSON.parse(configuration);
34
+ } catch (ignored) {
35
+ }
36
+
37
+ if (conf) {
38
+ this.configurationAsJSON = JSON.stringify(conf);
39
+ }
40
+ }
41
+
42
+ public toJSON(options: { removeValues?: boolean } = {}): any {
43
+ const json = super.toJSON();
44
+ json['date'] = this.date?.toISOString();
45
+ json['validity'] = this.validity;
46
+ json['configurationAsJSON'] = this.configurationAsJSON;
47
+
48
+ if (!options?.removeValues) {
49
+ json['values'] = this.values;
50
+ }
51
+ return json;
52
+ }
53
+
54
+ public getConfiguration(): any {
55
+ try {
56
+ return JSON.parse(this.configurationAsJSON);
57
+ } catch (e) {
58
+ }
59
+ return null;
60
+ }
61
+ }
@@ -1,17 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PeopleNode = void 0;
4
1
  /**
5
2
  * api/teams/:id => contacts
6
3
  */
7
- class PeopleNode {
8
- constructor(json) {
4
+ export class PeopleNode {
5
+
6
+ public id: string;
7
+ public roles: string[];
8
+ public email: string;
9
+ public name: string;
10
+
11
+ constructor(json: {
12
+ id: string,
13
+ roles: string[],
14
+ email: string,
15
+ name: string,
16
+ }
17
+ ) {
9
18
  this.id = json.id;
10
19
  this.roles = json.roles;
11
20
  this.email = json.email;
12
21
  this.name = json.name;
13
22
  }
14
- toJSON() {
23
+
24
+ public toJSON(): any {
15
25
  return {
16
26
  id: this.id,
17
27
  roles: this.roles,
@@ -19,14 +29,14 @@ class PeopleNode {
19
29
  name: this.name,
20
30
  };
21
31
  }
22
- hasRole(role) {
32
+
33
+ hasRole(role: string): boolean {
23
34
  return this.roles.indexOf(role) >= 0;
24
35
  }
25
- addRole(role) {
36
+
37
+ addRole(role: string) {
26
38
  if (!this.hasRole(role)) {
27
39
  this.roles.push(role);
28
40
  }
29
41
  }
30
42
  }
31
- exports.PeopleNode = PeopleNode;
32
- //# sourceMappingURL=PeopleNode.js.map
@@ -1,7 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RaainNode = void 0;
4
- const Link_1 = require("./Link");
1
+ import {Link} from './Link';
2
+ import {IVersion} from './IVersion';
3
+
5
4
  /**
6
5
  * Base class for all RAAIN nodes in the system.
7
6
  * Implements versioning and link management functionality.
@@ -24,7 +23,12 @@ const Link_1 = require("./Link");
24
23
  * });
25
24
  * ```
26
25
  */
27
- class RaainNode {
26
+ export class RaainNode implements IVersion {
27
+ /** Unique identifier for the node */
28
+ public id: string;
29
+ /** Version string of the node */
30
+ public version: string;
31
+
28
32
  /**
29
33
  * Creates a new RaainNode instance.
30
34
  *
@@ -33,42 +37,69 @@ class RaainNode {
33
37
  * @param json.links - Array of HATEOAS links
34
38
  * @param json.version - Version string
35
39
  */
36
- constructor(json) {
37
- if (!(json === null || json === void 0 ? void 0 : json.id)) {
40
+ constructor(json: {
41
+ id: string,
42
+ links?: Link[] | RaainNode[],
43
+ version?: string,
44
+ }) {
45
+ if (!json?.id) {
38
46
  throw new Error('RaainNode needs a valid Object or ID');
39
47
  }
48
+
40
49
  this.id = json.id;
41
50
  this.links = json.links ? json.links : [];
42
51
  this.version = json.version ? json.version : undefined;
43
52
  }
44
- static _getPurifiedLinks(linksToPurify) {
53
+
54
+ /** Array of HATEOAS links associated with the node */
55
+ protected _links: Link[];
56
+
57
+ /**
58
+ * Gets all links associated with the node.
59
+ *
60
+ * @returns Array of HATEOAS links
61
+ */
62
+ public get links(): Link[] {
63
+ return this._links;
64
+ }
65
+
66
+ /**
67
+ * Sets the links for the node.
68
+ *
69
+ * @param links - Array of links to set
70
+ */
71
+ public set links(links: Link[] | RaainNode[]) {
72
+ this._links = RaainNode._getPurifiedLinks(links);
73
+ }
74
+
75
+ private static _getPurifiedLinks(linksToPurify: any[]): Link[] {
45
76
  if (!linksToPurify || linksToPurify.length === 0) {
46
77
  return [];
47
78
  }
79
+
48
80
  const linksPurified = linksToPurify
49
81
  .filter(l => l !== null && l !== undefined)
50
82
  .map(l => {
51
- var _a;
52
- if (l instanceof Link_1.Link || Link_1.Link.isCloneable(l)) {
53
- return Link_1.Link.clone(l);
54
- }
55
- else if (l && typeof l.getLinkType === 'function' && l.id) {
56
- const linkType = l.getLinkType();
57
- let href = '../' + linkType + 's';
58
- const l2 = l;
59
- if ((_a = l2.date) === null || _a === void 0 ? void 0 : _a.toISOString) {
60
- href += '/' + l2.date.toISOString();
61
- if (l2.version) {
62
- href += '/' + l2.version;
83
+ if (l instanceof Link || Link.isCloneable(l)) {
84
+ return Link.clone(l);
85
+ } else if (l && typeof l.getLinkType === 'function' && l.id) {
86
+ const linkType = l.getLinkType();
87
+ let href = '../' + linkType + 's';
88
+ const l2 = l;
89
+ if (l2.date?.toISOString) {
90
+ href += '/' + l2.date.toISOString();
91
+ if (l2.version) {
92
+ href += '/' + l2.version;
93
+ }
63
94
  }
95
+ href += '/' + l2.id;
96
+ return new Link(linkType, href);
64
97
  }
65
- href += '/' + l2.id;
66
- return new Link_1.Link(linkType, href);
67
- }
68
- return null;
69
- })
98
+ return null;
99
+ })
70
100
  .filter(l => l !== null);
71
- function uniqBy(a, key) {
101
+
102
+ function uniqBy(a: Link[], key: (a: any) => string) {
72
103
  const seen = {};
73
104
  return a.filter((item) => {
74
105
  if (!item) {
@@ -82,64 +113,65 @@ class RaainNode {
82
113
  return true;
83
114
  });
84
115
  }
116
+
85
117
  return uniqBy(linksPurified, JSON.stringify);
86
118
  }
119
+
87
120
  /**
88
121
  * Converts the node to a JSON object.
89
122
  *
90
123
  * @returns A JSON object containing the node's data
91
124
  */
92
- toJSON() {
93
- const json = {
125
+ public toJSON(): any {
126
+ const json: any = {
94
127
  id: this.id,
95
128
  links: this.links
96
129
  };
130
+
97
131
  if (this.version) {
98
132
  json.version = this.version;
99
133
  }
134
+
100
135
  return json;
101
136
  }
102
- /**
103
- * Gets all links associated with the node.
104
- *
105
- * @returns Array of HATEOAS links
106
- */
107
- get links() {
108
- return this._links;
109
- }
110
- /**
111
- * Sets the links for the node.
112
- *
113
- * @param links - Array of links to set
114
- */
115
- set links(links) {
116
- this._links = RaainNode._getPurifiedLinks(links);
137
+
138
+ public getLinks(linkType?: string): Link[] {
139
+ if (!this._links) {
140
+ return [];
141
+ }
142
+ if (!linkType) {
143
+ return this._links;
144
+ }
145
+ // return this.links.filter(l => l && l.rel && linkType === l.rel);
146
+ return this._links.filter(l => l.getLinkType() === linkType);
147
+
117
148
  }
118
- /**
119
- * Gets the ID from a link by its relationship type.
120
- *
121
- * @param rel - Relationship type of the link
122
- * @returns The ID from the link, or undefined if not found
123
- */
124
- getLinkId(rel) {
125
- const link = this._links.find(l => l.getLinkType() === rel);
126
- return link ? link.getId() : undefined;
149
+
150
+ public getLink(linkType: string, index?: number): Link {
151
+ index = !index ? 0 : index;
152
+ const linksFound = this.getLinks(linkType);
153
+ if (linksFound.length <= index) {
154
+ return null;
155
+ }
156
+ return linksFound[index];
127
157
  }
158
+
128
159
  /**
129
160
  * Gets all link IDs associated with the node.
130
161
  *
131
162
  * @returns Array of link IDs
132
163
  */
133
- getLinkIds() {
164
+ public getLinkIds(): string[] {
134
165
  return this._links.map(l => l.getId());
135
166
  }
167
+
136
168
  /**
137
169
  * Gets the count of links, optionally filtered by type.
138
170
  *
139
171
  * @param linkType - Optional type of links to count
140
172
  * @returns The number of links
141
173
  */
142
- getLinksCount(linkType) {
174
+ public getLinksCount(linkType?: string): number {
143
175
  if (!this._links) {
144
176
  return 0;
145
177
  }
@@ -148,25 +180,26 @@ class RaainNode {
148
180
  }
149
181
  return this._links.filter(l => l.getLinkType() === linkType).length;
150
182
  }
183
+
151
184
  /**
152
185
  * Adds new links to the node.
153
186
  *
154
187
  * @param links - Array of links to add
155
188
  */
156
- addLinks(links) {
189
+ public addLinks(links: Link[] | RaainNode[]) {
157
190
  if (!links) {
158
191
  return;
159
192
  }
193
+
160
194
  this._links = RaainNode._getPurifiedLinks([...this._links, ...links]);
161
195
  }
196
+
162
197
  /**
163
198
  * Gets the version string of the node.
164
199
  *
165
200
  * @returns The version string
166
201
  */
167
- getVersion() {
202
+ public getVersion(): string | undefined {
168
203
  return this.version;
169
204
  }
170
205
  }
171
- exports.RaainNode = RaainNode;
172
- //# sourceMappingURL=RaainNode.js.map