Skip to content

Commit 986afb7

Browse files
authored
Enable strictPropertyInitialization in tsconfig.json. (#541)
This will stop situations where the throttling queue was uninitialized in the Draupnir instances. We should really enable `strict` for typescript. The blocker for that is `useUnknownInCatchVariables` around legacy code (which should be minor). And also `strictFunctionTypes`, which `interface-manager` exacerbates by not providing the right generics for `describeRenderer` and other methods. #496
1 parent 982f9c2 commit 986afb7

File tree

6 files changed

+42
-48
lines changed

6 files changed

+42
-48
lines changed

src/Draupnir.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export class Draupnir implements Client, MatrixAdaptorContext {
130130
this.client,
131131
this.config
132132
);
133+
this.taskQueue = new ThrottlingQueue(
134+
this.managementRoomOutput,
135+
config.backgroundDelayMS
136+
);
133137
this.reactionHandler = new MatrixReactionHandler(
134138
this.managementRoom.toRoomIDOrAlias(),
135139
client,

src/health/healthz.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import { IConfig } from "../config";
1616
export class Healthz {
1717
private healthCode: number;
1818

19-
constructor(private config: IConfig) {}
19+
constructor(private config: IConfig) {
20+
this.healthCode = this.config.health.healthz.unhealthyStatus;
21+
}
2022

2123
public set isHealthy(val: boolean) {
2224
this.healthCode = val

src/protections/BasicFlooding.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export class BasicFloodingProtection
163163
) {
164164
super(description, capabilities, protectedRoomsSet, {});
165165
this.userConsequences = capabilities.userConsequences;
166+
this.eventConsequences = capabilities.eventConsequences;
166167
}
167168

168169
public async handleTimelineEvent(

src/protections/MessageIsVoice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { LogLevel } from "matrix-bot-sdk";
1212
import {
1313
AbstractProtection,
1414
ActionResult,
15-
CapabilitySet,
1615
EventConsequences,
1716
Ok,
1817
ProtectedRoomsSet,
@@ -80,11 +79,12 @@ export class MessageIsVoiceProtection
8079
private readonly eventConsequences: EventConsequences;
8180
constructor(
8281
description: MessageIsVoiceDescription,
83-
capabilities: CapabilitySet,
82+
capabilities: MessageIsVoiceCapabilities,
8483
protectedRoomsSet: ProtectedRoomsSet,
8584
private readonly draupnir: Draupnir
8685
) {
8786
super(description, capabilities, protectedRoomsSet, {});
87+
this.eventConsequences = capabilities.eventConsequences;
8888
}
8989

9090
public async handleTimelineEvent(

src/queues/ThrottlingQueue.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ export class ThrottlingQueue {
2727
*/
2828
private timeout: ReturnType<typeof setTimeout> | null;
2929

30-
/**
31-
* How long we should wait between the completion of a tasks and the start of the next task.
32-
* Any >=0 number is good.
33-
*/
34-
private _delayMS: number;
35-
3630
/**
3731
* Construct an empty queue.
3832
*
@@ -43,7 +37,11 @@ export class ThrottlingQueue {
4337
*/
4438
constructor(
4539
private managementRoomOutput: ManagementRoomOutput,
46-
delayMS: number
40+
/**
41+
* How long we should wait between the completion of a tasks and the start of the next task.
42+
* Any >=0 number is good.
43+
*/
44+
private delayMS: number
4745
) {
4846
this.timeout = null;
4947
this.delayMS = delayMS;
@@ -125,7 +123,7 @@ export class ThrottlingQueue {
125123
}
126124
this.timeout = setTimeout(() => {
127125
void this.step();
128-
}, this._delayMS);
126+
}, this.delayMS);
129127
}
130128

131129
/**
@@ -148,20 +146,13 @@ export class ThrottlingQueue {
148146
*
149147
* This will be used next time a task is completed.
150148
*/
151-
set delayMS(delayMS: number) {
149+
public setDelayMS(delayMS: number) {
152150
if (delayMS < 0) {
153151
throw new TypeError(
154152
`Invalid delay ${delayMS}. Need a non-negative number of ms.`
155153
);
156154
}
157-
this._delayMS = delayMS;
158-
}
159-
160-
/**
161-
* Return the delay between completion of an event and the start of the next event.
162-
*/
163-
get delayMS(): number {
164-
return this._delayMS;
155+
this.delayMS = delayMS;
165156
}
166157

167158
/**

tsconfig.json

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
{
2-
"compilerOptions": {
3-
"alwaysStrict": true,
4-
"esModuleInterop": true,
5-
"exactOptionalPropertyTypes": true,
6-
"experimentalDecorators": true,
7-
"emitDecoratorMetadata": true,
8-
"module": "commonjs",
9-
"moduleResolution": "node",
10-
"newLine": "LF",
11-
"noImplicitAny": true,
12-
"noImplicitReturns": true,
13-
"noImplicitThis": true,
14-
"noUncheckedIndexedAccess": true,
15-
"noUnusedLocals": true,
16-
"outDir": "./lib",
17-
"sourceMap": true,
18-
"strictNullChecks": true,
19-
"target": "es2021",
20-
"types": [
21-
"node",
22-
"mocha"
23-
],
24-
"jsx": "react",
25-
"jsxFactory": "DeadDocumentJSX.JSXFactory"
26-
},
27-
"include": [
28-
"./src/**/*"
29-
],
2+
"compilerOptions": {
3+
"alwaysStrict": true,
4+
"esModuleInterop": true,
5+
"exactOptionalPropertyTypes": true,
6+
"experimentalDecorators": true,
7+
"emitDecoratorMetadata": true,
8+
"module": "commonjs",
9+
"moduleResolution": "node",
10+
"newLine": "LF",
11+
"noImplicitAny": true,
12+
"noImplicitReturns": true,
13+
"noImplicitThis": true,
14+
"noUncheckedIndexedAccess": true,
15+
"noUnusedLocals": true,
16+
"outDir": "./lib",
17+
"sourceMap": true,
18+
"strictNullChecks": true,
19+
"strictPropertyInitialization": true,
20+
"target": "es2021",
21+
"types": ["node", "mocha"],
22+
"jsx": "react",
23+
"jsxFactory": "DeadDocumentJSX.JSXFactory"
24+
},
25+
"include": ["./src/**/*"]
3026
}

0 commit comments

Comments
 (0)