1
+ const hasToken = ( types , token ) => {
2
+ if ( Array . isArray ( token ) ) return token . some ( ( t ) => hasToken ( types , t ) ) ;
3
+ return types . find ( ( type ) => type . includes ( token ) ) ;
4
+ } ;
5
+
6
+ const matchSubcommand = ( types , subcommand ) => {
7
+ if ( Array . isArray ( subcommand ) )
8
+ return subcommand . some ( ( s ) => matchSubcommand ( types , s ) ) ;
9
+ return types [ 0 ] . includes ( subcommand ) ;
10
+ } ;
11
+
1
12
module . exports = {
2
13
multi : "ChainableCommander" ,
3
14
get : "string | null" ,
4
15
set : ( types ) => {
5
- if ( types . find ( ( type ) => type . includes ( "GET" ) ) ) {
6
- return "string | null" ;
7
- }
8
- if ( types . find ( ( type ) => type . includes ( "NX" ) || type . includes ( "XX" ) ) ) {
9
- return "'OK' | null" ;
10
- }
16
+ if ( hasToken ( types , "GET" ) ) return "string | null" ;
17
+ if ( hasToken ( types , [ "NX" , "XX" ] ) ) return "'OK' | null" ;
11
18
return "'OK'" ;
12
19
} ,
13
20
ping : ( types ) => {
14
21
return types . length ? "string" : "'PONG'" ;
15
22
} ,
23
+ latency : ( types ) => {
24
+ if ( matchSubcommand ( types , [ "HELP" , "LATEST" , "HISTORY" ] ) ) {
25
+ return "unknown[]" ;
26
+ }
27
+ if ( matchSubcommand ( types , "RESET" ) ) {
28
+ return "number" ;
29
+ }
30
+ if ( matchSubcommand ( types , [ "DOCTOR" , "GRAPH" ] ) ) {
31
+ return "string" ;
32
+ }
33
+ } ,
16
34
append : "number" ,
17
35
asking : "'OK'" ,
18
36
auth : "'OK'" ,
@@ -71,6 +89,14 @@ module.exports = {
71
89
hmset : "'OK'" ,
72
90
hset : "number" ,
73
91
hsetnx : "number" ,
92
+ memory : ( types ) => {
93
+ if ( matchSubcommand ( types , "MALLOC-STATS" ) ) return "string" ;
94
+ if ( matchSubcommand ( types , "PURGE" ) ) return '"OK"' ;
95
+ if ( matchSubcommand ( types , "HELP" ) ) return "unknown[]" ;
96
+ if ( matchSubcommand ( types , "STATS" ) ) return "unknown[]" ;
97
+ if ( matchSubcommand ( types , "USAGE" ) ) return "number | null" ;
98
+ if ( matchSubcommand ( types , "DOCTOR" ) ) return "string" ;
99
+ } ,
74
100
hrandfield : "string | unknown[] | null" ,
75
101
hstrlen : "number" ,
76
102
hvals : "string[]" ,
@@ -84,8 +110,12 @@ module.exports = {
84
110
lindex : "string | null" ,
85
111
linsert : "number" ,
86
112
llen : "number" ,
87
- lpop : "string" | "unknown[] | null" ,
88
- lpos : null ,
113
+ lpop : ( types ) => {
114
+ return types . includes ( "number" ) ? "string[] | null" : "string | null" ;
115
+ } ,
116
+ lpos : ( types ) => {
117
+ return hasToken ( types , "COUNT" ) ? "number[]" : "number | null" ;
118
+ } ,
89
119
lpush : "number" ,
90
120
lpushx : "number" ,
91
121
lrange : "string[]" ,
@@ -116,7 +146,9 @@ module.exports = {
116
146
reset : "'OK'" ,
117
147
restore : "'OK'" ,
118
148
role : "unknown[]" ,
119
- rpop : "string" | "unknown[] | null" ,
149
+ rpop : ( types ) => {
150
+ return types . includes ( "number" ) ? "string[] | null" : "string | null" ;
151
+ } ,
120
152
rpoplpush : "string" ,
121
153
lmove : "string" ,
122
154
rpush : "number" ,
@@ -144,7 +176,7 @@ module.exports = {
144
176
sort : "number" | "unknown[]" ,
145
177
sortRo : "unknown[]" ,
146
178
spop : ( types ) => ( types . length > 1 ? "string[]" : "string | null" ) ,
147
- srandmember : "string" | " unknown[] | null",
179
+ srandmember : "string | unknown[] | null" ,
148
180
srem : "number" ,
149
181
strlen : "number" ,
150
182
sunion : "string[]" ,
0 commit comments