From e6486465decd612f7e437abe904960a47ff359ce Mon Sep 17 00:00:00 2001 From: kamtschatka Date: Mon, 1 Jul 2024 13:03:53 +0200 Subject: refactor: added the bookmark type to the database (#256) * refactoring asset types Extracted out functions to silently delete assets and to update them after crawling Generalized the mapping of assets to bookmark fields to make extending them easier * Added the bookmark type to the database Introduced an enum to have better type safety cleaned up the code and based some code on the type directly * add BookmarkType.UNKNWON * lint and remove unused function --------- Co-authored-by: MohamedBassem --- packages/shared/types/bookmarks.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'packages/shared') diff --git a/packages/shared/types/bookmarks.ts b/packages/shared/types/bookmarks.ts index c9e3e1a5..c0c12b56 100644 --- a/packages/shared/types/bookmarks.ts +++ b/packages/shared/types/bookmarks.ts @@ -4,8 +4,15 @@ import { zBookmarkTagSchema } from "./tags"; const MAX_TITLE_LENGTH = 100; +export const enum BookmarkTypes { + LINK = "link", + TEXT = "text", + ASSET = "asset", + UNKNWON = "unknown", +} + export const zBookmarkedLinkSchema = z.object({ - type: z.literal("link"), + type: z.literal(BookmarkTypes.LINK), url: z.string().url(), title: z.string().nullish(), description: z.string().nullish(), @@ -20,13 +27,13 @@ export const zBookmarkedLinkSchema = z.object({ export type ZBookmarkedLink = z.infer; export const zBookmarkedTextSchema = z.object({ - type: z.literal("text"), + type: z.literal(BookmarkTypes.TEXT), text: z.string(), }); export type ZBookmarkedText = z.infer; export const zBookmarkedAssetSchema = z.object({ - type: z.literal("asset"), + type: z.literal(BookmarkTypes.ASSET), assetType: z.enum(["image", "pdf"]), assetId: z.string(), fileName: z.string().nullish(), @@ -38,7 +45,7 @@ export const zBookmarkContentSchema = z.discriminatedUnion("type", [ zBookmarkedLinkSchema, zBookmarkedTextSchema, zBookmarkedAssetSchema, - z.object({ type: z.literal("unknown") }), + z.object({ type: z.literal(BookmarkTypes.UNKNWON) }), ]); export type ZBookmarkContent = z.infer; -- cgit v1.2.3-70-g09d2