cosmology-tech / telescope

A TypeScript Transpiler for Cosmos Protobufs ⚛️
https://cosmology.zone/products/telescope
Apache License 2.0
145 stars 43 forks source link

leaner helper functions and cutom hooks #664

Closed Zetazzz closed 1 month ago

Zetazzz commented 1 month ago

Prototypes:

https://github.com/cosmology-tech/create-cosmos-app/pull/209/files

examples/interchainjs/src/codegen/cosmos/bank/v1beta1/query.rpc.funcs.ts examples/interchainjs/src/codegen/cosmos/bank/v1beta1/tx.rpc.func.ts

new options added:

  // create helper functions and hooks
  helperFuncCreators?: {
    // if not enabled, no .func files will be generated.
    enabled: boolean;
    // there won't be custom hooks when not true.
    genCustomHooks?: boolean;
    include?: {
      // a group of types of service to include, undefined for All.
      serviceTypes?: ('Query' | 'Msg' | 'All')[];
      // patterns like:
      // **
      // cosmos.bank.v1beta1.bala*
      // cosmos.bank.v1beta1.allBalances
      patterns?: string[];
    };
    nameMappers?: {
      All?: {
        // default to "unchanged"
        // to map the method name to a new name to make the body part without the prefix.
        // e.g. "**" : (name: string) => `get${name}`;
        // e.g. "cosmos.bank.v1beta1.bala*" : (name: string) => `show${name}`;
        funcBody: {
          [key: string]: "unchanged" | ( (name: string) => string );
        },
        // default to "create"
        creatorPrefix: string;
        // default to "use"
        hookPrefix: string;
      };
      Query?: {
        // to map the method name to a new name to make the body part without the prefix.
        // default to "get"
        funcBody: {
          [key: string]: "unchanged" | "get" | ( (name: string) => string );
        },
        // default to "create"
        creatorPrefix: string;
        // default to "use"
        hookPrefix: string;
      };
      Msg?: {
        // to map the method name to a new name to make the body part without the prefix.
        // default to "unchanged"
        funcBody: {
          [key: string]: "unchanged" | ( (name: string) => string );
        },
        // default to "create"
        creatorPrefix: string;
        // default to "use"
        hookPrefix: string;
      };
    };
  };