dt-common-device 1.0.20 → 1.2.1
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/device/cloud/entities/CloudConnection.d.ts +6 -0
- package/dist/device/cloud/entities/CloudConnection.js +6 -0
- package/dist/device/cloud/entities/CloudDevice.js +0 -19
- package/dist/device/cloud/entities/CloudDeviceService.d.ts +5 -0
- package/dist/device/cloud/entities/CloudDeviceService.js +9 -0
- package/dist/device/cloud/entities/DeviceFactory.d.ts +2 -1
- package/dist/device/cloud/entities/index.d.ts +2 -0
- package/dist/device/cloud/entities/index.js +2 -0
- package/dist/device/cloud/interfaces/ICloudConnection.d.ts +5 -0
- package/dist/device/cloud/interfaces/ICloudConnection.js +2 -0
- package/dist/device/cloud/interfaces/IDeviceFactory.d.ts +4 -0
- package/dist/device/cloud/interfaces/IDeviceFactory.js +2 -0
- package/dist/device/cloud/interfaces/index.d.ts +1 -3
- package/dist/device/cloud/interfaces/index.js +1 -3
- package/dist/device/cloud/types.d.ts +1 -1
- package/dist/device/local/events/EventHandler.d.ts +10 -0
- package/dist/device/local/events/EventHandler.js +75 -0
- package/dist/device/local/events/Events.d.ts +21 -0
- package/dist/device/local/events/Events.js +24 -0
- package/dist/device/local/interfaces/IDtDevice.d.ts +16 -0
- package/dist/device/local/interfaces/IDtDevice.js +2 -0
- package/dist/device/local/interfaces/index.d.ts +0 -1
- package/dist/device/local/interfaces/index.js +0 -1
- package/dist/device/local/repository/Connection.repository.d.ts +7 -0
- package/dist/device/local/repository/Connection.repository.js +77 -0
- package/dist/device/local/repository/Device.repository.d.ts +16 -0
- package/dist/device/local/repository/Device.repository.js +134 -0
- package/dist/device/local/repository/Hub.repository.d.ts +13 -0
- package/dist/device/local/repository/Hub.repository.js +97 -0
- package/dist/device/local/repository/Property.repository.d.ts +9 -0
- package/dist/device/local/repository/Property.repository.js +81 -0
- package/dist/device/local/services/Connection.service.d.ts +3 -2
- package/dist/device/local/services/Connection.service.js +7 -4
- package/dist/device/local/services/Device.service.d.ts +7 -9
- package/dist/device/local/services/Device.service.js +17 -91
- package/dist/device/local/services/Hub.service.d.ts +7 -7
- package/dist/device/local/services/Hub.service.js +13 -21
- package/dist/device/local/services/Property.service.d.ts +9 -0
- package/dist/device/local/services/Property.service.js +13 -0
- package/dist/device/local/services/index.d.ts +2 -1
- package/dist/device/local/services/index.js +4 -2
- package/dist/index.d.ts +2 -3
- package/dist/index.js +8 -8
- package/package.json +4 -3
- package/src/device/cloud/entities/CloudConnection.ts +13 -0
- package/src/device/cloud/entities/CloudDevice.ts +1 -21
- package/src/device/cloud/entities/DeviceFactory.ts +2 -1
- package/src/device/cloud/entities/index.ts +2 -0
- package/src/device/cloud/interfaces/ICloudConnection.ts +6 -0
- package/src/device/cloud/interfaces/ICloudDevice.ts +0 -1
- package/src/device/cloud/interfaces/IDeviceFactory.ts +5 -0
- package/src/device/cloud/interfaces/index.ts +1 -3
- package/src/device/cloud/types.ts +1 -1
- package/src/device/local/events/EventHandler.ts +101 -0
- package/src/device/local/events/Events.ts +23 -0
- package/src/device/local/interfaces/IDtDevice.ts +16 -0
- package/src/device/local/interfaces/index.ts +0 -1
- package/src/device/local/repository/Connection.repository.ts +32 -0
- package/src/device/local/repository/Device.repository.ts +106 -0
- package/src/device/local/repository/Hub.repository.ts +51 -0
- package/src/device/local/repository/Property.repository.ts +32 -0
- package/src/device/local/services/Connection.service.ts +11 -9
- package/src/device/local/services/Device.service.ts +21 -109
- package/src/device/local/services/Hub.service.ts +17 -28
- package/src/device/local/services/Property.service.ts +12 -0
- package/src/device/local/services/index.ts +2 -1
- package/src/index.ts +5 -3
- package/src/device/cloud/interfaces/IConnectionService.ts +0 -15
- package/src/device/cloud/interfaces/IDeviceService.ts +0 -12
- package/src/device/cloud/interfaces/IHubService.ts +0 -5
- package/src/device/cloud/services/Connection.service.ts +0 -19
- package/src/device/cloud/services/index.ts +0 -2
- package/src/device/local/handler/EventHandler.ts +0 -52
- package/src/device/local/interfaces/IConnection.ts +0 -17
- package/src/device/local/interfaces/IHub.ts +0 -46
- /package/src/device/cloud/{services/CloudDevice.service.ts → entities/CloudDeviceService.ts} +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.PropertyRepository = void 0;
|
|
42
|
+
const db_1 = require("../../../db");
|
|
43
|
+
const typedi_1 = require("typedi");
|
|
44
|
+
let PropertyRepository = (() => {
|
|
45
|
+
let _classDecorators = [(0, typedi_1.Service)()];
|
|
46
|
+
let _classDescriptor;
|
|
47
|
+
let _classExtraInitializers = [];
|
|
48
|
+
let _classThis;
|
|
49
|
+
var PropertyRepository = _classThis = class {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.postgres = (0, db_1.getPostgresClient)();
|
|
52
|
+
}
|
|
53
|
+
async getPropertyPreferences(propertyId) {
|
|
54
|
+
try {
|
|
55
|
+
const propertyPreferences = await this.postgres.query("SELECT * FROM dt_property_settings WHERE propertyId = $1", [propertyId]);
|
|
56
|
+
if (propertyPreferences.rows.length > 0) {
|
|
57
|
+
return {
|
|
58
|
+
id: propertyPreferences.rows[0].id,
|
|
59
|
+
propertyId: propertyPreferences.rows[0].propertyId,
|
|
60
|
+
settings: JSON.parse(propertyPreferences.rows[0].settings),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.log(error);
|
|
67
|
+
throw new Error("Failed to get property preferences");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
__setFunctionName(_classThis, "PropertyRepository");
|
|
72
|
+
(() => {
|
|
73
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
74
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
75
|
+
PropertyRepository = _classThis = _classDescriptor.value;
|
|
76
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
77
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
78
|
+
})();
|
|
79
|
+
return PropertyRepository = _classThis;
|
|
80
|
+
})();
|
|
81
|
+
exports.PropertyRepository = PropertyRepository;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { IConnection } from "
|
|
1
|
+
import { IConnection } from "../../cloud/types";
|
|
2
2
|
export declare class LocalConnectionService {
|
|
3
|
-
private readonly
|
|
3
|
+
private readonly connectionRepository;
|
|
4
4
|
constructor();
|
|
5
5
|
getConnection(connectionId: string): Promise<IConnection>;
|
|
6
|
+
updateConnection(connectionId: string, data: any): Promise<any>;
|
|
6
7
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocalConnectionService = void 0;
|
|
4
|
-
const
|
|
4
|
+
const typedi_1 = require("typedi");
|
|
5
|
+
const Connection_repository_1 = require("../repository/Connection.repository");
|
|
5
6
|
class LocalConnectionService {
|
|
6
7
|
constructor() {
|
|
7
|
-
this.
|
|
8
|
+
this.connectionRepository = typedi_1.Container.get(Connection_repository_1.ConnectionRepository);
|
|
8
9
|
}
|
|
9
10
|
async getConnection(connectionId) {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
return await this.connectionRepository.getConnectionById(connectionId);
|
|
12
|
+
}
|
|
13
|
+
async updateConnection(connectionId, data) {
|
|
14
|
+
return await this.connectionRepository.updateConnection(connectionId, data);
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
exports.LocalConnectionService = LocalConnectionService;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { IDevice } from "../interfaces";
|
|
2
2
|
export declare class LocalDeviceService {
|
|
3
|
-
private readonly baseUrl;
|
|
4
3
|
private readonly source;
|
|
5
4
|
private readonly eventHandler;
|
|
6
5
|
private readonly alertService;
|
|
7
|
-
private readonly
|
|
6
|
+
private readonly deviceRepository;
|
|
8
7
|
constructor();
|
|
9
8
|
createDevice(body: IDevice): Promise<void>;
|
|
10
9
|
getDevice(deviceId: string, withHubDetails?: boolean): Promise<IDevice>;
|
|
@@ -12,15 +11,14 @@ export declare class LocalDeviceService {
|
|
|
12
11
|
getPropertyDevices(propertyId: string, withHubDetails?: boolean): Promise<IDevice[]>;
|
|
13
12
|
updateDevice(deviceId: string, body: any): Promise<any>;
|
|
14
13
|
deleteDevice(deviceId: string): Promise<any>;
|
|
15
|
-
getState(deviceId: string): Promise<
|
|
14
|
+
getState(deviceId: string): Promise<any>;
|
|
16
15
|
setState(deviceId: string, newState: any): Promise<void>;
|
|
17
|
-
getStatus(deviceId: string): Promise<
|
|
16
|
+
getStatus(deviceId: string): Promise<Record<string, any>>;
|
|
18
17
|
setStatus(deviceId: string, newStatus: any): Promise<void>;
|
|
19
|
-
getBatteryLevel(deviceId: string): Promise<
|
|
18
|
+
getBatteryLevel(deviceId: string): Promise<Record<string, any>>;
|
|
20
19
|
setBatteryLevel(deviceId: string, newBatteryLevel: any): Promise<void>;
|
|
21
|
-
getMetaData(deviceId: string): Promise<
|
|
20
|
+
getMetaData(deviceId: string): Promise<any>;
|
|
22
21
|
setMetaData(deviceId: string, metaData: Record<string, any>): Promise<void>;
|
|
23
|
-
|
|
24
|
-
getDevicesByAccessGroup(accessGroupId: string): Promise<
|
|
25
|
-
getPropertyPreferences(propertyId: string): Promise<any>;
|
|
22
|
+
getDevicesByZone(zoneId: string): Promise<import("../interfaces/IDtDevice").IDtDevice[]>;
|
|
23
|
+
getDevicesByAccessGroup(accessGroupId: string): Promise<import("../interfaces/IDtDevice").IDtDevice[]>;
|
|
26
24
|
}
|
|
@@ -4,82 +4,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.LocalDeviceService = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
7
|
const config_1 = require("../../../config/config");
|
|
9
8
|
const dt_pub_sub_1 = require("dt-pub-sub");
|
|
10
9
|
const dt_audit_library_1 = require("dt-audit-library");
|
|
11
|
-
const EventHandler_1 = require("../
|
|
10
|
+
const EventHandler_1 = require("../events/EventHandler");
|
|
12
11
|
const lodash_1 = require("lodash");
|
|
13
12
|
const Alert_service_1 = require("./Alert.service");
|
|
14
|
-
const
|
|
13
|
+
const Device_repository_1 = require("../repository/Device.repository");
|
|
14
|
+
const typedi_1 = __importDefault(require("typedi"));
|
|
15
15
|
class LocalDeviceService {
|
|
16
16
|
constructor() {
|
|
17
17
|
this.source = "dt-common-device";
|
|
18
|
-
const { DEVICE_SERVICE } = (0, config_1.getConfig)();
|
|
19
|
-
if (!DEVICE_SERVICE) {
|
|
20
|
-
throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE.");
|
|
21
|
-
}
|
|
22
18
|
// this.redis = getRedisClient();
|
|
23
|
-
this.postgres = (0, db_1.getPostgresClient)();
|
|
24
|
-
this.baseUrl = DEVICE_SERVICE;
|
|
25
19
|
(0, config_1.checkAwsEnv)();
|
|
26
20
|
(0, config_1.ensureAuditInitialized)();
|
|
27
21
|
this.eventHandler = new EventHandler_1.EventHandler();
|
|
28
22
|
this.alertService = new Alert_service_1.AlertService();
|
|
23
|
+
this.deviceRepository = typedi_1.default.get(Device_repository_1.DeviceRepository);
|
|
29
24
|
}
|
|
30
25
|
async createDevice(body) {
|
|
31
|
-
await
|
|
32
|
-
const payload = {
|
|
33
|
-
eventType: "device.created",
|
|
34
|
-
properties: {
|
|
35
|
-
...body,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
26
|
+
return await this.eventHandler.onDeviceCreate(body);
|
|
39
27
|
}
|
|
40
28
|
async getDevice(deviceId, withHubDetails = false) {
|
|
41
|
-
|
|
42
|
-
const response = await axios_1.default.get(`${this.baseUrl}/devices/${deviceId}?withHubDetails=${withHubDetails} `);
|
|
43
|
-
return response.data;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.log(error);
|
|
47
|
-
throw new Error(`Failed to get device: ${error.message}`);
|
|
48
|
-
}
|
|
29
|
+
return await this.deviceRepository.getDevice(deviceId, withHubDetails);
|
|
49
30
|
}
|
|
50
31
|
async getDevices(deviceIds, withHubDetails = false) {
|
|
51
|
-
return await
|
|
52
|
-
params: { deviceIds, withHubDetails },
|
|
53
|
-
});
|
|
32
|
+
return await this.deviceRepository.getDevices(deviceIds, withHubDetails);
|
|
54
33
|
}
|
|
55
34
|
async getPropertyDevices(propertyId, withHubDetails = false) {
|
|
56
|
-
return await
|
|
57
|
-
params: { propertyId, withHubDetails },
|
|
58
|
-
});
|
|
35
|
+
return await this.deviceRepository.getPropertyDevices(propertyId, withHubDetails);
|
|
59
36
|
}
|
|
60
37
|
async updateDevice(deviceId, body) {
|
|
61
|
-
|
|
62
|
-
await dt_pub_sub_1.eventDispatcher.publishEvent("device.updated", { deviceId, body }, this.source);
|
|
63
|
-
const payload = {
|
|
64
|
-
eventType: "device.updated",
|
|
65
|
-
properties: {
|
|
66
|
-
...body,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
38
|
+
return await this.eventHandler.onDeviceUpdate(deviceId, body);
|
|
70
39
|
}
|
|
71
40
|
async deleteDevice(deviceId) {
|
|
72
|
-
await
|
|
73
|
-
const payload = {
|
|
74
|
-
eventType: "device.deleted",
|
|
75
|
-
properties: {
|
|
76
|
-
deviceId,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
41
|
+
return await this.eventHandler.onDeviceDelete(deviceId);
|
|
80
42
|
}
|
|
81
43
|
async getState(deviceId) {
|
|
82
|
-
return await
|
|
44
|
+
return await this.deviceRepository.getState(deviceId);
|
|
83
45
|
}
|
|
84
46
|
async setState(deviceId, newState) {
|
|
85
47
|
// If old state and new state are different
|
|
@@ -90,7 +52,7 @@ class LocalDeviceService {
|
|
|
90
52
|
}
|
|
91
53
|
}
|
|
92
54
|
async getStatus(deviceId) {
|
|
93
|
-
return await
|
|
55
|
+
return await this.deviceRepository.getStatus(deviceId);
|
|
94
56
|
}
|
|
95
57
|
async setStatus(deviceId, newStatus) {
|
|
96
58
|
// If old status and new status are different
|
|
@@ -113,7 +75,7 @@ class LocalDeviceService {
|
|
|
113
75
|
}
|
|
114
76
|
}
|
|
115
77
|
async getBatteryLevel(deviceId) {
|
|
116
|
-
return await
|
|
78
|
+
return await this.deviceRepository.getBatteryLevel(deviceId);
|
|
117
79
|
}
|
|
118
80
|
async setBatteryLevel(deviceId, newBatteryLevel) {
|
|
119
81
|
// If old battery level and new battery level are different
|
|
@@ -132,7 +94,7 @@ class LocalDeviceService {
|
|
|
132
94
|
}
|
|
133
95
|
}
|
|
134
96
|
async getMetaData(deviceId) {
|
|
135
|
-
return await
|
|
97
|
+
return await this.deviceRepository.getMetaData(deviceId);
|
|
136
98
|
}
|
|
137
99
|
async setMetaData(deviceId, metaData) {
|
|
138
100
|
await dt_pub_sub_1.eventDispatcher.publishEvent("device.metaData.set", { deviceId, metaData }, this.source);
|
|
@@ -145,47 +107,11 @@ class LocalDeviceService {
|
|
|
145
107
|
};
|
|
146
108
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
147
109
|
}
|
|
148
|
-
async
|
|
149
|
-
|
|
150
|
-
// If not available, fetch from PostgreSQL DB
|
|
151
|
-
const result = await this.postgres.query("SELECT * FROM dt_devices WHERE zoneId = $1", [zoneId]);
|
|
152
|
-
if (result.rows.length > 0) {
|
|
153
|
-
return result.rows[0];
|
|
154
|
-
}
|
|
155
|
-
// If data is not available, return null
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
console.log(error);
|
|
160
|
-
throw new Error("Failed to get device by zone");
|
|
161
|
-
}
|
|
110
|
+
async getDevicesByZone(zoneId) {
|
|
111
|
+
return await this.deviceRepository.getDevicesByZone(zoneId);
|
|
162
112
|
}
|
|
163
113
|
async getDevicesByAccessGroup(accessGroupId) {
|
|
164
|
-
|
|
165
|
-
// Fetch from Postgres if not in cache
|
|
166
|
-
const result = await this.postgres.query("SELECT * FROM dt_group WHERE id = $1", [accessGroupId]);
|
|
167
|
-
if (result.rows.length > 0) {
|
|
168
|
-
return result.rows[0];
|
|
169
|
-
}
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
console.log(error);
|
|
174
|
-
throw new Error("Failed to get devices by access group");
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
async getPropertyPreferences(propertyId) {
|
|
178
|
-
try {
|
|
179
|
-
const propertyPreferences = await this.postgres.query("SELECT * FROM dt_property_settings WHERE propertyId = $1", [propertyId]);
|
|
180
|
-
if (propertyPreferences.rows.length > 0) {
|
|
181
|
-
return propertyPreferences.rows[0];
|
|
182
|
-
}
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
console.log(error);
|
|
187
|
-
throw new Error("Failed to get property preferences");
|
|
188
|
-
}
|
|
114
|
+
return await this.deviceRepository.getDevicesByAccessGroup(accessGroupId);
|
|
189
115
|
}
|
|
190
116
|
}
|
|
191
117
|
exports.LocalDeviceService = LocalDeviceService;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class
|
|
3
|
-
private readonly
|
|
1
|
+
import { IDevice } from "../interfaces";
|
|
2
|
+
export declare class LocalHubService {
|
|
3
|
+
private readonly hubRepository;
|
|
4
4
|
constructor();
|
|
5
|
-
addHub(body:
|
|
6
|
-
getHubs(hubIds: string[]): Promise<
|
|
7
|
-
getHub(hubId: string): Promise<
|
|
8
|
-
updateHub(hubId: string, body:
|
|
5
|
+
addHub(body: IDevice): Promise<IDevice>;
|
|
6
|
+
getHubs(hubIds: string[]): Promise<IDevice[]>;
|
|
7
|
+
getHub(hubId: string): Promise<IDevice>;
|
|
8
|
+
updateHub(hubId: string, body: Partial<IDevice>): Promise<IDevice>;
|
|
9
9
|
getStatus(hubId: string): Promise<any>;
|
|
10
10
|
deleteHub(hubId: string): Promise<any>;
|
|
11
11
|
deleteAllHubs(hubIds: string[]): Promise<any>;
|
|
@@ -3,41 +3,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
class
|
|
6
|
+
exports.LocalHubService = void 0;
|
|
7
|
+
const Hub_repository_1 = require("../repository/Hub.repository");
|
|
8
|
+
const typedi_1 = __importDefault(require("typedi"));
|
|
9
|
+
class LocalHubService {
|
|
10
10
|
constructor() {
|
|
11
|
-
|
|
12
|
-
if (!DEVICE_SERVICE) {
|
|
13
|
-
throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE.");
|
|
14
|
-
}
|
|
15
|
-
this.baseUrl = DEVICE_SERVICE;
|
|
11
|
+
this.hubRepository = typedi_1.default.get(Hub_repository_1.HubRepository);
|
|
16
12
|
}
|
|
17
13
|
async addHub(body) {
|
|
18
|
-
return await
|
|
14
|
+
return await this.hubRepository.addHub(body);
|
|
19
15
|
}
|
|
20
|
-
//get hubs takes an array of hub ids as query params
|
|
21
16
|
async getHubs(hubIds) {
|
|
22
|
-
|
|
23
|
-
return await axios_1.default.get(`${this.baseUrl}/devices/hubs${query}`);
|
|
17
|
+
return await this.hubRepository.getHubs(hubIds);
|
|
24
18
|
}
|
|
25
|
-
//get hub takes a hub id in params
|
|
26
19
|
async getHub(hubId) {
|
|
27
|
-
return await
|
|
20
|
+
return await this.hubRepository.getHub(hubId);
|
|
28
21
|
}
|
|
29
22
|
async updateHub(hubId, body) {
|
|
30
|
-
return await
|
|
23
|
+
return await this.hubRepository.updateHub(hubId, body);
|
|
31
24
|
}
|
|
32
25
|
async getStatus(hubId) {
|
|
33
|
-
return await
|
|
26
|
+
return await this.hubRepository.getStatus(hubId);
|
|
34
27
|
}
|
|
35
28
|
async deleteHub(hubId) {
|
|
36
|
-
return await
|
|
29
|
+
return await this.hubRepository.deleteHub(hubId);
|
|
37
30
|
}
|
|
38
31
|
async deleteAllHubs(hubIds) {
|
|
39
|
-
|
|
40
|
-
return await axios_1.default.delete(`${this.baseUrl}/devices/hubs${query}`);
|
|
32
|
+
return await this.hubRepository.deleteAllHubs(hubIds);
|
|
41
33
|
}
|
|
42
34
|
}
|
|
43
|
-
exports.
|
|
35
|
+
exports.LocalHubService = LocalHubService;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalPropertyService = void 0;
|
|
4
|
+
const Property_repository_1 = require("../repository/Property.repository");
|
|
5
|
+
class LocalPropertyService {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.propertyRepository = new Property_repository_1.PropertyRepository();
|
|
8
|
+
}
|
|
9
|
+
async getPropertyPreferences(propertyId) {
|
|
10
|
+
return await this.propertyRepository.getPropertyPreferences(propertyId);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.LocalPropertyService = LocalPropertyService;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { LocalDeviceService } from "./Device.service";
|
|
2
|
-
export {
|
|
2
|
+
export { LocalHubService } from "./Hub.service";
|
|
3
3
|
export { LocalConnectionService } from "./Connection.service";
|
|
4
|
+
export { LocalPropertyService } from "./Property.service";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = void 0;
|
|
3
|
+
exports.LocalPropertyService = exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = void 0;
|
|
4
4
|
var Device_service_1 = require("./Device.service");
|
|
5
5
|
Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return Device_service_1.LocalDeviceService; } });
|
|
6
6
|
var Hub_service_1 = require("./Hub.service");
|
|
7
|
-
Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return Hub_service_1.
|
|
7
|
+
Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return Hub_service_1.LocalHubService; } });
|
|
8
8
|
var Connection_service_1 = require("./Connection.service");
|
|
9
9
|
Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return Connection_service_1.LocalConnectionService; } });
|
|
10
|
+
var Property_service_1 = require("./Property.service");
|
|
11
|
+
Object.defineProperty(exports, "LocalPropertyService", { enumerable: true, get: function () { return Property_service_1.LocalPropertyService; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { LocalDeviceService, LocalHubService, LocalConnectionService, } from "./device/local/services";
|
|
1
|
+
export { CloudDevice, DeviceFactory, CloudConnection, CloudDeviceService, } from "./device/cloud/entities";
|
|
2
|
+
export { LocalDeviceService, LocalHubService, LocalConnectionService, LocalPropertyService, } from "./device/local/services";
|
|
4
3
|
export * from "./device/cloud/interfaces";
|
|
5
4
|
export * from "./device/cloud/types";
|
|
6
5
|
export * from "./device/local/interfaces";
|
package/dist/index.js
CHANGED
|
@@ -15,18 +15,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getConfig = exports.initialize = exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = exports.
|
|
18
|
+
exports.getConfig = exports.initialize = exports.LocalPropertyService = exports.LocalConnectionService = exports.LocalHubService = exports.LocalDeviceService = exports.CloudDeviceService = exports.CloudConnection = exports.DeviceFactory = exports.CloudDevice = void 0;
|
|
19
19
|
// Cloud exports
|
|
20
|
-
var services_1 = require("./device/cloud/services");
|
|
21
|
-
Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return services_1.CloudDeviceService; } });
|
|
22
|
-
Object.defineProperty(exports, "CloudConnectionService", { enumerable: true, get: function () { return services_1.ConnectionService; } });
|
|
23
20
|
var entities_1 = require("./device/cloud/entities");
|
|
24
21
|
Object.defineProperty(exports, "CloudDevice", { enumerable: true, get: function () { return entities_1.CloudDevice; } });
|
|
25
22
|
Object.defineProperty(exports, "DeviceFactory", { enumerable: true, get: function () { return entities_1.DeviceFactory; } });
|
|
26
|
-
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(exports, "
|
|
23
|
+
Object.defineProperty(exports, "CloudConnection", { enumerable: true, get: function () { return entities_1.CloudConnection; } });
|
|
24
|
+
Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return entities_1.CloudDeviceService; } });
|
|
25
|
+
var services_1 = require("./device/local/services");
|
|
26
|
+
Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return services_1.LocalDeviceService; } });
|
|
27
|
+
Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return services_1.LocalHubService; } });
|
|
28
|
+
Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return services_1.LocalConnectionService; } });
|
|
29
|
+
Object.defineProperty(exports, "LocalPropertyService", { enumerable: true, get: function () { return services_1.LocalPropertyService; } });
|
|
30
30
|
__exportStar(require("./device/cloud/interfaces"), exports);
|
|
31
31
|
__exportStar(require("./device/cloud/types"), exports);
|
|
32
32
|
// Local exports
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dt-common-device",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "tsc
|
|
7
|
+
"build": "tsc",
|
|
8
8
|
"patch": "npm version patch && npm run build",
|
|
9
9
|
"minor": "npm version minor && npm run build",
|
|
10
10
|
"major": "npm version major && npm run build",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"dt-pub-sub": "^1.0.0",
|
|
44
44
|
"ioredis": "5.6.1",
|
|
45
45
|
"lodash": "^4.17.21",
|
|
46
|
-
"pg": "8.16.3"
|
|
46
|
+
"pg": "8.16.3",
|
|
47
|
+
"typedi": "0.10.0"
|
|
47
48
|
}
|
|
48
49
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Device Cloud Service - Class Implementation
|
|
2
|
+
import { ICloudConnection } from "../interfaces";
|
|
3
|
+
import { IDeviceAccountResponse, IConnection } from "../types";
|
|
4
|
+
|
|
5
|
+
export abstract class CloudConnection implements ICloudConnection {
|
|
6
|
+
abstract createConnection(
|
|
7
|
+
data: IConnection,
|
|
8
|
+
userId: string
|
|
9
|
+
): Promise<IConnection>;
|
|
10
|
+
abstract getDeviceAccount(
|
|
11
|
+
connection: IConnection
|
|
12
|
+
): Promise<IDeviceAccountResponse>;
|
|
13
|
+
}
|
|
@@ -33,24 +33,4 @@ export abstract class CloudDevice implements ICloudDevice {
|
|
|
33
33
|
async getStatus(connectionId: string, deviceId: string): Promise<string> {
|
|
34
34
|
throw new Error("Method not implemented in Super Class.");
|
|
35
35
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/*
|
|
39
|
-
Usage Example:
|
|
40
|
-
|
|
41
|
-
// When extending CloudDevice, you can now do:
|
|
42
|
-
class MyCloudDevice extends CloudDevice {
|
|
43
|
-
constructor(device: IDevice, cloudDeviceService: ICloudDeviceService) {
|
|
44
|
-
super(device, cloudDeviceService);
|
|
45
|
-
// Additional initialization if needed
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Create and initialize in one step:
|
|
50
|
-
const device = await MyCloudDevice.create(device, cloudDeviceService);
|
|
51
|
-
// The device is now fully initialized with connection and localDevice loaded
|
|
52
|
-
|
|
53
|
-
// Or if you need to create without auto-initialization:
|
|
54
|
-
const device = new MyCloudDevice(device, cloudDeviceService);
|
|
55
|
-
await device.initialize(); // Manual initialization
|
|
56
|
-
*/
|
|
36
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { IDevice } from "../../local/interfaces";
|
|
2
2
|
import { LocalDeviceService } from "../../local/services/Device.service";
|
|
3
|
+
import { IDeviceFactory } from "../interfaces/IDeviceFactory";
|
|
3
4
|
|
|
4
|
-
export class DeviceFactory {
|
|
5
|
+
export class DeviceFactory implements IDeviceFactory {
|
|
5
6
|
private readonly localDeviceService: LocalDeviceService;
|
|
6
7
|
|
|
7
8
|
constructor() {
|