Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: align/improve AAS/AID <-> TD transformation

* fix: issue with using wrong arguments

* docs: update readme with the preferred way of using the interface

* refactor: initial test (setup)

* feat: update transformation to latest AID version

Note: examples AID_v03.json and AID_v03_counter.json are no longer compliant -> skipped for now

* refactor: initial setup for transforming TD to AAS/AID

* refactor: renaming

* refactor: add transformation code to

* refactor: simple interaction checks for TD to AID

* refactor: handle new security/securityDefinititions by @Kaz040

* refactor: restructure test input

* fix: add terms needed by AASX Explorer

* feat: add ability to choose protocol prefix of interest

* refactor: add TD counter transformation

* refactor: add support for form terms like "contentType" and htv:methodName"

* refactor: install/import fetch for Node prior to 18

* chore: update lock file

* refactor: avoid adding node-fetch as dependency

* refactor: wrap submodelElements in *one* AID submodel

* refactor: fix lint warnings

* refactor: skip online counter test

* refactor: remove out-dated samples and tests

* refactor: add support for thing metadata

* refactor: transform AAS description -> TD descriptions

* refactor: support title and descriptions

* refactor: remove commented code

* refactor: move public (important methods) upfront

* refactor: allow TD to AID transformation without specifying protocol prefixes

-> use *all* possible prefixes

* refactor: remove console.log with logInfo

* docs: update readme
  • Loading branch information
danielpeintner authored Sep 12, 2023
1 parent c8177c2 commit 03751a9
Show file tree
Hide file tree
Showing 9 changed files with 1,557 additions and 2,242 deletions.
57 changes: 43 additions & 14 deletions packages/td-tools/src/util/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

The [IDTA Asset Interface Description (AID) working group](https://github.com/admin-shell-io/submodel-templates/tree/main/development/Asset%20Interface%20Description/1/0) defines a submodel that can be used to describe the asset's service interface or asset's related service interfaces. The current AID working assumptions reuse existing definitions from [WoT Thing Descriptions](https://www.w3.org/TR/wot-thing-description11/) and hence it is possible to consume AAS with AID definitions with node-wot (e.g., read/subscribe live data of the asset and/or associated service).

### Sample Application

The file `AID_v03_counter.json` describes the counter sample in AID format. 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.
### Sample Applications

#### Prerequisites

- `npm install @node-wot/td-tools`
- `npm install @node-wot/core`
- `npm install @node-wot/binding-http`

#### Sample Code
#### 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 example tries to load an AID file in AID format and transforms it to a regular WoT TD.

```js
// aid-client.js
// aid-to-td.js
const fs = require("fs/promises"); // to read JSON file in AID format

Servient = require("@node-wot/core").Servient;
Expand All @@ -36,16 +36,16 @@ let assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil();

async function example() {
try {
const aid = await fs.readFile("AID_v03_counter.json", {
const aas = await fs.readFile("counterHTTP.json", {
encoding: "utf8",
});
// transform AID to WoT TD
let tdAID = assetInterfaceDescriptionUtil.transformToTD(aid, `{"title": "counter"}`);
// Note: transformToTD() may have up to 3 input parameters
// * aid (required): AID input
let tdAID = assetInterfaceDescriptionUtil.transformAAS2TD(aas, `{"title": "counter"}`);
// Note: transformAAS2TD() may have up to 3 input parameters
// * aas (required): AAS in JSON format
// * template (optional): Initial TD template
// * submodelRegex (optional): Submodel filter based on regular expression
// e.g., filtering HTTP only by calling transformToTD(aid, `{}`, "HTTP")
// e.g., filtering HTTP only by calling transformAAS2TD(aas, `{}`, "HTTP")

// do work as usual
const WoT = await servient.start();
Expand All @@ -63,10 +63,39 @@ async function example() {
example();
```

#### Run the sample script
#### WoT TD to AAS/AID

The example tries to load online counter TD and converts it to AAS JSON format.

```js
// td-to-aid.js
AssetInterfaceDescriptionUtil = require("@node-wot/td-tools").AssetInterfaceDescriptionUtil;

let assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil();

async function example() {
try {
const response = await fetch("http://plugfest.thingweb.io:8083/counter");
const counterTD = await response.json();

const sm = assetInterfaceDescriptionUtil.transformTD2AAS(JSON.stringify(counterTD), ["http", "coap"]);

// print JSON format of AAS
console.log(sm);
} catch (err) {
console.log(err);
}
}

// launch example
example();
```

`node aid-client.js`
#### Run the sample scripts

It will show the counter value retrieved from http://plugfest.thingweb.io:8083/counter/properties/count
`node aid-to-td.js`
... will show the counter value retrieved from http://plugfest.thingweb.io:8083/counter/properties/count
Note: make sure that the file `counterHTTP.json` is in the same folder as the script.

Note: make sure that the file `AID_v03_counter.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).
Loading

0 comments on commit 03751a9

Please sign in to comment.