package
Minimalist RPC library.
npm install rpc-engineGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Estimated unpacked size across 1 packages.
22.5 kB
Includes dependencies.
Minimalist RPC library.
Other stuff seems really intent on making serialization or transport decisions for me.
JSON-RPC without the JSON.
import Rpc from 'rpc-engine'
const a = new Rpc()
a.methods.add = (a, b) => {
return a + b
}
const b = new Rpc
$ npm run test
$ npm run test-browser # visit http://localhost:7357/testconst rpc = new RpcEngine(opts)opts An optional Object. All key-value pairs are copied to the instance.throw new RpcEngine.Error('error message')Throw an instance of this error during method handler execution when the intended audience is the remote caller. Alternatively myExistingError.insecureRpc = true can be set before rethrowing an existing error. Note that only { message, code, data } properties of errors are actually passed to the transport.
await rpc.call(method[, param1][, param2][, ...])Invokes a method on the remote side.
method A String.params Anything the transport (or rpc.serialize()) can handle. Optional.await rpc.notify(method[, param1][, param2][, ...])Invokes a method on the remote side without sending a message id.
method A String.params Anything the transport (or rpc.serialize()) can handle. Optional.await rpc.send(message)Messages destined for the remote site are passed to this method after processing. Consumers of this module are responsible for providing an implementation.
message Whatever format the transport likes. See rpc.serialize() to control this.await rpc.receive(message)Messages originating from the remote side must be passed to this method for processing. Consumers of this module are responsible for invoking this method somehow.
message An Object or something rpc.deserialize() can handle.await rpc.serialize(message)This method is an optional hook consumers of this module may implement to convert outgoing messages into something compatible with the transport being used.
message An Object.await rpc.deserialize(message)This method is an optional hook consumers of this module may implement to convert raw a incoming message into an Object.
message Whatever format the transport uses.rpc.close()This method can be invoked (for example, when the transport is closed) to immediately cancel any outstanding requests.
rpc.methodsAn Object representing the interface available to the remote peer. Keys are method names, values are functions.
rpc.defaultMethodA Function. If implemented, this method will be invoked for any incoming message or notification that does not match an explicit handler in rpc.methods.
rpc.objectModeA Boolean. RpcEngine defaults to passing parameters as an Array of positional arguments. Setting this property to true will pass them as key-value pairs instead. This is frequently needed for interop with other JSON-RPC implementations.
rpc.insecureErrorsA Boolean. When true, all errors thrown during method handler execution are returned to remote callers. To opt-in to sending a specific error to remote callers, set err.insecureRpc = true before throwing or throw an instance of RpcEngine.Error.
Event('error')Dispatched when something goes wrong while processing an incoming message.
Event(<arbitrary>)Dispatched when a notification is received, after any matching methods have been called.
rpc.insecureErrors and RpcEngine.Error as opt-in mechanismsinterface-{add,remove} can be emitted reliably.'error' when send operations fail and no callback was passed.RpcEnginemethods property to interfaceclose() method should cancel pending requests immediately{un}subscribe() on the receive sideonmessage to receive (breaking change)emit('error', error) rather than the onerror property (this is a breaking change)Math.random() for generating callback idsresults should be result)objectMode property for working with remotes that pass params, result as objects instead of arraysMIT