Skip to content

Commit ac032d8

Browse files
bmeverettleibale
andauthored
fix: loop over arguments instead of spreading (#2160)
* fix: loop over arguments instead of spreading * update to use concat * use the returned array from pushVerdictArguments (instead of assuming it'll push to the original array) * fix "Type 'RedisCommandArguments' is not assignable to type 'string[]'." * fix "Argument of type 'RedisCommandArgument | RedisCommandArguments[]' is not assignable to parameter of type 'RedisCommandArgument | RedisCommandArgument[]'" * fix "Type 'RedisCommandArguments' is not assignable to type 'string[]'" Co-authored-by: Leibale Eidelman <[email protected]>
1 parent 71d5823 commit ac032d8

File tree

7 files changed

+32
-36
lines changed

7 files changed

+32
-36
lines changed

packages/bloom/lib/commands/bloom/INSERT.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { pushVerdictArguments } from '@redis/client/dist/lib/commands/generic-transformers';
2+
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
23

34
export const FIRST_KEY_INDEX = 1;
45

@@ -12,9 +13,9 @@ interface InsertOptions {
1213

1314
export function transformArguments(
1415
key: string,
15-
items: string | Array<string>,
16+
items: RedisCommandArgument | Array<RedisCommandArgument>,
1617
options?: InsertOptions
17-
): Array<string> {
18+
): RedisCommandArguments {
1819
const args = ['BF.INSERT', key];
1920

2021
if (options?.CAPACITY) {
@@ -38,9 +39,7 @@ export function transformArguments(
3839
}
3940

4041
args.push('ITEMS');
41-
pushVerdictArguments(args, items);
42-
43-
return args;
42+
return pushVerdictArguments(args, items);
4443
}
4544

4645
export { transformBooleanArrayReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';

packages/client/lib/commands/PUBSUB_NUMSUB.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { pushVerdictArguments } from './generic-transformers';
2+
import { RedisCommandArgument, RedisCommandArguments } from '.';
23

34
export const IS_READ_ONLY = true;
45

5-
export function transformArguments(channels?: Array<string> | string): Array<string> {
6+
export function transformArguments(
7+
channels?: Array<RedisCommandArgument> | RedisCommandArgument
8+
): RedisCommandArguments {
69
const args = ['PUBSUB', 'NUMSUB'];
710

8-
if (channels) {
9-
pushVerdictArguments(args, channels);
10-
}
11+
if (channels) return pushVerdictArguments(args, channels);
1112

1213
return args;
1314
}

packages/client/lib/commands/XCLAIM.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export function transformArguments(
1818
id: RedisCommandArgument | Array<RedisCommandArgument>,
1919
options?: XClaimOptions
2020
): RedisCommandArguments {
21-
const args = ['XCLAIM', key, group, consumer, minIdleTime.toString()];
22-
23-
pushVerdictArguments(args, id);
21+
const args = pushVerdictArguments(
22+
['XCLAIM', key, group, consumer, minIdleTime.toString()],
23+
id
24+
);
2425

2526
if (options?.IDLE) {
2627
args.push('IDLE', options.IDLE.toString());

packages/client/lib/commands/generic-transformers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ export function pushEvalArguments(args: Array<string>, options?: EvalOptions): A
428428

429429
export function pushVerdictArguments(args: RedisCommandArguments, value: RedisCommandArgument | Array<RedisCommandArgument>): RedisCommandArguments {
430430
if (Array.isArray(value)) {
431-
args.push(...value);
431+
// https://github.com/redis/node-redis/pull/2160
432+
args = args.concat(value);
432433
} else {
433434
args.push(value);
434435
}

packages/json/lib/commands/GET.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { pushVerdictArguments } from '@redis/client/dist/lib/commands/generic-transformers';
2+
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
23

34
export const FIRST_KEY_INDEX = 1;
45

@@ -12,11 +13,11 @@ interface GetOptions {
1213
NOESCAPE?: true;
1314
}
1415

15-
export function transformArguments(key: string, options?: GetOptions): Array<string> {
16-
const args = ['JSON.GET', key];
16+
export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments {
17+
let args: RedisCommandArguments = ['JSON.GET', key];
1718

1819
if (options?.path) {
19-
pushVerdictArguments(args, options.path);
20+
args = pushVerdictArguments(args, options.path);
2021
}
2122

2223
if (options?.INDENT) {

packages/time-series/lib/commands/MGET_WITHLABELS.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
pushFilterArgument
99
} from '.';
1010
import { MGetRawReply, MGetReply } from './MGET';
11+
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
1112

1213
export const IS_READ_ONLY = true;
1314

@@ -18,14 +19,9 @@ interface MGetWithLabelsOptions {
1819
export function transformArguments(
1920
filter: Filter,
2021
options?: MGetWithLabelsOptions
21-
): Array<string> {
22-
const args = ['TS.MGET'];
23-
24-
pushWithLabelsArgument(args, options?.SELECTED_LABELS);
25-
26-
pushFilterArgument(args, filter);
27-
28-
return args;
22+
): RedisCommandArguments {
23+
const args = pushWithLabelsArgument(['TS.MGET'], options?.SELECTED_LABELS);
24+
return pushFilterArgument(args, filter);
2925
}
3026

3127
export interface MGetWithLabelsReply extends MGetReply {

packages/time-series/lib/commands/index.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ export type Filter = string | Array<string>;
313313

314314
export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array<string>): RedisCommandArguments {
315315
args.push('FILTER');
316-
pushVerdictArguments(args, filter);
317-
return args;
316+
return pushVerdictArguments(args, filter);
318317
}
319318

320319
export interface MRangeOptions extends RangeOptions {
@@ -328,10 +327,9 @@ export function pushMRangeArguments(
328327
filter: Filter,
329328
options?: MRangeOptions
330329
): RedisCommandArguments {
331-
pushRangeArguments(args, fromTimestamp, toTimestamp, options);
332-
pushFilterArgument(args, filter);
333-
pushMRangeGroupByArguments(args, options?.GROUPBY);
334-
return args;
330+
args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
331+
args = pushFilterArgument(args, filter);
332+
return pushMRangeGroupByArguments(args, options?.GROUPBY);
335333
}
336334

337335
export type SelectedLabels = string | Array<string>;
@@ -341,7 +339,7 @@ export function pushWithLabelsArgument(args: RedisCommandArguments, selectedLabe
341339
args.push('WITHLABELS');
342340
} else {
343341
args.push('SELECTED_LABELS');
344-
pushVerdictArguments(args, selectedLabels);
342+
args = pushVerdictArguments(args, selectedLabels);
345343
}
346344

347345
return args;
@@ -358,11 +356,10 @@ export function pushMRangeWithLabelsArguments(
358356
filter: Filter,
359357
options?: MRangeWithLabelsOptions
360358
): RedisCommandArguments {
361-
pushRangeArguments(args, fromTimestamp, toTimestamp, options);
362-
pushWithLabelsArgument(args, options?.SELECTED_LABELS);
363-
pushFilterArgument(args, filter);
364-
pushMRangeGroupByArguments(args, options?.GROUPBY);
365-
return args;
359+
args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
360+
args = pushWithLabelsArgument(args, options?.SELECTED_LABELS);
361+
args = pushFilterArgument(args, filter);
362+
return pushMRangeGroupByArguments(args, options?.GROUPBY);
366363
}
367364

368365
export function transformRangeReply(reply: Array<SampleRawReply>): Array<SampleReply> {

0 commit comments

Comments
 (0)