Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree shakable hooks generation update #716

Merged
merged 5 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,20 @@ See [RPC Clients](#rpc-clients) for more info.

| Option | Description | Defaults |
| --------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------- |
| `helperFuncCreators.enabled` | Enable the generation of helper function files `.func.ts` | `false` |
| `helperFuncCreators.genCustomHooks` | Generates React hooks alongside helper functions | `false` |
| `helperFuncCreators.include.serviceTypes`| Specifies which types of services to include (`Query`, `Msg`). `undefined` includes all types. | `undefined` |
| `helperFuncCreators.include.patterns` | Array of glob patterns patterns (e.g., `"**"`, `"cosmos.bank.v1beta1.bala*"`, etc.) to match specific proto services. | `undefined` |
| `helperFuncCreators.nameMappers` | Configuration object for customizing function names and prefixes | `{}` |
| `helperFuncCreators.nameMappers.All.funcBody` | Maps method names to a new name for all services. | `"unchanged"` |
| `helperFuncCreators.nameMappers.All.creatorPrefix` | Prefix for the function creator. | `"create"` |
| `helperFuncCreators.nameMappers.All.hookPrefix` | Prefix for the hooks. | `"use"` |
| `helperFuncCreators.nameMappers.Query.funcBody` | Maps method names to a new name for `Query` services. | `"get"` |
| `helperFuncCreators.nameMappers.Query.creatorPrefix`| Prefix for the function creator for `Query` services. | `"create"` |
| `helperFuncCreators.nameMappers.Query.hookPrefix` | Prefix for the hooks for `Query` services. | `"use"` |
| `helperFuncCreators.nameMappers.Msg.funcBody` | Maps method names to a new name for `Msg` services. | `"unchanged"` |
| `helperFuncCreators.nameMappers.Msg.creatorPrefix`| Prefix for the function creator for `Msg` services. | `"create"` |
| `helperFuncCreators.nameMappers.Msg.hookPrefix` | Prefix for the hooks for `Msg` services. | `"use"` |
| `helperFunctions.enabled` | Enable the generation of helper function files `.func.ts` | `false` |
| `helperFunctions.hooks` | Generates hooks selected alongside helper functions | `{ react: false, vue: false }` |
| `helperFunctions.include.serviceTypes`| Specifies which types of services to include (`Query`, `Msg`). `undefined` includes all types. | `undefined` |
| `helperFunctions.include.patterns` | Array of glob patterns patterns (e.g., `"**"`, `"cosmos.bank.v1beta1.bala*"`, etc.) to match specific proto services. | `undefined` |
| `helperFunctions.nameMappers` | Configuration object for customizing function names and prefixes | `{}` |
| `helperFunctions.nameMappers.All.funcBody` | Maps method names to a new name for all services. | `"unchanged"` |
| `helperFunctions.nameMappers.All.creatorPrefix` | Prefix for the function creator. | `"create"` |
| `helperFunctions.nameMappers.All.hookPrefix` | Prefix for the hooks. | `"use"` |
| `helperFunctions.nameMappers.Query.funcBody` | Maps method names to a new name for `Query` services. | `"get"` |
| `helperFunctions.nameMappers.Query.creatorPrefix`| Prefix for the function creator for `Query` services. | `"create"` |
| `helperFunctions.nameMappers.Query.hookPrefix` | Prefix for the hooks for `Query` services. | `"use"` |
| `helperFunctions.nameMappers.Msg.funcBody` | Maps method names to a new name for `Msg` services. | `"unchanged"` |
| `helperFunctions.nameMappers.Msg.creatorPrefix`| Prefix for the function creator for `Msg` services. | `"create"` |
| `helperFunctions.nameMappers.Msg.hookPrefix` | Prefix for the hooks for `Msg` services. | `"use"` |

See [Helper Functions Configuration](#helper-functions-configuration) for more info.

Expand Down Expand Up @@ -1260,9 +1260,12 @@ The nameMappers object supports three service types: All, Query, and Msg. Each p

```js
const options: TelescopeOptions = {
helperFuncCreators: {
helperFunctions: {
enabled: true,
genCustomHooks: true,
genCustomHooks: {
react: true,
vue: true
},
include: {
patterns: ["cosmos.gov.v1beta1.**", "cosmos.bank.v1beta1.*Send*"],
},
Expand Down
12 changes: 6 additions & 6 deletions __fixtures__/v-next/outputhelperfunc/akash/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ import * as _349 from "./market/v1beta2/service.rpc.msg";
import * as _350 from "./provider/v1beta1/provider.rpc.msg";
import * as _351 from "./provider/v1beta2/provider.rpc.msg";
import * as _352 from "./cert/v1beta2/query.pinia.store";
import * as _539 from "./lcd";
import * as _540 from "./rpc.query";
import * as _541 from "./rpc.tx";
import * as _542 from "./lcd";
import * as _543 from "./rpc.query";
import * as _544 from "./rpc.tx";
export namespace akash {
export namespace audit {
export const v1beta1 = {
Expand Down Expand Up @@ -225,8 +225,8 @@ export namespace akash {
};
}
export const ClientFactory = {
..._539,
..._540,
..._541
..._542,
..._543,
..._544
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { PageRequest, PageRequestSDKType, PageResponse, PageResponseSDKType } from "../../base/query/v1beta1/pagination";
import { Coin, CoinSDKType } from "../../base/v1beta1/coin";
import { Params, ParamsSDKType, Metadata, MetadataSDKType } from "./bank";
import { RpcResolver, buildQuery } from "../../../helper-func-types";
import { buildUseQuery } from "../../../react-query";
import { buildUseVueQuery } from "../../../vue-query";
import { QueryBalanceRequest, QueryBalanceRequestSDKType, QueryBalanceResponse, QueryBalanceResponseSDKType, QueryAllBalancesRequest, QueryAllBalancesRequestSDKType, QueryAllBalancesResponse, QueryAllBalancesResponseSDKType, QuerySpendableBalancesRequest, QuerySpendableBalancesRequestSDKType, QuerySpendableBalancesResponse, QuerySpendableBalancesResponseSDKType, QueryTotalSupplyRequest, QueryTotalSupplyRequestSDKType, QueryTotalSupplyResponse, QueryTotalSupplyResponseSDKType, QuerySupplyOfRequest, QuerySupplyOfRequestSDKType, QuerySupplyOfResponse, QuerySupplyOfResponseSDKType, QueryParamsRequest, QueryParamsRequestSDKType, QueryParamsResponse, QueryParamsResponseSDKType, QueryDenomMetadataRequest, QueryDenomMetadataRequestSDKType, QueryDenomMetadataResponse, QueryDenomMetadataResponseSDKType, QueryDenomsMetadataRequest, QueryDenomsMetadataRequestSDKType, QueryDenomsMetadataResponse, QueryDenomsMetadataResponseSDKType, QueryDenomOwnersRequest, QueryDenomOwnersRequestSDKType, QueryDenomOwnersResponse, QueryDenomOwnersResponseSDKType } from "./query";
export const createGetBalance = (clientResolver?: RpcResolver) => buildQuery<QueryBalanceRequest, QueryBalanceResponse>({
encode: QueryBalanceRequest.encode,
decode: QueryBalanceResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "Balance",
clientResolver,
deps: [QueryBalanceRequest, QueryBalanceResponse]
});
export const createGetAllBalances = (clientResolver?: RpcResolver) => buildQuery<QueryAllBalancesRequest, QueryAllBalancesResponse>({
encode: QueryAllBalancesRequest.encode,
decode: QueryAllBalancesResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "AllBalances",
clientResolver,
deps: [QueryAllBalancesRequest, QueryAllBalancesResponse]
});
export const createGetSpendableBalances = (clientResolver?: RpcResolver) => buildQuery<QuerySpendableBalancesRequest, QuerySpendableBalancesResponse>({
encode: QuerySpendableBalancesRequest.encode,
decode: QuerySpendableBalancesResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "SpendableBalances",
clientResolver,
deps: [QuerySpendableBalancesRequest, QuerySpendableBalancesResponse]
});
export const createGetTotalSupply = (clientResolver?: RpcResolver) => buildQuery<QueryTotalSupplyRequest, QueryTotalSupplyResponse>({
encode: QueryTotalSupplyRequest.encode,
decode: QueryTotalSupplyResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "TotalSupply",
clientResolver,
deps: [QueryTotalSupplyRequest, QueryTotalSupplyResponse]
});
export const createGetSupplyOf = (clientResolver?: RpcResolver) => buildQuery<QuerySupplyOfRequest, QuerySupplyOfResponse>({
encode: QuerySupplyOfRequest.encode,
decode: QuerySupplyOfResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "SupplyOf",
clientResolver,
deps: [QuerySupplyOfRequest, QuerySupplyOfResponse]
});
export const createGetParams = (clientResolver?: RpcResolver) => buildQuery<QueryParamsRequest, QueryParamsResponse>({
encode: QueryParamsRequest.encode,
decode: QueryParamsResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "Params",
clientResolver,
deps: [QueryParamsRequest, QueryParamsResponse]
});
export const createGetDenomMetadata = (clientResolver?: RpcResolver) => buildQuery<QueryDenomMetadataRequest, QueryDenomMetadataResponse>({
encode: QueryDenomMetadataRequest.encode,
decode: QueryDenomMetadataResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "DenomMetadata",
clientResolver,
deps: [QueryDenomMetadataRequest, QueryDenomMetadataResponse]
});
export const createGetDenomsMetadata = (clientResolver?: RpcResolver) => buildQuery<QueryDenomsMetadataRequest, QueryDenomsMetadataResponse>({
encode: QueryDenomsMetadataRequest.encode,
decode: QueryDenomsMetadataResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "DenomsMetadata",
clientResolver,
deps: [QueryDenomsMetadataRequest, QueryDenomsMetadataResponse]
});
export const createGetDenomOwners = (clientResolver?: RpcResolver) => buildQuery<QueryDenomOwnersRequest, QueryDenomOwnersResponse>({
encode: QueryDenomOwnersRequest.encode,
decode: QueryDenomOwnersResponse.decode,
service: "cosmos.bank.v1beta1.Query",
method: "DenomOwners",
clientResolver,
deps: [QueryDenomOwnersRequest, QueryDenomOwnersResponse]
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { PageRequest, PageRequestSDKType, PageResponse, PageResponseSDKType } from "../../base/query/v1beta1/pagination";
import { Coin, CoinSDKType } from "../../base/v1beta1/coin";
import { Params, ParamsSDKType, Metadata, MetadataSDKType } from "./bank";
import { RpcResolver, buildQuery } from "../../../helper-func-types";
import { buildUseQuery } from "../../../react-query";
import { buildUseVueQuery } from "../../../vue-query";
import { QueryBalanceRequest, QueryBalanceRequestSDKType, QueryBalanceResponse, QueryBalanceResponseSDKType, QueryAllBalancesRequest, QueryAllBalancesRequestSDKType, QueryAllBalancesResponse, QueryAllBalancesResponseSDKType, QuerySpendableBalancesRequest, QuerySpendableBalancesRequestSDKType, QuerySpendableBalancesResponse, QuerySpendableBalancesResponseSDKType, QueryTotalSupplyRequest, QueryTotalSupplyRequestSDKType, QueryTotalSupplyResponse, QueryTotalSupplyResponseSDKType, QuerySupplyOfRequest, QuerySupplyOfRequestSDKType, QuerySupplyOfResponse, QuerySupplyOfResponseSDKType, QueryParamsRequest, QueryParamsRequestSDKType, QueryParamsResponse, QueryParamsResponseSDKType, QueryDenomMetadataRequest, QueryDenomMetadataRequestSDKType, QueryDenomMetadataResponse, QueryDenomMetadataResponseSDKType, QueryDenomsMetadataRequest, QueryDenomsMetadataRequestSDKType, QueryDenomsMetadataResponse, QueryDenomsMetadataResponseSDKType, QueryDenomOwnersRequest, QueryDenomOwnersRequestSDKType, QueryDenomOwnersResponse, QueryDenomOwnersResponseSDKType } from "./query";
import { createGetBalance, createGetAllBalances, createGetSpendableBalances, createGetTotalSupply, createGetSupplyOf, createGetParams, createGetDenomMetadata, createGetDenomsMetadata, createGetDenomOwners } from "./query.rpc.func.ts";
export const useGetBalance = buildUseQuery<QueryBalanceRequest, QueryBalanceResponse>({
builderQueryFn: createGetBalance,
queryKeyPrefix: "BalanceQuery"
});
export const useGetAllBalances = buildUseQuery<QueryAllBalancesRequest, QueryAllBalancesResponse>({
builderQueryFn: createGetAllBalances,
queryKeyPrefix: "AllBalancesQuery"
});
export const useGetSpendableBalances = buildUseQuery<QuerySpendableBalancesRequest, QuerySpendableBalancesResponse>({
builderQueryFn: createGetSpendableBalances,
queryKeyPrefix: "SpendableBalancesQuery"
});
export const useGetTotalSupply = buildUseQuery<QueryTotalSupplyRequest, QueryTotalSupplyResponse>({
builderQueryFn: createGetTotalSupply,
queryKeyPrefix: "TotalSupplyQuery"
});
export const useGetSupplyOf = buildUseQuery<QuerySupplyOfRequest, QuerySupplyOfResponse>({
builderQueryFn: createGetSupplyOf,
queryKeyPrefix: "SupplyOfQuery"
});
export const useGetParams = buildUseQuery<QueryParamsRequest, QueryParamsResponse>({
builderQueryFn: createGetParams,
queryKeyPrefix: "ParamsQuery"
});
export const useGetDenomMetadata = buildUseQuery<QueryDenomMetadataRequest, QueryDenomMetadataResponse>({
builderQueryFn: createGetDenomMetadata,
queryKeyPrefix: "DenomMetadataQuery"
});
export const useGetDenomsMetadata = buildUseQuery<QueryDenomsMetadataRequest, QueryDenomsMetadataResponse>({
builderQueryFn: createGetDenomsMetadata,
queryKeyPrefix: "DenomsMetadataQuery"
});
export const useGetDenomOwners = buildUseQuery<QueryDenomOwnersRequest, QueryDenomOwnersResponse>({
builderQueryFn: createGetDenomOwners,
queryKeyPrefix: "DenomOwnersQuery"
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { PageRequest, PageRequestSDKType, PageResponse, PageResponseSDKType } from "../../base/query/v1beta1/pagination";
import { Coin, CoinSDKType } from "../../base/v1beta1/coin";
import { Params, ParamsSDKType, Metadata, MetadataSDKType } from "./bank";
import { RpcResolver, buildQuery } from "../../../helper-func-types";
import { buildUseQuery } from "../../../react-query";
import { buildUseVueQuery } from "../../../vue-query";
import { QueryBalanceRequest, QueryBalanceRequestSDKType, QueryBalanceResponse, QueryBalanceResponseSDKType, QueryAllBalancesRequest, QueryAllBalancesRequestSDKType, QueryAllBalancesResponse, QueryAllBalancesResponseSDKType, QuerySpendableBalancesRequest, QuerySpendableBalancesRequestSDKType, QuerySpendableBalancesResponse, QuerySpendableBalancesResponseSDKType, QueryTotalSupplyRequest, QueryTotalSupplyRequestSDKType, QueryTotalSupplyResponse, QueryTotalSupplyResponseSDKType, QuerySupplyOfRequest, QuerySupplyOfRequestSDKType, QuerySupplyOfResponse, QuerySupplyOfResponseSDKType, QueryParamsRequest, QueryParamsRequestSDKType, QueryParamsResponse, QueryParamsResponseSDKType, QueryDenomMetadataRequest, QueryDenomMetadataRequestSDKType, QueryDenomMetadataResponse, QueryDenomMetadataResponseSDKType, QueryDenomsMetadataRequest, QueryDenomsMetadataRequestSDKType, QueryDenomsMetadataResponse, QueryDenomsMetadataResponseSDKType, QueryDenomOwnersRequest, QueryDenomOwnersRequestSDKType, QueryDenomOwnersResponse, QueryDenomOwnersResponseSDKType } from "./query";
import { createGetBalance, createGetAllBalances, createGetSpendableBalances, createGetTotalSupply, createGetSupplyOf, createGetParams, createGetDenomMetadata, createGetDenomsMetadata, createGetDenomOwners } from "./query.rpc.func.ts";
export const useGetBalance = buildUseVueQuery<QueryBalanceRequest, QueryBalanceResponse>({
builderQueryFn: createGetBalance,
queryKeyPrefix: "BalanceQuery"
});
export const useGetAllBalances = buildUseVueQuery<QueryAllBalancesRequest, QueryAllBalancesResponse>({
builderQueryFn: createGetAllBalances,
queryKeyPrefix: "AllBalancesQuery"
});
export const useGetSpendableBalances = buildUseVueQuery<QuerySpendableBalancesRequest, QuerySpendableBalancesResponse>({
builderQueryFn: createGetSpendableBalances,
queryKeyPrefix: "SpendableBalancesQuery"
});
export const useGetTotalSupply = buildUseVueQuery<QueryTotalSupplyRequest, QueryTotalSupplyResponse>({
builderQueryFn: createGetTotalSupply,
queryKeyPrefix: "TotalSupplyQuery"
});
export const useGetSupplyOf = buildUseVueQuery<QuerySupplyOfRequest, QuerySupplyOfResponse>({
builderQueryFn: createGetSupplyOf,
queryKeyPrefix: "SupplyOfQuery"
});
export const useGetParams = buildUseVueQuery<QueryParamsRequest, QueryParamsResponse>({
builderQueryFn: createGetParams,
queryKeyPrefix: "ParamsQuery"
});
export const useGetDenomMetadata = buildUseVueQuery<QueryDenomMetadataRequest, QueryDenomMetadataResponse>({
builderQueryFn: createGetDenomMetadata,
queryKeyPrefix: "DenomMetadataQuery"
});
export const useGetDenomsMetadata = buildUseVueQuery<QueryDenomsMetadataRequest, QueryDenomsMetadataResponse>({
builderQueryFn: createGetDenomsMetadata,
queryKeyPrefix: "DenomsMetadataQuery"
});
export const useGetDenomOwners = buildUseVueQuery<QueryDenomOwnersRequest, QueryDenomOwnersResponse>({
builderQueryFn: createGetDenomOwners,
queryKeyPrefix: "DenomOwnersQuery"
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Input, InputSDKType, Output, OutputSDKType } from "./bank";
import { buildTx, ISigningClient, SigningClientResolver } from "../../../helper-func-types";
import { toEncoders, toConverters } from "@interchainjs/cosmos/utils";
import { buildUseMutation } from "../../../react-query";
import { buildUseVueMutation } from "../../../vue-query";
import { MsgSend, MsgSendSDKType, MsgSendResponse, MsgSendResponseSDKType, MsgMultiSend, MsgMultiSendSDKType, MsgMultiSendResponse, MsgMultiSendResponseSDKType } from "./tx";
export const createSend = (clientResolver?: SigningClientResolver) => buildTx<MsgSend>({
clientResolver,
Expand All @@ -11,16 +12,10 @@ export const createSend = (clientResolver?: SigningClientResolver) => buildTx<Ms
converters: toConverters(MsgSend),
deps: [MsgSend]
});
export const useSend = buildUseMutation<MsgSend, Error>({
builderMutationFn: createSend
});
export const createMultiSend = (clientResolver?: SigningClientResolver) => buildTx<MsgMultiSend>({
clientResolver,
typeUrl: MsgMultiSend.typeUrl,
encoders: toEncoders(MsgMultiSend),
converters: toConverters(MsgMultiSend),
deps: [MsgMultiSend]
});
export const useMultiSend = buildUseMutation<MsgMultiSend, Error>({
builderMutationFn: createMultiSend
});
Loading
Loading