Skip to content

Commit

Permalink
Parser support with all commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter committed Oct 15, 2024
1 parent 5ace34b commit c39f377
Show file tree
Hide file tree
Showing 1,005 changed files with 5,402 additions and 4,558 deletions.
3 changes: 2 additions & 1 deletion packages/bloom/lib/commands/bloom/ADD.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import ADD from './ADD';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.ADD', () => {
it('transformArguments', () => {
assert.deepEqual(
ADD.transformArguments('key', 'item'),
parseArgs(ADD, 'key', 'item'),
['BF.ADD', 'key', 'item']
);
});
Expand Down
8 changes: 5 additions & 3 deletions packages/bloom/lib/commands/bloom/ADD.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import { transformBooleanReply } from '@redis/client/dist/lib/commands/generic-transformers';

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, item: RedisArgument) {
return ['BF.ADD', key, item];
parseCommand(parser: CommandParser, key: RedisArgument, item: RedisArgument) {
parser.push('BF.ADD');
parser.pushKey(key);
parser.push(item);
},
transformReply: transformBooleanReply
} as const satisfies Command;
3 changes: 2 additions & 1 deletion packages/bloom/lib/commands/bloom/CARD.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import CARD from './CARD';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.CARD', () => {
it('transformArguments', () => {
assert.deepEqual(
CARD.transformArguments('bloom'),
parseArgs(CARD, 'bloom'),
['BF.CARD', 'bloom']
);
});
Expand Down
7 changes: 4 additions & 3 deletions packages/bloom/lib/commands/bloom/CARD.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument) {
return ['BF.CARD', key];
parseCommand(parser: CommandParser, key: RedisArgument) {
parser.push('BF.CARD');
parser.pushKey(key);
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;
3 changes: 2 additions & 1 deletion packages/bloom/lib/commands/bloom/EXISTS.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import EXISTS from './EXISTS';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.EXISTS', () => {
it('transformArguments', () => {
assert.deepEqual(
EXISTS.transformArguments('key', 'item'),
parseArgs(EXISTS, 'key', 'item'),
['BF.EXISTS', 'key', 'item']
);
});
Expand Down
8 changes: 5 additions & 3 deletions packages/bloom/lib/commands/bloom/EXISTS.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import { transformBooleanReply } from '@redis/client/dist/lib/commands/generic-transformers';

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument, item: RedisArgument) {
return ['BF.EXISTS', key, item];
parseCommand(parser: CommandParser, key: RedisArgument, item: RedisArgument) {
parser.push('BF.EXISTS');
parser.pushKey(key);
parser.push(item);
},
transformReply: transformBooleanReply
} as const satisfies Command;
3 changes: 2 additions & 1 deletion packages/bloom/lib/commands/bloom/INFO.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import INFO from './INFO';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.INFO', () => {
it('transformArguments', () => {
assert.deepEqual(
INFO.transformArguments('bloom'),
parseArgs(INFO, 'bloom'),
['BF.INFO', 'bloom']
);
});
Expand Down
15 changes: 4 additions & 11 deletions packages/bloom/lib/commands/bloom/INFO.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command, UnwrapReply, NullReply, NumberReply, TuplesToMapReply, Resp2Reply, SimpleStringReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
import { transformInfoV2Reply } from '.';

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

export interface BfInfoReply {
capacity: NumberReply;
size: NumberReply;
numberOfFilters: NumberReply;
numberOfInsertedItems: NumberReply;
expansionRate: NullReply | NumberReply;
}

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument) {
return ['BF.INFO', key];
parseCommand(parser: CommandParser, key: RedisArgument) {
parser.push('BF.INFO');
parser.pushKey(key);
},
transformReply: {
2: (reply: UnwrapReply<Resp2Reply<BfInfoReplyMap>>, _, typeMapping?: TypeMapping): BfInfoReplyMap => {
Expand Down
15 changes: 8 additions & 7 deletions packages/bloom/lib/commands/bloom/INSERT.spec.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import INSERT from './INSERT';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.INSERT', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
INSERT.transformArguments('key', 'item'),
parseArgs(INSERT, 'key', 'item'),
['BF.INSERT', 'key', 'ITEMS', 'item']
);
});

it('with CAPACITY', () => {
assert.deepEqual(
INSERT.transformArguments('key', 'item', { CAPACITY: 100 }),
parseArgs(INSERT, 'key', 'item', { CAPACITY: 100 }),
['BF.INSERT', 'key', 'CAPACITY', '100', 'ITEMS', 'item']
);
});

it('with ERROR', () => {
assert.deepEqual(
INSERT.transformArguments('key', 'item', { ERROR: 0.01 }),
parseArgs(INSERT, 'key', 'item', { ERROR: 0.01 }),
['BF.INSERT', 'key', 'ERROR', '0.01', 'ITEMS', 'item']
);
});

it('with EXPANSION', () => {
assert.deepEqual(
INSERT.transformArguments('key', 'item', { EXPANSION: 1 }),
parseArgs(INSERT, 'key', 'item', { EXPANSION: 1 }),
['BF.INSERT', 'key', 'EXPANSION', '1', 'ITEMS', 'item']
);
});

it('with NOCREATE', () => {
assert.deepEqual(
INSERT.transformArguments('key', 'item', { NOCREATE: true }),
parseArgs(INSERT, 'key', 'item', { NOCREATE: true }),
['BF.INSERT', 'key', 'NOCREATE', 'ITEMS', 'item']
);
});

it('with NONSCALING', () => {
assert.deepEqual(
INSERT.transformArguments('key', 'item', { NONSCALING: true }),
parseArgs(INSERT, 'key', 'item', { NONSCALING: true }),
['BF.INSERT', 'key', 'NONSCALING', 'ITEMS', 'item']
);
});

it('with CAPACITY, ERROR, EXPANSION, NOCREATE and NONSCALING', () => {
assert.deepEqual(
INSERT.transformArguments('key', 'item', {
parseArgs(INSERT, 'key', 'item', {
CAPACITY: 100,
ERROR: 0.01,
EXPANSION: 1,
Expand Down
24 changes: 13 additions & 11 deletions packages/bloom/lib/commands/bloom/INSERT.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
import { transformBooleanArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';

export interface BfInsertOptions {
Expand All @@ -11,37 +12,38 @@ export interface BfInsertOptions {
}

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(
parseCommand(
parser: CommandParser,
key: RedisArgument,
items: RedisVariadicArgument,
options?: BfInsertOptions
) {
const args = ['BF.INSERT', key];
parser.push('BF.INSERT');
parser.pushKey(key);

if (options?.CAPACITY !== undefined) {
args.push('CAPACITY', options.CAPACITY.toString());
parser.push('CAPACITY', options.CAPACITY.toString());
}

if (options?.ERROR !== undefined) {
args.push('ERROR', options.ERROR.toString());
parser.push('ERROR', options.ERROR.toString());
}

if (options?.EXPANSION !== undefined) {
args.push('EXPANSION', options.EXPANSION.toString());
parser.push('EXPANSION', options.EXPANSION.toString());
}

if (options?.NOCREATE) {
args.push('NOCREATE');
parser.push('NOCREATE');
}

if (options?.NONSCALING) {
args.push('NONSCALING');
parser.push('NONSCALING');
}

args.push('ITEMS');
return pushVariadicArguments(args, items);
parser.push('ITEMS');
parser.pushVariadic(items);
},
transformReply: transformBooleanArrayReply
} as const satisfies Command;
3 changes: 2 additions & 1 deletion packages/bloom/lib/commands/bloom/LOADCHUNK.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import LOADCHUNK from './LOADCHUNK';
import { RESP_TYPES } from '@redis/client';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.LOADCHUNK', () => {
it('transformArguments', () => {
assert.deepEqual(
LOADCHUNK.transformArguments('key', 0, ''),
parseArgs(LOADCHUNK, 'key', 0, ''),
['BF.LOADCHUNK', 'key', '0', '']
);
});
Expand Down
8 changes: 5 additions & 3 deletions packages/bloom/lib/commands/bloom/LOADCHUNK.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, iterator: number, chunk: RedisArgument) {
return ['BF.LOADCHUNK', key, iterator.toString(), chunk];
parseCommand(parser: CommandParser, key: RedisArgument, iterator: number, chunk: RedisArgument) {
parser.push('BF.LOADCHUNK');
parser.pushKey(key);
parser.push(iterator.toString(), chunk);
},
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command;
3 changes: 2 additions & 1 deletion packages/bloom/lib/commands/bloom/MADD.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import MADD from './MADD';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.MADD', () => {
it('transformArguments', () => {
assert.deepEqual(
MADD.transformArguments('key', ['1', '2']),
parseArgs(MADD, 'key', ['1', '2']),
['BF.MADD', 'key', '1', '2']
);
});
Expand Down
10 changes: 6 additions & 4 deletions packages/bloom/lib/commands/bloom/MADD.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
import { transformBooleanArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, items: RedisVariadicArgument) {
return pushVariadicArguments(['BF.MADD', key], items);
parseCommand(parser: CommandParser, key: RedisArgument, items: RedisVariadicArgument) {
parser.push('BF.MADD');
parser.pushKey(key);
parser.pushVariadic(items);
},
transformReply: transformBooleanArrayReply
} as const satisfies Command;
3 changes: 2 additions & 1 deletion packages/bloom/lib/commands/bloom/MEXISTS.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import MEXISTS from './MEXISTS';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.MEXISTS', () => {
it('transformArguments', () => {
assert.deepEqual(
MEXISTS.transformArguments('key', ['1', '2']),
parseArgs(MEXISTS, 'key', ['1', '2']),
['BF.MEXISTS', 'key', '1', '2']
);
});
Expand Down
10 changes: 6 additions & 4 deletions packages/bloom/lib/commands/bloom/MEXISTS.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
import { transformBooleanArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument, items: RedisVariadicArgument) {
return pushVariadicArguments(['BF.MEXISTS', key], items);
parseCommand(parser: CommandParser, key: RedisArgument, items: RedisVariadicArgument) {
parser.push('BF.MEXISTS');
parser.pushKey(key);
parser.pushVariadic(items);
},
transformReply: transformBooleanArrayReply
} as const satisfies Command;
9 changes: 5 additions & 4 deletions packages/bloom/lib/commands/bloom/RESERVE.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../../test-utils';
import RESERVE from './RESERVE';
import { parseArgs } from '@redis/client/dist/lib/commands/generic-transformers';

describe('BF.RESERVE', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
RESERVE.transformArguments('key', 0.01, 100),
parseArgs(RESERVE, 'key', 0.01, 100),
['BF.RESERVE', 'key', '0.01', '100']
);
});

it('with EXPANSION', () => {
assert.deepEqual(
RESERVE.transformArguments('key', 0.01, 100, {
parseArgs(RESERVE, 'key', 0.01, 100, {
EXPANSION: 1
}),
['BF.RESERVE', 'key', '0.01', '100', 'EXPANSION', '1']
Expand All @@ -22,7 +23,7 @@ describe('BF.RESERVE', () => {

it('with NONSCALING', () => {
assert.deepEqual(
RESERVE.transformArguments('key', 0.01, 100, {
parseArgs(RESERVE, 'key', 0.01, 100, {
NONSCALING: true
}),
['BF.RESERVE', 'key', '0.01', '100', 'NONSCALING']
Expand All @@ -31,7 +32,7 @@ describe('BF.RESERVE', () => {

it('with EXPANSION and NONSCALING', () => {
assert.deepEqual(
RESERVE.transformArguments('key', 0.01, 100, {
parseArgs(RESERVE, 'key', 0.01, 100, {
EXPANSION: 1,
NONSCALING: true
}),
Expand Down
Loading

0 comments on commit c39f377

Please sign in to comment.