Skip to content
Snippets Groups Projects
Commit fd81e704 authored by murgatroid99's avatar murgatroid99
Browse files

Made method names more idiomatically cased for clients and servers

parent 749985eb
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,8 @@
*
*/
var s = require('underscore.string');
/**
* Get a function that deserializes a specific type of protobuf.
* @param {function()} cls The constructor of the message type to deserialize
......@@ -73,6 +75,9 @@ function fullyQualifiedName(value) {
return '';
}
var name = value.name;
if (value.className === 'Service.RPCMethod') {
name = s(name).capitalize().value();
}
if (value.hasOwnProperty('parent')) {
var parent_name = fullyQualifiedName(value.parent);
if (parent_name !== '') {
......
......@@ -119,10 +119,10 @@ function mathDivMany(stream) {
var server = new Server({
'math.Math' : {
Div: mathDiv,
Fib: mathFib,
Sum: mathSum,
DivMany: mathDivMany
div: mathDiv,
fib: mathFib,
sum: mathSum,
divMany: mathDivMany
}
});
......
......@@ -8,8 +8,9 @@
"dependencies": {
"bindings": "^1.2.1",
"nan": "~1.3.0",
"protobufjs": "murgatroid99/ProtoBuf.js",
"underscore": "^1.7.0",
"protobufjs": "murgatroid99/ProtoBuf.js"
"underscore.string": "^3.0.0"
},
"devDependencies": {
"mocha": "~1.21.0",
......
......@@ -33,6 +33,9 @@
var _ = require('underscore');
var capitalize = require('underscore.string/capitalize');
var decapitalize = require('underscore.string/decapitalize');
var client = require('./client.js');
var common = require('./common.js');
......@@ -352,10 +355,11 @@ function makeClientConstructor(service) {
method_type = 'unary';
}
}
SurfaceClient.prototype[method.name] = requester_makers[method_type](
prefix + method.name,
common.serializeCls(method.resolvedRequestType.build()),
common.deserializeCls(method.resolvedResponseType.build()));
SurfaceClient.prototype[decapitalize(method.name)] =
requester_makers[method_type](
prefix + capitalize(method.name),
common.serializeCls(method.resolvedRequestType.build()),
common.deserializeCls(method.resolvedResponseType.build()));
});
SurfaceClient.service = service;
......
......@@ -33,6 +33,9 @@
var _ = require('underscore');
var capitalize = require('underscore.string/capitalize');
var decapitalize = require('underscore.string/decapitalize');
var Server = require('./server.js');
var stream = require('stream');
......@@ -332,15 +335,16 @@ function makeServerConstructor(services) {
method_type = 'unary';
}
}
if (service_handlers[service_name][method.name] === undefined) {
if (service_handlers[service_name][decapitalize(method.name)] ===
undefined) {
throw new Error('Method handler for ' +
common.fullyQualifiedName(method) + ' not provided.');
}
var binary_handler = handler_makers[method_type](
service_handlers[service_name][method.name],
service_handlers[service_name][decapitalize(method.name)],
common.serializeCls(method.resolvedResponseType.build()),
common.deserializeCls(method.resolvedRequestType.build()));
server.register(prefix + method.name, binary_handler);
server.register(prefix + capitalize(method.name), binary_handler);
});
}, this);
}
......
......@@ -61,7 +61,7 @@ describe('Math client', function() {
});
it('should handle a single request', function(done) {
var arg = {dividend: 7, divisor: 4};
var call = math_client.Div(arg, function handleDivResult(err, value) {
var call = math_client.div(arg, function handleDivResult(err, value) {
assert.ifError(err);
assert.equal(value.quotient, 1);
assert.equal(value.remainder, 3);
......@@ -72,7 +72,7 @@ describe('Math client', function() {
});
});
it('should handle a server streaming request', function(done) {
var call = math_client.Fib({limit: 7});
var call = math_client.fib({limit: 7});
var expected_results = [1, 1, 2, 3, 5, 8, 13];
var next_expected = 0;
call.on('data', function checkResponse(value) {
......@@ -85,7 +85,7 @@ describe('Math client', function() {
});
});
it('should handle a client streaming request', function(done) {
var call = math_client.Sum(function handleSumResult(err, value) {
var call = math_client.sum(function handleSumResult(err, value) {
assert.ifError(err);
assert.equal(value.num, 21);
});
......@@ -103,7 +103,7 @@ describe('Math client', function() {
assert.equal(value.quotient, index);
assert.equal(value.remainder, 1);
}
var call = math_client.DivMany();
var call = math_client.divMany();
var response_index = 0;
call.on('data', function(value) {
checkResponse(response_index, value);
......
......@@ -59,9 +59,9 @@ describe('Surface server constructor', function() {
assert.throws(function() {
new Server({
'math.Math': {
'Div': function() {},
'DivMany': function() {},
'Fib': function() {}
'div': function() {},
'divMany': function() {},
'fib': function() {}
}
});
}, /math.Math.Sum/);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment