Skip to content

Commit 2340c44

Browse files
committed
Parser support with all commands
1 parent c07b4db commit 2340c44

File tree

1,005 files changed

+5402
-4558
lines changed

Some content is hidden

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

1,005 files changed

+5402
-4558
lines changed

packages/bloom/lib/commands/bloom/ADD.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import ADD from './ADD';
4+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
describe('BF.ADD', () => {
67
it('transformArguments', () => {
78
assert.deepEqual(
8-
ADD.transformArguments('key', 'item'),
9+
parseArgs(ADD, 'key', 'item'),
910
['BF.ADD', 'key', 'item']
1011
);
1112
});
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { CommandParser } from '@redis/client/dist/lib/client/parser';
12
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
23
import { transformBooleanReply } from '@redis/client/dist/lib/commands/generic-transformers';
34

45
export default {
5-
FIRST_KEY_INDEX: 1,
66
IS_READ_ONLY: false,
7-
transformArguments(key: RedisArgument, item: RedisArgument) {
8-
return ['BF.ADD', key, item];
7+
parseCommand(parser: CommandParser, key: RedisArgument, item: RedisArgument) {
8+
parser.push('BF.ADD');
9+
parser.pushKey(key);
10+
parser.push(item);
911
},
1012
transformReply: transformBooleanReply
1113
} as const satisfies Command;

packages/bloom/lib/commands/bloom/CARD.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import CARD from './CARD';
4+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
describe('BF.CARD', () => {
67
it('transformArguments', () => {
78
assert.deepEqual(
8-
CARD.transformArguments('bloom'),
9+
parseArgs(CARD, 'bloom'),
910
['BF.CARD', 'bloom']
1011
);
1112
});
+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { CommandParser } from '@redis/client/dist/lib/client/parser';
12
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
23

34
export default {
4-
FIRST_KEY_INDEX: 1,
55
IS_READ_ONLY: true,
6-
transformArguments(key: RedisArgument) {
7-
return ['BF.CARD', key];
6+
parseCommand(parser: CommandParser, key: RedisArgument) {
7+
parser.push('BF.CARD');
8+
parser.pushKey(key);
89
},
910
transformReply: undefined as unknown as () => NumberReply
1011
} as const satisfies Command;

packages/bloom/lib/commands/bloom/EXISTS.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import EXISTS from './EXISTS';
4+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
describe('BF.EXISTS', () => {
67
it('transformArguments', () => {
78
assert.deepEqual(
8-
EXISTS.transformArguments('key', 'item'),
9+
parseArgs(EXISTS, 'key', 'item'),
910
['BF.EXISTS', 'key', 'item']
1011
);
1112
});
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { CommandParser } from '@redis/client/dist/lib/client/parser';
12
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
23
import { transformBooleanReply } from '@redis/client/dist/lib/commands/generic-transformers';
34

45
export default {
5-
FIRST_KEY_INDEX: 1,
66
IS_READ_ONLY: true,
7-
transformArguments(key: RedisArgument, item: RedisArgument) {
8-
return ['BF.EXISTS', key, item];
7+
parseCommand(parser: CommandParser, key: RedisArgument, item: RedisArgument) {
8+
parser.push('BF.EXISTS');
9+
parser.pushKey(key);
10+
parser.push(item);
911
},
1012
transformReply: transformBooleanReply
1113
} as const satisfies Command;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import INFO from './INFO';
4+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
describe('BF.INFO', () => {
67
it('transformArguments', () => {
78
assert.deepEqual(
8-
INFO.transformArguments('bloom'),
9+
parseArgs(INFO, 'bloom'),
910
['BF.INFO', 'bloom']
1011
);
1112
});

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

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CommandParser } from '@redis/client/dist/lib/client/parser';
12
import { RedisArgument, Command, UnwrapReply, NullReply, NumberReply, TuplesToMapReply, Resp2Reply, SimpleStringReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
23
import { transformInfoV2Reply } from '.';
34

@@ -9,19 +10,11 @@ export type BfInfoReplyMap = TuplesToMapReply<[
910
[SimpleStringReply<'Expansion rate'>, NullReply | NumberReply]
1011
]>;
1112

12-
export interface BfInfoReply {
13-
capacity: NumberReply;
14-
size: NumberReply;
15-
numberOfFilters: NumberReply;
16-
numberOfInsertedItems: NumberReply;
17-
expansionRate: NullReply | NumberReply;
18-
}
19-
2013
export default {
21-
FIRST_KEY_INDEX: 1,
2214
IS_READ_ONLY: true,
23-
transformArguments(key: RedisArgument) {
24-
return ['BF.INFO', key];
15+
parseCommand(parser: CommandParser, key: RedisArgument) {
16+
parser.push('BF.INFO');
17+
parser.pushKey(key);
2518
},
2619
transformReply: {
2720
2: (reply: UnwrapReply<Resp2Reply<BfInfoReplyMap>>, _, typeMapping?: TypeMapping): BfInfoReplyMap => {

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import INSERT from './INSERT';
4+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
describe('BF.INSERT', () => {
67
describe('transformArguments', () => {
78
it('simple', () => {
89
assert.deepEqual(
9-
INSERT.transformArguments('key', 'item'),
10+
parseArgs(INSERT, 'key', 'item'),
1011
['BF.INSERT', 'key', 'ITEMS', 'item']
1112
);
1213
});
1314

1415
it('with CAPACITY', () => {
1516
assert.deepEqual(
16-
INSERT.transformArguments('key', 'item', { CAPACITY: 100 }),
17+
parseArgs(INSERT, 'key', 'item', { CAPACITY: 100 }),
1718
['BF.INSERT', 'key', 'CAPACITY', '100', 'ITEMS', 'item']
1819
);
1920
});
2021

2122
it('with ERROR', () => {
2223
assert.deepEqual(
23-
INSERT.transformArguments('key', 'item', { ERROR: 0.01 }),
24+
parseArgs(INSERT, 'key', 'item', { ERROR: 0.01 }),
2425
['BF.INSERT', 'key', 'ERROR', '0.01', 'ITEMS', 'item']
2526
);
2627
});
2728

2829
it('with EXPANSION', () => {
2930
assert.deepEqual(
30-
INSERT.transformArguments('key', 'item', { EXPANSION: 1 }),
31+
parseArgs(INSERT, 'key', 'item', { EXPANSION: 1 }),
3132
['BF.INSERT', 'key', 'EXPANSION', '1', 'ITEMS', 'item']
3233
);
3334
});
3435

3536
it('with NOCREATE', () => {
3637
assert.deepEqual(
37-
INSERT.transformArguments('key', 'item', { NOCREATE: true }),
38+
parseArgs(INSERT, 'key', 'item', { NOCREATE: true }),
3839
['BF.INSERT', 'key', 'NOCREATE', 'ITEMS', 'item']
3940
);
4041
});
4142

4243
it('with NONSCALING', () => {
4344
assert.deepEqual(
44-
INSERT.transformArguments('key', 'item', { NONSCALING: true }),
45+
parseArgs(INSERT, 'key', 'item', { NONSCALING: true }),
4546
['BF.INSERT', 'key', 'NONSCALING', 'ITEMS', 'item']
4647
);
4748
});
4849

4950
it('with CAPACITY, ERROR, EXPANSION, NOCREATE and NONSCALING', () => {
5051
assert.deepEqual(
51-
INSERT.transformArguments('key', 'item', {
52+
parseArgs(INSERT, 'key', 'item', {
5253
CAPACITY: 100,
5354
ERROR: 0.01,
5455
EXPANSION: 1,
+13-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { CommandParser } from '@redis/client/dist/lib/client/parser';
12
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
2-
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
3+
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
34
import { transformBooleanArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
export interface BfInsertOptions {
@@ -11,37 +12,38 @@ export interface BfInsertOptions {
1112
}
1213

1314
export default {
14-
FIRST_KEY_INDEX: 1,
1515
IS_READ_ONLY: false,
16-
transformArguments(
16+
parseCommand(
17+
parser: CommandParser,
1718
key: RedisArgument,
1819
items: RedisVariadicArgument,
1920
options?: BfInsertOptions
2021
) {
21-
const args = ['BF.INSERT', key];
22+
parser.push('BF.INSERT');
23+
parser.pushKey(key);
2224

2325
if (options?.CAPACITY !== undefined) {
24-
args.push('CAPACITY', options.CAPACITY.toString());
26+
parser.push('CAPACITY', options.CAPACITY.toString());
2527
}
2628

2729
if (options?.ERROR !== undefined) {
28-
args.push('ERROR', options.ERROR.toString());
30+
parser.push('ERROR', options.ERROR.toString());
2931
}
3032

3133
if (options?.EXPANSION !== undefined) {
32-
args.push('EXPANSION', options.EXPANSION.toString());
34+
parser.push('EXPANSION', options.EXPANSION.toString());
3335
}
3436

3537
if (options?.NOCREATE) {
36-
args.push('NOCREATE');
38+
parser.push('NOCREATE');
3739
}
3840

3941
if (options?.NONSCALING) {
40-
args.push('NONSCALING');
42+
parser.push('NONSCALING');
4143
}
4244

43-
args.push('ITEMS');
44-
return pushVariadicArguments(args, items);
45+
parser.push('ITEMS');
46+
parser.pushVariadic(items);
4547
},
4648
transformReply: transformBooleanArrayReply
4749
} as const satisfies Command;

packages/bloom/lib/commands/bloom/LOADCHUNK.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import LOADCHUNK from './LOADCHUNK';
44
import { RESP_TYPES } from '@redis/client';
5+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
56

67
describe('BF.LOADCHUNK', () => {
78
it('transformArguments', () => {
89
assert.deepEqual(
9-
LOADCHUNK.transformArguments('key', 0, ''),
10+
parseArgs(LOADCHUNK, 'key', 0, ''),
1011
['BF.LOADCHUNK', 'key', '0', '']
1112
);
1213
});
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { CommandParser } from '@redis/client/dist/lib/client/parser';
12
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
23

34
export default {
4-
FIRST_KEY_INDEX: 1,
55
IS_READ_ONLY: false,
6-
transformArguments(key: RedisArgument, iterator: number, chunk: RedisArgument) {
7-
return ['BF.LOADCHUNK', key, iterator.toString(), chunk];
6+
parseCommand(parser: CommandParser, key: RedisArgument, iterator: number, chunk: RedisArgument) {
7+
parser.push('BF.LOADCHUNK');
8+
parser.pushKey(key);
9+
parser.push(iterator.toString(), chunk);
810
},
911
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
1012
} as const satisfies Command;

packages/bloom/lib/commands/bloom/MADD.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import MADD from './MADD';
4+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
describe('BF.MADD', () => {
67
it('transformArguments', () => {
78
assert.deepEqual(
8-
MADD.transformArguments('key', ['1', '2']),
9+
parseArgs(MADD, 'key', ['1', '2']),
910
['BF.MADD', 'key', '1', '2']
1011
);
1112
});
+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import { CommandParser } from '@redis/client/dist/lib/client/parser';
12
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
2-
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
3+
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
34
import { transformBooleanArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
export default {
6-
FIRST_KEY_INDEX: 1,
77
IS_READ_ONLY: false,
8-
transformArguments(key: RedisArgument, items: RedisVariadicArgument) {
9-
return pushVariadicArguments(['BF.MADD', key], items);
8+
parseCommand(parser: CommandParser, key: RedisArgument, items: RedisVariadicArgument) {
9+
parser.push('BF.MADD');
10+
parser.pushKey(key);
11+
parser.pushVariadic(items);
1012
},
1113
transformReply: transformBooleanArrayReply
1214
} as const satisfies Command;

packages/bloom/lib/commands/bloom/MEXISTS.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import MEXISTS from './MEXISTS';
4+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
describe('BF.MEXISTS', () => {
67
it('transformArguments', () => {
78
assert.deepEqual(
8-
MEXISTS.transformArguments('key', ['1', '2']),
9+
parseArgs(MEXISTS, 'key', ['1', '2']),
910
['BF.MEXISTS', 'key', '1', '2']
1011
);
1112
});
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import { CommandParser } from '@redis/client/dist/lib/client/parser';
12
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
2-
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
3+
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
34
import { transformBooleanArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
export default {
6-
FIRST_KEY_INDEX: 1,
77
IS_READ_ONLY: true,
8-
transformArguments(key: RedisArgument, items: RedisVariadicArgument) {
9-
return pushVariadicArguments(['BF.MEXISTS', key], items);
8+
parseCommand(parser: CommandParser, key: RedisArgument, items: RedisVariadicArgument) {
9+
parser.push('BF.MEXISTS');
10+
parser.pushKey(key);
11+
parser.pushVariadic(items);
1012
},
1113
transformReply: transformBooleanArrayReply
1214
} as const satisfies Command;

packages/bloom/lib/commands/bloom/RESERVE.spec.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../../test-utils';
33
import RESERVE from './RESERVE';
4+
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';
45

56
describe('BF.RESERVE', () => {
67
describe('transformArguments', () => {
78
it('simple', () => {
89
assert.deepEqual(
9-
RESERVE.transformArguments('key', 0.01, 100),
10+
parseArgs(RESERVE, 'key', 0.01, 100),
1011
['BF.RESERVE', 'key', '0.01', '100']
1112
);
1213
});
1314

1415
it('with EXPANSION', () => {
1516
assert.deepEqual(
16-
RESERVE.transformArguments('key', 0.01, 100, {
17+
parseArgs(RESERVE, 'key', 0.01, 100, {
1718
EXPANSION: 1
1819
}),
1920
['BF.RESERVE', 'key', '0.01', '100', 'EXPANSION', '1']
@@ -22,7 +23,7 @@ describe('BF.RESERVE', () => {
2223

2324
it('with NONSCALING', () => {
2425
assert.deepEqual(
25-
RESERVE.transformArguments('key', 0.01, 100, {
26+
parseArgs(RESERVE, 'key', 0.01, 100, {
2627
NONSCALING: true
2728
}),
2829
['BF.RESERVE', 'key', '0.01', '100', 'NONSCALING']
@@ -31,7 +32,7 @@ describe('BF.RESERVE', () => {
3132

3233
it('with EXPANSION and NONSCALING', () => {
3334
assert.deepEqual(
34-
RESERVE.transformArguments('key', 0.01, 100, {
35+
parseArgs(RESERVE, 'key', 0.01, 100, {
3536
EXPANSION: 1,
3637
NONSCALING: true
3738
}),

0 commit comments

Comments
 (0)