json-rpc-engine
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -8,3 +8,3 @@ module.exports = asMiddleware | ||
// copy engine result onto response | ||
res.result = engineRes.result | ||
Object.assign(res, engineRes) | ||
end() | ||
@@ -11,0 +11,0 @@ }) |
{ | ||
"name": "json-rpc-engine", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "a tool for processing JSON RPC", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test/basic.js" | ||
"test": "node test/index.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "author": "", |
@@ -53,8 +53,10 @@ # RpcEngine | ||
RpcEngines can be nested by converting them to middleware `engine.asMiddleware()` | ||
RpcEngines can be nested by converting them to middleware `asMiddleware(engine)` | ||
```js | ||
const asMiddleware = require('json-rpc-engine/lib/asMiddleware') | ||
let engine = new RpcEngine() | ||
let subengine = new RpcEngine() | ||
engine.push(subengine.asMiddleware()) | ||
engine.push(asMiddleware(subengine)) | ||
``` | ||
@@ -61,0 +63,0 @@ |
@@ -17,3 +17,3 @@ const RpcEngine = require('../index.js') | ||
engine.push(asMiddleware(engine)) | ||
engine.push(asMiddleware(subengine)) | ||
@@ -32,1 +32,56 @@ let payload = { id: 1, jsonrpc: '2.0', method: 'hello' } | ||
}) | ||
test('asMiddleware - decorate res', function(t){ | ||
let engine = new RpcEngine() | ||
let subengine = new RpcEngine() | ||
let originalReq = undefined | ||
subengine.push(function(req, res, next, end){ | ||
originalReq = req | ||
res.xyz = true | ||
end() | ||
}) | ||
engine.push(asMiddleware(subengine)) | ||
let payload = { id: 1, jsonrpc: '2.0', method: 'hello' } | ||
engine.handle(payload, function(err, res){ | ||
t.ifError(err, 'did not error') | ||
t.ok(res, 'has res') | ||
t.equals(originalReq.id, res.id, 'id matches') | ||
t.equals(originalReq.jsonrpc, res.jsonrpc, 'jsonrpc version matches') | ||
t.ok(res.xyz, 'res non-result prop was transfered') | ||
t.end() | ||
}) | ||
}) | ||
test('asMiddleware - decorate req', function(t){ | ||
let engine = new RpcEngine() | ||
let subengine = new RpcEngine() | ||
let originalReq = undefined | ||
subengine.push(function(req, res, next, end){ | ||
originalReq = req | ||
req.xyz = true | ||
end() | ||
}) | ||
engine.push(asMiddleware(subengine)) | ||
let payload = { id: 1, jsonrpc: '2.0', method: 'hello' } | ||
engine.handle(payload, function(err, res){ | ||
t.ifError(err, 'did not error') | ||
t.ok(res, 'has res') | ||
t.equals(originalReq.id, res.id, 'id matches') | ||
t.equals(originalReq.jsonrpc, res.jsonrpc, 'jsonrpc version matches') | ||
t.ok(originalReq.xyz, 'req prop was transfered') | ||
t.end() | ||
}) | ||
}) |
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
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
10574
249
77
0