dt-common-device 3.1.0 → 3.1.2
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.
- package/dist/admin/Admin.repository.d.ts +7 -0
- package/dist/admin/Admin.repository.js +182 -0
- package/dist/admin/Admin.service.d.ts +5 -0
- package/dist/admin/Admin.service.js +17 -0
- package/dist/admin/index.d.ts +1 -0
- package/dist/admin/index.js +17 -0
- package/dist/config/config.js +4 -0
- package/dist/config/config.types.d.ts +2 -0
- package/dist/constants/ConnectionProviders.d.ts +1 -0
- package/dist/constants/ConnectionProviders.js +1 -0
- package/dist/device/cloud/entities/DeviceFactory.js +73 -14
- package/dist/device/local/services/Device.service.js +294 -239
- package/dist/device/local/services/Hub.service.js +92 -38
- package/dist/events/BaseEventHandler.js +6 -1
- package/dist/events/DeviceEventHandler.js +6 -1
- package/dist/events/EventHandler.js +158 -104
- package/dist/events/EventProcessingService.js +8 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/microservice/MicroServiceFactory.d.ts +1 -1
- package/dist/microservice/MicroServiceFactory.js +5 -3
- package/dist/property/Property.service.js +86 -27
- package/dist/queue/services/QueueService.js +6 -1
- package/dist/queue/utils/rateLimit.utils.js +13 -8
- package/dist/utils/http.utils.d.ts +2 -0
- package/dist/utils/http.utils.js +30 -0
- package/package.json +1 -1
|
@@ -1,4 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
2
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
42
|
};
|
|
@@ -6,48 +44,64 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
44
|
exports.LocalHubService = void 0;
|
|
7
45
|
const Hub_repository_1 = require("../repository/Hub.repository");
|
|
8
46
|
const typedi_1 = __importDefault(require("typedi"));
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new Error("At least one hub ID is required");
|
|
47
|
+
const typedi_2 = require("typedi");
|
|
48
|
+
let LocalHubService = (() => {
|
|
49
|
+
let _classDecorators = [(0, typedi_2.Service)()];
|
|
50
|
+
let _classDescriptor;
|
|
51
|
+
let _classExtraInitializers = [];
|
|
52
|
+
let _classThis;
|
|
53
|
+
var LocalHubService = _classThis = class {
|
|
54
|
+
constructor() {
|
|
55
|
+
this.hubRepository = typedi_1.default.get(Hub_repository_1.HubRepository);
|
|
19
56
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async getHub(hubId) {
|
|
23
|
-
if (!hubId) {
|
|
24
|
-
throw new Error("Hub ID is required");
|
|
57
|
+
async addHub(body) {
|
|
58
|
+
return await this.hubRepository.addHub(body);
|
|
25
59
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
60
|
+
async getHubs(hubIds) {
|
|
61
|
+
if (!hubIds.length) {
|
|
62
|
+
throw new Error("At least one hub ID is required");
|
|
63
|
+
}
|
|
64
|
+
return await this.hubRepository.getHubs(hubIds);
|
|
31
65
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
66
|
+
async getHub(hubId) {
|
|
67
|
+
if (!hubId) {
|
|
68
|
+
throw new Error("Hub ID is required");
|
|
69
|
+
}
|
|
70
|
+
return await this.hubRepository.getHub(hubId);
|
|
37
71
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
72
|
+
async updateHub(hubId, body) {
|
|
73
|
+
if (!hubId) {
|
|
74
|
+
throw new Error("Hub ID is required");
|
|
75
|
+
}
|
|
76
|
+
return await this.hubRepository.updateHub(hubId, body);
|
|
43
77
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
78
|
+
async getStatus(hubId) {
|
|
79
|
+
if (!hubId) {
|
|
80
|
+
throw new Error("Hub ID is required");
|
|
81
|
+
}
|
|
82
|
+
return await this.hubRepository.getStatus(hubId);
|
|
49
83
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
84
|
+
async deleteHub(hubId) {
|
|
85
|
+
if (!hubId) {
|
|
86
|
+
throw new Error("Hub ID is required");
|
|
87
|
+
}
|
|
88
|
+
return await this.hubRepository.deleteHub(hubId);
|
|
89
|
+
}
|
|
90
|
+
async deleteAllHubs(hubIds) {
|
|
91
|
+
if (!hubIds.length) {
|
|
92
|
+
throw new Error("At least one hub ID is required");
|
|
93
|
+
}
|
|
94
|
+
return await this.hubRepository.deleteAllHubs(hubIds);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
__setFunctionName(_classThis, "LocalHubService");
|
|
98
|
+
(() => {
|
|
99
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
100
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
101
|
+
LocalHubService = _classThis = _classDescriptor.value;
|
|
102
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
103
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
104
|
+
})();
|
|
105
|
+
return LocalHubService = _classThis;
|
|
106
|
+
})();
|
|
53
107
|
exports.LocalHubService = LocalHubService;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.BaseEventHandler = void 0;
|
|
4
7
|
const config_1 = require("../config/config");
|
|
5
8
|
const Device_service_1 = require("../device/local/services/Device.service");
|
|
9
|
+
const typedi_1 = __importDefault(require("typedi"));
|
|
6
10
|
class BaseEventHandler {
|
|
7
11
|
constructor(supportedEventTypes, priority = 100) {
|
|
8
12
|
this.supportedEventTypes = supportedEventTypes;
|
|
9
13
|
this.priority = priority;
|
|
10
14
|
this.logger = (0, config_1.getConfig)().LOGGER;
|
|
11
|
-
|
|
15
|
+
// Use dependency injection instead of creating new instance
|
|
16
|
+
this.localDeviceService = typedi_1.default.get(Device_service_1.LocalDeviceService);
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
14
19
|
* Handle a single event - to be implemented by specific handlers
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.DeviceEventHandler = void 0;
|
|
4
7
|
const constants_1 = require("../constants");
|
|
5
8
|
const Event_1 = require("../constants/Event");
|
|
6
9
|
const services_1 = require("../device/local/services");
|
|
7
10
|
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
11
|
+
const typedi_1 = __importDefault(require("typedi"));
|
|
8
12
|
class DeviceEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
9
13
|
constructor() {
|
|
10
14
|
super([
|
|
@@ -15,7 +19,8 @@ class DeviceEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
|
15
19
|
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.LOW,
|
|
16
20
|
Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.CHANGED,
|
|
17
21
|
], 100);
|
|
18
|
-
|
|
22
|
+
// Use dependency injection instead of creating new instance
|
|
23
|
+
this.localHubService = typedi_1.default.get(services_1.LocalHubService);
|
|
19
24
|
}
|
|
20
25
|
async onEvent(event) {
|
|
21
26
|
this.logger.info("[DT | CDL]:[DeviceEventHandler]: Processing event", {
|
|
@@ -1,111 +1,165 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
2
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
41
|
exports.EventHandler = void 0;
|
|
4
42
|
const dt_pub_sub_1 = require("dt-pub-sub");
|
|
5
43
|
const dt_audit_library_1 = require("dt-audit-library");
|
|
6
44
|
const Event_1 = require("../constants/Event");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
45
|
+
const typedi_1 = require("typedi");
|
|
46
|
+
let EventHandler = (() => {
|
|
47
|
+
let _classDecorators = [(0, typedi_1.Service)()];
|
|
48
|
+
let _classDescriptor;
|
|
49
|
+
let _classExtraInitializers = [];
|
|
50
|
+
let _classThis;
|
|
51
|
+
var EventHandler = _classThis = class {
|
|
52
|
+
constructor() {
|
|
53
|
+
this.source = "dt-common-device";
|
|
54
|
+
}
|
|
55
|
+
async onDeviceCreate(body) {
|
|
56
|
+
// TODO: For Future Consumption
|
|
57
|
+
// await eventDispatcher.publishEvent(
|
|
58
|
+
// DT_EVENT_TYPES.DEVICE.CREATE.SUCCESS,
|
|
59
|
+
// body,
|
|
60
|
+
// this.source
|
|
61
|
+
// );
|
|
62
|
+
const payload = {
|
|
63
|
+
eventType: Event_1.DT_EVENT_TYPES.DEVICE.CREATE.SUCCESS,
|
|
64
|
+
properties: {
|
|
65
|
+
...body,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
69
|
+
}
|
|
70
|
+
async onDeviceUpdate(deviceId, body) {
|
|
71
|
+
await dt_pub_sub_1.eventDispatcher.publishEvent(Event_1.DT_EVENT_TYPES.DEVICE.UPDATE.SUCCESS, { deviceId, body }, this.source);
|
|
72
|
+
const payload = {
|
|
73
|
+
eventType: Event_1.DT_EVENT_TYPES.DEVICE.UPDATE.SUCCESS,
|
|
74
|
+
properties: {
|
|
75
|
+
...body,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
79
|
+
}
|
|
80
|
+
async onDeviceDelete(deviceId) {
|
|
81
|
+
await dt_pub_sub_1.eventDispatcher.publishEvent(Event_1.DT_EVENT_TYPES.DEVICE.DELETE.SUCCESS, { deviceId }, this.source);
|
|
82
|
+
const payload = {
|
|
83
|
+
eventType: Event_1.DT_EVENT_TYPES.DEVICE.DELETE.SUCCESS,
|
|
84
|
+
properties: {
|
|
85
|
+
deviceId,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
89
|
+
}
|
|
90
|
+
async onStateChange(deviceId, state) {
|
|
91
|
+
// TODO: For Future Consumption
|
|
92
|
+
/* await eventDispatcher.publishEvent(
|
|
93
|
+
DT_EVENT_TYPES.DEVICE.STATE.SET,
|
|
94
|
+
{ deviceId, state },
|
|
95
|
+
this.source
|
|
96
|
+
); */
|
|
97
|
+
const payload = {
|
|
98
|
+
eventType: Event_1.DT_EVENT_TYPES.DEVICE.STATE.SET,
|
|
99
|
+
properties: {
|
|
100
|
+
deviceId,
|
|
101
|
+
state,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
105
|
+
}
|
|
106
|
+
async onStatusChange(deviceId, status) {
|
|
107
|
+
// TODO: For Future Consumption
|
|
108
|
+
/* await eventDispatcher.publishEvent(
|
|
109
|
+
DT_EVENT_TYPES.DEVICE.STATUS.SET,
|
|
110
|
+
{ deviceId, status },
|
|
111
|
+
this.source
|
|
112
|
+
); */
|
|
113
|
+
const payload = {
|
|
114
|
+
eventType: Event_1.DT_EVENT_TYPES.DEVICE.STATUS.SET,
|
|
115
|
+
properties: {
|
|
116
|
+
deviceId,
|
|
117
|
+
status,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
121
|
+
}
|
|
122
|
+
async onBatteryLevelChange(deviceId, batteryLevel) {
|
|
123
|
+
// TODO: For Future Consumption
|
|
124
|
+
/* await eventDispatcher.publishEvent(
|
|
125
|
+
DT_EVENT_TYPES.DEVICE.BATTERY.SET,
|
|
126
|
+
{ deviceId, batteryLevel },
|
|
127
|
+
this.source
|
|
128
|
+
); */
|
|
129
|
+
const payload = {
|
|
130
|
+
eventType: Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.SET,
|
|
131
|
+
properties: {
|
|
132
|
+
deviceId,
|
|
133
|
+
batteryLevel,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
137
|
+
}
|
|
138
|
+
async onDeviceMetaChange(deviceId, metaData) {
|
|
139
|
+
// TODO: For Future Consumption
|
|
140
|
+
/* await eventDispatcher.publishEvent(
|
|
141
|
+
DT_EVENT_TYPES.DEVICE.META_DATA.SET,
|
|
142
|
+
{ deviceId, metaData },
|
|
143
|
+
this.source
|
|
144
|
+
); */
|
|
145
|
+
const payload = {
|
|
146
|
+
eventType: Event_1.DT_EVENT_TYPES.DEVICE.META_DATA.SET,
|
|
147
|
+
properties: {
|
|
148
|
+
deviceId,
|
|
149
|
+
metaData,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
__setFunctionName(_classThis, "EventHandler");
|
|
156
|
+
(() => {
|
|
157
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
158
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
159
|
+
EventHandler = _classThis = _classDescriptor.value;
|
|
160
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
161
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
162
|
+
})();
|
|
163
|
+
return EventHandler = _classThis;
|
|
164
|
+
})();
|
|
111
165
|
exports.EventHandler = EventHandler;
|
|
@@ -37,12 +37,16 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
37
37
|
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
38
|
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
39
|
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
40
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
44
|
exports.EventProcessingService = void 0;
|
|
42
45
|
const typedi_1 = require("typedi");
|
|
43
46
|
const DeviceEventHandler_1 = require("./DeviceEventHandler");
|
|
44
47
|
const config_1 = require("../config/config");
|
|
45
48
|
const EventHandlerOrchestrator_1 = require("./EventHandlerOrchestrator");
|
|
49
|
+
const typedi_2 = __importDefault(require("typedi"));
|
|
46
50
|
let EventProcessingService = (() => {
|
|
47
51
|
let _classDecorators = [(0, typedi_1.Service)()];
|
|
48
52
|
let _classDescriptor;
|
|
@@ -53,7 +57,8 @@ let EventProcessingService = (() => {
|
|
|
53
57
|
this.deviceEventTransformerFactory = deviceEventTransformerFactory;
|
|
54
58
|
this.deviceHandlers = new Map();
|
|
55
59
|
this.handlerOrchestrator = new EventHandlerOrchestrator_1.EventHandlerOrchestrator();
|
|
56
|
-
|
|
60
|
+
// Use dependency injection instead of creating new instance
|
|
61
|
+
this.deviceEventHandler = typedi_2.default.get(DeviceEventHandler_1.DeviceEventHandler);
|
|
57
62
|
this.logger = (0, config_1.getConfig)().LOGGER;
|
|
58
63
|
this.initializeDeviceHandlers();
|
|
59
64
|
this.initializeHandlers();
|
|
@@ -70,9 +75,9 @@ let EventProcessingService = (() => {
|
|
|
70
75
|
*/
|
|
71
76
|
initializeHandlers() {
|
|
72
77
|
try {
|
|
73
|
-
// Register generic handler for common events
|
|
78
|
+
// Register generic handler for common events - reuse existing instance
|
|
74
79
|
this.handlerOrchestrator.registerHandlers([
|
|
75
|
-
|
|
80
|
+
this.deviceEventHandler, // Use existing instance instead of creating new one
|
|
76
81
|
]);
|
|
77
82
|
this.logger.info("Base event handlers initialized successfully");
|
|
78
83
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { CloudDevice, CloudDeviceService, DeviceFactory, } from "./device/cloud/
|
|
|
4
4
|
export { LocalDeviceService, LocalHubService, LocalScheduleService, } from "./device/local/services";
|
|
5
5
|
export * from "./device/local/interfaces";
|
|
6
6
|
export * from "./device/cloud/interfaces";
|
|
7
|
+
export * from "./admin";
|
|
7
8
|
export * from "./connection";
|
|
8
9
|
export * from "./property";
|
|
9
10
|
export * from "./events";
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,8 @@ Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: funct
|
|
|
31
31
|
Object.defineProperty(exports, "LocalScheduleService", { enumerable: true, get: function () { return services_1.LocalScheduleService; } });
|
|
32
32
|
__exportStar(require("./device/local/interfaces"), exports);
|
|
33
33
|
__exportStar(require("./device/cloud/interfaces"), exports);
|
|
34
|
+
// ADMIN EXPORTS
|
|
35
|
+
__exportStar(require("./admin"), exports);
|
|
34
36
|
// CONNECTION EXPORTS
|
|
35
37
|
__exportStar(require("./connection"), exports);
|
|
36
38
|
// PROPERTY EXPORTS
|
|
@@ -2,7 +2,7 @@ import { SERVICE_NAME } from "../constants";
|
|
|
2
2
|
import { DeviceType } from "../device/cloud/interfaces";
|
|
3
3
|
export declare class MicroServiceFactory {
|
|
4
4
|
private readonly deviceType;
|
|
5
|
-
private static
|
|
5
|
+
private static instances;
|
|
6
6
|
constructor(deviceType: DeviceType);
|
|
7
7
|
getMicroService(): SERVICE_NAME;
|
|
8
8
|
static getInstance(deviceType: DeviceType): MicroServiceFactory;
|
|
@@ -22,10 +22,12 @@ class MicroServiceFactory {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
static getInstance(deviceType) {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// Use device type as key to allow multiple instances for different device types
|
|
26
|
+
if (!MicroServiceFactory.instances.has(deviceType)) {
|
|
27
|
+
MicroServiceFactory.instances.set(deviceType, new MicroServiceFactory(deviceType));
|
|
27
28
|
}
|
|
28
|
-
return MicroServiceFactory.
|
|
29
|
+
return MicroServiceFactory.instances.get(deviceType);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
exports.MicroServiceFactory = MicroServiceFactory;
|
|
33
|
+
MicroServiceFactory.instances = new Map();
|