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

jayson

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jayson - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

10

examples/promise/client.js

@@ -7,4 +7,10 @@ var jayson = require('../../promise');

client.request('add', [1, 2, 3, 4, 5]).then(function(response) {
console.log(response.result); // 15!
var reqs = [
client.request('add', [1, 2, 3, 4, 5]),
client.request('rejection', [])
];
Promise.all(reqs).then(function(responses) {
console.log(responses[0].result);
console.log(responses[1].error);
});

@@ -5,2 +5,3 @@ var jayson = require('../../promise');

var server = jayson.server({
add: function(args) {

@@ -11,5 +12,14 @@ return new Promise(function(resolve, reject) {

});
},
// example on how to reject
rejection: function(args) {
return new Promise(function(resolve, reject) {
// server.error just returns {code: 501, message: 'not implemented'}
reject(server.error(501, 'not implemented'));
});
}
});
server.http().listen(3000);

9

lib/utils.js

@@ -188,3 +188,3 @@ var _ = require('lodash');

Utils.parseBody(req, options, function(err, request) {
if(err) return respond(err, 500);
if(err) return respond(err, 400);

@@ -213,3 +213,4 @@ server.call(request, function(error, success) {

function respond(body, code, headers) {
function respond(response, code, headers) {
var body = response instanceof Error ? response.toString() : response;
server.emit('http response', res, req);

@@ -257,3 +258,3 @@ res.writeHead(code, headers || {});

var body = func.toString();
var args = /^function .*?\((.+?)\)/.exec(body);
var args = /^(?:function )*.*?\((.+?)\)/.exec(body);
if(!args) return [];

@@ -439,3 +440,3 @@ var list = (args.pop() || '').split(',');

&& typeof(error.code) === 'number'
&& parseInt(error.code) == error.code
&& parseInt(error.code, 10) === error.code
&& typeof(error.message) === 'string'

@@ -442,0 +443,0 @@ )

{
"name": "jayson",
"version": "2.0.2",
"version": "2.0.3",
"description": "JSON-RPC 1.0/2.0 compliant server and client",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -16,3 +16,3 @@ var Method = require('./method');

options = options || {};
options.methodConstructor = Method;
options.methodConstructor = options.methodConstructor || Method;
jayson.Server.call(this, methods, options);

@@ -19,0 +19,0 @@ };

@@ -138,3 +138,3 @@ # Jayson

- Install the development packages by executing `npm install --dev`
- Run the tests with `make test`
- Run the tests with `npm run test`

@@ -914,2 +914,3 @@ ## Usage

var server = jayson.server({
add: function(args) {

@@ -920,3 +921,12 @@ return new Promise(function(resolve, reject) {

});
},
// example on how to reject
rejection: function(args) {
return new Promise(function(resolve, reject) {
// server.error just returns {code: 501, message: 'not implemented'}
reject(server.error(501, 'not implemented'));
});
}
});

@@ -936,4 +946,10 @@

client.request('add', [1, 2, 3, 4, 5]).then(function(response) {
console.log(response.result); // 15!
var reqs = [
client.request('add', [1, 2, 3, 4, 5]),
client.request('rejection', [])
];
Promise.all(reqs).then(function(responses) {
console.log(responses[0].result);
console.log(responses[1].error);
});

@@ -944,3 +960,3 @@ ```

* JSON-RPC errors will not result in rejection of the Promise. It is however possible that a future version will include a client setting to have JSON-RPC errors result in rejection.
* JSON-RPC errors will not result in rejection of the Promise. It is however possible that a future version will include a client setting to have JSON-RPC errors result in rejection. Please note that network errors and the like will result in rejection.
* A `Promise` is considered to have been returned from a server method if the returned object has a property `then` that is a function.

@@ -953,2 +969,2 @@

Please make sure to follow the style of the project, and lint your code with `make lint` before submitting a patch.
Please make sure to follow the style of the project, and lint your code with `npm run lint` before submitting a patch.

@@ -35,2 +35,21 @@ var should = require('should');

it('should not crash when given invalid JSON', function(done) {
var reqOptions = {
hostname: 'localhost',
port: 3000,
method: 'POST',
headers: {'Content-Type': 'application/json'}
};
var req = http.request(reqOptions);
req.end('invalid json', 'utf8');
req.on('response', function(res) {
var body = '';
res.on('data', function(chunk) { body += chunk; });
res.on('end', function() {
res.statusCode.should.equal(400)
done();
});
});
});
});

@@ -37,0 +56,0 @@

@@ -112,2 +112,17 @@ var should = require('should');

it('should return the correct paremters when passed an ES6 style function with zero parameters', function() {
var func = () => {};
var result = utils.getParameterNames(func);
should.exist(result);
result.should.be.instanceof(Array).and.have.length(0);
});
it('should return the correct paremters when passed an ES6 style function with more than zero parameters', function() {
var func = (b, c, a) => {};
var result = utils.getParameterNames(func);
should.exist(result);
result.should.be.instanceof(Array).and.have.length(func.length);
result.should.containDeep(['b', 'c', 'a']);
});
});

@@ -114,0 +129,0 @@

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