DirectusResponseStrategy
Response strategy for the Directus driver
Parses Directus collection responses (with meta=total_count,filter_count
requested, which the request strategy always does):
{ "data": [{ "id": 1, "title": "Hello" }], "meta": { "total_count": 48, "filter_count": 12 }}The default total path is meta.filter_count — the number of items
matching the current filter, which is the relevant total for paging a
filtered collection (meta.total_count ignores filters; point the
total path at it via PaginationConfig if that is what you want).
The envelope carries no current-page or page-size field, so:
currentPagefalls back to 1 unless acurrentPagepath is configured and resolves (only guaranteed correct for single-page results — track the requested page in your own state for multi-page UIs).perPageresolves only when aperPagepath is configured.lastPageisceil(total ÷ perPage)when both are known; on a response that provably holds the whole filtered set it resolves to 1.
Every key path is overridable via PaginationConfig (dot notation
supported), so custom wrappers that do include paging fields map
without subclassing.
Constructor
Section titled “Constructor”new DirectusResponseStrategy()Methods
Section titled “Methods”paginate()
Section titled “paginate()”paginate(response: RawResponse, options: ResponseOptions): PaginatedCollection<T>Parse a Directus collection response into a PaginatedCollection
| Parameter | Type | Description |
|---|---|---|
response |
RawResponse |
The raw API response body |
options |
ResponseOptions |
The response key name configuration (dot-notation paths supported) |
Returns — A typed PaginatedCollection instance
resolve()
Section titled “resolve()”resolve(response: RawResponse, path: string): unknownResolve 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()
Section titled “resolveFrom()”resolveFrom(response: RawResponse, options: ResponseOptions, currentPage: number, perPage?: number): number | undefinedResolve 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()
Section titled “resolveTo()”resolveTo(response: RawResponse, options: ResponseOptions, currentPage: number, perPage?: number, total?: number): number | undefinedResolve 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
