Skip to content

Commit

Permalink
fix: do not require=import wot-typescript-definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
mkovatsc committed Jun 20, 2018
1 parent d261669 commit e5df693
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 205 deletions.
55 changes: 22 additions & 33 deletions examples/scripts/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,48 @@ const NAME_ACTION_DECREMENT = "decrement";
const NAME_ACTION_RESET = "reset";

let thing = WoT.produce({
name: "counter"
name: "counter",
description: "counter example Thing"
});

console.log("Created thing " + thing.name);

thing.addProperty({
name : NAME_PROPERTY_COUNT,
schema : '{ "type": "number"}',
value : 0,
observable : true,
writeable : true
})

thing.addAction({
name : NAME_ACTION_INCREMENT
})

thing.addAction({
name : NAME_ACTION_DECREMENT
})

thing.addAction({
name : NAME_ACTION_RESET
})

thing.setActionHandler(
NAME_ACTION_RESET,
(parameters) => {
console.log("Resetting");
thing.writeProperty(NAME_PROPERTY_COUNT, 0);
}
);
thing.addProperty(NAME_PROPERTY_COUNT, {
type: "integer",
observable: true,
writeable: true,
value: 23
});

thing.addAction(NAME_ACTION_INCREMENT);
thing.setActionHandler(
NAME_ACTION_INCREMENT,
(parameters) => {
console.log("Incrementing");
return thing.readProperty(NAME_PROPERTY_COUNT).then(function(count){
return thing.properties[NAME_PROPERTY_COUNT].get().then( (count) => {
let value = count + 1;
thing.writeProperty(NAME_PROPERTY_COUNT, value);
thing.properties[NAME_PROPERTY_COUNT].set(value);
});
}
);

thing.addAction(NAME_ACTION_DECREMENT);
thing.setActionHandler(
NAME_ACTION_DECREMENT,
(parameters) => {
console.log("Decrementing");
return thing.readProperty(NAME_PROPERTY_COUNT).then(function(count){
return thing.properties[NAME_PROPERTY_COUNT].get().then( (count) => {
let value = count - 1;
thing.writeProperty(NAME_PROPERTY_COUNT, value);
thing.properties[NAME_PROPERTY_COUNT].set(value);
});
}
);

thing.start();
thing.addAction(NAME_ACTION_RESET);
thing.setActionHandler(
NAME_ACTION_RESET,
(parameters) => {
console.log("Resetting");
thing.properties[NAME_PROPERTY_COUNT].set(0);
}
);
2 changes: 1 addition & 1 deletion examples/servients/coap-servient/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"devDependencies": {
"@types/node": "9.4.1",
"typescript": "2.5.2"
"typescript": "2.9.2"
},
"dependencies": {
"wot-typescript-definitions": "0.4.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/binding-coap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-wot/binding-coap",
"version": "0.5.0-SNAPSHOT.0",
"version": "0.5.0-SNAPSHOT.1",
"description": "CoAP client & server protocol binding for node-wot",
"author": "Eclipse Thingweb <[email protected]> (https://thingweb.io/)",
"license": "EPL-2.0 OR W3C-20150513",
Expand All @@ -20,12 +20,12 @@
"mocha": "3.5.3",
"mocha-typescript": "1.1.8",
"ts-node": "3.3.0",
"typescript": "2.5.2",
"typescript": "2.9.2",
"typescript-standard": "0.3.30"
},
"dependencies": {
"@node-wot/td-tools": "0.5.0-SNAPSHOT.0",
"@node-wot/core": "0.5.0-SNAPSHOT.0",
"@node-wot/td-tools": "0.5.0-SNAPSHOT.1",
"@node-wot/core": "0.5.0-SNAPSHOT.1",
"coap": "0.21.0"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions packages/binding-file/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-wot/binding-file",
"version": "0.5.0-SNAPSHOT.0",
"version": "0.5.0-SNAPSHOT.1",
"description": "File client protocol binding for node-wot",
"author": "Eclipse Thingweb <[email protected]> (https://thingweb.io/)",
"license": "EPL-2.0 OR W3C-20150513",
Expand All @@ -15,12 +15,12 @@
"types": "dist/file.d.ts",
"devDependencies": {
"@types/node": "9.4.1",
"typescript": "2.5.2",
"typescript": "2.9.2",
"typescript-standard": "0.3.30"
},
"dependencies": {
"@node-wot/td-tools": "0.5.0-SNAPSHOT.0",
"@node-wot/core": "0.5.0-SNAPSHOT.0"
"@node-wot/td-tools": "0.5.0-SNAPSHOT.1",
"@node-wot/core": "0.5.0-SNAPSHOT.1"
},
"scripts": {
"build": "tsc",
Expand Down
8 changes: 4 additions & 4 deletions packages/binding-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-wot/binding-http",
"version": "0.5.0-SNAPSHOT.0",
"version": "0.5.0-SNAPSHOT.1",
"description": "HTTP client & server protocol binding for node-wot",
"author": "Eclipse Thingweb <[email protected]> (https://thingweb.io/)",
"license": "EPL-2.0 OR W3C-20150513",
Expand All @@ -23,12 +23,12 @@
"request": "2.79.0",
"request-promise": "4.2.2",
"ts-node": "3.3.0",
"typescript": "2.5.2",
"typescript": "2.9.2",
"typescript-standard": "0.3.30"
},
"dependencies": {
"@node-wot/td-tools": "0.5.0-SNAPSHOT.0",
"@node-wot/core": "0.5.0-SNAPSHOT.0"
"@node-wot/td-tools": "0.5.0-SNAPSHOT.1",
"@node-wot/core": "0.5.0-SNAPSHOT.1"
},
"scripts": {
"build": "tsc",
Expand Down
75 changes: 0 additions & 75 deletions packages/binding-http/test/TDGenTest.ts

This file was deleted.

16 changes: 8 additions & 8 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-wot/cli",
"version": "0.5.0-SNAPSHOT.0",
"version": "0.5.0-SNAPSHOT.1",
"description": "servient command line interface",
"author": "Eclipse Thingweb <[email protected]> (https://thingweb.io/)",
"license": "EPL-2.0 OR W3C-20150513",
Expand All @@ -18,17 +18,17 @@
},
"devDependencies": {
"@types/node": "9.4.1",
"wot-typescript-definitions": "0.5.0-SNAPSHOT.2",
"ts-node": "3.3.0",
"typescript": "2.5.2",
"typescript": "2.9.2",
"typescript-standard": "0.3.30"
},
"dependencies": {
"@node-wot/binding-coap": "0.5.0-SNAPSHOT.0",
"@node-wot/binding-file": "0.5.0-SNAPSHOT.0",
"@node-wot/binding-http": "0.5.0-SNAPSHOT.0",
"@node-wot/core": "0.5.0-SNAPSHOT.0",
"@node-wot/td-tools": "0.5.0-SNAPSHOT.0",
"wot-typescript-definitions": "0.5.0-SNAPSHOT.1"
"@node-wot/binding-coap": "0.5.0-SNAPSHOT.1",
"@node-wot/binding-file": "0.5.0-SNAPSHOT.1",
"@node-wot/binding-http": "0.5.0-SNAPSHOT.1",
"@node-wot/core": "0.5.0-SNAPSHOT.1",
"@node-wot/td-tools": "0.5.0-SNAPSHOT.1"
},
"scripts": {
"build": "tsc",
Expand Down
6 changes: 0 additions & 6 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

// global W3C WoT Scripting API definitions
// using core definitions instead of 'wot-typescript-definitions' to avoid typing error
import _ from "@node-wot/core";
// node-wot implementation of W3C WoT Servient
import { Servient } from "@node-wot/core";

// default implementation of W3C WoT Servient (http(s) and file bindings)
import DefaultServient from "./default-servient";

Expand Down
39 changes: 14 additions & 25 deletions packages/cli/src/default-servient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
********************************************************************************/

// global W3C WoT Scripting API definitions
import _, { WoTFactory, ThingProperty, DataType } from "wot-typescript-definitions";
import * as WoT from "wot-typescript-definitions";
// node-wot implementation of W3C WoT Servient
import Servient from "@node-wot/core";
// protocols used
Expand Down Expand Up @@ -60,33 +60,26 @@ export default class DefaultServient extends Servient {
/**
* start
*/
public start(): Promise<WoTFactory> {
public start(): Promise<WoT.WoTFactory> {


return new Promise<WoTFactory>((resolve, reject) => {
super.start().then(WoT => {
return new Promise<WoT.WoTFactory>((resolve, reject) => {
super.start().then(myWoT => {
console.info("DefaultServient started");

// TODO think about builder pattern that starts with produce() ends with expose(), which exposes/publishes the Thing
let thing = WoT.produce(`{
let thing = myWoT.produce(`{
"name": "servient",
"description": "node-wot CLI Servient",
"system": "${process.arch}"
}`)
.addProperty("things", {
writable: true,
observable: false,
value: undefined,
type: DataType.string
// name: "things",
// schema: `{ "type": "array", "items": { "type": "string" } }`,
type: "string"
})
.addAction("log", {
input: { type: DataType.string},
output: { type: DataType.string}
// name: "log",
// inputSchema: `{ "type": "string" }`,
// outputSchema: `{ "type": "string" }`
input: { type: "string" },
output: { type: "string" }
})
.setActionHandler(
"log",
Expand All @@ -98,9 +91,7 @@ export default class DefaultServient extends Servient {
}
)
.addAction("shutdown", {
output: { type: DataType.string}
// name: "shutdown",
// outputSchema: `{ "type": "string" }`
output: { type: "string" }
})
.setActionHandler(
"shutdown",
Expand All @@ -116,25 +107,23 @@ export default class DefaultServient extends Servient {
if (this.config.servient.scriptAction) {
thing
.addAction("runScript", {
input: { type: DataType.string},
output: { type: DataType.string}
// name: "runScript",
// inputSchema: `{ "type": "string" }`,
// outputSchema: `{ "type": "string" }`
input: { type: "string" },
output: { type: "string" }
})
.setActionHandler(
"runScript",
(script: string) => {
return new Promise((resolve, reject) => {
console.log("runnig script", script);
resolve(this.runScript(script));
this.runScript(script);
resolve();
});
}
);
}

// pass WoTFactory on
resolve(WoT);
resolve(myWoT);

}).catch(err => {
console.trace(`error building CLI Management Thing: ${err}`);
Expand Down
Loading

0 comments on commit e5df693

Please sign in to comment.