Skip to content

Commit 03751a9

Browse files
AAS next (#1052)
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
1 parent c8177c2 commit 03751a9

File tree

9 files changed

+1557
-2242
lines changed

9 files changed

+1557
-2242
lines changed

packages/td-tools/src/util/README.md

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
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).
66

7-
### Sample Application
8-
9-
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.
7+
### Sample Applications
108

119
#### Prerequisites
1210

1311
- `npm install @node-wot/td-tools`
1412
- `npm install @node-wot/core`
1513
- `npm install @node-wot/binding-http`
1614

17-
#### Sample Code
15+
#### AAS/AID to WoT TD
16+
17+
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.
1818

1919
The example tries to load an AID file in AID format and transforms it to a regular WoT TD.
2020

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

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

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

5050
// do work as usual
5151
const WoT = await servient.start();
@@ -63,10 +63,39 @@ async function example() {
6363
example();
6464
```
6565

66-
#### Run the sample script
66+
#### WoT TD to AAS/AID
67+
68+
The example tries to load online counter TD and converts it to AAS JSON format.
69+
70+
```js
71+
// td-to-aid.js
72+
AssetInterfaceDescriptionUtil = require("@node-wot/td-tools").AssetInterfaceDescriptionUtil;
73+
74+
let assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil();
75+
76+
async function example() {
77+
try {
78+
const response = await fetch("http://plugfest.thingweb.io:8083/counter");
79+
const counterTD = await response.json();
80+
81+
const sm = assetInterfaceDescriptionUtil.transformTD2AAS(JSON.stringify(counterTD), ["http", "coap"]);
82+
83+
// print JSON format of AAS
84+
console.log(sm);
85+
} catch (err) {
86+
console.log(err);
87+
}
88+
}
89+
90+
// launch example
91+
example();
92+
```
6793

68-
`node aid-client.js`
94+
#### Run the sample scripts
6995

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

72-
Note: make sure that the file `AID_v03_counter.json` is in the same folder as the script.
100+
`node td-to-aid.js`
101+
... will show the online counter im AAS/AID JSON format (usable by AASX Package Explorer 2023-08-01.alpha).

0 commit comments

Comments
 (0)