Skip to content

Commit

Permalink
Merge pull request #722 from hyperweb-io/query-client-resolver
Browse files Browse the repository at this point in the history
fix as review comments for makeClient
  • Loading branch information
Zetazzz authored Jan 25, 2025
2 parents dbb47dd + 7cad806 commit 2e0d6c9
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ See [LCD Clients](#lcd-clients) for more info.
| `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] |
| `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` |
| `rpcClients.useConnectComet` | will use connectComet function to get a tendermint client | `undefined` |
| `rpcClients.useQueryClientResolver` | allow user to pass a query client resolver to create query client in createRPCQueryClient function | `undefined` |
| `rpcClients.useMakeClient` | allow user to pass a query client resolver to create query client in createRPCQueryClient function | `undefined` |
| `rpcClients.serviceImplement` | assign implement type of rpc methods, `Query` or `Tx`, by setting patterns under service types. | `undefined` |
`rpcClients.clientStyle.useUpdatedClientStyle` | The default value is `false`, which sets the generated client to use the legacy style. Setting it to `true` applies the updated style and activates the remaining options in clientStyle. | `false`
| `rpcClients.clientStyle.type` | A string array containing possible values: `all-client`, `sdk-module-client`, and `custom-client`. The value `all-client` generates an all-module-client file. The value `sdk-module-client` generates a client for the module specified by the `sdkModuleClientOption`. The value `custom-client` generates a customized client as specified by `customClientOption` | `undefined`
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv4/akash/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
akash: {
audit: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createCosmicRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
cosmos: {
bank: {
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv4/cosmos/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv4/cosmwasm/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv4/evmos/evmos-rpc-client.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createEvmosRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
cosmos: {
bank: {
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv4/evmos/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv4/ibc/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv4/osmosis/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv4/tendermint/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { QueryClient } from "@cosmjs/stargate";
import { createConnectCometQueryClient } from "../extern.js";
export const createRPCQueryClient = async ({
rpcEndpoint,
queryClientResolver
makeClient
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
makeClient?: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
const make = makeClient || createConnectCometQueryClient;
const client = await make(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
57 changes: 30 additions & 27 deletions packages/ast/src/clients/rpc/scoped/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as t from "@babel/types";
import { GenericParseContext } from "../../../encoding";
import { objectPattern } from "../../../utils";
import {
objectPattern,
objectProperty,
tsPropertySignature,
} from "../../../utils";
import { restoreExtension } from "@cosmology/utils";

export const rpcFuncArguments = (): t.ObjectPattern[] => {
Expand Down Expand Up @@ -174,9 +178,7 @@ export const createScopedRpcTmFactory = (
identifier: string
) => {
const newClientType = context.pluginValue("rpcClients.useConnectComet");
const useQueryClientResolver = context.pluginValue(
"rpcClients.useQueryClientResolver"
);
const useMakeClient = context.pluginValue("rpcClients.useMakeClient");

const extensions = context.pluginValue("rpcClients.extensions");
let functionParams;
Expand Down Expand Up @@ -234,10 +236,10 @@ export const createScopedRpcTmFactory = (
false,
true
),
useQueryClientResolver &&
useMakeClient &&
t.objectProperty(
t.identifier("queryClientResolver"),
t.identifier("queryClientResolver"),
t.identifier("makeClient"),
t.identifier("makeClient"),
false,
true
),
Expand All @@ -256,9 +258,9 @@ export const createScopedRpcTmFactory = (
])
)
),
useQueryClientResolver &&
t.tsPropertySignature(
t.identifier("queryClientResolver"),
useMakeClient &&
tsPropertySignature(
t.identifier("makeClient"),
t.tsTypeAnnotation(
t.tsFunctionType(
null,
Expand All @@ -278,38 +280,39 @@ export const createScopedRpcTmFactory = (
)
)
)
)
),
true
),
].filter(Boolean)
)
)
),
];

if (useQueryClientResolver) {
if (useMakeClient) {
let createQueryClientName = newClientType
? "createConnectCometQueryClient"
: "createTm34QueryClient";
context.addUtil(createQueryClientName);

functionStatements = [
t.variableDeclaration("let", [
t.variableDeclaration("const", [
t.variableDeclarator(
t.identifier("make"),
t.logicalExpression(
"||",
t.identifier("makeClient"),
t.identifier(createQueryClientName)
)
),
]),
t.variableDeclaration("const", [
t.variableDeclarator(
t.identifier("client"),
t.conditionalExpression(
t.identifier("queryClientResolver"),
t.awaitExpression(
t.callExpression(
t.identifier("queryClientResolver"),
[t.identifier("rpcEndpoint")]
)
),
t.awaitExpression(
t.callExpression(
t.identifier(createQueryClientName),
[t.identifier("rpcEndpoint")]
)
)
t.awaitExpression(
t.callExpression(t.identifier("make"), [
t.identifier("rpcEndpoint"),
])
)
),
]),
Expand Down
2 changes: 1 addition & 1 deletion packages/telescope/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ See [LCD Clients](#lcd-clients) for more info.
| `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] |
| `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` |
| `rpcClients.useConnectComet` | will use connectComet function to get a tendermint client | `undefined` |
| `rpcClients.useQueryClientResolver` | allow user to pass a query client resolver to create query client in createRPCQueryClient function | `undefined` |
| `rpcClients.useMakeClient` | allow user to pass a query client resolver to create query client in createRPCQueryClient function | `undefined` |
| `rpcClients.serviceImplement` | assign implement type of rpc methods, `Query` or `Tx`, by setting patterns under service types. | `undefined` |
`rpcClients.clientStyle.useUpdatedClientStyle` | The default value is `false`, which sets the generated client to use the legacy style. Setting it to `true` applies the updated style and activates the remaining options in clientStyle. | `false`
| `rpcClients.clientStyle.type` | A string array containing possible values: `all-client`, `sdk-module-client`, and `custom-client`. The value `all-client` generates an all-module-client file. The value `sdk-module-client` generates a client for the module specified by the `sdkModuleClientOption`. The value `custom-client` generates a customized client as specified by `customClientOption` | `undefined`
Expand Down
2 changes: 1 addition & 1 deletion packages/telescope/__tests__/telescope-v4.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const options: TelescopeOptions = {
'ABCIApplication'
],
useConnectComet: true,
useQueryClientResolver: true
useMakeClient: true
},

reactQuery: {
Expand Down
2 changes: 1 addition & 1 deletion packages/telescope/src/generators/create-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const plugin = (builder: TelescopeBuilder) => {
write(
builder,
"extern.ts",
builder.options.rpcClients?.useConnectComet || builder.options.rpcClients?.useQueryClientResolver ? externalComet : external
builder.options.rpcClients?.useConnectComet || builder.options.rpcClients?.useMakeClient ? externalComet : external
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/telescope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export interface TelescopeOpts {
};
}[];
useConnectComet?: boolean;
useQueryClientResolver?: boolean;
useMakeClient?: boolean;
};
helperFuncCreators?: {
enabled: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/types/telescope.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export interface TelescopeOpts {
};
}[];
useConnectComet?: boolean;
useQueryClientResolver?: boolean;
useMakeClient?: boolean;
};
helperFuncCreators?: {
enabled: boolean;
Expand Down

0 comments on commit 2e0d6c9

Please sign in to comment.