Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/dynablox_opencloud/src/helpers/ServicePaging.ts>ServicePage

A Roblox OpenCloud API wrapper for Deno and NodeJS written in TypeScript.
Latest
class ServicePage
import { ServicePage } from "https://deno.land/x/dynablox_opencloud@v0.2.2/src/helpers/ServicePaging.ts";

Service paging.

Constructors

new
ServicePage(
service: BaseService,
pageFunction: PageFunction,
parameters: Parameters<PageFunction>,
nextPageFunction: (parameters: Parameters<PageFunction>, data?: Awaited<ReturnType<PageFunction>>) => Parameters<PageFunction> | undefined,
previousPageFunction?: (parameters: Parameters<PageFunction>, data?: Awaited<ReturnType<PageFunction>>) => Parameters<PageFunction> | undefined,
dataTransformer?: (data: Awaited<ReturnType<PageFunction>>) => DataTransformed,
data?: Awaited<ReturnType<PageFunction>>,
pageNumber?: number,
)

Construct a new service paging helper.

Type Parameters

PageFunction extends (...args: any[]) => Promise<unknown>
optional
DataTransformed = Awaited<ReturnType<PageFunction>>

Properties

private
optional
_data: Awaited<ReturnType<PageFunction>>

The data returned from the last call. If it is undefined, then getCurrentPage() has not been called yet.

private
readonly
optional
_dataTransformer: (data: Awaited<ReturnType<PageFunction>>) => DataTransformed

Data tranformer to be read by external sources.

private
readonly
_nextPageFunction: (parameters: Parameters<PageFunction>, data?: Awaited<ReturnType<PageFunction>>) => Parameters<PageFunction> | undefined

The next page function to refer to for parameters.

private
readonly
_pageFunction: PageFunction

The function to paginate.

private
readonly
_parameters: Parameters<PageFunction>

The current parameters as of current request.

private
readonly
_previousPageFunction: ((parameters: Parameters<PageFunction>, data?: Awaited<ReturnType<PageFunction>>) => Parameters<PageFunction> | undefined) | undefined

The previous page function to refer to for parameters.

private
readonly
_service: BaseService

The service to call pageFunction from.

readonly
data: DataTransformed | Awaited<ReturnType<PageFunction>> | undefined

The returned from the last call. If it is undefined, then getCurrentPage() has not been called yet.

This data is either modified or the original data from the API response.

pageNumber: number

The page number.

Methods

Re-fetch the current page and replaces current data wirh new data.

Paginate to the next page. If nextPageFunction returns undefined, it will error. Otherwise, it will go on with the request.

Paginate to the previous page. It will error if previousPageFunction was never supplied. If preivousPageFunction returns undefined, it will error. Otherwise, it will go on with the request.

hasNextPage(): boolean

Get if there is a next page.

hasPreviousPage(): boolean

Get if there is a previous page.

[Symbol.asyncIterator](): AsyncGenerator<Awaited<DataTransformed>, void, void>

Async iterator implementation for the data.