protobuf.js
protobuf.js copied to clipboard
Add methodName to rpc methods to allow to determine methods after code minification
In current state when static code is minified, generated method names are replaced by single letter names.
This make almost impossible to implement correctly transport layer for services.
Those changes adds new property to methods: methodName
, that contains string to original method name.
After this change you should determine called method using methodName
instead of name
, but old behavior is still preserved.
Also this commit create new exported type: RpcServiceMethod
to allow to access new property in type safe way.
Runtime generated code was also extended with generated code. Although methodName is appended in every runtime rpc call - I didn't found a way how to make it one time action in method generation.
Test case was also extended to make sure that methodName
will containe the same value that name
.
Bonus: I fixed Travis build issue for you :-) I don't like to have that red X in my PR ;-)
@dcodeIO any chance for merge?
Can't you just do:
function rpcImpl(method, ...) {
if (method == MyService.prototype.myMethod) { ... }
}
@dcodeIO then you would need rpc transport layer to be dependent on all services. and you would need implement handling of those messages manually for every service, so at this point it is easier to use pure protobuf serialization and implement all rpc manually.
@dcodeIO This is quite cumbersome when building a transport that works with any proto file. Please consider merging this pr.
Does this solve it? Idea is that defining the name
property explicitly should survive minification.
@dcodeIO how to get a full method name (in format of ${serviceName}/${methodName}
) at runtime? The name
property gives access to the method name only, the service name is still missing.