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

Generate Typescript Typings via JsDoc #449

Closed
wants to merge 3 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 @@ -23,6 +23,7 @@ jobs:
- npx aegir build --bundlesize
- npx aegir dep-check -- -i wrtc -i electron-webrtc
- npm run lint
- npm run generate-typings

- stage: test
name: chrome
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
"leadMaintainer": "Jacob Heun <[email protected]>",
"main": "src/index.js",
"typings": "src/types.d.ts",
"files": [
"dist",
"src"
Expand All @@ -17,7 +18,8 @@
"release": "aegir release -t node -t browser",
"release-minor": "aegir release --type minor -t node -t browser",
"release-major": "aegir release --type major -t node -t browser",
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node"
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node",
"generate-typings": "./node_modules/.bin/jsdoc -c ./.jsdoc.json"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -84,6 +86,7 @@
"dirty-chai": "^2.0.1",
"electron-webrtc": "^0.3.0",
"interface-datastore": "^0.6.0",
"jsdoc": "^3.6.3",
"libp2p-bootstrap": "^0.9.7",
"libp2p-delegated-content-routing": "^0.2.2",
"libp2p-delegated-peer-routing": "^0.2.2",
Expand All @@ -109,6 +112,7 @@
"pull-protocol-buffers": "~0.1.2",
"pull-serializer": "^0.3.2",
"sinon": "^7.2.7",
"tsd-jsdoc": "^2.3.1",
"wrtc": "^0.4.1"
},
"contributors": [
Expand Down
1 change: 1 addition & 0 deletions src/circuit/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ log.err = debug('libp2p:circuit:error:transportdialer')

const createListener = require('./listener')

/** @class Circuit */
class Circuit {
static get tag () {
return 'Circuit'
Expand Down
5 changes: 4 additions & 1 deletion src/circuit/circuit/dialer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ log.err = debug('libp2p:circuit:error:dialer')
const multicodec = require('../multicodec')
const proto = require('../protocol')

/**
* @class Dialer
*
*/
class Dialer {
/**
* Creates an instance of Dialer.
* @param {Swarm} swarm - the swarm
* @param {any} options - config options
*
* @memberOf Dialer
*/
constructor (swarm, options) {
this.swarm = swarm
Expand Down
4 changes: 4 additions & 0 deletions src/circuit/circuit/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const debug = require('debug')
const log = debug('libp2p:circuit:stop')
log.err = debug('libp2p:circuit:error:stop')

/**
* @class
* @extends EventEmitter
*/
class Stop extends EE {
constructor (swarm) {
super()
Expand Down
8 changes: 7 additions & 1 deletion src/circuit/circuit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const PeerId = require('peer-id')
const proto = require('../protocol')
const { getPeerInfo } = require('../../get-peer-info')

module.exports = function (swarm) {
/**
* Utils
*
*/
function utils (swarm) {
/**
* Get b58 string from multiaddr or peerinfo
*
Expand Down Expand Up @@ -116,3 +120,5 @@ module.exports = function (swarm) {
peerIdFromId
}
}

module.exports = utils
18 changes: 15 additions & 3 deletions src/circuit/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ const debug = require('debug')

const log = debug('libp2p:circuit:listener')
log.err = debug('libp2p:circuit:error:listener')

module.exports = (swarm, options, connHandler) => {
/**
* @method
*
* @param {@} swarm
* @param {*} options
* @param {*} connHandler
* @returns {EventEmitter}
*/
function listener (swarm, options, connHandler) {
/**
* @class
*/
const listener = new EE()
const utils = utilsFactory(swarm)

Expand All @@ -28,7 +38,7 @@ module.exports = (swarm, options, connHandler) => {

/**
* Add swarm handler and listen for incoming connections
*
*
* @param {Multiaddr} ma
* @param {Function} callback
* @return {void}
Expand Down Expand Up @@ -147,3 +157,5 @@ module.exports = (swarm, options, connHandler) => {

return listener
}

module.exports = listener
15 changes: 12 additions & 3 deletions src/content-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ const parallel = require('async/parallel')
const errCode = require('err-code')
const promisify = require('promisify-es6')

module.exports = (node) => {
/**
* @method
* @param {*} node
*/

function router(node) {
const routers = node._modules.contentRouting || []

// If we have the dht, make it first
Expand All @@ -17,13 +22,14 @@ module.exports = (node) => {
/**
* Iterates over all content routers in series to find providers of the given key.
* Once a content router succeeds, iteration will stop.
*
*
* @method
* @param {CID} key The CID key of the content to find
* @param {object} options
* @param {number} options.maxTimeout How long the query should run
* @param {number} options.maxNumProviders - maximum number of providers to find
* @param {function(Error, Result<Array>)} callback
* @returns {void}
* @promise {void}
*/
findProviders: promisify((key, options, callback) => {
if (typeof options === 'function') {
Expand Down Expand Up @@ -67,6 +73,7 @@ module.exports = (node) => {
* Iterates over all content routers in parallel to notify it is
* a provider of the given key.
*
* @method
* @param {CID} key The CID key of the content to find
* @param {function(Error)} callback
* @returns {void}
Expand All @@ -82,3 +89,5 @@ module.exports = (node) => {
})
}
}

module.exports = router
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,11 @@ module.exports = Libp2p
/**
* Like `new Libp2p(options)` except it will create a `PeerInfo`
* instance if one is not provided in options.
*
* @method
* @param {object} options Libp2p configuration options
* @param {function(Error, Libp2p)} callback
* @returns {void}
* @return {Promise<{void}>}
*/
module.exports.createLibp2p = promisify((options, callback) => {
if (options.peerInfo) {
Expand Down
1 change: 1 addition & 0 deletions src/peer-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = (node) => {
/**
* Iterates over all peer routers in series to find the given peer.
*
* @method
* @param {String} id The id of the peer to find
* @param {object} options
* @param {number} options.maxTimeout How long the query should run
Expand Down
2 changes: 2 additions & 0 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = (node, Pubsub, config) => {
/**
* Subscribe the given handler to a pubsub topic
*
* @method
* @param {string} topic
* @param {function} handler The handler to subscribe
* @param {object|null} [options]
Expand Down Expand Up @@ -57,6 +58,7 @@ module.exports = (node, Pubsub, config) => {
/**
* Unsubscribes from a pubsub topic
*
* @method
* @param {string} topic
* @param {function|null} handler The handler to unsubscribe from
* @param {function} [callback] An optional callback
Expand Down
1 change: 1 addition & 0 deletions src/switch/connection/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const EventEmitter = require('events').EventEmitter
const debug = require('debug')
const withIs = require('class-is')

/** @class BaseConnection */
class BaseConnection extends EventEmitter {
constructor ({ _switch, name }) {
super()
Expand Down
3 changes: 3 additions & 0 deletions src/switch/dialer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const {
PRIORITY_LOW
} = require('../constants')

/**
* @module dialer/index
*/
module.exports = function (_switch) {
const dialQueueManager = new DialQueueManager(_switch)

Expand Down
2 changes: 1 addition & 1 deletion src/switch/dialer/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ log.error = debug('libp2p:switch:dial:error')
* @property {object} options
* @property {boolean} options.useFSM - If `callback` should return a ConnectionFSM
* @property {number} options.priority - The priority of the dial
* @property {function(Error, Connection|ConnectionFSM)} callback
* @property {function} callback function(Error, Connection|ConnectionFSM)
*/

/**
Expand Down
3 changes: 2 additions & 1 deletion src/switch/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const EventEmitter = require('events')
* @param {Switch} swtch
* @returns {EventEmitter}
*/
module.exports = (swtch) => {
function observer (swtch) {
const observer = Object.assign(new EventEmitter(), {
incoming: observe('in'),
outgoing: observe('out')
Expand Down Expand Up @@ -46,3 +46,4 @@ module.exports = (swtch) => {
})
}
}
module.exports = observer
4 changes: 3 additions & 1 deletion src/switch/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const directionToEvent = {
* @param {any} _options
* @returns {Stats}
*/
module.exports = (observer, _options) => {
function stats (observer, _options) {
const options = Object.assign({}, defaultOptions, _options)
const globalStats = new Stat(initialCounters, options)

Expand Down Expand Up @@ -148,3 +148,5 @@ module.exports = (observer, _options) => {
stats.emit('update')
}
}

module.exports = stats
3 changes: 2 additions & 1 deletion src/switch/stats/old-peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const LRU = require('hashlru')
* @param {Number} maxSize
* @returns {LRUCache}
*/
module.exports = (maxSize) => {
function oldPeers (maxSize) {
const patched = LRU(maxSize)
patched.delete = patched.remove
return patched
}
module.exports = oldPeers
8 changes: 6 additions & 2 deletions src/switch/stats/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class Stats extends EventEmitter {

/**
* Returns a clone of the current stats.
*
*
* @method
* @readonly
* @returns {Map<string, Stat>}
*/
get snapshot () {
Expand All @@ -76,7 +78,9 @@ class Stats extends EventEmitter {

/**
* Returns a clone of the internal movingAverages
*
*
* @method
* @readonly
* @returns {Array<MovingAverage>}
*/
get movingAverages () {
Expand Down
Loading