UNPKG

@cosmology/ast

Version:
29 lines (28 loc) 1.21 kB
import * as t from "@babel/types"; import { getAminoTypeName, getTypeUrl } from "@cosmology/utils"; export const createRegisterObject = (context, name, proto) => { if (name === "Any") { return; } context.addUtil("GlobalDecoderRegistry"); const typeUrl = getTypeUrl(context.ref.proto, proto); if (!typeUrl) return; return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier("GlobalDecoderRegistry"), t.identifier("register")), [ t.memberExpression(t.identifier(name), t.identifier("typeUrl")), t.identifier(name), ])); }; export const createRegisterAminoProtoMapping = (context, name, proto) => { if (name === "Any") { return; } context.addUtil("GlobalDecoderRegistry"); const str = getAminoTypeName(context, context.ref.proto, proto); if (!str || str.startsWith("/")) return; return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier("GlobalDecoderRegistry"), t.identifier("registerAminoProtoMapping")), [ t.memberExpression(t.identifier(name), t.identifier("aminoType")), t.memberExpression(t.identifier(name), t.identifier("typeUrl")), ])); };