-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
12,661 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
node_modules | ||
*.cpuprofile | ||
/test.js | ||
/test.* | ||
/.idea | ||
built | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const typeMaps = require("./typeMaps"); | ||
|
||
module.exports = { | ||
debug: [ | ||
[{ name: "subcommand", type: "string" }], | ||
[ | ||
{ name: "subcommand", type: "string" }, | ||
{ name: "args", type: typeMaps.string, multiple: true }, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const returnTypes = require("./returnTypes"); | ||
const argumentTypes = require("./argumentTypes"); | ||
const typeMaps = require("./typeMaps"); | ||
const { getCommanderInterface } = require("ioredis-interface-generator"); | ||
|
||
const ignoredCommands = ["monitor", "multi"]; | ||
const commands = require("redis-commands").list.filter( | ||
(name) => !ignoredCommands.includes(name) | ||
); | ||
|
||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const template = fs.readFileSync(path.join(__dirname, "/template.ts"), "utf8"); | ||
|
||
async function main() { | ||
const interface = await getCommanderInterface({ | ||
commands, | ||
complexityLimit: 50, | ||
redisOpts: { | ||
port: process.env.REDIS_PORT, | ||
}, | ||
returnTypes, | ||
argumentTypes, | ||
typeMaps: typeMaps, | ||
}); | ||
|
||
fs.writeFileSync( | ||
path.join(__dirname, "..", "..", "lib/utils/RedisCommander.ts"), | ||
template.replace("////", () => interface) | ||
); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.then(() => process.exit(0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
module.exports = { | ||
multi: "ChainableCommander", | ||
get: "string | null", | ||
set: (types) => { | ||
if (types.find((type) => type.includes("GET"))) { | ||
return "string | null"; | ||
} | ||
if (types.find((type) => type.includes("NX") || type.includes("XX"))) { | ||
return "'OK' | null"; | ||
} | ||
return "'OK'"; | ||
}, | ||
ping: (types) => { | ||
return types.length ? "string" : "'PONG'"; | ||
}, | ||
append: "number", | ||
asking: "'OK'", | ||
auth: "'OK'", | ||
bgrewriteaof: "string", | ||
bgsave: "'OK'", | ||
bitcount: "number", | ||
bitfield_ro: "unknown[]", | ||
bitop: "number", | ||
bitpos: "number", | ||
blpop: "[string, string] | null", | ||
brpop: "[string, string] | null", | ||
brpoplpush: "string | null", | ||
blmove: "string | null", | ||
lmpop: "unknown[] | null", | ||
blmpop: "unknown[] | null", | ||
bzpopmin: "unknown[] | null", | ||
bzpopmax: "unknown[] | null", | ||
command: "unknown[]", | ||
copy: "number", | ||
dbsize: "number", | ||
decr: "number", | ||
decrby: "number", | ||
del: "number", | ||
discard: "'OK'", | ||
dump: "string", | ||
echo: "string", | ||
exec: "[error: Error, result: unknown][] | null", | ||
exists: "number", | ||
expire: "number", | ||
expireat: "number", | ||
expiretime: "number", | ||
failover: "'OK'", | ||
flushall: "'OK'", | ||
flushdb: "'OK'", | ||
geoadd: "number", | ||
geohash: "string[]", | ||
geopos: "unknown[] | null", | ||
geodist: "string | null", | ||
georadius: "unknown[]", | ||
geosearch: "unknown[]", | ||
geosearchstore: "number", | ||
getbit: "number", | ||
getdel: "string | null", | ||
getex: "string | null", | ||
getrange: "string", | ||
getset: "string | null", | ||
hdel: "number", | ||
hello: "unknown[]", | ||
hexists: "number", | ||
hget: "string | null", | ||
hincrby: "number", | ||
hincrbyfloat: "string", | ||
hkeys: "string[]", | ||
hlen: "number", | ||
hmget: "(string | null)[]", | ||
hmset: "'OK'", | ||
hset: "number", | ||
hsetnx: "number", | ||
hrandfield: "string | unknown[] | null", | ||
hstrlen: "number", | ||
hvals: "string[]", | ||
incr: "number", | ||
incrby: "number", | ||
incrbyfloat: "string", | ||
info: "string", | ||
lolwut: "string", | ||
keys: "string[]", | ||
lastsave: "number", | ||
lindex: "string | null", | ||
linsert: "number", | ||
llen: "number", | ||
lpop: "string" | "unknown[] | null", | ||
lpos: null, | ||
lpush: "number", | ||
lpushx: "number", | ||
lrange: "string[]", | ||
lrem: "number", | ||
lset: "'OK'", | ||
ltrim: "'OK'", | ||
mget: "(string | null)[]", | ||
migrate: "'OK'", | ||
move: "number", | ||
mset: "'OK'", | ||
msetnx: "number", | ||
persist: "number", | ||
pexpire: "number", | ||
pexpireat: "number", | ||
pexpiretime: "number", | ||
pfadd: "number", | ||
pfcount: "number", | ||
pfmerge: "'OK'", | ||
pubsub: "unknown[]", | ||
pttl: "number", | ||
publish: "number", | ||
quit: "'OK'", | ||
randomkey: "string | null", | ||
readonly: "'OK'", | ||
readwrite: "'OK'", | ||
rename: "'OK'", | ||
renamenx: "number", | ||
reset: "'OK'", | ||
restore: "'OK'", | ||
role: "unknown[]", | ||
rpop: "string" | "unknown[] | null", | ||
rpoplpush: "string", | ||
lmove: "string", | ||
rpush: "number", | ||
rpushx: "number", | ||
sadd: "number", | ||
save: "'OK'", | ||
scard: "number", | ||
sdiff: "string[]", | ||
sdiffstore: "number", | ||
select: "'OK'", | ||
setbit: "number", | ||
setex: "'OK'", | ||
setnx: "number", | ||
setrange: "number", | ||
shutdown: "'OK'", | ||
sinter: "string[]", | ||
sintercard: "number", | ||
sinterstore: "number", | ||
sismember: "number", | ||
smismember: "unknown[]", | ||
slaveof: "'OK'", | ||
replicaof: "'OK'", | ||
smembers: "string[]", | ||
smove: "number", | ||
sort: "number" | "unknown[]", | ||
sortRo: "unknown[]", | ||
spop: (types) => (types.length > 1 ? "string[]" : "string | null"), | ||
srandmember: "string" | "unknown[] | null", | ||
srem: "number", | ||
strlen: "number", | ||
sunion: "string[]", | ||
sunionstore: "number", | ||
swapdb: "'OK'", | ||
time: "number[]", | ||
touch: "number", | ||
ttl: "number", | ||
type: "string", | ||
unlink: "number", | ||
unwatch: "'OK'", | ||
wait: "number", | ||
watch: "'OK'", | ||
zadd: (types) => { | ||
if (types.find((type) => type.includes("INCR"))) { | ||
if (types.find((type) => type.includes("XX") || type.includes("NX"))) { | ||
return "string | null"; | ||
} | ||
return "string"; | ||
} | ||
return "number"; | ||
}, | ||
zcard: "number", | ||
zcount: "number", | ||
zdiff: "string[]", | ||
zdiffstore: "number", | ||
zincrby: "string", | ||
zinter: "string[]", | ||
zintercard: "number", | ||
zinterstore: "number", | ||
zlexcount: "number", | ||
zpopmax: "string[]", | ||
zpopmin: "string[]", | ||
zrandmember: (types) => { | ||
return types.includes("number") ? "string | null" : "string[]"; | ||
}, | ||
zrangestore: "number", | ||
zrange: "string[]", | ||
zrangebylex: "string[]", | ||
zrevrangebylex: "string[]", | ||
zrangebyscore: "string[]", | ||
zrank: "number | null", | ||
zrem: "number", | ||
zremrangebylex: "number", | ||
zremrangebyrank: "number", | ||
zremrangebyscore: "number", | ||
zrevrange: "string[]", | ||
zrevrangebyscore: "string[]", | ||
zrevrank: "number | null", | ||
zscore: "string", | ||
zunion: "unknown[]", | ||
zmscore: "unknown[] | null", | ||
zunionstore: "number", | ||
scan: "[cursor: string, elements: string[]]", | ||
sscan: "[cursor: string, elements: string[]]", | ||
hscan: "[cursor: string, elements: string[]]", | ||
zscan: "[cursor: string, elements: string[]]", | ||
xadd: "string | null", | ||
xtrim: "number", | ||
xdel: "number", | ||
xrange: "[id: string, fields: string[]][]", | ||
xrevrange: "[id: string, fields: string[]][]", | ||
xlen: "number", | ||
xread: (types) => { | ||
if (types.find((type) => type.includes("BLOCK"))) { | ||
return "unknown[] | null"; | ||
} | ||
return "unknown[]"; | ||
}, | ||
xreadgroup: "unknown[]", | ||
xack: "number", | ||
xclaim: "unknown[]", | ||
xautoclaim: "unknown[]", | ||
xpending: "unknown[]", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
type RedisKey = string | Buffer; | ||
type RedisValue = string | Buffer | number; | ||
type Callback<T> = (err: Error | null, res: T) => void; | ||
|
||
// Inspired by https://github.com/mmkal/handy-redis/blob/main/src/generated/interface.ts. | ||
// Should be fixed with https://github.com/Microsoft/TypeScript/issues/1213 | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export interface ResultTypes<Result, Context> { | ||
default: Promise<Result>; | ||
pipeline: ChainableCommander; | ||
} | ||
|
||
export interface ChainableCommander | ||
extends RedisCommander<{ type: "pipeline" }> {} | ||
|
||
export type ClientContext = { type: keyof ResultTypes<unknown, unknown> }; | ||
export type Result<T, Context extends ClientContext> = | ||
// prettier-break | ||
ResultTypes<T, Context>[Context["type"]]; | ||
|
||
interface RedisCommander<Context extends ClientContext = { type: "default" }> { | ||
multi(): ChainableCommander; | ||
//// | ||
} | ||
|
||
export default RedisCommander; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
key: "RedisKey", | ||
string: "string | Buffer | number", | ||
pattern: "string", | ||
number: "number | string", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.