@@ -5,13 +5,22 @@ import { RedisScriptConfig, SHA1 } from '../lua-script';
5
5
import { RESP_TYPES } from './decoder' ;
6
6
import { VerbatimString } from './verbatim-string' ;
7
7
8
+ /**
9
+ * Type definition for RESP (Redis Serialization Protocol) types.
10
+ */
8
11
export type RESP_TYPES = typeof RESP_TYPES ;
9
12
13
+ /**
14
+ * Union type of all possible RESP types.
15
+ */
10
16
export type RespTypes = RESP_TYPES [ keyof RESP_TYPES ] ;
11
17
12
18
// using interface(s) to allow circular references
13
19
// type X = BlobStringReply | ArrayReply<X>;
14
20
21
+ /**
22
+ * Base interface for all RESP types.
23
+ */
15
24
export interface RespType <
16
25
RESP_TYPE extends RespTypes ,
17
26
DEFAULT ,
@@ -24,18 +33,27 @@ export interface RespType<
24
33
TYPE_MAPPING : MappedType < TYPE_MAPPING > ;
25
34
}
26
35
36
+ /**
37
+ * Represents a NULL response in Redis.
38
+ */
27
39
export interface NullReply extends RespType <
28
40
RESP_TYPES [ 'NULL' ] ,
29
41
null
30
42
> { }
31
43
44
+ /**
45
+ * Represents a boolean response in Redis.
46
+ */
32
47
export interface BooleanReply <
33
48
T extends boolean = boolean
34
49
> extends RespType <
35
50
RESP_TYPES [ 'BOOLEAN' ] ,
36
51
T
37
52
> { }
38
53
54
+ /**
55
+ * Represents a numeric response in Redis.
56
+ */
39
57
export interface NumberReply <
40
58
T extends number = number
41
59
> extends RespType <
@@ -45,6 +63,9 @@ export interface NumberReply<
45
63
number | string
46
64
> { }
47
65
66
+ /**
67
+ * Represents a big number response in Redis.
68
+ */
48
69
export interface BigNumberReply <
49
70
T extends bigint = bigint
50
71
> extends RespType <
@@ -54,6 +75,9 @@ export interface BigNumberReply<
54
75
bigint | number | string
55
76
> { }
56
77
78
+ /**
79
+ * Represents a double-precision floating point response in Redis.
80
+ */
57
81
export interface DoubleReply <
58
82
T extends number = number
59
83
> extends RespType <
@@ -63,6 +87,9 @@ export interface DoubleReply<
63
87
number | string
64
88
> { }
65
89
90
+ /**
91
+ * Represents a simple string response in Redis.
92
+ */
66
93
export interface SimpleStringReply <
67
94
T extends string = string
68
95
> extends RespType <
@@ -72,6 +99,9 @@ export interface SimpleStringReply<
72
99
string | Buffer
73
100
> { }
74
101
102
+ /**
103
+ * Represents a bulk string response in Redis.
104
+ */
75
105
export interface BlobStringReply <
76
106
T extends string = string
77
107
> extends RespType <
@@ -83,6 +113,9 @@ export interface BlobStringReply<
83
113
toString ( ) : string
84
114
}
85
115
116
+ /**
117
+ * Represents a verbatim string response in Redis.
118
+ */
86
119
export interface VerbatimStringReply <
87
120
T extends string = string
88
121
> extends RespType <
@@ -92,39 +125,57 @@ export interface VerbatimStringReply<
92
125
string | Buffer | VerbatimString
93
126
> { }
94
127
128
+ /**
129
+ * Represents a simple error response in Redis.
130
+ */
95
131
export interface SimpleErrorReply extends RespType <
96
132
RESP_TYPES [ 'SIMPLE_ERROR' ] ,
97
133
SimpleError ,
98
134
Buffer
99
135
> { }
100
136
137
+ /**
138
+ * Represents a bulk error response in Redis.
139
+ */
101
140
export interface BlobErrorReply extends RespType <
102
141
RESP_TYPES [ 'BLOB_ERROR' ] ,
103
142
BlobError ,
104
143
Buffer
105
144
> { }
106
145
146
+ /**
147
+ * Represents an array response in Redis.
148
+ */
107
149
export interface ArrayReply < T > extends RespType <
108
150
RESP_TYPES [ 'ARRAY' ] ,
109
151
Array < T > ,
110
152
never ,
111
153
Array < any >
112
154
> { }
113
155
156
+ /**
157
+ * Represents a tuple response in Redis.
158
+ */
114
159
export interface TuplesReply < T extends [ ...Array < unknown > ] > extends RespType <
115
160
RESP_TYPES [ 'ARRAY' ] ,
116
161
T ,
117
162
never ,
118
163
Array < any >
119
164
> { }
120
165
166
+ /**
167
+ * Represents a set response in Redis.
168
+ */
121
169
export interface SetReply < T > extends RespType <
122
170
RESP_TYPES [ 'SET' ] ,
123
171
Array < T > ,
124
172
Set < T > ,
125
173
Array < any > | Set < any >
126
174
> { }
127
175
176
+ /**
177
+ * Represents a map response in Redis.
178
+ */
128
179
export interface MapReply < K , V > extends RespType <
129
180
RESP_TYPES [ 'MAP' ] ,
130
181
{ [ key : string ] : V } ,
@@ -222,8 +273,14 @@ export type ReplyWithTypeMapping<
222
273
223
274
export type TransformReply = ( this : void , reply : any , preserve ?: any , typeMapping ?: TypeMapping ) => any ; // TODO;
224
275
276
+ /**
277
+ * Type definition for Redis command arguments.
278
+ */
225
279
export type RedisArgument = string | Buffer ;
226
280
281
+ /**
282
+ * Type definition for Redis command arguments with optional preserve flag.
283
+ */
227
284
export type CommandArguments = Array < RedisArgument > & { preserve ?: unknown } ;
228
285
229
286
// export const REQUEST_POLICIES = {
@@ -273,6 +330,9 @@ export type CommandArguments = Array<RedisArgument> & { preserve?: unknown };
273
330
// response?: ResponsePolicies | null;
274
331
// };
275
332
333
+ /**
334
+ * Interface defining a Redis command.
335
+ */
276
336
export type Command = {
277
337
CACHEABLE ?: boolean ;
278
338
IS_READ_ONLY ?: boolean ;
@@ -289,21 +349,41 @@ export type Command = {
289
349
unstableResp3 ?: boolean ;
290
350
} ;
291
351
352
+ /**
353
+ * Type definition for Redis commands.
354
+ */
292
355
export type RedisCommands = Record < string , Command > ;
293
356
357
+ /**
358
+ * Type definition for Redis modules.
359
+ */
294
360
export type RedisModules = Record < string , RedisCommands > ;
295
361
362
+ /**
363
+ * Interface extending Command for Redis functions.
364
+ */
296
365
export interface RedisFunction extends Command {
297
366
NUMBER_OF_KEYS ?: number ;
298
367
}
299
368
369
+ /**
370
+ * Type definition for Redis functions.
371
+ */
300
372
export type RedisFunctions = Record < string , Record < string , RedisFunction > > ;
301
373
374
+ /**
375
+ * Type definition for Redis scripts.
376
+ */
302
377
export type RedisScript = RedisScriptConfig & SHA1 ;
303
378
379
+ /**
380
+ * Type definition for Redis scripts collection.
381
+ */
304
382
export type RedisScripts = Record < string , RedisScript > ;
305
383
306
- // TODO: move to Commander?
384
+ /**
385
+ * Interface for Redis commander configuration.
386
+ */
307
387
export interface CommanderConfig <
308
388
M extends RedisModules ,
309
389
F extends RedisFunctions ,
@@ -314,11 +394,11 @@ export interface CommanderConfig<
314
394
functions ?: F ;
315
395
scripts ?: S ;
316
396
/**
317
- * TODO
397
+ * The RESP protocol version to use (2 or 3)
318
398
*/
319
399
RESP ?: RESP ;
320
400
/**
321
- * TODO
401
+ * Whether to use unstable RESP3 features
322
402
*/
323
403
unstableResp3 ?: boolean ;
324
404
}
@@ -350,8 +430,14 @@ export type Resp2Reply<RESP3REPLY> = (
350
430
RESP3REPLY
351
431
) ;
352
432
433
+ /**
434
+ * Type definition for RESP protocol versions (2 or 3).
435
+ */
353
436
export type RespVersions = 2 | 3 ;
354
437
438
+ /**
439
+ * Type definition for command replies.
440
+ */
355
441
export type CommandReply <
356
442
COMMAND extends Command ,
357
443
RESP extends RespVersions
@@ -364,6 +450,9 @@ export type CommandReply<
364
450
ReplyUnion
365
451
) ;
366
452
453
+ /**
454
+ * Type definition for command signatures.
455
+ */
367
456
export type CommandSignature <
368
457
COMMAND extends Command ,
369
458
RESP extends RespVersions ,
0 commit comments