@planet-a/affinity-node
Version:
API wrapper for the affinity.co API
18 lines (17 loc) • 604 B
TypeScript
import { Pagination } from './index.js';
export type PagedFn<T> = (...params: any[]) => Promise<{
data: Array<T> | null;
pagination: Pagination;
}>;
/**
* Given a function that returns a paged response, return an async generator that yields all pages.
*
* @example
* ```ts
* const paginatedCompanies = paginated(companiesApi.getV2Companies.bind(companiesApi))
* for await (const page of paginatedCompanies({ limit: 1 })) {
* console.log(page)
* }
* ```
*/
export declare const paginated: <T>(pagedFn: PagedFn<T>) => (...args: Parameters<typeof pagedFn>) => AsyncGenerator<Array<T>>;