From 8b52ffd51b5deabd74792ce644552aa4251d9340 Mon Sep 17 00:00:00 2001 From: Daniel Kluge Date: Mon, 30 Oct 2023 14:31:32 +0100 Subject: [PATCH] Small cleanup --- lib/src/example_modules/httpInterfaceServer.ts | 8 ++------ lib/src/example_modules/mqttConnector.ts | 13 ++++++------- lib/src/interfaceConnectionObject.ts | 9 ++++----- lib/src/multimessageBroker.ts | 6 ++---- lib/src/parser/AIMCMapper.ts | 2 +- lib/src/server.ts | 16 ++++++---------- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/lib/src/example_modules/httpInterfaceServer.ts b/lib/src/example_modules/httpInterfaceServer.ts index e63f4e2..62fcd27 100644 --- a/lib/src/example_modules/httpInterfaceServer.ts +++ b/lib/src/example_modules/httpInterfaceServer.ts @@ -11,17 +11,13 @@ export type Config = { } export default class HTTPInterfaceServer extends AASInterfaceServer { - protected name: string = "HTTPInterfaceServer"; - protected supportsSubscriptions: boolean = false; // TODO, longpolling? + public readonly name: string = "HTTPInterfaceServer"; + public readonly supportsSubscriptions: boolean = false; // TODO, longpolling? private app: Express = express(); private server: any = null; private observers: any[] = []; - public constructor(config: Config, aas: types.Environment, onRequestCallback: OnRequestCallback) { - super(config, aas, onRequestCallback); - } - public prepare(): void { this.app.use(express.json()); this.createRoutes(); diff --git a/lib/src/example_modules/mqttConnector.ts b/lib/src/example_modules/mqttConnector.ts index 2a41cab..5c50997 100644 --- a/lib/src/example_modules/mqttConnector.ts +++ b/lib/src/example_modules/mqttConnector.ts @@ -1,17 +1,16 @@ import * as mqtt from "mqtt"; -import type { Property, Operation, OperationVariable, BasicEventElement } from "@aas-core-works/aas-core3.0-typescript/dist/types/types"; import InterfaceConnectionObject from "interfaceConnectionObject"; import type { types } from "@aas-core-works/aas-core3.0-typescript"; export default class MQTTConnector extends InterfaceConnectionObject { - public name: string = "MQTT Connector"; - public uriProtocol: string[] = ["mqtt", "mqtts"]; - public connectionType: "ON_DEMAND" | "PERMANENT" = "PERMANENT"; - public supportsSubscriptions: boolean = true; + public readonly name: string = "MQTT Connector"; + public readonly uriProtocol: string[] = ["mqtt", "mqtts"]; + public readonly connectionType: "ON_DEMAND" | "PERMANENT" = "PERMANENT"; + public readonly supportsSubscriptions: boolean = true; private client: mqtt.MqttClient|null = null; - private messageStore: Record = {}; + private readonly messageStore: Record = {}; public connect(): boolean { if (!this.client) this.client = mqtt.connect(this.endpointMetadata.base, this.connectionParameter); @@ -93,7 +92,7 @@ export default class MQTTConnector extends InterfaceConnectionObject void): boolean { + public subscribeEvent(event: types.BasicEventElement, callback: (event: types.BasicEventElement) => void): boolean { // TODO // Vorher mal ne ordentliche Mapping-Definition diff --git a/lib/src/interfaceConnectionObject.ts b/lib/src/interfaceConnectionObject.ts index 57d615d..ba701c3 100644 --- a/lib/src/interfaceConnectionObject.ts +++ b/lib/src/interfaceConnectionObject.ts @@ -1,8 +1,7 @@ import type { types } from "@aas-core-works/aas-core3.0-typescript"; -import { AIMCMapper } from "parser/AIMCMapper"; +import AIMCMapper from "./parser/AIMCMapper"; import { v4 } from "uuid"; import type { EndpointMetadata } from "types/aidConf"; -import { Request } from "types/requests"; type ConnectionType = "ON_DEMAND" | "PERMANENT"; @@ -14,9 +13,9 @@ export default abstract class InterfaceConnectionObject { public abstract readonly connectionType: ConnectionType; public abstract readonly supportsSubscriptions: boolean; - protected observerStore: Record void)[]> = {}; - protected eventSubStore: Record void)[]> = {}; - protected asyncActionStateStore: Record = {}; + protected readonly observerStore: Record void)[]> = {}; + protected readonly eventSubStore: Record void)[]> = {}; + protected readonly asyncActionStateStore: Record = {}; public constructor( protected readonly connectionParameter: ConfigInterface, diff --git a/lib/src/multimessageBroker.ts b/lib/src/multimessageBroker.ts index 826f9a6..a522d68 100644 --- a/lib/src/multimessageBroker.ts +++ b/lib/src/multimessageBroker.ts @@ -1,10 +1,8 @@ import { types } from "@aas-core-works/aas-core3.0-typescript"; -import type AASInterfaceServer from "server"; +import type AASInterfaceServer from "./server"; import type { Request } from "types/requests"; import type InterfaceConnectionObject from "interfaceConnectionObject"; -import Traverser from "./helper/traverser"; -import { AIMCMapper } from "./parser/AIMCMapper"; -import { AssetInterfacesDescription } from "types/aidConf"; +import AIMCMapper from "./parser/AIMCMapper"; import AIDParser from "./parser/AIDParser"; type AASRegistration = { diff --git a/lib/src/parser/AIMCMapper.ts b/lib/src/parser/AIMCMapper.ts index 452f716..05b4133 100644 --- a/lib/src/parser/AIMCMapper.ts +++ b/lib/src/parser/AIMCMapper.ts @@ -5,7 +5,7 @@ import Traverser from "helper/traverser"; import AIDParser from "./AIDParser"; import { SubmodelElementCollection } from "@aas-core-works/aas-core3.0-typescript/dist/types/types"; -export class AIMCMapper { +export default class AIMCMapper { private map: AIMCMap = new Map(); diff --git a/lib/src/server.ts b/lib/src/server.ts index dafb0fc..bea0051 100644 --- a/lib/src/server.ts +++ b/lib/src/server.ts @@ -2,17 +2,13 @@ import { types } from "@aas-core-works/aas-core3.0-typescript"; import type { Request, OnRequestCallback } from "types/requests"; export default abstract class AASInterfaceServer { - protected abstract readonly name: string; - protected config: ConfigInterface; - protected abstract readonly supportsSubscriptions: boolean; - protected readonly aas: types.Environment; - protected onRequestCallback: OnRequestCallback + public abstract readonly name: string; + public abstract readonly supportsSubscriptions: boolean; - constructor(config: ConfigInterface, aas: types.Environment, onRequestCallback: OnRequestCallback) { - this.config = config; - this.aas = aas; - this.onRequestCallback = onRequestCallback; - } + constructor( + protected readonly config: ConfigInterface, + protected readonly aas: types.Environment, + protected readonly onRequestCallback: OnRequestCallback) {} public abstract prepare(): void; public abstract run(): void;