@cosmwasm/ts-codegen 0.13.4 → 0.14.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/main/builder/builder.js +30 -25
- package/main/commands/create-boilerplate.js +1 -1
- package/main/utils/schemas.js +43 -10
- package/module/builder/builder.js +15 -5
- package/module/commands/create-boilerplate.js +1 -1
- package/module/utils/schemas.js +45 -7
- package/package.json +3 -3
- package/types/src/types.d.ts +15 -0
- package/types/src/utils/schemas.d.ts +6 -4
package/main/builder/builder.js
CHANGED
@@ -114,7 +114,7 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
114
114
|
key: "renderTypes",
|
115
115
|
value: function () {
|
116
116
|
var _renderTypes = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(contract) {
|
117
|
-
var _this$options$types, enabled, options, schemas, files;
|
117
|
+
var _this$options$types, enabled, options, _yield$readSchemas, schemas, files;
|
118
118
|
|
119
119
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
120
120
|
while (1) {
|
@@ -136,15 +136,16 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
136
136
|
});
|
137
137
|
|
138
138
|
case 5:
|
139
|
-
|
140
|
-
|
139
|
+
_yield$readSchemas = _context.sent;
|
140
|
+
schemas = _yield$readSchemas.schemas;
|
141
|
+
_context.next = 9;
|
141
142
|
return (0, _types["default"])(contract.name, schemas, this.outPath, options);
|
142
143
|
|
143
|
-
case
|
144
|
+
case 9:
|
144
145
|
files = _context.sent;
|
145
146
|
[].push.apply(this.files, files);
|
146
147
|
|
147
|
-
case
|
148
|
+
case 11:
|
148
149
|
case "end":
|
149
150
|
return _context.stop();
|
150
151
|
}
|
@@ -162,7 +163,7 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
162
163
|
key: "renderClient",
|
163
164
|
value: function () {
|
164
165
|
var _renderClient = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(contract) {
|
165
|
-
var _this$options$client, enabled, options, schemas, files;
|
166
|
+
var _this$options$client, enabled, options, _yield$readSchemas2, schemas, files;
|
166
167
|
|
167
168
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
168
169
|
while (1) {
|
@@ -184,15 +185,16 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
184
185
|
});
|
185
186
|
|
186
187
|
case 5:
|
187
|
-
|
188
|
-
|
188
|
+
_yield$readSchemas2 = _context2.sent;
|
189
|
+
schemas = _yield$readSchemas2.schemas;
|
190
|
+
_context2.next = 9;
|
189
191
|
return (0, _client["default"])(contract.name, schemas, this.outPath, options);
|
190
192
|
|
191
|
-
case
|
193
|
+
case 9:
|
192
194
|
files = _context2.sent;
|
193
195
|
[].push.apply(this.files, files);
|
194
196
|
|
195
|
-
case
|
197
|
+
case 11:
|
196
198
|
case "end":
|
197
199
|
return _context2.stop();
|
198
200
|
}
|
@@ -210,7 +212,7 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
210
212
|
key: "renderRecoil",
|
211
213
|
value: function () {
|
212
214
|
var _renderRecoil = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(contract) {
|
213
|
-
var _this$options$recoil, enabled, options, schemas, files;
|
215
|
+
var _this$options$recoil, enabled, options, _yield$readSchemas3, schemas, files;
|
214
216
|
|
215
217
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
216
218
|
while (1) {
|
@@ -232,15 +234,16 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
232
234
|
});
|
233
235
|
|
234
236
|
case 5:
|
235
|
-
|
236
|
-
|
237
|
+
_yield$readSchemas3 = _context3.sent;
|
238
|
+
schemas = _yield$readSchemas3.schemas;
|
239
|
+
_context3.next = 9;
|
237
240
|
return (0, _recoil["default"])(contract.name, schemas, this.outPath, options);
|
238
241
|
|
239
|
-
case
|
242
|
+
case 9:
|
240
243
|
files = _context3.sent;
|
241
244
|
[].push.apply(this.files, files);
|
242
245
|
|
243
|
-
case
|
246
|
+
case 11:
|
244
247
|
case "end":
|
245
248
|
return _context3.stop();
|
246
249
|
}
|
@@ -258,7 +261,7 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
258
261
|
key: "renderReactQuery",
|
259
262
|
value: function () {
|
260
263
|
var _renderReactQuery = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(contract) {
|
261
|
-
var _this$options$reactQu, enabled, options, schemas, files;
|
264
|
+
var _this$options$reactQu, enabled, options, _yield$readSchemas4, schemas, files;
|
262
265
|
|
263
266
|
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
264
267
|
while (1) {
|
@@ -280,15 +283,16 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
280
283
|
});
|
281
284
|
|
282
285
|
case 5:
|
283
|
-
|
284
|
-
|
286
|
+
_yield$readSchemas4 = _context4.sent;
|
287
|
+
schemas = _yield$readSchemas4.schemas;
|
288
|
+
_context4.next = 9;
|
285
289
|
return (0, _reactQuery["default"])(contract.name, schemas, this.outPath, options);
|
286
290
|
|
287
|
-
case
|
291
|
+
case 9:
|
288
292
|
files = _context4.sent;
|
289
293
|
[].push.apply(this.files, files);
|
290
294
|
|
291
|
-
case
|
295
|
+
case 11:
|
292
296
|
case "end":
|
293
297
|
return _context4.stop();
|
294
298
|
}
|
@@ -306,7 +310,7 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
306
310
|
key: "renderMessageComposer",
|
307
311
|
value: function () {
|
308
312
|
var _renderMessageComposer = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(contract) {
|
309
|
-
var _this$options$message, enabled, options, schemas, files;
|
313
|
+
var _this$options$message, enabled, options, _yield$readSchemas5, schemas, files;
|
310
314
|
|
311
315
|
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
312
316
|
while (1) {
|
@@ -328,15 +332,16 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
328
332
|
});
|
329
333
|
|
330
334
|
case 5:
|
331
|
-
|
332
|
-
|
335
|
+
_yield$readSchemas5 = _context5.sent;
|
336
|
+
schemas = _yield$readSchemas5.schemas;
|
337
|
+
_context5.next = 9;
|
333
338
|
return (0, _messageComposer["default"])(contract.name, schemas, this.outPath, options);
|
334
339
|
|
335
|
-
case
|
340
|
+
case 9:
|
336
341
|
files = _context5.sent;
|
337
342
|
[].push.apply(this.files, files);
|
338
343
|
|
339
|
-
case
|
344
|
+
case 11:
|
340
345
|
case "end":
|
341
346
|
return _context5.stop();
|
342
347
|
}
|
@@ -35,7 +35,7 @@ var fs = require('fs');
|
|
35
35
|
|
36
36
|
var path = require('path');
|
37
37
|
|
38
|
-
var repo = '
|
38
|
+
var repo = 'https://github.com/pyramation/tmpl-cosmwasm-module.git';
|
39
39
|
|
40
40
|
var _default = /*#__PURE__*/function () {
|
41
41
|
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(argv) {
|
package/main/utils/schemas.js
CHANGED
@@ -27,17 +27,18 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
27
27
|
|
28
28
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
29
29
|
|
30
|
+
;
|
30
31
|
;
|
31
32
|
|
32
33
|
var readSchemas = /*#__PURE__*/function () {
|
33
34
|
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
34
|
-
var schemaDir,
|
35
|
+
var schemaDir, _ref$clean, clean, fn, files, schemas, idlObject, contract_name, contract_version, idl_version, responses, instantiate, execute, query, migrate, sudo;
|
35
36
|
|
36
37
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
37
38
|
while (1) {
|
38
39
|
switch (_context.prev = _context.next) {
|
39
40
|
case 0:
|
40
|
-
schemaDir = _ref.schemaDir,
|
41
|
+
schemaDir = _ref.schemaDir, _ref$clean = _ref.clean, clean = _ref$clean === void 0 ? true : _ref$clean;
|
41
42
|
fn = clean ? _cleanse.cleanse : function (str) {
|
42
43
|
return str;
|
43
44
|
};
|
@@ -46,25 +47,57 @@ var readSchemas = /*#__PURE__*/function () {
|
|
46
47
|
return JSON.parse((0, _fs.readFileSync)(file, 'utf-8'));
|
47
48
|
});
|
48
49
|
|
49
|
-
if (!(
|
50
|
+
if (!(schemas.length > 1)) {
|
51
|
+
_context.next = 6;
|
52
|
+
break;
|
53
|
+
}
|
54
|
+
|
55
|
+
return _context.abrupt("return", {
|
56
|
+
schemas: fn(schemas)
|
57
|
+
});
|
58
|
+
|
59
|
+
case 6:
|
60
|
+
if (!(schemas.length === 0)) {
|
50
61
|
_context.next = 8;
|
51
62
|
break;
|
52
63
|
}
|
53
64
|
|
65
|
+
throw new Error('Error [too few files]: requires one schema file per contract');
|
66
|
+
|
67
|
+
case 8:
|
54
68
|
if (!(schemas.length !== 1)) {
|
55
|
-
_context.next =
|
69
|
+
_context.next = 10;
|
56
70
|
break;
|
57
71
|
}
|
58
72
|
|
59
|
-
throw new Error('
|
73
|
+
throw new Error('Error [too many files]: CosmWasm v1.1 schemas supports one file');
|
60
74
|
|
61
|
-
case
|
62
|
-
|
75
|
+
case 10:
|
76
|
+
idlObject = schemas[0];
|
77
|
+
contract_name = idlObject.contract_name, contract_version = idlObject.contract_version, idl_version = idlObject.idl_version, responses = idlObject.responses, instantiate = idlObject.instantiate, execute = idlObject.execute, query = idlObject.query, migrate = idlObject.migrate, sudo = idlObject.sudo;
|
63
78
|
|
64
|
-
|
65
|
-
|
79
|
+
if (!(typeof idl_version !== 'string')) {
|
80
|
+
_context.next = 14;
|
81
|
+
break;
|
82
|
+
}
|
83
|
+
|
84
|
+
return _context.abrupt("return", {
|
85
|
+
schemas: fn(schemas)
|
86
|
+
});
|
87
|
+
|
88
|
+
case 14:
|
89
|
+
return _context.abrupt("return", {
|
90
|
+
schemas: Object.values(fn({
|
91
|
+
instantiate: instantiate,
|
92
|
+
execute: execute,
|
93
|
+
query: query,
|
94
|
+
migrate: migrate,
|
95
|
+
sudo: sudo
|
96
|
+
})).filter(Boolean),
|
97
|
+
idlObject: idlObject
|
98
|
+
});
|
66
99
|
|
67
|
-
case
|
100
|
+
case 15:
|
68
101
|
case "end":
|
69
102
|
return _context.stop();
|
70
103
|
}
|
@@ -77,7 +77,9 @@ export class TSBuilder {
|
|
77
77
|
options = _objectWithoutProperties(_this$options$types, _excluded);
|
78
78
|
|
79
79
|
if (!enabled) return;
|
80
|
-
const
|
80
|
+
const {
|
81
|
+
schemas
|
82
|
+
} = await readSchemas({
|
81
83
|
schemaDir: contract.dir
|
82
84
|
});
|
83
85
|
const files = await generateTypes(contract.name, schemas, this.outPath, options);
|
@@ -92,7 +94,9 @@ export class TSBuilder {
|
|
92
94
|
options = _objectWithoutProperties(_this$options$client, _excluded2);
|
93
95
|
|
94
96
|
if (!enabled) return;
|
95
|
-
const
|
97
|
+
const {
|
98
|
+
schemas
|
99
|
+
} = await readSchemas({
|
96
100
|
schemaDir: contract.dir
|
97
101
|
});
|
98
102
|
const files = await generateClient(contract.name, schemas, this.outPath, options);
|
@@ -107,7 +111,9 @@ export class TSBuilder {
|
|
107
111
|
options = _objectWithoutProperties(_this$options$recoil, _excluded3);
|
108
112
|
|
109
113
|
if (!enabled) return;
|
110
|
-
const
|
114
|
+
const {
|
115
|
+
schemas
|
116
|
+
} = await readSchemas({
|
111
117
|
schemaDir: contract.dir
|
112
118
|
});
|
113
119
|
const files = await generateRecoil(contract.name, schemas, this.outPath, options);
|
@@ -122,7 +128,9 @@ export class TSBuilder {
|
|
122
128
|
options = _objectWithoutProperties(_this$options$reactQu, _excluded4);
|
123
129
|
|
124
130
|
if (!enabled) return;
|
125
|
-
const
|
131
|
+
const {
|
132
|
+
schemas
|
133
|
+
} = await readSchemas({
|
126
134
|
schemaDir: contract.dir
|
127
135
|
});
|
128
136
|
const files = await generateReactQuery(contract.name, schemas, this.outPath, options);
|
@@ -137,7 +145,9 @@ export class TSBuilder {
|
|
137
145
|
options = _objectWithoutProperties(_this$options$message, _excluded5);
|
138
146
|
|
139
147
|
if (!enabled) return;
|
140
|
-
const
|
148
|
+
const {
|
149
|
+
schemas
|
150
|
+
} = await readSchemas({
|
141
151
|
schemaDir: contract.dir
|
142
152
|
});
|
143
153
|
const files = await generateMessageComposer(contract.name, schemas, this.outPath, options);
|
@@ -14,7 +14,7 @@ const fs = require('fs');
|
|
14
14
|
|
15
15
|
const path = require('path');
|
16
16
|
|
17
|
-
const repo = '
|
17
|
+
const repo = 'https://github.com/pyramation/tmpl-cosmwasm-module.git';
|
18
18
|
export default (async argv => {
|
19
19
|
if (!shell.which('git')) {
|
20
20
|
shell.echo('Sorry, this script requires git');
|
package/module/utils/schemas.js
CHANGED
@@ -10,24 +10,62 @@ import { cleanse } from './cleanse';
|
|
10
10
|
import { compile } from '@pyramation/json-schema-to-typescript';
|
11
11
|
import { parser } from './parse';
|
12
12
|
;
|
13
|
+
;
|
13
14
|
export const readSchemas = async ({
|
14
15
|
schemaDir,
|
15
|
-
schemaOptions,
|
16
16
|
clean = true
|
17
17
|
}) => {
|
18
18
|
const fn = clean ? cleanse : str => str;
|
19
19
|
const files = glob(schemaDir + '/**/*.json');
|
20
20
|
const schemas = files.map(file => JSON.parse(readFileSync(file, 'utf-8')));
|
21
21
|
|
22
|
-
if (
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
if (schemas.length > 1) {
|
23
|
+
// legacy
|
24
|
+
// TODO add console.warn here
|
25
|
+
return {
|
26
|
+
schemas: fn(schemas)
|
27
|
+
};
|
28
|
+
}
|
29
|
+
|
30
|
+
if (schemas.length === 0) {
|
31
|
+
throw new Error('Error [too few files]: requires one schema file per contract');
|
32
|
+
}
|
26
33
|
|
27
|
-
|
34
|
+
if (schemas.length !== 1) {
|
35
|
+
throw new Error('Error [too many files]: CosmWasm v1.1 schemas supports one file');
|
28
36
|
}
|
29
37
|
|
30
|
-
|
38
|
+
const idlObject = schemas[0];
|
39
|
+
const {
|
40
|
+
contract_name,
|
41
|
+
contract_version,
|
42
|
+
idl_version,
|
43
|
+
responses,
|
44
|
+
instantiate,
|
45
|
+
execute,
|
46
|
+
query,
|
47
|
+
migrate,
|
48
|
+
sudo
|
49
|
+
} = idlObject;
|
50
|
+
|
51
|
+
if (typeof idl_version !== 'string') {
|
52
|
+
// legacy
|
53
|
+
return {
|
54
|
+
schemas: fn(schemas)
|
55
|
+
};
|
56
|
+
} // TODO use contract_name, etc.
|
57
|
+
|
58
|
+
|
59
|
+
return {
|
60
|
+
schemas: Object.values(fn({
|
61
|
+
instantiate,
|
62
|
+
execute,
|
63
|
+
query,
|
64
|
+
migrate,
|
65
|
+
sudo
|
66
|
+
})).filter(Boolean),
|
67
|
+
idlObject
|
68
|
+
};
|
31
69
|
};
|
32
70
|
export const findQueryMsg = schemas => {
|
33
71
|
const QueryMsg = schemas.find(schema => schema.title === 'QueryMsg');
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cosmwasm/ts-codegen",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.14.2",
|
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",
|
7
7
|
"license": "SEE LICENSE IN LICENSE",
|
8
8
|
"main": "main/index.js",
|
9
9
|
"module": "module/index.js",
|
10
|
-
"typings": "types/index.d.ts",
|
10
|
+
"typings": "types/src/index.d.ts",
|
11
11
|
"bin": {
|
12
12
|
"cosmwasm-ts-codegen": "main/ts-codegen.js"
|
13
13
|
},
|
@@ -96,5 +96,5 @@
|
|
96
96
|
"shelljs": "0.8.5",
|
97
97
|
"wasm-ast-types": "^0.9.0"
|
98
98
|
},
|
99
|
-
"gitHead": "
|
99
|
+
"gitHead": "f1b4bb730177be7342b0867c162cc7edf5ce3a29"
|
100
100
|
}
|
package/types/src/types.d.ts
CHANGED
@@ -1 +1,16 @@
|
|
1
|
+
import { JSONSchema } from "wasm-ast-types";
|
2
|
+
interface KeyedSchema {
|
3
|
+
[key: string]: JSONSchema;
|
4
|
+
}
|
5
|
+
export interface IDLObject {
|
6
|
+
contract_name: string;
|
7
|
+
contract_version: string;
|
8
|
+
idl_version: string;
|
9
|
+
instantiate: JSONSchema;
|
10
|
+
execute: JSONSchema;
|
11
|
+
query: JSONSchema;
|
12
|
+
migrate: JSONSchema;
|
13
|
+
sudo: JSONSchema;
|
14
|
+
responses: KeyedSchema;
|
15
|
+
}
|
1
16
|
export {};
|
@@ -1,12 +1,14 @@
|
|
1
1
|
import { JSONSchema } from 'wasm-ast-types';
|
2
|
+
import { IDLObject } from '../types';
|
2
3
|
interface ReadSchemaOpts {
|
3
4
|
schemaDir: string;
|
4
|
-
schemaOptions?: {
|
5
|
-
packed?: boolean;
|
6
|
-
};
|
7
5
|
clean?: boolean;
|
8
6
|
}
|
9
|
-
|
7
|
+
interface ReadSchemasValue {
|
8
|
+
schemas: JSONSchema[];
|
9
|
+
idlObject?: IDLObject;
|
10
|
+
}
|
11
|
+
export declare const readSchemas: ({ schemaDir, clean }: ReadSchemaOpts) => Promise<ReadSchemasValue>;
|
10
12
|
export declare const findQueryMsg: (schemas: any) => any;
|
11
13
|
export declare const findExecuteMsg: (schemas: any) => any;
|
12
14
|
export declare const findAndParseTypes: (schemas: any) => Promise<{}>;
|