From 2a111bafbe7a7ec2b39fd4654449abc889bddd65 Mon Sep 17 00:00:00 2001 From: Stephan Hesse Date: Mon, 22 Oct 2018 17:20:30 +0200 Subject: [PATCH 1/4] Add type definitions see https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html --- index.d.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..ad16e01 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,33 @@ +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'; + + export default class P2pGraph { + constructor(rootElem: HTMLElement); + + add(peer: P2pGraphPeer); + connect(id1: string, id2: string); + disconnect(id: string); + areConnected(id1: string, id2: string); + getLink(i1: string, id2: string); + hasPeer(...ids: string[]): boolean; + hasLink(id1: string, id2: string); + 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); + } + +} + From 01a792a959b34335fe5ae75d9fe590bb01b40004 Mon Sep 17 00:00:00 2001 From: Stephan Hesse Date: Mon, 22 Oct 2018 17:32:15 +0200 Subject: [PATCH 2/4] Correct typings: Module isn't using an es6 default-export, but should be imported in TS with `import P2pGraph = require("p2p-graph");` --- index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index ad16e01..ce60594 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,7 +10,7 @@ declare module "p2p-graph" { type P2pGraphEvent = 'select'; - export default class P2pGraph { + class P2pGraph { constructor(rootElem: HTMLElement); add(peer: P2pGraphPeer); @@ -29,5 +29,6 @@ declare module "p2p-graph" { on(event: P2pGraphEvent, callback: (id: string) => void); } + export = P2pGraph; } From ab687b8dcb7fa6fc18ca3319a99230e3dbfced5c Mon Sep 17 00:00:00 2001 From: Stephan Hesse Date: Mon, 22 Oct 2018 17:34:13 +0200 Subject: [PATCH 3/4] Typings file: correct 2 spaces indentation --- index.d.ts | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/index.d.ts b/index.d.ts index ce60594..83a9761 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,34 +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'; + /*** + * @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 + } - class P2pGraph { - constructor(rootElem: HTMLElement); + type P2pGraphEvent = 'select'; - add(peer: P2pGraphPeer); - connect(id1: string, id2: string); - disconnect(id: string); - areConnected(id1: string, id2: string); - getLink(i1: string, id2: string); - hasPeer(...ids: string[]): boolean; - hasLink(id1: string, id2: string); - remove(id: string); - seed(id: string, isSeeding: boolean); - rate(id1: string, id2: string, avgRate: number); - list(): P2pGraphPeer[]; - destroy(); + class P2pGraph { + constructor(rootElem: HTMLElement); - on(event: P2pGraphEvent, callback: (id: string) => void); - } + add(peer: P2pGraphPeer); + connect(id1: string, id2: string); + disconnect(id: string); + areConnected(id1: string, id2: string); + getLink(i1: string, id2: string); + hasPeer(...ids: string[]): boolean; + hasLink(id1: string, id2: string); + remove(id: string); + seed(id: string, isSeeding: boolean); + rate(id1: string, id2: string, avgRate: number); + list(): P2pGraphPeer[]; + destroy(); - export = P2pGraph; + on(event: P2pGraphEvent, callback: (id: string) => void); + } + + export = P2pGraph; } From aa2a9f53501557e626a62c7e53e8e2c9ebe67cbc Mon Sep 17 00:00:00 2001 From: Stephan Hesse Date: Mon, 22 Oct 2018 19:55:02 +0200 Subject: [PATCH 4/4] add missing return types --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 83a9761..049c7d3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,10 +17,10 @@ declare module "p2p-graph" { add(peer: P2pGraphPeer); connect(id1: string, id2: string); disconnect(id: string); - areConnected(id1: string, id2: string); - getLink(i1: string, id2: 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); + hasLink(id1: string, id2: string): boolean; remove(id: string); seed(id: string, isSeeding: boolean); rate(id1: string, id2: string, avgRate: number);