Skip to content
API/AbstractDotPathResponseStrategy

AbstractDotPathResponseStrategy

src/strategies/abstract-dot-path-response.strategy.ts4 public methodsclass

Base class for response strategies whose pagination metadata lives at dot-notation paths inside the response body

JSON:API and NestJS share an identical body-traversal algorithm: the total / current-page / etc. live at nested keys like meta.total, and from/to are either present directly or must be derived from currentPage × perPage. Both strategies were duplicating this verbatim before this base existed; concrete classes now extend and provide only the docstring describing their driver’s specific path conventions (see JsonApiResponseStrategy, NestjsResponseStrategy).

Drivers whose pagination metadata travels via HTTP headers (PostgREST) or whose body has a flat shape with no dot paths (Laravel, Spatie) do not extend this class — they implement IResponseStrategy directly.

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

Parse a nested-envelope pagination response into a PaginatedCollection

Parameter Type Description
response RawResponse The raw API response object
options ResponseOptions The response key name configuration (dot-notation paths supported)

Returns — A typed PaginatedCollection instance

resolve(response: RawResponse, path: string): unknown

Resolve a value from a response object using a dot-notation path

Supports both flat keys ('data') and nested paths ('meta.totalItems').

Parameter Type Description
response RawResponse The raw response object
path string The dot-notation path to resolve

Returns — The resolved value, or undefined if any segment is missing

resolveFrom(response: RawResponse, options: ResponseOptions, currentPage: number, perPage?: number): number | undefined

Resolve the “from” index value

If options.from resolves to a value in the response, use it. Otherwise compute (currentPage - 1) * perPage + 1 when both are known.

Parameter Type Description
response RawResponse The raw response object
options ResponseOptions The response key name configuration
currentPage number The current page number
perPage number The number of items per page

Returns — The “from” index, or undefined when neither path nor inputs suffice

resolveTo(response: RawResponse, options: ResponseOptions, currentPage: number, perPage?: number, total?: number): number | undefined

Resolve the “to” index value

If options.to resolves to a value in the response, use it. Otherwise compute Math.min(currentPage * perPage, total) when all three are known.

Parameter Type Description
response RawResponse The raw response object
options ResponseOptions The response key name configuration
currentPage number The current page number
perPage number The number of items per page
total number The total number of items

Returns — The “to” index, or undefined when neither path nor inputs suffice