diff --git a/node/aas-aid/README.md b/node/aas-aid/README.md index 330e16b..863d0f3 100644 --- a/node/aas-aid/README.md +++ b/node/aas-aid/README.md @@ -14,7 +14,7 @@ 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 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 file `counterHTTP.json` describes the counter sample in AAS/AID format for http binding. The `AssetInterfacesDescription` 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 `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(...)`). @@ -27,13 +27,13 @@ Servient = require("@node-wot/core").Servient; HttpClientFactory = require("@node-wot/binding-http").HttpClientFactory; // AID Util -AssetInterfaceDescriptionUtil = require("@node-wot/td-tools").AssetInterfaceDescriptionUtil; +AssetInterfacesDescription = require("@node-wot/td-tools").AssetInterfacesDescription; // create Servient and add HTTP binding let servient = new Servient(); servient.addClientFactory(new HttpClientFactory(null)); -let assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil(); +let assetInterfacesDescription = new AssetInterfacesDescription(); async function example() { try { @@ -44,7 +44,7 @@ async function example() { const aid = JSON.stringify(JSON.parse(aas).submodels[0]); // transform AID to WoT TD - const tdAID = assetInterfaceDescriptionUtil.transformSM2TD(aid, `{"title": "counter"}`); + const tdAID = assetInterfacesDescription.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 @@ -74,16 +74,16 @@ Note: Besides converting it into an AID submodel it is also possible to convert ```js // td-to-aid.js -AssetInterfaceDescriptionUtil = require("@node-wot/td-tools").AssetInterfaceDescriptionUtil; +AssetInterfacesDescription = require("@node-wot/td-tools").AssetInterfacesDescription; -let assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil(); +let assetInterfacesDescription = new AssetInterfacesDescription(); async function example() { try { const response = await fetch("http://plugfest.thingweb.io:8083/counter"); const counterTD = await response.json(); - const sm = assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(counterTD), ["http", "coap"]); + const sm = assetInterfacesDescription.transformTD2SM(JSON.stringify(counterTD), ["http", "coap"]); // print JSON format of AID submodel console.log(sm); diff --git a/node/aas-aid/src/asset-interface-description.ts b/node/aas-aid/src/asset-interface-description.ts index 8364305..9cf07f8 100644 --- a/node/aas-aid/src/asset-interface-description.ts +++ b/node/aas-aid/src/asset-interface-description.ts @@ -35,7 +35,7 @@ const logError = debug(`${namespace}:error`); * */ -export class AssetInterfaceDescriptionUtil { +export class AssetInterfacesDescription { /** * Transform AAS in JSON format to a WoT ThingDescription (TD) * diff --git a/node/aas-aid/test/AssetInterfaceDescriptionTest.ts b/node/aas-aid/test/AssetInterfaceDescriptionTest.ts index ce2b648..9b9f63a 100644 --- a/node/aas-aid/test/AssetInterfaceDescriptionTest.ts +++ b/node/aas-aid/test/AssetInterfaceDescriptionTest.ts @@ -16,7 +16,7 @@ import { suite, test } from "@testdeck/mocha"; import { expect } from "chai"; -import { AssetInterfaceDescriptionUtil } from "../src/asset-interface-description"; +import { AssetInterfacesDescription } from "../src/asset-interface-description"; import { promises as fs } from "fs"; import { ThingDescription } from "wot-typescript-definitions"; @@ -27,8 +27,8 @@ const aidSchema = AIDSchema; const ajv = new Ajv({ strict: false }); @suite("tests to verify the Asset Interface Description Utils") -class AssetInterfaceDescriptionUtilTest { - private assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil(); +class AssetInterfaceDescriptionTest { + private assetInterfacesDescription = new AssetInterfacesDescription(); aidValidator = ajv.compile(aidSchema) as ValidateFunction; @@ -53,7 +53,7 @@ class AssetInterfaceDescriptionUtilTest { const isValid = this.validateAID(modelAIDobj.submodels[0]); expect(isValid.valid, isValid.errors).to.equal(true); - const td = this.assetInterfaceDescriptionUtil.transformAAS2TD(modelAID, `{"title": "bla"}`); + const td = this.assetInterfacesDescription.transformAAS2TD(modelAID, `{"title": "bla"}`); const tdObj = JSON.parse(td); expect(tdObj).to.have.property("@context").that.equals("https://www.w3.org/2022/wot/td/v1.1"); @@ -173,7 +173,7 @@ class AssetInterfaceDescriptionUtilTest { // TODO actions and events for counter thing (TBD by AAS) // check RegEx capability with fully qualified submodel - const td2 = this.assetInterfaceDescriptionUtil.transformAAS2TD( + const td2 = this.assetInterfacesDescription.transformAAS2TD( modelAID, `{"title": "counter"}`, "InterfaceHTTP" @@ -182,12 +182,12 @@ class AssetInterfaceDescriptionUtilTest { expect(tdObj).to.deep.equal(td2Obj); // check RegEx capability with search pattern for submodel - const td3 = this.assetInterfaceDescriptionUtil.transformAAS2TD(modelAID, `{"title": "counter"}`, "HTTP*"); + const td3 = this.assetInterfacesDescription.transformAAS2TD(modelAID, `{"title": "counter"}`, "HTTP*"); const td3Obj = JSON.parse(td3); expect(tdObj).to.deep.equal(td3Obj); // check RegEx capability with fully unknown submodel - const td4 = this.assetInterfaceDescriptionUtil.transformAAS2TD(modelAID, `{"title": "counter"}`, "OPC*"); + const td4 = this.assetInterfacesDescription.transformAAS2TD(modelAID, `{"title": "counter"}`, "OPC*"); const td4Obj = JSON.parse(td4); expect(td4Obj).to.not.have.property("properties"); } @@ -200,7 +200,7 @@ class AssetInterfaceDescriptionUtilTest { const isValid = this.validateAID(modelAIDobj.submodels[0]); expect(isValid.valid, isValid.errors).to.equal(true); - const td = this.assetInterfaceDescriptionUtil.transformAAS2TD(modelAID, `{"title": "bla"}`); + const td = this.assetInterfacesDescription.transformAAS2TD(modelAID, `{"title": "bla"}`); const tdObj = JSON.parse(td); expect(tdObj).to.have.property("@context").that.equals("https://www.w3.org/2022/wot/td/v1.1"); @@ -277,9 +277,9 @@ class AssetInterfaceDescriptionUtilTest { @test async "should correctly roundtrip inverterModbus from/to AID"() { const aasInput = (await fs.readFile("test/inverterModbus.json")).toString(); - const td = this.assetInterfaceDescriptionUtil.transformAAS2TD(aasInput); + const td = this.assetInterfacesDescription.transformAAS2TD(aasInput); - const aidOutput = this.assetInterfaceDescriptionUtil.transformTD2SM(td); + const aidOutput = this.assetInterfacesDescription.transformTD2SM(td); const smObj = JSON.parse(aidOutput); const isValid = this.validateAID(smObj); @@ -564,7 +564,7 @@ class AssetInterfaceDescriptionUtilTest { }; @test async "should correctly transform sample TD1 into AID submodel"() { - const sm = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td1), ["https"]); + const sm = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td1), ["https"]); const smObj = JSON.parse(sm); const isValid = this.validateAID(smObj); @@ -835,14 +835,14 @@ class AssetInterfaceDescriptionUtilTest { // Test to use all possible prefixes -> in this case it is only https // Note: id is autogenerated (if not present) -> needs to be exluded/removed/set in TD - const sm2 = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td1)); + const sm2 = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td1)); const sm2Obj = JSON.parse(sm2); expect(smObj).to.eql(sm2Obj); } @test async "should transform sample TD1 into JSON submodel without any properties due to unknown protocol prefix"() { - const sm = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td1), ["unknown"]); + const sm = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td1), ["unknown"]); const smObj = JSON.parse(sm); expect(smObj).to.have.property("idShort").that.equals("AssetInterfacesDescription"); @@ -867,7 +867,7 @@ class AssetInterfaceDescriptionUtilTest { } @test async "should correctly transform sample TD1 into JSON AAS"() { - const sm = this.assetInterfaceDescriptionUtil.transformTD2AAS(JSON.stringify(this.td1), ["http"]); + const sm = this.assetInterfacesDescription.transformTD2AAS(JSON.stringify(this.td1), ["http"]); const aasObj = JSON.parse(sm); expect(aasObj).to.have.property("assetAdministrationShells").to.be.an("array"); @@ -900,7 +900,7 @@ class AssetInterfaceDescriptionUtilTest { }; @test async "should correctly transform sample TD2 into AID submodel"() { - const sm = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td2)); + const sm = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td2)); const smObj = JSON.parse(sm); // console.log("###\n\n" + JSON.stringify(smObj) + "\n\n###"); @@ -1079,7 +1079,7 @@ class AssetInterfaceDescriptionUtilTest { }; @test async "should correctly transform sample TD3 into AID submodel"() { - const sm = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td3)); + const sm = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td3)); const smObj = JSON.parse(sm); // console.log("###\n\n" + JSON.stringify(smObj) + "\n\n###"); @@ -1251,7 +1251,7 @@ class AssetInterfaceDescriptionUtilTest { const response = await fetch("http://plugfest.thingweb.io:8083/counter"); const counterTD = await response.json(); - const sm = this.assetInterfaceDescriptionUtil.transformTD2AAS(JSON.stringify(counterTD), ["http"]); // "coap" + const sm = this.assetInterfacesDescription.transformTD2AAS(JSON.stringify(counterTD), ["http"]); // "coap" console.log("XXX AAS\n\n" + sm + "\n\nXXX"); const aasObj = JSON.parse(sm);