From 1f71e3fc6aa08175fe10eeb430ae0f6f830725e6 Mon Sep 17 00:00:00 2001 From: danielpeintner Date: Wed, 11 Oct 2023 09:50:25 +0200 Subject: [PATCH] refactor(td-tools): Aid updates (#1107) * fix(td-tools): use lowercase interaction names e.g., "Properties" -> "properties" * refactor: use AID submodel in examples (instead of AAS) * refactor: move deprecated method to end of public methods * Update packages/td-tools/src/util/README.md Co-authored-by: Jan Romann * docs: improved wording based on feedback from @wiresio --------- Co-authored-by: Jan Romann --- packages/td-tools/src/util/README.md | 23 +++++++++++------- .../src/util/asset-interface-description.ts | 22 ++++++++--------- .../test/AssetInterfaceDescriptionTest.ts | 4 +-- packages/td-tools/test/util/counterHTTP.aasx | Bin 3099 -> 3097 bytes packages/td-tools/test/util/counterHTTP.json | 6 ++--- .../td-tools/test/util/inverterModbus.json | 6 ++--- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/packages/td-tools/src/util/README.md b/packages/td-tools/src/util/README.md index 00f139f27..7e704b945 100644 --- a/packages/td-tools/src/util/README.md +++ b/packages/td-tools/src/util/README.md @@ -14,9 +14,10 @@ The [IDTA Asset Interface Description (AID) working group](https://github.com/ad #### AAS/AID to WoT TD -The file `counterHTTP.json` describes the counter sample in AID format for http binding. The `AssetInterfaceDescriptionUtil` utility class allows to transform the AID format to a valid WoT TD format which in the end can be properly consumed by node-wot. +The file `counterHTTP.json` describes the counter sample in AAS/AID format for http binding. The `AssetInterfaceDescriptionUtil` utility class allows to transform the AID format to a valid WoT TD format which in the end can be properly consumed by node-wot. -The example tries to load an AID file in AID format and transforms it to a regular WoT TD. +The example `aid-to-td.js` tries to transform an AID submodel (from an AAS file) into a regular WoT TD. +Note: Besides converting the AID submodel it is also possible to convert a full AAS file (see `transformTD2AAS(...)`). ```js // aid-to-td.js @@ -39,10 +40,13 @@ async function example() { const aas = await fs.readFile("counterHTTP.json", { encoding: "utf8", }); + // pick AID submodel + const aid = JSON.stringify(JSON.parse(aas).submodels[0]); + // transform AID to WoT TD - let tdAID = assetInterfaceDescriptionUtil.transformAAS2TD(aas, `{"title": "counter"}`); - // Note: transformAAS2TD() may have up to 3 input parameters - // * aas (required): AAS in JSON format + const tdAID = assetInterfaceDescriptionUtil.transformSM2TD(aid, `{"title": "counter"}`); + // Note: transformSM2TD() may have up to 3 input parameters + // * aid (required): AID submodel in JSON format // * template (optional): Initial TD template // * submodelRegex (optional): Submodel filter based on regular expression // e.g., filtering HTTP only by calling transformAAS2TD(aas, `{}`, "HTTP") @@ -65,7 +69,8 @@ example(); #### WoT TD to AAS/AID -The example tries to load online counter TD and converts it to AAS JSON format. +The example `td-to-aid.js` tries to load the online counter TD and converts it to an AID submodel in JSON format. +Note: Besides converting it into an AID submodel it is also possible to convert it into a full AAS form (see `transformTD2AAS(...)`). ```js // td-to-aid.js @@ -78,9 +83,9 @@ async function example() { const response = await fetch("http://plugfest.thingweb.io:8083/counter"); const counterTD = await response.json(); - const sm = assetInterfaceDescriptionUtil.transformTD2AAS(JSON.stringify(counterTD), ["http", "coap"]); + const sm = assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(counterTD), ["http", "coap"]); - // print JSON format of AAS + // print JSON format of AID submodel console.log(sm); } catch (err) { console.log(err); @@ -98,4 +103,4 @@ example(); Note: make sure that the file `counterHTTP.json` is in the same folder as the script. `node td-to-aid.js` -... will show the online counter im AAS/AID JSON format (usable by AASX Package Explorer 2023-08-01.alpha). +... will show the online counter im AAS/AID JSON format (compliant with AAS V3.0 and can be imported by AASX Package Explorer). diff --git a/packages/td-tools/src/util/asset-interface-description.ts b/packages/td-tools/src/util/asset-interface-description.ts index aa6e5dc1c..9f6e4ef76 100644 --- a/packages/td-tools/src/util/asset-interface-description.ts +++ b/packages/td-tools/src/util/asset-interface-description.ts @@ -36,11 +36,6 @@ const logError = debug(`${namespace}:error`); */ export class AssetInterfaceDescriptionUtil { - /** @deprecated use transformAAS2TD method instead */ - public transformToTD(aid: string, template?: string, submodelRegex?: string): string { - return this.transformAAS2TD(aid, template, submodelRegex); - } - /** * Transform AAS in JSON format to a WoT ThingDescription (TD) * @@ -188,6 +183,11 @@ export class AssetInterfaceDescriptionUtil { return JSON.stringify(aidObject); } + /** @deprecated use transformAAS2TD method instead */ + public transformToTD(aid: string, template?: string, submodelRegex?: string): string { + return this.transformAAS2TD(aid, template, submodelRegex); + } + /* * PRIVATE IMPLEMENTATION METHODS ARE FOLLOWING * @@ -454,7 +454,7 @@ export class AssetInterfaceDescriptionUtil { logInfo("InterfaceMetadata"); if (smValue.value instanceof Array) { for (const interactionValue of smValue.value) { - if (interactionValue.idShort === "Properties") { + if (interactionValue.idShort === "properties") { if (interactionValue.value instanceof Array) { for (const iValue of interactionValue.value) { logInfo("Property: " + iValue.idShort); @@ -468,7 +468,7 @@ export class AssetInterfaceDescriptionUtil { smInformation.properties.get(iValue.idShort)?.push(propInter); } } - } else if (interactionValue.idShort === "Operations") { + } else if (interactionValue.idShort === "actions") { if (interactionValue.value instanceof Array) { for (const iValue of interactionValue.value) { logInfo("Action: " + iValue.idShort); @@ -482,7 +482,7 @@ export class AssetInterfaceDescriptionUtil { smInformation.actions.get(iValue.idShort)?.push(actInter); } } - } else if (interactionValue.idShort === "Events") { + } else if (interactionValue.idShort === "events") { if (interactionValue.value instanceof Array) { for (const iValue of interactionValue.value) { logInfo("Event: " + iValue.idShort); @@ -898,19 +898,19 @@ export class AssetInterfaceDescriptionUtil { const values: Array = []; // Properties values.push({ - idShort: "Properties", + idShort: "properties", value: properties, modelType: "SubmodelElementCollection", }); // Actions values.push({ - idShort: "Actions", + idShort: "actions", value: actions, modelType: "SubmodelElementCollection", }); // Events values.push({ - idShort: "Events", + idShort: "events", value: events, modelType: "SubmodelElementCollection", }); diff --git a/packages/td-tools/test/AssetInterfaceDescriptionTest.ts b/packages/td-tools/test/AssetInterfaceDescriptionTest.ts index 7863cacc9..f411ffb64 100644 --- a/packages/td-tools/test/AssetInterfaceDescriptionTest.ts +++ b/packages/td-tools/test/AssetInterfaceDescriptionTest.ts @@ -321,7 +321,7 @@ class AssetInterfaceDescriptionUtilTest { expect(smValue).to.have.property("value").to.be.an("array").to.have.lengthOf.greaterThan(0); let hasProperties = false; for (const interactionValues of smValue.value) { - if (interactionValues.idShort === "Properties") { + if (interactionValues.idShort === "properties") { hasProperties = true; expect(interactionValues) .to.have.property("value") @@ -439,7 +439,7 @@ class AssetInterfaceDescriptionUtilTest { hasInterfaceMetadata = true; expect(smValue).to.have.property("value").to.be.an("array").to.have.lengthOf.greaterThan(0); for (const interactionValues of smValue.value) { - if (interactionValues.idShort === "Properties") { + if (interactionValues.idShort === "properties") { expect(interactionValues).to.have.property("value").to.be.an("array").to.have.lengthOf(0); } } diff --git a/packages/td-tools/test/util/counterHTTP.aasx b/packages/td-tools/test/util/counterHTTP.aasx index 3815efa46d53cea51740d62de78dd5dff9e0e496..eb01b3fbd86509245eb15febd41b858cc48242b3 100644 GIT binary patch delta 885 zcmV-*1B(2c7?~K5QU&2*))MxySMURWkyTM>!|)bi*pg*pg&3T_^pqhhS#HUtFJ79; z3<;NG76DqcFckZ^NTiG_vmTQfTfA7bJ885_TlvzQL+}MKrI?{4(X!WPH0_5Yk9Kh^ zUmi?G%fJOvt+WE?%JAvBK5D z<*w9SPf#}D5ZsbUGifJ`IY7Lc;)*~%xOO9L{X8HgzT7=5Nv7&W)NP__mB?B-x;BrU zYGj#qs+*dki~*jD+fx_BoZ0VxN!7Zo9{AfTpsEsTDPlWiY#U|Pllqx>~Z`DxSjZj9R++~l{jpO!8jC~r%(8l_r* zSsW9Ov{JhQ+pw7ki!xcEeR%)+(bi^HOaMx-@NUEe3o%udJt%o<7G#%kx#eS^W=6m` zXJH|>bE(?>zPA2K+e5p5FQW65c3-6MuiY2PLelPw?D>{hUj3Cy9NY5i$-b9gzBl_t zz5(=H^BQhe&UUj*6)H(GlpI2JYgju%PzDP&Msw%l5cs&3&)bv*DhP-`(#y!$d@XYfl?CQEq$Musv;< zwTkw%p(ft6rw#YEZpy2wlf}TERZ+WnL9_M~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/counterHTTP.json index dc31feddd..bf8286b0c 100644 --- a/packages/td-tools/test/util/counterHTTP.json +++ b/packages/td-tools/test/util/counterHTTP.json @@ -149,7 +149,7 @@ "embeddedDataSpecifications": [], "value": [ { - "idShort": "Properties", + "idShort": "properties", "semanticId": { "type": "ExternalReference", "keys": [] @@ -473,7 +473,7 @@ "modelType": "SubmodelElementCollection" }, { - "idShort": "Actions", + "idShort": "actions", "semanticId": { "type": "ExternalReference", "keys": [] @@ -483,7 +483,7 @@ "modelType": "SubmodelElementCollection" }, { - "idShort": "Events", + "idShort": "events", "semanticId": { "type": "ExternalReference", "keys": [] diff --git a/packages/td-tools/test/util/inverterModbus.json b/packages/td-tools/test/util/inverterModbus.json index c9f976b0b..09e879a0d 100644 --- a/packages/td-tools/test/util/inverterModbus.json +++ b/packages/td-tools/test/util/inverterModbus.json @@ -84,7 +84,7 @@ "idShort": "InterfaceMetadata", "value": [ { - "idShort": "Properties", + "idShort": "properties", "value": [ { "idShort": "device_name", @@ -144,12 +144,12 @@ "modelType": "SubmodelElementCollection" }, { - "idShort": "Actions", + "idShort": "actions", "value": [], "modelType": "SubmodelElementCollection" }, { - "idShort": "Events", + "idShort": "events", "value": [], "modelType": "SubmodelElementCollection" }