emitter-pubsub-broker
Advanced tools
Comparing version 0.6.0 to 1.0.0
@@ -1,5 +0,14 @@ | ||
# Change Log | ||
# Changelog | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
## [1.0.0](https://github.com/an-sh/emitter-pubsub-broker/compare/v0.5.0...v1.0.0) (2019-12-14) | ||
### ⚠ BREAKING CHANGES | ||
* Now only Node.js version 10 and later are supported | ||
* update packages ([7496a7f](https://github.com/an-sh/emitter-pubsub-broker/commit/7496a7fc33980294b970a5d1f710289aed232963)) | ||
<a name="0.5.0"></a> | ||
@@ -6,0 +15,0 @@ # [0.5.0](https://github.com/an-sh/emitter-pubsub-broker/compare/v0.4.0...v0.5.0) (2017-01-06) |
'use strict' | ||
var semver = require('semver') | ||
// Choosing between a source ES6 syntax and a transpiled ES5. | ||
if (semver.lt(process.version, '6.0.0')) { | ||
module.exports = require('./lib/EmitterPubsubBroker') | ||
} else { | ||
module.exports = require('./src/EmitterPubsubBroker') | ||
} | ||
module.exports = require('./src/EmitterPubsubBroker') |
{ | ||
"name": "emitter-pubsub-broker", | ||
"version": "0.6.0", | ||
"version": "1.0.0", | ||
"private": false, | ||
@@ -8,7 +8,4 @@ "description": "An utility for connecting EventEmitters via a pubsub.", | ||
"scripts": { | ||
"compile": "babel src --out-dir lib", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", | ||
"generate-docs": "jsdoc --configure .jsdoc.json --verbose", | ||
"prepare": "npm run compile", | ||
"pretest": "npm run compile", | ||
"test": "nyc mocha" | ||
@@ -32,23 +29,20 @@ }, | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=10" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"bluebird": "^3.3.5", | ||
"eventemitter3": "^3.0.0", | ||
"ioredis": "^3.2.2", | ||
"msgpack-lite": "^0.1.20", | ||
"semver": "^5.3.0" | ||
"bluebird": "^3.7.2", | ||
"eventemitter3": "^4.0.0", | ||
"ioredis": "^4.14.1", | ||
"msgpack-lite": "^0.1.20" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.11.4", | ||
"babel-preset-es2015-node4": "^2.1.0", | ||
"chai": "^4.1.2", | ||
"codecov": "^3.0.0", | ||
"docdash": "^0.4.0", | ||
"chai": "^4.2.0", | ||
"codecov": "^3.6.1", | ||
"docdash": "^1.1.1", | ||
"event-to-promise": "^0.8.0", | ||
"jsdoc": "^3.4.0", | ||
"mocha": "^4.1.0", | ||
"nyc": "^11.4.1", | ||
"standard": "^10.0.3" | ||
"jsdoc": "^3.6.3", | ||
"mocha": "^6.2.2", | ||
"nyc": "^14.1.1", | ||
"standard": "^14.3.1" | ||
}, | ||
@@ -55,0 +49,0 @@ "nyc": { |
@@ -49,3 +49,3 @@ | ||
[API](https://an-sh.github.io/emitter-pubsub-broker/0.5/index.html) | ||
[API](https://an-sh.github.io/emitter-pubsub-broker/1.0/index.html) | ||
documentation is available online. | ||
@@ -52,0 +52,0 @@ |
@@ -71,3 +71,3 @@ 'use strict' | ||
this.sub = new Redis(options) | ||
this.sub.subscribe().catchReturn() | ||
this.sub.subscribe().catch(() => {}) | ||
this.sub.on('messageBuffer', this._onMessage.bind(this)) | ||
@@ -79,3 +79,3 @@ this.sub.on('error', this.emit.bind(this)) | ||
_onMessage (buf, data) { | ||
let ch = buf.toString() | ||
const ch = buf.toString() | ||
this.emit('message', ch, data) | ||
@@ -221,3 +221,3 @@ } | ||
clients.add(client) | ||
let ch = this.prefix + channel | ||
const ch = this.prefix + channel | ||
return this.connector.subscribe(ch) | ||
@@ -231,3 +231,3 @@ } else { | ||
_channelRemoveClient (client, channel) { | ||
let clients = this.channelClients.get(channel) | ||
const clients = this.channelClients.get(channel) | ||
let nclients | ||
@@ -239,3 +239,3 @@ if (clients != null) { | ||
if (nclients === 0) { | ||
let ch = this.prefix + channel | ||
const ch = this.prefix + channel | ||
return this.connector.unsubscribe(ch) | ||
@@ -280,3 +280,3 @@ } else { | ||
unsubscribe (client, channel) { | ||
let channels = this.clientChannels.get(client) | ||
const channels = this.clientChannels.get(client) | ||
if (channels) { | ||
@@ -295,3 +295,3 @@ channels.delete(channel) | ||
unsubscribeAll (client) { | ||
let channels = this.clientChannels.get(client) | ||
const channels = this.clientChannels.get(client) | ||
this.clientChannels.delete(client) | ||
@@ -315,4 +315,4 @@ if (channels) { | ||
publish (channel, name, ...args) { | ||
let ch = this.prefix + channel | ||
return this._makeMessage({name, args}) | ||
const ch = this.prefix + channel | ||
return this._makeMessage({ name, args }) | ||
.then(msg => this.connector.publish(ch, msg)) | ||
@@ -332,5 +332,5 @@ } | ||
send (client, channel, name, ...args) { | ||
let ch = this.prefix + channel | ||
let sender = client.id | ||
return this._makeMessage({sender, name, args}) | ||
const ch = this.prefix + channel | ||
const sender = client.id | ||
return this._makeMessage({ sender, name, args }) | ||
.then(msg => this.connector.publish(ch, msg)) | ||
@@ -374,7 +374,7 @@ } | ||
this._unpackMessage(data).then(message => { | ||
let channel = ch.slice(this.prefix.length) | ||
let clients = this.channelClients.get(channel) | ||
const channel = ch.slice(this.prefix.length) | ||
const clients = this.channelClients.get(channel) | ||
/* istanbul ignore else */ | ||
if (clients) { | ||
let args = this.includeChannel | ||
const args = this.includeChannel | ||
? [message.name, channel, ...message.args] | ||
@@ -381,0 +381,0 @@ : [message.name, ...message.args] |
@@ -12,4 +12,4 @@ 'use strict' | ||
const configs = [ { name: 'memory', connect: '' }, | ||
{ name: 'redis', connect: 'redis://localhost:6379' } ] | ||
const configs = [{ name: 'memory', connect: '' }, | ||
{ name: 'redis', connect: 'redis://localhost:6379' }] | ||
@@ -24,3 +24,3 @@ let broker | ||
if (broker) { | ||
return broker.close().catchReturn() | ||
return broker.close().catch(() => {}) | ||
} | ||
@@ -31,3 +31,3 @@ }) | ||
configs.forEach(state => describe(state.name, function () { | ||
let { connect } = state | ||
const { connect } = state | ||
@@ -40,7 +40,7 @@ it('should create an object', function () { | ||
broker = new EmitterPubsubBroker(connect) | ||
let client = new EventEmitter() | ||
const client = new EventEmitter() | ||
return broker.subscribe(client, 'my-channel').then(() => { | ||
broker.publish('my-channel', 'myEvent', 1, '2') | ||
return eventToPromise(client, 'myEvent', {array: true}).then(args => { | ||
let [x, y] = args | ||
return eventToPromise(client, 'myEvent', { array: true }).then(args => { | ||
const [x, y] = args | ||
expect(x).equal(1) | ||
@@ -53,6 +53,6 @@ expect(y).equal('2') | ||
it('should emit published encoded messages', function (done) { | ||
broker = new EmitterPubsubBroker({connect, encoder: JSON.stringify, method: 'send'}) | ||
let client = new EventEmitter() | ||
broker = new EmitterPubsubBroker({ connect, encoder: JSON.stringify, method: 'send' }) | ||
const client = new EventEmitter() | ||
client.send = function (args) { | ||
let [ev, x, y] = JSON.parse(args) | ||
const [ev, x, y] = JSON.parse(args) | ||
expect(ev).equal('myEvent') | ||
@@ -69,10 +69,10 @@ expect(x).equal(1) | ||
it('should use custom serialisation', function () { | ||
let serialize = (data) => Promise.try(() => msgpack.encode(data)) | ||
let deserialize = (data) => Promise.try(() => msgpack.decode(data)) | ||
broker = new EmitterPubsubBroker({connect, serialize, deserialize}) | ||
let client = new EventEmitter() | ||
const serialize = (data) => Promise.try(() => msgpack.encode(data)) | ||
const deserialize = (data) => Promise.try(() => msgpack.decode(data)) | ||
broker = new EmitterPubsubBroker({ connect, serialize, deserialize }) | ||
const client = new EventEmitter() | ||
return broker.subscribe(client, 'my-channel').then(() => { | ||
broker.publish('my-channel', 'myEvent', 1, '2') | ||
return eventToPromise(client, 'myEvent', {array: true}).then(args => { | ||
let [x, y] = args | ||
return eventToPromise(client, 'myEvent', { array: true }).then(args => { | ||
const [x, y] = args | ||
expect(x).equal(1) | ||
@@ -85,8 +85,8 @@ expect(y).equal('2') | ||
it('should prepend a channel argument', function () { | ||
broker = new EmitterPubsubBroker({connect, includeChannel: true}) | ||
let client = new EventEmitter() | ||
broker = new EmitterPubsubBroker({ connect, includeChannel: true }) | ||
const client = new EventEmitter() | ||
return broker.subscribe(client, 'my-channel').then(() => { | ||
broker.publish('my-channel', 'myEvent', 1, '2') | ||
return eventToPromise(client, 'myEvent', {array: true}).then(args => { | ||
let [ch, x, y] = args | ||
return eventToPromise(client, 'myEvent', { array: true }).then(args => { | ||
const [ch, x, y] = args | ||
expect(ch).equal('my-channel') | ||
@@ -102,4 +102,4 @@ expect(x).equal(1) | ||
this.slow(2000) | ||
broker = new EmitterPubsubBroker({connect, includeChannel: true}) | ||
let client = new EventEmitter() | ||
broker = new EmitterPubsubBroker({ connect, includeChannel: true }) | ||
const client = new EventEmitter() | ||
return broker.subscribe(client, 'my-channel') | ||
@@ -118,4 +118,4 @@ .then(() => broker.unsubscribe(client, 'my-channel')) | ||
broker = new EmitterPubsubBroker(connect) | ||
let client1 = new EventEmitter() | ||
let client2 = new EventEmitter() | ||
const client1 = new EventEmitter() | ||
const client2 = new EventEmitter() | ||
client1.id = 'uniq' | ||
@@ -135,3 +135,3 @@ return broker.subscribe(client1, 'my-channel') | ||
broker = new EmitterPubsubBroker(connect) | ||
let client1 = new EventEmitter() | ||
const client1 = new EventEmitter() | ||
return Promise.all([ | ||
@@ -141,3 +141,3 @@ broker.subscribe(client1, 'my-channel'), | ||
.then(() => { | ||
let subs = broker.getSubscriptions(client1) | ||
const subs = broker.getSubscriptions(client1) | ||
expect(subs.size).equal(2) | ||
@@ -151,4 +151,4 @@ expect(subs.has('my-channel')).true | ||
broker = new EmitterPubsubBroker(connect) | ||
let client1 = new EventEmitter() | ||
let client2 = new EventEmitter() | ||
const client1 = new EventEmitter() | ||
const client2 = new EventEmitter() | ||
return Promise.all([ | ||
@@ -158,3 +158,3 @@ broker.subscribe(client1, 'channel'), | ||
.then(() => { | ||
let subs = broker.getClients('channel') | ||
const subs = broker.getClients('channel') | ||
expect(subs.size).equal(2) | ||
@@ -170,3 +170,3 @@ expect(subs.has(client1)).true | ||
broker = new EmitterPubsubBroker(connect) | ||
let client1 = new EventEmitter() | ||
const client1 = new EventEmitter() | ||
return Promise.all([ | ||
@@ -186,3 +186,3 @@ broker.subscribe(client1, 'my-channel'), | ||
broker = new EmitterPubsubBroker(connect) | ||
let client1 = new EventEmitter() | ||
const client1 = new EventEmitter() | ||
return broker.unsubscribe(client1, 'my-channel') | ||
@@ -193,3 +193,3 @@ }) | ||
broker = new EmitterPubsubBroker(connect) | ||
let client1 = new EventEmitter() | ||
const client1 = new EventEmitter() | ||
return broker.unsubscribeAll(client1) | ||
@@ -196,0 +196,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4
8
1
24969
12
554
+ Addeddebug@4.3.7(transitive)
+ Addedeventemitter3@4.0.7(transitive)
+ Addedioredis@4.28.5(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addedp-map@2.1.0(transitive)
+ Addedredis-errors@1.2.0(transitive)
+ Addedredis-parser@3.0.0(transitive)
+ Addedstandard-as-callback@2.1.0(transitive)
- Removedsemver@^5.3.0
- Removeddebug@2.6.9(transitive)
- Removedeventemitter3@3.1.2(transitive)
- Removedflexbuffer@0.0.6(transitive)
- Removedioredis@3.2.2(transitive)
- Removedlodash.assign@4.2.0(transitive)
- Removedlodash.bind@4.2.1(transitive)
- Removedlodash.clone@4.5.0(transitive)
- Removedlodash.clonedeep@4.5.0(transitive)
- Removedlodash.difference@4.5.0(transitive)
- Removedlodash.foreach@4.5.0(transitive)
- Removedlodash.isempty@4.4.0(transitive)
- Removedlodash.keys@4.2.0(transitive)
- Removedlodash.noop@3.0.1(transitive)
- Removedlodash.partial@4.2.1(transitive)
- Removedlodash.pick@4.4.0(transitive)
- Removedlodash.sample@4.2.1(transitive)
- Removedlodash.shuffle@4.2.0(transitive)
- Removedlodash.values@4.3.0(transitive)
- Removedms@2.0.0(transitive)
- Removedredis-parser@2.6.0(transitive)
- Removedsemver@5.7.2(transitive)
Updatedbluebird@^3.7.2
Updatedeventemitter3@^4.0.0
Updatedioredis@^4.14.1