Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable react-refresh/only-export-components */
import type { Metadata, Viewport } from "next"
import Script from "next/script"
import { Inter } from "next/font/google"

import { cn } from "@/lib/utils"
import { getSiteUrl, siteProfile } from "@/lib/site"
import { Providers } from "@/components/providers"

Expand All @@ -14,8 +12,6 @@ const metadataBase = new URL(getSiteUrl())
const siteName = siteProfile.name
const siteDescription = siteProfile.defaultDescription

const inter = Inter({ subsets: ["latin"] })

export const metadata: Metadata = {
metadataBase,
applicationName: siteName,
Expand Down Expand Up @@ -187,7 +183,7 @@ export default function RootLayout({
}>) {
return (
<html lang="en" suppressHydrationWarning>
<body className={cn(inter.className, "min-h-screen bg-background text-foreground antialiased")}>
<body className="min-h-screen bg-background text-foreground antialiased font-sans">
<Providers>{children}</Providers>
<Script id="structured-data" type="application/ld+json">
{JSON.stringify(structuredData)}
Expand Down
57 changes: 30 additions & 27 deletions lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,38 @@ function createStubClient(): PrismaClientType {
},
}

const createModelProxy = () =>
new Proxy(
{},
{
get(_, property) {
if (typeof property !== "string") {
return asyncError
}

const fallback = readFallbacks[property]
return fallback ?? asyncError
},
const createModelProxy = (): PrismaClientType[keyof PrismaClientType] =>
new Proxy({} as PrismaClientType[keyof PrismaClientType], {
get(_, property) {
if (typeof property !== "string") {
return asyncError
}

const fallback = readFallbacks[property]
return fallback ?? asyncError
},
)
})

const base = {
const proxyTarget = {
$connect: asyncError,
$disconnect: asyncError,
$use: syncError,
$on: syncError,
$transaction: asyncError,
} as Record<string, unknown>
$transaction: async (...args: unknown[]) => {
notifyStubUsage()
throw new Error(stubWarning)
},
} as PrismaClientType

return new Proxy(base, {
get(target, property) {
return new Proxy(proxyTarget, {
get(target, property, receiver) {
if (property in target) {
return target[property as keyof typeof target]
return Reflect.get(target, property, receiver)
}

return createModelProxy()
},
}) as PrismaClientType
})
}

let PrismaClientCtor: PrismaClientConstructor | undefined
Expand All @@ -102,15 +102,18 @@ try {
}
}

const prisma =
globalForPrisma.prisma ||
(PrismaClientCtor
? new PrismaClientCtor({
const hasDatabaseUrl = Boolean(process.env.DATABASE_URL)
const shouldUseStub = !PrismaClientCtor || !hasDatabaseUrl

const prisma: PrismaClientType =
globalForPrisma.prisma ??
(shouldUseStub
? createStubClient()
: new PrismaClientCtor!({
log: process.env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
})
: createStubClient())
}))

if (PrismaClientCtor) {
if (!shouldUseStub) {
registerPrismaRealtime(prisma as PrismaClientType)
}

Expand Down
10 changes: 7 additions & 3 deletions types/prisma.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
declare module "@prisma/client" {
export type Prisma = Record<string, unknown>

export type PrismaPromise<T = unknown> = Promise<T>

export class PrismaClient {
constructor(...args: unknown[])
$connect(): Promise<void>
$disconnect(): Promise<void>
$connect(): PrismaPromise<void>
$disconnect(): PrismaPromise<void>
$use(...args: unknown[]): void
[key: string]: unknown
$on(event: string, handler: (...args: unknown[]) => void): void
$transaction(...args: any[]): Promise<any>
[key: string]: any
}
}