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 +59 -0
- package/dist/config/config.js +1 -0
- package/dist/device/cloud/services/Connection.service.d.ts +7 -7
- package/dist/device/cloud/services/Connection.service.js +0 -20
- package/dist/device/cloud/services/Device.service.d.ts +7 -7
- package/dist/device/cloud/services/Device.service.js +0 -24
- package/dist/device/cloud/services/DeviceHub.service.d.ts +2 -2
- package/dist/device/cloud/services/DeviceHub.service.js +0 -4
- package/dist/types/config.types.d.ts +1 -0
- package/package.json +1 -1
- package/src/config/config.ts +1 -0
- package/src/device/cloud/services/Connection.service.ts +17 -24
- package/src/device/cloud/services/Device.service.ts +9 -32
- package/src/device/cloud/services/DeviceHub.service.ts +2 -5
- package/src/types/config.types.ts +1 -0
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
|
package/dist/config/config.js
CHANGED
|
@@ -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<
|
|
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<
|
|
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;
|
package/package.json
CHANGED
package/src/config/config.ts
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
// Device Cloud Service - Class Implementation
|
|
2
2
|
import { IDeviceConnectionService } from "../interfaces";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
IConnection,
|
|
5
|
+
IDevice,
|
|
6
|
+
IDeviceAccountResponse,
|
|
7
|
+
IConnectionConnectParams,
|
|
8
|
+
} from "../types";
|
|
4
9
|
|
|
5
|
-
export class ConnectionService implements IDeviceConnectionService {
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
|
}
|