summary refs log tree commit diff
path: root/src/util/schemas
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-01-20 18:10:47 +1100
committerGitHub <noreply@github.com>2023-01-20 18:10:47 +1100
commit084dc0be08555891cad4c2bb984822a62ec5ec9f (patch)
treeed2ca0fafefa2224ae32761f955f63935422a97d /src/util/schemas
parentfix: route file regex (#956) (diff)
downloadserver-084dc0be08555891cad4c2bb984822a62ec5ec9f.tar.xz
Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit

* Fix all ESLint errors

* Update GH workflow to check prettier and eslint
Diffstat (limited to 'src/util/schemas')
-rw-r--r--src/util/schemas/ChannelPermissionOverwriteSchema.ts3
-rw-r--r--src/util/schemas/IdentifySchema.ts12
-rw-r--r--src/util/schemas/LazyRequestSchema.ts8
-rw-r--r--src/util/schemas/MessageCreateSchema.ts9
-rw-r--r--src/util/schemas/UserSettingsSchema.ts2
-rw-r--r--src/util/schemas/Validator.ts10
6 files changed, 26 insertions, 18 deletions
diff --git a/src/util/schemas/ChannelPermissionOverwriteSchema.ts b/src/util/schemas/ChannelPermissionOverwriteSchema.ts
index 97fe9dee..62d0ad14 100644
--- a/src/util/schemas/ChannelPermissionOverwriteSchema.ts
+++ b/src/util/schemas/ChannelPermissionOverwriteSchema.ts
@@ -18,5 +18,4 @@
 
 import { ChannelPermissionOverwrite } from "@fosscord/util";
 
-export interface ChannelPermissionOverwriteSchema
-	extends ChannelPermissionOverwrite {}
+export type ChannelPermissionOverwriteSchema = ChannelPermissionOverwrite;
diff --git a/src/util/schemas/IdentifySchema.ts b/src/util/schemas/IdentifySchema.ts
index 18ab2b49..9bb14ca3 100644
--- a/src/util/schemas/IdentifySchema.ts
+++ b/src/util/schemas/IdentifySchema.ts
@@ -18,6 +18,8 @@
 
 import { ActivitySchema } from "@fosscord/util";
 
+// TODO: Need a way to allow camalCase and pascal_case without just duplicating the schema
+
 export const IdentifySchema = {
 	token: String,
 	$intents: BigInt, // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt
@@ -98,7 +100,7 @@ export interface IdentifySchema {
 		referring_domain_current?: string;
 		release_channel?: "stable" | "dev" | "ptb" | "canary";
 		client_build_number?: number;
-		client_event_source?: any;
+		client_event_source?: string;
 		client_version?: string;
 		system_locale?: string;
 	};
@@ -111,23 +113,23 @@ export interface IdentifySchema {
 	guild_subscriptions?: boolean;
 	capabilities?: number;
 	client_state?: {
-		guild_hashes?: any;
+		guild_hashes?: unknown;
 		highest_last_message_id?: string | number;
 		read_state_version?: number;
 		user_guild_settings_version?: number;
 		user_settings_version?: number;
 		useruser_guild_settings_version?: number;
 		private_channels_version?: number;
-		guild_versions?: any;
+		guild_versions?: unknown;
 		api_code_version?: number;
 	};
 	clientState?: {
-		guildHashes?: any;
+		guildHashes?: unknown;
 		highestLastMessageId?: string | number;
 		readStateVersion?: number;
 		userGuildSettingsVersion?: number;
 		useruserGuildSettingsVersion?: number;
-		guildVersions?: any;
+		guildVersions?: unknown;
 		apiCodeVersion?: number;
 	};
 	v?: number;
diff --git a/src/util/schemas/LazyRequestSchema.ts b/src/util/schemas/LazyRequestSchema.ts
index 02fe0d8b..7cf3fd36 100644
--- a/src/util/schemas/LazyRequestSchema.ts
+++ b/src/util/schemas/LazyRequestSchema.ts
@@ -22,8 +22,8 @@ export interface LazyRequestSchema {
 	activities?: boolean;
 	threads?: boolean;
 	typing?: true;
-	members?: any[];
-	thread_member_lists?: any[];
+	members?: unknown[];
+	thread_member_lists?: unknown[];
 }
 
 export const LazyRequestSchema = {
@@ -32,6 +32,6 @@ export const LazyRequestSchema = {
 	$channels: Object,
 	$typing: Boolean,
 	$threads: Boolean,
-	$members: [] as any[],
-	$thread_member_lists: [] as any[],
+	$members: [] as unknown[],
+	$thread_member_lists: [] as unknown[],
 };
diff --git a/src/util/schemas/MessageCreateSchema.ts b/src/util/schemas/MessageCreateSchema.ts
index 1dd5d32c..4ee6e738 100644
--- a/src/util/schemas/MessageCreateSchema.ts
+++ b/src/util/schemas/MessageCreateSchema.ts
@@ -18,6 +18,11 @@
 
 import { Embed } from "@fosscord/util";
 
+type Attachment = {
+	id: string;
+	filename: string;
+};
+
 export interface MessageCreateSchema {
 	type?: number;
 	content?: string;
@@ -41,11 +46,11 @@ export interface MessageCreateSchema {
 		fail_if_not_exists?: boolean;
 	};
 	payload_json?: string;
-	file?: any;
+	file?: { filename: string };
 	/**
 	TODO: we should create an interface for attachments
 	TODO: OpenWAAO<-->attachment-style metadata conversion
 	**/
-	attachments?: any[];
+	attachments?: Attachment[];
 	sticker_ids?: string[];
 }
diff --git a/src/util/schemas/UserSettingsSchema.ts b/src/util/schemas/UserSettingsSchema.ts
index e25588c4..5a590b02 100644
--- a/src/util/schemas/UserSettingsSchema.ts
+++ b/src/util/schemas/UserSettingsSchema.ts
@@ -18,4 +18,4 @@
 
 import { UserSettings } from "@fosscord/util";
 
-export interface UserSettingsSchema extends Partial<UserSettings> {}
+export type UserSettingsSchema = Partial<UserSettings>;
diff --git a/src/util/schemas/Validator.ts b/src/util/schemas/Validator.ts
index 26a88ef9..3190dd05 100644
--- a/src/util/schemas/Validator.ts
+++ b/src/util/schemas/Validator.ts
@@ -45,7 +45,7 @@ export const ajv = new Ajv({
 
 addFormats(ajv);
 
-export function validateSchema<G>(schema: string, data: G): G {
+export function validateSchema<G extends object>(schema: string, data: G): G {
 	const valid = ajv.validate(schema, normalizeBody(data));
 	if (!valid) throw ajv.errors;
 	return data;
@@ -55,13 +55,13 @@ export function validateSchema<G>(schema: string, data: G): G {
 // this removes null values as ajv doesn't treat them as undefined
 // normalizeBody allows to handle circular structures without issues
 // taken from https://github.com/serverless/serverless/blob/master/lib/classes/ConfigSchemaHandler/index.js#L30 (MIT license)
-export const normalizeBody = (body: any = {}) => {
+export const normalizeBody = (body: object = {}) => {
 	const normalizedObjectsSet = new WeakSet();
-	const normalizeObject = (object: any) => {
+	const normalizeObject = (object: object) => {
 		if (normalizedObjectsSet.has(object)) return;
 		normalizedObjectsSet.add(object);
 		if (Array.isArray(object)) {
-			for (const [index, value] of object.entries()) {
+			for (const [, value] of object.entries()) {
 				if (typeof value === "object") normalizeObject(value);
 			}
 		} else {
@@ -75,6 +75,8 @@ export const normalizeBody = (body: any = {}) => {
 						key === "discovery_splash"
 					)
 						continue;
+					// eslint-disable-next-line @typescript-eslint/ban-ts-comment
+					//@ts-ignore
 					delete object[key];
 				} else if (typeof value === "object") {
 					normalizeObject(value);