@tbiegner99/reporter 1.0.0

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 (90) hide show
  1. package/README.md +0 -0
  2. package/dist/src/constants.d.ts +9 -0
  3. package/dist/src/constants.d.ts.map +1 -0
  4. package/dist/src/constants.js +11 -0
  5. package/dist/src/index.d.ts +5 -0
  6. package/dist/src/index.d.ts.map +1 -0
  7. package/dist/src/index.js +20 -0
  8. package/dist/src/models/index.d.ts +2 -0
  9. package/dist/src/models/index.d.ts.map +1 -0
  10. package/dist/src/models/index.js +17 -0
  11. package/dist/src/models/measures/index.d.ts +9 -0
  12. package/dist/src/models/measures/index.d.ts.map +1 -0
  13. package/dist/src/models/measures/index.js +24 -0
  14. package/dist/src/models/measures/unit.d.ts +25 -0
  15. package/dist/src/models/measures/unit.d.ts.map +1 -0
  16. package/dist/src/models/measures/unit.js +51 -0
  17. package/dist/src/models/measures/units/direction.d.ts +20 -0
  18. package/dist/src/models/measures/units/direction.d.ts.map +1 -0
  19. package/dist/src/models/measures/units/direction.js +105 -0
  20. package/dist/src/models/measures/units/distance.d.ts +26 -0
  21. package/dist/src/models/measures/units/distance.d.ts.map +1 -0
  22. package/dist/src/models/measures/units/distance.js +60 -0
  23. package/dist/src/models/measures/units/percent.d.ts +18 -0
  24. package/dist/src/models/measures/units/percent.d.ts.map +1 -0
  25. package/dist/src/models/measures/units/percent.js +48 -0
  26. package/dist/src/models/measures/units/pressure.d.ts +25 -0
  27. package/dist/src/models/measures/units/pressure.d.ts.map +1 -0
  28. package/dist/src/models/measures/units/pressure.js +62 -0
  29. package/dist/src/models/measures/units/speed.d.ts +19 -0
  30. package/dist/src/models/measures/units/speed.d.ts.map +1 -0
  31. package/dist/src/models/measures/units/speed.js +64 -0
  32. package/dist/src/models/measures/units/temperature.d.ts +17 -0
  33. package/dist/src/models/measures/units/temperature.d.ts.map +1 -0
  34. package/dist/src/models/measures/units/temperature.js +56 -0
  35. package/dist/src/models/measures/units/time.d.ts +19 -0
  36. package/dist/src/models/measures/units/time.d.ts.map +1 -0
  37. package/dist/src/models/measures/units/time.js +50 -0
  38. package/dist/src/reading/HumidityReading.d.ts +5 -0
  39. package/dist/src/reading/HumidityReading.d.ts.map +1 -0
  40. package/dist/src/reading/HumidityReading.js +11 -0
  41. package/dist/src/reading/Reading.d.ts +10 -0
  42. package/dist/src/reading/Reading.d.ts.map +1 -0
  43. package/dist/src/reading/Reading.js +20 -0
  44. package/dist/src/reading/TemperatureReading.d.ts +6 -0
  45. package/dist/src/reading/TemperatureReading.d.ts.map +1 -0
  46. package/dist/src/reading/TemperatureReading.js +12 -0
  47. package/dist/src/reporter/CurrentStatusReporter.d.ts +13 -0
  48. package/dist/src/reporter/CurrentStatusReporter.d.ts.map +1 -0
  49. package/dist/src/reporter/CurrentStatusReporter.js +35 -0
  50. package/dist/src/reporter/DatabaseReporter.d.ts +29 -0
  51. package/dist/src/reporter/DatabaseReporter.d.ts.map +1 -0
  52. package/dist/src/reporter/DatabaseReporter.js +56 -0
  53. package/dist/src/reporter/KafkaReporter.d.ts +34 -0
  54. package/dist/src/reporter/KafkaReporter.d.ts.map +1 -0
  55. package/dist/src/reporter/KafkaReporter.js +86 -0
  56. package/dist/src/reporter/LoggerReporter.d.ts +24 -0
  57. package/dist/src/reporter/LoggerReporter.d.ts.map +1 -0
  58. package/dist/src/reporter/LoggerReporter.js +34 -0
  59. package/dist/src/reporter/MQTTReporter.d.ts +44 -0
  60. package/dist/src/reporter/MQTTReporter.d.ts.map +1 -0
  61. package/dist/src/reporter/MQTTReporter.js +101 -0
  62. package/dist/src/reporter/Reporter.d.ts +10 -0
  63. package/dist/src/reporter/Reporter.d.ts.map +1 -0
  64. package/dist/src/reporter/Reporter.js +15 -0
  65. package/dist/src/reporter/ReporterConfig.d.ts +136 -0
  66. package/dist/src/reporter/ReporterConfig.d.ts.map +1 -0
  67. package/dist/src/reporter/ReporterConfig.js +99 -0
  68. package/dist/src/reporter/ReporterFactory.d.ts +14 -0
  69. package/dist/src/reporter/ReporterFactory.d.ts.map +1 -0
  70. package/dist/src/reporter/ReporterFactory.js +74 -0
  71. package/dist/src/reporter/formatter/DefaultFormatter.d.ts +6 -0
  72. package/dist/src/reporter/formatter/DefaultFormatter.d.ts.map +1 -0
  73. package/dist/src/reporter/formatter/DefaultFormatter.js +12 -0
  74. package/dist/src/reporter/formatter/FormatterFactory.d.ts +9 -0
  75. package/dist/src/reporter/formatter/FormatterFactory.d.ts.map +1 -0
  76. package/dist/src/reporter/formatter/FormatterFactory.js +59 -0
  77. package/dist/src/reporter/formatter/HumidityFormatter.d.ts +7 -0
  78. package/dist/src/reporter/formatter/HumidityFormatter.d.ts.map +1 -0
  79. package/dist/src/reporter/formatter/HumidityFormatter.js +14 -0
  80. package/dist/src/reporter/formatter/TemperatureFormatter.d.ts +12 -0
  81. package/dist/src/reporter/formatter/TemperatureFormatter.d.ts.map +1 -0
  82. package/dist/src/reporter/formatter/TemperatureFormatter.js +20 -0
  83. package/dist/src/reporter/index.d.ts +5 -0
  84. package/dist/src/reporter/index.d.ts.map +1 -0
  85. package/dist/src/reporter/index.js +20 -0
  86. package/dist/src/service/CurrentConditionsManager.d.ts +34 -0
  87. package/dist/src/service/CurrentConditionsManager.d.ts.map +1 -0
  88. package/dist/src/service/CurrentConditionsManager.js +58 -0
  89. package/dist/tsconfig.tsbuildinfo +1 -0
  90. package/package.json +45 -0
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpeedUnit = void 0;
4
+ class SpeedUnit {
5
+ static fromSymbol(symbol) {
6
+ let unit = SpeedUnit.SUPPORTED_UNITS.find((u) => u.symbol === symbol || u.aliasSymbols.includes(symbol));
7
+ if (!unit) {
8
+ throw new Error(`Unsupported speed unit: ${symbol}`);
9
+ }
10
+ return unit;
11
+ }
12
+ constructor(symbol, name, toMpsFactor, aliasSymbols = []) {
13
+ this.symbol = symbol;
14
+ this.name = name;
15
+ this.toMpsFactor = toMpsFactor;
16
+ this.aliasSymbols = aliasSymbols;
17
+ }
18
+ toDisplayString() {
19
+ return this.symbol;
20
+ }
21
+ toMps(unit, value) {
22
+ const targetUnit = SpeedUnit.SUPPORTED_UNITS.find((u) => u.symbol === unit.symbol);
23
+ if (!targetUnit) {
24
+ throw new Error(`Unsupported speed unit: ${unit.symbol}`);
25
+ }
26
+ return value * targetUnit.toMpsFactor;
27
+ }
28
+ convertTo(unit, value) {
29
+ if (!unit || unit.symbol === this.symbol) {
30
+ return value;
31
+ }
32
+ const mps = this.toMps(this, value);
33
+ const targetUnit = SpeedUnit.SUPPORTED_UNITS.find((u) => u.symbol === unit.symbol);
34
+ if (!targetUnit) {
35
+ throw new Error(`Unsupported speed unit: ${unit.symbol}`);
36
+ }
37
+ return mps / targetUnit.toMpsFactor;
38
+ }
39
+ }
40
+ exports.SpeedUnit = SpeedUnit;
41
+ SpeedUnit.MPS = new SpeedUnit('m/s', 'Meters per second', 1, ['mps', 'm/s', 'm_s-1']);
42
+ SpeedUnit.FPS = new SpeedUnit('ft/s', 'Feet per second', 0.3048, [
43
+ 'fps',
44
+ 'ftps',
45
+ 'ft/s',
46
+ 'ft_s-1'
47
+ ]);
48
+ SpeedUnit.KMH = new SpeedUnit('kmh', 'Kilometers per hour', 0.277778, [
49
+ 'kph',
50
+ 'km/h',
51
+ 'kmph',
52
+ 'km_h-1'
53
+ ]);
54
+ SpeedUnit.MPH = new SpeedUnit('mph', 'Miles per hour', 0.44704, [
55
+ 'mi/h',
56
+ 'miph',
57
+ 'mi/h-1'
58
+ ]);
59
+ SpeedUnit.SUPPORTED_UNITS = [
60
+ SpeedUnit.MPS,
61
+ SpeedUnit.FPS,
62
+ SpeedUnit.KMH,
63
+ SpeedUnit.MPH
64
+ ];
@@ -0,0 +1,17 @@
1
+ import { Unit } from '../unit';
2
+ export type Temperature = 'C' | 'F' | 'K';
3
+ export declare class TemperatureUnit implements Unit<Temperature> {
4
+ readonly symbol: Temperature;
5
+ readonly name: string;
6
+ readonly aliasSymbols: string[];
7
+ static CELSIUS: TemperatureUnit;
8
+ static FAHRENHEIT: TemperatureUnit;
9
+ static KELVIN: TemperatureUnit;
10
+ static SUPPORTED_UNITS: TemperatureUnit[];
11
+ static fromSymbol(symbol: string): Unit<Temperature>;
12
+ private constructor();
13
+ toDisplayString(): string;
14
+ convertTo(unit: Unit<Temperature>, value: number): number;
15
+ toString(): string;
16
+ }
17
+ //# sourceMappingURL=temperature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temperature.d.ts","sourceRoot":"","sources":["../../../../../src/models/measures/units/temperature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAE1C,qBAAa,eAAgB,YAAW,IAAI,CAAC,WAAW,CAAC;aAsBjC,MAAM,EAAE,WAAW;aACnB,IAAI,EAAE,MAAM;aACZ,YAAY,EAAE,MAAM,EAAE;IAvB1C,MAAM,CAAC,OAAO,EAAE,eAAe,CAAuD;IACtF,MAAM,CAAC,UAAU,EAAE,eAAe,CAA0D;IAC5F,MAAM,CAAC,MAAM,EAAE,eAAe,CAA6C;IAE3E,MAAM,CAAC,eAAe,EAAE,eAAe,EAAE,CAIvC;IAEF,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;IAUpD,OAAO;IAMP,eAAe,IAAI,MAAM;IAIzB,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IA0BzD,QAAQ,IAAI,MAAM;CAGrB"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TemperatureUnit = void 0;
4
+ class TemperatureUnit {
5
+ static fromSymbol(symbol) {
6
+ let unit = TemperatureUnit.SUPPORTED_UNITS.find((u) => u.symbol === symbol || u.aliasSymbols.includes(symbol));
7
+ if (!unit) {
8
+ throw new Error(`Unsupported temperature unit: ${symbol}`);
9
+ }
10
+ return unit;
11
+ }
12
+ constructor(symbol, name, aliasSymbols = []) {
13
+ this.symbol = symbol;
14
+ this.name = name;
15
+ this.aliasSymbols = aliasSymbols;
16
+ }
17
+ toDisplayString() {
18
+ return `°${this.symbol}`;
19
+ }
20
+ convertTo(unit, value) {
21
+ if (!unit || unit.symbol === this.symbol) {
22
+ return value;
23
+ }
24
+ if (unit.symbol === 'C') {
25
+ switch (this.symbol) {
26
+ case 'F':
27
+ return (value * 5) / 9 - 32;
28
+ case 'K':
29
+ return value - 273.15;
30
+ case 'C':
31
+ return value;
32
+ default:
33
+ throw new Error(`Unsupported temperature unit: ${unit.symbol}`);
34
+ }
35
+ }
36
+ var normalizedValue = this.convertTo(TemperatureUnit.CELSIUS, value);
37
+ switch (unit.symbol) {
38
+ case 'F':
39
+ return (normalizedValue * 9) / 5 + 32;
40
+ case 'K':
41
+ return normalizedValue + 273.15;
42
+ }
43
+ }
44
+ toString() {
45
+ return this.name;
46
+ }
47
+ }
48
+ exports.TemperatureUnit = TemperatureUnit;
49
+ TemperatureUnit.CELSIUS = new TemperatureUnit('C', 'Celsius', ['degC', '°C']);
50
+ TemperatureUnit.FAHRENHEIT = new TemperatureUnit('F', 'Fahrenheit', ['degF', '°F']);
51
+ TemperatureUnit.KELVIN = new TemperatureUnit('K', 'Kelvin', ['K']);
52
+ TemperatureUnit.SUPPORTED_UNITS = [
53
+ TemperatureUnit.CELSIUS,
54
+ TemperatureUnit.FAHRENHEIT,
55
+ TemperatureUnit.KELVIN
56
+ ];
@@ -0,0 +1,19 @@
1
+ import { Unit } from '../unit';
2
+ export type Time = 's' | 'min' | 'h' | 'd';
3
+ export declare class TimeUnit implements Unit<Time> {
4
+ readonly symbol: Time;
5
+ readonly name: string;
6
+ private readonly toSecondsFactor;
7
+ private readonly aliasSymbols;
8
+ static readonly SECOND: TimeUnit;
9
+ static readonly MINUTE: TimeUnit;
10
+ static readonly HOUR: TimeUnit;
11
+ static readonly DAY: TimeUnit;
12
+ static readonly SUPPORTED_UNITS: TimeUnit[];
13
+ static fromSymbol(symbol: string): Unit<Time>;
14
+ private constructor();
15
+ toDisplayString(): string;
16
+ toSeconds(unit: Unit<Time>, value: number): number;
17
+ convertTo(unit: Unit<Time>, value: number): number;
18
+ }
19
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../../../src/models/measures/units/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,MAAM,IAAI,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;AAE3C,qBAAa,QAAS,YAAW,IAAI,CAAC,IAAI,CAAC;aAwBnB,MAAM,EAAE,IAAI;aACZ,IAAI,EAAE,MAAM;IAC5B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY;IA1BjC,MAAM,CAAC,QAAQ,CAAC,MAAM,WAAmD;IACzE,MAAM,CAAC,QAAQ,CAAC,MAAM,WAAqC;IAC3D,MAAM,CAAC,QAAQ,CAAC,IAAI,WAA2C;IAC/D,MAAM,CAAC,QAAQ,CAAC,GAAG,WAA4C;IAE/D,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,EAAE,CAKzC;IAEF,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;IAU7C,OAAO;IAOP,eAAe,IAAI,MAAM;IAIzB,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAQlD,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAWrD"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeUnit = void 0;
4
+ class TimeUnit {
5
+ static fromSymbol(symbol) {
6
+ let unit = TimeUnit.SUPPORTED_UNITS.find((u) => u.symbol === symbol || u.aliasSymbols.includes(symbol));
7
+ if (!unit) {
8
+ throw new Error(`Unsupported time unit: ${symbol}`);
9
+ }
10
+ return unit;
11
+ }
12
+ constructor(symbol, name, toSecondsFactor, aliasSymbols = []) {
13
+ this.symbol = symbol;
14
+ this.name = name;
15
+ this.toSecondsFactor = toSecondsFactor;
16
+ this.aliasSymbols = aliasSymbols;
17
+ }
18
+ toDisplayString() {
19
+ return this.symbol;
20
+ }
21
+ toSeconds(unit, value) {
22
+ const targetUnit = TimeUnit.SUPPORTED_UNITS.find((u) => u.symbol === unit.symbol);
23
+ if (!targetUnit) {
24
+ throw new Error(`Unsupported time unit: ${unit.symbol}`);
25
+ }
26
+ return value * targetUnit.toSecondsFactor;
27
+ }
28
+ convertTo(unit, value) {
29
+ if (!unit || unit.symbol === this.symbol) {
30
+ return value;
31
+ }
32
+ const seconds = this.toSeconds(unit, value);
33
+ const targetUnit = TimeUnit.SUPPORTED_UNITS.find((u) => u.symbol === unit.symbol);
34
+ if (!targetUnit) {
35
+ throw new Error(`Unsupported time unit: ${unit.symbol}`);
36
+ }
37
+ return seconds / targetUnit.toSecondsFactor;
38
+ }
39
+ }
40
+ exports.TimeUnit = TimeUnit;
41
+ TimeUnit.SECOND = new TimeUnit('s', 'Second', 1, ['sec', 'secs']);
42
+ TimeUnit.MINUTE = new TimeUnit('min', 'Minute', 60);
43
+ TimeUnit.HOUR = new TimeUnit('h', 'Hour', 3600, ['hr']);
44
+ TimeUnit.DAY = new TimeUnit('d', 'Day', 86400, ['day']);
45
+ TimeUnit.SUPPORTED_UNITS = [
46
+ TimeUnit.SECOND,
47
+ TimeUnit.MINUTE,
48
+ TimeUnit.HOUR,
49
+ TimeUnit.DAY
50
+ ];
@@ -0,0 +1,5 @@
1
+ import { Reading } from './Reading';
2
+ export declare class HumidityReading extends Reading {
3
+ constructor(value: any);
4
+ }
5
+ //# sourceMappingURL=HumidityReading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HumidityReading.d.ts","sourceRoot":"","sources":["../../../src/reading/HumidityReading.ts"],"names":[],"mappings":"AAAA,OAAQ,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAGnC,qBAAa,eAAgB,SAAQ,OAAO;gBAC9B,KAAK,KAAA;CAGlB"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HumidityReading = void 0;
4
+ const Reading_1 = require("./Reading");
5
+ const constants_1 = require("../config/constants");
6
+ class HumidityReading extends Reading_1.Reading {
7
+ constructor(value) {
8
+ super(constants_1.ReadingTypes.HUMIDITY, value, "%");
9
+ }
10
+ }
11
+ exports.HumidityReading = HumidityReading;
@@ -0,0 +1,10 @@
1
+ export declare class Reading {
2
+ private _type;
3
+ private _value;
4
+ private _unit;
5
+ constructor(_type: any, _value: any, _unit: any);
6
+ get type(): any;
7
+ get value(): any;
8
+ get unit(): any;
9
+ }
10
+ //# sourceMappingURL=Reading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Reading.d.ts","sourceRoot":"","sources":["../../../src/reading/Reading.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO;IACN,OAAO,CAAC,KAAK;IAAE,OAAO,CAAC,MAAM;IAAE,OAAO,CAAC,KAAK;gBAApC,KAAK,KAAA,EAAU,MAAM,KAAA,EAAU,KAAK,KAAA;IAExD,IAAI,IAAI,QAEP;IAED,IAAI,KAAK,QAER;IAED,IAAI,IAAI,QAEP;CACF"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Reading = void 0;
4
+ class Reading {
5
+ constructor(_type, _value, _unit) {
6
+ this._type = _type;
7
+ this._value = _value;
8
+ this._unit = _unit;
9
+ }
10
+ get type() {
11
+ return this._type;
12
+ }
13
+ get value() {
14
+ return this._value;
15
+ }
16
+ get unit() {
17
+ return this._unit;
18
+ }
19
+ }
20
+ exports.Reading = Reading;
@@ -0,0 +1,6 @@
1
+ import { Reading } from './Reading';
2
+ import { TemperatureUnit } from '../config/units';
3
+ export declare class TemperatureReading extends Reading {
4
+ constructor(value: number, unit?: TemperatureUnit);
5
+ }
6
+ //# sourceMappingURL=TemperatureReading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TemperatureReading.d.ts","sourceRoot":"","sources":["../../../src/reading/TemperatureReading.ts"],"names":[],"mappings":"AAAA,OAAQ,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAEnC,OAAQ,EAAe,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE,qBAAa,kBAAmB,SAAQ,OAAO;gBACjC,KAAK,EAAC,MAAM,EAAE,IAAI,CAAC,EAAC,eAAe;CAGhD"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TemperatureReading = void 0;
4
+ const Reading_1 = require("./Reading");
5
+ const constants_1 = require("../config/constants");
6
+ const units_1 = require("../config/units");
7
+ class TemperatureReading extends Reading_1.Reading {
8
+ constructor(value, unit) {
9
+ super(constants_1.ReadingTypes.TEMPERATURE, value, unit || units_1.Temperature.CELCIUS);
10
+ }
11
+ }
12
+ exports.TemperatureReading = TemperatureReading;
@@ -0,0 +1,13 @@
1
+ import { ReporterConfig } from './ReporterConfig';
2
+ import { CurrentConditionsManager } from '../service/CurrentConditionsManager';
3
+ import { Reporter } from './Reporter';
4
+ import { Reading } from '../models';
5
+ export declare class CurrentStatusReporter extends Reporter {
6
+ currentStatusManager: CurrentConditionsManager;
7
+ constructor(config: ReporterConfig, env: any);
8
+ shouldReportReading(reading: Reading<any>): boolean;
9
+ reportError(err: Error): Promise<void>;
10
+ getName(): string;
11
+ reportReading(reading: Reading<any>): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=CurrentStatusReporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrentStatusReporter.d.ts","sourceRoot":"","sources":["../../../src/reporter/CurrentStatusReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,qBAAsB,SAAQ,QAAQ;IACjD,oBAAoB,EAAE,wBAAwB,CAAC;gBACnC,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG;IAK5C,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;IAInC,WAAW,CAAC,GAAG,EAAE,KAAK;IAI5B,OAAO;IAID,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;CAc1C"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CurrentStatusReporter = void 0;
4
+ const constants_1 = require("../constants");
5
+ const Reporter_1 = require("./Reporter");
6
+ class CurrentStatusReporter extends Reporter_1.Reporter {
7
+ constructor(config, env) {
8
+ super();
9
+ this.currentStatusManager = env.currentStatusManager;
10
+ }
11
+ shouldReportReading(reading) {
12
+ return reading.type === constants_1.ReadingTypes.TEMPERATURE || reading.type === constants_1.ReadingTypes.HUMIDITY;
13
+ }
14
+ async reportError(err) {
15
+ this.currentStatusManager.setLastError(err);
16
+ }
17
+ getName() {
18
+ return 'currentStatus';
19
+ }
20
+ async reportReading(reading) {
21
+ this.currentStatusManager.setLastUpdate(new Date());
22
+ this.currentStatusManager.clearErrors();
23
+ switch (reading.type) {
24
+ case constants_1.ReadingTypes.TEMPERATURE:
25
+ this.currentStatusManager.setCurrentTemperature(reading.reading.value);
26
+ break;
27
+ case constants_1.ReadingTypes.HUMIDITY:
28
+ this.currentStatusManager.setCurrentHumidity(reading.reading.value);
29
+ break;
30
+ default:
31
+ break;
32
+ }
33
+ }
34
+ }
35
+ exports.CurrentStatusReporter = CurrentStatusReporter;
@@ -0,0 +1,29 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Reporter } from './Reporter';
3
+ import { ReporterConfig } from './ReporterConfig';
4
+ import { Reading } from '../models';
5
+ export interface DatabaseReporterConfig extends ReporterConfig {
6
+ host: string;
7
+ zoneName?: string;
8
+ reportingInterval: number;
9
+ zoneDescription: string;
10
+ }
11
+ export declare class DatabaseReporter extends Reporter {
12
+ isZoneCreated: boolean;
13
+ httpClient: AxiosInstance;
14
+ reporterHost: string;
15
+ zoneName: string;
16
+ zoneDescription: string;
17
+ lastReported: number | null;
18
+ reportingInterval: number;
19
+ constructor(config: DatabaseReporterConfig, env: any);
20
+ getName(): string;
21
+ shouldReportReading(reading: Reading<any>): boolean;
22
+ isOutsideOfReportingInterval(): boolean;
23
+ isReporterActive(): boolean;
24
+ createZone(zoneName: string): Promise<import("axios").AxiosResponse<any, any, {}>>;
25
+ createReading(zoneName: string, reading: Reading<any>): Promise<import("axios").AxiosResponse<any, any, {}>>;
26
+ reportError(): Promise<void>;
27
+ reportReading(reading: Reading<any>): Promise<void>;
28
+ }
29
+ //# sourceMappingURL=DatabaseReporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseReporter.d.ts","sourceRoot":"","sources":["../../../src/reporter/DatabaseReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,aAAa,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;gBACd,MAAM,EAAE,sBAAsB,EAAE,GAAG,EAAE,GAAG;IAWpD,OAAO;IAIP,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;IAOzC,4BAA4B;IAS5B,gBAAgB;IAMhB,UAAU,CAAC,QAAQ,EAAE,MAAM;IAO3B,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;IAS/C,WAAW;IAEX,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;CAQ1C"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseReporter = void 0;
4
+ const constants_1 = require("../constants");
5
+ const Reporter_1 = require("./Reporter");
6
+ class DatabaseReporter extends Reporter_1.Reporter {
7
+ constructor(config, env) {
8
+ super();
9
+ this.isZoneCreated = false;
10
+ this.httpClient = env.httpClient;
11
+ this.reporterHost = config.host;
12
+ this.zoneName = config.zoneName || env.ZONE_NAME;
13
+ this.zoneDescription = config.zoneDescription || env.ZONE_DESCRIPTION;
14
+ this.lastReported = null;
15
+ this.reportingInterval = config.reportingInterval;
16
+ }
17
+ getName() {
18
+ return 'databaseReporter';
19
+ }
20
+ shouldReportReading(reading) {
21
+ if (this.isReporterActive()) {
22
+ return reading.type === constants_1.ReadingTypes.TEMPERATURE || reading.type === constants_1.ReadingTypes.HUMIDITY;
23
+ }
24
+ return false;
25
+ }
26
+ isOutsideOfReportingInterval() {
27
+ return (!this.lastReported ||
28
+ !this.reportingInterval ||
29
+ this.reportingInterval <= 0 ||
30
+ Date.now() - this.lastReported >= this.reportingInterval);
31
+ }
32
+ isReporterActive() {
33
+ return (this.isOutsideOfReportingInterval() && Boolean(this.zoneName) && Boolean(this.reporterHost));
34
+ }
35
+ createZone(zoneName) {
36
+ return this.httpClient.post(`${this.reporterHost}/api/sensors/zones`, {
37
+ name: zoneName,
38
+ description: this.zoneDescription,
39
+ });
40
+ }
41
+ createReading(zoneName, reading) {
42
+ return this.httpClient.post(`${this.reporterHost}/api/sensors/zones/${zoneName}/readings/${reading.type}`, {
43
+ [reading.type]: reading.reading.value,
44
+ });
45
+ }
46
+ async reportError() { }
47
+ async reportReading(reading) {
48
+ if (!this.isZoneCreated) {
49
+ await this.createZone(this.zoneName);
50
+ this.isZoneCreated = true;
51
+ }
52
+ this.lastReported = Date.now();
53
+ await this.createReading(this.zoneName, reading);
54
+ }
55
+ }
56
+ exports.DatabaseReporter = DatabaseReporter;
@@ -0,0 +1,34 @@
1
+ import { Kafka, Producer } from 'kafkajs';
2
+ import { Reporter } from './Reporter';
3
+ import { ReporterConfig } from './ReporterConfig';
4
+ import { Reading } from '../models';
5
+ export interface KafkaReporterConfig extends ReporterConfig {
6
+ zoneName?: string;
7
+ topic: string;
8
+ reportingInterval: number;
9
+ zoneDescription: string;
10
+ brokers: string[];
11
+ logLevel?: number;
12
+ appName: string;
13
+ }
14
+ export declare class KafkaReporter extends Reporter {
15
+ topic: string;
16
+ brokers: string[];
17
+ zoneName: string;
18
+ zoneDescription: string;
19
+ lastReported: number;
20
+ reportingInterval: number;
21
+ client: Kafka;
22
+ producer: Producer;
23
+ isConnected: boolean;
24
+ constructor(config: KafkaReporterConfig, env: any);
25
+ getName(): string;
26
+ reportError(): Promise<void>;
27
+ init(): Promise<void>;
28
+ shouldReportReading(reading: Reading<any>): boolean;
29
+ isOutsideOfReportingInterval(): boolean;
30
+ isReporterActive(): boolean;
31
+ createReading(zoneName: string, reading: Reading<any>): Promise<void>;
32
+ reportReading(reading: Reading<any>): Promise<void>;
33
+ }
34
+ //# sourceMappingURL=KafkaReporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KafkaReporter.d.ts","sourceRoot":"","sources":["../../../src/reporter/KafkaReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAS,MAAM,WAAW,CAAC;AAG3C,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,aAAc,SAAQ,QAAQ;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,KAAK,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;gBAET,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,GAAG;IAiBjD,OAAO;IAGD,WAAW;IAEX,IAAI;IAWV,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO;IAOnD,4BAA4B;IAS5B,gBAAgB;IAIV,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;IAmBrD,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;CAY1C"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KafkaReporter = void 0;
4
+ const kafkajs_1 = require("kafkajs");
5
+ const constants_1 = require("../constants");
6
+ const Reporter_1 = require("./Reporter");
7
+ class KafkaReporter extends Reporter_1.Reporter {
8
+ constructor(config, env) {
9
+ super();
10
+ this.isConnected = false;
11
+ this.brokers = config.brokers;
12
+ this.topic = config.topic;
13
+ this.zoneName = config.zoneName || env.ZONE_NAME;
14
+ this.zoneDescription = config.zoneDescription || env.ZONE_DESCRIPTION;
15
+ this.lastReported = 0;
16
+ this.reportingInterval = config.reportingInterval;
17
+ this.client = new kafkajs_1.Kafka({
18
+ brokers: this.brokers,
19
+ logLevel: config.logLevel,
20
+ clientId: config.appName,
21
+ });
22
+ this.producer = this.client.producer();
23
+ }
24
+ getName() {
25
+ return 'kafkaReporter';
26
+ }
27
+ async reportError() { }
28
+ async init() {
29
+ try {
30
+ await this.producer.connect();
31
+ this.isConnected = true;
32
+ console.log('Connected to Kafka');
33
+ }
34
+ catch (err) {
35
+ console.error('Error connecting');
36
+ console.error(err.message);
37
+ }
38
+ }
39
+ shouldReportReading(reading) {
40
+ if (this.isReporterActive()) {
41
+ return reading.type === constants_1.ReadingTypes.TEMPERATURE || reading.type === constants_1.ReadingTypes.HUMIDITY;
42
+ }
43
+ return false;
44
+ }
45
+ isOutsideOfReportingInterval() {
46
+ return (!this.lastReported ||
47
+ !this.reportingInterval ||
48
+ this.reportingInterval <= 0 ||
49
+ Date.now() - this.lastReported > this.reportingInterval);
50
+ }
51
+ isReporterActive() {
52
+ return this.isOutsideOfReportingInterval() && Boolean(this.zoneName);
53
+ }
54
+ async createReading(zoneName, reading) {
55
+ const timestamp = Date.now();
56
+ console.info(`Sending ${reading.type} reading to Kafka`);
57
+ await this.producer.send({
58
+ topic: this.topic,
59
+ messages: [
60
+ {
61
+ value: JSON.stringify({
62
+ timestamp: reading.timestamp,
63
+ zoneName,
64
+ type: reading.type,
65
+ unit: reading.reading.unit,
66
+ value: reading.reading.value,
67
+ }),
68
+ },
69
+ ],
70
+ });
71
+ }
72
+ async reportReading(reading) {
73
+ try {
74
+ if (!this.isConnected) {
75
+ await this.init();
76
+ }
77
+ const type = reading.type.toLowerCase();
78
+ await this.createReading(this.zoneName, reading);
79
+ this.lastReported = Date.now();
80
+ }
81
+ catch (err) {
82
+ console.warn('Error saving reading to kafka', err);
83
+ }
84
+ }
85
+ }
86
+ exports.KafkaReporter = KafkaReporter;
@@ -0,0 +1,24 @@
1
+ import { ReporterConfig } from './ReporterConfig';
2
+ import { Reporter } from './Reporter';
3
+ import { Formatter } from './formatter/DefaultFormatter';
4
+ import { FormatterConfig } from './formatter/FormatterFactory';
5
+ import { Reading } from '../models';
6
+ export interface LoggerReporterConfig extends ReporterConfig {
7
+ host: string;
8
+ zoneName?: string;
9
+ reportingInterval: number;
10
+ zoneDescription: string;
11
+ formatters?: FormatterConfig[];
12
+ }
13
+ export declare class LoggerReporter extends Reporter {
14
+ config: LoggerReporterConfig;
15
+ env: any;
16
+ formatters: Formatter[];
17
+ constructor(config: LoggerReporterConfig, env: any);
18
+ reportError(): Promise<void>;
19
+ getName(): string;
20
+ init(): Promise<void>;
21
+ formatReading(reading: Reading<any>): string;
22
+ reportReading(reading: Reading<any>): Promise<void>;
23
+ }
24
+ //# sourceMappingURL=LoggerReporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggerReporter.d.ts","sourceRoot":"","sources":["../../../src/reporter/LoggerReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAoB,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;CAChC;AAED,qBAAa,cAAe,SAAQ,QAAQ;IAGjC,MAAM,EAAE,oBAAoB;IAC5B,GAAG,EAAE,GAAG;IAHjB,UAAU,EAAE,SAAS,EAAE,CAAC;gBAEf,MAAM,EAAE,oBAAoB,EAC5B,GAAG,EAAE,GAAG;IAKX,WAAW;IAEjB,OAAO;IAID,IAAI;IAMV,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;IAS7B,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;CAG1C"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggerReporter = void 0;
4
+ const Reporter_1 = require("./Reporter");
5
+ const DefaultFormatter_1 = require("./formatter/DefaultFormatter");
6
+ const FormatterFactory_1 = require("./formatter/FormatterFactory");
7
+ class LoggerReporter extends Reporter_1.Reporter {
8
+ constructor(config, env) {
9
+ super();
10
+ this.config = config;
11
+ this.env = env;
12
+ }
13
+ async reportError() { }
14
+ getName() {
15
+ return 'loggerReporter';
16
+ }
17
+ async init() {
18
+ this.formatters = this.config.formatters
19
+ ? await new FormatterFactory_1.FormatterFactory(this.config.formatters).constructFormatters()
20
+ : [];
21
+ }
22
+ formatReading(reading) {
23
+ for (let i = 0; i < this.formatters.length; i++) {
24
+ if (this.formatters[i].appliesTo(reading)) {
25
+ return this.formatters[i].format(reading);
26
+ }
27
+ }
28
+ return new DefaultFormatter_1.Formatter().format(reading);
29
+ }
30
+ async reportReading(reading) {
31
+ console.log(this.formatReading(reading));
32
+ }
33
+ }
34
+ exports.LoggerReporter = LoggerReporter;