diff --git a/packages/binding-coap/tsconfig.json b/packages/binding-coap/tsconfig.json index 086c6a78f..e9fa7c062 100644 --- a/packages/binding-coap/tsconfig.json +++ b/packages/binding-coap/tsconfig.json @@ -2,9 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src", - "strict": true, - "typeRoots": ["./node_modules/@types", "./typings"] + "rootDir": "src" }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }] diff --git a/packages/binding-file/tsconfig.json b/packages/binding-file/tsconfig.json index 99580e07e..e9fa7c062 100644 --- a/packages/binding-file/tsconfig.json +++ b/packages/binding-file/tsconfig.json @@ -1,8 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "strict": true, - "strictFunctionTypes": true, "outDir": "dist", "rootDir": "src" }, diff --git a/packages/binding-http/src/routes/action.ts b/packages/binding-http/src/routes/action.ts index 5112e3b99..4b33780ec 100644 --- a/packages/binding-http/src/routes/action.ts +++ b/packages/binding-http/src/routes/action.ts @@ -23,8 +23,13 @@ export default async function actionRoute( this: HttpServer, req: IncomingMessage, res: ServerResponse, - _params: { thing: string; action: string } + _params: { [k: string]: string | undefined } ): Promise { + if (_params.thing === undefined || _params.action === undefined) { + res.writeHead(400); + res.end(); + return; + } const thing = this.getThings().get(_params.thing); if (!thing) { diff --git a/packages/binding-http/src/routes/event.ts b/packages/binding-http/src/routes/event.ts index 6996f143b..d1fe23257 100644 --- a/packages/binding-http/src/routes/event.ts +++ b/packages/binding-http/src/routes/event.ts @@ -22,8 +22,13 @@ export default async function eventRoute( this: HttpServer, req: IncomingMessage, res: ServerResponse, - _params: { thing: string; event: string } + _params: { [k: string]: string | undefined } ): Promise { + if (_params.thing === undefined || _params.event === undefined) { + res.writeHead(400); + res.end(); + return; + } const thing = this.getThings().get(_params.thing); if (!thing) { @@ -62,6 +67,7 @@ export default async function eventRoute( if (!isEmpty(uriVariables)) { options.uriVariables = uriVariables; } + const eventName = _params.event; const listener = async (value: Content) => { try { // send event data @@ -77,24 +83,22 @@ export default async function eventRoute( } catch (err) { // Safe cast to NodeJS.ErrnoException we are checking if it is equal to ERR_HTTP_HEADERS_SENT if ((err as NodeJS.ErrnoException)?.code === "ERR_HTTP_HEADERS_SENT") { - thing.handleUnsubscribeEvent(_params.event, listener, options); + thing.handleUnsubscribeEvent(eventName, listener, options); return; } const message = err instanceof Error ? err.message : JSON.stringify(err); - warn( - `HttpServer on port ${this.getPort()} cannot process data for Event '${_params.event}: ${message}'` - ); + warn(`HttpServer on port ${this.getPort()} cannot process data for Event '${eventName}: ${message}'`); res.writeHead(500); res.end("Invalid Event Data"); } }; - await thing.handleSubscribeEvent(_params.event, listener, options); + await thing.handleSubscribeEvent(eventName, listener, options); res.on("close", () => { debug(`HttpServer on port ${this.getPort()} closed Event connection`); - thing.handleUnsubscribeEvent(_params.event, listener, options); + thing.handleUnsubscribeEvent(eventName, listener, options); }); - res.setTimeout(60 * 60 * 1000, () => thing.handleUnsubscribeEvent(_params.event, listener, options)); + res.setTimeout(60 * 60 * 1000, () => thing.handleUnsubscribeEvent(eventName, listener, options)); } else if (req.method === "HEAD") { // HEAD support for long polling subscription res.writeHead(202); diff --git a/packages/binding-http/src/routes/properties.ts b/packages/binding-http/src/routes/properties.ts index a7b0d6a84..0adfa5ba6 100644 --- a/packages/binding-http/src/routes/properties.ts +++ b/packages/binding-http/src/routes/properties.ts @@ -22,8 +22,14 @@ export default async function propertiesRoute( this: HttpServer, req: IncomingMessage, res: ServerResponse, - _params: { thing: string } + _params: { [k: string]: string | undefined } ): Promise { + if (_params.thing === undefined) { + res.writeHead(400); + res.end(); + return; + } + const thing = this.getThings().get(_params.thing); if (!thing) { diff --git a/packages/binding-http/src/routes/property-observe.ts b/packages/binding-http/src/routes/property-observe.ts index d1b8ddfcd..8535dae39 100644 --- a/packages/binding-http/src/routes/property-observe.ts +++ b/packages/binding-http/src/routes/property-observe.ts @@ -22,8 +22,14 @@ export default async function propertyObserveRoute( this: HttpServer, req: IncomingMessage, res: ServerResponse, - _params: { thing: string; property: string } + _params: { [k: string]: string | undefined } ): Promise { + if (_params.thing === undefined || _params.property === undefined) { + res.writeHead(400); + res.end(); + return; + } + const thing = this.getThings().get(_params.thing); if (!thing) { @@ -62,7 +68,7 @@ export default async function propertyObserveRoute( return; } } - + const propertyName = _params.property; if (req.method === "GET") { const listener = async (value: Content) => { try { @@ -79,7 +85,7 @@ export default async function propertyObserveRoute( } catch (err) { // Safe cast to NodeJS.ErrnoException we are checking if it is equal to ERR_HTTP_HEADERS_SENT if ((err as NodeJS.ErrnoException)?.code === "ERR_HTTP_HEADERS_SENT") { - thing.handleUnobserveProperty(_params.property, listener, options); + thing.handleUnobserveProperty(propertyName, listener, options); return; } const message = err instanceof Error ? err.message : JSON.stringify(err); @@ -95,9 +101,9 @@ export default async function propertyObserveRoute( await thing.handleObserveProperty(_params.property, listener, options); res.on("finish", () => { debug(`HttpServer on port ${this.getPort()} closed connection`); - thing.handleUnobserveProperty(_params.property, listener, options); + thing.handleUnobserveProperty(propertyName, listener, options); }); - res.setTimeout(60 * 60 * 1000, () => thing.handleUnobserveProperty(_params.property, listener, options)); + res.setTimeout(60 * 60 * 1000, () => thing.handleUnobserveProperty(propertyName, listener, options)); } else if (req.method === "HEAD") { // HEAD support for long polling subscription // TODO: set the Content-Type header to the type of the property diff --git a/packages/binding-http/src/routes/property.ts b/packages/binding-http/src/routes/property.ts index 47cc72b7e..919780240 100644 --- a/packages/binding-http/src/routes/property.ts +++ b/packages/binding-http/src/routes/property.ts @@ -22,8 +22,14 @@ export default async function propertyRoute( this: HttpServer, req: IncomingMessage, res: ServerResponse, - _params: { thing: string; property: string } + _params: { [k: string]: string | undefined } ): Promise { + if (_params.thing === undefined || _params.property === undefined) { + res.writeHead(400); + res.end(); + return; + } + const thing = this.getThings().get(_params.thing); if (!thing) { diff --git a/packages/binding-http/src/routes/thing-description.ts b/packages/binding-http/src/routes/thing-description.ts index 136787595..4a29a4272 100644 --- a/packages/binding-http/src/routes/thing-description.ts +++ b/packages/binding-http/src/routes/thing-description.ts @@ -127,8 +127,14 @@ export default async function thingDescriptionRoute( this: HttpServer, req: IncomingMessage, res: ServerResponse, - _params: { thing: string } + _params: { [k: string]: string | undefined } ): Promise { + if (_params.thing === undefined) { + res.writeHead(400); + res.end(); + return; + } + const thing = this.getThings().get(_params.thing); if (!thing) { res.writeHead(404); diff --git a/packages/binding-http/test/http-server-test.ts b/packages/binding-http/test/http-server-test.ts index afd275b0d..c4c6c5164 100644 --- a/packages/binding-http/test/http-server-test.ts +++ b/packages/binding-http/test/http-server-test.ts @@ -289,9 +289,9 @@ class HttpServerTest { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore testThing.properties.test.forms = []; - testThing.setActionHandler("try", (input: WoT.InteractionOutput, params: InteractionOptions) => { + testThing.setActionHandler("try", (input: WoT.InteractionOutput, params?: InteractionOptions) => { return new Promise((resolve, reject) => { - expect(params.uriVariables).to.deep.equal({ step: 5 }); + expect(params?.uriVariables).to.deep.equal({ step: 5 }); resolve("TEST"); }); }); diff --git a/packages/binding-http/tsconfig.json b/packages/binding-http/tsconfig.json index df9cd1d90..e9fa7c062 100644 --- a/packages/binding-http/tsconfig.json +++ b/packages/binding-http/tsconfig.json @@ -2,8 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src", - "strict": true + "rootDir": "src" }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }] diff --git a/packages/binding-mbus/tsconfig.json b/packages/binding-mbus/tsconfig.json index df9cd1d90..e9fa7c062 100644 --- a/packages/binding-mbus/tsconfig.json +++ b/packages/binding-mbus/tsconfig.json @@ -2,8 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src", - "strict": true + "rootDir": "src" }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }] diff --git a/packages/binding-modbus/test/test-modbus-server.ts b/packages/binding-modbus/test/test-modbus-server.ts index f0eeba4dd..6d223228f 100644 --- a/packages/binding-modbus/test/test-modbus-server.ts +++ b/packages/binding-modbus/test/test-modbus-server.ts @@ -78,9 +78,9 @@ export default class ModbusServer { public start(): Promise { return new Promise((resolve) => { - this.serverTCP.on("SocketError", (err: Error) => { + this.serverTCP.on("SocketError", (err: Error | null) => { // Handle socket error if needed, can be ignored - error(err.toString()); + error("SocketError:", err?.toString()); }); this.serverTCP.on("error", (err) => { debug(err?.toString()); diff --git a/packages/binding-modbus/tsconfig.json b/packages/binding-modbus/tsconfig.json index df9cd1d90..e9fa7c062 100644 --- a/packages/binding-modbus/tsconfig.json +++ b/packages/binding-modbus/tsconfig.json @@ -2,8 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src", - "strict": true + "rootDir": "src" }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }] diff --git a/packages/binding-mqtt/tsconfig.json b/packages/binding-mqtt/tsconfig.json index df9cd1d90..e9fa7c062 100644 --- a/packages/binding-mqtt/tsconfig.json +++ b/packages/binding-mqtt/tsconfig.json @@ -2,8 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src", - "strict": true + "rootDir": "src" }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }] diff --git a/packages/binding-netconf/tsconfig.json b/packages/binding-netconf/tsconfig.json index 17fe8a159..e9fa7c062 100644 --- a/packages/binding-netconf/tsconfig.json +++ b/packages/binding-netconf/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "strict": true, "outDir": "dist", "rootDir": "src" }, diff --git a/packages/binding-opcua/tsconfig.json b/packages/binding-opcua/tsconfig.json index 401574083..65cfae503 100644 --- a/packages/binding-opcua/tsconfig.json +++ b/packages/binding-opcua/tsconfig.json @@ -2,8 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src", - "strict": true + "rootDir": "src" }, "include": ["./src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }] diff --git a/packages/binding-websockets/tsconfig.json b/packages/binding-websockets/tsconfig.json index df9cd1d90..e9fa7c062 100644 --- a/packages/binding-websockets/tsconfig.json +++ b/packages/binding-websockets/tsconfig.json @@ -2,8 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src", - "strict": true + "rootDir": "src" }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }, { "path": "../core" }] diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 6531df4d3..2a18482f3 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -1,8 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "strict": true, - "strictFunctionTypes": true, "outDir": "dist", "rootDir": "src", "resolveJsonModule": true, diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index c97540a51..4bc652caa 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,8 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "strict": true, - "strictFunctionTypes": true, "resolveJsonModule": true, "outDir": "dist", "rootDir": "src" diff --git a/packages/examples/src/bindings/coap/example-client.ts b/packages/examples/src/bindings/coap/example-client.ts index 1c937641b..b815f0aac 100644 --- a/packages/examples/src/bindings/coap/example-client.ts +++ b/packages/examples/src/bindings/coap/example-client.ts @@ -24,7 +24,8 @@ servient.addClientFactory(new CoapClientFactory()); const wotHelper = new Helpers(servient); wotHelper .fetch("coap://plugfest.thingweb.io:5683/testthing") - .then(async (td: ThingDescription) => { + .then(async (fetched) => { + const td: ThingDescription = fetched as ThingDescription; // using await for serial execution (note 'async' in then() of fetch()) try { const WoT = await servient.start(); diff --git a/packages/examples/src/bindings/http/example-client.ts b/packages/examples/src/bindings/http/example-client.ts index 0983f3208..bab479dda 100644 --- a/packages/examples/src/bindings/http/example-client.ts +++ b/packages/examples/src/bindings/http/example-client.ts @@ -24,7 +24,8 @@ servient.addClientFactory(new HttpClientFactory()); const wotHelper = new Helpers(servient); wotHelper .fetch("http://plugfest.thingweb.io:8083/testthing") - .then(async (td: ThingDescription) => { + .then(async (fetched) => { + const td: ThingDescription = fetched as ThingDescription; // using await for serial execution (note 'async' in then() of fetch()) try { const WoT = await servient.start(); diff --git a/packages/examples/tsconfig.json b/packages/examples/tsconfig.json index 61b6c09bc..63049fbba 100644 --- a/packages/examples/tsconfig.json +++ b/packages/examples/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "strict": true, "outDir": "dist", "rootDir": "src", "target": "ES2018", diff --git a/packages/td-tools/tsconfig.json b/packages/td-tools/tsconfig.json index e0a29e71a..b2c3d8edc 100644 --- a/packages/td-tools/tsconfig.json +++ b/packages/td-tools/tsconfig.json @@ -1,8 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "strict": true, - "strictFunctionTypes": true, "resolveJsonModule": true, "types": ["node", "readable-stream"], "outDir": "dist", diff --git a/tsconfig.json b/tsconfig.json index 6738a4b40..5b3cda168 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,12 +5,10 @@ "skipLibCheck": false, "module": "commonjs", "outDir": "dist", - "alwaysStrict": true, - "strict": false, + "strict": true, "composite": true, "incremental": true, "sourceMap": true, - "noImplicitAny": true, "noImplicitReturns": true, "removeComments": true, "noLib": false, @@ -18,11 +16,8 @@ "experimentalDecorators": true, "declaration": true, "esModuleInterop": true, - "strictFunctionTypes": false, "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, "resolveJsonModule": false, - "noStrictGenericChecks": false, - "noImplicitThis": true, "skipDefaultLibCheck": false, "allowJs": false },