@node-wot/core
Advanced tools
Comparing version 0.7.6 to 0.7.7
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var float16_1 = require("@petamoriken/float16"); | ||
var OctetstreamCodec = (function () { | ||
@@ -10,2 +11,3 @@ function OctetstreamCodec() { | ||
OctetstreamCodec.prototype.bytesToValue = function (bytes, schema, parameters) { | ||
var _a; | ||
var bigendian = parameters.byteorder ? parameters.byteorder === "bigendian" : true; | ||
@@ -16,7 +18,20 @@ var signed = parameters.signed ? parameters.signed === "true" : false; | ||
} | ||
switch (schema.type) { | ||
var dataLength = bytes.length; | ||
var dataType = schema.type; | ||
if (/(short|(u)?int(8|16|32)?$|float(16|32|64)?|byte)/.test(dataType.toLowerCase())) { | ||
var typeSem = /(u)?(short|int|float|byte)(8|16|32|64)?/.exec(dataType.toLowerCase()); | ||
if (typeSem) { | ||
signed = typeSem[1] === undefined; | ||
dataType = typeSem[2]; | ||
dataLength = (_a = +typeSem[3] / 8, (_a !== null && _a !== void 0 ? _a : bytes.length)); | ||
} | ||
} | ||
switch (dataType) { | ||
case "boolean": | ||
return !bytes.every(function (val) { return val == 0; }); | ||
case "byte": | ||
case "short": | ||
case "int": | ||
case "integer": | ||
switch (bytes.length) { | ||
switch (dataLength) { | ||
case 1: | ||
@@ -39,6 +54,6 @@ return signed ? bytes.readInt8(0) : bytes.readUInt8(0); | ||
result = bytes.reduceRight(function (prev, curr, ix, arr) { return prev << 8 + curr; }); | ||
negative = bytes.readInt8(bytes.length - 1) < 0; | ||
negative = bytes.readInt8(dataLength - 1) < 0; | ||
} | ||
if (signed && negative) { | ||
result -= 1 << (8 * bytes.length); | ||
result -= 1 << (8 * dataLength); | ||
} | ||
@@ -50,4 +65,8 @@ if (!Number.isSafeInteger(result)) { | ||
} | ||
case "float": | ||
case "double": | ||
case "number": | ||
switch (bytes.length) { | ||
switch (dataLength) { | ||
case 2: | ||
return float16_1.getFloat16(new DataView(bytes.buffer), bytes.byteOffset, !bigendian); | ||
case 4: | ||
@@ -58,3 +77,3 @@ return bigendian ? bytes.readFloatBE(0) : bytes.readFloatLE(0); | ||
default: | ||
throw new Error("Wrong buffer length for type 'number', must be 4 or 8, is " + bytes.length); | ||
throw new Error("Wrong buffer length for type 'number', must be 2, 4, 8, or is " + dataLength); | ||
} | ||
@@ -65,15 +84,15 @@ case "string": | ||
case "object": | ||
throw new Error("Unable to handle object type " + schema.type); | ||
throw new Error("Unable to handle object type " + dataType); | ||
case "null": | ||
return null; | ||
} | ||
throw new Error("Unknown object type"); | ||
}; | ||
OctetstreamCodec.prototype.valueToBytes = function (value, schema, parameters) { | ||
if (parameters.length === null) { | ||
throw new Error("Missing 'length' parameter necessary for write"); | ||
var _a; | ||
if (!parameters.length) { | ||
console.warn("[core/octetstream-codec]", "Missing 'length' parameter necessary for write. I'll do my best"); | ||
} | ||
var bigendian = parameters.byteorder ? parameters.byteorder === "bigendian" : true; | ||
var signed = parameters.signed ? parameters.signed === "true" : false; | ||
var length = parseInt(parameters.length); | ||
var signed = parameters.signed ? parameters.signed === "true" : true; | ||
var length = parameters.length ? parseInt(parameters.length) : undefined; | ||
var buf; | ||
@@ -83,6 +102,19 @@ if (value === undefined) { | ||
} | ||
switch (schema.type) { | ||
var dataType = schema.type; | ||
if (/(short|(u)?int(8|16|32)?$|float(16|32|64)?|byte)/.test(dataType.toLowerCase())) { | ||
var typeSem = /(u)?(short|int|float|byte)(8|16|32|64)?/.exec(dataType.toLowerCase()); | ||
if (typeSem) { | ||
signed = typeSem[1] === undefined; | ||
dataType = typeSem[2]; | ||
length = (_a = +typeSem[3] / 8, (_a !== null && _a !== void 0 ? _a : length)); | ||
} | ||
} | ||
switch (dataType) { | ||
case "boolean": | ||
return Buffer.alloc(length, value ? 255 : 0); | ||
case "byte": | ||
case "short": | ||
case "int": | ||
case "integer": | ||
length = (length !== null && length !== void 0 ? length : 4); | ||
if (typeof value !== "number") { | ||
@@ -94,4 +126,5 @@ throw new Error("Value is not a number"); | ||
} | ||
var limit = Math.pow(2, 8 * length) - 1; | ||
if (signed) { | ||
if (value < -(1 << 8 * length - 1) || value >= (1 << 8 * length - 1)) { | ||
if (value < -limit || value >= limit) { | ||
throw new Error("Integer overflow when representing signed " + value + " in " + length + " byte(s)"); | ||
@@ -101,3 +134,3 @@ } | ||
else { | ||
if (value < 0 || value >= (1 << 8 * length)) { | ||
if (value < 0 || value >= limit) { | ||
throw new Error("Integer overflow when representing unsigned " + value + " in " + length + " byte(s)"); | ||
@@ -130,2 +163,3 @@ } | ||
return buf; | ||
case "float": | ||
case "number": | ||
@@ -135,4 +169,8 @@ if (typeof value !== "number") { | ||
} | ||
length = (length !== null && length !== void 0 ? length : 8); | ||
buf = Buffer.alloc(length); | ||
switch (length) { | ||
case 2: | ||
float16_1.setFloat16(new DataView(buf.buffer), 0, value, !bigendian); | ||
break; | ||
case 4: | ||
@@ -153,7 +191,6 @@ bigendian ? buf.writeFloatBE(value, 0) : buf.writeFloatLE(value, 0); | ||
case "object": | ||
throw new Error("Unable to handle object type " + schema.type); | ||
throw new Error("Unable to handle object type " + dataType); | ||
case "null": | ||
return null; | ||
} | ||
throw new Error("Unknown object type"); | ||
}; | ||
@@ -160,0 +197,0 @@ return OctetstreamCodec; |
@@ -71,4 +71,21 @@ "use strict"; | ||
ExposedThing.prototype.destroy = function () { | ||
var _this = this; | ||
console.debug("[core/exposed-thing]", "ExposedThing '" + this.title + "' destroying the thing and its interactions"); | ||
return new Promise(function (resolve, reject) { | ||
resolve(); | ||
_this.getServient().destroyThing(_this.id).then(function () { | ||
for (var propertyName in _this.properties) { | ||
var ps = _this.properties[propertyName].getState(); | ||
if (ps.subject) { | ||
ps.subject.complete(); | ||
} | ||
} | ||
for (var eventName in _this.events) { | ||
var es = _this.events[eventName].getState(); | ||
if (es.subject) { | ||
es.subject.complete(); | ||
} | ||
} | ||
_this.getSubjectTD().next(null); | ||
resolve(); | ||
}).catch(function (err) { return reject(err); }); | ||
}); | ||
@@ -75,0 +92,0 @@ }; |
@@ -25,2 +25,3 @@ /// <reference types="node" /> | ||
expose(thing: ExposedThing, tdTemplate?: WoT.ThingDescription): Promise<void>; | ||
destroy(thingId: string): Promise<boolean>; | ||
start(servient: Servient): Promise<void>; | ||
@@ -27,0 +28,0 @@ stop(): Promise<void>; |
@@ -18,2 +18,3 @@ import { CompilerFunction } from "vm2"; | ||
addThing(thing: ExposedThing): boolean; | ||
destroyThing(thingId: string): Promise<boolean>; | ||
getThing(id: string): ExposedThing; | ||
@@ -20,0 +21,0 @@ getThings(): object; |
@@ -126,2 +126,18 @@ "use strict"; | ||
}; | ||
Servient.prototype.destroyThing = function (thingId) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
if (_this.things.has(thingId)) { | ||
console.debug("[core/servient]", "Servient destroying thing with id '" + thingId + "'"); | ||
_this.things.delete(thingId); | ||
var serverPromises_1 = []; | ||
_this.servers.forEach(function (server) { serverPromises_1.push(server.destroy(thingId)); }); | ||
Promise.all(serverPromises_1).then(function () { return resolve(true); }).catch(function (err) { return reject(err); }); | ||
} | ||
else { | ||
console.warn("[core/servient]", "Servient was asked to destroy thing but failed to find thing with id '" + thingId + "'"); | ||
resolve(false); | ||
} | ||
}); | ||
}; | ||
Servient.prototype.getThing = function (id) { | ||
@@ -128,0 +144,0 @@ if (this.things.has(id)) { |
{ | ||
"name": "@node-wot/core", | ||
"version": "0.7.6", | ||
"version": "0.7.7", | ||
"description": "W3C Web of Things (WoT) Servient framework", | ||
@@ -27,9 +27,10 @@ "author": "Eclipse Thingweb <thingweb-dev@eclipse.org> (https://thingweb.io/)", | ||
"dependencies": { | ||
"wot-typescript-definitions": "0.7.3", | ||
"@node-wot/td-tools": "0.7.6", | ||
"uuid": "3.4.0", | ||
"@node-wot/td-tools": "0.7.7", | ||
"@petamoriken/float16": "^3.1.1", | ||
"@types/uritemplate": "0.3.4", | ||
"rxjs": "5.5.11", | ||
"uritemplate": "0.3.4", | ||
"@types/uritemplate": "0.3.4", | ||
"vm2": "^3.9.2" | ||
"uuid": "3.4.0", | ||
"vm2": "^3.9.2", | ||
"wot-typescript-definitions": "0.7.3" | ||
}, | ||
@@ -36,0 +37,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
174120
2349
8
+ Added@petamoriken/float16@^3.1.1
+ Added@node-wot/td-tools@0.7.7(transitive)
+ Added@petamoriken/float16@3.8.7(transitive)
- Removed@node-wot/td-tools@0.7.6(transitive)
Updated@node-wot/td-tools@0.7.7