@cosmwasm/ts-codegen 0.34.2 → 0.35.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.
- package/README.md +83 -20
- package/main/builder/builder.js +145 -247
- package/main/builder/index.js +0 -2
- package/main/bundler/bundler.js +3 -16
- package/main/bundler/index.js +0 -2
- package/main/cli.js +20 -38
- package/main/cmds.js +0 -5
- package/main/commands/create-boilerplate.js +132 -160
- package/main/commands/generate.js +168 -192
- package/main/commands/install.js +89 -123
- package/main/file.js +13 -25
- package/main/generators/client.js +55 -81
- package/main/generators/create-helpers.js +0 -14
- package/main/generators/message-composer.js +42 -68
- package/main/generators/msg-builder.js +49 -78
- package/main/generators/react-query.js +68 -92
- package/main/generators/recoil.js +47 -71
- package/main/generators/types.js +45 -73
- package/main/helpers/index.js +0 -6
- package/main/index.js +8 -30
- package/main/plugins/client.js +56 -90
- package/main/plugins/index.js +0 -2
- package/main/plugins/{msg-builder.js → message-builder.js} +56 -93
- package/main/plugins/message-composer.js +42 -76
- package/main/plugins/plugin-base.js +40 -70
- package/main/plugins/provider-bundle.js +42 -81
- package/main/plugins/provider.js +58 -103
- package/main/plugins/react-query.js +67 -99
- package/main/plugins/recoil.js +45 -82
- package/main/plugins/types.js +34 -68
- package/main/ts-codegen.js +7 -15
- package/main/utils/clean.js +8 -17
- package/main/utils/cleanse.js +10 -25
- package/main/utils/files.js +2 -22
- package/main/utils/header.js +0 -3
- package/main/utils/index.js +0 -2
- package/main/utils/parse.js +2 -7
- package/main/utils/prompt.js +16 -36
- package/main/utils/schemas.js +86 -133
- package/main/utils/unused.js +4 -15
- package/module/builder/builder.js +12 -33
- package/module/bundler/bundler.js +3 -3
- package/module/cli.js +0 -1
- package/module/commands/create-boilerplate.js +6 -19
- package/module/commands/generate.js +14 -19
- package/module/commands/install.js +14 -17
- package/module/file.js +0 -3
- package/module/generators/client.js +6 -7
- package/module/generators/create-helpers.js +0 -4
- package/module/generators/message-composer.js +4 -5
- package/module/generators/msg-builder.js +10 -14
- package/module/generators/react-query.js +8 -9
- package/module/generators/recoil.js +2 -3
- package/module/generators/types.js +4 -6
- package/module/plugins/client.js +4 -10
- package/module/plugins/{msg-builder.js → message-builder.js} +10 -18
- package/module/plugins/message-composer.js +4 -10
- package/module/plugins/plugin-base.js +10 -10
- package/module/plugins/provider-bundle.js +0 -10
- package/module/plugins/provider.js +0 -14
- package/module/plugins/react-query.js +8 -13
- package/module/plugins/recoil.js +2 -9
- package/module/plugins/types.js +4 -7
- package/module/ts-codegen.js +0 -2
- package/module/utils/clean.js +8 -13
- package/module/utils/cleanse.js +10 -21
- package/module/utils/files.js +2 -6
- package/module/utils/parse.js +2 -4
- package/module/utils/prompt.js +0 -5
- package/module/utils/schemas.js +2 -13
- package/module/utils/unused.js +4 -6
- package/package.json +3 -3
- package/src/builder/builder.ts +7 -6
- package/src/commands/generate.ts +14 -13
- package/src/generators/msg-builder.ts +7 -9
- package/src/plugins/{msg-builder.ts → message-builder.ts} +6 -6
- package/src/plugins/message-composer.ts +2 -2
- package/types/src/builder/builder.d.ts +3 -2
- package/types/src/generators/msg-builder.d.ts +2 -2
- package/types/src/generators/msg-builder.ts +2 -2
- package/types/src/plugins/message-builder.d.ts +12 -0
- package/types/src/plugins/msg-builder.d.ts +1 -1
package/README.md
CHANGED
@@ -47,7 +47,7 @@ The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-
|
|
47
47
|
- [Exporting Schemas](#exporting-schemas)
|
48
48
|
- [Developing](#developing)
|
49
49
|
- [Related](#related)
|
50
|
-
## Quickstart
|
50
|
+
## Quickstart
|
51
51
|
|
52
52
|
Clone your project and `cd` into your contracts folder
|
53
53
|
|
@@ -122,7 +122,7 @@ codegen({
|
|
122
122
|
messageComposer: {
|
123
123
|
enabled: false
|
124
124
|
},
|
125
|
-
|
125
|
+
messageBuilder: {
|
126
126
|
enabled: false
|
127
127
|
},
|
128
128
|
useContractsHooks: {
|
@@ -133,7 +133,7 @@ codegen({
|
|
133
133
|
console.log('✨ all done!');
|
134
134
|
});
|
135
135
|
```
|
136
|
-
#### Types
|
136
|
+
#### Types
|
137
137
|
|
138
138
|
Typescript types and interfaces are generated in separate files so they can be imported into various generated plugins.
|
139
139
|
|
@@ -149,7 +149,7 @@ Typescript types and interfaces are generated in separate files so they can be i
|
|
149
149
|
|
150
150
|
### Client
|
151
151
|
|
152
|
-
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.
|
152
|
+
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.
|
153
153
|
|
154
154
|
[see example output code](https://gist.github.com/pyramation/30508678b7563e286f06ccc5ac384817)
|
155
155
|
|
@@ -189,7 +189,7 @@ Generate [react-query v3](https://react-query-v3.tanstack.com/) or [react-query
|
|
189
189
|
| `reactQuery.camelize` | use camelCase style for property names |
|
190
190
|
|
191
191
|
|
192
|
-
#### React Query via CLI
|
192
|
+
#### React Query via CLI
|
193
193
|
|
194
194
|
Here is an example without optional client, using v3 for `react-query`, without mutations:
|
195
195
|
|
@@ -231,7 +231,7 @@ cosmwasm-ts-codegen generate \
|
|
231
231
|
--plugin recoil \
|
232
232
|
--schema ./schema \
|
233
233
|
--out ./ts \
|
234
|
-
--name MyContractName
|
234
|
+
--name MyContractName
|
235
235
|
```
|
236
236
|
|
237
237
|
#### Recoil Options
|
@@ -253,7 +253,7 @@ cosmwasm-ts-codegen generate \
|
|
253
253
|
--plugin message-composer \
|
254
254
|
--schema ./schema \
|
255
255
|
--out ./ts \
|
256
|
-
--name MyContractName
|
256
|
+
--name MyContractName
|
257
257
|
```
|
258
258
|
#### Message Composer Options
|
259
259
|
|
@@ -263,7 +263,7 @@ cosmwasm-ts-codegen generate \
|
|
263
263
|
|
264
264
|
### Message Builder
|
265
265
|
|
266
|
-
Generate raw message jsons for use in your application with the `
|
266
|
+
Generate raw message jsons for use in your application with the `message-builder` command.
|
267
267
|
|
268
268
|
[see example output code](https://gist.github.com/adairrr/b394e62beb9856b0351883f776650f26)
|
269
269
|
|
@@ -271,16 +271,16 @@ Generate raw message jsons for use in your application with the `msg-builder` co
|
|
271
271
|
|
272
272
|
```sh
|
273
273
|
cosmwasm-ts-codegen generate \
|
274
|
-
--plugin
|
274
|
+
--plugin message-builder \
|
275
275
|
--schema ./schema \
|
276
276
|
--out ./ts \
|
277
|
-
--name MyContractName
|
277
|
+
--name MyContractName
|
278
278
|
```
|
279
279
|
#### Message Builder Options
|
280
280
|
|
281
|
-
| option
|
282
|
-
|
283
|
-
| `
|
281
|
+
| option | description |
|
282
|
+
|------------------------- | ---------------------------------- |
|
283
|
+
| `messageBuilder.enabled` | enable the messageBuilder plugin |
|
284
284
|
|
285
285
|
|
286
286
|
### Use Contracts Hooks
|
@@ -296,8 +296,8 @@ import { useChain } from '@cosmos-kit/react';
|
|
296
296
|
import { ContractsProvider } from '../path/to/codegen/contracts-context';
|
297
297
|
|
298
298
|
export default function YourComponent() {
|
299
|
-
|
300
|
-
const {
|
299
|
+
|
300
|
+
const {
|
301
301
|
address,
|
302
302
|
getCosmWasmClient,
|
303
303
|
getSigningCosmWasmClient
|
@@ -317,6 +317,16 @@ export default function YourComponent() {
|
|
317
317
|
};
|
318
318
|
```
|
319
319
|
|
320
|
+
If you're using Babel, please make sure include '@babel/preset-react' in devDeps and presets in .babelrc.js:
|
321
|
+
|
322
|
+
```js
|
323
|
+
presets: [
|
324
|
+
'@babel/typescript',
|
325
|
+
'@babel/env',
|
326
|
+
'@babel/preset-react',
|
327
|
+
]
|
328
|
+
```
|
329
|
+
|
320
330
|
#### Use Contracts Hooks Usage
|
321
331
|
|
322
332
|
Once enabled, you can get contracts very simply:
|
@@ -357,11 +367,64 @@ const { CwAdminFactoryClient } = contracts.CwAdminFactory;
|
|
357
367
|
| `bundle.scope` | name of the scope, defaults to `contracts` (you can use `.` to make more scopes) |
|
358
368
|
| `bundle.bundleFile` | name of the bundle file |
|
359
369
|
|
370
|
+
#### Coding Style
|
371
|
+
|
372
|
+
| option | description | default |
|
373
|
+
| --------------------- | ---------------------------------------------- |
|
374
|
+
| `useShorthandCtor` | Enable using shorthand constructor. | true |
|
375
|
+
|
376
|
+
Using shorthand constructor (Might not be transpiled correctly with babel):
|
377
|
+
|
378
|
+
```ts
|
379
|
+
constructor(
|
380
|
+
protected address: string | undefined,
|
381
|
+
protected cosmWasmClient: CosmWasmClient | undefined,
|
382
|
+
protected signingCosmWasmClient: SigningCosmWasmClient | undefined,
|
383
|
+
private TSign?: new (
|
384
|
+
client: SigningCosmWasmClient,
|
385
|
+
sender: string,
|
386
|
+
contractAddress: string
|
387
|
+
) => TSign,
|
388
|
+
private TQuery?: new (
|
389
|
+
client: CosmWasmClient,
|
390
|
+
contractAddress: string
|
391
|
+
) => TQuery,
|
392
|
+
private TMsgComposer?: new (
|
393
|
+
sender: string,
|
394
|
+
contractAddress: string
|
395
|
+
) => TMsgComposer
|
396
|
+
) {}
|
397
|
+
```
|
398
|
+
|
399
|
+
Without using shorthand constructor:
|
400
|
+
|
401
|
+
```ts
|
402
|
+
address: string | undefined;
|
403
|
+
...
|
404
|
+
TMsgComposer?: new (
|
405
|
+
sender: string,
|
406
|
+
contractAddress: string
|
407
|
+
) => TMsgComposer;
|
408
|
+
|
409
|
+
constructor(
|
410
|
+
address: string | undefined,
|
411
|
+
...
|
412
|
+
TMsgComposer?: new (
|
413
|
+
sender: string,
|
414
|
+
contractAddress: string
|
415
|
+
) => TMsgComposer
|
416
|
+
) {
|
417
|
+
this.address = address;
|
418
|
+
...
|
419
|
+
this.TMsgComposer = TMsgComposer;
|
420
|
+
}
|
421
|
+
```
|
422
|
+
|
360
423
|
### CLI Usage and Examples
|
361
424
|
|
362
425
|
#### Interactive prompt
|
363
426
|
|
364
|
-
The CLI is interactive, and if you don't specify an option, it will interactively prompt you.
|
427
|
+
The CLI is interactive, and if you don't specify an option, it will interactively prompt you.
|
365
428
|
|
366
429
|
```sh
|
367
430
|
cosmwasm-ts-codegen generate
|
@@ -444,12 +507,12 @@ cosmwasm-ts-codegen generate \
|
|
444
507
|
for lower-level access, you can import the various plugins directly:
|
445
508
|
|
446
509
|
```ts
|
447
|
-
import {
|
510
|
+
import {
|
448
511
|
generateTypes,
|
449
512
|
generateClient,
|
450
513
|
generateReactQuery,
|
451
514
|
generateRecoil,
|
452
|
-
generateMessageComposer
|
515
|
+
generateMessageComposer
|
453
516
|
} from '@cosmwasm/ts-codegen';
|
454
517
|
```
|
455
518
|
### Example Output
|
@@ -474,7 +537,7 @@ https://gist.github.com/pyramation/a9520ccf131177b1841e02a97d7d3731
|
|
474
537
|
|
475
538
|
https://gist.github.com/pyramation/43320e8b952751a0bd5a77dbc5b601f4
|
476
539
|
|
477
|
-
- `cosmwasm-ts-codegen generate --plugin
|
540
|
+
- `cosmwasm-ts-codegen generate --plugin message-builder`
|
478
541
|
|
479
542
|
https://gist.github.com/adairrr/b394e62beb9856b0351883f776650f26
|
480
543
|
|
@@ -541,7 +604,7 @@ export_schema_with_title(
|
|
541
604
|
### Initial setup
|
542
605
|
|
543
606
|
```
|
544
|
-
yarn
|
607
|
+
yarn
|
545
608
|
yarn bootstrap
|
546
609
|
```
|
547
610
|
|