From a6943fa99fabd10b106e1f132777fbcc662cb26a Mon Sep 17 00:00:00 2001 From: danielpeintner Date: Tue, 8 Oct 2024 10:01:17 +0200 Subject: [PATCH] feat: allow to configure aasId and aasIdShort (#53) * feat: allow to configure aasId and aasIdShort * refactor: run format --- node/aas-aid/README.md | 2 +- node/aas-aid/src/asset-interfaces-description.ts | 9 ++++++--- .../test/asset-interfaces-description-test.ts | 13 +++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/node/aas-aid/README.md b/node/aas-aid/README.md index d8ca969..32778ac 100644 --- a/node/aas-aid/README.md +++ b/node/aas-aid/README.md @@ -82,7 +82,7 @@ Note: make sure that the file `counterHTTP.json` is in the same folder as the sc The example `td-to-aid.js` loads the online [counter TD](http://plugfest.thingweb.io:8083/counter/) and converts it to an AID submodel in JSON format. -Note: by using the option `createAAS` a full AAS form is created (instead of the AID submodel only). +Note: by using the option `createAAS` a full AAS form is created (instead of the AID submodel only). The AAS can be configured with `aasId` and `aasIdShort` also. ```js // td-to-aid.js diff --git a/node/aas-aid/src/asset-interfaces-description.ts b/node/aas-aid/src/asset-interfaces-description.ts index dd8000d..4f7e116 100644 --- a/node/aas-aid/src/asset-interfaces-description.ts +++ b/node/aas-aid/src/asset-interfaces-description.ts @@ -37,6 +37,8 @@ const logError = debug(`${namespace}:error`); export interface Options { createAAS?: boolean; + aasId?: string; + aasIdShort?: string; } export class AssetInterfacesDescription { @@ -82,7 +84,7 @@ export class AssetInterfacesDescription { * Transform WoT ThingDescription (TD) to AID submodel in JSON format * * @param td input TD - * @param options options such as creating AAS wrapper + * @param options options such as creating AAS wrapper with providing id/idShort * @param protocols protocol prefixes of interest (e.g., ["http", "coap"]) or optional if all * @returns transformed AAS in JSON format */ @@ -96,8 +98,9 @@ export class AssetInterfacesDescription { const submodelId = submodelObj.id; // configuration - const aasName = "SampleAAS"; - const aasId = "https://example.com/ids/aas/7474_9002_6022_1115"; + const aasName = !!options.aasIdShort ? options.aasIdShort : "SampleAAS"; + const aasId = + options.aasId?.length !== 0 ? options.aasId : "https://example.com/ids/aas/7474_9002_6022_1115"; const aas = { assetAdministrationShells: [ diff --git a/node/aas-aid/test/asset-interfaces-description-test.ts b/node/aas-aid/test/asset-interfaces-description-test.ts index 2d12b34..d8ebbe9 100644 --- a/node/aas-aid/test/asset-interfaces-description-test.ts +++ b/node/aas-aid/test/asset-interfaces-description-test.ts @@ -921,12 +921,17 @@ class AssetInterfaceDescriptionTest { } @test async "should correctly transform sample TD1 into JSON AAS"() { - const sm = this.assetInterfacesDescription.transformTD2AID(JSON.stringify(this.td1), { createAAS: true }, [ - "http", - ]); + const sm = this.assetInterfacesDescription.transformTD2AID( + JSON.stringify(this.td1), + { createAAS: true, aasIdShort: "FooAAS", aasId: "https://example.com/1234" }, + ["http"] + ); const aasObj = JSON.parse(sm); - expect(aasObj).to.have.property("assetAdministrationShells").to.be.an("array"); + expect(aasObj).to.have.property("assetAdministrationShells").to.be.an("array").to.have.lengthOf(1); + const aas = aasObj.assetAdministrationShells[0]; + expect(aas).to.have.property("idShort").to.eql("FooAAS"); + expect(aas).to.have.property("id").to.eql("https://example.com/1234"); expect(aasObj).to.have.property("submodels").to.be.an("array").to.have.lengthOf(1); // Note: proper AID submodel checks done in previous test-cases