UNPKG

@cosmology/ast

Version:
58 lines (57 loc) 2.8 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInitReqProperties = exports.headersInit = exports.initRequest = void 0; const utils_1 = require("../../../../../utils"); const t = __importStar(require("@babel/types")); // initRequest is used in constructing GRPC-Gateway methods // It is a second parameter in method signature. // ex: static Send(req: MsgSend, initReq?: fm.InitReq) // always the same, hence, declared outside of grpcGatewayMethodDefinition exports.initRequest = (0, utils_1.identifier)('initRequest', t.tSTypeAnnotation(t.tsTypeReference(t.tsQualifiedName(t.identifier('fm'), t.identifier('InitReq')))), true); // second params of grpc-gateway wrapper class /** * async account( req: QueryAccountRequest, headers?: HeadersInit, ) */ exports.headersInit = (0, utils_1.identifier)('headers', t.tSTypeAnnotation(t.tsTypeReference(t.identifier('HeadersInit'))), true); // initReqProperties contains information for initReq parameter in fetchReq arguments const getInitReqProperties = () => { const initReqProperties = []; // <...initReq> const argSpreadInit = t.spreadElement(t.identifier('initRequest')); // <method: 'POST'> const argPOST = t.objectProperty(t.identifier('method'), t.stringLiteral('POST'), false, false); // <JSON.stringify(req, fm.replacer)> const argBody = t.objectProperty(t.identifier('body'), t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify'), false), [ t.identifier('request'), t.memberExpression(t.identifier('fm'), t.identifier('replacer'), false) ])); initReqProperties.push(argSpreadInit, argPOST, argBody); return initReqProperties; }; exports.getInitReqProperties = getInitReqProperties;