Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type definitions #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
declare module "p2p-graph" {

/***
* @see https://github.com/feross/p2p-graph#api
*/
type P2pGraphPeer = {
id: string // must be unique for this graph
me: boolean, // reference
name: string // display name
}

type P2pGraphEvent = 'select';

class P2pGraph {
constructor(rootElem: HTMLElement);

add(peer: P2pGraphPeer);
connect(id1: string, id2: string);
disconnect(id: string);
areConnected(id1: string, id2: string): boolean;
getLink(i1: string, id2: string): any | null; // ? what is a "Link" exactly?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to clarify the API here

hasPeer(...ids: string[]): boolean;
hasLink(id1: string, id2: string): boolean;
remove(id: string);
seed(id: string, isSeeding: boolean);
rate(id1: string, id2: string, avgRate: number);
list(): P2pGraphPeer[];
destroy();

on(event: P2pGraphEvent, callback: (id: string) => void);
}

export = P2pGraph;
}