Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

add: generate typings, jsdoc annotations #185

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions .jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"recurseDepth": 10,
"source": {
"include": ["src/"],
"exclude": ["node_modules"]
},
"opts": {
"destination": "src/",
"template": "./node_modules/tsd-jsdoc/dist",
"recurse": true
}
}
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- npx aegir commitlint --travis
- npx aegir dep-check -- -i wrtc -i electron-webrtc
- npm run lint
- npm run generate-typings

- stage: test
name: chrome
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "libp2p WebRTC transport that includes a discovery mechanism provided by the signalling-star",
"leadMaintainer": "Vasco Santos <[email protected]>",
"main": "src/index.js",
"typings": "src/types.d.ts",
"bin": {
"webrtc-star": "src/sig-server/bin.js",
"star-sig": "src/sig-server/bin.js",
Expand All @@ -22,7 +23,8 @@
"release-minor": "aegir release --type minor -t node -t browser",
"release-major": "aegir release --type major -t node -t browser",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls"
"coverage-publish": "aegir coverage --provider coveralls",
"generate-typings": "./node_modules/.bin/jsdoc -c ./.jsdoc.json"
},
"pre-push": [
"lint",
Expand Down Expand Up @@ -50,7 +52,10 @@
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"electron-webrtc": "~0.3.0",
"jsdoc": "^3.6.3",
"prom-client": "^11.2.1",
"tsd-jsdoc": "^2.3.1",
"typescript-definition-tester": "0.0.6",
"wrtc": "~0.3.7"
},
"dependencies": {
Expand Down
33 changes: 29 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict'
/**
* @module js-libp2p-webrtc-star
*/

const debug = require('debug')
const log = debug('libp2p:webrtc-star')
Expand All @@ -25,8 +28,14 @@ const sioOptions = {
transports: ['websocket'],
'force new connection': true
}

/**
* @class
*/
class WebRTCStar {
/**
*
* @param {*} options
*/
constructor (options) {
options = options || {}

Expand Down Expand Up @@ -57,6 +66,12 @@ class WebRTCStar {
this._peerDiscovered = this._peerDiscovered.bind(this)
}

/**
*
* @param {*} ma
* @param {object} options
* @param {function} callback
*/
dial (ma, options, callback) {
if (typeof options === 'function') {
callback = options
Expand Down Expand Up @@ -128,7 +143,11 @@ class WebRTCStar {

return conn
}

/**
*
* @param {object} options
* @param {function} handler
*/
createListener (options, handler) {
if (typeof options === 'function') {
handler = options
Expand Down Expand Up @@ -228,7 +247,10 @@ class WebRTCStar {
this.listenersRefs[multiaddr.toString()] = listener
return listener
}

/**
*
* @param {*} multiaddrs
*/
filter (multiaddrs) {
if (!Array.isArray(multiaddrs)) {
multiaddrs = [multiaddrs]
Expand All @@ -242,7 +264,10 @@ class WebRTCStar {
return mafmt.WebRTCStar.matches(ma)
})
}

/**
*
* @param {*} maStr
*/
_peerDiscovered (maStr) {
if (!this.discovery._isStarted) return

Expand Down
50 changes: 50 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @module js-libp2p-webrtc-star
*/
declare module "js-libp2p-webrtc-star" {
/**
*
* @param {*} options
*/
class WebRTCStar {
constructor(options: any);
/**
*
* @param {*} ma
* @param {object} options
* @param {function} callback
*/
dial(ma: any, options: any, callback: (...params: any[]) => any): void;
/**
*
* @param {object} options
* @param {function} handler
*/
createListener(options: any, handler: (...params: any[]) => any): void;
/**
*
* @param {*} multiaddrs
*/
filter(multiaddrs: any): void;
/**
*
* @param {*} maStr
*/
_peerDiscovered(maStr: any): void;
}
}

/**
* @module js-libp2p-webrtc-star/utils
*/
declare module "js-libp2p-webrtc-star/utils" {
/**
* @param {*} ma
*/
function cleanUrlSIO(ma: any): void;
/**
* @param {*} maStr
*/
function cleanMultiaddr(maStr: any): void;
}

10 changes: 9 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use strict'

/**
* @module js-libp2p-webrtc-star/utils
*/
const multiaddr = require('multiaddr')

/**
* @param {*} ma
*/
function cleanUrlSIO (ma) {
const maStrSplit = ma.toString().split('/')
const tcpProto = ma.protos()[1].name
Expand All @@ -25,6 +30,9 @@ function cleanUrlSIO (ma) {
}
}

/**
* @param {*} maStr
*/
function cleanMultiaddr (maStr) {
const legacy = '/libp2p-webrtc-star'

Expand Down