Skip to content
API/PaginatedCollection

PaginatedCollection

src/models/paginated-collection.ts2 public methodsclass

One page of rows plus the pagination metadata the backend reported.

Built by a response strategy — usually through Paginator.paginate() — rather than by hand. Metadata a backend does not report is undefined. Call toPlain() for a plain-object copy.

new PaginatedCollection(data: T[], page: number, from?: number, to?: number, total?: number, perPage?: number, prevPageUrl?: string, nextPageUrl?: string, lastPage?: number, firstPageUrl?: string, lastPageUrl?: string)
Parameter Type Description
data T[] The rows on this page
page number The current page number, 1-based
from number Position of the first row on this page within the whole result set, 1-based
to number Position of the last row on this page within the whole result set, 1-based
total number Number of rows in the whole result set
perPage number Number of rows per page
prevPageUrl string URL of the previous page, when the backend reports links
nextPageUrl string URL of the next page, when the backend reports links
lastPage number Number of the last page
firstPageUrl string URL of the first page, when the backend reports links
lastPageUrl string URL of the last page, when the backend reports links
Property Type Description
data T[] The rows on this page
firstPageUrl string URL of the first page, when the backend reports links
from number Position of the first row on this page within the whole result set, 1-based
lastPage number Number of the last page
lastPageUrl string URL of the last page, when the backend reports links
nextPageUrl string URL of the next page, when the backend reports links
page number The current page number, 1-based
perPage number Number of rows per page
prevPageUrl string URL of the previous page, when the backend reports links
to number Position of the last row on this page within the whole result set, 1-based
total number Number of rows in the whole result set
normalize(selector?: string | function): Normalized

Normalize the collection to a paginated list of ids for state-managed applications.

This method returns a single key object, where the key is the page number and the associated value is an array of ids. Each id is fetched by the collection items, looking up for the “id” key. If an id is supplied to this method, it will be used instead of the default “id” key.

Please note that in case the key doesn’t exist in the collection’s item, a KeyNotFoundError is thrown

Parameter Type Description
selector string | function —

Returns — []

toPlain(): PaginatedResult<T>

Copy the page into a plain object that survives serialisation.

React Server Components refuse to pass class instances to Client Components, and JSON.stringify drops undefined values; the result avoids both. Every pagination field is present, null when the backend did not report it. data is a new array holding the same rows, which are passed through unchanged, so the result is JSON-safe exactly when they are. The collection itself is not modified.

const page = paginator.paginate<Article>(body).toPlain();
// { data: [...], page: 2, total: 57, nextPageUrl: null, ... }

Returns — The rows and every pagination field as a plain object