-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add types #16
feat: add types #16
Changes from 4 commits
21dc1d9
b0d06da
2d5eaf1
c92a92c
f510e8f
7371423
64a90ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: ci | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: npm install | ||
- run: npx aegir lint | ||
- run: npx aegir ts -p check | ||
- run: npx aegir build | ||
- run: npx aegir dep-check | ||
- uses: ipfs/aegir/actions/bundle-size@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
test-node: | ||
needs: check | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [windows-latest, ubuntu-latest, macos-latest] | ||
node: [14, 15] | ||
fail-fast: true | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- run: npm install | ||
- run: npx nyc --reporter=lcov aegir test -t node -- --bail | ||
- uses: codecov/codecov-action@v1 | ||
test-chrome: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: npm install | ||
- run: npx aegir test -t browser -t webworker --bail | ||
test-firefox: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: npm install | ||
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless | ||
test-webkit: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: microsoft/playwright-github-action@v1 | ||
- run: npm install | ||
- run: npx aegir test -t browser -t webworker --bail -- --browser webkit | ||
test-electron-main: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: npm install | ||
- run: npx xvfb-maybe aegir test -t electron-main --bail | ||
test-electron-renderer: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: npm install | ||
- run: npx xvfb-maybe aegir test -t electron-renderer --bail |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,25 +21,28 @@ function ipPortToMultiaddr (ip, port) { | |||||
throw errCode(new Error(`invalid ip provided: ${ip}`), errors.ERR_INVALID_IP_PARAMETER) | ||||||
} | ||||||
|
||||||
// @ts-ignore parseInt expects only string | ||||||
port = parseInt(port) | ||||||
|
||||||
if (isNaN(port)) { | ||||||
throw errCode(new Error(`invalid port provided: ${port}`), errors.ERR_INVALID_PORT_PARAMETER) | ||||||
} | ||||||
|
||||||
if (new Address4(ip).isValid()) { | ||||||
try { | ||||||
// Test valid IPv4 | ||||||
new Address4(ip) // eslint-disable-line no-new | ||||||
return multiaddr(`/ip4/${ip}/tcp/${port}`) | ||||||
} | ||||||
|
||||||
const ip6 = new Address6(ip) | ||||||
} catch (_) {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're ignoring the error you can use optional catch binding here:
Suggested change
|
||||||
|
||||||
if (ip6.isValid()) { | ||||||
try { | ||||||
// Test valid IPv6 | ||||||
const ip6 = new Address6(ip) | ||||||
return ip6.is4() | ||||||
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`) | ||||||
: multiaddr(`/ip6/${ip}/tcp/${port}`) | ||||||
} catch (err) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this error get logged somewhere? |
||||||
throw errCode(new Error(`invalid ip:port for creating a multiaddr: ${ip}:${port}`), errors.ERR_INVALID_IP) | ||||||
} | ||||||
|
||||||
throw errCode(new Error(`invalid ip:port for creating a multiaddr: ${ip}:${port}`), errors.ERR_INVALID_IP) | ||||||
} | ||||||
|
||||||
module.exports = ipPortToMultiaddr | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
'use strict' | ||
|
||
const abortable = require('abortable-iterator') | ||
const log = require('debug')('libp2p:stream:converter') | ||
const debug = require('debug') | ||
const log = debug('libp2p:stream:converter') | ||
|
||
/** | ||
* @typedef {import('multiaddr')} Multiaddr | ||
* @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection | ||
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream | ||
* | ||
* @typedef {Object} Timeline | ||
* @property {number} open - connection opening timestamp. | ||
* @property {number} [upgraded] - connection upgraded timestamp. | ||
* @property {number} [close] | ||
*/ | ||
|
||
/** | ||
* Convert a duplex iterable into a MultiaddrConnection. | ||
* https://github.com/libp2p/interface-transport#multiaddrconnection | ||
* | ||
* @param {object} streamProperties | ||
* @param {DuplexStream} streamProperties.stream | ||
* @param {MuxedStream} streamProperties.stream | ||
* @param {Multiaddr} streamProperties.remoteAddr | ||
* @param {Multiaddr} streamProperties.localAddr | ||
* @param {object} [options] | ||
|
@@ -17,8 +29,12 @@ const log = require('debug')('libp2p:stream:converter') | |
function streamToMaConnection ({ stream, remoteAddr, localAddr }, options = {}) { | ||
const { sink, source } = stream | ||
const maConn = { | ||
/** | ||
* @param {Uint8Array} source | ||
*/ | ||
async sink (source) { | ||
if (options.signal) { | ||
// @ts-ignore abortable has no type definitions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I retried it deconstructing the require and it has types indeed. However, types infer that the Uint8Array will be a source with numbers for reasons 🤷🏼 I updated the ignore message to not block on this |
||
source = abortable(source, options.signal) | ||
} | ||
|
||
|
@@ -35,23 +51,24 @@ function streamToMaConnection ({ stream, remoteAddr, localAddr }, options = {}) | |
} | ||
close() | ||
}, | ||
|
||
// @ts-ignore abortable has no type definitions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why, I will open an issue in |
||
source: options.signal ? abortable(source, options.signal) : source, | ||
conn: stream, | ||
localAddr, | ||
remoteAddr, | ||
timeline: { open: Date.now() }, | ||
|
||
/** @type {Timeline} */ | ||
timeline: { open: Date.now(), close: undefined }, | ||
close () { | ||
sink([]) | ||
close() | ||
sink(new Uint8Array(0)) | ||
return close() | ||
} | ||
} | ||
|
||
function close () { | ||
if (!maConn.timeline.close) { | ||
maConn.timeline.close = Date.now() | ||
} | ||
return Promise.resolve() | ||
} | ||
|
||
return maConn | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./node_modules/aegir/src/config/tsconfig.aegir.json", | ||
vasco-santos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"compilerOptions": { | ||
"outDir": "dist" | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to just wrap with an if clause