Chore: Replaced explicit with implicit types

This commit is contained in:
Aron Malcher 2024-02-28 22:17:52 +01:00
parent b28d381948
commit d022d9fcf6
Signed by: aronmal
GPG key ID: 816B7707426FC612
3 changed files with 22 additions and 48 deletions

View file

@ -1,20 +1,12 @@
import stringify from "json-stable-stringify"; import stringify from "json-stable-stringify";
import objectHash from "object-hash"; import objectHash from "object-hash";
import { guilds, matches, tpMessages } from "~/drizzle/schema";
import { ExtractDataTypes, GetColumns } from "~/types/db";
export const buildMatches = ( export const buildMatches = (
matches: { queryMatches: ExtractDataTypes<GetColumns<typeof matches>>[],
id: number;
messageId: number;
guildId: number;
channelId: number;
createrId: number;
roleId: number;
matchType: string;
opponentName: string;
utc_ts: Date;
}[],
) => ) =>
matches.map( queryMatches.map(
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
({ id, guildId, utc_ts, ...match }) => ({ ({ id, guildId, utc_ts, ...match }) => ({
...match, ...match,
@ -22,32 +14,12 @@ export const buildMatches = (
}), }),
); );
export function buildConfig(guildQuery: { export function buildConfig(
id: number; guildQuery: ExtractDataTypes<GetColumns<typeof guilds>> & {
timezone: string; tpMessages: ExtractDataTypes<GetColumns<typeof tpMessages>>[];
tpEnabled: boolean; matches: ExtractDataTypes<GetColumns<typeof matches>>[];
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;
}[];
}) {
const { const {
id, id,
timezone, timezone,

11
src/types/db.d.ts vendored Normal file
View file

@ -0,0 +1,11 @@
import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core";
export type GetColumns<T> =
T extends PgTableWithColumns<infer Table> ? Table["columns"] : never;
export type ExtractDataTypes<T> = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[K in keyof T]: T[K] extends PgColumn<infer ColumnConfig, any, any>
? ColumnConfig["data"]
: unknown;
};

View file

@ -1,6 +1,6 @@
import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core";
import { users } from "~/drizzle/schema"; import { users } from "~/drizzle/schema";
import { lucia } from "~/lib/auth"; import { lucia } from "~/lib/auth";
import { ExtractDataTypes, GetColumns } from "./db";
declare module "lucia" { declare module "lucia" {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
@ -10,15 +10,6 @@ declare module "lucia" {
} }
} }
type GetColumns<T> =
T extends PgTableWithColumns<infer First> ? First["columns"] : never;
type ExtractDataTypes<T> = {
[K in keyof T]: T[K] extends PgColumn<infer DataType, never, never>
? DataType["data"]
: never;
};
interface DatabaseUserAttributes interface DatabaseUserAttributes
extends ExtractDataTypes<GetColumns<typeof users>> { extends ExtractDataTypes<GetColumns<typeof users>> {
warst: string; warst: string;