Skip to content

Commit fa77c07

Browse files
authoredJun 25, 2022
feat: add command typings for Redis 7.0.2. Also fix a typing issue for hgetallBuffer. (#1611)
1 parent 975336d commit fa77c07

8 files changed

+366
-411
lines changed
 

‎bin/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
const returnTypes = require("./returnTypes");
22
const argumentTypes = require("./argumentTypes");
3+
const sortArguments = require("./sortArguments");
34
const typeMaps = require("./typeMaps");
45
const overrides = require("./overrides");
56
const { getCommanderInterface } = require("@ioredis/interface-generator");
67

8+
const HEADER = `/**
9+
* This file is generated by @ioredis/interface-generator.
10+
* Don't edit it manually. Instead, run \`npm run generate\` to update
11+
* this file.
12+
*/
13+
14+
`;
15+
716
const ignoredCommands = ["monitor", "multi"];
817
const commands = require("@ioredis/commands")
918
.list.filter((name) => !ignoredCommands.includes(name))
@@ -24,6 +33,7 @@ async function main() {
2433
overrides,
2534
returnTypes,
2635
argumentTypes,
36+
sortArguments,
2737
typeMaps: typeMaps,
2838
ignoredBufferVariant: [
2939
"incrbyfloat",
@@ -39,7 +49,7 @@ async function main() {
3949

4050
fs.writeFileSync(
4151
path.join(__dirname, "..", "lib/utils/RedisCommander.ts"),
42-
template.replace("////", () => interface)
52+
HEADER + template.replace("////", () => interface)
4353
);
4454
}
4555

‎bin/overrides.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
overwrite: true,
1212
defs: [
1313
"$1(key: RedisKey, callback?: Callback<Record<string, string>>): Result<Record<string, string>, Context>",
14-
"$1Buffer(key: RedisKey, callback?: Callback<[field: Buffer, value: Buffer][]>): Result<[field: Buffer, value: Buffer][], Context>",
14+
"$1Buffer(key: RedisKey, callback?: Callback<Record<string, Buffer>>): Result<Record<string, Buffer>, Context>",
1515
],
1616
},
1717
mset: msetOverrides,

‎bin/sortArguments.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
set: (args) => {
3+
const sorted = args.sort((a, b) => {
4+
const order = ["key", "value", "expiration", "condition", "get"];
5+
const indexA = order.indexOf(a.name);
6+
const indexB = order.indexOf(b.name);
7+
if (indexA === -1) {
8+
throw new Error('Invalid argument name: "' + a.name + '"');
9+
}
10+
if (indexB === -1) {
11+
throw new Error('Invalid argument name: "' + b.name + '"');
12+
}
13+
return indexA - indexB;
14+
});
15+
return sorted;
16+
},
17+
};

‎bin/template.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export interface ResultTypes<Result, Context> {
1111
pipeline: ChainableCommander;
1212
}
1313

14-
export interface ChainableCommander extends RedisCommander<{ type: "pipeline" }> {
14+
export interface ChainableCommander
15+
extends RedisCommander<{ type: "pipeline" }> {
1516
length: number;
1617
}
1718

0 commit comments

Comments
 (0)
Please sign in to comment.