This repository has been archived by the owner on Jul 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
108 lines (76 loc) · 3.11 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { EventEmitter } from "events";
import { MongoError, Collection } from "mongodb";
declare module "./" {
type ClientOptions = {
username?: string;
password?: string;
port?: number;
host?: string;
url?: string;
dbName: string;
}
type PieceOptions = {
fetchAll?: boolean;
autoCacheSync?: boolean;
}
type RawData<TKey, TValue> = {
_id: TKey;
value: TValue;
[key: string]: any;
}
interface ClientEvents {
close: [];
reconnect: [any];
timeout: [MongoError];
change: [any];
}
interface DynamicObject {
[key: string]: Piece;
}
export const version: string;
export class Client extends EventEmitter {
defer: Promise<void>;
dbName: string;
isReady: boolean;
closed: boolean;
constructor(options: ClientOptions);
multi(names: string[], options?: PieceOptions): DynamicObject;
piece<TKey = any, TValue = any>(name: string, options?: PieceOptions): Piece<TKey, TValue>;
close(): void;
on<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this;
once<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this;
emit<K extends keyof ClientEvents>(event: K, ...args: ClientEvents[K]): boolean;
}
export class Piece<TKey = any, TValue = any> extends EventEmitter {
base: Collection<{ TKey: TValue }>;
client: Client;
cache: Map<TKey, TValue>;
hasCache: boolean;
isCacheReady: boolean;
constructor(base: Collection, client: Client, options?: PieceOptions);
set(key: TKey, val: TValue, path?: string): Promise<void>;
push(key: TKey, val: TValue, path?: string, allowDupes?: boolean): Promise<void>;
ensure(key: TKey, val: TValue): Promise<TValue>;
ensure(key: TKey, val: TValue, path?: string): Promise<any>;
ensure(key: TKey, val: TValue, path?: string, raw?: boolean): Promise<RawData<TKey, TValue>>;
get(key: TKey): Promise<TValue>
get(key: TKey, path?: string): Promise<any>
get(key: TKey, path?: string, raw?: boolean): Promise<RawData<TKey, TValue>>;
fetch(key: TKey): Promise<TValue>
fetch(key: TKey, path?: string): Promise<any>
fetch(key: TKey, path?: string, raw?: boolean): Promise<RawData<TKey, TValue>>;
fetchAll(): Promise<void>;
has(key: TKey, path?: string): Promise<boolean>;
delete(key: TKey, path?: string): Promise<void>;
clear(): Promise<void>;
evict(key: TKey, path?: string): void;
evictAll(): void;
valueArray(cache?: boolean): Promise<TValue[]>;
keyArray(cache?: boolean): Promise<TKey[]>;
rawArray(): Promise<RawData<TKey, TValue>[]>;
size(fast?: boolean): Promise<number>;
on(event: "change", listener: (change: any) => void): this;
once(event: "change", listener: (change: any) => void): this;
emit(event: "change", change: any): boolean;
}
}