Skip to content

Commit f4771b4

Browse files
DOC-5043 sample of Cursor AI-generated doc comments
1 parent 924dafa commit f4771b4

File tree

5 files changed

+306
-17
lines changed

5 files changed

+306
-17
lines changed

packages/client/lib/RESP/types.ts

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ import { RedisScriptConfig, SHA1 } from '../lua-script';
55
import { RESP_TYPES } from './decoder';
66
import { VerbatimString } from './verbatim-string';
77

8+
/**
9+
* Type definition for RESP (Redis Serialization Protocol) types.
10+
*/
811
export type RESP_TYPES = typeof RESP_TYPES;
912

13+
/**
14+
* Union type of all possible RESP types.
15+
*/
1016
export type RespTypes = RESP_TYPES[keyof RESP_TYPES];
1117

1218
// using interface(s) to allow circular references
1319
// type X = BlobStringReply | ArrayReply<X>;
1420

21+
/**
22+
* Base interface for all RESP types.
23+
*/
1524
export interface RespType<
1625
RESP_TYPE extends RespTypes,
1726
DEFAULT,
@@ -24,18 +33,27 @@ export interface RespType<
2433
TYPE_MAPPING: MappedType<TYPE_MAPPING>;
2534
}
2635

36+
/**
37+
* Represents a NULL response in Redis.
38+
*/
2739
export interface NullReply extends RespType<
2840
RESP_TYPES['NULL'],
2941
null
3042
> {}
3143

44+
/**
45+
* Represents a boolean response in Redis.
46+
*/
3247
export interface BooleanReply<
3348
T extends boolean = boolean
3449
> extends RespType<
3550
RESP_TYPES['BOOLEAN'],
3651
T
3752
> {}
3853

54+
/**
55+
* Represents a numeric response in Redis.
56+
*/
3957
export interface NumberReply<
4058
T extends number = number
4159
> extends RespType<
@@ -45,6 +63,9 @@ export interface NumberReply<
4563
number | string
4664
> {}
4765

66+
/**
67+
* Represents a big number response in Redis.
68+
*/
4869
export interface BigNumberReply<
4970
T extends bigint = bigint
5071
> extends RespType<
@@ -54,6 +75,9 @@ export interface BigNumberReply<
5475
bigint | number | string
5576
> {}
5677

78+
/**
79+
* Represents a double-precision floating point response in Redis.
80+
*/
5781
export interface DoubleReply<
5882
T extends number = number
5983
> extends RespType<
@@ -63,6 +87,9 @@ export interface DoubleReply<
6387
number | string
6488
> {}
6589

90+
/**
91+
* Represents a simple string response in Redis.
92+
*/
6693
export interface SimpleStringReply<
6794
T extends string = string
6895
> extends RespType<
@@ -72,6 +99,9 @@ export interface SimpleStringReply<
7299
string | Buffer
73100
> {}
74101

102+
/**
103+
* Represents a bulk string response in Redis.
104+
*/
75105
export interface BlobStringReply<
76106
T extends string = string
77107
> extends RespType<
@@ -83,6 +113,9 @@ export interface BlobStringReply<
83113
toString(): string
84114
}
85115

116+
/**
117+
* Represents a verbatim string response in Redis.
118+
*/
86119
export interface VerbatimStringReply<
87120
T extends string = string
88121
> extends RespType<
@@ -92,39 +125,57 @@ export interface VerbatimStringReply<
92125
string | Buffer | VerbatimString
93126
> {}
94127

128+
/**
129+
* Represents a simple error response in Redis.
130+
*/
95131
export interface SimpleErrorReply extends RespType<
96132
RESP_TYPES['SIMPLE_ERROR'],
97133
SimpleError,
98134
Buffer
99135
> {}
100136

137+
/**
138+
* Represents a bulk error response in Redis.
139+
*/
101140
export interface BlobErrorReply extends RespType<
102141
RESP_TYPES['BLOB_ERROR'],
103142
BlobError,
104143
Buffer
105144
> {}
106145

146+
/**
147+
* Represents an array response in Redis.
148+
*/
107149
export interface ArrayReply<T> extends RespType<
108150
RESP_TYPES['ARRAY'],
109151
Array<T>,
110152
never,
111153
Array<any>
112154
> {}
113155

156+
/**
157+
* Represents a tuple response in Redis.
158+
*/
114159
export interface TuplesReply<T extends [...Array<unknown>]> extends RespType<
115160
RESP_TYPES['ARRAY'],
116161
T,
117162
never,
118163
Array<any>
119164
> {}
120165

166+
/**
167+
* Represents a set response in Redis.
168+
*/
121169
export interface SetReply<T> extends RespType<
122170
RESP_TYPES['SET'],
123171
Array<T>,
124172
Set<T>,
125173
Array<any> | Set<any>
126174
> {}
127175

176+
/**
177+
* Represents a map response in Redis.
178+
*/
128179
export interface MapReply<K, V> extends RespType<
129180
RESP_TYPES['MAP'],
130181
{ [key: string]: V },
@@ -222,8 +273,14 @@ export type ReplyWithTypeMapping<
222273

223274
export type TransformReply = (this: void, reply: any, preserve?: any, typeMapping?: TypeMapping) => any; // TODO;
224275

276+
/**
277+
* Type definition for Redis command arguments.
278+
*/
225279
export type RedisArgument = string | Buffer;
226280

281+
/**
282+
* Type definition for Redis command arguments with optional preserve flag.
283+
*/
227284
export type CommandArguments = Array<RedisArgument> & { preserve?: unknown };
228285

229286
// export const REQUEST_POLICIES = {
@@ -273,6 +330,9 @@ export type CommandArguments = Array<RedisArgument> & { preserve?: unknown };
273330
// response?: ResponsePolicies | null;
274331
// };
275332

333+
/**
334+
* Interface defining a Redis command.
335+
*/
276336
export type Command = {
277337
CACHEABLE?: boolean;
278338
IS_READ_ONLY?: boolean;
@@ -289,21 +349,41 @@ export type Command = {
289349
unstableResp3?: boolean;
290350
};
291351

352+
/**
353+
* Type definition for Redis commands.
354+
*/
292355
export type RedisCommands = Record<string, Command>;
293356

357+
/**
358+
* Type definition for Redis modules.
359+
*/
294360
export type RedisModules = Record<string, RedisCommands>;
295361

362+
/**
363+
* Interface extending Command for Redis functions.
364+
*/
296365
export interface RedisFunction extends Command {
297366
NUMBER_OF_KEYS?: number;
298367
}
299368

369+
/**
370+
* Type definition for Redis functions.
371+
*/
300372
export type RedisFunctions = Record<string, Record<string, RedisFunction>>;
301373

374+
/**
375+
* Type definition for Redis scripts.
376+
*/
302377
export type RedisScript = RedisScriptConfig & SHA1;
303378

379+
/**
380+
* Type definition for Redis scripts collection.
381+
*/
304382
export type RedisScripts = Record<string, RedisScript>;
305383

306-
// TODO: move to Commander?
384+
/**
385+
* Interface for Redis commander configuration.
386+
*/
307387
export interface CommanderConfig<
308388
M extends RedisModules,
309389
F extends RedisFunctions,
@@ -314,11 +394,11 @@ export interface CommanderConfig<
314394
functions?: F;
315395
scripts?: S;
316396
/**
317-
* TODO
397+
* The RESP protocol version to use (2 or 3)
318398
*/
319399
RESP?: RESP;
320400
/**
321-
* TODO
401+
* Whether to use unstable RESP3 features
322402
*/
323403
unstableResp3?: boolean;
324404
}
@@ -350,8 +430,14 @@ export type Resp2Reply<RESP3REPLY> = (
350430
RESP3REPLY
351431
);
352432

433+
/**
434+
* Type definition for RESP protocol versions (2 or 3).
435+
*/
353436
export type RespVersions = 2 | 3;
354437

438+
/**
439+
* Type definition for command replies.
440+
*/
355441
export type CommandReply<
356442
COMMAND extends Command,
357443
RESP extends RespVersions
@@ -364,6 +450,9 @@ export type CommandReply<
364450
ReplyUnion
365451
);
366452

453+
/**
454+
* Type definition for command signatures.
455+
*/
367456
export type CommandSignature<
368457
COMMAND extends Command,
369458
RESP extends RespVersions,

packages/client/lib/client/index.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import { RedisPoolOptions, RedisClientPool } from './pool';
1818
import { RedisVariadicArgument, parseArgs, pushVariadicArguments } from '../commands/generic-transformers';
1919
import { BasicCommandParser, CommandParser } from './parser';
2020

21+
/**
22+
* Interface defining options for creating a Redis client.
23+
*/
2124
export interface RedisClientOptions<
2225
M extends RedisModules = RedisModules,
2326
F extends RedisFunctions = RedisFunctions,
@@ -82,13 +85,24 @@ export interface RedisClientOptions<
8285
commandOptions?: CommandOptions<TYPE_MAPPING>;
8386
}
8487

88+
/**
89+
* Type mapping Redis commands to their signatures.
90+
* @template RESP - RESP protocol version
91+
* @template TYPE_MAPPING - Type mapping for Redis responses
92+
*/
8593
type WithCommands<
8694
RESP extends RespVersions,
8795
TYPE_MAPPING extends TypeMapping
8896
> = {
8997
[P in keyof typeof COMMANDS]: CommandSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING>;
9098
};
9199

100+
/**
101+
* Type mapping Redis modules to their command signatures.
102+
* @template M - Redis modules type
103+
* @template RESP - RESP protocol version
104+
* @template TYPE_MAPPING - Type mapping for Redis responses
105+
*/
92106
type WithModules<
93107
M extends RedisModules,
94108
RESP extends RespVersions,
@@ -99,6 +113,12 @@ type WithModules<
99113
};
100114
};
101115

116+
/**
117+
* Type mapping Redis functions to their command signatures.
118+
* @template F - Redis functions type
119+
* @template RESP - RESP protocol version
120+
* @template TYPE_MAPPING - Type mapping for Redis responses
121+
*/
102122
type WithFunctions<
103123
F extends RedisFunctions,
104124
RESP extends RespVersions,
@@ -109,6 +129,12 @@ type WithFunctions<
109129
};
110130
};
111131

132+
/**
133+
* Type mapping Redis scripts to their command signatures.
134+
* @template S - Redis scripts type
135+
* @template RESP - RESP protocol version
136+
* @template TYPE_MAPPING - Type mapping for Redis responses
137+
*/
112138
type WithScripts<
113139
S extends RedisScripts,
114140
RESP extends RespVersions,
@@ -117,6 +143,9 @@ type WithScripts<
117143
[P in keyof S]: CommandSignature<S[P], RESP, TYPE_MAPPING>;
118144
};
119145

146+
/**
147+
* Type combining all Redis client extensions (commands, modules, functions, scripts).
148+
*/
120149
export type RedisClientExtensions<
121150
M extends RedisModules = {},
122151
F extends RedisFunctions = {},
@@ -130,6 +159,9 @@ export type RedisClientExtensions<
130159
WithScripts<S, RESP, TYPE_MAPPING>
131160
);
132161

162+
/**
163+
* Type definition for a Redis client with all its extensions.
164+
*/
133165
export type RedisClientType<
134166
M extends RedisModules = {},
135167
F extends RedisFunctions = {},
@@ -141,16 +173,31 @@ export type RedisClientType<
141173
RedisClientExtensions<M, F, S, RESP, TYPE_MAPPING>
142174
);
143175

176+
/**
177+
* Type for a proxy client that can handle any Redis modules, functions, scripts, and RESP versions.
178+
*/
144179
type ProxyClient = RedisClient<any, any, any, any, any>;
145180

181+
/**
182+
* Type for a namespace proxy client that contains a reference to the underlying proxy client.
183+
*/
146184
type NamespaceProxyClient = { _self: ProxyClient };
147185

186+
/**
187+
* Interface defining options for scan iterators.
188+
*/
148189
interface ScanIteratorOptions {
149190
cursor?: RedisArgument;
150191
}
151192

193+
/**
194+
* Type definition for a monitor callback function.
195+
*/
152196
export type MonitorCallback<TYPE_MAPPING extends TypeMapping = TypeMapping> = (reply: ReplyWithTypeMapping<SimpleStringReply, TYPE_MAPPING>) => unknown;
153197

198+
/**
199+
* The main Redis client class that handles connections, commands, and pub/sub functionality.
200+
*/
154201
export default class RedisClient<
155202
M extends RedisModules,
156203
F extends RedisFunctions,

0 commit comments

Comments
 (0)