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+
112module . exports = {
213 multi : "ChainableCommander" ,
314 get : "string | null" ,
415 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" ;
1118 return "'OK'" ;
1219 } ,
1320 ping : ( types ) => {
1421 return types . length ? "string" : "'PONG'" ;
1522 } ,
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+ } ,
1634 append : "number" ,
1735 asking : "'OK'" ,
1836 auth : "'OK'" ,
@@ -71,6 +89,14 @@ module.exports = {
7189 hmset : "'OK'" ,
7290 hset : "number" ,
7391 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+ } ,
74100 hrandfield : "string | unknown[] | null" ,
75101 hstrlen : "number" ,
76102 hvals : "string[]" ,
@@ -84,8 +110,12 @@ module.exports = {
84110 lindex : "string | null" ,
85111 linsert : "number" ,
86112 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+ } ,
89119 lpush : "number" ,
90120 lpushx : "number" ,
91121 lrange : "string[]" ,
@@ -116,7 +146,9 @@ module.exports = {
116146 reset : "'OK'" ,
117147 restore : "'OK'" ,
118148 role : "unknown[]" ,
119- rpop : "string" | "unknown[] | null" ,
149+ rpop : ( types ) => {
150+ return types . includes ( "number" ) ? "string[] | null" : "string | null" ;
151+ } ,
120152 rpoplpush : "string" ,
121153 lmove : "string" ,
122154 rpush : "number" ,
@@ -144,7 +176,7 @@ module.exports = {
144176 sort : "number" | "unknown[]" ,
145177 sortRo : "unknown[]" ,
146178 spop : ( types ) => ( types . length > 1 ? "string[]" : "string | null" ) ,
147- srandmember : "string" | " unknown[] | null",
179+ srandmember : "string | unknown[] | null" ,
148180 srem : "number" ,
149181 strlen : "number" ,
150182 sunion : "string[]" ,
0 commit comments