From d022d9fcf6ba937dbfb710cf8a540ee18a9b9df4 Mon Sep 17 00:00:00 2001 From: aronmal Date: Wed, 28 Feb 2024 22:17:52 +0100 Subject: [PATCH] Chore: Replaced explicit with implicit types --- src/lib/responseBuilders.ts | 48 ++++++++----------------------------- src/types/db.d.ts | 11 +++++++++ src/types/lucia-auth.d.ts | 11 +-------- 3 files changed, 22 insertions(+), 48 deletions(-) create mode 100644 src/types/db.d.ts diff --git a/src/lib/responseBuilders.ts b/src/lib/responseBuilders.ts index 4bba2a8..105857f 100644 --- a/src/lib/responseBuilders.ts +++ b/src/lib/responseBuilders.ts @@ -1,20 +1,12 @@ import stringify from "json-stable-stringify"; import objectHash from "object-hash"; +import { guilds, matches, tpMessages } from "~/drizzle/schema"; +import { ExtractDataTypes, GetColumns } from "~/types/db"; export const buildMatches = ( - matches: { - id: number; - messageId: number; - guildId: number; - channelId: number; - createrId: number; - roleId: number; - matchType: string; - opponentName: string; - utc_ts: Date; - }[], + queryMatches: ExtractDataTypes>[], ) => - matches.map( + queryMatches.map( // eslint-disable-next-line @typescript-eslint/no-unused-vars ({ id, guildId, utc_ts, ...match }) => ({ ...match, @@ -22,32 +14,12 @@ export const buildMatches = ( }), ); -export function buildConfig(guildQuery: { - id: number; - timezone: string; - tpEnabled: boolean; - tpChannelId: number | null; - tpInterval: number; - tpRoles: boolean; - isAvailableRoleId: number | null; - wantsToBeNotifieRoledId: number | null; - tpMessages: { - messageId: number | null; - day: number; - guildId: number; - }[]; - matches: { - id: number; - messageId: number; - guildId: number; - channelId: number; - createrId: number; - roleId: number; - matchType: string; - opponentName: string; - utc_ts: Date; - }[]; -}) { +export function buildConfig( + guildQuery: ExtractDataTypes> & { + tpMessages: ExtractDataTypes>[]; + matches: ExtractDataTypes>[]; + }, +) { const { id, timezone, diff --git a/src/types/db.d.ts b/src/types/db.d.ts new file mode 100644 index 0000000..bb6a905 --- /dev/null +++ b/src/types/db.d.ts @@ -0,0 +1,11 @@ +import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core"; + +export type GetColumns = + T extends PgTableWithColumns ? Table["columns"] : never; + +export type ExtractDataTypes = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [K in keyof T]: T[K] extends PgColumn + ? ColumnConfig["data"] + : unknown; +}; diff --git a/src/types/lucia-auth.d.ts b/src/types/lucia-auth.d.ts index aea0005..880f727 100644 --- a/src/types/lucia-auth.d.ts +++ b/src/types/lucia-auth.d.ts @@ -1,6 +1,6 @@ -import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core"; import { users } from "~/drizzle/schema"; import { lucia } from "~/lib/auth"; +import { ExtractDataTypes, GetColumns } from "./db"; declare module "lucia" { // eslint-disable-next-line no-unused-vars @@ -10,15 +10,6 @@ declare module "lucia" { } } -type GetColumns = - T extends PgTableWithColumns ? First["columns"] : never; - -type ExtractDataTypes = { - [K in keyof T]: T[K] extends PgColumn - ? DataType["data"] - : never; -}; - interface DatabaseUserAttributes extends ExtractDataTypes> { warst: string;