Skip to content

Commit

Permalink
fix: compilation errors due to a benevolent tsconfig
Browse files Browse the repository at this point in the history
see eclipse-thingweb#758

Signed-off-by: reluc <relu.cri@gmail.com>
  • Loading branch information
relu91 committed Jun 8, 2022
1 parent a044370 commit c792091
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
8 changes: 6 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/binding-coap/src/coap-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class CoapServer implements ProtocolServer {
for (const propertyName in thing.properties) {
const href = base + "/" + this.PROPERTY_DIR + "/" + encodeURIComponent(propertyName);
const form = new TD.Form(href, type);
ProtocolHelpers.updatePropertyFormWithTemplate(form, tdTemplate, propertyName);
ProtocolHelpers.updatePropertyFormWithTemplate(form, thing.properties[propertyName]);
if (thing.properties[propertyName].readOnly) {
form.op = ["readproperty"];
} else if (thing.properties[propertyName].writeOnly) {
Expand All @@ -160,7 +160,7 @@ export default class CoapServer implements ProtocolServer {
for (const actionName in thing.actions) {
const href = base + "/" + this.ACTION_DIR + "/" + encodeURIComponent(actionName);
const form = new TD.Form(href, type);
ProtocolHelpers.updateActionFormWithTemplate(form, tdTemplate, actionName);
ProtocolHelpers.updateActionFormWithTemplate(form, thing.actions[actionName]);
form.op = "invokeaction";
thing.actions[actionName].forms.push(form);
console.debug(
Expand All @@ -172,7 +172,7 @@ export default class CoapServer implements ProtocolServer {
for (const eventName in thing.events) {
const href = base + "/" + this.EVENT_DIR + "/" + encodeURIComponent(eventName);
const form = new TD.Form(href, type);
ProtocolHelpers.updateEventFormWithTemplate(form, tdTemplate, eventName);
ProtocolHelpers.updateEventFormWithTemplate(form, thing.events[eventName]);
form.op = ["subscribeevent", "unsubscribeevent"];
thing.events[eventName].forms.push(form);
console.debug(
Expand Down
8 changes: 8 additions & 0 deletions packages/binding-coap/test/coap-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class CoapServerTest {

const test: DataSchemaValue = "testValue";
testThing.setPropertyReadHandler("test", (_) => Promise.resolve(test));
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testThing.properties.test.forms = [];

await coapServer.expose(testThing);
Expand Down Expand Up @@ -89,6 +91,8 @@ class CoapServerTest {
testThing.setPropertyWriteHandler("test", async (value) => {
test = await value.value();
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testThing.properties.test.forms = [];

await coapServer.expose(testThing);
Expand Down Expand Up @@ -126,6 +130,8 @@ class CoapServerTest {
resolve("TEST");
});
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testThing.actions.try.forms = [];

await coapServer.expose(testThing);
Expand Down Expand Up @@ -231,6 +237,8 @@ class CoapServerTest {
resolve(test);
});
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testThing.properties.test.forms = [];

await coapServer.expose(testThing);
Expand Down
3 changes: 2 additions & 1 deletion packages/binding-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"node-fetch": "^2.6.7",
"query-string": "^7.1.1",
"rxjs": "5.5.11",
"slugify": "^1.4.5"
"slugify": "^1.4.5",
"wot-thing-description-types": "^1.1.0-09-February-2022"
},
"scripts": {
"build": "tsc -b",
Expand Down
11 changes: 6 additions & 5 deletions packages/binding-http/src/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { OAuth2SecurityScheme } from "@node-wot/td-tools";
import slugify from "slugify";
import { ThingDescription } from "wot-typescript-definitions";
import * as acceptLanguageParser from "accept-language-parser";
import { PropertyElement } from "wot-thing-description-types";

export default class HttpServer implements ProtocolServer {
public readonly scheme: "http" | "https";
Expand Down Expand Up @@ -206,7 +207,7 @@ export default class HttpServer implements ProtocolServer {

private updateInteractionNameWithUriVariablePattern(
interactionName: string,
uriVariables: { [key: string]: TD.DataSchema }
uriVariables: PropertyElement["uriVariables"]
): string {
if (uriVariables && Object.keys(uriVariables).length > 0) {
let pattern = "{?";
Expand Down Expand Up @@ -321,7 +322,7 @@ export default class HttpServer implements ProtocolServer {
);
const href = base + "/" + this.PROPERTY_DIR + "/" + propertyNamePattern;
const form = new TD.Form(href, type);
ProtocolHelpers.updatePropertyFormWithTemplate(form, tdTemplate, propertyName);
ProtocolHelpers.updatePropertyFormWithTemplate(form, thing.properties[propertyName]);
if (thing.properties[propertyName].readOnly) {
form.op = ["readproperty"];
const hform: HttpForm = form;
Expand Down Expand Up @@ -372,7 +373,7 @@ export default class HttpServer implements ProtocolServer {
);
const href = base + "/" + this.ACTION_DIR + "/" + actionNamePattern;
const form = new TD.Form(href, type);
ProtocolHelpers.updateActionFormWithTemplate(form, tdTemplate, actionName);
ProtocolHelpers.updateActionFormWithTemplate(form, thing.actions[actionName]);
form.op = ["invokeaction"];
const hform: HttpForm = form;
if (hform["htv:methodName"] === undefined) {
Expand All @@ -392,7 +393,7 @@ export default class HttpServer implements ProtocolServer {
);
const href = base + "/" + this.EVENT_DIR + "/" + eventNamePattern;
const form = new TD.Form(href, type);
ProtocolHelpers.updateEventFormWithTemplate(form, tdTemplate, eventName);
ProtocolHelpers.updateEventFormWithTemplate(form, thing.events[eventName]);
form.subprotocol = "longpoll";
form.op = ["subscribeevent", "unsubscribeevent"];
thing.events[eventName].forms.push(form);
Expand Down Expand Up @@ -791,7 +792,7 @@ export default class HttpServer implements ProtocolServer {
}
} else if (segments[2] === this.ACTION_DIR) {
// sub-path -> select Action
const action: TD.ThingAction = thing.actions[segments[3]];
const action = thing.actions[segments[3]];
if (action) {
if (req.method === "POST") {
const options: WoT.InteractionOptions & { formIndex: number } = {
Expand Down
3 changes: 2 additions & 1 deletion packages/binding-mqtt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"@node-wot/td-tools": "0.8.1",
"aedes": "^0.46.2",
"mqtt": "^4.2.8",
"rxjs": "5.5.11"
"rxjs": "5.5.11",
"wot-thing-description-types": "^1.1.0-09-February-2022"
},
"scripts": {
"build": "tsc -b",
Expand Down
5 changes: 3 additions & 2 deletions packages/binding-mqtt/src/mqtt-broker-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as TD from "@node-wot/td-tools";
import { MqttBrokerServerConfig } from "./mqtt";
import { ProtocolServer, Servient, ExposedThing, ContentSerdes, ProtocolHelpers, Content } from "@node-wot/core";
import { InteractionOptions } from "wot-typescript-definitions";
import { ActionElement, PropertyElement } from "wot-thing-description-types";

export default class MqttBrokerServer implements ProtocolServer {
readonly scheme: string = "mqtt";
Expand Down Expand Up @@ -255,7 +256,7 @@ export default class MqttBrokerServer implements ProtocolServer {
}

private handleAction(
action: TD.ThingAction,
action: ActionElement,
packet: IPublishPacket,
payload: Buffer,
segments: string[],
Expand Down Expand Up @@ -312,7 +313,7 @@ export default class MqttBrokerServer implements ProtocolServer {
}

private handlePropertyWrite(
property: TD.ThingProperty,
property: PropertyElement,
packet: IPublishPacket,
payload: Buffer,
segments: string[],
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { DataSchemaValue, ExposedThingInit } from "wot-typescript-definitions";
import { SomeJSONSchema } from "ajv/dist/types/json-schema";
import { ThingInteraction, ThingModelHelpers } from "@node-wot/td-tools";
import { Resolver } from "@node-wot/td-tools/src/resolver-interface";
import { DataSchema } from "wot-thing-description-types";

const tdSchema = TDSchema;
// RegExps take from https://github.com/ajv-validator/ajv-formats/blob/master/src/formats.ts
Expand Down Expand Up @@ -344,7 +345,7 @@ export default class Helpers implements Resolver {
static parseUrlParameters(
url: string,
globalUriVariables: { [key: string]: TD.DataSchema },
uriVariables: { [key: string]: TD.DataSchema }
uriVariables: { [k: string]: DataSchema }
): Record<string, unknown> {
const params: Record<string, unknown> = {};
if (url == null || (!uriVariables && !globalUriVariables)) {
Expand Down

0 comments on commit c792091

Please sign in to comment.