Path: blob/master/node_modules/@adiwajshing/keyed-db/lib/KeyedDB.d.ts
1126 views
import { IKeyedDB, Identifiable, Comparable, PaginationMode } from "./Types";1export default class KeyedDB<T, K> implements IKeyedDB<T, K> {2private array;3private dict;4private key;5private idGetter;6/**7* @param key Return the unique key used to sort items8* @param id The unique ID for the items9*/10constructor(key: Comparable<T, K>, id?: Identifiable<T>);11get length(): number;12get first(): T;13get last(): T;14toJSON(): T[];15/**16* Inserts items into the DB in klogN time.17* Where k is the number of items being inserted.18* @param values19*/20insert(...values: T[]): void;21/**22* Upserts items into the DB in 2klogN time.23* Where k is the number of items being inserted.24*25* If a duplicate is found, it is deleted first and then the new one is inserted26* @param values27* @returns list of updated values28*/29upsert(...values: T[]): T[];30/**31* Inserts items only if they are not present in the DB32* @param values33* @returns list of all the inserted values34*/35insertIfAbsent(...values: T[]): T[];36/**37* Deletes an item indexed by the ID38* @param id39* @param assertPresent40*/41deleteById(id: string, assertPresent?: boolean): T;42delete(value: T): T;43slice(start?: number, end?: number): KeyedDB<T, K>;44/** Clears the DB */45clear(): void;46get(id: string): T;47all(): T[];48/**49* Updates a value specified by the ID50* and adjusts its position in the DB after an update if required51* @param id52* @param update53*/54update(id: string, update: (value: T) => void): 1 | 2;55/**56* @deprecated see `update`57*/58updateKey(value: T, update: (value: T) => void): 1 | 2;59filter(predicate: (value: T, index: number) => boolean): KeyedDB<T, K>;60/**61* Get the values of the data in a paginated manner62* @param value the value itself beyond which the content is to be retreived63* @param limit max number of items to retreive64* @param predicate optional filter65* @param mode whether to get the content `before` the cursor or `after` the cursor; default=`after`66*/67paginatedByValue(value: T | null, limit: number, predicate?: (value: T, index: number) => boolean, mode?: PaginationMode): T[];68/**69* Get the values of the data in a paginated manner70* @param value the cursor beyond which the content is to be retreived71* @param limit max number of items to retreive72* @param predicate optional filter73* @param mode whether to get the content `before` the cursor or `after` the cursor; default=`after`74*/75paginated(cursor: K | null, limit: number, predicate?: (value: T, index: number) => boolean, mode?: PaginationMode): T[];76private _insertSingle;77private filtered;78private firstIndex;79}808182