diff --git a/packages/client/lib/RESP/types.ts b/packages/client/lib/RESP/types.ts index 349e11db9c5..af72b1ee228 100644 --- a/packages/client/lib/RESP/types.ts +++ b/packages/client/lib/RESP/types.ts @@ -132,24 +132,14 @@ type MapKeyValue = [key: BlobStringReply, value: unknown]; type MapTuples = Array; -export interface TuplesToMapReply extends RespType< - RESP_TYPES['MAP'], - { - [P in T[number] as P[0] extends BlobStringReply ? S : never]: P[1]; - }, - Map | FlattenTuples -> {} - -type SimpleMapKeyValue = [key: SimpleStringReply, value: unknown]; +type ExtractMapKey = T extends BlobStringReply ? S : never; -type SimpleMapTuples = Array; - -export interface SimpleTuplesToMapReply extends RespType< +export interface TuplesToMapReply extends RespType< RESP_TYPES['MAP'], { - [P in T[number] as P[0] extends SimpleStringReply ? S : never]: P[1]; + [P in T[number] as ExtractMapKey]: P[1]; }, - Map | FlattenTuples + Map, T[number][1]> | FlattenTuples > {} type FlattenTuples = ( diff --git a/packages/client/lib/client/index.ts b/packages/client/lib/client/index.ts index b7d5ab79f28..e3aaff0a9bf 100644 --- a/packages/client/lib/client/index.ts +++ b/packages/client/lib/client/index.ts @@ -154,13 +154,7 @@ export default class RedisClient< return async function (this: ProxyClient, ...args: Array) { const redisArgs = command.transformArguments(...args); - let commandOptions: typeof this._commandOptions; - if (this._commandOptions) { - commandOptions = {...this._commandOptions}; - if (command.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._commandOptions && command.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined; const reply = await this.sendCommand(redisArgs, commandOptions); return transformReply ? @@ -174,13 +168,7 @@ export default class RedisClient< return async function (this: NamespaceProxyClient, ...args: Array) { const redisArgs = command.transformArguments(...args); - let commandOptions: typeof this._self._commandOptions; - if (this._self._commandOptions) { - commandOptions = {...this._self._commandOptions}; - if (command.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._self._commandOptions && command.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined; const reply = await this._self.sendCommand(redisArgs, commandOptions); return transformReply ? @@ -195,13 +183,7 @@ export default class RedisClient< return async function (this: NamespaceProxyClient, ...args: Array) { const fnArgs = fn.transformArguments(...args); - let commandOptions: typeof this._self._commandOptions; - if (this._self._commandOptions) { - commandOptions = {...this._self._commandOptions}; - if (fn.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._self._commandOptions && fn.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined; const reply = await this._self.sendCommand( prefix.concat(fnArgs), @@ -220,13 +202,7 @@ export default class RedisClient< const scriptArgs = script.transformArguments(...args); const redisArgs = prefix.concat(scriptArgs) - let commandOptions: typeof this._commandOptions; - if (this._commandOptions) { - commandOptions = {...this._commandOptions}; - if (script.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._commandOptions && script.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined; const reply = await this.executeScript(script, redisArgs, commandOptions); return transformReply ? diff --git a/packages/client/lib/client/pool.ts b/packages/client/lib/client/pool.ts index 1abd4c8edcf..7f727d8e48c 100644 --- a/packages/client/lib/client/pool.ts +++ b/packages/client/lib/client/pool.ts @@ -67,13 +67,7 @@ export class RedisClientPool< return async function (this: ProxyPool, ...args: Array) { const redisArgs = command.transformArguments(...args); - let commandOptions: typeof this._commandOptions; - if (this._commandOptions) { - commandOptions = {...this._commandOptions}; - if (command.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._commandOptions && command.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined; const reply = await this.sendCommand(redisArgs, commandOptions); return transformReply ? @@ -87,13 +81,7 @@ export class RedisClientPool< return async function (this: NamespaceProxyPool, ...args: Array) { const redisArgs = command.transformArguments(...args); - let commandOptions: typeof this._self._commandOptions; - if (this._self._commandOptions) { - commandOptions = {...this._self._commandOptions}; - if (command.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._self._commandOptions && command.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined; const reply = await this._self.sendCommand(redisArgs, commandOptions); return transformReply ? @@ -108,13 +96,7 @@ export class RedisClientPool< return async function (this: NamespaceProxyPool, ...args: Array) { const fnArgs = fn.transformArguments(...args); - let commandOptions: typeof this._self._commandOptions; - if (this._self._commandOptions) { - commandOptions = {...this._self._commandOptions}; - if (fn.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._self._commandOptions && fn.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined; const reply = await this._self.sendCommand( prefix.concat(fnArgs), @@ -133,13 +115,7 @@ export class RedisClientPool< const scriptArgs = script.transformArguments(...args); const redisArgs = prefix.concat(scriptArgs); - let commandOptions: typeof this._commandOptions; - if (this._commandOptions) { - commandOptions = {...this._commandOptions}; - if (script.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._commandOptions && script.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined; const reply = await this.executeScript(script, redisArgs, commandOptions); return transformReply ? diff --git a/packages/client/lib/cluster/index.ts b/packages/client/lib/cluster/index.ts index 20f55fe58c8..88abe9192bd 100644 --- a/packages/client/lib/cluster/index.ts +++ b/packages/client/lib/cluster/index.ts @@ -181,13 +181,7 @@ export default class RedisCluster< redisArgs ); - let commandOptions: typeof this._commandOptions; - if (this._commandOptions) { - commandOptions = {...this._commandOptions}; - if (command.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._commandOptions && command.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined; const reply = await this.sendCommand( firstKey, @@ -213,13 +207,7 @@ export default class RedisCluster< redisArgs ); - let commandOptions: typeof this._self._commandOptions; - if (this._self._commandOptions) { - commandOptions = {...this._self._commandOptions}; - if (command.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._self._commandOptions && command.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined; const reply = await this._self.sendCommand( firstKey, @@ -247,13 +235,7 @@ export default class RedisCluster< ); const redisArgs = prefix.concat(fnArgs); - let commandOptions: typeof this._self._commandOptions; - if (this._self._commandOptions) { - commandOptions = {...this._self._commandOptions}; - if (fn.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._self._commandOptions && fn.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined; const reply = await this._self.sendCommand( firstKey, @@ -281,14 +263,8 @@ export default class RedisCluster< ); const redisArgs = prefix.concat(scriptArgs); - let commandOptions: typeof this._commandOptions; - if (this._commandOptions) { - commandOptions = {...this._commandOptions}; - if (script.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } - + const commandOptions = this._commandOptions && script.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined; + const reply = await this.executeScript( script, firstKey, diff --git a/packages/client/lib/sentinel/utils.ts b/packages/client/lib/sentinel/utils.ts index 84af98bd79e..9b91984683f 100644 --- a/packages/client/lib/sentinel/utils.ts +++ b/packages/client/lib/sentinel/utils.ts @@ -40,13 +40,7 @@ export function createCommand(com return async function (this: T, ...args: Array) { const redisArgs = command.transformArguments(...args); - let commandOptions: typeof this._self.commandOptions; - if (this._self.commandOptions) { - commandOptions = {...this._self.commandOptions}; - if (command.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._self.commandOptions && command.ignoreTypeMapping ? { ...this._self.commandOptions, typeMapping: undefined} : undefined; const reply = await this._self.sendCommand( command.IS_READ_ONLY, @@ -67,13 +61,7 @@ export function createFunctionCommand) { const redisArgs = command.transformArguments(...args); - let commandOptions: typeof this._self._self.commandOptions; - if (this._self._self.commandOptions) { - commandOptions = {...this._self._self.commandOptions}; - if (command.ignoreTypeMapping) { - commandOptions.typeMapping = undefined - } - } + const commandOptions = this._self._self.commandOptions && command.ignoreTypeMapping ? { ...this._self._self.commandOptions, typeMapping: undefined} : undefined; const reply = await this._self._self.sendCommand( command.IS_READ_ONLY, @@ -119,13 +101,7 @@ export function createScriptCommand