aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc')
-rw-r--r--packages/trpc/routers/bookmarks.ts15
-rw-r--r--packages/trpc/routers/lists.ts2
-rw-r--r--packages/trpc/routers/tags.ts4
-rw-r--r--packages/trpc/routers/users.ts2
-rw-r--r--packages/trpc/types/bookmarks.ts118
-rw-r--r--packages/trpc/types/lists.ts18
-rw-r--r--packages/trpc/types/tags.ts18
-rw-r--r--packages/trpc/types/uploads.ts14
-rw-r--r--packages/trpc/types/users.ts26
9 files changed, 13 insertions, 204 deletions
diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts
index a447235b..0383d3f2 100644
--- a/packages/trpc/routers/bookmarks.ts
+++ b/packages/trpc/routers/bookmarks.ts
@@ -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,
@@ -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,
@@ -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;
diff --git a/packages/trpc/routers/lists.ts b/packages/trpc/routers/lists.ts
index fb6d8637..74b4f737 100644
--- a/packages/trpc/routers/lists.ts
+++ b/packages/trpc/routers/lists.ts
@@ -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<{
diff --git a/packages/trpc/routers/tags.ts b/packages/trpc/routers/tags.ts
index 53b72a23..ed4ac7d2 100644
--- a/packages/trpc/routers/tags.ts
+++ b/packages/trpc/routers/tags.ts
@@ -2,12 +2,12 @@ import { experimental_trpcMiddleware, TRPCError } from "@trpc/server";
import { and, count, eq } from "drizzle-orm";
import { z } from "zod";
+import type { ZAttachedByEnum } from "@hoarder/shared/types/tags";
import { bookmarkTags, tagsOnBookmarks } from "@hoarder/db/schema";
+import { zGetTagResponseSchema } from "@hoarder/shared/types/tags";
import type { Context } from "../index";
-import type { ZAttachedByEnum } from "../types/tags";
import { authedProcedure, router } from "../index";
-import { zGetTagResponseSchema } from "../types/tags";
function conditionFromInput(
input: { tagName: string } | { tagId: string },
diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.ts
index e7f0a59d..51f9429e 100644
--- a/packages/trpc/routers/users.ts
+++ b/packages/trpc/routers/users.ts
@@ -7,6 +7,7 @@ import { SqliteError } from "@hoarder/db";
import { users } from "@hoarder/db/schema";
import { deleteUserAssets } from "@hoarder/shared/assetdb";
import serverConfig from "@hoarder/shared/config";
+import { zSignUpSchema } from "@hoarder/shared/types/users";
import { hashPassword, validatePassword } from "../auth";
import {
@@ -15,7 +16,6 @@ import {
publicProcedure,
router,
} from "../index";
-import { zSignUpSchema } from "../types/users";
export const usersAppRouter = router({
create: publicProcedure
diff --git a/packages/trpc/types/bookmarks.ts b/packages/trpc/types/bookmarks.ts
deleted file mode 100644
index 2cf8152b..00000000
--- a/packages/trpc/types/bookmarks.ts
+++ /dev/null
@@ -1,118 +0,0 @@
-import { z } from "zod";
-
-import { zBookmarkTagSchema } from "./tags";
-
-const MAX_TITLE_LENGTH = 100;
-
-export const zBookmarkedLinkSchema = z.object({
- type: z.literal("link"),
- url: z.string().url(),
- title: z.string().nullish(),
- description: z.string().nullish(),
- imageUrl: z.string().url().nullish(),
- favicon: z.string().url().nullish(),
- htmlContent: z.string().nullish(),
- crawledAt: z.date().nullish(),
-});
-export type ZBookmarkedLink = z.infer<typeof zBookmarkedLinkSchema>;
-
-export const zBookmarkedTextSchema = z.object({
- type: z.literal("text"),
- text: z.string(),
-});
-export type ZBookmarkedText = z.infer<typeof zBookmarkedTextSchema>;
-
-export const zBookmarkedAssetSchema = z.object({
- type: z.literal("asset"),
- assetType: z.enum(["image", "pdf"]),
- assetId: z.string(),
- fileName: z.string().nullish(),
-});
-export type ZBookmarkedAsset = z.infer<typeof zBookmarkedAssetSchema>;
-
-export const zBookmarkContentSchema = z.discriminatedUnion("type", [
- zBookmarkedLinkSchema,
- zBookmarkedTextSchema,
- zBookmarkedAssetSchema,
- z.object({ type: z.literal("unknown") }),
-]);
-export type ZBookmarkContent = z.infer<typeof zBookmarkContentSchema>;
-
-export const zBareBookmarkSchema = z.object({
- id: z.string(),
- createdAt: z.date(),
- title: z.string().max(MAX_TITLE_LENGTH).nullish(),
- archived: z.boolean(),
- favourited: z.boolean(),
- taggingStatus: z.enum(["success", "failure", "pending"]).nullable(),
- note: z.string().nullish(),
-});
-
-export const zBookmarkSchema = zBareBookmarkSchema.merge(
- z.object({
- tags: z.array(zBookmarkTagSchema),
- content: zBookmarkContentSchema,
- }),
-);
-export type ZBookmark = z.infer<typeof zBookmarkSchema>;
-
-const zBookmarkTypeLinkSchema = zBareBookmarkSchema.merge(
- z.object({
- tags: z.array(zBookmarkTagSchema),
- content: zBookmarkedLinkSchema,
- }),
-);
-export type ZBookmarkTypeLink = z.infer<typeof zBookmarkTypeLinkSchema>;
-
-const zBookmarkTypeTextSchema = zBareBookmarkSchema.merge(
- z.object({
- tags: z.array(zBookmarkTagSchema),
- content: zBookmarkedTextSchema,
- }),
-);
-export type ZBookmarkTypeText = z.infer<typeof zBookmarkTypeTextSchema>;
-
-const zBookmarkTypeAssetSchema = zBareBookmarkSchema.merge(
- z.object({
- tags: z.array(zBookmarkTagSchema),
- content: zBookmarkedAssetSchema,
- }),
-);
-export type ZBookmarkTypeAsset = z.infer<typeof zBookmarkTypeAssetSchema>;
-
-// POST /v1/bookmarks
-export const zNewBookmarkRequestSchema = zBookmarkContentSchema;
-export type ZNewBookmarkRequest = z.infer<typeof zNewBookmarkRequestSchema>;
-
-// GET /v1/bookmarks
-
-export const DEFAULT_NUM_BOOKMARKS_PER_PAGE = 20;
-
-export const zGetBookmarksRequestSchema = z.object({
- ids: z.array(z.string()).optional(),
- archived: z.boolean().optional(),
- favourited: z.boolean().optional(),
- tagId: z.string().optional(),
- listId: z.string().optional(),
- limit: z.number().max(100).optional(),
- cursor: z.date().nullish(),
-});
-export type ZGetBookmarksRequest = z.infer<typeof zGetBookmarksRequestSchema>;
-
-export const zGetBookmarksResponseSchema = z.object({
- bookmarks: z.array(zBookmarkSchema),
- nextCursor: z.date().nullable(),
-});
-export type ZGetBookmarksResponse = z.infer<typeof zGetBookmarksResponseSchema>;
-
-// PATCH /v1/bookmarks/[bookmarkId]
-export const zUpdateBookmarksRequestSchema = z.object({
- bookmarkId: z.string(),
- archived: z.boolean().optional(),
- favourited: z.boolean().optional(),
- note: z.string().optional(),
- title: z.string().max(MAX_TITLE_LENGTH).nullish(),
-});
-export type ZUpdateBookmarksRequest = z.infer<
- typeof zUpdateBookmarksRequestSchema
->;
diff --git a/packages/trpc/types/lists.ts b/packages/trpc/types/lists.ts
deleted file mode 100644
index 4b0ccaca..00000000
--- a/packages/trpc/types/lists.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { z } from "zod";
-
-export const zBookmarkListSchema = z.object({
- id: z.string(),
- name: z.string(),
- icon: z.string(),
-});
-
-export const zBookmarkListWithBookmarksSchema = zBookmarkListSchema.merge(
- z.object({
- bookmarks: z.array(z.string()),
- }),
-);
-
-export type ZBookmarkList = z.infer<typeof zBookmarkListSchema>;
-export type ZBookmarkListWithBookmarks = z.infer<
- typeof zBookmarkListWithBookmarksSchema
->;
diff --git a/packages/trpc/types/tags.ts b/packages/trpc/types/tags.ts
deleted file mode 100644
index c9fe2a93..00000000
--- a/packages/trpc/types/tags.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { z } from "zod";
-
-export const zAttachedByEnumSchema = z.enum(["ai", "human"]);
-export type ZAttachedByEnum = z.infer<typeof zAttachedByEnumSchema>;
-export const zBookmarkTagSchema = z.object({
- id: z.string(),
- name: z.string(),
- attachedBy: zAttachedByEnumSchema,
-});
-export type ZBookmarkTags = z.infer<typeof zBookmarkTagSchema>;
-
-export const zGetTagResponseSchema = z.object({
- id: z.string(),
- name: z.string(),
- count: z.number(),
- countAttachedBy: z.record(zAttachedByEnumSchema, z.number()),
-});
-export type ZGetTagResponse = z.infer<typeof zGetTagResponseSchema>;
diff --git a/packages/trpc/types/uploads.ts b/packages/trpc/types/uploads.ts
deleted file mode 100644
index b53b86d5..00000000
--- a/packages/trpc/types/uploads.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { z } from "zod";
-
-export const zUploadErrorSchema = z.object({
- error: z.string(),
-});
-
-export const zUploadResponseSchema = z.object({
- assetId: z.string(),
- contentType: z.string(),
- size: z.number(),
- fileName: z.string(),
-});
-
-export type ZUploadResponse = z.infer<typeof zUploadResponseSchema>;
diff --git a/packages/trpc/types/users.ts b/packages/trpc/types/users.ts
deleted file mode 100644
index 3026337a..00000000
--- a/packages/trpc/types/users.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { z } from "zod";
-
-const PASSWORD_MAX_LENGTH = 100;
-
-export const zSignUpSchema = z
- .object({
- name: z.string().min(1, { message: "Name can't be empty" }),
- email: z.string().email(),
- password: z.string().min(8).max(PASSWORD_MAX_LENGTH),
- confirmPassword: z.string(),
- })
- .refine((data) => data.password === data.confirmPassword, {
- message: "Passwords don't match",
- path: ["confirmPassword"],
- });
-
-export const zChangePasswordSchema = z
- .object({
- currentPassword: z.string(),
- newPassword: z.string().min(8).max(PASSWORD_MAX_LENGTH),
- newPasswordConfirm: z.string(),
- })
- .refine((data) => data.newPassword === data.newPasswordConfirm, {
- message: "Passwords don't match",
- path: ["newPasswordConfirm"],
- });