diff --git a/.npmrc b/.npmrc index e69de29..f0c0c3d 100644 --- a/.npmrc +++ b/.npmrc @@ -0,0 +1 @@ +public-hoist-pattern[]=*prisma* diff --git a/apps/web/src/app/(auth)/login/actions.ts b/apps/web/src/app/(auth)/login/actions.ts index f160f99..18cb282 100644 --- a/apps/web/src/app/(auth)/login/actions.ts +++ b/apps/web/src/app/(auth)/login/actions.ts @@ -3,7 +3,7 @@ import { verify } from "@node-rs/argon2"; import { lucia } from "@zephyr/auth/auth"; import { type LoginValues, loginSchema } from "@zephyr/auth/validation"; -import prisma from "@zephyr/db/prisma"; +import { prisma } from "@zephyr/db"; import { isRedirectError } from "next/dist/client/components/redirect"; import { cookies } from "next/headers"; import { redirect } from "next/navigation"; diff --git a/apps/web/src/app/(auth)/signup/actions.ts b/apps/web/src/app/(auth)/signup/actions.ts index 338aacc..0b1db28 100644 --- a/apps/web/src/app/(auth)/signup/actions.ts +++ b/apps/web/src/app/(auth)/signup/actions.ts @@ -8,7 +8,7 @@ import { redirect } from "next/navigation"; import { lucia } from "@zephyr/auth/auth"; import { type SignUpValues, signUpSchema } from "@zephyr/auth/validation"; -import prisma from "@zephyr/db/prisma"; +import { prisma } from "@zephyr/db"; export async function signUp( credentials: SignUpValues diff --git a/apps/web/src/app/api/posts/[id]/vote/route.ts b/apps/web/src/app/api/posts/[id]/vote/route.ts index d1475b2..ff20b1e 100644 --- a/apps/web/src/app/api/posts/[id]/vote/route.ts +++ b/apps/web/src/app/api/posts/[id]/vote/route.ts @@ -1,7 +1,7 @@ import type { NextRequest } from "next/server"; import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; +import { prisma } from "@zephyr/db"; export async function POST( req: NextRequest, diff --git a/apps/web/src/app/api/posts/following/route.ts b/apps/web/src/app/api/posts/following/route.ts index 1637c21..f742111 100644 --- a/apps/web/src/app/api/posts/following/route.ts +++ b/apps/web/src/app/api/posts/following/route.ts @@ -1,8 +1,7 @@ import type { NextRequest } from "next/server"; import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; -import { type PostsPage, getPostDataInclude } from "@zephyr/db/prisma/client"; +import { type PostsPage, getPostDataInclude, prisma } from "@zephyr/db"; export async function GET(req: NextRequest) { try { diff --git a/apps/web/src/app/api/posts/for-you/route.ts b/apps/web/src/app/api/posts/for-you/route.ts index d3996dc..168ee2a 100644 --- a/apps/web/src/app/api/posts/for-you/route.ts +++ b/apps/web/src/app/api/posts/for-you/route.ts @@ -1,8 +1,7 @@ import type { NextRequest } from "next/server"; import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; -import { type PostsPage, getPostDataInclude } from "@zephyr/db/prisma/client"; +import { type PostsPage, getPostDataInclude, prisma } from "@zephyr/db"; export async function GET(req: NextRequest) { try { diff --git a/apps/web/src/app/api/users/[userId]/followers/route.ts b/apps/web/src/app/api/users/[userId]/followers/route.ts index 036d590..0350b21 100644 --- a/apps/web/src/app/api/users/[userId]/followers/route.ts +++ b/apps/web/src/app/api/users/[userId]/followers/route.ts @@ -1,6 +1,6 @@ import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; -import type { FollowerInfo } from "@zephyr/db/prisma/client"; +import type { FollowerInfo } from "@zephyr/db"; +import { prisma } from "@zephyr/db"; export async function GET( _req: Request, diff --git a/apps/web/src/app/api/users/[userId]/posts/route.ts b/apps/web/src/app/api/users/[userId]/posts/route.ts index 8998e10..bbab7b2 100644 --- a/apps/web/src/app/api/users/[userId]/posts/route.ts +++ b/apps/web/src/app/api/users/[userId]/posts/route.ts @@ -1,8 +1,7 @@ import type { NextRequest } from "next/server"; import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; -import { type PostsPage, getPostDataInclude } from "@zephyr/db/prisma/client"; +import { type PostsPage, getPostDataInclude, prisma } from "@zephyr/db"; export async function GET( req: NextRequest, diff --git a/apps/web/src/app/api/users/[userId]/profile/route.ts b/apps/web/src/app/api/users/[userId]/profile/route.ts index cba49ad..8ce37ed 100644 --- a/apps/web/src/app/api/users/[userId]/profile/route.ts +++ b/apps/web/src/app/api/users/[userId]/profile/route.ts @@ -1,8 +1,7 @@ import type { NextRequest } from "next/server"; import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; -import { getUserDataSelect } from "@zephyr/db/prisma/client"; +import { getUserDataSelect, prisma } from "@zephyr/db"; export async function GET( _req: NextRequest, diff --git a/apps/web/src/app/api/users/followed/route.ts b/apps/web/src/app/api/users/followed/route.ts index 78b2e81..5ed6d1a 100644 --- a/apps/web/src/app/api/users/followed/route.ts +++ b/apps/web/src/app/api/users/followed/route.ts @@ -1,6 +1,5 @@ import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; -import { getUserDataSelect } from "@zephyr/db/prisma/client"; +import { getUserDataSelect, prisma } from "@zephyr/db"; export async function GET() { try { diff --git a/apps/web/src/app/api/users/username-to-id/[username]/route.ts b/apps/web/src/app/api/users/username-to-id/[username]/route.ts index 73d0b17..5f4234b 100644 --- a/apps/web/src/app/api/users/username-to-id/[username]/route.ts +++ b/apps/web/src/app/api/users/username-to-id/[username]/route.ts @@ -1,7 +1,7 @@ import type { NextRequest } from "next/server"; import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; +import { prisma } from "@zephyr/db"; export async function GET( _req: NextRequest, diff --git a/apps/web/src/components/Home/FeedView.tsx b/apps/web/src/components/Home/FeedView.tsx index 83072ce..4278f7a 100644 --- a/apps/web/src/components/Home/FeedView.tsx +++ b/apps/web/src/components/Home/FeedView.tsx @@ -6,7 +6,7 @@ import React, { useEffect, useRef, useState } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import type { PostData } from "@zephyr/db/prisma/client"; +import type { PostData } from "@zephyr/db"; import PostCard from "./feedview/postCard"; import StoryCard from "./feedview/storyCard"; diff --git a/apps/web/src/components/Home/ForYouFeed.tsx b/apps/web/src/components/Home/ForYouFeed.tsx index 7baea24..f4e1637 100644 --- a/apps/web/src/components/Home/ForYouFeed.tsx +++ b/apps/web/src/components/Home/ForYouFeed.tsx @@ -6,7 +6,7 @@ import { Loader2 } from "lucide-react"; import kyInstance from "@/lib/ky"; import InfiniteScrollContainer from "@zephyr-ui/Layouts/InfiniteScrollContainer"; import PostsLoadingSkeleton from "@zephyr-ui/Posts/PostsLoadingSkeleton"; -import type { PostsPage } from "@zephyr/db/prisma/client"; +import type { PostsPage } from "@zephyr/db"; import FeedView from "./FeedView"; diff --git a/apps/web/src/components/Home/feedview/postCard.tsx b/apps/web/src/components/Home/feedview/postCard.tsx index 4acc8f1..d7e894a 100644 --- a/apps/web/src/components/Home/feedview/postCard.tsx +++ b/apps/web/src/components/Home/feedview/postCard.tsx @@ -27,7 +27,7 @@ import { formatRelativeDate } from "@/lib/utils"; import { useVoteMutation } from "@/posts/aura/auraMutations"; import UserAvatar from "@zephyr-ui/Layouts/UserAvatar"; import PostMoreButton from "@zephyr-ui/Posts/PostMoreButton"; -import type { PostData } from "@zephyr/db/prisma/client"; +import type { PostData } from "@zephyr/db"; interface PostCardProps { post: PostData; } diff --git a/apps/web/src/components/Home/sidebars/left/Friends.tsx b/apps/web/src/components/Home/sidebars/left/Friends.tsx index 0ea529a..4db76f8 100644 --- a/apps/web/src/components/Home/sidebars/left/Friends.tsx +++ b/apps/web/src/components/Home/sidebars/left/Friends.tsx @@ -7,10 +7,10 @@ import React from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardTitle } from "@/components/ui/card"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; +import type { UserData } from "@/db/client"; import { useFollowedUsers } from "@/hooks/userFollowerInfo"; import { useUnfollowUserMutation } from "@/hooks/userMutations"; import UserAvatar from "@zephyr-ui/Layouts/UserAvatar"; -import type { UserData } from "@zephyr/db/prisma/client"; import UnfollowUserDialog from "@zephyr-ui/Layouts/UnfollowUserDialog"; diff --git a/apps/web/src/components/Layouts/Following.tsx b/apps/web/src/components/Layouts/Following.tsx index 6a72267..8d5ec2a 100644 --- a/apps/web/src/components/Layouts/Following.tsx +++ b/apps/web/src/components/Layouts/Following.tsx @@ -6,7 +6,7 @@ import { Loader2 } from "lucide-react"; import kyInstance from "@/lib/ky"; import InfiniteScrollContainer from "@zephyr-ui/Layouts/InfiniteScrollContainer"; import PostsLoadingSkeleton from "@zephyr-ui/Posts/PostsLoadingSkeleton"; -import type { PostsPage } from "@zephyr/db/prisma/client"; +import type { PostsPage } from "@zephyr/db"; import FeedView from "@zephyr-ui/Home/FeedView"; diff --git a/apps/web/src/components/Layouts/UnfollowUserDialog.tsx b/apps/web/src/components/Layouts/UnfollowUserDialog.tsx index 431be0f..93617a1 100644 --- a/apps/web/src/components/Layouts/UnfollowUserDialog.tsx +++ b/apps/web/src/components/Layouts/UnfollowUserDialog.tsx @@ -11,7 +11,7 @@ import { DialogTitle } from "@/components/ui/dialog"; import { useUnfollowUserMutation } from "@/hooks/userMutations"; -import type { UserData } from "@zephyr/db/prisma/client"; +import type { UserData } from "@zephyr/db"; import LoadingButton from "@zephyr-ui/Auth/LoadingButton"; diff --git a/apps/web/src/components/Posts/DeletePostDialog.tsx b/apps/web/src/components/Posts/DeletePostDialog.tsx index 841fe23..ec40c63 100644 --- a/apps/web/src/components/Posts/DeletePostDialog.tsx +++ b/apps/web/src/components/Posts/DeletePostDialog.tsx @@ -8,7 +8,7 @@ import { DialogTitle } from "@/components/ui/dialog"; import { useDeletePostMutation } from "@/posts/mutations"; -import type { PostData } from "@zephyr/db/prisma/client"; +import type { PostData } from "@zephyr/db"; import LoadingButton from "@zephyr-ui/Auth/LoadingButton"; diff --git a/apps/web/src/components/Posts/PostMoreButton.tsx b/apps/web/src/components/Posts/PostMoreButton.tsx index c62b25a..3f05cb7 100644 --- a/apps/web/src/components/Posts/PostMoreButton.tsx +++ b/apps/web/src/components/Posts/PostMoreButton.tsx @@ -8,7 +8,7 @@ import { DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; -import type { PostData } from "@zephyr/db/prisma/client"; +import type { PostData } from "@zephyr/db"; import DeletePostDialog from "./DeletePostDialog"; diff --git a/apps/web/src/hooks/userFollowerInfo.ts b/apps/web/src/hooks/userFollowerInfo.ts index 960933b..85fa3fa 100644 --- a/apps/web/src/hooks/userFollowerInfo.ts +++ b/apps/web/src/hooks/userFollowerInfo.ts @@ -1,7 +1,7 @@ import { useQuery } from "@tanstack/react-query"; import kyInstance from "@/lib/ky"; -import type { FollowerInfo, UserData } from "@zephyr/db/prisma/client"; +import type { FollowerInfo, UserData } from "@zephyr/db"; export default function useFollowerInfo( userId: string, diff --git a/apps/web/src/hooks/userMutations.ts b/apps/web/src/hooks/userMutations.ts index 2a0156a..23ced2d 100644 --- a/apps/web/src/hooks/userMutations.ts +++ b/apps/web/src/hooks/userMutations.ts @@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; import { useToast } from "@/hooks/use-toast"; import kyInstance from "@/lib/ky"; -import type { UserData } from "@zephyr/db/prisma/client"; +import type { UserData } from "@zephyr/db"; async function followUser(userId: string): Promise { return kyInstance.post(`/api/users/${userId}/followers`).json(); diff --git a/apps/web/src/posts/actions.ts b/apps/web/src/posts/actions.ts index fa06bc6..780782f 100644 --- a/apps/web/src/posts/actions.ts +++ b/apps/web/src/posts/actions.ts @@ -1,7 +1,6 @@ "use server"; -import prisma from "@zephyr/db/prisma"; -import { getPostDataInclude } from "@zephyr/db/prisma/client"; +import { getPostDataInclude, prisma } from "@zephyr/db"; import { validateRequest } from "@zephyr/auth/auth"; diff --git a/apps/web/src/posts/aura/auraMutations.ts b/apps/web/src/posts/aura/auraMutations.ts index 5acbb72..e6bb556 100644 --- a/apps/web/src/posts/aura/auraMutations.ts +++ b/apps/web/src/posts/aura/auraMutations.ts @@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; import { useToast } from "@/hooks/use-toast"; import kyInstance from "@/lib/ky"; -import type { PostData } from "@zephyr/db/prisma/client"; +import type { PostData } from "@zephyr/db"; export function useVoteMutation() { const queryClient = useQueryClient(); diff --git a/apps/web/src/posts/editor/actions.ts b/apps/web/src/posts/editor/actions.ts index b89885b..c19123b 100644 --- a/apps/web/src/posts/editor/actions.ts +++ b/apps/web/src/posts/editor/actions.ts @@ -2,8 +2,7 @@ import { validateRequest } from "@zephyr/auth/auth"; import { createPostSchema } from "@zephyr/auth/validation"; -import prisma from "@zephyr/db/prisma"; -import { getPostDataInclude } from "@zephyr/db/prisma/client"; +import { getPostDataInclude, prisma } from "@zephyr/db"; export async function submitPost(input: string) { const { user } = await validateRequest(); diff --git a/apps/web/src/posts/editor/mutations.ts b/apps/web/src/posts/editor/mutations.ts index 1bc5756..2afe2fe 100644 --- a/apps/web/src/posts/editor/mutations.ts +++ b/apps/web/src/posts/editor/mutations.ts @@ -6,7 +6,7 @@ import { } from "@tanstack/react-query"; import { useToast } from "@/hooks/use-toast"; -import type { PostsPage } from "@zephyr/db/prisma/client"; +import type { PostsPage } from "@zephyr/db"; import { submitPost } from "./actions"; diff --git a/apps/web/src/posts/mutations.ts b/apps/web/src/posts/mutations.ts index 27cfc3e..07f44c7 100644 --- a/apps/web/src/posts/mutations.ts +++ b/apps/web/src/posts/mutations.ts @@ -7,7 +7,7 @@ import { import { usePathname, useRouter } from "next/navigation"; import { useToast } from "@/hooks/use-toast"; -import type { PostsPage } from "@zephyr/db/prisma/client"; +import type { PostsPage } from "@zephyr/db"; import { deletePost } from "./actions"; diff --git a/apps/web/src/state/TopicActions.tsx b/apps/web/src/state/TopicActions.tsx index 5628a04..53c8bfb 100644 --- a/apps/web/src/state/TopicActions.tsx +++ b/apps/web/src/state/TopicActions.tsx @@ -2,7 +2,7 @@ import { unstable_cache } from "next/cache"; -import prisma from "@zephyr/db/prisma"; +import { prisma } from "@zephyr/db"; export const getTrendingTopics = unstable_cache( async () => { diff --git a/apps/web/src/state/UserActions.tsx b/apps/web/src/state/UserActions.tsx index 9513bcd..81b657f 100644 --- a/apps/web/src/state/UserActions.tsx +++ b/apps/web/src/state/UserActions.tsx @@ -1,7 +1,7 @@ "use server"; import { validateRequest } from "@zephyr/auth/auth"; -import prisma from "@zephyr/db/prisma"; +import { prisma } from "@zephyr/db"; export async function getSuggestedConnections() { try { diff --git a/packages/auth/auth.ts b/packages/auth/auth.ts index 9089bc7..daf746e 100644 --- a/packages/auth/auth.ts +++ b/packages/auth/auth.ts @@ -1,5 +1,5 @@ import { PrismaAdapter } from "@lucia-auth/adapter-prisma"; -import { prisma } from "@zephyr/db/prisma"; +import { prisma } from "@zephyr/db"; import { Lucia, type Session, type User } from "lucia"; import { cookies } from "next/headers"; import { cache } from "react"; diff --git a/packages/db/index.ts b/packages/db/index.ts new file mode 100644 index 0000000..18eeb92 --- /dev/null +++ b/packages/db/index.ts @@ -0,0 +1,2 @@ +export * from "./src/client"; +export { default as prisma } from "./src/prisma"; diff --git a/packages/db/package.json b/packages/db/package.json index df0cf72..2d5ac94 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -3,9 +3,18 @@ "version": "0.0.1", "license": "AGPL-3.0", "private": true, + "exports": { + ".": "./index.ts" + }, "dependencies": { "@prisma/client": "^5.20.0" }, + "scripts": { + "db:generate": "prisma generate", + "db:migrate": "prisma migrate dev", + "db:studio": "prisma studio", + "db:push": "prisma db push --skip-generate" + }, "devDependencies": { "@types/node": "^22.7.5", "@zephyr/config": "workspace:*", diff --git a/packages/db/prisma/client.ts b/packages/db/src/client.ts similarity index 100% rename from packages/db/prisma/client.ts rename to packages/db/src/client.ts diff --git a/packages/db/prisma.ts b/packages/db/src/prisma.ts similarity index 100% rename from packages/db/prisma.ts rename to packages/db/src/prisma.ts index 186965e..cae2caa 100644 --- a/packages/db/prisma.ts +++ b/packages/db/src/prisma.ts @@ -10,6 +10,6 @@ declare global { const prisma = globalThis.prismaGlobal ?? prismaClientSingleton(); -export default prisma; - if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma; + +export default prisma; diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json index 569e134..70482af 100644 --- a/packages/db/tsconfig.json +++ b/packages/db/tsconfig.json @@ -6,5 +6,6 @@ "outDir": "dist", "baseUrl": "." }, - "include": ["./*.ts", "**/*.ts"] + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "tsup.config.ts"], + "exclude": ["node_modules"] } diff --git a/turbo.json b/turbo.json index 807e324..3230d06 100644 --- a/turbo.json +++ b/turbo.json @@ -2,8 +2,14 @@ "$schema": "https://turbo.build/schema.json", "ui": "tui", "tasks": { + "db:generate": { + "cache": false + }, + "db:push": { + "cache": false + }, "build": { - "dependsOn": ["^build"], + "dependsOn": ["^db:generate", "^build"], "inputs": ["$TURBO_DEFAULT$", ".env*"], "outputs": [".next/**", "!.next/cache/**"] }, @@ -11,7 +17,8 @@ "dependsOn": ["^lint"] }, "dev": { - "cache": false, + "dependsOn": ["^db:generate"], + "cache": true, "persistent": true } }