Documentation should be done

This commit is contained in:
Daniel Kluge
2023-11-02 18:29:04 +01:00
parent 591cf6662b
commit 819a0b1a72
21 changed files with 571 additions and 29 deletions
+13 -6
View File
@@ -1,25 +1,27 @@
import { types } from "@aas-core-works/aas-core3.0-typescript";
import { ConnectionConfiguration, AIMCMap } from "./types/aimcConf";
import type { types } from "@aas-core-works/aas-core3.0-typescript";
import type { ConnectionConfiguration, AIMCMap } from "./types/aimcConf";
import AIMCParser from "./parser/AIMCParser";
import Traverser from "./helper/traverser";
import AIDParser from "./parser/AIDParser";
import { SubmodelElementCollection } from "@aas-core-works/aas-core3.0-typescript/dist/types/types";
/**
* The AIMC Mapper.
* @remarks
* This class is used to map properties t endpoints.
* This class is used to map properties to endpoints.
* @public
*/
export default class AIMCMapper {
/**
* The map.
* @private
*/
private map: AIMCMap = new Map();
/**
* Creates the mapper.
* @param env The AAS Environment
* @public
*/
public constructor(private readonly env: types.Environment) {
this.generate();
@@ -27,6 +29,7 @@ export default class AIMCMapper {
/**
* Generates the map from the AAS Environment.
* @private
*/
private generate(): void {
const aimc = AIMCParser.parse(this.env);
@@ -48,11 +51,11 @@ export default class AIMCMapper {
let {first, second} = resolved;
let parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as SubmodelElementCollection);
let parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as types.SubmodelElementCollection);
if (parsedPropConf === null) {
// maybe the property is in the first element
[first, second] = [second, first];
parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as SubmodelElementCollection);
parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as types.SubmodelElementCollection);
}
if (parsedPropConf === null) continue;
@@ -69,6 +72,7 @@ export default class AIMCMapper {
/**
*
* @returns The complete map
* @public
*/
public getMap(): AIMCMap {
return this.map;
@@ -78,6 +82,7 @@ export default class AIMCMapper {
* Get endpoint for a specific Element
* @param element Element
* @returns Endpoint description or undefined if not found
* @public
*/
public get(element: types.Class): ConnectionConfiguration | undefined {
return this.map.get(element);
@@ -88,6 +93,7 @@ export default class AIMCMapper {
* Can return multiple as idShorts are not necessarily unique
* @param idShort idShort of the element
* @returns Endpoints descriptions of elements with that idShort
* @public
*/
public getByIdShort(idShort: string): ConnectionConfiguration[] {
const result = [];
@@ -101,6 +107,7 @@ export default class AIMCMapper {
* Get an element by its endpoint
* @param path Absolute endpoint path
* @returns Elements that use that path
* @public
*/
public reverseGet(path: string): types.Class[] {
const result = [];
+4
View File
@@ -4,6 +4,7 @@ import { types, jsonization } from "@aas-core-works/aas-core3.0-typescript";
/**
* Helper class to import AAS-Environments from files.
* @public
*/
export default class FileImporter {
@@ -13,6 +14,7 @@ export default class FileImporter {
* @returns Environment
* @throws Error if file is not a JSON file
* @throws Any IO error on file read operation
* @public
*/
public static readAASByPath(path: string): types.Environment {
if (!path.endsWith(".json")) throw new Error("File must be a JSON file");
@@ -30,6 +32,7 @@ export default class FileImporter {
* Import all AAS-Environments from a directory.
* @param path Directory path
* @returns Environments
* @public
*/
public static readAllAASFromPath(path: string): types.Environment[] {
@@ -47,6 +50,7 @@ export default class FileImporter {
* Get all JSON files from a directory.
* @param aasPath Directory path
* @returns Paths of the JSON files
* @private
*/
private static getAllAASFilePaths(aasPath: string): string[] {
const files = readdirSync(aasPath);
+10
View File
@@ -10,6 +10,7 @@ const GLOBALLY_IDENTIFIABLES = [types.KeyTypes.GlobalReference, types.KeyTypes.A
/**
* Helper to traverse the AAS-Environment.
* @public
*/
export default class Traverser {
@@ -18,6 +19,7 @@ export default class Traverser {
* @param environment Environment to search in
* @param id ID
* @returns AAS or null if not found
* @public
*/
public static findAASById(environment: types.Environment, id: string): types.AssetAdministrationShell | null {
if (environment.assetAdministrationShells === null) return null;
@@ -30,6 +32,7 @@ export default class Traverser {
* @param environment Environment to search in
* @param id ID
* @returns Submodel or null if not found
* @public
*/
public static findSMById(environment: types.Environment, id: string): types.Submodel | null {
if (environment.submodels === null) return null;
@@ -42,6 +45,7 @@ export default class Traverser {
* @param environment Environment to search in
* @param id idShort
* @returns Submodel or null if not found
* @public
*/
public static findSMByIdShort(environment: types.Environment, id: string): types.Submodel | null {
if (environment.submodels === null) return null;
@@ -54,6 +58,7 @@ export default class Traverser {
* @param env Environment to search in
* @param ref Reference
* @returns Element or null if not found
* @public
*/
public static resolveReference(env: types.Environment, ref: types.Reference): types.Class | null {
if (ref.type === types.ReferenceTypes.ExternalReference) return null; // Not implemented
@@ -77,6 +82,7 @@ export default class Traverser {
* @param env Environment to search in
* @param relationship Relationship element
* @returns Resolved relationship element or null if not found
* @public
*/
public static resolveRelationship(env: types.Environment, relationship: RelationshipElement): ResolvedRelationshipElement | null {
const first = Traverser.resolveReference(env, relationship.first);
@@ -91,6 +97,7 @@ export default class Traverser {
* @param start Start element
* @param idShorts Array of idShorts to traverse by
* @returns Target element at the end of the path or null if not found
* @public
*/
public static traverseByShortIds(start: types.Class, idShorts: string[]): types.Class | null {
let current: types.Class | null = start;
@@ -109,6 +116,7 @@ export default class Traverser {
* @param submodelOrIdShort Submodel element or Submodel idShort
* @param idShorts idShorts to traverse by
* @returns Target element at the end of the path or null if not found
* @public
*/
public static getElementByIdPath(env: types.Environment, submodelOrIdShort: string | types.Submodel, idShorts: string[]): types.Class | null {
const sm = typeof submodelOrIdShort === "string" ? Traverser.findSMByIdShort(env, submodelOrIdShort) : submodelOrIdShort;
@@ -121,6 +129,7 @@ export default class Traverser {
* @param start Start element
* @param checkFunction Function to find the element. First element which evaluates to true using this function will be returned.
* @returns Element or null if not found
* @public
*/
public static findElement(start: types.Class, checkFunction: (element: types.Class) => boolean): types.Class | null {
for (const element of start.descend()) {
@@ -135,6 +144,7 @@ export default class Traverser {
* @param start Start element
* @param idShort idShort to search for
* @returns Child element or null if not found
* @public
*/
public static findChildByIdShort(start: types.Class, idShort: string): types.Class | null {
for (const child of start.descendOnce()) {
+15 -1
View File
@@ -7,4 +7,18 @@ export * as Types from "./types";
export { Traverser, FileImporter } from "./helper";
export { AIDParser, AIMCParser } from "./parser";
export { jsonization as AASCoreJsonization, types as AASCoreTypes } from "@aas-core-works/aas-core3.0-typescript";
export { jsonization as AASCoreJsonization, types as AASCoreTypes } from "@aas-core-works/aas-core3.0-typescript";
/**
* A modular library for a Multimessagebroker for Industry 4.0 Applications.
* It can be used to create your own modules and run the broker.
*
* @remarks
* This is the library which defines {@link MultiMessageBroker|the logic} used to create {@link AbstractInterfaceServer|server interfaces} to the user (north-bound) following
* the Asset Administration Shell API specification and {@link AbstractConnectionObject|interface connectors} to the asset (south-bound) which
* can be arbitrary but defined in the AssetInterfacesDescription Submodel of the AAS.
* Mappings from the AssetInterfacesMappingConfiguration Submodel of the AAS are used to map specific elements of the AAS
* to dynamic data (using endpoints) of the asset.
*
* @packageDocumentation
*/
+44 -6
View File
@@ -10,42 +10,55 @@ export type OnEventCallback = (response: any) => void
/**
* Abstract class for an connector to an asset.
* This should be used as base class for your own connectors.
* @public
*/
export default abstract class InterfaceConnectionObject<ConfigInterface> {
/**
* A name for your connector.
* @remarks
* Currently not used.
* @public
* @virtual
* @readonly
* @alpha
*/
public static readonly connectorName: string;
/**
* Which protocols are supported by your connector.
* This is really important later so the AAS can decide which connector to use!
* @public
* @virtual
* @readonly
*/
public static readonly uriProtocol: string[]|string;
/**
* The type of connection your connector uses.
* @remarks
* Currently not used.
* @public
* @virtual
* @readonly
* @alpha
*/
public static readonly connectionType: ConnectionType;
/**
* Whether your connector supports subscriptions.
* @remarks
* Currently not used.
* @public
* @virtual
* @readonly
* @alpha
*/
public static readonly supportsSubscriptions: boolean;
/**
* A store for all observers and their callbacks.
* @sealed
*/
protected readonly observerStore: Record<any, ((value: any) => void)[]> = {};
/**
* A store for all event subscriptions and their callbacks.
* @sealed
*/
protected readonly eventSubStore: Record<any, ((value: any) => void)[]> = {};
/**
* A store for all async action handles and their results.
* @sealed
*/
protected readonly asyncActionStateStore: Record<any, {finished: boolean, result: any}> = {};
@@ -55,6 +68,8 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* @param endpointMetadata {@link EndpointMetadata}
* @param mapper {@link AIMCMapper}
* @param onConnectorEvent Callback when an event is received.
* @public
* @sealed
*/
public constructor(
protected readonly connectionParameter: ConfigInterface,
@@ -65,11 +80,15 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
/**
* This should connect the Connector to the asset.
* @returns Whether the connection was successful.
* @public
* @virtual
*/
public abstract connect(): boolean;
/**
* This should disconnect the Connector from the asset (if it even is connected).
* @public
* @virtual
*/
public abstract disconnect(): void;
@@ -77,6 +96,8 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* Read a property value from the asset.
* @param prop Property
* @returns Value of property casted to the type it says it should be.
* @public
* @virtual
*/
public abstract readProperty(prop: types.Property): void;
@@ -84,6 +105,8 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* Write a property value to the asset.
* @param prop Property
* @param value Value to write.
* @public
* @virtual
*/
public abstract writeProperty(prop: types.Property, value: any): void;
@@ -92,6 +115,8 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* @param prop Property
* @param callback Callback to call when the property changes.
* @returns Whether the creation of an observer was successful.
* @public
* @virtual
*/
public abstract observeProperty(prop: types.Property, callback: (value: any) => void): boolean;
@@ -100,6 +125,8 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* @param action Action
* @param args Arguments
* @returns Return value of the action.
* @public
* @virtual
*/
public abstract callActionSync(action: types.Operation, args: Record<string, any>): any;
@@ -108,6 +135,8 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* @param action Action
* @param args Arguments
* @returns Handle for the async action.
* @public
* @virtual
*/
public abstract callActionAsync(action: types.Operation, args: Record<string, any>): string | null;
@@ -115,6 +144,8 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* Read the state of an async action.
* @param handle Handle of the async action.
* @returns Whether the async action is finished.
* @public
* @virtual
*/
public readAsyncActionState(handle: string): boolean {
return this.asyncActionStateStore[handle].finished;
@@ -124,6 +155,8 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* Read the result of an async action.
* @param handle Handle of the async action.
* @returns Result of the async action.
* @public
* @virtual
*/
public readAsyncActionResponse(handle: string): any {
return this.asyncActionStateStore[handle].result;
@@ -134,18 +167,23 @@ export default abstract class InterfaceConnectionObject<ConfigInterface> {
* @param event Event
* @param callback Callback to call when the event occurs.
* @returns Whether the subscription was successful.
* @public
* @virtual
*/
public abstract subscribeEvent(event: types.BasicEventElement, callback: (event: types.BasicEventElement) => void): boolean;
/**
* Unsubscribe from an event.
* @param event Event
* @public
* @virtual
*/
public abstract unsubscribeEvent(event: types.BasicEventElement): void;
/**
* Generate a handle for an async action.
* @returns Handle
* @sealed
*/
protected generateAsyncHandle() {
const handle = v4();
+13
View File
@@ -32,28 +32,40 @@ type InterfaceConnectionEntry<ConfigInterface> = {
* @remarks
* Here are all Interface Servers and Connectors are created and managed.
* Also every request is handled here.
* @public
*/
export default class MultiMessageBroker {
/**
* MMB singleton instance
* @private
*/
private static instance: MultiMessageBroker|null = null;
/**
* Whether the broker is prepared.
* @private
*/
private prepared: boolean = false;
/**
* All registered AASs.
* @private
*/
private aasRegistrations: AASRegistrationPrepared[] = [];
/**
* All registered Interface Connectors.
* @private
*/
private interfaceConnections: InterfaceConnectionEntry<any>[] = [];
/**
* @private
*/
private constructor() {}
/**
* Get the singleton instance of the broker.
* @public
*/
public static getInstance(): MultiMessageBroker {
if (this.instance === null) this.instance = new MultiMessageBroker();
@@ -215,6 +227,7 @@ export default class MultiMessageBroker {
/**
* Callback on a connector event.
* @param response
* @alpha
*/
private onConnectorEvent(response: any) {
for (const aas of this.aasRegistrations) {
+59
View File
@@ -3,8 +3,18 @@ import type { AssetInterfacesDescription, EndpointMetadata, InterfaceDescription
import { AvailableEndpoint, endpointAvailable } from "../types/common";
import Traverser from "../helper/traverser";
/**
* Class for static methods to parse the AssetInterfacesDescription Submodel
* @public
*/
export default class AIDParser {
/**
* Full parsing of the AID Submodel.
* @param env AAS Environment
* @returns Parsed AID or null if it's not parsable
* @public
*/
public static parse(env: aasCore.types.Environment): AssetInterfacesDescription | null {
const sm = Traverser.findSMByIdShort(env, "AssetInterfacesDescription");
if (sm === null || sm.submodelElements === null) return null;
@@ -27,6 +37,12 @@ export default class AIDParser {
return parsed;
}
/**
* Parses one entry of an SubmodelElementList in die AID, containing one endpoint.
* @param entry AID entry for one endpoint
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
* @returns Description for one interface or null if not parsable
*/
private static parseAIDEntry(entry: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): InterfaceDescription | null {
const title = Traverser.findElement(entry, element => (element as any).idShort?.toLocaleLowerCase() === "title");
const titleString = title !== null && aasCore.types.isProperty(title) && title.value ? title.value : "";
@@ -47,6 +63,12 @@ export default class AIDParser {
}
/**
* Parse EndpointMetaData
* @param endpoint EndpointMetaData SubmodelElementCollection
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
* @returns Parsed EndpointMetaData or null if not parsable
*/
public static parseEndpointMetaData(endpoint: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): EndpointMetadata | null {
if (!endpoint.value || endpoint.idShort?.toLocaleLowerCase() !== "endpointmetadata") return null;
@@ -64,6 +86,16 @@ export default class AIDParser {
return parsed;
}
/**
* Parse an InterfaceMetaData SubmodelElementCollection
*
* @remarks
* Parses all properties, actions and events.
*
* @param interfaceMeta Interface MetaData SubmodelElementCollection
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
* @returns Parsed InterfaceMetaData or null if not parsable
*/
public static parseInterfaceMetaData(interfaceMeta: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): InterfaceMetadata | null {
if (!interfaceMeta.value || interfaceMeta.idShort?.toLocaleLowerCase() !== "interfacemetadata") return null;
@@ -94,6 +126,13 @@ export default class AIDParser {
return parsed as InterfaceMetadata;
}
/**
* Parse a single Property InterfaceMetadata
* @param prop SubmodelElementCollection of one Property
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
* @returns Parsed Property InterfaceMetadata or null if not parsable
* @beta
*/
public static parseInterfaceMetadataProperty(prop: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): InterfaceProperty | null {
if (!aasCore.types.isSubmodelElementCollection(prop) || !prop.value) return null;
@@ -115,6 +154,12 @@ export default class AIDParser {
return { ...parsed, forms: parsedForm } as InterfaceProperty;
}
/**
* Parse the forms of a single Property InterfaceMetadata
* @param form Form SubmodelElementCollection of one Property
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
* @returns Parsed Form or null if not parsable
*/
private static parseInterfaceMetadataPropertyForm(form: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): InterfacePropertyForm | null {
if (!form.value) return null;
@@ -132,11 +177,25 @@ export default class AIDParser {
return parsed as InterfacePropertyForm;
}
/**
* Parse a single Action InterfaceMetadata
* @param prop SubmodelElementCollection of one Action
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
* @returns Parsed Action InterfaceMetadata or null if not parsable
* @alpha
*/
public static parseInterfaceMetadataAction(action: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): InterfaceAction | null {
// TODO
return null;
}
/**
* Parse a single Event InterfaceMetadata
* @param prop SubmodelElementCollection of one Event
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
* @returns Parsed Event InterfaceMetadata or null if not parsable
* @alpha
*/
public static parseInterfaceMetadataEvent(event: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): InterfaceEvent | null {
// TODO
return null;
+26 -4
View File
@@ -3,8 +3,18 @@ import Traverser from "../helper/traverser";
import { AssetInterfacesMappingConfiguration, MappingConfEntry, MappingConfiguration } from "../types/aimcConf";
import { endpointAvailable, ResolvedRelationshipElement } from "../types/common";
/**
* Class for static methods to parse the AssetInterfacesMappingConfiguration Submodel
* @public
*/
export default class AIMCParser {
/**
* Parse the complete AIMC Submodel
* @param env Environment
* @returns Parsed AIMC or null if not parsable
* @public
*/
public static parse(env: aasCore.types.Environment): AssetInterfacesMappingConfiguration | null {
const sm = Traverser.findSMByIdShort(env, "AssetInterfacesMappingConfiguration");
if (sm === null || sm.submodelElements === null) return null;
@@ -27,6 +37,14 @@ export default class AIMCParser {
return parsed;
}
/**
* Parse one entry of the AIMC Submodel
* @remarks
* The Environment is necessary so references can be resolved further down the line.
* @param entry Parse one entry of the AIMC Submodel
* @param environment The complete environment
* @returns Parsed Endpoint and MappingConfiguration or null if not parsable
*/
public static parseAIMCEntry(entry: aasCore.types.SubmodelElementCollection, environment: aasCore.types.Environment): MappingConfEntry | null {
const ep = Traverser.findElement(entry, element => (element as any).idShort?.toLocaleLowerCase() === "endpointmetadatareference");
const mc = Traverser.findElement(entry, element => (element as any).idShort?.toLocaleLowerCase() === "mappingconfiguration");
@@ -49,6 +67,14 @@ export default class AIMCParser {
};
}
/**
* Parse MappingConfiguration SubmodelElementCollection
* @remarks
* The Environment is necessary so references can be resolved further down the line.
* @param conf MappingConfiguration SubmodelElementCollection
* @param env Environment
* @returns Parsed MappingConfiguration or null if not parsable
*/
public static parseMappingConfiguration(conf: aasCore.types.SubmodelElementCollection, env: aasCore.types.Environment): MappingConfiguration | null {
if (!conf.value) return null;
@@ -68,10 +94,6 @@ export default class AIMCParser {
for (const ssm of sourceSinkMappings.overValueOrEmpty()) {
if (!aasCore.types.isRelationshipElement(ssm)) continue;
// No resolve, to allow for mapping
//const resolved = Traverser.resolveRelationship(env, ssm);
//if (resolved === null) continue;
parsed.SourceSinkMappings.push(ssm as ResolvedRelationshipElement);
}
+18 -1
View File
@@ -6,18 +6,25 @@ import type { OnRequestCallback } from "./types/requests";
* 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;
@@ -26,8 +33,10 @@ export default abstract class AASInterfaceServer<ConfigInterface> {
* @param config Interface server config
* @param aas AAS Environment for the server
* @param onRequestCallback Callback when a request is received and parsed
* @public
* @sealed
*/
constructor(
public constructor(
protected readonly config: ConfigInterface,
protected readonly aas: types.Environment,
protected readonly onRequestCallback: OnRequestCallback) {}
@@ -36,19 +45,27 @@ export default abstract class AASInterfaceServer<ConfigInterface> {
* 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;
+3 -1
View File
@@ -1,4 +1,4 @@
import { AvailableEndpoint } from "./common";
import type { AvailableEndpoint } from "./common";
export type AssetInterfacesDescription = {
[key in AvailableEndpoint]?: InterfaceDescription[];
@@ -77,10 +77,12 @@ type InterfacePropertyFormMQTT = InterfacePropertyFormBase & {
qos?: 0 | 1 | 2;
}
/** @alpha */
export type InterfaceAction = {
// TODO
}
/** @alpha */
export type InterfaceEvent = {
// TODO
}
+68 -5
View File
@@ -1,16 +1,21 @@
import type { types } from "@aas-core-works/aas-core3.0-typescript";
export type Request = GetRequest | WriteRequest | ObserveRequest | CallRequest | CallAsyncRequest | AsyncStateRequest | AsyncResultRequest | SubscribeRequest | UnsubscribeRequest;
export type OnRequestCallback = (request: Request) => any & GetRequestCallback & WriteRequestCallback & ObserveRequestCallback & CallRequestCallback & CallAsyncRequestCallback & AsyncStateRequestCallback & AsyncResultRequestCallback & SubscribeRequestCallback & UnsubscribeRequestCallback;
/**
* Read Property Request
*/
type GetRequest = {
type: "READ";
target: types.Property;
}
/**
* Read Property Request Callback
*/
type GetRequestCallback = (request: GetRequest) => any;
/**
* Write Property Request
*/
type WriteRequest = {
type: "WRITE";
target: types.Property;
@@ -19,8 +24,14 @@ type WriteRequest = {
}
}
/**
* Wrote Property Request Callback
*/
type WriteRequestCallback = (request: WriteRequest) => void;
/**
* Observe Property Request
*/
type ObserveRequest = {
type: "OBSERVE";
target: types.Property;
@@ -29,8 +40,14 @@ type ObserveRequest = {
}
}
/**
* Observe Property Request Callback
*/
type ObserveRequestCallback = (request: ObserveRequest) => boolean;
/**
* Subscribe Event Request
*/
type SubscribeRequest = {
type: "SUBSCRIBE";
target: types.BasicEventElement;
@@ -39,15 +56,27 @@ type SubscribeRequest = {
}
}
/**
* Subscribe Event Request Callback
*/
type SubscribeRequestCallback = (request: SubscribeRequest) => boolean;
/**
* Unsubscribe Event Request
*/
type UnsubscribeRequest = {
type: "UNSUBSCRIBE";
target: types.BasicEventElement;
}
/**
* Unsubscribe Event Request Callback
*/
type UnsubscribeRequestCallback = (request: UnsubscribeRequest) => void;
/**
* Call Operation Request
*/
type CallRequest = {
type: "CALL";
target: types.Operation;
@@ -56,8 +85,14 @@ type CallRequest = {
}
}
/**
* Call Operation Request Callback
*/
type CallRequestCallback = (request: CallRequest) => any;
/**
* Call Async Operation Request
*/
type CallAsyncRequest = {
type: "CALL-ASYNC";
target: types.Operation;
@@ -66,20 +101,48 @@ type CallAsyncRequest = {
}
}
/**
* Call Async Operation Request Callback
*/
type CallAsyncRequestCallback = (request: CallAsyncRequest) => string | null;
/**
* Get Async Operation State Request
*/
type AsyncStateRequest = {
type: "GET-OP-STATE";
target: string;
}
/**
* Get Async Operation State Request Callback
*/
type AsyncStateRequestCallback = (request: AsyncStateRequest) => boolean;
/**
* Get Async Operation Result Request
*/
type AsyncResultRequest = {
type: "GET-OP-RESULT";
target: string;
}
/**
* Get Async Operation Result Request Callback
*/
type AsyncResultRequestCallback = (request: AsyncResultRequest) => any;
type RequestType = "READ" | "WRITE" | "OBSERVE" | "CALL" | "CALL-ASYNC" | "GET-OP-STATE" | "GET-OP-RESULT" | "SUBSCRIBE" | "UNSUBSCRIBE"
/**
* Possible Request Types
*/
type RequestType = "READ" | "WRITE" | "OBSERVE" | "CALL" | "CALL-ASYNC" | "GET-OP-STATE" | "GET-OP-RESULT" | "SUBSCRIBE" | "UNSUBSCRIBE"
/**
* Combined Request Type
*/
export type Request = GetRequest | WriteRequest | ObserveRequest | CallRequest | CallAsyncRequest | AsyncStateRequest | AsyncResultRequest | SubscribeRequest | UnsubscribeRequest;
/**
* Combined Request Callback Type
*/
export type OnRequestCallback = (request: Request) => any & GetRequestCallback & WriteRequestCallback & ObserveRequestCallback & CallRequestCallback & CallAsyncRequestCallback & AsyncStateRequestCallback & AsyncResultRequestCallback & SubscribeRequestCallback & UnsubscribeRequestCallback;