Skip to content

Commit 672246d

Browse files
authored
fix(ts): use all commands in cluster type (#3065)
RedisClusterType was using some type restrictions to hide some commands based on its properties. In reality, all commands should be exposed to user ( as in v4 ). fixes #3064
1 parent 7b56e9a commit 672246d

File tree

2 files changed

+8
-50
lines changed

2 files changed

+8
-50
lines changed

packages/client/lib/client/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ export interface RedisClientOptions<
146146
clientInfoTag?: string;
147147
}
148148

149-
type WithCommands<
149+
export type WithCommands<
150150
RESP extends RespVersions,
151151
TYPE_MAPPING extends TypeMapping
152152
> = {
153153
[P in keyof typeof COMMANDS]: CommandSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING>;
154154
};
155155

156-
type WithModules<
156+
export type WithModules<
157157
M extends RedisModules,
158158
RESP extends RespVersions,
159159
TYPE_MAPPING extends TypeMapping
@@ -163,7 +163,7 @@ type WithModules<
163163
};
164164
};
165165

166-
type WithFunctions<
166+
export type WithFunctions<
167167
F extends RedisFunctions,
168168
RESP extends RespVersions,
169169
TYPE_MAPPING extends TypeMapping
@@ -173,7 +173,7 @@ type WithFunctions<
173173
};
174174
};
175175

176-
type WithScripts<
176+
export type WithScripts<
177177
S extends RedisScripts,
178178
RESP extends RespVersions,
179179
TYPE_MAPPING extends TypeMapping
@@ -498,7 +498,7 @@ export default class RedisClient<
498498

499499
if (options?.url) {
500500
const parsedOptions = RedisClient.parseOptions(options);
501-
501+
502502
if (parsedOptions?.database) {
503503
this._self.#selectedDB = parsedOptions.database;
504504
}

packages/client/lib/cluster/index.ts

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RedisClientOptions, RedisClientType } from '../client';
22
import { CommandOptions } from '../client/commands-queue';
3-
import { Command, CommandArguments, CommanderConfig, CommandSignature, /*CommandPolicies, CommandWithPoliciesSignature,*/ TypeMapping, RedisArgument, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts, ReplyUnion, RespVersions } from '../RESP/types';
3+
import { Command, CommandArguments, CommanderConfig, TypeMapping, RedisArgument, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts, ReplyUnion, RespVersions } from '../RESP/types';
44
import COMMANDS from '../commands';
55
import { EventEmitter } from 'node:events';
66
import { attachConfig, functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander';
@@ -13,6 +13,8 @@ import { ClientSideCacheConfig, PooledClientSideCacheProvider } from '../client/
1313
import { BasicCommandParser } from '../client/parser';
1414
import { ASKING_CMD } from '../commands/ASKING';
1515
import SingleEntryCache from '../single-entry-cache'
16+
import { WithCommands, WithFunctions, WithModules, WithScripts } from '../client';
17+
1618
interface ClusterCommander<
1719
M extends RedisModules,
1820
F extends RedisFunctions,
@@ -103,50 +105,6 @@ export interface RedisClusterOptions<
103105
clientSideCache?: PooledClientSideCacheProvider | ClientSideCacheConfig;
104106
}
105107

106-
// remove once request & response policies are ready
107-
type ClusterCommand<
108-
NAME extends PropertyKey,
109-
COMMAND extends Command
110-
> = COMMAND['NOT_KEYED_COMMAND'] extends true ? (
111-
COMMAND['IS_FORWARD_COMMAND'] extends true ? NAME : never
112-
) : NAME;
113-
114-
// CommandWithPoliciesSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING, POLICIES>
115-
type WithCommands<
116-
RESP extends RespVersions,
117-
TYPE_MAPPING extends TypeMapping
118-
> = {
119-
[P in keyof typeof COMMANDS as ClusterCommand<P, (typeof COMMANDS)[P]>]: CommandSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING>;
120-
};
121-
122-
type WithModules<
123-
M extends RedisModules,
124-
RESP extends RespVersions,
125-
TYPE_MAPPING extends TypeMapping
126-
> = {
127-
[P in keyof M]: {
128-
[C in keyof M[P] as ClusterCommand<C, M[P][C]>]: CommandSignature<M[P][C], RESP, TYPE_MAPPING>;
129-
};
130-
};
131-
132-
type WithFunctions<
133-
F extends RedisFunctions,
134-
RESP extends RespVersions,
135-
TYPE_MAPPING extends TypeMapping
136-
> = {
137-
[L in keyof F]: {
138-
[C in keyof F[L] as ClusterCommand<C, F[L][C]>]: CommandSignature<F[L][C], RESP, TYPE_MAPPING>;
139-
};
140-
};
141-
142-
type WithScripts<
143-
S extends RedisScripts,
144-
RESP extends RespVersions,
145-
TYPE_MAPPING extends TypeMapping
146-
> = {
147-
[P in keyof S as ClusterCommand<P, S[P]>]: CommandSignature<S[P], RESP, TYPE_MAPPING>;
148-
};
149-
150108
export type RedisClusterType<
151109
M extends RedisModules = {},
152110
F extends RedisFunctions = {},

0 commit comments

Comments
 (0)