aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-05-19 13:44:27 +0100
committerMohamedBassem <me@mbassem.com>2024-05-19 13:46:33 +0100
commite8b47751660e24a6bd24941b6cb6b0ee79ffad3c (patch)
treef59c11d3dae9698c4b6e2f824da8eab7e60427ec /packages/shared
parentd1ad84be48bb3b6914c0d478d13f92861889c466 (diff)
downloadkarakeep-e8b47751660e24a6bd24941b6cb6b0ee79ffad3c.tar.zst
fix: Fix missing bookmarks during pagination if they got created in the same second. Fixes #140
Diffstat (limited to 'packages/shared')
-rw-r--r--packages/shared/types/bookmarks.ts13
1 files changed, 11 insertions, 2 deletions
diff --git a/packages/shared/types/bookmarks.ts b/packages/shared/types/bookmarks.ts
index 1511db48..10dba0c8 100644
--- a/packages/shared/types/bookmarks.ts
+++ b/packages/shared/types/bookmarks.ts
@@ -91,6 +91,11 @@ export type ZNewBookmarkRequest = z.infer<typeof zNewBookmarkRequestSchema>;
export const DEFAULT_NUM_BOOKMARKS_PER_PAGE = 20;
export const MAX_NUM_BOOKMARKS_PER_PAGE = 100;
+const zCursorV2 = z.object({
+ createdAt: z.date(),
+ id: z.string(),
+});
+
export const zGetBookmarksRequestSchema = z.object({
ids: z.array(z.string()).optional(),
archived: z.boolean().optional(),
@@ -98,13 +103,17 @@ export const zGetBookmarksRequestSchema = z.object({
tagId: z.string().optional(),
listId: z.string().optional(),
limit: z.number().max(MAX_NUM_BOOKMARKS_PER_PAGE).optional(),
- cursor: z.date().nullish(),
+ cursor: zCursorV2.or(z.date()).nullish(),
+ // TODO: Remove this field once all clients are updated to use the new cursor structure.
+ // This is done for backward comptability. If a client doesn't send this field, we'll assume it's an old client
+ // and repsond with the old cursor structure. Once all clients are updated, we can remove this field and drop the old cursor structure.
+ useCursorV2: z.boolean().optional(),
});
export type ZGetBookmarksRequest = z.infer<typeof zGetBookmarksRequestSchema>;
export const zGetBookmarksResponseSchema = z.object({
bookmarks: z.array(zBookmarkSchema),
- nextCursor: z.date().nullable(),
+ nextCursor: zCursorV2.or(z.date()).nullable(),
});
export type ZGetBookmarksResponse = z.infer<typeof zGetBookmarksResponseSchema>;