Skip to content

Commit

Permalink
leibele's type changing and cleaning up disabling of type mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter committed Jun 3, 2024
1 parent 2b6e99a commit 4fa8734
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 127 deletions.
18 changes: 4 additions & 14 deletions packages/client/lib/RESP/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,14 @@ type MapKeyValue = [key: BlobStringReply, value: unknown];

type MapTuples = Array<MapKeyValue>;

export interface TuplesToMapReply<T extends MapTuples> extends RespType<
RESP_TYPES['MAP'],
{
[P in T[number] as P[0] extends BlobStringReply<infer S> ? S : never]: P[1];
},
Map<T[number][0], T[number][1]> | FlattenTuples<T>
> {}

type SimpleMapKeyValue = [key: SimpleStringReply, value: unknown];
type ExtractMapKey<T> = T extends BlobStringReply<infer S> ? S : never;

type SimpleMapTuples = Array<SimpleMapKeyValue>;

export interface SimpleTuplesToMapReply<T extends SimpleMapTuples> extends RespType<
export interface TuplesToMapReply<T extends MapTuples> extends RespType<
RESP_TYPES['MAP'],
{
[P in T[number] as P[0] extends SimpleStringReply<infer S> ? S : never]: P[1];
[P in T[number] as ExtractMapKey<P[0]>]: P[1];
},
Map<T[number][0], T[number][1]> | FlattenTuples<T>
Map<ExtractMapKey<T[number][0]>, T[number][1]> | FlattenTuples<T>
> {}

type FlattenTuples<T> = (
Expand Down
32 changes: 4 additions & 28 deletions packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,7 @@ export default class RedisClient<
return async function (this: ProxyClient, ...args: Array<unknown>) {
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 ?
Expand All @@ -174,13 +168,7 @@ export default class RedisClient<
return async function (this: NamespaceProxyClient, ...args: Array<unknown>) {
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 ?
Expand All @@ -195,13 +183,7 @@ export default class RedisClient<
return async function (this: NamespaceProxyClient, ...args: Array<unknown>) {
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),
Expand All @@ -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 ?
Expand Down
32 changes: 4 additions & 28 deletions packages/client/lib/client/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ export class RedisClientPool<
return async function (this: ProxyPool, ...args: Array<unknown>) {
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 ?
Expand All @@ -87,13 +81,7 @@ export class RedisClientPool<
return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
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 ?
Expand All @@ -108,13 +96,7 @@ export class RedisClientPool<
return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
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),
Expand All @@ -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 ?
Expand Down
34 changes: 5 additions & 29 deletions packages/client/lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 4 additions & 28 deletions packages/client/lib/sentinel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ export function createCommand<T extends ProxySentinel | ProxySentinelClient>(com
return async function (this: T, ...args: Array<unknown>) {
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,
Expand All @@ -67,13 +61,7 @@ export function createFunctionCommand<T extends NamespaceProxySentinel | Namespa
const fnArgs = fn.transformArguments(...args);
const redisArgs = prefix.concat(fnArgs);

let commandOptions: typeof this._self._self.commandOptions;
if (this._self._self.commandOptions) {
commandOptions = {...this._self._self.commandOptions};
if (fn.ignoreTypeMapping) {
commandOptions.typeMapping = undefined
}
}
const commandOptions = this._self._self.commandOptions && fn.ignoreTypeMapping ? { ...this._self._self.commandOptions, typeMapping: undefined} : undefined;

const reply = await this._self._self.sendCommand(
fn.IS_READ_ONLY,
Expand All @@ -92,13 +80,7 @@ export function createModuleCommand<T extends NamespaceProxySentinel | Namespace
return async function (this: T, ...args: Array<unknown>) {
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,
Expand All @@ -119,13 +101,7 @@ export function createScriptCommand<T extends ProxySentinel | ProxySentinelClien
const scriptArgs = script.transformArguments(...args);
const redisArgs = prefix.concat(scriptArgs);

let commandOptions: typeof this._self.commandOptions;
if (this._self.commandOptions) {
commandOptions = {...this._self.commandOptions};
if (script.ignoreTypeMapping) {
commandOptions.typeMapping = undefined
}
}
const commandOptions = this._self.commandOptions && script.ignoreTypeMapping ? { ...this._self.commandOptions, typeMapping: undefined} : undefined;

const reply = await this._self.executeScript(
script,
Expand Down

0 comments on commit 4fa8734

Please sign in to comment.