-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
90 lines (73 loc) · 3.1 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
// Type definitions for LevelUp
// Project: https://github.com/Level/levelup
// Definitions by: Bret Little <https://github.com/blittle>, Thiago de Arruda <https://github.com/tarruda>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export = levelup;
declare var levelup: levelup.LevelUpConstructor;
declare namespace levelup {
interface CustomEncoding {
encode(val: any): Buffer| string;
decode(val: Buffer | string): any;
buffer: boolean;
type: string;
}
type Encoding = string | CustomEncoding;
interface Batch {
type: string;
key: any;
value?: any;
keyEncoding?: Encoding;
valueEncoding?: Encoding;
}
interface LevelUpBase<BatchType extends Batch> {
open(callback: (error : any) => any): void;
open(): Promise<LevelUp>;
close(callback: (error : any) => any): void;
close(): Promise<undefined>;
put(key: any, value: any): Promise<undefined>;
put(key: any, value: any, callback: (error: any) => any): void;
put(key: any, value: any, options: { sync?: boolean }): Promise<undefined>;
put(key: any, value: any, options: { sync?: boolean }, callback: (error: any) => any): void;
get(key: any): Promise<Buffer>;
get(key: any, callback: (error: any, value: any) => any): void;
get(key: any, options: { keyEncoding?: Encoding; fillCache?: boolean }): Promise<Buffer>;
get(key: any, options: { keyEncoding?: Encoding; fillCache?: boolean }, callback: (error: any, value: any) => any): void;
del(key: any): Promise<undefined>;
del(key: any, callback: (error: any) => any): void;
del(key: any, options: { keyEncoding?: Encoding; sync?: boolean }): Promise<undefined>;
del(key: any, options: { keyEncoding?: Encoding; sync?: boolean }, callback: (error: any) => any): void;
batch(array: BatchType[]): Promise<undefined>;
batch(array: BatchType[], callback: (error?: any)=>any): void;
batch(array: BatchType[], options: { keyEncoding?: Encoding; valueEncoding?: Encoding; sync?: boolean }): Promise<undefined>;
batch(array: BatchType[], options: { keyEncoding?: Encoding; valueEncoding?: Encoding; sync?: boolean }, callback: (error?: any)=>any): void;
batch():LevelUpChain;
isOpen():boolean;
isClosed():boolean;
createReadStream(options?: any): any;
createKeyStream(options?: any): any;
createValueStream(options?: any): any;
}
type LevelUp = LevelUpBase<Batch>
interface LevelUpChain {
put(key: any, value: any): LevelUpChain;
put(key: any, value: any, options?: { sync?: boolean }): LevelUpChain;
del(key: any): LevelUpChain;
del(key: any, options ?: { keyEncoding?: Encoding; sync?: boolean }): LevelUpChain;
clear(): LevelUpChain;
write() : Promise<undefined>;
write(callback: (error?: any)=>any) : void;
}
interface levelupOptions {
createIfMissing?: boolean;
errorIfExists?: boolean;
compression?: boolean;
cacheSize?: number;
keyEncoding?: Encoding;
valueEncoding?: Encoding;
db?: any;//Requires leveldown
}
interface LevelUpConstructor {
(hostname: string, options?: levelupOptions): LevelUp;
}
}