@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
package/README.md CHANGED
@@ -7,8 +7,8 @@ Generate TypeScript SDKs for your CosmWasm smart contracts
7
7
  </p>
8
8
 
9
9
  <p align="center" width="100%">
10
- <a href="https://github.com/CosmWasm/ts-codegen/actions/workflows/run-tests.yaml">
11
- <img height="20" src="https://github.com/CosmWasm/ts-codegen/actions/workflows/run-tests.yaml/badge.svg" />
10
+ <a href="https://github.com/hyperweb-io/ts-codegen/actions/workflows/run-tests.yaml">
11
+ <img height="20" src="https://github.com/hyperweb-io/ts-codegen/actions/workflows/run-tests.yaml/badge.svg" />
12
12
  </a>
13
13
  <a href="https://github.com/hyperweb-io/lib-count">
14
14
  <img height="20" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fhyperweb-io%2Flib-count%2Fmain%2Foutput%2Fbadges%2Fproducts%2Fcosmwasm%2Ftotal.json"/>
@@ -17,12 +17,11 @@ Generate TypeScript SDKs for your CosmWasm smart contracts
17
17
  <img height="20" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fhyperweb-io%2Flib-count%2Fmain%2Foutput%2Fbadges%2Fproducts%2Fcosmwasm%2Fmonthly.json"/>
18
18
  </a>
19
19
  <br />
20
- <a href="https://github.com/CosmWasm/ts-codegen/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
21
- <a href="https://github.com/CosmWasm/ts-codegen/blob/main/LICENSE-Apache"><img height="20" src="https://img.shields.io/badge/license-Apache-blue.svg"></a>
20
+ <a href="https://github.com/hyperweb-io/ts-codegen/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
21
+ <a href="https://github.com/hyperweb-io/ts-codegen/blob/main/LICENSE-Apache"><img height="20" src="https://img.shields.io/badge/license-Apache-blue.svg"></a>
22
22
  <a href="https://www.npmjs.com/package/@cosmwasm/ts-codegen"><img height="20" src="https://img.shields.io/github/package-json/v/CosmWasm/ts-codegen?filename=packages%2Fts-codegen%2Fpackage.json"></a>
23
23
  </p>
24
24
 
25
-
26
25
  ```
27
26
  npm install @cosmwasm/ts-codegen
28
27
  ```
@@ -30,25 +29,26 @@ npm install @cosmwasm/ts-codegen
30
29
  The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-codegen` converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.
31
30
 
32
31
  🎥 [Checkout our video playlist](https://cosmology.zone/learn/ts-codegen) to learn how to use `ts-codegen`!
32
+
33
33
  ## Table of contents
34
34
 
35
35
  - [@cosmwasm/ts-codegen](#cosmwasmts-codegen)
36
36
  - [Table of contents](#table-of-contents)
37
37
  - [Usage](#usage)
38
- - [Programmatic Usage](#programmatic-usage)
39
- - [Types](#types)
40
- - [TS Clients](#client)
41
- - [React Query](#react-query)
42
- - [Recoil](#recoil)
43
- - [Message Composer](#message-composer)
44
- - [Message Builder](#message-builder)
45
- - [Use Contracts Hook](#use-contracts-hooks-usage)
46
- - [Bundles](#bundles)
47
- - [CLI Usage and Examples](#cli-usage-and-examples)
48
- - [Advanced Usage](#advanced-usage)
38
+ - [Programmatic Usage](#programmatic-usage)
39
+ - [Types](#types)
40
+ - [TS Clients](#client)
41
+ - [React Query](#react-query)
42
+ - [Recoil](#recoil)
43
+ - [Message Composer](#message-composer)
44
+ - [Message Builder](#message-builder)
45
+ - [Use Contracts Hook](#use-contracts-hooks-usage)
46
+ - [Bundles](#bundles)
47
+ - [CLI Usage and Examples](#cli-usage-and-examples)
48
+ - [Advanced Usage](#advanced-usage)
49
49
  - [JSON Schema](#json-schema)
50
- - [JSON Schema Generation](#json-schema-generation)
51
- - [Exporting Schemas](#exporting-schemas)
50
+ - [JSON Schema Generation](#json-schema-generation)
51
+ - [Exporting Schemas](#exporting-schemas)
52
52
  - [Developing](#developing)
53
53
  - [Related](#related)
54
54
 
@@ -59,93 +59,131 @@ The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-
59
59
  For production usage, we recommend setting up a build script that uses the main entry point:
60
60
 
61
61
  ```ts
62
- import codegen from '@cosmwasm/ts-codegen';
62
+ import codegen from "@cosmwasm/ts-codegen";
63
63
 
64
64
  codegen({
65
65
  contracts: [
66
66
  {
67
- name: 'SG721',
68
- dir: './path/to/sg721/schema'
67
+ name: "SG721",
68
+ dir: "./path/to/sg721/schema",
69
69
  },
70
70
  {
71
- name: 'Minter',
72
- dir: './path/to/Minter/schema'
73
- }
71
+ name: "Minter",
72
+ dir: "./path/to/Minter/schema",
73
+ },
74
74
  ],
75
- outPath: './path/to/code/src/',
75
+ outPath: "./path/to/code/src/",
76
76
 
77
77
  // options are completely optional ;)
78
78
  options: {
79
79
  bundle: {
80
- bundleFile: 'index.ts',
81
- scope: 'contracts'
80
+ bundleFile: "index.ts",
81
+ scope: "contracts",
82
82
  },
83
83
  types: {
84
- enabled: true
84
+ enabled: true,
85
85
  },
86
86
  client: {
87
- enabled: true
87
+ enabled: true,
88
88
  },
89
89
  reactQuery: {
90
90
  enabled: true,
91
91
  optionalClient: true,
92
- version: 'v4',
92
+ version: "v4",
93
93
  mutations: true,
94
94
  queryKeys: true,
95
95
  queryFactory: true,
96
96
  },
97
97
  recoil: {
98
- enabled: false
98
+ enabled: false,
99
99
  },
100
100
  messageComposer: {
101
- enabled: false
101
+ enabled: false,
102
102
  },
103
103
  messageBuilder: {
104
- enabled: false
104
+ enabled: false,
105
105
  },
106
106
  useContractsHook: {
107
- enabled: false
108
- }
109
- }
107
+ enabled: false,
108
+ },
109
+ },
110
110
  }).then(() => {
111
- console.log('✨ all done!');
111
+ console.log("✨ all done!");
112
112
  });
113
113
  ```
114
+
114
115
  #### Types
115
116
 
116
117
  Typescript types and interfaces are generated in separate files so they can be imported into various generated plugins.
117
118
 
118
- [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.types.ts)
119
+ [see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.types.ts)
119
120
 
120
121
  #### Types Options
121
122
 
122
- | option | description |
123
- | ------------------------ | ---------------------------------------------------- |
124
- | `types.enabled` | enable type generation |
125
- | `types.aliasExecuteMsg` | generate a type alias based on the contract name |
126
- | `types.aliasEntryPoints` | generate type aliases for the entry points based on the contract name |
123
+ | option | description |
124
+ | ------------------------ | --------------------------------------------------------------------- |
125
+ | `types.enabled` | enable type generation |
126
+ | `types.aliasExecuteMsg` | generate a type alias based on the contract name |
127
+ | `types.aliasEntryPoints` | generate type aliases for the entry points based on the contract name |
128
+
129
+ ### BaseClient
130
+ The `baseClient.ts` will be generated as dependency for most files. It includes the base client for interchainjs.
131
+
132
+ #### Gas Configuration
133
+
134
+ The generated client provides flexible gas fee configuration options to handle different blockchain networks and fee settings.
135
+
136
+ ##### Default Gas Settings
137
+
138
+ By default, the client uses a gas limit of `200000` for all transactions. You can customize this behavior through the `setDefaultGasAmount`.
139
+
140
+ ##### ChainConfig Options
141
+
142
+ The `ChainConfig` interface supports two approaches for gas configuration:
143
+
144
+ 1. Chain Registry Integration (Recommended)
145
+
146
+ When you provide chain information, the client automatically fetches gas prices from the chain registry:
147
+
148
+ ```typescript
149
+ import { useChain } from '@interchain-kit/react';
150
+
151
+ const { chain } = useChain('osmosistestnet');
152
+ const chainConfig: ChainConfig = { chain: chain };
153
+ ```
154
+
155
+ 2. Manual Gas Price Configuration
156
+ You can explicitly set gas prices for more control:
157
+
158
+ ```typescript
159
+ const chainConfig: ChainConfig = {
160
+ gasPrice: {
161
+ denom: 'uosmo',
162
+ amount: '0.025'
163
+ }
164
+ };
165
+ ```
127
166
 
128
167
  ### Client
129
168
 
130
169
  The `client` plugin will generate TS client classes for your contracts. This option generates a `QueryClient` for queries as well as a `Client` for queries and mutations.
131
170
 
132
- [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.client.ts )
171
+ [see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.client.ts)
133
172
 
134
173
  #### Client Options
135
174
 
136
- | option | description |
137
- | --------------------------------------- | --------------------------------------------------- |
138
- | `client.enabled` | generate TS client classes for your contracts |
139
- | `client.execExtendsQuery` | execute should extend query message clients |
140
- | `client.noImplicitOverride` | should match your tsconfig noImplicitOverride option |
141
- | `client.useDeclareKeyword` | use declare keyword for inherited class fields |
142
-
175
+ | option | description |
176
+ | --------------------------- | ---------------------------------------------------- |
177
+ | `client.enabled` | generate TS client classes for your contracts |
178
+ | `client.execExtendsQuery` | execute should extend query message clients |
179
+ | `client.noImplicitOverride` | should match your tsconfig noImplicitOverride option |
180
+ | `client.useDeclareKeyword` | use declare keyword for inherited class fields |
143
181
 
144
182
  ### React Query
145
183
 
146
184
  Generate [react-query v3](https://react-query-v3.tanstack.com/) or [react-query v4](https://tanstack.com/query/v4/) bindings for your contracts with the `react-query` command.
147
185
 
148
- [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.react-query.ts)
186
+ [see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.react-query.ts)
149
187
 
150
188
  #### React Query Options
151
189
 
@@ -159,72 +197,66 @@ Generate [react-query v3](https://react-query-v3.tanstack.com/) or [react-query
159
197
  | `reactQuery.mutations` | also generate mutations |
160
198
  | `reactQuery.camelize` | use camelCase style for property names |
161
199
 
162
-
163
200
  ### Recoil
164
201
 
165
202
  Generate [recoil](https://recoiljs.org/) bindings for your contracts with the `recoil` command.
166
203
 
167
- [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.recoil.ts)
204
+ [see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.recoil.ts)
168
205
 
169
206
  #### Recoil Options
170
207
 
171
- | option | description |
172
- | ------------------------------ | ------------------------------------------------------------------- |
173
- | `recoil.enabled` | enable the recoil plugin |
208
+ | option | description |
209
+ | ---------------- | ------------------------ |
210
+ | `recoil.enabled` | enable the recoil plugin |
174
211
 
175
212
  ### Message Composer
176
213
 
177
- Generate pure message objects with the proper `utf8` encoding and `typeUrl` configured that you can broadcast yourself via `cosmjs` with the `message-composer` command.
214
+ Generate pure message objects with the proper `utf8` encoding and `typeUrl` configured that you can broadcast yourself via `interchainjs` with the `message-composer` command.
178
215
 
179
- [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.message-composer.ts)
216
+ [see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.message-composer.ts)
180
217
 
181
218
  #### Message Composer Options
182
219
 
183
- | option | description |
184
- | ------------------------------ | ------------------------------------------------------------------- |
185
- | `messageComposer.enabled` | enable the messageComposer plugin |
220
+ | option | description |
221
+ | ------------------------- | --------------------------------- |
222
+ | `messageComposer.enabled` | enable the messageComposer plugin |
186
223
 
187
224
  ### Message Builder
188
225
 
189
226
  Generate raw message jsons for use in your application with the `message-builder` command.
190
227
 
191
- [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.message-builder.ts)
228
+ [see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.message-builder.ts)
192
229
 
193
230
  #### Message Builder Options
194
231
 
195
- | option | description |
196
- |------------------------- | ---------------------------------- |
197
- | `messageBuilder.enabled` | enable the messageBuilder plugin |
198
-
232
+ | option | description |
233
+ | ------------------------ | -------------------------------- |
234
+ | `messageBuilder.enabled` | enable the messageBuilder plugin |
199
235
 
200
236
  ### `useContracts` Hook
201
237
 
202
238
  Generates `useContracts` hook to easily access contracts, already equipped with a signing client
203
239
 
204
- | option | description |
205
- | -------------------------------- | --------------------------------------- |
206
- | `useContractsHook.enabled` | enable the `useContracts` plugin |
240
+ | option | description |
241
+ | -------------------------- | -------------------------------- |
242
+ | `useContractsHook.enabled` | enable the `useContracts` plugin |
207
243
 
208
244
  #### Example Output
209
245
 
210
- - [Provider](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/Factory.provider.ts)
211
- - [Contract Providers](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contractContextProviders.ts)
212
- - [Contract Context](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contracts-context.tsx)
213
- - [Context Base](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contractContextBase.ts)
246
+ - [Provider](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/Factory.provider.ts)
247
+ - [Contract Providers](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contractContextProviders.ts)
248
+ - [Contract Context](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contracts-context.tsx)
249
+ - [Context Base](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contractContextBase.ts)
214
250
 
215
251
  #### Use Contracts Provider Usage
216
252
 
217
253
  ```tsx
218
- import { useChain } from '@cosmos-kit/react';
219
- import { ContractsProvider } from '../path/to/codegen/contracts-context';
254
+ import { useChain } from "@cosmos-kit/react";
255
+ import { ContractsProvider } from "../path/to/codegen/contracts-context";
220
256
 
221
257
  export default function YourComponent() {
222
-
223
- const {
224
- address,
225
- getCosmWasmClient,
226
- getSigningCosmWasmClient
227
- } = useChain(chainName);
258
+ const { address, getCosmWasmClient, getSigningCosmWasmClient } =
259
+ useChain(chainName);
228
260
 
229
261
  return (
230
262
  <ContractsProvider
@@ -234,10 +266,10 @@ export default function YourComponent() {
234
266
  getSigningCosmWasmClient,
235
267
  }}
236
268
  >
237
- <SomeCoolComponent />
269
+ <SomeCoolComponent />
238
270
  </ContractsProvider>
239
- )
240
- };
271
+ );
272
+ }
241
273
  ```
242
274
 
243
275
  #### Use Contracts Provider Babel/TSC config
@@ -245,11 +277,7 @@ export default function YourComponent() {
245
277
  If you're using Babel, please make sure include `'@babel/preset-react'` in devDeps and presets in `.babelrc.js`:
246
278
 
247
279
  ```js
248
- presets: [
249
- '@babel/typescript',
250
- '@babel/env',
251
- '@babel/preset-react',
252
- ]
280
+ presets: ["@babel/typescript", "@babel/env", "@babel/preset-react"];
253
281
  ```
254
282
 
255
283
  For `tsc`, you should set the `jsx` option to `'react'` in your `tsconfig.json`.
@@ -279,26 +307,24 @@ await marketplaceClient.updateAskPrice({
279
307
  The bundler will make a nice package of all your contracts. For example:
280
308
 
281
309
  ```ts
282
- const {
283
- MinterQueryClient,
284
- useMinterConfigQuery
285
- } = contracts.Minter;
310
+ const { MinterQueryClient, useMinterConfigQuery } = contracts.Minter;
286
311
 
287
312
  const { CwAdminFactoryClient } = contracts.CwAdminFactory;
288
313
  ```
314
+
289
315
  #### Bundler Options
290
316
 
291
- | option | description |
292
- | --------------------- | -------------------------------------------------------------------------------- |
293
- | `bundle.enabled` | enable the bundler plugin |
294
- | `bundle.scope` | name of the scope, defaults to `contracts` (you can use `.` to make more scopes) |
295
- | `bundle.bundleFile` | name of the bundle file |
317
+ | option | description |
318
+ | ------------------- | -------------------------------------------------------------------------------- |
319
+ | `bundle.enabled` | enable the bundler plugin |
320
+ | `bundle.scope` | name of the scope, defaults to `contracts` (you can use `.` to make more scopes) |
321
+ | `bundle.bundleFile` | name of the bundle file |
296
322
 
297
323
  #### Coding Style
298
324
 
299
- | option | description | default |
300
- | --------------------- | ------------------------------------ | ------- |
301
- | `useShorthandCtor` | Enable using shorthand constructor. | true |
325
+ | option | description | default |
326
+ | ------------------ | ----------------------------------- | ------- |
327
+ | `useShorthandCtor` | Enable using shorthand constructor. | true |
302
328
 
303
329
  Using shorthand constructor (Might not be transpiled correctly with babel):
304
330
 
@@ -386,9 +412,10 @@ cosmwasm-ts-codegen generate
386
412
  ◯ recoil
387
413
  ◯ react-query
388
414
  ◯ message-composer
389
- ```
415
+ ```
390
416
 
391
417
  In this example, you can press space bar to select a number of plugins you wish you enable.
418
+
392
419
  #### Specifying Plugins
393
420
 
394
421
  Additionally, it will also show you the name of the field (in this case `plugin`) so you can specify the parameter (for example when using CI/CD) on the comand line. Here is an exampl with `--plugin` set to `client` via CLI:
@@ -399,7 +426,7 @@ ts-codegen generate \
399
426
  --schema ./schema \
400
427
  --out ./ts \
401
428
  --name MyContractName
402
- ```
429
+ ```
403
430
 
404
431
  You can specify multiple `--plugin` options using the `generate` command:
405
432
 
@@ -465,7 +492,6 @@ ts-codegen generate \
465
492
  --name MyContractName
466
493
  ```
467
494
 
468
-
469
495
  #### React Query via CLI
470
496
 
471
497
  Here is an example without optional client, using v3 for `react-query`, without mutations:
@@ -528,6 +554,7 @@ ts-codegen generate \
528
554
  ### JSON Schema
529
555
 
530
556
  We generate code from the [JSON Schema](https://json-schema.org/) exported from CosmWasm smart contracts.
557
+
531
558
  ### JSON Schema Generation
532
559
 
533
560
  Currently you have to have the JSON Schema output. Here is an example to start.
@@ -546,7 +573,9 @@ now build the schema with `cargo schema`
546
573
  cd contracts/sg721/
547
574
  cargo schema
548
575
  ```
576
+
549
577
  ### Exporting Schemas
578
+
550
579
  #### `cosmwasm v1.1` Example
551
580
 
552
581
  Using the new `write_api` method, you can export schemas:
@@ -608,23 +637,23 @@ yarn test:watch
608
637
 
609
638
  ### Working with ASTs
610
639
 
611
- See the [docs](https://github.com/CosmWasm/ts-codegen/blob/main/packages/ast/README.md) in the `@cosmwasm/ts-codegen-ast` package.
640
+ See the [docs](https://github.com/hyperweb-io/ts-codegen/blob/main/packages/ast/README.md) in the `@cosmwasm/ts-codegen-ast` package.
612
641
 
613
- ## Interchain JavaScript Stack
642
+ ## Interchain JavaScript Stack
614
643
 
615
644
  A unified toolkit for building applications and smart contracts in the Interchain ecosystem ⚛️
616
645
 
617
- | Category | Tools | Description |
618
- |----------------------|------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
619
- | **Chain Information** | [**Chain Registry**](https://github.com/hyperweb-io/chain-registry), [**Utils**](https://www.npmjs.com/package/@chain-registry/utils), [**Client**](https://www.npmjs.com/package/@chain-registry/client) | Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application. |
620
- | **Wallet Connectors**| [**Interchain Kit**](https://github.com/hyperweb-io/interchain-kit)<sup>beta</sup>, [**Cosmos Kit**](https://github.com/hyperweb-io/cosmos-kit) | Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface. |
621
- | **Signing Clients** | [**InterchainJS**](https://github.com/hyperweb-io/interchainjs)<sup>beta</sup>, [**CosmJS**](https://github.com/cosmos/cosmjs) | A single, universal signing interface for any network |
622
- | **SDK Clients** | [**Telescope**](https://github.com/hyperweb-io/telescope) | Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules. |
623
- | **Starter Kits** | [**Create Interchain App**](https://github.com/hyperweb-io/create-interchain-app)<sup>beta</sup>, [**Create Cosmos App**](https://github.com/hyperweb-io/create-cosmos-app) | Set up a modern Interchain app by running one command. |
624
- | **UI Kits** | [**Interchain UI**](https://github.com/hyperweb-io/interchain-ui) | The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit. |
625
- | **Testing Frameworks** | [**Starship**](https://github.com/hyperweb-io/starship) | Unified Testing and Development for the Interchain. |
626
- | **TypeScript Smart Contracts** | [**Create Hyperweb App**](https://github.com/hyperweb-io/create-hyperweb-app) | Build and deploy full-stack blockchain applications with TypeScript |
627
- | **CosmWasm Contracts** | [**CosmWasm TS Codegen**](https://github.com/CosmWasm/ts-codegen) | Convert your CosmWasm smart contracts into dev-friendly TypeScript classes. |
646
+ | Category | Tools | Description |
647
+ | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
648
+ | **Chain Information** | [**Chain Registry**](https://github.com/hyperweb-io/chain-registry), [**Utils**](https://www.npmjs.com/package/@chain-registry/utils), [**Client**](https://www.npmjs.com/package/@chain-registry/client) | Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application. |
649
+ | **Wallet Connectors** | [**Interchain Kit**](https://github.com/hyperweb-io/interchain-kit)<sup>beta</sup>, [**Cosmos Kit**](https://github.com/hyperweb-io/cosmos-kit) | Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface. |
650
+ | **Signing Clients** | [**InterchainJS**](https://github.com/hyperweb-io/interchainjs)<sup>beta</sup>, [**CosmJS**](https://github.com/cosmos/cosmjs) | A single, universal signing interface for any network |
651
+ | **SDK Clients** | [**Telescope**](https://github.com/hyperweb-io/telescope) | Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules. |
652
+ | **Starter Kits** | [**Create Interchain App**](https://github.com/hyperweb-io/create-interchain-app)<sup>beta</sup>, [**Create Cosmos App**](https://github.com/hyperweb-io/create-cosmos-app) | Set up a modern Interchain app by running one command. |
653
+ | **UI Kits** | [**Interchain UI**](https://github.com/hyperweb-io/interchain-ui) | The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit. |
654
+ | **Testing Frameworks** | [**Starship**](https://github.com/hyperweb-io/starship) | Unified Testing and Development for the Interchain. |
655
+ | **TypeScript Smart Contracts** | [**Create Hyperweb App**](https://github.com/hyperweb-io/create-hyperweb-app) | Build and deploy full-stack blockchain applications with TypeScript |
656
+ | **CosmWasm Contracts** | [**CosmWasm TS Codegen**](https://github.com/hyperweb-io/ts-codegen) | Convert your CosmWasm smart contracts into dev-friendly TypeScript classes. |
628
657
 
629
658
  ## Credits
630
659
 
@@ -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
  };
@@ -53,25 +63,22 @@ const defaultOpts = {
53
63
  bundle: {
54
64
  enabled: true,
55
65
  scope: 'contracts',
56
- bundleFile: 'bundle.ts'
66
+ bundleFile: 'bundle.ts',
57
67
  },
58
- useShorthandCtor: true
68
+ useShorthandCtor: true,
59
69
  };
60
- ;
61
- ;
62
- ;
63
70
  function getContract(contractOpt) {
64
71
  if (typeof contractOpt === 'string') {
65
72
  const name = (0, path_2.basename)(contractOpt);
66
73
  const contractName = (0, case_1.pascal)(name);
67
74
  return {
68
75
  name: contractName,
69
- dir: contractOpt
76
+ dir: contractOpt,
70
77
  };
71
78
  }
72
79
  return {
73
80
  name: (0, case_1.pascal)(contractOpt.name),
74
- dir: contractOpt.dir
81
+ dir: contractOpt.dir,
75
82
  };
76
83
  }
77
84
  class TSBuilder {
@@ -92,7 +99,7 @@ class TSBuilder {
92
99
  if (plugins && plugins.length) {
93
100
  this.plugins.push(...plugins);
94
101
  }
95
- this.plugins.forEach(plugin => plugin.setBuilder(this));
102
+ this.plugins.forEach((plugin) => plugin.setBuilder(this));
96
103
  }
97
104
  async build() {
98
105
  await this.process();
@@ -104,7 +111,7 @@ class TSBuilder {
104
111
  const contract = getContract(contractOpt);
105
112
  //resolve contract schema.
106
113
  const contractInfo = await (0, utils_1.readSchemas)({
107
- schemaDir: contract.dir
114
+ schemaDir: contract.dir,
108
115
  });
109
116
  //lifecycle and plugins.
110
117
  await this.render('main', contract.name, contractInfo);
@@ -142,18 +149,13 @@ class TSBuilder {
142
149
  const bundlePath = (0, path_1.join)(this.options?.bundle?.bundlePath ?? this.outPath, bundleFile);
143
150
  const bundleVariables = {};
144
151
  const importPaths = [];
145
- allFiles.forEach(file => {
152
+ allFiles.forEach((file) => {
146
153
  (0, bundler_1.createFileBundle)(`${this.options.bundle.scope}.${file.contract}`, file.filename, bundlePath, importPaths, bundleVariables);
147
154
  });
148
155
  const ast = (0, bundler_1.recursiveModuleBundle)(bundleVariables);
149
- const nodes = [
150
- ...importPaths,
151
- ...ast
152
- ];
153
- // @ts-ignore
154
- let code = (0, generator_1.default)(t.program(
156
+ const nodes = [...importPaths, ...ast];
155
157
  // @ts-ignore
156
- nodes)).code;
158
+ let code = (0, generator_1.default)(t.program(nodes)).code;
157
159
  if (this.options?.bundle?.bundlePath) {
158
160
  (0, mkdirp_1.sync)(this.options?.bundle?.bundlePath);
159
161
  }
@@ -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
  };
@@ -31,20 +41,22 @@ const t = __importStar(require("@babel/types"));
31
41
  const nested_obj_1 = __importDefault(require("nested-obj"));
32
42
  const path_1 = require("path");
33
43
  const recursiveModuleBundle = (obj) => {
34
- return Object.keys(obj).map(key => {
44
+ return Object.keys(obj).map((key) => {
35
45
  const value = obj[key];
36
46
  if (typeof value === 'object' && value && value.__export) {
37
47
  // e.g. abci
38
48
  // 1. create variable for abci
39
49
  // 2. splat ALL _0, parms into abci
40
50
  // 3. export that variable
41
- const nmspc = t.variableDeclaration('const', [t.variableDeclarator(t.identifier(key), t.objectExpression(Object.keys(obj[key])
42
- .filter(a => a !== '__export')
43
- .filter(a => a.startsWith('_'))
44
- .map(a => t.spreadElement(t.identifier(a)))))]);
51
+ const nmspc = t.variableDeclaration('const', [
52
+ t.variableDeclarator(t.identifier(key), t.objectExpression(Object.keys(obj[key])
53
+ .filter((a) => a !== '__export')
54
+ .filter((a) => a.startsWith('_'))
55
+ .map((a) => t.spreadElement(t.identifier(a))))),
56
+ ]);
45
57
  const others = Object.keys(obj[key])
46
- .filter(a => a !== '__export')
47
- .filter(a => !a.startsWith('_'));
58
+ .filter((a) => a !== '__export')
59
+ .filter((a) => !a.startsWith('_'));
48
60
  if (others.length) {
49
61
  throw new Error('namespace and package not supported, yet.');
50
62
  }
@@ -62,9 +74,7 @@ const recursiveModuleBundle = (obj) => {
62
74
  });
63
75
  };
64
76
  exports.recursiveModuleBundle = recursiveModuleBundle;
65
- const importNamespace = (ident, path) => t.importDeclaration([
66
- t.importNamespaceSpecifier(t.identifier(ident))
67
- ], t.stringLiteral(path.replace((0, path_1.extname)(path), '')));
77
+ const importNamespace = (ident, path) => t.importDeclaration([t.importNamespaceSpecifier(t.identifier(ident))], t.stringLiteral(path.replace((0, path_1.extname)(path), '')));
68
78
  exports.importNamespace = importNamespace;
69
79
  let counter = 0;
70
80
  const createFileBundle = (pkg, filename, bundleFile, importPaths, bundleVariables) => {