Skip to content

Commit 7b73782

Browse files
authored
fix: fix various command import issues (#2944)
* fix: fix various command import issues there was some sort of a circular dependency in <module>/lib/commands/index.ts for various modules fixes #2937 fixes #2941 * remove redundant definition
1 parent bc4b210 commit 7b73782

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+416
-391
lines changed

packages/bloom/lib/commands/bloom/INFO.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommandParser } from '@redis/client/dist/lib/client/parser';
22
import { RedisArgument, Command, UnwrapReply, NullReply, NumberReply, TuplesToMapReply, Resp2Reply, SimpleStringReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
3-
import { transformInfoV2Reply } from '.';
3+
import { transformInfoV2Reply } from './helpers';
44

55
export type BfInfoReplyMap = TuplesToMapReply<[
66
[SimpleStringReply<'Capacity'>, NumberReply],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { RESP_TYPES, TypeMapping } from "@redis/client";
2+
3+
export function transformInfoV2Reply<T>(reply: Array<any>, typeMapping?: TypeMapping): T {
4+
const mapType = typeMapping ? typeMapping[RESP_TYPES.MAP] : undefined;
5+
6+
switch (mapType) {
7+
case Array: {
8+
return reply as unknown as T;
9+
}
10+
case Map: {
11+
const ret = new Map<string, any>();
12+
13+
for (let i = 0; i < reply.length; i += 2) {
14+
ret.set(reply[i].toString(), reply[i + 1]);
15+
}
16+
17+
return ret as unknown as T;
18+
}
19+
default: {
20+
const ret = Object.create(null);
21+
22+
for (let i = 0; i < reply.length; i += 2) {
23+
ret[reply[i].toString()] = reply[i + 1];
24+
}
25+
26+
return ret as unknown as T;
27+
}
28+
}
29+
}
Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RedisCommands, TypeMapping } from '@redis/client/dist/lib/RESP/types';
1+
import type { RedisCommands } from '@redis/client/dist/lib/RESP/types';
22

33
import ADD from './ADD';
44
import CARD from './CARD';
@@ -10,7 +10,8 @@ import MADD from './MADD';
1010
import MEXISTS from './MEXISTS';
1111
import RESERVE from './RESERVE';
1212
import SCANDUMP from './SCANDUMP';
13-
import { RESP_TYPES } from '@redis/client';
13+
14+
export * from './helpers';
1415

1516
export default {
1617
ADD,
@@ -34,31 +35,3 @@ export default {
3435
SCANDUMP,
3536
scanDump: SCANDUMP
3637
} as const satisfies RedisCommands;
37-
38-
export function transformInfoV2Reply<T>(reply: Array<any>, typeMapping?: TypeMapping): T {
39-
const mapType = typeMapping ? typeMapping[RESP_TYPES.MAP] : undefined;
40-
41-
switch (mapType) {
42-
case Array: {
43-
return reply as unknown as T;
44-
}
45-
case Map: {
46-
const ret = new Map<string, any>();
47-
48-
for (let i = 0; i < reply.length; i += 2) {
49-
ret.set(reply[i].toString(), reply[i + 1]);
50-
}
51-
52-
return ret as unknown as T;
53-
}
54-
default: {
55-
const ret = Object.create(null);
56-
57-
for (let i = 0; i < reply.length; i += 2) {
58-
ret[reply[i].toString()] = reply[i + 1];
59-
}
60-
61-
return ret as unknown as T;
62-
}
63-
}
64-
}

packages/client/lib/client/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,8 @@ export default class RedisClient<
704704
const reply = await this.sendCommand(parser.redisArgs, commandOptions);
705705

706706
if (transformReply) {
707-
return transformReply(reply, parser.preserve, commandOptions?.typeMapping);
707+
const res = transformReply(reply, parser.preserve, commandOptions?.typeMapping);
708+
return res
708709
}
709710

710711
return reply;

packages/json/lib/commands/ARRAPPEND.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommandParser } from '@redis/client/dist/lib/client/parser';
2-
import { RedisJSON, transformRedisJsonArgument } from '.';
2+
import { RedisJSON, transformRedisJsonArgument } from './helpers';
33
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
44

55
export default {

packages/json/lib/commands/ARRINDEX.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommandParser } from '@redis/client/dist/lib/client/parser';
22
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
3-
import { RedisJSON, transformRedisJsonArgument } from '.';
3+
import { RedisJSON, transformRedisJsonArgument } from './helpers';
44

55
export interface JsonArrIndexOptions {
66
range?: {

packages/json/lib/commands/ARRINSERT.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommandParser } from '@redis/client/dist/lib/client/parser';
22
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
3-
import { RedisJSON, transformRedisJsonArgument } from '.';
3+
import { RedisJSON, transformRedisJsonArgument } from './helpers';
44

55
export default {
66
IS_READ_ONLY: false,

packages/json/lib/commands/ARRPOP.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CommandParser } from '@redis/client/dist/lib/client/parser';
22
import { RedisArgument, ArrayReply, NullReply, BlobStringReply, Command, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
33
import { isArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';
4-
import { transformRedisJsonNullReply } from '.';
4+
import { transformRedisJsonNullReply } from './helpers';
55

66
export interface RedisArrPopOptions {
77
path: RedisArgument;

packages/json/lib/commands/GET.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,11 @@ describe('JSON.GET', () => {
3434
await client.json.get('key'),
3535
null
3636
);
37+
38+
await client.json.set('noderedis:users:1', '$', { name: 'Alice', age: 32, })
39+
const res = await client.json.get('noderedis:users:1');
40+
assert.equal(typeof res, 'object')
41+
assert.deepEqual(res, { name: 'Alice', age: 32, })
42+
3743
}, GLOBAL.SERVERS.OPEN);
3844
});

packages/json/lib/commands/GET.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { CommandParser } from '@redis/client/dist/lib/client/parser';
22
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
33
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
4-
import { transformRedisJsonNullReply } from '.';
4+
import { transformRedisJsonNullReply } from './helpers';
55

66
export interface JsonGetOptions {
77
path?: RedisVariadicArgument;
88
}
99

1010
export default {
1111
IS_READ_ONLY: false,
12-
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonGetOptions) {
12+
parseCommand(
13+
parser: CommandParser,
14+
key: RedisArgument,
15+
options?: JsonGetOptions
16+
) {
1317
parser.push('JSON.GET');
1418
parser.pushKey(key);
1519
if (options?.path !== undefined) {
16-
parser.pushVariadic(options.path)
20+
parser.pushVariadic(options.path);
1721
}
1822
},
1923
transformReply: transformRedisJsonNullReply
20-
} as const satisfies Command;
24+
} as const satisfies Command;

0 commit comments

Comments
 (0)