11import  {  RedisCommandArguments  }  from  '.' ; 
22
3- type  HSETObject  =  Record < string  |  number ,   string   |   number > ; 
3+ type  Types  =  string  |  number   |   Buffer ; 
44
5- type  HSETMap  =  Map < string  |  number ,  string   |   number > ; 
5+ type  HSETObject  =  Record < string  |  number ,  Types > ; 
66
7- type  HSETTuples  =  Array < [ string ,  string ] >  |  Array < string > ; 
7+ type  HSETMap  =  Map < Types ,  Types > ; 
8+ 
9+ type  HSETTuples  =  Array < [ Types ,  Types ] >  |  Array < Types > ; 
810
911export  const  FIRST_KEY_INDEX  =  1 ; 
1012
11- type  GenericArguments  =  [ key : string ] ; 
13+ type  GenericArguments  =  [ key : string   |   Buffer ] ; 
1214
13- type  SingleFieldArguments  =  [ ...generic : GenericArguments ,  field : string ,  value : string ] ; 
15+ type  SingleFieldArguments  =  [ ...generic : GenericArguments ,  field : Types ,  value : Types ] ; 
1416
1517type  MultipleFieldsArguments  =  [ ...generic : GenericArguments ,  value : HSETObject  |  HSETMap  |  HSETTuples ] ; 
1618
1719export  function  transformArguments ( ...[  key ,  value ,  fieldValue  ] : SingleFieldArguments  |  MultipleFieldsArguments ) : RedisCommandArguments  { 
18-     const  args  =  [ 'HSET' ,  key ] ; 
20+     const  args :  RedisCommandArguments  =  [ 'HSET' ,  key ] ; 
1921
20-     if  ( typeof  value  ===  'string' )  { 
21-         args . push ( value ,  fieldValue ! ) ; 
22+     if  ( typeof  value  ===  'string'  ||  typeof  value  ===  'number'  ||  Buffer . isBuffer ( value ) )  { 
23+         pushValue ( args ,  value ) ; 
24+         pushValue ( args ,  fieldValue ! ) ; 
2225    }  else  if  ( value  instanceof  Map )  { 
2326        pushMap ( args ,  value ) ; 
2427    }  else  if  ( Array . isArray ( value ) )  { 
@@ -30,20 +33,36 @@ export function transformArguments(...[ key, value, fieldValue ]: SingleFieldArg
3033    return  args ; 
3134} 
3235
33- function  pushMap ( args : Array < string > ,  map : HSETMap ) : void { 
36+ function  pushMap ( args : RedisCommandArguments ,  map : HSETMap ) : void { 
3437    for  ( const  [ key ,  value ]  of  map . entries ( ) )  { 
35-         args . push ( key . toString ( ) ,  value . toString ( ) ) ; 
38+         pushValue ( args ,  key ) ; 
39+         pushValue ( args ,  value ) ; 
3640    } 
3741} 
3842
39- function  pushTuples ( args : Array < string > ,  tuples : HSETTuples ) : void { 
40-     args . push ( ...tuples . flat ( ) ) ; 
43+ function  pushTuples ( args : RedisCommandArguments ,  tuples : HSETTuples ) : void { 
44+     for  ( const  tuple  of  tuples )  { 
45+         if  ( Array . isArray ( tuple ) )  { 
46+             pushTuples ( args ,  tuple ) ; 
47+             continue ; 
48+         } 
49+ 
50+         pushValue ( args ,  tuple ) ; 
51+     } 
4152} 
4253
43- function  pushObject ( args : Array < string > ,  object : HSETObject ) : void { 
54+ function  pushObject ( args : RedisCommandArguments ,  object : HSETObject ) : void { 
4455    for  ( const  key  of  Object . keys ( object ) )  { 
4556        args . push ( key . toString ( ) ,  object [ key ] . toString ( ) ) ; 
4657    } 
4758} 
4859
60+ function  pushValue ( args : RedisCommandArguments ,  value : Types ) : void { 
61+     args . push ( 
62+         typeof  value  ===  'number'  ?
63+             value . toString ( )  :
64+             value 
65+     ) ; 
66+ } 
67+ 
4968export  declare  function  transformReply ( ) : number ; 
0 commit comments