fix: guard pagination limits (#44) (thanks @jsholmes)

This commit is contained in:
Peter Steinberger
2026-01-12 07:07:47 +00:00
parent bc744a3bf9
commit afa7063a72
5 changed files with 79 additions and 5 deletions
+1 -1
View File
@@ -449,7 +449,7 @@ export function withLists<TBase extends AbstractConstructor<TwitterClientBase>>(
return { success: false as const, error: firstAttempt.error };
};
const unlimited = !Number.isFinite(limit);
const unlimited = limit === Number.POSITIVE_INFINITY;
while (unlimited || tweets.length < limit) {
const pageCount = unlimited ? pageSize : Math.min(pageSize, limit - tweets.length);
const page = await fetchWithRefresh(pageCount, cursor);
+1 -1
View File
@@ -209,7 +209,7 @@ export function withSearch<TBase extends AbstractConstructor<TwitterClientBase>>
return { success: false as const, error: firstAttempt.error };
};
const unlimited = !Number.isFinite(limit);
const unlimited = limit === Number.POSITIVE_INFINITY;
while (unlimited || tweets.length < limit) {
const pageCount = unlimited ? pageSize : Math.min(pageSize, limit - tweets.length);
const page = await fetchWithRefresh(pageCount, cursor);
+3 -3
View File
@@ -204,7 +204,7 @@ export function withTimelines<TBase extends AbstractConstructor<TwitterClientBas
return { success: false as const, error: firstAttempt.error };
};
const unlimited = !Number.isFinite(limit);
const unlimited = limit === Number.POSITIVE_INFINITY;
while (unlimited || tweets.length < limit) {
const pageCount = unlimited ? pageSize : Math.min(pageSize, limit - tweets.length);
const page = await fetchWithRefresh(pageCount, cursor);
@@ -382,7 +382,7 @@ export function withTimelines<TBase extends AbstractConstructor<TwitterClientBas
return { success: false as const, error: firstAttempt.error };
};
const unlimited = !Number.isFinite(limit);
const unlimited = limit === Number.POSITIVE_INFINITY;
while (unlimited || tweets.length < limit) {
const pageCount = unlimited ? pageSize : Math.min(pageSize, limit - tweets.length);
const page = await fetchWithRefresh(pageCount, cursor);
@@ -565,7 +565,7 @@ export function withTimelines<TBase extends AbstractConstructor<TwitterClientBas
return { success: false as const, error: firstAttempt.error };
};
const unlimited = !Number.isFinite(limit);
const unlimited = limit === Number.POSITIVE_INFINITY;
while (unlimited || tweets.length < limit) {
const pageCount = unlimited ? pageSize : Math.min(pageSize, limit - tweets.length);
const page = await fetchWithRefresh(pageCount, cursor);