objection-paginator
Version:
Paginated queries for Objection.js
84 lines (83 loc) • 2.28 kB
TypeScript
/**
* Describes the structure of cursor objects in transit.
*
* @remarks
* Properties here have abbreviated names to avoid wasting network resources.
*/
export interface CursorObj {
/**
* The Paginator's query name.
*/
q: string;
/**
* The Paginator's sort name.
*/
s: string;
/**
* The cursor values, if any.
*/
v?: any[];
}
/**
* An internal class which represents a decoded cursor.
*
* @remarks
* This class is responsible for serialization and parsing of cursors, as well
* as some initial validation that does not depend on sort configuration.
*/
export declare class Cursor {
/**
* The Paginator's query name.
*/
query: string;
/**
* The Paginator's sort name.
*/
sort: string;
/**
* The cursor's values, if any.
*/
values?: any[];
/**
* Creates a Cursor.
* @param query - The query name from the Paginator.
* @param sort - The sort name from the Paginator.
* @param values - The cursor's values, if any.
*/
constructor(query: string, sort: string, values?: any[]);
/**
* Creates a Cursor from its abbreviated object form.
* @param obj - The abbreviated object form.
* @returns The created Cursor.
*/
static fromObject(obj: CursorObj): Cursor;
/**
* Validates a parsed cursor object, still in its abbreviated form.
*
* @remarks
* This method will throw if the value does not conform to the CursorObj
* interface. It is needed to ensure our cursor typings remain correct at
* runtime.
*
* @param value - The abbreviated object form.
* @returns The unmutated value.
*/
static validateObject(value: any): CursorObj;
/**
* Creates a Cursor from a serialized string.
* @param str - The serialized cursor string.
* @returns The created cursor.
*/
static parse(str: string): Cursor;
/**
* Converts a Cursor into its abbreviated object form, in preparation for
* serialization.
* @returns The abbreviated cursor object.
*/
toObject(): CursorObj;
/**
* Converts a cursor to a serialized string.
* @returns The serialized cursor string.
*/
serialize(): string;
}