@cosmwasm/ts-codegen 1.0.0 → 1.2.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 CHANGED
@@ -18,7 +18,7 @@ Generate TypeScript SDKs for your CosmWasm smart contracts
18
18
 
19
19
 
20
20
  ```
21
- npm install -g @cosmwasm/ts-codegen
21
+ npm install @cosmwasm/ts-codegen
22
22
  ```
23
23
 
24
24
  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.
@@ -28,7 +28,6 @@ The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-
28
28
 
29
29
  - [@cosmwasm/ts-codegen](#cosmwasmts-codegen)
30
30
  - [Table of contents](#table-of-contents)
31
- - [QuickStart](#quickstart)
32
31
  - [Usage](#usage)
33
32
  - [Programmatic Usage](#programmatic-usage)
34
33
  - [Types](#types)
@@ -47,35 +46,9 @@ The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-
47
46
  - [Exporting Schemas](#exporting-schemas)
48
47
  - [Developing](#developing)
49
48
  - [Related](#related)
50
- ## Quickstart
51
-
52
- Clone your project and `cd` into your contracts folder
53
-
54
- ```sh
55
- git clone https://github.com/public-awesome/launchpad.git
56
- cd launchpad/contracts/sg721-base/
57
- ```
58
-
59
- Run `cosmwasm-ts-codegen` to generate your code.
60
-
61
- ```sh
62
- cosmwasm-ts-codegen generate \
63
- --plugin client \
64
- --schema ./schema \
65
- --out ./ts \
66
- --name SG721 \
67
- --no-bundle
68
- ```
69
-
70
- The output will be in the folder specified by `--out`, enjoy!
71
49
 
72
50
  ## Usage
73
51
 
74
- You can get started quickly using our `cli` by globally installing via npm:
75
-
76
- ```
77
- npm install -g @cosmwasm/ts-codegen
78
- ```
79
52
  ### Programmatic Usage
80
53
 
81
54
  For production usage, we recommend setting up a build script that uses the main entry point:
@@ -137,7 +110,7 @@ codegen({
137
110
 
138
111
  Typescript types and interfaces are generated in separate files so they can be imported into various generated plugins.
139
112
 
140
- [see example output code](https://gist.github.com/pyramation/107d4e8e30dc5eb3ffc07bc3000f4dd0)
113
+ [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.types.ts)
141
114
 
142
115
  #### Types Options
143
116
 
@@ -151,7 +124,7 @@ Typescript types and interfaces are generated in separate files so they can be i
151
124
 
152
125
  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
126
 
154
- [see example output code](https://gist.github.com/pyramation/30508678b7563e286f06ccc5ac384817)
127
+ [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.client.ts )
155
128
 
156
129
  #### Client Options
157
130
 
@@ -161,20 +134,12 @@ The `client` plugin will generate TS client classes for your contracts. This opt
161
134
  | `client.execExtendsQuery` | execute should extend query message clients |
162
135
  | `client.noImplicitOverride` | should match your tsconfig noImplicitOverride option |
163
136
 
164
- #### Client via CLI
165
137
 
166
- ```sh
167
- cosmwasm-ts-codegen generate \
168
- --plugin client
169
- --schema ./schema \
170
- --out ./ts \
171
- --name MyContractName
172
- ```
173
138
  ### React Query
174
139
 
175
140
  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.
176
141
 
177
- [see example output code](https://gist.github.com/pyramation/70aef28fd3af0ee164f7711704d3dfc0)
142
+ [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.react-query.ts)
178
143
 
179
144
  #### React Query Options
180
145
 
@@ -189,50 +154,11 @@ Generate [react-query v3](https://react-query-v3.tanstack.com/) or [react-query
189
154
  | `reactQuery.camelize` | use camelCase style for property names |
190
155
 
191
156
 
192
- #### React Query via CLI
193
-
194
- Here is an example without optional client, using v3 for `react-query`, without mutations:
195
-
196
- ```sh
197
- cosmwasm-ts-codegen generate \
198
- --plugin client \
199
- --plugin react-query \
200
- --schema ./schema \
201
- --out ./ts \
202
- --name MyContractName \
203
- --version v3 \
204
- --no-optionalClient \
205
- --no-mutations
206
- ```
207
-
208
- Example with optional client, using v4, with mutations:
209
-
210
- ```sh
211
- cosmwasm-ts-codegen generate \
212
- --plugin react-query \
213
- --schema ./schema \
214
- --out ./ts \
215
- --name MyContractName \
216
- --optionalClient \
217
- --version v4 \
218
- --mutations
219
- ```
220
-
221
157
  ### Recoil
222
158
 
223
159
  Generate [recoil](https://recoiljs.org/) bindings for your contracts with the `recoil` command.
224
160
 
225
- [see example output code](https://gist.github.com/pyramation/a9520ccf131177b1841e02a97d7d3731)
226
-
227
- #### Recoil via CLI
228
-
229
- ```sh
230
- cosmwasm-ts-codegen generate \
231
- --plugin recoil \
232
- --schema ./schema \
233
- --out ./ts \
234
- --name MyContractName
235
- ```
161
+ [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.recoil.ts)
236
162
 
237
163
  #### Recoil Options
238
164
 
@@ -244,17 +170,8 @@ cosmwasm-ts-codegen generate \
244
170
 
245
171
  Generate pure message objects with the proper `utf8` encoding and `typeUrl` configured that you can broadcast yourself via `cosmjs` with the `message-composer` command.
246
172
 
247
- [see example output code](https://gist.github.com/pyramation/43320e8b952751a0bd5a77dbc5b601f4)
173
+ [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.message-composer.ts)
248
174
 
249
- #### Message Composer via CLI
250
-
251
- ```sh
252
- cosmwasm-ts-codegen generate \
253
- --plugin message-composer \
254
- --schema ./schema \
255
- --out ./ts \
256
- --name MyContractName
257
- ```
258
175
  #### Message Composer Options
259
176
 
260
177
  | option | description |
@@ -265,17 +182,8 @@ cosmwasm-ts-codegen generate \
265
182
 
266
183
  Generate raw message jsons for use in your application with the `message-builder` command.
267
184
 
268
- [see example output code](https://gist.github.com/adairrr/b394e62beb9856b0351883f776650f26)
269
-
270
- #### Message Builder via CLI
185
+ [see example output code](https://github.com/CosmWasm/ts-codegen/blob/main/__output__/sg721/Sg721.message-builder.ts)
271
186
 
272
- ```sh
273
- cosmwasm-ts-codegen generate \
274
- --plugin message-builder \
275
- --schema ./schema \
276
- --out ./ts \
277
- --name MyContractName
278
- ```
279
187
  #### Message Builder Options
280
188
 
281
189
  | option | description |
@@ -426,6 +334,32 @@ Without using shorthand constructor:
426
334
 
427
335
  ### CLI Usage and Examples
428
336
 
337
+ You can get started quickly using our `cli` by globally installing via npm:
338
+
339
+ ```
340
+ npm install @cosmwasm/ts-codegen
341
+ ```
342
+
343
+ Clone your project and `cd` into your contracts folder
344
+
345
+ ```sh
346
+ git clone https://github.com/public-awesome/launchpad.git
347
+ cd launchpad/contracts/whitelists/
348
+ ```
349
+
350
+ Run `cosmwasm-ts-codegen` to generate your code.
351
+
352
+ ```sh
353
+ cosmwasm-ts-codegen generate \
354
+ --plugin client \
355
+ --schema ./schema \
356
+ --out ./ts \
357
+ --name Whitelist \
358
+ --no-bundle
359
+ ```
360
+
361
+ The output will be in the folder specified by `--out`, enjoy!
362
+
429
363
  #### Interactive prompt
430
364
 
431
365
  The CLI is interactive, and if you don't specify an option, it will interactively prompt you.
@@ -506,6 +440,77 @@ cosmwasm-ts-codegen generate \
506
440
  --name SG721
507
441
  ```
508
442
 
443
+ #### Client via CLI
444
+
445
+ ```sh
446
+ cosmwasm-ts-codegen generate \
447
+ --plugin client
448
+ --schema ./schema \
449
+ --out ./ts \
450
+ --name MyContractName
451
+ ```
452
+
453
+
454
+ #### React Query via CLI
455
+
456
+ Here is an example without optional client, using v3 for `react-query`, without mutations:
457
+
458
+ ```sh
459
+ cosmwasm-ts-codegen generate \
460
+ --plugin client \
461
+ --plugin react-query \
462
+ --schema ./schema \
463
+ --out ./ts \
464
+ --name MyContractName \
465
+ --version v3 \
466
+ --no-optionalClient \
467
+ --no-mutations
468
+ ```
469
+
470
+ Example with optional client, using v4, with mutations:
471
+
472
+ ```sh
473
+ cosmwasm-ts-codegen generate \
474
+ --plugin react-query \
475
+ --schema ./schema \
476
+ --out ./ts \
477
+ --name MyContractName \
478
+ --optionalClient \
479
+ --version v4 \
480
+ --mutations
481
+ ```
482
+
483
+ #### Recoil via CLI
484
+
485
+ ```sh
486
+ cosmwasm-ts-codegen generate \
487
+ --plugin recoil \
488
+ --schema ./schema \
489
+ --out ./ts \
490
+ --name MyContractName
491
+ ```
492
+
493
+ #### Message Composer via CLI
494
+
495
+ ```sh
496
+ cosmwasm-ts-codegen generate \
497
+ --plugin message-composer \
498
+ --schema ./schema \
499
+ --out ./ts \
500
+ --name MyContractName
501
+ ```
502
+
503
+ #### Message Builder via CLI
504
+
505
+ ```sh
506
+ cosmwasm-ts-codegen generate \
507
+ --plugin message-builder \
508
+ --schema ./schema \
509
+ --out ./ts \
510
+ --name MyContractName
511
+ ```
512
+
513
+
509
514
  ### Advanced Usage
510
515
 
511
516
  for lower-level access, you can import the various plugins directly:
@@ -1,8 +1,33 @@
1
1
  import { join, dirname, basename, extname } from "path";
2
+ import { readFileSync, existsSync } from "fs";
2
3
  import { sync as mkdirp } from "mkdirp";
3
- import pkg from "../../package.json";
4
4
  import { writeContentToFile } from "../utils/files";
5
5
  import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, } from "../helpers";
6
+ // need to search due to the dist/ folder and src/, etc.
7
+ function findPackageJson(currentDir) {
8
+ const filePath = join(currentDir, 'package.json');
9
+ // Check if package.json exists in the current directory
10
+ if (existsSync(filePath)) {
11
+ return filePath;
12
+ }
13
+ // Get the parent directory
14
+ const parentDir = dirname(currentDir);
15
+ // If reached the root directory, package.json is not found
16
+ if (parentDir === currentDir) {
17
+ throw new Error('package.json not found in any parent directory');
18
+ }
19
+ // Recursively look in the parent directory
20
+ return findPackageJson(parentDir);
21
+ }
22
+ function readAndParsePackageJson() {
23
+ // Start searching from the current directory
24
+ const pkgPath = findPackageJson(__dirname);
25
+ // Read and parse the package.json
26
+ const str = readFileSync(pkgPath, 'utf8');
27
+ const pkg = JSON.parse(str);
28
+ return pkg;
29
+ }
30
+ const pkg = readAndParsePackageJson();
6
31
  const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
7
32
  const header = `/**
8
33
  * This file and any referenced files were automatically generated by ${pkg.name}@${version}
package/esm/index.js CHANGED
@@ -2,6 +2,7 @@ import { TSBuilder } from './builder';
2
2
  export { default as generateTypes } from './generators/types';
3
3
  export { default as generateClient } from './generators/client';
4
4
  export { default as generateMessageComposer } from './generators/message-composer';
5
+ export { default as generateMessageBuilder } from './generators/message-builder';
5
6
  export { default as generateReactQuery } from './generators/react-query';
6
7
  export { default as generateRecoil } from './generators/recoil';
7
8
  export * from './utils';
@@ -1,17 +1,39 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.createHelpers = void 0;
7
4
  const path_1 = require("path");
5
+ const fs_1 = require("fs");
8
6
  const mkdirp_1 = require("mkdirp");
9
- const package_json_1 = __importDefault(require("../../package.json"));
10
7
  const files_1 = require("../utils/files");
11
8
  const helpers_1 = require("../helpers");
12
- const version = process.env.NODE_ENV === "test" ? "latest" : package_json_1.default.version;
9
+ // need to search due to the dist/ folder and src/, etc.
10
+ function findPackageJson(currentDir) {
11
+ const filePath = (0, path_1.join)(currentDir, 'package.json');
12
+ // Check if package.json exists in the current directory
13
+ if ((0, fs_1.existsSync)(filePath)) {
14
+ return filePath;
15
+ }
16
+ // Get the parent directory
17
+ const parentDir = (0, path_1.dirname)(currentDir);
18
+ // If reached the root directory, package.json is not found
19
+ if (parentDir === currentDir) {
20
+ throw new Error('package.json not found in any parent directory');
21
+ }
22
+ // Recursively look in the parent directory
23
+ return findPackageJson(parentDir);
24
+ }
25
+ function readAndParsePackageJson() {
26
+ // Start searching from the current directory
27
+ const pkgPath = findPackageJson(__dirname);
28
+ // Read and parse the package.json
29
+ const str = (0, fs_1.readFileSync)(pkgPath, 'utf8');
30
+ const pkg = JSON.parse(str);
31
+ return pkg;
32
+ }
33
+ const pkg = readAndParsePackageJson();
34
+ const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
13
35
  const header = `/**
14
- * This file and any referenced files were automatically generated by ${package_json_1.default.name}@${version}
36
+ * This file and any referenced files were automatically generated by ${pkg.name}@${version}
15
37
  * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
16
38
  * and run the transpile command or yarn proto command to regenerate this bundle.
17
39
  */
package/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { TSBuilderInput } from './builder';
2
2
  export { default as generateTypes } from './generators/types';
3
3
  export { default as generateClient } from './generators/client';
4
4
  export { default as generateMessageComposer } from './generators/message-composer';
5
+ export { default as generateMessageBuilder } from './generators/message-builder';
5
6
  export { default as generateReactQuery } from './generators/react-query';
6
7
  export { default as generateRecoil } from './generators/recoil';
7
8
  export * from './utils';
package/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.generateRecoil = exports.generateReactQuery = exports.generateMessageComposer = exports.generateClient = exports.generateTypes = void 0;
20
+ exports.generateRecoil = exports.generateReactQuery = exports.generateMessageBuilder = exports.generateMessageComposer = exports.generateClient = exports.generateTypes = void 0;
21
21
  const builder_1 = require("./builder");
22
22
  var types_1 = require("./generators/types");
23
23
  Object.defineProperty(exports, "generateTypes", { enumerable: true, get: function () { return __importDefault(types_1).default; } });
@@ -25,6 +25,8 @@ var client_1 = require("./generators/client");
25
25
  Object.defineProperty(exports, "generateClient", { enumerable: true, get: function () { return __importDefault(client_1).default; } });
26
26
  var message_composer_1 = require("./generators/message-composer");
27
27
  Object.defineProperty(exports, "generateMessageComposer", { enumerable: true, get: function () { return __importDefault(message_composer_1).default; } });
28
+ var message_builder_1 = require("./generators/message-builder");
29
+ Object.defineProperty(exports, "generateMessageBuilder", { enumerable: true, get: function () { return __importDefault(message_builder_1).default; } });
28
30
  var react_query_1 = require("./generators/react-query");
29
31
  Object.defineProperty(exports, "generateReactQuery", { enumerable: true, get: function () { return __importDefault(react_query_1).default; } });
30
32
  var recoil_1 = require("./generators/recoil");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
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",
@@ -13,7 +13,7 @@
13
13
  "directory": "dist"
14
14
  },
15
15
  "bin": {
16
- "cosmwasm-ts-codegen": "main/ts-codegen.js"
16
+ "cosmwasm-ts-codegen": "ts-codegen.js"
17
17
  },
18
18
  "scripts": {
19
19
  "copy": "copyfiles -f LICENSE-Apache LICENSE-MIT README.md package.json dist",
@@ -38,19 +38,8 @@
38
38
  "ast-stringify": "0.1.0"
39
39
  },
40
40
  "dependencies": {
41
- "@babel/core": "7.18.10",
42
- "@babel/generator": "7.18.12",
43
- "@babel/parser": "7.18.11",
44
- "@babel/plugin-proposal-class-properties": "7.18.6",
45
- "@babel/plugin-proposal-export-default-from": "7.18.10",
46
- "@babel/plugin-proposal-object-rest-spread": "7.18.9",
47
- "@babel/plugin-transform-runtime": "7.18.10",
48
- "@babel/preset-env": "7.18.10",
49
- "@babel/preset-typescript": "^7.18.6",
50
- "@babel/runtime": "^7.18.9",
51
- "@babel/traverse": "7.18.11",
52
41
  "@babel/types": "7.18.10",
53
- "@cosmology/ts-codegen-types": "^1.0.0",
42
+ "@cosmology/ts-codegen-types": "^1.1.0",
54
43
  "@pyramation/json-schema-to-typescript": " 11.0.4",
55
44
  "@types/rimraf": "3.0.2",
56
45
  "@types/shelljs": "0.8.15",
@@ -66,7 +55,7 @@
66
55
  "parse-package-name": "1.0.0",
67
56
  "rimraf": "3.0.2",
68
57
  "shelljs": "0.8.5",
69
- "wasm-ast-types": "^1.0.0"
58
+ "wasm-ast-types": "^1.1.0"
70
59
  },
71
60
  "keywords": [
72
61
  "cosmwasm",
@@ -74,5 +63,5 @@
74
63
  "smart contracts",
75
64
  "codegen"
76
65
  ],
77
- "gitHead": "7d55265f8f7cb567b921b78b9df5ca996bf9c8b6"
66
+ "gitHead": "e105783253da5352163be0bb2fc4ac65b027fa94"
78
67
  }