From 981cb7e2e434913b663fcda3844b7eec664b022f Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Sat, 15 Dec 2018 00:20:05 +0000 Subject: [PATCH] fix: remove lodash and pull-streams --- package.json | 21 ++++++++++----------- src/circuit/dialer.js | 3 +-- src/circuit/hop.js | 2 +- src/circuit/stream-handler.js | 11 +++++++---- test/dialer.spec.js | 16 +++++++++------- test/hop.spec.js | 16 +++++++++------- test/listener.spec.js | 24 +++++++++++++----------- 7 files changed, 50 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 8a9ebaa..c8831d4 100644 --- a/package.json +++ b/package.json @@ -48,8 +48,7 @@ "dirkmc " ], "devDependencies": { - "aegir": "^18.0.2", - "assert": "^1.4.1", + "aegir": "^18.0.3", "chai": "^4.2.0", "dirty-chai": "^2.0.1", "libp2p": "~0.24.3", @@ -59,17 +58,17 @@ }, "dependencies": { "async": "^2.6.1", - "debug": "^4.1.1", - "defaults-deep": "~0.2.4", - "interface-connection": "~0.3.3", - "mafmt": "^6.0.3", - "multiaddr": "^6.0.2", - "multistream-select": "~0.14.3", - "peer-id": "~0.12.1", - "peer-info": "~0.15.0", + "debug": "^4.1.0", + "interface-connection": "~0.3.2", + "mafmt": "^6.0.4", + "multiaddr": "^6.0.3", + "once": "^1.4.0", + "peer-id": "~0.12.2", + "peer-info": "~0.15.1", "protons": "^1.0.1", - "pull-abortable": "^4.1.1", "pull-handshake": "^1.1.4", + "pull-length-prefixed": "^1.3.1", + "pull-pair": "^1.1.0", "pull-stream": "^3.6.9" } } diff --git a/src/circuit/dialer.js b/src/circuit/dialer.js index 6185feb..55ff04b 100644 --- a/src/circuit/dialer.js +++ b/src/circuit/dialer.js @@ -3,7 +3,6 @@ const once = require('once') const PeerId = require('peer-id') const waterfall = require('async/waterfall') -const isFunction = require('lodash.isfunction') const multiaddr = require('multiaddr') const Connection = require('interface-connection').Connection @@ -138,7 +137,7 @@ class Dialer { * @private */ _dialPeer (dstMa, relay, cb) { - if (isFunction(relay)) { + if (typeof relay === 'function') { cb = relay relay = null } diff --git a/src/circuit/hop.js b/src/circuit/hop.js index 3fff2e0..17d9054 100644 --- a/src/circuit/hop.js +++ b/src/circuit/hop.js @@ -1,6 +1,6 @@ 'use strict' -const pull = require('pull-stream') +const pull = require('pull-stream/pull') const debug = require('debug') const PeerInfo = require('peer-info') const PeerId = require('peer-id') diff --git a/src/circuit/stream-handler.js b/src/circuit/stream-handler.js index 58cb6fc..895307b 100644 --- a/src/circuit/stream-handler.js +++ b/src/circuit/stream-handler.js @@ -1,6 +1,9 @@ 'use strict' -const pull = require('pull-stream') +const values = require('pull-stream/sources/values') +const collect = require('pull-stream/sinks/collect') +const empty = require('pull-stream/sources/empty') +const pull = require('pull-stream/pull') const lp = require('pull-length-prefixed') const handshake = require('pull-handshake') @@ -78,9 +81,9 @@ class StreamHandler { } pull( - pull.values([msg]), + values([msg]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { if (err) { log.err(err) this.shake.abort(err) @@ -128,7 +131,7 @@ class StreamHandler { // close stream pull( - pull.empty(), + empty(), this.rest() ) } diff --git a/test/dialer.spec.js b/test/dialer.spec.js index 0a045ac..2841899 100644 --- a/test/dialer.spec.js +++ b/test/dialer.spec.js @@ -10,7 +10,9 @@ const multiaddr = require('multiaddr') const PeerInfo = require('peer-info') const PeerId = require('peer-id') const waterfall = require('async/waterfall') -const pull = require('pull-stream') +const pull = require('pull-stream/pull') +const values = require('pull-stream/sources/values') +const asyncMap = require('pull-stream/throughs/async-map') const pair = require('pull-pair/duplex') const pb = require('pull-protocol-buffers') @@ -98,7 +100,7 @@ describe(`dialer tests`, function () { it(`should handle successful CAN_HOP`, (done) => { dialer._dialRelay.callsFake((_, cb) => { pull( - pull.values([{ + values([{ type: proto.CircuitRelay.type.HOP, code: proto.CircuitRelay.Status.SUCCESS }]), @@ -118,7 +120,7 @@ describe(`dialer tests`, function () { it(`should handle failed CAN_HOP`, function (done) { dialer._dialRelay.callsFake((_, cb) => { pull( - pull.values([{ + values([{ type: proto.CircuitRelay.type.HOP, code: proto.CircuitRelay.Status.HOP_CANT_SPEAK_RELAY }]), @@ -226,7 +228,7 @@ describe(`dialer tests`, function () { pull( p[0], pb.decode(proto.CircuitRelay), - pull.asyncMap((msg, cb) => { + asyncMap((msg, cb) => { expect(msg.dstPeer.addrs[0]).to.deep.equal(dstMa.buffer) cb(null, { type: proto.CircuitRelay.Type.STATUS, @@ -247,7 +249,7 @@ describe(`dialer tests`, function () { pull( p[0], pb.decode(proto.CircuitRelay), - pull.asyncMap((msg, cb) => { + asyncMap((msg, cb) => { expect(msg.dstPeer.addrs[0]).to.deep.equal(dstMa.buffer) cb(null, { type: proto.CircuitRelay.Type.STATUS, @@ -273,7 +275,7 @@ describe(`dialer tests`, function () { pull( p[0], pb.decode(proto.CircuitRelay), - pull.asyncMap((msg, cb) => { + asyncMap((msg, cb) => { expect(msg.dstPeer.addrs[0]).to.deep.equal(dstMa.buffer) cb(null, { type: proto.CircuitRelay.Type.STATUS, @@ -297,7 +299,7 @@ describe(`dialer tests`, function () { dialer._dialRelay.callsFake((_, cb) => { cb(null, conn) pull( - pull.values([{ + values([{ type: proto.CircuitRelay.Type.STATUS, code: proto.CircuitRelay.Status.MALFORMED_MESSAGE }]), diff --git a/test/hop.spec.js b/test/hop.spec.js index 1dc1c4e..f760432 100644 --- a/test/hop.spec.js +++ b/test/hop.spec.js @@ -10,7 +10,9 @@ const waterfall = require('async/waterfall') const PeerInfo = require('peer-info') const PeerId = require('peer-id') const multiaddr = require('multiaddr') -const pull = require('pull-stream') +const pull = require('pull-stream/pull') +const values = require('pull-stream/sources/values') +const collect = require('pull-stream/sinks/collect') const lp = require('pull-length-prefixed') const proto = require('../src/protocol') const StreamHandler = require('../src/circuit/stream-handler') @@ -359,19 +361,19 @@ describe('relay', () => { it('should create circuit', (done) => { pull( - pull.values([proto.CircuitRelay.encode({ + values([proto.CircuitRelay.encode({ type: proto.CircuitRelay.Type.STATUS, code: proto.CircuitRelay.Status.SUCCESS })]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { expect(err).to.not.exist() encoded.forEach((e) => dstShake.write(e)) pull( - pull.values([Buffer.from('hello')]), + values([Buffer.from('hello')]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { expect(err).to.not.exist() encoded.forEach((e) => srcShake.write(e)) @@ -414,12 +416,12 @@ describe('relay', () => { }) pull( - pull.values([proto.CircuitRelay.encode({ + values([proto.CircuitRelay.encode({ type: proto.CircuitRelay.Type.STATUS, code: proto.CircuitRelay.Status.STOP_RELAY_REFUSED })]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { expect(err).to.not.exist() encoded.forEach((e) => dstShake.write(e)) diff --git a/test/listener.spec.js b/test/listener.spec.js index e6907f2..cf5dad7 100644 --- a/test/listener.spec.js +++ b/test/listener.spec.js @@ -11,7 +11,9 @@ const handshake = require('pull-handshake') const Connection = require('interface-connection').Connection const proto = require('../src/protocol') const lp = require('pull-length-prefixed') -const pull = require('pull-stream') +const pull = require('pull-stream/pull') +const values = require('pull-stream/sources/values') +const collect = require('pull-stream/sinks/collect') const multicodec = require('../src/multicodec') const chai = require('chai') @@ -89,9 +91,9 @@ describe('listener', function () { } pull( - pull.values([proto.CircuitRelay.encode(relayMsg)]), + values([proto.CircuitRelay.encode(relayMsg)]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { expect(err).to.not.exist() encoded.forEach((e) => shake.write(e)) }) @@ -126,9 +128,9 @@ describe('listener', function () { } pull( - pull.values([proto.CircuitRelay.encode(relayMsg)]), + values([proto.CircuitRelay.encode(relayMsg)]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { expect(err).to.not.exist() encoded.forEach((e) => shake.write(e)) }) @@ -161,9 +163,9 @@ describe('listener', function () { }) pull( - pull.values([proto.CircuitRelay.encode(relayMsg)]), + values([proto.CircuitRelay.encode(relayMsg)]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { expect(err).to.not.exist() encoded.forEach((e) => shake.write(e)) }) @@ -198,9 +200,9 @@ describe('listener', function () { } pull( - pull.values([proto.CircuitRelay.encode(relayMsg)]), + values([proto.CircuitRelay.encode(relayMsg)]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { expect(err).to.not.exist() encoded.forEach((e) => shake.write(e)) }) @@ -223,9 +225,9 @@ describe('listener', function () { } pull( - pull.values([Buffer.from([relayMsg])]), + values([Buffer.from([relayMsg])]), lp.encode(), - pull.collect((err, encoded) => { + collect((err, encoded) => { expect(err).to.not.exist() encoded.forEach((e) => shake.write(e)) }),