Class: PageHelper

PageHelper


new PageHelper(client, set, params, options)

A wrapper that provides a helpful API for consuming FaunaDB pages.

Generally this is constructed through the Client#paginate method.

The PageHelper#map and PageHelper#filter methods will wrap the underlying query with a Map and Filter query function, respectively. These will be executed on the server when a promise-returning function is called.

The PageHelper#each and PageHelper#eachReverse functions dispatch queries to FaunaDB, and return Promises representing the completion of those queries. The callbacks provided to these functions are executed locally when the queries return.

The PageHelper#nextPage and PageHelper#previousPage functions also dispatch queries to FaunaDB, but return their responses in a wrapped Promise.

Parameters:
Name Type Argument Description
client Client

The FaunaDB client used to paginate.

set Object

The set to paginate.

params Object <nullable>

Parameters to be passed to the FaunaDB Paginate function.

options Object <nullable>

Object that configures the current pagination, overriding FaunaDB client options.

Properties
Name Type Argument Description
secret string <nullable>

FaunaDB secret (see Reference Documentation)

Methods


each(lambda)

Executes the provided function for each page.

Parameters:
Name Type Description
lambda PageHelper~eachFunction

A function to be executed for each page.

Returns:
Type
external:Promise.<void>

eachReverse(lambda)

Executes the provided function for each page, in the reverse direction.

Parameters:
Name Type Description
lambda PageHelper~eachFunction
Returns:
Type
external:Promise.<void>

filter(lambda)

Wraps the set to be paginated with a FaunaDB Filter funciton. As this function is executed on the server, the lambda param must return a valid query expression.

Parameters:
Name Type Description
lambda PageHelper~collectionFunction

The lambda expression to be passed into the Filter function.

Returns:
Type
PageHelper

map(lambda)

Wraps the set to be paginated with a FaunaDB Map function. As this function is executed on the server, the lambda param must return a valid query expression.

Parameters:
Name Type Description
lambda PageHelper~collectionFunction

The Lambda expression to be passed into the Map function.

Returns:
Type
PageHelper

nextPage()

Queries for the next page from the current cursor point; this mutates the state of the PageHelper when the query completes, updating the internal cursor state to that of the returned page.

Returns:
Type
external:Promise.<object>

previousPage()

Queries for the previous page from the current cursor point; this mutates the state of the PageHelper when the query completes, updating the internal cursor state to that of the returned page.

Returns:
Type
external:Promise.<object>

Type Definitions


collectionFunction(var)

A FaunaDB Lambda expression to be passed into one of the collection functions: Map or Filter.

Parameters:
Name Type Description
var any

The variable passed in by FaunaDB when this Lambda function is executed.

Returns:

The FaunaDB query expression to be returned by this Lambda.

Type
Expr

eachFunction(page)

Parameters:
Name Type Description
page Object

A page returned by FaunaDB's Paginate function.