UNPKG

@tgrospic/rnode-http-js

Version:
59 lines 2.2 kB
var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; import * as R from 'ramda'; // Converts RhoExpr response from RNode WebAPI // https://github.com/rchain/rchain/blob/b7331ae05/node/src/main/scala/coop/rchain/node/api/WebApi.scala#L128-L147 // - return!("One argument") // monadic // - return!((true, A, B)) // monadic as tuple // - return!(true, A, B) // polyadic // new return(`rho:rchain:deployId`) in { // return!((true, "Hello from blockchain!")) // } // TODO: make it stack safe export var rhoExprToJson = function (input) { var loop = function (rhoExpr) { return convert(rhoExpr)(converters); }; var converters = R.toPairs(converterMapping(loop)); return loop(input); }; var converterMapping = function (loop) { return ({ "ExprInt": R.identity, "ExprBool": R.identity, "ExprString": R.identity, "ExprBytes": R.identity, "ExprUri": R.identity, "UnforgDeploy": R.identity, "UnforgDeployer": R.identity, "UnforgPrivate": R.identity, "ExprUnforg": loop, "ExprPar": R.map(loop), "ExprTuple": R.map(loop), "ExprList": R.map(loop), "ExprSet": R.map(loop), "ExprMap": R.mapObjIndexed(loop), }); }; var convert = function (rhoExpr) { return R.pipe(R.map(matchTypeConverter(rhoExpr)), R.find(function (x) { return !R.isNil(x); }), // Return the whole object if unknown type function (x) { return R.isNil(x) ? [R.identity, rhoExpr] : x; }, function (_a) { var _b = __read(_a, 2), f = _b[0], d = _b[1]; return f(d); }); }; var matchTypeConverter = function (rhoExpr) { return function (_a) { var _b = __read(_a, 2), type = _b[0], f = _b[1]; var d = R.path([type, 'data'], rhoExpr); return R.isNil(d) ? void 666 : [f, d]; }; }; //# sourceMappingURL=rho-json.js.map