Skip to content

Commit

Permalink
Suggested index.d.ts changes per @chapterjason
Browse files Browse the repository at this point in the history
  • Loading branch information
wankdanker committed Oct 20, 2020
1 parent 47599d9 commit 90f1b25
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ declare module 'node-discover' {
import { EventEmitter } from 'events';
import { RemoteInfo } from 'dgram';

type Options = {
export type Options = {
helloInterval?: number;
checkInterval?: number;
nodeTimeout?: number;
Expand All @@ -26,15 +26,15 @@ declare module 'node-discover' {
hostname?: string;
};

type Message<T = unknown> = {
export type Message<T = unknown> = {
event: string;
pid: string;
iid: string;
hostName: string;
data?: T;
};

type Node<A = unknown> = {
export type Node<A = unknown> = {
isMaster: boolean;
isMasterEligible: boolean;
weight: number;
Expand All @@ -46,18 +46,24 @@ declare module 'node-discover' {
advertisement?: A;
};

type ThisNode<A = unknown> = {
export type ThisNode<A = unknown> = {
isMaster: boolean;
isMasterEligible: boolean;
weight: number;
address: string;
advertisement?: A;
};

type ChannelListener<D> = (data: D, obj: Message<D>, rinfo: RemoteInfo) => void;
export type ChannelListener<D> = (data: D, obj: Message<D>, rinfo: RemoteInfo) => void;

class Discover<A = any, C extends Record<string, any> = Record<string, any>> extends EventEmitter {
export type Network = {
instanceUuid: string;
};

export default class Discover<A = any, C extends Record<string, any> = Record<string, any>> extends EventEmitter {
nodes: Record<string, Node>;
me: ThisNode<A>;
broadcast: Network;
constructor(callback?: (error: Error, something: boolean) => void);
constructor(options?: Options, callback?: (error: Error, success: boolean) => void);

Expand Down Expand Up @@ -85,6 +91,4 @@ declare module 'node-discover' {
on(channel: 'hello', listener: ChannelListener<A>): this;
on<T extends keyof C>(channel: T, listener: ChannelListener<C[T]>): this;
}

export = Discover;
}

0 comments on commit 90f1b25

Please sign in to comment.