Skip to content

Commit

Permalink
feat: Remove writable and replace it with readOnly and writeOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed Jan 9, 2019
1 parent 1c8df2e commit 96c37f6
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/binding-coap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"@types/chai": "4.0.4",
"@types/node": "10.9.4",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4",
"chai": "4.1.2",
"mocha": "3.5.3",
"mocha-typescript": "1.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/chai": "4.0.4",
"@types/node": "10.9.4",
"@types/request-promise": "4.1.41",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4",
"chai": "4.1.2",
"mocha": "3.5.3",
"mocha-typescript": "1.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-mqtt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/chai": "4.0.4",
"@types/node": "10.9.4",
"@types/request-promise": "4.1.41",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4",
"chai": "4.1.2",
"mocha": "3.5.3",
"mocha-typescript": "1.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-websockets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/chai": "4.0.4",
"@types/node": "10.9.4",
"@types/ws": "5.1.2",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4",
"@node-wot/binding-http": "0.6.0-SNAPSHOT.4",
"@node-wot/td-tools": "0.6.0-SNAPSHOT.4",
"@node-wot/core": "0.6.0-SNAPSHOT.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"devDependencies": {
"@types/node": "10.9.4",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4",
"ts-node": "3.3.0",
"typescript": "2.9.2",
"typescript-standard": "0.3.30"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"@types/chai": "4.0.4",
"@types/node": "10.9.4",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4",
"chai": "4.1.2",
"mocha": "3.5.3",
"mocha-typescript": "1.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-servients/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@types/node": "10.9.4",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4",
"ts-node": "3.3.0",
"typescript": "2.9.2",
"typescript-standard": "0.3.30"
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/chai": "4.0.4",
"@types/node": "10.9.4",
"@types/request-promise": "4.1.41",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4",
"@node-wot/td-tools": "0.6.0-SNAPSHOT.4",
"@node-wot/core": "0.6.0-SNAPSHOT.4",
"@node-wot/binding-http": "0.6.0-SNAPSHOT.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/td-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"typescript-standard": "0.3.30",
"webpack": "4.16.0",
"webpack-command": "^0.4.1",
"wot-typescript-definitions": "0.6.0-SNAPSHOT.3"
"wot-typescript-definitions": "0.6.0-SNAPSHOT.4"
},
"dependencies": {
"is-absolute-url": "2.1.0"
Expand Down
9 changes: 6 additions & 3 deletions packages/td-tools/src/td-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ export function parseTD(td: string, normalize?: boolean): Thing {
if (thing.properties !== undefined && thing.properties instanceof Object) {
for (let propName in thing.properties) {
let prop: WoT.PropertyFragment = thing.properties[propName];
if (prop.writable === undefined || typeof prop.writable !== "boolean") {
prop.writable = false;
if (prop.readOnly === undefined || typeof prop.readOnly !== "boolean") {
prop.readOnly = false;
}
if (prop.observable == undefined || typeof prop.writable !== "boolean") {
if (prop.writeOnly === undefined || typeof prop.writeOnly !== "boolean") {
prop.writeOnly = false;
}
if (prop.observable == undefined || typeof prop.observable !== "boolean") {
prop.observable = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/td-tools/src/thing-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export abstract class ThingInteraction implements WoT.InteractionFragment {
}
/** Implements the Thing Property description */
export class ThingProperty extends ThingInteraction implements WoT.PropertyFragment, WoT.BaseSchema {
writable: boolean;
// writable: boolean;
observable: boolean;
type: string;
}
Expand Down
39 changes: 19 additions & 20 deletions packages/td-tools/test/TDParseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ let tdSample2 = `{
"properties": {
"temperature": {
"type": "number",
"writable": true,
"observable": false,
"forms": [{
"href": "coap://mytemp.example.com:5683/temp",
Expand All @@ -63,7 +62,6 @@ let tdSample3 = `{
"properties": {
"temperature": {
"type": "number",
"writable": true,
"observable": false,
"forms": [{
"href": "temp",
Expand All @@ -72,15 +70,16 @@ let tdSample3 = `{
},
"temperature2": {
"type": "number",
"writable": false,
"readOnly": true,
"observable": false,
"forms": [{
"href": "./temp",
"contentType": "application/json"
}]
},
"humidity": {
"type": "number",
"type": "number",
"readOnly": false,
"forms": [{
"href": "/humid",
"contentType": "application/json"
Expand Down Expand Up @@ -120,7 +119,7 @@ let tdSampleLemonbeatBurlingame = `{
"@type": ["sensor:luminance"],
"sensor:unit": "sensor:Candela",
"type": "number",
"writable": false,
"readOnly": true,
"observable": true,
"forms": [{
"href" : "sensors/luminance",
Expand All @@ -131,7 +130,7 @@ let tdSampleLemonbeatBurlingame = `{
"@type": ["sensor:humidity"],
"sensor:unit": "sensor:Percent",
type": "number",
"writable": false,
"readOnly": true,
"observable": true,
"forms": [{
"href" : "sensors/humidity",
Expand All @@ -142,7 +141,7 @@ let tdSampleLemonbeatBurlingame = `{
"@type": ["sensor:temperature"],
"sensor:unit": "sensor:Celsius",
"type": "number",
"writable": false,
"readOnly": true,
"observable": true,
"forms": [{
"href" : "sensors/temperature",
Expand All @@ -152,7 +151,7 @@ let tdSampleLemonbeatBurlingame = `{
"status": {
"@type": ["actuator:onOffStatus"],
"type": "boolean",
"writable": false,
"readOnly": true,
"observable": true,
"forms": [{
"href" : "fan/status",
Expand Down Expand Up @@ -193,7 +192,7 @@ let tdSampleMetadata1 = `{
"schema": {
"type": "number"
},
"writable": false,
"readOnly": true,
"forms": [{
"href": "temp",
"contentType": "application/json"
Expand All @@ -209,7 +208,7 @@ let tdSimple1 = `{
"name": "MyLampThing",
"properties": {
"status": {
"writable": false,
"readOnly": true,
"observable": false,
"type": "string",
"forms": [{
Expand Down Expand Up @@ -240,7 +239,7 @@ let tdBroken1 = `{
"name": "MyLampThing",
"properties": {
"status": {
"writable": false,
"readOnly": true,
"observable": false,
"type": "string",
"form": [{
Expand Down Expand Up @@ -268,7 +267,7 @@ let tdBroken2 = `{
"name": "MyLampThing",
"properties": {
"status": {
"writable": false,
"readOnly": true,
"observable": false,
"type": "string",
"forms": [{
Expand All @@ -295,7 +294,7 @@ let tdBroken3 = `{
"name": "MyLampThing",
"properties": {
"status": {
"writable": false,
"readOnly": true,
"observable": false,
"type": "string",
"forms": [{
Expand Down Expand Up @@ -382,7 +381,7 @@ class TDParserTest {
expect(thing).to.not.have.property("base");

expect(thing.properties).to.have.property("temperature");
expect(thing.properties["temperature"]).to.have.property("writable").that.equals(false);
expect(thing.properties["temperature"]).to.have.property("readOnly").that.equals(false);
expect(thing.properties["temperature"]).to.have.property("observable").that.equals(false);

expect(thing.properties["temperature"]).to.have.property("forms").to.have.lengthOf(1);
Expand All @@ -400,7 +399,7 @@ class TDParserTest {
expect(thing).to.not.have.property("base");

expect(thing.properties).to.have.property("temperature");
expect(thing.properties["temperature"]).to.have.property("writable").that.equals(true);
expect(thing.properties["temperature"]).to.have.property("readOnly").that.equals(false);
expect(thing.properties["temperature"]).to.have.property("observable").that.equals(false);

expect(thing.properties["temperature"]).to.have.property("forms").to.have.lengthOf(1);
Expand All @@ -418,19 +417,19 @@ class TDParserTest {
expect(thing).to.have.property("base").that.equals("coap://mytemp.example.com:5683/interactions/");

expect(thing.properties).to.have.property("temperature");
expect(thing.properties["temperature"]).to.have.property("writable").that.equals(true);
expect(thing.properties["temperature"]).to.have.property("readOnly").that.equals(false);
expect(thing.properties["temperature"]).to.have.property("observable").that.equals(false);
expect(thing.properties["temperature"]).to.have.property("forms").to.have.lengthOf(1);
expect(thing.properties["temperature"].forms[0]).to.have.property("contentType").that.equals("application/json");

expect(thing.properties).to.have.property("temperature2");
expect(thing.properties["temperature2"]).to.have.property("writable").that.equals(false);
expect(thing.properties["temperature2"]).to.have.property("readOnly").that.equals(true);
expect(thing.properties["temperature2"]).to.have.property("observable").that.equals(false);
expect(thing.properties["temperature2"]).to.have.property("forms").to.have.lengthOf(1);
expect(thing.properties["temperature2"].forms[0]).to.have.property("contentType").that.equals("application/json");

expect(thing.properties).to.have.property("humidity");
expect(thing.properties["humidity"]).to.have.property("writable").that.equals(false);
expect(thing.properties["humidity"]).to.have.property("readOnly").that.equals(false);
expect(thing.properties["humidity"]).to.have.property("observable").that.equals(false);
expect(thing.properties["humidity"]).to.have.property("forms").to.have.lengthOf(1);
expect(thing.properties["humidity"].forms[0]).to.have.property("contentType").that.equals("application/json");
Expand Down Expand Up @@ -492,7 +491,7 @@ class TDParserTest {
expect(thing).to.have.property("reference").that.equals("myTempThing");

expect(thing.properties).to.have.property("myTemp");
expect(thing.properties["myTemp"]).to.have.property("writable").that.equals(false);
expect(thing.properties["myTemp"]).to.have.property("readOnly").that.equals(true);
expect(thing.properties["myTemp"]).to.have.property("observable").that.equals(false);
expect(thing.properties["myTemp"]).to.have.property("forms").to.have.lengthOf(1);
expect(thing.properties["myTemp"].forms[0]).to.have.property("contentType").that.equals("application/json");
Expand Down Expand Up @@ -538,7 +537,7 @@ class TDParserTest {

// console.log(td["@context"]);
expect(thing.properties).to.have.property("status");
expect(thing.properties["status"].writable).equals(false);
expect(thing.properties["status"].readOnly).equals(true);
expect(thing.properties["status"].observable).equals(false);
}

Expand Down

0 comments on commit 96c37f6

Please sign in to comment.