Skip to content

Commit

Permalink
refactor: Move the shared types to the shared package
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Apr 18, 2024
1 parent 81fc4c4 commit deba31e
Show file tree
Hide file tree
Showing 48 changed files with 66 additions and 47 deletions.
2 changes: 1 addition & 1 deletion apps/cli/commands/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from "@commander-js/extra-typings";
import chalk from "chalk";
import { getAPIClient } from "lib/trpc";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

export const bookmarkCmd = new Command()
.name("bookmarks")
Expand Down
1 change: 1 addition & 0 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"@commander-js/extra-typings": "^12.0.1",
"@hoarder/trpc": "workspace:^0.1.0",
"@hoarder/shared": "workspace:^0.1.0",
"@hoarder/tsconfig": "workspace:^0.1.0",
"@tsconfig/node21": "^21.0.1",
"tsx": "^4.7.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/app/sharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { api } from "@/lib/trpc";
import { useUploadAsset } from "@/lib/upload";
import { z } from "zod";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

type Mode =
| { type: "idle" }
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/components/bookmarks/BookmarkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { api } from "@/lib/trpc";
import { MenuView } from "@react-native-menu/menu";
import { Ellipsis, Star } from "lucide-react-native";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
import {
useDeleteBookmark,
useUpdateBookmark,
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/components/bookmarks/BookmarkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActivityIndicator, Keyboard, Text, View } from "react-native";
import Animated, { LinearTransition } from "react-native-reanimated";
import { useScrollToTop } from "@react-navigation/native";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

import BookmarkCard from "./BookmarkCard";

Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/components/bookmarks/UpdatingBookmarkList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Text } from "react-native";
import { api } from "@/lib/trpc";

import type { ZGetBookmarksRequest } from "@hoarder/trpc/types/bookmarks";
import type { ZGetBookmarksRequest } from "@hoarder/shared/types/bookmarks";

import FullPageSpinner from "../ui/FullPageSpinner";
import BookmarkList from "./BookmarkList";
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/lib/upload.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useMutation } from "@tanstack/react-query";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
import {
zUploadErrorSchema,
zUploadResponseSchema,
} from "@hoarder/trpc/types/uploads";
} from "@hoarder/shared/types/uploads";

import type { Settings } from "./settings";
import { api } from "./trpc";
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@hoarder/trpc": "workspace:^0.1.0",
"@hoarder/shared": "workspace:^0.1.0",
"@hoarder/shared-react": "workspace:^0.1.0",
"@react-native-menu/menu": "^0.9.1",
"@tanstack/react-query": "^5.24.8",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/assets/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContextFromRequest } from "@/server/api/client";
import { TRPCError } from "@trpc/server";

import type { ZUploadResponse } from "@hoarder/trpc/types/uploads";
import type { ZUploadResponse } from "@hoarder/shared/types/uploads";
import { saveAsset } from "@hoarder/shared/assetdb";
import serverConfig from "@hoarder/shared/config";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/UploadDropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useCreateBookmarkWithPostHook } from "@hoarder/shared-react/hooks/bookm
import {
zUploadErrorSchema,
zUploadResponseSchema,
} from "@hoarder/trpc/types/uploads";
} from "@hoarder/shared/types/uploads";

import LoadingSpinner from "../ui/spinner";
import { toast } from "../ui/use-toast";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/bookmarks/AssetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { api } from "@/lib/trpc";
import type {
ZBookmark,
ZBookmarkTypeAsset,
} from "@hoarder/trpc/types/bookmarks";
} from "@hoarder/shared/types/bookmarks";

import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
import { Maximize2 } from "lucide-react";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

import BookmarkOptions from "./BookmarkOptions";
import { FavouritedActionIcon } from "./icons";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { cn } from "@/lib/utils";
import dayjs from "dayjs";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

import BookmarkActionBar from "./BookmarkActionBar";
import TagList from "./TagList";
Expand Down
5 changes: 4 additions & 1 deletion apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
Trash2,
} from "lucide-react";

import type { ZBookmark, ZBookmarkedLink } from "@hoarder/trpc/types/bookmarks";
import type {
ZBookmark,
ZBookmarkedLink,
} from "@hoarder/shared/types/bookmarks";
import {
useDeleteBookmark,
useRecrawlBookmark,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Textarea } from "@/components/ui/textarea";
import { toast } from "@/components/ui/use-toast";
import { api } from "@/lib/trpc";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

export function BookmarkedTextEditor({
bookmark,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/bookmarks/Bookmarks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Separator } from "@/components/ui/separator";
import { api } from "@/server/api/client";
import { getServerAuthSession } from "@/server/auth";

import type { ZGetBookmarksRequest } from "@hoarder/trpc/types/bookmarks";
import type { ZGetBookmarksRequest } from "@hoarder/shared/types/bookmarks";

import UpdatableBookmarksGrid from "./UpdatableBookmarksGrid";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Slot } from "@radix-ui/react-slot";
import Masonry from "react-masonry-css";
import resolveConfig from "tailwindcss/resolveConfig";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

import AssetCard from "./AssetCard";
import EditorCard from "./EditorCard";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/bookmarks/LinkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@/lib/bookmarkUtils";
import { api } from "@/lib/trpc";

import type { ZBookmarkTypeLink } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmarkTypeLink } from "@hoarder/shared/types/bookmarks";

import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/bookmarks/TagList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { badgeVariants } from "@/components/ui/badge";
import { Skeleton } from "@/components/ui/skeleton";
import { cn } from "@/lib/utils";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

export default function TagList({
bookmark,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/bookmarks/TagModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DialogTitle,
} from "@/components/ui/dialog";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

import { TagsEditor } from "./TagsEditor";

Expand Down
4 changes: 2 additions & 2 deletions apps/web/components/dashboard/bookmarks/TagsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { cn } from "@/lib/utils";
import { Sparkles } from "lucide-react";
import CreateableSelect from "react-select/creatable";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZAttachedByEnum } from "@hoarder/trpc/types/tags";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
import type { ZAttachedByEnum } from "@hoarder/shared/types/tags";
import { useUpdateBookmarkTags } from "@hoarder/shared-react/hooks/bookmarks";

interface EditableTag {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/bookmarks/TextCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { bookmarkLayoutSwitch } from "@/lib/userLocalSettings/bookmarksLayout";
import { cn } from "@/lib/utils";
import Markdown from "react-markdown";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

import { BookmarkedTextViewer } from "./BookmarkedTextViewer";
import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { api } from "@/lib/trpc";
import type {
ZGetBookmarksRequest,
ZGetBookmarksResponse,
} from "@hoarder/trpc/types/bookmarks";
} from "@hoarder/shared/types/bookmarks";
import { BookmarkGridContextProvider } from "@hoarder/shared-react/hooks/bookmark-grid-context";

import BookmarksGrid from "./BookmarksGrid";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/lists/AllListsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { api } from "@/lib/trpc";
import { keepPreviousData } from "@tanstack/react-query";
import { Plus } from "lucide-react";

import type { ZBookmarkList } from "@hoarder/trpc/types/lists";
import type { ZBookmarkList } from "@hoarder/shared/types/lists";

function ListItem({
name,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/lists/DeleteListButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { toast } from "@/components/ui/use-toast";
import { api } from "@/lib/trpc";
import { Trash2 } from "lucide-react";

import type { ZBookmarkList } from "@hoarder/trpc/types/lists";
import type { ZBookmarkList } from "@hoarder/shared/types/lists";

export default function DeleteListButton({ list }: { list: ZBookmarkList }) {
const router = useRouter();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/preview/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { toast } from "@/components/ui/use-toast";
import { Trash2 } from "lucide-react";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
import {
useDeleteBookmark,
useUpdateBookmark,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Image from "next/image";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

export function AssetContentSection({ bookmark }: { bookmark: ZBookmark }) {
if (bookmark.content.type != "asset") {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/preview/BookmarkPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import { CalendarDays, ExternalLink } from "lucide-react";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

import ActionBar from "./ActionBar";
import { AssetContentSection } from "./AssetContentSection";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/preview/EditableTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { toast } from "@/components/ui/use-toast";
import { Check, Pencil, X } from "lucide-react";

import { useUpdateBookmark } from "@hoarder/shared-react/hooks/bookmarks";
import { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import { ZBookmark } from "@hoarder/shared/types/bookmarks";

interface Props {
bookmarkId: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/preview/NoteEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Textarea } from "@/components/ui/textarea";
import { toast } from "@/components/ui/use-toast";
import { useClientConfig } from "@/lib/clientConfig";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
import { useUpdateBookmark } from "@hoarder/shared-react/hooks/bookmarks";

export function NoteEditor({ bookmark }: { bookmark: ZBookmark }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ScrollArea } from "@radix-ui/react-scroll-area";
import Markdown from "react-markdown";

import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

export function TextContentSection({ bookmark }: { bookmark: ZBookmark }) {
let content;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/settings/ChangePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { api } from "@/lib/trpc";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";

import { zChangePasswordSchema } from "@hoarder/trpc/types/users";
import { zChangePasswordSchema } from "@hoarder/shared/types/users";

export function ChangePassword() {
const form = useForm<z.infer<typeof zChangePasswordSchema>>({
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/sidebar/AllLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from "next/link";
import { api } from "@/lib/trpc";
import { Plus } from "lucide-react";

import type { ZBookmarkList } from "@hoarder/trpc/types/lists";
import type { ZBookmarkList } from "@hoarder/shared/types/lists";

import NewListModal, { useNewListModal } from "./NewListModal";
import SidebarItem from "./SidebarItem";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/tags/AllTagsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InfoTooltip from "@/components/ui/info-tooltip";
import { Separator } from "@/components/ui/separator";
import { api } from "@/lib/trpc";

import type { ZGetTagResponse } from "@hoarder/trpc/types/tags";
import type { ZGetTagResponse } from "@hoarder/shared/types/tags";

function TagPill({ name, count }: { name: string; count: number }) {
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/signin/CredentialsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { signIn } from "next-auth/react";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { zSignUpSchema } from "@hoarder/trpc/types/users";
import { zSignUpSchema } from "@hoarder/shared/types/users";

const signInSchema = z.object({
email: z.string().email(),
Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/bookmarkUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";

const MAX_LOADING_MSEC = 30 * 1000;

Expand Down
2 changes: 1 addition & 1 deletion packages/shared-react/hooks/bookmark-grid-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { createContext, useContext } from "react";

import type { ZGetBookmarksRequest } from "@hoarder/trpc/types/bookmarks";
import type { ZGetBookmarksRequest } from "@hoarder/shared/types/bookmarks";

export const BookmarkGridContext = createContext<
ZGetBookmarksRequest | undefined
Expand Down
1 change: 1 addition & 0 deletions packages/shared-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"private": true,
"dependencies": {
"@hoarder/trpc": "workspace:^0.1.0",
"@hoarder/shared": "workspace:^0.1.0",
"@tanstack/react-query": "^5.24.8",
"superjson": "^2.2.1",
"@trpc/client": "11.0.0-next-beta.308"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const zBookmarkListSchema = z.object({
id: z.string(),
name: z.string(),
icon: z.string(),
parentId: z.string().nullable(),
});

export const zBookmarkListWithBookmarksSchema = zBookmarkListSchema.merge(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 9 additions & 6 deletions packages/trpc/routers/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { and, desc, eq, exists, inArray, lte, or } from "drizzle-orm";
import invariant from "tiny-invariant";
import { z } from "zod";

import type {
ZBookmark,
ZBookmarkContent,
} from "@hoarder/shared/types/bookmarks";
import type { ZBookmarkTags } from "@hoarder/shared/types/tags";
import { db as DONT_USE_db } from "@hoarder/db";
import {
bookmarkAssets,
Expand All @@ -20,11 +25,6 @@ import {
SearchIndexingQueue,
} from "@hoarder/shared/queues";
import { getSearchIdxClient } from "@hoarder/shared/search";

import type { Context } from "../index";
import type { ZBookmark, ZBookmarkContent } from "../types/bookmarks";
import type { ZBookmarkTags } from "../types/tags";
import { authedProcedure, router } from "../index";
import {
DEFAULT_NUM_BOOKMARKS_PER_PAGE,
zBareBookmarkSchema,
Expand All @@ -33,7 +33,10 @@ import {
zGetBookmarksResponseSchema,
zNewBookmarkRequestSchema,
zUpdateBookmarksRequestSchema,
} from "../types/bookmarks";
} from "@hoarder/shared/types/bookmarks";

import type { Context } from "../index";
import { authedProcedure, router } from "../index";

export const ensureBookmarkOwnership = experimental_trpcMiddleware<{
ctx: Context;
Expand Down
2 changes: 1 addition & 1 deletion packages/trpc/routers/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { z } from "zod";

import { SqliteError } from "@hoarder/db";
import { bookmarkLists, bookmarksInLists } from "@hoarder/db/schema";
import { zBookmarkListSchema } from "@hoarder/shared/types/lists";

import type { Context } from "../index";
import { authedProcedure, router } from "../index";
import { zBookmarkListSchema } from "../types/lists";
import { ensureBookmarkOwnership } from "./bookmarks";

export const ensureListOwnership = experimental_trpcMiddleware<{
Expand Down
Loading

0 comments on commit deba31e

Please sign in to comment.