diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-09-14 08:27:44 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-09-14 08:42:58 +0000 |
| commit | bf5bf996c63cc3af92bc0f302ec37f7dbbc9e94a (patch) | |
| tree | 24066b4d21a08f35387da3680ae1d549a6d82d08 /packages/shared | |
| parent | a92ada7727b2596414aafe204e5001eb066569cb (diff) | |
| download | karakeep-bf5bf996c63cc3af92bc0f302ec37f7dbbc9e94a.tar.zst | |
refactor: strongly type the search plugin interface
Diffstat (limited to 'packages/shared')
| -rw-r--r-- | packages/shared/search.ts | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/packages/shared/search.ts b/packages/shared/search.ts index 5158f30f..d23ab29f 100644 --- a/packages/shared/search.ts +++ b/packages/shared/search.ts @@ -24,18 +24,34 @@ export const zBookmarkSearchDocument = z.object({ export type BookmarkSearchDocument = z.infer<typeof zBookmarkSearchDocument>; +export type SortOrder = "asc" | "desc"; +export type SortableAttributes = "createdAt"; + +export type FilterableAttributes = "userId" | "id"; +export type FilterQuery = + | { + type: "eq"; + field: FilterableAttributes; + value: string; + } + | { + type: "in"; + field: FilterableAttributes; + values: string[]; + }; + export interface SearchResult { id: string; score?: number; } export interface SearchOptions { - // TODO: Make query, filter and sort strongly typed query: string; - filter?: string[]; + // Diffeernt filters are ANDed together + filter?: FilterQuery[]; limit?: number; offset?: number; - sort?: string[]; + sort?: { field: SortableAttributes; order: SortOrder }[]; } export interface SearchResponse { |
