From 57cfddac6c59f007595765427f2ce98621b49185 Mon Sep 17 00:00:00 2001 From: Paul Munteanu Date: Sun, 23 May 2021 05:33:48 +0300 Subject: [PATCH 1/4] Fix compilation with strictNullChecks: true --- src/events/Message.ts | 1 + src/listener/listener.ts | 6 +++--- src/util/Send.ts | 2 +- tsconfig.json | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/events/Message.ts b/src/events/Message.ts index 2c3305cb..51c5a294 100644 --- a/src/events/Message.ts +++ b/src/events/Message.ts @@ -21,6 +21,7 @@ export async function Message(this: WebSocket, buffer: Data) { if (this.encoding === "etf" && buffer instanceof Buffer) data = erlpack.unpack(buffer); else if (this.encoding === "json" && typeof buffer === "string") data = JSON.parse(buffer); + else return; check.call(this, PayloadSchema, data); diff --git a/src/listener/listener.ts b/src/listener/listener.ts index 8183f70c..b8ee84fd 100644 --- a/src/listener/listener.ts +++ b/src/listener/listener.ts @@ -19,7 +19,7 @@ export interface DispatchOpts { function getPipeline(this: WebSocket, guilds: string[], channels: string[] = []) { if (this.shard_count) { - guilds = guilds.filter((x) => (BigInt(x) >> 22n) % this.shard_count === this.shard_id); + guilds = guilds.filter((x) => (BigInt(x) >> 22n) % this.shard_count! === this.shard_id); } return [ @@ -37,7 +37,7 @@ function getPipeline(this: WebSocket, guilds: string[], channels: string[] = []) export async function setupListener(this: WebSocket) { const user = await UserModel.findOne({ id: this.user_id }).lean().exec(); - var guilds = user.guilds; + var guilds = user!.guilds; const eventStream = new MongooseCache(db.collection("events"), getPipeline.call(this, guilds), { onlyEvents: true, @@ -60,7 +60,7 @@ export async function dispatch(this: WebSocket, document: Event, { eventStream, guilds.push(document.data.id); eventStream.changeStream(getPipeline.call(this, guilds)); } else if (document.event === "GUILD_DELETE") { - guilds.remove(document.guild_id); + guilds.remove(document.guild_id!); eventStream.changeStream(getPipeline.call(this, guilds)); } else if (document.event === "CHANNEL_DELETE") channel_id = null; if (document.guild_id && !this.intents.has("GUILDS")) return; diff --git a/src/util/Send.ts b/src/util/Send.ts index 09e947a5..be25ac4f 100644 --- a/src/util/Send.ts +++ b/src/util/Send.ts @@ -11,7 +11,7 @@ export async function Send(socket: WebSocket, data: Payload) { if (socket.encoding === "etf") buffer = erlpack.pack(data); // TODO: encode circular object else if (socket.encoding === "json") buffer = JSON.stringify(data); - + else return; // TODO: compression if (socket.deflate) { socket.deflate.write(buffer); diff --git a/tsconfig.json b/tsconfig.json index 279cbbf1..fd2c21ea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,7 +29,7 @@ /* Strict Type-Checking Options */ "strict": false /* Enable all strict type-checking options. */, "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, - // "strictNullChecks": true, /* Enable strict null checks. */ + "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ "strictPropertyInitialization": false /* Enable strict checking of property initialization in classes. */, From f5461b5420a9bf2d22bc16ddacfeb577350d6f06 Mon Sep 17 00:00:00 2001 From: Paul Munteanu Date: Sat, 29 May 2021 21:36:19 +0300 Subject: [PATCH 2/4] Compile TS during Docker image build --- Dockerfile | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b2329233..48f9dd36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,5 +8,6 @@ RUN apk --no-cache --virtual build-dependencies add \ RUN npm install RUN apk del build-dependencies COPY . . +RUN npm run build EXPOSE 3002 CMD ["npm", "start"] \ No newline at end of file diff --git a/package.json b/package.json index c5f3df24..c50fcbc5 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "npm run build && node dist/", + "start": "node dist/", "build": "npx tsc -b .", "dev": "tsnd --respawn src/index.ts" }, From cec472089c4b9e60610cf66f28212795aa53f9d8 Mon Sep 17 00:00:00 2001 From: Paul Munteanu Date: Sat, 29 May 2021 22:26:44 +0300 Subject: [PATCH 3/4] Build on start for the CONTRIBUTORS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c50fcbc5..c5f3df24 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "node dist/", + "start": "npm run build && node dist/", "build": "npx tsc -b .", "dev": "tsnd --respawn src/index.ts" }, From c65d28e18163ca6195a46a6f58f90401ed6fc514 Mon Sep 17 00:00:00 2001 From: Paul Munteanu Date: Sat, 29 May 2021 22:41:50 +0300 Subject: [PATCH 4/4] Dockerfile: run app instead of recompiling --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 48f9dd36..a69b2956 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ RUN apk del build-dependencies COPY . . RUN npm run build EXPOSE 3002 -CMD ["npm", "start"] \ No newline at end of file +CMD ["node", "dist/"] \ No newline at end of file