@cosmwasm/ts-codegen 0.6.1 → 0.7.2
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 +198 -17
- package/main/cli.js +1 -1
- package/main/cmds.js +0 -3
- package/main/commands/from-partial.js +9 -5
- package/main/commands/generate.js +10 -6
- package/main/commands/react-query.js +9 -5
- package/main/commands/recoil.js +9 -5
- package/main/file.js +1 -1
- package/main/{from-partial.js → generators/from-partial.js} +8 -7
- package/main/{react-query.js → generators/react-query.js} +16 -12
- package/main/{recoil.js → generators/recoil.js} +8 -7
- package/main/{generate.js → generators/ts-client.js} +12 -11
- package/main/index.js +12 -12
- package/main/{clean.js → utils/clean.js} +0 -0
- package/main/{cleanse.js → utils/cleanse.js} +0 -0
- package/main/{header.js → utils/header.js} +1 -1
- package/main/{imports.js → utils/imports.js} +0 -0
- package/main/utils/index.js +18 -0
- package/main/{parse.js → utils/parse.js} +0 -0
- package/main/{prompt.js → utils/prompt.js} +0 -0
- package/main/utils/schemas.js +167 -0
- package/module/cli.js +1 -1
- package/module/cmds.js +0 -2
- package/module/commands/from-partial.js +3 -3
- package/module/commands/generate.js +4 -4
- package/module/commands/react-query.js +3 -3
- package/module/commands/recoil.js +3 -3
- package/module/file.js +1 -1
- package/module/{from-partial.js → generators/from-partial.js} +7 -5
- package/module/{react-query.js → generators/react-query.js} +13 -8
- package/module/{recoil.js → generators/recoil.js} +7 -5
- package/module/{generate.js → generators/ts-client.js} +11 -9
- package/module/index.js +5 -5
- package/module/{clean.js → utils/clean.js} +0 -0
- package/module/{cleanse.js → utils/cleanse.js} +0 -0
- package/module/{header.js → utils/header.js} +1 -1
- package/module/{imports.js → utils/imports.js} +0 -0
- package/module/utils/index.js +1 -0
- package/module/{parse.js → utils/parse.js} +0 -0
- package/module/{prompt.js → utils/prompt.js} +0 -0
- package/module/{utils.js → utils/schemas.js} +18 -1
- package/package.json +4 -4
- package/types/cleanse.d.ts +1 -0
- package/types/generators/from-partial.d.ts +2 -0
- package/types/generators/react-query.d.ts +2 -0
- package/types/generators/recoil.d.ts +2 -0
- package/types/generators/ts-client.d.ts +2 -0
- package/types/imports.d.ts +1 -0
- package/types/index.d.ts +5 -5
- package/types/react-query.d.ts +1 -1
- package/types/ts-codegen.d.ts +2 -0
- package/types/utils/clean.d.ts +1 -0
- package/types/utils/cleanse.d.ts +1 -0
- package/types/utils/header.d.ts +1 -0
- package/types/utils/imports.d.ts +1 -0
- package/types/utils/index.d.ts +1 -0
- package/types/utils/parse.d.ts +1 -0
- package/types/utils/prompt.d.ts +3 -0
- package/types/utils/schemas.d.ts +10 -0
- package/types/utils.d.ts +8 -2
- package/main/commands/boilerplate.js +0 -195
- package/main/utils.js +0 -123
- package/module/commands/boilerplate.js +0 -116
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
|
+
- [From Partial](#from-partial)
|
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
|
-
|
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 ./
|
76
|
+
--out ./ts \
|
30
77
|
--name MyContractName
|
31
78
|
```
|
32
79
|
|
33
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
147
|
+
cosmwasm-ts-codegen recoil \
|
148
|
+
--schema ./schema \
|
149
|
+
--out ./ts \
|
150
|
+
--name MyContractName
|
151
|
+
```
|
50
152
|
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
+
### from-partial
|
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
|
-
###
|
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.
|
package/main/cli.js
CHANGED
@@ -11,7 +11,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
11
11
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
13
13
|
|
14
|
-
var _prompt = require("./prompt");
|
14
|
+
var _prompt = require("./utils/prompt");
|
15
15
|
|
16
16
|
var _cmds = require("./cmds");
|
17
17
|
|
package/main/cmds.js
CHANGED
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.Commands = void 0;
|
9
9
|
|
10
|
-
var _boilerplate2 = _interopRequireDefault(require("./commands/boilerplate"));
|
11
|
-
|
12
10
|
var _fromPartial = _interopRequireDefault(require("./commands/from-partial"));
|
13
11
|
|
14
12
|
var _generate2 = _interopRequireDefault(require("./commands/generate"));
|
@@ -19,7 +17,6 @@ var _recoil2 = _interopRequireDefault(require("./commands/recoil"));
|
|
19
17
|
|
20
18
|
var Commands = {};
|
21
19
|
exports.Commands = Commands;
|
22
|
-
Commands['boilerplate'] = _boilerplate2["default"];
|
23
20
|
Commands['from-partial'] = _fromPartial["default"];
|
24
21
|
Commands['generate'] = _generate2["default"];
|
25
22
|
Commands['react-query'] = _reactQuery["default"];
|
@@ -11,9 +11,9 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
11
11
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
13
13
|
|
14
|
-
var _prompt = require("../prompt");
|
14
|
+
var _prompt = require("../utils/prompt");
|
15
15
|
|
16
|
-
var _fromPartial = _interopRequireDefault(require("../from-partial"));
|
16
|
+
var _fromPartial = _interopRequireDefault(require("../generators/from-partial"));
|
17
17
|
|
18
18
|
var _utils = require("../utils");
|
19
19
|
|
@@ -51,14 +51,18 @@ var _default = /*#__PURE__*/function () {
|
|
51
51
|
schema = _yield$prompt.schema;
|
52
52
|
out = _yield$prompt.out;
|
53
53
|
name = _yield$prompt.name;
|
54
|
-
|
54
|
+
_context.next = 9;
|
55
|
+
return (0, _utils.readSchemas)({
|
55
56
|
schemaDir: schema,
|
56
57
|
argv: argv
|
57
58
|
});
|
58
|
-
|
59
|
+
|
60
|
+
case 9:
|
61
|
+
schemas = _context.sent;
|
62
|
+
_context.next = 12;
|
59
63
|
return (0, _fromPartial["default"])(name, schemas, out);
|
60
64
|
|
61
|
-
case
|
65
|
+
case 12:
|
62
66
|
case "end":
|
63
67
|
return _context.stop();
|
64
68
|
}
|
@@ -11,9 +11,9 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
11
11
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
13
13
|
|
14
|
-
var _prompt = require("../prompt");
|
14
|
+
var _prompt = require("../utils/prompt");
|
15
15
|
|
16
|
-
var
|
16
|
+
var _tsClient = _interopRequireDefault(require("../generators/ts-client"));
|
17
17
|
|
18
18
|
var _utils = require("../utils");
|
19
19
|
|
@@ -51,14 +51,18 @@ var _default = /*#__PURE__*/function () {
|
|
51
51
|
schema = _yield$prompt.schema;
|
52
52
|
out = _yield$prompt.out;
|
53
53
|
name = _yield$prompt.name;
|
54
|
-
|
54
|
+
_context.next = 9;
|
55
|
+
return (0, _utils.readSchemas)({
|
55
56
|
schemaDir: schema,
|
56
57
|
argv: argv
|
57
58
|
});
|
58
|
-
_context.next = 10;
|
59
|
-
return (0, _generate["default"])(name, schemas, out);
|
60
59
|
|
61
|
-
case
|
60
|
+
case 9:
|
61
|
+
schemas = _context.sent;
|
62
|
+
_context.next = 12;
|
63
|
+
return (0, _tsClient["default"])(name, schemas, out);
|
64
|
+
|
65
|
+
case 12:
|
62
66
|
case "end":
|
63
67
|
return _context.stop();
|
64
68
|
}
|
@@ -13,9 +13,9 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
13
13
|
|
14
14
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
15
15
|
|
16
|
-
var _prompt = require("../prompt");
|
16
|
+
var _prompt = require("../utils/prompt");
|
17
17
|
|
18
|
-
var _reactQuery = _interopRequireDefault(require("../react-query"));
|
18
|
+
var _reactQuery = _interopRequireDefault(require("../generators/react-query"));
|
19
19
|
|
20
20
|
var _utils = require("../utils");
|
21
21
|
|
@@ -71,14 +71,18 @@ var _default = /*#__PURE__*/function () {
|
|
71
71
|
out = _yield$prompt.out;
|
72
72
|
name = _yield$prompt.name;
|
73
73
|
options = (0, _objectWithoutProperties2["default"])(_yield$prompt, _excluded);
|
74
|
-
|
74
|
+
_context.next = 10;
|
75
|
+
return (0, _utils.readSchemas)({
|
75
76
|
schemaDir: schema,
|
76
77
|
argv: argv
|
77
78
|
});
|
78
|
-
|
79
|
+
|
80
|
+
case 10:
|
81
|
+
schemas = _context.sent;
|
82
|
+
_context.next = 13;
|
79
83
|
return (0, _reactQuery["default"])(name, schemas, out, options);
|
80
84
|
|
81
|
-
case
|
85
|
+
case 13:
|
82
86
|
case "end":
|
83
87
|
return _context.stop();
|
84
88
|
}
|
package/main/commands/recoil.js
CHANGED
@@ -11,9 +11,9 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
11
11
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
13
13
|
|
14
|
-
var _prompt = require("../prompt");
|
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
|
|
@@ -51,14 +51,18 @@ var _default = /*#__PURE__*/function () {
|
|
51
51
|
schema = _yield$prompt.schema;
|
52
52
|
out = _yield$prompt.out;
|
53
53
|
name = _yield$prompt.name;
|
54
|
-
|
54
|
+
_context.next = 9;
|
55
|
+
return (0, _utils.readSchemas)({
|
55
56
|
schemaDir: schema,
|
56
57
|
argv: argv
|
57
58
|
});
|
58
|
-
|
59
|
+
|
60
|
+
case 9:
|
61
|
+
schemas = _context.sent;
|
62
|
+
_context.next = 12;
|
59
63
|
return (0, _recoil["default"])(name, schemas, out);
|
60
64
|
|
61
|
-
case
|
65
|
+
case 12:
|
62
66
|
case "end":
|
63
67
|
return _context.stop();
|
64
68
|
}
|
package/main/file.js
CHANGED
@@ -7,7 +7,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
7
7
|
|
8
8
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
9
9
|
|
10
|
-
var _prompt = require("./prompt");
|
10
|
+
var _prompt = require("./utils/prompt");
|
11
11
|
|
12
12
|
var _cli = require("./cli");
|
13
13
|
|
@@ -15,7 +15,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
15
15
|
|
16
16
|
var _case = require("case");
|
17
17
|
|
18
|
-
var _header = require("
|
18
|
+
var _header = require("../utils/header");
|
19
19
|
|
20
20
|
var _path = require("path");
|
21
21
|
|
@@ -29,7 +29,7 @@ var _fs = require("fs");
|
|
29
29
|
|
30
30
|
var _generator = _interopRequireDefault(require("@babel/generator"));
|
31
31
|
|
32
|
-
var _utils = require("
|
32
|
+
var _utils = require("../utils");
|
33
33
|
|
34
34
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
35
35
|
|
@@ -37,7 +37,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
37
37
|
|
38
38
|
var _default = /*#__PURE__*/function () {
|
39
39
|
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, schemas, outPath) {
|
40
|
-
var FromPartialFile, Contract, ExecuteMsg, typeHash, body, children, TheClass, Interface, code;
|
40
|
+
var FromPartialFile, Contract, ExecuteMsg, typeHash, body, context, children, TheClass, Interface, code;
|
41
41
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
42
42
|
while (1) {
|
43
43
|
switch (_context.prev = _context.next) {
|
@@ -59,7 +59,8 @@ var _default = /*#__PURE__*/function () {
|
|
59
59
|
body.push(w.importStmt(['Coin'], '@cosmjs/amino'));
|
60
60
|
}
|
61
61
|
|
62
|
-
body.push(w.importStmt(Object.keys(typeHash), "./".concat(Contract).replace(/\.ts$/, '')));
|
62
|
+
body.push(w.importStmt(Object.keys(typeHash), "./".concat(Contract).replace(/\.ts$/, '')));
|
63
|
+
context = new w.RenderContext((0, _utils.getDefinitionSchema)(schemas)); // execute messages
|
63
64
|
|
64
65
|
if (ExecuteMsg) {
|
65
66
|
children = (0, w.getMessageProperties)(ExecuteMsg);
|
@@ -67,8 +68,8 @@ var _default = /*#__PURE__*/function () {
|
|
67
68
|
if (children.length > 0) {
|
68
69
|
TheClass = (0, _case.pascal)("".concat(name, "MessageComposer"));
|
69
70
|
Interface = (0, _case.pascal)("".concat(name, "Message"));
|
70
|
-
body.push(w.createFromPartialInterface(Interface, ExecuteMsg));
|
71
|
-
body.push(w.createFromPartialClass(TheClass, Interface, ExecuteMsg));
|
71
|
+
body.push(w.createFromPartialInterface(context, Interface, ExecuteMsg));
|
72
|
+
body.push(w.createFromPartialClass(context, TheClass, Interface, ExecuteMsg));
|
72
73
|
}
|
73
74
|
}
|
74
75
|
|
@@ -76,7 +77,7 @@ var _default = /*#__PURE__*/function () {
|
|
76
77
|
(0, _mkdirp.sync)(outPath);
|
77
78
|
(0, _fs.writeFileSync)((0, _path.join)(outPath, FromPartialFile), code);
|
78
79
|
|
79
|
-
case
|
80
|
+
case 17:
|
80
81
|
case "end":
|
81
82
|
return _context.stop();
|
82
83
|
}
|
@@ -15,7 +15,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
15
15
|
|
16
16
|
var _case = require("case");
|
17
17
|
|
18
|
-
var _header = require("
|
18
|
+
var _header = require("../utils/header");
|
19
19
|
|
20
20
|
var _path = require("path");
|
21
21
|
|
@@ -29,29 +29,33 @@ var _fs = require("fs");
|
|
29
29
|
|
30
30
|
var _generator = _interopRequireDefault(require("@babel/generator"));
|
31
31
|
|
32
|
-
var _utils = require("
|
32
|
+
var _utils = require("../utils");
|
33
33
|
|
34
|
-
var _imports = require("
|
34
|
+
var _imports = require("../utils/imports");
|
35
35
|
|
36
36
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
37
37
|
|
38
38
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
39
39
|
|
40
40
|
var _default = /*#__PURE__*/function () {
|
41
|
-
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(contractName, schemas, outPath,
|
42
|
-
var ReactQueryFile, Contract, QueryMsg, ExecuteMsg, typeHash, ExecuteClient, QueryClient, body, reactQueryImports, clientImports, shouldGenerateMutationHooks, code;
|
41
|
+
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(contractName, schemas, outPath, reactQueryOptions) {
|
42
|
+
var context, options, ReactQueryFile, Contract, QueryMsg, ExecuteMsg, typeHash, ExecuteClient, QueryClient, body, reactQueryImports, clientImports, shouldGenerateMutationHooks, code;
|
43
43
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
44
44
|
while (1) {
|
45
45
|
switch (_context.prev = _context.next) {
|
46
46
|
case 0:
|
47
|
+
context = new w.RenderContext((0, _utils.getDefinitionSchema)(schemas), {
|
48
|
+
reactQuery: reactQueryOptions !== null && reactQueryOptions !== void 0 ? reactQueryOptions : {}
|
49
|
+
});
|
50
|
+
options = context.options.reactQuery;
|
47
51
|
ReactQueryFile = (0, _case.pascal)("".concat(contractName, "Contract")) + '.react-query.ts';
|
48
52
|
Contract = (0, _case.pascal)("".concat(contractName, "Contract"));
|
49
53
|
QueryMsg = (0, _utils.findQueryMsg)(schemas);
|
50
54
|
ExecuteMsg = (0, _utils.findExecuteMsg)(schemas);
|
51
|
-
_context.next =
|
55
|
+
_context.next = 8;
|
52
56
|
return (0, _utils.findAndParseTypes)(schemas);
|
53
57
|
|
54
|
-
case
|
58
|
+
case 8:
|
55
59
|
typeHash = _context.sent;
|
56
60
|
ExecuteClient = (0, _case.pascal)("".concat(contractName, "Client"));
|
57
61
|
QueryClient = (0, _case.pascal)("".concat(contractName, "QueryClient"));
|
@@ -78,19 +82,19 @@ var _default = /*#__PURE__*/function () {
|
|
78
82
|
|
79
83
|
if (QueryMsg) {
|
80
84
|
[].push.apply(body, w.createReactQueryHooks({
|
85
|
+
context: context,
|
81
86
|
queryMsg: QueryMsg,
|
82
87
|
contractName: contractName,
|
83
|
-
QueryClient: QueryClient
|
84
|
-
options: options
|
88
|
+
QueryClient: QueryClient
|
85
89
|
}));
|
86
90
|
}
|
87
91
|
|
88
92
|
if (shouldGenerateMutationHooks) {
|
89
93
|
[].push.apply(body, w.createReactQueryMutationHooks({
|
94
|
+
context: context,
|
90
95
|
execMsg: ExecuteMsg,
|
91
96
|
contractName: contractName,
|
92
|
-
ExecuteClient: ExecuteClient
|
93
|
-
options: options
|
97
|
+
ExecuteClient: ExecuteClient
|
94
98
|
}));
|
95
99
|
}
|
96
100
|
|
@@ -98,7 +102,7 @@ var _default = /*#__PURE__*/function () {
|
|
98
102
|
(0, _mkdirp.sync)(outPath);
|
99
103
|
(0, _fs.writeFileSync)((0, _path.join)(outPath, ReactQueryFile), code);
|
100
104
|
|
101
|
-
case
|
105
|
+
case 25:
|
102
106
|
case "end":
|
103
107
|
return _context.stop();
|
104
108
|
}
|
@@ -15,7 +15,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
15
15
|
|
16
16
|
var _case = require("case");
|
17
17
|
|
18
|
-
var _header = require("
|
18
|
+
var _header = require("../utils/header");
|
19
19
|
|
20
20
|
var _path = require("path");
|
21
21
|
|
@@ -29,7 +29,7 @@ var _fs = require("fs");
|
|
29
29
|
|
30
30
|
var _generator = _interopRequireDefault(require("@babel/generator"));
|
31
31
|
|
32
|
-
var _utils = require("
|
32
|
+
var _utils = require("../utils");
|
33
33
|
|
34
34
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
35
35
|
|
@@ -37,7 +37,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
37
37
|
|
38
38
|
var _default = /*#__PURE__*/function () {
|
39
39
|
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, schemas, outPath) {
|
40
|
-
var RecoilFile, Contract, QueryMsg, typeHash, QueryClient, ReadOnlyInstance, body, code;
|
40
|
+
var RecoilFile, Contract, QueryMsg, typeHash, QueryClient, ReadOnlyInstance, body, context, code;
|
41
41
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
42
42
|
while (1) {
|
43
43
|
switch (_context.prev = _context.next) {
|
@@ -55,22 +55,23 @@ var _default = /*#__PURE__*/function () {
|
|
55
55
|
body = [];
|
56
56
|
body.push(w.importStmt(['selectorFamily'], 'recoil'));
|
57
57
|
body.push(w.importStmt(['cosmWasmClient'], './chain'));
|
58
|
-
body.push(w.importStmt(Object.keys(typeHash), "./".concat(Contract).replace(/\.ts$/, '')));
|
58
|
+
body.push(w.importStmt(Object.keys(typeHash), "./".concat(Contract).replace(/\.ts$/, '')));
|
59
|
+
context = new w.RenderContext((0, _utils.getDefinitionSchema)(schemas)); // query messages
|
59
60
|
|
60
61
|
if (QueryMsg) {
|
61
62
|
QueryClient = (0, _case.pascal)("".concat(name, "QueryClient"));
|
62
63
|
ReadOnlyInstance = (0, _case.pascal)("".concat(name, "ReadOnlyInterface"));
|
63
64
|
body.push(w.importStmt([QueryClient], "./".concat(Contract)));
|
64
65
|
body.push(w.createRecoilQueryClientType());
|
65
|
-
body.push(w.createRecoilQueryClient(name, QueryClient));
|
66
|
-
[].push.apply(body, w.createRecoilSelectors(name, QueryClient, QueryMsg));
|
66
|
+
body.push(w.createRecoilQueryClient(context, name, QueryClient));
|
67
|
+
[].push.apply(body, w.createRecoilSelectors(context, name, QueryClient, QueryMsg));
|
67
68
|
}
|
68
69
|
|
69
70
|
code = _header.header + (0, _generator["default"])(t.program(body)).code;
|
70
71
|
(0, _mkdirp.sync)(outPath);
|
71
72
|
(0, _fs.writeFileSync)((0, _path.join)(outPath, RecoilFile), code);
|
72
73
|
|
73
|
-
case
|
74
|
+
case 17:
|
74
75
|
case "end":
|
75
76
|
return _context.stop();
|
76
77
|
}
|