Made method names more idiomatically cased for clients and servers

pull/145/head
murgatroid99 10 years ago
parent 749985eb8d
commit fd81e70443
  1. 5
      src/node/common.js
  2. 8
      src/node/examples/math_server.js
  3. 3
      src/node/package.json
  4. 12
      src/node/surface_client.js
  5. 10
      src/node/surface_server.js
  6. 8
      src/node/test/math_client_test.js
  7. 6
      src/node/test/surface_test.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 !== '') {

@ -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/);

Loading…
Cancel
Save