diff options
-rw-r--r-- | src/node/common.js | 5 | ||||
-rw-r--r-- | src/node/examples/math_server.js | 8 | ||||
-rw-r--r-- | src/node/package.json | 3 | ||||
-rw-r--r-- | src/node/surface_client.js | 12 | ||||
-rw-r--r-- | src/node/surface_server.js | 10 | ||||
-rw-r--r-- | src/node/test/math_client_test.js | 8 | ||||
-rw-r--r-- | src/node/test/surface_test.js | 6 |
7 files changed, 33 insertions, 19 deletions
diff --git a/src/node/common.js b/src/node/common.js index 656a4aca95..c9684f0ec4 100644 --- a/src/node/common.js +++ b/src/node/common.js @@ -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 !== '') { diff --git a/src/node/examples/math_server.js b/src/node/examples/math_server.js index 366513dc17..d649b4fd6d 100644 --- a/src/node/examples/math_server.js +++ b/src/node/examples/math_server.js @@ -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 } }); diff --git a/src/node/package.json b/src/node/package.json index ed93c4ff41..7051f1c849 100644 --- a/src/node/package.json +++ b/src/node/package.json @@ -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", diff --git a/src/node/surface_client.js b/src/node/surface_client.js index 77dab5ca6f..996e3d101f 100644 --- a/src/node/surface_client.js +++ b/src/node/surface_client.js @@ -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; diff --git a/src/node/surface_server.js b/src/node/surface_server.js index b6e0c37b4c..0b19d96b4c 100644 --- a/src/node/surface_server.js +++ b/src/node/surface_server.js @@ -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); } diff --git a/src/node/test/math_client_test.js b/src/node/test/math_client_test.js index 45c956d179..5ddf75a200 100644 --- a/src/node/test/math_client_test.js +++ b/src/node/test/math_client_test.js @@ -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); diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 8d0d8ec3bc..34f1a156eb 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -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/); |