@owvision/station-interface-ts 0.0.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/src/index.ts ADDED
@@ -0,0 +1,57 @@
1
+ import * as grpc from "@grpc/grpc-js";
2
+ import {
3
+ GetSensorStateRequest,
4
+ GetStationDefinitionRequest,
5
+ SensorState,
6
+ StationDefinition,
7
+ StationInterfaceService,
8
+ type StationInterfaceServer,
9
+ } from "./generated/recorder.js";
10
+ export * from "./generated/recorder.js";
11
+
12
+ interface StationInterface {
13
+ /** Should read a value from the passed sensor. */
14
+ getSensorState(request: GetSensorStateRequest): Promise<SensorState>;
15
+
16
+ /** Should return a station definition (name, position, sensors, ...). */
17
+ getStationDefinition(
18
+ request: GetStationDefinitionRequest
19
+ ): Promise<StationDefinition>;
20
+ }
21
+
22
+ /** Starts the station interface (by default on grpc port `50051`). */
23
+ export function startInterface(
24
+ stationInterface: StationInterface,
25
+ port = 50051
26
+ ) {
27
+ const server = new grpc.Server();
28
+
29
+ const grpcService: StationInterfaceServer = {
30
+ async getSensorState(call, callback) {
31
+ const sensorState = await stationInterface.getSensorState(
32
+ call.request
33
+ );
34
+ callback(null, sensorState);
35
+ },
36
+ async getStationDefinition(call, callback) {
37
+ const stationDefinition =
38
+ await stationInterface.getStationDefinition(call.request);
39
+ callback(null, stationDefinition);
40
+ },
41
+ };
42
+
43
+ server.addService(StationInterfaceService, grpcService);
44
+
45
+ return new Promise<void>((res, rej) => {
46
+ server.bindAsync(
47
+ `127.0.0.1:${port}`,
48
+ grpc.ServerCredentials.createInsecure(),
49
+ (error, port) => {
50
+ if (error) {
51
+ rej(error);
52
+ }
53
+ res();
54
+ }
55
+ );
56
+ });
57
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ // File Layout
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+
8
+ // Environment Settings
9
+ // See also https://aka.ms/tsconfig/module
10
+ "module": "nodenext",
11
+ "target": "esnext",
12
+ "types": [],
13
+ // For nodejs:
14
+ // "lib": ["esnext"],
15
+ // "types": ["node"],
16
+ // and npm install -D @types/node
17
+
18
+ // Other Outputs
19
+ "sourceMap": true,
20
+ "declaration": true,
21
+ "declarationMap": true,
22
+
23
+ // Stricter Typechecking Options
24
+ "noUncheckedIndexedAccess": true,
25
+ "exactOptionalPropertyTypes": true,
26
+
27
+ // Style Options
28
+ // "noImplicitReturns": true,
29
+ // "noImplicitOverride": true,
30
+ // "noUnusedLocals": true,
31
+ // "noUnusedParameters": true,
32
+ // "noFallthroughCasesInSwitch": true,
33
+ // "noPropertyAccessFromIndexSignature": true,
34
+
35
+ // Recommended Options
36
+ "strict": true,
37
+ "jsx": "react-jsx",
38
+ "verbatimModuleSyntax": true,
39
+ "isolatedModules": true,
40
+ "noUncheckedSideEffectImports": true,
41
+ "moduleDetection": "force",
42
+ "skipLibCheck": true
43
+ }
44
+ }