diff --git a/.changeset/long-hounds-melt.md b/.changeset/long-hounds-melt.md new file mode 100644 index 0000000000..497f73eee2 --- /dev/null +++ b/.changeset/long-hounds-melt.md @@ -0,0 +1,5 @@ +--- +"blitz": major +--- + +update paginate.ts, return more params for more complex pagination control diff --git a/packages/blitz/src/paginate.ts b/packages/blitz/src/paginate.ts index 90d764445b..4206f533f2 100644 --- a/packages/blitz/src/paginate.ts +++ b/packages/blitz/src/paginate.ts @@ -48,11 +48,18 @@ export async function paginate({ const hasMore = skip + take < count const nextPage = hasMore ? {take, skip: skip + take} : null + const pageCount = Math.floor((count + take - 1) / take) + const from = skip + 1 + const to = skip + take return { items, nextPage, hasMore, + pageCount: pageCount, + pageSize: take, + from, + to, count, } } diff --git a/packages/blitz/tests/paginate.test.ts b/packages/blitz/tests/paginate.test.ts index b005995799..34b0d83e3e 100644 --- a/packages/blitz/tests/paginate.test.ts +++ b/packages/blitz/tests/paginate.test.ts @@ -74,6 +74,10 @@ describe("paginate", () => { nextPage: null, hasMore: false, count: 3, + from: 2, + pageCount: 2, + pageSize: 2, + to: 3, }, }, { @@ -88,6 +92,10 @@ describe("paginate", () => { nextPage: {skip: 3, take: 2}, hasMore: true, count: 4, + from: 2, + pageCount: 2, + pageSize: 2, + to: 3, }, }, ]