From adcaad28639312b302d3b7acf6c94c48598cdc9b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 31 May 2024 15:49:36 -0500 Subject: [PATCH] paginatedList: only return `next` when page isn't empty --- src/utils/api.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/api.ts b/src/utils/api.ts index 599163d..5ab4cc6 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -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.