aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-01-12 20:03:47 +0000
committerMohamed Bassem <me@mbassem.com>2025-01-12 20:03:47 +0000
commit9fd26b472b18924ab11afcebace90329b0fe3abf (patch)
tree04d2a8f8603978c27611574d663dfc58b3f285b0 /packages/trpc
parentc5298cf4b43795c0c261922ef0ad0f20245be4d5 (diff)
downloadkarakeep-9fd26b472b18924ab11afcebace90329b0fe3abf.tar.zst
feat: Add ability to filter by bookmark type
Diffstat (limited to 'packages/trpc')
-rw-r--r--packages/trpc/lib/__tests__/search.test.ts48
-rw-r--r--packages/trpc/lib/search.ts10
2 files changed, 58 insertions, 0 deletions
diff --git a/packages/trpc/lib/__tests__/search.test.ts b/packages/trpc/lib/__tests__/search.test.ts
index 468aef83..8a6f1949 100644
--- a/packages/trpc/lib/__tests__/search.test.ts
+++ b/packages/trpc/lib/__tests__/search.test.ts
@@ -280,6 +280,54 @@ describe("getBookmarkIdsFromMatcher", () => {
expect(result).toEqual(["b1", "b2"]);
});
+ it("should handle type matcher", async () => {
+ expect(
+ await getBookmarkIdsFromMatcher(mockCtx, {
+ type: "type",
+ typeName: BookmarkTypes.LINK,
+ inverse: false,
+ }),
+ ).toEqual(["b1", "b2", "b4"]);
+ expect(
+ await getBookmarkIdsFromMatcher(mockCtx, {
+ type: "type",
+ typeName: BookmarkTypes.TEXT,
+ inverse: false,
+ }),
+ ).toEqual(["b3", "b5"]);
+ expect(
+ await getBookmarkIdsFromMatcher(mockCtx, {
+ type: "type",
+ typeName: BookmarkTypes.ASSET,
+ inverse: false,
+ }),
+ ).toEqual(["b6"]);
+ });
+
+ it("should handle type matcher with inverse=true", async () => {
+ expect(
+ await getBookmarkIdsFromMatcher(mockCtx, {
+ type: "type",
+ typeName: BookmarkTypes.LINK,
+ inverse: true,
+ }),
+ ).toEqual(["b3", "b5", "b6"]);
+ expect(
+ await getBookmarkIdsFromMatcher(mockCtx, {
+ type: "type",
+ typeName: BookmarkTypes.TEXT,
+ inverse: true,
+ }),
+ ).toEqual(["b1", "b2", "b4", "b6"]);
+ expect(
+ await getBookmarkIdsFromMatcher(mockCtx, {
+ type: "type",
+ typeName: BookmarkTypes.ASSET,
+ inverse: true,
+ }),
+ ).toEqual(["b1", "b2", "b3", "b4", "b5"]);
+ });
+
it("should handle dateBefore matcher with inverse=true", async () => {
const matcher: Matcher = {
type: "dateBefore",
diff --git a/packages/trpc/lib/search.ts b/packages/trpc/lib/search.ts
index 74aaf51b..eac323df 100644
--- a/packages/trpc/lib/search.ts
+++ b/packages/trpc/lib/search.ts
@@ -7,6 +7,7 @@ import {
like,
lt,
lte,
+ ne,
notExists,
notLike,
} from "drizzle-orm";
@@ -233,6 +234,15 @@ async function getIds(
),
);
}
+ case "type": {
+ const comp = matcher.inverse
+ ? ne(bookmarks.type, matcher.typeName)
+ : eq(bookmarks.type, matcher.typeName);
+ return db
+ .select({ id: bookmarks.id })
+ .from(bookmarks)
+ .where(and(eq(bookmarks.userId, userId), comp));
+ }
case "and": {
const vals = await Promise.all(
matcher.matchers.map((m) => getIds(db, userId, m)),