@cosmwasm/ts-codegen 0.7.0 → 0.7.3

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 CHANGED
@@ -21,36 +21,163 @@ npm install -g @cosmwasm/ts-codegen
21
21
 
22
22
  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.
23
23
 
24
+ ## Table of contents
25
+
26
+ - [@cosmwasm/ts-codegen](#cosmwasmts-codegen)
27
+ - [Table of contents](#table-of-contents)
28
+ - [QuickStart](#quickstart)
29
+ - [Usage](#usage)
30
+ - [Generate TS Clients](#generate)
31
+ - [React Query](#react-query)
32
+ - [Recoil](#recoil)
33
+ - [Message Composer](#message-composer)
34
+ - [Example Output](#example-output)
35
+ - [JSON Schema](#json-schema)
36
+ - [JSON Schema Generation](#json-schema-generation)
37
+ - [Exporting Schemas](#exporting-schemas)
38
+ - [Developing](#developing)
39
+ - [Related](#related)
40
+ ### Quickstart
41
+
42
+ Clone your project and `cd` into your contracts folder
43
+
44
+ ```sh
45
+ git clone git@github.com:public-awesome/stargaze-contracts.git
46
+ cd stargaze-contracts/contracts/sg721/
47
+ ```
48
+
49
+ Run `cosmwasm-ts-codegen` to generate your code.
50
+
51
+ ```sh
52
+ cosmwasm-ts-codegen generate --schema ./schema --out ./ts --name SG721
53
+ ```
54
+
55
+ The output will be in the folder specified by `--out`, enjoy!
56
+
24
57
  ## usage
25
58
 
59
+ Get started quickly using our `cli` by globally installing via npm:
60
+
61
+ ```
62
+ npm install -g @cosmwasm/ts-codegen
26
63
  ```
27
- cosmwasm-ts-codegen generate \
64
+ ### generate
65
+
66
+ Generate a basic TS client for your contracts. The `generate` command will make types which will be essential for your bindings.
67
+
68
+ This command also generates a `QueryClient` for queries as well as a `Client` for queries and mutations.
69
+
70
+ [see example output code](https://gist.github.com/pyramation/ba67ec56e4e2a39cadea55430f9993e5)
71
+
72
+
73
+ ```sh
74
+ cosmwasm-ts-codegen generate \
28
75
  --schema ./schema \
29
- --out ./src \
76
+ --out ./ts \
30
77
  --name MyContractName
31
78
  ```
32
79
 
33
- ### example
80
+ for programmatic usage, you can use the `tsClient` function:
34
81
 
82
+ ```ts
83
+ import { tsClient } from '@cosmwasm/ts-codegen';
84
+ declare const tsClient = (name: string, schemas: any[], outPath: string) => Promise<void>;
35
85
  ```
36
- git clone git@github.com:public-awesome/stargaze-contracts.git
37
- cd stargaze-contracts/contracts/sg721/
38
- cosmwasm-ts-codegen generate --schema ./schema --out ./ts --name SG721
86
+
87
+ ### react query
88
+
89
+ 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.
90
+
91
+ [see example output code](https://gist.github.com/pyramation/a3bf4aa7b60a31287d0720ca1bb5473b)
92
+
93
+
94
+ Example without optional client, using v3, without mutations:
95
+
96
+ ```sh
97
+ cosmwasm-ts-codegen react-query \
98
+ --schema ./schema \
99
+ --out ./ts \
100
+ --name MyContractName \
101
+ --no-optionalClient \
102
+ --no-v4 \
103
+ --no-mutations
39
104
  ```
40
105
 
41
- ### JSON Schema Generation
106
+ Example with optional client, using v4, with mutations:
107
+
108
+ ```sh
109
+ cosmwasm-ts-codegen react-query \
110
+ --schema ./schema \
111
+ --out ./ts \
112
+ --name MyContractName \
113
+ --optionalClient \
114
+ --v4 \
115
+ --mutations
116
+ ```
117
+
118
+ For programmatic usage, you can use the `reactQuery` function:
119
+
120
+ ```ts
121
+ import { reactQuery } from '@cosmwasm/ts-codegen';
122
+ declare const reactQuery = (
123
+ contractName: string,
124
+ schemas: any[],
125
+ outPath: string,
126
+ reactQueryOptions?: ReactQueryOptions
127
+ ) => Promise<void>;
128
+ ```
129
+
130
+ #### React Query Options
131
+
132
+ | option | description |
133
+ | ------------------------------ | ------------------------------------------------------------------- |
134
+ | `reactQuery.optionalClient` | allows contract client to be undefined as the component renders |
135
+ | `reactQuery.v4` | uses `@tanstack/react-query` and syntax instead of v3 `react-query` |
136
+ | `reactQuery.mutations` | also generate mutations |
137
+ | `reactQuery.camelize` | use camelCase style for property names |
138
+
139
+ ### recoil
140
+
141
+ Generate [recoil](https://recoiljs.org/) bindings for your contracts with the `recoil` command.
142
+
143
+ [see example output code](https://gist.github.com/pyramation/48b28a75def1a16b233b369297f05f0e)
42
144
 
43
- Currently you have to have the JSON Schema output. Here is an example to start:
44
145
 
45
146
  ```sh
46
- ## get the Rust contracts
47
- git clone git@github.com:public-awesome/stargaze-contracts.git
48
- cd stargaze-contracts
49
- cargo build
147
+ cosmwasm-ts-codegen recoil \
148
+ --schema ./schema \
149
+ --out ./ts \
150
+ --name MyContractName
151
+ ```
50
152
 
51
- ## now build the schema
52
- cd contracts/sg721/
53
- cargo schema
153
+ for programmatic usage, you can use the `recoil` function:
154
+
155
+ ```ts
156
+ import { recoil } from '@cosmwasm/ts-codegen';
157
+ declare const recoil = (
158
+ name: string,
159
+ schemas: any[],
160
+ outPath: string
161
+ ) => Promise<void>;
162
+ ```
163
+ ### Message Composer
164
+
165
+ Generate pure message objects with the proper `utf8` encoding and `typeUrl` configured that you can broadcast yourself via `cosmjs` with the `from-partial` command.
166
+
167
+ [see example output code](https://gist.github.com/pyramation/f50869d1ecdb6d6ced2bc0a44c6ff492)
168
+
169
+ ```sh
170
+ cosmwasm-ts-codegen from-partial \
171
+ --schema ./schema \
172
+ --out ./ts \
173
+ --name MyContractName
174
+ ```
175
+
176
+ for programmatic usage, you can use the `fromPartial` function:
177
+
178
+ ```ts
179
+ import { fromPartial } from '@cosmwasm/ts-codegen';
180
+ declare const fromPartial = (name: string, schemas: any[], outPath: string) => Promise<void>;
54
181
  ```
55
182
 
56
183
  ### Example Output
@@ -72,8 +199,28 @@ https://gist.github.com/pyramation/a3bf4aa7b60a31287d0720ca1bb5473b
72
199
  https://gist.github.com/pyramation/48b28a75def1a16b233b369297f05f0e
73
200
 
74
201
 
75
- ### Exporting Schemas
202
+ ### JSON Schema
203
+
204
+ We generate code from the [JSON Schema](https://json-schema.org/) exported from CosmWasm smart contracts.
205
+ ### JSON Schema Generation
206
+
207
+ Currently you have to have the JSON Schema output. Here is an example to start.
208
+
209
+ First, get the Rust contracts and run `cargo build`:
210
+
211
+ ```sh
212
+ git clone git@github.com:public-awesome/stargaze-contracts.git
213
+ cd stargaze-contracts
214
+ cargo build
215
+ ```
216
+
217
+ now build the schema with `cargo schema`
76
218
 
219
+ ```sh
220
+ cd contracts/sg721/
221
+ cargo schema
222
+ ```
223
+ ### Exporting Schemas
77
224
  #### `cosmwasm_std` Examples
78
225
 
79
226
  ```rs
@@ -87,4 +234,38 @@ export_schema_with_title(
87
234
  &out_dir,
88
235
  "CosmosMsg_for_Empty",
89
236
  );
90
- ```
237
+ ```
238
+
239
+ ## Developing
240
+
241
+ ### Initial setup
242
+
243
+ ```
244
+ yarn
245
+ yarn bootstrap
246
+ ```
247
+
248
+ ### Building
249
+
250
+ ```
251
+ yarn build
252
+ ```
253
+
254
+ ### Tests
255
+
256
+ Then `cd` into a package and run the tests
257
+
258
+ ```
259
+ cd ./packages/wasm-ast-types
260
+ yarn test:watch
261
+ ```
262
+
263
+ ### Working with ASTs
264
+
265
+ See the [docs](https://github.com/CosmWasm/ts-codegen/blob/main/packages/wasm-ast-types/README.md) in the `wasm-ast-types` package.
266
+
267
+ ## Related
268
+
269
+ Checkout these related projects:
270
+
271
+ * [@osmonauts/telescope](https://github.com/osmosis-labs/telescope) a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.
@@ -13,7 +13,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
13
13
 
14
14
  var _prompt = require("../utils/prompt");
15
15
 
16
- var _recoil = _interopRequireDefault(require("../recoil"));
16
+ var _recoil = _interopRequireDefault(require("../generators/recoil"));
17
17
 
18
18
  var _utils = require("../utils");
19
19
 
@@ -1,5 +1,5 @@
1
1
  import { prompt } from '../utils/prompt';
2
- import recoil from '../recoil';
2
+ import recoil from '../generators/recoil';
3
3
  import { readSchemas } from '../utils';
4
4
  export default (async argv => {
5
5
  const questions = [{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "0.7.0",
3
+ "version": "0.7.3",
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
6
  "homepage": "https://github.com/cosmwasm/ts-codegen",
@@ -90,7 +90,7 @@
90
90
  "minimist": "1.2.6",
91
91
  "mkdirp": "1.0.4",
92
92
  "shelljs": "0.8.5",
93
- "wasm-ast-types": "^0.6.0"
93
+ "wasm-ast-types": "^0.6.1"
94
94
  },
95
- "gitHead": "51e6e530adc95d8118606379848080dd9bc3c25a"
95
+ "gitHead": "6a9da6ddd47a5c9cebebf5fb05f5c1edea2868e2"
96
96
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: (contractName: string, schemas: any[], outPath: string, reactQueryOptions?: ReactQueryOptions) => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
2
+ export default _default;
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { default as generate } from './generate';
2
- export { default as fromPartial } from './from-partial';
3
- export { default as reactQuery } from './react-query';
4
- export { default as recoil } from './recoil';
1
+ export { default as tsClient } from './generators/ts-client';
2
+ export { default as fromPartial } from './generators/from-partial';
3
+ export { default as reactQuery } from './generators/react-query';
4
+ export { default as recoil } from './generators/recoil';
5
5
  export * from './utils';
6
- export * from './imports';
6
+ export * from './utils/imports';
@@ -0,0 +1 @@
1
+ export declare const clean: (obj: any) => any;
@@ -0,0 +1 @@
1
+ export declare const cleanse: (obj: any) => any;
@@ -0,0 +1 @@
1
+ export declare const header: string;
@@ -0,0 +1 @@
1
+ export declare const cosmjsAminoImportStatements: (typeHash: any) => any;
@@ -0,0 +1 @@
1
+ export * from './schemas';
@@ -0,0 +1 @@
1
+ export declare const parser: (codes: any) => {};
@@ -0,0 +1,3 @@
1
+ export function getFuzzySearch(list: any): (answers: any, input: any) => Promise<any>;
2
+ export function getFuzzySearchNames(nameValueItemList: any): (answers: any, input: any) => Promise<any>;
3
+ export function prompt(questions?: any[], argv?: {}): Promise<any>;
@@ -0,0 +1,10 @@
1
+ import { JSONSchema } from 'wasm-ast-types';
2
+ export declare const readSchemas: ({ schemaDir, argv, clean }: {
3
+ schemaDir: any;
4
+ argv: any;
5
+ clean?: boolean;
6
+ }) => Promise<any>;
7
+ export declare const findQueryMsg: (schemas: any) => any;
8
+ export declare const findExecuteMsg: (schemas: any) => any;
9
+ export declare const findAndParseTypes: (schemas: any) => Promise<{}>;
10
+ export declare const getDefinitionSchema: (schemas: JSONSchema[]) => JSONSchema;