Skip to content

Commit

Permalink
feat: add command typings for Redis 7.0.2. Also fix a typing issue fo…
Browse files Browse the repository at this point in the history
…r hgetallBuffer. (#1611)
  • Loading branch information
luin committed Jun 25, 2022
1 parent 975336d commit fa77c07
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 411 deletions.
12 changes: 11 additions & 1 deletion bin/index.js
@@ -1,9 +1,18 @@
const returnTypes = require("./returnTypes");
const argumentTypes = require("./argumentTypes");
const sortArguments = require("./sortArguments");
const typeMaps = require("./typeMaps");
const overrides = require("./overrides");
const { getCommanderInterface } = require("@ioredis/interface-generator");

const HEADER = `/**
* This file is generated by @ioredis/interface-generator.
* Don't edit it manually. Instead, run \`npm run generate\` to update
* this file.
*/
`;

const ignoredCommands = ["monitor", "multi"];
const commands = require("@ioredis/commands")
.list.filter((name) => !ignoredCommands.includes(name))
Expand All @@ -24,6 +33,7 @@ async function main() {
overrides,
returnTypes,
argumentTypes,
sortArguments,
typeMaps: typeMaps,
ignoredBufferVariant: [
"incrbyfloat",
Expand All @@ -39,7 +49,7 @@ async function main() {

fs.writeFileSync(
path.join(__dirname, "..", "lib/utils/RedisCommander.ts"),
template.replace("////", () => interface)
HEADER + template.replace("////", () => interface)
);
}

Expand Down
2 changes: 1 addition & 1 deletion bin/overrides.js
Expand Up @@ -11,7 +11,7 @@ module.exports = {
overwrite: true,
defs: [
"$1(key: RedisKey, callback?: Callback<Record<string, string>>): Result<Record<string, string>, Context>",
"$1Buffer(key: RedisKey, callback?: Callback<[field: Buffer, value: Buffer][]>): Result<[field: Buffer, value: Buffer][], Context>",
"$1Buffer(key: RedisKey, callback?: Callback<Record<string, Buffer>>): Result<Record<string, Buffer>, Context>",
],
},
mset: msetOverrides,
Expand Down
17 changes: 17 additions & 0 deletions bin/sortArguments.js
@@ -0,0 +1,17 @@
module.exports = {
set: (args) => {
const sorted = args.sort((a, b) => {
const order = ["key", "value", "expiration", "condition", "get"];
const indexA = order.indexOf(a.name);
const indexB = order.indexOf(b.name);
if (indexA === -1) {
throw new Error('Invalid argument name: "' + a.name + '"');
}
if (indexB === -1) {
throw new Error('Invalid argument name: "' + b.name + '"');
}
return indexA - indexB;
});
return sorted;
},
};
3 changes: 2 additions & 1 deletion bin/template.ts
Expand Up @@ -11,7 +11,8 @@ export interface ResultTypes<Result, Context> {
pipeline: ChainableCommander;
}

export interface ChainableCommander extends RedisCommander<{ type: "pipeline" }> {
export interface ChainableCommander
extends RedisCommander<{ type: "pipeline" }> {
length: number;
}

Expand Down

0 comments on commit fa77c07

Please sign in to comment.