aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/lib
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc/lib')
-rw-r--r--packages/trpc/lib/__tests__/search.test.ts3
-rw-r--r--packages/trpc/lib/search.ts27
2 files changed, 25 insertions, 5 deletions
diff --git a/packages/trpc/lib/__tests__/search.test.ts b/packages/trpc/lib/__tests__/search.test.ts
index 8a6f1949..7f573b4f 100644
--- a/packages/trpc/lib/__tests__/search.test.ts
+++ b/packages/trpc/lib/__tests__/search.test.ts
@@ -111,6 +111,7 @@ beforeEach(async () => {
assetType: "image",
fileName: "test.png",
assetId: "asset-id",
+ sourceUrl: "https://example.com/image.png",
},
]);
@@ -236,7 +237,7 @@ describe("getBookmarkIdsFromMatcher", () => {
inverse: false,
};
const result = await getBookmarkIdsFromMatcher(mockCtx, matcher);
- expect(result).toEqual(["b1", "b4"]);
+ expect(result).toEqual(["b1", "b4", "b6"]);
});
it("should handle url matcher with inverse=true", async () => {
diff --git a/packages/trpc/lib/search.ts b/packages/trpc/lib/search.ts
index eac323df..de76748b 100644
--- a/packages/trpc/lib/search.ts
+++ b/packages/trpc/lib/search.ts
@@ -4,6 +4,7 @@ import {
exists,
gt,
gte,
+ isNotNull,
like,
lt,
lte,
@@ -13,6 +14,7 @@ import {
} from "drizzle-orm";
import {
+ bookmarkAssets,
bookmarkLinks,
bookmarkLists,
bookmarks,
@@ -197,6 +199,20 @@ async function getIds(
eq(bookmarks.userId, userId),
comp(bookmarkLinks.url, `%${matcher.url}%`),
),
+ )
+ .union(
+ db
+ .select({ id: bookmarkAssets.id })
+ .from(bookmarkAssets)
+ .leftJoin(bookmarks, eq(bookmarks.id, bookmarkAssets.id))
+ .where(
+ and(
+ eq(bookmarks.userId, userId),
+ // When a user is asking for a link, the inverse matcher should match only assets with URLs.
+ isNotNull(bookmarkAssets.sourceUrl),
+ comp(bookmarkAssets.sourceUrl, `%${matcher.url}%`),
+ ),
+ ),
);
}
case "favourited": {
@@ -235,13 +251,16 @@ async function getIds(
);
}
case "type": {
- const comp = matcher.inverse
- ? ne(bookmarks.type, matcher.typeName)
- : eq(bookmarks.type, matcher.typeName);
+ const comp = matcher.inverse ? ne : eq;
return db
.select({ id: bookmarks.id })
.from(bookmarks)
- .where(and(eq(bookmarks.userId, userId), comp));
+ .where(
+ and(
+ eq(bookmarks.userId, userId),
+ comp(bookmarks.type, matcher.typeName),
+ ),
+ );
}
case "and": {
const vals = await Promise.all(