1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | Object.defineProperty(exports, "__esModule", { value: true });
|
22 | exports.isJsonRpcResponse = exports.isJsonRpcRequest = exports.isJsonRpcNotification = exports.isJsonRpcError = exports.getPeer = void 0;
|
23 | const json_rpc_peer_1 = __importStar(require("json-rpc-peer"));
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | const isJsonRpcRequest = (payload) => ('method' in payload);
|
29 | exports.isJsonRpcRequest = isJsonRpcRequest;
|
30 | const isJsonRpcNotification = (payload) => isJsonRpcRequest(payload) && (!('id' in payload));
|
31 | exports.isJsonRpcNotification = isJsonRpcNotification;
|
32 | const isJsonRpcResponse = (payload) => ('result' in payload);
|
33 | exports.isJsonRpcResponse = isJsonRpcResponse;
|
34 | const isJsonRpcError = (payload) => ('error' in payload);
|
35 | exports.isJsonRpcError = isJsonRpcError;
|
36 | const getPeer = (options) => {
|
37 | const getServiceGrpcPort = () => options.serviceGrpcPort;
|
38 | const serviceImpl = {
|
39 | |
40 |
|
41 |
|
42 |
|
43 | getHostieGrpcPort: getServiceGrpcPort,
|
44 | };
|
45 | const onMessage = async (message) => {
|
46 | if (isJsonRpcRequest(message)) {
|
47 | const {
|
48 |
|
49 | method,
|
50 |
|
51 | } = message;
|
52 | if (!(method in serviceImpl)) {
|
53 | console.error('serviceImpl does not contain method: ' + method);
|
54 | return;
|
55 | }
|
56 | const serviceMethodName = method;
|
57 | switch (serviceMethodName) {
|
58 | |
59 |
|
60 |
|
61 |
|
62 | case 'getHostieGrpcPort':
|
63 | return serviceImpl[serviceMethodName]();
|
64 | default:
|
65 | throw new json_rpc_peer_1.MethodNotFound(serviceMethodName);
|
66 | }
|
67 | }
|
68 | else if (isJsonRpcResponse(message)) {
|
69 |
|
70 | }
|
71 | else if (isJsonRpcNotification(message)) {
|
72 |
|
73 | }
|
74 | else if (isJsonRpcError(message)) {
|
75 |
|
76 | }
|
77 | else {
|
78 | throw new Error('unknown json-rpc message: ' + JSON.stringify(message));
|
79 | }
|
80 | console.info(JSON.stringify(message));
|
81 | };
|
82 | const ioPeer = new json_rpc_peer_1.default(onMessage);
|
83 | return ioPeer;
|
84 | };
|
85 | exports.getPeer = getPeer;
|
86 |
|
\ | No newline at end of file |