File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
v2/api-validator/tests/utils Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,12 @@ export type Pageable<T> = (limit: number, startingAfter?: string) => Promise<T[]
88 * one by one while automagically managing the pagination behind the scene.
99 */
1010export async function * paginated < T > ( f : Pageable < T > , idPropName = 'id' ) : AsyncGenerator < T > {
11- const MAX_PAGES = 20 ;
11+ const MAX_PAGES = 1000 ;
1212 let pageCount = 0 ;
13- let cursor : string | undefined ;
13+ let startingAfter : string | undefined ;
1414
1515 while ( pageCount < MAX_PAGES ) {
16- const currentPage = await f ( LIMIT , cursor ) ;
16+ const currentPage = await f ( LIMIT , startingAfter ) ;
1717
1818 if ( currentPage . length === 0 ) {
1919 break ;
@@ -26,13 +26,13 @@ export async function* paginated<T>(f: Pageable<T>, idPropName = 'id'): AsyncGen
2626 }
2727
2828 const lastItem = currentPage [ currentPage . length - 1 ] ;
29- const nextCursor = lastItem ?. [ idPropName ] ;
29+ const lastItemId = lastItem ?. [ idPropName ] ;
3030
31- if ( ! nextCursor || nextCursor === cursor ) {
31+ if ( ! lastItemId || lastItemId === startingAfter ) {
3232 break ;
3333 }
3434
35- cursor = nextCursor ;
35+ startingAfter = lastItemId ;
3636 }
3737}
3838
You can’t perform that action at this time.
0 commit comments