From f12bf06205411dcc29e3484398ff0a979bc8e907 Mon Sep 17 00:00:00 2001 From: Nikolay Karadzhov Date: Fri, 22 Aug 2025 00:46:33 +0300 Subject: [PATCH] fix(ts): use all commands in cluster type 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 --- packages/client/lib/client/index.ts | 10 +++--- packages/client/lib/cluster/index.ts | 48 ++-------------------------- 2 files changed, 8 insertions(+), 50 deletions(-) diff --git a/packages/client/lib/client/index.ts b/packages/client/lib/client/index.ts index 1a27ea8898..57b1231670 100644 --- a/packages/client/lib/client/index.ts +++ b/packages/client/lib/client/index.ts @@ -146,14 +146,14 @@ export interface RedisClientOptions< clientInfoTag?: string; } -type WithCommands< +export type WithCommands< RESP extends RespVersions, TYPE_MAPPING extends TypeMapping > = { [P in keyof typeof COMMANDS]: CommandSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING>; }; -type WithModules< +export type WithModules< M extends RedisModules, RESP extends RespVersions, TYPE_MAPPING extends TypeMapping @@ -163,7 +163,7 @@ type WithModules< }; }; -type WithFunctions< +export type WithFunctions< F extends RedisFunctions, RESP extends RespVersions, TYPE_MAPPING extends TypeMapping @@ -173,7 +173,7 @@ type WithFunctions< }; }; -type WithScripts< +export type WithScripts< S extends RedisScripts, RESP extends RespVersions, TYPE_MAPPING extends TypeMapping @@ -498,7 +498,7 @@ export default class RedisClient< if (options?.url) { const parsedOptions = RedisClient.parseOptions(options); - + if (parsedOptions?.database) { this._self.#selectedDB = parsedOptions.database; } diff --git a/packages/client/lib/cluster/index.ts b/packages/client/lib/cluster/index.ts index 6d26ac98c9..16454e66fb 100644 --- a/packages/client/lib/cluster/index.ts +++ b/packages/client/lib/cluster/index.ts @@ -1,6 +1,6 @@ import { RedisClientOptions, RedisClientType } from '../client'; import { CommandOptions } from '../client/commands-queue'; -import { Command, CommandArguments, CommanderConfig, CommandSignature, /*CommandPolicies, CommandWithPoliciesSignature,*/ TypeMapping, RedisArgument, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts, ReplyUnion, RespVersions } from '../RESP/types'; +import { Command, CommandArguments, CommanderConfig, TypeMapping, RedisArgument, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts, ReplyUnion, RespVersions } from '../RESP/types'; import COMMANDS from '../commands'; import { EventEmitter } from 'node:events'; import { attachConfig, functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander'; @@ -13,6 +13,8 @@ import { ClientSideCacheConfig, PooledClientSideCacheProvider } from '../client/ import { BasicCommandParser } from '../client/parser'; import { ASKING_CMD } from '../commands/ASKING'; import SingleEntryCache from '../single-entry-cache' +import { WithCommands, WithFunctions, WithModules, WithScripts } from '../client'; + interface ClusterCommander< M extends RedisModules, F extends RedisFunctions, @@ -103,50 +105,6 @@ export interface RedisClusterOptions< clientSideCache?: PooledClientSideCacheProvider | ClientSideCacheConfig; } -// remove once request & response policies are ready -type ClusterCommand< - NAME extends PropertyKey, - COMMAND extends Command -> = COMMAND['NOT_KEYED_COMMAND'] extends true ? ( - COMMAND['IS_FORWARD_COMMAND'] extends true ? NAME : never -) : NAME; - -// CommandWithPoliciesSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING, POLICIES> -type WithCommands< - RESP extends RespVersions, - TYPE_MAPPING extends TypeMapping -> = { - [P in keyof typeof COMMANDS as ClusterCommand]: CommandSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING>; -}; - -type WithModules< - M extends RedisModules, - RESP extends RespVersions, - TYPE_MAPPING extends TypeMapping -> = { - [P in keyof M]: { - [C in keyof M[P] as ClusterCommand]: CommandSignature; - }; -}; - -type WithFunctions< - F extends RedisFunctions, - RESP extends RespVersions, - TYPE_MAPPING extends TypeMapping -> = { - [L in keyof F]: { - [C in keyof F[L] as ClusterCommand]: CommandSignature; - }; -}; - -type WithScripts< - S extends RedisScripts, - RESP extends RespVersions, - TYPE_MAPPING extends TypeMapping -> = { - [P in keyof S as ClusterCommand]: CommandSignature; -}; - export type RedisClusterType< M extends RedisModules = {}, F extends RedisFunctions = {},