@jsonjoy.com/reactive-rpc
Version:
Reactive-RPC is a library for building reactive APIs over WebSocket, HTTP, and other RPCs.
29 lines • 1.19 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiRpcCaller = void 0;
const StaticRpcMethod_1 = require("../methods/StaticRpcMethod");
const StreamingRpcMethod_1 = require("../methods/StreamingRpcMethod");
const RpcCaller_1 = require("./RpcCaller");
const printTree_1 = require("sonic-forest/lib/print/printTree");
class ApiRpcCaller extends RpcCaller_1.RpcCaller {
constructor({ api, ...rest }) {
super({
...rest,
getMethod: (name) => this.get(name),
});
this.methods = new Map();
for (const key in api) {
const method = api[key];
this.methods.set(key, (method.isStreaming ? new StreamingRpcMethod_1.StreamingRpcMethod(method) : new StaticRpcMethod_1.StaticRpcMethod(method)));
}
}
get(name) {
return this.methods.get(name);
}
toString(tab = '') {
return (`${this.constructor.name}` +
(0, printTree_1.printTree)(tab, [...this.methods.entries()].map(([name, method]) => () => `${name}${method.isStreaming ? ' (streaming)' : ''}`)));
}
}
exports.ApiRpcCaller = ApiRpcCaller;
//# sourceMappingURL=ApiRpcCaller.js.map
;