This repository was archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Feat/add types 2 #75
Merged
Merged
Feat/add types 2 #75
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - main | ||
| - default | ||
| pull_request: | ||
| branches: | ||
| - '**' | ||
|
|
||
| name: Typecheck | ||
| jobs: | ||
| check: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node-version: [12.x] | ||
| steps: | ||
| - uses: actions/checkout@v1 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v1 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - name: Install dependencies | ||
| run: npm install | ||
| - name: Typecheck | ||
| uses: gozala/typescript-error-reporter-action@v1.0.8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,3 @@ | ||
| 'use strict' | ||
|
|
||
| /** | ||
| * @module connection/index | ||
| * @type {typeof import('./connection')} | ||
| */ | ||
| exports.Connection = require('./connection') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| 'use strict' | ||
|
|
||
| module.exports = { | ||
| const STATUS = { | ||
| OPEN: /** @type {'open'} */('open'), | ||
| CLOSING: /** @type {'closing'} */('closing'), | ||
| CLOSED: /** @type {'closed'} */('closed') | ||
| } | ||
| module.exports = STATUS | ||
|
|
||
| /** | ||
| * @typedef {STATUS[keyof STATUS]} Status | ||
| */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,10 @@ | ||
| 'use strict' | ||
| /* eslint-disable valid-jsdoc */ | ||
|
|
||
| const debug = require('debug') | ||
| const EventEmitter = require('events') | ||
| const { EventEmitter } = require('events') | ||
| const errcode = require('err-code') | ||
|
|
||
| const pipe = require('it-pipe') | ||
| const { pipe } = require('it-pipe') | ||
|
|
||
| const MulticodecTopology = require('../topology/multicodec-topology') | ||
| const { codes } = require('./errors') | ||
|
|
@@ -46,7 +45,7 @@ class PubsubBaseProtocol extends EventEmitter { | |
| * @param {string} props.debugName - log namespace | ||
| * @param {Array<string>|string} props.multicodecs - protocol identificers to connect | ||
| * @param {Libp2p} props.libp2p | ||
| * @param {SignaturePolicy} [props.globalSignaturePolicy = SignaturePolicy.StrictSign] - defines how signatures should be handled | ||
| * @param {SignaturePolicyType} [props.globalSignaturePolicy = SignaturePolicy.StrictSign] - defines how signatures should be handled | ||
| * @param {boolean} [props.canRelayMessage = false] - if can relay messages not subscribed | ||
| * @param {boolean} [props.emitSelf = false] - if publish should emit to self, if subscribed | ||
| * @abstract | ||
|
|
@@ -226,6 +225,7 @@ class PubsubBaseProtocol extends EventEmitter { | |
| const peer = this._addPeer(peerId, protocol) | ||
| peer.attachInboundStream(stream) | ||
|
|
||
| // @ts-ignore - peer.inboundStream maybe null | ||
| this._processMessages(idB58Str, peer.inboundStream, peer) | ||
| } | ||
|
|
||
|
|
@@ -243,6 +243,7 @@ class PubsubBaseProtocol extends EventEmitter { | |
| try { | ||
| const { stream, protocol } = await conn.newStream(this.multicodecs) | ||
| const peer = this._addPeer(peerId, protocol) | ||
| // @ts-ignore MuxedStream is not DuplexIterableStream | ||
|
Member
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 will address this after merging. This should really be using the muxedStream |
||
| await peer.attachOutboundStream(stream) | ||
| } catch (err) { | ||
| this.log.err(err) | ||
|
|
@@ -257,7 +258,7 @@ class PubsubBaseProtocol extends EventEmitter { | |
| * | ||
| * @private | ||
| * @param {PeerId} peerId - peerId | ||
| * @param {Error} err - error for connection end | ||
| * @param {Error} [err] - error for connection end | ||
| */ | ||
| _onPeerDisconnected (peerId, err) { | ||
| const idB58Str = peerId.toB58String() | ||
|
|
@@ -341,6 +342,7 @@ class PubsubBaseProtocol extends EventEmitter { | |
| await pipe( | ||
| stream, | ||
| async (source) => { | ||
| // @ts-ignore - DuplexIterableStream isn't defined as iterable | ||
| for await (const data of source) { | ||
| const rpcBytes = data instanceof Uint8Array ? data : data.slice() | ||
| const rpcMsg = this._decodeRpc(rpcBytes) | ||
|
|
@@ -395,7 +397,7 @@ class PubsubBaseProtocol extends EventEmitter { | |
| * Handles a subscription change from a peer | ||
| * | ||
| * @param {string} id | ||
| * @param {RPC.SubOpt} subOpt | ||
| * @param {RPCSubOpts} subOpt | ||
| */ | ||
| _processRpcSubOpt (id, subOpt) { | ||
| const t = subOpt.topicID | ||
|
|
@@ -457,7 +459,7 @@ class PubsubBaseProtocol extends EventEmitter { | |
| * The default msgID implementation | ||
| * Child class can override this. | ||
| * | ||
| * @param {RPC.Message} msg - the message object | ||
| * @param {RPCMessage} msg - the message object | ||
| * @returns {Uint8Array} message id as bytes | ||
| */ | ||
| getMsgId (msg) { | ||
|
|
@@ -590,8 +592,8 @@ class PubsubBaseProtocol extends EventEmitter { | |
| * Should be used by the routers to create the message to send. | ||
| * | ||
| * @private | ||
| * @param {Message} message | ||
| * @returns {Promise<Message>} | ||
| * @param {RPCMessage} message | ||
| * @returns {Promise<RPCMessage>} | ||
| */ | ||
| _buildMessage (message) { | ||
| const signaturePolicy = this.globalSignaturePolicy | ||
|
|
@@ -728,6 +730,16 @@ class PubsubBaseProtocol extends EventEmitter { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @typedef {any} Libp2p | ||
| * @typedef {import('./peer-streams').DuplexIterableStream} DuplexIterableStream | ||
| * @typedef {import('../connection/connection')} Connection | ||
| * @typedef {import('./message').RPC} RPC | ||
| * @typedef {import('./message').SubOpts} RPCSubOpts | ||
| * @typedef {import('./message').Message} RPCMessage | ||
| * @typedef {import('./signature-policy').SignaturePolicyType} SignaturePolicyType | ||
| */ | ||
|
|
||
| module.exports = PubsubBaseProtocol | ||
| module.exports.message = message | ||
| module.exports.utils = utils | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This seems to be causing issues integrating with libp2p PR
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.
"Property 'OPEN' does not exist on type 'typeof import("/Users/vsantos/work/pl/gh/libp2p/js-libp2p-interfaces/dist/src/connection/status")'"
Using: