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