WordpressResponseStrategy
Defined in: src/lib/strategies/wordpress-response.strategy.ts:50
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 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.
See
https://developer.wordpress.org/rest-api/using-the-rest-api/pagination/
Implements
Constructors
Constructor
new WordpressResponseStrategy():
WordpressResponseStrategy
Returns
WordpressResponseStrategy
Methods
paginate()
paginate<
T>(response,options,headers?):PaginatedCollection<T>
Defined in: src/lib/strategies/wordpress-response.strategy.ts:70
Parse a WordPress REST response into a typed PaginatedCollection
Type Parameters
T
T extends IPaginatedObject
Parameters
response
Record<string, unknown>
The raw response. Either the array body directly, or
an object with the array at response[options.data].
options
The response key configuration (only options.data is
consulted; all pagination metadata comes from headers).
headers?
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