export type Id = string | number; export interface PaginationMeta { /** Store the ids for each page index. */ ids: Id[]; noMore: boolean; } export interface Pagination { items: Data[]; noMore: boolean; } export interface PaginationState { entityRecord: Record; paginationMetaRecord: Record; } export interface PaginationAdapter { initialState: PaginationState; /** * Add the data to the state. */ createOne(draft: PaginationState, rawData: RawData): void; /** * Try to read the data with the specified id. * If it is not existed, return `undefined`. */ tryReadOne(state: PaginationState, id: Id): Data | undefined; /** * Returns a function that accept a `state` as a parameter. * It is useful when you are using `useAccessor`. */ tryReadOneFactory(id: Id): (state: PaginationState) => Data | undefined; /** * Read the data with the specify id. If the data is not existed, it will throw an error. * This function is useful when you are sure that the data is existed. */ readOne(state: PaginationState, id: Id): Data; /** * Update the entity with the new data. If the entity is not existed, do nothing. */ updateOne(draft: PaginationState, id: Id, data: Partial): void; /** * Delete the entity with the specified id and remove the data from pagination (if existed). */ deleteOne(draft: PaginationState, id: Id): void; /** * Update the entity with the data. If the entity is not existed, insert it to the state. */ upsertOne(draft: PaginationState, rawData: RawData): void; /** * Try to read the pagination meta. If the meta is not existed, return `undefined`. */ tryReadPaginationMeta(state: PaginationState, key: string): PaginationMeta | undefined; /** * This function returns a function that accepts a state as the only one parameter. * It is useful when using `useAccessor`. */ tryReadPaginationMetaFactory(key: string): (state: PaginationState) => PaginationMeta | undefined; /** * Read the pagination meta with the specified key. If it is not existed, throw an error. * It is useful when you are sure that the pagination is existed. */ readPaginationMeta(state: PaginationState, key: string): PaginationMeta; /** * Try to read the pagination with the specified key. If it is not existed, return `undefined`. */ tryReadPagination(state: PaginationState, key: string): Pagination | undefined; /** * Returns a function that accepts state as the only one parameter. * If is useful when using `useAccessor`. */ tryReadPaginationFactory(key: string): (state: PaginationState) => Pagination | undefined; /** * Read the pagination with the specified key. If the pagination is not existed, throw an error. * It is useful when you are sure that the pagination is existed. */ readPagination(state: PaginationState, key: string): Pagination; /** * Replace the whole pagination with the given data array. */ replacePagination(draft: PaginationState, key: string, data: RawData[]): void; /** * Append the data to the pagination. If the pagination is not existed, create one. */ appendPagination(draft: PaginationState, key: string, data: RawData[]): void; /** * Prepend the data to the pagination. If the pagination is not existed, create one. */ prependPagination(draft: PaginationState, key: string, data: RawData[]): void; /** * Set the `noMore` property in the pagination meta. */ setNoMore(draft: PaginationState, key: string, noMore: boolean): void; /** * Sort the pagination by the `compare` function. */ sortPagination(draft: PaginationState, key: string, compare: (a: Data, b: Data) => number): void; } export declare function createPaginationAdapter({ getId, transform, }?: { getId?: (data: Data) => Id; transform?: (rawData: RawData) => Data; }): PaginationAdapter;