Skip to content

Commit d1d9dba

Browse files
committed
fix: rename interfaces by dropping prefix I
1 parent df9330b commit d1d9dba

File tree

16 files changed

+117
-136
lines changed

16 files changed

+117
-136
lines changed

lib/DataHandler.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NetStream, CommandItem, ICommand } from "./types";
1+
import { NetStream, CommandItem, Respondable } from "./types";
22
import Deque = require("denque");
33
import { EventEmitter } from "events";
44
import Command from "./command";
@@ -10,35 +10,30 @@ const debug = Debug("dataHandler");
1010

1111
type ReplyData = string | Buffer | number | Array<string | Buffer | number>;
1212

13-
export interface IDataHandlerOptions {
14-
stringNumbers: boolean;
15-
dropBufferSupport: boolean;
16-
}
17-
18-
interface ICondition {
13+
interface Condition {
1914
select: number;
2015
auth: string;
2116
subscriber: false | SubscriptionSet;
2217
}
2318

24-
interface IDataHandledable extends EventEmitter {
19+
interface DataHandledable extends EventEmitter {
2520
stream: NetStream;
2621
status: string;
27-
condition: ICondition;
22+
condition: Condition;
2823
commandQueue: Deque<CommandItem>;
2924

3025
disconnect(reconnect: boolean): void;
3126
recoverFromFatalError(commandError: Error, err: Error, options: any): void;
3227
handleReconnection(err: Error, item: CommandItem): void;
3328
}
3429

35-
interface IParserOptions {
30+
interface ParserOptions {
3631
stringNumbers: boolean;
3732
dropBufferSupport: boolean;
3833
}
3934

4035
export default class DataHandler {
41-
constructor(private redis: IDataHandledable, parserOptions: IParserOptions) {
36+
constructor(private redis: DataHandledable, parserOptions: ParserOptions) {
4237
const parser = new RedisParser({
4338
stringNumbers: parserOptions.stringNumbers,
4439
returnBuffers: !parserOptions.dropBufferSupport,
@@ -230,32 +225,43 @@ export default class DataHandler {
230225
}
231226
}
232227

233-
function fillSubCommand(command: ICommand, count: number) {
234-
// TODO: use WeakMap here
235-
if (typeof (command as any).remainReplies === "undefined") {
236-
(command as any).remainReplies = command.args.length;
237-
}
238-
if (--(command as any).remainReplies === 0) {
228+
const remainingRepliesMap = new WeakMap<Respondable, number>();
229+
230+
function fillSubCommand(command: Respondable, count: number) {
231+
let remainingReplies = remainingRepliesMap.has(command)
232+
? remainingRepliesMap.get(command)
233+
: command.args.length;
234+
235+
remainingReplies -= 1;
236+
237+
if (remainingReplies <= 0) {
239238
command.resolve(count);
239+
remainingRepliesMap.delete(command);
240240
return true;
241241
}
242+
remainingRepliesMap.set(command, remainingReplies);
242243
return false;
243244
}
244245

245-
function fillUnsubCommand(command: ICommand, count: number) {
246-
if (typeof (command as any).remainReplies === "undefined") {
247-
(command as any).remainReplies = command.args.length;
248-
}
249-
if ((command as any).remainReplies === 0) {
246+
function fillUnsubCommand(command: Respondable, count: number) {
247+
let remainingReplies = remainingRepliesMap.has(command)
248+
? remainingRepliesMap.get(command)
249+
: command.args.length;
250+
251+
if (remainingReplies === 0) {
250252
if (count === 0) {
253+
remainingRepliesMap.delete(command);
251254
command.resolve(count);
252255
return true;
253256
}
254257
return false;
255258
}
256-
if (--(command as any).remainReplies === 0) {
259+
260+
remainingReplies -= 1;
261+
if (remainingReplies <= 0) {
257262
command.resolve(count);
258263
return true;
259264
}
265+
remainingRepliesMap.set(command, remainingReplies);
260266
return false;
261267
}

lib/ScanStream.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { Readable, ReadableOptions } from "stream";
2-
/**
3-
* Options for ScanStream
4-
*
5-
* @export
6-
* @interface IScanStreamOptions
7-
* @extends {ReadableOptions}
8-
*/
9-
export interface IScanStreamOptions extends ReadableOptions {
2+
3+
export interface ScanStreamOptions extends ReadableOptions {
104
key?: string;
115
match?: string;
126
type?: string;
@@ -26,7 +20,7 @@ export default class ScanStream extends Readable {
2620
private _redisCursor = "0";
2721
private _redisDrained = false;
2822

29-
constructor(private opt: IScanStreamOptions) {
23+
constructor(private opt: ScanStreamOptions) {
3024
super(opt);
3125
}
3226

lib/SubscriptionSet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ICommandNameFlags } from "./command";
1+
import { CommandNameFlags } from "./command";
22

3-
type AddSet = ICommandNameFlags["ENTER_SUBSCRIBER_MODE"][number];
4-
type DelSet = ICommandNameFlags["EXIT_SUBSCRIBER_MODE"][number];
3+
type AddSet = CommandNameFlags["ENTER_SUBSCRIBER_MODE"][number];
4+
type DelSet = CommandNameFlags["EXIT_SUBSCRIBER_MODE"][number];
55

66
/**
77
* Tiny class to simplify dealing with subscription set

lib/cluster/ClusterOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type DNSLookupFunction = (
1818
family?: number
1919
) => void
2020
) => void;
21-
export interface INatMap {
21+
export interface NatMap {
2222
[key: string]: { host: string; port: number };
2323
}
2424

@@ -166,7 +166,7 @@ export interface ClusterOptions extends CommanderOptions {
166166
* @default require('dns').lookup
167167
*/
168168
dnsLookup?: DNSLookupFunction;
169-
natMap?: INatMap;
169+
natMap?: NatMap;
170170

171171
/**
172172
* See Redis class.

lib/cluster/DelayQueue.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import Deque = require("denque");
33

44
const debug = Debug("delayqueue");
55

6-
/**
7-
* Options for DelayQueue
8-
*
9-
* @export
10-
* @interface IDelayQueueOptions
11-
*/
12-
export interface IDelayQueueOptions {
6+
export interface DelayQueueOptions {
137
callback?: Function;
148
timeout: number;
159
}
@@ -29,13 +23,13 @@ export default class DelayQueue {
2923
*
3024
* @param {string} bucket bucket name
3125
* @param {Function} item function that will run later
32-
* @param {IDelayQueueOptions} options
26+
* @param {DelayQueueOptions} options
3327
* @memberof DelayQueue
3428
*/
3529
public push(
3630
bucket: string,
3731
item: Function,
38-
options: IDelayQueueOptions
32+
options: DelayQueueOptions
3933
): void {
4034
const callback = options.callback || process.nextTick;
4135
if (!this.queues[bucket]) {

lib/cluster/util.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export interface RedisOptions {
1313
[key: string]: any;
1414
}
1515

16-
export interface ISrvRecordsGroup {
16+
export interface SrvRecordsGroup {
1717
totalWeight: number;
1818
records: SrvRecord[];
1919
}
2020

21-
export interface IGroupedSrvRecords {
22-
[key: number]: ISrvRecordsGroup;
21+
export interface GroupedSrvRecords {
22+
[key: number]: SrvRecordsGroup;
2323
}
2424

2525
export function getNodeKey(node: RedisOptions): NodeKey {
@@ -80,7 +80,7 @@ export function getUniqueHostnamesFromOptions(nodes: RedisOptions[]): string[] {
8080
return Object.keys(uniqueHostsMap).filter((host) => !isIP(host));
8181
}
8282

83-
export function groupSrvRecords(records: SrvRecord[]): IGroupedSrvRecords {
83+
export function groupSrvRecords(records: SrvRecord[]): GroupedSrvRecords {
8484
const recordsByPriority = {};
8585
for (const record of records) {
8686
if (!recordsByPriority.hasOwnProperty(record.priority)) {
@@ -97,7 +97,7 @@ export function groupSrvRecords(records: SrvRecord[]): IGroupedSrvRecords {
9797
return recordsByPriority;
9898
}
9999

100-
export function weightSrvRecords(recordsGroup: ISrvRecordsGroup): SrvRecord {
100+
export function weightSrvRecords(recordsGroup: SrvRecordsGroup): SrvRecord {
101101
if (recordsGroup.records.length === 1) {
102102
recordsGroup.totalWeight = 0;
103103
return recordsGroup.records.shift();

lib/command.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@ import {
88
convertMapToArray,
99
convertObjectToArray,
1010
} from "./utils";
11-
import { CallbackFunction, ICommand, CommandParameter } from "./types";
11+
import { CallbackFunction, Respondable, CommandParameter } from "./types";
1212

1313
export type ArgumentType =
1414
| string
1515
| Buffer
1616
| number
1717
| (string | Buffer | number | any[])[];
1818

19-
interface ICommandOptions {
19+
interface CommandOptions {
2020
/**
2121
* Set the encoding of the reply, by default buffer will be returned.
22-
*
23-
* @type {(string | null)}
24-
* @memberof ICommandOptions
2522
*/
2623
replyEncoding?: BufferEncoding | null;
2724
errorStack?: Error;
@@ -34,11 +31,11 @@ interface ICommandOptions {
3431

3532
type ArgumentTransformer = (args: any[]) => any[];
3633
type ReplyTransformer = (reply: any) => any;
37-
interface IFlagMap {
34+
interface FlagMap {
3835
[flag: string]: { [command: string]: true };
3936
}
4037

41-
export interface ICommandNameFlags {
38+
export interface CommandNameFlags {
4239
// Commands that can be processed when client is in the subscriber mode
4340
VALID_IN_SUBSCRIBER_MODE: [
4441
"subscribe",
@@ -83,9 +80,9 @@ export interface ICommandNameFlags {
8380
* ```
8481
* @see {@link Redis#sendCommand} which can send a Command instance to Redis
8582
*/
86-
export default class Command implements ICommand {
83+
export default class Command implements Respondable {
8784
public static FLAGS: {
88-
[key in keyof ICommandNameFlags]: ICommandNameFlags[key];
85+
[key in keyof CommandNameFlags]: CommandNameFlags[key];
8986
} = {
9087
VALID_IN_SUBSCRIBER_MODE: [
9188
"subscribe",
@@ -101,12 +98,12 @@ export default class Command implements ICommand {
10198
WILL_DISCONNECT: ["quit"],
10299
};
103100

104-
private static flagMap?: IFlagMap;
101+
private static flagMap?: FlagMap;
105102

106-
private static getFlagMap(): IFlagMap {
103+
private static getFlagMap(): FlagMap {
107104
if (!this.flagMap) {
108105
this.flagMap = Object.keys(Command.FLAGS).reduce(
109-
(map: IFlagMap, flagName: string) => {
106+
(map: FlagMap, flagName: string) => {
110107
map[flagName] = {};
111108
Command.FLAGS[flagName].forEach((commandName: string) => {
112109
map[flagName][commandName] = true;
@@ -126,10 +123,10 @@ export default class Command implements ICommand {
126123
* @param {string} commandName
127124
* @return {boolean}
128125
*/
129-
public static checkFlag<T extends keyof ICommandNameFlags>(
126+
public static checkFlag<T extends keyof CommandNameFlags>(
130127
flagName: T,
131128
commandName: string
132-
): commandName is ICommandNameFlags[T][number] {
129+
): commandName is CommandNameFlags[T][number] {
133130
return !!this.getFlagMap()[flagName][commandName];
134131
}
135132

@@ -177,15 +174,15 @@ export default class Command implements ICommand {
177174
* Creates an instance of Command.
178175
* @param {string} name Command name
179176
* @param {(Array<string | Buffer | number>)} [args=[]] An array of command arguments
180-
* @param {ICommandOptions} [options={}]
177+
* @param {CommandOptions} [options={}]
181178
* @param {CallbackFunction} [callback] The callback that handles the response.
182179
* If omit, the response will be handled via Promise
183180
* @memberof Command
184181
*/
185182
constructor(
186183
public name: string,
187184
args: Array<ArgumentType> = [],
188-
options: ICommandOptions = {},
185+
options: CommandOptions = {},
189186
callback?: CallbackFunction
190187
) {
191188
this.replyEncoding = options.replyEncoding;

lib/connectors/SentinelConnector/FailoverDetector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { Debug } from "../../utils";
22
import SentinelConnector from "./index";
3-
import { ISentinel } from "./types";
3+
import { Sentinel } from "./types";
44

55
const debug = Debug("FailoverDetector");
66

77
const CHANNEL_NAME = "+switch-master";
88

99
export class FailoverDetector {
1010
private connector: SentinelConnector;
11-
private sentinels: ISentinel[];
11+
private sentinels: Sentinel[];
1212
private isDisconnected = false;
1313

1414
// sentinels can't be used for regular commands after this
15-
constructor(connector: SentinelConnector, sentinels: ISentinel[]) {
15+
constructor(connector: SentinelConnector, sentinels: Sentinel[]) {
1616
this.connector = connector;
1717
this.sentinels = sentinels;
1818
}

lib/connectors/SentinelConnector/SentinelIterator.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ISentinelAddress } from "./types";
1+
import { SentinelAddress } from "./types";
22

33
function isSentinelEql(
4-
a: Partial<ISentinelAddress>,
5-
b: Partial<ISentinelAddress>
4+
a: Partial<SentinelAddress>,
5+
b: Partial<SentinelAddress>
66
): boolean {
77
return (
88
(a.host || "127.0.0.1") === (b.host || "127.0.0.1") &&
@@ -11,11 +11,12 @@ function isSentinelEql(
1111
}
1212

1313
export default class SentinelIterator
14-
implements Iterator<Partial<ISentinelAddress>> {
14+
implements Iterator<Partial<SentinelAddress>>
15+
{
1516
private cursor = 0;
16-
private sentinels: Array<Partial<ISentinelAddress>>;
17+
private sentinels: Array<Partial<SentinelAddress>>;
1718

18-
constructor(sentinels: Array<Partial<ISentinelAddress>>) {
19+
constructor(sentinels: Array<Partial<SentinelAddress>>) {
1920
this.sentinels = sentinels.slice(0);
2021
}
2122

@@ -35,7 +36,7 @@ export default class SentinelIterator
3536
this.cursor = 0;
3637
}
3738

38-
add(sentinel: ISentinelAddress): boolean {
39+
add(sentinel: SentinelAddress): boolean {
3940
for (let i = 0; i < this.sentinels.length; i++) {
4041
if (isSentinelEql(sentinel, this.sentinels[i])) {
4142
return false;

0 commit comments

Comments
 (0)