You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
* increase test coverage * @node-redis to @redis * ugprade deps * fix benchmark * use 7.0 docker (not rc), update readmes, clean code, fix @-redis import * update readme * fix function in cluster * update docs Co-authored-by: Chayim <chayim@users.noreply.github.com> * Update clustering.md * add subpackages move warning * drop support for node 12 * upgrade deps * fix tsconfig.base.json Co-authored-by: Chayim <chayim@users.noreply.github.com>
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import { ClientCommandOptions } from '../client';
|
|
import { CommandOptions } from '../command-options';
|
|
import { RedisScriptConfig, SHA1 } from '../lua-script';
|
|
|
|
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 | 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 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;
|
|
}
|
|
|
|
export interface RedisModule {
|
|
[command: string]: RedisCommand;
|
|
}
|
|
|
|
export interface RedisModules {
|
|
[module: string]: RedisModule;
|
|
}
|
|
|
|
export interface RedisFunction extends RedisCommand {
|
|
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 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;
|