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

Generate Typescript Typings via JsDoc #91

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 @@ -27,6 +27,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
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec",
"leadMaintainer": "Jacob Heun <[email protected]>",
"main": "src/index.js",
"typings": "src/types.d.ts",
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
Expand All @@ -14,7 +15,9 @@
"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"

},
"browser": {
"src/listener": "./src/listener.browser.js"
Expand Down Expand Up @@ -52,9 +55,12 @@
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"interface-transport": "~0.3.7",
"jsdoc": "^3.6.3",
"multiaddr": "^6.0.6",
"pull-goodbye": "0.0.2",
"pull-stream": "^3.6.9"
"pull-stream": "^3.6.9",
"tsd-jsdoc": "^2.3.1",
"typescript-definition-tester": "0.0.6"
},
"contributors": [
"Chris Campbell <[email protected]>",
Expand Down
20 changes: 18 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ const log = debug('libp2p:websockets:dialer')

const createListener = require('./listener')

/**
* @class
*/
class WebSockets {
/**
*
* @param {*} ma
* @param {object} options
* @param {function} callback
*/
dial (ma, options, callback) {
if (typeof options === 'function') {
callback = options
Expand All @@ -35,7 +44,11 @@ class WebSockets {

return conn
}

/**
*
* @param {object} options
* @param {function} handler
*/
createListener (options, handler) {
if (typeof options === 'function') {
handler = options
Expand All @@ -44,7 +57,10 @@ class WebSockets {

return createListener(options, handler)
}

/**
*
* @param {*} multiaddrs
*/
filter (multiaddrs) {
if (!Array.isArray(multiaddrs)) {
multiaddrs = [multiaddrs]
Expand Down
13 changes: 11 additions & 2 deletions src/listener.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

/**
* @module js-libp2p-websockets/listener
*/
const Connection = require('interface-connection').Connection
const multiaddr = require('multiaddr')
const os = require('os')
Expand All @@ -8,7 +10,12 @@ function noop () {}

const createServer = require('pull-ws/server') || noop

module.exports = (options, handler) => {
/**
* Listener
* @param {*} options
* @param {*} handler
*/
function listener (options, handler) {
const listener = createServer(options, (socket) => {
socket.getObservedAddrs = (callback) => {
// TODO research if we can reuse the address in anyway
Expand Down Expand Up @@ -70,3 +77,5 @@ module.exports = (options, handler) => {

return listener
}

module.exports = listener
36 changes: 36 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @class
*/
declare class WebSockets {
/**
*
* @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;
}

/**
* @module js-libp2p-websockets/listener
*/
declare module "js-libp2p-websockets/listener" {
/**
* Listener
* @param {*} options
* @param {*} handler
*/
function listener(options: any, handler: any): void;
}