1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

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 <leibale1998@gmail.com>
This commit is contained in:
Brandon Everett
2022-07-13 07:01:35 -04:00
committed by GitHub
parent 71d582368a
commit ac032d82a0
7 changed files with 32 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
import { pushVerdictArguments } from '@redis/client/dist/lib/commands/generic-transformers'; import { pushVerdictArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
export const FIRST_KEY_INDEX = 1; export const FIRST_KEY_INDEX = 1;
@@ -12,9 +13,9 @@ interface InsertOptions {
export function transformArguments( export function transformArguments(
key: string, key: string,
items: string | Array<string>, items: RedisCommandArgument | Array<RedisCommandArgument>,
options?: InsertOptions options?: InsertOptions
): Array<string> { ): RedisCommandArguments {
const args = ['BF.INSERT', key]; const args = ['BF.INSERT', key];
if (options?.CAPACITY) { if (options?.CAPACITY) {
@@ -38,9 +39,7 @@ export function transformArguments(
} }
args.push('ITEMS'); args.push('ITEMS');
pushVerdictArguments(args, items); return pushVerdictArguments(args, items);
return args;
} }
export { transformBooleanArrayReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers'; export { transformBooleanArrayReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';

View File

@@ -1,13 +1,14 @@
import { pushVerdictArguments } from './generic-transformers'; import { pushVerdictArguments } from './generic-transformers';
import { RedisCommandArgument, RedisCommandArguments } from '.';
export const IS_READ_ONLY = true; export const IS_READ_ONLY = true;
export function transformArguments(channels?: Array<string> | string): Array<string> { export function transformArguments(
channels?: Array<RedisCommandArgument> | RedisCommandArgument
): RedisCommandArguments {
const args = ['PUBSUB', 'NUMSUB']; const args = ['PUBSUB', 'NUMSUB'];
if (channels) { if (channels) return pushVerdictArguments(args, channels);
pushVerdictArguments(args, channels);
}
return args; return args;
} }

View File

@@ -18,9 +18,10 @@ export function transformArguments(
id: RedisCommandArgument | Array<RedisCommandArgument>, id: RedisCommandArgument | Array<RedisCommandArgument>,
options?: XClaimOptions options?: XClaimOptions
): RedisCommandArguments { ): RedisCommandArguments {
const args = ['XCLAIM', key, group, consumer, minIdleTime.toString()]; const args = pushVerdictArguments(
['XCLAIM', key, group, consumer, minIdleTime.toString()],
pushVerdictArguments(args, id); id
);
if (options?.IDLE) { if (options?.IDLE) {
args.push('IDLE', options.IDLE.toString()); args.push('IDLE', options.IDLE.toString());

View File

@@ -428,7 +428,8 @@ export function pushEvalArguments(args: Array<string>, options?: EvalOptions): A
export function pushVerdictArguments(args: RedisCommandArguments, value: RedisCommandArgument | Array<RedisCommandArgument>): RedisCommandArguments { export function pushVerdictArguments(args: RedisCommandArguments, value: RedisCommandArgument | Array<RedisCommandArgument>): RedisCommandArguments {
if (Array.isArray(value)) { if (Array.isArray(value)) {
args.push(...value); // https://github.com/redis/node-redis/pull/2160
args = args.concat(value);
} else { } else {
args.push(value); args.push(value);
} }

View File

@@ -1,4 +1,5 @@
import { pushVerdictArguments } from '@redis/client/dist/lib/commands/generic-transformers'; import { pushVerdictArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
export const FIRST_KEY_INDEX = 1; export const FIRST_KEY_INDEX = 1;
@@ -12,11 +13,11 @@ interface GetOptions {
NOESCAPE?: true; NOESCAPE?: true;
} }
export function transformArguments(key: string, options?: GetOptions): Array<string> { export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments {
const args = ['JSON.GET', key]; let args: RedisCommandArguments = ['JSON.GET', key];
if (options?.path) { if (options?.path) {
pushVerdictArguments(args, options.path); args = pushVerdictArguments(args, options.path);
} }
if (options?.INDENT) { if (options?.INDENT) {

View File

@@ -8,6 +8,7 @@ import {
pushFilterArgument pushFilterArgument
} from '.'; } from '.';
import { MGetRawReply, MGetReply } from './MGET'; import { MGetRawReply, MGetReply } from './MGET';
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
export const IS_READ_ONLY = true; export const IS_READ_ONLY = true;
@@ -18,14 +19,9 @@ interface MGetWithLabelsOptions {
export function transformArguments( export function transformArguments(
filter: Filter, filter: Filter,
options?: MGetWithLabelsOptions options?: MGetWithLabelsOptions
): Array<string> { ): RedisCommandArguments {
const args = ['TS.MGET']; const args = pushWithLabelsArgument(['TS.MGET'], options?.SELECTED_LABELS);
return pushFilterArgument(args, filter);
pushWithLabelsArgument(args, options?.SELECTED_LABELS);
pushFilterArgument(args, filter);
return args;
} }
export interface MGetWithLabelsReply extends MGetReply { export interface MGetWithLabelsReply extends MGetReply {

View File

@@ -313,8 +313,7 @@ export type Filter = string | Array<string>;
export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array<string>): RedisCommandArguments { export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array<string>): RedisCommandArguments {
args.push('FILTER'); args.push('FILTER');
pushVerdictArguments(args, filter); return pushVerdictArguments(args, filter);
return args;
} }
export interface MRangeOptions extends RangeOptions { export interface MRangeOptions extends RangeOptions {
@@ -328,10 +327,9 @@ export function pushMRangeArguments(
filter: Filter, filter: Filter,
options?: MRangeOptions options?: MRangeOptions
): RedisCommandArguments { ): RedisCommandArguments {
pushRangeArguments(args, fromTimestamp, toTimestamp, options); args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
pushFilterArgument(args, filter); args = pushFilterArgument(args, filter);
pushMRangeGroupByArguments(args, options?.GROUPBY); return pushMRangeGroupByArguments(args, options?.GROUPBY);
return args;
} }
export type SelectedLabels = string | Array<string>; export type SelectedLabels = string | Array<string>;
@@ -341,7 +339,7 @@ export function pushWithLabelsArgument(args: RedisCommandArguments, selectedLabe
args.push('WITHLABELS'); args.push('WITHLABELS');
} else { } else {
args.push('SELECTED_LABELS'); args.push('SELECTED_LABELS');
pushVerdictArguments(args, selectedLabels); args = pushVerdictArguments(args, selectedLabels);
} }
return args; return args;
@@ -358,11 +356,10 @@ export function pushMRangeWithLabelsArguments(
filter: Filter, filter: Filter,
options?: MRangeWithLabelsOptions options?: MRangeWithLabelsOptions
): RedisCommandArguments { ): RedisCommandArguments {
pushRangeArguments(args, fromTimestamp, toTimestamp, options); args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
pushWithLabelsArgument(args, options?.SELECTED_LABELS); args = pushWithLabelsArgument(args, options?.SELECTED_LABELS);
pushFilterArgument(args, filter); args = pushFilterArgument(args, filter);
pushMRangeGroupByArguments(args, options?.GROUPBY); return pushMRangeGroupByArguments(args, options?.GROUPBY);
return args;
} }
export function transformRangeReply(reply: Array<SampleRawReply>): Array<SampleReply> { export function transformRangeReply(reply: Array<SampleRawReply>): Array<SampleReply> {