Skip to content

Commit 4fa8734

Browse files
committed
leibele's type changing and cleaning up disabling of type mapping
1 parent 2b6e99a commit 4fa8734

File tree

5 files changed

+21
-127
lines changed

5 files changed

+21
-127
lines changed

packages/client/lib/RESP/types.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,14 @@ type MapKeyValue = [key: BlobStringReply, value: unknown];
132132

133133
type MapTuples = Array<MapKeyValue>;
134134

135-
export interface TuplesToMapReply<T extends MapTuples> extends RespType<
136-
RESP_TYPES['MAP'],
137-
{
138-
[P in T[number] as P[0] extends BlobStringReply<infer S> ? S : never]: P[1];
139-
},
140-
Map<T[number][0], T[number][1]> | FlattenTuples<T>
141-
> {}
142-
143-
type SimpleMapKeyValue = [key: SimpleStringReply, value: unknown];
135+
type ExtractMapKey<T> = T extends BlobStringReply<infer S> ? S : never;
144136

145-
type SimpleMapTuples = Array<SimpleMapKeyValue>;
146-
147-
export interface SimpleTuplesToMapReply<T extends SimpleMapTuples> extends RespType<
137+
export interface TuplesToMapReply<T extends MapTuples> extends RespType<
148138
RESP_TYPES['MAP'],
149139
{
150-
[P in T[number] as P[0] extends SimpleStringReply<infer S> ? S : never]: P[1];
140+
[P in T[number] as ExtractMapKey<P[0]>]: P[1];
151141
},
152-
Map<T[number][0], T[number][1]> | FlattenTuples<T>
142+
Map<ExtractMapKey<T[number][0]>, T[number][1]> | FlattenTuples<T>
153143
> {}
154144

155145
type FlattenTuples<T> = (

packages/client/lib/client/index.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,7 @@ export default class RedisClient<
154154
return async function (this: ProxyClient, ...args: Array<unknown>) {
155155
const redisArgs = command.transformArguments(...args);
156156

157-
let commandOptions: typeof this._commandOptions;
158-
if (this._commandOptions) {
159-
commandOptions = {...this._commandOptions};
160-
if (command.ignoreTypeMapping) {
161-
commandOptions.typeMapping = undefined
162-
}
163-
}
157+
const commandOptions = this._commandOptions && command.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined;
164158

165159
const reply = await this.sendCommand(redisArgs, commandOptions);
166160
return transformReply ?
@@ -174,13 +168,7 @@ export default class RedisClient<
174168
return async function (this: NamespaceProxyClient, ...args: Array<unknown>) {
175169
const redisArgs = command.transformArguments(...args);
176170

177-
let commandOptions: typeof this._self._commandOptions;
178-
if (this._self._commandOptions) {
179-
commandOptions = {...this._self._commandOptions};
180-
if (command.ignoreTypeMapping) {
181-
commandOptions.typeMapping = undefined
182-
}
183-
}
171+
const commandOptions = this._self._commandOptions && command.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined;
184172

185173
const reply = await this._self.sendCommand(redisArgs, commandOptions);
186174
return transformReply ?
@@ -195,13 +183,7 @@ export default class RedisClient<
195183
return async function (this: NamespaceProxyClient, ...args: Array<unknown>) {
196184
const fnArgs = fn.transformArguments(...args);
197185

198-
let commandOptions: typeof this._self._commandOptions;
199-
if (this._self._commandOptions) {
200-
commandOptions = {...this._self._commandOptions};
201-
if (fn.ignoreTypeMapping) {
202-
commandOptions.typeMapping = undefined
203-
}
204-
}
186+
const commandOptions = this._self._commandOptions && fn.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined;
205187

206188
const reply = await this._self.sendCommand(
207189
prefix.concat(fnArgs),
@@ -220,13 +202,7 @@ export default class RedisClient<
220202
const scriptArgs = script.transformArguments(...args);
221203
const redisArgs = prefix.concat(scriptArgs)
222204

223-
let commandOptions: typeof this._commandOptions;
224-
if (this._commandOptions) {
225-
commandOptions = {...this._commandOptions};
226-
if (script.ignoreTypeMapping) {
227-
commandOptions.typeMapping = undefined
228-
}
229-
}
205+
const commandOptions = this._commandOptions && script.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined;
230206

231207
const reply = await this.executeScript(script, redisArgs, commandOptions);
232208
return transformReply ?

packages/client/lib/client/pool.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,7 @@ export class RedisClientPool<
6767
return async function (this: ProxyPool, ...args: Array<unknown>) {
6868
const redisArgs = command.transformArguments(...args);
6969

70-
let commandOptions: typeof this._commandOptions;
71-
if (this._commandOptions) {
72-
commandOptions = {...this._commandOptions};
73-
if (command.ignoreTypeMapping) {
74-
commandOptions.typeMapping = undefined
75-
}
76-
}
70+
const commandOptions = this._commandOptions && command.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined;
7771

7872
const reply = await this.sendCommand(redisArgs, commandOptions);
7973
return transformReply ?
@@ -87,13 +81,7 @@ export class RedisClientPool<
8781
return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
8882
const redisArgs = command.transformArguments(...args);
8983

90-
let commandOptions: typeof this._self._commandOptions;
91-
if (this._self._commandOptions) {
92-
commandOptions = {...this._self._commandOptions};
93-
if (command.ignoreTypeMapping) {
94-
commandOptions.typeMapping = undefined
95-
}
96-
}
84+
const commandOptions = this._self._commandOptions && command.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined;
9785

9886
const reply = await this._self.sendCommand(redisArgs, commandOptions);
9987
return transformReply ?
@@ -108,13 +96,7 @@ export class RedisClientPool<
10896
return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
10997
const fnArgs = fn.transformArguments(...args);
11098

111-
let commandOptions: typeof this._self._commandOptions;
112-
if (this._self._commandOptions) {
113-
commandOptions = {...this._self._commandOptions};
114-
if (fn.ignoreTypeMapping) {
115-
commandOptions.typeMapping = undefined
116-
}
117-
}
99+
const commandOptions = this._self._commandOptions && fn.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined;
118100

119101
const reply = await this._self.sendCommand(
120102
prefix.concat(fnArgs),
@@ -133,13 +115,7 @@ export class RedisClientPool<
133115
const scriptArgs = script.transformArguments(...args);
134116
const redisArgs = prefix.concat(scriptArgs);
135117

136-
let commandOptions: typeof this._commandOptions;
137-
if (this._commandOptions) {
138-
commandOptions = {...this._commandOptions};
139-
if (script.ignoreTypeMapping) {
140-
commandOptions.typeMapping = undefined
141-
}
142-
}
118+
const commandOptions = this._commandOptions && script.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined;
143119

144120
const reply = await this.executeScript(script, redisArgs, commandOptions);
145121
return transformReply ?

packages/client/lib/cluster/index.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,7 @@ export default class RedisCluster<
181181
redisArgs
182182
);
183183

184-
let commandOptions: typeof this._commandOptions;
185-
if (this._commandOptions) {
186-
commandOptions = {...this._commandOptions};
187-
if (command.ignoreTypeMapping) {
188-
commandOptions.typeMapping = undefined
189-
}
190-
}
184+
const commandOptions = this._commandOptions && command.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined;
191185

192186
const reply = await this.sendCommand(
193187
firstKey,
@@ -213,13 +207,7 @@ export default class RedisCluster<
213207
redisArgs
214208
);
215209

216-
let commandOptions: typeof this._self._commandOptions;
217-
if (this._self._commandOptions) {
218-
commandOptions = {...this._self._commandOptions};
219-
if (command.ignoreTypeMapping) {
220-
commandOptions.typeMapping = undefined
221-
}
222-
}
210+
const commandOptions = this._self._commandOptions && command.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined;
223211

224212
const reply = await this._self.sendCommand(
225213
firstKey,
@@ -247,13 +235,7 @@ export default class RedisCluster<
247235
);
248236
const redisArgs = prefix.concat(fnArgs);
249237

250-
let commandOptions: typeof this._self._commandOptions;
251-
if (this._self._commandOptions) {
252-
commandOptions = {...this._self._commandOptions};
253-
if (fn.ignoreTypeMapping) {
254-
commandOptions.typeMapping = undefined
255-
}
256-
}
238+
const commandOptions = this._self._commandOptions && fn.ignoreTypeMapping ? { ...this._self._commandOptions, typeMapping: undefined} : undefined;
257239

258240
const reply = await this._self.sendCommand(
259241
firstKey,
@@ -281,14 +263,8 @@ export default class RedisCluster<
281263
);
282264
const redisArgs = prefix.concat(scriptArgs);
283265

284-
let commandOptions: typeof this._commandOptions;
285-
if (this._commandOptions) {
286-
commandOptions = {...this._commandOptions};
287-
if (script.ignoreTypeMapping) {
288-
commandOptions.typeMapping = undefined
289-
}
290-
}
291-
266+
const commandOptions = this._commandOptions && script.ignoreTypeMapping ? { ...this._commandOptions, typeMapping: undefined} : undefined;
267+
292268
const reply = await this.executeScript(
293269
script,
294270
firstKey,

packages/client/lib/sentinel/utils.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ export function createCommand<T extends ProxySentinel | ProxySentinelClient>(com
4040
return async function (this: T, ...args: Array<unknown>) {
4141
const redisArgs = command.transformArguments(...args);
4242

43-
let commandOptions: typeof this._self.commandOptions;
44-
if (this._self.commandOptions) {
45-
commandOptions = {...this._self.commandOptions};
46-
if (command.ignoreTypeMapping) {
47-
commandOptions.typeMapping = undefined
48-
}
49-
}
43+
const commandOptions = this._self.commandOptions && command.ignoreTypeMapping ? { ...this._self.commandOptions, typeMapping: undefined} : undefined;
5044

5145
const reply = await this._self.sendCommand(
5246
command.IS_READ_ONLY,
@@ -67,13 +61,7 @@ export function createFunctionCommand<T extends NamespaceProxySentinel | Namespa
6761
const fnArgs = fn.transformArguments(...args);
6862
const redisArgs = prefix.concat(fnArgs);
6963

70-
let commandOptions: typeof this._self._self.commandOptions;
71-
if (this._self._self.commandOptions) {
72-
commandOptions = {...this._self._self.commandOptions};
73-
if (fn.ignoreTypeMapping) {
74-
commandOptions.typeMapping = undefined
75-
}
76-
}
64+
const commandOptions = this._self._self.commandOptions && fn.ignoreTypeMapping ? { ...this._self._self.commandOptions, typeMapping: undefined} : undefined;
7765

7866
const reply = await this._self._self.sendCommand(
7967
fn.IS_READ_ONLY,
@@ -92,13 +80,7 @@ export function createModuleCommand<T extends NamespaceProxySentinel | Namespace
9280
return async function (this: T, ...args: Array<unknown>) {
9381
const redisArgs = command.transformArguments(...args);
9482

95-
let commandOptions: typeof this._self._self.commandOptions;
96-
if (this._self._self.commandOptions) {
97-
commandOptions = {...this._self._self.commandOptions};
98-
if (command.ignoreTypeMapping) {
99-
commandOptions.typeMapping = undefined
100-
}
101-
}
83+
const commandOptions = this._self._self.commandOptions && command.ignoreTypeMapping ? { ...this._self._self.commandOptions, typeMapping: undefined} : undefined;
10284

10385
const reply = await this._self._self.sendCommand(
10486
command.IS_READ_ONLY,
@@ -119,13 +101,7 @@ export function createScriptCommand<T extends ProxySentinel | ProxySentinelClien
119101
const scriptArgs = script.transformArguments(...args);
120102
const redisArgs = prefix.concat(scriptArgs);
121103

122-
let commandOptions: typeof this._self.commandOptions;
123-
if (this._self.commandOptions) {
124-
commandOptions = {...this._self.commandOptions};
125-
if (script.ignoreTypeMapping) {
126-
commandOptions.typeMapping = undefined
127-
}
128-
}
104+
const commandOptions = this._self.commandOptions && script.ignoreTypeMapping ? { ...this._self.commandOptions, typeMapping: undefined} : undefined;
129105

130106
const reply = await this._self.executeScript(
131107
script,

0 commit comments

Comments
 (0)