diff --git a/examples/scripts/counter.js b/examples/scripts/counter.js index 842147b31..0f6e0a49e 100644 --- a/examples/scripts/counter.js +++ b/examples/scripts/counter.js @@ -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); + } +); diff --git a/examples/servients/coap-servient/package.json b/examples/servients/coap-servient/package.json index 38c4a7853..3771923d1 100644 --- a/examples/servients/coap-servient/package.json +++ b/examples/servients/coap-servient/package.json @@ -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", diff --git a/packages/binding-coap/package.json b/packages/binding-coap/package.json index cd6129de8..8e032a462 100644 --- a/packages/binding-coap/package.json +++ b/packages/binding-coap/package.json @@ -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 (https://thingweb.io/)", "license": "EPL-2.0 OR W3C-20150513", @@ -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": { diff --git a/packages/binding-file/package.json b/packages/binding-file/package.json index 14afa4f1d..714448486 100644 --- a/packages/binding-file/package.json +++ b/packages/binding-file/package.json @@ -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 (https://thingweb.io/)", "license": "EPL-2.0 OR W3C-20150513", @@ -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", diff --git a/packages/binding-http/package.json b/packages/binding-http/package.json index 0c1411b6b..d65569ed1 100644 --- a/packages/binding-http/package.json +++ b/packages/binding-http/package.json @@ -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 (https://thingweb.io/)", "license": "EPL-2.0 OR W3C-20150513", @@ -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", diff --git a/packages/binding-http/test/TDGenTest.ts b/packages/binding-http/test/TDGenTest.ts deleted file mode 100644 index 77b9e9eba..000000000 --- a/packages/binding-http/test/TDGenTest.ts +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and - * Document License (2015-05-13) which is available at - * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document. - * - * SPDX-License-Identifier: EPL-2.0 OR W3C-20150513 - ********************************************************************************/ - -/** - * Basic test suite for TD parsing - */ - -import { suite, test, slow, timeout, skip, only } from "mocha-typescript"; -import { expect, should } from "chai"; -// should must be called to augment all variables -should(); - -import Servient from "@node-wot/core"; -import ExposedThing from "@node-wot/core"; -import { ContentCodec } from "@node-wot/core"; -import { ProtocolServer } from "@node-wot/core"; -import * as Helpers from "@node-wot/core"; - -import * as TD from "@node-wot/td-tools"; - -import { DataType } from "wot-typescript-definitions"; - -import HttpServer from "../src/http-server"; - -@suite("TD Generation") -class TDGeneratorTest { - // @test "TD generation test"() { - - // let servient: Servient = new Servient(); - // servient.addServer(new HttpServer()); - // servient.start().then(WoT => { - - // let thing: WoT.ExposedThing = WoT.produce({ name: "TDGeneratorTest" }); - - // thing.addProperty("prop1", { - // type: DataType.number // `{ "type": "number" }` - // }); - // thing.addAction("act1", { - // input: { type: DataType.string }// `{ "type": "string" }` - // }); - - // let td: TD.Thing = TD.parseTDString(thing.getThingDescription()); - - // expect(td).to.have.property("name").that.equals("TDGeneratorTest"); - - // let add = Helpers.getAddresses()[0]; - // let ser: Array = servient.getServers(); - - // expect(ser).to.be.an('Array').with.length.above(0) - // expect(td.interaction[0]).to.have.property("name").that.include("prop1"); - // expect(td.interaction[1]).to.have.property("name").that.include("act1"); - // expect(td.interaction[0]).to.have.property("semanticType").that.include("Property"); - // expect(td.interaction[1]).to.have.property("semanticType").that.include("Action"); - - // if (ser[0].getPort() !== -1) { - // expect(td.interaction[0].form[0]).to.have.property("mediaType").that.equals("application/json"); - // expect(td.interaction[0].form[0]).to.have.property("href").that.equals("http://" + add + ":" + ser[0].getPort() + "/TDGeneratorTest/properties/prop1"); - // expect(td.interaction[1].form[0]).to.have.property("mediaType").that.equals("application/json"); - // expect(td.interaction[1].form[0]).to.have.property("href").that.equals("http://" + add + ":" + ser[0].getPort() + "/TDGeneratorTest/actions/act1"); - // } - // }); - // } -} diff --git a/packages/cli/package.json b/packages/cli/package.json index 3d56824dc..b31383936 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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 (https://thingweb.io/)", "license": "EPL-2.0 OR W3C-20150513", @@ -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", diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 79bd979b4..853621108 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -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"; diff --git a/packages/cli/src/default-servient.ts b/packages/cli/src/default-servient.ts index 6108fcd1a..758d1ca81 100644 --- a/packages/cli/src/default-servient.ts +++ b/packages/cli/src/default-servient.ts @@ -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 @@ -60,15 +60,14 @@ export default class DefaultServient extends Servient { /** * start */ - public start(): Promise { + public start(): Promise { - - return new Promise((resolve, reject) => { - super.start().then(WoT => { + return new Promise((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}" @@ -76,17 +75,11 @@ export default class DefaultServient extends Servient { .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", @@ -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", @@ -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}`); diff --git a/packages/core/package.json b/packages/core/package.json index b90baf64e..5173d314e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@node-wot/core", - "version": "0.5.0-SNAPSHOT.0", + "version": "0.5.0-SNAPSHOT.1", "description": "W3C Web of Things (WoT) Servient framework", "author": "Eclipse Thingweb (https://thingweb.io/)", "license": "EPL-2.0 OR W3C-20150513", @@ -16,17 +16,17 @@ "devDependencies": { "@types/chai": "4.0.4", "@types/node": "9.4.1", + "wot-typescript-definitions": "0.5.0-SNAPSHOT.2", "chai": "4.1.2", "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", - "rxjs": "5.4.3", - "wot-typescript-definitions": "0.5.0-SNAPSHOT.1" + "@node-wot/td-tools": "0.5.0-SNAPSHOT.1", + "rxjs": "5.4.3" }, "scripts": { "build": "tsc", diff --git a/packages/core/src/servient.ts b/packages/core/src/servient.ts index cf13835dc..e05f55d59 100644 --- a/packages/core/src/servient.ts +++ b/packages/core/src/servient.ts @@ -15,6 +15,8 @@ import * as vm from "vm"; +import * as WoT from "wot-typescript-definitions"; + import WoTImpl from "./wot-impl"; import ExposedThing from "./exposed-thing"; import { ProtocolClientFactory, ProtocolServer, ResourceListener, ProtocolClient } from "./resource-listeners/protocol-interfaces" diff --git a/packages/core/test/ServerTest.ts b/packages/core/test/ServerTest.ts index ecf3c0452..3cc1d3fac 100644 --- a/packages/core/test/ServerTest.ts +++ b/packages/core/test/ServerTest.ts @@ -26,12 +26,7 @@ import { expect, should } from "chai"; should(); import Servient from "../src/servient"; -import * as listeners from "../src/resource-listeners/all-resource-listeners"; -import { ProtocolServer, Content, ResourceListener } from "../src/resource-listeners/protocol-interfaces" -import ExposedThing from "../src/exposed-thing"; - -// import { ThingProperty } from "../src/consumed-thing"; -import { DataType } from "wot-typescript-definitions"; +import { ProtocolServer, ResourceListener } from "../src/resource-listeners/protocol-interfaces" // implement a testserver to mock a server class TestProtocolServer implements ProtocolServer { diff --git a/packages/demo-servients/package.json b/packages/demo-servients/package.json index 215f51fe8..a594d370e 100644 --- a/packages/demo-servients/package.json +++ b/packages/demo-servients/package.json @@ -1,6 +1,6 @@ { "name": "@node-wot/demo-servients", - "version": "0.5.0-SNAPSHOT.0", + "version": "0.5.0-SNAPSHOT.1", "private": true, "description": "W3C WoT demo Servient for the unpublished version of the monorepo", "author": "Eclipse Thingweb (https://thingweb.io/)", @@ -15,18 +15,18 @@ }, "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", - "rxjs": "5.4.3", - "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", + "rxjs": "5.4.3" }, "scripts": { "build": "tsc", diff --git a/packages/demo-servients/src/raspberry-servient.ts b/packages/demo-servients/src/raspberry-servient.ts index 8f0b52583..9e9cec069 100644 --- a/packages/demo-servients/src/raspberry-servient.ts +++ b/packages/demo-servients/src/raspberry-servient.ts @@ -21,7 +21,7 @@ import _ from "@node-wot/core"; import { Servient } from "@node-wot/core"; import { HttpServer } from "@node-wot/binding-http"; -import { DataType } from "wot-typescript-definitions"; +import * as WoT from "wot-typescript-definitions"; // exposed protocols import { CoapServer } from "@node-wot/binding-coap"; @@ -67,7 +67,7 @@ function main() { servient.addServer(new CoapServer()); // get WoT object for privileged script - servient.start().then( WoT => { + servient.start().then( myWoT => { console.info("RaspberryServient started"); @@ -75,36 +75,32 @@ function main() { let template: WoT.ThingTemplate = { name: "Unicorn" }; - let thing = WoT.produce(template); + let thing = myWoT.produce(template); unicorn = thing; let thingPropertyInitBrightness: WoT.PropertyInit = { // name: "brightness", value: 100, - type: DataType.integer, + type: WoT.DataType.integer, // schema: `{ "type": "integer", "minimum": 0, "maximum": 255 }`, writable: true }; let thingPropertyInitColor: WoT.PropertyInit = { - // name: "color", value: { r: 0, g: 0, b: 0 }, - type: DataType.object, - // schema: `{ - // "type": "object", - // "field": [ - // { "name": "r", "schema": { "type": "integer", "minimum": 0, "maximum": 255 } }, - // { "name": "g", "schema": { "type": "integer", "minimum": 0, "maximum": 255 } }, - // { "name": "b", "schema": { "type": "integer", "minimum": 0, "maximum": 255 } } - // ] - // }`, + type: WoT.DataType.object, +/* properties: { + r: { type: "integer", minimum: 0, maximum: 255 }, + g: { type: "integer", minimum: 0, maximum: 255 }, + b: { type: "integer", minimum: 0, maximum: 255 }, + }, */ writable: true }; let thingActionInitGradient: WoT.ActionInit = { // name: "gradient", - input: {type: DataType.array} + input: {type: WoT.DataType.array} // inputSchema: `{ // "type": "array", // "item": { @@ -121,7 +117,7 @@ function main() { let thingActionInitForce: WoT.ActionInit = { // name: "forceColor", - input: {type: DataType.object} + input: {type: WoT.DataType.object} // inputSchema: `{ // "type": "object", // "field": [ diff --git a/packages/integration-tests/package.json b/packages/integration-tests/package.json index 8c4825630..ac7912ced 100644 --- a/packages/integration-tests/package.json +++ b/packages/integration-tests/package.json @@ -1,18 +1,20 @@ { "name": "@node-wot/integration-tests", - "version": "0.5.0-SNAPSHOT.0", + "version": "0.5.0-SNAPSHOT.1", "private": true, "description": "Integration tests for node-wot (not published)", "author": "Eclipse Thingweb (https://thingweb.io/)", "license": "EPL-2.0 OR W3C-20150513", "repository": "https://github.com/thingweb/node-wot/tree/master/packages/integration-tests", "devDependencies": { - "@node-wot/binding-coap": "0.5.0-SNAPSHOT.0", - "@node-wot/binding-http": "0.5.0-SNAPSHOT.0", - "@node-wot/core": "0.5.0-SNAPSHOT.0", "@types/chai": "4.0.4", "@types/node": "9.4.1", "@types/request-promise": "4.1.41", + "wot-typescript-definitions": "0.5.0-SNAPSHOT.2", + "@node-wot/td-tools": "0.5.0-SNAPSHOT.1", + "@node-wot/core": "0.5.0-SNAPSHOT.1", + "@node-wot/binding-http": "0.5.0-SNAPSHOT.1", + "@node-wot/binding-coap": "0.5.0-SNAPSHOT.1", "chai": "4.1.2", "coap": "0.20.0", "mocha": "3.5.3", @@ -20,7 +22,7 @@ "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" }, "scripts": { diff --git a/packages/integration-tests/test/TDGenTest.ts b/packages/integration-tests/test/TDGenTest.ts new file mode 100644 index 000000000..f0bc3473b --- /dev/null +++ b/packages/integration-tests/test/TDGenTest.ts @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and + * Document License (2015-05-13) which is available at + * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document. + * + * SPDX-License-Identifier: EPL-2.0 OR W3C-20150513 + ********************************************************************************/ + +/** + * Basic test suite for TD parsing + */ + +import { suite, test, slow, timeout, skip, only } from "mocha-typescript"; +import { expect, should } from "chai"; +// should must be called to augment all variables +should(); + +import { Servient, ProtocolServer } from "@node-wot/core"; +import * as Helpers from "@node-wot/core"; + +import * as TD from "@node-wot/td-tools"; + +import { HttpServer } from "@node-wot/binding-http"; + +@suite("TD Generation") +class TDGeneratorTest { + @test async "TD generation test"() { + + let servient: Servient = new Servient(); + servient.addServer(new HttpServer()); + let myWoT = await servient.start(); + + let thing: WoT.ExposedThing = myWoT.produce({ name: "TDGeneratorTest" }); + + thing.addProperty("prop1", { + type: "number" + }); + thing.addAction("act1", { + input: { type: "string" } + }); + + let td: TD.Thing = TD.parseTDString(thing.getThingDescription()); + + expect(td).to.have.property("name").that.equals("TDGeneratorTest"); + + let add = Helpers.getAddresses()[0]; + let ser: Array = servient.getServers(); + + expect(ser).to.be.an('Array').with.length.above(0); + + expect(td.properties).to.have.property("prop1"); + expect(td.actions).to.have.property("act1"); + + if (ser[0].getPort() !== -1) { + expect(td.properties.prop1).to.have.property("forms"); + expect(td.properties.prop1.forms[0]).to.have.property("mediaType").that.equals("application/json"); + expect(td.properties.prop1.forms[0]).to.have.property("href").that.equals("http://" + add + ":" + ser[0].getPort() + "/TDGeneratorTest/properties/prop1"); + expect(td.actions.act1).to.have.property("forms"); + expect(td.actions.act1.forms[0]).to.have.property("mediaType").that.equals("application/json"); + expect(td.actions.act1.forms[0]).to.have.property("href").that.equals("http://" + add + ":" + ser[0].getPort() + "/TDGeneratorTest/actions/act1"); + } + } +} diff --git a/packages/td-tools/package.json b/packages/td-tools/package.json index 5c24b4847..d283c424c 100644 --- a/packages/td-tools/package.json +++ b/packages/td-tools/package.json @@ -1,6 +1,6 @@ { "name": "@node-wot/td-tools", - "version": "0.5.0-SNAPSHOT.0", + "version": "0.5.0-SNAPSHOT.1", "description": "W3C Web of Things (WoT) Thing Description parser, serializer, and other tools", "author": "Eclipse Thingweb (https://thingweb.io/)", "license": "EPL-2.0 OR W3C-20150513", @@ -16,15 +16,15 @@ "devDependencies": { "@types/chai": "4.0.4", "@types/node": "9.4.1", + "wot-typescript-definitions": "0.5.0-SNAPSHOT.2", "chai": "4.1.2", "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": { - "wot-typescript-definitions": "0.5.0-SNAPSHOT.1" }, "scripts": { "build": "tsc", diff --git a/packages/td-tools/src/thing-description.ts b/packages/td-tools/src/thing-description.ts index 1a9e62255..644af47d8 100644 --- a/packages/td-tools/src/thing-description.ts +++ b/packages/td-tools/src/thing-description.ts @@ -14,7 +14,7 @@ ********************************************************************************/ // global W3C WoT Scripting API definitions -import WoT, { WoTFactory } from "wot-typescript-definitions"; +import * as WoT from "wot-typescript-definitions"; export const DEFAULT_HTTP_CONTEXT: string = "http://w3c.github.io/wot/w3c-wot-td-context.jsonld"; export const DEFAULT_HTTPS_CONTEXT: string = "https://w3c.github.io/wot/w3c-wot-td-context.jsonld";