import NativeArray from '@ember/array/-private/native-array'; import RouterService from '@ember/routing/router-service'; import { TaskGenerator } from 'ember-concurrency'; import DS from 'ember-data'; import { QueryParamsObj } from '@gavant/ember-pagination/utils/query-params'; export declare type RecordArrayWithMeta = DS.AdapterPopulatedRecordArray & { meta: any; }; export interface ResponseMetadata { totalCount: number; } export interface Sorting { valuePath: string; sortPath?: string; isAscending: boolean; } export interface PaginationConfigs { limit?: number; filterList?: (keyof T)[]; includeList?: string[]; pagingRootKey?: string | null; filterRootKey?: string | null; includeKey?: string; sortKey?: string; serializeFilterValue?: (key: string, value: any) => string | null | undefined; processQueryParams?: (params: QueryParamsObj) => QueryParamsObj; onChangeSorting?: (sorts: string[], newSorts?: Sorting[]) => Promise | void; } export interface PaginationArgs extends PaginationConfigs { context: C; modelName: string; models: NativeArray | T[]; metadata?: M; sorts?: string[]; } export declare class Pagination { store: DS.Store; router: RouterService; /** * Configuration properties used to customize request parameters * @type {PaginationConfigs} * @memberof Pagination */ config: PaginationConfigs; /** * The parent context object, usually a Controller or Component * @type {*} * @memberof Pagination */ context: any; /** * The name of Ember Data model being paginated * @type {String} * @memberof Pagination */ modelName: string; /** * An array of sort property names sent on requests to sort the results * @type {(String[] | undefined)} * @memberof Pagination */ sorts: string[] | undefined; /** * The array of all the models currently loaded from pagination requests * @type {(NativeArray | T[])} * @memberof Pagination */ models: NativeArray | T[]; /** * The current metadata returned by the most recent pagination request * @type {(M | undefined)} * @memberof Pagination */ metadata: M | undefined; /** * Whether or not the API may have more results, based on the defined limit * and the number of results returned by the last request * @type {Boolean} * @memberof Pagination */ hasMore: boolean; /** * Tracks when a pagination request is currently in progress * Templates and application code should use `isLoadingModels` instead * @private * @type {Boolean} * @memberof Pagination */ private isLoading; /** * Whether or not a loading substate route is currently rendered * @readonly * @type {Boolean} * @memberof Pagination */ get isLoadingRoute(): boolean; /** * Whether or not the loadModels concurrency task is currently running * @readonly * @type {Boolean} * @memberof Pagination */ get isLoadModelsTaskRunning(): boolean; /** * Returns true if a pagination request is currently in progress * or a loading substate route is rendered. This should be used * in templates/app code to check if the paginator is "loading" * @readonly * @type {Boolean} * @memberof Pagination */ get isLoadingModels(): boolean; /** * The current offset to send in pagination requests, * based on the number of already loaded models * @readonly * @type {Number} * @memberof Pagination */ get offset(): number; /** * Sets the initial pagination data/configuration which at minimum, requires * a context, modelName, and initial models/metadata * @param {PaginationArgs} args */ constructor(args: PaginationArgs); /** * Sets various pagination configurations * @param {PaginationConfigs} args * @memberof Pagination */ setConfigs(config: PaginationConfigs): void; /** * Utility method for completely replacing the current models array/metadata * @param {NativeArray | T[]} models * @param {M} metadata * @memberof Pagination */ setModels(models: NativeArray | T[], metadata?: M): void; /** * Builds the query params object and makes the request for the next * page of results (or the first page, if reset is true) * @param {Boolean} reset * @param {Boolean} clearAfterRequest * @returns {Promise} * @memberof Pagination */ loadModels(reset?: boolean, clearAfterRequest?: boolean): TaskGenerator; /** * Makes the store.query() request using the provided query params object * @param {any} queryParams * @returns {Promise>} * @memberof Pagination */ queryModels(queryParams: any): Promise>; /** * Loads the next page of models if there are more to load and is not currently loading * @returns {Promise | null} * @memberof Pagination */ loadMoreModels(): Promise; /** * Reloads the first page of models, alias for `loadModels(true)` * @param {Boolean} clearAfterRequest * @returns {Promise} * @memberof Pagination */ reloadModels(clearAfterRequest?: boolean): import("ember-concurrency").TaskInstance; /** * Reloads the first page of models w/filters applied, alias for `loadModels(true)` * @param {Boolean} clearAfterRequest * @returns {Promise} * @memberof Pagination */ filterModels(clearAfterRequest?: boolean): import("ember-concurrency").TaskInstance; /** * Clears all current model models array * @memberof Pagination */ clearModels(): void; /** * Deletes the model and removes it from the models array * @param {T} model * @returns {Promise} * @memberof Pagination */ removeModel(model: T): Promise; /** * Updates the current sorts, calls an onChangeSorting() handler if provided * and reloads the first page of models * @param {Sorting[]} newSorts * @memberof Pagination */ changeSorting(newSorts: Sorting[]): Promise; /** * Clears the current sorts and reloads the first page of models * @memberof Pagination */ clearSorting(): Promise; /** * Clears all models from the models array and resets the current state * Sometimes useful in resetController() when the pagination may not * be recreated/overwritten on every transition, and you want to clear * it when leaving the page. * @memberof Pagination */ reset(): void; } /** * Creates and returns a new Pagination instance and binds its owner to be the same as * that of its parent "context" (e.g. Controller, Component, etc). * In most cases, this returned instance should be assigned to a @tracked property * on its parent context, so that it can be accessed on the associated template * @param {PaginationArgs} args */ declare const usePagination: (args: PaginationArgs) => Pagination; export default usePagination;