More work on the (better) AID
This commit is contained in:
+38
-4
@@ -3,6 +3,7 @@ import type { ConnectionConfiguration, AIMCMap } from "./types/aimcConf";
|
||||
import AIMCParser from "./parser/AIMCParser";
|
||||
import Traverser from "./helper/traverser";
|
||||
import AIDParser from "./parser/AIDParser";
|
||||
import type { InterfaceAction, InterfaceActionForm, InterfaceEvent, InterfaceEventForm, InterfaceProperty, InterfacePropertyForm } from "./types/aidConf";
|
||||
|
||||
/**
|
||||
* The AIMC Mapper.
|
||||
@@ -49,14 +50,47 @@ export default class AIMCMapper {
|
||||
const resolved = Traverser.resolveRelationship(this.env, ssm);
|
||||
if (resolved === null) continue;
|
||||
|
||||
// To know if we currently view a property, action or event, they reference keys can help us.
|
||||
// We know the third to last must be the "InterfaceMetadata" and the second to last must be the "Properties", "Actions" or "Events".
|
||||
// As we _maybe_ don't know if the first and second reference are switched we can check for the third to last.
|
||||
const elemType = (ssm as types.RelationshipElement).first.keys.at(-3)?.value.toLocaleLowerCase() === "interfacemetadata" ? (ssm as types.RelationshipElement).first.keys.at(-2)?.value : (ssm as types.RelationshipElement).second.keys.at(-2)?.value;
|
||||
|
||||
let {first, second} = resolved;
|
||||
|
||||
let parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as types.SubmodelElementCollection);
|
||||
let parsedPropConf: InterfaceProperty | InterfaceAction | InterfaceEvent | null = null;
|
||||
|
||||
switch (elemType?.toLocaleLowerCase()) {
|
||||
case "properties":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
case "actions":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataAction(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
case "events":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataEvent(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
default:
|
||||
// Error. We have not found a valid type of element to parse.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parsedPropConf === null) {
|
||||
// maybe the property is in the first element
|
||||
[first, second] = [second, first];
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as types.SubmodelElementCollection);
|
||||
|
||||
switch (elemType?.toLocaleLowerCase()) {
|
||||
case "properties":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
case "actions":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataAction(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
case "events":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataEvent(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parsedPropConf === null) continue;
|
||||
|
||||
this.map.set(second, {
|
||||
@@ -113,8 +147,8 @@ export default class AIMCMapper {
|
||||
const result = [];
|
||||
|
||||
for (const [e, cc] of this.map.entries()) {
|
||||
const formsPath = cc.base + cc.forms.href;
|
||||
if (formsPath === path) result.push(e);
|
||||
const formsPaths = cc.forms.map((f: InterfaceActionForm | InterfacePropertyForm | InterfaceEventForm) => cc.base + f.href);
|
||||
if (formsPaths.includes(path)) result.push(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user