@cosmwasm/ts-codegen 1.12.0 → 1.13.0
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.
- package/README.md +115 -121
- package/builder/builder.js +26 -24
- package/bundler/bundler.js +27 -17
- package/cli.js +2 -2
- package/commands/create-boilerplate.js +30 -19
- package/commands/generate.js +26 -35
- package/commands/install.js +22 -18
- package/esm/builder/builder.js +10 -18
- package/esm/bundler/bundler.js +10 -10
- package/esm/cli.js +2 -2
- package/esm/commands/create-boilerplate.js +12 -11
- package/esm/commands/generate.js +26 -35
- package/esm/commands/install.js +23 -19
- package/esm/file.js +4 -3
- package/esm/plugins/client.js +1 -1
- package/esm/plugins/message-builder.js +4 -4
- package/esm/plugins/message-composer.js +1 -1
- package/esm/plugins/plugin-base.js +3 -2
- package/esm/plugins/provider-bundle.js +1 -1
- package/esm/plugins/provider.js +1 -1
- package/esm/plugins/react-query.js +8 -7
- package/esm/plugins/recoil.js +4 -4
- package/esm/plugins/types.js +3 -3
- package/esm/ts-codegen.js +2 -1
- package/esm/utils/clean.js +1 -1
- package/esm/utils/cleanse.js +9 -5
- package/esm/utils/package.js +1 -1
- package/esm/utils/parse.js +5 -7
- package/esm/utils/prompt.js +2 -2
- package/esm/utils/schemas.js +32 -19
- package/esm/utils/unused.js +3 -4
- package/file.js +7 -3
- package/package.json +13 -13
- package/plugins/client.js +18 -8
- package/plugins/message-builder.js +20 -10
- package/plugins/message-composer.js +18 -8
- package/plugins/plugin-base.js +19 -8
- package/plugins/provider-bundle.js +17 -7
- package/plugins/provider.js +17 -7
- package/plugins/react-query.js +24 -13
- package/plugins/recoil.js +20 -10
- package/plugins/types.js +19 -9
- package/ts-codegen.js +5 -1
- package/utils/clean.js +1 -1
- package/utils/cleanse.d.ts +1 -0
- package/utils/cleanse.js +12 -7
- package/utils/files.js +17 -7
- package/utils/package.js +2 -3
- package/utils/parse.js +5 -7
- package/utils/prompt.js +2 -2
- package/utils/schemas.d.ts +5 -1
- package/utils/schemas.js +34 -20
- package/utils/unused.js +20 -11
package/README.md
CHANGED
@@ -7,22 +7,21 @@ 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/
|
11
|
-
<img height="20" src="https://github.com/
|
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
|
-
<a href="https://github.com/
|
14
|
-
<img height="20" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%
|
13
|
+
<a href="https://github.com/hyperweb-io/lib-count">
|
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"/>
|
15
15
|
</a>
|
16
|
-
<a href="https://github.com/
|
17
|
-
<img height="20" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%
|
16
|
+
<a href="https://github.com/hyperweb-io/lib-count">
|
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/
|
21
|
-
<a href="https://github.com/
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
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,93 @@ 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
|
62
|
+
import codegen from "@cosmwasm/ts-codegen";
|
63
63
|
|
64
64
|
codegen({
|
65
65
|
contracts: [
|
66
66
|
{
|
67
|
-
name:
|
68
|
-
dir:
|
67
|
+
name: "SG721",
|
68
|
+
dir: "./path/to/sg721/schema",
|
69
69
|
},
|
70
70
|
{
|
71
|
-
name:
|
72
|
-
dir:
|
73
|
-
}
|
71
|
+
name: "Minter",
|
72
|
+
dir: "./path/to/Minter/schema",
|
73
|
+
},
|
74
74
|
],
|
75
|
-
outPath:
|
75
|
+
outPath: "./path/to/code/src/",
|
76
76
|
|
77
77
|
// options are completely optional ;)
|
78
78
|
options: {
|
79
79
|
bundle: {
|
80
|
-
bundleFile:
|
81
|
-
scope:
|
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:
|
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(
|
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/
|
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 |
|
127
128
|
|
128
129
|
### Client
|
129
130
|
|
130
131
|
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
132
|
|
132
|
-
[see example output code](https://github.com/
|
133
|
+
[see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.client.ts)
|
133
134
|
|
134
135
|
#### Client Options
|
135
136
|
|
136
|
-
| option
|
137
|
-
|
|
138
|
-
| `client.enabled`
|
139
|
-
| `client.execExtendsQuery`
|
140
|
-
| `client.noImplicitOverride`
|
141
|
-
| `client.useDeclareKeyword`
|
142
|
-
|
137
|
+
| option | description |
|
138
|
+
| --------------------------- | ---------------------------------------------------- |
|
139
|
+
| `client.enabled` | generate TS client classes for your contracts |
|
140
|
+
| `client.execExtendsQuery` | execute should extend query message clients |
|
141
|
+
| `client.noImplicitOverride` | should match your tsconfig noImplicitOverride option |
|
142
|
+
| `client.useDeclareKeyword` | use declare keyword for inherited class fields |
|
143
143
|
|
144
144
|
### React Query
|
145
145
|
|
146
146
|
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
147
|
|
148
|
-
[see example output code](https://github.com/
|
148
|
+
[see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.react-query.ts)
|
149
149
|
|
150
150
|
#### React Query Options
|
151
151
|
|
@@ -159,72 +159,66 @@ Generate [react-query v3](https://react-query-v3.tanstack.com/) or [react-query
|
|
159
159
|
| `reactQuery.mutations` | also generate mutations |
|
160
160
|
| `reactQuery.camelize` | use camelCase style for property names |
|
161
161
|
|
162
|
-
|
163
162
|
### Recoil
|
164
163
|
|
165
164
|
Generate [recoil](https://recoiljs.org/) bindings for your contracts with the `recoil` command.
|
166
165
|
|
167
|
-
[see example output code](https://github.com/
|
166
|
+
[see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.recoil.ts)
|
168
167
|
|
169
168
|
#### Recoil Options
|
170
169
|
|
171
|
-
| option
|
172
|
-
|
|
173
|
-
| `recoil.enabled`
|
170
|
+
| option | description |
|
171
|
+
| ---------------- | ------------------------ |
|
172
|
+
| `recoil.enabled` | enable the recoil plugin |
|
174
173
|
|
175
174
|
### Message Composer
|
176
175
|
|
177
176
|
Generate pure message objects with the proper `utf8` encoding and `typeUrl` configured that you can broadcast yourself via `cosmjs` with the `message-composer` command.
|
178
177
|
|
179
|
-
[see example output code](https://github.com/
|
178
|
+
[see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.message-composer.ts)
|
180
179
|
|
181
180
|
#### Message Composer Options
|
182
181
|
|
183
|
-
| option
|
184
|
-
|
|
185
|
-
| `messageComposer.enabled`
|
182
|
+
| option | description |
|
183
|
+
| ------------------------- | --------------------------------- |
|
184
|
+
| `messageComposer.enabled` | enable the messageComposer plugin |
|
186
185
|
|
187
186
|
### Message Builder
|
188
187
|
|
189
188
|
Generate raw message jsons for use in your application with the `message-builder` command.
|
190
189
|
|
191
|
-
[see example output code](https://github.com/
|
190
|
+
[see example output code](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/sg721/Sg721.message-builder.ts)
|
192
191
|
|
193
192
|
#### Message Builder Options
|
194
193
|
|
195
|
-
| option | description
|
196
|
-
|
197
|
-
| `messageBuilder.enabled` | enable the messageBuilder plugin
|
198
|
-
|
194
|
+
| option | description |
|
195
|
+
| ------------------------ | -------------------------------- |
|
196
|
+
| `messageBuilder.enabled` | enable the messageBuilder plugin |
|
199
197
|
|
200
198
|
### `useContracts` Hook
|
201
199
|
|
202
200
|
Generates `useContracts` hook to easily access contracts, already equipped with a signing client
|
203
201
|
|
204
|
-
| option
|
205
|
-
|
|
206
|
-
| `useContractsHook.enabled`
|
202
|
+
| option | description |
|
203
|
+
| -------------------------- | -------------------------------- |
|
204
|
+
| `useContractsHook.enabled` | enable the `useContracts` plugin |
|
207
205
|
|
208
206
|
#### Example Output
|
209
207
|
|
210
|
-
- [Provider](https://github.com/
|
211
|
-
- [Contract Providers](https://github.com/
|
212
|
-
- [Contract Context](https://github.com/
|
213
|
-
- [Context Base](https://github.com/
|
208
|
+
- [Provider](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/Factory.provider.ts)
|
209
|
+
- [Contract Providers](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contractContextProviders.ts)
|
210
|
+
- [Contract Context](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contracts-context.tsx)
|
211
|
+
- [Context Base](https://github.com/hyperweb-io/ts-codegen/blob/main/__output__/builder/bundler_test/contracts/contractContextBase.ts)
|
214
212
|
|
215
213
|
#### Use Contracts Provider Usage
|
216
214
|
|
217
215
|
```tsx
|
218
|
-
import { useChain } from
|
219
|
-
import { ContractsProvider } from
|
216
|
+
import { useChain } from "@cosmos-kit/react";
|
217
|
+
import { ContractsProvider } from "../path/to/codegen/contracts-context";
|
220
218
|
|
221
219
|
export default function YourComponent() {
|
222
|
-
|
223
|
-
|
224
|
-
address,
|
225
|
-
getCosmWasmClient,
|
226
|
-
getSigningCosmWasmClient
|
227
|
-
} = useChain(chainName);
|
220
|
+
const { address, getCosmWasmClient, getSigningCosmWasmClient } =
|
221
|
+
useChain(chainName);
|
228
222
|
|
229
223
|
return (
|
230
224
|
<ContractsProvider
|
@@ -234,10 +228,10 @@ export default function YourComponent() {
|
|
234
228
|
getSigningCosmWasmClient,
|
235
229
|
}}
|
236
230
|
>
|
237
|
-
|
231
|
+
<SomeCoolComponent />
|
238
232
|
</ContractsProvider>
|
239
|
-
)
|
240
|
-
}
|
233
|
+
);
|
234
|
+
}
|
241
235
|
```
|
242
236
|
|
243
237
|
#### Use Contracts Provider Babel/TSC config
|
@@ -245,11 +239,7 @@ export default function YourComponent() {
|
|
245
239
|
If you're using Babel, please make sure include `'@babel/preset-react'` in devDeps and presets in `.babelrc.js`:
|
246
240
|
|
247
241
|
```js
|
248
|
-
|
249
|
-
'@babel/typescript',
|
250
|
-
'@babel/env',
|
251
|
-
'@babel/preset-react',
|
252
|
-
]
|
242
|
+
presets: ["@babel/typescript", "@babel/env", "@babel/preset-react"];
|
253
243
|
```
|
254
244
|
|
255
245
|
For `tsc`, you should set the `jsx` option to `'react'` in your `tsconfig.json`.
|
@@ -279,26 +269,24 @@ await marketplaceClient.updateAskPrice({
|
|
279
269
|
The bundler will make a nice package of all your contracts. For example:
|
280
270
|
|
281
271
|
```ts
|
282
|
-
const {
|
283
|
-
MinterQueryClient,
|
284
|
-
useMinterConfigQuery
|
285
|
-
} = contracts.Minter;
|
272
|
+
const { MinterQueryClient, useMinterConfigQuery } = contracts.Minter;
|
286
273
|
|
287
274
|
const { CwAdminFactoryClient } = contracts.CwAdminFactory;
|
288
275
|
```
|
276
|
+
|
289
277
|
#### Bundler Options
|
290
278
|
|
291
|
-
| option
|
292
|
-
|
|
293
|
-
| `bundle.enabled`
|
294
|
-
| `bundle.scope`
|
295
|
-
| `bundle.bundleFile`
|
279
|
+
| option | description |
|
280
|
+
| ------------------- | -------------------------------------------------------------------------------- |
|
281
|
+
| `bundle.enabled` | enable the bundler plugin |
|
282
|
+
| `bundle.scope` | name of the scope, defaults to `contracts` (you can use `.` to make more scopes) |
|
283
|
+
| `bundle.bundleFile` | name of the bundle file |
|
296
284
|
|
297
285
|
#### Coding Style
|
298
286
|
|
299
|
-
| option
|
300
|
-
|
|
301
|
-
| `useShorthandCtor`
|
287
|
+
| option | description | default |
|
288
|
+
| ------------------ | ----------------------------------- | ------- |
|
289
|
+
| `useShorthandCtor` | Enable using shorthand constructor. | true |
|
302
290
|
|
303
291
|
Using shorthand constructor (Might not be transpiled correctly with babel):
|
304
292
|
|
@@ -358,7 +346,7 @@ npm install @cosmwasm/ts-codegen
|
|
358
346
|
Clone your project and `cd` into your contracts folder
|
359
347
|
|
360
348
|
```sh
|
361
|
-
git clone https://github.com/
|
349
|
+
git clone https://github.com/hyperweb-io/launchpad.git
|
362
350
|
cd launchpad/contracts/whitelists/whitelist
|
363
351
|
```
|
364
352
|
|
@@ -386,9 +374,10 @@ cosmwasm-ts-codegen generate
|
|
386
374
|
◯ recoil
|
387
375
|
◯ react-query
|
388
376
|
◯ message-composer
|
389
|
-
|
377
|
+
```
|
390
378
|
|
391
379
|
In this example, you can press space bar to select a number of plugins you wish you enable.
|
380
|
+
|
392
381
|
#### Specifying Plugins
|
393
382
|
|
394
383
|
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 +388,7 @@ ts-codegen generate \
|
|
399
388
|
--schema ./schema \
|
400
389
|
--out ./ts \
|
401
390
|
--name MyContractName
|
402
|
-
|
391
|
+
```
|
403
392
|
|
404
393
|
You can specify multiple `--plugin` options using the `generate` command:
|
405
394
|
|
@@ -465,7 +454,6 @@ ts-codegen generate \
|
|
465
454
|
--name MyContractName
|
466
455
|
```
|
467
456
|
|
468
|
-
|
469
457
|
#### React Query via CLI
|
470
458
|
|
471
459
|
Here is an example without optional client, using v3 for `react-query`, without mutations:
|
@@ -528,6 +516,7 @@ ts-codegen generate \
|
|
528
516
|
### JSON Schema
|
529
517
|
|
530
518
|
We generate code from the [JSON Schema](https://json-schema.org/) exported from CosmWasm smart contracts.
|
519
|
+
|
531
520
|
### JSON Schema Generation
|
532
521
|
|
533
522
|
Currently you have to have the JSON Schema output. Here is an example to start.
|
@@ -546,7 +535,9 @@ now build the schema with `cargo schema`
|
|
546
535
|
cd contracts/sg721/
|
547
536
|
cargo schema
|
548
537
|
```
|
538
|
+
|
549
539
|
### Exporting Schemas
|
540
|
+
|
550
541
|
#### `cosmwasm v1.1` Example
|
551
542
|
|
552
543
|
Using the new `write_api` method, you can export schemas:
|
@@ -608,24 +599,27 @@ yarn test:watch
|
|
608
599
|
|
609
600
|
### Working with ASTs
|
610
601
|
|
611
|
-
See the [docs](https://github.com/
|
602
|
+
See the [docs](https://github.com/hyperweb-io/ts-codegen/blob/main/packages/ast/README.md) in the `@cosmwasm/ts-codegen-ast` package.
|
612
603
|
|
613
|
-
##
|
604
|
+
## Interchain JavaScript Stack
|
614
605
|
|
615
|
-
|
606
|
+
A unified toolkit for building applications and smart contracts in the Interchain ecosystem ⚛️
|
616
607
|
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
608
|
+
| Category | Tools | Description |
|
609
|
+
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
610
|
+
| **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. |
|
611
|
+
| **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. |
|
612
|
+
| **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 |
|
613
|
+
| **SDK Clients** | [**Telescope**](https://github.com/hyperweb-io/telescope) | Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules. |
|
614
|
+
| **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. |
|
615
|
+
| **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. |
|
616
|
+
| **Testing Frameworks** | [**Starship**](https://github.com/hyperweb-io/starship) | Unified Testing and Development for the Interchain. |
|
617
|
+
| **TypeScript Smart Contracts** | [**Create Hyperweb App**](https://github.com/hyperweb-io/create-hyperweb-app) | Build and deploy full-stack blockchain applications with TypeScript |
|
618
|
+
| **CosmWasm Contracts** | [**CosmWasm TS Codegen**](https://github.com/hyperweb-io/ts-codegen) | Convert your CosmWasm smart contracts into dev-friendly TypeScript classes. |
|
624
619
|
|
625
620
|
## Credits
|
626
621
|
|
627
|
-
🛠 Built by Cosmology — if you like our tools, please
|
628
|
-
|
622
|
+
🛠 Built by Hyperweb (formerly Cosmology) — if you like our tools, please checkout and contribute to [our github ⚛️](https://github.com/hyperweb-io)
|
629
623
|
|
630
624
|
## Disclaimer
|
631
625
|
|
package/builder/builder.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 (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
}
|
package/bundler/bundler.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 (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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', [
|
42
|
-
|
43
|
-
.filter(a => a
|
44
|
-
.
|
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) => {
|
package/cli.js
CHANGED
@@ -9,8 +9,8 @@ const question = [
|
|
9
9
|
type: 'fuzzy',
|
10
10
|
name: 'cmd',
|
11
11
|
message: 'what do you want to do?',
|
12
|
-
choices: Object.keys(cmds_1.Commands)
|
13
|
-
}
|
12
|
+
choices: Object.keys(cmds_1.Commands),
|
13
|
+
},
|
14
14
|
];
|
15
15
|
const cli = async (argv) => {
|
16
16
|
let { cmd } = await (0, prompt_1.prompt)(question, argv);
|