-
Notifications
You must be signed in to change notification settings - Fork 0
/
redite.d.ts
125 lines (108 loc) · 3.43 KB
/
redite.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { Redis } from "ioredis";
type MutatingMethod =
| "push"
| "remove"
| "removeIndex"
| "pop"
| "shift"
| "unshift";
type NonMutatingMethod =
| "concat"
| "find"
| "findIndex"
| "includes"
| "indexOf"
| "lastIndexOf"
| "map"
| "length"
| "filter"
| "join"
| "forEach";
type SupportedArrayMethod = MutatingMethod | NonMutatingMethod;
interface Constants {
MutatingMethod: MutatingMethod[];
NonMutatingMethod: NonMutatingMethod[];
SupportedArrayMethod: SupportedArrayMethod[];
}
interface RediteOptions {
client?: Redis;
url?: string;
serialise?: (value: any) => string;
parse?: (value: string) => any;
deletedString?: string;
ignoreUndefinedValues?: boolean;
}
declare function r(options?: RediteOptions): r.Redite;
declare namespace r {
// Needs to be an interface in order to have a callable type.
interface ChildWrapper {
_stack: string[];
finally(onfinally?: (() => void) | undefined | null): Promise<any>;
then(
onfulfilled?: ((value: any) => any) | undefined | null,
onrejected?: ((reason: any) => any) | undefined | null
): Promise<any>;
catch(onrejected?: ((reason: any) => any) | undefined | null): Promise<any>;
new (parentObj: Redite, parentKey: string, stack?: string[]);
set(value: any): Promise<void>;
has(key?: string): Promise<boolean>;
exists(key?: string): Promise<boolean>;
delete(key?: string): Promise<void>;
// Array method emulators
push(...values): Promise<void>;
pop(): Promise<any>;
shift(): Promise<any>;
unshift(...values): Promise<void>;
remove(value, amount?: number): Promise<void>;
removeIndex(index: number): Promise<void>;
concat(...values): Promise<any[]>;
find(
callback: (value, index?: number, array?: any[]) => boolean,
thisArg?
): Promise<any | undefined>;
findIndex(
callback: (value, index?: number, array?: any[]) => boolean,
thisArg?
): Promise<number>;
includes(value, startIndex?: number): Promise<boolean>;
indexOf(value, startIndex?: number): Promise<number>;
lastIndexOf(value, startIndex?: number): Promise<number>;
map(
callback: (value, index?: number, array?: any[]) => any,
thisArg?
): Promise<any[]>;
filter(
callback: (value, index?: number, array?: any[]) => boolean,
thisArg?
): Promise<any[]>;
join(separator?: string): Promise<string>;
forEach(
callback: (value, index?: number, array?: any[]) => void,
thisArg?
): Promise<any[]>;
length(): Promise<number>;
// Emulates proxy behaviour.
[key: string]: ChildWrapper | any;
[key: number]: ChildWrapper | any;
}
export class Redite {
$redis: Redis;
$serialise: (value: any) => string;
$parse: (value: string) => any;
$deletedString: string;
$ignoreUndefinedValues: boolean;
constructor(options?: RediteOptions);
has(key: string): Promise<boolean>;
delete(key: string): Promise<void>;
getStack(key: string, stack?: string[]): Promise<any>;
setStack(value: any, stack?: string[]): Promise<void>;
deleteStack(key: string, stack?: string[]): Promise<void>;
hasStack(key: string, stack?: string[]): Promise<boolean>;
arrayStack(method: string, stack?: string[]): (...args) => Promise<any>;
[key: string]: ChildWrapper | any;
[key: number]: ChildWrapper | any;
}
export const Constants: Constants;
export const ChildWrapper: ChildWrapper;
}
export = r;