More work on lib
This commit is contained in:
+36
-17
@@ -4,7 +4,7 @@ import { types, jsonization } from "@aas-core-works/aas-core3.0rc02-typescript";
|
||||
|
||||
export default class AASStore {
|
||||
private static instance: AASStore;
|
||||
private shells: Array<types.Environment> = [];
|
||||
private envs: Array<types.Environment> = [];
|
||||
|
||||
private constructor() { }
|
||||
|
||||
@@ -17,17 +17,17 @@ export default class AASStore {
|
||||
}
|
||||
|
||||
public addAAS(aas: types.Environment): void {
|
||||
this.shells.push(aas);
|
||||
this.envs.push(aas);
|
||||
}
|
||||
|
||||
public getAll(): Array<types.Environment> {
|
||||
return this.shells;
|
||||
return this.envs;
|
||||
}
|
||||
|
||||
public addAASByPath(path: string): void {
|
||||
if (!path.endsWith(".json")) throw new Error("File must be a JSON file");
|
||||
|
||||
const file = getAASFileContent(path);
|
||||
const file = readFileSync(path, { encoding: "utf-8" });
|
||||
|
||||
const aas = JSON.parse(file);
|
||||
const aasJson = jsonization.environmentFromJsonable(aas);
|
||||
@@ -39,7 +39,7 @@ export default class AASStore {
|
||||
public addAllAASFromPath(path: string): void {
|
||||
const errors: any[] = [];
|
||||
|
||||
getAllAASFiles(path).forEach(file => {
|
||||
this.getAllAASFilePaths(path).forEach(file => {
|
||||
try {
|
||||
this.addAASByPath(file);
|
||||
} catch (e) {
|
||||
@@ -50,24 +50,43 @@ export default class AASStore {
|
||||
throw errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function getAllAASFiles(aasPath: string): string[] {
|
||||
private getAllAASFilePaths(aasPath: string): string[] {
|
||||
const files = readdirSync(aasPath);
|
||||
return files.filter(file => file.endsWith(".json")).map(file => `${aasPath}/${file}`);
|
||||
}
|
||||
|
||||
export function getAASFileContent(aasPath: string): string {
|
||||
const content = readFileSync(aasPath, { encoding: "utf-8" });
|
||||
return content;
|
||||
public findAASById(id: string): types.AssetAdministrationShell | null {
|
||||
for (const env of this.envs) {
|
||||
if (env.assetAdministrationShells === null) continue;
|
||||
|
||||
for (const aas of env.assetAdministrationShells) {
|
||||
if (aas.id === id) return aas;
|
||||
}
|
||||
}
|
||||
|
||||
export function getAllAASFileContents(aasPath: string): string[] {
|
||||
const files = getAllAASFiles(aasPath)
|
||||
const content = [];
|
||||
for (const file of files) {
|
||||
content.push(getAASFileContent(file));
|
||||
return null;
|
||||
}
|
||||
|
||||
return content;
|
||||
public findSMById(id: string): types.Submodel | null {
|
||||
for (const env of this.envs) {
|
||||
if (env.submodels === null) continue;
|
||||
|
||||
for (const sm of env.submodels) {
|
||||
if (sm.id === id) return sm;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public findElement(submodelId: string, elementIdShort: string): types.Class | null {
|
||||
const sm = this.findSMById(submodelId);
|
||||
if (!sm) return null;
|
||||
|
||||
for (const element of sm.descend()) {
|
||||
if ((element as any).idShort === elementIdShort) return element;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,14 @@ export type OnResponseCallback = (response: any) => void
|
||||
|
||||
export default abstract class InterfaceConnectionObject<ConfigInterface> {
|
||||
protected abstract readonly name: string;
|
||||
protected abstract readonly uriProtocol: string[]|string;
|
||||
protected abstract readonly connectionType: ConnectionType;
|
||||
protected abstract readonly supportsSubscriptions: boolean;
|
||||
|
||||
protected config: ConfigInterface;
|
||||
private onResponseCallback: OnResponseCallback;
|
||||
|
||||
constructor(config: ConfigInterface, onResponseCallback: OnResponseCallback) {
|
||||
public constructor(config: ConfigInterface, onResponseCallback: OnResponseCallback) {
|
||||
this.config = config;
|
||||
this.onResponseCallback = onResponseCallback;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { types } from "@aas-core-works/aas-core3.0rc02-typescript";
|
||||
import type AASInterfaceServer from "server";
|
||||
import type { PossibleRequests } from "server";
|
||||
import type { Request } from "types/requests";
|
||||
import type InterfaceConnectionObject from "interfaceConnectionObject";
|
||||
import AASStore from "aasStore";
|
||||
|
||||
@@ -9,11 +9,11 @@ class MultiMessageBroker {
|
||||
|
||||
private serverInterfaces: Array<typeof AASInterfaceServer> = [];
|
||||
private serverInterfaceConfigs: Array<any> = [];
|
||||
private serverInstances: Array<AASInterfaceServer<any>|null> = [];
|
||||
private serverInstances: Array<AASInterfaceServer<typeof this.serverInterfaceConfigs[keyof typeof this.serverInterfaceConfigs]>|null> = [];
|
||||
|
||||
private connectorInterfaces: Array<typeof InterfaceConnectionObject> = [];
|
||||
private connectorConfigs: Array<any> = [];
|
||||
private connectorInstances: Array<InterfaceConnectionObject<any>|null> = [];
|
||||
private connectorInstances: Array<InterfaceConnectionObject<typeof this.connectorConfigs[keyof typeof this.connectorConfigs]>|null> = [];
|
||||
|
||||
public constructor() {}
|
||||
|
||||
@@ -51,7 +51,11 @@ class MultiMessageBroker {
|
||||
});
|
||||
}
|
||||
|
||||
private onInterfaceRequest(request: PossibleRequests) {
|
||||
private connectorConfigsFromAAS(aas: types.Environment): void {
|
||||
// TODO
|
||||
}
|
||||
|
||||
private onInterfaceRequest(request: Request) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
+25
-6
@@ -1,16 +1,16 @@
|
||||
import { types } from "@aas-core-works/aas-core3.0rc02-typescript";
|
||||
|
||||
export type PossibleRequests = "TODO";
|
||||
|
||||
export type OnRequestCallback = (request: PossibleRequests) => void
|
||||
import type { Request, OnRequestCallback } from "types/requests";
|
||||
|
||||
export default abstract class AASInterfaceServer<ConfigInterface> {
|
||||
protected abstract readonly name: string;
|
||||
protected config: ConfigInterface;
|
||||
private onRequestCallback: OnRequestCallback;
|
||||
protected abstract readonly supportsSubscriptions: boolean;
|
||||
protected readonly aas: types.Environment;
|
||||
private onRequestCallback: OnRequestCallback
|
||||
|
||||
constructor(config: ConfigInterface, aas: types.Environment, onRequestCallback: OnRequestCallback) {
|
||||
this.config = config;
|
||||
this.aas = aas;
|
||||
this.onRequestCallback = onRequestCallback;
|
||||
}
|
||||
|
||||
@@ -19,5 +19,24 @@ export default abstract class AASInterfaceServer<ConfigInterface> {
|
||||
public abstract stop(): void;
|
||||
public abstract notify(event: any): void;
|
||||
|
||||
protected abstract findElementByRequest(request: PossibleRequests): any | null;
|
||||
protected abstract findElementByRequest(request: Request): any | null;
|
||||
|
||||
protected findElementBySemanticId(id: string): types.Class | null {
|
||||
for (const element of this.aas.descend()) {
|
||||
if ((element as any).semanticId === id) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected findElementByShortId(id: string): types.Class | null {
|
||||
for (const element of this.aas.descend()) {
|
||||
if ((element as any).idShort === id) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export type Request = "TODO"
|
||||
|
||||
export type OnRequestCallback = (request: Request) => void
|
||||
Reference in New Issue
Block a user