dt-common-device 1.0.4 → 1.0.5

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/README.md CHANGED
@@ -28,6 +28,65 @@ At least one service URL must be provided.
28
28
 
29
29
  ---
30
30
 
31
+ ## Implementing Abstract Classes (Cloud Connection Example)
32
+
33
+ This library provides abstract classes (such as `ConnectionService`) that define the required contract for cloud connection managers. **You should extend these abstract classes and implement all required methods.**
34
+
35
+ **You do NOT need to instantiate your class unless you want to use it in your application logic.**
36
+
37
+ ### Example: Implementing a Cloud Connection Service
38
+
39
+ ```ts
40
+ import {
41
+ ConnectionService,
42
+ IConnection,
43
+ IDevice,
44
+ IDeviceAccountResponse,
45
+ IConnectionConnectParams,
46
+ } from "dt-common-device";
47
+
48
+ class MyConnectionService extends ConnectionService {
49
+ async createConnection(data: IConnection, userId: string): Promise<any> {
50
+ // Your implementation
51
+ }
52
+
53
+ async getDeviceAccount(
54
+ connection: IConnection
55
+ ): Promise<IDeviceAccountResponse> {
56
+ // Your implementation
57
+ }
58
+
59
+ async getDevices(connection: IConnection): Promise<IDevice[]> {
60
+ // Your implementation
61
+ }
62
+
63
+ async filterDevices(
64
+ connection: IConnection,
65
+ devices: Record<string, any>[]
66
+ ): Promise<IDevice[]> {
67
+ // Your implementation
68
+ }
69
+
70
+ async connect(
71
+ connection: IConnection,
72
+ connectionConnect: IConnectionConnectParams
73
+ ): Promise<any> {
74
+ // Your implementation
75
+ }
76
+ }
77
+ ```
78
+
79
+ - TypeScript will enforce that you implement all required methods.
80
+ - If you miss any, you will get a compile-time error.
81
+ - You only need to instantiate your class if you want to use it in your application logic:
82
+
83
+ ```ts
84
+ const myService = new MyConnectionService();
85
+ myService.createConnection(...);
86
+ ```
87
+
88
+ ---
89
+
31
90
  ## Importing Services
32
91
 
33
92
  ### Cloud Device Service
@@ -10,6 +10,7 @@ function initialize(cfg) {
10
10
  "OPERATIONAL_SERVICE",
11
11
  "DEVICE_SERVICE",
12
12
  "MONITORING_SERVICE",
13
+ "ENERGY_SERVICE",
13
14
  ].some((key) => Boolean(cfg[key]));
14
15
  if (!hasAtLeastOneService) {
15
16
  throw new Error("At least one http service must be initialized");
@@ -1,9 +1,9 @@
1
1
  import { IDeviceConnectionService } from "../interfaces";
2
- import { IConnection, IDevice, IDeviceAccountResponse } from "../types";
3
- export declare class ConnectionService implements IDeviceConnectionService {
4
- createConnection(data: IConnection, userId: string): Promise<void>;
5
- getDeviceAccount(connection: IConnection): Promise<IDeviceAccountResponse>;
6
- getDevices(connection: IConnection): Promise<IDevice[]>;
7
- filterDevices(connection: IConnection, devices: Record<string, any>[]): Promise<IDevice[]>;
8
- connect(connection: IConnection): Promise<void>;
2
+ import { IConnection, IDevice, IDeviceAccountResponse, IConnectionConnectParams } from "../types";
3
+ export declare abstract class ConnectionService implements IDeviceConnectionService {
4
+ abstract createConnection(data: IConnection, userId: string): Promise<any>;
5
+ abstract getDeviceAccount(connection: IConnection): Promise<IDeviceAccountResponse>;
6
+ abstract getDevices(connection: IConnection): Promise<IDevice[]>;
7
+ abstract filterDevices(connection: IConnection, devices: Record<string, any>[]): Promise<IDevice[]>;
8
+ abstract connect(connection: IConnection, connectionConnect: IConnectionConnectParams): Promise<any>;
9
9
  }
@@ -2,25 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectionService = void 0;
4
4
  class ConnectionService {
5
- async createConnection(data, userId) {
6
- // Implementation will be provided by the consuming project
7
- throw new Error("createConnection method not implemented");
8
- }
9
- async getDeviceAccount(connection) {
10
- // Implementation will be provided by the consuming project
11
- throw new Error("getDeviceAccount method not implemented");
12
- }
13
- async getDevices(connection) {
14
- // Implementation will be provided by the consuming project
15
- throw new Error("getDevices method not implemented");
16
- }
17
- async filterDevices(connection, devices) {
18
- // Implementation will be provided by the consuming project
19
- throw new Error("filterDevices method not implemented");
20
- }
21
- async connect(connection) {
22
- // Implementation will be provided by the consuming project
23
- throw new Error("connect method not implemented");
24
- }
25
5
  }
26
6
  exports.ConnectionService = ConnectionService;
@@ -1,10 +1,10 @@
1
1
  import { IDeviceService } from "../interfaces";
2
2
  import { IConnection } from "../types";
3
- export declare class DeviceService implements IDeviceService {
4
- getDevices(connection: IConnection): Promise<Record<string, any>[]>;
5
- getDevice(connectionId: string, deviceId: string): Promise<any>;
6
- getStatus(connectionId: string, deviceId: string): Promise<string | null>;
7
- getState(deviceId: string): Promise<Record<string, any>>;
8
- getGateways(connectionId: string): Promise<any[] | null>;
9
- getGatewayDetails(connectionId: string, gatewayId: string): Promise<Record<string, any>>;
3
+ export declare abstract class DeviceService implements IDeviceService {
4
+ abstract getDevices(connection: IConnection): Promise<Record<string, any>[]>;
5
+ abstract getDevice(connectionId: string, deviceId: string): Promise<any>;
6
+ abstract getStatus(connectionId: string, deviceId: string): Promise<string | null>;
7
+ abstract getState(deviceId: string): Promise<Record<string, any>>;
8
+ abstract getGateways(connectionId: string): Promise<any[] | null>;
9
+ abstract getGatewayDetails(connectionId: string, gatewayId: string): Promise<Record<string, any>>;
10
10
  }
@@ -2,29 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeviceService = void 0;
4
4
  class DeviceService {
5
- async getDevices(connection) {
6
- // Implementation will be provided by the consuming project
7
- throw new Error("getDevices method not implemented");
8
- }
9
- async getDevice(connectionId, deviceId) {
10
- // Implementation will be provided by the consuming project
11
- throw new Error("getDevice method not implemented");
12
- }
13
- async getStatus(connectionId, deviceId) {
14
- // Implementation will be provided by the consuming project
15
- throw new Error("getDeviceStatus method not implemented");
16
- }
17
- async getState(deviceId) {
18
- // Implementation will be provided by the consuming project
19
- throw new Error("getState method not implemented");
20
- }
21
- async getGateways(connectionId) {
22
- // Implementation will be provided by the consuming project
23
- throw new Error("getGateways method not implemented");
24
- }
25
- async getGatewayDetails(connectionId, gatewayId) {
26
- // Implementation will be provided by the consuming project
27
- throw new Error("getGatewayDetails method not implemented");
28
- }
29
5
  }
30
6
  exports.DeviceService = DeviceService;
@@ -1,3 +1,3 @@
1
- export declare class DeviceHubService {
2
- getHubs(): Promise<any>;
1
+ export declare abstract class DeviceHubService {
2
+ abstract getHubs(): Promise<any>;
3
3
  }
@@ -2,9 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeviceHubService = void 0;
4
4
  class DeviceHubService {
5
- async getHubs() {
6
- // implements will be provided by the consuming project
7
- throw new Error("getHubs method not implemented");
8
- }
9
5
  }
10
6
  exports.DeviceHubService = DeviceHubService;
@@ -3,5 +3,6 @@ export type DeviceConfig = {
3
3
  OPERATIONAL_SERVICE: string;
4
4
  DEVICE_SERVICE: string;
5
5
  MONITORING_SERVICE: string;
6
+ ENERGY_SERVICE: string;
6
7
  [key: string]: string;
7
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -9,6 +9,7 @@ export function initialize(cfg: DeviceConfig) {
9
9
  "OPERATIONAL_SERVICE",
10
10
  "DEVICE_SERVICE",
11
11
  "MONITORING_SERVICE",
12
+ "ENERGY_SERVICE",
12
13
  ].some((key) => Boolean(cfg[key]));
13
14
 
14
15
  if (!hasAtLeastOneService) {
@@ -1,35 +1,28 @@
1
1
  // Device Cloud Service - Class Implementation
2
2
  import { IDeviceConnectionService } from "../interfaces";
3
- import { IConnection, IDevice, IDeviceAccountResponse } from "../types";
3
+ import {
4
+ IConnection,
5
+ IDevice,
6
+ IDeviceAccountResponse,
7
+ IConnectionConnectParams,
8
+ } from "../types";
4
9
 
5
- export class ConnectionService implements IDeviceConnectionService {
6
- async createConnection(data: IConnection, userId: string) {
7
- // Implementation will be provided by the consuming project
8
- throw new Error("createConnection method not implemented");
9
- }
10
+ export abstract class ConnectionService implements IDeviceConnectionService {
11
+ abstract createConnection(data: IConnection, userId: string): Promise<any>;
10
12
 
11
- async getDeviceAccount(
13
+ abstract getDeviceAccount(
12
14
  connection: IConnection
13
- ): Promise<IDeviceAccountResponse> {
14
- // Implementation will be provided by the consuming project
15
- throw new Error("getDeviceAccount method not implemented");
16
- }
15
+ ): Promise<IDeviceAccountResponse>;
17
16
 
18
- async getDevices(connection: IConnection): Promise<IDevice[]> {
19
- // Implementation will be provided by the consuming project
20
- throw new Error("getDevices method not implemented");
21
- }
17
+ abstract getDevices(connection: IConnection): Promise<IDevice[]>;
22
18
 
23
- async filterDevices(
19
+ abstract filterDevices(
24
20
  connection: IConnection,
25
21
  devices: Record<string, any>[]
26
- ): Promise<IDevice[]> {
27
- // Implementation will be provided by the consuming project
28
- throw new Error("filterDevices method not implemented");
29
- }
22
+ ): Promise<IDevice[]>;
30
23
 
31
- async connect(connection: IConnection) {
32
- // Implementation will be provided by the consuming project
33
- throw new Error("connect method not implemented");
34
- }
24
+ abstract connect(
25
+ connection: IConnection,
26
+ connectionConnect: IConnectionConnectParams
27
+ ): Promise<any>;
35
28
  }
@@ -1,40 +1,17 @@
1
1
  import { IDeviceService } from "../interfaces";
2
2
  import { IConnection } from "../types";
3
3
 
4
- export class DeviceService implements IDeviceService {
5
- async getDevices(connection: IConnection): Promise<Record<string, any>[]> {
6
- // Implementation will be provided by the consuming project
7
- throw new Error("getDevices method not implemented");
8
- }
9
-
10
- async getDevice(connectionId: string, deviceId: string): Promise<any> {
11
- // Implementation will be provided by the consuming project
12
- throw new Error("getDevice method not implemented");
13
- }
14
-
15
- async getStatus(
4
+ export abstract class DeviceService implements IDeviceService {
5
+ abstract getDevices(connection: IConnection): Promise<Record<string, any>[]>;
6
+ abstract getDevice(connectionId: string, deviceId: string): Promise<any>;
7
+ abstract getStatus(
16
8
  connectionId: string,
17
9
  deviceId: string
18
- ): Promise<string | null> {
19
- // Implementation will be provided by the consuming project
20
- throw new Error("getDeviceStatus method not implemented");
21
- }
22
-
23
- async getState(deviceId: string): Promise<Record<string, any>> {
24
- // Implementation will be provided by the consuming project
25
- throw new Error("getState method not implemented");
26
- }
27
-
28
- async getGateways(connectionId: string): Promise<any[] | null> {
29
- // Implementation will be provided by the consuming project
30
- throw new Error("getGateways method not implemented");
31
- }
32
-
33
- async getGatewayDetails(
10
+ ): Promise<string | null>;
11
+ abstract getState(deviceId: string): Promise<Record<string, any>>;
12
+ abstract getGateways(connectionId: string): Promise<any[] | null>;
13
+ abstract getGatewayDetails(
34
14
  connectionId: string,
35
15
  gatewayId: string
36
- ): Promise<Record<string, any>> {
37
- // Implementation will be provided by the consuming project
38
- throw new Error("getGatewayDetails method not implemented");
39
- }
16
+ ): Promise<Record<string, any>>;
40
17
  }
@@ -1,6 +1,3 @@
1
- export class DeviceHubService {
2
- async getHubs(): Promise<any> {
3
- // implements will be provided by the consuming project
4
- throw new Error("getHubs method not implemented");
5
- }
1
+ export abstract class DeviceHubService {
2
+ abstract getHubs(): Promise<any>;
6
3
  }
@@ -3,5 +3,6 @@ export type DeviceConfig = {
3
3
  OPERATIONAL_SERVICE: string;
4
4
  DEVICE_SERVICE: string;
5
5
  MONITORING_SERVICE: string;
6
+ ENERGY_SERVICE: string;
6
7
  [key: string]: string;
7
8
  };