Skip to content

Commit

Permalink
Merge branch 'master' into strict-tsconfig-opcua
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed Aug 16, 2023
2 parents 571db00 + 3a74512 commit 0163468
Show file tree
Hide file tree
Showing 32 changed files with 330 additions and 187 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/ci-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
node-version: [16.x, 18.x]
node-version: [16.x, 18.x, 20.x]

steps:
- name: Checkout
Expand All @@ -19,9 +19,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: npm 7
# npm workspaces requires npm v7 or higher
run: npm i -g npm@7 --registry=https://registry.npmjs.org
- name: Install
run: npm ci

Expand All @@ -41,14 +38,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Use Node.js 14
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 14

- name: npm 7
# npm workspaces requires npm v7 or higher
run: npm i -g npm@7 --registry=https://registry.npmjs.org
node-version: 16

- name: Install
run: npm ci
Expand All @@ -61,10 +54,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: install node v14
- name: install node v16
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16
- name: verify packages version consistency accross sub-modules
run: npm run check:versions

Expand Down
17 changes: 5 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [16.x, 18.x]
node-version: [16.x, 18.x, 20.x]

steps:
- name: Checkout
Expand All @@ -19,9 +19,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: npm 7
# npm workspaces requires npm v7 or higher
run: npm i -g npm@7 --registry=https://registry.npmjs.org
- name: Install
run: npm ci

Expand All @@ -41,14 +38,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Use Node.js 14
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 14

- name: npm 7
# npm workspaces requires npm v7 or higher
run: npm i -g npm@7 --registry=https://registry.npmjs.org
node-version: 16

- name: Install
run: npm ci
Expand All @@ -61,10 +54,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: install node v14
- name: install node v16
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16
- name: verify packages version consistency accross sub-modules
run: npm run check:versions

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ cs.addCodec(new MyCodec("application/myType"));
### To use with Node.js

> **Warning**: We no longer actively support Node.js version 14 and lower.
> Node.js version 20 is not yet supported (https://github.com/eclipse-thingweb/node-wot/issues/1004)
- [Node.js](https://nodejs.org/) version 14+
- [npm](https://www.npmjs.com/) version 7+
Expand Down
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true
# When modifying this file, please validate using
# curl -X POST --data-binary @codecov.yml https://codecov.io/validate
16 changes: 10 additions & 6 deletions examples/scripts/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ WoT.produce({
const listToDelete = [];
for (const id of countdowns.keys()) {
const as = countdowns.get(id);
if (as.output !== undefined) {
if (as !== undefined && as.output !== undefined) {
const prev = as.output;
as.output--;
console.log("\t" + id + ", from " + prev + " to " + as.output);
Expand Down Expand Up @@ -125,18 +125,22 @@ WoT.produce({
};
const ii = resp;
console.log("init countdown value = " + JSON.stringify(resp));
countdowns.set(resp.href, resp);
countdowns.set(resp.href !== undefined ? resp.href : "", resp);
return ii;
});
thing.setActionHandler("stopCountdown", async (params, options) => {
if (params) {
const value = await params.value();
if (typeof value === "string" && countdowns.has(value)) {
const as = countdowns.get(value);
as.output = 0;
as.status = Status.completed;
console.log("Countdown stopped for href: " + value);
return undefined;
if (as !== undefined) {
as.output = 0;
as.status = Status.completed;
console.log("Countdown stopped for href: " + value);
return null;
} else {
throw Error("Countdown value is undefined for href, " + value);
}
} else {
throw Error("Input provided for stopCountdown is no string or invalid href, " + value);
}
Expand Down
23 changes: 13 additions & 10 deletions examples/scripts/counter-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

function getFormIndexForDecrementWithCoAP(thing) {
var _a;
const forms = (_a = thing.getThingDescription().actions) === null || _a === void 0 ? void 0 : _a.decrement.forms;
if (forms !== undefined) {
for (let i = 0; i < forms.length; i++) {
if (/^coaps?:\/\/.*/.test(forms[i].href)) {
return i;
}
}
}
// return formIndex: 0 if no CoAP target IRI found
return 0;
}
WoTHelpers.fetch("coap://localhost:5683/counter")
.then(async (td) => {
// using await for serial execution (note 'async' in then() of fetch())
Expand Down Expand Up @@ -45,13 +58,3 @@ WoTHelpers.fetch("coap://localhost:5683/counter")
.catch((err) => {
console.error("Fetch error:", err);
});
function getFormIndexForDecrementWithCoAP(thing) {
const forms = thing.getThingDescription().actions.decrement.forms;
for (let i = 0; i < forms.length; i++) {
if (/^coaps?:\/\/.*/.test(forms[i].href)) {
return i;
}
}
// return formIndex: 0 if no CoAP target IRI found
return 0;
}
6 changes: 3 additions & 3 deletions examples/scripts/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ WoT.produce({
let fill = "black";
if (options && typeof options === "object" && "uriVariables" in options) {
console.log("options = " + JSON.stringify(options));
if ("fill" in options.uriVariables) {
if (options.uriVariables && "fill" in options.uriVariables) {
const uriVariables = options.uriVariables;
fill = uriVariables.fill;
}
Expand All @@ -229,7 +229,7 @@ WoT.produce({
let step = 1;
if (options && typeof options === "object" && "uriVariables" in options) {
console.log("options = " + JSON.stringify(options));
if ("step" in options.uriVariables) {
if (options.uriVariables && "step" in options.uriVariables) {
const uriVariables = options.uriVariables;
step = uriVariables.step;
}
Expand All @@ -246,7 +246,7 @@ WoT.produce({
let step = 1;
if (options && typeof options === "object" && "uriVariables" in options) {
console.log("options = " + JSON.stringify(options));
if ("step" in options.uriVariables) {
if (options.uriVariables && "step" in options.uriVariables) {
const uriVariables = options.uriVariables;
step = uriVariables.step;
}
Expand Down
21 changes: 12 additions & 9 deletions examples/scripts/smart-coffee-machine-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
// This is an example of Web of Things consumer ("client" mode) Thing script.
// It considers a fictional smart coffee machine in order to demonstrate the capabilities of Web of Things.
// An accompanying tutorial is available at http://www.thingweb.io/smart-coffee-machine.html.

// Print data and an accompanying message in a distinguishable way
function log(msg, data) {
console.info("======================");
console.info(msg);
console.dir(data);
console.info("======================");
}
WoTHelpers.fetch("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) => {
try {
const thing = await WoT.consume(td);
Expand All @@ -40,7 +48,7 @@ WoTHelpers.fetch("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) =
const makeCoffee = await thing.invokeAction("makeDrink", undefined, {
uriVariables: { drinkId: "latte", size: "l", quantity: 3 },
});
const makeCoffeep = await makeCoffee.value();
const makeCoffeep = await (makeCoffee === null || makeCoffee === void 0 ? void 0 : makeCoffee.value());
if (makeCoffeep.result) {
log("Enjoy your drink!", makeCoffeep);
} else {
Expand All @@ -57,7 +65,9 @@ WoTHelpers.fetch("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) =
time: "10:00",
mode: "everyday",
});
const scheduledTaskp = await scheduledTask.value();
const scheduledTaskp = await (scheduledTask === null || scheduledTask === void 0
? void 0
: scheduledTask.value());
log(scheduledTaskp.message, scheduledTaskp);
// See how it has been added to the schedules property
const schedules = await (await thing.readProperty("schedules")).value();
Expand All @@ -74,10 +84,3 @@ WoTHelpers.fetch("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) =
console.error("Script error:", err);
}
});
// Print data and an accompanying message in a distinguishable way
function log(msg, data) {
console.info("======================");
console.info(msg);
console.dir(data);
console.info("======================");
}
5 changes: 3 additions & 2 deletions examples/security/oauth/consumer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2018 - 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -15,7 +15,8 @@
WoTHelpers.fetch("https://localhost:8080/oauth").then((td) => {
WoT.consume(td).then(async (thing) => {
try {
const result = await (await thing.invokeAction("sayOk")).value();
const resp = await thing.invokeAction("sayOk");
const result = resp === null || resp === void 0 ? void 0 : resp.value();
console.log("oAuth token was", result);
} catch (error) {
console.log("It seems that I couldn't access the resource");
Expand Down
6 changes: 3 additions & 3 deletions examples/testthing/testclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function testPropertyRead(thing, name) {
const value = await res.value();
console.info("PASS " + name + " READ:", value);
} catch (err) {
console.error("FAIL " + name + " READ:", err.message);
console.error("FAIL " + name + " READ:", JSON.stringify(err));
}
}
async function testPropertyWrite(thing, name, value, shouldFail) {
Expand All @@ -35,8 +35,8 @@ async function testPropertyWrite(thing, name, value, shouldFail) {
if (!shouldFail) console.info("PASS " + name + " WRITE (" + displayValue + ")");
else console.error("FAIL " + name + " WRITE: (" + displayValue + ")");
} catch (err) {
if (!shouldFail) console.error("FAIL " + name + " WRITE (" + displayValue + "):", err.message);
else console.info("PASS " + name + " WRITE (" + displayValue + "):", err.message);
if (!shouldFail) console.error("FAIL " + name + " WRITE (" + displayValue + "):", JSON.stringify(err));
else console.info("PASS " + name + " WRITE (" + displayValue + "):", JSON.stringify(err));
}
}
WoTHelpers.fetch("http://localhost:8080/testthing")
Expand Down
34 changes: 26 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/binding-mbus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@node-wot/core": "0.8.8",
"@node-wot/td-tools": "0.8.8",
"node-mbus": "^1.2.2",
"node-mbus": "^2.1.0",
"wot-typescript-definitions": "0.8.0-SNAPSHOT.26"
},
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions packages/binding-modbus/src/modbus-client-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ const warn = createWarnLogger("binding-modbus", "modbus-client-factory");

export default class ModbusClientFactory implements ProtocolClientFactory {
public readonly scheme: string = "modbus+tcp";
private singleton: ModbusClient;
private singleton?: ModbusClient;

public getClient(): ProtocolClient {
debug(`Get client for '${this.scheme}'`);
this.init();
return this.singleton;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- singleton is initialized in init()
return this.singleton!;
}

public init(): boolean {
Expand Down
Loading

0 comments on commit 0163468

Please sign in to comment.