1 |
|
2 | import { Callback, Respondable, CommandParameter } from "./types";
|
3 | export declare type ArgumentType = string | Buffer | number | (string | Buffer | number | any[])[];
|
4 | interface CommandOptions {
|
5 | |
6 |
|
7 |
|
8 | replyEncoding?: BufferEncoding | null;
|
9 | errorStack?: Error;
|
10 | keyPrefix?: string;
|
11 | |
12 |
|
13 |
|
14 | readOnly?: boolean;
|
15 | }
|
16 | declare type ArgumentTransformer = (args: any[]) => any[];
|
17 | declare type ReplyTransformer = (reply: any) => any;
|
18 | export interface CommandNameFlags {
|
19 | VALID_IN_SUBSCRIBER_MODE: [
|
20 | "subscribe",
|
21 | "psubscribe",
|
22 | "unsubscribe",
|
23 | "punsubscribe",
|
24 | "ssubscribe",
|
25 | "sunsubscribe",
|
26 | "ping",
|
27 | "quit"
|
28 | ];
|
29 | VALID_IN_MONITOR_MODE: ["monitor", "auth"];
|
30 | ENTER_SUBSCRIBER_MODE: ["subscribe", "psubscribe", "ssubscribe"];
|
31 | EXIT_SUBSCRIBER_MODE: ["unsubscribe", "punsubscribe", "sunsubscribe"];
|
32 | WILL_DISCONNECT: ["quit"];
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | export default class Command implements Respondable {
|
55 | name: string;
|
56 | static FLAGS: {
|
57 | [key in keyof CommandNameFlags]: CommandNameFlags[key];
|
58 | };
|
59 | private static flagMap?;
|
60 | private static _transformer;
|
61 | |
62 |
|
63 |
|
64 | static checkFlag<T extends keyof CommandNameFlags>(flagName: T, commandName: string): commandName is CommandNameFlags[T][number];
|
65 | static setArgumentTransformer(name: string, func: ArgumentTransformer): void;
|
66 | static setReplyTransformer(name: string, func: ReplyTransformer): void;
|
67 | private static getFlagMap;
|
68 | ignore?: boolean;
|
69 | isReadOnly?: boolean;
|
70 | args: CommandParameter[];
|
71 | inTransaction: boolean;
|
72 | pipelineIndex?: number;
|
73 | isResolved: boolean;
|
74 | reject: (err: Error) => void;
|
75 | resolve: (result: any) => void;
|
76 | promise: Promise<any>;
|
77 | private replyEncoding;
|
78 | private errorStack;
|
79 | private bufferMode;
|
80 | private callback;
|
81 | private transformed;
|
82 | private _commandTimeoutTimer?;
|
83 | private slot?;
|
84 | private keys?;
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | constructor(name: string, args?: Array<ArgumentType>, options?: CommandOptions, callback?: Callback);
|
94 | getSlot(): number;
|
95 | getKeys(): Array<string | Buffer>;
|
96 | /**
|
97 | * Convert command to writable buffer or string
|
98 | */
|
99 | toWritable(_socket: object): string | Buffer;
|
100 | stringifyArguments(): void;
|
101 | /**
|
102 | * Convert buffer/buffer[] to string/string[],
|
103 | * and apply reply transformer.
|
104 | */
|
105 | transformReply(result: Buffer | Buffer[]): string | string[] | Buffer | Buffer[];
|
106 | /**
|
107 | * Set the wait time before terminating the attempt to execute a command
|
108 | * and generating an error.
|
109 | */
|
110 | setTimeout(ms: number): void;
|
111 | private initPromise;
|
112 | /**
|
113 | * Iterate through the command arguments that are considered keys.
|
114 | */
|
115 | private _iterateKeys;
|
116 | /**
|
117 | * Convert the value from buffer to the target encoding.
|
118 | */
|
119 | private _convertValue;
|
120 | }
|
121 | export {};
|