paginatedList: only return `next` when page isn't empty

This commit is contained in:
Alex Gleason 2024-05-31 15:49:36 -05:00
parent 97d629cf07
commit adcaad2863
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 2 additions and 1 deletions

View File

@ -210,9 +210,10 @@ function paginatedList(
headers: HeaderRecord = {},
) {
const link = buildListLinkHeader(c.req.url, params);
const hasMore = entities.length > 0;
if (link) {
headers.link = link;
headers.link = hasMore ? link : link.split(', ').find((link) => link.endsWith('; rel="prev"'))!;
}
// Filter out undefined entities.