@cosmwasm/ts-codegen 0.30.1 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -2
- package/main/builder/builder.js +41 -4
- package/main/generators/create-helpers.js +38 -0
- package/main/helpers/contractContextBase.js +8 -0
- package/main/helpers/contractsContextTSX.js +8 -0
- package/main/helpers/index.js +31 -0
- package/main/plugins/client.js +11 -6
- package/main/plugins/message-composer.js +10 -6
- package/main/plugins/msg-builder.js +1 -1
- package/main/plugins/plugin-base.js +9 -2
- package/main/plugins/provider-bundle.js +146 -0
- package/main/plugins/provider.js +170 -0
- package/main/plugins/react-query.js +1 -1
- package/main/plugins/recoil.js +1 -1
- package/main/plugins/types.js +1 -1
- package/main/utils/files.js +77 -0
- package/main/utils/unused.js +68 -0
- package/module/builder/builder.js +28 -2
- package/module/generators/create-helpers.js +25 -0
- package/module/helpers/contractContextBase.js +92 -0
- package/module/helpers/contractsContextTSX.js +73 -0
- package/module/helpers/index.js +2 -0
- package/module/plugins/client.js +13 -10
- package/module/plugins/message-composer.js +12 -10
- package/module/plugins/msg-builder.js +1 -1
- package/module/plugins/plugin-base.js +15 -8
- package/module/plugins/provider-bundle.js +65 -0
- package/module/plugins/provider.js +81 -0
- package/module/plugins/react-query.js +1 -1
- package/module/plugins/recoil.js +1 -1
- package/module/plugins/types.js +1 -1
- package/module/utils/files.js +44 -0
- package/module/utils/unused.js +45 -0
- package/package.json +3 -3
- package/src/builder/builder.ts +36 -1
- package/src/generators/create-helpers.ts +28 -0
- package/src/helpers/contractContextBase.ts +92 -0
- package/src/helpers/contractsContextTSX.ts +73 -0
- package/src/helpers/index.ts +2 -0
- package/src/plugins/client.ts +30 -14
- package/src/plugins/message-composer.ts +23 -14
- package/src/plugins/msg-builder.ts +1 -1
- package/src/plugins/plugin-base.ts +30 -20
- package/src/plugins/provider-bundle.ts +97 -0
- package/src/plugins/provider.ts +114 -0
- package/src/plugins/react-query.ts +1 -1
- package/src/plugins/recoil.ts +1 -1
- package/src/plugins/types.ts +1 -1
- package/src/utils/files.ts +73 -0
- package/src/utils/unused.ts +52 -0
- package/types/src/builder/builder.d.ts +7 -1
- package/types/src/generators/create-helpers.d.ts +3 -0
- package/types/src/helpers/contractContextBase.d.ts +1 -0
- package/types/src/helpers/contractsContextTSX.d.ts +1 -0
- package/types/src/helpers/index.d.ts +2 -0
- package/types/src/plugins/client.d.ts +4 -3
- package/types/src/plugins/message-composer.d.ts +4 -3
- package/types/src/plugins/plugin-base.d.ts +7 -3
- package/types/src/plugins/provider-bundle.d.ts +13 -0
- package/types/src/plugins/provider.d.ts +15 -0
- package/types/src/plugins/use-contracts.d.ts +12 -0
- package/types/src/utils/files.d.ts +3 -0
- package/types/src/utils/unused.d.ts +5 -0
@@ -0,0 +1 @@
|
|
1
|
+
export declare const contractsContextTSX = "\nimport React, { useEffect, useMemo, useRef, useState, useContext } from 'react';\nimport {\n CosmWasmClient,\n SigningCosmWasmClient,\n} from '@cosmjs/cosmwasm-stargate';\n\nimport { IContractsContext, getProviders } from './contractContextProviders';\n\ninterface ContractsConfig {\n address: string | undefined;\n getCosmWasmClient: () => Promise<CosmWasmClient>;\n getSigningCosmWasmClient: () => Promise<SigningCosmWasmClient>;\n}\n\nconst ContractsContext = React.createContext<IContractsContext | null>(null);\n\nexport const ContractsProvider = ({\n children,\n contractsConfig,\n}: {\n children: React.ReactNode;\n contractsConfig: ContractsConfig;\n}) => {\n const [cosmWasmClient, setCosmWasmClient] = useState<CosmWasmClient>();\n const [signingCosmWasmClient, setSigningCosmWasmClient] =\n useState<SigningCosmWasmClient>();\n\n const { address, getCosmWasmClient, getSigningCosmWasmClient } =\n contractsConfig;\n\n const prevAddressRef = useRef<string | undefined>(address);\n\n const contracts: IContractsContext = useMemo(() => {\n return getProviders(address, cosmWasmClient, signingCosmWasmClient);\n }, [address, cosmWasmClient, signingCosmWasmClient]);\n\n useEffect(() => {\n const connectSigningCwClient = async () => {\n if (address && prevAddressRef.current !== address) {\n const signingCosmWasmClient = await getSigningCosmWasmClient();\n setSigningCosmWasmClient(signingCosmWasmClient);\n } else if (!address) {\n setSigningCosmWasmClient(undefined);\n }\n prevAddressRef.current = address;\n };\n connectSigningCwClient();\n }, [address, getSigningCosmWasmClient]);\n\n useEffect(() => {\n const connectCosmWasmClient = async () => {\n const cosmWasmClient = await getCosmWasmClient();\n setCosmWasmClient(cosmWasmClient);\n };\n connectCosmWasmClient();\n }, [getCosmWasmClient]);\n\n return (\n <ContractsContext.Provider value={contracts}>\n {children}\n </ContractsContext.Provider>\n );\n};\n\nexport const useContracts = () => {\n const contracts = useContext(ContractsContext);\n if (contracts === null) {\n throw new Error('useContracts must be used within a ContractsProvider');\n }\n return contracts;\n};\n";
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import { RenderContext, ContractInfo, RenderContextBase, RenderOptions } from
|
2
|
-
import { BuilderFileType } from
|
3
|
-
import { BuilderPluginBase } from
|
1
|
+
import { RenderContext, ContractInfo, RenderContextBase, RenderOptions } from "wasm-ast-types";
|
2
|
+
import { BuilderFileType } from "../builder";
|
3
|
+
import { BuilderPluginBase } from "./plugin-base";
|
4
|
+
export declare const TYPE = "client";
|
4
5
|
export declare class ClientPlugin extends BuilderPluginBase<RenderOptions> {
|
5
6
|
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
7
|
doRender(name: string, context: RenderContext): Promise<{
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import { ContractInfo, RenderContextBase, RenderContext, RenderOptions } from
|
2
|
-
import { BuilderFileType } from
|
3
|
-
import { BuilderPluginBase } from
|
1
|
+
import { ContractInfo, RenderContextBase, RenderContext, RenderOptions } from "wasm-ast-types";
|
2
|
+
import { BuilderFileType } from "../builder";
|
3
|
+
import { BuilderPluginBase } from "./plugin-base";
|
4
|
+
export declare const TYPE = "message-composer";
|
4
5
|
export declare class MessageComposerPlugin extends BuilderPluginBase<RenderOptions> {
|
5
6
|
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
7
|
doRender(name: string, context: RenderContext): Promise<{
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { ContractInfo, UtilMapping, IContext } from
|
2
|
-
import { BuilderFile, BuilderFileType } from
|
1
|
+
import { ContractInfo, UtilMapping, IContext } from "wasm-ast-types";
|
2
|
+
import { BuilderFile, BuilderFileType, TSBuilder } from "../builder";
|
3
3
|
/**
|
4
4
|
* IBuilderPlugin is a common plugin that render generated code.
|
5
5
|
*/
|
@@ -8,6 +8,8 @@ export interface IBuilderPlugin {
|
|
8
8
|
* a mapping of utils will be used in generated code.
|
9
9
|
*/
|
10
10
|
utils: UtilMapping;
|
11
|
+
builder?: TSBuilder;
|
12
|
+
setBuilder(builder: TSBuilder): any;
|
11
13
|
/**
|
12
14
|
* render generated cdoe.
|
13
15
|
* @param name the name of contract
|
@@ -23,9 +25,11 @@ export interface IBuilderPlugin {
|
|
23
25
|
export declare abstract class BuilderPluginBase<TOpt extends {
|
24
26
|
enabled?: boolean;
|
25
27
|
}> implements IBuilderPlugin {
|
28
|
+
builder?: TSBuilder;
|
26
29
|
option: TOpt;
|
27
30
|
utils: UtilMapping;
|
28
|
-
constructor(opt: TOpt);
|
31
|
+
constructor(opt: TOpt, builder?: TSBuilder);
|
32
|
+
setBuilder(builder: TSBuilder): void;
|
29
33
|
render(name: string, contractInfo: ContractInfo, outPath: string): Promise<BuilderFile[]>;
|
30
34
|
/**
|
31
35
|
* init context here
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ContractInfo, RenderContextBase, RenderContext } from "wasm-ast-types";
|
2
|
+
import { BuilderFileType, TSBuilderOptions } from "../builder";
|
3
|
+
import { BuilderPluginBase } from "./plugin-base";
|
4
|
+
export declare class ContractsProviderBundlePlugin extends BuilderPluginBase<TSBuilderOptions> {
|
5
|
+
constructor(opt: TSBuilderOptions);
|
6
|
+
initContext(contract: ContractInfo, options?: TSBuilderOptions): RenderContextBase<TSBuilderOptions>;
|
7
|
+
doRender(name: string, context: RenderContext): Promise<{
|
8
|
+
type: BuilderFileType;
|
9
|
+
pluginType?: string;
|
10
|
+
localname: string;
|
11
|
+
body: any[];
|
12
|
+
}[]>;
|
13
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { ContractInfo, RenderContextBase, RenderContext } from "wasm-ast-types";
|
2
|
+
import { BuilderFileType, TSBuilderOptions } from "../builder";
|
3
|
+
import { BuilderPluginBase } from "./plugin-base";
|
4
|
+
export declare const GetLocalNameByContractName: (name: any) => string;
|
5
|
+
export declare const GetLocalBaseNameByContractName: (name: any) => string;
|
6
|
+
export declare class ContractsContextProviderPlugin extends BuilderPluginBase<TSBuilderOptions> {
|
7
|
+
constructor(opt: TSBuilderOptions);
|
8
|
+
initContext(contract: ContractInfo, options?: TSBuilderOptions): RenderContextBase<TSBuilderOptions>;
|
9
|
+
doRender(name: string, context: RenderContext): Promise<{
|
10
|
+
type: BuilderFileType;
|
11
|
+
pluginType?: string;
|
12
|
+
localname: string;
|
13
|
+
body: any[];
|
14
|
+
}[]>;
|
15
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ContractInfo, RenderContextBase, RenderContext } from 'wasm-ast-types';
|
2
|
+
import { BuilderFileType, TSBuilderOptions } from '../builder';
|
3
|
+
import { BuilderPluginBase } from './plugin-base';
|
4
|
+
export declare class ContractsContextPlugin extends BuilderPluginBase<TSBuilderOptions> {
|
5
|
+
initContext(contract: ContractInfo, options?: TSBuilderOptions): RenderContextBase<TSBuilderOptions>;
|
6
|
+
doRender(name: string, context: RenderContext): Promise<{
|
7
|
+
type: BuilderFileType;
|
8
|
+
pluginType?: string;
|
9
|
+
localname: string;
|
10
|
+
body: any[];
|
11
|
+
}[]>;
|
12
|
+
}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import * as t from "@babel/types";
|
2
|
+
export declare const writeAstToFile: (outPath: string, program: t.Statement[], filename: string, removeUnusedImports?: boolean, isTsDisable?: boolean, isEslintDisable?: boolean) => void;
|
3
|
+
export declare const writeContentToFile: (outPath: string, content: string, filename: string, isTsDisable?: boolean, isEslintDisable?: boolean) => void;
|