diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..049c7d3 --- /dev/null +++ b/index.d.ts @@ -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? + 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; +} +