koorchik / node-mole-rpc

Transport agnostic spec compliant JSON RPC client and server
MIT License
61 stars 13 forks source link

protocols that include methods whose name begins with underscore not supported #16

Open leomoisio opened 3 years ago

leomoisio commented 3 years ago

Underscore appears to be legal first character for a method name in jsonrpc 2.0 but the implementation won't allow such method to be found - there's an explicit check against it in https://github.com/koorchik/node-mole-rpc/blob/master/MoleServer.js#L54 and this is even documented to be the case.

So currently the library can't be used with a protocol that has such method names in use.

koorchik commented 3 years ago

It is done intentionally. A common convention is to start private methods with an underscore. Could you describe your use case where underscore is required? I could add an option to ignore this check

leomoisio commented 3 years ago

My use case is to work with a protocol that already has such methods whose names begin with underscore, and I can't change the protocol. I need to be able to receive and respond to such requests.

koorchik commented 3 years ago

Yes, it makes sense to add an option like "allowPrivateMethods" or something like that. Is it a real case or a hypothetical situation?

leomoisio commented 3 years ago

It's a real case for a proprietary API, it did block me from using the library for this particular purpose.

Would it make sense to allow the exposed server class have a resolver method that gets the name of the jsonrpc method and tells which method to call?