Skip to content

Commit

Permalink
fix promise and await
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Jan 16, 2025
1 parent cd1ab64 commit cad016e
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 45 deletions.
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputv4/akash/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
akash: {
audit: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createCosmicRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
cosmos: {
bank: {
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputv4/cosmos/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputv4/cosmwasm/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputv4/evmos/evmos-rpc-client.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createEvmosRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
cosmos: {
bank: {
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputv4/evmos/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputv4/ibc/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputv4/osmosis/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/v-next/outputv4/tendermint/rpc.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const createRPCQueryClient = async ({
queryClientResolver
}: {
rpcEndpoint: string | HttpEndpoint;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => QueryClient;
queryClientResolver: (rpcEndpoint: string | HttpEndpoint) => Promise<QueryClient>;
}) => {
let client = queryClientResolver ? queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
let client = queryClientResolver ? await queryClientResolver(rpcEndpoint) : await createConnectCometQueryClient(rpcEndpoint);
return {
cosmos: {
app: {
Expand Down
69 changes: 42 additions & 27 deletions packages/ast/src/clients/rpc/scoped/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,40 +243,53 @@ export const createScopedRpcTmFactory = (
),
].filter(Boolean),
t.tsTypeAnnotation(
t.tsTypeLiteral([
t.tsPropertySignature(
t.identifier("rpcEndpoint"),
t.tsTypeAnnotation(
t.tsUnionType([
t.tsStringKeyword(),
t.tsTypeReference(
t.identifier("HttpEndpoint")
),
])
)
),
useQueryClientResolver &&
t.tsTypeLiteral(
[
t.tsPropertySignature(
t.identifier("queryClientResolver"),
t.identifier("rpcEndpoint"),
t.tsTypeAnnotation(
t.tsFunctionType(
null,
[rpcEndpointParam],
t.tsTypeAnnotation(
t.tsTypeReference(
t.identifier("QueryClient")
t.tsUnionType([
t.tsStringKeyword(),
t.tsTypeReference(
t.identifier("HttpEndpoint")
),
])
)
),
useQueryClientResolver &&
t.tsPropertySignature(
t.identifier("queryClientResolver"),
t.tsTypeAnnotation(
t.tsFunctionType(
null,
[rpcEndpointParam],
t.tsTypeAnnotation(
t.tsTypeReference(
t.identifier("Promise"),
t.tsTypeParameterInstantiation(
[
t.tsTypeReference(
t.identifier(
"QueryClient"
)
),
]
)
)
)
)
)
)
),
].filter(Boolean))
),
].filter(Boolean)
)
)
),
];

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

functionStatements = [
Expand All @@ -285,9 +298,11 @@ export const createScopedRpcTmFactory = (
t.identifier("client"),
t.conditionalExpression(
t.identifier("queryClientResolver"),
t.callExpression(
t.identifier("queryClientResolver"),
[t.identifier("rpcEndpoint")]
t.awaitExpression(
t.callExpression(
t.identifier("queryClientResolver"),
[t.identifier("rpcEndpoint")]
)
),
t.awaitExpression(
t.callExpression(
Expand Down

0 comments on commit cad016e

Please sign in to comment.