Skip to content

Commit 6437490

Browse files
committed
Format all files
1 parent 411a0d2 commit 6437490

File tree

10 files changed

+195
-173
lines changed

10 files changed

+195
-173
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.test.js
2+
*.test.tsx
3+
dist

.eslintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"extends": ["plugin:@typescript-eslint/recommended", "prettier"],
4+
"parserOptions": {
5+
"sourceType": "module"
6+
},
7+
"rules": {
8+
"prettier/prettier": "error"
9+
},
10+
"plugins": ["@typescript-eslint", "prettier"]
11+
}

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"arrowParens": "always",
6+
"printWidth": 132
7+
}

package.json

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
{
2-
"name": "@modbus2mqtt/server.shared",
3-
"version": "0.10.0",
4-
"type": "module",
5-
"description": "Interfaces and functions shared with server and angular ui",
6-
"keywords": [
7-
"modbus2mqtt"
8-
],
9-
"bugs": "https://github.com/modbus2mqtt/server/issues",
10-
"main": "cjs/index.js",
11-
"types": "cjs/index.d.ts",
12-
"author": "Volkmar Nissen <[email protected]>",
13-
"license": "MIT",
14-
"repository": {
15-
"type": "git",
16-
"url": "https://github.com/modbus2mqtt/server.shared"
17-
},
18-
"scripts": {
19-
"build.cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > cjs/package.json",
20-
"build.esm": "tsc --build tsconfig.json && echo '{\"type\": \"module\"}' > esm/package.json",
21-
"build": "npm run build.cjs && npm run build.esm"
22-
},
23-
"exports": {
24-
"require": "./cjs/index.js",
25-
"import": "./esm/index.js"
26-
},
27-
"devDependencies": {
28-
"tslib": "^2.6.3",
29-
"typescript": "^5.4.5"
30-
},
31-
"dependencies": {
2+
"name": "@modbus2mqtt/server.shared",
3+
"version": "0.10.0",
4+
"type": "module",
5+
"description": "Interfaces and functions shared with server and angular ui",
6+
"keywords": [
7+
"modbus2mqtt"
8+
],
9+
"bugs": "https://github.com/modbus2mqtt/server/issues",
10+
"main": "cjs/index.js",
11+
"types": "cjs/index.d.ts",
12+
"author": "Volkmar Nissen <[email protected]>",
13+
"license": "MIT",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/modbus2mqtt/server.shared"
17+
},
18+
"scripts": {
19+
"build.cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > cjs/package.json",
20+
"build.esm": "tsc --build tsconfig.json && echo '{\"type\": \"module\"}' > esm/package.json",
21+
"build": "npm run build.cjs && npm run build.esm",
22+
"pretty": "prettier --write \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json}\""
23+
},
24+
"exports": {
25+
"require": "./cjs/index.js",
26+
"import": "./esm/index.js"
27+
},
28+
"devDependencies": {
29+
"prettier": "^3.3.3",
30+
"tslib": "^2.6.3",
31+
"typescript": "^5.4.5"
32+
},
33+
"dependencies": {
3234
"@modbus2mqtt/specification.shared": "^0.8.0",
33-
"mqtt": "^5.7.1"
34-
}
35+
"mqtt": "^5.7.1"
36+
}
3537
}

src/Bus.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { IBus, IRTUConnection, ITCPConnection } from "./types";
1+
import { IBus, IRTUConnection, ITCPConnection } from './types'
22

33
export function getBusName(bus: IBus): string {
4-
let serialport = (bus.connectionData as IRTUConnection).serialport
5-
if (serialport)
6-
return serialport
7-
let tcpname = (bus.connectionData as ITCPConnection).host + ":" + (bus.connectionData as ITCPConnection).port
8-
return tcpname
9-
}
4+
let serialport = (bus.connectionData as IRTUConnection).serialport
5+
if (serialport) return serialport
6+
let tcpname = (bus.connectionData as ITCPConnection).host + ':' + (bus.connectionData as ITCPConnection).port
7+
return tcpname
8+
}

src/httpConstants.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
export const enum apiUri {
2-
modbusSpecification = '/api/modbus/specification',
3-
specsForSlaveId = '/api/specsForSlaveId',
4-
specifications = '/api/specifications',
5-
specfication = '/api/specification',
6-
specficationContribute = '/api/specification/contribute',
7-
specificationValidate = '/api/specification/validate',
8-
modbusEntity = '/api/modbus/entity',
9-
specificationFetchPublic = '/api/specification/fetchpublic',
10-
upload = "/api/upload",
11-
userAuthenticationStatus = '/userAuthenticationStatus',
12-
userLogin = '/user/login',
13-
converters = '/api/converters',
14-
userRegister = '/user/register',
15-
sslFiles = '/api/sslfiles',
16-
busses = '/api/busses',
17-
bus = '/api/bus',
18-
slaves = '/api/slaves',
19-
slave = '/api/slave',
20-
configuration = '/api/configuration',
21-
translate = '/api/translate',
22-
validateMqtt = '/api/validate/mqtt',
23-
writeEntity = '/api/modbus/write/entity',
24-
serialDevices = '/api/serial/devices',
25-
addFilesUrl = "/api/addFilesUrl",
26-
newSpecificationfiles = "/api/newSpecificationfiles"
27-
}
2+
modbusSpecification = '/api/modbus/specification',
3+
specsForSlaveId = '/api/specsForSlaveId',
4+
specifications = '/api/specifications',
5+
specfication = '/api/specification',
6+
specficationContribute = '/api/specification/contribute',
7+
specificationValidate = '/api/specification/validate',
8+
modbusEntity = '/api/modbus/entity',
9+
specificationFetchPublic = '/api/specification/fetchpublic',
10+
upload = '/api/upload',
11+
userAuthenticationStatus = '/userAuthenticationStatus',
12+
userLogin = '/user/login',
13+
converters = '/api/converters',
14+
userRegister = '/user/register',
15+
sslFiles = '/api/sslfiles',
16+
busses = '/api/busses',
17+
bus = '/api/bus',
18+
slaves = '/api/slaves',
19+
slave = '/api/slave',
20+
configuration = '/api/configuration',
21+
translate = '/api/translate',
22+
validateMqtt = '/api/validate/mqtt',
23+
writeEntity = '/api/modbus/write/entity',
24+
serialDevices = '/api/serial/devices',
25+
addFilesUrl = '/api/addFilesUrl',
26+
newSpecificationfiles = '/api/newSpecificationfiles',
27+
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './types'
22
export * from './httpConstants'
3-
export * from './Bus'
3+
export * from './Bus'

src/types.ts

Lines changed: 93 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,123 @@
1-
2-
import { IClientOptions } from 'mqtt';
3-
import { ISpecificationTexts, IbaseSpecification, IdentifiedStates, IimageAndDocumentUrl, ImodbusEntityIdentification, SpecificationStatus } from '@modbus2mqtt/specification.shared';
1+
import { IClientOptions } from 'mqtt'
2+
import {
3+
ISpecificationTexts,
4+
IbaseSpecification,
5+
IdentifiedStates,
6+
IimageAndDocumentUrl,
7+
ImodbusEntityIdentification,
8+
SpecificationStatus,
9+
} from '@modbus2mqtt/specification.shared'
410

511
export enum HttpErrorsEnum {
6-
OK = 200,
7-
OkCreated = 201,
8-
OkAccepted = 202,
9-
OkNonAuthoritativeInformation = 203,
10-
OkNoContent = 204,
11-
ErrBadRequest = 400,
12-
ErrUnauthorized = 401,
13-
ErrForbidden = 403,
14-
ErrNotFound = 404,
15-
ErrNotAcceptable = 406,
16-
ErrRequestTimeout = 408,
17-
ErrInvalidParameter = 422,
18-
SrvErrInternalServerError = 500
12+
OK = 200,
13+
OkCreated = 201,
14+
OkAccepted = 202,
15+
OkNonAuthoritativeInformation = 203,
16+
OkNoContent = 204,
17+
ErrBadRequest = 400,
18+
ErrUnauthorized = 401,
19+
ErrForbidden = 403,
20+
ErrNotFound = 404,
21+
ErrNotAcceptable = 406,
22+
ErrRequestTimeout = 408,
23+
ErrInvalidParameter = 422,
24+
SrvErrInternalServerError = 500,
1925
}
2026
export enum RoutingNames {
21-
login = 'login',
22-
register = 'register',
23-
configure = 'configure',
24-
busses = 'busses',
25-
specifications = 'specifications',
26-
slaves = 'slaves',
27-
specification = 'specification'
27+
login = 'login',
28+
register = 'register',
29+
configure = 'configure',
30+
busses = 'busses',
31+
specifications = 'specifications',
32+
slaves = 'slaves',
33+
specification = 'specification',
2834
}
2935
export interface ImqttClient extends IClientOptions {
30-
mqttserverurl?: string,
31-
ssl?: boolean
36+
mqttserverurl?: string
37+
ssl?: boolean
3238
}
3339

3440
export interface IRTUConnection {
35-
serialport: string,
36-
baudrate: number,
37-
timeout: number
41+
serialport: string
42+
baudrate: number
43+
timeout: number
3844
}
3945
export interface ITCPConnection {
40-
host: string,
41-
port: number,
42-
timeout: number
46+
host: string
47+
port: number
48+
timeout: number
4349
}
4450

45-
export type IModbusConnection = (IRTUConnection | ITCPConnection);
51+
export type IModbusConnection = IRTUConnection | ITCPConnection
4652

4753
export interface Iconfiguration {
48-
hassiotoken?: string;
49-
password?: string;
50-
username?: string;
51-
githubPersonalToken?: string;
52-
version: string,
53-
fakeModbus: boolean;
54-
mqttbasetopic: string;
55-
mqttdiscoveryprefix: string;
56-
mqttdiscoverylanguage: string;
57-
mqttusehassiotoken?: boolean;
58-
mqttconnect: ImqttClient;
59-
mqttcaFile?: string;
60-
mqttkeyFile?: string;
61-
mqttcertFile?: string;
62-
filelocation: string;
63-
httpport: number;
64-
rootUrl?: string;
54+
hassiotoken?: string
55+
password?: string
56+
username?: string
57+
githubPersonalToken?: string
58+
version: string
59+
fakeModbus: boolean
60+
mqttbasetopic: string
61+
mqttdiscoveryprefix: string
62+
mqttdiscoverylanguage: string
63+
mqttusehassiotoken?: boolean
64+
mqttconnect: ImqttClient
65+
mqttcaFile?: string
66+
mqttkeyFile?: string
67+
mqttcertFile?: string
68+
filelocation: string
69+
httpport: number
70+
rootUrl?: string
6571
}
6672
export enum AuthenticationErrors {
67-
EnvironmentVariableSecretNotSet = 1,
68-
HashError = 2,
69-
InvalidUserPasswordCombination = 3,
70-
InvalidParameters = 4,
71-
SignError = 5
73+
EnvironmentVariableSecretNotSet = 1,
74+
HashError = 2,
75+
InvalidUserPasswordCombination = 3,
76+
InvalidParameters = 4,
77+
SignError = 5,
7278
}
7379

7480
export interface IUserAuthenticationStatus {
75-
registered: boolean,
76-
hassiotoken: boolean,
77-
hasAuthToken: boolean,
78-
authTokenExpired: boolean,
79-
mqttConfigured: boolean,
80-
preSelectedBusId?: number
81+
registered: boolean
82+
hassiotoken: boolean
83+
hasAuthToken: boolean
84+
authTokenExpired: boolean
85+
mqttConfigured: boolean
86+
preSelectedBusId?: number
8187
}
8288
export interface IBus {
83-
busId: number,
84-
connectionData: IModbusConnection,
85-
slaves: Islave[]
89+
busId: number
90+
connectionData: IModbusConnection
91+
slaves: Islave[]
8692
}
8793
export function getConnectionName(connection: IModbusConnection): string {
88-
if ((connection as IRTUConnection).baudrate) {
89-
let c = (connection as IRTUConnection);
90-
return "RTU: " + c.serialport + "(" + c.baudrate + ") t: " + c.timeout;
91-
}
92-
else {
93-
let c = (connection as ITCPConnection);
94-
return "TCP: " + c.host + ":" + c.port + " t: " + (c.timeout ? c.timeout : 100);
95-
}
94+
if ((connection as IRTUConnection).baudrate) {
95+
let c = connection as IRTUConnection
96+
return 'RTU: ' + c.serialport + '(' + c.baudrate + ') t: ' + c.timeout
97+
} else {
98+
let c = connection as ITCPConnection
99+
return 'TCP: ' + c.host + ':' + c.port + ' t: ' + (c.timeout ? c.timeout : 100)
100+
}
96101
}
97102

98103
export interface Islave {
99-
slaveid: number;
100-
specificationid?: string;
101-
name?: string;
102-
polInterval?: number;
103-
specification?: IbaseSpecification;
104-
durationOfLongestModbusCall?: number;
105-
modbusTimout?: number;
106-
evalTimeout?: boolean;
107-
detectSpec?: boolean; // Will be set when creating a slave. If true, modbus2mqtt will set a specification matching to the modbusdata if there is one
104+
slaveid: number
105+
specificationid?: string
106+
name?: string
107+
polInterval?: number
108+
specification?: IbaseSpecification
109+
durationOfLongestModbusCall?: number
110+
modbusTimout?: number
111+
evalTimeout?: boolean
112+
detectSpec?: boolean // Will be set when creating a slave. If true, modbus2mqtt will set a specification matching to the modbusdata if there is one
108113
}
109114

110115
export interface IidentificationSpecification {
111-
filename: string;
112-
status: SpecificationStatus;
113-
entities: ImodbusEntityIdentification[];
114-
files: IimageAndDocumentUrl[];
115-
i18n: ISpecificationTexts[];
116-
identified: IdentifiedStates;
117-
configuredSlave?: Islave;
118-
}
116+
filename: string
117+
status: SpecificationStatus
118+
entities: ImodbusEntityIdentification[]
119+
files: IimageAndDocumentUrl[]
120+
i18n: ISpecificationTexts[]
121+
identified: IdentifiedStates
122+
configuredSlave?: Islave
123+
}

0 commit comments

Comments
 (0)