Files
diplomarbeit-code/lib/src/server.ts
T

72 lines
1.9 KiB
TypeScript

import { types } from "@aas-core-works/aas-core3.0-typescript";
import type { OnRequestCallback } from "./types/requests";
/**
* Abstract class for an interface server.
* This should be used as base class for your own interface servers!
*
* @typeParam ConfigInterface - The config interface for your interface server.
* @public
*/
export default abstract class AASInterfaceServer<ConfigInterface> {
/**
* A name for your interface server.
* @remarks
* Currently unused
* @public
* @readonly
* @virtual
*/
public static readonly serverInterfaceName: string;
/**
* Whether your interface server supports subscriptions.
* @remarks
* Currently unused
* @public
* @readonly
* @virtual
*/
public static readonly supportsSubscriptions: boolean;
/**
* Crate the interface server.
* @param config Interface server config
* @param aas AAS Environment for the server
* @param onRequestCallback Callback when a request is received and parsed
* @public
* @sealed
*/
public constructor(
protected readonly config: ConfigInterface,
protected readonly aas: types.Environment,
protected readonly onRequestCallback: OnRequestCallback) {}
/**
* Prepare the interface server.
* @remarks
* Here you can create routes, listeners, callbacks,...
* @virtual
* @public
*/
public abstract prepare(): void;
/**
* Run the interface server.
* @public
* @virtual
*/
public abstract run(): void;
/**
* Stop the interface server.
* @public
* @virtual
*/
public abstract stop(): void;
/**
* Notify observers/subscribers about an event.
* @param event Event to notify the interface server about
* @public
* @virtual
*/
public abstract notify(event: any): void;
}