Skip to content
API/AbstractFlatResponseStrategy

AbstractFlatResponseStrategy

src/strategies/abstract-flat-response.strategy.ts1 public methodsclass

Base class for response strategies whose pagination metadata is a flat key-value envelope on the response body

Laravel’s stock pagination and Spatie’s QueryBuilder both emit the same flat shape — { data, current_page, total, per_page, from, to, next_page_url, prev_page_url, first_page_url, last_page, last_page_url } — and both response strategies were duplicating the byte-identical new PaginatedCollection(response[options.X], ...) body before this base existed. Concrete classes now extend and provide only the docstring describing their driver’s specific shape (see LaravelResponseStrategy, SpatieResponseStrategy).

Drivers whose pagination metadata is a nested envelope (JSON:API, NestJS, Strapi) extend AbstractDotPathResponseStrategy instead. Drivers whose metadata comes from HTTP headers (PostgREST) or is derived from response URLs (DRF) implement IResponseStrategy directly.

new AbstractFlatResponseStrategy()
paginate(response: RawResponse, options: ResponseOptions): PaginatedCollection<T>

Parse a flat-envelope pagination response into a PaginatedCollection

Parameter Type Description
response RawResponse The raw API response object
options ResponseOptions The response key name configuration

Returns — A typed PaginatedCollection instance