This commit is contained in:
sk1982 2024-03-12 06:45:48 -04:00
parent 10d3d05781
commit f72005af77
5 changed files with 3519 additions and 0 deletions

29
src/db.ts Normal file
View File

@ -0,0 +1,29 @@
import { DB } from '@/types/db';
import { createPool } from 'mysql2';
import { Generated, Kysely, MysqlDialect } from 'kysely';
const createDb = () => {
if ((globalThis as any).db)
return (globalThis as any).db as Kysely<GeneratedDB>;
const dialect = new MysqlDialect({
pool: createPool(process.env.DATABASE_URL as string)
});
if (process.env.NODE_ENV === 'production')
delete process.env.DATABASE_URL;
return (globalThis as any).db = new Kysely<GeneratedDB>({ dialect });
}
type IdGenerated<C, T> = C extends 'id' ? Generated<T> : T;
// mark all id fields as generated
export type GeneratedDB = {
[Table in keyof DB]: {
[Column in keyof DB[Table]]: IdGenerated<Column, DB[Table][Column]>
}
};
export const db = createDb();

3458
src/types/db.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
declare module 'deep-is' {
export default function (a: any, b: any): boolean;
}

16
src/types/next-auth/index.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import NextAuth from 'next-auth';
import { UserPayload } from '@/types/user';
declare module 'next-auth' {
interface Session {
user: {
[T in keyof UserPayload]: UserPayload[T]
},
}
interface JWT {
user: {
[T in keyof UserPayload]: UserPayload[T]
}
}
}

13
src/types/user.ts Normal file
View File

@ -0,0 +1,13 @@
import { AimeUser } from '@/types/db';
export type DBUserPayload = Omit<AimeUser, 'password'> & {
chuni: boolean
};
export type UserPayload = {
[T in keyof DBUserPayload]: DBUserPayload[T] extends (Date | null) ? (string | null) :
DBUserPayload[T]
} & {
iat: number,
exp: number,
};