API/JsonServerResponseStrategy
JsonServerResponseStrategy
src/strategies/json-server-response.strategy.ts1 public methodsclass
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.
Constructor
Section titled “Constructor”new JsonServerResponseStrategy()Methods
Section titled “Methods”paginate()
Section titled “paginate()”paginate(response: RawResponse, options: ResponseOptions): PaginatedCollection<T>Parse a json-server pagination response into a PaginatedCollection
| Parameter | Type | Description |
|---|---|---|
response |
RawResponse |
The raw API response body |
options |
ResponseOptions |
The response key name configuration |
Returns — A typed PaginatedCollection instance
