InferredPaginator
SourceClass 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:
- If response contains
nextCursor
orpreviousCursor
value paginator is set to CursorPaginator - If response contains
limit
then paginator is set to LimitOffsetPaginator - If response contains
total
then paginator is set to PageNumberPaginator
API
Constructor
new InferredPaginator(currentStatePair,internalStatePair)
SourceParameter | Type | Description | |
---|---|---|---|
* | currentStatePair | any | |
* | internalStatePair | any |
Methods
firstState()
SourceReturn the state for the first page
Does not transition state. To transition state call first
instead.
One of the following:
LimitOffsetPaginationStateKey | Type | Description |
---|---|---|
limit | number|string | |
offset | number|string |
OR
CursorPaginationStateKey | Type | Description |
---|---|---|
cursor | string | |
pageSize | number |
OR
PageNumberPaginationStateKey | Type | Description |
---|---|---|
page | string|number | |
pageSize | string|number |
OR
nullgetRequestInit(currentInit)
SourceParameter | Type | Description | |
---|---|---|---|
* | currentInit | any |
Key | Type | Description |
---|---|---|
headers | HeadersInit|Record | Any headers to add to the request. You can unset default headers that might be specified in the default
|
query | Record | Any query request parameters |
urlArgs | Record | Any arguments for the URL |
last()
SourceGo 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
lastState()
SourceReturn the state for the first page
Does not transition state. To transition state call last
instead.
Not valid for CursorPaginator
One of the following:
LimitOffsetPaginationStateKey | Type | Description |
---|---|---|
limit | number|string | |
offset | number|string |
OR
PageNumberPaginationStateKey | Type | Description |
---|---|---|
page | string|number | |
pageSize | string|number |
OR
nulllimitState(limit)
SourceOnly valid if inferred paginator is LimitOffsetPaginator.
Parameter | Type | Description | |
---|---|---|---|
* | limit | number|null |
One of the following:
LimitOffsetPaginationStateKey | Type | Description |
---|---|---|
limit | number|string | |
offset | number|string |
OR
nullnextState()
SourceReturn the state for the next page
Does not transition state. To transition state call next
instead.
One of the following:
LimitOffsetPaginationStateKey | Type | Description |
---|---|---|
limit | number|string | |
offset | number|string |
OR
CursorPaginationStateKey | Type | Description |
---|---|---|
cursor | string | |
pageSize | number |
OR
PageNumberPaginationStateKey | Type | Description |
---|---|---|
page | string|number | |
pageSize | string|number |
OR
nulloffsetState(offset)
SourceOnly valid if inferred paginator is LimitOffsetPaginator.
Parameter | Type | Description | |
---|---|---|---|
* | offset | number|null |
One of the following:
LimitOffsetPaginationStateKey | Type | Description |
---|---|---|
limit | number|string | |
offset | number|string |
OR
nullpageSizeState(pageSize)
SourceOnly valid if inferred paginator is PageNumberPaginator.
Parameter | Type | Description | |
---|---|---|---|
* | pageSize | number|null |
One of the following:
CursorPaginationStateKey | Type | Description |
---|---|---|
cursor | string | |
pageSize | number |
OR
PageNumberPaginationStateKey | Type | Description |
---|---|---|
page | string|number | |
pageSize | string|number |
OR
nullpageState(page)
SourceOnly valid if inferred paginator is PageNumberPaginator.
Parameter | Type | Description | |
---|---|---|---|
* | page | number |
One of the following:
PageNumberPaginationStateKey | Type | Description |
---|---|---|
page | string|number | |
pageSize | string|number |
OR
nullpreviousState()
SourceReturn the state for the previous page
Does not transition state. To transition state call previous
instead.
One of the following:
LimitOffsetPaginationStateKey | Type | Description |
---|---|---|
limit | number|string | |
offset | number|string |
OR
CursorPaginationStateKey | Type | Description |
---|---|---|
cursor | string | |
pageSize | number |
OR
PageNumberPaginationStateKey | Type | Description |
---|---|---|
page | string|number | |
pageSize | string|number |
OR
nullreplaceStateControllers(props,props)
SourceParameter | Type | Description | |
---|---|---|---|
* | __namedParameters | [any, any] | |
* | __namedParameters | [any, any] |
setLimit(limit)
SourceOnly valid if inferred paginator is LimitOffsetPaginator.
Parameter | Type | Description | |
---|---|---|---|
* | limit | number|null |
setOffset(offset)
SourceOnly valid if inferred paginator is LimitOffsetPaginator.
Parameter | Type | Description | |
---|---|---|---|
* | offset | number|null |
setPage(page)
SourceOnly valid if inferred paginator is PageNumberPaginator.
Parameter | Type | Description | |
---|---|---|---|
* | page | number |
setPageSize(pageSize)
SourceOnly valid if inferred paginator is PageNumberPaginator.
Parameter | Type | Description | |
---|---|---|---|
* | pageSize | number|null |
setResponse(response)
SourceSets 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.
Parameter | Type | Description | |
---|---|---|---|
* | response | Record |
Static Methods
getPaginationState(requestDetails)
SourceParameter | Type | Description | |
---|---|---|---|
requestDetails.decodedBody | any | The value returned by This may be a sub-key of the data returned by
and
| |
requestDetails.query | Record | Any query string parameters | |
requestDetails.response | Response | The | |
* | requestDetails.url | string | Resolved URL |
requestDetails.urlArgs | Record | Any arguments used to resolve URL |
One of the following:
RecordOR
falseProperties
currentState: PaginatorState
cursor: string|null
The current cursor. Only valid if inferred paginator is CursorPaginator.
internalState: Record
limit: number|null
The current limit. Only valid if inferred paginator is LimitOffsetPaginator.
nextCursor: string|null
The next cursor. Only valid if inferred paginator is CursorPaginator.
offset: number|null
The current offset. Only valid if inferred paginator is LimitOffsetPaginator.
page: number|null
The current page number. Only valid if inferred paginator is PageNumberPaginator.
pageSize: number|null
The current page size. Only valid if inferred paginator is PageNumberPaginator.
paginator: undefined|CursorPaginator|PageNumberPaginator|LimitOffsetPaginator
The underlying inferred paginator instance (if known). Only available after setResponse
has been called.
previousCursor: string|null
The previous cursor. Only valid if inferred paginator is CursorPaginator.
responseIsSet: boolean
setCurrentState: Function
setInternalState: Function
total: number|null
The total number of records available. Not valid if inferred paginator is CursorPaginator.
totalPages: number|null
The total number of records available. Only valid if inferred paginator is PageNumberPaginator.