protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

Add methodName to rpc methods to allow to determine methods after code minification

Open Szpadel opened this issue 7 years ago • 6 comments

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

Szpadel avatar Jul 05 '17 09:07 Szpadel

@dcodeIO any chance for merge?

Szpadel avatar Jul 11 '17 18:07 Szpadel

Can't you just do:

function rpcImpl(method, ...) {
  if (method == MyService.prototype.myMethod) { ... }
}

dcodeIO avatar Nov 26 '17 22:11 dcodeIO

@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.

Szpadel avatar Nov 26 '17 23:11 Szpadel

@dcodeIO This is quite cumbersome when building a transport that works with any proto file. Please consider merging this pr.

MHDante avatar Mar 23 '18 05:03 MHDante

Does this solve it? Idea is that defining the name property explicitly should survive minification.

dcodeIO avatar May 18 '18 09:05 dcodeIO

@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.

avakhrenev avatar May 21 '18 09:05 avakhrenev