API/WordpressResponseStrategy
WordpressResponseStrategy
src/strategies/wordpress-response.strategy.ts1 public methodsclass
Response strategy for the WordPress REST API driver
WordPress returns a bare array body for collection endpoints. Pagination metadata travels in HTTP response headers:
X-WP-Total— total number of records in the collectionX-WP-TotalPages— total number of pages at the requestedper_pageLink— RFC 5988 navigation links (rel="next"/rel="prev")
The strategy surfaces the Link URLs as nextPageUrl /
prevPageUrl and derives position from them:
currentPageis theprevlink’spageparam + 1 (noprev→ page 1), falling back to thenextlink’spageparam − 1.perPageis the item count of the current page whenever anextlink exists (a page with a successor is necessarily full); on the last page of a multi-page set it is not introspectable and staysundefined.from/toderive fromcurrentPage×perPageon full pages, or count back from the total on the last page (from = total - data.length + 1,to = total).
This strategy expects the consumer to pass the array body as
response (or a plain object with readPath(response, options.data) pointing
at the array) and the response headers via the optional headers
bag — the same call-site shape as the PostgREST driver. Omitted
headers are tolerated and yield a collection with undefined
bounds.
Constructor
Section titled “Constructor”new WordpressResponseStrategy()Methods
Section titled “Methods”paginate()
Section titled “paginate()”paginate(response: RawResponse, options: ResponseOptions, headers?: HeaderBag): PaginatedCollection<T>Parse a WordPress REST response into a typed PaginatedCollection
| Parameter | Type | Description |
|---|---|---|
response |
RawResponse |
The raw response. Either the array body directly, or an object with the array at readPath(response, options.data). |
options |
ResponseOptions |
The response key configuration (only options.data is consulted; all pagination metadata comes from headers). |
headers |
HeaderBag |
Optional HTTP response headers. X-WP-Total / X-WP-TotalPages drive the totals and the Link header drives navigation and page derivation; omission is tolerated. |
Returns — A typed PaginatedCollection instance
