chore: fix eslint errors (fehmer) (#5166)

* fix eslint errors

* better type

* update type

* define type instead of ignoring errors

* add comment

---------

Co-authored-by: Miodec <jack@monkeytype.com>
This commit is contained in:
Christian Fehmer 2024-03-04 15:25:32 +01:00 committed by GitHub
parent f7fe0e3f01
commit 171133c795
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 48 additions and 25 deletions

View file

@ -117,7 +117,8 @@ type BooleanSchema = {
type StringSchema = {
type: "string";
} & BaseSchema;
type ArraySchema<T extends any[]> = {
type ArraySchema<T extends unknown[]> = {
type: "array";
items: Schema<T>[number];
} & BaseSchema;
@ -128,7 +129,7 @@ type ObjectSchema<T> = {
} & BaseSchema;
type Schema<T> = {
[P in keyof T]: T[P] extends any[]
[P in keyof T]: T[P] extends unknown[]
? ArraySchema<T[P]>
: T[P] extends number
? NumberSchema

View file

@ -24,16 +24,16 @@ const configLegacyProperties = [
export async function saveConfig(
uid: string,
config: object
config: SharedTypes.Config
): Promise<UpdateResult> {
const configChanges = _.mapKeys(config, (_value, key) => `config.${key}`);
const unset = _.fromPairs(
_.map(configLegacyProperties, (key) => [`config.${key}`, ""])
);
) as Record<string, "">;
return await db
.collection<any>("configs")
.collection<SharedTypes.Config>("configs")
.updateOne(
{ uid },
{ $set: configChanges, $unset: unset },
@ -41,11 +41,15 @@ export async function saveConfig(
);
}
export async function getConfig(uid: string): Promise<any> {
const config = await db.collection<any>("configs").findOne({ uid });
export async function getConfig(
uid: string
): Promise<SharedTypes.Config | null> {
const config = await db
.collection<SharedTypes.Config>("configs")
.findOne({ uid });
return config;
}
export async function deleteConfig(uid: string): Promise<any> {
return await db.collection<any>("configs").deleteOne({ uid });
export async function deleteConfig(uid: string): Promise<void> {
await db.collection<SharedTypes.Config>("configs").deleteOne({ uid });
}

View file

@ -34,7 +34,7 @@ export async function getPresets(uid: string): Promise<DBConfigPreset[]> {
export async function addPreset(
uid: string,
name: string,
config: any
config: SharedTypes.ConfigPreset
): Promise<PresetCreationResult> {
const presets = await getPresets(uid);
if (presets.length >= MAX_PRESETS) {
@ -56,7 +56,7 @@ export async function editPreset(
uid: string,
presetId: string,
name: string,
config: any
config: SharedTypes.ConfigPreset
): Promise<void> {
const presetUpdates =
config !== undefined && config !== null && Object.keys(config).length > 0

View file

@ -4,7 +4,7 @@ import { updateUserEmail } from "../utils/auth";
import { canFunboxGetPb, checkAndUpdatePb } from "../utils/pb";
import * as db from "../init/db";
import MonkeyError from "../utils/error";
import { Collection, ObjectId, WithId, Long, UpdateFilter } from "mongodb";
import { Collection, ObjectId, Long, UpdateFilter } from "mongodb";
import Logger from "../utils/logger";
import { flattenObjectDeep, isToday, isYesterday } from "../utils/misc";

View file

@ -7,6 +7,19 @@ import { NextFunction, Response } from "express";
import { MonkeyResponse, handleMonkeyResponse } from "../utils/monkey-response";
import { recordClientErrorByVersion } from "../utils/prometheus";
import { isDevEnvironment } from "../utils/misc";
import { ObjectId } from "mongodb";
type DBError = {
_id: ObjectId;
timestamp: number;
status: number;
uid: string;
message: string;
stack?: string;
endpoint: string;
method: string;
url: string;
};
async function errorHandlingMiddleware(
error: Error,
@ -56,7 +69,7 @@ async function errorHandlingMiddleware(
`${monkeyResponse.status} ${errorId} ${error.message} ${error.stack}`,
uid
);
await db.collection<any>("errors").insertOne({
await db.collection<DBError>("errors").insertOne({
_id: errorId,
timestamp: Date.now(),
status: monkeyResponse.status,

View file

@ -1,13 +1,14 @@
import { LbEntryWithRank } from "../utils/daily-leaderboards";
import { MonkeyQueue } from "./monkey-queue";
const QUEUE_NAME = "george-tasks";
type GeorgeTask = {
name: string;
args: any[];
args: unknown[];
};
function buildGeorgeTask(taskName: string, taskArgs: any[]): GeorgeTask {
function buildGeorgeTask(taskName: string, taskArgs: unknown[]): GeorgeTask {
return {
name: taskName,
args: taskArgs,
@ -60,7 +61,7 @@ class GeorgeQueue extends MonkeyQueue<GeorgeTask> {
}
async announceLeaderboardUpdate(
newRecords: any[],
newRecords: SharedTypes.LeaderboardEntry[],
leaderboardId: string
): Promise<void> {
const taskName = "announceLeaderboardUpdate";
@ -88,7 +89,7 @@ class GeorgeQueue extends MonkeyQueue<GeorgeTask> {
async announceDailyLeaderboardTopResults(
leaderboardId: string,
leaderboardTimestamp: number,
topResults: any[]
topResults: LbEntryWithRank[]
): Promise<void> {
const taskName = "announceDailyLeaderboardTopResults";

View file

@ -23,7 +23,7 @@ type GetRankResponse = {
entry: DailyLeaderboardEntry | null;
};
type LbEntryWithRank = {
export type LbEntryWithRank = {
rank: number;
} & DailyLeaderboardEntry;

View file

@ -17,7 +17,7 @@ type Log = {
timestamp: number;
uid: string;
event: string;
message: string;
message: string | Record<string, unknown>;
};
const customLevels = {
@ -87,7 +87,7 @@ const logger = createLogger({
const logToDb = async (
event: string,
message: any,
message: string | Record<string, unknown>,
uid?: string
): Promise<void> => {
const logsCollection = db.collection<Log>("logs");

View file

@ -30,7 +30,7 @@ export function kogasa(cov: number): number {
);
}
export function identity(value: any): string {
export function identity(value: unknown): string {
return Object.prototype.toString
.call(value)
.replace(/^\[object\s+([a-z]+)\]$/i, "$1")
@ -122,10 +122,10 @@ export function kogascore(wpm: number, acc: number, timestamp: number): number {
}
export function flattenObjectDeep(
obj: Record<string, any>,
obj: Record<string, unknown>,
prefix = ""
): Record<string, any> {
const result: Record<string, any> = {};
): Record<string, unknown> {
const result: Record<string, unknown> = {};
const keys = Object.keys(obj);
keys.forEach((key) => {
@ -134,7 +134,7 @@ export function flattenObjectDeep(
const newPrefix = prefix.length > 0 ? `${prefix}.${key}` : key;
if (_.isPlainObject(value)) {
const flattened = flattenObjectDeep(value);
const flattened = flattenObjectDeep(value as Record<string, unknown>);
const flattenedKeys = Object.keys(flattened);
if (flattenedKeys.length === 0) {

View file

@ -1,11 +1,15 @@
import { Response } from "express";
import { isCustomCode } from "../constants/monkey-status-codes";
//TODO FIX ANYS
export class MonkeyResponse {
message: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any;
status: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(message?: string, data?: any, status = 200) {
this.message = message ?? "ok";
this.data = data ?? null;