Skip to content

Commit f2a815f

Browse files
committed
fix(cardano-services-client)!: remove positional arg page in fetchSequentially
fetchSequentially page was specified in 2 places (paging options and a positional page parameter). Calling it with `page` in PaginationOptions ignores the page, leading to fetch of page: 1 infinitely. Removed the positional `page` arg to avoid confusion, and use the one from paginationOptions
1 parent 6d6afd4 commit f2a815f

File tree

1 file changed

+5
-2
lines changed
  • packages/cardano-services-client/src/blockfrost

1 file changed

+5
-2
lines changed

packages/cardano-services-client/src/blockfrost/util.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ export const fetchSequentially = async <Response, Item = Response>(
3232
haveEnoughItems?: (allItems: Item[], lastResponseBatch: Response[]) => boolean;
3333
paginationOptions?: PaginationOptions;
3434
},
35-
page = 1,
3635
accumulated: Item[] = []
3736
): Promise<Item[]> => {
3837
const count = props.paginationOptions?.count || 100;
38+
const page = props.paginationOptions?.page || 1;
3939
try {
4040
const response = await props.request(buildQueryString({ count, order: props.paginationOptions?.order, page }));
4141
const maybeTranslatedResponse = props.responseTranslator ? props.responseTranslator(response) : response;
4242
const newAccumulatedItems = [...accumulated, ...maybeTranslatedResponse] as Item[];
4343
const haveEnoughItems = props.haveEnoughItems?.(newAccumulatedItems, response);
4444
if (response.length === count && !haveEnoughItems) {
45-
return fetchSequentially<Response, Item>(props, page + 1, newAccumulatedItems);
45+
return fetchSequentially<Response, Item>(
46+
{ ...props, paginationOptions: { ...props.paginationOptions, page: page + 1 } },
47+
newAccumulatedItems
48+
);
4649
}
4750
return newAccumulatedItems;
4851
} catch (error) {

0 commit comments

Comments
 (0)