summary refs log tree commit diff
path: root/gateway
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-20 23:34:54 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-20 23:34:54 +0200
commitcdbb54bb3c5915556cd69b44a9eaef49c3d19d50 (patch)
treecf4ceb6f2cb52e285c6e3c2c7c173104ebe6c0cc /gateway
parentMerge branch 'master' into unittests (diff)
downloadserver-cdbb54bb3c5915556cd69b44a9eaef49c3d19d50.tar.xz
:art: rewrite imports
Diffstat (limited to 'gateway')
-rw-r--r--gateway/package-lock.json47
-rw-r--r--gateway/package.json1
-rw-r--r--gateway/src/events/Close.ts2
-rw-r--r--gateway/src/events/Connection.ts11
-rw-r--r--gateway/src/events/Message.ts3
-rw-r--r--gateway/src/listener/listener.ts7
-rw-r--r--gateway/src/opcodes/Heartbeat.ts5
-rw-r--r--gateway/src/opcodes/Identify.ts16
-rw-r--r--gateway/src/opcodes/LazyRequest.ts5
-rw-r--r--gateway/src/opcodes/PresenceUpdate.ts3
-rw-r--r--gateway/src/opcodes/RequestGuildMembers.ts4
-rw-r--r--gateway/src/opcodes/Resume.ts5
-rw-r--r--gateway/src/opcodes/VoiceStateUpdate.ts4
-rw-r--r--gateway/src/opcodes/index.ts3
-rw-r--r--gateway/src/opcodes/instanceOf.ts3
-rw-r--r--gateway/src/util/Send.ts6
-rw-r--r--gateway/src/util/WebSocket.ts4
-rw-r--r--gateway/src/util/setHeartbeat.ts2
-rw-r--r--gateway/tsconfig.json1
19 files changed, 83 insertions, 49 deletions
diff --git a/gateway/package-lock.json b/gateway/package-lock.json
index df97d858..7b9c8d3a 100644
--- a/gateway/package-lock.json
+++ b/gateway/package-lock.json
@@ -32,6 +32,7 @@
 				"@types/node-fetch": "^2.5.12",
 				"@types/uuid": "^8.3.0",
 				"@types/ws": "^7.4.0",
+				"@zerollup/ts-transform-paths": "^1.7.18",
 				"ts-node-dev": "^1.1.6",
 				"ts-patch": "^1.4.4",
 				"typescript": "^4.2.3"
@@ -51,6 +52,7 @@
 				"jsonwebtoken": "^8.5.1",
 				"lambert-server": "^1.2.10",
 				"missing-native-js-functions": "^1.2.15",
+				"multer": "^1.4.3",
 				"node-fetch": "^2.6.1",
 				"patch-package": "^6.4.7",
 				"pg": "^8.7.1",
@@ -65,6 +67,7 @@
 				"@types/amqplib": "^0.8.1",
 				"@types/jsonwebtoken": "^8.5.0",
 				"@types/mongoose-autopopulate": "^0.10.1",
+				"@types/multer": "^1.4.7",
 				"@types/node": "^14.17.9",
 				"@types/node-fetch": "^2.5.12",
 				"jest": "^27.0.6"
@@ -197,6 +200,30 @@
 			"resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.3.tgz",
 			"integrity": "sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw=="
 		},
+		"node_modules/@zerollup/ts-helpers": {
+			"version": "1.7.18",
+			"resolved": "https://registry.npmjs.org/@zerollup/ts-helpers/-/ts-helpers-1.7.18.tgz",
+			"integrity": "sha512-S9zN+y+i5yN/evfWquzSO3lubqPXIsPQf6p9OiPMpRxDx/0totPLF39XoRw48Dav5dSvbIE8D2eAPpXXJxvKwg==",
+			"dev": true,
+			"dependencies": {
+				"resolve": "^1.12.0"
+			},
+			"peerDependencies": {
+				"typescript": ">=3.7.2"
+			}
+		},
+		"node_modules/@zerollup/ts-transform-paths": {
+			"version": "1.7.18",
+			"resolved": "https://registry.npmjs.org/@zerollup/ts-transform-paths/-/ts-transform-paths-1.7.18.tgz",
+			"integrity": "sha512-YPVUxvWQVzRx1OBN0Pmkd58+R9FcfUJuwTaPUSoi5rKxuXMtxevTXdfi0w5mEaIH8b0DfL+wg0wFDHiJE+S2zA==",
+			"dev": true,
+			"dependencies": {
+				"@zerollup/ts-helpers": "^1.7.18"
+			},
+			"peerDependencies": {
+				"typescript": ">=3.7.2"
+			}
+		},
 		"node_modules/accepts": {
 			"version": "1.3.7",
 			"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
@@ -2690,6 +2717,7 @@
 				"@types/amqplib": "^0.8.1",
 				"@types/jsonwebtoken": "^8.5.0",
 				"@types/mongoose-autopopulate": "^0.10.1",
+				"@types/multer": "^1.4.7",
 				"@types/node": "^14.17.9",
 				"@types/node-fetch": "^2.5.12",
 				"ajv": "^8.6.2",
@@ -2701,6 +2729,7 @@
 				"jsonwebtoken": "^8.5.1",
 				"lambert-server": "^1.2.10",
 				"missing-native-js-functions": "^1.2.15",
+				"multer": "^1.4.3",
 				"node-fetch": "^2.6.1",
 				"patch-package": "^6.4.7",
 				"pg": "^8.7.1",
@@ -2834,6 +2863,24 @@
 			"resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.3.tgz",
 			"integrity": "sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw=="
 		},
+		"@zerollup/ts-helpers": {
+			"version": "1.7.18",
+			"resolved": "https://registry.npmjs.org/@zerollup/ts-helpers/-/ts-helpers-1.7.18.tgz",
+			"integrity": "sha512-S9zN+y+i5yN/evfWquzSO3lubqPXIsPQf6p9OiPMpRxDx/0totPLF39XoRw48Dav5dSvbIE8D2eAPpXXJxvKwg==",
+			"dev": true,
+			"requires": {
+				"resolve": "^1.12.0"
+			}
+		},
+		"@zerollup/ts-transform-paths": {
+			"version": "1.7.18",
+			"resolved": "https://registry.npmjs.org/@zerollup/ts-transform-paths/-/ts-transform-paths-1.7.18.tgz",
+			"integrity": "sha512-YPVUxvWQVzRx1OBN0Pmkd58+R9FcfUJuwTaPUSoi5rKxuXMtxevTXdfi0w5mEaIH8b0DfL+wg0wFDHiJE+S2zA==",
+			"dev": true,
+			"requires": {
+				"@zerollup/ts-helpers": "^1.7.18"
+			}
+		},
 		"accepts": {
 			"version": "1.3.7",
 			"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
diff --git a/gateway/package.json b/gateway/package.json
index f5e66a9a..595d0205 100644
--- a/gateway/package.json
+++ b/gateway/package.json
@@ -23,6 +23,7 @@
 		"@types/node-fetch": "^2.5.12",
 		"@types/uuid": "^8.3.0",
 		"@types/ws": "^7.4.0",
+		"@zerollup/ts-transform-paths": "^1.7.18",
 		"ts-node-dev": "^1.1.6",
 		"ts-patch": "^1.4.4",
 		"typescript": "^4.2.3"
diff --git a/gateway/src/events/Close.ts b/gateway/src/events/Close.ts
index 4afe8352..1299ad5c 100644
--- a/gateway/src/events/Close.ts
+++ b/gateway/src/events/Close.ts
@@ -1,4 +1,4 @@
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { WebSocket } from "@fosscord/gateway";
 import { Message } from "./Message";
 import { Session } from "@fosscord/util";
 
diff --git a/gateway/src/events/Connection.ts b/gateway/src/events/Connection.ts
index b9d2d6a1..cb4fc85a 100644
--- a/gateway/src/events/Connection.ts
+++ b/gateway/src/events/Connection.ts
@@ -1,11 +1,14 @@
 import WS from "ws";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import {
+	setHeartbeat,
+	Send,
+	CLOSECODES,
+	OPCODES,
+	WebSocket,
+} from "@fosscord/gateway";
 import { IncomingMessage } from "http";
 import { Close } from "./Close";
 import { Message } from "./Message";
-import { setHeartbeat } from "@fosscord/gateway/util/setHeartbeat";
-import { Send } from "@fosscord/gateway/util/Send";
-import { CLOSECODES, OPCODES } from "@fosscord/gateway/util/Constants";
 import { createDeflate } from "zlib";
 import { URL } from "url";
 import { Session } from "@fosscord/util";
diff --git a/gateway/src/events/Message.ts b/gateway/src/events/Message.ts
index 66f98f1c..be95bd15 100644
--- a/gateway/src/events/Message.ts
+++ b/gateway/src/events/Message.ts
@@ -1,10 +1,9 @@
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { WebSocket, Payload, CLOSECODES, OPCODES } from "@fosscord/gateway";
 var erlpack: any;
 try {
 	erlpack = require("erlpack");
 } catch (error) {}
 import OPCodeHandlers from "../opcodes";
-import { Payload, CLOSECODES, OPCODES } from "@fosscord/gateway/util/Constants";
 import { instanceOf, Tuple } from "lambert-server";
 import { check } from "../opcodes/instanceOf";
 import WS from "ws";
diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts
index ae13cca7..0fa6bb08 100644
--- a/gateway/src/listener/listener.ts
+++ b/gateway/src/listener/listener.ts
@@ -9,12 +9,9 @@ import {
 	ListenEventOpts,
 	Member,
 } from "@fosscord/util";
-import { OPCODES } from "@fosscord/gateway/util/Constants";
-import { Send } from "@fosscord/gateway/util/Send";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { OPCODES, WebSocket, Send } from "@fosscord/gateway";
 import "missing-native-js-functions";
 import { Channel as AMQChannel } from "amqplib";
-import { In, Like } from "typeorm";
 import { Recipient } from "@fosscord/util";
 
 // TODO: close connection on Invalidated Token
@@ -116,7 +113,7 @@ async function consume(this: WebSocket, opts: EventOpts) {
 					.has("VIEW_CHANNEL")
 			)
 				return;
-			//No break needed here, we need to call the listenEvent function below
+		//No break needed here, we need to call the listenEvent function below
 		case "GUILD_CREATE":
 			this.events[id] = await listenEvent(id, consumer, listenOpts);
 			break;
diff --git a/gateway/src/opcodes/Heartbeat.ts b/gateway/src/opcodes/Heartbeat.ts
index 34d8ca74..46caee56 100644
--- a/gateway/src/opcodes/Heartbeat.ts
+++ b/gateway/src/opcodes/Heartbeat.ts
@@ -1,7 +1,4 @@
-import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants";
-import { Send } from "@fosscord/gateway/util/Send";
-import { setHeartbeat } from "@fosscord/gateway/util/setHeartbeat";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { Payload, Send, setHeartbeat, WebSocket } from "@fosscord/gateway";
 
 export async function onHeartbeat(this: WebSocket, data: Payload) {
 	// TODO: validate payload
diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts
index d91cd7f2..a58583ee 100644
--- a/gateway/src/opcodes/Identify.ts
+++ b/gateway/src/opcodes/Identify.ts
@@ -1,5 +1,10 @@
-import { CLOSECODES, Payload, OPCODES } from "@fosscord/gateway/util/Constants";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import {
+	WebSocket,
+	CLOSECODES,
+	Payload,
+	OPCODES,
+	genSessionId,
+} from "@fosscord/gateway";
 import {
 	Channel,
 	checkToken,
@@ -24,7 +29,6 @@ import { Send } from "@fosscord/gateway/util/Send";
 const experiments: any = [];
 import { check } from "./instanceOf";
 import { Recipient } from "@fosscord/util";
-import { genSessionId } from "@fosscord/gateway/util/SessionUtils";
 
 // TODO: bot sharding
 // TODO: check priviliged intents
@@ -98,7 +102,9 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 		//TODO is this needed? check if users in group dm that are not friends are sent in the READY event
 		//users = users.concat(x.channel.recipients);
 		if (x.channel.isDm()) {
-			x.channel.recipients = x.channel.recipients!.filter((x) => x.id !== this.user_id);
+			x.channel.recipients = x.channel.recipients!.filter(
+				(x) => x.id !== this.user_id
+			);
 		}
 		return x.channel;
 	});
@@ -109,7 +115,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 	if (!user) return this.close(CLOSECODES.Authentication_failed);
 
 	for (let relation of user.relationships) {
-		const related_user = relation.to
+		const related_user = relation.to;
 		const public_related_user = {
 			username: related_user.username,
 			discriminator: related_user.discriminator,
diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts
index 41ec3446..db00157f 100644
--- a/gateway/src/opcodes/LazyRequest.ts
+++ b/gateway/src/opcodes/LazyRequest.ts
@@ -2,13 +2,10 @@ import {
 	getPermission,
 	Member,
 	PublicMemberProjection,
-	PublicUserProjection,
 	Role,
 } from "@fosscord/util";
 import { LazyRequest } from "../schema/LazyRequest";
-import { OPCODES, Payload } from "@fosscord/gateway/util/Constants";
-import { Send } from "@fosscord/gateway/util/Send";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { WebSocket, Send, OPCODES, Payload } from "@fosscord/gateway";
 import { check } from "./instanceOf";
 import "missing-native-js-functions";
 
diff --git a/gateway/src/opcodes/PresenceUpdate.ts b/gateway/src/opcodes/PresenceUpdate.ts
index 4febbfcb..53d7b9d2 100644
--- a/gateway/src/opcodes/PresenceUpdate.ts
+++ b/gateway/src/opcodes/PresenceUpdate.ts
@@ -1,5 +1,4 @@
-import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { WebSocket, Payload } from "@fosscord/gateway";
 
 export function onPresenceUpdate(this: WebSocket, data: Payload) {
 	// return this.close(CLOSECODES.Unknown_error);
diff --git a/gateway/src/opcodes/RequestGuildMembers.ts b/gateway/src/opcodes/RequestGuildMembers.ts
index 9c1654fa..b80721dc 100644
--- a/gateway/src/opcodes/RequestGuildMembers.ts
+++ b/gateway/src/opcodes/RequestGuildMembers.ts
@@ -1,6 +1,4 @@
-import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants";
-
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { Payload, WebSocket } from "@fosscord/gateway";
 
 export function onRequestGuildMembers(this: WebSocket, data: Payload) {
 	// return this.close(CLOSECODES.Unknown_error);
diff --git a/gateway/src/opcodes/Resume.ts b/gateway/src/opcodes/Resume.ts
index e155c139..398cce25 100644
--- a/gateway/src/opcodes/Resume.ts
+++ b/gateway/src/opcodes/Resume.ts
@@ -1,7 +1,4 @@
-import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants";
-import { Send } from "@fosscord/gateway/util/Send";
-
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { WebSocket, Payload, Send } from "@fosscord/gateway";
 
 export async function onResume(this: WebSocket, data: Payload) {
 	console.log("Got Resume -> cancel not implemented");
diff --git a/gateway/src/opcodes/VoiceStateUpdate.ts b/gateway/src/opcodes/VoiceStateUpdate.ts
index 60803ec3..084c5766 100644
--- a/gateway/src/opcodes/VoiceStateUpdate.ts
+++ b/gateway/src/opcodes/VoiceStateUpdate.ts
@@ -1,6 +1,5 @@
 import { VoiceStateUpdateSchema } from "../schema/VoiceStateUpdateSchema";
-import { Payload } from "@fosscord/gateway/util/Constants";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { Payload, WebSocket, genVoiceToken } from "@fosscord/gateway";
 import { check } from "./instanceOf";
 import {
 	Config,
@@ -12,7 +11,6 @@ import {
 	VoiceState,
 	VoiceStateUpdateEvent,
 } from "@fosscord/util";
-import { genVoiceToken } from "@fosscord/gateway/util/SessionUtils";
 // TODO: check if a voice server is setup
 // Notice: Bot users respect the voice channel's user limit, if set. When the voice channel is full, you will not receive the Voice State Update or Voice Server Update events in response to your own Voice State Update. Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not.
 
diff --git a/gateway/src/opcodes/index.ts b/gateway/src/opcodes/index.ts
index c4069589..027739db 100644
--- a/gateway/src/opcodes/index.ts
+++ b/gateway/src/opcodes/index.ts
@@ -1,5 +1,4 @@
-import { Payload } from "@fosscord/gateway/util/Constants";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { WebSocket, Payload } from "@fosscord/gateway";
 import { onHeartbeat } from "./Heartbeat";
 import { onIdentify } from "./Identify";
 import { onLazyRequest } from "./LazyRequest";
diff --git a/gateway/src/opcodes/instanceOf.ts b/gateway/src/opcodes/instanceOf.ts
index 6d84ac21..37d513ad 100644
--- a/gateway/src/opcodes/instanceOf.ts
+++ b/gateway/src/opcodes/instanceOf.ts
@@ -1,6 +1,5 @@
 import { instanceOf } from "lambert-server";
-import { CLOSECODES } from "@fosscord/gateway/util/Constants";
-import WebSocket from "@fosscord/gateway/util/WebSocket";
+import { WebSocket, CLOSECODES } from "@fosscord/gateway";
 
 export function check(this: WebSocket, schema: any, data: any) {
 	try {
diff --git a/gateway/src/util/Send.ts b/gateway/src/util/Send.ts
index 1b00e361..ff8aefc9 100644
--- a/gateway/src/util/Send.ts
+++ b/gateway/src/util/Send.ts
@@ -2,9 +2,7 @@ var erlpack: any;
 try {
 	erlpack = require("erlpack");
 } catch (error) {}
-import { Payload } from "@fosscord/gateway/util/Constants";
-
-import WebSocket from "./WebSocket";
+import { Payload, WebSocket } from "@fosscord/gateway";
 
 export async function Send(socket: WebSocket, data: Payload) {
 	let buffer: Buffer | string;
@@ -20,7 +18,7 @@ export async function Send(socket: WebSocket, data: Payload) {
 	}
 
 	return new Promise((res, rej) => {
-		socket.send(buffer, (err) => {
+		socket.send(buffer, (err: any) => {
 			if (err) return rej(err);
 			return res(null);
 		});
diff --git a/gateway/src/util/WebSocket.ts b/gateway/src/util/WebSocket.ts
index 15d1549f..b80265a7 100644
--- a/gateway/src/util/WebSocket.ts
+++ b/gateway/src/util/WebSocket.ts
@@ -3,7 +3,7 @@ import WS from "ws";
 import { Deflate } from "zlib";
 import { Channel } from "amqplib";
 
-interface WebSocket extends WS {
+export interface WebSocket extends WS {
 	version: number;
 	user_id: string;
 	session_id: string;
@@ -19,5 +19,3 @@ interface WebSocket extends WS {
 	permissions: Record<string, Permissions>;
 	events: Record<string, Function>;
 }
-
-export default WebSocket;
diff --git a/gateway/src/util/setHeartbeat.ts b/gateway/src/util/setHeartbeat.ts
index 9f88b481..f6871cfe 100644
--- a/gateway/src/util/setHeartbeat.ts
+++ b/gateway/src/util/setHeartbeat.ts
@@ -1,5 +1,5 @@
 import { CLOSECODES } from "./Constants";
-import WebSocket from "./WebSocket";
+import { WebSocket } from "./WebSocket";
 
 // TODO: make heartbeat timeout configurable
 export function setHeartbeat(socket: WebSocket) {
diff --git a/gateway/tsconfig.json b/gateway/tsconfig.json
index c50bd77a..dd066383 100644
--- a/gateway/tsconfig.json
+++ b/gateway/tsconfig.json
@@ -70,6 +70,7 @@
 		"resolveJsonModule": true,
 		"baseUrl": ".",
 		"paths": {
+			"@fosscord/gateway": ["src/index"],
 			"@fosscord/gateway/*": ["src/*"],
 			"@fosscord/util/*": ["../util/src/*"]
 		},