InferredPaginator

Source
import { InferredPaginator } from "@prestojs/util";

Class that infers the specific type of pagination based on the response.

Supports PageNumberPaginator, LimitOffsetPaginator and CursorPaginator with the following rules based on the response data:

API

new InferredPaginator(currentStatePair,internalStatePair)

Source
ParameterTypeDescription
*currentStatePairany
*internalStatePairany

Methods

Go to the first page.

void

Return the state for the first page

Does not transition state. To transition state call first instead.

One of the following:

LimitOffsetPaginationState
KeyTypeDescription
limitnumber|string
offsetnumber|string

OR

CursorPaginationState
KeyTypeDescription
cursorstring
pageSizenumber

OR

PageNumberPaginationState
KeyTypeDescription
pagestring|number
pageSizestring|number

OR

null
ParameterTypeDescription
*currentInitany
PaginatorRequestOptions
KeyTypeDescription
headersHeadersInit|Record

Any headers to add to the request. You can unset default headers that might be specified in the default Endpoint.defaultConfig.requestInit by setting the value to undefined.

queryRecord

Any query request parameters

urlArgsRecord

Any arguments for the URL

Returns true if there's more results after the current page

boolean

Go to the last page. If the last page isn't yet known (eg. results haven't yet been returned) then null will be returned.

If the last page is not yet known because results haven't been returned this function does nothing. Not valid for CursorPaginator

void

Return the state for the first page

Does not transition state. To transition state call last instead.

Not valid for CursorPaginator

One of the following:

LimitOffsetPaginationState
KeyTypeDescription
limitnumber|string
offsetnumber|string

OR

PageNumberPaginationState
KeyTypeDescription
pagestring|number
pageSizestring|number

OR

null

Only valid if inferred paginator is LimitOffsetPaginator.

See LimitOffsetPaginator.limitState

ParameterTypeDescription
*limitnumber|null

One of the following:

LimitOffsetPaginationState
KeyTypeDescription
limitnumber|string
offsetnumber|string

OR

null

Go to the next page.

void

Return the state for the next page

Does not transition state. To transition state call next instead.

One of the following:

LimitOffsetPaginationState
KeyTypeDescription
limitnumber|string
offsetnumber|string

OR

CursorPaginationState
KeyTypeDescription
cursorstring
pageSizenumber

OR

PageNumberPaginationState
KeyTypeDescription
pagestring|number
pageSizestring|number

OR

null

Only valid if inferred paginator is LimitOffsetPaginator.

See LimitOffsetPaginator.offsetState

ParameterTypeDescription
*offsetnumber|null

One of the following:

LimitOffsetPaginationState
KeyTypeDescription
limitnumber|string
offsetnumber|string

OR

null

Only valid if inferred paginator is PageNumberPaginator.

See PageNumberPaginator.pageSizeState

ParameterTypeDescription
*pageSizenumber|null

One of the following:

CursorPaginationState
KeyTypeDescription
cursorstring
pageSizenumber

OR

PageNumberPaginationState
KeyTypeDescription
pagestring|number
pageSizestring|number

OR

null

Only valid if inferred paginator is PageNumberPaginator.

See PageNumberPaginator.pageState

ParameterTypeDescription
*pagenumber

One of the following:

PageNumberPaginationState
KeyTypeDescription
pagestring|number
pageSizestring|number

OR

null

Go to the previous page.

void

Return the state for the previous page

Does not transition state. To transition state call previous instead.

One of the following:

LimitOffsetPaginationState
KeyTypeDescription
limitnumber|string
offsetnumber|string

OR

CursorPaginationState
KeyTypeDescription
cursorstring
pageSizenumber

OR

PageNumberPaginationState
KeyTypeDescription
pagestring|number
pageSizestring|number

OR

null
ParameterTypeDescription
*__namedParameters[any, any]
*__namedParameters[any, any]
void

Only valid if inferred paginator is LimitOffsetPaginator.

See LimitOffsetPaginator.setLimit

ParameterTypeDescription
*limitnumber|null
void

Only valid if inferred paginator is LimitOffsetPaginator.

See LimitOffsetPaginator.setOffset

ParameterTypeDescription
*offsetnumber|null
void

Only valid if inferred paginator is PageNumberPaginator.

See PageNumberPaginator.setPage

ParameterTypeDescription
*pagenumber
void

Only valid if inferred paginator is PageNumberPaginator.

See PageNumberPaginator.setPageSize

ParameterTypeDescription
*pageSizenumber|null
void

Sets the internal data based on response. This is where the paginator is inferred based on values in the response.

See getPaginationState for how to customise this if your backend implementation differs.

ParameterTypeDescription
*responseRecord
void

Static Methods

ParameterTypeDescription
requestDetails.decodedBodyany

The value returned by decodedBody. See Endpoint.execute.

This may be a sub-key of the data returned by Endpoint.execute, eg. if the path option is used in paginationMiddleware. eg. If decodedBody from the Endpoint was

{
users: {
count: 10,
results: [...],
}
extraDetails: {...}
}

and paginationMiddleware was used with path: 'users' then decodedBody would be:

{
count: 10,
results: [...]
}
requestDetails.queryRecord

Any query string parameters

requestDetails.responseResponse

The Response object, if available

*requestDetails.urlstring

Resolved URL

requestDetails.urlArgsRecord

Any arguments used to resolve URL

One of the following:

Record

OR

false

Properties

The current cursor. Only valid if inferred paginator is CursorPaginator.

The current limit. Only valid if inferred paginator is LimitOffsetPaginator.

The next cursor. Only valid if inferred paginator is CursorPaginator.

The current offset. Only valid if inferred paginator is LimitOffsetPaginator.

The current page number. Only valid if inferred paginator is PageNumberPaginator.

The current page size. Only valid if inferred paginator is PageNumberPaginator.

The underlying inferred paginator instance (if known). Only available after setResponse has been called.

The previous cursor. Only valid if inferred paginator is CursorPaginator.

The total number of records available. Not valid if inferred paginator is CursorPaginator.

The total number of records available. Only valid if inferred paginator is PageNumberPaginator.