You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Add support for redis functions (#2020)
* fix #1906 - implement BITFIELD_RO * initial support for redis functions * fix test utils * redis functions commands and tests * upgrade deps * fix "Property 'uninstall' does not exist on type 'SinonFakeTimers'" * upgrade dockers version * Merge branch 'master' of github.com:redis/node-redis into functions * fix FUNCTION LIST WITHCODE and FUNCTION STATS * upgrade deps * set minimum version for FCALL and FCALL_RO * fix FUNCTION LOAD * FUNCTION LOAD * fix FUNCTION LOAD & FUNCTION LIST & FUNCTION LOAD WITHCODE * fix FUNCTION_LIST_WITHCODE test
This commit is contained in:
@@ -1,22 +1,51 @@
|
||||
import { ClientCommandOptions } from '../client';
|
||||
import { CommandOptions } from '../command-options';
|
||||
import { RedisScriptConfig, SHA1 } from '../lua-script';
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface RedisCommandRawReplyArray extends Array<RedisCommandRawReply> {}
|
||||
export type RedisCommandRawReply = string | number | Buffer | null | undefined | RedisCommandRawReplyArray;
|
||||
export type RedisCommandRawReply = string | number | Buffer | null | undefined | Array<RedisCommandRawReply>;
|
||||
|
||||
export type RedisCommandArgument = string | Buffer;
|
||||
|
||||
export type RedisCommandArguments = Array<RedisCommandArgument> & { preserve?: unknown };
|
||||
|
||||
export interface RedisCommand {
|
||||
FIRST_KEY_INDEX?: number | ((...args: Array<any>) => RedisCommandArgument);
|
||||
FIRST_KEY_INDEX?: number | ((...args: Array<any>) => RedisCommandArgument | undefined);
|
||||
IS_READ_ONLY?: boolean;
|
||||
transformArguments(this: void, ...args: Array<any>): RedisCommandArguments;
|
||||
transformReply?(this: void, reply: any, preserved?: any): any;
|
||||
}
|
||||
|
||||
export type RedisCommandReply<C extends RedisCommand> = C['transformReply'] extends (...args: any) => infer T ? T : RedisCommandRawReply;
|
||||
export type RedisCommandReply<C extends RedisCommand> =
|
||||
C['transformReply'] extends (...args: any) => infer T ? T : RedisCommandRawReply;
|
||||
|
||||
export type ConvertArgumentType<Type, ToType> =
|
||||
Type extends RedisCommandArgument ? (
|
||||
Type extends (string & ToType) ? Type : ToType
|
||||
) : (
|
||||
Type extends Set<infer Member> ? Set<ConvertArgumentType<Member, ToType>> : (
|
||||
Type extends Map<infer Key, infer Value> ? Map<Key, ConvertArgumentType<Value, ToType>> : (
|
||||
Type extends Array<infer Member> ? Array<ConvertArgumentType<Member, ToType>> : (
|
||||
Type extends Date ? Type : (
|
||||
Type extends Record<PropertyKey, any> ? {
|
||||
[Property in keyof Type]: ConvertArgumentType<Type[Property], ToType>
|
||||
} : Type
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
export type RedisCommandSignature<
|
||||
Command extends RedisCommand,
|
||||
Params extends Array<unknown> = Parameters<Command['transformArguments']>
|
||||
> = <Options extends CommandOptions<ClientCommandOptions>>(
|
||||
...args: Params | [options: Options, ...rest: Params]
|
||||
) => Promise<
|
||||
ConvertArgumentType<
|
||||
RedisCommandReply<Command>,
|
||||
Options['returnBuffers'] extends true ? Buffer : string
|
||||
>
|
||||
>;
|
||||
|
||||
export interface RedisCommands {
|
||||
[command: string]: RedisCommand;
|
||||
@@ -30,13 +59,33 @@ export interface RedisModules {
|
||||
[module: string]: RedisModule;
|
||||
}
|
||||
|
||||
export interface RedisFunction extends RedisCommand {
|
||||
NAME: string;
|
||||
NUMBER_OF_KEYS?: number;
|
||||
}
|
||||
|
||||
export interface RedisFunctionLibrary {
|
||||
[fn: string]: RedisFunction;
|
||||
}
|
||||
|
||||
export interface RedisFunctions {
|
||||
[library: string]: RedisFunctionLibrary;
|
||||
}
|
||||
|
||||
export type RedisScript = RedisScriptConfig & SHA1;
|
||||
|
||||
export interface RedisScripts {
|
||||
[script: string]: RedisScript;
|
||||
}
|
||||
|
||||
export interface RedisPlugins<M extends RedisModules, S extends RedisScripts> {
|
||||
export interface RedisExtensions<
|
||||
M extends RedisModules = RedisModules,
|
||||
F extends RedisFunctions = RedisFunctions,
|
||||
S extends RedisScripts = RedisScripts
|
||||
> {
|
||||
modules?: M;
|
||||
functions?: F;
|
||||
scripts?: S;
|
||||
}
|
||||
|
||||
export type ExcludeMappedString<S> = string extends S ? never : S;
|
||||
|
Reference in New Issue
Block a user