feat: add cursor-based pagination to bookmarks command

- Add --cursor option to resume pagination from a specific point
- Change --max-pages to enable pagination independently
- Return nextCursor in JSON output for subsequent requests

feat: add cursor param and nextCursor to pagination methods

not modifying max-pages
This commit is contained in:
Leon Ho
2026-01-04 23:42:34 +00:00
committed by Peter Steinberger
parent c4fa04e0b2
commit 3442ba84c6
4 changed files with 91 additions and 19 deletions
+8 -4
View File
@@ -13,6 +13,8 @@ export interface TimelineFetchOptions {
/** Options for paged timeline fetch methods */
export interface TimelinePaginationOptions extends TimelineFetchOptions {
maxPages?: number;
/** Starting cursor for pagination (resume from previous fetch) */
cursor?: string;
}
export interface TwitterClientTimelineMethods {
@@ -198,7 +200,7 @@ export function withTimelines<TBase extends AbstractConstructor<TwitterClientBas
const pageSize = 20;
const seen = new Set<string>();
const tweets: TweetData[] = [];
let cursor: string | undefined;
let cursor: string | undefined = options.cursor;
let pagesFetched = 0;
const { includeRaw = false, maxPages } = options;
@@ -341,12 +343,13 @@ export function withTimelines<TBase extends AbstractConstructor<TwitterClientBas
break;
}
if (maxPages && pagesFetched >= maxPages) {
cursor = page.cursor;
break;
}
cursor = page.cursor;
}
return { success: true, tweets };
return { success: true, tweets, nextCursor: cursor };
}
private async getBookmarkFolderTimelinePaged(
@@ -358,7 +361,7 @@ export function withTimelines<TBase extends AbstractConstructor<TwitterClientBas
const pageSize = 20;
const seen = new Set<string>();
const tweets: TweetData[] = [];
let cursor: string | undefined;
let cursor: string | undefined = options.cursor;
let pagesFetched = 0;
const { includeRaw = false, maxPages } = options;
@@ -517,12 +520,13 @@ export function withTimelines<TBase extends AbstractConstructor<TwitterClientBas
break;
}
if (maxPages && pagesFetched >= maxPages) {
cursor = page.cursor;
break;
}
cursor = page.cursor;
}
return { success: true, tweets };
return { success: true, tweets, nextCursor: cursor };
}
private async fetchWithRetry(url: string, init: RequestInit): Promise<Response> {