Socket
Socket
Sign inDemoInstall

@node-wot/core

Package Overview
Dependencies
23
Maintainers
5
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.12 to 0.8.13

81

dist/codecs/octetstream-codec.js

@@ -15,9 +15,29 @@ "use strict";

debug("Parameters", parameters);
const bigEndian = !(((_a = parameters.byteSeq) === null || _a === void 0 ? void 0 : _a.includes(protocol_interfaces_1.Endianness.LITTLE_ENDIAN)) === true);
let signed = parameters.signed !== "false";
const length = parameters.length != null
? parseInt(parameters.length)
: (warn("Missing 'length' parameter necessary for write. I'll do my best"), undefined);
if (length !== undefined) {
if (isNaN(length) || length < 0) {
throw new Error("'length' parameter must be a non-negative number");
}
if (length !== bytes.length) {
throw new Error(`Lengths do not match, required: ${length} provided: ${bytes.length}`);
}
}
let signed = true;
if (parameters.signed !== undefined) {
if (parameters.signed !== "true" && parameters.signed !== "false") {
throw new Error("'signed' parameter must be 'true' or 'false'");
}
signed = parameters.signed === "true";
}
let bitLength = (schema === null || schema === void 0 ? void 0 : schema["ex:bitLength"]) !== undefined ? parseInt(schema["ex:bitLength"]) : bytes.length * 8;
if (isNaN(bitLength) || bitLength < 0) {
throw new Error("'ex:bitLength' must be a non-negative number");
}
const offset = (schema === null || schema === void 0 ? void 0 : schema["ex:bitOffset"]) !== undefined ? parseInt(schema["ex:bitOffset"]) : 0;
if (parameters.length != null && parseInt(parameters.length) !== bytes.length) {
throw new Error("Lengths do not match, required: " + parameters.length + " provided: " + bytes.length);
if (isNaN(offset) || offset < 0) {
throw new Error("'ex:bitOffset' must be a non-negative number");
}
let bitLength = (schema === null || schema === void 0 ? void 0 : schema["ex:bitLength"]) !== undefined ? parseInt(schema["ex:bitLength"]) : bytes.length * 8;
const bigEndian = !(((_a = parameters.byteSeq) === null || _a === void 0 ? void 0 : _a.includes(protocol_interfaces_1.Endianness.LITTLE_ENDIAN)) === true);
let dataType = schema === null || schema === void 0 ? void 0 : schema.type;

@@ -135,3 +155,4 @@ if (!dataType) {

const propertySchema = schema.properties[propertyName];
result[propertyName] = this.bytesToValue(bytes, propertySchema, parameters);
const length = bytes.length.toString();
result[propertyName] = this.bytesToValue(bytes, propertySchema, Object.assign(Object.assign({}, parameters), { length }));
}

@@ -143,10 +164,24 @@ return result;

debug(`OctetstreamCodec serializing '${value}'`);
if (parameters.length == null) {
warn("Missing 'length' parameter necessary for write. I'll do my best");
const bigEndian = !(((_a = parameters.byteSeq) === null || _a === void 0 ? void 0 : _a.includes(protocol_interfaces_1.Endianness.LITTLE_ENDIAN)) === true);
let signed = true;
if (parameters.signed !== undefined) {
if (parameters.signed !== "true" && parameters.signed !== "false") {
throw new Error("'signed' parameter must be 'true' or 'false'");
}
signed = parameters.signed === "true";
}
const bigEndian = !(((_a = parameters.byteSeq) === null || _a === void 0 ? void 0 : _a.includes(protocol_interfaces_1.Endianness.LITTLE_ENDIAN)) === true);
let signed = parameters.signed !== "false";
let length = parameters.length != null ? parseInt(parameters.length) : undefined;
let length = parameters.length != null
? parseInt(parameters.length)
: (warn("Missing 'length' parameter necessary for write. I'll do my best"), undefined);
if (length !== undefined && (isNaN(length) || length < 0)) {
throw new Error("'length' parameter must be a non-negative number");
}
let bitLength = (schema === null || schema === void 0 ? void 0 : schema["ex:bitLength"]) !== undefined ? parseInt(schema["ex:bitLength"]) : undefined;
if (bitLength !== undefined && (isNaN(bitLength) || bitLength < 0)) {
throw new Error("'ex:bitLength' must be a non-negative number");
}
const offset = (schema === null || schema === void 0 ? void 0 : schema["ex:bitOffset"]) !== undefined ? parseInt(schema["ex:bitOffset"]) : 0;
if (isNaN(offset) || offset < 0) {
throw new Error("'ex:bitOffset' must be a non-negative number");
}
let dataType = (_b = schema === null || schema === void 0 ? void 0 : schema.type) !== null && _b !== void 0 ? _b : undefined;

@@ -267,9 +302,13 @@ if (value === undefined) {

if (signed) {
if (value < -limit - 1 || value >= limit) {
throw new Error("Integer overflow when representing signed " + value + " in " + length + " bit(s)");
if (value < -limit - 1 || value > limit) {
throw new Error("Integer overflow when representing " + value + " as a signed integer using " + length + " bit(s)");
}
}
else {
if (value < 0 || value >= limit) {
throw new Error("Integer overflow when representing unsigned " + value + " in " + length + " bit(s)");
if (value < 0 || value > limit) {
throw new Error("Integer overflow when representing " +
value +
" as an unsigned integer using " +
length +
" bit(s)");
}

@@ -384,3 +423,11 @@ }

}
result = result !== null && result !== void 0 ? result : Buffer.alloc(parseInt(parameters.length));
const length = parseInt(parameters.length);
const offset = schema["ex:bitOffset"] !== undefined ? parseInt(schema["ex:bitOffset"]) : 0;
if (isNaN(offset) || offset < 0) {
throw new Error("'ex:bitOffset' must be a non-negative number");
}
if (offset > length * 8) {
throw new Error(`'ex:bitOffset' ${offset} exceeds 'length' ${length}`);
}
result = result !== null && result !== void 0 ? result : Buffer.alloc(length);
for (const propertyName in schema.properties) {

@@ -401,3 +448,3 @@ if (Object.hasOwnProperty.call(value, propertyName) === false) {

}
this.copyBits(buf, propertyOffset, result, propertyOffset, propertyLength);
this.copyBits(buf, propertyOffset, result, offset + propertyOffset, propertyLength);
}

@@ -404,0 +451,0 @@ return result;

@@ -38,2 +38,3 @@ import { ConsumedThing as IConsumedThing, InteractionInput, Subscription } from "wot-typescript-definitions";

readProperty(propertyName: string, options?: WoT.InteractionOptions): Promise<WoT.InteractionOutput>;
private handleInteractionOutput;
_readProperties(propertyNames: string[]): Promise<WoT.PropertyReadMap>;

@@ -40,0 +41,0 @@ readAllProperties(options?: WoT.InteractionOptions): Promise<WoT.PropertyReadMap>;

@@ -52,2 +52,3 @@ "use strict";

const helpers_1 = __importDefault(require("./helpers"));
const content_type_1 = __importDefault(require("content-type"));
const content_serdes_1 = __importDefault(require("./content-serdes"));

@@ -408,5 +409,23 @@ const UriTemplate = require("uritemplate");

const content = yield client.readResource(form);
return new interaction_output_1.InteractionOutput(content, form, tp);
try {
return this.handleInteractionOutput(content, form, tp);
}
catch (e) {
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
throw new Error(`Error while processing property for ${tp.title}. ${error.message}`);
}
});
}
handleInteractionOutput(content, form, outputDataSchema) {
var _a, _b;
(_a = content.type) !== null && _a !== void 0 ? _a : (content.type = (_b = form.contentType) !== null && _b !== void 0 ? _b : "application/json");
if (form.response != null) {
const parsedMediaTypeContent = content_type_1.default.parse(content.type);
const parsedMediaTypeForm = content_type_1.default.parse(form.response.contentType);
if (parsedMediaTypeContent.type !== parsedMediaTypeForm.type) {
throw new Error(`Unexpected type '${content.type}' in response. Should be '${form.response.contentType}'`);
}
}
return new interaction_output_1.InteractionOutput(content, form, outputDataSchema);
}
_readProperties(propertyNames) {

@@ -482,3 +501,2 @@ return __awaiter(this, void 0, void 0, function* () {

invokeAction(actionName, parameter, options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {

@@ -503,14 +521,8 @@ const ta = this.actions[actionName];

const content = yield client.invokeResource(form, input);
if (!content.type)
content.type = (_a = form.contentType) !== null && _a !== void 0 ? _a : "application/json";
if (form.response != null) {
if (content.type !== form.response.contentType) {
throw new Error(`Unexpected type in response`);
}
}
try {
return new interaction_output_1.InteractionOutput(content, form, ta.output);
return this.handleInteractionOutput(content, form, ta.output);
}
catch (_b) {
throw new Error(`Received invalid content from Thing`);
catch (e) {
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
throw new Error(`Error while processing action for ${ta.title}. ${error.message}`);
}

@@ -538,10 +550,8 @@ });

yield client.subscribeResource(formWithoutURITemplates, (content) => {
var _a;
if (!content.type)
content.type = (_a = form.contentType) !== null && _a !== void 0 ? _a : "application/json";
try {
listener(new interaction_output_1.InteractionOutput(content, form, tp));
listener(this.handleInteractionOutput(content, form, tp));
}
catch (e) {
warn(`Error while processing observe event for ${tp.title}`);
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
warn(`Error while processing observe property for ${tp.title}. ${error.message}`);
warn(e);

@@ -577,10 +587,8 @@ }

yield client.subscribeResource(formWithoutURITemplates, (content) => {
var _a;
if (!content.type)
content.type = (_a = form.contentType) !== null && _a !== void 0 ? _a : "application/json";
try {
listener(new interaction_output_1.InteractionOutput(content, form, te.data));
listener(this.handleInteractionOutput(content, form, te.data));
}
catch (e) {
warn(`Error while processing event for ${te.title}`);
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
warn(`Error while processing event for ${te.title}. ${error.message}`);
warn(e);

@@ -587,0 +595,0 @@ }

@@ -42,2 +42,3 @@ "use strict";

const ajv_1 = __importDefault(require("ajv"));
const ajv_formats_1 = __importDefault(require("ajv-formats"));
const td_json_schema_validation_json_1 = __importDefault(require("wot-thing-description-types/schema/td-json-schema-validation.json"));

@@ -48,6 +49,4 @@ const td_tools_1 = require("@node-wot/td-tools");

const tdSchema = td_json_schema_validation_json_1.default;
const ajv = new ajv_1.default({ strict: false })
.addFormat("iri-reference", /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i)
.addFormat("uri", /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/)
.addFormat("date-time", /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/);
const ajv = new ajv_1.default({ strict: false });
(0, ajv_formats_1.default)(ajv);
class Helpers {

@@ -54,0 +53,0 @@ constructor(srv) {

@@ -56,5 +56,7 @@ "use strict";

const ajv_1 = __importDefault(require("ajv"));
const ajv_formats_1 = __importDefault(require("ajv-formats"));
const logger_1 = require("./logger");
const { debug } = (0, logger_1.createLoggers)("core", "interaction-output");
const { debug, warn } = (0, logger_1.createLoggers)("core", "interaction-output");
const ajv = new ajv_1.default({ strict: false });
(0, ajv_formats_1.default)(ajv);
class InteractionOutput {

@@ -97,2 +99,6 @@ constructor(content, form, schema) {

return __awaiter(this, void 0, void 0, function* () {
if (this.schema == null) {
warn(`No schema defined. Hence undefined is reported for value() function. If you are invoking an action with no output that is on purpose, otherwise consider using arrayBuffer().`);
return undefined;
}
if (__classPrivateFieldGet(this, _InteractionOutput_value, "f") !== undefined) {

@@ -107,4 +113,4 @@ return __classPrivateFieldGet(this, _InteractionOutput_value, "f");

}
if (this.schema == null || this.schema.type == null) {
throw new errors_1.NotReadableError("No schema defined");
if (this.schema.type == null) {
throw new errors_1.NotReadableError("No schema type defined");
}

@@ -111,0 +117,0 @@ if (!content_serdes_1.ContentSerdes.get().isSupported(__classPrivateFieldGet(this, _InteractionOutput_content, "f").type)) {

{
"name": "@node-wot/core",
"version": "0.8.12",
"version": "0.8.13",
"description": "W3C Web of Things (WoT) Servient framework",

@@ -18,2 +18,3 @@ "author": "Eclipse Thingweb <thingweb-dev@eclipse.org> (https://thingweb.io/)",

"devDependencies": {
"@types/content-type": "^1.1.8",
"@types/debug": "^4.1.7",

@@ -24,6 +25,8 @@ "@types/uritemplate": "^0.3.4",

"dependencies": {
"@node-wot/td-tools": "0.8.12",
"@node-wot/td-tools": "0.8.13",
"@petamoriken/float16": "^3.1.1",
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"cbor": "^8.1.0",
"content-type": "^1.0.5",
"debug": "^4.3.4",

@@ -30,0 +33,0 @@ "uritemplate": "0.3.4",

@@ -62,10 +62,37 @@ /********************************************************************************

const bigEndian = !(parameters.byteSeq?.includes(Endianness.LITTLE_ENDIAN) === true); // default to big endian
let signed = parameters.signed !== "false"; // default to signed
const length =
parameters.length != null
? parseInt(parameters.length)
: (warn("Missing 'length' parameter necessary for write. I'll do my best"), undefined);
if (length !== undefined) {
if (isNaN(length) || length < 0) {
throw new Error("'length' parameter must be a non-negative number");
}
if (length !== bytes.length) {
throw new Error(`Lengths do not match, required: ${length} provided: ${bytes.length}`);
}
}
let signed = true; // default to signed
if (parameters.signed !== undefined) {
if (parameters.signed !== "true" && parameters.signed !== "false") {
throw new Error("'signed' parameter must be 'true' or 'false'");
}
signed = parameters.signed === "true";
}
let bitLength = schema?.["ex:bitLength"] !== undefined ? parseInt(schema["ex:bitLength"]) : bytes.length * 8;
if (isNaN(bitLength) || bitLength < 0) {
throw new Error("'ex:bitLength' must be a non-negative number");
}
const offset = schema?.["ex:bitOffset"] !== undefined ? parseInt(schema["ex:bitOffset"]) : 0;
if (parameters.length != null && parseInt(parameters.length) !== bytes.length) {
throw new Error("Lengths do not match, required: " + parameters.length + " provided: " + bytes.length);
if (isNaN(offset) || offset < 0) {
throw new Error("'ex:bitOffset' must be a non-negative number");
}
let bitLength: number =
schema?.["ex:bitLength"] !== undefined ? parseInt(schema["ex:bitLength"]) : bytes.length * 8;
const bigEndian = !(parameters.byteSeq?.includes(Endianness.LITTLE_ENDIAN) === true); // default to big endian
let dataType: string = schema?.type;

@@ -218,3 +245,4 @@

const propertySchema = schema.properties[propertyName];
result[propertyName] = this.bytesToValue(bytes, propertySchema, parameters);
const length = bytes.length.toString();
result[propertyName] = this.bytesToValue(bytes, propertySchema, { ...parameters, length });
}

@@ -227,12 +255,34 @@ return result;

if (parameters.length == null) {
warn("Missing 'length' parameter necessary for write. I'll do my best");
const bigEndian = !(parameters.byteSeq?.includes(Endianness.LITTLE_ENDIAN) === true); // default to big endian
let signed = true; // default to true
if (parameters.signed !== undefined) {
if (parameters.signed !== "true" && parameters.signed !== "false") {
throw new Error("'signed' parameter must be 'true' or 'false'");
}
signed = parameters.signed === "true";
}
const bigEndian = !(parameters.byteSeq?.includes(Endianness.LITTLE_ENDIAN) === true); // default to big endian
let signed = parameters.signed !== "false"; // default to signed
// byte length of the buffer to be returned
let length = parameters.length != null ? parseInt(parameters.length) : undefined;
let length =
parameters.length != null
? parseInt(parameters.length)
: (warn("Missing 'length' parameter necessary for write. I'll do my best"), undefined);
if (length !== undefined && (isNaN(length) || length < 0)) {
throw new Error("'length' parameter must be a non-negative number");
}
let bitLength = schema?.["ex:bitLength"] !== undefined ? parseInt(schema["ex:bitLength"]) : undefined;
if (bitLength !== undefined && (isNaN(bitLength) || bitLength < 0)) {
throw new Error("'ex:bitLength' must be a non-negative number");
}
const offset = schema?.["ex:bitOffset"] !== undefined ? parseInt(schema["ex:bitOffset"]) : 0;
if (isNaN(offset) || offset < 0) {
throw new Error("'ex:bitOffset' must be a non-negative number");
}
let dataType: string = schema?.type ?? undefined;

@@ -377,8 +427,16 @@

if (signed) {
if (value < -limit - 1 || value >= limit) {
throw new Error("Integer overflow when representing signed " + value + " in " + length + " bit(s)");
if (value < -limit - 1 || value > limit) {
throw new Error(
"Integer overflow when representing " + value + " as a signed integer using " + length + " bit(s)"
);
}
} else {
if (value < 0 || value >= limit) {
throw new Error("Integer overflow when representing unsigned " + value + " in " + length + " bit(s)");
if (value < 0 || value > limit) {
throw new Error(
"Integer overflow when representing " +
value +
" as an unsigned integer using " +
length +
" bit(s)"
);
}

@@ -541,3 +599,14 @@ }

result = result ?? Buffer.alloc(parseInt(parameters.length));
const length = parseInt(parameters.length);
const offset = schema["ex:bitOffset"] !== undefined ? parseInt(schema["ex:bitOffset"]) : 0;
if (isNaN(offset) || offset < 0) {
throw new Error("'ex:bitOffset' must be a non-negative number");
}
if (offset > length * 8) {
throw new Error(`'ex:bitOffset' ${offset} exceeds 'length' ${length}`);
}
result = result ?? Buffer.alloc(length);
for (const propertyName in schema.properties) {

@@ -557,3 +626,3 @@ if (Object.hasOwnProperty.call(value, propertyName) === false) {

}
this.copyBits(buf, propertyOffset, result, propertyOffset, propertyLength);
this.copyBits(buf, propertyOffset, result, offset + propertyOffset, propertyLength);
}

@@ -560,0 +629,0 @@ return result;

@@ -24,2 +24,4 @@ /********************************************************************************

import { ProtocolClient } from "./protocol-interfaces";
import { Content } from "./content";
import ContentType from "content-type";

@@ -559,5 +561,31 @@ import ContentManager from "./content-serdes";

const content = await client.readResource(form);
return new InteractionOutput(content, form, tp);
try {
return this.handleInteractionOutput(content, form, tp);
} catch (e) {
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
throw new Error(`Error while processing property for ${tp.title}. ${error.message}`);
}
}
private handleInteractionOutput(
content: Content,
form: TD.Form,
outputDataSchema: WoT.DataSchema | undefined
): InteractionOutput {
// infer media type from form if not in response metadata
content.type ??= form.contentType ?? "application/json";
// check if returned media type is the same as expected media type (from TD)
if (form.response != null) {
const parsedMediaTypeContent = ContentType.parse(content.type);
const parsedMediaTypeForm = ContentType.parse(form.response.contentType);
if (parsedMediaTypeContent.type !== parsedMediaTypeForm.type) {
throw new Error(
`Unexpected type '${content.type}' in response. Should be '${form.response.contentType}'`
);
}
}
return new InteractionOutput(content, form, outputDataSchema);
}
async _readProperties(propertyNames: string[]): Promise<WoT.PropertyReadMap> {

@@ -679,15 +707,7 @@ // collect all single promises into array

const content = await client.invokeResource(form, input);
// infer media type from form if not in response metadata
if (!content.type) content.type = form.contentType ?? "application/json";
// check if returned media type is the same as expected media type (from TD)
if (form.response != null) {
if (content.type !== form.response.contentType) {
throw new Error(`Unexpected type in response`);
}
}
try {
return new InteractionOutput(content, form, ta.output);
} catch {
throw new Error(`Received invalid content from Thing`);
return this.handleInteractionOutput(content, form, ta.output);
} catch (e) {
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
throw new Error(`Error while processing action for ${ta.title}. ${error.message}`);
}

@@ -731,8 +751,7 @@ }

(content) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- tsc get confused when nullables are to listeners lambdas
if (!content.type) content.type = form!.contentType ?? "application/json";
try {
listener(new InteractionOutput(content, form, tp));
listener(this.handleInteractionOutput(content, form, tp));
} catch (e) {
warn(`Error while processing observe event for ${tp.title}`);
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
warn(`Error while processing observe property for ${tp.title}. ${error.message}`);
warn(e);

@@ -789,8 +808,7 @@ }

(content) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- tsc get confused when nullables are to listeners lambdas
if (!content.type) content.type = form!.contentType ?? "application/json";
try {
listener(new InteractionOutput(content, form, te.data));
listener(this.handleInteractionOutput(content, form, te.data));
} catch (e) {
warn(`Error while processing event for ${te.title}`);
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
warn(`Error while processing event for ${te.title}. ${error.message}`);
warn(e);

@@ -797,0 +815,0 @@ }

@@ -36,2 +36,3 @@ /********************************************************************************

import Ajv, { ValidateFunction, ErrorObject } from "ajv";
import addFormats from "ajv-formats";
import TDSchema from "wot-thing-description-types/schema/td-json-schema-validation.json";

@@ -49,12 +50,5 @@ import { DataSchemaValue, ExposedThingInit } from "wot-typescript-definitions";

// RegExps take from https://github.com/ajv-validator/ajv-formats/blob/master/src/formats.ts
const ajv = new Ajv({ strict: false })
.addFormat(
"iri-reference",
/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i
)
.addFormat("uri", /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/)
.addFormat(
"date-time",
/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/
);
const ajv = new Ajv({ strict: false });
addFormats(ajv);
export default class Helpers implements Resolver {

@@ -61,0 +55,0 @@ static tsSchemaValidator = ajv.compile(Helpers.createExposeThingInitSchema(tdSchema)) as ValidateFunction;

@@ -22,5 +22,6 @@ /********************************************************************************

import Ajv from "ajv";
import addFormats from "ajv-formats";
import { createLoggers } from "./logger";
const { debug } = createLoggers("core", "interaction-output");
const { debug, warn } = createLoggers("core", "interaction-output");

@@ -34,2 +35,3 @@ // Problem: strict mode ajv does not accept unknown keywords in schemas

const ajv = new Ajv({ strict: false });
addFormats(ajv);

@@ -83,2 +85,10 @@ export class InteractionOutput implements WoT.InteractionOutput {

async value<T extends WoT.DataSchemaValue>(): Promise<T> {
// is there any value expected at all?
if (this.schema == null) {
warn(
`No schema defined. Hence undefined is reported for value() function. If you are invoking an action with no output that is on purpose, otherwise consider using arrayBuffer().`
);
return undefined as unknown as T;
}
// the value has been already read?

@@ -97,4 +107,4 @@ if (this.#value !== undefined) {

if (this.schema == null || this.schema.type == null) {
throw new NotReadableError("No schema defined");
if (this.schema.type == null) {
throw new NotReadableError("No schema type defined");
}

@@ -101,0 +111,0 @@

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc