|
1 |
| -import {RedisClient} from 'redis'; |
2 |
| - |
3 |
| -type MutatingMethod = 'push' | 'remove' | 'removeIndex' | 'pop' | 'shift' | 'unshift'; |
4 |
| -type NonMutatingMethod = 'concat' | 'find' | 'findIndex' | 'includes' | 'indexOf' | 'lastIndexOf' | 'map' | 'length' | 'filter' | 'join' | 'forEach'; |
| 1 | +import { Redis } from 'ioredis'; |
| 2 | + |
| 3 | +type MutatingMethod = |
| 4 | + | 'push' |
| 5 | + | 'remove' |
| 6 | + | 'removeIndex' |
| 7 | + | 'pop' |
| 8 | + | 'shift' |
| 9 | + | 'unshift'; |
| 10 | +type NonMutatingMethod = |
| 11 | + | 'concat' |
| 12 | + | 'find' |
| 13 | + | 'findIndex' |
| 14 | + | 'includes' |
| 15 | + | 'indexOf' |
| 16 | + | 'lastIndexOf' |
| 17 | + | 'map' |
| 18 | + | 'length' |
| 19 | + | 'filter' |
| 20 | + | 'join' |
| 21 | + | 'forEach'; |
5 | 22 | type SupportedArrayMethod = MutatingMethod | NonMutatingMethod;
|
6 | 23 |
|
7 | 24 | interface Constants {
|
8 |
| - MutatingMethod: MutatingMethod[], |
9 |
| - NonMutatingMethod: NonMutatingMethod[], |
10 |
| - SupportedArrayMethod: SupportedArrayMethod[] |
| 25 | + MutatingMethod: MutatingMethod[]; |
| 26 | + NonMutatingMethod: NonMutatingMethod[]; |
| 27 | + SupportedArrayMethod: SupportedArrayMethod[]; |
11 | 28 | }
|
12 | 29 |
|
13 | 30 | interface RediteOptions {
|
14 |
| - client?: RedisClient; |
15 |
| - url?: string; |
16 |
| - serialise?: (value: any) => string; |
17 |
| - parse?: (value: string) => any; |
18 |
| - deletedString?: string; |
19 |
| - unref?: boolean; |
20 |
| - customInspection?: boolean; |
21 |
| - ignoreUndefinedValues?: boolean; |
| 31 | + client?: Redis; |
| 32 | + url?: string; |
| 33 | + serialise?: (value: any) => string; |
| 34 | + parse?: (value: string) => any; |
| 35 | + deletedString?: string; |
| 36 | + unref?: boolean; |
| 37 | + customInspection?: boolean; |
| 38 | + ignoreUndefinedValues?: boolean; |
22 | 39 | }
|
23 | 40 |
|
24 | 41 | declare function r(options?: RediteOptions): r.Redite;
|
25 | 42 |
|
26 | 43 | declare namespace r {
|
27 |
| - // Needs to be an interface in order to have a callable type. |
28 |
| - interface ChildWrapper { |
29 |
| - _stack: string[]; |
30 |
| - |
31 |
| - finally(onfinally?: (() => void) | undefined | null): Promise<any> |
32 |
| - then(onfulfilled?: ((value: any) => any) | undefined | null, onrejected?: ((reason: any) => any) | undefined | null): Promise<any>; |
33 |
| - catch(onrejected?: ((reason: any) => any) | undefined | null): Promise<any>; |
34 |
| - |
35 |
| - new(parentObj: Redite, parentKey: string, stack?: string[]); |
36 |
| - set(value: any): Promise<void>; |
37 |
| - has(key?: string): Promise<boolean>; |
38 |
| - exists(key?: string): Promise<boolean>; |
39 |
| - delete(key?: string): Promise<void>; |
40 |
| - |
41 |
| - // Array method emulators |
42 |
| - push(...values): Promise<void>; |
43 |
| - pop(): Promise<any>; |
44 |
| - shift(): Promise<any>; |
45 |
| - unshift(...values): Promise<void>; |
46 |
| - remove(value, amount?: number): Promise<void>; |
47 |
| - removeIndex(index: number): Promise<void>; |
48 |
| - |
49 |
| - concat(...values): Promise<any[]>; |
50 |
| - find(callback: (value, index?: number, array?: any[]) => boolean, thisArg?): Promise<any | undefined>; |
51 |
| - findIndex(callback: (value, index?: number, array?: any[]) => boolean, thisArg?): Promise<number>; |
52 |
| - includes(value, startIndex?: number): Promise<boolean>; |
53 |
| - indexOf(value, startIndex?: number): Promise<number>; |
54 |
| - lastIndexOf(value, startIndex?: number): Promise<number>; |
55 |
| - map(callback: (value, index?: number, array?: any[]) => any, thisArg?): Promise<any[]>; |
56 |
| - filter(callback: (value, index?: number, array?: any[]) => boolean, thisArg?): Promise<any[]>; |
57 |
| - join(separator?: string): Promise<string>; |
58 |
| - forEach(callback: (value, index?: number, array?: any[]) => void, thisArg?): Promise<any[]>; |
59 |
| - length(): Promise<number>; |
60 |
| - |
61 |
| - // Emulates proxy behaviour. |
62 |
| - [key: string]: ChildWrapper | any; |
63 |
| - [key: number]: ChildWrapper | any; |
64 |
| - } |
65 |
| - |
66 |
| - export class Redite { |
67 |
| - _redis: RedisClient; |
68 |
| - _serialise: (value: any) => string; |
69 |
| - _parse: (value: string) => any; |
70 |
| - _deletedString: string; |
71 |
| - _customInspection: boolean; |
72 |
| - _ignoreUndefinedValues: boolean; |
73 |
| - |
74 |
| - constructor(options?: RediteOptions); |
75 |
| - |
76 |
| - has(key: string): Promise<boolean>; |
77 |
| - delete(key: string): Promise<void>; |
78 |
| - |
79 |
| - getStack(key: string, stack?: string[]): Promise<any>; |
80 |
| - setStack(value: any, stack?: string[]): Promise<void>; |
81 |
| - deleteStack(key: string, stack?: string[]): Promise<void>; |
82 |
| - hasStack(key: string, stack?: string[]): Promise<boolean>; |
83 |
| - arrayStack(method: string, stack?: string[]): (...args) => Promise<any>; |
84 |
| - |
85 |
| - [key: string]: ChildWrapper | any; |
86 |
| - [key: number]: ChildWrapper | any; |
87 |
| - } |
88 |
| - |
89 |
| - export const Constants: Constants; |
90 |
| - export const ChildWrapper: ChildWrapper; |
| 44 | + // Needs to be an interface in order to have a callable type. |
| 45 | + interface ChildWrapper { |
| 46 | + _stack: string[]; |
| 47 | + |
| 48 | + finally(onfinally?: (() => void) | undefined | null): Promise<any>; |
| 49 | + then( |
| 50 | + onfulfilled?: ((value: any) => any) | undefined | null, |
| 51 | + onrejected?: ((reason: any) => any) | undefined | null |
| 52 | + ): Promise<any>; |
| 53 | + catch(onrejected?: ((reason: any) => any) | undefined | null): Promise<any>; |
| 54 | + |
| 55 | + new (parentObj: Redite, parentKey: string, stack?: string[]); |
| 56 | + set(value: any): Promise<void>; |
| 57 | + has(key?: string): Promise<boolean>; |
| 58 | + exists(key?: string): Promise<boolean>; |
| 59 | + delete(key?: string): Promise<void>; |
| 60 | + |
| 61 | + // Array method emulators |
| 62 | + push(...values): Promise<void>; |
| 63 | + pop(): Promise<any>; |
| 64 | + shift(): Promise<any>; |
| 65 | + unshift(...values): Promise<void>; |
| 66 | + remove(value, amount?: number): Promise<void>; |
| 67 | + removeIndex(index: number): Promise<void>; |
| 68 | + |
| 69 | + concat(...values): Promise<any[]>; |
| 70 | + find( |
| 71 | + callback: (value, index?: number, array?: any[]) => boolean, |
| 72 | + thisArg? |
| 73 | + ): Promise<any | undefined>; |
| 74 | + findIndex( |
| 75 | + callback: (value, index?: number, array?: any[]) => boolean, |
| 76 | + thisArg? |
| 77 | + ): Promise<number>; |
| 78 | + includes(value, startIndex?: number): Promise<boolean>; |
| 79 | + indexOf(value, startIndex?: number): Promise<number>; |
| 80 | + lastIndexOf(value, startIndex?: number): Promise<number>; |
| 81 | + map( |
| 82 | + callback: (value, index?: number, array?: any[]) => any, |
| 83 | + thisArg? |
| 84 | + ): Promise<any[]>; |
| 85 | + filter( |
| 86 | + callback: (value, index?: number, array?: any[]) => boolean, |
| 87 | + thisArg? |
| 88 | + ): Promise<any[]>; |
| 89 | + join(separator?: string): Promise<string>; |
| 90 | + forEach( |
| 91 | + callback: (value, index?: number, array?: any[]) => void, |
| 92 | + thisArg? |
| 93 | + ): Promise<any[]>; |
| 94 | + length(): Promise<number>; |
| 95 | + |
| 96 | + // Emulates proxy behaviour. |
| 97 | + [key: string]: ChildWrapper | any; |
| 98 | + [key: number]: ChildWrapper | any; |
| 99 | + } |
| 100 | + |
| 101 | + export class Redite { |
| 102 | + _redis: RedisClient; |
| 103 | + _serialise: (value: any) => string; |
| 104 | + _parse: (value: string) => any; |
| 105 | + _deletedString: string; |
| 106 | + _customInspection: boolean; |
| 107 | + _ignoreUndefinedValues: boolean; |
| 108 | + |
| 109 | + constructor(options?: RediteOptions); |
| 110 | + |
| 111 | + has(key: string): Promise<boolean>; |
| 112 | + delete(key: string): Promise<void>; |
| 113 | + |
| 114 | + getStack(key: string, stack?: string[]): Promise<any>; |
| 115 | + setStack(value: any, stack?: string[]): Promise<void>; |
| 116 | + deleteStack(key: string, stack?: string[]): Promise<void>; |
| 117 | + hasStack(key: string, stack?: string[]): Promise<boolean>; |
| 118 | + arrayStack(method: string, stack?: string[]): (...args) => Promise<any>; |
| 119 | + |
| 120 | + [key: string]: ChildWrapper | any; |
| 121 | + [key: number]: ChildWrapper | any; |
| 122 | + } |
| 123 | + |
| 124 | + export const Constants: Constants; |
| 125 | + export const ChildWrapper: ChildWrapper; |
91 | 126 | }
|
92 | 127 |
|
93 | 128 | export = r;
|
0 commit comments