Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use only base tsconfig strict #1073

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/binding-coap/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"strict": true,
"typeRoots": ["./node_modules/@types", "./typings"]
},
"include": ["src/**/*"],
Expand Down
2 changes: 0 additions & 2 deletions packages/binding-file/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"strictFunctionTypes": true,
"outDir": "dist",
"rootDir": "src"
},
Expand Down
7 changes: 6 additions & 1 deletion packages/binding-http/src/routes/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (_params.thing === undefined || _params.action === undefined) {
res.writeHead(400);
res.end();
return;
}
const thing = this.getThings().get(_params.thing);

if (!thing) {
Expand Down
20 changes: 12 additions & 8 deletions packages/binding-http/src/routes/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (_params.thing === undefined || _params.event === undefined) {
res.writeHead(400);
res.end();
return;
}
const thing = this.getThings().get(_params.thing);

if (!thing) {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion packages/binding-http/src/routes/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export default async function propertiesRoute(
this: HttpServer,
req: IncomingMessage,
res: ServerResponse,
_params: { thing: string }
_params: { [k: string]: string | undefined }
): Promise<void> {
if (_params.thing === undefined) {
res.writeHead(400);
res.end();
return;
}

const thing = this.getThings().get(_params.thing);

if (!thing) {
Expand Down
16 changes: 11 additions & 5 deletions packages/binding-http/src/routes/property-observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (_params.thing === undefined || _params.property === undefined) {
res.writeHead(400);
res.end();
return;
}

const thing = this.getThings().get(_params.thing);

if (!thing) {
Expand Down Expand Up @@ -62,7 +68,7 @@ export default async function propertyObserveRoute(
return;
}
}

const propertyName = _params.property;
if (req.method === "GET") {
const listener = async (value: Content) => {
try {
Expand All @@ -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);
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion packages/binding-http/src/routes/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (_params.thing === undefined || _params.property === undefined) {
res.writeHead(400);
res.end();
return;
}

const thing = this.getThings().get(_params.thing);

if (!thing) {
Expand Down
8 changes: 7 additions & 1 deletion packages/binding-http/src/routes/thing-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ export default async function thingDescriptionRoute(
this: HttpServer,
req: IncomingMessage,
res: ServerResponse,
_params: { thing: string }
_params: { [k: string]: string | undefined }
): Promise<void> {
if (_params.thing === undefined) {
res.writeHead(400);
res.end();
return;
}

const thing = this.getThings().get(_params.thing);
if (!thing) {
res.writeHead(404);
Expand Down
4 changes: 2 additions & 2 deletions packages/binding-http/test/http-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>((resolve, reject) => {
expect(params.uriVariables).to.deep.equal({ step: 5 });
expect(params?.uriVariables).to.deep.equal({ step: 5 });
resolve("TEST");
});
});
Expand Down
3 changes: 1 addition & 2 deletions packages/binding-http/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"strict": true
"rootDir": "src"
},
"include": ["src/**/*"],
"references": [{ "path": "../td-tools" }, { "path": "../core" }]
Expand Down
3 changes: 1 addition & 2 deletions packages/binding-mbus/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"strict": true
"rootDir": "src"
},
"include": ["src/**/*"],
"references": [{ "path": "../td-tools" }, { "path": "../core" }]
Expand Down
4 changes: 2 additions & 2 deletions packages/binding-modbus/test/test-modbus-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export default class ModbusServer {

public start(): Promise<unknown> {
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());
Expand Down
3 changes: 1 addition & 2 deletions packages/binding-modbus/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"strict": true
"rootDir": "src"
},
"include": ["src/**/*"],
"references": [{ "path": "../td-tools" }, { "path": "../core" }]
Expand Down
3 changes: 1 addition & 2 deletions packages/binding-mqtt/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"strict": true
"rootDir": "src"
},
"include": ["src/**/*"],
"references": [{ "path": "../td-tools" }, { "path": "../core" }]
Expand Down
1 change: 0 additions & 1 deletion packages/binding-netconf/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"outDir": "dist",
"rootDir": "src"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/binding-opcua/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"strict": true
"rootDir": "src"
},
"include": ["./src/**/*"],
"references": [{ "path": "../td-tools" }, { "path": "../core" }]
Expand Down
3 changes: 1 addition & 2 deletions packages/binding-websockets/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"strict": true
"rootDir": "src"
},
"include": ["src/**/*"],
"references": [{ "path": "../td-tools" }, { "path": "../core" }]
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"strictFunctionTypes": true,
"outDir": "dist",
"rootDir": "src",
"resolveJsonModule": true,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"strictFunctionTypes": true,
"resolveJsonModule": true,
"outDir": "dist",
"rootDir": "src"
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/src/bindings/coap/example-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/src/bindings/http/example-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion packages/examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"outDir": "dist",
"rootDir": "src",
"target": "ES2018",
Expand Down
2 changes: 0 additions & 2 deletions packages/td-tools/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"strictFunctionTypes": true,
"resolveJsonModule": true,
"types": ["node", "readable-stream"],
"outDir": "dist",
Expand Down
7 changes: 1 addition & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@
"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,
"preserveConstEnums": true,
"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
},
Expand Down