diff --git a/.gitignore b/.gitignore index c52cb223..778b90d8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ dist build config.js **/volumes -**/prisma/generated newrelic_agent.log .idea !**/locales/en/translation.json diff --git a/.prettierignore b/.prettierignore index 79f84204..4d788958 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,7 +10,6 @@ dist build config.js **/volumes -**/prisma/generated newrelic_agent.log .idea !**/locales/en/translation.json diff --git a/packages/dota/.gitignore b/packages/dota/.gitignore index a951b455..a81b5084 100644 --- a/packages/dota/.gitignore +++ b/packages/dota/.gitignore @@ -5,6 +5,5 @@ dist build config.js **/volumes -prisma/generated newrelic_agent.log .idea diff --git a/packages/dota/src/db/prisma.ts b/packages/dota/src/db/prisma.ts index 5b904c0c..0d3efb72 100644 --- a/packages/dota/src/db/prisma.ts +++ b/packages/dota/src/db/prisma.ts @@ -1,18 +1,13 @@ -import { PrismaClient as PrismaMongo } from '@dotabod/prisma/dist/mongo/index.js' import { PrismaClient as PrismaPsql } from '@dotabod/prisma/dist/psql/index.js' // allow global `var` declarations declare global { // eslint-disable-next-line no-var var prisma: PrismaPsql | undefined - // eslint-disable-next-line no-var - var prismaMongo: PrismaMongo | undefined } export const prisma = global.prisma ?? new PrismaPsql() -export const prismaMongo = global.prismaMongo ?? new PrismaMongo() if (process.env.NODE_ENV !== 'production') { global.prisma = prisma - global.prismaMongo = prismaMongo } diff --git a/packages/dota/src/db/supabase-types.ts b/packages/dota/src/db/supabase-types.ts index 8dfa401b..9cb1bc5f 100644 --- a/packages/dota/src/db/supabase-types.ts +++ b/packages/dota/src/db/supabase-types.ts @@ -1,3 +1,5 @@ +export type Tables = + Database['public']['Tables'][T]['Row'] export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[] export interface Database { diff --git a/packages/dota/src/db/watcher.ts b/packages/dota/src/db/watcher.ts index 2d3d805b..60d5ed66 100644 --- a/packages/dota/src/db/watcher.ts +++ b/packages/dota/src/db/watcher.ts @@ -1,4 +1,3 @@ -import { Account, Setting, SteamAccount, User } from '@dotabod/prisma/dist/psql/index.js' import { DBSettings } from '@dotabod/settings' import { clearCacheForUser } from '../dota/clearCacheForUser.js' @@ -10,6 +9,7 @@ import { toggleDotabod } from '../twitch/toggleDotabod.js' import { logger } from '../utils/logger.js' import getDBUser from './getDBUser.js' import supabase from './supabase.js' +import { Tables } from './supabase-types.js' class SetupSupabase { channel: any // ReturnType @@ -46,7 +46,7 @@ class SetupSupabase { .on( 'postgres_changes', { event: 'DELETE', schema: 'public', table: 'users' }, - async (payload: { old: User }) => { + async (payload: { old: Tables<'users'> }) => { if (this.IS_DEV && !this.DEV_CHANNELS.includes(payload.old.name)) return if (!this.IS_DEV && this.DEV_CHANNELS.includes(payload.old.name)) return @@ -64,7 +64,7 @@ class SetupSupabase { .on( 'postgres_changes', { event: 'UPDATE', schema: 'public', table: 'accounts' }, - async (payload: { new: Account; old: Account }) => { + async (payload: { new: Tables<'accounts'>; old: Tables<'accounts'> }) => { // watch the accounts table for requires_refresh to change from true to false // if it does, add the user to twurple authprovider again via addUser() if (this.IS_DEV && !this.DEV_CHANNELIDS.includes(payload.new?.providerAccountId)) return @@ -92,8 +92,8 @@ class SetupSupabase { if (this.IS_DEV && !this.DEV_CHANNELS.includes(payload.new.name)) return if (!this.IS_DEV && this.DEV_CHANNELS.includes(payload.new.name)) return - const newObj = payload.new as User - const oldObj = payload.old as User + const newObj: Tables<'users'> = payload.new + const oldObj: Tables<'users'> = payload.old const client = findUser(newObj.id) if (!client) return @@ -146,7 +146,7 @@ class SetupSupabase { 'postgres_changes', { event: '*', schema: 'public', table: 'settings' }, (payload: any) => { - const newObj = payload.new as Setting + const newObj: Tables<'settings'> = payload.new const client = findUser(newObj.userId) if (newObj.key === DBSettings.commandDisable) { @@ -196,8 +196,8 @@ class SetupSupabase { 'postgres_changes', { event: '*', schema: 'public', table: 'steam_accounts' }, async (payload: any) => { - const newObj = payload.new as SteamAccount - const oldObj = payload.old as SteamAccount + const newObj: Tables<'steam_accounts'> = payload.new + const oldObj: Tables<'steam_accounts'> = payload.old const client = findUser(newObj.userId || oldObj.userId) // Just here to update local memory diff --git a/packages/dota/tsconfig.json b/packages/dota/tsconfig.json index 60fe9e79..c0e36a3c 100644 --- a/packages/dota/tsconfig.json +++ b/packages/dota/tsconfig.json @@ -13,7 +13,6 @@ "./.eslintrc.js" ], "exclude": [ - "prisma/generated", "node_modules", ], "ts-node": { diff --git a/packages/twitch/chat/.gitignore b/packages/twitch/chat/.gitignore index 3bc984c8..91a9e4ed 100644 --- a/packages/twitch/chat/.gitignore +++ b/packages/twitch/chat/.gitignore @@ -5,4 +5,3 @@ dist build config.js **/volumes -prisma/generated \ No newline at end of file diff --git a/packages/twitch/chat/src/db/prisma.ts b/packages/twitch/chat/src/db/prisma.ts deleted file mode 100644 index 0d19b534..00000000 --- a/packages/twitch/chat/src/db/prisma.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { PrismaClient as PrismaPsql } from '@dotabod/prisma/dist/psql/index.js' -// allow global `var` declarations -declare global { - // eslint-disable-next-line no-var - var prisma: PrismaPsql | undefined -} - -export const prisma = global.prisma ?? new PrismaPsql() - -if (process.env.NODE_ENV !== 'production') { - global.prisma = prisma -} diff --git a/packages/twitch/chat/src/db/supabase-types.ts b/packages/twitch/chat/src/db/supabase-types.ts index 8dfa401b..9cb1bc5f 100644 --- a/packages/twitch/chat/src/db/supabase-types.ts +++ b/packages/twitch/chat/src/db/supabase-types.ts @@ -1,3 +1,5 @@ +export type Tables = + Database['public']['Tables'][T]['Row'] export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[] export interface Database { diff --git a/packages/twitch/chat/src/db/watcher.ts b/packages/twitch/chat/src/db/watcher.ts index f9fe035a..eb857f31 100644 --- a/packages/twitch/chat/src/db/watcher.ts +++ b/packages/twitch/chat/src/db/watcher.ts @@ -1,5 +1,4 @@ -import { User } from '@dotabod/prisma/dist/psql/index.js' - +import { Tables } from './supabase-types.js' import supabase from './supabase.js' import { chatClient } from '../index.js' @@ -8,9 +7,9 @@ const DEV_CHANNELS = process.env.DEV_CHANNELS?.split(',') ?? [] const channel = supabase.channel(`${IS_DEV ? 'dev-' : ''}twitch-chat`) channel - .on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'users' }, (payload) => { - const oldUser = payload.old as User - const newUser = payload.new as User + .on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'users' }, (payload: any) => { + const oldUser: Tables<'users'> = payload.old + const newUser: Tables<'users'> = payload.new if (IS_DEV && !DEV_CHANNELS.includes(newUser.name)) return if (!IS_DEV && DEV_CHANNELS.includes(newUser.name)) return diff --git a/packages/twitch/events/.gitignore b/packages/twitch/events/.gitignore index d42d7032..f7de20ae 100644 --- a/packages/twitch/events/.gitignore +++ b/packages/twitch/events/.gitignore @@ -5,7 +5,6 @@ dist build config.js **/volumes -prisma/generated private.key public.key -.idea \ No newline at end of file +.idea diff --git a/packages/twitch/events/src/db/prisma.ts b/packages/twitch/events/src/db/prisma.ts deleted file mode 100644 index 0d3efb72..00000000 --- a/packages/twitch/events/src/db/prisma.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { PrismaClient as PrismaPsql } from '@dotabod/prisma/dist/psql/index.js' - -// allow global `var` declarations -declare global { - // eslint-disable-next-line no-var - var prisma: PrismaPsql | undefined -} - -export const prisma = global.prisma ?? new PrismaPsql() - -if (process.env.NODE_ENV !== 'production') { - global.prisma = prisma -} diff --git a/packages/twitch/events/src/db/supabase-types.ts b/packages/twitch/events/src/db/supabase-types.ts index 8dfa401b..9cb1bc5f 100644 --- a/packages/twitch/events/src/db/supabase-types.ts +++ b/packages/twitch/events/src/db/supabase-types.ts @@ -1,3 +1,5 @@ +export type Tables = + Database['public']['Tables'][T]['Row'] export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[] export interface Database { diff --git a/packages/twitch/events/src/index.ts b/packages/twitch/events/src/index.ts index 186a656c..83c4bb3e 100644 --- a/packages/twitch/events/src/index.ts +++ b/packages/twitch/events/src/index.ts @@ -1,10 +1,10 @@ import http from 'http' -import { Account } from '@dotabod/prisma/dist/psql/index' import { EnvPortAdapter, EventSubHttpListener } from '@twurple/eventsub-http' import express from 'express' import { Server as SocketServer } from 'socket.io' +import { Tables } from './db/supabase-types.js' import { handleNewUser } from './handleNewUser.js' import { SubscribeEvents } from './SubscribeEvents.js' import BotAPI from './twitch/lib/BotApiSingleton.js' @@ -88,7 +88,7 @@ webhookApp.post('/', express.json(), express.urlencoded({ extended: true }), (re } if (req.body.type === 'INSERT' && req.body.table === 'accounts') { - const user = req.body.record as Account + const user: Tables<'accounts'> = req.body.record if (IS_DEV && !DEV_CHANNELIDS.includes(user.providerAccountId)) return if (!IS_DEV && DEV_CHANNELIDS.includes(user.providerAccountId)) return diff --git a/runner.sh b/runner.sh index d080c2d4..51296316 100644 --- a/runner.sh +++ b/runner.sh @@ -49,7 +49,7 @@ gentypes() { for OUTPUT_DIR in "${OUTPUT_DIRS[@]}"; do OUTPUT_FILE="$OUTPUT_DIR/supabase-types.ts" npx supabase gen types typescript --project-id "$PROJECT_ID" --schema public >"$OUTPUT_FILE" - # Run prettier on the generated file + echo 'export type Tables = Database["public"]["Tables"][T]["Row"];' | cat - "$OUTPUT_FILE" >temp && mv temp "$OUTPUT_FILE" npx prettier --write "$OUTPUT_FILE" done }