Socket
Socket
Sign inDemoInstall

@node-wot/core

Package Overview
Dependencies
21
Maintainers
4
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.6 to 0.8.7

23

dist/codecs/text-codec.js

@@ -7,8 +7,3 @@ "use strict";

constructor(subMediaType) {
if (!subMediaType) {
this.subMediaType = "text/plain";
}
else {
this.subMediaType = subMediaType;
}
this.subMediaType = !subMediaType ? "text/plain" : subMediaType;
}

@@ -27,3 +22,8 @@ getMediaType() {

if (value !== undefined) {
body = JSON.stringify(value);
if (typeof value === "string") {
body = value;
}
else {
body = JSON.stringify(value);
}
}

@@ -65,8 +65,5 @@ let be;

}
if (be) {
return Buffer.from(body, be);
}
else {
return Buffer.from(body);
}
const buff = Buffer.alloc(body.length);
buff.write(body, be);
return buff;
}

@@ -73,0 +70,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -88,2 +92,14 @@ if (k2 === undefined) k2 = k;

}
function handleUriVariables(thing, ti, form, options) {
const ut = UriTemplate.parse(form.href);
const uriVariables = helpers_1.default.parseInteractionOptions(thing, ti, options).uriVariables;
const updatedHref = ut.expand(uriVariables !== null && uriVariables !== void 0 ? uriVariables : {});
if (updatedHref !== form.href) {
const updForm = Object.assign({}, form);
updForm.href = updatedHref;
form = updForm;
debug(`ConsumedThing '${thing.title}' update form URI to ${form.href}`);
}
return form;
}
class InternalPropertySubscription extends InternalSubscription {

@@ -120,4 +136,5 @@ constructor(thing, name, client, form) {

}
const formWithoutURIvariables = handleUriVariables(this.thing, tp, form, options);
debug(`ConsumedThing '${this.thing.title}' unobserving to ${form.href}`);
yield this.client.unlinkResource(form);
yield this.client.unlinkResource(formWithoutURIvariables);
this.active = false;

@@ -210,11 +227,9 @@ });

}
const { client, form } = this.thing.getClientFor(te.forms, "unsubscribeevent", Affordance.EventAffordance, options);
const { form } = this.thing.getClientFor(te.forms, "unsubscribeevent", Affordance.EventAffordance, options);
if (!form) {
throw new Error(`ConsumedThing '${this.thing.title}' did not get suitable form`);
}
if (!client) {
throw new Error(`ConsumedThing '${this.thing.title}' did not get suitable client for ${form.href}`);
}
const formWithoutURIvariables = handleUriVariables(this.thing, te, form, options);
debug(`ConsumedThing '${this.thing.title}' unsubscribing to ${form.href}`);
client.unlinkResource(form);
this.client.unlinkResource(formWithoutURIvariables);
this.active = false;

@@ -507,3 +522,3 @@ });

}
let { client, form } = this.getClientFor(tp.forms, "observeproperty", Affordance.PropertyAffordance, options);
const { client, form } = this.getClientFor(tp.forms, "observeproperty", Affordance.PropertyAffordance, options);
if (!form) {

@@ -519,4 +534,4 @@ throw new Error(`ConsumedThing '${this.title}' did not get suitable form`);

debug(`ConsumedThing '${this.title}' observing to ${form.href}`);
form = this.handleUriVariables(tp, form, options);
yield client.subscribeResource(form, (content) => {
const formWithoutURITemplates = this.handleUriVariables(tp, form, options);
yield client.subscribeResource(formWithoutURITemplates, (content) => {
var _a;

@@ -547,3 +562,3 @@ if (!content.type)

}
let { client, form } = this.getClientFor(te.forms, "subscribeevent", Affordance.EventAffordance, options);
const { client, form } = this.getClientFor(te.forms, "subscribeevent", Affordance.EventAffordance, options);
if (!form) {

@@ -559,4 +574,4 @@ throw new Error(`ConsumedThing '${this.title}' did not get suitable form`);

debug(`ConsumedThing '${this.title}' subscribing to ${form.href}`);
form = this.handleUriVariables(te, form, options);
yield client.subscribeResource(form, (content) => {
const formWithoutURITemplates = this.handleUriVariables(te, form, options);
yield client.subscribeResource(formWithoutURITemplates, (content) => {
var _a;

@@ -582,12 +597,3 @@ if (!content.type)

handleUriVariables(ti, form, options) {
const ut = UriTemplate.parse(form.href);
const uriVariables = helpers_1.default.parseInteractionOptions(this, ti, options).uriVariables;
const updatedHref = ut.expand(uriVariables !== null && uriVariables !== void 0 ? uriVariables : {});
if (updatedHref !== form.href) {
const updForm = Object.assign({}, form);
updForm.href = updatedHref;
form = updForm;
debug(`ConsumedThing '${this.title}' update form URI to ${form.href}`);
}
return form;
return handleUriVariables(this, ti, form, options);
}

@@ -594,0 +600,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
export declare class Content {

@@ -3,0 +4,0 @@ type: string;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -40,2 +44,3 @@ if (k2 === undefined) k2 = k;

const es2018_1 = require("web-streams-polyfill/ponyfill/es2018");
const core_1 = require("./core");
const content_serdes_1 = __importDefault(require("./content-serdes"));

@@ -311,15 +316,11 @@ const protocol_listener_registry_1 = __importDefault(require("./protocol-listener-registry"));

return __awaiter(this, void 0, void 0, function* () {
const promises = [];
for (const propertyName of propertyNames) {
const form = this.properties[propertyName].forms.find((form) => form.contentType === "application/json" || !form.contentType);
if (!form) {
continue;
}
promises.push(this.handleReadProperty(propertyName, options));
}
try {
const output = new Map();
const results = yield Promise.all(promises);
for (let i = 0; i < results.length; i++) {
output.set(propertyNames[i], results[i]);
for (const propertyName of propertyNames) {
const form = this.properties[propertyName].forms.find((form) => form.contentType === core_1.ContentSerdes.DEFAULT || !form.contentType);
if (!form) {
continue;
}
const contentResponse = yield this.handleReadProperty(propertyName, options);
output.set(propertyName, contentResponse);
}

@@ -326,0 +327,0 @@ return output;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import * as TD from "@node-wot/td-tools";

@@ -22,2 +24,3 @@ import { Readable } from "stream";

static getFormIndexForOperation(interaction: TD.ThingInteraction, type: "property" | "action" | "event", operationName?: "writeproperty" | "readproperty" | "invokeaction" | "subscribeevent" | "unsubscribeevent" | "unobserveproperty" | "observeproperty" | "readallproperties" | "readmultipleproperties", formIndex?: number): number;
static getPropertyOpValues(property: PropertyElement): string[];
}

@@ -6,3 +6,3 @@ "use strict";

const logger_1 = require("./logger");
const { debug } = (0, logger_1.createLoggers)("core", "protocol-helpers");
const { debug, warn } = (0, logger_1.createLoggers)("core", "protocol-helpers");
function ManagedStream(Base) {

@@ -262,4 +262,21 @@ return class extends Base {

}
static getPropertyOpValues(property) {
const op = [];
if (!property.readOnly) {
op.push("writeproperty");
}
if (!property.writeOnly) {
op.push("readproperty");
}
if (op.length === 0) {
warn("Property was declared both as readOnly and writeOnly.");
}
if (property.observable) {
op.push("observeproperty");
op.push("unobserveproperty");
}
return op;
}
}
exports.default = ProtocolHelpers;
//# sourceMappingURL=protocol-helpers.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

{
"name": "@node-wot/core",
"version": "0.8.6",
"version": "0.8.7",
"description": "W3C Web of Things (WoT) Servient framework",
"author": "Eclipse Thingweb <thingweb-dev@eclipse.org> (https://thingweb.io/)",
"license": "EPL-2.0 OR W3C-20150513",
"repository": "https://github.com/eclipse/thingweb.node-wot/tree/master/packages/core",
"repository": "https://github.com/eclipse-thingweb/node-wot/tree/master/packages/core",
"publishConfig": {

@@ -23,3 +23,3 @@ "access": "public"

"@types/debug": "^4.1.7",
"@types/node": "16.4.13",
"@types/node": "16.18.35",
"@types/uritemplate": "^0.3.4",

@@ -41,10 +41,9 @@ "@types/uuid": "^8.3.1",

"prettier": "^2.3.2",
"ts-node": "10.1.0",
"typescript": "4.4.3",
"ts-node": "^10.9.1",
"typescript": "4.7.4",
"typescript-standard": "^0.3.36",
"wot-thing-description-types": "1.1.0-23-March-2023",
"wot-typescript-definitions": "0.8.0-SNAPSHOT.25"
"wot-typescript-definitions": "0.8.0-SNAPSHOT.26"
},
"dependencies": {
"@node-wot/td-tools": "0.8.6",
"@node-wot/td-tools": "0.8.7",
"@petamoriken/float16": "^3.1.1",

@@ -66,5 +65,5 @@ "ajv": "^8.11.0",

"bugs": {
"url": "https://github.com/eclipse/thingweb.node-wot/issues"
"url": "https://github.com/eclipse-thingweb/node-wot/issues"
},
"homepage": "https://github.com/eclipse/thingweb.node-wot/tree/master/packages/core#readme",
"homepage": "https://github.com/eclipse-thingweb/node-wot/tree/master/packages/core#readme",
"directories": {

@@ -71,0 +70,0 @@ "test": "test"

@@ -5,4 +5,4 @@ # Core of node-wot

- [HTTP](https://github.com/eclipse/thingweb.node-wot/blob/master/packages/binding-http)
- [CoAP](https://github.com/eclipse/thingweb.node-wot/blob/master/packages/binding-coap)
- [HTTP](https://github.com/eclipse-thingweb/node-wot/blob/master/packages/binding-http)
- [CoAP](https://github.com/eclipse-thingweb/node-wot/blob/master/packages/binding-coap)
- ...

@@ -20,7 +20,7 @@

- https://github.com/eclipse/thingweb.node-wot/blob/master/packages/binding-http
- https://github.com/eclipse/thingweb.node-wot/blob/master/packages/binding-coap
- https://github.com/eclipse-thingweb/node-wot/blob/master/packages/binding-http
- https://github.com/eclipse-thingweb/node-wot/blob/master/packages/binding-coap
## More Details
See <https://github.com/eclipse/thingweb.node-wot/>
See <https://github.com/eclipse-thingweb/node-wot/>

@@ -26,7 +26,3 @@ /********************************************************************************

constructor(subMediaType?: string) {
if (!subMediaType) {
this.subMediaType = "text/plain";
} else {
this.subMediaType = subMediaType;
}
this.subMediaType = !subMediaType ? "text/plain" : subMediaType;
}

@@ -52,3 +48,7 @@

if (value !== undefined) {
body = JSON.stringify(value);
if (typeof value === "string") {
body = value;
} else {
body = JSON.stringify(value);
}
}

@@ -93,8 +93,7 @@

if (be) {
return Buffer.from(body, be);
} else {
return Buffer.from(body);
}
// Note: write buffer directly without quotes around as Buffer.from() would do
const buff = Buffer.alloc(body.length);
buff.write(body, be);
return buff;
}
}

@@ -124,2 +124,22 @@ /********************************************************************************

function handleUriVariables(
thing: ConsumedThing,
ti: ThingInteraction,
form: TD.Form,
options?: WoT.InteractionOptions
): TD.Form {
const ut = UriTemplate.parse(form.href);
const uriVariables = Helpers.parseInteractionOptions(thing, ti, options).uriVariables;
const updatedHref = ut.expand(uriVariables ?? {});
if (updatedHref !== form.href) {
// create shallow copy and update href
const updForm = { ...form };
updForm.href = updatedHref;
form = updForm;
debug(`ConsumedThing '${thing.title}' update form URI to ${form.href}`);
}
return form;
}
class InternalPropertySubscription extends InternalSubscription {

@@ -161,4 +181,5 @@ active = false;

const formWithoutURIvariables = handleUriVariables(this.thing, tp, form, options);
debug(`ConsumedThing '${this.thing.title}' unobserving to ${form.href}`);
await this.client.unlinkResource(form);
await this.client.unlinkResource(formWithoutURIvariables);
this.active = false;

@@ -287,16 +308,10 @@ }

const { client, form } = this.thing.getClientFor(
te.forms,
"unsubscribeevent",
Affordance.EventAffordance,
options
);
const { form } = this.thing.getClientFor(te.forms, "unsubscribeevent", Affordance.EventAffordance, options);
if (!form) {
throw new Error(`ConsumedThing '${this.thing.title}' did not get suitable form`);
}
if (!client) {
throw new Error(`ConsumedThing '${this.thing.title}' did not get suitable client for ${form.href}`);
}
const formWithoutURIvariables = handleUriVariables(this.thing, te, form, options);
debug(`ConsumedThing '${this.thing.title}' unsubscribing to ${form.href}`);
client.unlinkResource(form);
this.client.unlinkResource(formWithoutURIvariables);
this.active = false;

@@ -708,3 +723,3 @@ }

}
let { client, form } = this.getClientFor(tp.forms, "observeproperty", Affordance.PropertyAffordance, options);
const { client, form } = this.getClientFor(tp.forms, "observeproperty", Affordance.PropertyAffordance, options);
if (!form) {

@@ -724,6 +739,6 @@ throw new Error(`ConsumedThing '${this.title}' did not get suitable form`);

// uriVariables ?
form = this.handleUriVariables(tp, form, options);
const formWithoutURITemplates = this.handleUriVariables(tp, form, options);
await client.subscribeResource(
form,
formWithoutURITemplates,
// next

@@ -768,3 +783,3 @@ (content) => {

}
let { client, form } = this.getClientFor(te.forms, "subscribeevent", Affordance.EventAffordance, options);
const { client, form } = this.getClientFor(te.forms, "subscribeevent", Affordance.EventAffordance, options);
if (!form) {

@@ -784,6 +799,6 @@ throw new Error(`ConsumedThing '${this.title}' did not get suitable form`);

// uriVariables ?
form = this.handleUriVariables(te, form, options);
const formWithoutURITemplates = this.handleUriVariables(te, form, options);
await client.subscribeResource(
form,
formWithoutURITemplates,
(content) => {

@@ -818,15 +833,4 @@ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- tsc get confused when nullables are to listeners lambdas

handleUriVariables(ti: ThingInteraction, form: TD.Form, options?: WoT.InteractionOptions): TD.Form {
const ut = UriTemplate.parse(form.href);
const uriVariables = Helpers.parseInteractionOptions(this, ti, options).uriVariables;
const updatedHref = ut.expand(uriVariables ?? {});
if (updatedHref !== form.href) {
// create shallow copy and update href
const updForm = { ...form };
updForm.href = updatedHref;
form = updForm;
debug(`ConsumedThing '${this.title}' update form URI to ${form.href}`);
}
return form;
return handleUriVariables(this, ti, form, options);
}
}

@@ -27,3 +27,3 @@ /********************************************************************************

import { ReadableStream as PolyfillStream } from "web-streams-polyfill/ponyfill/es2018";
import { Content, PropertyContentMap } from "./core";
import { Content, ContentSerdes, PropertyContentMap } from "./core";
import ContentManager from "./content-serdes";

@@ -108,3 +108,3 @@ import {

// unset "@type":"tm:ThingModel" ?
// see https://github.com/eclipse/thingweb.node-wot/issues/426
// see https://github.com/eclipse-thingweb/node-wot/issues/426
/* if (this["@type"]) {

@@ -427,22 +427,15 @@ if (typeof this["@type"] === 'string' && this["@type"] === "tm:ThingModel") {

): Promise<PropertyContentMap> {
// collect all single promises into array
const promises: Promise<Content>[] = [];
for (const propertyName of propertyNames) {
// Note: currently only DataSchema properties are supported
const form = this.properties[propertyName].forms.find(
(form) => form.contentType === "application/json" || !form.contentType
);
if (!form) {
continue;
}
promises.push(this.handleReadProperty(propertyName, options));
}
try {
// wait for all promises to succeed and create response
// collect all single promises
const output = new Map<string, Content>();
const results = await Promise.all(promises);
for (let i = 0; i < results.length; i++) {
output.set(propertyNames[i], results[i]);
for (const propertyName of propertyNames) {
// Note: currently only JSON DataSchema properties are supported
const form = this.properties[propertyName].forms.find(
(form) => form.contentType === ContentSerdes.DEFAULT || !form.contentType
);
if (!form) {
continue;
}
const contentResponse = await this.handleReadProperty(propertyName, options);
output.set(propertyName, contentResponse);
}

@@ -449,0 +442,0 @@ return output;

@@ -22,3 +22,3 @@ /********************************************************************************

const { debug } = createLoggers("core", "protocol-helpers");
const { debug, warn } = createLoggers("core", "protocol-helpers");

@@ -384,2 +384,25 @@ export interface IManagedStream {

}
public static getPropertyOpValues(property: PropertyElement): string[] {
const op: string[] = [];
if (!property.readOnly) {
op.push("writeproperty");
}
if (!property.writeOnly) {
op.push("readproperty");
}
if (op.length === 0) {
warn("Property was declared both as readOnly and writeOnly.");
}
if (property.observable) {
op.push("observeproperty");
op.push("unobserveproperty");
}
return op;
}
}

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

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