Helper Functions Configuration
This document provides a reference for configuring helper function generation in Telescope.
Overview
Helper functions provide a simplified interface to interact with your blockchain's services. Telescope can automatically generate these functions based on your proto definitions, allowing for cleaner and more intuitive code.
Configuration
Helper function generation is configured in the helperFunctions section of your Telescope options:
import { TelescopeOptions } from "@cosmology/types";
 
const options: TelescopeOptions = {
  helperFunctions: {
    enabled: true,
    hooks: {
      react: true,
      vue: false
    },
    include: {
      serviceTypes: ["Query", "Msg"],
      patterns: ["cosmos.gov.v1beta1.**", "cosmos.bank.v1beta1.*Send*"]
    },
    nameMappers: {
      All: {
        "cosmos.gov.v1beta1.*Vote*": {
          funcBody: (name) => `helper${name}`,
          hookPrefix: "use"
        }
      },
      Query: {
        funcBody: (name) => `get${name}`,
        hookPrefix: "use"
      },
      Msg: {
        funcBody: "unchanged",
        hookPrefix: "useTx"
      }
    }
  }
};Configuration Properties
Basic Options
| Property | Type | Description | Default | 
|---|---|---|---|
| helperFunctions.enabled | boolean | Enable or disable helper function generation | false | 
| helperFunctions.hooks | object | Configuration for generating hook functions for React and Vue | { react: false, vue: false } | 
Include Options
| Property | Type | Description | Default | 
|---|---|---|---|
| helperFunctions.include.serviceTypes | string[] | Which service types to include ( Query,Msg) | undefined(all types) | 
| helperFunctions.include.patterns | string[] | Glob patterns to match specific services | undefined(all services) | 
Name Mapping Options
The nameMappers object allows you to customize how function names are generated. It has three categories:
- All- Applied to all service types
- Query- Applied only to Query services
- Msg- Applied only to Msg services
For each category, you can specify:
| Property | Type | Description | Default | 
|---|---|---|---|
| funcBody | string or function | How to transform method names | Query: "get", Msg: "unchanged" | 
| hookPrefix | string | Prefix for hook functions | "use" | 
Pattern Matching Priority
When multiple patterns match a service, the following priority rules apply:
- Service-specific patterns (Query,Msg) take precedence overAllpatterns
- More specific patterns take precedence over general patterns
- Patterns are case-sensitive
Name Transformation
The funcBody property can be either:
- 
A string value: - "unchanged"- Keep the original method name
- Any other string - Use as a prefix for the method name
 
- 
A function: (name: string) => string- Receives the original method name
- Returns the transformed name
 
Example function transformation:
funcBody: (name) => `execute${name.charAt(0).toUpperCase()}${name.slice(1)}`Generated Output Examples
Basic Helper Functions
For a service cosmos.gov.v1beta1.Query.proposals, with default configuration:
// Generated function
export function getProposals(
  rpcEndpoint: string, 
  params: QueryProposalsRequest
): Promise<QueryProposalsResponse> {
  // Implementation
}React Hooks
If React hooks are enabled:
// Generated React hook
export function useProposals(
  rpcEndpoint: string,
  params: QueryProposalsRequest, 
  options?: UseQueryOptions<QueryProposalsResponse>
): UseQueryResult<QueryProposalsResponse, Error> {
  // Implementation
}Custom Naming
With custom naming rules:
nameMappers: {
  Query: {
    "cosmos.gov.v1beta1.*Proposals*": {
      funcBody: (name) => `fetch${name}`,
      hookPrefix: "useGov"
    }
  }
}Would generate:
// Generated function
export function fetchProposals(/* ... */) { /* ... */ }
 
// Generated React hook
export function useGovFetchProposals(/* ... */) { /* ... */ }Best Practices
- Limit the scope: Use include.patternsto generate helpers only for the services you need
- Use consistent naming: Maintain a consistent naming convention across your codebase
- Prefer descriptive names: Use prefixes that describe the action (e.g., getfor queries,sendfor transactions)
- Document custom mappers: If using complex name transformations, document the logic for your team