@cosmwasm/ts-codegen 1.12.1 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +147 -118
  2. package/builder/builder.js +26 -24
  3. package/bundler/bundler.js +27 -17
  4. package/cli.js +2 -2
  5. package/commands/create-boilerplate.js +29 -18
  6. package/commands/generate.js +26 -35
  7. package/commands/install.js +22 -18
  8. package/esm/builder/builder.js +10 -18
  9. package/esm/bundler/bundler.js +10 -10
  10. package/esm/cli.js +2 -2
  11. package/esm/commands/create-boilerplate.js +11 -10
  12. package/esm/commands/generate.js +26 -35
  13. package/esm/commands/install.js +23 -19
  14. package/esm/file.js +4 -3
  15. package/esm/helpers/baseClient.js +184 -0
  16. package/esm/helpers/contractContextBase.js +15 -13
  17. package/esm/helpers/contractContextBaseShortHandCtor.js +11 -9
  18. package/esm/helpers/contractsContextTSX.js +7 -7
  19. package/esm/helpers/create-helpers.js +3 -1
  20. package/esm/helpers/index.js +1 -0
  21. package/esm/plugins/client.js +1 -1
  22. package/esm/plugins/message-builder.js +4 -4
  23. package/esm/plugins/message-composer.js +1 -1
  24. package/esm/plugins/plugin-base.js +3 -2
  25. package/esm/plugins/provider-bundle.js +9 -5
  26. package/esm/plugins/provider.js +1 -1
  27. package/esm/plugins/react-query.js +8 -7
  28. package/esm/plugins/recoil.js +4 -4
  29. package/esm/plugins/types.js +3 -3
  30. package/esm/ts-codegen.js +2 -1
  31. package/esm/utils/clean.js +1 -1
  32. package/esm/utils/cleanse.js +9 -5
  33. package/esm/utils/package.js +1 -1
  34. package/esm/utils/parse.js +5 -7
  35. package/esm/utils/prompt.js +2 -2
  36. package/esm/utils/schemas.js +32 -19
  37. package/esm/utils/unused.js +3 -4
  38. package/file.js +7 -3
  39. package/helpers/baseClient.d.ts +1 -0
  40. package/helpers/baseClient.js +187 -0
  41. package/helpers/contractContextBase.d.ts +1 -1
  42. package/helpers/contractContextBase.js +15 -13
  43. package/helpers/contractContextBaseShortHandCtor.d.ts +1 -1
  44. package/helpers/contractContextBaseShortHandCtor.js +11 -9
  45. package/helpers/contractsContextTSX.d.ts +1 -1
  46. package/helpers/contractsContextTSX.js +7 -7
  47. package/helpers/create-helpers.js +2 -0
  48. package/helpers/index.d.ts +1 -0
  49. package/helpers/index.js +1 -0
  50. package/package.json +20 -15
  51. package/plugins/client.js +18 -8
  52. package/plugins/message-builder.js +20 -10
  53. package/plugins/message-composer.js +18 -8
  54. package/plugins/plugin-base.js +19 -8
  55. package/plugins/provider-bundle.js +25 -11
  56. package/plugins/provider.js +17 -7
  57. package/plugins/react-query.js +24 -13
  58. package/plugins/recoil.js +20 -10
  59. package/plugins/types.js +19 -9
  60. package/ts-codegen.js +5 -1
  61. package/utils/clean.js +1 -1
  62. package/utils/cleanse.d.ts +1 -0
  63. package/utils/cleanse.js +12 -7
  64. package/utils/files.js +17 -7
  65. package/utils/package.js +2 -3
  66. package/utils/parse.js +5 -7
  67. package/utils/prompt.js +2 -2
  68. package/utils/schemas.d.ts +5 -1
  69. package/utils/schemas.js +34 -20
  70. package/utils/unused.js +20 -11
@@ -3,14 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.contractContextBase = void 0;
4
4
  exports.contractContextBase = `
5
5
  import {
6
- CosmWasmClient,
7
- SigningCosmWasmClient,
8
- } from '@cosmjs/cosmwasm-stargate';
6
+ ICosmWasmClient,
7
+ ISigningCosmWasmClient,
8
+ getCosmWasmClient,
9
+ getSigningCosmWasmClient,
10
+ } from './baseClient';
9
11
 
10
12
  export interface IContractConstructor {
11
13
  address: string | undefined;
12
- cosmWasmClient: CosmWasmClient | undefined;
13
- signingCosmWasmClient: SigningCosmWasmClient | undefined;
14
+ cosmWasmClient: ICosmWasmClient | undefined;
15
+ signingCosmWasmClient: ISigningCosmWasmClient | undefined;
14
16
  }
15
17
 
16
18
  export const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected';
@@ -52,15 +54,15 @@ export class ContractBase<
52
54
  > {
53
55
 
54
56
  address: string | undefined;
55
- cosmWasmClient: CosmWasmClient | undefined;
56
- signingCosmWasmClient: SigningCosmWasmClient | undefined;
57
+ cosmWasmClient: ICosmWasmClient | undefined;
58
+ signingCosmWasmClient: ISigningCosmWasmClient | undefined;
57
59
  TSign?: new (
58
- client: SigningCosmWasmClient,
60
+ client: ISigningCosmWasmClient,
59
61
  sender: string,
60
62
  contractAddress: string
61
63
  ) => TSign;
62
64
  TQuery?: new (
63
- client: CosmWasmClient,
65
+ client: ICosmWasmClient,
64
66
  contractAddress: string
65
67
  ) => TQuery;
66
68
  TMsgComposer?: new (
@@ -70,15 +72,15 @@ export class ContractBase<
70
72
 
71
73
  constructor(
72
74
  address: string | undefined,
73
- cosmWasmClient: CosmWasmClient | undefined,
74
- signingCosmWasmClient: SigningCosmWasmClient | undefined,
75
+ cosmWasmClient: ICosmWasmClient | undefined,
76
+ signingCosmWasmClient: ISigningCosmWasmClient | undefined,
75
77
  TSign?: new (
76
- client: SigningCosmWasmClient,
78
+ client: ISigningCosmWasmClient,
77
79
  sender: string,
78
80
  contractAddress: string
79
81
  ) => TSign,
80
82
  TQuery?: new (
81
- client: CosmWasmClient,
83
+ client: ICosmWasmClient,
82
84
  contractAddress: string
83
85
  ) => TQuery,
84
86
  TMsgComposer?: new (
@@ -1 +1 @@
1
- export declare const contractContextBaseShortHandCtor = "\nimport {\n CosmWasmClient,\n SigningCosmWasmClient,\n} from '@cosmjs/cosmwasm-stargate';\n\nexport interface IContractConstructor {\n address: string | undefined;\n cosmWasmClient: CosmWasmClient | undefined;\n signingCosmWasmClient: SigningCosmWasmClient | undefined;\n}\n\nexport const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected';\n\nexport const NO_COSMWASW_CLIENT_ERROR_MESSAGE = 'cosmWasmClient not connected';\n\nexport const NO_ADDRESS_ERROR_MESSAGE = \"address doesn't exist\";\n\nexport const NO_SIGNING_CLIENT_ERROR_MESSAGE =\n 'Signing client is not generated. Please check ts-codegen config';\n\nexport const NO_QUERY_CLIENT_ERROR_MESSAGE =\n 'Query client is not generated. Please check ts-codegen config';\n\nexport const NO_MESSAGE_COMPOSER_ERROR_MESSAGE =\n 'Message composer client is not generated. Please check ts-codegen config';\n\n/**\n * a placeholder for non-generated classes\n */\nexport interface IEmptyClient {}\n\nexport interface ISigningClientProvider<T> {\n getSigningClient(contractAddr: string): T;\n}\n\nexport interface IQueryClientProvider<T> {\n getQueryClient(contractAddr: string): T;\n}\n\nexport interface IMessageComposerProvider<T> {\n getMessageComposer(contractAddr: string): T;\n}\n\nexport class ContractBase<\n TSign = IEmptyClient,\n TQuery = IEmptyClient,\n TMsgComposer = IEmptyClient\n> {\n constructor(\n protected address: string | undefined,\n protected cosmWasmClient: CosmWasmClient | undefined,\n protected signingCosmWasmClient: SigningCosmWasmClient | undefined,\n private TSign?: new (\n client: SigningCosmWasmClient,\n sender: string,\n contractAddress: string\n ) => TSign,\n private TQuery?: new (\n client: CosmWasmClient,\n contractAddress: string\n ) => TQuery,\n private TMsgComposer?: new (\n sender: string,\n contractAddress: string\n ) => TMsgComposer\n ) {}\n\n public getSigningClient(contractAddr: string): TSign {\n if (!this.signingCosmWasmClient) throw new Error(NO_SINGING_ERROR_MESSAGE);\n if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE);\n if (!this.TSign) throw new Error(NO_SIGNING_CLIENT_ERROR_MESSAGE);\n return new this.TSign(\n this.signingCosmWasmClient,\n this.address,\n contractAddr\n );\n }\n\n public getQueryClient(contractAddr: string): TQuery {\n if (!this.cosmWasmClient) throw new Error(NO_COSMWASW_CLIENT_ERROR_MESSAGE);\n if (!this.TQuery) throw new Error(NO_QUERY_CLIENT_ERROR_MESSAGE);\n return new this.TQuery(this.cosmWasmClient, contractAddr);\n }\n\n public getMessageComposer(contractAddr: string): TMsgComposer {\n if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE);\n if (!this.TMsgComposer) throw new Error(NO_MESSAGE_COMPOSER_ERROR_MESSAGE);\n return new this.TMsgComposer(this.address, contractAddr);\n }\n}\n";
1
+ export declare const contractContextBaseShortHandCtor = "\nimport {\n ICosmWasmClient,\n ISigningCosmWasmClient,\n getCosmWasmClient,\n getSigningCosmWasmClient,\n} from './baseClient';\n\nexport interface IContractConstructor {\n address: string | undefined;\n cosmWasmClient: ICosmWasmClient | undefined;\n signingCosmWasmClient: ISigningCosmWasmClient | undefined;\n}\n\nexport const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected';\n\nexport const NO_COSMWASW_CLIENT_ERROR_MESSAGE = 'cosmWasmClient not connected';\n\nexport const NO_ADDRESS_ERROR_MESSAGE = \"address doesn't exist\";\n\nexport const NO_SIGNING_CLIENT_ERROR_MESSAGE =\n 'Signing client is not generated. Please check ts-codegen config';\n\nexport const NO_QUERY_CLIENT_ERROR_MESSAGE =\n 'Query client is not generated. Please check ts-codegen config';\n\nexport const NO_MESSAGE_COMPOSER_ERROR_MESSAGE =\n 'Message composer client is not generated. Please check ts-codegen config';\n\n/**\n * a placeholder for non-generated classes\n */\nexport interface IEmptyClient {}\n\nexport interface ISigningClientProvider<T> {\n getSigningClient(contractAddr: string): T;\n}\n\nexport interface IQueryClientProvider<T> {\n getQueryClient(contractAddr: string): T;\n}\n\nexport interface IMessageComposerProvider<T> {\n getMessageComposer(contractAddr: string): T;\n}\n\nexport class ContractBase<\n TSign = IEmptyClient,\n TQuery = IEmptyClient,\n TMsgComposer = IEmptyClient\n> {\n constructor(\n protected address: string | undefined,\n protected cosmWasmClient: ICosmWasmClient | undefined,\n protected signingCosmWasmClient: ISigningCosmWasmClient | undefined,\n private TSign?: new (\n client: ISigningCosmWasmClient,\n sender: string,\n contractAddress: string\n ) => TSign,\n private TQuery?: new (\n client: ICosmWasmClient,\n contractAddress: string\n ) => TQuery,\n private TMsgComposer?: new (\n sender: string,\n contractAddress: string\n ) => TMsgComposer\n ) {}\n\n public getSigningClient(contractAddr: string): TSign {\n if (!this.signingCosmWasmClient) throw new Error(NO_SINGING_ERROR_MESSAGE);\n if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE);\n if (!this.TSign) throw new Error(NO_SIGNING_CLIENT_ERROR_MESSAGE);\n return new this.TSign(\n this.signingCosmWasmClient,\n this.address,\n contractAddr\n );\n }\n\n public getQueryClient(contractAddr: string): TQuery {\n if (!this.cosmWasmClient) throw new Error(NO_COSMWASW_CLIENT_ERROR_MESSAGE);\n if (!this.TQuery) throw new Error(NO_QUERY_CLIENT_ERROR_MESSAGE);\n return new this.TQuery(this.cosmWasmClient, contractAddr);\n }\n\n public getMessageComposer(contractAddr: string): TMsgComposer {\n if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE);\n if (!this.TMsgComposer) throw new Error(NO_MESSAGE_COMPOSER_ERROR_MESSAGE);\n return new this.TMsgComposer(this.address, contractAddr);\n }\n}\n";
@@ -3,14 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.contractContextBaseShortHandCtor = void 0;
4
4
  exports.contractContextBaseShortHandCtor = `
5
5
  import {
6
- CosmWasmClient,
7
- SigningCosmWasmClient,
8
- } from '@cosmjs/cosmwasm-stargate';
6
+ ICosmWasmClient,
7
+ ISigningCosmWasmClient,
8
+ getCosmWasmClient,
9
+ getSigningCosmWasmClient,
10
+ } from './baseClient';
9
11
 
10
12
  export interface IContractConstructor {
11
13
  address: string | undefined;
12
- cosmWasmClient: CosmWasmClient | undefined;
13
- signingCosmWasmClient: SigningCosmWasmClient | undefined;
14
+ cosmWasmClient: ICosmWasmClient | undefined;
15
+ signingCosmWasmClient: ISigningCosmWasmClient | undefined;
14
16
  }
15
17
 
16
18
  export const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected';
@@ -52,15 +54,15 @@ export class ContractBase<
52
54
  > {
53
55
  constructor(
54
56
  protected address: string | undefined,
55
- protected cosmWasmClient: CosmWasmClient | undefined,
56
- protected signingCosmWasmClient: SigningCosmWasmClient | undefined,
57
+ protected cosmWasmClient: ICosmWasmClient | undefined,
58
+ protected signingCosmWasmClient: ISigningCosmWasmClient | undefined,
57
59
  private TSign?: new (
58
- client: SigningCosmWasmClient,
60
+ client: ISigningCosmWasmClient,
59
61
  sender: string,
60
62
  contractAddress: string
61
63
  ) => TSign,
62
64
  private TQuery?: new (
63
- client: CosmWasmClient,
65
+ client: ICosmWasmClient,
64
66
  contractAddress: string
65
67
  ) => TQuery,
66
68
  private TMsgComposer?: new (
@@ -1 +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\nexport interface 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: IContractsContext = useContext(ContractsContext);\n if (contracts === null) {\n throw new Error('useContracts must be used within a ContractsProvider');\n }\n return contracts;\n};\n";
1
+ export declare const contractsContextTSX = "\nimport React, { useEffect, useMemo, useRef, useState, useContext } from 'react';\nimport {\n ICosmWasmClient,\n ISigningCosmWasmClient,\n} from './baseClient';\n\nimport { IContractsContext, getProviders } from './contractContextProviders';\n\nexport interface ContractsConfig {\n address: string | undefined;\n getCosmWasmClient: () => Promise<ICosmWasmClient>;\n getSigningCosmWasmClient: () => Promise<ISigningCosmWasmClient>;\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<ICosmWasmClient>();\n const [signingCosmWasmClient, setSigningCosmWasmClient] =\n useState<ISigningCosmWasmClient>();\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: IContractsContext = useContext(ContractsContext);\n if (contracts === null) {\n throw new Error('useContracts must be used within a ContractsProvider');\n }\n return contracts;\n};\n";
@@ -4,16 +4,16 @@ exports.contractsContextTSX = void 0;
4
4
  exports.contractsContextTSX = `
5
5
  import React, { useEffect, useMemo, useRef, useState, useContext } from 'react';
6
6
  import {
7
- CosmWasmClient,
8
- SigningCosmWasmClient,
9
- } from '@cosmjs/cosmwasm-stargate';
7
+ ICosmWasmClient,
8
+ ISigningCosmWasmClient,
9
+ } from './baseClient';
10
10
 
11
11
  import { IContractsContext, getProviders } from './contractContextProviders';
12
12
 
13
13
  export interface ContractsConfig {
14
14
  address: string | undefined;
15
- getCosmWasmClient: () => Promise<CosmWasmClient>;
16
- getSigningCosmWasmClient: () => Promise<SigningCosmWasmClient>;
15
+ getCosmWasmClient: () => Promise<ICosmWasmClient>;
16
+ getSigningCosmWasmClient: () => Promise<ISigningCosmWasmClient>;
17
17
  }
18
18
 
19
19
  const ContractsContext = React.createContext<IContractsContext | null>(null);
@@ -25,9 +25,9 @@ export const ContractsProvider = ({
25
25
  children: React.ReactNode;
26
26
  contractsConfig: ContractsConfig;
27
27
  }) => {
28
- const [cosmWasmClient, setCosmWasmClient] = useState<CosmWasmClient>();
28
+ const [cosmWasmClient, setCosmWasmClient] = useState<ICosmWasmClient>();
29
29
  const [signingCosmWasmClient, setSigningCosmWasmClient] =
30
- useState<SigningCosmWasmClient>();
30
+ useState<ISigningCosmWasmClient>();
31
31
 
32
32
  const { address, getCosmWasmClient, getSigningCosmWasmClient } =
33
33
  contractsConfig;
@@ -20,6 +20,8 @@ const write = (outPath, file, content, varname) => {
20
20
  };
21
21
  const createHelpers = (input, builderContext) => {
22
22
  const files = [];
23
+ // Always generate baseClient.ts since InterchainJS interfaces are needed by all clients
24
+ files.push(write(input.outPath, 'baseClient.ts', helpers_1.baseClient));
23
25
  if (input.options?.useContractsHook?.enabled &&
24
26
  Object.keys(builderContext.providers)?.length) {
25
27
  const useShorthandCtor = input.options?.useShorthandCtor;
@@ -1,3 +1,4 @@
1
1
  export * from './contractContextBase';
2
2
  export * from './contractContextBaseShortHandCtor';
3
+ export * from './baseClient';
3
4
  export * from './contractsContextTSX';
package/helpers/index.js CHANGED
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./contractContextBase"), exports);
18
18
  __exportStar(require("./contractContextBaseShortHandCtor"), exports);
19
+ __exportStar(require("./baseClient"), exports);
19
20
  __exportStar(require("./contractsContextTSX"), exports);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "1.12.1",
3
+ "version": "1.13.1",
4
4
  "description": "@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
- "homepage": "https://github.com/cosmwasm/ts-codegen",
6
+ "homepage": "https://github.com/hyperweb-io/ts-codegen",
7
7
  "license": "SEE LICENSE IN LICENSE",
8
8
  "main": "index.js",
9
9
  "module": "esm/index.js",
@@ -20,31 +20,34 @@
20
20
  "copy": "copyfiles -f LICENSE-Apache LICENSE-MIT README.md package.json dist",
21
21
  "clean": "rimraf dist/**",
22
22
  "prepare": "npm run build",
23
- "cmds": "ts-node ./scripts/cmds.ts",
23
+ "cmds": "tsx ./scripts/cmds.ts",
24
24
  "build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
25
25
  "lint": "eslint . --fix",
26
+ "format": "prettier --write --log-level warn \"./**/*.ts\"",
26
27
  "test": "jest",
27
28
  "test:watch": "jest --watch",
28
- "dev": "ts-node src/ts-codegen",
29
- "file": "ts-node src/file"
29
+ "dev": "tsx src/ts-codegen",
30
+ "file": "tsx src/file"
30
31
  },
31
32
  "repository": {
32
33
  "type": "git",
33
- "url": "https://github.com/cosmwasm/ts-codegen"
34
+ "url": "https://github.com/hyperweb-io/ts-codegen"
34
35
  },
35
36
  "bugs": {
36
- "url": "https://github.com/cosmwasm/ts-codegen/issues"
37
- },
38
- "devDependencies": {
39
- "@cosmjs/cosmwasm-stargate": "0.32.3",
40
- "ast-stringify": "0.1.0"
37
+ "url": "https://github.com/hyperweb-io/ts-codegen/issues"
41
38
  },
42
39
  "dependencies": {
43
40
  "@babel/generator": "7.24.4",
44
41
  "@babel/traverse": "7.24.1",
45
42
  "@babel/types": "7.24.0",
46
- "@cosmwasm/ts-codegen-ast": "^1.8.1",
47
- "@cosmwasm/ts-codegen-types": "^1.3.1",
43
+ "@chain-registry/types": "^0.17.1",
44
+ "@chain-registry/utils": "^1.51.71",
45
+ "@chain-registry/v2": "^1.71.229",
46
+ "@cosmwasm/ts-codegen-ast": "^1.9.1",
47
+ "@cosmwasm/ts-codegen-types": "^1.4.1",
48
+ "@interchainjs/amino": "1.17.1",
49
+ "@interchainjs/cosmos": "1.17.1",
50
+ "@interchainjs/types": "1.17.1",
48
51
  "@pyramation/json-schema-to-typescript": " 11.0.4",
49
52
  "@types/rimraf": "3.0.2",
50
53
  "@types/shelljs": "0.8.15",
@@ -52,8 +55,10 @@
52
55
  "dargs": "7.0.0",
53
56
  "deepmerge": "4.2.2",
54
57
  "fuzzy": "0.1.3",
55
- "glob": "8.0.3",
58
+ "glob": "^10",
56
59
  "inquirerer": "0.1.3",
60
+ "interchainjs": "1.17.1",
61
+ "minimatch": "^10.0.3",
57
62
  "minimist": "1.2.6",
58
63
  "mkdirp": "1.0.4",
59
64
  "nested-obj": "0.0.1",
@@ -67,5 +72,5 @@
67
72
  "smart contracts",
68
73
  "codegen"
69
74
  ],
70
- "gitHead": "be8802a215dbc75df9af75dba2f6ac17c04d6938"
75
+ "gitHead": "472007b2c11c211f16e18d4653350bf7a8e16901"
71
76
  }
package/plugins/client.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.ClientPlugin = void 0;
27
37
  const w = __importStar(require("@cosmwasm/ts-codegen-ast"));
@@ -69,7 +79,7 @@ class ClientPlugin extends plugin_base_1.BuilderPluginBase {
69
79
  context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
70
80
  }
71
81
  }
72
- if (typeHash.hasOwnProperty('Coin')) {
82
+ if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
73
83
  // @ts-ignore
74
84
  delete context.utils.Coin;
75
85
  }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.MessageBuilderPlugin = void 0;
27
37
  const w = __importStar(require("@cosmwasm/ts-codegen-ast"));
@@ -63,7 +73,7 @@ class MessageBuilderPlugin extends plugin_base_1.BuilderPluginBase {
63
73
  body.push(w.createMessageBuilderClass(context, className, QueryMsg));
64
74
  }
65
75
  }
66
- if (typeHash.hasOwnProperty('Coin')) {
76
+ if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
67
77
  // @ts-ignore
68
78
  delete context.utils.Coin;
69
79
  }
@@ -71,8 +81,8 @@ class MessageBuilderPlugin extends plugin_base_1.BuilderPluginBase {
71
81
  {
72
82
  type: 'message-builder',
73
83
  localname,
74
- body
75
- }
84
+ body,
85
+ },
76
86
  ];
77
87
  }
78
88
  }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.MessageComposerPlugin = void 0;
27
37
  const w = __importStar(require("@cosmwasm/ts-codegen-ast"));
@@ -56,7 +66,7 @@ class MessageComposerPlugin extends plugin_base_1.BuilderPluginBase {
56
66
  context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
57
67
  }
58
68
  }
59
- if (typeHash.hasOwnProperty('Coin')) {
69
+ if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
60
70
  // @ts-ignore
61
71
  delete context.utils.Coin;
62
72
  }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -70,8 +80,9 @@ class BuilderPluginBase {
70
80
  }
71
81
  return results.map((result) => {
72
82
  const imports = context.getImports(this.utils, result.localname);
83
+ const nodes = [...imports, ...result.body];
73
84
  // @ts-ignore
74
- const code = header_1.header + (0, generator_1.default)(t.program([...imports, ...result.body])).code;
85
+ const code = header_1.header + (0, generator_1.default)(t.program(nodes)).code;
75
86
  (0, mkdirp_1.sync)(outPath);
76
87
  const filename = (0, path_1.join)(outPath, result.localname);
77
88
  (0, fs_1.writeFileSync)(filename, code);
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.ContractsProviderBundlePlugin = void 0;
27
37
  const w = __importStar(require("@cosmwasm/ts-codegen-ast"));
@@ -35,8 +45,10 @@ class ContractsProviderBundlePlugin extends plugin_base_1.BuilderPluginBase {
35
45
  this.lifecycle = 'after';
36
46
  this.defaultContractName = 'contractContextProviders';
37
47
  this.utils = {
38
- CosmWasmClient: '@cosmjs/cosmwasm-stargate',
39
- SigningCosmWasmClient: '@cosmjs/cosmwasm-stargate',
48
+ ICosmWasmClient: '__baseClient__',
49
+ ISigningCosmWasmClient: '__baseClient__',
50
+ getCosmWasmClient: '__baseClient__',
51
+ getSigningCosmWasmClient: '__baseClient__',
40
52
  IQueryClientProvider: '__contractContextBase__',
41
53
  ISigningClientProvider: '__contractContextBase__',
42
54
  IMessageComposerProvider: '__contractContextBase__',
@@ -55,8 +67,10 @@ class ContractsProviderBundlePlugin extends plugin_base_1.BuilderPluginBase {
55
67
  }
56
68
  const localname = 'contractContextProviders.ts';
57
69
  const body = [];
58
- context.addUtil('CosmWasmClient');
59
- context.addUtil('SigningCosmWasmClient');
70
+ context.addUtil('ICosmWasmClient');
71
+ context.addUtil('ISigningCosmWasmClient');
72
+ context.addUtil('getCosmWasmClient');
73
+ context.addUtil('getSigningCosmWasmClient');
60
74
  context.addUtil('IQueryClientProvider');
61
75
  context.addUtil('ISigningClientProvider');
62
76
  context.addUtil('IMessageComposerProvider');
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.ContractsContextProviderPlugin = exports.GetLocalBaseNameByContractName = exports.GetLocalNameByContractName = void 0;
27
37
  const w = __importStar(require("@cosmwasm/ts-codegen-ast"));
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.ReactQueryPlugin = void 0;
27
37
  const w = __importStar(require("@cosmwasm/ts-codegen-ast"));
@@ -50,7 +60,8 @@ class ReactQueryPlugin extends plugin_base_1.BuilderPluginBase {
50
60
  const QueryClient = (0, case_1.pascal)(`${name}QueryClient`);
51
61
  const body = [];
52
62
  const clientImports = [];
53
- QueryMsg && clientImports.push(QueryClient);
63
+ if (QueryMsg)
64
+ clientImports.push(QueryClient);
54
65
  // check that there are commands within the exec msg
55
66
  const shouldGenerateMutationHooks = ExecuteMsg &&
56
67
  options?.version === 'v4' &&
@@ -69,7 +80,7 @@ class ReactQueryPlugin extends plugin_base_1.BuilderPluginBase {
69
80
  context,
70
81
  queryMsg: QueryMsg,
71
82
  contractName: name,
72
- QueryClient
83
+ QueryClient,
73
84
  }));
74
85
  }
75
86
  if (shouldGenerateMutationHooks) {
@@ -77,10 +88,10 @@ class ReactQueryPlugin extends plugin_base_1.BuilderPluginBase {
77
88
  context,
78
89
  execMsg: ExecuteMsg,
79
90
  contractName: name,
80
- ExecuteClient
91
+ ExecuteClient,
81
92
  }));
82
93
  }
83
- if (typeHash.hasOwnProperty('Coin')) {
94
+ if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
84
95
  // @ts-ignore
85
96
  delete context.utils.Coin;
86
97
  }
@@ -88,8 +99,8 @@ class ReactQueryPlugin extends plugin_base_1.BuilderPluginBase {
88
99
  {
89
100
  type: 'react-query',
90
101
  localname,
91
- body
92
- }
102
+ body,
103
+ },
93
104
  ];
94
105
  }
95
106
  }