diff --git a/frontends/nextjs/src/lib/compiler/index.ts b/frontends/nextjs/src/lib/compiler/index.ts index 9810bb5fd..a07eb5e29 100644 --- a/frontends/nextjs/src/lib/compiler/index.ts +++ b/frontends/nextjs/src/lib/compiler/index.ts @@ -36,7 +36,7 @@ export async function compile(source: string, options?: CompileOptions): Promise return { code: result.code, - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition map: (result.map !== null && result.map !== undefined && result.map !== '') ? result.map : undefined, } } catch (error) { diff --git a/frontends/nextjs/src/lib/config/prisma.ts b/frontends/nextjs/src/lib/config/prisma.ts index 2c5b33cf9..6870641cc 100644 --- a/frontends/nextjs/src/lib/config/prisma.ts +++ b/frontends/nextjs/src/lib/config/prisma.ts @@ -6,8 +6,8 @@ import { PrismaClient } from '@prisma/client' import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3' -const globalForPrisma = globalThis as unknown as { - prisma: PrismaClient | undefined +const globalForPrisma = globalThis as { + prisma?: PrismaClient } const isTestEnv = process.env.NODE_ENV === 'test' || process.env.VITEST === 'true' @@ -32,9 +32,10 @@ const createMockPrisma = (): PrismaClient => { const createIntegrationPrisma = (): PrismaClient => { // For integration tests, use in-memory database via adapter factory - + const adapter = new PrismaBetterSqlite3({ url: ':memory:' }) - return new PrismaClient({ adapter }) + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + return new PrismaClient({ adapter }) as unknown as PrismaClient } const createProductionPrisma = (): PrismaClient => { @@ -54,16 +55,17 @@ const createProductionPrisma = (): PrismaClient => { try { // For Prisma 7, PrismaBetterSqlite3 is a FACTORY that takes config with url, not a client instance - + const adapter = new PrismaBetterSqlite3({ url: databaseUrl }) console.warn('[Prisma] Adapter factory created successfully') - + + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment const client = new PrismaClient({ adapter, log: process.env.NODE_ENV === 'development' ? ['error', 'warn', 'query'] : ['error'], - }) + }) as unknown as PrismaClient console.warn('[Prisma] PrismaClient created successfully') - + return client } catch (error) { console.error('[Prisma] Error creating Prisma client:', error) @@ -71,13 +73,16 @@ const createProductionPrisma = (): PrismaClient => { } } -export const prisma = +// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment +export const prisma = ( globalForPrisma.prisma ?? (isTestEnv ? (isIntegrationTest ? createIntegrationPrisma() : createMockPrisma()) : createProductionPrisma()) +) as PrismaClient + - if (process.env.NODE_ENV !== 'production' && (!isTestEnv || isIntegrationTest)) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment globalForPrisma.prisma = prisma } diff --git a/frontends/nextjs/src/lib/db/core/initialize-database.ts b/frontends/nextjs/src/lib/db/core/initialize-database.ts index 19ff6df33..b87bcfe91 100644 --- a/frontends/nextjs/src/lib/db/core/initialize-database.ts +++ b/frontends/nextjs/src/lib/db/core/initialize-database.ts @@ -5,6 +5,7 @@ import { prisma } from '../../config/prisma' */ export async function initializeDatabase(): Promise { try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access await prisma.$connect() // Database initialized successfully } catch (error) { diff --git a/frontends/nextjs/src/lib/middleware/auth-middleware.ts b/frontends/nextjs/src/lib/middleware/auth-middleware.ts index b79efb7fb..e464cbf5b 100644 --- a/frontends/nextjs/src/lib/middleware/auth-middleware.ts +++ b/frontends/nextjs/src/lib/middleware/auth-middleware.ts @@ -85,7 +85,7 @@ export async function authenticate( const user = await getCurrentUser() // Check if user is authenticated - if (user === null || user === undefined) { + if (user === null) { return { success: false, error: NextResponse.json( @@ -112,8 +112,7 @@ export async function authenticate( } // Run custom permission check if provided - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (customCheck !== null && customCheck !== undefined && !customCheck(user)) { + if (customCheck !== undefined && !customCheck(user)) { return { success: false, error: NextResponse.json( @@ -163,11 +162,10 @@ export async function requireAuth( options: AuthMiddlewareOptions = {} ): Promise { const { success, user, error } = await authenticate(request, options) - - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (!success || user === null || user === undefined) { + + if (!success) { throw new Error(error !== undefined ? 'Authentication failed' : 'Unknown authentication error') } - - return user + + return user as CurrentUser } diff --git a/frontends/nextjs/src/lib/ui-pages/load-page-from-db.ts b/frontends/nextjs/src/lib/ui-pages/load-page-from-db.ts index d2d4976a2..d7062a9aa 100644 --- a/frontends/nextjs/src/lib/ui-pages/load-page-from-db.ts +++ b/frontends/nextjs/src/lib/ui-pages/load-page-from-db.ts @@ -6,6 +6,7 @@ import type { PageConfig } from '../types/level-types' import { prisma } from '@/lib/config/prisma' export async function loadPageFromDb(path: string, tenantId?: string): Promise { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access const page = await prisma.pageConfig.findFirst({ where: { path,