JsonServerResponseStrategy
Defined in: src/lib/strategies/json-server-response.strategy.ts:42
Response strategy for the json-server driver
Parses json-server v1 paginated responses:
{
"first": 1,
"prev": null,
"next": 2,
"last": 5,
"pages": 5,
"items": 48,
"data": [...]
}
Uniquely among the drivers, first / prev / next / last are
page numbers, not URLs — so the navigation-URL slots on
PaginatedCollection stay undefined and the strategy instead uses
the numbers to derive position:
currentPageisprev + 1(prev === null→ page 1).perPageis the item count of the current page whenevernextis set (a page with a successor is necessarily full); on the last page of a multi-page set it is not introspectable and staysundefined.lastPagecomes straight frompages;from/toderive fromcurrentPage×perPageon full pages, or count back from the total on the last page (from = total - items + 1,to = total).
The data / items / pages key paths are configurable through
JsonServerResponseOptions; the prev / next keys are fixed by the
json-server envelope and live as private statics.
See
https://github.com/typicode/json-server
Implements
Constructors
Constructor
new JsonServerResponseStrategy():
JsonServerResponseStrategy
Returns
JsonServerResponseStrategy
Methods
paginate()
paginate<
T>(response,options):PaginatedCollection<T>
Defined in: src/lib/strategies/json-server-response.strategy.ts:61
Parse a json-server pagination response into a PaginatedCollection
Type Parameters
T
T extends IPaginatedObject
Parameters
response
Record<string, any>
The raw API response body
options
The response key name configuration
Returns
A typed PaginatedCollection instance