PostgrestResponseStrategy
Response strategy for the PostgREST driver
PostgREST (and Supabase, which wraps it) returns a bare array body for
collection endpoints. Pagination metadata is carried in the
Content-Range HTTP response header, e.g. 0-9/50 meaning “items 0–9
out of 50 total”. Consumers opt into totals by sending the
Prefer: count=exact request header.
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. See
Paginator.paginate() for the call-site shape.
The header places the rows but does not state the page size, and the
span of a short last page (30-33/34 at limit 10) is not it. The page
size is therefore the requested limit, which Paginator passes; the
span stands in only when no limit is given, and is right on every page
but a short last one. An empty collection, whose header gives * for
the range and 0 for the total, reads as one page holding no rows.
A server that caps rows below the limit (db-max-rows; Supabase’s Max
Rows, 1000 by default) returns fewer rows than were asked for on every
page, and the next page’s offset skips the rest. Keep the limit at or
below the cap.
Constructor
Section titled “Constructor”new PostgrestResponseStrategy()Methods
Section titled “Methods”paginate()
Section titled “paginate()”paginate(response: RawResponse, options: ResponseOptions, headers?: HeaderBag, limit?: number): PaginatedCollection<T>Parse a PostgREST 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 the Content-Range header). |
headers |
HeaderBag |
Optional HTTP response headers. The Content-Range header drives page/total derivation; omission is tolerated and yields a collection with undefined bounds (auto-sync will leave isLastPageKnown at false). |
limit |
number |
The page size the request asked for. Without it, the span of the range stands in, which misplaces a short last page. |
Returns — A typed PaginatedCollection instance
