Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bograch

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bograch - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

bograch-0.0.11.tgz

30

lib/client.js
'use strict';
var createPublicMethodName = require('./create-method-name');
var ServerError = require('./server-error');

@@ -17,2 +18,3 @@ function Client(transporter, options, cb) {

this._name = options.name;
this._ttl = options.ttl || 1000;
this.methods = {};

@@ -26,3 +28,3 @@

}
this.register(methods);

@@ -50,3 +52,3 @@ return cb(null, this);

var cb;
if (!methodName) {

@@ -58,13 +60,29 @@ throw new TypeError('Bograch.on requires a methodName');

}
while (typeof arguments[++i] !== 'function' && i < arguments.length) {
args.push(arguments[i]);
}
if (typeof arguments[i] === 'function') {
cb = arguments[i];
}
var publicMethodName = createPublicMethodName(this._name, methodName);
this._transporter.call(publicMethodName, args, cb);
var killed = false;
if (cb) {
var timeoutId = setTimeout(function () {
killed = true;
cb(new ServerError('responseTimeout',
'Method execution exceeded the time limit of `' + this._ttl + '`'));
}.bind(this), this._ttl);
}
this._transporter.call(publicMethodName, args, function () {
if (!killed && cb) {
clearTimeout(timeoutId);
cb.apply({}, arguments);
}
});
};

@@ -71,0 +89,0 @@

7

lib/server.js

@@ -44,3 +44,8 @@ 'use strict';

args.push(cb || function () {});
method.apply({}, args);
try {
method.apply({}, args);
} catch (err) {
cb(err);
}
});

@@ -47,0 +52,0 @@ };

{
"name": "bograch",
"version": "0.0.10",
"version": "0.0.11",
"description": "A communication gateway for NodeJS microservices.",

@@ -5,0 +5,0 @@ "main": "./lib",

@@ -20,3 +20,3 @@ 'use strict';

});
it('should throw an error if no callback function is passed', function () {

@@ -27,3 +27,3 @@ expect(function () {

});
it('should throw an error if invalid callback function is passed', function () {

@@ -34,3 +34,3 @@ expect(function () {

});
it('should not throw an exception if the second parameter is a callback function', function () {

@@ -47,3 +47,3 @@ expect(function () {

});
it('should pass all the arguments', function (done) {

@@ -58,2 +58,22 @@ boServer.on('sum', function (a, b, cb) {

});
it('should return error if remote method has an uncaught exception', function (done) {
boServer.on('exception', function (cb) {
throw 'foo';
});
boClient.call('exception', function (err) {
expect(err).to.be.equal('foo');
done();
});
});
it('should return error if remote method timed out', function (done) {
boServer.on('timeout', function (cb) {
'I am not calling the callback function. Ever!';
});
boClient.call('timeout', function (err) {
expect(err.type).to.be.equal('responseTimeout');
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc