Comparing version 0.0.2 to 0.0.3
'use strict'; | ||
var BograchClient = require('./bograch-client'); | ||
var BograchWorker = require('./bograch-worker'); | ||
var Client = require('./client'); | ||
var Server = require('./server'); | ||
function Bograch() { | ||
this._providers = {}; | ||
this._transporters = {}; | ||
} | ||
Bograch.prototype.use = function (name, provider) { | ||
if (!provider) { | ||
provider = name; | ||
if (!provider) { | ||
throw new Error('Bograch use must receive a provider'); | ||
Bograch.prototype.use = function (name, transporter) { | ||
if (!transporter) { | ||
transporter = name; | ||
if (!transporter) { | ||
throw new Error('Bograch use must receive a transporter'); | ||
} | ||
name = provider.name; | ||
name = transporter.name; | ||
} | ||
if (!name) { throw new Error('Bograch providers must have a name'); } | ||
if (!name) { throw new Error('Bograch transporters must have a name'); } | ||
this._providers[name] = provider; | ||
this._transporters[name] = transporter; | ||
this[name + 'Client'] = function (options) { | ||
var client = new Client(transporter, options); | ||
return client; | ||
}; | ||
this[name + 'Worker'] = function (options) { | ||
var worker = new Server(transporter, options); | ||
return worker; | ||
}; | ||
return this; | ||
}; | ||
Bograch.prototype.client = function (name) { | ||
Bograch.prototype.client = function (name, options) { | ||
if (!name || typeof name !== 'string') { | ||
throw new TypeError('Can\'t get a Bograch client w/o a name'); | ||
} | ||
if (!this._providers[name]) { | ||
throw new Error('No provider with the specified name has been found'); | ||
if (!this._transporters[name]) { | ||
throw new Error('No transporter with the specified name has been found'); | ||
} | ||
var client = new BograchClient(this._providers[name]); | ||
var client = new Client(this._transporters[name], options); | ||
return client; | ||
}; | ||
Bograch.prototype.worker = function (name) { | ||
Bograch.prototype.server = function (name, options) { | ||
if (!name || typeof name !== 'string') { | ||
throw new TypeError('Can\'t get a Bograch worker w/o a name'); | ||
throw new TypeError('Can\'t get a Bograch server w/o a name'); | ||
} | ||
if (!this._providers[name]) { | ||
throw new Error('No provider with the specified name has been found'); | ||
if (!this._transporters[name]) { | ||
throw new Error('No transporter with the specified name has been found'); | ||
} | ||
var worker = new BograchWorker(this._providers[name]); | ||
var worker = new Server(this._transporters[name], options); | ||
return worker; | ||
@@ -44,0 +55,0 @@ }; |
{ | ||
"name": "bograch", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A communication gateway for NodeJS microservices.", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -10,26 +10,26 @@ 'use strict'; | ||
bo.use(); | ||
}).to.throw(Error, 'Bograch use must receive a provider'); | ||
}).to.throw(Error, 'Bograch use must receive a transporter'); | ||
}); | ||
it('should return an error if no provider with name was passed', function () { | ||
it('should return an error if no transporter with name was passed', function () { | ||
expect(function () { | ||
bo.use('foo'); | ||
}).to.throw(Error, 'Bograch providers must have a name'); | ||
}).to.throw(Error, 'Bograch transporters must have a name'); | ||
}); | ||
it('should not return error if passed provider with name', function () { | ||
var provider = { | ||
it('should not return error if passed transporter with name', function () { | ||
var transporter = { | ||
name: 'foo' | ||
}; | ||
expect(function () { | ||
bo.use(provider); | ||
bo.use(transporter); | ||
}).not.to.throw(Error); | ||
}); | ||
it('should not return error if passed provider name and provider with name', function () { | ||
var provider = { | ||
it('should not return error if passed transporter name and transporter with name', function () { | ||
var transporter = { | ||
name: 'foo' | ||
}; | ||
expect(function () { | ||
bo.use('bar', provider); | ||
bo.use('bar', transporter); | ||
}).not.to.throw(Error); | ||
@@ -41,6 +41,6 @@ }); | ||
before(function () { | ||
bo._providers = {}; | ||
bo._transporters = {}; | ||
}); | ||
it('should thrown error if no provider name was passed', function () { | ||
it('should thrown error if no transporter name was passed', function () { | ||
expect(function () { | ||
@@ -51,39 +51,40 @@ bo.client(); | ||
it('should throw error if no provider with the passed name was found', function () { | ||
it('should throw error if no transporter with the passed name was found', function () { | ||
expect(function () { | ||
bo.client('foo'); | ||
}).to.throw(Error, 'No provider with the specified name has been found'); | ||
bo.client('foo', { name: 'test' }); | ||
}).to.throw(Error, 'No transporter with the specified name has been found'); | ||
}); | ||
it('should return client if provider is found', function () { | ||
it('should return client if transporter is found', function () { | ||
bo.use('foo', { | ||
name: 'foo' | ||
}); | ||
expect(bo.client('foo')).not.to.be.a('null'); | ||
expect(bo.client('foo', { name: 'test' })).not.to.be.a('null'); | ||
}); | ||
}); | ||
describe('Bograch worker', function () { | ||
describe('Bograch server', function () { | ||
before(function () { | ||
bo._providers = {}; | ||
bo._transporters = {}; | ||
}); | ||
it('should thrown error if no provider name was passed', function () { | ||
it('should thrown error if no transporter name was passed', function () { | ||
expect(function () { | ||
bo.worker(); | ||
}).to.throw(TypeError, 'Can\'t get a Bograch worker w/o a name'); | ||
bo.server(); | ||
}).to.throw(TypeError, 'Can\'t get a Bograch server w/o a name'); | ||
}); | ||
it('should throw error if no provider with the passed name was found', function () { | ||
it('should throw error if no transporter with the passed name was found', function () { | ||
expect(function () { | ||
bo.worker('foo'); | ||
}).to.throw(Error, 'No provider with the specified name has been found'); | ||
bo.server('foo', { name: 'test' }); | ||
}).to.throw(Error, 'No transporter with the specified name has been found'); | ||
}); | ||
it('should return client if provider is found', function () { | ||
it('should return server if transporter is found', function () { | ||
bo.use('foo', { | ||
name: 'foo' | ||
name: 'foo', | ||
on: function () {} | ||
}); | ||
expect(bo.worker('foo')).not.to.be.a('null'); | ||
expect(bo.server('foo', { name: 'test' })).not.to.be.a('null'); | ||
}); | ||
}); |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
30166
15
274
4