@wix/be-http-binding
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -9,6 +9,6 @@ | ||
function http(binding, requestMessage, responseMessage, methodOptions) { | ||
function http(binding, requestMessage, responseMessage, methodOptions = {}) { | ||
return { | ||
async invoke(message, options) { | ||
const result = await binding.invokeWith(methodOptions.invoker || options.invoker, requestMessage.fromValue(message)); | ||
async invoke(message, options = {}) { | ||
const result = await binding.invoke(requestMessage.fromValue(message), mergeOptions(methodOptions, options)); | ||
@@ -18,2 +18,9 @@ return responseMessage.fromValue(result); | ||
}; | ||
function mergeOptions(a, b) { | ||
return { | ||
...a, | ||
...b | ||
}; | ||
} | ||
} | ||
@@ -39,3 +46,4 @@ | ||
return { | ||
async invokeWith(invoker, rawMessage) { | ||
async invoke(rawMessage, options) { | ||
const invoker = options.invoker; | ||
const {uri, message} = getUriAndMessage(rawMessage); | ||
@@ -45,3 +53,4 @@ | ||
method, | ||
uri | ||
uri, | ||
options | ||
}; | ||
@@ -48,0 +57,0 @@ |
@@ -36,3 +36,4 @@ const {http, get, post, put} = require('./http-binding'); | ||
method: 'get', | ||
uri: '/pass?a=1' | ||
uri: '/pass?a=1', | ||
message: undefined | ||
}); | ||
@@ -88,11 +89,37 @@ }); | ||
it('should pass options to invoker', async() => { | ||
const givenMethod = http(get('/pass'), message, message, {invoker, methodOption: 'a'}); | ||
await givenMethod.invoke({ | ||
a: 1, | ||
b: 2 | ||
}, { | ||
invocationOption: 'b' | ||
}); | ||
const lastOptions = invoker.lastOptions(); | ||
expect(lastOptions.methodOption).to.equal('a'); | ||
expect(lastOptions.invocationOption).to.equal('b'); | ||
}); | ||
function testInvoker(fn) { | ||
const invocations = []; | ||
let lastOptions; | ||
return { | ||
invoke(request) { | ||
invocations.push(request); | ||
invoke(request) { | ||
invocations.push({ | ||
method: request.method, | ||
uri: request.uri, | ||
message: request.message | ||
}); | ||
lastOptions = request.options; | ||
return fn(request); | ||
}, | ||
lastOptions() { | ||
return lastOptions; | ||
}, | ||
invocations() { | ||
@@ -99,0 +126,0 @@ return invocations; |
{ | ||
"name": "@wix/be-http-binding", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"author": "Mantas Indrašius <mantasi@wix.com>", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
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
31882
516