Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAS next #1052

Merged
merged 30 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d16e650
fix: issue with using wrong arguments
danielpeintner Aug 7, 2023
89cb6f3
docs: update readme with the preferred way of using the interface
danielpeintner Aug 7, 2023
e45f624
refactor: initial test (setup)
danielpeintner Aug 7, 2023
d4243dd
feat: update transformation to latest AID version
danielpeintner Aug 23, 2023
9b00a7c
refactor: initial setup for transforming TD to AAS/AID
danielpeintner Aug 23, 2023
8e7917c
refactor: renaming
danielpeintner Aug 23, 2023
760b5be
refactor: add transformation code to
danielpeintner Aug 23, 2023
86d8c9a
refactor: simple interaction checks for TD to AID
danielpeintner Aug 24, 2023
5c0b5ee
docs: remove TODO
danielpeintner Aug 24, 2023
be18424
refactor: handle new security/securityDefinititions by @Kaz040
danielpeintner Aug 24, 2023
2218f6f
refactor: restructure test input
danielpeintner Aug 24, 2023
4fded0c
fix: add terms needed by AASX Explorer
danielpeintner Aug 24, 2023
de51585
feat: add ability to choose protocol prefix of interest
danielpeintner Aug 28, 2023
0435a8f
refactor: add TD counter transformation
danielpeintner Aug 28, 2023
2e24bb0
refactor: add support for form terms like "contentType" and htv:metho…
danielpeintner Aug 31, 2023
64e6e70
refactor: install/import fetch for Node prior to 18
danielpeintner Sep 5, 2023
a4d8c81
chore: update lock file
danielpeintner Sep 5, 2023
d98132a
refactor: avoid adding node-fetch as dependency
danielpeintner Sep 5, 2023
23898e8
refactor: wrap submodelElements in *one* AID submodel
danielpeintner Sep 5, 2023
f549d1d
refactor: fix lint warnings
danielpeintner Sep 5, 2023
76cf88c
refactor: skip online counter test
danielpeintner Sep 5, 2023
1d9cbe0
refactor: remove out-dated samples and tests
danielpeintner Sep 5, 2023
f28dcf5
refactor: add support for thing metadata
danielpeintner Sep 7, 2023
c69a1a8
refactor: transform AAS description -> TD descriptions
danielpeintner Sep 7, 2023
6b8fffb
refactor: support title and descriptions
danielpeintner Sep 7, 2023
7a6a3bf
refactor: remove commented code
danielpeintner Sep 7, 2023
2765dde
refactor: move public (important methods) upfront
danielpeintner Sep 7, 2023
186acaf
refactor: allow TD to AID transformation without specifying protocol …
danielpeintner Sep 7, 2023
c06c67c
refactor: remove console.log with logInfo
danielpeintner Sep 7, 2023
9de4893
docs: update readme
danielpeintner Sep 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading