param boundApiMethod param parameters param resultListKey param nextTokenKey param nextTokenInputKey param pageConsumer param limit returns { Promise < any [ ] > } export const paginatedRequest = async < Params > ( boundApiMethod , parameters , resultListKey , nextTokenKey , nextTokenInputKey = nextTokenKey , pageConsumer = async ( ) => { } , limit ? ) : Promise < any [ ] > => { let token = undefined ; const results = [ ] ; do { const response = await boundApiMethod ( { ... parameters , [ nextTokenInputKey ] : token , } ) . promise ( ) ; await pageConsumer ( response [ resultListKey ] ) ; results . push ( ... response [ resultListKey ] ) ; if ( limit && results . length >= limit ) { return results ; } token = response [ nextTokenKey ] ; } while ( token ) ; return results ; } ; param boundApiMethod param parameters param pageConsumer param limit returns { Promise < any [ ] > } export const dynamodbPaginatedRequest = < Params > ( boundApiMethod , parameters , pageConsumer = async ( ) => { } , limit ? ) : Promise < any [ ] > => paginatedRequest ( boundApiMethod , parameters , 'Items' , 'LastEvaluatedKey' , 'ExclusiveStartKey' , pageConsumer , limit ) ;