Skip to content

Commit

Permalink
Add all commands to new parser syntax for basic/graph/json
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter committed Apr 4, 2024
1 parent 657167c commit 93f897d
Show file tree
Hide file tree
Showing 733 changed files with 4,023 additions and 2,564 deletions.
16 changes: 13 additions & 3 deletions packages/client/lib/client/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RedisArgument, RespVersions } from "../..";
import { RedisArgument, RespVersions } from "../RESP/types";
import { RedisVariadicArgument } from "../commands/generic-transformers";

export interface CommandParser {
Expand All @@ -8,9 +8,10 @@ export interface CommandParser {
respVersion: RespVersions;
preserve: unknown;
cachable: boolean;

push: (arg: RedisArgument) => unknown;
pushVariadic: (vals: RedisVariadicArgument) => unknown;
pushVariadicWithLength: (vals: RedisVariadicArgument) => unknown;
pushVariadicNumber: (vals: number | Array<number>) => unknown;
pushKey: (key: RedisArgument) => unknown; // normal push of keys
pushKeys: (keys: RedisVariadicArgument) => unknown; // push multiple keys at a time
Expand Down Expand Up @@ -68,6 +69,15 @@ export class BasicCommandParser implements CommandParser {
}
}

pushVariadicWithLength(vals: RedisVariadicArgument) {
if (Array.isArray(vals)) {
this.#redisArgs.push(vals.length.toString());
} else {
this.#redisArgs.push('1');
}
this.pushVariadic(vals);
}

pushVariadicNumber(vals: number | number[]) {
if (Array.isArray(vals)) {
for (const val of vals) {
Expand Down Expand Up @@ -109,4 +119,4 @@ export class BasicCommandParser implements CommandParser {
setCachable() {
this.#cachable = true;
};
}
}
5 changes: 3 additions & 2 deletions packages/client/lib/commands/ACL_CAT.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import { parseArgs } from './generic-transformers';
import ACL_CAT from './ACL_CAT';

describe('ACL CAT', () => {
Expand All @@ -8,14 +9,14 @@ describe('ACL CAT', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
ACL_CAT.transformArguments(),
parseArgs(ACL_CAT),
['ACL', 'CAT']
);
});

it('with categoryName', () => {
assert.deepEqual(
ACL_CAT.transformArguments('dangerous'),
parseArgs(ACL_CAT, 'dangerous'),
['ACL', 'CAT', 'dangerous']
);
});
Expand Down
11 changes: 5 additions & 6 deletions packages/client/lib/commands/ACL_CAT.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
import { CommandParser } from '../client/parser';

export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(categoryName?: RedisArgument) {
const args: Array<RedisArgument> = ['ACL', 'CAT'];

parseCommand(parser: CommandParser, categoryName?: RedisArgument) {
parser.pushVariadic(['ACL', 'CAT']);
if (categoryName) {
args.push(categoryName);
parser.push(categoryName);
}

return args;
},
transformArguments(categoryName?: RedisArgument) { return [] },
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
} as const satisfies Command;
5 changes: 3 additions & 2 deletions packages/client/lib/commands/ACL_DELUSER.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ACL_DELUSER from './ACL_DELUSER';
import { parseArgs } from './generic-transformers';

describe('ACL DELUSER', () => {
testUtils.isVersionGreaterThanHook([6]);

describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
ACL_DELUSER.transformArguments('username'),
parseArgs(ACL_DELUSER, 'username'),
['ACL', 'DELUSER', 'username']
);
});

it('array', () => {
assert.deepEqual(
ACL_DELUSER.transformArguments(['1', '2']),
parseArgs(ACL_DELUSER, ['1', '2']),
['ACL', 'DELUSER', '1', '2']
);
});
Expand Down
9 changes: 6 additions & 3 deletions packages/client/lib/commands/ACL_DELUSER.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { NumberReply, Command } from '../RESP/types';
import { RedisVariadicArgument, pushVariadicArguments } from './generic-transformers';
import { CommandParser } from '../client/parser';
import { RedisVariadicArgument } from './generic-transformers';

export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(username: RedisVariadicArgument) {
return pushVariadicArguments(['ACL', 'DELUSER'], username);
parseCommand(parser: CommandParser, username: RedisVariadicArgument) {
parser.pushVariadic(['ACL', 'DELUSER']);
parser.pushVariadic(username);
},
transformArguments(username: RedisVariadicArgument) { return []; },
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;
3 changes: 2 additions & 1 deletion packages/client/lib/commands/ACL_DRYRUN.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ACL_DRYRUN from './ACL_DRYRUN';
import { parseArgs } from './generic-transformers';

describe('ACL DRYRUN', () => {
testUtils.isVersionGreaterThanHook([7]);

it('transformArguments', () => {
assert.deepEqual(
ACL_DRYRUN.transformArguments('default', ['GET', 'key']),
parseArgs(ACL_DRYRUN, 'default', ['GET', 'key']),
['ACL', 'DRYRUN', 'default', 'GET', 'key']
);
});
Expand Down
11 changes: 4 additions & 7 deletions packages/client/lib/commands/ACL_DRYRUN.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { RedisArgument, SimpleStringReply, BlobStringReply, Command } from '../RESP/types';
import { CommandParser } from '../client/parser';

export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(username: RedisArgument, command: Array<RedisArgument>) {
return [
'ACL',
'DRYRUN',
username,
...command
];
parseCommand(parser: CommandParser, username: RedisArgument, command: Array<RedisArgument>) {
parser.pushVariadic(['ACL', 'DRYRUN', username, ...command]);
},
transformArguments(username: RedisArgument, command: Array<RedisArgument>) { return [] },
transformReply: undefined as unknown as () => SimpleStringReply<'OK'> | BlobStringReply
} as const satisfies Command;

5 changes: 3 additions & 2 deletions packages/client/lib/commands/ACL_GENPASS.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ACL_GENPASS from './ACL_GENPASS';
import { parseArgs } from './generic-transformers';

describe('ACL GENPASS', () => {
testUtils.isVersionGreaterThanHook([6]);

describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
ACL_GENPASS.transformArguments(),
parseArgs(ACL_GENPASS),
['ACL', 'GENPASS']
);
});

it('with bits', () => {
assert.deepEqual(
ACL_GENPASS.transformArguments(128),
parseArgs(ACL_GENPASS, 128),
['ACL', 'GENPASS', '128']
);
});
Expand Down
11 changes: 5 additions & 6 deletions packages/client/lib/commands/ACL_GENPASS.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { BlobStringReply, Command } from '../RESP/types';
import { CommandParser } from '../client/parser';

export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(bits?: number) {
const args = ['ACL', 'GENPASS'];

parseCommand(parser: CommandParser, bits?: number) {
parser.pushVariadic(['ACL', 'GENPASS']);
if (bits) {
args.push(bits.toString());
parser.push(bits.toString());
}

return args;
},
transformArguments(bits?: number) { return [] },
transformReply: undefined as unknown as () => BlobStringReply
} as const satisfies Command;

3 changes: 2 additions & 1 deletion packages/client/lib/commands/ACL_GETUSER.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ACL_GETUSER from './ACL_GETUSER';
import { parseArgs } from './generic-transformers';

describe('ACL GETUSER', () => {
testUtils.isVersionGreaterThanHook([6]);

it('transformArguments', () => {
assert.deepEqual(
ACL_GETUSER.transformArguments('username'),
parseArgs(ACL_GETUSER, 'username'),
['ACL', 'GETUSER', 'username']
);
});
Expand Down
6 changes: 4 additions & 2 deletions packages/client/lib/commands/ACL_GETUSER.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RedisArgument, TuplesToMapReply, BlobStringReply, ArrayReply, UnwrapReply, Resp2Reply, Command } from '../RESP/types';
import { CommandParser } from '../client/parser';

type AclUser = TuplesToMapReply<[
[BlobStringReply<'flags'>, ArrayReply<BlobStringReply>],
Expand All @@ -19,9 +20,10 @@ type AclUser = TuplesToMapReply<[
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(username: RedisArgument) {
return ['ACL', 'GETUSER', username];
parseCommand(parser: CommandParser, username: RedisArgument) {
parser.pushVariadic(['ACL', 'GETUSER', username]);
},
transformArguments(username: RedisArgument) { return [] },
transformReply: {
2: (reply: UnwrapReply<Resp2Reply<AclUser>>) => ({
flags: reply[1],
Expand Down
3 changes: 2 additions & 1 deletion packages/client/lib/commands/ACL_LIST.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ACL_LIST from './ACL_LIST';
import { parseArgs } from './generic-transformers';

describe('ACL LIST', () => {
testUtils.isVersionGreaterThanHook([6]);

it('transformArguments', () => {
assert.deepEqual(
ACL_LIST.transformArguments(),
parseArgs(ACL_LIST),
['ACL', 'LIST']
);
});
Expand Down
6 changes: 4 additions & 2 deletions packages/client/lib/commands/ACL_LIST.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ArrayReply, BlobStringReply, Command } from '../RESP/types';
import { CommandParser } from '../client/parser';

export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments() {
return ['ACL', 'LIST'];
parseCommand(parser: CommandParser) {
parser.pushVariadic(['ACL', 'LIST']);
},
transformArguments() { return [] },
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
} as const satisfies Command;
3 changes: 2 additions & 1 deletion packages/client/lib/commands/ACL_LOAD.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { strict as assert } from 'node:assert';
import testUtils from '../test-utils';
import ACL_LOAD from './ACL_LOAD';
import { parseArgs } from './generic-transformers';

describe('ACL LOAD', () => {
testUtils.isVersionGreaterThanHook([6]);

it('transformArguments', () => {
assert.deepEqual(
ACL_LOAD.transformArguments(),
parseArgs(ACL_LOAD),
['ACL', 'LOAD']
);
});
Expand Down
6 changes: 4 additions & 2 deletions packages/client/lib/commands/ACL_LOAD.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { SimpleStringReply, Command } from '../RESP/types';
import { CommandParser } from '../client/parser';

export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments() {
return ['ACL', 'LOAD'];
parseCommand(parser: CommandParser) {
parser.pushVariadic(['ACL', 'LOAD']);
},
transformArguments() { return [] },
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command;
5 changes: 3 additions & 2 deletions packages/client/lib/commands/ACL_LOG.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ACL_LOG from './ACL_LOG';
import { parseArgs } from './generic-transformers';

describe('ACL LOG', () => {
testUtils.isVersionGreaterThanHook([6]);

describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
ACL_LOG.transformArguments(),
parseArgs(ACL_LOG),
['ACL', 'LOG']
);
});

it('with count', () => {
assert.deepEqual(
ACL_LOG.transformArguments(10),
parseArgs(ACL_LOG, 10),
['ACL', 'LOG', '10']
);
});
Expand Down
13 changes: 6 additions & 7 deletions packages/client/lib/commands/ACL_LOG.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ArrayReply, TuplesToMapReply, BlobStringReply, NumberReply, DoubleReply, UnwrapReply, Resp2Reply, Command } from '../RESP/types';
import { CommandParser } from '../client/parser';

export type AclLogReply = ArrayReply<TuplesToMapReply<[
[BlobStringReply<'count'>, NumberReply],
Expand All @@ -19,15 +20,13 @@ export type AclLogReply = ArrayReply<TuplesToMapReply<[
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(count?: number) {
const args = ['ACL', 'LOG'];

if (count !== undefined) {
args.push(count.toString());
parseCommand(parser: CommandParser, count?: number) {
parser.pushVariadic(['ACL', 'LOG']);
if (count != undefined) {
parser.push(count.toString());
}

return args;
},
transformArguments(count?: number) { return [] },
transformReply: {
2: (reply: UnwrapReply<Resp2Reply<AclLogReply>>) => {
return reply.map(item => {
Expand Down
3 changes: 2 additions & 1 deletion packages/client/lib/commands/ACL_LOG_RESET.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ACL_LOG_RESET from './ACL_LOG_RESET';
import { parseArgs } from './generic-transformers';

describe('ACL LOG RESET', () => {
testUtils.isVersionGreaterThanHook([6]);

it('transformArguments', () => {
assert.deepEqual(
ACL_LOG_RESET.transformArguments(),
parseArgs(ACL_LOG_RESET),
['ACL', 'LOG', 'RESET']
);
});
Expand Down
6 changes: 4 additions & 2 deletions packages/client/lib/commands/ACL_LOG_RESET.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { SimpleStringReply, Command } from '../RESP/types';
import { CommandParser } from '../client/parser';
import ACL_LOG from './ACL_LOG';

export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: ACL_LOG.IS_READ_ONLY,
transformArguments() {
return ['ACL', 'LOG', 'RESET'];
parseCommand(parser: CommandParser) {
parser.pushVariadic(['ACL', 'LOG', 'RESET']);
},
transformArguments() { return [] },
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command;
Loading

0 comments on commit 93f897d

Please sign in to comment.