Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@adiwajshing/keyed-db/lib/KeyedDB.d.ts
1126 views
1
import { IKeyedDB, Identifiable, Comparable, PaginationMode } from "./Types";
2
export default class KeyedDB<T, K> implements IKeyedDB<T, K> {
3
private array;
4
private dict;
5
private key;
6
private idGetter;
7
/**
8
* @param key Return the unique key used to sort items
9
* @param id The unique ID for the items
10
*/
11
constructor(key: Comparable<T, K>, id?: Identifiable<T>);
12
get length(): number;
13
get first(): T;
14
get last(): T;
15
toJSON(): T[];
16
/**
17
* Inserts items into the DB in klogN time.
18
* Where k is the number of items being inserted.
19
* @param values
20
*/
21
insert(...values: T[]): void;
22
/**
23
* Upserts items into the DB in 2klogN time.
24
* Where k is the number of items being inserted.
25
*
26
* If a duplicate is found, it is deleted first and then the new one is inserted
27
* @param values
28
* @returns list of updated values
29
*/
30
upsert(...values: T[]): T[];
31
/**
32
* Inserts items only if they are not present in the DB
33
* @param values
34
* @returns list of all the inserted values
35
*/
36
insertIfAbsent(...values: T[]): T[];
37
/**
38
* Deletes an item indexed by the ID
39
* @param id
40
* @param assertPresent
41
*/
42
deleteById(id: string, assertPresent?: boolean): T;
43
delete(value: T): T;
44
slice(start?: number, end?: number): KeyedDB<T, K>;
45
/** Clears the DB */
46
clear(): void;
47
get(id: string): T;
48
all(): T[];
49
/**
50
* Updates a value specified by the ID
51
* and adjusts its position in the DB after an update if required
52
* @param id
53
* @param update
54
*/
55
update(id: string, update: (value: T) => void): 1 | 2;
56
/**
57
* @deprecated see `update`
58
*/
59
updateKey(value: T, update: (value: T) => void): 1 | 2;
60
filter(predicate: (value: T, index: number) => boolean): KeyedDB<T, K>;
61
/**
62
* Get the values of the data in a paginated manner
63
* @param value the value itself beyond which the content is to be retreived
64
* @param limit max number of items to retreive
65
* @param predicate optional filter
66
* @param mode whether to get the content `before` the cursor or `after` the cursor; default=`after`
67
*/
68
paginatedByValue(value: T | null, limit: number, predicate?: (value: T, index: number) => boolean, mode?: PaginationMode): T[];
69
/**
70
* Get the values of the data in a paginated manner
71
* @param value the cursor beyond which the content is to be retreived
72
* @param limit max number of items to retreive
73
* @param predicate optional filter
74
* @param mode whether to get the content `before` the cursor or `after` the cursor; default=`after`
75
*/
76
paginated(cursor: K | null, limit: number, predicate?: (value: T, index: number) => boolean, mode?: PaginationMode): T[];
77
private _insertSingle;
78
private filtered;
79
private firstIndex;
80
}
81
82